potree.js 4.8 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254882558825688257882588825988260882618826288263882648826588266882678826888269882708827188272882738827488275882768827788278882798828088281882828828388284882858828688287882888828988290882918829288293882948829588296882978829888299883008830188302883038830488305883068830788308883098831088311883128831388314883158831688317883188831988320883218832288323883248832588326883278832888329883308833188332883338833488335883368833788338883398834088341883428834388344883458834688347883488834988350883518835288353883548835588356883578835888359883608836188362883638836488365883668836788368883698837088371883728837388374883758837688377883788837988380883818838288383883848838588386883878838888389883908839188392883938839488395883968839788398883998840088401884028840388404884058840688407884088840988410884118841288413884148841588416884178841888419884208842188422884238842488425884268842788428884298843088431884328843388434884358843688437884388843988440884418844288443884448844588446884478844888449884508845188452884538845488455884568845788458884598846088461884628846388464884658846688467884688846988470884718847288473884748847588476884778847888479884808848188482884838848488485884868848788488884898849088491884928849388494884958849688497884988849988500885018850288503885048850588506885078850888509885108851188512885138851488515885168851788518885198852088521885228852388524885258852688527885288852988530885318853288533885348853588536885378853888539885408854188542885438854488545885468854788548885498855088551885528855388554885558855688557885588855988560885618856288563885648856588566885678856888569885708857188572885738857488575885768857788578885798858088581885828858388584885858858688587885888858988590885918859288593885948859588596885978859888599886008860188602886038860488605886068860788608886098861088611886128861388614886158861688617886188861988620886218862288623886248862588626886278862888629886308863188632886338863488635886368863788638886398864088641886428864388644886458864688647886488864988650886518865288653886548865588656886578865888659886608866188662886638866488665886668866788668886698867088671886728867388674886758867688677886788867988680886818868288683886848868588686886878868888689886908869188692886938869488695886968869788698886998870088701887028870388704887058870688707887088870988710887118871288713887148871588716887178871888719887208872188722887238872488725887268872788728887298873088731887328873388734887358873688737887388873988740887418874288743887448874588746887478874888749887508875188752887538875488755887568875788758887598876088761887628876388764887658876688767887688876988770887718877288773887748877588776887778877888779887808878188782887838878488785887868878788788887898879088791887928879388794887958879688797887988879988800888018880288803888048880588806888078880888809888108881188812888138881488815888168881788818888198882088821888228882388824888258882688827888288882988830888318883288833888348883588836888378883888839888408884188842888438884488845888468884788848888498885088851888528885388854888558885688857888588885988860888618886288863888648886588866888678886888869888708887188872888738887488875888768887788878888798888088881888828888388884888858888688887888888888988890888918889288893888948889588896888978889888899889008890188902889038890488905889068890788908889098891088911889128891388914889158891688917889188891988920889218892288923889248892588926889278892888929889308893188932889338893488935889368893788938889398894088941889428894388944889458894688947889488894988950889518895288953889548895588956889578895888959889608896188962889638896488965889668896788968889698897088971889728897388974889758897688977889788897988980889818898288983889848898588986889878898888989889908899188992889938899488995889968899788998889998900089001890028900389004890058900689007890088900989010890118901289013890148901589016890178901889019890208902189022890238902489025890268902789028890298903089031890328903389034890358903689037890388903989040890418904289043890448904589046890478904889049890508905189052890538905489055890568905789058890598906089061890628906389064890658906689067890688906989070890718907289073890748907589076890778907889079890808908189082890838908489085890868908789088890898909089091890928909389094890958909689097890988909989100891018910289103891048910589106891078910889109891108911189112891138911489115891168911789118891198912089121891228912389124891258912689127891288912989130891318913289133891348913589136891378913889139891408914189142891438914489145891468914789148891498915089151891528915389154891558915689157891588915989160891618916289163891648916589166891678916889169891708917189172891738917489175891768917789178891798918089181891828918389184891858918689187891888918989190891918919289193891948919589196891978919889199892008920189202892038920489205892068920789208892098921089211892128921389214892158921689217892188921989220892218922289223892248922589226892278922889229892308923189232892338923489235892368923789238892398924089241892428924389244892458924689247892488924989250892518925289253892548925589256892578925889259892608926189262892638926489265892668926789268892698927089271892728927389274892758927689277892788927989280892818928289283892848928589286892878928889289892908929189292892938929489295892968929789298892998930089301893028930389304893058930689307893088930989310893118931289313893148931589316893178931889319893208932189322893238932489325893268932789328893298933089331893328933389334893358933689337893388933989340893418934289343893448934589346893478934889349893508935189352893538935489355893568935789358893598936089361893628936389364893658936689367893688936989370893718937289373893748937589376893778937889379893808938189382893838938489385893868938789388893898939089391893928939389394893958939689397893988939989400894018940289403894048940589406894078940889409894108941189412894138941489415894168941789418894198942089421894228942389424894258942689427894288942989430894318943289433894348943589436894378943889439894408944189442894438944489445894468944789448894498945089451894528945389454894558945689457894588945989460894618946289463894648946589466894678946889469894708947189472894738947489475894768947789478894798948089481894828948389484894858948689487894888948989490894918949289493894948949589496894978949889499895008950189502895038950489505895068950789508895098951089511895128951389514895158951689517895188951989520895218952289523895248952589526895278952889529895308953189532895338953489535895368953789538895398954089541895428954389544895458954689547895488954989550895518955289553895548955589556895578955889559895608956189562895638956489565895668956789568895698957089571895728957389574895758957689577895788957989580895818958289583895848958589586895878958889589895908959189592895938959489595895968959789598895998960089601896028960389604896058960689607896088960989610896118961289613896148961589616896178961889619896208962189622896238962489625896268962789628896298963089631896328963389634896358963689637896388963989640896418964289643896448964589646896478964889649896508965189652896538965489655896568965789658896598966089661896628966389664896658966689667896688966989670896718967289673896748967589676896778967889679896808968189682896838968489685896868968789688896898969089691896928969389694896958969689697896988969989700897018970289703897048970589706897078970889709897108971189712897138971489715897168971789718897198972089721897228972389724897258972689727897288972989730897318973289733897348973589736897378973889739897408974189742897438974489745897468974789748897498975089751897528975389754897558975689757897588975989760897618976289763897648976589766897678976889769897708977189772897738977489775897768977789778897798978089781897828978389784897858978689787897888978989790897918979289793897948979589796897978979889799898008980189802898038980489805898068980789808898098981089811898128981389814898158981689817898188981989820898218982289823898248982589826898278982889829898308983189832898338983489835898368983789838898398984089841898428984389844898458984689847898488984989850898518985289853898548985589856898578985889859898608986189862898638986489865898668986789868898698987089871898728987389874898758987689877898788987989880898818988289883898848988589886898878988889889898908989189892898938989489895898968989789898898998990089901899028990389904899058990689907899088990989910899118991289913899148991589916899178991889919899208992189922899238992489925899268992789928899298993089931899328993389934899358993689937899388993989940899418994289943899448994589946899478994889949899508995189952899538995489955899568995789958899598996089961899628996389964899658996689967899688996989970899718997289973899748997589976899778997889979899808998189982899838998489985899868998789988899898999089991899928999389994899958999689997899988999990000900019000290003900049000590006900079000890009900109001190012900139001490015900169001790018900199002090021900229002390024900259002690027900289002990030900319003290033900349003590036900379003890039900409004190042900439004490045900469004790048900499005090051900529005390054900559005690057900589005990060900619006290063900649006590066900679006890069900709007190072900739007490075900769007790078900799008090081900829008390084900859008690087900889008990090900919009290093900949009590096900979009890099901009010190102901039010490105901069010790108901099011090111901129011390114901159011690117901189011990120901219012290123901249012590126901279012890129901309013190132901339013490135901369013790138901399014090141901429014390144901459014690147901489014990150901519015290153901549015590156901579015890159901609016190162901639016490165901669016790168901699017090171901729017390174901759017690177901789017990180901819018290183901849018590186901879018890189901909019190192901939019490195901969019790198901999020090201902029020390204902059020690207902089020990210902119021290213902149021590216902179021890219902209022190222902239022490225902269022790228902299023090231902329023390234902359023690237902389023990240902419024290243902449024590246902479024890249902509025190252902539025490255902569025790258902599026090261902629026390264902659026690267902689026990270902719027290273902749027590276902779027890279902809028190282902839028490285902869028790288902899029090291902929029390294902959029690297902989029990300903019030290303903049030590306903079030890309903109031190312903139031490315903169031790318903199032090321903229032390324903259032690327903289032990330903319033290333903349033590336903379033890339903409034190342903439034490345903469034790348903499035090351903529035390354903559035690357903589035990360903619036290363903649036590366903679036890369903709037190372903739037490375903769037790378903799038090381903829038390384903859038690387903889038990390903919039290393903949039590396903979039890399904009040190402904039040490405904069040790408904099041090411904129041390414904159041690417904189041990420904219042290423904249042590426904279042890429904309043190432904339043490435904369043790438904399044090441904429044390444904459044690447904489044990450904519045290453904549045590456904579045890459904609046190462904639046490465904669046790468904699047090471904729047390474904759047690477904789047990480904819048290483904849048590486904879048890489904909049190492904939049490495904969049790498904999050090501905029050390504905059050690507905089050990510905119051290513905149051590516905179051890519905209052190522905239052490525905269052790528905299053090531905329053390534905359053690537905389053990540905419054290543905449054590546905479054890549905509055190552905539055490555905569055790558905599056090561905629056390564905659056690567905689056990570905719057290573905749057590576905779057890579905809058190582905839058490585905869058790588905899059090591905929059390594905959059690597905989059990600906019060290603906049060590606906079060890609906109061190612906139061490615906169061790618906199062090621906229062390624906259062690627906289062990630906319063290633906349063590636906379063890639906409064190642906439064490645906469064790648906499065090651906529065390654906559065690657906589065990660906619066290663906649066590666906679066890669906709067190672906739067490675906769067790678906799068090681906829068390684906859068690687906889068990690906919069290693906949069590696906979069890699907009070190702907039070490705907069070790708907099071090711907129071390714907159071690717907189071990720907219072290723907249072590726907279072890729907309073190732907339073490735907369073790738907399074090741907429074390744907459074690747907489074990750907519075290753907549075590756907579075890759907609076190762907639076490765907669076790768907699077090771907729077390774907759077690777907789077990780907819078290783907849078590786907879078890789907909079190792907939079490795907969079790798907999080090801908029080390804908059080690807908089080990810908119081290813908149081590816908179081890819908209082190822908239082490825908269082790828908299083090831908329083390834908359083690837908389083990840908419084290843908449084590846908479084890849908509085190852908539085490855908569085790858908599086090861908629086390864908659086690867908689086990870908719087290873908749087590876908779087890879908809088190882908839088490885908869088790888908899089090891908929089390894908959089690897908989089990900909019090290903909049090590906909079090890909909109091190912909139091490915909169091790918909199092090921909229092390924909259092690927909289092990930909319093290933909349093590936909379093890939909409094190942909439094490945909469094790948909499095090951909529095390954909559095690957909589095990960909619096290963909649096590966909679096890969909709097190972909739097490975909769097790978909799098090981909829098390984909859098690987909889098990990909919099290993909949099590996909979099890999910009100191002910039100491005910069100791008910099101091011910129101391014910159101691017910189101991020910219102291023910249102591026910279102891029910309103191032910339103491035910369103791038910399104091041910429104391044910459104691047910489104991050910519105291053910549105591056910579105891059910609106191062910639106491065910669106791068910699107091071910729107391074910759107691077910789107991080910819108291083910849108591086910879108891089910909109191092910939109491095910969109791098910999110091101911029110391104911059110691107911089110991110911119111291113911149111591116911179111891119911209112191122911239112491125911269112791128911299113091131911329113391134911359113691137911389113991140911419114291143911449114591146911479114891149911509115191152911539115491155911569115791158911599116091161911629116391164911659116691167911689116991170911719117291173911749117591176911779117891179911809118191182911839118491185911869118791188911899119091191911929119391194911959119691197911989119991200912019120291203912049120591206912079120891209912109121191212912139121491215912169121791218912199122091221912229122391224912259122691227912289122991230912319123291233912349123591236912379123891239912409124191242912439124491245912469124791248912499125091251912529125391254912559125691257912589125991260912619126291263912649126591266912679126891269912709127191272912739127491275912769127791278912799128091281912829128391284912859128691287912889128991290912919129291293912949129591296912979129891299913009130191302913039130491305913069130791308913099131091311913129131391314913159131691317913189131991320913219132291323913249132591326913279132891329913309133191332913339133491335913369133791338913399134091341913429134391344913459134691347913489134991350913519135291353913549135591356913579135891359913609136191362913639136491365913669136791368913699137091371913729137391374913759137691377913789137991380913819138291383913849138591386913879138891389913909139191392913939139491395913969139791398913999140091401914029140391404914059140691407914089140991410914119141291413914149141591416914179141891419914209142191422914239142491425914269142791428914299143091431914329143391434914359143691437914389143991440914419144291443914449144591446914479144891449914509145191452914539145491455914569145791458914599146091461914629146391464914659146691467914689146991470914719147291473914749147591476914779147891479914809148191482914839148491485914869148791488914899149091491914929149391494914959149691497914989149991500915019150291503915049150591506915079150891509915109151191512915139151491515915169151791518915199152091521915229152391524915259152691527915289152991530915319153291533915349153591536915379153891539915409154191542915439154491545915469154791548915499155091551915529155391554915559155691557915589155991560915619156291563915649156591566915679156891569915709157191572915739157491575915769157791578915799158091581915829158391584915859158691587915889158991590915919159291593915949159591596915979159891599916009160191602916039160491605916069160791608916099161091611916129161391614916159161691617916189161991620916219162291623916249162591626916279162891629916309163191632916339163491635916369163791638916399164091641916429164391644916459164691647916489164991650916519165291653916549165591656916579165891659916609166191662916639166491665916669166791668916699167091671916729167391674916759167691677916789167991680916819168291683916849168591686916879168891689916909169191692916939169491695916969169791698916999170091701917029170391704917059170691707917089170991710917119171291713917149171591716917179171891719917209172191722917239172491725917269172791728917299173091731917329173391734917359173691737917389173991740917419174291743917449174591746917479174891749917509175191752917539175491755917569175791758917599176091761917629176391764917659176691767917689176991770917719177291773917749177591776917779177891779917809178191782917839178491785917869178791788917899179091791917929179391794917959179691797917989179991800918019180291803918049180591806918079180891809918109181191812918139181491815918169181791818918199182091821918229182391824918259182691827918289182991830918319183291833918349183591836918379183891839918409184191842918439184491845918469184791848918499185091851918529185391854918559185691857918589185991860918619186291863918649186591866918679186891869918709187191872918739187491875918769187791878918799188091881918829188391884918859188691887918889188991890918919189291893918949189591896918979189891899919009190191902919039190491905919069190791908919099191091911919129191391914919159191691917919189191991920919219192291923919249192591926919279192891929919309193191932919339193491935919369193791938919399194091941919429194391944919459194691947919489194991950919519195291953919549195591956919579195891959919609196191962919639196491965919669196791968919699197091971919729197391974919759197691977919789197991980919819198291983919849198591986919879198891989919909199191992919939199491995919969199791998919999200092001920029200392004920059200692007920089200992010920119201292013920149201592016920179201892019920209202192022920239202492025920269202792028920299203092031920329203392034920359203692037920389203992040920419204292043920449204592046920479204892049920509205192052920539205492055920569205792058920599206092061920629206392064920659206692067920689206992070920719207292073920749207592076920779207892079920809208192082920839208492085920869208792088920899209092091920929209392094920959209692097920989209992100921019210292103921049210592106921079210892109921109211192112921139211492115921169211792118921199212092121921229212392124921259212692127921289212992130921319213292133921349213592136921379213892139921409214192142921439214492145921469214792148921499215092151921529215392154921559215692157921589215992160921619216292163921649216592166921679216892169921709217192172921739217492175921769217792178921799218092181921829218392184921859218692187921889218992190921919219292193921949219592196921979219892199922009220192202922039220492205922069220792208922099221092211922129221392214922159221692217922189221992220922219222292223922249222592226922279222892229922309223192232922339223492235922369223792238922399224092241922429224392244922459224692247922489224992250922519225292253922549225592256922579225892259922609226192262922639226492265922669226792268922699227092271922729227392274922759227692277922789227992280922819228292283922849228592286922879228892289922909229192292922939229492295922969229792298922999230092301923029230392304923059230692307923089230992310923119231292313923149231592316923179231892319923209232192322923239232492325923269232792328923299233092331923329233392334923359233692337923389233992340923419234292343923449234592346923479234892349923509235192352923539235492355923569235792358923599236092361923629236392364923659236692367923689236992370923719237292373923749237592376923779237892379923809238192382923839238492385923869238792388923899239092391923929239392394923959239692397923989239992400924019240292403924049240592406924079240892409924109241192412924139241492415924169241792418924199242092421924229242392424924259242692427924289242992430924319243292433924349243592436924379243892439924409244192442924439244492445924469244792448924499245092451924529245392454924559245692457924589245992460924619246292463924649246592466924679246892469924709247192472924739247492475924769247792478924799248092481924829248392484924859248692487924889248992490924919249292493924949249592496924979249892499925009250192502925039250492505925069250792508925099251092511925129251392514925159251692517925189251992520925219252292523925249252592526925279252892529925309253192532925339253492535925369253792538925399254092541925429254392544925459254692547925489254992550925519255292553925549255592556925579255892559925609256192562925639256492565925669256792568925699257092571925729257392574925759257692577925789257992580925819258292583925849258592586925879258892589925909259192592925939259492595925969259792598925999260092601926029260392604926059260692607926089260992610926119261292613926149261592616926179261892619926209262192622926239262492625926269262792628926299263092631926329263392634926359263692637926389263992640926419264292643926449264592646926479264892649926509265192652926539265492655926569265792658926599266092661926629266392664926659266692667926689266992670926719267292673926749267592676926779267892679926809268192682926839268492685926869268792688926899269092691926929269392694926959269692697926989269992700927019270292703927049270592706927079270892709927109271192712927139271492715927169271792718927199272092721927229272392724927259272692727927289272992730927319273292733927349273592736927379273892739927409274192742927439274492745927469274792748927499275092751927529275392754927559275692757927589275992760927619276292763927649276592766927679276892769927709277192772927739277492775927769277792778927799278092781927829278392784927859278692787927889278992790927919279292793927949279592796927979279892799928009280192802928039280492805928069280792808928099281092811928129281392814928159281692817928189281992820928219282292823928249282592826928279282892829928309283192832928339283492835928369283792838928399284092841928429284392844928459284692847928489284992850928519285292853928549285592856928579285892859928609286192862928639286492865928669286792868928699287092871928729287392874928759287692877928789287992880928819288292883928849288592886928879288892889928909289192892928939289492895928969289792898928999290092901929029290392904929059290692907929089290992910929119291292913929149291592916929179291892919929209292192922929239292492925929269292792928929299293092931929329293392934929359293692937929389293992940929419294292943929449294592946929479294892949929509295192952929539295492955929569295792958929599296092961929629296392964929659296692967929689296992970929719297292973929749297592976929779297892979929809298192982929839298492985929869298792988929899299092991929929299392994929959299692997929989299993000930019300293003930049300593006930079300893009930109301193012930139301493015930169301793018930199302093021930229302393024930259302693027930289302993030930319303293033930349303593036930379303893039930409304193042930439304493045930469304793048930499305093051930529305393054930559305693057930589305993060930619306293063930649306593066930679306893069930709307193072930739307493075930769307793078930799308093081930829308393084930859308693087930889308993090930919309293093930949309593096930979309893099931009310193102931039310493105931069310793108931099311093111931129311393114931159311693117931189311993120931219312293123931249312593126931279312893129931309313193132931339313493135931369313793138931399314093141931429314393144931459314693147931489314993150931519315293153931549315593156931579315893159931609316193162931639316493165931669316793168931699317093171931729317393174931759317693177931789317993180931819318293183931849318593186931879318893189931909319193192931939319493195931969319793198931999320093201932029320393204932059320693207932089320993210932119321293213932149321593216932179321893219932209322193222932239322493225932269322793228932299323093231932329323393234932359323693237932389323993240932419324293243932449324593246932479324893249932509325193252932539325493255932569325793258932599326093261932629326393264932659326693267932689326993270932719327293273932749327593276932779327893279932809328193282932839328493285932869328793288932899329093291932929329393294932959329693297932989329993300933019330293303933049330593306933079330893309933109331193312933139331493315933169331793318933199332093321933229332393324933259332693327933289332993330933319333293333933349333593336933379333893339933409334193342933439334493345933469334793348933499335093351933529335393354933559335693357933589335993360933619336293363933649336593366933679336893369933709337193372933739337493375933769337793378933799338093381933829338393384933859338693387933889338993390933919339293393933949339593396933979339893399934009340193402934039340493405934069340793408934099341093411934129341393414934159341693417934189341993420934219342293423934249342593426934279342893429934309343193432934339343493435934369343793438934399344093441934429344393444934459344693447934489344993450934519345293453934549345593456934579345893459934609346193462934639346493465934669346793468934699347093471934729347393474934759347693477934789347993480934819348293483934849348593486934879348893489934909349193492934939349493495934969349793498934999350093501935029350393504935059350693507935089350993510935119351293513935149351593516935179351893519935209352193522935239352493525935269352793528935299353093531935329353393534935359353693537935389353993540935419354293543935449354593546935479354893549935509355193552935539355493555935569355793558935599356093561935629356393564935659356693567935689356993570935719357293573935749357593576935779357893579935809358193582935839358493585935869358793588935899359093591935929359393594935959359693597935989359993600936019360293603936049360593606936079360893609936109361193612936139361493615936169361793618936199362093621936229362393624936259362693627936289362993630936319363293633936349363593636936379363893639936409364193642936439364493645936469364793648936499365093651936529365393654936559365693657936589365993660936619366293663936649366593666936679366893669936709367193672936739367493675936769367793678936799368093681936829368393684936859368693687936889368993690936919369293693936949369593696936979369893699937009370193702937039370493705937069370793708937099371093711937129371393714937159371693717937189371993720937219372293723937249372593726937279372893729937309373193732937339373493735937369373793738937399374093741937429374393744937459374693747937489374993750937519375293753937549375593756937579375893759937609376193762937639376493765937669376793768937699377093771937729377393774937759377693777937789377993780937819378293783937849378593786937879378893789937909379193792937939379493795937969379793798937999380093801938029380393804938059380693807938089380993810938119381293813938149381593816938179381893819938209382193822938239382493825938269382793828938299383093831938329383393834938359383693837938389383993840938419384293843938449384593846938479384893849938509385193852938539385493855938569385793858938599386093861938629386393864938659386693867938689386993870938719387293873938749387593876938779387893879938809388193882938839388493885938869388793888938899389093891938929389393894938959389693897938989389993900939019390293903939049390593906939079390893909939109391193912939139391493915939169391793918939199392093921939229392393924939259392693927939289392993930939319393293933939349393593936939379393893939939409394193942939439394493945939469394793948939499395093951939529395393954939559395693957939589395993960939619396293963939649396593966939679396893969939709397193972939739397493975939769397793978939799398093981939829398393984939859398693987939889398993990939919399293993939949399593996939979399893999940009400194002940039400494005940069400794008940099401094011940129401394014940159401694017940189401994020940219402294023940249402594026940279402894029940309403194032940339403494035940369403794038940399404094041940429404394044940459404694047940489404994050940519405294053940549405594056940579405894059940609406194062940639406494065940669406794068940699407094071940729407394074940759407694077940789407994080940819408294083940849408594086940879408894089940909409194092940939409494095940969409794098940999410094101941029410394104941059410694107941089410994110941119411294113941149411594116941179411894119941209412194122941239412494125941269412794128941299413094131941329413394134941359413694137941389413994140941419414294143941449414594146941479414894149941509415194152941539415494155941569415794158941599416094161941629416394164941659416694167941689416994170941719417294173941749417594176941779417894179941809418194182941839418494185941869418794188941899419094191941929419394194941959419694197941989419994200942019420294203942049420594206942079420894209942109421194212942139421494215942169421794218942199422094221942229422394224942259422694227942289422994230942319423294233942349423594236942379423894239942409424194242942439424494245942469424794248942499425094251942529425394254942559425694257942589425994260942619426294263942649426594266942679426894269942709427194272942739427494275942769427794278942799428094281942829428394284942859428694287942889428994290942919429294293942949429594296942979429894299943009430194302943039430494305943069430794308943099431094311943129431394314943159431694317943189431994320943219432294323943249432594326943279432894329943309433194332943339433494335943369433794338943399434094341943429434394344943459434694347943489434994350943519435294353943549435594356943579435894359943609436194362943639436494365943669436794368943699437094371943729437394374943759437694377943789437994380943819438294383943849438594386943879438894389943909439194392943939439494395943969439794398943999440094401944029440394404944059440694407944089440994410944119441294413944149441594416944179441894419944209442194422944239442494425944269442794428944299443094431944329443394434944359443694437944389443994440944419444294443944449444594446944479444894449944509445194452944539445494455944569445794458944599446094461944629446394464944659446694467944689446994470944719447294473944749447594476944779447894479944809448194482944839448494485944869448794488944899449094491944929449394494944959449694497944989449994500945019450294503945049450594506945079450894509945109451194512945139451494515945169451794518945199452094521945229452394524945259452694527945289452994530945319453294533945349453594536945379453894539945409454194542945439454494545945469454794548945499455094551945529455394554945559455694557945589455994560945619456294563945649456594566945679456894569945709457194572945739457494575945769457794578945799458094581945829458394584945859458694587945889458994590945919459294593945949459594596945979459894599946009460194602946039460494605946069460794608946099461094611946129461394614946159461694617946189461994620946219462294623946249462594626946279462894629946309463194632946339463494635946369463794638946399464094641946429464394644946459464694647946489464994650946519465294653946549465594656946579465894659946609466194662946639466494665946669466794668946699467094671946729467394674946759467694677946789467994680946819468294683946849468594686946879468894689946909469194692946939469494695946969469794698946999470094701947029470394704947059470694707947089470994710947119471294713947149471594716947179471894719947209472194722947239472494725947269472794728947299473094731947329473394734947359473694737947389473994740947419474294743947449474594746947479474894749947509475194752947539475494755947569475794758947599476094761947629476394764947659476694767947689476994770947719477294773947749477594776947779477894779947809478194782947839478494785947869478794788947899479094791947929479394794947959479694797947989479994800948019480294803948049480594806948079480894809948109481194812948139481494815948169481794818948199482094821948229482394824948259482694827948289482994830948319483294833948349483594836948379483894839948409484194842948439484494845948469484794848948499485094851948529485394854948559485694857948589485994860948619486294863948649486594866948679486894869948709487194872948739487494875948769487794878948799488094881948829488394884948859488694887948889488994890948919489294893948949489594896948979489894899949009490194902949039490494905949069490794908949099491094911949129491394914949159491694917949189491994920949219492294923949249492594926949279492894929949309493194932949339493494935949369493794938949399494094941949429494394944949459494694947949489494994950949519495294953949549495594956949579495894959949609496194962949639496494965949669496794968949699497094971949729497394974949759497694977949789497994980949819498294983949849498594986949879498894989949909499194992949939499494995949969499794998949999500095001950029500395004950059500695007950089500995010950119501295013950149501595016950179501895019950209502195022950239502495025950269502795028950299503095031950329503395034950359503695037950389503995040950419504295043950449504595046950479504895049950509505195052950539505495055950569505795058950599506095061950629506395064950659506695067950689506995070950719507295073950749507595076950779507895079950809508195082950839508495085950869508795088950899509095091950929509395094950959509695097950989509995100951019510295103951049510595106951079510895109951109511195112951139511495115951169511795118951199512095121951229512395124951259512695127951289512995130951319513295133951349513595136951379513895139951409514195142951439514495145951469514795148951499515095151951529515395154951559515695157951589515995160951619516295163951649516595166951679516895169951709517195172951739517495175951769517795178951799518095181951829518395184951859518695187951889518995190951919519295193951949519595196951979519895199952009520195202952039520495205952069520795208952099521095211952129521395214952159521695217952189521995220952219522295223952249522595226952279522895229952309523195232952339523495235952369523795238952399524095241952429524395244952459524695247952489524995250952519525295253952549525595256952579525895259952609526195262952639526495265952669526795268952699527095271952729527395274952759527695277952789527995280952819528295283952849528595286952879528895289952909529195292952939529495295952969529795298952999530095301953029530395304953059530695307953089530995310953119531295313953149531595316953179531895319953209532195322953239532495325953269532795328953299533095331953329533395334953359533695337953389533995340953419534295343953449534595346953479534895349953509535195352953539535495355953569535795358953599536095361953629536395364953659536695367953689536995370953719537295373953749537595376953779537895379953809538195382953839538495385953869538795388953899539095391953929539395394953959539695397953989539995400954019540295403954049540595406954079540895409954109541195412954139541495415954169541795418954199542095421954229542395424954259542695427954289542995430954319543295433954349543595436954379543895439954409544195442954439544495445954469544795448954499545095451954529545395454954559545695457954589545995460954619546295463954649546595466954679546895469954709547195472954739547495475954769547795478954799548095481954829548395484954859548695487954889548995490954919549295493954949549595496954979549895499955009550195502955039550495505955069550795508955099551095511955129551395514955159551695517955189551995520955219552295523955249552595526955279552895529955309553195532955339553495535955369553795538955399554095541955429554395544955459554695547955489554995550955519555295553955549555595556955579555895559955609556195562955639556495565955669556795568955699557095571955729557395574955759557695577955789557995580955819558295583955849558595586955879558895589955909559195592955939559495595955969559795598955999560095601956029560395604956059560695607956089560995610956119561295613956149561595616956179561895619956209562195622956239562495625956269562795628956299563095631956329563395634956359563695637956389563995640956419564295643956449564595646956479564895649956509565195652956539565495655956569565795658956599566095661956629566395664956659566695667956689566995670956719567295673956749567595676956779567895679956809568195682956839568495685956869568795688956899569095691956929569395694956959569695697956989569995700957019570295703957049570595706957079570895709957109571195712957139571495715957169571795718957199572095721957229572395724957259572695727957289572995730957319573295733957349573595736957379573895739957409574195742957439574495745957469574795748957499575095751957529575395754957559575695757957589575995760957619576295763957649576595766957679576895769957709577195772957739577495775957769577795778957799578095781957829578395784957859578695787957889578995790957919579295793957949579595796957979579895799958009580195802958039580495805958069580795808958099581095811958129581395814958159581695817958189581995820958219582295823958249582595826958279582895829958309583195832958339583495835958369583795838958399584095841958429584395844958459584695847958489584995850958519585295853958549585595856958579585895859958609586195862958639586495865958669586795868958699587095871958729587395874958759587695877958789587995880958819588295883958849588595886958879588895889958909589195892958939589495895958969589795898958999590095901959029590395904959059590695907959089590995910959119591295913959149591595916959179591895919959209592195922959239592495925959269592795928959299593095931959329593395934959359593695937959389593995940959419594295943959449594595946959479594895949959509595195952959539595495955959569595795958959599596095961959629596395964959659596695967959689596995970959719597295973959749597595976959779597895979959809598195982959839598495985959869598795988959899599095991959929599395994959959599695997959989599996000960019600296003960049600596006960079600896009960109601196012960139601496015960169601796018960199602096021960229602396024960259602696027960289602996030960319603296033960349603596036960379603896039960409604196042960439604496045960469604796048960499605096051960529605396054960559605696057960589605996060960619606296063960649606596066960679606896069960709607196072960739607496075960769607796078960799608096081960829608396084960859608696087960889608996090960919609296093960949609596096960979609896099961009610196102961039610496105961069610796108961099611096111961129611396114961159611696117961189611996120961219612296123961249612596126961279612896129961309613196132961339613496135961369613796138961399614096141961429614396144961459614696147961489614996150961519615296153961549615596156961579615896159961609616196162961639616496165961669616796168961699617096171961729617396174961759617696177961789617996180961819618296183961849618596186961879618896189961909619196192961939619496195961969619796198961999620096201962029620396204962059620696207962089620996210962119621296213962149621596216962179621896219962209622196222962239622496225962269622796228962299623096231962329623396234962359623696237962389623996240962419624296243962449624596246962479624896249962509625196252962539625496255962569625796258962599626096261962629626396264962659626696267962689626996270962719627296273962749627596276962779627896279962809628196282962839628496285962869628796288962899629096291962929629396294962959629696297962989629996300963019630296303963049630596306963079630896309963109631196312963139631496315963169631796318963199632096321963229632396324963259632696327963289632996330963319633296333963349633596336963379633896339963409634196342963439634496345963469634796348963499635096351963529635396354963559635696357963589635996360963619636296363963649636596366963679636896369963709637196372963739637496375963769637796378963799638096381963829638396384963859638696387963889638996390963919639296393963949639596396963979639896399964009640196402964039640496405964069640796408964099641096411964129641396414964159641696417964189641996420964219642296423964249642596426964279642896429964309643196432964339643496435964369643796438964399644096441964429644396444964459644696447964489644996450964519645296453964549645596456964579645896459964609646196462964639646496465964669646796468964699647096471964729647396474964759647696477964789647996480964819648296483964849648596486964879648896489964909649196492964939649496495964969649796498964999650096501965029650396504965059650696507965089650996510965119651296513965149651596516965179651896519965209652196522965239652496525965269652796528965299653096531965329653396534965359653696537965389653996540965419654296543965449654596546965479654896549965509655196552965539655496555965569655796558965599656096561965629656396564965659656696567965689656996570965719657296573965749657596576965779657896579965809658196582965839658496585965869658796588965899659096591965929659396594965959659696597965989659996600966019660296603966049660596606966079660896609966109661196612966139661496615966169661796618966199662096621966229662396624966259662696627966289662996630966319663296633966349663596636966379663896639966409664196642966439664496645966469664796648966499665096651966529665396654966559665696657966589665996660966619666296663966649666596666966679666896669966709667196672966739667496675966769667796678966799668096681966829668396684966859668696687966889668996690966919669296693966949669596696966979669896699967009670196702967039670496705967069670796708967099671096711967129671396714967159671696717967189671996720967219672296723967249672596726967279672896729967309673196732967339673496735967369673796738967399674096741967429674396744967459674696747967489674996750967519675296753967549675596756967579675896759967609676196762967639676496765967669676796768967699677096771967729677396774967759677696777967789677996780967819678296783967849678596786967879678896789967909679196792967939679496795967969679796798967999680096801968029680396804968059680696807968089680996810968119681296813968149681596816968179681896819968209682196822968239682496825968269682796828968299683096831968329683396834968359683696837968389683996840968419684296843968449684596846968479684896849968509685196852968539685496855968569685796858968599686096861968629686396864968659686696867968689686996870968719687296873968749687596876968779687896879968809688196882968839688496885968869688796888968899689096891968929689396894968959689696897968989689996900969019690296903969049690596906969079690896909969109691196912969139691496915969169691796918969199692096921969229692396924969259692696927969289692996930969319693296933969349693596936969379693896939969409694196942969439694496945969469694796948969499695096951969529695396954969559695696957969589695996960969619696296963969649696596966969679696896969969709697196972969739697496975969769697796978969799698096981969829698396984969859698696987969889698996990969919699296993969949699596996969979699896999970009700197002970039700497005970069700797008970099701097011970129701397014970159701697017970189701997020970219702297023970249702597026970279702897029970309703197032970339703497035970369703797038970399704097041970429704397044970459704697047970489704997050970519705297053970549705597056970579705897059970609706197062970639706497065970669706797068970699707097071970729707397074970759707697077970789707997080970819708297083970849708597086970879708897089970909709197092970939709497095970969709797098970999710097101971029710397104971059710697107971089710997110971119711297113971149711597116971179711897119971209712197122971239712497125971269712797128971299713097131971329713397134971359713697137971389713997140971419714297143971449714597146971479714897149971509715197152971539715497155971569715797158971599716097161971629716397164971659716697167971689716997170971719717297173971749717597176971779717897179971809718197182971839718497185971869718797188971899719097191971929719397194971959719697197971989719997200972019720297203972049720597206972079720897209972109721197212972139721497215972169721797218972199722097221972229722397224972259722697227972289722997230972319723297233972349723597236972379723897239972409724197242972439724497245972469724797248972499725097251972529725397254972559725697257972589725997260972619726297263972649726597266972679726897269972709727197272972739727497275972769727797278972799728097281972829728397284972859728697287972889728997290972919729297293972949729597296972979729897299973009730197302973039730497305973069730797308973099731097311973129731397314973159731697317973189731997320973219732297323973249732597326973279732897329973309733197332973339733497335973369733797338973399734097341973429734397344973459734697347973489734997350973519735297353973549735597356973579735897359973609736197362973639736497365973669736797368973699737097371973729737397374973759737697377973789737997380973819738297383973849738597386973879738897389973909739197392973939739497395973969739797398973999740097401974029740397404974059740697407974089740997410974119741297413974149741597416974179741897419974209742197422974239742497425974269742797428974299743097431974329743397434974359743697437974389743997440974419744297443974449744597446974479744897449974509745197452974539745497455974569745797458974599746097461974629746397464974659746697467974689746997470974719747297473974749747597476974779747897479974809748197482974839748497485974869748797488974899749097491974929749397494974959749697497974989749997500975019750297503975049750597506975079750897509975109751197512975139751497515975169751797518975199752097521975229752397524975259752697527975289752997530975319753297533975349753597536975379753897539975409754197542975439754497545975469754797548975499755097551975529755397554975559755697557975589755997560975619756297563975649756597566975679756897569975709757197572975739757497575975769757797578975799758097581975829758397584975859758697587975889758997590975919759297593975949759597596975979759897599976009760197602976039760497605976069760797608976099761097611976129761397614976159761697617976189761997620976219762297623976249762597626976279762897629976309763197632976339763497635976369763797638976399764097641976429764397644976459764697647976489764997650976519765297653976549765597656976579765897659976609766197662976639766497665976669766797668976699767097671976729767397674976759767697677976789767997680976819768297683976849768597686976879768897689976909769197692976939769497695976969769797698976999770097701977029770397704977059770697707977089770997710977119771297713977149771597716977179771897719977209772197722977239772497725977269772797728977299773097731977329773397734977359773697737977389773997740977419774297743977449774597746977479774897749977509775197752977539775497755977569775797758977599776097761977629776397764977659776697767977689776997770977719777297773977749777597776977779777897779977809778197782977839778497785977869778797788977899779097791977929779397794977959779697797977989779997800978019780297803978049780597806978079780897809978109781197812978139781497815978169781797818978199782097821978229782397824978259782697827978289782997830978319783297833978349783597836978379783897839978409784197842978439784497845978469784797848978499785097851978529785397854978559785697857978589785997860978619786297863978649786597866978679786897869978709787197872978739787497875978769787797878978799788097881978829788397884978859788697887978889788997890978919789297893978949789597896978979789897899979009790197902979039790497905979069790797908979099791097911979129791397914979159791697917979189791997920979219792297923979249792597926979279792897929979309793197932979339793497935979369793797938979399794097941979429794397944979459794697947979489794997950979519795297953979549795597956979579795897959979609796197962979639796497965979669796797968979699797097971979729797397974979759797697977979789797997980979819798297983979849798597986979879798897989979909799197992979939799497995979969799797998979999800098001980029800398004980059800698007980089800998010980119801298013980149801598016980179801898019980209802198022980239802498025980269802798028980299803098031980329803398034980359803698037980389803998040980419804298043980449804598046980479804898049980509805198052980539805498055980569805798058980599806098061980629806398064980659806698067980689806998070980719807298073980749807598076980779807898079980809808198082980839808498085980869808798088980899809098091980929809398094980959809698097980989809998100981019810298103981049810598106981079810898109981109811198112981139811498115981169811798118981199812098121981229812398124981259812698127981289812998130981319813298133981349813598136981379813898139981409814198142981439814498145981469814798148981499815098151981529815398154981559815698157981589815998160981619816298163981649816598166981679816898169981709817198172981739817498175981769817798178981799818098181981829818398184981859818698187981889818998190981919819298193981949819598196981979819898199982009820198202982039820498205982069820798208982099821098211982129821398214982159821698217982189821998220982219822298223982249822598226982279822898229982309823198232982339823498235982369823798238982399824098241982429824398244982459824698247982489824998250982519825298253982549825598256982579825898259982609826198262982639826498265982669826798268982699827098271982729827398274982759827698277982789827998280982819828298283982849828598286982879828898289982909829198292982939829498295982969829798298982999830098301983029830398304983059830698307983089830998310983119831298313983149831598316983179831898319983209832198322983239832498325983269832798328983299833098331983329833398334983359833698337983389833998340983419834298343983449834598346983479834898349983509835198352983539835498355983569835798358983599836098361983629836398364983659836698367983689836998370983719837298373983749837598376983779837898379983809838198382983839838498385983869838798388983899839098391983929839398394983959839698397983989839998400984019840298403984049840598406984079840898409984109841198412984139841498415984169841798418984199842098421984229842398424984259842698427984289842998430984319843298433984349843598436984379843898439984409844198442984439844498445984469844798448984499845098451984529845398454984559845698457984589845998460984619846298463984649846598466984679846898469984709847198472984739847498475984769847798478984799848098481984829848398484984859848698487984889848998490984919849298493984949849598496984979849898499985009850198502985039850498505985069850798508985099851098511985129851398514985159851698517985189851998520985219852298523985249852598526985279852898529985309853198532985339853498535985369853798538985399854098541985429854398544985459854698547985489854998550985519855298553985549855598556985579855898559985609856198562985639856498565985669856798568985699857098571985729857398574985759857698577985789857998580985819858298583985849858598586985879858898589985909859198592985939859498595985969859798598985999860098601986029860398604986059860698607986089860998610986119861298613986149861598616986179861898619986209862198622986239862498625986269862798628986299863098631986329863398634986359863698637986389863998640986419864298643986449864598646986479864898649986509865198652986539865498655986569865798658986599866098661986629866398664986659866698667986689866998670986719867298673986749867598676986779867898679986809868198682986839868498685986869868798688986899869098691986929869398694986959869698697986989869998700987019870298703987049870598706987079870898709987109871198712987139871498715987169871798718987199872098721987229872398724987259872698727987289872998730987319873298733987349873598736987379873898739987409874198742987439874498745987469874798748987499875098751987529875398754987559875698757987589875998760987619876298763987649876598766987679876898769987709877198772987739877498775987769877798778987799878098781987829878398784987859878698787987889878998790987919879298793987949879598796987979879898799988009880198802988039880498805988069880798808988099881098811988129881398814988159881698817988189881998820988219882298823988249882598826988279882898829988309883198832988339883498835988369883798838988399884098841988429884398844988459884698847988489884998850988519885298853988549885598856988579885898859988609886198862988639886498865988669886798868988699887098871988729887398874988759887698877988789887998880988819888298883988849888598886988879888898889988909889198892988939889498895988969889798898988999890098901989029890398904989059890698907989089890998910989119891298913989149891598916989179891898919989209892198922989239892498925989269892798928989299893098931989329893398934989359893698937989389893998940989419894298943989449894598946989479894898949989509895198952989539895498955989569895798958989599896098961989629896398964989659896698967989689896998970989719897298973989749897598976989779897898979989809898198982989839898498985989869898798988989899899098991989929899398994989959899698997989989899999000990019900299003990049900599006990079900899009990109901199012990139901499015990169901799018990199902099021990229902399024990259902699027990289902999030990319903299033990349903599036990379903899039990409904199042990439904499045990469904799048990499905099051990529905399054990559905699057990589905999060990619906299063990649906599066990679906899069990709907199072990739907499075990769907799078990799908099081990829908399084990859908699087990889908999090990919909299093990949909599096990979909899099991009910199102991039910499105991069910799108991099911099111991129911399114991159911699117991189911999120991219912299123991249912599126991279912899129991309913199132991339913499135991369913799138991399914099141991429914399144991459914699147991489914999150991519915299153991549915599156991579915899159991609916199162991639916499165991669916799168991699917099171991729917399174991759917699177991789917999180991819918299183991849918599186991879918899189991909919199192991939919499195991969919799198991999920099201992029920399204992059920699207992089920999210992119921299213992149921599216992179921899219992209922199222992239922499225992269922799228992299923099231992329923399234992359923699237992389923999240992419924299243992449924599246992479924899249992509925199252992539925499255992569925799258992599926099261992629926399264992659926699267992689926999270992719927299273992749927599276992779927899279992809928199282992839928499285992869928799288992899929099291992929929399294992959929699297992989929999300993019930299303993049930599306993079930899309993109931199312993139931499315993169931799318993199932099321993229932399324993259932699327993289932999330993319933299333993349933599336993379933899339993409934199342993439934499345993469934799348993499935099351993529935399354993559935699357993589935999360993619936299363993649936599366993679936899369993709937199372993739937499375993769937799378993799938099381993829938399384993859938699387993889938999390993919939299393993949939599396993979939899399994009940199402994039940499405994069940799408994099941099411994129941399414994159941699417994189941999420994219942299423994249942599426994279942899429994309943199432994339943499435994369943799438994399944099441994429944399444994459944699447994489944999450994519945299453994549945599456994579945899459994609946199462994639946499465994669946799468994699947099471994729947399474994759947699477994789947999480994819948299483994849948599486994879948899489994909949199492994939949499495994969949799498994999950099501995029950399504995059950699507995089950999510995119951299513995149951599516995179951899519995209952199522995239952499525995269952799528995299953099531995329953399534995359953699537995389953999540995419954299543995449954599546995479954899549995509955199552995539955499555995569955799558995599956099561995629956399564995659956699567995689956999570995719957299573995749957599576995779957899579995809958199582995839958499585995869958799588995899959099591995929959399594995959959699597995989959999600996019960299603996049960599606996079960899609996109961199612996139961499615996169961799618996199962099621996229962399624996259962699627996289962999630996319963299633996349963599636996379963899639996409964199642996439964499645996469964799648996499965099651996529965399654996559965699657996589965999660996619966299663996649966599666996679966899669996709967199672996739967499675996769967799678996799968099681996829968399684996859968699687996889968999690996919969299693996949969599696996979969899699997009970199702997039970499705997069970799708997099971099711997129971399714997159971699717997189971999720997219972299723997249972599726997279972899729997309973199732997339973499735997369973799738997399974099741997429974399744997459974699747997489974999750997519975299753997549975599756997579975899759997609976199762997639976499765997669976799768997699977099771997729977399774997759977699777997789977999780997819978299783997849978599786997879978899789997909979199792997939979499795997969979799798997999980099801998029980399804998059980699807998089980999810998119981299813998149981599816998179981899819998209982199822998239982499825998269982799828998299983099831998329983399834998359983699837998389983999840998419984299843998449984599846998479984899849998509985199852998539985499855998569985799858998599986099861998629986399864998659986699867998689986999870998719987299873998749987599876998779987899879998809988199882998839988499885998869988799888998899989099891998929989399894998959989699897998989989999900999019990299903999049990599906999079990899909999109991199912999139991499915999169991799918999199992099921999229992399924999259992699927999289992999930999319993299933999349993599936999379993899939999409994199942999439994499945999469994799948999499995099951999529995399954999559995699957999589995999960999619996299963999649996599966999679996899969999709997199972999739997499975999769997799978999799998099981999829998399984999859998699987999889998999990999919999299993999949999599996999979999899999100000100001100002100003100004100005100006100007100008100009100010100011100012100013100014100015100016100017100018100019100020100021100022100023100024100025100026100027100028100029100030100031100032100033100034100035100036100037100038100039100040100041100042100043100044100045100046100047100048100049100050100051100052100053100054100055100056100057100058100059100060100061100062100063100064100065100066100067100068100069100070100071100072100073100074100075100076100077100078100079100080100081100082100083100084100085100086100087100088100089100090100091100092100093100094100095100096100097100098100099100100100101100102100103100104100105100106100107100108100109100110100111100112100113100114100115100116100117100118100119100120100121100122100123100124100125100126100127100128100129100130100131100132100133100134100135100136100137100138100139100140100141100142100143100144100145100146100147100148100149100150100151100152100153100154100155100156100157100158100159100160100161100162100163100164100165100166100167100168100169100170100171100172100173100174100175100176100177100178100179100180100181100182100183100184100185100186100187100188100189100190100191100192100193100194100195100196100197100198100199100200100201100202100203100204100205100206100207100208100209100210100211100212100213100214100215100216100217100218100219100220100221100222100223100224100225100226100227100228100229100230100231100232100233100234100235100236100237100238100239100240100241100242100243100244100245100246100247100248100249100250100251100252100253100254100255100256100257100258100259100260100261100262100263100264100265100266100267100268100269100270100271100272100273100274100275100276100277100278100279100280100281100282100283100284100285100286100287100288100289100290100291100292100293100294100295100296100297100298100299100300100301100302100303100304100305100306100307100308100309100310100311100312100313100314100315100316100317100318100319100320100321100322100323100324100325100326100327100328100329100330100331100332100333100334100335100336100337100338100339100340100341100342100343100344100345100346100347100348100349100350100351100352100353100354100355100356100357100358100359100360100361100362100363100364100365100366100367100368100369100370100371100372100373100374100375100376100377100378100379100380100381100382100383100384100385100386100387100388100389100390100391100392100393100394100395100396100397100398100399100400100401100402100403100404100405100406100407100408100409100410100411100412100413100414100415100416100417100418100419100420100421100422100423100424100425100426100427100428100429100430100431100432100433100434100435100436100437100438100439100440100441100442100443100444100445100446100447100448100449100450100451100452100453100454100455100456100457100458100459100460100461100462100463100464100465100466100467100468100469100470100471100472100473100474100475100476100477100478100479100480100481100482100483100484100485100486100487100488100489100490100491100492100493100494100495100496100497100498100499100500100501100502100503100504100505100506100507100508100509100510100511100512100513100514100515100516100517100518100519100520100521100522100523100524100525100526100527100528100529100530100531100532100533100534100535100536100537100538100539100540100541100542100543100544100545100546100547100548100549100550100551100552100553100554100555100556100557100558100559100560100561100562100563100564100565100566100567100568100569100570100571100572100573100574100575100576100577100578100579100580100581100582100583100584100585100586100587100588100589100590100591100592100593100594100595100596100597100598100599100600100601100602100603100604100605100606100607100608100609100610100611100612100613100614100615100616100617100618100619100620100621100622100623100624100625100626100627100628100629100630100631100632100633100634100635100636100637100638100639100640100641100642100643100644100645100646100647100648100649100650100651100652100653100654100655100656100657100658100659100660100661100662100663100664100665100666100667100668100669100670100671100672100673100674100675100676100677100678100679100680100681100682100683100684100685100686100687100688100689100690100691100692100693100694100695100696100697100698100699100700100701100702100703100704100705100706100707100708100709100710100711100712100713100714100715100716100717100718100719100720100721100722100723100724100725100726100727100728100729100730100731100732100733100734100735100736100737100738100739100740100741100742100743100744100745100746100747100748100749100750100751100752100753100754100755100756100757100758100759100760100761100762100763100764100765100766100767100768100769100770100771100772100773100774100775100776100777100778100779100780100781100782100783100784100785100786100787100788100789100790100791100792100793100794100795100796100797100798100799100800100801100802100803100804100805100806100807100808100809100810100811100812100813100814100815100816100817100818100819100820100821100822100823100824100825100826100827100828100829100830100831100832100833100834100835100836100837100838100839100840100841100842100843100844100845100846100847100848100849100850100851100852100853100854100855100856100857100858100859100860100861100862100863100864100865100866100867100868100869100870100871100872100873100874100875100876100877100878100879100880100881100882100883100884100885100886100887100888100889100890100891100892100893100894100895100896100897100898100899100900100901100902100903100904100905100906100907100908100909100910100911100912100913100914100915100916100917100918100919100920100921100922100923100924100925100926100927100928100929100930100931100932100933100934100935100936100937100938100939100940100941100942100943100944100945100946100947100948100949100950100951100952100953100954100955100956100957100958100959100960100961100962100963100964100965100966100967100968100969100970100971100972100973100974100975100976100977100978100979100980100981100982100983100984100985100986100987100988100989100990100991100992100993100994100995100996100997100998100999101000101001101002101003101004101005101006101007101008101009101010101011101012101013101014101015101016101017101018101019101020101021101022101023101024101025101026101027101028101029101030101031101032101033101034101035101036101037101038101039101040101041101042101043101044101045101046101047101048101049101050101051101052101053101054101055101056101057101058101059101060101061101062101063101064101065101066101067101068101069101070101071101072101073101074101075101076101077101078101079101080101081101082101083101084101085101086101087101088101089101090101091101092101093101094101095101096101097101098101099101100101101101102101103101104101105101106101107101108101109101110101111101112101113101114101115101116101117101118101119101120101121101122101123101124101125101126101127101128101129101130101131101132101133101134101135101136101137101138101139101140101141101142101143101144101145101146101147101148101149101150101151101152101153101154101155101156101157101158101159101160101161101162101163101164101165101166101167101168101169101170101171101172101173101174101175101176101177101178101179101180101181101182101183101184101185101186101187101188101189101190101191101192101193101194101195101196101197101198101199101200101201101202101203101204101205101206101207101208101209101210101211101212101213101214101215101216101217101218101219101220101221101222101223101224101225101226101227101228101229101230101231101232101233101234101235101236101237101238101239101240101241101242101243101244101245101246101247101248101249101250101251101252101253101254101255101256101257101258101259101260101261101262101263101264101265101266101267101268101269101270101271101272101273101274101275101276101277101278101279101280101281101282101283101284101285101286101287101288101289101290101291101292101293101294101295101296101297101298101299101300101301101302101303101304101305101306101307101308101309101310101311101312101313101314101315101316101317101318101319101320101321101322101323101324101325101326101327101328101329101330101331101332101333101334101335101336101337101338101339101340101341101342101343101344101345101346101347101348101349101350101351101352101353101354101355101356101357101358101359101360101361101362101363101364101365101366101367101368101369101370101371101372101373101374101375101376101377101378101379101380101381101382101383101384101385101386101387101388101389101390101391101392101393101394101395101396101397101398101399101400101401101402101403101404101405101406101407101408101409101410101411101412101413101414101415101416101417101418101419101420101421101422101423101424101425101426101427101428101429101430101431101432101433101434101435101436101437101438101439101440101441101442101443101444101445101446101447101448101449101450101451101452101453101454101455101456101457101458101459101460101461101462101463101464101465101466101467101468101469101470101471101472101473101474101475101476101477101478101479101480101481101482101483101484101485101486101487101488101489101490101491101492101493101494101495101496101497101498101499101500101501101502101503101504101505101506101507101508101509101510101511101512101513101514101515101516101517101518101519101520101521101522101523101524101525101526101527101528101529101530101531101532101533101534101535101536101537101538101539101540101541101542101543101544101545101546101547101548101549101550101551101552101553101554101555101556101557101558101559101560101561101562101563101564101565101566101567101568101569101570101571101572101573101574101575101576101577101578101579101580101581101582101583101584101585101586101587101588101589101590101591101592101593101594101595101596101597101598101599101600101601101602101603101604101605101606101607101608101609101610101611101612101613101614101615101616101617101618101619101620101621101622101623101624101625101626101627101628101629101630101631101632101633101634101635101636101637101638101639101640101641101642101643101644101645101646101647101648101649101650101651101652101653101654101655101656101657101658101659101660101661101662101663101664101665101666101667101668101669101670101671101672101673101674101675101676101677101678101679101680101681101682101683101684101685101686101687101688101689101690101691101692101693101694101695101696101697101698101699101700101701101702101703101704101705101706101707101708101709101710101711101712101713101714101715101716101717101718101719101720101721101722101723101724101725101726101727101728101729101730101731101732101733101734101735101736101737101738101739101740101741101742101743101744101745101746101747101748101749101750101751101752101753101754101755101756101757101758101759101760101761101762101763101764101765101766101767101768101769101770101771101772101773101774101775101776101777101778101779101780101781101782101783101784101785101786101787101788101789101790101791101792101793101794101795101796101797101798101799101800101801101802101803101804101805101806101807101808101809101810101811101812101813101814101815101816101817101818101819101820101821101822101823101824101825101826101827101828101829101830101831101832101833101834101835101836101837101838101839101840101841101842101843101844101845101846101847101848101849101850101851101852101853101854101855101856101857101858101859101860101861101862101863101864101865101866101867101868101869101870101871101872101873101874101875101876101877101878101879101880101881101882101883101884101885101886101887101888101889101890101891101892101893101894101895101896101897101898101899101900101901101902101903101904101905101906101907101908101909101910101911101912101913101914101915101916101917101918101919101920101921101922101923101924101925101926101927101928101929101930101931101932101933101934101935101936101937101938101939101940101941101942101943101944101945101946101947101948101949101950101951101952101953101954101955101956101957101958101959101960101961101962101963101964101965101966101967101968101969101970101971101972101973101974101975101976101977101978101979101980101981101982101983101984101985101986101987101988101989101990101991101992101993101994101995101996101997101998101999102000102001102002102003102004102005102006102007102008102009102010102011102012102013102014102015102016102017102018102019102020102021102022102023102024102025102026102027102028102029102030102031102032102033102034102035102036102037102038102039102040102041102042102043102044102045102046102047102048102049102050102051102052102053102054102055102056102057102058102059102060102061102062102063102064102065102066102067102068102069102070102071102072102073102074102075102076102077102078102079102080102081102082102083102084102085102086102087102088102089102090102091102092102093102094102095102096102097102098102099102100102101102102102103102104102105102106102107102108102109102110102111102112102113102114102115102116102117102118102119102120102121102122102123102124102125102126102127102128102129102130102131102132102133102134102135102136102137102138102139102140102141102142102143102144102145102146102147102148102149102150102151102152102153102154102155102156102157102158102159102160102161102162102163102164102165102166102167102168102169102170102171102172102173102174102175102176102177102178102179102180102181102182102183102184102185102186102187102188102189102190102191102192102193102194102195102196102197102198102199102200102201102202102203102204102205102206102207102208102209102210102211102212102213102214102215102216102217102218102219102220102221102222102223102224102225102226102227102228102229102230102231102232102233102234102235102236102237102238102239102240102241102242102243102244102245102246102247102248102249102250102251102252102253102254102255102256102257102258102259102260102261102262102263102264102265102266102267102268102269102270102271102272102273102274102275102276102277102278102279102280102281102282102283102284102285102286102287102288102289102290102291102292102293102294102295102296102297102298102299102300102301102302102303102304102305102306102307102308102309102310102311102312102313102314102315102316102317102318102319102320102321102322102323102324102325102326102327102328102329102330102331102332102333102334102335102336102337102338102339102340102341102342102343102344102345102346102347102348102349102350102351102352102353102354102355102356102357102358102359102360102361102362102363102364102365102366102367102368102369102370102371102372102373102374102375102376102377102378102379102380102381102382102383102384102385102386102387102388102389102390102391102392102393102394102395102396102397102398102399102400102401102402102403102404102405102406102407102408102409102410102411102412102413102414102415102416102417102418102419102420102421102422102423102424102425102426102427102428102429102430102431102432102433102434102435102436102437102438102439102440102441102442102443102444102445102446102447102448102449102450102451102452102453102454102455102456102457102458102459102460102461102462102463102464102465102466102467102468102469102470102471102472102473102474102475102476102477102478102479102480102481102482102483102484102485102486102487102488102489102490102491102492102493102494102495102496102497102498102499102500102501102502102503102504102505102506102507102508102509102510102511102512102513102514102515102516102517102518102519102520102521102522102523102524102525102526102527102528102529102530102531102532102533102534102535102536102537102538102539102540102541102542102543102544102545102546102547102548102549102550102551102552102553102554102555102556102557102558102559102560102561102562102563102564102565102566102567102568102569102570102571102572102573102574102575102576102577102578102579102580102581102582102583102584102585102586102587102588102589102590102591102592102593102594102595102596102597102598102599102600102601102602102603102604102605102606102607102608102609102610102611102612102613102614102615102616102617102618102619102620102621102622102623102624102625102626102627102628102629102630102631102632102633102634102635102636102637102638102639102640102641102642102643102644102645102646102647102648102649102650102651102652102653102654102655102656102657102658102659102660102661102662102663102664102665102666102667102668102669102670102671102672102673102674102675102676102677102678102679102680102681102682102683102684102685102686102687102688102689102690102691102692102693102694102695102696102697102698102699102700102701102702102703102704102705102706102707102708102709102710102711102712102713102714102715102716102717102718102719102720102721102722102723102724102725102726102727102728102729102730102731102732102733102734102735102736102737102738102739102740102741102742102743102744102745102746102747102748102749102750102751102752102753102754102755102756102757102758102759102760102761102762102763102764102765102766102767102768102769102770102771102772102773102774102775102776102777102778102779102780102781102782102783102784102785102786102787102788102789102790102791102792102793102794102795102796102797102798102799102800102801102802102803102804102805102806102807102808102809102810102811102812102813102814102815102816102817102818102819102820102821102822102823102824102825102826102827102828102829102830102831102832102833102834102835102836102837102838102839102840102841102842102843102844102845102846102847102848102849102850102851102852102853102854102855102856102857102858102859102860102861102862102863102864102865102866102867102868102869102870102871102872102873102874102875102876102877102878102879102880102881102882102883102884102885102886102887102888102889102890102891102892102893102894102895102896102897102898102899102900102901102902102903102904102905102906102907102908102909102910102911102912102913102914102915102916102917102918102919102920102921102922102923102924102925102926102927102928102929102930102931102932102933102934102935102936102937102938102939102940102941102942102943102944102945102946102947102948102949102950102951102952102953102954102955102956102957102958102959102960102961102962102963102964102965102966102967102968102969102970102971102972102973102974102975102976102977102978102979102980102981102982102983102984102985102986102987102988102989102990102991102992102993102994102995102996102997102998102999103000103001103002103003103004103005103006103007103008103009103010103011103012103013103014103015103016103017103018103019103020103021103022103023103024103025103026103027103028103029103030103031103032103033103034103035103036103037103038103039103040103041103042103043103044103045103046103047103048103049103050103051103052103053103054103055103056103057103058103059103060103061103062103063103064103065103066103067103068103069103070103071103072103073103074103075103076103077103078103079103080103081103082103083103084103085103086103087103088103089103090103091103092103093103094103095103096103097103098103099103100103101103102103103103104103105103106103107103108103109103110103111103112103113103114103115103116103117103118103119103120103121103122103123103124103125103126103127103128103129103130103131103132103133103134103135103136103137103138103139103140103141103142103143103144103145103146103147103148103149103150103151103152103153103154103155103156103157103158103159103160103161103162103163103164103165103166103167103168103169103170103171103172103173103174103175103176103177103178103179103180103181103182103183103184103185103186103187103188103189103190103191103192103193103194103195103196103197103198103199103200103201103202103203103204103205103206103207103208103209103210103211103212103213103214103215103216103217103218103219103220103221103222103223103224103225103226103227103228103229103230103231103232103233103234103235103236103237103238103239103240103241103242103243103244103245103246103247103248103249103250103251103252103253103254103255103256103257103258103259103260103261103262103263103264103265103266103267103268103269103270103271103272103273103274103275103276103277103278103279103280103281103282103283103284103285103286103287103288103289103290103291103292103293103294103295103296103297103298103299103300103301103302103303103304103305103306103307103308103309103310103311103312103313103314103315103316103317103318103319103320103321103322103323103324103325103326103327103328103329103330103331103332103333103334103335103336103337103338103339103340103341103342103343103344103345103346103347103348103349103350103351103352103353103354103355103356103357103358103359103360103361103362103363103364103365103366103367103368103369103370103371103372103373103374103375103376103377103378103379103380103381103382103383103384103385103386103387103388103389103390103391103392103393103394103395103396103397103398103399103400103401103402103403103404103405103406103407103408103409103410103411103412103413103414103415103416103417103418103419103420103421103422103423103424103425103426103427103428103429103430103431103432103433103434103435103436103437103438103439103440103441103442103443103444103445103446103447103448103449103450103451103452103453103454103455103456103457103458103459103460103461103462103463103464103465103466103467103468103469103470103471103472103473103474103475103476103477103478103479103480103481103482103483103484103485103486103487103488103489103490103491103492103493103494103495103496103497103498103499103500103501103502103503103504103505103506103507103508103509103510103511103512103513103514103515103516103517103518103519103520103521103522103523103524103525103526103527103528103529103530103531103532103533103534103535103536103537103538103539103540103541103542103543103544103545103546103547103548103549103550103551103552103553103554103555103556103557103558103559103560103561103562103563103564103565103566103567103568103569103570103571103572103573103574103575103576103577103578103579103580103581103582103583103584103585103586103587103588103589103590103591103592103593103594103595103596103597103598103599103600103601103602103603103604103605103606103607103608103609103610103611103612103613103614103615103616103617103618103619103620103621103622103623103624103625103626103627103628103629103630103631103632103633103634103635103636103637103638103639103640103641103642103643103644103645103646103647103648103649103650103651103652103653103654103655103656103657103658103659103660103661103662103663103664103665103666103667103668103669103670103671103672103673103674103675103676103677103678103679103680103681103682103683103684103685103686103687103688103689103690103691103692103693103694103695103696103697103698103699103700103701103702103703103704103705103706103707103708103709103710103711103712103713103714103715103716103717103718103719103720103721103722103723103724103725103726103727103728103729103730103731103732103733103734103735103736103737103738103739103740103741103742103743103744103745103746103747103748103749103750103751103752103753103754103755103756103757103758103759103760103761103762103763103764103765103766103767103768103769103770103771103772103773103774103775103776103777103778103779103780103781103782103783103784103785103786103787103788103789103790103791103792103793103794103795103796103797103798103799103800103801103802103803103804103805103806103807103808103809103810103811103812103813103814103815103816103817103818103819103820103821103822103823103824103825103826103827103828103829103830103831103832103833103834103835103836103837103838103839103840103841103842103843103844103845103846103847103848103849103850103851103852103853103854103855103856103857103858103859103860103861103862103863103864103865103866103867103868103869103870103871103872103873103874103875103876103877103878103879103880103881103882103883103884103885103886103887103888103889103890103891103892103893103894103895103896103897103898103899103900103901103902103903103904103905103906103907103908103909103910103911103912103913103914103915103916103917103918103919103920103921103922103923103924103925103926103927103928103929103930103931103932103933103934103935103936103937103938103939103940103941103942103943103944103945103946103947103948103949103950103951103952103953103954103955103956103957103958103959103960103961103962103963103964103965103966103967103968103969103970103971103972103973103974103975103976103977103978103979103980103981103982103983103984103985103986103987103988103989103990103991103992103993103994103995103996103997103998103999104000104001104002104003104004104005104006104007104008104009104010104011104012104013104014104015104016104017104018104019104020104021104022104023104024104025104026104027104028104029104030104031104032104033104034104035104036104037104038104039104040104041104042104043104044104045104046104047104048104049104050104051104052104053104054104055104056104057104058104059104060104061104062104063104064104065104066104067104068104069104070104071104072104073104074104075104076104077104078104079104080104081104082104083104084104085104086104087104088104089104090104091104092104093104094104095104096104097104098104099104100104101104102104103104104104105104106104107104108104109104110104111104112104113104114104115104116104117104118104119104120104121104122104123104124104125104126104127104128104129104130104131104132104133104134104135104136104137104138104139104140104141104142104143104144104145104146104147104148104149104150104151104152104153104154104155104156104157104158104159104160104161104162104163104164104165104166104167104168104169104170104171104172104173104174104175104176104177104178104179104180104181104182104183104184104185104186104187104188104189104190104191104192104193104194104195104196104197104198104199104200104201104202104203104204104205104206104207104208104209104210104211104212104213104214104215104216104217104218104219104220104221104222104223104224104225104226104227104228104229104230104231104232104233104234104235104236104237104238104239104240104241104242104243104244104245104246104247104248104249104250104251104252104253104254104255104256104257104258104259104260104261104262104263104264104265104266104267104268104269104270104271104272104273104274104275104276104277104278104279104280104281104282104283104284104285104286104287104288104289104290104291104292104293104294104295104296104297104298104299104300104301104302104303104304104305104306104307104308104309104310104311104312104313104314104315104316104317104318104319104320104321104322104323104324104325104326104327104328104329104330104331104332104333104334104335104336104337104338104339104340104341104342104343104344104345104346104347104348104349104350104351104352104353104354104355104356104357104358104359104360104361104362104363104364104365104366104367104368104369104370104371104372104373104374104375104376104377104378104379104380104381104382104383104384104385104386104387104388104389104390104391104392104393104394104395104396104397104398104399104400104401104402104403104404104405104406104407104408104409104410104411104412104413104414104415104416104417104418104419104420104421104422104423104424104425104426104427104428104429104430104431104432104433104434104435104436104437104438104439104440104441104442104443104444104445104446104447104448104449104450104451104452104453104454104455104456104457104458104459104460104461104462104463104464104465104466104467104468104469104470104471104472104473104474104475104476104477104478104479104480104481104482104483104484104485104486104487104488104489104490104491104492104493104494104495104496104497104498104499104500104501104502104503104504104505104506104507104508104509104510104511104512104513104514104515104516104517104518104519104520104521104522104523104524104525104526104527104528104529104530104531104532104533104534104535104536104537104538104539104540104541104542104543104544104545104546104547104548104549104550104551104552104553104554104555104556104557104558104559104560104561104562104563104564104565104566104567104568104569104570104571104572104573104574104575104576104577104578104579104580104581104582104583104584104585104586104587104588104589104590104591104592104593104594104595104596104597104598104599104600104601104602104603104604104605104606104607104608104609104610104611104612104613104614104615104616104617104618104619104620104621104622104623104624104625104626104627104628104629104630104631104632104633104634104635104636104637104638104639104640104641104642104643104644104645104646104647104648104649104650104651104652104653104654104655104656104657104658104659104660104661104662104663104664104665104666104667104668104669104670104671104672104673104674104675104676104677104678104679104680104681104682104683104684104685104686104687104688104689104690104691104692104693104694104695104696104697104698104699104700104701104702104703104704104705104706104707104708104709104710104711104712104713104714104715104716104717104718104719104720104721104722104723104724104725104726104727104728104729104730104731104732104733104734104735104736104737104738104739104740104741104742104743104744104745104746104747104748104749104750104751104752104753104754104755104756104757104758104759104760104761104762104763104764104765104766104767104768104769104770104771104772104773104774104775104776104777104778104779104780104781104782104783104784104785104786104787104788104789104790104791104792104793104794104795104796104797104798104799104800104801104802104803104804104805104806104807104808104809104810104811104812104813104814104815104816104817104818104819104820104821104822104823104824104825104826104827104828104829104830104831104832104833104834104835104836104837104838104839104840104841104842104843104844104845104846104847104848104849104850104851104852104853104854104855104856104857104858104859104860104861104862104863104864104865104866104867104868104869104870104871104872104873104874104875104876104877104878104879104880104881104882104883104884104885104886104887104888104889104890104891104892104893104894104895104896104897104898104899104900104901104902104903104904104905104906104907104908104909104910104911104912104913104914104915104916104917104918104919104920104921104922104923104924104925104926104927104928104929104930104931104932104933104934104935104936104937104938104939104940104941104942104943104944104945104946104947104948104949104950104951104952104953104954104955104956104957104958104959104960104961104962104963104964104965104966104967104968104969104970104971104972104973104974104975104976104977104978104979104980104981104982104983104984104985104986104987104988104989104990104991104992104993104994104995104996104997104998104999105000105001105002105003105004105005105006105007105008105009105010105011105012105013105014105015105016105017105018105019105020105021105022105023105024105025105026105027105028105029105030105031105032105033105034105035105036105037105038105039105040105041105042105043105044105045105046105047105048105049105050105051105052105053105054105055105056105057105058105059105060105061105062105063105064105065105066105067105068105069105070105071105072105073105074105075105076105077105078105079105080105081105082105083105084105085105086105087105088105089105090105091105092105093105094105095105096105097105098105099105100105101105102105103105104105105105106105107105108105109105110105111105112105113105114105115105116105117105118105119105120105121105122105123105124105125105126105127105128105129105130105131105132105133105134105135105136105137105138105139105140105141105142105143105144105145105146105147105148105149105150105151105152105153105154105155105156105157105158105159105160105161105162105163105164105165105166105167105168105169105170105171105172105173105174105175105176105177105178105179105180105181105182105183105184105185105186105187105188105189105190105191105192105193105194105195105196105197105198105199105200105201105202105203105204105205105206105207105208105209105210105211105212105213105214105215105216105217105218105219105220105221105222105223105224105225105226105227105228105229105230105231105232105233105234105235105236105237105238105239105240105241105242105243105244105245105246105247105248105249105250105251105252105253105254105255105256105257105258105259105260105261105262105263105264105265105266105267105268105269105270105271105272105273105274105275105276105277105278105279105280105281105282105283105284105285105286105287105288105289105290105291105292105293105294105295105296105297105298105299105300105301105302105303105304105305105306105307105308105309105310105311105312105313105314105315105316105317105318105319105320105321105322105323105324105325105326105327105328105329105330105331105332105333105334105335105336105337105338105339105340105341105342105343105344105345105346105347105348105349105350105351105352105353105354105355105356105357105358105359105360105361105362105363105364105365105366105367105368105369105370105371105372105373105374105375105376105377105378105379105380105381105382105383105384105385105386105387105388105389105390105391105392105393105394105395105396105397105398105399105400105401105402105403105404105405105406105407105408105409105410105411105412105413105414105415105416105417105418105419105420105421105422105423105424105425105426105427105428105429105430105431105432105433105434105435105436105437105438105439105440105441105442105443105444105445105446105447105448105449105450105451105452105453105454105455105456105457105458105459105460105461105462105463105464105465105466105467105468105469105470105471105472105473105474105475105476105477105478105479105480105481105482105483105484105485105486105487105488105489105490105491105492105493105494105495105496105497105498105499105500105501105502105503105504105505105506105507105508105509105510105511105512105513105514105515105516105517105518105519105520105521105522105523105524105525105526105527105528105529105530105531105532105533105534105535105536105537105538105539105540105541105542105543105544105545105546105547105548105549105550105551105552105553105554105555105556105557105558105559105560105561105562105563105564105565105566105567105568105569105570105571105572105573105574105575105576105577105578105579105580105581105582105583105584105585105586105587105588105589105590105591105592105593105594105595105596105597105598105599105600105601105602105603105604105605105606105607105608105609105610105611105612105613105614105615105616105617105618105619105620105621105622105623105624105625105626105627105628105629105630105631105632105633105634105635105636105637105638105639105640105641105642105643105644105645105646105647105648105649105650105651105652105653105654105655105656105657105658105659105660105661105662105663105664105665105666105667105668105669105670105671105672105673105674105675105676105677105678105679105680105681105682105683105684105685105686105687105688105689105690105691105692105693105694105695105696105697105698105699105700105701105702105703105704105705105706105707105708105709105710105711105712105713105714105715105716105717105718105719105720105721105722105723105724105725105726105727105728105729105730105731105732105733105734105735105736105737105738105739105740105741105742105743105744105745105746105747105748105749105750105751105752105753105754105755105756105757105758105759105760105761105762105763105764105765105766105767105768105769105770105771105772105773105774105775105776105777105778105779105780105781105782105783105784105785105786105787105788105789105790105791105792105793105794105795105796105797105798105799105800105801105802105803105804105805105806105807105808105809105810105811105812105813105814105815105816105817105818105819105820105821105822105823105824105825105826105827105828105829105830105831105832105833105834105835105836105837105838105839105840105841105842105843105844105845105846105847105848105849105850105851105852105853105854105855105856105857105858105859105860105861105862105863105864105865105866105867105868105869105870105871105872105873105874105875105876105877105878105879105880105881105882105883105884105885105886105887105888105889105890105891105892105893105894105895105896105897105898105899105900105901105902105903105904105905105906105907105908105909105910105911105912105913105914105915105916105917105918105919105920105921105922105923105924105925105926105927105928105929105930105931105932105933105934105935105936105937105938105939105940105941105942105943105944105945105946105947105948105949105950105951105952105953105954105955105956105957105958105959105960105961105962105963105964105965105966105967105968105969105970105971105972105973105974105975105976105977105978105979105980105981105982105983105984105985105986105987105988105989105990105991105992105993105994105995105996105997105998105999106000106001106002106003106004106005106006106007106008106009106010106011106012106013106014106015106016106017106018106019106020106021106022106023106024106025106026106027106028106029106030106031106032106033106034106035106036106037106038106039106040106041106042106043106044106045106046106047106048106049106050106051106052106053106054106055106056106057106058106059106060106061106062106063106064106065106066106067106068106069106070106071106072106073106074106075106076106077106078106079106080106081106082106083106084106085106086106087106088106089106090106091106092106093106094106095106096106097106098106099106100106101106102106103106104106105106106106107106108106109106110106111106112106113106114106115106116106117106118106119106120106121106122106123106124106125106126106127106128106129106130106131106132106133106134106135106136106137106138106139106140106141106142106143106144106145106146106147106148106149106150106151106152106153106154106155106156106157106158106159106160106161106162106163106164106165106166106167106168106169106170106171106172106173106174106175106176106177106178106179106180106181106182106183106184106185106186106187106188106189106190106191106192106193106194106195106196106197106198106199106200106201106202106203106204106205106206106207106208106209106210106211106212106213106214106215106216106217106218106219106220106221106222106223106224106225106226106227106228106229106230106231106232106233106234106235106236106237106238106239106240106241106242106243106244106245106246106247106248106249106250106251106252106253106254106255106256106257106258106259106260106261106262106263106264106265106266106267106268106269106270106271106272106273106274106275106276106277106278106279106280106281106282106283106284106285106286106287106288106289106290106291106292106293106294106295106296106297106298106299106300106301106302106303106304106305106306106307106308106309106310106311106312106313106314106315106316106317106318106319106320106321106322106323106324106325106326106327106328106329106330106331106332106333106334106335106336106337106338106339106340106341106342106343106344106345106346106347106348106349106350106351106352106353106354106355106356106357106358106359106360106361106362106363106364106365106366106367106368106369106370106371106372106373106374106375106376106377106378106379106380106381106382106383106384106385106386106387106388106389106390106391106392106393106394106395106396106397106398106399106400106401106402106403106404106405106406106407106408106409106410106411106412106413106414106415106416106417106418106419106420106421106422106423106424106425106426106427106428106429106430106431106432106433106434106435106436106437106438106439106440106441106442106443106444106445106446106447106448106449106450106451106452106453106454106455106456106457106458106459106460106461106462106463106464106465106466106467106468106469106470106471106472106473106474106475106476106477106478106479106480106481106482106483106484106485106486106487106488106489106490106491106492106493106494106495106496106497106498106499106500106501106502106503106504106505106506106507106508106509106510106511106512106513106514106515106516106517106518106519106520106521106522106523106524106525106526106527106528106529106530106531106532106533106534106535106536106537106538106539106540106541106542106543106544106545106546106547106548106549106550106551106552106553106554106555106556106557106558106559106560106561106562106563106564106565106566106567106568106569106570106571106572106573106574106575106576106577106578106579106580106581106582106583106584106585106586106587106588106589106590106591106592106593106594106595106596106597106598106599106600106601106602106603106604106605106606106607106608106609106610106611106612106613106614106615106616106617106618106619106620106621106622106623106624106625106626106627106628106629106630106631106632106633106634106635106636106637106638106639106640106641106642106643106644106645106646106647106648106649106650106651106652106653106654106655106656106657106658106659106660106661106662106663106664106665106666106667106668106669106670106671106672106673106674106675106676106677106678106679106680106681106682106683106684106685106686106687106688106689106690106691106692106693106694106695106696106697106698106699106700106701106702106703106704106705106706106707106708106709106710106711106712106713106714106715106716106717106718106719106720106721106722106723106724106725106726106727106728106729106730106731106732106733106734106735106736106737106738106739106740106741106742106743106744106745106746106747106748106749106750106751106752106753106754106755106756106757106758106759106760106761106762106763106764106765106766106767106768106769106770106771106772106773106774106775106776106777106778106779106780106781106782106783106784106785106786106787106788106789106790106791106792106793106794106795106796106797106798106799106800106801106802106803106804106805106806106807106808106809106810106811106812106813106814106815106816106817106818106819106820106821106822106823106824106825106826106827106828106829106830106831106832106833106834106835106836106837106838106839106840106841106842106843106844106845106846106847106848106849106850106851106852106853106854106855106856106857106858106859106860106861106862106863106864106865106866106867106868106869106870106871106872106873106874106875106876106877106878106879106880106881106882106883106884106885106886106887106888106889106890106891106892106893106894106895106896106897106898106899106900106901106902106903106904106905106906106907106908106909106910106911106912106913106914106915106916106917106918106919106920106921106922106923106924106925106926106927106928106929106930106931106932106933106934106935106936106937106938106939106940106941106942106943106944106945106946106947106948106949106950106951106952106953106954106955106956106957106958106959106960106961106962106963106964106965106966106967106968106969106970106971106972106973106974106975106976106977106978106979106980106981106982106983106984106985106986106987106988106989106990106991106992106993106994106995106996106997106998106999107000107001107002107003107004107005107006107007107008107009107010107011107012107013107014107015107016107017107018107019107020107021107022107023107024107025107026107027107028107029107030107031107032107033107034107035107036107037107038107039107040107041107042107043107044107045107046107047107048107049107050107051107052107053107054107055107056107057107058107059107060107061107062107063107064107065107066107067107068107069107070107071107072107073107074107075107076107077107078107079107080107081107082107083107084107085107086107087107088107089107090107091107092107093107094107095107096107097107098107099107100107101107102107103107104107105107106107107107108107109107110107111107112107113107114107115107116107117107118107119107120107121107122107123107124107125107126107127107128107129107130107131107132107133107134107135107136107137107138107139107140107141107142107143107144107145107146107147107148107149107150107151107152107153107154107155107156107157107158107159107160107161107162107163107164107165107166107167107168107169107170107171107172107173107174107175107176107177107178107179107180107181107182107183107184107185107186107187107188107189107190107191107192107193107194107195107196107197107198107199107200107201107202107203107204107205107206107207107208107209107210107211107212107213107214107215107216107217107218107219107220107221107222107223107224107225107226107227107228107229107230107231107232107233107234107235107236107237107238107239107240107241107242107243107244107245107246107247107248107249107250107251107252107253107254107255107256107257107258107259107260107261107262107263107264107265107266107267107268107269107270107271107272107273107274107275107276107277107278107279107280107281107282107283107284107285107286107287107288107289107290107291107292107293107294107295107296107297107298107299107300107301107302107303107304107305107306107307107308107309107310107311107312107313107314107315107316107317107318107319107320107321107322107323107324107325107326107327107328107329107330107331107332107333107334107335107336107337107338107339107340107341107342107343107344107345107346107347107348107349107350107351107352107353107354107355107356107357107358107359107360107361107362107363107364107365107366107367107368107369107370107371107372107373107374107375107376107377107378107379107380107381107382107383107384107385107386107387107388107389107390107391107392107393107394107395107396107397107398107399107400107401107402107403107404107405107406107407107408107409107410107411107412107413107414107415107416107417107418107419107420107421107422107423107424107425107426107427107428107429107430107431107432107433107434107435107436107437107438107439107440107441107442107443107444107445107446107447107448107449107450107451107452107453107454107455107456107457107458107459107460107461107462107463107464107465107466107467107468107469107470107471107472107473107474107475107476107477107478107479107480107481107482107483107484107485107486107487107488107489107490107491107492107493107494107495107496107497107498107499107500107501107502107503107504107505107506107507107508107509107510107511107512107513107514107515107516107517107518107519107520107521107522107523107524107525107526107527107528107529107530107531107532107533107534107535107536107537107538107539107540107541107542107543107544107545107546107547107548107549107550107551107552107553107554107555107556107557107558107559107560107561107562107563107564107565107566107567107568107569107570107571107572107573107574107575107576107577107578107579107580107581107582107583107584107585107586107587107588107589107590107591107592107593107594107595107596107597107598107599107600107601107602107603107604107605107606107607107608107609107610107611107612107613107614107615107616107617107618107619107620107621107622107623107624107625107626107627107628107629107630107631107632107633107634107635107636107637107638107639107640107641107642107643107644107645107646107647107648107649107650107651107652107653107654107655107656107657107658107659107660107661107662107663107664107665107666107667107668107669107670107671107672107673107674107675107676107677107678107679107680107681107682107683107684107685107686107687107688107689107690107691107692107693107694107695107696107697107698107699107700107701107702107703107704107705107706107707107708107709107710107711107712107713107714107715107716107717107718107719107720107721107722107723107724107725107726107727107728107729107730107731107732107733107734107735107736107737107738107739107740107741107742107743107744107745107746107747107748107749107750107751107752107753107754107755107756107757107758107759107760107761107762107763107764107765107766107767107768107769107770107771107772107773107774107775107776107777107778107779107780107781107782107783107784107785107786107787107788107789107790107791107792107793107794107795107796107797107798107799107800107801107802107803107804107805107806107807107808107809107810107811107812107813107814107815107816107817107818107819107820107821107822107823107824107825107826107827107828107829107830107831107832107833107834107835107836107837107838107839107840107841107842107843107844107845107846107847107848107849107850107851107852107853107854107855107856107857107858107859107860107861107862107863107864107865107866107867107868107869107870107871107872107873107874107875107876107877107878107879107880107881107882107883107884107885107886107887107888107889107890107891107892107893107894107895107896107897107898107899107900107901107902107903107904107905107906107907107908107909107910107911107912107913107914107915107916107917107918107919107920107921107922107923107924107925107926107927107928107929107930107931107932107933107934107935107936107937107938107939107940107941107942107943107944107945107946107947107948107949107950107951107952107953107954107955107956107957107958107959107960107961107962107963107964107965107966107967107968107969107970107971107972107973107974107975107976107977107978107979107980107981107982107983107984107985107986107987107988107989107990107991107992107993107994107995107996107997107998107999108000108001108002108003108004108005108006108007108008108009108010108011108012108013108014108015108016108017108018108019108020108021108022108023108024108025108026108027108028108029108030108031108032108033108034108035108036108037108038108039108040108041108042108043108044108045108046108047108048108049108050108051108052108053108054108055108056108057108058108059108060108061108062108063108064108065108066108067108068108069108070108071108072108073108074108075108076108077108078108079108080108081108082108083108084108085108086108087108088108089108090108091108092108093108094108095108096108097108098108099108100108101108102108103108104108105108106108107108108108109108110108111108112108113108114108115108116108117108118108119108120108121108122108123108124108125108126108127108128108129108130108131108132108133108134108135108136108137108138108139108140108141108142108143108144108145108146108147108148108149108150108151108152108153108154108155108156108157108158108159108160108161108162108163108164108165108166108167108168108169108170108171108172108173108174108175108176108177108178108179108180108181108182108183108184108185108186108187108188108189108190108191108192108193108194108195108196108197108198108199108200108201108202108203108204108205108206108207108208108209108210108211108212108213108214108215108216108217108218108219108220108221108222108223108224108225108226108227108228108229108230108231108232108233108234108235108236108237108238108239108240108241108242108243108244108245108246108247108248108249108250108251108252108253108254108255108256108257108258108259108260108261108262108263108264108265108266108267108268108269108270108271108272108273108274108275108276108277108278108279108280108281108282108283108284108285108286108287108288108289108290108291108292108293108294108295108296108297108298108299108300108301108302108303108304108305108306108307108308108309108310108311108312108313108314108315108316108317108318108319108320108321108322108323108324108325108326108327108328108329108330108331108332108333108334108335108336108337108338108339108340108341108342108343108344108345108346108347108348108349108350108351108352108353108354108355108356108357108358108359108360108361108362108363108364108365108366108367108368108369108370108371108372108373108374108375108376108377108378108379108380108381108382108383108384108385108386108387108388108389108390108391108392108393108394108395108396108397108398108399108400108401108402108403108404108405108406108407108408108409108410108411108412108413108414108415108416108417108418108419108420108421108422108423108424108425108426108427108428108429108430108431108432108433108434108435108436108437108438108439108440108441108442108443108444108445108446108447108448108449108450108451108452108453108454108455108456108457108458108459108460108461108462108463108464108465108466108467108468108469108470108471108472108473108474108475108476108477108478108479108480108481108482108483108484108485108486108487108488108489108490108491108492108493108494108495108496108497108498108499108500108501108502108503108504108505108506108507108508108509108510108511108512108513108514108515108516108517108518108519108520108521108522108523108524108525108526108527108528108529108530108531108532108533108534108535108536108537108538108539108540108541108542108543108544108545108546108547108548108549108550108551108552108553108554108555108556108557108558108559108560108561108562108563108564108565108566108567108568108569108570108571108572108573108574108575108576108577108578108579108580108581108582108583108584108585108586108587108588108589108590108591108592108593108594108595108596108597108598108599108600108601108602108603108604108605108606108607108608108609108610108611108612108613108614108615108616108617108618108619108620108621108622108623108624108625108626108627108628108629108630108631108632108633108634108635108636108637108638108639108640108641108642108643108644108645108646108647108648108649108650108651108652108653108654108655108656108657108658108659108660108661108662108663108664108665108666108667108668108669108670108671108672108673108674108675108676108677108678108679108680108681108682108683108684108685108686108687108688108689108690108691108692108693108694108695108696108697108698108699108700108701108702108703108704108705108706108707108708108709108710108711108712108713108714108715108716108717108718108719108720108721108722108723108724108725108726108727108728108729108730108731108732108733108734108735108736108737108738108739108740108741108742108743108744108745108746108747108748108749108750108751108752108753108754108755108756108757108758108759108760108761108762108763108764108765108766108767108768108769108770108771108772108773108774108775108776108777108778108779108780108781108782108783108784108785108786108787108788108789108790108791108792108793108794108795108796108797108798108799108800108801108802108803108804108805108806108807108808108809108810108811108812108813108814108815108816108817108818108819108820108821108822108823108824108825108826108827108828108829108830108831108832108833108834108835108836108837108838108839108840108841108842108843108844108845108846108847108848108849108850108851108852108853108854108855108856108857108858108859108860108861108862108863108864108865108866108867108868108869108870108871108872108873108874108875108876108877108878108879108880108881108882108883108884108885108886108887108888108889108890108891108892108893108894108895108896108897108898108899108900108901108902108903108904108905108906108907108908108909108910108911108912108913108914108915108916108917108918108919108920108921108922108923108924108925108926108927108928108929108930108931108932108933108934108935108936108937108938108939108940108941108942108943108944108945108946108947108948108949108950108951108952108953108954108955108956108957108958108959108960108961108962108963108964108965108966108967108968108969108970108971108972108973108974108975108976108977108978108979108980108981108982108983108984108985108986108987108988108989108990108991108992108993108994108995108996108997108998108999109000109001109002109003109004109005109006109007109008109009109010109011109012109013109014109015109016109017109018109019109020109021109022109023109024109025109026109027109028109029109030109031109032109033109034109035109036109037109038109039109040109041109042109043109044109045109046109047109048109049109050109051109052109053109054109055109056109057109058109059109060109061109062109063109064109065109066109067109068109069109070109071109072109073109074109075109076109077109078109079109080109081109082109083109084109085109086109087109088109089109090109091109092109093109094109095109096109097109098109099109100109101109102109103109104109105109106109107109108109109109110109111109112109113109114109115109116109117109118109119109120109121109122109123109124109125109126109127109128109129109130109131109132109133109134109135109136109137109138109139109140109141109142109143109144109145109146109147109148109149109150109151109152109153109154109155109156109157109158109159109160109161109162109163109164109165109166109167109168109169109170109171109172109173109174109175109176109177109178109179109180109181109182109183109184109185109186109187109188109189109190109191109192109193109194109195109196109197109198109199109200109201109202109203109204109205109206109207109208109209109210109211109212109213109214109215109216109217109218109219109220109221109222109223109224109225109226109227109228109229109230109231109232109233109234109235109236109237109238109239109240109241109242109243109244109245109246109247109248109249109250109251109252109253109254109255109256109257109258109259109260109261109262109263109264109265109266109267109268109269109270109271109272109273109274109275109276109277109278109279109280109281109282109283109284109285109286109287109288109289109290109291109292109293109294109295109296109297109298109299109300109301109302109303109304109305109306109307109308109309109310109311109312109313109314109315109316109317109318109319109320109321109322109323109324109325109326109327109328109329109330109331109332109333109334109335109336109337109338109339109340109341109342109343109344109345109346109347109348109349109350109351109352109353109354109355109356109357109358109359109360109361109362109363109364109365109366109367109368109369109370109371109372109373109374109375109376109377109378109379109380109381109382109383109384109385109386109387109388109389109390109391109392109393109394109395109396109397109398109399109400109401109402109403109404109405109406109407109408109409109410109411109412109413109414109415109416109417109418109419109420109421109422109423109424109425109426109427109428109429109430109431109432109433109434109435109436109437109438109439109440109441109442109443109444109445109446109447109448109449109450109451109452109453109454109455109456109457109458109459109460109461109462109463109464109465109466109467109468109469109470109471109472109473109474109475109476109477109478109479109480109481109482109483109484109485109486109487109488109489109490109491109492109493109494109495109496109497109498109499109500109501109502109503109504109505109506109507109508109509109510109511109512109513109514109515109516109517109518109519109520109521109522109523109524109525109526109527109528109529109530109531109532109533109534109535109536109537109538109539109540109541109542109543109544109545109546109547109548109549109550109551109552109553109554109555109556109557109558109559109560109561109562109563109564109565109566109567109568109569109570109571109572109573109574109575109576109577109578109579109580109581109582109583109584109585109586109587109588109589109590109591109592109593109594109595109596109597109598109599109600109601109602109603109604109605109606109607109608109609109610109611109612109613109614109615109616109617109618109619109620109621109622109623109624109625109626109627109628109629109630109631109632109633109634109635109636109637109638109639109640109641109642109643109644109645109646109647109648109649109650109651109652109653109654109655109656109657109658109659109660109661109662109663109664109665109666109667109668109669109670109671109672109673109674109675109676109677109678109679109680109681109682109683109684109685109686109687109688109689109690109691109692109693109694109695109696109697109698109699109700109701109702109703109704109705109706109707109708109709109710109711109712109713109714109715109716109717109718109719109720109721109722109723109724109725109726109727109728109729109730109731109732109733109734109735109736109737109738109739109740109741109742109743109744109745109746109747109748109749109750109751109752109753109754109755109756109757109758109759109760109761109762109763109764109765109766109767109768109769109770109771109772109773109774109775109776109777109778109779109780109781109782109783109784109785109786109787109788109789109790109791109792109793109794109795109796109797109798109799109800109801109802109803109804109805109806109807109808109809109810109811109812109813109814109815109816109817109818109819109820109821109822109823109824109825109826109827109828109829109830109831109832109833109834109835109836109837109838109839109840109841109842109843109844109845109846109847109848109849109850109851109852109853109854109855109856109857109858109859109860109861109862109863109864109865109866109867109868109869109870109871109872109873109874109875109876109877109878109879109880109881109882109883109884109885109886109887109888109889109890109891109892109893109894109895109896109897109898109899109900109901109902109903109904109905109906109907109908109909109910109911109912109913109914109915109916109917109918109919109920109921109922109923109924109925109926109927109928109929109930109931109932109933109934109935109936109937109938109939109940109941109942109943109944109945109946109947109948109949109950109951109952109953109954109955109956109957109958109959109960109961109962109963109964109965109966109967109968109969109970109971109972109973109974109975109976109977109978109979109980109981109982109983109984109985109986109987109988109989109990109991109992109993109994109995109996109997109998109999110000110001110002110003110004110005110006110007110008110009110010110011110012110013110014110015110016110017110018110019110020110021110022110023110024110025110026110027110028110029110030110031110032110033110034110035110036110037110038110039110040110041110042110043110044110045110046110047110048110049110050110051110052110053110054110055110056110057110058110059110060110061110062110063110064110065110066110067110068110069110070110071110072110073110074110075110076110077110078110079110080110081110082110083110084110085110086110087110088110089110090110091110092110093110094110095110096110097110098110099110100110101110102110103110104110105110106110107110108110109110110110111110112110113110114110115110116110117110118110119110120110121110122110123110124110125110126110127110128110129110130110131110132110133110134110135110136110137110138110139110140110141110142110143110144110145110146110147110148110149110150110151110152110153110154110155110156110157110158110159110160110161110162110163110164110165110166110167110168110169110170110171110172110173110174110175110176110177110178110179110180110181110182110183110184110185110186110187110188110189110190110191110192110193110194110195110196110197110198110199110200110201110202110203110204110205110206110207110208110209110210110211110212110213110214110215110216110217110218110219110220110221110222110223110224110225110226110227110228110229110230110231110232110233110234110235110236110237110238110239110240110241110242110243110244110245110246110247110248110249110250110251110252110253110254110255110256110257110258110259110260110261110262110263110264110265110266110267110268110269110270110271110272110273110274110275110276110277110278110279110280110281110282110283110284110285110286110287110288110289110290110291110292110293110294110295110296110297110298110299110300110301110302110303110304110305110306110307110308110309110310110311110312110313110314110315110316110317110318110319110320110321110322110323110324110325110326110327110328110329110330110331110332110333110334110335110336110337110338110339110340110341110342110343110344110345110346110347110348110349110350110351110352110353110354110355110356110357110358110359110360110361110362110363110364110365110366110367110368110369110370110371110372110373110374110375110376110377110378110379110380110381110382110383110384110385110386110387110388110389110390110391110392110393110394110395110396110397110398110399110400110401110402110403110404110405110406110407110408110409110410110411110412110413110414110415110416110417110418110419110420110421110422110423110424110425110426110427110428110429110430110431110432110433110434110435110436110437110438110439110440110441110442110443110444110445110446110447110448110449110450110451110452110453110454110455110456110457110458110459110460110461110462110463110464110465110466110467110468110469110470110471110472110473110474110475110476110477110478110479110480110481110482110483110484110485110486110487110488110489110490110491110492110493110494110495110496110497110498110499110500110501110502110503110504110505110506110507110508110509110510110511110512110513110514110515110516110517110518110519110520110521110522110523110524110525110526110527110528110529110530110531110532110533110534110535110536110537110538110539110540110541110542110543110544110545110546110547110548110549110550110551110552110553110554110555110556110557110558110559110560110561110562110563110564110565110566110567110568110569110570110571110572110573110574110575110576110577110578110579110580110581110582110583110584110585110586110587110588110589110590110591110592110593110594110595110596110597110598110599110600110601110602110603110604110605110606110607110608110609110610110611110612110613110614110615110616110617110618110619110620110621110622110623110624110625110626110627110628110629110630110631110632110633110634110635110636110637110638110639110640110641110642110643110644110645110646110647110648110649110650110651110652110653110654110655110656110657110658110659110660110661110662110663110664110665110666110667110668110669110670110671110672110673110674110675110676110677110678110679110680110681110682110683110684110685110686110687110688110689110690110691110692110693110694110695110696110697110698110699110700110701110702110703110704110705110706110707110708110709110710110711110712110713110714110715110716110717110718110719110720110721110722110723110724110725110726110727110728110729110730110731110732110733110734110735110736110737110738110739110740110741110742110743110744110745110746110747110748110749110750110751110752110753110754110755110756110757110758110759110760110761110762110763110764110765110766110767110768110769110770110771110772110773110774110775110776110777110778110779110780110781110782110783110784110785110786110787110788110789110790110791110792110793110794110795110796110797110798110799110800110801110802110803110804110805110806110807110808110809110810110811110812110813110814110815110816110817110818110819110820110821110822110823110824110825110826110827110828110829110830110831110832110833110834110835110836110837110838110839110840110841110842110843110844110845110846110847110848110849110850110851110852110853110854110855110856110857110858110859110860110861110862110863110864110865110866110867110868110869110870110871110872110873110874110875110876110877110878110879110880110881110882110883110884110885110886110887110888110889110890110891110892110893110894110895110896110897110898110899110900110901110902110903110904110905110906110907110908110909110910110911110912110913110914110915110916110917110918110919110920110921110922110923110924110925110926110927110928110929110930110931110932110933110934110935110936110937110938110939110940110941110942110943110944110945110946110947110948110949110950110951110952110953110954110955110956110957110958110959110960110961110962110963110964110965110966110967110968110969110970110971110972110973110974110975110976110977110978110979110980110981110982110983110984110985110986110987110988110989110990110991110992110993110994110995110996110997110998110999111000111001111002111003111004111005111006111007111008111009111010111011111012111013111014111015111016111017111018111019111020111021111022111023111024111025111026111027111028111029111030111031111032111033111034111035111036111037111038111039111040111041111042111043111044111045111046111047111048111049111050111051111052111053111054111055111056111057111058111059111060111061111062111063111064111065111066111067111068111069111070111071111072111073111074111075111076111077111078111079111080111081111082111083111084111085111086111087111088111089111090111091111092111093111094111095111096111097111098111099111100111101111102111103111104111105111106111107111108111109111110111111111112111113111114111115111116111117111118111119111120111121111122111123111124111125111126111127111128111129111130111131111132111133111134111135111136111137111138111139111140111141111142111143111144111145111146111147111148111149111150111151111152111153111154111155111156111157111158111159111160111161111162111163111164111165111166111167111168111169111170111171111172111173111174111175111176111177111178111179111180111181111182111183111184111185111186111187111188111189111190111191111192111193111194111195111196111197111198111199111200111201111202111203111204111205111206111207111208111209111210111211111212111213111214111215111216111217111218111219111220111221111222111223111224111225111226111227111228111229111230111231111232111233111234111235111236111237111238111239111240111241111242111243111244111245111246111247111248111249111250111251111252111253111254111255111256111257111258111259111260111261111262111263111264111265111266111267111268111269111270111271111272111273111274111275111276111277111278111279111280111281111282111283111284111285111286111287111288111289111290111291111292111293111294111295111296111297111298111299111300111301111302111303111304111305111306111307111308111309111310111311111312111313111314111315111316111317111318111319111320111321111322111323111324111325111326111327111328111329111330111331111332111333111334111335111336111337111338111339111340111341111342111343111344111345111346111347111348111349111350111351111352111353111354111355111356111357111358111359111360111361111362111363111364111365111366111367111368111369111370111371111372111373111374111375111376111377111378111379111380111381111382111383111384111385111386111387111388111389111390111391111392111393111394111395111396111397111398111399111400111401111402111403111404111405111406111407111408111409111410111411111412111413111414111415111416111417111418111419111420111421111422111423111424111425111426111427111428111429111430111431111432111433111434111435111436111437111438111439111440111441111442111443111444111445111446111447111448111449111450111451111452111453111454111455111456111457111458111459111460111461111462111463111464111465111466111467111468111469111470111471111472111473111474111475111476111477111478111479111480111481111482111483111484111485111486111487111488111489111490111491111492111493111494111495111496111497111498111499111500111501111502111503111504111505111506111507111508111509111510111511111512111513111514111515111516111517111518111519111520111521111522111523111524111525111526111527111528111529111530111531111532111533111534111535111536111537111538111539111540111541111542111543111544111545111546111547111548111549111550111551111552111553111554111555111556111557111558111559111560111561111562111563111564111565111566111567111568111569111570111571111572111573111574111575111576111577111578111579111580111581111582111583111584111585111586111587111588111589111590111591111592111593111594111595111596111597111598111599111600111601111602111603111604111605111606111607111608111609111610111611111612111613111614111615111616111617111618111619111620111621111622111623111624111625111626111627111628111629111630111631111632111633111634111635111636111637111638111639111640111641111642111643111644111645111646111647111648111649111650111651111652111653111654111655111656111657111658111659111660111661111662111663111664111665111666111667111668111669111670111671111672111673111674111675111676111677111678111679111680111681111682111683111684111685111686111687111688111689111690111691111692111693111694111695111696111697111698111699111700111701111702111703111704111705111706111707111708111709111710111711111712111713111714111715111716111717111718111719111720111721111722111723111724111725111726111727111728111729111730111731111732111733111734111735111736111737111738111739111740111741111742111743111744111745111746111747111748111749111750111751111752111753111754111755111756111757111758111759111760111761111762111763111764111765111766111767111768111769111770111771111772111773111774111775111776111777111778111779111780111781111782111783111784111785111786111787111788111789111790111791111792111793111794111795111796111797111798111799111800111801111802111803111804111805111806111807111808111809111810111811111812111813111814111815111816111817111818111819111820111821111822111823111824111825111826111827111828111829111830111831111832111833111834111835111836111837111838111839111840111841111842111843111844111845111846111847111848111849111850111851111852111853111854111855111856111857111858111859111860111861111862111863111864111865111866111867111868111869111870111871111872111873111874111875111876111877111878111879111880111881111882111883111884111885111886111887111888111889111890111891111892111893111894111895111896111897111898111899111900111901111902111903111904111905111906111907111908111909111910111911111912111913111914111915111916111917111918111919111920111921111922111923111924111925111926111927111928111929111930111931111932111933111934111935111936111937111938111939111940111941111942111943111944111945111946111947111948111949111950111951111952111953111954111955111956111957111958111959111960111961111962111963111964111965111966111967111968111969111970111971111972111973111974111975111976111977111978111979111980111981111982111983111984111985111986111987111988111989111990111991111992111993111994111995111996111997111998111999112000112001112002112003112004112005112006112007112008112009112010112011112012112013112014112015112016112017112018112019112020112021112022112023112024112025112026112027112028112029112030112031112032112033112034112035112036112037112038112039112040112041112042112043112044112045112046112047112048112049112050112051112052112053112054112055112056112057112058112059112060112061112062112063112064112065112066112067112068112069112070112071112072112073112074112075112076112077112078112079112080112081112082112083112084112085112086112087112088112089112090112091112092112093112094112095112096112097112098112099112100112101112102112103112104112105112106112107112108112109112110112111112112112113112114112115112116112117112118112119112120112121112122112123112124112125112126112127112128112129112130112131112132112133112134112135112136112137112138112139112140112141112142112143112144112145112146112147112148112149112150112151112152112153112154112155112156112157112158112159112160112161112162112163112164112165112166112167112168112169112170112171112172112173112174112175112176112177112178112179112180112181112182112183112184112185112186112187112188112189112190112191112192112193112194112195112196112197112198112199112200112201112202112203112204112205112206112207112208112209112210112211112212112213112214112215112216112217112218112219112220112221112222112223112224112225112226112227112228112229112230112231112232112233112234112235112236112237112238112239112240112241112242112243112244112245112246112247112248112249112250112251112252112253112254112255112256112257112258112259112260112261112262112263112264112265112266112267112268112269112270112271112272112273112274112275112276112277112278112279112280112281112282112283112284112285112286112287112288112289112290112291112292112293112294112295112296112297112298112299112300112301112302112303112304112305112306112307112308112309112310112311112312112313112314112315112316112317112318112319112320112321112322112323112324112325112326112327112328112329112330112331112332112333112334112335112336112337112338112339112340112341112342112343112344112345112346112347112348112349112350112351112352112353112354112355112356112357112358112359112360112361112362112363112364112365112366112367112368112369112370112371112372112373112374112375112376112377112378112379112380112381112382112383112384112385112386112387112388112389112390112391112392112393112394112395112396112397112398112399112400112401112402112403112404112405112406112407112408112409112410112411112412112413112414112415112416112417112418112419112420112421112422112423112424112425112426112427112428112429112430112431112432112433112434112435112436112437112438112439112440112441112442112443112444112445112446112447112448112449112450112451112452112453112454112455112456112457112458112459112460112461112462112463112464112465112466112467112468112469112470112471112472112473112474112475112476112477112478112479112480112481112482112483112484112485112486112487112488112489112490112491112492112493112494112495112496112497112498112499112500112501112502112503112504112505112506112507112508112509112510112511112512112513112514112515112516112517112518112519112520112521112522112523112524112525112526112527112528112529112530112531112532112533112534112535112536112537112538112539112540112541112542112543112544112545112546112547112548112549112550112551112552112553112554112555112556112557112558112559112560112561112562112563112564112565112566112567112568112569112570112571112572112573112574112575112576112577112578112579112580112581112582112583112584112585112586112587112588112589112590112591112592112593112594112595112596112597112598112599112600112601112602112603112604112605112606112607112608112609112610112611112612112613112614112615112616112617112618112619112620112621112622112623112624112625112626112627112628112629112630112631112632112633112634112635112636112637112638112639112640112641112642112643112644112645112646112647112648112649112650112651112652112653112654112655112656112657112658112659112660112661112662112663112664112665112666112667112668112669112670112671112672112673112674112675112676112677112678112679112680112681112682112683112684112685112686112687112688112689112690112691112692112693112694112695112696112697112698112699112700112701112702112703112704112705112706112707112708112709112710112711112712112713112714112715112716112717112718112719112720112721112722112723112724112725112726112727112728112729112730112731112732112733112734112735112736112737112738112739112740112741112742112743112744112745112746112747112748112749112750112751112752112753112754112755112756112757112758112759112760112761112762112763112764112765112766112767112768112769112770112771112772112773112774112775112776112777112778112779112780112781112782112783112784112785112786112787112788112789112790112791112792112793112794112795112796112797112798112799112800112801112802112803112804112805112806112807112808112809112810112811112812112813112814112815112816112817112818112819112820112821112822112823112824112825112826112827112828112829112830112831112832112833112834112835112836112837112838112839112840112841112842112843112844112845112846112847112848112849112850112851112852112853112854112855112856112857112858112859112860112861112862112863112864112865112866112867112868112869112870112871112872112873112874112875112876112877112878112879112880112881112882112883112884112885112886112887112888112889112890112891112892112893112894112895112896112897112898112899112900112901112902112903112904112905112906112907112908112909112910112911112912112913112914112915112916112917112918112919112920112921112922112923112924112925112926112927112928112929112930112931112932112933112934112935112936112937112938112939112940112941112942112943112944112945112946112947112948112949112950112951112952112953112954112955112956112957112958112959112960112961112962112963112964112965112966112967112968112969112970112971112972112973112974112975112976112977112978112979112980112981112982112983112984112985112986112987112988112989112990112991112992112993112994112995112996112997112998112999113000113001113002113003113004113005113006113007113008113009113010113011113012113013113014113015113016113017113018113019113020113021113022113023113024113025113026113027113028113029113030113031113032113033113034113035113036113037113038113039113040113041113042113043113044113045113046113047113048113049113050113051113052113053113054113055113056113057113058113059113060113061113062113063113064113065113066113067113068113069113070113071113072113073113074113075113076113077113078113079113080113081113082113083113084113085113086113087113088113089113090113091113092113093113094113095113096113097113098113099113100113101113102113103113104113105113106113107113108113109113110113111113112113113113114113115113116113117113118113119113120113121113122113123113124113125113126113127113128113129113130113131113132113133113134113135113136113137113138113139113140113141113142113143113144113145113146113147113148113149113150113151113152113153113154113155113156113157113158113159113160113161113162113163113164113165113166113167113168113169113170113171113172113173113174113175113176113177113178113179113180113181113182113183113184113185113186113187113188113189113190113191113192113193113194113195113196113197113198113199113200113201113202113203113204113205113206113207113208113209113210113211113212113213113214113215113216113217113218113219113220113221113222113223113224113225113226113227113228113229113230113231113232113233113234113235113236113237113238113239113240113241113242113243113244113245113246113247113248113249113250113251113252113253113254113255113256113257113258113259113260113261113262113263113264113265113266113267113268113269113270113271113272113273113274113275113276113277113278113279113280113281113282113283113284113285113286113287113288113289113290113291113292113293113294113295113296113297113298113299113300113301113302113303113304113305113306113307113308113309113310113311113312113313113314113315113316113317113318113319113320113321113322113323113324113325113326113327113328113329113330113331113332113333113334113335113336113337113338113339113340113341113342113343113344113345113346113347113348113349113350113351113352113353113354113355113356113357113358113359113360113361113362113363113364113365113366113367113368113369113370113371113372113373113374113375113376113377113378113379113380113381113382113383113384113385113386113387113388113389113390113391113392113393113394113395113396113397113398113399113400113401113402113403113404113405113406113407113408113409113410113411113412113413113414113415113416113417113418113419113420113421113422113423113424113425113426113427113428113429113430113431113432113433113434113435113436113437113438113439113440113441113442113443113444113445113446113447113448113449113450113451113452113453113454113455113456113457113458113459113460113461113462113463113464113465113466113467113468113469113470113471113472113473113474113475113476113477113478113479113480113481113482113483113484113485113486113487113488113489113490113491113492113493113494113495113496113497113498113499113500113501113502113503113504113505113506113507113508113509113510113511113512113513113514113515113516113517113518113519113520113521113522113523113524113525113526113527113528113529113530113531113532113533113534113535113536113537113538113539113540113541113542113543113544113545113546113547113548113549113550113551113552113553113554113555113556113557113558113559113560113561113562113563113564113565113566113567113568113569113570113571113572113573113574113575113576113577113578113579113580113581113582113583113584113585113586113587113588113589113590113591113592113593113594113595113596113597113598113599113600113601113602113603113604113605113606113607113608113609113610113611113612113613113614113615113616113617113618113619113620113621113622113623113624113625113626113627113628113629113630113631113632113633113634113635113636113637113638113639113640113641113642113643113644113645113646113647113648113649113650113651113652113653113654113655113656113657113658113659113660113661113662113663113664113665113666113667113668113669113670113671113672113673113674113675113676113677113678113679113680113681113682113683113684113685113686113687113688113689113690113691113692113693113694113695113696113697113698113699113700113701113702113703113704113705113706113707113708113709113710113711113712113713113714113715113716113717113718113719113720113721113722113723113724113725113726113727113728113729113730113731113732113733113734113735113736113737113738113739113740113741113742113743113744113745113746113747113748113749113750113751113752113753113754113755113756113757113758113759113760113761113762113763113764113765113766113767113768113769113770113771113772113773113774113775113776113777113778113779113780113781113782113783113784113785113786113787113788113789113790113791113792113793113794113795113796113797113798113799113800113801113802113803113804113805113806113807113808113809113810113811113812113813113814113815113816113817113818113819113820113821113822113823113824113825113826113827113828113829113830113831113832113833113834113835113836113837113838113839113840113841113842113843113844113845113846113847113848113849113850113851113852113853113854113855113856113857113858113859113860113861113862113863113864113865113866113867113868113869113870113871113872113873113874113875113876113877113878113879113880113881113882113883113884113885113886113887113888113889113890113891113892113893113894113895113896113897113898113899113900113901113902113903113904113905113906113907113908113909113910113911113912113913113914113915113916113917113918113919113920113921113922113923113924113925113926113927113928113929113930113931113932113933113934113935113936113937113938113939113940113941113942113943113944113945113946113947113948113949113950113951113952113953113954113955113956113957113958113959113960113961113962113963113964113965113966113967113968113969113970113971113972113973113974113975113976113977113978113979113980113981113982113983113984113985113986113987113988113989113990113991113992113993113994113995113996113997113998113999114000114001114002114003114004114005114006114007114008114009114010114011114012114013114014114015114016114017114018114019114020114021114022114023114024114025114026114027114028114029114030114031114032114033114034114035114036114037114038114039114040114041114042114043114044114045114046114047114048114049114050114051114052114053114054114055114056114057114058114059114060114061114062114063114064114065114066114067114068114069114070114071114072114073114074114075114076114077114078114079114080114081114082114083114084114085114086114087114088114089114090114091114092114093114094114095114096114097114098114099114100114101114102114103114104114105114106114107114108114109114110114111114112114113114114114115114116114117114118114119114120114121114122114123114124114125114126114127114128114129114130114131114132114133114134114135114136114137114138114139114140114141114142114143114144114145114146114147114148114149114150114151114152114153114154114155114156114157114158114159114160114161114162114163114164114165114166114167114168114169114170114171114172114173114174114175114176114177114178114179114180114181114182114183114184114185114186114187114188114189114190114191114192114193114194114195114196114197114198114199114200114201114202114203114204114205114206114207114208114209114210114211114212114213114214114215114216114217114218114219114220114221114222114223114224114225114226114227114228114229114230114231114232114233114234114235114236114237114238114239114240114241114242114243114244114245114246114247114248114249114250114251114252114253114254114255114256114257114258114259114260114261114262114263114264114265114266114267114268114269114270114271114272114273114274114275114276114277114278114279114280114281114282114283114284114285114286114287114288114289114290114291114292114293114294114295114296114297114298114299114300114301114302114303114304114305114306114307114308114309114310114311114312114313114314114315114316114317114318114319114320114321114322114323114324114325114326114327114328114329114330114331114332114333114334114335114336114337114338114339114340114341114342114343114344114345114346114347114348114349114350114351114352114353114354114355114356114357114358114359114360114361114362114363114364114365114366114367114368114369114370114371114372114373114374114375114376114377114378114379114380114381114382114383114384114385114386114387114388114389114390114391114392114393114394114395114396114397114398114399114400114401114402114403114404114405114406114407114408114409114410114411114412114413114414114415114416114417114418114419114420114421114422114423114424114425114426114427114428114429114430114431114432114433114434114435114436114437114438114439114440114441114442114443114444114445114446114447114448114449114450114451114452114453114454114455114456114457114458114459114460114461114462114463114464114465114466114467114468114469114470114471114472114473114474114475114476114477114478114479114480114481114482114483114484114485114486114487114488114489114490114491114492114493114494114495114496114497114498114499114500114501114502114503114504114505114506114507114508114509114510114511114512114513114514114515114516114517114518114519114520114521114522114523114524114525114526114527114528114529114530114531114532114533114534114535114536114537114538114539114540114541114542114543114544114545114546114547114548114549114550114551114552114553114554114555114556114557114558114559114560114561114562114563114564114565114566114567114568114569114570114571114572114573114574114575114576114577114578114579114580114581114582114583114584114585114586114587114588114589114590114591114592114593114594114595114596114597114598114599114600114601114602114603114604114605114606114607114608114609114610114611114612114613114614114615114616114617114618114619114620114621114622114623114624114625114626114627114628114629114630114631114632114633114634114635114636114637114638114639114640114641114642114643114644114645114646114647114648114649114650114651114652114653114654114655114656114657114658114659114660114661114662114663114664114665114666114667114668114669114670114671114672114673114674114675114676114677114678114679114680114681114682114683114684114685114686114687114688114689114690114691114692114693114694114695114696114697114698114699114700114701114702114703114704114705114706114707114708114709114710114711114712114713114714114715114716114717114718114719114720114721114722114723114724114725114726114727114728114729114730114731114732114733114734114735114736114737114738114739114740114741114742114743114744114745114746114747114748114749114750114751114752114753114754114755114756114757114758114759114760114761114762114763114764114765114766114767114768114769114770114771114772114773114774114775114776114777114778114779114780114781114782114783114784114785114786114787114788114789114790114791114792114793114794114795114796114797114798114799114800114801114802114803114804114805114806114807114808114809114810114811114812114813114814114815114816114817114818114819114820114821114822114823114824114825114826114827114828114829114830114831114832114833114834114835114836114837114838114839114840114841114842114843114844114845114846114847114848114849114850114851114852114853114854114855114856114857114858114859114860114861114862114863114864114865114866114867114868114869114870114871114872114873114874114875114876114877114878114879114880114881114882114883114884114885114886114887114888114889114890114891114892114893114894114895114896114897114898114899114900114901114902114903114904114905114906114907114908114909114910114911114912114913114914114915114916114917114918114919114920114921114922114923114924114925114926114927114928114929114930114931114932114933114934114935114936114937114938114939114940114941114942114943114944114945114946114947114948114949114950114951114952114953114954114955114956114957114958114959114960114961114962114963114964114965114966114967114968114969114970114971114972114973114974114975114976114977114978114979114980114981114982114983114984114985114986114987114988114989114990114991114992114993114994114995114996114997114998114999115000115001115002115003115004115005115006115007115008115009115010115011115012115013115014115015115016115017115018115019115020115021115022115023115024115025115026115027115028115029115030115031115032115033115034115035115036115037115038115039115040115041115042115043115044115045115046115047115048115049115050115051115052115053115054115055115056115057115058115059115060115061115062115063115064115065115066115067115068115069115070115071115072115073115074115075115076115077115078115079115080115081115082115083115084115085115086115087115088115089115090115091115092115093115094115095115096115097115098115099115100115101115102115103115104115105115106115107115108115109115110115111115112115113115114115115115116115117115118115119115120115121115122115123115124115125115126115127115128115129115130115131115132115133115134115135115136115137115138115139115140115141115142115143115144115145115146115147115148115149115150115151115152115153115154115155115156115157115158115159115160115161115162115163115164115165115166115167115168115169115170115171115172115173115174115175115176115177115178115179115180115181115182115183115184115185115186115187115188115189115190115191115192115193115194115195115196115197115198115199115200115201115202115203115204115205115206115207115208115209115210115211115212115213115214115215115216115217115218115219115220115221115222115223115224115225115226115227115228115229115230115231115232115233115234115235115236115237115238115239115240115241115242115243115244115245115246115247115248115249115250115251115252115253115254115255115256115257115258115259115260115261115262115263115264115265115266115267115268115269115270115271115272115273115274115275115276115277115278115279115280115281115282115283115284115285115286115287115288115289115290115291115292115293115294115295115296115297115298115299115300115301115302115303115304115305115306115307115308115309115310115311115312115313115314115315115316115317115318115319115320115321115322115323115324115325115326115327115328115329115330115331115332115333115334115335115336115337115338115339115340115341115342115343115344115345115346115347115348115349115350115351115352115353115354115355115356115357115358115359115360115361115362115363115364115365115366115367115368115369115370115371115372115373115374115375115376115377115378115379115380115381115382115383115384115385115386115387115388115389115390115391115392115393115394115395115396115397115398115399115400115401115402115403115404115405115406115407115408115409115410115411115412115413115414115415115416115417115418115419115420115421115422115423115424115425115426115427115428115429115430115431115432115433115434115435115436115437115438115439115440115441115442115443115444115445115446115447115448115449115450115451115452115453115454115455115456115457115458115459115460115461115462115463115464115465115466115467115468115469115470115471115472115473115474115475115476115477115478115479115480115481115482115483115484115485115486115487115488115489115490115491115492115493115494115495115496115497115498115499115500115501115502115503115504115505115506115507115508115509115510115511115512115513115514115515115516115517115518115519115520115521115522115523115524115525115526115527115528115529115530115531115532115533115534115535115536115537115538115539115540115541115542115543115544115545115546115547115548115549115550115551115552115553115554115555115556115557115558115559115560115561115562115563115564115565115566115567115568115569115570115571115572115573115574115575115576115577115578115579115580115581115582115583115584115585115586115587115588115589115590115591115592115593115594115595115596115597115598115599115600115601115602115603115604115605115606115607115608115609115610115611115612115613115614115615115616115617115618115619115620115621115622115623115624115625115626115627115628115629115630115631115632115633115634115635115636115637115638115639115640115641115642115643115644115645115646115647115648115649115650115651115652115653115654115655115656115657115658115659115660115661115662115663115664115665115666115667115668115669115670115671115672115673115674115675115676115677115678115679115680115681115682115683115684115685115686115687115688115689115690115691115692115693115694115695115696115697115698115699115700115701115702115703115704115705115706115707115708115709115710115711115712115713115714115715115716115717115718115719115720115721115722115723115724115725115726115727115728115729115730115731115732115733115734115735115736115737115738115739115740115741115742115743115744115745115746115747115748115749115750115751115752115753115754115755115756115757115758115759115760115761115762115763115764115765115766115767115768115769115770115771115772115773115774115775115776115777115778115779115780115781115782115783115784115785115786115787115788115789115790115791115792115793115794115795115796115797115798115799115800115801115802115803115804115805115806115807115808115809115810115811115812115813115814115815115816115817115818115819115820115821115822115823115824115825115826115827115828115829115830115831115832115833115834115835115836115837115838115839115840115841115842115843115844115845115846115847115848115849115850115851115852115853115854115855115856115857115858115859115860115861115862115863115864115865115866115867115868115869115870115871115872115873115874115875115876115877115878115879115880115881115882115883115884115885115886115887115888115889115890115891115892115893115894115895115896115897115898115899115900115901115902115903115904115905115906115907115908115909115910115911115912115913115914115915115916115917115918115919115920115921115922115923115924115925115926115927115928115929115930115931115932115933115934115935115936115937115938115939115940115941115942115943115944115945115946115947115948115949115950115951115952115953115954115955115956115957115958115959115960115961115962115963115964115965115966115967115968115969115970115971115972115973115974115975115976115977115978115979115980115981115982115983115984115985115986115987115988115989115990115991115992115993115994115995115996115997115998115999116000116001116002116003116004116005116006116007116008116009116010116011116012116013116014116015116016116017116018116019116020116021116022116023116024116025116026116027116028116029116030116031116032116033116034116035116036116037116038116039116040116041116042116043116044116045116046116047116048116049116050116051116052116053116054116055116056116057116058116059116060116061116062116063116064116065116066116067116068116069116070116071116072116073116074116075116076116077116078116079116080116081116082116083116084116085116086116087116088116089116090116091116092116093116094116095116096116097116098116099116100116101116102116103116104116105116106116107116108116109116110116111116112116113116114116115116116116117116118116119116120116121116122116123116124116125116126116127116128116129116130116131116132116133116134116135116136116137116138116139116140116141116142116143116144116145116146116147116148116149116150116151116152116153116154116155116156116157116158116159116160116161116162116163116164116165116166116167116168116169116170116171116172116173116174116175116176116177116178116179116180116181116182116183116184116185116186116187116188116189116190116191116192116193116194116195116196116197116198116199116200116201116202116203116204116205116206116207116208116209116210116211116212116213116214116215116216116217116218116219116220116221116222116223116224116225116226116227116228116229116230116231116232116233116234116235116236116237116238116239116240116241116242116243116244116245116246116247116248116249116250116251116252116253116254116255116256116257116258116259116260116261116262116263116264116265116266116267116268116269116270116271116272116273116274116275116276116277116278116279116280116281116282116283116284116285116286116287116288116289116290116291116292116293116294116295116296116297116298116299116300116301116302116303116304116305116306116307116308116309116310116311116312116313116314116315116316116317116318116319116320116321116322116323116324116325116326116327116328116329116330116331116332116333116334116335116336116337116338116339116340116341116342116343116344116345116346116347116348116349116350116351116352116353116354116355116356116357116358116359116360116361116362116363116364116365116366116367116368116369116370116371116372116373116374116375116376116377116378116379116380116381116382116383116384116385116386116387116388116389116390116391116392116393116394116395116396116397116398116399116400116401116402116403116404116405116406116407116408116409116410116411116412116413116414116415116416116417116418116419116420116421116422116423116424116425116426116427116428116429116430116431116432116433116434116435116436116437116438116439116440116441116442116443116444116445116446116447116448116449116450116451116452116453116454116455116456116457116458116459116460116461116462116463116464116465116466116467116468116469116470116471116472116473116474116475116476116477116478116479116480116481116482116483116484116485116486116487116488116489116490116491116492116493116494116495116496116497116498116499116500116501116502116503116504116505116506116507116508116509116510116511116512116513116514116515116516116517116518116519116520116521116522116523116524116525116526116527116528116529116530116531116532116533116534116535116536116537116538116539116540116541116542116543116544116545116546116547116548116549116550116551116552116553116554116555116556116557116558116559116560116561116562116563116564116565116566116567116568116569116570116571116572116573116574116575116576116577116578116579116580116581116582116583116584116585116586116587116588116589116590116591116592116593116594116595116596116597116598116599116600116601116602116603116604116605116606116607116608116609116610116611116612116613116614116615116616116617116618116619116620116621116622116623116624116625116626116627116628116629116630116631116632116633116634116635116636116637116638116639116640116641116642116643116644116645116646116647116648116649116650116651116652116653116654116655116656116657116658116659116660116661116662116663116664116665116666116667116668116669116670116671116672116673116674116675116676116677116678116679116680116681116682116683116684116685116686116687116688116689116690116691116692116693116694116695116696116697116698116699116700116701116702116703116704116705116706116707116708116709116710116711116712116713116714116715116716116717116718116719116720116721116722116723116724116725116726116727116728116729116730116731116732116733116734116735116736116737116738116739116740116741116742116743116744116745116746116747116748116749116750116751116752116753116754116755116756116757116758116759116760116761116762116763116764116765116766116767116768116769116770116771116772116773116774116775116776116777116778116779116780116781116782116783116784116785116786116787116788116789116790116791116792116793116794116795116796116797116798116799116800116801116802116803116804116805116806116807116808116809116810116811116812116813116814116815116816116817116818116819116820116821116822116823116824116825116826116827116828116829116830116831116832116833116834116835116836116837116838116839116840116841116842116843116844116845116846116847116848116849116850116851116852116853116854116855116856116857116858116859116860116861116862116863116864116865116866116867116868116869116870116871116872116873116874116875116876116877116878116879116880116881116882116883116884116885116886116887116888116889116890116891116892116893116894116895116896116897116898116899116900116901116902116903116904116905116906116907116908116909116910116911116912116913116914116915116916116917116918116919116920116921116922116923116924116925116926116927116928116929116930116931116932116933116934116935116936116937116938116939116940116941116942116943116944116945116946116947116948116949116950116951116952116953116954116955116956116957116958116959116960116961116962116963116964116965116966116967116968116969116970116971116972116973116974116975116976116977116978116979116980116981116982116983116984116985116986116987116988116989116990116991116992116993116994116995116996116997116998116999117000117001117002117003117004117005117006117007117008117009117010117011117012117013117014117015117016117017117018117019117020117021117022117023117024117025117026117027117028117029117030117031117032117033117034117035117036117037117038117039117040117041117042117043117044117045117046117047117048117049117050117051117052117053117054117055117056117057117058117059117060117061117062117063117064117065117066117067117068117069117070117071117072117073117074117075117076117077117078117079117080117081117082117083117084117085117086117087117088117089117090117091117092117093117094117095117096117097117098117099117100117101117102117103117104117105117106117107117108117109117110117111117112117113117114117115117116117117117118117119117120117121117122117123117124117125117126117127117128117129117130117131117132117133117134117135117136117137117138117139117140117141117142117143117144117145117146117147117148117149117150117151117152117153117154117155117156117157117158117159117160117161117162117163117164117165117166117167117168117169117170117171117172117173117174117175117176117177117178117179117180117181117182117183117184117185117186117187117188117189117190117191117192117193117194117195117196117197117198117199117200117201117202117203117204117205117206117207117208117209117210117211117212117213117214117215117216117217117218117219117220117221117222117223117224117225117226117227117228117229117230117231117232117233117234117235117236117237117238117239117240117241117242117243117244117245117246117247117248117249117250117251117252117253117254117255117256117257117258117259117260117261117262117263117264117265117266117267117268117269117270117271117272117273117274117275117276117277117278117279117280117281117282117283117284117285117286117287117288117289117290117291117292117293117294117295117296117297117298117299117300117301117302117303117304117305117306117307117308117309117310117311117312117313117314117315117316117317117318117319117320117321117322117323117324117325117326117327117328117329117330117331117332117333117334117335117336117337117338117339117340117341117342117343117344117345117346117347117348117349117350117351117352117353117354117355117356117357117358117359117360117361117362117363117364117365117366117367117368117369117370117371117372117373117374117375117376117377117378117379117380117381117382117383117384117385117386117387117388117389117390117391117392117393117394117395117396117397117398117399117400117401117402117403117404117405117406117407117408117409117410117411117412117413117414117415117416117417117418117419117420117421117422117423117424117425117426117427117428117429117430117431117432117433117434117435117436117437117438117439117440117441117442117443117444117445117446117447117448117449117450117451117452117453117454117455117456117457117458117459117460117461117462117463117464117465117466117467117468117469117470117471117472117473117474117475117476117477117478117479117480117481117482117483117484117485117486117487117488117489117490117491117492117493117494117495117496117497117498117499117500117501117502117503117504117505117506117507117508117509117510117511117512117513117514117515117516117517117518117519117520117521117522117523117524117525117526117527117528117529117530117531117532117533117534117535117536117537117538117539117540117541117542117543117544117545117546117547117548117549117550117551117552117553117554117555117556117557117558117559117560117561117562117563117564117565117566117567117568117569117570117571117572117573117574117575117576117577117578117579117580117581117582117583117584117585117586117587117588117589117590117591117592117593117594117595117596117597117598117599117600117601117602117603117604117605117606117607117608117609117610117611117612117613117614117615117616117617117618117619117620117621117622117623117624117625117626117627117628117629117630117631117632117633117634117635117636117637117638117639117640117641117642117643117644117645117646117647117648117649117650117651117652117653117654117655117656117657117658117659117660117661117662117663117664117665117666117667117668117669117670117671117672117673117674117675117676117677117678117679117680117681117682117683117684117685117686117687117688117689117690117691117692117693117694117695117696117697117698117699117700117701117702117703117704117705117706117707117708117709117710117711117712117713117714117715117716117717117718117719117720117721117722117723117724117725117726117727117728117729117730117731117732117733117734117735117736117737117738117739117740117741117742117743117744117745117746117747117748117749117750117751117752117753117754117755117756117757117758117759117760117761117762117763117764117765117766117767117768117769117770117771117772117773117774117775117776117777117778117779117780117781117782117783117784117785117786117787117788117789117790117791117792117793117794117795117796117797117798117799117800117801117802117803117804117805117806117807117808117809117810117811117812117813117814117815117816117817117818117819117820117821117822117823117824117825117826117827117828117829117830117831117832117833117834117835117836117837117838117839117840117841117842117843117844117845117846117847117848117849117850117851117852117853117854117855117856117857117858117859117860117861117862117863117864117865117866117867117868117869117870117871117872117873117874117875117876117877117878117879117880117881117882117883117884117885117886117887117888117889117890117891117892117893117894117895117896117897117898117899117900117901117902117903117904117905117906117907117908117909117910117911117912117913117914117915117916117917117918117919117920117921117922117923117924117925117926117927117928117929117930117931117932117933117934117935117936117937117938117939117940117941117942117943117944117945117946117947117948117949117950117951117952117953117954117955117956117957117958117959117960117961117962117963117964117965117966117967117968117969117970117971117972117973117974117975117976117977117978117979117980117981117982117983117984117985117986117987117988117989117990117991117992117993117994117995117996117997117998117999118000118001118002118003118004118005118006118007118008118009118010118011118012118013118014118015118016118017118018118019118020118021118022118023118024118025118026118027118028118029118030118031118032118033118034118035118036118037118038118039118040118041118042118043118044118045118046118047118048118049118050118051118052118053118054118055118056118057118058118059118060118061118062118063118064118065118066118067118068118069118070118071118072118073118074118075118076118077118078118079118080118081118082118083118084118085118086118087118088118089118090118091118092118093118094118095118096118097118098118099118100118101118102118103118104118105118106118107118108118109118110118111118112118113118114118115118116118117118118118119118120118121118122118123118124118125118126118127118128118129118130118131118132118133118134118135118136118137118138118139118140118141118142118143118144118145118146118147118148118149118150118151118152118153118154118155118156118157118158118159118160118161118162118163118164118165118166118167118168118169118170118171118172118173118174118175118176118177118178118179118180118181118182118183118184118185118186118187118188118189118190118191118192118193118194118195118196118197118198118199118200118201118202118203118204118205118206118207118208118209118210118211118212118213118214118215118216118217118218118219118220118221118222118223118224118225118226118227118228118229118230118231118232118233118234118235118236118237118238118239118240118241118242118243118244118245118246118247118248118249118250118251118252118253118254118255118256118257118258118259118260118261118262118263118264118265118266118267118268118269118270118271118272118273118274118275118276118277118278118279118280118281118282118283118284118285118286118287118288118289118290118291118292118293118294118295118296118297118298118299118300118301118302118303118304118305118306118307118308118309118310118311118312118313118314118315118316118317118318118319118320118321118322118323118324118325118326118327118328118329118330118331118332118333118334118335118336118337118338118339118340118341118342118343118344118345118346118347118348118349118350118351118352118353118354118355118356118357118358118359118360118361118362118363118364118365118366118367118368118369118370118371118372118373118374118375118376118377118378118379118380118381118382118383118384118385118386118387118388118389118390118391118392118393118394118395118396118397118398118399118400118401118402118403118404118405118406118407118408118409118410118411118412118413118414118415118416118417118418118419118420118421118422118423118424118425118426118427118428118429118430118431118432118433118434118435118436118437118438118439118440118441118442118443118444118445118446118447118448118449118450118451118452118453118454118455118456118457118458118459118460118461118462118463118464118465118466118467118468118469118470118471118472118473118474118475118476118477118478118479118480118481118482118483118484118485118486118487118488118489118490118491118492118493118494118495118496118497118498118499118500118501118502118503118504118505118506118507118508118509118510118511118512118513118514118515118516118517118518118519118520118521118522118523118524118525118526118527118528118529118530118531118532118533118534118535118536118537118538118539118540118541118542118543118544118545118546118547118548118549118550118551118552118553118554118555118556118557118558118559118560118561118562118563118564118565118566118567118568118569118570118571118572118573118574118575118576118577118578118579118580118581118582118583118584118585118586118587118588118589118590118591118592118593118594118595118596118597118598118599118600118601118602118603118604118605118606118607118608118609118610118611118612118613118614118615118616118617118618118619118620118621118622118623118624118625118626118627118628118629118630118631118632118633118634118635118636118637118638118639118640118641118642118643118644118645118646118647118648118649118650118651118652118653118654118655118656118657118658118659118660118661118662118663118664118665118666118667118668118669118670118671118672118673118674118675118676118677118678118679118680118681118682118683118684118685118686118687118688118689118690118691118692118693118694118695118696118697118698118699118700118701118702118703118704118705118706118707118708118709118710118711118712118713118714118715118716118717118718118719118720118721118722118723118724118725118726118727118728118729118730118731118732118733118734118735118736118737118738118739118740118741118742118743118744118745118746118747118748118749118750118751118752118753118754118755118756118757118758118759118760118761118762118763118764118765118766118767118768118769118770118771118772118773118774118775118776118777118778118779118780118781118782118783118784118785118786118787118788118789118790118791118792118793118794118795118796118797118798118799118800118801118802118803118804118805118806118807118808118809118810118811118812118813118814118815118816118817118818118819118820118821118822118823118824118825118826118827118828118829118830118831118832118833118834118835118836118837118838118839118840118841118842118843118844118845118846118847118848118849118850118851118852118853118854118855118856118857118858118859118860118861118862118863118864118865118866118867118868118869118870118871118872118873118874118875118876118877118878118879118880118881118882118883118884118885118886118887118888118889118890118891118892118893118894118895118896118897118898118899118900118901118902118903118904118905118906118907118908118909118910118911118912118913118914118915118916118917118918118919118920118921118922118923118924118925118926118927118928118929118930118931118932118933118934118935118936118937118938118939118940118941118942118943118944118945118946118947118948118949118950118951118952118953118954118955118956118957118958118959118960118961118962118963118964118965118966118967118968118969118970118971118972118973118974118975118976118977118978118979118980118981118982118983118984118985118986118987118988118989118990118991118992118993118994118995118996118997118998118999119000119001119002119003119004119005119006119007119008119009119010119011119012119013119014119015119016119017119018119019119020119021119022119023119024119025119026119027119028119029119030119031119032119033119034119035119036119037119038119039119040119041119042119043119044119045119046119047119048119049119050119051119052119053119054119055119056119057119058119059119060119061119062119063119064119065119066119067119068119069119070119071119072119073119074119075119076119077119078119079119080119081119082119083119084119085119086119087119088119089119090119091119092119093119094119095119096119097119098119099119100119101119102119103119104119105119106119107119108119109119110119111119112119113119114119115119116119117119118119119119120119121119122119123119124119125119126119127119128119129119130119131119132119133119134119135119136119137119138119139119140119141119142119143119144119145119146119147119148119149119150119151119152119153119154119155119156119157119158119159119160119161119162119163119164119165119166119167119168119169119170119171119172119173119174119175119176119177119178119179119180119181119182119183119184119185119186119187119188119189119190119191119192119193119194119195119196119197119198119199119200119201119202119203119204119205119206119207119208119209119210119211119212119213119214119215119216119217119218119219119220119221119222119223119224119225119226119227119228119229119230119231119232119233119234119235119236119237119238119239119240119241119242119243119244119245119246119247119248119249119250119251119252119253119254119255119256119257119258119259119260119261119262119263119264119265119266119267119268119269119270119271119272119273119274119275119276119277119278119279119280119281119282119283119284119285119286119287119288119289119290119291119292119293119294119295119296119297119298119299119300119301119302119303119304119305119306119307119308119309119310119311119312119313119314119315119316119317119318119319119320119321119322119323119324119325119326119327119328119329119330119331119332119333119334119335119336119337119338119339119340119341119342119343119344119345119346119347119348119349119350119351119352119353119354119355119356119357119358119359119360119361119362119363119364119365119366119367119368119369119370119371119372119373119374119375119376119377119378119379119380119381119382119383119384119385119386119387119388119389119390119391119392119393119394119395119396119397119398119399119400119401119402119403119404119405119406119407119408119409119410119411119412119413119414119415119416119417119418119419119420119421119422119423119424119425119426119427119428119429119430119431119432119433119434119435119436119437119438119439119440119441119442119443119444119445119446119447119448119449119450119451119452119453119454119455119456119457119458119459119460119461119462119463119464119465119466119467119468119469119470119471119472119473119474119475119476119477119478119479119480119481119482119483119484119485119486119487119488119489119490119491119492119493119494119495119496119497119498119499119500119501119502119503119504119505119506119507119508119509119510119511119512119513119514119515119516119517119518119519119520119521119522119523119524119525119526119527119528119529119530119531119532119533119534119535119536119537119538119539119540119541119542119543119544119545119546119547119548119549119550119551119552119553119554119555119556119557119558119559119560119561119562119563119564119565119566119567119568119569119570119571119572119573119574119575119576119577119578119579119580119581119582119583119584119585119586119587119588119589119590119591119592119593119594119595119596119597119598119599119600119601119602119603119604119605119606119607119608119609119610119611119612119613119614119615119616119617119618119619119620119621119622119623119624119625119626119627119628119629119630119631119632119633119634119635119636119637119638119639119640119641119642119643119644119645119646119647119648119649119650119651119652119653119654119655119656119657119658119659119660119661119662119663119664119665119666119667119668119669119670119671119672119673119674119675119676119677119678119679119680119681119682119683119684119685119686119687119688119689119690119691119692119693119694119695119696119697119698119699119700119701119702119703119704119705119706119707119708119709119710119711119712119713119714119715119716119717119718119719119720119721119722119723119724119725119726119727119728119729119730119731119732119733119734119735119736119737119738119739119740119741119742119743119744119745119746119747119748119749119750119751119752119753119754119755119756119757119758119759119760119761119762119763119764119765119766119767119768119769119770119771119772119773119774119775119776119777119778119779119780119781119782119783119784119785119786119787119788119789119790119791119792119793119794119795119796119797119798119799119800119801119802119803119804119805119806119807119808119809119810119811119812119813119814119815119816119817119818119819119820119821119822119823119824119825119826119827119828119829119830119831119832119833119834119835119836119837119838119839119840119841119842119843119844119845119846119847119848119849119850119851119852119853119854119855119856119857119858119859119860119861119862119863119864119865119866119867119868119869119870119871119872119873119874119875119876119877119878119879119880119881119882119883119884119885119886119887119888119889119890119891119892119893119894119895119896119897119898119899119900119901119902119903119904119905119906119907119908119909119910119911119912119913119914119915119916119917119918119919119920119921119922119923119924119925119926119927119928119929119930119931119932119933119934119935119936119937119938119939119940119941119942119943119944119945119946119947119948119949119950119951119952119953119954119955119956119957119958119959119960119961119962119963119964119965119966119967119968119969119970119971119972119973119974119975119976119977119978119979119980119981119982119983119984119985119986119987119988119989119990119991119992119993119994119995119996119997119998119999120000120001120002120003120004120005120006120007120008120009120010120011120012120013120014120015120016120017120018120019120020120021120022120023120024120025120026120027120028120029120030120031120032120033120034120035120036120037120038120039120040120041120042120043120044120045120046120047120048120049120050120051120052120053120054120055120056120057120058120059120060120061120062120063120064120065120066120067120068120069120070120071120072120073120074120075120076120077120078120079120080120081120082120083120084120085120086120087120088120089120090120091120092120093120094120095120096120097120098120099120100120101120102120103120104120105120106120107120108120109120110120111120112120113120114120115120116120117120118120119120120120121120122120123120124120125120126120127120128120129120130120131120132120133120134120135120136120137120138120139120140120141120142120143120144120145120146120147120148120149120150120151120152120153120154120155120156120157120158120159120160120161120162120163120164120165120166120167120168120169120170120171120172120173120174120175120176120177120178120179120180120181120182120183120184120185120186120187120188120189120190120191120192120193120194120195120196120197120198120199120200120201120202120203120204120205120206120207120208120209120210120211120212120213120214120215120216120217120218120219120220120221120222120223120224120225120226120227120228120229120230120231120232120233120234120235120236120237120238120239120240120241120242120243120244120245120246120247120248120249120250120251120252120253120254120255120256120257120258120259120260120261120262120263120264120265120266120267120268120269120270120271120272120273120274120275120276120277120278120279120280120281120282120283120284120285120286120287120288120289120290120291120292120293120294120295120296120297120298120299120300120301120302120303120304120305120306120307120308120309120310120311120312120313120314120315120316120317120318120319120320120321120322120323120324120325120326120327120328120329120330120331120332120333120334120335120336120337120338120339120340120341120342120343120344120345120346120347120348120349120350120351120352120353120354120355120356120357120358120359120360120361120362120363120364120365120366120367120368120369120370120371120372120373120374120375120376120377120378120379120380120381120382120383120384120385120386120387120388120389120390120391120392120393120394120395120396120397120398120399120400120401120402120403120404120405120406120407120408120409120410120411120412120413120414120415120416120417120418120419120420120421120422120423120424120425120426120427120428120429120430120431120432120433120434120435120436120437120438120439120440120441120442120443120444120445120446120447120448120449120450120451120452120453120454120455120456120457120458120459120460120461120462120463120464120465120466120467120468120469120470120471120472120473120474120475120476120477120478120479120480120481120482120483120484120485120486120487120488120489120490120491120492120493120494120495120496120497120498120499120500120501120502120503120504120505120506120507120508120509120510120511120512120513120514120515120516120517120518120519120520120521120522120523120524120525120526120527120528120529120530120531120532120533120534120535120536120537120538120539120540120541120542120543120544120545120546120547120548120549120550120551120552120553120554120555120556120557120558120559120560120561120562120563120564120565120566120567120568120569120570120571120572120573120574120575120576120577120578120579120580120581120582120583120584120585120586120587120588120589120590120591120592120593120594120595120596120597120598120599120600120601120602120603120604120605120606120607120608120609120610120611120612120613120614120615120616120617120618120619120620120621120622120623120624120625120626120627120628120629120630120631120632120633120634120635120636120637120638120639120640120641120642120643120644120645120646120647120648120649120650120651120652120653120654120655120656120657120658120659120660120661120662120663120664120665120666120667120668120669120670120671120672120673120674120675120676120677120678120679120680120681120682120683120684120685120686120687120688120689120690120691120692120693120694120695120696120697120698120699120700120701120702120703120704120705120706120707120708120709120710120711120712120713120714120715120716120717120718120719120720120721120722120723120724120725120726120727120728120729120730120731120732120733120734120735120736120737120738120739120740120741120742120743120744120745120746120747120748120749120750120751120752120753120754120755120756120757120758120759120760120761120762120763120764120765120766120767120768120769120770120771120772120773120774120775120776120777120778120779120780120781120782120783120784120785120786120787120788120789120790120791120792120793120794120795120796120797120798120799120800120801120802120803120804120805120806120807120808120809120810120811120812120813120814120815120816120817120818120819120820120821120822120823120824120825120826120827120828120829120830120831120832120833120834120835120836120837120838120839120840120841120842120843120844120845120846120847120848120849120850120851120852120853120854120855120856120857120858120859120860120861120862120863120864120865120866120867120868120869120870120871120872120873120874120875120876120877120878120879120880120881120882120883120884120885120886120887120888120889120890120891120892120893120894120895120896120897120898120899120900120901120902120903120904120905120906120907120908120909120910120911120912120913120914120915120916120917120918120919120920120921120922120923120924120925120926120927120928120929120930120931120932120933120934120935120936120937120938120939120940120941120942120943120944120945120946120947120948120949120950120951120952120953120954120955120956120957120958120959120960120961120962120963120964120965120966120967120968120969120970120971120972120973120974120975120976120977120978120979120980120981120982120983120984120985120986120987120988120989120990120991120992120993120994120995120996120997120998120999121000121001121002121003121004121005121006121007121008121009121010121011121012121013121014121015121016121017121018121019121020121021121022121023121024121025121026121027121028121029121030121031121032121033121034121035121036121037121038121039121040121041121042121043121044121045121046121047121048121049121050121051121052121053121054121055121056121057121058121059121060121061121062121063121064121065121066121067121068121069121070121071121072121073121074121075121076121077121078121079121080121081121082121083121084121085121086121087121088121089121090121091121092121093121094121095121096121097121098121099121100121101121102121103121104121105121106121107121108121109121110121111121112121113121114121115121116121117121118121119121120121121121122121123121124121125121126121127121128121129121130121131121132121133121134121135121136121137121138121139121140121141121142121143121144121145121146121147121148121149121150121151121152121153121154121155121156121157121158121159121160121161121162121163121164121165121166121167121168121169121170121171121172121173121174121175121176121177121178121179121180121181121182121183121184121185121186121187121188121189121190121191121192121193121194121195121196121197121198121199121200121201121202121203121204121205121206121207121208121209121210121211121212121213121214121215121216121217121218121219121220121221121222121223121224121225121226121227121228121229121230121231121232121233121234121235121236121237121238121239121240121241121242121243121244121245121246121247121248121249121250121251121252121253121254121255121256121257121258121259121260121261121262121263121264121265121266121267121268121269121270121271121272121273121274121275121276121277121278121279121280121281121282121283121284121285121286121287121288121289121290121291121292121293121294121295121296121297121298121299121300121301121302121303121304121305121306121307121308121309121310121311121312121313121314121315121316121317121318121319121320121321121322121323121324121325121326121327121328121329121330121331121332121333121334121335121336121337121338121339121340121341121342121343121344121345121346121347121348121349121350121351121352121353121354121355121356121357121358121359121360121361121362121363121364121365121366121367121368121369121370121371121372121373121374121375121376121377121378121379121380121381121382121383121384121385121386121387121388121389121390121391121392121393121394121395121396121397121398121399121400121401121402121403121404121405121406121407121408121409121410121411121412121413121414121415121416121417121418121419121420121421121422121423121424121425121426121427121428121429121430121431121432121433121434121435121436121437121438121439121440121441121442121443121444121445121446121447121448121449121450121451121452121453121454121455121456121457121458121459121460121461121462121463121464121465121466121467121468121469121470121471121472121473121474121475121476121477121478121479121480121481121482121483121484121485121486121487121488121489121490121491121492121493121494121495121496121497121498121499121500121501121502121503121504121505121506121507121508121509121510121511121512121513121514121515121516121517121518121519121520121521121522121523121524121525121526121527121528121529121530121531121532121533121534121535121536121537121538121539121540121541121542121543121544121545121546121547121548121549121550121551121552121553121554121555121556121557121558121559121560121561121562121563121564121565121566121567121568121569121570121571121572121573121574121575121576121577121578121579121580121581121582121583121584121585121586121587121588121589121590121591121592121593121594121595121596121597121598121599121600121601121602121603121604121605121606121607121608121609121610121611121612121613121614121615121616121617121618121619121620121621121622121623121624121625121626121627121628121629121630121631121632121633121634121635121636121637121638121639121640121641121642121643121644121645121646121647121648121649121650121651121652121653121654121655121656121657121658121659121660121661121662121663121664121665121666121667121668121669121670121671121672121673121674121675121676121677121678121679121680121681121682121683121684121685121686121687121688121689121690121691121692121693121694121695121696121697121698121699121700121701121702121703121704121705121706121707121708121709121710121711121712121713121714121715121716121717121718121719121720121721121722121723121724121725121726121727121728121729121730121731121732121733121734121735121736121737121738121739121740121741121742121743121744121745121746121747121748121749121750121751121752121753121754121755121756121757121758121759121760121761121762121763121764121765121766121767121768121769121770121771121772121773121774121775121776121777121778121779121780121781121782121783121784121785121786121787121788121789121790121791121792121793121794121795121796121797121798121799121800121801121802121803121804121805121806121807121808121809121810121811121812121813121814121815121816121817121818121819121820121821121822121823121824121825121826121827121828121829121830121831121832121833121834121835121836121837121838121839121840121841121842121843121844121845121846121847121848121849121850121851121852121853121854121855121856121857121858121859121860121861121862121863121864121865121866121867121868121869121870121871121872121873121874121875121876121877121878121879121880121881121882121883121884121885121886121887121888121889121890121891121892121893121894121895121896121897121898121899121900121901121902121903121904121905121906121907121908121909121910121911121912121913121914121915121916121917121918121919121920121921121922121923121924121925121926121927121928121929121930121931121932121933121934121935121936121937121938121939121940121941121942121943121944121945121946121947121948121949121950121951121952121953121954121955121956121957121958121959121960121961121962121963121964121965121966121967121968121969121970121971121972121973121974121975121976121977121978121979121980121981121982121983121984121985121986121987121988121989121990121991121992121993121994121995121996121997121998121999122000122001122002122003122004122005122006122007122008122009122010122011122012122013122014122015122016122017122018122019122020122021122022122023122024122025122026122027122028122029122030122031122032122033122034122035122036122037122038122039122040122041122042122043122044122045122046122047122048122049122050122051122052122053122054122055122056122057122058122059122060122061122062122063122064122065122066122067122068122069122070122071122072122073122074122075122076122077122078122079122080122081122082122083122084122085122086122087122088122089122090122091122092122093122094122095122096122097122098122099122100122101122102122103122104122105122106122107122108122109122110122111122112122113122114122115122116122117122118122119122120122121122122122123122124122125122126122127122128122129122130122131122132122133122134122135122136122137122138122139122140122141122142122143122144122145122146122147122148122149122150122151122152122153122154122155122156122157122158122159122160122161122162122163122164122165122166122167122168122169122170122171122172122173122174122175122176122177122178122179122180122181122182122183122184122185122186122187122188122189122190122191122192122193122194122195122196122197122198122199122200122201122202122203122204122205122206122207122208122209122210122211122212122213122214122215122216122217122218122219122220122221122222122223122224122225122226122227122228122229122230122231122232122233122234122235122236122237122238122239122240122241122242122243122244122245122246122247122248122249122250122251122252122253122254122255122256122257122258122259122260122261122262122263122264122265122266122267122268122269122270122271122272122273122274122275122276122277122278122279122280122281122282122283122284122285122286122287122288122289122290122291122292122293122294122295122296122297122298122299122300122301122302122303122304122305122306122307122308122309122310122311122312122313122314122315122316122317122318122319122320122321122322122323122324122325122326122327122328122329122330122331122332122333122334122335122336122337122338122339122340122341122342122343122344122345122346122347122348122349122350122351122352122353122354122355122356122357122358122359122360122361122362122363122364122365122366122367122368122369122370122371122372122373122374122375122376122377122378122379122380122381122382122383122384122385122386122387122388122389122390122391122392122393122394122395122396122397122398122399122400122401122402122403122404122405122406122407122408122409122410122411122412122413122414122415122416122417122418122419122420122421122422122423122424122425122426122427122428122429122430122431122432122433122434122435122436122437122438122439122440122441122442122443122444122445122446122447122448122449122450122451122452122453122454122455122456122457122458122459122460122461122462122463122464122465122466122467122468122469122470122471122472122473122474122475122476122477122478122479122480122481122482122483122484122485122486122487122488122489122490122491122492122493122494122495122496122497122498122499122500122501122502122503122504122505122506122507122508122509122510122511122512122513122514122515122516122517122518122519122520122521122522122523122524122525122526122527122528122529122530122531122532122533122534122535122536122537122538122539122540122541122542122543122544122545122546122547122548122549122550122551122552122553122554122555122556122557122558122559122560122561122562122563122564122565122566122567122568122569122570122571122572122573122574122575122576122577122578122579122580122581122582122583122584122585122586122587122588122589122590122591122592122593122594122595122596122597122598122599122600122601122602122603122604122605122606122607122608122609122610122611122612122613122614122615122616122617122618122619122620122621122622122623122624122625122626122627122628122629122630122631122632122633122634122635122636122637122638122639122640122641122642122643122644122645122646122647122648122649122650122651122652122653122654122655122656122657122658122659122660122661122662122663122664122665122666122667122668122669122670122671122672122673122674122675122676122677122678122679122680122681122682122683122684122685122686122687122688122689122690122691122692122693122694122695122696122697122698122699122700122701122702122703122704122705122706122707122708122709122710122711122712122713122714122715122716122717122718122719122720122721122722122723122724122725122726122727122728122729122730122731122732122733122734122735122736122737122738122739122740122741122742122743122744122745122746122747122748122749122750122751122752122753122754122755122756122757122758122759122760122761122762122763122764122765122766122767122768122769122770122771122772122773122774122775122776122777122778122779122780122781122782122783122784122785122786122787122788122789122790122791122792122793122794122795122796122797122798122799122800122801122802122803122804122805122806122807122808122809122810122811122812122813122814122815122816122817122818122819122820122821122822122823122824122825122826122827122828122829122830122831122832122833122834122835122836122837122838122839122840122841122842122843122844122845122846122847122848122849122850122851122852122853122854122855122856122857122858122859122860122861122862122863122864122865122866122867122868122869122870122871122872122873122874122875122876122877122878122879122880122881122882122883122884122885122886122887122888122889122890122891122892122893122894122895122896122897122898122899122900122901122902122903122904122905122906122907122908122909122910122911122912122913122914122915122916122917122918122919122920122921122922122923122924122925122926122927122928122929122930122931122932122933122934122935122936122937122938122939122940122941122942122943122944122945122946122947122948122949122950122951122952122953122954122955122956122957122958122959122960122961122962122963122964122965122966122967122968122969122970122971122972122973122974122975122976122977122978122979122980122981122982122983122984122985122986122987122988122989122990122991122992122993122994122995122996122997122998122999123000123001123002123003123004123005123006123007123008123009123010123011123012123013123014123015123016123017123018123019123020123021123022123023123024123025123026123027123028123029123030123031123032123033123034123035123036123037123038123039123040123041123042123043123044123045123046123047123048123049123050123051123052123053123054123055123056123057123058123059123060123061123062123063123064123065123066123067123068123069123070123071123072123073123074123075123076123077123078123079123080123081123082123083123084123085123086123087123088123089123090123091123092123093123094123095123096123097123098123099123100123101123102123103123104123105123106123107123108123109123110123111123112123113123114123115123116123117123118123119123120123121123122123123123124123125123126123127123128123129123130123131123132123133123134123135123136123137123138123139123140123141123142123143123144123145123146123147123148123149123150123151123152123153123154123155123156123157123158123159123160123161123162123163123164123165123166123167123168123169123170123171123172123173123174123175123176123177123178123179123180123181123182123183123184123185123186123187123188123189123190123191123192123193123194123195123196123197123198123199123200123201123202123203123204123205123206123207123208123209123210123211123212123213123214123215123216123217123218123219123220123221123222123223123224123225123226123227123228123229123230123231123232123233123234123235123236123237123238123239123240123241123242123243123244123245123246123247123248123249123250123251123252123253123254123255123256123257123258123259123260123261123262123263123264123265123266123267123268123269123270123271123272123273123274123275123276123277123278123279123280123281123282123283123284123285123286123287123288123289123290123291123292123293123294123295123296123297123298123299123300123301123302123303123304123305123306123307123308123309123310123311123312123313123314123315123316123317123318123319123320123321123322123323123324123325123326123327123328123329123330123331123332123333123334123335123336123337123338123339123340123341123342123343123344123345123346123347123348123349123350123351123352123353123354123355123356123357123358123359123360123361123362123363123364123365123366123367123368123369123370123371123372123373123374123375123376123377123378123379123380123381123382123383123384123385123386123387123388123389123390123391123392123393123394123395123396123397123398123399123400123401123402123403123404123405123406123407123408123409123410123411123412123413123414123415123416123417123418123419123420123421123422123423123424123425123426123427123428123429123430123431123432123433123434123435123436123437123438123439123440123441123442123443123444123445123446123447123448123449123450123451123452123453123454123455123456123457123458123459123460123461123462123463123464123465123466123467123468123469123470123471123472123473123474123475123476123477123478123479123480123481123482123483123484123485123486123487123488123489123490123491123492123493123494123495123496123497123498123499123500123501123502123503123504123505123506123507123508123509123510123511123512123513123514123515123516123517123518123519123520123521123522123523123524123525123526123527123528123529123530123531123532123533123534123535123536123537123538123539123540123541123542123543123544123545123546123547123548123549123550123551123552123553123554123555123556123557123558123559123560123561123562123563123564123565123566123567123568123569123570123571123572123573123574123575123576123577123578123579123580123581123582123583123584123585123586123587123588123589123590123591123592123593123594123595123596123597123598123599123600123601123602123603123604123605123606123607123608123609123610123611123612123613123614123615123616123617123618123619123620123621123622123623123624123625123626123627123628123629123630123631123632123633123634123635123636123637123638123639123640123641123642123643123644123645123646123647123648123649123650123651123652123653123654123655123656123657123658123659123660123661123662123663123664123665123666123667123668123669123670123671123672123673123674123675123676123677123678123679123680123681123682123683123684123685123686123687123688123689123690123691123692123693123694123695123696123697123698123699123700123701123702123703123704123705123706123707123708123709123710123711123712123713123714123715123716123717123718123719123720123721123722123723123724123725123726123727123728123729123730123731123732123733123734123735123736123737123738123739123740123741123742123743123744123745123746123747123748123749123750123751123752123753123754123755123756123757123758123759123760123761123762123763123764123765123766123767123768123769123770123771123772123773123774123775123776123777123778123779123780123781123782123783123784123785123786123787123788123789123790123791123792123793123794123795123796123797123798123799123800123801123802123803123804123805123806123807123808123809123810123811123812123813123814123815123816123817123818123819123820123821123822123823123824123825123826123827123828123829123830123831123832123833123834123835123836123837123838123839123840123841123842123843123844123845123846123847123848123849123850123851123852123853123854123855123856123857123858123859123860123861123862123863123864123865123866123867123868123869123870123871123872123873123874123875123876123877123878123879123880123881123882123883123884123885123886123887123888123889123890123891123892123893123894123895123896123897123898123899123900123901123902123903123904123905123906123907123908123909123910123911123912123913123914123915123916123917123918123919123920123921123922123923123924123925123926123927123928123929123930123931123932123933123934123935123936123937123938123939123940123941123942123943123944123945123946123947123948123949123950123951123952123953123954123955123956123957123958123959123960123961123962123963123964123965123966123967123968123969123970123971123972123973123974123975123976123977123978123979123980123981123982123983123984123985123986123987123988123989123990123991123992123993123994123995123996123997123998123999124000124001124002124003124004124005124006124007124008124009124010124011124012124013124014124015124016124017124018124019124020124021124022124023124024124025124026124027124028124029124030124031124032124033124034124035124036124037124038124039124040124041124042124043124044124045124046124047124048124049124050124051124052124053124054124055124056124057124058124059124060124061124062124063124064124065124066124067124068124069124070124071124072124073124074124075124076124077124078124079124080124081124082124083124084124085124086124087124088124089124090124091124092124093124094124095124096124097124098124099124100124101124102124103124104124105124106124107124108124109124110124111124112124113124114124115124116124117124118124119124120124121124122124123124124124125124126124127124128124129124130124131124132124133124134124135124136124137124138124139124140124141124142124143124144124145124146124147124148124149124150124151124152124153124154124155124156124157124158124159124160124161124162124163124164124165124166124167124168124169124170124171124172124173124174124175124176124177124178124179124180124181124182124183124184124185124186124187124188124189124190124191124192124193124194124195124196124197124198124199124200124201124202124203124204124205124206124207124208124209124210124211124212124213124214124215124216124217124218124219124220124221124222124223124224124225124226124227124228124229124230124231124232124233124234124235124236124237124238124239124240124241124242124243124244124245124246124247124248124249124250124251124252124253124254124255124256124257124258124259124260124261124262124263124264124265124266124267124268124269124270124271124272124273124274124275124276124277124278124279124280124281124282124283124284124285124286124287124288124289124290124291124292124293124294124295124296124297124298124299124300124301124302124303124304124305124306124307124308124309124310124311124312124313124314124315124316124317124318124319124320124321124322124323124324124325124326124327124328124329124330124331124332124333124334124335124336124337124338124339124340124341124342124343124344124345124346124347124348124349124350124351124352124353124354124355124356124357124358124359124360124361124362124363124364124365124366124367124368124369124370124371124372124373124374124375124376124377124378124379124380124381124382124383124384124385124386124387124388124389124390124391124392124393124394124395124396124397124398124399124400124401124402124403124404124405124406124407124408124409124410124411124412124413124414124415124416124417124418124419124420124421124422124423124424124425124426124427124428124429124430124431124432124433124434124435124436124437124438124439124440124441124442124443124444124445124446124447124448124449124450124451124452124453124454124455124456124457124458124459124460124461124462124463124464124465124466124467124468124469124470124471124472124473124474124475124476124477124478124479124480124481124482124483124484124485124486124487124488124489124490124491124492124493124494124495124496124497124498124499124500124501124502124503124504124505124506124507124508124509124510124511124512124513124514124515124516124517124518124519124520124521124522124523124524124525124526124527124528124529124530124531124532124533124534124535124536124537124538124539124540124541124542124543124544124545124546124547124548124549124550124551124552124553124554124555124556124557124558124559124560124561124562124563124564124565124566124567124568124569124570124571124572124573124574124575124576124577124578124579124580124581124582124583124584124585124586124587124588124589124590124591124592124593124594124595124596124597124598124599124600124601124602124603124604124605124606124607124608124609124610124611124612124613124614124615124616124617124618124619124620124621124622124623124624124625124626124627124628124629124630124631124632124633124634124635124636124637124638124639124640124641124642124643124644124645124646124647124648124649124650124651124652124653124654124655124656124657124658124659124660124661124662124663124664124665124666124667124668124669124670124671124672124673124674124675124676124677124678124679124680124681124682124683124684124685124686124687124688124689124690124691124692124693124694124695124696124697124698124699124700124701124702124703124704124705124706124707124708124709124710124711124712124713124714124715124716124717124718124719124720124721124722124723124724124725124726124727124728124729124730124731124732124733124734124735124736124737124738124739124740124741124742124743124744124745124746124747124748124749124750124751124752124753124754124755124756124757124758124759124760124761124762124763124764124765124766124767124768124769124770124771124772124773124774124775124776124777124778124779124780124781124782124783124784124785124786124787124788124789124790124791124792124793124794124795124796124797124798124799124800124801124802124803124804124805124806124807124808124809124810124811124812124813124814124815124816124817124818124819124820124821124822124823124824124825124826124827124828124829124830124831124832124833124834124835124836124837124838124839124840124841124842124843124844124845124846124847124848124849124850124851124852124853124854124855124856124857124858124859124860124861124862124863124864124865124866124867124868124869124870124871124872124873124874124875124876124877124878124879124880124881124882124883124884124885124886124887124888124889124890124891124892124893124894124895124896124897124898124899124900124901124902124903124904124905124906124907124908124909124910124911124912124913124914124915124916124917124918124919124920124921124922124923124924124925124926124927124928124929124930124931124932124933124934124935124936124937124938124939124940124941124942124943124944124945124946124947124948124949124950124951124952124953124954124955124956124957124958124959124960124961124962124963124964124965124966124967124968124969124970124971124972124973124974124975124976124977124978124979124980124981124982124983124984124985124986124987124988124989124990124991124992124993124994124995124996124997124998124999125000125001125002125003125004125005125006125007125008125009125010125011125012125013125014125015125016125017125018125019125020125021125022125023125024125025125026125027125028125029125030125031125032125033125034125035125036125037125038125039125040125041125042125043125044125045125046125047125048125049125050125051125052125053125054125055125056125057125058125059125060125061125062125063125064125065125066125067125068125069125070125071125072125073125074125075125076125077125078125079125080125081125082125083125084125085125086125087125088125089125090125091125092125093125094125095125096125097125098125099125100125101125102125103125104125105125106125107125108125109125110125111125112125113125114125115125116125117125118125119125120125121125122125123125124125125125126125127125128125129125130125131125132125133125134125135125136125137125138125139125140125141125142125143125144125145125146125147125148125149125150125151125152125153125154125155125156125157125158125159125160125161125162125163125164125165125166125167125168125169125170125171125172125173125174125175125176125177125178125179125180125181125182125183125184125185125186125187125188125189125190125191125192125193125194125195125196125197125198125199125200125201125202125203125204125205125206125207125208125209125210125211125212125213125214125215125216125217125218125219125220125221125222125223125224125225125226125227125228125229125230125231125232125233125234125235125236125237125238125239125240125241125242125243125244125245125246125247125248125249125250125251125252125253125254125255125256125257125258125259125260125261125262125263125264125265125266125267125268125269125270125271125272125273125274125275125276125277125278125279125280125281125282125283125284125285125286125287125288125289125290125291125292125293125294125295125296125297125298125299125300125301125302125303125304125305125306125307125308125309125310125311125312125313125314125315125316125317125318125319125320125321125322125323125324125325125326125327125328125329125330125331125332125333125334125335125336125337125338125339125340125341125342125343125344125345125346125347125348125349125350125351125352125353125354125355125356125357125358125359125360125361125362125363125364125365125366125367125368125369125370125371125372125373125374125375125376125377125378125379125380125381125382125383125384125385125386125387125388125389125390125391125392125393125394125395125396125397125398125399125400125401125402125403125404125405125406125407125408125409125410125411125412125413125414125415125416125417125418125419125420125421125422125423125424125425125426125427125428125429125430125431125432125433125434125435125436125437125438125439125440125441125442125443125444125445125446125447125448125449125450125451125452125453125454125455125456125457125458125459125460125461125462125463125464125465125466125467125468125469125470125471125472125473125474125475125476125477125478125479125480125481125482125483125484125485125486125487125488125489125490125491125492125493125494125495125496125497125498125499125500125501125502125503125504125505125506125507125508125509125510125511125512125513125514125515125516125517125518125519125520125521125522125523125524125525125526125527125528125529125530125531125532125533125534125535125536125537125538125539125540125541125542125543125544125545125546125547125548125549125550125551125552125553125554125555125556125557125558125559125560125561125562125563125564125565125566125567125568125569125570125571125572125573125574125575125576125577125578125579125580125581125582125583125584125585125586125587125588125589125590125591125592125593125594125595125596125597125598125599125600125601125602125603125604125605125606125607125608125609125610125611125612125613125614125615125616125617125618125619125620125621125622125623125624125625125626125627125628125629125630125631125632125633125634125635125636125637125638125639125640125641125642125643125644125645125646125647125648125649125650125651125652125653125654125655125656125657125658125659125660125661125662125663125664125665125666125667125668125669125670125671125672125673125674125675125676125677125678125679125680125681125682125683125684125685125686125687125688125689125690125691125692125693125694125695125696125697125698125699125700125701125702125703125704125705125706125707125708125709125710125711125712125713125714125715125716125717125718125719125720125721125722125723125724125725125726125727125728125729125730125731125732125733125734125735125736125737125738125739125740125741125742125743125744125745125746125747125748125749125750125751125752125753125754125755125756125757125758125759125760125761125762125763125764125765125766125767125768125769125770125771125772125773125774125775125776125777125778125779125780125781125782125783125784125785125786125787125788125789125790125791125792125793125794125795125796125797125798125799125800125801125802125803125804125805125806125807125808125809125810125811125812125813125814125815125816125817125818125819125820125821125822125823125824125825125826125827125828125829125830125831125832125833125834125835125836125837125838125839125840125841125842125843125844125845125846125847125848125849125850125851125852125853125854125855125856125857125858125859125860125861125862125863125864125865125866125867125868125869125870125871125872125873125874125875125876125877125878125879125880125881125882125883125884125885125886125887125888125889125890125891125892125893125894125895125896125897125898125899125900125901125902125903125904125905125906125907125908125909125910125911125912125913125914125915125916125917125918125919125920125921125922125923125924125925125926125927125928125929125930125931125932125933125934125935125936125937125938125939125940125941125942125943125944125945125946125947125948125949125950125951125952125953125954125955125956125957125958125959125960125961125962125963125964125965125966125967125968125969125970125971125972125973125974125975125976125977125978125979125980125981125982125983125984125985125986125987125988125989125990125991125992125993125994125995125996125997125998125999126000126001126002126003126004126005126006126007126008126009126010126011126012126013126014126015126016126017126018126019126020126021126022126023126024126025126026126027126028126029126030126031126032126033126034126035126036126037126038126039126040126041126042126043126044126045126046126047126048126049126050126051126052126053126054126055126056126057126058126059126060126061126062126063126064126065126066126067126068126069126070126071126072126073126074126075126076126077126078126079126080126081126082126083126084126085126086126087126088126089126090126091126092126093126094126095126096126097126098126099126100126101126102126103126104126105126106126107126108126109126110126111126112126113126114126115126116126117126118126119126120126121126122126123126124126125126126126127126128126129126130126131126132126133126134126135126136126137126138126139126140126141126142126143126144126145126146126147126148126149126150126151126152126153126154126155126156126157126158126159126160126161126162126163126164126165126166126167126168126169126170126171126172126173126174126175126176126177126178126179126180126181126182126183126184126185126186126187126188126189126190126191126192126193126194126195126196126197126198126199126200126201126202126203126204126205126206126207126208126209126210126211126212126213126214126215126216126217126218126219126220126221126222126223126224126225126226126227126228126229126230126231126232126233126234126235126236126237126238126239126240126241126242126243126244126245126246126247126248126249126250126251126252126253126254126255126256126257126258126259126260126261126262126263126264126265126266126267126268126269126270126271126272126273126274126275126276126277126278126279126280126281126282126283126284126285126286126287126288126289126290126291126292126293126294126295126296126297126298126299126300126301126302126303126304126305126306126307126308126309126310126311126312126313126314126315126316126317126318126319126320126321126322126323126324126325126326126327126328126329126330126331126332126333126334126335126336126337126338126339126340126341126342126343126344126345126346126347126348126349126350126351126352126353126354126355126356126357126358126359126360126361126362126363126364126365126366126367126368126369126370126371126372126373126374126375126376126377126378126379126380126381126382126383126384126385126386126387126388126389126390126391126392126393126394126395126396126397126398126399126400126401126402126403126404126405126406126407126408126409126410126411126412126413126414126415126416126417126418126419126420126421126422126423126424126425126426126427126428126429126430126431126432126433126434126435126436126437126438126439126440126441126442126443126444126445126446126447126448126449126450126451126452126453126454126455126456126457126458126459126460126461126462126463126464126465126466126467126468126469126470126471126472126473126474126475126476126477126478126479126480126481126482126483126484126485126486126487126488126489126490126491126492126493126494126495126496126497126498126499126500126501126502126503126504126505126506126507126508126509126510126511126512126513126514126515126516126517126518126519126520126521126522126523126524126525126526126527126528126529126530126531126532126533126534126535126536126537126538126539126540126541126542126543126544126545126546126547126548126549126550126551126552126553126554126555126556126557126558126559126560126561126562126563126564126565126566126567126568126569126570126571126572126573126574126575126576126577126578126579126580126581126582126583126584126585126586126587126588126589126590126591126592126593126594126595126596126597126598126599126600126601126602126603126604126605126606126607126608126609126610126611126612126613126614126615126616126617126618126619126620126621126622126623126624126625126626126627126628126629126630126631126632126633126634126635126636126637126638126639126640126641126642126643126644126645126646126647126648126649126650126651126652126653126654126655126656126657126658126659126660126661126662126663126664126665126666126667126668126669126670126671126672126673126674126675126676126677126678126679126680126681126682126683126684126685126686126687126688126689126690126691126692126693126694126695126696126697126698126699126700126701126702126703126704126705126706126707126708126709126710126711126712126713126714126715126716126717126718126719126720126721126722126723126724126725126726126727126728126729126730126731126732126733126734126735126736126737126738126739126740126741126742126743126744126745126746126747126748126749126750126751126752126753126754126755126756126757126758126759126760126761126762126763126764126765126766126767126768126769126770126771126772126773126774126775126776126777126778126779126780126781126782126783126784126785126786126787126788126789126790126791126792126793126794126795126796126797126798126799126800126801126802126803126804126805126806126807126808126809126810126811126812126813126814126815126816126817126818126819126820126821126822126823126824126825126826126827126828126829126830126831126832126833126834126835126836126837126838126839126840126841126842126843126844126845126846126847126848126849126850126851126852126853126854126855126856126857126858126859126860126861126862126863126864126865126866126867126868126869126870126871126872126873126874126875126876126877126878126879126880126881126882126883126884126885126886126887126888126889126890126891126892126893126894126895126896126897126898126899126900126901126902126903126904126905126906126907126908126909126910126911126912126913126914126915126916126917126918126919126920126921126922126923126924126925126926126927126928126929126930126931126932126933126934126935126936126937126938126939126940126941126942126943126944126945126946126947126948126949126950126951126952126953126954126955126956126957126958126959126960126961126962126963126964126965126966126967126968126969126970126971126972126973126974126975126976126977126978126979126980126981126982126983126984126985126986126987126988126989126990126991126992126993126994126995126996126997126998126999127000127001127002127003127004127005127006127007127008127009127010127011127012127013127014127015127016127017127018127019127020127021127022127023127024127025127026127027127028127029127030127031127032127033127034127035127036127037127038127039127040127041127042127043127044127045127046127047127048127049127050127051127052127053127054127055127056127057127058127059127060127061127062127063127064127065127066127067127068127069127070127071127072127073127074127075127076127077127078127079127080127081127082127083127084127085127086127087127088127089127090127091127092127093127094127095127096127097127098127099127100127101127102127103127104127105127106127107127108127109127110127111127112127113127114127115127116127117127118127119127120127121127122127123127124127125127126127127127128127129127130127131127132127133127134127135127136127137127138127139127140127141127142127143127144127145127146127147127148127149127150127151127152127153127154127155127156127157127158127159127160127161127162127163127164127165127166127167127168127169127170127171127172127173127174127175127176127177127178127179127180127181127182127183127184127185127186127187127188127189127190127191127192127193127194127195127196127197127198127199127200127201127202127203127204127205127206127207127208127209127210127211127212127213127214127215127216127217127218127219127220127221127222127223127224127225127226127227127228127229127230127231127232127233127234127235127236127237127238127239127240127241127242127243127244127245127246127247127248127249127250127251127252127253127254127255127256127257127258127259127260127261127262127263127264127265127266127267127268127269127270127271127272127273127274127275127276127277127278127279127280127281127282127283127284127285127286127287127288127289127290127291127292127293127294127295127296127297127298127299127300127301127302127303127304127305127306127307127308127309127310127311127312127313127314127315127316127317127318127319127320127321127322127323127324127325127326127327127328127329127330127331127332127333127334127335127336127337127338127339127340127341127342127343127344127345127346127347127348127349127350127351127352127353127354127355127356127357127358127359127360127361127362127363127364127365127366127367127368127369127370127371127372127373127374127375127376127377127378127379127380127381127382127383127384127385127386127387127388127389127390127391127392127393127394127395127396127397127398127399127400127401127402127403127404127405127406127407127408127409127410127411127412127413127414127415127416127417127418127419127420127421127422127423127424127425127426127427127428127429127430127431127432127433127434127435127436127437127438127439127440127441127442127443127444127445127446127447127448127449127450127451127452127453127454127455127456127457127458127459127460127461127462127463127464127465127466127467127468127469127470127471127472127473127474127475127476127477127478127479127480127481127482127483127484127485127486127487127488127489127490127491127492127493127494127495127496127497127498127499127500127501127502127503127504127505127506127507127508127509127510127511127512127513127514127515127516127517127518127519127520127521127522127523127524127525127526127527127528127529127530127531127532127533127534127535127536127537127538127539127540127541127542127543127544127545127546127547127548127549127550127551127552127553127554127555127556127557127558127559127560127561127562127563127564127565127566127567127568127569127570127571127572127573127574127575127576127577127578127579127580127581127582127583127584127585127586127587127588127589127590127591127592127593127594127595127596127597127598127599127600127601127602127603127604127605127606127607127608127609127610127611127612127613127614127615127616127617127618127619127620127621127622127623127624127625127626127627127628127629127630127631127632127633127634127635127636127637127638127639127640127641127642127643127644127645127646127647127648127649127650127651127652127653127654127655127656127657127658127659127660127661127662127663127664127665127666127667127668127669127670127671127672127673127674127675127676127677127678127679127680127681127682127683127684127685127686127687127688127689127690127691127692127693127694127695127696127697127698127699127700127701127702127703127704127705127706127707127708127709127710127711127712127713127714127715127716127717127718127719127720127721127722127723127724127725127726127727127728127729127730127731127732127733127734127735127736127737127738127739127740127741127742127743127744127745127746127747127748127749127750127751127752127753127754127755127756127757127758127759127760127761127762127763127764127765127766127767127768127769127770127771127772127773127774127775127776127777127778127779127780127781127782127783127784127785127786127787127788127789127790127791127792127793127794127795127796127797127798127799127800127801127802127803127804127805127806127807127808127809127810127811127812127813127814127815127816127817127818127819127820127821127822127823127824127825127826127827127828127829127830127831127832127833127834127835127836127837127838127839127840127841127842127843127844127845127846127847127848127849127850127851127852127853127854127855127856127857127858127859127860127861127862127863127864127865127866127867127868127869127870127871127872127873127874127875127876127877127878127879127880127881127882127883127884127885127886127887127888127889127890127891127892127893127894127895127896127897127898127899127900127901127902127903127904127905127906127907127908127909127910127911127912127913127914127915127916127917127918127919127920127921127922127923127924127925127926127927127928127929127930127931127932127933127934127935127936127937127938127939127940127941127942127943127944127945127946127947127948127949127950127951127952127953127954127955127956127957127958127959127960127961127962127963127964127965127966127967127968127969127970127971127972127973127974127975127976127977127978127979127980127981127982127983127984127985127986127987127988127989127990127991127992127993127994127995127996127997127998127999128000128001128002128003128004128005128006128007128008128009128010128011128012128013128014128015128016128017128018128019128020128021128022128023128024128025128026128027128028128029128030128031128032128033128034128035128036128037128038128039128040128041128042128043128044128045128046128047128048128049128050128051128052128053128054128055128056128057128058128059128060128061128062128063128064128065128066128067128068128069128070128071128072128073128074128075128076128077128078128079128080128081128082128083128084128085128086128087128088128089128090128091128092128093128094128095128096128097128098128099128100128101128102128103128104128105128106128107128108128109128110128111128112128113128114128115128116128117128118128119128120128121128122128123128124128125128126128127128128128129128130128131128132128133128134128135128136128137128138128139128140128141128142128143128144128145128146128147128148128149128150128151128152128153128154128155128156128157128158128159128160128161128162128163128164128165128166128167128168128169128170128171128172128173128174128175128176128177128178128179128180128181128182128183128184128185128186128187128188128189128190128191128192128193128194128195128196128197128198128199128200128201128202128203128204128205128206128207128208128209128210128211128212128213128214128215128216128217128218128219128220128221128222128223128224128225128226128227128228128229128230128231128232128233128234128235128236128237128238128239128240128241128242128243128244128245128246128247128248128249128250128251128252128253128254128255128256128257128258128259128260128261128262128263128264128265128266128267128268128269128270128271128272128273128274128275128276128277128278128279128280128281128282128283128284128285128286128287128288128289128290128291128292128293128294128295128296128297128298128299128300128301128302128303128304128305128306128307128308128309128310128311128312128313128314128315128316128317128318128319128320128321128322128323128324128325128326128327128328128329128330128331128332128333128334128335128336128337128338128339128340128341128342128343128344128345128346128347128348128349128350128351128352128353128354128355128356128357128358128359128360128361128362128363128364128365128366128367128368128369128370128371128372128373128374128375128376128377128378128379128380128381128382128383128384128385128386128387128388128389128390128391128392128393128394128395128396128397128398128399128400128401128402128403128404128405128406128407128408128409128410128411128412128413128414128415128416128417128418128419128420128421128422128423128424128425128426128427128428128429128430128431128432128433128434128435128436128437128438128439128440128441128442128443128444128445128446128447128448128449128450128451128452128453128454128455128456128457128458128459128460128461128462128463128464128465128466128467128468128469128470128471128472128473128474128475128476128477128478128479128480128481128482128483128484128485128486128487128488128489128490128491128492128493128494128495128496128497128498128499128500128501128502128503128504128505128506128507128508128509128510128511128512128513128514128515128516128517128518128519128520128521128522128523128524128525128526128527128528128529128530128531128532128533128534128535128536128537128538128539128540128541128542128543128544128545128546128547128548128549128550128551128552128553128554128555128556128557128558128559128560128561128562128563128564128565128566128567128568128569128570128571128572128573128574128575128576128577128578128579128580128581128582128583128584128585128586128587128588128589128590128591128592128593128594128595128596128597128598128599128600128601128602128603128604128605128606128607128608128609128610128611128612128613128614128615128616128617128618128619128620128621128622128623128624128625128626128627128628128629128630128631128632128633128634128635128636128637128638128639128640128641128642128643128644128645128646128647128648128649128650128651128652128653128654128655128656128657128658128659128660128661128662128663128664128665128666128667128668128669128670128671128672128673128674128675128676128677128678128679128680128681128682128683128684128685128686128687128688128689128690128691128692128693128694128695128696128697128698128699128700128701128702128703128704128705128706128707128708128709128710128711128712128713128714128715128716128717128718128719128720128721128722128723128724128725128726128727128728128729128730128731128732128733128734128735128736128737128738128739128740128741128742128743128744128745128746128747128748128749128750128751128752128753128754128755128756128757128758128759128760128761128762128763128764128765128766128767128768128769128770128771128772128773128774128775128776128777128778128779128780128781128782128783128784128785128786128787128788128789128790128791128792128793128794128795128796128797128798128799128800128801128802128803128804128805128806128807128808128809128810128811128812128813128814128815128816128817128818128819128820128821128822128823128824128825128826128827128828128829128830128831128832128833128834128835128836128837128838128839128840128841128842128843128844128845128846128847128848128849128850128851128852128853128854128855128856128857128858128859128860128861128862128863128864128865128866128867128868128869128870128871128872128873128874128875128876128877128878128879128880128881128882128883128884128885128886128887128888128889128890128891128892128893128894128895128896128897128898128899128900128901128902128903128904128905128906128907128908128909128910128911128912128913128914128915128916128917128918128919128920128921128922128923128924128925128926128927128928128929128930128931128932128933128934128935128936128937128938128939128940128941128942128943128944128945128946128947128948128949128950128951128952128953128954128955128956128957128958128959128960128961128962128963128964128965128966128967128968128969128970128971128972128973128974128975128976128977128978128979128980128981128982128983128984128985128986128987128988128989128990128991128992128993128994128995128996128997128998128999129000129001129002129003129004129005129006129007129008129009129010129011129012129013129014129015129016129017129018129019129020129021129022129023129024129025129026129027129028129029129030129031129032129033129034129035129036129037129038129039129040129041129042129043129044129045129046129047129048129049129050129051129052129053129054129055129056129057129058129059129060129061129062129063129064129065129066129067129068129069129070129071129072129073129074129075129076129077129078129079129080129081129082129083129084129085129086129087129088129089129090129091129092129093129094129095129096129097129098129099129100129101129102129103129104129105129106129107129108129109129110129111129112129113129114129115129116129117129118129119129120129121129122129123129124129125129126129127129128129129129130129131129132129133129134129135129136129137129138129139129140129141129142129143129144129145129146129147129148129149129150129151129152129153129154129155129156129157129158129159129160129161129162129163129164129165129166129167129168129169129170129171129172129173129174129175129176129177129178129179129180129181129182129183129184129185129186129187129188129189129190129191129192129193129194129195129196129197129198129199129200129201129202129203129204129205129206129207129208129209129210129211129212129213129214129215129216129217129218129219129220129221129222129223129224129225129226129227129228129229129230129231129232129233129234129235129236129237129238129239129240129241129242129243129244129245129246129247129248129249129250129251129252129253129254129255129256129257129258129259129260129261129262129263129264129265129266129267129268129269129270129271129272129273129274129275129276129277129278129279129280129281129282129283129284129285129286129287129288129289129290129291129292129293129294129295129296129297129298129299129300129301129302129303129304129305129306129307129308129309129310129311129312129313129314129315129316129317129318129319129320129321129322129323129324129325129326129327129328129329129330129331129332129333129334129335129336129337129338129339129340129341129342129343129344129345129346129347129348129349129350129351129352129353129354129355129356129357129358129359129360129361129362129363129364129365129366129367129368129369129370129371129372129373129374129375129376129377129378129379129380129381129382129383129384129385129386129387129388129389129390129391129392129393129394129395129396129397129398129399129400129401129402129403129404129405129406129407129408129409129410129411129412129413129414129415129416129417129418129419129420129421129422129423129424129425129426129427129428129429129430129431129432129433129434129435129436129437129438129439129440129441129442129443129444129445129446129447129448129449129450129451129452129453129454129455129456129457129458129459129460129461129462129463129464129465129466129467129468129469129470129471129472129473129474129475129476129477129478129479129480129481129482129483129484129485129486129487129488129489129490129491129492129493129494129495129496129497129498129499129500129501129502129503129504129505129506129507129508129509129510129511129512129513129514129515129516129517129518129519129520129521129522129523129524129525129526129527129528129529129530129531129532129533129534129535129536129537129538129539129540129541129542129543129544129545129546129547129548129549129550129551129552129553129554129555129556129557129558129559129560129561129562129563129564129565129566129567129568129569129570129571129572129573129574129575129576129577129578129579129580129581129582129583129584129585129586129587129588129589129590129591129592129593129594129595129596129597129598129599129600129601129602129603129604129605129606129607129608129609129610129611129612129613129614129615129616129617129618129619129620129621129622129623129624129625129626129627129628129629129630129631129632129633129634129635129636129637129638129639129640129641129642129643129644129645129646129647129648129649129650129651129652129653129654129655129656129657129658129659129660129661129662129663129664129665129666129667129668129669129670129671129672129673129674129675129676129677129678129679129680129681129682129683129684129685129686129687129688129689129690129691129692129693129694129695129696129697129698129699129700129701129702129703129704129705129706129707129708129709129710129711129712129713129714129715129716129717129718129719129720129721129722129723129724129725129726129727129728129729129730129731129732129733129734129735129736129737129738129739129740129741129742129743129744129745129746129747129748129749129750129751129752129753129754129755129756129757129758129759129760129761129762129763129764129765129766129767129768129769129770129771129772129773129774129775129776129777129778129779129780129781129782129783129784129785129786129787129788129789129790129791129792129793129794129795129796129797129798129799129800129801129802129803129804129805129806129807129808129809129810129811129812129813129814129815129816129817129818129819129820129821129822129823129824129825129826129827129828129829129830129831129832129833129834129835129836129837129838129839129840129841129842129843129844129845129846129847129848129849129850129851129852129853129854129855129856129857129858129859129860129861129862129863129864129865129866129867129868129869129870129871129872129873129874129875129876129877129878129879129880129881129882129883129884129885129886129887129888129889129890129891129892129893129894129895129896129897129898129899129900129901129902129903129904129905129906129907129908129909129910129911129912129913129914129915129916129917129918129919129920129921129922129923129924129925129926129927129928129929129930129931129932129933129934129935129936129937129938129939129940129941129942129943129944129945129946129947129948129949129950129951129952129953129954129955129956129957129958129959129960129961129962129963129964129965129966129967129968129969129970129971129972129973129974129975129976129977129978129979129980129981129982129983129984129985129986129987129988129989129990129991129992129993129994129995129996129997129998129999130000130001130002130003130004130005130006130007130008130009130010130011130012130013130014130015130016130017130018130019130020130021130022130023130024130025130026130027130028130029130030130031130032130033130034130035130036130037130038130039130040130041130042130043130044130045130046130047130048130049130050130051130052130053130054130055130056130057130058130059130060130061130062130063130064130065130066130067130068130069130070130071130072130073130074130075130076130077130078130079130080130081130082130083130084130085130086130087130088130089130090130091130092130093130094130095130096130097130098130099130100130101130102130103130104130105130106130107130108130109130110130111130112130113130114130115130116130117130118130119130120130121130122130123130124130125130126130127130128130129130130130131130132130133130134130135130136130137130138130139130140130141130142130143130144130145130146130147130148130149130150130151130152130153130154130155130156130157130158130159130160130161130162130163130164130165130166130167130168130169130170130171130172130173130174130175130176130177130178130179130180130181130182130183130184130185130186130187130188130189130190130191130192130193130194130195130196130197130198130199130200130201130202130203130204130205130206130207130208130209130210130211130212130213130214130215130216130217130218130219130220130221130222130223130224130225130226130227130228130229130230130231130232130233130234130235130236130237130238130239130240130241130242130243130244130245130246130247130248130249130250130251130252130253130254130255130256130257130258130259130260130261130262130263130264130265130266130267130268130269130270130271130272130273130274130275130276130277130278130279130280130281130282130283130284130285130286130287130288130289130290130291130292130293130294130295130296130297130298130299130300130301130302130303130304130305130306130307130308130309130310130311130312130313130314130315130316130317130318130319130320130321130322130323130324130325130326130327130328130329130330130331130332130333130334130335130336130337130338130339130340130341130342130343130344130345130346130347130348130349130350130351130352130353130354130355130356130357130358130359130360130361130362130363130364130365130366130367130368130369130370130371130372130373130374130375130376130377130378130379130380130381130382130383130384130385130386130387130388130389130390130391130392130393130394130395130396130397130398130399130400130401130402130403130404130405130406130407130408130409130410130411130412130413130414130415130416130417130418130419130420130421130422130423130424130425130426130427130428130429130430130431130432130433130434130435130436130437130438130439130440130441130442130443130444130445130446130447130448130449130450130451130452130453130454130455130456130457130458130459130460130461130462130463130464130465130466130467130468130469130470130471130472130473130474130475130476130477130478130479130480130481130482130483130484130485130486130487130488130489130490130491130492130493130494130495130496130497130498130499130500130501130502130503130504130505130506130507130508130509130510130511130512130513130514130515130516130517130518130519130520130521130522130523130524130525130526130527130528130529130530130531130532130533130534130535130536130537130538130539130540130541130542130543130544130545130546130547130548130549130550130551130552130553130554130555130556130557130558130559130560130561130562130563130564130565130566130567130568130569130570130571130572130573130574130575130576130577130578130579130580130581130582130583130584130585130586130587130588130589130590130591130592130593130594130595130596130597130598130599130600130601130602130603130604130605130606130607130608130609130610130611130612130613130614130615130616130617130618130619130620130621130622130623130624130625130626130627130628130629130630130631130632130633130634130635130636130637130638130639130640130641130642130643130644130645130646130647130648130649130650130651130652130653130654130655130656130657130658130659130660130661130662130663130664130665130666130667130668130669130670130671130672130673130674130675130676130677130678130679130680130681130682130683130684130685130686130687130688130689130690130691130692130693130694130695130696130697130698130699130700130701130702130703130704130705130706130707130708130709130710130711130712130713130714130715130716130717130718130719130720130721130722130723130724130725130726130727130728130729130730130731130732130733130734130735130736130737130738130739130740130741130742130743130744130745130746130747130748130749130750130751130752130753130754130755130756130757130758130759130760130761130762130763130764130765130766130767130768130769130770130771130772130773130774130775130776130777130778130779130780130781130782130783130784130785130786130787130788130789130790130791130792130793130794130795130796130797130798130799130800130801130802130803130804130805130806130807130808130809130810130811130812130813130814130815130816130817130818130819130820130821130822130823130824130825130826130827130828130829130830130831130832130833130834130835130836130837130838130839130840130841130842130843130844130845130846130847130848130849130850130851130852130853130854130855130856130857130858130859130860130861130862130863130864130865130866130867130868130869130870130871130872130873130874130875130876130877130878130879130880130881130882130883130884130885130886130887130888130889130890130891130892130893130894130895130896130897130898130899130900130901130902130903130904130905130906130907130908130909130910130911130912130913130914130915130916130917130918130919130920130921130922130923130924130925130926130927130928130929130930130931130932130933130934130935130936130937130938130939130940130941130942130943130944130945130946130947130948130949130950130951130952130953130954130955130956130957130958130959130960130961130962130963130964130965130966130967130968130969130970130971130972130973130974130975130976130977130978130979130980130981130982130983130984130985130986130987130988130989130990130991130992130993130994130995130996130997130998130999131000131001131002131003131004131005131006131007131008131009131010131011131012131013131014131015131016131017131018131019131020131021131022131023131024131025131026131027131028131029131030131031131032131033131034131035131036131037131038131039131040131041131042131043131044131045131046131047131048131049131050131051131052131053131054131055131056131057131058131059131060131061131062131063131064131065131066131067131068131069131070131071131072131073131074131075131076131077131078131079131080131081131082131083131084131085131086131087131088131089131090131091131092131093131094131095131096131097131098131099131100131101131102131103131104131105131106131107131108131109131110131111131112131113131114131115131116131117131118131119131120131121131122131123131124131125131126131127131128131129131130131131131132131133131134131135131136131137131138131139131140131141131142131143131144131145131146131147131148131149131150131151131152131153131154131155131156131157131158131159131160131161131162131163131164131165131166131167131168131169131170131171131172131173131174131175131176131177131178131179131180131181131182131183131184131185131186131187131188131189131190131191131192131193131194131195131196131197131198131199131200131201131202131203131204131205131206131207131208131209131210131211131212131213131214131215131216131217131218131219131220131221131222131223131224131225131226131227131228131229131230131231131232131233131234131235131236131237131238131239131240131241131242131243131244131245131246131247131248131249131250131251131252131253131254131255131256131257131258131259131260131261131262131263131264131265131266131267131268131269131270131271131272131273131274131275131276131277131278131279131280131281131282131283131284131285131286131287131288131289131290131291131292131293131294131295131296131297131298131299131300131301131302131303131304131305131306131307131308131309131310131311131312131313131314131315131316131317131318131319131320131321131322131323131324131325131326131327131328131329131330131331131332131333131334131335131336131337131338131339131340131341131342131343131344131345131346131347131348131349131350131351131352131353131354131355131356131357131358131359131360131361131362131363131364131365131366131367131368131369131370131371131372131373131374131375131376131377131378131379131380131381131382131383131384131385131386131387131388131389131390131391131392131393131394131395131396131397131398131399131400131401131402131403131404131405131406131407131408131409131410131411131412131413131414131415131416131417131418131419131420131421131422131423131424131425131426131427131428131429131430131431131432131433131434131435131436131437131438131439131440131441131442131443131444131445131446131447131448131449131450131451131452131453131454131455131456131457131458131459131460131461131462131463131464131465131466131467131468131469131470131471131472131473131474131475131476131477131478131479131480131481131482131483131484131485131486131487131488131489131490131491131492131493131494131495131496131497131498131499131500131501131502131503131504131505131506131507131508131509131510131511131512131513131514131515131516131517131518131519131520131521131522131523131524131525131526131527131528131529131530131531131532131533131534131535131536131537131538131539131540131541131542131543131544131545131546131547131548131549131550131551131552131553131554131555131556131557131558131559131560131561131562131563131564131565131566131567131568131569131570131571131572131573131574131575131576131577131578131579131580131581131582131583131584131585131586131587131588131589131590131591131592131593131594131595131596131597131598131599131600131601131602131603131604131605131606131607131608131609131610131611131612131613131614131615131616131617131618131619131620131621131622131623131624131625131626131627131628131629131630131631131632131633131634131635131636131637131638131639131640131641131642131643131644131645131646131647131648131649131650131651131652131653131654131655131656131657131658131659131660131661131662131663131664131665131666131667131668131669131670131671131672131673131674131675131676131677131678131679131680131681131682131683131684131685131686131687131688131689131690131691131692131693131694131695131696131697131698131699131700131701131702131703131704131705131706131707131708131709131710131711131712131713131714131715131716131717131718131719131720131721131722131723131724131725131726131727131728131729131730131731131732131733131734131735131736131737131738131739131740131741131742131743131744131745131746131747131748131749131750131751131752131753131754131755131756131757131758131759131760131761131762131763131764131765131766131767131768131769131770131771131772131773131774131775131776131777131778131779131780131781131782131783131784131785131786131787131788131789131790131791131792131793131794131795131796131797131798131799131800131801131802131803131804131805131806131807131808131809131810131811131812131813131814131815131816131817131818131819131820131821131822131823131824131825131826131827131828131829131830131831131832131833131834131835131836131837131838131839131840131841131842131843131844131845131846131847131848131849131850131851131852131853131854131855131856131857131858131859131860131861131862131863131864131865131866131867131868131869131870131871131872131873131874131875131876131877131878131879131880131881131882131883131884131885131886131887131888131889131890131891131892131893131894131895131896131897131898131899131900131901131902131903131904131905131906131907131908131909131910131911131912131913131914131915131916131917131918131919131920131921131922131923131924131925131926131927131928131929131930131931131932131933131934131935131936131937131938131939131940131941131942131943131944131945131946131947131948131949131950131951131952131953131954131955131956131957131958131959131960131961131962131963131964131965131966131967131968131969131970131971131972131973131974131975131976131977131978131979131980131981131982131983131984131985131986131987131988131989131990131991131992131993131994131995131996131997131998131999132000132001132002132003132004132005132006132007132008132009132010132011132012132013132014132015132016132017132018132019132020132021132022132023132024132025132026132027132028132029132030132031132032132033132034132035132036132037132038132039132040132041132042132043132044132045132046132047132048132049132050132051132052132053132054132055132056132057132058132059132060132061132062132063132064132065132066132067132068132069132070132071132072132073132074132075132076132077132078132079132080132081132082132083132084132085132086132087132088132089132090132091132092132093132094132095132096132097132098132099132100132101132102132103132104132105132106132107132108132109132110132111132112132113132114132115132116132117132118132119132120132121132122132123132124132125132126132127132128132129132130132131132132132133132134132135132136132137132138132139132140132141132142132143132144132145132146132147132148132149132150132151132152132153132154132155132156132157132158132159132160132161132162132163132164132165132166132167132168132169132170132171132172132173132174132175132176132177132178132179132180132181132182132183132184132185132186132187132188132189132190132191132192132193132194132195132196132197132198132199132200132201132202132203132204132205132206132207132208132209132210132211132212132213132214132215132216132217132218132219132220132221132222132223132224132225132226132227132228132229132230132231132232132233132234132235132236132237132238132239132240132241132242132243132244132245132246132247132248132249132250132251132252132253132254132255132256132257132258132259132260132261132262132263132264132265132266132267132268132269132270132271132272132273132274132275132276132277132278132279132280132281132282132283132284132285132286132287132288132289132290132291132292132293132294132295132296132297132298132299132300132301132302132303132304132305132306132307132308132309132310132311132312132313132314132315132316132317132318132319132320132321132322132323132324132325132326132327132328132329132330132331132332132333132334132335132336132337132338132339132340132341132342132343132344132345132346132347132348132349132350132351132352132353132354132355132356132357132358132359132360132361132362132363132364132365132366132367132368132369132370132371132372132373132374132375132376132377132378132379132380132381132382132383132384132385132386132387132388132389132390132391132392132393132394132395132396132397132398132399132400132401132402132403132404132405132406132407132408132409132410132411132412132413132414132415132416132417132418132419132420132421132422132423132424132425132426132427132428132429132430132431132432132433132434132435132436132437132438132439132440132441132442132443132444132445132446132447132448132449132450132451132452132453132454132455132456132457132458132459132460132461132462132463132464132465132466132467132468132469132470132471132472132473132474132475132476132477132478132479132480132481132482132483132484132485132486132487132488132489132490132491132492132493132494132495132496132497132498132499132500132501132502132503132504132505132506132507132508132509132510132511132512132513132514132515132516132517132518132519132520132521132522132523132524132525132526132527132528132529132530132531132532132533132534132535132536132537132538132539132540132541132542132543132544132545132546132547132548132549132550132551132552132553132554132555132556132557132558132559132560132561132562132563132564132565132566132567132568132569132570132571132572132573132574132575132576132577132578132579132580132581132582132583132584132585132586132587132588132589132590132591132592132593132594132595132596132597132598132599132600132601132602132603132604132605132606132607132608132609132610132611132612132613132614132615132616132617132618132619132620132621132622132623132624132625132626132627132628132629132630132631132632132633132634132635132636132637132638132639132640132641132642132643132644132645132646132647132648132649132650132651132652132653132654132655132656132657132658132659132660132661132662132663132664132665132666132667132668132669132670132671132672132673132674132675132676132677132678132679132680132681132682132683132684132685132686132687132688132689132690132691132692132693132694132695132696132697132698132699132700132701132702132703132704132705132706132707132708132709132710132711132712132713132714132715132716132717132718132719132720132721132722132723132724132725132726132727132728132729132730132731132732132733132734132735132736132737132738132739132740132741132742132743132744132745132746132747132748132749132750132751132752132753132754132755132756132757132758132759132760132761132762132763132764132765132766132767132768132769132770132771132772132773132774132775132776132777132778132779132780132781132782132783132784132785132786132787132788132789132790132791132792132793132794132795132796132797132798132799132800132801132802132803132804132805132806132807132808132809132810132811132812132813132814132815132816132817132818132819132820132821132822132823132824132825132826132827132828132829132830132831132832132833132834132835132836132837132838132839132840132841132842132843132844132845132846132847132848132849132850132851132852132853132854132855132856132857132858132859132860132861132862132863132864132865132866132867132868132869132870132871132872132873132874132875132876132877132878132879132880132881132882132883132884132885132886132887132888132889132890132891132892132893132894132895132896132897132898132899132900132901132902132903132904132905132906132907132908132909132910132911132912132913132914132915132916132917132918132919132920132921132922132923132924132925132926132927132928132929132930132931132932132933132934132935132936132937132938132939132940132941132942132943132944132945132946132947132948132949132950132951132952132953132954132955132956132957132958132959132960132961132962132963132964132965132966132967132968132969132970132971132972132973132974132975132976132977132978132979132980132981132982132983132984132985132986132987132988132989132990132991132992132993132994132995132996132997132998132999133000133001133002133003133004133005133006133007133008133009133010133011133012133013133014133015133016133017133018133019133020133021133022133023133024133025133026133027133028133029133030133031133032133033133034133035133036133037133038133039133040133041133042133043133044133045133046133047133048133049133050133051133052133053133054133055133056133057133058133059133060133061133062133063133064133065133066133067133068133069133070133071133072133073133074133075133076133077133078133079133080133081133082133083133084133085133086133087133088133089133090133091133092133093133094133095133096133097133098133099133100133101133102133103133104133105133106133107133108133109133110133111133112133113133114133115133116133117133118133119133120133121133122133123133124133125133126133127133128133129133130133131133132133133133134133135133136133137133138133139133140133141133142133143133144133145133146133147133148133149133150133151133152133153133154133155133156133157133158133159133160133161133162133163133164133165133166133167133168133169133170133171133172133173133174133175133176133177133178133179133180133181133182133183133184133185133186133187133188133189133190133191133192133193133194133195133196133197133198133199133200133201133202133203133204133205133206133207133208133209133210133211133212133213133214133215133216133217133218133219133220133221133222133223133224133225133226133227133228133229133230133231133232133233133234133235133236133237133238133239133240133241133242133243133244133245133246133247133248133249133250133251133252133253133254133255133256133257133258133259133260133261133262133263133264133265133266133267133268133269133270133271133272133273133274133275133276133277133278133279133280133281133282133283133284133285133286133287133288133289133290133291133292133293133294133295133296133297133298133299133300133301133302133303133304133305133306133307133308133309133310133311133312133313133314133315133316133317133318133319133320133321133322133323133324133325133326133327133328133329133330133331133332133333133334133335133336133337133338133339133340133341133342133343133344133345133346133347133348133349133350133351133352133353133354133355133356133357133358133359133360133361133362133363133364133365133366133367133368133369133370133371133372133373133374133375133376133377133378133379133380133381133382133383133384133385133386133387133388133389133390133391133392133393133394133395133396133397133398133399133400133401133402133403133404133405133406133407133408133409133410133411133412133413133414133415133416133417133418133419133420133421133422133423133424133425133426133427133428133429133430133431133432133433133434133435133436133437133438133439133440133441133442133443133444133445133446133447133448133449133450133451133452133453133454133455133456133457133458133459133460133461133462133463133464133465133466133467133468133469133470133471133472133473133474133475133476133477133478133479133480133481133482133483133484133485133486133487133488133489133490133491133492133493133494133495133496133497133498133499133500133501133502133503133504133505133506133507133508133509133510133511133512133513133514133515133516133517133518133519133520133521133522133523133524133525133526133527133528133529133530133531133532133533133534133535133536133537133538133539133540133541133542133543133544133545133546133547133548133549133550133551133552133553133554133555133556133557133558133559133560133561133562133563133564133565133566133567133568133569133570133571133572133573133574133575133576133577133578133579133580133581133582133583133584133585133586133587133588133589133590133591133592133593133594133595133596133597133598133599133600133601133602133603133604133605133606133607133608133609133610133611133612133613133614133615133616133617133618133619133620133621133622133623133624133625133626133627133628133629133630133631133632133633133634133635133636133637133638133639133640133641133642133643133644133645133646133647133648133649133650133651133652133653133654133655133656133657133658133659133660133661133662133663133664133665133666133667133668133669133670133671133672133673133674133675133676133677133678133679133680133681133682133683133684133685133686133687133688133689133690133691133692133693133694133695133696133697133698133699133700133701133702133703133704133705133706133707133708133709133710133711133712133713133714133715133716133717133718133719133720133721133722133723133724133725133726133727133728133729133730133731133732133733133734133735133736133737133738133739133740133741133742133743133744133745133746133747133748133749133750133751133752133753133754133755133756133757133758133759133760133761133762133763133764133765133766133767133768133769133770133771133772133773133774133775133776133777133778133779133780133781133782133783133784133785133786133787133788133789133790133791133792133793133794133795133796133797133798133799133800133801133802133803133804133805133806133807133808133809133810133811133812133813133814133815133816133817133818133819133820133821133822133823133824133825133826133827133828133829133830133831133832133833133834133835133836133837133838133839133840133841133842133843133844133845133846133847133848133849133850133851133852133853133854133855133856133857133858133859133860133861133862133863133864133865133866133867133868133869133870133871133872133873133874133875133876133877133878133879133880133881133882133883133884133885133886133887133888133889133890133891133892133893133894133895133896133897133898133899133900133901133902133903133904133905133906133907133908133909133910133911133912133913133914133915133916133917133918133919133920133921133922133923133924133925133926133927133928133929133930133931133932133933133934133935133936133937133938133939133940133941133942133943133944133945133946133947133948133949133950133951133952133953133954133955133956133957133958133959133960133961133962133963133964133965133966133967133968133969133970133971133972133973133974133975133976133977133978133979133980133981133982133983133984133985133986133987133988133989133990133991133992133993133994133995133996133997133998133999134000134001134002134003134004134005134006134007134008134009134010134011134012134013134014134015134016134017134018134019134020134021134022134023134024134025134026134027134028134029134030134031134032134033134034134035134036134037134038134039134040134041134042134043134044134045134046134047134048134049134050134051134052134053134054134055134056134057134058134059134060134061134062134063134064134065134066134067134068134069134070134071134072134073134074134075134076134077134078134079134080134081134082134083134084134085134086134087134088134089134090134091134092134093134094134095134096134097134098134099134100134101134102134103134104134105134106134107134108134109134110134111134112134113134114134115134116134117134118134119134120134121134122134123134124134125134126134127134128134129134130134131134132134133134134134135134136134137134138134139134140134141134142134143134144134145134146134147134148134149134150134151134152134153134154134155134156134157134158134159134160134161134162134163134164134165134166134167134168134169134170134171134172134173134174134175134176134177134178134179134180134181134182134183134184134185134186134187134188134189134190134191134192134193134194134195134196134197134198134199134200134201134202134203134204134205134206134207134208134209134210134211134212134213134214134215134216134217134218134219134220134221134222134223134224134225134226134227134228134229134230134231134232134233134234134235134236134237134238134239134240134241134242134243134244134245134246134247134248134249134250134251134252134253134254134255134256134257134258134259134260134261134262134263134264134265134266134267134268134269134270134271134272134273134274134275134276134277134278134279134280134281134282134283134284134285134286134287134288134289134290134291134292134293134294134295134296134297134298134299134300134301134302134303134304134305134306134307134308134309134310134311134312134313134314134315134316134317134318134319134320134321134322134323134324134325134326134327134328134329134330134331134332134333134334134335134336134337134338134339134340134341134342134343134344134345134346134347134348134349134350134351134352134353134354134355134356134357134358134359134360134361134362134363134364134365134366134367134368134369134370134371134372134373134374134375134376134377134378134379134380134381134382134383134384134385134386134387134388134389134390134391134392134393134394134395134396134397134398134399134400134401134402134403134404134405134406134407134408134409134410134411134412134413134414134415134416134417134418134419134420134421134422134423134424134425134426134427134428134429134430134431134432134433134434134435134436134437134438134439134440134441134442134443134444134445134446134447134448134449134450134451134452134453134454134455134456134457134458134459134460134461134462134463134464134465134466134467134468134469134470134471134472134473134474134475134476134477134478134479134480134481134482134483134484134485134486134487134488134489134490134491134492134493134494134495134496134497134498134499134500134501134502134503134504134505134506134507134508134509134510134511134512134513134514134515134516134517134518134519134520134521134522134523134524134525134526134527134528134529134530134531134532134533134534134535134536134537134538134539134540134541134542134543134544134545134546134547134548134549134550134551134552134553134554134555134556134557134558134559134560134561134562134563134564134565134566134567134568134569134570134571134572134573134574134575134576134577134578134579134580134581134582134583134584134585134586134587134588134589134590134591134592134593134594134595134596134597134598134599134600134601134602134603134604134605134606134607134608134609134610134611134612134613134614134615134616134617134618134619134620134621134622134623134624134625134626134627134628134629134630134631134632134633134634134635134636134637134638134639134640134641134642134643134644134645134646134647134648134649134650134651134652134653134654134655134656134657134658134659134660134661134662134663134664134665134666134667134668134669134670134671134672134673134674134675134676134677134678134679134680134681134682134683134684134685134686134687134688134689134690134691134692134693134694134695134696134697134698134699134700134701134702134703134704134705134706134707134708134709134710134711134712134713134714134715134716134717134718134719134720134721134722134723134724134725134726134727134728134729134730134731134732134733134734134735134736134737134738134739134740134741134742134743134744134745134746134747134748134749134750134751134752134753134754134755134756134757134758134759134760134761134762134763134764134765134766134767134768134769134770134771134772134773134774134775134776134777134778134779134780134781134782134783134784134785134786134787134788134789134790134791134792134793134794134795134796134797134798134799134800134801134802134803134804134805134806134807134808134809134810134811134812134813134814134815134816134817134818134819134820134821134822134823134824134825134826134827134828134829134830134831134832134833134834134835134836134837134838134839134840134841134842134843134844134845134846134847134848134849134850134851134852134853134854134855134856134857134858134859134860134861134862134863134864134865134866134867134868134869134870134871134872134873134874134875134876134877134878134879134880134881134882134883134884134885134886134887134888134889134890134891134892134893134894134895134896134897134898134899134900134901134902134903134904134905134906134907134908134909134910134911134912134913134914134915134916134917134918134919134920134921134922134923134924134925134926134927134928134929134930134931134932134933134934134935134936134937134938134939134940134941134942134943134944134945134946134947134948134949134950134951134952134953134954134955134956134957134958134959134960134961134962134963134964134965134966134967134968134969134970134971134972134973134974134975134976134977134978134979134980134981134982134983134984134985134986134987134988134989134990134991134992134993134994134995134996134997134998134999135000135001135002135003135004135005135006135007135008135009135010135011135012135013135014135015135016135017135018135019135020135021135022135023135024135025135026135027135028135029135030135031135032135033135034135035135036135037135038135039135040135041135042135043135044135045135046135047135048135049135050135051135052135053135054135055135056135057135058135059135060135061135062135063135064135065135066135067135068135069135070135071135072135073135074135075135076135077135078135079135080135081135082135083135084135085135086135087135088135089135090135091135092135093135094135095135096135097135098135099135100135101135102135103135104135105135106135107135108135109135110135111135112135113135114135115135116135117135118135119135120135121135122135123135124135125135126135127135128135129135130135131135132135133135134135135135136135137135138135139135140135141135142135143135144135145135146135147135148135149135150135151135152135153135154135155135156135157135158135159135160135161135162135163135164135165135166135167135168135169135170135171135172135173135174135175135176135177135178135179135180135181135182135183135184135185135186135187135188135189135190135191135192135193135194135195135196135197135198135199135200135201135202135203135204135205135206135207135208135209135210135211135212135213135214135215135216135217135218135219135220135221135222135223135224135225135226135227135228135229135230135231135232135233135234135235135236135237135238135239135240135241135242135243135244135245135246135247135248135249135250135251135252135253135254135255135256135257135258135259135260135261135262135263135264135265135266135267135268135269135270135271135272135273135274135275135276135277135278135279135280135281135282135283135284135285135286135287135288135289135290135291135292135293135294135295135296135297135298135299135300135301135302135303135304135305135306135307135308135309135310135311135312135313135314135315135316135317135318135319135320135321135322135323135324135325135326135327135328135329135330135331135332135333135334135335135336135337135338135339135340135341135342135343135344135345135346135347135348135349135350135351135352135353135354135355135356135357135358135359135360135361135362135363135364135365135366135367135368135369135370135371135372135373135374135375135376135377135378135379135380135381135382135383135384135385135386135387135388135389135390135391135392135393135394135395135396135397135398135399135400135401135402135403135404135405135406135407135408135409135410135411135412135413135414135415135416135417135418135419135420135421135422135423135424135425135426135427135428135429135430135431135432135433135434135435135436135437135438135439135440135441135442135443135444135445135446135447135448135449135450135451135452135453135454135455135456135457135458135459135460135461135462135463135464135465135466135467135468135469135470135471135472135473135474135475135476135477135478135479135480135481135482135483135484135485135486135487135488135489135490135491135492135493135494135495135496135497135498135499135500135501135502135503135504135505135506135507135508135509135510135511135512135513135514135515135516135517135518135519135520135521135522135523135524135525135526135527135528135529135530135531135532135533135534135535135536135537135538135539135540135541135542135543135544135545135546135547135548135549135550135551135552135553135554135555135556135557135558135559135560135561135562135563135564135565135566135567135568135569135570135571135572135573135574135575135576135577135578135579135580135581135582135583135584135585135586135587135588135589135590135591135592135593135594135595135596135597135598135599135600135601135602135603135604135605135606135607135608135609135610135611135612135613135614135615135616135617135618135619135620135621135622135623135624135625135626135627135628135629135630135631135632135633135634135635135636135637135638135639135640135641135642135643135644135645135646135647135648135649135650135651135652135653135654135655135656135657135658135659135660135661135662135663135664135665135666135667135668135669135670135671135672135673135674135675135676135677135678135679135680135681135682135683135684135685135686135687135688135689135690135691135692135693135694135695135696135697135698135699135700135701135702135703135704135705135706135707135708135709135710135711135712135713135714135715135716135717135718135719135720135721135722135723135724135725135726135727135728135729135730135731135732135733135734135735135736135737135738135739135740135741135742135743135744135745135746135747135748135749135750135751135752135753135754135755135756135757135758135759135760135761135762135763135764135765135766135767135768135769135770135771135772135773135774135775135776135777135778135779135780135781135782135783135784135785135786135787135788135789135790135791135792135793135794135795135796135797135798135799135800135801135802135803135804135805135806135807135808135809135810135811135812135813135814135815135816135817135818135819135820135821135822135823135824135825135826135827135828135829135830135831135832135833135834135835135836135837135838135839135840135841135842135843135844135845135846135847135848135849135850135851135852135853135854135855135856135857135858135859135860135861135862135863135864135865135866135867135868135869135870135871135872135873135874135875135876135877135878135879135880135881135882135883135884135885135886135887135888135889135890135891135892135893135894135895135896135897135898135899135900135901135902135903135904135905135906135907135908135909135910135911135912135913135914135915135916135917135918135919135920135921135922135923135924135925135926135927135928135929135930135931135932135933135934135935135936135937135938135939135940135941135942135943135944135945135946135947135948135949135950135951135952135953135954135955135956135957135958135959135960135961135962135963135964135965135966135967135968135969135970135971135972135973135974135975135976135977135978135979135980135981135982135983135984135985135986135987135988135989135990135991135992135993135994135995135996135997135998135999136000136001136002136003136004136005136006136007136008136009136010136011136012136013136014136015136016136017136018136019136020136021136022136023136024136025136026136027136028136029136030136031136032136033136034136035136036136037136038136039136040136041136042136043136044136045136046136047136048136049136050136051136052136053136054136055136056136057136058136059136060136061136062136063136064136065136066136067136068136069136070136071136072136073136074136075136076136077136078136079136080136081136082136083136084136085136086136087136088136089136090136091136092136093136094136095136096136097136098136099136100136101136102136103136104136105136106136107136108136109136110136111136112136113136114136115136116136117136118136119136120136121136122136123136124136125136126136127136128136129136130136131136132136133136134136135136136136137136138136139136140136141136142136143136144136145136146136147136148136149136150136151136152136153136154136155136156136157136158136159136160136161136162136163136164136165136166136167136168136169136170136171136172136173136174136175136176136177136178136179136180136181136182136183136184136185136186136187136188136189136190136191136192136193136194136195136196136197136198136199136200136201136202136203136204136205136206136207136208136209136210136211136212136213136214136215136216136217136218136219136220136221136222136223136224136225136226136227136228136229136230136231136232136233136234136235136236136237136238136239136240136241136242136243136244136245136246136247136248136249136250136251136252136253136254136255136256136257136258136259136260136261136262136263136264136265136266136267136268136269136270136271136272136273136274136275136276136277136278136279136280136281136282136283136284136285136286136287136288136289136290136291136292136293136294136295136296136297136298136299136300136301136302136303136304136305136306136307136308136309136310136311136312136313136314136315136316136317136318136319136320136321136322136323136324136325136326136327136328136329136330136331136332136333136334136335136336136337136338136339136340136341136342136343136344136345136346136347136348136349136350136351136352136353136354136355136356136357136358136359136360136361136362136363136364136365136366136367136368136369136370136371136372136373136374136375136376136377136378136379136380136381136382136383136384136385136386136387136388136389136390136391136392136393136394136395136396136397136398136399136400136401136402136403136404136405136406136407136408136409136410136411136412136413136414136415136416136417136418136419136420136421136422136423136424136425136426136427136428136429136430136431136432136433136434136435136436136437136438136439136440136441136442136443136444136445136446136447136448136449136450136451136452136453136454136455136456136457136458136459136460136461136462136463136464136465136466136467136468136469136470136471136472136473136474136475136476136477136478136479136480136481136482136483136484136485136486136487136488136489136490136491136492136493136494136495136496136497136498136499136500136501136502136503136504136505136506136507136508136509136510136511136512136513136514136515136516136517136518136519136520136521136522136523136524136525136526136527136528136529136530136531136532136533136534136535136536136537136538136539136540136541136542136543136544136545136546136547136548136549136550136551136552136553136554136555136556136557136558136559136560136561136562136563136564136565136566136567136568136569136570136571136572136573136574136575136576136577136578136579136580136581136582136583136584136585136586136587136588136589136590136591136592136593136594136595136596136597136598136599136600136601136602136603136604136605136606136607136608136609136610136611136612136613136614136615136616136617136618136619136620136621136622136623136624136625136626136627136628136629136630136631136632136633136634136635136636136637136638136639136640136641136642136643136644136645136646136647136648136649136650136651136652136653136654136655136656136657136658136659136660136661136662136663136664136665136666136667136668136669136670136671136672136673136674136675136676136677136678136679136680136681136682136683136684136685136686136687136688136689136690136691136692136693136694136695136696136697136698136699136700136701136702136703136704136705136706136707136708136709136710136711136712136713136714136715136716136717136718136719136720136721136722136723136724136725136726136727136728136729136730136731136732136733136734136735136736136737136738136739136740136741136742136743136744136745136746136747136748136749136750136751136752136753136754136755136756136757136758136759136760136761136762136763136764136765136766136767136768136769136770136771136772136773136774136775136776136777136778136779136780136781136782136783136784136785136786136787136788136789136790136791136792136793136794136795136796136797136798136799136800136801136802136803136804136805136806136807136808136809136810136811136812136813136814136815136816136817136818136819136820136821136822136823136824136825136826136827136828136829136830136831136832136833136834136835136836136837136838136839136840136841136842136843136844136845136846136847136848136849136850136851136852136853136854136855136856136857136858136859136860136861136862136863136864136865136866136867136868136869136870136871136872136873136874136875136876136877136878136879136880136881136882136883136884136885136886136887136888136889136890136891136892136893136894136895136896136897136898136899136900136901136902136903136904136905136906136907136908136909136910136911136912136913136914136915136916136917136918136919136920136921136922136923136924136925136926136927136928136929136930136931136932136933136934136935136936136937136938136939136940136941136942136943136944136945136946136947136948136949136950136951136952136953136954136955136956136957136958136959136960136961136962136963136964136965136966136967136968136969136970136971136972136973136974136975136976136977136978136979136980136981136982136983136984136985136986136987136988136989136990136991136992136993136994136995136996136997136998136999137000137001137002137003137004137005137006137007137008137009137010137011137012137013137014137015137016137017137018137019137020137021137022137023137024137025137026137027137028137029137030137031137032137033137034137035137036137037137038137039137040137041137042137043137044137045137046137047137048137049137050137051137052137053137054137055137056137057137058137059137060137061137062137063137064137065137066137067137068137069137070137071137072137073137074137075137076137077137078137079137080137081137082137083137084137085137086137087137088137089137090137091137092137093137094137095137096137097137098137099137100137101137102137103137104137105137106137107137108137109137110137111137112137113137114137115137116137117137118137119137120137121137122137123137124137125137126137127137128137129137130137131137132137133137134137135137136137137137138137139137140137141137142137143137144137145137146137147137148137149137150137151137152137153137154137155137156137157137158137159137160137161137162137163137164137165137166137167137168137169137170137171137172137173137174137175137176137177137178137179137180137181137182137183137184137185137186137187137188137189137190137191137192137193137194137195137196137197137198137199137200137201137202137203137204137205137206137207137208137209137210137211137212137213137214137215137216137217137218137219137220137221137222137223137224137225137226137227137228137229137230137231137232137233137234137235137236137237137238137239137240137241137242137243137244137245137246137247137248137249137250137251137252137253137254137255137256137257137258137259137260137261137262137263137264137265137266137267137268137269137270137271137272137273137274137275137276137277137278137279137280137281137282137283137284137285137286137287137288137289137290137291137292137293137294137295137296137297137298137299137300137301137302137303137304137305137306137307137308137309137310137311137312137313137314137315137316137317137318137319137320137321137322137323137324137325137326137327137328137329137330137331137332137333137334137335137336137337137338137339137340137341137342137343137344137345137346137347137348137349137350137351137352137353137354137355137356137357137358137359137360137361137362137363137364137365137366137367137368137369137370137371137372137373137374137375137376137377137378137379137380137381137382137383137384137385137386137387137388137389137390137391137392137393137394137395137396137397137398137399137400137401137402137403137404137405137406137407137408137409137410137411137412137413137414137415137416137417137418137419137420137421137422137423137424137425137426137427137428137429137430137431137432137433137434137435137436137437137438137439137440137441137442137443137444137445137446137447137448137449137450137451137452137453137454137455137456137457137458137459137460137461137462137463137464137465137466137467137468137469137470137471137472137473137474137475137476137477137478137479137480137481137482137483137484137485137486137487137488137489137490137491137492137493137494137495137496137497137498137499137500137501137502137503137504137505137506137507137508137509137510137511137512137513137514137515137516137517137518137519137520137521137522137523137524137525137526137527137528137529137530137531137532137533137534137535137536137537137538137539137540137541137542137543137544137545137546137547137548137549137550137551137552137553137554137555137556137557137558137559137560137561137562137563137564137565137566137567137568137569137570137571137572137573137574137575137576137577137578137579137580137581137582137583137584137585137586137587137588137589137590137591137592137593137594137595137596137597137598137599137600137601137602137603137604137605137606137607137608137609137610137611137612137613137614137615137616137617137618137619137620137621137622137623137624137625137626137627137628137629137630137631137632137633137634137635137636137637137638137639137640137641137642137643137644137645137646137647137648137649137650137651137652137653137654137655137656137657137658137659137660137661137662137663137664137665137666137667137668137669137670137671137672137673137674137675137676137677137678137679137680137681137682137683137684137685137686137687137688137689137690137691137692137693137694137695137696137697137698137699137700137701137702137703137704137705137706137707137708137709137710137711137712137713137714137715137716137717137718137719137720137721137722137723137724137725137726137727137728137729137730137731137732137733137734137735137736137737137738137739137740137741137742137743137744137745137746137747137748137749137750137751137752137753137754137755137756137757137758137759137760137761137762137763137764137765137766137767137768137769137770137771137772137773137774137775137776137777137778137779137780137781137782137783137784137785137786137787137788137789137790137791137792137793137794137795137796137797137798137799137800137801137802137803137804137805137806137807137808137809137810137811137812137813137814137815137816137817137818137819137820137821137822137823137824137825137826137827137828137829137830137831137832137833137834137835137836137837137838137839137840137841137842137843137844137845137846137847137848137849137850137851137852137853137854137855137856137857137858137859137860137861137862137863137864137865137866137867137868137869137870137871137872137873137874137875137876137877137878137879137880137881137882137883137884137885137886137887137888137889137890137891137892137893137894137895137896137897137898137899137900137901137902137903137904137905137906137907137908137909137910137911137912137913137914137915137916137917137918137919137920137921137922137923137924137925137926137927137928137929137930137931137932137933137934137935137936137937137938137939137940137941137942137943137944137945137946137947137948137949137950137951137952137953137954137955137956137957137958137959137960137961137962137963137964137965137966137967137968137969137970137971137972137973137974137975137976137977137978137979137980137981137982137983137984137985137986137987137988137989137990137991137992137993137994137995137996137997137998137999138000138001138002138003138004138005138006138007138008138009138010138011138012138013138014138015138016138017138018138019138020138021138022138023138024138025138026138027138028138029138030138031138032138033138034138035138036138037138038138039138040138041138042138043138044138045138046138047138048138049138050138051138052138053138054138055138056138057138058138059138060138061138062138063138064138065138066138067138068138069138070138071138072138073138074138075138076138077138078138079138080138081138082138083138084138085138086138087138088138089138090138091138092138093138094138095138096138097138098138099138100138101138102138103138104138105138106138107138108138109138110138111138112138113138114138115138116138117138118138119138120138121138122138123138124138125138126138127138128138129138130138131138132138133138134138135138136138137138138138139138140138141138142138143138144138145138146138147138148138149138150138151138152138153138154138155138156138157138158138159138160138161138162138163138164138165138166138167138168138169138170138171138172138173138174138175138176138177138178138179138180138181138182138183138184138185138186138187138188138189138190138191138192138193138194138195138196138197138198138199138200138201138202138203138204138205138206138207138208138209138210138211138212138213138214138215138216138217138218138219138220138221138222138223138224138225138226138227138228138229138230138231138232138233138234138235138236138237138238138239138240138241138242138243138244138245138246138247138248138249138250138251138252138253138254138255138256138257138258138259138260138261138262138263138264138265138266138267138268138269138270138271138272138273138274138275138276138277138278138279138280138281138282138283138284138285138286138287138288138289138290138291138292138293138294138295138296138297138298138299138300138301138302138303138304138305138306138307138308138309138310138311138312138313138314138315138316138317138318138319138320138321138322138323138324138325138326138327138328138329138330138331138332138333138334138335138336138337138338138339138340138341138342138343138344138345138346138347138348138349138350138351138352138353138354138355138356138357138358138359138360138361138362138363138364138365138366138367138368138369138370138371138372138373138374138375138376138377138378138379138380138381138382138383138384138385138386138387138388138389138390138391138392138393138394138395138396138397138398138399138400138401138402138403138404138405138406138407138408138409138410138411138412138413138414138415138416138417138418138419138420138421138422138423138424138425138426138427138428138429138430138431138432138433138434138435138436138437138438138439138440138441138442138443138444138445138446138447138448138449138450138451138452138453138454138455138456138457138458138459138460138461138462138463138464138465138466138467138468138469138470138471138472138473138474138475138476138477138478138479138480138481138482138483138484138485138486138487138488138489138490138491138492138493138494138495138496138497138498138499138500138501138502138503138504138505138506138507138508138509138510138511138512138513138514138515138516138517138518138519138520138521138522138523138524138525138526138527138528138529138530138531138532138533138534138535138536138537138538138539138540138541138542138543138544138545138546138547138548138549138550138551138552138553138554138555138556138557138558138559138560138561138562138563138564138565138566138567138568138569138570138571138572138573138574138575138576138577138578138579138580138581138582138583138584138585138586138587138588138589138590138591138592138593138594138595138596138597138598138599138600138601138602138603138604138605138606138607138608138609138610138611138612138613138614138615138616138617138618138619138620138621138622138623138624138625138626138627138628138629138630138631138632138633138634138635138636138637138638138639138640138641138642138643138644138645138646138647138648138649138650138651138652138653138654138655138656138657138658138659138660138661138662138663138664138665138666138667138668138669138670138671138672138673138674138675138676138677138678138679138680138681138682138683138684138685138686138687138688138689138690138691138692138693138694138695138696138697138698138699138700138701138702138703138704138705138706138707138708138709138710138711138712138713138714138715138716138717138718138719138720138721138722138723138724138725138726138727138728138729138730138731138732138733138734138735138736138737138738138739138740138741138742138743138744138745138746138747138748138749138750138751138752138753138754138755138756138757138758138759138760138761138762138763138764138765138766138767138768138769138770138771138772138773138774138775138776138777138778138779138780138781138782138783138784138785138786138787138788138789138790138791138792138793138794138795138796138797138798138799138800138801138802138803138804138805138806138807138808138809138810138811138812138813138814138815138816138817138818138819138820138821138822138823138824138825138826138827138828138829138830138831138832138833138834138835138836138837138838138839138840138841138842138843138844138845138846138847138848138849138850138851138852138853138854138855138856138857138858138859138860138861138862138863138864138865138866138867138868138869138870138871138872138873138874138875138876138877138878138879138880138881138882138883138884138885138886138887138888138889138890138891138892138893138894138895138896138897138898138899138900138901138902138903138904138905138906138907138908138909138910138911138912138913138914138915138916138917138918138919138920138921138922138923138924138925138926138927138928138929138930138931138932138933138934138935138936138937138938138939138940138941138942138943138944138945138946138947138948138949138950138951138952138953138954138955138956138957138958138959138960138961138962138963138964138965138966138967138968138969138970138971138972138973138974138975138976138977138978138979138980138981138982138983138984138985138986138987138988138989138990138991138992138993138994138995138996138997138998138999139000139001139002139003139004139005139006139007139008139009139010139011139012139013139014139015139016139017139018139019139020139021139022139023139024139025139026139027139028139029139030139031139032139033139034139035139036139037139038139039139040139041139042139043139044139045139046139047139048139049139050139051139052139053139054139055139056139057139058139059139060139061139062139063139064139065139066139067139068139069139070139071139072139073139074139075139076139077139078139079139080139081139082139083139084139085139086139087139088139089139090139091139092139093139094139095139096139097139098139099139100139101139102139103139104139105139106139107139108139109139110139111139112139113139114139115139116139117139118139119139120139121139122139123139124139125139126139127139128139129139130139131139132139133139134139135139136139137139138139139139140139141139142139143139144139145139146139147139148139149139150139151139152139153139154139155139156139157139158139159139160139161139162139163139164139165139166139167139168139169139170139171139172139173139174139175139176139177139178139179139180139181139182139183139184139185139186139187139188139189139190139191139192139193139194139195139196139197139198139199139200139201139202139203139204139205139206139207139208139209139210139211139212139213139214139215139216139217139218139219139220139221139222139223139224139225139226139227139228139229139230139231139232139233139234139235139236139237139238139239139240139241139242139243139244139245139246139247139248139249139250139251139252139253139254139255139256139257139258139259139260139261139262139263139264139265139266139267139268139269139270139271139272139273139274139275139276139277139278139279139280139281139282139283139284139285139286139287139288139289139290139291139292139293139294139295139296139297139298139299139300139301139302139303139304139305139306139307139308139309139310139311139312139313139314139315139316139317139318139319139320139321139322139323139324139325139326139327139328139329139330139331139332139333139334139335139336139337139338139339139340139341139342139343139344139345139346139347139348139349139350139351139352139353139354139355139356139357139358139359139360139361139362139363139364139365139366139367139368139369139370139371139372139373139374139375139376139377139378139379139380139381139382139383139384139385139386139387139388139389139390139391139392139393139394139395139396139397139398139399139400139401139402139403139404139405139406139407139408139409139410139411139412139413139414139415139416139417139418139419139420139421139422139423139424139425139426139427139428139429139430139431139432139433139434139435139436139437139438139439139440139441139442139443139444139445139446139447139448139449139450139451139452139453139454139455139456139457139458139459139460139461139462139463139464139465139466139467139468139469139470139471139472139473139474139475139476139477139478139479139480139481139482139483139484139485139486139487139488139489139490139491139492139493139494139495139496139497139498139499139500139501139502139503139504139505139506139507139508139509139510139511139512139513139514139515139516139517139518139519139520139521139522139523139524139525139526139527139528139529139530139531139532139533139534139535139536139537139538139539139540139541139542139543139544139545139546139547139548139549139550139551139552139553139554139555139556139557139558139559139560139561139562139563139564139565139566139567139568139569139570139571139572139573139574139575139576139577139578139579139580139581139582139583139584139585139586139587139588139589139590139591139592139593139594139595139596139597139598139599139600139601139602139603139604139605139606139607139608139609139610139611139612139613139614139615139616139617139618139619139620139621139622139623139624139625139626139627139628139629139630139631139632139633139634139635139636139637139638139639139640139641139642139643139644139645139646139647139648139649139650139651139652139653139654139655139656139657139658139659139660139661139662139663139664139665139666139667139668139669139670139671139672139673139674139675139676139677139678139679139680139681139682139683139684139685139686139687139688139689139690139691139692139693139694139695139696139697139698139699139700139701139702139703139704139705139706139707139708139709139710139711139712139713139714139715139716139717139718139719139720139721139722139723139724139725139726139727139728139729139730139731139732139733139734139735139736139737139738139739139740139741139742139743139744139745139746139747139748139749139750139751139752139753139754139755139756139757139758139759139760139761139762139763139764139765139766139767139768139769139770139771139772139773139774139775139776139777139778139779139780139781139782139783139784139785139786139787139788139789139790139791139792139793139794139795139796139797139798139799139800139801139802139803139804139805139806139807139808139809139810139811139812139813139814139815139816139817139818139819139820139821139822139823139824139825139826139827139828139829139830139831139832139833139834139835139836139837139838139839139840139841139842139843139844139845139846139847139848139849139850139851139852139853139854139855139856139857139858139859139860139861139862139863139864139865139866139867139868139869139870139871139872139873139874139875139876139877139878139879139880139881139882139883139884139885139886139887139888139889139890139891139892139893139894139895139896139897139898139899139900139901139902139903139904139905139906139907139908139909139910139911139912139913139914139915139916139917139918139919139920139921139922139923139924139925139926139927139928139929139930139931139932139933139934139935139936139937139938139939139940139941139942139943139944139945139946139947139948139949139950139951139952139953139954139955139956139957139958139959139960139961139962139963139964139965139966139967139968139969139970139971139972139973139974139975139976139977139978139979139980139981139982139983139984139985139986139987139988139989139990139991139992139993139994139995139996139997139998139999140000140001140002140003140004140005140006140007140008140009140010140011140012140013140014140015140016140017140018140019140020140021140022140023140024140025140026140027140028140029140030140031140032140033140034140035140036140037140038140039140040140041140042140043140044140045140046140047140048140049140050140051140052140053140054140055140056140057140058140059140060140061140062140063140064140065140066140067140068140069140070140071140072140073140074140075140076140077140078140079140080140081140082140083140084140085140086140087140088140089140090140091140092140093140094140095140096140097140098140099140100140101140102140103140104140105140106140107140108140109140110140111140112140113140114140115140116140117140118140119140120140121140122140123140124140125140126140127140128140129140130140131140132140133140134140135140136140137140138140139140140140141140142140143140144140145140146140147140148140149140150140151140152140153140154140155140156140157140158140159140160140161140162140163140164140165140166140167140168140169140170140171140172140173140174140175140176140177140178140179140180140181140182140183140184140185140186140187140188140189140190140191140192140193140194140195140196140197140198140199140200140201140202140203140204140205140206140207140208140209140210140211140212140213140214140215140216140217140218140219140220140221140222140223140224140225140226140227140228140229140230140231140232140233140234140235140236140237140238140239140240140241140242140243140244140245140246140247140248140249140250140251140252140253140254140255140256140257140258140259140260140261140262140263140264140265140266140267140268140269140270140271140272140273140274140275140276140277140278140279140280140281140282140283140284140285140286140287140288140289140290140291140292140293140294140295140296140297140298140299140300140301140302140303140304140305140306140307140308140309140310140311140312140313140314140315140316140317140318140319140320140321140322140323140324140325140326140327140328140329140330140331140332140333140334140335140336140337140338140339140340140341140342140343140344140345140346140347140348140349140350140351140352140353140354140355140356140357140358140359140360140361140362140363140364140365140366140367140368140369140370140371140372140373140374140375140376140377140378140379140380140381140382140383140384140385140386140387140388140389140390140391140392140393140394140395140396140397140398140399140400140401140402140403140404140405140406140407140408140409140410140411140412140413140414140415140416140417140418140419140420140421140422140423140424140425140426140427140428140429140430140431140432140433140434140435140436140437140438140439140440140441140442140443140444140445140446140447140448140449140450140451140452140453140454140455140456140457140458140459140460140461140462140463140464140465140466140467140468140469140470140471140472140473140474140475140476140477140478140479140480140481140482140483140484140485140486140487140488140489140490140491140492140493140494140495140496140497140498140499140500140501140502140503140504140505140506140507140508140509140510140511140512140513140514140515140516140517140518140519140520140521140522140523140524140525140526140527140528140529140530140531140532140533140534140535140536140537140538140539140540140541140542140543140544140545140546140547140548140549140550140551140552140553140554140555140556140557140558140559140560140561140562140563140564140565140566140567140568140569140570140571140572140573140574140575140576140577140578140579140580140581140582140583140584140585140586140587140588140589140590140591140592140593140594140595140596140597140598140599140600140601140602140603140604140605140606140607140608140609140610140611140612140613140614140615140616140617140618140619140620140621140622140623140624140625140626140627140628140629140630140631140632140633140634140635140636140637140638140639140640140641140642140643140644140645140646140647140648140649140650140651140652140653140654140655140656140657140658140659140660140661140662140663140664140665140666140667140668140669140670140671140672140673140674140675140676140677140678140679140680140681140682140683140684140685140686140687140688140689140690140691140692140693140694140695140696140697140698140699140700140701140702140703140704140705140706140707140708140709140710140711140712140713140714140715140716140717140718140719140720140721140722140723140724140725140726140727140728140729140730140731140732140733140734140735140736140737140738140739140740140741140742140743140744140745140746140747140748140749140750140751140752140753140754140755140756140757140758140759140760140761140762140763140764140765140766140767140768140769140770140771140772140773140774140775140776140777140778140779140780140781140782140783140784140785140786140787140788140789140790140791140792140793140794140795140796140797140798140799140800140801140802140803140804140805140806140807140808140809140810140811140812140813140814140815140816140817140818140819140820140821140822140823140824140825140826140827140828140829140830140831140832140833140834140835140836140837140838140839140840140841140842140843140844140845140846140847140848140849140850140851140852140853140854140855140856140857140858140859140860140861140862140863140864140865140866140867140868140869140870140871140872140873140874140875140876140877140878140879140880140881140882140883140884140885140886140887140888140889140890140891140892140893140894140895140896140897140898140899140900140901140902140903140904140905140906140907140908140909140910140911140912140913140914140915140916140917140918140919140920140921140922140923140924140925140926140927140928140929140930140931140932140933140934140935140936140937140938140939140940140941140942140943140944140945140946140947140948140949140950140951140952140953140954140955140956140957140958140959140960140961140962140963140964140965140966140967140968140969140970140971140972140973140974140975140976140977140978140979140980140981140982140983140984140985140986140987140988140989140990140991140992140993140994140995140996140997140998140999141000141001141002141003141004141005141006141007141008141009141010141011141012141013141014141015141016141017141018141019141020141021141022141023141024141025141026141027141028141029141030141031141032141033141034141035141036141037141038141039141040141041141042141043141044141045141046141047141048141049141050141051141052141053141054141055141056141057141058141059141060141061141062141063141064141065141066141067141068141069141070141071141072141073141074141075141076141077141078141079141080141081141082141083141084141085141086141087141088141089141090141091141092141093141094141095141096141097141098141099141100141101141102141103141104141105141106141107141108141109141110141111141112141113141114141115141116141117141118141119141120141121141122141123141124141125141126141127141128141129141130141131141132141133141134141135141136141137141138141139141140141141141142141143141144141145141146141147141148141149141150141151141152141153141154141155141156141157141158141159141160141161141162141163141164141165141166141167141168141169141170141171141172141173141174141175141176141177141178141179141180141181141182141183141184141185141186141187141188141189141190141191141192141193141194141195141196141197141198141199141200141201141202141203141204141205141206141207141208141209141210141211141212141213141214141215141216141217141218141219141220141221141222141223141224141225141226141227141228141229141230141231141232141233141234141235141236141237141238141239141240141241141242141243141244141245141246141247141248141249141250141251141252141253141254141255141256141257141258141259141260141261141262141263141264141265141266141267141268141269141270141271141272141273141274141275141276141277141278141279141280141281141282141283141284141285141286141287141288141289141290141291141292141293141294141295141296141297141298141299141300141301141302141303141304141305141306141307141308141309141310141311141312141313141314141315141316141317141318141319141320141321141322141323141324141325141326141327141328141329141330141331141332141333141334141335141336141337141338141339141340141341141342141343141344141345141346141347141348141349141350141351141352141353141354141355141356141357141358141359141360141361141362141363141364141365141366141367141368141369141370141371141372141373141374141375141376141377141378141379141380141381141382141383141384141385141386141387141388141389141390141391141392141393141394141395141396141397141398141399141400141401141402141403141404141405141406141407141408141409141410141411141412141413141414141415141416141417141418141419141420141421141422141423141424141425141426141427141428141429141430141431141432141433141434141435141436141437141438141439141440141441141442141443141444141445141446141447141448141449141450141451141452141453141454141455141456141457141458141459141460141461141462141463141464141465141466141467141468141469141470141471141472141473141474141475141476141477141478141479141480141481141482141483141484141485141486141487141488141489141490141491141492141493141494141495141496141497141498141499141500141501141502141503141504141505141506141507141508141509141510141511141512141513141514141515141516141517141518141519141520141521141522141523141524141525141526141527141528141529141530141531141532141533141534141535141536141537141538141539141540141541141542141543141544141545141546141547141548141549141550141551141552141553141554141555141556141557141558141559141560141561141562141563141564141565141566141567141568141569141570141571141572141573141574141575141576141577141578141579141580141581141582141583141584141585141586141587141588141589141590141591141592141593141594141595141596141597141598141599141600141601141602141603141604141605141606141607141608141609141610141611141612141613141614141615141616141617141618141619141620141621141622141623141624141625141626141627141628141629141630141631141632141633141634141635141636141637141638141639141640141641141642141643141644141645141646141647141648141649141650141651141652141653141654141655141656141657141658141659141660141661141662141663141664141665141666141667141668141669141670141671141672141673141674141675141676141677141678141679141680141681141682141683141684141685141686141687141688141689141690141691141692141693141694141695141696141697141698141699141700141701141702141703141704141705141706141707141708141709141710141711141712141713141714141715141716141717141718141719141720141721141722141723141724141725141726141727141728141729141730141731141732141733141734141735141736141737141738141739141740141741141742141743141744141745141746141747141748141749141750141751141752141753141754141755141756141757141758141759141760141761141762141763141764141765141766141767141768141769141770141771141772141773141774141775141776141777141778141779141780141781141782141783141784141785141786141787141788141789141790141791141792141793141794141795141796141797141798141799141800141801141802141803141804141805141806141807141808141809141810141811141812141813141814141815141816141817141818141819141820141821141822141823141824141825141826141827141828141829141830141831141832141833141834141835141836141837141838141839141840141841141842141843141844141845141846141847141848141849141850141851141852141853141854141855141856141857141858141859141860141861141862141863141864141865141866141867141868141869141870141871141872141873141874141875141876141877141878141879141880141881141882141883141884141885141886141887141888141889141890141891141892141893141894141895141896141897141898141899141900141901141902141903141904141905141906141907141908141909141910141911141912141913141914141915141916141917141918141919141920141921141922141923141924141925141926141927141928141929141930141931141932141933141934141935141936141937141938141939141940141941141942141943141944141945141946141947141948141949141950141951141952141953141954141955141956141957141958141959141960141961141962141963141964141965141966141967141968141969141970141971141972141973141974141975141976141977141978141979141980141981141982141983141984141985141986141987141988141989141990141991141992141993141994141995141996141997141998141999142000142001142002142003142004142005142006142007142008142009142010142011142012142013142014142015142016142017142018142019142020142021142022142023142024142025142026142027142028142029142030142031142032142033142034142035142036142037142038142039142040142041142042142043142044142045142046142047142048142049142050142051142052142053142054142055142056142057142058142059142060142061142062142063142064142065142066142067142068142069142070142071142072142073142074142075142076142077142078142079142080142081142082142083142084142085142086142087142088142089142090142091142092142093142094142095142096142097142098142099142100142101142102142103142104142105142106142107142108142109142110142111142112142113142114142115142116142117142118142119142120142121142122142123142124142125142126142127142128142129142130142131142132142133142134142135142136142137142138142139142140142141142142142143142144142145142146142147142148142149142150142151142152142153142154142155142156142157142158142159142160142161142162142163142164142165142166142167142168142169142170142171142172142173142174142175142176142177142178142179142180142181142182142183142184142185142186142187142188142189142190142191142192142193142194142195142196142197142198142199142200142201142202142203142204142205142206142207142208142209142210142211142212142213142214142215142216142217142218142219142220142221142222142223142224142225142226142227142228142229142230142231142232142233142234142235142236142237142238142239142240142241142242142243142244142245142246142247142248142249142250142251142252142253142254142255142256142257142258142259142260142261142262142263142264142265142266142267142268142269142270142271142272142273142274142275142276142277142278142279142280142281142282142283142284142285142286142287142288142289142290142291142292142293142294142295142296142297142298142299142300142301142302142303142304142305142306142307142308142309142310142311142312142313142314142315142316142317142318142319142320142321142322142323142324142325142326142327142328142329142330142331142332142333142334142335142336142337142338142339142340142341142342142343142344142345142346142347142348142349142350142351142352142353142354142355142356142357142358142359142360142361142362142363142364142365142366142367142368142369142370142371142372142373142374142375142376142377142378142379142380142381142382142383142384142385142386142387142388142389142390142391142392142393142394142395142396142397142398142399142400142401142402142403142404142405142406142407142408142409142410142411142412142413142414142415142416142417142418142419142420142421142422142423142424142425142426142427142428142429142430142431142432142433142434142435142436142437142438142439142440142441142442142443142444142445142446142447142448142449142450142451142452142453142454142455142456142457142458142459142460142461142462142463142464142465142466142467142468142469142470142471142472142473142474142475142476142477142478142479142480142481142482142483142484142485142486142487142488142489142490142491142492142493142494142495142496142497142498142499142500142501142502142503142504142505142506142507142508142509142510142511142512142513142514142515142516142517142518142519142520142521142522142523142524142525142526142527142528142529142530142531142532142533142534142535142536142537142538142539142540142541142542142543142544142545142546142547142548142549142550142551142552142553142554142555142556142557142558142559142560142561142562142563142564142565142566142567142568142569142570142571142572142573142574142575142576142577142578142579142580142581142582142583142584142585142586142587142588142589142590142591142592142593142594142595142596142597142598142599142600142601142602142603142604142605142606142607142608142609142610142611142612142613142614142615142616142617142618142619142620142621142622142623142624142625142626142627142628142629142630142631142632142633142634142635142636142637142638142639142640142641142642142643142644142645142646142647142648142649142650142651142652142653142654142655142656142657142658142659142660142661142662142663142664142665142666142667142668142669142670142671142672142673142674142675142676142677142678142679142680142681142682142683142684142685142686142687142688142689142690142691142692142693142694142695142696142697142698142699142700142701142702142703142704142705142706142707142708142709142710142711142712142713142714142715142716142717142718142719142720142721142722142723142724142725142726142727142728142729142730142731142732142733142734142735142736142737142738142739142740142741142742142743142744142745142746142747142748142749142750142751142752142753142754142755142756142757142758142759142760142761142762142763142764142765142766142767142768142769142770142771142772142773142774142775142776142777142778142779142780142781142782142783142784142785142786142787142788142789142790142791142792142793142794142795142796142797142798142799142800142801142802142803142804142805142806142807142808142809142810142811142812142813142814142815142816142817142818142819142820142821142822142823142824142825142826142827142828142829142830142831142832142833142834142835142836142837142838142839142840142841142842142843142844142845142846142847142848142849142850142851142852142853142854142855142856142857142858142859142860142861142862142863142864142865142866142867142868142869142870142871142872142873142874142875142876142877142878142879142880142881142882142883142884142885142886142887142888142889142890142891142892142893142894142895142896142897142898142899142900142901142902142903142904142905142906142907142908142909142910142911142912142913142914142915142916142917142918142919142920142921142922142923142924142925142926142927142928142929142930142931142932142933142934142935142936142937142938142939142940142941142942142943142944142945142946142947142948142949142950142951142952142953142954142955142956142957142958142959142960142961142962142963142964142965142966142967142968142969142970142971142972142973142974142975142976142977142978142979142980142981142982142983142984142985142986142987142988142989142990142991142992142993142994142995142996142997142998142999143000143001143002143003143004143005143006143007143008143009143010143011143012143013143014143015143016143017143018143019143020143021143022143023143024143025143026143027143028143029143030143031143032143033143034143035143036143037143038143039143040143041143042143043143044143045143046143047143048143049143050143051143052143053143054143055143056143057143058143059143060143061143062143063143064143065143066143067143068143069143070143071143072143073143074143075143076143077143078143079143080143081143082143083143084143085143086143087143088143089143090143091143092143093143094143095143096143097143098143099143100143101143102143103143104143105143106143107143108143109143110143111143112143113143114143115143116143117143118143119143120143121143122143123143124143125143126143127143128143129143130143131143132143133143134143135143136143137143138143139143140143141143142143143143144143145143146143147143148143149143150143151143152143153143154143155143156143157143158143159143160143161143162143163143164143165143166143167143168143169143170143171143172143173143174143175143176143177143178143179143180143181143182143183143184143185143186143187143188143189143190143191143192143193143194143195143196143197143198143199143200143201143202143203143204143205143206143207143208143209143210143211143212143213143214143215143216143217143218143219143220143221143222143223143224143225143226143227143228143229143230143231143232143233143234143235143236143237143238143239143240143241143242143243143244143245143246143247143248143249143250143251143252143253143254143255143256143257143258143259143260143261143262143263143264143265143266143267143268143269143270143271143272143273143274143275143276143277143278143279143280143281143282143283143284143285143286143287143288143289143290143291143292143293143294143295143296143297143298143299143300143301143302143303143304143305143306143307143308143309143310143311143312143313143314143315143316143317143318143319143320143321143322143323143324143325143326143327143328143329143330143331143332143333143334143335143336143337143338143339143340143341143342143343143344143345143346143347143348143349143350143351143352143353143354143355143356143357143358143359143360143361143362143363143364143365143366143367143368143369143370143371143372143373143374143375143376143377143378143379143380143381143382143383143384143385143386143387143388143389143390143391143392143393143394143395143396143397143398143399143400143401143402143403143404143405143406143407143408143409143410143411143412143413143414143415143416143417143418143419143420143421143422143423143424143425143426143427143428143429143430143431143432143433143434143435143436143437143438143439143440143441143442143443143444143445143446143447143448143449143450143451143452143453143454143455143456143457143458143459143460143461143462143463143464143465143466143467143468143469143470143471143472143473143474143475143476143477143478143479143480143481143482143483143484143485143486143487143488143489143490143491143492143493143494143495143496143497143498143499143500143501143502143503143504143505143506143507143508143509143510143511143512143513143514143515143516143517143518143519143520143521143522143523143524143525143526143527143528143529143530143531143532143533143534143535143536143537143538143539143540143541143542143543143544143545143546143547143548143549143550143551143552143553143554143555143556143557143558143559143560143561143562143563143564143565143566143567143568143569143570143571143572143573143574143575143576143577143578143579143580143581143582143583143584143585143586143587143588143589143590143591143592143593143594143595143596143597143598143599143600143601143602143603143604143605143606143607143608143609143610143611143612143613143614143615143616143617143618143619143620143621143622143623143624143625143626143627143628143629143630143631143632143633143634143635143636143637143638143639143640143641143642143643143644143645143646143647143648143649143650143651143652143653143654143655143656143657143658143659143660143661143662143663143664143665143666143667143668143669143670143671143672143673143674143675143676143677143678143679143680143681143682143683143684143685143686143687143688143689143690143691143692143693143694143695143696143697143698143699143700143701143702143703143704143705143706143707143708143709143710143711143712143713143714143715143716143717143718143719143720143721143722143723143724143725143726143727143728143729143730143731143732143733143734143735143736143737143738143739143740143741143742143743143744143745143746143747143748143749143750143751143752143753143754143755143756143757143758143759143760143761143762143763143764143765143766143767143768143769143770143771143772143773143774143775143776143777143778143779143780143781143782143783143784143785143786143787143788143789143790143791143792143793143794143795143796143797143798143799143800143801143802143803143804143805143806143807143808143809143810143811143812143813143814143815143816143817143818143819143820143821143822143823143824143825143826143827143828143829143830143831143832143833143834143835143836143837143838143839143840143841143842143843143844143845143846143847143848143849143850143851143852143853143854143855143856143857143858143859143860143861143862143863143864143865143866143867143868143869143870143871143872143873143874143875143876143877143878143879143880143881143882143883143884143885143886143887143888143889143890143891143892143893143894143895143896143897143898143899143900143901143902143903143904143905143906143907143908143909143910143911143912143913143914143915143916143917143918143919143920143921143922143923143924143925143926143927143928143929143930143931143932143933143934143935143936143937143938143939143940143941143942143943143944143945143946143947143948143949143950143951143952143953143954143955143956143957143958143959143960143961143962143963143964143965143966143967143968143969143970143971143972143973143974143975143976143977143978143979143980143981143982143983143984143985143986143987143988143989143990143991143992143993143994143995143996143997143998143999144000144001144002144003144004144005144006144007144008144009144010144011144012144013144014144015144016144017144018144019144020144021144022144023144024144025144026144027144028144029144030144031144032144033144034144035144036144037144038144039144040144041144042144043144044144045144046144047144048144049144050144051144052144053144054144055144056144057144058144059144060144061144062144063144064144065144066144067144068144069144070144071144072144073144074144075144076144077144078144079144080144081144082144083144084144085144086144087144088144089144090144091144092144093144094144095144096144097144098144099144100144101144102144103144104144105144106144107144108144109144110144111144112144113144114144115144116144117144118144119144120144121144122144123144124144125144126144127144128144129144130144131144132144133144134144135144136144137144138144139144140144141144142144143144144144145144146144147144148144149144150144151144152144153144154144155144156144157144158144159144160144161144162144163144164144165144166144167144168144169144170144171144172144173144174144175144176144177144178144179144180144181144182144183144184144185144186144187144188144189144190144191144192144193144194144195144196144197144198144199144200144201144202144203144204144205144206144207144208144209144210144211144212144213144214144215144216144217144218144219144220144221144222144223144224144225144226144227144228144229144230144231144232144233144234144235144236144237144238144239144240144241144242144243144244144245144246144247144248144249144250144251144252144253144254144255144256144257144258144259144260144261144262144263144264144265144266144267144268144269144270144271144272144273144274144275144276144277144278144279144280144281144282144283144284144285144286144287144288144289144290144291144292144293144294144295144296144297144298144299144300144301144302144303144304144305144306144307144308144309144310144311144312144313144314144315144316144317144318144319144320144321144322144323144324144325144326144327144328144329144330144331144332144333144334144335144336144337144338144339144340144341144342144343144344144345144346144347144348144349144350144351144352144353144354144355144356144357144358144359144360144361144362144363144364144365144366144367144368144369144370144371144372144373144374144375144376144377144378144379144380144381144382144383144384144385144386144387144388144389144390144391144392144393144394144395144396144397144398144399144400144401144402144403144404144405144406144407144408144409144410144411144412144413144414144415144416144417144418144419144420144421144422144423144424144425144426144427144428144429144430144431144432144433144434144435144436144437144438144439144440144441144442144443144444144445144446144447144448144449144450144451144452144453144454144455144456144457144458144459144460144461144462144463144464144465144466144467144468144469144470144471144472144473144474144475144476144477144478144479144480144481144482144483144484144485144486144487144488144489144490144491144492144493144494144495144496144497144498144499144500144501144502144503144504144505144506144507144508144509144510144511144512144513144514144515144516144517144518144519144520144521144522144523144524144525144526144527144528144529144530144531144532144533144534144535144536144537144538144539144540144541144542144543144544144545144546144547144548144549144550144551144552144553144554144555144556144557144558144559144560144561144562144563144564144565144566144567144568144569144570144571144572144573144574144575144576144577144578144579144580144581144582144583144584144585144586144587144588144589144590144591144592144593144594144595144596144597144598144599144600144601144602144603144604144605144606144607144608144609144610144611144612144613144614144615144616144617144618144619144620144621144622144623144624144625144626144627144628144629144630144631144632144633144634144635144636144637144638144639144640144641144642144643144644144645144646144647144648144649144650144651144652144653144654144655144656144657144658144659144660144661144662144663144664144665144666144667144668144669144670144671144672144673144674144675144676144677144678144679144680144681144682144683144684144685144686144687144688144689144690144691144692144693144694144695144696144697144698144699144700144701144702144703144704144705144706144707144708144709144710144711144712144713144714144715144716144717144718144719144720144721144722144723144724144725144726144727144728144729144730144731144732144733144734144735144736144737144738144739144740144741144742144743144744144745144746144747144748144749144750144751144752144753144754144755144756144757144758144759144760144761144762144763144764144765144766144767144768144769144770144771144772144773144774144775144776144777144778144779144780144781144782144783144784144785144786144787144788144789144790144791144792144793144794144795144796144797144798144799144800144801144802144803144804144805144806144807144808144809144810144811144812144813144814144815144816144817144818144819144820144821144822144823144824144825144826144827144828144829144830144831144832144833144834144835144836144837144838144839144840144841144842144843144844144845144846144847144848144849144850144851144852144853144854144855144856144857144858144859144860144861144862144863144864144865144866144867144868144869144870144871144872144873144874144875144876144877144878144879144880144881144882144883144884144885144886144887144888144889144890144891144892144893144894144895144896144897144898144899144900144901144902144903144904144905144906144907144908144909144910144911144912144913144914144915144916144917144918144919144920144921144922144923144924144925144926144927144928144929144930144931144932144933144934144935144936144937144938144939144940144941144942144943144944144945144946144947144948144949144950144951144952144953144954144955144956144957144958144959144960144961144962144963144964144965144966144967144968144969144970144971144972144973144974144975144976144977144978144979144980144981144982144983144984144985144986144987144988144989144990144991144992144993144994144995144996144997144998144999145000145001145002145003145004145005145006145007145008145009145010145011145012145013145014145015145016145017145018145019145020145021145022145023145024145025145026145027145028145029145030145031145032145033145034145035145036145037145038145039145040145041145042145043145044145045145046145047145048145049145050145051145052145053145054145055145056145057145058145059145060145061145062145063145064145065145066145067145068145069145070145071145072145073145074145075145076145077145078145079145080145081145082145083145084145085145086145087145088145089145090145091145092145093145094145095145096145097145098145099145100145101145102145103145104145105145106145107145108145109145110145111145112145113145114145115145116145117145118145119145120145121145122145123145124145125145126145127145128145129145130145131145132145133145134145135145136145137145138145139145140145141145142145143145144145145145146145147145148145149145150145151145152145153145154145155145156145157145158145159145160145161145162145163145164145165145166145167145168145169145170145171145172145173145174145175145176145177145178145179145180145181145182145183145184145185145186145187145188145189145190145191145192145193145194145195145196145197145198145199145200145201145202145203145204145205145206145207145208145209145210145211145212145213145214145215145216145217145218145219145220145221145222145223145224145225145226145227145228145229145230145231145232145233145234145235145236145237145238145239145240145241145242145243145244145245145246145247145248145249145250145251145252145253145254145255145256145257145258145259145260145261145262145263145264145265145266145267145268145269145270145271145272145273145274145275145276145277145278145279145280145281145282145283145284145285145286145287145288145289145290145291145292145293145294145295145296145297145298145299145300145301145302145303145304145305145306145307145308145309145310145311145312145313145314145315145316145317145318145319145320145321145322145323145324145325145326145327145328145329145330145331145332145333145334145335145336145337145338145339145340145341145342145343145344145345145346145347145348145349145350145351145352145353145354145355145356145357145358145359145360145361145362145363145364145365145366145367145368145369145370145371145372145373145374145375145376145377145378145379145380145381145382145383145384145385145386145387145388145389145390145391145392145393145394145395145396145397145398145399145400145401145402145403145404145405145406145407145408145409145410145411145412145413145414145415145416145417145418145419145420145421145422145423145424145425145426145427145428145429145430145431145432145433145434145435145436145437145438145439145440145441145442145443145444145445145446145447145448145449145450145451145452145453145454145455145456145457145458145459145460145461145462145463145464145465145466145467145468145469145470145471145472145473145474145475145476145477145478145479145480145481145482145483145484145485145486145487145488145489145490145491145492145493145494145495145496145497145498145499145500145501145502145503145504145505145506145507145508145509145510145511145512145513145514145515145516145517145518145519145520145521145522145523145524145525145526145527145528145529145530145531145532145533145534145535145536145537145538145539145540145541145542145543145544145545145546145547145548145549145550145551145552145553145554145555145556145557145558145559145560145561145562145563145564145565145566145567145568145569145570145571145572145573145574145575145576145577145578145579145580145581145582145583145584145585145586145587145588145589145590145591145592145593145594145595145596145597145598145599145600145601145602145603145604145605145606145607145608145609145610145611145612145613145614145615145616145617145618145619145620145621145622145623145624145625145626145627145628145629145630145631145632145633145634145635145636145637145638145639145640145641145642145643145644145645145646145647145648145649145650145651145652145653145654145655145656145657145658145659145660145661145662145663145664145665145666145667145668145669145670145671145672145673145674145675145676145677145678145679145680145681145682145683145684145685145686145687145688145689145690145691145692145693145694145695145696145697145698145699145700145701145702145703145704145705145706145707145708145709145710145711145712145713145714145715145716145717145718145719145720145721145722145723145724145725145726145727145728145729145730145731145732145733145734145735145736145737145738145739145740145741145742145743145744145745145746145747145748145749145750145751145752145753145754145755145756145757145758145759145760145761145762145763145764145765145766145767145768145769145770145771145772145773145774145775145776145777145778145779145780145781145782145783145784145785145786145787145788145789145790145791145792145793145794145795145796145797145798145799145800145801145802145803145804145805145806145807145808145809145810145811145812145813145814145815145816145817145818145819145820145821145822145823145824145825145826145827145828145829145830145831145832145833145834145835145836145837145838145839145840145841145842145843145844145845145846145847145848145849145850145851145852145853145854145855145856145857145858145859145860145861145862145863145864145865145866145867145868145869145870145871145872145873145874145875145876145877145878145879145880145881145882145883145884145885145886145887145888145889145890145891145892145893145894145895145896145897145898145899145900145901145902145903145904145905145906145907145908145909145910145911145912145913145914145915145916145917145918145919145920145921145922145923145924145925145926145927145928145929145930145931145932145933145934145935145936145937145938145939145940145941145942145943145944145945145946145947145948145949145950145951145952145953145954145955145956145957145958145959145960145961145962145963145964145965145966145967145968145969145970145971145972145973145974145975145976145977145978145979145980145981145982145983145984145985145986145987145988145989145990145991145992145993145994145995145996145997145998145999146000146001146002146003146004146005146006146007146008146009146010146011146012146013146014146015146016146017146018146019146020146021146022146023146024146025146026146027146028146029146030146031146032146033146034146035146036146037146038146039146040146041146042146043146044146045146046146047146048146049146050146051146052146053146054146055146056146057146058146059146060146061146062146063146064146065146066146067146068146069146070146071146072146073146074146075146076146077146078146079146080146081146082146083146084146085146086146087146088146089146090146091146092146093146094146095146096146097146098146099146100146101146102146103146104146105146106146107146108146109146110146111146112146113146114146115146116146117146118146119146120146121146122146123146124146125146126146127146128146129146130146131146132146133146134146135146136146137146138146139146140146141146142146143146144146145146146146147146148146149146150146151146152146153146154146155146156146157146158146159146160146161146162146163146164146165146166146167146168146169146170146171146172146173146174146175146176146177146178146179146180146181146182146183146184146185146186146187146188146189146190146191146192146193146194146195146196146197146198146199146200146201146202146203146204146205146206146207146208146209146210146211146212146213146214146215146216146217146218146219146220146221146222146223146224146225146226146227146228146229146230146231146232146233146234146235146236146237146238146239146240146241146242146243146244146245146246146247146248146249146250146251146252146253146254146255146256146257146258146259146260146261146262146263146264146265146266146267146268146269146270146271146272146273146274146275146276146277146278146279146280146281146282146283146284146285146286146287146288146289146290146291146292146293146294146295146296146297146298146299146300146301146302146303146304146305146306146307146308146309146310146311146312146313146314146315146316146317146318146319146320146321146322146323146324146325146326146327146328146329146330146331146332146333146334146335146336146337146338146339146340146341146342146343146344146345146346146347146348146349146350146351146352146353146354146355146356146357146358146359146360146361146362146363146364146365146366146367146368146369146370146371146372146373146374146375146376146377146378146379146380146381146382146383146384146385146386146387146388146389146390146391146392146393146394146395146396146397146398146399146400146401146402146403146404146405146406146407146408146409146410146411146412146413146414146415146416146417146418146419146420146421146422146423146424146425146426146427146428146429146430146431146432146433146434146435146436146437146438146439146440146441146442146443146444146445146446146447146448146449146450146451146452146453146454146455146456146457146458146459146460146461146462146463146464146465146466146467146468146469146470146471146472146473146474146475146476146477146478146479146480146481146482146483146484146485146486146487146488146489146490146491146492146493146494146495146496146497146498146499146500146501146502146503146504146505146506146507146508146509146510146511146512146513146514146515146516146517146518146519146520146521146522146523146524146525146526146527146528146529146530146531146532146533146534146535146536146537146538146539146540146541146542146543146544146545146546146547146548146549146550146551146552146553146554146555146556146557146558146559146560146561146562146563146564146565146566146567146568146569146570146571146572146573146574146575146576146577146578146579146580146581146582146583146584146585146586146587146588146589146590146591146592146593146594146595146596146597146598146599146600146601146602146603146604146605146606146607146608146609146610146611146612146613146614146615146616146617146618146619146620146621146622146623146624146625146626146627146628146629146630146631146632146633146634146635146636146637146638146639146640146641146642146643146644146645146646146647146648146649146650146651146652146653146654146655146656146657146658146659146660146661146662146663146664146665146666146667146668146669146670146671146672146673146674146675146676146677146678146679146680146681146682146683146684146685146686146687146688146689146690146691146692146693146694146695146696146697146698146699146700146701146702146703146704146705146706146707146708146709146710146711146712146713146714146715146716146717146718146719146720146721146722146723146724146725146726146727146728146729146730146731146732146733146734146735146736146737146738146739146740146741146742146743146744146745146746146747146748146749146750146751146752146753146754146755146756146757146758146759146760146761146762146763146764146765146766146767146768146769146770146771146772146773146774146775146776146777146778146779146780146781146782146783146784146785146786146787146788146789146790146791146792146793146794146795146796146797146798146799146800146801146802146803146804146805146806146807146808146809146810146811146812146813146814146815146816146817146818146819146820146821146822146823146824146825146826146827146828146829146830146831146832146833146834146835146836146837146838146839146840146841146842146843146844146845146846146847146848146849146850146851146852146853146854146855146856146857146858146859146860146861146862146863146864146865146866146867146868146869146870146871146872146873146874146875146876146877146878146879146880146881146882146883146884146885146886146887146888146889146890146891146892146893146894146895146896146897146898146899146900146901146902146903146904146905146906146907146908146909146910146911146912146913146914146915146916146917146918146919146920146921146922146923146924146925146926146927146928146929146930146931146932146933146934146935146936146937146938146939146940146941146942146943146944146945146946146947146948146949146950146951146952146953146954146955146956146957146958146959146960146961146962146963146964146965146966146967146968146969146970146971146972146973146974146975146976146977146978146979146980146981146982146983146984146985146986146987146988146989146990146991146992146993146994146995146996146997146998146999147000147001147002147003147004147005147006147007147008147009147010147011147012147013147014147015147016147017147018147019147020147021147022147023147024147025147026147027147028147029147030147031147032147033147034147035147036147037147038147039147040147041147042147043147044147045147046147047147048147049147050147051147052147053147054147055147056147057147058147059147060147061147062147063147064147065147066147067147068147069147070147071147072147073147074147075147076147077147078147079147080147081147082147083147084147085147086147087147088147089147090147091147092147093147094147095147096147097147098147099147100147101147102147103147104147105147106147107147108147109147110147111147112147113147114147115147116147117147118147119147120147121147122147123147124147125147126147127147128147129147130147131147132147133147134147135147136147137147138147139147140147141147142147143147144147145147146147147147148147149147150147151147152147153147154147155147156147157147158147159147160147161147162147163147164147165147166147167147168147169147170147171147172147173147174147175147176147177147178147179147180147181147182147183147184147185147186147187147188147189147190147191147192147193147194147195147196147197147198147199147200147201147202147203147204147205147206147207147208147209147210147211147212147213147214147215147216147217147218147219147220147221147222147223147224147225147226147227147228147229147230147231147232147233147234147235147236147237147238147239147240147241147242147243147244147245147246147247147248147249147250147251147252147253147254147255147256147257147258147259147260147261147262147263147264147265147266147267147268147269147270147271147272147273147274147275147276147277147278147279147280147281147282147283147284147285147286147287147288147289147290147291147292147293147294147295147296147297147298147299147300147301147302147303147304147305147306147307147308147309147310147311147312147313147314147315147316147317147318147319147320147321147322147323147324147325147326147327147328147329147330147331147332147333147334147335147336147337147338147339147340147341147342147343147344147345147346147347147348147349147350147351147352147353147354147355147356147357147358147359147360147361147362147363147364147365147366147367147368147369147370147371147372147373147374147375147376147377147378147379147380147381147382147383147384147385147386147387147388147389147390147391147392147393147394147395147396147397147398147399147400147401147402147403147404147405147406147407147408147409147410147411147412147413147414147415147416147417147418147419147420147421147422147423147424147425147426147427147428147429147430147431147432147433147434147435147436147437147438147439147440147441147442147443147444147445147446147447147448147449147450147451147452147453147454147455147456147457147458147459147460147461147462147463147464147465147466147467147468147469147470147471147472147473147474147475147476147477147478147479147480147481147482147483147484147485147486147487147488147489147490147491147492147493147494147495147496147497147498147499147500147501147502147503147504147505147506147507147508147509147510147511147512147513147514147515147516147517147518147519147520147521147522147523147524147525147526147527147528147529147530147531147532147533147534147535147536147537147538147539147540147541147542147543147544147545147546147547147548147549147550147551147552147553147554147555147556147557147558147559147560147561147562147563147564147565147566147567147568147569147570147571147572147573147574147575147576147577147578147579147580147581147582147583147584147585147586147587147588147589147590147591147592147593147594147595147596147597147598147599147600147601147602147603147604147605147606147607147608147609147610147611147612147613147614147615147616147617147618147619147620147621147622147623147624147625147626147627147628147629147630147631147632147633147634147635147636147637147638147639147640147641147642147643147644147645147646147647147648147649147650147651147652147653147654147655147656147657147658147659147660147661147662147663147664147665147666147667147668147669147670147671147672147673147674147675147676147677147678147679147680147681147682147683147684147685147686147687147688147689147690147691147692147693147694147695147696147697147698147699147700147701147702147703147704147705147706147707147708147709147710147711147712147713147714147715147716147717147718147719147720147721147722147723147724147725147726147727147728147729147730147731147732147733147734147735147736147737147738147739147740147741147742147743147744147745147746147747147748147749147750147751147752147753147754147755147756147757147758147759147760147761147762147763147764147765147766147767147768147769147770147771147772147773147774147775147776147777147778147779147780147781147782147783147784147785147786147787147788147789147790147791147792147793147794147795147796147797147798147799147800147801147802147803147804147805147806147807147808147809147810147811147812147813147814147815147816147817147818147819147820147821147822147823147824147825147826147827147828147829147830147831147832147833147834147835147836147837147838147839147840147841147842147843147844147845147846147847147848147849147850147851147852147853147854147855147856147857147858147859147860147861147862147863147864147865147866147867147868147869147870147871147872147873147874147875147876147877147878147879147880147881147882147883147884147885147886147887147888147889147890147891147892147893147894147895147896147897147898147899147900147901147902147903147904147905147906147907147908147909147910147911147912147913147914147915147916147917147918147919147920147921147922147923147924147925147926147927147928147929147930147931147932147933147934147935147936147937147938147939147940147941147942147943147944147945147946147947147948147949147950147951147952147953147954147955147956147957147958147959147960147961147962147963147964147965147966147967147968147969147970147971147972147973147974147975147976147977147978147979147980147981147982147983147984147985147986147987147988147989147990147991147992147993147994147995147996147997147998147999148000148001148002148003148004148005148006148007148008148009148010148011148012148013148014148015148016148017148018148019148020148021148022148023148024148025148026148027148028148029148030148031148032148033148034148035148036148037148038148039148040148041148042148043148044148045148046148047148048148049148050148051148052148053148054148055148056148057148058148059148060148061148062148063148064148065148066148067148068148069148070148071148072148073148074148075148076148077148078148079148080148081148082148083148084148085148086148087148088148089148090148091148092148093148094148095148096148097148098148099148100148101148102148103148104148105148106148107148108148109148110148111148112148113148114148115148116148117148118148119148120148121148122148123148124148125148126148127148128148129148130148131148132148133148134148135148136148137148138148139148140148141148142148143148144148145148146148147148148148149148150148151148152148153148154148155148156148157148158148159148160148161148162148163148164148165148166148167148168148169148170148171148172148173148174148175148176148177148178148179148180148181148182148183148184148185148186148187148188148189148190148191148192148193148194148195148196148197148198148199148200148201148202148203148204148205148206148207148208148209148210148211148212148213148214148215148216148217148218148219148220148221148222148223148224148225148226148227148228148229148230148231148232148233148234148235148236148237148238148239148240148241148242148243148244148245148246148247148248148249148250148251148252148253148254148255148256148257148258148259148260148261148262148263148264148265148266148267148268148269148270148271148272148273148274148275148276148277148278148279148280148281148282148283148284148285148286148287148288148289148290148291148292148293148294148295148296148297148298148299148300148301148302148303148304148305148306148307148308148309148310148311148312148313148314148315148316148317148318148319148320148321148322148323148324148325148326148327148328148329148330148331148332148333148334148335148336148337148338148339148340148341148342148343148344148345148346148347148348148349148350148351148352148353148354148355148356148357148358148359148360148361148362148363148364148365148366148367148368148369148370148371148372148373148374148375148376148377148378148379148380148381148382148383148384148385148386148387148388148389148390148391148392148393148394148395148396148397148398148399148400148401148402148403148404148405148406148407148408148409148410148411148412148413148414148415148416148417148418148419148420148421148422148423148424148425148426148427148428148429148430148431148432148433148434148435148436148437148438148439148440148441148442148443148444148445148446148447148448148449148450148451148452148453148454148455148456148457148458148459148460148461148462148463148464148465148466148467148468148469148470148471148472148473148474148475148476148477148478148479148480148481148482148483148484148485148486148487148488148489148490148491148492148493148494148495148496148497148498148499148500148501148502148503148504148505148506148507148508148509148510148511148512148513148514148515148516148517148518148519148520148521148522148523148524148525148526148527148528148529148530148531148532148533148534148535148536148537148538148539148540148541148542148543148544148545148546148547148548148549148550148551148552148553148554148555148556148557148558148559148560148561148562148563148564148565148566148567148568148569148570148571148572148573148574148575148576148577148578148579148580148581148582148583148584148585148586148587148588148589148590148591148592148593148594148595148596148597148598148599148600148601148602148603148604148605148606148607148608148609148610148611148612148613148614148615148616148617148618148619148620148621148622148623148624148625148626148627148628148629148630148631148632148633148634148635148636148637148638148639148640148641148642148643148644148645148646148647148648148649148650148651148652148653148654148655148656148657148658148659148660148661148662148663148664148665148666148667148668148669148670148671148672148673148674148675148676148677148678148679148680148681148682148683148684148685148686148687148688148689148690148691148692148693148694148695148696148697148698148699148700148701148702148703148704148705148706148707148708148709148710148711148712148713148714148715148716148717148718148719148720148721148722148723148724148725148726148727148728148729148730148731148732148733148734148735148736148737148738148739148740148741148742148743148744148745148746148747148748148749148750148751148752148753148754148755148756148757148758148759148760148761148762148763148764148765148766148767148768148769148770148771148772148773148774148775148776148777148778148779148780148781148782148783148784148785148786148787148788148789148790148791148792148793148794148795148796148797148798148799148800148801148802148803148804148805148806148807148808148809148810148811148812148813148814148815148816148817148818148819148820148821148822148823148824148825148826148827148828148829148830148831148832148833148834148835148836148837148838148839148840148841148842148843148844148845148846148847148848148849148850148851148852148853148854148855148856148857148858148859148860148861148862148863148864148865148866148867148868148869148870148871148872148873148874148875148876148877148878148879148880148881148882148883148884148885148886148887148888148889148890148891148892148893148894148895148896148897148898148899148900148901148902148903148904148905148906148907148908148909148910148911148912148913148914148915148916148917148918148919148920148921148922148923148924148925148926148927148928148929148930148931148932148933148934148935148936148937148938148939148940148941148942148943148944148945148946148947148948148949148950148951148952148953148954148955148956148957148958148959148960148961148962148963148964148965148966148967148968148969148970148971148972148973148974148975148976148977148978148979148980148981148982148983148984148985148986148987148988148989148990148991148992148993148994148995148996148997148998148999149000149001149002149003149004149005149006149007149008149009149010149011149012149013149014149015149016149017149018149019149020149021149022149023149024149025149026149027149028149029149030149031149032149033149034149035149036149037149038149039149040149041149042149043149044149045149046149047149048149049149050149051149052149053149054149055149056149057149058149059149060149061149062149063149064149065149066149067149068149069149070149071149072149073149074149075149076149077149078149079149080149081149082149083149084149085149086149087149088149089149090149091149092149093149094149095149096149097149098149099149100149101149102149103149104149105149106149107149108149109149110149111149112149113149114149115149116149117149118149119149120149121149122149123149124149125149126149127149128149129149130149131149132149133149134149135149136149137149138149139149140149141149142149143149144149145149146149147149148149149149150149151149152149153149154149155149156149157149158149159149160149161149162149163149164149165149166149167149168149169149170149171149172149173149174149175149176149177149178149179149180149181149182149183149184149185149186149187149188149189149190149191149192149193149194149195149196149197149198149199149200149201149202149203149204149205149206149207149208149209149210149211149212149213149214149215149216149217149218149219149220149221149222149223149224149225149226149227149228149229149230149231149232149233149234149235149236149237149238149239149240149241149242149243149244149245149246149247149248149249149250149251149252149253149254149255149256149257149258149259149260149261149262149263149264149265149266149267149268149269149270149271149272149273149274149275149276149277149278149279149280149281149282149283149284149285149286149287149288149289149290149291149292149293149294149295149296149297149298149299149300149301149302149303149304149305149306149307149308149309149310149311149312149313149314149315149316149317149318149319149320149321149322149323149324149325149326149327149328149329149330149331149332149333149334149335149336149337149338149339149340149341149342149343149344149345149346149347149348149349149350149351149352149353149354149355149356149357149358149359149360149361149362149363149364149365149366149367149368149369149370149371149372149373149374149375149376149377149378149379149380149381149382149383149384149385149386149387149388149389149390149391149392149393149394149395149396149397149398149399149400149401149402149403149404149405149406149407149408149409149410149411149412149413149414149415149416149417149418149419149420149421149422149423149424149425149426149427149428149429149430149431149432149433149434149435149436149437149438149439149440149441149442149443149444149445149446149447149448149449149450149451149452149453149454149455149456149457149458149459149460149461149462149463149464149465149466149467149468149469149470149471149472149473149474149475149476149477149478149479149480149481149482149483149484149485149486149487149488149489149490149491149492149493149494149495149496149497149498149499149500149501149502149503149504149505149506149507149508149509149510149511149512149513149514149515149516149517149518149519149520149521149522149523149524149525149526149527149528149529149530149531149532149533149534149535149536149537149538149539149540149541149542149543149544149545149546149547149548149549149550149551149552149553149554149555149556149557149558149559149560149561149562149563149564149565149566149567149568149569149570149571149572149573149574149575149576149577149578149579149580149581149582149583149584149585149586149587149588149589149590149591149592149593149594149595149596149597149598149599149600149601149602149603149604149605149606149607149608149609149610149611149612149613149614149615149616149617149618149619149620149621149622149623149624149625149626149627149628149629149630149631149632149633149634149635149636149637149638149639149640149641149642149643149644149645149646149647149648149649149650149651149652149653149654149655149656149657149658149659149660149661149662149663149664149665149666149667149668149669149670149671149672149673149674149675149676149677149678149679149680149681149682149683149684149685149686149687149688149689149690149691149692149693149694149695149696149697149698149699149700149701149702149703149704149705149706149707149708149709149710149711149712149713149714149715149716149717149718149719149720149721149722149723149724149725149726149727149728149729149730149731149732149733149734149735149736149737149738149739149740149741149742149743149744149745149746149747149748149749149750149751149752149753149754149755149756149757149758149759149760149761149762149763149764149765149766149767149768149769149770149771149772149773149774149775149776149777149778149779149780149781149782149783149784149785149786149787149788149789149790149791149792149793149794149795149796149797149798149799149800149801149802149803149804149805149806149807149808149809149810149811149812149813149814149815149816149817149818149819149820149821149822149823149824149825149826149827149828149829149830149831149832149833149834149835149836149837149838149839149840149841149842149843149844149845149846149847149848149849149850149851149852149853149854149855149856149857149858149859149860149861149862149863149864149865149866149867149868149869149870149871149872149873149874149875149876149877149878149879149880149881149882149883149884149885149886149887149888149889149890149891149892149893149894149895149896149897149898149899149900149901149902149903149904149905149906149907149908149909149910149911149912149913149914149915149916149917149918149919149920149921149922149923149924149925149926149927149928149929149930149931149932149933149934149935149936149937149938149939149940149941149942149943149944149945149946149947149948149949149950149951149952149953149954149955149956149957149958149959149960149961149962149963149964149965149966149967149968149969149970149971149972149973149974149975149976149977149978149979149980149981149982149983149984149985149986149987149988149989149990149991149992149993149994149995149996149997149998149999150000150001150002150003150004150005150006150007150008150009150010150011150012150013150014150015150016150017150018150019150020150021150022150023150024150025150026150027150028150029150030150031150032150033150034150035150036150037150038150039150040150041150042150043150044150045150046150047150048150049150050150051150052150053150054150055150056150057150058150059150060150061150062150063150064150065150066150067150068150069150070150071150072150073150074150075150076150077150078150079150080150081150082150083150084150085150086150087150088150089150090150091150092150093150094150095150096150097150098150099150100150101150102150103150104150105150106150107150108150109150110150111150112150113150114150115150116150117150118150119150120150121150122150123150124150125150126150127150128150129150130150131150132150133150134150135150136150137150138150139150140150141150142150143150144150145150146150147150148150149150150150151150152150153150154150155150156150157150158150159150160150161150162150163150164150165150166150167150168150169150170150171150172150173150174150175150176150177150178150179150180150181150182150183150184150185150186150187150188150189150190150191150192150193150194150195150196150197150198150199150200150201150202150203150204150205150206150207150208150209150210150211150212150213150214150215150216150217150218150219150220150221150222150223150224150225150226150227150228150229150230150231150232150233150234150235150236150237150238150239150240150241150242150243150244150245150246150247150248150249150250150251150252150253150254150255150256150257150258150259150260150261150262150263150264150265150266150267150268150269150270150271150272150273150274150275150276150277150278150279150280150281150282150283150284150285150286150287150288150289150290150291150292150293150294150295150296150297150298150299150300150301150302150303150304150305150306150307150308150309150310150311150312150313150314150315150316150317150318150319150320150321150322150323150324150325150326150327150328150329150330150331150332150333150334150335150336150337150338150339150340150341150342150343150344150345150346150347150348150349150350150351150352150353150354150355150356150357150358150359150360150361150362150363150364150365150366150367150368150369150370150371150372150373150374150375150376150377150378150379150380150381150382150383150384150385150386150387150388150389150390150391150392150393150394150395150396150397150398150399150400150401150402150403150404150405150406150407150408150409150410150411150412150413150414150415150416150417150418150419150420150421150422150423150424150425150426150427150428150429150430150431150432150433150434150435150436150437150438150439150440150441150442150443150444150445150446150447150448150449150450150451150452150453150454150455150456150457150458150459150460150461150462150463150464150465150466150467150468150469150470150471150472150473150474150475150476150477150478150479150480150481150482150483150484150485150486150487150488150489150490150491150492150493150494150495150496150497150498150499150500150501150502150503150504150505150506150507150508150509150510150511150512150513150514150515150516150517150518150519150520150521150522150523150524150525150526150527150528150529150530150531150532150533150534150535150536150537150538150539150540150541150542150543150544150545150546150547150548150549150550150551150552150553150554150555150556150557150558150559150560150561150562150563150564150565150566150567150568150569150570150571150572150573150574150575150576150577150578150579150580150581150582150583150584150585150586150587150588150589150590150591150592150593150594150595150596150597150598150599150600150601150602150603150604150605150606150607150608150609150610150611150612150613150614150615150616150617150618150619150620150621150622150623150624150625150626150627150628150629150630150631150632150633150634150635150636150637150638150639150640150641150642150643150644150645150646150647150648150649150650150651150652150653150654150655150656150657150658150659150660150661150662150663150664150665150666150667150668150669150670150671150672150673150674150675150676150677150678150679150680150681150682150683150684150685150686150687150688150689150690150691150692150693150694150695150696150697150698150699150700150701150702150703150704150705150706150707150708150709150710150711150712150713150714150715150716150717150718150719150720150721150722150723150724150725150726150727150728150729150730150731150732150733150734150735150736150737150738150739150740150741150742150743150744150745150746150747150748150749150750150751150752150753150754150755150756150757150758150759150760150761150762150763150764150765150766150767150768150769150770150771150772150773150774150775150776150777150778150779150780150781150782150783150784150785150786150787150788150789150790150791150792150793150794150795150796150797150798150799150800150801150802150803150804150805150806150807150808150809150810150811150812150813150814150815150816150817150818150819150820150821150822150823150824150825150826150827150828150829150830150831150832150833150834150835150836150837150838150839150840150841150842150843150844150845150846150847150848150849150850150851150852150853150854150855150856150857150858150859150860150861150862150863150864150865150866150867150868150869150870150871150872150873150874150875150876150877150878150879150880150881150882150883150884150885150886150887150888150889150890150891150892150893150894150895150896150897150898150899150900150901150902150903150904150905150906150907150908150909150910150911150912150913150914150915150916150917150918150919150920150921150922150923150924150925150926150927150928150929150930150931150932150933150934150935150936150937150938150939150940150941150942150943150944150945150946150947150948150949150950150951150952150953150954150955150956150957150958150959150960150961150962150963150964150965150966150967150968150969150970150971150972150973150974150975150976150977150978150979150980150981150982150983150984150985150986150987150988150989150990150991150992150993150994150995150996150997150998150999151000151001151002151003151004151005151006151007151008151009151010151011151012151013151014151015151016151017151018151019151020151021151022151023151024151025151026151027151028151029151030151031151032151033151034151035151036151037151038151039151040151041151042151043151044151045151046151047151048151049151050151051151052151053151054151055151056151057151058151059151060151061151062151063151064151065151066151067151068151069151070151071151072151073151074151075151076151077151078151079151080151081151082151083151084151085151086151087151088151089151090151091151092151093151094151095151096151097151098151099151100151101151102151103151104151105151106151107151108151109151110151111151112151113151114151115151116151117151118151119151120151121151122151123151124151125151126151127151128151129151130151131151132151133151134151135151136151137151138151139151140151141151142151143151144151145151146151147151148151149151150151151151152151153151154151155151156151157151158151159151160151161151162151163151164151165151166151167151168151169151170151171151172151173151174151175151176151177151178151179151180151181151182151183151184151185151186151187151188151189151190151191151192151193151194151195151196151197151198151199151200151201151202151203151204151205151206151207151208151209151210151211151212151213151214151215151216151217151218151219151220151221151222151223151224151225151226151227151228151229151230151231151232151233151234151235151236151237151238151239151240151241151242151243151244151245151246151247151248151249151250151251151252151253151254151255151256151257151258151259151260151261151262151263151264151265151266151267151268151269151270151271151272151273151274151275151276151277151278151279151280151281151282151283151284151285151286151287151288151289151290151291151292151293151294151295151296151297151298151299151300151301151302151303151304151305151306151307151308151309151310151311151312151313151314151315151316151317151318151319151320151321151322151323151324151325151326151327151328151329151330151331151332151333151334151335151336151337151338151339151340151341151342151343151344151345151346151347151348151349151350151351151352151353151354151355151356151357151358151359151360151361151362151363151364151365151366151367151368151369151370151371151372151373151374151375151376151377151378151379151380151381151382151383151384151385151386151387151388151389151390151391151392151393151394151395151396151397151398151399151400151401151402151403151404151405151406151407151408151409151410151411151412151413151414151415151416151417151418151419151420151421151422151423151424151425151426151427151428151429151430151431151432151433151434151435151436151437151438151439151440151441151442151443151444151445151446151447151448151449151450151451151452151453151454151455151456151457151458151459151460151461151462151463151464151465151466151467151468151469151470151471151472151473151474151475151476151477151478151479151480151481151482151483151484151485151486151487151488151489151490151491151492151493151494151495151496151497151498151499151500151501151502151503151504151505151506151507151508151509151510151511151512151513151514151515151516151517151518151519151520151521151522151523151524151525151526151527151528151529151530151531151532151533151534151535151536151537151538151539151540151541151542151543151544151545151546151547151548151549151550151551151552151553151554151555151556151557151558151559151560151561151562151563151564151565151566151567151568151569151570151571151572151573151574151575151576151577151578151579151580151581151582151583151584151585151586151587151588151589151590151591151592151593151594151595151596151597151598151599151600151601151602151603151604151605151606151607151608151609151610151611151612151613151614151615151616151617151618151619151620151621151622151623151624151625151626151627151628151629151630151631151632151633151634151635151636151637151638151639151640151641151642151643151644151645151646151647151648151649151650151651151652151653151654151655151656151657151658151659151660151661151662151663151664151665151666151667151668151669151670151671151672151673151674151675151676151677151678151679151680151681151682151683151684151685151686151687151688151689151690151691151692151693151694151695151696151697151698151699151700151701151702151703151704151705151706151707151708151709151710151711151712151713151714151715151716151717151718151719151720151721151722151723151724151725151726151727151728151729151730151731151732151733151734151735151736151737151738151739151740151741151742151743151744151745151746151747151748151749151750151751151752151753151754151755151756151757151758151759151760151761151762151763151764151765151766151767151768151769151770151771151772151773151774151775151776151777151778151779151780151781151782151783151784151785151786151787151788151789151790151791151792151793151794151795151796151797151798151799151800151801151802151803151804151805151806151807151808151809151810151811151812151813151814151815151816151817151818151819151820151821151822151823151824151825151826151827151828151829151830151831151832151833151834151835151836151837151838151839151840151841151842151843151844151845151846151847151848151849151850151851151852151853151854151855151856151857151858151859151860151861151862151863151864151865151866151867151868151869151870151871151872151873151874151875151876151877151878151879151880151881151882151883151884151885151886151887151888151889151890151891151892151893151894151895151896151897151898151899151900151901151902151903151904151905151906151907151908151909151910151911151912151913151914151915151916151917151918151919151920151921151922151923151924151925151926151927151928151929151930151931151932151933151934151935151936151937151938151939151940151941151942151943151944151945151946151947151948151949151950151951151952151953151954151955151956151957151958151959151960151961151962151963151964151965151966151967151968151969151970151971151972151973151974151975151976151977151978151979151980151981151982151983151984151985151986151987151988151989151990151991151992151993151994151995151996151997151998151999152000152001152002152003152004152005152006152007152008152009152010152011152012152013152014152015152016152017152018152019152020152021152022152023152024152025152026152027152028152029152030152031152032152033152034152035152036152037152038152039152040152041152042152043152044152045152046152047152048152049152050152051152052152053152054152055152056152057152058152059152060152061152062152063152064152065152066152067152068152069152070152071152072152073152074152075152076152077152078152079152080152081152082152083152084152085152086152087152088152089152090152091152092152093152094152095152096152097152098152099152100152101152102152103152104152105152106152107152108152109152110152111152112152113152114152115152116152117152118152119152120152121152122152123152124152125152126152127152128152129152130152131152132152133152134152135152136152137152138152139152140152141152142152143152144152145152146152147152148152149152150152151152152152153152154152155152156152157152158152159152160152161152162152163152164152165152166152167152168152169152170152171152172152173152174152175152176152177152178152179152180152181152182152183152184152185152186152187152188152189152190152191152192152193152194152195152196152197152198152199152200152201152202152203152204152205152206152207152208152209152210152211152212152213152214152215152216152217152218152219152220152221152222152223152224152225152226152227152228152229152230152231152232152233152234152235152236152237152238152239152240152241152242152243152244152245152246152247152248152249152250152251152252152253152254152255152256152257152258152259152260152261152262152263152264152265152266152267152268152269152270152271152272152273152274152275152276152277152278152279152280152281152282152283152284152285152286152287152288152289152290152291152292152293152294152295152296152297152298152299152300152301152302152303152304152305152306152307152308152309152310152311152312152313152314152315152316152317152318152319152320152321152322152323152324152325152326152327152328152329152330152331152332152333152334152335152336152337152338152339152340152341152342152343152344152345152346152347152348152349152350152351152352152353152354152355152356152357152358152359152360152361152362152363152364152365152366152367152368152369152370152371152372152373152374152375152376152377152378152379152380152381152382152383152384152385152386152387152388152389152390152391152392152393152394152395152396152397152398152399152400152401152402152403152404152405152406152407152408152409152410152411152412152413152414152415152416152417152418152419152420152421152422152423152424152425152426152427152428152429152430152431152432152433152434152435152436152437152438152439152440152441152442152443152444152445152446152447152448152449152450152451152452152453152454152455152456152457152458152459152460152461152462152463152464152465152466152467152468152469152470152471152472152473152474152475152476152477152478152479152480152481152482152483152484152485152486152487152488152489152490152491152492152493152494152495152496152497152498152499152500152501152502152503152504152505152506152507152508152509152510152511152512152513152514152515152516152517152518152519152520152521152522152523152524152525152526152527152528152529152530152531152532152533152534152535152536152537152538152539152540152541152542152543152544152545152546152547152548152549152550152551152552152553152554152555152556152557152558152559152560152561152562152563152564152565152566152567152568152569152570152571152572152573152574152575152576152577152578152579152580152581152582152583152584152585152586152587152588152589152590152591152592152593152594152595152596152597152598152599152600152601152602152603152604152605152606152607152608152609152610152611152612152613152614152615152616152617152618152619152620152621152622152623152624152625152626152627152628152629152630152631152632152633152634152635152636152637152638152639152640152641152642152643152644152645152646152647152648152649152650152651152652152653152654152655152656152657152658152659152660152661152662152663152664152665152666152667152668152669152670152671152672152673152674152675152676152677152678152679152680152681152682152683152684152685152686152687152688152689152690152691152692152693152694152695152696152697152698152699152700152701152702152703152704152705152706152707152708152709152710152711152712152713152714152715152716152717152718152719152720152721152722152723152724152725152726152727152728152729152730152731152732152733152734152735152736152737152738152739152740152741152742152743152744152745152746152747152748152749152750152751152752152753152754152755152756152757152758152759152760152761152762152763152764152765152766152767152768152769152770152771152772152773152774152775152776152777152778152779152780152781152782152783152784152785152786152787152788152789152790152791152792152793152794152795152796152797152798152799152800152801152802152803152804152805152806152807152808152809152810152811152812152813152814152815152816152817152818152819152820152821152822152823152824152825152826152827152828152829152830152831152832152833152834152835152836152837152838152839152840152841152842152843152844152845152846152847152848152849152850152851152852152853152854152855152856152857152858152859152860152861152862152863152864152865152866152867152868152869152870152871152872152873152874152875152876152877152878152879152880152881152882152883152884152885152886152887152888152889152890152891152892152893152894152895152896152897152898152899152900152901152902152903152904152905152906152907152908152909152910152911152912152913152914152915152916152917152918152919152920152921152922152923152924152925152926152927152928152929152930152931152932152933152934152935152936152937152938152939152940152941152942152943152944152945152946152947152948152949152950152951152952152953152954152955152956152957152958152959152960152961152962152963152964152965152966152967152968152969152970152971152972152973152974152975152976152977152978152979152980152981152982152983152984152985152986152987152988152989152990152991152992152993152994152995152996152997152998152999153000153001153002153003153004153005153006153007153008153009153010153011153012153013153014153015153016153017153018153019153020153021153022153023153024153025153026153027153028153029153030153031153032153033153034153035153036153037153038153039153040153041153042153043153044153045153046153047153048153049153050153051153052153053153054153055153056153057153058153059153060153061153062153063153064153065153066153067153068153069153070153071153072153073153074153075153076153077153078153079153080153081153082153083153084153085153086153087153088153089153090153091153092153093153094153095153096153097153098153099153100153101153102153103153104153105153106153107153108153109153110153111153112153113153114153115153116153117153118153119153120153121153122153123153124153125153126153127153128153129153130153131153132153133153134153135153136153137153138153139153140153141153142153143153144153145153146153147153148153149153150153151153152153153153154153155153156153157153158153159153160153161153162153163153164153165153166153167153168153169153170153171153172153173153174153175153176153177153178153179153180153181153182153183153184153185153186153187153188153189153190153191153192153193153194153195153196153197153198153199153200153201153202153203153204153205153206153207153208153209153210153211153212153213153214153215153216153217153218153219153220153221153222153223153224153225153226153227153228153229153230153231153232153233153234153235153236153237153238153239153240153241153242153243153244153245153246153247153248153249153250153251153252153253153254153255153256153257153258153259153260153261153262153263153264153265153266153267153268153269153270153271153272153273153274153275153276153277153278153279153280153281153282153283153284153285153286153287153288153289153290153291153292153293153294153295153296153297153298153299153300153301153302153303153304153305153306153307153308153309153310153311153312153313153314153315153316153317153318153319153320153321153322153323153324153325153326153327153328153329153330153331153332153333153334153335153336153337153338153339153340153341153342153343153344153345153346153347153348153349153350153351153352153353153354153355153356153357153358153359153360153361153362153363153364153365153366153367153368153369153370153371153372153373153374153375153376153377153378153379153380153381153382153383153384153385153386153387153388153389153390153391153392153393153394153395153396153397153398153399153400153401153402153403153404153405153406153407153408153409153410153411153412153413153414153415153416153417153418153419153420153421153422153423153424153425153426153427153428153429153430153431153432153433153434153435153436153437153438153439153440153441153442153443153444153445153446153447153448153449153450153451153452153453153454153455153456153457153458153459153460153461153462153463153464153465153466153467153468153469153470153471153472153473153474153475153476153477153478153479153480153481153482153483153484153485153486153487153488153489153490153491153492153493153494153495153496153497153498153499153500153501153502153503153504153505153506153507153508153509153510153511153512153513153514153515153516153517153518153519153520153521153522153523153524153525153526153527153528153529153530153531153532153533153534153535153536153537153538153539153540153541153542153543153544153545153546153547153548153549153550153551153552153553153554153555153556153557153558153559153560153561153562153563153564153565153566153567153568153569153570153571153572153573153574153575153576153577153578153579153580153581153582153583153584153585153586153587153588153589153590153591153592153593153594153595153596153597153598153599153600153601153602153603153604153605153606153607153608153609153610153611153612153613153614153615153616153617153618153619153620153621153622153623153624153625153626153627153628153629153630153631153632153633153634153635153636153637153638153639153640153641153642153643153644153645153646153647153648153649153650153651153652153653153654153655153656153657153658153659153660153661153662153663153664153665153666153667153668153669153670153671153672153673153674153675153676153677153678153679153680153681153682153683153684153685153686153687153688153689153690153691153692153693153694153695153696153697153698153699153700153701153702153703153704153705153706153707153708153709153710153711153712153713153714153715153716153717153718153719153720153721153722153723153724153725153726153727153728153729153730153731153732153733153734153735153736153737153738153739153740153741153742153743153744153745153746153747153748153749153750153751153752153753153754153755153756153757153758153759153760153761153762153763153764153765153766153767153768153769153770153771153772153773153774153775153776153777153778153779153780153781153782153783153784153785153786153787153788153789153790153791153792153793153794153795153796153797153798153799153800153801153802153803153804153805153806153807153808153809153810153811153812153813153814153815153816153817153818153819153820153821153822153823153824153825153826153827153828153829153830153831153832153833153834153835153836153837153838153839153840153841153842153843153844153845153846153847153848153849153850153851153852153853153854153855153856153857153858153859153860153861153862153863153864153865153866153867153868153869153870153871153872153873153874153875153876153877153878153879153880153881153882153883153884153885153886153887153888153889153890153891153892153893153894153895153896153897153898153899153900153901153902153903153904153905153906153907153908153909153910153911153912153913153914153915153916153917153918153919153920153921153922153923153924153925153926153927153928153929153930153931153932153933153934153935153936153937153938153939153940153941153942153943153944153945153946153947153948153949153950153951153952153953153954153955153956153957153958153959153960153961153962153963153964153965153966153967153968153969153970153971153972153973153974153975153976153977153978153979153980153981153982153983153984153985153986153987153988153989153990153991153992153993153994153995153996153997153998153999154000154001154002154003154004154005154006154007154008154009154010154011154012154013154014154015154016154017154018154019154020154021154022154023154024154025154026154027154028154029154030154031154032154033154034154035154036154037154038154039154040154041154042154043154044154045154046154047154048154049154050154051154052154053154054154055154056154057154058154059154060154061154062154063154064154065154066154067154068154069154070154071154072154073154074154075154076154077154078154079154080154081154082154083154084154085154086154087154088154089154090154091154092154093154094154095154096154097154098154099154100154101154102154103154104154105154106154107154108154109154110154111154112154113154114154115154116154117154118154119154120154121154122154123154124154125154126154127154128154129154130154131154132154133154134154135154136154137154138154139154140154141154142154143154144154145154146154147154148154149154150154151154152154153154154154155154156154157154158154159154160154161154162154163154164154165154166154167154168154169154170154171154172154173154174154175154176154177154178154179154180154181154182154183154184154185154186154187154188154189154190154191154192154193154194154195154196154197154198154199154200154201154202154203154204154205154206154207154208154209154210154211154212154213154214154215154216154217154218154219154220154221154222154223154224154225154226154227154228154229154230154231154232154233154234154235154236154237154238154239154240154241154242154243154244154245154246154247154248154249154250154251154252154253154254154255154256154257154258154259154260154261154262154263154264154265154266154267154268154269154270154271154272154273154274154275154276154277154278154279154280154281154282154283154284154285154286154287154288154289154290154291154292154293154294154295154296154297154298154299154300154301154302154303154304154305154306154307154308154309154310154311154312154313154314154315154316154317154318154319154320154321154322154323154324154325154326154327154328154329154330154331154332154333154334154335154336154337154338154339154340154341154342154343154344154345154346154347154348154349154350154351154352154353154354154355154356154357154358154359154360154361154362154363154364154365154366154367154368154369154370154371154372154373154374154375154376154377154378154379154380154381154382154383154384154385154386154387154388154389154390154391154392154393154394154395154396154397154398154399154400154401154402154403154404154405154406154407154408154409154410154411154412154413154414154415154416154417154418154419154420154421154422154423154424154425154426154427154428154429154430154431154432154433154434154435154436154437154438154439154440154441154442154443154444154445154446154447154448154449154450154451154452154453154454154455154456154457154458154459154460154461154462154463154464154465154466154467154468154469154470154471154472154473154474154475154476154477154478154479154480154481154482154483154484154485154486154487154488154489154490154491154492154493154494154495154496154497154498154499154500154501154502154503154504154505154506154507154508154509154510154511154512154513154514154515154516154517154518154519154520154521154522154523154524154525154526154527154528154529154530154531154532154533154534154535154536154537154538154539154540154541154542154543154544154545154546154547154548154549154550154551154552154553154554154555154556154557154558154559154560154561154562154563154564154565154566154567154568154569154570154571154572154573154574154575154576154577154578154579154580154581154582154583154584154585154586154587154588154589154590154591154592154593154594154595154596154597154598154599154600154601154602154603154604154605154606154607154608154609154610154611154612154613154614154615154616154617154618154619154620154621154622154623154624154625154626154627154628154629154630154631154632154633154634154635154636154637154638154639154640154641154642154643154644154645154646154647154648154649154650154651154652154653154654154655154656154657154658154659154660154661154662154663154664154665154666154667154668154669154670154671154672154673154674154675154676154677154678154679154680154681154682154683154684154685154686154687154688154689154690154691154692154693154694154695154696154697154698154699154700154701154702154703154704154705154706154707154708154709154710154711154712154713154714154715154716154717154718154719154720154721154722154723154724154725154726154727154728154729154730154731154732154733154734154735154736154737154738154739154740154741154742154743154744154745154746154747154748154749154750154751154752154753154754154755154756154757154758154759154760154761154762154763154764154765154766154767154768154769154770154771154772154773154774154775154776154777154778154779154780154781154782154783154784154785154786154787154788154789154790154791154792154793154794154795154796154797154798154799154800154801154802154803154804154805154806154807154808154809154810154811154812154813154814154815154816154817154818154819154820154821154822154823154824154825154826154827154828154829154830154831154832154833154834154835154836154837154838154839154840154841154842154843154844154845154846154847154848154849154850154851154852154853154854154855154856154857154858154859154860154861154862154863154864154865154866154867154868154869154870154871154872154873154874154875154876154877154878154879154880154881154882154883154884154885154886154887154888154889154890154891154892154893154894154895154896154897154898154899154900154901154902154903154904154905154906154907154908154909154910154911154912154913154914154915154916154917154918154919154920154921154922154923154924154925154926154927154928154929154930154931154932154933154934154935154936154937154938154939154940154941154942154943154944154945154946154947154948154949154950154951154952154953154954154955154956154957154958154959154960154961154962154963154964154965154966154967154968154969154970154971154972154973154974154975154976154977154978154979154980154981154982154983154984154985154986154987154988154989154990154991154992154993154994154995154996154997154998154999155000155001155002155003155004155005155006155007155008155009155010155011155012155013155014155015155016155017155018155019155020155021155022155023155024155025155026155027155028155029155030155031155032155033155034155035155036155037155038155039155040155041155042155043155044155045155046155047155048155049155050155051155052155053155054155055155056155057155058155059155060155061155062155063155064155065155066155067155068155069155070155071155072155073155074155075155076155077155078155079155080155081155082155083155084155085155086155087155088155089155090155091155092155093155094155095155096155097155098155099155100155101155102155103155104155105155106155107155108155109155110155111155112155113155114155115155116155117155118155119155120155121155122155123155124155125155126155127155128155129155130155131155132155133155134155135155136155137155138155139155140155141155142155143155144155145155146155147155148155149155150155151155152155153155154155155155156155157155158155159155160155161155162155163155164155165155166155167155168155169155170155171155172155173155174155175155176155177155178155179155180155181155182155183155184155185155186155187155188155189155190155191155192155193155194155195155196155197155198155199155200155201155202155203155204155205155206155207155208155209155210155211155212155213155214155215155216155217155218155219155220155221155222155223155224155225155226155227155228155229155230155231155232155233155234155235155236155237155238155239155240155241155242155243155244155245155246155247155248155249155250155251155252155253155254155255155256155257155258155259155260155261155262155263155264155265155266155267155268155269155270155271155272155273155274155275155276155277155278155279155280155281155282155283155284155285155286155287155288155289155290155291155292155293155294155295155296155297155298155299155300155301155302155303155304155305155306155307155308155309155310155311155312155313155314155315155316155317155318155319155320155321155322155323155324155325155326155327155328155329155330155331155332155333155334155335155336155337155338155339155340155341155342155343155344155345155346155347155348155349155350155351155352155353155354155355155356155357155358155359155360155361155362155363155364155365155366155367155368155369155370155371155372155373155374155375155376155377155378155379155380155381155382155383155384155385155386155387155388155389155390155391155392155393155394155395155396155397155398155399155400155401155402155403155404155405155406155407155408155409155410155411155412155413155414155415155416155417155418155419155420155421155422155423155424155425155426155427155428155429155430155431155432155433155434155435155436155437155438155439155440155441155442155443155444155445155446155447155448155449155450155451155452155453155454155455155456155457155458155459155460155461155462155463155464155465155466155467155468155469155470155471155472155473155474155475155476155477155478155479155480155481155482155483155484155485155486155487155488155489155490155491155492155493155494155495155496155497155498155499155500155501155502155503155504155505155506155507155508155509155510155511155512155513155514155515155516155517155518155519155520155521155522155523155524155525155526155527155528155529155530155531155532155533155534155535155536155537155538155539155540155541155542155543155544155545155546155547155548155549155550155551155552155553155554155555155556155557155558155559155560155561155562155563155564155565155566155567155568155569155570155571155572155573155574155575155576155577155578155579155580155581155582155583155584155585155586155587155588155589155590155591155592155593155594155595155596155597155598155599155600155601155602155603155604155605155606155607155608155609155610155611155612155613155614155615155616155617155618155619155620155621155622155623155624155625155626155627155628155629155630155631155632155633155634155635155636155637155638155639155640155641155642155643155644155645155646155647155648155649155650155651155652155653155654155655155656155657155658155659155660155661155662155663155664155665155666155667155668155669155670155671155672155673155674155675155676155677155678155679155680155681155682155683155684155685155686155687155688155689155690155691155692155693155694155695155696155697155698155699155700155701155702155703155704155705155706155707155708155709155710155711155712155713155714155715155716155717155718155719155720155721155722155723155724155725155726155727155728155729155730155731155732155733155734155735155736155737155738155739155740155741155742155743155744155745155746155747155748155749155750155751155752155753155754155755155756155757155758155759155760155761155762155763155764155765155766155767155768155769155770155771155772155773155774155775155776155777155778155779155780155781155782155783155784155785155786155787155788155789155790155791155792155793155794155795155796155797155798155799155800155801155802155803155804155805155806155807155808155809155810155811155812155813155814155815155816155817155818155819155820155821155822155823155824155825155826155827155828155829155830155831155832155833155834155835155836155837155838155839155840155841155842155843155844155845155846155847155848155849155850155851155852155853155854155855155856155857155858155859155860155861155862155863155864155865155866155867155868155869155870155871155872155873155874155875155876155877155878155879155880155881155882155883155884155885155886155887155888155889155890155891155892155893155894155895155896155897155898155899155900155901155902155903155904155905155906155907155908155909155910155911155912155913155914155915155916155917155918155919155920155921155922155923155924155925155926155927155928155929155930155931155932155933155934155935155936155937155938155939155940155941155942155943155944155945155946155947155948155949155950155951155952155953155954155955155956155957155958155959155960155961155962155963155964155965155966155967155968155969155970155971155972155973155974155975155976155977155978155979155980155981155982155983155984155985155986155987155988155989155990155991155992155993155994155995155996155997155998155999156000156001156002156003156004156005156006156007156008156009156010156011156012156013156014156015156016156017156018156019156020156021156022156023156024156025156026156027156028156029156030156031156032156033156034156035156036156037156038156039156040156041156042156043156044156045156046156047156048156049156050156051156052156053156054156055156056156057156058156059156060156061156062156063156064156065156066156067156068156069156070156071156072156073156074156075156076156077156078156079156080156081156082156083156084156085156086156087156088156089156090156091156092156093156094156095156096156097156098156099156100156101156102156103156104156105156106156107156108156109156110156111156112156113156114156115156116156117156118156119156120156121156122156123156124156125156126156127156128156129156130156131156132156133156134156135156136156137156138156139156140156141156142156143156144156145156146156147156148156149156150156151156152156153156154156155156156156157156158156159156160156161156162156163156164156165156166156167156168156169156170156171156172156173156174156175156176156177156178156179156180156181156182156183156184156185156186156187156188156189156190156191156192156193156194156195156196156197156198156199156200156201156202156203156204156205156206156207156208156209156210156211156212156213156214156215156216156217156218156219156220156221156222156223156224156225156226156227156228156229156230156231156232156233156234156235156236156237156238156239156240156241156242156243156244156245156246156247156248156249156250156251156252156253156254156255156256156257156258156259156260156261156262156263156264156265156266156267156268156269156270156271156272156273156274156275156276156277156278156279156280156281156282156283156284156285156286156287156288156289156290156291156292156293156294156295156296156297156298156299156300156301156302156303156304156305156306156307156308156309156310156311156312156313156314156315156316156317156318156319156320156321156322156323156324156325156326156327156328156329156330156331156332156333156334156335156336156337156338156339156340156341156342156343156344156345156346156347156348156349156350156351156352156353156354156355156356156357156358156359156360156361156362156363156364156365156366156367156368156369156370156371156372156373156374156375156376156377156378156379156380156381156382156383156384156385156386156387156388156389156390156391156392156393156394156395156396156397156398156399156400156401156402156403156404156405156406156407156408156409156410156411156412156413156414156415156416156417156418156419156420156421156422156423156424156425156426156427156428156429156430156431156432156433156434156435156436156437156438156439156440156441156442156443156444156445156446156447156448156449156450156451156452156453156454156455156456156457156458156459156460156461156462156463156464156465156466156467156468156469156470156471156472156473156474156475156476156477156478156479156480156481156482156483156484156485156486156487156488156489156490156491156492156493156494156495156496156497156498156499156500156501156502156503156504156505156506156507156508156509156510156511156512156513156514156515156516156517156518156519156520156521156522156523156524156525156526156527156528156529156530156531156532156533156534156535156536156537156538156539156540156541156542156543156544156545156546156547156548156549156550156551156552156553156554156555156556156557156558156559156560156561156562156563156564156565156566156567156568156569156570156571156572156573156574156575156576156577156578156579156580156581156582156583156584156585156586156587156588156589156590156591156592156593156594156595156596156597156598156599156600156601156602156603156604156605156606156607156608156609156610156611156612156613156614156615156616156617156618156619156620156621156622156623156624156625156626156627156628156629156630156631156632156633156634156635156636156637156638156639156640156641156642156643156644156645156646156647156648156649156650156651156652156653156654156655156656156657156658156659156660156661156662156663156664156665156666156667156668156669156670156671156672156673156674156675156676156677156678156679156680156681156682156683156684156685156686156687156688156689156690156691156692156693156694156695156696156697156698156699156700156701156702156703156704156705156706156707156708156709156710156711156712156713156714156715156716156717156718156719156720156721156722156723156724156725156726156727156728156729156730156731156732156733156734156735156736156737156738156739156740156741156742156743156744156745156746156747156748156749156750156751156752156753156754156755156756156757156758156759156760156761156762156763156764156765156766156767156768156769156770156771156772156773156774156775156776156777156778156779156780156781156782156783156784156785156786156787156788156789156790156791156792156793156794156795156796156797156798156799156800156801156802156803156804156805156806156807156808156809156810156811156812156813156814156815156816156817156818156819156820156821156822156823156824156825156826156827156828156829156830156831156832156833156834156835156836156837156838156839156840156841156842156843156844156845156846156847156848156849156850156851156852156853156854156855156856156857156858156859156860156861156862156863156864156865156866156867156868156869156870156871156872156873156874156875156876156877156878156879156880156881156882156883156884156885156886156887156888156889156890156891156892156893156894156895156896156897156898156899156900156901156902156903156904156905156906156907156908156909156910156911156912156913156914156915156916156917156918156919156920156921156922156923156924156925156926156927156928156929156930156931156932156933156934156935156936156937156938156939156940156941156942156943156944156945156946156947156948156949156950156951156952156953156954156955156956156957156958156959156960156961156962156963156964156965156966156967156968156969156970156971156972156973156974156975156976156977156978156979156980156981156982156983156984156985156986156987156988156989156990156991156992156993156994156995156996156997156998156999157000157001157002157003157004157005157006157007157008157009157010157011157012157013157014157015157016157017157018157019157020157021157022157023157024157025157026157027157028157029157030157031157032157033157034157035157036157037157038157039157040157041157042157043157044157045157046157047157048157049157050157051157052157053157054157055157056157057157058157059157060157061157062157063157064157065157066157067157068157069157070157071157072157073157074157075157076157077157078157079157080157081157082157083157084157085157086157087157088157089157090157091157092157093157094157095157096157097157098157099157100157101157102157103157104157105157106157107157108157109157110157111157112157113157114157115157116157117157118157119157120157121157122157123157124157125157126157127157128157129157130157131157132157133157134157135157136157137157138157139157140157141157142157143157144157145157146157147157148157149157150157151157152157153157154157155157156157157157158157159157160157161157162157163157164157165157166157167157168157169157170157171157172157173157174157175157176157177157178157179157180157181157182157183157184157185157186157187157188157189157190157191157192157193157194157195157196157197157198157199157200157201157202157203157204157205157206157207157208157209157210157211157212157213157214157215157216157217157218157219157220157221157222157223157224157225157226157227157228157229157230157231157232157233157234157235157236157237157238157239157240157241157242157243157244157245157246157247157248157249157250157251157252157253157254157255157256157257157258157259157260157261157262157263157264157265157266157267157268157269157270157271157272157273157274157275157276157277157278157279157280157281157282157283157284157285157286157287157288157289157290157291157292157293157294157295157296157297157298157299157300157301157302157303157304157305157306157307157308157309157310157311157312157313157314157315157316157317157318157319157320157321157322157323157324157325157326157327157328157329157330157331157332157333157334157335157336157337157338157339157340157341157342157343157344157345157346157347157348157349157350157351157352157353157354157355157356157357157358157359157360157361157362157363157364157365157366157367157368157369157370157371157372157373157374157375157376157377157378157379157380157381157382157383157384157385157386157387157388157389157390157391157392157393157394157395157396157397157398157399157400157401157402157403157404157405157406157407157408157409157410157411157412157413157414157415157416157417157418157419157420157421157422157423157424157425157426157427157428157429157430157431157432157433157434157435157436157437157438157439157440157441157442157443157444157445157446157447157448157449157450157451157452157453157454157455157456157457157458157459157460157461157462157463157464157465157466157467157468157469157470157471157472157473157474157475157476157477157478157479157480157481157482157483157484157485157486157487157488157489157490157491157492157493157494157495157496157497157498157499157500157501157502157503157504157505157506157507157508157509157510157511157512157513157514157515157516157517157518157519157520157521157522157523157524157525157526157527157528157529157530157531157532157533157534157535157536157537157538157539157540157541157542157543157544157545157546157547157548157549157550157551157552157553157554157555157556157557157558157559157560157561157562157563157564157565157566157567157568157569157570157571157572157573157574157575157576157577157578157579157580157581157582157583157584157585157586157587157588157589157590157591157592157593157594157595157596157597157598157599157600157601157602157603157604157605157606157607157608157609157610157611157612157613157614157615157616157617157618157619157620157621157622157623157624157625157626157627157628157629157630157631157632157633157634157635157636157637157638157639157640157641157642157643157644157645157646157647157648157649157650157651157652157653157654157655157656157657157658157659157660157661157662157663157664157665157666157667157668157669157670157671157672157673157674157675157676157677157678157679157680157681157682157683157684157685157686157687157688157689157690157691157692157693157694157695157696157697157698157699157700157701157702157703157704157705157706157707157708157709157710157711157712157713157714157715157716157717157718157719157720157721157722157723157724157725157726157727157728157729157730157731157732157733157734157735157736157737157738157739157740157741157742157743157744157745157746157747157748157749157750157751157752157753157754157755157756157757157758157759157760157761157762157763157764157765157766157767157768157769157770157771157772157773157774157775157776157777157778157779157780157781157782157783157784157785157786157787157788157789157790157791157792157793157794157795157796157797157798157799157800157801157802157803157804157805157806157807157808157809157810157811157812157813157814157815157816157817157818157819157820157821157822157823157824157825157826157827157828157829157830157831157832157833157834157835157836157837157838157839157840157841157842157843157844157845157846157847157848157849157850157851157852157853157854157855157856157857157858157859157860157861157862157863157864157865157866157867157868157869157870157871157872157873157874157875157876157877157878157879157880157881157882157883157884157885157886157887157888157889157890157891157892157893157894157895157896157897157898157899157900157901157902157903157904157905157906157907157908157909157910157911157912157913157914157915157916157917157918157919157920157921157922157923157924157925157926157927157928157929157930157931157932157933157934157935157936157937157938157939157940157941157942157943157944157945157946157947157948157949157950157951157952157953157954157955157956157957157958157959157960157961157962157963157964157965157966157967157968157969157970157971157972157973157974157975157976157977157978157979157980157981157982157983157984157985157986157987157988157989157990157991157992157993157994157995157996157997157998157999158000158001158002158003158004158005158006158007158008158009158010158011158012158013158014158015158016158017158018158019158020158021158022158023158024158025158026158027158028158029158030158031158032158033158034158035158036158037158038158039158040158041158042158043158044158045158046158047158048158049158050158051158052158053158054158055158056158057158058158059158060158061158062158063158064158065158066158067158068158069158070158071158072158073158074158075158076158077158078158079158080158081158082158083158084158085158086158087158088158089158090158091158092158093158094158095158096158097158098158099158100158101158102158103158104158105158106158107158108158109158110158111158112158113158114158115158116158117158118158119158120158121158122158123158124158125158126158127158128158129158130158131158132158133158134158135158136158137158138158139158140158141158142158143158144158145158146158147158148158149158150158151158152158153158154158155158156158157158158158159158160158161158162158163158164158165158166158167158168158169158170158171158172158173158174158175158176158177158178158179158180158181158182158183158184158185158186158187158188158189158190158191158192158193158194158195158196158197158198158199158200158201158202158203158204158205158206158207158208158209158210158211158212158213158214158215158216158217158218158219158220158221158222158223158224158225158226158227158228158229158230158231158232158233158234158235158236158237158238158239158240158241158242158243158244158245158246158247158248158249158250158251158252158253158254158255158256158257158258158259158260158261158262158263158264158265158266158267158268158269158270158271158272158273158274158275158276158277158278158279158280158281158282158283158284158285158286158287158288158289158290158291158292158293158294158295158296158297158298158299158300158301158302158303158304158305158306158307158308158309158310158311158312158313158314158315158316158317158318158319158320158321158322158323158324158325158326158327158328158329158330158331158332158333158334158335158336158337158338158339158340158341158342158343158344158345158346158347158348158349158350158351158352158353158354158355158356158357158358158359158360158361158362158363158364158365158366158367158368158369158370158371158372158373158374158375158376158377158378158379158380158381158382158383158384158385158386158387158388158389158390158391158392158393158394158395158396158397158398158399158400158401158402158403158404158405158406158407158408158409158410158411158412158413158414158415158416158417158418158419158420158421158422158423158424158425158426158427158428158429158430158431158432158433158434158435158436158437158438158439158440158441158442158443158444158445158446158447158448158449158450158451158452158453158454158455158456158457158458158459158460158461158462158463158464158465158466158467158468158469158470158471158472158473158474158475158476158477158478158479158480158481158482158483158484158485158486158487158488158489158490158491158492158493158494158495158496158497158498158499158500158501158502158503158504158505158506158507158508158509158510158511158512158513158514158515158516158517158518158519158520158521158522158523158524158525158526158527158528158529158530158531158532158533158534158535158536158537158538158539158540158541158542158543158544158545158546158547158548158549158550158551158552158553158554158555158556158557158558158559158560158561158562158563158564158565158566158567158568158569158570158571158572158573158574158575158576158577158578158579158580158581158582158583158584158585158586158587158588158589158590158591158592158593158594158595158596158597158598158599158600158601158602158603158604158605158606158607158608158609158610158611158612158613158614158615158616158617158618158619158620158621158622158623158624158625158626158627158628158629158630158631158632158633158634158635158636158637158638158639158640158641158642158643158644158645158646158647158648158649158650158651158652158653158654158655158656158657158658158659158660158661158662158663158664158665158666158667158668158669158670158671158672158673158674158675158676158677158678158679158680158681158682158683158684158685158686158687158688158689158690158691158692158693158694158695158696158697158698158699158700158701158702158703158704158705158706158707158708158709158710158711158712158713158714158715158716158717158718158719158720158721158722158723158724158725158726158727158728158729158730158731158732158733158734158735158736158737158738158739158740158741158742158743158744158745158746158747158748158749158750158751158752158753158754158755158756158757158758158759158760158761158762158763158764158765158766158767158768158769158770158771158772158773158774158775158776158777158778158779158780158781158782158783158784158785158786158787158788158789158790158791158792158793158794158795158796158797158798158799158800158801158802158803158804158805158806158807158808158809158810158811158812158813158814158815158816158817158818158819158820158821158822158823158824158825158826158827158828158829158830158831158832158833158834158835158836158837158838158839158840158841158842158843158844158845158846158847158848158849158850158851158852158853158854158855158856158857158858158859158860158861158862158863158864158865158866158867158868158869158870158871158872158873158874158875158876158877158878158879158880158881158882158883158884158885158886158887158888158889158890158891158892158893158894158895158896158897158898158899158900158901158902158903158904158905158906158907158908158909158910158911158912158913158914158915158916158917158918158919158920158921158922158923158924158925158926158927158928158929158930158931158932158933158934158935158936158937158938158939158940158941158942158943158944158945158946158947158948158949158950158951158952158953158954158955158956158957158958158959158960158961158962158963158964158965158966158967158968158969158970158971158972158973158974158975158976158977158978158979158980158981158982158983158984158985158986158987158988158989158990158991158992158993158994158995158996158997158998158999159000159001159002159003159004159005159006159007159008159009159010159011159012159013159014159015159016159017159018159019159020159021159022159023159024159025159026159027159028159029159030159031159032159033159034159035159036159037159038159039159040159041159042159043159044159045159046159047159048159049159050159051159052159053159054159055159056159057159058159059159060159061159062159063159064159065159066159067159068159069159070159071159072159073159074159075159076159077159078159079159080159081159082159083159084159085159086159087159088159089159090159091159092159093159094159095159096159097159098159099159100159101159102159103159104159105159106159107159108159109159110159111159112159113159114159115159116159117159118159119159120159121159122159123159124159125159126159127159128159129159130159131159132159133159134159135159136159137159138159139159140159141159142159143159144159145159146159147159148159149159150159151159152159153159154159155159156159157159158159159159160159161159162159163159164159165159166159167159168159169159170159171159172159173159174159175159176159177159178159179159180159181159182159183159184159185159186159187159188159189159190159191159192159193159194159195159196159197159198159199159200159201159202159203159204159205159206159207159208159209159210159211159212159213159214159215159216159217159218159219159220159221159222159223159224159225159226159227159228159229159230159231159232159233159234159235159236159237159238159239159240159241159242159243159244159245159246159247159248159249159250159251159252159253159254159255159256159257159258159259159260159261159262159263159264159265159266159267159268159269159270159271159272159273159274159275159276159277159278159279159280159281159282159283159284159285159286159287159288159289159290159291159292159293159294159295159296159297159298159299159300159301159302159303159304159305159306159307159308159309159310159311159312159313159314159315159316159317159318159319159320159321159322159323159324159325159326159327159328159329159330159331159332159333159334159335159336159337159338159339159340159341159342159343159344159345159346159347159348159349159350159351159352159353159354159355159356159357159358159359159360159361159362159363159364159365159366159367159368159369159370159371159372159373159374159375159376159377159378159379159380159381159382159383159384159385159386159387159388159389159390159391159392159393159394159395159396159397159398159399159400159401159402159403159404159405159406159407159408159409159410159411159412159413159414159415159416159417159418159419159420159421159422159423159424159425159426159427159428159429159430159431159432159433159434159435159436159437159438159439159440159441159442159443159444159445159446159447159448159449159450159451159452159453159454159455159456159457159458159459159460159461159462159463159464159465159466159467159468159469159470159471159472159473159474159475159476159477159478159479159480159481159482159483159484159485159486159487159488159489159490159491159492159493159494159495159496159497159498159499159500159501159502159503159504159505159506159507159508159509159510159511159512159513159514159515159516159517159518159519159520159521159522159523159524159525159526159527159528159529159530159531159532159533159534159535159536159537159538159539159540159541159542159543159544159545159546159547159548159549159550159551159552159553159554159555159556159557159558159559159560159561159562159563159564159565159566159567159568159569159570159571159572159573159574159575159576159577159578159579159580159581159582159583159584159585159586159587159588159589159590159591159592159593159594159595159596159597159598159599159600159601159602159603159604159605159606159607159608159609159610159611159612159613159614159615159616159617159618159619159620159621159622159623159624159625159626159627159628159629159630159631159632159633159634159635159636159637159638159639159640159641159642159643159644159645159646159647159648159649159650159651159652159653159654159655159656159657159658159659159660159661159662159663159664159665159666159667159668159669159670159671159672159673159674159675159676159677159678159679159680159681159682159683159684159685159686159687159688159689159690159691159692159693159694159695159696159697159698159699159700159701159702159703159704159705159706159707159708159709159710159711159712159713159714159715159716159717159718159719159720159721159722159723159724159725159726159727159728159729159730159731159732159733159734159735159736159737159738159739159740159741159742159743159744159745159746159747159748159749159750159751159752159753159754159755159756159757159758159759159760159761159762159763159764159765159766159767159768159769159770159771159772159773159774159775159776159777159778159779159780159781159782159783159784159785159786159787159788159789159790159791159792159793159794159795159796159797159798159799159800159801159802159803159804159805159806159807159808159809159810159811159812159813159814159815159816159817159818159819159820159821159822159823159824159825159826159827159828159829159830159831159832159833159834159835159836159837159838159839159840159841159842159843159844159845159846159847159848159849159850159851159852159853159854159855159856159857159858159859159860159861159862159863159864159865159866159867159868159869159870159871159872159873159874159875159876159877159878159879159880159881159882159883159884159885159886159887159888159889159890159891159892159893159894159895159896159897159898159899159900159901159902159903159904159905159906159907159908159909159910159911159912159913159914159915159916159917159918159919159920159921159922159923159924159925159926159927159928159929159930159931159932159933159934159935159936159937159938159939159940159941159942159943159944159945159946159947159948159949159950159951159952159953159954159955159956159957159958159959159960159961159962159963159964159965159966159967159968159969159970159971159972159973159974159975159976159977159978159979159980159981159982159983159984159985159986159987159988159989159990159991159992159993159994159995159996159997159998159999160000160001160002160003160004160005160006160007160008160009160010160011160012160013160014160015160016160017160018160019160020160021160022160023160024160025160026160027160028160029160030160031160032160033160034160035160036160037160038160039160040160041160042160043160044160045160046160047160048160049160050160051160052160053160054160055160056160057160058160059160060160061160062160063160064160065160066160067160068160069160070160071160072160073160074160075160076160077160078160079160080160081160082160083160084160085160086160087160088160089160090160091160092160093160094160095160096160097160098160099160100160101160102160103160104160105160106160107160108160109160110160111160112160113160114160115160116160117160118160119160120160121160122160123160124160125160126160127160128160129160130160131160132160133160134160135160136160137160138160139160140160141160142160143160144160145160146160147160148160149160150160151160152160153160154160155160156160157160158160159160160160161160162160163160164160165160166160167160168160169160170160171160172160173160174160175160176160177160178160179160180160181160182160183160184160185160186160187160188160189160190160191160192160193160194160195160196160197160198160199160200160201160202160203160204160205160206160207160208160209160210160211160212160213160214160215160216160217160218160219160220160221160222160223160224160225160226160227160228160229160230160231160232160233160234160235160236160237160238160239160240160241160242160243160244160245160246160247160248160249160250160251160252160253160254160255160256160257160258160259160260160261160262160263160264160265160266160267160268160269160270160271160272160273160274160275160276160277160278160279160280160281160282160283160284160285160286160287160288160289160290160291160292160293160294160295160296160297160298160299160300160301160302160303160304160305160306160307160308160309160310160311160312160313160314160315160316160317160318160319160320160321160322160323160324160325160326160327160328160329160330160331160332160333160334160335160336160337160338160339160340160341160342160343160344160345160346160347160348160349160350160351160352160353160354160355160356160357160358160359160360160361160362160363160364160365160366160367160368160369160370160371160372160373160374160375160376160377160378160379160380160381160382160383160384160385160386160387160388160389160390160391160392160393160394160395160396160397160398160399160400160401160402160403160404160405160406160407160408160409160410160411160412160413160414160415160416160417160418160419160420160421160422160423160424160425160426160427160428160429160430160431160432160433160434160435160436160437160438160439160440160441160442160443160444160445160446160447160448160449160450160451160452160453160454160455160456160457160458160459160460160461160462160463160464160465160466160467160468160469160470160471160472160473160474160475160476160477160478160479160480160481160482160483160484160485160486160487160488160489160490160491160492160493160494160495160496160497160498160499160500160501160502160503160504160505160506160507160508160509160510160511160512160513160514160515160516160517160518160519160520160521160522160523160524160525160526160527160528160529160530160531160532160533160534160535160536160537160538160539160540160541160542160543160544160545160546160547160548160549160550160551160552160553160554160555160556160557160558160559160560160561160562160563160564160565160566160567160568160569160570160571160572160573160574160575160576160577160578160579160580160581160582160583160584160585160586160587160588160589160590160591160592160593160594160595160596160597160598160599160600160601160602160603160604160605160606160607160608160609160610160611160612160613160614160615160616160617160618160619160620160621160622160623160624160625160626160627160628160629160630160631160632160633160634160635160636160637160638160639160640160641160642160643160644160645160646160647160648160649160650160651160652160653160654160655160656160657160658160659160660160661160662160663160664160665160666160667160668160669160670160671160672160673160674160675160676160677160678160679160680160681160682160683160684160685160686160687160688160689160690160691160692160693160694160695160696160697160698160699160700160701160702160703160704160705160706160707160708160709160710160711160712160713160714160715160716160717160718160719160720160721160722160723160724160725160726160727160728160729160730160731160732160733160734160735160736160737160738160739160740160741160742160743160744160745160746160747160748160749160750160751160752160753160754160755160756160757160758160759160760160761160762160763160764160765160766160767160768160769160770160771160772160773160774160775160776160777160778160779160780160781160782160783160784160785160786160787160788160789160790160791160792160793160794160795160796160797160798160799160800160801160802160803160804160805160806160807160808160809160810160811160812160813160814160815160816160817160818160819160820160821160822160823160824160825160826160827160828160829160830160831160832160833160834160835160836160837160838160839160840160841160842160843160844160845160846160847160848160849160850160851160852160853160854160855160856160857160858160859160860160861160862160863160864160865160866160867160868160869160870160871160872160873160874160875160876160877160878160879160880160881160882160883160884160885160886160887160888160889160890160891160892160893160894160895160896160897160898160899160900160901160902160903160904160905160906160907160908160909160910160911160912160913160914160915160916160917160918160919160920160921160922160923160924160925160926160927160928160929160930160931160932160933160934160935160936160937160938160939160940160941160942160943160944160945160946160947160948160949160950160951160952160953160954160955160956160957160958160959160960160961160962160963160964160965160966160967160968160969160970160971160972160973160974160975160976160977160978160979160980160981160982160983160984160985160986160987160988160989160990160991160992160993160994160995160996160997160998160999161000161001161002161003161004161005161006161007161008161009161010161011161012161013161014161015161016161017161018161019161020161021161022161023161024161025161026161027161028161029161030161031161032161033161034161035161036161037161038161039161040161041161042161043161044161045161046161047161048161049161050161051161052161053161054161055161056161057161058161059161060161061161062161063161064161065161066161067161068161069161070161071161072161073161074161075161076161077161078161079161080161081161082161083161084161085161086161087161088161089161090161091161092161093161094161095161096161097161098161099161100161101161102161103161104161105161106161107161108161109161110161111161112161113161114161115161116161117161118161119161120161121161122161123161124161125161126161127161128161129161130161131161132161133161134161135161136161137161138161139161140161141161142161143161144161145161146161147161148161149161150161151161152161153161154161155161156161157161158161159161160161161161162161163161164161165161166161167161168161169161170161171161172161173161174161175161176161177161178161179161180161181161182161183161184161185161186161187161188161189161190161191161192161193161194161195161196161197161198161199161200161201161202161203161204161205161206161207161208161209161210161211161212161213161214161215161216161217161218161219161220161221161222161223161224161225161226161227161228161229161230161231161232161233161234161235161236161237161238161239161240161241161242161243161244161245161246161247161248161249161250161251161252161253161254161255161256161257161258161259161260161261161262161263161264161265161266161267161268161269161270161271161272161273161274161275161276161277161278161279161280161281161282161283161284161285161286161287161288161289161290161291161292161293161294161295161296161297161298161299161300161301161302161303161304161305161306161307161308161309161310161311161312161313161314161315161316161317161318161319161320161321161322161323161324161325161326161327161328161329161330161331161332161333161334161335161336161337161338161339161340161341161342161343161344161345161346161347161348161349161350161351161352161353161354161355161356161357161358161359161360161361161362161363161364161365161366161367161368161369161370161371161372161373161374161375161376161377161378161379161380161381161382161383161384161385161386161387161388161389161390161391161392161393161394161395161396161397161398161399161400161401161402161403161404161405161406161407161408161409161410161411161412161413161414161415161416161417161418161419161420161421161422161423161424161425161426161427161428161429161430161431161432161433161434161435161436161437161438161439161440161441161442161443161444161445161446161447161448161449161450161451161452161453161454161455161456161457161458161459161460161461161462161463161464161465161466161467161468161469161470161471161472161473161474161475161476161477161478161479161480161481161482161483161484161485161486161487161488161489161490161491161492161493161494161495161496161497161498161499161500161501161502161503161504161505161506161507161508161509161510161511161512161513161514161515161516161517161518161519161520161521161522161523161524161525161526161527161528161529161530161531161532161533161534161535161536161537161538161539161540161541161542161543161544161545161546161547161548161549161550161551161552161553161554161555161556161557161558161559161560161561161562161563161564161565161566161567161568161569161570161571161572161573161574161575161576161577161578161579161580161581161582161583161584161585161586161587161588161589161590161591161592161593161594161595161596161597161598161599161600161601161602161603161604161605161606161607161608161609161610161611161612161613161614161615161616161617161618161619161620161621161622161623161624161625161626161627161628161629161630161631161632161633161634161635161636161637161638161639161640161641161642161643161644161645161646161647161648161649161650161651161652161653161654161655161656161657161658161659161660161661161662161663161664161665161666161667161668161669161670161671161672161673161674161675161676161677161678161679161680161681161682161683161684161685161686161687161688161689161690161691161692161693161694161695161696161697161698161699161700161701161702161703161704161705161706161707161708161709161710161711161712161713161714161715161716161717161718161719161720161721161722161723161724161725161726161727161728161729161730161731161732161733161734161735161736161737161738161739161740161741161742161743161744161745161746161747161748161749161750161751161752161753161754161755161756161757161758161759161760161761161762161763161764161765161766161767161768161769161770161771161772161773161774161775161776161777161778161779161780161781161782161783161784161785161786161787161788161789161790161791161792161793161794161795161796161797161798161799161800161801161802161803161804161805161806161807161808161809161810161811161812161813161814161815161816161817161818161819161820161821161822161823161824161825161826161827161828161829161830161831161832161833161834161835161836161837161838161839161840161841161842161843161844161845161846161847161848161849161850161851161852161853161854161855161856161857161858161859161860161861161862161863161864161865161866161867161868161869161870161871161872161873161874161875161876161877161878161879161880161881161882161883161884161885161886161887161888161889161890161891161892161893161894161895161896161897161898161899161900161901161902161903161904161905161906161907161908161909161910161911161912161913161914161915161916161917161918161919161920161921161922161923161924161925161926161927161928161929161930161931161932161933161934161935161936161937161938161939161940161941161942161943161944161945161946161947161948161949161950161951161952161953161954161955161956161957161958161959161960161961161962161963161964161965161966161967161968161969161970161971161972161973161974161975161976161977161978161979161980161981161982161983161984161985161986161987161988161989161990161991161992161993161994161995161996161997161998161999162000162001162002162003162004162005162006162007162008162009162010162011162012162013162014162015162016162017162018162019162020162021162022162023162024162025162026162027162028162029162030162031162032162033162034162035162036162037162038162039162040162041162042162043162044162045162046162047162048162049162050162051162052162053162054162055162056162057162058162059162060162061162062162063162064162065162066162067162068162069162070162071162072162073162074162075162076162077162078162079162080162081162082162083162084162085162086162087162088162089162090162091162092162093162094162095162096162097162098162099162100162101162102162103162104162105162106162107162108162109162110162111162112162113162114162115162116162117162118162119162120162121162122162123162124162125162126162127162128162129162130162131162132162133162134162135162136162137162138162139162140162141162142162143162144162145162146162147162148162149162150162151162152162153162154162155162156162157162158162159162160162161162162162163162164162165162166162167162168162169162170162171162172162173162174162175162176162177162178162179162180162181162182162183162184162185162186162187162188162189162190162191162192162193162194162195162196162197162198162199162200162201162202162203162204162205162206162207162208162209162210162211162212162213162214162215162216162217162218162219162220162221162222162223162224162225162226162227162228162229162230162231162232162233162234162235162236162237162238162239162240162241162242162243162244162245162246162247162248162249162250162251162252162253162254162255162256162257162258162259162260162261162262162263162264162265162266162267162268162269162270162271162272162273162274162275162276162277162278162279162280162281162282162283162284162285162286162287162288162289162290162291162292162293162294162295162296162297162298162299162300162301162302162303162304162305162306162307162308162309162310162311162312162313162314162315162316162317162318162319162320162321162322162323162324162325162326162327162328162329162330162331162332162333162334162335162336162337162338162339162340162341162342162343162344162345162346162347162348162349162350162351162352162353162354162355162356162357162358162359162360162361162362162363162364162365162366162367162368162369162370162371162372162373162374162375162376162377162378162379162380162381162382162383162384162385162386162387162388162389162390162391162392162393162394162395162396162397162398162399162400162401162402162403162404162405162406162407162408162409162410162411162412162413162414162415162416162417162418162419162420162421162422162423162424162425162426162427162428162429162430162431162432162433162434162435162436162437162438162439162440162441162442162443162444162445162446162447162448162449162450162451162452162453162454162455162456162457162458162459162460162461162462162463162464162465162466162467162468162469162470162471162472162473162474162475162476162477162478162479162480162481162482162483162484162485162486162487162488162489162490162491162492162493162494162495162496162497162498162499162500162501162502162503162504162505162506162507162508162509162510162511162512162513162514162515162516162517162518162519162520162521162522162523162524162525162526162527162528162529162530162531162532162533162534162535162536162537162538162539162540162541162542162543162544162545162546162547162548162549162550162551162552162553162554162555162556162557162558162559162560162561162562162563162564162565162566162567162568162569162570162571162572162573162574162575162576162577162578162579162580162581162582162583162584162585162586162587162588162589162590162591162592162593162594162595162596162597162598162599162600162601162602162603162604162605162606162607162608162609162610162611162612162613162614162615162616162617162618162619162620162621162622162623162624162625162626162627162628162629162630162631162632162633162634162635162636162637162638162639162640162641162642162643162644162645162646162647162648162649162650162651162652162653162654162655162656162657162658162659162660162661162662162663162664162665162666162667162668162669162670162671162672162673162674162675162676162677162678162679162680162681162682162683162684162685162686162687162688162689162690162691162692162693162694162695162696162697162698162699162700162701162702162703162704162705162706162707162708162709162710162711162712162713162714162715162716162717162718162719162720162721162722162723162724162725162726162727162728162729162730162731162732162733162734162735162736162737162738162739162740162741162742162743162744162745162746162747162748162749162750162751162752162753162754162755162756162757162758162759162760162761162762162763162764162765162766162767162768162769162770162771162772162773162774162775162776162777162778162779162780162781162782162783162784162785162786162787162788162789162790162791162792162793162794162795162796162797162798162799162800162801162802162803162804162805162806162807162808162809162810162811162812162813162814162815162816162817162818162819162820162821162822162823162824162825162826162827162828162829162830162831162832162833162834162835162836162837162838162839162840162841162842162843162844162845162846162847162848162849162850162851162852162853162854162855162856162857162858162859162860162861162862162863162864162865162866162867162868162869162870162871162872162873162874162875162876162877162878162879162880162881162882162883162884162885162886162887162888162889162890162891162892162893162894162895162896162897162898162899162900162901162902162903162904162905162906162907162908162909162910162911162912162913162914162915162916162917162918162919162920162921162922162923162924162925162926162927162928162929162930162931162932162933162934162935162936162937162938162939162940162941162942162943162944162945162946162947162948162949162950162951162952162953162954162955162956162957162958162959162960162961162962162963162964162965162966162967162968162969162970162971162972162973162974162975162976162977162978162979162980162981162982162983162984162985162986162987162988162989162990162991162992162993162994162995162996162997162998162999163000163001163002163003163004163005163006163007163008163009163010163011163012163013163014163015163016163017163018163019163020163021163022163023163024163025163026163027163028163029163030163031163032163033163034163035163036163037163038163039163040163041163042163043163044163045163046163047163048163049163050163051163052163053163054163055163056163057163058163059163060163061163062163063163064163065163066163067163068163069163070163071163072163073163074163075163076163077163078163079163080163081163082163083163084163085163086163087163088163089163090163091163092163093163094163095163096163097163098163099163100163101163102163103163104163105163106163107163108163109163110163111163112163113163114163115163116163117163118163119163120163121163122163123163124163125163126163127163128163129163130163131163132163133163134163135163136163137163138163139163140163141163142163143163144163145163146163147163148163149163150163151163152163153163154163155163156163157163158163159163160163161163162163163163164163165163166163167163168163169163170163171163172163173163174163175163176163177163178163179163180163181163182163183163184163185163186163187163188163189163190163191163192163193163194163195163196163197163198163199163200163201163202163203163204163205163206163207163208163209163210163211163212163213163214163215163216163217163218163219163220163221163222163223163224163225163226163227163228163229163230163231163232163233163234163235163236163237163238163239163240163241163242163243163244163245163246163247163248163249163250163251163252163253163254163255163256163257163258163259163260163261163262163263163264163265163266163267163268163269163270163271163272163273163274163275163276163277163278163279163280163281163282163283163284163285163286163287163288163289163290163291163292163293163294163295163296163297163298163299163300163301163302163303163304163305163306163307163308163309163310163311163312163313163314163315163316163317163318163319163320163321163322163323163324163325163326163327163328163329163330163331163332163333163334163335163336163337163338163339163340163341163342163343163344163345163346163347163348163349163350163351163352163353163354163355163356163357163358163359163360163361163362163363163364163365163366163367163368163369163370163371163372163373163374163375163376163377163378163379163380163381163382163383163384163385163386163387163388163389163390163391163392163393163394163395163396163397163398163399163400163401163402163403163404163405163406163407163408163409163410163411163412163413163414163415163416163417163418163419163420163421163422163423163424163425163426163427163428163429163430163431163432163433163434163435163436163437163438163439163440163441163442163443163444163445163446163447163448163449163450163451163452163453163454163455163456163457163458163459163460163461163462163463163464163465163466163467163468163469163470163471163472163473163474163475163476163477163478163479163480163481163482163483163484163485163486163487163488163489163490163491163492163493163494163495163496163497163498163499163500163501163502163503163504163505163506163507163508163509163510163511163512163513163514163515163516163517163518163519163520163521163522163523163524163525163526163527163528163529163530163531163532163533163534163535163536163537163538163539163540163541163542163543163544163545163546163547163548163549163550163551163552163553163554163555163556163557163558163559163560163561163562163563163564163565163566163567163568163569163570163571163572163573163574163575163576163577163578163579163580163581163582163583163584163585163586163587163588163589163590163591163592163593163594163595163596163597163598163599163600163601163602163603163604163605163606163607163608163609163610163611163612163613163614163615163616163617163618163619163620163621163622163623163624163625163626163627163628163629163630163631163632163633163634163635163636163637163638163639163640163641163642163643163644163645163646163647163648163649163650163651163652163653163654163655163656163657163658163659163660163661163662163663163664163665163666163667163668163669163670163671163672163673163674163675163676163677163678163679163680163681163682163683163684163685163686163687163688163689163690163691163692163693163694163695163696163697163698163699163700163701163702163703163704163705163706163707163708163709163710163711163712163713163714163715163716163717163718163719163720163721163722163723163724163725163726163727163728163729163730163731163732163733163734163735163736163737163738163739163740163741163742163743163744163745163746163747163748163749163750163751163752163753163754163755163756163757163758163759163760163761163762163763163764163765163766163767163768163769163770163771163772163773163774163775163776163777163778163779163780163781163782163783163784163785163786163787163788163789163790163791163792163793163794163795163796163797163798163799163800163801163802163803163804163805163806163807163808163809163810163811163812163813163814163815163816163817163818163819163820163821163822163823163824163825163826163827163828163829163830163831163832163833163834163835163836163837163838163839163840163841163842163843163844163845163846163847163848163849163850163851163852163853163854163855163856163857163858163859163860163861163862163863163864163865163866163867163868163869163870163871163872163873163874163875163876163877163878163879163880163881163882163883163884163885163886163887163888163889163890163891163892163893163894163895163896163897163898163899163900163901163902163903163904163905163906163907163908163909163910163911163912163913163914163915163916163917163918163919163920163921163922163923163924163925163926163927163928163929163930163931163932163933163934163935163936163937163938163939163940163941163942163943163944163945163946163947163948163949163950163951163952163953163954163955163956163957163958163959163960163961163962163963163964163965163966163967163968163969163970163971163972163973163974163975163976163977163978163979163980163981163982163983163984163985163986163987163988163989163990163991163992163993163994163995163996163997163998163999164000164001164002164003164004164005164006164007164008164009164010164011164012164013164014164015164016164017164018164019164020164021164022164023164024164025164026164027164028164029164030164031164032164033164034164035164036164037164038164039164040164041164042164043164044164045164046164047164048164049164050164051164052164053164054164055164056164057164058164059164060164061164062164063164064164065164066164067164068164069164070164071164072164073164074164075164076164077164078164079164080164081164082164083164084164085164086164087164088164089164090164091164092164093164094164095164096164097164098164099164100164101164102164103164104164105164106164107164108164109164110164111164112164113164114164115164116164117164118164119164120164121164122164123164124164125164126164127164128164129164130164131164132164133164134164135164136164137164138164139164140164141164142164143164144164145164146164147164148164149164150164151164152164153164154164155164156164157164158164159164160164161164162164163164164164165164166164167164168164169164170164171164172164173164174164175164176164177164178164179164180164181164182164183164184164185164186164187164188164189164190164191164192164193164194164195164196164197164198164199164200164201164202164203164204164205164206164207164208164209164210164211164212164213164214164215164216164217164218164219164220164221164222164223164224164225164226164227164228164229164230164231164232164233164234164235164236164237164238164239164240164241164242164243164244164245164246164247164248164249164250164251164252164253164254164255164256164257164258164259164260164261164262164263164264164265164266164267164268164269164270164271164272164273164274164275164276164277164278164279164280164281164282164283164284164285164286164287164288164289164290164291164292164293164294164295164296164297164298164299164300164301164302164303164304164305164306164307164308164309164310164311164312164313164314164315164316164317164318164319164320164321164322164323164324164325164326164327164328164329164330164331164332164333164334164335164336164337164338164339164340164341164342164343164344164345164346164347164348164349164350164351164352164353164354164355164356164357164358164359164360164361164362164363164364164365164366164367164368164369164370164371164372164373164374164375164376164377164378164379164380164381164382164383164384164385164386164387164388164389164390164391164392164393164394164395164396164397164398164399164400164401164402164403164404164405164406164407164408164409164410164411164412164413164414164415164416164417164418164419164420164421164422164423164424164425164426164427164428164429164430164431164432164433164434164435164436164437164438164439164440164441164442164443164444164445164446164447164448164449164450164451164452164453164454164455164456164457164458164459164460164461164462164463164464164465164466164467164468164469164470164471164472164473164474164475164476164477164478164479164480164481164482164483164484164485164486164487164488164489164490164491164492164493164494164495164496164497164498164499164500164501164502164503164504164505164506164507164508164509164510164511164512164513164514164515164516164517164518164519164520164521164522164523164524164525164526164527164528164529164530164531164532164533164534164535164536164537164538164539164540164541164542164543164544164545164546164547164548164549164550164551164552164553164554164555164556164557164558164559164560164561164562164563164564164565164566164567164568164569164570164571164572164573164574164575164576164577164578164579164580164581164582164583164584164585164586164587164588164589164590164591164592164593164594164595164596164597164598164599164600164601164602164603164604164605164606164607164608164609164610164611164612164613164614164615164616164617164618164619164620164621164622164623164624164625164626164627164628164629164630164631164632164633164634164635164636164637164638164639164640164641164642164643164644164645164646164647164648164649164650164651164652164653164654164655164656164657164658164659164660164661164662164663164664164665164666164667164668164669164670164671164672164673164674164675164676164677164678164679164680164681164682164683164684164685164686164687164688164689164690164691164692164693164694164695164696164697164698164699164700164701164702164703164704164705164706164707164708164709164710164711164712164713164714164715164716164717164718164719164720164721164722164723164724164725164726164727164728164729164730164731164732164733164734164735164736164737164738164739164740164741164742164743164744164745164746164747164748164749164750164751164752164753164754164755164756164757164758164759164760164761164762164763164764164765164766164767164768164769164770164771164772164773164774164775164776164777164778164779164780164781164782164783164784164785164786164787164788164789164790164791164792164793164794164795164796164797164798164799164800164801164802164803164804164805164806164807164808164809164810164811164812164813164814164815164816164817164818164819164820164821164822164823164824164825164826164827164828164829164830164831164832164833164834164835164836164837164838164839164840164841164842164843164844164845164846164847164848164849164850164851164852164853164854164855164856164857164858164859164860164861164862164863164864164865164866164867164868164869164870164871164872164873164874164875164876164877164878164879164880164881164882164883164884164885164886164887164888164889164890164891164892164893164894164895164896164897164898164899164900164901164902164903164904164905164906164907164908164909164910164911164912164913164914164915164916164917164918164919164920164921164922164923164924164925164926164927164928164929164930164931164932164933164934164935164936164937164938164939164940164941164942164943164944164945164946164947164948164949164950164951164952164953164954164955164956164957164958164959164960164961164962164963164964164965164966164967164968164969164970164971164972164973164974164975164976164977164978164979164980164981164982164983164984164985164986164987164988164989164990164991164992164993164994164995164996164997164998164999165000165001165002165003165004165005165006165007165008165009165010165011165012165013165014165015165016165017165018165019165020165021165022165023165024165025165026165027165028165029165030165031165032165033165034165035165036165037165038165039165040165041165042165043165044165045165046165047165048165049165050165051165052165053165054165055165056165057165058165059165060165061165062165063165064165065165066165067165068165069165070165071165072165073165074165075165076165077165078165079165080165081165082165083165084165085165086165087165088165089165090165091165092165093165094165095165096165097165098165099165100165101165102165103165104165105165106165107165108165109165110165111165112165113165114165115165116165117165118165119165120165121165122165123165124165125165126165127165128165129165130165131165132165133165134165135165136165137165138165139165140165141165142165143165144165145165146165147165148165149165150165151165152165153165154165155165156165157165158165159165160165161165162165163165164165165165166165167165168165169165170165171165172165173165174165175165176165177165178165179165180165181165182165183165184165185165186165187165188165189165190165191165192165193165194165195165196165197165198165199165200165201165202165203165204165205165206165207165208165209165210165211165212165213165214165215165216165217165218165219165220165221165222165223165224165225165226165227165228165229165230165231165232165233165234165235165236165237165238165239165240165241165242165243165244165245165246165247165248165249165250165251165252165253165254165255165256165257165258165259165260165261165262165263165264165265165266165267165268165269165270165271165272165273165274165275165276165277165278165279165280165281165282165283165284165285165286165287165288165289165290165291165292165293165294165295165296165297165298165299165300165301165302165303165304165305165306165307165308165309165310165311165312165313165314165315165316165317165318165319165320165321165322165323165324165325165326165327165328165329165330165331165332165333165334165335165336165337165338165339165340165341165342165343165344165345165346165347165348165349165350165351165352165353165354165355165356165357165358165359165360165361165362165363165364165365165366165367165368165369165370165371165372165373165374165375165376165377165378165379165380165381165382165383165384165385165386165387165388165389165390165391165392165393165394165395165396165397165398165399165400165401165402165403165404165405165406165407165408165409165410165411165412165413165414165415165416165417165418165419165420165421165422165423165424165425165426165427165428165429165430165431165432165433165434165435165436165437165438165439165440165441165442165443165444165445165446165447165448165449165450165451165452165453165454165455165456165457165458165459165460165461165462165463165464165465165466165467165468165469165470165471165472165473165474165475165476165477165478165479165480165481165482165483165484165485165486165487165488165489165490165491165492165493165494165495165496165497165498165499165500165501165502165503165504165505165506165507165508165509165510165511165512165513165514165515165516165517165518165519165520165521165522165523165524165525165526165527165528165529165530165531165532165533165534165535165536165537165538165539165540165541165542165543165544165545165546165547165548165549165550165551165552165553165554165555165556165557165558165559165560165561165562165563165564165565165566165567165568165569165570165571165572165573165574165575165576165577165578165579165580165581165582165583165584165585165586165587165588165589165590165591165592165593165594165595165596165597165598165599165600165601165602165603165604165605165606165607165608165609165610165611165612165613165614165615165616165617165618165619165620165621165622165623165624165625165626165627165628165629165630165631165632165633165634165635165636165637165638165639165640165641165642165643165644165645165646165647165648165649165650165651165652165653165654165655165656165657165658165659165660165661165662165663165664165665165666165667165668165669165670165671165672165673165674165675165676165677165678165679165680165681165682165683165684165685165686165687165688165689165690165691165692165693165694165695165696165697165698165699165700165701165702165703165704165705165706165707165708165709165710165711165712165713165714165715165716165717165718165719165720165721165722165723165724165725165726165727165728165729165730165731165732165733165734165735165736165737165738165739165740165741165742165743165744165745165746165747165748165749165750165751165752165753165754165755165756165757165758165759165760165761165762165763165764165765165766165767165768165769165770165771165772165773165774165775165776165777165778165779165780165781165782165783165784165785165786165787165788165789165790165791165792165793165794165795165796165797165798165799165800165801165802165803165804165805165806165807165808165809165810165811165812165813165814165815165816165817165818165819165820165821165822165823165824165825165826165827165828165829165830165831165832165833165834165835165836165837165838165839165840165841165842165843165844165845165846165847165848165849165850165851165852165853165854165855165856165857165858165859165860165861165862165863165864165865165866165867165868165869165870165871165872165873165874165875165876165877165878165879165880165881165882165883165884165885165886165887165888165889165890165891165892165893165894165895165896165897165898165899165900165901165902165903165904165905165906165907165908165909165910165911165912165913165914165915165916165917165918165919165920165921165922165923165924165925165926165927165928165929165930165931165932165933165934165935165936165937165938165939165940165941165942165943165944165945165946165947165948165949165950165951165952165953165954165955165956165957165958165959165960165961165962165963165964165965165966165967165968165969165970165971165972165973165974165975165976165977165978165979165980165981165982165983165984165985165986165987165988165989165990165991165992165993165994165995165996165997165998165999166000166001166002166003166004166005166006166007166008166009166010166011166012166013166014166015166016166017166018166019166020166021166022166023166024166025166026166027166028166029166030166031166032166033166034166035166036166037166038166039166040166041166042166043166044166045166046166047166048166049166050166051166052166053166054166055166056166057166058166059166060166061166062166063166064166065166066166067166068166069166070166071166072166073166074166075166076166077166078166079166080166081166082166083166084166085166086166087166088166089166090166091166092166093166094166095166096166097166098166099166100166101166102166103166104166105166106166107166108166109166110166111166112166113166114166115166116166117166118166119166120166121166122166123166124166125166126166127166128166129166130166131166132166133166134166135166136166137166138166139166140166141166142166143166144166145166146166147166148166149166150166151166152166153166154166155166156166157166158166159166160166161166162166163166164166165166166166167166168166169166170166171166172166173166174166175166176166177166178166179166180166181166182166183166184166185166186166187166188166189166190166191166192166193166194166195166196166197166198166199166200166201166202166203166204166205166206166207166208166209166210166211166212166213166214166215166216166217166218166219166220166221166222166223166224166225166226166227166228166229166230166231166232166233166234166235166236166237166238166239166240166241166242166243166244166245166246166247166248166249166250166251166252166253166254166255166256166257166258166259166260166261166262166263166264166265166266166267166268166269166270166271166272166273166274166275166276166277166278166279166280166281166282166283166284166285166286166287166288166289166290166291166292166293166294166295166296166297166298166299166300166301166302166303166304166305166306166307166308166309166310166311166312166313166314166315166316166317166318166319166320166321166322166323166324166325166326166327166328166329166330166331166332166333166334166335166336166337166338166339166340166341166342166343166344166345166346166347166348166349166350166351166352166353166354166355166356166357166358166359166360166361166362166363166364166365166366166367166368166369166370166371166372166373166374166375166376166377166378166379166380166381166382166383166384166385166386166387166388166389166390166391166392166393166394166395166396166397166398166399166400166401166402166403166404166405166406166407166408166409166410166411166412166413166414166415166416166417166418166419166420166421166422166423166424166425166426166427166428166429166430166431166432166433166434166435166436166437166438166439166440166441166442166443166444166445166446166447166448166449166450166451166452166453166454166455166456166457166458166459166460166461166462166463166464166465166466166467166468166469166470166471166472166473166474166475166476166477166478166479166480166481166482166483166484166485166486166487166488166489166490166491166492166493166494166495166496166497166498166499166500166501166502166503166504166505166506166507166508166509166510166511166512166513166514166515166516166517166518166519166520166521166522166523166524166525166526166527166528166529166530166531166532166533166534166535166536166537166538166539166540166541166542166543166544166545166546166547166548166549166550166551166552166553166554166555166556166557166558166559166560166561166562166563166564166565166566166567166568166569166570166571166572166573166574166575166576166577166578166579166580166581166582166583166584166585166586166587166588166589166590166591166592166593166594166595166596166597166598166599166600166601166602166603166604166605166606166607166608166609166610166611166612166613166614166615166616166617166618166619166620166621166622166623166624166625166626166627166628166629166630166631166632166633166634166635166636166637166638166639166640166641166642166643166644166645166646166647166648166649166650166651166652166653166654166655166656166657166658166659166660166661
  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. const REVISION = '124';
  8. const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  9. const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  10. const CullFaceNone = 0;
  11. const CullFaceBack = 1;
  12. const CullFaceFront = 2;
  13. const CullFaceFrontBack = 3;
  14. const BasicShadowMap = 0;
  15. const PCFShadowMap = 1;
  16. const PCFSoftShadowMap = 2;
  17. const VSMShadowMap = 3;
  18. const FrontSide = 0;
  19. const BackSide = 1;
  20. const DoubleSide = 2;
  21. const FlatShading$1 = 1;
  22. const SmoothShading = 2;
  23. const NoBlending = 0;
  24. const NormalBlending = 1;
  25. const AdditiveBlending = 2;
  26. const SubtractiveBlending = 3;
  27. const MultiplyBlending = 4;
  28. const CustomBlending = 5;
  29. const AddEquation = 100;
  30. const SubtractEquation = 101;
  31. const ReverseSubtractEquation = 102;
  32. const MinEquation = 103;
  33. const MaxEquation = 104;
  34. const ZeroFactor = 200;
  35. const OneFactor = 201;
  36. const SrcColorFactor = 202;
  37. const OneMinusSrcColorFactor = 203;
  38. const SrcAlphaFactor = 204;
  39. const OneMinusSrcAlphaFactor = 205;
  40. const DstAlphaFactor = 206;
  41. const OneMinusDstAlphaFactor = 207;
  42. const DstColorFactor = 208;
  43. const OneMinusDstColorFactor = 209;
  44. const SrcAlphaSaturateFactor = 210;
  45. const NeverDepth = 0;
  46. const AlwaysDepth = 1;
  47. const LessDepth = 2;
  48. const LessEqualDepth = 3;
  49. const EqualDepth = 4;
  50. const GreaterEqualDepth = 5;
  51. const GreaterDepth = 6;
  52. const NotEqualDepth = 7;
  53. const MultiplyOperation = 0;
  54. const MixOperation = 1;
  55. const AddOperation = 2;
  56. const NoToneMapping = 0;
  57. const LinearToneMapping = 1;
  58. const ReinhardToneMapping = 2;
  59. const CineonToneMapping = 3;
  60. const ACESFilmicToneMapping = 4;
  61. const CustomToneMapping = 5;
  62. const UVMapping = 300;
  63. const CubeReflectionMapping = 301;
  64. const CubeRefractionMapping = 302;
  65. const EquirectangularReflectionMapping = 303;
  66. const EquirectangularRefractionMapping = 304;
  67. const CubeUVReflectionMapping = 306;
  68. const CubeUVRefractionMapping = 307;
  69. const RepeatWrapping = 1000;
  70. const ClampToEdgeWrapping = 1001;
  71. const MirroredRepeatWrapping = 1002;
  72. const NearestFilter = 1003;
  73. const NearestMipmapNearestFilter = 1004;
  74. const NearestMipMapNearestFilter = 1004;
  75. const NearestMipmapLinearFilter = 1005;
  76. const NearestMipMapLinearFilter = 1005;
  77. const LinearFilter = 1006;
  78. const LinearMipmapNearestFilter = 1007;
  79. const LinearMipMapNearestFilter = 1007;
  80. const LinearMipmapLinearFilter = 1008;
  81. const LinearMipMapLinearFilter = 1008;
  82. const UnsignedByteType = 1009;
  83. const ByteType = 1010;
  84. const ShortType = 1011;
  85. const UnsignedShortType = 1012;
  86. const IntType = 1013;
  87. const UnsignedIntType = 1014;
  88. const FloatType = 1015;
  89. const HalfFloatType = 1016;
  90. const UnsignedShort4444Type = 1017;
  91. const UnsignedShort5551Type = 1018;
  92. const UnsignedShort565Type = 1019;
  93. const UnsignedInt248Type$1 = 1020;
  94. const AlphaFormat = 1021;
  95. const RGBFormat = 1022;
  96. const RGBAFormat = 1023;
  97. const LuminanceFormat = 1024;
  98. const LuminanceAlphaFormat = 1025;
  99. const RGBEFormat = RGBAFormat;
  100. const DepthFormat = 1026;
  101. const DepthStencilFormat = 1027;
  102. const RedFormat = 1028;
  103. const RedIntegerFormat = 1029;
  104. const RGFormat = 1030;
  105. const RGIntegerFormat = 1031;
  106. const RGBIntegerFormat = 1032;
  107. const RGBAIntegerFormat = 1033;
  108. const RGB_S3TC_DXT1_Format = 33776;
  109. const RGBA_S3TC_DXT1_Format$1 = 33777;
  110. const RGBA_S3TC_DXT3_Format = 33778;
  111. const RGBA_S3TC_DXT5_Format$1 = 33779;
  112. const RGB_PVRTC_4BPPV1_Format = 35840;
  113. const RGB_PVRTC_2BPPV1_Format = 35841;
  114. const RGBA_PVRTC_4BPPV1_Format = 35842;
  115. const RGBA_PVRTC_2BPPV1_Format = 35843;
  116. const RGB_ETC1_Format = 36196;
  117. const RGB_ETC2_Format = 37492;
  118. const RGBA_ETC2_EAC_Format = 37496;
  119. const RGBA_ASTC_4x4_Format = 37808;
  120. const RGBA_ASTC_5x4_Format = 37809;
  121. const RGBA_ASTC_5x5_Format = 37810;
  122. const RGBA_ASTC_6x5_Format = 37811;
  123. const RGBA_ASTC_6x6_Format = 37812;
  124. const RGBA_ASTC_8x5_Format = 37813;
  125. const RGBA_ASTC_8x6_Format = 37814;
  126. const RGBA_ASTC_8x8_Format = 37815;
  127. const RGBA_ASTC_10x5_Format = 37816;
  128. const RGBA_ASTC_10x6_Format = 37817;
  129. const RGBA_ASTC_10x8_Format = 37818;
  130. const RGBA_ASTC_10x10_Format = 37819;
  131. const RGBA_ASTC_12x10_Format = 37820;
  132. const RGBA_ASTC_12x12_Format = 37821;
  133. const RGBA_BPTC_Format = 36492;
  134. const SRGB8_ALPHA8_ASTC_4x4_Format = 37840;
  135. const SRGB8_ALPHA8_ASTC_5x4_Format = 37841;
  136. const SRGB8_ALPHA8_ASTC_5x5_Format = 37842;
  137. const SRGB8_ALPHA8_ASTC_6x5_Format = 37843;
  138. const SRGB8_ALPHA8_ASTC_6x6_Format = 37844;
  139. const SRGB8_ALPHA8_ASTC_8x5_Format = 37845;
  140. const SRGB8_ALPHA8_ASTC_8x6_Format = 37846;
  141. const SRGB8_ALPHA8_ASTC_8x8_Format = 37847;
  142. const SRGB8_ALPHA8_ASTC_10x5_Format = 37848;
  143. const SRGB8_ALPHA8_ASTC_10x6_Format = 37849;
  144. const SRGB8_ALPHA8_ASTC_10x8_Format = 37850;
  145. const SRGB8_ALPHA8_ASTC_10x10_Format = 37851;
  146. const SRGB8_ALPHA8_ASTC_12x10_Format = 37852;
  147. const SRGB8_ALPHA8_ASTC_12x12_Format = 37853;
  148. const LoopOnce = 2200;
  149. const LoopRepeat = 2201;
  150. const LoopPingPong = 2202;
  151. const InterpolateDiscrete = 2300;
  152. const InterpolateLinear = 2301;
  153. const InterpolateSmooth = 2302;
  154. const ZeroCurvatureEnding = 2400;
  155. const ZeroSlopeEnding = 2401;
  156. const WrapAroundEnding = 2402;
  157. const NormalAnimationBlendMode = 2500;
  158. const AdditiveAnimationBlendMode = 2501;
  159. const TrianglesDrawMode = 0;
  160. const TriangleStripDrawMode = 1;
  161. const TriangleFanDrawMode = 2;
  162. const LinearEncoding = 3000;
  163. const sRGBEncoding = 3001;
  164. const GammaEncoding = 3007;
  165. const RGBEEncoding = 3002;
  166. const LogLuvEncoding = 3003;
  167. const RGBM7Encoding = 3004;
  168. const RGBM16Encoding = 3005;
  169. const RGBDEncoding = 3006;
  170. const BasicDepthPacking = 3200;
  171. const RGBADepthPacking = 3201;
  172. const TangentSpaceNormalMap = 0;
  173. const ObjectSpaceNormalMap = 1;
  174. const ZeroStencilOp = 0;
  175. const KeepStencilOp = 7680;
  176. const ReplaceStencilOp = 7681;
  177. const IncrementStencilOp = 7682;
  178. const DecrementStencilOp = 7683;
  179. const IncrementWrapStencilOp = 34055;
  180. const DecrementWrapStencilOp = 34056;
  181. const InvertStencilOp = 5386;
  182. const NeverStencilFunc = 512;
  183. const LessStencilFunc = 513;
  184. const EqualStencilFunc = 514;
  185. const LessEqualStencilFunc = 515;
  186. const GreaterStencilFunc = 516;
  187. const NotEqualStencilFunc = 517;
  188. const GreaterEqualStencilFunc = 518;
  189. const AlwaysStencilFunc = 519;
  190. const StaticDrawUsage = 35044;
  191. const DynamicDrawUsage = 35048;
  192. const StreamDrawUsage = 35040;
  193. const StaticReadUsage = 35045;
  194. const DynamicReadUsage = 35049;
  195. const StreamReadUsage = 35041;
  196. const StaticCopyUsage = 35046;
  197. const DynamicCopyUsage = 35050;
  198. const StreamCopyUsage = 35042;
  199. const GLSL1 = '100';
  200. const GLSL3 = '300 es';
  201. /**
  202. * https://github.com/mrdoob/eventdispatcher.js/
  203. */
  204. function EventDispatcher() {}
  205. Object.assign( EventDispatcher.prototype, {
  206. addEventListener: function ( type, listener ) {
  207. if ( this._listeners === undefined ) this._listeners = {};
  208. const listeners = this._listeners;
  209. if ( listeners[ type ] === undefined ) {
  210. listeners[ type ] = [];
  211. }
  212. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  213. listeners[ type ].push( listener );
  214. }
  215. },
  216. hasEventListener: function ( type, listener ) {
  217. if ( this._listeners === undefined ) return false;
  218. const listeners = this._listeners;
  219. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  220. },
  221. dispatchEvent: function ( event ) {
  222. if ( this._listeners === undefined ) return;
  223. const listeners = this._listeners;
  224. const listenerArray = listeners[ event.type ];
  225. if ( listenerArray !== undefined ) {
  226. event.target = this;
  227. // Make a copy, in case listeners are removed while iterating.
  228. const array = listenerArray.slice( 0 );
  229. for ( let i = 0, l = array.length; i < l; i ++ ) {
  230. array[ i ].call( this, event );
  231. }
  232. }
  233. }
  234. } );
  235. const _lut = [];
  236. for ( let i = 0; i < 256; i ++ ) {
  237. _lut[ i ] = ( i < 16 ? '0' : '' ) + ( i ).toString( 16 );
  238. }
  239. let _seed = 1234567;
  240. const MathUtils = {
  241. DEG2RAD: Math.PI / 180,
  242. RAD2DEG: 180 / Math.PI,
  243. generateUUID: function () {
  244. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  245. const d0 = Math.random() * 0xffffffff | 0;
  246. const d1 = Math.random() * 0xffffffff | 0;
  247. const d2 = Math.random() * 0xffffffff | 0;
  248. const d3 = Math.random() * 0xffffffff | 0;
  249. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  250. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  251. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  252. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  253. // .toUpperCase() here flattens concatenated strings to save heap memory space.
  254. return uuid.toUpperCase();
  255. },
  256. clamp: function ( value, min, max ) {
  257. return Math.max( min, Math.min( max, value ) );
  258. },
  259. // compute euclidian modulo of m % n
  260. // https://en.wikipedia.org/wiki/Modulo_operation
  261. euclideanModulo: function ( n, m ) {
  262. return ( ( n % m ) + m ) % m;
  263. },
  264. // Linear mapping from range <a1, a2> to range <b1, b2>
  265. mapLinear: function ( x, a1, a2, b1, b2 ) {
  266. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  267. },
  268. // https://en.wikipedia.org/wiki/Linear_interpolation
  269. lerp: function ( x, y, t ) {
  270. return ( 1 - t ) * x + t * y;
  271. },
  272. // http://en.wikipedia.org/wiki/Smoothstep
  273. smoothstep: function ( x, min, max ) {
  274. if ( x <= min ) return 0;
  275. if ( x >= max ) return 1;
  276. x = ( x - min ) / ( max - min );
  277. return x * x * ( 3 - 2 * x );
  278. },
  279. smootherstep: function ( x, min, max ) {
  280. if ( x <= min ) return 0;
  281. if ( x >= max ) return 1;
  282. x = ( x - min ) / ( max - min );
  283. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  284. },
  285. // Random integer from <low, high> interval
  286. randInt: function ( low, high ) {
  287. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  288. },
  289. // Random float from <low, high> interval
  290. randFloat: function ( low, high ) {
  291. return low + Math.random() * ( high - low );
  292. },
  293. // Random float from <-range/2, range/2> interval
  294. randFloatSpread: function ( range ) {
  295. return range * ( 0.5 - Math.random() );
  296. },
  297. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  298. seededRandom: function ( s ) {
  299. if ( s !== undefined ) _seed = s % 2147483647;
  300. // Park-Miller algorithm
  301. _seed = _seed * 16807 % 2147483647;
  302. return ( _seed - 1 ) / 2147483646;
  303. },
  304. degToRad: function ( degrees ) {
  305. return degrees * MathUtils.DEG2RAD;
  306. },
  307. radToDeg: function ( radians ) {
  308. return radians * MathUtils.RAD2DEG;
  309. },
  310. isPowerOfTwo: function ( value ) {
  311. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  312. },
  313. ceilPowerOfTwo: function ( value ) {
  314. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  315. },
  316. floorPowerOfTwo: function ( value ) {
  317. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  318. },
  319. setQuaternionFromProperEuler: function ( q, a, b, c, order ) {
  320. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  321. // rotations are applied to the axes in the order specified by 'order'
  322. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  323. // angles are in radians
  324. const cos = Math.cos;
  325. const sin = Math.sin;
  326. const c2 = cos( b / 2 );
  327. const s2 = sin( b / 2 );
  328. const c13 = cos( ( a + c ) / 2 );
  329. const s13 = sin( ( a + c ) / 2 );
  330. const c1_3 = cos( ( a - c ) / 2 );
  331. const s1_3 = sin( ( a - c ) / 2 );
  332. const c3_1 = cos( ( c - a ) / 2 );
  333. const s3_1 = sin( ( c - a ) / 2 );
  334. switch ( order ) {
  335. case 'XYX':
  336. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  337. break;
  338. case 'YZY':
  339. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  340. break;
  341. case 'ZXZ':
  342. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  343. break;
  344. case 'XZX':
  345. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  346. break;
  347. case 'YXY':
  348. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  349. break;
  350. case 'ZYZ':
  351. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  352. break;
  353. default:
  354. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  355. }
  356. }
  357. };
  358. class Vector2 {
  359. constructor( x = 0, y = 0 ) {
  360. Object.defineProperty( this, 'isVector2', { value: true } );
  361. this.x = x;
  362. this.y = y;
  363. }
  364. get width() {
  365. return this.x;
  366. }
  367. set width( value ) {
  368. this.x = value;
  369. }
  370. get height() {
  371. return this.y;
  372. }
  373. set height( value ) {
  374. this.y = value;
  375. }
  376. set( x, y ) {
  377. this.x = x;
  378. this.y = y;
  379. return this;
  380. }
  381. setScalar( scalar ) {
  382. this.x = scalar;
  383. this.y = scalar;
  384. return this;
  385. }
  386. setX( x ) {
  387. this.x = x;
  388. return this;
  389. }
  390. setY( y ) {
  391. this.y = y;
  392. return this;
  393. }
  394. setComponent( index, value ) {
  395. switch ( index ) {
  396. case 0: this.x = value; break;
  397. case 1: this.y = value; break;
  398. default: throw new Error( 'index is out of range: ' + index );
  399. }
  400. return this;
  401. }
  402. getComponent( index ) {
  403. switch ( index ) {
  404. case 0: return this.x;
  405. case 1: return this.y;
  406. default: throw new Error( 'index is out of range: ' + index );
  407. }
  408. }
  409. clone() {
  410. return new this.constructor( this.x, this.y );
  411. }
  412. copy( v ) {
  413. this.x = v.x;
  414. this.y = v.y;
  415. return this;
  416. }
  417. add( v, w ) {
  418. if ( w !== undefined ) {
  419. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  420. return this.addVectors( v, w );
  421. }
  422. this.x += v.x;
  423. this.y += v.y;
  424. return this;
  425. }
  426. addScalar( s ) {
  427. this.x += s;
  428. this.y += s;
  429. return this;
  430. }
  431. addVectors( a, b ) {
  432. this.x = a.x + b.x;
  433. this.y = a.y + b.y;
  434. return this;
  435. }
  436. addScaledVector( v, s ) {
  437. this.x += v.x * s;
  438. this.y += v.y * s;
  439. return this;
  440. }
  441. sub( v, w ) {
  442. if ( w !== undefined ) {
  443. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  444. return this.subVectors( v, w );
  445. }
  446. this.x -= v.x;
  447. this.y -= v.y;
  448. return this;
  449. }
  450. subScalar( s ) {
  451. this.x -= s;
  452. this.y -= s;
  453. return this;
  454. }
  455. subVectors( a, b ) {
  456. this.x = a.x - b.x;
  457. this.y = a.y - b.y;
  458. return this;
  459. }
  460. multiply( v ) {
  461. this.x *= v.x;
  462. this.y *= v.y;
  463. return this;
  464. }
  465. multiplyScalar( scalar ) {
  466. this.x *= scalar;
  467. this.y *= scalar;
  468. return this;
  469. }
  470. divide( v ) {
  471. this.x /= v.x;
  472. this.y /= v.y;
  473. return this;
  474. }
  475. divideScalar( scalar ) {
  476. return this.multiplyScalar( 1 / scalar );
  477. }
  478. applyMatrix3( m ) {
  479. const x = this.x, y = this.y;
  480. const e = m.elements;
  481. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  482. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  483. return this;
  484. }
  485. min( v ) {
  486. this.x = Math.min( this.x, v.x );
  487. this.y = Math.min( this.y, v.y );
  488. return this;
  489. }
  490. max( v ) {
  491. this.x = Math.max( this.x, v.x );
  492. this.y = Math.max( this.y, v.y );
  493. return this;
  494. }
  495. clamp( min, max ) {
  496. // assumes min < max, componentwise
  497. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  498. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  499. return this;
  500. }
  501. clampScalar( minVal, maxVal ) {
  502. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  503. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  504. return this;
  505. }
  506. clampLength( min, max ) {
  507. const length = this.length();
  508. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  509. }
  510. floor() {
  511. this.x = Math.floor( this.x );
  512. this.y = Math.floor( this.y );
  513. return this;
  514. }
  515. ceil() {
  516. this.x = Math.ceil( this.x );
  517. this.y = Math.ceil( this.y );
  518. return this;
  519. }
  520. round() {
  521. this.x = Math.round( this.x );
  522. this.y = Math.round( this.y );
  523. return this;
  524. }
  525. roundToZero() {
  526. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  527. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  528. return this;
  529. }
  530. negate() {
  531. this.x = - this.x;
  532. this.y = - this.y;
  533. return this;
  534. }
  535. dot( v ) {
  536. return this.x * v.x + this.y * v.y;
  537. }
  538. cross( v ) {
  539. return this.x * v.y - this.y * v.x;
  540. }
  541. lengthSq() {
  542. return this.x * this.x + this.y * this.y;
  543. }
  544. length() {
  545. return Math.sqrt( this.x * this.x + this.y * this.y );
  546. }
  547. manhattanLength() {
  548. return Math.abs( this.x ) + Math.abs( this.y );
  549. }
  550. normalize() {
  551. return this.divideScalar( this.length() || 1 );
  552. }
  553. angle() {
  554. // computes the angle in radians with respect to the positive x-axis
  555. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  556. return angle;
  557. }
  558. distanceTo( v ) {
  559. return Math.sqrt( this.distanceToSquared( v ) );
  560. }
  561. distanceToSquared( v ) {
  562. const dx = this.x - v.x, dy = this.y - v.y;
  563. return dx * dx + dy * dy;
  564. }
  565. manhattanDistanceTo( v ) {
  566. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  567. }
  568. setLength( length ) {
  569. return this.normalize().multiplyScalar( length );
  570. }
  571. lerp( v, alpha ) {
  572. this.x += ( v.x - this.x ) * alpha;
  573. this.y += ( v.y - this.y ) * alpha;
  574. return this;
  575. }
  576. lerpVectors( v1, v2, alpha ) {
  577. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  578. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  579. return this;
  580. }
  581. equals( v ) {
  582. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  583. }
  584. fromArray( array, offset = 0 ) {
  585. this.x = array[ offset ];
  586. this.y = array[ offset + 1 ];
  587. return this;
  588. }
  589. toArray( array = [], offset = 0 ) {
  590. array[ offset ] = this.x;
  591. array[ offset + 1 ] = this.y;
  592. return array;
  593. }
  594. fromBufferAttribute( attribute, index, offset ) {
  595. if ( offset !== undefined ) {
  596. console.warn( 'THREE.Vector2: offset has been removed from .fromBufferAttribute().' );
  597. }
  598. this.x = attribute.getX( index );
  599. this.y = attribute.getY( index );
  600. return this;
  601. }
  602. rotateAround( center, angle ) {
  603. const c = Math.cos( angle ), s = Math.sin( angle );
  604. const x = this.x - center.x;
  605. const y = this.y - center.y;
  606. this.x = x * c - y * s + center.x;
  607. this.y = x * s + y * c + center.y;
  608. return this;
  609. }
  610. random() {
  611. this.x = Math.random();
  612. this.y = Math.random();
  613. return this;
  614. }
  615. }
  616. class Matrix3 {
  617. constructor() {
  618. Object.defineProperty( this, 'isMatrix3', { value: true } );
  619. this.elements = [
  620. 1, 0, 0,
  621. 0, 1, 0,
  622. 0, 0, 1
  623. ];
  624. if ( arguments.length > 0 ) {
  625. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  626. }
  627. }
  628. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  629. const te = this.elements;
  630. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  631. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  632. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  633. return this;
  634. }
  635. identity() {
  636. this.set(
  637. 1, 0, 0,
  638. 0, 1, 0,
  639. 0, 0, 1
  640. );
  641. return this;
  642. }
  643. clone() {
  644. return new this.constructor().fromArray( this.elements );
  645. }
  646. copy( m ) {
  647. const te = this.elements;
  648. const me = m.elements;
  649. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  650. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  651. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  652. return this;
  653. }
  654. extractBasis( xAxis, yAxis, zAxis ) {
  655. xAxis.setFromMatrix3Column( this, 0 );
  656. yAxis.setFromMatrix3Column( this, 1 );
  657. zAxis.setFromMatrix3Column( this, 2 );
  658. return this;
  659. }
  660. setFromMatrix4( m ) {
  661. const me = m.elements;
  662. this.set(
  663. me[ 0 ], me[ 4 ], me[ 8 ],
  664. me[ 1 ], me[ 5 ], me[ 9 ],
  665. me[ 2 ], me[ 6 ], me[ 10 ]
  666. );
  667. return this;
  668. }
  669. multiply( m ) {
  670. return this.multiplyMatrices( this, m );
  671. }
  672. premultiply( m ) {
  673. return this.multiplyMatrices( m, this );
  674. }
  675. multiplyMatrices( a, b ) {
  676. const ae = a.elements;
  677. const be = b.elements;
  678. const te = this.elements;
  679. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  680. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  681. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  682. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  683. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  684. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  685. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  686. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  687. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  688. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  689. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  690. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  691. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  692. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  693. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  694. return this;
  695. }
  696. multiplyScalar( s ) {
  697. const te = this.elements;
  698. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  699. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  700. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  701. return this;
  702. }
  703. determinant() {
  704. const te = this.elements;
  705. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  706. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  707. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  708. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  709. }
  710. invert() {
  711. const te = this.elements,
  712. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  713. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  714. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  715. t11 = n33 * n22 - n32 * n23,
  716. t12 = n32 * n13 - n33 * n12,
  717. t13 = n23 * n12 - n22 * n13,
  718. det = n11 * t11 + n21 * t12 + n31 * t13;
  719. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  720. const detInv = 1 / det;
  721. te[ 0 ] = t11 * detInv;
  722. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  723. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  724. te[ 3 ] = t12 * detInv;
  725. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  726. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  727. te[ 6 ] = t13 * detInv;
  728. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  729. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  730. return this;
  731. }
  732. transpose() {
  733. let tmp;
  734. const m = this.elements;
  735. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  736. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  737. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  738. return this;
  739. }
  740. getNormalMatrix( matrix4 ) {
  741. return this.setFromMatrix4( matrix4 ).copy( this ).invert().transpose();
  742. }
  743. transposeIntoArray( r ) {
  744. const m = this.elements;
  745. r[ 0 ] = m[ 0 ];
  746. r[ 1 ] = m[ 3 ];
  747. r[ 2 ] = m[ 6 ];
  748. r[ 3 ] = m[ 1 ];
  749. r[ 4 ] = m[ 4 ];
  750. r[ 5 ] = m[ 7 ];
  751. r[ 6 ] = m[ 2 ];
  752. r[ 7 ] = m[ 5 ];
  753. r[ 8 ] = m[ 8 ];
  754. return this;
  755. }
  756. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  757. const c = Math.cos( rotation );
  758. const s = Math.sin( rotation );
  759. this.set(
  760. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  761. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  762. 0, 0, 1
  763. );
  764. return this;
  765. }
  766. scale( sx, sy ) {
  767. const te = this.elements;
  768. te[ 0 ] *= sx; te[ 3 ] *= sx; te[ 6 ] *= sx;
  769. te[ 1 ] *= sy; te[ 4 ] *= sy; te[ 7 ] *= sy;
  770. return this;
  771. }
  772. rotate( theta ) {
  773. const c = Math.cos( theta );
  774. const s = Math.sin( theta );
  775. const te = this.elements;
  776. const a11 = te[ 0 ], a12 = te[ 3 ], a13 = te[ 6 ];
  777. const a21 = te[ 1 ], a22 = te[ 4 ], a23 = te[ 7 ];
  778. te[ 0 ] = c * a11 + s * a21;
  779. te[ 3 ] = c * a12 + s * a22;
  780. te[ 6 ] = c * a13 + s * a23;
  781. te[ 1 ] = - s * a11 + c * a21;
  782. te[ 4 ] = - s * a12 + c * a22;
  783. te[ 7 ] = - s * a13 + c * a23;
  784. return this;
  785. }
  786. translate( tx, ty ) {
  787. const te = this.elements;
  788. te[ 0 ] += tx * te[ 2 ]; te[ 3 ] += tx * te[ 5 ]; te[ 6 ] += tx * te[ 8 ];
  789. te[ 1 ] += ty * te[ 2 ]; te[ 4 ] += ty * te[ 5 ]; te[ 7 ] += ty * te[ 8 ];
  790. return this;
  791. }
  792. equals( matrix ) {
  793. const te = this.elements;
  794. const me = matrix.elements;
  795. for ( let i = 0; i < 9; i ++ ) {
  796. if ( te[ i ] !== me[ i ] ) return false;
  797. }
  798. return true;
  799. }
  800. fromArray( array, offset = 0 ) {
  801. for ( let i = 0; i < 9; i ++ ) {
  802. this.elements[ i ] = array[ i + offset ];
  803. }
  804. return this;
  805. }
  806. toArray( array = [], offset = 0 ) {
  807. const te = this.elements;
  808. array[ offset ] = te[ 0 ];
  809. array[ offset + 1 ] = te[ 1 ];
  810. array[ offset + 2 ] = te[ 2 ];
  811. array[ offset + 3 ] = te[ 3 ];
  812. array[ offset + 4 ] = te[ 4 ];
  813. array[ offset + 5 ] = te[ 5 ];
  814. array[ offset + 6 ] = te[ 6 ];
  815. array[ offset + 7 ] = te[ 7 ];
  816. array[ offset + 8 ] = te[ 8 ];
  817. return array;
  818. }
  819. }
  820. let _canvas;
  821. const ImageUtils = {
  822. getDataURL: function ( image ) {
  823. if ( /^data:/i.test( image.src ) ) {
  824. return image.src;
  825. }
  826. if ( typeof HTMLCanvasElement == 'undefined' ) {
  827. return image.src;
  828. }
  829. let canvas;
  830. if ( image instanceof HTMLCanvasElement ) {
  831. canvas = image;
  832. } else {
  833. if ( _canvas === undefined ) _canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  834. _canvas.width = image.width;
  835. _canvas.height = image.height;
  836. const context = _canvas.getContext( '2d' );
  837. if ( image instanceof ImageData ) {
  838. context.putImageData( image, 0, 0 );
  839. } else {
  840. context.drawImage( image, 0, 0, image.width, image.height );
  841. }
  842. canvas = _canvas;
  843. }
  844. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  845. return canvas.toDataURL( 'image/jpeg', 0.6 );
  846. } else {
  847. return canvas.toDataURL( 'image/png' );
  848. }
  849. }
  850. };
  851. let textureId = 0;
  852. function Texture( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = 1, encoding = LinearEncoding ) {
  853. Object.defineProperty( this, 'id', { value: textureId ++ } );
  854. this.uuid = MathUtils.generateUUID();
  855. this.name = '';
  856. this.image = image;
  857. this.mipmaps = [];
  858. this.mapping = mapping;
  859. this.wrapS = wrapS;
  860. this.wrapT = wrapT;
  861. this.magFilter = magFilter;
  862. this.minFilter = minFilter;
  863. this.anisotropy = anisotropy;
  864. this.format = format;
  865. this.internalFormat = null;
  866. this.type = type;
  867. this.offset = new Vector2( 0, 0 );
  868. this.repeat = new Vector2( 1, 1 );
  869. this.center = new Vector2( 0, 0 );
  870. this.rotation = 0;
  871. this.matrixAutoUpdate = true;
  872. this.matrix = new Matrix3();
  873. this.generateMipmaps = true;
  874. this.premultiplyAlpha = false;
  875. this.flipY = true;
  876. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  877. // Values of encoding !== THREE.LinearEncoding only supported on map, envMap and emissiveMap.
  878. //
  879. // Also changing the encoding after already used by a Material will not automatically make the Material
  880. // update. You need to explicitly call Material.needsUpdate to trigger it to recompile.
  881. this.encoding = encoding;
  882. this.version = 0;
  883. this.onUpdate = null;
  884. }
  885. Texture.DEFAULT_IMAGE = undefined;
  886. Texture.DEFAULT_MAPPING = UVMapping;
  887. Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  888. constructor: Texture,
  889. isTexture: true,
  890. updateMatrix: function () {
  891. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  892. },
  893. clone: function () {
  894. return new this.constructor().copy( this );
  895. },
  896. copy: function ( source ) {
  897. this.name = source.name;
  898. this.image = source.image;
  899. this.mipmaps = source.mipmaps.slice( 0 );
  900. this.mapping = source.mapping;
  901. this.wrapS = source.wrapS;
  902. this.wrapT = source.wrapT;
  903. this.magFilter = source.magFilter;
  904. this.minFilter = source.minFilter;
  905. this.anisotropy = source.anisotropy;
  906. this.format = source.format;
  907. this.internalFormat = source.internalFormat;
  908. this.type = source.type;
  909. this.offset.copy( source.offset );
  910. this.repeat.copy( source.repeat );
  911. this.center.copy( source.center );
  912. this.rotation = source.rotation;
  913. this.matrixAutoUpdate = source.matrixAutoUpdate;
  914. this.matrix.copy( source.matrix );
  915. this.generateMipmaps = source.generateMipmaps;
  916. this.premultiplyAlpha = source.premultiplyAlpha;
  917. this.flipY = source.flipY;
  918. this.unpackAlignment = source.unpackAlignment;
  919. this.encoding = source.encoding;
  920. return this;
  921. },
  922. toJSON: function ( meta ) {
  923. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  924. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  925. return meta.textures[ this.uuid ];
  926. }
  927. const output = {
  928. metadata: {
  929. version: 4.5,
  930. type: 'Texture',
  931. generator: 'Texture.toJSON'
  932. },
  933. uuid: this.uuid,
  934. name: this.name,
  935. mapping: this.mapping,
  936. repeat: [ this.repeat.x, this.repeat.y ],
  937. offset: [ this.offset.x, this.offset.y ],
  938. center: [ this.center.x, this.center.y ],
  939. rotation: this.rotation,
  940. wrap: [ this.wrapS, this.wrapT ],
  941. format: this.format,
  942. type: this.type,
  943. encoding: this.encoding,
  944. minFilter: this.minFilter,
  945. magFilter: this.magFilter,
  946. anisotropy: this.anisotropy,
  947. flipY: this.flipY,
  948. premultiplyAlpha: this.premultiplyAlpha,
  949. unpackAlignment: this.unpackAlignment
  950. };
  951. if ( this.image !== undefined ) {
  952. // TODO: Move to THREE.Image
  953. const image = this.image;
  954. if ( image.uuid === undefined ) {
  955. image.uuid = MathUtils.generateUUID(); // UGH
  956. }
  957. if ( ! isRootObject && meta.images[ image.uuid ] === undefined ) {
  958. let url;
  959. if ( Array.isArray( image ) ) {
  960. // process array of images e.g. CubeTexture
  961. url = [];
  962. for ( let i = 0, l = image.length; i < l; i ++ ) {
  963. // check cube texture with data textures
  964. if ( image[ i ].isDataTexture ) {
  965. url.push( serializeImage( image[ i ].image ) );
  966. } else {
  967. url.push( serializeImage( image[ i ] ) );
  968. }
  969. }
  970. } else {
  971. // process single image
  972. url = serializeImage( image );
  973. }
  974. meta.images[ image.uuid ] = {
  975. uuid: image.uuid,
  976. url: url
  977. };
  978. }
  979. output.image = image.uuid;
  980. }
  981. if ( ! isRootObject ) {
  982. meta.textures[ this.uuid ] = output;
  983. }
  984. return output;
  985. },
  986. dispose: function () {
  987. this.dispatchEvent( { type: 'dispose' } );
  988. },
  989. transformUv: function ( uv ) {
  990. if ( this.mapping !== UVMapping ) return uv;
  991. uv.applyMatrix3( this.matrix );
  992. if ( uv.x < 0 || uv.x > 1 ) {
  993. switch ( this.wrapS ) {
  994. case RepeatWrapping:
  995. uv.x = uv.x - Math.floor( uv.x );
  996. break;
  997. case ClampToEdgeWrapping:
  998. uv.x = uv.x < 0 ? 0 : 1;
  999. break;
  1000. case MirroredRepeatWrapping:
  1001. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1002. uv.x = Math.ceil( uv.x ) - uv.x;
  1003. } else {
  1004. uv.x = uv.x - Math.floor( uv.x );
  1005. }
  1006. break;
  1007. }
  1008. }
  1009. if ( uv.y < 0 || uv.y > 1 ) {
  1010. switch ( this.wrapT ) {
  1011. case RepeatWrapping:
  1012. uv.y = uv.y - Math.floor( uv.y );
  1013. break;
  1014. case ClampToEdgeWrapping:
  1015. uv.y = uv.y < 0 ? 0 : 1;
  1016. break;
  1017. case MirroredRepeatWrapping:
  1018. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1019. uv.y = Math.ceil( uv.y ) - uv.y;
  1020. } else {
  1021. uv.y = uv.y - Math.floor( uv.y );
  1022. }
  1023. break;
  1024. }
  1025. }
  1026. if ( this.flipY ) {
  1027. uv.y = 1 - uv.y;
  1028. }
  1029. return uv;
  1030. }
  1031. } );
  1032. Object.defineProperty( Texture.prototype, 'needsUpdate', {
  1033. set: function ( value ) {
  1034. if ( value === true ) this.version ++;
  1035. }
  1036. } );
  1037. function serializeImage( image ) {
  1038. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1039. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1040. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1041. // default images
  1042. return ImageUtils.getDataURL( image );
  1043. } else {
  1044. if ( image.data ) {
  1045. // images of DataTexture
  1046. return {
  1047. data: Array.prototype.slice.call( image.data ),
  1048. width: image.width,
  1049. height: image.height,
  1050. type: image.data.constructor.name
  1051. };
  1052. } else {
  1053. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1054. return {};
  1055. }
  1056. }
  1057. }
  1058. class Vector4 {
  1059. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1060. Object.defineProperty( this, 'isVector4', { value: true } );
  1061. this.x = x;
  1062. this.y = y;
  1063. this.z = z;
  1064. this.w = w;
  1065. }
  1066. get width() {
  1067. return this.z;
  1068. }
  1069. set width( value ) {
  1070. this.z = value;
  1071. }
  1072. get height() {
  1073. return this.w;
  1074. }
  1075. set height( value ) {
  1076. this.w = value;
  1077. }
  1078. set( x, y, z, w ) {
  1079. this.x = x;
  1080. this.y = y;
  1081. this.z = z;
  1082. this.w = w;
  1083. return this;
  1084. }
  1085. setScalar( scalar ) {
  1086. this.x = scalar;
  1087. this.y = scalar;
  1088. this.z = scalar;
  1089. this.w = scalar;
  1090. return this;
  1091. }
  1092. setX( x ) {
  1093. this.x = x;
  1094. return this;
  1095. }
  1096. setY( y ) {
  1097. this.y = y;
  1098. return this;
  1099. }
  1100. setZ( z ) {
  1101. this.z = z;
  1102. return this;
  1103. }
  1104. setW( w ) {
  1105. this.w = w;
  1106. return this;
  1107. }
  1108. setComponent( index, value ) {
  1109. switch ( index ) {
  1110. case 0: this.x = value; break;
  1111. case 1: this.y = value; break;
  1112. case 2: this.z = value; break;
  1113. case 3: this.w = value; break;
  1114. default: throw new Error( 'index is out of range: ' + index );
  1115. }
  1116. return this;
  1117. }
  1118. getComponent( index ) {
  1119. switch ( index ) {
  1120. case 0: return this.x;
  1121. case 1: return this.y;
  1122. case 2: return this.z;
  1123. case 3: return this.w;
  1124. default: throw new Error( 'index is out of range: ' + index );
  1125. }
  1126. }
  1127. clone() {
  1128. return new this.constructor( this.x, this.y, this.z, this.w );
  1129. }
  1130. copy( v ) {
  1131. this.x = v.x;
  1132. this.y = v.y;
  1133. this.z = v.z;
  1134. this.w = ( v.w !== undefined ) ? v.w : 1;
  1135. return this;
  1136. }
  1137. add( v, w ) {
  1138. if ( w !== undefined ) {
  1139. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1140. return this.addVectors( v, w );
  1141. }
  1142. this.x += v.x;
  1143. this.y += v.y;
  1144. this.z += v.z;
  1145. this.w += v.w;
  1146. return this;
  1147. }
  1148. addScalar( s ) {
  1149. this.x += s;
  1150. this.y += s;
  1151. this.z += s;
  1152. this.w += s;
  1153. return this;
  1154. }
  1155. addVectors( a, b ) {
  1156. this.x = a.x + b.x;
  1157. this.y = a.y + b.y;
  1158. this.z = a.z + b.z;
  1159. this.w = a.w + b.w;
  1160. return this;
  1161. }
  1162. addScaledVector( v, s ) {
  1163. this.x += v.x * s;
  1164. this.y += v.y * s;
  1165. this.z += v.z * s;
  1166. this.w += v.w * s;
  1167. return this;
  1168. }
  1169. sub( v, w ) {
  1170. if ( w !== undefined ) {
  1171. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1172. return this.subVectors( v, w );
  1173. }
  1174. this.x -= v.x;
  1175. this.y -= v.y;
  1176. this.z -= v.z;
  1177. this.w -= v.w;
  1178. return this;
  1179. }
  1180. subScalar( s ) {
  1181. this.x -= s;
  1182. this.y -= s;
  1183. this.z -= s;
  1184. this.w -= s;
  1185. return this;
  1186. }
  1187. subVectors( a, b ) {
  1188. this.x = a.x - b.x;
  1189. this.y = a.y - b.y;
  1190. this.z = a.z - b.z;
  1191. this.w = a.w - b.w;
  1192. return this;
  1193. }
  1194. multiplyScalar( scalar ) {
  1195. this.x *= scalar;
  1196. this.y *= scalar;
  1197. this.z *= scalar;
  1198. this.w *= scalar;
  1199. return this;
  1200. }
  1201. applyMatrix4( m ) {
  1202. const x = this.x, y = this.y, z = this.z, w = this.w;
  1203. const e = m.elements;
  1204. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1205. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1206. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1207. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1208. return this;
  1209. }
  1210. divideScalar( scalar ) {
  1211. return this.multiplyScalar( 1 / scalar );
  1212. }
  1213. setAxisAngleFromQuaternion( q ) {
  1214. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1215. // q is assumed to be normalized
  1216. this.w = 2 * Math.acos( q.w );
  1217. const s = Math.sqrt( 1 - q.w * q.w );
  1218. if ( s < 0.0001 ) {
  1219. this.x = 1;
  1220. this.y = 0;
  1221. this.z = 0;
  1222. } else {
  1223. this.x = q.x / s;
  1224. this.y = q.y / s;
  1225. this.z = q.z / s;
  1226. }
  1227. return this;
  1228. }
  1229. setAxisAngleFromRotationMatrix( m ) {
  1230. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1231. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1232. let angle, x, y, z; // variables for result
  1233. const epsilon = 0.01, // margin to allow for rounding errors
  1234. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1235. te = m.elements,
  1236. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1237. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1238. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1239. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1240. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1241. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1242. // singularity found
  1243. // first check for identity matrix which must have +1 for all terms
  1244. // in leading diagonal and zero in other terms
  1245. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1246. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1247. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1248. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1249. // this singularity is identity matrix so angle = 0
  1250. this.set( 1, 0, 0, 0 );
  1251. return this; // zero angle, arbitrary axis
  1252. }
  1253. // otherwise this singularity is angle = 180
  1254. angle = Math.PI;
  1255. const xx = ( m11 + 1 ) / 2;
  1256. const yy = ( m22 + 1 ) / 2;
  1257. const zz = ( m33 + 1 ) / 2;
  1258. const xy = ( m12 + m21 ) / 4;
  1259. const xz = ( m13 + m31 ) / 4;
  1260. const yz = ( m23 + m32 ) / 4;
  1261. if ( ( xx > yy ) && ( xx > zz ) ) {
  1262. // m11 is the largest diagonal term
  1263. if ( xx < epsilon ) {
  1264. x = 0;
  1265. y = 0.707106781;
  1266. z = 0.707106781;
  1267. } else {
  1268. x = Math.sqrt( xx );
  1269. y = xy / x;
  1270. z = xz / x;
  1271. }
  1272. } else if ( yy > zz ) {
  1273. // m22 is the largest diagonal term
  1274. if ( yy < epsilon ) {
  1275. x = 0.707106781;
  1276. y = 0;
  1277. z = 0.707106781;
  1278. } else {
  1279. y = Math.sqrt( yy );
  1280. x = xy / y;
  1281. z = yz / y;
  1282. }
  1283. } else {
  1284. // m33 is the largest diagonal term so base result on this
  1285. if ( zz < epsilon ) {
  1286. x = 0.707106781;
  1287. y = 0.707106781;
  1288. z = 0;
  1289. } else {
  1290. z = Math.sqrt( zz );
  1291. x = xz / z;
  1292. y = yz / z;
  1293. }
  1294. }
  1295. this.set( x, y, z, angle );
  1296. return this; // return 180 deg rotation
  1297. }
  1298. // as we have reached here there are no singularities so we can handle normally
  1299. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1300. ( m13 - m31 ) * ( m13 - m31 ) +
  1301. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1302. if ( Math.abs( s ) < 0.001 ) s = 1;
  1303. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1304. // caught by singularity test above, but I've left it in just in case
  1305. this.x = ( m32 - m23 ) / s;
  1306. this.y = ( m13 - m31 ) / s;
  1307. this.z = ( m21 - m12 ) / s;
  1308. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1309. return this;
  1310. }
  1311. min( v ) {
  1312. this.x = Math.min( this.x, v.x );
  1313. this.y = Math.min( this.y, v.y );
  1314. this.z = Math.min( this.z, v.z );
  1315. this.w = Math.min( this.w, v.w );
  1316. return this;
  1317. }
  1318. max( v ) {
  1319. this.x = Math.max( this.x, v.x );
  1320. this.y = Math.max( this.y, v.y );
  1321. this.z = Math.max( this.z, v.z );
  1322. this.w = Math.max( this.w, v.w );
  1323. return this;
  1324. }
  1325. clamp( min, max ) {
  1326. // assumes min < max, componentwise
  1327. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1328. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1329. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1330. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1331. return this;
  1332. }
  1333. clampScalar( minVal, maxVal ) {
  1334. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  1335. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  1336. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  1337. this.w = Math.max( minVal, Math.min( maxVal, this.w ) );
  1338. return this;
  1339. }
  1340. clampLength( min, max ) {
  1341. const length = this.length();
  1342. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  1343. }
  1344. floor() {
  1345. this.x = Math.floor( this.x );
  1346. this.y = Math.floor( this.y );
  1347. this.z = Math.floor( this.z );
  1348. this.w = Math.floor( this.w );
  1349. return this;
  1350. }
  1351. ceil() {
  1352. this.x = Math.ceil( this.x );
  1353. this.y = Math.ceil( this.y );
  1354. this.z = Math.ceil( this.z );
  1355. this.w = Math.ceil( this.w );
  1356. return this;
  1357. }
  1358. round() {
  1359. this.x = Math.round( this.x );
  1360. this.y = Math.round( this.y );
  1361. this.z = Math.round( this.z );
  1362. this.w = Math.round( this.w );
  1363. return this;
  1364. }
  1365. roundToZero() {
  1366. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1367. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1368. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1369. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1370. return this;
  1371. }
  1372. negate() {
  1373. this.x = - this.x;
  1374. this.y = - this.y;
  1375. this.z = - this.z;
  1376. this.w = - this.w;
  1377. return this;
  1378. }
  1379. dot( v ) {
  1380. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1381. }
  1382. lengthSq() {
  1383. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1384. }
  1385. length() {
  1386. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1387. }
  1388. manhattanLength() {
  1389. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1390. }
  1391. normalize() {
  1392. return this.divideScalar( this.length() || 1 );
  1393. }
  1394. setLength( length ) {
  1395. return this.normalize().multiplyScalar( length );
  1396. }
  1397. lerp( v, alpha ) {
  1398. this.x += ( v.x - this.x ) * alpha;
  1399. this.y += ( v.y - this.y ) * alpha;
  1400. this.z += ( v.z - this.z ) * alpha;
  1401. this.w += ( v.w - this.w ) * alpha;
  1402. return this;
  1403. }
  1404. lerpVectors( v1, v2, alpha ) {
  1405. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1406. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1407. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1408. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1409. return this;
  1410. }
  1411. equals( v ) {
  1412. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1413. }
  1414. fromArray( array, offset = 0 ) {
  1415. this.x = array[ offset ];
  1416. this.y = array[ offset + 1 ];
  1417. this.z = array[ offset + 2 ];
  1418. this.w = array[ offset + 3 ];
  1419. return this;
  1420. }
  1421. toArray( array = [], offset = 0 ) {
  1422. array[ offset ] = this.x;
  1423. array[ offset + 1 ] = this.y;
  1424. array[ offset + 2 ] = this.z;
  1425. array[ offset + 3 ] = this.w;
  1426. return array;
  1427. }
  1428. fromBufferAttribute( attribute, index, offset ) {
  1429. if ( offset !== undefined ) {
  1430. console.warn( 'THREE.Vector4: offset has been removed from .fromBufferAttribute().' );
  1431. }
  1432. this.x = attribute.getX( index );
  1433. this.y = attribute.getY( index );
  1434. this.z = attribute.getZ( index );
  1435. this.w = attribute.getW( index );
  1436. return this;
  1437. }
  1438. random() {
  1439. this.x = Math.random();
  1440. this.y = Math.random();
  1441. this.z = Math.random();
  1442. this.w = Math.random();
  1443. return this;
  1444. }
  1445. }
  1446. /*
  1447. In options, we can specify:
  1448. * Texture parameters for an auto-generated target texture
  1449. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1450. */
  1451. function WebGLRenderTarget( width, height, options ) {
  1452. this.width = width;
  1453. this.height = height;
  1454. this.scissor = new Vector4( 0, 0, width, height );
  1455. this.scissorTest = false;
  1456. this.viewport = new Vector4( 0, 0, width, height );
  1457. options = options || {};
  1458. this.texture = new Texture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  1459. this.texture.image = {};
  1460. this.texture.image.width = width;
  1461. this.texture.image.height = height;
  1462. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  1463. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  1464. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  1465. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : false;
  1466. this.depthTexture = options.depthTexture !== undefined ? options.depthTexture : null;
  1467. }
  1468. WebGLRenderTarget.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  1469. constructor: WebGLRenderTarget,
  1470. isWebGLRenderTarget: true,
  1471. setSize: function ( width, height ) {
  1472. if ( this.width !== width || this.height !== height ) {
  1473. this.width = width;
  1474. this.height = height;
  1475. this.texture.image.width = width;
  1476. this.texture.image.height = height;
  1477. this.dispose();
  1478. }
  1479. this.viewport.set( 0, 0, width, height );
  1480. this.scissor.set( 0, 0, width, height );
  1481. },
  1482. clone: function () {
  1483. return new this.constructor().copy( this );
  1484. },
  1485. copy: function ( source ) {
  1486. this.width = source.width;
  1487. this.height = source.height;
  1488. this.viewport.copy( source.viewport );
  1489. this.texture = source.texture.clone();
  1490. this.depthBuffer = source.depthBuffer;
  1491. this.stencilBuffer = source.stencilBuffer;
  1492. this.depthTexture = source.depthTexture;
  1493. return this;
  1494. },
  1495. dispose: function () {
  1496. this.dispatchEvent( { type: 'dispose' } );
  1497. }
  1498. } );
  1499. function WebGLMultisampleRenderTarget( width, height, options ) {
  1500. WebGLRenderTarget.call( this, width, height, options );
  1501. this.samples = 4;
  1502. }
  1503. WebGLMultisampleRenderTarget.prototype = Object.assign( Object.create( WebGLRenderTarget.prototype ), {
  1504. constructor: WebGLMultisampleRenderTarget,
  1505. isWebGLMultisampleRenderTarget: true,
  1506. copy: function ( source ) {
  1507. WebGLRenderTarget.prototype.copy.call( this, source );
  1508. this.samples = source.samples;
  1509. return this;
  1510. }
  1511. } );
  1512. class Quaternion {
  1513. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1514. Object.defineProperty( this, 'isQuaternion', { value: true } );
  1515. this._x = x;
  1516. this._y = y;
  1517. this._z = z;
  1518. this._w = w;
  1519. }
  1520. static slerp( qa, qb, qm, t ) {
  1521. return qm.copy( qa ).slerp( qb, t );
  1522. }
  1523. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  1524. // fuzz-free, array-based Quaternion SLERP operation
  1525. let x0 = src0[ srcOffset0 + 0 ],
  1526. y0 = src0[ srcOffset0 + 1 ],
  1527. z0 = src0[ srcOffset0 + 2 ],
  1528. w0 = src0[ srcOffset0 + 3 ];
  1529. const x1 = src1[ srcOffset1 + 0 ],
  1530. y1 = src1[ srcOffset1 + 1 ],
  1531. z1 = src1[ srcOffset1 + 2 ],
  1532. w1 = src1[ srcOffset1 + 3 ];
  1533. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  1534. let s = 1 - t;
  1535. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  1536. dir = ( cos >= 0 ? 1 : - 1 ),
  1537. sqrSin = 1 - cos * cos;
  1538. // Skip the Slerp for tiny steps to avoid numeric problems:
  1539. if ( sqrSin > Number.EPSILON ) {
  1540. const sin = Math.sqrt( sqrSin ),
  1541. len = Math.atan2( sin, cos * dir );
  1542. s = Math.sin( s * len ) / sin;
  1543. t = Math.sin( t * len ) / sin;
  1544. }
  1545. const tDir = t * dir;
  1546. x0 = x0 * s + x1 * tDir;
  1547. y0 = y0 * s + y1 * tDir;
  1548. z0 = z0 * s + z1 * tDir;
  1549. w0 = w0 * s + w1 * tDir;
  1550. // Normalize in case we just did a lerp:
  1551. if ( s === 1 - t ) {
  1552. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  1553. x0 *= f;
  1554. y0 *= f;
  1555. z0 *= f;
  1556. w0 *= f;
  1557. }
  1558. }
  1559. dst[ dstOffset ] = x0;
  1560. dst[ dstOffset + 1 ] = y0;
  1561. dst[ dstOffset + 2 ] = z0;
  1562. dst[ dstOffset + 3 ] = w0;
  1563. }
  1564. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  1565. const x0 = src0[ srcOffset0 ];
  1566. const y0 = src0[ srcOffset0 + 1 ];
  1567. const z0 = src0[ srcOffset0 + 2 ];
  1568. const w0 = src0[ srcOffset0 + 3 ];
  1569. const x1 = src1[ srcOffset1 ];
  1570. const y1 = src1[ srcOffset1 + 1 ];
  1571. const z1 = src1[ srcOffset1 + 2 ];
  1572. const w1 = src1[ srcOffset1 + 3 ];
  1573. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  1574. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  1575. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  1576. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  1577. return dst;
  1578. }
  1579. get x() {
  1580. return this._x;
  1581. }
  1582. set x( value ) {
  1583. this._x = value;
  1584. this._onChangeCallback();
  1585. }
  1586. get y() {
  1587. return this._y;
  1588. }
  1589. set y( value ) {
  1590. this._y = value;
  1591. this._onChangeCallback();
  1592. }
  1593. get z() {
  1594. return this._z;
  1595. }
  1596. set z( value ) {
  1597. this._z = value;
  1598. this._onChangeCallback();
  1599. }
  1600. get w() {
  1601. return this._w;
  1602. }
  1603. set w( value ) {
  1604. this._w = value;
  1605. this._onChangeCallback();
  1606. }
  1607. set( x, y, z, w ) {
  1608. this._x = x;
  1609. this._y = y;
  1610. this._z = z;
  1611. this._w = w;
  1612. this._onChangeCallback();
  1613. return this;
  1614. }
  1615. clone() {
  1616. return new this.constructor( this._x, this._y, this._z, this._w );
  1617. }
  1618. copy( quaternion ) {
  1619. this._x = quaternion.x;
  1620. this._y = quaternion.y;
  1621. this._z = quaternion.z;
  1622. this._w = quaternion.w;
  1623. this._onChangeCallback();
  1624. return this;
  1625. }
  1626. setFromEuler( euler, update ) {
  1627. if ( ! ( euler && euler.isEuler ) ) {
  1628. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1629. }
  1630. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  1631. // http://www.mathworks.com/matlabcentral/fileexchange/
  1632. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  1633. // content/SpinCalc.m
  1634. const cos = Math.cos;
  1635. const sin = Math.sin;
  1636. const c1 = cos( x / 2 );
  1637. const c2 = cos( y / 2 );
  1638. const c3 = cos( z / 2 );
  1639. const s1 = sin( x / 2 );
  1640. const s2 = sin( y / 2 );
  1641. const s3 = sin( z / 2 );
  1642. switch ( order ) {
  1643. case 'XYZ':
  1644. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1645. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1646. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1647. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1648. break;
  1649. case 'YXZ':
  1650. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1651. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1652. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1653. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1654. break;
  1655. case 'ZXY':
  1656. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1657. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1658. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1659. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1660. break;
  1661. case 'ZYX':
  1662. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1663. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1664. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1665. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1666. break;
  1667. case 'YZX':
  1668. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  1669. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  1670. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  1671. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  1672. break;
  1673. case 'XZY':
  1674. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  1675. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  1676. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  1677. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  1678. break;
  1679. default:
  1680. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  1681. }
  1682. if ( update !== false ) this._onChangeCallback();
  1683. return this;
  1684. }
  1685. setFromAxisAngle( axis, angle ) {
  1686. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  1687. // assumes axis is normalized
  1688. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  1689. this._x = axis.x * s;
  1690. this._y = axis.y * s;
  1691. this._z = axis.z * s;
  1692. this._w = Math.cos( halfAngle );
  1693. this._onChangeCallback();
  1694. return this;
  1695. }
  1696. setFromRotationMatrix( m ) {
  1697. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  1698. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1699. const te = m.elements,
  1700. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1701. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1702. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  1703. trace = m11 + m22 + m33;
  1704. if ( trace > 0 ) {
  1705. const s = 0.5 / Math.sqrt( trace + 1.0 );
  1706. this._w = 0.25 / s;
  1707. this._x = ( m32 - m23 ) * s;
  1708. this._y = ( m13 - m31 ) * s;
  1709. this._z = ( m21 - m12 ) * s;
  1710. } else if ( m11 > m22 && m11 > m33 ) {
  1711. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  1712. this._w = ( m32 - m23 ) / s;
  1713. this._x = 0.25 * s;
  1714. this._y = ( m12 + m21 ) / s;
  1715. this._z = ( m13 + m31 ) / s;
  1716. } else if ( m22 > m33 ) {
  1717. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  1718. this._w = ( m13 - m31 ) / s;
  1719. this._x = ( m12 + m21 ) / s;
  1720. this._y = 0.25 * s;
  1721. this._z = ( m23 + m32 ) / s;
  1722. } else {
  1723. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  1724. this._w = ( m21 - m12 ) / s;
  1725. this._x = ( m13 + m31 ) / s;
  1726. this._y = ( m23 + m32 ) / s;
  1727. this._z = 0.25 * s;
  1728. }
  1729. this._onChangeCallback();
  1730. return this;
  1731. }
  1732. setFromUnitVectors( vFrom, vTo ) {
  1733. // assumes direction vectors vFrom and vTo are normalized
  1734. const EPS = 0.000001;
  1735. let r = vFrom.dot( vTo ) + 1;
  1736. if ( r < EPS ) {
  1737. r = 0;
  1738. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  1739. this._x = - vFrom.y;
  1740. this._y = vFrom.x;
  1741. this._z = 0;
  1742. this._w = r;
  1743. } else {
  1744. this._x = 0;
  1745. this._y = - vFrom.z;
  1746. this._z = vFrom.y;
  1747. this._w = r;
  1748. }
  1749. } else {
  1750. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  1751. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  1752. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  1753. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  1754. this._w = r;
  1755. }
  1756. return this.normalize();
  1757. }
  1758. angleTo( q ) {
  1759. return 2 * Math.acos( Math.abs( MathUtils.clamp( this.dot( q ), - 1, 1 ) ) );
  1760. }
  1761. rotateTowards( q, step ) {
  1762. const angle = this.angleTo( q );
  1763. if ( angle === 0 ) return this;
  1764. const t = Math.min( 1, step / angle );
  1765. this.slerp( q, t );
  1766. return this;
  1767. }
  1768. identity() {
  1769. return this.set( 0, 0, 0, 1 );
  1770. }
  1771. invert() {
  1772. // quaternion is assumed to have unit length
  1773. return this.conjugate();
  1774. }
  1775. conjugate() {
  1776. this._x *= - 1;
  1777. this._y *= - 1;
  1778. this._z *= - 1;
  1779. this._onChangeCallback();
  1780. return this;
  1781. }
  1782. dot( v ) {
  1783. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  1784. }
  1785. lengthSq() {
  1786. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  1787. }
  1788. length() {
  1789. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  1790. }
  1791. normalize() {
  1792. let l = this.length();
  1793. if ( l === 0 ) {
  1794. this._x = 0;
  1795. this._y = 0;
  1796. this._z = 0;
  1797. this._w = 1;
  1798. } else {
  1799. l = 1 / l;
  1800. this._x = this._x * l;
  1801. this._y = this._y * l;
  1802. this._z = this._z * l;
  1803. this._w = this._w * l;
  1804. }
  1805. this._onChangeCallback();
  1806. return this;
  1807. }
  1808. multiply( q, p ) {
  1809. if ( p !== undefined ) {
  1810. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  1811. return this.multiplyQuaternions( q, p );
  1812. }
  1813. return this.multiplyQuaternions( this, q );
  1814. }
  1815. premultiply( q ) {
  1816. return this.multiplyQuaternions( q, this );
  1817. }
  1818. multiplyQuaternions( a, b ) {
  1819. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  1820. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  1821. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  1822. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  1823. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  1824. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  1825. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  1826. this._onChangeCallback();
  1827. return this;
  1828. }
  1829. slerp( qb, t ) {
  1830. if ( t === 0 ) return this;
  1831. if ( t === 1 ) return this.copy( qb );
  1832. const x = this._x, y = this._y, z = this._z, w = this._w;
  1833. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  1834. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  1835. if ( cosHalfTheta < 0 ) {
  1836. this._w = - qb._w;
  1837. this._x = - qb._x;
  1838. this._y = - qb._y;
  1839. this._z = - qb._z;
  1840. cosHalfTheta = - cosHalfTheta;
  1841. } else {
  1842. this.copy( qb );
  1843. }
  1844. if ( cosHalfTheta >= 1.0 ) {
  1845. this._w = w;
  1846. this._x = x;
  1847. this._y = y;
  1848. this._z = z;
  1849. return this;
  1850. }
  1851. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  1852. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  1853. const s = 1 - t;
  1854. this._w = s * w + t * this._w;
  1855. this._x = s * x + t * this._x;
  1856. this._y = s * y + t * this._y;
  1857. this._z = s * z + t * this._z;
  1858. this.normalize();
  1859. this._onChangeCallback();
  1860. return this;
  1861. }
  1862. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  1863. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  1864. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  1865. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  1866. this._w = ( w * ratioA + this._w * ratioB );
  1867. this._x = ( x * ratioA + this._x * ratioB );
  1868. this._y = ( y * ratioA + this._y * ratioB );
  1869. this._z = ( z * ratioA + this._z * ratioB );
  1870. this._onChangeCallback();
  1871. return this;
  1872. }
  1873. equals( quaternion ) {
  1874. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  1875. }
  1876. fromArray( array, offset = 0 ) {
  1877. this._x = array[ offset ];
  1878. this._y = array[ offset + 1 ];
  1879. this._z = array[ offset + 2 ];
  1880. this._w = array[ offset + 3 ];
  1881. this._onChangeCallback();
  1882. return this;
  1883. }
  1884. toArray( array = [], offset = 0 ) {
  1885. array[ offset ] = this._x;
  1886. array[ offset + 1 ] = this._y;
  1887. array[ offset + 2 ] = this._z;
  1888. array[ offset + 3 ] = this._w;
  1889. return array;
  1890. }
  1891. fromBufferAttribute( attribute, index ) {
  1892. this._x = attribute.getX( index );
  1893. this._y = attribute.getY( index );
  1894. this._z = attribute.getZ( index );
  1895. this._w = attribute.getW( index );
  1896. return this;
  1897. }
  1898. _onChange( callback ) {
  1899. this._onChangeCallback = callback;
  1900. return this;
  1901. }
  1902. _onChangeCallback() {}
  1903. }
  1904. class Vector3 {
  1905. constructor( x = 0, y = 0, z = 0 ) {
  1906. Object.defineProperty( this, 'isVector3', { value: true } );
  1907. this.x = x;
  1908. this.y = y;
  1909. this.z = z;
  1910. }
  1911. set( x, y, z ) {
  1912. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  1913. this.x = x;
  1914. this.y = y;
  1915. this.z = z;
  1916. return this;
  1917. }
  1918. setScalar( scalar ) {
  1919. this.x = scalar;
  1920. this.y = scalar;
  1921. this.z = scalar;
  1922. return this;
  1923. }
  1924. setX( x ) {
  1925. this.x = x;
  1926. return this;
  1927. }
  1928. setY( y ) {
  1929. this.y = y;
  1930. return this;
  1931. }
  1932. setZ( z ) {
  1933. this.z = z;
  1934. return this;
  1935. }
  1936. setComponent( index, value ) {
  1937. switch ( index ) {
  1938. case 0: this.x = value; break;
  1939. case 1: this.y = value; break;
  1940. case 2: this.z = value; break;
  1941. default: throw new Error( 'index is out of range: ' + index );
  1942. }
  1943. return this;
  1944. }
  1945. getComponent( index ) {
  1946. switch ( index ) {
  1947. case 0: return this.x;
  1948. case 1: return this.y;
  1949. case 2: return this.z;
  1950. default: throw new Error( 'index is out of range: ' + index );
  1951. }
  1952. }
  1953. clone() {
  1954. return new this.constructor( this.x, this.y, this.z );
  1955. }
  1956. copy( v ) {
  1957. this.x = v.x;
  1958. this.y = v.y;
  1959. this.z = v.z;
  1960. return this;
  1961. }
  1962. add( v, w ) {
  1963. if ( w !== undefined ) {
  1964. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1965. return this.addVectors( v, w );
  1966. }
  1967. this.x += v.x;
  1968. this.y += v.y;
  1969. this.z += v.z;
  1970. return this;
  1971. }
  1972. addScalar( s ) {
  1973. this.x += s;
  1974. this.y += s;
  1975. this.z += s;
  1976. return this;
  1977. }
  1978. addVectors( a, b ) {
  1979. this.x = a.x + b.x;
  1980. this.y = a.y + b.y;
  1981. this.z = a.z + b.z;
  1982. return this;
  1983. }
  1984. addScaledVector( v, s ) {
  1985. this.x += v.x * s;
  1986. this.y += v.y * s;
  1987. this.z += v.z * s;
  1988. return this;
  1989. }
  1990. sub( v, w ) {
  1991. if ( w !== undefined ) {
  1992. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1993. return this.subVectors( v, w );
  1994. }
  1995. this.x -= v.x;
  1996. this.y -= v.y;
  1997. this.z -= v.z;
  1998. return this;
  1999. }
  2000. subScalar( s ) {
  2001. this.x -= s;
  2002. this.y -= s;
  2003. this.z -= s;
  2004. return this;
  2005. }
  2006. subVectors( a, b ) {
  2007. this.x = a.x - b.x;
  2008. this.y = a.y - b.y;
  2009. this.z = a.z - b.z;
  2010. return this;
  2011. }
  2012. multiply( v, w ) {
  2013. if ( w !== undefined ) {
  2014. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  2015. return this.multiplyVectors( v, w );
  2016. }
  2017. this.x *= v.x;
  2018. this.y *= v.y;
  2019. this.z *= v.z;
  2020. return this;
  2021. }
  2022. multiplyScalar( scalar ) {
  2023. this.x *= scalar;
  2024. this.y *= scalar;
  2025. this.z *= scalar;
  2026. return this;
  2027. }
  2028. multiplyVectors( a, b ) {
  2029. this.x = a.x * b.x;
  2030. this.y = a.y * b.y;
  2031. this.z = a.z * b.z;
  2032. return this;
  2033. }
  2034. applyEuler( euler ) {
  2035. if ( ! ( euler && euler.isEuler ) ) {
  2036. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  2037. }
  2038. return this.applyQuaternion( _quaternion.setFromEuler( euler ) );
  2039. }
  2040. applyAxisAngle( axis, angle ) {
  2041. return this.applyQuaternion( _quaternion.setFromAxisAngle( axis, angle ) );
  2042. }
  2043. applyMatrix3( m ) {
  2044. const x = this.x, y = this.y, z = this.z;
  2045. const e = m.elements;
  2046. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2047. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2048. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2049. return this;
  2050. }
  2051. applyNormalMatrix( m ) {
  2052. return this.applyMatrix3( m ).normalize();
  2053. }
  2054. applyMatrix4( m ) {
  2055. const x = this.x, y = this.y, z = this.z;
  2056. const e = m.elements;
  2057. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2058. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2059. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2060. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2061. return this;
  2062. }
  2063. applyQuaternion( q ) {
  2064. const x = this.x, y = this.y, z = this.z;
  2065. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2066. // calculate quat * vector
  2067. const ix = qw * x + qy * z - qz * y;
  2068. const iy = qw * y + qz * x - qx * z;
  2069. const iz = qw * z + qx * y - qy * x;
  2070. const iw = - qx * x - qy * y - qz * z;
  2071. // calculate result * inverse quat
  2072. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  2073. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  2074. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  2075. return this;
  2076. }
  2077. project( camera ) {
  2078. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2079. }
  2080. unproject( camera ) {
  2081. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2082. }
  2083. transformDirection( m ) {
  2084. // input: THREE.Matrix4 affine matrix
  2085. // vector interpreted as a direction
  2086. const x = this.x, y = this.y, z = this.z;
  2087. const e = m.elements;
  2088. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2089. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2090. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2091. return this.normalize();
  2092. }
  2093. divide( v ) {
  2094. this.x /= v.x;
  2095. this.y /= v.y;
  2096. this.z /= v.z;
  2097. return this;
  2098. }
  2099. divideScalar( scalar ) {
  2100. return this.multiplyScalar( 1 / scalar );
  2101. }
  2102. min( v ) {
  2103. this.x = Math.min( this.x, v.x );
  2104. this.y = Math.min( this.y, v.y );
  2105. this.z = Math.min( this.z, v.z );
  2106. return this;
  2107. }
  2108. max( v ) {
  2109. this.x = Math.max( this.x, v.x );
  2110. this.y = Math.max( this.y, v.y );
  2111. this.z = Math.max( this.z, v.z );
  2112. return this;
  2113. }
  2114. clamp( min, max ) {
  2115. // assumes min < max, componentwise
  2116. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  2117. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  2118. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  2119. return this;
  2120. }
  2121. clampScalar( minVal, maxVal ) {
  2122. this.x = Math.max( minVal, Math.min( maxVal, this.x ) );
  2123. this.y = Math.max( minVal, Math.min( maxVal, this.y ) );
  2124. this.z = Math.max( minVal, Math.min( maxVal, this.z ) );
  2125. return this;
  2126. }
  2127. clampLength( min, max ) {
  2128. const length = this.length();
  2129. return this.divideScalar( length || 1 ).multiplyScalar( Math.max( min, Math.min( max, length ) ) );
  2130. }
  2131. floor() {
  2132. this.x = Math.floor( this.x );
  2133. this.y = Math.floor( this.y );
  2134. this.z = Math.floor( this.z );
  2135. return this;
  2136. }
  2137. ceil() {
  2138. this.x = Math.ceil( this.x );
  2139. this.y = Math.ceil( this.y );
  2140. this.z = Math.ceil( this.z );
  2141. return this;
  2142. }
  2143. round() {
  2144. this.x = Math.round( this.x );
  2145. this.y = Math.round( this.y );
  2146. this.z = Math.round( this.z );
  2147. return this;
  2148. }
  2149. roundToZero() {
  2150. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  2151. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  2152. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  2153. return this;
  2154. }
  2155. negate() {
  2156. this.x = - this.x;
  2157. this.y = - this.y;
  2158. this.z = - this.z;
  2159. return this;
  2160. }
  2161. dot( v ) {
  2162. return this.x * v.x + this.y * v.y + this.z * v.z;
  2163. }
  2164. // TODO lengthSquared?
  2165. lengthSq() {
  2166. return this.x * this.x + this.y * this.y + this.z * this.z;
  2167. }
  2168. length() {
  2169. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2170. }
  2171. manhattanLength() {
  2172. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2173. }
  2174. normalize() {
  2175. return this.divideScalar( this.length() || 1 );
  2176. }
  2177. setLength( length ) {
  2178. return this.normalize().multiplyScalar( length );
  2179. }
  2180. lerp( v, alpha ) {
  2181. this.x += ( v.x - this.x ) * alpha;
  2182. this.y += ( v.y - this.y ) * alpha;
  2183. this.z += ( v.z - this.z ) * alpha;
  2184. return this;
  2185. }
  2186. lerpVectors( v1, v2, alpha ) {
  2187. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2188. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2189. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2190. return this;
  2191. }
  2192. cross( v, w ) {
  2193. if ( w !== undefined ) {
  2194. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  2195. return this.crossVectors( v, w );
  2196. }
  2197. return this.crossVectors( this, v );
  2198. }
  2199. crossVectors( a, b ) {
  2200. const ax = a.x, ay = a.y, az = a.z;
  2201. const bx = b.x, by = b.y, bz = b.z;
  2202. this.x = ay * bz - az * by;
  2203. this.y = az * bx - ax * bz;
  2204. this.z = ax * by - ay * bx;
  2205. return this;
  2206. }
  2207. projectOnVector( v ) {
  2208. const denominator = v.lengthSq();
  2209. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2210. const scalar = v.dot( this ) / denominator;
  2211. return this.copy( v ).multiplyScalar( scalar );
  2212. }
  2213. projectOnPlane( planeNormal ) {
  2214. _vector.copy( this ).projectOnVector( planeNormal );
  2215. return this.sub( _vector );
  2216. }
  2217. reflect( normal ) {
  2218. // reflect incident vector off plane orthogonal to normal
  2219. // normal is assumed to have unit length
  2220. return this.sub( _vector.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2221. }
  2222. angleTo( v ) {
  2223. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2224. if ( denominator === 0 ) return Math.PI / 2;
  2225. const theta = this.dot( v ) / denominator;
  2226. // clamp, to handle numerical problems
  2227. return Math.acos( MathUtils.clamp( theta, - 1, 1 ) );
  2228. }
  2229. distanceTo( v ) {
  2230. return Math.sqrt( this.distanceToSquared( v ) );
  2231. }
  2232. distanceToSquared( v ) {
  2233. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2234. return dx * dx + dy * dy + dz * dz;
  2235. }
  2236. manhattanDistanceTo( v ) {
  2237. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2238. }
  2239. setFromSpherical( s ) {
  2240. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2241. }
  2242. setFromSphericalCoords( radius, phi, theta ) {
  2243. const sinPhiRadius = Math.sin( phi ) * radius;
  2244. this.x = sinPhiRadius * Math.sin( theta );
  2245. this.y = Math.cos( phi ) * radius;
  2246. this.z = sinPhiRadius * Math.cos( theta );
  2247. return this;
  2248. }
  2249. setFromCylindrical( c ) {
  2250. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2251. }
  2252. setFromCylindricalCoords( radius, theta, y ) {
  2253. this.x = radius * Math.sin( theta );
  2254. this.y = y;
  2255. this.z = radius * Math.cos( theta );
  2256. return this;
  2257. }
  2258. setFromMatrixPosition( m ) {
  2259. const e = m.elements;
  2260. this.x = e[ 12 ];
  2261. this.y = e[ 13 ];
  2262. this.z = e[ 14 ];
  2263. return this;
  2264. }
  2265. setFromMatrixScale( m ) {
  2266. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2267. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2268. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2269. this.x = sx;
  2270. this.y = sy;
  2271. this.z = sz;
  2272. return this;
  2273. }
  2274. setFromMatrixColumn( m, index ) {
  2275. return this.fromArray( m.elements, index * 4 );
  2276. }
  2277. setFromMatrix3Column( m, index ) {
  2278. return this.fromArray( m.elements, index * 3 );
  2279. }
  2280. equals( v ) {
  2281. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2282. }
  2283. fromArray( array, offset = 0 ) {
  2284. this.x = array[ offset ];
  2285. this.y = array[ offset + 1 ];
  2286. this.z = array[ offset + 2 ];
  2287. return this;
  2288. }
  2289. toArray( array = [], offset = 0 ) {
  2290. array[ offset ] = this.x;
  2291. array[ offset + 1 ] = this.y;
  2292. array[ offset + 2 ] = this.z;
  2293. return array;
  2294. }
  2295. fromBufferAttribute( attribute, index, offset ) {
  2296. if ( offset !== undefined ) {
  2297. console.warn( 'THREE.Vector3: offset has been removed from .fromBufferAttribute().' );
  2298. }
  2299. this.x = attribute.getX( index );
  2300. this.y = attribute.getY( index );
  2301. this.z = attribute.getZ( index );
  2302. return this;
  2303. }
  2304. random() {
  2305. this.x = Math.random();
  2306. this.y = Math.random();
  2307. this.z = Math.random();
  2308. return this;
  2309. }
  2310. }
  2311. const _vector = /*@__PURE__*/ new Vector3();
  2312. const _quaternion = /*@__PURE__*/ new Quaternion();
  2313. class Box3 {
  2314. constructor( min, max ) {
  2315. Object.defineProperty( this, 'isBox3', { value: true } );
  2316. this.min = ( min !== undefined ) ? min : new Vector3( + Infinity, + Infinity, + Infinity );
  2317. this.max = ( max !== undefined ) ? max : new Vector3( - Infinity, - Infinity, - Infinity );
  2318. }
  2319. set( min, max ) {
  2320. this.min.copy( min );
  2321. this.max.copy( max );
  2322. return this;
  2323. }
  2324. setFromArray( array ) {
  2325. let minX = + Infinity;
  2326. let minY = + Infinity;
  2327. let minZ = + Infinity;
  2328. let maxX = - Infinity;
  2329. let maxY = - Infinity;
  2330. let maxZ = - Infinity;
  2331. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  2332. const x = array[ i ];
  2333. const y = array[ i + 1 ];
  2334. const z = array[ i + 2 ];
  2335. if ( x < minX ) minX = x;
  2336. if ( y < minY ) minY = y;
  2337. if ( z < minZ ) minZ = z;
  2338. if ( x > maxX ) maxX = x;
  2339. if ( y > maxY ) maxY = y;
  2340. if ( z > maxZ ) maxZ = z;
  2341. }
  2342. this.min.set( minX, minY, minZ );
  2343. this.max.set( maxX, maxY, maxZ );
  2344. return this;
  2345. }
  2346. setFromBufferAttribute( attribute ) {
  2347. let minX = + Infinity;
  2348. let minY = + Infinity;
  2349. let minZ = + Infinity;
  2350. let maxX = - Infinity;
  2351. let maxY = - Infinity;
  2352. let maxZ = - Infinity;
  2353. for ( let i = 0, l = attribute.count; i < l; i ++ ) {
  2354. const x = attribute.getX( i );
  2355. const y = attribute.getY( i );
  2356. const z = attribute.getZ( i );
  2357. if ( x < minX ) minX = x;
  2358. if ( y < minY ) minY = y;
  2359. if ( z < minZ ) minZ = z;
  2360. if ( x > maxX ) maxX = x;
  2361. if ( y > maxY ) maxY = y;
  2362. if ( z > maxZ ) maxZ = z;
  2363. }
  2364. this.min.set( minX, minY, minZ );
  2365. this.max.set( maxX, maxY, maxZ );
  2366. return this;
  2367. }
  2368. setFromPoints( points ) {
  2369. this.makeEmpty();
  2370. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2371. this.expandByPoint( points[ i ] );
  2372. }
  2373. return this;
  2374. }
  2375. setFromCenterAndSize( center, size ) {
  2376. const halfSize = _vector$1.copy( size ).multiplyScalar( 0.5 );
  2377. this.min.copy( center ).sub( halfSize );
  2378. this.max.copy( center ).add( halfSize );
  2379. return this;
  2380. }
  2381. setFromObject( object ) {
  2382. this.makeEmpty();
  2383. return this.expandByObject( object );
  2384. }
  2385. clone() {
  2386. return new this.constructor().copy( this );
  2387. }
  2388. copy( box ) {
  2389. this.min.copy( box.min );
  2390. this.max.copy( box.max );
  2391. return this;
  2392. }
  2393. makeEmpty() {
  2394. this.min.x = this.min.y = this.min.z = + Infinity;
  2395. this.max.x = this.max.y = this.max.z = - Infinity;
  2396. return this;
  2397. }
  2398. isEmpty() {
  2399. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2400. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2401. }
  2402. getCenter( target ) {
  2403. if ( target === undefined ) {
  2404. console.warn( 'THREE.Box3: .getCenter() target is now required' );
  2405. target = new Vector3();
  2406. }
  2407. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2408. }
  2409. getSize( target ) {
  2410. if ( target === undefined ) {
  2411. console.warn( 'THREE.Box3: .getSize() target is now required' );
  2412. target = new Vector3();
  2413. }
  2414. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2415. }
  2416. expandByPoint( point ) {
  2417. this.min.min( point );
  2418. this.max.max( point );
  2419. return this;
  2420. }
  2421. expandByVector( vector ) {
  2422. this.min.sub( vector );
  2423. this.max.add( vector );
  2424. return this;
  2425. }
  2426. expandByScalar( scalar ) {
  2427. this.min.addScalar( - scalar );
  2428. this.max.addScalar( scalar );
  2429. return this;
  2430. }
  2431. expandByObject( object ) {
  2432. // Computes the world-axis-aligned bounding box of an object (including its children),
  2433. // accounting for both the object's, and children's, world transforms
  2434. object.updateWorldMatrix( false, false );
  2435. const geometry = object.geometry;
  2436. if ( geometry !== undefined ) {
  2437. if ( geometry.boundingBox === null ) {
  2438. geometry.computeBoundingBox();
  2439. }
  2440. _box.copy( geometry.boundingBox );
  2441. _box.applyMatrix4( object.matrixWorld );
  2442. this.union( _box );
  2443. }
  2444. const children = object.children;
  2445. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2446. this.expandByObject( children[ i ] );
  2447. }
  2448. return this;
  2449. }
  2450. containsPoint( point ) {
  2451. return point.x < this.min.x || point.x > this.max.x ||
  2452. point.y < this.min.y || point.y > this.max.y ||
  2453. point.z < this.min.z || point.z > this.max.z ? false : true;
  2454. }
  2455. containsBox( box ) {
  2456. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2457. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2458. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2459. }
  2460. getParameter( point, target ) {
  2461. // This can potentially have a divide by zero if the box
  2462. // has a size dimension of 0.
  2463. if ( target === undefined ) {
  2464. console.warn( 'THREE.Box3: .getParameter() target is now required' );
  2465. target = new Vector3();
  2466. }
  2467. return target.set(
  2468. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2469. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2470. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2471. );
  2472. }
  2473. intersectsBox( box ) {
  2474. // using 6 splitting planes to rule out intersections.
  2475. return box.max.x < this.min.x || box.min.x > this.max.x ||
  2476. box.max.y < this.min.y || box.min.y > this.max.y ||
  2477. box.max.z < this.min.z || box.min.z > this.max.z ? false : true;
  2478. }
  2479. intersectsSphere( sphere ) {
  2480. // Find the point on the AABB closest to the sphere center.
  2481. this.clampPoint( sphere.center, _vector$1 );
  2482. // If that point is inside the sphere, the AABB and sphere intersect.
  2483. return _vector$1.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2484. }
  2485. intersectsPlane( plane ) {
  2486. // We compute the minimum and maximum dot product values. If those values
  2487. // are on the same side (back or front) of the plane, then there is no intersection.
  2488. let min, max;
  2489. if ( plane.normal.x > 0 ) {
  2490. min = plane.normal.x * this.min.x;
  2491. max = plane.normal.x * this.max.x;
  2492. } else {
  2493. min = plane.normal.x * this.max.x;
  2494. max = plane.normal.x * this.min.x;
  2495. }
  2496. if ( plane.normal.y > 0 ) {
  2497. min += plane.normal.y * this.min.y;
  2498. max += plane.normal.y * this.max.y;
  2499. } else {
  2500. min += plane.normal.y * this.max.y;
  2501. max += plane.normal.y * this.min.y;
  2502. }
  2503. if ( plane.normal.z > 0 ) {
  2504. min += plane.normal.z * this.min.z;
  2505. max += plane.normal.z * this.max.z;
  2506. } else {
  2507. min += plane.normal.z * this.max.z;
  2508. max += plane.normal.z * this.min.z;
  2509. }
  2510. return ( min <= - plane.constant && max >= - plane.constant );
  2511. }
  2512. intersectsTriangle( triangle ) {
  2513. if ( this.isEmpty() ) {
  2514. return false;
  2515. }
  2516. // compute box center and extents
  2517. this.getCenter( _center );
  2518. _extents.subVectors( this.max, _center );
  2519. // translate triangle to aabb origin
  2520. _v0.subVectors( triangle.a, _center );
  2521. _v1.subVectors( triangle.b, _center );
  2522. _v2.subVectors( triangle.c, _center );
  2523. // compute edge vectors for triangle
  2524. _f0.subVectors( _v1, _v0 );
  2525. _f1.subVectors( _v2, _v1 );
  2526. _f2.subVectors( _v0, _v2 );
  2527. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  2528. // 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
  2529. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  2530. let axes = [
  2531. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  2532. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  2533. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  2534. ];
  2535. if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
  2536. return false;
  2537. }
  2538. // test 3 face normals from the aabb
  2539. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  2540. if ( ! satForAxes( axes, _v0, _v1, _v2, _extents ) ) {
  2541. return false;
  2542. }
  2543. // finally testing the face normal of the triangle
  2544. // use already existing triangle edge vectors here
  2545. _triangleNormal.crossVectors( _f0, _f1 );
  2546. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  2547. return satForAxes( axes, _v0, _v1, _v2, _extents );
  2548. }
  2549. clampPoint( point, target ) {
  2550. if ( target === undefined ) {
  2551. console.warn( 'THREE.Box3: .clampPoint() target is now required' );
  2552. target = new Vector3();
  2553. }
  2554. return target.copy( point ).clamp( this.min, this.max );
  2555. }
  2556. distanceToPoint( point ) {
  2557. const clampedPoint = _vector$1.copy( point ).clamp( this.min, this.max );
  2558. return clampedPoint.sub( point ).length();
  2559. }
  2560. getBoundingSphere( target ) {
  2561. if ( target === undefined ) {
  2562. console.error( 'THREE.Box3: .getBoundingSphere() target is now required' );
  2563. //target = new Sphere(); // removed to avoid cyclic dependency
  2564. }
  2565. this.getCenter( target.center );
  2566. target.radius = this.getSize( _vector$1 ).length() * 0.5;
  2567. return target;
  2568. }
  2569. intersect( box ) {
  2570. this.min.max( box.min );
  2571. this.max.min( box.max );
  2572. // 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.
  2573. if ( this.isEmpty() ) this.makeEmpty();
  2574. return this;
  2575. }
  2576. union( box ) {
  2577. this.min.min( box.min );
  2578. this.max.max( box.max );
  2579. return this;
  2580. }
  2581. applyMatrix4( matrix ) {
  2582. // transform of empty box is an empty box.
  2583. if ( this.isEmpty() ) return this;
  2584. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2585. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2586. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2587. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2588. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2589. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2590. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2591. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2592. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2593. this.setFromPoints( _points );
  2594. return this;
  2595. }
  2596. translate( offset ) {
  2597. this.min.add( offset );
  2598. this.max.add( offset );
  2599. return this;
  2600. }
  2601. equals( box ) {
  2602. return box.min.equals( this.min ) && box.max.equals( this.max );
  2603. }
  2604. }
  2605. function satForAxes( axes, v0, v1, v2, extents ) {
  2606. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  2607. _testAxis.fromArray( axes, i );
  2608. // project the aabb onto the seperating axis
  2609. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  2610. // project all 3 vertices of the triangle onto the seperating axis
  2611. const p0 = v0.dot( _testAxis );
  2612. const p1 = v1.dot( _testAxis );
  2613. const p2 = v2.dot( _testAxis );
  2614. // actual test, basically see if either of the most extreme of the triangle points intersects r
  2615. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  2616. // points of the projected triangle are outside the projected half-length of the aabb
  2617. // the axis is seperating and we can exit
  2618. return false;
  2619. }
  2620. }
  2621. return true;
  2622. }
  2623. const _points = [
  2624. /*@__PURE__*/ new Vector3(),
  2625. /*@__PURE__*/ new Vector3(),
  2626. /*@__PURE__*/ new Vector3(),
  2627. /*@__PURE__*/ new Vector3(),
  2628. /*@__PURE__*/ new Vector3(),
  2629. /*@__PURE__*/ new Vector3(),
  2630. /*@__PURE__*/ new Vector3(),
  2631. /*@__PURE__*/ new Vector3()
  2632. ];
  2633. const _vector$1 = /*@__PURE__*/ new Vector3();
  2634. const _box = /*@__PURE__*/ new Box3();
  2635. // triangle centered vertices
  2636. const _v0 = /*@__PURE__*/ new Vector3();
  2637. const _v1 = /*@__PURE__*/ new Vector3();
  2638. const _v2 = /*@__PURE__*/ new Vector3();
  2639. // triangle edge vectors
  2640. const _f0 = /*@__PURE__*/ new Vector3();
  2641. const _f1 = /*@__PURE__*/ new Vector3();
  2642. const _f2 = /*@__PURE__*/ new Vector3();
  2643. const _center = /*@__PURE__*/ new Vector3();
  2644. const _extents = /*@__PURE__*/ new Vector3();
  2645. const _triangleNormal = /*@__PURE__*/ new Vector3();
  2646. const _testAxis = /*@__PURE__*/ new Vector3();
  2647. const _box$1 = /*@__PURE__*/ new Box3();
  2648. class Sphere {
  2649. constructor( center, radius ) {
  2650. this.center = ( center !== undefined ) ? center : new Vector3();
  2651. this.radius = ( radius !== undefined ) ? radius : - 1;
  2652. }
  2653. set( center, radius ) {
  2654. this.center.copy( center );
  2655. this.radius = radius;
  2656. return this;
  2657. }
  2658. setFromPoints( points, optionalCenter ) {
  2659. const center = this.center;
  2660. if ( optionalCenter !== undefined ) {
  2661. center.copy( optionalCenter );
  2662. } else {
  2663. _box$1.setFromPoints( points ).getCenter( center );
  2664. }
  2665. let maxRadiusSq = 0;
  2666. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2667. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  2668. }
  2669. this.radius = Math.sqrt( maxRadiusSq );
  2670. return this;
  2671. }
  2672. clone() {
  2673. return new this.constructor().copy( this );
  2674. }
  2675. copy( sphere ) {
  2676. this.center.copy( sphere.center );
  2677. this.radius = sphere.radius;
  2678. return this;
  2679. }
  2680. isEmpty() {
  2681. return ( this.radius < 0 );
  2682. }
  2683. makeEmpty() {
  2684. this.center.set( 0, 0, 0 );
  2685. this.radius = - 1;
  2686. return this;
  2687. }
  2688. containsPoint( point ) {
  2689. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  2690. }
  2691. distanceToPoint( point ) {
  2692. return ( point.distanceTo( this.center ) - this.radius );
  2693. }
  2694. intersectsSphere( sphere ) {
  2695. const radiusSum = this.radius + sphere.radius;
  2696. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  2697. }
  2698. intersectsBox( box ) {
  2699. return box.intersectsSphere( this );
  2700. }
  2701. intersectsPlane( plane ) {
  2702. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  2703. }
  2704. clampPoint( point, target ) {
  2705. const deltaLengthSq = this.center.distanceToSquared( point );
  2706. if ( target === undefined ) {
  2707. console.warn( 'THREE.Sphere: .clampPoint() target is now required' );
  2708. target = new Vector3();
  2709. }
  2710. target.copy( point );
  2711. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  2712. target.sub( this.center ).normalize();
  2713. target.multiplyScalar( this.radius ).add( this.center );
  2714. }
  2715. return target;
  2716. }
  2717. getBoundingBox( target ) {
  2718. if ( target === undefined ) {
  2719. console.warn( 'THREE.Sphere: .getBoundingBox() target is now required' );
  2720. target = new Box3();
  2721. }
  2722. if ( this.isEmpty() ) {
  2723. // Empty sphere produces empty bounding box
  2724. target.makeEmpty();
  2725. return target;
  2726. }
  2727. target.set( this.center, this.center );
  2728. target.expandByScalar( this.radius );
  2729. return target;
  2730. }
  2731. applyMatrix4( matrix ) {
  2732. this.center.applyMatrix4( matrix );
  2733. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  2734. return this;
  2735. }
  2736. translate( offset ) {
  2737. this.center.add( offset );
  2738. return this;
  2739. }
  2740. equals( sphere ) {
  2741. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  2742. }
  2743. }
  2744. const _vector$2 = /*@__PURE__*/ new Vector3();
  2745. const _segCenter = /*@__PURE__*/ new Vector3();
  2746. const _segDir = /*@__PURE__*/ new Vector3();
  2747. const _diff = /*@__PURE__*/ new Vector3();
  2748. const _edge1 = /*@__PURE__*/ new Vector3();
  2749. const _edge2 = /*@__PURE__*/ new Vector3();
  2750. const _normal = /*@__PURE__*/ new Vector3();
  2751. class Ray {
  2752. constructor( origin, direction ) {
  2753. this.origin = ( origin !== undefined ) ? origin : new Vector3();
  2754. this.direction = ( direction !== undefined ) ? direction : new Vector3( 0, 0, - 1 );
  2755. }
  2756. set( origin, direction ) {
  2757. this.origin.copy( origin );
  2758. this.direction.copy( direction );
  2759. return this;
  2760. }
  2761. clone() {
  2762. return new this.constructor().copy( this );
  2763. }
  2764. copy( ray ) {
  2765. this.origin.copy( ray.origin );
  2766. this.direction.copy( ray.direction );
  2767. return this;
  2768. }
  2769. at( t, target ) {
  2770. if ( target === undefined ) {
  2771. console.warn( 'THREE.Ray: .at() target is now required' );
  2772. target = new Vector3();
  2773. }
  2774. return target.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  2775. }
  2776. lookAt( v ) {
  2777. this.direction.copy( v ).sub( this.origin ).normalize();
  2778. return this;
  2779. }
  2780. recast( t ) {
  2781. this.origin.copy( this.at( t, _vector$2 ) );
  2782. return this;
  2783. }
  2784. closestPointToPoint( point, target ) {
  2785. if ( target === undefined ) {
  2786. console.warn( 'THREE.Ray: .closestPointToPoint() target is now required' );
  2787. target = new Vector3();
  2788. }
  2789. target.subVectors( point, this.origin );
  2790. const directionDistance = target.dot( this.direction );
  2791. if ( directionDistance < 0 ) {
  2792. return target.copy( this.origin );
  2793. }
  2794. return target.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2795. }
  2796. distanceToPoint( point ) {
  2797. return Math.sqrt( this.distanceSqToPoint( point ) );
  2798. }
  2799. distanceSqToPoint( point ) {
  2800. const directionDistance = _vector$2.subVectors( point, this.origin ).dot( this.direction );
  2801. // point behind the ray
  2802. if ( directionDistance < 0 ) {
  2803. return this.origin.distanceToSquared( point );
  2804. }
  2805. _vector$2.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  2806. return _vector$2.distanceToSquared( point );
  2807. }
  2808. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  2809. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteDistRaySegment.h
  2810. // It returns the min distance between the ray and the segment
  2811. // defined by v0 and v1
  2812. // It can also set two optional targets :
  2813. // - The closest point on the ray
  2814. // - The closest point on the segment
  2815. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  2816. _segDir.copy( v1 ).sub( v0 ).normalize();
  2817. _diff.copy( this.origin ).sub( _segCenter );
  2818. const segExtent = v0.distanceTo( v1 ) * 0.5;
  2819. const a01 = - this.direction.dot( _segDir );
  2820. const b0 = _diff.dot( this.direction );
  2821. const b1 = - _diff.dot( _segDir );
  2822. const c = _diff.lengthSq();
  2823. const det = Math.abs( 1 - a01 * a01 );
  2824. let s0, s1, sqrDist, extDet;
  2825. if ( det > 0 ) {
  2826. // The ray and segment are not parallel.
  2827. s0 = a01 * b1 - b0;
  2828. s1 = a01 * b0 - b1;
  2829. extDet = segExtent * det;
  2830. if ( s0 >= 0 ) {
  2831. if ( s1 >= - extDet ) {
  2832. if ( s1 <= extDet ) {
  2833. // region 0
  2834. // Minimum at interior points of ray and segment.
  2835. const invDet = 1 / det;
  2836. s0 *= invDet;
  2837. s1 *= invDet;
  2838. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  2839. } else {
  2840. // region 1
  2841. s1 = segExtent;
  2842. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2843. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2844. }
  2845. } else {
  2846. // region 5
  2847. s1 = - segExtent;
  2848. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2849. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2850. }
  2851. } else {
  2852. if ( s1 <= - extDet ) {
  2853. // region 4
  2854. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  2855. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2856. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2857. } else if ( s1 <= extDet ) {
  2858. // region 3
  2859. s0 = 0;
  2860. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2861. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  2862. } else {
  2863. // region 2
  2864. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  2865. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  2866. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2867. }
  2868. }
  2869. } else {
  2870. // Ray and segment are parallel.
  2871. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  2872. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  2873. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  2874. }
  2875. if ( optionalPointOnRay ) {
  2876. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  2877. }
  2878. if ( optionalPointOnSegment ) {
  2879. optionalPointOnSegment.copy( _segDir ).multiplyScalar( s1 ).add( _segCenter );
  2880. }
  2881. return sqrDist;
  2882. }
  2883. intersectSphere( sphere, target ) {
  2884. _vector$2.subVectors( sphere.center, this.origin );
  2885. const tca = _vector$2.dot( this.direction );
  2886. const d2 = _vector$2.dot( _vector$2 ) - tca * tca;
  2887. const radius2 = sphere.radius * sphere.radius;
  2888. if ( d2 > radius2 ) return null;
  2889. const thc = Math.sqrt( radius2 - d2 );
  2890. // t0 = first intersect point - entrance on front of sphere
  2891. const t0 = tca - thc;
  2892. // t1 = second intersect point - exit point on back of sphere
  2893. const t1 = tca + thc;
  2894. // test to see if both t0 and t1 are behind the ray - if so, return null
  2895. if ( t0 < 0 && t1 < 0 ) return null;
  2896. // test to see if t0 is behind the ray:
  2897. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  2898. // in order to always return an intersect point that is in front of the ray.
  2899. if ( t0 < 0 ) return this.at( t1, target );
  2900. // else t0 is in front of the ray, so return the first collision point scaled by t0
  2901. return this.at( t0, target );
  2902. }
  2903. intersectsSphere( sphere ) {
  2904. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  2905. }
  2906. distanceToPlane( plane ) {
  2907. const denominator = plane.normal.dot( this.direction );
  2908. if ( denominator === 0 ) {
  2909. // line is coplanar, return origin
  2910. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  2911. return 0;
  2912. }
  2913. // Null is preferable to undefined since undefined means.... it is undefined
  2914. return null;
  2915. }
  2916. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  2917. // Return if the ray never intersects the plane
  2918. return t >= 0 ? t : null;
  2919. }
  2920. intersectPlane( plane, target ) {
  2921. const t = this.distanceToPlane( plane );
  2922. if ( t === null ) {
  2923. return null;
  2924. }
  2925. return this.at( t, target );
  2926. }
  2927. intersectsPlane( plane ) {
  2928. // check if the ray lies on the plane first
  2929. const distToPoint = plane.distanceToPoint( this.origin );
  2930. if ( distToPoint === 0 ) {
  2931. return true;
  2932. }
  2933. const denominator = plane.normal.dot( this.direction );
  2934. if ( denominator * distToPoint < 0 ) {
  2935. return true;
  2936. }
  2937. // ray origin is behind the plane (and is pointing behind it)
  2938. return false;
  2939. }
  2940. intersectBox( box, target ) {
  2941. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  2942. const invdirx = 1 / this.direction.x,
  2943. invdiry = 1 / this.direction.y,
  2944. invdirz = 1 / this.direction.z;
  2945. const origin = this.origin;
  2946. if ( invdirx >= 0 ) {
  2947. tmin = ( box.min.x - origin.x ) * invdirx;
  2948. tmax = ( box.max.x - origin.x ) * invdirx;
  2949. } else {
  2950. tmin = ( box.max.x - origin.x ) * invdirx;
  2951. tmax = ( box.min.x - origin.x ) * invdirx;
  2952. }
  2953. if ( invdiry >= 0 ) {
  2954. tymin = ( box.min.y - origin.y ) * invdiry;
  2955. tymax = ( box.max.y - origin.y ) * invdiry;
  2956. } else {
  2957. tymin = ( box.max.y - origin.y ) * invdiry;
  2958. tymax = ( box.min.y - origin.y ) * invdiry;
  2959. }
  2960. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  2961. // These lines also handle the case where tmin or tmax is NaN
  2962. // (result of 0 * Infinity). x !== x returns true if x is NaN
  2963. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  2964. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  2965. if ( invdirz >= 0 ) {
  2966. tzmin = ( box.min.z - origin.z ) * invdirz;
  2967. tzmax = ( box.max.z - origin.z ) * invdirz;
  2968. } else {
  2969. tzmin = ( box.max.z - origin.z ) * invdirz;
  2970. tzmax = ( box.min.z - origin.z ) * invdirz;
  2971. }
  2972. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  2973. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  2974. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  2975. //return point closest to the ray (positive side)
  2976. if ( tmax < 0 ) return null;
  2977. return this.at( tmin >= 0 ? tmin : tmax, target );
  2978. }
  2979. intersectsBox( box ) {
  2980. return this.intersectBox( box, _vector$2 ) !== null;
  2981. }
  2982. intersectTriangle( a, b, c, backfaceCulling, target ) {
  2983. // Compute the offset origin, edges, and normal.
  2984. // from http://www.geometrictools.com/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  2985. _edge1.subVectors( b, a );
  2986. _edge2.subVectors( c, a );
  2987. _normal.crossVectors( _edge1, _edge2 );
  2988. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  2989. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  2990. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  2991. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  2992. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  2993. let DdN = this.direction.dot( _normal );
  2994. let sign;
  2995. if ( DdN > 0 ) {
  2996. if ( backfaceCulling ) return null;
  2997. sign = 1;
  2998. } else if ( DdN < 0 ) {
  2999. sign = - 1;
  3000. DdN = - DdN;
  3001. } else {
  3002. return null;
  3003. }
  3004. _diff.subVectors( this.origin, a );
  3005. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3006. // b1 < 0, no intersection
  3007. if ( DdQxE2 < 0 ) {
  3008. return null;
  3009. }
  3010. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3011. // b2 < 0, no intersection
  3012. if ( DdE1xQ < 0 ) {
  3013. return null;
  3014. }
  3015. // b1+b2 > 1, no intersection
  3016. if ( DdQxE2 + DdE1xQ > DdN ) {
  3017. return null;
  3018. }
  3019. // Line intersects triangle, check if ray does.
  3020. const QdN = - sign * _diff.dot( _normal );
  3021. // t < 0, no intersection
  3022. if ( QdN < 0 ) {
  3023. return null;
  3024. }
  3025. // Ray intersects triangle.
  3026. return this.at( QdN / DdN, target );
  3027. }
  3028. applyMatrix4( matrix4 ) {
  3029. this.origin.applyMatrix4( matrix4 );
  3030. this.direction.transformDirection( matrix4 );
  3031. return this;
  3032. }
  3033. equals( ray ) {
  3034. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3035. }
  3036. }
  3037. class Matrix4 {
  3038. constructor() {
  3039. Object.defineProperty( this, 'isMatrix4', { value: true } );
  3040. this.elements = [
  3041. 1, 0, 0, 0,
  3042. 0, 1, 0, 0,
  3043. 0, 0, 1, 0,
  3044. 0, 0, 0, 1
  3045. ];
  3046. if ( arguments.length > 0 ) {
  3047. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  3048. }
  3049. }
  3050. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3051. const te = this.elements;
  3052. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3053. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3054. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3055. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3056. return this;
  3057. }
  3058. identity() {
  3059. this.set(
  3060. 1, 0, 0, 0,
  3061. 0, 1, 0, 0,
  3062. 0, 0, 1, 0,
  3063. 0, 0, 0, 1
  3064. );
  3065. return this;
  3066. }
  3067. clone() {
  3068. return new Matrix4().fromArray( this.elements );
  3069. }
  3070. copy( m ) {
  3071. const te = this.elements;
  3072. const me = m.elements;
  3073. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3074. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3075. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3076. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3077. return this;
  3078. }
  3079. copyPosition( m ) {
  3080. const te = this.elements, me = m.elements;
  3081. te[ 12 ] = me[ 12 ];
  3082. te[ 13 ] = me[ 13 ];
  3083. te[ 14 ] = me[ 14 ];
  3084. return this;
  3085. }
  3086. extractBasis( xAxis, yAxis, zAxis ) {
  3087. xAxis.setFromMatrixColumn( this, 0 );
  3088. yAxis.setFromMatrixColumn( this, 1 );
  3089. zAxis.setFromMatrixColumn( this, 2 );
  3090. return this;
  3091. }
  3092. makeBasis( xAxis, yAxis, zAxis ) {
  3093. this.set(
  3094. xAxis.x, yAxis.x, zAxis.x, 0,
  3095. xAxis.y, yAxis.y, zAxis.y, 0,
  3096. xAxis.z, yAxis.z, zAxis.z, 0,
  3097. 0, 0, 0, 1
  3098. );
  3099. return this;
  3100. }
  3101. extractRotation( m ) {
  3102. // this method does not support reflection matrices
  3103. const te = this.elements;
  3104. const me = m.elements;
  3105. const scaleX = 1 / _v1$1.setFromMatrixColumn( m, 0 ).length();
  3106. const scaleY = 1 / _v1$1.setFromMatrixColumn( m, 1 ).length();
  3107. const scaleZ = 1 / _v1$1.setFromMatrixColumn( m, 2 ).length();
  3108. te[ 0 ] = me[ 0 ] * scaleX;
  3109. te[ 1 ] = me[ 1 ] * scaleX;
  3110. te[ 2 ] = me[ 2 ] * scaleX;
  3111. te[ 3 ] = 0;
  3112. te[ 4 ] = me[ 4 ] * scaleY;
  3113. te[ 5 ] = me[ 5 ] * scaleY;
  3114. te[ 6 ] = me[ 6 ] * scaleY;
  3115. te[ 7 ] = 0;
  3116. te[ 8 ] = me[ 8 ] * scaleZ;
  3117. te[ 9 ] = me[ 9 ] * scaleZ;
  3118. te[ 10 ] = me[ 10 ] * scaleZ;
  3119. te[ 11 ] = 0;
  3120. te[ 12 ] = 0;
  3121. te[ 13 ] = 0;
  3122. te[ 14 ] = 0;
  3123. te[ 15 ] = 1;
  3124. return this;
  3125. }
  3126. makeRotationFromEuler( euler ) {
  3127. if ( ! ( euler && euler.isEuler ) ) {
  3128. console.error( 'THREE.Matrix4: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  3129. }
  3130. const te = this.elements;
  3131. const x = euler.x, y = euler.y, z = euler.z;
  3132. const a = Math.cos( x ), b = Math.sin( x );
  3133. const c = Math.cos( y ), d = Math.sin( y );
  3134. const e = Math.cos( z ), f = Math.sin( z );
  3135. if ( euler.order === 'XYZ' ) {
  3136. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3137. te[ 0 ] = c * e;
  3138. te[ 4 ] = - c * f;
  3139. te[ 8 ] = d;
  3140. te[ 1 ] = af + be * d;
  3141. te[ 5 ] = ae - bf * d;
  3142. te[ 9 ] = - b * c;
  3143. te[ 2 ] = bf - ae * d;
  3144. te[ 6 ] = be + af * d;
  3145. te[ 10 ] = a * c;
  3146. } else if ( euler.order === 'YXZ' ) {
  3147. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3148. te[ 0 ] = ce + df * b;
  3149. te[ 4 ] = de * b - cf;
  3150. te[ 8 ] = a * d;
  3151. te[ 1 ] = a * f;
  3152. te[ 5 ] = a * e;
  3153. te[ 9 ] = - b;
  3154. te[ 2 ] = cf * b - de;
  3155. te[ 6 ] = df + ce * b;
  3156. te[ 10 ] = a * c;
  3157. } else if ( euler.order === 'ZXY' ) {
  3158. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3159. te[ 0 ] = ce - df * b;
  3160. te[ 4 ] = - a * f;
  3161. te[ 8 ] = de + cf * b;
  3162. te[ 1 ] = cf + de * b;
  3163. te[ 5 ] = a * e;
  3164. te[ 9 ] = df - ce * b;
  3165. te[ 2 ] = - a * d;
  3166. te[ 6 ] = b;
  3167. te[ 10 ] = a * c;
  3168. } else if ( euler.order === 'ZYX' ) {
  3169. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3170. te[ 0 ] = c * e;
  3171. te[ 4 ] = be * d - af;
  3172. te[ 8 ] = ae * d + bf;
  3173. te[ 1 ] = c * f;
  3174. te[ 5 ] = bf * d + ae;
  3175. te[ 9 ] = af * d - be;
  3176. te[ 2 ] = - d;
  3177. te[ 6 ] = b * c;
  3178. te[ 10 ] = a * c;
  3179. } else if ( euler.order === 'YZX' ) {
  3180. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3181. te[ 0 ] = c * e;
  3182. te[ 4 ] = bd - ac * f;
  3183. te[ 8 ] = bc * f + ad;
  3184. te[ 1 ] = f;
  3185. te[ 5 ] = a * e;
  3186. te[ 9 ] = - b * e;
  3187. te[ 2 ] = - d * e;
  3188. te[ 6 ] = ad * f + bc;
  3189. te[ 10 ] = ac - bd * f;
  3190. } else if ( euler.order === 'XZY' ) {
  3191. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3192. te[ 0 ] = c * e;
  3193. te[ 4 ] = - f;
  3194. te[ 8 ] = d * e;
  3195. te[ 1 ] = ac * f + bd;
  3196. te[ 5 ] = a * e;
  3197. te[ 9 ] = ad * f - bc;
  3198. te[ 2 ] = bc * f - ad;
  3199. te[ 6 ] = b * e;
  3200. te[ 10 ] = bd * f + ac;
  3201. }
  3202. // bottom row
  3203. te[ 3 ] = 0;
  3204. te[ 7 ] = 0;
  3205. te[ 11 ] = 0;
  3206. // last column
  3207. te[ 12 ] = 0;
  3208. te[ 13 ] = 0;
  3209. te[ 14 ] = 0;
  3210. te[ 15 ] = 1;
  3211. return this;
  3212. }
  3213. makeRotationFromQuaternion( q ) {
  3214. return this.compose( _zero, q, _one );
  3215. }
  3216. lookAt( eye, target, up ) {
  3217. const te = this.elements;
  3218. _z.subVectors( eye, target );
  3219. if ( _z.lengthSq() === 0 ) {
  3220. // eye and target are in the same position
  3221. _z.z = 1;
  3222. }
  3223. _z.normalize();
  3224. _x.crossVectors( up, _z );
  3225. if ( _x.lengthSq() === 0 ) {
  3226. // up and z are parallel
  3227. if ( Math.abs( up.z ) === 1 ) {
  3228. _z.x += 0.0001;
  3229. } else {
  3230. _z.z += 0.0001;
  3231. }
  3232. _z.normalize();
  3233. _x.crossVectors( up, _z );
  3234. }
  3235. _x.normalize();
  3236. _y.crossVectors( _z, _x );
  3237. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3238. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3239. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3240. return this;
  3241. }
  3242. multiply( m, n ) {
  3243. if ( n !== undefined ) {
  3244. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3245. return this.multiplyMatrices( m, n );
  3246. }
  3247. return this.multiplyMatrices( this, m );
  3248. }
  3249. premultiply( m ) {
  3250. return this.multiplyMatrices( m, this );
  3251. }
  3252. multiplyMatrices( a, b ) {
  3253. const ae = a.elements;
  3254. const be = b.elements;
  3255. const te = this.elements;
  3256. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3257. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3258. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3259. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3260. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3261. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3262. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3263. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3264. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3265. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3266. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3267. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3268. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3269. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3270. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3271. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3272. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3273. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3274. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3275. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3276. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3277. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3278. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3279. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3280. return this;
  3281. }
  3282. multiplyScalar( s ) {
  3283. const te = this.elements;
  3284. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3285. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3286. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3287. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3288. return this;
  3289. }
  3290. determinant() {
  3291. const te = this.elements;
  3292. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3293. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3294. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3295. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3296. //TODO: make this more efficient
  3297. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3298. return (
  3299. n41 * (
  3300. + n14 * n23 * n32
  3301. - n13 * n24 * n32
  3302. - n14 * n22 * n33
  3303. + n12 * n24 * n33
  3304. + n13 * n22 * n34
  3305. - n12 * n23 * n34
  3306. ) +
  3307. n42 * (
  3308. + n11 * n23 * n34
  3309. - n11 * n24 * n33
  3310. + n14 * n21 * n33
  3311. - n13 * n21 * n34
  3312. + n13 * n24 * n31
  3313. - n14 * n23 * n31
  3314. ) +
  3315. n43 * (
  3316. + n11 * n24 * n32
  3317. - n11 * n22 * n34
  3318. - n14 * n21 * n32
  3319. + n12 * n21 * n34
  3320. + n14 * n22 * n31
  3321. - n12 * n24 * n31
  3322. ) +
  3323. n44 * (
  3324. - n13 * n22 * n31
  3325. - n11 * n23 * n32
  3326. + n11 * n22 * n33
  3327. + n13 * n21 * n32
  3328. - n12 * n21 * n33
  3329. + n12 * n23 * n31
  3330. )
  3331. );
  3332. }
  3333. transpose() {
  3334. const te = this.elements;
  3335. let tmp;
  3336. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3337. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3338. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3339. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3340. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3341. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3342. return this;
  3343. }
  3344. setPosition( x, y, z ) {
  3345. const te = this.elements;
  3346. if ( x.isVector3 ) {
  3347. te[ 12 ] = x.x;
  3348. te[ 13 ] = x.y;
  3349. te[ 14 ] = x.z;
  3350. } else {
  3351. te[ 12 ] = x;
  3352. te[ 13 ] = y;
  3353. te[ 14 ] = z;
  3354. }
  3355. return this;
  3356. }
  3357. invert() {
  3358. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3359. const te = this.elements,
  3360. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3361. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3362. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3363. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3364. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3365. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3366. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3367. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3368. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3369. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3370. const detInv = 1 / det;
  3371. te[ 0 ] = t11 * detInv;
  3372. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3373. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3374. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3375. te[ 4 ] = t12 * detInv;
  3376. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3377. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3378. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3379. te[ 8 ] = t13 * detInv;
  3380. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3381. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3382. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3383. te[ 12 ] = t14 * detInv;
  3384. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3385. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3386. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3387. return this;
  3388. }
  3389. scale( v ) {
  3390. const te = this.elements;
  3391. const x = v.x, y = v.y, z = v.z;
  3392. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3393. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3394. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3395. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3396. return this;
  3397. }
  3398. getMaxScaleOnAxis() {
  3399. const te = this.elements;
  3400. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3401. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3402. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3403. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3404. }
  3405. makeTranslation( x, y, z ) {
  3406. this.set(
  3407. 1, 0, 0, x,
  3408. 0, 1, 0, y,
  3409. 0, 0, 1, z,
  3410. 0, 0, 0, 1
  3411. );
  3412. return this;
  3413. }
  3414. makeRotationX( theta ) {
  3415. const c = Math.cos( theta ), s = Math.sin( theta );
  3416. this.set(
  3417. 1, 0, 0, 0,
  3418. 0, c, - s, 0,
  3419. 0, s, c, 0,
  3420. 0, 0, 0, 1
  3421. );
  3422. return this;
  3423. }
  3424. makeRotationY( theta ) {
  3425. const c = Math.cos( theta ), s = Math.sin( theta );
  3426. this.set(
  3427. c, 0, s, 0,
  3428. 0, 1, 0, 0,
  3429. - s, 0, c, 0,
  3430. 0, 0, 0, 1
  3431. );
  3432. return this;
  3433. }
  3434. makeRotationZ( theta ) {
  3435. const c = Math.cos( theta ), s = Math.sin( theta );
  3436. this.set(
  3437. c, - s, 0, 0,
  3438. s, c, 0, 0,
  3439. 0, 0, 1, 0,
  3440. 0, 0, 0, 1
  3441. );
  3442. return this;
  3443. }
  3444. makeRotationAxis( axis, angle ) {
  3445. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3446. const c = Math.cos( angle );
  3447. const s = Math.sin( angle );
  3448. const t = 1 - c;
  3449. const x = axis.x, y = axis.y, z = axis.z;
  3450. const tx = t * x, ty = t * y;
  3451. this.set(
  3452. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3453. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3454. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3455. 0, 0, 0, 1
  3456. );
  3457. return this;
  3458. }
  3459. makeScale( x, y, z ) {
  3460. this.set(
  3461. x, 0, 0, 0,
  3462. 0, y, 0, 0,
  3463. 0, 0, z, 0,
  3464. 0, 0, 0, 1
  3465. );
  3466. return this;
  3467. }
  3468. makeShear( x, y, z ) {
  3469. this.set(
  3470. 1, y, z, 0,
  3471. x, 1, z, 0,
  3472. x, y, 1, 0,
  3473. 0, 0, 0, 1
  3474. );
  3475. return this;
  3476. }
  3477. compose( position, quaternion, scale ) {
  3478. const te = this.elements;
  3479. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  3480. const x2 = x + x, y2 = y + y, z2 = z + z;
  3481. const xx = x * x2, xy = x * y2, xz = x * z2;
  3482. const yy = y * y2, yz = y * z2, zz = z * z2;
  3483. const wx = w * x2, wy = w * y2, wz = w * z2;
  3484. const sx = scale.x, sy = scale.y, sz = scale.z;
  3485. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  3486. te[ 1 ] = ( xy + wz ) * sx;
  3487. te[ 2 ] = ( xz - wy ) * sx;
  3488. te[ 3 ] = 0;
  3489. te[ 4 ] = ( xy - wz ) * sy;
  3490. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  3491. te[ 6 ] = ( yz + wx ) * sy;
  3492. te[ 7 ] = 0;
  3493. te[ 8 ] = ( xz + wy ) * sz;
  3494. te[ 9 ] = ( yz - wx ) * sz;
  3495. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  3496. te[ 11 ] = 0;
  3497. te[ 12 ] = position.x;
  3498. te[ 13 ] = position.y;
  3499. te[ 14 ] = position.z;
  3500. te[ 15 ] = 1;
  3501. return this;
  3502. }
  3503. decompose( position, quaternion, scale ) {
  3504. const te = this.elements;
  3505. let sx = _v1$1.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3506. const sy = _v1$1.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3507. const sz = _v1$1.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3508. // if determine is negative, we need to invert one scale
  3509. const det = this.determinant();
  3510. if ( det < 0 ) sx = - sx;
  3511. position.x = te[ 12 ];
  3512. position.y = te[ 13 ];
  3513. position.z = te[ 14 ];
  3514. // scale the rotation part
  3515. _m1.copy( this );
  3516. const invSX = 1 / sx;
  3517. const invSY = 1 / sy;
  3518. const invSZ = 1 / sz;
  3519. _m1.elements[ 0 ] *= invSX;
  3520. _m1.elements[ 1 ] *= invSX;
  3521. _m1.elements[ 2 ] *= invSX;
  3522. _m1.elements[ 4 ] *= invSY;
  3523. _m1.elements[ 5 ] *= invSY;
  3524. _m1.elements[ 6 ] *= invSY;
  3525. _m1.elements[ 8 ] *= invSZ;
  3526. _m1.elements[ 9 ] *= invSZ;
  3527. _m1.elements[ 10 ] *= invSZ;
  3528. quaternion.setFromRotationMatrix( _m1 );
  3529. scale.x = sx;
  3530. scale.y = sy;
  3531. scale.z = sz;
  3532. return this;
  3533. }
  3534. makePerspective( left, right, top, bottom, near, far ) {
  3535. if ( far === undefined ) {
  3536. console.warn( 'THREE.Matrix4: .makePerspective() has been redefined and has a new signature. Please check the docs.' );
  3537. }
  3538. const te = this.elements;
  3539. const x = 2 * near / ( right - left );
  3540. const y = 2 * near / ( top - bottom );
  3541. const a = ( right + left ) / ( right - left );
  3542. const b = ( top + bottom ) / ( top - bottom );
  3543. const c = - ( far + near ) / ( far - near );
  3544. const d = - 2 * far * near / ( far - near );
  3545. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3546. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3547. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3548. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3549. return this;
  3550. }
  3551. makeOrthographic( left, right, top, bottom, near, far ) {
  3552. const te = this.elements;
  3553. const w = 1.0 / ( right - left );
  3554. const h = 1.0 / ( top - bottom );
  3555. const p = 1.0 / ( far - near );
  3556. const x = ( right + left ) * w;
  3557. const y = ( top + bottom ) * h;
  3558. const z = ( far + near ) * p;
  3559. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3560. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  3561. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 * p; te[ 14 ] = - z;
  3562. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3563. return this;
  3564. }
  3565. equals( matrix ) {
  3566. const te = this.elements;
  3567. const me = matrix.elements;
  3568. for ( let i = 0; i < 16; i ++ ) {
  3569. if ( te[ i ] !== me[ i ] ) return false;
  3570. }
  3571. return true;
  3572. }
  3573. fromArray( array, offset = 0 ) {
  3574. for ( let i = 0; i < 16; i ++ ) {
  3575. this.elements[ i ] = array[ i + offset ];
  3576. }
  3577. return this;
  3578. }
  3579. toArray( array = [], offset = 0 ) {
  3580. const te = this.elements;
  3581. array[ offset ] = te[ 0 ];
  3582. array[ offset + 1 ] = te[ 1 ];
  3583. array[ offset + 2 ] = te[ 2 ];
  3584. array[ offset + 3 ] = te[ 3 ];
  3585. array[ offset + 4 ] = te[ 4 ];
  3586. array[ offset + 5 ] = te[ 5 ];
  3587. array[ offset + 6 ] = te[ 6 ];
  3588. array[ offset + 7 ] = te[ 7 ];
  3589. array[ offset + 8 ] = te[ 8 ];
  3590. array[ offset + 9 ] = te[ 9 ];
  3591. array[ offset + 10 ] = te[ 10 ];
  3592. array[ offset + 11 ] = te[ 11 ];
  3593. array[ offset + 12 ] = te[ 12 ];
  3594. array[ offset + 13 ] = te[ 13 ];
  3595. array[ offset + 14 ] = te[ 14 ];
  3596. array[ offset + 15 ] = te[ 15 ];
  3597. return array;
  3598. }
  3599. }
  3600. const _v1$1 = /*@__PURE__*/ new Vector3();
  3601. const _m1 = /*@__PURE__*/ new Matrix4();
  3602. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  3603. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  3604. const _x = /*@__PURE__*/ new Vector3();
  3605. const _y = /*@__PURE__*/ new Vector3();
  3606. const _z = /*@__PURE__*/ new Vector3();
  3607. class Euler {
  3608. constructor( x = 0, y = 0, z = 0, order = Euler.DefaultOrder ) {
  3609. Object.defineProperty( this, 'isEuler', { value: true } );
  3610. this._x = x;
  3611. this._y = y;
  3612. this._z = z;
  3613. this._order = order;
  3614. }
  3615. get x() {
  3616. return this._x;
  3617. }
  3618. set x( value ) {
  3619. this._x = value;
  3620. this._onChangeCallback();
  3621. }
  3622. get y() {
  3623. return this._y;
  3624. }
  3625. set y( value ) {
  3626. this._y = value;
  3627. this._onChangeCallback();
  3628. }
  3629. get z() {
  3630. return this._z;
  3631. }
  3632. set z( value ) {
  3633. this._z = value;
  3634. this._onChangeCallback();
  3635. }
  3636. get order() {
  3637. return this._order;
  3638. }
  3639. set order( value ) {
  3640. this._order = value;
  3641. this._onChangeCallback();
  3642. }
  3643. set( x, y, z, order ) {
  3644. this._x = x;
  3645. this._y = y;
  3646. this._z = z;
  3647. this._order = order || this._order;
  3648. this._onChangeCallback();
  3649. return this;
  3650. }
  3651. clone() {
  3652. return new this.constructor( this._x, this._y, this._z, this._order );
  3653. }
  3654. copy( euler ) {
  3655. this._x = euler._x;
  3656. this._y = euler._y;
  3657. this._z = euler._z;
  3658. this._order = euler._order;
  3659. this._onChangeCallback();
  3660. return this;
  3661. }
  3662. setFromRotationMatrix( m, order, update ) {
  3663. const clamp = MathUtils.clamp;
  3664. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3665. const te = m.elements;
  3666. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  3667. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  3668. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  3669. order = order || this._order;
  3670. switch ( order ) {
  3671. case 'XYZ':
  3672. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  3673. if ( Math.abs( m13 ) < 0.9999999 ) {
  3674. this._x = Math.atan2( - m23, m33 );
  3675. this._z = Math.atan2( - m12, m11 );
  3676. } else {
  3677. this._x = Math.atan2( m32, m22 );
  3678. this._z = 0;
  3679. }
  3680. break;
  3681. case 'YXZ':
  3682. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  3683. if ( Math.abs( m23 ) < 0.9999999 ) {
  3684. this._y = Math.atan2( m13, m33 );
  3685. this._z = Math.atan2( m21, m22 );
  3686. } else {
  3687. this._y = Math.atan2( - m31, m11 );
  3688. this._z = 0;
  3689. }
  3690. break;
  3691. case 'ZXY':
  3692. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  3693. if ( Math.abs( m32 ) < 0.9999999 ) {
  3694. this._y = Math.atan2( - m31, m33 );
  3695. this._z = Math.atan2( - m12, m22 );
  3696. } else {
  3697. this._y = 0;
  3698. this._z = Math.atan2( m21, m11 );
  3699. }
  3700. break;
  3701. case 'ZYX':
  3702. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  3703. if ( Math.abs( m31 ) < 0.9999999 ) {
  3704. this._x = Math.atan2( m32, m33 );
  3705. this._z = Math.atan2( m21, m11 );
  3706. } else {
  3707. this._x = 0;
  3708. this._z = Math.atan2( - m12, m22 );
  3709. }
  3710. break;
  3711. case 'YZX':
  3712. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  3713. if ( Math.abs( m21 ) < 0.9999999 ) {
  3714. this._x = Math.atan2( - m23, m22 );
  3715. this._y = Math.atan2( - m31, m11 );
  3716. } else {
  3717. this._x = 0;
  3718. this._y = Math.atan2( m13, m33 );
  3719. }
  3720. break;
  3721. case 'XZY':
  3722. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  3723. if ( Math.abs( m12 ) < 0.9999999 ) {
  3724. this._x = Math.atan2( m32, m22 );
  3725. this._y = Math.atan2( m13, m11 );
  3726. } else {
  3727. this._x = Math.atan2( - m23, m33 );
  3728. this._y = 0;
  3729. }
  3730. break;
  3731. default:
  3732. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  3733. }
  3734. this._order = order;
  3735. if ( update !== false ) this._onChangeCallback();
  3736. return this;
  3737. }
  3738. setFromQuaternion( q, order, update ) {
  3739. _matrix.makeRotationFromQuaternion( q );
  3740. return this.setFromRotationMatrix( _matrix, order, update );
  3741. }
  3742. setFromVector3( v, order ) {
  3743. return this.set( v.x, v.y, v.z, order || this._order );
  3744. }
  3745. reorder( newOrder ) {
  3746. // WARNING: this discards revolution information -bhouston
  3747. _quaternion$1.setFromEuler( this );
  3748. return this.setFromQuaternion( _quaternion$1, newOrder );
  3749. }
  3750. equals( euler ) {
  3751. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  3752. }
  3753. fromArray( array ) {
  3754. this._x = array[ 0 ];
  3755. this._y = array[ 1 ];
  3756. this._z = array[ 2 ];
  3757. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  3758. this._onChangeCallback();
  3759. return this;
  3760. }
  3761. toArray( array = [], offset = 0 ) {
  3762. array[ offset ] = this._x;
  3763. array[ offset + 1 ] = this._y;
  3764. array[ offset + 2 ] = this._z;
  3765. array[ offset + 3 ] = this._order;
  3766. return array;
  3767. }
  3768. toVector3( optionalResult ) {
  3769. if ( optionalResult ) {
  3770. return optionalResult.set( this._x, this._y, this._z );
  3771. } else {
  3772. return new Vector3( this._x, this._y, this._z );
  3773. }
  3774. }
  3775. _onChange( callback ) {
  3776. this._onChangeCallback = callback;
  3777. return this;
  3778. }
  3779. _onChangeCallback() {}
  3780. }
  3781. Euler.DefaultOrder = 'XYZ';
  3782. Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  3783. const _matrix = /*@__PURE__*/ new Matrix4();
  3784. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  3785. class Layers {
  3786. constructor() {
  3787. this.mask = 1 | 0;
  3788. }
  3789. set( channel ) {
  3790. this.mask = 1 << channel | 0;
  3791. }
  3792. enable( channel ) {
  3793. this.mask |= 1 << channel | 0;
  3794. }
  3795. enableAll() {
  3796. this.mask = 0xffffffff | 0;
  3797. }
  3798. toggle( channel ) {
  3799. this.mask ^= 1 << channel | 0;
  3800. }
  3801. disable( channel ) {
  3802. this.mask &= ~ ( 1 << channel | 0 );
  3803. }
  3804. disableAll() {
  3805. this.mask = 0;
  3806. }
  3807. test( layers ) {
  3808. return ( this.mask & layers.mask ) !== 0;
  3809. }
  3810. }
  3811. let _object3DId = 0;
  3812. const _v1$2 = new Vector3();
  3813. const _q1 = new Quaternion();
  3814. const _m1$1 = new Matrix4();
  3815. const _target = new Vector3();
  3816. const _position = new Vector3();
  3817. const _scale = new Vector3();
  3818. const _quaternion$2 = new Quaternion();
  3819. const _xAxis = new Vector3( 1, 0, 0 );
  3820. const _yAxis = new Vector3( 0, 1, 0 );
  3821. const _zAxis = new Vector3( 0, 0, 1 );
  3822. const _addedEvent = { type: 'added' };
  3823. const _removedEvent = { type: 'removed' };
  3824. function Object3D() {
  3825. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  3826. this.uuid = MathUtils.generateUUID();
  3827. this.name = '';
  3828. this.type = 'Object3D';
  3829. this.parent = null;
  3830. this.children = [];
  3831. this.up = Object3D.DefaultUp.clone();
  3832. const position = new Vector3();
  3833. const rotation = new Euler();
  3834. const quaternion = new Quaternion();
  3835. const scale = new Vector3( 1, 1, 1 );
  3836. function onRotationChange() {
  3837. quaternion.setFromEuler( rotation, false );
  3838. }
  3839. function onQuaternionChange() {
  3840. rotation.setFromQuaternion( quaternion, undefined, false );
  3841. }
  3842. rotation._onChange( onRotationChange );
  3843. quaternion._onChange( onQuaternionChange );
  3844. Object.defineProperties( this, {
  3845. position: {
  3846. configurable: true,
  3847. enumerable: true,
  3848. value: position
  3849. },
  3850. rotation: {
  3851. configurable: true,
  3852. enumerable: true,
  3853. value: rotation
  3854. },
  3855. quaternion: {
  3856. configurable: true,
  3857. enumerable: true,
  3858. value: quaternion
  3859. },
  3860. scale: {
  3861. configurable: true,
  3862. enumerable: true,
  3863. value: scale
  3864. },
  3865. modelViewMatrix: {
  3866. value: new Matrix4()
  3867. },
  3868. normalMatrix: {
  3869. value: new Matrix3()
  3870. }
  3871. } );
  3872. this.matrix = new Matrix4();
  3873. this.matrixWorld = new Matrix4();
  3874. this.matrixAutoUpdate = Object3D.DefaultMatrixAutoUpdate;
  3875. this.matrixWorldNeedsUpdate = false;
  3876. this.layers = new Layers();
  3877. this.visible = true;
  3878. this.castShadow = false;
  3879. this.receiveShadow = false;
  3880. this.frustumCulled = true;
  3881. this.renderOrder = 0;
  3882. this.animations = [];
  3883. this.userData = {};
  3884. }
  3885. Object3D.DefaultUp = new Vector3( 0, 1, 0 );
  3886. Object3D.DefaultMatrixAutoUpdate = true;
  3887. Object3D.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  3888. constructor: Object3D,
  3889. isObject3D: true,
  3890. onBeforeRender: function () {},
  3891. onAfterRender: function () {},
  3892. applyMatrix4: function ( matrix ) {
  3893. if ( this.matrixAutoUpdate ) this.updateMatrix();
  3894. this.matrix.premultiply( matrix );
  3895. this.matrix.decompose( this.position, this.quaternion, this.scale );
  3896. },
  3897. applyQuaternion: function ( q ) {
  3898. this.quaternion.premultiply( q );
  3899. return this;
  3900. },
  3901. setRotationFromAxisAngle: function ( axis, angle ) {
  3902. // assumes axis is normalized
  3903. this.quaternion.setFromAxisAngle( axis, angle );
  3904. },
  3905. setRotationFromEuler: function ( euler ) {
  3906. this.quaternion.setFromEuler( euler, true );
  3907. },
  3908. setRotationFromMatrix: function ( m ) {
  3909. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  3910. this.quaternion.setFromRotationMatrix( m );
  3911. },
  3912. setRotationFromQuaternion: function ( q ) {
  3913. // assumes q is normalized
  3914. this.quaternion.copy( q );
  3915. },
  3916. rotateOnAxis: function ( axis, angle ) {
  3917. // rotate object on axis in object space
  3918. // axis is assumed to be normalized
  3919. _q1.setFromAxisAngle( axis, angle );
  3920. this.quaternion.multiply( _q1 );
  3921. return this;
  3922. },
  3923. rotateOnWorldAxis: function ( axis, angle ) {
  3924. // rotate object on axis in world space
  3925. // axis is assumed to be normalized
  3926. // method assumes no rotated parent
  3927. _q1.setFromAxisAngle( axis, angle );
  3928. this.quaternion.premultiply( _q1 );
  3929. return this;
  3930. },
  3931. rotateX: function ( angle ) {
  3932. return this.rotateOnAxis( _xAxis, angle );
  3933. },
  3934. rotateY: function ( angle ) {
  3935. return this.rotateOnAxis( _yAxis, angle );
  3936. },
  3937. rotateZ: function ( angle ) {
  3938. return this.rotateOnAxis( _zAxis, angle );
  3939. },
  3940. translateOnAxis: function ( axis, distance ) {
  3941. // translate object by distance along axis in object space
  3942. // axis is assumed to be normalized
  3943. _v1$2.copy( axis ).applyQuaternion( this.quaternion );
  3944. this.position.add( _v1$2.multiplyScalar( distance ) );
  3945. return this;
  3946. },
  3947. translateX: function ( distance ) {
  3948. return this.translateOnAxis( _xAxis, distance );
  3949. },
  3950. translateY: function ( distance ) {
  3951. return this.translateOnAxis( _yAxis, distance );
  3952. },
  3953. translateZ: function ( distance ) {
  3954. return this.translateOnAxis( _zAxis, distance );
  3955. },
  3956. localToWorld: function ( vector ) {
  3957. return vector.applyMatrix4( this.matrixWorld );
  3958. },
  3959. worldToLocal: function ( vector ) {
  3960. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  3961. },
  3962. lookAt: function ( x, y, z ) {
  3963. // This method does not support objects having non-uniformly-scaled parent(s)
  3964. if ( x.isVector3 ) {
  3965. _target.copy( x );
  3966. } else {
  3967. _target.set( x, y, z );
  3968. }
  3969. const parent = this.parent;
  3970. this.updateWorldMatrix( true, false );
  3971. _position.setFromMatrixPosition( this.matrixWorld );
  3972. if ( this.isCamera || this.isLight ) {
  3973. _m1$1.lookAt( _position, _target, this.up );
  3974. } else {
  3975. _m1$1.lookAt( _target, _position, this.up );
  3976. }
  3977. this.quaternion.setFromRotationMatrix( _m1$1 );
  3978. if ( parent ) {
  3979. _m1$1.extractRotation( parent.matrixWorld );
  3980. _q1.setFromRotationMatrix( _m1$1 );
  3981. this.quaternion.premultiply( _q1.invert() );
  3982. }
  3983. },
  3984. add: function ( object ) {
  3985. if ( arguments.length > 1 ) {
  3986. for ( let i = 0; i < arguments.length; i ++ ) {
  3987. this.add( arguments[ i ] );
  3988. }
  3989. return this;
  3990. }
  3991. if ( object === this ) {
  3992. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  3993. return this;
  3994. }
  3995. if ( object && object.isObject3D ) {
  3996. if ( object.parent !== null ) {
  3997. object.parent.remove( object );
  3998. }
  3999. object.parent = this;
  4000. this.children.push( object );
  4001. object.dispatchEvent( _addedEvent );
  4002. } else {
  4003. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4004. }
  4005. return this;
  4006. },
  4007. remove: function ( object ) {
  4008. if ( arguments.length > 1 ) {
  4009. for ( let i = 0; i < arguments.length; i ++ ) {
  4010. this.remove( arguments[ i ] );
  4011. }
  4012. return this;
  4013. }
  4014. const index = this.children.indexOf( object );
  4015. if ( index !== - 1 ) {
  4016. object.parent = null;
  4017. this.children.splice( index, 1 );
  4018. object.dispatchEvent( _removedEvent );
  4019. }
  4020. return this;
  4021. },
  4022. clear: function () {
  4023. for ( let i = 0; i < this.children.length; i ++ ) {
  4024. const object = this.children[ i ];
  4025. object.parent = null;
  4026. object.dispatchEvent( _removedEvent );
  4027. }
  4028. this.children.length = 0;
  4029. return this;
  4030. },
  4031. attach: function ( object ) {
  4032. // adds object as a child of this, while maintaining the object's world transform
  4033. this.updateWorldMatrix( true, false );
  4034. _m1$1.copy( this.matrixWorld ).invert();
  4035. if ( object.parent !== null ) {
  4036. object.parent.updateWorldMatrix( true, false );
  4037. _m1$1.multiply( object.parent.matrixWorld );
  4038. }
  4039. object.applyMatrix4( _m1$1 );
  4040. object.updateWorldMatrix( false, false );
  4041. this.add( object );
  4042. return this;
  4043. },
  4044. getObjectById: function ( id ) {
  4045. return this.getObjectByProperty( 'id', id );
  4046. },
  4047. getObjectByName: function ( name ) {
  4048. return this.getObjectByProperty( 'name', name );
  4049. },
  4050. getObjectByProperty: function ( name, value ) {
  4051. if ( this[ name ] === value ) return this;
  4052. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4053. const child = this.children[ i ];
  4054. const object = child.getObjectByProperty( name, value );
  4055. if ( object !== undefined ) {
  4056. return object;
  4057. }
  4058. }
  4059. return undefined;
  4060. },
  4061. getWorldPosition: function ( target ) {
  4062. if ( target === undefined ) {
  4063. console.warn( 'THREE.Object3D: .getWorldPosition() target is now required' );
  4064. target = new Vector3();
  4065. }
  4066. this.updateWorldMatrix( true, false );
  4067. return target.setFromMatrixPosition( this.matrixWorld );
  4068. },
  4069. getWorldQuaternion: function ( target ) {
  4070. if ( target === undefined ) {
  4071. console.warn( 'THREE.Object3D: .getWorldQuaternion() target is now required' );
  4072. target = new Quaternion();
  4073. }
  4074. this.updateWorldMatrix( true, false );
  4075. this.matrixWorld.decompose( _position, target, _scale );
  4076. return target;
  4077. },
  4078. getWorldScale: function ( target ) {
  4079. if ( target === undefined ) {
  4080. console.warn( 'THREE.Object3D: .getWorldScale() target is now required' );
  4081. target = new Vector3();
  4082. }
  4083. this.updateWorldMatrix( true, false );
  4084. this.matrixWorld.decompose( _position, _quaternion$2, target );
  4085. return target;
  4086. },
  4087. getWorldDirection: function ( target ) {
  4088. if ( target === undefined ) {
  4089. console.warn( 'THREE.Object3D: .getWorldDirection() target is now required' );
  4090. target = new Vector3();
  4091. }
  4092. this.updateWorldMatrix( true, false );
  4093. const e = this.matrixWorld.elements;
  4094. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4095. },
  4096. raycast: function () {},
  4097. traverse: function ( callback ) {
  4098. callback( this );
  4099. const children = this.children;
  4100. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4101. children[ i ].traverse( callback );
  4102. }
  4103. },
  4104. traverseVisible: function ( callback ) {
  4105. if ( this.visible === false ) return;
  4106. callback( this );
  4107. const children = this.children;
  4108. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4109. children[ i ].traverseVisible( callback );
  4110. }
  4111. },
  4112. traverseAncestors: function ( callback ) {
  4113. const parent = this.parent;
  4114. if ( parent !== null ) {
  4115. callback( parent );
  4116. parent.traverseAncestors( callback );
  4117. }
  4118. },
  4119. updateMatrix: function () {
  4120. this.matrix.compose( this.position, this.quaternion, this.scale );
  4121. this.matrixWorldNeedsUpdate = true;
  4122. },
  4123. updateMatrixWorld: function ( force ) {
  4124. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4125. if ( this.matrixWorldNeedsUpdate || force ) {
  4126. if ( this.parent === null ) {
  4127. this.matrixWorld.copy( this.matrix );
  4128. } else {
  4129. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4130. }
  4131. this.matrixWorldNeedsUpdate = false;
  4132. force = true;
  4133. }
  4134. // update children
  4135. const children = this.children;
  4136. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4137. children[ i ].updateMatrixWorld( force );
  4138. }
  4139. },
  4140. updateWorldMatrix: function ( updateParents, updateChildren ) {
  4141. const parent = this.parent;
  4142. if ( updateParents === true && parent !== null ) {
  4143. parent.updateWorldMatrix( true, false );
  4144. }
  4145. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4146. if ( this.parent === null ) {
  4147. this.matrixWorld.copy( this.matrix );
  4148. } else {
  4149. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4150. }
  4151. // update children
  4152. if ( updateChildren === true ) {
  4153. const children = this.children;
  4154. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4155. children[ i ].updateWorldMatrix( false, true );
  4156. }
  4157. }
  4158. },
  4159. toJSON: function ( meta ) {
  4160. // meta is a string when called from JSON.stringify
  4161. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4162. const output = {};
  4163. // meta is a hash used to collect geometries, materials.
  4164. // not providing it implies that this is the root object
  4165. // being serialized.
  4166. if ( isRootObject ) {
  4167. // initialize meta obj
  4168. meta = {
  4169. geometries: {},
  4170. materials: {},
  4171. textures: {},
  4172. images: {},
  4173. shapes: {},
  4174. skeletons: {},
  4175. animations: {}
  4176. };
  4177. output.metadata = {
  4178. version: 4.5,
  4179. type: 'Object',
  4180. generator: 'Object3D.toJSON'
  4181. };
  4182. }
  4183. // standard Object3D serialization
  4184. const object = {};
  4185. object.uuid = this.uuid;
  4186. object.type = this.type;
  4187. if ( this.name !== '' ) object.name = this.name;
  4188. if ( this.castShadow === true ) object.castShadow = true;
  4189. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4190. if ( this.visible === false ) object.visible = false;
  4191. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4192. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4193. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4194. object.layers = this.layers.mask;
  4195. object.matrix = this.matrix.toArray();
  4196. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4197. // object specific properties
  4198. if ( this.isInstancedMesh ) {
  4199. object.type = 'InstancedMesh';
  4200. object.count = this.count;
  4201. object.instanceMatrix = this.instanceMatrix.toJSON();
  4202. }
  4203. //
  4204. function serialize( library, element ) {
  4205. if ( library[ element.uuid ] === undefined ) {
  4206. library[ element.uuid ] = element.toJSON( meta );
  4207. }
  4208. return element.uuid;
  4209. }
  4210. if ( this.isMesh || this.isLine || this.isPoints ) {
  4211. object.geometry = serialize( meta.geometries, this.geometry );
  4212. const parameters = this.geometry.parameters;
  4213. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4214. const shapes = parameters.shapes;
  4215. if ( Array.isArray( shapes ) ) {
  4216. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4217. const shape = shapes[ i ];
  4218. serialize( meta.shapes, shape );
  4219. }
  4220. } else {
  4221. serialize( meta.shapes, shapes );
  4222. }
  4223. }
  4224. }
  4225. if ( this.isSkinnedMesh ) {
  4226. object.bindMode = this.bindMode;
  4227. object.bindMatrix = this.bindMatrix.toArray();
  4228. if ( this.skeleton !== undefined ) {
  4229. serialize( meta.skeletons, this.skeleton );
  4230. object.skeleton = this.skeleton.uuid;
  4231. }
  4232. }
  4233. if ( this.material !== undefined ) {
  4234. if ( Array.isArray( this.material ) ) {
  4235. const uuids = [];
  4236. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4237. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4238. }
  4239. object.material = uuids;
  4240. } else {
  4241. object.material = serialize( meta.materials, this.material );
  4242. }
  4243. }
  4244. //
  4245. if ( this.children.length > 0 ) {
  4246. object.children = [];
  4247. for ( let i = 0; i < this.children.length; i ++ ) {
  4248. object.children.push( this.children[ i ].toJSON( meta ).object );
  4249. }
  4250. }
  4251. //
  4252. if ( this.animations.length > 0 ) {
  4253. object.animations = [];
  4254. for ( let i = 0; i < this.animations.length; i ++ ) {
  4255. const animation = this.animations[ i ];
  4256. object.animations.push( serialize( meta.animations, animation ) );
  4257. }
  4258. }
  4259. if ( isRootObject ) {
  4260. const geometries = extractFromCache( meta.geometries );
  4261. const materials = extractFromCache( meta.materials );
  4262. const textures = extractFromCache( meta.textures );
  4263. const images = extractFromCache( meta.images );
  4264. const shapes = extractFromCache( meta.shapes );
  4265. const skeletons = extractFromCache( meta.skeletons );
  4266. const animations = extractFromCache( meta.animations );
  4267. if ( geometries.length > 0 ) output.geometries = geometries;
  4268. if ( materials.length > 0 ) output.materials = materials;
  4269. if ( textures.length > 0 ) output.textures = textures;
  4270. if ( images.length > 0 ) output.images = images;
  4271. if ( shapes.length > 0 ) output.shapes = shapes;
  4272. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4273. if ( animations.length > 0 ) output.animations = animations;
  4274. }
  4275. output.object = object;
  4276. return output;
  4277. // extract data from the cache hash
  4278. // remove metadata on each item
  4279. // and return as array
  4280. function extractFromCache( cache ) {
  4281. const values = [];
  4282. for ( const key in cache ) {
  4283. const data = cache[ key ];
  4284. delete data.metadata;
  4285. values.push( data );
  4286. }
  4287. return values;
  4288. }
  4289. },
  4290. clone: function ( recursive ) {
  4291. return new this.constructor().copy( this, recursive );
  4292. },
  4293. copy: function ( source, recursive = true ) {
  4294. this.name = source.name;
  4295. this.up.copy( source.up );
  4296. this.position.copy( source.position );
  4297. this.rotation.order = source.rotation.order;
  4298. this.quaternion.copy( source.quaternion );
  4299. this.scale.copy( source.scale );
  4300. this.matrix.copy( source.matrix );
  4301. this.matrixWorld.copy( source.matrixWorld );
  4302. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4303. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4304. this.layers.mask = source.layers.mask;
  4305. this.visible = source.visible;
  4306. this.castShadow = source.castShadow;
  4307. this.receiveShadow = source.receiveShadow;
  4308. this.frustumCulled = source.frustumCulled;
  4309. this.renderOrder = source.renderOrder;
  4310. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4311. if ( recursive === true ) {
  4312. for ( let i = 0; i < source.children.length; i ++ ) {
  4313. const child = source.children[ i ];
  4314. this.add( child.clone() );
  4315. }
  4316. }
  4317. return this;
  4318. }
  4319. } );
  4320. const _vector1 = /*@__PURE__*/ new Vector3();
  4321. const _vector2 = /*@__PURE__*/ new Vector3();
  4322. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  4323. class Plane {
  4324. constructor( normal, constant ) {
  4325. Object.defineProperty( this, 'isPlane', { value: true } );
  4326. // normal is assumed to be normalized
  4327. this.normal = ( normal !== undefined ) ? normal : new Vector3( 1, 0, 0 );
  4328. this.constant = ( constant !== undefined ) ? constant : 0;
  4329. }
  4330. set( normal, constant ) {
  4331. this.normal.copy( normal );
  4332. this.constant = constant;
  4333. return this;
  4334. }
  4335. setComponents( x, y, z, w ) {
  4336. this.normal.set( x, y, z );
  4337. this.constant = w;
  4338. return this;
  4339. }
  4340. setFromNormalAndCoplanarPoint( normal, point ) {
  4341. this.normal.copy( normal );
  4342. this.constant = - point.dot( this.normal );
  4343. return this;
  4344. }
  4345. setFromCoplanarPoints( a, b, c ) {
  4346. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  4347. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  4348. this.setFromNormalAndCoplanarPoint( normal, a );
  4349. return this;
  4350. }
  4351. clone() {
  4352. return new this.constructor().copy( this );
  4353. }
  4354. copy( plane ) {
  4355. this.normal.copy( plane.normal );
  4356. this.constant = plane.constant;
  4357. return this;
  4358. }
  4359. normalize() {
  4360. // Note: will lead to a divide by zero if the plane is invalid.
  4361. const inverseNormalLength = 1.0 / this.normal.length();
  4362. this.normal.multiplyScalar( inverseNormalLength );
  4363. this.constant *= inverseNormalLength;
  4364. return this;
  4365. }
  4366. negate() {
  4367. this.constant *= - 1;
  4368. this.normal.negate();
  4369. return this;
  4370. }
  4371. distanceToPoint( point ) {
  4372. return this.normal.dot( point ) + this.constant;
  4373. }
  4374. distanceToSphere( sphere ) {
  4375. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4376. }
  4377. projectPoint( point, target ) {
  4378. if ( target === undefined ) {
  4379. console.warn( 'THREE.Plane: .projectPoint() target is now required' );
  4380. target = new Vector3();
  4381. }
  4382. return target.copy( this.normal ).multiplyScalar( - this.distanceToPoint( point ) ).add( point );
  4383. }
  4384. intersectLine( line, target ) {
  4385. if ( target === undefined ) {
  4386. console.warn( 'THREE.Plane: .intersectLine() target is now required' );
  4387. target = new Vector3();
  4388. }
  4389. const direction = line.delta( _vector1 );
  4390. const denominator = this.normal.dot( direction );
  4391. if ( denominator === 0 ) {
  4392. // line is coplanar, return origin
  4393. if ( this.distanceToPoint( line.start ) === 0 ) {
  4394. return target.copy( line.start );
  4395. }
  4396. // Unsure if this is the correct method to handle this case.
  4397. return undefined;
  4398. }
  4399. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4400. if ( t < 0 || t > 1 ) {
  4401. return undefined;
  4402. }
  4403. return target.copy( direction ).multiplyScalar( t ).add( line.start );
  4404. }
  4405. intersectsLine( line ) {
  4406. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4407. const startSign = this.distanceToPoint( line.start );
  4408. const endSign = this.distanceToPoint( line.end );
  4409. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4410. }
  4411. intersectsBox( box ) {
  4412. return box.intersectsPlane( this );
  4413. }
  4414. intersectsSphere( sphere ) {
  4415. return sphere.intersectsPlane( this );
  4416. }
  4417. coplanarPoint( target ) {
  4418. if ( target === undefined ) {
  4419. console.warn( 'THREE.Plane: .coplanarPoint() target is now required' );
  4420. target = new Vector3();
  4421. }
  4422. return target.copy( this.normal ).multiplyScalar( - this.constant );
  4423. }
  4424. applyMatrix4( matrix, optionalNormalMatrix ) {
  4425. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  4426. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  4427. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  4428. this.constant = - referencePoint.dot( normal );
  4429. return this;
  4430. }
  4431. translate( offset ) {
  4432. this.constant -= offset.dot( this.normal );
  4433. return this;
  4434. }
  4435. equals( plane ) {
  4436. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4437. }
  4438. }
  4439. const _v0$1 = /*@__PURE__*/ new Vector3();
  4440. const _v1$3 = /*@__PURE__*/ new Vector3();
  4441. const _v2$1 = /*@__PURE__*/ new Vector3();
  4442. const _v3 = /*@__PURE__*/ new Vector3();
  4443. const _vab = /*@__PURE__*/ new Vector3();
  4444. const _vac = /*@__PURE__*/ new Vector3();
  4445. const _vbc = /*@__PURE__*/ new Vector3();
  4446. const _vap = /*@__PURE__*/ new Vector3();
  4447. const _vbp = /*@__PURE__*/ new Vector3();
  4448. const _vcp = /*@__PURE__*/ new Vector3();
  4449. class Triangle {
  4450. constructor( a, b, c ) {
  4451. this.a = ( a !== undefined ) ? a : new Vector3();
  4452. this.b = ( b !== undefined ) ? b : new Vector3();
  4453. this.c = ( c !== undefined ) ? c : new Vector3();
  4454. }
  4455. static getNormal( a, b, c, target ) {
  4456. if ( target === undefined ) {
  4457. console.warn( 'THREE.Triangle: .getNormal() target is now required' );
  4458. target = new Vector3();
  4459. }
  4460. target.subVectors( c, b );
  4461. _v0$1.subVectors( a, b );
  4462. target.cross( _v0$1 );
  4463. const targetLengthSq = target.lengthSq();
  4464. if ( targetLengthSq > 0 ) {
  4465. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4466. }
  4467. return target.set( 0, 0, 0 );
  4468. }
  4469. // static/instance method to calculate barycentric coordinates
  4470. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4471. static getBarycoord( point, a, b, c, target ) {
  4472. _v0$1.subVectors( c, a );
  4473. _v1$3.subVectors( b, a );
  4474. _v2$1.subVectors( point, a );
  4475. const dot00 = _v0$1.dot( _v0$1 );
  4476. const dot01 = _v0$1.dot( _v1$3 );
  4477. const dot02 = _v0$1.dot( _v2$1 );
  4478. const dot11 = _v1$3.dot( _v1$3 );
  4479. const dot12 = _v1$3.dot( _v2$1 );
  4480. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4481. if ( target === undefined ) {
  4482. console.warn( 'THREE.Triangle: .getBarycoord() target is now required' );
  4483. target = new Vector3();
  4484. }
  4485. // collinear or singular triangle
  4486. if ( denom === 0 ) {
  4487. // arbitrary location outside of triangle?
  4488. // not sure if this is the best idea, maybe should be returning undefined
  4489. return target.set( - 2, - 1, - 1 );
  4490. }
  4491. const invDenom = 1 / denom;
  4492. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4493. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4494. // barycentric coordinates must always sum to 1
  4495. return target.set( 1 - u - v, v, u );
  4496. }
  4497. static containsPoint( point, a, b, c ) {
  4498. this.getBarycoord( point, a, b, c, _v3 );
  4499. return ( _v3.x >= 0 ) && ( _v3.y >= 0 ) && ( ( _v3.x + _v3.y ) <= 1 );
  4500. }
  4501. static getUV( point, p1, p2, p3, uv1, uv2, uv3, target ) {
  4502. this.getBarycoord( point, p1, p2, p3, _v3 );
  4503. target.set( 0, 0 );
  4504. target.addScaledVector( uv1, _v3.x );
  4505. target.addScaledVector( uv2, _v3.y );
  4506. target.addScaledVector( uv3, _v3.z );
  4507. return target;
  4508. }
  4509. static isFrontFacing( a, b, c, direction ) {
  4510. _v0$1.subVectors( c, b );
  4511. _v1$3.subVectors( a, b );
  4512. // strictly front facing
  4513. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  4514. }
  4515. set( a, b, c ) {
  4516. this.a.copy( a );
  4517. this.b.copy( b );
  4518. this.c.copy( c );
  4519. return this;
  4520. }
  4521. setFromPointsAndIndices( points, i0, i1, i2 ) {
  4522. this.a.copy( points[ i0 ] );
  4523. this.b.copy( points[ i1 ] );
  4524. this.c.copy( points[ i2 ] );
  4525. return this;
  4526. }
  4527. clone() {
  4528. return new this.constructor().copy( this );
  4529. }
  4530. copy( triangle ) {
  4531. this.a.copy( triangle.a );
  4532. this.b.copy( triangle.b );
  4533. this.c.copy( triangle.c );
  4534. return this;
  4535. }
  4536. getArea() {
  4537. _v0$1.subVectors( this.c, this.b );
  4538. _v1$3.subVectors( this.a, this.b );
  4539. return _v0$1.cross( _v1$3 ).length() * 0.5;
  4540. }
  4541. getMidpoint( target ) {
  4542. if ( target === undefined ) {
  4543. console.warn( 'THREE.Triangle: .getMidpoint() target is now required' );
  4544. target = new Vector3();
  4545. }
  4546. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4547. }
  4548. getNormal( target ) {
  4549. return Triangle.getNormal( this.a, this.b, this.c, target );
  4550. }
  4551. getPlane( target ) {
  4552. if ( target === undefined ) {
  4553. console.warn( 'THREE.Triangle: .getPlane() target is now required' );
  4554. target = new Plane();
  4555. }
  4556. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  4557. }
  4558. getBarycoord( point, target ) {
  4559. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  4560. }
  4561. getUV( point, uv1, uv2, uv3, target ) {
  4562. return Triangle.getUV( point, this.a, this.b, this.c, uv1, uv2, uv3, target );
  4563. }
  4564. containsPoint( point ) {
  4565. return Triangle.containsPoint( point, this.a, this.b, this.c );
  4566. }
  4567. isFrontFacing( direction ) {
  4568. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  4569. }
  4570. intersectsBox( box ) {
  4571. return box.intersectsTriangle( this );
  4572. }
  4573. closestPointToPoint( p, target ) {
  4574. if ( target === undefined ) {
  4575. console.warn( 'THREE.Triangle: .closestPointToPoint() target is now required' );
  4576. target = new Vector3();
  4577. }
  4578. const a = this.a, b = this.b, c = this.c;
  4579. let v, w;
  4580. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  4581. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  4582. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  4583. // basically, we're distinguishing which of the voronoi regions of the triangle
  4584. // the point lies in with the minimum amount of redundant computation.
  4585. _vab.subVectors( b, a );
  4586. _vac.subVectors( c, a );
  4587. _vap.subVectors( p, a );
  4588. const d1 = _vab.dot( _vap );
  4589. const d2 = _vac.dot( _vap );
  4590. if ( d1 <= 0 && d2 <= 0 ) {
  4591. // vertex region of A; barycentric coords (1, 0, 0)
  4592. return target.copy( a );
  4593. }
  4594. _vbp.subVectors( p, b );
  4595. const d3 = _vab.dot( _vbp );
  4596. const d4 = _vac.dot( _vbp );
  4597. if ( d3 >= 0 && d4 <= d3 ) {
  4598. // vertex region of B; barycentric coords (0, 1, 0)
  4599. return target.copy( b );
  4600. }
  4601. const vc = d1 * d4 - d3 * d2;
  4602. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  4603. v = d1 / ( d1 - d3 );
  4604. // edge region of AB; barycentric coords (1-v, v, 0)
  4605. return target.copy( a ).addScaledVector( _vab, v );
  4606. }
  4607. _vcp.subVectors( p, c );
  4608. const d5 = _vab.dot( _vcp );
  4609. const d6 = _vac.dot( _vcp );
  4610. if ( d6 >= 0 && d5 <= d6 ) {
  4611. // vertex region of C; barycentric coords (0, 0, 1)
  4612. return target.copy( c );
  4613. }
  4614. const vb = d5 * d2 - d1 * d6;
  4615. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  4616. w = d2 / ( d2 - d6 );
  4617. // edge region of AC; barycentric coords (1-w, 0, w)
  4618. return target.copy( a ).addScaledVector( _vac, w );
  4619. }
  4620. const va = d3 * d6 - d5 * d4;
  4621. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  4622. _vbc.subVectors( c, b );
  4623. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  4624. // edge region of BC; barycentric coords (0, 1-w, w)
  4625. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  4626. }
  4627. // face region
  4628. const denom = 1 / ( va + vb + vc );
  4629. // u = va * denom
  4630. v = vb * denom;
  4631. w = vc * denom;
  4632. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  4633. }
  4634. equals( triangle ) {
  4635. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4636. }
  4637. }
  4638. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  4639. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  4640. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  4641. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  4642. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  4643. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  4644. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  4645. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  4646. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  4647. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  4648. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  4649. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  4650. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  4651. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  4652. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  4653. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  4654. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  4655. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  4656. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  4657. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  4658. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  4659. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  4660. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  4661. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  4662. const _hslA = { h: 0, s: 0, l: 0 };
  4663. const _hslB = { h: 0, s: 0, l: 0 };
  4664. function hue2rgb( p, q, t ) {
  4665. if ( t < 0 ) t += 1;
  4666. if ( t > 1 ) t -= 1;
  4667. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  4668. if ( t < 1 / 2 ) return q;
  4669. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  4670. return p;
  4671. }
  4672. function SRGBToLinear( c ) {
  4673. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  4674. }
  4675. function LinearToSRGB( c ) {
  4676. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  4677. }
  4678. class Color {
  4679. constructor( r, g, b ) {
  4680. Object.defineProperty( this, 'isColor', { value: true } );
  4681. if ( g === undefined && b === undefined ) {
  4682. // r is THREE.Color, hex or string
  4683. return this.set( r );
  4684. }
  4685. return this.setRGB( r, g, b );
  4686. }
  4687. set( value ) {
  4688. if ( value && value.isColor ) {
  4689. this.copy( value );
  4690. } else if ( typeof value === 'number' ) {
  4691. this.setHex( value );
  4692. } else if ( typeof value === 'string' ) {
  4693. this.setStyle( value );
  4694. }
  4695. return this;
  4696. }
  4697. setScalar( scalar ) {
  4698. this.r = scalar;
  4699. this.g = scalar;
  4700. this.b = scalar;
  4701. return this;
  4702. }
  4703. setHex( hex ) {
  4704. hex = Math.floor( hex );
  4705. this.r = ( hex >> 16 & 255 ) / 255;
  4706. this.g = ( hex >> 8 & 255 ) / 255;
  4707. this.b = ( hex & 255 ) / 255;
  4708. return this;
  4709. }
  4710. setRGB( r, g, b ) {
  4711. this.r = r;
  4712. this.g = g;
  4713. this.b = b;
  4714. return this;
  4715. }
  4716. setHSL( h, s, l ) {
  4717. // h,s,l ranges are in 0.0 - 1.0
  4718. h = MathUtils.euclideanModulo( h, 1 );
  4719. s = MathUtils.clamp( s, 0, 1 );
  4720. l = MathUtils.clamp( l, 0, 1 );
  4721. if ( s === 0 ) {
  4722. this.r = this.g = this.b = l;
  4723. } else {
  4724. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  4725. const q = ( 2 * l ) - p;
  4726. this.r = hue2rgb( q, p, h + 1 / 3 );
  4727. this.g = hue2rgb( q, p, h );
  4728. this.b = hue2rgb( q, p, h - 1 / 3 );
  4729. }
  4730. return this;
  4731. }
  4732. setStyle( style ) {
  4733. function handleAlpha( string ) {
  4734. if ( string === undefined ) return;
  4735. if ( parseFloat( string ) < 1 ) {
  4736. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  4737. }
  4738. }
  4739. let m;
  4740. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  4741. // rgb / hsl
  4742. let color;
  4743. const name = m[ 1 ];
  4744. const components = m[ 2 ];
  4745. switch ( name ) {
  4746. case 'rgb':
  4747. case 'rgba':
  4748. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  4749. // rgb(255,0,0) rgba(255,0,0,0.5)
  4750. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  4751. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  4752. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  4753. handleAlpha( color[ 4 ] );
  4754. return this;
  4755. }
  4756. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  4757. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  4758. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  4759. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  4760. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  4761. handleAlpha( color[ 4 ] );
  4762. return this;
  4763. }
  4764. break;
  4765. case 'hsl':
  4766. case 'hsla':
  4767. if ( color = /^(\d*\.?\d+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  4768. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  4769. const h = parseFloat( color[ 1 ] ) / 360;
  4770. const s = parseInt( color[ 2 ], 10 ) / 100;
  4771. const l = parseInt( color[ 3 ], 10 ) / 100;
  4772. handleAlpha( color[ 4 ] );
  4773. return this.setHSL( h, s, l );
  4774. }
  4775. break;
  4776. }
  4777. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  4778. // hex color
  4779. const hex = m[ 1 ];
  4780. const size = hex.length;
  4781. if ( size === 3 ) {
  4782. // #ff0
  4783. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  4784. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  4785. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  4786. return this;
  4787. } else if ( size === 6 ) {
  4788. // #ff0000
  4789. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  4790. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  4791. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  4792. return this;
  4793. }
  4794. }
  4795. if ( style && style.length > 0 ) {
  4796. return this.setColorName( style );
  4797. }
  4798. return this;
  4799. }
  4800. setColorName( style ) {
  4801. // color keywords
  4802. const hex = _colorKeywords[ style ];
  4803. if ( hex !== undefined ) {
  4804. // red
  4805. this.setHex( hex );
  4806. } else {
  4807. // unknown color
  4808. console.warn( 'THREE.Color: Unknown color ' + style );
  4809. }
  4810. return this;
  4811. }
  4812. clone() {
  4813. return new this.constructor( this.r, this.g, this.b );
  4814. }
  4815. copy( color ) {
  4816. this.r = color.r;
  4817. this.g = color.g;
  4818. this.b = color.b;
  4819. return this;
  4820. }
  4821. copyGammaToLinear( color, gammaFactor = 2.0 ) {
  4822. this.r = Math.pow( color.r, gammaFactor );
  4823. this.g = Math.pow( color.g, gammaFactor );
  4824. this.b = Math.pow( color.b, gammaFactor );
  4825. return this;
  4826. }
  4827. copyLinearToGamma( color, gammaFactor = 2.0 ) {
  4828. const safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  4829. this.r = Math.pow( color.r, safeInverse );
  4830. this.g = Math.pow( color.g, safeInverse );
  4831. this.b = Math.pow( color.b, safeInverse );
  4832. return this;
  4833. }
  4834. convertGammaToLinear( gammaFactor ) {
  4835. this.copyGammaToLinear( this, gammaFactor );
  4836. return this;
  4837. }
  4838. convertLinearToGamma( gammaFactor ) {
  4839. this.copyLinearToGamma( this, gammaFactor );
  4840. return this;
  4841. }
  4842. copySRGBToLinear( color ) {
  4843. this.r = SRGBToLinear( color.r );
  4844. this.g = SRGBToLinear( color.g );
  4845. this.b = SRGBToLinear( color.b );
  4846. return this;
  4847. }
  4848. copyLinearToSRGB( color ) {
  4849. this.r = LinearToSRGB( color.r );
  4850. this.g = LinearToSRGB( color.g );
  4851. this.b = LinearToSRGB( color.b );
  4852. return this;
  4853. }
  4854. convertSRGBToLinear() {
  4855. this.copySRGBToLinear( this );
  4856. return this;
  4857. }
  4858. convertLinearToSRGB() {
  4859. this.copyLinearToSRGB( this );
  4860. return this;
  4861. }
  4862. getHex() {
  4863. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  4864. }
  4865. getHexString() {
  4866. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  4867. }
  4868. getHSL( target ) {
  4869. // h,s,l ranges are in 0.0 - 1.0
  4870. if ( target === undefined ) {
  4871. console.warn( 'THREE.Color: .getHSL() target is now required' );
  4872. target = { h: 0, s: 0, l: 0 };
  4873. }
  4874. const r = this.r, g = this.g, b = this.b;
  4875. const max = Math.max( r, g, b );
  4876. const min = Math.min( r, g, b );
  4877. let hue, saturation;
  4878. const lightness = ( min + max ) / 2.0;
  4879. if ( min === max ) {
  4880. hue = 0;
  4881. saturation = 0;
  4882. } else {
  4883. const delta = max - min;
  4884. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  4885. switch ( max ) {
  4886. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  4887. case g: hue = ( b - r ) / delta + 2; break;
  4888. case b: hue = ( r - g ) / delta + 4; break;
  4889. }
  4890. hue /= 6;
  4891. }
  4892. target.h = hue;
  4893. target.s = saturation;
  4894. target.l = lightness;
  4895. return target;
  4896. }
  4897. getStyle() {
  4898. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  4899. }
  4900. offsetHSL( h, s, l ) {
  4901. this.getHSL( _hslA );
  4902. _hslA.h += h; _hslA.s += s; _hslA.l += l;
  4903. this.setHSL( _hslA.h, _hslA.s, _hslA.l );
  4904. return this;
  4905. }
  4906. add( color ) {
  4907. this.r += color.r;
  4908. this.g += color.g;
  4909. this.b += color.b;
  4910. return this;
  4911. }
  4912. addColors( color1, color2 ) {
  4913. this.r = color1.r + color2.r;
  4914. this.g = color1.g + color2.g;
  4915. this.b = color1.b + color2.b;
  4916. return this;
  4917. }
  4918. addScalar( s ) {
  4919. this.r += s;
  4920. this.g += s;
  4921. this.b += s;
  4922. return this;
  4923. }
  4924. sub( color ) {
  4925. this.r = Math.max( 0, this.r - color.r );
  4926. this.g = Math.max( 0, this.g - color.g );
  4927. this.b = Math.max( 0, this.b - color.b );
  4928. return this;
  4929. }
  4930. multiply( color ) {
  4931. this.r *= color.r;
  4932. this.g *= color.g;
  4933. this.b *= color.b;
  4934. return this;
  4935. }
  4936. multiplyScalar( s ) {
  4937. this.r *= s;
  4938. this.g *= s;
  4939. this.b *= s;
  4940. return this;
  4941. }
  4942. lerp( color, alpha ) {
  4943. this.r += ( color.r - this.r ) * alpha;
  4944. this.g += ( color.g - this.g ) * alpha;
  4945. this.b += ( color.b - this.b ) * alpha;
  4946. return this;
  4947. }
  4948. lerpHSL( color, alpha ) {
  4949. this.getHSL( _hslA );
  4950. color.getHSL( _hslB );
  4951. const h = MathUtils.lerp( _hslA.h, _hslB.h, alpha );
  4952. const s = MathUtils.lerp( _hslA.s, _hslB.s, alpha );
  4953. const l = MathUtils.lerp( _hslA.l, _hslB.l, alpha );
  4954. this.setHSL( h, s, l );
  4955. return this;
  4956. }
  4957. equals( c ) {
  4958. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  4959. }
  4960. fromArray( array, offset = 0 ) {
  4961. this.r = array[ offset ];
  4962. this.g = array[ offset + 1 ];
  4963. this.b = array[ offset + 2 ];
  4964. return this;
  4965. }
  4966. toArray( array = [], offset = 0 ) {
  4967. array[ offset ] = this.r;
  4968. array[ offset + 1 ] = this.g;
  4969. array[ offset + 2 ] = this.b;
  4970. return array;
  4971. }
  4972. fromBufferAttribute( attribute, index ) {
  4973. this.r = attribute.getX( index );
  4974. this.g = attribute.getY( index );
  4975. this.b = attribute.getZ( index );
  4976. if ( attribute.normalized === true ) {
  4977. // assuming Uint8Array
  4978. this.r /= 255;
  4979. this.g /= 255;
  4980. this.b /= 255;
  4981. }
  4982. return this;
  4983. }
  4984. toJSON() {
  4985. return this.getHex();
  4986. }
  4987. }
  4988. Color.NAMES = _colorKeywords;
  4989. Color.prototype.r = 1;
  4990. Color.prototype.g = 1;
  4991. Color.prototype.b = 1;
  4992. class Face3 {
  4993. constructor( a, b, c, normal, color, materialIndex = 0 ) {
  4994. this.a = a;
  4995. this.b = b;
  4996. this.c = c;
  4997. this.normal = ( normal && normal.isVector3 ) ? normal : new Vector3();
  4998. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4999. this.color = ( color && color.isColor ) ? color : new Color();
  5000. this.vertexColors = Array.isArray( color ) ? color : [];
  5001. this.materialIndex = materialIndex;
  5002. }
  5003. clone() {
  5004. return new this.constructor().copy( this );
  5005. }
  5006. copy( source ) {
  5007. this.a = source.a;
  5008. this.b = source.b;
  5009. this.c = source.c;
  5010. this.normal.copy( source.normal );
  5011. this.color.copy( source.color );
  5012. this.materialIndex = source.materialIndex;
  5013. for ( let i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5014. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5015. }
  5016. for ( let i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5017. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5018. }
  5019. return this;
  5020. }
  5021. }
  5022. let materialId = 0;
  5023. function Material() {
  5024. Object.defineProperty( this, 'id', { value: materialId ++ } );
  5025. this.uuid = MathUtils.generateUUID();
  5026. this.name = '';
  5027. this.type = 'Material';
  5028. this.fog = true;
  5029. this.blending = NormalBlending;
  5030. this.side = FrontSide;
  5031. this.flatShading = false;
  5032. this.vertexColors = false;
  5033. this.opacity = 1;
  5034. this.transparent = false;
  5035. this.blendSrc = SrcAlphaFactor;
  5036. this.blendDst = OneMinusSrcAlphaFactor;
  5037. this.blendEquation = AddEquation;
  5038. this.blendSrcAlpha = null;
  5039. this.blendDstAlpha = null;
  5040. this.blendEquationAlpha = null;
  5041. this.depthFunc = LessEqualDepth;
  5042. this.depthTest = true;
  5043. this.depthWrite = true;
  5044. this.stencilWriteMask = 0xff;
  5045. this.stencilFunc = AlwaysStencilFunc;
  5046. this.stencilRef = 0;
  5047. this.stencilFuncMask = 0xff;
  5048. this.stencilFail = KeepStencilOp;
  5049. this.stencilZFail = KeepStencilOp;
  5050. this.stencilZPass = KeepStencilOp;
  5051. this.stencilWrite = false;
  5052. this.clippingPlanes = null;
  5053. this.clipIntersection = false;
  5054. this.clipShadows = false;
  5055. this.shadowSide = null;
  5056. this.colorWrite = true;
  5057. this.precision = null; // override the renderer's default precision for this material
  5058. this.polygonOffset = false;
  5059. this.polygonOffsetFactor = 0;
  5060. this.polygonOffsetUnits = 0;
  5061. this.dithering = false;
  5062. this.alphaTest = 0;
  5063. this.premultipliedAlpha = false;
  5064. this.visible = true;
  5065. this.toneMapped = true;
  5066. this.userData = {};
  5067. this.version = 0;
  5068. }
  5069. Material.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5070. constructor: Material,
  5071. isMaterial: true,
  5072. onBeforeCompile: function ( /* shaderobject, renderer */ ) {},
  5073. customProgramCacheKey: function () {
  5074. return this.onBeforeCompile.toString();
  5075. },
  5076. setValues: function ( values ) {
  5077. if ( values === undefined ) return;
  5078. for ( const key in values ) {
  5079. const newValue = values[ key ];
  5080. if ( newValue === undefined ) {
  5081. console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
  5082. continue;
  5083. }
  5084. // for backward compatability if shading is set in the constructor
  5085. if ( key === 'shading' ) {
  5086. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  5087. this.flatShading = ( newValue === FlatShading$1 ) ? true : false;
  5088. continue;
  5089. }
  5090. const currentValue = this[ key ];
  5091. if ( currentValue === undefined ) {
  5092. //console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
  5093. continue;
  5094. }
  5095. if ( currentValue && currentValue.isColor ) {
  5096. currentValue.set( newValue );
  5097. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5098. currentValue.copy( newValue );
  5099. } else {
  5100. this[ key ] = newValue;
  5101. }
  5102. }
  5103. },
  5104. toJSON: function ( meta ) {
  5105. const isRoot = ( meta === undefined || typeof meta === 'string' );
  5106. if ( isRoot ) {
  5107. meta = {
  5108. textures: {},
  5109. images: {}
  5110. };
  5111. }
  5112. const data = {
  5113. metadata: {
  5114. version: 4.5,
  5115. type: 'Material',
  5116. generator: 'Material.toJSON'
  5117. }
  5118. };
  5119. // standard Material serialization
  5120. data.uuid = this.uuid;
  5121. data.type = this.type;
  5122. if ( this.name !== '' ) data.name = this.name;
  5123. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5124. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5125. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5126. if ( this.sheen && this.sheen.isColor ) data.sheen = this.sheen.getHex();
  5127. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5128. if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5129. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5130. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5131. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5132. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5133. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5134. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5135. }
  5136. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5137. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5138. }
  5139. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5140. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5141. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5142. }
  5143. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5144. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5145. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5146. if ( this.lightMap && this.lightMap.isTexture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5147. if ( this.aoMap && this.aoMap.isTexture ) {
  5148. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5149. data.aoMapIntensity = this.aoMapIntensity;
  5150. }
  5151. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5152. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5153. data.bumpScale = this.bumpScale;
  5154. }
  5155. if ( this.normalMap && this.normalMap.isTexture ) {
  5156. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5157. data.normalMapType = this.normalMapType;
  5158. data.normalScale = this.normalScale.toArray();
  5159. }
  5160. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5161. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5162. data.displacementScale = this.displacementScale;
  5163. data.displacementBias = this.displacementBias;
  5164. }
  5165. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5166. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5167. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5168. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5169. if ( this.envMap && this.envMap.isTexture ) {
  5170. data.envMap = this.envMap.toJSON( meta ).uuid;
  5171. data.reflectivity = this.reflectivity; // Scale behind envMap
  5172. data.refractionRatio = this.refractionRatio;
  5173. if ( this.combine !== undefined ) data.combine = this.combine;
  5174. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5175. }
  5176. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5177. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5178. }
  5179. if ( this.size !== undefined ) data.size = this.size;
  5180. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5181. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5182. if ( this.flatShading === true ) data.flatShading = this.flatShading;
  5183. if ( this.side !== FrontSide ) data.side = this.side;
  5184. if ( this.vertexColors ) data.vertexColors = true;
  5185. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5186. if ( this.transparent === true ) data.transparent = this.transparent;
  5187. data.depthFunc = this.depthFunc;
  5188. data.depthTest = this.depthTest;
  5189. data.depthWrite = this.depthWrite;
  5190. data.stencilWrite = this.stencilWrite;
  5191. data.stencilWriteMask = this.stencilWriteMask;
  5192. data.stencilFunc = this.stencilFunc;
  5193. data.stencilRef = this.stencilRef;
  5194. data.stencilFuncMask = this.stencilFuncMask;
  5195. data.stencilFail = this.stencilFail;
  5196. data.stencilZFail = this.stencilZFail;
  5197. data.stencilZPass = this.stencilZPass;
  5198. // rotation (SpriteMaterial)
  5199. if ( this.rotation && this.rotation !== 0 ) data.rotation = this.rotation;
  5200. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5201. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5202. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5203. if ( this.linewidth && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5204. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5205. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5206. if ( this.scale !== undefined ) data.scale = this.scale;
  5207. if ( this.dithering === true ) data.dithering = true;
  5208. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5209. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = this.premultipliedAlpha;
  5210. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  5211. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5212. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5213. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5214. if ( this.morphTargets === true ) data.morphTargets = true;
  5215. if ( this.morphNormals === true ) data.morphNormals = true;
  5216. if ( this.skinning === true ) data.skinning = true;
  5217. if ( this.visible === false ) data.visible = false;
  5218. if ( this.toneMapped === false ) data.toneMapped = false;
  5219. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  5220. // TODO: Copied from Object3D.toJSON
  5221. function extractFromCache( cache ) {
  5222. const values = [];
  5223. for ( const key in cache ) {
  5224. const data = cache[ key ];
  5225. delete data.metadata;
  5226. values.push( data );
  5227. }
  5228. return values;
  5229. }
  5230. if ( isRoot ) {
  5231. const textures = extractFromCache( meta.textures );
  5232. const images = extractFromCache( meta.images );
  5233. if ( textures.length > 0 ) data.textures = textures;
  5234. if ( images.length > 0 ) data.images = images;
  5235. }
  5236. return data;
  5237. },
  5238. clone: function () {
  5239. return new this.constructor().copy( this );
  5240. },
  5241. copy: function ( source ) {
  5242. this.name = source.name;
  5243. this.fog = source.fog;
  5244. this.blending = source.blending;
  5245. this.side = source.side;
  5246. this.flatShading = source.flatShading;
  5247. this.vertexColors = source.vertexColors;
  5248. this.opacity = source.opacity;
  5249. this.transparent = source.transparent;
  5250. this.blendSrc = source.blendSrc;
  5251. this.blendDst = source.blendDst;
  5252. this.blendEquation = source.blendEquation;
  5253. this.blendSrcAlpha = source.blendSrcAlpha;
  5254. this.blendDstAlpha = source.blendDstAlpha;
  5255. this.blendEquationAlpha = source.blendEquationAlpha;
  5256. this.depthFunc = source.depthFunc;
  5257. this.depthTest = source.depthTest;
  5258. this.depthWrite = source.depthWrite;
  5259. this.stencilWriteMask = source.stencilWriteMask;
  5260. this.stencilFunc = source.stencilFunc;
  5261. this.stencilRef = source.stencilRef;
  5262. this.stencilFuncMask = source.stencilFuncMask;
  5263. this.stencilFail = source.stencilFail;
  5264. this.stencilZFail = source.stencilZFail;
  5265. this.stencilZPass = source.stencilZPass;
  5266. this.stencilWrite = source.stencilWrite;
  5267. const srcPlanes = source.clippingPlanes;
  5268. let dstPlanes = null;
  5269. if ( srcPlanes !== null ) {
  5270. const n = srcPlanes.length;
  5271. dstPlanes = new Array( n );
  5272. for ( let i = 0; i !== n; ++ i ) {
  5273. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5274. }
  5275. }
  5276. this.clippingPlanes = dstPlanes;
  5277. this.clipIntersection = source.clipIntersection;
  5278. this.clipShadows = source.clipShadows;
  5279. this.shadowSide = source.shadowSide;
  5280. this.colorWrite = source.colorWrite;
  5281. this.precision = source.precision;
  5282. this.polygonOffset = source.polygonOffset;
  5283. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5284. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5285. this.dithering = source.dithering;
  5286. this.alphaTest = source.alphaTest;
  5287. this.premultipliedAlpha = source.premultipliedAlpha;
  5288. this.visible = source.visible;
  5289. this.toneMapped = source.toneMapped;
  5290. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5291. return this;
  5292. },
  5293. dispose: function () {
  5294. this.dispatchEvent( { type: 'dispose' } );
  5295. }
  5296. } );
  5297. Object.defineProperty( Material.prototype, 'needsUpdate', {
  5298. set: function ( value ) {
  5299. if ( value === true ) this.version ++;
  5300. }
  5301. } );
  5302. /**
  5303. * parameters = {
  5304. * color: <hex>,
  5305. * opacity: <float>,
  5306. * map: new THREE.Texture( <Image> ),
  5307. *
  5308. * lightMap: new THREE.Texture( <Image> ),
  5309. * lightMapIntensity: <float>
  5310. *
  5311. * aoMap: new THREE.Texture( <Image> ),
  5312. * aoMapIntensity: <float>
  5313. *
  5314. * specularMap: new THREE.Texture( <Image> ),
  5315. *
  5316. * alphaMap: new THREE.Texture( <Image> ),
  5317. *
  5318. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  5319. * combine: THREE.Multiply,
  5320. * reflectivity: <float>,
  5321. * refractionRatio: <float>,
  5322. *
  5323. * depthTest: <bool>,
  5324. * depthWrite: <bool>,
  5325. *
  5326. * wireframe: <boolean>,
  5327. * wireframeLinewidth: <float>,
  5328. *
  5329. * skinning: <bool>,
  5330. * morphTargets: <bool>
  5331. * }
  5332. */
  5333. function MeshBasicMaterial( parameters ) {
  5334. Material.call( this );
  5335. this.type = 'MeshBasicMaterial';
  5336. this.color = new Color( 0xffffff ); // emissive
  5337. this.map = null;
  5338. this.lightMap = null;
  5339. this.lightMapIntensity = 1.0;
  5340. this.aoMap = null;
  5341. this.aoMapIntensity = 1.0;
  5342. this.specularMap = null;
  5343. this.alphaMap = null;
  5344. this.envMap = null;
  5345. this.combine = MultiplyOperation;
  5346. this.reflectivity = 1;
  5347. this.refractionRatio = 0.98;
  5348. this.wireframe = false;
  5349. this.wireframeLinewidth = 1;
  5350. this.wireframeLinecap = 'round';
  5351. this.wireframeLinejoin = 'round';
  5352. this.skinning = false;
  5353. this.morphTargets = false;
  5354. this.setValues( parameters );
  5355. }
  5356. MeshBasicMaterial.prototype = Object.create( Material.prototype );
  5357. MeshBasicMaterial.prototype.constructor = MeshBasicMaterial;
  5358. MeshBasicMaterial.prototype.isMeshBasicMaterial = true;
  5359. MeshBasicMaterial.prototype.copy = function ( source ) {
  5360. Material.prototype.copy.call( this, source );
  5361. this.color.copy( source.color );
  5362. this.map = source.map;
  5363. this.lightMap = source.lightMap;
  5364. this.lightMapIntensity = source.lightMapIntensity;
  5365. this.aoMap = source.aoMap;
  5366. this.aoMapIntensity = source.aoMapIntensity;
  5367. this.specularMap = source.specularMap;
  5368. this.alphaMap = source.alphaMap;
  5369. this.envMap = source.envMap;
  5370. this.combine = source.combine;
  5371. this.reflectivity = source.reflectivity;
  5372. this.refractionRatio = source.refractionRatio;
  5373. this.wireframe = source.wireframe;
  5374. this.wireframeLinewidth = source.wireframeLinewidth;
  5375. this.wireframeLinecap = source.wireframeLinecap;
  5376. this.wireframeLinejoin = source.wireframeLinejoin;
  5377. this.skinning = source.skinning;
  5378. this.morphTargets = source.morphTargets;
  5379. return this;
  5380. };
  5381. const _vector$3 = new Vector3();
  5382. const _vector2$1 = new Vector2();
  5383. function BufferAttribute( array, itemSize, normalized ) {
  5384. if ( Array.isArray( array ) ) {
  5385. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  5386. }
  5387. this.name = '';
  5388. this.array = array;
  5389. this.itemSize = itemSize;
  5390. this.count = array !== undefined ? array.length / itemSize : 0;
  5391. this.normalized = normalized === true;
  5392. this.usage = StaticDrawUsage;
  5393. this.updateRange = { offset: 0, count: - 1 };
  5394. this.version = 0;
  5395. }
  5396. Object.defineProperty( BufferAttribute.prototype, 'needsUpdate', {
  5397. set: function ( value ) {
  5398. if ( value === true ) this.version ++;
  5399. }
  5400. } );
  5401. Object.assign( BufferAttribute.prototype, {
  5402. isBufferAttribute: true,
  5403. onUploadCallback: function () {},
  5404. setUsage: function ( value ) {
  5405. this.usage = value;
  5406. return this;
  5407. },
  5408. copy: function ( source ) {
  5409. this.name = source.name;
  5410. this.array = new source.array.constructor( source.array );
  5411. this.itemSize = source.itemSize;
  5412. this.count = source.count;
  5413. this.normalized = source.normalized;
  5414. this.usage = source.usage;
  5415. return this;
  5416. },
  5417. copyAt: function ( index1, attribute, index2 ) {
  5418. index1 *= this.itemSize;
  5419. index2 *= attribute.itemSize;
  5420. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  5421. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5422. }
  5423. return this;
  5424. },
  5425. copyArray: function ( array ) {
  5426. this.array.set( array );
  5427. return this;
  5428. },
  5429. copyColorsArray: function ( colors ) {
  5430. const array = this.array;
  5431. let offset = 0;
  5432. for ( let i = 0, l = colors.length; i < l; i ++ ) {
  5433. let color = colors[ i ];
  5434. if ( color === undefined ) {
  5435. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5436. color = new Color();
  5437. }
  5438. array[ offset ++ ] = color.r;
  5439. array[ offset ++ ] = color.g;
  5440. array[ offset ++ ] = color.b;
  5441. }
  5442. return this;
  5443. },
  5444. copyVector2sArray: function ( vectors ) {
  5445. const array = this.array;
  5446. let offset = 0;
  5447. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5448. let vector = vectors[ i ];
  5449. if ( vector === undefined ) {
  5450. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5451. vector = new Vector2();
  5452. }
  5453. array[ offset ++ ] = vector.x;
  5454. array[ offset ++ ] = vector.y;
  5455. }
  5456. return this;
  5457. },
  5458. copyVector3sArray: function ( vectors ) {
  5459. const array = this.array;
  5460. let offset = 0;
  5461. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5462. let vector = vectors[ i ];
  5463. if ( vector === undefined ) {
  5464. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5465. vector = new Vector3();
  5466. }
  5467. array[ offset ++ ] = vector.x;
  5468. array[ offset ++ ] = vector.y;
  5469. array[ offset ++ ] = vector.z;
  5470. }
  5471. return this;
  5472. },
  5473. copyVector4sArray: function ( vectors ) {
  5474. const array = this.array;
  5475. let offset = 0;
  5476. for ( let i = 0, l = vectors.length; i < l; i ++ ) {
  5477. let vector = vectors[ i ];
  5478. if ( vector === undefined ) {
  5479. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5480. vector = new Vector4();
  5481. }
  5482. array[ offset ++ ] = vector.x;
  5483. array[ offset ++ ] = vector.y;
  5484. array[ offset ++ ] = vector.z;
  5485. array[ offset ++ ] = vector.w;
  5486. }
  5487. return this;
  5488. },
  5489. applyMatrix3: function ( m ) {
  5490. if ( this.itemSize === 2 ) {
  5491. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5492. _vector2$1.fromBufferAttribute( this, i );
  5493. _vector2$1.applyMatrix3( m );
  5494. this.setXY( i, _vector2$1.x, _vector2$1.y );
  5495. }
  5496. } else if ( this.itemSize === 3 ) {
  5497. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5498. _vector$3.fromBufferAttribute( this, i );
  5499. _vector$3.applyMatrix3( m );
  5500. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5501. }
  5502. }
  5503. return this;
  5504. },
  5505. applyMatrix4: function ( m ) {
  5506. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5507. _vector$3.x = this.getX( i );
  5508. _vector$3.y = this.getY( i );
  5509. _vector$3.z = this.getZ( i );
  5510. _vector$3.applyMatrix4( m );
  5511. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5512. }
  5513. return this;
  5514. },
  5515. applyNormalMatrix: function ( m ) {
  5516. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5517. _vector$3.x = this.getX( i );
  5518. _vector$3.y = this.getY( i );
  5519. _vector$3.z = this.getZ( i );
  5520. _vector$3.applyNormalMatrix( m );
  5521. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5522. }
  5523. return this;
  5524. },
  5525. transformDirection: function ( m ) {
  5526. for ( let i = 0, l = this.count; i < l; i ++ ) {
  5527. _vector$3.x = this.getX( i );
  5528. _vector$3.y = this.getY( i );
  5529. _vector$3.z = this.getZ( i );
  5530. _vector$3.transformDirection( m );
  5531. this.setXYZ( i, _vector$3.x, _vector$3.y, _vector$3.z );
  5532. }
  5533. return this;
  5534. },
  5535. set: function ( value, offset = 0 ) {
  5536. this.array.set( value, offset );
  5537. return this;
  5538. },
  5539. getX: function ( index ) {
  5540. return this.array[ index * this.itemSize ];
  5541. },
  5542. setX: function ( index, x ) {
  5543. this.array[ index * this.itemSize ] = x;
  5544. return this;
  5545. },
  5546. getY: function ( index ) {
  5547. return this.array[ index * this.itemSize + 1 ];
  5548. },
  5549. setY: function ( index, y ) {
  5550. this.array[ index * this.itemSize + 1 ] = y;
  5551. return this;
  5552. },
  5553. getZ: function ( index ) {
  5554. return this.array[ index * this.itemSize + 2 ];
  5555. },
  5556. setZ: function ( index, z ) {
  5557. this.array[ index * this.itemSize + 2 ] = z;
  5558. return this;
  5559. },
  5560. getW: function ( index ) {
  5561. return this.array[ index * this.itemSize + 3 ];
  5562. },
  5563. setW: function ( index, w ) {
  5564. this.array[ index * this.itemSize + 3 ] = w;
  5565. return this;
  5566. },
  5567. setXY: function ( index, x, y ) {
  5568. index *= this.itemSize;
  5569. this.array[ index + 0 ] = x;
  5570. this.array[ index + 1 ] = y;
  5571. return this;
  5572. },
  5573. setXYZ: function ( index, x, y, z ) {
  5574. index *= this.itemSize;
  5575. this.array[ index + 0 ] = x;
  5576. this.array[ index + 1 ] = y;
  5577. this.array[ index + 2 ] = z;
  5578. return this;
  5579. },
  5580. setXYZW: function ( index, x, y, z, w ) {
  5581. index *= this.itemSize;
  5582. this.array[ index + 0 ] = x;
  5583. this.array[ index + 1 ] = y;
  5584. this.array[ index + 2 ] = z;
  5585. this.array[ index + 3 ] = w;
  5586. return this;
  5587. },
  5588. onUpload: function ( callback ) {
  5589. this.onUploadCallback = callback;
  5590. return this;
  5591. },
  5592. clone: function () {
  5593. return new this.constructor( this.array, this.itemSize ).copy( this );
  5594. },
  5595. toJSON: function () {
  5596. return {
  5597. itemSize: this.itemSize,
  5598. type: this.array.constructor.name,
  5599. array: Array.prototype.slice.call( this.array ),
  5600. normalized: this.normalized
  5601. };
  5602. }
  5603. } );
  5604. //
  5605. function Int8BufferAttribute( array, itemSize, normalized ) {
  5606. BufferAttribute.call( this, new Int8Array( array ), itemSize, normalized );
  5607. }
  5608. Int8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5609. Int8BufferAttribute.prototype.constructor = Int8BufferAttribute;
  5610. function Uint8BufferAttribute( array, itemSize, normalized ) {
  5611. BufferAttribute.call( this, new Uint8Array( array ), itemSize, normalized );
  5612. }
  5613. Uint8BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5614. Uint8BufferAttribute.prototype.constructor = Uint8BufferAttribute;
  5615. function Uint8ClampedBufferAttribute( array, itemSize, normalized ) {
  5616. BufferAttribute.call( this, new Uint8ClampedArray( array ), itemSize, normalized );
  5617. }
  5618. Uint8ClampedBufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5619. Uint8ClampedBufferAttribute.prototype.constructor = Uint8ClampedBufferAttribute;
  5620. function Int16BufferAttribute( array, itemSize, normalized ) {
  5621. BufferAttribute.call( this, new Int16Array( array ), itemSize, normalized );
  5622. }
  5623. Int16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5624. Int16BufferAttribute.prototype.constructor = Int16BufferAttribute;
  5625. function Uint16BufferAttribute( array, itemSize, normalized ) {
  5626. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5627. }
  5628. Uint16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5629. Uint16BufferAttribute.prototype.constructor = Uint16BufferAttribute;
  5630. function Int32BufferAttribute( array, itemSize, normalized ) {
  5631. BufferAttribute.call( this, new Int32Array( array ), itemSize, normalized );
  5632. }
  5633. Int32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5634. Int32BufferAttribute.prototype.constructor = Int32BufferAttribute;
  5635. function Uint32BufferAttribute( array, itemSize, normalized ) {
  5636. BufferAttribute.call( this, new Uint32Array( array ), itemSize, normalized );
  5637. }
  5638. Uint32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5639. Uint32BufferAttribute.prototype.constructor = Uint32BufferAttribute;
  5640. function Float16BufferAttribute( array, itemSize, normalized ) {
  5641. BufferAttribute.call( this, new Uint16Array( array ), itemSize, normalized );
  5642. }
  5643. Float16BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5644. Float16BufferAttribute.prototype.constructor = Float16BufferAttribute;
  5645. Float16BufferAttribute.prototype.isFloat16BufferAttribute = true;
  5646. function Float32BufferAttribute( array, itemSize, normalized ) {
  5647. BufferAttribute.call( this, new Float32Array( array ), itemSize, normalized );
  5648. }
  5649. Float32BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5650. Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
  5651. function Float64BufferAttribute( array, itemSize, normalized ) {
  5652. BufferAttribute.call( this, new Float64Array( array ), itemSize, normalized );
  5653. }
  5654. Float64BufferAttribute.prototype = Object.create( BufferAttribute.prototype );
  5655. Float64BufferAttribute.prototype.constructor = Float64BufferAttribute;
  5656. class DirectGeometry {
  5657. constructor() {
  5658. this.vertices = [];
  5659. this.normals = [];
  5660. this.colors = [];
  5661. this.uvs = [];
  5662. this.uvs2 = [];
  5663. this.groups = [];
  5664. this.morphTargets = {};
  5665. this.skinWeights = [];
  5666. this.skinIndices = [];
  5667. // this.lineDistances = [];
  5668. this.boundingBox = null;
  5669. this.boundingSphere = null;
  5670. // update flags
  5671. this.verticesNeedUpdate = false;
  5672. this.normalsNeedUpdate = false;
  5673. this.colorsNeedUpdate = false;
  5674. this.uvsNeedUpdate = false;
  5675. this.groupsNeedUpdate = false;
  5676. }
  5677. computeGroups( geometry ) {
  5678. const groups = [];
  5679. let group, i;
  5680. let materialIndex = undefined;
  5681. const faces = geometry.faces;
  5682. for ( i = 0; i < faces.length; i ++ ) {
  5683. const face = faces[ i ];
  5684. // materials
  5685. if ( face.materialIndex !== materialIndex ) {
  5686. materialIndex = face.materialIndex;
  5687. if ( group !== undefined ) {
  5688. group.count = ( i * 3 ) - group.start;
  5689. groups.push( group );
  5690. }
  5691. group = {
  5692. start: i * 3,
  5693. materialIndex: materialIndex
  5694. };
  5695. }
  5696. }
  5697. if ( group !== undefined ) {
  5698. group.count = ( i * 3 ) - group.start;
  5699. groups.push( group );
  5700. }
  5701. this.groups = groups;
  5702. }
  5703. fromGeometry( geometry ) {
  5704. const faces = geometry.faces;
  5705. const vertices = geometry.vertices;
  5706. const faceVertexUvs = geometry.faceVertexUvs;
  5707. const hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5708. const hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5709. // morphs
  5710. const morphTargets = geometry.morphTargets;
  5711. const morphTargetsLength = morphTargets.length;
  5712. let morphTargetsPosition;
  5713. if ( morphTargetsLength > 0 ) {
  5714. morphTargetsPosition = [];
  5715. for ( let i = 0; i < morphTargetsLength; i ++ ) {
  5716. morphTargetsPosition[ i ] = {
  5717. name: morphTargets[ i ].name,
  5718. data: []
  5719. };
  5720. }
  5721. this.morphTargets.position = morphTargetsPosition;
  5722. }
  5723. const morphNormals = geometry.morphNormals;
  5724. const morphNormalsLength = morphNormals.length;
  5725. let morphTargetsNormal;
  5726. if ( morphNormalsLength > 0 ) {
  5727. morphTargetsNormal = [];
  5728. for ( let i = 0; i < morphNormalsLength; i ++ ) {
  5729. morphTargetsNormal[ i ] = {
  5730. name: morphNormals[ i ].name,
  5731. data: []
  5732. };
  5733. }
  5734. this.morphTargets.normal = morphTargetsNormal;
  5735. }
  5736. // skins
  5737. const skinIndices = geometry.skinIndices;
  5738. const skinWeights = geometry.skinWeights;
  5739. const hasSkinIndices = skinIndices.length === vertices.length;
  5740. const hasSkinWeights = skinWeights.length === vertices.length;
  5741. //
  5742. if ( vertices.length > 0 && faces.length === 0 ) {
  5743. console.error( 'THREE.DirectGeometry: Faceless geometries are not supported.' );
  5744. }
  5745. for ( let i = 0; i < faces.length; i ++ ) {
  5746. const face = faces[ i ];
  5747. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  5748. const vertexNormals = face.vertexNormals;
  5749. if ( vertexNormals.length === 3 ) {
  5750. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  5751. } else {
  5752. const normal = face.normal;
  5753. this.normals.push( normal, normal, normal );
  5754. }
  5755. const vertexColors = face.vertexColors;
  5756. if ( vertexColors.length === 3 ) {
  5757. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  5758. } else {
  5759. const color = face.color;
  5760. this.colors.push( color, color, color );
  5761. }
  5762. if ( hasFaceVertexUv === true ) {
  5763. const vertexUvs = faceVertexUvs[ 0 ][ i ];
  5764. if ( vertexUvs !== undefined ) {
  5765. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5766. } else {
  5767. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  5768. this.uvs.push( new Vector2(), new Vector2(), new Vector2() );
  5769. }
  5770. }
  5771. if ( hasFaceVertexUv2 === true ) {
  5772. const vertexUvs = faceVertexUvs[ 1 ][ i ];
  5773. if ( vertexUvs !== undefined ) {
  5774. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  5775. } else {
  5776. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  5777. this.uvs2.push( new Vector2(), new Vector2(), new Vector2() );
  5778. }
  5779. }
  5780. // morphs
  5781. for ( let j = 0; j < morphTargetsLength; j ++ ) {
  5782. const morphTarget = morphTargets[ j ].vertices;
  5783. morphTargetsPosition[ j ].data.push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  5784. }
  5785. for ( let j = 0; j < morphNormalsLength; j ++ ) {
  5786. const morphNormal = morphNormals[ j ].vertexNormals[ i ];
  5787. morphTargetsNormal[ j ].data.push( morphNormal.a, morphNormal.b, morphNormal.c );
  5788. }
  5789. // skins
  5790. if ( hasSkinIndices ) {
  5791. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  5792. }
  5793. if ( hasSkinWeights ) {
  5794. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  5795. }
  5796. }
  5797. this.computeGroups( geometry );
  5798. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  5799. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  5800. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  5801. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  5802. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  5803. if ( geometry.boundingSphere !== null ) {
  5804. this.boundingSphere = geometry.boundingSphere.clone();
  5805. }
  5806. if ( geometry.boundingBox !== null ) {
  5807. this.boundingBox = geometry.boundingBox.clone();
  5808. }
  5809. return this;
  5810. }
  5811. }
  5812. function arrayMax( array ) {
  5813. if ( array.length === 0 ) return - Infinity;
  5814. let max = array[ 0 ];
  5815. for ( let i = 1, l = array.length; i < l; ++ i ) {
  5816. if ( array[ i ] > max ) max = array[ i ];
  5817. }
  5818. return max;
  5819. }
  5820. const TYPED_ARRAYS = {
  5821. Int8Array: Int8Array,
  5822. Uint8Array: Uint8Array,
  5823. // Workaround for IE11 pre KB2929437. See #11440
  5824. Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
  5825. Int16Array: Int16Array,
  5826. Uint16Array: Uint16Array,
  5827. Int32Array: Int32Array,
  5828. Uint32Array: Uint32Array,
  5829. Float32Array: Float32Array,
  5830. Float64Array: Float64Array
  5831. };
  5832. function getTypedArray( type, buffer ) {
  5833. return new TYPED_ARRAYS[ type ]( buffer );
  5834. }
  5835. let _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
  5836. const _m1$2 = new Matrix4();
  5837. const _obj = new Object3D();
  5838. const _offset = new Vector3();
  5839. const _box$2 = new Box3();
  5840. const _boxMorphTargets = new Box3();
  5841. const _vector$4 = new Vector3();
  5842. function BufferGeometry() {
  5843. Object.defineProperty( this, 'id', { value: _bufferGeometryId += 2 } );
  5844. this.uuid = MathUtils.generateUUID();
  5845. this.name = '';
  5846. this.type = 'BufferGeometry';
  5847. this.index = null;
  5848. this.attributes = {};
  5849. this.morphAttributes = {};
  5850. this.morphTargetsRelative = false;
  5851. this.groups = [];
  5852. this.boundingBox = null;
  5853. this.boundingSphere = null;
  5854. this.drawRange = { start: 0, count: Infinity };
  5855. this.userData = {};
  5856. }
  5857. BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  5858. constructor: BufferGeometry,
  5859. isBufferGeometry: true,
  5860. getIndex: function () {
  5861. return this.index;
  5862. },
  5863. setIndex: function ( index ) {
  5864. if ( Array.isArray( index ) ) {
  5865. this.index = new ( arrayMax( index ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  5866. } else {
  5867. this.index = index;
  5868. }
  5869. return this;
  5870. },
  5871. getAttribute: function ( name ) {
  5872. return this.attributes[ name ];
  5873. },
  5874. setAttribute: function ( name, attribute ) {
  5875. this.attributes[ name ] = attribute;
  5876. return this;
  5877. },
  5878. deleteAttribute: function ( name ) {
  5879. delete this.attributes[ name ];
  5880. return this;
  5881. },
  5882. hasAttribute: function ( name ) {
  5883. return this.attributes[ name ] !== undefined;
  5884. },
  5885. addGroup: function ( start, count, materialIndex = 0 ) {
  5886. this.groups.push( {
  5887. start: start,
  5888. count: count,
  5889. materialIndex: materialIndex
  5890. } );
  5891. },
  5892. clearGroups: function () {
  5893. this.groups = [];
  5894. },
  5895. setDrawRange: function ( start, count ) {
  5896. this.drawRange.start = start;
  5897. this.drawRange.count = count;
  5898. },
  5899. applyMatrix4: function ( matrix ) {
  5900. const position = this.attributes.position;
  5901. if ( position !== undefined ) {
  5902. position.applyMatrix4( matrix );
  5903. position.needsUpdate = true;
  5904. }
  5905. const normal = this.attributes.normal;
  5906. if ( normal !== undefined ) {
  5907. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  5908. normal.applyNormalMatrix( normalMatrix );
  5909. normal.needsUpdate = true;
  5910. }
  5911. const tangent = this.attributes.tangent;
  5912. if ( tangent !== undefined ) {
  5913. tangent.transformDirection( matrix );
  5914. tangent.needsUpdate = true;
  5915. }
  5916. if ( this.boundingBox !== null ) {
  5917. this.computeBoundingBox();
  5918. }
  5919. if ( this.boundingSphere !== null ) {
  5920. this.computeBoundingSphere();
  5921. }
  5922. return this;
  5923. },
  5924. rotateX: function ( angle ) {
  5925. // rotate geometry around world x-axis
  5926. _m1$2.makeRotationX( angle );
  5927. this.applyMatrix4( _m1$2 );
  5928. return this;
  5929. },
  5930. rotateY: function ( angle ) {
  5931. // rotate geometry around world y-axis
  5932. _m1$2.makeRotationY( angle );
  5933. this.applyMatrix4( _m1$2 );
  5934. return this;
  5935. },
  5936. rotateZ: function ( angle ) {
  5937. // rotate geometry around world z-axis
  5938. _m1$2.makeRotationZ( angle );
  5939. this.applyMatrix4( _m1$2 );
  5940. return this;
  5941. },
  5942. translate: function ( x, y, z ) {
  5943. // translate geometry
  5944. _m1$2.makeTranslation( x, y, z );
  5945. this.applyMatrix4( _m1$2 );
  5946. return this;
  5947. },
  5948. scale: function ( x, y, z ) {
  5949. // scale geometry
  5950. _m1$2.makeScale( x, y, z );
  5951. this.applyMatrix4( _m1$2 );
  5952. return this;
  5953. },
  5954. lookAt: function ( vector ) {
  5955. _obj.lookAt( vector );
  5956. _obj.updateMatrix();
  5957. this.applyMatrix4( _obj.matrix );
  5958. return this;
  5959. },
  5960. center: function () {
  5961. this.computeBoundingBox();
  5962. this.boundingBox.getCenter( _offset ).negate();
  5963. this.translate( _offset.x, _offset.y, _offset.z );
  5964. return this;
  5965. },
  5966. setFromObject: function ( object ) {
  5967. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  5968. const geometry = object.geometry;
  5969. if ( object.isPoints || object.isLine ) {
  5970. const positions = new Float32BufferAttribute( geometry.vertices.length * 3, 3 );
  5971. const colors = new Float32BufferAttribute( geometry.colors.length * 3, 3 );
  5972. this.setAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  5973. this.setAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  5974. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  5975. const lineDistances = new Float32BufferAttribute( geometry.lineDistances.length, 1 );
  5976. this.setAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  5977. }
  5978. if ( geometry.boundingSphere !== null ) {
  5979. this.boundingSphere = geometry.boundingSphere.clone();
  5980. }
  5981. if ( geometry.boundingBox !== null ) {
  5982. this.boundingBox = geometry.boundingBox.clone();
  5983. }
  5984. } else if ( object.isMesh ) {
  5985. if ( geometry && geometry.isGeometry ) {
  5986. this.fromGeometry( geometry );
  5987. }
  5988. }
  5989. return this;
  5990. },
  5991. setFromPoints: function ( points ) {
  5992. const position = [];
  5993. for ( let i = 0, l = points.length; i < l; i ++ ) {
  5994. const point = points[ i ];
  5995. position.push( point.x, point.y, point.z || 0 );
  5996. }
  5997. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  5998. return this;
  5999. },
  6000. updateFromObject: function ( object ) {
  6001. let geometry = object.geometry;
  6002. if ( object.isMesh ) {
  6003. let direct = geometry.__directGeometry;
  6004. if ( geometry.elementsNeedUpdate === true ) {
  6005. direct = undefined;
  6006. geometry.elementsNeedUpdate = false;
  6007. }
  6008. if ( direct === undefined ) {
  6009. return this.fromGeometry( geometry );
  6010. }
  6011. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6012. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6013. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6014. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6015. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6016. geometry.verticesNeedUpdate = false;
  6017. geometry.normalsNeedUpdate = false;
  6018. geometry.colorsNeedUpdate = false;
  6019. geometry.uvsNeedUpdate = false;
  6020. geometry.groupsNeedUpdate = false;
  6021. geometry = direct;
  6022. }
  6023. if ( geometry.verticesNeedUpdate === true ) {
  6024. const attribute = this.attributes.position;
  6025. if ( attribute !== undefined ) {
  6026. attribute.copyVector3sArray( geometry.vertices );
  6027. attribute.needsUpdate = true;
  6028. }
  6029. geometry.verticesNeedUpdate = false;
  6030. }
  6031. if ( geometry.normalsNeedUpdate === true ) {
  6032. const attribute = this.attributes.normal;
  6033. if ( attribute !== undefined ) {
  6034. attribute.copyVector3sArray( geometry.normals );
  6035. attribute.needsUpdate = true;
  6036. }
  6037. geometry.normalsNeedUpdate = false;
  6038. }
  6039. if ( geometry.colorsNeedUpdate === true ) {
  6040. const attribute = this.attributes.color;
  6041. if ( attribute !== undefined ) {
  6042. attribute.copyColorsArray( geometry.colors );
  6043. attribute.needsUpdate = true;
  6044. }
  6045. geometry.colorsNeedUpdate = false;
  6046. }
  6047. if ( geometry.uvsNeedUpdate ) {
  6048. const attribute = this.attributes.uv;
  6049. if ( attribute !== undefined ) {
  6050. attribute.copyVector2sArray( geometry.uvs );
  6051. attribute.needsUpdate = true;
  6052. }
  6053. geometry.uvsNeedUpdate = false;
  6054. }
  6055. if ( geometry.lineDistancesNeedUpdate ) {
  6056. const attribute = this.attributes.lineDistance;
  6057. if ( attribute !== undefined ) {
  6058. attribute.copyArray( geometry.lineDistances );
  6059. attribute.needsUpdate = true;
  6060. }
  6061. geometry.lineDistancesNeedUpdate = false;
  6062. }
  6063. if ( geometry.groupsNeedUpdate ) {
  6064. geometry.computeGroups( object.geometry );
  6065. this.groups = geometry.groups;
  6066. geometry.groupsNeedUpdate = false;
  6067. }
  6068. return this;
  6069. },
  6070. fromGeometry: function ( geometry ) {
  6071. geometry.__directGeometry = new DirectGeometry().fromGeometry( geometry );
  6072. return this.fromDirectGeometry( geometry.__directGeometry );
  6073. },
  6074. fromDirectGeometry: function ( geometry ) {
  6075. const positions = new Float32Array( geometry.vertices.length * 3 );
  6076. this.setAttribute( 'position', new BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6077. if ( geometry.normals.length > 0 ) {
  6078. const normals = new Float32Array( geometry.normals.length * 3 );
  6079. this.setAttribute( 'normal', new BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6080. }
  6081. if ( geometry.colors.length > 0 ) {
  6082. const colors = new Float32Array( geometry.colors.length * 3 );
  6083. this.setAttribute( 'color', new BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6084. }
  6085. if ( geometry.uvs.length > 0 ) {
  6086. const uvs = new Float32Array( geometry.uvs.length * 2 );
  6087. this.setAttribute( 'uv', new BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6088. }
  6089. if ( geometry.uvs2.length > 0 ) {
  6090. const uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6091. this.setAttribute( 'uv2', new BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6092. }
  6093. // groups
  6094. this.groups = geometry.groups;
  6095. // morphs
  6096. for ( const name in geometry.morphTargets ) {
  6097. const array = [];
  6098. const morphTargets = geometry.morphTargets[ name ];
  6099. for ( let i = 0, l = morphTargets.length; i < l; i ++ ) {
  6100. const morphTarget = morphTargets[ i ];
  6101. const attribute = new Float32BufferAttribute( morphTarget.data.length * 3, 3 );
  6102. attribute.name = morphTarget.name;
  6103. array.push( attribute.copyVector3sArray( morphTarget.data ) );
  6104. }
  6105. this.morphAttributes[ name ] = array;
  6106. }
  6107. // skinning
  6108. if ( geometry.skinIndices.length > 0 ) {
  6109. const skinIndices = new Float32BufferAttribute( geometry.skinIndices.length * 4, 4 );
  6110. this.setAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6111. }
  6112. if ( geometry.skinWeights.length > 0 ) {
  6113. const skinWeights = new Float32BufferAttribute( geometry.skinWeights.length * 4, 4 );
  6114. this.setAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6115. }
  6116. //
  6117. if ( geometry.boundingSphere !== null ) {
  6118. this.boundingSphere = geometry.boundingSphere.clone();
  6119. }
  6120. if ( geometry.boundingBox !== null ) {
  6121. this.boundingBox = geometry.boundingBox.clone();
  6122. }
  6123. return this;
  6124. },
  6125. computeBoundingBox: function () {
  6126. if ( this.boundingBox === null ) {
  6127. this.boundingBox = new Box3();
  6128. }
  6129. const position = this.attributes.position;
  6130. const morphAttributesPosition = this.morphAttributes.position;
  6131. if ( position && position.isGLBufferAttribute ) {
  6132. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this );
  6133. this.boundingBox.set(
  6134. new Vector3( - Infinity, - Infinity, - Infinity ),
  6135. new Vector3( + Infinity, + Infinity, + Infinity )
  6136. );
  6137. return;
  6138. }
  6139. if ( position !== undefined ) {
  6140. this.boundingBox.setFromBufferAttribute( position );
  6141. // process morph attributes if present
  6142. if ( morphAttributesPosition ) {
  6143. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6144. const morphAttribute = morphAttributesPosition[ i ];
  6145. _box$2.setFromBufferAttribute( morphAttribute );
  6146. if ( this.morphTargetsRelative ) {
  6147. _vector$4.addVectors( this.boundingBox.min, _box$2.min );
  6148. this.boundingBox.expandByPoint( _vector$4 );
  6149. _vector$4.addVectors( this.boundingBox.max, _box$2.max );
  6150. this.boundingBox.expandByPoint( _vector$4 );
  6151. } else {
  6152. this.boundingBox.expandByPoint( _box$2.min );
  6153. this.boundingBox.expandByPoint( _box$2.max );
  6154. }
  6155. }
  6156. }
  6157. } else {
  6158. this.boundingBox.makeEmpty();
  6159. }
  6160. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6161. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6162. }
  6163. },
  6164. computeBoundingSphere: function () {
  6165. if ( this.boundingSphere === null ) {
  6166. this.boundingSphere = new Sphere();
  6167. }
  6168. const position = this.attributes.position;
  6169. const morphAttributesPosition = this.morphAttributes.position;
  6170. if ( position && position.isGLBufferAttribute ) {
  6171. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this );
  6172. this.boundingSphere.set( new Vector3(), Infinity );
  6173. return;
  6174. }
  6175. if ( position ) {
  6176. // first, find the center of the bounding sphere
  6177. const center = this.boundingSphere.center;
  6178. _box$2.setFromBufferAttribute( position );
  6179. // process morph attributes if present
  6180. if ( morphAttributesPosition ) {
  6181. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6182. const morphAttribute = morphAttributesPosition[ i ];
  6183. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6184. if ( this.morphTargetsRelative ) {
  6185. _vector$4.addVectors( _box$2.min, _boxMorphTargets.min );
  6186. _box$2.expandByPoint( _vector$4 );
  6187. _vector$4.addVectors( _box$2.max, _boxMorphTargets.max );
  6188. _box$2.expandByPoint( _vector$4 );
  6189. } else {
  6190. _box$2.expandByPoint( _boxMorphTargets.min );
  6191. _box$2.expandByPoint( _boxMorphTargets.max );
  6192. }
  6193. }
  6194. }
  6195. _box$2.getCenter( center );
  6196. // second, try to find a boundingSphere with a radius smaller than the
  6197. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6198. let maxRadiusSq = 0;
  6199. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6200. _vector$4.fromBufferAttribute( position, i );
  6201. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6202. }
  6203. // process morph attributes if present
  6204. if ( morphAttributesPosition ) {
  6205. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6206. const morphAttribute = morphAttributesPosition[ i ];
  6207. const morphTargetsRelative = this.morphTargetsRelative;
  6208. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6209. _vector$4.fromBufferAttribute( morphAttribute, j );
  6210. if ( morphTargetsRelative ) {
  6211. _offset.fromBufferAttribute( position, j );
  6212. _vector$4.add( _offset );
  6213. }
  6214. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$4 ) );
  6215. }
  6216. }
  6217. }
  6218. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6219. if ( isNaN( this.boundingSphere.radius ) ) {
  6220. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6221. }
  6222. }
  6223. },
  6224. computeFaceNormals: function () {
  6225. // backwards compatibility
  6226. },
  6227. computeVertexNormals: function () {
  6228. const index = this.index;
  6229. const positionAttribute = this.getAttribute( 'position' );
  6230. if ( positionAttribute !== undefined ) {
  6231. let normalAttribute = this.getAttribute( 'normal' );
  6232. if ( normalAttribute === undefined ) {
  6233. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6234. this.setAttribute( 'normal', normalAttribute );
  6235. } else {
  6236. // reset existing normals to zero
  6237. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6238. normalAttribute.setXYZ( i, 0, 0, 0 );
  6239. }
  6240. }
  6241. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6242. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6243. const cb = new Vector3(), ab = new Vector3();
  6244. // indexed elements
  6245. if ( index ) {
  6246. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6247. const vA = index.getX( i + 0 );
  6248. const vB = index.getX( i + 1 );
  6249. const vC = index.getX( i + 2 );
  6250. pA.fromBufferAttribute( positionAttribute, vA );
  6251. pB.fromBufferAttribute( positionAttribute, vB );
  6252. pC.fromBufferAttribute( positionAttribute, vC );
  6253. cb.subVectors( pC, pB );
  6254. ab.subVectors( pA, pB );
  6255. cb.cross( ab );
  6256. nA.fromBufferAttribute( normalAttribute, vA );
  6257. nB.fromBufferAttribute( normalAttribute, vB );
  6258. nC.fromBufferAttribute( normalAttribute, vC );
  6259. nA.add( cb );
  6260. nB.add( cb );
  6261. nC.add( cb );
  6262. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6263. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6264. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6265. }
  6266. } else {
  6267. // non-indexed elements (unconnected triangle soup)
  6268. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6269. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6270. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6271. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6272. cb.subVectors( pC, pB );
  6273. ab.subVectors( pA, pB );
  6274. cb.cross( ab );
  6275. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6276. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6277. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6278. }
  6279. }
  6280. this.normalizeNormals();
  6281. normalAttribute.needsUpdate = true;
  6282. }
  6283. },
  6284. merge: function ( geometry, offset ) {
  6285. if ( ! ( geometry && geometry.isBufferGeometry ) ) {
  6286. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6287. return;
  6288. }
  6289. if ( offset === undefined ) {
  6290. offset = 0;
  6291. console.warn(
  6292. 'THREE.BufferGeometry.merge(): Overwriting original geometry, starting at offset=0. '
  6293. + 'Use BufferGeometryUtils.mergeBufferGeometries() for lossless merge.'
  6294. );
  6295. }
  6296. const attributes = this.attributes;
  6297. for ( const key in attributes ) {
  6298. if ( geometry.attributes[ key ] === undefined ) continue;
  6299. const attribute1 = attributes[ key ];
  6300. const attributeArray1 = attribute1.array;
  6301. const attribute2 = geometry.attributes[ key ];
  6302. const attributeArray2 = attribute2.array;
  6303. const attributeOffset = attribute2.itemSize * offset;
  6304. const length = Math.min( attributeArray2.length, attributeArray1.length - attributeOffset );
  6305. for ( let i = 0, j = attributeOffset; i < length; i ++, j ++ ) {
  6306. attributeArray1[ j ] = attributeArray2[ i ];
  6307. }
  6308. }
  6309. return this;
  6310. },
  6311. normalizeNormals: function () {
  6312. const normals = this.attributes.normal;
  6313. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6314. _vector$4.fromBufferAttribute( normals, i );
  6315. _vector$4.normalize();
  6316. normals.setXYZ( i, _vector$4.x, _vector$4.y, _vector$4.z );
  6317. }
  6318. },
  6319. toNonIndexed: function () {
  6320. function convertBufferAttribute( attribute, indices ) {
  6321. const array = attribute.array;
  6322. const itemSize = attribute.itemSize;
  6323. const normalized = attribute.normalized;
  6324. const array2 = new array.constructor( indices.length * itemSize );
  6325. let index = 0, index2 = 0;
  6326. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6327. index = indices[ i ] * itemSize;
  6328. for ( let j = 0; j < itemSize; j ++ ) {
  6329. array2[ index2 ++ ] = array[ index ++ ];
  6330. }
  6331. }
  6332. return new BufferAttribute( array2, itemSize, normalized );
  6333. }
  6334. //
  6335. if ( this.index === null ) {
  6336. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6337. return this;
  6338. }
  6339. const geometry2 = new BufferGeometry();
  6340. const indices = this.index.array;
  6341. const attributes = this.attributes;
  6342. // attributes
  6343. for ( const name in attributes ) {
  6344. const attribute = attributes[ name ];
  6345. const newAttribute = convertBufferAttribute( attribute, indices );
  6346. geometry2.setAttribute( name, newAttribute );
  6347. }
  6348. // morph attributes
  6349. const morphAttributes = this.morphAttributes;
  6350. for ( const name in morphAttributes ) {
  6351. const morphArray = [];
  6352. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6353. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6354. const attribute = morphAttribute[ i ];
  6355. const newAttribute = convertBufferAttribute( attribute, indices );
  6356. morphArray.push( newAttribute );
  6357. }
  6358. geometry2.morphAttributes[ name ] = morphArray;
  6359. }
  6360. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6361. // groups
  6362. const groups = this.groups;
  6363. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6364. const group = groups[ i ];
  6365. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6366. }
  6367. return geometry2;
  6368. },
  6369. toJSON: function () {
  6370. const data = {
  6371. metadata: {
  6372. version: 4.5,
  6373. type: 'BufferGeometry',
  6374. generator: 'BufferGeometry.toJSON'
  6375. }
  6376. };
  6377. // standard BufferGeometry serialization
  6378. data.uuid = this.uuid;
  6379. data.type = this.type;
  6380. if ( this.name !== '' ) data.name = this.name;
  6381. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6382. if ( this.parameters !== undefined ) {
  6383. const parameters = this.parameters;
  6384. for ( const key in parameters ) {
  6385. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6386. }
  6387. return data;
  6388. }
  6389. data.data = { attributes: {} };
  6390. const index = this.index;
  6391. if ( index !== null ) {
  6392. data.data.index = {
  6393. type: index.array.constructor.name,
  6394. array: Array.prototype.slice.call( index.array )
  6395. };
  6396. }
  6397. const attributes = this.attributes;
  6398. for ( const key in attributes ) {
  6399. const attribute = attributes[ key ];
  6400. const attributeData = attribute.toJSON( data.data );
  6401. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6402. data.data.attributes[ key ] = attributeData;
  6403. }
  6404. const morphAttributes = {};
  6405. let hasMorphAttributes = false;
  6406. for ( const key in this.morphAttributes ) {
  6407. const attributeArray = this.morphAttributes[ key ];
  6408. const array = [];
  6409. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6410. const attribute = attributeArray[ i ];
  6411. const attributeData = attribute.toJSON( data.data );
  6412. if ( attribute.name !== '' ) attributeData.name = attribute.name;
  6413. array.push( attributeData );
  6414. }
  6415. if ( array.length > 0 ) {
  6416. morphAttributes[ key ] = array;
  6417. hasMorphAttributes = true;
  6418. }
  6419. }
  6420. if ( hasMorphAttributes ) {
  6421. data.data.morphAttributes = morphAttributes;
  6422. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6423. }
  6424. const groups = this.groups;
  6425. if ( groups.length > 0 ) {
  6426. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6427. }
  6428. const boundingSphere = this.boundingSphere;
  6429. if ( boundingSphere !== null ) {
  6430. data.data.boundingSphere = {
  6431. center: boundingSphere.center.toArray(),
  6432. radius: boundingSphere.radius
  6433. };
  6434. }
  6435. return data;
  6436. },
  6437. clone: function () {
  6438. /*
  6439. // Handle primitives
  6440. const parameters = this.parameters;
  6441. if ( parameters !== undefined ) {
  6442. const values = [];
  6443. for ( const key in parameters ) {
  6444. values.push( parameters[ key ] );
  6445. }
  6446. const geometry = Object.create( this.constructor.prototype );
  6447. this.constructor.apply( geometry, values );
  6448. return geometry;
  6449. }
  6450. return new this.constructor().copy( this );
  6451. */
  6452. return new BufferGeometry().copy( this );
  6453. },
  6454. copy: function ( source ) {
  6455. // reset
  6456. this.index = null;
  6457. this.attributes = {};
  6458. this.morphAttributes = {};
  6459. this.groups = [];
  6460. this.boundingBox = null;
  6461. this.boundingSphere = null;
  6462. // used for storing cloned, shared data
  6463. const data = {};
  6464. // name
  6465. this.name = source.name;
  6466. // index
  6467. const index = source.index;
  6468. if ( index !== null ) {
  6469. this.setIndex( index.clone( data ) );
  6470. }
  6471. // attributes
  6472. const attributes = source.attributes;
  6473. for ( const name in attributes ) {
  6474. const attribute = attributes[ name ];
  6475. this.setAttribute( name, attribute.clone( data ) );
  6476. }
  6477. // morph attributes
  6478. const morphAttributes = source.morphAttributes;
  6479. for ( const name in morphAttributes ) {
  6480. const array = [];
  6481. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6482. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6483. array.push( morphAttribute[ i ].clone( data ) );
  6484. }
  6485. this.morphAttributes[ name ] = array;
  6486. }
  6487. this.morphTargetsRelative = source.morphTargetsRelative;
  6488. // groups
  6489. const groups = source.groups;
  6490. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6491. const group = groups[ i ];
  6492. this.addGroup( group.start, group.count, group.materialIndex );
  6493. }
  6494. // bounding box
  6495. const boundingBox = source.boundingBox;
  6496. if ( boundingBox !== null ) {
  6497. this.boundingBox = boundingBox.clone();
  6498. }
  6499. // bounding sphere
  6500. const boundingSphere = source.boundingSphere;
  6501. if ( boundingSphere !== null ) {
  6502. this.boundingSphere = boundingSphere.clone();
  6503. }
  6504. // draw range
  6505. this.drawRange.start = source.drawRange.start;
  6506. this.drawRange.count = source.drawRange.count;
  6507. // user data
  6508. this.userData = source.userData;
  6509. return this;
  6510. },
  6511. dispose: function () {
  6512. this.dispatchEvent( { type: 'dispose' } );
  6513. }
  6514. } );
  6515. const _inverseMatrix = new Matrix4();
  6516. const _ray = new Ray();
  6517. const _sphere = new Sphere();
  6518. const _vA = new Vector3();
  6519. const _vB = new Vector3();
  6520. const _vC = new Vector3();
  6521. const _tempA = new Vector3();
  6522. const _tempB = new Vector3();
  6523. const _tempC = new Vector3();
  6524. const _morphA = new Vector3();
  6525. const _morphB = new Vector3();
  6526. const _morphC = new Vector3();
  6527. const _uvA = new Vector2();
  6528. const _uvB = new Vector2();
  6529. const _uvC = new Vector2();
  6530. const _intersectionPoint = new Vector3();
  6531. const _intersectionPointWorld = new Vector3();
  6532. function Mesh( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6533. Object3D.call( this );
  6534. this.type = 'Mesh';
  6535. this.geometry = geometry;
  6536. this.material = material;
  6537. this.updateMorphTargets();
  6538. }
  6539. Mesh.prototype = Object.assign( Object.create( Object3D.prototype ), {
  6540. constructor: Mesh,
  6541. isMesh: true,
  6542. copy: function ( source ) {
  6543. Object3D.prototype.copy.call( this, source );
  6544. if ( source.morphTargetInfluences !== undefined ) {
  6545. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6546. }
  6547. if ( source.morphTargetDictionary !== undefined ) {
  6548. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6549. }
  6550. this.material = source.material;
  6551. this.geometry = source.geometry;
  6552. return this;
  6553. },
  6554. updateMorphTargets: function () {
  6555. const geometry = this.geometry;
  6556. if ( geometry.isBufferGeometry ) {
  6557. const morphAttributes = geometry.morphAttributes;
  6558. const keys = Object.keys( morphAttributes );
  6559. if ( keys.length > 0 ) {
  6560. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6561. if ( morphAttribute !== undefined ) {
  6562. this.morphTargetInfluences = [];
  6563. this.morphTargetDictionary = {};
  6564. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6565. const name = morphAttribute[ m ].name || String( m );
  6566. this.morphTargetInfluences.push( 0 );
  6567. this.morphTargetDictionary[ name ] = m;
  6568. }
  6569. }
  6570. }
  6571. } else {
  6572. const morphTargets = geometry.morphTargets;
  6573. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  6574. console.error( 'THREE.Mesh.updateMorphTargets() no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  6575. }
  6576. }
  6577. },
  6578. raycast: function ( raycaster, intersects ) {
  6579. const geometry = this.geometry;
  6580. const material = this.material;
  6581. const matrixWorld = this.matrixWorld;
  6582. if ( material === undefined ) return;
  6583. // Checking boundingSphere distance to ray
  6584. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  6585. _sphere.copy( geometry.boundingSphere );
  6586. _sphere.applyMatrix4( matrixWorld );
  6587. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  6588. //
  6589. _inverseMatrix.copy( matrixWorld ).invert();
  6590. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  6591. // Check boundingBox before continuing
  6592. if ( geometry.boundingBox !== null ) {
  6593. if ( _ray.intersectsBox( geometry.boundingBox ) === false ) return;
  6594. }
  6595. let intersection;
  6596. if ( geometry.isBufferGeometry ) {
  6597. const index = geometry.index;
  6598. const position = geometry.attributes.position;
  6599. const morphPosition = geometry.morphAttributes.position;
  6600. const morphTargetsRelative = geometry.morphTargetsRelative;
  6601. const uv = geometry.attributes.uv;
  6602. const uv2 = geometry.attributes.uv2;
  6603. const groups = geometry.groups;
  6604. const drawRange = geometry.drawRange;
  6605. if ( index !== null ) {
  6606. // indexed buffer geometry
  6607. if ( Array.isArray( material ) ) {
  6608. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6609. const group = groups[ i ];
  6610. const groupMaterial = material[ group.materialIndex ];
  6611. const start = Math.max( group.start, drawRange.start );
  6612. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6613. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6614. const a = index.getX( j );
  6615. const b = index.getX( j + 1 );
  6616. const c = index.getX( j + 2 );
  6617. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6618. if ( intersection ) {
  6619. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  6620. intersection.face.materialIndex = group.materialIndex;
  6621. intersects.push( intersection );
  6622. }
  6623. }
  6624. }
  6625. } else {
  6626. const start = Math.max( 0, drawRange.start );
  6627. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  6628. for ( let i = start, il = end; i < il; i += 3 ) {
  6629. const a = index.getX( i );
  6630. const b = index.getX( i + 1 );
  6631. const c = index.getX( i + 2 );
  6632. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6633. if ( intersection ) {
  6634. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  6635. intersects.push( intersection );
  6636. }
  6637. }
  6638. }
  6639. } else if ( position !== undefined ) {
  6640. // non-indexed buffer geometry
  6641. if ( Array.isArray( material ) ) {
  6642. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  6643. const group = groups[ i ];
  6644. const groupMaterial = material[ group.materialIndex ];
  6645. const start = Math.max( group.start, drawRange.start );
  6646. const end = Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) );
  6647. for ( let j = start, jl = end; j < jl; j += 3 ) {
  6648. const a = j;
  6649. const b = j + 1;
  6650. const c = j + 2;
  6651. intersection = checkBufferGeometryIntersection( this, groupMaterial, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6652. if ( intersection ) {
  6653. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  6654. intersection.face.materialIndex = group.materialIndex;
  6655. intersects.push( intersection );
  6656. }
  6657. }
  6658. }
  6659. } else {
  6660. const start = Math.max( 0, drawRange.start );
  6661. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  6662. for ( let i = start, il = end; i < il; i += 3 ) {
  6663. const a = i;
  6664. const b = i + 1;
  6665. const c = i + 2;
  6666. intersection = checkBufferGeometryIntersection( this, material, raycaster, _ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c );
  6667. if ( intersection ) {
  6668. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  6669. intersects.push( intersection );
  6670. }
  6671. }
  6672. }
  6673. }
  6674. } else if ( geometry.isGeometry ) {
  6675. const isMultiMaterial = Array.isArray( material );
  6676. const vertices = geometry.vertices;
  6677. const faces = geometry.faces;
  6678. let uvs;
  6679. const faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  6680. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  6681. for ( let f = 0, fl = faces.length; f < fl; f ++ ) {
  6682. const face = faces[ f ];
  6683. const faceMaterial = isMultiMaterial ? material[ face.materialIndex ] : material;
  6684. if ( faceMaterial === undefined ) continue;
  6685. const fvA = vertices[ face.a ];
  6686. const fvB = vertices[ face.b ];
  6687. const fvC = vertices[ face.c ];
  6688. intersection = checkIntersection( this, faceMaterial, raycaster, _ray, fvA, fvB, fvC, _intersectionPoint );
  6689. if ( intersection ) {
  6690. if ( uvs && uvs[ f ] ) {
  6691. const uvs_f = uvs[ f ];
  6692. _uvA.copy( uvs_f[ 0 ] );
  6693. _uvB.copy( uvs_f[ 1 ] );
  6694. _uvC.copy( uvs_f[ 2 ] );
  6695. intersection.uv = Triangle.getUV( _intersectionPoint, fvA, fvB, fvC, _uvA, _uvB, _uvC, new Vector2() );
  6696. }
  6697. intersection.face = face;
  6698. intersection.faceIndex = f;
  6699. intersects.push( intersection );
  6700. }
  6701. }
  6702. }
  6703. }
  6704. } );
  6705. function checkIntersection( object, material, raycaster, ray, pA, pB, pC, point ) {
  6706. let intersect;
  6707. if ( material.side === BackSide ) {
  6708. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  6709. } else {
  6710. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== DoubleSide, point );
  6711. }
  6712. if ( intersect === null ) return null;
  6713. _intersectionPointWorld.copy( point );
  6714. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  6715. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  6716. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  6717. return {
  6718. distance: distance,
  6719. point: _intersectionPointWorld.clone(),
  6720. object: object
  6721. };
  6722. }
  6723. function checkBufferGeometryIntersection( object, material, raycaster, ray, position, morphPosition, morphTargetsRelative, uv, uv2, a, b, c ) {
  6724. _vA.fromBufferAttribute( position, a );
  6725. _vB.fromBufferAttribute( position, b );
  6726. _vC.fromBufferAttribute( position, c );
  6727. const morphInfluences = object.morphTargetInfluences;
  6728. if ( material.morphTargets && morphPosition && morphInfluences ) {
  6729. _morphA.set( 0, 0, 0 );
  6730. _morphB.set( 0, 0, 0 );
  6731. _morphC.set( 0, 0, 0 );
  6732. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  6733. const influence = morphInfluences[ i ];
  6734. const morphAttribute = morphPosition[ i ];
  6735. if ( influence === 0 ) continue;
  6736. _tempA.fromBufferAttribute( morphAttribute, a );
  6737. _tempB.fromBufferAttribute( morphAttribute, b );
  6738. _tempC.fromBufferAttribute( morphAttribute, c );
  6739. if ( morphTargetsRelative ) {
  6740. _morphA.addScaledVector( _tempA, influence );
  6741. _morphB.addScaledVector( _tempB, influence );
  6742. _morphC.addScaledVector( _tempC, influence );
  6743. } else {
  6744. _morphA.addScaledVector( _tempA.sub( _vA ), influence );
  6745. _morphB.addScaledVector( _tempB.sub( _vB ), influence );
  6746. _morphC.addScaledVector( _tempC.sub( _vC ), influence );
  6747. }
  6748. }
  6749. _vA.add( _morphA );
  6750. _vB.add( _morphB );
  6751. _vC.add( _morphC );
  6752. }
  6753. if ( object.isSkinnedMesh ) {
  6754. object.boneTransform( a, _vA );
  6755. object.boneTransform( b, _vB );
  6756. object.boneTransform( c, _vC );
  6757. }
  6758. const intersection = checkIntersection( object, material, raycaster, ray, _vA, _vB, _vC, _intersectionPoint );
  6759. if ( intersection ) {
  6760. if ( uv ) {
  6761. _uvA.fromBufferAttribute( uv, a );
  6762. _uvB.fromBufferAttribute( uv, b );
  6763. _uvC.fromBufferAttribute( uv, c );
  6764. intersection.uv = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6765. }
  6766. if ( uv2 ) {
  6767. _uvA.fromBufferAttribute( uv2, a );
  6768. _uvB.fromBufferAttribute( uv2, b );
  6769. _uvC.fromBufferAttribute( uv2, c );
  6770. intersection.uv2 = Triangle.getUV( _intersectionPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() );
  6771. }
  6772. const face = new Face3( a, b, c );
  6773. Triangle.getNormal( _vA, _vB, _vC, face.normal );
  6774. intersection.face = face;
  6775. }
  6776. return intersection;
  6777. }
  6778. class BoxBufferGeometry extends BufferGeometry {
  6779. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  6780. super();
  6781. this.type = 'BoxBufferGeometry';
  6782. this.parameters = {
  6783. width: width,
  6784. height: height,
  6785. depth: depth,
  6786. widthSegments: widthSegments,
  6787. heightSegments: heightSegments,
  6788. depthSegments: depthSegments
  6789. };
  6790. const scope = this;
  6791. // segments
  6792. widthSegments = Math.floor( widthSegments );
  6793. heightSegments = Math.floor( heightSegments );
  6794. depthSegments = Math.floor( depthSegments );
  6795. // buffers
  6796. const indices = [];
  6797. const vertices = [];
  6798. const normals = [];
  6799. const uvs = [];
  6800. // helper variables
  6801. let numberOfVertices = 0;
  6802. let groupStart = 0;
  6803. // build each side of the box geometry
  6804. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  6805. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  6806. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  6807. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  6808. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  6809. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  6810. // build geometry
  6811. this.setIndex( indices );
  6812. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  6813. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  6814. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  6815. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  6816. const segmentWidth = width / gridX;
  6817. const segmentHeight = height / gridY;
  6818. const widthHalf = width / 2;
  6819. const heightHalf = height / 2;
  6820. const depthHalf = depth / 2;
  6821. const gridX1 = gridX + 1;
  6822. const gridY1 = gridY + 1;
  6823. let vertexCounter = 0;
  6824. let groupCount = 0;
  6825. const vector = new Vector3();
  6826. // generate vertices, normals and uvs
  6827. for ( let iy = 0; iy < gridY1; iy ++ ) {
  6828. const y = iy * segmentHeight - heightHalf;
  6829. for ( let ix = 0; ix < gridX1; ix ++ ) {
  6830. const x = ix * segmentWidth - widthHalf;
  6831. // set values to correct vector component
  6832. vector[ u ] = x * udir;
  6833. vector[ v ] = y * vdir;
  6834. vector[ w ] = depthHalf;
  6835. // now apply vector to vertex buffer
  6836. vertices.push( vector.x, vector.y, vector.z );
  6837. // set values to correct vector component
  6838. vector[ u ] = 0;
  6839. vector[ v ] = 0;
  6840. vector[ w ] = depth > 0 ? 1 : - 1;
  6841. // now apply vector to normal buffer
  6842. normals.push( vector.x, vector.y, vector.z );
  6843. // uvs
  6844. uvs.push( ix / gridX );
  6845. uvs.push( 1 - ( iy / gridY ) );
  6846. // counters
  6847. vertexCounter += 1;
  6848. }
  6849. }
  6850. // indices
  6851. // 1. you need three indices to draw a single face
  6852. // 2. a single segment consists of two faces
  6853. // 3. so we need to generate six (2*3) indices per segment
  6854. for ( let iy = 0; iy < gridY; iy ++ ) {
  6855. for ( let ix = 0; ix < gridX; ix ++ ) {
  6856. const a = numberOfVertices + ix + gridX1 * iy;
  6857. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  6858. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  6859. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  6860. // faces
  6861. indices.push( a, b, d );
  6862. indices.push( b, c, d );
  6863. // increase counter
  6864. groupCount += 6;
  6865. }
  6866. }
  6867. // add a group to the geometry. this will ensure multi material support
  6868. scope.addGroup( groupStart, groupCount, materialIndex );
  6869. // calculate new start value for groups
  6870. groupStart += groupCount;
  6871. // update total number of vertices
  6872. numberOfVertices += vertexCounter;
  6873. }
  6874. }
  6875. }
  6876. /**
  6877. * Uniform Utilities
  6878. */
  6879. function cloneUniforms( src ) {
  6880. const dst = {};
  6881. for ( const u in src ) {
  6882. dst[ u ] = {};
  6883. for ( const p in src[ u ] ) {
  6884. const property = src[ u ][ p ];
  6885. if ( property && ( property.isColor ||
  6886. property.isMatrix3 || property.isMatrix4 ||
  6887. property.isVector2 || property.isVector3 || property.isVector4 ||
  6888. property.isTexture ) ) {
  6889. dst[ u ][ p ] = property.clone();
  6890. } else if ( Array.isArray( property ) ) {
  6891. dst[ u ][ p ] = property.slice();
  6892. } else {
  6893. dst[ u ][ p ] = property;
  6894. }
  6895. }
  6896. }
  6897. return dst;
  6898. }
  6899. function mergeUniforms( uniforms ) {
  6900. const merged = {};
  6901. for ( let u = 0; u < uniforms.length; u ++ ) {
  6902. const tmp = cloneUniforms( uniforms[ u ] );
  6903. for ( const p in tmp ) {
  6904. merged[ p ] = tmp[ p ];
  6905. }
  6906. }
  6907. return merged;
  6908. }
  6909. // Legacy
  6910. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  6911. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  6912. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  6913. /**
  6914. * parameters = {
  6915. * defines: { "label" : "value" },
  6916. * uniforms: { "parameter1": { value: 1.0 }, "parameter2": { value2: 2 } },
  6917. *
  6918. * fragmentShader: <string>,
  6919. * vertexShader: <string>,
  6920. *
  6921. * wireframe: <boolean>,
  6922. * wireframeLinewidth: <float>,
  6923. *
  6924. * lights: <bool>,
  6925. *
  6926. * skinning: <bool>,
  6927. * morphTargets: <bool>,
  6928. * morphNormals: <bool>
  6929. * }
  6930. */
  6931. function ShaderMaterial( parameters ) {
  6932. Material.call( this );
  6933. this.type = 'ShaderMaterial';
  6934. this.defines = {};
  6935. this.uniforms = {};
  6936. this.vertexShader = default_vertex;
  6937. this.fragmentShader = default_fragment;
  6938. this.linewidth = 1;
  6939. this.wireframe = false;
  6940. this.wireframeLinewidth = 1;
  6941. this.fog = false; // set to use scene fog
  6942. this.lights = false; // set to use scene lights
  6943. this.clipping = false; // set to use user-defined clipping planes
  6944. this.skinning = false; // set to use skinning attribute streams
  6945. this.morphTargets = false; // set to use morph targets
  6946. this.morphNormals = false; // set to use morph normals
  6947. this.extensions = {
  6948. derivatives: false, // set to use derivatives
  6949. fragDepth: false, // set to use fragment depth values
  6950. drawBuffers: false, // set to use draw buffers
  6951. shaderTextureLOD: false // set to use shader texture LOD
  6952. };
  6953. // When rendered geometry doesn't include these attributes but the material does,
  6954. // use these default values in WebGL. This avoids errors when buffer data is missing.
  6955. this.defaultAttributeValues = {
  6956. 'color': [ 1, 1, 1 ],
  6957. 'uv': [ 0, 0 ],
  6958. 'uv2': [ 0, 0 ]
  6959. };
  6960. this.index0AttributeName = undefined;
  6961. this.uniformsNeedUpdate = false;
  6962. this.glslVersion = null;
  6963. if ( parameters !== undefined ) {
  6964. if ( parameters.attributes !== undefined ) {
  6965. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  6966. }
  6967. this.setValues( parameters );
  6968. }
  6969. }
  6970. ShaderMaterial.prototype = Object.create( Material.prototype );
  6971. ShaderMaterial.prototype.constructor = ShaderMaterial;
  6972. ShaderMaterial.prototype.isShaderMaterial = true;
  6973. ShaderMaterial.prototype.copy = function ( source ) {
  6974. Material.prototype.copy.call( this, source );
  6975. this.fragmentShader = source.fragmentShader;
  6976. this.vertexShader = source.vertexShader;
  6977. this.uniforms = cloneUniforms( source.uniforms );
  6978. this.defines = Object.assign( {}, source.defines );
  6979. this.wireframe = source.wireframe;
  6980. this.wireframeLinewidth = source.wireframeLinewidth;
  6981. this.lights = source.lights;
  6982. this.clipping = source.clipping;
  6983. this.skinning = source.skinning;
  6984. this.morphTargets = source.morphTargets;
  6985. this.morphNormals = source.morphNormals;
  6986. this.extensions = Object.assign( {}, source.extensions );
  6987. this.glslVersion = source.glslVersion;
  6988. return this;
  6989. };
  6990. ShaderMaterial.prototype.toJSON = function ( meta ) {
  6991. const data = Material.prototype.toJSON.call( this, meta );
  6992. data.glslVersion = this.glslVersion;
  6993. data.uniforms = {};
  6994. for ( const name in this.uniforms ) {
  6995. const uniform = this.uniforms[ name ];
  6996. const value = uniform.value;
  6997. if ( value && value.isTexture ) {
  6998. data.uniforms[ name ] = {
  6999. type: 't',
  7000. value: value.toJSON( meta ).uuid
  7001. };
  7002. } else if ( value && value.isColor ) {
  7003. data.uniforms[ name ] = {
  7004. type: 'c',
  7005. value: value.getHex()
  7006. };
  7007. } else if ( value && value.isVector2 ) {
  7008. data.uniforms[ name ] = {
  7009. type: 'v2',
  7010. value: value.toArray()
  7011. };
  7012. } else if ( value && value.isVector3 ) {
  7013. data.uniforms[ name ] = {
  7014. type: 'v3',
  7015. value: value.toArray()
  7016. };
  7017. } else if ( value && value.isVector4 ) {
  7018. data.uniforms[ name ] = {
  7019. type: 'v4',
  7020. value: value.toArray()
  7021. };
  7022. } else if ( value && value.isMatrix3 ) {
  7023. data.uniforms[ name ] = {
  7024. type: 'm3',
  7025. value: value.toArray()
  7026. };
  7027. } else if ( value && value.isMatrix4 ) {
  7028. data.uniforms[ name ] = {
  7029. type: 'm4',
  7030. value: value.toArray()
  7031. };
  7032. } else {
  7033. data.uniforms[ name ] = {
  7034. value: value
  7035. };
  7036. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7037. }
  7038. }
  7039. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7040. data.vertexShader = this.vertexShader;
  7041. data.fragmentShader = this.fragmentShader;
  7042. const extensions = {};
  7043. for ( const key in this.extensions ) {
  7044. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7045. }
  7046. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7047. return data;
  7048. };
  7049. function Camera() {
  7050. Object3D.call( this );
  7051. this.type = 'Camera';
  7052. this.matrixWorldInverse = new Matrix4();
  7053. this.projectionMatrix = new Matrix4();
  7054. this.projectionMatrixInverse = new Matrix4();
  7055. }
  7056. Camera.prototype = Object.assign( Object.create( Object3D.prototype ), {
  7057. constructor: Camera,
  7058. isCamera: true,
  7059. copy: function ( source, recursive ) {
  7060. Object3D.prototype.copy.call( this, source, recursive );
  7061. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7062. this.projectionMatrix.copy( source.projectionMatrix );
  7063. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7064. return this;
  7065. },
  7066. getWorldDirection: function ( target ) {
  7067. if ( target === undefined ) {
  7068. console.warn( 'THREE.Camera: .getWorldDirection() target is now required' );
  7069. target = new Vector3();
  7070. }
  7071. this.updateWorldMatrix( true, false );
  7072. const e = this.matrixWorld.elements;
  7073. return target.set( - e[ 8 ], - e[ 9 ], - e[ 10 ] ).normalize();
  7074. },
  7075. updateMatrixWorld: function ( force ) {
  7076. Object3D.prototype.updateMatrixWorld.call( this, force );
  7077. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7078. },
  7079. updateWorldMatrix: function ( updateParents, updateChildren ) {
  7080. Object3D.prototype.updateWorldMatrix.call( this, updateParents, updateChildren );
  7081. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7082. },
  7083. clone: function () {
  7084. return new this.constructor().copy( this );
  7085. }
  7086. } );
  7087. function PerspectiveCamera( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7088. Camera.call( this );
  7089. this.type = 'PerspectiveCamera';
  7090. this.fov = fov;
  7091. this.zoom = 1;
  7092. this.near = near;
  7093. this.far = far;
  7094. this.focus = 10;
  7095. this.aspect = aspect;
  7096. this.view = null;
  7097. this.filmGauge = 35; // width of the film (default in millimeters)
  7098. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7099. this.updateProjectionMatrix();
  7100. }
  7101. PerspectiveCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  7102. constructor: PerspectiveCamera,
  7103. isPerspectiveCamera: true,
  7104. copy: function ( source, recursive ) {
  7105. Camera.prototype.copy.call( this, source, recursive );
  7106. this.fov = source.fov;
  7107. this.zoom = source.zoom;
  7108. this.near = source.near;
  7109. this.far = source.far;
  7110. this.focus = source.focus;
  7111. this.aspect = source.aspect;
  7112. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7113. this.filmGauge = source.filmGauge;
  7114. this.filmOffset = source.filmOffset;
  7115. return this;
  7116. },
  7117. /**
  7118. * Sets the FOV by focal length in respect to the current .filmGauge.
  7119. *
  7120. * The default film gauge is 35, so that the focal length can be specified for
  7121. * a 35mm (full frame) camera.
  7122. *
  7123. * Values for focal length and film gauge must have the same unit.
  7124. */
  7125. setFocalLength: function ( focalLength ) {
  7126. // see http://www.bobatkins.com/photography/technical/field_of_view.html
  7127. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7128. this.fov = MathUtils.RAD2DEG * 2 * Math.atan( vExtentSlope );
  7129. this.updateProjectionMatrix();
  7130. },
  7131. /**
  7132. * Calculates the focal length from the current .fov and .filmGauge.
  7133. */
  7134. getFocalLength: function () {
  7135. const vExtentSlope = Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov );
  7136. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7137. },
  7138. getEffectiveFOV: function () {
  7139. return MathUtils.RAD2DEG * 2 * Math.atan(
  7140. Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7141. },
  7142. getFilmWidth: function () {
  7143. // film not completely covered in portrait format (aspect < 1)
  7144. return this.filmGauge * Math.min( this.aspect, 1 );
  7145. },
  7146. getFilmHeight: function () {
  7147. // film not completely covered in landscape format (aspect > 1)
  7148. return this.filmGauge / Math.max( this.aspect, 1 );
  7149. },
  7150. /**
  7151. * Sets an offset in a larger frustum. This is useful for multi-window or
  7152. * multi-monitor/multi-machine setups.
  7153. *
  7154. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7155. * the monitors are in grid like this
  7156. *
  7157. * +---+---+---+
  7158. * | A | B | C |
  7159. * +---+---+---+
  7160. * | D | E | F |
  7161. * +---+---+---+
  7162. *
  7163. * then for each monitor you would call it like this
  7164. *
  7165. * const w = 1920;
  7166. * const h = 1080;
  7167. * const fullWidth = w * 3;
  7168. * const fullHeight = h * 2;
  7169. *
  7170. * --A--
  7171. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7172. * --B--
  7173. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7174. * --C--
  7175. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7176. * --D--
  7177. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7178. * --E--
  7179. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7180. * --F--
  7181. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7182. *
  7183. * Note there is no reason monitors have to be the same size or in a grid.
  7184. */
  7185. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  7186. this.aspect = fullWidth / fullHeight;
  7187. if ( this.view === null ) {
  7188. this.view = {
  7189. enabled: true,
  7190. fullWidth: 1,
  7191. fullHeight: 1,
  7192. offsetX: 0,
  7193. offsetY: 0,
  7194. width: 1,
  7195. height: 1
  7196. };
  7197. }
  7198. this.view.enabled = true;
  7199. this.view.fullWidth = fullWidth;
  7200. this.view.fullHeight = fullHeight;
  7201. this.view.offsetX = x;
  7202. this.view.offsetY = y;
  7203. this.view.width = width;
  7204. this.view.height = height;
  7205. this.updateProjectionMatrix();
  7206. },
  7207. clearViewOffset: function () {
  7208. if ( this.view !== null ) {
  7209. this.view.enabled = false;
  7210. }
  7211. this.updateProjectionMatrix();
  7212. },
  7213. updateProjectionMatrix: function () {
  7214. const near = this.near;
  7215. let top = near * Math.tan( MathUtils.DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7216. let height = 2 * top;
  7217. let width = this.aspect * height;
  7218. let left = - 0.5 * width;
  7219. const view = this.view;
  7220. if ( this.view !== null && this.view.enabled ) {
  7221. const fullWidth = view.fullWidth,
  7222. fullHeight = view.fullHeight;
  7223. left += view.offsetX * width / fullWidth;
  7224. top -= view.offsetY * height / fullHeight;
  7225. width *= view.width / fullWidth;
  7226. height *= view.height / fullHeight;
  7227. }
  7228. const skew = this.filmOffset;
  7229. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7230. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far );
  7231. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7232. },
  7233. toJSON: function ( meta ) {
  7234. const data = Object3D.prototype.toJSON.call( this, meta );
  7235. data.object.fov = this.fov;
  7236. data.object.zoom = this.zoom;
  7237. data.object.near = this.near;
  7238. data.object.far = this.far;
  7239. data.object.focus = this.focus;
  7240. data.object.aspect = this.aspect;
  7241. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7242. data.object.filmGauge = this.filmGauge;
  7243. data.object.filmOffset = this.filmOffset;
  7244. return data;
  7245. }
  7246. } );
  7247. const fov = 90, aspect = 1;
  7248. function CubeCamera( near, far, renderTarget ) {
  7249. Object3D.call( this );
  7250. this.type = 'CubeCamera';
  7251. if ( renderTarget.isWebGLCubeRenderTarget !== true ) {
  7252. console.error( 'THREE.CubeCamera: The constructor now expects an instance of WebGLCubeRenderTarget as third parameter.' );
  7253. return;
  7254. }
  7255. this.renderTarget = renderTarget;
  7256. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7257. cameraPX.layers = this.layers;
  7258. cameraPX.up.set( 0, - 1, 0 );
  7259. cameraPX.lookAt( new Vector3( 1, 0, 0 ) );
  7260. this.add( cameraPX );
  7261. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7262. cameraNX.layers = this.layers;
  7263. cameraNX.up.set( 0, - 1, 0 );
  7264. cameraNX.lookAt( new Vector3( - 1, 0, 0 ) );
  7265. this.add( cameraNX );
  7266. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7267. cameraPY.layers = this.layers;
  7268. cameraPY.up.set( 0, 0, 1 );
  7269. cameraPY.lookAt( new Vector3( 0, 1, 0 ) );
  7270. this.add( cameraPY );
  7271. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7272. cameraNY.layers = this.layers;
  7273. cameraNY.up.set( 0, 0, - 1 );
  7274. cameraNY.lookAt( new Vector3( 0, - 1, 0 ) );
  7275. this.add( cameraNY );
  7276. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7277. cameraPZ.layers = this.layers;
  7278. cameraPZ.up.set( 0, - 1, 0 );
  7279. cameraPZ.lookAt( new Vector3( 0, 0, 1 ) );
  7280. this.add( cameraPZ );
  7281. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7282. cameraNZ.layers = this.layers;
  7283. cameraNZ.up.set( 0, - 1, 0 );
  7284. cameraNZ.lookAt( new Vector3( 0, 0, - 1 ) );
  7285. this.add( cameraNZ );
  7286. this.update = function ( renderer, scene ) {
  7287. if ( this.parent === null ) this.updateMatrixWorld();
  7288. const currentXrEnabled = renderer.xr.enabled;
  7289. const currentRenderTarget = renderer.getRenderTarget();
  7290. renderer.xr.enabled = false;
  7291. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7292. renderTarget.texture.generateMipmaps = false;
  7293. renderer.setRenderTarget( renderTarget, 0 );
  7294. renderer.render( scene, cameraPX );
  7295. renderer.setRenderTarget( renderTarget, 1 );
  7296. renderer.render( scene, cameraNX );
  7297. renderer.setRenderTarget( renderTarget, 2 );
  7298. renderer.render( scene, cameraPY );
  7299. renderer.setRenderTarget( renderTarget, 3 );
  7300. renderer.render( scene, cameraNY );
  7301. renderer.setRenderTarget( renderTarget, 4 );
  7302. renderer.render( scene, cameraPZ );
  7303. renderTarget.texture.generateMipmaps = generateMipmaps;
  7304. renderer.setRenderTarget( renderTarget, 5 );
  7305. renderer.render( scene, cameraNZ );
  7306. renderer.setRenderTarget( currentRenderTarget );
  7307. renderer.xr.enabled = currentXrEnabled;
  7308. };
  7309. }
  7310. CubeCamera.prototype = Object.create( Object3D.prototype );
  7311. CubeCamera.prototype.constructor = CubeCamera;
  7312. function CubeTexture( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding ) {
  7313. images = images !== undefined ? images : [];
  7314. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7315. format = format !== undefined ? format : RGBFormat;
  7316. Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7317. this.flipY = false;
  7318. // Why CubeTexture._needsFlipEnvMap is necessary:
  7319. //
  7320. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7321. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7322. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7323. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7324. // and the flag _needsFlipEnvMap controls this conversion. The flip is not required (and thus _needsFlipEnvMap is set to false)
  7325. // when using WebGLCubeRenderTarget.texture as a cube texture.
  7326. this._needsFlipEnvMap = true;
  7327. }
  7328. CubeTexture.prototype = Object.create( Texture.prototype );
  7329. CubeTexture.prototype.constructor = CubeTexture;
  7330. CubeTexture.prototype.isCubeTexture = true;
  7331. Object.defineProperty( CubeTexture.prototype, 'images', {
  7332. get: function () {
  7333. return this.image;
  7334. },
  7335. set: function ( value ) {
  7336. this.image = value;
  7337. }
  7338. } );
  7339. function WebGLCubeRenderTarget( size, options, dummy ) {
  7340. if ( Number.isInteger( options ) ) {
  7341. console.warn( 'THREE.WebGLCubeRenderTarget: constructor signature is now WebGLCubeRenderTarget( size, options )' );
  7342. options = dummy;
  7343. }
  7344. WebGLRenderTarget.call( this, size, size, options );
  7345. options = options || {};
  7346. this.texture = new CubeTexture( undefined, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.encoding );
  7347. this.texture._needsFlipEnvMap = false;
  7348. }
  7349. WebGLCubeRenderTarget.prototype = Object.create( WebGLRenderTarget.prototype );
  7350. WebGLCubeRenderTarget.prototype.constructor = WebGLCubeRenderTarget;
  7351. WebGLCubeRenderTarget.prototype.isWebGLCubeRenderTarget = true;
  7352. WebGLCubeRenderTarget.prototype.fromEquirectangularTexture = function ( renderer, texture ) {
  7353. this.texture.type = texture.type;
  7354. this.texture.format = RGBAFormat; // see #18859
  7355. this.texture.encoding = texture.encoding;
  7356. this.texture.generateMipmaps = texture.generateMipmaps;
  7357. this.texture.minFilter = texture.minFilter;
  7358. this.texture.magFilter = texture.magFilter;
  7359. const shader = {
  7360. uniforms: {
  7361. tEquirect: { value: null },
  7362. },
  7363. vertexShader: /* glsl */`
  7364. varying vec3 vWorldDirection;
  7365. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7366. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7367. }
  7368. void main() {
  7369. vWorldDirection = transformDirection( position, modelMatrix );
  7370. #include <begin_vertex>
  7371. #include <project_vertex>
  7372. }
  7373. `,
  7374. fragmentShader: /* glsl */`
  7375. uniform sampler2D tEquirect;
  7376. varying vec3 vWorldDirection;
  7377. #include <common>
  7378. void main() {
  7379. vec3 direction = normalize( vWorldDirection );
  7380. vec2 sampleUV = equirectUv( direction );
  7381. gl_FragColor = texture2D( tEquirect, sampleUV );
  7382. }
  7383. `
  7384. };
  7385. const geometry = new BoxBufferGeometry( 5, 5, 5 );
  7386. const material = new ShaderMaterial( {
  7387. name: 'CubemapFromEquirect',
  7388. uniforms: cloneUniforms( shader.uniforms ),
  7389. vertexShader: shader.vertexShader,
  7390. fragmentShader: shader.fragmentShader,
  7391. side: BackSide,
  7392. blending: NoBlending
  7393. } );
  7394. material.uniforms.tEquirect.value = texture;
  7395. const mesh = new Mesh( geometry, material );
  7396. const currentMinFilter = texture.minFilter;
  7397. // Avoid blurred poles
  7398. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7399. const camera = new CubeCamera( 1, 10, this );
  7400. camera.update( renderer, mesh );
  7401. texture.minFilter = currentMinFilter;
  7402. mesh.geometry.dispose();
  7403. mesh.material.dispose();
  7404. return this;
  7405. };
  7406. WebGLCubeRenderTarget.prototype.clear = function ( renderer, color, depth, stencil ) {
  7407. const currentRenderTarget = renderer.getRenderTarget();
  7408. for ( let i = 0; i < 6; i ++ ) {
  7409. renderer.setRenderTarget( this, i );
  7410. renderer.clear( color, depth, stencil );
  7411. }
  7412. renderer.setRenderTarget( currentRenderTarget );
  7413. };
  7414. function DataTexture( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  7415. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  7416. this.image = { data: data || null, width: width || 1, height: height || 1 };
  7417. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  7418. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  7419. this.generateMipmaps = false;
  7420. this.flipY = false;
  7421. this.unpackAlignment = 1;
  7422. this.needsUpdate = true;
  7423. }
  7424. DataTexture.prototype = Object.create( Texture.prototype );
  7425. DataTexture.prototype.constructor = DataTexture;
  7426. DataTexture.prototype.isDataTexture = true;
  7427. const _sphere$1 = /*@__PURE__*/ new Sphere();
  7428. const _vector$5 = /*@__PURE__*/ new Vector3();
  7429. class Frustum {
  7430. constructor( p0, p1, p2, p3, p4, p5 ) {
  7431. this.planes = [
  7432. ( p0 !== undefined ) ? p0 : new Plane(),
  7433. ( p1 !== undefined ) ? p1 : new Plane(),
  7434. ( p2 !== undefined ) ? p2 : new Plane(),
  7435. ( p3 !== undefined ) ? p3 : new Plane(),
  7436. ( p4 !== undefined ) ? p4 : new Plane(),
  7437. ( p5 !== undefined ) ? p5 : new Plane()
  7438. ];
  7439. }
  7440. set( p0, p1, p2, p3, p4, p5 ) {
  7441. const planes = this.planes;
  7442. planes[ 0 ].copy( p0 );
  7443. planes[ 1 ].copy( p1 );
  7444. planes[ 2 ].copy( p2 );
  7445. planes[ 3 ].copy( p3 );
  7446. planes[ 4 ].copy( p4 );
  7447. planes[ 5 ].copy( p5 );
  7448. return this;
  7449. }
  7450. clone() {
  7451. return new this.constructor().copy( this );
  7452. }
  7453. copy( frustum ) {
  7454. const planes = this.planes;
  7455. for ( let i = 0; i < 6; i ++ ) {
  7456. planes[ i ].copy( frustum.planes[ i ] );
  7457. }
  7458. return this;
  7459. }
  7460. setFromProjectionMatrix( m ) {
  7461. const planes = this.planes;
  7462. const me = m.elements;
  7463. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  7464. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  7465. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  7466. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  7467. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  7468. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  7469. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  7470. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  7471. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  7472. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  7473. return this;
  7474. }
  7475. intersectsObject( object ) {
  7476. const geometry = object.geometry;
  7477. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7478. _sphere$1.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  7479. return this.intersectsSphere( _sphere$1 );
  7480. }
  7481. intersectsSprite( sprite ) {
  7482. _sphere$1.center.set( 0, 0, 0 );
  7483. _sphere$1.radius = 0.7071067811865476;
  7484. _sphere$1.applyMatrix4( sprite.matrixWorld );
  7485. return this.intersectsSphere( _sphere$1 );
  7486. }
  7487. intersectsSphere( sphere ) {
  7488. const planes = this.planes;
  7489. const center = sphere.center;
  7490. const negRadius = - sphere.radius;
  7491. for ( let i = 0; i < 6; i ++ ) {
  7492. const distance = planes[ i ].distanceToPoint( center );
  7493. if ( distance < negRadius ) {
  7494. return false;
  7495. }
  7496. }
  7497. return true;
  7498. }
  7499. intersectsBox( box ) {
  7500. const planes = this.planes;
  7501. for ( let i = 0; i < 6; i ++ ) {
  7502. const plane = planes[ i ];
  7503. // corner at max distance
  7504. _vector$5.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  7505. _vector$5.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  7506. _vector$5.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  7507. if ( plane.distanceToPoint( _vector$5 ) < 0 ) {
  7508. return false;
  7509. }
  7510. }
  7511. return true;
  7512. }
  7513. containsPoint( point ) {
  7514. const planes = this.planes;
  7515. for ( let i = 0; i < 6; i ++ ) {
  7516. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  7517. return false;
  7518. }
  7519. }
  7520. return true;
  7521. }
  7522. }
  7523. function WebGLAnimation() {
  7524. let context = null;
  7525. let isAnimating = false;
  7526. let animationLoop = null;
  7527. let requestId = null;
  7528. function onAnimationFrame( time, frame ) {
  7529. animationLoop( time, frame );
  7530. requestId = context.requestAnimationFrame( onAnimationFrame );
  7531. }
  7532. return {
  7533. start: function () {
  7534. if ( isAnimating === true ) return;
  7535. if ( animationLoop === null ) return;
  7536. requestId = context.requestAnimationFrame( onAnimationFrame );
  7537. isAnimating = true;
  7538. },
  7539. stop: function () {
  7540. context.cancelAnimationFrame( requestId );
  7541. isAnimating = false;
  7542. },
  7543. setAnimationLoop: function ( callback ) {
  7544. animationLoop = callback;
  7545. },
  7546. setContext: function ( value ) {
  7547. context = value;
  7548. }
  7549. };
  7550. }
  7551. function WebGLAttributes( gl, capabilities ) {
  7552. const isWebGL2 = capabilities.isWebGL2;
  7553. const buffers = new WeakMap();
  7554. function createBuffer( attribute, bufferType ) {
  7555. const array = attribute.array;
  7556. const usage = attribute.usage;
  7557. const buffer = gl.createBuffer();
  7558. gl.bindBuffer( bufferType, buffer );
  7559. gl.bufferData( bufferType, array, usage );
  7560. attribute.onUploadCallback();
  7561. let type = 5126;
  7562. if ( array instanceof Float32Array ) {
  7563. type = 5126;
  7564. } else if ( array instanceof Float64Array ) {
  7565. console.warn( 'THREE.WebGLAttributes: Unsupported data buffer format: Float64Array.' );
  7566. } else if ( array instanceof Uint16Array ) {
  7567. if ( attribute.isFloat16BufferAttribute ) {
  7568. if ( isWebGL2 ) {
  7569. type = 5131;
  7570. } else {
  7571. console.warn( 'THREE.WebGLAttributes: Usage of Float16BufferAttribute requires WebGL2.' );
  7572. }
  7573. } else {
  7574. type = 5123;
  7575. }
  7576. } else if ( array instanceof Int16Array ) {
  7577. type = 5122;
  7578. } else if ( array instanceof Uint32Array ) {
  7579. type = 5125;
  7580. } else if ( array instanceof Int32Array ) {
  7581. type = 5124;
  7582. } else if ( array instanceof Int8Array ) {
  7583. type = 5120;
  7584. } else if ( array instanceof Uint8Array ) {
  7585. type = 5121;
  7586. }
  7587. return {
  7588. buffer: buffer,
  7589. type: type,
  7590. bytesPerElement: array.BYTES_PER_ELEMENT,
  7591. version: attribute.version
  7592. };
  7593. }
  7594. function updateBuffer( buffer, attribute, bufferType ) {
  7595. const array = attribute.array;
  7596. const updateRange = attribute.updateRange;
  7597. gl.bindBuffer( bufferType, buffer );
  7598. if ( updateRange.count === - 1 ) {
  7599. // Not using update ranges
  7600. gl.bufferSubData( bufferType, 0, array );
  7601. } else {
  7602. if ( isWebGL2 ) {
  7603. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7604. array, updateRange.offset, updateRange.count );
  7605. } else {
  7606. gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
  7607. array.subarray( updateRange.offset, updateRange.offset + updateRange.count ) );
  7608. }
  7609. updateRange.count = - 1; // reset range
  7610. }
  7611. }
  7612. //
  7613. function get( attribute ) {
  7614. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7615. return buffers.get( attribute );
  7616. }
  7617. function remove( attribute ) {
  7618. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7619. const data = buffers.get( attribute );
  7620. if ( data ) {
  7621. gl.deleteBuffer( data.buffer );
  7622. buffers.delete( attribute );
  7623. }
  7624. }
  7625. function update( attribute, bufferType ) {
  7626. if ( attribute.isGLBufferAttribute ) {
  7627. const cached = buffers.get( attribute );
  7628. if ( ! cached || cached.version < attribute.version ) {
  7629. buffers.set( attribute, {
  7630. buffer: attribute.buffer,
  7631. type: attribute.type,
  7632. bytesPerElement: attribute.elementSize,
  7633. version: attribute.version
  7634. } );
  7635. }
  7636. return;
  7637. }
  7638. if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;
  7639. const data = buffers.get( attribute );
  7640. if ( data === undefined ) {
  7641. buffers.set( attribute, createBuffer( attribute, bufferType ) );
  7642. } else if ( data.version < attribute.version ) {
  7643. updateBuffer( data.buffer, attribute, bufferType );
  7644. data.version = attribute.version;
  7645. }
  7646. }
  7647. return {
  7648. get: get,
  7649. remove: remove,
  7650. update: update
  7651. };
  7652. }
  7653. class PlaneBufferGeometry extends BufferGeometry {
  7654. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  7655. super();
  7656. this.type = 'PlaneBufferGeometry';
  7657. this.parameters = {
  7658. width: width,
  7659. height: height,
  7660. widthSegments: widthSegments,
  7661. heightSegments: heightSegments
  7662. };
  7663. const width_half = width / 2;
  7664. const height_half = height / 2;
  7665. const gridX = Math.floor( widthSegments );
  7666. const gridY = Math.floor( heightSegments );
  7667. const gridX1 = gridX + 1;
  7668. const gridY1 = gridY + 1;
  7669. const segment_width = width / gridX;
  7670. const segment_height = height / gridY;
  7671. //
  7672. const indices = [];
  7673. const vertices = [];
  7674. const normals = [];
  7675. const uvs = [];
  7676. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7677. const y = iy * segment_height - height_half;
  7678. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7679. const x = ix * segment_width - width_half;
  7680. vertices.push( x, - y, 0 );
  7681. normals.push( 0, 0, 1 );
  7682. uvs.push( ix / gridX );
  7683. uvs.push( 1 - ( iy / gridY ) );
  7684. }
  7685. }
  7686. for ( let iy = 0; iy < gridY; iy ++ ) {
  7687. for ( let ix = 0; ix < gridX; ix ++ ) {
  7688. const a = ix + gridX1 * iy;
  7689. const b = ix + gridX1 * ( iy + 1 );
  7690. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  7691. const d = ( ix + 1 ) + gridX1 * iy;
  7692. indices.push( a, b, d );
  7693. indices.push( b, c, d );
  7694. }
  7695. }
  7696. this.setIndex( indices );
  7697. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7698. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7699. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7700. }
  7701. }
  7702. var alphamap_fragment = "#ifdef USE_ALPHAMAP\n\tdiffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif";
  7703. var alphamap_pars_fragment = "#ifdef USE_ALPHAMAP\n\tuniform sampler2D alphaMap;\n#endif";
  7704. var alphatest_fragment = "#ifdef ALPHATEST\n\tif ( diffuseColor.a < ALPHATEST ) discard;\n#endif";
  7705. 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";
  7706. var aomap_pars_fragment = "#ifdef USE_AOMAP\n\tuniform sampler2D aoMap;\n\tuniform float aoMapIntensity;\n#endif";
  7707. var begin_vertex = "vec3 transformed = vec3( position );";
  7708. var beginnormal_vertex = "vec3 objectNormal = vec3( normal );\n#ifdef USE_TANGENT\n\tvec3 objectTangent = vec3( tangent.xyz );\n#endif";
  7709. 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";
  7710. 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";
  7711. 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";
  7712. var clipping_planes_pars_fragment = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n\tuniform vec4 clippingPlanes[ NUM_CLIPPING_PLANES ];\n#endif";
  7713. var clipping_planes_pars_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvarying vec3 vClipPosition;\n#endif";
  7714. var clipping_planes_vertex = "#if NUM_CLIPPING_PLANES > 0\n\tvClipPosition = - mvPosition.xyz;\n#endif";
  7715. var color_fragment = "#ifdef USE_COLOR\n\tdiffuseColor.rgb *= vColor;\n#endif";
  7716. var color_pars_fragment = "#ifdef USE_COLOR\n\tvarying vec3 vColor;\n#endif";
  7717. var color_pars_vertex = "#if defined( USE_COLOR ) || defined( USE_INSTANCING_COLOR )\n\tvarying vec3 vColor;\n#endif";
  7718. 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";
  7719. 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}";
  7720. 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";
  7721. 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";
  7722. var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler2D displacementMap;\n\tuniform float displacementScale;\n\tuniform float displacementBias;\n#endif";
  7723. var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vUv ).x * displacementScale + displacementBias );\n#endif";
  7724. var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vUv );\n\temissiveColor.rgb = emissiveMapTexelToLinear( emissiveColor ).rgb;\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
  7725. var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
  7726. var encodings_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
  7727. 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}";
  7728. 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";
  7729. 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";
  7730. 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";
  7731. 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";
  7732. 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";
  7733. var fog_vertex = "#ifdef USE_FOG\n\tfogDepth = - mvPosition.z;\n#endif";
  7734. var fog_pars_vertex = "#ifdef USE_FOG\n\tvarying float fogDepth;\n#endif";
  7735. 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";
  7736. 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";
  7737. 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}";
  7738. var lightmap_fragment = "#ifdef USE_LIGHTMAP\n\tvec4 lightMapTexel= texture2D( lightMap, vUv2 );\n\treflectedLight.indirectDiffuse += PI * lightMapTexelToLinear( lightMapTexel ).rgb * lightMapIntensity;\n#endif";
  7739. var lightmap_pars_fragment = "#ifdef USE_LIGHTMAP\n\tuniform sampler2D lightMap;\n\tuniform float lightMapIntensity;\n#endif";
  7740. 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";
  7741. 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";
  7742. 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";
  7743. var lights_toon_fragment = "ToonMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;";
  7744. 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)";
  7745. var lights_phong_fragment = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;";
  7746. 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)";
  7747. 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";
  7748. 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}";
  7749. 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";
  7750. 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";
  7751. 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";
  7752. 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";
  7753. 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";
  7754. 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";
  7755. 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";
  7756. var map_fragment = "#ifdef USE_MAP\n\tvec4 texelColor = texture2D( map, vUv );\n\ttexelColor = mapTexelToLinear( texelColor );\n\tdiffuseColor *= texelColor;\n#endif";
  7757. var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
  7758. 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";
  7759. 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";
  7760. var metalnessmap_fragment = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n\tvec4 texelMetalness = texture2D( metalnessMap, vUv );\n\tmetalnessFactor *= texelMetalness.b;\n#endif";
  7761. var metalnessmap_pars_fragment = "#ifdef USE_METALNESSMAP\n\tuniform sampler2D metalnessMap;\n#endif";
  7762. 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";
  7763. 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";
  7764. 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";
  7765. 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;";
  7766. 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";
  7767. 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";
  7768. var clearcoat_normal_fragment_begin = "#ifdef CLEARCOAT\n\tvec3 clearcoatNormal = geometryNormal;\n#endif";
  7769. 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";
  7770. 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";
  7771. 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}";
  7772. var premultiplied_alpha_fragment = "#ifdef PREMULTIPLIED_ALPHA\n\tgl_FragColor.rgb *= gl_FragColor.a;\n#endif";
  7773. 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;";
  7774. var dithering_fragment = "#ifdef DITHERING\n\tgl_FragColor.rgb = dithering( gl_FragColor.rgb );\n#endif";
  7775. 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";
  7776. var roughnessmap_fragment = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n\tvec4 texelRoughness = texture2D( roughnessMap, vUv );\n\troughnessFactor *= texelRoughness.g;\n#endif";
  7777. var roughnessmap_pars_fragment = "#ifdef USE_ROUGHNESSMAP\n\tuniform sampler2D roughnessMap;\n#endif";
  7778. 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";
  7779. 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";
  7780. 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";
  7781. 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}";
  7782. 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";
  7783. 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";
  7784. 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";
  7785. 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";
  7786. 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";
  7787. var specularmap_pars_fragment = "#ifdef USE_SPECULARMAP\n\tuniform sampler2D specularMap;\n#endif";
  7788. var tonemapping_fragment = "#if defined( TONE_MAPPING )\n\tgl_FragColor.rgb = toneMapping( gl_FragColor.rgb );\n#endif";
  7789. 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; }";
  7790. var transmissionmap_fragment = "#ifdef USE_TRANSMISSIONMAP\n\ttotalTransmission *= texture2D( transmissionMap, vUv ).r;\n#endif";
  7791. var transmissionmap_pars_fragment = "#ifdef USE_TRANSMISSIONMAP\n\tuniform sampler2D transmissionMap;\n#endif";
  7792. var uv_pars_fragment = "#if ( defined( USE_UV ) && ! defined( UVS_VERTEX_ONLY ) )\n\tvarying vec2 vUv;\n#endif";
  7793. 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";
  7794. var uv_vertex = "#ifdef USE_UV\n\tvUv = ( uvTransform * vec3( uv, 1 ) ).xy;\n#endif";
  7795. var uv2_pars_fragment = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvarying vec2 vUv2;\n#endif";
  7796. 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";
  7797. var uv2_vertex = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\tvUv2 = ( uv2Transform * vec3( uv2, 1 ) ).xy;\n#endif";
  7798. 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";
  7799. 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}";
  7800. 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}";
  7801. 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}";
  7802. 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}";
  7803. 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}";
  7804. 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}";
  7805. 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}";
  7806. 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}";
  7807. 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}";
  7808. 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}";
  7809. 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}";
  7810. 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}";
  7811. 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}";
  7812. 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}";
  7813. 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}";
  7814. 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}";
  7815. 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}";
  7816. 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}";
  7817. 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}";
  7818. 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}";
  7819. 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}";
  7820. 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}";
  7821. 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}";
  7822. 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}";
  7823. 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}";
  7824. 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}";
  7825. 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}";
  7826. 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}";
  7827. 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}";
  7828. 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}";
  7829. 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}";
  7830. 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}";
  7831. const ShaderChunk = {
  7832. alphamap_fragment: alphamap_fragment,
  7833. alphamap_pars_fragment: alphamap_pars_fragment,
  7834. alphatest_fragment: alphatest_fragment,
  7835. aomap_fragment: aomap_fragment,
  7836. aomap_pars_fragment: aomap_pars_fragment,
  7837. begin_vertex: begin_vertex,
  7838. beginnormal_vertex: beginnormal_vertex,
  7839. bsdfs: bsdfs,
  7840. bumpmap_pars_fragment: bumpmap_pars_fragment,
  7841. clipping_planes_fragment: clipping_planes_fragment,
  7842. clipping_planes_pars_fragment: clipping_planes_pars_fragment,
  7843. clipping_planes_pars_vertex: clipping_planes_pars_vertex,
  7844. clipping_planes_vertex: clipping_planes_vertex,
  7845. color_fragment: color_fragment,
  7846. color_pars_fragment: color_pars_fragment,
  7847. color_pars_vertex: color_pars_vertex,
  7848. color_vertex: color_vertex,
  7849. common: common,
  7850. cube_uv_reflection_fragment: cube_uv_reflection_fragment,
  7851. defaultnormal_vertex: defaultnormal_vertex,
  7852. displacementmap_pars_vertex: displacementmap_pars_vertex,
  7853. displacementmap_vertex: displacementmap_vertex,
  7854. emissivemap_fragment: emissivemap_fragment,
  7855. emissivemap_pars_fragment: emissivemap_pars_fragment,
  7856. encodings_fragment: encodings_fragment,
  7857. encodings_pars_fragment: encodings_pars_fragment,
  7858. envmap_fragment: envmap_fragment,
  7859. envmap_common_pars_fragment: envmap_common_pars_fragment,
  7860. envmap_pars_fragment: envmap_pars_fragment,
  7861. envmap_pars_vertex: envmap_pars_vertex,
  7862. envmap_physical_pars_fragment: envmap_physical_pars_fragment,
  7863. envmap_vertex: envmap_vertex,
  7864. fog_vertex: fog_vertex,
  7865. fog_pars_vertex: fog_pars_vertex,
  7866. fog_fragment: fog_fragment,
  7867. fog_pars_fragment: fog_pars_fragment,
  7868. gradientmap_pars_fragment: gradientmap_pars_fragment,
  7869. lightmap_fragment: lightmap_fragment,
  7870. lightmap_pars_fragment: lightmap_pars_fragment,
  7871. lights_lambert_vertex: lights_lambert_vertex,
  7872. lights_pars_begin: lights_pars_begin,
  7873. lights_toon_fragment: lights_toon_fragment,
  7874. lights_toon_pars_fragment: lights_toon_pars_fragment,
  7875. lights_phong_fragment: lights_phong_fragment,
  7876. lights_phong_pars_fragment: lights_phong_pars_fragment,
  7877. lights_physical_fragment: lights_physical_fragment,
  7878. lights_physical_pars_fragment: lights_physical_pars_fragment,
  7879. lights_fragment_begin: lights_fragment_begin,
  7880. lights_fragment_maps: lights_fragment_maps,
  7881. lights_fragment_end: lights_fragment_end,
  7882. logdepthbuf_fragment: logdepthbuf_fragment,
  7883. logdepthbuf_pars_fragment: logdepthbuf_pars_fragment,
  7884. logdepthbuf_pars_vertex: logdepthbuf_pars_vertex,
  7885. logdepthbuf_vertex: logdepthbuf_vertex,
  7886. map_fragment: map_fragment,
  7887. map_pars_fragment: map_pars_fragment,
  7888. map_particle_fragment: map_particle_fragment,
  7889. map_particle_pars_fragment: map_particle_pars_fragment,
  7890. metalnessmap_fragment: metalnessmap_fragment,
  7891. metalnessmap_pars_fragment: metalnessmap_pars_fragment,
  7892. morphnormal_vertex: morphnormal_vertex,
  7893. morphtarget_pars_vertex: morphtarget_pars_vertex,
  7894. morphtarget_vertex: morphtarget_vertex,
  7895. normal_fragment_begin: normal_fragment_begin,
  7896. normal_fragment_maps: normal_fragment_maps,
  7897. normalmap_pars_fragment: normalmap_pars_fragment,
  7898. clearcoat_normal_fragment_begin: clearcoat_normal_fragment_begin,
  7899. clearcoat_normal_fragment_maps: clearcoat_normal_fragment_maps,
  7900. clearcoat_pars_fragment: clearcoat_pars_fragment,
  7901. packing: packing,
  7902. premultiplied_alpha_fragment: premultiplied_alpha_fragment,
  7903. project_vertex: project_vertex,
  7904. dithering_fragment: dithering_fragment,
  7905. dithering_pars_fragment: dithering_pars_fragment,
  7906. roughnessmap_fragment: roughnessmap_fragment,
  7907. roughnessmap_pars_fragment: roughnessmap_pars_fragment,
  7908. shadowmap_pars_fragment: shadowmap_pars_fragment,
  7909. shadowmap_pars_vertex: shadowmap_pars_vertex,
  7910. shadowmap_vertex: shadowmap_vertex,
  7911. shadowmask_pars_fragment: shadowmask_pars_fragment,
  7912. skinbase_vertex: skinbase_vertex,
  7913. skinning_pars_vertex: skinning_pars_vertex,
  7914. skinning_vertex: skinning_vertex,
  7915. skinnormal_vertex: skinnormal_vertex,
  7916. specularmap_fragment: specularmap_fragment,
  7917. specularmap_pars_fragment: specularmap_pars_fragment,
  7918. tonemapping_fragment: tonemapping_fragment,
  7919. tonemapping_pars_fragment: tonemapping_pars_fragment,
  7920. transmissionmap_fragment: transmissionmap_fragment,
  7921. transmissionmap_pars_fragment: transmissionmap_pars_fragment,
  7922. uv_pars_fragment: uv_pars_fragment,
  7923. uv_pars_vertex: uv_pars_vertex,
  7924. uv_vertex: uv_vertex,
  7925. uv2_pars_fragment: uv2_pars_fragment,
  7926. uv2_pars_vertex: uv2_pars_vertex,
  7927. uv2_vertex: uv2_vertex,
  7928. worldpos_vertex: worldpos_vertex,
  7929. background_frag: background_frag,
  7930. background_vert: background_vert,
  7931. cube_frag: cube_frag,
  7932. cube_vert: cube_vert,
  7933. depth_frag: depth_frag,
  7934. depth_vert: depth_vert,
  7935. distanceRGBA_frag: distanceRGBA_frag,
  7936. distanceRGBA_vert: distanceRGBA_vert,
  7937. equirect_frag: equirect_frag,
  7938. equirect_vert: equirect_vert,
  7939. linedashed_frag: linedashed_frag,
  7940. linedashed_vert: linedashed_vert,
  7941. meshbasic_frag: meshbasic_frag,
  7942. meshbasic_vert: meshbasic_vert,
  7943. meshlambert_frag: meshlambert_frag,
  7944. meshlambert_vert: meshlambert_vert,
  7945. meshmatcap_frag: meshmatcap_frag,
  7946. meshmatcap_vert: meshmatcap_vert,
  7947. meshtoon_frag: meshtoon_frag,
  7948. meshtoon_vert: meshtoon_vert,
  7949. meshphong_frag: meshphong_frag,
  7950. meshphong_vert: meshphong_vert,
  7951. meshphysical_frag: meshphysical_frag,
  7952. meshphysical_vert: meshphysical_vert,
  7953. normal_frag: normal_frag,
  7954. normal_vert: normal_vert,
  7955. points_frag: points_frag,
  7956. points_vert: points_vert,
  7957. shadow_frag: shadow_frag,
  7958. shadow_vert: shadow_vert,
  7959. sprite_frag: sprite_frag,
  7960. sprite_vert: sprite_vert
  7961. };
  7962. /**
  7963. * Uniforms library for shared webgl shaders
  7964. */
  7965. const UniformsLib = {
  7966. common: {
  7967. diffuse: { value: new Color( 0xeeeeee ) },
  7968. opacity: { value: 1.0 },
  7969. map: { value: null },
  7970. uvTransform: { value: new Matrix3() },
  7971. uv2Transform: { value: new Matrix3() },
  7972. alphaMap: { value: null },
  7973. },
  7974. specularmap: {
  7975. specularMap: { value: null },
  7976. },
  7977. envmap: {
  7978. envMap: { value: null },
  7979. flipEnvMap: { value: - 1 },
  7980. reflectivity: { value: 1.0 },
  7981. refractionRatio: { value: 0.98 },
  7982. maxMipLevel: { value: 0 }
  7983. },
  7984. aomap: {
  7985. aoMap: { value: null },
  7986. aoMapIntensity: { value: 1 }
  7987. },
  7988. lightmap: {
  7989. lightMap: { value: null },
  7990. lightMapIntensity: { value: 1 }
  7991. },
  7992. emissivemap: {
  7993. emissiveMap: { value: null }
  7994. },
  7995. bumpmap: {
  7996. bumpMap: { value: null },
  7997. bumpScale: { value: 1 }
  7998. },
  7999. normalmap: {
  8000. normalMap: { value: null },
  8001. normalScale: { value: new Vector2( 1, 1 ) }
  8002. },
  8003. displacementmap: {
  8004. displacementMap: { value: null },
  8005. displacementScale: { value: 1 },
  8006. displacementBias: { value: 0 }
  8007. },
  8008. roughnessmap: {
  8009. roughnessMap: { value: null }
  8010. },
  8011. metalnessmap: {
  8012. metalnessMap: { value: null }
  8013. },
  8014. gradientmap: {
  8015. gradientMap: { value: null }
  8016. },
  8017. fog: {
  8018. fogDensity: { value: 0.00025 },
  8019. fogNear: { value: 1 },
  8020. fogFar: { value: 2000 },
  8021. fogColor: { value: new Color( 0xffffff ) }
  8022. },
  8023. lights: {
  8024. ambientLightColor: { value: [] },
  8025. lightProbe: { value: [] },
  8026. directionalLights: { value: [], properties: {
  8027. direction: {},
  8028. color: {}
  8029. } },
  8030. directionalLightShadows: { value: [], properties: {
  8031. shadowBias: {},
  8032. shadowNormalBias: {},
  8033. shadowRadius: {},
  8034. shadowMapSize: {}
  8035. } },
  8036. directionalShadowMap: { value: [] },
  8037. directionalShadowMatrix: { value: [] },
  8038. spotLights: { value: [], properties: {
  8039. color: {},
  8040. position: {},
  8041. direction: {},
  8042. distance: {},
  8043. coneCos: {},
  8044. penumbraCos: {},
  8045. decay: {}
  8046. } },
  8047. spotLightShadows: { value: [], properties: {
  8048. shadowBias: {},
  8049. shadowNormalBias: {},
  8050. shadowRadius: {},
  8051. shadowMapSize: {}
  8052. } },
  8053. spotShadowMap: { value: [] },
  8054. spotShadowMatrix: { value: [] },
  8055. pointLights: { value: [], properties: {
  8056. color: {},
  8057. position: {},
  8058. decay: {},
  8059. distance: {}
  8060. } },
  8061. pointLightShadows: { value: [], properties: {
  8062. shadowBias: {},
  8063. shadowNormalBias: {},
  8064. shadowRadius: {},
  8065. shadowMapSize: {},
  8066. shadowCameraNear: {},
  8067. shadowCameraFar: {}
  8068. } },
  8069. pointShadowMap: { value: [] },
  8070. pointShadowMatrix: { value: [] },
  8071. hemisphereLights: { value: [], properties: {
  8072. direction: {},
  8073. skyColor: {},
  8074. groundColor: {}
  8075. } },
  8076. // TODO (abelnation): RectAreaLight BRDF data needs to be moved from example to main src
  8077. rectAreaLights: { value: [], properties: {
  8078. color: {},
  8079. position: {},
  8080. width: {},
  8081. height: {}
  8082. } },
  8083. ltc_1: { value: null },
  8084. ltc_2: { value: null }
  8085. },
  8086. points: {
  8087. diffuse: { value: new Color( 0xeeeeee ) },
  8088. opacity: { value: 1.0 },
  8089. size: { value: 1.0 },
  8090. scale: { value: 1.0 },
  8091. map: { value: null },
  8092. alphaMap: { value: null },
  8093. uvTransform: { value: new Matrix3() }
  8094. },
  8095. sprite: {
  8096. diffuse: { value: new Color( 0xeeeeee ) },
  8097. opacity: { value: 1.0 },
  8098. center: { value: new Vector2( 0.5, 0.5 ) },
  8099. rotation: { value: 0.0 },
  8100. map: { value: null },
  8101. alphaMap: { value: null },
  8102. uvTransform: { value: new Matrix3() }
  8103. }
  8104. };
  8105. const ShaderLib = {
  8106. basic: {
  8107. uniforms: mergeUniforms( [
  8108. UniformsLib.common,
  8109. UniformsLib.specularmap,
  8110. UniformsLib.envmap,
  8111. UniformsLib.aomap,
  8112. UniformsLib.lightmap,
  8113. UniformsLib.fog
  8114. ] ),
  8115. vertexShader: ShaderChunk.meshbasic_vert,
  8116. fragmentShader: ShaderChunk.meshbasic_frag
  8117. },
  8118. lambert: {
  8119. uniforms: mergeUniforms( [
  8120. UniformsLib.common,
  8121. UniformsLib.specularmap,
  8122. UniformsLib.envmap,
  8123. UniformsLib.aomap,
  8124. UniformsLib.lightmap,
  8125. UniformsLib.emissivemap,
  8126. UniformsLib.fog,
  8127. UniformsLib.lights,
  8128. {
  8129. emissive: { value: new Color( 0x000000 ) }
  8130. }
  8131. ] ),
  8132. vertexShader: ShaderChunk.meshlambert_vert,
  8133. fragmentShader: ShaderChunk.meshlambert_frag
  8134. },
  8135. phong: {
  8136. uniforms: mergeUniforms( [
  8137. UniformsLib.common,
  8138. UniformsLib.specularmap,
  8139. UniformsLib.envmap,
  8140. UniformsLib.aomap,
  8141. UniformsLib.lightmap,
  8142. UniformsLib.emissivemap,
  8143. UniformsLib.bumpmap,
  8144. UniformsLib.normalmap,
  8145. UniformsLib.displacementmap,
  8146. UniformsLib.fog,
  8147. UniformsLib.lights,
  8148. {
  8149. emissive: { value: new Color( 0x000000 ) },
  8150. specular: { value: new Color( 0x111111 ) },
  8151. shininess: { value: 30 }
  8152. }
  8153. ] ),
  8154. vertexShader: ShaderChunk.meshphong_vert,
  8155. fragmentShader: ShaderChunk.meshphong_frag
  8156. },
  8157. standard: {
  8158. uniforms: mergeUniforms( [
  8159. UniformsLib.common,
  8160. UniformsLib.envmap,
  8161. UniformsLib.aomap,
  8162. UniformsLib.lightmap,
  8163. UniformsLib.emissivemap,
  8164. UniformsLib.bumpmap,
  8165. UniformsLib.normalmap,
  8166. UniformsLib.displacementmap,
  8167. UniformsLib.roughnessmap,
  8168. UniformsLib.metalnessmap,
  8169. UniformsLib.fog,
  8170. UniformsLib.lights,
  8171. {
  8172. emissive: { value: new Color( 0x000000 ) },
  8173. roughness: { value: 1.0 },
  8174. metalness: { value: 0.0 },
  8175. envMapIntensity: { value: 1 } // temporary
  8176. }
  8177. ] ),
  8178. vertexShader: ShaderChunk.meshphysical_vert,
  8179. fragmentShader: ShaderChunk.meshphysical_frag
  8180. },
  8181. toon: {
  8182. uniforms: mergeUniforms( [
  8183. UniformsLib.common,
  8184. UniformsLib.aomap,
  8185. UniformsLib.lightmap,
  8186. UniformsLib.emissivemap,
  8187. UniformsLib.bumpmap,
  8188. UniformsLib.normalmap,
  8189. UniformsLib.displacementmap,
  8190. UniformsLib.gradientmap,
  8191. UniformsLib.fog,
  8192. UniformsLib.lights,
  8193. {
  8194. emissive: { value: new Color( 0x000000 ) }
  8195. }
  8196. ] ),
  8197. vertexShader: ShaderChunk.meshtoon_vert,
  8198. fragmentShader: ShaderChunk.meshtoon_frag
  8199. },
  8200. matcap: {
  8201. uniforms: mergeUniforms( [
  8202. UniformsLib.common,
  8203. UniformsLib.bumpmap,
  8204. UniformsLib.normalmap,
  8205. UniformsLib.displacementmap,
  8206. UniformsLib.fog,
  8207. {
  8208. matcap: { value: null }
  8209. }
  8210. ] ),
  8211. vertexShader: ShaderChunk.meshmatcap_vert,
  8212. fragmentShader: ShaderChunk.meshmatcap_frag
  8213. },
  8214. points: {
  8215. uniforms: mergeUniforms( [
  8216. UniformsLib.points,
  8217. UniformsLib.fog
  8218. ] ),
  8219. vertexShader: ShaderChunk.points_vert,
  8220. fragmentShader: ShaderChunk.points_frag
  8221. },
  8222. dashed: {
  8223. uniforms: mergeUniforms( [
  8224. UniformsLib.common,
  8225. UniformsLib.fog,
  8226. {
  8227. scale: { value: 1 },
  8228. dashSize: { value: 1 },
  8229. totalSize: { value: 2 }
  8230. }
  8231. ] ),
  8232. vertexShader: ShaderChunk.linedashed_vert,
  8233. fragmentShader: ShaderChunk.linedashed_frag
  8234. },
  8235. depth: {
  8236. uniforms: mergeUniforms( [
  8237. UniformsLib.common,
  8238. UniformsLib.displacementmap
  8239. ] ),
  8240. vertexShader: ShaderChunk.depth_vert,
  8241. fragmentShader: ShaderChunk.depth_frag
  8242. },
  8243. normal: {
  8244. uniforms: mergeUniforms( [
  8245. UniformsLib.common,
  8246. UniformsLib.bumpmap,
  8247. UniformsLib.normalmap,
  8248. UniformsLib.displacementmap,
  8249. {
  8250. opacity: { value: 1.0 }
  8251. }
  8252. ] ),
  8253. vertexShader: ShaderChunk.normal_vert,
  8254. fragmentShader: ShaderChunk.normal_frag
  8255. },
  8256. sprite: {
  8257. uniforms: mergeUniforms( [
  8258. UniformsLib.sprite,
  8259. UniformsLib.fog
  8260. ] ),
  8261. vertexShader: ShaderChunk.sprite_vert,
  8262. fragmentShader: ShaderChunk.sprite_frag
  8263. },
  8264. background: {
  8265. uniforms: {
  8266. uvTransform: { value: new Matrix3() },
  8267. t2D: { value: null },
  8268. },
  8269. vertexShader: ShaderChunk.background_vert,
  8270. fragmentShader: ShaderChunk.background_frag
  8271. },
  8272. /* -------------------------------------------------------------------------
  8273. // Cube map shader
  8274. ------------------------------------------------------------------------- */
  8275. cube: {
  8276. uniforms: mergeUniforms( [
  8277. UniformsLib.envmap,
  8278. {
  8279. opacity: { value: 1.0 }
  8280. }
  8281. ] ),
  8282. vertexShader: ShaderChunk.cube_vert,
  8283. fragmentShader: ShaderChunk.cube_frag
  8284. },
  8285. equirect: {
  8286. uniforms: {
  8287. tEquirect: { value: null },
  8288. },
  8289. vertexShader: ShaderChunk.equirect_vert,
  8290. fragmentShader: ShaderChunk.equirect_frag
  8291. },
  8292. distanceRGBA: {
  8293. uniforms: mergeUniforms( [
  8294. UniformsLib.common,
  8295. UniformsLib.displacementmap,
  8296. {
  8297. referencePosition: { value: new Vector3() },
  8298. nearDistance: { value: 1 },
  8299. farDistance: { value: 1000 }
  8300. }
  8301. ] ),
  8302. vertexShader: ShaderChunk.distanceRGBA_vert,
  8303. fragmentShader: ShaderChunk.distanceRGBA_frag
  8304. },
  8305. shadow: {
  8306. uniforms: mergeUniforms( [
  8307. UniformsLib.lights,
  8308. UniformsLib.fog,
  8309. {
  8310. color: { value: new Color( 0x00000 ) },
  8311. opacity: { value: 1.0 }
  8312. },
  8313. ] ),
  8314. vertexShader: ShaderChunk.shadow_vert,
  8315. fragmentShader: ShaderChunk.shadow_frag
  8316. }
  8317. };
  8318. ShaderLib.physical = {
  8319. uniforms: mergeUniforms( [
  8320. ShaderLib.standard.uniforms,
  8321. {
  8322. clearcoat: { value: 0 },
  8323. clearcoatMap: { value: null },
  8324. clearcoatRoughness: { value: 0 },
  8325. clearcoatRoughnessMap: { value: null },
  8326. clearcoatNormalScale: { value: new Vector2( 1, 1 ) },
  8327. clearcoatNormalMap: { value: null },
  8328. sheen: { value: new Color( 0x000000 ) },
  8329. transmission: { value: 0 },
  8330. transmissionMap: { value: null },
  8331. }
  8332. ] ),
  8333. vertexShader: ShaderChunk.meshphysical_vert,
  8334. fragmentShader: ShaderChunk.meshphysical_frag
  8335. };
  8336. function WebGLBackground( renderer, cubemaps, state, objects, premultipliedAlpha ) {
  8337. const clearColor = new Color( 0x000000 );
  8338. let clearAlpha = 0;
  8339. let planeMesh;
  8340. let boxMesh;
  8341. let currentBackground = null;
  8342. let currentBackgroundVersion = 0;
  8343. let currentTonemapping = null;
  8344. function render( renderList, scene, camera, forceClear ) {
  8345. let background = scene.isScene === true ? scene.background : null;
  8346. if ( background && background.isTexture ) {
  8347. background = cubemaps.get( background );
  8348. }
  8349. // Ignore background in AR
  8350. // TODO: Reconsider this.
  8351. const xr = renderer.xr;
  8352. const session = xr.getSession && xr.getSession();
  8353. if ( session && session.environmentBlendMode === 'additive' ) {
  8354. background = null;
  8355. }
  8356. if ( background === null ) {
  8357. setClear( clearColor, clearAlpha );
  8358. } else if ( background && background.isColor ) {
  8359. setClear( background, 1 );
  8360. forceClear = true;
  8361. }
  8362. if ( renderer.autoClear || forceClear ) {
  8363. renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  8364. }
  8365. if ( background && ( background.isCubeTexture || background.isWebGLCubeRenderTarget || background.mapping === CubeUVReflectionMapping ) ) {
  8366. if ( boxMesh === undefined ) {
  8367. boxMesh = new Mesh(
  8368. new BoxBufferGeometry( 1, 1, 1 ),
  8369. new ShaderMaterial( {
  8370. name: 'BackgroundCubeMaterial',
  8371. uniforms: cloneUniforms( ShaderLib.cube.uniforms ),
  8372. vertexShader: ShaderLib.cube.vertexShader,
  8373. fragmentShader: ShaderLib.cube.fragmentShader,
  8374. side: BackSide,
  8375. depthTest: false,
  8376. depthWrite: false,
  8377. fog: false
  8378. } )
  8379. );
  8380. boxMesh.geometry.deleteAttribute( 'normal' );
  8381. boxMesh.geometry.deleteAttribute( 'uv' );
  8382. boxMesh.onBeforeRender = function ( renderer, scene, camera ) {
  8383. this.matrixWorld.copyPosition( camera.matrixWorld );
  8384. };
  8385. // enable code injection for non-built-in material
  8386. Object.defineProperty( boxMesh.material, 'envMap', {
  8387. get: function () {
  8388. return this.uniforms.envMap.value;
  8389. }
  8390. } );
  8391. objects.update( boxMesh );
  8392. }
  8393. if ( background.isWebGLCubeRenderTarget ) {
  8394. // TODO Deprecate
  8395. background = background.texture;
  8396. }
  8397. boxMesh.material.uniforms.envMap.value = background;
  8398. boxMesh.material.uniforms.flipEnvMap.value = ( background.isCubeTexture && background._needsFlipEnvMap ) ? - 1 : 1;
  8399. if ( currentBackground !== background ||
  8400. currentBackgroundVersion !== background.version ||
  8401. currentTonemapping !== renderer.toneMapping ) {
  8402. boxMesh.material.needsUpdate = true;
  8403. currentBackground = background;
  8404. currentBackgroundVersion = background.version;
  8405. currentTonemapping = renderer.toneMapping;
  8406. }
  8407. // push to the pre-sorted opaque render list
  8408. renderList.unshift( boxMesh, boxMesh.geometry, boxMesh.material, 0, 0, null );
  8409. } else if ( background && background.isTexture ) {
  8410. if ( planeMesh === undefined ) {
  8411. planeMesh = new Mesh(
  8412. new PlaneBufferGeometry( 2, 2 ),
  8413. new ShaderMaterial( {
  8414. name: 'BackgroundMaterial',
  8415. uniforms: cloneUniforms( ShaderLib.background.uniforms ),
  8416. vertexShader: ShaderLib.background.vertexShader,
  8417. fragmentShader: ShaderLib.background.fragmentShader,
  8418. side: FrontSide,
  8419. depthTest: false,
  8420. depthWrite: false,
  8421. fog: false
  8422. } )
  8423. );
  8424. planeMesh.geometry.deleteAttribute( 'normal' );
  8425. // enable code injection for non-built-in material
  8426. Object.defineProperty( planeMesh.material, 'map', {
  8427. get: function () {
  8428. return this.uniforms.t2D.value;
  8429. }
  8430. } );
  8431. objects.update( planeMesh );
  8432. }
  8433. planeMesh.material.uniforms.t2D.value = background;
  8434. if ( background.matrixAutoUpdate === true ) {
  8435. background.updateMatrix();
  8436. }
  8437. planeMesh.material.uniforms.uvTransform.value.copy( background.matrix );
  8438. if ( currentBackground !== background ||
  8439. currentBackgroundVersion !== background.version ||
  8440. currentTonemapping !== renderer.toneMapping ) {
  8441. planeMesh.material.needsUpdate = true;
  8442. currentBackground = background;
  8443. currentBackgroundVersion = background.version;
  8444. currentTonemapping = renderer.toneMapping;
  8445. }
  8446. // push to the pre-sorted opaque render list
  8447. renderList.unshift( planeMesh, planeMesh.geometry, planeMesh.material, 0, 0, null );
  8448. }
  8449. }
  8450. function setClear( color, alpha ) {
  8451. state.buffers.color.setClear( color.r, color.g, color.b, alpha, premultipliedAlpha );
  8452. }
  8453. return {
  8454. getClearColor: function () {
  8455. return clearColor;
  8456. },
  8457. setClearColor: function ( color, alpha = 1 ) {
  8458. clearColor.set( color );
  8459. clearAlpha = alpha;
  8460. setClear( clearColor, clearAlpha );
  8461. },
  8462. getClearAlpha: function () {
  8463. return clearAlpha;
  8464. },
  8465. setClearAlpha: function ( alpha ) {
  8466. clearAlpha = alpha;
  8467. setClear( clearColor, clearAlpha );
  8468. },
  8469. render: render
  8470. };
  8471. }
  8472. function WebGLBindingStates( gl, extensions, attributes, capabilities ) {
  8473. const maxVertexAttributes = gl.getParameter( 34921 );
  8474. const extension = capabilities.isWebGL2 ? null : extensions.get( 'OES_vertex_array_object' );
  8475. const vaoAvailable = capabilities.isWebGL2 || extension !== null;
  8476. const bindingStates = {};
  8477. const defaultState = createBindingState( null );
  8478. let currentState = defaultState;
  8479. function setup( object, material, program, geometry, index ) {
  8480. let updateBuffers = false;
  8481. if ( vaoAvailable ) {
  8482. const state = getBindingState( geometry, program, material );
  8483. if ( currentState !== state ) {
  8484. currentState = state;
  8485. bindVertexArrayObject( currentState.object );
  8486. }
  8487. updateBuffers = needsUpdate( geometry, index );
  8488. if ( updateBuffers ) saveCache( geometry, index );
  8489. } else {
  8490. const wireframe = ( material.wireframe === true );
  8491. if ( currentState.geometry !== geometry.id ||
  8492. currentState.program !== program.id ||
  8493. currentState.wireframe !== wireframe ) {
  8494. currentState.geometry = geometry.id;
  8495. currentState.program = program.id;
  8496. currentState.wireframe = wireframe;
  8497. updateBuffers = true;
  8498. }
  8499. }
  8500. if ( object.isInstancedMesh === true ) {
  8501. updateBuffers = true;
  8502. }
  8503. if ( index !== null ) {
  8504. attributes.update( index, 34963 );
  8505. }
  8506. if ( updateBuffers ) {
  8507. setupVertexAttributes( object, material, program, geometry );
  8508. if ( index !== null ) {
  8509. gl.bindBuffer( 34963, attributes.get( index ).buffer );
  8510. }
  8511. }
  8512. }
  8513. function createVertexArrayObject() {
  8514. if ( capabilities.isWebGL2 ) return gl.createVertexArray();
  8515. return extension.createVertexArrayOES();
  8516. }
  8517. function bindVertexArrayObject( vao ) {
  8518. if ( capabilities.isWebGL2 ) return gl.bindVertexArray( vao );
  8519. return extension.bindVertexArrayOES( vao );
  8520. }
  8521. function deleteVertexArrayObject( vao ) {
  8522. if ( capabilities.isWebGL2 ) return gl.deleteVertexArray( vao );
  8523. return extension.deleteVertexArrayOES( vao );
  8524. }
  8525. function getBindingState( geometry, program, material ) {
  8526. const wireframe = ( material.wireframe === true );
  8527. let programMap = bindingStates[ geometry.id ];
  8528. if ( programMap === undefined ) {
  8529. programMap = {};
  8530. bindingStates[ geometry.id ] = programMap;
  8531. }
  8532. let stateMap = programMap[ program.id ];
  8533. if ( stateMap === undefined ) {
  8534. stateMap = {};
  8535. programMap[ program.id ] = stateMap;
  8536. }
  8537. let state = stateMap[ wireframe ];
  8538. if ( state === undefined ) {
  8539. state = createBindingState( createVertexArrayObject() );
  8540. stateMap[ wireframe ] = state;
  8541. }
  8542. return state;
  8543. }
  8544. function createBindingState( vao ) {
  8545. const newAttributes = [];
  8546. const enabledAttributes = [];
  8547. const attributeDivisors = [];
  8548. for ( let i = 0; i < maxVertexAttributes; i ++ ) {
  8549. newAttributes[ i ] = 0;
  8550. enabledAttributes[ i ] = 0;
  8551. attributeDivisors[ i ] = 0;
  8552. }
  8553. return {
  8554. // for backward compatibility on non-VAO support browser
  8555. geometry: null,
  8556. program: null,
  8557. wireframe: false,
  8558. newAttributes: newAttributes,
  8559. enabledAttributes: enabledAttributes,
  8560. attributeDivisors: attributeDivisors,
  8561. object: vao,
  8562. attributes: {},
  8563. index: null
  8564. };
  8565. }
  8566. function needsUpdate( geometry, index ) {
  8567. const cachedAttributes = currentState.attributes;
  8568. const geometryAttributes = geometry.attributes;
  8569. let attributesNum = 0;
  8570. for ( const key in geometryAttributes ) {
  8571. const cachedAttribute = cachedAttributes[ key ];
  8572. const geometryAttribute = geometryAttributes[ key ];
  8573. if ( cachedAttribute === undefined ) return true;
  8574. if ( cachedAttribute.attribute !== geometryAttribute ) return true;
  8575. if ( cachedAttribute.data !== geometryAttribute.data ) return true;
  8576. attributesNum ++;
  8577. }
  8578. if ( currentState.attributesNum !== attributesNum ) return true;
  8579. if ( currentState.index !== index ) return true;
  8580. return false;
  8581. }
  8582. function saveCache( geometry, index ) {
  8583. const cache = {};
  8584. const attributes = geometry.attributes;
  8585. let attributesNum = 0;
  8586. for ( const key in attributes ) {
  8587. const attribute = attributes[ key ];
  8588. const data = {};
  8589. data.attribute = attribute;
  8590. if ( attribute.data ) {
  8591. data.data = attribute.data;
  8592. }
  8593. cache[ key ] = data;
  8594. attributesNum ++;
  8595. }
  8596. currentState.attributes = cache;
  8597. currentState.attributesNum = attributesNum;
  8598. currentState.index = index;
  8599. }
  8600. function initAttributes() {
  8601. const newAttributes = currentState.newAttributes;
  8602. for ( let i = 0, il = newAttributes.length; i < il; i ++ ) {
  8603. newAttributes[ i ] = 0;
  8604. }
  8605. }
  8606. function enableAttribute( attribute ) {
  8607. enableAttributeAndDivisor( attribute, 0 );
  8608. }
  8609. function enableAttributeAndDivisor( attribute, meshPerAttribute ) {
  8610. const newAttributes = currentState.newAttributes;
  8611. const enabledAttributes = currentState.enabledAttributes;
  8612. const attributeDivisors = currentState.attributeDivisors;
  8613. newAttributes[ attribute ] = 1;
  8614. if ( enabledAttributes[ attribute ] === 0 ) {
  8615. gl.enableVertexAttribArray( attribute );
  8616. enabledAttributes[ attribute ] = 1;
  8617. }
  8618. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  8619. const extension = capabilities.isWebGL2 ? gl : extensions.get( 'ANGLE_instanced_arrays' );
  8620. extension[ capabilities.isWebGL2 ? 'vertexAttribDivisor' : 'vertexAttribDivisorANGLE' ]( attribute, meshPerAttribute );
  8621. attributeDivisors[ attribute ] = meshPerAttribute;
  8622. }
  8623. }
  8624. function disableUnusedAttributes() {
  8625. const newAttributes = currentState.newAttributes;
  8626. const enabledAttributes = currentState.enabledAttributes;
  8627. for ( let i = 0, il = enabledAttributes.length; i < il; i ++ ) {
  8628. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  8629. gl.disableVertexAttribArray( i );
  8630. enabledAttributes[ i ] = 0;
  8631. }
  8632. }
  8633. }
  8634. function vertexAttribPointer( index, size, type, normalized, stride, offset ) {
  8635. if ( capabilities.isWebGL2 === true && ( type === 5124 || type === 5125 ) ) {
  8636. gl.vertexAttribIPointer( index, size, type, stride, offset );
  8637. } else {
  8638. gl.vertexAttribPointer( index, size, type, normalized, stride, offset );
  8639. }
  8640. }
  8641. function setupVertexAttributes( object, material, program, geometry ) {
  8642. if ( capabilities.isWebGL2 === false && ( object.isInstancedMesh || geometry.isInstancedBufferGeometry ) ) {
  8643. if ( extensions.get( 'ANGLE_instanced_arrays' ) === null ) return;
  8644. }
  8645. initAttributes();
  8646. const geometryAttributes = geometry.attributes;
  8647. const programAttributes = program.getAttributes();
  8648. const materialDefaultAttributeValues = material.defaultAttributeValues;
  8649. for ( const name in programAttributes ) {
  8650. const programAttribute = programAttributes[ name ];
  8651. if ( programAttribute >= 0 ) {
  8652. const geometryAttribute = geometryAttributes[ name ];
  8653. if ( geometryAttribute !== undefined ) {
  8654. const normalized = geometryAttribute.normalized;
  8655. const size = geometryAttribute.itemSize;
  8656. const attribute = attributes.get( geometryAttribute );
  8657. // TODO Attribute may not be available on context restore
  8658. if ( attribute === undefined ) continue;
  8659. const buffer = attribute.buffer;
  8660. const type = attribute.type;
  8661. const bytesPerElement = attribute.bytesPerElement;
  8662. if ( geometryAttribute.isInterleavedBufferAttribute ) {
  8663. const data = geometryAttribute.data;
  8664. const stride = data.stride;
  8665. const offset = geometryAttribute.offset;
  8666. if ( data && data.isInstancedInterleavedBuffer ) {
  8667. enableAttributeAndDivisor( programAttribute, data.meshPerAttribute );
  8668. if ( geometry._maxInstanceCount === undefined ) {
  8669. geometry._maxInstanceCount = data.meshPerAttribute * data.count;
  8670. }
  8671. } else {
  8672. enableAttribute( programAttribute );
  8673. }
  8674. gl.bindBuffer( 34962, buffer );
  8675. vertexAttribPointer( programAttribute, size, type, normalized, stride * bytesPerElement, offset * bytesPerElement );
  8676. } else {
  8677. if ( geometryAttribute.isInstancedBufferAttribute ) {
  8678. enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute );
  8679. if ( geometry._maxInstanceCount === undefined ) {
  8680. geometry._maxInstanceCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  8681. }
  8682. } else {
  8683. enableAttribute( programAttribute );
  8684. }
  8685. gl.bindBuffer( 34962, buffer );
  8686. vertexAttribPointer( programAttribute, size, type, normalized, 0, 0 );
  8687. }
  8688. } else if ( name === 'instanceMatrix' ) {
  8689. const attribute = attributes.get( object.instanceMatrix );
  8690. // TODO Attribute may not be available on context restore
  8691. if ( attribute === undefined ) continue;
  8692. const buffer = attribute.buffer;
  8693. const type = attribute.type;
  8694. enableAttributeAndDivisor( programAttribute + 0, 1 );
  8695. enableAttributeAndDivisor( programAttribute + 1, 1 );
  8696. enableAttributeAndDivisor( programAttribute + 2, 1 );
  8697. enableAttributeAndDivisor( programAttribute + 3, 1 );
  8698. gl.bindBuffer( 34962, buffer );
  8699. gl.vertexAttribPointer( programAttribute + 0, 4, type, false, 64, 0 );
  8700. gl.vertexAttribPointer( programAttribute + 1, 4, type, false, 64, 16 );
  8701. gl.vertexAttribPointer( programAttribute + 2, 4, type, false, 64, 32 );
  8702. gl.vertexAttribPointer( programAttribute + 3, 4, type, false, 64, 48 );
  8703. } else if ( name === 'instanceColor' ) {
  8704. const attribute = attributes.get( object.instanceColor );
  8705. // TODO Attribute may not be available on context restore
  8706. if ( attribute === undefined ) continue;
  8707. const buffer = attribute.buffer;
  8708. const type = attribute.type;
  8709. enableAttributeAndDivisor( programAttribute, 1 );
  8710. gl.bindBuffer( 34962, buffer );
  8711. gl.vertexAttribPointer( programAttribute, 3, type, false, 12, 0 );
  8712. } else if ( materialDefaultAttributeValues !== undefined ) {
  8713. const value = materialDefaultAttributeValues[ name ];
  8714. if ( value !== undefined ) {
  8715. switch ( value.length ) {
  8716. case 2:
  8717. gl.vertexAttrib2fv( programAttribute, value );
  8718. break;
  8719. case 3:
  8720. gl.vertexAttrib3fv( programAttribute, value );
  8721. break;
  8722. case 4:
  8723. gl.vertexAttrib4fv( programAttribute, value );
  8724. break;
  8725. default:
  8726. gl.vertexAttrib1fv( programAttribute, value );
  8727. }
  8728. }
  8729. }
  8730. }
  8731. }
  8732. disableUnusedAttributes();
  8733. }
  8734. function dispose() {
  8735. reset();
  8736. for ( const geometryId in bindingStates ) {
  8737. const programMap = bindingStates[ geometryId ];
  8738. for ( const programId in programMap ) {
  8739. const stateMap = programMap[ programId ];
  8740. for ( const wireframe in stateMap ) {
  8741. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8742. delete stateMap[ wireframe ];
  8743. }
  8744. delete programMap[ programId ];
  8745. }
  8746. delete bindingStates[ geometryId ];
  8747. }
  8748. }
  8749. function releaseStatesOfGeometry( geometry ) {
  8750. if ( bindingStates[ geometry.id ] === undefined ) return;
  8751. const programMap = bindingStates[ geometry.id ];
  8752. for ( const programId in programMap ) {
  8753. const stateMap = programMap[ programId ];
  8754. for ( const wireframe in stateMap ) {
  8755. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8756. delete stateMap[ wireframe ];
  8757. }
  8758. delete programMap[ programId ];
  8759. }
  8760. delete bindingStates[ geometry.id ];
  8761. }
  8762. function releaseStatesOfProgram( program ) {
  8763. for ( const geometryId in bindingStates ) {
  8764. const programMap = bindingStates[ geometryId ];
  8765. if ( programMap[ program.id ] === undefined ) continue;
  8766. const stateMap = programMap[ program.id ];
  8767. for ( const wireframe in stateMap ) {
  8768. deleteVertexArrayObject( stateMap[ wireframe ].object );
  8769. delete stateMap[ wireframe ];
  8770. }
  8771. delete programMap[ program.id ];
  8772. }
  8773. }
  8774. function reset() {
  8775. resetDefaultState();
  8776. if ( currentState === defaultState ) return;
  8777. currentState = defaultState;
  8778. bindVertexArrayObject( currentState.object );
  8779. }
  8780. // for backward-compatilibity
  8781. function resetDefaultState() {
  8782. defaultState.geometry = null;
  8783. defaultState.program = null;
  8784. defaultState.wireframe = false;
  8785. }
  8786. return {
  8787. setup: setup,
  8788. reset: reset,
  8789. resetDefaultState: resetDefaultState,
  8790. dispose: dispose,
  8791. releaseStatesOfGeometry: releaseStatesOfGeometry,
  8792. releaseStatesOfProgram: releaseStatesOfProgram,
  8793. initAttributes: initAttributes,
  8794. enableAttribute: enableAttribute,
  8795. disableUnusedAttributes: disableUnusedAttributes
  8796. };
  8797. }
  8798. function WebGLBufferRenderer( gl, extensions, info, capabilities ) {
  8799. const isWebGL2 = capabilities.isWebGL2;
  8800. let mode;
  8801. function setMode( value ) {
  8802. mode = value;
  8803. }
  8804. function render( start, count ) {
  8805. gl.drawArrays( mode, start, count );
  8806. info.update( count, mode, 1 );
  8807. }
  8808. function renderInstances( start, count, primcount ) {
  8809. if ( primcount === 0 ) return;
  8810. let extension, methodName;
  8811. if ( isWebGL2 ) {
  8812. extension = gl;
  8813. methodName = 'drawArraysInstanced';
  8814. } else {
  8815. extension = extensions.get( 'ANGLE_instanced_arrays' );
  8816. methodName = 'drawArraysInstancedANGLE';
  8817. if ( extension === null ) {
  8818. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  8819. return;
  8820. }
  8821. }
  8822. extension[ methodName ]( mode, start, count, primcount );
  8823. info.update( count, mode, primcount );
  8824. }
  8825. //
  8826. this.setMode = setMode;
  8827. this.render = render;
  8828. this.renderInstances = renderInstances;
  8829. }
  8830. function WebGLCapabilities( gl, extensions, parameters ) {
  8831. let maxAnisotropy;
  8832. function getMaxAnisotropy() {
  8833. if ( maxAnisotropy !== undefined ) return maxAnisotropy;
  8834. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  8835. if ( extension !== null ) {
  8836. maxAnisotropy = gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  8837. } else {
  8838. maxAnisotropy = 0;
  8839. }
  8840. return maxAnisotropy;
  8841. }
  8842. function getMaxPrecision( precision ) {
  8843. if ( precision === 'highp' ) {
  8844. if ( gl.getShaderPrecisionFormat( 35633, 36338 ).precision > 0 &&
  8845. gl.getShaderPrecisionFormat( 35632, 36338 ).precision > 0 ) {
  8846. return 'highp';
  8847. }
  8848. precision = 'mediump';
  8849. }
  8850. if ( precision === 'mediump' ) {
  8851. if ( gl.getShaderPrecisionFormat( 35633, 36337 ).precision > 0 &&
  8852. gl.getShaderPrecisionFormat( 35632, 36337 ).precision > 0 ) {
  8853. return 'mediump';
  8854. }
  8855. }
  8856. return 'lowp';
  8857. }
  8858. /* eslint-disable no-undef */
  8859. const isWebGL2 = ( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext ) ||
  8860. ( typeof WebGL2ComputeRenderingContext !== 'undefined' && gl instanceof WebGL2ComputeRenderingContext );
  8861. /* eslint-enable no-undef */
  8862. let precision = parameters.precision !== undefined ? parameters.precision : 'highp';
  8863. const maxPrecision = getMaxPrecision( precision );
  8864. if ( maxPrecision !== precision ) {
  8865. console.warn( 'THREE.WebGLRenderer:', precision, 'not supported, using', maxPrecision, 'instead.' );
  8866. precision = maxPrecision;
  8867. }
  8868. const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
  8869. const maxTextures = gl.getParameter( 34930 );
  8870. const maxVertexTextures = gl.getParameter( 35660 );
  8871. const maxTextureSize = gl.getParameter( 3379 );
  8872. const maxCubemapSize = gl.getParameter( 34076 );
  8873. const maxAttributes = gl.getParameter( 34921 );
  8874. const maxVertexUniforms = gl.getParameter( 36347 );
  8875. const maxVaryings = gl.getParameter( 36348 );
  8876. const maxFragmentUniforms = gl.getParameter( 36349 );
  8877. const vertexTextures = maxVertexTextures > 0;
  8878. const floatFragmentTextures = isWebGL2 || !! extensions.get( 'OES_texture_float' );
  8879. const floatVertexTextures = vertexTextures && floatFragmentTextures;
  8880. const maxSamples = isWebGL2 ? gl.getParameter( 36183 ) : 0;
  8881. return {
  8882. isWebGL2: isWebGL2,
  8883. getMaxAnisotropy: getMaxAnisotropy,
  8884. getMaxPrecision: getMaxPrecision,
  8885. precision: precision,
  8886. logarithmicDepthBuffer: logarithmicDepthBuffer,
  8887. maxTextures: maxTextures,
  8888. maxVertexTextures: maxVertexTextures,
  8889. maxTextureSize: maxTextureSize,
  8890. maxCubemapSize: maxCubemapSize,
  8891. maxAttributes: maxAttributes,
  8892. maxVertexUniforms: maxVertexUniforms,
  8893. maxVaryings: maxVaryings,
  8894. maxFragmentUniforms: maxFragmentUniforms,
  8895. vertexTextures: vertexTextures,
  8896. floatFragmentTextures: floatFragmentTextures,
  8897. floatVertexTextures: floatVertexTextures,
  8898. maxSamples: maxSamples
  8899. };
  8900. }
  8901. function WebGLClipping( properties ) {
  8902. const scope = this;
  8903. let globalState = null,
  8904. numGlobalPlanes = 0,
  8905. localClippingEnabled = false,
  8906. renderingShadows = false;
  8907. const plane = new Plane(),
  8908. viewNormalMatrix = new Matrix3(),
  8909. uniform = { value: null, needsUpdate: false };
  8910. this.uniform = uniform;
  8911. this.numPlanes = 0;
  8912. this.numIntersection = 0;
  8913. this.init = function ( planes, enableLocalClipping, camera ) {
  8914. const enabled =
  8915. planes.length !== 0 ||
  8916. enableLocalClipping ||
  8917. // enable state of previous frame - the clipping code has to
  8918. // run another frame in order to reset the state:
  8919. numGlobalPlanes !== 0 ||
  8920. localClippingEnabled;
  8921. localClippingEnabled = enableLocalClipping;
  8922. globalState = projectPlanes( planes, camera, 0 );
  8923. numGlobalPlanes = planes.length;
  8924. return enabled;
  8925. };
  8926. this.beginShadows = function () {
  8927. renderingShadows = true;
  8928. projectPlanes( null );
  8929. };
  8930. this.endShadows = function () {
  8931. renderingShadows = false;
  8932. resetGlobalState();
  8933. };
  8934. this.setState = function ( material, camera, useCache ) {
  8935. const planes = material.clippingPlanes,
  8936. clipIntersection = material.clipIntersection,
  8937. clipShadows = material.clipShadows;
  8938. const materialProperties = properties.get( material );
  8939. if ( ! localClippingEnabled || planes === null || planes.length === 0 || renderingShadows && ! clipShadows ) {
  8940. // there's no local clipping
  8941. if ( renderingShadows ) {
  8942. // there's no global clipping
  8943. projectPlanes( null );
  8944. } else {
  8945. resetGlobalState();
  8946. }
  8947. } else {
  8948. const nGlobal = renderingShadows ? 0 : numGlobalPlanes,
  8949. lGlobal = nGlobal * 4;
  8950. let dstArray = materialProperties.clippingState || null;
  8951. uniform.value = dstArray; // ensure unique state
  8952. dstArray = projectPlanes( planes, camera, lGlobal, useCache );
  8953. for ( let i = 0; i !== lGlobal; ++ i ) {
  8954. dstArray[ i ] = globalState[ i ];
  8955. }
  8956. materialProperties.clippingState = dstArray;
  8957. this.numIntersection = clipIntersection ? this.numPlanes : 0;
  8958. this.numPlanes += nGlobal;
  8959. }
  8960. };
  8961. function resetGlobalState() {
  8962. if ( uniform.value !== globalState ) {
  8963. uniform.value = globalState;
  8964. uniform.needsUpdate = numGlobalPlanes > 0;
  8965. }
  8966. scope.numPlanes = numGlobalPlanes;
  8967. scope.numIntersection = 0;
  8968. }
  8969. function projectPlanes( planes, camera, dstOffset, skipTransform ) {
  8970. const nPlanes = planes !== null ? planes.length : 0;
  8971. let dstArray = null;
  8972. if ( nPlanes !== 0 ) {
  8973. dstArray = uniform.value;
  8974. if ( skipTransform !== true || dstArray === null ) {
  8975. const flatSize = dstOffset + nPlanes * 4,
  8976. viewMatrix = camera.matrixWorldInverse;
  8977. viewNormalMatrix.getNormalMatrix( viewMatrix );
  8978. if ( dstArray === null || dstArray.length < flatSize ) {
  8979. dstArray = new Float32Array( flatSize );
  8980. }
  8981. for ( let i = 0, i4 = dstOffset; i !== nPlanes; ++ i, i4 += 4 ) {
  8982. plane.copy( planes[ i ] ).applyMatrix4( viewMatrix, viewNormalMatrix );
  8983. plane.normal.toArray( dstArray, i4 );
  8984. dstArray[ i4 + 3 ] = plane.constant;
  8985. }
  8986. }
  8987. uniform.value = dstArray;
  8988. uniform.needsUpdate = true;
  8989. }
  8990. scope.numPlanes = nPlanes;
  8991. scope.numIntersection = 0;
  8992. return dstArray;
  8993. }
  8994. }
  8995. function WebGLCubeMaps( renderer ) {
  8996. let cubemaps = new WeakMap();
  8997. function mapTextureMapping( texture, mapping ) {
  8998. if ( mapping === EquirectangularReflectionMapping ) {
  8999. texture.mapping = CubeReflectionMapping;
  9000. } else if ( mapping === EquirectangularRefractionMapping ) {
  9001. texture.mapping = CubeRefractionMapping;
  9002. }
  9003. return texture;
  9004. }
  9005. function get( texture ) {
  9006. if ( texture && texture.isTexture ) {
  9007. const mapping = texture.mapping;
  9008. if ( mapping === EquirectangularReflectionMapping || mapping === EquirectangularRefractionMapping ) {
  9009. if ( cubemaps.has( texture ) ) {
  9010. const cubemap = cubemaps.get( texture ).texture;
  9011. return mapTextureMapping( cubemap, texture.mapping );
  9012. } else {
  9013. const image = texture.image;
  9014. if ( image && image.height > 0 ) {
  9015. const currentRenderList = renderer.getRenderList();
  9016. const currentRenderTarget = renderer.getRenderTarget();
  9017. const renderTarget = new WebGLCubeRenderTarget( image.height / 2 );
  9018. renderTarget.fromEquirectangularTexture( renderer, texture );
  9019. cubemaps.set( texture, renderTarget );
  9020. renderer.setRenderTarget( currentRenderTarget );
  9021. renderer.setRenderList( currentRenderList );
  9022. texture.addEventListener( 'dispose', onTextureDispose );
  9023. return mapTextureMapping( renderTarget.texture, texture.mapping );
  9024. } else {
  9025. // image not yet ready. try the conversion next frame
  9026. return null;
  9027. }
  9028. }
  9029. }
  9030. }
  9031. return texture;
  9032. }
  9033. function onTextureDispose( event ) {
  9034. const texture = event.target;
  9035. texture.removeEventListener( 'dispose', onTextureDispose );
  9036. const cubemap = cubemaps.get( texture );
  9037. if ( cubemap !== undefined ) {
  9038. cubemaps.delete( texture );
  9039. cubemap.dispose();
  9040. }
  9041. }
  9042. function dispose() {
  9043. cubemaps = new WeakMap();
  9044. }
  9045. return {
  9046. get: get,
  9047. dispose: dispose
  9048. };
  9049. }
  9050. function WebGLExtensions( gl ) {
  9051. const extensions = {};
  9052. return {
  9053. has: function ( name ) {
  9054. if ( extensions[ name ] !== undefined ) {
  9055. return extensions[ name ] !== null;
  9056. }
  9057. let extension;
  9058. switch ( name ) {
  9059. case 'WEBGL_depth_texture':
  9060. extension = gl.getExtension( 'WEBGL_depth_texture' ) || gl.getExtension( 'MOZ_WEBGL_depth_texture' ) || gl.getExtension( 'WEBKIT_WEBGL_depth_texture' );
  9061. break;
  9062. case 'EXT_texture_filter_anisotropic':
  9063. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  9064. break;
  9065. case 'WEBGL_compressed_texture_s3tc':
  9066. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  9067. break;
  9068. case 'WEBGL_compressed_texture_pvrtc':
  9069. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  9070. break;
  9071. default:
  9072. extension = gl.getExtension( name );
  9073. }
  9074. extensions[ name ] = extension;
  9075. return extension !== null;
  9076. },
  9077. get: function ( name ) {
  9078. if ( ! this.has( name ) ) {
  9079. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  9080. }
  9081. return extensions[ name ];
  9082. }
  9083. };
  9084. }
  9085. function WebGLGeometries( gl, attributes, info, bindingStates ) {
  9086. const geometries = new WeakMap();
  9087. const wireframeAttributes = new WeakMap();
  9088. function onGeometryDispose( event ) {
  9089. const geometry = event.target;
  9090. const buffergeometry = geometries.get( geometry );
  9091. if ( buffergeometry.index !== null ) {
  9092. attributes.remove( buffergeometry.index );
  9093. }
  9094. for ( const name in buffergeometry.attributes ) {
  9095. attributes.remove( buffergeometry.attributes[ name ] );
  9096. }
  9097. geometry.removeEventListener( 'dispose', onGeometryDispose );
  9098. geometries.delete( geometry );
  9099. const attribute = wireframeAttributes.get( buffergeometry );
  9100. if ( attribute ) {
  9101. attributes.remove( attribute );
  9102. wireframeAttributes.delete( buffergeometry );
  9103. }
  9104. bindingStates.releaseStatesOfGeometry( buffergeometry );
  9105. if ( geometry.isInstancedBufferGeometry === true ) {
  9106. delete geometry._maxInstanceCount;
  9107. }
  9108. //
  9109. info.memory.geometries --;
  9110. }
  9111. function get( object, geometry ) {
  9112. let buffergeometry = geometries.get( geometry );
  9113. if ( buffergeometry ) return buffergeometry;
  9114. geometry.addEventListener( 'dispose', onGeometryDispose );
  9115. if ( geometry.isBufferGeometry ) {
  9116. buffergeometry = geometry;
  9117. } else if ( geometry.isGeometry ) {
  9118. if ( geometry._bufferGeometry === undefined ) {
  9119. geometry._bufferGeometry = new BufferGeometry().setFromObject( object );
  9120. }
  9121. buffergeometry = geometry._bufferGeometry;
  9122. }
  9123. geometries.set( geometry, buffergeometry );
  9124. info.memory.geometries ++;
  9125. return buffergeometry;
  9126. }
  9127. function update( geometry ) {
  9128. const geometryAttributes = geometry.attributes;
  9129. // Updating index buffer in VAO now. See WebGLBindingStates.
  9130. for ( const name in geometryAttributes ) {
  9131. attributes.update( geometryAttributes[ name ], 34962 );
  9132. }
  9133. // morph targets
  9134. const morphAttributes = geometry.morphAttributes;
  9135. for ( const name in morphAttributes ) {
  9136. const array = morphAttributes[ name ];
  9137. for ( let i = 0, l = array.length; i < l; i ++ ) {
  9138. attributes.update( array[ i ], 34962 );
  9139. }
  9140. }
  9141. }
  9142. function updateWireframeAttribute( geometry ) {
  9143. const indices = [];
  9144. const geometryIndex = geometry.index;
  9145. const geometryPosition = geometry.attributes.position;
  9146. let version = 0;
  9147. if ( geometryIndex !== null ) {
  9148. const array = geometryIndex.array;
  9149. version = geometryIndex.version;
  9150. for ( let i = 0, l = array.length; i < l; i += 3 ) {
  9151. const a = array[ i + 0 ];
  9152. const b = array[ i + 1 ];
  9153. const c = array[ i + 2 ];
  9154. indices.push( a, b, b, c, c, a );
  9155. }
  9156. } else {
  9157. const array = geometryPosition.array;
  9158. version = geometryPosition.version;
  9159. for ( let i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  9160. const a = i + 0;
  9161. const b = i + 1;
  9162. const c = i + 2;
  9163. indices.push( a, b, b, c, c, a );
  9164. }
  9165. }
  9166. const attribute = new ( arrayMax( indices ) > 65535 ? Uint32BufferAttribute : Uint16BufferAttribute )( indices, 1 );
  9167. attribute.version = version;
  9168. // Updating index buffer in VAO now. See WebGLBindingStates
  9169. //
  9170. const previousAttribute = wireframeAttributes.get( geometry );
  9171. if ( previousAttribute ) attributes.remove( previousAttribute );
  9172. //
  9173. wireframeAttributes.set( geometry, attribute );
  9174. }
  9175. function getWireframeAttribute( geometry ) {
  9176. const currentAttribute = wireframeAttributes.get( geometry );
  9177. if ( currentAttribute ) {
  9178. const geometryIndex = geometry.index;
  9179. if ( geometryIndex !== null ) {
  9180. // if the attribute is obsolete, create a new one
  9181. if ( currentAttribute.version < geometryIndex.version ) {
  9182. updateWireframeAttribute( geometry );
  9183. }
  9184. }
  9185. } else {
  9186. updateWireframeAttribute( geometry );
  9187. }
  9188. return wireframeAttributes.get( geometry );
  9189. }
  9190. return {
  9191. get: get,
  9192. update: update,
  9193. getWireframeAttribute: getWireframeAttribute
  9194. };
  9195. }
  9196. function WebGLIndexedBufferRenderer( gl, extensions, info, capabilities ) {
  9197. const isWebGL2 = capabilities.isWebGL2;
  9198. let mode;
  9199. function setMode( value ) {
  9200. mode = value;
  9201. }
  9202. let type, bytesPerElement;
  9203. function setIndex( value ) {
  9204. type = value.type;
  9205. bytesPerElement = value.bytesPerElement;
  9206. }
  9207. function render( start, count ) {
  9208. gl.drawElements( mode, count, type, start * bytesPerElement );
  9209. info.update( count, mode, 1 );
  9210. }
  9211. function renderInstances( start, count, primcount ) {
  9212. if ( primcount === 0 ) return;
  9213. let extension, methodName;
  9214. if ( isWebGL2 ) {
  9215. extension = gl;
  9216. methodName = 'drawElementsInstanced';
  9217. } else {
  9218. extension = extensions.get( 'ANGLE_instanced_arrays' );
  9219. methodName = 'drawElementsInstancedANGLE';
  9220. if ( extension === null ) {
  9221. console.error( 'THREE.WebGLIndexedBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  9222. return;
  9223. }
  9224. }
  9225. extension[ methodName ]( mode, count, type, start * bytesPerElement, primcount );
  9226. info.update( count, mode, primcount );
  9227. }
  9228. //
  9229. this.setMode = setMode;
  9230. this.setIndex = setIndex;
  9231. this.render = render;
  9232. this.renderInstances = renderInstances;
  9233. }
  9234. function WebGLInfo( gl ) {
  9235. const memory = {
  9236. geometries: 0,
  9237. textures: 0
  9238. };
  9239. const render = {
  9240. frame: 0,
  9241. calls: 0,
  9242. triangles: 0,
  9243. points: 0,
  9244. lines: 0
  9245. };
  9246. function update( count, mode, instanceCount ) {
  9247. render.calls ++;
  9248. switch ( mode ) {
  9249. case 4:
  9250. render.triangles += instanceCount * ( count / 3 );
  9251. break;
  9252. case 1:
  9253. render.lines += instanceCount * ( count / 2 );
  9254. break;
  9255. case 3:
  9256. render.lines += instanceCount * ( count - 1 );
  9257. break;
  9258. case 2:
  9259. render.lines += instanceCount * count;
  9260. break;
  9261. case 0:
  9262. render.points += instanceCount * count;
  9263. break;
  9264. default:
  9265. console.error( 'THREE.WebGLInfo: Unknown draw mode:', mode );
  9266. break;
  9267. }
  9268. }
  9269. function reset() {
  9270. render.frame ++;
  9271. render.calls = 0;
  9272. render.triangles = 0;
  9273. render.points = 0;
  9274. render.lines = 0;
  9275. }
  9276. return {
  9277. memory: memory,
  9278. render: render,
  9279. programs: null,
  9280. autoReset: true,
  9281. reset: reset,
  9282. update: update
  9283. };
  9284. }
  9285. function numericalSort( a, b ) {
  9286. return a[ 0 ] - b[ 0 ];
  9287. }
  9288. function absNumericalSort( a, b ) {
  9289. return Math.abs( b[ 1 ] ) - Math.abs( a[ 1 ] );
  9290. }
  9291. function WebGLMorphtargets( gl ) {
  9292. const influencesList = {};
  9293. const morphInfluences = new Float32Array( 8 );
  9294. const workInfluences = [];
  9295. for ( let i = 0; i < 8; i ++ ) {
  9296. workInfluences[ i ] = [ i, 0 ];
  9297. }
  9298. function update( object, geometry, material, program ) {
  9299. const objectInfluences = object.morphTargetInfluences;
  9300. // When object doesn't have morph target influences defined, we treat it as a 0-length array
  9301. // This is important to make sure we set up morphTargetBaseInfluence / morphTargetInfluences
  9302. const length = objectInfluences === undefined ? 0 : objectInfluences.length;
  9303. let influences = influencesList[ geometry.id ];
  9304. if ( influences === undefined ) {
  9305. // initialise list
  9306. influences = [];
  9307. for ( let i = 0; i < length; i ++ ) {
  9308. influences[ i ] = [ i, 0 ];
  9309. }
  9310. influencesList[ geometry.id ] = influences;
  9311. }
  9312. // Collect influences
  9313. for ( let i = 0; i < length; i ++ ) {
  9314. const influence = influences[ i ];
  9315. influence[ 0 ] = i;
  9316. influence[ 1 ] = objectInfluences[ i ];
  9317. }
  9318. influences.sort( absNumericalSort );
  9319. for ( let i = 0; i < 8; i ++ ) {
  9320. if ( i < length && influences[ i ][ 1 ] ) {
  9321. workInfluences[ i ][ 0 ] = influences[ i ][ 0 ];
  9322. workInfluences[ i ][ 1 ] = influences[ i ][ 1 ];
  9323. } else {
  9324. workInfluences[ i ][ 0 ] = Number.MAX_SAFE_INTEGER;
  9325. workInfluences[ i ][ 1 ] = 0;
  9326. }
  9327. }
  9328. workInfluences.sort( numericalSort );
  9329. const morphTargets = material.morphTargets && geometry.morphAttributes.position;
  9330. const morphNormals = material.morphNormals && geometry.morphAttributes.normal;
  9331. let morphInfluencesSum = 0;
  9332. for ( let i = 0; i < 8; i ++ ) {
  9333. const influence = workInfluences[ i ];
  9334. const index = influence[ 0 ];
  9335. const value = influence[ 1 ];
  9336. if ( index !== Number.MAX_SAFE_INTEGER && value ) {
  9337. if ( morphTargets && geometry.getAttribute( 'morphTarget' + i ) !== morphTargets[ index ] ) {
  9338. geometry.setAttribute( 'morphTarget' + i, morphTargets[ index ] );
  9339. }
  9340. if ( morphNormals && geometry.getAttribute( 'morphNormal' + i ) !== morphNormals[ index ] ) {
  9341. geometry.setAttribute( 'morphNormal' + i, morphNormals[ index ] );
  9342. }
  9343. morphInfluences[ i ] = value;
  9344. morphInfluencesSum += value;
  9345. } else {
  9346. if ( morphTargets && geometry.hasAttribute( 'morphTarget' + i ) === true ) {
  9347. geometry.deleteAttribute( 'morphTarget' + i );
  9348. }
  9349. if ( morphNormals && geometry.hasAttribute( 'morphNormal' + i ) === true ) {
  9350. geometry.deleteAttribute( 'morphNormal' + i );
  9351. }
  9352. morphInfluences[ i ] = 0;
  9353. }
  9354. }
  9355. // GLSL shader uses formula baseinfluence * base + sum(target * influence)
  9356. // This allows us to switch between absolute morphs and relative morphs without changing shader code
  9357. // When baseinfluence = 1 - sum(influence), the above is equivalent to sum((target - base) * influence)
  9358. const morphBaseInfluence = geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9359. program.getUniforms().setValue( gl, 'morphTargetBaseInfluence', morphBaseInfluence );
  9360. program.getUniforms().setValue( gl, 'morphTargetInfluences', morphInfluences );
  9361. }
  9362. return {
  9363. update: update
  9364. };
  9365. }
  9366. function WebGLObjects( gl, geometries, attributes, info ) {
  9367. let updateMap = new WeakMap();
  9368. function update( object ) {
  9369. const frame = info.render.frame;
  9370. const geometry = object.geometry;
  9371. const buffergeometry = geometries.get( object, geometry );
  9372. // Update once per frame
  9373. if ( updateMap.get( buffergeometry ) !== frame ) {
  9374. if ( geometry.isGeometry ) {
  9375. buffergeometry.updateFromObject( object );
  9376. }
  9377. geometries.update( buffergeometry );
  9378. updateMap.set( buffergeometry, frame );
  9379. }
  9380. if ( object.isInstancedMesh ) {
  9381. if ( object.hasEventListener( 'dispose', onInstancedMeshDispose ) === false ) {
  9382. object.addEventListener( 'dispose', onInstancedMeshDispose );
  9383. }
  9384. attributes.update( object.instanceMatrix, 34962 );
  9385. if ( object.instanceColor !== null ) {
  9386. attributes.update( object.instanceColor, 34962 );
  9387. }
  9388. }
  9389. return buffergeometry;
  9390. }
  9391. function dispose() {
  9392. updateMap = new WeakMap();
  9393. }
  9394. function onInstancedMeshDispose( event ) {
  9395. const instancedMesh = event.target;
  9396. instancedMesh.removeEventListener( 'dispose', onInstancedMeshDispose );
  9397. attributes.remove( instancedMesh.instanceMatrix );
  9398. if ( instancedMesh.instanceColor !== null ) attributes.remove( instancedMesh.instanceColor );
  9399. }
  9400. return {
  9401. update: update,
  9402. dispose: dispose
  9403. };
  9404. }
  9405. function DataTexture2DArray( data = null, width = 1, height = 1, depth = 1 ) {
  9406. Texture.call( this, null );
  9407. this.image = { data, width, height, depth };
  9408. this.magFilter = NearestFilter;
  9409. this.minFilter = NearestFilter;
  9410. this.wrapR = ClampToEdgeWrapping;
  9411. this.generateMipmaps = false;
  9412. this.flipY = false;
  9413. this.needsUpdate = true;
  9414. }
  9415. DataTexture2DArray.prototype = Object.create( Texture.prototype );
  9416. DataTexture2DArray.prototype.constructor = DataTexture2DArray;
  9417. DataTexture2DArray.prototype.isDataTexture2DArray = true;
  9418. function DataTexture3D( data = null, width = 1, height = 1, depth = 1 ) {
  9419. // We're going to add .setXXX() methods for setting properties later.
  9420. // Users can still set in DataTexture3D directly.
  9421. //
  9422. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  9423. // texture.anisotropy = 16;
  9424. //
  9425. // See #14839
  9426. Texture.call( this, null );
  9427. this.image = { data, width, height, depth };
  9428. this.magFilter = NearestFilter;
  9429. this.minFilter = NearestFilter;
  9430. this.wrapR = ClampToEdgeWrapping;
  9431. this.generateMipmaps = false;
  9432. this.flipY = false;
  9433. this.needsUpdate = true;
  9434. }
  9435. DataTexture3D.prototype = Object.create( Texture.prototype );
  9436. DataTexture3D.prototype.constructor = DataTexture3D;
  9437. DataTexture3D.prototype.isDataTexture3D = true;
  9438. /**
  9439. * Uniforms of a program.
  9440. * Those form a tree structure with a special top-level container for the root,
  9441. * which you get by calling 'new WebGLUniforms( gl, program )'.
  9442. *
  9443. *
  9444. * Properties of inner nodes including the top-level container:
  9445. *
  9446. * .seq - array of nested uniforms
  9447. * .map - nested uniforms by name
  9448. *
  9449. *
  9450. * Methods of all nodes except the top-level container:
  9451. *
  9452. * .setValue( gl, value, [textures] )
  9453. *
  9454. * uploads a uniform value(s)
  9455. * the 'textures' parameter is needed for sampler uniforms
  9456. *
  9457. *
  9458. * Static methods of the top-level container (textures factorizations):
  9459. *
  9460. * .upload( gl, seq, values, textures )
  9461. *
  9462. * sets uniforms in 'seq' to 'values[id].value'
  9463. *
  9464. * .seqWithValue( seq, values ) : filteredSeq
  9465. *
  9466. * filters 'seq' entries with corresponding entry in values
  9467. *
  9468. *
  9469. * Methods of the top-level container (textures factorizations):
  9470. *
  9471. * .setValue( gl, name, value, textures )
  9472. *
  9473. * sets uniform with name 'name' to 'value'
  9474. *
  9475. * .setOptional( gl, obj, prop )
  9476. *
  9477. * like .set for an optional property of the object
  9478. *
  9479. */
  9480. const emptyTexture = new Texture();
  9481. const emptyTexture2dArray = new DataTexture2DArray();
  9482. const emptyTexture3d = new DataTexture3D();
  9483. const emptyCubeTexture = new CubeTexture();
  9484. // --- Utilities ---
  9485. // Array Caches (provide typed arrays for temporary by size)
  9486. const arrayCacheF32 = [];
  9487. const arrayCacheI32 = [];
  9488. // Float32Array caches used for uploading Matrix uniforms
  9489. const mat4array = new Float32Array( 16 );
  9490. const mat3array = new Float32Array( 9 );
  9491. const mat2array = new Float32Array( 4 );
  9492. // Flattening for arrays of vectors and matrices
  9493. function flatten( array, nBlocks, blockSize ) {
  9494. const firstElem = array[ 0 ];
  9495. if ( firstElem <= 0 || firstElem > 0 ) return array;
  9496. // unoptimized: ! isNaN( firstElem )
  9497. // see http://jacksondunstan.com/articles/983
  9498. const n = nBlocks * blockSize;
  9499. let r = arrayCacheF32[ n ];
  9500. if ( r === undefined ) {
  9501. r = new Float32Array( n );
  9502. arrayCacheF32[ n ] = r;
  9503. }
  9504. if ( nBlocks !== 0 ) {
  9505. firstElem.toArray( r, 0 );
  9506. for ( let i = 1, offset = 0; i !== nBlocks; ++ i ) {
  9507. offset += blockSize;
  9508. array[ i ].toArray( r, offset );
  9509. }
  9510. }
  9511. return r;
  9512. }
  9513. function arraysEqual( a, b ) {
  9514. if ( a.length !== b.length ) return false;
  9515. for ( let i = 0, l = a.length; i < l; i ++ ) {
  9516. if ( a[ i ] !== b[ i ] ) return false;
  9517. }
  9518. return true;
  9519. }
  9520. function copyArray( a, b ) {
  9521. for ( let i = 0, l = b.length; i < l; i ++ ) {
  9522. a[ i ] = b[ i ];
  9523. }
  9524. }
  9525. // Texture unit allocation
  9526. function allocTexUnits( textures, n ) {
  9527. let r = arrayCacheI32[ n ];
  9528. if ( r === undefined ) {
  9529. r = new Int32Array( n );
  9530. arrayCacheI32[ n ] = r;
  9531. }
  9532. for ( let i = 0; i !== n; ++ i ) {
  9533. r[ i ] = textures.allocateTextureUnit();
  9534. }
  9535. return r;
  9536. }
  9537. // --- Setters ---
  9538. // Note: Defining these methods externally, because they come in a bunch
  9539. // and this way their names minify.
  9540. // Single scalar
  9541. function setValueV1f( gl, v ) {
  9542. const cache = this.cache;
  9543. if ( cache[ 0 ] === v ) return;
  9544. gl.uniform1f( this.addr, v );
  9545. cache[ 0 ] = v;
  9546. }
  9547. // Single float vector (from flat array or THREE.VectorN)
  9548. function setValueV2f( gl, v ) {
  9549. const cache = this.cache;
  9550. if ( v.x !== undefined ) {
  9551. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y ) {
  9552. gl.uniform2f( this.addr, v.x, v.y );
  9553. cache[ 0 ] = v.x;
  9554. cache[ 1 ] = v.y;
  9555. }
  9556. } else {
  9557. if ( arraysEqual( cache, v ) ) return;
  9558. gl.uniform2fv( this.addr, v );
  9559. copyArray( cache, v );
  9560. }
  9561. }
  9562. function setValueV3f( gl, v ) {
  9563. const cache = this.cache;
  9564. if ( v.x !== undefined ) {
  9565. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z ) {
  9566. gl.uniform3f( this.addr, v.x, v.y, v.z );
  9567. cache[ 0 ] = v.x;
  9568. cache[ 1 ] = v.y;
  9569. cache[ 2 ] = v.z;
  9570. }
  9571. } else if ( v.r !== undefined ) {
  9572. if ( cache[ 0 ] !== v.r || cache[ 1 ] !== v.g || cache[ 2 ] !== v.b ) {
  9573. gl.uniform3f( this.addr, v.r, v.g, v.b );
  9574. cache[ 0 ] = v.r;
  9575. cache[ 1 ] = v.g;
  9576. cache[ 2 ] = v.b;
  9577. }
  9578. } else {
  9579. if ( arraysEqual( cache, v ) ) return;
  9580. gl.uniform3fv( this.addr, v );
  9581. copyArray( cache, v );
  9582. }
  9583. }
  9584. function setValueV4f( gl, v ) {
  9585. const cache = this.cache;
  9586. if ( v.x !== undefined ) {
  9587. if ( cache[ 0 ] !== v.x || cache[ 1 ] !== v.y || cache[ 2 ] !== v.z || cache[ 3 ] !== v.w ) {
  9588. gl.uniform4f( this.addr, v.x, v.y, v.z, v.w );
  9589. cache[ 0 ] = v.x;
  9590. cache[ 1 ] = v.y;
  9591. cache[ 2 ] = v.z;
  9592. cache[ 3 ] = v.w;
  9593. }
  9594. } else {
  9595. if ( arraysEqual( cache, v ) ) return;
  9596. gl.uniform4fv( this.addr, v );
  9597. copyArray( cache, v );
  9598. }
  9599. }
  9600. // Single matrix (from flat array or MatrixN)
  9601. function setValueM2( gl, v ) {
  9602. const cache = this.cache;
  9603. const elements = v.elements;
  9604. if ( elements === undefined ) {
  9605. if ( arraysEqual( cache, v ) ) return;
  9606. gl.uniformMatrix2fv( this.addr, false, v );
  9607. copyArray( cache, v );
  9608. } else {
  9609. if ( arraysEqual( cache, elements ) ) return;
  9610. mat2array.set( elements );
  9611. gl.uniformMatrix2fv( this.addr, false, mat2array );
  9612. copyArray( cache, elements );
  9613. }
  9614. }
  9615. function setValueM3( gl, v ) {
  9616. const cache = this.cache;
  9617. const elements = v.elements;
  9618. if ( elements === undefined ) {
  9619. if ( arraysEqual( cache, v ) ) return;
  9620. gl.uniformMatrix3fv( this.addr, false, v );
  9621. copyArray( cache, v );
  9622. } else {
  9623. if ( arraysEqual( cache, elements ) ) return;
  9624. mat3array.set( elements );
  9625. gl.uniformMatrix3fv( this.addr, false, mat3array );
  9626. copyArray( cache, elements );
  9627. }
  9628. }
  9629. function setValueM4( gl, v ) {
  9630. const cache = this.cache;
  9631. const elements = v.elements;
  9632. if ( elements === undefined ) {
  9633. if ( arraysEqual( cache, v ) ) return;
  9634. gl.uniformMatrix4fv( this.addr, false, v );
  9635. copyArray( cache, v );
  9636. } else {
  9637. if ( arraysEqual( cache, elements ) ) return;
  9638. mat4array.set( elements );
  9639. gl.uniformMatrix4fv( this.addr, false, mat4array );
  9640. copyArray( cache, elements );
  9641. }
  9642. }
  9643. // Single texture (2D / Cube)
  9644. function setValueT1( gl, v, textures ) {
  9645. const cache = this.cache;
  9646. const unit = textures.allocateTextureUnit();
  9647. if ( cache[ 0 ] !== unit ) {
  9648. gl.uniform1i( this.addr, unit );
  9649. cache[ 0 ] = unit;
  9650. }
  9651. textures.safeSetTexture2D( v || emptyTexture, unit );
  9652. }
  9653. function setValueT2DArray1( gl, v, textures ) {
  9654. const cache = this.cache;
  9655. const unit = textures.allocateTextureUnit();
  9656. if ( cache[ 0 ] !== unit ) {
  9657. gl.uniform1i( this.addr, unit );
  9658. cache[ 0 ] = unit;
  9659. }
  9660. textures.setTexture2DArray( v || emptyTexture2dArray, unit );
  9661. }
  9662. function setValueT3D1( gl, v, textures ) {
  9663. const cache = this.cache;
  9664. const unit = textures.allocateTextureUnit();
  9665. if ( cache[ 0 ] !== unit ) {
  9666. gl.uniform1i( this.addr, unit );
  9667. cache[ 0 ] = unit;
  9668. }
  9669. textures.setTexture3D( v || emptyTexture3d, unit );
  9670. }
  9671. function setValueT6( gl, v, textures ) {
  9672. const cache = this.cache;
  9673. const unit = textures.allocateTextureUnit();
  9674. if ( cache[ 0 ] !== unit ) {
  9675. gl.uniform1i( this.addr, unit );
  9676. cache[ 0 ] = unit;
  9677. }
  9678. textures.safeSetTextureCube( v || emptyCubeTexture, unit );
  9679. }
  9680. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9681. function setValueV1i( gl, v ) {
  9682. const cache = this.cache;
  9683. if ( cache[ 0 ] === v ) return;
  9684. gl.uniform1i( this.addr, v );
  9685. cache[ 0 ] = v;
  9686. }
  9687. function setValueV2i( gl, v ) {
  9688. const cache = this.cache;
  9689. if ( arraysEqual( cache, v ) ) return;
  9690. gl.uniform2iv( this.addr, v );
  9691. copyArray( cache, v );
  9692. }
  9693. function setValueV3i( gl, v ) {
  9694. const cache = this.cache;
  9695. if ( arraysEqual( cache, v ) ) return;
  9696. gl.uniform3iv( this.addr, v );
  9697. copyArray( cache, v );
  9698. }
  9699. function setValueV4i( gl, v ) {
  9700. const cache = this.cache;
  9701. if ( arraysEqual( cache, v ) ) return;
  9702. gl.uniform4iv( this.addr, v );
  9703. copyArray( cache, v );
  9704. }
  9705. // uint
  9706. function setValueV1ui( gl, v ) {
  9707. const cache = this.cache;
  9708. if ( cache[ 0 ] === v ) return;
  9709. gl.uniform1ui( this.addr, v );
  9710. cache[ 0 ] = v;
  9711. }
  9712. // Helper to pick the right setter for the singular case
  9713. function getSingularSetter( type ) {
  9714. switch ( type ) {
  9715. case 0x1406: return setValueV1f; // FLOAT
  9716. case 0x8b50: return setValueV2f; // _VEC2
  9717. case 0x8b51: return setValueV3f; // _VEC3
  9718. case 0x8b52: return setValueV4f; // _VEC4
  9719. case 0x8b5a: return setValueM2; // _MAT2
  9720. case 0x8b5b: return setValueM3; // _MAT3
  9721. case 0x8b5c: return setValueM4; // _MAT4
  9722. case 0x1404: case 0x8b56: return setValueV1i; // INT, BOOL
  9723. case 0x8b53: case 0x8b57: return setValueV2i; // _VEC2
  9724. case 0x8b54: case 0x8b58: return setValueV3i; // _VEC3
  9725. case 0x8b55: case 0x8b59: return setValueV4i; // _VEC4
  9726. case 0x1405: return setValueV1ui; // UINT
  9727. case 0x8b5e: // SAMPLER_2D
  9728. case 0x8d66: // SAMPLER_EXTERNAL_OES
  9729. case 0x8dca: // INT_SAMPLER_2D
  9730. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  9731. case 0x8b62: // SAMPLER_2D_SHADOW
  9732. return setValueT1;
  9733. case 0x8b5f: // SAMPLER_3D
  9734. case 0x8dcb: // INT_SAMPLER_3D
  9735. case 0x8dd3: // UNSIGNED_INT_SAMPLER_3D
  9736. return setValueT3D1;
  9737. case 0x8b60: // SAMPLER_CUBE
  9738. case 0x8dcc: // INT_SAMPLER_CUBE
  9739. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  9740. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  9741. return setValueT6;
  9742. case 0x8dc1: // SAMPLER_2D_ARRAY
  9743. case 0x8dcf: // INT_SAMPLER_2D_ARRAY
  9744. case 0x8dd7: // UNSIGNED_INT_SAMPLER_2D_ARRAY
  9745. case 0x8dc4: // SAMPLER_2D_ARRAY_SHADOW
  9746. return setValueT2DArray1;
  9747. }
  9748. }
  9749. // Array of scalars
  9750. function setValueV1fArray( gl, v ) {
  9751. gl.uniform1fv( this.addr, v );
  9752. }
  9753. // Integer / Boolean vectors or arrays thereof (always flat arrays)
  9754. function setValueV1iArray( gl, v ) {
  9755. gl.uniform1iv( this.addr, v );
  9756. }
  9757. function setValueV2iArray( gl, v ) {
  9758. gl.uniform2iv( this.addr, v );
  9759. }
  9760. function setValueV3iArray( gl, v ) {
  9761. gl.uniform3iv( this.addr, v );
  9762. }
  9763. function setValueV4iArray( gl, v ) {
  9764. gl.uniform4iv( this.addr, v );
  9765. }
  9766. // Array of vectors (flat or from THREE classes)
  9767. function setValueV2fArray( gl, v ) {
  9768. const data = flatten( v, this.size, 2 );
  9769. gl.uniform2fv( this.addr, data );
  9770. }
  9771. function setValueV3fArray( gl, v ) {
  9772. const data = flatten( v, this.size, 3 );
  9773. gl.uniform3fv( this.addr, data );
  9774. }
  9775. function setValueV4fArray( gl, v ) {
  9776. const data = flatten( v, this.size, 4 );
  9777. gl.uniform4fv( this.addr, data );
  9778. }
  9779. // Array of matrices (flat or from THREE clases)
  9780. function setValueM2Array( gl, v ) {
  9781. const data = flatten( v, this.size, 4 );
  9782. gl.uniformMatrix2fv( this.addr, false, data );
  9783. }
  9784. function setValueM3Array( gl, v ) {
  9785. const data = flatten( v, this.size, 9 );
  9786. gl.uniformMatrix3fv( this.addr, false, data );
  9787. }
  9788. function setValueM4Array( gl, v ) {
  9789. const data = flatten( v, this.size, 16 );
  9790. gl.uniformMatrix4fv( this.addr, false, data );
  9791. }
  9792. // Array of textures (2D / Cube)
  9793. function setValueT1Array( gl, v, textures ) {
  9794. const n = v.length;
  9795. const units = allocTexUnits( textures, n );
  9796. gl.uniform1iv( this.addr, units );
  9797. for ( let i = 0; i !== n; ++ i ) {
  9798. textures.safeSetTexture2D( v[ i ] || emptyTexture, units[ i ] );
  9799. }
  9800. }
  9801. function setValueT6Array( gl, v, textures ) {
  9802. const n = v.length;
  9803. const units = allocTexUnits( textures, n );
  9804. gl.uniform1iv( this.addr, units );
  9805. for ( let i = 0; i !== n; ++ i ) {
  9806. textures.safeSetTextureCube( v[ i ] || emptyCubeTexture, units[ i ] );
  9807. }
  9808. }
  9809. // Helper to pick the right setter for a pure (bottom-level) array
  9810. function getPureArraySetter( type ) {
  9811. switch ( type ) {
  9812. case 0x1406: return setValueV1fArray; // FLOAT
  9813. case 0x8b50: return setValueV2fArray; // _VEC2
  9814. case 0x8b51: return setValueV3fArray; // _VEC3
  9815. case 0x8b52: return setValueV4fArray; // _VEC4
  9816. case 0x8b5a: return setValueM2Array; // _MAT2
  9817. case 0x8b5b: return setValueM3Array; // _MAT3
  9818. case 0x8b5c: return setValueM4Array; // _MAT4
  9819. case 0x1404: case 0x8b56: return setValueV1iArray; // INT, BOOL
  9820. case 0x8b53: case 0x8b57: return setValueV2iArray; // _VEC2
  9821. case 0x8b54: case 0x8b58: return setValueV3iArray; // _VEC3
  9822. case 0x8b55: case 0x8b59: return setValueV4iArray; // _VEC4
  9823. case 0x8b5e: // SAMPLER_2D
  9824. case 0x8d66: // SAMPLER_EXTERNAL_OES
  9825. case 0x8dca: // INT_SAMPLER_2D
  9826. case 0x8dd2: // UNSIGNED_INT_SAMPLER_2D
  9827. case 0x8b62: // SAMPLER_2D_SHADOW
  9828. return setValueT1Array;
  9829. case 0x8b60: // SAMPLER_CUBE
  9830. case 0x8dcc: // INT_SAMPLER_CUBE
  9831. case 0x8dd4: // UNSIGNED_INT_SAMPLER_CUBE
  9832. case 0x8dc5: // SAMPLER_CUBE_SHADOW
  9833. return setValueT6Array;
  9834. }
  9835. }
  9836. // --- Uniform Classes ---
  9837. function SingleUniform( id, activeInfo, addr ) {
  9838. this.id = id;
  9839. this.addr = addr;
  9840. this.cache = [];
  9841. this.setValue = getSingularSetter( activeInfo.type );
  9842. // this.path = activeInfo.name; // DEBUG
  9843. }
  9844. function PureArrayUniform( id, activeInfo, addr ) {
  9845. this.id = id;
  9846. this.addr = addr;
  9847. this.cache = [];
  9848. this.size = activeInfo.size;
  9849. this.setValue = getPureArraySetter( activeInfo.type );
  9850. // this.path = activeInfo.name; // DEBUG
  9851. }
  9852. PureArrayUniform.prototype.updateCache = function ( data ) {
  9853. const cache = this.cache;
  9854. if ( data instanceof Float32Array && cache.length !== data.length ) {
  9855. this.cache = new Float32Array( data.length );
  9856. }
  9857. copyArray( cache, data );
  9858. };
  9859. function StructuredUniform( id ) {
  9860. this.id = id;
  9861. this.seq = [];
  9862. this.map = {};
  9863. }
  9864. StructuredUniform.prototype.setValue = function ( gl, value, textures ) {
  9865. const seq = this.seq;
  9866. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9867. const u = seq[ i ];
  9868. u.setValue( gl, value[ u.id ], textures );
  9869. }
  9870. };
  9871. // --- Top-level ---
  9872. // Parser - builds up the property tree from the path strings
  9873. const RePathPart = /(\w+)(\])?(\[|\.)?/g;
  9874. // extracts
  9875. // - the identifier (member name or array index)
  9876. // - followed by an optional right bracket (found when array index)
  9877. // - followed by an optional left bracket or dot (type of subscript)
  9878. //
  9879. // Note: These portions can be read in a non-overlapping fashion and
  9880. // allow straightforward parsing of the hierarchy that WebGL encodes
  9881. // in the uniform names.
  9882. function addUniform( container, uniformObject ) {
  9883. container.seq.push( uniformObject );
  9884. container.map[ uniformObject.id ] = uniformObject;
  9885. }
  9886. function parseUniform( activeInfo, addr, container ) {
  9887. const path = activeInfo.name,
  9888. pathLength = path.length;
  9889. // reset RegExp object, because of the early exit of a previous run
  9890. RePathPart.lastIndex = 0;
  9891. while ( true ) {
  9892. const match = RePathPart.exec( path ),
  9893. matchEnd = RePathPart.lastIndex;
  9894. let id = match[ 1 ];
  9895. const idIsIndex = match[ 2 ] === ']',
  9896. subscript = match[ 3 ];
  9897. if ( idIsIndex ) id = id | 0; // convert to integer
  9898. if ( subscript === undefined || subscript === '[' && matchEnd + 2 === pathLength ) {
  9899. // bare name or "pure" bottom-level array "[0]" suffix
  9900. addUniform( container, subscript === undefined ?
  9901. new SingleUniform( id, activeInfo, addr ) :
  9902. new PureArrayUniform( id, activeInfo, addr ) );
  9903. break;
  9904. } else {
  9905. // step into inner node / create it in case it doesn't exist
  9906. const map = container.map;
  9907. let next = map[ id ];
  9908. if ( next === undefined ) {
  9909. next = new StructuredUniform( id );
  9910. addUniform( container, next );
  9911. }
  9912. container = next;
  9913. }
  9914. }
  9915. }
  9916. // Root Container
  9917. function WebGLUniforms( gl, program ) {
  9918. this.seq = [];
  9919. this.map = {};
  9920. const n = gl.getProgramParameter( program, 35718 );
  9921. for ( let i = 0; i < n; ++ i ) {
  9922. const info = gl.getActiveUniform( program, i ),
  9923. addr = gl.getUniformLocation( program, info.name );
  9924. parseUniform( info, addr, this );
  9925. }
  9926. }
  9927. WebGLUniforms.prototype.setValue = function ( gl, name, value, textures ) {
  9928. const u = this.map[ name ];
  9929. if ( u !== undefined ) u.setValue( gl, value, textures );
  9930. };
  9931. WebGLUniforms.prototype.setOptional = function ( gl, object, name ) {
  9932. const v = object[ name ];
  9933. if ( v !== undefined ) this.setValue( gl, name, v );
  9934. };
  9935. // Static interface
  9936. WebGLUniforms.upload = function ( gl, seq, values, textures ) {
  9937. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9938. const u = seq[ i ],
  9939. v = values[ u.id ];
  9940. if ( v.needsUpdate !== false ) {
  9941. // note: always updating when .needsUpdate is undefined
  9942. u.setValue( gl, v.value, textures );
  9943. }
  9944. }
  9945. };
  9946. WebGLUniforms.seqWithValue = function ( seq, values ) {
  9947. const r = [];
  9948. for ( let i = 0, n = seq.length; i !== n; ++ i ) {
  9949. const u = seq[ i ];
  9950. if ( u.id in values ) r.push( u );
  9951. }
  9952. return r;
  9953. };
  9954. function WebGLShader( gl, type, string ) {
  9955. const shader = gl.createShader( type );
  9956. gl.shaderSource( shader, string );
  9957. gl.compileShader( shader );
  9958. return shader;
  9959. }
  9960. let programIdCount = 0;
  9961. function addLineNumbers( string ) {
  9962. const lines = string.split( '\n' );
  9963. for ( let i = 0; i < lines.length; i ++ ) {
  9964. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  9965. }
  9966. return lines.join( '\n' );
  9967. }
  9968. function getEncodingComponents( encoding ) {
  9969. switch ( encoding ) {
  9970. case LinearEncoding:
  9971. return [ 'Linear', '( value )' ];
  9972. case sRGBEncoding:
  9973. return [ 'sRGB', '( value )' ];
  9974. case RGBEEncoding:
  9975. return [ 'RGBE', '( value )' ];
  9976. case RGBM7Encoding:
  9977. return [ 'RGBM', '( value, 7.0 )' ];
  9978. case RGBM16Encoding:
  9979. return [ 'RGBM', '( value, 16.0 )' ];
  9980. case RGBDEncoding:
  9981. return [ 'RGBD', '( value, 256.0 )' ];
  9982. case GammaEncoding:
  9983. return [ 'Gamma', '( value, float( GAMMA_FACTOR ) )' ];
  9984. case LogLuvEncoding:
  9985. return [ 'LogLuv', '( value )' ];
  9986. default:
  9987. console.warn( 'THREE.WebGLProgram: Unsupported encoding:', encoding );
  9988. return [ 'Linear', '( value )' ];
  9989. }
  9990. }
  9991. function getShaderErrors( gl, shader, type ) {
  9992. const status = gl.getShaderParameter( shader, 35713 );
  9993. const log = gl.getShaderInfoLog( shader ).trim();
  9994. if ( status && log === '' ) return '';
  9995. // --enable-privileged-webgl-extension
  9996. // console.log( '**' + type + '**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  9997. const source = gl.getShaderSource( shader );
  9998. return 'THREE.WebGLShader: gl.getShaderInfoLog() ' + type + '\n' + log + addLineNumbers( source );
  9999. }
  10000. function getTexelDecodingFunction( functionName, encoding ) {
  10001. const components = getEncodingComponents( encoding );
  10002. return 'vec4 ' + functionName + '( vec4 value ) { return ' + components[ 0 ] + 'ToLinear' + components[ 1 ] + '; }';
  10003. }
  10004. function getTexelEncodingFunction( functionName, encoding ) {
  10005. const components = getEncodingComponents( encoding );
  10006. return 'vec4 ' + functionName + '( vec4 value ) { return LinearTo' + components[ 0 ] + components[ 1 ] + '; }';
  10007. }
  10008. function getToneMappingFunction( functionName, toneMapping ) {
  10009. let toneMappingName;
  10010. switch ( toneMapping ) {
  10011. case LinearToneMapping:
  10012. toneMappingName = 'Linear';
  10013. break;
  10014. case ReinhardToneMapping:
  10015. toneMappingName = 'Reinhard';
  10016. break;
  10017. case CineonToneMapping:
  10018. toneMappingName = 'OptimizedCineon';
  10019. break;
  10020. case ACESFilmicToneMapping:
  10021. toneMappingName = 'ACESFilmic';
  10022. break;
  10023. case CustomToneMapping:
  10024. toneMappingName = 'Custom';
  10025. break;
  10026. default:
  10027. console.warn( 'THREE.WebGLProgram: Unsupported toneMapping:', toneMapping );
  10028. toneMappingName = 'Linear';
  10029. }
  10030. return 'vec3 ' + functionName + '( vec3 color ) { return ' + toneMappingName + 'ToneMapping( color ); }';
  10031. }
  10032. function generateExtensions( parameters ) {
  10033. const chunks = [
  10034. ( parameters.extensionDerivatives || parameters.envMapCubeUV || parameters.bumpMap || parameters.tangentSpaceNormalMap || parameters.clearcoatNormalMap || parameters.flatShading || parameters.shaderID === 'physical' ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  10035. ( parameters.extensionFragDepth || parameters.logarithmicDepthBuffer ) && parameters.rendererExtensionFragDepth ? '#extension GL_EXT_frag_depth : enable' : '',
  10036. ( parameters.extensionDrawBuffers && parameters.rendererExtensionDrawBuffers ) ? '#extension GL_EXT_draw_buffers : require' : '',
  10037. ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ? '#extension GL_EXT_shader_texture_lod : enable' : ''
  10038. ];
  10039. return chunks.filter( filterEmptyLine ).join( '\n' );
  10040. }
  10041. function generateDefines( defines ) {
  10042. const chunks = [];
  10043. for ( const name in defines ) {
  10044. const value = defines[ name ];
  10045. if ( value === false ) continue;
  10046. chunks.push( '#define ' + name + ' ' + value );
  10047. }
  10048. return chunks.join( '\n' );
  10049. }
  10050. function fetchAttributeLocations( gl, program ) {
  10051. const attributes = {};
  10052. const n = gl.getProgramParameter( program, 35721 );
  10053. for ( let i = 0; i < n; i ++ ) {
  10054. const info = gl.getActiveAttrib( program, i );
  10055. const name = info.name;
  10056. // console.log( 'THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:', name, i );
  10057. attributes[ name ] = gl.getAttribLocation( program, name );
  10058. }
  10059. return attributes;
  10060. }
  10061. function filterEmptyLine( string ) {
  10062. return string !== '';
  10063. }
  10064. function replaceLightNums( string, parameters ) {
  10065. return string
  10066. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  10067. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  10068. .replace( /NUM_RECT_AREA_LIGHTS/g, parameters.numRectAreaLights )
  10069. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  10070. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights )
  10071. .replace( /NUM_DIR_LIGHT_SHADOWS/g, parameters.numDirLightShadows )
  10072. .replace( /NUM_SPOT_LIGHT_SHADOWS/g, parameters.numSpotLightShadows )
  10073. .replace( /NUM_POINT_LIGHT_SHADOWS/g, parameters.numPointLightShadows );
  10074. }
  10075. function replaceClippingPlaneNums( string, parameters ) {
  10076. return string
  10077. .replace( /NUM_CLIPPING_PLANES/g, parameters.numClippingPlanes )
  10078. .replace( /UNION_CLIPPING_PLANES/g, ( parameters.numClippingPlanes - parameters.numClipIntersection ) );
  10079. }
  10080. // Resolve Includes
  10081. const includePattern = /^[ \t]*#include +<([\w\d./]+)>/gm;
  10082. function resolveIncludes( string ) {
  10083. return string.replace( includePattern, includeReplacer );
  10084. }
  10085. function includeReplacer( match, include ) {
  10086. const string = ShaderChunk[ include ];
  10087. if ( string === undefined ) {
  10088. throw new Error( 'Can not resolve #include <' + include + '>' );
  10089. }
  10090. return resolveIncludes( string );
  10091. }
  10092. // Unroll Loops
  10093. const deprecatedUnrollLoopPattern = /#pragma unroll_loop[\s]+?for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  10094. const 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;
  10095. function unrollLoops( string ) {
  10096. return string
  10097. .replace( unrollLoopPattern, loopReplacer )
  10098. .replace( deprecatedUnrollLoopPattern, deprecatedLoopReplacer );
  10099. }
  10100. function deprecatedLoopReplacer( match, start, end, snippet ) {
  10101. console.warn( 'WebGLProgram: #pragma unroll_loop shader syntax is deprecated. Please use #pragma unroll_loop_start syntax instead.' );
  10102. return loopReplacer( match, start, end, snippet );
  10103. }
  10104. function loopReplacer( match, start, end, snippet ) {
  10105. let string = '';
  10106. for ( let i = parseInt( start ); i < parseInt( end ); i ++ ) {
  10107. string += snippet
  10108. .replace( /\[\s*i\s*\]/g, '[ ' + i + ' ]' )
  10109. .replace( /UNROLLED_LOOP_INDEX/g, i );
  10110. }
  10111. return string;
  10112. }
  10113. //
  10114. function generatePrecision( parameters ) {
  10115. let precisionstring = 'precision ' + parameters.precision + ' float;\nprecision ' + parameters.precision + ' int;';
  10116. if ( parameters.precision === 'highp' ) {
  10117. precisionstring += '\n#define HIGH_PRECISION';
  10118. } else if ( parameters.precision === 'mediump' ) {
  10119. precisionstring += '\n#define MEDIUM_PRECISION';
  10120. } else if ( parameters.precision === 'lowp' ) {
  10121. precisionstring += '\n#define LOW_PRECISION';
  10122. }
  10123. return precisionstring;
  10124. }
  10125. function generateShadowMapTypeDefine( parameters ) {
  10126. let shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  10127. if ( parameters.shadowMapType === PCFShadowMap ) {
  10128. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  10129. } else if ( parameters.shadowMapType === PCFSoftShadowMap ) {
  10130. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  10131. } else if ( parameters.shadowMapType === VSMShadowMap ) {
  10132. shadowMapTypeDefine = 'SHADOWMAP_TYPE_VSM';
  10133. }
  10134. return shadowMapTypeDefine;
  10135. }
  10136. function generateEnvMapTypeDefine( parameters ) {
  10137. let envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10138. if ( parameters.envMap ) {
  10139. switch ( parameters.envMapMode ) {
  10140. case CubeReflectionMapping:
  10141. case CubeRefractionMapping:
  10142. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  10143. break;
  10144. case CubeUVReflectionMapping:
  10145. case CubeUVRefractionMapping:
  10146. envMapTypeDefine = 'ENVMAP_TYPE_CUBE_UV';
  10147. break;
  10148. }
  10149. }
  10150. return envMapTypeDefine;
  10151. }
  10152. function generateEnvMapModeDefine( parameters ) {
  10153. let envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  10154. if ( parameters.envMap ) {
  10155. switch ( parameters.envMapMode ) {
  10156. case CubeRefractionMapping:
  10157. case CubeUVRefractionMapping:
  10158. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  10159. break;
  10160. }
  10161. }
  10162. return envMapModeDefine;
  10163. }
  10164. function generateEnvMapBlendingDefine( parameters ) {
  10165. let envMapBlendingDefine = 'ENVMAP_BLENDING_NONE';
  10166. if ( parameters.envMap ) {
  10167. switch ( parameters.combine ) {
  10168. case MultiplyOperation:
  10169. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  10170. break;
  10171. case MixOperation:
  10172. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  10173. break;
  10174. case AddOperation:
  10175. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  10176. break;
  10177. }
  10178. }
  10179. return envMapBlendingDefine;
  10180. }
  10181. function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
  10182. const gl = renderer.getContext();
  10183. const defines = parameters.defines;
  10184. let vertexShader = parameters.vertexShader;
  10185. let fragmentShader = parameters.fragmentShader;
  10186. const shadowMapTypeDefine = generateShadowMapTypeDefine( parameters );
  10187. const envMapTypeDefine = generateEnvMapTypeDefine( parameters );
  10188. const envMapModeDefine = generateEnvMapModeDefine( parameters );
  10189. const envMapBlendingDefine = generateEnvMapBlendingDefine( parameters );
  10190. const gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  10191. const customExtensions = parameters.isWebGL2 ? '' : generateExtensions( parameters );
  10192. const customDefines = generateDefines( defines );
  10193. const program = gl.createProgram();
  10194. let prefixVertex, prefixFragment;
  10195. let versionString = parameters.glslVersion ? '#version ' + parameters.glslVersion + '\n' : '';
  10196. if ( parameters.isRawShaderMaterial ) {
  10197. prefixVertex = [
  10198. customDefines
  10199. ].filter( filterEmptyLine ).join( '\n' );
  10200. if ( prefixVertex.length > 0 ) {
  10201. prefixVertex += '\n';
  10202. }
  10203. prefixFragment = [
  10204. customExtensions,
  10205. customDefines
  10206. ].filter( filterEmptyLine ).join( '\n' );
  10207. if ( prefixFragment.length > 0 ) {
  10208. prefixFragment += '\n';
  10209. }
  10210. } else {
  10211. prefixVertex = [
  10212. generatePrecision( parameters ),
  10213. '#define SHADER_NAME ' + parameters.shaderName,
  10214. customDefines,
  10215. parameters.instancing ? '#define USE_INSTANCING' : '',
  10216. parameters.instancingColor ? '#define USE_INSTANCING_COLOR' : '',
  10217. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  10218. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10219. '#define MAX_BONES ' + parameters.maxBones,
  10220. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10221. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10222. parameters.map ? '#define USE_MAP' : '',
  10223. parameters.envMap ? '#define USE_ENVMAP' : '',
  10224. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10225. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10226. parameters.aoMap ? '#define USE_AOMAP' : '',
  10227. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10228. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10229. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10230. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10231. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10232. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10233. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10234. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10235. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  10236. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10237. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10238. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10239. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10240. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  10241. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10242. parameters.vertexColors ? '#define USE_COLOR' : '',
  10243. parameters.vertexUvs ? '#define USE_UV' : '',
  10244. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10245. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10246. parameters.skinning ? '#define USE_SKINNING' : '',
  10247. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  10248. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  10249. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  10250. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10251. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10252. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10253. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10254. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  10255. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10256. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10257. 'uniform mat4 modelMatrix;',
  10258. 'uniform mat4 modelViewMatrix;',
  10259. 'uniform mat4 projectionMatrix;',
  10260. 'uniform mat4 viewMatrix;',
  10261. 'uniform mat3 normalMatrix;',
  10262. 'uniform vec3 cameraPosition;',
  10263. 'uniform bool isOrthographic;',
  10264. '#ifdef USE_INSTANCING',
  10265. ' attribute mat4 instanceMatrix;',
  10266. '#endif',
  10267. '#ifdef USE_INSTANCING_COLOR',
  10268. ' attribute vec3 instanceColor;',
  10269. '#endif',
  10270. 'attribute vec3 position;',
  10271. 'attribute vec3 normal;',
  10272. 'attribute vec2 uv;',
  10273. '#ifdef USE_TANGENT',
  10274. ' attribute vec4 tangent;',
  10275. '#endif',
  10276. '#ifdef USE_COLOR',
  10277. ' attribute vec3 color;',
  10278. '#endif',
  10279. '#ifdef USE_MORPHTARGETS',
  10280. ' attribute vec3 morphTarget0;',
  10281. ' attribute vec3 morphTarget1;',
  10282. ' attribute vec3 morphTarget2;',
  10283. ' attribute vec3 morphTarget3;',
  10284. ' #ifdef USE_MORPHNORMALS',
  10285. ' attribute vec3 morphNormal0;',
  10286. ' attribute vec3 morphNormal1;',
  10287. ' attribute vec3 morphNormal2;',
  10288. ' attribute vec3 morphNormal3;',
  10289. ' #else',
  10290. ' attribute vec3 morphTarget4;',
  10291. ' attribute vec3 morphTarget5;',
  10292. ' attribute vec3 morphTarget6;',
  10293. ' attribute vec3 morphTarget7;',
  10294. ' #endif',
  10295. '#endif',
  10296. '#ifdef USE_SKINNING',
  10297. ' attribute vec4 skinIndex;',
  10298. ' attribute vec4 skinWeight;',
  10299. '#endif',
  10300. '\n'
  10301. ].filter( filterEmptyLine ).join( '\n' );
  10302. prefixFragment = [
  10303. customExtensions,
  10304. generatePrecision( parameters ),
  10305. '#define SHADER_NAME ' + parameters.shaderName,
  10306. customDefines,
  10307. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest + ( parameters.alphaTest % 1 ? '' : '.0' ) : '', // add '.0' if integer
  10308. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  10309. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  10310. ( parameters.useFog && parameters.fogExp2 ) ? '#define FOG_EXP2' : '',
  10311. parameters.map ? '#define USE_MAP' : '',
  10312. parameters.matcap ? '#define USE_MATCAP' : '',
  10313. parameters.envMap ? '#define USE_ENVMAP' : '',
  10314. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  10315. parameters.envMap ? '#define ' + envMapModeDefine : '',
  10316. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  10317. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  10318. parameters.aoMap ? '#define USE_AOMAP' : '',
  10319. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  10320. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  10321. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  10322. ( parameters.normalMap && parameters.objectSpaceNormalMap ) ? '#define OBJECTSPACE_NORMALMAP' : '',
  10323. ( parameters.normalMap && parameters.tangentSpaceNormalMap ) ? '#define TANGENTSPACE_NORMALMAP' : '',
  10324. parameters.clearcoatMap ? '#define USE_CLEARCOATMAP' : '',
  10325. parameters.clearcoatRoughnessMap ? '#define USE_CLEARCOAT_ROUGHNESSMAP' : '',
  10326. parameters.clearcoatNormalMap ? '#define USE_CLEARCOAT_NORMALMAP' : '',
  10327. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  10328. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  10329. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  10330. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  10331. parameters.sheen ? '#define USE_SHEEN' : '',
  10332. parameters.transmissionMap ? '#define USE_TRANSMISSIONMAP' : '',
  10333. parameters.vertexTangents ? '#define USE_TANGENT' : '',
  10334. parameters.vertexColors || parameters.instancingColor ? '#define USE_COLOR' : '',
  10335. parameters.vertexUvs ? '#define USE_UV' : '',
  10336. parameters.uvsVertexOnly ? '#define UVS_VERTEX_ONLY' : '',
  10337. parameters.gradientMap ? '#define USE_GRADIENTMAP' : '',
  10338. parameters.flatShading ? '#define FLAT_SHADED' : '',
  10339. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  10340. parameters.flipSided ? '#define FLIP_SIDED' : '',
  10341. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  10342. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  10343. parameters.premultipliedAlpha ? '#define PREMULTIPLIED_ALPHA' : '',
  10344. parameters.physicallyCorrectLights ? '#define PHYSICALLY_CORRECT_LIGHTS' : '',
  10345. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  10346. ( parameters.logarithmicDepthBuffer && parameters.rendererExtensionFragDepth ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  10347. ( ( parameters.extensionShaderTextureLOD || parameters.envMap ) && parameters.rendererExtensionShaderTextureLod ) ? '#define TEXTURE_LOD_EXT' : '',
  10348. 'uniform mat4 viewMatrix;',
  10349. 'uniform vec3 cameraPosition;',
  10350. 'uniform bool isOrthographic;',
  10351. ( parameters.toneMapping !== NoToneMapping ) ? '#define TONE_MAPPING' : '',
  10352. ( parameters.toneMapping !== NoToneMapping ) ? ShaderChunk[ 'tonemapping_pars_fragment' ] : '', // this code is required here because it is used by the toneMapping() function defined below
  10353. ( parameters.toneMapping !== NoToneMapping ) ? getToneMappingFunction( 'toneMapping', parameters.toneMapping ) : '',
  10354. parameters.dithering ? '#define DITHERING' : '',
  10355. ShaderChunk[ 'encodings_pars_fragment' ], // this code is required here because it is used by the various encoding/decoding function defined below
  10356. parameters.map ? getTexelDecodingFunction( 'mapTexelToLinear', parameters.mapEncoding ) : '',
  10357. parameters.matcap ? getTexelDecodingFunction( 'matcapTexelToLinear', parameters.matcapEncoding ) : '',
  10358. parameters.envMap ? getTexelDecodingFunction( 'envMapTexelToLinear', parameters.envMapEncoding ) : '',
  10359. parameters.emissiveMap ? getTexelDecodingFunction( 'emissiveMapTexelToLinear', parameters.emissiveMapEncoding ) : '',
  10360. parameters.lightMap ? getTexelDecodingFunction( 'lightMapTexelToLinear', parameters.lightMapEncoding ) : '',
  10361. getTexelEncodingFunction( 'linearToOutputTexel', parameters.outputEncoding ),
  10362. parameters.depthPacking ? '#define DEPTH_PACKING ' + parameters.depthPacking : '',
  10363. '\n'
  10364. ].filter( filterEmptyLine ).join( '\n' );
  10365. }
  10366. vertexShader = resolveIncludes( vertexShader );
  10367. vertexShader = replaceLightNums( vertexShader, parameters );
  10368. vertexShader = replaceClippingPlaneNums( vertexShader, parameters );
  10369. fragmentShader = resolveIncludes( fragmentShader );
  10370. fragmentShader = replaceLightNums( fragmentShader, parameters );
  10371. fragmentShader = replaceClippingPlaneNums( fragmentShader, parameters );
  10372. vertexShader = unrollLoops( vertexShader );
  10373. fragmentShader = unrollLoops( fragmentShader );
  10374. if ( parameters.isWebGL2 && parameters.isRawShaderMaterial !== true ) {
  10375. // GLSL 3.0 conversion for built-in materials and ShaderMaterial
  10376. versionString = '#version 300 es\n';
  10377. prefixVertex = [
  10378. '#define attribute in',
  10379. '#define varying out',
  10380. '#define texture2D texture'
  10381. ].join( '\n' ) + '\n' + prefixVertex;
  10382. prefixFragment = [
  10383. '#define varying in',
  10384. ( parameters.glslVersion === GLSL3 ) ? '' : 'out highp vec4 pc_fragColor;',
  10385. ( parameters.glslVersion === GLSL3 ) ? '' : '#define gl_FragColor pc_fragColor',
  10386. '#define gl_FragDepthEXT gl_FragDepth',
  10387. '#define texture2D texture',
  10388. '#define textureCube texture',
  10389. '#define texture2DProj textureProj',
  10390. '#define texture2DLodEXT textureLod',
  10391. '#define texture2DProjLodEXT textureProjLod',
  10392. '#define textureCubeLodEXT textureLod',
  10393. '#define texture2DGradEXT textureGrad',
  10394. '#define texture2DProjGradEXT textureProjGrad',
  10395. '#define textureCubeGradEXT textureGrad'
  10396. ].join( '\n' ) + '\n' + prefixFragment;
  10397. }
  10398. const vertexGlsl = versionString + prefixVertex + vertexShader;
  10399. const fragmentGlsl = versionString + prefixFragment + fragmentShader;
  10400. // console.log( '*VERTEX*', vertexGlsl );
  10401. // console.log( '*FRAGMENT*', fragmentGlsl );
  10402. const glVertexShader = WebGLShader( gl, 35633, vertexGlsl );
  10403. const glFragmentShader = WebGLShader( gl, 35632, fragmentGlsl );
  10404. gl.attachShader( program, glVertexShader );
  10405. gl.attachShader( program, glFragmentShader );
  10406. // Force a particular attribute to index 0.
  10407. if ( parameters.index0AttributeName !== undefined ) {
  10408. gl.bindAttribLocation( program, 0, parameters.index0AttributeName );
  10409. } else if ( parameters.morphTargets === true ) {
  10410. // programs with morphTargets displace position out of attribute 0
  10411. gl.bindAttribLocation( program, 0, 'position' );
  10412. }
  10413. gl.linkProgram( program );
  10414. // check for link errors
  10415. if ( renderer.debug.checkShaderErrors ) {
  10416. const programLog = gl.getProgramInfoLog( program ).trim();
  10417. const vertexLog = gl.getShaderInfoLog( glVertexShader ).trim();
  10418. const fragmentLog = gl.getShaderInfoLog( glFragmentShader ).trim();
  10419. let runnable = true;
  10420. let haveDiagnostics = true;
  10421. if ( gl.getProgramParameter( program, 35714 ) === false ) {
  10422. runnable = false;
  10423. const vertexErrors = getShaderErrors( gl, glVertexShader, 'vertex' );
  10424. const fragmentErrors = getShaderErrors( gl, glFragmentShader, 'fragment' );
  10425. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), '35715', gl.getProgramParameter( program, 35715 ), 'gl.getProgramInfoLog', programLog, vertexErrors, fragmentErrors );
  10426. //add:
  10427. if(fragmentErrors){
  10428. console.log(fragmentGlsl.split("\n").map((a, i) => `${i + 1}`.padEnd(5) + a).join("\n") );
  10429. }else {
  10430. console.log(vertexGlsl.split("\n").map((a, i) => `${i + 1}`.padEnd(5) + a).join("\n") );
  10431. }
  10432. } else if ( programLog !== '' ) {
  10433. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  10434. } else if ( vertexLog === '' || fragmentLog === '' ) {
  10435. haveDiagnostics = false;
  10436. }
  10437. if ( haveDiagnostics ) {
  10438. this.diagnostics = {
  10439. runnable: runnable,
  10440. programLog: programLog,
  10441. vertexShader: {
  10442. log: vertexLog,
  10443. prefix: prefixVertex
  10444. },
  10445. fragmentShader: {
  10446. log: fragmentLog,
  10447. prefix: prefixFragment
  10448. }
  10449. };
  10450. }
  10451. }
  10452. // Clean up
  10453. // Crashes in iOS9 and iOS10. #18402
  10454. // gl.detachShader( program, glVertexShader );
  10455. // gl.detachShader( program, glFragmentShader );
  10456. gl.deleteShader( glVertexShader );
  10457. gl.deleteShader( glFragmentShader );
  10458. // set up caching for uniform locations
  10459. let cachedUniforms;
  10460. this.getUniforms = function () {
  10461. if ( cachedUniforms === undefined ) {
  10462. cachedUniforms = new WebGLUniforms( gl, program );
  10463. }
  10464. return cachedUniforms;
  10465. };
  10466. // set up caching for attribute locations
  10467. let cachedAttributes;
  10468. this.getAttributes = function () {
  10469. if ( cachedAttributes === undefined ) {
  10470. cachedAttributes = fetchAttributeLocations( gl, program );
  10471. }
  10472. return cachedAttributes;
  10473. };
  10474. // free resource
  10475. this.destroy = function () {
  10476. bindingStates.releaseStatesOfProgram( this );
  10477. gl.deleteProgram( program );
  10478. this.program = undefined;
  10479. };
  10480. //
  10481. this.name = parameters.shaderName;
  10482. this.id = programIdCount ++;
  10483. this.cacheKey = cacheKey;
  10484. this.usedTimes = 1;
  10485. this.program = program;
  10486. this.vertexShader = glVertexShader;
  10487. this.fragmentShader = glFragmentShader;
  10488. return this;
  10489. }
  10490. function WebGLPrograms( renderer, cubemaps, extensions, capabilities, bindingStates, clipping ) {
  10491. const programs = [];
  10492. const isWebGL2 = capabilities.isWebGL2;
  10493. const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
  10494. const floatVertexTextures = capabilities.floatVertexTextures;
  10495. const maxVertexUniforms = capabilities.maxVertexUniforms;
  10496. const vertexTextures = capabilities.vertexTextures;
  10497. let precision = capabilities.precision;
  10498. const shaderIDs = {
  10499. MeshDepthMaterial: 'depth',
  10500. MeshDistanceMaterial: 'distanceRGBA',
  10501. MeshNormalMaterial: 'normal',
  10502. MeshBasicMaterial: 'basic',
  10503. MeshLambertMaterial: 'lambert',
  10504. MeshPhongMaterial: 'phong',
  10505. MeshToonMaterial: 'toon',
  10506. MeshStandardMaterial: 'physical',
  10507. MeshPhysicalMaterial: 'physical',
  10508. MeshMatcapMaterial: 'matcap',
  10509. LineBasicMaterial: 'basic',
  10510. LineDashedMaterial: 'dashed',
  10511. PointsMaterial: 'points',
  10512. ShadowMaterial: 'shadow',
  10513. SpriteMaterial: 'sprite'
  10514. };
  10515. const parameterNames = [
  10516. 'precision', 'isWebGL2', 'supportsVertexTextures', 'outputEncoding', 'instancing', 'instancingColor',
  10517. 'map', 'mapEncoding', 'matcap', 'matcapEncoding', 'envMap', 'envMapMode', 'envMapEncoding', 'envMapCubeUV',
  10518. 'lightMap', 'lightMapEncoding', 'aoMap', 'emissiveMap', 'emissiveMapEncoding', 'bumpMap', 'normalMap', 'objectSpaceNormalMap', 'tangentSpaceNormalMap', 'clearcoatMap', 'clearcoatRoughnessMap', 'clearcoatNormalMap', 'displacementMap', 'specularMap',
  10519. 'roughnessMap', 'metalnessMap', 'gradientMap',
  10520. 'alphaMap', 'combine', 'vertexColors', 'vertexTangents', 'vertexUvs', 'uvsVertexOnly', 'fog', 'useFog', 'fogExp2',
  10521. 'flatShading', 'sizeAttenuation', 'logarithmicDepthBuffer', 'skinning',
  10522. 'maxBones', 'useVertexTexture', 'morphTargets', 'morphNormals',
  10523. 'maxMorphTargets', 'maxMorphNormals', 'premultipliedAlpha',
  10524. 'numDirLights', 'numPointLights', 'numSpotLights', 'numHemiLights', 'numRectAreaLights',
  10525. 'numDirLightShadows', 'numPointLightShadows', 'numSpotLightShadows',
  10526. 'shadowMapEnabled', 'shadowMapType', 'toneMapping', 'physicallyCorrectLights',
  10527. 'alphaTest', 'doubleSided', 'flipSided', 'numClippingPlanes', 'numClipIntersection', 'depthPacking', 'dithering',
  10528. 'sheen', 'transmissionMap'
  10529. ];
  10530. function getMaxBones( object ) {
  10531. const skeleton = object.skeleton;
  10532. const bones = skeleton.bones;
  10533. if ( floatVertexTextures ) {
  10534. return 1024;
  10535. } else {
  10536. // default for when object is not specified
  10537. // ( for example when prebuilding shader to be used with multiple objects )
  10538. //
  10539. // - leave some extra space for other uniforms
  10540. // - limit here is ANGLE's 254 max uniform vectors
  10541. // (up to 54 should be safe)
  10542. const nVertexUniforms = maxVertexUniforms;
  10543. const nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  10544. const maxBones = Math.min( nVertexMatrices, bones.length );
  10545. if ( maxBones < bones.length ) {
  10546. console.warn( 'THREE.WebGLRenderer: Skeleton has ' + bones.length + ' bones. This GPU supports ' + maxBones + '.' );
  10547. return 0;
  10548. }
  10549. return maxBones;
  10550. }
  10551. }
  10552. function getTextureEncodingFromMap( map ) {
  10553. let encoding;
  10554. if ( map && map.isTexture ) {
  10555. encoding = map.encoding;
  10556. } else if ( map && map.isWebGLRenderTarget ) {
  10557. console.warn( 'THREE.WebGLPrograms.getTextureEncodingFromMap: don\'t use render targets as textures. Use their .texture property instead.' );
  10558. encoding = map.texture.encoding;
  10559. } else {
  10560. encoding = LinearEncoding;
  10561. }
  10562. return encoding;
  10563. }
  10564. function getParameters( material, lights, shadows, scene, object ) {
  10565. const fog = scene.fog;
  10566. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  10567. const envMap = cubemaps.get( material.envMap || environment );
  10568. const shaderID = shaderIDs[ material.type ];
  10569. // heuristics to create shader parameters according to lights in the scene
  10570. // (not to blow over maxLights budget)
  10571. const maxBones = object.isSkinnedMesh ? getMaxBones( object ) : 0;
  10572. if ( material.precision !== null ) {
  10573. precision = capabilities.getMaxPrecision( material.precision );
  10574. if ( precision !== material.precision ) {
  10575. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  10576. }
  10577. }
  10578. let vertexShader, fragmentShader;
  10579. if ( shaderID ) {
  10580. const shader = ShaderLib[ shaderID ];
  10581. vertexShader = shader.vertexShader;
  10582. fragmentShader = shader.fragmentShader;
  10583. } else {
  10584. vertexShader = material.vertexShader;
  10585. fragmentShader = material.fragmentShader;
  10586. }
  10587. const currentRenderTarget = renderer.getRenderTarget();
  10588. const parameters = {
  10589. isWebGL2: isWebGL2,
  10590. shaderID: shaderID,
  10591. shaderName: material.type,
  10592. vertexShader: vertexShader,
  10593. fragmentShader: fragmentShader,
  10594. defines: material.defines,
  10595. isRawShaderMaterial: material.isRawShaderMaterial === true,
  10596. glslVersion: material.glslVersion,
  10597. precision: precision,
  10598. instancing: object.isInstancedMesh === true,
  10599. instancingColor: object.isInstancedMesh === true && object.instanceColor !== null,
  10600. supportsVertexTextures: vertexTextures,
  10601. outputEncoding: ( currentRenderTarget !== null ) ? getTextureEncodingFromMap( currentRenderTarget.texture ) : renderer.outputEncoding,
  10602. map: !! material.map,
  10603. mapEncoding: getTextureEncodingFromMap( material.map ),
  10604. matcap: !! material.matcap,
  10605. matcapEncoding: getTextureEncodingFromMap( material.matcap ),
  10606. envMap: !! envMap,
  10607. envMapMode: envMap && envMap.mapping,
  10608. envMapEncoding: getTextureEncodingFromMap( envMap ),
  10609. envMapCubeUV: ( !! envMap ) && ( ( envMap.mapping === CubeUVReflectionMapping ) || ( envMap.mapping === CubeUVRefractionMapping ) ),
  10610. lightMap: !! material.lightMap,
  10611. lightMapEncoding: getTextureEncodingFromMap( material.lightMap ),
  10612. aoMap: !! material.aoMap,
  10613. emissiveMap: !! material.emissiveMap,
  10614. emissiveMapEncoding: getTextureEncodingFromMap( material.emissiveMap ),
  10615. bumpMap: !! material.bumpMap,
  10616. normalMap: !! material.normalMap,
  10617. objectSpaceNormalMap: material.normalMapType === ObjectSpaceNormalMap,
  10618. tangentSpaceNormalMap: material.normalMapType === TangentSpaceNormalMap,
  10619. clearcoatMap: !! material.clearcoatMap,
  10620. clearcoatRoughnessMap: !! material.clearcoatRoughnessMap,
  10621. clearcoatNormalMap: !! material.clearcoatNormalMap,
  10622. displacementMap: !! material.displacementMap,
  10623. roughnessMap: !! material.roughnessMap,
  10624. metalnessMap: !! material.metalnessMap,
  10625. specularMap: !! material.specularMap,
  10626. alphaMap: !! material.alphaMap,
  10627. gradientMap: !! material.gradientMap,
  10628. sheen: !! material.sheen,
  10629. transmissionMap: !! material.transmissionMap,
  10630. combine: material.combine,
  10631. vertexTangents: ( material.normalMap && material.vertexTangents ),
  10632. vertexColors: material.vertexColors,
  10633. 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,
  10634. uvsVertexOnly: ! ( !! material.map || !! material.bumpMap || !! material.normalMap || !! material.specularMap || !! material.alphaMap || !! material.emissiveMap || !! material.roughnessMap || !! material.metalnessMap || !! material.clearcoatNormalMap || !! material.transmissionMap ) && !! material.displacementMap,
  10635. fog: !! fog,
  10636. useFog: material.fog,
  10637. fogExp2: ( fog && fog.isFogExp2 ),
  10638. flatShading: material.flatShading,
  10639. sizeAttenuation: material.sizeAttenuation,
  10640. logarithmicDepthBuffer: logarithmicDepthBuffer,
  10641. skinning: material.skinning && maxBones > 0,
  10642. maxBones: maxBones,
  10643. useVertexTexture: floatVertexTextures,
  10644. morphTargets: material.morphTargets,
  10645. morphNormals: material.morphNormals,
  10646. maxMorphTargets: renderer.maxMorphTargets,
  10647. maxMorphNormals: renderer.maxMorphNormals,
  10648. numDirLights: lights.directional.length,
  10649. numPointLights: lights.point.length,
  10650. numSpotLights: lights.spot.length,
  10651. numRectAreaLights: lights.rectArea.length,
  10652. numHemiLights: lights.hemi.length,
  10653. numDirLightShadows: lights.directionalShadowMap.length,
  10654. numPointLightShadows: lights.pointShadowMap.length,
  10655. numSpotLightShadows: lights.spotShadowMap.length,
  10656. numClippingPlanes: clipping.numPlanes,
  10657. numClipIntersection: clipping.numIntersection,
  10658. dithering: material.dithering,
  10659. shadowMapEnabled: renderer.shadowMap.enabled && shadows.length > 0,
  10660. shadowMapType: renderer.shadowMap.type,
  10661. toneMapping: material.toneMapped ? renderer.toneMapping : NoToneMapping,
  10662. physicallyCorrectLights: renderer.physicallyCorrectLights,
  10663. premultipliedAlpha: material.premultipliedAlpha,
  10664. alphaTest: material.alphaTest,
  10665. doubleSided: material.side === DoubleSide,
  10666. flipSided: material.side === BackSide,
  10667. depthPacking: ( material.depthPacking !== undefined ) ? material.depthPacking : false,
  10668. index0AttributeName: material.index0AttributeName,
  10669. extensionDerivatives: material.extensions && material.extensions.derivatives,
  10670. extensionFragDepth: material.extensions && material.extensions.fragDepth,
  10671. extensionDrawBuffers: material.extensions && material.extensions.drawBuffers,
  10672. extensionShaderTextureLOD: material.extensions && material.extensions.shaderTextureLOD,
  10673. rendererExtensionFragDepth: isWebGL2 || extensions.has( 'EXT_frag_depth' ),
  10674. rendererExtensionDrawBuffers: isWebGL2 || extensions.has( 'WEBGL_draw_buffers' ),
  10675. rendererExtensionShaderTextureLod: isWebGL2 || extensions.has( 'EXT_shader_texture_lod' ),
  10676. customProgramCacheKey: material.customProgramCacheKey()
  10677. };
  10678. return parameters;
  10679. }
  10680. function getProgramCacheKey( parameters ) {
  10681. const array = [];
  10682. if ( parameters.shaderID ) {
  10683. array.push( parameters.shaderID );
  10684. } else {
  10685. array.push( parameters.fragmentShader );
  10686. array.push( parameters.vertexShader );
  10687. }
  10688. if ( parameters.defines !== undefined ) {
  10689. for ( const name in parameters.defines ) {
  10690. array.push( name );
  10691. array.push( parameters.defines[ name ] );
  10692. }
  10693. }
  10694. if ( parameters.isRawShaderMaterial === false ) {
  10695. for ( let i = 0; i < parameterNames.length; i ++ ) {
  10696. array.push( parameters[ parameterNames[ i ] ] );
  10697. }
  10698. array.push( renderer.outputEncoding );
  10699. array.push( renderer.gammaFactor );
  10700. }
  10701. array.push( parameters.customProgramCacheKey );
  10702. return array.join();
  10703. }
  10704. function getUniforms( material ) {
  10705. const shaderID = shaderIDs[ material.type ];
  10706. let uniforms;
  10707. if ( shaderID ) {
  10708. const shader = ShaderLib[ shaderID ];
  10709. uniforms = UniformsUtils.clone( shader.uniforms );
  10710. } else {
  10711. uniforms = material.uniforms;
  10712. }
  10713. return uniforms;
  10714. }
  10715. function acquireProgram( parameters, cacheKey ) {
  10716. let program;
  10717. // Check if code has been already compiled
  10718. for ( let p = 0, pl = programs.length; p < pl; p ++ ) {
  10719. const preexistingProgram = programs[ p ];
  10720. if ( preexistingProgram.cacheKey === cacheKey ) {
  10721. program = preexistingProgram;
  10722. ++ program.usedTimes;
  10723. break;
  10724. }
  10725. }
  10726. if ( program === undefined ) {
  10727. program = new WebGLProgram( renderer, cacheKey, parameters, bindingStates );
  10728. programs.push( program );
  10729. }
  10730. return program;
  10731. }
  10732. function releaseProgram( program ) {
  10733. if ( -- program.usedTimes === 0 ) {
  10734. // Remove from unordered set
  10735. const i = programs.indexOf( program );
  10736. programs[ i ] = programs[ programs.length - 1 ];
  10737. programs.pop();
  10738. // Free WebGL resources
  10739. program.destroy();
  10740. }
  10741. }
  10742. return {
  10743. getParameters: getParameters,
  10744. getProgramCacheKey: getProgramCacheKey,
  10745. getUniforms: getUniforms,
  10746. acquireProgram: acquireProgram,
  10747. releaseProgram: releaseProgram,
  10748. // Exposed for resource monitoring & error feedback via renderer.info:
  10749. programs: programs
  10750. };
  10751. }
  10752. function WebGLProperties() {
  10753. let properties = new WeakMap();
  10754. function get( object ) {
  10755. let map = properties.get( object );
  10756. if ( map === undefined ) {
  10757. map = {};
  10758. properties.set( object, map );
  10759. }
  10760. return map;
  10761. }
  10762. function remove( object ) {
  10763. properties.delete( object );
  10764. }
  10765. function update( object, key, value ) {
  10766. properties.get( object )[ key ] = value;
  10767. }
  10768. function dispose() {
  10769. properties = new WeakMap();
  10770. }
  10771. return {
  10772. get: get,
  10773. remove: remove,
  10774. update: update,
  10775. dispose: dispose
  10776. };
  10777. }
  10778. function painterSortStable( a, b ) {
  10779. if ( a.groupOrder !== b.groupOrder ) {
  10780. return a.groupOrder - b.groupOrder;
  10781. } else if ( a.renderOrder !== b.renderOrder ) {
  10782. return a.renderOrder - b.renderOrder;
  10783. } else if ( a.program !== b.program ) {
  10784. return a.program.id - b.program.id;
  10785. } else if ( a.material.id !== b.material.id ) {
  10786. return a.material.id - b.material.id;
  10787. } else if ( a.z !== b.z ) {
  10788. return a.z - b.z;
  10789. } else {
  10790. return a.id - b.id;
  10791. }
  10792. }
  10793. function reversePainterSortStable( a, b ) {
  10794. if ( a.groupOrder !== b.groupOrder ) {
  10795. return a.groupOrder - b.groupOrder;
  10796. } else if ( a.renderOrder !== b.renderOrder ) {
  10797. return a.renderOrder - b.renderOrder;
  10798. } else if ( a.z !== b.z ) {
  10799. return b.z - a.z;
  10800. } else {
  10801. return a.id - b.id;
  10802. }
  10803. }
  10804. function WebGLRenderList( properties ) {
  10805. const renderItems = [];
  10806. let renderItemsIndex = 0;
  10807. const opaque = [];
  10808. const transparent = [];
  10809. const defaultProgram = { id: - 1 };
  10810. function init() {
  10811. renderItemsIndex = 0;
  10812. opaque.length = 0;
  10813. transparent.length = 0;
  10814. }
  10815. function getNextRenderItem( object, geometry, material, groupOrder, z, group ) {
  10816. let renderItem = renderItems[ renderItemsIndex ];
  10817. const materialProperties = properties.get( material );
  10818. if ( renderItem === undefined ) {
  10819. renderItem = {
  10820. id: object.id,
  10821. object: object,
  10822. geometry: geometry,
  10823. material: material,
  10824. program: materialProperties.program || defaultProgram,
  10825. groupOrder: groupOrder,
  10826. renderOrder: object.renderOrder,
  10827. z: z,
  10828. group: group
  10829. };
  10830. renderItems[ renderItemsIndex ] = renderItem;
  10831. } else {
  10832. renderItem.id = object.id;
  10833. renderItem.object = object;
  10834. renderItem.geometry = geometry;
  10835. renderItem.material = material;
  10836. renderItem.program = materialProperties.program || defaultProgram;
  10837. renderItem.groupOrder = groupOrder;
  10838. renderItem.renderOrder = object.renderOrder;
  10839. renderItem.z = z;
  10840. renderItem.group = group;
  10841. }
  10842. renderItemsIndex ++;
  10843. return renderItem;
  10844. }
  10845. function push( object, geometry, material, groupOrder, z, group ) {
  10846. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10847. ( material.transparent === true ? transparent : opaque ).push( renderItem );
  10848. }
  10849. function unshift( object, geometry, material, groupOrder, z, group ) {
  10850. const renderItem = getNextRenderItem( object, geometry, material, groupOrder, z, group );
  10851. ( material.transparent === true ? transparent : opaque ).unshift( renderItem );
  10852. }
  10853. function sort( customOpaqueSort, customTransparentSort ) {
  10854. if ( opaque.length > 1 ) opaque.sort( customOpaqueSort || painterSortStable );
  10855. if ( transparent.length > 1 ) transparent.sort( customTransparentSort || reversePainterSortStable );
  10856. }
  10857. function finish() {
  10858. // Clear references from inactive renderItems in the list
  10859. for ( let i = renderItemsIndex, il = renderItems.length; i < il; i ++ ) {
  10860. const renderItem = renderItems[ i ];
  10861. if ( renderItem.id === null ) break;
  10862. renderItem.id = null;
  10863. renderItem.object = null;
  10864. renderItem.geometry = null;
  10865. renderItem.material = null;
  10866. renderItem.program = null;
  10867. renderItem.group = null;
  10868. }
  10869. }
  10870. return {
  10871. opaque: opaque,
  10872. transparent: transparent,
  10873. init: init,
  10874. push: push,
  10875. unshift: unshift,
  10876. finish: finish,
  10877. sort: sort
  10878. };
  10879. }
  10880. function WebGLRenderLists( properties ) {
  10881. let lists = new WeakMap();
  10882. function get( scene, camera ) {
  10883. const cameras = lists.get( scene );
  10884. let list;
  10885. if ( cameras === undefined ) {
  10886. list = new WebGLRenderList( properties );
  10887. lists.set( scene, new WeakMap() );
  10888. lists.get( scene ).set( camera, list );
  10889. } else {
  10890. list = cameras.get( camera );
  10891. if ( list === undefined ) {
  10892. list = new WebGLRenderList( properties );
  10893. cameras.set( camera, list );
  10894. }
  10895. }
  10896. return list;
  10897. }
  10898. function dispose() {
  10899. lists = new WeakMap();
  10900. }
  10901. return {
  10902. get: get,
  10903. dispose: dispose
  10904. };
  10905. }
  10906. function UniformsCache() {
  10907. const lights = {};
  10908. return {
  10909. get: function ( light ) {
  10910. if ( lights[ light.id ] !== undefined ) {
  10911. return lights[ light.id ];
  10912. }
  10913. let uniforms;
  10914. switch ( light.type ) {
  10915. case 'DirectionalLight':
  10916. uniforms = {
  10917. direction: new Vector3(),
  10918. color: new Color()
  10919. };
  10920. break;
  10921. case 'SpotLight':
  10922. uniforms = {
  10923. position: new Vector3(),
  10924. direction: new Vector3(),
  10925. color: new Color(),
  10926. distance: 0,
  10927. coneCos: 0,
  10928. penumbraCos: 0,
  10929. decay: 0
  10930. };
  10931. break;
  10932. case 'PointLight':
  10933. uniforms = {
  10934. position: new Vector3(),
  10935. color: new Color(),
  10936. distance: 0,
  10937. decay: 0
  10938. };
  10939. break;
  10940. case 'HemisphereLight':
  10941. uniforms = {
  10942. direction: new Vector3(),
  10943. skyColor: new Color(),
  10944. groundColor: new Color()
  10945. };
  10946. break;
  10947. case 'RectAreaLight':
  10948. uniforms = {
  10949. color: new Color(),
  10950. position: new Vector3(),
  10951. halfWidth: new Vector3(),
  10952. halfHeight: new Vector3()
  10953. };
  10954. break;
  10955. }
  10956. lights[ light.id ] = uniforms;
  10957. return uniforms;
  10958. }
  10959. };
  10960. }
  10961. function ShadowUniformsCache() {
  10962. const lights = {};
  10963. return {
  10964. get: function ( light ) {
  10965. if ( lights[ light.id ] !== undefined ) {
  10966. return lights[ light.id ];
  10967. }
  10968. let uniforms;
  10969. switch ( light.type ) {
  10970. case 'DirectionalLight':
  10971. uniforms = {
  10972. shadowBias: 0,
  10973. shadowNormalBias: 0,
  10974. shadowRadius: 1,
  10975. shadowMapSize: new Vector2()
  10976. };
  10977. break;
  10978. case 'SpotLight':
  10979. uniforms = {
  10980. shadowBias: 0,
  10981. shadowNormalBias: 0,
  10982. shadowRadius: 1,
  10983. shadowMapSize: new Vector2()
  10984. };
  10985. break;
  10986. case 'PointLight':
  10987. uniforms = {
  10988. shadowBias: 0,
  10989. shadowNormalBias: 0,
  10990. shadowRadius: 1,
  10991. shadowMapSize: new Vector2(),
  10992. shadowCameraNear: 1,
  10993. shadowCameraFar: 1000
  10994. };
  10995. break;
  10996. // TODO (abelnation): set RectAreaLight shadow uniforms
  10997. }
  10998. lights[ light.id ] = uniforms;
  10999. return uniforms;
  11000. }
  11001. };
  11002. }
  11003. let nextVersion = 0;
  11004. function shadowCastingLightsFirst( lightA, lightB ) {
  11005. return ( lightB.castShadow ? 1 : 0 ) - ( lightA.castShadow ? 1 : 0 );
  11006. }
  11007. function WebGLLights( extensions, capabilities ) {
  11008. const cache = new UniformsCache();
  11009. const shadowCache = ShadowUniformsCache();
  11010. const state = {
  11011. version: 0,
  11012. hash: {
  11013. directionalLength: - 1,
  11014. pointLength: - 1,
  11015. spotLength: - 1,
  11016. rectAreaLength: - 1,
  11017. hemiLength: - 1,
  11018. numDirectionalShadows: - 1,
  11019. numPointShadows: - 1,
  11020. numSpotShadows: - 1
  11021. },
  11022. ambient: [ 0, 0, 0 ],
  11023. probe: [],
  11024. directional: [],
  11025. directionalShadow: [],
  11026. directionalShadowMap: [],
  11027. directionalShadowMatrix: [],
  11028. spot: [],
  11029. spotShadow: [],
  11030. spotShadowMap: [],
  11031. spotShadowMatrix: [],
  11032. rectArea: [],
  11033. rectAreaLTC1: null,
  11034. rectAreaLTC2: null,
  11035. point: [],
  11036. pointShadow: [],
  11037. pointShadowMap: [],
  11038. pointShadowMatrix: [],
  11039. hemi: []
  11040. };
  11041. for ( let i = 0; i < 9; i ++ ) state.probe.push( new Vector3() );
  11042. const vector3 = new Vector3();
  11043. const matrix4 = new Matrix4();
  11044. const matrix42 = new Matrix4();
  11045. function setup( lights ) {
  11046. let r = 0, g = 0, b = 0;
  11047. for ( let i = 0; i < 9; i ++ ) state.probe[ i ].set( 0, 0, 0 );
  11048. let directionalLength = 0;
  11049. let pointLength = 0;
  11050. let spotLength = 0;
  11051. let rectAreaLength = 0;
  11052. let hemiLength = 0;
  11053. let numDirectionalShadows = 0;
  11054. let numPointShadows = 0;
  11055. let numSpotShadows = 0;
  11056. lights.sort( shadowCastingLightsFirst );
  11057. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  11058. const light = lights[ i ];
  11059. const color = light.color;
  11060. const intensity = light.intensity;
  11061. const distance = light.distance;
  11062. const shadowMap = ( light.shadow && light.shadow.map ) ? light.shadow.map.texture : null;
  11063. if ( light.isAmbientLight ) {
  11064. r += color.r * intensity;
  11065. g += color.g * intensity;
  11066. b += color.b * intensity;
  11067. } else if ( light.isLightProbe ) {
  11068. for ( let j = 0; j < 9; j ++ ) {
  11069. state.probe[ j ].addScaledVector( light.sh.coefficients[ j ], intensity );
  11070. }
  11071. } else if ( light.isDirectionalLight ) {
  11072. const uniforms = cache.get( light );
  11073. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11074. if ( light.castShadow ) {
  11075. const shadow = light.shadow;
  11076. const shadowUniforms = shadowCache.get( light );
  11077. shadowUniforms.shadowBias = shadow.bias;
  11078. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11079. shadowUniforms.shadowRadius = shadow.radius;
  11080. shadowUniforms.shadowMapSize = shadow.mapSize;
  11081. state.directionalShadow[ directionalLength ] = shadowUniforms;
  11082. state.directionalShadowMap[ directionalLength ] = shadowMap;
  11083. state.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  11084. numDirectionalShadows ++;
  11085. }
  11086. state.directional[ directionalLength ] = uniforms;
  11087. directionalLength ++;
  11088. } else if ( light.isSpotLight ) {
  11089. const uniforms = cache.get( light );
  11090. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11091. uniforms.color.copy( color ).multiplyScalar( intensity );
  11092. uniforms.distance = distance;
  11093. uniforms.coneCos = Math.cos( light.angle );
  11094. uniforms.penumbraCos = Math.cos( light.angle * ( 1 - light.penumbra ) );
  11095. uniforms.decay = light.decay;
  11096. if ( light.castShadow ) {
  11097. const shadow = light.shadow;
  11098. const shadowUniforms = shadowCache.get( light );
  11099. shadowUniforms.shadowBias = shadow.bias;
  11100. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11101. shadowUniforms.shadowRadius = shadow.radius;
  11102. shadowUniforms.shadowMapSize = shadow.mapSize;
  11103. state.spotShadow[ spotLength ] = shadowUniforms;
  11104. state.spotShadowMap[ spotLength ] = shadowMap;
  11105. state.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  11106. numSpotShadows ++;
  11107. }
  11108. state.spot[ spotLength ] = uniforms;
  11109. spotLength ++;
  11110. } else if ( light.isRectAreaLight ) {
  11111. const uniforms = cache.get( light );
  11112. // (a) intensity is the total visible light emitted
  11113. //uniforms.color.copy( color ).multiplyScalar( intensity / ( light.width * light.height * Math.PI ) );
  11114. // (b) intensity is the brightness of the light
  11115. uniforms.color.copy( color ).multiplyScalar( intensity );
  11116. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11117. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11118. state.rectArea[ rectAreaLength ] = uniforms;
  11119. rectAreaLength ++;
  11120. } else if ( light.isPointLight ) {
  11121. const uniforms = cache.get( light );
  11122. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  11123. uniforms.distance = light.distance;
  11124. uniforms.decay = light.decay;
  11125. if ( light.castShadow ) {
  11126. const shadow = light.shadow;
  11127. const shadowUniforms = shadowCache.get( light );
  11128. shadowUniforms.shadowBias = shadow.bias;
  11129. shadowUniforms.shadowNormalBias = shadow.normalBias;
  11130. shadowUniforms.shadowRadius = shadow.radius;
  11131. shadowUniforms.shadowMapSize = shadow.mapSize;
  11132. shadowUniforms.shadowCameraNear = shadow.camera.near;
  11133. shadowUniforms.shadowCameraFar = shadow.camera.far;
  11134. state.pointShadow[ pointLength ] = shadowUniforms;
  11135. state.pointShadowMap[ pointLength ] = shadowMap;
  11136. state.pointShadowMatrix[ pointLength ] = light.shadow.matrix;
  11137. numPointShadows ++;
  11138. }
  11139. state.point[ pointLength ] = uniforms;
  11140. pointLength ++;
  11141. } else if ( light.isHemisphereLight ) {
  11142. const uniforms = cache.get( light );
  11143. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  11144. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  11145. state.hemi[ hemiLength ] = uniforms;
  11146. hemiLength ++;
  11147. }
  11148. }
  11149. if ( rectAreaLength > 0 ) {
  11150. if ( capabilities.isWebGL2 ) {
  11151. // WebGL 2
  11152. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11153. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11154. } else {
  11155. // WebGL 1
  11156. if ( extensions.has( 'OES_texture_float_linear' ) === true ) {
  11157. state.rectAreaLTC1 = UniformsLib.LTC_FLOAT_1;
  11158. state.rectAreaLTC2 = UniformsLib.LTC_FLOAT_2;
  11159. } else if ( extensions.has( 'OES_texture_half_float_linear' ) === true ) {
  11160. state.rectAreaLTC1 = UniformsLib.LTC_HALF_1;
  11161. state.rectAreaLTC2 = UniformsLib.LTC_HALF_2;
  11162. } else {
  11163. console.error( 'THREE.WebGLRenderer: Unable to use RectAreaLight. Missing WebGL extensions.' );
  11164. }
  11165. }
  11166. }
  11167. state.ambient[ 0 ] = r;
  11168. state.ambient[ 1 ] = g;
  11169. state.ambient[ 2 ] = b;
  11170. const hash = state.hash;
  11171. if ( hash.directionalLength !== directionalLength ||
  11172. hash.pointLength !== pointLength ||
  11173. hash.spotLength !== spotLength ||
  11174. hash.rectAreaLength !== rectAreaLength ||
  11175. hash.hemiLength !== hemiLength ||
  11176. hash.numDirectionalShadows !== numDirectionalShadows ||
  11177. hash.numPointShadows !== numPointShadows ||
  11178. hash.numSpotShadows !== numSpotShadows ) {
  11179. state.directional.length = directionalLength;
  11180. state.spot.length = spotLength;
  11181. state.rectArea.length = rectAreaLength;
  11182. state.point.length = pointLength;
  11183. state.hemi.length = hemiLength;
  11184. state.directionalShadow.length = numDirectionalShadows;
  11185. state.directionalShadowMap.length = numDirectionalShadows;
  11186. state.pointShadow.length = numPointShadows;
  11187. state.pointShadowMap.length = numPointShadows;
  11188. state.spotShadow.length = numSpotShadows;
  11189. state.spotShadowMap.length = numSpotShadows;
  11190. state.directionalShadowMatrix.length = numDirectionalShadows;
  11191. state.pointShadowMatrix.length = numPointShadows;
  11192. state.spotShadowMatrix.length = numSpotShadows;
  11193. hash.directionalLength = directionalLength;
  11194. hash.pointLength = pointLength;
  11195. hash.spotLength = spotLength;
  11196. hash.rectAreaLength = rectAreaLength;
  11197. hash.hemiLength = hemiLength;
  11198. hash.numDirectionalShadows = numDirectionalShadows;
  11199. hash.numPointShadows = numPointShadows;
  11200. hash.numSpotShadows = numSpotShadows;
  11201. state.version = nextVersion ++;
  11202. }
  11203. }
  11204. function setupView( lights, camera ) {
  11205. let directionalLength = 0;
  11206. let pointLength = 0;
  11207. let spotLength = 0;
  11208. let rectAreaLength = 0;
  11209. let hemiLength = 0;
  11210. const viewMatrix = camera.matrixWorldInverse;
  11211. for ( let i = 0, l = lights.length; i < l; i ++ ) {
  11212. const light = lights[ i ];
  11213. if ( light.isDirectionalLight ) {
  11214. const uniforms = state.directional[ directionalLength ];
  11215. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11216. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11217. uniforms.direction.sub( vector3 );
  11218. uniforms.direction.transformDirection( viewMatrix );
  11219. directionalLength ++;
  11220. } else if ( light.isSpotLight ) {
  11221. const uniforms = state.spot[ spotLength ];
  11222. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11223. uniforms.position.applyMatrix4( viewMatrix );
  11224. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11225. vector3.setFromMatrixPosition( light.target.matrixWorld );
  11226. uniforms.direction.sub( vector3 );
  11227. uniforms.direction.transformDirection( viewMatrix );
  11228. spotLength ++;
  11229. } else if ( light.isRectAreaLight ) {
  11230. const uniforms = state.rectArea[ rectAreaLength ];
  11231. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11232. uniforms.position.applyMatrix4( viewMatrix );
  11233. // extract local rotation of light to derive width/height half vectors
  11234. matrix42.identity();
  11235. matrix4.copy( light.matrixWorld );
  11236. matrix4.premultiply( viewMatrix );
  11237. matrix42.extractRotation( matrix4 );
  11238. uniforms.halfWidth.set( light.width * 0.5, 0.0, 0.0 );
  11239. uniforms.halfHeight.set( 0.0, light.height * 0.5, 0.0 );
  11240. uniforms.halfWidth.applyMatrix4( matrix42 );
  11241. uniforms.halfHeight.applyMatrix4( matrix42 );
  11242. rectAreaLength ++;
  11243. } else if ( light.isPointLight ) {
  11244. const uniforms = state.point[ pointLength ];
  11245. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  11246. uniforms.position.applyMatrix4( viewMatrix );
  11247. pointLength ++;
  11248. } else if ( light.isHemisphereLight ) {
  11249. const uniforms = state.hemi[ hemiLength ];
  11250. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  11251. uniforms.direction.transformDirection( viewMatrix );
  11252. uniforms.direction.normalize();
  11253. hemiLength ++;
  11254. }
  11255. }
  11256. }
  11257. return {
  11258. setup: setup,
  11259. setupView: setupView,
  11260. state: state
  11261. };
  11262. }
  11263. function WebGLRenderState( extensions, capabilities ) {
  11264. const lights = new WebGLLights( extensions, capabilities );
  11265. const lightsArray = [];
  11266. const shadowsArray = [];
  11267. function init() {
  11268. lightsArray.length = 0;
  11269. shadowsArray.length = 0;
  11270. }
  11271. function pushLight( light ) {
  11272. lightsArray.push( light );
  11273. }
  11274. function pushShadow( shadowLight ) {
  11275. shadowsArray.push( shadowLight );
  11276. }
  11277. function setupLights() {
  11278. lights.setup( lightsArray );
  11279. }
  11280. function setupLightsView( camera ) {
  11281. lights.setupView( lightsArray, camera );
  11282. }
  11283. const state = {
  11284. lightsArray: lightsArray,
  11285. shadowsArray: shadowsArray,
  11286. lights: lights
  11287. };
  11288. return {
  11289. init: init,
  11290. state: state,
  11291. setupLights: setupLights,
  11292. setupLightsView: setupLightsView,
  11293. pushLight: pushLight,
  11294. pushShadow: pushShadow
  11295. };
  11296. }
  11297. function WebGLRenderStates( extensions, capabilities ) {
  11298. let renderStates = new WeakMap();
  11299. function get( scene, renderCallDepth = 0 ) {
  11300. let renderState;
  11301. if ( renderStates.has( scene ) === false ) {
  11302. renderState = new WebGLRenderState( extensions, capabilities );
  11303. renderStates.set( scene, [] );
  11304. renderStates.get( scene ).push( renderState );
  11305. } else {
  11306. if ( renderCallDepth >= renderStates.get( scene ).length ) {
  11307. renderState = new WebGLRenderState( extensions, capabilities );
  11308. renderStates.get( scene ).push( renderState );
  11309. } else {
  11310. renderState = renderStates.get( scene )[ renderCallDepth ];
  11311. }
  11312. }
  11313. return renderState;
  11314. }
  11315. function dispose() {
  11316. renderStates = new WeakMap();
  11317. }
  11318. return {
  11319. get: get,
  11320. dispose: dispose
  11321. };
  11322. }
  11323. /**
  11324. * parameters = {
  11325. *
  11326. * opacity: <float>,
  11327. *
  11328. * map: new THREE.Texture( <Image> ),
  11329. *
  11330. * alphaMap: new THREE.Texture( <Image> ),
  11331. *
  11332. * displacementMap: new THREE.Texture( <Image> ),
  11333. * displacementScale: <float>,
  11334. * displacementBias: <float>,
  11335. *
  11336. * wireframe: <boolean>,
  11337. * wireframeLinewidth: <float>
  11338. * }
  11339. */
  11340. function MeshDepthMaterial( parameters ) {
  11341. Material.call( this );
  11342. this.type = 'MeshDepthMaterial';
  11343. this.depthPacking = BasicDepthPacking;
  11344. this.skinning = false;
  11345. this.morphTargets = false;
  11346. this.map = null;
  11347. this.alphaMap = null;
  11348. this.displacementMap = null;
  11349. this.displacementScale = 1;
  11350. this.displacementBias = 0;
  11351. this.wireframe = false;
  11352. this.wireframeLinewidth = 1;
  11353. this.fog = false;
  11354. this.setValues( parameters );
  11355. }
  11356. MeshDepthMaterial.prototype = Object.create( Material.prototype );
  11357. MeshDepthMaterial.prototype.constructor = MeshDepthMaterial;
  11358. MeshDepthMaterial.prototype.isMeshDepthMaterial = true;
  11359. MeshDepthMaterial.prototype.copy = function ( source ) {
  11360. Material.prototype.copy.call( this, source );
  11361. this.depthPacking = source.depthPacking;
  11362. this.skinning = source.skinning;
  11363. this.morphTargets = source.morphTargets;
  11364. this.map = source.map;
  11365. this.alphaMap = source.alphaMap;
  11366. this.displacementMap = source.displacementMap;
  11367. this.displacementScale = source.displacementScale;
  11368. this.displacementBias = source.displacementBias;
  11369. this.wireframe = source.wireframe;
  11370. this.wireframeLinewidth = source.wireframeLinewidth;
  11371. return this;
  11372. };
  11373. /**
  11374. * parameters = {
  11375. *
  11376. * referencePosition: <float>,
  11377. * nearDistance: <float>,
  11378. * farDistance: <float>,
  11379. *
  11380. * skinning: <bool>,
  11381. * morphTargets: <bool>,
  11382. *
  11383. * map: new THREE.Texture( <Image> ),
  11384. *
  11385. * alphaMap: new THREE.Texture( <Image> ),
  11386. *
  11387. * displacementMap: new THREE.Texture( <Image> ),
  11388. * displacementScale: <float>,
  11389. * displacementBias: <float>
  11390. *
  11391. * }
  11392. */
  11393. function MeshDistanceMaterial( parameters ) {
  11394. Material.call( this );
  11395. this.type = 'MeshDistanceMaterial';
  11396. this.referencePosition = new Vector3();
  11397. this.nearDistance = 1;
  11398. this.farDistance = 1000;
  11399. this.skinning = false;
  11400. this.morphTargets = false;
  11401. this.map = null;
  11402. this.alphaMap = null;
  11403. this.displacementMap = null;
  11404. this.displacementScale = 1;
  11405. this.displacementBias = 0;
  11406. this.fog = false;
  11407. this.setValues( parameters );
  11408. }
  11409. MeshDistanceMaterial.prototype = Object.create( Material.prototype );
  11410. MeshDistanceMaterial.prototype.constructor = MeshDistanceMaterial;
  11411. MeshDistanceMaterial.prototype.isMeshDistanceMaterial = true;
  11412. MeshDistanceMaterial.prototype.copy = function ( source ) {
  11413. Material.prototype.copy.call( this, source );
  11414. this.referencePosition.copy( source.referencePosition );
  11415. this.nearDistance = source.nearDistance;
  11416. this.farDistance = source.farDistance;
  11417. this.skinning = source.skinning;
  11418. this.morphTargets = source.morphTargets;
  11419. this.map = source.map;
  11420. this.alphaMap = source.alphaMap;
  11421. this.displacementMap = source.displacementMap;
  11422. this.displacementScale = source.displacementScale;
  11423. this.displacementBias = source.displacementBias;
  11424. return this;
  11425. };
  11426. 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}";
  11427. var vsm_vert = "void main() {\n\tgl_Position = vec4( position, 1.0 );\n}";
  11428. function WebGLShadowMap( _renderer, _objects, maxTextureSize ) {
  11429. let _frustum = new Frustum();
  11430. const _shadowMapSize = new Vector2(),
  11431. _viewportSize = new Vector2(),
  11432. _viewport = new Vector4(),
  11433. _depthMaterials = [],
  11434. _distanceMaterials = [],
  11435. _materialCache = {};
  11436. const shadowSide = { 0: BackSide, 1: FrontSide, 2: DoubleSide };
  11437. const shadowMaterialVertical = new ShaderMaterial( {
  11438. defines: {
  11439. SAMPLE_RATE: 2.0 / 8.0,
  11440. HALF_SAMPLE_RATE: 1.0 / 8.0
  11441. },
  11442. uniforms: {
  11443. shadow_pass: { value: null },
  11444. resolution: { value: new Vector2() },
  11445. radius: { value: 4.0 }
  11446. },
  11447. vertexShader: vsm_vert,
  11448. fragmentShader: vsm_frag
  11449. } );
  11450. const shadowMaterialHorizontal = shadowMaterialVertical.clone();
  11451. shadowMaterialHorizontal.defines.HORIZONTAL_PASS = 1;
  11452. const fullScreenTri = new BufferGeometry();
  11453. fullScreenTri.setAttribute(
  11454. 'position',
  11455. new BufferAttribute(
  11456. new Float32Array( [ - 1, - 1, 0.5, 3, - 1, 0.5, - 1, 3, 0.5 ] ),
  11457. 3
  11458. )
  11459. );
  11460. const fullScreenMesh = new Mesh( fullScreenTri, shadowMaterialVertical );
  11461. const scope = this;
  11462. this.enabled = false;
  11463. this.autoUpdate = true;
  11464. this.needsUpdate = false;
  11465. this.type = PCFShadowMap;
  11466. this.render = function ( lights, scene, camera ) {
  11467. if ( scope.enabled === false ) return;
  11468. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  11469. if ( lights.length === 0 ) return;
  11470. const currentRenderTarget = _renderer.getRenderTarget();
  11471. const activeCubeFace = _renderer.getActiveCubeFace();
  11472. const activeMipmapLevel = _renderer.getActiveMipmapLevel();
  11473. const _state = _renderer.state;
  11474. // Set GL state for depth map.
  11475. _state.setBlending( NoBlending );
  11476. _state.buffers.color.setClear( 1, 1, 1, 1 );
  11477. _state.buffers.depth.setTest( true );
  11478. _state.setScissorTest( false );
  11479. // render depth map
  11480. for ( let i = 0, il = lights.length; i < il; i ++ ) {
  11481. const light = lights[ i ];
  11482. const shadow = light.shadow;
  11483. if ( shadow === undefined ) {
  11484. console.warn( 'THREE.WebGLShadowMap:', light, 'has no shadow.' );
  11485. continue;
  11486. }
  11487. if ( shadow.autoUpdate === false && shadow.needsUpdate === false ) continue;
  11488. _shadowMapSize.copy( shadow.mapSize );
  11489. const shadowFrameExtents = shadow.getFrameExtents();
  11490. _shadowMapSize.multiply( shadowFrameExtents );
  11491. _viewportSize.copy( shadow.mapSize );
  11492. if ( _shadowMapSize.x > maxTextureSize || _shadowMapSize.y > maxTextureSize ) {
  11493. if ( _shadowMapSize.x > maxTextureSize ) {
  11494. _viewportSize.x = Math.floor( maxTextureSize / shadowFrameExtents.x );
  11495. _shadowMapSize.x = _viewportSize.x * shadowFrameExtents.x;
  11496. shadow.mapSize.x = _viewportSize.x;
  11497. }
  11498. if ( _shadowMapSize.y > maxTextureSize ) {
  11499. _viewportSize.y = Math.floor( maxTextureSize / shadowFrameExtents.y );
  11500. _shadowMapSize.y = _viewportSize.y * shadowFrameExtents.y;
  11501. shadow.mapSize.y = _viewportSize.y;
  11502. }
  11503. }
  11504. if ( shadow.map === null && ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11505. const pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  11506. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11507. shadow.map.texture.name = light.name + '.shadowMap';
  11508. shadow.mapPass = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11509. shadow.camera.updateProjectionMatrix();
  11510. }
  11511. if ( shadow.map === null ) {
  11512. const pars = { minFilter: NearestFilter, magFilter: NearestFilter, format: RGBAFormat };
  11513. shadow.map = new WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  11514. shadow.map.texture.name = light.name + '.shadowMap';
  11515. shadow.camera.updateProjectionMatrix();
  11516. }
  11517. _renderer.setRenderTarget( shadow.map );
  11518. _renderer.clear();
  11519. const viewportCount = shadow.getViewportCount();
  11520. for ( let vp = 0; vp < viewportCount; vp ++ ) {
  11521. const viewport = shadow.getViewport( vp );
  11522. _viewport.set(
  11523. _viewportSize.x * viewport.x,
  11524. _viewportSize.y * viewport.y,
  11525. _viewportSize.x * viewport.z,
  11526. _viewportSize.y * viewport.w
  11527. );
  11528. _state.viewport( _viewport );
  11529. shadow.updateMatrices( light, vp );
  11530. _frustum = shadow.getFrustum();
  11531. renderObject( scene, camera, shadow.camera, light, this.type );
  11532. }
  11533. // do blur pass for VSM
  11534. if ( ! shadow.isPointLightShadow && this.type === VSMShadowMap ) {
  11535. VSMPass( shadow, camera );
  11536. }
  11537. shadow.needsUpdate = false;
  11538. }
  11539. scope.needsUpdate = false;
  11540. _renderer.setRenderTarget( currentRenderTarget, activeCubeFace, activeMipmapLevel );
  11541. };
  11542. function VSMPass( shadow, camera ) {
  11543. const geometry = _objects.update( fullScreenMesh );
  11544. // vertical pass
  11545. shadowMaterialVertical.uniforms.shadow_pass.value = shadow.map.texture;
  11546. shadowMaterialVertical.uniforms.resolution.value = shadow.mapSize;
  11547. shadowMaterialVertical.uniforms.radius.value = shadow.radius;
  11548. _renderer.setRenderTarget( shadow.mapPass );
  11549. _renderer.clear();
  11550. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialVertical, fullScreenMesh, null );
  11551. // horizontal pass
  11552. shadowMaterialHorizontal.uniforms.shadow_pass.value = shadow.mapPass.texture;
  11553. shadowMaterialHorizontal.uniforms.resolution.value = shadow.mapSize;
  11554. shadowMaterialHorizontal.uniforms.radius.value = shadow.radius;
  11555. _renderer.setRenderTarget( shadow.map );
  11556. _renderer.clear();
  11557. _renderer.renderBufferDirect( camera, null, geometry, shadowMaterialHorizontal, fullScreenMesh, null );
  11558. }
  11559. function getDepthMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11560. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11561. let material = _depthMaterials[ index ];
  11562. if ( material === undefined ) {
  11563. material = new MeshDepthMaterial( {
  11564. depthPacking: RGBADepthPacking,
  11565. morphTargets: useMorphing,
  11566. skinning: useSkinning
  11567. } );
  11568. _depthMaterials[ index ] = material;
  11569. }
  11570. return material;
  11571. }
  11572. function getDistanceMaterialVariant( useMorphing, useSkinning, useInstancing ) {
  11573. const index = useMorphing << 0 | useSkinning << 1 | useInstancing << 2;
  11574. let material = _distanceMaterials[ index ];
  11575. if ( material === undefined ) {
  11576. material = new MeshDistanceMaterial( {
  11577. morphTargets: useMorphing,
  11578. skinning: useSkinning
  11579. } );
  11580. _distanceMaterials[ index ] = material;
  11581. }
  11582. return material;
  11583. }
  11584. function getDepthMaterial( object, geometry, material, light, shadowCameraNear, shadowCameraFar, type ) {
  11585. let result = null;
  11586. let getMaterialVariant = getDepthMaterialVariant;
  11587. let customMaterial = object.customDepthMaterial;
  11588. if ( light.isPointLight === true ) {
  11589. getMaterialVariant = getDistanceMaterialVariant;
  11590. customMaterial = object.customDistanceMaterial;
  11591. }
  11592. if ( customMaterial === undefined ) {
  11593. let useMorphing = false;
  11594. if ( material.morphTargets === true ) {
  11595. useMorphing = geometry.morphAttributes && geometry.morphAttributes.position && geometry.morphAttributes.position.length > 0;
  11596. }
  11597. let useSkinning = false;
  11598. if ( object.isSkinnedMesh === true ) {
  11599. if ( material.skinning === true ) {
  11600. useSkinning = true;
  11601. } else {
  11602. console.warn( 'THREE.WebGLShadowMap: THREE.SkinnedMesh with material.skinning set to false:', object );
  11603. }
  11604. }
  11605. const useInstancing = object.isInstancedMesh === true;
  11606. result = getMaterialVariant( useMorphing, useSkinning, useInstancing );
  11607. } else {
  11608. result = customMaterial;
  11609. }
  11610. if ( _renderer.localClippingEnabled &&
  11611. material.clipShadows === true &&
  11612. material.clippingPlanes.length !== 0 ) {
  11613. // in this case we need a unique material instance reflecting the
  11614. // appropriate state
  11615. const keyA = result.uuid, keyB = material.uuid;
  11616. let materialsForVariant = _materialCache[ keyA ];
  11617. if ( materialsForVariant === undefined ) {
  11618. materialsForVariant = {};
  11619. _materialCache[ keyA ] = materialsForVariant;
  11620. }
  11621. let cachedMaterial = materialsForVariant[ keyB ];
  11622. if ( cachedMaterial === undefined ) {
  11623. cachedMaterial = result.clone();
  11624. materialsForVariant[ keyB ] = cachedMaterial;
  11625. }
  11626. result = cachedMaterial;
  11627. }
  11628. result.visible = material.visible;
  11629. result.wireframe = material.wireframe;
  11630. if ( type === VSMShadowMap ) {
  11631. result.side = ( material.shadowSide !== null ) ? material.shadowSide : material.side;
  11632. } else {
  11633. result.side = ( material.shadowSide !== null ) ? material.shadowSide : shadowSide[ material.side ];
  11634. }
  11635. result.clipShadows = material.clipShadows;
  11636. result.clippingPlanes = material.clippingPlanes;
  11637. result.clipIntersection = material.clipIntersection;
  11638. result.wireframeLinewidth = material.wireframeLinewidth;
  11639. result.linewidth = material.linewidth;
  11640. if ( light.isPointLight === true && result.isMeshDistanceMaterial === true ) {
  11641. result.referencePosition.setFromMatrixPosition( light.matrixWorld );
  11642. result.nearDistance = shadowCameraNear;
  11643. result.farDistance = shadowCameraFar;
  11644. }
  11645. return result;
  11646. }
  11647. function renderObject( object, camera, shadowCamera, light, type ) {
  11648. if ( object.visible === false ) return;
  11649. const visible = object.layers.test( camera.layers );
  11650. if ( visible && ( object.isMesh || object.isLine || object.isPoints ) ) {
  11651. if ( ( object.castShadow || ( object.receiveShadow && type === VSMShadowMap ) ) && ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) ) {
  11652. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  11653. const geometry = _objects.update( object );
  11654. const material = object.material;
  11655. if ( Array.isArray( material ) ) {
  11656. const groups = geometry.groups;
  11657. for ( let k = 0, kl = groups.length; k < kl; k ++ ) {
  11658. const group = groups[ k ];
  11659. const groupMaterial = material[ group.materialIndex ];
  11660. if ( groupMaterial && groupMaterial.visible ) {
  11661. const depthMaterial = getDepthMaterial( object, geometry, groupMaterial, light, shadowCamera.near, shadowCamera.far, type );
  11662. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  11663. }
  11664. }
  11665. } else if ( material.visible ) {
  11666. const depthMaterial = getDepthMaterial( object, geometry, material, light, shadowCamera.near, shadowCamera.far, type );
  11667. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  11668. }
  11669. }
  11670. }
  11671. const children = object.children;
  11672. for ( let i = 0, l = children.length; i < l; i ++ ) {
  11673. renderObject( children[ i ], camera, shadowCamera, light, type );
  11674. }
  11675. }
  11676. }
  11677. function WebGLState( gl, extensions, capabilities ) {
  11678. const isWebGL2 = capabilities.isWebGL2;
  11679. function ColorBuffer() {
  11680. let locked = false;
  11681. const color = new Vector4();
  11682. let currentColorMask = null;
  11683. const currentColorClear = new Vector4( 0, 0, 0, 0 );
  11684. return {
  11685. setMask: function ( colorMask ) {
  11686. if ( currentColorMask !== colorMask && ! locked ) {
  11687. gl.colorMask( colorMask, colorMask, colorMask, colorMask );
  11688. currentColorMask = colorMask;
  11689. }
  11690. },
  11691. setLocked: function ( lock ) {
  11692. locked = lock;
  11693. },
  11694. setClear: function ( r, g, b, a, premultipliedAlpha ) {
  11695. if ( premultipliedAlpha === true ) {
  11696. r *= a; g *= a; b *= a;
  11697. }
  11698. color.set( r, g, b, a );
  11699. if ( currentColorClear.equals( color ) === false ) {
  11700. gl.clearColor( r, g, b, a );
  11701. currentColorClear.copy( color );
  11702. }
  11703. },
  11704. reset: function () {
  11705. locked = false;
  11706. currentColorMask = null;
  11707. currentColorClear.set( - 1, 0, 0, 0 ); // set to invalid state
  11708. }
  11709. };
  11710. }
  11711. function DepthBuffer() {
  11712. let locked = false;
  11713. let currentDepthMask = null;
  11714. let currentDepthFunc = null;
  11715. let currentDepthClear = null;
  11716. return {
  11717. setTest: function ( depthTest ) {
  11718. if ( depthTest ) {
  11719. enable( 2929 );
  11720. } else {
  11721. disable( 2929 );
  11722. }
  11723. },
  11724. setMask: function ( depthMask ) {
  11725. if ( currentDepthMask !== depthMask && ! locked ) {
  11726. gl.depthMask( depthMask );
  11727. currentDepthMask = depthMask;
  11728. }
  11729. },
  11730. setFunc: function ( depthFunc ) {
  11731. if ( currentDepthFunc !== depthFunc ) {
  11732. if ( depthFunc ) {
  11733. switch ( depthFunc ) {
  11734. case NeverDepth:
  11735. gl.depthFunc( 512 );
  11736. break;
  11737. case AlwaysDepth:
  11738. gl.depthFunc( 519 );
  11739. break;
  11740. case LessDepth:
  11741. gl.depthFunc( 513 );
  11742. break;
  11743. case LessEqualDepth:
  11744. gl.depthFunc( 515 );
  11745. break;
  11746. case EqualDepth:
  11747. gl.depthFunc( 514 );
  11748. break;
  11749. case GreaterEqualDepth:
  11750. gl.depthFunc( 518 );
  11751. break;
  11752. case GreaterDepth:
  11753. gl.depthFunc( 516 );
  11754. break;
  11755. case NotEqualDepth:
  11756. gl.depthFunc( 517 );
  11757. break;
  11758. default:
  11759. gl.depthFunc( 515 );
  11760. }
  11761. } else {
  11762. gl.depthFunc( 515 );
  11763. }
  11764. currentDepthFunc = depthFunc;
  11765. }
  11766. },
  11767. setLocked: function ( lock ) {
  11768. locked = lock;
  11769. },
  11770. setClear: function ( depth ) {
  11771. if ( currentDepthClear !== depth ) {
  11772. gl.clearDepth( depth );
  11773. currentDepthClear = depth;
  11774. }
  11775. },
  11776. reset: function () {
  11777. locked = false;
  11778. currentDepthMask = null;
  11779. currentDepthFunc = null;
  11780. currentDepthClear = null;
  11781. }
  11782. };
  11783. }
  11784. function StencilBuffer() {
  11785. let locked = false;
  11786. let currentStencilMask = null;
  11787. let currentStencilFunc = null;
  11788. let currentStencilRef = null;
  11789. let currentStencilFuncMask = null;
  11790. let currentStencilFail = null;
  11791. let currentStencilZFail = null;
  11792. let currentStencilZPass = null;
  11793. let currentStencilClear = null;
  11794. return {
  11795. setTest: function ( stencilTest ) {
  11796. if ( ! locked ) {
  11797. if ( stencilTest ) {
  11798. enable( 2960 );
  11799. } else {
  11800. disable( 2960 );
  11801. }
  11802. }
  11803. },
  11804. setMask: function ( stencilMask ) {
  11805. if ( currentStencilMask !== stencilMask && ! locked ) {
  11806. gl.stencilMask( stencilMask );
  11807. currentStencilMask = stencilMask;
  11808. }
  11809. },
  11810. setFunc: function ( stencilFunc, stencilRef, stencilMask ) {
  11811. if ( currentStencilFunc !== stencilFunc ||
  11812. currentStencilRef !== stencilRef ||
  11813. currentStencilFuncMask !== stencilMask ) {
  11814. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  11815. currentStencilFunc = stencilFunc;
  11816. currentStencilRef = stencilRef;
  11817. currentStencilFuncMask = stencilMask;
  11818. }
  11819. },
  11820. setOp: function ( stencilFail, stencilZFail, stencilZPass ) {
  11821. if ( currentStencilFail !== stencilFail ||
  11822. currentStencilZFail !== stencilZFail ||
  11823. currentStencilZPass !== stencilZPass ) {
  11824. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  11825. currentStencilFail = stencilFail;
  11826. currentStencilZFail = stencilZFail;
  11827. currentStencilZPass = stencilZPass;
  11828. }
  11829. },
  11830. setLocked: function ( lock ) {
  11831. locked = lock;
  11832. },
  11833. setClear: function ( stencil ) {
  11834. if ( currentStencilClear !== stencil ) {
  11835. gl.clearStencil( stencil );
  11836. currentStencilClear = stencil;
  11837. }
  11838. },
  11839. reset: function () {
  11840. locked = false;
  11841. currentStencilMask = null;
  11842. currentStencilFunc = null;
  11843. currentStencilRef = null;
  11844. currentStencilFuncMask = null;
  11845. currentStencilFail = null;
  11846. currentStencilZFail = null;
  11847. currentStencilZPass = null;
  11848. currentStencilClear = null;
  11849. }
  11850. };
  11851. }
  11852. //
  11853. const colorBuffer = new ColorBuffer();
  11854. const depthBuffer = new DepthBuffer();
  11855. const stencilBuffer = new StencilBuffer();
  11856. let enabledCapabilities = {};
  11857. let currentProgram = null;
  11858. let currentBlendingEnabled = null;
  11859. let currentBlending = null;
  11860. let currentBlendEquation = null;
  11861. let currentBlendSrc = null;
  11862. let currentBlendDst = null;
  11863. let currentBlendEquationAlpha = null;
  11864. let currentBlendSrcAlpha = null;
  11865. let currentBlendDstAlpha = null;
  11866. let currentPremultipledAlpha = false;
  11867. let currentFlipSided = null;
  11868. let currentCullFace = null;
  11869. let currentLineWidth = null;
  11870. let currentPolygonOffsetFactor = null;
  11871. let currentPolygonOffsetUnits = null;
  11872. const maxTextures = gl.getParameter( 35661 );
  11873. let lineWidthAvailable = false;
  11874. let version = 0;
  11875. const glVersion = gl.getParameter( 7938 );
  11876. if ( glVersion.indexOf( 'WebGL' ) !== - 1 ) {
  11877. version = parseFloat( /^WebGL (\d)/.exec( glVersion )[ 1 ] );
  11878. lineWidthAvailable = ( version >= 1.0 );
  11879. } else if ( glVersion.indexOf( 'OpenGL ES' ) !== - 1 ) {
  11880. version = parseFloat( /^OpenGL ES (\d)/.exec( glVersion )[ 1 ] );
  11881. lineWidthAvailable = ( version >= 2.0 );
  11882. }
  11883. let currentTextureSlot = null;
  11884. let currentBoundTextures = {};
  11885. const currentScissor = new Vector4();
  11886. const currentViewport = new Vector4();
  11887. function createTexture( type, target, count ) {
  11888. const data = new Uint8Array( 4 ); // 4 is required to match default unpack alignment of 4.
  11889. const texture = gl.createTexture();
  11890. gl.bindTexture( type, texture );
  11891. gl.texParameteri( type, 10241, 9728 );
  11892. gl.texParameteri( type, 10240, 9728 );
  11893. for ( let i = 0; i < count; i ++ ) {
  11894. gl.texImage2D( target + i, 0, 6408, 1, 1, 0, 6408, 5121, data );
  11895. }
  11896. return texture;
  11897. }
  11898. const emptyTextures = {};
  11899. emptyTextures[ 3553 ] = createTexture( 3553, 3553, 1 );
  11900. emptyTextures[ 34067 ] = createTexture( 34067, 34069, 6 );
  11901. // init
  11902. colorBuffer.setClear( 0, 0, 0, 1 );
  11903. depthBuffer.setClear( 1 );
  11904. stencilBuffer.setClear( 0 );
  11905. enable( 2929 );
  11906. depthBuffer.setFunc( LessEqualDepth );
  11907. setFlipSided( false );
  11908. setCullFace( CullFaceBack );
  11909. enable( 2884 );
  11910. setBlending( NoBlending );
  11911. //
  11912. function enable( id ) {
  11913. if ( enabledCapabilities[ id ] !== true ) {
  11914. gl.enable( id );
  11915. enabledCapabilities[ id ] = true;
  11916. }
  11917. }
  11918. function disable( id ) {
  11919. if ( enabledCapabilities[ id ] !== false ) {
  11920. gl.disable( id );
  11921. enabledCapabilities[ id ] = false;
  11922. }
  11923. }
  11924. function useProgram( program ) {
  11925. if ( currentProgram !== program ) {
  11926. gl.useProgram( program );
  11927. currentProgram = program;
  11928. return true;
  11929. }
  11930. return false;
  11931. }
  11932. const equationToGL = {
  11933. [ AddEquation ]: 32774,
  11934. [ SubtractEquation ]: 32778,
  11935. [ ReverseSubtractEquation ]: 32779
  11936. };
  11937. if ( isWebGL2 ) {
  11938. equationToGL[ MinEquation ] = 32775;
  11939. equationToGL[ MaxEquation ] = 32776;
  11940. } else {
  11941. const extension = extensions.get( 'EXT_blend_minmax' );
  11942. if ( extension !== null ) {
  11943. equationToGL[ MinEquation ] = extension.MIN_EXT;
  11944. equationToGL[ MaxEquation ] = extension.MAX_EXT;
  11945. }
  11946. }
  11947. const factorToGL = {
  11948. [ ZeroFactor ]: 0,
  11949. [ OneFactor ]: 1,
  11950. [ SrcColorFactor ]: 768,
  11951. [ SrcAlphaFactor ]: 770,
  11952. [ SrcAlphaSaturateFactor ]: 776,
  11953. [ DstColorFactor ]: 774,
  11954. [ DstAlphaFactor ]: 772,
  11955. [ OneMinusSrcColorFactor ]: 769,
  11956. [ OneMinusSrcAlphaFactor ]: 771,
  11957. [ OneMinusDstColorFactor ]: 775,
  11958. [ OneMinusDstAlphaFactor ]: 773
  11959. };
  11960. function setBlending( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha, premultipliedAlpha ) {
  11961. if ( blending === NoBlending ) {
  11962. if ( currentBlendingEnabled ) {
  11963. disable( 3042 );
  11964. currentBlendingEnabled = false;
  11965. }
  11966. return;
  11967. }
  11968. if ( ! currentBlendingEnabled ) {
  11969. enable( 3042 );
  11970. currentBlendingEnabled = true;
  11971. }
  11972. if ( blending !== CustomBlending ) {
  11973. if ( blending !== currentBlending || premultipliedAlpha !== currentPremultipledAlpha ) {
  11974. if ( currentBlendEquation !== AddEquation || currentBlendEquationAlpha !== AddEquation ) {
  11975. gl.blendEquation( 32774 );
  11976. currentBlendEquation = AddEquation;
  11977. currentBlendEquationAlpha = AddEquation;
  11978. }
  11979. if ( premultipliedAlpha ) {
  11980. switch ( blending ) {
  11981. case NormalBlending:
  11982. gl.blendFuncSeparate( 1, 771, 1, 771 );
  11983. break;
  11984. case AdditiveBlending:
  11985. gl.blendFunc( 1, 1 );
  11986. break;
  11987. case SubtractiveBlending:
  11988. gl.blendFuncSeparate( 0, 0, 769, 771 );
  11989. break;
  11990. case MultiplyBlending:
  11991. gl.blendFuncSeparate( 0, 768, 0, 770 );
  11992. break;
  11993. default:
  11994. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  11995. break;
  11996. }
  11997. } else {
  11998. switch ( blending ) {
  11999. case NormalBlending:
  12000. gl.blendFuncSeparate( 770, 771, 1, 771 );
  12001. break;
  12002. case AdditiveBlending:
  12003. gl.blendFunc( 770, 1 );
  12004. break;
  12005. case SubtractiveBlending:
  12006. gl.blendFunc( 0, 769 );
  12007. break;
  12008. case MultiplyBlending:
  12009. gl.blendFunc( 0, 768 );
  12010. break;
  12011. default:
  12012. console.error( 'THREE.WebGLState: Invalid blending: ', blending );
  12013. break;
  12014. }
  12015. }
  12016. currentBlendSrc = null;
  12017. currentBlendDst = null;
  12018. currentBlendSrcAlpha = null;
  12019. currentBlendDstAlpha = null;
  12020. currentBlending = blending;
  12021. currentPremultipledAlpha = premultipliedAlpha;
  12022. }
  12023. return;
  12024. }
  12025. // custom blending
  12026. blendEquationAlpha = blendEquationAlpha || blendEquation;
  12027. blendSrcAlpha = blendSrcAlpha || blendSrc;
  12028. blendDstAlpha = blendDstAlpha || blendDst;
  12029. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  12030. gl.blendEquationSeparate( equationToGL[ blendEquation ], equationToGL[ blendEquationAlpha ] );
  12031. currentBlendEquation = blendEquation;
  12032. currentBlendEquationAlpha = blendEquationAlpha;
  12033. }
  12034. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  12035. gl.blendFuncSeparate( factorToGL[ blendSrc ], factorToGL[ blendDst ], factorToGL[ blendSrcAlpha ], factorToGL[ blendDstAlpha ] );
  12036. currentBlendSrc = blendSrc;
  12037. currentBlendDst = blendDst;
  12038. currentBlendSrcAlpha = blendSrcAlpha;
  12039. currentBlendDstAlpha = blendDstAlpha;
  12040. }
  12041. currentBlending = blending;
  12042. currentPremultipledAlpha = null;
  12043. }
  12044. function setMaterial( material, frontFaceCW ) {
  12045. material.side === DoubleSide
  12046. ? disable( 2884 )
  12047. : enable( 2884 );
  12048. let flipSided = ( material.side === BackSide );
  12049. if ( frontFaceCW ) flipSided = ! flipSided;
  12050. setFlipSided( flipSided );
  12051. ( material.blending === NormalBlending && material.transparent === false )
  12052. ? setBlending( NoBlending )
  12053. : setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha, material.premultipliedAlpha );
  12054. depthBuffer.setFunc( material.depthFunc );
  12055. depthBuffer.setTest( material.depthTest );
  12056. depthBuffer.setMask( material.depthWrite );
  12057. colorBuffer.setMask( material.colorWrite );
  12058. const stencilWrite = material.stencilWrite;
  12059. stencilBuffer.setTest( stencilWrite );
  12060. if ( stencilWrite ) {
  12061. stencilBuffer.setMask( material.stencilWriteMask );
  12062. stencilBuffer.setFunc( material.stencilFunc, material.stencilRef, material.stencilFuncMask );
  12063. stencilBuffer.setOp( material.stencilFail, material.stencilZFail, material.stencilZPass );
  12064. }
  12065. setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12066. }
  12067. //
  12068. function setFlipSided( flipSided ) {
  12069. if ( currentFlipSided !== flipSided ) {
  12070. if ( flipSided ) {
  12071. gl.frontFace( 2304 );
  12072. } else {
  12073. gl.frontFace( 2305 );
  12074. }
  12075. currentFlipSided = flipSided;
  12076. }
  12077. }
  12078. function setCullFace( cullFace ) {
  12079. if ( cullFace !== CullFaceNone ) {
  12080. enable( 2884 );
  12081. if ( cullFace !== currentCullFace ) {
  12082. if ( cullFace === CullFaceBack ) {
  12083. gl.cullFace( 1029 );
  12084. } else if ( cullFace === CullFaceFront ) {
  12085. gl.cullFace( 1028 );
  12086. } else {
  12087. gl.cullFace( 1032 );
  12088. }
  12089. }
  12090. } else {
  12091. disable( 2884 );
  12092. }
  12093. currentCullFace = cullFace;
  12094. }
  12095. function setLineWidth( width ) {
  12096. if ( width !== currentLineWidth ) {
  12097. if ( lineWidthAvailable ) gl.lineWidth( width );
  12098. currentLineWidth = width;
  12099. }
  12100. }
  12101. function setPolygonOffset( polygonOffset, factor, units ) {
  12102. if ( polygonOffset ) {
  12103. enable( 32823 );
  12104. if ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) {
  12105. gl.polygonOffset( factor, units );
  12106. currentPolygonOffsetFactor = factor;
  12107. currentPolygonOffsetUnits = units;
  12108. }
  12109. } else {
  12110. disable( 32823 );
  12111. }
  12112. }
  12113. function setScissorTest( scissorTest ) {
  12114. if ( scissorTest ) {
  12115. enable( 3089 );
  12116. } else {
  12117. disable( 3089 );
  12118. }
  12119. }
  12120. // texture
  12121. function activeTexture( webglSlot ) {
  12122. if ( webglSlot === undefined ) webglSlot = 33984 + maxTextures - 1;
  12123. if ( currentTextureSlot !== webglSlot ) {
  12124. gl.activeTexture( webglSlot );
  12125. currentTextureSlot = webglSlot;
  12126. }
  12127. }
  12128. function bindTexture( webglType, webglTexture ) {
  12129. if ( currentTextureSlot === null ) {
  12130. activeTexture();
  12131. }
  12132. let boundTexture = currentBoundTextures[ currentTextureSlot ];
  12133. if ( boundTexture === undefined ) {
  12134. boundTexture = { type: undefined, texture: undefined };
  12135. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  12136. }
  12137. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  12138. gl.bindTexture( webglType, webglTexture || emptyTextures[ webglType ] );
  12139. boundTexture.type = webglType;
  12140. boundTexture.texture = webglTexture;
  12141. }
  12142. }
  12143. function unbindTexture() {
  12144. const boundTexture = currentBoundTextures[ currentTextureSlot ];
  12145. if ( boundTexture !== undefined && boundTexture.type !== undefined ) {
  12146. gl.bindTexture( boundTexture.type, null );
  12147. boundTexture.type = undefined;
  12148. boundTexture.texture = undefined;
  12149. }
  12150. }
  12151. function compressedTexImage2D() {
  12152. try {
  12153. gl.compressedTexImage2D.apply( gl, arguments );
  12154. } catch ( error ) {
  12155. console.error( 'THREE.WebGLState:', error );
  12156. }
  12157. }
  12158. function texImage2D() {
  12159. try {
  12160. gl.texImage2D.apply( gl, arguments );
  12161. } catch ( error ) {
  12162. console.error( 'THREE.WebGLState:', error );
  12163. }
  12164. }
  12165. function texImage3D() {
  12166. try {
  12167. gl.texImage3D.apply( gl, arguments );
  12168. } catch ( error ) {
  12169. console.error( 'THREE.WebGLState:', error );
  12170. }
  12171. }
  12172. //
  12173. function scissor( scissor ) {
  12174. if ( currentScissor.equals( scissor ) === false ) {
  12175. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  12176. currentScissor.copy( scissor );
  12177. }
  12178. }
  12179. function viewport( viewport ) {
  12180. if ( currentViewport.equals( viewport ) === false ) {
  12181. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  12182. currentViewport.copy( viewport );
  12183. }
  12184. }
  12185. //
  12186. function reset() {
  12187. enabledCapabilities = {};
  12188. currentTextureSlot = null;
  12189. currentBoundTextures = {};
  12190. currentProgram = null;
  12191. currentBlendingEnabled = null;
  12192. currentBlending = null;
  12193. currentBlendEquation = null;
  12194. currentBlendSrc = null;
  12195. currentBlendDst = null;
  12196. currentBlendEquationAlpha = null;
  12197. currentBlendSrcAlpha = null;
  12198. currentBlendDstAlpha = null;
  12199. currentPremultipledAlpha = false;
  12200. currentFlipSided = null;
  12201. currentCullFace = null;
  12202. currentLineWidth = null;
  12203. currentPolygonOffsetFactor = null;
  12204. currentPolygonOffsetUnits = null;
  12205. colorBuffer.reset();
  12206. depthBuffer.reset();
  12207. stencilBuffer.reset();
  12208. }
  12209. return {
  12210. buffers: {
  12211. color: colorBuffer,
  12212. depth: depthBuffer,
  12213. stencil: stencilBuffer
  12214. },
  12215. enable: enable,
  12216. disable: disable,
  12217. useProgram: useProgram,
  12218. setBlending: setBlending,
  12219. setMaterial: setMaterial,
  12220. setFlipSided: setFlipSided,
  12221. setCullFace: setCullFace,
  12222. setLineWidth: setLineWidth,
  12223. setPolygonOffset: setPolygonOffset,
  12224. setScissorTest: setScissorTest,
  12225. activeTexture: activeTexture,
  12226. bindTexture: bindTexture,
  12227. unbindTexture: unbindTexture,
  12228. compressedTexImage2D: compressedTexImage2D,
  12229. texImage2D: texImage2D,
  12230. texImage3D: texImage3D,
  12231. scissor: scissor,
  12232. viewport: viewport,
  12233. reset: reset
  12234. };
  12235. }
  12236. function WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info ) {
  12237. const isWebGL2 = capabilities.isWebGL2;
  12238. const maxTextures = capabilities.maxTextures;
  12239. const maxCubemapSize = capabilities.maxCubemapSize;
  12240. const maxTextureSize = capabilities.maxTextureSize;
  12241. const maxSamples = capabilities.maxSamples;
  12242. const _videoTextures = new WeakMap();
  12243. let _canvas;
  12244. // cordova iOS (as of 5.0) still uses UIWebView, which provides OffscreenCanvas,
  12245. // also OffscreenCanvas.getContext("webgl"), but not OffscreenCanvas.getContext("2d")!
  12246. // Some implementations may only implement OffscreenCanvas partially (e.g. lacking 2d).
  12247. let useOffscreenCanvas = false;
  12248. try {
  12249. useOffscreenCanvas = typeof OffscreenCanvas !== 'undefined'
  12250. && ( new OffscreenCanvas( 1, 1 ).getContext( '2d' ) ) !== null;
  12251. } catch ( err ) {
  12252. // Ignore any errors
  12253. }
  12254. function createCanvas( width, height ) {
  12255. // Use OffscreenCanvas when available. Specially needed in web workers
  12256. return useOffscreenCanvas ?
  12257. new OffscreenCanvas( width, height ) :
  12258. document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  12259. }
  12260. function resizeImage( image, needsPowerOfTwo, needsNewCanvas, maxSize ) {
  12261. let scale = 1;
  12262. // handle case if texture exceeds max size
  12263. if ( image.width > maxSize || image.height > maxSize ) {
  12264. scale = maxSize / Math.max( image.width, image.height );
  12265. }
  12266. // only perform resize if necessary
  12267. if ( scale < 1 || needsPowerOfTwo === true ) {
  12268. // only perform resize for certain image types
  12269. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  12270. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  12271. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  12272. const floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;
  12273. const width = floor( scale * image.width );
  12274. const height = floor( scale * image.height );
  12275. if ( _canvas === undefined ) _canvas = createCanvas( width, height );
  12276. // cube textures can't reuse the same canvas
  12277. const canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;
  12278. canvas.width = width;
  12279. canvas.height = height;
  12280. const context = canvas.getContext( '2d' );
  12281. context.drawImage( image, 0, 0, width, height );
  12282. console.warn( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );
  12283. return canvas;
  12284. } else {
  12285. if ( 'data' in image ) {
  12286. console.warn( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );
  12287. }
  12288. return image;
  12289. }
  12290. }
  12291. return image;
  12292. }
  12293. function isPowerOfTwo( image ) {
  12294. return MathUtils.isPowerOfTwo( image.width ) && MathUtils.isPowerOfTwo( image.height );
  12295. }
  12296. function textureNeedsPowerOfTwo( texture ) {
  12297. if ( isWebGL2 ) return false;
  12298. return ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) ||
  12299. ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter );
  12300. }
  12301. function textureNeedsGenerateMipmaps( texture, supportsMips ) {
  12302. return texture.generateMipmaps && supportsMips &&
  12303. texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
  12304. }
  12305. function generateMipmap( target, texture, width, height ) {
  12306. _gl.generateMipmap( target );
  12307. const textureProperties = properties.get( texture );
  12308. // Note: Math.log( x ) * Math.LOG2E used instead of Math.log2( x ) which is not supported by IE11
  12309. textureProperties.__maxMipLevel = Math.log( Math.max( width, height ) ) * Math.LOG2E;
  12310. }
  12311. function getInternalFormat( internalFormatName, glFormat, glType ) {
  12312. if ( isWebGL2 === false ) return glFormat;
  12313. if ( internalFormatName !== null ) {
  12314. if ( _gl[ internalFormatName ] !== undefined ) return _gl[ internalFormatName ];
  12315. console.warn( 'THREE.WebGLRenderer: Attempt to use non-existing WebGL internal format \'' + internalFormatName + '\'' );
  12316. }
  12317. let internalFormat = glFormat;
  12318. if ( glFormat === 6403 ) {
  12319. if ( glType === 5126 ) internalFormat = 33326;
  12320. if ( glType === 5131 ) internalFormat = 33325;
  12321. if ( glType === 5121 ) internalFormat = 33321;
  12322. }
  12323. if ( glFormat === 6407 ) {
  12324. if ( glType === 5126 ) internalFormat = 34837;
  12325. if ( glType === 5131 ) internalFormat = 34843;
  12326. if ( glType === 5121 ) internalFormat = 32849;
  12327. }
  12328. if ( glFormat === 6408 ) {
  12329. if ( glType === 5126 ) internalFormat = 34836;
  12330. if ( glType === 5131 ) internalFormat = 34842;
  12331. if ( glType === 5121 ) internalFormat = 32856;
  12332. }
  12333. if ( internalFormat === 33325 || internalFormat === 33326 ||
  12334. internalFormat === 34842 || internalFormat === 34836 ) {
  12335. extensions.get( 'EXT_color_buffer_float' );
  12336. }
  12337. return internalFormat;
  12338. }
  12339. // Fallback filters for non-power-of-2 textures
  12340. function filterFallback( f ) {
  12341. if ( f === NearestFilter || f === NearestMipmapNearestFilter || f === NearestMipmapLinearFilter ) {
  12342. return 9728;
  12343. }
  12344. return 9729;
  12345. }
  12346. //
  12347. function onTextureDispose( event ) {
  12348. const texture = event.target;
  12349. texture.removeEventListener( 'dispose', onTextureDispose );
  12350. deallocateTexture( texture );
  12351. if ( texture.isVideoTexture ) {
  12352. _videoTextures.delete( texture );
  12353. }
  12354. info.memory.textures --;
  12355. }
  12356. function onRenderTargetDispose( event ) {
  12357. const renderTarget = event.target;
  12358. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12359. deallocateRenderTarget( renderTarget );
  12360. info.memory.textures --;
  12361. }
  12362. //
  12363. function deallocateTexture( texture ) {
  12364. const textureProperties = properties.get( texture );
  12365. if ( textureProperties.__webglInit === undefined ) return;
  12366. _gl.deleteTexture( textureProperties.__webglTexture );
  12367. properties.remove( texture );
  12368. }
  12369. function deallocateRenderTarget( renderTarget ) {
  12370. const renderTargetProperties = properties.get( renderTarget );
  12371. const textureProperties = properties.get( renderTarget.texture );
  12372. if ( ! renderTarget ) return;
  12373. if ( textureProperties.__webglTexture !== undefined ) {
  12374. _gl.deleteTexture( textureProperties.__webglTexture );
  12375. }
  12376. if ( renderTarget.depthTexture ) {
  12377. renderTarget.depthTexture.dispose();
  12378. }
  12379. if ( renderTarget.isWebGLCubeRenderTarget ) {
  12380. for ( let i = 0; i < 6; i ++ ) {
  12381. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12382. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  12383. }
  12384. } else {
  12385. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12386. if ( renderTargetProperties.__webglDepthbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  12387. if ( renderTargetProperties.__webglMultisampledFramebuffer ) _gl.deleteFramebuffer( renderTargetProperties.__webglMultisampledFramebuffer );
  12388. if ( renderTargetProperties.__webglColorRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglColorRenderbuffer );
  12389. if ( renderTargetProperties.__webglDepthRenderbuffer ) _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthRenderbuffer );
  12390. }
  12391. properties.remove( renderTarget.texture );
  12392. properties.remove( renderTarget );
  12393. }
  12394. //
  12395. let textureUnits = 0;
  12396. function resetTextureUnits() {
  12397. textureUnits = 0;
  12398. }
  12399. function allocateTextureUnit() {
  12400. const textureUnit = textureUnits;
  12401. if ( textureUnit >= maxTextures ) {
  12402. console.warn( 'THREE.WebGLTextures: Trying to use ' + textureUnit + ' texture units while this GPU supports only ' + maxTextures );
  12403. }
  12404. textureUnits += 1;
  12405. return textureUnit;
  12406. }
  12407. //
  12408. function setTexture2D( texture, slot ) {
  12409. const textureProperties = properties.get( texture );
  12410. if ( texture.isVideoTexture ) updateVideoTexture( texture );
  12411. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12412. const image = texture.image;
  12413. if ( image === undefined ) {
  12414. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined' );
  12415. } else if ( image.complete === false ) {
  12416. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete' );
  12417. } else {
  12418. uploadTexture( textureProperties, texture, slot );
  12419. return;
  12420. }
  12421. }
  12422. state.activeTexture( 33984 + slot );
  12423. state.bindTexture( 3553, textureProperties.__webglTexture );
  12424. }
  12425. function setTexture2DArray( texture, slot ) {
  12426. const textureProperties = properties.get( texture );
  12427. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12428. uploadTexture( textureProperties, texture, slot );
  12429. return;
  12430. }
  12431. state.activeTexture( 33984 + slot );
  12432. state.bindTexture( 35866, textureProperties.__webglTexture );
  12433. }
  12434. function setTexture3D( texture, slot ) {
  12435. const textureProperties = properties.get( texture );
  12436. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12437. uploadTexture( textureProperties, texture, slot );
  12438. return;
  12439. }
  12440. state.activeTexture( 33984 + slot );
  12441. state.bindTexture( 32879, textureProperties.__webglTexture );
  12442. }
  12443. function setTextureCube( texture, slot ) {
  12444. const textureProperties = properties.get( texture );
  12445. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  12446. uploadCubeTexture( textureProperties, texture, slot );
  12447. return;
  12448. }
  12449. state.activeTexture( 33984 + slot );
  12450. state.bindTexture( 34067, textureProperties.__webglTexture );
  12451. }
  12452. const wrappingToGL = {
  12453. [ RepeatWrapping ]: 10497,
  12454. [ ClampToEdgeWrapping ]: 33071,
  12455. [ MirroredRepeatWrapping ]: 33648
  12456. };
  12457. const filterToGL = {
  12458. [ NearestFilter ]: 9728,
  12459. [ NearestMipmapNearestFilter ]: 9984,
  12460. [ NearestMipmapLinearFilter ]: 9986,
  12461. [ LinearFilter ]: 9729,
  12462. [ LinearMipmapNearestFilter ]: 9985,
  12463. [ LinearMipmapLinearFilter ]: 9987
  12464. };
  12465. function setTextureParameters( textureType, texture, supportsMips ) {
  12466. if ( supportsMips ) {
  12467. _gl.texParameteri( textureType, 10242, wrappingToGL[ texture.wrapS ] );
  12468. _gl.texParameteri( textureType, 10243, wrappingToGL[ texture.wrapT ] );
  12469. if ( textureType === 32879 || textureType === 35866 ) {
  12470. _gl.texParameteri( textureType, 32882, wrappingToGL[ texture.wrapR ] );
  12471. }
  12472. _gl.texParameteri( textureType, 10240, filterToGL[ texture.magFilter ] );
  12473. _gl.texParameteri( textureType, 10241, filterToGL[ texture.minFilter ] );
  12474. } else {
  12475. _gl.texParameteri( textureType, 10242, 33071 );
  12476. _gl.texParameteri( textureType, 10243, 33071 );
  12477. if ( textureType === 32879 || textureType === 35866 ) {
  12478. _gl.texParameteri( textureType, 32882, 33071 );
  12479. }
  12480. if ( texture.wrapS !== ClampToEdgeWrapping || texture.wrapT !== ClampToEdgeWrapping ) {
  12481. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.' );
  12482. }
  12483. _gl.texParameteri( textureType, 10240, filterFallback( texture.magFilter ) );
  12484. _gl.texParameteri( textureType, 10241, filterFallback( texture.minFilter ) );
  12485. if ( texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter ) {
  12486. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.' );
  12487. }
  12488. }
  12489. const extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12490. if ( extension ) {
  12491. if ( texture.type === FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  12492. if ( texture.type === HalfFloatType && ( isWebGL2 || extensions.get( 'OES_texture_half_float_linear' ) ) === null ) return;
  12493. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  12494. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, capabilities.getMaxAnisotropy() ) );
  12495. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  12496. }
  12497. }
  12498. }
  12499. function initTexture( textureProperties, texture ) {
  12500. if ( textureProperties.__webglInit === undefined ) {
  12501. textureProperties.__webglInit = true;
  12502. texture.addEventListener( 'dispose', onTextureDispose );
  12503. textureProperties.__webglTexture = _gl.createTexture();
  12504. info.memory.textures ++;
  12505. }
  12506. }
  12507. function uploadTexture( textureProperties, texture, slot ) {
  12508. let textureType = 3553;
  12509. if ( texture.isDataTexture2DArray ) textureType = 35866;
  12510. if ( texture.isDataTexture3D ) textureType = 32879;
  12511. initTexture( textureProperties, texture );
  12512. state.activeTexture( 33984 + slot );
  12513. state.bindTexture( textureType, textureProperties.__webglTexture );
  12514. _gl.pixelStorei( 37440, texture.flipY );
  12515. _gl.pixelStorei( 37441, texture.premultiplyAlpha );
  12516. _gl.pixelStorei( 3317, texture.unpackAlignment );
  12517. const needsPowerOfTwo = textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false;
  12518. const image = resizeImage( texture.image, needsPowerOfTwo, false, maxTextureSize );
  12519. const supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12520. glFormat = utils.convert( texture.format );
  12521. let glType = utils.convert( texture.type ),
  12522. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12523. setTextureParameters( textureType, texture, supportsMips );
  12524. let mipmap;
  12525. const mipmaps = texture.mipmaps;
  12526. if ( texture.isDepthTexture ) {
  12527. // populate depth texture with dummy data
  12528. glInternalFormat = 6402;
  12529. if ( isWebGL2 ) {
  12530. if ( texture.type === FloatType ) {
  12531. glInternalFormat = 36012;
  12532. } else if ( texture.type === UnsignedIntType ) {
  12533. glInternalFormat = 33190;
  12534. } else if ( texture.type === UnsignedInt248Type$1 ) {
  12535. glInternalFormat = 35056;
  12536. } else {
  12537. glInternalFormat = 33189; // WebGL2 requires sized internalformat for glTexImage2D
  12538. }
  12539. } else {
  12540. if ( texture.type === FloatType ) {
  12541. console.error( 'WebGLRenderer: Floating point depth texture requires WebGL2.' );
  12542. }
  12543. }
  12544. // validation checks for WebGL 1
  12545. if ( texture.format === DepthFormat && glInternalFormat === 6402 ) {
  12546. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12547. // DEPTH_COMPONENT and type is not UNSIGNED_SHORT or UNSIGNED_INT
  12548. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12549. if ( texture.type !== UnsignedShortType && texture.type !== UnsignedIntType ) {
  12550. console.warn( 'THREE.WebGLRenderer: Use UnsignedShortType or UnsignedIntType for DepthFormat DepthTexture.' );
  12551. texture.type = UnsignedShortType;
  12552. glType = utils.convert( texture.type );
  12553. }
  12554. }
  12555. if ( texture.format === DepthStencilFormat && glInternalFormat === 6402 ) {
  12556. // Depth stencil textures need the DEPTH_STENCIL internal format
  12557. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12558. glInternalFormat = 34041;
  12559. // The error INVALID_OPERATION is generated by texImage2D if format and internalformat are
  12560. // DEPTH_STENCIL and type is not UNSIGNED_INT_24_8_WEBGL.
  12561. // (https://www.khronos.org/registry/webgl/extensions/WEBGL_depth_texture/)
  12562. if ( texture.type !== UnsignedInt248Type$1 ) {
  12563. console.warn( 'THREE.WebGLRenderer: Use UnsignedInt248Type for DepthStencilFormat DepthTexture.' );
  12564. texture.type = UnsignedInt248Type$1;
  12565. glType = utils.convert( texture.type );
  12566. }
  12567. }
  12568. //
  12569. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null );
  12570. } else if ( texture.isDataTexture ) {
  12571. // use manually created mipmaps if available
  12572. // if there are no manual mipmaps
  12573. // set 0 level mipmap and then use GL to generate other mipmap levels
  12574. if ( mipmaps.length > 0 && supportsMips ) {
  12575. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12576. mipmap = mipmaps[ i ];
  12577. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12578. }
  12579. texture.generateMipmaps = false;
  12580. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12581. } else {
  12582. state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, image.data );
  12583. textureProperties.__maxMipLevel = 0;
  12584. }
  12585. } else if ( texture.isCompressedTexture ) {
  12586. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12587. mipmap = mipmaps[ i ];
  12588. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12589. if ( glFormat !== null ) {
  12590. state.compressedTexImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12591. } else {
  12592. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()' );
  12593. }
  12594. } else {
  12595. state.texImage2D( 3553, i, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12596. }
  12597. }
  12598. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12599. } else if ( texture.isDataTexture2DArray ) {
  12600. state.texImage3D( 35866, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12601. textureProperties.__maxMipLevel = 0;
  12602. } else if ( texture.isDataTexture3D ) {
  12603. state.texImage3D( 32879, 0, glInternalFormat, image.width, image.height, image.depth, 0, glFormat, glType, image.data );
  12604. textureProperties.__maxMipLevel = 0;
  12605. } else {
  12606. // regular Texture (image, video, canvas)
  12607. // use manually created mipmaps if available
  12608. // if there are no manual mipmaps
  12609. // set 0 level mipmap and then use GL to generate other mipmap levels
  12610. if ( mipmaps.length > 0 && supportsMips ) {
  12611. for ( let i = 0, il = mipmaps.length; i < il; i ++ ) {
  12612. mipmap = mipmaps[ i ];
  12613. state.texImage2D( 3553, i, glInternalFormat, glFormat, glType, mipmap );
  12614. }
  12615. texture.generateMipmaps = false;
  12616. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12617. } else {
  12618. state.texImage2D( 3553, 0, glInternalFormat, glFormat, glType, image );
  12619. textureProperties.__maxMipLevel = 0;
  12620. }
  12621. }
  12622. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12623. generateMipmap( textureType, texture, image.width, image.height );
  12624. }
  12625. textureProperties.__version = texture.version;
  12626. if ( texture.onUpdate ) texture.onUpdate( texture );
  12627. }
  12628. function uploadCubeTexture( textureProperties, texture, slot ) {
  12629. if ( texture.image.length !== 6 ) return;
  12630. initTexture( textureProperties, texture );
  12631. state.activeTexture( 33984 + slot );
  12632. state.bindTexture( 34067, textureProperties.__webglTexture );
  12633. _gl.pixelStorei( 37440, texture.flipY );
  12634. const isCompressed = ( texture && ( texture.isCompressedTexture || texture.image[ 0 ].isCompressedTexture ) );
  12635. const isDataTexture = ( texture.image[ 0 ] && texture.image[ 0 ].isDataTexture );
  12636. const cubeImage = [];
  12637. for ( let i = 0; i < 6; i ++ ) {
  12638. if ( ! isCompressed && ! isDataTexture ) {
  12639. cubeImage[ i ] = resizeImage( texture.image[ i ], false, true, maxCubemapSize );
  12640. } else {
  12641. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  12642. }
  12643. }
  12644. const image = cubeImage[ 0 ],
  12645. supportsMips = isPowerOfTwo( image ) || isWebGL2,
  12646. glFormat = utils.convert( texture.format ),
  12647. glType = utils.convert( texture.type ),
  12648. glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType );
  12649. setTextureParameters( 34067, texture, supportsMips );
  12650. let mipmaps;
  12651. if ( isCompressed ) {
  12652. for ( let i = 0; i < 6; i ++ ) {
  12653. mipmaps = cubeImage[ i ].mipmaps;
  12654. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12655. const mipmap = mipmaps[ j ];
  12656. if ( texture.format !== RGBAFormat && texture.format !== RGBFormat ) {
  12657. if ( glFormat !== null ) {
  12658. state.compressedTexImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  12659. } else {
  12660. console.warn( 'THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setTextureCube()' );
  12661. }
  12662. } else {
  12663. state.texImage2D( 34069 + i, j, glInternalFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  12664. }
  12665. }
  12666. }
  12667. textureProperties.__maxMipLevel = mipmaps.length - 1;
  12668. } else {
  12669. mipmaps = texture.mipmaps;
  12670. for ( let i = 0; i < 6; i ++ ) {
  12671. if ( isDataTexture ) {
  12672. state.texImage2D( 34069 + i, 0, glInternalFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  12673. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12674. const mipmap = mipmaps[ j ];
  12675. const mipmapImage = mipmap.image[ i ].image;
  12676. state.texImage2D( 34069 + i, j + 1, glInternalFormat, mipmapImage.width, mipmapImage.height, 0, glFormat, glType, mipmapImage.data );
  12677. }
  12678. } else {
  12679. state.texImage2D( 34069 + i, 0, glInternalFormat, glFormat, glType, cubeImage[ i ] );
  12680. for ( let j = 0; j < mipmaps.length; j ++ ) {
  12681. const mipmap = mipmaps[ j ];
  12682. state.texImage2D( 34069 + i, j + 1, glInternalFormat, glFormat, glType, mipmap.image[ i ] );
  12683. }
  12684. }
  12685. }
  12686. textureProperties.__maxMipLevel = mipmaps.length;
  12687. }
  12688. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12689. // We assume images for cube map have the same size.
  12690. generateMipmap( 34067, texture, image.width, image.height );
  12691. }
  12692. textureProperties.__version = texture.version;
  12693. if ( texture.onUpdate ) texture.onUpdate( texture );
  12694. }
  12695. // Render targets
  12696. // Setup storage for target texture and bind it to correct framebuffer
  12697. function setupFrameBufferTexture( framebuffer, renderTarget, attachment, textureTarget ) {
  12698. const glFormat = utils.convert( renderTarget.texture.format );
  12699. const glType = utils.convert( renderTarget.texture.type );
  12700. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  12701. state.texImage2D( textureTarget, 0, glInternalFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  12702. _gl.bindFramebuffer( 36160, framebuffer );
  12703. _gl.framebufferTexture2D( 36160, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  12704. _gl.bindFramebuffer( 36160, null );
  12705. }
  12706. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  12707. function setupRenderBufferStorage( renderbuffer, renderTarget, isMultisample ) {
  12708. _gl.bindRenderbuffer( 36161, renderbuffer );
  12709. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  12710. let glInternalFormat = 33189;
  12711. if ( isMultisample ) {
  12712. const depthTexture = renderTarget.depthTexture;
  12713. if ( depthTexture && depthTexture.isDepthTexture ) {
  12714. if ( depthTexture.type === FloatType ) {
  12715. glInternalFormat = 36012;
  12716. } else if ( depthTexture.type === UnsignedIntType ) {
  12717. glInternalFormat = 33190;
  12718. }
  12719. }
  12720. const samples = getRenderTargetSamples( renderTarget );
  12721. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12722. } else {
  12723. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12724. }
  12725. _gl.framebufferRenderbuffer( 36160, 36096, 36161, renderbuffer );
  12726. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  12727. if ( isMultisample ) {
  12728. const samples = getRenderTargetSamples( renderTarget );
  12729. _gl.renderbufferStorageMultisample( 36161, samples, 35056, renderTarget.width, renderTarget.height );
  12730. } else {
  12731. _gl.renderbufferStorage( 36161, 34041, renderTarget.width, renderTarget.height );
  12732. }
  12733. _gl.framebufferRenderbuffer( 36160, 33306, 36161, renderbuffer );
  12734. } else {
  12735. const glFormat = utils.convert( renderTarget.texture.format );
  12736. const glType = utils.convert( renderTarget.texture.type );
  12737. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  12738. if ( isMultisample ) {
  12739. const samples = getRenderTargetSamples( renderTarget );
  12740. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12741. } else {
  12742. _gl.renderbufferStorage( 36161, glInternalFormat, renderTarget.width, renderTarget.height );
  12743. }
  12744. }
  12745. _gl.bindRenderbuffer( 36161, null );
  12746. }
  12747. // Setup resources for a Depth Texture for a FBO (needs an extension)
  12748. function setupDepthTexture( framebuffer, renderTarget ) {
  12749. const isCube = ( renderTarget && renderTarget.isWebGLCubeRenderTarget );
  12750. if ( isCube ) throw new Error( 'Depth Texture with cube render targets is not supported' );
  12751. _gl.bindFramebuffer( 36160, framebuffer );
  12752. if ( ! ( renderTarget.depthTexture && renderTarget.depthTexture.isDepthTexture ) ) {
  12753. throw new Error( 'renderTarget.depthTexture must be an instance of THREE.DepthTexture' );
  12754. }
  12755. // upload an empty depth texture with framebuffer size
  12756. if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
  12757. renderTarget.depthTexture.image.width !== renderTarget.width ||
  12758. renderTarget.depthTexture.image.height !== renderTarget.height ) {
  12759. renderTarget.depthTexture.image.width = renderTarget.width;
  12760. renderTarget.depthTexture.image.height = renderTarget.height;
  12761. renderTarget.depthTexture.needsUpdate = true;
  12762. }
  12763. setTexture2D( renderTarget.depthTexture, 0 );
  12764. const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
  12765. if ( renderTarget.depthTexture.format === DepthFormat ) {
  12766. _gl.framebufferTexture2D( 36160, 36096, 3553, webglDepthTexture, 0 );
  12767. } else if ( renderTarget.depthTexture.format === DepthStencilFormat ) {
  12768. _gl.framebufferTexture2D( 36160, 33306, 3553, webglDepthTexture, 0 );
  12769. } else {
  12770. throw new Error( 'Unknown depthTexture format' );
  12771. }
  12772. }
  12773. // Setup GL resources for a non-texture depth buffer
  12774. function setupDepthRenderbuffer( renderTarget ) {
  12775. const renderTargetProperties = properties.get( renderTarget );
  12776. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  12777. if ( renderTarget.depthTexture ) {
  12778. if ( isCube ) throw new Error( 'target.depthTexture not supported in Cube render targets' );
  12779. setupDepthTexture( renderTargetProperties.__webglFramebuffer, renderTarget );
  12780. } else {
  12781. if ( isCube ) {
  12782. renderTargetProperties.__webglDepthbuffer = [];
  12783. for ( let i = 0; i < 6; i ++ ) {
  12784. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer[ i ] );
  12785. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  12786. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget, false );
  12787. }
  12788. } else {
  12789. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglFramebuffer );
  12790. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  12791. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget, false );
  12792. }
  12793. }
  12794. _gl.bindFramebuffer( 36160, null );
  12795. }
  12796. // Set up GL resources for the render target
  12797. function setupRenderTarget( renderTarget ) {
  12798. const renderTargetProperties = properties.get( renderTarget );
  12799. const textureProperties = properties.get( renderTarget.texture );
  12800. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  12801. textureProperties.__webglTexture = _gl.createTexture();
  12802. info.memory.textures ++;
  12803. const isCube = ( renderTarget.isWebGLCubeRenderTarget === true );
  12804. const isMultisample = ( renderTarget.isWebGLMultisampleRenderTarget === true );
  12805. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  12806. // Handles WebGL2 RGBFormat fallback - #18858
  12807. if ( isWebGL2 && renderTarget.texture.format === RGBFormat && ( renderTarget.texture.type === FloatType || renderTarget.texture.type === HalfFloatType ) ) {
  12808. renderTarget.texture.format = RGBAFormat;
  12809. console.warn( 'THREE.WebGLRenderer: Rendering to textures with RGB format is not supported. Using RGBA format instead.' );
  12810. }
  12811. // Setup framebuffer
  12812. if ( isCube ) {
  12813. renderTargetProperties.__webglFramebuffer = [];
  12814. for ( let i = 0; i < 6; i ++ ) {
  12815. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  12816. }
  12817. } else {
  12818. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  12819. if ( isMultisample ) {
  12820. if ( isWebGL2 ) {
  12821. renderTargetProperties.__webglMultisampledFramebuffer = _gl.createFramebuffer();
  12822. renderTargetProperties.__webglColorRenderbuffer = _gl.createRenderbuffer();
  12823. _gl.bindRenderbuffer( 36161, renderTargetProperties.__webglColorRenderbuffer );
  12824. const glFormat = utils.convert( renderTarget.texture.format );
  12825. const glType = utils.convert( renderTarget.texture.type );
  12826. const glInternalFormat = getInternalFormat( renderTarget.texture.internalFormat, glFormat, glType );
  12827. const samples = getRenderTargetSamples( renderTarget );
  12828. _gl.renderbufferStorageMultisample( 36161, samples, glInternalFormat, renderTarget.width, renderTarget.height );
  12829. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer );
  12830. _gl.framebufferRenderbuffer( 36160, 36064, 36161, renderTargetProperties.__webglColorRenderbuffer );
  12831. _gl.bindRenderbuffer( 36161, null );
  12832. if ( renderTarget.depthBuffer ) {
  12833. renderTargetProperties.__webglDepthRenderbuffer = _gl.createRenderbuffer();
  12834. setupRenderBufferStorage( renderTargetProperties.__webglDepthRenderbuffer, renderTarget, true );
  12835. }
  12836. _gl.bindFramebuffer( 36160, null );
  12837. } else {
  12838. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12839. }
  12840. }
  12841. }
  12842. // Setup color buffer
  12843. if ( isCube ) {
  12844. state.bindTexture( 34067, textureProperties.__webglTexture );
  12845. setTextureParameters( 34067, renderTarget.texture, supportsMips );
  12846. for ( let i = 0; i < 6; i ++ ) {
  12847. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, 36064, 34069 + i );
  12848. }
  12849. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12850. generateMipmap( 34067, renderTarget.texture, renderTarget.width, renderTarget.height );
  12851. }
  12852. state.bindTexture( 34067, null );
  12853. } else {
  12854. state.bindTexture( 3553, textureProperties.__webglTexture );
  12855. setTextureParameters( 3553, renderTarget.texture, supportsMips );
  12856. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, 36064, 3553 );
  12857. if ( textureNeedsGenerateMipmaps( renderTarget.texture, supportsMips ) ) {
  12858. generateMipmap( 3553, renderTarget.texture, renderTarget.width, renderTarget.height );
  12859. }
  12860. state.bindTexture( 3553, null );
  12861. }
  12862. // Setup depth and stencil buffers
  12863. if ( renderTarget.depthBuffer ) {
  12864. setupDepthRenderbuffer( renderTarget );
  12865. }
  12866. }
  12867. function updateRenderTargetMipmap( renderTarget ) {
  12868. const texture = renderTarget.texture;
  12869. const supportsMips = isPowerOfTwo( renderTarget ) || isWebGL2;
  12870. if ( textureNeedsGenerateMipmaps( texture, supportsMips ) ) {
  12871. const target = renderTarget.isWebGLCubeRenderTarget ? 34067 : 3553;
  12872. const webglTexture = properties.get( texture ).__webglTexture;
  12873. state.bindTexture( target, webglTexture );
  12874. generateMipmap( target, texture, renderTarget.width, renderTarget.height );
  12875. state.bindTexture( target, null );
  12876. }
  12877. }
  12878. function updateMultisampleRenderTarget( renderTarget ) {
  12879. if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  12880. if ( isWebGL2 ) {
  12881. const renderTargetProperties = properties.get( renderTarget );
  12882. _gl.bindFramebuffer( 36008, renderTargetProperties.__webglMultisampledFramebuffer );
  12883. _gl.bindFramebuffer( 36009, renderTargetProperties.__webglFramebuffer );
  12884. const width = renderTarget.width;
  12885. const height = renderTarget.height;
  12886. let mask = 16384;
  12887. if ( renderTarget.depthBuffer ) mask |= 256;
  12888. if ( renderTarget.stencilBuffer ) mask |= 1024;
  12889. _gl.blitFramebuffer( 0, 0, width, height, 0, 0, width, height, mask, 9728 );
  12890. _gl.bindFramebuffer( 36160, renderTargetProperties.__webglMultisampledFramebuffer ); // see #18905
  12891. } else {
  12892. console.warn( 'THREE.WebGLRenderer: WebGLMultisampleRenderTarget can only be used with WebGL2.' );
  12893. }
  12894. }
  12895. }
  12896. function getRenderTargetSamples( renderTarget ) {
  12897. return ( isWebGL2 && renderTarget.isWebGLMultisampleRenderTarget ) ?
  12898. Math.min( maxSamples, renderTarget.samples ) : 0;
  12899. }
  12900. function updateVideoTexture( texture ) {
  12901. const frame = info.render.frame;
  12902. // Check the last frame we updated the VideoTexture
  12903. if ( _videoTextures.get( texture ) !== frame ) {
  12904. _videoTextures.set( texture, frame );
  12905. texture.update();
  12906. }
  12907. }
  12908. // backwards compatibility
  12909. let warnedTexture2D = false;
  12910. let warnedTextureCube = false;
  12911. function safeSetTexture2D( texture, slot ) {
  12912. if ( texture && texture.isWebGLRenderTarget ) {
  12913. if ( warnedTexture2D === false ) {
  12914. console.warn( 'THREE.WebGLTextures.safeSetTexture2D: don\'t use render targets as textures. Use their .texture property instead.' );
  12915. warnedTexture2D = true;
  12916. }
  12917. texture = texture.texture;
  12918. }
  12919. setTexture2D( texture, slot );
  12920. }
  12921. function safeSetTextureCube( texture, slot ) {
  12922. if ( texture && texture.isWebGLCubeRenderTarget ) {
  12923. if ( warnedTextureCube === false ) {
  12924. console.warn( 'THREE.WebGLTextures.safeSetTextureCube: don\'t use cube render targets as textures. Use their .texture property instead.' );
  12925. warnedTextureCube = true;
  12926. }
  12927. texture = texture.texture;
  12928. }
  12929. setTextureCube( texture, slot );
  12930. }
  12931. //
  12932. this.allocateTextureUnit = allocateTextureUnit;
  12933. this.resetTextureUnits = resetTextureUnits;
  12934. this.setTexture2D = setTexture2D;
  12935. this.setTexture2DArray = setTexture2DArray;
  12936. this.setTexture3D = setTexture3D;
  12937. this.setTextureCube = setTextureCube;
  12938. this.setupRenderTarget = setupRenderTarget;
  12939. this.updateRenderTargetMipmap = updateRenderTargetMipmap;
  12940. this.updateMultisampleRenderTarget = updateMultisampleRenderTarget;
  12941. this.safeSetTexture2D = safeSetTexture2D;
  12942. this.safeSetTextureCube = safeSetTextureCube;
  12943. }
  12944. function WebGLUtils( gl, extensions, capabilities ) {
  12945. const isWebGL2 = capabilities.isWebGL2;
  12946. function convert( p ) {
  12947. let extension;
  12948. if ( p === UnsignedByteType ) return 5121;
  12949. if ( p === UnsignedShort4444Type ) return 32819;
  12950. if ( p === UnsignedShort5551Type ) return 32820;
  12951. if ( p === UnsignedShort565Type ) return 33635;
  12952. if ( p === ByteType ) return 5120;
  12953. if ( p === ShortType ) return 5122;
  12954. if ( p === UnsignedShortType ) return 5123;
  12955. if ( p === IntType ) return 5124;
  12956. if ( p === UnsignedIntType ) return 5125;
  12957. if ( p === FloatType ) return 5126;
  12958. if ( p === HalfFloatType ) {
  12959. if ( isWebGL2 ) return 5131;
  12960. extension = extensions.get( 'OES_texture_half_float' );
  12961. if ( extension !== null ) {
  12962. return extension.HALF_FLOAT_OES;
  12963. } else {
  12964. return null;
  12965. }
  12966. }
  12967. if ( p === AlphaFormat ) return 6406;
  12968. if ( p === RGBFormat ) return 6407;
  12969. if ( p === RGBAFormat ) return 6408;
  12970. if ( p === LuminanceFormat ) return 6409;
  12971. if ( p === LuminanceAlphaFormat ) return 6410;
  12972. if ( p === DepthFormat ) return 6402;
  12973. if ( p === DepthStencilFormat ) return 34041;
  12974. if ( p === RedFormat ) return 6403;
  12975. // WebGL2 formats.
  12976. if ( p === RedIntegerFormat ) return 36244;
  12977. if ( p === RGFormat ) return 33319;
  12978. if ( p === RGIntegerFormat ) return 33320;
  12979. if ( p === RGBIntegerFormat ) return 36248;
  12980. if ( p === RGBAIntegerFormat ) return 36249;
  12981. if ( p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format$1 ||
  12982. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format$1 ) {
  12983. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  12984. if ( extension !== null ) {
  12985. if ( p === RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  12986. if ( p === RGBA_S3TC_DXT1_Format$1 ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  12987. if ( p === RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  12988. if ( p === RGBA_S3TC_DXT5_Format$1 ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  12989. } else {
  12990. return null;
  12991. }
  12992. }
  12993. if ( p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  12994. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format ) {
  12995. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  12996. if ( extension !== null ) {
  12997. if ( p === RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  12998. if ( p === RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  12999. if ( p === RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13000. if ( p === RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13001. } else {
  13002. return null;
  13003. }
  13004. }
  13005. if ( p === RGB_ETC1_Format ) {
  13006. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  13007. if ( extension !== null ) {
  13008. return extension.COMPRESSED_RGB_ETC1_WEBGL;
  13009. } else {
  13010. return null;
  13011. }
  13012. }
  13013. if ( p === RGB_ETC2_Format || p === RGBA_ETC2_EAC_Format ) {
  13014. extension = extensions.get( 'WEBGL_compressed_texture_etc' );
  13015. if ( extension !== null ) {
  13016. if ( p === RGB_ETC2_Format ) return extension.COMPRESSED_RGB8_ETC2;
  13017. if ( p === RGBA_ETC2_EAC_Format ) return extension.COMPRESSED_RGBA8_ETC2_EAC;
  13018. }
  13019. }
  13020. if ( p === RGBA_ASTC_4x4_Format || p === RGBA_ASTC_5x4_Format || p === RGBA_ASTC_5x5_Format ||
  13021. p === RGBA_ASTC_6x5_Format || p === RGBA_ASTC_6x6_Format || p === RGBA_ASTC_8x5_Format ||
  13022. p === RGBA_ASTC_8x6_Format || p === RGBA_ASTC_8x8_Format || p === RGBA_ASTC_10x5_Format ||
  13023. p === RGBA_ASTC_10x6_Format || p === RGBA_ASTC_10x8_Format || p === RGBA_ASTC_10x10_Format ||
  13024. p === RGBA_ASTC_12x10_Format || p === RGBA_ASTC_12x12_Format ||
  13025. p === SRGB8_ALPHA8_ASTC_4x4_Format || p === SRGB8_ALPHA8_ASTC_5x4_Format || p === SRGB8_ALPHA8_ASTC_5x5_Format ||
  13026. p === SRGB8_ALPHA8_ASTC_6x5_Format || p === SRGB8_ALPHA8_ASTC_6x6_Format || p === SRGB8_ALPHA8_ASTC_8x5_Format ||
  13027. p === SRGB8_ALPHA8_ASTC_8x6_Format || p === SRGB8_ALPHA8_ASTC_8x8_Format || p === SRGB8_ALPHA8_ASTC_10x5_Format ||
  13028. p === SRGB8_ALPHA8_ASTC_10x6_Format || p === SRGB8_ALPHA8_ASTC_10x8_Format || p === SRGB8_ALPHA8_ASTC_10x10_Format ||
  13029. p === SRGB8_ALPHA8_ASTC_12x10_Format || p === SRGB8_ALPHA8_ASTC_12x12_Format ) {
  13030. extension = extensions.get( 'WEBGL_compressed_texture_astc' );
  13031. if ( extension !== null ) {
  13032. // TODO Complete?
  13033. return p;
  13034. } else {
  13035. return null;
  13036. }
  13037. }
  13038. if ( p === RGBA_BPTC_Format ) {
  13039. extension = extensions.get( 'EXT_texture_compression_bptc' );
  13040. if ( extension !== null ) {
  13041. // TODO Complete?
  13042. return p;
  13043. } else {
  13044. return null;
  13045. }
  13046. }
  13047. if ( p === UnsignedInt248Type$1 ) {
  13048. if ( isWebGL2 ) return 34042;
  13049. extension = extensions.get( 'WEBGL_depth_texture' );
  13050. if ( extension !== null ) {
  13051. return extension.UNSIGNED_INT_24_8_WEBGL;
  13052. } else {
  13053. return null;
  13054. }
  13055. }
  13056. }
  13057. return { convert: convert };
  13058. }
  13059. function ArrayCamera( array = [] ) {
  13060. PerspectiveCamera.call( this );
  13061. this.cameras = array;
  13062. }
  13063. ArrayCamera.prototype = Object.assign( Object.create( PerspectiveCamera.prototype ), {
  13064. constructor: ArrayCamera,
  13065. isArrayCamera: true
  13066. } );
  13067. function Group() {
  13068. Object3D.call( this );
  13069. this.type = 'Group';
  13070. }
  13071. Group.prototype = Object.assign( Object.create( Object3D.prototype ), {
  13072. constructor: Group,
  13073. isGroup: true
  13074. } );
  13075. function WebXRController() {
  13076. this._targetRay = null;
  13077. this._grip = null;
  13078. this._hand = null;
  13079. }
  13080. Object.assign( WebXRController.prototype, {
  13081. constructor: WebXRController,
  13082. getHandSpace: function () {
  13083. if ( this._hand === null ) {
  13084. this._hand = new Group();
  13085. this._hand.matrixAutoUpdate = false;
  13086. this._hand.visible = false;
  13087. this._hand.joints = [];
  13088. this._hand.inputState = { pinching: false };
  13089. if ( window.XRHand ) {
  13090. for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
  13091. // The transform of this joint will be updated with the joint pose on each frame
  13092. const joint = new Group();
  13093. joint.matrixAutoUpdate = false;
  13094. joint.visible = false;
  13095. this._hand.joints.push( joint );
  13096. // ??
  13097. this._hand.add( joint );
  13098. }
  13099. }
  13100. }
  13101. return this._hand;
  13102. },
  13103. getTargetRaySpace: function () {
  13104. if ( this._targetRay === null ) {
  13105. this._targetRay = new Group();
  13106. this._targetRay.matrixAutoUpdate = false;
  13107. this._targetRay.visible = false;
  13108. }
  13109. return this._targetRay;
  13110. },
  13111. getGripSpace: function () {
  13112. if ( this._grip === null ) {
  13113. this._grip = new Group();
  13114. this._grip.matrixAutoUpdate = false;
  13115. this._grip.visible = false;
  13116. }
  13117. return this._grip;
  13118. },
  13119. dispatchEvent: function ( event ) {
  13120. if ( this._targetRay !== null ) {
  13121. this._targetRay.dispatchEvent( event );
  13122. }
  13123. if ( this._grip !== null ) {
  13124. this._grip.dispatchEvent( event );
  13125. }
  13126. if ( this._hand !== null ) {
  13127. this._hand.dispatchEvent( event );
  13128. }
  13129. return this;
  13130. },
  13131. disconnect: function ( inputSource ) {
  13132. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13133. if ( this._targetRay !== null ) {
  13134. this._targetRay.visible = false;
  13135. }
  13136. if ( this._grip !== null ) {
  13137. this._grip.visible = false;
  13138. }
  13139. if ( this._hand !== null ) {
  13140. this._hand.visible = false;
  13141. }
  13142. return this;
  13143. },
  13144. update: function ( inputSource, frame, referenceSpace ) {
  13145. let inputPose = null;
  13146. let gripPose = null;
  13147. let handPose = null;
  13148. const targetRay = this._targetRay;
  13149. const grip = this._grip;
  13150. const hand = this._hand;
  13151. if ( inputSource && frame.session.visibilityState !== 'visible-blurred' ) {
  13152. if ( hand && inputSource.hand ) {
  13153. handPose = true;
  13154. for ( let i = 0; i <= window.XRHand.LITTLE_PHALANX_TIP; i ++ ) {
  13155. if ( inputSource.hand[ i ] ) {
  13156. // Update the joints groups with the XRJoint poses
  13157. const jointPose = frame.getJointPose( inputSource.hand[ i ], referenceSpace );
  13158. const joint = hand.joints[ i ];
  13159. if ( jointPose !== null ) {
  13160. joint.matrix.fromArray( jointPose.transform.matrix );
  13161. joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
  13162. joint.jointRadius = jointPose.radius;
  13163. }
  13164. joint.visible = jointPose !== null;
  13165. // Custom events
  13166. // Check pinch
  13167. const indexTip = hand.joints[ window.XRHand.INDEX_PHALANX_TIP ];
  13168. const thumbTip = hand.joints[ window.XRHand.THUMB_PHALANX_TIP ];
  13169. const distance = indexTip.position.distanceTo( thumbTip.position );
  13170. const distanceToPinch = 0.02;
  13171. const threshold = 0.005;
  13172. if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
  13173. hand.inputState.pinching = false;
  13174. this.dispatchEvent( {
  13175. type: 'pinchend',
  13176. handedness: inputSource.handedness,
  13177. target: this
  13178. } );
  13179. } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
  13180. hand.inputState.pinching = true;
  13181. this.dispatchEvent( {
  13182. type: 'pinchstart',
  13183. handedness: inputSource.handedness,
  13184. target: this
  13185. } );
  13186. }
  13187. }
  13188. }
  13189. } else {
  13190. if ( targetRay !== null ) {
  13191. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  13192. if ( inputPose !== null ) {
  13193. targetRay.matrix.fromArray( inputPose.transform.matrix );
  13194. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  13195. }
  13196. }
  13197. if ( grip !== null && inputSource.gripSpace ) {
  13198. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  13199. if ( gripPose !== null ) {
  13200. grip.matrix.fromArray( gripPose.transform.matrix );
  13201. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  13202. }
  13203. }
  13204. }
  13205. }
  13206. if ( targetRay !== null ) {
  13207. targetRay.visible = ( inputPose !== null );
  13208. }
  13209. if ( grip !== null ) {
  13210. grip.visible = ( gripPose !== null );
  13211. }
  13212. if ( hand !== null ) {
  13213. hand.visible = ( handPose !== null );
  13214. }
  13215. return this;
  13216. }
  13217. } );
  13218. function WebXRManager( renderer, gl ) {
  13219. const scope = this;
  13220. let session = null;
  13221. let framebufferScaleFactor = 1.0;
  13222. let referenceSpace = null;
  13223. let referenceSpaceType = 'local-floor';
  13224. let pose = null;
  13225. const controllers = [];
  13226. const inputSourcesMap = new Map();
  13227. //
  13228. const cameraL = new PerspectiveCamera();
  13229. cameraL.layers.enable( 1 );
  13230. cameraL.viewport = new Vector4();
  13231. const cameraR = new PerspectiveCamera();
  13232. cameraR.layers.enable( 2 );
  13233. cameraR.viewport = new Vector4();
  13234. const cameras = [ cameraL, cameraR ];
  13235. const cameraVR = new ArrayCamera();
  13236. cameraVR.layers.enable( 1 );
  13237. cameraVR.layers.enable( 2 );
  13238. let _currentDepthNear = null;
  13239. let _currentDepthFar = null;
  13240. //
  13241. this.enabled = false;
  13242. this.isPresenting = false;
  13243. this.getController = function ( index ) {
  13244. let controller = controllers[ index ];
  13245. if ( controller === undefined ) {
  13246. controller = new WebXRController();
  13247. controllers[ index ] = controller;
  13248. }
  13249. return controller.getTargetRaySpace();
  13250. };
  13251. this.getControllerGrip = function ( index ) {
  13252. let controller = controllers[ index ];
  13253. if ( controller === undefined ) {
  13254. controller = new WebXRController();
  13255. controllers[ index ] = controller;
  13256. }
  13257. return controller.getGripSpace();
  13258. };
  13259. this.getHand = function ( index ) {
  13260. let controller = controllers[ index ];
  13261. if ( controller === undefined ) {
  13262. controller = new WebXRController();
  13263. controllers[ index ] = controller;
  13264. }
  13265. return controller.getHandSpace();
  13266. };
  13267. //
  13268. function onSessionEvent( event ) {
  13269. const controller = inputSourcesMap.get( event.inputSource );
  13270. if ( controller ) {
  13271. controller.dispatchEvent( { type: event.type, data: event.inputSource } );
  13272. }
  13273. }
  13274. function onSessionEnd() {
  13275. inputSourcesMap.forEach( function ( controller, inputSource ) {
  13276. controller.disconnect( inputSource );
  13277. } );
  13278. inputSourcesMap.clear();
  13279. //
  13280. renderer.setFramebuffer( null );
  13281. renderer.setRenderTarget( renderer.getRenderTarget() ); // Hack #15830
  13282. animation.stop();
  13283. scope.isPresenting = false;
  13284. scope.dispatchEvent( { type: 'sessionend' } );
  13285. }
  13286. function onRequestReferenceSpace( value ) {
  13287. referenceSpace = value;
  13288. animation.setContext( session );
  13289. animation.start();
  13290. scope.isPresenting = true;
  13291. scope.dispatchEvent( { type: 'sessionstart' } );
  13292. }
  13293. this.setFramebufferScaleFactor = function ( value ) {
  13294. framebufferScaleFactor = value;
  13295. if ( scope.isPresenting === true ) {
  13296. console.warn( 'THREE.WebXRManager: Cannot change framebuffer scale while presenting.' );
  13297. }
  13298. };
  13299. this.setReferenceSpaceType = function ( value ) {
  13300. referenceSpaceType = value;
  13301. if ( scope.isPresenting === true ) {
  13302. console.warn( 'THREE.WebXRManager: Cannot change reference space type while presenting.' );
  13303. }
  13304. };
  13305. this.getReferenceSpace = function () {
  13306. return referenceSpace;
  13307. };
  13308. this.getSession = function () {
  13309. return session;
  13310. };
  13311. this.setSession = function ( value ) {
  13312. session = value;
  13313. if ( session !== null ) {
  13314. session.addEventListener( 'select', onSessionEvent );
  13315. session.addEventListener( 'selectstart', onSessionEvent );
  13316. session.addEventListener( 'selectend', onSessionEvent );
  13317. session.addEventListener( 'squeeze', onSessionEvent );
  13318. session.addEventListener( 'squeezestart', onSessionEvent );
  13319. session.addEventListener( 'squeezeend', onSessionEvent );
  13320. session.addEventListener( 'end', onSessionEnd );
  13321. const attributes = gl.getContextAttributes();
  13322. if ( attributes.xrCompatible !== true ) {
  13323. gl.makeXRCompatible();
  13324. }
  13325. const layerInit = {
  13326. antialias: attributes.antialias,
  13327. alpha: attributes.alpha,
  13328. depth: attributes.depth,
  13329. stencil: attributes.stencil,
  13330. framebufferScaleFactor: framebufferScaleFactor
  13331. };
  13332. // eslint-disable-next-line no-undef
  13333. const baseLayer = new XRWebGLLayer( session, gl, layerInit );
  13334. session.updateRenderState( { baseLayer: baseLayer } );
  13335. session.requestReferenceSpace( referenceSpaceType ).then( onRequestReferenceSpace );
  13336. //
  13337. session.addEventListener( 'inputsourceschange', updateInputSources );
  13338. }
  13339. };
  13340. function updateInputSources( event ) {
  13341. const inputSources = session.inputSources;
  13342. // Assign inputSources to available controllers
  13343. for ( let i = 0; i < controllers.length; i ++ ) {
  13344. inputSourcesMap.set( inputSources[ i ], controllers[ i ] );
  13345. }
  13346. // Notify disconnected
  13347. for ( let i = 0; i < event.removed.length; i ++ ) {
  13348. const inputSource = event.removed[ i ];
  13349. const controller = inputSourcesMap.get( inputSource );
  13350. if ( controller ) {
  13351. controller.dispatchEvent( { type: 'disconnected', data: inputSource } );
  13352. inputSourcesMap.delete( inputSource );
  13353. }
  13354. }
  13355. // Notify connected
  13356. for ( let i = 0; i < event.added.length; i ++ ) {
  13357. const inputSource = event.added[ i ];
  13358. const controller = inputSourcesMap.get( inputSource );
  13359. if ( controller ) {
  13360. controller.dispatchEvent( { type: 'connected', data: inputSource } );
  13361. }
  13362. }
  13363. }
  13364. //
  13365. const cameraLPos = new Vector3();
  13366. const cameraRPos = new Vector3();
  13367. /**
  13368. * Assumes 2 cameras that are parallel and share an X-axis, and that
  13369. * the cameras' projection and world matrices have already been set.
  13370. * And that near and far planes are identical for both cameras.
  13371. * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
  13372. */
  13373. function setProjectionFromUnion( camera, cameraL, cameraR ) {
  13374. cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
  13375. cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
  13376. const ipd = cameraLPos.distanceTo( cameraRPos );
  13377. const projL = cameraL.projectionMatrix.elements;
  13378. const projR = cameraR.projectionMatrix.elements;
  13379. // VR systems will have identical far and near planes, and
  13380. // most likely identical top and bottom frustum extents.
  13381. // Use the left camera for these values.
  13382. const near = projL[ 14 ] / ( projL[ 10 ] - 1 );
  13383. const far = projL[ 14 ] / ( projL[ 10 ] + 1 );
  13384. const topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
  13385. const bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
  13386. const leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
  13387. const rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
  13388. const left = near * leftFov;
  13389. const right = near * rightFov;
  13390. // Calculate the new camera's position offset from the
  13391. // left camera. xOffset should be roughly half `ipd`.
  13392. const zOffset = ipd / ( - leftFov + rightFov );
  13393. const xOffset = zOffset * - leftFov;
  13394. // TODO: Better way to apply this offset?
  13395. cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
  13396. camera.translateX( xOffset );
  13397. camera.translateZ( zOffset );
  13398. camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
  13399. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  13400. // Find the union of the frustum values of the cameras and scale
  13401. // the values so that the near plane's position does not change in world space,
  13402. // although must now be relative to the new union camera.
  13403. const near2 = near + zOffset;
  13404. const far2 = far + zOffset;
  13405. const left2 = left - xOffset;
  13406. const right2 = right + ( ipd - xOffset );
  13407. const top2 = topFov * far / far2 * near2;
  13408. const bottom2 = bottomFov * far / far2 * near2;
  13409. camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
  13410. }
  13411. function updateCamera( camera, parent ) {
  13412. if ( parent === null ) {
  13413. camera.matrixWorld.copy( camera.matrix );
  13414. } else {
  13415. camera.matrixWorld.multiplyMatrices( parent.matrixWorld, camera.matrix );
  13416. }
  13417. camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
  13418. }
  13419. this.getCamera = function ( camera ) {
  13420. cameraVR.near = cameraR.near = cameraL.near = camera.near;
  13421. cameraVR.far = cameraR.far = cameraL.far = camera.far;
  13422. if ( _currentDepthNear !== cameraVR.near || _currentDepthFar !== cameraVR.far ) {
  13423. // Note that the new renderState won't apply until the next frame. See #18320
  13424. session.updateRenderState( {
  13425. depthNear: cameraVR.near,
  13426. depthFar: cameraVR.far
  13427. } );
  13428. _currentDepthNear = cameraVR.near;
  13429. _currentDepthFar = cameraVR.far;
  13430. }
  13431. const parent = camera.parent;
  13432. const cameras = cameraVR.cameras;
  13433. updateCamera( cameraVR, parent );
  13434. for ( let i = 0; i < cameras.length; i ++ ) {
  13435. updateCamera( cameras[ i ], parent );
  13436. }
  13437. // update camera and its children
  13438. camera.matrixWorld.copy( cameraVR.matrixWorld );
  13439. const children = camera.children;
  13440. for ( let i = 0, l = children.length; i < l; i ++ ) {
  13441. children[ i ].updateMatrixWorld( true );
  13442. }
  13443. // update projection matrix for proper view frustum culling
  13444. if ( cameras.length === 2 ) {
  13445. setProjectionFromUnion( cameraVR, cameraL, cameraR );
  13446. } else {
  13447. // assume single camera setup (AR)
  13448. cameraVR.projectionMatrix.copy( cameraL.projectionMatrix );
  13449. }
  13450. return cameraVR;
  13451. };
  13452. // Animation Loop
  13453. let onAnimationFrameCallback = null;
  13454. function onAnimationFrame( time, frame ) {
  13455. pose = frame.getViewerPose( referenceSpace );
  13456. if ( pose !== null ) {
  13457. const views = pose.views;
  13458. const baseLayer = session.renderState.baseLayer;
  13459. renderer.setFramebuffer( baseLayer.framebuffer );
  13460. let cameraVRNeedsUpdate = false;
  13461. // check if it's necessary to rebuild cameraVR's camera list
  13462. if ( views.length !== cameraVR.cameras.length ) {
  13463. cameraVR.cameras.length = 0;
  13464. cameraVRNeedsUpdate = true;
  13465. }
  13466. for ( let i = 0; i < views.length; i ++ ) {
  13467. const view = views[ i ];
  13468. const viewport = baseLayer.getViewport( view );
  13469. const camera = cameras[ i ];
  13470. camera.matrix.fromArray( view.transform.matrix );
  13471. camera.projectionMatrix.fromArray( view.projectionMatrix );
  13472. camera.viewport.set( viewport.x, viewport.y, viewport.width, viewport.height );
  13473. if ( i === 0 ) {
  13474. cameraVR.matrix.copy( camera.matrix );
  13475. }
  13476. if ( cameraVRNeedsUpdate === true ) {
  13477. cameraVR.cameras.push( camera );
  13478. }
  13479. }
  13480. }
  13481. //
  13482. const inputSources = session.inputSources;
  13483. for ( let i = 0; i < controllers.length; i ++ ) {
  13484. const controller = controllers[ i ];
  13485. const inputSource = inputSources[ i ];
  13486. controller.update( inputSource, frame, referenceSpace );
  13487. }
  13488. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time, frame );
  13489. }
  13490. const animation = new WebGLAnimation();
  13491. animation.setAnimationLoop( onAnimationFrame );
  13492. this.setAnimationLoop = function ( callback ) {
  13493. onAnimationFrameCallback = callback;
  13494. };
  13495. this.dispose = function () {};
  13496. }
  13497. Object.assign( WebXRManager.prototype, EventDispatcher.prototype );
  13498. function WebGLMaterials( properties ) {
  13499. function refreshFogUniforms( uniforms, fog ) {
  13500. uniforms.fogColor.value.copy( fog.color );
  13501. if ( fog.isFog ) {
  13502. uniforms.fogNear.value = fog.near;
  13503. uniforms.fogFar.value = fog.far;
  13504. } else if ( fog.isFogExp2 ) {
  13505. uniforms.fogDensity.value = fog.density;
  13506. }
  13507. }
  13508. function refreshMaterialUniforms( uniforms, material, pixelRatio, height ) {
  13509. if ( material.isMeshBasicMaterial ) {
  13510. refreshUniformsCommon( uniforms, material );
  13511. } else if ( material.isMeshLambertMaterial ) {
  13512. refreshUniformsCommon( uniforms, material );
  13513. refreshUniformsLambert( uniforms, material );
  13514. } else if ( material.isMeshToonMaterial ) {
  13515. refreshUniformsCommon( uniforms, material );
  13516. refreshUniformsToon( uniforms, material );
  13517. } else if ( material.isMeshPhongMaterial ) {
  13518. refreshUniformsCommon( uniforms, material );
  13519. refreshUniformsPhong( uniforms, material );
  13520. } else if ( material.isMeshStandardMaterial ) {
  13521. refreshUniformsCommon( uniforms, material );
  13522. if ( material.isMeshPhysicalMaterial ) {
  13523. refreshUniformsPhysical( uniforms, material );
  13524. } else {
  13525. refreshUniformsStandard( uniforms, material );
  13526. }
  13527. } else if ( material.isMeshMatcapMaterial ) {
  13528. refreshUniformsCommon( uniforms, material );
  13529. refreshUniformsMatcap( uniforms, material );
  13530. } else if ( material.isMeshDepthMaterial ) {
  13531. refreshUniformsCommon( uniforms, material );
  13532. refreshUniformsDepth( uniforms, material );
  13533. } else if ( material.isMeshDistanceMaterial ) {
  13534. refreshUniformsCommon( uniforms, material );
  13535. refreshUniformsDistance( uniforms, material );
  13536. } else if ( material.isMeshNormalMaterial ) {
  13537. refreshUniformsCommon( uniforms, material );
  13538. refreshUniformsNormal( uniforms, material );
  13539. } else if ( material.isLineBasicMaterial ) {
  13540. refreshUniformsLine( uniforms, material );
  13541. if ( material.isLineDashedMaterial ) {
  13542. refreshUniformsDash( uniforms, material );
  13543. }
  13544. } else if ( material.isPointsMaterial ) {
  13545. refreshUniformsPoints( uniforms, material, pixelRatio, height );
  13546. } else if ( material.isSpriteMaterial ) {
  13547. refreshUniformsSprites( uniforms, material );
  13548. } else if ( material.isShadowMaterial ) {
  13549. uniforms.color.value.copy( material.color );
  13550. uniforms.opacity.value = material.opacity;
  13551. } else if ( material.isShaderMaterial ) {
  13552. material.uniformsNeedUpdate = false; // #15581
  13553. }
  13554. }
  13555. function refreshUniformsCommon( uniforms, material ) {
  13556. uniforms.opacity.value = material.opacity;
  13557. if ( material.color ) {
  13558. uniforms.diffuse.value.copy( material.color );
  13559. }
  13560. if ( material.emissive ) {
  13561. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  13562. }
  13563. if ( material.map ) {
  13564. uniforms.map.value = material.map;
  13565. }
  13566. if ( material.alphaMap ) {
  13567. uniforms.alphaMap.value = material.alphaMap;
  13568. }
  13569. if ( material.specularMap ) {
  13570. uniforms.specularMap.value = material.specularMap;
  13571. }
  13572. const envMap = properties.get( material ).envMap;
  13573. if ( envMap ) {
  13574. uniforms.envMap.value = envMap;
  13575. uniforms.flipEnvMap.value = ( envMap.isCubeTexture && envMap._needsFlipEnvMap ) ? - 1 : 1;
  13576. uniforms.reflectivity.value = material.reflectivity;
  13577. uniforms.refractionRatio.value = material.refractionRatio;
  13578. const maxMipLevel = properties.get( envMap ).__maxMipLevel;
  13579. if ( maxMipLevel !== undefined ) {
  13580. uniforms.maxMipLevel.value = maxMipLevel;
  13581. }
  13582. }
  13583. if ( material.lightMap ) {
  13584. uniforms.lightMap.value = material.lightMap;
  13585. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13586. }
  13587. if ( material.aoMap ) {
  13588. uniforms.aoMap.value = material.aoMap;
  13589. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13590. }
  13591. // uv repeat and offset setting priorities
  13592. // 1. color map
  13593. // 2. specular map
  13594. // 3. displacementMap map
  13595. // 4. normal map
  13596. // 5. bump map
  13597. // 6. roughnessMap map
  13598. // 7. metalnessMap map
  13599. // 8. alphaMap map
  13600. // 9. emissiveMap map
  13601. // 10. clearcoat map
  13602. // 11. clearcoat normal map
  13603. // 12. clearcoat roughnessMap map
  13604. let uvScaleMap;
  13605. if ( material.map ) {
  13606. uvScaleMap = material.map;
  13607. } else if ( material.specularMap ) {
  13608. uvScaleMap = material.specularMap;
  13609. } else if ( material.displacementMap ) {
  13610. uvScaleMap = material.displacementMap;
  13611. } else if ( material.normalMap ) {
  13612. uvScaleMap = material.normalMap;
  13613. } else if ( material.bumpMap ) {
  13614. uvScaleMap = material.bumpMap;
  13615. } else if ( material.roughnessMap ) {
  13616. uvScaleMap = material.roughnessMap;
  13617. } else if ( material.metalnessMap ) {
  13618. uvScaleMap = material.metalnessMap;
  13619. } else if ( material.alphaMap ) {
  13620. uvScaleMap = material.alphaMap;
  13621. } else if ( material.emissiveMap ) {
  13622. uvScaleMap = material.emissiveMap;
  13623. } else if ( material.clearcoatMap ) {
  13624. uvScaleMap = material.clearcoatMap;
  13625. } else if ( material.clearcoatNormalMap ) {
  13626. uvScaleMap = material.clearcoatNormalMap;
  13627. } else if ( material.clearcoatRoughnessMap ) {
  13628. uvScaleMap = material.clearcoatRoughnessMap;
  13629. }
  13630. if ( uvScaleMap !== undefined ) {
  13631. // backwards compatibility
  13632. if ( uvScaleMap.isWebGLRenderTarget ) {
  13633. uvScaleMap = uvScaleMap.texture;
  13634. }
  13635. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13636. uvScaleMap.updateMatrix();
  13637. }
  13638. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13639. }
  13640. // uv repeat and offset setting priorities for uv2
  13641. // 1. ao map
  13642. // 2. light map
  13643. let uv2ScaleMap;
  13644. if ( material.aoMap ) {
  13645. uv2ScaleMap = material.aoMap;
  13646. } else if ( material.lightMap ) {
  13647. uv2ScaleMap = material.lightMap;
  13648. }
  13649. if ( uv2ScaleMap !== undefined ) {
  13650. // backwards compatibility
  13651. if ( uv2ScaleMap.isWebGLRenderTarget ) {
  13652. uv2ScaleMap = uv2ScaleMap.texture;
  13653. }
  13654. if ( uv2ScaleMap.matrixAutoUpdate === true ) {
  13655. uv2ScaleMap.updateMatrix();
  13656. }
  13657. uniforms.uv2Transform.value.copy( uv2ScaleMap.matrix );
  13658. }
  13659. }
  13660. function refreshUniformsLine( uniforms, material ) {
  13661. uniforms.diffuse.value.copy( material.color );
  13662. uniforms.opacity.value = material.opacity;
  13663. }
  13664. function refreshUniformsDash( uniforms, material ) {
  13665. uniforms.dashSize.value = material.dashSize;
  13666. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13667. uniforms.scale.value = material.scale;
  13668. }
  13669. function refreshUniformsPoints( uniforms, material, pixelRatio, height ) {
  13670. uniforms.diffuse.value.copy( material.color );
  13671. uniforms.opacity.value = material.opacity;
  13672. uniforms.size.value = material.size * pixelRatio;
  13673. uniforms.scale.value = height * 0.5;
  13674. if ( material.map ) {
  13675. uniforms.map.value = material.map;
  13676. }
  13677. if ( material.alphaMap ) {
  13678. uniforms.alphaMap.value = material.alphaMap;
  13679. }
  13680. // uv repeat and offset setting priorities
  13681. // 1. color map
  13682. // 2. alpha map
  13683. let uvScaleMap;
  13684. if ( material.map ) {
  13685. uvScaleMap = material.map;
  13686. } else if ( material.alphaMap ) {
  13687. uvScaleMap = material.alphaMap;
  13688. }
  13689. if ( uvScaleMap !== undefined ) {
  13690. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13691. uvScaleMap.updateMatrix();
  13692. }
  13693. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13694. }
  13695. }
  13696. function refreshUniformsSprites( uniforms, material ) {
  13697. uniforms.diffuse.value.copy( material.color );
  13698. uniforms.opacity.value = material.opacity;
  13699. uniforms.rotation.value = material.rotation;
  13700. if ( material.map ) {
  13701. uniforms.map.value = material.map;
  13702. }
  13703. if ( material.alphaMap ) {
  13704. uniforms.alphaMap.value = material.alphaMap;
  13705. }
  13706. // uv repeat and offset setting priorities
  13707. // 1. color map
  13708. // 2. alpha map
  13709. let uvScaleMap;
  13710. if ( material.map ) {
  13711. uvScaleMap = material.map;
  13712. } else if ( material.alphaMap ) {
  13713. uvScaleMap = material.alphaMap;
  13714. }
  13715. if ( uvScaleMap !== undefined ) {
  13716. if ( uvScaleMap.matrixAutoUpdate === true ) {
  13717. uvScaleMap.updateMatrix();
  13718. }
  13719. uniforms.uvTransform.value.copy( uvScaleMap.matrix );
  13720. }
  13721. }
  13722. function refreshUniformsLambert( uniforms, material ) {
  13723. if ( material.emissiveMap ) {
  13724. uniforms.emissiveMap.value = material.emissiveMap;
  13725. }
  13726. }
  13727. function refreshUniformsPhong( uniforms, material ) {
  13728. uniforms.specular.value.copy( material.specular );
  13729. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13730. if ( material.emissiveMap ) {
  13731. uniforms.emissiveMap.value = material.emissiveMap;
  13732. }
  13733. if ( material.bumpMap ) {
  13734. uniforms.bumpMap.value = material.bumpMap;
  13735. uniforms.bumpScale.value = material.bumpScale;
  13736. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13737. }
  13738. if ( material.normalMap ) {
  13739. uniforms.normalMap.value = material.normalMap;
  13740. uniforms.normalScale.value.copy( material.normalScale );
  13741. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13742. }
  13743. if ( material.displacementMap ) {
  13744. uniforms.displacementMap.value = material.displacementMap;
  13745. uniforms.displacementScale.value = material.displacementScale;
  13746. uniforms.displacementBias.value = material.displacementBias;
  13747. }
  13748. }
  13749. function refreshUniformsToon( uniforms, material ) {
  13750. if ( material.gradientMap ) {
  13751. uniforms.gradientMap.value = material.gradientMap;
  13752. }
  13753. if ( material.emissiveMap ) {
  13754. uniforms.emissiveMap.value = material.emissiveMap;
  13755. }
  13756. if ( material.bumpMap ) {
  13757. uniforms.bumpMap.value = material.bumpMap;
  13758. uniforms.bumpScale.value = material.bumpScale;
  13759. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13760. }
  13761. if ( material.normalMap ) {
  13762. uniforms.normalMap.value = material.normalMap;
  13763. uniforms.normalScale.value.copy( material.normalScale );
  13764. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13765. }
  13766. if ( material.displacementMap ) {
  13767. uniforms.displacementMap.value = material.displacementMap;
  13768. uniforms.displacementScale.value = material.displacementScale;
  13769. uniforms.displacementBias.value = material.displacementBias;
  13770. }
  13771. }
  13772. function refreshUniformsStandard( uniforms, material ) {
  13773. uniforms.roughness.value = material.roughness;
  13774. uniforms.metalness.value = material.metalness;
  13775. if ( material.roughnessMap ) {
  13776. uniforms.roughnessMap.value = material.roughnessMap;
  13777. }
  13778. if ( material.metalnessMap ) {
  13779. uniforms.metalnessMap.value = material.metalnessMap;
  13780. }
  13781. if ( material.emissiveMap ) {
  13782. uniforms.emissiveMap.value = material.emissiveMap;
  13783. }
  13784. if ( material.bumpMap ) {
  13785. uniforms.bumpMap.value = material.bumpMap;
  13786. uniforms.bumpScale.value = material.bumpScale;
  13787. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13788. }
  13789. if ( material.normalMap ) {
  13790. uniforms.normalMap.value = material.normalMap;
  13791. uniforms.normalScale.value.copy( material.normalScale );
  13792. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13793. }
  13794. if ( material.displacementMap ) {
  13795. uniforms.displacementMap.value = material.displacementMap;
  13796. uniforms.displacementScale.value = material.displacementScale;
  13797. uniforms.displacementBias.value = material.displacementBias;
  13798. }
  13799. const envMap = properties.get( material ).envMap;
  13800. if ( envMap ) {
  13801. //uniforms.envMap.value = material.envMap; // part of uniforms common
  13802. uniforms.envMapIntensity.value = material.envMapIntensity;
  13803. }
  13804. }
  13805. function refreshUniformsPhysical( uniforms, material ) {
  13806. refreshUniformsStandard( uniforms, material );
  13807. uniforms.reflectivity.value = material.reflectivity; // also part of uniforms common
  13808. uniforms.clearcoat.value = material.clearcoat;
  13809. uniforms.clearcoatRoughness.value = material.clearcoatRoughness;
  13810. if ( material.sheen ) uniforms.sheen.value.copy( material.sheen );
  13811. if ( material.clearcoatMap ) {
  13812. uniforms.clearcoatMap.value = material.clearcoatMap;
  13813. }
  13814. if ( material.clearcoatRoughnessMap ) {
  13815. uniforms.clearcoatRoughnessMap.value = material.clearcoatRoughnessMap;
  13816. }
  13817. if ( material.clearcoatNormalMap ) {
  13818. uniforms.clearcoatNormalScale.value.copy( material.clearcoatNormalScale );
  13819. uniforms.clearcoatNormalMap.value = material.clearcoatNormalMap;
  13820. if ( material.side === BackSide ) {
  13821. uniforms.clearcoatNormalScale.value.negate();
  13822. }
  13823. }
  13824. uniforms.transmission.value = material.transmission;
  13825. if ( material.transmissionMap ) {
  13826. uniforms.transmissionMap.value = material.transmissionMap;
  13827. }
  13828. }
  13829. function refreshUniformsMatcap( uniforms, material ) {
  13830. if ( material.matcap ) {
  13831. uniforms.matcap.value = material.matcap;
  13832. }
  13833. if ( material.bumpMap ) {
  13834. uniforms.bumpMap.value = material.bumpMap;
  13835. uniforms.bumpScale.value = material.bumpScale;
  13836. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13837. }
  13838. if ( material.normalMap ) {
  13839. uniforms.normalMap.value = material.normalMap;
  13840. uniforms.normalScale.value.copy( material.normalScale );
  13841. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13842. }
  13843. if ( material.displacementMap ) {
  13844. uniforms.displacementMap.value = material.displacementMap;
  13845. uniforms.displacementScale.value = material.displacementScale;
  13846. uniforms.displacementBias.value = material.displacementBias;
  13847. }
  13848. }
  13849. function refreshUniformsDepth( uniforms, material ) {
  13850. if ( material.displacementMap ) {
  13851. uniforms.displacementMap.value = material.displacementMap;
  13852. uniforms.displacementScale.value = material.displacementScale;
  13853. uniforms.displacementBias.value = material.displacementBias;
  13854. }
  13855. }
  13856. function refreshUniformsDistance( uniforms, material ) {
  13857. if ( material.displacementMap ) {
  13858. uniforms.displacementMap.value = material.displacementMap;
  13859. uniforms.displacementScale.value = material.displacementScale;
  13860. uniforms.displacementBias.value = material.displacementBias;
  13861. }
  13862. uniforms.referencePosition.value.copy( material.referencePosition );
  13863. uniforms.nearDistance.value = material.nearDistance;
  13864. uniforms.farDistance.value = material.farDistance;
  13865. }
  13866. function refreshUniformsNormal( uniforms, material ) {
  13867. if ( material.bumpMap ) {
  13868. uniforms.bumpMap.value = material.bumpMap;
  13869. uniforms.bumpScale.value = material.bumpScale;
  13870. if ( material.side === BackSide ) uniforms.bumpScale.value *= - 1;
  13871. }
  13872. if ( material.normalMap ) {
  13873. uniforms.normalMap.value = material.normalMap;
  13874. uniforms.normalScale.value.copy( material.normalScale );
  13875. if ( material.side === BackSide ) uniforms.normalScale.value.negate();
  13876. }
  13877. if ( material.displacementMap ) {
  13878. uniforms.displacementMap.value = material.displacementMap;
  13879. uniforms.displacementScale.value = material.displacementScale;
  13880. uniforms.displacementBias.value = material.displacementBias;
  13881. }
  13882. }
  13883. return {
  13884. refreshFogUniforms: refreshFogUniforms,
  13885. refreshMaterialUniforms: refreshMaterialUniforms
  13886. };
  13887. }
  13888. function createCanvasElement() {
  13889. const canvas = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'canvas' );
  13890. canvas.style.display = 'block';
  13891. return canvas;
  13892. }
  13893. function WebGLRenderer( parameters ) {
  13894. parameters = parameters || {};
  13895. const _canvas = parameters.canvas !== undefined ? parameters.canvas : createCanvasElement(),
  13896. _context = parameters.context !== undefined ? parameters.context : null,
  13897. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  13898. _depth = parameters.depth !== undefined ? parameters.depth : true,
  13899. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  13900. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  13901. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  13902. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  13903. _powerPreference = parameters.powerPreference !== undefined ? parameters.powerPreference : 'default',
  13904. _failIfMajorPerformanceCaveat = parameters.failIfMajorPerformanceCaveat !== undefined ? parameters.failIfMajorPerformanceCaveat : false;
  13905. let currentRenderList = null;
  13906. let currentRenderState = null;
  13907. // render() can be called from within a callback triggered by another render.
  13908. // We track this so that the nested render call gets its state isolated from the parent render call.
  13909. const renderStateStack = [];
  13910. // public properties
  13911. this.domElement = _canvas;
  13912. // Debug configuration container
  13913. this.debug = {
  13914. /**
  13915. * Enables error checking and reporting when shader programs are being compiled
  13916. * @type {boolean}
  13917. */
  13918. checkShaderErrors: true
  13919. };
  13920. // clearing
  13921. this.autoClear = true;
  13922. this.autoClearColor = true;
  13923. this.autoClearDepth = true;
  13924. this.autoClearStencil = true;
  13925. // scene graph
  13926. this.sortObjects = true;
  13927. // user-defined clipping
  13928. this.clippingPlanes = [];
  13929. this.localClippingEnabled = false;
  13930. // physically based shading
  13931. this.gammaFactor = 2.0; // for backwards compatibility
  13932. this.outputEncoding = LinearEncoding;
  13933. // physical lights
  13934. this.physicallyCorrectLights = false;
  13935. // tone mapping
  13936. this.toneMapping = NoToneMapping;
  13937. this.toneMappingExposure = 1.0;
  13938. // morphs
  13939. this.maxMorphTargets = 8;
  13940. this.maxMorphNormals = 4;
  13941. // internal properties
  13942. const _this = this;
  13943. let _isContextLost = false;
  13944. // internal state cache
  13945. let _framebuffer = null;
  13946. let _currentActiveCubeFace = 0;
  13947. let _currentActiveMipmapLevel = 0;
  13948. let _currentRenderTarget = null;
  13949. let _currentFramebuffer = null;
  13950. let _currentMaterialId = - 1;
  13951. let _currentCamera = null;
  13952. const _currentViewport = new Vector4();
  13953. const _currentScissor = new Vector4();
  13954. let _currentScissorTest = null;
  13955. //
  13956. let _width = _canvas.width;
  13957. let _height = _canvas.height;
  13958. let _pixelRatio = 1;
  13959. let _opaqueSort = null;
  13960. let _transparentSort = null;
  13961. const _viewport = new Vector4( 0, 0, _width, _height );
  13962. const _scissor = new Vector4( 0, 0, _width, _height );
  13963. let _scissorTest = false;
  13964. // frustum
  13965. const _frustum = new Frustum();
  13966. // clipping
  13967. let _clippingEnabled = false;
  13968. let _localClippingEnabled = false;
  13969. // camera matrices cache
  13970. const _projScreenMatrix = new Matrix4();
  13971. const _vector3 = new Vector3();
  13972. const _emptyScene = { background: null, fog: null, environment: null, overrideMaterial: null, isScene: true };
  13973. function getTargetPixelRatio() {
  13974. return _currentRenderTarget === null ? _pixelRatio : 1;
  13975. }
  13976. // initialize
  13977. let _gl = _context;
  13978. function getContext( contextNames, contextAttributes ) {
  13979. for ( let i = 0; i < contextNames.length; i ++ ) {
  13980. const contextName = contextNames[ i ];
  13981. const context = _canvas.getContext( contextName, contextAttributes );
  13982. if ( context !== null ) return context;
  13983. }
  13984. return null;
  13985. }
  13986. try {
  13987. const contextAttributes = {
  13988. alpha: _alpha,
  13989. depth: _depth,
  13990. stencil: _stencil,
  13991. antialias: _antialias,
  13992. premultipliedAlpha: _premultipliedAlpha,
  13993. preserveDrawingBuffer: _preserveDrawingBuffer,
  13994. powerPreference: _powerPreference,
  13995. failIfMajorPerformanceCaveat: _failIfMajorPerformanceCaveat
  13996. };
  13997. // event listeners must be registered before WebGL context is created, see #12753
  13998. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  13999. _canvas.addEventListener( 'webglcontextrestored', onContextRestore, false );
  14000. if ( _gl === null ) {
  14001. const contextNames = [ 'webgl2', 'webgl', 'experimental-webgl' ];
  14002. if ( _this.isWebGL1Renderer === true ) {
  14003. contextNames.shift();
  14004. }
  14005. _gl = getContext( contextNames, contextAttributes );
  14006. if ( _gl === null ) {
  14007. if ( getContext( contextNames ) ) {
  14008. throw new Error( 'Error creating WebGL context with your selected attributes.' );
  14009. } else {
  14010. throw new Error( 'Error creating WebGL context.' );
  14011. }
  14012. }
  14013. }
  14014. // Some experimental-webgl implementations do not have getShaderPrecisionFormat
  14015. if ( _gl.getShaderPrecisionFormat === undefined ) {
  14016. _gl.getShaderPrecisionFormat = function () {
  14017. return { 'rangeMin': 1, 'rangeMax': 1, 'precision': 1 };
  14018. };
  14019. }
  14020. } catch ( error ) {
  14021. console.error( 'THREE.WebGLRenderer: ' + error.message );
  14022. throw error;
  14023. }
  14024. let extensions, capabilities, state, info;
  14025. let properties, textures, cubemaps, attributes, geometries, objects;
  14026. let programCache, materials, renderLists, renderStates, clipping;
  14027. let background, morphtargets, bufferRenderer, indexedBufferRenderer;
  14028. let utils, bindingStates;
  14029. function initGLContext() {
  14030. extensions = new WebGLExtensions( _gl );
  14031. capabilities = new WebGLCapabilities( _gl, extensions, parameters );
  14032. if ( capabilities.isWebGL2 === false ) {
  14033. extensions.get( 'WEBGL_depth_texture' );
  14034. extensions.get( 'OES_texture_float' );
  14035. extensions.get( 'OES_texture_half_float' );
  14036. extensions.get( 'OES_texture_half_float_linear' );
  14037. extensions.get( 'OES_standard_derivatives' );
  14038. extensions.get( 'OES_element_index_uint' );
  14039. extensions.get( 'OES_vertex_array_object' );
  14040. extensions.get( 'ANGLE_instanced_arrays' );
  14041. }
  14042. extensions.get( 'OES_texture_float_linear' );
  14043. utils = new WebGLUtils( _gl, extensions, capabilities );
  14044. state = new WebGLState( _gl, extensions, capabilities );
  14045. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14046. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14047. info = new WebGLInfo( _gl );
  14048. properties = new WebGLProperties();
  14049. textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
  14050. cubemaps = new WebGLCubeMaps( _this );
  14051. attributes = new WebGLAttributes( _gl, capabilities );
  14052. bindingStates = new WebGLBindingStates( _gl, extensions, attributes, capabilities );
  14053. geometries = new WebGLGeometries( _gl, attributes, info, bindingStates );
  14054. objects = new WebGLObjects( _gl, geometries, attributes, info );
  14055. morphtargets = new WebGLMorphtargets( _gl );
  14056. clipping = new WebGLClipping( properties );
  14057. programCache = new WebGLPrograms( _this, cubemaps, extensions, capabilities, bindingStates, clipping );
  14058. materials = new WebGLMaterials( properties );
  14059. renderLists = new WebGLRenderLists( properties );
  14060. renderStates = new WebGLRenderStates( extensions, capabilities );
  14061. background = new WebGLBackground( _this, cubemaps, state, objects, _premultipliedAlpha );
  14062. bufferRenderer = new WebGLBufferRenderer( _gl, extensions, info, capabilities );
  14063. indexedBufferRenderer = new WebGLIndexedBufferRenderer( _gl, extensions, info, capabilities );
  14064. info.programs = programCache.programs;
  14065. _this.capabilities = capabilities;
  14066. _this.extensions = extensions;
  14067. _this.properties = properties;
  14068. _this.renderLists = renderLists;
  14069. _this.state = state;
  14070. _this.info = info;
  14071. _this._textures = textures;//add
  14072. }
  14073. initGLContext();
  14074. // xr
  14075. const xr = new WebXRManager( _this, _gl );
  14076. this.xr = xr;
  14077. // shadow map
  14078. const shadowMap = new WebGLShadowMap( _this, objects, capabilities.maxTextureSize );
  14079. this.shadowMap = shadowMap;
  14080. // API
  14081. this.getContext = function () {
  14082. return _gl;
  14083. };
  14084. this.getContextAttributes = function () {
  14085. return _gl.getContextAttributes();
  14086. };
  14087. this.forceContextLoss = function () {
  14088. const extension = extensions.get( 'WEBGL_lose_context' );
  14089. if ( extension ) extension.loseContext();
  14090. };
  14091. this.forceContextRestore = function () {
  14092. const extension = extensions.get( 'WEBGL_lose_context' );
  14093. if ( extension ) extension.restoreContext();
  14094. };
  14095. this.getPixelRatio = function () {
  14096. return _pixelRatio;
  14097. };
  14098. this.setPixelRatio = function ( value ) {
  14099. if ( value === undefined ) return;
  14100. _pixelRatio = value;
  14101. this.setSize( _width, _height, false );
  14102. };
  14103. this.getSize = function ( target ) {
  14104. if ( target === undefined ) {
  14105. console.warn( 'WebGLRenderer: .getsize() now requires a Vector2 as an argument' );
  14106. target = new Vector2();
  14107. }
  14108. return target.set( _width, _height );
  14109. };
  14110. this.setSize = function ( width, height, updateStyle ) {
  14111. if ( xr.isPresenting ) {
  14112. console.warn( 'THREE.WebGLRenderer: Can\'t change size while VR device is presenting.' );
  14113. return;
  14114. }
  14115. _width = width;
  14116. _height = height;
  14117. _canvas.width = Math.floor( width * _pixelRatio );
  14118. _canvas.height = Math.floor( height * _pixelRatio );
  14119. if ( updateStyle !== false ) {
  14120. _canvas.style.width = width + 'px';
  14121. _canvas.style.height = height + 'px';
  14122. }
  14123. this.setViewport( 0, 0, width, height );
  14124. };
  14125. this.getDrawingBufferSize = function ( target ) {
  14126. if ( target === undefined ) {
  14127. console.warn( 'WebGLRenderer: .getdrawingBufferSize() now requires a Vector2 as an argument' );
  14128. target = new Vector2();
  14129. }
  14130. return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor();
  14131. };
  14132. this.setDrawingBufferSize = function ( width, height, pixelRatio ) {
  14133. _width = width;
  14134. _height = height;
  14135. _pixelRatio = pixelRatio;
  14136. _canvas.width = Math.floor( width * pixelRatio );
  14137. _canvas.height = Math.floor( height * pixelRatio );
  14138. this.setViewport( 0, 0, width, height );
  14139. };
  14140. this.getCurrentViewport = function ( target ) {
  14141. if ( target === undefined ) {
  14142. console.warn( 'WebGLRenderer: .getCurrentViewport() now requires a Vector4 as an argument' );
  14143. target = new Vector4();
  14144. }
  14145. return target.copy( _currentViewport );
  14146. };
  14147. this.getViewport = function ( target ) {
  14148. return target.copy( _viewport );
  14149. };
  14150. this.setViewport = function ( x, y, width, height ) {
  14151. if ( x.isVector4 ) {
  14152. _viewport.set( x.x, x.y, x.z, x.w );
  14153. } else {
  14154. _viewport.set( x, y, width, height );
  14155. }
  14156. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() );
  14157. };
  14158. this.getScissor = function ( target ) {
  14159. return target.copy( _scissor );
  14160. };
  14161. this.setScissor = function ( x, y, width, height ) {
  14162. if ( x.isVector4 ) {
  14163. _scissor.set( x.x, x.y, x.z, x.w );
  14164. } else {
  14165. _scissor.set( x, y, width, height );
  14166. }
  14167. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor() );
  14168. };
  14169. this.getScissorTest = function () {
  14170. return _scissorTest;
  14171. };
  14172. this.setScissorTest = function ( boolean ) {
  14173. state.setScissorTest( _scissorTest = boolean );
  14174. };
  14175. this.setOpaqueSort = function ( method ) {
  14176. _opaqueSort = method;
  14177. };
  14178. this.setTransparentSort = function ( method ) {
  14179. _transparentSort = method;
  14180. };
  14181. // Clearing
  14182. this.getClearColor = function ( target ) {
  14183. if ( target === undefined ) {
  14184. console.warn( 'WebGLRenderer: .getClearColor() now requires a Color as an argument' );
  14185. target = new Color();
  14186. }
  14187. return target.copy( background.getClearColor() );
  14188. };
  14189. this.setClearColor = function () {
  14190. background.setClearColor.apply( background, arguments );
  14191. };
  14192. this.getClearAlpha = function () {
  14193. return background.getClearAlpha();
  14194. };
  14195. this.setClearAlpha = function () {
  14196. background.setClearAlpha.apply( background, arguments );
  14197. };
  14198. this.clear = function ( color, depth, stencil ) {
  14199. let bits = 0;
  14200. if ( color === undefined || color ) bits |= 16384;
  14201. if ( depth === undefined || depth ) bits |= 256;
  14202. if ( stencil === undefined || stencil ) bits |= 1024;
  14203. _gl.clear( bits );
  14204. };
  14205. this.clearColor = function () {
  14206. this.clear( true, false, false );
  14207. };
  14208. this.clearDepth = function () {
  14209. this.clear( false, true, false );
  14210. };
  14211. this.clearStencil = function () {
  14212. this.clear( false, false, true );
  14213. };
  14214. //
  14215. this.dispose = function () {
  14216. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  14217. _canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
  14218. renderLists.dispose();
  14219. renderStates.dispose();
  14220. properties.dispose();
  14221. cubemaps.dispose();
  14222. objects.dispose();
  14223. bindingStates.dispose();
  14224. xr.dispose();
  14225. animation.stop();
  14226. };
  14227. // Events
  14228. function onContextLost( event ) {
  14229. event.preventDefault();
  14230. console.log( 'THREE.WebGLRenderer: Context Lost.' );
  14231. _isContextLost = true;
  14232. }
  14233. function onContextRestore( /* event */ ) {
  14234. console.log( 'THREE.WebGLRenderer: Context Restored.' );
  14235. _isContextLost = false;
  14236. initGLContext();
  14237. }
  14238. function onMaterialDispose( event ) {
  14239. const material = event.target;
  14240. material.removeEventListener( 'dispose', onMaterialDispose );
  14241. deallocateMaterial( material );
  14242. }
  14243. // Buffer deallocation
  14244. function deallocateMaterial( material ) {
  14245. releaseMaterialProgramReference( material );
  14246. properties.remove( material );
  14247. }
  14248. function releaseMaterialProgramReference( material ) {
  14249. const programInfo = properties.get( material ).program;
  14250. if ( programInfo !== undefined ) {
  14251. programCache.releaseProgram( programInfo );
  14252. }
  14253. }
  14254. // Buffer rendering
  14255. function renderObjectImmediate( object, program ) {
  14256. object.render( function ( object ) {
  14257. _this.renderBufferImmediate( object, program );
  14258. } );
  14259. }
  14260. this.renderBufferImmediate = function ( object, program ) {
  14261. bindingStates.initAttributes();
  14262. const buffers = properties.get( object );
  14263. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  14264. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  14265. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  14266. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  14267. const programAttributes = program.getAttributes();
  14268. if ( object.hasPositions ) {
  14269. _gl.bindBuffer( 34962, buffers.position );
  14270. _gl.bufferData( 34962, object.positionArray, 35048 );
  14271. bindingStates.enableAttribute( programAttributes.position );
  14272. _gl.vertexAttribPointer( programAttributes.position, 3, 5126, false, 0, 0 );
  14273. }
  14274. if ( object.hasNormals ) {
  14275. _gl.bindBuffer( 34962, buffers.normal );
  14276. _gl.bufferData( 34962, object.normalArray, 35048 );
  14277. bindingStates.enableAttribute( programAttributes.normal );
  14278. _gl.vertexAttribPointer( programAttributes.normal, 3, 5126, false, 0, 0 );
  14279. }
  14280. if ( object.hasUvs ) {
  14281. _gl.bindBuffer( 34962, buffers.uv );
  14282. _gl.bufferData( 34962, object.uvArray, 35048 );
  14283. bindingStates.enableAttribute( programAttributes.uv );
  14284. _gl.vertexAttribPointer( programAttributes.uv, 2, 5126, false, 0, 0 );
  14285. }
  14286. if ( object.hasColors ) {
  14287. _gl.bindBuffer( 34962, buffers.color );
  14288. _gl.bufferData( 34962, object.colorArray, 35048 );
  14289. bindingStates.enableAttribute( programAttributes.color );
  14290. _gl.vertexAttribPointer( programAttributes.color, 3, 5126, false, 0, 0 );
  14291. }
  14292. bindingStates.disableUnusedAttributes();
  14293. _gl.drawArrays( 4, 0, object.count );
  14294. object.count = 0;
  14295. };
  14296. this.renderBufferDirect = function ( camera, scene, geometry, material, object, group ) {
  14297. if ( scene === null ) scene = _emptyScene; // renderBufferDirect second parameter used to be fog (could be null)
  14298. const frontFaceCW = ( object.isMesh && object.matrixWorld.determinant() < 0 );
  14299. const program = setProgram( camera, scene, material, object );
  14300. state.setMaterial( material, frontFaceCW );
  14301. //
  14302. let index = geometry.index;
  14303. const position = geometry.attributes.position;
  14304. //
  14305. if ( index === null ) {
  14306. if ( position === undefined || position.count === 0 ) return;
  14307. } else if ( index.count === 0 ) {
  14308. return;
  14309. }
  14310. //
  14311. let rangeFactor = 1;
  14312. if ( material.wireframe === true ) {
  14313. index = geometries.getWireframeAttribute( geometry );
  14314. rangeFactor = 2;
  14315. }
  14316. if ( material.morphTargets || material.morphNormals ) {
  14317. morphtargets.update( object, geometry, material, program );
  14318. }
  14319. bindingStates.setup( object, material, program, geometry, index );
  14320. let attribute;
  14321. let renderer = bufferRenderer;
  14322. if ( index !== null ) {
  14323. attribute = attributes.get( index );
  14324. renderer = indexedBufferRenderer;
  14325. renderer.setIndex( attribute );
  14326. }
  14327. //
  14328. const dataCount = ( index !== null ) ? index.count : position.count;
  14329. const rangeStart = geometry.drawRange.start * rangeFactor;
  14330. const rangeCount = geometry.drawRange.count * rangeFactor;
  14331. const groupStart = group !== null ? group.start * rangeFactor : 0;
  14332. const groupCount = group !== null ? group.count * rangeFactor : Infinity;
  14333. const drawStart = Math.max( rangeStart, groupStart );
  14334. const drawEnd = Math.min( dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  14335. const drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  14336. if ( drawCount === 0 ) return;
  14337. //
  14338. if ( object.isMesh ) {
  14339. if ( material.wireframe === true ) {
  14340. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  14341. renderer.setMode( 1 );
  14342. } else {
  14343. renderer.setMode( 4 );
  14344. }
  14345. } else if ( object.isLine ) {
  14346. let lineWidth = material.linewidth;
  14347. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  14348. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  14349. if ( object.isLineSegments ) {
  14350. renderer.setMode( 1 );
  14351. } else if ( object.isLineLoop ) {
  14352. renderer.setMode( 2 );
  14353. } else {
  14354. renderer.setMode( 3 );
  14355. }
  14356. } else if ( object.isPoints ) {
  14357. renderer.setMode( 0 );
  14358. } else if ( object.isSprite ) {
  14359. renderer.setMode( 4 );
  14360. }
  14361. if ( object.isInstancedMesh ) {
  14362. renderer.renderInstances( drawStart, drawCount, object.count );
  14363. } else if ( geometry.isInstancedBufferGeometry ) {
  14364. const instanceCount = Math.min( geometry.instanceCount, geometry._maxInstanceCount );
  14365. renderer.renderInstances( drawStart, drawCount, instanceCount );
  14366. } else {
  14367. renderer.render( drawStart, drawCount );
  14368. }
  14369. };
  14370. // Compile
  14371. this.compile = function ( scene, camera ) {
  14372. currentRenderState = renderStates.get( scene );
  14373. currentRenderState.init();
  14374. scene.traverseVisible( function ( object ) {
  14375. if ( object.isLight && object.layers.test( camera.layers ) ) {
  14376. currentRenderState.pushLight( object );
  14377. if ( object.castShadow ) {
  14378. currentRenderState.pushShadow( object );
  14379. }
  14380. }
  14381. } );
  14382. currentRenderState.setupLights();
  14383. const compiled = new WeakMap();
  14384. scene.traverse( function ( object ) {
  14385. const material = object.material;
  14386. if ( material ) {
  14387. if ( Array.isArray( material ) ) {
  14388. for ( let i = 0; i < material.length; i ++ ) {
  14389. const material2 = material[ i ];
  14390. if ( compiled.has( material2 ) === false ) {
  14391. initMaterial( material2, scene, object );
  14392. compiled.set( material2 );
  14393. }
  14394. }
  14395. } else if ( compiled.has( material ) === false ) {
  14396. initMaterial( material, scene, object );
  14397. compiled.set( material );
  14398. }
  14399. }
  14400. } );
  14401. };
  14402. // Animation Loop
  14403. let onAnimationFrameCallback = null;
  14404. function onAnimationFrame( time ) {
  14405. if ( xr.isPresenting ) return;
  14406. if ( onAnimationFrameCallback ) onAnimationFrameCallback( time );
  14407. }
  14408. const animation = new WebGLAnimation();
  14409. animation.setAnimationLoop( onAnimationFrame );
  14410. if ( typeof window !== 'undefined' ) animation.setContext( window );
  14411. this.setAnimationLoop = function ( callback ) {
  14412. onAnimationFrameCallback = callback;
  14413. xr.setAnimationLoop( callback );
  14414. ( callback === null ) ? animation.stop() : animation.start();
  14415. };
  14416. // Rendering
  14417. this.render = function ( scene, camera ) {
  14418. let renderTarget, forceClear;
  14419. if ( arguments[ 2 ] !== undefined ) {
  14420. console.warn( 'THREE.WebGLRenderer.render(): the renderTarget argument has been removed. Use .setRenderTarget() instead.' );
  14421. renderTarget = arguments[ 2 ];
  14422. }
  14423. if ( arguments[ 3 ] !== undefined ) {
  14424. console.warn( 'THREE.WebGLRenderer.render(): the forceClear argument has been removed. Use .clear() instead.' );
  14425. forceClear = arguments[ 3 ];
  14426. }
  14427. if ( camera !== undefined && camera.isCamera !== true ) {
  14428. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  14429. return;
  14430. }
  14431. if ( _isContextLost === true ) return;
  14432. // reset caching for this frame
  14433. bindingStates.resetDefaultState();
  14434. _currentMaterialId = - 1;
  14435. _currentCamera = null;
  14436. // update scene graph
  14437. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14438. // update camera matrices and frustum
  14439. if ( camera.parent === null ) camera.updateMatrixWorld();
  14440. if ( xr.enabled === true && xr.isPresenting === true ) {
  14441. camera = xr.getCamera( camera );
  14442. }
  14443. //
  14444. if ( scene.isScene === true ) scene.onBeforeRender( _this, scene, camera, renderTarget || _currentRenderTarget );
  14445. currentRenderState = renderStates.get( scene, renderStateStack.length );
  14446. currentRenderState.init();
  14447. renderStateStack.push( currentRenderState );
  14448. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  14449. _frustum.setFromProjectionMatrix( _projScreenMatrix );
  14450. _localClippingEnabled = this.localClippingEnabled;
  14451. _clippingEnabled = clipping.init( this.clippingPlanes, _localClippingEnabled, camera );
  14452. currentRenderList = renderLists.get( scene, camera );
  14453. currentRenderList.init();
  14454. projectObject( scene, camera, 0, _this.sortObjects );
  14455. currentRenderList.finish();
  14456. if ( _this.sortObjects === true ) {
  14457. currentRenderList.sort( _opaqueSort, _transparentSort );
  14458. }
  14459. //
  14460. if ( _clippingEnabled === true ) clipping.beginShadows();
  14461. const shadowsArray = currentRenderState.state.shadowsArray;
  14462. shadowMap.render( shadowsArray, scene, camera );
  14463. currentRenderState.setupLights();
  14464. currentRenderState.setupLightsView( camera );
  14465. if ( _clippingEnabled === true ) clipping.endShadows();
  14466. //
  14467. if ( this.info.autoReset === true ) this.info.reset();
  14468. if ( renderTarget !== undefined ) {
  14469. this.setRenderTarget( renderTarget );
  14470. }
  14471. //
  14472. background.render( currentRenderList, scene, camera, forceClear );
  14473. // render scene
  14474. const opaqueObjects = currentRenderList.opaque;
  14475. const transparentObjects = currentRenderList.transparent;
  14476. if ( opaqueObjects.length > 0 ) renderObjects( opaqueObjects, scene, camera );
  14477. if ( transparentObjects.length > 0 ) renderObjects( transparentObjects, scene, camera );
  14478. //
  14479. if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
  14480. //
  14481. if ( _currentRenderTarget !== null ) {
  14482. // Generate mipmap if we're using any kind of mipmap filtering
  14483. textures.updateRenderTargetMipmap( _currentRenderTarget );
  14484. // resolve multisample renderbuffers to a single-sample texture if necessary
  14485. textures.updateMultisampleRenderTarget( _currentRenderTarget );
  14486. }
  14487. // Ensure depth buffer writing is enabled so it can be cleared on next render
  14488. state.buffers.depth.setTest( true );
  14489. state.buffers.depth.setMask( true );
  14490. state.buffers.color.setMask( true );
  14491. state.setPolygonOffset( false );
  14492. // _gl.finish();
  14493. renderStateStack.pop();
  14494. if ( renderStateStack.length > 0 ) {
  14495. currentRenderState = renderStateStack[ renderStateStack.length - 1 ];
  14496. } else {
  14497. currentRenderState = null;
  14498. }
  14499. currentRenderList = null;
  14500. };
  14501. function projectObject( object, camera, groupOrder, sortObjects ) {
  14502. if ( object.visible === false ) return;
  14503. const visible = object.layers.test( camera.layers );
  14504. if ( visible ) {
  14505. if ( object.isGroup ) {
  14506. groupOrder = object.renderOrder;
  14507. } else if ( object.isLOD ) {
  14508. if ( object.autoUpdate === true ) object.update( camera );
  14509. } else if ( object.isLight ) {
  14510. currentRenderState.pushLight( object );
  14511. if ( object.castShadow ) {
  14512. currentRenderState.pushShadow( object );
  14513. }
  14514. } else if ( object.isSprite ) {
  14515. if ( ! object.frustumCulled || _frustum.intersectsSprite( object ) ) {
  14516. if ( sortObjects ) {
  14517. _vector3.setFromMatrixPosition( object.matrixWorld )
  14518. .applyMatrix4( _projScreenMatrix );
  14519. }
  14520. const geometry = objects.update( object );
  14521. const material = object.material;
  14522. if ( material.visible ) {
  14523. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14524. }
  14525. }
  14526. } else if ( object.isImmediateRenderObject ) {
  14527. if ( sortObjects ) {
  14528. _vector3.setFromMatrixPosition( object.matrixWorld )
  14529. .applyMatrix4( _projScreenMatrix );
  14530. }
  14531. currentRenderList.push( object, null, object.material, groupOrder, _vector3.z, null );
  14532. } else if ( object.isMesh || object.isLine || object.isPoints ) {
  14533. if ( object.isSkinnedMesh ) {
  14534. // update skeleton only once in a frame
  14535. if ( object.skeleton.frame !== info.render.frame ) {
  14536. object.skeleton.update();
  14537. object.skeleton.frame = info.render.frame;
  14538. }
  14539. }
  14540. if ( ! object.frustumCulled || _frustum.intersectsObject( object ) ) {
  14541. if ( sortObjects ) {
  14542. _vector3.setFromMatrixPosition( object.matrixWorld )
  14543. .applyMatrix4( _projScreenMatrix );
  14544. }
  14545. const geometry = objects.update( object );
  14546. const material = object.material;
  14547. if ( Array.isArray( material ) ) {
  14548. const groups = geometry.groups;
  14549. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  14550. const group = groups[ i ];
  14551. const groupMaterial = material[ group.materialIndex ];
  14552. if ( groupMaterial && groupMaterial.visible ) {
  14553. currentRenderList.push( object, geometry, groupMaterial, groupOrder, _vector3.z, group );
  14554. }
  14555. }
  14556. } else if ( material.visible ) {
  14557. currentRenderList.push( object, geometry, material, groupOrder, _vector3.z, null );
  14558. }
  14559. }
  14560. }
  14561. }
  14562. const children = object.children;
  14563. for ( let i = 0, l = children.length; i < l; i ++ ) {
  14564. projectObject( children[ i ], camera, groupOrder, sortObjects );
  14565. }
  14566. }
  14567. function renderObjects( renderList, scene, camera ) {
  14568. const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
  14569. for ( let i = 0, l = renderList.length; i < l; i ++ ) {
  14570. const renderItem = renderList[ i ];
  14571. const object = renderItem.object;
  14572. const geometry = renderItem.geometry;
  14573. const material = overrideMaterial === null ? renderItem.material : overrideMaterial;
  14574. const group = renderItem.group;
  14575. if ( camera.isArrayCamera ) {
  14576. const cameras = camera.cameras;
  14577. for ( let j = 0, jl = cameras.length; j < jl; j ++ ) {
  14578. const camera2 = cameras[ j ];
  14579. if ( object.layers.test( camera2.layers ) ) {
  14580. state.viewport( _currentViewport.copy( camera2.viewport ) );
  14581. currentRenderState.setupLightsView( camera2 );
  14582. renderObject( object, scene, camera2, geometry, material, group );
  14583. }
  14584. }
  14585. } else {
  14586. renderObject( object, scene, camera, geometry, material, group );
  14587. }
  14588. }
  14589. }
  14590. function renderObject( object, scene, camera, geometry, material, group ) {
  14591. object.onBeforeRender( _this, scene, camera, geometry, material, group );
  14592. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14593. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  14594. if ( object.isImmediateRenderObject ) {
  14595. const program = setProgram( camera, scene, material, object );
  14596. state.setMaterial( material );
  14597. bindingStates.reset();
  14598. renderObjectImmediate( object, program );
  14599. } else {
  14600. _this.renderBufferDirect( camera, scene, geometry, material, object, group );
  14601. }
  14602. object.onAfterRender( _this, scene, camera, geometry, material, group );
  14603. }
  14604. function initMaterial( material, scene, object ) {
  14605. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14606. const materialProperties = properties.get( material );
  14607. const lights = currentRenderState.state.lights;
  14608. const shadowsArray = currentRenderState.state.shadowsArray;
  14609. const lightsStateVersion = lights.state.version;
  14610. const parameters = programCache.getParameters( material, lights.state, shadowsArray, scene, object );
  14611. const programCacheKey = programCache.getProgramCacheKey( parameters );
  14612. let program = materialProperties.program;
  14613. let programChange = true;
  14614. if ( program === undefined ) {
  14615. // new material
  14616. material.addEventListener( 'dispose', onMaterialDispose );
  14617. } else if ( program.cacheKey !== programCacheKey ) {
  14618. // changed glsl or parameters
  14619. releaseMaterialProgramReference( material );
  14620. } else if ( materialProperties.lightsStateVersion !== lightsStateVersion ) {
  14621. programChange = false;
  14622. } else if ( parameters.shaderID !== undefined ) {
  14623. // same glsl and uniform list, envMap still needs the update here to avoid a frame-late effect
  14624. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  14625. materialProperties.envMap = cubemaps.get( material.envMap || environment );
  14626. return;
  14627. } else {
  14628. // only rebuild uniform list
  14629. programChange = false;
  14630. }
  14631. if ( programChange ) {
  14632. parameters.uniforms = programCache.getUniforms( material );
  14633. material.onBeforeCompile( parameters, _this );
  14634. program = programCache.acquireProgram( parameters, programCacheKey );
  14635. materialProperties.program = program;
  14636. materialProperties.uniforms = parameters.uniforms;
  14637. materialProperties.outputEncoding = parameters.outputEncoding;
  14638. }
  14639. const uniforms = materialProperties.uniforms;
  14640. if ( ! material.isShaderMaterial &&
  14641. ! material.isRawShaderMaterial ||
  14642. material.clipping === true ) {
  14643. materialProperties.numClippingPlanes = clipping.numPlanes;
  14644. materialProperties.numIntersection = clipping.numIntersection;
  14645. uniforms.clippingPlanes = clipping.uniform;
  14646. }
  14647. materialProperties.environment = material.isMeshStandardMaterial ? scene.environment : null;
  14648. materialProperties.fog = scene.fog;
  14649. materialProperties.envMap = cubemaps.get( material.envMap || materialProperties.environment );
  14650. // store the light setup it was created for
  14651. materialProperties.needsLights = materialNeedsLights( material );
  14652. materialProperties.lightsStateVersion = lightsStateVersion;
  14653. if ( materialProperties.needsLights ) {
  14654. // wire up the material to this renderer's lighting state
  14655. uniforms.ambientLightColor.value = lights.state.ambient;
  14656. uniforms.lightProbe.value = lights.state.probe;
  14657. uniforms.directionalLights.value = lights.state.directional;
  14658. uniforms.directionalLightShadows.value = lights.state.directionalShadow;
  14659. uniforms.spotLights.value = lights.state.spot;
  14660. uniforms.spotLightShadows.value = lights.state.spotShadow;
  14661. uniforms.rectAreaLights.value = lights.state.rectArea;
  14662. uniforms.ltc_1.value = lights.state.rectAreaLTC1;
  14663. uniforms.ltc_2.value = lights.state.rectAreaLTC2;
  14664. uniforms.pointLights.value = lights.state.point;
  14665. uniforms.pointLightShadows.value = lights.state.pointShadow;
  14666. uniforms.hemisphereLights.value = lights.state.hemi;
  14667. uniforms.directionalShadowMap.value = lights.state.directionalShadowMap;
  14668. uniforms.directionalShadowMatrix.value = lights.state.directionalShadowMatrix;
  14669. uniforms.spotShadowMap.value = lights.state.spotShadowMap;
  14670. uniforms.spotShadowMatrix.value = lights.state.spotShadowMatrix;
  14671. uniforms.pointShadowMap.value = lights.state.pointShadowMap;
  14672. uniforms.pointShadowMatrix.value = lights.state.pointShadowMatrix;
  14673. // TODO (abelnation): add area lights shadow info to uniforms
  14674. }
  14675. const progUniforms = materialProperties.program.getUniforms();
  14676. const uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
  14677. materialProperties.uniformsList = uniformsList;
  14678. }
  14679. function setProgram( camera, scene, material, object ) {
  14680. if ( scene.isScene !== true ) scene = _emptyScene; // scene could be a Mesh, Line, Points, ...
  14681. textures.resetTextureUnits();
  14682. const fog = scene.fog;
  14683. const environment = material.isMeshStandardMaterial ? scene.environment : null;
  14684. const encoding = ( _currentRenderTarget === null ) ? _this.outputEncoding : _currentRenderTarget.texture.encoding;
  14685. const envMap = cubemaps.get( material.envMap || environment );
  14686. const materialProperties = properties.get( material );
  14687. const lights = currentRenderState.state.lights;
  14688. if ( _clippingEnabled === true ) {
  14689. if ( _localClippingEnabled === true || camera !== _currentCamera ) {
  14690. const useCache =
  14691. camera === _currentCamera &&
  14692. material.id === _currentMaterialId;
  14693. // we might want to call this function with some ClippingGroup
  14694. // object instead of the material, once it becomes feasible
  14695. // (#8465, #8379)
  14696. clipping.setState( material, camera, useCache );
  14697. }
  14698. }
  14699. if ( material.version === materialProperties.__version ) {
  14700. if ( material.fog && materialProperties.fog !== fog ) {
  14701. initMaterial( material, scene, object );
  14702. } else if ( materialProperties.environment !== environment ) {
  14703. initMaterial( material, scene, object );
  14704. } else if ( materialProperties.needsLights && ( materialProperties.lightsStateVersion !== lights.state.version ) ) {
  14705. initMaterial( material, scene, object );
  14706. } else if ( materialProperties.numClippingPlanes !== undefined &&
  14707. ( materialProperties.numClippingPlanes !== clipping.numPlanes ||
  14708. materialProperties.numIntersection !== clipping.numIntersection ) ) {
  14709. initMaterial( material, scene, object );
  14710. } else if ( materialProperties.outputEncoding !== encoding ) {
  14711. initMaterial( material, scene, object );
  14712. } else if ( materialProperties.envMap !== envMap ) {
  14713. initMaterial( material, scene, object );
  14714. }
  14715. } else {
  14716. initMaterial( material, scene, object );
  14717. materialProperties.__version = material.version;
  14718. }
  14719. let refreshProgram = false;
  14720. let refreshMaterial = false;
  14721. let refreshLights = false;
  14722. const program = materialProperties.program,
  14723. p_uniforms = program.getUniforms(),
  14724. m_uniforms = materialProperties.uniforms;
  14725. if ( state.useProgram( program.program ) ) {
  14726. refreshProgram = true;
  14727. refreshMaterial = true;
  14728. refreshLights = true;
  14729. }
  14730. if ( material.id !== _currentMaterialId ) {
  14731. _currentMaterialId = material.id;
  14732. refreshMaterial = true;
  14733. }
  14734. if ( refreshProgram || _currentCamera !== camera ) {
  14735. p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
  14736. if ( capabilities.logarithmicDepthBuffer ) {
  14737. p_uniforms.setValue( _gl, 'logDepthBufFC',
  14738. 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  14739. }
  14740. if ( _currentCamera !== camera ) {
  14741. _currentCamera = camera;
  14742. // lighting uniforms depend on the camera so enforce an update
  14743. // now, in case this material supports lights - or later, when
  14744. // the next material that does gets activated:
  14745. refreshMaterial = true; // set to true on material change
  14746. refreshLights = true; // remains set until update done
  14747. }
  14748. // load material specific uniforms
  14749. // (shader material also gets them for the sake of genericity)
  14750. if ( material.isShaderMaterial ||
  14751. material.isMeshPhongMaterial ||
  14752. material.isMeshToonMaterial ||
  14753. material.isMeshStandardMaterial ||
  14754. material.envMap ) {
  14755. const uCamPos = p_uniforms.map.cameraPosition;
  14756. if ( uCamPos !== undefined ) {
  14757. uCamPos.setValue( _gl,
  14758. _vector3.setFromMatrixPosition( camera.matrixWorld ) );
  14759. }
  14760. }
  14761. if ( material.isMeshPhongMaterial ||
  14762. material.isMeshToonMaterial ||
  14763. material.isMeshLambertMaterial ||
  14764. material.isMeshBasicMaterial ||
  14765. material.isMeshStandardMaterial ||
  14766. material.isShaderMaterial ) {
  14767. p_uniforms.setValue( _gl, 'isOrthographic', camera.isOrthographicCamera === true );
  14768. }
  14769. if ( material.isMeshPhongMaterial ||
  14770. material.isMeshToonMaterial ||
  14771. material.isMeshLambertMaterial ||
  14772. material.isMeshBasicMaterial ||
  14773. material.isMeshStandardMaterial ||
  14774. material.isShaderMaterial ||
  14775. material.isShadowMaterial ||
  14776. material.skinning ) {
  14777. p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
  14778. }
  14779. }
  14780. // skinning uniforms must be set even if material didn't change
  14781. // auto-setting of texture unit for bone texture must go before other textures
  14782. // otherwise textures used for skinning can take over texture units reserved for other material textures
  14783. if ( material.skinning ) {
  14784. p_uniforms.setOptional( _gl, object, 'bindMatrix' );
  14785. p_uniforms.setOptional( _gl, object, 'bindMatrixInverse' );
  14786. const skeleton = object.skeleton;
  14787. if ( skeleton ) {
  14788. const bones = skeleton.bones;
  14789. if ( capabilities.floatVertexTextures ) {
  14790. if ( skeleton.boneTexture === null ) {
  14791. // layout (1 matrix = 4 pixels)
  14792. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  14793. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  14794. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  14795. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  14796. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  14797. let size = Math.sqrt( bones.length * 4 ); // 4 pixels needed for 1 matrix
  14798. size = MathUtils.ceilPowerOfTwo( size );
  14799. size = Math.max( size, 4 );
  14800. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  14801. boneMatrices.set( skeleton.boneMatrices ); // copy current values
  14802. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  14803. skeleton.boneMatrices = boneMatrices;
  14804. skeleton.boneTexture = boneTexture;
  14805. skeleton.boneTextureSize = size;
  14806. }
  14807. p_uniforms.setValue( _gl, 'boneTexture', skeleton.boneTexture, textures );
  14808. p_uniforms.setValue( _gl, 'boneTextureSize', skeleton.boneTextureSize );
  14809. } else {
  14810. p_uniforms.setOptional( _gl, skeleton, 'boneMatrices' );
  14811. }
  14812. }
  14813. }
  14814. if ( refreshMaterial || materialProperties.receiveShadow !== object.receiveShadow ) {
  14815. materialProperties.receiveShadow = object.receiveShadow;
  14816. p_uniforms.setValue( _gl, 'receiveShadow', object.receiveShadow );
  14817. }
  14818. if ( refreshMaterial ) {
  14819. p_uniforms.setValue( _gl, 'toneMappingExposure', _this.toneMappingExposure );
  14820. if ( materialProperties.needsLights ) {
  14821. // the current material requires lighting info
  14822. // note: all lighting uniforms are always set correctly
  14823. // they simply reference the renderer's state for their
  14824. // values
  14825. //
  14826. // use the current material's .needsUpdate flags to set
  14827. // the GL state when required
  14828. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  14829. }
  14830. // refresh uniforms common to several materials
  14831. if ( fog && material.fog ) {
  14832. materials.refreshFogUniforms( m_uniforms, fog );
  14833. }
  14834. materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height );
  14835. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14836. }
  14837. if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
  14838. WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
  14839. material.uniformsNeedUpdate = false;
  14840. }
  14841. if ( material.isSpriteMaterial ) {
  14842. p_uniforms.setValue( _gl, 'center', object.center );
  14843. }
  14844. // common matrices
  14845. p_uniforms.setValue( _gl, 'modelViewMatrix', object.modelViewMatrix );
  14846. p_uniforms.setValue( _gl, 'normalMatrix', object.normalMatrix );
  14847. p_uniforms.setValue( _gl, 'modelMatrix', object.matrixWorld );
  14848. return program;
  14849. }
  14850. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  14851. function markUniformsLightsNeedsUpdate( uniforms, value ) {
  14852. uniforms.ambientLightColor.needsUpdate = value;
  14853. uniforms.lightProbe.needsUpdate = value;
  14854. uniforms.directionalLights.needsUpdate = value;
  14855. uniforms.directionalLightShadows.needsUpdate = value;
  14856. uniforms.pointLights.needsUpdate = value;
  14857. uniforms.pointLightShadows.needsUpdate = value;
  14858. uniforms.spotLights.needsUpdate = value;
  14859. uniforms.spotLightShadows.needsUpdate = value;
  14860. uniforms.rectAreaLights.needsUpdate = value;
  14861. uniforms.hemisphereLights.needsUpdate = value;
  14862. }
  14863. function materialNeedsLights( material ) {
  14864. return material.isMeshLambertMaterial || material.isMeshToonMaterial || material.isMeshPhongMaterial ||
  14865. material.isMeshStandardMaterial || material.isShadowMaterial ||
  14866. ( material.isShaderMaterial && material.lights === true );
  14867. }
  14868. //
  14869. this.setFramebuffer = function ( value ) {
  14870. if ( _framebuffer !== value && _currentRenderTarget === null ) _gl.bindFramebuffer( 36160, value );
  14871. _framebuffer = value;
  14872. };
  14873. this.getActiveCubeFace = function () {
  14874. return _currentActiveCubeFace;
  14875. };
  14876. this.getActiveMipmapLevel = function () {
  14877. return _currentActiveMipmapLevel;
  14878. };
  14879. this.getRenderList = function () {
  14880. return currentRenderList;
  14881. };
  14882. this.setRenderList = function ( renderList ) {
  14883. currentRenderList = renderList;
  14884. };
  14885. this.getRenderTarget = function () {
  14886. return _currentRenderTarget;
  14887. };
  14888. this.setRenderTarget = function ( renderTarget, activeCubeFace = 0, activeMipmapLevel = 0 ) {
  14889. _currentRenderTarget = renderTarget;
  14890. _currentActiveCubeFace = activeCubeFace;
  14891. _currentActiveMipmapLevel = activeMipmapLevel;
  14892. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14893. textures.setupRenderTarget( renderTarget );
  14894. }
  14895. let framebuffer = _framebuffer;
  14896. let isCube = false;
  14897. if ( renderTarget ) {
  14898. const __webglFramebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14899. if ( renderTarget.isWebGLCubeRenderTarget ) {
  14900. framebuffer = __webglFramebuffer[ activeCubeFace ];
  14901. isCube = true;
  14902. } else if ( renderTarget.isWebGLMultisampleRenderTarget ) {
  14903. framebuffer = properties.get( renderTarget ).__webglMultisampledFramebuffer;
  14904. } else {
  14905. framebuffer = __webglFramebuffer;
  14906. }
  14907. _currentViewport.copy( renderTarget.viewport );
  14908. _currentScissor.copy( renderTarget.scissor );
  14909. _currentScissorTest = renderTarget.scissorTest;
  14910. } else {
  14911. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor();
  14912. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor();
  14913. _currentScissorTest = _scissorTest;
  14914. }
  14915. if ( _currentFramebuffer !== framebuffer ) {
  14916. _gl.bindFramebuffer( 36160, framebuffer );
  14917. _currentFramebuffer = framebuffer;
  14918. }
  14919. state.viewport( _currentViewport );
  14920. state.scissor( _currentScissor );
  14921. state.setScissorTest( _currentScissorTest );
  14922. if ( isCube ) {
  14923. const textureProperties = properties.get( renderTarget.texture );
  14924. _gl.framebufferTexture2D( 36160, 36064, 34069 + activeCubeFace, textureProperties.__webglTexture, activeMipmapLevel );
  14925. }
  14926. };
  14927. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer, activeCubeFaceIndex ) {
  14928. if ( ! ( renderTarget && renderTarget.isWebGLRenderTarget ) ) {
  14929. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14930. return;
  14931. }
  14932. let framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14933. if ( renderTarget.isWebGLCubeRenderTarget && activeCubeFaceIndex !== undefined ) {
  14934. framebuffer = framebuffer[ activeCubeFaceIndex ];
  14935. }
  14936. if ( framebuffer ) {
  14937. let restore = false;
  14938. if ( framebuffer !== _currentFramebuffer ) {
  14939. _gl.bindFramebuffer( 36160, framebuffer );
  14940. restore = true;
  14941. }
  14942. try {
  14943. const texture = renderTarget.texture;
  14944. const textureFormat = texture.format;
  14945. const textureType = texture.type;
  14946. if ( textureFormat !== RGBAFormat && utils.convert( textureFormat ) !== _gl.getParameter( 35739 ) ) {
  14947. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14948. return;
  14949. }
  14950. if ( textureType !== UnsignedByteType && utils.convert( textureType ) !== _gl.getParameter( 35738 ) && // IE11, Edge and Chrome Mac < 52 (#9513)
  14951. ! ( textureType === FloatType && ( capabilities.isWebGL2 || extensions.get( 'OES_texture_float' ) || extensions.get( 'WEBGL_color_buffer_float' ) ) ) && // Chrome Mac >= 52 and Firefox
  14952. ! ( textureType === HalfFloatType && ( capabilities.isWebGL2 ? extensions.get( 'EXT_color_buffer_float' ) : extensions.get( 'EXT_color_buffer_half_float' ) ) ) ) {
  14953. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14954. return;
  14955. }
  14956. if ( _gl.checkFramebufferStatus( 36160 ) === 36053 ) {
  14957. // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
  14958. if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
  14959. _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), buffer );
  14960. }
  14961. } else {
  14962. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14963. }
  14964. } finally {
  14965. if ( restore ) {
  14966. _gl.bindFramebuffer( 36160, _currentFramebuffer );
  14967. }
  14968. }
  14969. }
  14970. };
  14971. this.copyFramebufferToTexture = function ( position, texture, level = 0 ) {
  14972. const levelScale = Math.pow( 2, - level );
  14973. const width = Math.floor( texture.image.width * levelScale );
  14974. const height = Math.floor( texture.image.height * levelScale );
  14975. const glFormat = utils.convert( texture.format );
  14976. textures.setTexture2D( texture, 0 );
  14977. _gl.copyTexImage2D( 3553, level, glFormat, position.x, position.y, width, height, 0 );
  14978. state.unbindTexture();
  14979. };
  14980. this.copyTextureToTexture = function ( position, srcTexture, dstTexture, level = 0 ) {
  14981. const width = srcTexture.image.width;
  14982. const height = srcTexture.image.height;
  14983. const glFormat = utils.convert( dstTexture.format );
  14984. const glType = utils.convert( dstTexture.type );
  14985. textures.setTexture2D( dstTexture, 0 );
  14986. // As another texture upload may have changed pixelStorei
  14987. // parameters, make sure they are correct for the dstTexture
  14988. _gl.pixelStorei( 37440, dstTexture.flipY );
  14989. _gl.pixelStorei( 37441, dstTexture.premultiplyAlpha );
  14990. _gl.pixelStorei( 3317, dstTexture.unpackAlignment );
  14991. if ( srcTexture.isDataTexture ) {
  14992. _gl.texSubImage2D( 3553, level, position.x, position.y, width, height, glFormat, glType, srcTexture.image.data );
  14993. } else {
  14994. if ( srcTexture.isCompressedTexture ) {
  14995. _gl.compressedTexSubImage2D( 3553, level, position.x, position.y, srcTexture.mipmaps[ 0 ].width, srcTexture.mipmaps[ 0 ].height, glFormat, srcTexture.mipmaps[ 0 ].data );
  14996. } else {
  14997. _gl.texSubImage2D( 3553, level, position.x, position.y, glFormat, glType, srcTexture.image );
  14998. }
  14999. }
  15000. // Generate mipmaps only when copying level 0
  15001. if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( 3553 );
  15002. state.unbindTexture();
  15003. };
  15004. this.initTexture = function ( texture ) {
  15005. textures.setTexture2D( texture, 0 );
  15006. state.unbindTexture();
  15007. };
  15008. this.resetState = function () {
  15009. state.reset();
  15010. bindingStates.reset();
  15011. };
  15012. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15013. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15014. }
  15015. }
  15016. function WebGL1Renderer( parameters ) {
  15017. WebGLRenderer.call( this, parameters );
  15018. }
  15019. WebGL1Renderer.prototype = Object.assign( Object.create( WebGLRenderer.prototype ), {
  15020. constructor: WebGL1Renderer,
  15021. isWebGL1Renderer: true
  15022. } );
  15023. class FogExp2 {
  15024. constructor( color, density ) {
  15025. Object.defineProperty( this, 'isFogExp2', { value: true } );
  15026. this.name = '';
  15027. this.color = new Color( color );
  15028. this.density = ( density !== undefined ) ? density : 0.00025;
  15029. }
  15030. clone() {
  15031. return new FogExp2( this.color, this.density );
  15032. }
  15033. toJSON( /* meta */ ) {
  15034. return {
  15035. type: 'FogExp2',
  15036. color: this.color.getHex(),
  15037. density: this.density
  15038. };
  15039. }
  15040. }
  15041. class Fog {
  15042. constructor( color, near, far ) {
  15043. Object.defineProperty( this, 'isFog', { value: true } );
  15044. this.name = '';
  15045. this.color = new Color( color );
  15046. this.near = ( near !== undefined ) ? near : 1;
  15047. this.far = ( far !== undefined ) ? far : 1000;
  15048. }
  15049. clone() {
  15050. return new Fog( this.color, this.near, this.far );
  15051. }
  15052. toJSON( /* meta */ ) {
  15053. return {
  15054. type: 'Fog',
  15055. color: this.color.getHex(),
  15056. near: this.near,
  15057. far: this.far
  15058. };
  15059. }
  15060. }
  15061. class Scene extends Object3D {
  15062. constructor() {
  15063. super();
  15064. Object.defineProperty( this, 'isScene', { value: true } );
  15065. this.type = 'Scene';
  15066. this.background = null;
  15067. this.environment = null;
  15068. this.fog = null;
  15069. this.overrideMaterial = null;
  15070. this.autoUpdate = true; // checked by the renderer
  15071. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  15072. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
  15073. }
  15074. }
  15075. copy( source, recursive ) {
  15076. super.copy( source, recursive );
  15077. if ( source.background !== null ) this.background = source.background.clone();
  15078. if ( source.environment !== null ) this.environment = source.environment.clone();
  15079. if ( source.fog !== null ) this.fog = source.fog.clone();
  15080. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  15081. this.autoUpdate = source.autoUpdate;
  15082. this.matrixAutoUpdate = source.matrixAutoUpdate;
  15083. return this;
  15084. }
  15085. toJSON( meta ) {
  15086. const data = super.toJSON( meta );
  15087. if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
  15088. if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
  15089. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  15090. return data;
  15091. }
  15092. }
  15093. function InterleavedBuffer( array, stride ) {
  15094. this.array = array;
  15095. this.stride = stride;
  15096. this.count = array !== undefined ? array.length / stride : 0;
  15097. this.usage = StaticDrawUsage;
  15098. this.updateRange = { offset: 0, count: - 1 };
  15099. this.version = 0;
  15100. this.uuid = MathUtils.generateUUID();
  15101. }
  15102. Object.defineProperty( InterleavedBuffer.prototype, 'needsUpdate', {
  15103. set: function ( value ) {
  15104. if ( value === true ) this.version ++;
  15105. }
  15106. } );
  15107. Object.assign( InterleavedBuffer.prototype, {
  15108. isInterleavedBuffer: true,
  15109. onUploadCallback: function () {},
  15110. setUsage: function ( value ) {
  15111. this.usage = value;
  15112. return this;
  15113. },
  15114. copy: function ( source ) {
  15115. this.array = new source.array.constructor( source.array );
  15116. this.count = source.count;
  15117. this.stride = source.stride;
  15118. this.usage = source.usage;
  15119. return this;
  15120. },
  15121. copyAt: function ( index1, attribute, index2 ) {
  15122. index1 *= this.stride;
  15123. index2 *= attribute.stride;
  15124. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  15125. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  15126. }
  15127. return this;
  15128. },
  15129. set: function ( value, offset = 0 ) {
  15130. this.array.set( value, offset );
  15131. return this;
  15132. },
  15133. clone: function ( data ) {
  15134. if ( data.arrayBuffers === undefined ) {
  15135. data.arrayBuffers = {};
  15136. }
  15137. if ( this.array.buffer._uuid === undefined ) {
  15138. this.array.buffer._uuid = MathUtils.generateUUID();
  15139. }
  15140. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  15141. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  15142. }
  15143. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  15144. const ib = new InterleavedBuffer( array, this.stride );
  15145. ib.setUsage( this.usage );
  15146. return ib;
  15147. },
  15148. onUpload: function ( callback ) {
  15149. this.onUploadCallback = callback;
  15150. return this;
  15151. },
  15152. toJSON: function ( data ) {
  15153. if ( data.arrayBuffers === undefined ) {
  15154. data.arrayBuffers = {};
  15155. }
  15156. // generate UUID for array buffer if necessary
  15157. if ( this.array.buffer._uuid === undefined ) {
  15158. this.array.buffer._uuid = MathUtils.generateUUID();
  15159. }
  15160. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  15161. data.arrayBuffers[ this.array.buffer._uuid ] = Array.prototype.slice.call( new Uint32Array( this.array.buffer ) );
  15162. }
  15163. //
  15164. return {
  15165. uuid: this.uuid,
  15166. buffer: this.array.buffer._uuid,
  15167. type: this.array.constructor.name,
  15168. stride: this.stride
  15169. };
  15170. }
  15171. } );
  15172. const _vector$6 = new Vector3();
  15173. function InterleavedBufferAttribute( interleavedBuffer, itemSize, offset, normalized ) {
  15174. this.name = '';
  15175. this.data = interleavedBuffer;
  15176. this.itemSize = itemSize;
  15177. this.offset = offset;
  15178. this.normalized = normalized === true;
  15179. }
  15180. Object.defineProperties( InterleavedBufferAttribute.prototype, {
  15181. count: {
  15182. get: function () {
  15183. return this.data.count;
  15184. }
  15185. },
  15186. array: {
  15187. get: function () {
  15188. return this.data.array;
  15189. }
  15190. },
  15191. needsUpdate: {
  15192. set: function ( value ) {
  15193. this.data.needsUpdate = value;
  15194. }
  15195. }
  15196. } );
  15197. Object.assign( InterleavedBufferAttribute.prototype, {
  15198. isInterleavedBufferAttribute: true,
  15199. applyMatrix4: function ( m ) {
  15200. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  15201. _vector$6.x = this.getX( i );
  15202. _vector$6.y = this.getY( i );
  15203. _vector$6.z = this.getZ( i );
  15204. _vector$6.applyMatrix4( m );
  15205. this.setXYZ( i, _vector$6.x, _vector$6.y, _vector$6.z );
  15206. }
  15207. return this;
  15208. },
  15209. setX: function ( index, x ) {
  15210. this.data.array[ index * this.data.stride + this.offset ] = x;
  15211. return this;
  15212. },
  15213. setY: function ( index, y ) {
  15214. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  15215. return this;
  15216. },
  15217. setZ: function ( index, z ) {
  15218. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  15219. return this;
  15220. },
  15221. setW: function ( index, w ) {
  15222. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  15223. return this;
  15224. },
  15225. getX: function ( index ) {
  15226. return this.data.array[ index * this.data.stride + this.offset ];
  15227. },
  15228. getY: function ( index ) {
  15229. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  15230. },
  15231. getZ: function ( index ) {
  15232. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  15233. },
  15234. getW: function ( index ) {
  15235. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  15236. },
  15237. setXY: function ( index, x, y ) {
  15238. index = index * this.data.stride + this.offset;
  15239. this.data.array[ index + 0 ] = x;
  15240. this.data.array[ index + 1 ] = y;
  15241. return this;
  15242. },
  15243. setXYZ: function ( index, x, y, z ) {
  15244. index = index * this.data.stride + this.offset;
  15245. this.data.array[ index + 0 ] = x;
  15246. this.data.array[ index + 1 ] = y;
  15247. this.data.array[ index + 2 ] = z;
  15248. return this;
  15249. },
  15250. setXYZW: function ( index, x, y, z, w ) {
  15251. index = index * this.data.stride + this.offset;
  15252. this.data.array[ index + 0 ] = x;
  15253. this.data.array[ index + 1 ] = y;
  15254. this.data.array[ index + 2 ] = z;
  15255. this.data.array[ index + 3 ] = w;
  15256. return this;
  15257. },
  15258. clone: function ( data ) {
  15259. if ( data === undefined ) {
  15260. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interlaved buffer attribute will deinterleave buffer data.' );
  15261. const array = [];
  15262. for ( let i = 0; i < this.count; i ++ ) {
  15263. const index = i * this.data.stride + this.offset;
  15264. for ( let j = 0; j < this.itemSize; j ++ ) {
  15265. array.push( this.data.array[ index + j ] );
  15266. }
  15267. }
  15268. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  15269. } else {
  15270. if ( data.interleavedBuffers === undefined ) {
  15271. data.interleavedBuffers = {};
  15272. }
  15273. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  15274. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  15275. }
  15276. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  15277. }
  15278. },
  15279. toJSON: function ( data ) {
  15280. if ( data === undefined ) {
  15281. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interlaved buffer attribute will deinterleave buffer data.' );
  15282. const array = [];
  15283. for ( let i = 0; i < this.count; i ++ ) {
  15284. const index = i * this.data.stride + this.offset;
  15285. for ( let j = 0; j < this.itemSize; j ++ ) {
  15286. array.push( this.data.array[ index + j ] );
  15287. }
  15288. }
  15289. // deinterleave data and save it as an ordinary buffer attribute for now
  15290. return {
  15291. itemSize: this.itemSize,
  15292. type: this.array.constructor.name,
  15293. array: array,
  15294. normalized: this.normalized
  15295. };
  15296. } else {
  15297. // save as true interlaved attribtue
  15298. if ( data.interleavedBuffers === undefined ) {
  15299. data.interleavedBuffers = {};
  15300. }
  15301. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  15302. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  15303. }
  15304. return {
  15305. isInterleavedBufferAttribute: true,
  15306. itemSize: this.itemSize,
  15307. data: this.data.uuid,
  15308. offset: this.offset,
  15309. normalized: this.normalized
  15310. };
  15311. }
  15312. }
  15313. } );
  15314. /**
  15315. * parameters = {
  15316. * color: <hex>,
  15317. * map: new THREE.Texture( <Image> ),
  15318. * alphaMap: new THREE.Texture( <Image> ),
  15319. * rotation: <float>,
  15320. * sizeAttenuation: <bool>
  15321. * }
  15322. */
  15323. function SpriteMaterial( parameters ) {
  15324. Material.call( this );
  15325. this.type = 'SpriteMaterial';
  15326. this.color = new Color( 0xffffff );
  15327. this.map = null;
  15328. this.alphaMap = null;
  15329. this.rotation = 0;
  15330. this.sizeAttenuation = true;
  15331. this.transparent = true;
  15332. this.setValues( parameters );
  15333. }
  15334. SpriteMaterial.prototype = Object.create( Material.prototype );
  15335. SpriteMaterial.prototype.constructor = SpriteMaterial;
  15336. SpriteMaterial.prototype.isSpriteMaterial = true;
  15337. SpriteMaterial.prototype.copy = function ( source ) {
  15338. Material.prototype.copy.call( this, source );
  15339. this.color.copy( source.color );
  15340. this.map = source.map;
  15341. this.alphaMap = source.alphaMap;
  15342. this.rotation = source.rotation;
  15343. this.sizeAttenuation = source.sizeAttenuation;
  15344. return this;
  15345. };
  15346. let _geometry;
  15347. const _intersectPoint = new Vector3();
  15348. const _worldScale = new Vector3();
  15349. const _mvPosition = new Vector3();
  15350. const _alignedPosition = new Vector2();
  15351. const _rotatedPosition = new Vector2();
  15352. const _viewWorldMatrix = new Matrix4();
  15353. const _vA$1 = new Vector3();
  15354. const _vB$1 = new Vector3();
  15355. const _vC$1 = new Vector3();
  15356. const _uvA$1 = new Vector2();
  15357. const _uvB$1 = new Vector2();
  15358. const _uvC$1 = new Vector2();
  15359. function Sprite$1( material ) {
  15360. Object3D.call( this );
  15361. this.type = 'Sprite';
  15362. if ( _geometry === undefined ) {
  15363. _geometry = new BufferGeometry();
  15364. const float32Array = new Float32Array( [
  15365. - 0.5, - 0.5, 0, 0, 0,
  15366. 0.5, - 0.5, 0, 1, 0,
  15367. 0.5, 0.5, 0, 1, 1,
  15368. - 0.5, 0.5, 0, 0, 1
  15369. ] );
  15370. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  15371. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  15372. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  15373. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  15374. }
  15375. this.geometry = _geometry;
  15376. this.material = ( material !== undefined ) ? material : new SpriteMaterial();
  15377. this.center = new Vector2( 0.5, 0.5 );
  15378. }
  15379. Sprite$1.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15380. constructor: Sprite$1,
  15381. isSprite: true,
  15382. raycast: function ( raycaster, intersects ) {
  15383. if ( raycaster.camera === null ) {
  15384. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  15385. }
  15386. _worldScale.setFromMatrixScale( this.matrixWorld );
  15387. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  15388. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  15389. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  15390. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  15391. _worldScale.multiplyScalar( - _mvPosition.z );
  15392. }
  15393. const rotation = this.material.rotation;
  15394. let sin, cos;
  15395. if ( rotation !== 0 ) {
  15396. cos = Math.cos( rotation );
  15397. sin = Math.sin( rotation );
  15398. }
  15399. const center = this.center;
  15400. transformVertex( _vA$1.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15401. transformVertex( _vB$1.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15402. transformVertex( _vC$1.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15403. _uvA$1.set( 0, 0 );
  15404. _uvB$1.set( 1, 0 );
  15405. _uvC$1.set( 1, 1 );
  15406. // check first triangle
  15407. let intersect = raycaster.ray.intersectTriangle( _vA$1, _vB$1, _vC$1, false, _intersectPoint );
  15408. if ( intersect === null ) {
  15409. // check second triangle
  15410. transformVertex( _vB$1.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  15411. _uvB$1.set( 0, 1 );
  15412. intersect = raycaster.ray.intersectTriangle( _vA$1, _vC$1, _vB$1, false, _intersectPoint );
  15413. if ( intersect === null ) {
  15414. return;
  15415. }
  15416. }
  15417. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  15418. if ( distance < raycaster.near || distance > raycaster.far ) return;
  15419. intersects.push( {
  15420. distance: distance,
  15421. point: _intersectPoint.clone(),
  15422. uv: Triangle.getUV( _intersectPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() ),
  15423. face: null,
  15424. object: this
  15425. } );
  15426. },
  15427. copy: function ( source ) {
  15428. Object3D.prototype.copy.call( this, source );
  15429. if ( source.center !== undefined ) this.center.copy( source.center );
  15430. this.material = source.material;
  15431. return this;
  15432. }
  15433. } );
  15434. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  15435. // compute position in camera space
  15436. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  15437. // to check if rotation is not zero
  15438. if ( sin !== undefined ) {
  15439. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  15440. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  15441. } else {
  15442. _rotatedPosition.copy( _alignedPosition );
  15443. }
  15444. vertexPosition.copy( mvPosition );
  15445. vertexPosition.x += _rotatedPosition.x;
  15446. vertexPosition.y += _rotatedPosition.y;
  15447. // transform to world space
  15448. vertexPosition.applyMatrix4( _viewWorldMatrix );
  15449. }
  15450. const _v1$4 = new Vector3();
  15451. const _v2$2 = new Vector3();
  15452. function LOD() {
  15453. Object3D.call( this );
  15454. this._currentLevel = 0;
  15455. this.type = 'LOD';
  15456. Object.defineProperties( this, {
  15457. levels: {
  15458. enumerable: true,
  15459. value: []
  15460. }
  15461. } );
  15462. this.autoUpdate = true;
  15463. }
  15464. LOD.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15465. constructor: LOD,
  15466. isLOD: true,
  15467. copy: function ( source ) {
  15468. Object3D.prototype.copy.call( this, source, false );
  15469. const levels = source.levels;
  15470. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  15471. const level = levels[ i ];
  15472. this.addLevel( level.object.clone(), level.distance );
  15473. }
  15474. this.autoUpdate = source.autoUpdate;
  15475. return this;
  15476. },
  15477. addLevel: function ( object, distance = 0 ) {
  15478. distance = Math.abs( distance );
  15479. const levels = this.levels;
  15480. let l;
  15481. for ( l = 0; l < levels.length; l ++ ) {
  15482. if ( distance < levels[ l ].distance ) {
  15483. break;
  15484. }
  15485. }
  15486. levels.splice( l, 0, { distance: distance, object: object } );
  15487. this.add( object );
  15488. return this;
  15489. },
  15490. getCurrentLevel: function () {
  15491. return this._currentLevel;
  15492. },
  15493. getObjectForDistance: function ( distance ) {
  15494. const levels = this.levels;
  15495. if ( levels.length > 0 ) {
  15496. let i, l;
  15497. for ( i = 1, l = levels.length; i < l; i ++ ) {
  15498. if ( distance < levels[ i ].distance ) {
  15499. break;
  15500. }
  15501. }
  15502. return levels[ i - 1 ].object;
  15503. }
  15504. return null;
  15505. },
  15506. raycast: function ( raycaster, intersects ) {
  15507. const levels = this.levels;
  15508. if ( levels.length > 0 ) {
  15509. _v1$4.setFromMatrixPosition( this.matrixWorld );
  15510. const distance = raycaster.ray.origin.distanceTo( _v1$4 );
  15511. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  15512. }
  15513. },
  15514. update: function ( camera ) {
  15515. const levels = this.levels;
  15516. if ( levels.length > 1 ) {
  15517. _v1$4.setFromMatrixPosition( camera.matrixWorld );
  15518. _v2$2.setFromMatrixPosition( this.matrixWorld );
  15519. const distance = _v1$4.distanceTo( _v2$2 ) / camera.zoom;
  15520. levels[ 0 ].object.visible = true;
  15521. let i, l;
  15522. for ( i = 1, l = levels.length; i < l; i ++ ) {
  15523. if ( distance >= levels[ i ].distance ) {
  15524. levels[ i - 1 ].object.visible = false;
  15525. levels[ i ].object.visible = true;
  15526. } else {
  15527. break;
  15528. }
  15529. }
  15530. this._currentLevel = i - 1;
  15531. for ( ; i < l; i ++ ) {
  15532. levels[ i ].object.visible = false;
  15533. }
  15534. }
  15535. },
  15536. toJSON: function ( meta ) {
  15537. const data = Object3D.prototype.toJSON.call( this, meta );
  15538. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  15539. data.object.levels = [];
  15540. const levels = this.levels;
  15541. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  15542. const level = levels[ i ];
  15543. data.object.levels.push( {
  15544. object: level.object.uuid,
  15545. distance: level.distance
  15546. } );
  15547. }
  15548. return data;
  15549. }
  15550. } );
  15551. const _basePosition = new Vector3();
  15552. const _skinIndex = new Vector4();
  15553. const _skinWeight = new Vector4();
  15554. const _vector$7 = new Vector3();
  15555. const _matrix$1 = new Matrix4();
  15556. function SkinnedMesh( geometry, material ) {
  15557. if ( geometry && geometry.isGeometry ) {
  15558. console.error( 'THREE.SkinnedMesh no longer supports THREE.Geometry. Use THREE.BufferGeometry instead.' );
  15559. }
  15560. Mesh.call( this, geometry, material );
  15561. this.type = 'SkinnedMesh';
  15562. this.bindMode = 'attached';
  15563. this.bindMatrix = new Matrix4();
  15564. this.bindMatrixInverse = new Matrix4();
  15565. }
  15566. SkinnedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15567. constructor: SkinnedMesh,
  15568. isSkinnedMesh: true,
  15569. copy: function ( source ) {
  15570. Mesh.prototype.copy.call( this, source );
  15571. this.bindMode = source.bindMode;
  15572. this.bindMatrix.copy( source.bindMatrix );
  15573. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  15574. this.skeleton = source.skeleton;
  15575. return this;
  15576. },
  15577. bind: function ( skeleton, bindMatrix ) {
  15578. this.skeleton = skeleton;
  15579. if ( bindMatrix === undefined ) {
  15580. this.updateMatrixWorld( true );
  15581. this.skeleton.calculateInverses();
  15582. bindMatrix = this.matrixWorld;
  15583. }
  15584. this.bindMatrix.copy( bindMatrix );
  15585. this.bindMatrixInverse.copy( bindMatrix ).invert();
  15586. },
  15587. pose: function () {
  15588. this.skeleton.pose();
  15589. },
  15590. normalizeSkinWeights: function () {
  15591. const vector = new Vector4();
  15592. const skinWeight = this.geometry.attributes.skinWeight;
  15593. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  15594. vector.x = skinWeight.getX( i );
  15595. vector.y = skinWeight.getY( i );
  15596. vector.z = skinWeight.getZ( i );
  15597. vector.w = skinWeight.getW( i );
  15598. const scale = 1.0 / vector.manhattanLength();
  15599. if ( scale !== Infinity ) {
  15600. vector.multiplyScalar( scale );
  15601. } else {
  15602. vector.set( 1, 0, 0, 0 ); // do something reasonable
  15603. }
  15604. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  15605. }
  15606. },
  15607. updateMatrixWorld: function ( force ) {
  15608. Mesh.prototype.updateMatrixWorld.call( this, force );
  15609. if ( this.bindMode === 'attached' ) {
  15610. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  15611. } else if ( this.bindMode === 'detached' ) {
  15612. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  15613. } else {
  15614. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  15615. }
  15616. },
  15617. boneTransform: function ( index, target ) {
  15618. const skeleton = this.skeleton;
  15619. const geometry = this.geometry;
  15620. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  15621. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  15622. _basePosition.fromBufferAttribute( geometry.attributes.position, index ).applyMatrix4( this.bindMatrix );
  15623. target.set( 0, 0, 0 );
  15624. for ( let i = 0; i < 4; i ++ ) {
  15625. const weight = _skinWeight.getComponent( i );
  15626. if ( weight !== 0 ) {
  15627. const boneIndex = _skinIndex.getComponent( i );
  15628. _matrix$1.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  15629. target.addScaledVector( _vector$7.copy( _basePosition ).applyMatrix4( _matrix$1 ), weight );
  15630. }
  15631. }
  15632. return target.applyMatrix4( this.bindMatrixInverse );
  15633. }
  15634. } );
  15635. function Bone() {
  15636. Object3D.call( this );
  15637. this.type = 'Bone';
  15638. }
  15639. Bone.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15640. constructor: Bone,
  15641. isBone: true
  15642. } );
  15643. const _offsetMatrix = new Matrix4();
  15644. const _identityMatrix = new Matrix4();
  15645. function Skeleton( bones = [], boneInverses = [] ) {
  15646. this.uuid = MathUtils.generateUUID();
  15647. this.bones = bones.slice( 0 );
  15648. this.boneInverses = boneInverses;
  15649. this.boneMatrices = null;
  15650. this.boneTexture = null;
  15651. this.boneTextureSize = 0;
  15652. this.frame = - 1;
  15653. this.init();
  15654. }
  15655. Object.assign( Skeleton.prototype, {
  15656. init: function () {
  15657. const bones = this.bones;
  15658. const boneInverses = this.boneInverses;
  15659. this.boneMatrices = new Float32Array( bones.length * 16 );
  15660. // calculate inverse bone matrices if necessary
  15661. if ( boneInverses.length === 0 ) {
  15662. this.calculateInverses();
  15663. } else {
  15664. // handle special case
  15665. if ( bones.length !== boneInverses.length ) {
  15666. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  15667. this.boneInverses = [];
  15668. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15669. this.boneInverses.push( new Matrix4() );
  15670. }
  15671. }
  15672. }
  15673. },
  15674. calculateInverses: function () {
  15675. this.boneInverses.length = 0;
  15676. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15677. const inverse = new Matrix4();
  15678. if ( this.bones[ i ] ) {
  15679. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  15680. }
  15681. this.boneInverses.push( inverse );
  15682. }
  15683. },
  15684. pose: function () {
  15685. // recover the bind-time world matrices
  15686. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15687. const bone = this.bones[ i ];
  15688. if ( bone ) {
  15689. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  15690. }
  15691. }
  15692. // compute the local matrices, positions, rotations and scales
  15693. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15694. const bone = this.bones[ i ];
  15695. if ( bone ) {
  15696. if ( bone.parent && bone.parent.isBone ) {
  15697. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  15698. bone.matrix.multiply( bone.matrixWorld );
  15699. } else {
  15700. bone.matrix.copy( bone.matrixWorld );
  15701. }
  15702. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  15703. }
  15704. }
  15705. },
  15706. update: function () {
  15707. const bones = this.bones;
  15708. const boneInverses = this.boneInverses;
  15709. const boneMatrices = this.boneMatrices;
  15710. const boneTexture = this.boneTexture;
  15711. // flatten bone matrices to array
  15712. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  15713. // compute the offset between the current and the original transform
  15714. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  15715. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  15716. _offsetMatrix.toArray( boneMatrices, i * 16 );
  15717. }
  15718. if ( boneTexture !== null ) {
  15719. boneTexture.needsUpdate = true;
  15720. }
  15721. },
  15722. clone: function () {
  15723. return new Skeleton( this.bones, this.boneInverses );
  15724. },
  15725. getBoneByName: function ( name ) {
  15726. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  15727. const bone = this.bones[ i ];
  15728. if ( bone.name === name ) {
  15729. return bone;
  15730. }
  15731. }
  15732. return undefined;
  15733. },
  15734. dispose: function ( ) {
  15735. if ( this.boneTexture !== null ) {
  15736. this.boneTexture.dispose();
  15737. this.boneTexture = null;
  15738. }
  15739. },
  15740. fromJSON: function ( json, bones ) {
  15741. this.uuid = json.uuid;
  15742. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  15743. const uuid = json.bones[ i ];
  15744. let bone = bones[ uuid ];
  15745. if ( bone === undefined ) {
  15746. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  15747. bone = new Bone();
  15748. }
  15749. this.bones.push( bone );
  15750. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  15751. }
  15752. this.init();
  15753. return this;
  15754. },
  15755. toJSON: function () {
  15756. const data = {
  15757. metadata: {
  15758. version: 4.5,
  15759. type: 'Skeleton',
  15760. generator: 'Skeleton.toJSON'
  15761. },
  15762. bones: [],
  15763. boneInverses: []
  15764. };
  15765. data.uuid = this.uuid;
  15766. const bones = this.bones;
  15767. const boneInverses = this.boneInverses;
  15768. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  15769. const bone = bones[ i ];
  15770. data.bones.push( bone.uuid );
  15771. const boneInverse = boneInverses[ i ];
  15772. data.boneInverses.push( boneInverse.toArray() );
  15773. }
  15774. return data;
  15775. }
  15776. } );
  15777. const _instanceLocalMatrix = new Matrix4();
  15778. const _instanceWorldMatrix = new Matrix4();
  15779. const _instanceIntersects = [];
  15780. const _mesh = new Mesh();
  15781. function InstancedMesh( geometry, material, count ) {
  15782. Mesh.call( this, geometry, material );
  15783. this.instanceMatrix = new BufferAttribute( new Float32Array( count * 16 ), 16 );
  15784. this.instanceColor = null;
  15785. this.count = count;
  15786. this.frustumCulled = false;
  15787. }
  15788. InstancedMesh.prototype = Object.assign( Object.create( Mesh.prototype ), {
  15789. constructor: InstancedMesh,
  15790. isInstancedMesh: true,
  15791. copy: function ( source ) {
  15792. Mesh.prototype.copy.call( this, source );
  15793. this.instanceMatrix.copy( source.instanceMatrix );
  15794. this.count = source.count;
  15795. return this;
  15796. },
  15797. getColorAt: function ( index, color ) {
  15798. color.fromArray( this.instanceColor.array, index * 3 );
  15799. },
  15800. getMatrixAt: function ( index, matrix ) {
  15801. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  15802. },
  15803. raycast: function ( raycaster, intersects ) {
  15804. const matrixWorld = this.matrixWorld;
  15805. const raycastTimes = this.count;
  15806. _mesh.geometry = this.geometry;
  15807. _mesh.material = this.material;
  15808. if ( _mesh.material === undefined ) return;
  15809. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  15810. // calculate the world matrix for each instance
  15811. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  15812. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  15813. // the mesh represents this single instance
  15814. _mesh.matrixWorld = _instanceWorldMatrix;
  15815. _mesh.raycast( raycaster, _instanceIntersects );
  15816. // process the result of raycast
  15817. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  15818. const intersect = _instanceIntersects[ i ];
  15819. intersect.instanceId = instanceId;
  15820. intersect.object = this;
  15821. intersects.push( intersect );
  15822. }
  15823. _instanceIntersects.length = 0;
  15824. }
  15825. },
  15826. setColorAt: function ( index, color ) {
  15827. if ( this.instanceColor === null ) {
  15828. this.instanceColor = new BufferAttribute( new Float32Array( this.count * 3 ), 3 );
  15829. }
  15830. color.toArray( this.instanceColor.array, index * 3 );
  15831. },
  15832. setMatrixAt: function ( index, matrix ) {
  15833. matrix.toArray( this.instanceMatrix.array, index * 16 );
  15834. },
  15835. updateMorphTargets: function () {
  15836. },
  15837. dispose: function () {
  15838. this.dispatchEvent( { type: 'dispose' } );
  15839. }
  15840. } );
  15841. /**
  15842. * parameters = {
  15843. * color: <hex>,
  15844. * opacity: <float>,
  15845. *
  15846. * linewidth: <float>,
  15847. * linecap: "round",
  15848. * linejoin: "round"
  15849. * }
  15850. */
  15851. function LineBasicMaterial( parameters ) {
  15852. Material.call( this );
  15853. this.type = 'LineBasicMaterial';
  15854. this.color = new Color( 0xffffff );
  15855. this.linewidth = 1;
  15856. this.linecap = 'round';
  15857. this.linejoin = 'round';
  15858. this.morphTargets = false;
  15859. this.setValues( parameters );
  15860. }
  15861. LineBasicMaterial.prototype = Object.create( Material.prototype );
  15862. LineBasicMaterial.prototype.constructor = LineBasicMaterial;
  15863. LineBasicMaterial.prototype.isLineBasicMaterial = true;
  15864. LineBasicMaterial.prototype.copy = function ( source ) {
  15865. Material.prototype.copy.call( this, source );
  15866. this.color.copy( source.color );
  15867. this.linewidth = source.linewidth;
  15868. this.linecap = source.linecap;
  15869. this.linejoin = source.linejoin;
  15870. this.morphTargets = source.morphTargets;
  15871. return this;
  15872. };
  15873. const _start = new Vector3();
  15874. const _end = new Vector3();
  15875. const _inverseMatrix$1 = new Matrix4();
  15876. const _ray$1 = new Ray();
  15877. const _sphere$2 = new Sphere();
  15878. function Line( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  15879. Object3D.call( this );
  15880. this.type = 'Line';
  15881. this.geometry = geometry;
  15882. this.material = material;
  15883. this.updateMorphTargets();
  15884. }
  15885. Line.prototype = Object.assign( Object.create( Object3D.prototype ), {
  15886. constructor: Line,
  15887. isLine: true,
  15888. copy: function ( source ) {
  15889. Object3D.prototype.copy.call( this, source );
  15890. this.material = source.material;
  15891. this.geometry = source.geometry;
  15892. return this;
  15893. },
  15894. computeLineDistances: function () {
  15895. const geometry = this.geometry;
  15896. if ( geometry.isBufferGeometry ) {
  15897. // we assume non-indexed geometry
  15898. if ( geometry.index === null ) {
  15899. const positionAttribute = geometry.attributes.position;
  15900. const lineDistances = [ 0 ];
  15901. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  15902. _start.fromBufferAttribute( positionAttribute, i - 1 );
  15903. _end.fromBufferAttribute( positionAttribute, i );
  15904. lineDistances[ i ] = lineDistances[ i - 1 ];
  15905. lineDistances[ i ] += _start.distanceTo( _end );
  15906. }
  15907. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  15908. } else {
  15909. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  15910. }
  15911. } else if ( geometry.isGeometry ) {
  15912. const vertices = geometry.vertices;
  15913. const lineDistances = geometry.lineDistances;
  15914. lineDistances[ 0 ] = 0;
  15915. for ( let i = 1, l = vertices.length; i < l; i ++ ) {
  15916. lineDistances[ i ] = lineDistances[ i - 1 ];
  15917. lineDistances[ i ] += vertices[ i - 1 ].distanceTo( vertices[ i ] );
  15918. }
  15919. }
  15920. return this;
  15921. },
  15922. raycast: function ( raycaster, intersects ) {
  15923. const geometry = this.geometry;
  15924. const matrixWorld = this.matrixWorld;
  15925. const threshold = raycaster.params.Line.threshold;
  15926. // Checking boundingSphere distance to ray
  15927. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  15928. _sphere$2.copy( geometry.boundingSphere );
  15929. _sphere$2.applyMatrix4( matrixWorld );
  15930. _sphere$2.radius += threshold;
  15931. if ( raycaster.ray.intersectsSphere( _sphere$2 ) === false ) return;
  15932. //
  15933. _inverseMatrix$1.copy( matrixWorld ).invert();
  15934. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  15935. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  15936. const localThresholdSq = localThreshold * localThreshold;
  15937. const vStart = new Vector3();
  15938. const vEnd = new Vector3();
  15939. const interSegment = new Vector3();
  15940. const interRay = new Vector3();
  15941. const step = this.isLineSegments ? 2 : 1;
  15942. if ( geometry.isBufferGeometry ) {
  15943. const index = geometry.index;
  15944. const attributes = geometry.attributes;
  15945. const positionAttribute = attributes.position;
  15946. if ( index !== null ) {
  15947. const indices = index.array;
  15948. for ( let i = 0, l = indices.length - 1; i < l; i += step ) {
  15949. const a = indices[ i ];
  15950. const b = indices[ i + 1 ];
  15951. vStart.fromBufferAttribute( positionAttribute, a );
  15952. vEnd.fromBufferAttribute( positionAttribute, b );
  15953. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15954. if ( distSq > localThresholdSq ) continue;
  15955. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15956. const distance = raycaster.ray.origin.distanceTo( interRay );
  15957. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15958. intersects.push( {
  15959. distance: distance,
  15960. // What do we want? intersection point on the ray or on the segment??
  15961. // point: raycaster.ray.at( distance ),
  15962. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15963. index: i,
  15964. face: null,
  15965. faceIndex: null,
  15966. object: this
  15967. } );
  15968. }
  15969. } else {
  15970. for ( let i = 0, l = positionAttribute.count - 1; i < l; i += step ) {
  15971. vStart.fromBufferAttribute( positionAttribute, i );
  15972. vEnd.fromBufferAttribute( positionAttribute, i + 1 );
  15973. const distSq = _ray$1.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  15974. if ( distSq > localThresholdSq ) continue;
  15975. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15976. const distance = raycaster.ray.origin.distanceTo( interRay );
  15977. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15978. intersects.push( {
  15979. distance: distance,
  15980. // What do we want? intersection point on the ray or on the segment??
  15981. // point: raycaster.ray.at( distance ),
  15982. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  15983. index: i,
  15984. face: null,
  15985. faceIndex: null,
  15986. object: this
  15987. } );
  15988. }
  15989. }
  15990. } else if ( geometry.isGeometry ) {
  15991. const vertices = geometry.vertices;
  15992. const nbVertices = vertices.length;
  15993. for ( let i = 0; i < nbVertices - 1; i += step ) {
  15994. const distSq = _ray$1.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  15995. if ( distSq > localThresholdSq ) continue;
  15996. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  15997. const distance = raycaster.ray.origin.distanceTo( interRay );
  15998. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  15999. intersects.push( {
  16000. distance: distance,
  16001. // What do we want? intersection point on the ray or on the segment??
  16002. // point: raycaster.ray.at( distance ),
  16003. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  16004. index: i,
  16005. face: null,
  16006. faceIndex: null,
  16007. object: this
  16008. } );
  16009. }
  16010. }
  16011. },
  16012. updateMorphTargets: function () {
  16013. const geometry = this.geometry;
  16014. if ( geometry.isBufferGeometry ) {
  16015. const morphAttributes = geometry.morphAttributes;
  16016. const keys = Object.keys( morphAttributes );
  16017. if ( keys.length > 0 ) {
  16018. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  16019. if ( morphAttribute !== undefined ) {
  16020. this.morphTargetInfluences = [];
  16021. this.morphTargetDictionary = {};
  16022. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16023. const name = morphAttribute[ m ].name || String( m );
  16024. this.morphTargetInfluences.push( 0 );
  16025. this.morphTargetDictionary[ name ] = m;
  16026. }
  16027. }
  16028. }
  16029. } else {
  16030. const morphTargets = geometry.morphTargets;
  16031. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16032. console.error( 'THREE.Line.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16033. }
  16034. }
  16035. }
  16036. } );
  16037. const _start$1 = new Vector3();
  16038. const _end$1 = new Vector3();
  16039. function LineSegments( geometry, material ) {
  16040. Line.call( this, geometry, material );
  16041. this.type = 'LineSegments';
  16042. }
  16043. LineSegments.prototype = Object.assign( Object.create( Line.prototype ), {
  16044. constructor: LineSegments,
  16045. isLineSegments: true,
  16046. computeLineDistances: function () {
  16047. const geometry = this.geometry;
  16048. if ( geometry.isBufferGeometry ) {
  16049. // we assume non-indexed geometry
  16050. if ( geometry.index === null ) {
  16051. const positionAttribute = geometry.attributes.position;
  16052. const lineDistances = [];
  16053. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  16054. _start$1.fromBufferAttribute( positionAttribute, i );
  16055. _end$1.fromBufferAttribute( positionAttribute, i + 1 );
  16056. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16057. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16058. }
  16059. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  16060. } else {
  16061. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  16062. }
  16063. } else if ( geometry.isGeometry ) {
  16064. const vertices = geometry.vertices;
  16065. const lineDistances = geometry.lineDistances;
  16066. for ( let i = 0, l = vertices.length; i < l; i += 2 ) {
  16067. _start$1.copy( vertices[ i ] );
  16068. _end$1.copy( vertices[ i + 1 ] );
  16069. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  16070. lineDistances[ i + 1 ] = lineDistances[ i ] + _start$1.distanceTo( _end$1 );
  16071. }
  16072. }
  16073. return this;
  16074. }
  16075. } );
  16076. function LineLoop( geometry, material ) {
  16077. Line.call( this, geometry, material );
  16078. this.type = 'LineLoop';
  16079. }
  16080. LineLoop.prototype = Object.assign( Object.create( Line.prototype ), {
  16081. constructor: LineLoop,
  16082. isLineLoop: true,
  16083. } );
  16084. /**
  16085. * parameters = {
  16086. * color: <hex>,
  16087. * opacity: <float>,
  16088. * map: new THREE.Texture( <Image> ),
  16089. * alphaMap: new THREE.Texture( <Image> ),
  16090. *
  16091. * size: <float>,
  16092. * sizeAttenuation: <bool>
  16093. *
  16094. * morphTargets: <bool>
  16095. * }
  16096. */
  16097. function PointsMaterial( parameters ) {
  16098. Material.call( this );
  16099. this.type = 'PointsMaterial';
  16100. this.color = new Color( 0xffffff );
  16101. this.map = null;
  16102. this.alphaMap = null;
  16103. this.size = 1;
  16104. this.sizeAttenuation = true;
  16105. this.morphTargets = false;
  16106. this.setValues( parameters );
  16107. }
  16108. PointsMaterial.prototype = Object.create( Material.prototype );
  16109. PointsMaterial.prototype.constructor = PointsMaterial;
  16110. PointsMaterial.prototype.isPointsMaterial = true;
  16111. PointsMaterial.prototype.copy = function ( source ) {
  16112. Material.prototype.copy.call( this, source );
  16113. this.color.copy( source.color );
  16114. this.map = source.map;
  16115. this.alphaMap = source.alphaMap;
  16116. this.size = source.size;
  16117. this.sizeAttenuation = source.sizeAttenuation;
  16118. this.morphTargets = source.morphTargets;
  16119. return this;
  16120. };
  16121. const _inverseMatrix$2 = new Matrix4();
  16122. const _ray$2 = new Ray();
  16123. const _sphere$3 = new Sphere();
  16124. const _position$1 = new Vector3();
  16125. function Points( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  16126. Object3D.call( this );
  16127. this.type = 'Points';
  16128. this.geometry = geometry;
  16129. this.material = material;
  16130. this.updateMorphTargets();
  16131. }
  16132. Points.prototype = Object.assign( Object.create( Object3D.prototype ), {
  16133. constructor: Points,
  16134. isPoints: true,
  16135. copy: function ( source ) {
  16136. Object3D.prototype.copy.call( this, source );
  16137. this.material = source.material;
  16138. this.geometry = source.geometry;
  16139. return this;
  16140. },
  16141. raycast: function ( raycaster, intersects ) {
  16142. const geometry = this.geometry;
  16143. const matrixWorld = this.matrixWorld;
  16144. const threshold = raycaster.params.Points.threshold;
  16145. // Checking boundingSphere distance to ray
  16146. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  16147. _sphere$3.copy( geometry.boundingSphere );
  16148. _sphere$3.applyMatrix4( matrixWorld );
  16149. _sphere$3.radius += threshold;
  16150. if ( raycaster.ray.intersectsSphere( _sphere$3 ) === false ) return;
  16151. //
  16152. _inverseMatrix$2.copy( matrixWorld ).invert();
  16153. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  16154. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  16155. const localThresholdSq = localThreshold * localThreshold;
  16156. if ( geometry.isBufferGeometry ) {
  16157. const index = geometry.index;
  16158. const attributes = geometry.attributes;
  16159. const positionAttribute = attributes.position;
  16160. if ( index !== null ) {
  16161. const indices = index.array;
  16162. for ( let i = 0, il = indices.length; i < il; i ++ ) {
  16163. const a = indices[ i ];
  16164. _position$1.fromBufferAttribute( positionAttribute, a );
  16165. testPoint( _position$1, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16166. }
  16167. } else {
  16168. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  16169. _position$1.fromBufferAttribute( positionAttribute, i );
  16170. testPoint( _position$1, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16171. }
  16172. }
  16173. } else {
  16174. const vertices = geometry.vertices;
  16175. for ( let i = 0, l = vertices.length; i < l; i ++ ) {
  16176. testPoint( vertices[ i ], i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  16177. }
  16178. }
  16179. },
  16180. updateMorphTargets: function () {
  16181. const geometry = this.geometry;
  16182. if ( geometry.isBufferGeometry ) {
  16183. const morphAttributes = geometry.morphAttributes;
  16184. const keys = Object.keys( morphAttributes );
  16185. if ( keys.length > 0 ) {
  16186. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  16187. if ( morphAttribute !== undefined ) {
  16188. this.morphTargetInfluences = [];
  16189. this.morphTargetDictionary = {};
  16190. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  16191. const name = morphAttribute[ m ].name || String( m );
  16192. this.morphTargetInfluences.push( 0 );
  16193. this.morphTargetDictionary[ name ] = m;
  16194. }
  16195. }
  16196. }
  16197. } else {
  16198. const morphTargets = geometry.morphTargets;
  16199. if ( morphTargets !== undefined && morphTargets.length > 0 ) {
  16200. console.error( 'THREE.Points.updateMorphTargets() does not support THREE.Geometry. Use THREE.BufferGeometry instead.' );
  16201. }
  16202. }
  16203. }
  16204. } );
  16205. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  16206. const rayPointDistanceSq = _ray$2.distanceSqToPoint( point );
  16207. if ( rayPointDistanceSq < localThresholdSq ) {
  16208. const intersectPoint = new Vector3();
  16209. _ray$2.closestPointToPoint( point, intersectPoint );
  16210. intersectPoint.applyMatrix4( matrixWorld );
  16211. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  16212. if ( distance < raycaster.near || distance > raycaster.far ) return;
  16213. intersects.push( {
  16214. distance: distance,
  16215. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  16216. point: intersectPoint,
  16217. index: index,
  16218. face: null,
  16219. object: object
  16220. } );
  16221. }
  16222. }
  16223. function VideoTexture( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16224. Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16225. this.format = format !== undefined ? format : RGBFormat;
  16226. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  16227. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  16228. this.generateMipmaps = false;
  16229. const scope = this;
  16230. function updateVideo() {
  16231. scope.needsUpdate = true;
  16232. video.requestVideoFrameCallback( updateVideo );
  16233. }
  16234. if ( 'requestVideoFrameCallback' in video ) {
  16235. video.requestVideoFrameCallback( updateVideo );
  16236. }
  16237. }
  16238. VideoTexture.prototype = Object.assign( Object.create( Texture.prototype ), {
  16239. constructor: VideoTexture,
  16240. clone: function () {
  16241. return new this.constructor( this.image ).copy( this );
  16242. },
  16243. isVideoTexture: true,
  16244. update: function () {
  16245. const video = this.image;
  16246. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  16247. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  16248. this.needsUpdate = true;
  16249. }
  16250. }
  16251. } );
  16252. function CompressedTexture( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, encoding ) {
  16253. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, encoding );
  16254. this.image = { width: width, height: height };
  16255. this.mipmaps = mipmaps;
  16256. // no flipping for cube textures
  16257. // (also flipping doesn't work for compressed textures )
  16258. this.flipY = false;
  16259. // can't generate mipmaps for compressed textures
  16260. // mips must be embedded in DDS files
  16261. this.generateMipmaps = false;
  16262. }
  16263. CompressedTexture.prototype = Object.create( Texture.prototype );
  16264. CompressedTexture.prototype.constructor = CompressedTexture;
  16265. CompressedTexture.prototype.isCompressedTexture = true;
  16266. function CanvasTexture( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  16267. Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16268. this.needsUpdate = true;
  16269. }
  16270. CanvasTexture.prototype = Object.create( Texture.prototype );
  16271. CanvasTexture.prototype.constructor = CanvasTexture;
  16272. CanvasTexture.prototype.isCanvasTexture = true;
  16273. function DepthTexture( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format ) {
  16274. format = format !== undefined ? format : DepthFormat;
  16275. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  16276. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  16277. }
  16278. if ( type === undefined && format === DepthFormat ) type = UnsignedShortType;
  16279. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type$1;
  16280. Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  16281. this.image = { width: width, height: height };
  16282. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  16283. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  16284. this.flipY = false;
  16285. this.generateMipmaps = false;
  16286. }
  16287. DepthTexture.prototype = Object.create( Texture.prototype );
  16288. DepthTexture.prototype.constructor = DepthTexture;
  16289. DepthTexture.prototype.isDepthTexture = true;
  16290. let _geometryId = 0; // Geometry uses even numbers as Id
  16291. const _m1$3 = new Matrix4();
  16292. const _obj$1 = new Object3D();
  16293. const _offset$1 = new Vector3();
  16294. function Geometry() {
  16295. Object.defineProperty( this, 'id', { value: _geometryId += 2 } );
  16296. this.uuid = MathUtils.generateUUID();
  16297. this.name = '';
  16298. this.type = 'Geometry';
  16299. this.vertices = [];
  16300. this.colors = [];
  16301. this.faces = [];
  16302. this.faceVertexUvs = [[]];
  16303. this.morphTargets = [];
  16304. this.morphNormals = [];
  16305. this.skinWeights = [];
  16306. this.skinIndices = [];
  16307. this.lineDistances = [];
  16308. this.boundingBox = null;
  16309. this.boundingSphere = null;
  16310. // update flags
  16311. this.elementsNeedUpdate = false;
  16312. this.verticesNeedUpdate = false;
  16313. this.uvsNeedUpdate = false;
  16314. this.normalsNeedUpdate = false;
  16315. this.colorsNeedUpdate = false;
  16316. this.lineDistancesNeedUpdate = false;
  16317. this.groupsNeedUpdate = false;
  16318. }
  16319. Geometry.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  16320. constructor: Geometry,
  16321. isGeometry: true,
  16322. applyMatrix4: function ( matrix ) {
  16323. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  16324. for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
  16325. const vertex = this.vertices[ i ];
  16326. vertex.applyMatrix4( matrix );
  16327. }
  16328. for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
  16329. const face = this.faces[ i ];
  16330. face.normal.applyMatrix3( normalMatrix ).normalize();
  16331. for ( let j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  16332. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  16333. }
  16334. }
  16335. if ( this.boundingBox !== null ) {
  16336. this.computeBoundingBox();
  16337. }
  16338. if ( this.boundingSphere !== null ) {
  16339. this.computeBoundingSphere();
  16340. }
  16341. this.verticesNeedUpdate = true;
  16342. this.normalsNeedUpdate = true;
  16343. return this;
  16344. },
  16345. rotateX: function ( angle ) {
  16346. // rotate geometry around world x-axis
  16347. _m1$3.makeRotationX( angle );
  16348. this.applyMatrix4( _m1$3 );
  16349. return this;
  16350. },
  16351. rotateY: function ( angle ) {
  16352. // rotate geometry around world y-axis
  16353. _m1$3.makeRotationY( angle );
  16354. this.applyMatrix4( _m1$3 );
  16355. return this;
  16356. },
  16357. rotateZ: function ( angle ) {
  16358. // rotate geometry around world z-axis
  16359. _m1$3.makeRotationZ( angle );
  16360. this.applyMatrix4( _m1$3 );
  16361. return this;
  16362. },
  16363. translate: function ( x, y, z ) {
  16364. // translate geometry
  16365. _m1$3.makeTranslation( x, y, z );
  16366. this.applyMatrix4( _m1$3 );
  16367. return this;
  16368. },
  16369. scale: function ( x, y, z ) {
  16370. // scale geometry
  16371. _m1$3.makeScale( x, y, z );
  16372. this.applyMatrix4( _m1$3 );
  16373. return this;
  16374. },
  16375. lookAt: function ( vector ) {
  16376. _obj$1.lookAt( vector );
  16377. _obj$1.updateMatrix();
  16378. this.applyMatrix4( _obj$1.matrix );
  16379. return this;
  16380. },
  16381. fromBufferGeometry: function ( geometry ) {
  16382. const scope = this;
  16383. const index = geometry.index !== null ? geometry.index : undefined;
  16384. const attributes = geometry.attributes;
  16385. if ( attributes.position === undefined ) {
  16386. console.error( 'THREE.Geometry.fromBufferGeometry(): Position attribute required for conversion.' );
  16387. return this;
  16388. }
  16389. const position = attributes.position;
  16390. const normal = attributes.normal;
  16391. const color = attributes.color;
  16392. const uv = attributes.uv;
  16393. const uv2 = attributes.uv2;
  16394. if ( uv2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  16395. for ( let i = 0; i < position.count; i ++ ) {
  16396. scope.vertices.push( new Vector3().fromBufferAttribute( position, i ) );
  16397. if ( color !== undefined ) {
  16398. scope.colors.push( new Color().fromBufferAttribute( color, i ) );
  16399. }
  16400. }
  16401. function addFace( a, b, c, materialIndex ) {
  16402. const vertexColors = ( color === undefined ) ? [] : [
  16403. scope.colors[ a ].clone(),
  16404. scope.colors[ b ].clone(),
  16405. scope.colors[ c ].clone()
  16406. ];
  16407. const vertexNormals = ( normal === undefined ) ? [] : [
  16408. new Vector3().fromBufferAttribute( normal, a ),
  16409. new Vector3().fromBufferAttribute( normal, b ),
  16410. new Vector3().fromBufferAttribute( normal, c )
  16411. ];
  16412. const face = new Face3( a, b, c, vertexNormals, vertexColors, materialIndex );
  16413. scope.faces.push( face );
  16414. if ( uv !== undefined ) {
  16415. scope.faceVertexUvs[ 0 ].push( [
  16416. new Vector2().fromBufferAttribute( uv, a ),
  16417. new Vector2().fromBufferAttribute( uv, b ),
  16418. new Vector2().fromBufferAttribute( uv, c )
  16419. ] );
  16420. }
  16421. if ( uv2 !== undefined ) {
  16422. scope.faceVertexUvs[ 1 ].push( [
  16423. new Vector2().fromBufferAttribute( uv2, a ),
  16424. new Vector2().fromBufferAttribute( uv2, b ),
  16425. new Vector2().fromBufferAttribute( uv2, c )
  16426. ] );
  16427. }
  16428. }
  16429. const groups = geometry.groups;
  16430. if ( groups.length > 0 ) {
  16431. for ( let i = 0; i < groups.length; i ++ ) {
  16432. const group = groups[ i ];
  16433. const start = group.start;
  16434. const count = group.count;
  16435. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  16436. if ( index !== undefined ) {
  16437. addFace( index.getX( j ), index.getX( j + 1 ), index.getX( j + 2 ), group.materialIndex );
  16438. } else {
  16439. addFace( j, j + 1, j + 2, group.materialIndex );
  16440. }
  16441. }
  16442. }
  16443. } else {
  16444. if ( index !== undefined ) {
  16445. for ( let i = 0; i < index.count; i += 3 ) {
  16446. addFace( index.getX( i ), index.getX( i + 1 ), index.getX( i + 2 ) );
  16447. }
  16448. } else {
  16449. for ( let i = 0; i < position.count; i += 3 ) {
  16450. addFace( i, i + 1, i + 2 );
  16451. }
  16452. }
  16453. }
  16454. this.computeFaceNormals();
  16455. if ( geometry.boundingBox !== null ) {
  16456. this.boundingBox = geometry.boundingBox.clone();
  16457. }
  16458. if ( geometry.boundingSphere !== null ) {
  16459. this.boundingSphere = geometry.boundingSphere.clone();
  16460. }
  16461. return this;
  16462. },
  16463. center: function () {
  16464. this.computeBoundingBox();
  16465. this.boundingBox.getCenter( _offset$1 ).negate();
  16466. this.translate( _offset$1.x, _offset$1.y, _offset$1.z );
  16467. return this;
  16468. },
  16469. normalize: function () {
  16470. this.computeBoundingSphere();
  16471. const center = this.boundingSphere.center;
  16472. const radius = this.boundingSphere.radius;
  16473. const s = radius === 0 ? 1 : 1.0 / radius;
  16474. const matrix = new Matrix4();
  16475. matrix.set(
  16476. s, 0, 0, - s * center.x,
  16477. 0, s, 0, - s * center.y,
  16478. 0, 0, s, - s * center.z,
  16479. 0, 0, 0, 1
  16480. );
  16481. this.applyMatrix4( matrix );
  16482. return this;
  16483. },
  16484. computeFaceNormals: function () {
  16485. const cb = new Vector3(), ab = new Vector3();
  16486. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16487. const face = this.faces[ f ];
  16488. const vA = this.vertices[ face.a ];
  16489. const vB = this.vertices[ face.b ];
  16490. const vC = this.vertices[ face.c ];
  16491. cb.subVectors( vC, vB );
  16492. ab.subVectors( vA, vB );
  16493. cb.cross( ab );
  16494. cb.normalize();
  16495. face.normal.copy( cb );
  16496. }
  16497. },
  16498. computeVertexNormals: function ( areaWeighted = true ) {
  16499. const vertices = new Array( this.vertices.length );
  16500. for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  16501. vertices[ v ] = new Vector3();
  16502. }
  16503. if ( areaWeighted ) {
  16504. // vertex normals weighted by triangle areas
  16505. // http://www.iquilezles.org/www/articles/normals/normals.htm
  16506. const cb = new Vector3(), ab = new Vector3();
  16507. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16508. const face = this.faces[ f ];
  16509. const vA = this.vertices[ face.a ];
  16510. const vB = this.vertices[ face.b ];
  16511. const vC = this.vertices[ face.c ];
  16512. cb.subVectors( vC, vB );
  16513. ab.subVectors( vA, vB );
  16514. cb.cross( ab );
  16515. vertices[ face.a ].add( cb );
  16516. vertices[ face.b ].add( cb );
  16517. vertices[ face.c ].add( cb );
  16518. }
  16519. } else {
  16520. this.computeFaceNormals();
  16521. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16522. const face = this.faces[ f ];
  16523. vertices[ face.a ].add( face.normal );
  16524. vertices[ face.b ].add( face.normal );
  16525. vertices[ face.c ].add( face.normal );
  16526. }
  16527. }
  16528. for ( let v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  16529. vertices[ v ].normalize();
  16530. }
  16531. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16532. const face = this.faces[ f ];
  16533. const vertexNormals = face.vertexNormals;
  16534. if ( vertexNormals.length === 3 ) {
  16535. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  16536. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  16537. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  16538. } else {
  16539. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  16540. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  16541. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  16542. }
  16543. }
  16544. if ( this.faces.length > 0 ) {
  16545. this.normalsNeedUpdate = true;
  16546. }
  16547. },
  16548. computeFlatVertexNormals: function () {
  16549. this.computeFaceNormals();
  16550. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16551. const face = this.faces[ f ];
  16552. const vertexNormals = face.vertexNormals;
  16553. if ( vertexNormals.length === 3 ) {
  16554. vertexNormals[ 0 ].copy( face.normal );
  16555. vertexNormals[ 1 ].copy( face.normal );
  16556. vertexNormals[ 2 ].copy( face.normal );
  16557. } else {
  16558. vertexNormals[ 0 ] = face.normal.clone();
  16559. vertexNormals[ 1 ] = face.normal.clone();
  16560. vertexNormals[ 2 ] = face.normal.clone();
  16561. }
  16562. }
  16563. if ( this.faces.length > 0 ) {
  16564. this.normalsNeedUpdate = true;
  16565. }
  16566. },
  16567. computeMorphNormals: function () {
  16568. // save original normals
  16569. // - create temp variables on first access
  16570. // otherwise just copy (for faster repeated calls)
  16571. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16572. const face = this.faces[ f ];
  16573. if ( ! face.__originalFaceNormal ) {
  16574. face.__originalFaceNormal = face.normal.clone();
  16575. } else {
  16576. face.__originalFaceNormal.copy( face.normal );
  16577. }
  16578. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  16579. for ( let i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  16580. if ( ! face.__originalVertexNormals[ i ] ) {
  16581. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  16582. } else {
  16583. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  16584. }
  16585. }
  16586. }
  16587. // use temp geometry to compute face and vertex normals for each morph
  16588. const tmpGeo = new Geometry();
  16589. tmpGeo.faces = this.faces;
  16590. for ( let i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  16591. // create on first access
  16592. if ( ! this.morphNormals[ i ] ) {
  16593. this.morphNormals[ i ] = {};
  16594. this.morphNormals[ i ].faceNormals = [];
  16595. this.morphNormals[ i ].vertexNormals = [];
  16596. const dstNormalsFace = this.morphNormals[ i ].faceNormals;
  16597. const dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  16598. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16599. const faceNormal = new Vector3();
  16600. const vertexNormals = { a: new Vector3(), b: new Vector3(), c: new Vector3() };
  16601. dstNormalsFace.push( faceNormal );
  16602. dstNormalsVertex.push( vertexNormals );
  16603. }
  16604. }
  16605. const morphNormals = this.morphNormals[ i ];
  16606. // set vertices to morph target
  16607. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  16608. // compute morph normals
  16609. tmpGeo.computeFaceNormals();
  16610. tmpGeo.computeVertexNormals();
  16611. // store morph normals
  16612. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16613. const face = this.faces[ f ];
  16614. const faceNormal = morphNormals.faceNormals[ f ];
  16615. const vertexNormals = morphNormals.vertexNormals[ f ];
  16616. faceNormal.copy( face.normal );
  16617. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  16618. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  16619. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  16620. }
  16621. }
  16622. // restore original normals
  16623. for ( let f = 0, fl = this.faces.length; f < fl; f ++ ) {
  16624. const face = this.faces[ f ];
  16625. face.normal = face.__originalFaceNormal;
  16626. face.vertexNormals = face.__originalVertexNormals;
  16627. }
  16628. },
  16629. computeBoundingBox: function () {
  16630. if ( this.boundingBox === null ) {
  16631. this.boundingBox = new Box3();
  16632. }
  16633. this.boundingBox.setFromPoints( this.vertices );
  16634. },
  16635. computeBoundingSphere: function () {
  16636. if ( this.boundingSphere === null ) {
  16637. this.boundingSphere = new Sphere();
  16638. }
  16639. this.boundingSphere.setFromPoints( this.vertices );
  16640. },
  16641. merge: function ( geometry, matrix, materialIndexOffset = 0 ) {
  16642. if ( ! ( geometry && geometry.isGeometry ) ) {
  16643. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  16644. return;
  16645. }
  16646. let normalMatrix;
  16647. const vertexOffset = this.vertices.length,
  16648. vertices1 = this.vertices,
  16649. vertices2 = geometry.vertices,
  16650. faces1 = this.faces,
  16651. faces2 = geometry.faces,
  16652. colors1 = this.colors,
  16653. colors2 = geometry.colors;
  16654. if ( matrix !== undefined ) {
  16655. normalMatrix = new Matrix3().getNormalMatrix( matrix );
  16656. }
  16657. // vertices
  16658. for ( let i = 0, il = vertices2.length; i < il; i ++ ) {
  16659. const vertex = vertices2[ i ];
  16660. const vertexCopy = vertex.clone();
  16661. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  16662. vertices1.push( vertexCopy );
  16663. }
  16664. // colors
  16665. for ( let i = 0, il = colors2.length; i < il; i ++ ) {
  16666. colors1.push( colors2[ i ].clone() );
  16667. }
  16668. // faces
  16669. for ( let i = 0, il = faces2.length; i < il; i ++ ) {
  16670. const face = faces2[ i ];
  16671. let normal, color;
  16672. const faceVertexNormals = face.vertexNormals,
  16673. faceVertexColors = face.vertexColors;
  16674. const faceCopy = new Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  16675. faceCopy.normal.copy( face.normal );
  16676. if ( normalMatrix !== undefined ) {
  16677. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  16678. }
  16679. for ( let j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  16680. normal = faceVertexNormals[ j ].clone();
  16681. if ( normalMatrix !== undefined ) {
  16682. normal.applyMatrix3( normalMatrix ).normalize();
  16683. }
  16684. faceCopy.vertexNormals.push( normal );
  16685. }
  16686. faceCopy.color.copy( face.color );
  16687. for ( let j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  16688. color = faceVertexColors[ j ];
  16689. faceCopy.vertexColors.push( color.clone() );
  16690. }
  16691. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  16692. faces1.push( faceCopy );
  16693. }
  16694. // uvs
  16695. for ( let i = 0, il = geometry.faceVertexUvs.length; i < il; i ++ ) {
  16696. const faceVertexUvs2 = geometry.faceVertexUvs[ i ];
  16697. if ( this.faceVertexUvs[ i ] === undefined ) this.faceVertexUvs[ i ] = [];
  16698. for ( let j = 0, jl = faceVertexUvs2.length; j < jl; j ++ ) {
  16699. const uvs2 = faceVertexUvs2[ j ], uvsCopy = [];
  16700. for ( let k = 0, kl = uvs2.length; k < kl; k ++ ) {
  16701. uvsCopy.push( uvs2[ k ].clone() );
  16702. }
  16703. this.faceVertexUvs[ i ].push( uvsCopy );
  16704. }
  16705. }
  16706. },
  16707. mergeMesh: function ( mesh ) {
  16708. if ( ! ( mesh && mesh.isMesh ) ) {
  16709. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  16710. return;
  16711. }
  16712. if ( mesh.matrixAutoUpdate ) mesh.updateMatrix();
  16713. this.merge( mesh.geometry, mesh.matrix );
  16714. },
  16715. /*
  16716. * Checks for duplicate vertices with hashmap.
  16717. * Duplicated vertices are removed
  16718. * and faces' vertices are updated.
  16719. */
  16720. mergeVertices: function ( precisionPoints = 4 ) {
  16721. const verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  16722. const unique = [], changes = [];
  16723. const precision = Math.pow( 10, precisionPoints );
  16724. for ( let i = 0, il = this.vertices.length; i < il; i ++ ) {
  16725. const v = this.vertices[ i ];
  16726. const key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  16727. if ( verticesMap[ key ] === undefined ) {
  16728. verticesMap[ key ] = i;
  16729. unique.push( this.vertices[ i ] );
  16730. changes[ i ] = unique.length - 1;
  16731. } else {
  16732. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  16733. changes[ i ] = changes[ verticesMap[ key ] ];
  16734. }
  16735. }
  16736. // if faces are completely degenerate after merging vertices, we
  16737. // have to remove them from the geometry.
  16738. const faceIndicesToRemove = [];
  16739. for ( let i = 0, il = this.faces.length; i < il; i ++ ) {
  16740. const face = this.faces[ i ];
  16741. face.a = changes[ face.a ];
  16742. face.b = changes[ face.b ];
  16743. face.c = changes[ face.c ];
  16744. const indices = [ face.a, face.b, face.c ];
  16745. // if any duplicate vertices are found in a Face3
  16746. // we have to remove the face as nothing can be saved
  16747. for ( let n = 0; n < 3; n ++ ) {
  16748. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  16749. faceIndicesToRemove.push( i );
  16750. break;
  16751. }
  16752. }
  16753. }
  16754. for ( let i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  16755. const idx = faceIndicesToRemove[ i ];
  16756. this.faces.splice( idx, 1 );
  16757. for ( let j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  16758. this.faceVertexUvs[ j ].splice( idx, 1 );
  16759. }
  16760. }
  16761. // Use unique set of vertices
  16762. const diff = this.vertices.length - unique.length;
  16763. this.vertices = unique;
  16764. return diff;
  16765. },
  16766. setFromPoints: function ( points ) {
  16767. this.vertices = [];
  16768. for ( let i = 0, l = points.length; i < l; i ++ ) {
  16769. const point = points[ i ];
  16770. this.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  16771. }
  16772. return this;
  16773. },
  16774. sortFacesByMaterialIndex: function () {
  16775. const faces = this.faces;
  16776. const length = faces.length;
  16777. // tag faces
  16778. for ( let i = 0; i < length; i ++ ) {
  16779. faces[ i ]._id = i;
  16780. }
  16781. // sort faces
  16782. function materialIndexSort( a, b ) {
  16783. return a.materialIndex - b.materialIndex;
  16784. }
  16785. faces.sort( materialIndexSort );
  16786. // sort uvs
  16787. const uvs1 = this.faceVertexUvs[ 0 ];
  16788. const uvs2 = this.faceVertexUvs[ 1 ];
  16789. let newUvs1, newUvs2;
  16790. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  16791. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  16792. for ( let i = 0; i < length; i ++ ) {
  16793. const id = faces[ i ]._id;
  16794. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  16795. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  16796. }
  16797. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  16798. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  16799. },
  16800. toJSON: function () {
  16801. const data = {
  16802. metadata: {
  16803. version: 4.5,
  16804. type: 'Geometry',
  16805. generator: 'Geometry.toJSON'
  16806. }
  16807. };
  16808. // standard Geometry serialization
  16809. data.uuid = this.uuid;
  16810. data.type = this.type;
  16811. if ( this.name !== '' ) data.name = this.name;
  16812. if ( this.parameters !== undefined ) {
  16813. const parameters = this.parameters;
  16814. for ( const key in parameters ) {
  16815. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  16816. }
  16817. return data;
  16818. }
  16819. const vertices = [];
  16820. for ( let i = 0; i < this.vertices.length; i ++ ) {
  16821. const vertex = this.vertices[ i ];
  16822. vertices.push( vertex.x, vertex.y, vertex.z );
  16823. }
  16824. const faces = [];
  16825. const normals = [];
  16826. const normalsHash = {};
  16827. const colors = [];
  16828. const colorsHash = {};
  16829. const uvs = [];
  16830. const uvsHash = {};
  16831. for ( let i = 0; i < this.faces.length; i ++ ) {
  16832. const face = this.faces[ i ];
  16833. const hasMaterial = true;
  16834. const hasFaceUv = false; // deprecated
  16835. const hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  16836. const hasFaceNormal = face.normal.length() > 0;
  16837. const hasFaceVertexNormal = face.vertexNormals.length > 0;
  16838. const hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  16839. const hasFaceVertexColor = face.vertexColors.length > 0;
  16840. let faceType = 0;
  16841. faceType = setBit( faceType, 0, 0 ); // isQuad
  16842. faceType = setBit( faceType, 1, hasMaterial );
  16843. faceType = setBit( faceType, 2, hasFaceUv );
  16844. faceType = setBit( faceType, 3, hasFaceVertexUv );
  16845. faceType = setBit( faceType, 4, hasFaceNormal );
  16846. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  16847. faceType = setBit( faceType, 6, hasFaceColor );
  16848. faceType = setBit( faceType, 7, hasFaceVertexColor );
  16849. faces.push( faceType );
  16850. faces.push( face.a, face.b, face.c );
  16851. faces.push( face.materialIndex );
  16852. if ( hasFaceVertexUv ) {
  16853. const faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  16854. faces.push(
  16855. getUvIndex( faceVertexUvs[ 0 ] ),
  16856. getUvIndex( faceVertexUvs[ 1 ] ),
  16857. getUvIndex( faceVertexUvs[ 2 ] )
  16858. );
  16859. }
  16860. if ( hasFaceNormal ) {
  16861. faces.push( getNormalIndex( face.normal ) );
  16862. }
  16863. if ( hasFaceVertexNormal ) {
  16864. const vertexNormals = face.vertexNormals;
  16865. faces.push(
  16866. getNormalIndex( vertexNormals[ 0 ] ),
  16867. getNormalIndex( vertexNormals[ 1 ] ),
  16868. getNormalIndex( vertexNormals[ 2 ] )
  16869. );
  16870. }
  16871. if ( hasFaceColor ) {
  16872. faces.push( getColorIndex( face.color ) );
  16873. }
  16874. if ( hasFaceVertexColor ) {
  16875. const vertexColors = face.vertexColors;
  16876. faces.push(
  16877. getColorIndex( vertexColors[ 0 ] ),
  16878. getColorIndex( vertexColors[ 1 ] ),
  16879. getColorIndex( vertexColors[ 2 ] )
  16880. );
  16881. }
  16882. }
  16883. function setBit( value, position, enabled ) {
  16884. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  16885. }
  16886. function getNormalIndex( normal ) {
  16887. const hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  16888. if ( normalsHash[ hash ] !== undefined ) {
  16889. return normalsHash[ hash ];
  16890. }
  16891. normalsHash[ hash ] = normals.length / 3;
  16892. normals.push( normal.x, normal.y, normal.z );
  16893. return normalsHash[ hash ];
  16894. }
  16895. function getColorIndex( color ) {
  16896. const hash = color.r.toString() + color.g.toString() + color.b.toString();
  16897. if ( colorsHash[ hash ] !== undefined ) {
  16898. return colorsHash[ hash ];
  16899. }
  16900. colorsHash[ hash ] = colors.length;
  16901. colors.push( color.getHex() );
  16902. return colorsHash[ hash ];
  16903. }
  16904. function getUvIndex( uv ) {
  16905. const hash = uv.x.toString() + uv.y.toString();
  16906. if ( uvsHash[ hash ] !== undefined ) {
  16907. return uvsHash[ hash ];
  16908. }
  16909. uvsHash[ hash ] = uvs.length / 2;
  16910. uvs.push( uv.x, uv.y );
  16911. return uvsHash[ hash ];
  16912. }
  16913. data.data = {};
  16914. data.data.vertices = vertices;
  16915. data.data.normals = normals;
  16916. if ( colors.length > 0 ) data.data.colors = colors;
  16917. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  16918. data.data.faces = faces;
  16919. return data;
  16920. },
  16921. clone: function () {
  16922. /*
  16923. // Handle primitives
  16924. const parameters = this.parameters;
  16925. if ( parameters !== undefined ) {
  16926. const values = [];
  16927. for ( const key in parameters ) {
  16928. values.push( parameters[ key ] );
  16929. }
  16930. const geometry = Object.create( this.constructor.prototype );
  16931. this.constructor.apply( geometry, values );
  16932. return geometry;
  16933. }
  16934. return new this.constructor().copy( this );
  16935. */
  16936. return new Geometry().copy( this );
  16937. },
  16938. copy: function ( source ) {
  16939. // reset
  16940. this.vertices = [];
  16941. this.colors = [];
  16942. this.faces = [];
  16943. this.faceVertexUvs = [[]];
  16944. this.morphTargets = [];
  16945. this.morphNormals = [];
  16946. this.skinWeights = [];
  16947. this.skinIndices = [];
  16948. this.lineDistances = [];
  16949. this.boundingBox = null;
  16950. this.boundingSphere = null;
  16951. // name
  16952. this.name = source.name;
  16953. // vertices
  16954. const vertices = source.vertices;
  16955. for ( let i = 0, il = vertices.length; i < il; i ++ ) {
  16956. this.vertices.push( vertices[ i ].clone() );
  16957. }
  16958. // colors
  16959. const colors = source.colors;
  16960. for ( let i = 0, il = colors.length; i < il; i ++ ) {
  16961. this.colors.push( colors[ i ].clone() );
  16962. }
  16963. // faces
  16964. const faces = source.faces;
  16965. for ( let i = 0, il = faces.length; i < il; i ++ ) {
  16966. this.faces.push( faces[ i ].clone() );
  16967. }
  16968. // face vertex uvs
  16969. for ( let i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  16970. const faceVertexUvs = source.faceVertexUvs[ i ];
  16971. if ( this.faceVertexUvs[ i ] === undefined ) {
  16972. this.faceVertexUvs[ i ] = [];
  16973. }
  16974. for ( let j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  16975. const uvs = faceVertexUvs[ j ], uvsCopy = [];
  16976. for ( let k = 0, kl = uvs.length; k < kl; k ++ ) {
  16977. const uv = uvs[ k ];
  16978. uvsCopy.push( uv.clone() );
  16979. }
  16980. this.faceVertexUvs[ i ].push( uvsCopy );
  16981. }
  16982. }
  16983. // morph targets
  16984. const morphTargets = source.morphTargets;
  16985. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  16986. const morphTarget = {};
  16987. morphTarget.name = morphTargets[ i ].name;
  16988. // vertices
  16989. if ( morphTargets[ i ].vertices !== undefined ) {
  16990. morphTarget.vertices = [];
  16991. for ( let j = 0, jl = morphTargets[ i ].vertices.length; j < jl; j ++ ) {
  16992. morphTarget.vertices.push( morphTargets[ i ].vertices[ j ].clone() );
  16993. }
  16994. }
  16995. // normals
  16996. if ( morphTargets[ i ].normals !== undefined ) {
  16997. morphTarget.normals = [];
  16998. for ( let j = 0, jl = morphTargets[ i ].normals.length; j < jl; j ++ ) {
  16999. morphTarget.normals.push( morphTargets[ i ].normals[ j ].clone() );
  17000. }
  17001. }
  17002. this.morphTargets.push( morphTarget );
  17003. }
  17004. // morph normals
  17005. const morphNormals = source.morphNormals;
  17006. for ( let i = 0, il = morphNormals.length; i < il; i ++ ) {
  17007. const morphNormal = {};
  17008. // vertex normals
  17009. if ( morphNormals[ i ].vertexNormals !== undefined ) {
  17010. morphNormal.vertexNormals = [];
  17011. for ( let j = 0, jl = morphNormals[ i ].vertexNormals.length; j < jl; j ++ ) {
  17012. const srcVertexNormal = morphNormals[ i ].vertexNormals[ j ];
  17013. const destVertexNormal = {};
  17014. destVertexNormal.a = srcVertexNormal.a.clone();
  17015. destVertexNormal.b = srcVertexNormal.b.clone();
  17016. destVertexNormal.c = srcVertexNormal.c.clone();
  17017. morphNormal.vertexNormals.push( destVertexNormal );
  17018. }
  17019. }
  17020. // face normals
  17021. if ( morphNormals[ i ].faceNormals !== undefined ) {
  17022. morphNormal.faceNormals = [];
  17023. for ( let j = 0, jl = morphNormals[ i ].faceNormals.length; j < jl; j ++ ) {
  17024. morphNormal.faceNormals.push( morphNormals[ i ].faceNormals[ j ].clone() );
  17025. }
  17026. }
  17027. this.morphNormals.push( morphNormal );
  17028. }
  17029. // skin weights
  17030. const skinWeights = source.skinWeights;
  17031. for ( let i = 0, il = skinWeights.length; i < il; i ++ ) {
  17032. this.skinWeights.push( skinWeights[ i ].clone() );
  17033. }
  17034. // skin indices
  17035. const skinIndices = source.skinIndices;
  17036. for ( let i = 0, il = skinIndices.length; i < il; i ++ ) {
  17037. this.skinIndices.push( skinIndices[ i ].clone() );
  17038. }
  17039. // line distances
  17040. const lineDistances = source.lineDistances;
  17041. for ( let i = 0, il = lineDistances.length; i < il; i ++ ) {
  17042. this.lineDistances.push( lineDistances[ i ] );
  17043. }
  17044. // bounding box
  17045. const boundingBox = source.boundingBox;
  17046. if ( boundingBox !== null ) {
  17047. this.boundingBox = boundingBox.clone();
  17048. }
  17049. // bounding sphere
  17050. const boundingSphere = source.boundingSphere;
  17051. if ( boundingSphere !== null ) {
  17052. this.boundingSphere = boundingSphere.clone();
  17053. }
  17054. // update flags
  17055. this.elementsNeedUpdate = source.elementsNeedUpdate;
  17056. this.verticesNeedUpdate = source.verticesNeedUpdate;
  17057. this.uvsNeedUpdate = source.uvsNeedUpdate;
  17058. this.normalsNeedUpdate = source.normalsNeedUpdate;
  17059. this.colorsNeedUpdate = source.colorsNeedUpdate;
  17060. this.lineDistancesNeedUpdate = source.lineDistancesNeedUpdate;
  17061. this.groupsNeedUpdate = source.groupsNeedUpdate;
  17062. return this;
  17063. },
  17064. dispose: function () {
  17065. this.dispatchEvent( { type: 'dispose' } );
  17066. }
  17067. } );
  17068. class BoxGeometry extends Geometry {
  17069. constructor( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  17070. super();
  17071. this.type = 'BoxGeometry';
  17072. this.parameters = {
  17073. width: width,
  17074. height: height,
  17075. depth: depth,
  17076. widthSegments: widthSegments,
  17077. heightSegments: heightSegments,
  17078. depthSegments: depthSegments
  17079. };
  17080. this.fromBufferGeometry( new BoxBufferGeometry( width, height, depth, widthSegments, heightSegments, depthSegments ) );
  17081. this.mergeVertices();
  17082. }
  17083. }
  17084. class CircleBufferGeometry extends BufferGeometry {
  17085. constructor( radius = 1, segments = 8, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17086. super();
  17087. this.type = 'CircleBufferGeometry';
  17088. this.parameters = {
  17089. radius: radius,
  17090. segments: segments,
  17091. thetaStart: thetaStart,
  17092. thetaLength: thetaLength
  17093. };
  17094. segments = Math.max( 3, segments );
  17095. // buffers
  17096. const indices = [];
  17097. const vertices = [];
  17098. const normals = [];
  17099. const uvs = [];
  17100. // helper variables
  17101. const vertex = new Vector3();
  17102. const uv = new Vector2();
  17103. // center point
  17104. vertices.push( 0, 0, 0 );
  17105. normals.push( 0, 0, 1 );
  17106. uvs.push( 0.5, 0.5 );
  17107. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  17108. const segment = thetaStart + s / segments * thetaLength;
  17109. // vertex
  17110. vertex.x = radius * Math.cos( segment );
  17111. vertex.y = radius * Math.sin( segment );
  17112. vertices.push( vertex.x, vertex.y, vertex.z );
  17113. // normal
  17114. normals.push( 0, 0, 1 );
  17115. // uvs
  17116. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  17117. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  17118. uvs.push( uv.x, uv.y );
  17119. }
  17120. // indices
  17121. for ( let i = 1; i <= segments; i ++ ) {
  17122. indices.push( i, i + 1, 0 );
  17123. }
  17124. // build geometry
  17125. this.setIndex( indices );
  17126. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17127. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17128. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17129. }
  17130. }
  17131. class CircleGeometry extends Geometry {
  17132. constructor( radius, segments, thetaStart, thetaLength ) {
  17133. super();
  17134. this.type = 'CircleGeometry';
  17135. this.parameters = {
  17136. radius: radius,
  17137. segments: segments,
  17138. thetaStart: thetaStart,
  17139. thetaLength: thetaLength
  17140. };
  17141. this.fromBufferGeometry( new CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  17142. this.mergeVertices();
  17143. }
  17144. }
  17145. class CylinderBufferGeometry extends BufferGeometry {
  17146. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17147. super();
  17148. this.type = 'CylinderBufferGeometry';
  17149. this.parameters = {
  17150. radiusTop: radiusTop,
  17151. radiusBottom: radiusBottom,
  17152. height: height,
  17153. radialSegments: radialSegments,
  17154. heightSegments: heightSegments,
  17155. openEnded: openEnded,
  17156. thetaStart: thetaStart,
  17157. thetaLength: thetaLength
  17158. };
  17159. const scope = this;
  17160. radialSegments = Math.floor( radialSegments );
  17161. heightSegments = Math.floor( heightSegments );
  17162. // buffers
  17163. const indices = [];
  17164. const vertices = [];
  17165. const normals = [];
  17166. const uvs = [];
  17167. // helper variables
  17168. let index = 0;
  17169. const indexArray = [];
  17170. const halfHeight = height / 2;
  17171. let groupStart = 0;
  17172. // generate geometry
  17173. generateTorso();
  17174. if ( openEnded === false ) {
  17175. if ( radiusTop > 0 ) generateCap( true );
  17176. if ( radiusBottom > 0 ) generateCap( false );
  17177. }
  17178. // build geometry
  17179. this.setIndex( indices );
  17180. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17181. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  17182. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  17183. function generateTorso() {
  17184. const normal = new Vector3();
  17185. const vertex = new Vector3();
  17186. let groupCount = 0;
  17187. // this will be used to calculate the normal
  17188. const slope = ( radiusBottom - radiusTop ) / height;
  17189. // generate vertices, normals and uvs
  17190. for ( let y = 0; y <= heightSegments; y ++ ) {
  17191. const indexRow = [];
  17192. const v = y / heightSegments;
  17193. // calculate the radius of the current row
  17194. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  17195. for ( let x = 0; x <= radialSegments; x ++ ) {
  17196. const u = x / radialSegments;
  17197. const theta = u * thetaLength + thetaStart;
  17198. const sinTheta = Math.sin( theta );
  17199. const cosTheta = Math.cos( theta );
  17200. // vertex
  17201. vertex.x = radius * sinTheta;
  17202. vertex.y = - v * height + halfHeight;
  17203. vertex.z = radius * cosTheta;
  17204. vertices.push( vertex.x, vertex.y, vertex.z );
  17205. // normal
  17206. normal.set( sinTheta, slope, cosTheta ).normalize();
  17207. normals.push( normal.x, normal.y, normal.z );
  17208. // uv
  17209. uvs.push( u, 1 - v );
  17210. // save index of vertex in respective row
  17211. indexRow.push( index ++ );
  17212. }
  17213. // now save vertices of the row in our index array
  17214. indexArray.push( indexRow );
  17215. }
  17216. // generate indices
  17217. for ( let x = 0; x < radialSegments; x ++ ) {
  17218. for ( let y = 0; y < heightSegments; y ++ ) {
  17219. // we use the index array to access the correct indices
  17220. const a = indexArray[ y ][ x ];
  17221. const b = indexArray[ y + 1 ][ x ];
  17222. const c = indexArray[ y + 1 ][ x + 1 ];
  17223. const d = indexArray[ y ][ x + 1 ];
  17224. // faces
  17225. indices.push( a, b, d );
  17226. indices.push( b, c, d );
  17227. // update group counter
  17228. groupCount += 6;
  17229. }
  17230. }
  17231. // add a group to the geometry. this will ensure multi material support
  17232. scope.addGroup( groupStart, groupCount, 0 );
  17233. // calculate new start value for groups
  17234. groupStart += groupCount;
  17235. }
  17236. function generateCap( top ) {
  17237. // save the index of the first center vertex
  17238. const centerIndexStart = index;
  17239. const uv = new Vector2();
  17240. const vertex = new Vector3();
  17241. let groupCount = 0;
  17242. const radius = ( top === true ) ? radiusTop : radiusBottom;
  17243. const sign = ( top === true ) ? 1 : - 1;
  17244. // first we generate the center vertex data of the cap.
  17245. // because the geometry needs one set of uvs per face,
  17246. // we must generate a center vertex per face/segment
  17247. for ( let x = 1; x <= radialSegments; x ++ ) {
  17248. // vertex
  17249. vertices.push( 0, halfHeight * sign, 0 );
  17250. // normal
  17251. normals.push( 0, sign, 0 );
  17252. // uv
  17253. uvs.push( 0.5, 0.5 );
  17254. // increase index
  17255. index ++;
  17256. }
  17257. // save the index of the last center vertex
  17258. const centerIndexEnd = index;
  17259. // now we generate the surrounding vertices, normals and uvs
  17260. for ( let x = 0; x <= radialSegments; x ++ ) {
  17261. const u = x / radialSegments;
  17262. const theta = u * thetaLength + thetaStart;
  17263. const cosTheta = Math.cos( theta );
  17264. const sinTheta = Math.sin( theta );
  17265. // vertex
  17266. vertex.x = radius * sinTheta;
  17267. vertex.y = halfHeight * sign;
  17268. vertex.z = radius * cosTheta;
  17269. vertices.push( vertex.x, vertex.y, vertex.z );
  17270. // normal
  17271. normals.push( 0, sign, 0 );
  17272. // uv
  17273. uv.x = ( cosTheta * 0.5 ) + 0.5;
  17274. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  17275. uvs.push( uv.x, uv.y );
  17276. // increase index
  17277. index ++;
  17278. }
  17279. // generate indices
  17280. for ( let x = 0; x < radialSegments; x ++ ) {
  17281. const c = centerIndexStart + x;
  17282. const i = centerIndexEnd + x;
  17283. if ( top === true ) {
  17284. // face top
  17285. indices.push( i, i + 1, c );
  17286. } else {
  17287. // face bottom
  17288. indices.push( i + 1, i, c );
  17289. }
  17290. groupCount += 3;
  17291. }
  17292. // add a group to the geometry. this will ensure multi material support
  17293. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  17294. // calculate new start value for groups
  17295. groupStart += groupCount;
  17296. }
  17297. }
  17298. }
  17299. class CylinderGeometry extends Geometry {
  17300. constructor( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17301. super();
  17302. this.type = 'CylinderGeometry';
  17303. this.parameters = {
  17304. radiusTop: radiusTop,
  17305. radiusBottom: radiusBottom,
  17306. height: height,
  17307. radialSegments: radialSegments,
  17308. heightSegments: heightSegments,
  17309. openEnded: openEnded,
  17310. thetaStart: thetaStart,
  17311. thetaLength: thetaLength
  17312. };
  17313. this.fromBufferGeometry( new CylinderBufferGeometry( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) );
  17314. this.mergeVertices();
  17315. }
  17316. }
  17317. class ConeGeometry extends CylinderGeometry {
  17318. constructor( radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  17319. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17320. this.type = 'ConeGeometry';
  17321. this.parameters = {
  17322. radius: radius,
  17323. height: height,
  17324. radialSegments: radialSegments,
  17325. heightSegments: heightSegments,
  17326. openEnded: openEnded,
  17327. thetaStart: thetaStart,
  17328. thetaLength: thetaLength
  17329. };
  17330. }
  17331. }
  17332. class ConeBufferGeometry extends CylinderBufferGeometry {
  17333. constructor( radius = 1, height = 1, radialSegments = 8, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  17334. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  17335. this.type = 'ConeBufferGeometry';
  17336. this.parameters = {
  17337. radius: radius,
  17338. height: height,
  17339. radialSegments: radialSegments,
  17340. heightSegments: heightSegments,
  17341. openEnded: openEnded,
  17342. thetaStart: thetaStart,
  17343. thetaLength: thetaLength
  17344. };
  17345. }
  17346. }
  17347. class PolyhedronBufferGeometry extends BufferGeometry {
  17348. constructor( vertices, indices, radius = 1, detail = 0 ) {
  17349. super();
  17350. this.type = 'PolyhedronBufferGeometry';
  17351. this.parameters = {
  17352. vertices: vertices,
  17353. indices: indices,
  17354. radius: radius,
  17355. detail: detail
  17356. };
  17357. // default buffer data
  17358. const vertexBuffer = [];
  17359. const uvBuffer = [];
  17360. // the subdivision creates the vertex buffer data
  17361. subdivide( detail );
  17362. // all vertices should lie on a conceptual sphere with a given radius
  17363. applyRadius( radius );
  17364. // finally, create the uv data
  17365. generateUVs();
  17366. // build non-indexed geometry
  17367. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  17368. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  17369. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  17370. if ( detail === 0 ) {
  17371. this.computeVertexNormals(); // flat normals
  17372. } else {
  17373. this.normalizeNormals(); // smooth normals
  17374. }
  17375. // helper functions
  17376. function subdivide( detail ) {
  17377. const a = new Vector3();
  17378. const b = new Vector3();
  17379. const c = new Vector3();
  17380. // iterate over all faces and apply a subdivison with the given detail value
  17381. for ( let i = 0; i < indices.length; i += 3 ) {
  17382. // get the vertices of the face
  17383. getVertexByIndex( indices[ i + 0 ], a );
  17384. getVertexByIndex( indices[ i + 1 ], b );
  17385. getVertexByIndex( indices[ i + 2 ], c );
  17386. // perform subdivision
  17387. subdivideFace( a, b, c, detail );
  17388. }
  17389. }
  17390. function subdivideFace( a, b, c, detail ) {
  17391. const cols = detail + 1;
  17392. // we use this multidimensional array as a data structure for creating the subdivision
  17393. const v = [];
  17394. // construct all of the vertices for this subdivision
  17395. for ( let i = 0; i <= cols; i ++ ) {
  17396. v[ i ] = [];
  17397. const aj = a.clone().lerp( c, i / cols );
  17398. const bj = b.clone().lerp( c, i / cols );
  17399. const rows = cols - i;
  17400. for ( let j = 0; j <= rows; j ++ ) {
  17401. if ( j === 0 && i === cols ) {
  17402. v[ i ][ j ] = aj;
  17403. } else {
  17404. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  17405. }
  17406. }
  17407. }
  17408. // construct all of the faces
  17409. for ( let i = 0; i < cols; i ++ ) {
  17410. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  17411. const k = Math.floor( j / 2 );
  17412. if ( j % 2 === 0 ) {
  17413. pushVertex( v[ i ][ k + 1 ] );
  17414. pushVertex( v[ i + 1 ][ k ] );
  17415. pushVertex( v[ i ][ k ] );
  17416. } else {
  17417. pushVertex( v[ i ][ k + 1 ] );
  17418. pushVertex( v[ i + 1 ][ k + 1 ] );
  17419. pushVertex( v[ i + 1 ][ k ] );
  17420. }
  17421. }
  17422. }
  17423. }
  17424. function applyRadius( radius ) {
  17425. const vertex = new Vector3();
  17426. // iterate over the entire buffer and apply the radius to each vertex
  17427. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  17428. vertex.x = vertexBuffer[ i + 0 ];
  17429. vertex.y = vertexBuffer[ i + 1 ];
  17430. vertex.z = vertexBuffer[ i + 2 ];
  17431. vertex.normalize().multiplyScalar( radius );
  17432. vertexBuffer[ i + 0 ] = vertex.x;
  17433. vertexBuffer[ i + 1 ] = vertex.y;
  17434. vertexBuffer[ i + 2 ] = vertex.z;
  17435. }
  17436. }
  17437. function generateUVs() {
  17438. const vertex = new Vector3();
  17439. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  17440. vertex.x = vertexBuffer[ i + 0 ];
  17441. vertex.y = vertexBuffer[ i + 1 ];
  17442. vertex.z = vertexBuffer[ i + 2 ];
  17443. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  17444. const v = inclination( vertex ) / Math.PI + 0.5;
  17445. uvBuffer.push( u, 1 - v );
  17446. }
  17447. correctUVs();
  17448. correctSeam();
  17449. }
  17450. function correctSeam() {
  17451. // handle case when face straddles the seam, see #3269
  17452. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  17453. // uv data of a single face
  17454. const x0 = uvBuffer[ i + 0 ];
  17455. const x1 = uvBuffer[ i + 2 ];
  17456. const x2 = uvBuffer[ i + 4 ];
  17457. const max = Math.max( x0, x1, x2 );
  17458. const min = Math.min( x0, x1, x2 );
  17459. // 0.9 is somewhat arbitrary
  17460. if ( max > 0.9 && min < 0.1 ) {
  17461. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  17462. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  17463. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  17464. }
  17465. }
  17466. }
  17467. function pushVertex( vertex ) {
  17468. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  17469. }
  17470. function getVertexByIndex( index, vertex ) {
  17471. const stride = index * 3;
  17472. vertex.x = vertices[ stride + 0 ];
  17473. vertex.y = vertices[ stride + 1 ];
  17474. vertex.z = vertices[ stride + 2 ];
  17475. }
  17476. function correctUVs() {
  17477. const a = new Vector3();
  17478. const b = new Vector3();
  17479. const c = new Vector3();
  17480. const centroid = new Vector3();
  17481. const uvA = new Vector2();
  17482. const uvB = new Vector2();
  17483. const uvC = new Vector2();
  17484. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  17485. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  17486. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  17487. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  17488. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  17489. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  17490. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  17491. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  17492. const azi = azimuth( centroid );
  17493. correctUV( uvA, j + 0, a, azi );
  17494. correctUV( uvB, j + 2, b, azi );
  17495. correctUV( uvC, j + 4, c, azi );
  17496. }
  17497. }
  17498. function correctUV( uv, stride, vector, azimuth ) {
  17499. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  17500. uvBuffer[ stride ] = uv.x - 1;
  17501. }
  17502. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  17503. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  17504. }
  17505. }
  17506. // Angle around the Y axis, counter-clockwise when looking from above.
  17507. function azimuth( vector ) {
  17508. return Math.atan2( vector.z, - vector.x );
  17509. }
  17510. // Angle above the XZ plane.
  17511. function inclination( vector ) {
  17512. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  17513. }
  17514. }
  17515. }
  17516. class DodecahedronBufferGeometry extends PolyhedronBufferGeometry {
  17517. constructor( radius = 1, detail = 0 ) {
  17518. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  17519. const r = 1 / t;
  17520. const vertices = [
  17521. // (±1, ±1, ±1)
  17522. - 1, - 1, - 1, - 1, - 1, 1,
  17523. - 1, 1, - 1, - 1, 1, 1,
  17524. 1, - 1, - 1, 1, - 1, 1,
  17525. 1, 1, - 1, 1, 1, 1,
  17526. // (0, ±1/φ, ±φ)
  17527. 0, - r, - t, 0, - r, t,
  17528. 0, r, - t, 0, r, t,
  17529. // (±1/φ, ±φ, 0)
  17530. - r, - t, 0, - r, t, 0,
  17531. r, - t, 0, r, t, 0,
  17532. // (±φ, 0, ±1/φ)
  17533. - t, 0, - r, t, 0, - r,
  17534. - t, 0, r, t, 0, r
  17535. ];
  17536. const indices = [
  17537. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  17538. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  17539. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  17540. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  17541. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  17542. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  17543. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  17544. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  17545. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  17546. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  17547. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  17548. 1, 12, 14, 1, 14, 5, 1, 5, 9
  17549. ];
  17550. super( vertices, indices, radius, detail );
  17551. this.type = 'DodecahedronBufferGeometry';
  17552. this.parameters = {
  17553. radius: radius,
  17554. detail: detail
  17555. };
  17556. }
  17557. }
  17558. class DodecahedronGeometry extends Geometry {
  17559. constructor( radius, detail ) {
  17560. super();
  17561. this.type = 'DodecahedronGeometry';
  17562. this.parameters = {
  17563. radius: radius,
  17564. detail: detail
  17565. };
  17566. this.fromBufferGeometry( new DodecahedronBufferGeometry( radius, detail ) );
  17567. this.mergeVertices();
  17568. }
  17569. }
  17570. const _v0$2 = new Vector3();
  17571. const _v1$5 = new Vector3();
  17572. const _normal$1 = new Vector3();
  17573. const _triangle = new Triangle();
  17574. class EdgesGeometry extends BufferGeometry {
  17575. constructor( geometry, thresholdAngle ) {
  17576. super();
  17577. this.type = 'EdgesGeometry';
  17578. this.parameters = {
  17579. thresholdAngle: thresholdAngle
  17580. };
  17581. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  17582. if ( geometry.isGeometry ) {
  17583. geometry = new BufferGeometry().fromGeometry( geometry );
  17584. }
  17585. const precisionPoints = 4;
  17586. const precision = Math.pow( 10, precisionPoints );
  17587. const thresholdDot = Math.cos( MathUtils.DEG2RAD * thresholdAngle );
  17588. const indexAttr = geometry.getIndex();
  17589. const positionAttr = geometry.getAttribute( 'position' );
  17590. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  17591. const indexArr = [ 0, 0, 0 ];
  17592. const vertKeys = [ 'a', 'b', 'c' ];
  17593. const hashes = new Array( 3 );
  17594. const edgeData = {};
  17595. const vertices = [];
  17596. for ( let i = 0; i < indexCount; i += 3 ) {
  17597. if ( indexAttr ) {
  17598. indexArr[ 0 ] = indexAttr.getX( i );
  17599. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  17600. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  17601. } else {
  17602. indexArr[ 0 ] = i;
  17603. indexArr[ 1 ] = i + 1;
  17604. indexArr[ 2 ] = i + 2;
  17605. }
  17606. const { a, b, c } = _triangle;
  17607. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  17608. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  17609. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  17610. _triangle.getNormal( _normal$1 );
  17611. // create hashes for the edge from the vertices
  17612. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  17613. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  17614. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  17615. // skip degenerate triangles
  17616. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  17617. continue;
  17618. }
  17619. // iterate over every edge
  17620. for ( let j = 0; j < 3; j ++ ) {
  17621. // get the first and next vertex making up the edge
  17622. const jNext = ( j + 1 ) % 3;
  17623. const vecHash0 = hashes[ j ];
  17624. const vecHash1 = hashes[ jNext ];
  17625. const v0 = _triangle[ vertKeys[ j ] ];
  17626. const v1 = _triangle[ vertKeys[ jNext ] ];
  17627. const hash = `${ vecHash0 }_${ vecHash1 }`;
  17628. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  17629. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  17630. // if we found a sibling edge add it into the vertex array if
  17631. // it meets the angle threshold and delete the edge from the map.
  17632. if ( _normal$1.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  17633. vertices.push( v0.x, v0.y, v0.z );
  17634. vertices.push( v1.x, v1.y, v1.z );
  17635. }
  17636. edgeData[ reverseHash ] = null;
  17637. } else if ( ! ( hash in edgeData ) ) {
  17638. // if we've already got an edge here then skip adding a new one
  17639. edgeData[ hash ] = {
  17640. index0: indexArr[ j ],
  17641. index1: indexArr[ jNext ],
  17642. normal: _normal$1.clone(),
  17643. };
  17644. }
  17645. }
  17646. }
  17647. // iterate over all remaining, unmatched edges and add them to the vertex array
  17648. for ( const key in edgeData ) {
  17649. if ( edgeData[ key ] ) {
  17650. const { index0, index1 } = edgeData[ key ];
  17651. _v0$2.fromBufferAttribute( positionAttr, index0 );
  17652. _v1$5.fromBufferAttribute( positionAttr, index1 );
  17653. vertices.push( _v0$2.x, _v0$2.y, _v0$2.z );
  17654. vertices.push( _v1$5.x, _v1$5.y, _v1$5.z );
  17655. }
  17656. }
  17657. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  17658. }
  17659. }
  17660. /**
  17661. * Port from https://github.com/mapbox/earcut (v2.2.2)
  17662. */
  17663. const Earcut = {
  17664. triangulate: function ( data, holeIndices, dim ) {
  17665. dim = dim || 2;
  17666. const hasHoles = holeIndices && holeIndices.length;
  17667. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  17668. let outerNode = linkedList( data, 0, outerLen, dim, true );
  17669. const triangles = [];
  17670. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  17671. let minX, minY, maxX, maxY, x, y, invSize;
  17672. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  17673. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  17674. if ( data.length > 80 * dim ) {
  17675. minX = maxX = data[ 0 ];
  17676. minY = maxY = data[ 1 ];
  17677. for ( let i = dim; i < outerLen; i += dim ) {
  17678. x = data[ i ];
  17679. y = data[ i + 1 ];
  17680. if ( x < minX ) minX = x;
  17681. if ( y < minY ) minY = y;
  17682. if ( x > maxX ) maxX = x;
  17683. if ( y > maxY ) maxY = y;
  17684. }
  17685. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  17686. invSize = Math.max( maxX - minX, maxY - minY );
  17687. invSize = invSize !== 0 ? 1 / invSize : 0;
  17688. }
  17689. earcutLinked( outerNode, triangles, dim, minX, minY, invSize );
  17690. return triangles;
  17691. }
  17692. };
  17693. // create a circular doubly linked list from polygon points in the specified winding order
  17694. function linkedList( data, start, end, dim, clockwise ) {
  17695. let i, last;
  17696. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  17697. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17698. } else {
  17699. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  17700. }
  17701. if ( last && equals( last, last.next ) ) {
  17702. removeNode( last );
  17703. last = last.next;
  17704. }
  17705. return last;
  17706. }
  17707. // eliminate colinear or duplicate points
  17708. function filterPoints( start, end ) {
  17709. if ( ! start ) return start;
  17710. if ( ! end ) end = start;
  17711. let p = start,
  17712. again;
  17713. do {
  17714. again = false;
  17715. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  17716. removeNode( p );
  17717. p = end = p.prev;
  17718. if ( p === p.next ) break;
  17719. again = true;
  17720. } else {
  17721. p = p.next;
  17722. }
  17723. } while ( again || p !== end );
  17724. return end;
  17725. }
  17726. // main ear slicing loop which triangulates a polygon (given as a linked list)
  17727. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  17728. if ( ! ear ) return;
  17729. // interlink polygon nodes in z-order
  17730. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  17731. let stop = ear,
  17732. prev, next;
  17733. // iterate through ears, slicing them one by one
  17734. while ( ear.prev !== ear.next ) {
  17735. prev = ear.prev;
  17736. next = ear.next;
  17737. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  17738. // cut off the triangle
  17739. triangles.push( prev.i / dim );
  17740. triangles.push( ear.i / dim );
  17741. triangles.push( next.i / dim );
  17742. removeNode( ear );
  17743. // skipping the next vertex leads to less sliver triangles
  17744. ear = next.next;
  17745. stop = next.next;
  17746. continue;
  17747. }
  17748. ear = next;
  17749. // if we looped through the whole remaining polygon and can't find any more ears
  17750. if ( ear === stop ) {
  17751. // try filtering points and slicing again
  17752. if ( ! pass ) {
  17753. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  17754. // if this didn't work, try curing all small self-intersections locally
  17755. } else if ( pass === 1 ) {
  17756. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  17757. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  17758. // as a last resort, try splitting the remaining polygon into two
  17759. } else if ( pass === 2 ) {
  17760. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  17761. }
  17762. break;
  17763. }
  17764. }
  17765. }
  17766. // check whether a polygon node forms a valid ear with adjacent nodes
  17767. function isEar( ear ) {
  17768. const a = ear.prev,
  17769. b = ear,
  17770. c = ear.next;
  17771. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17772. // now make sure we don't have other points inside the potential ear
  17773. let p = ear.next.next;
  17774. while ( p !== ear.prev ) {
  17775. if ( pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17776. area( p.prev, p, p.next ) >= 0 ) return false;
  17777. p = p.next;
  17778. }
  17779. return true;
  17780. }
  17781. function isEarHashed( ear, minX, minY, invSize ) {
  17782. const a = ear.prev,
  17783. b = ear,
  17784. c = ear.next;
  17785. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  17786. // triangle bbox; min & max are calculated like this for speed
  17787. const minTX = a.x < b.x ? ( a.x < c.x ? a.x : c.x ) : ( b.x < c.x ? b.x : c.x ),
  17788. minTY = a.y < b.y ? ( a.y < c.y ? a.y : c.y ) : ( b.y < c.y ? b.y : c.y ),
  17789. maxTX = a.x > b.x ? ( a.x > c.x ? a.x : c.x ) : ( b.x > c.x ? b.x : c.x ),
  17790. maxTY = a.y > b.y ? ( a.y > c.y ? a.y : c.y ) : ( b.y > c.y ? b.y : c.y );
  17791. // z-order range for the current triangle bbox;
  17792. const minZ = zOrder( minTX, minTY, minX, minY, invSize ),
  17793. maxZ = zOrder( maxTX, maxTY, minX, minY, invSize );
  17794. let p = ear.prevZ,
  17795. n = ear.nextZ;
  17796. // look for points inside the triangle in both directions
  17797. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  17798. if ( p !== ear.prev && p !== ear.next &&
  17799. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17800. area( p.prev, p, p.next ) >= 0 ) return false;
  17801. p = p.prevZ;
  17802. if ( n !== ear.prev && n !== ear.next &&
  17803. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17804. area( n.prev, n, n.next ) >= 0 ) return false;
  17805. n = n.nextZ;
  17806. }
  17807. // look for remaining points in decreasing z-order
  17808. while ( p && p.z >= minZ ) {
  17809. if ( p !== ear.prev && p !== ear.next &&
  17810. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y ) &&
  17811. area( p.prev, p, p.next ) >= 0 ) return false;
  17812. p = p.prevZ;
  17813. }
  17814. // look for remaining points in increasing z-order
  17815. while ( n && n.z <= maxZ ) {
  17816. if ( n !== ear.prev && n !== ear.next &&
  17817. pointInTriangle( a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y ) &&
  17818. area( n.prev, n, n.next ) >= 0 ) return false;
  17819. n = n.nextZ;
  17820. }
  17821. return true;
  17822. }
  17823. // go through all polygon nodes and cure small local self-intersections
  17824. function cureLocalIntersections( start, triangles, dim ) {
  17825. let p = start;
  17826. do {
  17827. const a = p.prev,
  17828. b = p.next.next;
  17829. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  17830. triangles.push( a.i / dim );
  17831. triangles.push( p.i / dim );
  17832. triangles.push( b.i / dim );
  17833. // remove two nodes involved
  17834. removeNode( p );
  17835. removeNode( p.next );
  17836. p = start = b;
  17837. }
  17838. p = p.next;
  17839. } while ( p !== start );
  17840. return filterPoints( p );
  17841. }
  17842. // try splitting polygon into two and triangulate them independently
  17843. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  17844. // look for a valid diagonal that divides the polygon into two
  17845. let a = start;
  17846. do {
  17847. let b = a.next.next;
  17848. while ( b !== a.prev ) {
  17849. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  17850. // split the polygon in two by the diagonal
  17851. let c = splitPolygon( a, b );
  17852. // filter colinear points around the cuts
  17853. a = filterPoints( a, a.next );
  17854. c = filterPoints( c, c.next );
  17855. // run earcut on each half
  17856. earcutLinked( a, triangles, dim, minX, minY, invSize );
  17857. earcutLinked( c, triangles, dim, minX, minY, invSize );
  17858. return;
  17859. }
  17860. b = b.next;
  17861. }
  17862. a = a.next;
  17863. } while ( a !== start );
  17864. }
  17865. // link every hole into the outer loop, producing a single-ring polygon without holes
  17866. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  17867. const queue = [];
  17868. let i, len, start, end, list;
  17869. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  17870. start = holeIndices[ i ] * dim;
  17871. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  17872. list = linkedList( data, start, end, dim, false );
  17873. if ( list === list.next ) list.steiner = true;
  17874. queue.push( getLeftmost( list ) );
  17875. }
  17876. queue.sort( compareX );
  17877. // process holes from left to right
  17878. for ( i = 0; i < queue.length; i ++ ) {
  17879. eliminateHole( queue[ i ], outerNode );
  17880. outerNode = filterPoints( outerNode, outerNode.next );
  17881. }
  17882. return outerNode;
  17883. }
  17884. function compareX( a, b ) {
  17885. return a.x - b.x;
  17886. }
  17887. // find a bridge between vertices that connects hole with an outer ring and and link it
  17888. function eliminateHole( hole, outerNode ) {
  17889. outerNode = findHoleBridge( hole, outerNode );
  17890. if ( outerNode ) {
  17891. const b = splitPolygon( outerNode, hole );
  17892. // filter collinear points around the cuts
  17893. filterPoints( outerNode, outerNode.next );
  17894. filterPoints( b, b.next );
  17895. }
  17896. }
  17897. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  17898. function findHoleBridge( hole, outerNode ) {
  17899. let p = outerNode;
  17900. const hx = hole.x;
  17901. const hy = hole.y;
  17902. let qx = - Infinity, m;
  17903. // find a segment intersected by a ray from the hole's leftmost point to the left;
  17904. // segment's endpoint with lesser x will be potential connection point
  17905. do {
  17906. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  17907. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  17908. if ( x <= hx && x > qx ) {
  17909. qx = x;
  17910. if ( x === hx ) {
  17911. if ( hy === p.y ) return p;
  17912. if ( hy === p.next.y ) return p.next;
  17913. }
  17914. m = p.x < p.next.x ? p : p.next;
  17915. }
  17916. }
  17917. p = p.next;
  17918. } while ( p !== outerNode );
  17919. if ( ! m ) return null;
  17920. if ( hx === qx ) return m; // hole touches outer segment; pick leftmost endpoint
  17921. // look for points inside the triangle of hole point, segment intersection and endpoint;
  17922. // if there are no points found, we have a valid connection;
  17923. // otherwise choose the point of the minimum angle with the ray as connection point
  17924. const stop = m,
  17925. mx = m.x,
  17926. my = m.y;
  17927. let tanMin = Infinity, tan;
  17928. p = m;
  17929. do {
  17930. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  17931. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  17932. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  17933. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  17934. m = p;
  17935. tanMin = tan;
  17936. }
  17937. }
  17938. p = p.next;
  17939. } while ( p !== stop );
  17940. return m;
  17941. }
  17942. // whether sector in vertex m contains sector in vertex p in the same coordinates
  17943. function sectorContainsSector( m, p ) {
  17944. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  17945. }
  17946. // interlink polygon nodes in z-order
  17947. function indexCurve( start, minX, minY, invSize ) {
  17948. let p = start;
  17949. do {
  17950. if ( p.z === null ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  17951. p.prevZ = p.prev;
  17952. p.nextZ = p.next;
  17953. p = p.next;
  17954. } while ( p !== start );
  17955. p.prevZ.nextZ = null;
  17956. p.prevZ = null;
  17957. sortLinked( p );
  17958. }
  17959. // Simon Tatham's linked list merge sort algorithm
  17960. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  17961. function sortLinked( list ) {
  17962. let i, p, q, e, tail, numMerges, pSize, qSize,
  17963. inSize = 1;
  17964. do {
  17965. p = list;
  17966. list = null;
  17967. tail = null;
  17968. numMerges = 0;
  17969. while ( p ) {
  17970. numMerges ++;
  17971. q = p;
  17972. pSize = 0;
  17973. for ( i = 0; i < inSize; i ++ ) {
  17974. pSize ++;
  17975. q = q.nextZ;
  17976. if ( ! q ) break;
  17977. }
  17978. qSize = inSize;
  17979. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  17980. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  17981. e = p;
  17982. p = p.nextZ;
  17983. pSize --;
  17984. } else {
  17985. e = q;
  17986. q = q.nextZ;
  17987. qSize --;
  17988. }
  17989. if ( tail ) tail.nextZ = e;
  17990. else list = e;
  17991. e.prevZ = tail;
  17992. tail = e;
  17993. }
  17994. p = q;
  17995. }
  17996. tail.nextZ = null;
  17997. inSize *= 2;
  17998. } while ( numMerges > 1 );
  17999. return list;
  18000. }
  18001. // z-order of a point given coords and inverse of the longer side of data bbox
  18002. function zOrder( x, y, minX, minY, invSize ) {
  18003. // coords are transformed into non-negative 15-bit integer range
  18004. x = 32767 * ( x - minX ) * invSize;
  18005. y = 32767 * ( y - minY ) * invSize;
  18006. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  18007. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  18008. x = ( x | ( x << 2 ) ) & 0x33333333;
  18009. x = ( x | ( x << 1 ) ) & 0x55555555;
  18010. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  18011. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  18012. y = ( y | ( y << 2 ) ) & 0x33333333;
  18013. y = ( y | ( y << 1 ) ) & 0x55555555;
  18014. return x | ( y << 1 );
  18015. }
  18016. // find the leftmost node of a polygon ring
  18017. function getLeftmost( start ) {
  18018. let p = start,
  18019. leftmost = start;
  18020. do {
  18021. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  18022. p = p.next;
  18023. } while ( p !== start );
  18024. return leftmost;
  18025. }
  18026. // check if a point lies within a convex triangle
  18027. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  18028. return ( cx - px ) * ( ay - py ) - ( ax - px ) * ( cy - py ) >= 0 &&
  18029. ( ax - px ) * ( by - py ) - ( bx - px ) * ( ay - py ) >= 0 &&
  18030. ( bx - px ) * ( cy - py ) - ( cx - px ) * ( by - py ) >= 0;
  18031. }
  18032. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  18033. function isValidDiagonal( a, b ) {
  18034. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  18035. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  18036. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  18037. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  18038. }
  18039. // signed area of a triangle
  18040. function area( p, q, r ) {
  18041. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  18042. }
  18043. // check if two points are equal
  18044. function equals( p1, p2 ) {
  18045. return p1.x === p2.x && p1.y === p2.y;
  18046. }
  18047. // check if two segments intersect
  18048. function intersects( p1, q1, p2, q2 ) {
  18049. const o1 = sign( area( p1, q1, p2 ) );
  18050. const o2 = sign( area( p1, q1, q2 ) );
  18051. const o3 = sign( area( p2, q2, p1 ) );
  18052. const o4 = sign( area( p2, q2, q1 ) );
  18053. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  18054. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  18055. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  18056. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  18057. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  18058. return false;
  18059. }
  18060. // for collinear points p, q, r, check if point q lies on segment pr
  18061. function onSegment( p, q, r ) {
  18062. 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 );
  18063. }
  18064. function sign( num ) {
  18065. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  18066. }
  18067. // check if a polygon diagonal intersects any polygon segments
  18068. function intersectsPolygon( a, b ) {
  18069. let p = a;
  18070. do {
  18071. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  18072. intersects( p, p.next, a, b ) ) return true;
  18073. p = p.next;
  18074. } while ( p !== a );
  18075. return false;
  18076. }
  18077. // check if a polygon diagonal is locally inside the polygon
  18078. function locallyInside( a, b ) {
  18079. return area( a.prev, a, a.next ) < 0 ?
  18080. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  18081. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  18082. }
  18083. // check if the middle point of a polygon diagonal is inside the polygon
  18084. function middleInside( a, b ) {
  18085. let p = a,
  18086. inside = false;
  18087. const px = ( a.x + b.x ) / 2,
  18088. py = ( a.y + b.y ) / 2;
  18089. do {
  18090. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  18091. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  18092. inside = ! inside;
  18093. p = p.next;
  18094. } while ( p !== a );
  18095. return inside;
  18096. }
  18097. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  18098. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  18099. function splitPolygon( a, b ) {
  18100. const a2 = new Node( a.i, a.x, a.y ),
  18101. b2 = new Node( b.i, b.x, b.y ),
  18102. an = a.next,
  18103. bp = b.prev;
  18104. a.next = b;
  18105. b.prev = a;
  18106. a2.next = an;
  18107. an.prev = a2;
  18108. b2.next = a2;
  18109. a2.prev = b2;
  18110. bp.next = b2;
  18111. b2.prev = bp;
  18112. return b2;
  18113. }
  18114. // create a node and optionally link it with previous one (in a circular doubly linked list)
  18115. function insertNode( i, x, y, last ) {
  18116. const p = new Node( i, x, y );
  18117. if ( ! last ) {
  18118. p.prev = p;
  18119. p.next = p;
  18120. } else {
  18121. p.next = last.next;
  18122. p.prev = last;
  18123. last.next.prev = p;
  18124. last.next = p;
  18125. }
  18126. return p;
  18127. }
  18128. function removeNode( p ) {
  18129. p.next.prev = p.prev;
  18130. p.prev.next = p.next;
  18131. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  18132. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  18133. }
  18134. function Node( i, x, y ) {
  18135. // vertex index in coordinates array
  18136. this.i = i;
  18137. // vertex coordinates
  18138. this.x = x;
  18139. this.y = y;
  18140. // previous and next vertex nodes in a polygon ring
  18141. this.prev = null;
  18142. this.next = null;
  18143. // z-order curve value
  18144. this.z = null;
  18145. // previous and next nodes in z-order
  18146. this.prevZ = null;
  18147. this.nextZ = null;
  18148. // indicates whether this is a steiner point
  18149. this.steiner = false;
  18150. }
  18151. function signedArea( data, start, end, dim ) {
  18152. let sum = 0;
  18153. for ( let i = start, j = end - dim; i < end; i += dim ) {
  18154. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  18155. j = i;
  18156. }
  18157. return sum;
  18158. }
  18159. const ShapeUtils = {
  18160. // calculate area of the contour polygon
  18161. area: function ( contour ) {
  18162. const n = contour.length;
  18163. let a = 0.0;
  18164. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  18165. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  18166. }
  18167. return a * 0.5;
  18168. },
  18169. isClockWise: function ( pts ) {
  18170. return ShapeUtils.area( pts ) < 0;
  18171. },
  18172. triangulateShape: function ( contour, holes ) {
  18173. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  18174. const holeIndices = []; // array of hole indices
  18175. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  18176. removeDupEndPts( contour );
  18177. addContour( vertices, contour );
  18178. //
  18179. let holeIndex = contour.length;
  18180. holes.forEach( removeDupEndPts );
  18181. for ( let i = 0; i < holes.length; i ++ ) {
  18182. holeIndices.push( holeIndex );
  18183. holeIndex += holes[ i ].length;
  18184. addContour( vertices, holes[ i ] );
  18185. }
  18186. //
  18187. const triangles = Earcut.triangulate( vertices, holeIndices );
  18188. //
  18189. for ( let i = 0; i < triangles.length; i += 3 ) {
  18190. faces.push( triangles.slice( i, i + 3 ) );
  18191. }
  18192. return faces;
  18193. }
  18194. };
  18195. function removeDupEndPts( points ) {
  18196. const l = points.length;
  18197. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  18198. points.pop();
  18199. }
  18200. }
  18201. function addContour( vertices, contour ) {
  18202. for ( let i = 0; i < contour.length; i ++ ) {
  18203. vertices.push( contour[ i ].x );
  18204. vertices.push( contour[ i ].y );
  18205. }
  18206. }
  18207. /**
  18208. * Creates extruded geometry from a path shape.
  18209. *
  18210. * parameters = {
  18211. *
  18212. * curveSegments: <int>, // number of points on the curves
  18213. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18214. * depth: <float>, // Depth to extrude the shape
  18215. *
  18216. * bevelEnabled: <bool>, // turn on bevel
  18217. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18218. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18219. * bevelOffset: <float>, // how far from shape outline does bevel start
  18220. * bevelSegments: <int>, // number of bevel layers
  18221. *
  18222. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18223. *
  18224. * UVGenerator: <Object> // object that provides UV generator functions
  18225. *
  18226. * }
  18227. */
  18228. class ExtrudeBufferGeometry extends BufferGeometry {
  18229. constructor( shapes, options ) {
  18230. super();
  18231. this.type = 'ExtrudeBufferGeometry';
  18232. this.parameters = {
  18233. shapes: shapes,
  18234. options: options
  18235. };
  18236. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18237. const scope = this;
  18238. const verticesArray = [];
  18239. const uvArray = [];
  18240. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  18241. const shape = shapes[ i ];
  18242. addShape( shape );
  18243. }
  18244. // build geometry
  18245. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  18246. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  18247. this.computeVertexNormals();
  18248. // functions
  18249. function addShape( shape ) {
  18250. const placeholder = [];
  18251. // options
  18252. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18253. const steps = options.steps !== undefined ? options.steps : 1;
  18254. let depth = options.depth !== undefined ? options.depth : 100;
  18255. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  18256. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6;
  18257. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2;
  18258. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  18259. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18260. const extrudePath = options.extrudePath;
  18261. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  18262. // deprecated options
  18263. if ( options.amount !== undefined ) {
  18264. console.warn( 'THREE.ExtrudeBufferGeometry: amount has been renamed to depth.' );
  18265. depth = options.amount;
  18266. }
  18267. //
  18268. let extrudePts, extrudeByPath = false;
  18269. let splineTube, binormal, normal, position2;
  18270. if ( extrudePath ) {
  18271. extrudePts = extrudePath.getSpacedPoints( steps );
  18272. extrudeByPath = true;
  18273. bevelEnabled = false; // bevels not supported for path extrusion
  18274. // SETUP TNB variables
  18275. // TODO1 - have a .isClosed in spline?
  18276. splineTube = extrudePath.computeFrenetFrames( steps, false );
  18277. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18278. binormal = new Vector3();
  18279. normal = new Vector3();
  18280. position2 = new Vector3();
  18281. }
  18282. // Safeguards if bevels are not enabled
  18283. if ( ! bevelEnabled ) {
  18284. bevelSegments = 0;
  18285. bevelThickness = 0;
  18286. bevelSize = 0;
  18287. bevelOffset = 0;
  18288. }
  18289. // Variables initialization
  18290. const shapePoints = shape.extractPoints( curveSegments );
  18291. let vertices = shapePoints.shape;
  18292. const holes = shapePoints.holes;
  18293. const reverse = ! ShapeUtils.isClockWise( vertices );
  18294. if ( reverse ) {
  18295. vertices = vertices.reverse();
  18296. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18297. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18298. const ahole = holes[ h ];
  18299. if ( ShapeUtils.isClockWise( ahole ) ) {
  18300. holes[ h ] = ahole.reverse();
  18301. }
  18302. }
  18303. }
  18304. const faces = ShapeUtils.triangulateShape( vertices, holes );
  18305. /* Vertices */
  18306. const contour = vertices; // vertices has all points but contour has only points of circumference
  18307. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18308. const ahole = holes[ h ];
  18309. vertices = vertices.concat( ahole );
  18310. }
  18311. function scalePt2( pt, vec, size ) {
  18312. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  18313. return vec.clone().multiplyScalar( size ).add( pt );
  18314. }
  18315. const vlen = vertices.length, flen = faces.length;
  18316. // Find directions for point movement
  18317. function getBevelVec( inPt, inPrev, inNext ) {
  18318. // computes for inPt the corresponding point inPt' on a new contour
  18319. // shifted by 1 unit (length of normalized vector) to the left
  18320. // if we walk along contour clockwise, this new contour is outside the old one
  18321. //
  18322. // inPt' is the intersection of the two lines parallel to the two
  18323. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18324. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  18325. // good reading for geometry algorithms (here: line-line intersection)
  18326. // http://geomalgorithms.com/a05-_intersect-1.html
  18327. const v_prev_x = inPt.x - inPrev.x,
  18328. v_prev_y = inPt.y - inPrev.y;
  18329. const v_next_x = inNext.x - inPt.x,
  18330. v_next_y = inNext.y - inPt.y;
  18331. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18332. // check for collinear edges
  18333. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18334. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  18335. // not collinear
  18336. // length of vectors for normalizing
  18337. const v_prev_len = Math.sqrt( v_prev_lensq );
  18338. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18339. // shift adjacent points by unit vectors to the left
  18340. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18341. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18342. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18343. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18344. // scaling factor for v_prev to intersection point
  18345. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18346. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18347. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18348. // vector from inPt to intersection point
  18349. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18350. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18351. // Don't normalize!, otherwise sharp corners become ugly
  18352. // but prevent crazy spikes
  18353. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18354. if ( v_trans_lensq <= 2 ) {
  18355. return new Vector2( v_trans_x, v_trans_y );
  18356. } else {
  18357. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18358. }
  18359. } else {
  18360. // handle special case of collinear edges
  18361. let direction_eq = false; // assumes: opposite
  18362. if ( v_prev_x > Number.EPSILON ) {
  18363. if ( v_next_x > Number.EPSILON ) {
  18364. direction_eq = true;
  18365. }
  18366. } else {
  18367. if ( v_prev_x < - Number.EPSILON ) {
  18368. if ( v_next_x < - Number.EPSILON ) {
  18369. direction_eq = true;
  18370. }
  18371. } else {
  18372. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18373. direction_eq = true;
  18374. }
  18375. }
  18376. }
  18377. if ( direction_eq ) {
  18378. // console.log("Warning: lines are a straight sequence");
  18379. v_trans_x = - v_prev_y;
  18380. v_trans_y = v_prev_x;
  18381. shrink_by = Math.sqrt( v_prev_lensq );
  18382. } else {
  18383. // console.log("Warning: lines are a straight spike");
  18384. v_trans_x = v_prev_x;
  18385. v_trans_y = v_prev_y;
  18386. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18387. }
  18388. }
  18389. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18390. }
  18391. const contourMovements = [];
  18392. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18393. if ( j === il ) j = 0;
  18394. if ( k === il ) k = 0;
  18395. // (j)---(i)---(k)
  18396. // console.log('i,j,k', i, j , k)
  18397. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18398. }
  18399. const holesMovements = [];
  18400. let oneHoleMovements, verticesMovements = contourMovements.concat();
  18401. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18402. const ahole = holes[ h ];
  18403. oneHoleMovements = [];
  18404. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18405. if ( j === il ) j = 0;
  18406. if ( k === il ) k = 0;
  18407. // (j)---(i)---(k)
  18408. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18409. }
  18410. holesMovements.push( oneHoleMovements );
  18411. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18412. }
  18413. // Loop bevelSegments, 1 for the front, 1 for the back
  18414. for ( let b = 0; b < bevelSegments; b ++ ) {
  18415. //for ( b = bevelSegments; b > 0; b -- ) {
  18416. const t = b / bevelSegments;
  18417. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18418. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18419. // contract shape
  18420. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  18421. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18422. v( vert.x, vert.y, - z );
  18423. }
  18424. // expand holes
  18425. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18426. const ahole = holes[ h ];
  18427. oneHoleMovements = holesMovements[ h ];
  18428. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  18429. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18430. v( vert.x, vert.y, - z );
  18431. }
  18432. }
  18433. }
  18434. const bs = bevelSize + bevelOffset;
  18435. // Back facing vertices
  18436. for ( let i = 0; i < vlen; i ++ ) {
  18437. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18438. if ( ! extrudeByPath ) {
  18439. v( vert.x, vert.y, 0 );
  18440. } else {
  18441. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18442. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18443. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18444. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18445. v( position2.x, position2.y, position2.z );
  18446. }
  18447. }
  18448. // Add stepped vertices...
  18449. // Including front facing vertices
  18450. for ( let s = 1; s <= steps; s ++ ) {
  18451. for ( let i = 0; i < vlen; i ++ ) {
  18452. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18453. if ( ! extrudeByPath ) {
  18454. v( vert.x, vert.y, depth / steps * s );
  18455. } else {
  18456. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18457. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18458. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18459. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18460. v( position2.x, position2.y, position2.z );
  18461. }
  18462. }
  18463. }
  18464. // Add bevel segments planes
  18465. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18466. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  18467. const t = b / bevelSegments;
  18468. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  18469. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  18470. // contract shape
  18471. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  18472. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18473. v( vert.x, vert.y, depth + z );
  18474. }
  18475. // expand holes
  18476. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18477. const ahole = holes[ h ];
  18478. oneHoleMovements = holesMovements[ h ];
  18479. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  18480. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18481. if ( ! extrudeByPath ) {
  18482. v( vert.x, vert.y, depth + z );
  18483. } else {
  18484. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  18485. }
  18486. }
  18487. }
  18488. }
  18489. /* Faces */
  18490. // Top and bottom faces
  18491. if(!options.openEnded){//xzw add 可以选择开口,不创建Top and bottom faces
  18492. buildLidFaces();
  18493. }
  18494. // Sides faces
  18495. buildSideFaces();
  18496. ///// Internal functions
  18497. function buildLidFaces() {
  18498. const start = verticesArray.length / 3;
  18499. if ( bevelEnabled ) {
  18500. let layer = 0; // steps + 1
  18501. let offset = vlen * layer;
  18502. // Bottom faces
  18503. for ( let i = 0; i < flen; i ++ ) {
  18504. const face = faces[ i ];
  18505. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  18506. }
  18507. layer = steps + bevelSegments * 2;
  18508. offset = vlen * layer;
  18509. // Top faces
  18510. for ( let i = 0; i < flen; i ++ ) {
  18511. const face = faces[ i ];
  18512. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  18513. }
  18514. } else {
  18515. // Bottom faces
  18516. for ( let i = 0; i < flen; i ++ ) {
  18517. const face = faces[ i ];
  18518. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  18519. }
  18520. // Top faces
  18521. for ( let i = 0; i < flen; i ++ ) {
  18522. const face = faces[ i ];
  18523. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  18524. }
  18525. }
  18526. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  18527. }
  18528. // Create faces for the z-sides of the shape
  18529. function buildSideFaces() {
  18530. const start = verticesArray.length / 3;
  18531. let layeroffset = 0;
  18532. sidewalls( contour, layeroffset );
  18533. layeroffset += contour.length;
  18534. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  18535. const ahole = holes[ h ];
  18536. sidewalls( ahole, layeroffset );
  18537. //, true
  18538. layeroffset += ahole.length;
  18539. }
  18540. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  18541. }
  18542. function sidewalls( contour, layeroffset) {
  18543. let i = contour.length;
  18544. let shapeDontClose = shape.dontClose; //xzw add不闭合
  18545. while ( -- i >= 0 ) {
  18546. if(shapeDontClose && i==0)break; //xzw add
  18547. const j = i;
  18548. let k = i - 1;
  18549. if ( k < 0 ) k = contour.length - 1;
  18550. //console.log('b', i,j, i-1, k,vertices.length);
  18551. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  18552. const slen1 = vlen * s;
  18553. const slen2 = vlen * ( s + 1 );
  18554. const a = layeroffset + j + slen1,
  18555. b = layeroffset + k + slen1,
  18556. c = layeroffset + k + slen2,
  18557. d = layeroffset + j + slen2;
  18558. f4( a, b, c, d );
  18559. }
  18560. }
  18561. }
  18562. function v( x, y, z ) {
  18563. placeholder.push( x );
  18564. placeholder.push( y );
  18565. placeholder.push( z );
  18566. }
  18567. function f3( a, b, c ) {
  18568. addVertex( a );
  18569. addVertex( b );
  18570. addVertex( c );
  18571. const nextIndex = verticesArray.length / 3;
  18572. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18573. addUV( uvs[ 0 ] );
  18574. addUV( uvs[ 1 ] );
  18575. addUV( uvs[ 2 ] );
  18576. }
  18577. function f4( a, b, c, d ) {
  18578. addVertex( a );
  18579. addVertex( b );
  18580. addVertex( d );
  18581. addVertex( b );
  18582. addVertex( c );
  18583. addVertex( d );
  18584. const nextIndex = verticesArray.length / 3;
  18585. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  18586. addUV( uvs[ 0 ] );
  18587. addUV( uvs[ 1 ] );
  18588. addUV( uvs[ 3 ] );
  18589. addUV( uvs[ 1 ] );
  18590. addUV( uvs[ 2 ] );
  18591. addUV( uvs[ 3 ] );
  18592. }
  18593. function addVertex( index ) {
  18594. verticesArray.push( placeholder[ index * 3 + 0 ] );
  18595. verticesArray.push( placeholder[ index * 3 + 1 ] );
  18596. verticesArray.push( placeholder[ index * 3 + 2 ] );
  18597. }
  18598. function addUV( vector2 ) {
  18599. uvArray.push( vector2.x );
  18600. uvArray.push( vector2.y );
  18601. }
  18602. }
  18603. }
  18604. toJSON() {
  18605. const data = BufferGeometry.prototype.toJSON.call( this );
  18606. const shapes = this.parameters.shapes;
  18607. const options = this.parameters.options;
  18608. return toJSON( shapes, options, data );
  18609. }
  18610. }
  18611. const WorldUVGenerator = {
  18612. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  18613. const a_x = vertices[ indexA * 3 ];
  18614. const a_y = vertices[ indexA * 3 + 1 ];
  18615. const b_x = vertices[ indexB * 3 ];
  18616. const b_y = vertices[ indexB * 3 + 1 ];
  18617. const c_x = vertices[ indexC * 3 ];
  18618. const c_y = vertices[ indexC * 3 + 1 ];
  18619. return [
  18620. new Vector2( a_x, a_y ),
  18621. new Vector2( b_x, b_y ),
  18622. new Vector2( c_x, c_y )
  18623. ];
  18624. },
  18625. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  18626. const a_x = vertices[ indexA * 3 ];
  18627. const a_y = vertices[ indexA * 3 + 1 ];
  18628. const a_z = vertices[ indexA * 3 + 2 ];
  18629. const b_x = vertices[ indexB * 3 ];
  18630. const b_y = vertices[ indexB * 3 + 1 ];
  18631. const b_z = vertices[ indexB * 3 + 2 ];
  18632. const c_x = vertices[ indexC * 3 ];
  18633. const c_y = vertices[ indexC * 3 + 1 ];
  18634. const c_z = vertices[ indexC * 3 + 2 ];
  18635. const d_x = vertices[ indexD * 3 ];
  18636. const d_y = vertices[ indexD * 3 + 1 ];
  18637. const d_z = vertices[ indexD * 3 + 2 ];
  18638. if ( Math.abs( a_y - b_y ) < 0.01 ) {
  18639. return [
  18640. new Vector2( a_x, 1 - a_z ),
  18641. new Vector2( b_x, 1 - b_z ),
  18642. new Vector2( c_x, 1 - c_z ),
  18643. new Vector2( d_x, 1 - d_z )
  18644. ];
  18645. } else {
  18646. return [
  18647. new Vector2( a_y, 1 - a_z ),
  18648. new Vector2( b_y, 1 - b_z ),
  18649. new Vector2( c_y, 1 - c_z ),
  18650. new Vector2( d_y, 1 - d_z )
  18651. ];
  18652. }
  18653. }
  18654. };
  18655. function toJSON( shapes, options, data ) {
  18656. data.shapes = [];
  18657. if ( Array.isArray( shapes ) ) {
  18658. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  18659. const shape = shapes[ i ];
  18660. data.shapes.push( shape.uuid );
  18661. }
  18662. } else {
  18663. data.shapes.push( shapes.uuid );
  18664. }
  18665. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18666. return data;
  18667. }
  18668. /**
  18669. * Creates extruded geometry from a path shape.
  18670. *
  18671. * parameters = {
  18672. *
  18673. * curveSegments: <int>, // number of points on the curves
  18674. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18675. * depth: <float>, // Depth to extrude the shape
  18676. *
  18677. * bevelEnabled: <bool>, // turn on bevel
  18678. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18679. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  18680. * bevelOffset: <float>, // how far from shape outline does bevel start
  18681. * bevelSegments: <int>, // number of bevel layers
  18682. *
  18683. * extrudePath: <THREE.Curve> // curve to extrude shape along
  18684. *
  18685. * UVGenerator: <Object> // object that provides UV generator functions
  18686. *
  18687. * }
  18688. */
  18689. class ExtrudeGeometry extends Geometry {
  18690. constructor( shapes, options ) {
  18691. super();
  18692. this.type = 'ExtrudeGeometry';
  18693. this.parameters = {
  18694. shapes: shapes,
  18695. options: options
  18696. };
  18697. this.fromBufferGeometry( new ExtrudeBufferGeometry( shapes, options ) );
  18698. this.mergeVertices();
  18699. }
  18700. toJSON() {
  18701. const data = super.toJSON();
  18702. const shapes = this.parameters.shapes;
  18703. const options = this.parameters.options;
  18704. return toJSON$1( shapes, options, data );
  18705. }
  18706. }
  18707. function toJSON$1( shapes, options, data ) {
  18708. data.shapes = [];
  18709. if ( Array.isArray( shapes ) ) {
  18710. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  18711. const shape = shapes[ i ];
  18712. data.shapes.push( shape.uuid );
  18713. }
  18714. } else {
  18715. data.shapes.push( shapes.uuid );
  18716. }
  18717. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  18718. return data;
  18719. }
  18720. class IcosahedronBufferGeometry extends PolyhedronBufferGeometry {
  18721. constructor( radius = 1, detail = 0 ) {
  18722. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  18723. const vertices = [
  18724. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  18725. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  18726. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  18727. ];
  18728. const indices = [
  18729. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  18730. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  18731. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  18732. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  18733. ];
  18734. super( vertices, indices, radius, detail );
  18735. this.type = 'IcosahedronBufferGeometry';
  18736. this.parameters = {
  18737. radius: radius,
  18738. detail: detail
  18739. };
  18740. }
  18741. }
  18742. class IcosahedronGeometry extends Geometry {
  18743. constructor( radius, detail ) {
  18744. super();
  18745. this.type = 'IcosahedronGeometry';
  18746. this.parameters = {
  18747. radius: radius,
  18748. detail: detail
  18749. };
  18750. this.fromBufferGeometry( new IcosahedronBufferGeometry( radius, detail ) );
  18751. this.mergeVertices();
  18752. }
  18753. }
  18754. class LatheBufferGeometry extends BufferGeometry {
  18755. constructor( points, segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) {
  18756. super();
  18757. this.type = 'LatheBufferGeometry';
  18758. this.parameters = {
  18759. points: points,
  18760. segments: segments,
  18761. phiStart: phiStart,
  18762. phiLength: phiLength
  18763. };
  18764. segments = Math.floor( segments );
  18765. // clamp phiLength so it's in range of [ 0, 2PI ]
  18766. phiLength = MathUtils.clamp( phiLength, 0, Math.PI * 2 );
  18767. // buffers
  18768. const indices = [];
  18769. const vertices = [];
  18770. const uvs = [];
  18771. // helper variables
  18772. const inverseSegments = 1.0 / segments;
  18773. const vertex = new Vector3();
  18774. const uv = new Vector2();
  18775. // generate vertices and uvs
  18776. for ( let i = 0; i <= segments; i ++ ) {
  18777. const phi = phiStart + i * inverseSegments * phiLength;
  18778. const sin = Math.sin( phi );
  18779. const cos = Math.cos( phi );
  18780. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  18781. // vertex
  18782. vertex.x = points[ j ].x * sin;
  18783. vertex.y = points[ j ].y;
  18784. vertex.z = points[ j ].x * cos;
  18785. vertices.push( vertex.x, vertex.y, vertex.z );
  18786. // uv
  18787. uv.x = i / segments;
  18788. uv.y = j / ( points.length - 1 );
  18789. uvs.push( uv.x, uv.y );
  18790. }
  18791. }
  18792. // indices
  18793. for ( let i = 0; i < segments; i ++ ) {
  18794. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  18795. const base = j + i * points.length;
  18796. const a = base;
  18797. const b = base + points.length;
  18798. const c = base + points.length + 1;
  18799. const d = base + 1;
  18800. // faces
  18801. indices.push( a, b, d );
  18802. indices.push( b, c, d );
  18803. }
  18804. }
  18805. // build geometry
  18806. this.setIndex( indices );
  18807. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18808. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18809. // generate normals
  18810. this.computeVertexNormals();
  18811. // if the geometry is closed, we need to average the normals along the seam.
  18812. // because the corresponding vertices are identical (but still have different UVs).
  18813. if ( phiLength === Math.PI * 2 ) {
  18814. const normals = this.attributes.normal.array;
  18815. const n1 = new Vector3();
  18816. const n2 = new Vector3();
  18817. const n = new Vector3();
  18818. // this is the buffer offset for the last line of vertices
  18819. const base = segments * points.length * 3;
  18820. for ( let i = 0, j = 0; i < points.length; i ++, j += 3 ) {
  18821. // select the normal of the vertex in the first line
  18822. n1.x = normals[ j + 0 ];
  18823. n1.y = normals[ j + 1 ];
  18824. n1.z = normals[ j + 2 ];
  18825. // select the normal of the vertex in the last line
  18826. n2.x = normals[ base + j + 0 ];
  18827. n2.y = normals[ base + j + 1 ];
  18828. n2.z = normals[ base + j + 2 ];
  18829. // average normals
  18830. n.addVectors( n1, n2 ).normalize();
  18831. // assign the new values to both normals
  18832. normals[ j + 0 ] = normals[ base + j + 0 ] = n.x;
  18833. normals[ j + 1 ] = normals[ base + j + 1 ] = n.y;
  18834. normals[ j + 2 ] = normals[ base + j + 2 ] = n.z;
  18835. }
  18836. }
  18837. }
  18838. }
  18839. class LatheGeometry extends Geometry {
  18840. constructor( points, segments, phiStart, phiLength ) {
  18841. super();
  18842. this.type = 'LatheGeometry';
  18843. this.parameters = {
  18844. points: points,
  18845. segments: segments,
  18846. phiStart: phiStart,
  18847. phiLength: phiLength
  18848. };
  18849. this.fromBufferGeometry( new LatheBufferGeometry( points, segments, phiStart, phiLength ) );
  18850. this.mergeVertices();
  18851. }
  18852. }
  18853. class OctahedronBufferGeometry extends PolyhedronBufferGeometry {
  18854. constructor( radius = 1, detail = 0 ) {
  18855. const vertices = [
  18856. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  18857. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  18858. ];
  18859. const indices = [
  18860. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  18861. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  18862. 1, 3, 4, 1, 4, 2
  18863. ];
  18864. super( vertices, indices, radius, detail );
  18865. this.type = 'OctahedronBufferGeometry';
  18866. this.parameters = {
  18867. radius: radius,
  18868. detail: detail
  18869. };
  18870. }
  18871. }
  18872. class OctahedronGeometry extends Geometry {
  18873. constructor( radius, detail ) {
  18874. super();
  18875. this.type = 'OctahedronGeometry';
  18876. this.parameters = {
  18877. radius: radius,
  18878. detail: detail
  18879. };
  18880. this.fromBufferGeometry( new OctahedronBufferGeometry( radius, detail ) );
  18881. this.mergeVertices();
  18882. }
  18883. }
  18884. /**
  18885. * Parametric Surfaces Geometry
  18886. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18887. */
  18888. function ParametricBufferGeometry( func, slices, stacks ) {
  18889. BufferGeometry.call( this );
  18890. this.type = 'ParametricBufferGeometry';
  18891. this.parameters = {
  18892. func: func,
  18893. slices: slices,
  18894. stacks: stacks
  18895. };
  18896. // buffers
  18897. const indices = [];
  18898. const vertices = [];
  18899. const normals = [];
  18900. const uvs = [];
  18901. const EPS = 0.00001;
  18902. const normal = new Vector3();
  18903. const p0 = new Vector3(), p1 = new Vector3();
  18904. const pu = new Vector3(), pv = new Vector3();
  18905. if ( func.length < 3 ) {
  18906. console.error( 'THREE.ParametricGeometry: Function must now modify a Vector3 as third parameter.' );
  18907. }
  18908. // generate vertices, normals and uvs
  18909. const sliceCount = slices + 1;
  18910. for ( let i = 0; i <= stacks; i ++ ) {
  18911. const v = i / stacks;
  18912. for ( let j = 0; j <= slices; j ++ ) {
  18913. const u = j / slices;
  18914. // vertex
  18915. func( u, v, p0 );
  18916. vertices.push( p0.x, p0.y, p0.z );
  18917. // normal
  18918. // approximate tangent vectors via finite differences
  18919. if ( u - EPS >= 0 ) {
  18920. func( u - EPS, v, p1 );
  18921. pu.subVectors( p0, p1 );
  18922. } else {
  18923. func( u + EPS, v, p1 );
  18924. pu.subVectors( p1, p0 );
  18925. }
  18926. if ( v - EPS >= 0 ) {
  18927. func( u, v - EPS, p1 );
  18928. pv.subVectors( p0, p1 );
  18929. } else {
  18930. func( u, v + EPS, p1 );
  18931. pv.subVectors( p1, p0 );
  18932. }
  18933. // cross product of tangent vectors returns surface normal
  18934. normal.crossVectors( pu, pv ).normalize();
  18935. normals.push( normal.x, normal.y, normal.z );
  18936. // uv
  18937. uvs.push( u, v );
  18938. }
  18939. }
  18940. // generate indices
  18941. for ( let i = 0; i < stacks; i ++ ) {
  18942. for ( let j = 0; j < slices; j ++ ) {
  18943. const a = i * sliceCount + j;
  18944. const b = i * sliceCount + j + 1;
  18945. const c = ( i + 1 ) * sliceCount + j + 1;
  18946. const d = ( i + 1 ) * sliceCount + j;
  18947. // faces one and two
  18948. indices.push( a, b, d );
  18949. indices.push( b, c, d );
  18950. }
  18951. }
  18952. // build geometry
  18953. this.setIndex( indices );
  18954. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  18955. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  18956. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  18957. }
  18958. ParametricBufferGeometry.prototype = Object.create( BufferGeometry.prototype );
  18959. ParametricBufferGeometry.prototype.constructor = ParametricBufferGeometry;
  18960. /**
  18961. * Parametric Surfaces Geometry
  18962. * based on the brilliant article by @prideout https://prideout.net/blog/old/blog/index.html@p=44.html
  18963. */
  18964. function ParametricGeometry( func, slices, stacks ) {
  18965. Geometry.call( this );
  18966. this.type = 'ParametricGeometry';
  18967. this.parameters = {
  18968. func: func,
  18969. slices: slices,
  18970. stacks: stacks
  18971. };
  18972. this.fromBufferGeometry( new ParametricBufferGeometry( func, slices, stacks ) );
  18973. this.mergeVertices();
  18974. }
  18975. ParametricGeometry.prototype = Object.create( Geometry.prototype );
  18976. ParametricGeometry.prototype.constructor = ParametricGeometry;
  18977. class PlaneGeometry extends Geometry {
  18978. constructor( width, height, widthSegments, heightSegments ) {
  18979. super();
  18980. this.type = 'PlaneGeometry';
  18981. this.parameters = {
  18982. width: width,
  18983. height: height,
  18984. widthSegments: widthSegments,
  18985. heightSegments: heightSegments
  18986. };
  18987. this.fromBufferGeometry( new PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  18988. this.mergeVertices();
  18989. }
  18990. }
  18991. class PolyhedronGeometry extends Geometry {
  18992. constructor( vertices, indices, radius, detail ) {
  18993. super();
  18994. this.type = 'PolyhedronGeometry';
  18995. this.parameters = {
  18996. vertices: vertices,
  18997. indices: indices,
  18998. radius: radius,
  18999. detail: detail
  19000. };
  19001. this.fromBufferGeometry( new PolyhedronBufferGeometry( vertices, indices, radius, detail ) );
  19002. this.mergeVertices();
  19003. }
  19004. }
  19005. class RingBufferGeometry extends BufferGeometry {
  19006. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 8, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  19007. super();
  19008. this.type = 'RingBufferGeometry';
  19009. this.parameters = {
  19010. innerRadius: innerRadius,
  19011. outerRadius: outerRadius,
  19012. thetaSegments: thetaSegments,
  19013. phiSegments: phiSegments,
  19014. thetaStart: thetaStart,
  19015. thetaLength: thetaLength
  19016. };
  19017. thetaSegments = Math.max( 3, thetaSegments );
  19018. phiSegments = Math.max( 1, phiSegments );
  19019. // buffers
  19020. const indices = [];
  19021. const vertices = [];
  19022. const normals = [];
  19023. const uvs = [];
  19024. // some helper variables
  19025. let radius = innerRadius;
  19026. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19027. const vertex = new Vector3();
  19028. const uv = new Vector2();
  19029. // generate vertices, normals and uvs
  19030. for ( let j = 0; j <= phiSegments; j ++ ) {
  19031. for ( let i = 0; i <= thetaSegments; i ++ ) {
  19032. // values are generate from the inside of the ring to the outside
  19033. const segment = thetaStart + i / thetaSegments * thetaLength;
  19034. // vertex
  19035. vertex.x = radius * Math.cos( segment );
  19036. vertex.y = radius * Math.sin( segment );
  19037. vertices.push( vertex.x, vertex.y, vertex.z );
  19038. // normal
  19039. normals.push( 0, 0, 1 );
  19040. // uv
  19041. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  19042. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  19043. uvs.push( uv.x, uv.y );
  19044. }
  19045. // increase the radius for next row of vertices
  19046. radius += radiusStep;
  19047. }
  19048. // indices
  19049. for ( let j = 0; j < phiSegments; j ++ ) {
  19050. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  19051. for ( let i = 0; i < thetaSegments; i ++ ) {
  19052. const segment = i + thetaSegmentLevel;
  19053. const a = segment;
  19054. const b = segment + thetaSegments + 1;
  19055. const c = segment + thetaSegments + 2;
  19056. const d = segment + 1;
  19057. // faces
  19058. indices.push( a, b, d );
  19059. indices.push( b, c, d );
  19060. }
  19061. }
  19062. // build geometry
  19063. this.setIndex( indices );
  19064. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19065. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19066. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19067. }
  19068. }
  19069. class RingGeometry extends Geometry {
  19070. constructor( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19071. super();
  19072. this.type = 'RingGeometry';
  19073. this.parameters = {
  19074. innerRadius: innerRadius,
  19075. outerRadius: outerRadius,
  19076. thetaSegments: thetaSegments,
  19077. phiSegments: phiSegments,
  19078. thetaStart: thetaStart,
  19079. thetaLength: thetaLength
  19080. };
  19081. this.fromBufferGeometry( new RingBufferGeometry( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) );
  19082. this.mergeVertices();
  19083. }
  19084. }
  19085. class ShapeBufferGeometry extends BufferGeometry {
  19086. constructor( shapes, curveSegments = 12 ) {
  19087. super();
  19088. this.type = 'ShapeBufferGeometry';
  19089. this.parameters = {
  19090. shapes: shapes,
  19091. curveSegments: curveSegments
  19092. };
  19093. // buffers
  19094. const indices = [];
  19095. const vertices = [];
  19096. const normals = [];
  19097. const uvs = [];
  19098. // helper variables
  19099. let groupStart = 0;
  19100. let groupCount = 0;
  19101. // allow single and array values for "shapes" parameter
  19102. if ( Array.isArray( shapes ) === false ) {
  19103. addShape( shapes );
  19104. } else {
  19105. for ( let i = 0; i < shapes.length; i ++ ) {
  19106. addShape( shapes[ i ] );
  19107. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  19108. groupStart += groupCount;
  19109. groupCount = 0;
  19110. }
  19111. }
  19112. // build geometry
  19113. this.setIndex( indices );
  19114. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19115. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19116. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19117. // helper functions
  19118. function addShape( shape ) {
  19119. const indexOffset = vertices.length / 3;
  19120. const points = shape.extractPoints( curveSegments );
  19121. let shapeVertices = points.shape;
  19122. const shapeHoles = points.holes;
  19123. // check direction of vertices
  19124. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  19125. shapeVertices = shapeVertices.reverse();
  19126. }
  19127. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19128. const shapeHole = shapeHoles[ i ];
  19129. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  19130. shapeHoles[ i ] = shapeHole.reverse();
  19131. }
  19132. }
  19133. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  19134. // join vertices of inner and outer paths to a single array
  19135. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  19136. const shapeHole = shapeHoles[ i ];
  19137. shapeVertices = shapeVertices.concat( shapeHole );
  19138. }
  19139. // vertices, normals, uvs
  19140. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  19141. const vertex = shapeVertices[ i ];
  19142. vertices.push( vertex.x, vertex.y, 0 );
  19143. normals.push( 0, 0, 1 );
  19144. uvs.push( vertex.x, vertex.y ); // world uvs
  19145. }
  19146. // incides
  19147. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  19148. const face = faces[ i ];
  19149. const a = face[ 0 ] + indexOffset;
  19150. const b = face[ 1 ] + indexOffset;
  19151. const c = face[ 2 ] + indexOffset;
  19152. indices.push( a, b, c );
  19153. groupCount += 3;
  19154. }
  19155. }
  19156. }
  19157. toJSON() {
  19158. const data = BufferGeometry.prototype.toJSON.call( this );
  19159. const shapes = this.parameters.shapes;
  19160. return toJSON$2( shapes, data );
  19161. }
  19162. }
  19163. function toJSON$2( shapes, data ) {
  19164. data.shapes = [];
  19165. if ( Array.isArray( shapes ) ) {
  19166. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  19167. const shape = shapes[ i ];
  19168. data.shapes.push( shape.uuid );
  19169. }
  19170. } else {
  19171. data.shapes.push( shapes.uuid );
  19172. }
  19173. return data;
  19174. }
  19175. class ShapeGeometry extends Geometry {
  19176. constructor( shapes, curveSegments ) {
  19177. super();
  19178. this.type = 'ShapeGeometry';
  19179. if ( typeof curveSegments === 'object' ) {
  19180. console.warn( 'THREE.ShapeGeometry: Options parameter has been removed.' );
  19181. curveSegments = curveSegments.curveSegments;
  19182. }
  19183. this.parameters = {
  19184. shapes: shapes,
  19185. curveSegments: curveSegments
  19186. };
  19187. this.fromBufferGeometry( new ShapeBufferGeometry( shapes, curveSegments ) );
  19188. this.mergeVertices();
  19189. }
  19190. toJSON() {
  19191. const data = Geometry.prototype.toJSON.call( this );
  19192. const shapes = this.parameters.shapes;
  19193. return toJSON$3( shapes, data );
  19194. }
  19195. }
  19196. function toJSON$3( shapes, data ) {
  19197. data.shapes = [];
  19198. if ( Array.isArray( shapes ) ) {
  19199. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  19200. const shape = shapes[ i ];
  19201. data.shapes.push( shape.uuid );
  19202. }
  19203. } else {
  19204. data.shapes.push( shapes.uuid );
  19205. }
  19206. return data;
  19207. }
  19208. class SphereBufferGeometry extends BufferGeometry {
  19209. constructor( radius = 1, widthSegments = 8, heightSegments = 6, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  19210. super();
  19211. this.type = 'SphereBufferGeometry';
  19212. this.parameters = {
  19213. radius: radius,
  19214. widthSegments: widthSegments,
  19215. heightSegments: heightSegments,
  19216. phiStart: phiStart,
  19217. phiLength: phiLength,
  19218. thetaStart: thetaStart,
  19219. thetaLength: thetaLength
  19220. };
  19221. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  19222. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  19223. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  19224. let index = 0;
  19225. const grid = [];
  19226. const vertex = new Vector3();
  19227. const normal = new Vector3();
  19228. // buffers
  19229. const indices = [];
  19230. const vertices = [];
  19231. const normals = [];
  19232. const uvs = [];
  19233. // generate vertices, normals and uvs
  19234. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  19235. const verticesRow = [];
  19236. const v = iy / heightSegments;
  19237. // special case for the poles
  19238. let uOffset = 0;
  19239. if ( iy == 0 && thetaStart == 0 ) {
  19240. uOffset = 0.5 / widthSegments;
  19241. } else if ( iy == heightSegments && thetaEnd == Math.PI ) {
  19242. uOffset = - 0.5 / widthSegments;
  19243. }
  19244. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  19245. const u = ix / widthSegments;
  19246. // vertex
  19247. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19248. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19249. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19250. vertices.push( vertex.x, vertex.y, vertex.z );
  19251. // normal
  19252. normal.copy( vertex ).normalize();
  19253. normals.push( normal.x, normal.y, normal.z );
  19254. // uv
  19255. uvs.push( u + uOffset, 1 - v );
  19256. verticesRow.push( index ++ );
  19257. }
  19258. grid.push( verticesRow );
  19259. }
  19260. // indices
  19261. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  19262. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  19263. const a = grid[ iy ][ ix + 1 ];
  19264. const b = grid[ iy ][ ix ];
  19265. const c = grid[ iy + 1 ][ ix ];
  19266. const d = grid[ iy + 1 ][ ix + 1 ];
  19267. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  19268. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  19269. }
  19270. }
  19271. // build geometry
  19272. this.setIndex( indices );
  19273. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19274. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19275. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19276. }
  19277. }
  19278. class SphereGeometry extends Geometry {
  19279. constructor( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19280. super();
  19281. this.type = 'SphereGeometry';
  19282. this.parameters = {
  19283. radius: radius,
  19284. widthSegments: widthSegments,
  19285. heightSegments: heightSegments,
  19286. phiStart: phiStart,
  19287. phiLength: phiLength,
  19288. thetaStart: thetaStart,
  19289. thetaLength: thetaLength
  19290. };
  19291. this.fromBufferGeometry( new SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  19292. this.mergeVertices();
  19293. }
  19294. }
  19295. class TetrahedronBufferGeometry extends PolyhedronBufferGeometry {
  19296. constructor( radius = 1, detail = 0 ) {
  19297. const vertices = [
  19298. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  19299. ];
  19300. const indices = [
  19301. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  19302. ];
  19303. super( vertices, indices, radius, detail );
  19304. this.type = 'TetrahedronBufferGeometry';
  19305. this.parameters = {
  19306. radius: radius,
  19307. detail: detail
  19308. };
  19309. }
  19310. }
  19311. class TetrahedronGeometry extends Geometry {
  19312. constructor( radius, detail ) {
  19313. super();
  19314. this.type = 'TetrahedronGeometry';
  19315. this.parameters = {
  19316. radius: radius,
  19317. detail: detail
  19318. };
  19319. this.fromBufferGeometry( new TetrahedronBufferGeometry( radius, detail ) );
  19320. this.mergeVertices();
  19321. }
  19322. }
  19323. /**
  19324. * Text = 3D Text
  19325. *
  19326. * parameters = {
  19327. * font: <THREE.Font>, // font
  19328. *
  19329. * size: <float>, // size of the text
  19330. * height: <float>, // thickness to extrude text
  19331. * curveSegments: <int>, // number of points on the curves
  19332. *
  19333. * bevelEnabled: <bool>, // turn on bevel
  19334. * bevelThickness: <float>, // how deep into text bevel goes
  19335. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  19336. * bevelOffset: <float> // how far from text outline does bevel start
  19337. * }
  19338. */
  19339. class TextBufferGeometry extends ExtrudeBufferGeometry {
  19340. constructor( text, parameters = {} ) {
  19341. const font = parameters.font;
  19342. if ( ! ( font && font.isFont ) ) {
  19343. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  19344. return new BufferGeometry();
  19345. }
  19346. const shapes = font.generateShapes( text, parameters.size );
  19347. // translate parameters to ExtrudeGeometry API
  19348. parameters.depth = parameters.height !== undefined ? parameters.height : 50;
  19349. // defaults
  19350. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19351. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19352. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19353. super( shapes, parameters );
  19354. this.type = 'TextBufferGeometry';
  19355. }
  19356. }
  19357. /**
  19358. * Text = 3D Text
  19359. *
  19360. * parameters = {
  19361. * font: <THREE.Font>, // font
  19362. *
  19363. * size: <float>, // size of the text
  19364. * height: <float>, // thickness to extrude text
  19365. * curveSegments: <int>, // number of points on the curves
  19366. *
  19367. * bevelEnabled: <bool>, // turn on bevel
  19368. * bevelThickness: <float>, // how deep into text bevel goes
  19369. * bevelSize: <float>, // how far from text outline (including bevelOffset) is bevel
  19370. * bevelOffset: <float> // how far from text outline does bevel start
  19371. * }
  19372. */
  19373. class TextGeometry extends Geometry {
  19374. constructor( text, parameters ) {
  19375. super();
  19376. this.type = 'TextGeometry';
  19377. this.parameters = {
  19378. text: text,
  19379. parameters: parameters
  19380. };
  19381. this.fromBufferGeometry( new TextBufferGeometry( text, parameters ) );
  19382. this.mergeVertices();
  19383. }
  19384. }
  19385. class TorusBufferGeometry extends BufferGeometry {
  19386. constructor( radius = 1, tube = 0.4, radialSegments = 8, tubularSegments = 6, arc = Math.PI * 2 ) {
  19387. super();
  19388. this.type = 'TorusBufferGeometry';
  19389. this.parameters = {
  19390. radius: radius,
  19391. tube: tube,
  19392. radialSegments: radialSegments,
  19393. tubularSegments: tubularSegments,
  19394. arc: arc
  19395. };
  19396. radialSegments = Math.floor( radialSegments );
  19397. tubularSegments = Math.floor( tubularSegments );
  19398. // buffers
  19399. const indices = [];
  19400. const vertices = [];
  19401. const normals = [];
  19402. const uvs = [];
  19403. // helper variables
  19404. const center = new Vector3();
  19405. const vertex = new Vector3();
  19406. const normal = new Vector3();
  19407. // generate vertices, normals and uvs
  19408. for ( let j = 0; j <= radialSegments; j ++ ) {
  19409. for ( let i = 0; i <= tubularSegments; i ++ ) {
  19410. const u = i / tubularSegments * arc;
  19411. const v = j / radialSegments * Math.PI * 2;
  19412. // vertex
  19413. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19414. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19415. vertex.z = tube * Math.sin( v );
  19416. vertices.push( vertex.x, vertex.y, vertex.z );
  19417. // normal
  19418. center.x = radius * Math.cos( u );
  19419. center.y = radius * Math.sin( u );
  19420. normal.subVectors( vertex, center ).normalize();
  19421. normals.push( normal.x, normal.y, normal.z );
  19422. // uv
  19423. uvs.push( i / tubularSegments );
  19424. uvs.push( j / radialSegments );
  19425. }
  19426. }
  19427. // generate indices
  19428. for ( let j = 1; j <= radialSegments; j ++ ) {
  19429. for ( let i = 1; i <= tubularSegments; i ++ ) {
  19430. // indices
  19431. const a = ( tubularSegments + 1 ) * j + i - 1;
  19432. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19433. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19434. const d = ( tubularSegments + 1 ) * j + i;
  19435. // faces
  19436. indices.push( a, b, d );
  19437. indices.push( b, c, d );
  19438. }
  19439. }
  19440. // build geometry
  19441. this.setIndex( indices );
  19442. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19443. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19444. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19445. }
  19446. }
  19447. class TorusGeometry extends Geometry {
  19448. constructor( radius, tube, radialSegments, tubularSegments, arc ) {
  19449. super();
  19450. this.type = 'TorusGeometry';
  19451. this.parameters = {
  19452. radius: radius,
  19453. tube: tube,
  19454. radialSegments: radialSegments,
  19455. tubularSegments: tubularSegments,
  19456. arc: arc
  19457. };
  19458. this.fromBufferGeometry( new TorusBufferGeometry( radius, tube, radialSegments, tubularSegments, arc ) );
  19459. this.mergeVertices();
  19460. }
  19461. }
  19462. class TorusKnotBufferGeometry extends BufferGeometry {
  19463. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  19464. super();
  19465. this.type = 'TorusKnotBufferGeometry';
  19466. this.parameters = {
  19467. radius: radius,
  19468. tube: tube,
  19469. tubularSegments: tubularSegments,
  19470. radialSegments: radialSegments,
  19471. p: p,
  19472. q: q
  19473. };
  19474. tubularSegments = Math.floor( tubularSegments );
  19475. radialSegments = Math.floor( radialSegments );
  19476. // buffers
  19477. const indices = [];
  19478. const vertices = [];
  19479. const normals = [];
  19480. const uvs = [];
  19481. // helper variables
  19482. const vertex = new Vector3();
  19483. const normal = new Vector3();
  19484. const P1 = new Vector3();
  19485. const P2 = new Vector3();
  19486. const B = new Vector3();
  19487. const T = new Vector3();
  19488. const N = new Vector3();
  19489. // generate vertices, normals and uvs
  19490. for ( let i = 0; i <= tubularSegments; ++ i ) {
  19491. // the radian "u" is used to calculate the position on the torus curve of the current tubular segement
  19492. const u = i / tubularSegments * p * Math.PI * 2;
  19493. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  19494. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  19495. calculatePositionOnCurve( u, p, q, radius, P1 );
  19496. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  19497. // calculate orthonormal basis
  19498. T.subVectors( P2, P1 );
  19499. N.addVectors( P2, P1 );
  19500. B.crossVectors( T, N );
  19501. N.crossVectors( B, T );
  19502. // normalize B, N. T can be ignored, we don't use it
  19503. B.normalize();
  19504. N.normalize();
  19505. for ( let j = 0; j <= radialSegments; ++ j ) {
  19506. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  19507. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  19508. const v = j / radialSegments * Math.PI * 2;
  19509. const cx = - tube * Math.cos( v );
  19510. const cy = tube * Math.sin( v );
  19511. // now calculate the final vertex position.
  19512. // first we orient the extrusion with our basis vectos, then we add it to the current position on the curve
  19513. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  19514. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  19515. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  19516. vertices.push( vertex.x, vertex.y, vertex.z );
  19517. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  19518. normal.subVectors( vertex, P1 ).normalize();
  19519. normals.push( normal.x, normal.y, normal.z );
  19520. // uv
  19521. uvs.push( i / tubularSegments );
  19522. uvs.push( j / radialSegments );
  19523. }
  19524. }
  19525. // generate indices
  19526. for ( let j = 1; j <= tubularSegments; j ++ ) {
  19527. for ( let i = 1; i <= radialSegments; i ++ ) {
  19528. // indices
  19529. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  19530. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  19531. const c = ( radialSegments + 1 ) * j + i;
  19532. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  19533. // faces
  19534. indices.push( a, b, d );
  19535. indices.push( b, c, d );
  19536. }
  19537. }
  19538. // build geometry
  19539. this.setIndex( indices );
  19540. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19541. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19542. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19543. // this function calculates the current position on the torus curve
  19544. function calculatePositionOnCurve( u, p, q, radius, position ) {
  19545. const cu = Math.cos( u );
  19546. const su = Math.sin( u );
  19547. const quOverP = q / p * u;
  19548. const cs = Math.cos( quOverP );
  19549. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  19550. position.y = radius * ( 2 + cs ) * su * 0.5;
  19551. position.z = radius * Math.sin( quOverP ) * 0.5;
  19552. }
  19553. }
  19554. }
  19555. class TorusKnotGeometry extends Geometry {
  19556. constructor( radius, tube, tubularSegments, radialSegments, p, q, heightScale ) {
  19557. super();
  19558. this.type = 'TorusKnotGeometry';
  19559. this.parameters = {
  19560. radius: radius,
  19561. tube: tube,
  19562. tubularSegments: tubularSegments,
  19563. radialSegments: radialSegments,
  19564. p: p,
  19565. q: q
  19566. };
  19567. if ( heightScale !== undefined ) console.warn( 'THREE.TorusKnotGeometry: heightScale has been deprecated. Use .scale( x, y, z ) instead.' );
  19568. this.fromBufferGeometry( new TorusKnotBufferGeometry( radius, tube, tubularSegments, radialSegments, p, q ) );
  19569. this.mergeVertices();
  19570. }
  19571. }
  19572. class TubeBufferGeometry extends BufferGeometry {
  19573. constructor( path, tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
  19574. super();
  19575. this.type = 'TubeBufferGeometry';
  19576. this.parameters = {
  19577. path: path,
  19578. tubularSegments: tubularSegments,
  19579. radius: radius,
  19580. radialSegments: radialSegments,
  19581. closed: closed
  19582. };
  19583. const frames = path.computeFrenetFrames( tubularSegments, closed );
  19584. // expose internals
  19585. this.tangents = frames.tangents;
  19586. this.normals = frames.normals;
  19587. this.binormals = frames.binormals;
  19588. // helper variables
  19589. const vertex = new Vector3();
  19590. const normal = new Vector3();
  19591. const uv = new Vector2();
  19592. let P = new Vector3();
  19593. // buffer
  19594. const vertices = [];
  19595. const normals = [];
  19596. const uvs = [];
  19597. const indices = [];
  19598. // create buffer data
  19599. generateBufferData();
  19600. // build geometry
  19601. this.setIndex( indices );
  19602. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19603. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  19604. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  19605. // functions
  19606. function generateBufferData() {
  19607. for ( let i = 0; i < tubularSegments; i ++ ) {
  19608. generateSegment( i );
  19609. }
  19610. // if the geometry is not closed, generate the last row of vertices and normals
  19611. // at the regular position on the given path
  19612. //
  19613. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  19614. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  19615. // uvs are generated in a separate function.
  19616. // this makes it easy compute correct values for closed geometries
  19617. generateUVs();
  19618. // finally create faces
  19619. generateIndices();
  19620. }
  19621. function generateSegment( i ) {
  19622. // we use getPointAt to sample evenly distributed points from the given path
  19623. P = path.getPointAt( i / tubularSegments, P );
  19624. // retrieve corresponding normal and binormal
  19625. const N = frames.normals[ i ];
  19626. const B = frames.binormals[ i ];
  19627. // generate normals and vertices for the current segment
  19628. for ( let j = 0; j <= radialSegments; j ++ ) {
  19629. const v = j / radialSegments * Math.PI * 2;
  19630. const sin = Math.sin( v );
  19631. const cos = - Math.cos( v );
  19632. // normal
  19633. normal.x = ( cos * N.x + sin * B.x );
  19634. normal.y = ( cos * N.y + sin * B.y );
  19635. normal.z = ( cos * N.z + sin * B.z );
  19636. normal.normalize();
  19637. normals.push( normal.x, normal.y, normal.z );
  19638. // vertex
  19639. vertex.x = P.x + radius * normal.x;
  19640. vertex.y = P.y + radius * normal.y;
  19641. vertex.z = P.z + radius * normal.z;
  19642. vertices.push( vertex.x, vertex.y, vertex.z );
  19643. }
  19644. }
  19645. function generateIndices() {
  19646. for ( let j = 1; j <= tubularSegments; j ++ ) {
  19647. for ( let i = 1; i <= radialSegments; i ++ ) {
  19648. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  19649. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  19650. const c = ( radialSegments + 1 ) * j + i;
  19651. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  19652. // faces
  19653. indices.push( a, b, d );
  19654. indices.push( b, c, d );
  19655. }
  19656. }
  19657. }
  19658. function generateUVs() {
  19659. for ( let i = 0; i <= tubularSegments; i ++ ) {
  19660. for ( let j = 0; j <= radialSegments; j ++ ) {
  19661. uv.x = i / tubularSegments;
  19662. uv.y = j / radialSegments;
  19663. uvs.push( uv.x, uv.y );
  19664. }
  19665. }
  19666. }
  19667. }
  19668. toJSON() {
  19669. const data = BufferGeometry.prototype.toJSON.call( this );
  19670. data.path = this.parameters.path.toJSON();
  19671. return data;
  19672. }
  19673. }
  19674. class TubeGeometry extends Geometry {
  19675. constructor( path, tubularSegments, radius, radialSegments, closed, taper ) {
  19676. super();
  19677. this.type = 'TubeGeometry';
  19678. this.parameters = {
  19679. path: path,
  19680. tubularSegments: tubularSegments,
  19681. radius: radius,
  19682. radialSegments: radialSegments,
  19683. closed: closed
  19684. };
  19685. if ( taper !== undefined ) console.warn( 'THREE.TubeGeometry: taper has been removed.' );
  19686. const bufferGeometry = new TubeBufferGeometry( path, tubularSegments, radius, radialSegments, closed );
  19687. // expose internals
  19688. this.tangents = bufferGeometry.tangents;
  19689. this.normals = bufferGeometry.normals;
  19690. this.binormals = bufferGeometry.binormals;
  19691. // create geometry
  19692. this.fromBufferGeometry( bufferGeometry );
  19693. this.mergeVertices();
  19694. }
  19695. }
  19696. class WireframeGeometry extends BufferGeometry {
  19697. constructor( geometry ) {
  19698. super();
  19699. this.type = 'WireframeGeometry';
  19700. // buffer
  19701. const vertices = [];
  19702. // helper variables
  19703. const edge = [ 0, 0 ], edges = {};
  19704. const keys = [ 'a', 'b', 'c' ];
  19705. // different logic for Geometry and BufferGeometry
  19706. if ( geometry && geometry.isGeometry ) {
  19707. // create a data structure that contains all edges without duplicates
  19708. const faces = geometry.faces;
  19709. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  19710. const face = faces[ i ];
  19711. for ( let j = 0; j < 3; j ++ ) {
  19712. const edge1 = face[ keys[ j ] ];
  19713. const edge2 = face[ keys[ ( j + 1 ) % 3 ] ];
  19714. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  19715. edge[ 1 ] = Math.max( edge1, edge2 );
  19716. const key = edge[ 0 ] + ',' + edge[ 1 ];
  19717. if ( edges[ key ] === undefined ) {
  19718. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  19719. }
  19720. }
  19721. }
  19722. // generate vertices
  19723. for ( const key in edges ) {
  19724. const e = edges[ key ];
  19725. let vertex = geometry.vertices[ e.index1 ];
  19726. vertices.push( vertex.x, vertex.y, vertex.z );
  19727. vertex = geometry.vertices[ e.index2 ];
  19728. vertices.push( vertex.x, vertex.y, vertex.z );
  19729. }
  19730. } else if ( geometry && geometry.isBufferGeometry ) {
  19731. const vertex = new Vector3();
  19732. if ( geometry.index !== null ) {
  19733. // indexed BufferGeometry
  19734. const position = geometry.attributes.position;
  19735. const indices = geometry.index;
  19736. let groups = geometry.groups;
  19737. if ( groups.length === 0 ) {
  19738. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  19739. }
  19740. // create a data structure that contains all eges without duplicates
  19741. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  19742. const group = groups[ o ];
  19743. const start = group.start;
  19744. const count = group.count;
  19745. for ( let i = start, l = ( start + count ); i < l; i += 3 ) {
  19746. for ( let j = 0; j < 3; j ++ ) {
  19747. const edge1 = indices.getX( i + j );
  19748. const edge2 = indices.getX( i + ( j + 1 ) % 3 );
  19749. edge[ 0 ] = Math.min( edge1, edge2 ); // sorting prevents duplicates
  19750. edge[ 1 ] = Math.max( edge1, edge2 );
  19751. const key = edge[ 0 ] + ',' + edge[ 1 ];
  19752. if ( edges[ key ] === undefined ) {
  19753. edges[ key ] = { index1: edge[ 0 ], index2: edge[ 1 ] };
  19754. }
  19755. }
  19756. }
  19757. }
  19758. // generate vertices
  19759. for ( const key in edges ) {
  19760. const e = edges[ key ];
  19761. vertex.fromBufferAttribute( position, e.index1 );
  19762. vertices.push( vertex.x, vertex.y, vertex.z );
  19763. vertex.fromBufferAttribute( position, e.index2 );
  19764. vertices.push( vertex.x, vertex.y, vertex.z );
  19765. }
  19766. } else {
  19767. // non-indexed BufferGeometry
  19768. const position = geometry.attributes.position;
  19769. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  19770. for ( let j = 0; j < 3; j ++ ) {
  19771. // three edges per triangle, an edge is represented as (index1, index2)
  19772. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  19773. const index1 = 3 * i + j;
  19774. vertex.fromBufferAttribute( position, index1 );
  19775. vertices.push( vertex.x, vertex.y, vertex.z );
  19776. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  19777. vertex.fromBufferAttribute( position, index2 );
  19778. vertices.push( vertex.x, vertex.y, vertex.z );
  19779. }
  19780. }
  19781. }
  19782. }
  19783. // build geometry
  19784. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  19785. }
  19786. }
  19787. var Geometries = /*#__PURE__*/Object.freeze({
  19788. __proto__: null,
  19789. BoxGeometry: BoxGeometry,
  19790. BoxBufferGeometry: BoxBufferGeometry,
  19791. CircleGeometry: CircleGeometry,
  19792. CircleBufferGeometry: CircleBufferGeometry,
  19793. ConeGeometry: ConeGeometry,
  19794. ConeBufferGeometry: ConeBufferGeometry,
  19795. CylinderGeometry: CylinderGeometry,
  19796. CylinderBufferGeometry: CylinderBufferGeometry,
  19797. DodecahedronGeometry: DodecahedronGeometry,
  19798. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  19799. EdgesGeometry: EdgesGeometry,
  19800. ExtrudeGeometry: ExtrudeGeometry,
  19801. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  19802. IcosahedronGeometry: IcosahedronGeometry,
  19803. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  19804. LatheGeometry: LatheGeometry,
  19805. LatheBufferGeometry: LatheBufferGeometry,
  19806. OctahedronGeometry: OctahedronGeometry,
  19807. OctahedronBufferGeometry: OctahedronBufferGeometry,
  19808. ParametricGeometry: ParametricGeometry,
  19809. ParametricBufferGeometry: ParametricBufferGeometry,
  19810. PlaneGeometry: PlaneGeometry,
  19811. PlaneBufferGeometry: PlaneBufferGeometry,
  19812. PolyhedronGeometry: PolyhedronGeometry,
  19813. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  19814. RingGeometry: RingGeometry,
  19815. RingBufferGeometry: RingBufferGeometry,
  19816. ShapeGeometry: ShapeGeometry,
  19817. ShapeBufferGeometry: ShapeBufferGeometry,
  19818. SphereGeometry: SphereGeometry,
  19819. SphereBufferGeometry: SphereBufferGeometry,
  19820. TetrahedronGeometry: TetrahedronGeometry,
  19821. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  19822. TextGeometry: TextGeometry,
  19823. TextBufferGeometry: TextBufferGeometry,
  19824. TorusGeometry: TorusGeometry,
  19825. TorusBufferGeometry: TorusBufferGeometry,
  19826. TorusKnotGeometry: TorusKnotGeometry,
  19827. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  19828. TubeGeometry: TubeGeometry,
  19829. TubeBufferGeometry: TubeBufferGeometry,
  19830. WireframeGeometry: WireframeGeometry
  19831. });
  19832. /**
  19833. * parameters = {
  19834. * color: <THREE.Color>
  19835. * }
  19836. */
  19837. function ShadowMaterial( parameters ) {
  19838. Material.call( this );
  19839. this.type = 'ShadowMaterial';
  19840. this.color = new Color( 0x000000 );
  19841. this.transparent = true;
  19842. this.setValues( parameters );
  19843. }
  19844. ShadowMaterial.prototype = Object.create( Material.prototype );
  19845. ShadowMaterial.prototype.constructor = ShadowMaterial;
  19846. ShadowMaterial.prototype.isShadowMaterial = true;
  19847. ShadowMaterial.prototype.copy = function ( source ) {
  19848. Material.prototype.copy.call( this, source );
  19849. this.color.copy( source.color );
  19850. return this;
  19851. };
  19852. function RawShaderMaterial( parameters ) {
  19853. ShaderMaterial.call( this, parameters );
  19854. this.type = 'RawShaderMaterial';
  19855. }
  19856. RawShaderMaterial.prototype = Object.create( ShaderMaterial.prototype );
  19857. RawShaderMaterial.prototype.constructor = RawShaderMaterial;
  19858. RawShaderMaterial.prototype.isRawShaderMaterial = true;
  19859. /**
  19860. * parameters = {
  19861. * color: <hex>,
  19862. * roughness: <float>,
  19863. * metalness: <float>,
  19864. * opacity: <float>,
  19865. *
  19866. * map: new THREE.Texture( <Image> ),
  19867. *
  19868. * lightMap: new THREE.Texture( <Image> ),
  19869. * lightMapIntensity: <float>
  19870. *
  19871. * aoMap: new THREE.Texture( <Image> ),
  19872. * aoMapIntensity: <float>
  19873. *
  19874. * emissive: <hex>,
  19875. * emissiveIntensity: <float>
  19876. * emissiveMap: new THREE.Texture( <Image> ),
  19877. *
  19878. * bumpMap: new THREE.Texture( <Image> ),
  19879. * bumpScale: <float>,
  19880. *
  19881. * normalMap: new THREE.Texture( <Image> ),
  19882. * normalMapType: THREE.TangentSpaceNormalMap,
  19883. * normalScale: <Vector2>,
  19884. *
  19885. * displacementMap: new THREE.Texture( <Image> ),
  19886. * displacementScale: <float>,
  19887. * displacementBias: <float>,
  19888. *
  19889. * roughnessMap: new THREE.Texture( <Image> ),
  19890. *
  19891. * metalnessMap: new THREE.Texture( <Image> ),
  19892. *
  19893. * alphaMap: new THREE.Texture( <Image> ),
  19894. *
  19895. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  19896. * envMapIntensity: <float>
  19897. *
  19898. * refractionRatio: <float>,
  19899. *
  19900. * wireframe: <boolean>,
  19901. * wireframeLinewidth: <float>,
  19902. *
  19903. * skinning: <bool>,
  19904. * morphTargets: <bool>,
  19905. * morphNormals: <bool>
  19906. * }
  19907. */
  19908. function MeshStandardMaterial( parameters ) {
  19909. Material.call( this );
  19910. this.defines = { 'STANDARD': '' };
  19911. this.type = 'MeshStandardMaterial';
  19912. this.color = new Color( 0xffffff ); // diffuse
  19913. this.roughness = 1.0;
  19914. this.metalness = 0.0;
  19915. this.map = null;
  19916. this.lightMap = null;
  19917. this.lightMapIntensity = 1.0;
  19918. this.aoMap = null;
  19919. this.aoMapIntensity = 1.0;
  19920. this.emissive = new Color( 0x000000 );
  19921. this.emissiveIntensity = 1.0;
  19922. this.emissiveMap = null;
  19923. this.bumpMap = null;
  19924. this.bumpScale = 1;
  19925. this.normalMap = null;
  19926. this.normalMapType = TangentSpaceNormalMap;
  19927. this.normalScale = new Vector2( 1, 1 );
  19928. this.displacementMap = null;
  19929. this.displacementScale = 1;
  19930. this.displacementBias = 0;
  19931. this.roughnessMap = null;
  19932. this.metalnessMap = null;
  19933. this.alphaMap = null;
  19934. this.envMap = null;
  19935. this.envMapIntensity = 1.0;
  19936. this.refractionRatio = 0.98;
  19937. this.wireframe = false;
  19938. this.wireframeLinewidth = 1;
  19939. this.wireframeLinecap = 'round';
  19940. this.wireframeLinejoin = 'round';
  19941. this.skinning = false;
  19942. this.morphTargets = false;
  19943. this.morphNormals = false;
  19944. this.vertexTangents = false;
  19945. this.setValues( parameters );
  19946. }
  19947. MeshStandardMaterial.prototype = Object.create( Material.prototype );
  19948. MeshStandardMaterial.prototype.constructor = MeshStandardMaterial;
  19949. MeshStandardMaterial.prototype.isMeshStandardMaterial = true;
  19950. MeshStandardMaterial.prototype.copy = function ( source ) {
  19951. Material.prototype.copy.call( this, source );
  19952. this.defines = { 'STANDARD': '' };
  19953. this.color.copy( source.color );
  19954. this.roughness = source.roughness;
  19955. this.metalness = source.metalness;
  19956. this.map = source.map;
  19957. this.lightMap = source.lightMap;
  19958. this.lightMapIntensity = source.lightMapIntensity;
  19959. this.aoMap = source.aoMap;
  19960. this.aoMapIntensity = source.aoMapIntensity;
  19961. this.emissive.copy( source.emissive );
  19962. this.emissiveMap = source.emissiveMap;
  19963. this.emissiveIntensity = source.emissiveIntensity;
  19964. this.bumpMap = source.bumpMap;
  19965. this.bumpScale = source.bumpScale;
  19966. this.normalMap = source.normalMap;
  19967. this.normalMapType = source.normalMapType;
  19968. this.normalScale.copy( source.normalScale );
  19969. this.displacementMap = source.displacementMap;
  19970. this.displacementScale = source.displacementScale;
  19971. this.displacementBias = source.displacementBias;
  19972. this.roughnessMap = source.roughnessMap;
  19973. this.metalnessMap = source.metalnessMap;
  19974. this.alphaMap = source.alphaMap;
  19975. this.envMap = source.envMap;
  19976. this.envMapIntensity = source.envMapIntensity;
  19977. this.refractionRatio = source.refractionRatio;
  19978. this.wireframe = source.wireframe;
  19979. this.wireframeLinewidth = source.wireframeLinewidth;
  19980. this.wireframeLinecap = source.wireframeLinecap;
  19981. this.wireframeLinejoin = source.wireframeLinejoin;
  19982. this.skinning = source.skinning;
  19983. this.morphTargets = source.morphTargets;
  19984. this.morphNormals = source.morphNormals;
  19985. this.vertexTangents = source.vertexTangents;
  19986. return this;
  19987. };
  19988. /**
  19989. * parameters = {
  19990. * clearcoat: <float>,
  19991. * clearcoatMap: new THREE.Texture( <Image> ),
  19992. * clearcoatRoughness: <float>,
  19993. * clearcoatRoughnessMap: new THREE.Texture( <Image> ),
  19994. * clearcoatNormalScale: <Vector2>,
  19995. * clearcoatNormalMap: new THREE.Texture( <Image> ),
  19996. *
  19997. * reflectivity: <float>,
  19998. * ior: <float>,
  19999. *
  20000. * sheen: <Color>,
  20001. *
  20002. * transmission: <float>,
  20003. * transmissionMap: new THREE.Texture( <Image> )
  20004. * }
  20005. */
  20006. function MeshPhysicalMaterial( parameters ) {
  20007. MeshStandardMaterial.call( this );
  20008. this.defines = {
  20009. 'STANDARD': '',
  20010. 'PHYSICAL': ''
  20011. };
  20012. this.type = 'MeshPhysicalMaterial';
  20013. this.clearcoat = 0.0;
  20014. this.clearcoatMap = null;
  20015. this.clearcoatRoughness = 0.0;
  20016. this.clearcoatRoughnessMap = null;
  20017. this.clearcoatNormalScale = new Vector2( 1, 1 );
  20018. this.clearcoatNormalMap = null;
  20019. this.reflectivity = 0.5; // maps to F0 = 0.04
  20020. Object.defineProperty( this, 'ior', {
  20021. get: function () {
  20022. return ( 1 + 0.4 * this.reflectivity ) / ( 1 - 0.4 * this.reflectivity );
  20023. },
  20024. set: function ( ior ) {
  20025. this.reflectivity = MathUtils.clamp( 2.5 * ( ior - 1 ) / ( ior + 1 ), 0, 1 );
  20026. }
  20027. } );
  20028. this.sheen = null; // null will disable sheen bsdf
  20029. this.transmission = 0.0;
  20030. this.transmissionMap = null;
  20031. this.setValues( parameters );
  20032. }
  20033. MeshPhysicalMaterial.prototype = Object.create( MeshStandardMaterial.prototype );
  20034. MeshPhysicalMaterial.prototype.constructor = MeshPhysicalMaterial;
  20035. MeshPhysicalMaterial.prototype.isMeshPhysicalMaterial = true;
  20036. MeshPhysicalMaterial.prototype.copy = function ( source ) {
  20037. MeshStandardMaterial.prototype.copy.call( this, source );
  20038. this.defines = {
  20039. 'STANDARD': '',
  20040. 'PHYSICAL': ''
  20041. };
  20042. this.clearcoat = source.clearcoat;
  20043. this.clearcoatMap = source.clearcoatMap;
  20044. this.clearcoatRoughness = source.clearcoatRoughness;
  20045. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  20046. this.clearcoatNormalMap = source.clearcoatNormalMap;
  20047. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  20048. this.reflectivity = source.reflectivity;
  20049. if ( source.sheen ) {
  20050. this.sheen = ( this.sheen || new Color() ).copy( source.sheen );
  20051. } else {
  20052. this.sheen = null;
  20053. }
  20054. this.transmission = source.transmission;
  20055. this.transmissionMap = source.transmissionMap;
  20056. return this;
  20057. };
  20058. /**
  20059. * parameters = {
  20060. * color: <hex>,
  20061. * specular: <hex>,
  20062. * shininess: <float>,
  20063. * opacity: <float>,
  20064. *
  20065. * map: new THREE.Texture( <Image> ),
  20066. *
  20067. * lightMap: new THREE.Texture( <Image> ),
  20068. * lightMapIntensity: <float>
  20069. *
  20070. * aoMap: new THREE.Texture( <Image> ),
  20071. * aoMapIntensity: <float>
  20072. *
  20073. * emissive: <hex>,
  20074. * emissiveIntensity: <float>
  20075. * emissiveMap: new THREE.Texture( <Image> ),
  20076. *
  20077. * bumpMap: new THREE.Texture( <Image> ),
  20078. * bumpScale: <float>,
  20079. *
  20080. * normalMap: new THREE.Texture( <Image> ),
  20081. * normalMapType: THREE.TangentSpaceNormalMap,
  20082. * normalScale: <Vector2>,
  20083. *
  20084. * displacementMap: new THREE.Texture( <Image> ),
  20085. * displacementScale: <float>,
  20086. * displacementBias: <float>,
  20087. *
  20088. * specularMap: new THREE.Texture( <Image> ),
  20089. *
  20090. * alphaMap: new THREE.Texture( <Image> ),
  20091. *
  20092. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20093. * combine: THREE.MultiplyOperation,
  20094. * reflectivity: <float>,
  20095. * refractionRatio: <float>,
  20096. *
  20097. * wireframe: <boolean>,
  20098. * wireframeLinewidth: <float>,
  20099. *
  20100. * skinning: <bool>,
  20101. * morphTargets: <bool>,
  20102. * morphNormals: <bool>
  20103. * }
  20104. */
  20105. function MeshPhongMaterial( parameters ) {
  20106. Material.call( this );
  20107. this.type = 'MeshPhongMaterial';
  20108. this.color = new Color( 0xffffff ); // diffuse
  20109. this.specular = new Color( 0x111111 );
  20110. this.shininess = 30;
  20111. this.map = null;
  20112. this.lightMap = null;
  20113. this.lightMapIntensity = 1.0;
  20114. this.aoMap = null;
  20115. this.aoMapIntensity = 1.0;
  20116. this.emissive = new Color( 0x000000 );
  20117. this.emissiveIntensity = 1.0;
  20118. this.emissiveMap = null;
  20119. this.bumpMap = null;
  20120. this.bumpScale = 1;
  20121. this.normalMap = null;
  20122. this.normalMapType = TangentSpaceNormalMap;
  20123. this.normalScale = new Vector2( 1, 1 );
  20124. this.displacementMap = null;
  20125. this.displacementScale = 1;
  20126. this.displacementBias = 0;
  20127. this.specularMap = null;
  20128. this.alphaMap = null;
  20129. this.envMap = null;
  20130. this.combine = MultiplyOperation;
  20131. this.reflectivity = 1;
  20132. this.refractionRatio = 0.98;
  20133. this.wireframe = false;
  20134. this.wireframeLinewidth = 1;
  20135. this.wireframeLinecap = 'round';
  20136. this.wireframeLinejoin = 'round';
  20137. this.skinning = false;
  20138. this.morphTargets = false;
  20139. this.morphNormals = false;
  20140. this.setValues( parameters );
  20141. }
  20142. MeshPhongMaterial.prototype = Object.create( Material.prototype );
  20143. MeshPhongMaterial.prototype.constructor = MeshPhongMaterial;
  20144. MeshPhongMaterial.prototype.isMeshPhongMaterial = true;
  20145. MeshPhongMaterial.prototype.copy = function ( source ) {
  20146. Material.prototype.copy.call( this, source );
  20147. this.color.copy( source.color );
  20148. this.specular.copy( source.specular );
  20149. this.shininess = source.shininess;
  20150. this.map = source.map;
  20151. this.lightMap = source.lightMap;
  20152. this.lightMapIntensity = source.lightMapIntensity;
  20153. this.aoMap = source.aoMap;
  20154. this.aoMapIntensity = source.aoMapIntensity;
  20155. this.emissive.copy( source.emissive );
  20156. this.emissiveMap = source.emissiveMap;
  20157. this.emissiveIntensity = source.emissiveIntensity;
  20158. this.bumpMap = source.bumpMap;
  20159. this.bumpScale = source.bumpScale;
  20160. this.normalMap = source.normalMap;
  20161. this.normalMapType = source.normalMapType;
  20162. this.normalScale.copy( source.normalScale );
  20163. this.displacementMap = source.displacementMap;
  20164. this.displacementScale = source.displacementScale;
  20165. this.displacementBias = source.displacementBias;
  20166. this.specularMap = source.specularMap;
  20167. this.alphaMap = source.alphaMap;
  20168. this.envMap = source.envMap;
  20169. this.combine = source.combine;
  20170. this.reflectivity = source.reflectivity;
  20171. this.refractionRatio = source.refractionRatio;
  20172. this.wireframe = source.wireframe;
  20173. this.wireframeLinewidth = source.wireframeLinewidth;
  20174. this.wireframeLinecap = source.wireframeLinecap;
  20175. this.wireframeLinejoin = source.wireframeLinejoin;
  20176. this.skinning = source.skinning;
  20177. this.morphTargets = source.morphTargets;
  20178. this.morphNormals = source.morphNormals;
  20179. return this;
  20180. };
  20181. /**
  20182. * parameters = {
  20183. * color: <hex>,
  20184. *
  20185. * map: new THREE.Texture( <Image> ),
  20186. * gradientMap: new THREE.Texture( <Image> ),
  20187. *
  20188. * lightMap: new THREE.Texture( <Image> ),
  20189. * lightMapIntensity: <float>
  20190. *
  20191. * aoMap: new THREE.Texture( <Image> ),
  20192. * aoMapIntensity: <float>
  20193. *
  20194. * emissive: <hex>,
  20195. * emissiveIntensity: <float>
  20196. * emissiveMap: new THREE.Texture( <Image> ),
  20197. *
  20198. * bumpMap: new THREE.Texture( <Image> ),
  20199. * bumpScale: <float>,
  20200. *
  20201. * normalMap: new THREE.Texture( <Image> ),
  20202. * normalMapType: THREE.TangentSpaceNormalMap,
  20203. * normalScale: <Vector2>,
  20204. *
  20205. * displacementMap: new THREE.Texture( <Image> ),
  20206. * displacementScale: <float>,
  20207. * displacementBias: <float>,
  20208. *
  20209. * alphaMap: new THREE.Texture( <Image> ),
  20210. *
  20211. * wireframe: <boolean>,
  20212. * wireframeLinewidth: <float>,
  20213. *
  20214. * skinning: <bool>,
  20215. * morphTargets: <bool>,
  20216. * morphNormals: <bool>
  20217. * }
  20218. */
  20219. function MeshToonMaterial( parameters ) {
  20220. Material.call( this );
  20221. this.defines = { 'TOON': '' };
  20222. this.type = 'MeshToonMaterial';
  20223. this.color = new Color( 0xffffff );
  20224. this.map = null;
  20225. this.gradientMap = null;
  20226. this.lightMap = null;
  20227. this.lightMapIntensity = 1.0;
  20228. this.aoMap = null;
  20229. this.aoMapIntensity = 1.0;
  20230. this.emissive = new Color( 0x000000 );
  20231. this.emissiveIntensity = 1.0;
  20232. this.emissiveMap = null;
  20233. this.bumpMap = null;
  20234. this.bumpScale = 1;
  20235. this.normalMap = null;
  20236. this.normalMapType = TangentSpaceNormalMap;
  20237. this.normalScale = new Vector2( 1, 1 );
  20238. this.displacementMap = null;
  20239. this.displacementScale = 1;
  20240. this.displacementBias = 0;
  20241. this.alphaMap = null;
  20242. this.wireframe = false;
  20243. this.wireframeLinewidth = 1;
  20244. this.wireframeLinecap = 'round';
  20245. this.wireframeLinejoin = 'round';
  20246. this.skinning = false;
  20247. this.morphTargets = false;
  20248. this.morphNormals = false;
  20249. this.setValues( parameters );
  20250. }
  20251. MeshToonMaterial.prototype = Object.create( Material.prototype );
  20252. MeshToonMaterial.prototype.constructor = MeshToonMaterial;
  20253. MeshToonMaterial.prototype.isMeshToonMaterial = true;
  20254. MeshToonMaterial.prototype.copy = function ( source ) {
  20255. Material.prototype.copy.call( this, source );
  20256. this.color.copy( source.color );
  20257. this.map = source.map;
  20258. this.gradientMap = source.gradientMap;
  20259. this.lightMap = source.lightMap;
  20260. this.lightMapIntensity = source.lightMapIntensity;
  20261. this.aoMap = source.aoMap;
  20262. this.aoMapIntensity = source.aoMapIntensity;
  20263. this.emissive.copy( source.emissive );
  20264. this.emissiveMap = source.emissiveMap;
  20265. this.emissiveIntensity = source.emissiveIntensity;
  20266. this.bumpMap = source.bumpMap;
  20267. this.bumpScale = source.bumpScale;
  20268. this.normalMap = source.normalMap;
  20269. this.normalMapType = source.normalMapType;
  20270. this.normalScale.copy( source.normalScale );
  20271. this.displacementMap = source.displacementMap;
  20272. this.displacementScale = source.displacementScale;
  20273. this.displacementBias = source.displacementBias;
  20274. this.alphaMap = source.alphaMap;
  20275. this.wireframe = source.wireframe;
  20276. this.wireframeLinewidth = source.wireframeLinewidth;
  20277. this.wireframeLinecap = source.wireframeLinecap;
  20278. this.wireframeLinejoin = source.wireframeLinejoin;
  20279. this.skinning = source.skinning;
  20280. this.morphTargets = source.morphTargets;
  20281. this.morphNormals = source.morphNormals;
  20282. return this;
  20283. };
  20284. /**
  20285. * parameters = {
  20286. * opacity: <float>,
  20287. *
  20288. * bumpMap: new THREE.Texture( <Image> ),
  20289. * bumpScale: <float>,
  20290. *
  20291. * normalMap: new THREE.Texture( <Image> ),
  20292. * normalMapType: THREE.TangentSpaceNormalMap,
  20293. * normalScale: <Vector2>,
  20294. *
  20295. * displacementMap: new THREE.Texture( <Image> ),
  20296. * displacementScale: <float>,
  20297. * displacementBias: <float>,
  20298. *
  20299. * wireframe: <boolean>,
  20300. * wireframeLinewidth: <float>
  20301. *
  20302. * skinning: <bool>,
  20303. * morphTargets: <bool>,
  20304. * morphNormals: <bool>
  20305. * }
  20306. */
  20307. function MeshNormalMaterial( parameters ) {
  20308. Material.call( this );
  20309. this.type = 'MeshNormalMaterial';
  20310. this.bumpMap = null;
  20311. this.bumpScale = 1;
  20312. this.normalMap = null;
  20313. this.normalMapType = TangentSpaceNormalMap;
  20314. this.normalScale = new Vector2( 1, 1 );
  20315. this.displacementMap = null;
  20316. this.displacementScale = 1;
  20317. this.displacementBias = 0;
  20318. this.wireframe = false;
  20319. this.wireframeLinewidth = 1;
  20320. this.fog = false;
  20321. this.skinning = false;
  20322. this.morphTargets = false;
  20323. this.morphNormals = false;
  20324. this.setValues( parameters );
  20325. }
  20326. MeshNormalMaterial.prototype = Object.create( Material.prototype );
  20327. MeshNormalMaterial.prototype.constructor = MeshNormalMaterial;
  20328. MeshNormalMaterial.prototype.isMeshNormalMaterial = true;
  20329. MeshNormalMaterial.prototype.copy = function ( source ) {
  20330. Material.prototype.copy.call( this, source );
  20331. this.bumpMap = source.bumpMap;
  20332. this.bumpScale = source.bumpScale;
  20333. this.normalMap = source.normalMap;
  20334. this.normalMapType = source.normalMapType;
  20335. this.normalScale.copy( source.normalScale );
  20336. this.displacementMap = source.displacementMap;
  20337. this.displacementScale = source.displacementScale;
  20338. this.displacementBias = source.displacementBias;
  20339. this.wireframe = source.wireframe;
  20340. this.wireframeLinewidth = source.wireframeLinewidth;
  20341. this.skinning = source.skinning;
  20342. this.morphTargets = source.morphTargets;
  20343. this.morphNormals = source.morphNormals;
  20344. return this;
  20345. };
  20346. /**
  20347. * parameters = {
  20348. * color: <hex>,
  20349. * opacity: <float>,
  20350. *
  20351. * map: new THREE.Texture( <Image> ),
  20352. *
  20353. * lightMap: new THREE.Texture( <Image> ),
  20354. * lightMapIntensity: <float>
  20355. *
  20356. * aoMap: new THREE.Texture( <Image> ),
  20357. * aoMapIntensity: <float>
  20358. *
  20359. * emissive: <hex>,
  20360. * emissiveIntensity: <float>
  20361. * emissiveMap: new THREE.Texture( <Image> ),
  20362. *
  20363. * specularMap: new THREE.Texture( <Image> ),
  20364. *
  20365. * alphaMap: new THREE.Texture( <Image> ),
  20366. *
  20367. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  20368. * combine: THREE.Multiply,
  20369. * reflectivity: <float>,
  20370. * refractionRatio: <float>,
  20371. *
  20372. * wireframe: <boolean>,
  20373. * wireframeLinewidth: <float>,
  20374. *
  20375. * skinning: <bool>,
  20376. * morphTargets: <bool>,
  20377. * morphNormals: <bool>
  20378. * }
  20379. */
  20380. function MeshLambertMaterial( parameters ) {
  20381. Material.call( this );
  20382. this.type = 'MeshLambertMaterial';
  20383. this.color = new Color( 0xffffff ); // diffuse
  20384. this.map = null;
  20385. this.lightMap = null;
  20386. this.lightMapIntensity = 1.0;
  20387. this.aoMap = null;
  20388. this.aoMapIntensity = 1.0;
  20389. this.emissive = new Color( 0x000000 );
  20390. this.emissiveIntensity = 1.0;
  20391. this.emissiveMap = null;
  20392. this.specularMap = null;
  20393. this.alphaMap = null;
  20394. this.envMap = null;
  20395. this.combine = MultiplyOperation;
  20396. this.reflectivity = 1;
  20397. this.refractionRatio = 0.98;
  20398. this.wireframe = false;
  20399. this.wireframeLinewidth = 1;
  20400. this.wireframeLinecap = 'round';
  20401. this.wireframeLinejoin = 'round';
  20402. this.skinning = false;
  20403. this.morphTargets = false;
  20404. this.morphNormals = false;
  20405. this.setValues( parameters );
  20406. }
  20407. MeshLambertMaterial.prototype = Object.create( Material.prototype );
  20408. MeshLambertMaterial.prototype.constructor = MeshLambertMaterial;
  20409. MeshLambertMaterial.prototype.isMeshLambertMaterial = true;
  20410. MeshLambertMaterial.prototype.copy = function ( source ) {
  20411. Material.prototype.copy.call( this, source );
  20412. this.color.copy( source.color );
  20413. this.map = source.map;
  20414. this.lightMap = source.lightMap;
  20415. this.lightMapIntensity = source.lightMapIntensity;
  20416. this.aoMap = source.aoMap;
  20417. this.aoMapIntensity = source.aoMapIntensity;
  20418. this.emissive.copy( source.emissive );
  20419. this.emissiveMap = source.emissiveMap;
  20420. this.emissiveIntensity = source.emissiveIntensity;
  20421. this.specularMap = source.specularMap;
  20422. this.alphaMap = source.alphaMap;
  20423. this.envMap = source.envMap;
  20424. this.combine = source.combine;
  20425. this.reflectivity = source.reflectivity;
  20426. this.refractionRatio = source.refractionRatio;
  20427. this.wireframe = source.wireframe;
  20428. this.wireframeLinewidth = source.wireframeLinewidth;
  20429. this.wireframeLinecap = source.wireframeLinecap;
  20430. this.wireframeLinejoin = source.wireframeLinejoin;
  20431. this.skinning = source.skinning;
  20432. this.morphTargets = source.morphTargets;
  20433. this.morphNormals = source.morphNormals;
  20434. return this;
  20435. };
  20436. /**
  20437. * parameters = {
  20438. * color: <hex>,
  20439. * opacity: <float>,
  20440. *
  20441. * matcap: new THREE.Texture( <Image> ),
  20442. *
  20443. * map: new THREE.Texture( <Image> ),
  20444. *
  20445. * bumpMap: new THREE.Texture( <Image> ),
  20446. * bumpScale: <float>,
  20447. *
  20448. * normalMap: new THREE.Texture( <Image> ),
  20449. * normalMapType: THREE.TangentSpaceNormalMap,
  20450. * normalScale: <Vector2>,
  20451. *
  20452. * displacementMap: new THREE.Texture( <Image> ),
  20453. * displacementScale: <float>,
  20454. * displacementBias: <float>,
  20455. *
  20456. * alphaMap: new THREE.Texture( <Image> ),
  20457. *
  20458. * skinning: <bool>,
  20459. * morphTargets: <bool>,
  20460. * morphNormals: <bool>
  20461. * }
  20462. */
  20463. function MeshMatcapMaterial( parameters ) {
  20464. Material.call( this );
  20465. this.defines = { 'MATCAP': '' };
  20466. this.type = 'MeshMatcapMaterial';
  20467. this.color = new Color( 0xffffff ); // diffuse
  20468. this.matcap = null;
  20469. this.map = null;
  20470. this.bumpMap = null;
  20471. this.bumpScale = 1;
  20472. this.normalMap = null;
  20473. this.normalMapType = TangentSpaceNormalMap;
  20474. this.normalScale = new Vector2( 1, 1 );
  20475. this.displacementMap = null;
  20476. this.displacementScale = 1;
  20477. this.displacementBias = 0;
  20478. this.alphaMap = null;
  20479. this.skinning = false;
  20480. this.morphTargets = false;
  20481. this.morphNormals = false;
  20482. this.setValues( parameters );
  20483. }
  20484. MeshMatcapMaterial.prototype = Object.create( Material.prototype );
  20485. MeshMatcapMaterial.prototype.constructor = MeshMatcapMaterial;
  20486. MeshMatcapMaterial.prototype.isMeshMatcapMaterial = true;
  20487. MeshMatcapMaterial.prototype.copy = function ( source ) {
  20488. Material.prototype.copy.call( this, source );
  20489. this.defines = { 'MATCAP': '' };
  20490. this.color.copy( source.color );
  20491. this.matcap = source.matcap;
  20492. this.map = source.map;
  20493. this.bumpMap = source.bumpMap;
  20494. this.bumpScale = source.bumpScale;
  20495. this.normalMap = source.normalMap;
  20496. this.normalMapType = source.normalMapType;
  20497. this.normalScale.copy( source.normalScale );
  20498. this.displacementMap = source.displacementMap;
  20499. this.displacementScale = source.displacementScale;
  20500. this.displacementBias = source.displacementBias;
  20501. this.alphaMap = source.alphaMap;
  20502. this.skinning = source.skinning;
  20503. this.morphTargets = source.morphTargets;
  20504. this.morphNormals = source.morphNormals;
  20505. return this;
  20506. };
  20507. /**
  20508. * parameters = {
  20509. * color: <hex>,
  20510. * opacity: <float>,
  20511. *
  20512. * linewidth: <float>,
  20513. *
  20514. * scale: <float>,
  20515. * dashSize: <float>,
  20516. * gapSize: <float>
  20517. * }
  20518. */
  20519. function LineDashedMaterial( parameters ) {
  20520. LineBasicMaterial.call( this );
  20521. this.type = 'LineDashedMaterial';
  20522. this.scale = 1;
  20523. this.dashSize = 3;
  20524. this.gapSize = 1;
  20525. this.setValues( parameters );
  20526. }
  20527. LineDashedMaterial.prototype = Object.create( LineBasicMaterial.prototype );
  20528. LineDashedMaterial.prototype.constructor = LineDashedMaterial;
  20529. LineDashedMaterial.prototype.isLineDashedMaterial = true;
  20530. LineDashedMaterial.prototype.copy = function ( source ) {
  20531. LineBasicMaterial.prototype.copy.call( this, source );
  20532. this.scale = source.scale;
  20533. this.dashSize = source.dashSize;
  20534. this.gapSize = source.gapSize;
  20535. return this;
  20536. };
  20537. var Materials = /*#__PURE__*/Object.freeze({
  20538. __proto__: null,
  20539. ShadowMaterial: ShadowMaterial,
  20540. SpriteMaterial: SpriteMaterial,
  20541. RawShaderMaterial: RawShaderMaterial,
  20542. ShaderMaterial: ShaderMaterial,
  20543. PointsMaterial: PointsMaterial,
  20544. MeshPhysicalMaterial: MeshPhysicalMaterial,
  20545. MeshStandardMaterial: MeshStandardMaterial,
  20546. MeshPhongMaterial: MeshPhongMaterial,
  20547. MeshToonMaterial: MeshToonMaterial,
  20548. MeshNormalMaterial: MeshNormalMaterial,
  20549. MeshLambertMaterial: MeshLambertMaterial,
  20550. MeshDepthMaterial: MeshDepthMaterial,
  20551. MeshDistanceMaterial: MeshDistanceMaterial,
  20552. MeshBasicMaterial: MeshBasicMaterial,
  20553. MeshMatcapMaterial: MeshMatcapMaterial,
  20554. LineDashedMaterial: LineDashedMaterial,
  20555. LineBasicMaterial: LineBasicMaterial,
  20556. Material: Material
  20557. });
  20558. const AnimationUtils = {
  20559. // same as Array.prototype.slice, but also works on typed arrays
  20560. arraySlice: function ( array, from, to ) {
  20561. if ( AnimationUtils.isTypedArray( array ) ) {
  20562. // in ios9 array.subarray(from, undefined) will return empty array
  20563. // but array.subarray(from) or array.subarray(from, len) is correct
  20564. return new array.constructor( array.subarray( from, to !== undefined ? to : array.length ) );
  20565. }
  20566. return array.slice( from, to );
  20567. },
  20568. // converts an array to a specific type
  20569. convertArray: function ( array, type, forceClone ) {
  20570. if ( ! array || // let 'undefined' and 'null' pass
  20571. ! forceClone && array.constructor === type ) return array;
  20572. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  20573. return new type( array ); // create typed array
  20574. }
  20575. return Array.prototype.slice.call( array ); // create Array
  20576. },
  20577. isTypedArray: function ( object ) {
  20578. return ArrayBuffer.isView( object ) &&
  20579. ! ( object instanceof DataView );
  20580. },
  20581. // returns an array by which times and values can be sorted
  20582. getKeyframeOrder: function ( times ) {
  20583. function compareTime( i, j ) {
  20584. return times[ i ] - times[ j ];
  20585. }
  20586. const n = times.length;
  20587. const result = new Array( n );
  20588. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  20589. result.sort( compareTime );
  20590. return result;
  20591. },
  20592. // uses the array previously returned by 'getKeyframeOrder' to sort data
  20593. sortedArray: function ( values, stride, order ) {
  20594. const nValues = values.length;
  20595. const result = new values.constructor( nValues );
  20596. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  20597. const srcOffset = order[ i ] * stride;
  20598. for ( let j = 0; j !== stride; ++ j ) {
  20599. result[ dstOffset ++ ] = values[ srcOffset + j ];
  20600. }
  20601. }
  20602. return result;
  20603. },
  20604. // function for parsing AOS keyframe formats
  20605. flattenJSON: function ( jsonKeys, times, values, valuePropertyName ) {
  20606. let i = 1, key = jsonKeys[ 0 ];
  20607. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  20608. key = jsonKeys[ i ++ ];
  20609. }
  20610. if ( key === undefined ) return; // no data
  20611. let value = key[ valuePropertyName ];
  20612. if ( value === undefined ) return; // no data
  20613. if ( Array.isArray( value ) ) {
  20614. do {
  20615. value = key[ valuePropertyName ];
  20616. if ( value !== undefined ) {
  20617. times.push( key.time );
  20618. values.push.apply( values, value ); // push all elements
  20619. }
  20620. key = jsonKeys[ i ++ ];
  20621. } while ( key !== undefined );
  20622. } else if ( value.toArray !== undefined ) {
  20623. // ...assume THREE.Math-ish
  20624. do {
  20625. value = key[ valuePropertyName ];
  20626. if ( value !== undefined ) {
  20627. times.push( key.time );
  20628. value.toArray( values, values.length );
  20629. }
  20630. key = jsonKeys[ i ++ ];
  20631. } while ( key !== undefined );
  20632. } else {
  20633. // otherwise push as-is
  20634. do {
  20635. value = key[ valuePropertyName ];
  20636. if ( value !== undefined ) {
  20637. times.push( key.time );
  20638. values.push( value );
  20639. }
  20640. key = jsonKeys[ i ++ ];
  20641. } while ( key !== undefined );
  20642. }
  20643. },
  20644. subclip: function ( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  20645. const clip = sourceClip.clone();
  20646. clip.name = name;
  20647. const tracks = [];
  20648. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  20649. const track = clip.tracks[ i ];
  20650. const valueSize = track.getValueSize();
  20651. const times = [];
  20652. const values = [];
  20653. for ( let j = 0; j < track.times.length; ++ j ) {
  20654. const frame = track.times[ j ] * fps;
  20655. if ( frame < startFrame || frame >= endFrame ) continue;
  20656. times.push( track.times[ j ] );
  20657. for ( let k = 0; k < valueSize; ++ k ) {
  20658. values.push( track.values[ j * valueSize + k ] );
  20659. }
  20660. }
  20661. if ( times.length === 0 ) continue;
  20662. track.times = AnimationUtils.convertArray( times, track.times.constructor );
  20663. track.values = AnimationUtils.convertArray( values, track.values.constructor );
  20664. tracks.push( track );
  20665. }
  20666. clip.tracks = tracks;
  20667. // find minimum .times value across all tracks in the trimmed clip
  20668. let minStartTime = Infinity;
  20669. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  20670. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  20671. minStartTime = clip.tracks[ i ].times[ 0 ];
  20672. }
  20673. }
  20674. // shift all tracks such that clip begins at t=0
  20675. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  20676. clip.tracks[ i ].shift( - 1 * minStartTime );
  20677. }
  20678. clip.resetDuration();
  20679. return clip;
  20680. },
  20681. makeClipAdditive: function ( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  20682. if ( fps <= 0 ) fps = 30;
  20683. const numTracks = referenceClip.tracks.length;
  20684. const referenceTime = referenceFrame / fps;
  20685. // Make each track's values relative to the values at the reference frame
  20686. for ( let i = 0; i < numTracks; ++ i ) {
  20687. const referenceTrack = referenceClip.tracks[ i ];
  20688. const referenceTrackType = referenceTrack.ValueTypeName;
  20689. // Skip this track if it's non-numeric
  20690. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  20691. // Find the track in the target clip whose name and type matches the reference track
  20692. const targetTrack = targetClip.tracks.find( function ( track ) {
  20693. return track.name === referenceTrack.name
  20694. && track.ValueTypeName === referenceTrackType;
  20695. } );
  20696. if ( targetTrack === undefined ) continue;
  20697. let referenceOffset = 0;
  20698. const referenceValueSize = referenceTrack.getValueSize();
  20699. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  20700. referenceOffset = referenceValueSize / 3;
  20701. }
  20702. let targetOffset = 0;
  20703. const targetValueSize = targetTrack.getValueSize();
  20704. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  20705. targetOffset = targetValueSize / 3;
  20706. }
  20707. const lastIndex = referenceTrack.times.length - 1;
  20708. let referenceValue;
  20709. // Find the value to subtract out of the track
  20710. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  20711. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  20712. const startIndex = referenceOffset;
  20713. const endIndex = referenceValueSize - referenceOffset;
  20714. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  20715. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  20716. // Reference frame is after the last keyframe, so just use the last keyframe
  20717. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  20718. const endIndex = startIndex + referenceValueSize - referenceOffset;
  20719. referenceValue = AnimationUtils.arraySlice( referenceTrack.values, startIndex, endIndex );
  20720. } else {
  20721. // Interpolate to the reference value
  20722. const interpolant = referenceTrack.createInterpolant();
  20723. const startIndex = referenceOffset;
  20724. const endIndex = referenceValueSize - referenceOffset;
  20725. interpolant.evaluate( referenceTime );
  20726. referenceValue = AnimationUtils.arraySlice( interpolant.resultBuffer, startIndex, endIndex );
  20727. }
  20728. // Conjugate the quaternion
  20729. if ( referenceTrackType === 'quaternion' ) {
  20730. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  20731. referenceQuat.toArray( referenceValue );
  20732. }
  20733. // Subtract the reference value from all of the track values
  20734. const numTimes = targetTrack.times.length;
  20735. for ( let j = 0; j < numTimes; ++ j ) {
  20736. const valueStart = j * targetValueSize + targetOffset;
  20737. if ( referenceTrackType === 'quaternion' ) {
  20738. // Multiply the conjugate for quaternion track types
  20739. Quaternion.multiplyQuaternionsFlat(
  20740. targetTrack.values,
  20741. valueStart,
  20742. referenceValue,
  20743. 0,
  20744. targetTrack.values,
  20745. valueStart
  20746. );
  20747. } else {
  20748. const valueEnd = targetValueSize - targetOffset * 2;
  20749. // Subtract each value for all other numeric track types
  20750. for ( let k = 0; k < valueEnd; ++ k ) {
  20751. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  20752. }
  20753. }
  20754. }
  20755. }
  20756. targetClip.blendMode = AdditiveAnimationBlendMode;
  20757. return targetClip;
  20758. }
  20759. };
  20760. /**
  20761. * Abstract base class of interpolants over parametric samples.
  20762. *
  20763. * The parameter domain is one dimensional, typically the time or a path
  20764. * along a curve defined by the data.
  20765. *
  20766. * The sample values can have any dimensionality and derived classes may
  20767. * apply special interpretations to the data.
  20768. *
  20769. * This class provides the interval seek in a Template Method, deferring
  20770. * the actual interpolation to derived classes.
  20771. *
  20772. * Time complexity is O(1) for linear access crossing at most two points
  20773. * and O(log N) for random access, where N is the number of positions.
  20774. *
  20775. * References:
  20776. *
  20777. * http://www.oodesign.com/template-method-pattern.html
  20778. *
  20779. */
  20780. function Interpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20781. this.parameterPositions = parameterPositions;
  20782. this._cachedIndex = 0;
  20783. this.resultBuffer = resultBuffer !== undefined ?
  20784. resultBuffer : new sampleValues.constructor( sampleSize );
  20785. this.sampleValues = sampleValues;
  20786. this.valueSize = sampleSize;
  20787. }
  20788. Object.assign( Interpolant.prototype, {
  20789. evaluate: function ( t ) {
  20790. const pp = this.parameterPositions;
  20791. let i1 = this._cachedIndex,
  20792. t1 = pp[ i1 ],
  20793. t0 = pp[ i1 - 1 ];
  20794. validate_interval: {
  20795. seek: {
  20796. let right;
  20797. linear_scan: {
  20798. //- See http://jsperf.com/comparison-to-undefined/3
  20799. //- slower code:
  20800. //-
  20801. //- if ( t >= t1 || t1 === undefined ) {
  20802. forward_scan: if ( ! ( t < t1 ) ) {
  20803. for ( let giveUpAt = i1 + 2; ; ) {
  20804. if ( t1 === undefined ) {
  20805. if ( t < t0 ) break forward_scan;
  20806. // after end
  20807. i1 = pp.length;
  20808. this._cachedIndex = i1;
  20809. return this.afterEnd_( i1 - 1, t, t0 );
  20810. }
  20811. if ( i1 === giveUpAt ) break; // this loop
  20812. t0 = t1;
  20813. t1 = pp[ ++ i1 ];
  20814. if ( t < t1 ) {
  20815. // we have arrived at the sought interval
  20816. break seek;
  20817. }
  20818. }
  20819. // prepare binary search on the right side of the index
  20820. right = pp.length;
  20821. break linear_scan;
  20822. }
  20823. //- slower code:
  20824. //- if ( t < t0 || t0 === undefined ) {
  20825. if ( ! ( t >= t0 ) ) {
  20826. // looping?
  20827. const t1global = pp[ 1 ];
  20828. if ( t < t1global ) {
  20829. i1 = 2; // + 1, using the scan for the details
  20830. t0 = t1global;
  20831. }
  20832. // linear reverse scan
  20833. for ( let giveUpAt = i1 - 2; ; ) {
  20834. if ( t0 === undefined ) {
  20835. // before start
  20836. this._cachedIndex = 0;
  20837. return this.beforeStart_( 0, t, t1 );
  20838. }
  20839. if ( i1 === giveUpAt ) break; // this loop
  20840. t1 = t0;
  20841. t0 = pp[ -- i1 - 1 ];
  20842. if ( t >= t0 ) {
  20843. // we have arrived at the sought interval
  20844. break seek;
  20845. }
  20846. }
  20847. // prepare binary search on the left side of the index
  20848. right = i1;
  20849. i1 = 0;
  20850. break linear_scan;
  20851. }
  20852. // the interval is valid
  20853. break validate_interval;
  20854. } // linear scan
  20855. // binary search
  20856. while ( i1 < right ) {
  20857. const mid = ( i1 + right ) >>> 1;
  20858. if ( t < pp[ mid ] ) {
  20859. right = mid;
  20860. } else {
  20861. i1 = mid + 1;
  20862. }
  20863. }
  20864. t1 = pp[ i1 ];
  20865. t0 = pp[ i1 - 1 ];
  20866. // check boundary cases, again
  20867. if ( t0 === undefined ) {
  20868. this._cachedIndex = 0;
  20869. return this.beforeStart_( 0, t, t1 );
  20870. }
  20871. if ( t1 === undefined ) {
  20872. i1 = pp.length;
  20873. this._cachedIndex = i1;
  20874. return this.afterEnd_( i1 - 1, t0, t );
  20875. }
  20876. } // seek
  20877. this._cachedIndex = i1;
  20878. this.intervalChanged_( i1, t0, t1 );
  20879. } // validate_interval
  20880. return this.interpolate_( i1, t0, t, t1 );
  20881. },
  20882. settings: null, // optional, subclass-specific settings structure
  20883. // Note: The indirection allows central control of many interpolants.
  20884. // --- Protected interface
  20885. DefaultSettings_: {},
  20886. getSettings_: function () {
  20887. return this.settings || this.DefaultSettings_;
  20888. },
  20889. copySampleValue_: function ( index ) {
  20890. // copies a sample value to the result buffer
  20891. const result = this.resultBuffer,
  20892. values = this.sampleValues,
  20893. stride = this.valueSize,
  20894. offset = index * stride;
  20895. for ( let i = 0; i !== stride; ++ i ) {
  20896. result[ i ] = values[ offset + i ];
  20897. }
  20898. return result;
  20899. },
  20900. // Template methods for derived classes:
  20901. interpolate_: function ( /* i1, t0, t, t1 */ ) {
  20902. throw new Error( 'call to abstract method' );
  20903. // implementations shall return this.resultBuffer
  20904. },
  20905. intervalChanged_: function ( /* i1, t0, t1 */ ) {
  20906. // empty
  20907. }
  20908. } );
  20909. // DECLARE ALIAS AFTER assign prototype
  20910. Object.assign( Interpolant.prototype, {
  20911. //( 0, t, t0 ), returns this.resultBuffer
  20912. beforeStart_: Interpolant.prototype.copySampleValue_,
  20913. //( N-1, tN-1, t ), returns this.resultBuffer
  20914. afterEnd_: Interpolant.prototype.copySampleValue_,
  20915. } );
  20916. /**
  20917. * Fast and simple cubic spline interpolant.
  20918. *
  20919. * It was derived from a Hermitian construction setting the first derivative
  20920. * at each sample position to the linear slope between neighboring positions
  20921. * over their parameter interval.
  20922. */
  20923. function CubicInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  20924. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  20925. this._weightPrev = - 0;
  20926. this._offsetPrev = - 0;
  20927. this._weightNext = - 0;
  20928. this._offsetNext = - 0;
  20929. }
  20930. CubicInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  20931. constructor: CubicInterpolant,
  20932. DefaultSettings_: {
  20933. endingStart: ZeroCurvatureEnding,
  20934. endingEnd: ZeroCurvatureEnding
  20935. },
  20936. intervalChanged_: function ( i1, t0, t1 ) {
  20937. const pp = this.parameterPositions;
  20938. let iPrev = i1 - 2,
  20939. iNext = i1 + 1,
  20940. tPrev = pp[ iPrev ],
  20941. tNext = pp[ iNext ];
  20942. if ( tPrev === undefined ) {
  20943. switch ( this.getSettings_().endingStart ) {
  20944. case ZeroSlopeEnding:
  20945. // f'(t0) = 0
  20946. iPrev = i1;
  20947. tPrev = 2 * t0 - t1;
  20948. break;
  20949. case WrapAroundEnding:
  20950. // use the other end of the curve
  20951. iPrev = pp.length - 2;
  20952. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  20953. break;
  20954. default: // ZeroCurvatureEnding
  20955. // f''(t0) = 0 a.k.a. Natural Spline
  20956. iPrev = i1;
  20957. tPrev = t1;
  20958. }
  20959. }
  20960. if ( tNext === undefined ) {
  20961. switch ( this.getSettings_().endingEnd ) {
  20962. case ZeroSlopeEnding:
  20963. // f'(tN) = 0
  20964. iNext = i1;
  20965. tNext = 2 * t1 - t0;
  20966. break;
  20967. case WrapAroundEnding:
  20968. // use the other end of the curve
  20969. iNext = 1;
  20970. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  20971. break;
  20972. default: // ZeroCurvatureEnding
  20973. // f''(tN) = 0, a.k.a. Natural Spline
  20974. iNext = i1 - 1;
  20975. tNext = t0;
  20976. }
  20977. }
  20978. const halfDt = ( t1 - t0 ) * 0.5,
  20979. stride = this.valueSize;
  20980. this._weightPrev = halfDt / ( t0 - tPrev );
  20981. this._weightNext = halfDt / ( tNext - t1 );
  20982. this._offsetPrev = iPrev * stride;
  20983. this._offsetNext = iNext * stride;
  20984. },
  20985. interpolate_: function ( i1, t0, t, t1 ) {
  20986. const result = this.resultBuffer,
  20987. values = this.sampleValues,
  20988. stride = this.valueSize,
  20989. o1 = i1 * stride, o0 = o1 - stride,
  20990. oP = this._offsetPrev, oN = this._offsetNext,
  20991. wP = this._weightPrev, wN = this._weightNext,
  20992. p = ( t - t0 ) / ( t1 - t0 ),
  20993. pp = p * p,
  20994. ppp = pp * p;
  20995. // evaluate polynomials
  20996. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  20997. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  20998. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  20999. const sN = wN * ppp - wN * pp;
  21000. // combine data linearly
  21001. for ( let i = 0; i !== stride; ++ i ) {
  21002. result[ i ] =
  21003. sP * values[ oP + i ] +
  21004. s0 * values[ o0 + i ] +
  21005. s1 * values[ o1 + i ] +
  21006. sN * values[ oN + i ];
  21007. }
  21008. return result;
  21009. }
  21010. } );
  21011. function LinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21012. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21013. }
  21014. LinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21015. constructor: LinearInterpolant,
  21016. interpolate_: function ( i1, t0, t, t1 ) {
  21017. const result = this.resultBuffer,
  21018. values = this.sampleValues,
  21019. stride = this.valueSize,
  21020. offset1 = i1 * stride,
  21021. offset0 = offset1 - stride,
  21022. weight1 = ( t - t0 ) / ( t1 - t0 ),
  21023. weight0 = 1 - weight1;
  21024. for ( let i = 0; i !== stride; ++ i ) {
  21025. result[ i ] =
  21026. values[ offset0 + i ] * weight0 +
  21027. values[ offset1 + i ] * weight1;
  21028. }
  21029. return result;
  21030. }
  21031. } );
  21032. /**
  21033. *
  21034. * Interpolant that evaluates to the sample value at the position preceeding
  21035. * the parameter.
  21036. */
  21037. function DiscreteInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21038. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21039. }
  21040. DiscreteInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21041. constructor: DiscreteInterpolant,
  21042. interpolate_: function ( i1 /*, t0, t, t1 */ ) {
  21043. return this.copySampleValue_( i1 - 1 );
  21044. }
  21045. } );
  21046. function KeyframeTrack( name, times, values, interpolation ) {
  21047. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  21048. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  21049. this.name = name;
  21050. this.times = AnimationUtils.convertArray( times, this.TimeBufferType );
  21051. this.values = AnimationUtils.convertArray( values, this.ValueBufferType );
  21052. this.setInterpolation( interpolation || this.DefaultInterpolation );
  21053. }
  21054. // Static methods
  21055. Object.assign( KeyframeTrack, {
  21056. // Serialization (in static context, because of constructor invocation
  21057. // and automatic invocation of .toJSON):
  21058. toJSON: function ( track ) {
  21059. const trackType = track.constructor;
  21060. let json;
  21061. // derived classes can define a static toJSON method
  21062. if ( trackType.toJSON !== undefined ) {
  21063. json = trackType.toJSON( track );
  21064. } else {
  21065. // by default, we assume the data can be serialized as-is
  21066. json = {
  21067. 'name': track.name,
  21068. 'times': AnimationUtils.convertArray( track.times, Array ),
  21069. 'values': AnimationUtils.convertArray( track.values, Array )
  21070. };
  21071. const interpolation = track.getInterpolation();
  21072. if ( interpolation !== track.DefaultInterpolation ) {
  21073. json.interpolation = interpolation;
  21074. }
  21075. }
  21076. json.type = track.ValueTypeName; // mandatory
  21077. return json;
  21078. }
  21079. } );
  21080. Object.assign( KeyframeTrack.prototype, {
  21081. constructor: KeyframeTrack,
  21082. TimeBufferType: Float32Array,
  21083. ValueBufferType: Float32Array,
  21084. DefaultInterpolation: InterpolateLinear,
  21085. InterpolantFactoryMethodDiscrete: function ( result ) {
  21086. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  21087. },
  21088. InterpolantFactoryMethodLinear: function ( result ) {
  21089. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21090. },
  21091. InterpolantFactoryMethodSmooth: function ( result ) {
  21092. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  21093. },
  21094. setInterpolation: function ( interpolation ) {
  21095. let factoryMethod;
  21096. switch ( interpolation ) {
  21097. case InterpolateDiscrete:
  21098. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  21099. break;
  21100. case InterpolateLinear:
  21101. factoryMethod = this.InterpolantFactoryMethodLinear;
  21102. break;
  21103. case InterpolateSmooth:
  21104. factoryMethod = this.InterpolantFactoryMethodSmooth;
  21105. break;
  21106. }
  21107. if ( factoryMethod === undefined ) {
  21108. const message = 'unsupported interpolation for ' +
  21109. this.ValueTypeName + ' keyframe track named ' + this.name;
  21110. if ( this.createInterpolant === undefined ) {
  21111. // fall back to default, unless the default itself is messed up
  21112. if ( interpolation !== this.DefaultInterpolation ) {
  21113. this.setInterpolation( this.DefaultInterpolation );
  21114. } else {
  21115. throw new Error( message ); // fatal, in this case
  21116. }
  21117. }
  21118. console.warn( 'THREE.KeyframeTrack:', message );
  21119. return this;
  21120. }
  21121. this.createInterpolant = factoryMethod;
  21122. return this;
  21123. },
  21124. getInterpolation: function () {
  21125. switch ( this.createInterpolant ) {
  21126. case this.InterpolantFactoryMethodDiscrete:
  21127. return InterpolateDiscrete;
  21128. case this.InterpolantFactoryMethodLinear:
  21129. return InterpolateLinear;
  21130. case this.InterpolantFactoryMethodSmooth:
  21131. return InterpolateSmooth;
  21132. }
  21133. },
  21134. getValueSize: function () {
  21135. return this.values.length / this.times.length;
  21136. },
  21137. // move all keyframes either forwards or backwards in time
  21138. shift: function ( timeOffset ) {
  21139. if ( timeOffset !== 0.0 ) {
  21140. const times = this.times;
  21141. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  21142. times[ i ] += timeOffset;
  21143. }
  21144. }
  21145. return this;
  21146. },
  21147. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  21148. scale: function ( timeScale ) {
  21149. if ( timeScale !== 1.0 ) {
  21150. const times = this.times;
  21151. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  21152. times[ i ] *= timeScale;
  21153. }
  21154. }
  21155. return this;
  21156. },
  21157. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  21158. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  21159. trim: function ( startTime, endTime ) {
  21160. const times = this.times,
  21161. nKeys = times.length;
  21162. let from = 0,
  21163. to = nKeys - 1;
  21164. while ( from !== nKeys && times[ from ] < startTime ) {
  21165. ++ from;
  21166. }
  21167. while ( to !== - 1 && times[ to ] > endTime ) {
  21168. -- to;
  21169. }
  21170. ++ to; // inclusive -> exclusive bound
  21171. if ( from !== 0 || to !== nKeys ) {
  21172. // empty tracks are forbidden, so keep at least one keyframe
  21173. if ( from >= to ) {
  21174. to = Math.max( to, 1 );
  21175. from = to - 1;
  21176. }
  21177. const stride = this.getValueSize();
  21178. this.times = AnimationUtils.arraySlice( times, from, to );
  21179. this.values = AnimationUtils.arraySlice( this.values, from * stride, to * stride );
  21180. }
  21181. return this;
  21182. },
  21183. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  21184. validate: function () {
  21185. let valid = true;
  21186. const valueSize = this.getValueSize();
  21187. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  21188. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  21189. valid = false;
  21190. }
  21191. const times = this.times,
  21192. values = this.values,
  21193. nKeys = times.length;
  21194. if ( nKeys === 0 ) {
  21195. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  21196. valid = false;
  21197. }
  21198. let prevTime = null;
  21199. for ( let i = 0; i !== nKeys; i ++ ) {
  21200. const currTime = times[ i ];
  21201. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  21202. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  21203. valid = false;
  21204. break;
  21205. }
  21206. if ( prevTime !== null && prevTime > currTime ) {
  21207. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  21208. valid = false;
  21209. break;
  21210. }
  21211. prevTime = currTime;
  21212. }
  21213. if ( values !== undefined ) {
  21214. if ( AnimationUtils.isTypedArray( values ) ) {
  21215. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  21216. const value = values[ i ];
  21217. if ( isNaN( value ) ) {
  21218. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  21219. valid = false;
  21220. break;
  21221. }
  21222. }
  21223. }
  21224. }
  21225. return valid;
  21226. },
  21227. // removes equivalent sequential keys as common in morph target sequences
  21228. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  21229. optimize: function () {
  21230. // times or values may be shared with other tracks, so overwriting is unsafe
  21231. const times = AnimationUtils.arraySlice( this.times ),
  21232. values = AnimationUtils.arraySlice( this.values ),
  21233. stride = this.getValueSize(),
  21234. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  21235. lastIndex = times.length - 1;
  21236. let writeIndex = 1;
  21237. for ( let i = 1; i < lastIndex; ++ i ) {
  21238. let keep = false;
  21239. const time = times[ i ];
  21240. const timeNext = times[ i + 1 ];
  21241. // remove adjacent keyframes scheduled at the same time
  21242. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  21243. if ( ! smoothInterpolation ) {
  21244. // remove unnecessary keyframes same as their neighbors
  21245. const offset = i * stride,
  21246. offsetP = offset - stride,
  21247. offsetN = offset + stride;
  21248. for ( let j = 0; j !== stride; ++ j ) {
  21249. const value = values[ offset + j ];
  21250. if ( value !== values[ offsetP + j ] ||
  21251. value !== values[ offsetN + j ] ) {
  21252. keep = true;
  21253. break;
  21254. }
  21255. }
  21256. } else {
  21257. keep = true;
  21258. }
  21259. }
  21260. // in-place compaction
  21261. if ( keep ) {
  21262. if ( i !== writeIndex ) {
  21263. times[ writeIndex ] = times[ i ];
  21264. const readOffset = i * stride,
  21265. writeOffset = writeIndex * stride;
  21266. for ( let j = 0; j !== stride; ++ j ) {
  21267. values[ writeOffset + j ] = values[ readOffset + j ];
  21268. }
  21269. }
  21270. ++ writeIndex;
  21271. }
  21272. }
  21273. // flush last keyframe (compaction looks ahead)
  21274. if ( lastIndex > 0 ) {
  21275. times[ writeIndex ] = times[ lastIndex ];
  21276. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  21277. values[ writeOffset + j ] = values[ readOffset + j ];
  21278. }
  21279. ++ writeIndex;
  21280. }
  21281. if ( writeIndex !== times.length ) {
  21282. this.times = AnimationUtils.arraySlice( times, 0, writeIndex );
  21283. this.values = AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  21284. } else {
  21285. this.times = times;
  21286. this.values = values;
  21287. }
  21288. return this;
  21289. },
  21290. clone: function () {
  21291. const times = AnimationUtils.arraySlice( this.times, 0 );
  21292. const values = AnimationUtils.arraySlice( this.values, 0 );
  21293. const TypedKeyframeTrack = this.constructor;
  21294. const track = new TypedKeyframeTrack( this.name, times, values );
  21295. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  21296. track.createInterpolant = this.createInterpolant;
  21297. return track;
  21298. }
  21299. } );
  21300. /**
  21301. * A Track of Boolean keyframe values.
  21302. */
  21303. function BooleanKeyframeTrack( name, times, values ) {
  21304. KeyframeTrack.call( this, name, times, values );
  21305. }
  21306. BooleanKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21307. constructor: BooleanKeyframeTrack,
  21308. ValueTypeName: 'bool',
  21309. ValueBufferType: Array,
  21310. DefaultInterpolation: InterpolateDiscrete,
  21311. InterpolantFactoryMethodLinear: undefined,
  21312. InterpolantFactoryMethodSmooth: undefined
  21313. // Note: Actually this track could have a optimized / compressed
  21314. // representation of a single value and a custom interpolant that
  21315. // computes "firstValue ^ isOdd( index )".
  21316. } );
  21317. /**
  21318. * A Track of keyframe values that represent color.
  21319. */
  21320. function ColorKeyframeTrack( name, times, values, interpolation ) {
  21321. KeyframeTrack.call( this, name, times, values, interpolation );
  21322. }
  21323. ColorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21324. constructor: ColorKeyframeTrack,
  21325. ValueTypeName: 'color'
  21326. // ValueBufferType is inherited
  21327. // DefaultInterpolation is inherited
  21328. // Note: Very basic implementation and nothing special yet.
  21329. // However, this is the place for color space parameterization.
  21330. } );
  21331. /**
  21332. * A Track of numeric keyframe values.
  21333. */
  21334. function NumberKeyframeTrack( name, times, values, interpolation ) {
  21335. KeyframeTrack.call( this, name, times, values, interpolation );
  21336. }
  21337. NumberKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21338. constructor: NumberKeyframeTrack,
  21339. ValueTypeName: 'number'
  21340. // ValueBufferType is inherited
  21341. // DefaultInterpolation is inherited
  21342. } );
  21343. /**
  21344. * Spherical linear unit quaternion interpolant.
  21345. */
  21346. function QuaternionLinearInterpolant( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  21347. Interpolant.call( this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  21348. }
  21349. QuaternionLinearInterpolant.prototype = Object.assign( Object.create( Interpolant.prototype ), {
  21350. constructor: QuaternionLinearInterpolant,
  21351. interpolate_: function ( i1, t0, t, t1 ) {
  21352. const result = this.resultBuffer,
  21353. values = this.sampleValues,
  21354. stride = this.valueSize,
  21355. alpha = ( t - t0 ) / ( t1 - t0 );
  21356. let offset = i1 * stride;
  21357. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  21358. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  21359. }
  21360. return result;
  21361. }
  21362. } );
  21363. /**
  21364. * A Track of quaternion keyframe values.
  21365. */
  21366. function QuaternionKeyframeTrack( name, times, values, interpolation ) {
  21367. KeyframeTrack.call( this, name, times, values, interpolation );
  21368. }
  21369. QuaternionKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21370. constructor: QuaternionKeyframeTrack,
  21371. ValueTypeName: 'quaternion',
  21372. // ValueBufferType is inherited
  21373. DefaultInterpolation: InterpolateLinear,
  21374. InterpolantFactoryMethodLinear: function ( result ) {
  21375. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  21376. },
  21377. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  21378. } );
  21379. /**
  21380. * A Track that interpolates Strings
  21381. */
  21382. function StringKeyframeTrack( name, times, values, interpolation ) {
  21383. KeyframeTrack.call( this, name, times, values, interpolation );
  21384. }
  21385. StringKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21386. constructor: StringKeyframeTrack,
  21387. ValueTypeName: 'string',
  21388. ValueBufferType: Array,
  21389. DefaultInterpolation: InterpolateDiscrete,
  21390. InterpolantFactoryMethodLinear: undefined,
  21391. InterpolantFactoryMethodSmooth: undefined
  21392. } );
  21393. /**
  21394. * A Track of vectored keyframe values.
  21395. */
  21396. function VectorKeyframeTrack( name, times, values, interpolation ) {
  21397. KeyframeTrack.call( this, name, times, values, interpolation );
  21398. }
  21399. VectorKeyframeTrack.prototype = Object.assign( Object.create( KeyframeTrack.prototype ), {
  21400. constructor: VectorKeyframeTrack,
  21401. ValueTypeName: 'vector'
  21402. // ValueBufferType is inherited
  21403. // DefaultInterpolation is inherited
  21404. } );
  21405. function AnimationClip( name, duration = - 1, tracks, blendMode = NormalAnimationBlendMode ) {
  21406. this.name = name;
  21407. this.tracks = tracks;
  21408. this.duration = duration;
  21409. this.blendMode = blendMode;
  21410. this.uuid = MathUtils.generateUUID();
  21411. // this means it should figure out its duration by scanning the tracks
  21412. if ( this.duration < 0 ) {
  21413. this.resetDuration();
  21414. }
  21415. }
  21416. function getTrackTypeForValueTypeName( typeName ) {
  21417. switch ( typeName.toLowerCase() ) {
  21418. case 'scalar':
  21419. case 'double':
  21420. case 'float':
  21421. case 'number':
  21422. case 'integer':
  21423. return NumberKeyframeTrack;
  21424. case 'vector':
  21425. case 'vector2':
  21426. case 'vector3':
  21427. case 'vector4':
  21428. return VectorKeyframeTrack;
  21429. case 'color':
  21430. return ColorKeyframeTrack;
  21431. case 'quaternion':
  21432. return QuaternionKeyframeTrack;
  21433. case 'bool':
  21434. case 'boolean':
  21435. return BooleanKeyframeTrack;
  21436. case 'string':
  21437. return StringKeyframeTrack;
  21438. }
  21439. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  21440. }
  21441. function parseKeyframeTrack( json ) {
  21442. if ( json.type === undefined ) {
  21443. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  21444. }
  21445. const trackType = getTrackTypeForValueTypeName( json.type );
  21446. if ( json.times === undefined ) {
  21447. const times = [], values = [];
  21448. AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  21449. json.times = times;
  21450. json.values = values;
  21451. }
  21452. // derived classes can define a static parse method
  21453. if ( trackType.parse !== undefined ) {
  21454. return trackType.parse( json );
  21455. } else {
  21456. // by default, we assume a constructor compatible with the base
  21457. return new trackType( json.name, json.times, json.values, json.interpolation );
  21458. }
  21459. }
  21460. Object.assign( AnimationClip, {
  21461. parse: function ( json ) {
  21462. const tracks = [],
  21463. jsonTracks = json.tracks,
  21464. frameTime = 1.0 / ( json.fps || 1.0 );
  21465. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  21466. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  21467. }
  21468. const clip = new AnimationClip( json.name, json.duration, tracks, json.blendMode );
  21469. clip.uuid = json.uuid;
  21470. return clip;
  21471. },
  21472. toJSON: function ( clip ) {
  21473. const tracks = [],
  21474. clipTracks = clip.tracks;
  21475. const json = {
  21476. 'name': clip.name,
  21477. 'duration': clip.duration,
  21478. 'tracks': tracks,
  21479. 'uuid': clip.uuid,
  21480. 'blendMode': clip.blendMode
  21481. };
  21482. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  21483. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  21484. }
  21485. return json;
  21486. },
  21487. CreateFromMorphTargetSequence: function ( name, morphTargetSequence, fps, noLoop ) {
  21488. const numMorphTargets = morphTargetSequence.length;
  21489. const tracks = [];
  21490. for ( let i = 0; i < numMorphTargets; i ++ ) {
  21491. let times = [];
  21492. let values = [];
  21493. times.push(
  21494. ( i + numMorphTargets - 1 ) % numMorphTargets,
  21495. i,
  21496. ( i + 1 ) % numMorphTargets );
  21497. values.push( 0, 1, 0 );
  21498. const order = AnimationUtils.getKeyframeOrder( times );
  21499. times = AnimationUtils.sortedArray( times, 1, order );
  21500. values = AnimationUtils.sortedArray( values, 1, order );
  21501. // if there is a key at the first frame, duplicate it as the
  21502. // last frame as well for perfect loop.
  21503. if ( ! noLoop && times[ 0 ] === 0 ) {
  21504. times.push( numMorphTargets );
  21505. values.push( values[ 0 ] );
  21506. }
  21507. tracks.push(
  21508. new NumberKeyframeTrack(
  21509. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  21510. times, values
  21511. ).scale( 1.0 / fps ) );
  21512. }
  21513. return new AnimationClip( name, - 1, tracks );
  21514. },
  21515. findByName: function ( objectOrClipArray, name ) {
  21516. let clipArray = objectOrClipArray;
  21517. if ( ! Array.isArray( objectOrClipArray ) ) {
  21518. const o = objectOrClipArray;
  21519. clipArray = o.geometry && o.geometry.animations || o.animations;
  21520. }
  21521. for ( let i = 0; i < clipArray.length; i ++ ) {
  21522. if ( clipArray[ i ].name === name ) {
  21523. return clipArray[ i ];
  21524. }
  21525. }
  21526. return null;
  21527. },
  21528. CreateClipsFromMorphTargetSequences: function ( morphTargets, fps, noLoop ) {
  21529. const animationToMorphTargets = {};
  21530. // tested with https://regex101.com/ on trick sequences
  21531. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  21532. const pattern = /^([\w-]*?)([\d]+)$/;
  21533. // sort morph target names into animation groups based
  21534. // patterns like Walk_001, Walk_002, Run_001, Run_002
  21535. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  21536. const morphTarget = morphTargets[ i ];
  21537. const parts = morphTarget.name.match( pattern );
  21538. if ( parts && parts.length > 1 ) {
  21539. const name = parts[ 1 ];
  21540. let animationMorphTargets = animationToMorphTargets[ name ];
  21541. if ( ! animationMorphTargets ) {
  21542. animationToMorphTargets[ name ] = animationMorphTargets = [];
  21543. }
  21544. animationMorphTargets.push( morphTarget );
  21545. }
  21546. }
  21547. const clips = [];
  21548. for ( const name in animationToMorphTargets ) {
  21549. clips.push( AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  21550. }
  21551. return clips;
  21552. },
  21553. // parse the animation.hierarchy format
  21554. parseAnimation: function ( animation, bones ) {
  21555. if ( ! animation ) {
  21556. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  21557. return null;
  21558. }
  21559. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  21560. // only return track if there are actually keys.
  21561. if ( animationKeys.length !== 0 ) {
  21562. const times = [];
  21563. const values = [];
  21564. AnimationUtils.flattenJSON( animationKeys, times, values, propertyName );
  21565. // empty keys are filtered out, so check again
  21566. if ( times.length !== 0 ) {
  21567. destTracks.push( new trackType( trackName, times, values ) );
  21568. }
  21569. }
  21570. };
  21571. const tracks = [];
  21572. const clipName = animation.name || 'default';
  21573. const fps = animation.fps || 30;
  21574. const blendMode = animation.blendMode;
  21575. // automatic length determination in AnimationClip.
  21576. let duration = animation.length || - 1;
  21577. const hierarchyTracks = animation.hierarchy || [];
  21578. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  21579. const animationKeys = hierarchyTracks[ h ].keys;
  21580. // skip empty tracks
  21581. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  21582. // process morph targets
  21583. if ( animationKeys[ 0 ].morphTargets ) {
  21584. // figure out all morph targets used in this track
  21585. const morphTargetNames = {};
  21586. let k;
  21587. for ( k = 0; k < animationKeys.length; k ++ ) {
  21588. if ( animationKeys[ k ].morphTargets ) {
  21589. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  21590. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  21591. }
  21592. }
  21593. }
  21594. // create a track for each morph target with all zero
  21595. // morphTargetInfluences except for the keys in which
  21596. // the morphTarget is named.
  21597. for ( const morphTargetName in morphTargetNames ) {
  21598. const times = [];
  21599. const values = [];
  21600. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  21601. const animationKey = animationKeys[ k ];
  21602. times.push( animationKey.time );
  21603. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  21604. }
  21605. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  21606. }
  21607. duration = morphTargetNames.length * ( fps || 1.0 );
  21608. } else {
  21609. // ...assume skeletal animation
  21610. const boneName = '.bones[' + bones[ h ].name + ']';
  21611. addNonemptyTrack(
  21612. VectorKeyframeTrack, boneName + '.position',
  21613. animationKeys, 'pos', tracks );
  21614. addNonemptyTrack(
  21615. QuaternionKeyframeTrack, boneName + '.quaternion',
  21616. animationKeys, 'rot', tracks );
  21617. addNonemptyTrack(
  21618. VectorKeyframeTrack, boneName + '.scale',
  21619. animationKeys, 'scl', tracks );
  21620. }
  21621. }
  21622. if ( tracks.length === 0 ) {
  21623. return null;
  21624. }
  21625. const clip = new AnimationClip( clipName, duration, tracks, blendMode );
  21626. return clip;
  21627. }
  21628. } );
  21629. Object.assign( AnimationClip.prototype, {
  21630. resetDuration: function () {
  21631. const tracks = this.tracks;
  21632. let duration = 0;
  21633. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  21634. const track = this.tracks[ i ];
  21635. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  21636. }
  21637. this.duration = duration;
  21638. return this;
  21639. },
  21640. trim: function () {
  21641. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21642. this.tracks[ i ].trim( 0, this.duration );
  21643. }
  21644. return this;
  21645. },
  21646. validate: function () {
  21647. let valid = true;
  21648. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21649. valid = valid && this.tracks[ i ].validate();
  21650. }
  21651. return valid;
  21652. },
  21653. optimize: function () {
  21654. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21655. this.tracks[ i ].optimize();
  21656. }
  21657. return this;
  21658. },
  21659. clone: function () {
  21660. const tracks = [];
  21661. for ( let i = 0; i < this.tracks.length; i ++ ) {
  21662. tracks.push( this.tracks[ i ].clone() );
  21663. }
  21664. return new AnimationClip( this.name, this.duration, tracks, this.blendMode );
  21665. },
  21666. toJSON: function () {
  21667. return AnimationClip.toJSON( this );
  21668. }
  21669. } );
  21670. const Cache = {
  21671. enabled: false,
  21672. files: {},
  21673. add: function ( key, file ) {
  21674. if ( this.enabled === false ) return;
  21675. // console.log( 'THREE.Cache', 'Adding key:', key );
  21676. this.files[ key ] = file;
  21677. },
  21678. get: function ( key ) {
  21679. if ( this.enabled === false ) return;
  21680. // console.log( 'THREE.Cache', 'Checking key:', key );
  21681. return this.files[ key ];
  21682. },
  21683. remove: function ( key ) {
  21684. delete this.files[ key ];
  21685. },
  21686. clear: function () {
  21687. this.files = {};
  21688. }
  21689. };
  21690. function LoadingManager( onLoad, onProgress, onError ) {
  21691. const scope = this;
  21692. let isLoading = false;
  21693. let itemsLoaded = 0;
  21694. let itemsTotal = 0;
  21695. let urlModifier = undefined;
  21696. const handlers = [];
  21697. // Refer to #5689 for the reason why we don't set .onStart
  21698. // in the constructor
  21699. this.onStart = undefined;
  21700. this.onLoad = onLoad;
  21701. this.onProgress = onProgress;
  21702. this.onError = onError;
  21703. this.itemStart = function ( url ) {
  21704. itemsTotal ++;
  21705. if ( isLoading === false ) {
  21706. if ( scope.onStart !== undefined ) {
  21707. scope.onStart( url, itemsLoaded, itemsTotal );
  21708. }
  21709. }
  21710. isLoading = true;
  21711. };
  21712. this.itemEnd = function ( url ) {
  21713. itemsLoaded ++;
  21714. if ( scope.onProgress !== undefined ) {
  21715. scope.onProgress( url, itemsLoaded, itemsTotal );
  21716. }
  21717. if ( itemsLoaded === itemsTotal ) {
  21718. isLoading = false;
  21719. if ( scope.onLoad !== undefined ) {
  21720. scope.onLoad();
  21721. }
  21722. }
  21723. };
  21724. this.itemError = function ( url ) {
  21725. if ( scope.onError !== undefined ) {
  21726. scope.onError( url );
  21727. }
  21728. };
  21729. this.resolveURL = function ( url ) {
  21730. if ( urlModifier ) {
  21731. return urlModifier( url );
  21732. }
  21733. return url;
  21734. };
  21735. this.setURLModifier = function ( transform ) {
  21736. urlModifier = transform;
  21737. return this;
  21738. };
  21739. this.addHandler = function ( regex, loader ) {
  21740. handlers.push( regex, loader );
  21741. return this;
  21742. };
  21743. this.removeHandler = function ( regex ) {
  21744. const index = handlers.indexOf( regex );
  21745. if ( index !== - 1 ) {
  21746. handlers.splice( index, 2 );
  21747. }
  21748. return this;
  21749. };
  21750. this.getHandler = function ( file ) {
  21751. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  21752. const regex = handlers[ i ];
  21753. const loader = handlers[ i + 1 ];
  21754. if ( regex.global ) regex.lastIndex = 0; // see #17920
  21755. if ( regex.test( file ) ) {
  21756. return loader;
  21757. }
  21758. }
  21759. return null;
  21760. };
  21761. }
  21762. const DefaultLoadingManager = new LoadingManager();
  21763. function Loader( manager ) {
  21764. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  21765. this.crossOrigin = 'anonymous';
  21766. this.withCredentials = false;
  21767. this.path = '';
  21768. this.resourcePath = '';
  21769. this.requestHeader = {};
  21770. }
  21771. Object.assign( Loader.prototype, {
  21772. load: function ( /* url, onLoad, onProgress, onError */ ) {},
  21773. loadAsync: function ( url, onProgress ) {
  21774. const scope = this;
  21775. return new Promise( function ( resolve, reject ) {
  21776. scope.load( url, resolve, onProgress, reject );
  21777. } );
  21778. },
  21779. parse: function ( /* data */ ) {},
  21780. setCrossOrigin: function ( crossOrigin ) {
  21781. this.crossOrigin = crossOrigin;
  21782. return this;
  21783. },
  21784. setWithCredentials: function ( value ) {
  21785. this.withCredentials = value;
  21786. return this;
  21787. },
  21788. setPath: function ( path ) {
  21789. this.path = path;
  21790. return this;
  21791. },
  21792. setResourcePath: function ( resourcePath ) {
  21793. this.resourcePath = resourcePath;
  21794. return this;
  21795. },
  21796. setRequestHeader: function ( requestHeader ) {
  21797. this.requestHeader = requestHeader;
  21798. return this;
  21799. }
  21800. } );
  21801. const loading = {};
  21802. function FileLoader( manager ) {
  21803. Loader.call( this, manager );
  21804. }
  21805. FileLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21806. constructor: FileLoader,
  21807. load: function ( url, onLoad, onProgress, onError ) {
  21808. if ( url === undefined ) url = '';
  21809. if ( this.path !== undefined ) url = this.path + url;
  21810. url = this.manager.resolveURL( url );
  21811. const scope = this;
  21812. const cached = Cache.get( url );
  21813. if ( cached !== undefined ) {
  21814. scope.manager.itemStart( url );
  21815. setTimeout( function () {
  21816. if ( onLoad ) onLoad( cached );
  21817. scope.manager.itemEnd( url );
  21818. }, 0 );
  21819. return cached;
  21820. }
  21821. // Check if request is duplicate
  21822. if ( loading[ url ] !== undefined ) {
  21823. loading[ url ].push( {
  21824. onLoad: onLoad,
  21825. onProgress: onProgress,
  21826. onError: onError
  21827. } );
  21828. return;
  21829. }
  21830. // Check for data: URI
  21831. const dataUriRegex = /^data:(.*?)(;base64)?,(.*)$/;
  21832. const dataUriRegexResult = url.match( dataUriRegex );
  21833. let request;
  21834. // Safari can not handle Data URIs through XMLHttpRequest so process manually
  21835. if ( dataUriRegexResult ) {
  21836. const mimeType = dataUriRegexResult[ 1 ];
  21837. const isBase64 = !! dataUriRegexResult[ 2 ];
  21838. let data = dataUriRegexResult[ 3 ];
  21839. data = decodeURIComponent( data );
  21840. if ( isBase64 ) data = atob( data );
  21841. try {
  21842. let response;
  21843. const responseType = ( this.responseType || '' ).toLowerCase();
  21844. switch ( responseType ) {
  21845. case 'arraybuffer':
  21846. case 'blob':
  21847. const view = new Uint8Array( data.length );
  21848. for ( let i = 0; i < data.length; i ++ ) {
  21849. view[ i ] = data.charCodeAt( i );
  21850. }
  21851. if ( responseType === 'blob' ) {
  21852. response = new Blob( [ view.buffer ], { type: mimeType } );
  21853. } else {
  21854. response = view.buffer;
  21855. }
  21856. break;
  21857. case 'document':
  21858. const parser = new DOMParser();
  21859. response = parser.parseFromString( data, mimeType );
  21860. break;
  21861. case 'json':
  21862. response = JSON.parse( data );
  21863. break;
  21864. default: // 'text' or other
  21865. response = data;
  21866. break;
  21867. }
  21868. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21869. setTimeout( function () {
  21870. if ( onLoad ) onLoad( response );
  21871. scope.manager.itemEnd( url );
  21872. }, 0 );
  21873. } catch ( error ) {
  21874. // Wait for next browser tick like standard XMLHttpRequest event dispatching does
  21875. setTimeout( function () {
  21876. if ( onError ) onError( error );
  21877. scope.manager.itemError( url );
  21878. scope.manager.itemEnd( url );
  21879. }, 0 );
  21880. }
  21881. } else {
  21882. // Initialise array for duplicate requests
  21883. loading[ url ] = [];
  21884. loading[ url ].push( {
  21885. onLoad: onLoad,
  21886. onProgress: onProgress,
  21887. onError: onError
  21888. } );
  21889. request = new XMLHttpRequest();
  21890. request.open( 'GET', url, true );
  21891. request.addEventListener( 'load', function ( event ) {
  21892. const response = this.response;
  21893. const callbacks = loading[ url ];
  21894. delete loading[ url ];
  21895. if ( this.status === 200 || this.status === 0 ) {
  21896. // Some browsers return HTTP Status 0 when using non-http protocol
  21897. // e.g. 'file://' or 'data://'. Handle as success.
  21898. if ( this.status === 0 ) console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  21899. // Add to cache only on HTTP success, so that we do not cache
  21900. // error response bodies as proper responses to requests.
  21901. Cache.add( url, response );
  21902. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  21903. const callback = callbacks[ i ];
  21904. if ( callback.onLoad ) callback.onLoad( response );
  21905. }
  21906. scope.manager.itemEnd( url );
  21907. } else {
  21908. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  21909. const callback = callbacks[ i ];
  21910. if ( callback.onError ) callback.onError( event );
  21911. }
  21912. scope.manager.itemError( url );
  21913. scope.manager.itemEnd( url );
  21914. }
  21915. }, false );
  21916. request.addEventListener( 'progress', function ( event ) {
  21917. const callbacks = loading[ url ];
  21918. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  21919. const callback = callbacks[ i ];
  21920. if ( callback.onProgress ) callback.onProgress( event );
  21921. }
  21922. }, false );
  21923. request.addEventListener( 'error', function ( event ) {
  21924. const callbacks = loading[ url ];
  21925. delete loading[ url ];
  21926. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  21927. const callback = callbacks[ i ];
  21928. if ( callback.onError ) callback.onError( event );
  21929. }
  21930. scope.manager.itemError( url );
  21931. scope.manager.itemEnd( url );
  21932. }, false );
  21933. request.addEventListener( 'abort', function ( event ) {
  21934. const callbacks = loading[ url ];
  21935. delete loading[ url ];
  21936. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  21937. const callback = callbacks[ i ];
  21938. if ( callback.onError ) callback.onError( event );
  21939. }
  21940. scope.manager.itemError( url );
  21941. scope.manager.itemEnd( url );
  21942. }, false );
  21943. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  21944. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  21945. if ( request.overrideMimeType ) request.overrideMimeType( this.mimeType !== undefined ? this.mimeType : 'text/plain' );
  21946. for ( const header in this.requestHeader ) {
  21947. request.setRequestHeader( header, this.requestHeader[ header ] );
  21948. }
  21949. request.send( null );
  21950. }
  21951. scope.manager.itemStart( url );
  21952. return request;
  21953. },
  21954. setResponseType: function ( value ) {
  21955. this.responseType = value;
  21956. return this;
  21957. },
  21958. setMimeType: function ( value ) {
  21959. this.mimeType = value;
  21960. return this;
  21961. }
  21962. } );
  21963. function AnimationLoader( manager ) {
  21964. Loader.call( this, manager );
  21965. }
  21966. AnimationLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  21967. constructor: AnimationLoader,
  21968. load: function ( url, onLoad, onProgress, onError ) {
  21969. const scope = this;
  21970. const loader = new FileLoader( scope.manager );
  21971. loader.setPath( scope.path );
  21972. loader.setRequestHeader( scope.requestHeader );
  21973. loader.setWithCredentials( scope.withCredentials );
  21974. loader.load( url, function ( text ) {
  21975. try {
  21976. onLoad( scope.parse( JSON.parse( text ) ) );
  21977. } catch ( e ) {
  21978. if ( onError ) {
  21979. onError( e );
  21980. } else {
  21981. console.error( e );
  21982. }
  21983. scope.manager.itemError( url );
  21984. }
  21985. }, onProgress, onError );
  21986. },
  21987. parse: function ( json ) {
  21988. const animations = [];
  21989. for ( let i = 0; i < json.length; i ++ ) {
  21990. const clip = AnimationClip.parse( json[ i ] );
  21991. animations.push( clip );
  21992. }
  21993. return animations;
  21994. }
  21995. } );
  21996. /**
  21997. * Abstract Base class to block based textures loader (dds, pvr, ...)
  21998. *
  21999. * Sub classes have to implement the parse() method which will be used in load().
  22000. */
  22001. function CompressedTextureLoader( manager ) {
  22002. Loader.call( this, manager );
  22003. }
  22004. CompressedTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22005. constructor: CompressedTextureLoader,
  22006. load: function ( url, onLoad, onProgress, onError ) {
  22007. const scope = this;
  22008. const images = [];
  22009. const texture = new CompressedTexture();
  22010. const loader = new FileLoader( this.manager );
  22011. loader.setPath( this.path );
  22012. loader.setResponseType( 'arraybuffer' );
  22013. loader.setRequestHeader( this.requestHeader );
  22014. loader.setWithCredentials( scope.withCredentials );
  22015. let loaded = 0;
  22016. function loadTexture( i ) {
  22017. loader.load( url[ i ], function ( buffer ) {
  22018. const texDatas = scope.parse( buffer, true );
  22019. images[ i ] = {
  22020. width: texDatas.width,
  22021. height: texDatas.height,
  22022. format: texDatas.format,
  22023. mipmaps: texDatas.mipmaps
  22024. };
  22025. loaded += 1;
  22026. if ( loaded === 6 ) {
  22027. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  22028. texture.image = images;
  22029. texture.format = texDatas.format;
  22030. texture.needsUpdate = true;
  22031. if ( onLoad ) onLoad( texture );
  22032. }
  22033. }, onProgress, onError );
  22034. }
  22035. if ( Array.isArray( url ) ) {
  22036. for ( let i = 0, il = url.length; i < il; ++ i ) {
  22037. loadTexture( i );
  22038. }
  22039. } else {
  22040. // compressed cubemap texture stored in a single DDS file
  22041. loader.load( url, function ( buffer ) {
  22042. const texDatas = scope.parse( buffer, true );
  22043. if ( texDatas.isCubemap ) {
  22044. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  22045. for ( let f = 0; f < faces; f ++ ) {
  22046. images[ f ] = { mipmaps: [] };
  22047. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  22048. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  22049. images[ f ].format = texDatas.format;
  22050. images[ f ].width = texDatas.width;
  22051. images[ f ].height = texDatas.height;
  22052. }
  22053. }
  22054. texture.image = images;
  22055. } else {
  22056. texture.image.width = texDatas.width;
  22057. texture.image.height = texDatas.height;
  22058. texture.mipmaps = texDatas.mipmaps;
  22059. }
  22060. if ( texDatas.mipmapCount === 1 ) {
  22061. texture.minFilter = LinearFilter;
  22062. }
  22063. texture.format = texDatas.format;
  22064. texture.needsUpdate = true;
  22065. if ( onLoad ) onLoad( texture );
  22066. }, onProgress, onError );
  22067. }
  22068. return texture;
  22069. }
  22070. } );
  22071. function ImageLoader( manager ) {
  22072. Loader.call( this, manager );
  22073. }
  22074. ImageLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22075. constructor: ImageLoader,
  22076. load: function ( url, onLoad, onProgress, onError ) {
  22077. if ( this.path !== undefined ) url = this.path + url;
  22078. url = this.manager.resolveURL( url );
  22079. const scope = this;
  22080. const cached = Cache.get( url );
  22081. if ( cached !== undefined ) {
  22082. scope.manager.itemStart( url );
  22083. setTimeout( function () {
  22084. if ( onLoad ) onLoad( cached );
  22085. scope.manager.itemEnd( url );
  22086. }, 0 );
  22087. return cached;
  22088. }
  22089. const image = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'img' );
  22090. function onImageLoad() {
  22091. image.removeEventListener( 'load', onImageLoad, false );
  22092. image.removeEventListener( 'error', onImageError, false );
  22093. Cache.add( url, this );
  22094. if ( onLoad ) onLoad( this );
  22095. scope.manager.itemEnd( url );
  22096. }
  22097. function onImageError( event ) {
  22098. image.removeEventListener( 'load', onImageLoad, false );
  22099. image.removeEventListener( 'error', onImageError, false );
  22100. if ( onError ) onError( event );
  22101. scope.manager.itemError( url );
  22102. scope.manager.itemEnd( url );
  22103. }
  22104. image.addEventListener( 'load', onImageLoad, false );
  22105. image.addEventListener( 'error', onImageError, false );
  22106. if ( url.substr( 0, 5 ) !== 'data:' ) {
  22107. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  22108. }
  22109. scope.manager.itemStart( url );
  22110. image.src = url;
  22111. return image;
  22112. }
  22113. } );
  22114. function CubeTextureLoader( manager ) {
  22115. Loader.call( this, manager );
  22116. }
  22117. CubeTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22118. constructor: CubeTextureLoader,
  22119. load: function ( urls, onLoad, onProgress, onError ) {
  22120. const texture = new CubeTexture();
  22121. const loader = new ImageLoader( this.manager );
  22122. loader.setCrossOrigin( this.crossOrigin );
  22123. loader.setPath( this.path );
  22124. let loaded = 0;
  22125. function loadTexture( i ) {
  22126. loader.load( urls[ i ], function ( image ) {
  22127. texture.images[ i ] = image;
  22128. loaded ++;
  22129. if ( loaded === 6 ) {
  22130. texture.needsUpdate = true;
  22131. if ( onLoad ) onLoad( texture );
  22132. }
  22133. }, undefined, onError );
  22134. }
  22135. for ( let i = 0; i < urls.length; ++ i ) {
  22136. loadTexture( i );
  22137. }
  22138. return texture;
  22139. }
  22140. } );
  22141. /**
  22142. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  22143. *
  22144. * Sub classes have to implement the parse() method which will be used in load().
  22145. */
  22146. function DataTextureLoader( manager ) {
  22147. Loader.call( this, manager );
  22148. }
  22149. DataTextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22150. constructor: DataTextureLoader,
  22151. load: function ( url, onLoad, onProgress, onError ) {
  22152. const scope = this;
  22153. const texture = new DataTexture();
  22154. const loader = new FileLoader( this.manager );
  22155. loader.setResponseType( 'arraybuffer' );
  22156. loader.setRequestHeader( this.requestHeader );
  22157. loader.setPath( this.path );
  22158. loader.setWithCredentials( scope.withCredentials );
  22159. loader.load( url, function ( buffer ) {
  22160. const texData = scope.parse( buffer );
  22161. if ( ! texData ) return;
  22162. if ( texData.image !== undefined ) {
  22163. texture.image = texData.image;
  22164. } else if ( texData.data !== undefined ) {
  22165. texture.image.width = texData.width;
  22166. texture.image.height = texData.height;
  22167. texture.image.data = texData.data;
  22168. }
  22169. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  22170. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  22171. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  22172. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  22173. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  22174. if ( texData.format !== undefined ) {
  22175. texture.format = texData.format;
  22176. }
  22177. if ( texData.type !== undefined ) {
  22178. texture.type = texData.type;
  22179. }
  22180. if ( texData.mipmaps !== undefined ) {
  22181. texture.mipmaps = texData.mipmaps;
  22182. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  22183. }
  22184. if ( texData.mipmapCount === 1 ) {
  22185. texture.minFilter = LinearFilter;
  22186. }
  22187. texture.needsUpdate = true;
  22188. if ( onLoad ) onLoad( texture, texData );
  22189. }, onProgress, onError );
  22190. return texture;
  22191. }
  22192. } );
  22193. function TextureLoader( manager ) {
  22194. Loader.call( this, manager );
  22195. }
  22196. TextureLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  22197. constructor: TextureLoader,
  22198. load: function ( url, onLoad, onProgress, onError ) {
  22199. const texture = new Texture();
  22200. const loader = new ImageLoader( this.manager );
  22201. loader.setCrossOrigin( this.crossOrigin );
  22202. loader.setPath( this.path );
  22203. loader.load( url, function ( image ) {
  22204. texture.image = image;
  22205. // JPEGs can't have an alpha channel, so memory can be saved by storing them as RGB.
  22206. const isJPEG = url.search( /\.jpe?g($|\?)/i ) > 0 || url.search( /^data\:image\/jpeg/ ) === 0;
  22207. texture.format = isJPEG ? RGBFormat : RGBAFormat;
  22208. texture.needsUpdate = true;
  22209. if ( onLoad !== undefined ) {
  22210. onLoad( texture );
  22211. }
  22212. }, onProgress, onError );
  22213. return texture;
  22214. }
  22215. } );
  22216. /**
  22217. * Extensible curve object.
  22218. *
  22219. * Some common of curve methods:
  22220. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  22221. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  22222. * .getPoints(), .getSpacedPoints()
  22223. * .getLength()
  22224. * .updateArcLengths()
  22225. *
  22226. * This following curves inherit from THREE.Curve:
  22227. *
  22228. * -- 2D curves --
  22229. * THREE.ArcCurve
  22230. * THREE.CubicBezierCurve
  22231. * THREE.EllipseCurve
  22232. * THREE.LineCurve
  22233. * THREE.QuadraticBezierCurve
  22234. * THREE.SplineCurve
  22235. *
  22236. * -- 3D curves --
  22237. * THREE.CatmullRomCurve3
  22238. * THREE.CubicBezierCurve3
  22239. * THREE.LineCurve3
  22240. * THREE.QuadraticBezierCurve3
  22241. *
  22242. * A series of curves can be represented as a THREE.CurvePath.
  22243. *
  22244. **/
  22245. function Curve() {
  22246. this.type = 'Curve';
  22247. this.arcLengthDivisions = 200;
  22248. }
  22249. Object.assign( Curve.prototype, {
  22250. // Virtual base class method to overwrite and implement in subclasses
  22251. // - t [0 .. 1]
  22252. getPoint: function ( /* t, optionalTarget */ ) {
  22253. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  22254. return null;
  22255. },
  22256. // Get point at relative position in curve according to arc length
  22257. // - u [0 .. 1]
  22258. getPointAt: function ( u, optionalTarget ) {
  22259. const t = this.getUtoTmapping( u );
  22260. return this.getPoint( t, optionalTarget );
  22261. },
  22262. // Get sequence of points using getPoint( t )
  22263. getPoints: function ( divisions = 5 ) {
  22264. const points = [];
  22265. for ( let d = 0; d <= divisions; d ++ ) {
  22266. points.push( this.getPoint( d / divisions ) );
  22267. }
  22268. return points;
  22269. },
  22270. // Get sequence of points using getPointAt( u )
  22271. getSpacedPoints: function ( divisions = 5 ) {
  22272. const points = [];
  22273. for ( let d = 0; d <= divisions; d ++ ) {
  22274. points.push( this.getPointAt( d / divisions ) );
  22275. }
  22276. return points;
  22277. },
  22278. // Get total curve arc length
  22279. getLength: function () {
  22280. const lengths = this.getLengths();
  22281. return lengths[ lengths.length - 1 ];
  22282. },
  22283. // Get list of cumulative segment lengths
  22284. getLengths: function ( divisions ) {
  22285. if ( divisions === undefined ) divisions = this.arcLengthDivisions;
  22286. if ( this.cacheArcLengths &&
  22287. ( this.cacheArcLengths.length === divisions + 1 ) &&
  22288. ! this.needsUpdate ) {
  22289. return this.cacheArcLengths;
  22290. }
  22291. this.needsUpdate = false;
  22292. const cache = [];
  22293. let current, last = this.getPoint( 0 );
  22294. let sum = 0;
  22295. cache.push( 0 );
  22296. for ( let p = 1; p <= divisions; p ++ ) {
  22297. current = this.getPoint( p / divisions );
  22298. sum += current.distanceTo( last );
  22299. cache.push( sum );
  22300. last = current;
  22301. }
  22302. this.cacheArcLengths = cache;
  22303. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  22304. },
  22305. updateArcLengths: function () {
  22306. this.needsUpdate = true;
  22307. this.getLengths();
  22308. },
  22309. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  22310. getUtoTmapping: function ( u, distance ) {
  22311. const arcLengths = this.getLengths();
  22312. let i = 0;
  22313. const il = arcLengths.length;
  22314. let targetArcLength; // The targeted u distance value to get
  22315. if ( distance ) {
  22316. targetArcLength = distance;
  22317. } else {
  22318. targetArcLength = u * arcLengths[ il - 1 ];
  22319. }
  22320. // binary search for the index with largest value smaller than target u distance
  22321. let low = 0, high = il - 1, comparison;
  22322. while ( low <= high ) {
  22323. 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
  22324. comparison = arcLengths[ i ] - targetArcLength;
  22325. if ( comparison < 0 ) {
  22326. low = i + 1;
  22327. } else if ( comparison > 0 ) {
  22328. high = i - 1;
  22329. } else {
  22330. high = i;
  22331. break;
  22332. // DONE
  22333. }
  22334. }
  22335. i = high;
  22336. if ( arcLengths[ i ] === targetArcLength ) {
  22337. return i / ( il - 1 );
  22338. }
  22339. // we could get finer grain at lengths, or use simple interpolation between two points
  22340. const lengthBefore = arcLengths[ i ];
  22341. const lengthAfter = arcLengths[ i + 1 ];
  22342. const segmentLength = lengthAfter - lengthBefore;
  22343. // determine where we are between the 'before' and 'after' points
  22344. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  22345. // add that fractional amount to t
  22346. const t = ( i + segmentFraction ) / ( il - 1 );
  22347. return t;
  22348. },
  22349. // Returns a unit vector tangent at t
  22350. // In case any sub curve does not implement its tangent derivation,
  22351. // 2 points a small delta apart will be used to find its gradient
  22352. // which seems to give a reasonable approximation
  22353. getTangent: function ( t, optionalTarget ) {
  22354. const delta = 0.0001;
  22355. let t1 = t - delta;
  22356. let t2 = t + delta;
  22357. // Capping in case of danger
  22358. if ( t1 < 0 ) t1 = 0;
  22359. if ( t2 > 1 ) t2 = 1;
  22360. const pt1 = this.getPoint( t1 );
  22361. const pt2 = this.getPoint( t2 );
  22362. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  22363. tangent.copy( pt2 ).sub( pt1 ).normalize();
  22364. return tangent;
  22365. },
  22366. getTangentAt: function ( u, optionalTarget ) {
  22367. const t = this.getUtoTmapping( u );
  22368. return this.getTangent( t, optionalTarget );
  22369. },
  22370. computeFrenetFrames: function ( segments, closed ) {
  22371. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22372. const normal = new Vector3();
  22373. const tangents = [];
  22374. const normals = [];
  22375. const binormals = [];
  22376. const vec = new Vector3();
  22377. const mat = new Matrix4();
  22378. // compute the tangent vectors for each segment on the curve
  22379. for ( let i = 0; i <= segments; i ++ ) {
  22380. const u = i / segments;
  22381. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  22382. tangents[ i ].normalize();
  22383. }
  22384. // select an initial normal vector perpendicular to the first tangent vector,
  22385. // and in the direction of the minimum tangent xyz component
  22386. normals[ 0 ] = new Vector3();
  22387. binormals[ 0 ] = new Vector3();
  22388. let min = Number.MAX_VALUE;
  22389. const tx = Math.abs( tangents[ 0 ].x );
  22390. const ty = Math.abs( tangents[ 0 ].y );
  22391. const tz = Math.abs( tangents[ 0 ].z );
  22392. if ( tx <= min ) {
  22393. min = tx;
  22394. normal.set( 1, 0, 0 );
  22395. }
  22396. if ( ty <= min ) {
  22397. min = ty;
  22398. normal.set( 0, 1, 0 );
  22399. }
  22400. if ( tz <= min ) {
  22401. normal.set( 0, 0, 1 );
  22402. }
  22403. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  22404. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  22405. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  22406. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  22407. for ( let i = 1; i <= segments; i ++ ) {
  22408. normals[ i ] = normals[ i - 1 ].clone();
  22409. binormals[ i ] = binormals[ i - 1 ].clone();
  22410. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  22411. if ( vec.length() > Number.EPSILON ) {
  22412. vec.normalize();
  22413. const theta = Math.acos( MathUtils.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  22414. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  22415. }
  22416. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22417. }
  22418. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  22419. if ( closed === true ) {
  22420. let theta = Math.acos( MathUtils.clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  22421. theta /= segments;
  22422. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  22423. theta = - theta;
  22424. }
  22425. for ( let i = 1; i <= segments; i ++ ) {
  22426. // twist a little...
  22427. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  22428. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  22429. }
  22430. }
  22431. return {
  22432. tangents: tangents,
  22433. normals: normals,
  22434. binormals: binormals
  22435. };
  22436. },
  22437. clone: function () {
  22438. return new this.constructor().copy( this );
  22439. },
  22440. copy: function ( source ) {
  22441. this.arcLengthDivisions = source.arcLengthDivisions;
  22442. return this;
  22443. },
  22444. toJSON: function () {
  22445. const data = {
  22446. metadata: {
  22447. version: 4.5,
  22448. type: 'Curve',
  22449. generator: 'Curve.toJSON'
  22450. }
  22451. };
  22452. data.arcLengthDivisions = this.arcLengthDivisions;
  22453. data.type = this.type;
  22454. return data;
  22455. },
  22456. fromJSON: function ( json ) {
  22457. this.arcLengthDivisions = json.arcLengthDivisions;
  22458. return this;
  22459. }
  22460. } );
  22461. function EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  22462. Curve.call( this );
  22463. this.type = 'EllipseCurve';
  22464. this.aX = aX || 0;
  22465. this.aY = aY || 0;
  22466. this.xRadius = xRadius || 1;
  22467. this.yRadius = yRadius || 1;
  22468. this.aStartAngle = aStartAngle || 0;
  22469. this.aEndAngle = aEndAngle || 2 * Math.PI;
  22470. this.aClockwise = aClockwise || false;
  22471. this.aRotation = aRotation || 0;
  22472. }
  22473. EllipseCurve.prototype = Object.create( Curve.prototype );
  22474. EllipseCurve.prototype.constructor = EllipseCurve;
  22475. EllipseCurve.prototype.isEllipseCurve = true;
  22476. EllipseCurve.prototype.getPoint = function ( t, optionalTarget ) {
  22477. const point = optionalTarget || new Vector2();
  22478. const twoPi = Math.PI * 2;
  22479. let deltaAngle = this.aEndAngle - this.aStartAngle;
  22480. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  22481. // ensures that deltaAngle is 0 .. 2 PI
  22482. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  22483. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  22484. if ( deltaAngle < Number.EPSILON ) {
  22485. if ( samePoints ) {
  22486. deltaAngle = 0;
  22487. } else {
  22488. deltaAngle = twoPi;
  22489. }
  22490. }
  22491. if ( this.aClockwise === true && ! samePoints ) {
  22492. if ( deltaAngle === twoPi ) {
  22493. deltaAngle = - twoPi;
  22494. } else {
  22495. deltaAngle = deltaAngle - twoPi;
  22496. }
  22497. }
  22498. const angle = this.aStartAngle + t * deltaAngle;
  22499. let x = this.aX + this.xRadius * Math.cos( angle );
  22500. let y = this.aY + this.yRadius * Math.sin( angle );
  22501. if ( this.aRotation !== 0 ) {
  22502. const cos = Math.cos( this.aRotation );
  22503. const sin = Math.sin( this.aRotation );
  22504. const tx = x - this.aX;
  22505. const ty = y - this.aY;
  22506. // Rotate the point about the center of the ellipse.
  22507. x = tx * cos - ty * sin + this.aX;
  22508. y = tx * sin + ty * cos + this.aY;
  22509. }
  22510. return point.set( x, y );
  22511. };
  22512. EllipseCurve.prototype.copy = function ( source ) {
  22513. Curve.prototype.copy.call( this, source );
  22514. this.aX = source.aX;
  22515. this.aY = source.aY;
  22516. this.xRadius = source.xRadius;
  22517. this.yRadius = source.yRadius;
  22518. this.aStartAngle = source.aStartAngle;
  22519. this.aEndAngle = source.aEndAngle;
  22520. this.aClockwise = source.aClockwise;
  22521. this.aRotation = source.aRotation;
  22522. return this;
  22523. };
  22524. EllipseCurve.prototype.toJSON = function () {
  22525. const data = Curve.prototype.toJSON.call( this );
  22526. data.aX = this.aX;
  22527. data.aY = this.aY;
  22528. data.xRadius = this.xRadius;
  22529. data.yRadius = this.yRadius;
  22530. data.aStartAngle = this.aStartAngle;
  22531. data.aEndAngle = this.aEndAngle;
  22532. data.aClockwise = this.aClockwise;
  22533. data.aRotation = this.aRotation;
  22534. return data;
  22535. };
  22536. EllipseCurve.prototype.fromJSON = function ( json ) {
  22537. Curve.prototype.fromJSON.call( this, json );
  22538. this.aX = json.aX;
  22539. this.aY = json.aY;
  22540. this.xRadius = json.xRadius;
  22541. this.yRadius = json.yRadius;
  22542. this.aStartAngle = json.aStartAngle;
  22543. this.aEndAngle = json.aEndAngle;
  22544. this.aClockwise = json.aClockwise;
  22545. this.aRotation = json.aRotation;
  22546. return this;
  22547. };
  22548. function ArcCurve( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  22549. EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  22550. this.type = 'ArcCurve';
  22551. }
  22552. ArcCurve.prototype = Object.create( EllipseCurve.prototype );
  22553. ArcCurve.prototype.constructor = ArcCurve;
  22554. ArcCurve.prototype.isArcCurve = true;
  22555. /**
  22556. * Centripetal CatmullRom Curve - which is useful for avoiding
  22557. * cusps and self-intersections in non-uniform catmull rom curves.
  22558. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  22559. *
  22560. * curve.type accepts centripetal(default), chordal and catmullrom
  22561. * curve.tension is used for catmullrom which defaults to 0.5
  22562. */
  22563. /*
  22564. Based on an optimized c++ solution in
  22565. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  22566. - http://ideone.com/NoEbVM
  22567. This CubicPoly class could be used for reusing some variables and calculations,
  22568. but for three.js curve use, it could be possible inlined and flatten into a single function call
  22569. which can be placed in CurveUtils.
  22570. */
  22571. function CubicPoly() {
  22572. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  22573. /*
  22574. * Compute coefficients for a cubic polynomial
  22575. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  22576. * such that
  22577. * p(0) = x0, p(1) = x1
  22578. * and
  22579. * p'(0) = t0, p'(1) = t1.
  22580. */
  22581. function init( x0, x1, t0, t1 ) {
  22582. c0 = x0;
  22583. c1 = t0;
  22584. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  22585. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  22586. }
  22587. return {
  22588. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  22589. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  22590. },
  22591. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  22592. // compute tangents when parameterized in [t1,t2]
  22593. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  22594. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  22595. // rescale tangents for parametrization in [0,1]
  22596. t1 *= dt1;
  22597. t2 *= dt1;
  22598. init( x1, x2, t1, t2 );
  22599. },
  22600. calc: function ( t ) {
  22601. const t2 = t * t;
  22602. const t3 = t2 * t;
  22603. return c0 + c1 * t + c2 * t2 + c3 * t3;
  22604. }
  22605. };
  22606. }
  22607. //
  22608. const tmp = new Vector3();
  22609. const px = new CubicPoly(), py = new CubicPoly(), pz = new CubicPoly();
  22610. function CatmullRomCurve3( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  22611. Curve.call( this );
  22612. this.type = 'CatmullRomCurve3';
  22613. this.points = points;
  22614. this.closed = closed;
  22615. this.curveType = curveType;
  22616. this.tension = tension;
  22617. }
  22618. CatmullRomCurve3.prototype = Object.create( Curve.prototype );
  22619. CatmullRomCurve3.prototype.constructor = CatmullRomCurve3;
  22620. CatmullRomCurve3.prototype.isCatmullRomCurve3 = true;
  22621. CatmullRomCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  22622. const point = optionalTarget;
  22623. const points = this.points;
  22624. const l = points.length;
  22625. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  22626. let intPoint = Math.floor( p );
  22627. let weight = p - intPoint;
  22628. if ( this.closed ) {
  22629. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  22630. } else if ( weight === 0 && intPoint === l - 1 ) {
  22631. intPoint = l - 2;
  22632. weight = 1;
  22633. }
  22634. let p0, p3; // 4 points (p1 & p2 defined below)
  22635. if ( this.closed || intPoint > 0 ) {
  22636. p0 = points[ ( intPoint - 1 ) % l ];
  22637. } else {
  22638. // extrapolate first point
  22639. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  22640. p0 = tmp;
  22641. }
  22642. const p1 = points[ intPoint % l ];
  22643. const p2 = points[ ( intPoint + 1 ) % l ];
  22644. if ( this.closed || intPoint + 2 < l ) {
  22645. p3 = points[ ( intPoint + 2 ) % l ];
  22646. } else {
  22647. // extrapolate last point
  22648. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  22649. p3 = tmp;
  22650. }
  22651. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  22652. // init Centripetal / Chordal Catmull-Rom
  22653. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  22654. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  22655. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  22656. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  22657. // safety check for repeated points
  22658. if ( dt1 < 1e-4 ) dt1 = 1.0;
  22659. if ( dt0 < 1e-4 ) dt0 = dt1;
  22660. if ( dt2 < 1e-4 ) dt2 = dt1;
  22661. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  22662. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  22663. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  22664. } else if ( this.curveType === 'catmullrom' ) {
  22665. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  22666. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  22667. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  22668. }
  22669. point.set(
  22670. px.calc( weight ),
  22671. py.calc( weight ),
  22672. pz.calc( weight )
  22673. );
  22674. return point;
  22675. };
  22676. CatmullRomCurve3.prototype.copy = function ( source ) {
  22677. Curve.prototype.copy.call( this, source );
  22678. this.points = [];
  22679. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  22680. const point = source.points[ i ];
  22681. this.points.push( point.clone() );
  22682. }
  22683. this.closed = source.closed;
  22684. this.curveType = source.curveType;
  22685. this.tension = source.tension;
  22686. return this;
  22687. };
  22688. CatmullRomCurve3.prototype.toJSON = function () {
  22689. const data = Curve.prototype.toJSON.call( this );
  22690. data.points = [];
  22691. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  22692. const point = this.points[ i ];
  22693. data.points.push( point.toArray() );
  22694. }
  22695. data.closed = this.closed;
  22696. data.curveType = this.curveType;
  22697. data.tension = this.tension;
  22698. return data;
  22699. };
  22700. CatmullRomCurve3.prototype.fromJSON = function ( json ) {
  22701. Curve.prototype.fromJSON.call( this, json );
  22702. this.points = [];
  22703. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  22704. const point = json.points[ i ];
  22705. this.points.push( new Vector3().fromArray( point ) );
  22706. }
  22707. this.closed = json.closed;
  22708. this.curveType = json.curveType;
  22709. this.tension = json.tension;
  22710. return this;
  22711. };
  22712. /**
  22713. * Bezier Curves formulas obtained from
  22714. * http://en.wikipedia.org/wiki/Bézier_curve
  22715. */
  22716. function CatmullRom( t, p0, p1, p2, p3 ) {
  22717. const v0 = ( p2 - p0 ) * 0.5;
  22718. const v1 = ( p3 - p1 ) * 0.5;
  22719. const t2 = t * t;
  22720. const t3 = t * t2;
  22721. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  22722. }
  22723. //
  22724. function QuadraticBezierP0( t, p ) {
  22725. const k = 1 - t;
  22726. return k * k * p;
  22727. }
  22728. function QuadraticBezierP1( t, p ) {
  22729. return 2 * ( 1 - t ) * t * p;
  22730. }
  22731. function QuadraticBezierP2( t, p ) {
  22732. return t * t * p;
  22733. }
  22734. function QuadraticBezier( t, p0, p1, p2 ) {
  22735. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  22736. QuadraticBezierP2( t, p2 );
  22737. }
  22738. //
  22739. function CubicBezierP0( t, p ) {
  22740. const k = 1 - t;
  22741. return k * k * k * p;
  22742. }
  22743. function CubicBezierP1( t, p ) {
  22744. const k = 1 - t;
  22745. return 3 * k * k * t * p;
  22746. }
  22747. function CubicBezierP2( t, p ) {
  22748. return 3 * ( 1 - t ) * t * t * p;
  22749. }
  22750. function CubicBezierP3( t, p ) {
  22751. return t * t * t * p;
  22752. }
  22753. function CubicBezier( t, p0, p1, p2, p3 ) {
  22754. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  22755. CubicBezierP3( t, p3 );
  22756. }
  22757. function CubicBezierCurve( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  22758. Curve.call( this );
  22759. this.type = 'CubicBezierCurve';
  22760. this.v0 = v0;
  22761. this.v1 = v1;
  22762. this.v2 = v2;
  22763. this.v3 = v3;
  22764. }
  22765. CubicBezierCurve.prototype = Object.create( Curve.prototype );
  22766. CubicBezierCurve.prototype.constructor = CubicBezierCurve;
  22767. CubicBezierCurve.prototype.isCubicBezierCurve = true;
  22768. CubicBezierCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  22769. const point = optionalTarget;
  22770. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22771. point.set(
  22772. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22773. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  22774. );
  22775. return point;
  22776. };
  22777. CubicBezierCurve.prototype.copy = function ( source ) {
  22778. Curve.prototype.copy.call( this, source );
  22779. this.v0.copy( source.v0 );
  22780. this.v1.copy( source.v1 );
  22781. this.v2.copy( source.v2 );
  22782. this.v3.copy( source.v3 );
  22783. return this;
  22784. };
  22785. CubicBezierCurve.prototype.toJSON = function () {
  22786. const data = Curve.prototype.toJSON.call( this );
  22787. data.v0 = this.v0.toArray();
  22788. data.v1 = this.v1.toArray();
  22789. data.v2 = this.v2.toArray();
  22790. data.v3 = this.v3.toArray();
  22791. return data;
  22792. };
  22793. CubicBezierCurve.prototype.fromJSON = function ( json ) {
  22794. Curve.prototype.fromJSON.call( this, json );
  22795. this.v0.fromArray( json.v0 );
  22796. this.v1.fromArray( json.v1 );
  22797. this.v2.fromArray( json.v2 );
  22798. this.v3.fromArray( json.v3 );
  22799. return this;
  22800. };
  22801. function CubicBezierCurve3( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  22802. Curve.call( this );
  22803. this.type = 'CubicBezierCurve3';
  22804. this.v0 = v0;
  22805. this.v1 = v1;
  22806. this.v2 = v2;
  22807. this.v3 = v3;
  22808. }
  22809. CubicBezierCurve3.prototype = Object.create( Curve.prototype );
  22810. CubicBezierCurve3.prototype.constructor = CubicBezierCurve3;
  22811. CubicBezierCurve3.prototype.isCubicBezierCurve3 = true;
  22812. CubicBezierCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  22813. const point = optionalTarget;
  22814. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  22815. point.set(
  22816. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  22817. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  22818. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  22819. );
  22820. return point;
  22821. };
  22822. CubicBezierCurve3.prototype.copy = function ( source ) {
  22823. Curve.prototype.copy.call( this, source );
  22824. this.v0.copy( source.v0 );
  22825. this.v1.copy( source.v1 );
  22826. this.v2.copy( source.v2 );
  22827. this.v3.copy( source.v3 );
  22828. return this;
  22829. };
  22830. CubicBezierCurve3.prototype.toJSON = function () {
  22831. const data = Curve.prototype.toJSON.call( this );
  22832. data.v0 = this.v0.toArray();
  22833. data.v1 = this.v1.toArray();
  22834. data.v2 = this.v2.toArray();
  22835. data.v3 = this.v3.toArray();
  22836. return data;
  22837. };
  22838. CubicBezierCurve3.prototype.fromJSON = function ( json ) {
  22839. Curve.prototype.fromJSON.call( this, json );
  22840. this.v0.fromArray( json.v0 );
  22841. this.v1.fromArray( json.v1 );
  22842. this.v2.fromArray( json.v2 );
  22843. this.v3.fromArray( json.v3 );
  22844. return this;
  22845. };
  22846. function LineCurve( v1 = new Vector2(), v2 = new Vector2() ) {
  22847. Curve.call( this );
  22848. this.type = 'LineCurve';
  22849. this.v1 = v1;
  22850. this.v2 = v2;
  22851. }
  22852. LineCurve.prototype = Object.create( Curve.prototype );
  22853. LineCurve.prototype.constructor = LineCurve;
  22854. LineCurve.prototype.isLineCurve = true;
  22855. LineCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  22856. const point = optionalTarget;
  22857. if ( t === 1 ) {
  22858. point.copy( this.v2 );
  22859. } else {
  22860. point.copy( this.v2 ).sub( this.v1 );
  22861. point.multiplyScalar( t ).add( this.v1 );
  22862. }
  22863. return point;
  22864. };
  22865. // Line curve is linear, so we can overwrite default getPointAt
  22866. LineCurve.prototype.getPointAt = function ( u, optionalTarget ) {
  22867. return this.getPoint( u, optionalTarget );
  22868. };
  22869. LineCurve.prototype.getTangent = function ( t, optionalTarget ) {
  22870. const tangent = optionalTarget || new Vector2();
  22871. tangent.copy( this.v2 ).sub( this.v1 ).normalize();
  22872. return tangent;
  22873. };
  22874. LineCurve.prototype.copy = function ( source ) {
  22875. Curve.prototype.copy.call( this, source );
  22876. this.v1.copy( source.v1 );
  22877. this.v2.copy( source.v2 );
  22878. return this;
  22879. };
  22880. LineCurve.prototype.toJSON = function () {
  22881. const data = Curve.prototype.toJSON.call( this );
  22882. data.v1 = this.v1.toArray();
  22883. data.v2 = this.v2.toArray();
  22884. return data;
  22885. };
  22886. LineCurve.prototype.fromJSON = function ( json ) {
  22887. Curve.prototype.fromJSON.call( this, json );
  22888. this.v1.fromArray( json.v1 );
  22889. this.v2.fromArray( json.v2 );
  22890. return this;
  22891. };
  22892. function LineCurve3( v1 = new Vector3(), v2 = new Vector3() ) {
  22893. Curve.call( this );
  22894. this.type = 'LineCurve3';
  22895. this.v1 = v1;
  22896. this.v2 = v2;
  22897. }
  22898. LineCurve3.prototype = Object.create( Curve.prototype );
  22899. LineCurve3.prototype.constructor = LineCurve3;
  22900. LineCurve3.prototype.isLineCurve3 = true;
  22901. LineCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  22902. const point = optionalTarget;
  22903. if ( t === 1 ) {
  22904. point.copy( this.v2 );
  22905. } else {
  22906. point.copy( this.v2 ).sub( this.v1 );
  22907. point.multiplyScalar( t ).add( this.v1 );
  22908. }
  22909. return point;
  22910. };
  22911. // Line curve is linear, so we can overwrite default getPointAt
  22912. LineCurve3.prototype.getPointAt = function ( u, optionalTarget ) {
  22913. return this.getPoint( u, optionalTarget );
  22914. };
  22915. LineCurve3.prototype.copy = function ( source ) {
  22916. Curve.prototype.copy.call( this, source );
  22917. this.v1.copy( source.v1 );
  22918. this.v2.copy( source.v2 );
  22919. return this;
  22920. };
  22921. LineCurve3.prototype.toJSON = function () {
  22922. const data = Curve.prototype.toJSON.call( this );
  22923. data.v1 = this.v1.toArray();
  22924. data.v2 = this.v2.toArray();
  22925. return data;
  22926. };
  22927. LineCurve3.prototype.fromJSON = function ( json ) {
  22928. Curve.prototype.fromJSON.call( this, json );
  22929. this.v1.fromArray( json.v1 );
  22930. this.v2.fromArray( json.v2 );
  22931. return this;
  22932. };
  22933. function QuadraticBezierCurve( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  22934. Curve.call( this );
  22935. this.type = 'QuadraticBezierCurve';
  22936. this.v0 = v0;
  22937. this.v1 = v1;
  22938. this.v2 = v2;
  22939. }
  22940. QuadraticBezierCurve.prototype = Object.create( Curve.prototype );
  22941. QuadraticBezierCurve.prototype.constructor = QuadraticBezierCurve;
  22942. QuadraticBezierCurve.prototype.isQuadraticBezierCurve = true;
  22943. QuadraticBezierCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  22944. const point = optionalTarget;
  22945. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22946. point.set(
  22947. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22948. QuadraticBezier( t, v0.y, v1.y, v2.y )
  22949. );
  22950. return point;
  22951. };
  22952. QuadraticBezierCurve.prototype.copy = function ( source ) {
  22953. Curve.prototype.copy.call( this, source );
  22954. this.v0.copy( source.v0 );
  22955. this.v1.copy( source.v1 );
  22956. this.v2.copy( source.v2 );
  22957. return this;
  22958. };
  22959. QuadraticBezierCurve.prototype.toJSON = function () {
  22960. const data = Curve.prototype.toJSON.call( this );
  22961. data.v0 = this.v0.toArray();
  22962. data.v1 = this.v1.toArray();
  22963. data.v2 = this.v2.toArray();
  22964. return data;
  22965. };
  22966. QuadraticBezierCurve.prototype.fromJSON = function ( json ) {
  22967. Curve.prototype.fromJSON.call( this, json );
  22968. this.v0.fromArray( json.v0 );
  22969. this.v1.fromArray( json.v1 );
  22970. this.v2.fromArray( json.v2 );
  22971. return this;
  22972. };
  22973. function QuadraticBezierCurve3( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  22974. Curve.call( this );
  22975. this.type = 'QuadraticBezierCurve3';
  22976. this.v0 = v0;
  22977. this.v1 = v1;
  22978. this.v2 = v2;
  22979. }
  22980. QuadraticBezierCurve3.prototype = Object.create( Curve.prototype );
  22981. QuadraticBezierCurve3.prototype.constructor = QuadraticBezierCurve3;
  22982. QuadraticBezierCurve3.prototype.isQuadraticBezierCurve3 = true;
  22983. QuadraticBezierCurve3.prototype.getPoint = function ( t, optionalTarget = new Vector3() ) {
  22984. const point = optionalTarget;
  22985. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  22986. point.set(
  22987. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  22988. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  22989. QuadraticBezier( t, v0.z, v1.z, v2.z )
  22990. );
  22991. return point;
  22992. };
  22993. QuadraticBezierCurve3.prototype.copy = function ( source ) {
  22994. Curve.prototype.copy.call( this, source );
  22995. this.v0.copy( source.v0 );
  22996. this.v1.copy( source.v1 );
  22997. this.v2.copy( source.v2 );
  22998. return this;
  22999. };
  23000. QuadraticBezierCurve3.prototype.toJSON = function () {
  23001. const data = Curve.prototype.toJSON.call( this );
  23002. data.v0 = this.v0.toArray();
  23003. data.v1 = this.v1.toArray();
  23004. data.v2 = this.v2.toArray();
  23005. return data;
  23006. };
  23007. QuadraticBezierCurve3.prototype.fromJSON = function ( json ) {
  23008. Curve.prototype.fromJSON.call( this, json );
  23009. this.v0.fromArray( json.v0 );
  23010. this.v1.fromArray( json.v1 );
  23011. this.v2.fromArray( json.v2 );
  23012. return this;
  23013. };
  23014. function SplineCurve( points = [] ) {
  23015. Curve.call( this );
  23016. this.type = 'SplineCurve';
  23017. this.points = points;
  23018. }
  23019. SplineCurve.prototype = Object.create( Curve.prototype );
  23020. SplineCurve.prototype.constructor = SplineCurve;
  23021. SplineCurve.prototype.isSplineCurve = true;
  23022. SplineCurve.prototype.getPoint = function ( t, optionalTarget = new Vector2() ) {
  23023. const point = optionalTarget;
  23024. const points = this.points;
  23025. const p = ( points.length - 1 ) * t;
  23026. const intPoint = Math.floor( p );
  23027. const weight = p - intPoint;
  23028. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  23029. const p1 = points[ intPoint ];
  23030. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  23031. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  23032. point.set(
  23033. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  23034. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  23035. );
  23036. return point;
  23037. };
  23038. SplineCurve.prototype.copy = function ( source ) {
  23039. Curve.prototype.copy.call( this, source );
  23040. this.points = [];
  23041. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  23042. const point = source.points[ i ];
  23043. this.points.push( point.clone() );
  23044. }
  23045. return this;
  23046. };
  23047. SplineCurve.prototype.toJSON = function () {
  23048. const data = Curve.prototype.toJSON.call( this );
  23049. data.points = [];
  23050. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  23051. const point = this.points[ i ];
  23052. data.points.push( point.toArray() );
  23053. }
  23054. return data;
  23055. };
  23056. SplineCurve.prototype.fromJSON = function ( json ) {
  23057. Curve.prototype.fromJSON.call( this, json );
  23058. this.points = [];
  23059. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  23060. const point = json.points[ i ];
  23061. this.points.push( new Vector2().fromArray( point ) );
  23062. }
  23063. return this;
  23064. };
  23065. var Curves = /*#__PURE__*/Object.freeze({
  23066. __proto__: null,
  23067. ArcCurve: ArcCurve,
  23068. CatmullRomCurve3: CatmullRomCurve3,
  23069. CubicBezierCurve: CubicBezierCurve,
  23070. CubicBezierCurve3: CubicBezierCurve3,
  23071. EllipseCurve: EllipseCurve,
  23072. LineCurve: LineCurve,
  23073. LineCurve3: LineCurve3,
  23074. QuadraticBezierCurve: QuadraticBezierCurve,
  23075. QuadraticBezierCurve3: QuadraticBezierCurve3,
  23076. SplineCurve: SplineCurve
  23077. });
  23078. /**************************************************************
  23079. * Curved Path - a curve path is simply a array of connected
  23080. * curves, but retains the api of a curve
  23081. **************************************************************/
  23082. function CurvePath() {
  23083. Curve.call( this );
  23084. this.type = 'CurvePath';
  23085. this.curves = [];
  23086. this.autoClose = false; // Automatically closes the path
  23087. }
  23088. CurvePath.prototype = Object.assign( Object.create( Curve.prototype ), {
  23089. constructor: CurvePath,
  23090. add: function ( curve ) {
  23091. this.curves.push( curve );
  23092. },
  23093. closePath: function () {
  23094. // Add a line curve if start and end of lines are not connected
  23095. const startPoint = this.curves[ 0 ].getPoint( 0 );
  23096. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  23097. if ( ! startPoint.equals( endPoint ) ) {
  23098. this.curves.push( new LineCurve( endPoint, startPoint ) );
  23099. }
  23100. },
  23101. // To get accurate point with reference to
  23102. // entire path distance at time t,
  23103. // following has to be done:
  23104. // 1. Length of each sub path have to be known
  23105. // 2. Locate and identify type of curve
  23106. // 3. Get t for the curve
  23107. // 4. Return curve.getPointAt(t')
  23108. getPoint: function ( t ) {
  23109. const d = t * this.getLength();
  23110. const curveLengths = this.getCurveLengths();
  23111. let i = 0;
  23112. // To think about boundaries points.
  23113. while ( i < curveLengths.length ) {
  23114. if ( curveLengths[ i ] >= d ) {
  23115. const diff = curveLengths[ i ] - d;
  23116. const curve = this.curves[ i ];
  23117. const segmentLength = curve.getLength();
  23118. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  23119. return curve.getPointAt( u );
  23120. }
  23121. i ++;
  23122. }
  23123. return null;
  23124. // loop where sum != 0, sum > d , sum+1 <d
  23125. },
  23126. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  23127. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  23128. // getPoint() depends on getLength
  23129. getLength: function () {
  23130. const lens = this.getCurveLengths();
  23131. return lens[ lens.length - 1 ];
  23132. },
  23133. // cacheLengths must be recalculated.
  23134. updateArcLengths: function () {
  23135. this.needsUpdate = true;
  23136. this.cacheLengths = null;
  23137. this.getCurveLengths();
  23138. },
  23139. // Compute lengths and cache them
  23140. // We cannot overwrite getLengths() because UtoT mapping uses it.
  23141. getCurveLengths: function () {
  23142. // We use cache values if curves and cache array are same length
  23143. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  23144. return this.cacheLengths;
  23145. }
  23146. // Get length of sub-curve
  23147. // Push sums into cached array
  23148. const lengths = [];
  23149. let sums = 0;
  23150. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  23151. sums += this.curves[ i ].getLength();
  23152. lengths.push( sums );
  23153. }
  23154. this.cacheLengths = lengths;
  23155. return lengths;
  23156. },
  23157. getSpacedPoints: function ( divisions = 40 ) {
  23158. const points = [];
  23159. for ( let i = 0; i <= divisions; i ++ ) {
  23160. points.push( this.getPoint( i / divisions ) );
  23161. }
  23162. if ( this.autoClose ) {
  23163. points.push( points[ 0 ] );
  23164. }
  23165. return points;
  23166. },
  23167. getPoints: function ( divisions = 12 ) {
  23168. const points = [];
  23169. let last;
  23170. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  23171. const curve = curves[ i ];
  23172. const resolution = ( curve && curve.isEllipseCurve ) ? divisions * 2
  23173. : ( curve && ( curve.isLineCurve || curve.isLineCurve3 ) ) ? 1
  23174. : ( curve && curve.isSplineCurve ) ? divisions * curve.points.length
  23175. : divisions;
  23176. const pts = curve.getPoints( resolution );
  23177. for ( let j = 0; j < pts.length; j ++ ) {
  23178. const point = pts[ j ];
  23179. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  23180. points.push( point );
  23181. last = point;
  23182. }
  23183. }
  23184. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  23185. points.push( points[ 0 ] );
  23186. }
  23187. return points;
  23188. },
  23189. copy: function ( source ) {
  23190. Curve.prototype.copy.call( this, source );
  23191. this.curves = [];
  23192. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  23193. const curve = source.curves[ i ];
  23194. this.curves.push( curve.clone() );
  23195. }
  23196. this.autoClose = source.autoClose;
  23197. return this;
  23198. },
  23199. toJSON: function () {
  23200. const data = Curve.prototype.toJSON.call( this );
  23201. data.autoClose = this.autoClose;
  23202. data.curves = [];
  23203. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  23204. const curve = this.curves[ i ];
  23205. data.curves.push( curve.toJSON() );
  23206. }
  23207. return data;
  23208. },
  23209. fromJSON: function ( json ) {
  23210. Curve.prototype.fromJSON.call( this, json );
  23211. this.autoClose = json.autoClose;
  23212. this.curves = [];
  23213. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  23214. const curve = json.curves[ i ];
  23215. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  23216. }
  23217. return this;
  23218. }
  23219. } );
  23220. function Path( points ) {
  23221. CurvePath.call( this );
  23222. this.type = 'Path';
  23223. this.currentPoint = new Vector2();
  23224. if ( points ) {
  23225. this.setFromPoints( points );
  23226. }
  23227. }
  23228. Path.prototype = Object.assign( Object.create( CurvePath.prototype ), {
  23229. constructor: Path,
  23230. setFromPoints: function ( points ) {
  23231. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  23232. for ( let i = 1, l = points.length; i < l; i ++ ) {
  23233. this.lineTo( points[ i ].x, points[ i ].y );
  23234. }
  23235. return this;
  23236. },
  23237. moveTo: function ( x, y ) {
  23238. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  23239. return this;
  23240. },
  23241. lineTo: function ( x, y ) {
  23242. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  23243. this.curves.push( curve );
  23244. this.currentPoint.set( x, y );
  23245. return this;
  23246. },
  23247. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  23248. const curve = new QuadraticBezierCurve(
  23249. this.currentPoint.clone(),
  23250. new Vector2( aCPx, aCPy ),
  23251. new Vector2( aX, aY )
  23252. );
  23253. this.curves.push( curve );
  23254. this.currentPoint.set( aX, aY );
  23255. return this;
  23256. },
  23257. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  23258. const curve = new CubicBezierCurve(
  23259. this.currentPoint.clone(),
  23260. new Vector2( aCP1x, aCP1y ),
  23261. new Vector2( aCP2x, aCP2y ),
  23262. new Vector2( aX, aY )
  23263. );
  23264. this.curves.push( curve );
  23265. this.currentPoint.set( aX, aY );
  23266. return this;
  23267. },
  23268. splineThru: function ( pts /*Array of Vector*/ ) {
  23269. const npts = [ this.currentPoint.clone() ].concat( pts );
  23270. const curve = new SplineCurve( npts );
  23271. this.curves.push( curve );
  23272. this.currentPoint.copy( pts[ pts.length - 1 ] );
  23273. return this;
  23274. },
  23275. arc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23276. const x0 = this.currentPoint.x;
  23277. const y0 = this.currentPoint.y;
  23278. this.absarc( aX + x0, aY + y0, aRadius,
  23279. aStartAngle, aEndAngle, aClockwise );
  23280. return this;
  23281. },
  23282. absarc: function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  23283. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  23284. return this;
  23285. },
  23286. ellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23287. const x0 = this.currentPoint.x;
  23288. const y0 = this.currentPoint.y;
  23289. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23290. return this;
  23291. },
  23292. absellipse: function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  23293. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  23294. if ( this.curves.length > 0 ) {
  23295. // if a previous curve is present, attempt to join
  23296. const firstPoint = curve.getPoint( 0 );
  23297. if ( ! firstPoint.equals( this.currentPoint ) ) {
  23298. this.lineTo( firstPoint.x, firstPoint.y );
  23299. }
  23300. }
  23301. this.curves.push( curve );
  23302. const lastPoint = curve.getPoint( 1 );
  23303. this.currentPoint.copy( lastPoint );
  23304. return this;
  23305. },
  23306. copy: function ( source ) {
  23307. CurvePath.prototype.copy.call( this, source );
  23308. this.currentPoint.copy( source.currentPoint );
  23309. return this;
  23310. },
  23311. toJSON: function () {
  23312. const data = CurvePath.prototype.toJSON.call( this );
  23313. data.currentPoint = this.currentPoint.toArray();
  23314. return data;
  23315. },
  23316. fromJSON: function ( json ) {
  23317. CurvePath.prototype.fromJSON.call( this, json );
  23318. this.currentPoint.fromArray( json.currentPoint );
  23319. return this;
  23320. }
  23321. } );
  23322. function Shape( points ) {
  23323. Path.call( this, points );
  23324. this.uuid = MathUtils.generateUUID();
  23325. this.type = 'Shape';
  23326. this.holes = [];
  23327. }
  23328. Shape.prototype = Object.assign( Object.create( Path.prototype ), {
  23329. constructor: Shape,
  23330. getPointsHoles: function ( divisions ) {
  23331. const holesPts = [];
  23332. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  23333. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  23334. }
  23335. return holesPts;
  23336. },
  23337. // get points of shape and holes (keypoints based on segments parameter)
  23338. extractPoints: function ( divisions ) {
  23339. return {
  23340. shape: this.getPoints( divisions ),
  23341. holes: this.getPointsHoles( divisions )
  23342. };
  23343. },
  23344. copy: function ( source ) {
  23345. Path.prototype.copy.call( this, source );
  23346. this.holes = [];
  23347. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  23348. const hole = source.holes[ i ];
  23349. this.holes.push( hole.clone() );
  23350. }
  23351. return this;
  23352. },
  23353. toJSON: function () {
  23354. const data = Path.prototype.toJSON.call( this );
  23355. data.uuid = this.uuid;
  23356. data.holes = [];
  23357. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  23358. const hole = this.holes[ i ];
  23359. data.holes.push( hole.toJSON() );
  23360. }
  23361. return data;
  23362. },
  23363. fromJSON: function ( json ) {
  23364. Path.prototype.fromJSON.call( this, json );
  23365. this.uuid = json.uuid;
  23366. this.holes = [];
  23367. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  23368. const hole = json.holes[ i ];
  23369. this.holes.push( new Path().fromJSON( hole ) );
  23370. }
  23371. return this;
  23372. }
  23373. } );
  23374. function Light( color, intensity = 1 ) {
  23375. Object3D.call( this );
  23376. this.type = 'Light';
  23377. this.color = new Color( color );
  23378. this.intensity = intensity;
  23379. }
  23380. Light.prototype = Object.assign( Object.create( Object3D.prototype ), {
  23381. constructor: Light,
  23382. isLight: true,
  23383. copy: function ( source ) {
  23384. Object3D.prototype.copy.call( this, source );
  23385. this.color.copy( source.color );
  23386. this.intensity = source.intensity;
  23387. return this;
  23388. },
  23389. toJSON: function ( meta ) {
  23390. const data = Object3D.prototype.toJSON.call( this, meta );
  23391. data.object.color = this.color.getHex();
  23392. data.object.intensity = this.intensity;
  23393. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  23394. if ( this.distance !== undefined ) data.object.distance = this.distance;
  23395. if ( this.angle !== undefined ) data.object.angle = this.angle;
  23396. if ( this.decay !== undefined ) data.object.decay = this.decay;
  23397. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  23398. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  23399. return data;
  23400. }
  23401. } );
  23402. function HemisphereLight( skyColor, groundColor, intensity ) {
  23403. Light.call( this, skyColor, intensity );
  23404. this.type = 'HemisphereLight';
  23405. this.position.copy( Object3D.DefaultUp );
  23406. this.updateMatrix();
  23407. this.groundColor = new Color( groundColor );
  23408. }
  23409. HemisphereLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23410. constructor: HemisphereLight,
  23411. isHemisphereLight: true,
  23412. copy: function ( source ) {
  23413. Light.prototype.copy.call( this, source );
  23414. this.groundColor.copy( source.groundColor );
  23415. return this;
  23416. }
  23417. } );
  23418. function LightShadow( camera ) {
  23419. this.camera = camera;
  23420. this.bias = 0;
  23421. this.normalBias = 0;
  23422. this.radius = 1;
  23423. this.mapSize = new Vector2( 512, 512 );
  23424. this.map = null;
  23425. this.mapPass = null;
  23426. this.matrix = new Matrix4();
  23427. this.autoUpdate = true;
  23428. this.needsUpdate = false;
  23429. this._frustum = new Frustum();
  23430. this._frameExtents = new Vector2( 1, 1 );
  23431. this._viewportCount = 1;
  23432. this._viewports = [
  23433. new Vector4( 0, 0, 1, 1 )
  23434. ];
  23435. }
  23436. Object.assign( LightShadow.prototype, {
  23437. _projScreenMatrix: new Matrix4(),
  23438. _lightPositionWorld: new Vector3(),
  23439. _lookTarget: new Vector3(),
  23440. getViewportCount: function () {
  23441. return this._viewportCount;
  23442. },
  23443. getFrustum: function () {
  23444. return this._frustum;
  23445. },
  23446. updateMatrices: function ( light ) {
  23447. const shadowCamera = this.camera,
  23448. shadowMatrix = this.matrix,
  23449. projScreenMatrix = this._projScreenMatrix,
  23450. lookTarget = this._lookTarget,
  23451. lightPositionWorld = this._lightPositionWorld;
  23452. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23453. shadowCamera.position.copy( lightPositionWorld );
  23454. lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  23455. shadowCamera.lookAt( lookTarget );
  23456. shadowCamera.updateMatrixWorld();
  23457. projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  23458. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23459. shadowMatrix.set(
  23460. 0.5, 0.0, 0.0, 0.5,
  23461. 0.0, 0.5, 0.0, 0.5,
  23462. 0.0, 0.0, 0.5, 0.5,
  23463. 0.0, 0.0, 0.0, 1.0
  23464. );
  23465. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  23466. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  23467. },
  23468. getViewport: function ( viewportIndex ) {
  23469. return this._viewports[ viewportIndex ];
  23470. },
  23471. getFrameExtents: function () {
  23472. return this._frameExtents;
  23473. },
  23474. copy: function ( source ) {
  23475. this.camera = source.camera.clone();
  23476. this.bias = source.bias;
  23477. this.radius = source.radius;
  23478. this.mapSize.copy( source.mapSize );
  23479. return this;
  23480. },
  23481. clone: function () {
  23482. return new this.constructor().copy( this );
  23483. },
  23484. toJSON: function () {
  23485. const object = {};
  23486. if ( this.bias !== 0 ) object.bias = this.bias;
  23487. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  23488. if ( this.radius !== 1 ) object.radius = this.radius;
  23489. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  23490. object.camera = this.camera.toJSON( false ).object;
  23491. delete object.camera.matrix;
  23492. return object;
  23493. }
  23494. } );
  23495. function SpotLightShadow() {
  23496. LightShadow.call( this, new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  23497. this.focus = 1;
  23498. }
  23499. SpotLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23500. constructor: SpotLightShadow,
  23501. isSpotLightShadow: true,
  23502. updateMatrices: function ( light ) {
  23503. const camera = this.camera;
  23504. const fov = MathUtils.RAD2DEG * 2 * light.angle * this.focus;
  23505. const aspect = this.mapSize.width / this.mapSize.height;
  23506. const far = light.distance || camera.far;
  23507. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  23508. camera.fov = fov;
  23509. camera.aspect = aspect;
  23510. camera.far = far;
  23511. camera.updateProjectionMatrix();
  23512. }
  23513. LightShadow.prototype.updateMatrices.call( this, light );
  23514. }
  23515. } );
  23516. function SpotLight( color, intensity, distance, angle, penumbra, decay ) {
  23517. Light.call( this, color, intensity );
  23518. this.type = 'SpotLight';
  23519. this.position.copy( Object3D.DefaultUp );
  23520. this.updateMatrix();
  23521. this.target = new Object3D();
  23522. Object.defineProperty( this, 'power', {
  23523. get: function () {
  23524. // intensity = power per solid angle.
  23525. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23526. return this.intensity * Math.PI;
  23527. },
  23528. set: function ( power ) {
  23529. // intensity = power per solid angle.
  23530. // ref: equation (17) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23531. this.intensity = power / Math.PI;
  23532. }
  23533. } );
  23534. this.distance = ( distance !== undefined ) ? distance : 0;
  23535. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  23536. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  23537. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23538. this.shadow = new SpotLightShadow();
  23539. }
  23540. SpotLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23541. constructor: SpotLight,
  23542. isSpotLight: true,
  23543. copy: function ( source ) {
  23544. Light.prototype.copy.call( this, source );
  23545. this.distance = source.distance;
  23546. this.angle = source.angle;
  23547. this.penumbra = source.penumbra;
  23548. this.decay = source.decay;
  23549. this.target = source.target.clone();
  23550. this.shadow = source.shadow.clone();
  23551. return this;
  23552. }
  23553. } );
  23554. function PointLightShadow() {
  23555. LightShadow.call( this, new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  23556. this._frameExtents = new Vector2( 4, 2 );
  23557. this._viewportCount = 6;
  23558. this._viewports = [
  23559. // These viewports map a cube-map onto a 2D texture with the
  23560. // following orientation:
  23561. //
  23562. // xzXZ
  23563. // y Y
  23564. //
  23565. // X - Positive x direction
  23566. // x - Negative x direction
  23567. // Y - Positive y direction
  23568. // y - Negative y direction
  23569. // Z - Positive z direction
  23570. // z - Negative z direction
  23571. // positive X
  23572. new Vector4( 2, 1, 1, 1 ),
  23573. // negative X
  23574. new Vector4( 0, 1, 1, 1 ),
  23575. // positive Z
  23576. new Vector4( 3, 1, 1, 1 ),
  23577. // negative Z
  23578. new Vector4( 1, 1, 1, 1 ),
  23579. // positive Y
  23580. new Vector4( 3, 0, 1, 1 ),
  23581. // negative Y
  23582. new Vector4( 1, 0, 1, 1 )
  23583. ];
  23584. this._cubeDirections = [
  23585. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  23586. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  23587. ];
  23588. this._cubeUps = [
  23589. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  23590. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  23591. ];
  23592. }
  23593. PointLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23594. constructor: PointLightShadow,
  23595. isPointLightShadow: true,
  23596. updateMatrices: function ( light, viewportIndex = 0 ) {
  23597. const camera = this.camera,
  23598. shadowMatrix = this.matrix,
  23599. lightPositionWorld = this._lightPositionWorld,
  23600. lookTarget = this._lookTarget,
  23601. projScreenMatrix = this._projScreenMatrix;
  23602. lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  23603. camera.position.copy( lightPositionWorld );
  23604. lookTarget.copy( camera.position );
  23605. lookTarget.add( this._cubeDirections[ viewportIndex ] );
  23606. camera.up.copy( this._cubeUps[ viewportIndex ] );
  23607. camera.lookAt( lookTarget );
  23608. camera.updateMatrixWorld();
  23609. shadowMatrix.makeTranslation( - lightPositionWorld.x, - lightPositionWorld.y, - lightPositionWorld.z );
  23610. projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  23611. this._frustum.setFromProjectionMatrix( projScreenMatrix );
  23612. }
  23613. } );
  23614. function PointLight( color, intensity, distance, decay ) {
  23615. Light.call( this, color, intensity );
  23616. this.type = 'PointLight';
  23617. Object.defineProperty( this, 'power', {
  23618. get: function () {
  23619. // intensity = power per solid angle.
  23620. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23621. return this.intensity * 4 * Math.PI;
  23622. },
  23623. set: function ( power ) {
  23624. // intensity = power per solid angle.
  23625. // ref: equation (15) from https://seblagarde.files.wordpress.com/2015/07/course_notes_moving_frostbite_to_pbr_v32.pdf
  23626. this.intensity = power / ( 4 * Math.PI );
  23627. }
  23628. } );
  23629. this.distance = ( distance !== undefined ) ? distance : 0;
  23630. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  23631. this.shadow = new PointLightShadow();
  23632. }
  23633. PointLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23634. constructor: PointLight,
  23635. isPointLight: true,
  23636. copy: function ( source ) {
  23637. Light.prototype.copy.call( this, source );
  23638. this.distance = source.distance;
  23639. this.decay = source.decay;
  23640. this.shadow = source.shadow.clone();
  23641. return this;
  23642. }
  23643. } );
  23644. function OrthographicCamera( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  23645. Camera.call( this );
  23646. this.type = 'OrthographicCamera';
  23647. this.zoom = 1;
  23648. this.view = null;
  23649. this.left = left;
  23650. this.right = right;
  23651. this.top = top;
  23652. this.bottom = bottom;
  23653. this.near = near;
  23654. this.far = far;
  23655. this.updateProjectionMatrix();
  23656. }
  23657. OrthographicCamera.prototype = Object.assign( Object.create( Camera.prototype ), {
  23658. constructor: OrthographicCamera,
  23659. isOrthographicCamera: true,
  23660. copy: function ( source, recursive ) {
  23661. Camera.prototype.copy.call( this, source, recursive );
  23662. this.left = source.left;
  23663. this.right = source.right;
  23664. this.top = source.top;
  23665. this.bottom = source.bottom;
  23666. this.near = source.near;
  23667. this.far = source.far;
  23668. this.zoom = source.zoom;
  23669. this.view = source.view === null ? null : Object.assign( {}, source.view );
  23670. return this;
  23671. },
  23672. setViewOffset: function ( fullWidth, fullHeight, x, y, width, height ) {
  23673. if ( this.view === null ) {
  23674. this.view = {
  23675. enabled: true,
  23676. fullWidth: 1,
  23677. fullHeight: 1,
  23678. offsetX: 0,
  23679. offsetY: 0,
  23680. width: 1,
  23681. height: 1
  23682. };
  23683. }
  23684. this.view.enabled = true;
  23685. this.view.fullWidth = fullWidth;
  23686. this.view.fullHeight = fullHeight;
  23687. this.view.offsetX = x;
  23688. this.view.offsetY = y;
  23689. this.view.width = width;
  23690. this.view.height = height;
  23691. this.updateProjectionMatrix();
  23692. },
  23693. clearViewOffset: function () {
  23694. if ( this.view !== null ) {
  23695. this.view.enabled = false;
  23696. }
  23697. this.updateProjectionMatrix();
  23698. },
  23699. updateProjectionMatrix: function () {
  23700. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  23701. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  23702. const cx = ( this.right + this.left ) / 2;
  23703. const cy = ( this.top + this.bottom ) / 2;
  23704. let left = cx - dx;
  23705. let right = cx + dx;
  23706. let top = cy + dy;
  23707. let bottom = cy - dy;
  23708. if ( this.view !== null && this.view.enabled ) {
  23709. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  23710. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  23711. left += scaleW * this.view.offsetX;
  23712. right = left + scaleW * this.view.width;
  23713. top -= scaleH * this.view.offsetY;
  23714. bottom = top - scaleH * this.view.height;
  23715. }
  23716. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far );
  23717. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  23718. },
  23719. toJSON: function ( meta ) {
  23720. const data = Object3D.prototype.toJSON.call( this, meta );
  23721. data.object.zoom = this.zoom;
  23722. data.object.left = this.left;
  23723. data.object.right = this.right;
  23724. data.object.top = this.top;
  23725. data.object.bottom = this.bottom;
  23726. data.object.near = this.near;
  23727. data.object.far = this.far;
  23728. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  23729. return data;
  23730. }
  23731. } );
  23732. function DirectionalLightShadow() {
  23733. LightShadow.call( this, new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  23734. }
  23735. DirectionalLightShadow.prototype = Object.assign( Object.create( LightShadow.prototype ), {
  23736. constructor: DirectionalLightShadow,
  23737. isDirectionalLightShadow: true,
  23738. updateMatrices: function ( light ) {
  23739. LightShadow.prototype.updateMatrices.call( this, light );
  23740. }
  23741. } );
  23742. function DirectionalLight( color, intensity ) {
  23743. Light.call( this, color, intensity );
  23744. this.type = 'DirectionalLight';
  23745. this.position.copy( Object3D.DefaultUp );
  23746. this.updateMatrix();
  23747. this.target = new Object3D();
  23748. this.shadow = new DirectionalLightShadow();
  23749. }
  23750. DirectionalLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23751. constructor: DirectionalLight,
  23752. isDirectionalLight: true,
  23753. copy: function ( source ) {
  23754. Light.prototype.copy.call( this, source );
  23755. this.target = source.target.clone();
  23756. this.shadow = source.shadow.clone();
  23757. return this;
  23758. }
  23759. } );
  23760. function AmbientLight( color, intensity ) {
  23761. Light.call( this, color, intensity );
  23762. this.type = 'AmbientLight';
  23763. }
  23764. AmbientLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23765. constructor: AmbientLight,
  23766. isAmbientLight: true
  23767. } );
  23768. function RectAreaLight( color, intensity, width, height ) {
  23769. Light.call( this, color, intensity );
  23770. this.type = 'RectAreaLight';
  23771. this.width = ( width !== undefined ) ? width : 10;
  23772. this.height = ( height !== undefined ) ? height : 10;
  23773. }
  23774. RectAreaLight.prototype = Object.assign( Object.create( Light.prototype ), {
  23775. constructor: RectAreaLight,
  23776. isRectAreaLight: true,
  23777. copy: function ( source ) {
  23778. Light.prototype.copy.call( this, source );
  23779. this.width = source.width;
  23780. this.height = source.height;
  23781. return this;
  23782. },
  23783. toJSON: function ( meta ) {
  23784. const data = Light.prototype.toJSON.call( this, meta );
  23785. data.object.width = this.width;
  23786. data.object.height = this.height;
  23787. return data;
  23788. }
  23789. } );
  23790. /**
  23791. * Primary reference:
  23792. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23793. *
  23794. * Secondary reference:
  23795. * https://www.ppsloan.org/publications/StupidSH36.pdf
  23796. */
  23797. // 3-band SH defined by 9 coefficients
  23798. class SphericalHarmonics3 {
  23799. constructor() {
  23800. Object.defineProperty( this, 'isSphericalHarmonics3', { value: true } );
  23801. this.coefficients = [];
  23802. for ( let i = 0; i < 9; i ++ ) {
  23803. this.coefficients.push( new Vector3() );
  23804. }
  23805. }
  23806. set( coefficients ) {
  23807. for ( let i = 0; i < 9; i ++ ) {
  23808. this.coefficients[ i ].copy( coefficients[ i ] );
  23809. }
  23810. return this;
  23811. }
  23812. zero() {
  23813. for ( let i = 0; i < 9; i ++ ) {
  23814. this.coefficients[ i ].set( 0, 0, 0 );
  23815. }
  23816. return this;
  23817. }
  23818. // get the radiance in the direction of the normal
  23819. // target is a Vector3
  23820. getAt( normal, target ) {
  23821. // normal is assumed to be unit length
  23822. const x = normal.x, y = normal.y, z = normal.z;
  23823. const coeff = this.coefficients;
  23824. // band 0
  23825. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  23826. // band 1
  23827. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  23828. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  23829. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  23830. // band 2
  23831. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  23832. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  23833. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  23834. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  23835. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  23836. return target;
  23837. }
  23838. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  23839. // target is a Vector3
  23840. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  23841. getIrradianceAt( normal, target ) {
  23842. // normal is assumed to be unit length
  23843. const x = normal.x, y = normal.y, z = normal.z;
  23844. const coeff = this.coefficients;
  23845. // band 0
  23846. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  23847. // band 1
  23848. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  23849. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  23850. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  23851. // band 2
  23852. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  23853. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  23854. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  23855. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  23856. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  23857. return target;
  23858. }
  23859. add( sh ) {
  23860. for ( let i = 0; i < 9; i ++ ) {
  23861. this.coefficients[ i ].add( sh.coefficients[ i ] );
  23862. }
  23863. return this;
  23864. }
  23865. addScaledSH( sh, s ) {
  23866. for ( let i = 0; i < 9; i ++ ) {
  23867. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  23868. }
  23869. return this;
  23870. }
  23871. scale( s ) {
  23872. for ( let i = 0; i < 9; i ++ ) {
  23873. this.coefficients[ i ].multiplyScalar( s );
  23874. }
  23875. return this;
  23876. }
  23877. lerp( sh, alpha ) {
  23878. for ( let i = 0; i < 9; i ++ ) {
  23879. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  23880. }
  23881. return this;
  23882. }
  23883. equals( sh ) {
  23884. for ( let i = 0; i < 9; i ++ ) {
  23885. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  23886. return false;
  23887. }
  23888. }
  23889. return true;
  23890. }
  23891. copy( sh ) {
  23892. return this.set( sh.coefficients );
  23893. }
  23894. clone() {
  23895. return new this.constructor().copy( this );
  23896. }
  23897. fromArray( array, offset = 0 ) {
  23898. const coefficients = this.coefficients;
  23899. for ( let i = 0; i < 9; i ++ ) {
  23900. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  23901. }
  23902. return this;
  23903. }
  23904. toArray( array = [], offset = 0 ) {
  23905. const coefficients = this.coefficients;
  23906. for ( let i = 0; i < 9; i ++ ) {
  23907. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  23908. }
  23909. return array;
  23910. }
  23911. // evaluate the basis functions
  23912. // shBasis is an Array[ 9 ]
  23913. static getBasisAt( normal, shBasis ) {
  23914. // normal is assumed to be unit length
  23915. const x = normal.x, y = normal.y, z = normal.z;
  23916. // band 0
  23917. shBasis[ 0 ] = 0.282095;
  23918. // band 1
  23919. shBasis[ 1 ] = 0.488603 * y;
  23920. shBasis[ 2 ] = 0.488603 * z;
  23921. shBasis[ 3 ] = 0.488603 * x;
  23922. // band 2
  23923. shBasis[ 4 ] = 1.092548 * x * y;
  23924. shBasis[ 5 ] = 1.092548 * y * z;
  23925. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  23926. shBasis[ 7 ] = 1.092548 * x * z;
  23927. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  23928. }
  23929. }
  23930. function LightProbe( sh, intensity ) {
  23931. Light.call( this, undefined, intensity );
  23932. this.type = 'LightProbe';
  23933. this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
  23934. }
  23935. LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
  23936. constructor: LightProbe,
  23937. isLightProbe: true,
  23938. copy: function ( source ) {
  23939. Light.prototype.copy.call( this, source );
  23940. this.sh.copy( source.sh );
  23941. return this;
  23942. },
  23943. fromJSON: function ( json ) {
  23944. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  23945. this.sh.fromArray( json.sh );
  23946. return this;
  23947. },
  23948. toJSON: function ( meta ) {
  23949. const data = Light.prototype.toJSON.call( this, meta );
  23950. data.object.sh = this.sh.toArray();
  23951. return data;
  23952. }
  23953. } );
  23954. function MaterialLoader( manager ) {
  23955. Loader.call( this, manager );
  23956. this.textures = {};
  23957. }
  23958. MaterialLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  23959. constructor: MaterialLoader,
  23960. load: function ( url, onLoad, onProgress, onError ) {
  23961. const scope = this;
  23962. const loader = new FileLoader( scope.manager );
  23963. loader.setPath( scope.path );
  23964. loader.setRequestHeader( scope.requestHeader );
  23965. loader.setWithCredentials( scope.withCredentials );
  23966. loader.load( url, function ( text ) {
  23967. try {
  23968. onLoad( scope.parse( JSON.parse( text ) ) );
  23969. } catch ( e ) {
  23970. if ( onError ) {
  23971. onError( e );
  23972. } else {
  23973. console.error( e );
  23974. }
  23975. scope.manager.itemError( url );
  23976. }
  23977. }, onProgress, onError );
  23978. },
  23979. parse: function ( json ) {
  23980. const textures = this.textures;
  23981. function getTexture( name ) {
  23982. if ( textures[ name ] === undefined ) {
  23983. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  23984. }
  23985. return textures[ name ];
  23986. }
  23987. const material = new Materials[ json.type ]();
  23988. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  23989. if ( json.name !== undefined ) material.name = json.name;
  23990. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  23991. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  23992. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  23993. if ( json.sheen !== undefined ) material.sheen = new Color().setHex( json.sheen );
  23994. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  23995. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  23996. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  23997. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  23998. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  23999. if ( json.fog !== undefined ) material.fog = json.fog;
  24000. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  24001. if ( json.blending !== undefined ) material.blending = json.blending;
  24002. if ( json.combine !== undefined ) material.combine = json.combine;
  24003. if ( json.side !== undefined ) material.side = json.side;
  24004. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  24005. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  24006. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  24007. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  24008. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  24009. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  24010. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  24011. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  24012. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  24013. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  24014. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  24015. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  24016. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  24017. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  24018. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  24019. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  24020. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  24021. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  24022. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  24023. if ( json.linewidth !== 1 ) material.linewidth = json.linewidth;
  24024. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  24025. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  24026. if ( json.scale !== undefined ) material.scale = json.scale;
  24027. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  24028. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  24029. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  24030. if ( json.skinning !== undefined ) material.skinning = json.skinning;
  24031. if ( json.morphTargets !== undefined ) material.morphTargets = json.morphTargets;
  24032. if ( json.morphNormals !== undefined ) material.morphNormals = json.morphNormals;
  24033. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  24034. if ( json.vertexTangents !== undefined ) material.vertexTangents = json.vertexTangents;
  24035. if ( json.visible !== undefined ) material.visible = json.visible;
  24036. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  24037. if ( json.userData !== undefined ) material.userData = json.userData;
  24038. if ( json.vertexColors !== undefined ) {
  24039. if ( typeof json.vertexColors === 'number' ) {
  24040. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  24041. } else {
  24042. material.vertexColors = json.vertexColors;
  24043. }
  24044. }
  24045. // Shader Material
  24046. if ( json.uniforms !== undefined ) {
  24047. for ( const name in json.uniforms ) {
  24048. const uniform = json.uniforms[ name ];
  24049. material.uniforms[ name ] = {};
  24050. switch ( uniform.type ) {
  24051. case 't':
  24052. material.uniforms[ name ].value = getTexture( uniform.value );
  24053. break;
  24054. case 'c':
  24055. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  24056. break;
  24057. case 'v2':
  24058. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  24059. break;
  24060. case 'v3':
  24061. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  24062. break;
  24063. case 'v4':
  24064. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  24065. break;
  24066. case 'm3':
  24067. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  24068. break;
  24069. case 'm4':
  24070. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  24071. break;
  24072. default:
  24073. material.uniforms[ name ].value = uniform.value;
  24074. }
  24075. }
  24076. }
  24077. if ( json.defines !== undefined ) material.defines = json.defines;
  24078. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  24079. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  24080. if ( json.extensions !== undefined ) {
  24081. for ( const key in json.extensions ) {
  24082. material.extensions[ key ] = json.extensions[ key ];
  24083. }
  24084. }
  24085. // Deprecated
  24086. if ( json.shading !== undefined ) material.flatShading = json.shading === 1; // THREE.FlatShading
  24087. // for PointsMaterial
  24088. if ( json.size !== undefined ) material.size = json.size;
  24089. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  24090. // maps
  24091. if ( json.map !== undefined ) material.map = getTexture( json.map );
  24092. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  24093. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  24094. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  24095. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  24096. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  24097. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  24098. if ( json.normalScale !== undefined ) {
  24099. let normalScale = json.normalScale;
  24100. if ( Array.isArray( normalScale ) === false ) {
  24101. // Blender exporter used to export a scalar. See #7459
  24102. normalScale = [ normalScale, normalScale ];
  24103. }
  24104. material.normalScale = new Vector2().fromArray( normalScale );
  24105. }
  24106. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  24107. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  24108. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  24109. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  24110. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  24111. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  24112. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  24113. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  24114. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  24115. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  24116. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  24117. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  24118. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  24119. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  24120. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  24121. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  24122. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  24123. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  24124. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  24125. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  24126. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  24127. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  24128. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  24129. return material;
  24130. },
  24131. setTextures: function ( value ) {
  24132. this.textures = value;
  24133. return this;
  24134. }
  24135. } );
  24136. const LoaderUtils = {
  24137. decodeText: function ( array ) {
  24138. if ( typeof TextDecoder !== 'undefined' ) {
  24139. return new TextDecoder().decode( array );
  24140. }
  24141. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  24142. // throws a "maximum call stack size exceeded" error for large arrays.
  24143. let s = '';
  24144. for ( let i = 0, il = array.length; i < il; i ++ ) {
  24145. // Implicitly assumes little-endian.
  24146. s += String.fromCharCode( array[ i ] );
  24147. }
  24148. try {
  24149. // merges multi-byte utf-8 characters.
  24150. return decodeURIComponent( escape( s ) );
  24151. } catch ( e ) { // see #16358
  24152. return s;
  24153. }
  24154. },
  24155. extractUrlBase: function ( url ) {
  24156. const index = url.lastIndexOf( '/' );
  24157. if ( index === - 1 ) return './';
  24158. return url.substr( 0, index + 1 );
  24159. }
  24160. };
  24161. function InstancedBufferGeometry() {
  24162. BufferGeometry.call( this );
  24163. this.type = 'InstancedBufferGeometry';
  24164. this.instanceCount = Infinity;
  24165. }
  24166. InstancedBufferGeometry.prototype = Object.assign( Object.create( BufferGeometry.prototype ), {
  24167. constructor: InstancedBufferGeometry,
  24168. isInstancedBufferGeometry: true,
  24169. copy: function ( source ) {
  24170. BufferGeometry.prototype.copy.call( this, source );
  24171. this.instanceCount = source.instanceCount;
  24172. return this;
  24173. },
  24174. clone: function () {
  24175. return new this.constructor().copy( this );
  24176. },
  24177. toJSON: function () {
  24178. const data = BufferGeometry.prototype.toJSON.call( this );
  24179. data.instanceCount = this.instanceCount;
  24180. data.isInstancedBufferGeometry = true;
  24181. return data;
  24182. }
  24183. } );
  24184. function InstancedBufferAttribute( array, itemSize, normalized, meshPerAttribute ) {
  24185. if ( typeof ( normalized ) === 'number' ) {
  24186. meshPerAttribute = normalized;
  24187. normalized = false;
  24188. console.error( 'THREE.InstancedBufferAttribute: The constructor now expects normalized as the third argument.' );
  24189. }
  24190. BufferAttribute.call( this, array, itemSize, normalized );
  24191. this.meshPerAttribute = meshPerAttribute || 1;
  24192. }
  24193. InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribute.prototype ), {
  24194. constructor: InstancedBufferAttribute,
  24195. isInstancedBufferAttribute: true,
  24196. copy: function ( source ) {
  24197. BufferAttribute.prototype.copy.call( this, source );
  24198. this.meshPerAttribute = source.meshPerAttribute;
  24199. return this;
  24200. },
  24201. toJSON: function () {
  24202. const data = BufferAttribute.prototype.toJSON.call( this );
  24203. data.meshPerAttribute = this.meshPerAttribute;
  24204. data.isInstancedBufferAttribute = true;
  24205. return data;
  24206. }
  24207. } );
  24208. function BufferGeometryLoader( manager ) {
  24209. Loader.call( this, manager );
  24210. }
  24211. BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24212. constructor: BufferGeometryLoader,
  24213. load: function ( url, onLoad, onProgress, onError ) {
  24214. const scope = this;
  24215. const loader = new FileLoader( scope.manager );
  24216. loader.setPath( scope.path );
  24217. loader.setRequestHeader( scope.requestHeader );
  24218. loader.setWithCredentials( scope.withCredentials );
  24219. loader.load( url, function ( text ) {
  24220. try {
  24221. onLoad( scope.parse( JSON.parse( text ) ) );
  24222. } catch ( e ) {
  24223. if ( onError ) {
  24224. onError( e );
  24225. } else {
  24226. console.error( e );
  24227. }
  24228. scope.manager.itemError( url );
  24229. }
  24230. }, onProgress, onError );
  24231. },
  24232. parse: function ( json ) {
  24233. const interleavedBufferMap = {};
  24234. const arrayBufferMap = {};
  24235. function getInterleavedBuffer( json, uuid ) {
  24236. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  24237. const interleavedBuffers = json.interleavedBuffers;
  24238. const interleavedBuffer = interleavedBuffers[ uuid ];
  24239. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  24240. const array = getTypedArray( interleavedBuffer.type, buffer );
  24241. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  24242. ib.uuid = interleavedBuffer.uuid;
  24243. interleavedBufferMap[ uuid ] = ib;
  24244. return ib;
  24245. }
  24246. function getArrayBuffer( json, uuid ) {
  24247. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  24248. const arrayBuffers = json.arrayBuffers;
  24249. const arrayBuffer = arrayBuffers[ uuid ];
  24250. const ab = new Uint32Array( arrayBuffer ).buffer;
  24251. arrayBufferMap[ uuid ] = ab;
  24252. return ab;
  24253. }
  24254. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  24255. const index = json.data.index;
  24256. if ( index !== undefined ) {
  24257. const typedArray = getTypedArray( index.type, index.array );
  24258. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  24259. }
  24260. const attributes = json.data.attributes;
  24261. for ( const key in attributes ) {
  24262. const attribute = attributes[ key ];
  24263. let bufferAttribute;
  24264. if ( attribute.isInterleavedBufferAttribute ) {
  24265. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24266. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24267. } else {
  24268. const typedArray = getTypedArray( attribute.type, attribute.array );
  24269. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  24270. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  24271. }
  24272. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24273. geometry.setAttribute( key, bufferAttribute );
  24274. }
  24275. const morphAttributes = json.data.morphAttributes;
  24276. if ( morphAttributes ) {
  24277. for ( const key in morphAttributes ) {
  24278. const attributeArray = morphAttributes[ key ];
  24279. const array = [];
  24280. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  24281. const attribute = attributeArray[ i ];
  24282. let bufferAttribute;
  24283. if ( attribute.isInterleavedBufferAttribute ) {
  24284. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  24285. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  24286. } else {
  24287. const typedArray = getTypedArray( attribute.type, attribute.array );
  24288. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  24289. }
  24290. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  24291. array.push( bufferAttribute );
  24292. }
  24293. geometry.morphAttributes[ key ] = array;
  24294. }
  24295. }
  24296. const morphTargetsRelative = json.data.morphTargetsRelative;
  24297. if ( morphTargetsRelative ) {
  24298. geometry.morphTargetsRelative = true;
  24299. }
  24300. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  24301. if ( groups !== undefined ) {
  24302. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  24303. const group = groups[ i ];
  24304. geometry.addGroup( group.start, group.count, group.materialIndex );
  24305. }
  24306. }
  24307. const boundingSphere = json.data.boundingSphere;
  24308. if ( boundingSphere !== undefined ) {
  24309. const center = new Vector3();
  24310. if ( boundingSphere.center !== undefined ) {
  24311. center.fromArray( boundingSphere.center );
  24312. }
  24313. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  24314. }
  24315. if ( json.name ) geometry.name = json.name;
  24316. if ( json.userData ) geometry.userData = json.userData;
  24317. return geometry;
  24318. }
  24319. } );
  24320. class ObjectLoader extends Loader {
  24321. constructor( manager ) {
  24322. super( manager );
  24323. }
  24324. load( url, onLoad, onProgress, onError ) {
  24325. const scope = this;
  24326. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  24327. this.resourcePath = this.resourcePath || path;
  24328. const loader = new FileLoader( this.manager );
  24329. loader.setPath( this.path );
  24330. loader.setRequestHeader( this.requestHeader );
  24331. loader.setWithCredentials( this.withCredentials );
  24332. loader.load( url, function ( text ) {
  24333. let json = null;
  24334. try {
  24335. json = JSON.parse( text );
  24336. } catch ( error ) {
  24337. if ( onError !== undefined ) onError( error );
  24338. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  24339. return;
  24340. }
  24341. const metadata = json.metadata;
  24342. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  24343. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  24344. return;
  24345. }
  24346. scope.parse( json, onLoad );
  24347. }, onProgress, onError );
  24348. }
  24349. parse( json, onLoad ) {
  24350. const animations = this.parseAnimations( json.animations );
  24351. const shapes = this.parseShapes( json.shapes );
  24352. const geometries = this.parseGeometries( json.geometries, shapes );
  24353. const images = this.parseImages( json.images, function () {
  24354. if ( onLoad !== undefined ) onLoad( object );
  24355. } );
  24356. const textures = this.parseTextures( json.textures, images );
  24357. const materials = this.parseMaterials( json.materials, textures );
  24358. const object = this.parseObject( json.object, geometries, materials, animations );
  24359. const skeletons = this.parseSkeletons( json.skeletons, object );
  24360. this.bindSkeletons( object, skeletons );
  24361. //
  24362. if ( onLoad !== undefined ) {
  24363. let hasImages = false;
  24364. for ( const uuid in images ) {
  24365. if ( images[ uuid ] instanceof HTMLImageElement ) {
  24366. hasImages = true;
  24367. break;
  24368. }
  24369. }
  24370. if ( hasImages === false ) onLoad( object );
  24371. }
  24372. return object;
  24373. }
  24374. parseShapes( json ) {
  24375. const shapes = {};
  24376. if ( json !== undefined ) {
  24377. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24378. const shape = new Shape().fromJSON( json[ i ] );
  24379. shapes[ shape.uuid ] = shape;
  24380. }
  24381. }
  24382. return shapes;
  24383. }
  24384. parseSkeletons( json, object ) {
  24385. const skeletons = {};
  24386. const bones = {};
  24387. // generate bone lookup table
  24388. object.traverse( function ( child ) {
  24389. if ( child.isBone ) bones[ child.uuid ] = child;
  24390. } );
  24391. // create skeletons
  24392. if ( json !== undefined ) {
  24393. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24394. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  24395. skeletons[ skeleton.uuid ] = skeleton;
  24396. }
  24397. }
  24398. return skeletons;
  24399. }
  24400. parseGeometries( json, shapes ) {
  24401. const geometries = {};
  24402. let geometryShapes;
  24403. if ( json !== undefined ) {
  24404. const bufferGeometryLoader = new BufferGeometryLoader();
  24405. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24406. let geometry;
  24407. const data = json[ i ];
  24408. switch ( data.type ) {
  24409. case 'PlaneGeometry':
  24410. case 'PlaneBufferGeometry':
  24411. geometry = new Geometries[ data.type ](
  24412. data.width,
  24413. data.height,
  24414. data.widthSegments,
  24415. data.heightSegments
  24416. );
  24417. break;
  24418. case 'BoxGeometry':
  24419. case 'BoxBufferGeometry':
  24420. case 'CubeGeometry': // backwards compatible
  24421. geometry = new Geometries[ data.type ](
  24422. data.width,
  24423. data.height,
  24424. data.depth,
  24425. data.widthSegments,
  24426. data.heightSegments,
  24427. data.depthSegments
  24428. );
  24429. break;
  24430. case 'CircleGeometry':
  24431. case 'CircleBufferGeometry':
  24432. geometry = new Geometries[ data.type ](
  24433. data.radius,
  24434. data.segments,
  24435. data.thetaStart,
  24436. data.thetaLength
  24437. );
  24438. break;
  24439. case 'CylinderGeometry':
  24440. case 'CylinderBufferGeometry':
  24441. geometry = new Geometries[ data.type ](
  24442. data.radiusTop,
  24443. data.radiusBottom,
  24444. data.height,
  24445. data.radialSegments,
  24446. data.heightSegments,
  24447. data.openEnded,
  24448. data.thetaStart,
  24449. data.thetaLength
  24450. );
  24451. break;
  24452. case 'ConeGeometry':
  24453. case 'ConeBufferGeometry':
  24454. geometry = new Geometries[ data.type ](
  24455. data.radius,
  24456. data.height,
  24457. data.radialSegments,
  24458. data.heightSegments,
  24459. data.openEnded,
  24460. data.thetaStart,
  24461. data.thetaLength
  24462. );
  24463. break;
  24464. case 'SphereGeometry':
  24465. case 'SphereBufferGeometry':
  24466. geometry = new Geometries[ data.type ](
  24467. data.radius,
  24468. data.widthSegments,
  24469. data.heightSegments,
  24470. data.phiStart,
  24471. data.phiLength,
  24472. data.thetaStart,
  24473. data.thetaLength
  24474. );
  24475. break;
  24476. case 'DodecahedronGeometry':
  24477. case 'DodecahedronBufferGeometry':
  24478. case 'IcosahedronGeometry':
  24479. case 'IcosahedronBufferGeometry':
  24480. case 'OctahedronGeometry':
  24481. case 'OctahedronBufferGeometry':
  24482. case 'TetrahedronGeometry':
  24483. case 'TetrahedronBufferGeometry':
  24484. geometry = new Geometries[ data.type ](
  24485. data.radius,
  24486. data.detail
  24487. );
  24488. break;
  24489. case 'RingGeometry':
  24490. case 'RingBufferGeometry':
  24491. geometry = new Geometries[ data.type ](
  24492. data.innerRadius,
  24493. data.outerRadius,
  24494. data.thetaSegments,
  24495. data.phiSegments,
  24496. data.thetaStart,
  24497. data.thetaLength
  24498. );
  24499. break;
  24500. case 'TorusGeometry':
  24501. case 'TorusBufferGeometry':
  24502. geometry = new Geometries[ data.type ](
  24503. data.radius,
  24504. data.tube,
  24505. data.radialSegments,
  24506. data.tubularSegments,
  24507. data.arc
  24508. );
  24509. break;
  24510. case 'TorusKnotGeometry':
  24511. case 'TorusKnotBufferGeometry':
  24512. geometry = new Geometries[ data.type ](
  24513. data.radius,
  24514. data.tube,
  24515. data.tubularSegments,
  24516. data.radialSegments,
  24517. data.p,
  24518. data.q
  24519. );
  24520. break;
  24521. case 'TubeGeometry':
  24522. case 'TubeBufferGeometry':
  24523. // This only works for built-in curves (e.g. CatmullRomCurve3).
  24524. // User defined curves or instances of CurvePath will not be deserialized.
  24525. geometry = new Geometries[ data.type ](
  24526. new Curves[ data.path.type ]().fromJSON( data.path ),
  24527. data.tubularSegments,
  24528. data.radius,
  24529. data.radialSegments,
  24530. data.closed
  24531. );
  24532. break;
  24533. case 'LatheGeometry':
  24534. case 'LatheBufferGeometry':
  24535. geometry = new Geometries[ data.type ](
  24536. data.points,
  24537. data.segments,
  24538. data.phiStart,
  24539. data.phiLength
  24540. );
  24541. break;
  24542. case 'PolyhedronGeometry':
  24543. case 'PolyhedronBufferGeometry':
  24544. geometry = new Geometries[ data.type ](
  24545. data.vertices,
  24546. data.indices,
  24547. data.radius,
  24548. data.details
  24549. );
  24550. break;
  24551. case 'ShapeGeometry':
  24552. case 'ShapeBufferGeometry':
  24553. geometryShapes = [];
  24554. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24555. const shape = shapes[ data.shapes[ j ] ];
  24556. geometryShapes.push( shape );
  24557. }
  24558. geometry = new Geometries[ data.type ](
  24559. geometryShapes,
  24560. data.curveSegments
  24561. );
  24562. break;
  24563. case 'ExtrudeGeometry':
  24564. case 'ExtrudeBufferGeometry':
  24565. geometryShapes = [];
  24566. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  24567. const shape = shapes[ data.shapes[ j ] ];
  24568. geometryShapes.push( shape );
  24569. }
  24570. const extrudePath = data.options.extrudePath;
  24571. if ( extrudePath !== undefined ) {
  24572. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  24573. }
  24574. geometry = new Geometries[ data.type ](
  24575. geometryShapes,
  24576. data.options
  24577. );
  24578. break;
  24579. case 'BufferGeometry':
  24580. case 'InstancedBufferGeometry':
  24581. geometry = bufferGeometryLoader.parse( data );
  24582. break;
  24583. case 'Geometry':
  24584. console.error( 'THREE.ObjectLoader: Loading "Geometry" is not supported anymore.' );
  24585. break;
  24586. default:
  24587. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  24588. continue;
  24589. }
  24590. geometry.uuid = data.uuid;
  24591. if ( data.name !== undefined ) geometry.name = data.name;
  24592. if ( geometry.isBufferGeometry === true && data.userData !== undefined ) geometry.userData = data.userData;
  24593. geometries[ data.uuid ] = geometry;
  24594. }
  24595. }
  24596. return geometries;
  24597. }
  24598. parseMaterials( json, textures ) {
  24599. const cache = {}; // MultiMaterial
  24600. const materials = {};
  24601. if ( json !== undefined ) {
  24602. const loader = new MaterialLoader();
  24603. loader.setTextures( textures );
  24604. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24605. const data = json[ i ];
  24606. if ( data.type === 'MultiMaterial' ) {
  24607. // Deprecated
  24608. const array = [];
  24609. for ( let j = 0; j < data.materials.length; j ++ ) {
  24610. const material = data.materials[ j ];
  24611. if ( cache[ material.uuid ] === undefined ) {
  24612. cache[ material.uuid ] = loader.parse( material );
  24613. }
  24614. array.push( cache[ material.uuid ] );
  24615. }
  24616. materials[ data.uuid ] = array;
  24617. } else {
  24618. if ( cache[ data.uuid ] === undefined ) {
  24619. cache[ data.uuid ] = loader.parse( data );
  24620. }
  24621. materials[ data.uuid ] = cache[ data.uuid ];
  24622. }
  24623. }
  24624. }
  24625. return materials;
  24626. }
  24627. parseAnimations( json ) {
  24628. const animations = {};
  24629. if ( json !== undefined ) {
  24630. for ( let i = 0; i < json.length; i ++ ) {
  24631. const data = json[ i ];
  24632. const clip = AnimationClip.parse( data );
  24633. animations[ clip.uuid ] = clip;
  24634. }
  24635. }
  24636. return animations;
  24637. }
  24638. parseImages( json, onLoad ) {
  24639. const scope = this;
  24640. const images = {};
  24641. let loader;
  24642. function loadImage( url ) {
  24643. scope.manager.itemStart( url );
  24644. return loader.load( url, function () {
  24645. scope.manager.itemEnd( url );
  24646. }, undefined, function () {
  24647. scope.manager.itemError( url );
  24648. scope.manager.itemEnd( url );
  24649. } );
  24650. }
  24651. function deserializeImage( image ) {
  24652. if ( typeof image === 'string' ) {
  24653. const url = image;
  24654. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  24655. return loadImage( path );
  24656. } else {
  24657. if ( image.data ) {
  24658. return {
  24659. data: getTypedArray( image.type, image.data ),
  24660. width: image.width,
  24661. height: image.height
  24662. };
  24663. } else {
  24664. return null;
  24665. }
  24666. }
  24667. }
  24668. if ( json !== undefined && json.length > 0 ) {
  24669. const manager = new LoadingManager( onLoad );
  24670. loader = new ImageLoader( manager );
  24671. loader.setCrossOrigin( this.crossOrigin );
  24672. for ( let i = 0, il = json.length; i < il; i ++ ) {
  24673. const image = json[ i ];
  24674. const url = image.url;
  24675. if ( Array.isArray( url ) ) {
  24676. // load array of images e.g CubeTexture
  24677. images[ image.uuid ] = [];
  24678. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  24679. const currentUrl = url[ j ];
  24680. const deserializedImage = deserializeImage( currentUrl );
  24681. if ( deserializedImage !== null ) {
  24682. if ( deserializedImage instanceof HTMLImageElement ) {
  24683. images[ image.uuid ].push( deserializedImage );
  24684. } else {
  24685. // special case: handle array of data textures for cube textures
  24686. images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  24687. }
  24688. }
  24689. }
  24690. } else {
  24691. // load single image
  24692. const deserializedImage = deserializeImage( image.url );
  24693. if ( deserializedImage !== null ) {
  24694. images[ image.uuid ] = deserializedImage;
  24695. }
  24696. }
  24697. }
  24698. }
  24699. return images;
  24700. }
  24701. parseTextures( json, images ) {
  24702. function parseConstant( value, type ) {
  24703. if ( typeof value === 'number' ) return value;
  24704. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  24705. return type[ value ];
  24706. }
  24707. const textures = {};
  24708. if ( json !== undefined ) {
  24709. for ( let i = 0, l = json.length; i < l; i ++ ) {
  24710. const data = json[ i ];
  24711. if ( data.image === undefined ) {
  24712. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  24713. }
  24714. if ( images[ data.image ] === undefined ) {
  24715. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  24716. }
  24717. let texture;
  24718. const image = images[ data.image ];
  24719. if ( Array.isArray( image ) ) {
  24720. texture = new CubeTexture( image );
  24721. if ( image.length === 6 ) texture.needsUpdate = true;
  24722. } else {
  24723. if ( image && image.data ) {
  24724. texture = new DataTexture( image.data, image.width, image.height );
  24725. } else {
  24726. texture = new Texture( image );
  24727. }
  24728. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  24729. }
  24730. texture.uuid = data.uuid;
  24731. if ( data.name !== undefined ) texture.name = data.name;
  24732. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  24733. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  24734. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  24735. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  24736. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  24737. if ( data.wrap !== undefined ) {
  24738. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  24739. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  24740. }
  24741. if ( data.format !== undefined ) texture.format = data.format;
  24742. if ( data.type !== undefined ) texture.type = data.type;
  24743. if ( data.encoding !== undefined ) texture.encoding = data.encoding;
  24744. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  24745. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  24746. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  24747. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  24748. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  24749. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  24750. textures[ data.uuid ] = texture;
  24751. }
  24752. }
  24753. return textures;
  24754. }
  24755. parseObject( data, geometries, materials, animations ) {
  24756. let object;
  24757. function getGeometry( name ) {
  24758. if ( geometries[ name ] === undefined ) {
  24759. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  24760. }
  24761. return geometries[ name ];
  24762. }
  24763. function getMaterial( name ) {
  24764. if ( name === undefined ) return undefined;
  24765. if ( Array.isArray( name ) ) {
  24766. const array = [];
  24767. for ( let i = 0, l = name.length; i < l; i ++ ) {
  24768. const uuid = name[ i ];
  24769. if ( materials[ uuid ] === undefined ) {
  24770. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  24771. }
  24772. array.push( materials[ uuid ] );
  24773. }
  24774. return array;
  24775. }
  24776. if ( materials[ name ] === undefined ) {
  24777. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  24778. }
  24779. return materials[ name ];
  24780. }
  24781. let geometry, material;
  24782. switch ( data.type ) {
  24783. case 'Scene':
  24784. object = new Scene();
  24785. if ( data.background !== undefined ) {
  24786. if ( Number.isInteger( data.background ) ) {
  24787. object.background = new Color( data.background );
  24788. }
  24789. }
  24790. if ( data.fog !== undefined ) {
  24791. if ( data.fog.type === 'Fog' ) {
  24792. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  24793. } else if ( data.fog.type === 'FogExp2' ) {
  24794. object.fog = new FogExp2( data.fog.color, data.fog.density );
  24795. }
  24796. }
  24797. break;
  24798. case 'PerspectiveCamera':
  24799. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  24800. if ( data.focus !== undefined ) object.focus = data.focus;
  24801. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24802. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  24803. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  24804. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24805. break;
  24806. case 'OrthographicCamera':
  24807. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  24808. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  24809. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  24810. break;
  24811. case 'AmbientLight':
  24812. object = new AmbientLight( data.color, data.intensity );
  24813. break;
  24814. case 'DirectionalLight':
  24815. object = new DirectionalLight( data.color, data.intensity );
  24816. break;
  24817. case 'PointLight':
  24818. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  24819. break;
  24820. case 'RectAreaLight':
  24821. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  24822. break;
  24823. case 'SpotLight':
  24824. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  24825. break;
  24826. case 'HemisphereLight':
  24827. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  24828. break;
  24829. case 'LightProbe':
  24830. object = new LightProbe().fromJSON( data );
  24831. break;
  24832. case 'SkinnedMesh':
  24833. geometry = getGeometry( data.geometry );
  24834. material = getMaterial( data.material );
  24835. object = new SkinnedMesh( geometry, material );
  24836. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  24837. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  24838. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  24839. break;
  24840. case 'Mesh':
  24841. geometry = getGeometry( data.geometry );
  24842. material = getMaterial( data.material );
  24843. object = new Mesh( geometry, material );
  24844. break;
  24845. case 'InstancedMesh':
  24846. geometry = getGeometry( data.geometry );
  24847. material = getMaterial( data.material );
  24848. const count = data.count;
  24849. const instanceMatrix = data.instanceMatrix;
  24850. object = new InstancedMesh( geometry, material, count );
  24851. object.instanceMatrix = new BufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  24852. break;
  24853. case 'LOD':
  24854. object = new LOD();
  24855. break;
  24856. case 'Line':
  24857. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  24858. break;
  24859. case 'LineLoop':
  24860. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  24861. break;
  24862. case 'LineSegments':
  24863. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  24864. break;
  24865. case 'PointCloud':
  24866. case 'Points':
  24867. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  24868. break;
  24869. case 'Sprite':
  24870. object = new Sprite$1( getMaterial( data.material ) );
  24871. break;
  24872. case 'Group':
  24873. object = new Group();
  24874. break;
  24875. case 'Bone':
  24876. object = new Bone();
  24877. break;
  24878. default:
  24879. object = new Object3D();
  24880. }
  24881. object.uuid = data.uuid;
  24882. if ( data.name !== undefined ) object.name = data.name;
  24883. if ( data.matrix !== undefined ) {
  24884. object.matrix.fromArray( data.matrix );
  24885. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  24886. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  24887. } else {
  24888. if ( data.position !== undefined ) object.position.fromArray( data.position );
  24889. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  24890. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  24891. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  24892. }
  24893. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  24894. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  24895. if ( data.shadow ) {
  24896. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  24897. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  24898. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  24899. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  24900. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  24901. }
  24902. if ( data.visible !== undefined ) object.visible = data.visible;
  24903. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  24904. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  24905. if ( data.userData !== undefined ) object.userData = data.userData;
  24906. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  24907. if ( data.children !== undefined ) {
  24908. const children = data.children;
  24909. for ( let i = 0; i < children.length; i ++ ) {
  24910. object.add( this.parseObject( children[ i ], geometries, materials, animations ) );
  24911. }
  24912. }
  24913. if ( data.animations !== undefined ) {
  24914. const objectAnimations = data.animations;
  24915. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  24916. const uuid = objectAnimations[ i ];
  24917. object.animations.push( animations[ uuid ] );
  24918. }
  24919. }
  24920. if ( data.type === 'LOD' ) {
  24921. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  24922. const levels = data.levels;
  24923. for ( let l = 0; l < levels.length; l ++ ) {
  24924. const level = levels[ l ];
  24925. const child = object.getObjectByProperty( 'uuid', level.object );
  24926. if ( child !== undefined ) {
  24927. object.addLevel( child, level.distance );
  24928. }
  24929. }
  24930. }
  24931. return object;
  24932. }
  24933. bindSkeletons( object, skeletons ) {
  24934. if ( Object.keys( skeletons ).length === 0 ) return;
  24935. object.traverse( function ( child ) {
  24936. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  24937. const skeleton = skeletons[ child.skeleton ];
  24938. if ( skeleton === undefined ) {
  24939. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  24940. } else {
  24941. child.bind( skeleton, child.bindMatrix );
  24942. }
  24943. }
  24944. } );
  24945. }
  24946. /* DEPRECATED */
  24947. setTexturePath( value ) {
  24948. console.warn( 'THREE.ObjectLoader: .setTexturePath() has been renamed to .setResourcePath().' );
  24949. return this.setResourcePath( value );
  24950. }
  24951. }
  24952. const TEXTURE_MAPPING = {
  24953. UVMapping: UVMapping,
  24954. CubeReflectionMapping: CubeReflectionMapping,
  24955. CubeRefractionMapping: CubeRefractionMapping,
  24956. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  24957. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  24958. CubeUVReflectionMapping: CubeUVReflectionMapping,
  24959. CubeUVRefractionMapping: CubeUVRefractionMapping
  24960. };
  24961. const TEXTURE_WRAPPING = {
  24962. RepeatWrapping: RepeatWrapping,
  24963. ClampToEdgeWrapping: ClampToEdgeWrapping,
  24964. MirroredRepeatWrapping: MirroredRepeatWrapping
  24965. };
  24966. const TEXTURE_FILTER = {
  24967. NearestFilter: NearestFilter,
  24968. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  24969. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  24970. LinearFilter: LinearFilter,
  24971. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  24972. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  24973. };
  24974. function ImageBitmapLoader( manager ) {
  24975. if ( typeof createImageBitmap === 'undefined' ) {
  24976. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  24977. }
  24978. if ( typeof fetch === 'undefined' ) {
  24979. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  24980. }
  24981. Loader.call( this, manager );
  24982. this.options = { premultiplyAlpha: 'none' };
  24983. }
  24984. ImageBitmapLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  24985. constructor: ImageBitmapLoader,
  24986. isImageBitmapLoader: true,
  24987. setOptions: function setOptions( options ) {
  24988. this.options = options;
  24989. return this;
  24990. },
  24991. load: function ( url, onLoad, onProgress, onError ) {
  24992. if ( url === undefined ) url = '';
  24993. if ( this.path !== undefined ) url = this.path + url;
  24994. url = this.manager.resolveURL( url );
  24995. const scope = this;
  24996. const cached = Cache.get( url );
  24997. if ( cached !== undefined ) {
  24998. scope.manager.itemStart( url );
  24999. setTimeout( function () {
  25000. if ( onLoad ) onLoad( cached );
  25001. scope.manager.itemEnd( url );
  25002. }, 0 );
  25003. return cached;
  25004. }
  25005. const fetchOptions = {};
  25006. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  25007. fetch( url, fetchOptions ).then( function ( res ) {
  25008. return res.blob();
  25009. } ).then( function ( blob ) {
  25010. //console.log('getBlob', url )
  25011. return createImageBitmap( blob, scope.options );
  25012. } ).then( function ( imageBitmap ) {
  25013. Cache.add( url, imageBitmap );
  25014. if ( onLoad ) onLoad( imageBitmap );
  25015. scope.manager.itemEnd( url );
  25016. } ).catch( function ( e ) {
  25017. //console.log('error', url, e)
  25018. if ( onError ) onError( e, url );
  25019. scope.manager.itemError( url );
  25020. scope.manager.itemEnd( url );
  25021. } );
  25022. scope.manager.itemStart( url );
  25023. }
  25024. } );
  25025. function ShapePath() {
  25026. this.type = 'ShapePath';
  25027. this.color = new Color();
  25028. this.subPaths = [];
  25029. this.currentPath = null;
  25030. }
  25031. Object.assign( ShapePath.prototype, {
  25032. moveTo: function ( x, y ) {
  25033. this.currentPath = new Path();
  25034. this.subPaths.push( this.currentPath );
  25035. this.currentPath.moveTo( x, y );
  25036. return this;
  25037. },
  25038. lineTo: function ( x, y ) {
  25039. this.currentPath.lineTo( x, y );
  25040. return this;
  25041. },
  25042. quadraticCurveTo: function ( aCPx, aCPy, aX, aY ) {
  25043. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  25044. return this;
  25045. },
  25046. bezierCurveTo: function ( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  25047. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  25048. return this;
  25049. },
  25050. splineThru: function ( pts ) {
  25051. this.currentPath.splineThru( pts );
  25052. return this;
  25053. },
  25054. toShapes: function ( isCCW, noHoles ) {
  25055. function toShapesNoHoles( inSubpaths ) {
  25056. const shapes = [];
  25057. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  25058. const tmpPath = inSubpaths[ i ];
  25059. const tmpShape = new Shape();
  25060. tmpShape.curves = tmpPath.curves;
  25061. shapes.push( tmpShape );
  25062. }
  25063. return shapes;
  25064. }
  25065. function isPointInsidePolygon( inPt, inPolygon ) {
  25066. const polyLen = inPolygon.length;
  25067. // inPt on polygon contour => immediate success or
  25068. // toggling of inside/outside at every single! intersection point of an edge
  25069. // with the horizontal line through inPt, left of inPt
  25070. // not counting lowerY endpoints of edges and whole edges on that line
  25071. let inside = false;
  25072. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  25073. let edgeLowPt = inPolygon[ p ];
  25074. let edgeHighPt = inPolygon[ q ];
  25075. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  25076. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  25077. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  25078. // not parallel
  25079. if ( edgeDy < 0 ) {
  25080. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  25081. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  25082. }
  25083. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  25084. if ( inPt.y === edgeLowPt.y ) {
  25085. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  25086. // continue; // no intersection or edgeLowPt => doesn't count !!!
  25087. } else {
  25088. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  25089. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  25090. if ( perpEdge < 0 ) continue;
  25091. inside = ! inside; // true intersection left of inPt
  25092. }
  25093. } else {
  25094. // parallel or collinear
  25095. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  25096. // edge lies on the same horizontal line as inPt
  25097. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  25098. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  25099. // continue;
  25100. }
  25101. }
  25102. return inside;
  25103. }
  25104. const isClockWise = ShapeUtils.isClockWise;
  25105. const subPaths = this.subPaths;
  25106. if ( subPaths.length === 0 ) return [];
  25107. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  25108. let solid, tmpPath, tmpShape;
  25109. const shapes = [];
  25110. if ( subPaths.length === 1 ) {
  25111. tmpPath = subPaths[ 0 ];
  25112. tmpShape = new Shape();
  25113. tmpShape.curves = tmpPath.curves;
  25114. shapes.push( tmpShape );
  25115. return shapes;
  25116. }
  25117. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  25118. holesFirst = isCCW ? ! holesFirst : holesFirst;
  25119. // console.log("Holes first", holesFirst);
  25120. const betterShapeHoles = [];
  25121. const newShapes = [];
  25122. let newShapeHoles = [];
  25123. let mainIdx = 0;
  25124. let tmpPoints;
  25125. newShapes[ mainIdx ] = undefined;
  25126. newShapeHoles[ mainIdx ] = [];
  25127. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  25128. tmpPath = subPaths[ i ];
  25129. tmpPoints = tmpPath.getPoints();
  25130. solid = isClockWise( tmpPoints );
  25131. solid = isCCW ? ! solid : solid;
  25132. if ( solid ) {
  25133. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  25134. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  25135. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  25136. if ( holesFirst ) mainIdx ++;
  25137. newShapeHoles[ mainIdx ] = [];
  25138. //console.log('cw', i);
  25139. } else {
  25140. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  25141. //console.log('ccw', i);
  25142. }
  25143. }
  25144. // only Holes? -> probably all Shapes with wrong orientation
  25145. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  25146. if ( newShapes.length > 1 ) {
  25147. let ambiguous = false;
  25148. const toChange = [];
  25149. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25150. betterShapeHoles[ sIdx ] = [];
  25151. }
  25152. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  25153. const sho = newShapeHoles[ sIdx ];
  25154. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  25155. const ho = sho[ hIdx ];
  25156. let hole_unassigned = true;
  25157. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  25158. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  25159. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  25160. if ( hole_unassigned ) {
  25161. hole_unassigned = false;
  25162. betterShapeHoles[ s2Idx ].push( ho );
  25163. } else {
  25164. ambiguous = true;
  25165. }
  25166. }
  25167. }
  25168. if ( hole_unassigned ) {
  25169. betterShapeHoles[ sIdx ].push( ho );
  25170. }
  25171. }
  25172. }
  25173. // console.log("ambiguous: ", ambiguous);
  25174. if ( toChange.length > 0 ) {
  25175. // console.log("to change: ", toChange);
  25176. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  25177. }
  25178. }
  25179. let tmpHoles;
  25180. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  25181. tmpShape = newShapes[ i ].s;
  25182. shapes.push( tmpShape );
  25183. tmpHoles = newShapeHoles[ i ];
  25184. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  25185. tmpShape.holes.push( tmpHoles[ j ].h );
  25186. }
  25187. }
  25188. //console.log("shape", shapes);
  25189. return shapes;
  25190. }
  25191. } );
  25192. function Font( data ) {
  25193. this.type = 'Font';
  25194. this.data = data;
  25195. }
  25196. Object.assign( Font.prototype, {
  25197. isFont: true,
  25198. generateShapes: function ( text, size = 100 ) {
  25199. const shapes = [];
  25200. const paths = createPaths( text, size, this.data );
  25201. for ( let p = 0, pl = paths.length; p < pl; p ++ ) {
  25202. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  25203. }
  25204. return shapes;
  25205. }
  25206. } );
  25207. function createPaths( text, size, data ) {
  25208. const chars = Array.from ? Array.from( text ) : String( text ).split( '' ); // workaround for IE11, see #13988
  25209. const scale = size / data.resolution;
  25210. const line_height = ( data.boundingBox.yMax - data.boundingBox.yMin + data.underlineThickness ) * scale;
  25211. const paths = [];
  25212. let offsetX = 0, offsetY = 0;
  25213. for ( let i = 0; i < chars.length; i ++ ) {
  25214. const char = chars[ i ];
  25215. if ( char === '\n' ) {
  25216. offsetX = 0;
  25217. offsetY -= line_height;
  25218. } else {
  25219. const ret = createPath( char, scale, offsetX, offsetY, data );
  25220. offsetX += ret.offsetX;
  25221. paths.push( ret.path );
  25222. }
  25223. }
  25224. return paths;
  25225. }
  25226. function createPath( char, scale, offsetX, offsetY, data ) {
  25227. const glyph = data.glyphs[ char ] || data.glyphs[ '?' ];
  25228. if ( ! glyph ) {
  25229. console.error( 'THREE.Font: character "' + char + '" does not exists in font family ' + data.familyName + '.' );
  25230. return;
  25231. }
  25232. const path = new ShapePath();
  25233. let x, y, cpx, cpy, cpx1, cpy1, cpx2, cpy2;
  25234. if ( glyph.o ) {
  25235. const outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  25236. for ( let i = 0, l = outline.length; i < l; ) {
  25237. const action = outline[ i ++ ];
  25238. switch ( action ) {
  25239. case 'm': // moveTo
  25240. x = outline[ i ++ ] * scale + offsetX;
  25241. y = outline[ i ++ ] * scale + offsetY;
  25242. path.moveTo( x, y );
  25243. break;
  25244. case 'l': // lineTo
  25245. x = outline[ i ++ ] * scale + offsetX;
  25246. y = outline[ i ++ ] * scale + offsetY;
  25247. path.lineTo( x, y );
  25248. break;
  25249. case 'q': // quadraticCurveTo
  25250. cpx = outline[ i ++ ] * scale + offsetX;
  25251. cpy = outline[ i ++ ] * scale + offsetY;
  25252. cpx1 = outline[ i ++ ] * scale + offsetX;
  25253. cpy1 = outline[ i ++ ] * scale + offsetY;
  25254. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  25255. break;
  25256. case 'b': // bezierCurveTo
  25257. cpx = outline[ i ++ ] * scale + offsetX;
  25258. cpy = outline[ i ++ ] * scale + offsetY;
  25259. cpx1 = outline[ i ++ ] * scale + offsetX;
  25260. cpy1 = outline[ i ++ ] * scale + offsetY;
  25261. cpx2 = outline[ i ++ ] * scale + offsetX;
  25262. cpy2 = outline[ i ++ ] * scale + offsetY;
  25263. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  25264. break;
  25265. }
  25266. }
  25267. }
  25268. return { offsetX: glyph.ha * scale, path: path };
  25269. }
  25270. function FontLoader( manager ) {
  25271. Loader.call( this, manager );
  25272. }
  25273. FontLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25274. constructor: FontLoader,
  25275. load: function ( url, onLoad, onProgress, onError ) {
  25276. const scope = this;
  25277. const loader = new FileLoader( this.manager );
  25278. loader.setPath( this.path );
  25279. loader.setRequestHeader( this.requestHeader );
  25280. loader.setWithCredentials( scope.withCredentials );
  25281. loader.load( url, function ( text ) {
  25282. let json;
  25283. try {
  25284. json = JSON.parse( text );
  25285. } catch ( e ) {
  25286. console.warn( 'THREE.FontLoader: typeface.js support is being deprecated. Use typeface.json instead.' );
  25287. json = JSON.parse( text.substring( 65, text.length - 2 ) );
  25288. }
  25289. const font = scope.parse( json );
  25290. if ( onLoad ) onLoad( font );
  25291. }, onProgress, onError );
  25292. },
  25293. parse: function ( json ) {
  25294. return new Font( json );
  25295. }
  25296. } );
  25297. let _context;
  25298. const AudioContext = {
  25299. getContext: function () {
  25300. if ( _context === undefined ) {
  25301. _context = new ( window.AudioContext || window.webkitAudioContext )();
  25302. }
  25303. return _context;
  25304. },
  25305. setContext: function ( value ) {
  25306. _context = value;
  25307. }
  25308. };
  25309. function AudioLoader( manager ) {
  25310. Loader.call( this, manager );
  25311. }
  25312. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  25313. constructor: AudioLoader,
  25314. load: function ( url, onLoad, onProgress, onError ) {
  25315. const scope = this;
  25316. const loader = new FileLoader( scope.manager );
  25317. loader.setResponseType( 'arraybuffer' );
  25318. loader.setPath( scope.path );
  25319. loader.setRequestHeader( scope.requestHeader );
  25320. loader.setWithCredentials( scope.withCredentials );
  25321. loader.load( url, function ( buffer ) {
  25322. try {
  25323. // Create a copy of the buffer. The `decodeAudioData` method
  25324. // detaches the buffer when complete, preventing reuse.
  25325. const bufferCopy = buffer.slice( 0 );
  25326. const context = AudioContext.getContext();
  25327. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  25328. onLoad( audioBuffer );
  25329. } );
  25330. } catch ( e ) {
  25331. if ( onError ) {
  25332. onError( e );
  25333. } else {
  25334. console.error( e );
  25335. }
  25336. scope.manager.itemError( url );
  25337. }
  25338. }, onProgress, onError );
  25339. }
  25340. } );
  25341. function HemisphereLightProbe( skyColor, groundColor, intensity ) {
  25342. LightProbe.call( this, undefined, intensity );
  25343. const color1 = new Color().set( skyColor );
  25344. const color2 = new Color().set( groundColor );
  25345. const sky = new Vector3( color1.r, color1.g, color1.b );
  25346. const ground = new Vector3( color2.r, color2.g, color2.b );
  25347. // without extra factor of PI in the shader, should = 1 / Math.sqrt( Math.PI );
  25348. const c0 = Math.sqrt( Math.PI );
  25349. const c1 = c0 * Math.sqrt( 0.75 );
  25350. this.sh.coefficients[ 0 ].copy( sky ).add( ground ).multiplyScalar( c0 );
  25351. this.sh.coefficients[ 1 ].copy( sky ).sub( ground ).multiplyScalar( c1 );
  25352. }
  25353. HemisphereLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25354. constructor: HemisphereLightProbe,
  25355. isHemisphereLightProbe: true,
  25356. copy: function ( source ) { // modifying colors not currently supported
  25357. LightProbe.prototype.copy.call( this, source );
  25358. return this;
  25359. },
  25360. toJSON: function ( meta ) {
  25361. const data = LightProbe.prototype.toJSON.call( this, meta );
  25362. // data.sh = this.sh.toArray(); // todo
  25363. return data;
  25364. }
  25365. } );
  25366. function AmbientLightProbe( color, intensity ) {
  25367. LightProbe.call( this, undefined, intensity );
  25368. const color1 = new Color().set( color );
  25369. // without extra factor of PI in the shader, would be 2 / Math.sqrt( Math.PI );
  25370. this.sh.coefficients[ 0 ].set( color1.r, color1.g, color1.b ).multiplyScalar( 2 * Math.sqrt( Math.PI ) );
  25371. }
  25372. AmbientLightProbe.prototype = Object.assign( Object.create( LightProbe.prototype ), {
  25373. constructor: AmbientLightProbe,
  25374. isAmbientLightProbe: true,
  25375. copy: function ( source ) { // modifying color not currently supported
  25376. LightProbe.prototype.copy.call( this, source );
  25377. return this;
  25378. },
  25379. toJSON: function ( meta ) {
  25380. const data = LightProbe.prototype.toJSON.call( this, meta );
  25381. // data.sh = this.sh.toArray(); // todo
  25382. return data;
  25383. }
  25384. } );
  25385. const _eyeRight = new Matrix4();
  25386. const _eyeLeft = new Matrix4();
  25387. function StereoCamera() {
  25388. this.type = 'StereoCamera';
  25389. this.aspect = 1;
  25390. this.eyeSep = 0.064;
  25391. this.cameraL = new PerspectiveCamera();
  25392. this.cameraL.layers.enable( 1 );
  25393. this.cameraL.matrixAutoUpdate = false;
  25394. this.cameraR = new PerspectiveCamera();
  25395. this.cameraR.layers.enable( 2 );
  25396. this.cameraR.matrixAutoUpdate = false;
  25397. this._cache = {
  25398. focus: null,
  25399. fov: null,
  25400. aspect: null,
  25401. near: null,
  25402. far: null,
  25403. zoom: null,
  25404. eyeSep: null
  25405. };
  25406. }
  25407. Object.assign( StereoCamera.prototype, {
  25408. update: function ( camera ) {
  25409. const cache = this._cache;
  25410. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  25411. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  25412. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  25413. if ( needsUpdate ) {
  25414. cache.focus = camera.focus;
  25415. cache.fov = camera.fov;
  25416. cache.aspect = camera.aspect * this.aspect;
  25417. cache.near = camera.near;
  25418. cache.far = camera.far;
  25419. cache.zoom = camera.zoom;
  25420. cache.eyeSep = this.eyeSep;
  25421. // Off-axis stereoscopic effect based on
  25422. // http://paulbourke.net/stereographics/stereorender/
  25423. const projectionMatrix = camera.projectionMatrix.clone();
  25424. const eyeSepHalf = cache.eyeSep / 2;
  25425. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  25426. const ymax = ( cache.near * Math.tan( MathUtils.DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  25427. let xmin, xmax;
  25428. // translate xOffset
  25429. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  25430. _eyeRight.elements[ 12 ] = eyeSepHalf;
  25431. // for left eye
  25432. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  25433. xmax = ymax * cache.aspect + eyeSepOnProjection;
  25434. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25435. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25436. this.cameraL.projectionMatrix.copy( projectionMatrix );
  25437. // for right eye
  25438. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  25439. xmax = ymax * cache.aspect - eyeSepOnProjection;
  25440. projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  25441. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  25442. this.cameraR.projectionMatrix.copy( projectionMatrix );
  25443. }
  25444. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  25445. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  25446. }
  25447. } );
  25448. class Clock {
  25449. constructor( autoStart ) {
  25450. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  25451. this.startTime = 0;
  25452. this.oldTime = 0;
  25453. this.elapsedTime = 0;
  25454. this.running = false;
  25455. }
  25456. start() {
  25457. this.startTime = now();
  25458. this.oldTime = this.startTime;
  25459. this.elapsedTime = 0;
  25460. this.running = true;
  25461. }
  25462. stop() {
  25463. this.getElapsedTime();
  25464. this.running = false;
  25465. this.autoStart = false;
  25466. }
  25467. getElapsedTime() {
  25468. this.getDelta();
  25469. return this.elapsedTime;
  25470. }
  25471. getDelta() {
  25472. let diff = 0;
  25473. if ( this.autoStart && ! this.running ) {
  25474. this.start();
  25475. return 0;
  25476. }
  25477. if ( this.running ) {
  25478. const newTime = now();
  25479. diff = ( newTime - this.oldTime ) / 1000;
  25480. this.oldTime = newTime;
  25481. this.elapsedTime += diff;
  25482. }
  25483. return diff;
  25484. }
  25485. }
  25486. function now() {
  25487. return ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
  25488. }
  25489. const _position$2 = /*@__PURE__*/ new Vector3();
  25490. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  25491. const _scale$1 = /*@__PURE__*/ new Vector3();
  25492. const _orientation = /*@__PURE__*/ new Vector3();
  25493. class AudioListener extends Object3D {
  25494. constructor() {
  25495. super();
  25496. this.type = 'AudioListener';
  25497. this.context = AudioContext.getContext();
  25498. this.gain = this.context.createGain();
  25499. this.gain.connect( this.context.destination );
  25500. this.filter = null;
  25501. this.timeDelta = 0;
  25502. // private
  25503. this._clock = new Clock();
  25504. }
  25505. getInput() {
  25506. return this.gain;
  25507. }
  25508. removeFilter() {
  25509. if ( this.filter !== null ) {
  25510. this.gain.disconnect( this.filter );
  25511. this.filter.disconnect( this.context.destination );
  25512. this.gain.connect( this.context.destination );
  25513. this.filter = null;
  25514. }
  25515. return this;
  25516. }
  25517. getFilter() {
  25518. return this.filter;
  25519. }
  25520. setFilter( value ) {
  25521. if ( this.filter !== null ) {
  25522. this.gain.disconnect( this.filter );
  25523. this.filter.disconnect( this.context.destination );
  25524. } else {
  25525. this.gain.disconnect( this.context.destination );
  25526. }
  25527. this.filter = value;
  25528. this.gain.connect( this.filter );
  25529. this.filter.connect( this.context.destination );
  25530. return this;
  25531. }
  25532. getMasterVolume() {
  25533. return this.gain.gain.value;
  25534. }
  25535. setMasterVolume( value ) {
  25536. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25537. return this;
  25538. }
  25539. updateMatrixWorld( force ) {
  25540. super.updateMatrixWorld( force );
  25541. const listener = this.context.listener;
  25542. const up = this.up;
  25543. this.timeDelta = this._clock.getDelta();
  25544. this.matrixWorld.decompose( _position$2, _quaternion$3, _scale$1 );
  25545. _orientation.set( 0, 0, - 1 ).applyQuaternion( _quaternion$3 );
  25546. if ( listener.positionX ) {
  25547. // code path for Chrome (see #14393)
  25548. const endTime = this.context.currentTime + this.timeDelta;
  25549. listener.positionX.linearRampToValueAtTime( _position$2.x, endTime );
  25550. listener.positionY.linearRampToValueAtTime( _position$2.y, endTime );
  25551. listener.positionZ.linearRampToValueAtTime( _position$2.z, endTime );
  25552. listener.forwardX.linearRampToValueAtTime( _orientation.x, endTime );
  25553. listener.forwardY.linearRampToValueAtTime( _orientation.y, endTime );
  25554. listener.forwardZ.linearRampToValueAtTime( _orientation.z, endTime );
  25555. listener.upX.linearRampToValueAtTime( up.x, endTime );
  25556. listener.upY.linearRampToValueAtTime( up.y, endTime );
  25557. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  25558. } else {
  25559. listener.setPosition( _position$2.x, _position$2.y, _position$2.z );
  25560. listener.setOrientation( _orientation.x, _orientation.y, _orientation.z, up.x, up.y, up.z );
  25561. }
  25562. }
  25563. }
  25564. class Audio extends Object3D {
  25565. constructor( listener ) {
  25566. super();
  25567. this.type = 'Audio';
  25568. this.listener = listener;
  25569. this.context = listener.context;
  25570. this.gain = this.context.createGain();
  25571. this.gain.connect( listener.getInput() );
  25572. this.autoplay = false;
  25573. this.buffer = null;
  25574. this.detune = 0;
  25575. this.loop = false;
  25576. this.loopStart = 0;
  25577. this.loopEnd = 0;
  25578. this.offset = 0;
  25579. this.duration = undefined;
  25580. this.playbackRate = 1;
  25581. this.isPlaying = false;
  25582. this.hasPlaybackControl = true;
  25583. this.source = null;
  25584. this.sourceType = 'empty';
  25585. this._startedAt = 0;
  25586. this._progress = 0;
  25587. this._connected = false;
  25588. this.filters = [];
  25589. }
  25590. getOutput() {
  25591. return this.gain;
  25592. }
  25593. setNodeSource( audioNode ) {
  25594. this.hasPlaybackControl = false;
  25595. this.sourceType = 'audioNode';
  25596. this.source = audioNode;
  25597. this.connect();
  25598. return this;
  25599. }
  25600. setMediaElementSource( mediaElement ) {
  25601. this.hasPlaybackControl = false;
  25602. this.sourceType = 'mediaNode';
  25603. this.source = this.context.createMediaElementSource( mediaElement );
  25604. this.connect();
  25605. return this;
  25606. }
  25607. setMediaStreamSource( mediaStream ) {
  25608. this.hasPlaybackControl = false;
  25609. this.sourceType = 'mediaStreamNode';
  25610. this.source = this.context.createMediaStreamSource( mediaStream );
  25611. this.connect();
  25612. return this;
  25613. }
  25614. setBuffer( audioBuffer ) {
  25615. this.buffer = audioBuffer;
  25616. this.sourceType = 'buffer';
  25617. if ( this.autoplay ) this.play();
  25618. return this;
  25619. }
  25620. play( delay = 0 ) {
  25621. if ( this.isPlaying === true ) {
  25622. console.warn( 'THREE.Audio: Audio is already playing.' );
  25623. return;
  25624. }
  25625. if ( this.hasPlaybackControl === false ) {
  25626. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25627. return;
  25628. }
  25629. this._startedAt = this.context.currentTime + delay;
  25630. const source = this.context.createBufferSource();
  25631. source.buffer = this.buffer;
  25632. source.loop = this.loop;
  25633. source.loopStart = this.loopStart;
  25634. source.loopEnd = this.loopEnd;
  25635. source.onended = this.onEnded.bind( this );
  25636. source.start( this._startedAt, this._progress + this.offset, this.duration );
  25637. this.isPlaying = true;
  25638. this.source = source;
  25639. this.setDetune( this.detune );
  25640. this.setPlaybackRate( this.playbackRate );
  25641. return this.connect();
  25642. }
  25643. pause() {
  25644. if ( this.hasPlaybackControl === false ) {
  25645. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25646. return;
  25647. }
  25648. if ( this.isPlaying === true ) {
  25649. // update current progress
  25650. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  25651. if ( this.loop === true ) {
  25652. // ensure _progress does not exceed duration with looped audios
  25653. this._progress = this._progress % ( this.duration || this.buffer.duration );
  25654. }
  25655. this.source.stop();
  25656. this.source.onended = null;
  25657. this.isPlaying = false;
  25658. }
  25659. return this;
  25660. }
  25661. stop() {
  25662. if ( this.hasPlaybackControl === false ) {
  25663. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25664. return;
  25665. }
  25666. this._progress = 0;
  25667. this.source.stop();
  25668. this.source.onended = null;
  25669. this.isPlaying = false;
  25670. return this;
  25671. }
  25672. connect() {
  25673. if ( this.filters.length > 0 ) {
  25674. this.source.connect( this.filters[ 0 ] );
  25675. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  25676. this.filters[ i - 1 ].connect( this.filters[ i ] );
  25677. }
  25678. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  25679. } else {
  25680. this.source.connect( this.getOutput() );
  25681. }
  25682. this._connected = true;
  25683. return this;
  25684. }
  25685. disconnect() {
  25686. if ( this.filters.length > 0 ) {
  25687. this.source.disconnect( this.filters[ 0 ] );
  25688. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  25689. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  25690. }
  25691. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  25692. } else {
  25693. this.source.disconnect( this.getOutput() );
  25694. }
  25695. this._connected = false;
  25696. return this;
  25697. }
  25698. getFilters() {
  25699. return this.filters;
  25700. }
  25701. setFilters( value ) {
  25702. if ( ! value ) value = [];
  25703. if ( this._connected === true ) {
  25704. this.disconnect();
  25705. this.filters = value.slice();
  25706. this.connect();
  25707. } else {
  25708. this.filters = value.slice();
  25709. }
  25710. return this;
  25711. }
  25712. setDetune( value ) {
  25713. this.detune = value;
  25714. if ( this.source.detune === undefined ) return; // only set detune when available
  25715. if ( this.isPlaying === true ) {
  25716. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  25717. }
  25718. return this;
  25719. }
  25720. getDetune() {
  25721. return this.detune;
  25722. }
  25723. getFilter() {
  25724. return this.getFilters()[ 0 ];
  25725. }
  25726. setFilter( filter ) {
  25727. return this.setFilters( filter ? [ filter ] : [] );
  25728. }
  25729. setPlaybackRate( value ) {
  25730. if ( this.hasPlaybackControl === false ) {
  25731. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25732. return;
  25733. }
  25734. this.playbackRate = value;
  25735. if ( this.isPlaying === true ) {
  25736. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  25737. }
  25738. return this;
  25739. }
  25740. getPlaybackRate() {
  25741. return this.playbackRate;
  25742. }
  25743. onEnded() {
  25744. this.isPlaying = false;
  25745. }
  25746. getLoop() {
  25747. if ( this.hasPlaybackControl === false ) {
  25748. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25749. return false;
  25750. }
  25751. return this.loop;
  25752. }
  25753. setLoop( value ) {
  25754. if ( this.hasPlaybackControl === false ) {
  25755. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  25756. return;
  25757. }
  25758. this.loop = value;
  25759. if ( this.isPlaying === true ) {
  25760. this.source.loop = this.loop;
  25761. }
  25762. return this;
  25763. }
  25764. setLoopStart( value ) {
  25765. this.loopStart = value;
  25766. return this;
  25767. }
  25768. setLoopEnd( value ) {
  25769. this.loopEnd = value;
  25770. return this;
  25771. }
  25772. getVolume() {
  25773. return this.gain.gain.value;
  25774. }
  25775. setVolume( value ) {
  25776. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  25777. return this;
  25778. }
  25779. }
  25780. const _position$3 = /*@__PURE__*/ new Vector3();
  25781. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  25782. const _scale$2 = /*@__PURE__*/ new Vector3();
  25783. const _orientation$1 = /*@__PURE__*/ new Vector3();
  25784. class PositionalAudio extends Audio {
  25785. constructor( listener ) {
  25786. super( listener );
  25787. this.panner = this.context.createPanner();
  25788. this.panner.panningModel = 'HRTF';
  25789. this.panner.connect( this.gain );
  25790. }
  25791. getOutput() {
  25792. return this.panner;
  25793. }
  25794. getRefDistance() {
  25795. return this.panner.refDistance;
  25796. }
  25797. setRefDistance( value ) {
  25798. this.panner.refDistance = value;
  25799. return this;
  25800. }
  25801. getRolloffFactor() {
  25802. return this.panner.rolloffFactor;
  25803. }
  25804. setRolloffFactor( value ) {
  25805. this.panner.rolloffFactor = value;
  25806. return this;
  25807. }
  25808. getDistanceModel() {
  25809. return this.panner.distanceModel;
  25810. }
  25811. setDistanceModel( value ) {
  25812. this.panner.distanceModel = value;
  25813. return this;
  25814. }
  25815. getMaxDistance() {
  25816. return this.panner.maxDistance;
  25817. }
  25818. setMaxDistance( value ) {
  25819. this.panner.maxDistance = value;
  25820. return this;
  25821. }
  25822. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  25823. this.panner.coneInnerAngle = coneInnerAngle;
  25824. this.panner.coneOuterAngle = coneOuterAngle;
  25825. this.panner.coneOuterGain = coneOuterGain;
  25826. return this;
  25827. }
  25828. updateMatrixWorld( force ) {
  25829. super.updateMatrixWorld( force );
  25830. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  25831. this.matrixWorld.decompose( _position$3, _quaternion$4, _scale$2 );
  25832. _orientation$1.set( 0, 0, 1 ).applyQuaternion( _quaternion$4 );
  25833. const panner = this.panner;
  25834. if ( panner.positionX ) {
  25835. // code path for Chrome and Firefox (see #14393)
  25836. const endTime = this.context.currentTime + this.listener.timeDelta;
  25837. panner.positionX.linearRampToValueAtTime( _position$3.x, endTime );
  25838. panner.positionY.linearRampToValueAtTime( _position$3.y, endTime );
  25839. panner.positionZ.linearRampToValueAtTime( _position$3.z, endTime );
  25840. panner.orientationX.linearRampToValueAtTime( _orientation$1.x, endTime );
  25841. panner.orientationY.linearRampToValueAtTime( _orientation$1.y, endTime );
  25842. panner.orientationZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  25843. } else {
  25844. panner.setPosition( _position$3.x, _position$3.y, _position$3.z );
  25845. panner.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z );
  25846. }
  25847. }
  25848. }
  25849. class AudioAnalyser {
  25850. constructor( audio, fftSize = 2048 ) {
  25851. this.analyser = audio.context.createAnalyser();
  25852. this.analyser.fftSize = fftSize;
  25853. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  25854. audio.getOutput().connect( this.analyser );
  25855. }
  25856. getFrequencyData() {
  25857. this.analyser.getByteFrequencyData( this.data );
  25858. return this.data;
  25859. }
  25860. getAverageFrequency() {
  25861. let value = 0;
  25862. const data = this.getFrequencyData();
  25863. for ( let i = 0; i < data.length; i ++ ) {
  25864. value += data[ i ];
  25865. }
  25866. return value / data.length;
  25867. }
  25868. }
  25869. function PropertyMixer( binding, typeName, valueSize ) {
  25870. this.binding = binding;
  25871. this.valueSize = valueSize;
  25872. let mixFunction,
  25873. mixFunctionAdditive,
  25874. setIdentity;
  25875. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  25876. //
  25877. // interpolators can use .buffer as their .result
  25878. // the data then goes to 'incoming'
  25879. //
  25880. // 'accu0' and 'accu1' are used frame-interleaved for
  25881. // the cumulative result and are compared to detect
  25882. // changes
  25883. //
  25884. // 'orig' stores the original state of the property
  25885. //
  25886. // 'add' is used for additive cumulative results
  25887. //
  25888. // 'work' is optional and is only present for quaternion types. It is used
  25889. // to store intermediate quaternion multiplication results
  25890. switch ( typeName ) {
  25891. case 'quaternion':
  25892. mixFunction = this._slerp;
  25893. mixFunctionAdditive = this._slerpAdditive;
  25894. setIdentity = this._setAdditiveIdentityQuaternion;
  25895. this.buffer = new Float64Array( valueSize * 6 );
  25896. this._workIndex = 5;
  25897. break;
  25898. case 'string':
  25899. case 'bool':
  25900. mixFunction = this._select;
  25901. // Use the regular mix function and for additive on these types,
  25902. // additive is not relevant for non-numeric types
  25903. mixFunctionAdditive = this._select;
  25904. setIdentity = this._setAdditiveIdentityOther;
  25905. this.buffer = new Array( valueSize * 5 );
  25906. break;
  25907. default:
  25908. mixFunction = this._lerp;
  25909. mixFunctionAdditive = this._lerpAdditive;
  25910. setIdentity = this._setAdditiveIdentityNumeric;
  25911. this.buffer = new Float64Array( valueSize * 5 );
  25912. }
  25913. this._mixBufferRegion = mixFunction;
  25914. this._mixBufferRegionAdditive = mixFunctionAdditive;
  25915. this._setIdentity = setIdentity;
  25916. this._origIndex = 3;
  25917. this._addIndex = 4;
  25918. this.cumulativeWeight = 0;
  25919. this.cumulativeWeightAdditive = 0;
  25920. this.useCount = 0;
  25921. this.referenceCount = 0;
  25922. }
  25923. Object.assign( PropertyMixer.prototype, {
  25924. // accumulate data in the 'incoming' region into 'accu<i>'
  25925. accumulate: function ( accuIndex, weight ) {
  25926. // note: happily accumulating nothing when weight = 0, the caller knows
  25927. // the weight and shouldn't have made the call in the first place
  25928. const buffer = this.buffer,
  25929. stride = this.valueSize,
  25930. offset = accuIndex * stride + stride;
  25931. let currentWeight = this.cumulativeWeight;
  25932. if ( currentWeight === 0 ) {
  25933. // accuN := incoming * weight
  25934. for ( let i = 0; i !== stride; ++ i ) {
  25935. buffer[ offset + i ] = buffer[ i ];
  25936. }
  25937. currentWeight = weight;
  25938. } else {
  25939. // accuN := accuN + incoming * weight
  25940. currentWeight += weight;
  25941. const mix = weight / currentWeight;
  25942. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  25943. }
  25944. this.cumulativeWeight = currentWeight;
  25945. },
  25946. // accumulate data in the 'incoming' region into 'add'
  25947. accumulateAdditive: function ( weight ) {
  25948. const buffer = this.buffer,
  25949. stride = this.valueSize,
  25950. offset = stride * this._addIndex;
  25951. if ( this.cumulativeWeightAdditive === 0 ) {
  25952. // add = identity
  25953. this._setIdentity();
  25954. }
  25955. // add := add + incoming * weight
  25956. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  25957. this.cumulativeWeightAdditive += weight;
  25958. },
  25959. // apply the state of 'accu<i>' to the binding when accus differ
  25960. apply: function ( accuIndex ) {
  25961. const stride = this.valueSize,
  25962. buffer = this.buffer,
  25963. offset = accuIndex * stride + stride,
  25964. weight = this.cumulativeWeight,
  25965. weightAdditive = this.cumulativeWeightAdditive,
  25966. binding = this.binding;
  25967. this.cumulativeWeight = 0;
  25968. this.cumulativeWeightAdditive = 0;
  25969. if ( weight < 1 ) {
  25970. // accuN := accuN + original * ( 1 - cumulativeWeight )
  25971. const originalValueOffset = stride * this._origIndex;
  25972. this._mixBufferRegion(
  25973. buffer, offset, originalValueOffset, 1 - weight, stride );
  25974. }
  25975. if ( weightAdditive > 0 ) {
  25976. // accuN := accuN + additive accuN
  25977. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  25978. }
  25979. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  25980. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  25981. // value has changed -> update scene graph
  25982. binding.setValue( buffer, offset );
  25983. break;
  25984. }
  25985. }
  25986. },
  25987. // remember the state of the bound property and copy it to both accus
  25988. saveOriginalState: function () {
  25989. const binding = this.binding;
  25990. const buffer = this.buffer,
  25991. stride = this.valueSize,
  25992. originalValueOffset = stride * this._origIndex;
  25993. binding.getValue( buffer, originalValueOffset );
  25994. // accu[0..1] := orig -- initially detect changes against the original
  25995. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  25996. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  25997. }
  25998. // Add to identity for additive
  25999. this._setIdentity();
  26000. this.cumulativeWeight = 0;
  26001. this.cumulativeWeightAdditive = 0;
  26002. },
  26003. // apply the state previously taken via 'saveOriginalState' to the binding
  26004. restoreOriginalState: function () {
  26005. const originalValueOffset = this.valueSize * 3;
  26006. this.binding.setValue( this.buffer, originalValueOffset );
  26007. },
  26008. _setAdditiveIdentityNumeric: function () {
  26009. const startIndex = this._addIndex * this.valueSize;
  26010. const endIndex = startIndex + this.valueSize;
  26011. for ( let i = startIndex; i < endIndex; i ++ ) {
  26012. this.buffer[ i ] = 0;
  26013. }
  26014. },
  26015. _setAdditiveIdentityQuaternion: function () {
  26016. this._setAdditiveIdentityNumeric();
  26017. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  26018. },
  26019. _setAdditiveIdentityOther: function () {
  26020. const startIndex = this._origIndex * this.valueSize;
  26021. const targetIndex = this._addIndex * this.valueSize;
  26022. for ( let i = 0; i < this.valueSize; i ++ ) {
  26023. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  26024. }
  26025. },
  26026. // mix functions
  26027. _select: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26028. if ( t >= 0.5 ) {
  26029. for ( let i = 0; i !== stride; ++ i ) {
  26030. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  26031. }
  26032. }
  26033. },
  26034. _slerp: function ( buffer, dstOffset, srcOffset, t ) {
  26035. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  26036. },
  26037. _slerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26038. const workOffset = this._workIndex * stride;
  26039. // Store result in intermediate buffer offset
  26040. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  26041. // Slerp to the intermediate result
  26042. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  26043. },
  26044. _lerp: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26045. const s = 1 - t;
  26046. for ( let i = 0; i !== stride; ++ i ) {
  26047. const j = dstOffset + i;
  26048. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  26049. }
  26050. },
  26051. _lerpAdditive: function ( buffer, dstOffset, srcOffset, t, stride ) {
  26052. for ( let i = 0; i !== stride; ++ i ) {
  26053. const j = dstOffset + i;
  26054. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  26055. }
  26056. }
  26057. } );
  26058. // Characters [].:/ are reserved for track binding syntax.
  26059. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  26060. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  26061. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  26062. // only latin characters, and the unicode \p{L} is not yet supported. So
  26063. // instead, we exclude reserved characters and match everything else.
  26064. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  26065. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  26066. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  26067. // be matched to parse the rest of the track name.
  26068. const _directoryRe = /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  26069. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  26070. const _nodeRe = /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  26071. // Object on target node, and accessor. May not contain reserved
  26072. // characters. Accessor may contain any character except closing bracket.
  26073. const _objectRe = /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  26074. // Property and accessor. May not contain reserved characters. Accessor may
  26075. // contain any non-bracket characters.
  26076. const _propertyRe = /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  26077. const _trackRe = new RegExp( ''
  26078. + '^'
  26079. + _directoryRe
  26080. + _nodeRe
  26081. + _objectRe
  26082. + _propertyRe
  26083. + '$'
  26084. );
  26085. const _supportedObjectNames = [ 'material', 'materials', 'bones' ];
  26086. function Composite( targetGroup, path, optionalParsedPath ) {
  26087. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  26088. this._targetGroup = targetGroup;
  26089. this._bindings = targetGroup.subscribe_( path, parsedPath );
  26090. }
  26091. Object.assign( Composite.prototype, {
  26092. getValue: function ( array, offset ) {
  26093. this.bind(); // bind all binding
  26094. const firstValidIndex = this._targetGroup.nCachedObjects_,
  26095. binding = this._bindings[ firstValidIndex ];
  26096. // and only call .getValue on the first
  26097. if ( binding !== undefined ) binding.getValue( array, offset );
  26098. },
  26099. setValue: function ( array, offset ) {
  26100. const bindings = this._bindings;
  26101. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26102. bindings[ i ].setValue( array, offset );
  26103. }
  26104. },
  26105. bind: function () {
  26106. const bindings = this._bindings;
  26107. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26108. bindings[ i ].bind();
  26109. }
  26110. },
  26111. unbind: function () {
  26112. const bindings = this._bindings;
  26113. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  26114. bindings[ i ].unbind();
  26115. }
  26116. }
  26117. } );
  26118. function PropertyBinding( rootNode, path, parsedPath ) {
  26119. this.path = path;
  26120. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  26121. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName ) || rootNode;
  26122. this.rootNode = rootNode;
  26123. }
  26124. Object.assign( PropertyBinding, {
  26125. Composite: Composite,
  26126. create: function ( root, path, parsedPath ) {
  26127. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  26128. return new PropertyBinding( root, path, parsedPath );
  26129. } else {
  26130. return new PropertyBinding.Composite( root, path, parsedPath );
  26131. }
  26132. },
  26133. /**
  26134. * Replaces spaces with underscores and removes unsupported characters from
  26135. * node names, to ensure compatibility with parseTrackName().
  26136. *
  26137. * @param {string} name Node name to be sanitized.
  26138. * @return {string}
  26139. */
  26140. sanitizeNodeName: function ( name ) {
  26141. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  26142. },
  26143. parseTrackName: function ( trackName ) {
  26144. const matches = _trackRe.exec( trackName );
  26145. if ( ! matches ) {
  26146. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  26147. }
  26148. const results = {
  26149. // directoryName: matches[ 1 ], // (tschw) currently unused
  26150. nodeName: matches[ 2 ],
  26151. objectName: matches[ 3 ],
  26152. objectIndex: matches[ 4 ],
  26153. propertyName: matches[ 5 ], // required
  26154. propertyIndex: matches[ 6 ]
  26155. };
  26156. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  26157. if ( lastDot !== undefined && lastDot !== - 1 ) {
  26158. const objectName = results.nodeName.substring( lastDot + 1 );
  26159. // Object names must be checked against an allowlist. Otherwise, there
  26160. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  26161. // 'bar' could be the objectName, or part of a nodeName (which can
  26162. // include '.' characters).
  26163. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  26164. results.nodeName = results.nodeName.substring( 0, lastDot );
  26165. results.objectName = objectName;
  26166. }
  26167. }
  26168. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  26169. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  26170. }
  26171. return results;
  26172. },
  26173. findNode: function ( root, nodeName ) {
  26174. if ( ! nodeName || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  26175. return root;
  26176. }
  26177. // search into skeleton bones.
  26178. if ( root.skeleton ) {
  26179. const bone = root.skeleton.getBoneByName( nodeName );
  26180. if ( bone !== undefined ) {
  26181. return bone;
  26182. }
  26183. }
  26184. // search into node subtree.
  26185. if ( root.children ) {
  26186. const searchNodeSubtree = function ( children ) {
  26187. for ( let i = 0; i < children.length; i ++ ) {
  26188. const childNode = children[ i ];
  26189. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  26190. return childNode;
  26191. }
  26192. const result = searchNodeSubtree( childNode.children );
  26193. if ( result ) return result;
  26194. }
  26195. return null;
  26196. };
  26197. const subTreeNode = searchNodeSubtree( root.children );
  26198. if ( subTreeNode ) {
  26199. return subTreeNode;
  26200. }
  26201. }
  26202. return null;
  26203. }
  26204. } );
  26205. Object.assign( PropertyBinding.prototype, { // prototype, continued
  26206. // these are used to "bind" a nonexistent property
  26207. _getValue_unavailable: function () {},
  26208. _setValue_unavailable: function () {},
  26209. BindingType: {
  26210. Direct: 0,
  26211. EntireArray: 1,
  26212. ArrayElement: 2,
  26213. HasFromToArray: 3
  26214. },
  26215. Versioning: {
  26216. None: 0,
  26217. NeedsUpdate: 1,
  26218. MatrixWorldNeedsUpdate: 2
  26219. },
  26220. GetterByBindingType: [
  26221. function getValue_direct( buffer, offset ) {
  26222. buffer[ offset ] = this.node[ this.propertyName ];
  26223. },
  26224. function getValue_array( buffer, offset ) {
  26225. const source = this.resolvedProperty;
  26226. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  26227. buffer[ offset ++ ] = source[ i ];
  26228. }
  26229. },
  26230. function getValue_arrayElement( buffer, offset ) {
  26231. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  26232. },
  26233. function getValue_toArray( buffer, offset ) {
  26234. this.resolvedProperty.toArray( buffer, offset );
  26235. }
  26236. ],
  26237. SetterByBindingTypeAndVersioning: [
  26238. [
  26239. // Direct
  26240. function setValue_direct( buffer, offset ) {
  26241. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26242. },
  26243. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  26244. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26245. this.targetObject.needsUpdate = true;
  26246. },
  26247. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26248. this.targetObject[ this.propertyName ] = buffer[ offset ];
  26249. this.targetObject.matrixWorldNeedsUpdate = true;
  26250. }
  26251. ], [
  26252. // EntireArray
  26253. function setValue_array( buffer, offset ) {
  26254. const dest = this.resolvedProperty;
  26255. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26256. dest[ i ] = buffer[ offset ++ ];
  26257. }
  26258. },
  26259. function setValue_array_setNeedsUpdate( buffer, offset ) {
  26260. const dest = this.resolvedProperty;
  26261. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26262. dest[ i ] = buffer[ offset ++ ];
  26263. }
  26264. this.targetObject.needsUpdate = true;
  26265. },
  26266. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26267. const dest = this.resolvedProperty;
  26268. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  26269. dest[ i ] = buffer[ offset ++ ];
  26270. }
  26271. this.targetObject.matrixWorldNeedsUpdate = true;
  26272. }
  26273. ], [
  26274. // ArrayElement
  26275. function setValue_arrayElement( buffer, offset ) {
  26276. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26277. },
  26278. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  26279. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26280. this.targetObject.needsUpdate = true;
  26281. },
  26282. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26283. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  26284. this.targetObject.matrixWorldNeedsUpdate = true;
  26285. }
  26286. ], [
  26287. // HasToFromArray
  26288. function setValue_fromArray( buffer, offset ) {
  26289. this.resolvedProperty.fromArray( buffer, offset );
  26290. },
  26291. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  26292. this.resolvedProperty.fromArray( buffer, offset );
  26293. this.targetObject.needsUpdate = true;
  26294. },
  26295. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  26296. this.resolvedProperty.fromArray( buffer, offset );
  26297. this.targetObject.matrixWorldNeedsUpdate = true;
  26298. }
  26299. ]
  26300. ],
  26301. getValue: function getValue_unbound( targetArray, offset ) {
  26302. this.bind();
  26303. this.getValue( targetArray, offset );
  26304. // Note: This class uses a State pattern on a per-method basis:
  26305. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  26306. // prototype version of these methods with one that represents
  26307. // the bound state. When the property is not found, the methods
  26308. // become no-ops.
  26309. },
  26310. setValue: function getValue_unbound( sourceArray, offset ) {
  26311. this.bind();
  26312. this.setValue( sourceArray, offset );
  26313. },
  26314. // create getter / setter pair for a property in the scene graph
  26315. bind: function () {
  26316. let targetObject = this.node;
  26317. const parsedPath = this.parsedPath;
  26318. const objectName = parsedPath.objectName;
  26319. const propertyName = parsedPath.propertyName;
  26320. let propertyIndex = parsedPath.propertyIndex;
  26321. if ( ! targetObject ) {
  26322. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName ) || this.rootNode;
  26323. this.node = targetObject;
  26324. }
  26325. // set fail state so we can just 'return' on error
  26326. this.getValue = this._getValue_unavailable;
  26327. this.setValue = this._setValue_unavailable;
  26328. // ensure there is a value node
  26329. if ( ! targetObject ) {
  26330. console.error( 'THREE.PropertyBinding: Trying to update node for track: ' + this.path + ' but it wasn\'t found.' );
  26331. return;
  26332. }
  26333. if ( objectName ) {
  26334. let objectIndex = parsedPath.objectIndex;
  26335. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  26336. switch ( objectName ) {
  26337. case 'materials':
  26338. if ( ! targetObject.material ) {
  26339. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  26340. return;
  26341. }
  26342. if ( ! targetObject.material.materials ) {
  26343. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  26344. return;
  26345. }
  26346. targetObject = targetObject.material.materials;
  26347. break;
  26348. case 'bones':
  26349. if ( ! targetObject.skeleton ) {
  26350. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  26351. return;
  26352. }
  26353. // potential future optimization: skip this if propertyIndex is already an integer
  26354. // and convert the integer string to a true integer.
  26355. targetObject = targetObject.skeleton.bones;
  26356. // support resolving morphTarget names into indices.
  26357. for ( let i = 0; i < targetObject.length; i ++ ) {
  26358. if ( targetObject[ i ].name === objectIndex ) {
  26359. objectIndex = i;
  26360. break;
  26361. }
  26362. }
  26363. break;
  26364. default:
  26365. if ( targetObject[ objectName ] === undefined ) {
  26366. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  26367. return;
  26368. }
  26369. targetObject = targetObject[ objectName ];
  26370. }
  26371. if ( objectIndex !== undefined ) {
  26372. if ( targetObject[ objectIndex ] === undefined ) {
  26373. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  26374. return;
  26375. }
  26376. targetObject = targetObject[ objectIndex ];
  26377. }
  26378. }
  26379. // resolve property
  26380. const nodeProperty = targetObject[ propertyName ];
  26381. if ( nodeProperty === undefined ) {
  26382. const nodeName = parsedPath.nodeName;
  26383. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  26384. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  26385. return;
  26386. }
  26387. // determine versioning scheme
  26388. let versioning = this.Versioning.None;
  26389. this.targetObject = targetObject;
  26390. if ( targetObject.needsUpdate !== undefined ) { // material
  26391. versioning = this.Versioning.NeedsUpdate;
  26392. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  26393. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  26394. }
  26395. // determine how the property gets bound
  26396. let bindingType = this.BindingType.Direct;
  26397. if ( propertyIndex !== undefined ) {
  26398. // access a sub element of the property array (only primitives are supported right now)
  26399. if ( propertyName === 'morphTargetInfluences' ) {
  26400. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  26401. // support resolving morphTarget names into indices.
  26402. if ( ! targetObject.geometry ) {
  26403. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  26404. return;
  26405. }
  26406. if ( targetObject.geometry.isBufferGeometry ) {
  26407. if ( ! targetObject.geometry.morphAttributes ) {
  26408. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  26409. return;
  26410. }
  26411. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  26412. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  26413. }
  26414. } else {
  26415. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences on THREE.Geometry. Use THREE.BufferGeometry instead.', this );
  26416. return;
  26417. }
  26418. }
  26419. bindingType = this.BindingType.ArrayElement;
  26420. this.resolvedProperty = nodeProperty;
  26421. this.propertyIndex = propertyIndex;
  26422. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  26423. // must use copy for Object3D.Euler/Quaternion
  26424. bindingType = this.BindingType.HasFromToArray;
  26425. this.resolvedProperty = nodeProperty;
  26426. } else if ( Array.isArray( nodeProperty ) ) {
  26427. bindingType = this.BindingType.EntireArray;
  26428. this.resolvedProperty = nodeProperty;
  26429. } else {
  26430. this.propertyName = propertyName;
  26431. }
  26432. // select getter / setter
  26433. this.getValue = this.GetterByBindingType[ bindingType ];
  26434. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  26435. },
  26436. unbind: function () {
  26437. this.node = null;
  26438. // back to the prototype version of getValue / setValue
  26439. // note: avoiding to mutate the shape of 'this' via 'delete'
  26440. this.getValue = this._getValue_unbound;
  26441. this.setValue = this._setValue_unbound;
  26442. }
  26443. } );
  26444. // DECLARE ALIAS AFTER assign prototype
  26445. Object.assign( PropertyBinding.prototype, {
  26446. // initial state of these methods that calls 'bind'
  26447. _getValue_unbound: PropertyBinding.prototype.getValue,
  26448. _setValue_unbound: PropertyBinding.prototype.setValue,
  26449. } );
  26450. /**
  26451. *
  26452. * A group of objects that receives a shared animation state.
  26453. *
  26454. * Usage:
  26455. *
  26456. * - Add objects you would otherwise pass as 'root' to the
  26457. * constructor or the .clipAction method of AnimationMixer.
  26458. *
  26459. * - Instead pass this object as 'root'.
  26460. *
  26461. * - You can also add and remove objects later when the mixer
  26462. * is running.
  26463. *
  26464. * Note:
  26465. *
  26466. * Objects of this class appear as one object to the mixer,
  26467. * so cache control of the individual objects must be done
  26468. * on the group.
  26469. *
  26470. * Limitation:
  26471. *
  26472. * - The animated properties must be compatible among the
  26473. * all objects in the group.
  26474. *
  26475. * - A single property can either be controlled through a
  26476. * target group or directly, but not both.
  26477. */
  26478. function AnimationObjectGroup() {
  26479. this.uuid = MathUtils.generateUUID();
  26480. // cached objects followed by the active ones
  26481. this._objects = Array.prototype.slice.call( arguments );
  26482. this.nCachedObjects_ = 0; // threshold
  26483. // note: read by PropertyBinding.Composite
  26484. const indices = {};
  26485. this._indicesByUUID = indices; // for bookkeeping
  26486. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26487. indices[ arguments[ i ].uuid ] = i;
  26488. }
  26489. this._paths = []; // inside: string
  26490. this._parsedPaths = []; // inside: { we don't care, here }
  26491. this._bindings = []; // inside: Array< PropertyBinding >
  26492. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  26493. const scope = this;
  26494. this.stats = {
  26495. objects: {
  26496. get total() {
  26497. return scope._objects.length;
  26498. },
  26499. get inUse() {
  26500. return this.total - scope.nCachedObjects_;
  26501. }
  26502. },
  26503. get bindingsPerObject() {
  26504. return scope._bindings.length;
  26505. }
  26506. };
  26507. }
  26508. Object.assign( AnimationObjectGroup.prototype, {
  26509. isAnimationObjectGroup: true,
  26510. add: function () {
  26511. const objects = this._objects,
  26512. indicesByUUID = this._indicesByUUID,
  26513. paths = this._paths,
  26514. parsedPaths = this._parsedPaths,
  26515. bindings = this._bindings,
  26516. nBindings = bindings.length;
  26517. let knownObject = undefined,
  26518. nObjects = objects.length,
  26519. nCachedObjects = this.nCachedObjects_;
  26520. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26521. const object = arguments[ i ],
  26522. uuid = object.uuid;
  26523. let index = indicesByUUID[ uuid ];
  26524. if ( index === undefined ) {
  26525. // unknown object -> add it to the ACTIVE region
  26526. index = nObjects ++;
  26527. indicesByUUID[ uuid ] = index;
  26528. objects.push( object );
  26529. // accounting is done, now do the same for all bindings
  26530. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26531. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  26532. }
  26533. } else if ( index < nCachedObjects ) {
  26534. knownObject = objects[ index ];
  26535. // move existing object to the ACTIVE region
  26536. const firstActiveIndex = -- nCachedObjects,
  26537. lastCachedObject = objects[ firstActiveIndex ];
  26538. indicesByUUID[ lastCachedObject.uuid ] = index;
  26539. objects[ index ] = lastCachedObject;
  26540. indicesByUUID[ uuid ] = firstActiveIndex;
  26541. objects[ firstActiveIndex ] = object;
  26542. // accounting is done, now do the same for all bindings
  26543. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26544. const bindingsForPath = bindings[ j ],
  26545. lastCached = bindingsForPath[ firstActiveIndex ];
  26546. let binding = bindingsForPath[ index ];
  26547. bindingsForPath[ index ] = lastCached;
  26548. if ( binding === undefined ) {
  26549. // since we do not bother to create new bindings
  26550. // for objects that are cached, the binding may
  26551. // or may not exist
  26552. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  26553. }
  26554. bindingsForPath[ firstActiveIndex ] = binding;
  26555. }
  26556. } else if ( objects[ index ] !== knownObject ) {
  26557. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  26558. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  26559. } // else the object is already where we want it to be
  26560. } // for arguments
  26561. this.nCachedObjects_ = nCachedObjects;
  26562. },
  26563. remove: function () {
  26564. const objects = this._objects,
  26565. indicesByUUID = this._indicesByUUID,
  26566. bindings = this._bindings,
  26567. nBindings = bindings.length;
  26568. let nCachedObjects = this.nCachedObjects_;
  26569. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26570. const object = arguments[ i ],
  26571. uuid = object.uuid,
  26572. index = indicesByUUID[ uuid ];
  26573. if ( index !== undefined && index >= nCachedObjects ) {
  26574. // move existing object into the CACHED region
  26575. const lastCachedIndex = nCachedObjects ++,
  26576. firstActiveObject = objects[ lastCachedIndex ];
  26577. indicesByUUID[ firstActiveObject.uuid ] = index;
  26578. objects[ index ] = firstActiveObject;
  26579. indicesByUUID[ uuid ] = lastCachedIndex;
  26580. objects[ lastCachedIndex ] = object;
  26581. // accounting is done, now do the same for all bindings
  26582. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26583. const bindingsForPath = bindings[ j ],
  26584. firstActive = bindingsForPath[ lastCachedIndex ],
  26585. binding = bindingsForPath[ index ];
  26586. bindingsForPath[ index ] = firstActive;
  26587. bindingsForPath[ lastCachedIndex ] = binding;
  26588. }
  26589. }
  26590. } // for arguments
  26591. this.nCachedObjects_ = nCachedObjects;
  26592. },
  26593. // remove & forget
  26594. uncache: function () {
  26595. const objects = this._objects,
  26596. indicesByUUID = this._indicesByUUID,
  26597. bindings = this._bindings,
  26598. nBindings = bindings.length;
  26599. let nCachedObjects = this.nCachedObjects_,
  26600. nObjects = objects.length;
  26601. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  26602. const object = arguments[ i ],
  26603. uuid = object.uuid,
  26604. index = indicesByUUID[ uuid ];
  26605. if ( index !== undefined ) {
  26606. delete indicesByUUID[ uuid ];
  26607. if ( index < nCachedObjects ) {
  26608. // object is cached, shrink the CACHED region
  26609. const firstActiveIndex = -- nCachedObjects,
  26610. lastCachedObject = objects[ firstActiveIndex ],
  26611. lastIndex = -- nObjects,
  26612. lastObject = objects[ lastIndex ];
  26613. // last cached object takes this object's place
  26614. indicesByUUID[ lastCachedObject.uuid ] = index;
  26615. objects[ index ] = lastCachedObject;
  26616. // last object goes to the activated slot and pop
  26617. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  26618. objects[ firstActiveIndex ] = lastObject;
  26619. objects.pop();
  26620. // accounting is done, now do the same for all bindings
  26621. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26622. const bindingsForPath = bindings[ j ],
  26623. lastCached = bindingsForPath[ firstActiveIndex ],
  26624. last = bindingsForPath[ lastIndex ];
  26625. bindingsForPath[ index ] = lastCached;
  26626. bindingsForPath[ firstActiveIndex ] = last;
  26627. bindingsForPath.pop();
  26628. }
  26629. } else {
  26630. // object is active, just swap with the last and pop
  26631. const lastIndex = -- nObjects,
  26632. lastObject = objects[ lastIndex ];
  26633. if ( lastIndex > 0 ) {
  26634. indicesByUUID[ lastObject.uuid ] = index;
  26635. }
  26636. objects[ index ] = lastObject;
  26637. objects.pop();
  26638. // accounting is done, now do the same for all bindings
  26639. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  26640. const bindingsForPath = bindings[ j ];
  26641. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  26642. bindingsForPath.pop();
  26643. }
  26644. } // cached or active
  26645. } // if object is known
  26646. } // for arguments
  26647. this.nCachedObjects_ = nCachedObjects;
  26648. },
  26649. // Internal interface used by befriended PropertyBinding.Composite:
  26650. subscribe_: function ( path, parsedPath ) {
  26651. // returns an array of bindings for the given path that is changed
  26652. // according to the contained objects in the group
  26653. const indicesByPath = this._bindingsIndicesByPath;
  26654. let index = indicesByPath[ path ];
  26655. const bindings = this._bindings;
  26656. if ( index !== undefined ) return bindings[ index ];
  26657. const paths = this._paths,
  26658. parsedPaths = this._parsedPaths,
  26659. objects = this._objects,
  26660. nObjects = objects.length,
  26661. nCachedObjects = this.nCachedObjects_,
  26662. bindingsForPath = new Array( nObjects );
  26663. index = bindings.length;
  26664. indicesByPath[ path ] = index;
  26665. paths.push( path );
  26666. parsedPaths.push( parsedPath );
  26667. bindings.push( bindingsForPath );
  26668. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  26669. const object = objects[ i ];
  26670. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  26671. }
  26672. return bindingsForPath;
  26673. },
  26674. unsubscribe_: function ( path ) {
  26675. // tells the group to forget about a property path and no longer
  26676. // update the array previously obtained with 'subscribe_'
  26677. const indicesByPath = this._bindingsIndicesByPath,
  26678. index = indicesByPath[ path ];
  26679. if ( index !== undefined ) {
  26680. const paths = this._paths,
  26681. parsedPaths = this._parsedPaths,
  26682. bindings = this._bindings,
  26683. lastBindingsIndex = bindings.length - 1,
  26684. lastBindings = bindings[ lastBindingsIndex ],
  26685. lastBindingsPath = path[ lastBindingsIndex ];
  26686. indicesByPath[ lastBindingsPath ] = index;
  26687. bindings[ index ] = lastBindings;
  26688. bindings.pop();
  26689. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  26690. parsedPaths.pop();
  26691. paths[ index ] = paths[ lastBindingsIndex ];
  26692. paths.pop();
  26693. }
  26694. }
  26695. } );
  26696. class AnimationAction {
  26697. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  26698. this._mixer = mixer;
  26699. this._clip = clip;
  26700. this._localRoot = localRoot;
  26701. this.blendMode = blendMode;
  26702. const tracks = clip.tracks,
  26703. nTracks = tracks.length,
  26704. interpolants = new Array( nTracks );
  26705. const interpolantSettings = {
  26706. endingStart: ZeroCurvatureEnding,
  26707. endingEnd: ZeroCurvatureEnding
  26708. };
  26709. for ( let i = 0; i !== nTracks; ++ i ) {
  26710. const interpolant = tracks[ i ].createInterpolant( null );
  26711. interpolants[ i ] = interpolant;
  26712. interpolant.settings = interpolantSettings;
  26713. }
  26714. this._interpolantSettings = interpolantSettings;
  26715. this._interpolants = interpolants; // bound by the mixer
  26716. // inside: PropertyMixer (managed by the mixer)
  26717. this._propertyBindings = new Array( nTracks );
  26718. this._cacheIndex = null; // for the memory manager
  26719. this._byClipCacheIndex = null; // for the memory manager
  26720. this._timeScaleInterpolant = null;
  26721. this._weightInterpolant = null;
  26722. this.loop = LoopRepeat;
  26723. this._loopCount = - 1;
  26724. // global mixer time when the action is to be started
  26725. // it's set back to 'null' upon start of the action
  26726. this._startTime = null;
  26727. // scaled local time of the action
  26728. // gets clamped or wrapped to 0..clip.duration according to loop
  26729. this.time = 0;
  26730. this.timeScale = 1;
  26731. this._effectiveTimeScale = 1;
  26732. this.weight = 1;
  26733. this._effectiveWeight = 1;
  26734. this.repetitions = Infinity; // no. of repetitions when looping
  26735. this.paused = false; // true -> zero effective time scale
  26736. this.enabled = true; // false -> zero effective weight
  26737. this.clampWhenFinished = false;// keep feeding the last frame?
  26738. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  26739. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  26740. }
  26741. // State & Scheduling
  26742. play() {
  26743. this._mixer._activateAction( this );
  26744. return this;
  26745. }
  26746. stop() {
  26747. this._mixer._deactivateAction( this );
  26748. return this.reset();
  26749. }
  26750. reset() {
  26751. this.paused = false;
  26752. this.enabled = true;
  26753. this.time = 0; // restart clip
  26754. this._loopCount = - 1;// forget previous loops
  26755. this._startTime = null;// forget scheduling
  26756. return this.stopFading().stopWarping();
  26757. }
  26758. isRunning() {
  26759. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  26760. this._startTime === null && this._mixer._isActiveAction( this );
  26761. }
  26762. // return true when play has been called
  26763. isScheduled() {
  26764. return this._mixer._isActiveAction( this );
  26765. }
  26766. startAt( time ) {
  26767. this._startTime = time;
  26768. return this;
  26769. }
  26770. setLoop( mode, repetitions ) {
  26771. this.loop = mode;
  26772. this.repetitions = repetitions;
  26773. return this;
  26774. }
  26775. // Weight
  26776. // set the weight stopping any scheduled fading
  26777. // although .enabled = false yields an effective weight of zero, this
  26778. // method does *not* change .enabled, because it would be confusing
  26779. setEffectiveWeight( weight ) {
  26780. this.weight = weight;
  26781. // note: same logic as when updated at runtime
  26782. this._effectiveWeight = this.enabled ? weight : 0;
  26783. return this.stopFading();
  26784. }
  26785. // return the weight considering fading and .enabled
  26786. getEffectiveWeight() {
  26787. return this._effectiveWeight;
  26788. }
  26789. fadeIn( duration ) {
  26790. return this._scheduleFading( duration, 0, 1 );
  26791. }
  26792. fadeOut( duration ) {
  26793. return this._scheduleFading( duration, 1, 0 );
  26794. }
  26795. crossFadeFrom( fadeOutAction, duration, warp ) {
  26796. fadeOutAction.fadeOut( duration );
  26797. this.fadeIn( duration );
  26798. if ( warp ) {
  26799. const fadeInDuration = this._clip.duration,
  26800. fadeOutDuration = fadeOutAction._clip.duration,
  26801. startEndRatio = fadeOutDuration / fadeInDuration,
  26802. endStartRatio = fadeInDuration / fadeOutDuration;
  26803. fadeOutAction.warp( 1.0, startEndRatio, duration );
  26804. this.warp( endStartRatio, 1.0, duration );
  26805. }
  26806. return this;
  26807. }
  26808. crossFadeTo( fadeInAction, duration, warp ) {
  26809. return fadeInAction.crossFadeFrom( this, duration, warp );
  26810. }
  26811. stopFading() {
  26812. const weightInterpolant = this._weightInterpolant;
  26813. if ( weightInterpolant !== null ) {
  26814. this._weightInterpolant = null;
  26815. this._mixer._takeBackControlInterpolant( weightInterpolant );
  26816. }
  26817. return this;
  26818. }
  26819. // Time Scale Control
  26820. // set the time scale stopping any scheduled warping
  26821. // although .paused = true yields an effective time scale of zero, this
  26822. // method does *not* change .paused, because it would be confusing
  26823. setEffectiveTimeScale( timeScale ) {
  26824. this.timeScale = timeScale;
  26825. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  26826. return this.stopWarping();
  26827. }
  26828. // return the time scale considering warping and .paused
  26829. getEffectiveTimeScale() {
  26830. return this._effectiveTimeScale;
  26831. }
  26832. setDuration( duration ) {
  26833. this.timeScale = this._clip.duration / duration;
  26834. return this.stopWarping();
  26835. }
  26836. syncWith( action ) {
  26837. this.time = action.time;
  26838. this.timeScale = action.timeScale;
  26839. return this.stopWarping();
  26840. }
  26841. halt( duration ) {
  26842. return this.warp( this._effectiveTimeScale, 0, duration );
  26843. }
  26844. warp( startTimeScale, endTimeScale, duration ) {
  26845. const mixer = this._mixer,
  26846. now = mixer.time,
  26847. timeScale = this.timeScale;
  26848. let interpolant = this._timeScaleInterpolant;
  26849. if ( interpolant === null ) {
  26850. interpolant = mixer._lendControlInterpolant();
  26851. this._timeScaleInterpolant = interpolant;
  26852. }
  26853. const times = interpolant.parameterPositions,
  26854. values = interpolant.sampleValues;
  26855. times[ 0 ] = now;
  26856. times[ 1 ] = now + duration;
  26857. values[ 0 ] = startTimeScale / timeScale;
  26858. values[ 1 ] = endTimeScale / timeScale;
  26859. return this;
  26860. }
  26861. stopWarping() {
  26862. const timeScaleInterpolant = this._timeScaleInterpolant;
  26863. if ( timeScaleInterpolant !== null ) {
  26864. this._timeScaleInterpolant = null;
  26865. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  26866. }
  26867. return this;
  26868. }
  26869. // Object Accessors
  26870. getMixer() {
  26871. return this._mixer;
  26872. }
  26873. getClip() {
  26874. return this._clip;
  26875. }
  26876. getRoot() {
  26877. return this._localRoot || this._mixer._root;
  26878. }
  26879. // Interna
  26880. _update( time, deltaTime, timeDirection, accuIndex ) {
  26881. // called by the mixer
  26882. if ( ! this.enabled ) {
  26883. // call ._updateWeight() to update ._effectiveWeight
  26884. this._updateWeight( time );
  26885. return;
  26886. }
  26887. const startTime = this._startTime;
  26888. if ( startTime !== null ) {
  26889. // check for scheduled start of action
  26890. const timeRunning = ( time - startTime ) * timeDirection;
  26891. if ( timeRunning < 0 || timeDirection === 0 ) {
  26892. return; // yet to come / don't decide when delta = 0
  26893. }
  26894. // start
  26895. this._startTime = null; // unschedule
  26896. deltaTime = timeDirection * timeRunning;
  26897. }
  26898. // apply time scale and advance time
  26899. deltaTime *= this._updateTimeScale( time );
  26900. const clipTime = this._updateTime( deltaTime );
  26901. // note: _updateTime may disable the action resulting in
  26902. // an effective weight of 0
  26903. const weight = this._updateWeight( time );
  26904. if ( weight > 0 ) {
  26905. const interpolants = this._interpolants;
  26906. const propertyMixers = this._propertyBindings;
  26907. switch ( this.blendMode ) {
  26908. case AdditiveAnimationBlendMode:
  26909. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  26910. interpolants[ j ].evaluate( clipTime );
  26911. propertyMixers[ j ].accumulateAdditive( weight );
  26912. }
  26913. break;
  26914. case NormalAnimationBlendMode:
  26915. default:
  26916. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  26917. interpolants[ j ].evaluate( clipTime );
  26918. propertyMixers[ j ].accumulate( accuIndex, weight );
  26919. }
  26920. }
  26921. }
  26922. }
  26923. _updateWeight( time ) {
  26924. let weight = 0;
  26925. if ( this.enabled ) {
  26926. weight = this.weight;
  26927. const interpolant = this._weightInterpolant;
  26928. if ( interpolant !== null ) {
  26929. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  26930. weight *= interpolantValue;
  26931. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26932. this.stopFading();
  26933. if ( interpolantValue === 0 ) {
  26934. // faded out, disable
  26935. this.enabled = false;
  26936. }
  26937. }
  26938. }
  26939. }
  26940. this._effectiveWeight = weight;
  26941. return weight;
  26942. }
  26943. _updateTimeScale( time ) {
  26944. let timeScale = 0;
  26945. if ( ! this.paused ) {
  26946. timeScale = this.timeScale;
  26947. const interpolant = this._timeScaleInterpolant;
  26948. if ( interpolant !== null ) {
  26949. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  26950. timeScale *= interpolantValue;
  26951. if ( time > interpolant.parameterPositions[ 1 ] ) {
  26952. this.stopWarping();
  26953. if ( timeScale === 0 ) {
  26954. // motion has halted, pause
  26955. this.paused = true;
  26956. } else {
  26957. // warp done - apply final time scale
  26958. this.timeScale = timeScale;
  26959. }
  26960. }
  26961. }
  26962. }
  26963. this._effectiveTimeScale = timeScale;
  26964. return timeScale;
  26965. }
  26966. _updateTime( deltaTime ) {
  26967. const duration = this._clip.duration;
  26968. const loop = this.loop;
  26969. let time = this.time + deltaTime;
  26970. let loopCount = this._loopCount;
  26971. const pingPong = ( loop === LoopPingPong );
  26972. if ( deltaTime === 0 ) {
  26973. if ( loopCount === - 1 ) return time;
  26974. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  26975. }
  26976. if ( loop === LoopOnce ) {
  26977. if ( loopCount === - 1 ) {
  26978. // just started
  26979. this._loopCount = 0;
  26980. this._setEndings( true, true, false );
  26981. }
  26982. handle_stop: {
  26983. if ( time >= duration ) {
  26984. time = duration;
  26985. } else if ( time < 0 ) {
  26986. time = 0;
  26987. } else {
  26988. this.time = time;
  26989. break handle_stop;
  26990. }
  26991. if ( this.clampWhenFinished ) this.paused = true;
  26992. else this.enabled = false;
  26993. this.time = time;
  26994. this._mixer.dispatchEvent( {
  26995. type: 'finished', action: this,
  26996. direction: deltaTime < 0 ? - 1 : 1
  26997. } );
  26998. }
  26999. } else { // repetitive Repeat or PingPong
  27000. if ( loopCount === - 1 ) {
  27001. // just started
  27002. if ( deltaTime >= 0 ) {
  27003. loopCount = 0;
  27004. this._setEndings( true, this.repetitions === 0, pingPong );
  27005. } else {
  27006. // when looping in reverse direction, the initial
  27007. // transition through zero counts as a repetition,
  27008. // so leave loopCount at -1
  27009. this._setEndings( this.repetitions === 0, true, pingPong );
  27010. }
  27011. }
  27012. if ( time >= duration || time < 0 ) {
  27013. // wrap around
  27014. const loopDelta = Math.floor( time / duration ); // signed
  27015. time -= duration * loopDelta;
  27016. loopCount += Math.abs( loopDelta );
  27017. const pending = this.repetitions - loopCount;
  27018. if ( pending <= 0 ) {
  27019. // have to stop (switch state, clamp time, fire event)
  27020. if ( this.clampWhenFinished ) this.paused = true;
  27021. else this.enabled = false;
  27022. time = deltaTime > 0 ? duration : 0;
  27023. this.time = time;
  27024. this._mixer.dispatchEvent( {
  27025. type: 'finished', action: this,
  27026. direction: deltaTime > 0 ? 1 : - 1
  27027. } );
  27028. } else {
  27029. // keep running
  27030. if ( pending === 1 ) {
  27031. // entering the last round
  27032. const atStart = deltaTime < 0;
  27033. this._setEndings( atStart, ! atStart, pingPong );
  27034. } else {
  27035. this._setEndings( false, false, pingPong );
  27036. }
  27037. this._loopCount = loopCount;
  27038. this.time = time;
  27039. this._mixer.dispatchEvent( {
  27040. type: 'loop', action: this, loopDelta: loopDelta
  27041. } );
  27042. }
  27043. } else {
  27044. this.time = time;
  27045. }
  27046. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  27047. // invert time for the "pong round"
  27048. return duration - time;
  27049. }
  27050. }
  27051. return time;
  27052. }
  27053. _setEndings( atStart, atEnd, pingPong ) {
  27054. const settings = this._interpolantSettings;
  27055. if ( pingPong ) {
  27056. settings.endingStart = ZeroSlopeEnding;
  27057. settings.endingEnd = ZeroSlopeEnding;
  27058. } else {
  27059. // assuming for LoopOnce atStart == atEnd == true
  27060. if ( atStart ) {
  27061. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27062. } else {
  27063. settings.endingStart = WrapAroundEnding;
  27064. }
  27065. if ( atEnd ) {
  27066. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  27067. } else {
  27068. settings.endingEnd = WrapAroundEnding;
  27069. }
  27070. }
  27071. }
  27072. _scheduleFading( duration, weightNow, weightThen ) {
  27073. const mixer = this._mixer, now = mixer.time;
  27074. let interpolant = this._weightInterpolant;
  27075. if ( interpolant === null ) {
  27076. interpolant = mixer._lendControlInterpolant();
  27077. this._weightInterpolant = interpolant;
  27078. }
  27079. const times = interpolant.parameterPositions,
  27080. values = interpolant.sampleValues;
  27081. times[ 0 ] = now;
  27082. values[ 0 ] = weightNow;
  27083. times[ 1 ] = now + duration;
  27084. values[ 1 ] = weightThen;
  27085. return this;
  27086. }
  27087. }
  27088. function AnimationMixer( root ) {
  27089. this._root = root;
  27090. this._initMemoryManager();
  27091. this._accuIndex = 0;
  27092. this.time = 0;
  27093. this.timeScale = 1.0;
  27094. }
  27095. AnimationMixer.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
  27096. constructor: AnimationMixer,
  27097. _bindAction: function ( action, prototypeAction ) {
  27098. const root = action._localRoot || this._root,
  27099. tracks = action._clip.tracks,
  27100. nTracks = tracks.length,
  27101. bindings = action._propertyBindings,
  27102. interpolants = action._interpolants,
  27103. rootUuid = root.uuid,
  27104. bindingsByRoot = this._bindingsByRootAndName;
  27105. let bindingsByName = bindingsByRoot[ rootUuid ];
  27106. if ( bindingsByName === undefined ) {
  27107. bindingsByName = {};
  27108. bindingsByRoot[ rootUuid ] = bindingsByName;
  27109. }
  27110. for ( let i = 0; i !== nTracks; ++ i ) {
  27111. const track = tracks[ i ],
  27112. trackName = track.name;
  27113. let binding = bindingsByName[ trackName ];
  27114. if ( binding !== undefined ) {
  27115. bindings[ i ] = binding;
  27116. } else {
  27117. binding = bindings[ i ];
  27118. if ( binding !== undefined ) {
  27119. // existing binding, make sure the cache knows
  27120. if ( binding._cacheIndex === null ) {
  27121. ++ binding.referenceCount;
  27122. this._addInactiveBinding( binding, rootUuid, trackName );
  27123. }
  27124. continue;
  27125. }
  27126. const path = prototypeAction && prototypeAction.
  27127. _propertyBindings[ i ].binding.parsedPath;
  27128. binding = new PropertyMixer(
  27129. PropertyBinding.create( root, trackName, path ),
  27130. track.ValueTypeName, track.getValueSize() );
  27131. ++ binding.referenceCount;
  27132. this._addInactiveBinding( binding, rootUuid, trackName );
  27133. bindings[ i ] = binding;
  27134. }
  27135. interpolants[ i ].resultBuffer = binding.buffer;
  27136. }
  27137. },
  27138. _activateAction: function ( action ) {
  27139. if ( ! this._isActiveAction( action ) ) {
  27140. if ( action._cacheIndex === null ) {
  27141. // this action has been forgotten by the cache, but the user
  27142. // appears to be still using it -> rebind
  27143. const rootUuid = ( action._localRoot || this._root ).uuid,
  27144. clipUuid = action._clip.uuid,
  27145. actionsForClip = this._actionsByClip[ clipUuid ];
  27146. this._bindAction( action,
  27147. actionsForClip && actionsForClip.knownActions[ 0 ] );
  27148. this._addInactiveAction( action, clipUuid, rootUuid );
  27149. }
  27150. const bindings = action._propertyBindings;
  27151. // increment reference counts / sort out state
  27152. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27153. const binding = bindings[ i ];
  27154. if ( binding.useCount ++ === 0 ) {
  27155. this._lendBinding( binding );
  27156. binding.saveOriginalState();
  27157. }
  27158. }
  27159. this._lendAction( action );
  27160. }
  27161. },
  27162. _deactivateAction: function ( action ) {
  27163. if ( this._isActiveAction( action ) ) {
  27164. const bindings = action._propertyBindings;
  27165. // decrement reference counts / sort out state
  27166. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27167. const binding = bindings[ i ];
  27168. if ( -- binding.useCount === 0 ) {
  27169. binding.restoreOriginalState();
  27170. this._takeBackBinding( binding );
  27171. }
  27172. }
  27173. this._takeBackAction( action );
  27174. }
  27175. },
  27176. // Memory manager
  27177. _initMemoryManager: function () {
  27178. this._actions = []; // 'nActiveActions' followed by inactive ones
  27179. this._nActiveActions = 0;
  27180. this._actionsByClip = {};
  27181. // inside:
  27182. // {
  27183. // knownActions: Array< AnimationAction > - used as prototypes
  27184. // actionByRoot: AnimationAction - lookup
  27185. // }
  27186. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  27187. this._nActiveBindings = 0;
  27188. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  27189. this._controlInterpolants = []; // same game as above
  27190. this._nActiveControlInterpolants = 0;
  27191. const scope = this;
  27192. this.stats = {
  27193. actions: {
  27194. get total() {
  27195. return scope._actions.length;
  27196. },
  27197. get inUse() {
  27198. return scope._nActiveActions;
  27199. }
  27200. },
  27201. bindings: {
  27202. get total() {
  27203. return scope._bindings.length;
  27204. },
  27205. get inUse() {
  27206. return scope._nActiveBindings;
  27207. }
  27208. },
  27209. controlInterpolants: {
  27210. get total() {
  27211. return scope._controlInterpolants.length;
  27212. },
  27213. get inUse() {
  27214. return scope._nActiveControlInterpolants;
  27215. }
  27216. }
  27217. };
  27218. },
  27219. // Memory management for AnimationAction objects
  27220. _isActiveAction: function ( action ) {
  27221. const index = action._cacheIndex;
  27222. return index !== null && index < this._nActiveActions;
  27223. },
  27224. _addInactiveAction: function ( action, clipUuid, rootUuid ) {
  27225. const actions = this._actions,
  27226. actionsByClip = this._actionsByClip;
  27227. let actionsForClip = actionsByClip[ clipUuid ];
  27228. if ( actionsForClip === undefined ) {
  27229. actionsForClip = {
  27230. knownActions: [ action ],
  27231. actionByRoot: {}
  27232. };
  27233. action._byClipCacheIndex = 0;
  27234. actionsByClip[ clipUuid ] = actionsForClip;
  27235. } else {
  27236. const knownActions = actionsForClip.knownActions;
  27237. action._byClipCacheIndex = knownActions.length;
  27238. knownActions.push( action );
  27239. }
  27240. action._cacheIndex = actions.length;
  27241. actions.push( action );
  27242. actionsForClip.actionByRoot[ rootUuid ] = action;
  27243. },
  27244. _removeInactiveAction: function ( action ) {
  27245. const actions = this._actions,
  27246. lastInactiveAction = actions[ actions.length - 1 ],
  27247. cacheIndex = action._cacheIndex;
  27248. lastInactiveAction._cacheIndex = cacheIndex;
  27249. actions[ cacheIndex ] = lastInactiveAction;
  27250. actions.pop();
  27251. action._cacheIndex = null;
  27252. const clipUuid = action._clip.uuid,
  27253. actionsByClip = this._actionsByClip,
  27254. actionsForClip = actionsByClip[ clipUuid ],
  27255. knownActionsForClip = actionsForClip.knownActions,
  27256. lastKnownAction =
  27257. knownActionsForClip[ knownActionsForClip.length - 1 ],
  27258. byClipCacheIndex = action._byClipCacheIndex;
  27259. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  27260. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  27261. knownActionsForClip.pop();
  27262. action._byClipCacheIndex = null;
  27263. const actionByRoot = actionsForClip.actionByRoot,
  27264. rootUuid = ( action._localRoot || this._root ).uuid;
  27265. delete actionByRoot[ rootUuid ];
  27266. if ( knownActionsForClip.length === 0 ) {
  27267. delete actionsByClip[ clipUuid ];
  27268. }
  27269. this._removeInactiveBindingsForAction( action );
  27270. },
  27271. _removeInactiveBindingsForAction: function ( action ) {
  27272. const bindings = action._propertyBindings;
  27273. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  27274. const binding = bindings[ i ];
  27275. if ( -- binding.referenceCount === 0 ) {
  27276. this._removeInactiveBinding( binding );
  27277. }
  27278. }
  27279. },
  27280. _lendAction: function ( action ) {
  27281. // [ active actions | inactive actions ]
  27282. // [ active actions >| inactive actions ]
  27283. // s a
  27284. // <-swap->
  27285. // a s
  27286. const actions = this._actions,
  27287. prevIndex = action._cacheIndex,
  27288. lastActiveIndex = this._nActiveActions ++,
  27289. firstInactiveAction = actions[ lastActiveIndex ];
  27290. action._cacheIndex = lastActiveIndex;
  27291. actions[ lastActiveIndex ] = action;
  27292. firstInactiveAction._cacheIndex = prevIndex;
  27293. actions[ prevIndex ] = firstInactiveAction;
  27294. },
  27295. _takeBackAction: function ( action ) {
  27296. // [ active actions | inactive actions ]
  27297. // [ active actions |< inactive actions ]
  27298. // a s
  27299. // <-swap->
  27300. // s a
  27301. const actions = this._actions,
  27302. prevIndex = action._cacheIndex,
  27303. firstInactiveIndex = -- this._nActiveActions,
  27304. lastActiveAction = actions[ firstInactiveIndex ];
  27305. action._cacheIndex = firstInactiveIndex;
  27306. actions[ firstInactiveIndex ] = action;
  27307. lastActiveAction._cacheIndex = prevIndex;
  27308. actions[ prevIndex ] = lastActiveAction;
  27309. },
  27310. // Memory management for PropertyMixer objects
  27311. _addInactiveBinding: function ( binding, rootUuid, trackName ) {
  27312. const bindingsByRoot = this._bindingsByRootAndName,
  27313. bindings = this._bindings;
  27314. let bindingByName = bindingsByRoot[ rootUuid ];
  27315. if ( bindingByName === undefined ) {
  27316. bindingByName = {};
  27317. bindingsByRoot[ rootUuid ] = bindingByName;
  27318. }
  27319. bindingByName[ trackName ] = binding;
  27320. binding._cacheIndex = bindings.length;
  27321. bindings.push( binding );
  27322. },
  27323. _removeInactiveBinding: function ( binding ) {
  27324. const bindings = this._bindings,
  27325. propBinding = binding.binding,
  27326. rootUuid = propBinding.rootNode.uuid,
  27327. trackName = propBinding.path,
  27328. bindingsByRoot = this._bindingsByRootAndName,
  27329. bindingByName = bindingsByRoot[ rootUuid ],
  27330. lastInactiveBinding = bindings[ bindings.length - 1 ],
  27331. cacheIndex = binding._cacheIndex;
  27332. lastInactiveBinding._cacheIndex = cacheIndex;
  27333. bindings[ cacheIndex ] = lastInactiveBinding;
  27334. bindings.pop();
  27335. delete bindingByName[ trackName ];
  27336. if ( Object.keys( bindingByName ).length === 0 ) {
  27337. delete bindingsByRoot[ rootUuid ];
  27338. }
  27339. },
  27340. _lendBinding: function ( binding ) {
  27341. const bindings = this._bindings,
  27342. prevIndex = binding._cacheIndex,
  27343. lastActiveIndex = this._nActiveBindings ++,
  27344. firstInactiveBinding = bindings[ lastActiveIndex ];
  27345. binding._cacheIndex = lastActiveIndex;
  27346. bindings[ lastActiveIndex ] = binding;
  27347. firstInactiveBinding._cacheIndex = prevIndex;
  27348. bindings[ prevIndex ] = firstInactiveBinding;
  27349. },
  27350. _takeBackBinding: function ( binding ) {
  27351. const bindings = this._bindings,
  27352. prevIndex = binding._cacheIndex,
  27353. firstInactiveIndex = -- this._nActiveBindings,
  27354. lastActiveBinding = bindings[ firstInactiveIndex ];
  27355. binding._cacheIndex = firstInactiveIndex;
  27356. bindings[ firstInactiveIndex ] = binding;
  27357. lastActiveBinding._cacheIndex = prevIndex;
  27358. bindings[ prevIndex ] = lastActiveBinding;
  27359. },
  27360. // Memory management of Interpolants for weight and time scale
  27361. _lendControlInterpolant: function () {
  27362. const interpolants = this._controlInterpolants,
  27363. lastActiveIndex = this._nActiveControlInterpolants ++;
  27364. let interpolant = interpolants[ lastActiveIndex ];
  27365. if ( interpolant === undefined ) {
  27366. interpolant = new LinearInterpolant(
  27367. new Float32Array( 2 ), new Float32Array( 2 ),
  27368. 1, this._controlInterpolantsResultBuffer );
  27369. interpolant.__cacheIndex = lastActiveIndex;
  27370. interpolants[ lastActiveIndex ] = interpolant;
  27371. }
  27372. return interpolant;
  27373. },
  27374. _takeBackControlInterpolant: function ( interpolant ) {
  27375. const interpolants = this._controlInterpolants,
  27376. prevIndex = interpolant.__cacheIndex,
  27377. firstInactiveIndex = -- this._nActiveControlInterpolants,
  27378. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  27379. interpolant.__cacheIndex = firstInactiveIndex;
  27380. interpolants[ firstInactiveIndex ] = interpolant;
  27381. lastActiveInterpolant.__cacheIndex = prevIndex;
  27382. interpolants[ prevIndex ] = lastActiveInterpolant;
  27383. },
  27384. _controlInterpolantsResultBuffer: new Float32Array( 1 ),
  27385. // return an action for a clip optionally using a custom root target
  27386. // object (this method allocates a lot of dynamic memory in case a
  27387. // previously unknown clip/root combination is specified)
  27388. clipAction: function ( clip, optionalRoot, blendMode ) {
  27389. const root = optionalRoot || this._root,
  27390. rootUuid = root.uuid;
  27391. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  27392. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  27393. const actionsForClip = this._actionsByClip[ clipUuid ];
  27394. let prototypeAction = null;
  27395. if ( blendMode === undefined ) {
  27396. if ( clipObject !== null ) {
  27397. blendMode = clipObject.blendMode;
  27398. } else {
  27399. blendMode = NormalAnimationBlendMode;
  27400. }
  27401. }
  27402. if ( actionsForClip !== undefined ) {
  27403. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  27404. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  27405. return existingAction;
  27406. }
  27407. // we know the clip, so we don't have to parse all
  27408. // the bindings again but can just copy
  27409. prototypeAction = actionsForClip.knownActions[ 0 ];
  27410. // also, take the clip from the prototype action
  27411. if ( clipObject === null )
  27412. clipObject = prototypeAction._clip;
  27413. }
  27414. // clip must be known when specified via string
  27415. if ( clipObject === null ) return null;
  27416. // allocate all resources required to run it
  27417. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  27418. this._bindAction( newAction, prototypeAction );
  27419. // and make the action known to the memory manager
  27420. this._addInactiveAction( newAction, clipUuid, rootUuid );
  27421. return newAction;
  27422. },
  27423. // get an existing action
  27424. existingAction: function ( clip, optionalRoot ) {
  27425. const root = optionalRoot || this._root,
  27426. rootUuid = root.uuid,
  27427. clipObject = typeof clip === 'string' ?
  27428. AnimationClip.findByName( root, clip ) : clip,
  27429. clipUuid = clipObject ? clipObject.uuid : clip,
  27430. actionsForClip = this._actionsByClip[ clipUuid ];
  27431. if ( actionsForClip !== undefined ) {
  27432. return actionsForClip.actionByRoot[ rootUuid ] || null;
  27433. }
  27434. return null;
  27435. },
  27436. // deactivates all previously scheduled actions
  27437. stopAllAction: function () {
  27438. const actions = this._actions,
  27439. nActions = this._nActiveActions;
  27440. for ( let i = nActions - 1; i >= 0; -- i ) {
  27441. actions[ i ].stop();
  27442. }
  27443. return this;
  27444. },
  27445. // advance the time and update apply the animation
  27446. update: function ( deltaTime ) {
  27447. deltaTime *= this.timeScale;
  27448. const actions = this._actions,
  27449. nActions = this._nActiveActions,
  27450. time = this.time += deltaTime,
  27451. timeDirection = Math.sign( deltaTime ),
  27452. accuIndex = this._accuIndex ^= 1;
  27453. // run active actions
  27454. for ( let i = 0; i !== nActions; ++ i ) {
  27455. const action = actions[ i ];
  27456. action._update( time, deltaTime, timeDirection, accuIndex );
  27457. }
  27458. // update scene graph
  27459. const bindings = this._bindings,
  27460. nBindings = this._nActiveBindings;
  27461. for ( let i = 0; i !== nBindings; ++ i ) {
  27462. bindings[ i ].apply( accuIndex );
  27463. }
  27464. return this;
  27465. },
  27466. // Allows you to seek to a specific time in an animation.
  27467. setTime: function ( timeInSeconds ) {
  27468. this.time = 0; // Zero out time attribute for AnimationMixer object;
  27469. for ( let i = 0; i < this._actions.length; i ++ ) {
  27470. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  27471. }
  27472. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  27473. },
  27474. // return this mixer's root target object
  27475. getRoot: function () {
  27476. return this._root;
  27477. },
  27478. // free all resources specific to a particular clip
  27479. uncacheClip: function ( clip ) {
  27480. const actions = this._actions,
  27481. clipUuid = clip.uuid,
  27482. actionsByClip = this._actionsByClip,
  27483. actionsForClip = actionsByClip[ clipUuid ];
  27484. if ( actionsForClip !== undefined ) {
  27485. // note: just calling _removeInactiveAction would mess up the
  27486. // iteration state and also require updating the state we can
  27487. // just throw away
  27488. const actionsToRemove = actionsForClip.knownActions;
  27489. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  27490. const action = actionsToRemove[ i ];
  27491. this._deactivateAction( action );
  27492. const cacheIndex = action._cacheIndex,
  27493. lastInactiveAction = actions[ actions.length - 1 ];
  27494. action._cacheIndex = null;
  27495. action._byClipCacheIndex = null;
  27496. lastInactiveAction._cacheIndex = cacheIndex;
  27497. actions[ cacheIndex ] = lastInactiveAction;
  27498. actions.pop();
  27499. this._removeInactiveBindingsForAction( action );
  27500. }
  27501. delete actionsByClip[ clipUuid ];
  27502. }
  27503. },
  27504. // free all resources specific to a particular root target object
  27505. uncacheRoot: function ( root ) {
  27506. const rootUuid = root.uuid,
  27507. actionsByClip = this._actionsByClip;
  27508. for ( const clipUuid in actionsByClip ) {
  27509. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  27510. action = actionByRoot[ rootUuid ];
  27511. if ( action !== undefined ) {
  27512. this._deactivateAction( action );
  27513. this._removeInactiveAction( action );
  27514. }
  27515. }
  27516. const bindingsByRoot = this._bindingsByRootAndName,
  27517. bindingByName = bindingsByRoot[ rootUuid ];
  27518. if ( bindingByName !== undefined ) {
  27519. for ( const trackName in bindingByName ) {
  27520. const binding = bindingByName[ trackName ];
  27521. binding.restoreOriginalState();
  27522. this._removeInactiveBinding( binding );
  27523. }
  27524. }
  27525. },
  27526. // remove a targeted clip from the cache
  27527. uncacheAction: function ( clip, optionalRoot ) {
  27528. const action = this.existingAction( clip, optionalRoot );
  27529. if ( action !== null ) {
  27530. this._deactivateAction( action );
  27531. this._removeInactiveAction( action );
  27532. }
  27533. }
  27534. } );
  27535. class Uniform {
  27536. constructor( value ) {
  27537. if ( typeof value === 'string' ) {
  27538. console.warn( 'THREE.Uniform: Type parameter is no longer needed.' );
  27539. value = arguments[ 1 ];
  27540. }
  27541. this.value = value;
  27542. }
  27543. clone() {
  27544. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  27545. }
  27546. }
  27547. function InstancedInterleavedBuffer( array, stride, meshPerAttribute ) {
  27548. InterleavedBuffer.call( this, array, stride );
  27549. this.meshPerAttribute = meshPerAttribute || 1;
  27550. }
  27551. InstancedInterleavedBuffer.prototype = Object.assign( Object.create( InterleavedBuffer.prototype ), {
  27552. constructor: InstancedInterleavedBuffer,
  27553. isInstancedInterleavedBuffer: true,
  27554. copy: function ( source ) {
  27555. InterleavedBuffer.prototype.copy.call( this, source );
  27556. this.meshPerAttribute = source.meshPerAttribute;
  27557. return this;
  27558. },
  27559. clone: function ( data ) {
  27560. const ib = InterleavedBuffer.prototype.clone.call( this, data );
  27561. ib.meshPerAttribute = this.meshPerAttribute;
  27562. return ib;
  27563. },
  27564. toJSON: function ( data ) {
  27565. const json = InterleavedBuffer.prototype.toJSON.call( this, data );
  27566. json.isInstancedInterleavedBuffer = true;
  27567. json.meshPerAttribute = this.meshPerAttribute;
  27568. return json;
  27569. }
  27570. } );
  27571. function GLBufferAttribute( buffer, type, itemSize, elementSize, count ) {
  27572. this.buffer = buffer;
  27573. this.type = type;
  27574. this.itemSize = itemSize;
  27575. this.elementSize = elementSize;
  27576. this.count = count;
  27577. this.version = 0;
  27578. }
  27579. Object.defineProperty( GLBufferAttribute.prototype, 'needsUpdate', {
  27580. set: function ( value ) {
  27581. if ( value === true ) this.version ++;
  27582. }
  27583. } );
  27584. Object.assign( GLBufferAttribute.prototype, {
  27585. isGLBufferAttribute: true,
  27586. setBuffer: function ( buffer ) {
  27587. this.buffer = buffer;
  27588. return this;
  27589. },
  27590. setType: function ( type, elementSize ) {
  27591. this.type = type;
  27592. this.elementSize = elementSize;
  27593. return this;
  27594. },
  27595. setItemSize: function ( itemSize ) {
  27596. this.itemSize = itemSize;
  27597. return this;
  27598. },
  27599. setCount: function ( count ) {
  27600. this.count = count;
  27601. return this;
  27602. },
  27603. } );
  27604. function Raycaster( origin, direction, near, far ) {
  27605. this.ray = new Ray( origin, direction );
  27606. // direction is assumed to be normalized (for accurate distance calculations)
  27607. this.near = near || 0;
  27608. this.far = far || Infinity;
  27609. this.camera = null;
  27610. this.layers = new Layers();
  27611. this.params = {
  27612. Mesh: {},
  27613. Line: { threshold: 1 },
  27614. LOD: {},
  27615. Points: { threshold: 1 },
  27616. Sprite: {}
  27617. };
  27618. Object.defineProperties( this.params, {
  27619. PointCloud: {
  27620. get: function () {
  27621. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  27622. return this.Points;
  27623. }
  27624. }
  27625. } );
  27626. }
  27627. function ascSort( a, b ) {
  27628. return a.distance - b.distance;
  27629. }
  27630. function intersectObject( object, raycaster, intersects, recursive ) {
  27631. if ( object.layers.test( raycaster.layers ) ) {
  27632. object.raycast( raycaster, intersects );
  27633. }
  27634. if ( recursive === true ) {
  27635. const children = object.children;
  27636. for ( let i = 0, l = children.length; i < l; i ++ ) {
  27637. intersectObject( children[ i ], raycaster, intersects, true );
  27638. }
  27639. }
  27640. }
  27641. Object.assign( Raycaster.prototype, {
  27642. set: function ( origin, direction ) {
  27643. // direction is assumed to be normalized (for accurate distance calculations)
  27644. this.ray.set( origin, direction );
  27645. },
  27646. setFromCamera: function ( coords, camera ) {
  27647. if ( camera && camera.isPerspectiveCamera ) {
  27648. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  27649. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  27650. this.camera = camera;
  27651. } else if ( camera && camera.isOrthographicCamera ) {
  27652. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  27653. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  27654. this.camera = camera;
  27655. } else {
  27656. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  27657. }
  27658. },
  27659. intersectObject: function ( object, recursive, optionalTarget ) {
  27660. const intersects = optionalTarget || [];
  27661. intersectObject( object, this, intersects, recursive );
  27662. intersects.sort( ascSort );
  27663. return intersects;
  27664. },
  27665. intersectObjects: function ( objects, recursive, optionalTarget ) {
  27666. const intersects = optionalTarget || [];
  27667. if ( Array.isArray( objects ) === false ) {
  27668. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  27669. return intersects;
  27670. }
  27671. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  27672. intersectObject( objects[ i ], this, intersects, recursive );
  27673. }
  27674. intersects.sort( ascSort );
  27675. return intersects;
  27676. }
  27677. } );
  27678. /**
  27679. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  27680. *
  27681. * The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
  27682. * The azimuthal angle (theta) is measured from the positive z-axis.
  27683. */
  27684. class Spherical {
  27685. constructor( radius = 1, phi = 0, theta = 0 ) {
  27686. this.radius = radius;
  27687. this.phi = phi; // polar angle
  27688. this.theta = theta; // azimuthal angle
  27689. return this;
  27690. }
  27691. set( radius, phi, theta ) {
  27692. this.radius = radius;
  27693. this.phi = phi;
  27694. this.theta = theta;
  27695. return this;
  27696. }
  27697. clone() {
  27698. return new this.constructor().copy( this );
  27699. }
  27700. copy( other ) {
  27701. this.radius = other.radius;
  27702. this.phi = other.phi;
  27703. this.theta = other.theta;
  27704. return this;
  27705. }
  27706. // restrict phi to be betwee EPS and PI-EPS
  27707. makeSafe() {
  27708. const EPS = 0.000001;
  27709. this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
  27710. return this;
  27711. }
  27712. setFromVector3( v ) {
  27713. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27714. }
  27715. setFromCartesianCoords( x, y, z ) {
  27716. this.radius = Math.sqrt( x * x + y * y + z * z );
  27717. if ( this.radius === 0 ) {
  27718. this.theta = 0;
  27719. this.phi = 0;
  27720. } else {
  27721. this.theta = Math.atan2( x, z );
  27722. this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
  27723. }
  27724. return this;
  27725. }
  27726. }
  27727. /**
  27728. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  27729. */
  27730. class Cylindrical {
  27731. constructor( radius, theta, y ) {
  27732. this.radius = ( radius !== undefined ) ? radius : 1.0; // distance from the origin to a point in the x-z plane
  27733. this.theta = ( theta !== undefined ) ? theta : 0; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  27734. this.y = ( y !== undefined ) ? y : 0; // height above the x-z plane
  27735. return this;
  27736. }
  27737. set( radius, theta, y ) {
  27738. this.radius = radius;
  27739. this.theta = theta;
  27740. this.y = y;
  27741. return this;
  27742. }
  27743. clone() {
  27744. return new this.constructor().copy( this );
  27745. }
  27746. copy( other ) {
  27747. this.radius = other.radius;
  27748. this.theta = other.theta;
  27749. this.y = other.y;
  27750. return this;
  27751. }
  27752. setFromVector3( v ) {
  27753. return this.setFromCartesianCoords( v.x, v.y, v.z );
  27754. }
  27755. setFromCartesianCoords( x, y, z ) {
  27756. this.radius = Math.sqrt( x * x + z * z );
  27757. this.theta = Math.atan2( x, z );
  27758. this.y = y;
  27759. return this;
  27760. }
  27761. }
  27762. const _vector$8 = /*@__PURE__*/ new Vector2();
  27763. class Box2 {
  27764. constructor( min, max ) {
  27765. Object.defineProperty( this, 'isBox2', { value: true } );
  27766. this.min = ( min !== undefined ) ? min : new Vector2( + Infinity, + Infinity );
  27767. this.max = ( max !== undefined ) ? max : new Vector2( - Infinity, - Infinity );
  27768. }
  27769. set( min, max ) {
  27770. this.min.copy( min );
  27771. this.max.copy( max );
  27772. return this;
  27773. }
  27774. setFromPoints( points ) {
  27775. this.makeEmpty();
  27776. for ( let i = 0, il = points.length; i < il; i ++ ) {
  27777. this.expandByPoint( points[ i ] );
  27778. }
  27779. return this;
  27780. }
  27781. setFromCenterAndSize( center, size ) {
  27782. const halfSize = _vector$8.copy( size ).multiplyScalar( 0.5 );
  27783. this.min.copy( center ).sub( halfSize );
  27784. this.max.copy( center ).add( halfSize );
  27785. return this;
  27786. }
  27787. clone() {
  27788. return new this.constructor().copy( this );
  27789. }
  27790. copy( box ) {
  27791. this.min.copy( box.min );
  27792. this.max.copy( box.max );
  27793. return this;
  27794. }
  27795. makeEmpty() {
  27796. this.min.x = this.min.y = + Infinity;
  27797. this.max.x = this.max.y = - Infinity;
  27798. return this;
  27799. }
  27800. isEmpty() {
  27801. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  27802. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  27803. }
  27804. getCenter( target ) {
  27805. if ( target === undefined ) {
  27806. console.warn( 'THREE.Box2: .getCenter() target is now required' );
  27807. target = new Vector2();
  27808. }
  27809. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  27810. }
  27811. getSize( target ) {
  27812. if ( target === undefined ) {
  27813. console.warn( 'THREE.Box2: .getSize() target is now required' );
  27814. target = new Vector2();
  27815. }
  27816. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  27817. }
  27818. expandByPoint( point ) {
  27819. this.min.min( point );
  27820. this.max.max( point );
  27821. return this;
  27822. }
  27823. expandByVector( vector ) {
  27824. this.min.sub( vector );
  27825. this.max.add( vector );
  27826. return this;
  27827. }
  27828. expandByScalar( scalar ) {
  27829. this.min.addScalar( - scalar );
  27830. this.max.addScalar( scalar );
  27831. return this;
  27832. }
  27833. containsPoint( point ) {
  27834. return point.x < this.min.x || point.x > this.max.x ||
  27835. point.y < this.min.y || point.y > this.max.y ? false : true;
  27836. }
  27837. containsBox( box ) {
  27838. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  27839. this.min.y <= box.min.y && box.max.y <= this.max.y;
  27840. }
  27841. getParameter( point, target ) {
  27842. // This can potentially have a divide by zero if the box
  27843. // has a size dimension of 0.
  27844. if ( target === undefined ) {
  27845. console.warn( 'THREE.Box2: .getParameter() target is now required' );
  27846. target = new Vector2();
  27847. }
  27848. return target.set(
  27849. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  27850. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  27851. );
  27852. }
  27853. intersectsBox( box ) {
  27854. // using 4 splitting planes to rule out intersections
  27855. return box.max.x < this.min.x || box.min.x > this.max.x ||
  27856. box.max.y < this.min.y || box.min.y > this.max.y ? false : true;
  27857. }
  27858. clampPoint( point, target ) {
  27859. if ( target === undefined ) {
  27860. console.warn( 'THREE.Box2: .clampPoint() target is now required' );
  27861. target = new Vector2();
  27862. }
  27863. return target.copy( point ).clamp( this.min, this.max );
  27864. }
  27865. distanceToPoint( point ) {
  27866. const clampedPoint = _vector$8.copy( point ).clamp( this.min, this.max );
  27867. return clampedPoint.sub( point ).length();
  27868. }
  27869. intersect( box ) {
  27870. this.min.max( box.min );
  27871. this.max.min( box.max );
  27872. return this;
  27873. }
  27874. union( box ) {
  27875. this.min.min( box.min );
  27876. this.max.max( box.max );
  27877. return this;
  27878. }
  27879. translate( offset ) {
  27880. this.min.add( offset );
  27881. this.max.add( offset );
  27882. return this;
  27883. }
  27884. equals( box ) {
  27885. return box.min.equals( this.min ) && box.max.equals( this.max );
  27886. }
  27887. }
  27888. const _startP = /*@__PURE__*/ new Vector3();
  27889. const _startEnd = /*@__PURE__*/ new Vector3();
  27890. class Line3 {
  27891. constructor( start, end ) {
  27892. this.start = ( start !== undefined ) ? start : new Vector3();
  27893. this.end = ( end !== undefined ) ? end : new Vector3();
  27894. }
  27895. set( start, end ) {
  27896. this.start.copy( start );
  27897. this.end.copy( end );
  27898. return this;
  27899. }
  27900. clone() {
  27901. return new this.constructor().copy( this );
  27902. }
  27903. copy( line ) {
  27904. this.start.copy( line.start );
  27905. this.end.copy( line.end );
  27906. return this;
  27907. }
  27908. getCenter( target ) {
  27909. if ( target === undefined ) {
  27910. console.warn( 'THREE.Line3: .getCenter() target is now required' );
  27911. target = new Vector3();
  27912. }
  27913. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  27914. }
  27915. delta( target ) {
  27916. if ( target === undefined ) {
  27917. console.warn( 'THREE.Line3: .delta() target is now required' );
  27918. target = new Vector3();
  27919. }
  27920. return target.subVectors( this.end, this.start );
  27921. }
  27922. distanceSq() {
  27923. return this.start.distanceToSquared( this.end );
  27924. }
  27925. distance() {
  27926. return this.start.distanceTo( this.end );
  27927. }
  27928. at( t, target ) {
  27929. if ( target === undefined ) {
  27930. console.warn( 'THREE.Line3: .at() target is now required' );
  27931. target = new Vector3();
  27932. }
  27933. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27934. }
  27935. closestPointToPointParameter( point, clampToLine ) {
  27936. _startP.subVectors( point, this.start );
  27937. _startEnd.subVectors( this.end, this.start );
  27938. const startEnd2 = _startEnd.dot( _startEnd );
  27939. const startEnd_startP = _startEnd.dot( _startP );
  27940. let t = startEnd_startP / startEnd2;
  27941. if ( clampToLine ) {
  27942. t = MathUtils.clamp( t, 0, 1 );
  27943. }
  27944. return t;
  27945. }
  27946. closestPointToPoint( point, clampToLine, target ) {
  27947. const t = this.closestPointToPointParameter( point, clampToLine );
  27948. if ( target === undefined ) {
  27949. console.warn( 'THREE.Line3: .closestPointToPoint() target is now required' );
  27950. target = new Vector3();
  27951. }
  27952. return this.delta( target ).multiplyScalar( t ).add( this.start );
  27953. }
  27954. applyMatrix4( matrix ) {
  27955. this.start.applyMatrix4( matrix );
  27956. this.end.applyMatrix4( matrix );
  27957. return this;
  27958. }
  27959. equals( line ) {
  27960. return line.start.equals( this.start ) && line.end.equals( this.end );
  27961. }
  27962. }
  27963. function ImmediateRenderObject( material ) {
  27964. Object3D.call( this );
  27965. this.material = material;
  27966. this.render = function ( /* renderCallback */ ) {};
  27967. this.hasPositions = false;
  27968. this.hasNormals = false;
  27969. this.hasColors = false;
  27970. this.hasUvs = false;
  27971. this.positionArray = null;
  27972. this.normalArray = null;
  27973. this.colorArray = null;
  27974. this.uvArray = null;
  27975. this.count = 0;
  27976. }
  27977. ImmediateRenderObject.prototype = Object.create( Object3D.prototype );
  27978. ImmediateRenderObject.prototype.constructor = ImmediateRenderObject;
  27979. ImmediateRenderObject.prototype.isImmediateRenderObject = true;
  27980. const _vector$9 = /*@__PURE__*/ new Vector3();
  27981. class SpotLightHelper extends Object3D {
  27982. constructor( light, color ) {
  27983. super();
  27984. this.light = light;
  27985. this.light.updateMatrixWorld();
  27986. this.matrix = light.matrixWorld;
  27987. this.matrixAutoUpdate = false;
  27988. this.color = color;
  27989. const geometry = new BufferGeometry();
  27990. const positions = [
  27991. 0, 0, 0, 0, 0, 1,
  27992. 0, 0, 0, 1, 0, 1,
  27993. 0, 0, 0, - 1, 0, 1,
  27994. 0, 0, 0, 0, 1, 1,
  27995. 0, 0, 0, 0, - 1, 1
  27996. ];
  27997. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  27998. const p1 = ( i / l ) * Math.PI * 2;
  27999. const p2 = ( j / l ) * Math.PI * 2;
  28000. positions.push(
  28001. Math.cos( p1 ), Math.sin( p1 ), 1,
  28002. Math.cos( p2 ), Math.sin( p2 ), 1
  28003. );
  28004. }
  28005. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28006. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28007. this.cone = new LineSegments( geometry, material );
  28008. this.add( this.cone );
  28009. this.update();
  28010. }
  28011. dispose() {
  28012. this.cone.geometry.dispose();
  28013. this.cone.material.dispose();
  28014. }
  28015. update() {
  28016. this.light.updateMatrixWorld();
  28017. const coneLength = this.light.distance ? this.light.distance : 1000;
  28018. const coneWidth = coneLength * Math.tan( this.light.angle );
  28019. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  28020. _vector$9.setFromMatrixPosition( this.light.target.matrixWorld );
  28021. this.cone.lookAt( _vector$9 );
  28022. if ( this.color !== undefined ) {
  28023. this.cone.material.color.set( this.color );
  28024. } else {
  28025. this.cone.material.color.copy( this.light.color );
  28026. }
  28027. }
  28028. }
  28029. const _vector$a = /*@__PURE__*/ new Vector3();
  28030. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  28031. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  28032. class SkeletonHelper extends LineSegments {
  28033. constructor( object ) {
  28034. const bones = getBoneList( object );
  28035. const geometry = new BufferGeometry();
  28036. const vertices = [];
  28037. const colors = [];
  28038. const color1 = new Color( 0, 0, 1 );
  28039. const color2 = new Color( 0, 1, 0 );
  28040. for ( let i = 0; i < bones.length; i ++ ) {
  28041. const bone = bones[ i ];
  28042. if ( bone.parent && bone.parent.isBone ) {
  28043. vertices.push( 0, 0, 0 );
  28044. vertices.push( 0, 0, 0 );
  28045. colors.push( color1.r, color1.g, color1.b );
  28046. colors.push( color2.r, color2.g, color2.b );
  28047. }
  28048. }
  28049. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28050. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28051. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  28052. super( geometry, material );
  28053. this.type = 'SkeletonHelper';
  28054. this.isSkeletonHelper = true;
  28055. this.root = object;
  28056. this.bones = bones;
  28057. this.matrix = object.matrixWorld;
  28058. this.matrixAutoUpdate = false;
  28059. }
  28060. updateMatrixWorld( force ) {
  28061. const bones = this.bones;
  28062. const geometry = this.geometry;
  28063. const position = geometry.getAttribute( 'position' );
  28064. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  28065. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  28066. const bone = bones[ i ];
  28067. if ( bone.parent && bone.parent.isBone ) {
  28068. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  28069. _vector$a.setFromMatrixPosition( _boneMatrix );
  28070. position.setXYZ( j, _vector$a.x, _vector$a.y, _vector$a.z );
  28071. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  28072. _vector$a.setFromMatrixPosition( _boneMatrix );
  28073. position.setXYZ( j + 1, _vector$a.x, _vector$a.y, _vector$a.z );
  28074. j += 2;
  28075. }
  28076. }
  28077. geometry.getAttribute( 'position' ).needsUpdate = true;
  28078. super.updateMatrixWorld( force );
  28079. }
  28080. }
  28081. function getBoneList( object ) {
  28082. const boneList = [];
  28083. if ( object && object.isBone ) {
  28084. boneList.push( object );
  28085. }
  28086. for ( let i = 0; i < object.children.length; i ++ ) {
  28087. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  28088. }
  28089. return boneList;
  28090. }
  28091. class PointLightHelper extends Mesh {
  28092. constructor( light, sphereSize, color ) {
  28093. const geometry = new SphereBufferGeometry( sphereSize, 4, 2 );
  28094. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28095. super( geometry, material );
  28096. this.light = light;
  28097. this.light.updateMatrixWorld();
  28098. this.color = color;
  28099. this.type = 'PointLightHelper';
  28100. this.matrix = this.light.matrixWorld;
  28101. this.matrixAutoUpdate = false;
  28102. this.update();
  28103. /*
  28104. // TODO: delete this comment?
  28105. const distanceGeometry = new THREE.IcosahedronBufferGeometry( 1, 2 );
  28106. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  28107. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  28108. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  28109. const d = light.distance;
  28110. if ( d === 0.0 ) {
  28111. this.lightDistance.visible = false;
  28112. } else {
  28113. this.lightDistance.scale.set( d, d, d );
  28114. }
  28115. this.add( this.lightDistance );
  28116. */
  28117. }
  28118. dispose() {
  28119. this.geometry.dispose();
  28120. this.material.dispose();
  28121. }
  28122. update() {
  28123. if ( this.color !== undefined ) {
  28124. this.material.color.set( this.color );
  28125. } else {
  28126. this.material.color.copy( this.light.color );
  28127. }
  28128. /*
  28129. const d = this.light.distance;
  28130. if ( d === 0.0 ) {
  28131. this.lightDistance.visible = false;
  28132. } else {
  28133. this.lightDistance.visible = true;
  28134. this.lightDistance.scale.set( d, d, d );
  28135. }
  28136. */
  28137. }
  28138. }
  28139. const _vector$b = /*@__PURE__*/ new Vector3();
  28140. const _color1 = /*@__PURE__*/ new Color();
  28141. const _color2 = /*@__PURE__*/ new Color();
  28142. class HemisphereLightHelper extends Object3D {
  28143. constructor( light, size, color ) {
  28144. super();
  28145. this.light = light;
  28146. this.light.updateMatrixWorld();
  28147. this.matrix = light.matrixWorld;
  28148. this.matrixAutoUpdate = false;
  28149. this.color = color;
  28150. const geometry = new OctahedronBufferGeometry( size );
  28151. geometry.rotateY( Math.PI * 0.5 );
  28152. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  28153. if ( this.color === undefined ) this.material.vertexColors = true;
  28154. const position = geometry.getAttribute( 'position' );
  28155. const colors = new Float32Array( position.count * 3 );
  28156. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  28157. this.add( new Mesh( geometry, this.material ) );
  28158. this.update();
  28159. }
  28160. dispose() {
  28161. this.children[ 0 ].geometry.dispose();
  28162. this.children[ 0 ].material.dispose();
  28163. }
  28164. update() {
  28165. const mesh = this.children[ 0 ];
  28166. if ( this.color !== undefined ) {
  28167. this.material.color.set( this.color );
  28168. } else {
  28169. const colors = mesh.geometry.getAttribute( 'color' );
  28170. _color1.copy( this.light.color );
  28171. _color2.copy( this.light.groundColor );
  28172. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  28173. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  28174. colors.setXYZ( i, color.r, color.g, color.b );
  28175. }
  28176. colors.needsUpdate = true;
  28177. }
  28178. mesh.lookAt( _vector$b.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  28179. }
  28180. }
  28181. class GridHelper extends LineSegments {
  28182. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  28183. color1 = new Color( color1 );
  28184. color2 = new Color( color2 );
  28185. const center = divisions / 2;
  28186. const step = size / divisions;
  28187. const halfSize = size / 2;
  28188. const vertices = [], colors = [];
  28189. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  28190. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  28191. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  28192. const color = i === center ? color1 : color2;
  28193. color.toArray( colors, j ); j += 3;
  28194. color.toArray( colors, j ); j += 3;
  28195. color.toArray( colors, j ); j += 3;
  28196. color.toArray( colors, j ); j += 3;
  28197. }
  28198. const geometry = new BufferGeometry();
  28199. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28200. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28201. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28202. super( geometry, material );
  28203. this.type = 'GridHelper';
  28204. }
  28205. }
  28206. class PolarGridHelper extends LineSegments {
  28207. constructor( radius = 10, radials = 16, circles = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  28208. color1 = new Color( color1 );
  28209. color2 = new Color( color2 );
  28210. const vertices = [];
  28211. const colors = [];
  28212. // create the radials
  28213. for ( let i = 0; i <= radials; i ++ ) {
  28214. const v = ( i / radials ) * ( Math.PI * 2 );
  28215. const x = Math.sin( v ) * radius;
  28216. const z = Math.cos( v ) * radius;
  28217. vertices.push( 0, 0, 0 );
  28218. vertices.push( x, 0, z );
  28219. const color = ( i & 1 ) ? color1 : color2;
  28220. colors.push( color.r, color.g, color.b );
  28221. colors.push( color.r, color.g, color.b );
  28222. }
  28223. // create the circles
  28224. for ( let i = 0; i <= circles; i ++ ) {
  28225. const color = ( i & 1 ) ? color1 : color2;
  28226. const r = radius - ( radius / circles * i );
  28227. for ( let j = 0; j < divisions; j ++ ) {
  28228. // first vertex
  28229. let v = ( j / divisions ) * ( Math.PI * 2 );
  28230. let x = Math.sin( v ) * r;
  28231. let z = Math.cos( v ) * r;
  28232. vertices.push( x, 0, z );
  28233. colors.push( color.r, color.g, color.b );
  28234. // second vertex
  28235. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  28236. x = Math.sin( v ) * r;
  28237. z = Math.cos( v ) * r;
  28238. vertices.push( x, 0, z );
  28239. colors.push( color.r, color.g, color.b );
  28240. }
  28241. }
  28242. const geometry = new BufferGeometry();
  28243. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28244. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28245. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28246. super( geometry, material );
  28247. this.type = 'PolarGridHelper';
  28248. }
  28249. }
  28250. const _v1$6 = /*@__PURE__*/ new Vector3();
  28251. const _v2$3 = /*@__PURE__*/ new Vector3();
  28252. const _v3$1 = /*@__PURE__*/ new Vector3();
  28253. class DirectionalLightHelper extends Object3D {
  28254. constructor( light, size, color ) {
  28255. super();
  28256. this.light = light;
  28257. this.light.updateMatrixWorld();
  28258. this.matrix = light.matrixWorld;
  28259. this.matrixAutoUpdate = false;
  28260. this.color = color;
  28261. if ( size === undefined ) size = 1;
  28262. let geometry = new BufferGeometry();
  28263. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  28264. - size, size, 0,
  28265. size, size, 0,
  28266. size, - size, 0,
  28267. - size, - size, 0,
  28268. - size, size, 0
  28269. ], 3 ) );
  28270. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  28271. this.lightPlane = new Line( geometry, material );
  28272. this.add( this.lightPlane );
  28273. geometry = new BufferGeometry();
  28274. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  28275. this.targetLine = new Line( geometry, material );
  28276. this.add( this.targetLine );
  28277. this.update();
  28278. }
  28279. dispose() {
  28280. this.lightPlane.geometry.dispose();
  28281. this.lightPlane.material.dispose();
  28282. this.targetLine.geometry.dispose();
  28283. this.targetLine.material.dispose();
  28284. }
  28285. update() {
  28286. _v1$6.setFromMatrixPosition( this.light.matrixWorld );
  28287. _v2$3.setFromMatrixPosition( this.light.target.matrixWorld );
  28288. _v3$1.subVectors( _v2$3, _v1$6 );
  28289. this.lightPlane.lookAt( _v2$3 );
  28290. if ( this.color !== undefined ) {
  28291. this.lightPlane.material.color.set( this.color );
  28292. this.targetLine.material.color.set( this.color );
  28293. } else {
  28294. this.lightPlane.material.color.copy( this.light.color );
  28295. this.targetLine.material.color.copy( this.light.color );
  28296. }
  28297. this.targetLine.lookAt( _v2$3 );
  28298. this.targetLine.scale.z = _v3$1.length();
  28299. }
  28300. }
  28301. const _vector$c = /*@__PURE__*/ new Vector3();
  28302. const _camera = /*@__PURE__*/ new Camera();
  28303. /**
  28304. * - shows frustum, line of sight and up of the camera
  28305. * - suitable for fast updates
  28306. * - based on frustum visualization in lightgl.js shadowmap example
  28307. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  28308. */
  28309. class CameraHelper extends LineSegments {
  28310. constructor( camera ) {
  28311. const geometry = new BufferGeometry();
  28312. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  28313. const vertices = [];
  28314. const colors = [];
  28315. const pointMap = {};
  28316. // colors
  28317. const colorFrustum = new Color( 0xffaa00 );
  28318. const colorCone = new Color( 0xff0000 );
  28319. const colorUp = new Color( 0x00aaff );
  28320. const colorTarget = new Color( 0xffffff );
  28321. const colorCross = new Color( 0x333333 );
  28322. // near
  28323. addLine( 'n1', 'n2', colorFrustum );
  28324. addLine( 'n2', 'n4', colorFrustum );
  28325. addLine( 'n4', 'n3', colorFrustum );
  28326. addLine( 'n3', 'n1', colorFrustum );
  28327. // far
  28328. addLine( 'f1', 'f2', colorFrustum );
  28329. addLine( 'f2', 'f4', colorFrustum );
  28330. addLine( 'f4', 'f3', colorFrustum );
  28331. addLine( 'f3', 'f1', colorFrustum );
  28332. // sides
  28333. addLine( 'n1', 'f1', colorFrustum );
  28334. addLine( 'n2', 'f2', colorFrustum );
  28335. addLine( 'n3', 'f3', colorFrustum );
  28336. addLine( 'n4', 'f4', colorFrustum );
  28337. // cone
  28338. addLine( 'p', 'n1', colorCone );
  28339. addLine( 'p', 'n2', colorCone );
  28340. addLine( 'p', 'n3', colorCone );
  28341. addLine( 'p', 'n4', colorCone );
  28342. // up
  28343. addLine( 'u1', 'u2', colorUp );
  28344. addLine( 'u2', 'u3', colorUp );
  28345. addLine( 'u3', 'u1', colorUp );
  28346. // target
  28347. addLine( 'c', 't', colorTarget );
  28348. addLine( 'p', 'c', colorCross );
  28349. // cross
  28350. addLine( 'cn1', 'cn2', colorCross );
  28351. addLine( 'cn3', 'cn4', colorCross );
  28352. addLine( 'cf1', 'cf2', colorCross );
  28353. addLine( 'cf3', 'cf4', colorCross );
  28354. function addLine( a, b, color ) {
  28355. addPoint( a, color );
  28356. addPoint( b, color );
  28357. }
  28358. function addPoint( id, color ) {
  28359. vertices.push( 0, 0, 0 );
  28360. colors.push( color.r, color.g, color.b );
  28361. if ( pointMap[ id ] === undefined ) {
  28362. pointMap[ id ] = [];
  28363. }
  28364. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  28365. }
  28366. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28367. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28368. super( geometry, material );
  28369. this.type = 'CameraHelper';
  28370. this.camera = camera;
  28371. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  28372. this.matrix = camera.matrixWorld;
  28373. this.matrixAutoUpdate = false;
  28374. this.pointMap = pointMap;
  28375. this.update();
  28376. }
  28377. update() {
  28378. const geometry = this.geometry;
  28379. const pointMap = this.pointMap;
  28380. const w = 1, h = 1;
  28381. // we need just camera projection matrix inverse
  28382. // world matrix must be identity
  28383. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  28384. // center / target
  28385. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  28386. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  28387. // near
  28388. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  28389. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  28390. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  28391. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  28392. // far
  28393. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  28394. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  28395. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  28396. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  28397. // up
  28398. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  28399. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  28400. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  28401. // cross
  28402. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  28403. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  28404. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  28405. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  28406. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  28407. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  28408. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  28409. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  28410. geometry.getAttribute( 'position' ).needsUpdate = true;
  28411. }
  28412. }
  28413. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  28414. _vector$c.set( x, y, z ).unproject( camera );
  28415. const points = pointMap[ point ];
  28416. if ( points !== undefined ) {
  28417. const position = geometry.getAttribute( 'position' );
  28418. for ( let i = 0, l = points.length; i < l; i ++ ) {
  28419. position.setXYZ( points[ i ], _vector$c.x, _vector$c.y, _vector$c.z );
  28420. }
  28421. }
  28422. }
  28423. const _box$3 = /*@__PURE__*/ new Box3();
  28424. class BoxHelper extends LineSegments {
  28425. constructor( object, color = 0xffff00 ) {
  28426. const 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 ] );
  28427. const positions = new Float32Array( 8 * 3 );
  28428. const geometry = new BufferGeometry();
  28429. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28430. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  28431. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28432. this.object = object;
  28433. this.type = 'BoxHelper';
  28434. this.matrixAutoUpdate = false;
  28435. this.update();
  28436. }
  28437. update( object ) {
  28438. if ( object !== undefined ) {
  28439. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  28440. }
  28441. if ( this.object !== undefined ) {
  28442. _box$3.setFromObject( this.object );
  28443. }
  28444. if ( _box$3.isEmpty() ) return;
  28445. const min = _box$3.min;
  28446. const max = _box$3.max;
  28447. /*
  28448. 5____4
  28449. 1/___0/|
  28450. | 6__|_7
  28451. 2/___3/
  28452. 0: max.x, max.y, max.z
  28453. 1: min.x, max.y, max.z
  28454. 2: min.x, min.y, max.z
  28455. 3: max.x, min.y, max.z
  28456. 4: max.x, max.y, min.z
  28457. 5: min.x, max.y, min.z
  28458. 6: min.x, min.y, min.z
  28459. 7: max.x, min.y, min.z
  28460. */
  28461. const position = this.geometry.attributes.position;
  28462. const array = position.array;
  28463. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  28464. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  28465. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  28466. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  28467. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  28468. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  28469. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  28470. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  28471. position.needsUpdate = true;
  28472. this.geometry.computeBoundingSphere();
  28473. }
  28474. setFromObject( object ) {
  28475. this.object = object;
  28476. this.update();
  28477. return this;
  28478. }
  28479. copy( source ) {
  28480. LineSegments.prototype.copy.call( this, source );
  28481. this.object = source.object;
  28482. return this;
  28483. }
  28484. }
  28485. class Box3Helper extends LineSegments {
  28486. constructor( box, color = 0xffff00 ) {
  28487. const 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 ] );
  28488. const 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 ];
  28489. const geometry = new BufferGeometry();
  28490. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  28491. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28492. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28493. this.box = box;
  28494. this.type = 'Box3Helper';
  28495. this.geometry.computeBoundingSphere();
  28496. }
  28497. updateMatrixWorld( force ) {
  28498. const box = this.box;
  28499. if ( box.isEmpty() ) return;
  28500. box.getCenter( this.position );
  28501. box.getSize( this.scale );
  28502. this.scale.multiplyScalar( 0.5 );
  28503. super.updateMatrixWorld( force );
  28504. }
  28505. }
  28506. class PlaneHelper extends Line {
  28507. constructor( plane, size = 1, hex = 0xffff00 ) {
  28508. const color = hex;
  28509. const 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 ];
  28510. const geometry = new BufferGeometry();
  28511. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  28512. geometry.computeBoundingSphere();
  28513. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28514. this.type = 'PlaneHelper';
  28515. this.plane = plane;
  28516. this.size = size;
  28517. const positions2 = [ 1, 1, 1, - 1, 1, 1, - 1, - 1, 1, 1, 1, 1, - 1, - 1, 1, 1, - 1, 1 ];
  28518. const geometry2 = new BufferGeometry();
  28519. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  28520. geometry2.computeBoundingSphere();
  28521. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  28522. }
  28523. updateMatrixWorld( force ) {
  28524. let scale = - this.plane.constant;
  28525. if ( Math.abs( scale ) < 1e-8 ) scale = 1e-8; // sign does not matter
  28526. this.scale.set( 0.5 * this.size, 0.5 * this.size, scale );
  28527. this.children[ 0 ].material.side = ( scale < 0 ) ? BackSide : FrontSide; // renderer flips side when determinant < 0; flipping not wanted here
  28528. this.lookAt( this.plane.normal );
  28529. super.updateMatrixWorld( force );
  28530. }
  28531. }
  28532. const _axis = /*@__PURE__*/ new Vector3();
  28533. let _lineGeometry, _coneGeometry;
  28534. class ArrowHelper extends Object3D {
  28535. constructor( dir, origin, length, color, headLength, headWidth ) {
  28536. super();
  28537. // dir is assumed to be normalized
  28538. this.type = 'ArrowHelper';
  28539. if ( dir === undefined ) dir = new Vector3( 0, 0, 1 );
  28540. if ( origin === undefined ) origin = new Vector3( 0, 0, 0 );
  28541. if ( length === undefined ) length = 1;
  28542. if ( color === undefined ) color = 0xffff00;
  28543. if ( headLength === undefined ) headLength = 0.2 * length;
  28544. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28545. if ( _lineGeometry === undefined ) {
  28546. _lineGeometry = new BufferGeometry();
  28547. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  28548. _coneGeometry = new CylinderBufferGeometry( 0, 0.5, 1, 5, 1 );
  28549. _coneGeometry.translate( 0, - 0.5, 0 );
  28550. }
  28551. this.position.copy( origin );
  28552. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  28553. this.line.matrixAutoUpdate = false;
  28554. this.add( this.line );
  28555. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  28556. this.cone.matrixAutoUpdate = false;
  28557. this.add( this.cone );
  28558. this.setDirection( dir );
  28559. this.setLength( length, headLength, headWidth );
  28560. }
  28561. setDirection( dir ) {
  28562. // dir is assumed to be normalized
  28563. if ( dir.y > 0.99999 ) {
  28564. this.quaternion.set( 0, 0, 0, 1 );
  28565. } else if ( dir.y < - 0.99999 ) {
  28566. this.quaternion.set( 1, 0, 0, 0 );
  28567. } else {
  28568. _axis.set( dir.z, 0, - dir.x ).normalize();
  28569. const radians = Math.acos( dir.y );
  28570. this.quaternion.setFromAxisAngle( _axis, radians );
  28571. }
  28572. }
  28573. setLength( length, headLength, headWidth ) {
  28574. if ( headLength === undefined ) headLength = 0.2 * length;
  28575. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  28576. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  28577. this.line.updateMatrix();
  28578. this.cone.scale.set( headWidth, headLength, headWidth );
  28579. this.cone.position.y = length;
  28580. this.cone.updateMatrix();
  28581. }
  28582. setColor( color ) {
  28583. this.line.material.color.set( color );
  28584. this.cone.material.color.set( color );
  28585. }
  28586. copy( source ) {
  28587. super.copy( source, false );
  28588. this.line.copy( source.line );
  28589. this.cone.copy( source.cone );
  28590. return this;
  28591. }
  28592. }
  28593. class AxesHelper extends LineSegments {
  28594. constructor( size = 1 ) {
  28595. const vertices = [
  28596. 0, 0, 0, size, 0, 0,
  28597. 0, 0, 0, 0, size, 0,
  28598. 0, 0, 0, 0, 0, size
  28599. ];
  28600. const colors = [
  28601. 1, 0, 0, 1, 0.6, 0,
  28602. 0, 1, 0, 0.6, 1, 0,
  28603. 0, 0, 1, 0, 0.6, 1
  28604. ];
  28605. const geometry = new BufferGeometry();
  28606. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  28607. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  28608. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  28609. super( geometry, material );
  28610. this.type = 'AxesHelper';
  28611. }
  28612. }
  28613. const _floatView = new Float32Array( 1 );
  28614. const _int32View = new Int32Array( _floatView.buffer );
  28615. const DataUtils = {
  28616. // Converts float32 to float16 (stored as uint16 value).
  28617. toHalfFloat: function ( val ) {
  28618. // Source: http://gamedev.stackexchange.com/questions/17326/conversion-of-a-number-from-single-precision-floating-point-representation-to-a/17410#17410
  28619. /* This method is faster than the OpenEXR implementation (very often
  28620. * used, eg. in Ogre), with the additional benefit of rounding, inspired
  28621. * by James Tursa?s half-precision code. */
  28622. _floatView[ 0 ] = val;
  28623. const x = _int32View[ 0 ];
  28624. let bits = ( x >> 16 ) & 0x8000; /* Get the sign */
  28625. let m = ( x >> 12 ) & 0x07ff; /* Keep one extra bit for rounding */
  28626. const e = ( x >> 23 ) & 0xff; /* Using int is faster here */
  28627. /* If zero, or denormal, or exponent underflows too much for a denormal
  28628. * half, return signed zero. */
  28629. if ( e < 103 ) return bits;
  28630. /* If NaN, return NaN. If Inf or exponent overflow, return Inf. */
  28631. if ( e > 142 ) {
  28632. bits |= 0x7c00;
  28633. /* If exponent was 0xff and one mantissa bit was set, it means NaN,
  28634. * not Inf, so make sure we set one mantissa bit too. */
  28635. bits |= ( ( e == 255 ) ? 0 : 1 ) && ( x & 0x007fffff );
  28636. return bits;
  28637. }
  28638. /* If exponent underflows but not too much, return a denormal */
  28639. if ( e < 113 ) {
  28640. m |= 0x0800;
  28641. /* Extra rounding may overflow and set mantissa to 0 and exponent
  28642. * to 1, which is OK. */
  28643. bits |= ( m >> ( 114 - e ) ) + ( ( m >> ( 113 - e ) ) & 1 );
  28644. return bits;
  28645. }
  28646. bits |= ( ( e - 112 ) << 10 ) | ( m >> 1 );
  28647. /* Extra rounding. An overflow will set mantissa to 0 and increment
  28648. * the exponent, which is OK. */
  28649. bits += m & 1;
  28650. return bits;
  28651. }
  28652. };
  28653. const LOD_MIN = 4;
  28654. const LOD_MAX = 8;
  28655. const SIZE_MAX = Math.pow( 2, LOD_MAX );
  28656. // The standard deviations (radians) associated with the extra mips. These are
  28657. // chosen to approximate a Trowbridge-Reitz distribution function times the
  28658. // geometric shadowing function. These sigma values squared must match the
  28659. // variance #defines in cube_uv_reflection_fragment.glsl.js.
  28660. const EXTRA_LOD_SIGMA = [ 0.125, 0.215, 0.35, 0.446, 0.526, 0.582 ];
  28661. const TOTAL_LODS = LOD_MAX - LOD_MIN + 1 + EXTRA_LOD_SIGMA.length;
  28662. // The maximum length of the blur for loop. Smaller sigmas will use fewer
  28663. // samples and exit early, but not recompile the shader.
  28664. const MAX_SAMPLES = 20;
  28665. const ENCODINGS = {
  28666. [ LinearEncoding ]: 0,
  28667. [ sRGBEncoding ]: 1,
  28668. [ RGBEEncoding ]: 2,
  28669. [ RGBM7Encoding ]: 3,
  28670. [ RGBM16Encoding ]: 4,
  28671. [ RGBDEncoding ]: 5,
  28672. [ GammaEncoding ]: 6
  28673. };
  28674. const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
  28675. const { _lodPlanes, _sizeLods, _sigmas } = /*@__PURE__*/ _createPlanes();
  28676. const _clearColor = /*@__PURE__*/ new Color();
  28677. let _oldTarget = null;
  28678. // Golden Ratio
  28679. const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
  28680. const INV_PHI = 1 / PHI;
  28681. // Vertices of a dodecahedron (except the opposites, which represent the
  28682. // same axis), used as axis directions evenly spread on a sphere.
  28683. const _axisDirections = [
  28684. /*@__PURE__*/ new Vector3( 1, 1, 1 ),
  28685. /*@__PURE__*/ new Vector3( - 1, 1, 1 ),
  28686. /*@__PURE__*/ new Vector3( 1, 1, - 1 ),
  28687. /*@__PURE__*/ new Vector3( - 1, 1, - 1 ),
  28688. /*@__PURE__*/ new Vector3( 0, PHI, INV_PHI ),
  28689. /*@__PURE__*/ new Vector3( 0, PHI, - INV_PHI ),
  28690. /*@__PURE__*/ new Vector3( INV_PHI, 0, PHI ),
  28691. /*@__PURE__*/ new Vector3( - INV_PHI, 0, PHI ),
  28692. /*@__PURE__*/ new Vector3( PHI, INV_PHI, 0 ),
  28693. /*@__PURE__*/ new Vector3( - PHI, INV_PHI, 0 ) ];
  28694. /**
  28695. * This class generates a Prefiltered, Mipmapped Radiance Environment Map
  28696. * (PMREM) from a cubeMap environment texture. This allows different levels of
  28697. * blur to be quickly accessed based on material roughness. It is packed into a
  28698. * special CubeUV format that allows us to perform custom interpolation so that
  28699. * we can support nonlinear formats such as RGBE. Unlike a traditional mipmap
  28700. * chain, it only goes down to the LOD_MIN level (above), and then creates extra
  28701. * even more filtered 'mips' at the same LOD_MIN resolution, associated with
  28702. * higher roughness levels. In this way we maintain resolution to smoothly
  28703. * interpolate diffuse lighting while limiting sampling computation.
  28704. */
  28705. class PMREMGenerator {
  28706. constructor( renderer ) {
  28707. this._renderer = renderer;
  28708. this._pingPongRenderTarget = null;
  28709. this._blurMaterial = _getBlurShader( MAX_SAMPLES );
  28710. this._equirectShader = null;
  28711. this._cubemapShader = null;
  28712. this._compileMaterial( this._blurMaterial );
  28713. }
  28714. /**
  28715. * Generates a PMREM from a supplied Scene, which can be faster than using an
  28716. * image if networking bandwidth is low. Optional sigma specifies a blur radius
  28717. * in radians to be applied to the scene before PMREM generation. Optional near
  28718. * and far planes ensure the scene is rendered in its entirety (the cubeCamera
  28719. * is placed at the origin).
  28720. */
  28721. fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
  28722. _oldTarget = this._renderer.getRenderTarget();
  28723. const cubeUVRenderTarget = this._allocateTargets();
  28724. this._sceneToCubeUV( scene, near, far, cubeUVRenderTarget );
  28725. if ( sigma > 0 ) {
  28726. this._blur( cubeUVRenderTarget, 0, 0, sigma );
  28727. }
  28728. this._applyPMREM( cubeUVRenderTarget );
  28729. this._cleanup( cubeUVRenderTarget );
  28730. return cubeUVRenderTarget;
  28731. }
  28732. /**
  28733. * Generates a PMREM from an equirectangular texture, which can be either LDR
  28734. * (RGBFormat) or HDR (RGBEFormat). The ideal input image size is 1k (1024 x 512),
  28735. * as this matches best with the 256 x 256 cubemap output.
  28736. */
  28737. fromEquirectangular( equirectangular ) {
  28738. return this._fromTexture( equirectangular );
  28739. }
  28740. /**
  28741. * Generates a PMREM from an cubemap texture, which can be either LDR
  28742. * (RGBFormat) or HDR (RGBEFormat). The ideal input cube size is 256 x 256,
  28743. * as this matches best with the 256 x 256 cubemap output.
  28744. */
  28745. fromCubemap( cubemap ) {
  28746. return this._fromTexture( cubemap );
  28747. }
  28748. /**
  28749. * Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
  28750. * your texture's network fetch for increased concurrency.
  28751. */
  28752. compileCubemapShader() {
  28753. if ( this._cubemapShader === null ) {
  28754. this._cubemapShader = _getCubemapShader();
  28755. this._compileMaterial( this._cubemapShader );
  28756. }
  28757. }
  28758. /**
  28759. * Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
  28760. * your texture's network fetch for increased concurrency.
  28761. */
  28762. compileEquirectangularShader() {
  28763. if ( this._equirectShader === null ) {
  28764. this._equirectShader = _getEquirectShader();
  28765. this._compileMaterial( this._equirectShader );
  28766. }
  28767. }
  28768. /**
  28769. * Disposes of the PMREMGenerator's internal memory. Note that PMREMGenerator is a static class,
  28770. * so you should not need more than one PMREMGenerator object. If you do, calling dispose() on
  28771. * one of them will cause any others to also become unusable.
  28772. */
  28773. dispose() {
  28774. this._blurMaterial.dispose();
  28775. if ( this._cubemapShader !== null ) this._cubemapShader.dispose();
  28776. if ( this._equirectShader !== null ) this._equirectShader.dispose();
  28777. for ( let i = 0; i < _lodPlanes.length; i ++ ) {
  28778. _lodPlanes[ i ].dispose();
  28779. }
  28780. }
  28781. // private interface
  28782. _cleanup( outputTarget ) {
  28783. this._pingPongRenderTarget.dispose();
  28784. this._renderer.setRenderTarget( _oldTarget );
  28785. outputTarget.scissorTest = false;
  28786. _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
  28787. }
  28788. _fromTexture( texture ) {
  28789. _oldTarget = this._renderer.getRenderTarget();
  28790. const cubeUVRenderTarget = this._allocateTargets( texture );
  28791. this._textureToCubeUV( texture, cubeUVRenderTarget );
  28792. this._applyPMREM( cubeUVRenderTarget );
  28793. this._cleanup( cubeUVRenderTarget );
  28794. return cubeUVRenderTarget;
  28795. }
  28796. _allocateTargets( texture ) { // warning: null texture is valid
  28797. const params = {
  28798. magFilter: NearestFilter,
  28799. minFilter: NearestFilter,
  28800. generateMipmaps: false,
  28801. type: UnsignedByteType,
  28802. format: RGBEFormat,
  28803. encoding: _isLDR( texture ) ? texture.encoding : RGBEEncoding,
  28804. depthBuffer: false
  28805. };
  28806. const cubeUVRenderTarget = _createRenderTarget( params );
  28807. cubeUVRenderTarget.depthBuffer = texture ? false : true;
  28808. this._pingPongRenderTarget = _createRenderTarget( params );
  28809. return cubeUVRenderTarget;
  28810. }
  28811. _compileMaterial( material ) {
  28812. const tmpMesh = new Mesh( _lodPlanes[ 0 ], material );
  28813. this._renderer.compile( tmpMesh, _flatCamera );
  28814. }
  28815. _sceneToCubeUV( scene, near, far, cubeUVRenderTarget ) {
  28816. const fov = 90;
  28817. const aspect = 1;
  28818. const cubeCamera = new PerspectiveCamera( fov, aspect, near, far );
  28819. const upSign = [ 1, - 1, 1, 1, 1, 1 ];
  28820. const forwardSign = [ 1, 1, 1, - 1, - 1, - 1 ];
  28821. const renderer = this._renderer;
  28822. const outputEncoding = renderer.outputEncoding;
  28823. const toneMapping = renderer.toneMapping;
  28824. renderer.getClearColor( _clearColor );
  28825. const clearAlpha = renderer.getClearAlpha();
  28826. renderer.toneMapping = NoToneMapping;
  28827. renderer.outputEncoding = LinearEncoding;
  28828. let background = scene.background;
  28829. if ( background && background.isColor ) {
  28830. background.convertSRGBToLinear();
  28831. // Convert linear to RGBE
  28832. const maxComponent = Math.max( background.r, background.g, background.b );
  28833. const fExp = Math.min( Math.max( Math.ceil( Math.log2( maxComponent ) ), - 128.0 ), 127.0 );
  28834. background = background.multiplyScalar( Math.pow( 2.0, - fExp ) );
  28835. const alpha = ( fExp + 128.0 ) / 255.0;
  28836. renderer.setClearColor( background, alpha );
  28837. scene.background = null;
  28838. }
  28839. for ( let i = 0; i < 6; i ++ ) {
  28840. const col = i % 3;
  28841. if ( col == 0 ) {
  28842. cubeCamera.up.set( 0, upSign[ i ], 0 );
  28843. cubeCamera.lookAt( forwardSign[ i ], 0, 0 );
  28844. } else if ( col == 1 ) {
  28845. cubeCamera.up.set( 0, 0, upSign[ i ] );
  28846. cubeCamera.lookAt( 0, forwardSign[ i ], 0 );
  28847. } else {
  28848. cubeCamera.up.set( 0, upSign[ i ], 0 );
  28849. cubeCamera.lookAt( 0, 0, forwardSign[ i ] );
  28850. }
  28851. _setViewport( cubeUVRenderTarget,
  28852. col * SIZE_MAX, i > 2 ? SIZE_MAX : 0, SIZE_MAX, SIZE_MAX );
  28853. renderer.setRenderTarget( cubeUVRenderTarget );
  28854. renderer.render( scene, cubeCamera );
  28855. }
  28856. renderer.toneMapping = toneMapping;
  28857. renderer.outputEncoding = outputEncoding;
  28858. renderer.setClearColor( _clearColor, clearAlpha );
  28859. }
  28860. _textureToCubeUV( texture, cubeUVRenderTarget ) {
  28861. const renderer = this._renderer;
  28862. if ( texture.isCubeTexture ) {
  28863. if ( this._cubemapShader == null ) {
  28864. this._cubemapShader = _getCubemapShader();
  28865. }
  28866. } else {
  28867. if ( this._equirectShader == null ) {
  28868. this._equirectShader = _getEquirectShader();
  28869. }
  28870. }
  28871. const material = texture.isCubeTexture ? this._cubemapShader : this._equirectShader;
  28872. const mesh = new Mesh( _lodPlanes[ 0 ], material );
  28873. const uniforms = material.uniforms;
  28874. uniforms[ 'envMap' ].value = texture;
  28875. if ( ! texture.isCubeTexture ) {
  28876. uniforms[ 'texelSize' ].value.set( 1.0 / texture.image.width, 1.0 / texture.image.height );
  28877. }
  28878. uniforms[ 'inputEncoding' ].value = ENCODINGS[ texture.encoding ];
  28879. uniforms[ 'outputEncoding' ].value = ENCODINGS[ cubeUVRenderTarget.texture.encoding ];
  28880. _setViewport( cubeUVRenderTarget, 0, 0, 3 * SIZE_MAX, 2 * SIZE_MAX );
  28881. renderer.setRenderTarget( cubeUVRenderTarget );
  28882. renderer.render( mesh, _flatCamera );
  28883. }
  28884. _applyPMREM( cubeUVRenderTarget ) {
  28885. const renderer = this._renderer;
  28886. const autoClear = renderer.autoClear;
  28887. renderer.autoClear = false;
  28888. for ( let i = 1; i < TOTAL_LODS; i ++ ) {
  28889. const sigma = Math.sqrt( _sigmas[ i ] * _sigmas[ i ] - _sigmas[ i - 1 ] * _sigmas[ i - 1 ] );
  28890. const poleAxis = _axisDirections[ ( i - 1 ) % _axisDirections.length ];
  28891. this._blur( cubeUVRenderTarget, i - 1, i, sigma, poleAxis );
  28892. }
  28893. renderer.autoClear = autoClear;
  28894. }
  28895. /**
  28896. * This is a two-pass Gaussian blur for a cubemap. Normally this is done
  28897. * vertically and horizontally, but this breaks down on a cube. Here we apply
  28898. * the blur latitudinally (around the poles), and then longitudinally (towards
  28899. * the poles) to approximate the orthogonally-separable blur. It is least
  28900. * accurate at the poles, but still does a decent job.
  28901. */
  28902. _blur( cubeUVRenderTarget, lodIn, lodOut, sigma, poleAxis ) {
  28903. const pingPongRenderTarget = this._pingPongRenderTarget;
  28904. this._halfBlur(
  28905. cubeUVRenderTarget,
  28906. pingPongRenderTarget,
  28907. lodIn,
  28908. lodOut,
  28909. sigma,
  28910. 'latitudinal',
  28911. poleAxis );
  28912. this._halfBlur(
  28913. pingPongRenderTarget,
  28914. cubeUVRenderTarget,
  28915. lodOut,
  28916. lodOut,
  28917. sigma,
  28918. 'longitudinal',
  28919. poleAxis );
  28920. }
  28921. _halfBlur( targetIn, targetOut, lodIn, lodOut, sigmaRadians, direction, poleAxis ) {
  28922. const renderer = this._renderer;
  28923. const blurMaterial = this._blurMaterial;
  28924. if ( direction !== 'latitudinal' && direction !== 'longitudinal' ) {
  28925. console.error(
  28926. 'blur direction must be either latitudinal or longitudinal!' );
  28927. }
  28928. // Number of standard deviations at which to cut off the discrete approximation.
  28929. const STANDARD_DEVIATIONS = 3;
  28930. const blurMesh = new Mesh( _lodPlanes[ lodOut ], blurMaterial );
  28931. const blurUniforms = blurMaterial.uniforms;
  28932. const pixels = _sizeLods[ lodIn ] - 1;
  28933. const radiansPerPixel = isFinite( sigmaRadians ) ? Math.PI / ( 2 * pixels ) : 2 * Math.PI / ( 2 * MAX_SAMPLES - 1 );
  28934. const sigmaPixels = sigmaRadians / radiansPerPixel;
  28935. const samples = isFinite( sigmaRadians ) ? 1 + Math.floor( STANDARD_DEVIATIONS * sigmaPixels ) : MAX_SAMPLES;
  28936. if ( samples > MAX_SAMPLES ) {
  28937. console.warn( `sigmaRadians, ${
  28938. sigmaRadians}, is too large and will clip, as it requested ${
  28939. samples} samples when the maximum is set to ${MAX_SAMPLES}` );
  28940. }
  28941. const weights = [];
  28942. let sum = 0;
  28943. for ( let i = 0; i < MAX_SAMPLES; ++ i ) {
  28944. const x = i / sigmaPixels;
  28945. const weight = Math.exp( - x * x / 2 );
  28946. weights.push( weight );
  28947. if ( i == 0 ) {
  28948. sum += weight;
  28949. } else if ( i < samples ) {
  28950. sum += 2 * weight;
  28951. }
  28952. }
  28953. for ( let i = 0; i < weights.length; i ++ ) {
  28954. weights[ i ] = weights[ i ] / sum;
  28955. }
  28956. blurUniforms[ 'envMap' ].value = targetIn.texture;
  28957. blurUniforms[ 'samples' ].value = samples;
  28958. blurUniforms[ 'weights' ].value = weights;
  28959. blurUniforms[ 'latitudinal' ].value = direction === 'latitudinal';
  28960. if ( poleAxis ) {
  28961. blurUniforms[ 'poleAxis' ].value = poleAxis;
  28962. }
  28963. blurUniforms[ 'dTheta' ].value = radiansPerPixel;
  28964. blurUniforms[ 'mipInt' ].value = LOD_MAX - lodIn;
  28965. blurUniforms[ 'inputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  28966. blurUniforms[ 'outputEncoding' ].value = ENCODINGS[ targetIn.texture.encoding ];
  28967. const outputSize = _sizeLods[ lodOut ];
  28968. const x = 3 * Math.max( 0, SIZE_MAX - 2 * outputSize );
  28969. const y = ( lodOut === 0 ? 0 : 2 * SIZE_MAX ) + 2 * outputSize * ( lodOut > LOD_MAX - LOD_MIN ? lodOut - LOD_MAX + LOD_MIN : 0 );
  28970. _setViewport( targetOut, x, y, 3 * outputSize, 2 * outputSize );
  28971. renderer.setRenderTarget( targetOut );
  28972. renderer.render( blurMesh, _flatCamera );
  28973. }
  28974. }
  28975. function _isLDR( texture ) {
  28976. if ( texture === undefined || texture.type !== UnsignedByteType ) return false;
  28977. return texture.encoding === LinearEncoding || texture.encoding === sRGBEncoding || texture.encoding === GammaEncoding;
  28978. }
  28979. function _createPlanes() {
  28980. const _lodPlanes = [];
  28981. const _sizeLods = [];
  28982. const _sigmas = [];
  28983. let lod = LOD_MAX;
  28984. for ( let i = 0; i < TOTAL_LODS; i ++ ) {
  28985. const sizeLod = Math.pow( 2, lod );
  28986. _sizeLods.push( sizeLod );
  28987. let sigma = 1.0 / sizeLod;
  28988. if ( i > LOD_MAX - LOD_MIN ) {
  28989. sigma = EXTRA_LOD_SIGMA[ i - LOD_MAX + LOD_MIN - 1 ];
  28990. } else if ( i == 0 ) {
  28991. sigma = 0;
  28992. }
  28993. _sigmas.push( sigma );
  28994. const texelSize = 1.0 / ( sizeLod - 1 );
  28995. const min = - texelSize / 2;
  28996. const max = 1 + texelSize / 2;
  28997. const uv1 = [ min, min, max, min, max, max, min, min, max, max, min, max ];
  28998. const cubeFaces = 6;
  28999. const vertices = 6;
  29000. const positionSize = 3;
  29001. const uvSize = 2;
  29002. const faceIndexSize = 1;
  29003. const position = new Float32Array( positionSize * vertices * cubeFaces );
  29004. const uv = new Float32Array( uvSize * vertices * cubeFaces );
  29005. const faceIndex = new Float32Array( faceIndexSize * vertices * cubeFaces );
  29006. for ( let face = 0; face < cubeFaces; face ++ ) {
  29007. const x = ( face % 3 ) * 2 / 3 - 1;
  29008. const y = face > 2 ? 0 : - 1;
  29009. const coordinates = [
  29010. x, y, 0,
  29011. x + 2 / 3, y, 0,
  29012. x + 2 / 3, y + 1, 0,
  29013. x, y, 0,
  29014. x + 2 / 3, y + 1, 0,
  29015. x, y + 1, 0
  29016. ];
  29017. position.set( coordinates, positionSize * vertices * face );
  29018. uv.set( uv1, uvSize * vertices * face );
  29019. const fill = [ face, face, face, face, face, face ];
  29020. faceIndex.set( fill, faceIndexSize * vertices * face );
  29021. }
  29022. const planes = new BufferGeometry();
  29023. planes.setAttribute( 'position', new BufferAttribute( position, positionSize ) );
  29024. planes.setAttribute( 'uv', new BufferAttribute( uv, uvSize ) );
  29025. planes.setAttribute( 'faceIndex', new BufferAttribute( faceIndex, faceIndexSize ) );
  29026. _lodPlanes.push( planes );
  29027. if ( lod > LOD_MIN ) {
  29028. lod --;
  29029. }
  29030. }
  29031. return { _lodPlanes, _sizeLods, _sigmas };
  29032. }
  29033. function _createRenderTarget( params ) {
  29034. const cubeUVRenderTarget = new WebGLRenderTarget( 3 * SIZE_MAX, 3 * SIZE_MAX, params );
  29035. cubeUVRenderTarget.texture.mapping = CubeUVReflectionMapping;
  29036. cubeUVRenderTarget.texture.name = 'PMREM.cubeUv';
  29037. cubeUVRenderTarget.scissorTest = true;
  29038. return cubeUVRenderTarget;
  29039. }
  29040. function _setViewport( target, x, y, width, height ) {
  29041. target.viewport.set( x, y, width, height );
  29042. target.scissor.set( x, y, width, height );
  29043. }
  29044. function _getBlurShader( maxSamples ) {
  29045. const weights = new Float32Array( maxSamples );
  29046. const poleAxis = new Vector3( 0, 1, 0 );
  29047. const shaderMaterial = new RawShaderMaterial( {
  29048. name: 'SphericalGaussianBlur',
  29049. defines: { 'n': maxSamples },
  29050. uniforms: {
  29051. 'envMap': { value: null },
  29052. 'samples': { value: 1 },
  29053. 'weights': { value: weights },
  29054. 'latitudinal': { value: false },
  29055. 'dTheta': { value: 0 },
  29056. 'mipInt': { value: 0 },
  29057. 'poleAxis': { value: poleAxis },
  29058. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29059. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29060. },
  29061. vertexShader: _getCommonVertexShader(),
  29062. fragmentShader: /* glsl */`
  29063. precision mediump float;
  29064. precision mediump int;
  29065. varying vec3 vOutputDirection;
  29066. uniform sampler2D envMap;
  29067. uniform int samples;
  29068. uniform float weights[ n ];
  29069. uniform bool latitudinal;
  29070. uniform float dTheta;
  29071. uniform float mipInt;
  29072. uniform vec3 poleAxis;
  29073. ${ _getEncodings() }
  29074. #define ENVMAP_TYPE_CUBE_UV
  29075. #include <cube_uv_reflection_fragment>
  29076. vec3 getSample( float theta, vec3 axis ) {
  29077. float cosTheta = cos( theta );
  29078. // Rodrigues' axis-angle rotation
  29079. vec3 sampleDirection = vOutputDirection * cosTheta
  29080. + cross( axis, vOutputDirection ) * sin( theta )
  29081. + axis * dot( axis, vOutputDirection ) * ( 1.0 - cosTheta );
  29082. return bilinearCubeUV( envMap, sampleDirection, mipInt );
  29083. }
  29084. void main() {
  29085. vec3 axis = latitudinal ? poleAxis : cross( poleAxis, vOutputDirection );
  29086. if ( all( equal( axis, vec3( 0.0 ) ) ) ) {
  29087. axis = vec3( vOutputDirection.z, 0.0, - vOutputDirection.x );
  29088. }
  29089. axis = normalize( axis );
  29090. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  29091. gl_FragColor.rgb += weights[ 0 ] * getSample( 0.0, axis );
  29092. for ( int i = 1; i < n; i++ ) {
  29093. if ( i >= samples ) {
  29094. break;
  29095. }
  29096. float theta = dTheta * float( i );
  29097. gl_FragColor.rgb += weights[ i ] * getSample( -1.0 * theta, axis );
  29098. gl_FragColor.rgb += weights[ i ] * getSample( theta, axis );
  29099. }
  29100. gl_FragColor = linearToOutputTexel( gl_FragColor );
  29101. }
  29102. `,
  29103. blending: NoBlending,
  29104. depthTest: false,
  29105. depthWrite: false
  29106. } );
  29107. return shaderMaterial;
  29108. }
  29109. function _getEquirectShader() {
  29110. const texelSize = new Vector2( 1, 1 );
  29111. const shaderMaterial = new RawShaderMaterial( {
  29112. name: 'EquirectangularToCubeUV',
  29113. uniforms: {
  29114. 'envMap': { value: null },
  29115. 'texelSize': { value: texelSize },
  29116. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29117. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29118. },
  29119. vertexShader: _getCommonVertexShader(),
  29120. fragmentShader: /* glsl */`
  29121. precision mediump float;
  29122. precision mediump int;
  29123. varying vec3 vOutputDirection;
  29124. uniform sampler2D envMap;
  29125. uniform vec2 texelSize;
  29126. ${ _getEncodings() }
  29127. #include <common>
  29128. void main() {
  29129. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  29130. vec3 outputDirection = normalize( vOutputDirection );
  29131. vec2 uv = equirectUv( outputDirection );
  29132. vec2 f = fract( uv / texelSize - 0.5 );
  29133. uv -= f * texelSize;
  29134. vec3 tl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  29135. uv.x += texelSize.x;
  29136. vec3 tr = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  29137. uv.y += texelSize.y;
  29138. vec3 br = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  29139. uv.x -= texelSize.x;
  29140. vec3 bl = envMapTexelToLinear( texture2D ( envMap, uv ) ).rgb;
  29141. vec3 tm = mix( tl, tr, f.x );
  29142. vec3 bm = mix( bl, br, f.x );
  29143. gl_FragColor.rgb = mix( tm, bm, f.y );
  29144. gl_FragColor = linearToOutputTexel( gl_FragColor );
  29145. }
  29146. `,
  29147. blending: NoBlending,
  29148. depthTest: false,
  29149. depthWrite: false
  29150. } );
  29151. return shaderMaterial;
  29152. }
  29153. function _getCubemapShader() {
  29154. const shaderMaterial = new RawShaderMaterial( {
  29155. name: 'CubemapToCubeUV',
  29156. uniforms: {
  29157. 'envMap': { value: null },
  29158. 'inputEncoding': { value: ENCODINGS[ LinearEncoding ] },
  29159. 'outputEncoding': { value: ENCODINGS[ LinearEncoding ] }
  29160. },
  29161. vertexShader: _getCommonVertexShader(),
  29162. fragmentShader: /* glsl */`
  29163. precision mediump float;
  29164. precision mediump int;
  29165. varying vec3 vOutputDirection;
  29166. uniform samplerCube envMap;
  29167. ${ _getEncodings() }
  29168. void main() {
  29169. gl_FragColor = vec4( 0.0, 0.0, 0.0, 1.0 );
  29170. gl_FragColor.rgb = envMapTexelToLinear( textureCube( envMap, vec3( - vOutputDirection.x, vOutputDirection.yz ) ) ).rgb;
  29171. gl_FragColor = linearToOutputTexel( gl_FragColor );
  29172. }
  29173. `,
  29174. blending: NoBlending,
  29175. depthTest: false,
  29176. depthWrite: false
  29177. } );
  29178. return shaderMaterial;
  29179. }
  29180. function _getCommonVertexShader() {
  29181. return /* glsl */`
  29182. precision mediump float;
  29183. precision mediump int;
  29184. attribute vec3 position;
  29185. attribute vec2 uv;
  29186. attribute float faceIndex;
  29187. varying vec3 vOutputDirection;
  29188. // RH coordinate system; PMREM face-indexing convention
  29189. vec3 getDirection( vec2 uv, float face ) {
  29190. uv = 2.0 * uv - 1.0;
  29191. vec3 direction = vec3( uv, 1.0 );
  29192. if ( face == 0.0 ) {
  29193. direction = direction.zyx; // ( 1, v, u ) pos x
  29194. } else if ( face == 1.0 ) {
  29195. direction = direction.xzy;
  29196. direction.xz *= -1.0; // ( -u, 1, -v ) pos y
  29197. } else if ( face == 2.0 ) {
  29198. direction.x *= -1.0; // ( -u, v, 1 ) pos z
  29199. } else if ( face == 3.0 ) {
  29200. direction = direction.zyx;
  29201. direction.xz *= -1.0; // ( -1, v, -u ) neg x
  29202. } else if ( face == 4.0 ) {
  29203. direction = direction.xzy;
  29204. direction.xy *= -1.0; // ( -u, -1, v ) neg y
  29205. } else if ( face == 5.0 ) {
  29206. direction.z *= -1.0; // ( u, v, -1 ) neg z
  29207. }
  29208. return direction;
  29209. }
  29210. void main() {
  29211. vOutputDirection = getDirection( uv, faceIndex );
  29212. gl_Position = vec4( position, 1.0 );
  29213. }
  29214. `;
  29215. }
  29216. function _getEncodings() {
  29217. return /* glsl */`
  29218. uniform int inputEncoding;
  29219. uniform int outputEncoding;
  29220. #include <encodings_pars_fragment>
  29221. vec4 inputTexelToLinear( vec4 value ) {
  29222. if ( inputEncoding == 0 ) {
  29223. return value;
  29224. } else if ( inputEncoding == 1 ) {
  29225. return sRGBToLinear( value );
  29226. } else if ( inputEncoding == 2 ) {
  29227. return RGBEToLinear( value );
  29228. } else if ( inputEncoding == 3 ) {
  29229. return RGBMToLinear( value, 7.0 );
  29230. } else if ( inputEncoding == 4 ) {
  29231. return RGBMToLinear( value, 16.0 );
  29232. } else if ( inputEncoding == 5 ) {
  29233. return RGBDToLinear( value, 256.0 );
  29234. } else {
  29235. return GammaToLinear( value, 2.2 );
  29236. }
  29237. }
  29238. vec4 linearToOutputTexel( vec4 value ) {
  29239. if ( outputEncoding == 0 ) {
  29240. return value;
  29241. } else if ( outputEncoding == 1 ) {
  29242. return LinearTosRGB( value );
  29243. } else if ( outputEncoding == 2 ) {
  29244. return LinearToRGBE( value );
  29245. } else if ( outputEncoding == 3 ) {
  29246. return LinearToRGBM( value, 7.0 );
  29247. } else if ( outputEncoding == 4 ) {
  29248. return LinearToRGBM( value, 16.0 );
  29249. } else if ( outputEncoding == 5 ) {
  29250. return LinearToRGBD( value, 256.0 );
  29251. } else {
  29252. return LinearToGamma( value, 2.2 );
  29253. }
  29254. }
  29255. vec4 envMapTexelToLinear( vec4 color ) {
  29256. return inputTexelToLinear( color );
  29257. }
  29258. `;
  29259. }
  29260. function Face4( a, b, c, d, normal, color, materialIndex ) {
  29261. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  29262. return new Face3( a, b, c, normal, color, materialIndex );
  29263. }
  29264. const LineStrip = 0;
  29265. const LinePieces = 1;
  29266. const NoColors = 0;
  29267. const FaceColors = 1;
  29268. const VertexColors = 2;
  29269. function MeshFaceMaterial( materials ) {
  29270. console.warn( 'THREE.MeshFaceMaterial has been removed. Use an Array instead.' );
  29271. return materials;
  29272. }
  29273. function MultiMaterial( materials = [] ) {
  29274. console.warn( 'THREE.MultiMaterial has been removed. Use an Array instead.' );
  29275. materials.isMultiMaterial = true;
  29276. materials.materials = materials;
  29277. materials.clone = function () {
  29278. return materials.slice();
  29279. };
  29280. return materials;
  29281. }
  29282. function PointCloud( geometry, material ) {
  29283. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  29284. return new Points( geometry, material );
  29285. }
  29286. function Particle( material ) {
  29287. console.warn( 'THREE.Particle has been renamed to THREE.Sprite.' );
  29288. return new Sprite$1( material );
  29289. }
  29290. function ParticleSystem( geometry, material ) {
  29291. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  29292. return new Points( geometry, material );
  29293. }
  29294. function PointCloudMaterial( parameters ) {
  29295. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  29296. return new PointsMaterial( parameters );
  29297. }
  29298. function ParticleBasicMaterial( parameters ) {
  29299. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  29300. return new PointsMaterial( parameters );
  29301. }
  29302. function ParticleSystemMaterial( parameters ) {
  29303. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  29304. return new PointsMaterial( parameters );
  29305. }
  29306. function Vertex( x, y, z ) {
  29307. console.warn( 'THREE.Vertex has been removed. Use THREE.Vector3 instead.' );
  29308. return new Vector3( x, y, z );
  29309. }
  29310. //
  29311. function DynamicBufferAttribute( array, itemSize ) {
  29312. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setUsage( THREE.DynamicDrawUsage ) instead.' );
  29313. return new BufferAttribute( array, itemSize ).setUsage( DynamicDrawUsage );
  29314. }
  29315. function Int8Attribute( array, itemSize ) {
  29316. console.warn( 'THREE.Int8Attribute has been removed. Use new THREE.Int8BufferAttribute() instead.' );
  29317. return new Int8BufferAttribute( array, itemSize );
  29318. }
  29319. function Uint8Attribute( array, itemSize ) {
  29320. console.warn( 'THREE.Uint8Attribute has been removed. Use new THREE.Uint8BufferAttribute() instead.' );
  29321. return new Uint8BufferAttribute( array, itemSize );
  29322. }
  29323. function Uint8ClampedAttribute( array, itemSize ) {
  29324. console.warn( 'THREE.Uint8ClampedAttribute has been removed. Use new THREE.Uint8ClampedBufferAttribute() instead.' );
  29325. return new Uint8ClampedBufferAttribute( array, itemSize );
  29326. }
  29327. function Int16Attribute( array, itemSize ) {
  29328. console.warn( 'THREE.Int16Attribute has been removed. Use new THREE.Int16BufferAttribute() instead.' );
  29329. return new Int16BufferAttribute( array, itemSize );
  29330. }
  29331. function Uint16Attribute( array, itemSize ) {
  29332. console.warn( 'THREE.Uint16Attribute has been removed. Use new THREE.Uint16BufferAttribute() instead.' );
  29333. return new Uint16BufferAttribute( array, itemSize );
  29334. }
  29335. function Int32Attribute( array, itemSize ) {
  29336. console.warn( 'THREE.Int32Attribute has been removed. Use new THREE.Int32BufferAttribute() instead.' );
  29337. return new Int32BufferAttribute( array, itemSize );
  29338. }
  29339. function Uint32Attribute( array, itemSize ) {
  29340. console.warn( 'THREE.Uint32Attribute has been removed. Use new THREE.Uint32BufferAttribute() instead.' );
  29341. return new Uint32BufferAttribute( array, itemSize );
  29342. }
  29343. function Float32Attribute( array, itemSize ) {
  29344. console.warn( 'THREE.Float32Attribute has been removed. Use new THREE.Float32BufferAttribute() instead.' );
  29345. return new Float32BufferAttribute( array, itemSize );
  29346. }
  29347. function Float64Attribute( array, itemSize ) {
  29348. console.warn( 'THREE.Float64Attribute has been removed. Use new THREE.Float64BufferAttribute() instead.' );
  29349. return new Float64BufferAttribute( array, itemSize );
  29350. }
  29351. //
  29352. Curve.create = function ( construct, getPoint ) {
  29353. console.log( 'THREE.Curve.create() has been deprecated' );
  29354. construct.prototype = Object.create( Curve.prototype );
  29355. construct.prototype.constructor = construct;
  29356. construct.prototype.getPoint = getPoint;
  29357. return construct;
  29358. };
  29359. //
  29360. Object.assign( CurvePath.prototype, {
  29361. createPointsGeometry: function ( divisions ) {
  29362. console.warn( 'THREE.CurvePath: .createPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29363. // generate geometry from path points (for Line or Points objects)
  29364. const pts = this.getPoints( divisions );
  29365. return this.createGeometry( pts );
  29366. },
  29367. createSpacedPointsGeometry: function ( divisions ) {
  29368. console.warn( 'THREE.CurvePath: .createSpacedPointsGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29369. // generate geometry from equidistant sampling along the path
  29370. const pts = this.getSpacedPoints( divisions );
  29371. return this.createGeometry( pts );
  29372. },
  29373. createGeometry: function ( points ) {
  29374. console.warn( 'THREE.CurvePath: .createGeometry() has been removed. Use new THREE.Geometry().setFromPoints( points ) instead.' );
  29375. const geometry = new Geometry();
  29376. for ( let i = 0, l = points.length; i < l; i ++ ) {
  29377. const point = points[ i ];
  29378. geometry.vertices.push( new Vector3( point.x, point.y, point.z || 0 ) );
  29379. }
  29380. return geometry;
  29381. }
  29382. } );
  29383. //
  29384. Object.assign( Path.prototype, {
  29385. fromPoints: function ( points ) {
  29386. console.warn( 'THREE.Path: .fromPoints() has been renamed to .setFromPoints().' );
  29387. return this.setFromPoints( points );
  29388. }
  29389. } );
  29390. //
  29391. function ClosedSplineCurve3( points ) {
  29392. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29393. CatmullRomCurve3.call( this, points );
  29394. this.type = 'catmullrom';
  29395. this.closed = true;
  29396. }
  29397. ClosedSplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29398. //
  29399. function SplineCurve3( points ) {
  29400. console.warn( 'THREE.SplineCurve3 has been deprecated. Use THREE.CatmullRomCurve3 instead.' );
  29401. CatmullRomCurve3.call( this, points );
  29402. this.type = 'catmullrom';
  29403. }
  29404. SplineCurve3.prototype = Object.create( CatmullRomCurve3.prototype );
  29405. //
  29406. function Spline( points ) {
  29407. console.warn( 'THREE.Spline has been removed. Use THREE.CatmullRomCurve3 instead.' );
  29408. CatmullRomCurve3.call( this, points );
  29409. this.type = 'catmullrom';
  29410. }
  29411. Spline.prototype = Object.create( CatmullRomCurve3.prototype );
  29412. Object.assign( Spline.prototype, {
  29413. initFromArray: function ( /* a */ ) {
  29414. console.error( 'THREE.Spline: .initFromArray() has been removed.' );
  29415. },
  29416. getControlPointsArray: function ( /* optionalTarget */ ) {
  29417. console.error( 'THREE.Spline: .getControlPointsArray() has been removed.' );
  29418. },
  29419. reparametrizeByArcLength: function ( /* samplingCoef */ ) {
  29420. console.error( 'THREE.Spline: .reparametrizeByArcLength() has been removed.' );
  29421. }
  29422. } );
  29423. //
  29424. function AxisHelper( size ) {
  29425. console.warn( 'THREE.AxisHelper has been renamed to THREE.AxesHelper.' );
  29426. return new AxesHelper( size );
  29427. }
  29428. function BoundingBoxHelper( object, color ) {
  29429. console.warn( 'THREE.BoundingBoxHelper has been deprecated. Creating a THREE.BoxHelper instead.' );
  29430. return new BoxHelper( object, color );
  29431. }
  29432. function EdgesHelper( object, hex ) {
  29433. console.warn( 'THREE.EdgesHelper has been removed. Use THREE.EdgesGeometry instead.' );
  29434. return new LineSegments( new EdgesGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29435. }
  29436. GridHelper.prototype.setColors = function () {
  29437. console.error( 'THREE.GridHelper: setColors() has been deprecated, pass them in the constructor instead.' );
  29438. };
  29439. SkeletonHelper.prototype.update = function () {
  29440. console.error( 'THREE.SkeletonHelper: update() no longer needs to be called.' );
  29441. };
  29442. function WireframeHelper( object, hex ) {
  29443. console.warn( 'THREE.WireframeHelper has been removed. Use THREE.WireframeGeometry instead.' );
  29444. return new LineSegments( new WireframeGeometry( object.geometry ), new LineBasicMaterial( { color: hex !== undefined ? hex : 0xffffff } ) );
  29445. }
  29446. //
  29447. Object.assign( Loader.prototype, {
  29448. extractUrlBase: function ( url ) {
  29449. console.warn( 'THREE.Loader: .extractUrlBase() has been deprecated. Use THREE.LoaderUtils.extractUrlBase() instead.' );
  29450. return LoaderUtils.extractUrlBase( url );
  29451. }
  29452. } );
  29453. Loader.Handlers = {
  29454. add: function ( /* regex, loader */ ) {
  29455. console.error( 'THREE.Loader: Handlers.add() has been removed. Use LoadingManager.addHandler() instead.' );
  29456. },
  29457. get: function ( /* file */ ) {
  29458. console.error( 'THREE.Loader: Handlers.get() has been removed. Use LoadingManager.getHandler() instead.' );
  29459. }
  29460. };
  29461. function XHRLoader( manager ) {
  29462. console.warn( 'THREE.XHRLoader has been renamed to THREE.FileLoader.' );
  29463. return new FileLoader( manager );
  29464. }
  29465. function BinaryTextureLoader( manager ) {
  29466. console.warn( 'THREE.BinaryTextureLoader has been renamed to THREE.DataTextureLoader.' );
  29467. return new DataTextureLoader( manager );
  29468. }
  29469. //
  29470. Object.assign( Box2.prototype, {
  29471. center: function ( optionalTarget ) {
  29472. console.warn( 'THREE.Box2: .center() has been renamed to .getCenter().' );
  29473. return this.getCenter( optionalTarget );
  29474. },
  29475. empty: function () {
  29476. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  29477. return this.isEmpty();
  29478. },
  29479. isIntersectionBox: function ( box ) {
  29480. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29481. return this.intersectsBox( box );
  29482. },
  29483. size: function ( optionalTarget ) {
  29484. console.warn( 'THREE.Box2: .size() has been renamed to .getSize().' );
  29485. return this.getSize( optionalTarget );
  29486. }
  29487. } );
  29488. Object.assign( Box3.prototype, {
  29489. center: function ( optionalTarget ) {
  29490. console.warn( 'THREE.Box3: .center() has been renamed to .getCenter().' );
  29491. return this.getCenter( optionalTarget );
  29492. },
  29493. empty: function () {
  29494. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  29495. return this.isEmpty();
  29496. },
  29497. isIntersectionBox: function ( box ) {
  29498. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29499. return this.intersectsBox( box );
  29500. },
  29501. isIntersectionSphere: function ( sphere ) {
  29502. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29503. return this.intersectsSphere( sphere );
  29504. },
  29505. size: function ( optionalTarget ) {
  29506. console.warn( 'THREE.Box3: .size() has been renamed to .getSize().' );
  29507. return this.getSize( optionalTarget );
  29508. }
  29509. } );
  29510. Object.assign( Sphere.prototype, {
  29511. empty: function () {
  29512. console.warn( 'THREE.Sphere: .empty() has been renamed to .isEmpty().' );
  29513. return this.isEmpty();
  29514. },
  29515. } );
  29516. Frustum.prototype.setFromMatrix = function ( m ) {
  29517. console.warn( 'THREE.Frustum: .setFromMatrix() has been renamed to .setFromProjectionMatrix().' );
  29518. return this.setFromProjectionMatrix( m );
  29519. };
  29520. Line3.prototype.center = function ( optionalTarget ) {
  29521. console.warn( 'THREE.Line3: .center() has been renamed to .getCenter().' );
  29522. return this.getCenter( optionalTarget );
  29523. };
  29524. Object.assign( MathUtils, {
  29525. random16: function () {
  29526. console.warn( 'THREE.Math: .random16() has been deprecated. Use Math.random() instead.' );
  29527. return Math.random();
  29528. },
  29529. nearestPowerOfTwo: function ( value ) {
  29530. console.warn( 'THREE.Math: .nearestPowerOfTwo() has been renamed to .floorPowerOfTwo().' );
  29531. return MathUtils.floorPowerOfTwo( value );
  29532. },
  29533. nextPowerOfTwo: function ( value ) {
  29534. console.warn( 'THREE.Math: .nextPowerOfTwo() has been renamed to .ceilPowerOfTwo().' );
  29535. return MathUtils.ceilPowerOfTwo( value );
  29536. }
  29537. } );
  29538. Object.assign( Matrix3.prototype, {
  29539. flattenToArrayOffset: function ( array, offset ) {
  29540. console.warn( 'THREE.Matrix3: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  29541. return this.toArray( array, offset );
  29542. },
  29543. multiplyVector3: function ( vector ) {
  29544. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  29545. return vector.applyMatrix3( this );
  29546. },
  29547. multiplyVector3Array: function ( /* a */ ) {
  29548. console.error( 'THREE.Matrix3: .multiplyVector3Array() has been removed.' );
  29549. },
  29550. applyToBufferAttribute: function ( attribute ) {
  29551. console.warn( 'THREE.Matrix3: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix3( matrix ) instead.' );
  29552. return attribute.applyMatrix3( this );
  29553. },
  29554. applyToVector3Array: function ( /* array, offset, length */ ) {
  29555. console.error( 'THREE.Matrix3: .applyToVector3Array() has been removed.' );
  29556. },
  29557. getInverse: function ( matrix ) {
  29558. console.warn( 'THREE.Matrix3: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  29559. return this.copy( matrix ).invert();
  29560. }
  29561. } );
  29562. Object.assign( Matrix4.prototype, {
  29563. extractPosition: function ( m ) {
  29564. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  29565. return this.copyPosition( m );
  29566. },
  29567. flattenToArrayOffset: function ( array, offset ) {
  29568. console.warn( 'THREE.Matrix4: .flattenToArrayOffset() has been deprecated. Use .toArray() instead.' );
  29569. return this.toArray( array, offset );
  29570. },
  29571. getPosition: function () {
  29572. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  29573. return new Vector3().setFromMatrixColumn( this, 3 );
  29574. },
  29575. setRotationFromQuaternion: function ( q ) {
  29576. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  29577. return this.makeRotationFromQuaternion( q );
  29578. },
  29579. multiplyToArray: function () {
  29580. console.warn( 'THREE.Matrix4: .multiplyToArray() has been removed.' );
  29581. },
  29582. multiplyVector3: function ( vector ) {
  29583. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29584. return vector.applyMatrix4( this );
  29585. },
  29586. multiplyVector4: function ( vector ) {
  29587. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29588. return vector.applyMatrix4( this );
  29589. },
  29590. multiplyVector3Array: function ( /* a */ ) {
  29591. console.error( 'THREE.Matrix4: .multiplyVector3Array() has been removed.' );
  29592. },
  29593. rotateAxis: function ( v ) {
  29594. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  29595. v.transformDirection( this );
  29596. },
  29597. crossVector: function ( vector ) {
  29598. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  29599. return vector.applyMatrix4( this );
  29600. },
  29601. translate: function () {
  29602. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  29603. },
  29604. rotateX: function () {
  29605. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  29606. },
  29607. rotateY: function () {
  29608. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  29609. },
  29610. rotateZ: function () {
  29611. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  29612. },
  29613. rotateByAxis: function () {
  29614. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  29615. },
  29616. applyToBufferAttribute: function ( attribute ) {
  29617. console.warn( 'THREE.Matrix4: .applyToBufferAttribute() has been removed. Use attribute.applyMatrix4( matrix ) instead.' );
  29618. return attribute.applyMatrix4( this );
  29619. },
  29620. applyToVector3Array: function ( /* array, offset, length */ ) {
  29621. console.error( 'THREE.Matrix4: .applyToVector3Array() has been removed.' );
  29622. },
  29623. makeFrustum: function ( left, right, bottom, top, near, far ) {
  29624. console.warn( 'THREE.Matrix4: .makeFrustum() has been removed. Use .makePerspective( left, right, top, bottom, near, far ) instead.' );
  29625. return this.makePerspective( left, right, top, bottom, near, far );
  29626. },
  29627. getInverse: function ( matrix ) {
  29628. console.warn( 'THREE.Matrix4: .getInverse() has been removed. Use matrixInv.copy( matrix ).invert(); instead.' );
  29629. return this.copy( matrix ).invert();
  29630. }
  29631. } );
  29632. Plane.prototype.isIntersectionLine = function ( line ) {
  29633. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  29634. return this.intersectsLine( line );
  29635. };
  29636. Object.assign( Quaternion.prototype, {
  29637. multiplyVector3: function ( vector ) {
  29638. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  29639. return vector.applyQuaternion( this );
  29640. },
  29641. inverse: function ( ) {
  29642. console.warn( 'THREE.Quaternion: .inverse() has been renamed to invert().' );
  29643. return this.invert();
  29644. }
  29645. } );
  29646. Object.assign( Ray.prototype, {
  29647. isIntersectionBox: function ( box ) {
  29648. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  29649. return this.intersectsBox( box );
  29650. },
  29651. isIntersectionPlane: function ( plane ) {
  29652. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  29653. return this.intersectsPlane( plane );
  29654. },
  29655. isIntersectionSphere: function ( sphere ) {
  29656. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  29657. return this.intersectsSphere( sphere );
  29658. }
  29659. } );
  29660. Object.assign( Triangle.prototype, {
  29661. area: function () {
  29662. console.warn( 'THREE.Triangle: .area() has been renamed to .getArea().' );
  29663. return this.getArea();
  29664. },
  29665. barycoordFromPoint: function ( point, target ) {
  29666. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29667. return this.getBarycoord( point, target );
  29668. },
  29669. midpoint: function ( target ) {
  29670. console.warn( 'THREE.Triangle: .midpoint() has been renamed to .getMidpoint().' );
  29671. return this.getMidpoint( target );
  29672. },
  29673. normal: function ( target ) {
  29674. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29675. return this.getNormal( target );
  29676. },
  29677. plane: function ( target ) {
  29678. console.warn( 'THREE.Triangle: .plane() has been renamed to .getPlane().' );
  29679. return this.getPlane( target );
  29680. }
  29681. } );
  29682. Object.assign( Triangle, {
  29683. barycoordFromPoint: function ( point, a, b, c, target ) {
  29684. console.warn( 'THREE.Triangle: .barycoordFromPoint() has been renamed to .getBarycoord().' );
  29685. return Triangle.getBarycoord( point, a, b, c, target );
  29686. },
  29687. normal: function ( a, b, c, target ) {
  29688. console.warn( 'THREE.Triangle: .normal() has been renamed to .getNormal().' );
  29689. return Triangle.getNormal( a, b, c, target );
  29690. }
  29691. } );
  29692. Object.assign( Shape.prototype, {
  29693. extractAllPoints: function ( divisions ) {
  29694. console.warn( 'THREE.Shape: .extractAllPoints() has been removed. Use .extractPoints() instead.' );
  29695. return this.extractPoints( divisions );
  29696. },
  29697. extrude: function ( options ) {
  29698. console.warn( 'THREE.Shape: .extrude() has been removed. Use ExtrudeGeometry() instead.' );
  29699. return new ExtrudeGeometry( this, options );
  29700. },
  29701. makeGeometry: function ( options ) {
  29702. console.warn( 'THREE.Shape: .makeGeometry() has been removed. Use ShapeGeometry() instead.' );
  29703. return new ShapeGeometry( this, options );
  29704. }
  29705. } );
  29706. Object.assign( Vector2.prototype, {
  29707. fromAttribute: function ( attribute, index, offset ) {
  29708. console.warn( 'THREE.Vector2: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29709. return this.fromBufferAttribute( attribute, index, offset );
  29710. },
  29711. distanceToManhattan: function ( v ) {
  29712. console.warn( 'THREE.Vector2: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29713. return this.manhattanDistanceTo( v );
  29714. },
  29715. lengthManhattan: function () {
  29716. console.warn( 'THREE.Vector2: .lengthManhattan() has been renamed to .manhattanLength().' );
  29717. return this.manhattanLength();
  29718. }
  29719. } );
  29720. Object.assign( Vector3.prototype, {
  29721. setEulerFromRotationMatrix: function () {
  29722. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  29723. },
  29724. setEulerFromQuaternion: function () {
  29725. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  29726. },
  29727. getPositionFromMatrix: function ( m ) {
  29728. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  29729. return this.setFromMatrixPosition( m );
  29730. },
  29731. getScaleFromMatrix: function ( m ) {
  29732. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  29733. return this.setFromMatrixScale( m );
  29734. },
  29735. getColumnFromMatrix: function ( index, matrix ) {
  29736. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  29737. return this.setFromMatrixColumn( matrix, index );
  29738. },
  29739. applyProjection: function ( m ) {
  29740. console.warn( 'THREE.Vector3: .applyProjection() has been removed. Use .applyMatrix4( m ) instead.' );
  29741. return this.applyMatrix4( m );
  29742. },
  29743. fromAttribute: function ( attribute, index, offset ) {
  29744. console.warn( 'THREE.Vector3: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29745. return this.fromBufferAttribute( attribute, index, offset );
  29746. },
  29747. distanceToManhattan: function ( v ) {
  29748. console.warn( 'THREE.Vector3: .distanceToManhattan() has been renamed to .manhattanDistanceTo().' );
  29749. return this.manhattanDistanceTo( v );
  29750. },
  29751. lengthManhattan: function () {
  29752. console.warn( 'THREE.Vector3: .lengthManhattan() has been renamed to .manhattanLength().' );
  29753. return this.manhattanLength();
  29754. }
  29755. } );
  29756. Object.assign( Vector4.prototype, {
  29757. fromAttribute: function ( attribute, index, offset ) {
  29758. console.warn( 'THREE.Vector4: .fromAttribute() has been renamed to .fromBufferAttribute().' );
  29759. return this.fromBufferAttribute( attribute, index, offset );
  29760. },
  29761. lengthManhattan: function () {
  29762. console.warn( 'THREE.Vector4: .lengthManhattan() has been renamed to .manhattanLength().' );
  29763. return this.manhattanLength();
  29764. }
  29765. } );
  29766. //
  29767. Object.assign( Geometry.prototype, {
  29768. computeTangents: function () {
  29769. console.error( 'THREE.Geometry: .computeTangents() has been removed.' );
  29770. },
  29771. computeLineDistances: function () {
  29772. console.error( 'THREE.Geometry: .computeLineDistances() has been removed. Use THREE.Line.computeLineDistances() instead.' );
  29773. },
  29774. applyMatrix: function ( matrix ) {
  29775. console.warn( 'THREE.Geometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  29776. return this.applyMatrix4( matrix );
  29777. }
  29778. } );
  29779. Object.assign( Object3D.prototype, {
  29780. getChildByName: function ( name ) {
  29781. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  29782. return this.getObjectByName( name );
  29783. },
  29784. renderDepth: function () {
  29785. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  29786. },
  29787. translate: function ( distance, axis ) {
  29788. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  29789. return this.translateOnAxis( axis, distance );
  29790. },
  29791. getWorldRotation: function () {
  29792. console.error( 'THREE.Object3D: .getWorldRotation() has been removed. Use THREE.Object3D.getWorldQuaternion( target ) instead.' );
  29793. },
  29794. applyMatrix: function ( matrix ) {
  29795. console.warn( 'THREE.Object3D: .applyMatrix() has been renamed to .applyMatrix4().' );
  29796. return this.applyMatrix4( matrix );
  29797. }
  29798. } );
  29799. Object.defineProperties( Object3D.prototype, {
  29800. eulerOrder: {
  29801. get: function () {
  29802. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29803. return this.rotation.order;
  29804. },
  29805. set: function ( value ) {
  29806. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  29807. this.rotation.order = value;
  29808. }
  29809. },
  29810. useQuaternion: {
  29811. get: function () {
  29812. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29813. },
  29814. set: function () {
  29815. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  29816. }
  29817. }
  29818. } );
  29819. Object.assign( Mesh.prototype, {
  29820. setDrawMode: function () {
  29821. console.error( 'THREE.Mesh: .setDrawMode() has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29822. },
  29823. } );
  29824. Object.defineProperties( Mesh.prototype, {
  29825. drawMode: {
  29826. get: function () {
  29827. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode.' );
  29828. return TrianglesDrawMode;
  29829. },
  29830. set: function () {
  29831. console.error( 'THREE.Mesh: .drawMode has been removed. The renderer now always assumes THREE.TrianglesDrawMode. Transform your geometry via BufferGeometryUtils.toTrianglesDrawMode() if necessary.' );
  29832. }
  29833. }
  29834. } );
  29835. Object.defineProperties( LOD.prototype, {
  29836. objects: {
  29837. get: function () {
  29838. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  29839. return this.levels;
  29840. }
  29841. }
  29842. } );
  29843. Object.defineProperty( Skeleton.prototype, 'useVertexTexture', {
  29844. get: function () {
  29845. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29846. },
  29847. set: function () {
  29848. console.warn( 'THREE.Skeleton: useVertexTexture has been removed.' );
  29849. }
  29850. } );
  29851. SkinnedMesh.prototype.initBones = function () {
  29852. console.error( 'THREE.SkinnedMesh: initBones() has been removed.' );
  29853. };
  29854. Object.defineProperty( Curve.prototype, '__arcLengthDivisions', {
  29855. get: function () {
  29856. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29857. return this.arcLengthDivisions;
  29858. },
  29859. set: function ( value ) {
  29860. console.warn( 'THREE.Curve: .__arcLengthDivisions is now .arcLengthDivisions.' );
  29861. this.arcLengthDivisions = value;
  29862. }
  29863. } );
  29864. //
  29865. PerspectiveCamera.prototype.setLens = function ( focalLength, filmGauge ) {
  29866. console.warn( 'THREE.PerspectiveCamera.setLens is deprecated. ' +
  29867. 'Use .setFocalLength and .filmGauge for a photographic setup.' );
  29868. if ( filmGauge !== undefined ) this.filmGauge = filmGauge;
  29869. this.setFocalLength( focalLength );
  29870. };
  29871. //
  29872. Object.defineProperties( Light.prototype, {
  29873. onlyShadow: {
  29874. set: function () {
  29875. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  29876. }
  29877. },
  29878. shadowCameraFov: {
  29879. set: function ( value ) {
  29880. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  29881. this.shadow.camera.fov = value;
  29882. }
  29883. },
  29884. shadowCameraLeft: {
  29885. set: function ( value ) {
  29886. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  29887. this.shadow.camera.left = value;
  29888. }
  29889. },
  29890. shadowCameraRight: {
  29891. set: function ( value ) {
  29892. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  29893. this.shadow.camera.right = value;
  29894. }
  29895. },
  29896. shadowCameraTop: {
  29897. set: function ( value ) {
  29898. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  29899. this.shadow.camera.top = value;
  29900. }
  29901. },
  29902. shadowCameraBottom: {
  29903. set: function ( value ) {
  29904. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  29905. this.shadow.camera.bottom = value;
  29906. }
  29907. },
  29908. shadowCameraNear: {
  29909. set: function ( value ) {
  29910. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  29911. this.shadow.camera.near = value;
  29912. }
  29913. },
  29914. shadowCameraFar: {
  29915. set: function ( value ) {
  29916. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  29917. this.shadow.camera.far = value;
  29918. }
  29919. },
  29920. shadowCameraVisible: {
  29921. set: function () {
  29922. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  29923. }
  29924. },
  29925. shadowBias: {
  29926. set: function ( value ) {
  29927. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  29928. this.shadow.bias = value;
  29929. }
  29930. },
  29931. shadowDarkness: {
  29932. set: function () {
  29933. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  29934. }
  29935. },
  29936. shadowMapWidth: {
  29937. set: function ( value ) {
  29938. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  29939. this.shadow.mapSize.width = value;
  29940. }
  29941. },
  29942. shadowMapHeight: {
  29943. set: function ( value ) {
  29944. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  29945. this.shadow.mapSize.height = value;
  29946. }
  29947. }
  29948. } );
  29949. //
  29950. Object.defineProperties( BufferAttribute.prototype, {
  29951. length: {
  29952. get: function () {
  29953. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Use .count instead.' );
  29954. return this.array.length;
  29955. }
  29956. },
  29957. dynamic: {
  29958. get: function () {
  29959. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29960. return this.usage === DynamicDrawUsage;
  29961. },
  29962. set: function ( /* value */ ) {
  29963. console.warn( 'THREE.BufferAttribute: .dynamic has been deprecated. Use .usage instead.' );
  29964. this.setUsage( DynamicDrawUsage );
  29965. }
  29966. }
  29967. } );
  29968. Object.assign( BufferAttribute.prototype, {
  29969. setDynamic: function ( value ) {
  29970. //console.warn( 'THREE.BufferAttribute: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  29971. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  29972. return this;
  29973. },
  29974. copyIndicesArray: function ( /* indices */ ) {
  29975. console.error( 'THREE.BufferAttribute: .copyIndicesArray() has been removed.' );
  29976. },
  29977. setArray: function ( /* array */ ) {
  29978. console.error( 'THREE.BufferAttribute: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  29979. }
  29980. } );
  29981. Object.assign( BufferGeometry.prototype, {
  29982. addIndex: function ( index ) {
  29983. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  29984. this.setIndex( index );
  29985. },
  29986. addAttribute: function ( name, attribute ) {
  29987. console.warn( 'THREE.BufferGeometry: .addAttribute() has been renamed to .setAttribute().' );
  29988. if ( ! ( attribute && attribute.isBufferAttribute ) && ! ( attribute && attribute.isInterleavedBufferAttribute ) ) {
  29989. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  29990. return this.setAttribute( name, new BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  29991. }
  29992. if ( name === 'index' ) {
  29993. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  29994. this.setIndex( attribute );
  29995. return this;
  29996. }
  29997. return this.setAttribute( name, attribute );
  29998. },
  29999. addDrawCall: function ( start, count, indexOffset ) {
  30000. if ( indexOffset !== undefined ) {
  30001. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  30002. }
  30003. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  30004. this.addGroup( start, count );
  30005. },
  30006. clearDrawCalls: function () {
  30007. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  30008. this.clearGroups();
  30009. },
  30010. computeTangents: function () {
  30011. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  30012. },
  30013. computeOffsets: function () {
  30014. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  30015. },
  30016. removeAttribute: function ( name ) {
  30017. console.warn( 'THREE.BufferGeometry: .removeAttribute() has been renamed to .deleteAttribute().' );
  30018. return this.deleteAttribute( name );
  30019. },
  30020. applyMatrix: function ( matrix ) {
  30021. console.warn( 'THREE.BufferGeometry: .applyMatrix() has been renamed to .applyMatrix4().' );
  30022. return this.applyMatrix4( matrix );
  30023. }
  30024. } );
  30025. Object.defineProperties( BufferGeometry.prototype, {
  30026. drawcalls: {
  30027. get: function () {
  30028. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  30029. return this.groups;
  30030. }
  30031. },
  30032. offsets: {
  30033. get: function () {
  30034. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  30035. return this.groups;
  30036. }
  30037. }
  30038. } );
  30039. Object.defineProperties( InstancedBufferGeometry.prototype, {
  30040. maxInstancedCount: {
  30041. get: function () {
  30042. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30043. return this.instanceCount;
  30044. },
  30045. set: function ( value ) {
  30046. console.warn( 'THREE.InstancedBufferGeometry: .maxInstancedCount has been renamed to .instanceCount.' );
  30047. this.instanceCount = value;
  30048. }
  30049. }
  30050. } );
  30051. Object.defineProperties( Raycaster.prototype, {
  30052. linePrecision: {
  30053. get: function () {
  30054. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30055. return this.params.Line.threshold;
  30056. },
  30057. set: function ( value ) {
  30058. console.warn( 'THREE.Raycaster: .linePrecision has been deprecated. Use .params.Line.threshold instead.' );
  30059. this.params.Line.threshold = value;
  30060. }
  30061. }
  30062. } );
  30063. Object.defineProperties( InterleavedBuffer.prototype, {
  30064. dynamic: {
  30065. get: function () {
  30066. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30067. return this.usage === DynamicDrawUsage;
  30068. },
  30069. set: function ( value ) {
  30070. console.warn( 'THREE.InterleavedBuffer: .length has been deprecated. Use .usage instead.' );
  30071. this.setUsage( value );
  30072. }
  30073. }
  30074. } );
  30075. Object.assign( InterleavedBuffer.prototype, {
  30076. setDynamic: function ( value ) {
  30077. console.warn( 'THREE.InterleavedBuffer: .setDynamic() has been deprecated. Use .setUsage() instead.' );
  30078. this.setUsage( value === true ? DynamicDrawUsage : StaticDrawUsage );
  30079. return this;
  30080. },
  30081. setArray: function ( /* array */ ) {
  30082. console.error( 'THREE.InterleavedBuffer: .setArray has been removed. Use BufferGeometry .setAttribute to replace/resize attribute buffers' );
  30083. }
  30084. } );
  30085. //
  30086. Object.assign( ExtrudeBufferGeometry.prototype, {
  30087. getArrays: function () {
  30088. console.error( 'THREE.ExtrudeBufferGeometry: .getArrays() has been removed.' );
  30089. },
  30090. addShapeList: function () {
  30091. console.error( 'THREE.ExtrudeBufferGeometry: .addShapeList() has been removed.' );
  30092. },
  30093. addShape: function () {
  30094. console.error( 'THREE.ExtrudeBufferGeometry: .addShape() has been removed.' );
  30095. }
  30096. } );
  30097. //
  30098. Object.assign( Scene.prototype, {
  30099. dispose: function () {
  30100. console.error( 'THREE.Scene: .dispose() has been removed.' );
  30101. }
  30102. } );
  30103. //
  30104. Object.defineProperties( Uniform.prototype, {
  30105. dynamic: {
  30106. set: function () {
  30107. console.warn( 'THREE.Uniform: .dynamic has been removed. Use object.onBeforeRender() instead.' );
  30108. }
  30109. },
  30110. onUpdate: {
  30111. value: function () {
  30112. console.warn( 'THREE.Uniform: .onUpdate() has been removed. Use object.onBeforeRender() instead.' );
  30113. return this;
  30114. }
  30115. }
  30116. } );
  30117. //
  30118. Object.defineProperties( Material.prototype, {
  30119. wrapAround: {
  30120. get: function () {
  30121. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30122. },
  30123. set: function () {
  30124. console.warn( 'THREE.Material: .wrapAround has been removed.' );
  30125. }
  30126. },
  30127. overdraw: {
  30128. get: function () {
  30129. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30130. },
  30131. set: function () {
  30132. console.warn( 'THREE.Material: .overdraw has been removed.' );
  30133. }
  30134. },
  30135. wrapRGB: {
  30136. get: function () {
  30137. console.warn( 'THREE.Material: .wrapRGB has been removed.' );
  30138. return new Color();
  30139. }
  30140. },
  30141. shading: {
  30142. get: function () {
  30143. console.error( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30144. },
  30145. set: function ( value ) {
  30146. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  30147. this.flatShading = ( value === FlatShading$1 );
  30148. }
  30149. },
  30150. stencilMask: {
  30151. get: function () {
  30152. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30153. return this.stencilFuncMask;
  30154. },
  30155. set: function ( value ) {
  30156. console.warn( 'THREE.' + this.type + ': .stencilMask has been removed. Use .stencilFuncMask instead.' );
  30157. this.stencilFuncMask = value;
  30158. }
  30159. }
  30160. } );
  30161. Object.defineProperties( MeshPhongMaterial.prototype, {
  30162. metal: {
  30163. get: function () {
  30164. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  30165. return false;
  30166. },
  30167. set: function () {
  30168. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  30169. }
  30170. }
  30171. } );
  30172. Object.defineProperties( MeshPhysicalMaterial.prototype, {
  30173. transparency: {
  30174. get: function () {
  30175. console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' );
  30176. return this.transmission;
  30177. },
  30178. set: function ( value ) {
  30179. console.warn( 'THREE.MeshPhysicalMaterial: .transparency has been renamed to .transmission.' );
  30180. this.transmission = value;
  30181. }
  30182. }
  30183. } );
  30184. Object.defineProperties( ShaderMaterial.prototype, {
  30185. derivatives: {
  30186. get: function () {
  30187. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30188. return this.extensions.derivatives;
  30189. },
  30190. set: function ( value ) {
  30191. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  30192. this.extensions.derivatives = value;
  30193. }
  30194. }
  30195. } );
  30196. //
  30197. Object.assign( WebGLRenderer.prototype, {
  30198. clearTarget: function ( renderTarget, color, depth, stencil ) {
  30199. console.warn( 'THREE.WebGLRenderer: .clearTarget() has been deprecated. Use .setRenderTarget() and .clear() instead.' );
  30200. this.setRenderTarget( renderTarget );
  30201. this.clear( color, depth, stencil );
  30202. },
  30203. animate: function ( callback ) {
  30204. console.warn( 'THREE.WebGLRenderer: .animate() is now .setAnimationLoop().' );
  30205. this.setAnimationLoop( callback );
  30206. },
  30207. getCurrentRenderTarget: function () {
  30208. console.warn( 'THREE.WebGLRenderer: .getCurrentRenderTarget() is now .getRenderTarget().' );
  30209. return this.getRenderTarget();
  30210. },
  30211. getMaxAnisotropy: function () {
  30212. console.warn( 'THREE.WebGLRenderer: .getMaxAnisotropy() is now .capabilities.getMaxAnisotropy().' );
  30213. return this.capabilities.getMaxAnisotropy();
  30214. },
  30215. getPrecision: function () {
  30216. console.warn( 'THREE.WebGLRenderer: .getPrecision() is now .capabilities.precision.' );
  30217. return this.capabilities.precision;
  30218. },
  30219. resetGLState: function () {
  30220. console.warn( 'THREE.WebGLRenderer: .resetGLState() is now .state.reset().' );
  30221. return this.state.reset();
  30222. },
  30223. supportsFloatTextures: function () {
  30224. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  30225. return this.extensions.get( 'OES_texture_float' );
  30226. },
  30227. supportsHalfFloatTextures: function () {
  30228. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  30229. return this.extensions.get( 'OES_texture_half_float' );
  30230. },
  30231. supportsStandardDerivatives: function () {
  30232. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  30233. return this.extensions.get( 'OES_standard_derivatives' );
  30234. },
  30235. supportsCompressedTextureS3TC: function () {
  30236. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  30237. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  30238. },
  30239. supportsCompressedTexturePVRTC: function () {
  30240. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  30241. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  30242. },
  30243. supportsBlendMinMax: function () {
  30244. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  30245. return this.extensions.get( 'EXT_blend_minmax' );
  30246. },
  30247. supportsVertexTextures: function () {
  30248. console.warn( 'THREE.WebGLRenderer: .supportsVertexTextures() is now .capabilities.vertexTextures.' );
  30249. return this.capabilities.vertexTextures;
  30250. },
  30251. supportsInstancedArrays: function () {
  30252. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  30253. return this.extensions.get( 'ANGLE_instanced_arrays' );
  30254. },
  30255. enableScissorTest: function ( boolean ) {
  30256. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  30257. this.setScissorTest( boolean );
  30258. },
  30259. initMaterial: function () {
  30260. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  30261. },
  30262. addPrePlugin: function () {
  30263. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  30264. },
  30265. addPostPlugin: function () {
  30266. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  30267. },
  30268. updateShadowMap: function () {
  30269. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  30270. },
  30271. setFaceCulling: function () {
  30272. console.warn( 'THREE.WebGLRenderer: .setFaceCulling() has been removed.' );
  30273. },
  30274. allocTextureUnit: function () {
  30275. console.warn( 'THREE.WebGLRenderer: .allocTextureUnit() has been removed.' );
  30276. },
  30277. setTexture: function () {
  30278. console.warn( 'THREE.WebGLRenderer: .setTexture() has been removed.' );
  30279. },
  30280. setTexture2D: function () {
  30281. console.warn( 'THREE.WebGLRenderer: .setTexture2D() has been removed.' );
  30282. },
  30283. setTextureCube: function () {
  30284. console.warn( 'THREE.WebGLRenderer: .setTextureCube() has been removed.' );
  30285. },
  30286. getActiveMipMapLevel: function () {
  30287. console.warn( 'THREE.WebGLRenderer: .getActiveMipMapLevel() is now .getActiveMipmapLevel().' );
  30288. return this.getActiveMipmapLevel();
  30289. }
  30290. } );
  30291. Object.defineProperties( WebGLRenderer.prototype, {
  30292. shadowMapEnabled: {
  30293. get: function () {
  30294. return this.shadowMap.enabled;
  30295. },
  30296. set: function ( value ) {
  30297. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  30298. this.shadowMap.enabled = value;
  30299. }
  30300. },
  30301. shadowMapType: {
  30302. get: function () {
  30303. return this.shadowMap.type;
  30304. },
  30305. set: function ( value ) {
  30306. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  30307. this.shadowMap.type = value;
  30308. }
  30309. },
  30310. shadowMapCullFace: {
  30311. get: function () {
  30312. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30313. return undefined;
  30314. },
  30315. set: function ( /* value */ ) {
  30316. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace has been removed. Set Material.shadowSide instead.' );
  30317. }
  30318. },
  30319. context: {
  30320. get: function () {
  30321. console.warn( 'THREE.WebGLRenderer: .context has been removed. Use .getContext() instead.' );
  30322. return this.getContext();
  30323. }
  30324. },
  30325. vr: {
  30326. get: function () {
  30327. console.warn( 'THREE.WebGLRenderer: .vr has been renamed to .xr' );
  30328. return this.xr;
  30329. }
  30330. },
  30331. gammaInput: {
  30332. get: function () {
  30333. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30334. return false;
  30335. },
  30336. set: function () {
  30337. console.warn( 'THREE.WebGLRenderer: .gammaInput has been removed. Set the encoding for textures via Texture.encoding instead.' );
  30338. }
  30339. },
  30340. gammaOutput: {
  30341. get: function () {
  30342. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30343. return false;
  30344. },
  30345. set: function ( value ) {
  30346. console.warn( 'THREE.WebGLRenderer: .gammaOutput has been removed. Set WebGLRenderer.outputEncoding instead.' );
  30347. this.outputEncoding = ( value === true ) ? sRGBEncoding : LinearEncoding;
  30348. }
  30349. },
  30350. toneMappingWhitePoint: {
  30351. get: function () {
  30352. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  30353. return 1.0;
  30354. },
  30355. set: function () {
  30356. console.warn( 'THREE.WebGLRenderer: .toneMappingWhitePoint has been removed.' );
  30357. }
  30358. },
  30359. } );
  30360. Object.defineProperties( WebGLShadowMap.prototype, {
  30361. cullFace: {
  30362. get: function () {
  30363. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30364. return undefined;
  30365. },
  30366. set: function ( /* cullFace */ ) {
  30367. console.warn( 'THREE.WebGLRenderer: .shadowMap.cullFace has been removed. Set Material.shadowSide instead.' );
  30368. }
  30369. },
  30370. renderReverseSided: {
  30371. get: function () {
  30372. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30373. return undefined;
  30374. },
  30375. set: function () {
  30376. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderReverseSided has been removed. Set Material.shadowSide instead.' );
  30377. }
  30378. },
  30379. renderSingleSided: {
  30380. get: function () {
  30381. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30382. return undefined;
  30383. },
  30384. set: function () {
  30385. console.warn( 'THREE.WebGLRenderer: .shadowMap.renderSingleSided has been removed. Set Material.shadowSide instead.' );
  30386. }
  30387. }
  30388. } );
  30389. function WebGLRenderTargetCube( width, height, options ) {
  30390. console.warn( 'THREE.WebGLRenderTargetCube( width, height, options ) is now WebGLCubeRenderTarget( size, options ).' );
  30391. return new WebGLCubeRenderTarget( width, options );
  30392. }
  30393. //
  30394. Object.defineProperties( WebGLRenderTarget.prototype, {
  30395. wrapS: {
  30396. get: function () {
  30397. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30398. return this.texture.wrapS;
  30399. },
  30400. set: function ( value ) {
  30401. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  30402. this.texture.wrapS = value;
  30403. }
  30404. },
  30405. wrapT: {
  30406. get: function () {
  30407. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30408. return this.texture.wrapT;
  30409. },
  30410. set: function ( value ) {
  30411. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  30412. this.texture.wrapT = value;
  30413. }
  30414. },
  30415. magFilter: {
  30416. get: function () {
  30417. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30418. return this.texture.magFilter;
  30419. },
  30420. set: function ( value ) {
  30421. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  30422. this.texture.magFilter = value;
  30423. }
  30424. },
  30425. minFilter: {
  30426. get: function () {
  30427. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30428. return this.texture.minFilter;
  30429. },
  30430. set: function ( value ) {
  30431. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  30432. this.texture.minFilter = value;
  30433. }
  30434. },
  30435. anisotropy: {
  30436. get: function () {
  30437. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30438. return this.texture.anisotropy;
  30439. },
  30440. set: function ( value ) {
  30441. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  30442. this.texture.anisotropy = value;
  30443. }
  30444. },
  30445. offset: {
  30446. get: function () {
  30447. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30448. return this.texture.offset;
  30449. },
  30450. set: function ( value ) {
  30451. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  30452. this.texture.offset = value;
  30453. }
  30454. },
  30455. repeat: {
  30456. get: function () {
  30457. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30458. return this.texture.repeat;
  30459. },
  30460. set: function ( value ) {
  30461. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  30462. this.texture.repeat = value;
  30463. }
  30464. },
  30465. format: {
  30466. get: function () {
  30467. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30468. return this.texture.format;
  30469. },
  30470. set: function ( value ) {
  30471. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  30472. this.texture.format = value;
  30473. }
  30474. },
  30475. type: {
  30476. get: function () {
  30477. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30478. return this.texture.type;
  30479. },
  30480. set: function ( value ) {
  30481. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  30482. this.texture.type = value;
  30483. }
  30484. },
  30485. generateMipmaps: {
  30486. get: function () {
  30487. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30488. return this.texture.generateMipmaps;
  30489. },
  30490. set: function ( value ) {
  30491. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  30492. this.texture.generateMipmaps = value;
  30493. }
  30494. }
  30495. } );
  30496. //
  30497. Object.defineProperties( Audio.prototype, {
  30498. load: {
  30499. value: function ( file ) {
  30500. console.warn( 'THREE.Audio: .load has been deprecated. Use THREE.AudioLoader instead.' );
  30501. const scope = this;
  30502. const audioLoader = new AudioLoader();
  30503. audioLoader.load( file, function ( buffer ) {
  30504. scope.setBuffer( buffer );
  30505. } );
  30506. return this;
  30507. }
  30508. },
  30509. startTime: {
  30510. set: function () {
  30511. console.warn( 'THREE.Audio: .startTime is now .play( delay ).' );
  30512. }
  30513. }
  30514. } );
  30515. AudioAnalyser.prototype.getData = function () {
  30516. console.warn( 'THREE.AudioAnalyser: .getData() is now .getFrequencyData().' );
  30517. return this.getFrequencyData();
  30518. };
  30519. //
  30520. CubeCamera.prototype.updateCubeMap = function ( renderer, scene ) {
  30521. console.warn( 'THREE.CubeCamera: .updateCubeMap() is now .update().' );
  30522. return this.update( renderer, scene );
  30523. };
  30524. CubeCamera.prototype.clear = function ( renderer, color, depth, stencil ) {
  30525. console.warn( 'THREE.CubeCamera: .clear() is now .renderTarget.clear().' );
  30526. return this.renderTarget.clear( renderer, color, depth, stencil );
  30527. };
  30528. //
  30529. const GeometryUtils = {
  30530. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  30531. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  30532. let matrix;
  30533. if ( geometry2.isMesh ) {
  30534. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  30535. matrix = geometry2.matrix;
  30536. geometry2 = geometry2.geometry;
  30537. }
  30538. geometry1.merge( geometry2, matrix, materialIndexOffset );
  30539. },
  30540. center: function ( geometry ) {
  30541. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  30542. return geometry.center();
  30543. }
  30544. };
  30545. ImageUtils.crossOrigin = undefined;
  30546. ImageUtils.loadTexture = function ( url, mapping, onLoad, onError ) {
  30547. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  30548. const loader = new TextureLoader();
  30549. loader.setCrossOrigin( this.crossOrigin );
  30550. const texture = loader.load( url, onLoad, undefined, onError );
  30551. if ( mapping ) texture.mapping = mapping;
  30552. return texture;
  30553. };
  30554. ImageUtils.loadTextureCube = function ( urls, mapping, onLoad, onError ) {
  30555. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  30556. const loader = new CubeTextureLoader();
  30557. loader.setCrossOrigin( this.crossOrigin );
  30558. const texture = loader.load( urls, onLoad, undefined, onError );
  30559. if ( mapping ) texture.mapping = mapping;
  30560. return texture;
  30561. };
  30562. ImageUtils.loadCompressedTexture = function () {
  30563. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  30564. };
  30565. ImageUtils.loadCompressedTextureCube = function () {
  30566. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  30567. };
  30568. //
  30569. function CanvasRenderer() {
  30570. console.error( 'THREE.CanvasRenderer has been removed' );
  30571. }
  30572. //
  30573. function JSONLoader() {
  30574. console.error( 'THREE.JSONLoader has been removed.' );
  30575. }
  30576. //
  30577. const SceneUtils = {
  30578. createMultiMaterialObject: function ( /* geometry, materials */ ) {
  30579. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30580. },
  30581. detach: function ( /* child, parent, scene */ ) {
  30582. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30583. },
  30584. attach: function ( /* child, scene, parent */ ) {
  30585. console.error( 'THREE.SceneUtils has been moved to /examples/jsm/utils/SceneUtils.js' );
  30586. }
  30587. };
  30588. //
  30589. function LensFlare() {
  30590. console.error( 'THREE.LensFlare has been moved to /examples/jsm/objects/Lensflare.js' );
  30591. }
  30592. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  30593. /* eslint-disable no-undef */
  30594. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  30595. revision: REVISION,
  30596. } } ) );
  30597. /* eslint-enable no-undef */
  30598. }
  30599. var THREE$1 = /*#__PURE__*/Object.freeze({
  30600. __proto__: null,
  30601. ACESFilmicToneMapping: ACESFilmicToneMapping,
  30602. AddEquation: AddEquation,
  30603. AddOperation: AddOperation,
  30604. AdditiveAnimationBlendMode: AdditiveAnimationBlendMode,
  30605. AdditiveBlending: AdditiveBlending,
  30606. AlphaFormat: AlphaFormat,
  30607. AlwaysDepth: AlwaysDepth,
  30608. AlwaysStencilFunc: AlwaysStencilFunc,
  30609. AmbientLight: AmbientLight,
  30610. AmbientLightProbe: AmbientLightProbe,
  30611. AnimationClip: AnimationClip,
  30612. AnimationLoader: AnimationLoader,
  30613. AnimationMixer: AnimationMixer,
  30614. AnimationObjectGroup: AnimationObjectGroup,
  30615. AnimationUtils: AnimationUtils,
  30616. ArcCurve: ArcCurve,
  30617. ArrayCamera: ArrayCamera,
  30618. ArrowHelper: ArrowHelper,
  30619. Audio: Audio,
  30620. AudioAnalyser: AudioAnalyser,
  30621. AudioContext: AudioContext,
  30622. AudioListener: AudioListener,
  30623. AudioLoader: AudioLoader,
  30624. AxesHelper: AxesHelper,
  30625. AxisHelper: AxisHelper,
  30626. BackSide: BackSide,
  30627. BasicDepthPacking: BasicDepthPacking,
  30628. BasicShadowMap: BasicShadowMap,
  30629. BinaryTextureLoader: BinaryTextureLoader,
  30630. Bone: Bone,
  30631. BooleanKeyframeTrack: BooleanKeyframeTrack,
  30632. BoundingBoxHelper: BoundingBoxHelper,
  30633. Box2: Box2,
  30634. Box3: Box3,
  30635. Box3Helper: Box3Helper,
  30636. BoxBufferGeometry: BoxBufferGeometry,
  30637. BoxGeometry: BoxGeometry,
  30638. BoxHelper: BoxHelper,
  30639. BufferAttribute: BufferAttribute,
  30640. BufferGeometry: BufferGeometry,
  30641. BufferGeometryLoader: BufferGeometryLoader,
  30642. ByteType: ByteType,
  30643. Cache: Cache,
  30644. Camera: Camera,
  30645. CameraHelper: CameraHelper,
  30646. CanvasRenderer: CanvasRenderer,
  30647. CanvasTexture: CanvasTexture,
  30648. CatmullRomCurve3: CatmullRomCurve3,
  30649. CineonToneMapping: CineonToneMapping,
  30650. CircleBufferGeometry: CircleBufferGeometry,
  30651. CircleGeometry: CircleGeometry,
  30652. ClampToEdgeWrapping: ClampToEdgeWrapping,
  30653. Clock: Clock,
  30654. ClosedSplineCurve3: ClosedSplineCurve3,
  30655. Color: Color,
  30656. ColorKeyframeTrack: ColorKeyframeTrack,
  30657. CompressedTexture: CompressedTexture,
  30658. CompressedTextureLoader: CompressedTextureLoader,
  30659. ConeBufferGeometry: ConeBufferGeometry,
  30660. ConeGeometry: ConeGeometry,
  30661. CubeCamera: CubeCamera,
  30662. CubeGeometry: BoxGeometry,
  30663. CubeReflectionMapping: CubeReflectionMapping,
  30664. CubeRefractionMapping: CubeRefractionMapping,
  30665. CubeTexture: CubeTexture,
  30666. CubeTextureLoader: CubeTextureLoader,
  30667. CubeUVReflectionMapping: CubeUVReflectionMapping,
  30668. CubeUVRefractionMapping: CubeUVRefractionMapping,
  30669. CubicBezierCurve: CubicBezierCurve,
  30670. CubicBezierCurve3: CubicBezierCurve3,
  30671. CubicInterpolant: CubicInterpolant,
  30672. CullFaceBack: CullFaceBack,
  30673. CullFaceFront: CullFaceFront,
  30674. CullFaceFrontBack: CullFaceFrontBack,
  30675. CullFaceNone: CullFaceNone,
  30676. Curve: Curve,
  30677. CurvePath: CurvePath,
  30678. CustomBlending: CustomBlending,
  30679. CustomToneMapping: CustomToneMapping,
  30680. CylinderBufferGeometry: CylinderBufferGeometry,
  30681. CylinderGeometry: CylinderGeometry,
  30682. Cylindrical: Cylindrical,
  30683. DataTexture: DataTexture,
  30684. DataTexture2DArray: DataTexture2DArray,
  30685. DataTexture3D: DataTexture3D,
  30686. DataTextureLoader: DataTextureLoader,
  30687. DataUtils: DataUtils,
  30688. DecrementStencilOp: DecrementStencilOp,
  30689. DecrementWrapStencilOp: DecrementWrapStencilOp,
  30690. DefaultLoadingManager: DefaultLoadingManager,
  30691. DepthFormat: DepthFormat,
  30692. DepthStencilFormat: DepthStencilFormat,
  30693. DepthTexture: DepthTexture,
  30694. DirectionalLight: DirectionalLight,
  30695. DirectionalLightHelper: DirectionalLightHelper,
  30696. DiscreteInterpolant: DiscreteInterpolant,
  30697. DodecahedronBufferGeometry: DodecahedronBufferGeometry,
  30698. DodecahedronGeometry: DodecahedronGeometry,
  30699. DoubleSide: DoubleSide,
  30700. DstAlphaFactor: DstAlphaFactor,
  30701. DstColorFactor: DstColorFactor,
  30702. DynamicBufferAttribute: DynamicBufferAttribute,
  30703. DynamicCopyUsage: DynamicCopyUsage,
  30704. DynamicDrawUsage: DynamicDrawUsage,
  30705. DynamicReadUsage: DynamicReadUsage,
  30706. EdgesGeometry: EdgesGeometry,
  30707. EdgesHelper: EdgesHelper,
  30708. EllipseCurve: EllipseCurve,
  30709. EqualDepth: EqualDepth,
  30710. EqualStencilFunc: EqualStencilFunc,
  30711. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  30712. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  30713. Euler: Euler,
  30714. EventDispatcher: EventDispatcher,
  30715. ExtrudeBufferGeometry: ExtrudeBufferGeometry,
  30716. ExtrudeGeometry: ExtrudeGeometry,
  30717. Face3: Face3,
  30718. Face4: Face4,
  30719. FaceColors: FaceColors,
  30720. FileLoader: FileLoader,
  30721. FlatShading: FlatShading$1,
  30722. Float16BufferAttribute: Float16BufferAttribute,
  30723. Float32Attribute: Float32Attribute,
  30724. Float32BufferAttribute: Float32BufferAttribute,
  30725. Float64Attribute: Float64Attribute,
  30726. Float64BufferAttribute: Float64BufferAttribute,
  30727. FloatType: FloatType,
  30728. Fog: Fog,
  30729. FogExp2: FogExp2,
  30730. Font: Font,
  30731. FontLoader: FontLoader,
  30732. FrontSide: FrontSide,
  30733. Frustum: Frustum,
  30734. GLBufferAttribute: GLBufferAttribute,
  30735. GLSL1: GLSL1,
  30736. GLSL3: GLSL3,
  30737. GammaEncoding: GammaEncoding,
  30738. Geometry: Geometry,
  30739. GeometryUtils: GeometryUtils,
  30740. GreaterDepth: GreaterDepth,
  30741. GreaterEqualDepth: GreaterEqualDepth,
  30742. GreaterEqualStencilFunc: GreaterEqualStencilFunc,
  30743. GreaterStencilFunc: GreaterStencilFunc,
  30744. GridHelper: GridHelper,
  30745. Group: Group,
  30746. HalfFloatType: HalfFloatType,
  30747. HemisphereLight: HemisphereLight,
  30748. HemisphereLightHelper: HemisphereLightHelper,
  30749. HemisphereLightProbe: HemisphereLightProbe,
  30750. IcosahedronBufferGeometry: IcosahedronBufferGeometry,
  30751. IcosahedronGeometry: IcosahedronGeometry,
  30752. ImageBitmapLoader: ImageBitmapLoader,
  30753. ImageLoader: ImageLoader,
  30754. ImageUtils: ImageUtils,
  30755. ImmediateRenderObject: ImmediateRenderObject,
  30756. IncrementStencilOp: IncrementStencilOp,
  30757. IncrementWrapStencilOp: IncrementWrapStencilOp,
  30758. InstancedBufferAttribute: InstancedBufferAttribute,
  30759. InstancedBufferGeometry: InstancedBufferGeometry,
  30760. InstancedInterleavedBuffer: InstancedInterleavedBuffer,
  30761. InstancedMesh: InstancedMesh,
  30762. Int16Attribute: Int16Attribute,
  30763. Int16BufferAttribute: Int16BufferAttribute,
  30764. Int32Attribute: Int32Attribute,
  30765. Int32BufferAttribute: Int32BufferAttribute,
  30766. Int8Attribute: Int8Attribute,
  30767. Int8BufferAttribute: Int8BufferAttribute,
  30768. IntType: IntType,
  30769. InterleavedBuffer: InterleavedBuffer,
  30770. InterleavedBufferAttribute: InterleavedBufferAttribute,
  30771. Interpolant: Interpolant,
  30772. InterpolateDiscrete: InterpolateDiscrete,
  30773. InterpolateLinear: InterpolateLinear,
  30774. InterpolateSmooth: InterpolateSmooth,
  30775. InvertStencilOp: InvertStencilOp,
  30776. JSONLoader: JSONLoader,
  30777. KeepStencilOp: KeepStencilOp,
  30778. KeyframeTrack: KeyframeTrack,
  30779. LOD: LOD,
  30780. LatheBufferGeometry: LatheBufferGeometry,
  30781. LatheGeometry: LatheGeometry,
  30782. Layers: Layers,
  30783. LensFlare: LensFlare,
  30784. LessDepth: LessDepth,
  30785. LessEqualDepth: LessEqualDepth,
  30786. LessEqualStencilFunc: LessEqualStencilFunc,
  30787. LessStencilFunc: LessStencilFunc,
  30788. Light: Light,
  30789. LightProbe: LightProbe,
  30790. Line: Line,
  30791. Line3: Line3,
  30792. LineBasicMaterial: LineBasicMaterial,
  30793. LineCurve: LineCurve,
  30794. LineCurve3: LineCurve3,
  30795. LineDashedMaterial: LineDashedMaterial,
  30796. LineLoop: LineLoop,
  30797. LinePieces: LinePieces,
  30798. LineSegments: LineSegments,
  30799. LineStrip: LineStrip,
  30800. LinearEncoding: LinearEncoding,
  30801. LinearFilter: LinearFilter,
  30802. LinearInterpolant: LinearInterpolant,
  30803. LinearMipMapLinearFilter: LinearMipMapLinearFilter,
  30804. LinearMipMapNearestFilter: LinearMipMapNearestFilter,
  30805. LinearMipmapLinearFilter: LinearMipmapLinearFilter,
  30806. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  30807. LinearToneMapping: LinearToneMapping,
  30808. Loader: Loader,
  30809. LoaderUtils: LoaderUtils,
  30810. LoadingManager: LoadingManager,
  30811. LogLuvEncoding: LogLuvEncoding,
  30812. LoopOnce: LoopOnce,
  30813. LoopPingPong: LoopPingPong,
  30814. LoopRepeat: LoopRepeat,
  30815. LuminanceAlphaFormat: LuminanceAlphaFormat,
  30816. LuminanceFormat: LuminanceFormat,
  30817. MOUSE: MOUSE,
  30818. Material: Material,
  30819. MaterialLoader: MaterialLoader,
  30820. Math: MathUtils,
  30821. MathUtils: MathUtils,
  30822. Matrix3: Matrix3,
  30823. Matrix4: Matrix4,
  30824. MaxEquation: MaxEquation,
  30825. Mesh: Mesh,
  30826. MeshBasicMaterial: MeshBasicMaterial,
  30827. MeshDepthMaterial: MeshDepthMaterial,
  30828. MeshDistanceMaterial: MeshDistanceMaterial,
  30829. MeshFaceMaterial: MeshFaceMaterial,
  30830. MeshLambertMaterial: MeshLambertMaterial,
  30831. MeshMatcapMaterial: MeshMatcapMaterial,
  30832. MeshNormalMaterial: MeshNormalMaterial,
  30833. MeshPhongMaterial: MeshPhongMaterial,
  30834. MeshPhysicalMaterial: MeshPhysicalMaterial,
  30835. MeshStandardMaterial: MeshStandardMaterial,
  30836. MeshToonMaterial: MeshToonMaterial,
  30837. MinEquation: MinEquation,
  30838. MirroredRepeatWrapping: MirroredRepeatWrapping,
  30839. MixOperation: MixOperation,
  30840. MultiMaterial: MultiMaterial,
  30841. MultiplyBlending: MultiplyBlending,
  30842. MultiplyOperation: MultiplyOperation,
  30843. NearestFilter: NearestFilter,
  30844. NearestMipMapLinearFilter: NearestMipMapLinearFilter,
  30845. NearestMipMapNearestFilter: NearestMipMapNearestFilter,
  30846. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  30847. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  30848. NeverDepth: NeverDepth,
  30849. NeverStencilFunc: NeverStencilFunc,
  30850. NoBlending: NoBlending,
  30851. NoColors: NoColors,
  30852. NoToneMapping: NoToneMapping,
  30853. NormalAnimationBlendMode: NormalAnimationBlendMode,
  30854. NormalBlending: NormalBlending,
  30855. NotEqualDepth: NotEqualDepth,
  30856. NotEqualStencilFunc: NotEqualStencilFunc,
  30857. NumberKeyframeTrack: NumberKeyframeTrack,
  30858. Object3D: Object3D,
  30859. ObjectLoader: ObjectLoader,
  30860. ObjectSpaceNormalMap: ObjectSpaceNormalMap,
  30861. OctahedronBufferGeometry: OctahedronBufferGeometry,
  30862. OctahedronGeometry: OctahedronGeometry,
  30863. OneFactor: OneFactor,
  30864. OneMinusDstAlphaFactor: OneMinusDstAlphaFactor,
  30865. OneMinusDstColorFactor: OneMinusDstColorFactor,
  30866. OneMinusSrcAlphaFactor: OneMinusSrcAlphaFactor,
  30867. OneMinusSrcColorFactor: OneMinusSrcColorFactor,
  30868. OrthographicCamera: OrthographicCamera,
  30869. PCFShadowMap: PCFShadowMap,
  30870. PCFSoftShadowMap: PCFSoftShadowMap,
  30871. PMREMGenerator: PMREMGenerator,
  30872. ParametricBufferGeometry: ParametricBufferGeometry,
  30873. ParametricGeometry: ParametricGeometry,
  30874. Particle: Particle,
  30875. ParticleBasicMaterial: ParticleBasicMaterial,
  30876. ParticleSystem: ParticleSystem,
  30877. ParticleSystemMaterial: ParticleSystemMaterial,
  30878. Path: Path,
  30879. PerspectiveCamera: PerspectiveCamera,
  30880. Plane: Plane,
  30881. PlaneBufferGeometry: PlaneBufferGeometry,
  30882. PlaneGeometry: PlaneGeometry,
  30883. PlaneHelper: PlaneHelper,
  30884. PointCloud: PointCloud,
  30885. PointCloudMaterial: PointCloudMaterial,
  30886. PointLight: PointLight,
  30887. PointLightHelper: PointLightHelper,
  30888. Points: Points,
  30889. PointsMaterial: PointsMaterial,
  30890. PolarGridHelper: PolarGridHelper,
  30891. PolyhedronBufferGeometry: PolyhedronBufferGeometry,
  30892. PolyhedronGeometry: PolyhedronGeometry,
  30893. PositionalAudio: PositionalAudio,
  30894. PropertyBinding: PropertyBinding,
  30895. PropertyMixer: PropertyMixer,
  30896. QuadraticBezierCurve: QuadraticBezierCurve,
  30897. QuadraticBezierCurve3: QuadraticBezierCurve3,
  30898. Quaternion: Quaternion,
  30899. QuaternionKeyframeTrack: QuaternionKeyframeTrack,
  30900. QuaternionLinearInterpolant: QuaternionLinearInterpolant,
  30901. REVISION: REVISION,
  30902. RGBADepthPacking: RGBADepthPacking,
  30903. RGBAFormat: RGBAFormat,
  30904. RGBAIntegerFormat: RGBAIntegerFormat,
  30905. RGBA_ASTC_10x10_Format: RGBA_ASTC_10x10_Format,
  30906. RGBA_ASTC_10x5_Format: RGBA_ASTC_10x5_Format,
  30907. RGBA_ASTC_10x6_Format: RGBA_ASTC_10x6_Format,
  30908. RGBA_ASTC_10x8_Format: RGBA_ASTC_10x8_Format,
  30909. RGBA_ASTC_12x10_Format: RGBA_ASTC_12x10_Format,
  30910. RGBA_ASTC_12x12_Format: RGBA_ASTC_12x12_Format,
  30911. RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
  30912. RGBA_ASTC_5x4_Format: RGBA_ASTC_5x4_Format,
  30913. RGBA_ASTC_5x5_Format: RGBA_ASTC_5x5_Format,
  30914. RGBA_ASTC_6x5_Format: RGBA_ASTC_6x5_Format,
  30915. RGBA_ASTC_6x6_Format: RGBA_ASTC_6x6_Format,
  30916. RGBA_ASTC_8x5_Format: RGBA_ASTC_8x5_Format,
  30917. RGBA_ASTC_8x6_Format: RGBA_ASTC_8x6_Format,
  30918. RGBA_ASTC_8x8_Format: RGBA_ASTC_8x8_Format,
  30919. RGBA_BPTC_Format: RGBA_BPTC_Format,
  30920. RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
  30921. RGBA_PVRTC_2BPPV1_Format: RGBA_PVRTC_2BPPV1_Format,
  30922. RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
  30923. RGBA_S3TC_DXT1_Format: RGBA_S3TC_DXT1_Format$1,
  30924. RGBA_S3TC_DXT3_Format: RGBA_S3TC_DXT3_Format,
  30925. RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format$1,
  30926. RGBDEncoding: RGBDEncoding,
  30927. RGBEEncoding: RGBEEncoding,
  30928. RGBEFormat: RGBEFormat,
  30929. RGBFormat: RGBFormat,
  30930. RGBIntegerFormat: RGBIntegerFormat,
  30931. RGBM16Encoding: RGBM16Encoding,
  30932. RGBM7Encoding: RGBM7Encoding,
  30933. RGB_ETC1_Format: RGB_ETC1_Format,
  30934. RGB_ETC2_Format: RGB_ETC2_Format,
  30935. RGB_PVRTC_2BPPV1_Format: RGB_PVRTC_2BPPV1_Format,
  30936. RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
  30937. RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
  30938. RGFormat: RGFormat,
  30939. RGIntegerFormat: RGIntegerFormat,
  30940. RawShaderMaterial: RawShaderMaterial,
  30941. Ray: Ray,
  30942. Raycaster: Raycaster,
  30943. RectAreaLight: RectAreaLight,
  30944. RedFormat: RedFormat,
  30945. RedIntegerFormat: RedIntegerFormat,
  30946. ReinhardToneMapping: ReinhardToneMapping,
  30947. RepeatWrapping: RepeatWrapping,
  30948. ReplaceStencilOp: ReplaceStencilOp,
  30949. ReverseSubtractEquation: ReverseSubtractEquation,
  30950. RingBufferGeometry: RingBufferGeometry,
  30951. RingGeometry: RingGeometry,
  30952. SRGB8_ALPHA8_ASTC_10x10_Format: SRGB8_ALPHA8_ASTC_10x10_Format,
  30953. SRGB8_ALPHA8_ASTC_10x5_Format: SRGB8_ALPHA8_ASTC_10x5_Format,
  30954. SRGB8_ALPHA8_ASTC_10x6_Format: SRGB8_ALPHA8_ASTC_10x6_Format,
  30955. SRGB8_ALPHA8_ASTC_10x8_Format: SRGB8_ALPHA8_ASTC_10x8_Format,
  30956. SRGB8_ALPHA8_ASTC_12x10_Format: SRGB8_ALPHA8_ASTC_12x10_Format,
  30957. SRGB8_ALPHA8_ASTC_12x12_Format: SRGB8_ALPHA8_ASTC_12x12_Format,
  30958. SRGB8_ALPHA8_ASTC_4x4_Format: SRGB8_ALPHA8_ASTC_4x4_Format,
  30959. SRGB8_ALPHA8_ASTC_5x4_Format: SRGB8_ALPHA8_ASTC_5x4_Format,
  30960. SRGB8_ALPHA8_ASTC_5x5_Format: SRGB8_ALPHA8_ASTC_5x5_Format,
  30961. SRGB8_ALPHA8_ASTC_6x5_Format: SRGB8_ALPHA8_ASTC_6x5_Format,
  30962. SRGB8_ALPHA8_ASTC_6x6_Format: SRGB8_ALPHA8_ASTC_6x6_Format,
  30963. SRGB8_ALPHA8_ASTC_8x5_Format: SRGB8_ALPHA8_ASTC_8x5_Format,
  30964. SRGB8_ALPHA8_ASTC_8x6_Format: SRGB8_ALPHA8_ASTC_8x6_Format,
  30965. SRGB8_ALPHA8_ASTC_8x8_Format: SRGB8_ALPHA8_ASTC_8x8_Format,
  30966. Scene: Scene,
  30967. SceneUtils: SceneUtils,
  30968. ShaderChunk: ShaderChunk,
  30969. ShaderLib: ShaderLib,
  30970. ShaderMaterial: ShaderMaterial,
  30971. ShadowMaterial: ShadowMaterial,
  30972. Shape: Shape,
  30973. ShapeBufferGeometry: ShapeBufferGeometry,
  30974. ShapeGeometry: ShapeGeometry,
  30975. ShapePath: ShapePath,
  30976. ShapeUtils: ShapeUtils,
  30977. ShortType: ShortType,
  30978. Skeleton: Skeleton,
  30979. SkeletonHelper: SkeletonHelper,
  30980. SkinnedMesh: SkinnedMesh,
  30981. SmoothShading: SmoothShading,
  30982. Sphere: Sphere,
  30983. SphereBufferGeometry: SphereBufferGeometry,
  30984. SphereGeometry: SphereGeometry,
  30985. Spherical: Spherical,
  30986. SphericalHarmonics3: SphericalHarmonics3,
  30987. Spline: Spline,
  30988. SplineCurve: SplineCurve,
  30989. SplineCurve3: SplineCurve3,
  30990. SpotLight: SpotLight,
  30991. SpotLightHelper: SpotLightHelper,
  30992. Sprite: Sprite$1,
  30993. SpriteMaterial: SpriteMaterial,
  30994. SrcAlphaFactor: SrcAlphaFactor,
  30995. SrcAlphaSaturateFactor: SrcAlphaSaturateFactor,
  30996. SrcColorFactor: SrcColorFactor,
  30997. StaticCopyUsage: StaticCopyUsage,
  30998. StaticDrawUsage: StaticDrawUsage,
  30999. StaticReadUsage: StaticReadUsage,
  31000. StereoCamera: StereoCamera,
  31001. StreamCopyUsage: StreamCopyUsage,
  31002. StreamDrawUsage: StreamDrawUsage,
  31003. StreamReadUsage: StreamReadUsage,
  31004. StringKeyframeTrack: StringKeyframeTrack,
  31005. SubtractEquation: SubtractEquation,
  31006. SubtractiveBlending: SubtractiveBlending,
  31007. TOUCH: TOUCH,
  31008. TangentSpaceNormalMap: TangentSpaceNormalMap,
  31009. TetrahedronBufferGeometry: TetrahedronBufferGeometry,
  31010. TetrahedronGeometry: TetrahedronGeometry,
  31011. TextBufferGeometry: TextBufferGeometry,
  31012. TextGeometry: TextGeometry,
  31013. Texture: Texture,
  31014. TextureLoader: TextureLoader,
  31015. TorusBufferGeometry: TorusBufferGeometry,
  31016. TorusGeometry: TorusGeometry,
  31017. TorusKnotBufferGeometry: TorusKnotBufferGeometry,
  31018. TorusKnotGeometry: TorusKnotGeometry,
  31019. Triangle: Triangle,
  31020. TriangleFanDrawMode: TriangleFanDrawMode,
  31021. TriangleStripDrawMode: TriangleStripDrawMode,
  31022. TrianglesDrawMode: TrianglesDrawMode,
  31023. TubeBufferGeometry: TubeBufferGeometry,
  31024. TubeGeometry: TubeGeometry,
  31025. UVMapping: UVMapping,
  31026. Uint16Attribute: Uint16Attribute,
  31027. Uint16BufferAttribute: Uint16BufferAttribute,
  31028. Uint32Attribute: Uint32Attribute,
  31029. Uint32BufferAttribute: Uint32BufferAttribute,
  31030. Uint8Attribute: Uint8Attribute,
  31031. Uint8BufferAttribute: Uint8BufferAttribute,
  31032. Uint8ClampedAttribute: Uint8ClampedAttribute,
  31033. Uint8ClampedBufferAttribute: Uint8ClampedBufferAttribute,
  31034. Uniform: Uniform,
  31035. UniformsLib: UniformsLib,
  31036. UniformsUtils: UniformsUtils,
  31037. UnsignedByteType: UnsignedByteType,
  31038. UnsignedInt248Type: UnsignedInt248Type$1,
  31039. UnsignedIntType: UnsignedIntType,
  31040. UnsignedShort4444Type: UnsignedShort4444Type,
  31041. UnsignedShort5551Type: UnsignedShort5551Type,
  31042. UnsignedShort565Type: UnsignedShort565Type,
  31043. UnsignedShortType: UnsignedShortType,
  31044. VSMShadowMap: VSMShadowMap,
  31045. Vector2: Vector2,
  31046. Vector3: Vector3,
  31047. Vector4: Vector4,
  31048. VectorKeyframeTrack: VectorKeyframeTrack,
  31049. Vertex: Vertex,
  31050. VertexColors: VertexColors,
  31051. VideoTexture: VideoTexture,
  31052. WebGL1Renderer: WebGL1Renderer,
  31053. WebGLCubeRenderTarget: WebGLCubeRenderTarget,
  31054. WebGLMultisampleRenderTarget: WebGLMultisampleRenderTarget,
  31055. WebGLRenderTarget: WebGLRenderTarget,
  31056. WebGLRenderTargetCube: WebGLRenderTargetCube,
  31057. WebGLRenderer: WebGLRenderer,
  31058. WebGLUtils: WebGLUtils,
  31059. WireframeGeometry: WireframeGeometry,
  31060. WireframeHelper: WireframeHelper,
  31061. WrapAroundEnding: WrapAroundEnding,
  31062. XHRLoader: XHRLoader,
  31063. ZeroCurvatureEnding: ZeroCurvatureEnding,
  31064. ZeroFactor: ZeroFactor,
  31065. ZeroSlopeEnding: ZeroSlopeEnding,
  31066. ZeroStencilOp: ZeroStencilOp,
  31067. sRGBEncoding: sRGBEncoding
  31068. });
  31069. var points = [];
  31070. var lines = [];
  31071. var rings = [];
  31072. var precision = 0.1; //容错精度 //正常是0.01 但是在编辑时容易出现交错的线看不出来,导致需要getSliceLines 然后多出新增点
  31073. var getPoint = function(o, type){
  31074. var point;
  31075. if(typeof o == "string" || typeof o == "number")point = points.find(p=> p.ids.includes(o));
  31076. else {
  31077. point = points.find(p=> math.closeTo(p.x , o.x, precision) && math.closeTo(p.y , o.y, precision) );
  31078. if(!point) point = new Point(o.x, o.y,{record:true, id:o.id}, type);
  31079. else {
  31080. //console.log('addPoint', point, o)
  31081. point.addPoint(o.id);
  31082. }
  31083. }
  31084. if(!point){
  31085. console.log("no point!");
  31086. }
  31087. return point
  31088. };
  31089. var getLine = function(id){
  31090. return lines.find(line=> line.ids.includes(id));
  31091. };
  31092. var getAngleInfo = function(points){
  31093. var info = {};
  31094. info.angle = points[1].clone().sub(points[0]).angle();
  31095. if(math.closeTo(info.angle, Math.PI*2)){ //如360-0.01
  31096. info.angle -= Math.PI*2; //有可能得到负数-0.001
  31097. }else if(info.angle > Math.PI || math.closeTo(info.angle, Math.PI)){//如180+-0.01
  31098. info.angle -= Math.PI;
  31099. info.reverse = true;
  31100. }
  31101. return info //结果大约是 0 - 3.14
  31102. };
  31103. class Point extends Vector2{
  31104. constructor(x, y, o={}){
  31105. super(x, y);
  31106. if(o.record){
  31107. this.id = o.id;
  31108. if(this.id == void 0) this.id = "add_"+points.length;
  31109. this.ids = [this.id] ;//存储拥有该坐标的点原始数据的id
  31110. points.push(this);
  31111. }
  31112. this.type = o.type || "";
  31113. this.lines = [];
  31114. }
  31115. addPoint(id){
  31116. this.ids.push(id);
  31117. }
  31118. searchLineByFactor(dir, type, comeLine){
  31119. var lines = this.lines.filter(line=>line.searchTime<2);
  31120. if(lines.length==0)return;
  31121. else if(lines.length==1)return lines[0];
  31122. else lines = lines.filter(line=>line!=comeLine);
  31123. if(lines.length==1)return lines[0];
  31124. var result;
  31125. lines.forEach(line=>{
  31126. var vec = line.getVector();
  31127. if(line.points[1] == this) vec.negate();
  31128. var factor = math.getVec2Angle(dir, vec);
  31129. if(new Vector3(dir.x, dir.y, 0).cross(new Vector3(vec.x, vec.y, 0)).z<0) factor*= -1; /////
  31130. if(!result){
  31131. result = {line, factor};
  31132. }
  31133. else {
  31134. if(type == "min" && factor<result.factor || type == "max" && factor>result.factor) result = {line, factor};
  31135. }
  31136. });
  31137. return result.line;
  31138. }
  31139. }
  31140. var lineLen=0;
  31141. class Line$1{
  31142. constructor(o){
  31143. if(o.points[0] == o.points[1])return;
  31144. this.points = o.points;
  31145. this.type = o.type || 'line';
  31146. if(this.type == 'line'){
  31147. var oldLine = lines.find(line=>line.points.includes(o.points[0]) && line.points.includes(o.points[1]));
  31148. if(oldLine){
  31149. o.id != void 0 && oldLine.ids.push(o.id);
  31150. return oldLine;
  31151. }
  31152. this.id = o.id == void 0 ? ("line"+lineLen ++) : o.id;
  31153. this.ids = [this.id];
  31154. o.dontWriteToPoint || this.points.forEach((point)=>{point.lines.push(this);});
  31155. o.isChild || lines.push(this);
  31156. this.searchTime = 0; // 最多两次
  31157. }
  31158. this.children = [];//分割
  31159. this.parents = [];//分割
  31160. this.match = [];
  31161. }
  31162. getAngleInfo(){
  31163. var angleInfo = getAngleInfo(this.points);
  31164. this.angle = angleInfo.angle;
  31165. this.reverse = angleInfo.reverse;
  31166. }
  31167. getIntersectWithLine(line, precision){
  31168. var joint = line.points.find(point=>this.points.includes(point));
  31169. if(joint)return {point:joint, type:"joint"};
  31170. var intersect = math.isLineIntersect( line.points , this.points , false, precision );
  31171. if(intersect) return {point: intersect, type:"intersect"};
  31172. }
  31173. writeToPoint(){
  31174. this.points.forEach((point)=>{point.lines.includes(this) || point.lines.push(this);});
  31175. }
  31176. checkIfParent(line){
  31177. if(this == line){
  31178. return true;//原因就是slice的点和端点很近 误差导致
  31179. }
  31180. else return this.parents.find(e=>e.checkIfParent(line))
  31181. }
  31182. splitByPoint(point){
  31183. var line1 = new Line$1({points:[point, this.points[0]], dontWriteToPoint:true, hasntsure:true});
  31184. var line2 = new Line$1({points:[point, this.points[1]], dontWriteToPoint:true, hasntsure:true});
  31185. if(!line1.points || !line2.points){//有至少一个是点相同的,没写到group.lines里
  31186. console.warn('splitByPoint 线有点相同');
  31187. return;
  31188. }
  31189. if(this.checkIfParent(line1)||this.checkIfParent(line2) || line1.checkIfParent(this) || line2.checkIfParent(this)){
  31190. console.warn("splitByPoint 发现parent和children一样");//,请检查getSliceWalls,尤其 if(math.closeTo(line1.angle,line2.angle)){ 处
  31191. return;
  31192. }
  31193. var deal = (line)=>{
  31194. this.children.push(line);
  31195. line.parents.push(this);
  31196. if(!lines.includes(line))lines.push(line);
  31197. line.writeToPoint();
  31198. };
  31199. deal(line1);
  31200. deal(line2);
  31201. var index = this.points[0].lines.indexOf(this);
  31202. index > -1 && this.points[0].lines.splice(index,1);
  31203. var index = this.points[1].lines.indexOf(this);
  31204. index > -1 && this.points[1].lines.splice(index,1);
  31205. return [line1,line2]
  31206. }
  31207. splitByPoints(points){
  31208. points = points.map(point=>{return {dis:point.distanceTo(this.points[0]), point:point}});
  31209. points.sort((point1, point2)=>{return point1.dis - point2.dis});
  31210. var children = [];
  31211. points.forEach((point, index)=>{
  31212. var line1 = new Line$1({points:[point.point, index==0?this.points[0]:points[index-1].point ],group:this.group , dontWriteToPoint:true, hasntsure:true});
  31213. children.push(line1);
  31214. });
  31215. var line2 = new Line$1({points:[points[points.length-1].point, this.points[1] ],group:this.group , dontWriteToPoint:true, hasntsure:true});
  31216. children.push(line2);
  31217. var a = children.find(line=> !line.points || this.checkIfParent(line) || line.checkIfParent(this));
  31218. if(a){
  31219. console.error("splitByPoints return");
  31220. return;
  31221. }
  31222. children.forEach(line=>{
  31223. this.children.push(line);
  31224. line.parents.push(this);
  31225. if(!lines.includes(line))lines.push(line);
  31226. line.writeToPoint();
  31227. line.writeToPoint();
  31228. });
  31229. var index = this.points[0].lines.indexOf(this);
  31230. index > -1 && this.points[0].lines.splice(index,1);
  31231. var index = this.points[1].lines.indexOf(this);
  31232. index > -1 && this.points[1].lines.splice(index,1);
  31233. }
  31234. getAllSlices(){//如果有被分割的片段 就返回片段,否则返回自身
  31235. var children = [];
  31236. var traverse = function(elem){
  31237. if(elem.children.length == 0) children.push(elem);
  31238. else elem.children.forEach(traverse);
  31239. };
  31240. traverse(this);
  31241. return children
  31242. }
  31243. getVector(){
  31244. return this.points[1].clone().sub(this.points[0]);
  31245. }
  31246. getLength(){
  31247. return this.points[0].distanceTo(this.points[1])
  31248. }
  31249. getCenter(){
  31250. return this.points[1].clone().add(this.points[0]).multiplyScalar(.5);
  31251. }
  31252. }
  31253. var getMixedSet = function(arr1, arr2){//交集
  31254. return arr1.filter(item=>arr2.includes(item));
  31255. };
  31256. var getUnionSet = function(arr1, arr2){//并集
  31257. return arr1.concat(arr2.filter(item=>!arr1.includes(item)))
  31258. };
  31259. var getDifferenceSet = function(arr1, arr2){//差集
  31260. var arr11 = arr1.filter(item=>!arr2.includes(item));
  31261. var arr22 = arr2.filter(item=>!arr1.includes(item));
  31262. return arr11.concat(arr22)
  31263. };
  31264. var getDifferenceSetMuti = function(arr){//收集绝对没有重复的元素,也就是判断出现次数=1的
  31265. var set = [];
  31266. arr.forEach(arr1=>{
  31267. arr1.forEach(item=>{
  31268. var index = set.indexOf(item);
  31269. if(index>-1){
  31270. set.splice(index, 1);
  31271. }else {
  31272. set.push(item);
  31273. }
  31274. });
  31275. });
  31276. return set;
  31277. };
  31278. function DoorAtWhichLine(points, lines){
  31279. var mid = points[0].clone().add(points[1]).multiplyScalar(0.5);
  31280. lines = lines.filter(line=>math.ifPointAtLineBound(mid, line.points, precision));
  31281. if(lines.length == 0)return
  31282. var result = {line:null, dis:Infinity};
  31283. lines.forEach(line=>{
  31284. var foot = math.getFootPoint(mid, line.points[0], line.points[1] );
  31285. var dis = foot.distanceTo(mid);
  31286. if(dis<result.dis){
  31287. result.line = line; result.dis = dis;
  31288. }
  31289. });
  31290. return result
  31291. }
  31292. var ringLen = 0;
  31293. class Ring{
  31294. constructor(o){
  31295. this.id = ringLen ++;
  31296. this.type = o.type || 'normal';
  31297. this.points = o.points;
  31298. this.lines = o.lines;
  31299. rings.push(this);
  31300. this.child = [];//包含的环
  31301. this.parent = [];//被包含的环
  31302. this.smallNeibours = [];//相邻最小环(存在和它有一个以上的相同边的最小环)
  31303. var area = math.getArea(this.points);
  31304. this.area = Math.abs(area);
  31305. this.isClockwise = area<0;//是否逆时针。一般都是逆时针得到的,如果是顺时针,可能是贪吃蛇的情况,可能不是最小环,需要去掉。
  31306. }
  31307. }
  31308. var findLine = function(p1,p2){
  31309. return lines.find(line=>line.points.includes(p1) && line.points.includes(p2) )
  31310. };
  31311. var ifSamePart = function(checkPart , part){//checkPart中所包含的part片段是否和基准part的顺序一样(逆序也可以, 中间有其他数也可以,起始不同也行。比如 01234和204一样的)
  31312. var axis, startIndex, newCheckPart=[];
  31313. for(var j=0,len1 = checkPart.length; j<len1; j++){//将checkPart中比part多的数除去,使两个数组中包含的数完全相同。
  31314. if(part.indexOf(checkPart[j])>-1)newCheckPart.push(checkPart[j]);
  31315. }
  31316. for(var i=0,len = part.length; i<len; i++){
  31317. var index = newCheckPart.indexOf(part[i]);
  31318. if(index == -1)return false;
  31319. if(i == 0) startIndex = index;//标记第一个查找点对应的index
  31320. else if(i == 1){//标记查找顺序是正还是逆
  31321. axis = index - startIndex;
  31322. if(axis == len - 1) axis = -1;//刚好是首和尾
  31323. else if(axis == 1- len) axis = 1;
  31324. if(axis != -1 && axis != 1){
  31325. return false
  31326. }
  31327. }else {//判断是否是按顺序的
  31328. if(index != ((startIndex+axis * i + len) % len) ) return false;
  31329. }
  31330. }
  31331. return {sameAxis:axis>0}; //如果一样的话返回正逆是否相同
  31332. };
  31333. //或者判断是否有相同边(但是相同点是可以组成不同环)
  31334. var ifSameRing = function(ring1, ring2){//判断两个环是否相等。 除了可以逆向外顺序要对
  31335. if(ring1 instanceof Ring)ring1 = ring1.points;
  31336. if(ring2 instanceof Ring)ring2 = ring2.points;
  31337. if(ring1.length != ring2.length)return false;
  31338. if(ring1.lines && ring2.lines){
  31339. if(getDifferenceSet(ring1.lines , ring2.lines).length == 0)return true;//差集个数为0
  31340. }else {
  31341. if(ifSamePart(ring1, ring2))return true
  31342. }
  31343. };
  31344. var atWhichChildLine = function(point, line, precision){
  31345. if(line.children.length == 0){//这里可能要放低精度 保证能找到
  31346. if(math.ifPointAtLineBound(point, line.points, precision)) return line;
  31347. }else {
  31348. for(var i=0;i<line.children.length;i++){
  31349. var at = atWhichChildLine(point, line.children[i], precision);
  31350. if(at)return at
  31351. }
  31352. }
  31353. };
  31354. function getSliceLines(){
  31355. var len = lines.length;
  31356. var deal = function(line1,line2){
  31357. if(line1 == line2)return;
  31358. if(line1.angle == void 0) line1.getAngleInfo();
  31359. if(line2.angle == void 0) line2.getAngleInfo();
  31360. var intersect = line1.getIntersectWithLine(line2, precision);
  31361. if(intersect){
  31362. var point; //得到交点
  31363. if(intersect.type == "intersect"){
  31364. point = getPoint(intersect.point, "whenGetSliceLines");
  31365. var line1_ = atWhichChildLine(point, line1);
  31366. var line2_ = atWhichChildLine(point, line2);
  31367. //重合的情况还没考虑(平行)
  31368. if(!line1_) line1_ = atWhichChildLine(point, line1, precision);//降低精度
  31369. if(!line1_) line1_ = atWhichChildLine(point, line1, precision*2);//降低精度
  31370. if(!line2_) line2_ = atWhichChildLine(point, line2, precision);
  31371. if(!line2_) line2_ = atWhichChildLine(point, line2, precision*2);//降低精度
  31372. //拆分线条:
  31373. //如果还报错,找不到ChildLine,就直接返回吧 或者搞个循环 逐渐降低精度
  31374. if(!line1_ || !line2_){
  31375. console.warn("atWhichChildLine仍旧找不到 :" + line1.id + ',' + line2.id + ", pointId: "+point.id);
  31376. line1_ || console.warn("找不到line1");
  31377. line2_ || console.warn("找不到line2");
  31378. return;
  31379. }
  31380. if(line1_.points.find(p=>p == point) && line2_.points.find(p=>p == point)){//这个点是line1_、 line2_端点,不做处理
  31381. //console.log("joint型 "+point.id)
  31382. }else if(line1_.points.find(p=>p == point)){//T型交叉
  31383. line2_.splitByPoint(point);//加入到母线中,之后还先用母线判断交点
  31384. //console.log("T型交叉1 "+point.id)
  31385. }else if(line2_.points.find(p=>p == point)){//T型交叉
  31386. line1_.splitByPoint(point);
  31387. //console.log("T型交叉2 "+point.id)
  31388. }else {//十字交叉
  31389. line1_.splitByPoint(point);
  31390. line2_.splitByPoint(point);
  31391. }
  31392. }else {
  31393. point = intersect.point;//交点是端点
  31394. if(math.closeTo(line1.angle,line2.angle)){ //重合一部分
  31395. var children1 = line1.getAllSlices();
  31396. var children2 = line2.getAllSlices();
  31397. if(children1.length>1 || children2.length>1){ //使用最小分割片段来比较
  31398. children1.forEach(child1=>{
  31399. children2.forEach(child2=>{
  31400. deal(child1, child2);
  31401. });
  31402. });
  31403. return;
  31404. }
  31405. var anotherPoint1 = line1.points.find(point_=>point_!=point);
  31406. var anotherPoint2 = line2.points.find(point_=>point_!=point);
  31407. if(math.ifPointAtLineBound(anotherPoint1, line2.points)){
  31408. line2.splitByPoint(anotherPoint1);
  31409. }else if(math.ifPointAtLineBound(anotherPoint2, line1.points)){
  31410. line1.splitByPoint(anotherPoint2);
  31411. }
  31412. }
  31413. }
  31414. }else if(math.closeTo(line1.angle,line2.angle)){
  31415. var vec1 = line1.getVector();
  31416. var vec = line1.points[0].clone().sub(line2.points[0]);
  31417. var cos = math.getVec2Cos(vec1, vec);
  31418. if(math.closeTo(cos, -1, 1e-4) || math.closeTo(cos, 1, 1e-4)){ //共线
  31419. var children1 = line1.getAllSlices();
  31420. var children2 = line2.getAllSlices();
  31421. if(children1.length>1 || children2.length>1){ //使用最小分割片段来比较
  31422. children1.forEach(child1=>{
  31423. children2.forEach(child2=>{
  31424. deal(child1, child2);
  31425. });
  31426. });
  31427. return;
  31428. }
  31429. //判断是否重叠
  31430. var A = line1.points[0];
  31431. var C = line1.reverse == line2.reverse ? line2.points[0] : line2.points[1];
  31432. var B = line1.points[1];
  31433. var D = line1.reverse == line2.reverse ? line2.points[1] : line2.points[0];
  31434. var BC = C.clone().sub(B);
  31435. var AD = D.clone().sub(A);
  31436. if(BC.length()<AD.length()){
  31437. var BA = A.clone().sub(B);
  31438. if(math.getVec2Angle(BC, BA) >= 1.57 )return;//没有重叠部分
  31439. }else {
  31440. var AB = B.clone().sub(A);
  31441. if(math.getVec2Angle(AD, AB) >= 1.57 )return;
  31442. }
  31443. var f = function(line1,line2){
  31444. var one = math.ifPointAtLineBound(line1.points[0], line2.points);
  31445. var two = math.ifPointAtLineBound(line1.points[1], line2.points);
  31446. if(one && two){//line1在line2上
  31447. line2.splitByPoints( line1.points );
  31448. return true
  31449. }else if(one || two){//错开
  31450. var point1 = one ? line1.points[0] : line1.points[1];
  31451. var anotherPoint1 = one ? line1.points[1] : line1.points[0];
  31452. var dis1 = line2.points[0].distanceTo(anotherPoint1);
  31453. var dis2 = line2.points[1].distanceTo(anotherPoint1);
  31454. var point2 = dis1 < dis2 ? line2.points[0] : line2.points[1];
  31455. line1.splitByPoint(point2);
  31456. line2.splitByPoint(point1);
  31457. return true
  31458. }
  31459. };
  31460. f(line1, line2) || f(line2, line1);
  31461. }
  31462. }
  31463. };
  31464. for(let i=0;i<len;i++){
  31465. let line1 = lines[i];
  31466. for(let j=i+1;j<len;j++){
  31467. let line2 = lines[j];
  31468. deal(line1,line2);
  31469. }
  31470. }
  31471. //console.log("原有线条个数:"+len)
  31472. //lines = lines.filter((line)=>{return line.children.length == 0})
  31473. //console.log("现有线条个数:"+lines.length)
  31474. }
  31475. var bound = new Box2();
  31476. var build = function(o){
  31477. //融合了相近点
  31478. //根据bound 处理precision
  31479. o.points.forEach(p=>{
  31480. bound.expandByPoint(new Vector2(p.x,p.y));
  31481. });
  31482. if(o.precision != void 0){
  31483. precision = o.precision;
  31484. }else {
  31485. var boundSize = bound.getSize(new Vector2);
  31486. precision = MathUtils.clamp(Math.max(boundSize.x, boundSize.y) / 70, 0.2, 2);
  31487. }
  31488. o.points.forEach(point=>getPoint(point));//{x:..,y:..}
  31489. o.lines.forEach(line=>{ //{p1:id1. p2:id2}
  31490. new Line$1({points:[getPoint(line.p1), getPoint(line.p2)], id:line.id });
  31491. });
  31492. //注意:不能出现一条线的两个点坐标一致,否则寻路时方向出错。 所以手动融合下相近点。
  31493. };
  31494. var searchRings = function(o={}){
  31495. points = [];
  31496. lines = [];
  31497. rings = [];
  31498. lineLen = ringLen = 0;
  31499. o.points = o.points || [];
  31500. o.lines = o.lines || [];
  31501. build(o);
  31502. if(!o.dontSliceLines){
  31503. getSliceLines();
  31504. }
  31505. //查找最小回路:
  31506. //参考: 引入方向因子的最小回路、最大回路搜索算法.pdf
  31507. //方法: 逆时针寻找(标记)最外层大环 -->从走过的点开始逆时针寻找最小环(直到所有可走的路被走过两次)-->逆时针寻找最外层大环(直到所有可走的路被走过两次)-->..
  31508. //其中找大环时选择方向因子最小的路, 而小环则相反(但只有开始第一条路是一样的, 都是选择最左边的点的因子最小的路)。
  31509. //标记方法: 每条线需要被搜索两次才算完毕。搜索完毕的线退出搜索。(依据:搜索完全部最小回路后 , 在无向图中删除搜索过 2 次的边及孤立节点得到退化图 , 恰好构成最大回路。)
  31510. var searchTime = 0;
  31511. var addRingJudgeCount = 0;
  31512. var addRingJudge = function(ring, lines, connectedLines, type){// 处理拣出的片段
  31513. addRingJudgeCount++;
  31514. //console.log("addRingJudge points("+ type+"):"+ ring.map(point=>point.id) )
  31515. if(o.onlyGetOutRing && type == "small")return
  31516. if(type == "small" || o.onlyGetOutRing){//挑出回路:
  31517. var newRings = [];
  31518. while(ring.length){
  31519. var road = [];
  31520. var turnBack = false;
  31521. for(let i=0;i<ring.length;i++){
  31522. if(road.includes(ring[i])){//如果走到方才的点,可能形成回路。 无论是不是回路都要摘去这段。
  31523. var index = road.indexOf(ring[i]);
  31524. var pointArr = ring.slice(index, i);
  31525. var linesArr = lines.slice(index, i);
  31526. ring.splice(index,i-index);
  31527. lines.splice(index,i-index);
  31528. if(pointArr.length>2){// 如果只有两个数,代表原路返回, 如 1->2(->1)
  31529. if( !rings.find(ring_=>ifSameRing(pointArr, ring_))) newRings.push( new Ring({points: pointArr, lines:linesArr}) );
  31530. }
  31531. turnBack = true;
  31532. break;
  31533. }else {
  31534. road.push(ring[i]);
  31535. turnBack = false;
  31536. }
  31537. }
  31538. if(!turnBack){//没有重复的点,那么就直接处理整条。
  31539. if(ring.length>2){// 如果只有两个数,代表原路返回, 如 1->2(->1)
  31540. if( !rings.find(ring_=>ifSameRing(ring, ring_))) newRings.push( new Ring({points: ring, lines}) );
  31541. }
  31542. break;
  31543. }
  31544. }
  31545. if(type != 'small'){
  31546. newRings.forEach(e=>e.isOutRing = true);
  31547. }
  31548. //console.log(newRings)
  31549. }else {
  31550. return ring
  31551. }
  31552. };
  31553. var search = function(point2d, comeRoad, type, connectedLines){
  31554. searchTime++;
  31555. var goLine;
  31556. var direction;
  31557. if(type.includes("big")){
  31558. if(!comeRoad){
  31559. if(type.includes("Left")){//逆时针
  31560. direction = new Vector2(1,0);
  31561. }else {
  31562. direction = new Vector2(-1,0);
  31563. }
  31564. goLine = point2d.searchLineByFactor(direction,"min");
  31565. }else {
  31566. var lastPoint = comeRoad.points[comeRoad.points.length-1];
  31567. direction = point2d.clone().sub(lastPoint);
  31568. goLine = point2d.searchLineByFactor(direction,"min", findLine(point2d, lastPoint));
  31569. }
  31570. }else {
  31571. if(!comeRoad){
  31572. //似乎找最小环时,第一条线也是找最小的因子,这样才能保证逆时针(除非只有顺时针一条路)
  31573. direction = new Vector2(1,0);
  31574. goLine = point2d.searchLineByFactor(direction,"min");
  31575. }else {
  31576. var lastPoint = comeRoad.points[comeRoad.points.length-1];
  31577. direction = point2d.clone().sub(lastPoint);
  31578. goLine = point2d.searchLineByFactor(direction,"max", findLine(point2d, lastPoint));
  31579. }
  31580. }
  31581. if(!goLine)return
  31582. goLine.searchTime++;
  31583. connectedLines.includes(goLine) || connectedLines.push(goLine);
  31584. var nextPoint = goLine.points.find( point => point2d!=point );
  31585. //if( comeRoad && comeRoad.points[comeRoad.points.length - 1] == nextPoint ) return;//不能查找来时的方向(反方向)
  31586. //走不通就原路返回
  31587. var roadPoints = comeRoad ? comeRoad.points.concat([point2d]) : [point2d];//每个分叉都能构成一条新的road
  31588. var roadLines = comeRoad ? comeRoad.lines.concat([goLine]) : [goLine];
  31589. //走到第一个点就算停止,这时候可能得到一个环、或者一段走了两遍的线、或者一条线上带了些环。
  31590. if(nextPoint == roadPoints[0]) return addRingJudge(roadPoints, roadLines, connectedLines, type) //形成环
  31591. else {
  31592. /* var len = roadPoints.indexOf(nextPoint);
  31593. if( len > -1){ //走到走过的路的某一点 构成这段路的回路
  31594. var points = roadPoints.slice(len, roadPoints.length);
  31595. var lines = roadLines.slice(len, roadPoints.length);
  31596. addRingJudge(points, lines)
  31597. }else{ */
  31598. return search(nextPoint, {lines:roadLines, points:roadPoints}, type, connectedLines);//继续寻路
  31599. //}
  31600. }
  31601. };
  31602. while(1){//搜寻一次大环
  31603. var connectedLines = [];//被搜寻过的且searchTime<2的线。一旦全部搜完就说明该连通区域搜寻完毕,继续查下一个连通区域。
  31604. var startPoint = null;
  31605. points.forEach(point=>{//找出x最小的点
  31606. if(!point.lines.find(line=>line.searchTime<2))return;
  31607. if(!startPoint)startPoint = point;
  31608. else if(point.x < startPoint.x)startPoint = point;
  31609. });
  31610. if(!startPoint)break; //说明全部找完
  31611. var ring = search(startPoint, null, "bigLeft", connectedLines);//逆时针
  31612. //search(startPoint, null, "bigRight", connectedLines);//顺时针(为了防止最外层不是回路之前写了顺时针,但如果是回路就会走重复。后来发现只要逆时针即可,因为走完后剩下的可以再次找大环)
  31613. connectedLines = connectedLines.filter(line=>line.searchTime<2);
  31614. while(connectedLines.length>0){//目标是顺着connectedLines把所有连通的小环都找到
  31615. let points_ = [];//connectedLines中所有的点
  31616. connectedLines.forEach(line=>line.points.forEach(point=>{if(!points_.includes(point))points_.push(point); }));
  31617. var startPoint = null;
  31618. points_.forEach(point=>{//找出x最小的点
  31619. if(!point.lines.find(line=>line.searchTime<2))return;
  31620. if(!startPoint)startPoint = point;
  31621. else if(point.x < startPoint.x)startPoint = point;
  31622. });
  31623. if(!startPoint)break;
  31624. search(startPoint, null, "small", connectedLines);
  31625. connectedLines = connectedLines.filter(line=>line.searchTime<2);
  31626. }
  31627. }
  31628. /* if(o.onlyGetOutRing){
  31629. rings = rings.filter(e=>e.isOutRing)
  31630. } */
  31631. //console.log("searchTime "+searchTime + ", addRingJudgeCount " +addRingJudgeCount)
  31632. //找出所有的相邻关系,包括公共边
  31633. var len = rings.length;
  31634. for(let i=0; i<len; i++){
  31635. let ring1 = rings[i];
  31636. for(let j=i+1; j<len; j++){
  31637. let ring2 = rings[j];
  31638. var bothHasLines = getMixedSet(ring1.lines, ring2.lines);
  31639. if(bothHasLines.length){//ring1oíring2?àáú
  31640. ring1.smallNeibours.push(ring2);
  31641. ring2.smallNeibours.push(ring1);
  31642. }else {
  31643. }
  31644. }
  31645. }
  31646. rings.forEach(ring1=>{
  31647. for(let i=0; i<len; i++){
  31648. var ring2 = rings[i];
  31649. if(ring1 == ring2 || ring1.smallNeibours.includes(ring2))continue;
  31650. let inside;
  31651. for(let u=0;u<ring1.points.length;u++){
  31652. inside = math.isPointInArea(ring2.points, null, ring1.points[u]);
  31653. if(!inside)break
  31654. else if(inside && !inside.atLine){
  31655. break
  31656. }
  31657. }
  31658. if(inside){ //只要其中一个点在ring2内,就说明ring1是内环
  31659. if(inside.atLine){//(还是会存在点全在线上的情况,这时候判断中心点)
  31660. var center = math.getCenterOfGravityPoint(ring1.points);
  31661. let inside1 = math.isPointInArea(ring2.points, null, center);
  31662. if(!inside1){
  31663. continue
  31664. }
  31665. }
  31666. ring2.child.push(ring1);
  31667. ring1.parent.push(ring2);
  31668. }
  31669. }
  31670. });
  31671. //去除非最小的ring 是否应该检测parent child?
  31672. /*
  31673. like this:
  31674. |———————————————————————|
  31675. |———|———————|———————| |
  31676. | | | | |
  31677. | |———————|———————| |
  31678. |———————————————————————|
  31679. */
  31680. var wiseRings = rings.filter(r=>!r.isClockwise);//一般都是逆时针得到的,如果是顺时针,可能是贪吃蛇的情况,可能不是最小环,需要去掉。
  31681. if(wiseRings.length > 0){
  31682. //console.log('%c存在非最小的ring! 进行处理:',"color:#00f");
  31683. wiseRings.forEach(ring=>{ //(此案例验证出smallNeibours就是它的最小构成,可以再看看别的案例)
  31684. if(ring.smallNeibours.length>0){//另:如果内部只有一个,说明它是最小环,不需要处理
  31685. var is = false;
  31686. var difference = getDifferenceSet(ring.lines , getDifferenceSetMuti(ring.smallNeibours.concat(ring.child).map(ring=>ring.lines)));//获取所有smallNeibours和child的边中没有重复过的边(就是outline) 和该ring的线比较
  31687. is = difference.every(line=> ring.child.find(r=>r.lines.includes(line)) ); //多出的线只能是child中的线
  31688. if(is){
  31689. console.log('%c删除非最小环 ring'+ring.id,"color:#00f");
  31690. console.log(ring);
  31691. rings.splice(rings.indexOf(ring), 1);
  31692. ring.child.forEach(c=>{var index = c.parent.indexOf(ring);index>-1 && c.parent.splice(index,1);});
  31693. ring.parent.forEach(c=>{var index = c.child.indexOf(ring);index>-1 && c.child.splice(index,1);});
  31694. ring.smallNeibours.forEach(c=>{var index = c.smallNeibours.indexOf(ring);index>-1 && c.smallNeibours.splice(index,1);});
  31695. }
  31696. }
  31697. });
  31698. }
  31699. /* rings = rings.filter(ring=>{
  31700. rings = rings.filter(ring=>{
  31701. var enoughSize = ring.area > 0.5
  31702. if(!enoughSize){console.log('因面积过小去除ring '+ring.id + " , area: "+ring.area)}
  31703. return enoughSize
  31704. })
  31705. rings.forEach(ring=>{
  31706. if(ring.closetChilds){
  31707. ring.closetChilds = ring.closetChilds.filter(e=>rings.includes(e))
  31708. }
  31709. })
  31710. return rings
  31711. }) */ //在dealRings前不能随意删除rings,因为判断是否是最小环时需要全部的环
  31712. rings.forEach(ring=>{ //这里和cad中的不太一样, cad中双数个parent算外环,单数内环; 这里不分内外, 只看有无parent child
  31713. if(ring.parent.length){
  31714. ring.closetParent = ring.parent.find(ring_ => ring_.parent.length == ring.parent.length - 1);//最近一层的大环就是比它的parent个数少一的
  31715. ring.closetParent.closetChilds || (ring.closetParent.closetChilds = []);//内环可能多个
  31716. ring.closetParent.closetChilds.push(ring);
  31717. }
  31718. });
  31719. //console.log(rings)
  31720. var _ring = rings.map(ring=>{
  31721. var data = {
  31722. id: ring.id,
  31723. points: ring.points.map(point=>{return {id: point.ids[0], x:point.x, y:point.y}}),
  31724. /* doors : o.doors.filter(door=>{
  31725. if(ring.closetChilds){
  31726. var childOutLines = getDifferenceSetMuti(ring.closetChilds.map(ring=>ring.lines)) //最近子环的外边
  31727. return ring.lines.concat(childOutLines).includes(door.atLine)
  31728. }else{
  31729. return ring.lines.includes(door.atLine)
  31730. }
  31731. }), */
  31732. area:ring.area,
  31733. closetParent : ring.closetParent && ring.closetParent.id,
  31734. closetChilds : ring.closetChilds && ring.closetChilds.map(e=>e.id)
  31735. };
  31736. return data
  31737. });
  31738. //console.log(JSON.stringify(_ring))
  31739. return _ring
  31740. };
  31741. var easing = {};
  31742. //渐变曲线函数,反应加速度的变化
  31743. //currentTime:x轴当前时间(从0-到duration), startY:起始点, duration:总时长, wholeY:路程 (即endY-startY)
  31744. //参数基本是 x, 0, 1, 1
  31745. /*
  31746. easeOut 基本是y= m * (x-dur)^k + n, 若k为偶数,m<0, 若k为奇数,m>0; (因为偶数的话必须开口向下才能获得斜率递减的递增的那段,而奇数是对称的,单调递增. )
  31747. 根据x=0时y=0, x=dur时y=S , 得 n = S,m = -S/(-dur)^k
  31748. */
  31749. easing.getEaseOut = function(k){// k 是>=2的整数. 越大变化率越大, 相同初始速度所需要时间越久
  31750. let easeFun;
  31751. k = Math.round(k);
  31752. if(k<2){
  31753. k = Math.PI / 2;
  31754. easeFun = easing.easeOutSine;
  31755. }else {
  31756. easeFun = function(currentTime, startY, wholeY, duration) {
  31757. if(k>2){
  31758. console.log(k);
  31759. }
  31760. return -wholeY/Math.pow(-duration, k) * Math.pow(currentTime-duration, k) + wholeY
  31761. };
  31762. }
  31763. return {
  31764. k,
  31765. easeFun
  31766. }
  31767. };
  31768. easing.linearTween = function(currentTime, startY, wholeY, duration) {
  31769. return wholeY * currentTime / duration + startY
  31770. }
  31771. ,
  31772. easing.easeInQuad = function(currentTime, startY, wholeY, duration) {
  31773. return currentTime /= duration,
  31774. wholeY * currentTime * currentTime + startY
  31775. }
  31776. ,
  31777. easing.easeOutQuad = function(currentTime, startY, wholeY, duration) { // 如套上实际的距离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
  31778. return currentTime /= duration,
  31779. -wholeY * currentTime * (currentTime - 2) + startY
  31780. }
  31781. ,
  31782. easing.easeInOutQuad = function(currentTime, startY, wholeY, duration) {
  31783. return currentTime /= duration / 2,
  31784. currentTime < 1 ? wholeY / 2 * currentTime * currentTime + startY : (currentTime--,
  31785. -wholeY / 2 * (currentTime * (currentTime - 2) - 1) + startY)
  31786. }
  31787. ,
  31788. easing.easeInCubic = function(currentTime, startY, wholeY, duration) {
  31789. return currentTime /= duration,
  31790. wholeY * currentTime * currentTime * currentTime + startY
  31791. }
  31792. ,
  31793. easing.easeOutCubic = function(currentTime, startY, wholeY, duration) {// y = S / dur^3 *(x-dur)^3 + S,对称中心是(dur,S),从0-dur是 斜率递减的递增函数,导数为3S/dur^3 * (x-dur)^2, 0时速度为3S/dur
  31794. return currentTime /= duration,
  31795. currentTime--,
  31796. wholeY * (currentTime * currentTime * currentTime + 1) + startY
  31797. }
  31798. ,
  31799. easing.easeInOutCubic = function(currentTime, startY, wholeY, duration) {
  31800. return currentTime /= duration / 2,
  31801. currentTime < 1 ? wholeY / 2 * currentTime * currentTime * currentTime + startY : (currentTime -= 2,
  31802. wholeY / 2 * (currentTime * currentTime * currentTime + 2) + startY)
  31803. }
  31804. ,
  31805. easing.easeInQuart = function(currentTime, startY, wholeY, duration) {
  31806. return currentTime /= duration,
  31807. wholeY * currentTime * currentTime * currentTime * currentTime + startY
  31808. }
  31809. ,
  31810. easing.easeOutQuart = function(currentTime, startY, wholeY, duration) {//根据上面的计算,估计0时速度应该是4S/dur吧……
  31811. return currentTime /= duration,
  31812. currentTime--,
  31813. -wholeY * (currentTime * currentTime * currentTime * currentTime - 1) + startY
  31814. }
  31815. ,
  31816. easing.easeInOutQuart = function(currentTime, startY, wholeY, duration) {
  31817. return currentTime /= duration / 2,
  31818. currentTime < 1 ? wholeY / 2 * currentTime * currentTime * currentTime * currentTime + startY : (currentTime -= 2,
  31819. -wholeY / 2 * (currentTime * currentTime * currentTime * currentTime - 2) + startY)
  31820. }
  31821. ,
  31822. easing.easeInQuint = function(currentTime, startY, wholeY, duration) {
  31823. return currentTime /= duration,
  31824. wholeY * currentTime * currentTime * currentTime * currentTime * currentTime + startY
  31825. }
  31826. ,
  31827. easing.easeOutQuint = function(currentTime, startY, wholeY, duration) {
  31828. return currentTime /= duration,
  31829. currentTime--,
  31830. wholeY * (currentTime * currentTime * currentTime * currentTime * currentTime + 1) + startY
  31831. }
  31832. ,
  31833. easing.easeInOutQuint = function(currentTime, startY, wholeY, duration) {
  31834. return currentTime /= duration / 2,
  31835. currentTime < 1 ? wholeY / 2 * currentTime * currentTime * currentTime * currentTime * currentTime + startY : (currentTime -= 2,
  31836. wholeY / 2 * (currentTime * currentTime * currentTime * currentTime * currentTime + 2) + startY)
  31837. }
  31838. ,
  31839. easing.easeInSine = function(currentTime, startY, wholeY, duration) {
  31840. return -wholeY * Math.cos(currentTime / duration * (Math.PI / 2)) + wholeY + startY
  31841. }
  31842. ,
  31843. easing.easeOutSine = function(currentTime, startY, wholeY, duration) {// y' = S * PI / 2 / dur * cos(PI/2/dur * x)
  31844. return wholeY * Math.sin(currentTime / duration * (Math.PI / 2)) + startY
  31845. }
  31846. ,
  31847. easing.easeInOutSine = function(currentTime, startY, wholeY, duration) {
  31848. return -wholeY / 2 * (Math.cos(Math.PI * currentTime / duration) - 1) + startY
  31849. }
  31850. ,
  31851. easing.easeInExpo = function(currentTime, startY, wholeY, duration) {
  31852. return wholeY * Math.pow(2, 10 * (currentTime / duration - 1)) + startY
  31853. }
  31854. ,
  31855. easing.easeOutExpo = function(currentTime, startY, wholeY, duration) {
  31856. return wholeY * (-Math.pow(2, -10 * currentTime / duration) + 1) + startY
  31857. }
  31858. ,
  31859. easing.easeInOutExpo = function(currentTime, startY, wholeY, duration) {
  31860. return currentTime /= duration / 2,
  31861. currentTime < 1 ? wholeY / 2 * Math.pow(2, 10 * (currentTime - 1)) + startY : (currentTime--,
  31862. wholeY / 2 * (-Math.pow(2, -10 * currentTime) + 2) + startY)
  31863. }
  31864. ,
  31865. easing.easeInCirc = function(currentTime, startY, wholeY, duration) {
  31866. return currentTime /= duration,
  31867. -wholeY * (Math.sqrt(1 - currentTime * currentTime) - 1) + startY
  31868. }
  31869. ,
  31870. easing.easeOutCirc = function(currentTime, startY, wholeY, duration) {
  31871. return currentTime /= duration,
  31872. currentTime--,
  31873. wholeY * Math.sqrt(1 - currentTime * currentTime) + startY
  31874. }
  31875. ,
  31876. easing.easeInOutCirc = function(currentTime, startY, wholeY, duration) {
  31877. return currentTime /= duration / 2,
  31878. currentTime < 1 ? -wholeY / 2 * (Math.sqrt(1 - currentTime * currentTime) - 1) + startY : (currentTime -= 2,
  31879. wholeY / 2 * (Math.sqrt(1 - currentTime * currentTime) + 1) + startY)
  31880. }
  31881. ,
  31882. easing.easeInElastic = function(currentTime, startY, wholeY, duration) {
  31883. var r = 1.70158
  31884. , o = 0
  31885. , a = wholeY;
  31886. return 0 === currentTime ? startY : 1 === (currentTime /= duration) ? startY + wholeY : (o || (o = .3 * duration),
  31887. a < Math.abs(wholeY) ? (a = wholeY,
  31888. r = o / 4) : r = o / (2 * Math.PI) * Math.asin(wholeY / a),
  31889. -(a * Math.pow(2, 10 * (currentTime -= 1)) * Math.sin((currentTime * duration - r) * (2 * Math.PI) / o)) + startY)
  31890. }
  31891. ,
  31892. easing.easeOutElastic = function(currentTime, startY, wholeY, duration) {
  31893. var r = 1.70158
  31894. , o = 0
  31895. , a = wholeY;
  31896. return 0 === currentTime ? startY : 1 === (currentTime /= duration) ? startY + wholeY : (o || (o = .3 * duration),
  31897. a < Math.abs(wholeY) ? (a = wholeY,
  31898. r = o / 4) : r = o / (2 * Math.PI) * Math.asin(wholeY / a),
  31899. a * Math.pow(2, -10 * currentTime) * Math.sin((currentTime * duration - r) * (2 * Math.PI) / o) + wholeY + startY)
  31900. }
  31901. ,
  31902. easing.easeInOutElastic = function(currentTime, startY, wholeY, duration) {
  31903. var r = 1.70158
  31904. , o = 0
  31905. , a = wholeY;
  31906. return 0 === currentTime ? startY : 2 === (currentTime /= duration / 2) ? startY + wholeY : (o || (o = duration * (.3 * 1.5)),
  31907. a < Math.abs(wholeY) ? (a = wholeY,
  31908. r = o / 4) : r = o / (2 * Math.PI) * Math.asin(wholeY / a),
  31909. 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)
  31910. }
  31911. ,
  31912. easing.easeInBack = function(currentTime, startY, wholeY, duration, r) {
  31913. return void 0 === r && (r = 1.70158),
  31914. wholeY * (currentTime /= duration) * currentTime * ((r + 1) * currentTime - r) + startY
  31915. }
  31916. ,
  31917. easing.easeOutBack = function(currentTime, startY, wholeY, duration, r) {
  31918. return void 0 === r && (r = 1.70158),
  31919. wholeY * ((currentTime = currentTime / duration - 1) * currentTime * ((r + 1) * currentTime + r) + 1) + startY
  31920. }
  31921. ,
  31922. easing.easeInOutBack = function(currentTime, startY, wholeY, duration, r) {
  31923. return void 0 === r && (r = 1.70158),
  31924. (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
  31925. }
  31926. ,
  31927. easing.easeOutBounce = function(currentTime, startY, wholeY, duration) {
  31928. 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
  31929. }
  31930. ,
  31931. easing.easeInBounce = function(currentTime, startY, wholeY, r) {
  31932. return wholeY - easing.easeOutBounce(r - currentTime, 0, wholeY, r) + startY
  31933. }
  31934. ,
  31935. easing.easeInOutBounce = function(currentTime, startY, wholeY, r) {
  31936. 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
  31937. };
  31938. var lerp = {
  31939. /* vector: function(currentTime, startY, f) {//xzw change, add f
  31940. var wholeY = currentTime.clone();
  31941. return startY = startY.clone(),
  31942. function(duration) {
  31943. currentTime.set(wholeY.x * (1 - duration) + startY.x * duration, wholeY.y * (1 - duration) + startY.y * duration, wholeY.z * (1 - duration) + startY.z * duration)
  31944. f && f(currentTime,duration);
  31945. }
  31946. },
  31947. quaternion: function(currentTime, startY, f) {//xzw change, add f
  31948. var wholeY = currentTime.clone();
  31949. return function(duration) {
  31950. currentTime.copy(wholeY).slerp(startY, duration);
  31951. f && f(currentTime,duration);
  31952. }
  31953. },
  31954. property: function(currentTime, startY, wholeY, duration) {
  31955. var r = currentTime[startY];
  31956. return function(o) {
  31957. currentTime[startY] = r * (1 - o) + wholeY * o,
  31958. duration && duration(currentTime[startY])
  31959. }
  31960. },
  31961. uniform: function(currentTime, startY, wholeY) {
  31962. var duration = currentTime.material.uniforms[startY].value;
  31963. return function(r) {
  31964. try{
  31965. currentTime.material.uniforms[startY] && (currentTime.material.uniforms[startY].value = duration * (1 - r) + wholeY * r)
  31966. }catch(currentTime){
  31967. console.log(1)
  31968. }
  31969. }
  31970. },
  31971. matrix4: function(currentTime, startY) {
  31972. var wholeY = currentTime.clone();
  31973. return function(duration) {
  31974. for (var r = currentTime.elements, o = wholeY.elements, a = startY.elements, s = 0; s < 16; s++)
  31975. r[s] = o[s] * (1 - duration) + a[s] * duration
  31976. }
  31977. },
  31978. allUniforms: function(currentTime, startY, wholeY) {
  31979. var duration = currentTime.map(function(currentTime) {
  31980. return this.uniform(currentTime, startY, wholeY)
  31981. }
  31982. .bind(this));
  31983. return function(currentTime) {
  31984. duration.forEach(function(startY) {
  31985. startY(currentTime)
  31986. })
  31987. }
  31988. } */
  31989. vector: function(t, i, f) {//xzw change, add f
  31990. var n = t.clone();
  31991. return i = i.clone(),
  31992. function(e, delta) {
  31993. t.set(n.x * (1 - e) + i.x * e, n.y * (1 - e) + i.y * e, n.z * (1 - e) + i.z * e);
  31994. f && f(t,e, delta);
  31995. }
  31996. },
  31997. quaternion: function(t, i, f) {//xzw change, add f
  31998. var n = t.clone();
  31999. return function(e) {
  32000. t.copy(n).slerp(i, e);
  32001. f && f(t,e);
  32002. }
  32003. },
  32004. property: function(t, i, n, r) {
  32005. var o = t[i];
  32006. return function(e) {
  32007. t[i] = o * (1 - e) + n * e,
  32008. r && r(t[i]);
  32009. }
  32010. },
  32011. uniform: function(t, i, n) {
  32012. var r = t.material.uniforms[i].value;
  32013. return function(e) {
  32014. t.material.uniforms[i] && (t.material.uniforms[i].value = r * (1 - e) + n * e);
  32015. }
  32016. },
  32017. matrix4: function(o, a) {
  32018. var s = o.clone();
  32019. return function(e) {
  32020. for (var t = o.elements, i = s.elements, n = a.elements, r = 0; r < 16; r++)
  32021. t[r] = i[r] * (1 - e) + n[r] * e;
  32022. }
  32023. },
  32024. allUniforms: function(e, t, i) {
  32025. var n = e.map(function(e) {
  32026. return this.uniform(e, t, i)
  32027. }
  32028. .bind(this));
  32029. return function(t) {
  32030. n.forEach(function(e) {
  32031. e(t);
  32032. });
  32033. }
  32034. }
  32035. };
  32036. /*
  32037. 渐变
  32038. */
  32039. var transitions = {
  32040. globalDone: null,
  32041. funcs: [],
  32042. counter: 0,
  32043. uniqueID: 0,
  32044. start: function(func, duration, done, delay, ease, name, id, cancelFun, ignoreFirstFrame=true) {
  32045. return delay = delay || 0,
  32046. this.funcs.push({
  32047. func: func,
  32048. current: -delay * Math.abs(duration), //当前时间
  32049. duration: (1 - Math.max(delay, 0)) * Math.abs(duration), //总时长
  32050. done: done,
  32051. easing: ease || easing.linearTween, //渐变曲线
  32052. cycling: duration < 0,
  32053. running: !0,
  32054. debug: delay < 0,
  32055. name: name || "T" + this.counter,
  32056. id: void 0 === id ? this.counter : id,
  32057. paused: !1,
  32058. cancelFun : cancelFun, //取消时执行的函数
  32059. updateCount:0,
  32060. ignoreFirstFrame,
  32061. }),
  32062. func(0, 16),
  32063. this.counter += 1,
  32064. func
  32065. },
  32066. trigger: function(e) {
  32067. var t = void 0 === e.delayRatio ? 0 : e.delayRatio
  32068. , u = e.func || function() {}
  32069. , r = void 0 === e.duration ? 0 : e.duration;
  32070. void 0 !== e.cycling && e.cycling && (r = -Math.abs(r));
  32071. var o = e.done || null
  32072. , a = e.easing || easing.linearTween
  32073. , s = e.name || "R" + this.counter
  32074. , l = void 0 === e.id ? this.counter : e.id;
  32075. return this.start(u, r, o, t, a, s, l)
  32076. },
  32077. setTimeout: function(e, t, u) {
  32078. var duration = void 0 === u ? this.counter : u;
  32079. return this.trigger({
  32080. done: e,
  32081. duration: void 0 === t ? 0 : t,
  32082. name: "O" + this.counter,
  32083. id: duration
  32084. })
  32085. },
  32086. pause: function() {
  32087. this.paused = !0;
  32088. },
  32089. resume: function() {
  32090. this.paused = !1;
  32091. },
  32092. update: function(e) {
  32093. this.funcs.forEach(function(t) {
  32094. if(t.updateCount++ == 0 && t.ignoreFirstFrame) return //add start可能发生在一帧中任意时刻,而每次update的是在一帧中的固定时刻,所以从start到第一次update的时间并不是所传入的delta,该delta 是上一帧的update到这一帧的update的耗时。 故去掉了第一次的update,相当于延迟一帧再update.
  32095. if (!(t.paused || (t.current += 1e3 * e, t.current < 0))){
  32096. if (t.current >= t.duration && !t.cycling) {
  32097. var u = t.easing(1, 0, 1, 1);
  32098. t.func(u, 1e3 * e),
  32099. t.done && t.done(),
  32100. t.running = !1;
  32101. } else {
  32102. var duration = t.easing(t.current % t.duration / t.duration, 0, 1, 1)
  32103. , r = t.func(duration, 1e3 * e) || !1;
  32104. r && (t.done && t.done(),
  32105. t.running = !1);
  32106. }
  32107. }
  32108. });
  32109. var t = this.funcs.length;
  32110. this.funcs = this.funcs.filter(function(e) {
  32111. return e.running
  32112. });
  32113. var u = this.funcs.length;
  32114. if (t > 0 && 0 === u && this.globalDone) {
  32115. var duration = this.globalDone;
  32116. this.globalDone = null,
  32117. duration();
  32118. }
  32119. },
  32120. adjustSpeed: function(e, t) {
  32121. for (var u = this.getById(e), duration = 0; duration < u.length; duration++) {
  32122. var r = u[duration];
  32123. r.duration /= t,
  32124. r.current /= t;
  32125. }
  32126. },
  32127. getById: function(e) {
  32128. return this.funcs.filter(function(t) {
  32129. return e === t.id
  32130. })
  32131. },
  32132. get: function(e) {
  32133. for (var t = 0; t < this.funcs.length; t += 1)
  32134. if (this.funcs[t].func === e)
  32135. return this.funcs[t];
  32136. return null
  32137. },
  32138. isRunning: function(e) {
  32139. var t = this.get(e);
  32140. return null !== t && t.running
  32141. },
  32142. countActive: function() {
  32143. for (var e = 0, t = 0; t < this.funcs.length; t += 1)
  32144. e += this.funcs[t].running;
  32145. return e
  32146. },
  32147. listActive: function() {
  32148. for (var e = [], t = 0; t < this.funcs.length; t += 1)
  32149. this.funcs[t].running && e.push(this.funcs[t].name);
  32150. return e
  32151. },
  32152. done: function(e) {
  32153. this.globalDone = e;
  32154. },
  32155. cancelById: function(e, dealCancelFun) { //xzw add dealDone
  32156. var t = void 0 === e ? 0 : e;
  32157. let cancels = [];
  32158. this.funcs = this.funcs.filter(function(e) {
  32159. var is = e.id == t;
  32160. if(is && dealCancelFun){
  32161. e.cancelFun && cancels.push(e.cancelFun);
  32162. //e.cancelFun && e.cancelFun()
  32163. }
  32164. return !is
  32165. });
  32166. cancels.forEach(e=>{e();}); //先从funcs中去除后再执行
  32167. },
  32168. cancel: function(e) {
  32169. this.funcs = this.funcs.filter(function(t) {
  32170. return t.func !== e
  32171. });
  32172. },
  32173. getUniqueId: function() {
  32174. return this.uniqueID -= 1,
  32175. this.uniqueID
  32176. }
  32177. };
  32178. //THREE.Vector2.name2 = 'Common'
  32179. var Common = {
  32180. sortByScore: function(list, request, rank){
  32181. var i = request ? Common.filterAll(list, request) : list;
  32182. return 0 === i.length ? [] : i = i.map(function(e) {
  32183. let results = rank.map(function(f){return f(e)});
  32184. let scores = results.map(e=>e.score != void 0 ? e.score : e);
  32185. let logs = results.map(e=>e.log);
  32186. return {
  32187. item: e,
  32188. scores,
  32189. logs,
  32190. score: scores.reduce(function(t, i) {//总分
  32191. return t + i
  32192. }, 0)
  32193. }
  32194. }).sort(function(e, t) {
  32195. return t.score - e.score;
  32196. })
  32197. }
  32198. ,
  32199. filterAll: function(e, t) {
  32200. return e.filter(function (e) {
  32201. return t.every(function (t) {
  32202. return t(e)
  32203. })
  32204. })
  32205. },
  32206. //---------------
  32207. find : function(list, request, rank, sortByScore ) {
  32208. if(sortByScore){
  32209. var r = this.sortByScore(list, request, rank);
  32210. return r[0] && r[0].item
  32211. }else {
  32212. var i = request ? Common.filterAll(list, request) : list;
  32213. return 0 === i.length ? null : (rank && rank.forEach(function(e) {
  32214. i = Common.stableSort(i, e);
  32215. }),
  32216. i[0])
  32217. }
  32218. }
  32219. ,
  32220. stableSort: function(e, f) {//用到排序函数,涉及到两个item相减
  32221. return e.map(function(e, i) {
  32222. return {
  32223. value: e,
  32224. index: i
  32225. }
  32226. }).sort(function(e, u) {
  32227. var n = f(e.value, u.value);
  32228. return 0 !== n ? n : e.index - u.index //似乎就是加多了这一步:若差距为0,按照原顺序
  32229. }).map(function(e) {
  32230. return e.value
  32231. })
  32232. },
  32233. average: function (e, t) {
  32234. if (0 === e.length)
  32235. return null;
  32236. for (var i = 0, n = 0, r = 0; r < e.length; r++) {
  32237. var o = t ? e[r][t] : e[r];
  32238. i += o,
  32239. n++;
  32240. }
  32241. return i / n
  32242. },
  32243. //---------------------------
  32244. getMixedSet : function(arr1, arr2){//交集
  32245. return arr1.filter(item=>arr2.includes(item));
  32246. },
  32247. getUnionSet : function(arr1, arr2){//并集
  32248. return arr1.concat(arr2.filter(item=>!arr1.includes(item)))
  32249. },
  32250. getDifferenceSet : function(arr1, arr2){//差集 不能识别重复的,如getDifferenceSet([1,2,2],[1,1,2]) 为空
  32251. var arr11 = arr1.filter(item=>!arr2.includes(item));
  32252. var arr22 = arr2.filter(item=>!arr1.includes(item));
  32253. return arr11.concat(arr22)
  32254. },
  32255. getDifferenceSetMuti : function(arr){//收集绝对没有重复的元素,也就是判断出现次数=1的
  32256. var set = [];
  32257. arr.forEach(arr1=>{
  32258. arr1.forEach(item=>{
  32259. var index = set.indexOf(item);
  32260. if(index>-1){
  32261. set.splice(index, 1);
  32262. }else {
  32263. set.push(item);
  32264. }
  32265. });
  32266. });
  32267. return set;
  32268. }
  32269. ,
  32270. CloneJson : function(data){
  32271. var str = JSON.stringify(data);
  32272. return JSON.parse(str)
  32273. }
  32274. ,
  32275. CloneObject : function (copyObj, isSimpleCopy, simpleCopyList = [], judgeSimpleCopyFun) {
  32276. //isSimpleCopy 只复制最外层
  32277. //复制json result的可能:普通数字或字符串、普通数组、复杂对象
  32278. judgeSimpleCopyFun || (judgeSimpleCopyFun=()=>{});
  32279. if (!copyObj || typeof copyObj == 'number' || typeof copyObj == 'string' ||copyObj.isObject3D || copyObj instanceof Function || simpleCopyList.some(className => copyObj instanceof className) || judgeSimpleCopyFun(copyObj)) {
  32280. return copyObj
  32281. }
  32282. if (copyObj instanceof Array) {
  32283. return copyObj.map(e => {
  32284. return this.CloneObject(e, isSimpleCopy, simpleCopyList, judgeSimpleCopyFun)
  32285. })
  32286. } else {
  32287. if (copyObj.clone instanceof Function) {
  32288. //解决一部分
  32289. return copyObj.clone()
  32290. }
  32291. }
  32292. let result = {};
  32293. for (var key in copyObj) {
  32294. if (copyObj[key] instanceof Object && !isSimpleCopy ) result[key] = this.CloneObject(copyObj[key], isSimpleCopy, simpleCopyList, judgeSimpleCopyFun);
  32295. else result[key] = copyObj[key];
  32296. //如果是函数类同基本数据,即复制引用
  32297. }
  32298. return result
  32299. }
  32300. ,
  32301. CloneClassObject :function(copyObj, {ignoreList=[],simpleCopyList=[]}={}){//复杂类对象
  32302. var newobj = new copyObj.constructor();
  32303. this.CopyClassObject(newobj, copyObj, {ignoreList,simpleCopyList});
  32304. return newobj
  32305. }
  32306. ,
  32307. CopyClassObject :function(targetObj, copyObj, {ignoreList=[],simpleCopyList=[]}={}){//复杂类对象
  32308. for(let i in copyObj){
  32309. if(i in copyObj.__proto__)break; //到函数了跳出
  32310. if(ignoreList.includes(i)){
  32311. continue;
  32312. }else if(simpleCopyList.includes(i)){
  32313. targetObj[i] = copyObj[i];
  32314. }else {
  32315. targetObj[i] = this.CloneObject(copyObj[i], false, simpleCopyList );
  32316. }
  32317. /* else if(copyObj[i].clone instanceof Function ){
  32318. targetObj[i] = copyObj[i].clone()
  32319. }else{
  32320. targetObj[i] = copyObj[i];
  32321. } */
  32322. }
  32323. }
  32324. ,
  32325. ifSame : function(object1, object2, simpleEqualClass=[]){ //对于复杂的类对象,若能简单判断就直接写进simpleEqualClass
  32326. if(object1 == object2 )return true // 0 != undefined , 0 == ''
  32327. else if(!object1 || !object2) return false
  32328. else if(object1.constructor != object2.constructor){
  32329. return false
  32330. }else if(simpleEqualClass.some(className => object1 instanceof className)){
  32331. return object1 == object2
  32332. }else if(object1 instanceof Array ) {
  32333. if(object1.length != object2.length)return false;
  32334. var _object2 = object2.slice(0);
  32335. for(let i=0;i<object1.length;i++){
  32336. var u = _object2.find(e=>Common.ifSame(object1[i], e, simpleEqualClass));
  32337. if(u == void 0 && !_object2.includes(u) && !object1.includes(u))return false;
  32338. else {
  32339. let index = _object2.indexOf(u);
  32340. _object2.splice(index,1);
  32341. }
  32342. }
  32343. return true
  32344. }else if(object1.equals instanceof Function ){//复杂数据仅支持这种,其他的可能卡住?
  32345. return object1.equals(object2)
  32346. }else if(typeof object1 == 'number' || typeof object1 == 'string'){
  32347. if(isNaN(object1) && isNaN(object2))return true
  32348. else return object1 == object2
  32349. }else if(typeof object1 == "object"){
  32350. var keys1 = Object.keys(object1);
  32351. var keys2 = Object.keys(object2);
  32352. if(!Common.ifSame(keys1,keys2,simpleEqualClass))return false;
  32353. for(let i in object1){
  32354. var same = Common.ifSame(object1[i], object2[i],simpleEqualClass);
  32355. if(!same)return false
  32356. }
  32357. return true
  32358. }else {
  32359. console.log('isSame出现例外');
  32360. }
  32361. }
  32362. ,
  32363. downloadFile : function(data, filename, cb) {
  32364. var save_link = document.createElementNS('http://www.w3.org/1999/xhtml', 'a');
  32365. save_link.href = data;
  32366. save_link.download = filename;
  32367. var event = document.createEvent('MouseEvents');
  32368. event.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  32369. save_link.dispatchEvent(event);
  32370. cb && cb();
  32371. },
  32372. replaceAll : function (str, f, e) {
  32373. //f全部替换成e
  32374. var reg = new RegExp(f, "g"); //创建正则RegExp对象
  32375. return str.replace(reg, e);
  32376. },
  32377. dealURL(url){
  32378. let urlNew = this.replaceAll(url, "\\+", "%2B");// 浏览器似乎不支持访问带+的地址
  32379. urlNew = this.replaceAll(urlNew, "/.//", "/"); //去除双斜杠(/.//)
  32380. return urlNew
  32381. },
  32382. getNameFromURL(url){
  32383. if(!url)return ''
  32384. let get = (e)=>{
  32385. return e.split('/').pop()
  32386. };
  32387. if(url instanceof Array){
  32388. return url.map(e=>get(e))
  32389. }
  32390. return get(url)
  32391. },
  32392. //---------------------------
  32393. intervalTool:{ //延时update,防止卡顿
  32394. list:[],
  32395. /* isWaiting:function(name, func, delayTime){
  32396. if(!this.list.includes(name)){ //如果没有该项, 则开始判断
  32397. var needWait = func(); //触发了改变,则等待一段时间后再自动判断
  32398. if(needWait){
  32399. this.list.push(name);
  32400. setTimeout(()=>{
  32401. var a = this.list.indexOf(name);
  32402. this.list.splice(a,1);
  32403. this.isWaiting(name, func, delayTime) //循环
  32404. },delayTime)
  32405. }
  32406. }
  32407. }, */
  32408. isWaiting:function(name, func, delayTime/* , autoCycle */){
  32409. let item = this.list.find(e=>e.name == name);
  32410. if(!item){ //如果没有该项, 则加入循环
  32411. let ifContinue = func();
  32412. item = {name, func, delayTime};
  32413. this.list.push(item);
  32414. setTimeout(()=>{
  32415. var a = this.list.indexOf(item);
  32416. this.list.splice(a,1);
  32417. let {func, delayTime} = item;
  32418. if(item.requestUpdate || ifContinue ) this.isWaiting(name, func, delayTime); //循环
  32419. },delayTime);
  32420. }else {//如果有该项,说明现在请求下一次继续更新
  32421. //if(delayTime == 0){//想立刻更新一次
  32422. // func()
  32423. //}else{
  32424. //更新属性
  32425. item.func = func;
  32426. item.delayTime = delayTime;
  32427. item.requestUpdate = true;
  32428. //}
  32429. }
  32430. },
  32431. }
  32432. ,
  32433. pushToGroupAuto : function(items, groups, recognizeFunction, recognizeGroup){//自动分组。 items是将分到一起的组合。items.length = 1 or 2.
  32434. recognizeFunction = recognizeFunction || function(){};
  32435. if(recognizeGroup){ //有更复杂的识别处理,直接传递整个组
  32436. var atGroups = groups.filter(group=>recognizeGroup(group, items));
  32437. }else {
  32438. var atGroups = groups.filter(group=>group.find(
  32439. item => items[0] == item || recognizeFunction(item, items[0]) || items[1] == item || items[1] && recognizeFunction(item, items[1])
  32440. ));
  32441. }
  32442. if(atGroups.length){//在不同组
  32443. //因为items是一组的,所以先都放入组1
  32444. items.forEach(item=> {if(!atGroups[0].includes(item)) atGroups[0].push(item);});
  32445. if(atGroups.length>1){//如果在不同组,说明这两个组需要合并
  32446. var combineGroup = [];
  32447. atGroups.forEach(group=>{
  32448. combineGroup = Common.getUnionSet(combineGroup, group);
  32449. groups.splice(groups.indexOf(group),1);
  32450. });
  32451. groups.push(combineGroup);
  32452. }
  32453. }else {//直接加入为一组
  32454. groups.push(items);
  32455. }
  32456. },
  32457. getBestCount : (function(){
  32458. let lastCount = {};
  32459. return function(name, minCount=1,maxCount=6, durBound1 = 1.2, durBound2 = 10, ifLog, maxHistory){
  32460. let timeStamp = performance.getEntriesByName("loop-start");
  32461. let count;
  32462. if(timeStamp.length){
  32463. let dur = performance.now() - timeStamp[timeStamp.length-1].startTime; //dur在iphoneX中静止有7,pc是2
  32464. count = Math.round(math.linearClamp(dur, [durBound1,durBound2], [maxCount, minCount]));
  32465. if (maxHistory) {
  32466. if (!lastCount[name]) lastCount[name] = [];
  32467. if (count == 0 && lastCount[name].length > maxHistory - 1 && !lastCount[name].some(e => e > 0)) {
  32468. count = 1;
  32469. }
  32470. lastCount[name].push(count);
  32471. if (lastCount[name].length > maxHistory) lastCount[name].splice(0, 1);
  32472. }
  32473. if(ifLog){//注意,console.log本身用时挺高, 降4倍时可能占用0.5毫秒
  32474. name && count && console.log(name, count , ' ,dur:', dur.toFixed(3));
  32475. }
  32476. }else {
  32477. count = maxCount; // ?
  32478. }
  32479. //主要在手机端有效果。
  32480. return count
  32481. }
  32482. })(),
  32483. batchHandling : {//分批处理
  32484. lists:[],
  32485. getSlice : function(name, items , {stopWhenAllUsed, min=5,max=100, durBound1 , durBound2, useEquals , maxUseCount}){
  32486. if(items.length == 0 ||
  32487. ((maxUseCount = maxUseCount == void 0 ? Common.getBestCount(name, min,max , durBound1, durBound2 /* , true */ ) : maxUseCount), !maxUseCount) //本次最多可以使用的个数
  32488. ){
  32489. return {list:[]}
  32490. }
  32491. if(!this.lists[name]) this.lists[name] = {list:[] };
  32492. //更新列表项目,但不变原来的顺序
  32493. let list = this.lists[name].list.filter(a=>items.some(item=> useEquals ? a.item.equals(item) : a.item == item));//去掉已经不在items里的项目
  32494. this.lists[name].list = list;
  32495. items.forEach(item=>{//增加新的项目。
  32496. if(!list.some(a=>useEquals ? a.item.equals(item) : a.item == item )){
  32497. list.push({item, count:0});
  32498. }
  32499. });
  32500. //至此,在后排的都是未使用的
  32501. let unUsed = list.filter(e=>e.count == 0);//未使用的项目(count为0)优先
  32502. let result = [];
  32503. unUsed.slice(0,maxUseCount).forEach(e=>{
  32504. result.push(e.item);
  32505. e.count ++;
  32506. });
  32507. if(unUsed.length > maxUseCount){
  32508. //还是剩有未使用的项目,等待下一次
  32509. }else {
  32510. //所有项目都能使用一次
  32511. if(!stopWhenAllUsed){ //若不是全部使用就停止
  32512. let wholeCount = Math.min(items.length, maxUseCount);
  32513. let restCount = wholeCount - result.length; //补齐
  32514. list.slice(0,restCount).forEach(e=>{
  32515. result.push(e.item);
  32516. e.count ++;
  32517. });
  32518. }
  32519. list.forEach(e=>e.count--); //复原,等待新的循环
  32520. }
  32521. /* result.forEach((e,i)=>{//有重复的
  32522. if( result.slice(0,i).some(a=>a.equals(e)) || result.slice(i+1).some(a=>a.equals(e)) ) {
  32523. console.log(e)
  32524. }
  32525. }) */
  32526. return {list:result }
  32527. }
  32528. },
  32529. getRootWindow(){//获取包含Potree的根window
  32530. let win = window;
  32531. try{
  32532. while(win.parent!=win && win.parent.Potree){
  32533. win = win.parent;
  32534. }
  32535. if(window != win)return win
  32536. }catch(e){
  32537. //console.log(e) //可能跨域,从而win.parent.Potree报错
  32538. console.log('getRootWindow 跨域');
  32539. return
  32540. }
  32541. },
  32542. watch: function(object, propName, initialValue){ //监听某个属性的变化
  32543. let v = initialValue;
  32544. Object.defineProperty(object, propName, {
  32545. get: function() {
  32546. return v
  32547. },
  32548. set: function(e) {
  32549. console.warn('watch:',propName, e);
  32550. v = e;
  32551. }
  32552. });
  32553. },
  32554. imgAddLabel : function (img, labelImg, labelInfo = {}) {
  32555. //图上加另一张小图,用于添加水印
  32556. let canvas;
  32557. if(img instanceof Image){
  32558. canvas = document.createElement('canvas');
  32559. }else {
  32560. canvas = img;
  32561. }
  32562. let context = canvas.getContext('2d');
  32563. let marginLeft = labelInfo.bgMargin && labelInfo.bgMargin.left || 0;
  32564. let marginRight = labelInfo.bgMargin && labelInfo.bgMargin.right || 0;
  32565. let marginTop = labelInfo.bgMargin && labelInfo.bgMargin.top || 0;
  32566. let marginBottom = labelInfo.bgMargin && labelInfo.bgMargin.bottom || 0;
  32567. if(img instanceof Image){//如果img是canvas,说明已绘制在canvas上了就不用绘制了
  32568. let width = img.width + marginLeft + marginRight;
  32569. let height = img.height + marginTop + marginBottom;
  32570. canvas.width = width;
  32571. canvas.height = height;
  32572. if(labelInfo.bgColor){
  32573. context.fillStyle = 'rgba(' + labelInfo.bgColor.r + ',' + labelInfo.bgColor.g + ',' + labelInfo.bgColor.b + ',' + labelInfo.bgColor.a + ')';
  32574. context.fillRect(0,0,width,height);
  32575. }
  32576. context.drawImage(img, marginLeft, marginTop, img.width, img.height);
  32577. }
  32578. let labelWidth = labelInfo.widthRatioToImg ? img.width * labelInfo.widthRatioToImg : labelImg.width; //widthRatioToImg:label的width占img的width的比例
  32579. let labelHeight = (labelWidth * labelImg.height) / labelImg.width;
  32580. if (labelInfo.leftRatioToImg == void 0 && labelInfo.rightRatioToImg != void 0) {
  32581. labelInfo.leftRatioToImg = 1 - labelInfo.rightRatioToImg - (labelInfo.widthRatioToImg || labelImg.width / img.width);
  32582. }
  32583. if (labelInfo.topRatioToImg == void 0 && labelInfo.bottomRatioToImg != void 0) {
  32584. labelInfo.topRatioToImg = 1 - labelInfo.bottomRatioToImg - labelHeight / img.height;
  32585. }
  32586. let labelLeft = img.width * labelInfo.leftRatioToImg + marginLeft; //leftRatioToImg:label的left占img的width的比例
  32587. let labelTop = img.height * labelInfo.topRatioToImg + marginTop; //topRatioToImg:label的top占img的height的比例
  32588. context.globalAlpha = labelInfo.opacity != void 0 ? labelInfo.opacity : 1;
  32589. context.drawImage(labelImg, labelLeft, labelTop, labelWidth, labelHeight);
  32590. if(labelInfo.outputCanvas){
  32591. return canvas
  32592. }
  32593. var dataUrl = canvas.toDataURL('image/png', labelInfo.compressRatio);
  32594. //Common.downloadFile(dataUrl, 'screenshot.png')
  32595. context.clearRect(0,0,canvas.width,canvas.height);
  32596. return dataUrl
  32597. },
  32598. changeShaderToWebgl2(vs, fs, matType, otherReplaces=[]){//部分shader要根据webgl版本作更改
  32599. if(!Potree.settings.isWebgl2)return {vs, fs}
  32600. let turnTo300 = matType != 'ShaderMaterial' && (vs.includes('gl_FragDepthEXT') || fs.includes('gl_FragDepthEXT') );
  32601. let addV300 = turnTo300 && matType != 'RawShaderMaterial'; // RawShaderMaterial直接material.glslVersion = '300 es' 以加在define之前
  32602. let change = (shader, shaderType)=>{
  32603. let newShader = shader;
  32604. if(turnTo300){ //非shaderMaterial需要手动改为300 es的写法
  32605. addV300 && (newShader = '#version 300 es \n' + newShader); //需要加 #version 300 es。 three.js自带的渲染会自动加所以不用
  32606. newShader = newShader.replaceAll('varying ', shaderType == 'vs' ? 'out ' : 'in ');
  32607. newShader = newShader.replaceAll('attribute ', 'in ');
  32608. if(shaderType == 'fs'){
  32609. newShader = newShader.replaceAll('gl_FragColor', 'fragColor');
  32610. newShader = newShader.replace('void main', 'out vec4 fragColor;\n void main' );//在void main前加入这个声明
  32611. }
  32612. newShader = newShader.replaceAll('gl_FragDepthEXT','gl_FragDepth');
  32613. newShader = newShader.replaceAll('texture2D','texture');
  32614. newShader = newShader.replaceAll('textureCube','texture');
  32615. }
  32616. newShader = newShader.replace('#extension GL_EXT_frag_depth : enable','');
  32617. newShader = newShader.replaceAll('defined(GL_EXT_frag_depth) &&','');
  32618. otherReplaces.forEach(({oldStr,newStr})=>{
  32619. newShader = newShader.replaceAll(oldStr,newStr);
  32620. });
  32621. return newShader
  32622. };
  32623. vs = change(vs,'vs');
  32624. fs = change(fs,'fs');
  32625. //console.log('成功替换为webgl2' )
  32626. return {vs,fs}
  32627. }//three.js的shaderMaterial也有替换功能,搜 '#define gl_FragDepthEXT gl_FragDepth',
  32628. };
  32629. Potree.Common = Common;
  32630. class View{//base
  32631. constructor () {
  32632. this.position = new Vector3(0, 0, 0);
  32633. this.yaw = Math.PI / 4;
  32634. this._pitch = -Math.PI / 4;
  32635. this.radius = 1;
  32636. this.maxPitch = Math.PI / 2;
  32637. this.minPitch = -Math.PI / 2;
  32638. }
  32639. clone () {
  32640. let c = new View();
  32641. c.yaw = this.yaw;
  32642. c._pitch = this.pitch;
  32643. c.radius = this.radius;
  32644. c.maxPitch = this.maxPitch;
  32645. c.minPitch = this.minPitch;
  32646. return c;
  32647. }
  32648. get pitch () {
  32649. return this._pitch;
  32650. }
  32651. set pitch (angle) {
  32652. this._pitch = Math.max(Math.min(angle, this.maxPitch), this.minPitch);
  32653. }
  32654. get direction () {
  32655. let dir = new Vector3(0, 1, 0);
  32656. dir.applyAxisAngle(new Vector3(1, 0, 0), this.pitch);
  32657. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  32658. return dir;
  32659. }
  32660. set direction (dir) {
  32661. dir = dir.clone().normalize();//add
  32662. if(dir.x === 0 && dir.y === 0){
  32663. this.pitch = Math.PI / 2 * Math.sign(dir.z);
  32664. //this.yaw = 0 //add:还是要指定一下, 否则不统一
  32665. }else {
  32666. let yaw = Math.atan2(dir.y, dir.x) - Math.PI / 2;
  32667. let pitch = Math.atan2(dir.z, Math.sqrt(dir.x * dir.x + dir.y * dir.y));
  32668. this.yaw = yaw;
  32669. this.pitch = pitch;
  32670. }
  32671. }
  32672. lookAt(t){//setPivot
  32673. let V;
  32674. if(arguments.length === 1){
  32675. V = new Vector3().subVectors(t, this.position);
  32676. }else if(arguments.length === 3){
  32677. V = new Vector3().subVectors(new Vector3(...arguments), this.position);
  32678. }
  32679. let radius = V.length();
  32680. let dir = V.normalize();
  32681. this.radius = radius;
  32682. this.direction = dir;
  32683. }
  32684. getPivot () {
  32685. return new Vector3().addVectors(this.position, this.direction.multiplyScalar(this.radius));
  32686. }
  32687. getSide () {
  32688. let side = new Vector3(1, 0, 0);
  32689. side.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  32690. return side;
  32691. }
  32692. pan (x, y) {
  32693. let dir = new Vector3(0, 1, 0);
  32694. dir.applyAxisAngle(new Vector3(1, 0, 0), this.pitch);
  32695. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  32696. // let side = new THREE.Vector3(1, 0, 0);
  32697. // side.applyAxisAngle(new THREE.Vector3(0, 0, 1), this.yaw);
  32698. let side = this.getSide();
  32699. let up = side.clone().cross(dir);
  32700. let pan = side.multiplyScalar(x).add(up.multiplyScalar(y));
  32701. this.position = this.position.add(pan);
  32702. // this.target = this.target.add(pan);
  32703. }
  32704. translate (x, y, z) {
  32705. let dir = new Vector3(0, 1, 0);
  32706. dir.applyAxisAngle(new Vector3(1, 0, 0), this.pitch);
  32707. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  32708. let side = new Vector3(1, 0, 0);
  32709. side.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);
  32710. let up = side.clone().cross(dir);
  32711. let t = side.multiplyScalar(x)
  32712. .add(dir.multiplyScalar(y))
  32713. .add(up.multiplyScalar(z));
  32714. this.position = this.position.add(t);
  32715. }
  32716. translateWorld (x, y, z) {
  32717. this.position.x += x;
  32718. this.position.y += y;
  32719. this.position.z += z;
  32720. }
  32721. setView(position, target, duration = 0, callback = null){
  32722. let endPosition = null;
  32723. if(position instanceof Array){
  32724. endPosition = new Vector3(...position);
  32725. }else if(position.x != null){
  32726. endPosition = position.clone();
  32727. }
  32728. let endTarget = null;
  32729. if(target instanceof Array){
  32730. endTarget = new Vector3(...target);
  32731. }else if(target.x != null){
  32732. endTarget = target.clone();
  32733. }
  32734. const startPosition = this.position.clone();
  32735. const startTarget = this.getPivot();
  32736. //const endPosition = position.clone();
  32737. //const endTarget = target.clone();
  32738. let easing = TWEEN.Easing.Quartic.Out;
  32739. if(duration === 0){
  32740. this.position.copy(endPosition);
  32741. this.lookAt(endTarget);
  32742. }else {
  32743. let value = {x: 0};
  32744. let tween = new TWEEN.Tween(value).to({x: 1}, duration);
  32745. tween.easing(easing);
  32746. //this.tweens.push(tween);
  32747. tween.onUpdate(() => {
  32748. let t = value.x;
  32749. //console.log(t);
  32750. const pos = new Vector3(
  32751. (1 - t) * startPosition.x + t * endPosition.x,
  32752. (1 - t) * startPosition.y + t * endPosition.y,
  32753. (1 - t) * startPosition.z + t * endPosition.z,
  32754. );
  32755. const target = new Vector3(
  32756. (1 - t) * startTarget.x + t * endTarget.x,
  32757. (1 - t) * startTarget.y + t * endTarget.y,
  32758. (1 - t) * startTarget.z + t * endTarget.z,
  32759. );
  32760. this.position.copy(pos);
  32761. this.lookAt(target);
  32762. });
  32763. tween.start();
  32764. tween.onComplete(() => {
  32765. if(callback){
  32766. callback();
  32767. }
  32768. });
  32769. }
  32770. }
  32771. };
  32772. let sid = 0;
  32773. class ExtendView extends View {
  32774. constructor () {
  32775. super();
  32776. this.yaw = 0; //Math.PI / 4; // = 4dkk lon + 90
  32777. this._pitch = 0; //-Math.PI / 4; //上下旋转 = 4dkk lat
  32778. this.sid = sid++;
  32779. this.LookTransition = 'LookTransition'+this.sid;
  32780. this.FlyTransition = 'FlyTransition'+this.sid;
  32781. }
  32782. //add------
  32783. applyToCamera(camera){
  32784. camera.position.copy(this.position);
  32785. camera.rotation.copy(this.rotation);
  32786. camera.updateMatrix();
  32787. camera.updateMatrixWorld();
  32788. //camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  32789. }
  32790. get rotation(){
  32791. var rotation = new Euler;
  32792. rotation.order = "ZXY";
  32793. rotation.x = Math.PI / 2 + this.pitch;
  32794. rotation.z = this.yaw;
  32795. return rotation
  32796. }
  32797. set rotation(rotation){
  32798. if(rotation.y != 0){//因为 rotation的y不一定是0 , 所以不能直接逆着get rotation写。
  32799. //console.error('set rotation y不为0!!!!?', rotation ) //过渡时因为quaternion lerp所以不为0。没办法了orz
  32800. this.direction = new Vector3(0,0,-1).applyEuler(rotation); //转回direction有损耗,在俯视时的(dir.x==dir.y==0), 丢失yaw信息从而 yaw无法获取(希望不要遇到这种情况,如果有的话,考虑先计算yaw,似乎好像可以算)
  32801. }else {//尽量不用direction
  32802. this.pitch = rotation.x - Math.PI / 2;
  32803. this.yaw = rotation.z;
  32804. }
  32805. }
  32806. get quaternion(){
  32807. return new Quaternion().setFromEuler(this.rotation)
  32808. }
  32809. set quaternion(q){
  32810. this.rotation = new Euler().setFromQuaternion(q);
  32811. }
  32812. copy(a){
  32813. Common.CopyClassObject(this, a, {ignoreList: ['_listeners']});
  32814. }
  32815. clone () {
  32816. return Common.CloneClassObject(this, {ignoreList: ['_listeners']})
  32817. }
  32818. //----------
  32819. setCubeView(dir) {
  32820. switch(dir) {
  32821. case "front":
  32822. this.yaw = 0;
  32823. this.pitch = 0;
  32824. break;
  32825. case "back":
  32826. this.yaw = Math.PI;
  32827. this.pitch = 0;
  32828. break;
  32829. case "left":
  32830. this.yaw = -Math.PI / 2;
  32831. this.pitch = 0;
  32832. break;
  32833. case "right":
  32834. this.yaw = Math.PI / 2;
  32835. this.pitch = 0;
  32836. break;
  32837. case "top":
  32838. this.yaw = 0;
  32839. this.pitch = -Math.PI / 2;
  32840. break;
  32841. case "bottom":
  32842. this.yaw = -Math.PI;
  32843. this.pitch = Math.PI / 2;
  32844. break;
  32845. }
  32846. }
  32847. /* pan (x, y) {
  32848. let dir = new THREE.Vector3(0, 1, 0);
  32849. dir.applyAxisAngle(new THREE.Vector3(1, 0, 0), this.pitch);
  32850. dir.applyAxisAngle(new THREE.Vector3(0, 0, 1), this.yaw);
  32851. // let side = new THREE.Vector3(1, 0, 0);
  32852. // side.applyAxisAngle(new THREE.Vector3(0, 0, 1), this.yaw);
  32853. let side = this.getSide();
  32854. let up = side.clone().cross(dir);
  32855. let pan = side.multiplyScalar(x).add(up.multiplyScalar(y));
  32856. this.position = this.position.add(pan);
  32857. // this.target = this.target.add(pan);
  32858. } */
  32859. pan (x, y) { //发现pan其实就是translate
  32860. this.translate(x, 0, y);
  32861. }
  32862. translate (x, y, z, forceHorizon ) {
  32863. //相机方向
  32864. let dir = new Vector3(0, 1, 0);
  32865. dir.applyAxisAngle(new Vector3(1, 0, 0), forceHorizon ? 0 : this.pitch); //上下角度
  32866. dir.applyAxisAngle(new Vector3(0, 0, 1), this.yaw);//水平角度
  32867. let side = new Vector3(1, 0, 0);
  32868. side.applyAxisAngle(new Vector3(0, 0, 1), this.yaw); //垂直于相机当前水平朝向的 左右方向
  32869. let up = side.clone().cross(dir); //垂直于相机当前水平朝向的 向上方向
  32870. let t = side.multiplyScalar(x) //x影响 左右分量
  32871. .add(dir.multiplyScalar(y)) //y影响 前后分量
  32872. .add(up.multiplyScalar(z)); //z影响 上下分量
  32873. this.position = this.position.add(t);
  32874. if((!math.closeTo(x, 0, 1e-2) || !math.closeTo(y, 0, 1e-2) || !math.closeTo(z, 0, 1e-2)) && Potree.settings.displayMode != 'showPanos'){
  32875. this.cancelFlying('pos');
  32876. }
  32877. this.restrictPos();
  32878. }
  32879. translateWorld (x, y, z) {
  32880. super.translateWorld(x, y, z);
  32881. if((!math.closeTo(x, 0, 1e-2) || !math.closeTo(y, 0, 1e-2) || !math.closeTo(z, 0, 1e-2)) && Potree.settings.displayMode != 'showPanos'){
  32882. this.cancelFlying('pos');
  32883. }
  32884. this.restrictPos();
  32885. }
  32886. restrictPos(position){//add
  32887. if(this.limitBound){
  32888. (position || this.position).clamp(this.limitBound.min, this.limitBound.max);
  32889. }
  32890. }
  32891. isFlying(type='all'){
  32892. let a = transitions.getById(this.FlyTransition).length > 0;
  32893. let b = transitions.getById(this.LookTransition).length > 0;
  32894. return type == 'pos' ? a : type == 'rotate' ? b : (a || b)
  32895. }
  32896. cancelFlying(type='all', dealCancel=true){//外界只能通过这个来cancel
  32897. type == 'pos' ? transitions.cancelById(this.FlyTransition, dealCancel )
  32898. : type == 'rotate' ? transitions.cancelById(this.LookTransition, dealCancel )
  32899. : (transitions.cancelById(this.FlyTransition, dealCancel ), transitions.cancelById(this.LookTransition, dealCancel ));
  32900. //console.log('cancelFlying ' , this.sid, type)
  32901. }
  32902. setView( info = {}){
  32903. // position, target, duration = 0, callback = null, onUpdate = null, Easing='', cancelFun
  32904. this.cancelFlying();
  32905. let posWaitDone, rotWaitDone , dir;
  32906. let posDone = ()=>{
  32907. rotWaitDone || done();
  32908. posWaitDone = false;
  32909. };
  32910. let rotDone = ()=>{
  32911. if(endTarget){
  32912. this.lookAt(endTarget); //compute radius for orbitcontrol
  32913. }else if(endQuaternion){
  32914. this.rotation = new Euler().setFromQuaternion(endQuaternion);
  32915. }else if(endYaw != void 0){
  32916. this.yaw = endYaw, this.pitch = endPitch;
  32917. }
  32918. //if(dir.x == 0 && dir.y == 0)this.yaw = 0 //统一一下 朝上的话是正的。朝下的一般不是0,会保留一个接近0的小数所以不用管
  32919. posWaitDone || done();
  32920. rotWaitDone = false;
  32921. };
  32922. let done = ()=>{ //一定要旋转和位移都结束了才能执行
  32923. let f = ()=>{
  32924. this.position.copy(endPosition); //因为延时1后control的update会导致位置改变
  32925. info.callback && info.callback();
  32926. this.dispatchEvent('flyingDone');
  32927. };
  32928. if(info.duration){
  32929. setTimeout(f,1);//延迟是为了使isFlying先为false
  32930. }else {
  32931. f(); //有的需要迅速执行回调
  32932. }
  32933. };
  32934. let endPosition = new Vector3().copy(info.position);
  32935. let startPosition = this.position.clone();
  32936. let startQuaternion, endQuaternion, endTarget = info.target && new Vector3().copy(info.target) ,
  32937. endYaw, startYaw, endPitch, startPitch ;
  32938. this.restrictPos(endPosition);
  32939. if(info.endYaw == void 0){
  32940. if(info.target ){
  32941. endQuaternion = math.getQuaFromPosAim(endPosition,endTarget); //若为垂直,会自动偏向x负的方向
  32942. }else if(info.quaternion){
  32943. endQuaternion = info.quaternion.clone();
  32944. }
  32945. if(endQuaternion && math.closeTo(Math.abs(this.direction.z), 1, 1e-4)){ //在垂直的视角下的quaternion刚开始突变的厉害,这时候可能渐变yaw比较好(如俯视时点击测量线)
  32946. let a = this.clone();
  32947. a.quaternion = endQuaternion;
  32948. info.endYaw = a.yaw; info.endPitch = a.pitch;
  32949. //console.log('turn to yaw')
  32950. }
  32951. }
  32952. if(info.endYaw != void 0) {
  32953. startPitch = this.pitch;
  32954. endPitch = info.endPitch;
  32955. startYaw = this.yaw;
  32956. endYaw = info.endYaw;
  32957. if(Math.abs(startYaw - endYaw)>Math.PI){//如果差距大于半个圆,就要反个方向转(把大的那个数字减去360度)
  32958. startYaw > endYaw ? (startYaw -= Math.PI*2) : (endYaw -= Math.PI*2);
  32959. }
  32960. //console.log('startYaw', startYaw, 'endYaw', endYaw)
  32961. }
  32962. if(endQuaternion){
  32963. startQuaternion = this.quaternion;
  32964. }
  32965. if(!info.duration){
  32966. this.position.copy(endPosition);
  32967. this.restrictPos();
  32968. posWaitDone = true, rotWaitDone = true;
  32969. info.onUpdate && info.onUpdate(1);
  32970. posDone();
  32971. rotDone();
  32972. }else {
  32973. info.onUpdate && info.onUpdate(0); //初始化progress
  32974. let posChange = !this.position.equals(endPosition);
  32975. if(posChange){
  32976. posWaitDone = true;
  32977. transitions.start(lerp.vector(this.position, endPosition, (pos, progress, delta)=>{
  32978. info.onUpdate && info.onUpdate(progress, delta);
  32979. }), info.duration, posDone , 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine ,null, this.FlyTransition, ()=>{
  32980. //中途取消
  32981. if(endTarget ){
  32982. /* endPosition = new THREE.Vector3().copy(this.position)//更改旋转的endQuaternion
  32983. endQuaternion = math.getQuaFromPosAim(endPosition,endTarget) */
  32984. //直接改变endQuaternion会突变,所以还是cancel吧
  32985. this.cancelFlying('rotate');
  32986. }
  32987. posWaitDone = false;
  32988. info.cancelFun && info.cancelFun();
  32989. }, info.ignoreFirstFrame);
  32990. }
  32991. if(endQuaternion || endYaw != void 0){
  32992. rotWaitDone = true;
  32993. transitions.start( (progress, delta )=>{
  32994. if(endYaw != void 0){
  32995. this.yaw = startYaw * (1-progress) + endYaw * progress;
  32996. this.pitch = startPitch * (1-progress) + endPitch * progress;
  32997. }else {
  32998. let quaternion = (new Quaternion()).copy(startQuaternion);
  32999. lerp.quaternion(quaternion, endQuaternion)(progress); //在垂直的视角下的角度突变的厉害,这时候可能渐变yaw比较好
  33000. this.quaternion = quaternion;
  33001. //console.log(quaternion,this.yaw)
  33002. }
  33003. posChange || info.onUpdate && info.onUpdate(progress, delta);
  33004. }, info.duration, rotDone , 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine ,null, this.LookTransition, ()=>{
  33005. //中途取消
  33006. rotWaitDone = false;
  33007. info.cancelFun && info.cancelFun();
  33008. }, info.ignoreFirstFrame);
  33009. }
  33010. /* transitions.start(lerp.vector(this.position, endPosition, (pos, progress)=>{
  33011. let t = progress
  33012. if(endQuaternion){
  33013. let quaternion = (new THREE.Quaternion()).copy(startQuaternion)
  33014. lerp.quaternion(quaternion, endQuaternion)(progress),
  33015. this.rotation = new THREE.Euler().setFromQuaternion(quaternion)
  33016. }
  33017. this.restrictPos()
  33018. //console.log('setView flying')
  33019. info.onUpdate && info.onUpdate(t)//add
  33020. }), info.duration, done, 0, info.Easing ? easing[info.Easing] : easing.easeInOutSine ,null, this.LookTransition, info.cancelFun); //easeInOutQuad
  33021. */
  33022. }
  33023. }
  33024. //平移Ortho相机
  33025. moveOrthoCamera(viewport, info, duration, easeName){//boundSize优先于endZoom。
  33026. let camera = info.camera || viewport.camera;
  33027. let startZoom = camera.zoom;
  33028. let endPosition = info.endPosition;
  33029. let boundSize = info.boundSize;
  33030. let endZoom = info.endZoom;
  33031. let margin = info.margin || {x:0,y:0};/* 200 */ //像素
  33032. let onUpdate = info.onUpdate;
  33033. if(info.bound){//需要修改boundSize以适应相机的旋转,当相机不在xy水平面上朝向z时
  33034. endPosition = endPosition || info.bound.getCenter(new Vector3());
  33035. let matrixRot = new Matrix4().makeRotationFromEuler(this.rotation).invert();
  33036. let boundingBox = info.bound.clone().applyMatrix4(matrixRot);
  33037. boundSize = boundingBox.getSize(new Vector3());
  33038. }
  33039. if(boundSize && boundSize.x == 0 && boundSize.y == 0){
  33040. boundSize.set(1,1); //避免infinity
  33041. }
  33042. this.setView( Object.assign(info, { position:endPosition, duration,
  33043. onUpdate:(progress, delta)=>{
  33044. if(boundSize || endZoom){
  33045. if(boundSize){
  33046. let aspect = boundSize.x / boundSize.y;
  33047. let w, h;
  33048. if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
  33049. h = boundSize.y;
  33050. endZoom = (viewport.resolution.y - margin.y) / h; //注意,要在resolution不为0时执行
  33051. }else {
  33052. w = boundSize.x;
  33053. endZoom = (viewport.resolution.x - margin.x) / w;
  33054. }
  33055. //onUpdate时更新endzoom是因为画布大小可能更改
  33056. }
  33057. this.zoom = camera.zoom = endZoom * progress + startZoom * (1 - progress); //view里也加一下,有些地方需要记录,如截图
  33058. camera.updateProjectionMatrix();
  33059. onUpdate && onUpdate(progress, delta);
  33060. }
  33061. },
  33062. Easing:easeName
  33063. }));
  33064. }
  33065. zoomOrthoCamera(camera, endZoom, pointer, duration, onProgress){//定点缩放
  33066. let startZoom = camera.zoom;
  33067. let pointerPos = new Vector3(pointer.x, pointer.y,0.5);
  33068. transitions.start(( progress)=>{
  33069. let oldPos = pointerPos.clone().unproject(camera);
  33070. this.zoom = camera.zoom = endZoom * progress + startZoom * (1 - progress);
  33071. camera.updateProjectionMatrix();
  33072. let newPos = pointerPos.clone().unproject(camera);
  33073. //定点缩放, 恢复一下鼠标所在位置的位置改变量
  33074. let moveVec = new Vector3().subVectors(newPos, oldPos);
  33075. camera.position.sub(moveVec);
  33076. this.position.copy(camera.position);
  33077. onProgress && onProgress();
  33078. } , duration, null/* done */, 0, easing.easeInOutSine, null, "zoomInView"/* , info.cancelFun */);
  33079. }
  33080. tranCamera(viewport, info, duration, easeName){
  33081. viewport.camera = info.midCamera;
  33082. //viewport.camera.matrixWorld = info.endCamera.matrixWorld
  33083. //viewer.setCameraMode(CameraMode.ORTHOGRAPHIC)
  33084. info.midCamera.projectionMatrix.copy(info.startCamera.projectionMatrix);
  33085. let onUpdate = info.onUpdate;
  33086. info.onUpdate = (progress, delta)=>{
  33087. lerp.matrix4(info.midCamera.projectionMatrix, info.endCamera.projectionMatrix)(progress);
  33088. onUpdate && onUpdate(progress, delta);
  33089. };
  33090. let callback = info.callback;
  33091. info.callback = ()=>{
  33092. viewport.camera = info.endCamera;
  33093. viewer.scene.measurements.forEach((e)=>{
  33094. Potree.Utils.updateVisible(e, 'tranCamera', true);
  33095. });
  33096. this.applyToCamera(viewport.camera);
  33097. viewer.dispatchEvent({type:'camera_changed', viewport:viewer.mainViewport, changeInfo:{}});//update sprite
  33098. callback && callback();
  33099. };
  33100. //info.forbitCancel = true
  33101. info.camera = info.endCamera;
  33102. if(info.camera.type == "OrthographicCamera"){
  33103. this.moveOrthoCamera(viewport, info, duration, easeName);
  33104. }else {
  33105. this.setView( Object.assign(info, { duration}) );
  33106. }
  33107. }
  33108. };
  33109. var math = {
  33110. getBaseLog(x, y) {//返回以 x 为底 y 的对数(即 logx y) . Math.log 返回一个数的自然对数
  33111. return Math.log(y) / Math.log(x);
  33112. }
  33113. ,
  33114. convertVector : {
  33115. ZupToYup: function(e){//navvis -> 4dkk
  33116. return new Vector3(e.x,e.z,-e.y)
  33117. },
  33118. YupToZup: function(e){//4dkk -> navvis
  33119. return new Vector3(e.x,-e.z,e.y)
  33120. },
  33121. },
  33122. convertQuaternion: {
  33123. ZupToYup: function(e){//navvis -> 4dkk //不同于convertVisionQuaternion
  33124. let rotation = new Euler(-Math.PI/2,0,0);
  33125. let quaternion = new Quaternion().setFromEuler(rotation);
  33126. return e.clone().premultiply(quaternion)
  33127. //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)))
  33128. },
  33129. YupToZup: function(e){//4dkk -> navvis
  33130. let rotation = new Euler(Math.PI/2,0,0);
  33131. let quaternion = new Quaternion().setFromEuler(rotation);
  33132. return e.clone().premultiply(quaternion)
  33133. },
  33134. },
  33135. convertVisionQuaternion: function(e) {
  33136. return new Quaternion(e.x,e.z,-e.y,e.w).multiply((new Quaternion).setFromAxisAngle(new Vector3(0,1,0), MathUtils.degToRad(90)))
  33137. },
  33138. invertVisionQuaternion : function(e) {//反转给算法部
  33139. var a = e.clone().multiply((new Quaternion).setFromAxisAngle(new Vector3(0,1,0), MathUtils.degToRad(-90)));
  33140. return new Quaternion(a.x,-a.z,a.y,a.w)
  33141. },
  33142. //------------
  33143. getVec2Angle : function(dir1,dir2){
  33144. return Math.acos( MathUtils.clamp(this.getVec2Cos(dir1,dir2), -1,1) )
  33145. },
  33146. getVec2Cos : function(dir1,dir2){
  33147. return dir1.dot(dir2) / dir1.length() / dir2.length()
  33148. },
  33149. getAngle:function(vec1, vec2, axis='z'){//带方向的角度 vector3
  33150. if(!vec1.isVector3){
  33151. vec1 = new Vector3(vec1.x, vec1.y, 0);
  33152. vec2 = new Vector3(vec2.x, vec2.y, 0);
  33153. }
  33154. var angle = vec1.angleTo(vec2);
  33155. var axis_ = vec1.clone().cross(vec2);
  33156. if(typeof axis == 'string'){
  33157. if(axis_[axis] < 0){
  33158. angle *= -1;
  33159. }
  33160. }else {//vector3
  33161. if(axis_.dot(axis)< 0){
  33162. angle *= -1;
  33163. }
  33164. }
  33165. return angle
  33166. },
  33167. closeTo : function(a,b, precision=1e-6){
  33168. let f = (a,b)=>{
  33169. return Math.abs(a-b) < precision;
  33170. };
  33171. if(typeof (a) == 'number'){
  33172. return f(a, b);
  33173. }else {
  33174. let judge = (name)=>{
  33175. if(a[name] == void 0)return true //有值就判断,没值就不判断
  33176. else return f(a[name],b[name])
  33177. };
  33178. return judge('x') && judge('y') && judge('z') && judge('w')
  33179. }
  33180. },
  33181. toPrecision: function (e, t) {//xzw change 保留小数
  33182. var f = function (e, t) {
  33183. var i = Math.pow(10, t);
  33184. return Math.round(e * i) / i
  33185. };
  33186. if (e instanceof Array) {
  33187. for (var s = 0; s < e.length; s++) {
  33188. e[s] = f(e[s], t);
  33189. }
  33190. return e;
  33191. } else if (e instanceof Object) {
  33192. for (var s in e) {
  33193. e[s] = f(e[s], t);
  33194. }
  33195. return e;
  33196. } else if(typeof e == 'number'){
  33197. return f(e, t)
  33198. }else {
  33199. return e
  33200. }
  33201. },
  33202. isEmptyQuaternion: function(e) {
  33203. return 0 === Math.abs(e.x) && 0 === Math.abs(e.y) && 0 === Math.abs(e.z) && 0 === Math.abs(e.w)
  33204. },
  33205. projectPositionToCanvas: function(e, t, i) {
  33206. i = i || new Vector3,
  33207. i.copy(e);
  33208. var r = .5 * $('#player').width()
  33209. , o = .5 * $('#player').height();
  33210. return i.project(t),
  33211. i.x = i.x * r + r,
  33212. i.y = -(i.y * o) + o,
  33213. i
  33214. },
  33215. handelPadResize:false,
  33216. /* handelPadding : function () { //去除player左边和上面的宽高,因为pc的player左上有其他element 许钟文
  33217. var pads = [];//记录下来避免反复计算
  33218. var index = [];
  33219. var resetPad = function(){
  33220. pads = [];
  33221. index = [];
  33222. math.handelPadResize = false; //switchview时resized为true
  33223. }
  33224. if(config.isEdit && !config.isMobile){
  33225. window.addEventListener('resize',resetPad);
  33226. }
  33227. return function(x, y, domE){
  33228. if(!config.isEdit || config.isMobile) {
  33229. return {
  33230. x: x,
  33231. y: y
  33232. }
  33233. }
  33234. if(this.handelPadResize)resetPad();
  33235. domE = domE || $('#player')[0];
  33236. var pad;
  33237. var i = index.indexOf(domE);
  33238. if (i == -1){
  33239. index.push(domE);
  33240. pad = {
  33241. x: this.getOffset("left", domE),
  33242. y: this.getOffset("top", domE)
  33243. }
  33244. pads.push(pad)
  33245. }
  33246. else pad = pads[i];
  33247. return {
  33248. x: x - pad.x,
  33249. y: y - pad.y
  33250. }
  33251. }
  33252. }(), */
  33253. getOffset: function (type, element, parent) {//获取元素的边距 许钟文
  33254. var offset = (type == "left") ? element.offsetLeft : element.offsetTop;
  33255. if (!parent) parent = $("body")[0];
  33256. while (element = element.offsetParent) {
  33257. if (element == parent) break;
  33258. offset += (type == "left") ? element.offsetLeft : element.offsetTop;
  33259. }
  33260. return offset;
  33261. }
  33262. ,
  33263. constrainedTurn: function(e) {
  33264. var t = e % (2 * Math.PI);
  33265. return t = t > Math.PI ? t -= 2 * Math.PI : t < -Math.PI ? t += 2 * Math.PI : t
  33266. },
  33267. getFOVDotThreshold: function(e) {
  33268. return Math.cos(MathUtils.degToRad(e / 2))
  33269. },
  33270. transform2DForwardVectorByCubeFace: function(e, t, i, n) {
  33271. switch (e) {
  33272. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  33273. i.set(1, t.y, t.x);
  33274. break;
  33275. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  33276. i.set(-1, t.y, -t.x);
  33277. break;
  33278. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  33279. i.set(-t.x, 1, -t.y);
  33280. break;
  33281. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  33282. i.set(-t.x, -1, t.y);
  33283. break;
  33284. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  33285. i.set(-t.x, t.y, 1);
  33286. break;
  33287. case GLCubeFaces.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  33288. i.set(t.x, t.y, -1);
  33289. }
  33290. n && i.normalize();
  33291. },
  33292. getFootPoint : function(oldPos, p1, p2, restricInline){ //找oldPos在线段p1, p2上的垂足
  33293. /* if(isWorld){//输出全局坐标 需要考虑meshGroup.position
  33294. p1 = p1.clone();
  33295. p2 = p2.clone();
  33296. p1.y += mainDesign.meshGroup.position.y;
  33297. p2.y += mainDesign.meshGroup.position.y;
  33298. } */
  33299. if(p1.equals(p2))return p1.clone()
  33300. var op1 = oldPos.clone().sub(p1);
  33301. var p1p2 = p1.clone().sub(p2);
  33302. var p1p2Len = p1p2.length();
  33303. var leftLen = op1.dot(p1p2) / p1p2Len;
  33304. var pos = p1.clone().add(p1p2.multiplyScalar( leftLen/p1p2Len ));
  33305. if(restricInline && pos.clone().sub(p1).dot( pos.clone().sub(p2) ) > 0){//foot不在线段上
  33306. if(pos.distanceTo(p1) < pos.distanceTo(p2)) pos = p1.clone();
  33307. else pos = p2.clone();
  33308. }
  33309. return pos;
  33310. },
  33311. /**
  33312. * 计算多边形的重心
  33313. * @param {*} points
  33314. */
  33315. getCenterOfGravityPoint : function(mPoints){
  33316. var area = 0.0;//多边形面积
  33317. var Gx = 0.0, Gy = 0.0;// 重心的x、y
  33318. for (var i = 1; i <= mPoints.length; i++) {
  33319. var ix = mPoints[i % mPoints.length].x;
  33320. var iy = mPoints[i % mPoints.length].y;
  33321. var nx = mPoints[i - 1].x;
  33322. var ny = mPoints[i - 1].y;
  33323. var temp = (ix * ny - iy * nx) / 2.0;
  33324. area += temp;
  33325. Gx += temp * (ix + nx) / 3.0;
  33326. Gy += temp * (iy + ny) / 3.0;
  33327. }
  33328. Gx = Gx / area;
  33329. Gy = Gy / area;
  33330. return { x: Gx, y: Gy };
  33331. },
  33332. getBound : function(ring){
  33333. var bound = new Box2();
  33334. for(var j=0,len = ring.length; j<len; j++){
  33335. bound.expandByPoint(ring[j]);
  33336. }
  33337. return bound;
  33338. },
  33339. isPointInArea : function(ring, holes, point, ifAtLine){//判断点是否在某个环内, 若传递了holes代表还要不能在内环内
  33340. var bound = this.getBound(ring);
  33341. if(point.x < bound.min.x || point.x > bound.max.x || point.y < bound.min.y || point.y > bound.max.y)return false;
  33342. var inside = false;
  33343. var x = point.x,
  33344. y = point.y;
  33345. for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
  33346. var xi = ring[i].x,
  33347. yi = ring[i].y;
  33348. var xj = ring[j].x,
  33349. yj = ring[j].y;
  33350. if((xi - x)*(yj - y) == (xi - x)*(yi - y) && x>=Math.min(xi,xj) && x<=Math.max(xi,xj)//xzw add
  33351. && y>=Math.min(yi,yj) && y<=Math.max(yi,yj)
  33352. ){
  33353. //return !!ifAtLine;//在线段上,则判断为…… (默认在外)
  33354. return {atLine:true}
  33355. }
  33356. if (((yi > y) != (yj > y)) &&
  33357. (x < (xj - xi) * (y - yi) / (yj - yi) + xi)
  33358. ) {
  33359. inside = !inside;
  33360. }
  33361. }
  33362. if(inside && holes){
  33363. return !holes.some(ring=>this.isPointInArea(ring, null, point, ifAtLine) ) //不能存在于任何一个二级内环内
  33364. }else {
  33365. return inside;
  33366. }
  33367. },
  33368. getArea : function (ring) { //求面积 顺时针为正 来自three shape
  33369. for (var t = ring.length, i = 0, n = t - 1, r = 0; r < t; n = r++)
  33370. i += ring[n].x * ring[r].y - ring[r].x * ring[n].y;
  33371. return -.5 * i
  33372. },
  33373. getVolume:function(faceArr){//求三角多面体的体积。和求面积同理都用鞋带计算法 https://blog.csdn.net/weixin_43414513/article/details/123758897
  33374. //问题:怎么确定方向
  33375. //每个三角形的顺序必须是右手螺旋法则指向物体外(外向里看为逆时针),分别为ABC,则每个三角形和原点O构成的三棱锥体积为 (OA cross OB) dot(OC) / 6 . 结果一般朝向原点的为负,反之为正
  33376. },
  33377. isInBetween : function(a, b, c, precision) {
  33378. // 如果b几乎等于a或c,返回false.为了避免浮点运行时两值几乎相等,但存在相差0.00000...0001的这种情况出现使用下面方式进行避免
  33379. /* if (Math.abs(a - b) < 0.000001 || Math.abs(b - c) < 0.000001) {
  33380. return false;
  33381. }
  33382. return (a <= b && b <= c) || (c <= b && b <= a);*/
  33383. //更改:如果b和a或c中一个接近 就算在a和c之间
  33384. return (a <= b && b <= c) || (c <= b && b <= a) || this.closeTo(a,b,precision) || this.closeTo(b,c,precision);
  33385. },
  33386. ifPointAtLineBound:function(point, linePoints, precision){
  33387. //待验证 横线和竖线比较特殊
  33388. return math.isInBetween(linePoints[0].x, point.x, linePoints[1].x, precision) && math.isInBetween(linePoints[0].y, point.y, linePoints[1].y, precision)
  33389. }
  33390. ,
  33391. isLineIntersect: function (line1, line2, notSegment, precision) {//线段和线段是否有交点. notSegment代表是直线而不是线段
  33392. var a1 = line1[1].y - line1[0].y;
  33393. var b1 = line1[0].x - line1[1].x;
  33394. var c1 = a1 * line1[0].x + b1 * line1[0].y;
  33395. //转换成一般式: Ax+By = C
  33396. var a2 = line2[1].y - line2[0].y;
  33397. var b2 = line2[0].x - line2[1].x;
  33398. var c2 = a2 * line2[0].x + b2 * line2[0].y;
  33399. // 计算交点
  33400. var d = a1 * b2 - a2 * b1;
  33401. // 当d==0时,两线平行
  33402. if (d == 0) {
  33403. return false;
  33404. } else {
  33405. var x = (b2 * c1 - b1 * c2) / d;
  33406. var y = (a1 * c2 - a2 * c1) / d;
  33407. // 检测交点是否在两条线段上
  33408. /* if (notSegment || (isInBetween(line1[0].x, x, line1[1].x) || isInBetween(line1[0].y, y, line1[1].y)) &&
  33409. (isInBetween(line2[0].x, x, line2[1].x) || isInBetween(line2[0].y, y, line2[1].y))) {
  33410. return {x,y};
  33411. } */
  33412. if (notSegment || math.ifPointAtLineBound({x,y}, line1, precision) && math.ifPointAtLineBound({x,y}, line2, precision)){
  33413. return {x,y};
  33414. }
  33415. }
  33416. },
  33417. getNormal2d : function(o={} ){//获取二维法向量 方向向内
  33418. var x,y, x1,y1;
  33419. //line2d的向量
  33420. if(o.vec){
  33421. x1 = o.vec.x; y1 = o.vec.y;
  33422. }else {
  33423. x1 = o.p1.x - o.p2.x;
  33424. y1 = o.p1.y - o.p2.y;
  33425. }
  33426. //假设法向量的x或y固定为1或-1
  33427. if(y1 != 0){
  33428. x = 1;
  33429. y = - (x1 * x) / y1;
  33430. }else if(x1 != 0){//y如果为0,正常情况x不会是0
  33431. y = 1;
  33432. x = - (y1 * y) / x1;
  33433. }else {
  33434. console.log("两个点一样");
  33435. return null;
  33436. }
  33437. //判断方向里或者外:
  33438. var vNormal = new Vector3(x, 0, y);
  33439. var vLine = new Vector3(x1, 0, y1);
  33440. var vDir = vNormal.cross(vLine);
  33441. if(vDir.y>0){
  33442. x *= -1;
  33443. y *= -1;
  33444. }
  33445. return new Vector2(x, y).normalize();
  33446. },
  33447. getQuaBetween2Vector:function(oriVec, newVec, upVec){ //获取从oriVec旋转到newVec可以应用的quaternion
  33448. var angle = oriVec.angleTo(newVec);
  33449. var axis = oriVec.clone().cross( newVec).normalize();//两个up之间
  33450. if(axis.length() == 0){//当夹角为180 或 0 度时,得到的axis为(0,0,0),故使用备用的指定upVec
  33451. return new Quaternion().setFromAxisAngle( upVec, angle );
  33452. }
  33453. return new Quaternion().setFromAxisAngle( axis, angle );
  33454. } ,
  33455. /*
  33456. getQuaBetween2Vector2 : function(oriVec, newVec ){//not camera
  33457. var _ = (new THREE.Matrix4).lookAt( oriVec, new THREE.Vector3, new THREE.Vector3(0,1,0))
  33458. var aimQua = (new THREE.Quaternion).setFromRotationMatrix(_)
  33459. var _2 = (new THREE.Matrix4).lookAt( newVec, new THREE.Vector3, new THREE.Vector3(0,1,0))
  33460. var aimQua2 = (new THREE.Quaternion).setFromRotationMatrix(_2)
  33461. return aimQua2.multiply(aimQua.clone().inverse())
  33462. } */
  33463. getQuaByAim: function (aim, center=new Vector3) {
  33464. let forward = new Vector3(0, 1, 0);
  33465. let qua1 = new Quaternion().setFromUnitVectors(forward, aim.clone().sub(center).normalize());
  33466. /* var _ = (new THREE.Matrix4).lookAt(center,aim, new THREE.Vector3(0,1,0));
  33467. let qua2 = (new THREE.Quaternion).setFromRotationMatrix(_);
  33468. let rot1 = new THREE.Euler().setFromQuaternion(qua1)
  33469. let rot2 = new THREE.Euler().setFromQuaternion(qua2) //奇怪,qua2怎么都不对
  33470. console.log(rot1,rot2) */
  33471. return qua1
  33472. },
  33473. getAimByQua: function (quaternion, center=new Vector3) {
  33474. return new Vector3(0, 0, -1).applyQuaternion(quaternion).add(center)
  33475. },
  33476. getScaleForConstantSize : function(){ //获得规定二维大小的mesh的scale值。可以避免因camera的projection造成的mesh视觉大小改变。 来源:tag.updateDisc
  33477. var w;
  33478. var i = new Vector3, o = new Vector3, l = new Vector3, c = new Vector3, h = new Vector3;
  33479. return function(op={}){
  33480. if(op.width2d) w = op.width2d; //如果恒定二维宽度
  33481. else {//否则考虑上距离,加一丢丢近大远小的效果
  33482. var currentDis, nearBound, farBound;
  33483. if(op.camera.type == "OrthographicCamera"){
  33484. currentDis = 200 / op.camera.zoom; //(op.camera.right - op.camera.left) / op.camera.zoom
  33485. }else {
  33486. currentDis = op.position.distanceTo(op.camera.position);
  33487. }
  33488. w = op.maxSize - ( op.maxSize - op.minSize) * MathUtils.smoothstep(currentDis, op.nearBound, op.farBound);
  33489. //maxSize : mesh要表现的最大像素宽度; nearBound: 最近距离,若比nearBound近,则使用maxSize
  33490. }
  33491. i.copy(op.position).project(op.camera); //tag中心在屏幕上的二维坐标
  33492. o.set(op.resolution.x / 2, op.resolution.y / 2, 1).multiply(i); //转化成px -w/2 到 w/2的范围
  33493. l.set(w / 2, 0, 0).add(o); //加上tag宽度的一半
  33494. c.set(2 / op.resolution.x, 2 / op.resolution.y, 1).multiply(l); //再转回 -1 到 1的范围
  33495. h.copy(c).unproject(op.camera);//再转成三维坐标,求得tag边缘的位置
  33496. var g = h.distanceTo(op.position);//就能得到tag的三维半径
  33497. //这里使用的都是resolution2, 好处是手机端不会太小, 坏处是pc更改网页显示百分比时显示的大小会变(或许可以自己算出设备真实的deviceRatio, 因window.screen是不会改变的),但考虑到用户可以自行调节字大小也许是好的
  33498. return g //可能NAN 当相机和position重叠时
  33499. }
  33500. }()
  33501. ,
  33502. //W , H, left, top分别是rect的宽、高、左、上
  33503. getCrossPointAtRect : function(p1, aim, W , H, left, top){//求射线p1-aim在rect边界上的交点,其中aim在rect范围内,p1则不一定(交点在aim这边的延长线上)
  33504. var x,y, borderX;
  33505. var r = (aim.x - p1.x) / (aim.y - p1.y);//根据相似三角形原理先求出这个比值
  33506. var getX = function(y){
  33507. return r * (y-p1.y) + p1.x;
  33508. };
  33509. var getY = function(x){
  33510. return 1/r * (x-p1.x) + p1.y;
  33511. };
  33512. if(aim.x >= p1.x){
  33513. borderX = W+left;
  33514. }else {
  33515. borderX = left;
  33516. }
  33517. x = borderX;
  33518. y = getY(x);
  33519. if(y < top || y > top+H){
  33520. if(y < top){
  33521. y = top;
  33522. }else {
  33523. y = top+H;
  33524. }
  33525. x = getX(y);
  33526. }
  33527. return new Vector2(x, y);
  33528. },
  33529. getDirFromUV : function(uv){ //获取dir 反向计算 - - 二维转三维比较麻烦
  33530. var dirB; //所求 单位向量
  33531. var y = Math.cos(uv.y * Math.PI); //uv中纵向可以直接确定y, 根据上面getUVfromDir的反向计算
  33532. // 故 uv.y * Math.PI 就是到垂直线(向上)的夹角
  33533. var angle = 2 * Math.PI * uv.x - Math.PI; //x/z代表的是角度
  33534. var axisX, axisZ; //axis为1代表是正,-1是负数
  33535. if (-Math.PI <= angle && angle < 0) {
  33536. axisX = -1; //下半圆
  33537. } else {
  33538. axisX = 1; //上半圆
  33539. }
  33540. if (-Math.PI / 2 <= angle && angle < Math.PI / 2) {
  33541. axisZ = 1; //右半圆
  33542. } else {
  33543. axisZ = -1; //左半圆
  33544. }
  33545. var XDivideZ = Math.tan(angle);
  33546. var z = Math.sqrt((1 - y * y) / (1 + XDivideZ * XDivideZ));
  33547. var x = XDivideZ * z;
  33548. if (z * axisZ < 0) { //异号
  33549. z *= -1;
  33550. x *= -1;
  33551. if (x * axisX < 0) {
  33552. // console.log("wrong!!!!!??????????")
  33553. }
  33554. }
  33555. x *= -1; //计算完成后这里不能漏掉 *= -1
  33556. dirB = this.convertVector.YupToZup(new Vector3(x, y, z));
  33557. //理想状态下x和z和anotherDir相同
  33558. return dirB
  33559. },
  33560. getUVfromDir : function(dir) { //获取UV 同shader里的计算
  33561. var dir = this.convertVector.ZupToYup(dir);
  33562. dir.x *= -1; //计算前这里不能漏掉 *= -1 见shader
  33563. var tx = Math.atan2(dir.x, dir.z) / (Math.PI * 2.0) + 0.5; //atan2(y,x) 返回从 X 轴正向逆时针旋转到点 (x,y) 时经过的角度。区间是-PI 到 PI 之间的值
  33564. var ty = Math.acos(dir.y) / Math.PI;
  33565. return new Vector2(tx, ty)
  33566. //理想状态下tx相同
  33567. },
  33568. getDirByLonLat : function(lon,lat){
  33569. var dir = new Vector3;
  33570. var phi = MathUtils.degToRad(90 - lat);
  33571. var theta = MathUtils.degToRad(lon);
  33572. dir.x = Math.sin(phi) * Math.cos(theta);
  33573. dir.y = Math.cos(phi);
  33574. dir.z = Math.sin(phi) * Math.sin(theta);
  33575. return dir
  33576. } //0,0 => (1,0,0) 270=>(0,0,-1)
  33577. ,
  33578. projectPointAtPlane:function(o={}){//获取一个点在一个面上的投影 {facePoints:[a,b,c], point:}
  33579. var plane = new Plane().setFromCoplanarPoints(...o.facePoints);
  33580. return plane.projectPoint(o.point, new Vector3() )
  33581. }
  33582. ,
  33583. getPolygonsMixedRings:function( polygons, onlyGetOutRing){//{points:[vector2,...],holes:[[],[]]}
  33584. let points = [];
  33585. let lines = [];
  33586. let i = 0;
  33587. polygons.forEach(e=> points.push(...e.map(a=>new Vector2().copy(a) )) );
  33588. polygons.forEach((ps,j)=>{
  33589. let length = ps.length;
  33590. let index = 0;
  33591. while(index<length){
  33592. lines.push({p1:index+i,p2:(index+1)%length+i});
  33593. index ++;
  33594. }
  33595. i+=length;
  33596. });
  33597. points.forEach((p,j)=>{p.id = j;});
  33598. let rings = searchRings({
  33599. points,
  33600. lines,
  33601. onlyGetOutRing
  33602. });
  33603. //console.log(rings)
  33604. rings = rings.filter(e=>e.closetParent == void 0);// 子环不加,被外环包含了
  33605. return rings
  33606. },
  33607. getQuaFromPosAim( position, target ){
  33608. /* let matrix = (new THREE.Matrix4).lookAt(position, target, new THREE.Vector3(0,0,1)) //这里垂直的话会默认给一个右向所以不这么写
  33609. return (new THREE.Quaternion).setFromRotationMatrix(matrix) */
  33610. let view = new ExtendView();
  33611. view.direction = new Vector3().subVectors(target,position);
  33612. return view.quaternion
  33613. },
  33614. getBoundByPoints(points, minSize){
  33615. var bound = new Box3;
  33616. points.forEach(point=>{
  33617. bound.expandByPoint(point);
  33618. });
  33619. let center = bound.getCenter(new Vector3);
  33620. if(minSize){
  33621. let minBound = (new Box3()).setFromCenterAndSize(center, minSize);
  33622. bound.union(minBound);
  33623. }
  33624. return {
  33625. bounding:bound,
  33626. size: bound.getSize(new Vector3),
  33627. center,
  33628. }
  33629. },
  33630. /* linearClamp(value, x1,x2, y1, y2){//x为bound.min, bound.max
  33631. value = THREE.Math.clamp(value, x1,x2)
  33632. return y1 + ( y2 - y1) * (value - x1) / (x2 - x1)
  33633. } */
  33634. linearClamp(value, xArr , yArr){ //xArr需要按顺序从小到大,yArr对应xArr中的值
  33635. let len = xArr.length;
  33636. if(value <= xArr[0]) return yArr[0]
  33637. if(value >= xArr[len - 1]) return yArr[len - 1]
  33638. let i = 0;
  33639. while(++i < len ){
  33640. if(value < xArr[i]){
  33641. let x1 = xArr[i-1], x2 = xArr[i], y1 = yArr[i-1], y2 = yArr[i];
  33642. value = y1 + ( y2 - y1) * (value - x1) / (x2 - x1);
  33643. break
  33644. }
  33645. }
  33646. return value
  33647. }
  33648. };
  33649. /*
  33650. 如何将若干个点拟合出线段
  33651. // 假设你有一个点数组,每个点表示为一个包含x和y坐标的对象
  33652. const points = [
  33653. { x: 1, y: 2 },
  33654. { x: 2, y: 3 },
  33655. { x: 3, y: 4 },
  33656. { x: 4, y: 5 },
  33657. // ... 更多点
  33658. ];
  33659. // 定义用于计算最小二乘法参数的函数
  33660. function leastSquares( ) {
  33661. let sumX = 0;
  33662. let sumY = 0;
  33663. let sumXY = 0;
  33664. let sumX2 = 0;
  33665. let n = points.length;
  33666. for (const point of points) {
  33667. sumX += point.x;
  33668. sumY += point.y;
  33669. sumXY += point.x * point.y;
  33670. sumX2 += point.x * point.x;
  33671. }
  33672. const k = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX); //不知道为何这样算,自己解不出来(使点到直线距离之和平方最小),但测了下似乎是准的
  33673. const b = (sumY - k * sumX) / n;
  33674. return { k, b };
  33675. }
  33676. // 使用上述函数计算拟合直线的参数
  33677. const { k, b } = leastSquares(points);
  33678. // 现在你可以使用这些参数来表示拟合出的线段
  33679. console.log(`拟合线段的方程为: y = ${k}x + ${b}`);
  33680. */
  33681. Potree.math = math;
  33682. function mobileVersion(e, t) {
  33683. //ios的版本
  33684. var i = window.navigator.userAgent,
  33685. n = i.match(e);
  33686. return (
  33687. (n = n ? n[1].split(t) : []),
  33688. {
  33689. major: parseInt(n[0]) || 0,
  33690. minor: parseInt(n[1]) || 0,
  33691. patch: parseInt(n[2]) || 0,
  33692. }
  33693. )
  33694. }
  33695. var browser = {
  33696. isFullscreen: function() {
  33697. return (
  33698. document.fullscreenElement ||
  33699. document.mozFullscreenElement ||
  33700. document.mozFullScreenElement ||
  33701. document.webkitFullscreenElement ||
  33702. document.msFullscreenElement
  33703. )
  33704. },
  33705. supportsFullscreen: function() {
  33706. return (
  33707. document.fullscreenEnabled ||
  33708. document.mozFullscreenEnabled ||
  33709. document.mozFullScreenEnabled ||
  33710. document.webkitFullscreenEnabled ||
  33711. document.msFullscreenEnabled
  33712. )
  33713. },
  33714. isPointerLocked: function() {
  33715. return (
  33716. document.pointerLockElement ||
  33717. document.mozPointerLockElement ||
  33718. document.webkitPointerLockElement
  33719. )
  33720. },
  33721. requestFullscreen: function(dom, t) {
  33722. dom.requestFullscreen ?
  33723. dom.requestFullscreen() :
  33724. dom.mozRequestFullScreen ?
  33725. dom.mozRequestFullScreen() :
  33726. dom.webkitRequestFullscreen ?
  33727. dom.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT) :
  33728. dom.msRequestFullscreen && dom.msRequestFullscreen(),
  33729. t &&
  33730. $(document).on(
  33731. "fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange",
  33732. browser.requestPointerLock
  33733. );
  33734. },
  33735. requestPointerLock: function() {
  33736. var e;
  33737. if (document.fullscreenElement) e = document.fullscreenElement();
  33738. else if (document.mozFullscreenElement) e = document.mozFullscreenElement();
  33739. else if (document.mozFullScreenElement) e = document.mozFullScreenElement();
  33740. else {
  33741. if (!document.webkitFullscreenElement) return
  33742. e = document.webkitFullscreenElement();
  33743. };
  33744. (e.requestPointerLock =
  33745. e.requestPointerLock || e.mozRequestPointerLock || e.webkitRequestPointerLock),
  33746. e.requestPointerLock(),
  33747. $(document).off(
  33748. "fullscreenchange webkitfullscreenchange mozfullscreenchange MSFullscreenChange",
  33749. this
  33750. );
  33751. },
  33752. exitPointerLock: function() {
  33753. ;
  33754. (document.exitPointerLock =
  33755. document.exitPointerLock ||
  33756. document.mozExitPointerLock ||
  33757. document.webkitExitPointerLock),
  33758. document.exitPointerLock();
  33759. },
  33760. exitFullscreen: function() {
  33761. document.exitFullscreen ?
  33762. document.exitFullscreen() :
  33763. document.msExitFullscreen ?
  33764. document.msExitFullscreen() :
  33765. document.mozCancelFullScreen ?
  33766. document.mozCancelFullScreen() :
  33767. document.webkitExitFullscreen && document.webkitExitFullscreen();
  33768. },
  33769. details: function() {
  33770. var e = navigator.userAgent.match("(Firefox|Chrome|Safari)/([\\d]+)");
  33771. return e ?
  33772. {
  33773. name: e[1],
  33774. version: parseInt(e[2]),
  33775. platform: navigator.platform,
  33776. } : {}
  33777. },
  33778. is: function(e) {
  33779. return this.details() && this.details().name === e
  33780. },
  33781. inIframe: function() {
  33782. return window.parent !== window
  33783. },
  33784. aspectRatio: function($elem) {
  33785. $elem = $elem || $("#player");
  33786. var e = $elem.width() / $elem.height();
  33787. return isFinite(e) ? e : 0
  33788. },
  33789. userAgent: function() {
  33790. return window.navigator.userAgent
  33791. },
  33792. isMobile: function() {
  33793. var e = navigator.userAgent || navigator.vendor || window.opera;
  33794. return (
  33795. /(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(
  33796. e
  33797. ) ||
  33798. /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(
  33799. e.substr(0, 4)
  33800. )
  33801. )
  33802. },
  33803. isLandscape: function() {
  33804. return this.isMobile && this.aspectRatio() > 1
  33805. },
  33806. isSmallScreen: function() {
  33807. var e = screen.width / window.devicePixelRatio;
  33808. return e < 240
  33809. },
  33810. detectIE: function() {
  33811. var e = window.navigator.userAgent,
  33812. t = e.indexOf("MSIE ");
  33813. return t !== -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./)
  33814. },
  33815. detectSafari: function() {
  33816. var e = window.navigator.userAgent,
  33817. t = e.indexOf("Safari");
  33818. return t !== -1 && !this.detectOpera() && !this.detectChrome() //xzw add detectOpera
  33819. },
  33820. detectFirefox: function() {
  33821. var e = window.navigator.userAgent;
  33822. return e.indexOf("Firefox") !== -1
  33823. },
  33824. detectChrome: function() {
  33825. var e = window.navigator.userAgent;
  33826. return e.indexOf("Chrome") !== -1 && !this.detectOpera()
  33827. },
  33828. detectOpera: function() {
  33829. var e = window.navigator.userAgent;
  33830. return e.indexOf("OPR") !== -1
  33831. },
  33832. detectIOS: function() {
  33833. return this.detectIPhone() || this.detectIPad() || this.detectIPod()
  33834. },
  33835. detectIPad: function() {
  33836. var e = window.navigator.userAgent,
  33837. t = /iPad/;
  33838. return t.test(e)
  33839. },
  33840. detectIPod: function() {
  33841. var e = window.navigator.userAgent,
  33842. t = /iPod/;
  33843. return t.test(e)
  33844. },
  33845. detectIPhone: function() {
  33846. var e = window.navigator.userAgent,
  33847. t = /iPhone/;
  33848. return t.test(e)
  33849. },
  33850. detectAndroid: function() {
  33851. var e = window.navigator.userAgent;
  33852. return e.indexOf("Android") !== -1
  33853. },
  33854. detectAndroidMobile: function() {
  33855. var e = window.navigator.userAgent;
  33856. return this.detectAndroid() && e.indexOf("Mobile") !== -1
  33857. },
  33858. detectSamsungNative: function() {
  33859. var e = window.navigator.userAgent;
  33860. return (
  33861. e.indexOf("SM-G900H") !== -1 ||
  33862. e.indexOf("GT-I9500") !== -1 ||
  33863. e.indexOf("SM-N900") !== -1
  33864. )
  33865. },
  33866. detectSamsungS6: function() {
  33867. var e = window.navigator.userAgent;
  33868. return e.indexOf("SM-G92") !== -1
  33869. },
  33870. /************************************************************徐世廷*************************************************************/
  33871. detectHUAWEI5X: function() {
  33872. return -1 !== window.navigator.userAgent.indexOf("KIW-TL00H")
  33873. },
  33874. /*******************************************************************************************************************************/
  33875. detectWebVR: function() {
  33876. return !(!window.navigator.getVRDisplays || !window.VRDisplay)
  33877. },
  33878. getVRDisplay: function() {
  33879. var e = $.Deferred();
  33880. return this.detectWebVR() ?
  33881. (navigator.getVRDisplays().then(function(t) {
  33882. t.length >= 1 && e.resolve(t[0]), e.reject(null);
  33883. }),
  33884. e) :
  33885. e.reject(null)
  33886. },
  33887. iosVersion: function() {
  33888. if (!this.detectIOS()) throw new DeviceMismatchException("Did not detect an iDevice")
  33889. var e = /((?:\d+\_?){1,3}) like Mac OS/,
  33890. t = "_";
  33891. return mobileVersion(e, t)
  33892. },
  33893. androidVersion: function() {
  33894. if (!this.detectAndroid())
  33895. throw new DeviceMismatchException("Did not detect an Android based device")
  33896. var e = /Android ((?:\d+\.?){1,3})/,
  33897. t = ".";
  33898. return mobileVersion(e, t)
  33899. },
  33900. valueFromCookie: function(e, t) {
  33901. var i = new RegExp(e + "=([0-9a-f]+)(; ?|$)").exec(document.cookie);
  33902. if (!i) return t
  33903. var n = i[1];
  33904. return "boolean" == typeof t ?
  33905. "true" === n || "1" === n :
  33906. "number" == typeof t ?
  33907. parseFloat(n) :
  33908. n
  33909. },
  33910. valueFromHash: function(e, t) {
  33911. var i = new RegExp("[#&?]" + e + "=([^#&?]*)"),
  33912. n = i.exec(window.location.href);
  33913. if (!n) return t
  33914. var r = n[1];
  33915. return "boolean" == typeof t ?
  33916. "true" === r || "1" === r :
  33917. "number" == typeof t ?
  33918. parseFloat(r) :
  33919. window.decodeURIComponent(r)
  33920. },
  33921. //-------许钟文:-------------------------------------------------
  33922. getProjectNum: function() {
  33923. //获取场景projectNum
  33924. if (window.__ProjectNum && window.__ProjectNum != "__ProjectNum__") {
  33925. return window.__ProjectNum
  33926. }
  33927. var number = window.location.href.substring(window.location.href.indexOf("=") + 1);
  33928. if (number.indexOf("&") != -1) {
  33929. number = number.substring(0, number.indexOf("&"));
  33930. }
  33931. if (number.indexOf("#") != -1) {
  33932. number = number.substring(0, number.indexOf("#"));
  33933. }
  33934. return number
  33935. },
  33936. urlHasValue: function(key, isGetValue) {
  33937. let querys = window.location.search.substr(1).split("&");
  33938. if (isGetValue) {
  33939. for (let i = 0; i < querys.length; i++) {
  33940. let keypair = querys[i].split("=");
  33941. if (keypair.length === 2 && keypair[0] === key) {
  33942. return keypair[1]
  33943. }
  33944. }
  33945. return ""
  33946. } else {
  33947. for (let i = 0; i < querys.length; i++) {
  33948. let keypair = querys[i].split("=");
  33949. if (keypair[0] == key) {
  33950. return true
  33951. }
  33952. }
  33953. return false
  33954. }
  33955. },
  33956. /**
  33957. * 获取查询参数的值
  33958. * @param {String} key
  33959. * @returns String
  33960. */
  33961. urlQueryValue(key) {
  33962. return this.urlHasValue(key, true) || ""
  33963. },
  33964. /**
  33965. * 判断是否存在hash
  33966. * @param {String} key
  33967. * @returns Boolean
  33968. */
  33969. urlIsHasHash(key) {
  33970. let querys = window.location.hash.substr(1).replace('/?', '').split("&");
  33971. return querys.includes(key)
  33972. },
  33973. islongPhone: function() {
  33974. //是否是刘海全面屏幕 仅仅根据比例判断 - -
  33975. //screen.height == 812 && screen.width == 375)
  33976. var r = screen.height / screen.width; //可能横屏
  33977. return this.isMobile() && (r > 1.99 || r < 0.502512) //18/9=2.165 //???
  33978. },
  33979. detectWeixin: function() {
  33980. //微信 包括PC的微信
  33981. return window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == "micromessenger"
  33982. },
  33983. detectWeixinMiniProgram: function() {
  33984. return window.navigator.userAgent.match("miniProgram")
  33985. },
  33986. detectEdge: function() {
  33987. return window.navigator.userAgent.indexOf("Edge") > -1
  33988. },
  33989. detectApp: function() {
  33990. return this.urlHasValue("app")
  33991. },
  33992. /**
  33993. * 判断标签页是否切换状态
  33994. */
  33995. isTabHidden: function() {
  33996. var prefixes = ["webkit", "moz", "ms", "o"];
  33997. if ("hidden" in document) return document.hidden
  33998. for (var i = 0; i < prefixes.length; i++) {
  33999. if (prefixes[i] + "Hidden" in document) return document[prefixes[i] + "Hidden"]
  34000. }
  34001. return false
  34002. },
  34003. };
  34004. WebGLRenderer.prototype.paramThreeToGL = function(e) {
  34005. var t, i = this.extensions, r = this.getContext();//context;
  34006. if (e === RepeatWrapping)
  34007. return r.REPEAT;
  34008. if (e === ClampToEdgeWrapping)
  34009. return r.CLAMP_TO_EDGE;
  34010. if (e === MirroredRepeatWrapping)
  34011. return r.MIRRORED_REPEAT;
  34012. if (e === NearestFilter)
  34013. return r.NEAREST;
  34014. if (e === NearestMipMapNearestFilter)
  34015. return r.NEAREST_MIPMAP_NEAREST;
  34016. if (e === NearestMipMapLinearFilter)
  34017. return r.NEAREST_MIPMAP_LINEAR;
  34018. if (e === LinearFilter)
  34019. return r.LINEAR;
  34020. if (e === LinearMipMapNearestFilter)
  34021. return r.LINEAR_MIPMAP_NEAREST;
  34022. if (e === LinearMipMapLinearFilter)
  34023. return r.LINEAR_MIPMAP_LINEAR;
  34024. if (e === UnsignedByteType)
  34025. return r.UNSIGNED_BYTE;
  34026. if (e === UnsignedShort4444Type)
  34027. return r.UNSIGNED_SHORT_4_4_4_4;
  34028. if (e === UnsignedShort5551Type)
  34029. return r.UNSIGNED_SHORT_5_5_5_1;
  34030. if (e === UnsignedShort565Type)
  34031. return r.UNSIGNED_SHORT_5_6_5;
  34032. if (e === ByteType)
  34033. return r.BYTE;
  34034. if (e === ShortType)
  34035. return r.SHORT;
  34036. if (e === UnsignedShortType)
  34037. return r.UNSIGNED_SHORT;
  34038. if (e === IntType)
  34039. return r.INT;
  34040. if (e === UnsignedIntType)
  34041. return r.UNSIGNED_INT;
  34042. if (e === FloatType)
  34043. return r.FLOAT;
  34044. if (t = i.get("OES_texture_half_float"),
  34045. null !== t && e === HalfFloatType)
  34046. return t.HALF_FLOAT_OES;
  34047. if (e === AlphaFormat)
  34048. return r.ALPHA;
  34049. if (e === RGBFormat)
  34050. return r.RGB;
  34051. if (e === RGBAFormat)
  34052. return r.RGBA;
  34053. if (e === LuminanceFormat)
  34054. return r.LUMINANCE;
  34055. if (e === LuminanceAlphaFormat)
  34056. return r.LUMINANCE_ALPHA;
  34057. if (e === AddEquation)
  34058. return r.FUNC_ADD;
  34059. if (e === SubtractEquation)
  34060. return r.FUNC_SUBTRACT;
  34061. if (e === ReverseSubtractEquation)
  34062. return r.FUNC_REVERSE_SUBTRACT;
  34063. if (e === ZeroFactor)
  34064. return r.ZERO;
  34065. if (e === OneFactor)
  34066. return r.ONE;
  34067. if (e === SrcColorFactor)
  34068. return r.SRC_COLOR;
  34069. if (e === OneMinusSrcColorFactor)
  34070. return r.ONE_MINUS_SRC_COLOR;
  34071. if (e === SrcAlphaFactor)
  34072. return r.SRC_ALPHA;
  34073. if (e === OneMinusSrcAlphaFactor)
  34074. return r.ONE_MINUS_SRC_ALPHA;
  34075. if (e === DstAlphaFactor)
  34076. return r.DST_ALPHA;
  34077. if (e === OneMinusDstAlphaFactor)
  34078. return r.ONE_MINUS_DST_ALPHA;
  34079. if (e === DstColorFactor)
  34080. return r.DST_COLOR;
  34081. if (e === OneMinusDstColorFactor)
  34082. return r.ONE_MINUS_DST_COLOR;
  34083. if (e === SrcAlphaSaturateFactor)
  34084. return r.SRC_ALPHA_SATURATE;
  34085. if (t = i.get("WEBGL_compressed_texture_s3tc"),
  34086. null !== t) {
  34087. if (e === RGB_S3TC_DXT1_Format)
  34088. return t.COMPRESSED_RGB_S3TC_DXT1_EXT;
  34089. if (e === RGBA_S3TC_DXT1_Format$1)
  34090. return t.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  34091. if (e === RGBA_S3TC_DXT3_Format)
  34092. return t.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  34093. if (e === RGBA_S3TC_DXT5_Format$1)
  34094. return t.COMPRESSED_RGBA_S3TC_DXT5_EXT
  34095. }
  34096. if (t = i.get("WEBGL_compressed_texture_pvrtc"),
  34097. null !== t) {
  34098. if (e === RGB_PVRTC_4BPPV1_Format)
  34099. return t.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  34100. if (e === RGB_PVRTC_2BPPV1_Format)
  34101. return t.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  34102. if (e === RGBA_PVRTC_4BPPV1_Format)
  34103. return t.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  34104. if (e === RGBA_PVRTC_2BPPV1_Format)
  34105. return t.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
  34106. }
  34107. if (t = i.get("WEBGL_compressed_texture_etc1"),
  34108. null !== t && e === RGB_ETC1_Format)
  34109. return t.COMPRESSED_RGB_ETC1_WEBGL;
  34110. if (t = i.get("EXT_blend_minmax"),
  34111. null !== t) {
  34112. if (e === MinEquation)
  34113. return t.MIN_EXT;
  34114. if (e === MaxEquation)
  34115. return t.MAX_EXT
  34116. }
  34117. return 0
  34118. };
  34119. EventDispatcher.prototype.addEventListener = function(type, listener, {importance=0, once}={}){ //add importance
  34120. if ( this._listeners === undefined ) this._listeners = {};
  34121. const listeners = this._listeners;
  34122. if ( listeners[ type ] === undefined ) {
  34123. listeners[ type ] = [];
  34124. }
  34125. /* if(type == 'flyingDone'){
  34126. console.log('addEventListener flyingDone')
  34127. } */
  34128. if ( !listeners[ type ].some(e=>e.listener == listener ) ) {
  34129. listeners[type].push({ listener, importance, once});
  34130. listeners[type] = listeners[type].sort((e,a)=> a.importance - e.importance);//add
  34131. }
  34132. };
  34133. EventDispatcher.prototype.hasEventListener = function(type, listener){
  34134. if ( this._listeners === undefined ) return false;
  34135. const listeners = this._listeners;
  34136. return listeners[ type ] !== undefined && listeners[ type ].some(e=>e.listener == listener )
  34137. };
  34138. EventDispatcher.prototype.removeEventListener = function(type, listener){
  34139. if ( this._listeners === undefined ) return;
  34140. const listeners = this._listeners;
  34141. const listenerArray = listeners[ type ];
  34142. if ( listenerArray !== undefined ) {
  34143. /* const index = listenerArray.indexOf( listener );
  34144. if ( index !== - 1 ) {
  34145. listenerArray.splice( index, 1 );
  34146. } */
  34147. let item = listenerArray.find(e=>e.listener == listener);
  34148. item && listenerArray.splice(listenerArray.indexOf(item), 1);
  34149. }
  34150. };
  34151. EventDispatcher.prototype.removeEventListeners = function(type){ //add
  34152. if(this._listeners && this._listeners[type] !== undefined){
  34153. delete this._listeners[type];
  34154. }
  34155. };
  34156. EventDispatcher.prototype.removeAllListeners = function(){ //add
  34157. this._listeners = {};
  34158. };
  34159. EventDispatcher.prototype.dispatchEvent = function(event){
  34160. if(typeof event == 'string'){//add
  34161. event = {type:event};
  34162. }
  34163. if ( this._listeners === undefined ) return;
  34164. const listeners = this._listeners;
  34165. const listenerArray = listeners[ event.type ];
  34166. if ( listenerArray !== undefined ) {
  34167. event.target = this;
  34168. // Make a copy, in case listeners are removed while iterating.
  34169. for(let {listener, once} of listenerArray.slice(0)){
  34170. if(once){
  34171. this.removeEventListener(event.type,listener);
  34172. }
  34173. let result = listener.call(this, event); //add stopContinue
  34174. if(result && result.stopContinue){
  34175. break
  34176. }
  34177. }
  34178. }
  34179. };
  34180. EventDispatcher.prototype.traverse = function(callback){
  34181. let result = callback( this );
  34182. if(result && result.stopContinue){//xzw add
  34183. return
  34184. }
  34185. const children = this.children;
  34186. if(children){
  34187. for ( let i = 0, l = children.length; i < l; i ++ ) {
  34188. children[ i ].traverse( callback );
  34189. }
  34190. }
  34191. };
  34192. Object3D.prototype.traverse = function ( callback ) {
  34193. let result = callback( this );
  34194. if(result && result.stopContinue){//xzw add
  34195. return
  34196. }
  34197. const children = this.children;
  34198. for ( let i = 0, l = children.length; i < l; i ++ ) {
  34199. children[ i ] && children[ i ].traverse( callback );
  34200. }
  34201. };
  34202. Material.prototype.setValues = function ( values ) {
  34203. if ( values === undefined ) return;
  34204. for ( const key in values ) {
  34205. const newValue = values[ key ];
  34206. if ( newValue === undefined ) {
  34207. console.warn( 'THREE.Material: \'' + key + '\' parameter is undefined.' );
  34208. continue;
  34209. }
  34210. // for backward compatability if shading is set in the constructor
  34211. if ( key === 'shading' ) {
  34212. console.warn( 'THREE.' + this.type + ': .shading has been removed. Use the boolean .flatShading instead.' );
  34213. this.flatShading = ( newValue === FlatShading ) ? true : false;
  34214. continue;
  34215. }
  34216. const currentValue = this[ key ];
  34217. /* if ( currentValue === undefined ) { //-----主要删了这段,否则很难和 set 一起使用
  34218. //console.warn( 'THREE.' + this.type + ': \'' + key + '\' is not a property of this material.' );
  34219. continue;
  34220. } */
  34221. if ( currentValue && currentValue.isColor ) {
  34222. currentValue.set( newValue );
  34223. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  34224. currentValue.copy( newValue );
  34225. } else {
  34226. this[ key ] = newValue;
  34227. }
  34228. }
  34229. };
  34230. function ascSort$1( a, b ) {
  34231. return a.distance - b.distance;
  34232. }
  34233. function intersectObject$1( object, raycaster, intersects, recursive, ignoreUnvisible ) {
  34234. if(ignoreUnvisible && !object.visible)return //add
  34235. if ( object.layers.test( raycaster.layers ) ) {
  34236. object.raycast( raycaster, intersects );
  34237. }
  34238. if ( recursive === true ) {
  34239. const children = object.children;
  34240. for ( let i = 0, l = children.length; i < l; i ++ ) {
  34241. intersectObject$1( children[ i ], raycaster, intersects, true, ignoreUnvisible);
  34242. }
  34243. }
  34244. }
  34245. Raycaster.prototype.intersectObject = function ( object, recursive, optionalTarget, ignoreUnvisible ) {
  34246. const intersects = optionalTarget || [];
  34247. intersectObject$1( object, this, intersects, recursive, ignoreUnvisible );
  34248. intersects.sort( ascSort$1 );
  34249. return intersects;
  34250. };
  34251. Raycaster.prototype.intersectObjects = function ( objects, recursive, optionalTarget, ignoreUnvisible ) {//add ignoreUnvisible 跳过不可见
  34252. const intersects = optionalTarget || [];
  34253. if ( Array.isArray( objects ) === false ) {
  34254. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  34255. return intersects;
  34256. }
  34257. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  34258. intersectObject$1( objects[ i ], this, intersects, recursive, ignoreUnvisible );
  34259. }
  34260. intersects.sort( ascSort$1 );
  34261. return intersects;
  34262. };
  34263. Object3D.prototype.realVisible = function(){
  34264. let v = true;
  34265. let parent = this;
  34266. let lastParent;
  34267. while(parent){
  34268. if(parent.visible === false){
  34269. v = false;
  34270. break;
  34271. }
  34272. lastParent = parent;
  34273. parent = parent.parent;
  34274. }
  34275. if(v && !(lastParent instanceof Scene)){//已被删除
  34276. v = false;
  34277. }
  34278. return v
  34279. };
  34280. var MathLight = {};
  34281. MathLight.RADIANS_PER_DEGREE = Math.PI / 180;
  34282. MathLight.DEGREES_PER_RADIAN = 180 / Math.PI;
  34283. MathLight.Vector3 = function(e, t, i) {
  34284. this.x = e || 0,
  34285. this.y = t || 0,
  34286. this.z = i || 0;
  34287. };
  34288. MathLight.Matrix4 = function() {
  34289. this.elements = new Float32Array([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]),
  34290. arguments.length > 0 && console.error("MathLight.Matrix4: the constructor no longer reads arguments. use .set() instead.");
  34291. };
  34292. MathLight.Matrix4.prototype = {
  34293. identity: function() {
  34294. return this.set(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1),
  34295. this
  34296. },
  34297. copy: function(e) {
  34298. return this.elements.set(e.elements),
  34299. this
  34300. },
  34301. applyToVector3: function(e) {
  34302. var t = e.x
  34303. , i = e.y
  34304. , n = e.z
  34305. , r = this.elements;
  34306. return e.x = r[0] * t + r[4] * i + r[8] * n + r[12],
  34307. e.y = r[1] * t + r[5] * i + r[9] * n + r[13],
  34308. e.z = r[2] * t + r[6] * i + r[10] * n + r[14],
  34309. this
  34310. },
  34311. getInverse: function(e, t) {
  34312. var i = this.elements
  34313. , n = e.elements
  34314. , r = n[0]
  34315. , o = n[1]
  34316. , a = n[2]
  34317. , s = n[3]
  34318. , l = n[4]
  34319. , c = n[5]
  34320. , h = n[6]
  34321. , u = n[7]
  34322. , d = n[8]
  34323. , p = n[9]
  34324. , f = n[10]
  34325. , g = n[11]
  34326. , m = n[12]
  34327. , v = n[13]
  34328. , A = n[14]
  34329. , y = n[15]
  34330. , C = p * A * u - v * f * u + v * h * g - c * A * g - p * h * y + c * f * y
  34331. , I = m * f * u - d * A * u - m * h * g + l * A * g + d * h * y - l * f * y
  34332. , E = d * v * u - m * p * u + m * c * g - l * v * g - d * c * y + l * p * y
  34333. , b = m * p * h - d * v * h - m * c * f + l * v * f + d * c * A - l * p * A
  34334. , w = r * C + o * I + a * E + s * b;
  34335. if (0 === w) {
  34336. var _ = "MathLight.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  34337. if (t)
  34338. throw new Error(_);
  34339. return console.warn(_),
  34340. this.identity()
  34341. }
  34342. var T = 1 / w;
  34343. return i[0] = C * T,
  34344. i[1] = (v * f * s - p * A * s - v * a * g + o * A * g + p * a * y - o * f * y) * T,
  34345. i[2] = (c * A * s - v * h * s + v * a * u - o * A * u - c * a * y + o * h * y) * T,
  34346. i[3] = (p * h * s - c * f * s - p * a * u + o * f * u + c * a * g - o * h * g) * T,
  34347. i[4] = I * T,
  34348. i[5] = (d * A * s - m * f * s + m * a * g - r * A * g - d * a * y + r * f * y) * T,
  34349. i[6] = (m * h * s - l * A * s - m * a * u + r * A * u + l * a * y - r * h * y) * T,
  34350. i[7] = (l * f * s - d * h * s + d * a * u - r * f * u - l * a * g + r * h * g) * T,
  34351. i[8] = E * T,
  34352. i[9] = (m * p * s - d * v * s - m * o * g + r * v * g + d * o * y - r * p * y) * T,
  34353. i[10] = (l * v * s - m * c * s + m * o * u - r * v * u - l * o * y + r * c * y) * T,
  34354. i[11] = (d * c * s - l * p * s - d * o * u + r * p * u + l * o * g - r * c * g) * T,
  34355. i[12] = b * T,
  34356. i[13] = (d * v * a - m * p * a + m * o * f - r * v * f - d * o * A + r * p * A) * T,
  34357. i[14] = (m * c * a - l * v * a - m * o * h + r * v * h + l * o * A - r * c * A) * T,
  34358. i[15] = (l * p * a - d * c * a + d * o * h - r * p * h - l * o * f + r * c * f) * T,
  34359. this
  34360. },
  34361. makeRotationFromQuaternion: function(e) {
  34362. var t = this.elements
  34363. , i = e.x
  34364. , n = e.y
  34365. , r = e.z
  34366. , o = e.w
  34367. , a = i + i
  34368. , s = n + n
  34369. , l = r + r
  34370. , c = i * a
  34371. , h = i * s
  34372. , u = i * l
  34373. , d = n * s
  34374. , p = n * l
  34375. , f = r * l
  34376. , g = o * a
  34377. , m = o * s
  34378. , v = o * l;
  34379. return t[0] = 1 - (d + f),
  34380. t[4] = h - v,
  34381. t[8] = u + m,
  34382. t[1] = h + v,
  34383. t[5] = 1 - (c + f),
  34384. t[9] = p - g,
  34385. t[2] = u - m,
  34386. t[6] = p + g,
  34387. t[10] = 1 - (c + d),
  34388. t[3] = 0,
  34389. t[7] = 0,
  34390. t[11] = 0,
  34391. t[12] = 0,
  34392. t[13] = 0,
  34393. t[14] = 0,
  34394. t[15] = 1,
  34395. this
  34396. }
  34397. };
  34398. MathLight.Quaternion = function(e, t, i, n) {
  34399. this._x = e || 0,
  34400. this._y = t || 0,
  34401. this._z = i || 0,
  34402. this._w = void 0 !== n ? n : 1;
  34403. };
  34404. MathLight.Quaternion.prototype = {
  34405. get x() {
  34406. return this._x
  34407. },
  34408. set x(e) {
  34409. this._x = e;
  34410. },
  34411. get y() {
  34412. return this._y
  34413. },
  34414. set y(e) {
  34415. this._y = e;
  34416. },
  34417. get z() {
  34418. return this._z
  34419. },
  34420. set z(e) {
  34421. this._z = e;
  34422. },
  34423. get w() {
  34424. return this._w
  34425. },
  34426. set w(e) {
  34427. this._w = e;
  34428. },
  34429. copy: function(e) {
  34430. this._x = e.x,
  34431. this._y = e.y,
  34432. this._z = e.z,
  34433. this._w = e.w;
  34434. },
  34435. inverse: function() {
  34436. return this.conjugate().normalize()
  34437. },
  34438. conjugate: function() {
  34439. return this._x *= -1,
  34440. this._y *= -1,
  34441. this._z *= -1,
  34442. this
  34443. },
  34444. length: function() {
  34445. return Math.sqrt(this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w)
  34446. },
  34447. normalize: function() {
  34448. var e = this.length();
  34449. return 0 === e ? (this._x = 0,
  34450. this._y = 0,
  34451. this._z = 0,
  34452. this._w = 1) : (e = 1 / e,
  34453. this._x = this._x * e,
  34454. this._y = this._y * e,
  34455. this._z = this._z * e,
  34456. this._w = this._w * e),
  34457. this
  34458. },
  34459. setFromAxisAngle: function(e, t) {
  34460. var i = t / 2
  34461. , n = Math.sin(i);
  34462. return this._x = e.x * n,
  34463. this._y = e.y * n,
  34464. this._z = e.z * n,
  34465. this._w = Math.cos(i),
  34466. this
  34467. },
  34468. setFromUnitVectors: function() {
  34469. var e, t, i = 1e-6;
  34470. return function(n, o) {
  34471. return void 0 === e && (e = new MathLight.Vector3),
  34472. t = MathLight.dot(n, o) + 1,
  34473. t < i ? (t = 0,
  34474. 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),
  34475. this._x = e.x,
  34476. this._y = e.y,
  34477. this._z = e.z,
  34478. this._w = t,
  34479. this.normalize()
  34480. }
  34481. }(),
  34482. multiply: function(e) {
  34483. return this.multiplyQuaternions(this, e)
  34484. },
  34485. premultiply: function(e) {
  34486. return this.multiplyQuaternions(e, this)
  34487. },
  34488. multiplyQuaternions: function(e, t) {
  34489. var i = e._x
  34490. , n = e._y
  34491. , r = e._z
  34492. , o = e._w
  34493. , a = t._x
  34494. , s = t._y
  34495. , l = t._z
  34496. , c = t._w;
  34497. return this._x = i * c + o * a + n * l - r * s,
  34498. this._y = n * c + o * s + r * a - i * l,
  34499. this._z = r * c + o * l + i * s - n * a,
  34500. this._w = o * c - i * a - n * s - r * l,
  34501. this
  34502. }
  34503. };
  34504. MathLight.convertWorkshopVector = function(e) {
  34505. return new MathLight.Vector3(-e.x,e.y,e.z)
  34506. };
  34507. MathLight.convertWorkshopQuaternion = function(e) {
  34508. 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))
  34509. };
  34510. MathLight.convertWorkshopOrthoZoom = function(e) {
  34511. //return e === -1 ? -1 : e / 16 * ($('#player').width() / $('#player').height()) / n.workshopApsect
  34512. return e === -1 ? -1 : e * ($("#player").width() / $("#player").height()) ;
  34513. };
  34514. MathLight.convertWorkshopPanoramaQuaternion = function(e) {
  34515. 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))
  34516. };
  34517. MathLight.normalize = function(e) {
  34518. var t = e.x * e.x + e.y * e.y + e.z * e.z
  34519. , i = Math.sqrt(t);
  34520. e.x /= i,
  34521. e.y /= i,
  34522. e.z /= i;
  34523. };
  34524. MathLight.dot = function(e, t) {
  34525. return e.x * t.x + e.y * t.y + e.z * t.z
  34526. };
  34527. MathLight.cross = function(e, t, i) {
  34528. var n = e.x
  34529. , r = e.y
  34530. , o = e.z;
  34531. i.x = r * t.z - o * t.y,
  34532. i.y = o * t.x - n * t.z,
  34533. i.z = n * t.y - r * t.x;
  34534. };
  34535. MathLight.setVector = function(e, t, i, n) {
  34536. e.x = t,
  34537. e.y = i,
  34538. e.z = n;
  34539. };
  34540. MathLight.copyVector = function(e, t) {
  34541. t.x = e.x,
  34542. t.y = e.y,
  34543. t.z = e.z;
  34544. };
  34545. MathLight.addVector = function(e, t) {
  34546. e.x += t.x,
  34547. e.y += t.y,
  34548. e.z += t.z;
  34549. };
  34550. MathLight.subVector = function(e, t) {
  34551. e.x -= t.x,
  34552. e.y -= t.y,
  34553. e.z -= t.z;
  34554. };
  34555. MathLight.applyQuaternionToVector = function(e, t) {
  34556. var i = t.x
  34557. , n = t.y
  34558. , r = t.z
  34559. , o = e.x
  34560. , a = e.y
  34561. , s = e.z
  34562. , l = e.w
  34563. , c = l * i + a * r - s * n
  34564. , h = l * n + s * i - o * r
  34565. , u = l * r + o * n - a * i
  34566. , d = -o * i - a * n - s * r;
  34567. t.x = c * l + d * -o + h * -s - u * -a,
  34568. t.y = h * l + d * -a + u * -o - c * -s,
  34569. t.z = u * l + d * -s + c * -a - h * -o;
  34570. };
  34571. MathLight.angleBetweenVectors = function(e, t) {
  34572. return Math.acos(MathLight.dot(e, t))
  34573. };
  34574. var cameraLight = {
  34575. clampVFOV: function(currentFov, maxHFov, width, height) {//限制currentFov, 使之造成的横向fov不大于指定值maxHFov
  34576. var r = cameraLight.getHFOVFromVFOV(currentFov, width, height);
  34577. return r > maxHFov ? cameraLight.getVFOVFromHFOV(maxHFov, width, height) : currentFov
  34578. },
  34579. getHFOVForCamera: function(camera, getRad) {
  34580. return cameraLight.getHFOVByScreenPrecent(camera.fov, camera.aspect, getRad)
  34581. },
  34582. //add
  34583. getHFOVByScreenPrecent: function(fov, percent, getRad) { //当fov为占比百分百时,percent代表在屏幕上从中心到边缘的占比
  34584. let rad = 2 * Math.atan(percent * Math.tan(fov * MathLight.RADIANS_PER_DEGREE / 2));
  34585. if(getRad)return rad
  34586. else return rad * MathLight.DEGREES_PER_RADIAN;
  34587. }
  34588. };
  34589. const XHRFactory = {
  34590. config: {
  34591. withCredentials: false,
  34592. customHeaders: [
  34593. { header: null, value: null }
  34594. ]
  34595. },
  34596. createXMLHttpRequest: function () {
  34597. let xhr = new XMLHttpRequest();
  34598. if (this.config.customHeaders &&
  34599. Array.isArray(this.config.customHeaders) &&
  34600. this.config.customHeaders.length > 0) {
  34601. let baseOpen = xhr.open;
  34602. let customHeaders = this.config.customHeaders;
  34603. xhr.open = function () {
  34604. baseOpen.apply(this, [].slice.call(arguments));
  34605. customHeaders.forEach(function (customHeader) {
  34606. if (!!customHeader.header && !!customHeader.value) {
  34607. xhr.setRequestHeader(customHeader.header, customHeader.value);
  34608. }
  34609. });
  34610. };
  34611. }
  34612. return xhr;
  34613. }
  34614. };
  34615. class TextSprite$1 extends Object3D{//old
  34616. constructor(text){
  34617. super();
  34618. let texture = new Texture();
  34619. texture.minFilter = LinearFilter;
  34620. texture.magFilter = LinearFilter;
  34621. let spriteMaterial = new SpriteMaterial({
  34622. map: texture,
  34623. depthTest: false,
  34624. depthWrite: false});
  34625. this.texture = texture;
  34626. this.material = spriteMaterial;
  34627. //this.material = getRawMaterial(texture);
  34628. this.sprite = new Sprite$1(this.material);
  34629. this.add(this.sprite);
  34630. this.borderThickness = 4;
  34631. this.fontface = 'Arial';
  34632. this.fontsize = 28;
  34633. this.borderColor = { r: 0, g: 0, b: 0, a: 1.0 };
  34634. this.backgroundColor = { r: 255, g: 255, b: 255, a: 1.0 };
  34635. this.textColor = {r: 255, g: 255, b: 255, a: 1.0};
  34636. this.text = '';
  34637. this.setText(text);
  34638. }
  34639. setText(text){
  34640. if (this.text !== text){
  34641. this.text = text;
  34642. this.update();
  34643. }
  34644. }
  34645. setTextColor(color){
  34646. this.textColor = color;
  34647. this.update();
  34648. }
  34649. setBorderColor(color){
  34650. this.borderColor = color;
  34651. this.update();
  34652. }
  34653. setBackgroundColor(color){
  34654. this.backgroundColor = color;
  34655. this.update();
  34656. }
  34657. update(){
  34658. let canvas = document.createElement('canvas');
  34659. let context = canvas.getContext('2d');
  34660. context.font = 'Bold ' + this.fontsize + 'px ' + this.fontface;
  34661. // get size data (height depends only on font size)
  34662. let metrics = context.measureText(this.text);
  34663. let textWidth = metrics.width;
  34664. let margin = 5;
  34665. let spriteWidth = 2 * margin + textWidth + 2 * this.borderThickness;
  34666. let spriteHeight = this.fontsize * 1.4 + 2 * this.borderThickness;
  34667. context.canvas.width = spriteWidth;
  34668. context.canvas.height = spriteHeight;
  34669. context.font = 'Bold ' + this.fontsize + 'px ' + this.fontface;
  34670. // background color
  34671. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' +
  34672. this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
  34673. // border color
  34674. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' +
  34675. this.borderColor.b + ',' + this.borderColor.a + ')';
  34676. context.lineWidth = this.borderThickness;
  34677. this.roundRect(context, this.borderThickness / 2, this.borderThickness / 2,
  34678. textWidth + this.borderThickness + 2 * margin, this.fontsize * 1.4 + this.borderThickness, 6);
  34679. // text color
  34680. context.strokeStyle = 'rgba(0, 0, 0, 1.0)';
  34681. context.strokeText(this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
  34682. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' +
  34683. this.textColor.b + ',' + this.textColor.a + ')';
  34684. context.fillText(this.text, this.borderThickness + margin, this.fontsize + this.borderThickness);
  34685. let texture = new Texture(canvas);
  34686. texture.minFilter = LinearFilter;
  34687. texture.magFilter = LinearFilter;
  34688. texture.needsUpdate = true;
  34689. //this.material.needsUpdate = true;
  34690. // { // screen-space sprite
  34691. // let [screenWidth, screenHeight] = [1620, 937];
  34692. // let uniforms = this.sprite.material.uniforms;
  34693. // let aspect = spriteHeight / spriteWidth;
  34694. // let factor = 0.5;
  34695. // let w = spriteWidth / screenWidth;
  34696. // let h = spriteHeight / screenHeight;
  34697. // uniforms.uScale.value = [2 * w, 2 * h];
  34698. // //uniforms.uScale.value = [factor * 1, factor * aspect];
  34699. // this.sprite.material.uniforms.map.value = texture;
  34700. // }
  34701. this.sprite.material.map = texture;
  34702. this.texture = texture;
  34703. this.sprite.scale.set(spriteWidth * 0.01, spriteHeight * 0.01, 1.0);
  34704. }
  34705. roundRect(ctx, x, y, w, h, r){
  34706. ctx.beginPath();
  34707. ctx.moveTo(x + r, y);
  34708. ctx.lineTo(x + w - r, y);
  34709. ctx.quadraticCurveTo(x + w, y, x + w, y + r);
  34710. ctx.lineTo(x + w, y + h - r);
  34711. ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
  34712. ctx.lineTo(x + r, y + h);
  34713. ctx.quadraticCurveTo(x, y + h, x, y + h - r);
  34714. ctx.lineTo(x, y + r);
  34715. ctx.quadraticCurveTo(x, y, x + r, y);
  34716. ctx.closePath();
  34717. ctx.fill();
  34718. ctx.stroke();
  34719. }
  34720. }
  34721. class Volume extends Object3D {
  34722. constructor (args = {}) {
  34723. super();
  34724. if(this.constructor.name === "Volume"){
  34725. console.warn("Can't create object of class Volume directly. Use classes BoxVolume or SphereVolume instead.");
  34726. }
  34727. //console.log(this);
  34728. //console.log(this.constructor);
  34729. //console.log(this.constructor.name);
  34730. this._clip = args.clip || false;
  34731. this._visible = true;
  34732. this.showVolumeLabel = true;
  34733. this._modifiable = args.modifiable || true;
  34734. this.label = new TextSprite$1('0');
  34735. this.label.setBorderColor({r: 0, g: 255, b: 0, a: 0.0});
  34736. this.label.setBackgroundColor({r: 0, g: 255, b: 0, a: 0.0});
  34737. this.label.material.depthTest = false;
  34738. this.label.material.depthWrite = false;
  34739. this.label.material.transparent = true;
  34740. this.label.position.y -= 0.5;
  34741. this.add(this.label);
  34742. this.label.updateMatrixWorld = () => {
  34743. let volumeWorldPos = new Vector3();
  34744. volumeWorldPos.setFromMatrixPosition(this.matrixWorld);
  34745. this.label.position.copy(volumeWorldPos);
  34746. this.label.updateMatrix();
  34747. this.label.matrixWorld.copy(this.label.matrix);
  34748. this.label.matrixWorldNeedsUpdate = false;
  34749. for (let i = 0, l = this.label.children.length; i < l; i++) {
  34750. this.label.children[ i ].updateMatrixWorld(true);
  34751. }
  34752. };
  34753. { // event listeners
  34754. this.addEventListener('select', e => {});
  34755. this.addEventListener('deselect', e => {});
  34756. }
  34757. }
  34758. get visible(){
  34759. return this._visible;
  34760. }
  34761. set visible(value){
  34762. if(this._visible !== value){
  34763. this._visible = value;
  34764. this.dispatchEvent({type: "visibility_changed", object: this});
  34765. }
  34766. }
  34767. getVolume () {
  34768. console.warn("override this in subclass");
  34769. }
  34770. update () {
  34771. };
  34772. raycast (raycaster, intersects) {
  34773. }
  34774. get clip () {
  34775. return this._clip;
  34776. }
  34777. set clip (value) {
  34778. if(this._clip !== value){
  34779. this._clip = value;
  34780. this.update();
  34781. this.dispatchEvent({
  34782. type: "clip_changed",
  34783. object: this
  34784. });
  34785. }
  34786. }
  34787. get modifieable () {
  34788. return this._modifiable;
  34789. }
  34790. set modifieable (value) {
  34791. this._modifiable = value;
  34792. this.update();
  34793. }
  34794. };
  34795. class BoxVolume extends Volume{
  34796. constructor(args = {}){
  34797. super(args);
  34798. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  34799. this.name = 'box_' + this.constructor.counter;
  34800. let boxGeometry = new BoxGeometry(1, 1, 1);
  34801. boxGeometry.computeBoundingBox();
  34802. let boxFrameGeometry = new Geometry();
  34803. {
  34804. let Vector3$1 = Vector3;
  34805. boxFrameGeometry.vertices.push(
  34806. // bottom
  34807. new Vector3$1(-0.5, -0.5, 0.5),
  34808. new Vector3$1(0.5, -0.5, 0.5),
  34809. new Vector3$1(0.5, -0.5, 0.5),
  34810. new Vector3$1(0.5, -0.5, -0.5),
  34811. new Vector3$1(0.5, -0.5, -0.5),
  34812. new Vector3$1(-0.5, -0.5, -0.5),
  34813. new Vector3$1(-0.5, -0.5, -0.5),
  34814. new Vector3$1(-0.5, -0.5, 0.5),
  34815. // top
  34816. new Vector3$1(-0.5, 0.5, 0.5),
  34817. new Vector3$1(0.5, 0.5, 0.5),
  34818. new Vector3$1(0.5, 0.5, 0.5),
  34819. new Vector3$1(0.5, 0.5, -0.5),
  34820. new Vector3$1(0.5, 0.5, -0.5),
  34821. new Vector3$1(-0.5, 0.5, -0.5),
  34822. new Vector3$1(-0.5, 0.5, -0.5),
  34823. new Vector3$1(-0.5, 0.5, 0.5),
  34824. // sides
  34825. new Vector3$1(-0.5, -0.5, 0.5),
  34826. new Vector3$1(-0.5, 0.5, 0.5),
  34827. new Vector3$1(0.5, -0.5, 0.5),
  34828. new Vector3$1(0.5, 0.5, 0.5),
  34829. new Vector3$1(0.5, -0.5, -0.5),
  34830. new Vector3$1(0.5, 0.5, -0.5),
  34831. new Vector3$1(-0.5, -0.5, -0.5),
  34832. new Vector3$1(-0.5, 0.5, -0.5),
  34833. );
  34834. }
  34835. this.material = new MeshBasicMaterial({
  34836. color: 0x00ff00,
  34837. transparent: true,
  34838. opacity: 0.3,
  34839. depthTest: true,
  34840. depthWrite: false});
  34841. this.box = new Mesh(boxGeometry, this.material);
  34842. this.box.geometry.computeBoundingBox();
  34843. this.boundingBox = this.box.geometry.boundingBox;
  34844. this.add(this.box);
  34845. this.frame = new LineSegments(boxFrameGeometry, new LineBasicMaterial({color: 0x000000}));
  34846. // this.frame.mode = THREE.Lines;
  34847. this.add(this.frame);
  34848. this.update();
  34849. }
  34850. update(){
  34851. this.boundingBox = this.box.geometry.boundingBox;
  34852. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  34853. if (this._clip) {
  34854. this.box.visible = false;
  34855. this.label.visible = false;
  34856. } else {
  34857. this.box.visible = true;
  34858. this.label.visible = this.showVolumeLabel;
  34859. }
  34860. }
  34861. raycast (raycaster, intersects) {
  34862. let is = [];
  34863. this.box.raycast(raycaster, is);
  34864. if (is.length > 0) {
  34865. let I = is[0];
  34866. intersects.push({
  34867. distance: I.distance,
  34868. object: this,
  34869. point: I.point.clone()
  34870. });
  34871. }
  34872. }
  34873. getVolume(){
  34874. return Math.abs(this.scale.x * this.scale.y * this.scale.z);
  34875. }
  34876. };
  34877. class SphereVolume$1 extends Volume{
  34878. constructor(args = {}){
  34879. super(args);
  34880. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  34881. this.name = 'sphere_' + this.constructor.counter;
  34882. let sphereGeometry = new SphereGeometry(1, 32, 32);
  34883. sphereGeometry.computeBoundingBox();
  34884. this.material = new MeshBasicMaterial({
  34885. color: 0x00ff00,
  34886. transparent: true,
  34887. opacity: 0.3,
  34888. depthTest: true,
  34889. depthWrite: false});
  34890. this.sphere = new Mesh(sphereGeometry, this.material);
  34891. this.sphere.visible = false;
  34892. this.sphere.geometry.computeBoundingBox();
  34893. this.boundingBox = this.sphere.geometry.boundingBox;
  34894. this.add(this.sphere);
  34895. this.label.visible = false;
  34896. let frameGeometry = new Geometry();
  34897. {
  34898. let steps = 64;
  34899. let uSegments = 8;
  34900. let vSegments = 5;
  34901. let r = 1;
  34902. for(let uSegment = 0; uSegment < uSegments; uSegment++){
  34903. let alpha = (uSegment / uSegments) * Math.PI * 2;
  34904. let dirx = Math.cos(alpha);
  34905. let diry = Math.sin(alpha);
  34906. for(let i = 0; i <= steps; i++){
  34907. let v = (i / steps) * Math.PI * 2;
  34908. let vNext = v + 2 * Math.PI / steps;
  34909. let height = Math.sin(v);
  34910. let xyAmount = Math.cos(v);
  34911. let heightNext = Math.sin(vNext);
  34912. let xyAmountNext = Math.cos(vNext);
  34913. let vertex = new Vector3(dirx * xyAmount, diry * xyAmount, height);
  34914. frameGeometry.vertices.push(vertex);
  34915. let vertexNext = new Vector3(dirx * xyAmountNext, diry * xyAmountNext, heightNext);
  34916. frameGeometry.vertices.push(vertexNext);
  34917. }
  34918. }
  34919. // creates rings at poles, just because it's easier to implement
  34920. for(let vSegment = 0; vSegment <= vSegments + 1; vSegment++){
  34921. //let height = (vSegment / (vSegments + 1)) * 2 - 1; // -1 to 1
  34922. let uh = (vSegment / (vSegments + 1)); // -1 to 1
  34923. uh = (1 - uh) * (-Math.PI / 2) + uh *(Math.PI / 2);
  34924. let height = Math.sin(uh);
  34925. console.log(uh, height);
  34926. for(let i = 0; i <= steps; i++){
  34927. let u = (i / steps) * Math.PI * 2;
  34928. let uNext = u + 2 * Math.PI / steps;
  34929. let dirx = Math.cos(u);
  34930. let diry = Math.sin(u);
  34931. let dirxNext = Math.cos(uNext);
  34932. let diryNext = Math.sin(uNext);
  34933. let xyAmount = Math.sqrt(1 - height * height);
  34934. let vertex = new Vector3(dirx * xyAmount, diry * xyAmount, height);
  34935. frameGeometry.vertices.push(vertex);
  34936. let vertexNext = new Vector3(dirxNext * xyAmount, diryNext * xyAmount, height);
  34937. frameGeometry.vertices.push(vertexNext);
  34938. }
  34939. }
  34940. }
  34941. this.frame = new LineSegments(frameGeometry, new LineBasicMaterial({color: 0x000000}));
  34942. this.add(this.frame);
  34943. let frameMaterial = new MeshBasicMaterial({wireframe: true, color: 0x000000});
  34944. this.frame = new Mesh(sphereGeometry, frameMaterial);
  34945. //this.add(this.frame);
  34946. //this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
  34947. // this.frame.mode = THREE.Lines;
  34948. //this.add(this.frame);
  34949. this.update();
  34950. }
  34951. update(){
  34952. this.boundingBox = this.sphere.geometry.boundingBox;
  34953. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  34954. //if (this._clip) {
  34955. // this.sphere.visible = false;
  34956. // this.label.visible = false;
  34957. //} else {
  34958. // this.sphere.visible = true;
  34959. // this.label.visible = this.showVolumeLabel;
  34960. //}
  34961. }
  34962. raycast (raycaster, intersects) {
  34963. let is = [];
  34964. this.sphere.raycast(raycaster, is);
  34965. if (is.length > 0) {
  34966. let I = is[0];
  34967. intersects.push({
  34968. distance: I.distance,
  34969. object: this,
  34970. point: I.point.clone()
  34971. });
  34972. }
  34973. }
  34974. // see https://en.wikipedia.org/wiki/Ellipsoid#Volume
  34975. getVolume(){
  34976. return (4 / 3) * Math.PI * this.scale.x * this.scale.y * this.scale.z;
  34977. }
  34978. };
  34979. class Profile extends Object3D{
  34980. constructor () {
  34981. super();
  34982. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  34983. this.name = 'Profile_' + this.constructor.counter;
  34984. this.points = [];
  34985. this.spheres = [];
  34986. this.edges = [];
  34987. this.boxes = [];
  34988. this.width = 1;
  34989. this.height = 20;
  34990. this._modifiable = true;
  34991. this.sphereGeometry = new SphereGeometry(0.4, 10, 10);
  34992. this.color = new Color(0xff0000);
  34993. this.lineColor = new Color(0xff0000);
  34994. }
  34995. createSphereMaterial () {
  34996. let sphereMaterial = new MeshLambertMaterial({
  34997. //shading: THREE.SmoothShading,
  34998. color: 0xff0000,
  34999. depthTest: false,
  35000. depthWrite: false}
  35001. );
  35002. return sphereMaterial;
  35003. };
  35004. getSegments () {
  35005. let segments = [];
  35006. for (let i = 0; i < this.points.length - 1; i++) {
  35007. let start = this.points[i].clone();
  35008. let end = this.points[i + 1].clone();
  35009. segments.push({start: start, end: end});
  35010. }
  35011. return segments;
  35012. }
  35013. getSegmentMatrices () {
  35014. let segments = this.getSegments();
  35015. let matrices = [];
  35016. for (let segment of segments) {
  35017. let {start, end} = segment;
  35018. let box = new Object3D();
  35019. let length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
  35020. box.scale.set(length, 10000, this.width);
  35021. box.up.set(0, 0, 1);
  35022. let center = new Vector3().addVectors(start, end).multiplyScalar(0.5);
  35023. let diff = new Vector3().subVectors(end, start);
  35024. let target = new Vector3(diff.y, -diff.x, 0);
  35025. box.position.set(0, 0, 0);
  35026. box.lookAt(target);
  35027. box.position.copy(center);
  35028. box.updateMatrixWorld();
  35029. matrices.push(box.matrixWorld);
  35030. }
  35031. return matrices;
  35032. }
  35033. addMarker (point) {
  35034. this.points.push(point);
  35035. let sphere = new Mesh(this.sphereGeometry, this.createSphereMaterial());
  35036. this.add(sphere);
  35037. this.spheres.push(sphere);
  35038. // edges & boxes
  35039. if (this.points.length > 1) {
  35040. let lineGeometry = new Geometry();
  35041. lineGeometry.vertices.push(new Vector3(), new Vector3());
  35042. lineGeometry.colors.push(this.lineColor, this.lineColor, this.lineColor);
  35043. let lineMaterial = new LineBasicMaterial({
  35044. vertexColors: VertexColors,
  35045. linewidth: 2,
  35046. transparent: true,
  35047. opacity: 0.4
  35048. });
  35049. lineMaterial.depthTest = false;
  35050. let edge = new Line(lineGeometry, lineMaterial);
  35051. edge.visible = false;
  35052. this.add(edge);
  35053. this.edges.push(edge);
  35054. let boxGeometry = new BoxGeometry(1, 1, 1);
  35055. let boxMaterial = new MeshBasicMaterial({color: 0xff0000, transparent: true, opacity: 0.2});
  35056. let box = new Mesh(boxGeometry, boxMaterial);
  35057. box.visible = false;
  35058. this.add(box);
  35059. this.boxes.push(box);
  35060. }
  35061. { // event listeners
  35062. let drag = (e) => {
  35063. let I = Utils.getMousePointCloudIntersection(
  35064. e.drag.end,
  35065. e.viewer.scene.getActiveCamera(),
  35066. e.viewer,
  35067. e.viewer.scene.pointclouds);
  35068. if (I) {
  35069. let i = this.spheres.indexOf(e.drag.object);
  35070. if (i !== -1) {
  35071. this.setPosition(i, I.location);
  35072. //this.dispatchEvent({
  35073. // 'type': 'marker_moved',
  35074. // 'profile': this,
  35075. // 'index': i
  35076. //});
  35077. }
  35078. }
  35079. };
  35080. let drop = e => {
  35081. let i = this.spheres.indexOf(e.drag.object);
  35082. if (i !== -1) {
  35083. this.dispatchEvent({
  35084. 'type': 'marker_dropped',
  35085. 'profile': this,
  35086. 'index': i
  35087. });
  35088. }
  35089. };
  35090. let mouseover = (e) => e.object.material.emissive.setHex(0x888888);
  35091. let mouseleave = (e) => e.object.material.emissive.setHex(0x000000);
  35092. sphere.addEventListener('drag', drag);
  35093. sphere.addEventListener('drop', drop);
  35094. sphere.addEventListener('mouseover', mouseover);
  35095. sphere.addEventListener('mouseleave', mouseleave);
  35096. }
  35097. let event = {
  35098. type: 'marker_added',
  35099. profile: this,
  35100. sphere: sphere
  35101. };
  35102. this.dispatchEvent(event);
  35103. this.setPosition(this.points.length - 1, point);
  35104. }
  35105. removeMarker (index) {
  35106. this.points.splice(index, 1);
  35107. this.remove(this.spheres[index]);
  35108. let edgeIndex = (index === 0) ? 0 : (index - 1);
  35109. this.remove(this.edges[edgeIndex]);
  35110. this.edges.splice(edgeIndex, 1);
  35111. this.remove(this.boxes[edgeIndex]);
  35112. this.boxes.splice(edgeIndex, 1);
  35113. this.spheres.splice(index, 1);
  35114. this.update();
  35115. this.dispatchEvent({
  35116. 'type': 'marker_removed',
  35117. 'profile': this
  35118. });
  35119. }
  35120. setPosition (index, position) {
  35121. let point = this.points[index];
  35122. point.copy(position);
  35123. let event = {
  35124. type: 'marker_moved',
  35125. profile: this,
  35126. index: index,
  35127. position: point.clone()
  35128. };
  35129. this.dispatchEvent(event);
  35130. this.update();
  35131. }
  35132. setWidth (width) {
  35133. this.width = width;
  35134. let event = {
  35135. type: 'width_changed',
  35136. profile: this,
  35137. width: width
  35138. };
  35139. this.dispatchEvent(event);
  35140. this.update();
  35141. }
  35142. getWidth () {
  35143. return this.width;
  35144. }
  35145. update () {
  35146. if (this.points.length === 0) {
  35147. return;
  35148. } else if (this.points.length === 1) {
  35149. let point = this.points[0];
  35150. this.spheres[0].position.copy(point);
  35151. return;
  35152. }
  35153. let min = this.points[0].clone();
  35154. let max = this.points[0].clone();
  35155. let centroid = new Vector3();
  35156. let lastIndex = this.points.length - 1;
  35157. for (let i = 0; i <= lastIndex; i++) {
  35158. let point = this.points[i];
  35159. let sphere = this.spheres[i];
  35160. let leftIndex = (i === 0) ? lastIndex : i - 1;
  35161. // let rightIndex = (i === lastIndex) ? 0 : i + 1;
  35162. let leftVertex = this.points[leftIndex];
  35163. // let rightVertex = this.points[rightIndex];
  35164. let leftEdge = this.edges[leftIndex];
  35165. let rightEdge = this.edges[i];
  35166. let leftBox = this.boxes[leftIndex];
  35167. // rightBox = this.boxes[i];
  35168. // let leftEdgeLength = point.distanceTo(leftVertex);
  35169. // let rightEdgeLength = point.distanceTo(rightVertex);
  35170. // let leftEdgeCenter = new THREE.Vector3().addVectors(leftVertex, point).multiplyScalar(0.5);
  35171. // let rightEdgeCenter = new THREE.Vector3().addVectors(point, rightVertex).multiplyScalar(0.5);
  35172. sphere.position.copy(point);
  35173. if (this._modifiable) {
  35174. sphere.visible = true;
  35175. } else {
  35176. sphere.visible = false;
  35177. }
  35178. if (leftEdge) {
  35179. leftEdge.geometry.vertices[1].copy(point);
  35180. leftEdge.geometry.verticesNeedUpdate = true;
  35181. leftEdge.geometry.computeBoundingSphere();
  35182. }
  35183. if (rightEdge) {
  35184. rightEdge.geometry.vertices[0].copy(point);
  35185. rightEdge.geometry.verticesNeedUpdate = true;
  35186. rightEdge.geometry.computeBoundingSphere();
  35187. }
  35188. if (leftBox) {
  35189. let start = leftVertex;
  35190. let end = point;
  35191. let length = start.clone().setZ(0).distanceTo(end.clone().setZ(0));
  35192. leftBox.scale.set(length, 1000000, this.width);
  35193. leftBox.up.set(0, 0, 1);
  35194. let center = new Vector3().addVectors(start, end).multiplyScalar(0.5);
  35195. let diff = new Vector3().subVectors(end, start);
  35196. let target = new Vector3(diff.y, -diff.x, 0);
  35197. leftBox.position.set(0, 0, 0);
  35198. leftBox.lookAt(target);
  35199. leftBox.position.copy(center);
  35200. }
  35201. centroid.add(point);
  35202. min.min(point);
  35203. max.max(point);
  35204. }
  35205. centroid.multiplyScalar(1 / this.points.length);
  35206. for (let i = 0; i < this.boxes.length; i++) {
  35207. let box = this.boxes[i];
  35208. box.position.z = min.z + (max.z - min.z) / 2;
  35209. }
  35210. }
  35211. raycast (raycaster, intersects) {
  35212. for (let i = 0; i < this.points.length; i++) {
  35213. let sphere = this.spheres[i];
  35214. sphere.raycast(raycaster, intersects);
  35215. }
  35216. // recalculate distances because they are not necessarely correct
  35217. // for scaled objects.
  35218. // see https://github.com/mrdoob/three.js/issues/5827
  35219. // TODO: remove this once the bug has been fixed
  35220. for (let i = 0; i < intersects.length; i++) {
  35221. let I = intersects[i];
  35222. I.distance = raycaster.ray.origin.distanceTo(I.point);
  35223. }
  35224. intersects.sort(function (a, b) { return a.distance - b.distance; });
  35225. };
  35226. get modifiable () {
  35227. return this._modifiable;
  35228. }
  35229. set modifiable (value) {
  35230. this._modifiable = value;
  35231. this.update();
  35232. }
  35233. }
  35234. const _box$4 = new Box3();
  35235. const _vector$d = new Vector3();
  35236. class LineSegmentsGeometry extends InstancedBufferGeometry {
  35237. constructor() {
  35238. super();
  35239. this.isLineSegmentsGeometry = true;
  35240. this.type = 'LineSegmentsGeometry';
  35241. const 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 ];
  35242. const uvs = [ - 1, 2, 1, 2, - 1, 1, 1, 1, - 1, - 1, 1, - 1, - 1, - 2, 1, - 2 ];
  35243. const index = [ 0, 2, 1, 2, 3, 1, 2, 4, 3, 4, 5, 3, 4, 6, 5, 6, 7, 5 ];
  35244. this.setIndex( index );
  35245. this.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  35246. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  35247. }
  35248. applyMatrix4( matrix ) {
  35249. const start = this.attributes.instanceStart;
  35250. const end = this.attributes.instanceEnd;
  35251. if ( start !== undefined ) {
  35252. start.applyMatrix4( matrix );
  35253. end.applyMatrix4( matrix );
  35254. start.needsUpdate = true;
  35255. }
  35256. if ( this.boundingBox !== null ) {
  35257. this.computeBoundingBox();
  35258. }
  35259. if ( this.boundingSphere !== null ) {
  35260. this.computeBoundingSphere();
  35261. }
  35262. return this;
  35263. }
  35264. setPositions( array ) {
  35265. let lineSegments;
  35266. if ( array instanceof Float32Array ) {
  35267. lineSegments = array;
  35268. } else if ( Array.isArray( array ) ) {
  35269. lineSegments = new Float32Array( array );
  35270. }
  35271. const instanceBuffer = new InstancedInterleavedBuffer( lineSegments, 6, 1 ); // xyz, xyz
  35272. this.setAttribute( 'instanceStart', new InterleavedBufferAttribute( instanceBuffer, 3, 0 ) ); // xyz
  35273. this.setAttribute( 'instanceEnd', new InterleavedBufferAttribute( instanceBuffer, 3, 3 ) ); // xyz
  35274. //
  35275. this.computeBoundingBox();
  35276. this.computeBoundingSphere();
  35277. return this;
  35278. }
  35279. setColors( array ) {
  35280. let colors;
  35281. if ( array instanceof Float32Array ) {
  35282. colors = array;
  35283. } else if ( Array.isArray( array ) ) {
  35284. colors = new Float32Array( array );
  35285. }
  35286. const instanceColorBuffer = new InstancedInterleavedBuffer( colors, 6, 1 ); // rgb, rgb
  35287. this.setAttribute( 'instanceColorStart', new InterleavedBufferAttribute( instanceColorBuffer, 3, 0 ) ); // rgb
  35288. this.setAttribute( 'instanceColorEnd', new InterleavedBufferAttribute( instanceColorBuffer, 3, 3 ) ); // rgb
  35289. return this;
  35290. }
  35291. fromWireframeGeometry( geometry ) {
  35292. this.setPositions( geometry.attributes.position.array );
  35293. return this;
  35294. }
  35295. fromEdgesGeometry( geometry ) {
  35296. this.setPositions( geometry.attributes.position.array );
  35297. return this;
  35298. }
  35299. fromMesh( mesh ) {
  35300. this.fromWireframeGeometry( new WireframeGeometry( mesh.geometry ) );
  35301. // set colors, maybe
  35302. return this;
  35303. }
  35304. fromLineSegments( lineSegments ) {
  35305. const geometry = lineSegments.geometry;
  35306. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  35307. // set colors, maybe
  35308. return this;
  35309. }
  35310. computeBoundingBox() {
  35311. if ( this.boundingBox === null ) {
  35312. this.boundingBox = new Box3();
  35313. }
  35314. const start = this.attributes.instanceStart;
  35315. const end = this.attributes.instanceEnd;
  35316. if ( start !== undefined && end !== undefined ) {
  35317. this.boundingBox.setFromBufferAttribute( start );
  35318. _box$4.setFromBufferAttribute( end );
  35319. this.boundingBox.union( _box$4 );
  35320. }
  35321. }
  35322. computeBoundingSphere() {
  35323. if ( this.boundingSphere === null ) {
  35324. this.boundingSphere = new Sphere();
  35325. }
  35326. if ( this.boundingBox === null ) {
  35327. this.computeBoundingBox();
  35328. }
  35329. const start = this.attributes.instanceStart;
  35330. const end = this.attributes.instanceEnd;
  35331. if ( start !== undefined && end !== undefined ) {
  35332. const center = this.boundingSphere.center;
  35333. this.boundingBox.getCenter( center );
  35334. let maxRadiusSq = 0;
  35335. for ( let i = 0, il = start.count; i < il; i ++ ) {
  35336. _vector$d.fromBufferAttribute( start, i );
  35337. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$d ) );
  35338. _vector$d.fromBufferAttribute( end, i );
  35339. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$d ) );
  35340. }
  35341. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  35342. if ( isNaN( this.boundingSphere.radius ) ) {
  35343. console.error( 'THREE.LineSegmentsGeometry.computeBoundingSphere(): Computed radius is NaN. The instanced position data is likely to have NaN values.', this );
  35344. }
  35345. }
  35346. }
  35347. toJSON() {
  35348. // todo
  35349. }
  35350. applyMatrix( matrix ) {
  35351. console.warn( 'THREE.LineSegmentsGeometry: applyMatrix() has been renamed to applyMatrix4().' );
  35352. return this.applyMatrix4( matrix );
  35353. }
  35354. }
  35355. /**
  35356. * parameters = {
  35357. * color: <hex>,
  35358. * lineWidth: <float>,
  35359. * dashed: <boolean>,
  35360. * dashScale: <float>,
  35361. * dashSize: <float>,
  35362. * dashOffset: <float>,
  35363. * gapSize: <float>,
  35364. * resolution: <Vector2>, // to be set by renderer
  35365. * }
  35366. */
  35367. UniformsLib.line = {
  35368. /*
  35369. worldUnits: { value: 1 },
  35370. lineWidth: { value: 1 },
  35371. resolution: { value: new Vector2( 1, 1 ) },
  35372. dashOffset: { value: 0 },
  35373. dashScale: { value: 1 },
  35374. dashSize: { value: 1 },
  35375. gapSize: { value: 1 } // todo FIX - maybe change to totalSize
  35376. */
  35377. worldUnits: { value: 1 },
  35378. lineWidth: { value: 1 },
  35379. resolution: { value: new Vector2( 1, 1 ) },
  35380. viewportOffset: { value: new Vector2(0, 0 ) }, //left, top
  35381. devicePixelRatio:{ value:window.devicePixelRatio},
  35382. dashScale: { value: 1 },
  35383. dashSize: { value: 1 },
  35384. dashOffset: { value: 0 },
  35385. gapSize: { value: 1 },
  35386. opacity: { value: 1 },
  35387. backColor: {type:'v3', value: new Color("#ddd")},
  35388. clipDistance : { type: 'f', value: 4}, //消失距离
  35389. occlusionDistance : { type: 'f', value: 1 }, //变为backColor距离
  35390. maxClipFactor : { type: 'f', value: 1 }, //0-1
  35391. maxOcclusionFactor : { type: 'f', value: 1 }, //0-1
  35392. depthTexture:{ value: null },
  35393. nearPlane:{value: 0.1},
  35394. farPlane:{value: 100000},
  35395. //uUseOrthographicCamera:{ type: "b", value: false },
  35396. };
  35397. ShaderLib[ 'line' ] = {
  35398. uniforms: UniformsUtils.merge( [
  35399. UniformsLib.common,
  35400. UniformsLib.fog,
  35401. UniformsLib.line
  35402. ] ),
  35403. vertexShader:
  35404. /* glsl */`
  35405. #include <common>
  35406. #include <color_pars_vertex>
  35407. #include <fog_pars_vertex>
  35408. #include <logdepthbuf_pars_vertex>
  35409. #include <clipping_planes_pars_vertex>
  35410. uniform float lineWidth;
  35411. uniform vec2 resolution;
  35412. uniform float devicePixelRatio; //add
  35413. attribute vec3 instanceStart;
  35414. attribute vec3 instanceEnd;
  35415. attribute vec3 instanceColorStart;
  35416. attribute vec3 instanceColorEnd;
  35417. #ifdef WORLD_UNITS
  35418. varying vec4 worldPos;
  35419. varying vec3 worldStart;
  35420. varying vec3 worldEnd;
  35421. #ifdef USE_DASH
  35422. varying vec2 vUv;
  35423. #endif
  35424. #else
  35425. varying vec2 vUv;
  35426. #endif
  35427. #ifdef USE_DASH
  35428. uniform float dashScale;
  35429. attribute float instanceDistanceStart;
  35430. attribute float instanceDistanceEnd;
  35431. varying float vLineDistance;
  35432. #endif
  35433. void trimSegment( const in vec4 start, inout vec4 end ) {
  35434. // trim end segment so it terminates between the camera plane and the near plane
  35435. // conservative estimate of the near plane
  35436. float a = projectionMatrix[ 2 ][ 2 ]; // 3nd entry in 3th column
  35437. float b = projectionMatrix[ 3 ][ 2 ]; // 3nd entry in 4th column
  35438. float nearEstimate = - 0.5 * b / a;
  35439. float alpha = ( nearEstimate - start.z ) / ( end.z - start.z );
  35440. end.xyz = mix( start.xyz, end.xyz, alpha );
  35441. }
  35442. void main() {
  35443. #ifdef USE_COLOR
  35444. vColor.xyz = ( position.y < 0.5 ) ? instanceColorStart : instanceColorEnd;
  35445. #endif
  35446. #ifdef USE_DASH
  35447. vLineDistance = ( position.y < 0.5 ) ? dashScale * instanceDistanceStart : dashScale * instanceDistanceEnd;
  35448. vUv = uv;
  35449. #endif
  35450. float aspect = resolution.x / resolution.y;
  35451. // camera space
  35452. vec4 start = modelViewMatrix * vec4( instanceStart, 1.0 );
  35453. vec4 end = modelViewMatrix * vec4( instanceEnd, 1.0 );
  35454. #ifdef WORLD_UNITS
  35455. worldStart = start.xyz;
  35456. worldEnd = end.xyz;
  35457. #else
  35458. vUv = uv;
  35459. #endif
  35460. // special case for perspective projection, and segments that terminate either in, or behind, the camera plane
  35461. // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
  35462. // but we need to perform ndc-space calculations in the shader, so we must address this issue directly
  35463. // perhaps there is a more elegant solution -- WestLangley
  35464. bool perspective = ( projectionMatrix[ 2 ][ 3 ] == - 1.0 ); // 4th entry in the 3rd column
  35465. if ( perspective ) {
  35466. if ( start.z < 0.0 && end.z >= 0.0 ) {
  35467. trimSegment( start, end );
  35468. } else if ( end.z < 0.0 && start.z >= 0.0 ) {
  35469. trimSegment( end, start );
  35470. }
  35471. }
  35472. // clip space
  35473. vec4 clipStart = projectionMatrix * start;
  35474. vec4 clipEnd = projectionMatrix * end;
  35475. // ndc space
  35476. vec3 ndcStart = clipStart.xyz / clipStart.w;
  35477. vec3 ndcEnd = clipEnd.xyz / clipEnd.w;
  35478. // direction
  35479. vec2 dir = ndcEnd.xy - ndcStart.xy;
  35480. // account for clip-space aspect ratio
  35481. dir.x *= aspect;
  35482. dir = normalize( dir );
  35483. #ifdef WORLD_UNITS
  35484. // get the offset direction as perpendicular to the view vector
  35485. vec3 worldDir = normalize( end.xyz - start.xyz );
  35486. vec3 offset;
  35487. if ( position.y < 0.5 ) {
  35488. offset = normalize( cross( start.xyz, worldDir ) );
  35489. } else {
  35490. offset = normalize( cross( end.xyz, worldDir ) );
  35491. }
  35492. // sign flip
  35493. if ( position.x < 0.0 ) offset *= - 1.0;
  35494. float forwardOffset = dot( worldDir, vec3( 0.0, 0.0, 1.0 ) );
  35495. // don't extend the line if we're rendering dashes because we
  35496. // won't be rendering the endcaps
  35497. #ifndef USE_DASH
  35498. // extend the line bounds to encompass endcaps
  35499. start.xyz += - worldDir * lineWidth * 0.5;
  35500. end.xyz += worldDir * lineWidth * 0.5;
  35501. // shift the position of the quad so it hugs the forward edge of the line
  35502. offset.xy -= dir * forwardOffset;
  35503. offset.z += 0.5;
  35504. #endif
  35505. // endcaps
  35506. if ( position.y > 1.0 || position.y < 0.0 ) {
  35507. offset.xy += dir * 2.0 * forwardOffset;
  35508. }
  35509. // adjust for lineWidth
  35510. offset *= lineWidth * 0.5;
  35511. // set the world position
  35512. worldPos = ( position.y < 0.5 ) ? start : end;
  35513. worldPos.xyz += offset;
  35514. // project the worldpos
  35515. vec4 clip = projectionMatrix * worldPos;
  35516. // shift the depth of the projected points so the line
  35517. // segments overlap neatly
  35518. vec3 clipPose = ( position.y < 0.5 ) ? ndcStart : ndcEnd;
  35519. clip.z = clipPose.z * clip.w;
  35520. #else
  35521. vec2 offset = vec2( dir.y, - dir.x );
  35522. // undo aspect ratio adjustment
  35523. dir.x /= aspect;
  35524. offset.x /= aspect;
  35525. // sign flip
  35526. if ( position.x < 0.0 ) offset *= - 1.0;
  35527. // endcaps
  35528. if ( position.y < 0.0 ) {
  35529. offset += - dir;
  35530. } else if ( position.y > 1.0 ) {
  35531. offset += dir;
  35532. }
  35533. // adjust for lineWidth
  35534. offset *= lineWidth;
  35535. // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
  35536. offset /= resolution.y; //* devicePixelRatio;
  35537. // select end
  35538. vec4 clip = ( position.y < 0.5 ) ? clipStart : clipEnd;
  35539. // back to clip space
  35540. offset *= clip.w;
  35541. clip.xy += offset;
  35542. #endif
  35543. gl_Position = clip;
  35544. vec4 mvPosition = ( position.y < 0.5 ) ? start : end; // this is an approximation
  35545. #include <logdepthbuf_vertex>
  35546. #include <clipping_planes_vertex>
  35547. #include <fog_vertex>
  35548. }
  35549. `,
  35550. fragmentShader:
  35551. /* glsl */`
  35552. uniform vec3 diffuse;
  35553. uniform float opacity;
  35554. uniform float lineWidth;
  35555. uniform bool uUseOrthographicCamera;
  35556. #ifdef USE_DASH
  35557. uniform float dashOffset;
  35558. uniform float dashSize;
  35559. uniform float gapSize;
  35560. #endif
  35561. //加
  35562. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  35563. uniform sampler2D depthTexture;
  35564. uniform float nearPlane;
  35565. uniform float farPlane;
  35566. uniform vec2 resolution;
  35567. uniform vec2 viewportOffset;
  35568. uniform vec3 backColor;
  35569. uniform float occlusionDistance;
  35570. uniform float clipDistance;
  35571. uniform float maxClipFactor;
  35572. uniform float maxOcclusionFactor;
  35573. #endif
  35574. varying float vLineDistance;
  35575. #ifdef WORLD_UNITS
  35576. varying vec4 worldPos;
  35577. varying vec3 worldStart;
  35578. varying vec3 worldEnd;
  35579. #ifdef USE_DASH
  35580. varying vec2 vUv;
  35581. #endif
  35582. #else
  35583. varying vec2 vUv;
  35584. #endif
  35585. #include <common>
  35586. #include <color_pars_fragment>
  35587. #include <fog_pars_fragment>
  35588. #include <logdepthbuf_pars_fragment>
  35589. #include <clipping_planes_pars_fragment>
  35590. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  35591. float convertToLinear(float zValue)
  35592. {
  35593. //if(uUseOrthographicCamera){
  35594. // return zValue*(farPlane-nearPlane)+nearPlane;
  35595. //}else{
  35596. float z = zValue * 2.0 - 1.0;
  35597. return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - z * (farPlane - nearPlane));
  35598. //}
  35599. }
  35600. #endif
  35601. vec2 closestLineToLine(vec3 p1, vec3 p2, vec3 p3, vec3 p4) {
  35602. float mua;
  35603. float mub;
  35604. vec3 p13 = p1 - p3;
  35605. vec3 p43 = p4 - p3;
  35606. vec3 p21 = p2 - p1;
  35607. float d1343 = dot( p13, p43 );
  35608. float d4321 = dot( p43, p21 );
  35609. float d1321 = dot( p13, p21 );
  35610. float d4343 = dot( p43, p43 );
  35611. float d2121 = dot( p21, p21 );
  35612. float denom = d2121 * d4343 - d4321 * d4321;
  35613. float numer = d1343 * d4321 - d1321 * d4343;
  35614. mua = numer / denom;
  35615. mua = clamp( mua, 0.0, 1.0 );
  35616. mub = ( d1343 + d4321 * ( mua ) ) / d4343;
  35617. mub = clamp( mub, 0.0, 1.0 );
  35618. return vec2( mua, mub );
  35619. }
  35620. void main() {
  35621. #include <clipping_planes_fragment>
  35622. /*#ifdef USE_DASH
  35623. if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps
  35624. if ( mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize ) discard; // todo - FIX
  35625. #endif*/
  35626. #ifdef USE_DASH
  35627. if ( vUv.y < - 1.0 || vUv.y > 1.0 ) discard; // discard endcaps
  35628. bool unvisible = mod( vLineDistance + dashOffset, dashSize + gapSize ) > dashSize;
  35629. //加
  35630. #ifdef DASH_with_depth
  35631. #else
  35632. if (unvisible) discard; // todo - FIX
  35633. #endif
  35634. #endif
  35635. float alpha = opacity;
  35636. #ifdef WORLD_UNITS
  35637. // Find the closest points on the view ray and the line segment
  35638. vec3 rayEnd = normalize( worldPos.xyz ) * 1e5;
  35639. vec3 lineDir = worldEnd - worldStart;
  35640. vec2 params = closestLineToLine( worldStart, worldEnd, vec3( 0.0, 0.0, 0.0 ), rayEnd );
  35641. vec3 p1 = worldStart + lineDir * params.x;
  35642. vec3 p2 = rayEnd * params.y;
  35643. vec3 delta = p1 - p2;
  35644. float len = length( delta );
  35645. float norm = len / lineWidth;
  35646. #ifndef USE_DASH
  35647. #ifdef USE_ALPHA_TO_COVERAGE
  35648. float dnorm = fwidth( norm );
  35649. alpha = 1.0 - smoothstep( 0.5 - dnorm, 0.5 + dnorm, norm );
  35650. #else
  35651. if ( norm > 0.5 ) {
  35652. discard;
  35653. }
  35654. #endif
  35655. #endif
  35656. #else
  35657. #ifdef USE_ALPHA_TO_COVERAGE
  35658. // artifacts appear on some hardware if a derivative is taken within a conditional
  35659. float a = vUv.x;
  35660. float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
  35661. float len2 = a * a + b * b;
  35662. float dlen = fwidth( len2 );
  35663. if ( abs( vUv.y ) > 1.0 ) {
  35664. alpha = 1.0 - smoothstep( 1.0 - dlen, 1.0 + dlen, len2 );
  35665. }
  35666. #else
  35667. if ( abs( vUv.y ) > 1.0 ) {
  35668. float a = vUv.x;
  35669. float b = ( vUv.y > 0.0 ) ? vUv.y - 1.0 : vUv.y + 1.0;
  35670. float len2 = a * a + b * b;
  35671. if ( len2 > 1.0 ) discard;
  35672. }
  35673. #endif
  35674. #endif
  35675. vec4 diffuseColor = vec4( diffuse, alpha );
  35676. //加
  35677. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  35678. float mixFactor = 0.0;
  35679. float clipFactor = 0.0;
  35680. float fragDepth = convertToLinear(gl_FragCoord.z);
  35681. //gl_FragCoord大小为 viewport client大小
  35682. vec2 depthTxtCoords = vec2(gl_FragCoord.x - viewportOffset.x, gl_FragCoord.y - viewportOffset.y) / resolution;
  35683. float textureDepth = convertToLinear(texture2D(depthTexture, depthTxtCoords).r);
  35684. float delta = fragDepth - textureDepth;
  35685. if (delta > 0.0)
  35686. {
  35687. mixFactor = clamp(delta / occlusionDistance, 0.0, maxOcclusionFactor);
  35688. clipFactor = clamp(delta / clipDistance, 0.0, maxClipFactor);
  35689. }
  35690. if (clipFactor == 1.0)
  35691. {
  35692. discard;
  35693. }
  35694. vec4 backColor_ = vec4(backColor, opacity); //vec4(0.8,0.8,0.8, 0.8*opacity);
  35695. #ifdef DASH_with_depth
  35696. // 只在被遮住的部分显示虚线, 所以若同时是虚线不可见部分和被遮住时, a为0
  35697. if(unvisible) backColor_.a = 0.0;
  35698. #endif
  35699. //vec4 diffuseColor = vec4(mix(diffuse, backColor_, mixFactor), opacity*(1.0 - clipFactor));
  35700. diffuseColor = mix(diffuseColor, backColor_ , mixFactor);
  35701. diffuseColor.a *= (1.0 - clipFactor);
  35702. #endif
  35703. #include <logdepthbuf_fragment>
  35704. #include <color_fragment>
  35705. //gl_FragColor = vec4( diffuseColor.rgb, alpha );
  35706. gl_FragColor = vec4( diffuseColor.rgb, diffuseColor.a );
  35707. #include <tonemapping_fragment>
  35708. #include <encodings_fragment>
  35709. #include <fog_fragment>
  35710. #include <premultiplied_alpha_fragment>
  35711. }
  35712. `
  35713. };
  35714. class LineMaterial extends ShaderMaterial {
  35715. constructor( parameters ) {
  35716. let {vs,fs} = Potree.Common.changeShaderToWebgl2(ShaderLib[ 'line' ].vertexShader, ShaderLib[ 'line' ].fragmentShader, 'ShaderMaterial');
  35717. super( {
  35718. type: 'LineMaterial',
  35719. uniforms: UniformsUtils.clone( ShaderLib[ 'line' ].uniforms ),
  35720. vertexShader: vs,
  35721. fragmentShader: fs,
  35722. clipping: true // required for clipping support
  35723. } );
  35724. this.isLineMaterial = true;
  35725. this.lineWidth_ = 0;
  35726. this.supportExtDepth = parameters.supportExtDepth;
  35727. this.depthTestWhenPick = false; //pick时是否识别点云等
  35728. if(parameters.color){
  35729. this.color = new Color(parameters.color);
  35730. }
  35731. if(parameters.backColor){
  35732. this.uniforms.backColor.value = new Color(parameters.backColor);
  35733. }
  35734. if(parameters.clipDistance){
  35735. this.uniforms.clipDistance.value = parameters.clipDistance;
  35736. }
  35737. if(parameters.occlusionDistance){
  35738. this.uniforms.occlusionDistance.value = parameters.occlusionDistance;
  35739. }
  35740. if(parameters.maxClipFactor){
  35741. this.uniforms.maxClipFactor.value = parameters.maxClipFactor;
  35742. }
  35743. Object.defineProperties( this, {
  35744. color: {
  35745. enumerable: true,
  35746. get: function () {
  35747. return this.uniforms.diffuse.value;
  35748. },
  35749. set: function ( value ) {
  35750. this.uniforms.diffuse.value = value;
  35751. }
  35752. },
  35753. worldUnits: {
  35754. enumerable: true,
  35755. get: function () {
  35756. return 'WORLD_UNITS' in this.defines;
  35757. },
  35758. set: function ( value ) {
  35759. if ( value === true ) {
  35760. this.defines.WORLD_UNITS = '';
  35761. } else {
  35762. delete this.defines.WORLD_UNITS;
  35763. }
  35764. }
  35765. },
  35766. lineWidth: {
  35767. enumerable: true,
  35768. get: function () {
  35769. return this.lineWidth_;//this.uniforms.lineWidth.value;
  35770. },
  35771. set: function ( value ) {
  35772. this.uniforms.lineWidth.value = value * window.devicePixelRatio;
  35773. this.lineWidth_ = value;
  35774. }
  35775. },
  35776. dashed: {
  35777. enumerable: true,
  35778. get: function () {
  35779. return Boolean( 'USE_DASH' in this.defines );
  35780. },
  35781. set( value ) {
  35782. if ( Boolean( value ) !== Boolean( 'USE_DASH' in this.defines ) ) {
  35783. this.needsUpdate = true;
  35784. }
  35785. if ( value === true ) {
  35786. this.defines.USE_DASH = '';
  35787. } else {
  35788. delete this.defines.USE_DASH;
  35789. }
  35790. }
  35791. },
  35792. dashScale: {
  35793. enumerable: true,
  35794. get: function () {
  35795. return this.uniforms.dashScale.value;
  35796. },
  35797. set: function ( value ) {
  35798. this.uniforms.dashScale.value = value;
  35799. }
  35800. },
  35801. dashSize: {
  35802. enumerable: true,
  35803. get: function () {
  35804. return this.uniforms.dashSize.value;
  35805. },
  35806. set: function ( value ) {
  35807. this.uniforms.dashSize.value = value;
  35808. }
  35809. },
  35810. dashOffset: {
  35811. enumerable: true,
  35812. get: function () {
  35813. return this.uniforms.dashOffset.value;
  35814. },
  35815. set: function ( value ) {
  35816. this.uniforms.dashOffset.value = value;
  35817. }
  35818. },
  35819. gapSize: {
  35820. enumerable: true,
  35821. get: function () {
  35822. return this.uniforms.gapSize.value;
  35823. },
  35824. set: function ( value ) {
  35825. this.uniforms.gapSize.value = value;
  35826. }
  35827. },
  35828. opacity: {
  35829. enumerable: true,
  35830. get: function () {
  35831. return this.uniforms.opacity.value;
  35832. },
  35833. set: function ( value ) {
  35834. this.uniforms.opacity.value = value;
  35835. }
  35836. },
  35837. resolution: {
  35838. enumerable: true,
  35839. get: function () {
  35840. return this.uniforms.resolution.value;
  35841. },
  35842. set: function ( value ) {
  35843. this.uniforms.resolution.value.copy( value );
  35844. }
  35845. },
  35846. alphaToCoverage: {
  35847. enumerable: true,
  35848. get: function () {
  35849. return Boolean( 'USE_ALPHA_TO_COVERAGE' in this.defines );
  35850. },
  35851. set: function ( value ) {
  35852. if ( Boolean( value ) !== Boolean( 'USE_ALPHA_TO_COVERAGE' in this.defines ) ) {
  35853. this.needsUpdate = true;
  35854. }
  35855. if ( value === true ) {
  35856. this.defines.USE_ALPHA_TO_COVERAGE = '';
  35857. this.extensions.derivatives = true;
  35858. } else {
  35859. delete this.defines.USE_ALPHA_TO_COVERAGE;
  35860. this.extensions.derivatives = false;
  35861. }
  35862. }
  35863. },
  35864. dashWithDepth:{//add
  35865. enumerable: true,
  35866. get: function () {
  35867. return 'DASH_with_depth' in this.defines
  35868. },
  35869. set: function ( value ) {
  35870. value = value && !!this.supportExtDepth;
  35871. if(value != this.dashWithDepth){
  35872. if(value){
  35873. this.defines.DASH_with_depth = '';
  35874. }else {
  35875. delete this.defines.DASH_with_depth;
  35876. }
  35877. this.needsUpdate = true;
  35878. }
  35879. }
  35880. },
  35881. } );
  35882. this.events = {
  35883. setSize:(e)=>{//如果出现横条状的异常,往往是viewportOffset出错 //地图不需要
  35884. let viewport = e.viewport;
  35885. //console.log(viewport.name, viewport.resolution2)
  35886. this.uniforms.resolution.value.copy(viewport.resolution2);
  35887. this.uniforms.devicePixelRatio.value = window.devicePixelRatio;
  35888. this.lineWidth = this.lineWidth_; //update
  35889. if(!this.realUseDepth || !e.viewport)return
  35890. let viewportOffset = viewport.offset || new THREE.Vector2();
  35891. this.uniforms.viewportOffset.value.copy(viewportOffset);
  35892. },
  35893. render:(e)=>{//before render 如果有大于两个viewport的话,不同viewport用不同的depthTex
  35894. this.useDepth && this.updateDepthParams(e);
  35895. var viewport = e.viewport || viewer.mainViewport;
  35896. if(viewport != this.lastViewport){ //当mapViewer要渲染测量线后,就需要变viewport
  35897. this.events.setSize({viewport});
  35898. }
  35899. this.lastViewport = viewport;
  35900. }
  35901. };
  35902. this.setValues( parameters );
  35903. let viewport = viewer.mainViewport;
  35904. this.events.setSize({viewport});
  35905. viewer.addEventListener('resize', this.events.setSize);
  35906. viewer.addEventListener("render.begin", this.events.render);
  35907. }
  35908. get useDepth(){
  35909. return this.useDepth_
  35910. }
  35911. set useDepth(value){
  35912. value = value && this.supportExtDepth; //如果不支持 EXT_DEPTH 的话会失效
  35913. if(this.useDepth_ != value){
  35914. this.setRealDepth(value);
  35915. this.useDepth_ = value;
  35916. }
  35917. }
  35918. setRealDepth(useDepth, viewport){//确实使用到depthTex
  35919. if(this.realUseDepth != useDepth){
  35920. if(useDepth ){
  35921. this.defines.useDepth = '';
  35922. }else {
  35923. delete this.defines.useDepth;
  35924. }
  35925. this.realUseDepth = useDepth;
  35926. if(this.autoDepthTest)this.depthWrite = this.depthTest = !useDepth; //如果useDepth = false,使用原始的depthTest
  35927. this.needsUpdate = true;
  35928. if(!viewport)viewport = viewer.mainViewport; //暂时这么设置
  35929. useDepth && this.events.setSize({viewport});
  35930. }
  35931. }
  35932. updateDepthParams(e={}){
  35933. var viewport = e.viewport || viewer.mainViewport;
  35934. var camera = viewport.camera;
  35935. let hasDepth = this.useDepth && camera.isPerspectiveCamera &&
  35936. (Potree.settings.pointEnableRT || Potree.settings.displayMode == 'showPanos' || viewer.useEDL);
  35937. this.setRealDepth(hasDepth, viewport);
  35938. if(hasDepth){
  35939. this.uniforms.depthTexture.value = viewer.getPRenderer().getRtEDL(viewport).depthTexture; //其实只赋值一次就行
  35940. this.uniforms.nearPlane.value = camera.near;
  35941. this.uniforms.farPlane.value = camera.far;
  35942. }
  35943. //this.uniforms.uUseOrthographicCamera.value = !camera.isPerspectiveCamera
  35944. }
  35945. }
  35946. const _start$2 = new Vector3();
  35947. const _end$2 = new Vector3();
  35948. const _start4 = new Vector4();
  35949. const _end4 = new Vector4();
  35950. const _ssOrigin = new Vector4();
  35951. const _ssOrigin3 = new Vector3();
  35952. const _mvMatrix = new Matrix4();
  35953. const _line = new Line3();
  35954. const _closestPoint = new Vector3();
  35955. const _box$5 = new Box3();
  35956. const _sphere$4 = new Sphere();
  35957. const _clipToWorldVector = new Vector4();
  35958. let _ray$3, _instanceStart, _instanceEnd, _lineWidth;
  35959. // Returns the margin required to expand by in world space given the distance from the camera,
  35960. // line width, resolution, and camera projection
  35961. function getWorldSpaceHalfWidth( camera, distance, resolution ) {
  35962. // transform into clip space, adjust the x and y values by the pixel width offset, then
  35963. // transform back into world space to get world offset. Note clip space is [-1, 1] so full
  35964. // width does not need to be halved.
  35965. _clipToWorldVector.set( 0, 0, - distance, 1.0 ).applyMatrix4( camera.projectionMatrix );
  35966. _clipToWorldVector.multiplyScalar( 1.0 / _clipToWorldVector.w );
  35967. _clipToWorldVector.x = _lineWidth / resolution.width;
  35968. _clipToWorldVector.y = _lineWidth / resolution.height;
  35969. _clipToWorldVector.applyMatrix4( camera.projectionMatrixInverse );
  35970. _clipToWorldVector.multiplyScalar( 1.0 / _clipToWorldVector.w );
  35971. return Math.abs( Math.max( _clipToWorldVector.x, _clipToWorldVector.y ) );
  35972. }
  35973. function raycastWorldUnits( lineSegments, intersects ) {
  35974. for ( let i = 0, l = _instanceStart.count; i < l; i ++ ) {
  35975. _line.start.fromBufferAttribute( _instanceStart, i );
  35976. _line.end.fromBufferAttribute( _instanceEnd, i );
  35977. const pointOnLine = new Vector3();
  35978. const point = new Vector3();
  35979. _ray$3.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
  35980. const isInside = point.distanceTo( pointOnLine ) < _lineWidth * 0.5;
  35981. if ( isInside ) {
  35982. intersects.push( {
  35983. point,
  35984. pointOnLine,
  35985. distance: _ray$3.origin.distanceTo( point ),
  35986. object: lineSegments,
  35987. face: null,
  35988. faceIndex: i,
  35989. uv: null,
  35990. uv2: null,
  35991. } );
  35992. }
  35993. }
  35994. }
  35995. function raycastScreenSpace( lineSegments, camera, intersects ) {
  35996. const projectionMatrix = camera.projectionMatrix;
  35997. const material = lineSegments.material;
  35998. const resolution = material.resolution;
  35999. const matrixWorld = lineSegments.matrixWorld;
  36000. const geometry = lineSegments.geometry;
  36001. const instanceStart = geometry.attributes.instanceStart;
  36002. const instanceEnd = geometry.attributes.instanceEnd;
  36003. const near = - camera.near;
  36004. //
  36005. // pick a point 1 unit out along the ray to avoid the ray origin
  36006. // sitting at the camera origin which will cause "w" to be 0 when
  36007. // applying the projection matrix.
  36008. _ray$3.at( 1, _ssOrigin );
  36009. // ndc space [ - 1.0, 1.0 ]
  36010. _ssOrigin.w = 1;
  36011. _ssOrigin.applyMatrix4( camera.matrixWorldInverse );
  36012. _ssOrigin.applyMatrix4( projectionMatrix );
  36013. _ssOrigin.multiplyScalar( 1 / _ssOrigin.w );
  36014. // screen space
  36015. _ssOrigin.x *= resolution.x / 2;
  36016. _ssOrigin.y *= resolution.y / 2;
  36017. _ssOrigin.z = 0;
  36018. _ssOrigin3.copy( _ssOrigin );
  36019. _mvMatrix.multiplyMatrices( camera.matrixWorldInverse, matrixWorld );
  36020. for ( let i = 0, l = instanceStart.count; i < l; i ++ ) {
  36021. _start4.fromBufferAttribute( instanceStart, i );
  36022. _end4.fromBufferAttribute( instanceEnd, i );
  36023. _start4.w = 1;
  36024. _end4.w = 1;
  36025. // camera space
  36026. _start4.applyMatrix4( _mvMatrix );
  36027. _end4.applyMatrix4( _mvMatrix );
  36028. // skip the segment if it's entirely behind the camera
  36029. const isBehindCameraNear = _start4.z > near && _end4.z > near;
  36030. if ( isBehindCameraNear ) {
  36031. continue;
  36032. }
  36033. // trim the segment if it extends behind camera near
  36034. if ( _start4.z > near ) {
  36035. const deltaDist = _start4.z - _end4.z;
  36036. const t = ( _start4.z - near ) / deltaDist;
  36037. _start4.lerp( _end4, t );
  36038. } else if ( _end4.z > near ) {
  36039. const deltaDist = _end4.z - _start4.z;
  36040. const t = ( _end4.z - near ) / deltaDist;
  36041. _end4.lerp( _start4, t );
  36042. }
  36043. // clip space
  36044. _start4.applyMatrix4( projectionMatrix );
  36045. _end4.applyMatrix4( projectionMatrix );
  36046. // ndc space [ - 1.0, 1.0 ]
  36047. _start4.multiplyScalar( 1 / _start4.w );
  36048. _end4.multiplyScalar( 1 / _end4.w );
  36049. // screen space
  36050. _start4.x *= resolution.x / 2;
  36051. _start4.y *= resolution.y / 2;
  36052. _end4.x *= resolution.x / 2;
  36053. _end4.y *= resolution.y / 2;
  36054. // create 2d segment
  36055. _line.start.copy( _start4 );
  36056. _line.start.z = 0;
  36057. _line.end.copy( _end4 );
  36058. _line.end.z = 0;
  36059. // get closest point on ray to segment
  36060. const param = _line.closestPointToPointParameter( _ssOrigin3, true );
  36061. _line.at( param, _closestPoint );
  36062. // check if the intersection point is within clip space
  36063. const zPos = MathUtils.lerp( _start4.z, _end4.z, param );
  36064. const isInClipSpace = zPos >= - 1 && zPos <= 1;
  36065. const isInside = _ssOrigin3.distanceTo( _closestPoint ) < _lineWidth * 0.5;
  36066. if ( isInClipSpace && isInside ) {
  36067. _line.start.fromBufferAttribute( instanceStart, i );
  36068. _line.end.fromBufferAttribute( instanceEnd, i );
  36069. _line.start.applyMatrix4( matrixWorld );
  36070. _line.end.applyMatrix4( matrixWorld );
  36071. const pointOnLine = new Vector3();
  36072. const point = new Vector3();
  36073. _ray$3.distanceSqToSegment( _line.start, _line.end, point, pointOnLine );
  36074. intersects.push( {
  36075. point: point,
  36076. pointOnLine: pointOnLine,
  36077. distance: _ray$3.origin.distanceTo( point ),
  36078. object: lineSegments,
  36079. face: null,
  36080. faceIndex: i,
  36081. uv: null,
  36082. uv2: null,
  36083. } );
  36084. }
  36085. }
  36086. }
  36087. class LineSegments2 extends Mesh {
  36088. constructor( geometry = new LineSegmentsGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
  36089. super( geometry, material );
  36090. this.isLineSegments2 = true;
  36091. this.type = 'LineSegments2';
  36092. }
  36093. // for backwards-compatibility, but could be a method of LineSegmentsGeometry...
  36094. computeLineDistances() {
  36095. const geometry = this.geometry;
  36096. const instanceStart = geometry.attributes.instanceStart;
  36097. const instanceEnd = geometry.attributes.instanceEnd;
  36098. const lineDistances = new Float32Array( 2 * instanceStart.count );
  36099. for ( let i = 0, j = 0, l = instanceStart.count; i < l; i ++, j += 2 ) {
  36100. _start$2.fromBufferAttribute( instanceStart, i );
  36101. _end$2.fromBufferAttribute( instanceEnd, i );
  36102. lineDistances[ j ] = ( j === 0 ) ? 0 : lineDistances[ j - 1 ];
  36103. lineDistances[ j + 1 ] = lineDistances[ j ] + _start$2.distanceTo( _end$2 );
  36104. }
  36105. const instanceDistanceBuffer = new InstancedInterleavedBuffer( lineDistances, 2, 1 ); // d0, d1
  36106. geometry.setAttribute( 'instanceDistanceStart', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 0 ) ); // d0
  36107. geometry.setAttribute( 'instanceDistanceEnd', new InterleavedBufferAttribute( instanceDistanceBuffer, 1, 1 ) ); // d1
  36108. return this;
  36109. }
  36110. raycast( raycaster, intersects ) {
  36111. const worldUnits = this.material.worldUnits;
  36112. const camera = raycaster.camera;
  36113. if ( camera === null && ! worldUnits ) {
  36114. console.error( 'LineSegments2: "Raycaster.camera" needs to be set in order to raycast against LineSegments2 while worldUnits is set to false.' );
  36115. }
  36116. const threshold = ( raycaster.params.Line2 !== undefined ) ? raycaster.params.Line2.threshold || 0 : 0;
  36117. _ray$3 = raycaster.ray;
  36118. const matrixWorld = this.matrixWorld;
  36119. const geometry = this.geometry;
  36120. const material = this.material;
  36121. _lineWidth = material.lineWidth + threshold;
  36122. _instanceStart = geometry.attributes.instanceStart;
  36123. _instanceEnd = geometry.attributes.instanceEnd;
  36124. // check if we intersect the sphere bounds
  36125. if ( geometry.boundingSphere === null ) {
  36126. geometry.computeBoundingSphere();
  36127. }
  36128. _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( matrixWorld );
  36129. // increase the sphere bounds by the worst case line screen space width
  36130. let sphereMargin;
  36131. if ( worldUnits ) {
  36132. sphereMargin = _lineWidth * 0.5;
  36133. } else {
  36134. const distanceToSphere = Math.max( camera.near, _sphere$4.distanceToPoint( _ray$3.origin ) );
  36135. sphereMargin = getWorldSpaceHalfWidth( camera, distanceToSphere, material.resolution );
  36136. }
  36137. _sphere$4.radius += sphereMargin;
  36138. if ( _ray$3.intersectsSphere( _sphere$4 ) === false ) {
  36139. return;
  36140. }
  36141. // check if we intersect the box bounds
  36142. if ( geometry.boundingBox === null ) {
  36143. geometry.computeBoundingBox();
  36144. }
  36145. _box$5.copy( geometry.boundingBox ).applyMatrix4( matrixWorld );
  36146. // increase the box bounds by the worst case line width
  36147. let boxMargin;
  36148. if ( worldUnits ) {
  36149. boxMargin = _lineWidth * 0.5;
  36150. } else {
  36151. const distanceToBox = Math.max( camera.near, _box$5.distanceToPoint( _ray$3.origin ) );
  36152. boxMargin = getWorldSpaceHalfWidth( camera, distanceToBox, material.resolution );
  36153. }
  36154. _box$5.expandByScalar( boxMargin );
  36155. if ( _ray$3.intersectsBox( _box$5 ) === false ) {
  36156. return;
  36157. }
  36158. if ( worldUnits ) {
  36159. raycastWorldUnits( this, intersects );
  36160. } else {
  36161. raycastScreenSpace( this, camera, intersects );
  36162. }
  36163. }
  36164. }
  36165. class LineGeometry extends LineSegmentsGeometry {
  36166. constructor() {
  36167. super();
  36168. this.isLineGeometry = true;
  36169. this.type = 'LineGeometry';
  36170. }
  36171. setPositions( array ) {//见potree.shim.js
  36172. // converts [ x1, y1, z1, x2, y2, z2, ... ] to pairs format
  36173. const length = array.length - 3;
  36174. const points = new Float32Array( 2 * length );
  36175. for ( let i = 0; i < length; i += 3 ) {
  36176. points[ 2 * i ] = array[ i ];
  36177. points[ 2 * i + 1 ] = array[ i + 1 ];
  36178. points[ 2 * i + 2 ] = array[ i + 2 ];
  36179. points[ 2 * i + 3 ] = array[ i + 3 ];
  36180. points[ 2 * i + 4 ] = array[ i + 4 ];
  36181. points[ 2 * i + 5 ] = array[ i + 5 ];
  36182. }
  36183. super.setPositions( points );
  36184. return this;
  36185. }
  36186. setColors( array ) {
  36187. // converts [ r1, g1, b1, r2, g2, b2, ... ] to pairs format
  36188. const length = array.length - 3;
  36189. const colors = new Float32Array( 2 * length );
  36190. for ( let i = 0; i < length; i += 3 ) {
  36191. colors[ 2 * i ] = array[ i ];
  36192. colors[ 2 * i + 1 ] = array[ i + 1 ];
  36193. colors[ 2 * i + 2 ] = array[ i + 2 ];
  36194. colors[ 2 * i + 3 ] = array[ i + 3 ];
  36195. colors[ 2 * i + 4 ] = array[ i + 4 ];
  36196. colors[ 2 * i + 5 ] = array[ i + 5 ];
  36197. }
  36198. super.setColors( colors );
  36199. return this;
  36200. }
  36201. fromLine( line ) {
  36202. const geometry = line.geometry;
  36203. this.setPositions( geometry.attributes.position.array ); // assumes non-indexed
  36204. // set colors, maybe
  36205. return this;
  36206. }
  36207. }
  36208. class Line2 extends LineSegments2 {
  36209. constructor( geometry = new LineGeometry(), material = new LineMaterial( { color: Math.random() * 0xffffff } ) ) {
  36210. super( geometry, material );
  36211. this.isLine2 = true;
  36212. this.type = 'Line2';
  36213. }
  36214. }
  36215. //old
  36216. function createHeightLine(){
  36217. let lineGeometry = new LineGeometry();
  36218. lineGeometry.setPositions([
  36219. 0, 0, 0,
  36220. 0, 0, 0,
  36221. ]);
  36222. let lineMaterial = new LineMaterial({
  36223. color: 0x00ff00,
  36224. dashSize: 5,
  36225. gapSize: 2,
  36226. linewidth: 2,
  36227. resolution: new Vector2(1000, 1000),
  36228. });
  36229. lineMaterial.depthTest = false;
  36230. const heightEdge = new Line2(lineGeometry, lineMaterial);
  36231. heightEdge.visible = false;
  36232. //this.add(this.heightEdge);
  36233. return heightEdge;
  36234. }
  36235. function createHeightLabel(){
  36236. const heightLabel = new TextSprite$1('');
  36237. heightLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  36238. heightLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36239. heightLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36240. heightLabel.fontsize = 16;
  36241. heightLabel.material.depthTest = false;
  36242. heightLabel.material.opacity = 1;
  36243. heightLabel.visible = false;
  36244. return heightLabel;
  36245. }
  36246. function createAreaLabel(){
  36247. const areaLabel = new TextSprite$1('');
  36248. areaLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  36249. areaLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36250. areaLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36251. areaLabel.fontsize = 16;
  36252. areaLabel.material.depthTest = false;
  36253. areaLabel.material.opacity = 1;
  36254. areaLabel.visible = false;
  36255. return areaLabel;
  36256. }
  36257. function createCircleRadiusLabel(){
  36258. const circleRadiusLabel = new TextSprite$1("");
  36259. circleRadiusLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  36260. circleRadiusLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36261. circleRadiusLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36262. circleRadiusLabel.fontsize = 16;
  36263. circleRadiusLabel.material.depthTest = false;
  36264. circleRadiusLabel.material.opacity = 1;
  36265. circleRadiusLabel.visible = false;
  36266. return circleRadiusLabel;
  36267. }
  36268. function createCircleRadiusLine(){
  36269. const lineGeometry = new LineGeometry();
  36270. lineGeometry.setPositions([
  36271. 0, 0, 0,
  36272. 0, 0, 0,
  36273. ]);
  36274. const lineMaterial = new LineMaterial({
  36275. color: 0xff0000,
  36276. linewidth: 2,
  36277. resolution: new Vector2(1000, 1000),
  36278. gapSize: 1,
  36279. dashed: true,
  36280. });
  36281. lineMaterial.depthTest = false;
  36282. const circleRadiusLine = new Line2(lineGeometry, lineMaterial);
  36283. circleRadiusLine.visible = false;
  36284. return circleRadiusLine;
  36285. }
  36286. function createCircleLine(){
  36287. const coordinates = [];
  36288. let n = 128;
  36289. for(let i = 0; i <= n; i++){
  36290. let u0 = 2 * Math.PI * (i / n);
  36291. let u1 = 2 * Math.PI * (i + 1) / n;
  36292. let p0 = new Vector3(
  36293. Math.cos(u0),
  36294. Math.sin(u0),
  36295. 0
  36296. );
  36297. let p1 = new Vector3(
  36298. Math.cos(u1),
  36299. Math.sin(u1),
  36300. 0
  36301. );
  36302. coordinates.push(
  36303. ...p0.toArray(),
  36304. ...p1.toArray(),
  36305. );
  36306. }
  36307. const geometry = new LineGeometry();
  36308. geometry.setPositions(coordinates);
  36309. const material = new LineMaterial({
  36310. color: 0xff0000,
  36311. dashSize: 5,
  36312. gapSize: 2,
  36313. linewidth: 2,
  36314. resolution: new Vector2(1000, 1000),
  36315. });
  36316. material.depthTest = false;
  36317. const circleLine = new Line2(geometry, material);
  36318. circleLine.visible = false;
  36319. circleLine.computeLineDistances();
  36320. return circleLine;
  36321. }
  36322. function createCircleCenter(){
  36323. const sg = new SphereGeometry(1, 32, 32);
  36324. const sm = new MeshNormalMaterial();
  36325. const circleCenter = new Mesh(sg, sm);
  36326. circleCenter.visible = false;
  36327. return circleCenter;
  36328. }
  36329. function createLine(){
  36330. const geometry = new LineGeometry();
  36331. geometry.setPositions([
  36332. 0, 0, 0,
  36333. 0, 0, 0,
  36334. ]);
  36335. const material = new LineMaterial({
  36336. color: 0xff0000,
  36337. linewidth: 2,
  36338. resolution: new Vector2(1000, 1000),
  36339. gapSize: 1,
  36340. dashed: true,
  36341. });
  36342. material.depthTest = false;
  36343. const line = new Line2(geometry, material);
  36344. return line;
  36345. }
  36346. function createCircle(){
  36347. const coordinates = [];
  36348. let n = 128;
  36349. for(let i = 0; i <= n; i++){
  36350. let u0 = 2 * Math.PI * (i / n);
  36351. let u1 = 2 * Math.PI * (i + 1) / n;
  36352. let p0 = new Vector3(
  36353. Math.cos(u0),
  36354. Math.sin(u0),
  36355. 0
  36356. );
  36357. let p1 = new Vector3(
  36358. Math.cos(u1),
  36359. Math.sin(u1),
  36360. 0
  36361. );
  36362. coordinates.push(
  36363. ...p0.toArray(),
  36364. ...p1.toArray(),
  36365. );
  36366. }
  36367. const geometry = new LineGeometry();
  36368. geometry.setPositions(coordinates);
  36369. const material = new LineMaterial({
  36370. color: 0xff0000,
  36371. dashSize: 5,
  36372. gapSize: 2,
  36373. linewidth: 2,
  36374. resolution: new Vector2(1000, 1000),
  36375. });
  36376. material.depthTest = false;
  36377. const line = new Line2(geometry, material);
  36378. line.computeLineDistances();
  36379. return line;
  36380. }
  36381. function createAzimuth(){
  36382. const azimuth = {
  36383. label: null,
  36384. center: null,
  36385. target: null,
  36386. north: null,
  36387. centerToNorth: null,
  36388. centerToTarget: null,
  36389. centerToTargetground: null,
  36390. targetgroundToTarget: null,
  36391. circle: null,
  36392. node: null,
  36393. };
  36394. const sg = new SphereGeometry(1, 32, 32);
  36395. const sm = new MeshNormalMaterial();
  36396. {
  36397. const label = new TextSprite$1("");
  36398. label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  36399. label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36400. label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36401. label.fontsize = 16;
  36402. label.material.depthTest = false;
  36403. label.material.opacity = 1;
  36404. azimuth.label = label;
  36405. }
  36406. azimuth.center = new Mesh(sg, sm);
  36407. azimuth.target = new Mesh(sg, sm);
  36408. azimuth.north = new Mesh(sg, sm);
  36409. azimuth.centerToNorth = createLine();
  36410. azimuth.centerToTarget = createLine();
  36411. azimuth.centerToTargetground = createLine();
  36412. azimuth.targetgroundToTarget = createLine();
  36413. azimuth.circle = createCircle();
  36414. azimuth.node = new Object3D();
  36415. azimuth.node.add(
  36416. azimuth.centerToNorth,
  36417. azimuth.centerToTarget,
  36418. azimuth.centerToTargetground,
  36419. azimuth.targetgroundToTarget,
  36420. azimuth.circle,
  36421. azimuth.label,
  36422. azimuth.center,
  36423. azimuth.target,
  36424. azimuth.north,
  36425. );
  36426. return azimuth;
  36427. }
  36428. class Measure extends Object3D {
  36429. constructor () {
  36430. super();
  36431. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  36432. this.name = 'Measure_' + this.constructor.counter;
  36433. this.points = [];
  36434. this._showDistances = true;
  36435. this._showCoordinates = false;
  36436. this._showArea = false;
  36437. this._closed = true;
  36438. this._showAngles = false;
  36439. this._showCircle = false;
  36440. this._showHeight = false;
  36441. this._showEdges = true;
  36442. this._showAzimuth = false;
  36443. this.maxMarkers = Number.MAX_SAFE_INTEGER;
  36444. this.sphereGeometry = new SphereGeometry(0.4, 10, 10);
  36445. this.color = new Color(0xff0000);
  36446. this.spheres = [];
  36447. this.edges = [];
  36448. this.sphereLabels = [];
  36449. this.edgeLabels = [];
  36450. this.angleLabels = [];
  36451. this.coordinateLabels = [];
  36452. this.heightEdge = createHeightLine();
  36453. this.heightLabel = createHeightLabel();
  36454. this.areaLabel = createAreaLabel();
  36455. this.circleRadiusLabel = createCircleRadiusLabel();
  36456. this.circleRadiusLine = createCircleRadiusLine();
  36457. this.circleLine = createCircleLine();
  36458. this.circleCenter = createCircleCenter();
  36459. this.azimuth = createAzimuth();
  36460. this.add(this.heightEdge);
  36461. this.add(this.heightLabel);
  36462. this.add(this.areaLabel);
  36463. this.add(this.circleRadiusLabel);
  36464. this.add(this.circleRadiusLine);
  36465. this.add(this.circleLine);
  36466. this.add(this.circleCenter);
  36467. this.add(this.azimuth.node);
  36468. }
  36469. createSphereMaterial () {
  36470. let sphereMaterial = new MeshLambertMaterial({
  36471. //shading: THREE.SmoothShading,
  36472. color: this.color,
  36473. depthTest: false,
  36474. depthWrite: false}
  36475. );
  36476. return sphereMaterial;
  36477. };
  36478. addMarker (point) {
  36479. if (point.x != null) {
  36480. point = {position: point};
  36481. }else if(point instanceof Array){
  36482. point = {position: new Vector3(...point)};
  36483. }
  36484. this.points.push(point);
  36485. // sphere
  36486. let sphere = new Mesh(this.sphereGeometry, this.createSphereMaterial());
  36487. this.add(sphere);
  36488. this.spheres.push(sphere);
  36489. { // edges
  36490. let lineGeometry = new LineGeometry();
  36491. lineGeometry.setPositions( [
  36492. 0, 0, 0,
  36493. 0, 0, 0,
  36494. ]);
  36495. let lineMaterial = new LineMaterial({
  36496. color: 0xff0000,
  36497. linewidth: 2,
  36498. resolution: new Vector2(1000, 1000),
  36499. });
  36500. lineMaterial.depthTest = false;
  36501. let edge = new Line2(lineGeometry, lineMaterial);
  36502. edge.visible = true;
  36503. this.add(edge);
  36504. this.edges.push(edge);
  36505. }
  36506. { // edge labels
  36507. let edgeLabel = new TextSprite$1();
  36508. edgeLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36509. edgeLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36510. edgeLabel.material.depthTest = false;
  36511. edgeLabel.visible = false;
  36512. edgeLabel.fontsize = 16;
  36513. this.edgeLabels.push(edgeLabel);
  36514. this.add(edgeLabel);
  36515. }
  36516. { // angle labels
  36517. let angleLabel = new TextSprite$1();
  36518. angleLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36519. angleLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36520. angleLabel.fontsize = 16;
  36521. angleLabel.material.depthTest = false;
  36522. angleLabel.material.opacity = 1;
  36523. angleLabel.visible = false;
  36524. this.angleLabels.push(angleLabel);
  36525. this.add(angleLabel);
  36526. }
  36527. { // coordinate labels
  36528. let coordinateLabel = new TextSprite$1();
  36529. coordinateLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  36530. coordinateLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  36531. coordinateLabel.fontsize = 16;
  36532. coordinateLabel.material.depthTest = false;
  36533. coordinateLabel.material.opacity = 1;
  36534. coordinateLabel.visible = false;
  36535. this.coordinateLabels.push(coordinateLabel);
  36536. this.add(coordinateLabel);
  36537. }
  36538. { // Event Listeners
  36539. let drag = (e) => {
  36540. let I = Utils.getMousePointCloudIntersection(
  36541. e.drag.end,
  36542. e.viewer.scene.getActiveCamera(),
  36543. e.viewer,
  36544. e.viewer.scene.pointclouds,
  36545. {pickClipped: true});
  36546. if (I) {
  36547. let i = this.spheres.indexOf(e.drag.object);
  36548. if (i !== -1) {
  36549. let point = this.points[i];
  36550. // loop through current keys and cleanup ones that will be orphaned
  36551. for (let key of Object.keys(point)) {
  36552. if (!I.point[key]) {
  36553. delete point[key];
  36554. }
  36555. }
  36556. for (let key of Object.keys(I.point).filter(e => e !== 'position')) {
  36557. point[key] = I.point[key];
  36558. }
  36559. this.setPosition(i, I.location);
  36560. }
  36561. }
  36562. };
  36563. let drop = e => {
  36564. let i = this.spheres.indexOf(e.drag.object);
  36565. if (i !== -1) {
  36566. this.dispatchEvent({
  36567. 'type': 'marker_dropped',
  36568. 'measurement': this,
  36569. 'index': i
  36570. });
  36571. }
  36572. };
  36573. let mouseover = (e) => e.object.material.emissive.setHex(0x888888);
  36574. let mouseleave = (e) => e.object.material.emissive.setHex(0x000000);
  36575. sphere.addEventListener('drag', drag);
  36576. sphere.addEventListener('drop', drop);
  36577. sphere.addEventListener('mouseover', mouseover);
  36578. sphere.addEventListener('mouseleave', mouseleave);
  36579. }
  36580. let event = {
  36581. type: 'marker_added',
  36582. measurement: this,
  36583. sphere: sphere
  36584. };
  36585. this.dispatchEvent(event);
  36586. this.setMarker(this.points.length - 1, point);
  36587. };
  36588. removeMarker (index) {
  36589. this.points.splice(index, 1);
  36590. this.remove(this.spheres[index]);
  36591. let edgeIndex = (index === 0) ? 0 : (index - 1);
  36592. this.remove(this.edges[edgeIndex]);
  36593. this.edges.splice(edgeIndex, 1);
  36594. this.remove(this.edgeLabels[edgeIndex]);
  36595. this.edgeLabels.splice(edgeIndex, 1);
  36596. this.coordinateLabels.splice(index, 1);
  36597. this.remove(this.angleLabels[index]);
  36598. this.angleLabels.splice(index, 1);
  36599. this.spheres.splice(index, 1);
  36600. this.update();
  36601. this.dispatchEvent({type: 'marker_removed', measurement: this});
  36602. };
  36603. setMarker (index, point) {
  36604. this.points[index] = point;
  36605. let event = {
  36606. type: 'marker_moved',
  36607. measure: this,
  36608. index: index,
  36609. position: point.position.clone()
  36610. };
  36611. this.dispatchEvent(event);
  36612. this.update();
  36613. }
  36614. setPosition (index, position) {
  36615. let point = this.points[index];
  36616. point.position.copy(position);
  36617. let event = {
  36618. type: 'marker_moved',
  36619. measure: this,
  36620. index: index,
  36621. position: position.clone()
  36622. };
  36623. this.dispatchEvent(event);
  36624. this.update();
  36625. };
  36626. getArea () {
  36627. let area = 0;
  36628. let j = this.points.length - 1;
  36629. for (let i = 0; i < this.points.length; i++) {
  36630. let p1 = this.points[i].position;
  36631. let p2 = this.points[j].position;
  36632. area += (p2.x + p1.x) * (p1.y - p2.y);
  36633. j = i;
  36634. }
  36635. return Math.abs(area / 2);
  36636. };
  36637. getTotalDistance () {
  36638. if (this.points.length === 0) {
  36639. return 0;
  36640. }
  36641. let distance = 0;
  36642. for (let i = 1; i < this.points.length; i++) {
  36643. let prev = this.points[i - 1].position;
  36644. let curr = this.points[i].position;
  36645. let d = prev.distanceTo(curr);
  36646. distance += d;
  36647. }
  36648. if (this.closed && this.points.length > 1) {
  36649. let first = this.points[0].position;
  36650. let last = this.points[this.points.length - 1].position;
  36651. let d = last.distanceTo(first);
  36652. distance += d;
  36653. }
  36654. return distance;
  36655. }
  36656. getAngleBetweenLines (cornerPoint, point1, point2) {
  36657. let v1 = new Vector3().subVectors(point1.position, cornerPoint.position);
  36658. let v2 = new Vector3().subVectors(point2.position, cornerPoint.position);
  36659. // avoid the error printed by threejs if denominator is 0
  36660. const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
  36661. if(denominator === 0){
  36662. return 0;
  36663. }else {
  36664. return v1.angleTo(v2);
  36665. }
  36666. };
  36667. getAngle (index) {
  36668. if (this.points.length < 3 || index >= this.points.length) {
  36669. return 0;
  36670. }
  36671. let previous = (index === 0) ? this.points[this.points.length - 1] : this.points[index - 1];
  36672. let point = this.points[index];
  36673. let next = this.points[(index + 1) % (this.points.length)];
  36674. return this.getAngleBetweenLines(point, previous, next);
  36675. }
  36676. // updateAzimuth(){
  36677. // // if(this.points.length !== 2){
  36678. // // return;
  36679. // // }
  36680. // // const azimuth = this.azimuth;
  36681. // // const [p0, p1] = this.points;
  36682. // // const r = p0.position.distanceTo(p1.position);
  36683. // }
  36684. update () {
  36685. if (this.points.length === 0) {
  36686. return;
  36687. } else if (this.points.length === 1) {
  36688. let point = this.points[0];
  36689. let position = point.position;
  36690. this.spheres[0].position.copy(position);
  36691. { // coordinate labels
  36692. let coordinateLabel = this.coordinateLabels[0];
  36693. let msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
  36694. coordinateLabel.setText(msg);
  36695. coordinateLabel.visible = this.showCoordinates;
  36696. }
  36697. return;
  36698. }
  36699. let lastIndex = this.points.length - 1;
  36700. let centroid = new Vector3();
  36701. for (let i = 0; i <= lastIndex; i++) {
  36702. let point = this.points[i];
  36703. centroid.add(point.position);
  36704. }
  36705. centroid.divideScalar(this.points.length);
  36706. for (let i = 0; i <= lastIndex; i++) {
  36707. let index = i;
  36708. let nextIndex = (i + 1 > lastIndex) ? 0 : i + 1;
  36709. let previousIndex = (i === 0) ? lastIndex : i - 1;
  36710. let point = this.points[index];
  36711. let nextPoint = this.points[nextIndex];
  36712. let previousPoint = this.points[previousIndex];
  36713. let sphere = this.spheres[index];
  36714. // spheres
  36715. sphere.position.copy(point.position);
  36716. sphere.material.color = this.color;
  36717. { // edges
  36718. let edge = this.edges[index];
  36719. edge.material.color = this.color;
  36720. edge.position.copy(point.position);
  36721. edge.geometry.setPositions([
  36722. 0, 0, 0,
  36723. ...nextPoint.position.clone().sub(point.position).toArray(),
  36724. ]);
  36725. edge.geometry.verticesNeedUpdate = true;
  36726. edge.geometry.computeBoundingSphere();
  36727. edge.computeLineDistances();
  36728. edge.visible = index < lastIndex || this.closed;
  36729. if(!this.showEdges){
  36730. edge.visible = false;
  36731. }
  36732. }
  36733. { // edge labels
  36734. let edgeLabel = this.edgeLabels[i];
  36735. let center = new Vector3().add(point.position);
  36736. center.add(nextPoint.position);
  36737. center = center.multiplyScalar(0.5);
  36738. let distance = point.position.distanceTo(nextPoint.position);
  36739. edgeLabel.position.copy(center);
  36740. let suffix = "";
  36741. if(this.lengthUnit != null && this.lengthUnitDisplay != null){
  36742. distance = distance / this.lengthUnit.unitspermeter * this.lengthUnitDisplay.unitspermeter; //convert to meters then to the display unit
  36743. suffix = this.lengthUnitDisplay.code;
  36744. }
  36745. let txtLength = Utils.addCommas(distance.toFixed(2));
  36746. edgeLabel.setText(`${txtLength} ${suffix}`);
  36747. edgeLabel.visible = this.showDistances && (index < lastIndex || this.closed) && this.points.length >= 2 && distance > 0;
  36748. }
  36749. { // angle labels
  36750. let angleLabel = this.angleLabels[i];
  36751. let angle = this.getAngleBetweenLines(point, previousPoint, nextPoint);
  36752. let dir = nextPoint.position.clone().sub(previousPoint.position);
  36753. dir.multiplyScalar(0.5);
  36754. dir = previousPoint.position.clone().add(dir).sub(point.position).normalize();
  36755. let dist = Math.min(point.position.distanceTo(previousPoint.position), point.position.distanceTo(nextPoint.position));
  36756. dist = dist / 9;
  36757. let labelPos = point.position.clone().add(dir.multiplyScalar(dist));
  36758. angleLabel.position.copy(labelPos);
  36759. let msg = Utils.addCommas((angle * (180.0 / Math.PI)).toFixed(1)) + '\u00B0';
  36760. angleLabel.setText(msg);
  36761. angleLabel.visible = this.showAngles && (index < lastIndex || this.closed) && this.points.length >= 3 && angle > 0;
  36762. }
  36763. }
  36764. { // update height stuff
  36765. let heightEdge = this.heightEdge;
  36766. heightEdge.visible = this.showHeight;
  36767. this.heightLabel.visible = this.showHeight;
  36768. if (this.showHeight) {
  36769. let sorted = this.points.slice().sort((a, b) => a.position.z - b.position.z);
  36770. let lowPoint = sorted[0].position.clone();
  36771. let highPoint = sorted[sorted.length - 1].position.clone();
  36772. let min = lowPoint.z;
  36773. let max = highPoint.z;
  36774. let height = max - min;
  36775. let start = new Vector3(highPoint.x, highPoint.y, min);
  36776. let end = new Vector3(highPoint.x, highPoint.y, max);
  36777. heightEdge.position.copy(lowPoint);
  36778. heightEdge.geometry.setPositions([
  36779. 0, 0, 0,
  36780. ...start.clone().sub(lowPoint).toArray(),
  36781. ...start.clone().sub(lowPoint).toArray(),
  36782. ...end.clone().sub(lowPoint).toArray(),
  36783. ]);
  36784. heightEdge.geometry.verticesNeedUpdate = true;
  36785. // heightEdge.geometry.computeLineDistances();
  36786. // heightEdge.geometry.lineDistancesNeedUpdate = true;
  36787. heightEdge.geometry.computeBoundingSphere();
  36788. heightEdge.computeLineDistances();
  36789. // heightEdge.material.dashSize = height / 40;
  36790. // heightEdge.material.gapSize = height / 40;
  36791. let heightLabelPosition = start.clone().add(end).multiplyScalar(0.5);
  36792. this.heightLabel.position.copy(heightLabelPosition);
  36793. let suffix = "";
  36794. if(this.lengthUnit != null && this.lengthUnitDisplay != null){
  36795. height = height / this.lengthUnit.unitspermeter * this.lengthUnitDisplay.unitspermeter; //convert to meters then to the display unit
  36796. suffix = this.lengthUnitDisplay.code;
  36797. }
  36798. let txtHeight = Utils.addCommas(height.toFixed(2));
  36799. let msg = `${txtHeight} ${suffix}`;
  36800. this.heightLabel.setText(msg);
  36801. }
  36802. }
  36803. { // update circle stuff
  36804. const circleRadiusLabel = this.circleRadiusLabel;
  36805. const circleRadiusLine = this.circleRadiusLine;
  36806. const circleLine = this.circleLine;
  36807. const circleCenter = this.circleCenter;
  36808. const circleOkay = this.points.length === 3;
  36809. circleRadiusLabel.visible = this.showCircle && circleOkay;
  36810. circleRadiusLine.visible = this.showCircle && circleOkay;
  36811. circleLine.visible = this.showCircle && circleOkay;
  36812. circleCenter.visible = this.showCircle && circleOkay;
  36813. if(this.showCircle && circleOkay){
  36814. const A = this.points[0].position;
  36815. const B = this.points[1].position;
  36816. const C = this.points[2].position;
  36817. const AB = B.clone().sub(A);
  36818. const AC = C.clone().sub(A);
  36819. const N = AC.clone().cross(AB).normalize();
  36820. const center = Potree.Utils.computeCircleCenter(A, B, C);
  36821. const radius = center.distanceTo(A);
  36822. const scale = radius / 20;
  36823. circleCenter.position.copy(center);
  36824. circleCenter.scale.set(scale, scale, scale);
  36825. //circleRadiusLine.geometry.vertices[0].set(0, 0, 0);
  36826. //circleRadiusLine.geometry.vertices[1].copy(B.clone().sub(center));
  36827. circleRadiusLine.geometry.setPositions( [
  36828. 0, 0, 0,
  36829. ...B.clone().sub(center).toArray()
  36830. ] );
  36831. circleRadiusLine.geometry.verticesNeedUpdate = true;
  36832. circleRadiusLine.geometry.computeBoundingSphere();
  36833. circleRadiusLine.position.copy(center);
  36834. circleRadiusLine.computeLineDistances();
  36835. const target = center.clone().add(N);
  36836. circleLine.position.copy(center);
  36837. circleLine.scale.set(radius, radius, radius);
  36838. circleLine.lookAt(target);
  36839. circleRadiusLabel.visible = true;
  36840. circleRadiusLabel.position.copy(center.clone().add(B).multiplyScalar(0.5));
  36841. circleRadiusLabel.setText(`${radius.toFixed(3)}`);
  36842. }
  36843. }
  36844. { // update area label
  36845. this.areaLabel.position.copy(centroid);
  36846. this.areaLabel.visible = this.showArea && this.points.length >= 3;
  36847. let area = this.getArea();
  36848. let suffix = "";
  36849. if(this.lengthUnit != null && this.lengthUnitDisplay != null){
  36850. area = area / Math.pow(this.lengthUnit.unitspermeter, 2) * Math.pow(this.lengthUnitDisplay.unitspermeter, 2); //convert to square meters then to the square display unit
  36851. suffix = this.lengthUnitDisplay.code;
  36852. }
  36853. let txtArea = Utils.addCommas(area.toFixed(1));
  36854. let msg = `${txtArea} ${suffix}\u00B2`;
  36855. this.areaLabel.setText(msg);
  36856. }
  36857. // this.updateAzimuth();
  36858. };
  36859. raycast (raycaster, intersects) {
  36860. for (let i = 0; i < this.points.length; i++) {
  36861. let sphere = this.spheres[i];
  36862. sphere.raycast(raycaster, intersects);
  36863. }
  36864. // recalculate distances because they are not necessarely correct
  36865. // for scaled objects.
  36866. // see https://github.com/mrdoob/three.js/issues/5827
  36867. // TODO: remove this once the bug has been fixed
  36868. for (let i = 0; i < intersects.length; i++) {
  36869. let I = intersects[i];
  36870. I.distance = raycaster.ray.origin.distanceTo(I.point);
  36871. }
  36872. intersects.sort(function (a, b) { return a.distance - b.distance; });
  36873. };
  36874. get showCoordinates () {
  36875. return this._showCoordinates;
  36876. }
  36877. set showCoordinates (value) {
  36878. this._showCoordinates = value;
  36879. this.update();
  36880. }
  36881. get showAngles () {
  36882. return this._showAngles;
  36883. }
  36884. set showAngles (value) {
  36885. this._showAngles = value;
  36886. this.update();
  36887. }
  36888. get showCircle () {
  36889. return this._showCircle;
  36890. }
  36891. set showCircle (value) {
  36892. this._showCircle = value;
  36893. this.update();
  36894. }
  36895. get showAzimuth(){
  36896. return this._showAzimuth;
  36897. }
  36898. set showAzimuth(value){
  36899. this._showAzimuth = value;
  36900. this.update();
  36901. }
  36902. get showEdges () {
  36903. return this._showEdges;
  36904. }
  36905. set showEdges (value) {
  36906. this._showEdges = value;
  36907. this.update();
  36908. }
  36909. get showHeight () {
  36910. return this._showHeight;
  36911. }
  36912. set showHeight (value) {
  36913. this._showHeight = value;
  36914. this.update();
  36915. }
  36916. get showArea () {
  36917. return this._showArea;
  36918. }
  36919. set showArea (value) {
  36920. this._showArea = value;
  36921. this.update();
  36922. }
  36923. get closed () {
  36924. return this._closed;
  36925. }
  36926. set closed (value) {
  36927. this._closed = value;
  36928. this.update();
  36929. }
  36930. get showDistances () {
  36931. return this._showDistances;
  36932. }
  36933. set showDistances (value) {
  36934. this._showDistances = value;
  36935. this.update();
  36936. }
  36937. }
  36938. class PolygonClipVolume extends Object3D{
  36939. constructor(camera){
  36940. super();
  36941. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  36942. this.name = "polygon_clip_volume_" + this.constructor.counter;
  36943. this.camera = camera.clone();
  36944. this.camera.rotation.set(...camera.rotation.toArray()); // [r85] workaround because camera.clone() doesn't work on rotation
  36945. this.camera.rotation.order = camera.rotation.order;
  36946. this.camera.updateMatrixWorld();
  36947. this.camera.updateProjectionMatrix();
  36948. this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert();
  36949. this.viewMatrix = this.camera.matrixWorldInverse.clone();
  36950. this.projMatrix = this.camera.projectionMatrix.clone();
  36951. // projected markers
  36952. this.markers = [];
  36953. this.initialized = false;
  36954. }
  36955. addMarker() {
  36956. let marker = new Mesh();
  36957. let cancel;
  36958. let drag = e => {
  36959. let size = e.viewer.renderer.getSize(new Vector2());
  36960. let projectedPos = new Vector3(
  36961. 2.0 * (e.drag.end.x / size.width) - 1.0,
  36962. -2.0 * (e.drag.end.y / size.height) + 1.0,
  36963. 0
  36964. );
  36965. marker.position.copy(projectedPos);
  36966. };
  36967. let drop = e => {
  36968. cancel();
  36969. };
  36970. cancel = e => {
  36971. marker.removeEventListener("drag", drag);
  36972. marker.removeEventListener("drop", drop);
  36973. };
  36974. marker.addEventListener("drag", drag);
  36975. marker.addEventListener("drop", drop);
  36976. this.markers.push(marker);
  36977. }
  36978. removeLastMarker() {
  36979. if(this.markers.length > 0) {
  36980. this.markers.splice(this.markers.length - 1, 1);
  36981. }
  36982. }
  36983. };
  36984. class Utils {
  36985. static async loadShapefileFeatures (file, callback) {
  36986. let features = [];
  36987. let handleFinish = () => {
  36988. callback(features);
  36989. };
  36990. let source = await shapefile.open(file);
  36991. while(true){
  36992. let result = await source.read();
  36993. if (result.done) {
  36994. handleFinish();
  36995. break;
  36996. }
  36997. if (result.value && result.value.type === 'Feature' && result.value.geometry !== undefined) {
  36998. features.push(result.value);
  36999. }
  37000. }
  37001. }
  37002. static toString (value) {
  37003. if (value.x != null) {
  37004. return value.x.toFixed(2) + ', ' + value.y.toFixed(2) + ', ' + value.z.toFixed(2);
  37005. } else {
  37006. return '' + value + '';
  37007. }
  37008. }
  37009. static normalizeURL (url) {
  37010. let u = new URL(url);
  37011. return u.protocol + '//' + u.hostname + u.pathname.replace(/\/+/g, '/');
  37012. };
  37013. static pathExists (url) {
  37014. let req = XHRFactory.createXMLHttpRequest();
  37015. req.open('GET', url, false);
  37016. req.send(null);
  37017. if (req.status !== 200) {
  37018. return false;
  37019. }
  37020. return true;
  37021. };
  37022. static debugSphere(parent, position, scale, color){
  37023. let geometry = new SphereGeometry(1, 8, 8);
  37024. let material;
  37025. if(color !== undefined){
  37026. material = new MeshBasicMaterial({color: color});
  37027. }else {
  37028. material = new MeshNormalMaterial();
  37029. }
  37030. let sphere = new Mesh(geometry, material);
  37031. sphere.position.copy(position);
  37032. sphere.scale.set(scale, scale, scale);
  37033. parent.add(sphere);
  37034. return sphere;
  37035. }
  37036. static debugLine(parent, start, end, color){
  37037. let material = new LineBasicMaterial({ color: color });
  37038. let geometry = new Geometry();
  37039. const p1 = new Vector3(0, 0, 0);
  37040. const p2 = end.clone().sub(start);
  37041. geometry.vertices.push(p1, p2);
  37042. let tl = new Line( geometry, material );
  37043. tl.position.copy(start);
  37044. parent.add(tl);
  37045. let line = {
  37046. node: tl,
  37047. set: (start, end) => {
  37048. geometry.vertices[0].copy(start);
  37049. geometry.vertices[1].copy(end);
  37050. geometry.verticesNeedUpdate = true;
  37051. },
  37052. };
  37053. return line;
  37054. }
  37055. static debugCircle(parent, center, radius, normal, color){
  37056. let material = new LineBasicMaterial({ color: color });
  37057. let geometry = new Geometry();
  37058. let n = 32;
  37059. for(let i = 0; i <= n; i++){
  37060. let u0 = 2 * Math.PI * (i / n);
  37061. let u1 = 2 * Math.PI * (i + 1) / n;
  37062. let p0 = new Vector3(
  37063. Math.cos(u0),
  37064. Math.sin(u0),
  37065. 0
  37066. );
  37067. let p1 = new Vector3(
  37068. Math.cos(u1),
  37069. Math.sin(u1),
  37070. 0
  37071. );
  37072. geometry.vertices.push(p0, p1);
  37073. }
  37074. let tl = new Line( geometry, material );
  37075. tl.position.copy(center);
  37076. tl.scale.set(radius, radius, radius);
  37077. parent.add(tl);
  37078. }
  37079. static debugBox(parent, box, transform = new Matrix4(), color = 0xFFFF00){
  37080. let vertices = [
  37081. [box.min.x, box.min.y, box.min.z],
  37082. [box.min.x, box.min.y, box.max.z],
  37083. [box.min.x, box.max.y, box.min.z],
  37084. [box.min.x, box.max.y, box.max.z],
  37085. [box.max.x, box.min.y, box.min.z],
  37086. [box.max.x, box.min.y, box.max.z],
  37087. [box.max.x, box.max.y, box.min.z],
  37088. [box.max.x, box.max.y, box.max.z],
  37089. ].map(v => new Vector3(...v));
  37090. let edges = [
  37091. [0, 4], [4, 5], [5, 1], [1, 0],
  37092. [2, 6], [6, 7], [7, 3], [3, 2],
  37093. [0, 2], [4, 6], [5, 7], [1, 3]
  37094. ];
  37095. let center = box.getCenter(new Vector3());
  37096. let centroids = [
  37097. {position: [box.min.x, center.y, center.z], color: 0xFF0000},
  37098. {position: [box.max.x, center.y, center.z], color: 0x880000},
  37099. {position: [center.x, box.min.y, center.z], color: 0x00FF00},
  37100. {position: [center.x, box.max.y, center.z], color: 0x008800},
  37101. {position: [center.x, center.y, box.min.z], color: 0x0000FF},
  37102. {position: [center.x, center.y, box.max.z], color: 0x000088},
  37103. ];
  37104. for(let vertex of vertices){
  37105. let pos = vertex.clone().applyMatrix4(transform);
  37106. Utils.debugSphere(parent, pos, 0.1, 0xFF0000);
  37107. }
  37108. for(let edge of edges){
  37109. let start = vertices[edge[0]].clone().applyMatrix4(transform);
  37110. let end = vertices[edge[1]].clone().applyMatrix4(transform);
  37111. Utils.debugLine(parent, start, end, color);
  37112. }
  37113. for(let centroid of centroids){
  37114. let pos = new Vector3(...centroid.position).applyMatrix4(transform);
  37115. Utils.debugSphere(parent, pos, 0.1, centroid.color);
  37116. }
  37117. }
  37118. static debugPlane(parent, plane, size = 1, color = 0x0000FF){
  37119. let planehelper = new PlaneHelper(plane, size, color);
  37120. parent.add(planehelper);
  37121. }
  37122. /**
  37123. * adapted from mhluska at https://github.com/mrdoob/three.js/issues/1561
  37124. */
  37125. static computeTransformedBoundingBox (box, transform) {
  37126. let vertices = [
  37127. new Vector3(box.min.x, box.min.y, box.min.z).applyMatrix4(transform),
  37128. new Vector3(box.min.x, box.min.y, box.min.z).applyMatrix4(transform),
  37129. new Vector3(box.max.x, box.min.y, box.min.z).applyMatrix4(transform),
  37130. new Vector3(box.min.x, box.max.y, box.min.z).applyMatrix4(transform),
  37131. new Vector3(box.min.x, box.min.y, box.max.z).applyMatrix4(transform),
  37132. new Vector3(box.min.x, box.max.y, box.max.z).applyMatrix4(transform),
  37133. new Vector3(box.max.x, box.max.y, box.min.z).applyMatrix4(transform),
  37134. new Vector3(box.max.x, box.min.y, box.max.z).applyMatrix4(transform),
  37135. new Vector3(box.max.x, box.max.y, box.max.z).applyMatrix4(transform)
  37136. ];
  37137. let boundingBox = new Box3();
  37138. boundingBox.setFromPoints(vertices);
  37139. return boundingBox;
  37140. };//感觉就是bound.applyMatrix4(transform)
  37141. /**
  37142. * add separators to large numbers
  37143. *
  37144. * @param nStr
  37145. * @returns
  37146. */
  37147. static addCommas (nStr) {
  37148. nStr += '';
  37149. let x = nStr.split('.');
  37150. let x1 = x[0];
  37151. let x2 = x.length > 1 ? '.' + x[1] : '';
  37152. let rgx = /(\d+)(\d{3})/;
  37153. while (rgx.test(x1)) {
  37154. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  37155. }
  37156. return x1 + x2;
  37157. };
  37158. static removeCommas (str) {
  37159. return str.replace(/,/g, '');
  37160. }
  37161. /**
  37162. * create worker from a string
  37163. *
  37164. * code from http://stackoverflow.com/questions/10343913/how-to-create-a-web-worker-from-a-string
  37165. */
  37166. static createWorker (code) {
  37167. let blob = new Blob([code], {type: 'application/javascript'});
  37168. let worker = new Worker(URL.createObjectURL(blob));
  37169. return worker;
  37170. };
  37171. static moveTo(scene, endPosition, endTarget){
  37172. let view = scene.view;
  37173. let camera = scene.getActiveCamera();
  37174. let animationDuration = 500;
  37175. let easing = TWEEN.Easing.Quartic.Out;
  37176. { // animate camera position
  37177. let tween = new TWEEN.Tween(view.position).to(endPosition, animationDuration);
  37178. tween.easing(easing);
  37179. tween.start();
  37180. }
  37181. { // animate camera target
  37182. let camTargetDistance = camera.position.distanceTo(endTarget);
  37183. let target = new Vector3().addVectors(
  37184. camera.position,
  37185. camera.getWorldDirection(new Vector3()).clone().multiplyScalar(camTargetDistance)
  37186. );
  37187. let tween = new TWEEN.Tween(target).to(endTarget, animationDuration);
  37188. tween.easing(easing);
  37189. tween.onUpdate(() => {
  37190. view.lookAt(target);
  37191. });
  37192. tween.onComplete(() => {
  37193. view.lookAt(target);
  37194. });
  37195. tween.start();
  37196. }
  37197. }
  37198. static loadSkybox (path) {
  37199. let parent = new Object3D("skybox_root");
  37200. let camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 100000);
  37201. camera.up.set(0, 0, 1);
  37202. let scene = new Scene();
  37203. let format = '.jpg';
  37204. let urls = [
  37205. path + 'px' + format, path + 'nx' + format,
  37206. path + 'py' + format, path + 'ny' + format,
  37207. path + 'pz' + format, path + 'nz' + format
  37208. ];
  37209. let materialArray = [];
  37210. {
  37211. for (let i = 0; i < 6; i++) {
  37212. let material = new MeshBasicMaterial({
  37213. map: null,
  37214. side: BackSide,
  37215. depthTest: false,
  37216. depthWrite: false,
  37217. color: 0x424556
  37218. });
  37219. materialArray.push(material);
  37220. let loader = new TextureLoader();
  37221. loader.load(urls[i],
  37222. function loaded (texture) {
  37223. material.map = texture;
  37224. material.needsUpdate = true;
  37225. material.color.setHex(0xffffff);
  37226. }, function progress (xhr) {
  37227. // console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  37228. }, function error (xhr) {
  37229. console.log('An error happened', xhr);
  37230. }
  37231. );
  37232. }
  37233. }
  37234. let skyGeometry = new BoxGeometry(700, 700, 700);
  37235. let skybox = new Mesh(skyGeometry, materialArray);
  37236. scene.add(skybox);
  37237. scene.traverse(n => n.frustumCulled = false);
  37238. // z up
  37239. scene.rotation.x = Math.PI / 2;
  37240. parent.children.push(camera);
  37241. camera.parent = parent;
  37242. return {camera, scene, parent};
  37243. };
  37244. static createGrid (width, length, spacing, color) {
  37245. let material = new LineBasicMaterial({
  37246. color: color || 0x888888
  37247. });
  37248. let geometry = new Geometry();
  37249. for (let i = 0; i <= length; i++) {
  37250. geometry.vertices.push(new Vector3(-(spacing * width) / 2, i * spacing - (spacing * length) / 2, 0));
  37251. geometry.vertices.push(new Vector3(+(spacing * width) / 2, i * spacing - (spacing * length) / 2, 0));
  37252. }
  37253. for (let i = 0; i <= width; i++) {
  37254. geometry.vertices.push(new Vector3(i * spacing - (spacing * width) / 2, -(spacing * length) / 2, 0));
  37255. geometry.vertices.push(new Vector3(i * spacing - (spacing * width) / 2, +(spacing * length) / 2, 0));
  37256. }
  37257. let line = new LineSegments(geometry, material, LinePieces);
  37258. line.receiveShadow = true;
  37259. return line;
  37260. }
  37261. static createBackgroundTexture (width, height) {
  37262. function gauss (x, y) {
  37263. return (1 / (2 * Math.PI)) * Math.exp(-(x * x + y * y) / 2);
  37264. };
  37265. // map.magFilter = THREE.NearestFilter;
  37266. let size = width * height;
  37267. let data = new Uint8Array(3 * size);
  37268. let chroma = [1, 1.5, 1.7];
  37269. let max = gauss(0, 0);
  37270. for (let x = 0; x < width; x++) {
  37271. for (let y = 0; y < height; y++) {
  37272. let u = 2 * (x / width) - 1;
  37273. let v = 2 * (y / height) - 1;
  37274. let i = x + width * y;
  37275. let d = gauss(2 * u, 2 * v) / max;
  37276. let r = (Math.random() + Math.random() + Math.random()) / 3;
  37277. r = (d * 0.5 + 0.5) * r * 0.03;
  37278. r = r * 0.4;
  37279. // d = Math.pow(d, 0.6);
  37280. data[3 * i + 0] = 255 * (d / 15 + 0.05 + r) * chroma[0];
  37281. data[3 * i + 1] = 255 * (d / 15 + 0.05 + r) * chroma[1];
  37282. data[3 * i + 2] = 255 * (d / 15 + 0.05 + r) * chroma[2];
  37283. }
  37284. }
  37285. let texture = new DataTexture(data, width, height, RGBFormat);
  37286. texture.needsUpdate = true;
  37287. return texture;
  37288. }
  37289. static getMousePointCloudIntersection (mouse, camera, viewer, pointclouds, params = {}) {
  37290. let renderer = viewer.renderer;
  37291. let nmouse = {
  37292. x: (mouse.x / renderer.domElement.clientWidth) * 2 - 1,
  37293. y: -(mouse.y / renderer.domElement.clientHeight) * 2 + 1
  37294. };
  37295. let pickParams = {};
  37296. if(params.pickClipped){
  37297. pickParams.pickClipped = params.pickClipped;
  37298. }
  37299. pickParams.x = mouse.x;
  37300. pickParams.y = renderer.domElement.clientHeight - mouse.y;
  37301. let raycaster = new Raycaster();
  37302. raycaster.setFromCamera(nmouse, camera);
  37303. let ray = raycaster.ray;
  37304. let selectedPointcloud = null;
  37305. let closestDistance = Infinity;
  37306. let closestIntersection = null;
  37307. let closestPoint = null;
  37308. for(let pointcloud of pointclouds){
  37309. let point = pointcloud.pick(viewer, camera, ray, pickParams);
  37310. if(!point){
  37311. continue;
  37312. }
  37313. let distance = camera.position.distanceTo(point.position);
  37314. if (distance < closestDistance) {
  37315. closestDistance = distance;
  37316. selectedPointcloud = pointcloud;
  37317. closestIntersection = point.position;
  37318. closestPoint = point;
  37319. }
  37320. }
  37321. if (selectedPointcloud) {
  37322. return {
  37323. location: closestIntersection,
  37324. distance: closestDistance,
  37325. pointcloud: selectedPointcloud,
  37326. point: closestPoint
  37327. };
  37328. } else {
  37329. return null;
  37330. }
  37331. }
  37332. static pixelsArrayToImage (pixels, width, height) {
  37333. let canvas = document.createElement('canvas');
  37334. canvas.width = width;
  37335. canvas.height = height;
  37336. let context = canvas.getContext('2d');
  37337. pixels = new pixels.constructor(pixels);
  37338. for (let i = 0; i < pixels.length; i++) {
  37339. pixels[i * 4 + 3] = 255;
  37340. }
  37341. let imageData = context.createImageData(width, height);
  37342. imageData.data.set(pixels);
  37343. context.putImageData(imageData, 0, 0);
  37344. let img = new Image();
  37345. img.src = canvas.toDataURL();
  37346. // img.style.transform = "scaleY(-1)";
  37347. return img;
  37348. }
  37349. static pixelsArrayToDataUrl(pixels, width, height) {
  37350. let canvas = document.createElement('canvas');
  37351. canvas.width = width;
  37352. canvas.height = height;
  37353. let context = canvas.getContext('2d');
  37354. pixels = new pixels.constructor(pixels);
  37355. for (let i = 0; i < pixels.length; i++) {
  37356. pixels[i * 4 + 3] = 255;
  37357. }
  37358. let imageData = context.createImageData(width, height);
  37359. imageData.data.set(pixels);
  37360. context.putImageData(imageData, 0, 0);
  37361. let dataURL = canvas.toDataURL();
  37362. return dataURL;
  37363. }
  37364. static pixelsArrayToCanvas(pixels, width, height){
  37365. let canvas = document.createElement('canvas');
  37366. canvas.width = width;
  37367. canvas.height = height;
  37368. let context = canvas.getContext('2d');
  37369. pixels = new pixels.constructor(pixels);
  37370. //for (let i = 0; i < pixels.length; i++) {
  37371. // pixels[i * 4 + 3] = 255;
  37372. //}
  37373. // flip vertically
  37374. let bytesPerLine = width * 4;
  37375. for(let i = 0; i < parseInt(height / 2); i++){
  37376. let j = height - i - 1;
  37377. let lineI = pixels.slice(i * bytesPerLine, i * bytesPerLine + bytesPerLine);
  37378. let lineJ = pixels.slice(j * bytesPerLine, j * bytesPerLine + bytesPerLine);
  37379. pixels.set(lineJ, i * bytesPerLine);
  37380. pixels.set(lineI, j * bytesPerLine);
  37381. }
  37382. let imageData = context.createImageData(width, height);
  37383. imageData.data.set(pixels);
  37384. context.putImageData(imageData, 0, 0);
  37385. return canvas;
  37386. }
  37387. static removeListeners(dispatcher, type){
  37388. if (dispatcher._listeners === undefined) {
  37389. return;
  37390. }
  37391. if (dispatcher._listeners[ type ]) {
  37392. delete dispatcher._listeners[ type ];
  37393. }
  37394. }
  37395. static mouseToRay(mouse, camera, width, height){
  37396. let normalizedMouse = {
  37397. x: (mouse.x / width) * 2 - 1,
  37398. y: -(mouse.y / height) * 2 + 1
  37399. };
  37400. let vector = new Vector3(normalizedMouse.x, normalizedMouse.y, 0.5);
  37401. let origin = camera.position.clone();
  37402. vector.unproject(camera);
  37403. let direction = new Vector3().subVectors(vector, origin).normalize();
  37404. let ray = new Ray(origin, direction);
  37405. return ray;
  37406. }
  37407. static projectedRadius(radius, camera, distance, screenWidth, screenHeight){
  37408. if(camera instanceof OrthographicCamera){
  37409. return Utils.projectedRadiusOrtho(radius, camera.projectionMatrix, screenWidth, screenHeight);
  37410. }else if(camera instanceof PerspectiveCamera){
  37411. return Utils.projectedRadiusPerspective(radius, camera.fov * Math.PI / 180, distance, screenHeight);
  37412. }else {
  37413. throw new Error("invalid parameters");
  37414. }
  37415. }
  37416. static projectedRadiusPerspective(radius, fov, distance, screenHeight) {
  37417. let projFactor = (1 / Math.tan(fov / 2)) / distance;
  37418. projFactor = projFactor * screenHeight / 2;
  37419. return radius * projFactor;
  37420. }
  37421. static projectedRadiusOrtho(radius, proj, screenWidth, screenHeight) {
  37422. let p1 = new Vector4(0);
  37423. let p2 = new Vector4(radius);
  37424. p1.applyMatrix4(proj);
  37425. p2.applyMatrix4(proj);
  37426. p1 = new Vector3(p1.x, p1.y, p1.z);
  37427. p2 = new Vector3(p2.x, p2.y, p2.z);
  37428. p1.x = (p1.x + 1.0) * 0.5 * screenWidth;
  37429. p1.y = (p1.y + 1.0) * 0.5 * screenHeight;
  37430. p2.x = (p2.x + 1.0) * 0.5 * screenWidth;
  37431. p2.y = (p2.y + 1.0) * 0.5 * screenHeight;
  37432. return p1.distanceTo(p2);
  37433. }
  37434. static topView(camera, node){
  37435. camera.position.set(0, 1, 0);
  37436. camera.rotation.set(-Math.PI / 2, 0, 0);
  37437. camera.zoomTo(node, 1);
  37438. }
  37439. static frontView (camera, node) {
  37440. camera.position.set(0, 0, 1);
  37441. camera.rotation.set(0, 0, 0);
  37442. camera.zoomTo(node, 1);
  37443. }
  37444. static leftView (camera, node) {
  37445. camera.position.set(-1, 0, 0);
  37446. camera.rotation.set(0, -Math.PI / 2, 0);
  37447. camera.zoomTo(node, 1);
  37448. }
  37449. static rightView (camera, node) {
  37450. camera.position.set(1, 0, 0);
  37451. camera.rotation.set(0, Math.PI / 2, 0);
  37452. camera.zoomTo(node, 1);
  37453. }
  37454. static findClosestGpsTime(target, viewer){
  37455. const start = performance.now();
  37456. const nodes = [];
  37457. for(const pc of viewer.scene.pointclouds){
  37458. nodes.push(pc.root);
  37459. for(const child of pc.root.children){
  37460. if(child){
  37461. nodes.push(child);
  37462. }
  37463. }
  37464. }
  37465. let closestNode = null;
  37466. let closestIndex = Infinity;
  37467. let closestDistance = Infinity;
  37468. let closestValue = 0;
  37469. for(const node of nodes){
  37470. const isOkay = node.geometryNode != null
  37471. && node.geometryNode.geometry != null
  37472. && node.sceneNode != null;
  37473. if(!isOkay){
  37474. continue;
  37475. }
  37476. let geometry = node.geometryNode.geometry;
  37477. let gpsTime = geometry.attributes["gps-time"];
  37478. let range = gpsTime.potree.range;
  37479. for(let i = 0; i < gpsTime.array.length; i++){
  37480. let value = gpsTime.array[i];
  37481. value = value * (range[1] - range[0]) + range[0];
  37482. const distance = Math.abs(target - value);
  37483. if(distance < closestDistance){
  37484. closestIndex = i;
  37485. closestDistance = distance;
  37486. closestValue = value;
  37487. closestNode = node;
  37488. //console.log("found a closer one: " + value);
  37489. }
  37490. }
  37491. }
  37492. const geometry = closestNode.geometryNode.geometry;
  37493. const position = new Vector3(
  37494. geometry.attributes.position.array[3 * closestIndex + 0],
  37495. geometry.attributes.position.array[3 * closestIndex + 1],
  37496. geometry.attributes.position.array[3 * closestIndex + 2],
  37497. );
  37498. position.applyMatrix4(closestNode.sceneNode.matrixWorld);
  37499. const end = performance.now();
  37500. const duration = (end - start);
  37501. console.log(`duration: ${duration.toFixed(3)}ms`);
  37502. return {
  37503. node: closestNode,
  37504. index: closestIndex,
  37505. position: position,
  37506. };
  37507. }
  37508. /**
  37509. *
  37510. * 0: no intersection
  37511. * 1: intersection
  37512. * 2: fully inside
  37513. */
  37514. static frustumSphereIntersection (frustum, sphere) {
  37515. let planes = frustum.planes;
  37516. let center = sphere.center;
  37517. let negRadius = -sphere.radius;
  37518. let minDistance = Number.MAX_VALUE;
  37519. for (let i = 0; i < 6; i++) {
  37520. let distance = planes[ i ].distanceToPoint(center);
  37521. if (distance < negRadius) {
  37522. return 0;
  37523. }
  37524. minDistance = Math.min(minDistance, distance);
  37525. }
  37526. return (minDistance >= sphere.radius) ? 2 : 1;
  37527. }
  37528. // code taken from three.js
  37529. // ImageUtils - generateDataTexture()
  37530. static generateDataTexture (width, height, color) {
  37531. let size = width * height;
  37532. let data = new Uint8Array(4 * width * height);
  37533. let r = Math.floor(color.r * 255);
  37534. let g = Math.floor(color.g * 255);
  37535. let b = Math.floor(color.b * 255);
  37536. for (let i = 0; i < size; i++) {
  37537. data[ i * 3 ] = r;
  37538. data[ i * 3 + 1 ] = g;
  37539. data[ i * 3 + 2 ] = b;
  37540. }
  37541. let texture = new DataTexture(data, width, height, RGBAFormat);
  37542. texture.needsUpdate = true;
  37543. texture.magFilter = NearestFilter;
  37544. return texture;
  37545. }
  37546. // from http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript
  37547. static getParameterByName (name) {
  37548. name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
  37549. let regex = new RegExp('[\\?&]' + name + '=([^&#]*)');
  37550. let results = regex.exec(document.location.search);
  37551. return results === null ? null : decodeURIComponent(results[1].replace(/\+/g, ' '));
  37552. }
  37553. static setParameter (name, value) {
  37554. // value = encodeURIComponent(value);
  37555. name = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
  37556. let regex = new RegExp('([\\?&])(' + name + '=([^&#]*))');
  37557. let results = regex.exec(document.location.search);
  37558. let url = window.location.href;
  37559. if (results === null) {
  37560. if (window.location.search.length === 0) {
  37561. url = url + '?';
  37562. } else {
  37563. url = url + '&';
  37564. }
  37565. url = url + name + '=' + value;
  37566. } else {
  37567. let newValue = name + '=' + value;
  37568. url = url.replace(results[2], newValue);
  37569. }
  37570. window.history.replaceState({}, '', url);
  37571. }
  37572. static createChildAABB(aabb, index){
  37573. let min = aabb.min.clone();
  37574. let max = aabb.max.clone();
  37575. let size = new Vector3().subVectors(max, min);
  37576. if ((index & 0b0001) > 0) {
  37577. min.z += size.z / 2;
  37578. } else {
  37579. max.z -= size.z / 2;
  37580. }
  37581. if ((index & 0b0010) > 0) {
  37582. min.y += size.y / 2;
  37583. } else {
  37584. max.y -= size.y / 2;
  37585. }
  37586. if ((index & 0b0100) > 0) {
  37587. min.x += size.x / 2;
  37588. } else {
  37589. max.x -= size.x / 2;
  37590. }
  37591. return new Box3(min, max);
  37592. }
  37593. // see https://stackoverflow.com/questions/400212/how-do-i-copy-to-the-clipboard-in-javascript
  37594. static clipboardCopy(text){
  37595. let textArea = document.createElement("textarea");
  37596. textArea.style.position = 'fixed';
  37597. textArea.style.top = 0;
  37598. textArea.style.left = 0;
  37599. textArea.style.width = '2em';
  37600. textArea.style.height = '2em';
  37601. textArea.style.padding = 0;
  37602. textArea.style.border = 'none';
  37603. textArea.style.outline = 'none';
  37604. textArea.style.boxShadow = 'none';
  37605. textArea.style.background = 'transparent';
  37606. textArea.value = text;
  37607. document.body.appendChild(textArea);
  37608. textArea.select();
  37609. try {
  37610. let success = document.execCommand('copy');
  37611. if(success){
  37612. console.log("copied text to clipboard");
  37613. }else {
  37614. console.log("copy to clipboard failed");
  37615. }
  37616. } catch (err) {
  37617. console.log("error while trying to copy to clipboard");
  37618. }
  37619. document.body.removeChild(textArea);
  37620. }
  37621. static getMeasurementIcon(measurement){
  37622. if (measurement instanceof Measure) {
  37623. if (measurement.showDistances && !measurement.showArea && !measurement.showAngles) {
  37624. return `${Potree.resourcePath}/icons/distance.svg`;
  37625. } else if (measurement.showDistances && measurement.showArea && !measurement.showAngles) {
  37626. return `${Potree.resourcePath}/icons/area.svg`;
  37627. } else if (measurement.maxMarkers === 1) {
  37628. return `${Potree.resourcePath}/icons/point.svg`;
  37629. } else if (!measurement.showDistances && !measurement.showArea && measurement.showAngles) {
  37630. return `${Potree.resourcePath}/icons/angle.png`;
  37631. } else if (measurement.showHeight) {
  37632. return `${Potree.resourcePath}/icons/height.svg`;
  37633. } else {
  37634. return `${Potree.resourcePath}/icons/distance.svg`;
  37635. }
  37636. } else if (measurement instanceof Profile) {
  37637. return `${Potree.resourcePath}/icons/profile.svg`;
  37638. } else if (measurement instanceof Volume) {
  37639. return `${Potree.resourcePath}/icons/volume.svg`;
  37640. } else if (measurement instanceof PolygonClipVolume) {
  37641. return `${Potree.resourcePath}/icons/clip-polygon.svg`;
  37642. }
  37643. }
  37644. static lineToLineIntersection(P0, P1, P2, P3){
  37645. const P = [P0, P1, P2, P3];
  37646. const d = (m, n, o, p) => {
  37647. let result =
  37648. (P[m].x - P[n].x) * (P[o].x - P[p].x)
  37649. + (P[m].y - P[n].y) * (P[o].y - P[p].y)
  37650. + (P[m].z - P[n].z) * (P[o].z - P[p].z);
  37651. return result;
  37652. };
  37653. const mua = (d(0, 2, 3, 2) * d(3, 2, 1, 0) - d(0, 2, 1, 0) * d(3, 2, 3, 2))
  37654. /**-----------------------------------------------------------------**/ /
  37655. (d(1, 0, 1, 0) * d(3, 2, 3, 2) - d(3, 2, 1, 0) * d(3, 2, 1, 0));
  37656. const mub = (d(0, 2, 3, 2) + mua * d(3, 2, 1, 0))
  37657. /**--------------------------------------**/ /
  37658. d(3, 2, 3, 2);
  37659. const P01 = P1.clone().sub(P0);
  37660. const P23 = P3.clone().sub(P2);
  37661. const Pa = P0.clone().add(P01.multiplyScalar(mua));
  37662. const Pb = P2.clone().add(P23.multiplyScalar(mub));
  37663. const center = Pa.clone().add(Pb).multiplyScalar(0.5);
  37664. return center;
  37665. }
  37666. static computeCircleCenter(A, B, C){
  37667. const AB = B.clone().sub(A);
  37668. const AC = C.clone().sub(A);
  37669. const N = AC.clone().cross(AB).normalize();
  37670. const ab_dir = AB.clone().cross(N).normalize();
  37671. const ac_dir = AC.clone().cross(N).normalize();
  37672. const ab_origin = A.clone().add(B).multiplyScalar(0.5);
  37673. const ac_origin = A.clone().add(C).multiplyScalar(0.5);
  37674. const P0 = ab_origin;
  37675. const P1 = ab_origin.clone().add(ab_dir);
  37676. const P2 = ac_origin;
  37677. const P3 = ac_origin.clone().add(ac_dir);
  37678. const center = Utils.lineToLineIntersection(P0, P1, P2, P3);
  37679. return center;
  37680. // Potree.Utils.debugLine(viewer.scene.scene, P0, P1, 0x00ff00);
  37681. // Potree.Utils.debugLine(viewer.scene.scene, P2, P3, 0x0000ff);
  37682. // Potree.Utils.debugSphere(viewer.scene.scene, center, 0.03, 0xff00ff);
  37683. // const radius = center.distanceTo(A);
  37684. // Potree.Utils.debugCircle(viewer.scene.scene, center, radius, new THREE.Vector3(0, 0, 1), 0xff00ff);
  37685. }
  37686. static getNorthVec(p1, distance, projection){
  37687. if(projection){
  37688. // if there is a projection, transform coordinates to WGS84
  37689. // and compute angle to north there
  37690. proj4.defs("pointcloud", projection);
  37691. const transform = proj4("pointcloud", "WGS84");
  37692. const llP1 = transform.forward(p1.toArray());
  37693. let llP2 = transform.forward([p1.x, p1.y + distance]);
  37694. const polarRadius = Math.sqrt((llP2[0] - llP1[0]) ** 2 + (llP2[1] - llP1[1]) ** 2);
  37695. llP2 = [llP1[0], llP1[1] + polarRadius];
  37696. const northVec = transform.inverse(llP2);
  37697. return new Vector3(...northVec, p1.z).sub(p1);
  37698. }else {
  37699. // if there is no projection, assume [0, 1, 0] as north direction
  37700. const vec = new Vector3(0, 1, 0).multiplyScalar(distance);
  37701. return vec;
  37702. }
  37703. }
  37704. static computeAzimuth(p1, p2, projection){
  37705. let azimuth = 0;
  37706. if(projection){
  37707. // if there is a projection, transform coordinates to WGS84
  37708. // and compute angle to north there
  37709. let transform;
  37710. if (projection.includes('EPSG')) {
  37711. transform = proj4(projection, "WGS84");
  37712. } else {
  37713. proj4.defs("pointcloud", projection);
  37714. transform = proj4("pointcloud", "WGS84");
  37715. }
  37716. const llP1 = transform.forward(p1.toArray());
  37717. const llP2 = transform.forward(p2.toArray());
  37718. const dir = [
  37719. llP2[0] - llP1[0],
  37720. llP2[1] - llP1[1],
  37721. ];
  37722. azimuth = Math.atan2(dir[1], dir[0]) - Math.PI / 2;
  37723. }else {
  37724. // if there is no projection, assume [0, 1, 0] as north direction
  37725. const dir = [p2.x - p1.x, p2.y - p1.y];
  37726. azimuth = Math.atan2(dir[1], dir[0]) - Math.PI / 2;
  37727. }
  37728. // make clockwise
  37729. azimuth = -azimuth;
  37730. return azimuth;
  37731. }
  37732. static async loadScript(url){
  37733. return new Promise( resolve => {
  37734. const element = document.getElementById(url);
  37735. if(element){
  37736. resolve();
  37737. }else {
  37738. const script = document.createElement("script");
  37739. script.id = url;
  37740. script.onload = () => {
  37741. resolve();
  37742. };
  37743. script.src = url;
  37744. document.body.appendChild(script);
  37745. }
  37746. });
  37747. }
  37748. static createSvgGradient(scheme){
  37749. // this is what we are creating:
  37750. //
  37751. //<svg width="1em" height="3em" xmlns="http://www.w3.org/2000/svg">
  37752. // <defs>
  37753. // <linearGradient id="gradientID" gradientTransform="rotate(90)">
  37754. // <stop offset="0%" stop-color="rgb(93, 78, 162)" />
  37755. // ...
  37756. // <stop offset="100%" stop-color="rgb(157, 0, 65)" />
  37757. // </linearGradient>
  37758. // </defs>
  37759. //
  37760. // <rect width="100%" height="100%" fill="url('#myGradient')" stroke="black" stroke-width="0.1em"/>
  37761. //</svg>
  37762. const gradientId = `${Math.random()}_${Date.now()}`;
  37763. const svgn = "http://www.w3.org/2000/svg";
  37764. const svg = document.createElementNS(svgn, "svg");
  37765. svg.setAttributeNS(null, "width", "2em");
  37766. svg.setAttributeNS(null, "height", "3em");
  37767. { // <defs>
  37768. const defs = document.createElementNS(svgn, "defs");
  37769. const linearGradient = document.createElementNS(svgn, "linearGradient");
  37770. linearGradient.setAttributeNS(null, "id", gradientId);
  37771. linearGradient.setAttributeNS(null, "gradientTransform", "rotate(90)");
  37772. for(let i = scheme.length - 1; i >= 0; i--){
  37773. const stopVal = scheme[i];
  37774. const percent = parseInt(100 - stopVal[0] * 100);
  37775. const [r, g, b] = stopVal[1].toArray().map(v => parseInt(v * 255));
  37776. const stop = document.createElementNS(svgn, "stop");
  37777. stop.setAttributeNS(null, "offset", `${percent}%`);
  37778. stop.setAttributeNS(null, "stop-color", `rgb(${r}, ${g}, ${b})`);
  37779. linearGradient.appendChild(stop);
  37780. }
  37781. defs.appendChild(linearGradient);
  37782. svg.appendChild(defs);
  37783. }
  37784. const rect = document.createElementNS(svgn, "rect");
  37785. rect.setAttributeNS(null, "width", `100%`);
  37786. rect.setAttributeNS(null, "height", `100%`);
  37787. rect.setAttributeNS(null, "fill", `url("#${gradientId}")`);
  37788. rect.setAttributeNS(null, "stroke", `black`);
  37789. rect.setAttributeNS(null, "stroke-width", `0.1em`);
  37790. svg.appendChild(rect);
  37791. return svg;
  37792. }
  37793. static async waitAny(promises){
  37794. return new Promise( (resolve) => {
  37795. promises.map( promise => {
  37796. promise.then( () => {
  37797. resolve();
  37798. });
  37799. });
  37800. });
  37801. }
  37802. }
  37803. Utils.screenPass = new function () {
  37804. this.screenScene = new Scene();
  37805. this.screenQuad = new Mesh(new PlaneBufferGeometry(2, 2, 1));
  37806. this.screenQuad.material.depthTest = true;
  37807. this.screenQuad.material.depthWrite = true;
  37808. this.screenQuad.material.transparent = true;
  37809. this.screenScene.add(this.screenQuad);
  37810. this.camera = new Camera();
  37811. this.render = function (renderer, material, target) {
  37812. this.screenQuad.material = material;
  37813. if (typeof target === 'undefined') {
  37814. renderer.render(this.screenScene, this.camera);
  37815. } else {
  37816. renderer.render(this.screenScene, this.camera, target);
  37817. }
  37818. };
  37819. }();
  37820. class Version{
  37821. constructor(version){
  37822. this.version = version;
  37823. let vmLength = (version.indexOf('.') === -1) ? version.length : version.indexOf('.');
  37824. this.versionMajor = parseInt(version.substr(0, vmLength));
  37825. this.versionMinor = parseInt(version.substr(vmLength + 1));
  37826. if (this.versionMinor.length === 0) {
  37827. this.versionMinor = 0;
  37828. }
  37829. }
  37830. newerThan(version){
  37831. let v = new Version(version);
  37832. if (this.versionMajor > v.versionMajor) {
  37833. return true;
  37834. } else if (this.versionMajor === v.versionMajor && this.versionMinor > v.versionMinor) {
  37835. return true;
  37836. } else {
  37837. return false;
  37838. }
  37839. }
  37840. equalOrHigher(version){
  37841. let v = new Version(version);
  37842. if (this.versionMajor > v.versionMajor) {
  37843. return true;
  37844. } else if (this.versionMajor === v.versionMajor && this.versionMinor >= v.versionMinor) {
  37845. return true;
  37846. } else {
  37847. return false;
  37848. }
  37849. }
  37850. upTo(version){
  37851. return !this.newerThan(version);
  37852. }
  37853. }
  37854. //加载 解析点云
  37855. class BinaryLoader{
  37856. constructor(version, boundingBox, scale){
  37857. if (typeof (version) === 'string') {
  37858. this.version = new Version(version);
  37859. } else {
  37860. this.version = version;
  37861. }
  37862. this.boundingBox = boundingBox;
  37863. this.scale = scale;
  37864. }
  37865. load(node){
  37866. if (node.loaded) {
  37867. return;
  37868. }
  37869. let url = node.getURL();
  37870. if (this.version.equalOrHigher('1.4')) {
  37871. url += '.bin';
  37872. }
  37873. let xhr = XHRFactory.createXMLHttpRequest();
  37874. xhr.open('GET', url, true);
  37875. xhr.responseType = 'arraybuffer';
  37876. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  37877. xhr.onreadystatechange = () => {
  37878. if (xhr.readyState === 4) {
  37879. if((xhr.status === 200 || xhr.status === 0) && xhr.response !== null){
  37880. let buffer = xhr.response;
  37881. this.parse(node, buffer);
  37882. } else {
  37883. //console.error(`Failed to load file! HTTP status: ${xhr.status}, file: ${url}`);
  37884. throw new Error(`Failed to load file! HTTP status: ${xhr.status}, file: ${url}`);
  37885. }
  37886. }
  37887. };
  37888. try {
  37889. xhr.send(null);
  37890. } catch (e) {
  37891. console.log('fehler beim laden der punktwolke: ' + e);
  37892. }
  37893. };
  37894. parse(node, buffer, callback){
  37895. let pointAttributes = node.pcoGeometry.pointAttributes;
  37896. let numPoints = buffer.byteLength / node.pcoGeometry.pointAttributes.byteSize;
  37897. if (this.version.upTo('1.5')) {
  37898. node.numPoints = numPoints;
  37899. }
  37900. let workerPath = Potree.scriptPath + '/workers/BinaryDecoderWorker.js';
  37901. let worker = Potree.workerPool.getWorker(workerPath);
  37902. worker.onmessage = function (e) {
  37903. let data = e.data;
  37904. let buffers = data.attributeBuffers;
  37905. let tightBoundingBox = new Box3(
  37906. new Vector3().fromArray(data.tightBoundingBox.min),
  37907. new Vector3().fromArray(data.tightBoundingBox.max)
  37908. );
  37909. Potree.workerPool.returnWorker(workerPath, worker);
  37910. let geometry = new BufferGeometry();
  37911. for(let property in buffers){
  37912. let buffer = buffers[property].buffer;
  37913. let batchAttribute = buffers[property].attribute;
  37914. if (property === "POSITION_CARTESIAN") {
  37915. geometry.setAttribute('position', new BufferAttribute(new Float32Array(buffer), 3));
  37916. } else if (property === "rgba") {
  37917. geometry.setAttribute("rgba", new BufferAttribute(new Uint8Array(buffer), 4, true));
  37918. } else if (property === "NORMAL_SPHEREMAPPED") {
  37919. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  37920. } else if (property === "NORMAL_OCT16") {
  37921. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  37922. } else if (property === "NORMAL") {
  37923. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  37924. } else if (property === "INDICES") {
  37925. let bufferAttribute = new BufferAttribute(new Uint8Array(buffer), 4);
  37926. bufferAttribute.normalized = true;
  37927. geometry.setAttribute('indices', bufferAttribute);
  37928. } else if (property === "SPACING") {
  37929. let bufferAttribute = new BufferAttribute(new Float32Array(buffer), 1);
  37930. geometry.setAttribute('spacing', bufferAttribute);
  37931. } else {
  37932. const bufferAttribute = new BufferAttribute(new Float32Array(buffer), 1);
  37933. bufferAttribute.potree = {
  37934. offset: buffers[property].offset,
  37935. scale: buffers[property].scale,
  37936. preciseBuffer: buffers[property].preciseBuffer,
  37937. range: batchAttribute.range,
  37938. };
  37939. geometry.setAttribute(property, bufferAttribute);
  37940. const attribute = pointAttributes.attributes.find(a => a.name === batchAttribute.name);
  37941. attribute.range[0] = Math.min(attribute.range[0], batchAttribute.range[0]);
  37942. attribute.range[1] = Math.max(attribute.range[1], batchAttribute.range[1]);
  37943. if(node.getLevel() === 0){
  37944. attribute.initialRange = batchAttribute.range;
  37945. }
  37946. }
  37947. }
  37948. tightBoundingBox.max.sub(tightBoundingBox.min);
  37949. tightBoundingBox.min.set(0, 0, 0);
  37950. let numPoints = e.data.buffer.byteLength / pointAttributes.byteSize;
  37951. node.numPoints = numPoints;
  37952. node.geometry = geometry;
  37953. node.mean = new Vector3(...data.mean);
  37954. node.tightBoundingBox = tightBoundingBox;
  37955. node.loaded = true;
  37956. node.loading = false;
  37957. node.estimatedSpacing = data.estimatedSpacing;
  37958. Potree.numNodesLoading--;
  37959. callback();//add
  37960. };
  37961. let message = {
  37962. buffer: buffer,
  37963. pointAttributes: pointAttributes,
  37964. version: this.version.version,
  37965. min: [ node.boundingBox.min.x, node.boundingBox.min.y, node.boundingBox.min.z ],
  37966. offset: [node.pcoGeometry.offset.x, node.pcoGeometry.offset.y, node.pcoGeometry.offset.z],
  37967. scale: this.scale,
  37968. spacing: node.spacing,
  37969. hasChildren: node.hasChildren,
  37970. name: node.name
  37971. };
  37972. worker.postMessage(message, [message.buffer]);
  37973. };
  37974. }
  37975. let ftCanvas = document.createElement('canvas');
  37976. const Features = (function () {
  37977. let gl = ftCanvas.getContext('webgl') || ftCanvas.getContext('experimental-webgl');
  37978. if (gl === null){
  37979. return {};
  37980. }
  37981. // -- code taken from THREE.WebGLRenderer --
  37982. let _vertexShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.HIGH_FLOAT);
  37983. let _vertexShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.MEDIUM_FLOAT);
  37984. // Unused: let _vertexShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat(gl.VERTEX_SHADER, gl.LOW_FLOAT);
  37985. let _fragmentShaderPrecisionHighpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.HIGH_FLOAT);
  37986. let _fragmentShaderPrecisionMediumpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT);
  37987. // Unused: let _fragmentShaderPrecisionLowpFloat = gl.getShaderPrecisionFormat(gl.FRAGMENT_SHADER, gl.LOW_FLOAT);
  37988. let highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  37989. let mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  37990. // -----------------------------------------
  37991. let precision;
  37992. if (highpAvailable) {
  37993. precision = 'highp';
  37994. } else if (mediumpAvailable) {
  37995. precision = 'mediump';
  37996. } else {
  37997. precision = 'lowp';
  37998. }
  37999. return {
  38000. SHADER_INTERPOLATION: {
  38001. isSupported: function () {
  38002. let supported = true;
  38003. supported = supported && gl.getExtension('EXT_frag_depth');
  38004. supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
  38005. return supported;
  38006. }
  38007. },
  38008. SHADER_SPLATS: {
  38009. isSupported: function () {
  38010. let supported = true;
  38011. supported = supported && gl.getExtension('EXT_frag_depth');
  38012. supported = supported && gl.getExtension('OES_texture_float');
  38013. supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
  38014. return supported;
  38015. }
  38016. },
  38017. SHADER_EDL: {
  38018. isSupported: function () {
  38019. let supported = true;
  38020. supported = supported && gl.getExtension('EXT_frag_depth');
  38021. supported = supported && gl.getExtension('OES_texture_float');
  38022. supported = supported && gl.getParameter(gl.MAX_VARYING_VECTORS) >= 8;
  38023. //supported = supported || (gl instanceof WebGL2RenderingContext);
  38024. return supported;
  38025. }
  38026. },
  38027. //WEBGL2: {
  38028. // isSupported: function(){
  38029. // return typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext;
  38030. // }
  38031. //},
  38032. precision: precision
  38033. };
  38034. }());
  38035. /**
  38036. * Some types of possible point attribute data formats
  38037. *
  38038. * @class
  38039. */
  38040. const PointAttributeTypes = {
  38041. DATA_TYPE_DOUBLE: {ordinal: 0, name: "double", size: 8},
  38042. DATA_TYPE_FLOAT: {ordinal: 1, name: "float", size: 4},
  38043. DATA_TYPE_INT8: {ordinal: 2, name: "int8", size: 1},
  38044. DATA_TYPE_UINT8: {ordinal: 3, name: "uint8", size: 1},
  38045. DATA_TYPE_INT16: {ordinal: 4, name: "int16", size: 2},
  38046. DATA_TYPE_UINT16: {ordinal: 5, name: "uint16", size: 2},
  38047. DATA_TYPE_INT32: {ordinal: 6, name: "int32", size: 4},
  38048. DATA_TYPE_UINT32: {ordinal: 7, name: "uint32", size: 4},
  38049. DATA_TYPE_INT64: {ordinal: 8, name: "int64", size: 8},
  38050. DATA_TYPE_UINT64: {ordinal: 9, name: "uint64", size: 8}
  38051. };
  38052. let i = 0;
  38053. for (let obj in PointAttributeTypes) {
  38054. PointAttributeTypes[i] = PointAttributeTypes[obj];
  38055. i++;
  38056. }
  38057. class PointAttribute{
  38058. constructor(name, type, numElements){
  38059. this.name = name;
  38060. this.type = type;
  38061. this.numElements = numElements;
  38062. this.byteSize = this.numElements * this.type.size;
  38063. this.description = "";
  38064. this.range = [Infinity, -Infinity];
  38065. }
  38066. };
  38067. PointAttribute.POSITION_CARTESIAN = new PointAttribute(
  38068. "POSITION_CARTESIAN", PointAttributeTypes.DATA_TYPE_FLOAT, 3);
  38069. PointAttribute.RGBA_PACKED = new PointAttribute(
  38070. "COLOR_PACKED", PointAttributeTypes.DATA_TYPE_INT8, 4);
  38071. PointAttribute.COLOR_PACKED = PointAttribute.RGBA_PACKED;
  38072. PointAttribute.RGB_PACKED = new PointAttribute(
  38073. "COLOR_PACKED", PointAttributeTypes.DATA_TYPE_INT8, 3);
  38074. PointAttribute.NORMAL_FLOATS = new PointAttribute(
  38075. "NORMAL_FLOATS", PointAttributeTypes.DATA_TYPE_FLOAT, 3);
  38076. PointAttribute.INTENSITY = new PointAttribute(
  38077. "INTENSITY", PointAttributeTypes.DATA_TYPE_UINT16, 1);
  38078. PointAttribute.CLASSIFICATION = new PointAttribute(
  38079. "CLASSIFICATION", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  38080. PointAttribute.NORMAL_SPHEREMAPPED = new PointAttribute(
  38081. "NORMAL_SPHEREMAPPED", PointAttributeTypes.DATA_TYPE_UINT8, 2);
  38082. PointAttribute.NORMAL_OCT16 = new PointAttribute(
  38083. "NORMAL_OCT16", PointAttributeTypes.DATA_TYPE_UINT8, 2);
  38084. PointAttribute.NORMAL = new PointAttribute(
  38085. "NORMAL", PointAttributeTypes.DATA_TYPE_FLOAT, 3);
  38086. PointAttribute.RETURN_NUMBER = new PointAttribute(
  38087. "RETURN_NUMBER", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  38088. PointAttribute.NUMBER_OF_RETURNS = new PointAttribute(
  38089. "NUMBER_OF_RETURNS", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  38090. PointAttribute.SOURCE_ID = new PointAttribute(
  38091. "SOURCE_ID", PointAttributeTypes.DATA_TYPE_UINT16, 1);
  38092. PointAttribute.INDICES = new PointAttribute(
  38093. "INDICES", PointAttributeTypes.DATA_TYPE_UINT32, 1);
  38094. PointAttribute.SPACING = new PointAttribute(
  38095. "SPACING", PointAttributeTypes.DATA_TYPE_FLOAT, 1);
  38096. PointAttribute.GPS_TIME = new PointAttribute(
  38097. "GPS_TIME", PointAttributeTypes.DATA_TYPE_DOUBLE, 1);
  38098. class PointAttributes{
  38099. constructor(pointAttributes){
  38100. this.attributes = [];
  38101. this.byteSize = 0;
  38102. this.size = 0;
  38103. this.vectors = [];
  38104. if (pointAttributes != null) {
  38105. for (let i = 0; i < pointAttributes.length; i++) {
  38106. let pointAttributeName = pointAttributes[i];
  38107. let pointAttribute = PointAttribute[pointAttributeName];
  38108. this.attributes.push(pointAttribute);
  38109. this.byteSize += pointAttribute.byteSize;
  38110. this.size++;
  38111. }
  38112. }
  38113. }
  38114. add(pointAttribute){
  38115. this.attributes.push(pointAttribute);
  38116. this.byteSize += pointAttribute.byteSize;
  38117. this.size++;
  38118. };
  38119. addVector(vector){
  38120. this.vectors.push(vector);
  38121. }
  38122. hasNormals(){
  38123. for (let name in this.attributes) {
  38124. let pointAttribute = this.attributes[name];
  38125. if (
  38126. pointAttribute === PointAttribute.NORMAL_SPHEREMAPPED ||
  38127. pointAttribute === PointAttribute.NORMAL_FLOATS ||
  38128. pointAttribute === PointAttribute.NORMAL ||
  38129. pointAttribute === PointAttribute.NORMAL_OCT16) {
  38130. return true;
  38131. }
  38132. }
  38133. return false;
  38134. };
  38135. }
  38136. class Points$1 {
  38137. constructor () {
  38138. this.boundingBox = new Box3();
  38139. this.numPoints = 0;
  38140. this.data = {};
  38141. }
  38142. add (points) {
  38143. let currentSize = this.numPoints;
  38144. let additionalSize = points.numPoints;
  38145. let newSize = currentSize + additionalSize;
  38146. let thisAttributes = Object.keys(this.data);
  38147. let otherAttributes = Object.keys(points.data);
  38148. let attributes = new Set([...thisAttributes, ...otherAttributes]);
  38149. for (let attribute of attributes) {
  38150. if (thisAttributes.includes(attribute) && otherAttributes.includes(attribute)) {
  38151. // attribute in both, merge
  38152. let Type = this.data[attribute].constructor;
  38153. let merged = new Type(this.data[attribute].length + points.data[attribute].length);
  38154. merged.set(this.data[attribute], 0);
  38155. merged.set(points.data[attribute], this.data[attribute].length);
  38156. this.data[attribute] = merged;
  38157. } else if (thisAttributes.includes(attribute) && !otherAttributes.includes(attribute)) {
  38158. // attribute only in this; take over this and expand to new size
  38159. let elementsPerPoint = this.data[attribute].length / this.numPoints;
  38160. let Type = this.data[attribute].constructor;
  38161. let expanded = new Type(elementsPerPoint * newSize);
  38162. expanded.set(this.data[attribute], 0);
  38163. this.data[attribute] = expanded;
  38164. } else if (!thisAttributes.includes(attribute) && otherAttributes.includes(attribute)) {
  38165. // attribute only in points to be added; take over new points and expand to new size
  38166. let elementsPerPoint = points.data[attribute].length / points.numPoints;
  38167. let Type = points.data[attribute].constructor;
  38168. let expanded = new Type(elementsPerPoint * newSize);
  38169. expanded.set(points.data[attribute], elementsPerPoint * currentSize);
  38170. this.data[attribute] = expanded;
  38171. }
  38172. }
  38173. this.numPoints = newSize;
  38174. this.boundingBox.union(points.boundingBox);
  38175. }
  38176. }
  38177. class CSVExporter {
  38178. static toString (points) {
  38179. let string = '';
  38180. let attributes = Object.keys(points.data)
  38181. .filter(a => a !== 'normal')
  38182. .sort((a, b) => {
  38183. if (a === 'position') return -1;
  38184. if (b === 'position') return 1;
  38185. if (a === 'rgba') return -1;
  38186. if (b === 'rgba') return 1;
  38187. });
  38188. let headerValues = [];
  38189. for (let attribute of attributes) {
  38190. let itemSize = points.data[attribute].length / points.numPoints;
  38191. if (attribute === 'position') {
  38192. headerValues = headerValues.concat(['x', 'y', 'z']);
  38193. } else if (attribute === 'rgba') {
  38194. headerValues = headerValues.concat(['r', 'g', 'b', 'a']);
  38195. } else if (itemSize > 1) {
  38196. for (let i = 0; i < itemSize; i++) {
  38197. headerValues.push(`${attribute}_${i}`);
  38198. }
  38199. } else {
  38200. headerValues.push(attribute);
  38201. }
  38202. }
  38203. string = headerValues.join(', ') + '\n';
  38204. for (let i = 0; i < points.numPoints; i++) {
  38205. let values = [];
  38206. for (let attribute of attributes) {
  38207. let itemSize = points.data[attribute].length / points.numPoints;
  38208. let value = points.data[attribute]
  38209. .subarray(itemSize * i, itemSize * i + itemSize)
  38210. .join(', ');
  38211. values.push(value);
  38212. }
  38213. string += values.join(', ') + '\n';
  38214. }
  38215. return string;
  38216. }
  38217. };
  38218. class LASExporter {
  38219. static toLAS (points) {
  38220. // TODO Unused: let string = '';
  38221. let boundingBox = points.boundingBox;
  38222. let offset = boundingBox.min.clone();
  38223. let diagonal = boundingBox.min.distanceTo(boundingBox.max);
  38224. let scale = new Vector3(0.001, 0.001, 0.001);
  38225. if (diagonal > 1000 * 1000) {
  38226. scale = new Vector3(0.01, 0.01, 0.01);
  38227. } else {
  38228. scale = new Vector3(0.001, 0.001, 0.001);
  38229. }
  38230. let setString = function (string, offset, buffer) {
  38231. let view = new Uint8Array(buffer);
  38232. for (let i = 0; i < string.length; i++) {
  38233. let charCode = string.charCodeAt(i);
  38234. view[offset + i] = charCode;
  38235. }
  38236. };
  38237. let buffer = new ArrayBuffer(227 + 28 * points.numPoints);
  38238. let view = new DataView(buffer);
  38239. let u8View = new Uint8Array(buffer);
  38240. // let u16View = new Uint16Array(buffer);
  38241. setString('LASF', 0, buffer);
  38242. u8View[24] = 1;
  38243. u8View[25] = 2;
  38244. // system identifier o:26 l:32
  38245. // generating software o:58 l:32
  38246. setString('Potree 1.7', 58, buffer);
  38247. // file creation day of year o:90 l:2
  38248. // file creation year o:92 l:2
  38249. // header size o:94 l:2
  38250. view.setUint16(94, 227, true);
  38251. // offset to point data o:96 l:4
  38252. view.setUint32(96, 227, true);
  38253. // number of letiable length records o:100 l:4
  38254. // point data record format 104 1
  38255. u8View[104] = 2;
  38256. // point data record length 105 2
  38257. view.setUint16(105, 28, true);
  38258. // number of point records 107 4
  38259. view.setUint32(107, points.numPoints, true);
  38260. // number of points by return 111 20
  38261. // x scale factor 131 8
  38262. view.setFloat64(131, scale.x, true);
  38263. // y scale factor 139 8
  38264. view.setFloat64(139, scale.y, true);
  38265. // z scale factor 147 8
  38266. view.setFloat64(147, scale.z, true);
  38267. // x offset 155 8
  38268. view.setFloat64(155, offset.x, true);
  38269. // y offset 163 8
  38270. view.setFloat64(163, offset.y, true);
  38271. // z offset 171 8
  38272. view.setFloat64(171, offset.z, true);
  38273. // max x 179 8
  38274. view.setFloat64(179, boundingBox.max.x, true);
  38275. // min x 187 8
  38276. view.setFloat64(187, boundingBox.min.x, true);
  38277. // max y 195 8
  38278. view.setFloat64(195, boundingBox.max.y, true);
  38279. // min y 203 8
  38280. view.setFloat64(203, boundingBox.min.y, true);
  38281. // max z 211 8
  38282. view.setFloat64(211, boundingBox.max.z, true);
  38283. // min z 219 8
  38284. view.setFloat64(219, boundingBox.min.z, true);
  38285. let boffset = 227;
  38286. for (let i = 0; i < points.numPoints; i++) {
  38287. let px = points.data.position[3 * i + 0];
  38288. let py = points.data.position[3 * i + 1];
  38289. let pz = points.data.position[3 * i + 2];
  38290. let ux = parseInt((px - offset.x) / scale.x);
  38291. let uy = parseInt((py - offset.y) / scale.y);
  38292. let uz = parseInt((pz - offset.z) / scale.z);
  38293. view.setUint32(boffset + 0, ux, true);
  38294. view.setUint32(boffset + 4, uy, true);
  38295. view.setUint32(boffset + 8, uz, true);
  38296. if (points.data.intensity) {
  38297. view.setUint16(boffset + 12, (points.data.intensity[i]), true);
  38298. }
  38299. let rt = 0;
  38300. if (points.data.returnNumber) {
  38301. rt += points.data.returnNumber[i];
  38302. }
  38303. if (points.data.numberOfReturns) {
  38304. rt += (points.data.numberOfReturns[i] << 3);
  38305. }
  38306. view.setUint8(boffset + 14, rt);
  38307. if (points.data.classification) {
  38308. view.setUint8(boffset + 15, points.data.classification[i]);
  38309. }
  38310. // scan angle rank
  38311. // user data
  38312. // point source id
  38313. if (points.data.pointSourceID) {
  38314. view.setUint16(boffset + 18, points.data.pointSourceID[i]);
  38315. }
  38316. if (points.data.rgba) {
  38317. let rgba = points.data.rgba;
  38318. view.setUint16(boffset + 20, (rgba[4 * i + 0] * 255), true);
  38319. view.setUint16(boffset + 22, (rgba[4 * i + 1] * 255), true);
  38320. view.setUint16(boffset + 24, (rgba[4 * i + 2] * 255), true);
  38321. }
  38322. boffset += 28;
  38323. }
  38324. return buffer;
  38325. }
  38326. }
  38327. /**
  38328. * @author mrdoob / http://mrdoob.com/ https://github.com/mrdoob/eventdispatcher.js
  38329. *
  38330. * with slight modifications by mschuetz, http://potree.org
  38331. *
  38332. */
  38333. // The MIT License
  38334. //
  38335. // Copyright (c) 2011 Mr.doob
  38336. //
  38337. // Permission is hereby granted, free of charge, to any person obtaining a copy
  38338. // of this software and associated documentation files (the "Software"), to deal
  38339. // in the Software without restriction, including without limitation the rights
  38340. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  38341. // copies of the Software, and to permit persons to whom the Software is
  38342. // furnished to do so, subject to the following conditions:
  38343. //
  38344. // The above copyright notice and this permission notice shall be included in
  38345. // all copies or substantial portions of the Software.
  38346. //
  38347. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  38348. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  38349. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  38350. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  38351. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  38352. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  38353. // THE SOFTWARE.
  38354. class EventDispatcher$1{
  38355. constructor(){
  38356. this._listeners = {};
  38357. }
  38358. addEventListener(type, listener){
  38359. const listeners = this._listeners;
  38360. if(listeners[type] === undefined){
  38361. listeners[type] = [];
  38362. }
  38363. if(listeners[type].indexOf(listener) === - 1){
  38364. listeners[type].push( listener );
  38365. }
  38366. }
  38367. hasEventListener(type, listener){
  38368. const listeners = this._listeners;
  38369. return listeners[type] !== undefined && listeners[type].indexOf(listener) !== - 1;
  38370. }
  38371. removeEventListener(type, listener){
  38372. let listeners = this._listeners;
  38373. let listenerArray = listeners[type];
  38374. if (listenerArray !== undefined){
  38375. let index = listenerArray.indexOf(listener);
  38376. if(index !== - 1){
  38377. listenerArray.splice(index, 1);
  38378. }
  38379. }
  38380. }
  38381. removeEventListeners(type){
  38382. if(this._listeners[type] !== undefined){
  38383. delete this._listeners[type];
  38384. }
  38385. };
  38386. dispatchEvent(event){
  38387. let listeners = this._listeners;
  38388. let listenerArray = listeners[event.type];
  38389. if ( listenerArray !== undefined ) {
  38390. event.target = this;
  38391. for(let listener of listenerArray.slice(0)){
  38392. listener.call(this, event);
  38393. }
  38394. }
  38395. }
  38396. }
  38397. class PointCloudTreeNode extends EventDispatcher$1{
  38398. constructor(){
  38399. super();
  38400. this.needsTransformUpdate = true;
  38401. }
  38402. getChildren () {
  38403. throw new Error('override function');
  38404. }
  38405. getBoundingBox () {
  38406. throw new Error('override function');
  38407. }
  38408. isLoaded () {
  38409. throw new Error('override function');
  38410. }
  38411. isGeometryNode () {
  38412. throw new Error('override function');
  38413. }
  38414. isTreeNode () {
  38415. throw new Error('override function');
  38416. }
  38417. getLevel () {
  38418. throw new Error('override function');
  38419. }
  38420. getBoundingSphere () {
  38421. throw new Error('override function');
  38422. }
  38423. };
  38424. class PointCloudTree extends Object3D {
  38425. constructor () {
  38426. super();
  38427. //this.spriteGroup = new THREE.Object3D //add
  38428. }
  38429. initialized () {
  38430. return this.root !== null;
  38431. }
  38432. };
  38433. class PointCloudOctreeGeometry{
  38434. constructor(){
  38435. this.url = null;
  38436. this.octreeDir = null;
  38437. this.spacing = 0;
  38438. this.boundingBox = null;
  38439. this.root = null;
  38440. this.nodes = null;
  38441. this.pointAttributes = null;
  38442. this.hierarchyStepSize = -1;
  38443. this.loader = null;
  38444. }
  38445. }
  38446. class PointCloudOctreeGeometryNode extends PointCloudTreeNode{
  38447. constructor(name, pcoGeometry, boundingBox){
  38448. super();
  38449. this.id = PointCloudOctreeGeometryNode.IDCount++;
  38450. this.name = name;
  38451. this.index = parseInt(name.charAt(name.length - 1));
  38452. this.pcoGeometry = pcoGeometry;
  38453. this.geometry = null;
  38454. this.boundingBox = boundingBox;
  38455. this.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  38456. this.children = {};
  38457. this.numPoints = 0;
  38458. this.level = null;
  38459. this.loaded = false;
  38460. this.oneTimeDisposeHandlers = [];
  38461. }
  38462. isGeometryNode(){
  38463. return true;
  38464. }
  38465. getLevel(){
  38466. return this.level;
  38467. }
  38468. isTreeNode(){
  38469. return false;
  38470. }
  38471. isLoaded(){
  38472. return this.loaded;
  38473. }
  38474. getBoundingSphere(){
  38475. return this.boundingSphere;
  38476. }
  38477. getBoundingBox(){
  38478. return this.boundingBox;
  38479. }
  38480. getChildren(){
  38481. let children = [];
  38482. for (let i = 0; i < 8; i++) {
  38483. if (this.children[i]) {
  38484. children.push(this.children[i]);
  38485. }
  38486. }
  38487. return children;
  38488. }
  38489. getBoundingBox(){
  38490. return this.boundingBox;
  38491. }
  38492. getURL(){
  38493. let url = '';
  38494. let version = this.pcoGeometry.loader.version;
  38495. if (version.equalOrHigher('1.5')) {
  38496. url = this.pcoGeometry.octreeDir + '/' + this.getHierarchyPath() + '/' + this.name;
  38497. } else if (version.equalOrHigher('1.4')) {
  38498. url = this.pcoGeometry.octreeDir + '/' + this.name;
  38499. } else if (version.upTo('1.3')) {
  38500. url = this.pcoGeometry.octreeDir + '/' + this.name;
  38501. }
  38502. return url;
  38503. }
  38504. getHierarchyPath(){
  38505. let path = 'r/';
  38506. let hierarchyStepSize = this.pcoGeometry.hierarchyStepSize;
  38507. let indices = this.name.substr(1);
  38508. let numParts = Math.floor(indices.length / hierarchyStepSize);
  38509. for (let i = 0; i < numParts; i++) {
  38510. path += indices.substr(i * hierarchyStepSize, hierarchyStepSize) + '/';
  38511. }
  38512. path = path.slice(0, -1);
  38513. return path;
  38514. }
  38515. addChild(child) {
  38516. this.children[child.index] = child;
  38517. child.parent = this;
  38518. }
  38519. load(){
  38520. if (this.loading === true || this.loaded === true || Potree.numNodesLoading >= Potree.maxNodesLoading) {
  38521. return;
  38522. }
  38523. this.loading = true;
  38524. Potree.numNodesLoading++;
  38525. if (this.pcoGeometry.loader.version.equalOrHigher('1.5')) {
  38526. if ((this.level % this.pcoGeometry.hierarchyStepSize) === 0 && this.hasChildren) {
  38527. this.loadHierachyThenPoints();
  38528. } else {
  38529. this.loadPoints();
  38530. }
  38531. } else {
  38532. this.pcoGeometry.dispatchEvent({type:'updateNodeMaxLevel',level:this.level});//add
  38533. this.loadPoints();
  38534. }
  38535. }
  38536. loadPoints(){
  38537. this.pcoGeometry.loader.load(this);
  38538. }
  38539. loadHierachyThenPoints(){
  38540. let node = this;
  38541. // load hierarchy
  38542. let callback = function (node, hbuffer) {
  38543. let tStart = performance.now();
  38544. let view = new DataView(hbuffer);
  38545. let stack = [];
  38546. let children = view.getUint8(0);
  38547. let numPoints = view.getUint32(1, true);
  38548. node.numPoints = numPoints;
  38549. stack.push({children: children, numPoints: numPoints, name: node.name});
  38550. let decoded = [];
  38551. let offset = 5;
  38552. while (stack.length > 0) {
  38553. let snode = stack.shift();
  38554. let mask = 1;
  38555. for (let i = 0; i < 8; i++) {
  38556. if ((snode.children & mask) !== 0) {
  38557. let childName = snode.name + i;
  38558. let childChildren = view.getUint8(offset);
  38559. let childNumPoints = view.getUint32(offset + 1, true);
  38560. stack.push({children: childChildren, numPoints: childNumPoints, name: childName});
  38561. decoded.push({children: childChildren, numPoints: childNumPoints, name: childName});
  38562. offset += 5;
  38563. }
  38564. mask = mask * 2;
  38565. }
  38566. if (offset === hbuffer.byteLength) {
  38567. break;
  38568. }
  38569. }
  38570. // console.log(decoded);
  38571. let nodes = {};
  38572. nodes[node.name] = node;
  38573. let pco = node.pcoGeometry;
  38574. for (let i = 0; i < decoded.length; i++) {
  38575. let name = decoded[i].name;
  38576. let decodedNumPoints = decoded[i].numPoints;
  38577. let index = parseInt(name.charAt(name.length - 1));
  38578. let parentName = name.substring(0, name.length - 1);
  38579. let parentNode = nodes[parentName];
  38580. let level = name.length - 1;
  38581. let boundingBox = Utils.createChildAABB(parentNode.boundingBox, index);
  38582. let currentNode = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  38583. currentNode.level = level;
  38584. currentNode.numPoints = decodedNumPoints;
  38585. currentNode.hasChildren = decoded[i].children > 0;
  38586. currentNode.spacing = pco.spacing / Math.pow(2, level);
  38587. parentNode.addChild(currentNode);
  38588. nodes[name] = currentNode;
  38589. }
  38590. let duration = performance.now() - tStart;
  38591. if(duration > 5){
  38592. let msg = `duration: ${duration}ms, numNodes: ${decoded.length}`;
  38593. console.log(msg);
  38594. }
  38595. node.loadPoints();
  38596. };
  38597. if ((node.level % node.pcoGeometry.hierarchyStepSize) === 0) {
  38598. // let hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
  38599. let hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc';
  38600. let xhr = XHRFactory.createXMLHttpRequest();
  38601. xhr.open('GET', hurl, true);
  38602. xhr.responseType = 'arraybuffer';
  38603. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  38604. xhr.onreadystatechange = () => {
  38605. if (xhr.readyState === 4) {
  38606. if (xhr.status === 200 || xhr.status === 0) {
  38607. let hbuffer = xhr.response;
  38608. callback(node, hbuffer);
  38609. } else {
  38610. console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + hurl);
  38611. Potree.numNodesLoading--;
  38612. }
  38613. }
  38614. };
  38615. try {
  38616. xhr.send(null);
  38617. } catch (e) {
  38618. console.log('fehler beim laden der punktwolke: ' + e);
  38619. }
  38620. }
  38621. }
  38622. getNumPoints(){
  38623. return this.numPoints;
  38624. }
  38625. dispose(){
  38626. if (this.geometry && this.parent != null) {
  38627. this.geometry.dispose();
  38628. this.geometry = null;
  38629. this.loaded = false;
  38630. this.dispatchEvent( { type: 'dispose' } );
  38631. for (let i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
  38632. let handler = this.oneTimeDisposeHandlers[i];
  38633. handler();
  38634. }
  38635. this.oneTimeDisposeHandlers = [];
  38636. }
  38637. }
  38638. }
  38639. PointCloudOctreeGeometryNode.IDCount = 0;
  38640. // -------------------------------------------
  38641. // to get a ready to use gradient array from a chroma.js gradient:
  38642. // http://gka.github.io/chroma.js/
  38643. // -------------------------------------------
  38644. //
  38645. // let stops = [];
  38646. // for(let i = 0; i <= 10; i++){
  38647. // let range = chroma.scale(['yellow', 'navy']).mode('lch').domain([10,0])(i)._rgb
  38648. // .slice(0, 3)
  38649. // .map(v => (v / 255).toFixed(4))
  38650. // .join(", ");
  38651. //
  38652. // let line = `[${i / 10}, new THREE.Color(${range})],`;
  38653. //
  38654. // stops.push(line);
  38655. // }
  38656. // stops.join("\n");
  38657. //
  38658. //
  38659. //
  38660. // -------------------------------------------
  38661. // to get a ready to use gradient array from matplotlib:
  38662. // -------------------------------------------
  38663. // import matplotlib.pyplot as plt
  38664. // import matplotlib.colors as colors
  38665. //
  38666. // norm = colors.Normalize(vmin=0,vmax=1)
  38667. // cmap = plt.cm.viridis
  38668. //
  38669. // for i in range(0,11):
  38670. // u = i / 10
  38671. // rgb = cmap(norm(u))[0:3]
  38672. // rgb = ["{0:.3f}".format(v) for v in rgb]
  38673. // rgb = "[" + str(u) + ", new THREE.Color(" + ", ".join(rgb) + ")],"
  38674. // print(rgb)
  38675. let Gradients = {
  38676. // From chroma spectral http://gka.github.io/chroma.js/
  38677. SPECTRAL: [
  38678. [0, new Color(0.3686, 0.3098, 0.6353)],
  38679. [0.1, new Color(0.1961, 0.5333, 0.7412)],
  38680. [0.2, new Color(0.4000, 0.7608, 0.6471)],
  38681. [0.3, new Color(0.6706, 0.8667, 0.6431)],
  38682. [0.4, new Color(0.9020, 0.9608, 0.5961)],
  38683. [0.5, new Color(1.0000, 1.0000, 0.7490)],
  38684. [0.6, new Color(0.9961, 0.8784, 0.5451)],
  38685. [0.7, new Color(0.9922, 0.6824, 0.3804)],
  38686. [0.8, new Color(0.9569, 0.4275, 0.2627)],
  38687. [0.9, new Color(0.8353, 0.2431, 0.3098)],
  38688. [1, new Color(0.6196, 0.0039, 0.2588)]
  38689. ],
  38690. PLASMA: [
  38691. [0.0, new Color(0.241, 0.015, 0.610)],
  38692. [0.1, new Color(0.387, 0.001, 0.654)],
  38693. [0.2, new Color(0.524, 0.025, 0.653)],
  38694. [0.3, new Color(0.651, 0.125, 0.596)],
  38695. [0.4, new Color(0.752, 0.227, 0.513)],
  38696. [0.5, new Color(0.837, 0.329, 0.431)],
  38697. [0.6, new Color(0.907, 0.435, 0.353)],
  38698. [0.7, new Color(0.963, 0.554, 0.272)],
  38699. [0.8, new Color(0.992, 0.681, 0.195)],
  38700. [0.9, new Color(0.987, 0.822, 0.144)],
  38701. [1.0, new Color(0.940, 0.975, 0.131)]
  38702. ],
  38703. YELLOW_GREEN: [
  38704. [0, new Color(0.1647, 0.2824, 0.3451)],
  38705. [0.1, new Color(0.1338, 0.3555, 0.4227)],
  38706. [0.2, new Color(0.0610, 0.4319, 0.4864)],
  38707. [0.3, new Color(0.0000, 0.5099, 0.5319)],
  38708. [0.4, new Color(0.0000, 0.5881, 0.5569)],
  38709. [0.5, new Color(0.1370, 0.6650, 0.5614)],
  38710. [0.6, new Color(0.2906, 0.7395, 0.5477)],
  38711. [0.7, new Color(0.4453, 0.8099, 0.5201)],
  38712. [0.8, new Color(0.6102, 0.8748, 0.4850)],
  38713. [0.9, new Color(0.7883, 0.9323, 0.4514)],
  38714. [1, new Color(0.9804, 0.9804, 0.4314)]
  38715. ],
  38716. VIRIDIS: [
  38717. [0.0, new Color(0.267, 0.005, 0.329)],
  38718. [0.1, new Color(0.283, 0.141, 0.458)],
  38719. [0.2, new Color(0.254, 0.265, 0.530)],
  38720. [0.3, new Color(0.207, 0.372, 0.553)],
  38721. [0.4, new Color(0.164, 0.471, 0.558)],
  38722. [0.5, new Color(0.128, 0.567, 0.551)],
  38723. [0.6, new Color(0.135, 0.659, 0.518)],
  38724. [0.7, new Color(0.267, 0.749, 0.441)],
  38725. [0.8, new Color(0.478, 0.821, 0.318)],
  38726. [0.9, new Color(0.741, 0.873, 0.150)],
  38727. [1.0, new Color(0.993, 0.906, 0.144)]
  38728. ],
  38729. INFERNO: [
  38730. [0.0, new Color(0.077, 0.042, 0.206)],
  38731. [0.1, new Color(0.225, 0.036, 0.388)],
  38732. [0.2, new Color(0.373, 0.074, 0.432)],
  38733. [0.3, new Color(0.522, 0.128, 0.420)],
  38734. [0.4, new Color(0.665, 0.182, 0.370)],
  38735. [0.5, new Color(0.797, 0.255, 0.287)],
  38736. [0.6, new Color(0.902, 0.364, 0.184)],
  38737. [0.7, new Color(0.969, 0.516, 0.063)],
  38738. [0.8, new Color(0.988, 0.683, 0.072)],
  38739. [0.9, new Color(0.961, 0.859, 0.298)],
  38740. [1.0, new Color(0.988, 0.998, 0.645)]
  38741. ],
  38742. GRAYSCALE: [
  38743. [0, new Color(0, 0, 0)],
  38744. [1, new Color(1, 1, 1)]
  38745. ],
  38746. // 16 samples of the TURBU color scheme
  38747. // values taken from: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
  38748. // original file licensed under Apache-2.0
  38749. TURBO: [
  38750. [0.00, new Color(0.18995, 0.07176, 0.23217)],
  38751. [0.07, new Color(0.25107, 0.25237, 0.63374)],
  38752. [0.13, new Color(0.27628, 0.42118, 0.89123)],
  38753. [0.20, new Color(0.25862, 0.57958, 0.99876)],
  38754. [0.27, new Color(0.15844, 0.73551, 0.92305)],
  38755. [0.33, new Color(0.09267, 0.86554, 0.7623)],
  38756. [0.40, new Color(0.19659, 0.94901, 0.59466)],
  38757. [0.47, new Color(0.42778, 0.99419, 0.38575)],
  38758. [0.53, new Color(0.64362, 0.98999, 0.23356)],
  38759. [0.60, new Color(0.80473, 0.92452, 0.20459)],
  38760. [0.67, new Color(0.93301, 0.81236, 0.22667)],
  38761. [0.73, new Color(0.99314, 0.67408, 0.20348)],
  38762. [0.80, new Color(0.9836, 0.49291, 0.12849)],
  38763. [0.87, new Color(0.92105, 0.31489, 0.05475)],
  38764. [0.93, new Color(0.81608, 0.18462, 0.01809)],
  38765. [1.00, new Color(0.66449, 0.08436, 0.00424)],
  38766. ],
  38767. RAINBOW: [
  38768. [0, new Color(0.278, 0, 0.714)],
  38769. [1 / 6, new Color(0, 0, 1)],
  38770. [2 / 6, new Color(0, 1, 1)],
  38771. [3 / 6, new Color(0, 1, 0)],
  38772. [4 / 6, new Color(1, 1, 0)],
  38773. [5 / 6, new Color(1, 0.64, 0)],
  38774. [1, new Color(1, 0, 0)]
  38775. ],
  38776. CONTOUR: [
  38777. [0.00, new Color(0, 0, 0)],
  38778. [0.03, new Color(0, 0, 0)],
  38779. [0.04, new Color(1, 1, 1)],
  38780. [1.00, new Color(1, 1, 1)]
  38781. ],
  38782. };
  38783. let Shaders = {};
  38784. Shaders["pointcloud_new.vs"] = `
  38785. precision highp float;
  38786. precision highp int;
  38787. #define PI 3.141592653589793
  38788. #if defined(usePanoMap)
  38789. uniform samplerCube pano0Map; //随便设置一个samplerCube去使用都会让点云消失
  38790. uniform samplerCube pano1Map;
  38791. uniform float progress;
  38792. uniform float easeInOutRatio;
  38793. uniform vec3 pano0Position;
  38794. uniform mat4 pano0Matrix;
  38795. uniform vec3 pano1Position;
  38796. uniform mat4 pano1Matrix;
  38797. /*
  38798. varying vec3 vWorldPosition0;
  38799. varying vec3 vWorldPosition1;
  38800. */
  38801. #endif
  38802. //--------------
  38803. attribute vec3 position;
  38804. attribute vec3 color;
  38805. attribute float intensity;
  38806. attribute float classification;
  38807. attribute float returnNumber;
  38808. attribute float numberOfReturns;
  38809. attribute float pointSourceID;
  38810. attribute vec4 indices; //每个点的index
  38811. attribute float spacing;
  38812. attribute float gpsTime;
  38813. attribute vec3 normal;
  38814. attribute float aExtra;
  38815. uniform mat4 modelMatrix;
  38816. uniform mat4 modelViewMatrix;
  38817. uniform mat4 projectionMatrix;
  38818. uniform mat4 viewMatrix;
  38819. uniform mat4 uViewInv;
  38820. //uniform float uScreenWidth;
  38821. //uniform float uScreenHeight;
  38822. uniform vec2 resolution;
  38823. uniform float fov;
  38824. uniform float near;
  38825. uniform float far;
  38826. uniform bool uDebug;
  38827. uniform bool uUseOrthographicCamera;
  38828. uniform float uOrthoWidth;
  38829. uniform float uOrthoHeight;
  38830. #define CLIPTASK_NONE 0
  38831. #define CLIPTASK_HIGHLIGHT 1
  38832. #define CLIPTASK_SHOW_INSIDE 2
  38833. #define CLIPTASK_SHOW_OUTSIDE 3
  38834. #define CLIPMETHOD_INSIDE_ANY 0
  38835. #define CLIPMETHOD_INSIDE_ALL 1
  38836. //最外层裁剪(下载)
  38837. #if defined(bigClipInBox)
  38838. uniform mat4 clipBoxBig_in;
  38839. #endif
  38840. //内层裁剪
  38841. #if defined(num_in_clipboxes) && num_in_clipboxes > 0
  38842. uniform mat4 clipBoxes_in[num_in_clipboxes];
  38843. #endif
  38844. #if defined(num_out_clipboxes) && num_out_clipboxes > 0
  38845. uniform mat4 clipBoxes_out[num_out_clipboxes];
  38846. #endif
  38847. #if defined(num_clipspheres) && num_clipspheres > 0
  38848. uniform mat4 uClipSpheres[num_clipspheres];
  38849. #endif
  38850. #if defined(num_highlightBox) && num_highlightBox > 0
  38851. uniform mat4 boxes_highlight[num_highlightBox];
  38852. #endif
  38853. #if defined(num_prism) && num_prism > 0
  38854. uniform mat3 prismList[num_prism];
  38855. uniform vec2 prismPoints[prismPointCountSum];
  38856. #endif
  38857. #if defined(showBaseHeight)
  38858. uniform sampler2D baseHeightAreaMap ;
  38859. uniform vec2 baseHeightBoundZ;
  38860. uniform vec4 baseHeightBoundXY;
  38861. #endif
  38862. uniform float size;
  38863. uniform float minSize;
  38864. uniform float maxSize;
  38865. uniform float orthoMaxSize;//add
  38866. uniform float uPCIndex;
  38867. uniform float uOctreeSpacing;
  38868. uniform float uNodeSpacing;
  38869. uniform float uOctreeSize;
  38870. uniform vec3 uBBSize;
  38871. uniform float uLevel;
  38872. uniform float levelPercent;//add
  38873. uniform float uVNStart;
  38874. uniform bool uIsLeafNode;
  38875. uniform vec3 uColor;
  38876. uniform float uOpacity;
  38877. varying float vOpacity; //add
  38878. uniform vec2 elevationRange;
  38879. uniform vec2 intensityRange;
  38880. uniform vec2 uFilterReturnNumberRange;
  38881. uniform vec2 uFilterNumberOfReturnsRange;
  38882. uniform vec2 uFilterPointSourceIDClipRange;
  38883. uniform vec2 uFilterGPSTimeClipRange;
  38884. //uniform float ufilterByNormalThreshold;
  38885. uniform float uGpsScale;
  38886. uniform float uGpsOffset;
  38887. uniform vec2 uNormalizedGpsBufferRange;
  38888. uniform vec3 uIntensity_gbc;
  38889. uniform vec3 uRGB_gbc;
  38890. uniform vec3 uExtra_gbc;
  38891. uniform float uTransition;
  38892. uniform float wRGB;
  38893. uniform float wIntensity;
  38894. uniform float wElevation;
  38895. uniform float wClassification;
  38896. uniform float wReturnNumber;
  38897. uniform float wSourceID;
  38898. uniform vec2 uExtraNormalizedRange;
  38899. uniform vec2 uExtraRange;
  38900. uniform float uExtraScale;
  38901. uniform float uExtraOffset;
  38902. uniform vec3 uShadowColor;
  38903. uniform sampler2D visibleNodes;
  38904. uniform sampler2D gradient;
  38905. uniform sampler2D classificationLUT;
  38906. #if defined(color_type_matcap)
  38907. uniform sampler2D matcapTextureUniform;
  38908. #endif
  38909. uniform bool backfaceCulling;
  38910. #if defined(num_shadowmaps) && num_shadowmaps > 0
  38911. uniform sampler2D uShadowMap[num_shadowmaps];
  38912. uniform mat4 uShadowWorldView[num_shadowmaps];
  38913. uniform mat4 uShadowProj[num_shadowmaps];
  38914. #endif
  38915. varying vec3 vColor;
  38916. varying float vLogDepth;
  38917. varying vec3 vViewPosition;
  38918. varying float vRadius;
  38919. varying float vPointSize;
  38920. float Round(float number){
  38921. return floor(number + 0.5);
  38922. }
  38923. //
  38924. // ### ######## ### ######## ######## #### ## ## ######## ###### #### ######## ######## ######
  38925. // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  38926. // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  38927. // ## ## ## ## ## ## ######## ## ## ## ## ###### ###### ## ## ###### ######
  38928. // ######### ## ## ######### ## ## ## ## ## ## ## ## ## ## ##
  38929. // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  38930. // ## ## ######## ## ## ## ## #### ### ######## ###### #### ######## ######## ######
  38931. //
  38932. // ---------------------
  38933. // OCTREE
  38934. // ---------------------
  38935. #if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_octree)
  38936. /**
  38937. * number of 1-bits up to inclusive index position
  38938. * number is treated as if it were an integer in the range 0-255
  38939. *
  38940. */
  38941. int numberOfOnes(int number, int index){
  38942. int numOnes = 0;
  38943. int tmp = 128;
  38944. for(int i = 7; i >= 0; i--){
  38945. if(number >= tmp){
  38946. number = number - tmp;
  38947. if(i <= index){
  38948. numOnes++;
  38949. }
  38950. }
  38951. tmp = tmp / 2;
  38952. }
  38953. return numOnes;
  38954. }
  38955. /**
  38956. * checks whether the bit at index is 1
  38957. * number is treated as if it were an integer in the range 0-255
  38958. *
  38959. */
  38960. bool isBitSet(int number, int index){
  38961. // weird multi else if due to lack of proper array, int and bitwise support in WebGL 1.0
  38962. int powi = 1;
  38963. if(index == 0){
  38964. powi = 1;
  38965. }else if(index == 1){
  38966. powi = 2;
  38967. }else if(index == 2){
  38968. powi = 4;
  38969. }else if(index == 3){
  38970. powi = 8;
  38971. }else if(index == 4){
  38972. powi = 16;
  38973. }else if(index == 5){
  38974. powi = 32;
  38975. }else if(index == 6){
  38976. powi = 64;
  38977. }else if(index == 7){
  38978. powi = 128;
  38979. }else{
  38980. return false;
  38981. }
  38982. int ndp = number / powi;
  38983. return mod(float(ndp), 2.0) != 0.0;
  38984. }
  38985. /**
  38986. * find the LOD at the point position
  38987. */
  38988. float getLOD(){//////we use this
  38989. vec3 offset = vec3(0.0, 0.0, 0.0);
  38990. int iOffset = int(uVNStart);
  38991. float depth = uLevel;
  38992. for(float i = 0.0; i <= 30.0; i++){
  38993. float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0);
  38994. vec3 index3d = (position-offset) / nodeSizeAtLevel;
  38995. index3d = floor(index3d + 0.5);
  38996. int index = int(Round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));
  38997. vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));
  38998. int mask = int(Round(value.r * 255.0));
  38999. if(isBitSet(mask, index)){
  39000. // there are more visible child nodes at this position
  39001. int advanceG = int(Round(value.g * 255.0)) * 256;
  39002. int advanceB = int(Round(value.b * 255.0));
  39003. int advanceChild = numberOfOnes(mask, index - 1);
  39004. int advance = advanceG + advanceB + advanceChild;
  39005. iOffset = iOffset + advance;
  39006. depth++;
  39007. }else{
  39008. // no more visible child nodes at this position
  39009. //return value.a * 255.0;
  39010. float lodOffset = (255.0 * value.a) / 10.0 - 10.0;
  39011. return depth + lodOffset;
  39012. }
  39013. offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;
  39014. }
  39015. return depth;
  39016. }
  39017. float getSpacing(){
  39018. vec3 offset = vec3(0.0, 0.0, 0.0);
  39019. int iOffset = int(uVNStart);
  39020. float depth = uLevel;
  39021. float spacing = uNodeSpacing;
  39022. for(float i = 0.0; i <= 30.0; i++){
  39023. float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0);
  39024. vec3 index3d = (position-offset) / nodeSizeAtLevel;
  39025. index3d = floor(index3d + 0.5);
  39026. int index = int(Round(4.0 * index3d.x + 2.0 * index3d.y + index3d.z));
  39027. vec4 value = texture2D(visibleNodes, vec2(float(iOffset) / 2048.0, 0.0));
  39028. int mask = int(Round(value.r * 255.0));
  39029. float spacingFactor = value.a;
  39030. if(i > 0.0){
  39031. spacing = spacing / (255.0 * spacingFactor);
  39032. }
  39033. if(isBitSet(mask, index)){
  39034. // there are more visible child nodes at this position
  39035. int advanceG = int(Round(value.g * 255.0)) * 256;
  39036. int advanceB = int(Round(value.b * 255.0));
  39037. int advanceChild = numberOfOnes(mask, index - 1);
  39038. int advance = advanceG + advanceB + advanceChild;
  39039. iOffset = iOffset + advance;
  39040. //spacing = spacing / (255.0 * spacingFactor);
  39041. //spacing = spacing / 3.0;
  39042. depth++;
  39043. }else{
  39044. // no more visible child nodes at this position
  39045. return spacing;
  39046. }
  39047. offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;
  39048. }
  39049. return spacing;
  39050. }
  39051. float getPointSizeAttenuation(){
  39052. return pow(2.0, getLOD());
  39053. }
  39054. #endif
  39055. // ---------------------
  39056. // KD-TREE
  39057. // ---------------------
  39058. #if (defined(adaptive_point_size) || defined(color_type_level_of_detail)) && defined(tree_type_kdtree)
  39059. float getLOD(){
  39060. vec3 offset = vec3(0.0, 0.0, 0.0);
  39061. float iOffset = 0.0;
  39062. float depth = 0.0;
  39063. vec3 size = uBBSize;
  39064. vec3 pos = position;
  39065. for(float i = 0.0; i <= 1000.0; i++){
  39066. vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));
  39067. int children = int(value.r * 255.0);
  39068. float next = value.g * 255.0;
  39069. int split = int(value.b * 255.0);
  39070. if(next == 0.0){
  39071. return depth;
  39072. }
  39073. vec3 splitv = vec3(0.0, 0.0, 0.0);
  39074. if(split == 1){
  39075. splitv.x = 1.0;
  39076. }else if(split == 2){
  39077. splitv.y = 1.0;
  39078. }else if(split == 4){
  39079. splitv.z = 1.0;
  39080. }
  39081. iOffset = iOffset + next;
  39082. float factor = length(pos * splitv / size);
  39083. if(factor < 0.5){
  39084. // left
  39085. if(children == 0 || children == 2){
  39086. return depth;
  39087. }
  39088. }else{
  39089. // right
  39090. pos = pos - size * splitv * 0.5;
  39091. if(children == 0 || children == 1){
  39092. return depth;
  39093. }
  39094. if(children == 3){
  39095. iOffset = iOffset + 1.0;
  39096. }
  39097. }
  39098. size = size * ((1.0 - (splitv + 1.0) / 2.0) + 0.5);
  39099. depth++;
  39100. }
  39101. return depth;
  39102. }
  39103. float getPointSizeAttenuation(){
  39104. return 0.5 * pow(1.3, getLOD());
  39105. }
  39106. #endif
  39107. //
  39108. // ### ######## ######## ######## #### ######## ## ## ######## ######## ######
  39109. // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  39110. // ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  39111. // ## ## ## ## ######## ## ######## ## ## ## ###### ######
  39112. // ######### ## ## ## ## ## ## ## ## ## ## ## ##
  39113. // ## ## ## ## ## ## ## ## ## ## ## ## ## ## ##
  39114. // ## ## ## ## ## ## #### ######## ####### ## ######## ######
  39115. //
  39116. // formula adapted from: http://www.dfstudios.co.uk/articles/programming/image-programming-algorithms/image-processing-algorithms-part-5-contrast-adjustment/
  39117. float getContrastFactor(float contrast){
  39118. return (1.0158730158730156 * (contrast + 1.0)) / (1.0158730158730156 - contrast);
  39119. }
  39120. vec3 getRGB(){
  39121. vec3 rgb = color;
  39122. rgb = pow(rgb, vec3(uRGB_gbc.x));
  39123. rgb = rgb + uRGB_gbc.y;
  39124. rgb = (rgb - 0.5) * getContrastFactor(uRGB_gbc.z) + 0.5;
  39125. rgb = clamp(rgb, 0.0, 1.0);
  39126. return rgb;
  39127. }
  39128. float getIntensity(){
  39129. float w = (intensity - intensityRange.x) / (intensityRange.y - intensityRange.x);
  39130. w = pow(w, uIntensity_gbc.x);
  39131. w = w + uIntensity_gbc.y;
  39132. w = (w - 0.5) * getContrastFactor(uIntensity_gbc.z) + 0.5;
  39133. w = clamp(w, 0.0, 1.0);
  39134. return w;
  39135. }
  39136. vec3 getGpsTime(){
  39137. float w = (gpsTime + uGpsOffset) * uGpsScale;
  39138. vec3 c = texture2D(gradient, vec2(w, 1.0 - w)).rgb;
  39139. // vec2 r = uNormalizedGpsBufferRange;
  39140. // float w = gpsTime * (r.y - r.x) + r.x;
  39141. // w = clamp(w, 0.0, 1.0);
  39142. // vec3 c = texture2D(gradient, vec2(w,1.0-w)).rgb;
  39143. return c;
  39144. }
  39145. vec3 getElevation(vec4 world){
  39146. float w = (world.z - elevationRange.x) / (elevationRange.y - elevationRange.x);
  39147. vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;
  39148. return cElevation;
  39149. }
  39150. vec4 getClassification(){
  39151. vec2 uv = vec2(classification / 255.0, 0.5);
  39152. vec4 classColor = texture2D(classificationLUT, uv);
  39153. return classColor;
  39154. }
  39155. vec3 getReturns(){
  39156. // 0b 00_000_111
  39157. float rn = mod(returnNumber, 8.0);
  39158. // 0b 00_111_000
  39159. float nr = mod(returnNumber / 8.0, 8.0);
  39160. if(nr <= 1.0){
  39161. return vec3(1.0, 0.0, 0.0);
  39162. }else{
  39163. return vec3(0.0, 1.0, 0.0);
  39164. }
  39165. // return vec3(nr / 4.0, 0.0, 0.0);
  39166. // if(nr == 1.0){
  39167. // return vec3(1.0, 1.0, 0.0);
  39168. // }else{
  39169. // if(rn == 1.0){
  39170. // return vec3(1.0, 0.0, 0.0);
  39171. // }else if(rn == nr){
  39172. // return vec3(0.0, 0.0, 1.0);
  39173. // }else{
  39174. // return vec3(0.0, 1.0, 0.0);
  39175. // }
  39176. // }
  39177. // if(numberOfReturns == 1.0){
  39178. // return vec3(1.0, 1.0, 0.0);
  39179. // }else{
  39180. // if(returnNumber == 1.0){
  39181. // return vec3(1.0, 0.0, 0.0);
  39182. // }else if(returnNumber == numberOfReturns){
  39183. // return vec3(0.0, 0.0, 1.0);
  39184. // }else{
  39185. // return vec3(0.0, 1.0, 0.0);
  39186. // }
  39187. // }
  39188. }
  39189. vec3 getReturnNumber(){
  39190. if(numberOfReturns == 1.0){
  39191. return vec3(1.0, 1.0, 0.0);
  39192. }else{
  39193. if(returnNumber == 1.0){
  39194. return vec3(1.0, 0.0, 0.0);
  39195. }else if(returnNumber == numberOfReturns){
  39196. return vec3(0.0, 0.0, 1.0);
  39197. }else{
  39198. return vec3(0.0, 1.0, 0.0);
  39199. }
  39200. }
  39201. }
  39202. vec3 getNumberOfReturns(){
  39203. float value = numberOfReturns;
  39204. float w = value / 6.0;
  39205. vec3 color = texture2D(gradient, vec2(w, 1.0 - w)).rgb;
  39206. return color;
  39207. }
  39208. vec3 getSourceID(){
  39209. float w = mod(pointSourceID, 10.0) / 10.0;
  39210. return texture2D(gradient, vec2(w,1.0 - w)).rgb;
  39211. }
  39212. vec3 getCompositeColor(vec4 world){
  39213. vec3 c;
  39214. float w;
  39215. c += wRGB * getRGB();
  39216. w += wRGB;
  39217. c += wIntensity * getIntensity() * vec3(1.0, 1.0, 1.0);
  39218. w += wIntensity;
  39219. c += wElevation * getElevation(world);
  39220. w += wElevation;
  39221. c += wReturnNumber * getReturnNumber();
  39222. w += wReturnNumber;
  39223. c += wSourceID * getSourceID();
  39224. w += wSourceID;
  39225. vec4 cl = wClassification * getClassification();
  39226. c += cl.a * cl.rgb;
  39227. w += wClassification * cl.a;
  39228. c = c / w;
  39229. if(w == 0.0){
  39230. //c = color;
  39231. gl_Position = vec4(100.0, 100.0, 100.0, 0.0);
  39232. }
  39233. return c;
  39234. }
  39235. vec3 getNormal(){
  39236. //vec3 n_hsv = vec3( modelMatrix * vec4( normal, 0.0 )) * 0.5 + 0.5; // (n_world.xyz + vec3(1.,1.,1.)) / 2.;
  39237. vec3 n_view = normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) );
  39238. return n_view;
  39239. }
  39240. bool applyBackfaceCulling() {
  39241. // Black not facing vertices / Backface culling
  39242. vec3 e = normalize(vec3(modelViewMatrix * vec4( position, 1. )));
  39243. vec3 n = getNormal(); // normalize( vec3(modelViewMatrix * vec4( normal, 0.0 )) );
  39244. if((uUseOrthographicCamera && n.z <= 0.) || (!uUseOrthographicCamera && dot( n, e ) >= 0.)) {
  39245. return true;
  39246. } else {
  39247. return false;
  39248. }
  39249. }
  39250. #if defined(color_type_matcap)
  39251. // Matcap Material
  39252. vec3 getMatcap(){
  39253. vec3 eye = normalize( vec3( modelViewMatrix * vec4( position, 1. ) ) );
  39254. if(uUseOrthographicCamera) {
  39255. eye = vec3(0., 0., -1.);
  39256. }
  39257. vec3 r_en = reflect( eye, getNormal() ); // or r_en = e - 2. * dot( n, e ) * n;
  39258. float m = 2. * sqrt(pow( r_en.x, 2. ) + pow( r_en.y, 2. ) + pow( r_en.z + 1., 2. ));
  39259. vec2 vN = r_en.xy / m + .5;
  39260. return texture2D(matcapTextureUniform, vN).rgb;
  39261. }
  39262. #endif
  39263. vec3 getExtra(){
  39264. float w = (aExtra + uExtraOffset) * uExtraScale;
  39265. w = clamp(w, 0.0, 1.0);
  39266. vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb;
  39267. // vec2 r = uExtraNormalizedRange;
  39268. // float w = aExtra * (r.y - r.x) + r.x;
  39269. // w = (w - uExtraRange.x) / (uExtraRange.y - uExtraRange.x);
  39270. // w = clamp(w, 0.0, 1.0);
  39271. // vec3 color = texture2D(gradient, vec2(w,1.0-w)).rgb;
  39272. return color;
  39273. }
  39274. vec3 getColor(vec4 world){
  39275. vec3 color;
  39276. #ifdef color_type_rgba
  39277. color = getRGB();
  39278. #elif defined color_type_height || defined color_type_elevation
  39279. color = getElevation(world);
  39280. #elif defined color_type_rgb_height
  39281. vec3 cHeight = getElevation();
  39282. color = (1.0 - uTransition) * getRGB() + uTransition * cHeight;
  39283. #elif defined color_type_depth
  39284. float linearDepth = gl_Position.w;
  39285. float expDepth = (gl_Position.z / gl_Position.w) * 0.5 + 0.5;
  39286. color = vec3(linearDepth, expDepth, 0.0);
  39287. //color = vec3(1.0, 0.5, 0.3);
  39288. #elif defined color_type_intensity
  39289. float w = getIntensity();
  39290. color = vec3(w, w, w);
  39291. #elif defined color_type_gps_time
  39292. color = getGpsTime();
  39293. #elif defined color_type_intensity_gradient
  39294. float w = getIntensity();
  39295. color = texture2D(gradient, vec2(w,1.0-w)).rgb;
  39296. #elif defined color_type_color
  39297. color = uColor;
  39298. #elif defined color_type_level_of_detail
  39299. float depth = getLOD();
  39300. float w = depth / 10.0;
  39301. color = texture2D(gradient, vec2(w,1.0-w)).rgb;
  39302. #elif defined color_type_indices
  39303. color = indices.rgb;
  39304. #elif defined color_type_classification
  39305. vec4 cl = getClassification();
  39306. color = cl.rgb;
  39307. #elif defined color_type_return_number
  39308. color = getReturnNumber();
  39309. #elif defined color_type_returns
  39310. color = getReturns();
  39311. #elif defined color_type_number_of_returns
  39312. color = getNumberOfReturns();
  39313. #elif defined color_type_source_id
  39314. color = getSourceID();
  39315. #elif defined color_type_point_source_id
  39316. color = getSourceID();
  39317. #elif defined color_type_normal
  39318. color = (modelMatrix * vec4(normal, 0.0)).xyz;
  39319. #elif defined color_type_phong
  39320. color = color;
  39321. #elif defined color_type_composite
  39322. color = getCompositeColor(world);
  39323. #elif defined color_type_matcap
  39324. color = getMatcap();
  39325. #elif defined color_type_heightCpt //add
  39326. color = vec3(0.0,0.0,0.0);
  39327. #else
  39328. color = getExtra();
  39329. #endif
  39330. if (backfaceCulling && applyBackfaceCulling()){
  39331. //color = vec3(0.);
  39332. }
  39333. //applyBackfaceCulling直接返回false或者注释color = vec3(0.);都没问题
  39334. return color;
  39335. }
  39336. float getPointSize(){
  39337. float pointSize = 1.0;
  39338. float maxSize_ = maxSize;
  39339. float slope = tan(fov / 2.0);
  39340. float projFactor = -0.5 * resolution.y / (slope * vViewPosition.z);
  39341. /*
  39342. float scale = length(
  39343. modelViewMatrix * vec4(0, 0, 0, 1) -
  39344. modelViewMatrix * vec4(uOctreeSpacing, 0, 0, 1)
  39345. ) / uOctreeSpacing;
  39346. projFactor = projFactor * scale;
  39347. */
  39348. float r = uOctreeSpacing * 1.7;
  39349. //vRadius = r;
  39350. #if defined fixed_point_size
  39351. pointSize = size;
  39352. #elif defined attenuated_point_size
  39353. if(uUseOrthographicCamera){
  39354. pointSize = size / uOrthoWidth * resolution.x; //改成近似adaptive_point_size根据窗口缩放。其实就是size * zoom (size单位转化为米,如size为1代表一个点云在场景中1米宽,zoom代表1px=1/zoom米)
  39355. maxSize_ = orthoMaxSize; //for panoEditor, when zoom in, need more details, rather than always same size
  39356. }else{ //近大远小,模拟真实mesh,边缘放大
  39357. //pointSize = size * spacing * projFactor; //spacing是attribute 为空 如果有这个值就能更自适应填补
  39358. //pointSize = size * uOctreeSpacing * projFactor / 18.0; //直接用cloud的spacing里,不过因为都一样所以可能没有什么意义
  39359. //pointSize = pointSize * projFactor;
  39360. pointSize = size * projFactor ;
  39361. }
  39362. #elif defined adaptive_point_size
  39363. if(uUseOrthographicCamera) {
  39364. float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation();
  39365. pointSize = (worldSpaceSize / uOrthoWidth) * resolution.x; //uScreenWidth;
  39366. maxSize_ = orthoMaxSize;
  39367. } else {
  39368. float worldSpaceSize = 1.0 * size * r / getPointSizeAttenuation();
  39369. pointSize = worldSpaceSize * projFactor;
  39370. }
  39371. #endif
  39372. pointSize = max(minSize, pointSize);
  39373. pointSize = min(maxSize_, pointSize);
  39374. vRadius = pointSize / projFactor;
  39375. return pointSize;
  39376. }
  39377. bool insideBox(mat4 clipBox, vec4 worldPos){//add
  39378. vec4 clipPosition = clipBox * worldPos;
  39379. bool inside = -0.5 <= clipPosition.x && clipPosition.x <= 0.5;
  39380. inside = inside && -0.5 <= clipPosition.y && clipPosition.y <= 0.5;
  39381. inside = inside && -0.5 <= clipPosition.z && clipPosition.z <= 0.5;
  39382. return inside;
  39383. }
  39384. #if defined(color_type_heightCpt)
  39385. vec3 percentToByte(float num){
  39386. //输出是0-1, shader精度不够,只够存3个数
  39387. float a = 1.0;
  39388. float result[4];
  39389. for(int i=0;i<3;i++){
  39390. a = i == 2 ? a/255.0 : a / 256.0 ;
  39391. //分成256份,其中255份给当前位置,最后一份给后一个位置,而到了最后一个位置时没有下一个位置了所以只分成255份
  39392. if(num > a){
  39393. float c = num / a;
  39394. float r = floor(c);
  39395. r = min(255.0, r);
  39396. result[i] = r;
  39397. num -= r * a;
  39398. }else{
  39399. result[i] = 0.0;
  39400. }
  39401. }
  39402. return vec3(result[0]/255.0, result[1]/255.0,result[2]/255.0);
  39403. //除以多少255还是256? 参考uPCIndex / 255.0 应该是255
  39404. }
  39405. #endif
  39406. #if defined(num_prism) && num_prism > 0
  39407. int insidePrism(mat3 prismInfo, int pointIndexStart, vec4 worldPos){//是否在棱柱里
  39408. float zMin = prismInfo[0][0];
  39409. float zMid = prismInfo[0][1];
  39410. float zMax = prismInfo[0][2];
  39411. float xMin = prismInfo[1][0];
  39412. float xMax = prismInfo[1][1];
  39413. float yMin = prismInfo[1][2];
  39414. float yMax = prismInfo[2][0];
  39415. int pointCount = int(Round(prismInfo[2][1]));
  39416. if( worldPos.x < xMin || worldPos.x > xMax || worldPos.y < yMin || worldPos.y > yMax)return 0;
  39417. #ifndef showBaseHeight
  39418. if( worldPos.z < zMin || worldPos.z > zMax) return 0;
  39419. #endif
  39420. bool inside = false;
  39421. int j=pointCount-1;
  39422. for(int i=0; i<prism_maxPointsCount; i++){
  39423. if(i>=pointCount)break;
  39424. float xi = prismPoints[i+pointIndexStart].x, yi = prismPoints[i+pointIndexStart].y, xj = prismPoints[j+pointIndexStart].x, yj = prismPoints[j+pointIndexStart].y;
  39425. if(((yi > worldPos.y) != (yj > worldPos.y)) && (worldPos.x < (xj - xi) * (worldPos.y - yi) / (yj - yi) + xi)){
  39426. inside = !inside;
  39427. }
  39428. j=i;
  39429. }
  39430. if(inside){
  39431. #ifdef showBaseHeight
  39432. return 1;
  39433. #else
  39434. #ifdef color_type_heightCpt
  39435. vColor = percentToByte((worldPos.z - zMin) / (zMax - zMin));
  39436. #endif
  39437. #endif
  39438. return worldPos.z < zMid ? 1 : 2;
  39439. }else return 0;
  39440. }
  39441. #endif
  39442. #ifdef showBaseHeight
  39443. float byteToFloat(vec3 color){
  39444. float percent = 0.0;
  39445. float a = 1.0;
  39446. for(int i=0;i<3;i++){
  39447. a = i == 2 ? a/255.0 : a/256.0;
  39448. percent += a * color[i] ;
  39449. }
  39450. return percent * 255.0 ;
  39451. }
  39452. #endif
  39453. void doClipping(vec4 world){
  39454. {
  39455. vec4 cl = getClassification();
  39456. if(cl.a == 0.0){
  39457. gl_Position = vec4(100.0, 100.0, 100.0, 0.0);
  39458. return;
  39459. }
  39460. }
  39461. #if defined(clip_return_number_enabled)
  39462. { // return number filter
  39463. vec2 range = uFilterReturnNumberRange;
  39464. if(returnNumber < range.x || returnNumber > range.y){
  39465. gl_Position = vec4(100.0, 100.0, 100.0, 0.0);
  39466. return;
  39467. }
  39468. }
  39469. #endif
  39470. #if defined(clip_number_of_returns_enabled)
  39471. { // number of return filter
  39472. vec2 range = uFilterNumberOfReturnsRange;
  39473. if(numberOfReturns < range.x || numberOfReturns > range.y){
  39474. gl_Position = vec4(100.0, 100.0, 100.0, 0.0);
  39475. return;
  39476. }
  39477. }
  39478. #endif
  39479. #if defined(clip_gps_enabled)
  39480. { // GPS time filter
  39481. float time = (gpsTime + uGpsOffset) * uGpsScale;
  39482. vec2 range = uFilterGPSTimeClipRange;
  39483. if(time < range.x || time > range.y){
  39484. gl_Position = vec4(100.0, 100.0, 100.0, 0.0);
  39485. return;
  39486. }
  39487. }
  39488. #endif
  39489. #if defined(clip_point_source_id_enabled)
  39490. { // point source id filter
  39491. vec2 range = uFilterPointSourceIDClipRange;
  39492. if(pointSourceID < range.x || pointSourceID > range.y){
  39493. gl_Position = vec4(100.0, 100.0, 100.0, 0.0);
  39494. return;
  39495. }
  39496. }
  39497. #endif
  39498. //总共三种box : 最外层可见、内层可见和不可见(外层可见和内层可见是交集,内层可见和内层不可见是并集)
  39499. #if defined(bigClipInBox)
  39500. if(!insideBox(clipBoxBig_in, world)){
  39501. gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
  39502. return;;
  39503. }
  39504. #endif
  39505. #if defined(num_in_clipboxes) && num_in_clipboxes > 0
  39506. //当有可见box时,需要在任一可见box内才可见
  39507. bool visi1 = false;
  39508. for(int i = 0; i < num_in_clipboxes; i++){
  39509. if(insideBox(clipBoxes_in[i], world)){
  39510. visi1 = true;
  39511. break;
  39512. }
  39513. }
  39514. if(!visi1){
  39515. gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
  39516. return;
  39517. }
  39518. #endif
  39519. #if defined(num_out_clipboxes) && num_out_clipboxes > 0
  39520. //当有不可见box时,不在所有不可见box内才可见
  39521. bool visi2 = true;
  39522. for(int i = 0; i < num_out_clipboxes; i++){
  39523. if(insideBox(clipBoxes_out[i], world)){
  39524. visi2 = false;
  39525. break;
  39526. }
  39527. }
  39528. if(!visi2){
  39529. gl_Position = vec4(100.0, 100.0, 100.0, 1.0);
  39530. return;
  39531. }
  39532. #endif
  39533. #if defined(num_highlightBox) && num_highlightBox > 0
  39534. //当有高亮box时,需要在任一可见高亮内都高宽
  39535. bool highlight = false;
  39536. for(int i = 0; i < num_highlightBox; i++){
  39537. if(insideBox(boxes_highlight[i], world)){
  39538. highlight = true;
  39539. break;
  39540. }
  39541. }
  39542. if(highlight){
  39543. vColor.r += 0.5;
  39544. }
  39545. #endif
  39546. int highlight_ = 0;
  39547. #if defined(num_prism) && num_prism > 0
  39548. //基于prism棱柱的土方量显示或计算
  39549. int pointIndexStart = 0;
  39550. for(int i = 0; i < num_prism; i++){
  39551. highlight_ = insidePrism(prismList[i], pointIndexStart, world);
  39552. if(highlight_>0){
  39553. #if !defined(showBaseHeight) && !defined(color_type_heightCpt)
  39554. if(highlight_ == 1){
  39555. vColor.r += 0.5;
  39556. }else if(highlight_ == 2){
  39557. vColor.g += 0.5;
  39558. }
  39559. #endif
  39560. break;
  39561. }
  39562. pointIndexStart += int(Round(prismList[i][2][1]));
  39563. }
  39564. #ifdef color_type_heightCpt
  39565. if(highlight_==0){
  39566. gl_Position = vec4(100.0, 100.0, 100.0, 1.0); //unvisible
  39567. return;
  39568. }
  39569. #endif
  39570. #endif
  39571. #ifdef showBaseHeight
  39572. //基于模型的土方量显示或计算
  39573. bool outsidePrism = false;
  39574. #if defined(num_prism) && num_prism > 0//高亮交集
  39575. if( highlight_ == 0 ){
  39576. outsidePrism = true;
  39577. }
  39578. #endif
  39579. if(!outsidePrism){
  39580. float zMin = baseHeightBoundZ.x;
  39581. float zMax = baseHeightBoundZ.y;
  39582. float xMin = baseHeightBoundXY.x;
  39583. float xMax = baseHeightBoundXY.y;
  39584. float yMin = baseHeightBoundXY.z;
  39585. float yMax = baseHeightBoundXY.w;
  39586. bool inside = false;
  39587. if(world.z < zMin || world.z > zMax || world.x < xMin || world.x > xMax || world.y < yMin || world.y > yMax){
  39588. inside = false;
  39589. }else{
  39590. vec2 uv = vec2((world.x - xMin) / (xMax - xMin), (world.y - yMin) / (yMax - yMin) );
  39591. vec4 color = texture2D(baseHeightAreaMap,uv);
  39592. //抗锯齿待写
  39593. if(color.a==1.0){
  39594. float currentHeight = (world.z - zMin) / (zMax - zMin) ;
  39595. #ifdef color_type_heightCpt
  39596. /*float diff = currentHeight - baseHeight;
  39597. if(diff<0.0){
  39598. diff = -diff;
  39599. vOpacity = 0.5;//需要透明通道,容易出错
  39600. }else{
  39601. vOpacity = 1.0;
  39602. }
  39603. vColor = percentToByte(diff);
  39604. */
  39605. vColor = percentToByte(currentHeight);
  39606. //vColor = color.rgb;
  39607. vOpacity = 1.0;
  39608. #else
  39609. //vColor = color.rgb;
  39610. float baseHeight = byteToFloat(color.rgb);
  39611. if(currentHeight > baseHeight){
  39612. vColor.g += 0.5;
  39613. }else{
  39614. vColor.r += 0.5;
  39615. }
  39616. #endif
  39617. inside = true;
  39618. }else{
  39619. inside = false;
  39620. }
  39621. }
  39622. if(inside == false){
  39623. #ifdef color_type_heightCpt
  39624. gl_Position = vec4(100.0, 100.0, 100.0, 1.0); //unvisible
  39625. return;
  39626. #endif
  39627. }
  39628. }
  39629. #endif
  39630. }
  39631. //
  39632. // ## ## ### #### ## ##
  39633. // ### ### ## ## ## ### ##
  39634. // #### #### ## ## ## #### ##
  39635. // ## ### ## ## ## ## ## ## ##
  39636. // ## ## ######### ## ## ####
  39637. // ## ## ## ## ## ## ###
  39638. // ## ## ## ## #### ## ##
  39639. //
  39640. vec2 getSamplerCoord( vec3 direction )
  39641. {
  39642. direction = normalize(direction);
  39643. float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;
  39644. float ty=acos(direction.z)/PI;
  39645. return vec2(tx,ty);
  39646. }
  39647. vec3 transformAxis( vec3 direction ) //navvis->4dkk
  39648. {
  39649. float y = direction.y;
  39650. direction.y = direction.z;
  39651. direction.z = -y;
  39652. return direction;
  39653. }
  39654. void main() {
  39655. //bool filtered_by_normal = false;
  39656. float normalZ = 0.0;
  39657. #ifdef use_filter_by_normal
  39658. /*if(abs(getNormal().z) > 0.4) { //ufilterByNormalThreshold 暂定 3
  39659. // Move point outside clip space space to discard it.
  39660. //gl_Position = vec4(0.0, 0.0, 2.0, 1.0); //gl_Position的可视区域是 x,y,z都是[-1,1]
  39661. //return;
  39662. //filtered_by_normal = true; //标记一下。不直接不绘制,因为有的法线都是垂直向上
  39663. }*/
  39664. normalZ = abs(getNormal().z);
  39665. #endif
  39666. vec4 worldPos = modelMatrix * vec4(position, 1.0);
  39667. vec4 mvPosition = modelViewMatrix * vec4(position, 1.0 ); //vec4 mvPosition = viewMatrix * worldPos;
  39668. vViewPosition = mvPosition.xyz;
  39669. gl_Position = projectionMatrix * mvPosition;
  39670. vLogDepth = log2(-mvPosition.z);
  39671. // COLOR
  39672. //加-------------------
  39673. #if defined(usePanoMap)
  39674. vec3 positionLocalToPanoCenter0 = worldPos.xyz - pano0Position;
  39675. vec3 vWorldPosition0 = (vec4(positionLocalToPanoCenter0, 1.0) * pano0Matrix).xyz;
  39676. vWorldPosition0.x *= -1.0;
  39677. vWorldPosition0 = transformAxis(vWorldPosition0);
  39678. vec3 positionLocalToPanoCenter1 = worldPos.xyz - pano1Position;
  39679. vec3 vWorldPosition1 = (vec4(positionLocalToPanoCenter1, 1.0) * pano1Matrix).xyz;
  39680. vWorldPosition1.x *= -1.0;
  39681. vWorldPosition1 = transformAxis(vWorldPosition1);
  39682. /*
  39683. vec2 samplerCoord0 = getSamplerCoord(vWorldPosition0.xyz);
  39684. vec2 samplerCoord1 = getSamplerCoord(vWorldPosition1.xyz);
  39685. vec4 colorFromPano0 = texture2D(pano0Map,samplerCoord0);
  39686. vec4 colorFromPano1 = texture2D(pano1Map,samplerCoord1);
  39687. */
  39688. vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);
  39689. vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);
  39690. vColor = mix(colorFromPano0,colorFromPano1,progress).xyz;
  39691. //float easeInOutRatio = 0.0; //缓冲,渐变点云到贴图的颜色
  39692. if(progress < easeInOutRatio){
  39693. float easeProgress = (easeInOutRatio - progress) / easeInOutRatio;
  39694. vec3 vColor1 = getColor(worldPos);
  39695. vColor = mix(vColor,vColor1,easeProgress);
  39696. }else if(progress > 1.0 - easeInOutRatio){
  39697. float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio;
  39698. vec3 vColor1 = getColor(worldPos);
  39699. vColor = mix(vColor,vColor1,easeProgress);
  39700. }
  39701. #else
  39702. vColor = getColor(worldPos);
  39703. #endif
  39704. //-------------------
  39705. if(uOpacity>=1.0 || uUseOrthographicCamera){
  39706. vOpacity = uOpacity;
  39707. if(uOpacity<1.0){ //uUseOrthographicCamera
  39708. //防止缩小后点云几乎看不见
  39709. vOpacity *= 4.0-3.0 * levelPercent;
  39710. }
  39711. }else{ //#ifdef attenuated_opacity zoom不会改变z 所以这并不是用在分屏时候的
  39712. float v = -gl_Position.z-1.0 ; // 范围从-2到0, e的-2到0次方的范围是0.818到1
  39713. //vOpacity = uOpacity * exp(v/ (levelPercent * 20.0 ) );
  39714. //近处加深,远处变淡 gl_Position.z似乎朝向屏幕里为正
  39715. float r = clamp( pow(1.1, v/10.0 ), 0.1, 1.0 ); //除以的数字越大,近高远低的程度越小,范围越长。 程度太高远处单薄的区域看不见 pow的底数越大改变率越大
  39716. vOpacity = uOpacity * r ;
  39717. }
  39718. vOpacity *= max(0.3, pow((1.0 - normalZ),5.0));//垂直朝相机时降低透明度
  39719. //vOpacity = clamp(vOpacity, 0.0, 1.0);
  39720. // POINT SIZE
  39721. float pointSize = getPointSize();
  39722. gl_PointSize = pointSize;
  39723. vPointSize = pointSize;
  39724. // only for "replacing" approaches
  39725. // if(getLOD() != uLevel){
  39726. // gl_Position = vec4(10.0, 10.0, 10.0, 1.0);
  39727. // }
  39728. #if defined hq_depth_pass
  39729. float originalDepth = gl_Position.w;
  39730. float adjustedDepth = originalDepth + 2.0 * vRadius;
  39731. float adjust = adjustedDepth / originalDepth;
  39732. mvPosition.xyz = mvPosition.xyz * adjust;
  39733. gl_Position = projectionMatrix * mvPosition;
  39734. #endif
  39735. // CLIPPING
  39736. doClipping(worldPos);
  39737. #if defined(num_clipspheres) && num_clipspheres > 0
  39738. for(int i = 0; i < num_clipspheres; i++){
  39739. vec4 sphereLocal = uClipSpheres[i] * mvPosition;
  39740. float distance = length(sphereLocal.xyz);
  39741. if(distance < 1.0){
  39742. float w = distance;
  39743. vec3 cGradient = texture2D(gradient, vec2(w, 1.0 - w)).rgb;
  39744. vColor = cGradient;
  39745. //vColor = cGradient * 0.7 + vColor * 0.3;
  39746. }
  39747. }
  39748. #endif
  39749. #if defined(num_shadowmaps) && num_shadowmaps > 0
  39750. const float sm_near = 0.1;
  39751. const float sm_far = 10000.0;
  39752. for(int i = 0; i < num_shadowmaps; i++){
  39753. vec3 viewPos = (uShadowWorldView[i] * vec4(position, 1.0)).xyz;
  39754. float distanceToLight = abs(viewPos.z);
  39755. vec4 projPos = uShadowProj[i] * uShadowWorldView[i] * vec4(position, 1);
  39756. vec3 nc = projPos.xyz / projPos.w;
  39757. float u = nc.x * 0.5 + 0.5;
  39758. float v = nc.y * 0.5 + 0.5;
  39759. vec2 sampleStep = vec2(1.0 / (2.0*1024.0), 1.0 / (2.0*1024.0)) * 1.5;
  39760. vec2 sampleLocations[9];
  39761. sampleLocations[0] = vec2(0.0, 0.0);
  39762. sampleLocations[1] = sampleStep;
  39763. sampleLocations[2] = -sampleStep;
  39764. sampleLocations[3] = vec2(sampleStep.x, -sampleStep.y);
  39765. sampleLocations[4] = vec2(-sampleStep.x, sampleStep.y);
  39766. sampleLocations[5] = vec2(0.0, sampleStep.y);
  39767. sampleLocations[6] = vec2(0.0, -sampleStep.y);
  39768. sampleLocations[7] = vec2(sampleStep.x, 0.0);
  39769. sampleLocations[8] = vec2(-sampleStep.x, 0.0);
  39770. float visibleSamples = 0.0;
  39771. float numSamples = 0.0;
  39772. float bias = vRadius * 2.0;
  39773. for(int j = 0; j < 9; j++){
  39774. vec4 depthMapValue = texture2D(uShadowMap[i], vec2(u, v) + sampleLocations[j]);
  39775. float linearDepthFromSM = depthMapValue.x + bias;
  39776. float linearDepthFromViewer = distanceToLight;
  39777. if(linearDepthFromSM > linearDepthFromViewer){
  39778. visibleSamples += 1.0;
  39779. }
  39780. numSamples += 1.0;
  39781. }
  39782. float visibility = visibleSamples / numSamples;
  39783. 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){
  39784. //vColor = vec3(0.0, 0.0, 0.2);
  39785. }else{
  39786. //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);
  39787. vColor = vColor * visibility + vColor * uShadowColor * (1.0 - visibility);
  39788. }
  39789. }
  39790. #endif
  39791. }
  39792. `;
  39793. Shaders["pointcloud_new.fs"] = `
  39794. #if defined paraboloid_point_shape
  39795. #extension GL_EXT_frag_depth : enable
  39796. #endif
  39797. #define PI 3.141592653589793
  39798. precision highp float;
  39799. precision highp int;
  39800. /*
  39801. #if defined(usePanoMap)
  39802. uniform samplerCube pano0Map; //随便设置一个samplerCube去使用都会让点云消失
  39803. uniform samplerCube pano1Map;
  39804. uniform float progress;
  39805. uniform float easeInOutRatio;
  39806. uniform vec3 pano0Position;
  39807. uniform mat4 pano0Matrix;
  39808. uniform vec3 pano1Position;
  39809. uniform mat4 pano1Matrix;
  39810. varying vec3 vWorldPosition0;
  39811. varying vec3 vWorldPosition1;
  39812. #endif
  39813. */
  39814. //------------
  39815. uniform mat4 viewMatrix;
  39816. uniform mat4 uViewInv;
  39817. uniform mat4 uProjInv;
  39818. uniform vec3 cameraPosition;
  39819. uniform mat4 projectionMatrix;
  39820. //uniform float uOpacity;
  39821. varying float vOpacity; //add
  39822. uniform float blendHardness;
  39823. uniform float blendDepthSupplement;
  39824. uniform float fov;
  39825. uniform float uSpacing;
  39826. uniform float near;
  39827. uniform float far;
  39828. uniform float uPCIndex;
  39829. uniform float uScreenWidth;
  39830. uniform float uScreenHeight;
  39831. varying vec3 vColor;
  39832. varying float vLogDepth;
  39833. varying vec3 vViewPosition;
  39834. varying float vRadius;
  39835. varying float vPointSize;
  39836. varying vec3 vPosition;
  39837. float specularStrength = 1.0;
  39838. vec2 getSamplerCoord( vec3 direction )
  39839. {
  39840. direction = normalize(direction);
  39841. float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;
  39842. float ty=acos(direction.z)/PI;
  39843. return vec2(tx,ty);
  39844. }
  39845. void main() {
  39846. vec3 color = vColor;
  39847. /*#if defined(usePanoMap) //加 经测试,即使全部写在fragment里也是无论pointsize多大都是一个点一个颜色,所以干脆写在vectex里
  39848. vec4 colorFromPano0=textureCube(pano0Map,vWorldPosition0.xyz);
  39849. vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1.xyz);
  39850. color = mix(colorFromPano0,colorFromPano1,progress).xyz;
  39851. //float easeInOutRatio = 0.0; //缓冲,渐变点云到贴图的颜色
  39852. if(progress < easeInOutRatio){
  39853. float easeProgress = (easeInOutRatio - progress) / easeInOutRatio;
  39854. color = mix(color,vColor,easeProgress);
  39855. }else if(progress > 1.0 - easeInOutRatio){
  39856. float easeProgress = (progress - (1.0 - easeInOutRatio) ) / easeInOutRatio;
  39857. color = mix(color,vColor,easeProgress);
  39858. }
  39859. #else
  39860. color = vColor;
  39861. #endif*/
  39862. float depth = gl_FragCoord.z;
  39863. #if defined(circle_point_shape) || defined(paraboloid_point_shape)
  39864. float u = 2.0 * gl_PointCoord.x - 1.0;
  39865. float v = 2.0 * gl_PointCoord.y - 1.0;
  39866. #endif
  39867. #if defined(circle_point_shape)
  39868. float cc = u*u + v*v;
  39869. if(cc > 1.0){
  39870. discard;
  39871. }
  39872. #endif
  39873. #if defined color_type_indices //pick point recognize
  39874. gl_FragColor = vec4(color, uPCIndex / 255.0); //uPCIndex : node Index
  39875. #else
  39876. gl_FragColor = vec4(color, vOpacity);
  39877. #endif
  39878. #if defined paraboloid_point_shape
  39879. float wi = 0.0 - ( u*u + v*v);
  39880. vec4 pos = vec4(vViewPosition, 1.0);
  39881. pos.z += wi * vRadius;
  39882. float linearDepth = -pos.z;
  39883. pos = projectionMatrix * pos;
  39884. pos = pos / pos.w;
  39885. float expDepth = pos.z;
  39886. depth = (pos.z + 1.0) / 2.0;
  39887. gl_FragDepthEXT = depth;
  39888. gl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0); //add
  39889. #if defined(color_type_depth)
  39890. color.r = linearDepth;
  39891. color.g = expDepth;
  39892. #endif
  39893. #if defined(use_edl)
  39894. gl_FragColor.a = log2(linearDepth);
  39895. #endif
  39896. #else
  39897. #if defined(use_edl)
  39898. gl_FragColor.a = vLogDepth;
  39899. #endif
  39900. #endif
  39901. #if defined(weighted_splats)
  39902. float distance = 2.0 * length(gl_PointCoord.xy - 0.5);
  39903. float weight = max(0.0, 1.0 - distance);
  39904. weight = pow(weight, 1.5);
  39905. gl_FragColor.a = weight;
  39906. gl_FragColor.xyz = gl_FragColor.xyz * weight;
  39907. #endif
  39908. //gl_FragColor = vec4(0.0, 0.7, 0.0, 1.0);
  39909. }
  39910. `;
  39911. Shaders["pointcloud_sm.vs"] = `
  39912. precision mediump float;
  39913. precision mediump int;
  39914. attribute vec3 position;
  39915. attribute vec3 color;
  39916. uniform mat4 modelMatrix;
  39917. uniform mat4 modelViewMatrix;
  39918. uniform mat4 projectionMatrix;
  39919. uniform mat4 viewMatrix;
  39920. uniform float uScreenWidth;
  39921. uniform float uScreenHeight;
  39922. uniform float near;
  39923. uniform float far;
  39924. uniform float uSpacing;
  39925. uniform float uOctreeSize;
  39926. uniform float uLevel;
  39927. uniform float uVNStart;
  39928. uniform sampler2D visibleNodes;
  39929. varying float vLinearDepth;
  39930. varying vec3 vColor;
  39931. #define PI 3.141592653589793
  39932. // ---------------------
  39933. // OCTREE
  39934. // ---------------------
  39935. #if defined(adaptive_point_size)
  39936. /**
  39937. * number of 1-bits up to inclusive index position
  39938. * number is treated as if it were an integer in the range 0-255
  39939. *
  39940. */
  39941. float numberOfOnes(float number, float index){
  39942. float tmp = mod(number, pow(2.0, index + 1.0));
  39943. float numOnes = 0.0;
  39944. for(float i = 0.0; i < 8.0; i++){
  39945. if(mod(tmp, 2.0) != 0.0){
  39946. numOnes++;
  39947. }
  39948. tmp = floor(tmp / 2.0);
  39949. }
  39950. return numOnes;
  39951. }
  39952. /**
  39953. * checks whether the bit at index is 1
  39954. * number is treated as if it were an integer in the range 0-255
  39955. *
  39956. */
  39957. bool isBitSet(float number, float index){
  39958. return mod(floor(number / pow(2.0, index)), 2.0) != 0.0;
  39959. }
  39960. /**
  39961. * find the LOD at the point position
  39962. */
  39963. float getLOD(){
  39964. vec3 offset = vec3(0.0, 0.0, 0.0);
  39965. float iOffset = uVNStart;
  39966. float depth = uLevel;
  39967. for(float i = 0.0; i <= 30.0; i++){
  39968. float nodeSizeAtLevel = uOctreeSize / pow(2.0, i + uLevel + 0.0);
  39969. vec3 index3d = (position-offset) / nodeSizeAtLevel;
  39970. index3d = floor(index3d + 0.5);
  39971. float index = 4.0 * index3d.x + 2.0 * index3d.y + index3d.z;
  39972. vec4 value = texture2D(visibleNodes, vec2(iOffset / 2048.0, 0.0));
  39973. float mask = value.r * 255.0;
  39974. if(isBitSet(mask, index)){
  39975. // there are more visible child nodes at this position
  39976. iOffset = iOffset + value.g * 255.0 * 256.0 + value.b * 255.0 + numberOfOnes(mask, index - 1.0);
  39977. depth++;
  39978. }else{
  39979. // no more visible child nodes at this position
  39980. return depth;
  39981. }
  39982. offset = offset + (vec3(1.0, 1.0, 1.0) * nodeSizeAtLevel * 0.5) * index3d;
  39983. }
  39984. return depth;
  39985. }
  39986. #endif
  39987. float getPointSize(){
  39988. float pointSize = 1.0;
  39989. float slope = tan(fov / 2.0);
  39990. float projFactor = -0.5 * uScreenHeight / (slope * vViewPosition.z);
  39991. float r = uOctreeSpacing * 1.5;
  39992. vRadius = r;
  39993. #if defined fixed_point_size
  39994. pointSize = size;
  39995. #elif defined attenuated_point_size
  39996. if(uUseOrthographicCamera){
  39997. pointSize = size;
  39998. }else{
  39999. pointSize = pointSize * projFactor;
  40000. }
  40001. #elif defined adaptive_point_size
  40002. if(uUseOrthographicCamera) {
  40003. float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
  40004. pointSize = (worldSpaceSize / uOrthoWidth) * uScreenWidth;
  40005. } else {
  40006. float worldSpaceSize = 1.5 * size * r / getPointSizeAttenuation();
  40007. pointSize = worldSpaceSize * projFactor;
  40008. }
  40009. #endif
  40010. pointSize = max(minSize, pointSize);
  40011. pointSize = min(maxSize, pointSize);
  40012. vRadius = pointSize / projFactor;
  40013. return pointSize;
  40014. }
  40015. void main() {
  40016. vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
  40017. vLinearDepth = gl_Position.w;
  40018. float pointSize = getPointSize();
  40019. gl_PointSize = pointSize;
  40020. }
  40021. `;
  40022. Shaders["pointcloud_sm.fs"] = `
  40023. precision mediump float;
  40024. precision mediump int;
  40025. varying vec3 vColor;
  40026. varying float vLinearDepth;
  40027. void main() {
  40028. //gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
  40029. //gl_FragColor = vec4(vColor, 1.0);
  40030. //gl_FragColor = vec4(vLinearDepth, pow(vLinearDepth, 2.0), 0.0, 1.0);
  40031. gl_FragColor = vec4(vLinearDepth, vLinearDepth / 30.0, vLinearDepth / 30.0, 1.0);
  40032. }
  40033. `;
  40034. Shaders["normalize.vs"] = `
  40035. precision mediump float;
  40036. precision mediump int;
  40037. attribute vec3 position;
  40038. attribute vec2 uv;
  40039. uniform mat4 projectionMatrix;
  40040. uniform mat4 modelViewMatrix;
  40041. varying vec2 vUv;
  40042. void main() {
  40043. vUv = uv;
  40044. gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
  40045. }`;
  40046. Shaders["normalize.fs"] = `
  40047. #extension GL_EXT_frag_depth : enable
  40048. precision mediump float;
  40049. precision mediump int;
  40050. uniform sampler2D uWeightMap;
  40051. uniform sampler2D uDepthMap;
  40052. varying vec2 vUv;
  40053. void main() {
  40054. float depth = texture2D(uDepthMap, vUv).r;
  40055. if(depth >= 1.0){
  40056. discard;
  40057. }
  40058. gl_FragColor = vec4(depth, 1.0, 0.0, 1.0);
  40059. vec4 color = texture2D(uWeightMap, vUv);
  40060. color = color / color.w;
  40061. gl_FragColor = vec4(color.xyz, 1.0);
  40062. gl_FragDepthEXT = depth;
  40063. }`;
  40064. Shaders["normalize_and_edl.fs"] = `
  40065. #extension GL_EXT_frag_depth : enable
  40066. //
  40067. // adapted from the EDL shader code from Christian Boucheny in cloud compare:
  40068. // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
  40069. //
  40070. precision mediump float;
  40071. precision mediump int;
  40072. uniform sampler2D uWeightMap;
  40073. uniform sampler2D uEDLMap;
  40074. uniform sampler2D uDepthMap;
  40075. uniform float screenWidth;
  40076. uniform float screenHeight;
  40077. uniform vec2 neighbours[NEIGHBOUR_COUNT];
  40078. uniform float edlStrength;
  40079. uniform float radius;
  40080. varying vec2 vUv;
  40081. float response(float depth){
  40082. vec2 uvRadius = radius / vec2(screenWidth, screenHeight);
  40083. float sum = 0.0;
  40084. for(int i = 0; i < NEIGHBOUR_COUNT; i++){
  40085. vec2 uvNeighbor = vUv + uvRadius * neighbours[i];
  40086. float neighbourDepth = texture2D(uEDLMap, uvNeighbor).a;
  40087. if(neighbourDepth != 0.0){
  40088. if(depth == 0.0){
  40089. sum += 100.0;
  40090. }else{
  40091. sum += max(0.0, depth - neighbourDepth);
  40092. }
  40093. }
  40094. }
  40095. return sum / float(NEIGHBOUR_COUNT);
  40096. }
  40097. void main() {
  40098. float edlDepth = texture2D(uEDLMap, vUv).a;
  40099. float res = response(edlDepth);
  40100. float shade = exp(-res * 300.0 * edlStrength);
  40101. float depth = texture2D(uDepthMap, vUv).r;
  40102. if(depth >= 1.0 && res == 0.0){
  40103. discard;
  40104. }
  40105. vec4 color = texture2D(uWeightMap, vUv);
  40106. color = color / color.w;
  40107. color = color * shade;
  40108. gl_FragColor = vec4(color.xyz, 1.0);
  40109. gl_FragDepthEXT = depth;
  40110. }`;
  40111. Shaders["edl_new.vs"] = `
  40112. precision mediump float;
  40113. precision mediump int;
  40114. attribute vec3 position;
  40115. attribute vec2 uv;
  40116. uniform mat4 projectionMatrix;
  40117. uniform mat4 modelViewMatrix;
  40118. varying vec2 vUv;
  40119. void main() {
  40120. vUv = uv;
  40121. vec4 mvPosition = modelViewMatrix * vec4(position,1.0);
  40122. gl_Position = projectionMatrix * mvPosition;
  40123. }`;
  40124. Shaders["edl_new.fs"] = `
  40125. #extension GL_EXT_frag_depth : enable
  40126. //
  40127. // adapted from the EDL shader code from Christian Boucheny in cloud compare:
  40128. // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
  40129. //
  40130. precision mediump float;
  40131. precision mediump int;
  40132. //uniform float screenWidth;
  40133. //uniform float screenHeight;
  40134. uniform vec2 resolution;
  40135. uniform vec2 neighbours[NEIGHBOUR_COUNT];
  40136. uniform float edlStrength;
  40137. uniform float radius;
  40138. uniform float opacity;
  40139. //uniform float uNear;
  40140. //uniform float uFar;
  40141. uniform mat4 uProj;
  40142. uniform sampler2D uEDLColor;
  40143. uniform sampler2D uEDLDepth;
  40144. varying vec2 vUv;
  40145. uniform int useEDL;
  40146. float response(float depth){
  40147. vec2 uvRadius = radius / resolution; //vec2(screenWidth, screenHeight);
  40148. float sum = 0.0;
  40149. for(int i = 0; i < NEIGHBOUR_COUNT; i++){
  40150. vec2 uvNeighbor = vUv + uvRadius * neighbours[i];
  40151. //获取周围八个格子的值
  40152. float neighbourDepth = texture2D(uEDLColor, uvNeighbor).a;
  40153. neighbourDepth = (neighbourDepth == 1.0) ? 0.0 : neighbourDepth;
  40154. if(neighbourDepth != 0.0){
  40155. //if(depth == 0.0){
  40156. // sum += 100.0;
  40157. //}else{
  40158. sum += max(0.0, depth - neighbourDepth); //获取差值
  40159. //}
  40160. }
  40161. }
  40162. return sum / float(NEIGHBOUR_COUNT);
  40163. }
  40164. void main(){
  40165. vec4 cEDL = texture2D(uEDLColor, vUv);
  40166. float depth = cEDL.a;
  40167. depth = (depth == 1.0) ? 0.0 : depth;
  40168. if(depth == 0.0){ //去掉这句就能在无点云像素的地方渲染outline,但会遮住其他mesh
  40169. discard;
  40170. }
  40171. if(useEDL == 1){
  40172. float res = response(depth);
  40173. float shade = exp(-res * 300.0 * edlStrength); //自然常数e为底的指数函数
  40174. const float min = 0.2; //add 使边缘色变浅 范围从0-1 变为min-1
  40175. shade = shade * (1.0-min) + min;
  40176. gl_FragColor = vec4(cEDL.rgb * shade, opacity);
  40177. }else{//加 不改颜色的情况
  40178. gl_FragColor = vec4(cEDL.rgb, opacity);
  40179. }
  40180. //注意,edlStrength越强,在相同depth的叠放的点云间的轮廓线颜色越深
  40181. //作用:勾勒边缘,强化深度差异,模拟阴影,加强结构立体感
  40182. { // write regular hyperbolic depth values to depth buffer 修改深度
  40183. float dl = pow(2.0, depth);
  40184. vec4 dp = uProj * vec4(0.0, 0.0, -dl, 1.0);
  40185. float pz = dp.z / dp.w;
  40186. float fragDepth = (pz + 1.0) / 2.0;
  40187. gl_FragDepthEXT = fragDepth;
  40188. }
  40189. }
  40190. `;
  40191. Shaders["blur.vs"] = `
  40192. varying vec2 vUv;
  40193. void main() {
  40194. vUv = uv;
  40195. gl_Position = projectionMatrix * modelViewMatrix * vec4(position,1.0);
  40196. }`;
  40197. Shaders["blur.fs"] = `
  40198. uniform mat4 projectionMatrix;
  40199. uniform float screenWidth;
  40200. uniform float screenHeight;
  40201. uniform float near;
  40202. uniform float far;
  40203. uniform sampler2D map;
  40204. varying vec2 vUv;
  40205. void main() {
  40206. float dx = 1.0 / screenWidth;
  40207. float dy = 1.0 / screenHeight;
  40208. vec3 color = vec3(0.0, 0.0, 0.0);
  40209. color += texture2D(map, vUv + vec2(-dx, -dy)).rgb;
  40210. color += texture2D(map, vUv + vec2( 0, -dy)).rgb;
  40211. color += texture2D(map, vUv + vec2(+dx, -dy)).rgb;
  40212. color += texture2D(map, vUv + vec2(-dx, 0)).rgb;
  40213. color += texture2D(map, vUv + vec2( 0, 0)).rgb;
  40214. color += texture2D(map, vUv + vec2(+dx, 0)).rgb;
  40215. color += texture2D(map, vUv + vec2(-dx, dy)).rgb;
  40216. color += texture2D(map, vUv + vec2( 0, dy)).rgb;
  40217. color += texture2D(map, vUv + vec2(+dx, dy)).rgb;
  40218. color = color / 9.0;
  40219. gl_FragColor = vec4(color, 1.0);
  40220. }`;
  40221. Shaders["depthBasic.vs"] = `
  40222. varying vec2 vUv;
  40223. void main() {
  40224. vUv = uv;
  40225. gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  40226. }
  40227. `;
  40228. Shaders["depthBasic.fs"] = `varying vec2 vUv;
  40229. uniform float opacity;
  40230. uniform float mapScale;
  40231. uniform vec3 baseColor;
  40232. #if defined use_map
  40233. uniform sampler2D map;
  40234. vec4 getMapColor(vec4 color){
  40235. if(mapScale == 1.0){
  40236. color = texture2D(map, vUv) * color;
  40237. return color;
  40238. }else{
  40239. vec2 uv = (vUv - 0.5) / mapScale + 0.5;
  40240. if(uv.x > 1.0 || uv.y > 1.0 || uv.x < 0.0 || uv.y < 0.0){
  40241. //color = vec4(0.0,0.0,0.0,0.0);
  40242. discard;
  40243. }else{
  40244. color = texture2D(map, uv) * color;
  40245. }
  40246. return color;
  40247. }
  40248. }
  40249. #endif
  40250. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  40251. //似乎通过gl.getExtension('EXT_frag_depth')得到的GL_EXT_frag_depth
  40252. uniform sampler2D depthTexture;
  40253. uniform float nearPlane;
  40254. uniform float farPlane;
  40255. uniform vec2 resolution;
  40256. uniform vec2 viewportOffset; // viewportOffset 范围从0-整个画布的像素
  40257. uniform vec3 backColor;
  40258. uniform float occlusionDistance;
  40259. uniform float clipDistance;
  40260. uniform float maxClipFactor;
  40261. uniform float maxOcclusionFactor;
  40262. //uniform bool uUseOrthographicCamera;
  40263. float convertToLinear(float zValue)
  40264. {
  40265. //if(uUseOrthographicCamera){
  40266. // return zValue*(farPlane-nearPlane)+nearPlane;
  40267. //}else{
  40268. float z = zValue * 2.0 - 1.0;
  40269. return (2.0 * nearPlane * farPlane) / (farPlane + nearPlane - z * (farPlane - nearPlane));
  40270. //}
  40271. }
  40272. #endif
  40273. void main() {
  40274. vec4 color = vec4(baseColor, opacity);
  40275. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  40276. // mixFactor and clipFactor define the color mixing proportion between the states of
  40277. // full visibility and occluded visibility
  40278. // and
  40279. // full visibility and total invisibility
  40280. float mixFactor = 0.0;
  40281. float clipFactor = 0.0;
  40282. // The linear depth value of the current fragment
  40283. float fragDepth = convertToLinear(gl_FragCoord.z);
  40284. // The coordinates of the current fragment in the depth texture
  40285. vec2 depthTxtCoords = vec2(gl_FragCoord.x-viewportOffset.x, gl_FragCoord.y - viewportOffset.y) / resolution;
  40286. //gl_FragCoord大小为 viewport client大小
  40287. // The linear depth value of the pixel occupied by this fragment in the depth buffer
  40288. float textureDepth = convertToLinear(texture2D(depthTexture, depthTxtCoords).r);
  40289. // The difference between the two depths
  40290. float delta = fragDepth - textureDepth;
  40291. if (delta > 0.0)//差距
  40292. {
  40293. // occlusionDistance and clipDistance define the width of the respective zones and
  40294. // mixFactor and clipFactor express the interpolation between the two colors depending on the position
  40295. // of the current fragment withing those zones.
  40296. mixFactor = clamp(delta / occlusionDistance, 0.0, maxOcclusionFactor);
  40297. clipFactor = clamp(delta / clipDistance, 0.0, maxClipFactor);
  40298. }
  40299. // If the fragment is totally transparent, don't bother drawing it
  40300. if (clipFactor == 1.0)
  40301. {
  40302. discard;
  40303. }else{
  40304. #if defined use_map
  40305. color = getMapColor(color);
  40306. #endif
  40307. color = vec4(mix(color.rgb, backColor, mixFactor), color.a * (1.0 - clipFactor));
  40308. }
  40309. #else
  40310. #if defined use_map
  40311. color = getMapColor(color);
  40312. #endif
  40313. #endif
  40314. gl_FragColor = color;
  40315. }
  40316. `;
  40317. Shaders["copyCubeMap.vs"] = `varying vec3 vWorldPos;
  40318. vec3 transformAxis( vec3 direction ) //navvis->4dkk
  40319. {
  40320. float y = direction.y;
  40321. direction.y = direction.z;
  40322. direction.z = -y;
  40323. return direction;
  40324. }
  40325. void main() {
  40326. vWorldPos = vec3(-position.x, -position.y, position.z);
  40327. //vWorldPos = transformAxis(vWorldPos);
  40328. gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  40329. }
  40330. `;
  40331. Shaders["copyCubeMap.fs"] = `varying vec3 vWorldPos;
  40332. uniform float alpha;
  40333. uniform samplerCube tDiffuse;
  40334. void main() {
  40335. vec4 texColor = textureCube(tDiffuse, vWorldPos);
  40336. gl_FragColor = vec4(texColor.rgb, texColor.a * alpha);
  40337. }
  40338. `;
  40339. Shaders["basicTextured.vs"] = `varying vec2 vUv;
  40340. void main() {
  40341. vUv = uv;
  40342. gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
  40343. }
  40344. `;
  40345. Shaders["basicTextured.fs"] = `varying vec2 vUv;
  40346. uniform float opacity;
  40347. #ifdef HasMap
  40348. uniform sampler2D map;
  40349. #endif
  40350. #ifdef HasColor
  40351. uniform vec3 color;
  40352. #endif
  40353. void main() {
  40354. vec4 color_;
  40355. #ifdef HasColor
  40356. color_ = vec4(color, opacity);
  40357. #else
  40358. color_ = vec4(1.0,1.0,1.0, opacity);
  40359. #endif
  40360. #ifdef HasMap
  40361. vec4 texColor = texture2D(map, vUv);
  40362. gl_FragColor = texColor * color_;
  40363. #else
  40364. gl_FragColor = color_;
  40365. #endif
  40366. }
  40367. `;
  40368. Shaders["skybox.vs"] = `uniform mat4 matrix;
  40369. varying vec3 vWorldPosition;
  40370. void main()
  40371. {
  40372. vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz ; // - cameraPosition;
  40373. vWorldPosition = (vec4(vWorldPosition, 1.0) * matrix).xyz;
  40374. vWorldPosition.x *= -1.0;
  40375. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  40376. }`;
  40377. Shaders["skybox.fs"] = `varying vec3 vWorldPosition;
  40378. uniform sampler2D tDiffuse;
  40379. #define PI 3.141592653
  40380. /*vec2 getSamplerCoord( vec3 direction )
  40381. {
  40382. direction = normalize(direction);
  40383. float tx=atan(direction.x,direction.z)/(PI*2.0)+0.5;
  40384. float ty=acos(direction.y)/PI;
  40385. return vec2(tx,ty);
  40386. }*/
  40387. vec2 getSamplerCoord( vec3 direction )
  40388. {
  40389. direction = normalize(direction);
  40390. float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;
  40391. float ty=acos(direction.z)/PI;
  40392. return vec2(tx,ty);
  40393. }
  40394. void main()
  40395. {
  40396. vec2 samplerCoord = getSamplerCoord(vWorldPosition);
  40397. vec4 color = texture2D(tDiffuse, samplerCoord);
  40398. //gl_FragColor = RGBEToLinear( color ); //对于hdr必须加这一句,否则效果很奇怪。copy自meshBasicMaterial里的mat_fragment的mapTexelToLinear函数,只要有map就会使用该函数
  40399. gl_FragColor = color;
  40400. //#include <tonemapping_fragment>
  40401. //////#include <encodings_fragment>
  40402. }
  40403. `;
  40404. const ClassificationScheme = {
  40405. DEFAULT: {
  40406. 0: { visible: true, name: 'never classified' , color: [0.5, 0.5, 0.5, 1.0] },
  40407. 1: { visible: true, name: 'unclassified' , color: [0.5, 0.5, 0.5, 1.0] },
  40408. 2: { visible: true, name: 'ground' , color: [0.63, 0.32, 0.18, 1.0] },
  40409. 3: { visible: true, name: 'low vegetation' , color: [0.0, 1.0, 0.0, 1.0] },
  40410. 4: { visible: true, name: 'medium vegetation' , color: [0.0, 0.8, 0.0, 1.0] },
  40411. 5: { visible: true, name: 'high vegetation' , color: [0.0, 0.6, 0.0, 1.0] },
  40412. 6: { visible: true, name: 'building' , color: [1.0, 0.66, 0.0, 1.0] },
  40413. 7: { visible: true, name: 'low point(noise)' , color: [1.0, 0.0, 1.0, 1.0] },
  40414. 8: { visible: true, name: 'key-point' , color: [1.0, 0.0, 0.0, 1.0] },
  40415. 9: { visible: true, name: 'water' , color: [0.0, 0.0, 1.0, 1.0] },
  40416. 12: { visible: true, name: 'overlap' , color: [1.0, 1.0, 0.0, 1.0] },
  40417. DEFAULT: { visible: true, name: 'default' , color: [0.3, 0.6, 0.6, 0.5] },
  40418. }
  40419. };
  40420. Object.defineProperty(ClassificationScheme, 'RANDOM', {
  40421. get: function() {
  40422. let scheme = {};
  40423. for(let i = 0; i <= 255; i++){
  40424. scheme[i] = new Vector4(Math.random(), Math.random(), Math.random());
  40425. }
  40426. scheme["DEFAULT"] = new Vector4(Math.random(), Math.random(), Math.random());
  40427. return scheme;
  40428. }
  40429. });
  40430. class EnumItem{
  40431. constructor(object){
  40432. for(let key of Object.keys(object)){
  40433. this[key] = object[key];
  40434. }
  40435. }
  40436. inspect(){
  40437. return `Enum(${this.name}: ${this.value})`;
  40438. }
  40439. };
  40440. class Enum{
  40441. constructor(object){
  40442. this.object = object;
  40443. for(let key of Object.keys(object)){
  40444. let value = object[key];
  40445. if(typeof value === "object"){
  40446. value.name = key;
  40447. }else {
  40448. value = {name: key, value: value};
  40449. }
  40450. this[key] = new EnumItem(value);
  40451. }
  40452. }
  40453. fromValue(value){
  40454. for(let key of Object.keys(this.object)){
  40455. if(this[key].value === value){
  40456. return this[key];
  40457. }
  40458. }
  40459. throw new Error(`No enum for value: ${value}`);
  40460. }
  40461. };
  40462. const CameraMode = {
  40463. ORTHOGRAPHIC: 0,
  40464. PERSPECTIVE: 1,
  40465. VR: 2,
  40466. };
  40467. const ClipTask = {
  40468. NONE: 0,
  40469. HIGHLIGHT: 1,
  40470. SHOW_INSIDE: 2,
  40471. SHOW_OUTSIDE: 3
  40472. };
  40473. const ClipMethod = {
  40474. INSIDE_ANY: 0,
  40475. INSIDE_ALL: 1
  40476. };
  40477. const ElevationGradientRepeat = {
  40478. CLAMP: 0,
  40479. REPEAT: 1,
  40480. MIRRORED_REPEAT: 2,
  40481. };
  40482. const MOUSE$1 = {
  40483. LEFT: 0b0001,
  40484. RIGHT: 0b0010,
  40485. MIDDLE: 0b0100
  40486. };
  40487. const PointSizeType = {
  40488. FIXED: 0,
  40489. ATTENUATED: 1,
  40490. ADAPTIVE: 2
  40491. };
  40492. const PointShape$1 = {
  40493. SQUARE: 0,
  40494. CIRCLE: 1,
  40495. PARABOLOID: 2
  40496. };
  40497. const TreeType = {
  40498. OCTREE: 0,
  40499. KDTREE: 1
  40500. };
  40501. const LengthUnits = {
  40502. METER: {code: 'm', unitspermeter: 1.0},
  40503. FEET: {code: 'ft', unitspermeter: 3.28084},
  40504. INCH: {code: '\u2033', unitspermeter: 39.3701}
  40505. };
  40506. //
  40507. // how to calculate the radius of a projected sphere in screen space
  40508. // http://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space
  40509. // http://stackoverflow.com/questions/3717226/radius-of-projected-sphere
  40510. //
  40511. class PointCloudMaterial$1 extends RawShaderMaterial {//base
  40512. constructor (parameters = {}) {
  40513. super();
  40514. this.visibleNodesTexture = Utils.generateDataTexture(2048, 1, new Color(0xffffff));
  40515. this.visibleNodesTexture.minFilter = NearestFilter;
  40516. this.visibleNodesTexture.magFilter = NearestFilter;
  40517. let getValid = (a, b) => {
  40518. if(a !== undefined){
  40519. return a;
  40520. }else {
  40521. return b;
  40522. }
  40523. };
  40524. let pointSize = getValid(parameters.size, 1.0);
  40525. let minSize = getValid(parameters.minSize, 2.0);
  40526. let maxSize = getValid(parameters.maxSize, 50.0);
  40527. let treeType = getValid(parameters.treeType, TreeType.OCTREE);
  40528. this._pointSizeType = PointSizeType.FIXED;
  40529. this._shape = PointShape$1.SQUARE;
  40530. this._useClipBox = false;
  40531. this.clipBoxes = [];
  40532. this.clipPolygons = [];
  40533. this._weighted = false;
  40534. this._gradient = Gradients.SPECTRAL;
  40535. this.gradientTexture = PointCloudMaterial$1.generateGradientTexture(this._gradient);
  40536. //this._matcap = "matcap.jpg";
  40537. //this.matcapTexture = PointCloudMaterial.generateMatcapTexture(this._matcap);
  40538. this.lights = false;
  40539. this.fog = false;
  40540. this._treeType = treeType;
  40541. this._useEDL = false;
  40542. this.defines = new Map();
  40543. this.ranges = new Map();
  40544. this._activeAttributeName = null;
  40545. this._defaultIntensityRangeChanged = false;
  40546. this._defaultElevationRangeChanged = false;
  40547. {
  40548. const [width, height] = [256, 1];
  40549. let data = new Uint8Array(width * 4);
  40550. let texture = new DataTexture(data, width, height, RGBAFormat);
  40551. texture.magFilter = NearestFilter;
  40552. texture.needsUpdate = true;
  40553. this.classificationTexture = texture;
  40554. }
  40555. this.attributes = {
  40556. position: { type: 'fv', value: [] },
  40557. color: { type: 'fv', value: [] },
  40558. normal: { type: 'fv', value: [] },
  40559. intensity: { type: 'f', value: [] },
  40560. classification: { type: 'f', value: [] },
  40561. returnNumber: { type: 'f', value: [] },
  40562. numberOfReturns: { type: 'f', value: [] },
  40563. pointSourceID: { type: 'f', value: [] },
  40564. indices: { type: 'fv', value: [] }
  40565. };
  40566. this.uniforms = {
  40567. level: { type: "f", value: 0.0 },
  40568. vnStart: { type: "f", value: 0.0 },
  40569. spacing: { type: "f", value: 1.0 },
  40570. blendHardness: { type: "f", value: 2.0 },
  40571. blendDepthSupplement: { type: "f", value: 0.0 },
  40572. fov: { type: "f", value: 1.0 },
  40573. screenWidth: { type: "f", value: 1.0 },
  40574. screenHeight: { type: "f", value: 1.0 },
  40575. near: { type: "f", value: 0.1 },
  40576. far: { type: "f", value: 1.0 },
  40577. uColor: { type: "c", value: new Color( 0xffffff ) },
  40578. uOpacity: { type: "f", value: 1.0 },
  40579. size: { type: "f", value: pointSize },
  40580. minSize: { type: "f", value: minSize },
  40581. maxSize: { type: "f", value: maxSize },
  40582. octreeSize: { type: "f", value: 0 },
  40583. bbSize: { type: "fv", value: [0, 0, 0] },
  40584. elevationRange: { type: "2fv", value: [0, 0] },
  40585. clipBoxCount: { type: "f", value: 0 },
  40586. //clipSphereCount: { type: "f", value: 0 },
  40587. clipPolygonCount: { type: "i", value: 0 },
  40588. clipBoxes: { type: "Matrix4fv", value: [] },
  40589. //clipSpheres: { type: "Matrix4fv", value: [] },
  40590. clipPolygons: { type: "3fv", value: [] },
  40591. clipPolygonVCount: { type: "iv", value: [] },
  40592. clipPolygonVP: { type: "Matrix4fv", value: [] },
  40593. visibleNodes: { type: "t", value: this.visibleNodesTexture },
  40594. pcIndex: { type: "f", value: 0 },
  40595. gradient: { type: "t", value: this.gradientTexture },
  40596. classificationLUT: { type: "t", value: this.classificationTexture },
  40597. uHQDepthMap: { type: "t", value: null },
  40598. toModel: { type: "Matrix4f", value: [] },
  40599. diffuse: { type: "fv", value: [1, 1, 1] },
  40600. transition: { type: "f", value: 0.5 },
  40601. intensityRange: { type: "fv", value: [Infinity, -Infinity] },
  40602. intensity_gbc: { type: "fv", value: [1, 0, 0]},
  40603. uRGB_gbc: { type: "fv", value: [1, 0, 0]},
  40604. // intensityGamma: { type: "f", value: 1 },
  40605. // intensityContrast: { type: "f", value: 0 },
  40606. // intensityBrightness:{ type: "f", value: 0 },
  40607. // rgbGamma: { type: "f", value: 1 },
  40608. // rgbContrast: { type: "f", value: 0 },
  40609. // rgbBrightness: { type: "f", value: 0 },
  40610. wRGB: { type: "f", value: 1 },
  40611. wIntensity: { type: "f", value: 0 },
  40612. wElevation: { type: "f", value: 0 },
  40613. wClassification: { type: "f", value: 0 },
  40614. wReturnNumber: { type: "f", value: 0 },
  40615. wSourceID: { type: "f", value: 0 },
  40616. useOrthographicCamera: { type: "b", value: false },
  40617. elevationGradientRepat: { type: "i", value: ElevationGradientRepeat.CLAMP },
  40618. clipTask: { type: "i", value: 1 },
  40619. clipMethod: { type: "i", value: 1 },
  40620. uShadowColor: { type: "3fv", value: [0, 0, 0] },
  40621. uExtraScale: { type: "f", value: 1},
  40622. uExtraOffset: { type: "f", value: 0},
  40623. uExtraRange: { type: "2fv", value: [0, 1] },
  40624. uExtraGammaBrightContr: { type: "3fv", value: [1, 0, 0] },
  40625. uFilterReturnNumberRange: { type: "fv", value: [0, 7]},
  40626. uFilterNumberOfReturnsRange: { type: "fv", value: [0, 7]},
  40627. uFilterGPSTimeClipRange: { type: "fv", value: [0, 7]},
  40628. uFilterPointSourceIDClipRange: { type: "fv", value: [0, 65535]},
  40629. //matcapTextureUniform: { type: "t", value: this.matcapTexture },
  40630. backfaceCulling: { type: "b", value: false },
  40631. };
  40632. this.classification = ClassificationScheme.DEFAULT;
  40633. this.defaultAttributeValues.normal = [0, 0, 0];
  40634. this.defaultAttributeValues.classification = [0, 0, 0];
  40635. this.defaultAttributeValues.indices = [0, 0, 0, 0];
  40636. this.vertexShader = Shaders['pointcloud.vs'];
  40637. this.fragmentShader = Shaders['pointcloud.fs'];
  40638. this.vertexColors = VertexColors;
  40639. this.updateShaderSource();
  40640. }
  40641. setDefine(key, value){
  40642. if(value !== undefined && value !== null){
  40643. if(this.defines.get(key) !== value){
  40644. this.defines.set(key, value);
  40645. this.updateShaderSource();
  40646. }
  40647. }else {
  40648. this.removeDefine(key);
  40649. }
  40650. }
  40651. removeDefine(key){
  40652. this.defines.delete(key);
  40653. }
  40654. updateShaderSource () {
  40655. let vs = Shaders['pointcloud.vs'];
  40656. let fs = Shaders['pointcloud.fs'];
  40657. let definesString = this.getDefines();
  40658. let vsVersionIndex = vs.indexOf("#version ");
  40659. let fsVersionIndex = fs.indexOf("#version ");
  40660. if(vsVersionIndex >= 0){
  40661. vs = vs.replace(/(#version .*)/, `$1\n${definesString}`);
  40662. }else {
  40663. vs = `${definesString}\n${vs}`;
  40664. }
  40665. if(fsVersionIndex >= 0){
  40666. fs = fs.replace(/(#version .*)/, `$1\n${definesString}`);
  40667. }else {
  40668. fs = `${definesString}\n${fs}`;
  40669. }
  40670. this.vertexShader = vs;
  40671. this.fragmentShader = fs;
  40672. if (this.opacity === 1.0) {
  40673. this.blending = NoBlending;
  40674. this.transparent = false;
  40675. this.depthTest = true;
  40676. this.depthWrite = true;
  40677. this.depthFunc = LessEqualDepth;
  40678. } else if (this.opacity < 1.0 && !this.useEDL) {
  40679. this.blending = AdditiveBlending;
  40680. this.transparent = true;
  40681. this.depthTest = false;
  40682. this.depthWrite = true;
  40683. this.depthFunc = AlwaysDepth;
  40684. }
  40685. if (this.weighted) {
  40686. this.blending = AdditiveBlending;
  40687. this.transparent = true;
  40688. this.depthTest = true;
  40689. this.depthWrite = false;
  40690. }
  40691. this.needsUpdate = true;
  40692. }
  40693. getDefines () {
  40694. let defines = [];
  40695. if (this.pointSizeType === PointSizeType.FIXED) {
  40696. defines.push('#define fixed_point_size');
  40697. } else if (this.pointSizeType === PointSizeType.ATTENUATED) {
  40698. defines.push('#define attenuated_point_size');
  40699. } else if (this.pointSizeType === PointSizeType.ADAPTIVE) {
  40700. defines.push('#define adaptive_point_size');
  40701. }
  40702. if (this.shape === PointShape$1.SQUARE) {
  40703. defines.push('#define square_point_shape');
  40704. } else if (this.shape === PointShape$1.CIRCLE) {
  40705. defines.push('#define circle_point_shape');
  40706. } else if (this.shape === PointShape$1.PARABOLOID) {
  40707. defines.push('#define paraboloid_point_shape');
  40708. }
  40709. if (this._useEDL) {
  40710. defines.push('#define use_edl');
  40711. }
  40712. if(this.activeAttributeName){
  40713. let attributeName = this.activeAttributeName.replace(/[^a-zA-Z0-9]/g, '_');
  40714. defines.push(`#define color_type_${attributeName}`);
  40715. }
  40716. if(this._treeType === TreeType.OCTREE){
  40717. defines.push('#define tree_type_octree');
  40718. }else if(this._treeType === TreeType.KDTREE){
  40719. defines.push('#define tree_type_kdtree');
  40720. }
  40721. if (this.weighted) {
  40722. defines.push('#define weighted_splats');
  40723. }
  40724. for(let [key, value] of this.defines){
  40725. defines.push(value);
  40726. }
  40727. return defines.join("\n");
  40728. }
  40729. setClipBoxes (clipBoxes) {
  40730. if (!clipBoxes) {
  40731. return;
  40732. }
  40733. let doUpdate = (this.clipBoxes.length !== clipBoxes.length) && (clipBoxes.length === 0 || this.clipBoxes.length === 0);
  40734. this.uniforms.clipBoxCount.value = this.clipBoxes.length;
  40735. this.clipBoxes = clipBoxes;
  40736. if (doUpdate) {
  40737. this.updateShaderSource();
  40738. }
  40739. this.uniforms.clipBoxes.value = new Float32Array(this.clipBoxes.length * 16);
  40740. for (let i = 0; i < this.clipBoxes.length; i++) {
  40741. let box = clipBoxes[i];
  40742. this.uniforms.clipBoxes.value.set(box.inverse.elements, 16 * i);
  40743. }
  40744. for (let i = 0; i < this.uniforms.clipBoxes.value.length; i++) {
  40745. if (Number.isNaN(this.uniforms.clipBoxes.value[i])) {
  40746. this.uniforms.clipBoxes.value[i] = Infinity;
  40747. }
  40748. }
  40749. }
  40750. setClipPolygons(clipPolygons, maxPolygonVertices) {
  40751. if(!clipPolygons){
  40752. return;
  40753. }
  40754. this.clipPolygons = clipPolygons;
  40755. let doUpdate = (this.clipPolygons.length !== clipPolygons.length);
  40756. if(doUpdate){
  40757. this.updateShaderSource();
  40758. }
  40759. }
  40760. get gradient(){
  40761. return this._gradient;
  40762. }
  40763. set gradient (value) {//海拔贴图
  40764. if (this._gradient !== value) {
  40765. this._gradient = value;
  40766. this.gradientTexture = PointCloudMaterial$1.generateGradientTexture(this._gradient);
  40767. this.uniforms.gradient.value = this.gradientTexture;
  40768. }
  40769. }
  40770. /* get matcap(){
  40771. return this._matcap;
  40772. }
  40773. set matcap (value) {
  40774. if (this._matcap !== value) {
  40775. this._matcap = value;
  40776. this.matcapTexture = Potree.PointCloudMaterial.generateMatcapTexture(this._matcap);
  40777. this.uniforms.matcapTextureUniform.value = this.matcapTexture;
  40778. }
  40779. } */
  40780. get useOrthographicCamera() {
  40781. return this.uniforms.useOrthographicCamera.value;
  40782. }
  40783. set useOrthographicCamera(value) {
  40784. if(this.uniforms.useOrthographicCamera.value !== value){
  40785. this.uniforms.useOrthographicCamera.value = value;
  40786. }
  40787. }
  40788. get backfaceCulling() {
  40789. return this.uniforms.backfaceCulling.value;
  40790. }
  40791. set backfaceCulling(value) {
  40792. if(this.uniforms.backfaceCulling.value !== value){
  40793. this.uniforms.backfaceCulling.value = value;
  40794. this.dispatchEvent({type: 'backface_changed', target: this});
  40795. }
  40796. }
  40797. recomputeClassification () {
  40798. const classification = this.classification;
  40799. const data = this.classificationTexture.image.data;
  40800. let width = 256;
  40801. const black = [1, 1, 1, 1];
  40802. let valuesChanged = false;
  40803. for (let i = 0; i < width; i++) {
  40804. let color;
  40805. let visible = true;
  40806. if (classification[i]) {
  40807. color = classification[i].color;
  40808. visible = classification[i].visible;
  40809. } else if (classification[i % 32]) {
  40810. color = classification[i % 32].color;
  40811. visible = classification[i % 32].visible;
  40812. } else if(classification.DEFAULT) {
  40813. color = classification.DEFAULT.color;
  40814. visible = classification.DEFAULT.visible;
  40815. }else {
  40816. color = black;
  40817. }
  40818. const r = parseInt(255 * color[0]);
  40819. const g = parseInt(255 * color[1]);
  40820. const b = parseInt(255 * color[2]);
  40821. const a = visible ? parseInt(255 * color[3]) : 0;
  40822. if(data[4 * i + 0] !== r){
  40823. data[4 * i + 0] = r;
  40824. valuesChanged = true;
  40825. }
  40826. if(data[4 * i + 1] !== g){
  40827. data[4 * i + 1] = g;
  40828. valuesChanged = true;
  40829. }
  40830. if(data[4 * i + 2] !== b){
  40831. data[4 * i + 2] = b;
  40832. valuesChanged = true;
  40833. }
  40834. if(data[4 * i + 3] !== a){
  40835. data[4 * i + 3] = a;
  40836. valuesChanged = true;
  40837. }
  40838. }
  40839. if(valuesChanged){
  40840. this.classificationTexture.needsUpdate = true;
  40841. this.dispatchEvent({
  40842. type: 'material_property_changed',
  40843. target: this
  40844. });
  40845. }
  40846. }
  40847. get spacing () {
  40848. return this.uniforms.spacing.value;
  40849. }
  40850. set spacing (value) {
  40851. if (this.uniforms.spacing.value !== value) { // 即 uOctreeSpacing 来自cloud.js里
  40852. this.uniforms.spacing.value = value;
  40853. }
  40854. }
  40855. get useClipBox () {
  40856. return this._useClipBox;
  40857. }
  40858. set useClipBox (value) {
  40859. if (this._useClipBox !== value) {
  40860. this._useClipBox = value;
  40861. this.updateShaderSource();
  40862. }
  40863. }
  40864. get clipTask(){
  40865. return this.uniforms.clipTask.value;
  40866. }
  40867. set clipTask(mode){
  40868. this.uniforms.clipTask.value = mode;
  40869. }
  40870. get elevationGradientRepat(){
  40871. return this.uniforms.elevationGradientRepat.value;
  40872. }
  40873. set elevationGradientRepat(mode){
  40874. this.uniforms.elevationGradientRepat.value = mode;
  40875. }
  40876. get clipMethod(){
  40877. return this.uniforms.clipMethod.value;
  40878. }
  40879. set clipMethod(mode){
  40880. this.uniforms.clipMethod.value = mode;
  40881. }
  40882. get weighted(){
  40883. return this._weighted;
  40884. }
  40885. set weighted (value) {
  40886. if (this._weighted !== value) {
  40887. this._weighted = value;
  40888. this.updateShaderSource();
  40889. }
  40890. }
  40891. get fov () {
  40892. return this.uniforms.fov.value;
  40893. }
  40894. set fov (value) {
  40895. if (this.uniforms.fov.value !== value) {
  40896. this.uniforms.fov.value = value;
  40897. // this.updateShaderSource();
  40898. }
  40899. }
  40900. get screenWidth () {
  40901. return this.uniforms.screenWidth.value;
  40902. }
  40903. set screenWidth (value) {
  40904. if (this.uniforms.screenWidth.value !== value) {
  40905. this.uniforms.screenWidth.value = value;
  40906. // this.updateShaderSource();
  40907. }
  40908. }
  40909. get screenHeight () {
  40910. return this.uniforms.screenHeight.value;
  40911. }
  40912. set screenHeight (value) {
  40913. if (this.uniforms.screenHeight.value !== value) {
  40914. this.uniforms.screenHeight.value = value;
  40915. // this.updateShaderSource();
  40916. }
  40917. }
  40918. get near () {
  40919. return this.uniforms.near.value;
  40920. }
  40921. set near (value) {
  40922. if (this.uniforms.near.value !== value) {
  40923. this.uniforms.near.value = value;
  40924. }
  40925. }
  40926. get far () {
  40927. return this.uniforms.far.value;
  40928. }
  40929. set far (value) {
  40930. if (this.uniforms.far.value !== value) {
  40931. this.uniforms.far.value = value;
  40932. }
  40933. }
  40934. get opacity(){
  40935. return this.uniforms.uOpacity.value;
  40936. }
  40937. set opacity (value) {
  40938. if (this.uniforms && this.uniforms.uOpacity) {
  40939. if (this.uniforms.uOpacity.value !== value) {
  40940. this.uniforms.uOpacity.value = value;
  40941. this.updateShaderSource();
  40942. this.dispatchEvent({
  40943. type: 'opacity_changed',
  40944. target: this
  40945. });
  40946. this.dispatchEvent({
  40947. type: 'material_property_changed',
  40948. target: this
  40949. });
  40950. }
  40951. }
  40952. }
  40953. get activeAttributeName(){
  40954. return this._activeAttributeName;
  40955. }
  40956. set activeAttributeName(value){
  40957. if (this._activeAttributeName !== value) {
  40958. this._activeAttributeName = value;
  40959. this.updateShaderSource();
  40960. this.dispatchEvent({
  40961. type: 'active_attribute_changed',
  40962. target: this
  40963. });
  40964. this.dispatchEvent({
  40965. type: 'material_property_changed',
  40966. target: this
  40967. });
  40968. }
  40969. }
  40970. get pointSizeType () {
  40971. return this._pointSizeType;
  40972. }
  40973. set pointSizeType (value) {
  40974. if (this._pointSizeType !== value) {
  40975. this._pointSizeType = value;
  40976. this.updateShaderSource(); //这句表明这个属性频繁更改会卡顿
  40977. this.dispatchEvent({
  40978. type: 'point_size_type_changed',
  40979. target: this
  40980. });
  40981. this.dispatchEvent({
  40982. type: 'material_property_changed',
  40983. target: this
  40984. });
  40985. }
  40986. }
  40987. get useEDL(){
  40988. return this._useEDL;
  40989. }
  40990. set useEDL (value) {
  40991. if (this._useEDL !== value) {
  40992. this._useEDL = value;
  40993. this.updateShaderSource();
  40994. }
  40995. }
  40996. get color () {
  40997. return this.uniforms.uColor.value;
  40998. }
  40999. set color (value) {
  41000. if (!this.uniforms.uColor.value.equals(value)) {
  41001. this.uniforms.uColor.value.copy(value);
  41002. this.dispatchEvent({
  41003. type: 'color_changed',
  41004. target: this
  41005. });
  41006. this.dispatchEvent({
  41007. type: 'material_property_changed',
  41008. target: this
  41009. });
  41010. }
  41011. }
  41012. get shape () {
  41013. return this._shape;
  41014. }
  41015. set shape (value) {
  41016. if (this._shape !== value) {
  41017. this._shape = value;
  41018. this.updateShaderSource();
  41019. this.dispatchEvent({type: 'point_shape_changed', target: this});
  41020. this.dispatchEvent({
  41021. type: 'material_property_changed',
  41022. target: this
  41023. });
  41024. }
  41025. }
  41026. get treeType () {
  41027. return this._treeType;
  41028. }
  41029. set treeType (value) {
  41030. if (this._treeType !== value) {
  41031. this._treeType = value;
  41032. this.updateShaderSource();
  41033. }
  41034. }
  41035. get bbSize () {
  41036. return this.uniforms.bbSize.value;
  41037. }
  41038. set bbSize (value) {
  41039. this.uniforms.bbSize.value = value;
  41040. }
  41041. get size () {
  41042. return this.uniforms.size.value;
  41043. }
  41044. set size (value) {
  41045. if (this.uniforms.size.value !== value) {
  41046. this.uniforms.size.value = value;
  41047. this.dispatchEvent({
  41048. type: 'point_size_changed',
  41049. target: this
  41050. });
  41051. this.dispatchEvent({
  41052. type: 'material_property_changed',
  41053. target: this
  41054. });
  41055. }
  41056. }
  41057. get minSize(){
  41058. return this.uniforms.minSize.value;
  41059. }
  41060. set minSize(value){
  41061. if (this.uniforms.minSize.value !== value) {
  41062. this.uniforms.minSize.value = value;
  41063. this.dispatchEvent({
  41064. type: 'point_size_changed',
  41065. target: this
  41066. });
  41067. this.dispatchEvent({
  41068. type: 'material_property_changed',
  41069. target: this
  41070. });
  41071. }
  41072. }
  41073. get elevationRange () {
  41074. return this.uniforms.elevationRange.value;
  41075. }
  41076. set elevationRange (value) {
  41077. let changed = this.uniforms.elevationRange.value[0] !== value[0]
  41078. || this.uniforms.elevationRange.value[1] !== value[1];
  41079. if(changed){
  41080. this.uniforms.elevationRange.value = value;
  41081. this._defaultElevationRangeChanged = true;
  41082. this.dispatchEvent({
  41083. type: 'material_property_changed',
  41084. target: this
  41085. });
  41086. }
  41087. }
  41088. get heightMin () {
  41089. return this.uniforms.elevationRange.value[0];
  41090. }
  41091. set heightMin (value) {
  41092. this.elevationRange = [value, this.elevationRange[1]];
  41093. }
  41094. get heightMax () {
  41095. return this.uniforms.elevationRange.value[1];
  41096. }
  41097. set heightMax (value) {
  41098. this.elevationRange = [this.elevationRange[0], value];
  41099. }
  41100. get transition () {
  41101. return this.uniforms.transition.value;
  41102. }
  41103. set transition (value) {
  41104. this.uniforms.transition.value = value;
  41105. }
  41106. get intensityRange () {
  41107. return this.uniforms.intensityRange.value;
  41108. }
  41109. set intensityRange (value) {
  41110. if (!(value instanceof Array && value.length === 2)) {
  41111. return;
  41112. }
  41113. if (value[0] === this.uniforms.intensityRange.value[0] &&
  41114. value[1] === this.uniforms.intensityRange.value[1]) {
  41115. return;
  41116. }
  41117. this.uniforms.intensityRange.value = value;
  41118. this._defaultIntensityRangeChanged = true;
  41119. this.dispatchEvent({
  41120. type: 'material_property_changed',
  41121. target: this
  41122. });
  41123. }
  41124. get intensityGamma () {
  41125. return this.uniforms.intensity_gbc.value[0];
  41126. }
  41127. set intensityGamma (value) {
  41128. if (this.uniforms.intensity_gbc.value[0] !== value) {
  41129. this.uniforms.intensity_gbc.value[0] = value;
  41130. this.dispatchEvent({
  41131. type: 'material_property_changed',
  41132. target: this
  41133. });
  41134. }
  41135. }
  41136. get intensityContrast () {
  41137. return this.uniforms.intensity_gbc.value[2];
  41138. }
  41139. set intensityContrast (value) {
  41140. if (this.uniforms.intensity_gbc.value[2] !== value) {
  41141. this.uniforms.intensity_gbc.value[2] = value;
  41142. this.dispatchEvent({
  41143. type: 'material_property_changed',
  41144. target: this
  41145. });
  41146. }
  41147. }
  41148. get intensityBrightness () {
  41149. return this.uniforms.intensity_gbc.value[1];
  41150. }
  41151. set intensityBrightness (value) {
  41152. if (this.uniforms.intensity_gbc.value[1] !== value) {
  41153. this.uniforms.intensity_gbc.value[1] = value;
  41154. this.dispatchEvent({
  41155. type: 'material_property_changed',
  41156. target: this
  41157. });
  41158. }
  41159. }
  41160. get rgbGamma () {
  41161. return this.uniforms.uRGB_gbc.value[0];
  41162. }
  41163. set rgbGamma (value) {
  41164. if (this.uniforms.uRGB_gbc.value[0] !== value) {
  41165. this.uniforms.uRGB_gbc.value[0] = value;
  41166. this.dispatchEvent({
  41167. type: 'material_property_changed',
  41168. target: this
  41169. });
  41170. }
  41171. }
  41172. get rgbContrast () {
  41173. return this.uniforms.uRGB_gbc.value[2];
  41174. }
  41175. set rgbContrast (value) {
  41176. if (this.uniforms.uRGB_gbc.value[2] !== value) {
  41177. this.uniforms.uRGB_gbc.value[2] = value;
  41178. this.dispatchEvent({
  41179. type: 'material_property_changed',
  41180. target: this
  41181. });
  41182. }
  41183. }
  41184. get rgbBrightness () {
  41185. return this.uniforms.uRGB_gbc.value[1];
  41186. }
  41187. set rgbBrightness (value) {
  41188. if (this.uniforms.uRGB_gbc.value[1] !== value) {
  41189. this.uniforms.uRGB_gbc.value[1] = value;
  41190. this.dispatchEvent({
  41191. type: 'material_property_changed',
  41192. target: this
  41193. });
  41194. }
  41195. }
  41196. get extraGamma () {
  41197. return this.uniforms.uExtraGammaBrightContr.value[0];
  41198. }
  41199. set extraGamma (value) {
  41200. if (this.uniforms.uExtraGammaBrightContr.value[0] !== value) {
  41201. this.uniforms.uExtraGammaBrightContr.value[0] = value;
  41202. this.dispatchEvent({
  41203. type: 'material_property_changed',
  41204. target: this
  41205. });
  41206. }
  41207. }
  41208. get extraBrightness () {
  41209. return this.uniforms.uExtraGammaBrightContr.value[1];
  41210. }
  41211. set extraBrightness (value) {
  41212. if (this.uniforms.uExtraGammaBrightContr.value[1] !== value) {
  41213. this.uniforms.uExtraGammaBrightContr.value[1] = value;
  41214. this.dispatchEvent({
  41215. type: 'material_property_changed',
  41216. target: this
  41217. });
  41218. }
  41219. }
  41220. get extraContrast () {
  41221. return this.uniforms.uExtraGammaBrightContr.value[2];
  41222. }
  41223. set extraContrast (value) {
  41224. if (this.uniforms.uExtraGammaBrightContr.value[2] !== value) {
  41225. this.uniforms.uExtraGammaBrightContr.value[2] = value;
  41226. this.dispatchEvent({
  41227. type: 'material_property_changed',
  41228. target: this
  41229. });
  41230. }
  41231. }
  41232. getRange(attributeName){
  41233. return this.ranges.get(attributeName);
  41234. }
  41235. setRange(attributeName, newRange){
  41236. let rangeChanged = false;
  41237. let oldRange = this.ranges.get(attributeName);
  41238. if(oldRange != null && newRange != null){
  41239. rangeChanged = oldRange[0] !== newRange[0] || oldRange[1] !== newRange[1];
  41240. }else {
  41241. rangeChanged = true;
  41242. }
  41243. this.ranges.set(attributeName, newRange);
  41244. if(rangeChanged){
  41245. this.dispatchEvent({
  41246. type: 'material_property_changed',
  41247. target: this
  41248. });
  41249. }
  41250. }
  41251. get extraRange () {
  41252. return this.uniforms.uExtraRange.value;
  41253. }
  41254. set extraRange (value) {
  41255. if (!(value instanceof Array && value.length === 2)) {
  41256. return;
  41257. }
  41258. if (value[0] === this.uniforms.uExtraRange.value[0] &&
  41259. value[1] === this.uniforms.uExtraRange.value[1]) {
  41260. return;
  41261. }
  41262. this.uniforms.uExtraRange.value = value;
  41263. this._defaultExtraRangeChanged = true;
  41264. this.dispatchEvent({
  41265. type: 'material_property_changed',
  41266. target: this
  41267. });
  41268. }
  41269. get weightRGB () {
  41270. return this.uniforms.wRGB.value;
  41271. }
  41272. set weightRGB (value) {
  41273. if(this.uniforms.wRGB.value !== value){
  41274. this.uniforms.wRGB.value = value;
  41275. this.dispatchEvent({
  41276. type: 'material_property_changed',
  41277. target: this
  41278. });
  41279. }
  41280. }
  41281. get weightIntensity () {
  41282. return this.uniforms.wIntensity.value;
  41283. }
  41284. set weightIntensity (value) {
  41285. if(this.uniforms.wIntensity.value !== value){
  41286. this.uniforms.wIntensity.value = value;
  41287. this.dispatchEvent({
  41288. type: 'material_property_changed',
  41289. target: this
  41290. });
  41291. }
  41292. }
  41293. get weightElevation () {
  41294. return this.uniforms.wElevation.value;
  41295. }
  41296. set weightElevation (value) {
  41297. if(this.uniforms.wElevation.value !== value){
  41298. this.uniforms.wElevation.value = value;
  41299. this.dispatchEvent({
  41300. type: 'material_property_changed',
  41301. target: this
  41302. });
  41303. }
  41304. }
  41305. get weightClassification () {
  41306. return this.uniforms.wClassification.value;
  41307. }
  41308. set weightClassification (value) {
  41309. if(this.uniforms.wClassification.value !== value){
  41310. this.uniforms.wClassification.value = value;
  41311. this.dispatchEvent({
  41312. type: 'material_property_changed',
  41313. target: this
  41314. });
  41315. }
  41316. }
  41317. get weightReturnNumber () {
  41318. return this.uniforms.wReturnNumber.value;
  41319. }
  41320. set weightReturnNumber (value) {
  41321. if(this.uniforms.wReturnNumber.value !== value){
  41322. this.uniforms.wReturnNumber.value = value;
  41323. this.dispatchEvent({
  41324. type: 'material_property_changed',
  41325. target: this
  41326. });
  41327. }
  41328. }
  41329. get weightSourceID () {
  41330. return this.uniforms.wSourceID.value;
  41331. }
  41332. set weightSourceID (value) {
  41333. if(this.uniforms.wSourceID.value !== value){
  41334. this.uniforms.wSourceID.value = value;
  41335. this.dispatchEvent({
  41336. type: 'material_property_changed',
  41337. target: this
  41338. });
  41339. }
  41340. }
  41341. static generateGradientTexture (gradient) {
  41342. let size = 64;
  41343. // create canvas
  41344. let canvas = document.createElement('canvas');
  41345. canvas.width = size;
  41346. canvas.height = size;
  41347. // get context
  41348. let context = canvas.getContext('2d');
  41349. // draw gradient
  41350. context.rect(0, 0, size, size);
  41351. let ctxGradient = context.createLinearGradient(0, 0, size, size);
  41352. for (let i = 0; i < gradient.length; i++) {
  41353. let step = gradient[i];
  41354. ctxGradient.addColorStop(step[0], '#' + step[1].getHexString());
  41355. }
  41356. context.fillStyle = ctxGradient;
  41357. context.fill();
  41358. //let texture = new THREE.Texture(canvas);
  41359. let texture = new CanvasTexture(canvas);
  41360. texture.needsUpdate = true;
  41361. texture.minFilter = LinearFilter;
  41362. texture.wrap = RepeatWrapping;
  41363. texture.repeat = 2;
  41364. // textureImage = texture.image;
  41365. return texture;
  41366. }
  41367. static generateMatcapTexture (matcap) {
  41368. var url = new URL(Potree.resourcePath + "/textures/matcap/" + matcap).href;
  41369. let texture = new TextureLoader().load( url );
  41370. texture.magFilter = texture.minFilter = LinearFilter;
  41371. texture.needsUpdate = true;
  41372. // 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
  41373. // Switch matcap texture on the fly : viewer.scene.pointclouds[0].material.matcap = 'matcap1.jpg';
  41374. // 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
  41375. return texture;
  41376. }
  41377. disableEvents(){
  41378. if(this._hiddenListeners === undefined){
  41379. this._hiddenListeners = this._listeners;
  41380. this._listeners = {};
  41381. }
  41382. };
  41383. enableEvents(){
  41384. this._listeners = this._hiddenListeners;
  41385. this._hiddenListeners = undefined;
  41386. };
  41387. // copyFrom(from){
  41388. // var a = 10;
  41389. // for(let name of Object.keys(this.uniforms)){
  41390. // this.uniforms[name].value = from.uniforms[name].value;
  41391. // }
  41392. // }
  41393. // copy(from){
  41394. // this.copyFrom(from);
  41395. // }
  41396. }
  41397. //见ExtendPointCloudOctree
  41398. class PointCloudOctreeNode extends PointCloudTreeNode {
  41399. constructor () {
  41400. super();
  41401. //this.children = {};
  41402. this.children = [];
  41403. this.sceneNode = null;
  41404. this.octree = null;
  41405. }
  41406. getNumPoints () {
  41407. return this.geometryNode.numPoints;
  41408. }
  41409. isLoaded () {
  41410. return true;
  41411. }
  41412. isTreeNode () {
  41413. return true;
  41414. }
  41415. isGeometryNode () {
  41416. return false;
  41417. }
  41418. getLevel () {
  41419. return this.geometryNode.level;
  41420. }
  41421. getBoundingSphere () {
  41422. return this.geometryNode.boundingSphere;
  41423. }
  41424. getBoundingBox () {
  41425. return this.geometryNode.boundingBox;
  41426. }
  41427. getChildren () {
  41428. let children = [];
  41429. for (let i = 0; i < 8; i++) {
  41430. if (this.children[i]) {
  41431. children.push(this.children[i]);
  41432. }
  41433. }
  41434. return children;
  41435. }
  41436. getPointsInBox(boxNode){
  41437. if(!this.sceneNode){
  41438. return null;
  41439. }
  41440. let buffer = this.geometryNode.buffer;
  41441. let posOffset = buffer.offset("position");
  41442. let stride = buffer.stride;
  41443. let view = new DataView(buffer.data);
  41444. let worldToBox = boxNode.matrixWorld.clone().invert();
  41445. let objectToBox = new Matrix4().multiplyMatrices(worldToBox, this.sceneNode.matrixWorld);
  41446. let inBox = [];
  41447. let pos = new Vector4();
  41448. for(let i = 0; i < buffer.numElements; i++){
  41449. let x = view.getFloat32(i * stride + posOffset + 0, true);
  41450. let y = view.getFloat32(i * stride + posOffset + 4, true);
  41451. let z = view.getFloat32(i * stride + posOffset + 8, true);
  41452. pos.set(x, y, z, 1);
  41453. pos.applyMatrix4(objectToBox);
  41454. if(-0.5 < pos.x && pos.x < 0.5){
  41455. if(-0.5 < pos.y && pos.y < 0.5){
  41456. if(-0.5 < pos.z && pos.z < 0.5){
  41457. pos.set(x, y, z, 1).applyMatrix4(this.sceneNode.matrixWorld);
  41458. inBox.push(new Vector3(pos.x, pos.y, pos.z));
  41459. }
  41460. }
  41461. }
  41462. }
  41463. return inBox;
  41464. }
  41465. get name () {
  41466. return this.geometryNode.name;
  41467. }
  41468. };
  41469. class PointCloudOctree extends PointCloudTree {//base
  41470. constructor (geometry, material) {
  41471. super();
  41472. this.pointBudget = Infinity; //一直是这个值
  41473. this.pcoGeometry = geometry;
  41474. this.boundingBox = this.pcoGeometry.boundingBox;
  41475. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  41476. this.material = material || new PointCloudMaterial$1();
  41477. this.visiblePointsTarget = 2 * 1000 * 1000;
  41478. this.minimumNodePixelSize = 150;
  41479. this.level = 0;
  41480. this.position.copy(geometry.offset);
  41481. this.updateMatrix();
  41482. {
  41483. let priorityQueue = ["rgba", "rgb", "intensity", "classification"];
  41484. let selected = "rgba";
  41485. for(let attributeName of priorityQueue){
  41486. let attribute = this.pcoGeometry.pointAttributes.attributes.find(a => a.name === attributeName);
  41487. if(!attribute){
  41488. continue;
  41489. }
  41490. let min = attribute.range[0].constructor.name === "Array" ? attribute.range[0] : [attribute.range[0]];
  41491. let max = attribute.range[1].constructor.name === "Array" ? attribute.range[1] : [attribute.range[1]];
  41492. let range_min = new Vector3(...min);
  41493. let range_max = new Vector3(...max);
  41494. let range = range_min.distanceTo(range_max);
  41495. if(range === 0){
  41496. continue;
  41497. }
  41498. selected = attributeName;
  41499. break;
  41500. }
  41501. this.material.activeAttributeName = selected;
  41502. }
  41503. this.showBoundingBox = false;
  41504. this.boundingBoxNodes = [];
  41505. this.loadQueue = [];
  41506. this.visibleBounds = new Box3();
  41507. this.visibleNodes = [];
  41508. this.visibleGeometry = [];
  41509. this.generateDEM = false;
  41510. this.profileRequests = [];
  41511. this.name = '';
  41512. this._visible = true;
  41513. {
  41514. let box = [this.pcoGeometry.tightBoundingBox, this.getBoundingBoxWorld()]
  41515. .find(v => v !== undefined);
  41516. this.updateMatrixWorld(true);
  41517. box = Utils.computeTransformedBoundingBox(box, this.matrixWorld);
  41518. let bMin = box.min.z;
  41519. let bMax = box.max.z;
  41520. this.material.heightMin = bMin;
  41521. this.material.heightMax = bMax;
  41522. }
  41523. // TODO read projection from file instead
  41524. this.projection = geometry.projection;
  41525. this.fallbackProjection = geometry.fallbackProjection;
  41526. this.root = this.pcoGeometry.root;
  41527. }
  41528. setName (name) {
  41529. if (this.name !== name) {
  41530. this.name = name;
  41531. this.dispatchEvent({type: 'name_changed', name: name, pointcloud: this});
  41532. }
  41533. }
  41534. getName () {
  41535. return this.name;
  41536. }
  41537. getAttribute(name){
  41538. const attribute = this.pcoGeometry.pointAttributes.attributes.find(a => a.name === name);
  41539. if(attribute){
  41540. return attribute;
  41541. }else {
  41542. return null;
  41543. }
  41544. }
  41545. getAttributes(){
  41546. return this.pcoGeometry.pointAttributes;
  41547. }
  41548. toTreeNode (geometryNode, parent) {
  41549. let node = new PointCloudOctreeNode();
  41550. // if(geometryNode.name === "r40206"){
  41551. // console.log("creating node for r40206");
  41552. // }
  41553. let sceneNode = new Points(geometryNode.geometry, this.material);
  41554. sceneNode.name = geometryNode.name;
  41555. sceneNode.position.copy(geometryNode.boundingBox.min);
  41556. sceneNode.frustumCulled = false;
  41557. sceneNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
  41558. if (material.program) {
  41559. _this.getContext().useProgram(material.program.program);
  41560. if (material.program.getUniforms().map.level) {
  41561. let level = geometryNode.getLevel();
  41562. material.uniforms.level.value = level;
  41563. material.program.getUniforms().map.level.setValue(_this.getContext(), level);
  41564. }
  41565. if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
  41566. let vnStart = this.visibleNodeTextureOffsets.get(node);
  41567. material.uniforms.vnStart.value = vnStart;
  41568. material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
  41569. }
  41570. if (material.program.getUniforms().map.pcIndex) {
  41571. let i = node.pcIndex ? node.pcIndex : this.visibleNodes.indexOf(node);
  41572. material.uniforms.pcIndex.value = i;
  41573. material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), i);
  41574. }
  41575. }
  41576. };
  41577. // { // DEBUG
  41578. // let sg = new THREE.SphereGeometry(1, 16, 16);
  41579. // let sm = new THREE.MeshNormalMaterial();
  41580. // let s = new THREE.Mesh(sg, sm);
  41581. // s.scale.set(5, 5, 5);
  41582. // s.position.copy(geometryNode.mean)
  41583. // .add(this.position)
  41584. // .add(geometryNode.boundingBox.min);
  41585. //
  41586. // viewer.scene.scene.add(s);
  41587. // }
  41588. node.geometryNode = geometryNode;
  41589. node.sceneNode = sceneNode;
  41590. node.pointcloud = this;
  41591. node.children = [];
  41592. //for (let key in geometryNode.children) {
  41593. // node.children[key] = geometryNode.children[key];
  41594. //}
  41595. for(let i = 0; i < 8; i++){
  41596. node.children[i] = geometryNode.children[i];
  41597. }
  41598. if (!parent) {
  41599. this.root = node;
  41600. this.add(sceneNode);
  41601. } else {
  41602. let childIndex = parseInt(geometryNode.name[geometryNode.name.length - 1]);
  41603. parent.sceneNode.add(sceneNode);
  41604. parent.children[childIndex] = node;
  41605. }
  41606. let disposeListener = function () {
  41607. let childIndex = parseInt(geometryNode.name[geometryNode.name.length - 1]);
  41608. parent.sceneNode.remove(node.sceneNode);
  41609. parent.children[childIndex] = geometryNode;
  41610. };
  41611. geometryNode.oneTimeDisposeHandlers.push(disposeListener);
  41612. return node;
  41613. }
  41614. updateVisibleBounds () {
  41615. let leafNodes = [];
  41616. for (let i = 0; i < this.visibleNodes.length; i++) {
  41617. let node = this.visibleNodes[i];
  41618. let isLeaf = true;
  41619. for (let j = 0; j < node.children.length; j++) {
  41620. let child = node.children[j];
  41621. if (child instanceof PointCloudOctreeNode) {
  41622. isLeaf = isLeaf && !child.sceneNode.visible;
  41623. } else if (child instanceof PointCloudOctreeGeometryNode) {
  41624. isLeaf = true;
  41625. }
  41626. }
  41627. if (isLeaf) {
  41628. leafNodes.push(node);
  41629. }
  41630. }
  41631. this.visibleBounds.min = new Vector3(Infinity, Infinity, Infinity);
  41632. this.visibleBounds.max = new Vector3(-Infinity, -Infinity, -Infinity);
  41633. for (let i = 0; i < leafNodes.length; i++) {
  41634. let node = leafNodes[i];
  41635. this.visibleBounds.expandByPoint(node.getBoundingBox().min);
  41636. this.visibleBounds.expandByPoint(node.getBoundingBox().max);
  41637. }
  41638. }
  41639. updateMaterial (material, visibleNodes, camera, renderer) {
  41640. material.fov = camera.fov * (Math.PI / 180);
  41641. material.screenWidth = renderer.domElement.clientWidth;
  41642. material.screenHeight = renderer.domElement.clientHeight;
  41643. material.spacing = this.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z);
  41644. material.near = camera.near;
  41645. material.far = camera.far;
  41646. material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  41647. }
  41648. computeVisibilityTextureData(nodes, camera){
  41649. if(Potree.measureTimings) performance.mark("computeVisibilityTextureData-start");
  41650. let data = new Uint8Array(nodes.length * 4);
  41651. let visibleNodeTextureOffsets = new Map();
  41652. // copy array
  41653. nodes = nodes.slice();
  41654. // sort by level and index, e.g. r, r0, r3, r4, r01, r07, r30, ...
  41655. let sort = function (a, b) {
  41656. let na = a.geometryNode.name;
  41657. let nb = b.geometryNode.name;
  41658. if (na.length !== nb.length) return na.length - nb.length;
  41659. if (na < nb) return -1;
  41660. if (na > nb) return 1;
  41661. return 0;
  41662. };
  41663. nodes.sort(sort);
  41664. let worldDir = new Vector3();
  41665. let nodeMap = new Map();
  41666. let offsetsToChild = new Array(nodes.length).fill(Infinity);
  41667. for(let i = 0; i < nodes.length; i++){
  41668. let node = nodes[i];
  41669. nodeMap.set(node.name, node);
  41670. visibleNodeTextureOffsets.set(node, i);
  41671. if(i > 0){
  41672. let index = parseInt(node.name.slice(-1));
  41673. let parentName = node.name.slice(0, -1);
  41674. let parent = nodeMap.get(parentName);
  41675. let parentOffset = visibleNodeTextureOffsets.get(parent);
  41676. let parentOffsetToChild = (i - parentOffset);
  41677. offsetsToChild[parentOffset] = Math.min(offsetsToChild[parentOffset], parentOffsetToChild);
  41678. data[parentOffset * 4 + 0] = data[parentOffset * 4 + 0] | (1 << index);
  41679. data[parentOffset * 4 + 1] = (offsetsToChild[parentOffset] >> 8);
  41680. data[parentOffset * 4 + 2] = (offsetsToChild[parentOffset] % 256);
  41681. }
  41682. let density = node.geometryNode.density;
  41683. if(typeof density === "number"){
  41684. let lodOffset = Math.log2(density) / 2 - 1.5;
  41685. let offsetUint8 = (lodOffset + 10) * 10;
  41686. data[i * 4 + 3] = offsetUint8;
  41687. }else {
  41688. data[i * 4 + 3] = 100;
  41689. }
  41690. }
  41691. if(Potree.measureTimings){
  41692. performance.mark("computeVisibilityTextureData-end");
  41693. performance.measure("render.computeVisibilityTextureData", "computeVisibilityTextureData-start", "computeVisibilityTextureData-end");
  41694. }
  41695. return {
  41696. data: data,
  41697. offsets: visibleNodeTextureOffsets
  41698. };
  41699. }
  41700. nodeIntersectsProfile (node, profile) {
  41701. let bbWorld = node.boundingBox.clone().applyMatrix4(this.matrixWorld);
  41702. let bsWorld = bbWorld.getBoundingSphere(new Sphere());
  41703. let intersects = false;
  41704. for (let i = 0; i < profile.points.length - 1; i++) {
  41705. let start = new Vector3(profile.points[i + 0].x, profile.points[i + 0].y, bsWorld.center.z);
  41706. let end = new Vector3(profile.points[i + 1].x, profile.points[i + 1].y, bsWorld.center.z);
  41707. let closest = new Line3(start, end).closestPointToPoint(bsWorld.center, true, new Vector3());
  41708. let distance = closest.distanceTo(bsWorld.center);
  41709. intersects = intersects || (distance < (bsWorld.radius + profile.width));
  41710. }
  41711. //console.log(`${node.name}: ${intersects}`);
  41712. return intersects;
  41713. }
  41714. deepestNodeAt(position){
  41715. const toObjectSpace = this.matrixWorld.clone().invert();
  41716. const objPos = position.clone().applyMatrix4(toObjectSpace);
  41717. let current = this.root;
  41718. while(true){
  41719. let containingChild = null;
  41720. for(const child of current.children){
  41721. if(child !== undefined){
  41722. if(child.getBoundingBox().containsPoint(objPos)){
  41723. containingChild = child;
  41724. }
  41725. }
  41726. }
  41727. if(containingChild !== null && containingChild instanceof PointCloudOctreeNode){
  41728. current = containingChild;
  41729. }else {
  41730. break;
  41731. }
  41732. }
  41733. const deepest = current;
  41734. return deepest;
  41735. }
  41736. nodesOnRay (nodes, ray) {
  41737. let nodesOnRay = [];
  41738. let _ray = ray.clone();
  41739. for (let i = 0; i < nodes.length; i++) {
  41740. let node = nodes[i];
  41741. let sphere = node.getBoundingSphere().clone().applyMatrix4(this.matrixWorld);
  41742. if (_ray.intersectsSphere(sphere)) {
  41743. nodesOnRay.push(node);
  41744. }
  41745. }
  41746. return nodesOnRay;
  41747. }
  41748. updateMatrixWorld (force) {
  41749. if (this.matrixAutoUpdate === true) this.updateMatrix();
  41750. if (this.matrixWorldNeedsUpdate === true || force === true) {
  41751. if (!this.parent) {
  41752. this.matrixWorld.copy(this.matrix);
  41753. } else {
  41754. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  41755. }
  41756. this.matrixWorldNeedsUpdate = false;
  41757. force = true;
  41758. }
  41759. }
  41760. hideDescendants (object) {
  41761. let stack = [];
  41762. for (let i = 0; i < object.children.length; i++) {
  41763. let child = object.children[i];
  41764. if (child.visible) {
  41765. stack.push(child);
  41766. }
  41767. }
  41768. while (stack.length > 0) {
  41769. let object = stack.shift();
  41770. object.visible = false;
  41771. for (let i = 0; i < object.children.length; i++) {
  41772. let child = object.children[i];
  41773. if (child.visible) {
  41774. stack.push(child);
  41775. }
  41776. }
  41777. }
  41778. }
  41779. moveToOrigin () {
  41780. this.position.set(0, 0, 0);
  41781. this.updateMatrixWorld(true);
  41782. let box = this.boundingBox;
  41783. let transform = this.matrixWorld;
  41784. let tBox = Utils.computeTransformedBoundingBox(box, transform);
  41785. this.position.set(0, 0, 0).sub(tBox.getCenter(new Vector3()));
  41786. };
  41787. moveToGroundPlane () {
  41788. this.updateMatrixWorld(true);
  41789. let box = this.boundingBox;
  41790. let transform = this.matrixWorld;
  41791. let tBox = Utils.computeTransformedBoundingBox(box, transform);
  41792. this.position.y += -tBox.min.y;
  41793. };
  41794. getBoundingBoxWorld () {
  41795. this.updateMatrixWorld(true);
  41796. let box = this.boundingBox;
  41797. let transform = this.matrixWorld;
  41798. let tBox = Utils.computeTransformedBoundingBox(box, transform);
  41799. return tBox;
  41800. };
  41801. /**
  41802. * returns points inside the profile points
  41803. *
  41804. * maxDepth: search points up to the given octree depth
  41805. *
  41806. *
  41807. * The return value is an array with all segments of the profile path
  41808. * let segment = {
  41809. * start: THREE.Vector3,
  41810. * end: THREE.Vector3,
  41811. * points: {}
  41812. * project: function()
  41813. * };
  41814. *
  41815. * The project() function inside each segment can be used to transform
  41816. * that segments point coordinates to line up along the x-axis.
  41817. *
  41818. *
  41819. */
  41820. getPointsInProfile (profile, maxDepth, callback) {
  41821. if (callback) {
  41822. let request = new Potree.ProfileRequest(this, profile, maxDepth, callback);
  41823. this.profileRequests.push(request);
  41824. return request;
  41825. }
  41826. let points = {
  41827. segments: [],
  41828. boundingBox: new Box3(),
  41829. projectedBoundingBox: new Box2()
  41830. };
  41831. // evaluate segments
  41832. for (let i = 0; i < profile.points.length - 1; i++) {
  41833. let start = profile.points[i];
  41834. let end = profile.points[i + 1];
  41835. let ps = this.getProfile(start, end, profile.width, maxDepth);
  41836. let segment = {
  41837. start: start,
  41838. end: end,
  41839. points: ps,
  41840. project: null
  41841. };
  41842. points.segments.push(segment);
  41843. points.boundingBox.expandByPoint(ps.boundingBox.min);
  41844. points.boundingBox.expandByPoint(ps.boundingBox.max);
  41845. }
  41846. // add projection functions to the segments
  41847. let mileage = new Vector3();
  41848. for (let i = 0; i < points.segments.length; i++) {
  41849. let segment = points.segments[i];
  41850. let start = segment.start;
  41851. let end = segment.end;
  41852. let project = (function (_start, _end, _mileage, _boundingBox) {
  41853. let start = _start;
  41854. let end = _end;
  41855. let mileage = _mileage;
  41856. let boundingBox = _boundingBox;
  41857. let xAxis = new Vector3(1, 0, 0);
  41858. let dir = new Vector3().subVectors(end, start);
  41859. dir.y = 0;
  41860. dir.normalize();
  41861. let alpha = Math.acos(xAxis.dot(dir));
  41862. if (dir.z > 0) {
  41863. alpha = -alpha;
  41864. }
  41865. return function (position) {
  41866. let toOrigin = new Matrix4().makeTranslation(-start.x, -boundingBox.min.y, -start.z);
  41867. let alignWithX = new Matrix4().makeRotationY(-alpha);
  41868. let applyMileage = new Matrix4().makeTranslation(mileage.x, 0, 0);
  41869. let pos = position.clone();
  41870. pos.applyMatrix4(toOrigin);
  41871. pos.applyMatrix4(alignWithX);
  41872. pos.applyMatrix4(applyMileage);
  41873. return pos;
  41874. };
  41875. }(start, end, mileage.clone(), points.boundingBox.clone()));
  41876. segment.project = project;
  41877. mileage.x += new Vector3(start.x, 0, start.z).distanceTo(new Vector3(end.x, 0, end.z));
  41878. mileage.y += end.y - start.y;
  41879. }
  41880. points.projectedBoundingBox.min.x = 0;
  41881. points.projectedBoundingBox.min.y = points.boundingBox.min.y;
  41882. points.projectedBoundingBox.max.x = mileage.x;
  41883. points.projectedBoundingBox.max.y = points.boundingBox.max.y;
  41884. return points;
  41885. }
  41886. /**
  41887. * returns points inside the given profile bounds.
  41888. *
  41889. * start:
  41890. * end:
  41891. * width:
  41892. * depth: search points up to the given octree depth
  41893. * callback: if specified, points are loaded before searching
  41894. *
  41895. *
  41896. */
  41897. getProfile (start, end, width, depth, callback) {
  41898. let request = new Potree.ProfileRequest(start, end, width, depth, callback);
  41899. this.profileRequests.push(request);
  41900. };
  41901. getVisibleExtent () {
  41902. return this.visibleBounds.applyMatrix4(this.matrixWorld);
  41903. };
  41904. intersectsPoint(position){
  41905. let rootAvailable = this.pcoGeometry.root && this.pcoGeometry.root.geometry;
  41906. if(!rootAvailable){
  41907. return false;
  41908. }
  41909. if(typeof this.signedDistanceField === "undefined"){
  41910. const resolution = 32;
  41911. const field = new Float32Array(resolution ** 3).fill(Infinity);
  41912. const positions = this.pcoGeometry.root.geometry.attributes.position;
  41913. const boundingBox = this.boundingBox;
  41914. const n = positions.count;
  41915. for(let i = 0; i < n; i = i + 3){
  41916. const x = positions.array[3 * i + 0];
  41917. const y = positions.array[3 * i + 1];
  41918. const z = positions.array[3 * i + 2];
  41919. const ix = parseInt(Math.min(resolution * (x / boundingBox.max.x), resolution - 1));
  41920. const iy = parseInt(Math.min(resolution * (y / boundingBox.max.y), resolution - 1));
  41921. const iz = parseInt(Math.min(resolution * (z / boundingBox.max.z), resolution - 1));
  41922. const index = ix + iy * resolution + iz * resolution * resolution;
  41923. field[index] = 0;
  41924. }
  41925. const sdf = {
  41926. resolution: resolution,
  41927. field: field,
  41928. };
  41929. this.signedDistanceField = sdf;
  41930. }
  41931. {
  41932. const sdf = this.signedDistanceField;
  41933. const boundingBox = this.boundingBox;
  41934. const toObjectSpace = this.matrixWorld.clone().invert();
  41935. const objPos = position.clone().applyMatrix4(toObjectSpace);
  41936. const resolution = sdf.resolution;
  41937. const ix = parseInt(resolution * (objPos.x / boundingBox.max.x));
  41938. const iy = parseInt(resolution * (objPos.y / boundingBox.max.y));
  41939. const iz = parseInt(resolution * (objPos.z / boundingBox.max.z));
  41940. if(ix < 0 || iy < 0 || iz < 0){
  41941. return false;
  41942. }
  41943. if(ix >= resolution || iy >= resolution || iz >= resolution){
  41944. return false;
  41945. }
  41946. const index = ix + iy * resolution + iz * resolution * resolution;
  41947. const value = sdf.field[index];
  41948. if(value === 0){
  41949. return true;
  41950. }
  41951. }
  41952. return false;
  41953. }
  41954. /**
  41955. *
  41956. *
  41957. *
  41958. * params.pickWindowSize: Look for points inside a pixel window of this size.
  41959. * Use odd values: 1, 3, 5, ...
  41960. *
  41961. *
  41962. * TODO: only draw pixels that are actually read with readPixels().
  41963. *
  41964. */
  41965. pick(viewer, camera, ray, params = {}){
  41966. let renderer = viewer.renderer;
  41967. let pRenderer = viewer.pRenderer;
  41968. performance.mark("pick-start");
  41969. let getVal = (a, b) => a !== undefined ? a : b;
  41970. let pickWindowSize = getVal(params.pickWindowSize, 65);
  41971. let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
  41972. let size = renderer.getSize(new Vector2());
  41973. let width = Math.ceil(getVal(params.width, size.width));
  41974. let height = Math.ceil(getVal(params.height, size.height));
  41975. let pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
  41976. let pointSize = getVal(params.pointSize, this.material.size);
  41977. let nodes = this.nodesOnRay(this.visibleNodes, ray);
  41978. if (nodes.length === 0) {
  41979. return null;
  41980. }
  41981. if (!this.pickState) {
  41982. let scene = new Scene();
  41983. let material = new Potree.PointCloudMaterial();
  41984. material.activeAttributeName = "indices";
  41985. let renderTarget = new WebGLRenderTarget(
  41986. 1, 1,
  41987. { minFilter: LinearFilter,
  41988. magFilter: NearestFilter,
  41989. format: RGBAFormat }
  41990. );
  41991. this.pickState = {
  41992. renderTarget: renderTarget,
  41993. material: material,
  41994. scene: scene
  41995. };
  41996. };
  41997. let pickState = this.pickState;
  41998. let pickMaterial = pickState.material;
  41999. { // update pick material
  42000. pickMaterial.pointSizeType = pointSizeType;
  42001. //pickMaterial.shape = this.material.shape;
  42002. pickMaterial.shape = Potree.PointShape.PARABOLOID;
  42003. pickMaterial.uniforms.uFilterReturnNumberRange.value = this.material.uniforms.uFilterReturnNumberRange.value;
  42004. pickMaterial.uniforms.uFilterNumberOfReturnsRange.value = this.material.uniforms.uFilterNumberOfReturnsRange.value;
  42005. pickMaterial.uniforms.uFilterGPSTimeClipRange.value = this.material.uniforms.uFilterGPSTimeClipRange.value;
  42006. pickMaterial.uniforms.uFilterPointSourceIDClipRange.value = this.material.uniforms.uFilterPointSourceIDClipRange.value;
  42007. pickMaterial.activeAttributeName = "indices";
  42008. pickMaterial.size = pointSize;
  42009. pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
  42010. pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
  42011. pickMaterial.classification = this.material.classification;
  42012. pickMaterial.recomputeClassification();
  42013. if(params.pickClipped){
  42014. pickMaterial.clipBoxes = this.material.clipBoxes;
  42015. pickMaterial.uniforms.clipBoxes = this.material.uniforms.clipBoxes;
  42016. if(this.material.clipTask === Potree.ClipTask.HIGHLIGHT){
  42017. pickMaterial.clipTask = Potree.ClipTask.NONE;
  42018. }else {
  42019. pickMaterial.clipTask = this.material.clipTask;
  42020. }
  42021. pickMaterial.clipMethod = this.material.clipMethod;
  42022. }else {
  42023. pickMaterial.clipBoxes = [];
  42024. }
  42025. this.updateMaterial(pickMaterial, nodes, camera, renderer);
  42026. }
  42027. pickState.renderTarget.setSize(width, height);
  42028. let pixelPos = new Vector2(params.x, params.y);
  42029. let gl = renderer.getContext();
  42030. gl.enable(gl.SCISSOR_TEST);
  42031. gl.scissor(
  42032. parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
  42033. parseInt(pixelPos.y - (pickWindowSize - 1) / 2),
  42034. parseInt(pickWindowSize), parseInt(pickWindowSize));
  42035. renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
  42036. renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
  42037. renderer.state.setBlending(NoBlending);
  42038. { // RENDER
  42039. renderer.setRenderTarget(pickState.renderTarget);
  42040. gl.clearColor(0, 0, 0, 0);
  42041. renderer.clear(true, true, true);
  42042. let tmp = this.material;
  42043. this.material = pickMaterial;
  42044. pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget);
  42045. this.material = tmp;
  42046. }
  42047. let clamp = (number, min, max) => Math.min(Math.max(min, number), max);
  42048. let x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
  42049. let y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
  42050. let w = parseInt(Math.min(x + pickWindowSize, width) - x);
  42051. let h = parseInt(Math.min(y + pickWindowSize, height) - y);
  42052. let pixelCount = w * h;
  42053. let buffer = new Uint8Array(4 * pixelCount);
  42054. gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
  42055. renderer.setRenderTarget(null);
  42056. renderer.state.reset();
  42057. renderer.setScissorTest(false);
  42058. gl.disable(gl.SCISSOR_TEST);
  42059. let pixels = buffer;
  42060. let ibuffer = new Uint32Array(buffer.buffer);
  42061. // find closest hit inside pixelWindow boundaries
  42062. let min = Number.MAX_VALUE;
  42063. let hits = [];
  42064. for (let u = 0; u < pickWindowSize; u++) {
  42065. for (let v = 0; v < pickWindowSize; v++) {
  42066. let offset = (u + v * pickWindowSize);
  42067. let distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
  42068. let pcIndex = pixels[4 * offset + 3];
  42069. pixels[4 * offset + 3] = 0;
  42070. let pIndex = ibuffer[offset];
  42071. if(!(pcIndex === 0 && pIndex === 0) && (pcIndex !== undefined) && (pIndex !== undefined)){
  42072. let hit = {
  42073. pIndex: pIndex,
  42074. pcIndex: pcIndex,
  42075. distanceToCenter: distance
  42076. };
  42077. if(params.all){
  42078. hits.push(hit);
  42079. }else {
  42080. if(hits.length > 0){
  42081. if(distance < hits[0].distanceToCenter){
  42082. hits[0] = hit;
  42083. }
  42084. }else {
  42085. hits.push(hit);
  42086. }
  42087. }
  42088. }
  42089. }
  42090. }
  42091. // { // DEBUG: show panel with pick image
  42092. // let img = Utils.pixelsArrayToImage(buffer, w, h);
  42093. // let screenshot = img.src;
  42094. // if(!this.debugDIV){
  42095. // this.debugDIV = $(`
  42096. // <div id="pickDebug"
  42097. // style="position: absolute;
  42098. // right: 400px; width: 300px;
  42099. // bottom: 44px; width: 300px;
  42100. // z-index: 1000;
  42101. // "></div>`);
  42102. // $(document.body).append(this.debugDIV);
  42103. // }
  42104. // this.debugDIV.empty();
  42105. // this.debugDIV.append($(`<img src="${screenshot}"
  42106. // style="transform: scaleY(-1); width: 300px"/>`));
  42107. // //$(this.debugWindow.document).append($(`<img src="${screenshot}"/>`));
  42108. // //this.debugWindow.document.write('<img src="'+screenshot+'"/>');
  42109. // }
  42110. for(let hit of hits){
  42111. let point = {};
  42112. if (!nodes[hit.pcIndex]) {
  42113. return null;
  42114. }
  42115. let node = nodes[hit.pcIndex];
  42116. let pc = node.sceneNode;
  42117. let geometry = node.geometryNode.geometry;
  42118. for(let attributeName in geometry.attributes){
  42119. let attribute = geometry.attributes[attributeName];
  42120. if (attributeName === 'position') {
  42121. let x = attribute.array[3 * hit.pIndex + 0];
  42122. let y = attribute.array[3 * hit.pIndex + 1];
  42123. let z = attribute.array[3 * hit.pIndex + 2];
  42124. let position = new Vector3(x, y, z);
  42125. position.applyMatrix4(pc.matrixWorld);
  42126. point[attributeName] = position;
  42127. } else if (attributeName === 'indices') {
  42128. } else {
  42129. let values = attribute.array.slice(attribute.itemSize * hit.pIndex, attribute.itemSize * (hit.pIndex + 1)) ;
  42130. if(attribute.potree){
  42131. const {scale, offset} = attribute.potree;
  42132. values = values.map(v => v / scale + offset);
  42133. }
  42134. point[attributeName] = values;
  42135. //debugger;
  42136. //if (values.itemSize === 1) {
  42137. // point[attribute.name] = values.array[hit.pIndex];
  42138. //} else {
  42139. // let value = [];
  42140. // for (let j = 0; j < values.itemSize; j++) {
  42141. // value.push(values.array[values.itemSize * hit.pIndex + j]);
  42142. // }
  42143. // point[attribute.name] = value;
  42144. //}
  42145. }
  42146. }
  42147. hit.point = point;
  42148. }
  42149. performance.mark("pick-end");
  42150. performance.measure("pick", "pick-start", "pick-end");
  42151. if(params.all){
  42152. return hits.map(hit => hit.point);
  42153. }else {
  42154. if(hits.length === 0){
  42155. return null;
  42156. }else {
  42157. return hits[0].point;
  42158. //let sorted = hits.sort( (a, b) => a.distanceToCenter - b.distanceToCenter);
  42159. //return sorted[0].point;
  42160. }
  42161. }
  42162. };
  42163. * getFittedBoxGen(boxNode){
  42164. let start = performance.now();
  42165. let shrinkedLocalBounds = new Box3();
  42166. let worldToBox = boxNode.matrixWorld.clone().invert();
  42167. for(let node of this.visibleNodes){
  42168. if(!node.sceneNode){
  42169. continue;
  42170. }
  42171. let buffer = node.geometryNode.buffer;
  42172. let posOffset = buffer.offset("position");
  42173. let stride = buffer.stride;
  42174. let view = new DataView(buffer.data);
  42175. let objectToBox = new Matrix4().multiplyMatrices(worldToBox, node.sceneNode.matrixWorld);
  42176. let pos = new Vector4();
  42177. for(let i = 0; i < buffer.numElements; i++){
  42178. let x = view.getFloat32(i * stride + posOffset + 0, true);
  42179. let y = view.getFloat32(i * stride + posOffset + 4, true);
  42180. let z = view.getFloat32(i * stride + posOffset + 8, true);
  42181. pos.set(x, y, z, 1);
  42182. pos.applyMatrix4(objectToBox);
  42183. if(-0.5 < pos.x && pos.x < 0.5){
  42184. if(-0.5 < pos.y && pos.y < 0.5){
  42185. if(-0.5 < pos.z && pos.z < 0.5){
  42186. shrinkedLocalBounds.expandByPoint(pos);
  42187. }
  42188. }
  42189. }
  42190. }
  42191. yield;
  42192. }
  42193. let fittedPosition = shrinkedLocalBounds.getCenter(new Vector3()).applyMatrix4(boxNode.matrixWorld);
  42194. let fitted = new Object3D();
  42195. fitted.position.copy(fittedPosition);
  42196. fitted.scale.copy(boxNode.scale);
  42197. fitted.rotation.copy(boxNode.rotation);
  42198. let ds = new Vector3().subVectors(shrinkedLocalBounds.max, shrinkedLocalBounds.min);
  42199. fitted.scale.multiply(ds);
  42200. let duration = performance.now() - start;
  42201. console.log("duration: ", duration);
  42202. yield fitted;
  42203. }
  42204. getFittedBox(boxNode, maxLevel = Infinity){
  42205. maxLevel = Infinity;
  42206. let start = performance.now();
  42207. let shrinkedLocalBounds = new Box3();
  42208. let worldToBox = boxNode.matrixWorld.clone().invert();
  42209. for(let node of this.visibleNodes){
  42210. if(!node.sceneNode || node.getLevel() > maxLevel){
  42211. continue;
  42212. }
  42213. let buffer = node.geometryNode.buffer;
  42214. let posOffset = buffer.offset("position");
  42215. let stride = buffer.stride;
  42216. let view = new DataView(buffer.data);
  42217. let objectToBox = new Matrix4().multiplyMatrices(worldToBox, node.sceneNode.matrixWorld);
  42218. let pos = new Vector4();
  42219. for(let i = 0; i < buffer.numElements; i++){
  42220. let x = view.getFloat32(i * stride + posOffset + 0, true);
  42221. let y = view.getFloat32(i * stride + posOffset + 4, true);
  42222. let z = view.getFloat32(i * stride + posOffset + 8, true);
  42223. pos.set(x, y, z, 1);
  42224. pos.applyMatrix4(objectToBox);
  42225. if(-0.5 < pos.x && pos.x < 0.5){
  42226. if(-0.5 < pos.y && pos.y < 0.5){
  42227. if(-0.5 < pos.z && pos.z < 0.5){
  42228. shrinkedLocalBounds.expandByPoint(pos);
  42229. }
  42230. }
  42231. }
  42232. }
  42233. }
  42234. let fittedPosition = shrinkedLocalBounds.getCenter(new Vector3()).applyMatrix4(boxNode.matrixWorld);
  42235. let fitted = new Object3D();
  42236. fitted.position.copy(fittedPosition);
  42237. fitted.scale.copy(boxNode.scale);
  42238. fitted.rotation.copy(boxNode.rotation);
  42239. let ds = new Vector3().subVectors(shrinkedLocalBounds.max, shrinkedLocalBounds.min);
  42240. fitted.scale.multiply(ds);
  42241. let duration = performance.now() - start;
  42242. console.log("duration: ", duration);
  42243. return fitted;
  42244. }
  42245. get progress () {
  42246. return this.visibleNodes.length / this.visibleGeometry.length;
  42247. }
  42248. find(name){
  42249. let node = null;
  42250. for(let char of name){
  42251. if(char === "r"){
  42252. node = this.root;
  42253. }else {
  42254. node = node.children[char];
  42255. }
  42256. }
  42257. return node;
  42258. }
  42259. get visible(){
  42260. return this._visible;
  42261. }
  42262. set visible(value){
  42263. if(value !== this._visible){
  42264. this._visible = value;
  42265. this.dispatchEvent({type: 'visibility_changed', pointcloud: this});
  42266. }
  42267. }
  42268. }
  42269. class PointCloudArena4DNode extends PointCloudTreeNode {
  42270. constructor () {
  42271. super();
  42272. this.left = null;
  42273. this.right = null;
  42274. this.sceneNode = null;
  42275. this.kdtree = null;
  42276. }
  42277. getNumPoints () {
  42278. return this.geometryNode.numPoints;
  42279. }
  42280. isLoaded () {
  42281. return true;
  42282. }
  42283. isTreeNode () {
  42284. return true;
  42285. }
  42286. isGeometryNode () {
  42287. return false;
  42288. }
  42289. getLevel () {
  42290. return this.geometryNode.level;
  42291. }
  42292. getBoundingSphere () {
  42293. return this.geometryNode.boundingSphere;
  42294. }
  42295. getBoundingBox () {
  42296. return this.geometryNode.boundingBox;
  42297. }
  42298. toTreeNode (child) {
  42299. let geometryNode = null;
  42300. if (this.left === child) {
  42301. geometryNode = this.left;
  42302. } else if (this.right === child) {
  42303. geometryNode = this.right;
  42304. }
  42305. if (!geometryNode.loaded) {
  42306. return;
  42307. }
  42308. let node = new PointCloudArena4DNode();
  42309. let sceneNode = PointCloud(geometryNode.geometry, this.kdtree.material);
  42310. sceneNode.visible = false;
  42311. node.kdtree = this.kdtree;
  42312. node.geometryNode = geometryNode;
  42313. node.sceneNode = sceneNode;
  42314. node.parent = this;
  42315. node.left = this.geometryNode.left;
  42316. node.right = this.geometryNode.right;
  42317. }
  42318. getChildren () {
  42319. let children = [];
  42320. if (this.left) {
  42321. children.push(this.left);
  42322. }
  42323. if (this.right) {
  42324. children.push(this.right);
  42325. }
  42326. return children;
  42327. }
  42328. };
  42329. class PointCloudArena4D$1 extends PointCloudTree{
  42330. constructor (geometry) {
  42331. super();
  42332. this.root = null;
  42333. if (geometry.root) {
  42334. this.root = geometry.root;
  42335. } else {
  42336. geometry.addEventListener('hierarchy_loaded', () => {
  42337. this.root = geometry.root;
  42338. });
  42339. }
  42340. this.visiblePointsTarget = 2 * 1000 * 1000;
  42341. this.minimumNodePixelSize = 150;
  42342. this.position.sub(geometry.offset);
  42343. this.updateMatrix();
  42344. this.numVisibleNodes = 0;
  42345. this.numVisiblePoints = 0;
  42346. this.boundingBoxNodes = [];
  42347. this.loadQueue = [];
  42348. this.visibleNodes = [];
  42349. this.pcoGeometry = geometry;
  42350. this.boundingBox = this.pcoGeometry.boundingBox;
  42351. this.boundingSphere = this.pcoGeometry.boundingSphere;
  42352. this.material = new PointCloudMaterial$1({vertexColors: VertexColors, size: 0.05, treeType: TreeType.KDTREE});
  42353. this.material.sizeType = PointSizeType.ATTENUATED;
  42354. this.material.size = 0.05;
  42355. this.profileRequests = [];
  42356. this.name = '';
  42357. }
  42358. getBoundingBoxWorld () {
  42359. this.updateMatrixWorld(true);
  42360. let box = this.boundingBox;
  42361. let transform = this.matrixWorld;
  42362. let tBox = Utils.computeTransformedBoundingBox(box, transform);
  42363. return tBox;
  42364. };
  42365. setName (name) {
  42366. if (this.name !== name) {
  42367. this.name = name;
  42368. this.dispatchEvent({type: 'name_changed', name: name, pointcloud: this});
  42369. }
  42370. }
  42371. getName () {
  42372. return this.name;
  42373. }
  42374. getLevel () {
  42375. return this.level;
  42376. }
  42377. toTreeNode (geometryNode, parent) {
  42378. let node = new PointCloudArena4DNode();
  42379. let sceneNode = new Points(geometryNode.geometry, this.material);
  42380. sceneNode.frustumCulled = false;
  42381. sceneNode.onBeforeRender = (_this, scene, camera, geometry, material, group) => {
  42382. if (material.program) {
  42383. _this.getContext().useProgram(material.program.program);
  42384. if (material.program.getUniforms().map.level) {
  42385. let level = geometryNode.getLevel();
  42386. material.uniforms.level.value = level;
  42387. material.program.getUniforms().map.level.setValue(_this.getContext(), level);
  42388. }
  42389. if (this.visibleNodeTextureOffsets && material.program.getUniforms().map.vnStart) {
  42390. let vnStart = this.visibleNodeTextureOffsets.get(node);
  42391. material.uniforms.vnStart.value = vnStart;
  42392. material.program.getUniforms().map.vnStart.setValue(_this.getContext(), vnStart);
  42393. }
  42394. if (material.program.getUniforms().map.pcIndex) {
  42395. let i = node.pcIndex ? node.pcIndex : this.visibleNodes.indexOf(node);
  42396. material.uniforms.pcIndex.value = i;
  42397. material.program.getUniforms().map.pcIndex.setValue(_this.getContext(), i);
  42398. }
  42399. }
  42400. };
  42401. node.geometryNode = geometryNode;
  42402. node.sceneNode = sceneNode;
  42403. node.pointcloud = this;
  42404. node.left = geometryNode.left;
  42405. node.right = geometryNode.right;
  42406. if (!parent) {
  42407. this.root = node;
  42408. this.add(sceneNode);
  42409. } else {
  42410. parent.sceneNode.add(sceneNode);
  42411. if (parent.left === geometryNode) {
  42412. parent.left = node;
  42413. } else if (parent.right === geometryNode) {
  42414. parent.right = node;
  42415. }
  42416. }
  42417. let disposeListener = function () {
  42418. parent.sceneNode.remove(node.sceneNode);
  42419. if (parent.left === node) {
  42420. parent.left = geometryNode;
  42421. } else if (parent.right === node) {
  42422. parent.right = geometryNode;
  42423. }
  42424. };
  42425. geometryNode.oneTimeDisposeHandlers.push(disposeListener);
  42426. return node;
  42427. }
  42428. updateMaterial (material, visibleNodes, camera, renderer) {
  42429. material.fov = camera.fov * (Math.PI / 180);
  42430. material.screenWidth = renderer.domElement.clientWidth;
  42431. material.screenHeight = renderer.domElement.clientHeight;
  42432. material.spacing = this.pcoGeometry.spacing;
  42433. material.near = camera.near;
  42434. material.far = camera.far;
  42435. // reduce shader source updates by setting maxLevel slightly higher than actually necessary
  42436. if (this.maxLevel > material.levels) {
  42437. material.levels = this.maxLevel + 2;
  42438. }
  42439. // material.uniforms.octreeSize.value = this.boundingBox.size().x;
  42440. let bbSize = this.boundingBox.getSize(new Vector3());
  42441. material.bbSize = [bbSize.x, bbSize.y, bbSize.z];
  42442. }
  42443. updateVisibleBounds () {
  42444. }
  42445. hideDescendants (object) {
  42446. let stack = [];
  42447. for (let i = 0; i < object.children.length; i++) {
  42448. let child = object.children[i];
  42449. if (child.visible) {
  42450. stack.push(child);
  42451. }
  42452. }
  42453. while (stack.length > 0) {
  42454. let child = stack.shift();
  42455. child.visible = false;
  42456. if (child.boundingBoxNode) {
  42457. child.boundingBoxNode.visible = false;
  42458. }
  42459. for (let i = 0; i < child.children.length; i++) {
  42460. let childOfChild = child.children[i];
  42461. if (childOfChild.visible) {
  42462. stack.push(childOfChild);
  42463. }
  42464. }
  42465. }
  42466. }
  42467. updateMatrixWorld (force) {
  42468. // node.matrixWorld.multiplyMatrices( node.parent.matrixWorld, node.matrix );
  42469. if (this.matrixAutoUpdate === true) this.updateMatrix();
  42470. if (this.matrixWorldNeedsUpdate === true || force === true) {
  42471. if (this.parent === undefined) {
  42472. this.matrixWorld.copy(this.matrix);
  42473. } else {
  42474. this.matrixWorld.multiplyMatrices(this.parent.matrixWorld, this.matrix);
  42475. }
  42476. this.matrixWorldNeedsUpdate = false;
  42477. force = true;
  42478. }
  42479. }
  42480. nodesOnRay (nodes, ray) {
  42481. let nodesOnRay = [];
  42482. let _ray = ray.clone();
  42483. for (let i = 0; i < nodes.length; i++) {
  42484. let node = nodes[i];
  42485. let sphere = node.getBoundingSphere().clone().applyMatrix4(node.sceneNode.matrixWorld);
  42486. // TODO Unused: let box = node.getBoundingBox().clone().applyMatrix4(node.sceneNode.matrixWorld);
  42487. if (_ray.intersectsSphere(sphere)) {
  42488. nodesOnRay.push(node);
  42489. }
  42490. // if(_ray.isIntersectionBox(box)){
  42491. // nodesOnRay.push(node);
  42492. // }
  42493. }
  42494. return nodesOnRay;
  42495. }
  42496. pick(viewer, camera, ray, params = {}){
  42497. let renderer = viewer.renderer;
  42498. let pRenderer = viewer.pRenderer;
  42499. performance.mark("pick-start");
  42500. let getVal = (a, b) => a !== undefined ? a : b;
  42501. let pickWindowSize = getVal(params.pickWindowSize, 17);
  42502. let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
  42503. let size = renderer.getSize(new Vector2());
  42504. let width = Math.ceil(getVal(params.width, size.width));
  42505. let height = Math.ceil(getVal(params.height, size.height));
  42506. let pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
  42507. let pointSize = getVal(params.pointSize, this.material.size);
  42508. let nodes = this.nodesOnRay(this.visibleNodes, ray);
  42509. if (nodes.length === 0) {
  42510. return null;
  42511. }
  42512. if (!this.pickState) {
  42513. let scene = new Scene();
  42514. let material = new PointCloudMaterial$1();
  42515. material.activeAttributeName = "indices";
  42516. let renderTarget = new WebGLRenderTarget(
  42517. 1, 1,
  42518. { minFilter: LinearFilter,
  42519. magFilter: NearestFilter,
  42520. format: RGBAFormat }
  42521. );
  42522. this.pickState = {
  42523. renderTarget: renderTarget,
  42524. material: material,
  42525. scene: scene
  42526. };
  42527. };
  42528. let pickState = this.pickState;
  42529. let pickMaterial = pickState.material;
  42530. { // update pick material
  42531. pickMaterial.pointSizeType = pointSizeType;
  42532. pickMaterial.shape = this.material.shape;
  42533. pickMaterial.size = pointSize;
  42534. pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
  42535. pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
  42536. pickMaterial.classification = this.material.classification;
  42537. if(params.pickClipped){
  42538. pickMaterial.clipBoxes = this.material.clipBoxes;
  42539. if(this.material.clipTask === ClipTask.HIGHLIGHT){
  42540. pickMaterial.clipTask = ClipTask.NONE;
  42541. }else {
  42542. pickMaterial.clipTask = this.material.clipTask;
  42543. }
  42544. }else {
  42545. pickMaterial.clipBoxes = [];
  42546. }
  42547. this.updateMaterial(pickMaterial, nodes, camera, renderer);
  42548. }
  42549. pickState.renderTarget.setSize(width, height);
  42550. let pixelPos = new Vector2(params.x, params.y);
  42551. let gl = renderer.getContext();
  42552. gl.enable(gl.SCISSOR_TEST);
  42553. gl.scissor(
  42554. parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
  42555. parseInt(pixelPos.y - (pickWindowSize - 1) / 2),
  42556. parseInt(pickWindowSize), parseInt(pickWindowSize));
  42557. renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
  42558. renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
  42559. renderer.state.setBlending(NoBlending);
  42560. renderer.clearTarget(pickState.renderTarget, true, true, true);
  42561. { // RENDER
  42562. renderer.setRenderTarget(pickState.renderTarget);
  42563. gl.clearColor(0, 0, 0, 0);
  42564. renderer.clearTarget( pickState.renderTarget, true, true, true );
  42565. let tmp = this.material;
  42566. this.material = pickMaterial;
  42567. pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget);
  42568. this.material = tmp;
  42569. }
  42570. let clamp = (number, min, max) => Math.min(Math.max(min, number), max);
  42571. let x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
  42572. let y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
  42573. let w = parseInt(Math.min(x + pickWindowSize, width) - x);
  42574. let h = parseInt(Math.min(y + pickWindowSize, height) - y);
  42575. let pixelCount = w * h;
  42576. let buffer = new Uint8Array(4 * pixelCount);
  42577. gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer);
  42578. renderer.setRenderTarget(null);
  42579. renderer.state.reset();
  42580. renderer.setScissorTest(false);
  42581. gl.disable(gl.SCISSOR_TEST);
  42582. let pixels = buffer;
  42583. let ibuffer = new Uint32Array(buffer.buffer);
  42584. // find closest hit inside pixelWindow boundaries
  42585. let min = Number.MAX_VALUE;
  42586. let hits = [];
  42587. for (let u = 0; u < pickWindowSize; u++) {
  42588. for (let v = 0; v < pickWindowSize; v++) {
  42589. let offset = (u + v * pickWindowSize);
  42590. let distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
  42591. let pcIndex = pixels[4 * offset + 3];
  42592. pixels[4 * offset + 3] = 0;
  42593. let pIndex = ibuffer[offset];
  42594. if(!(pcIndex === 0 && pIndex === 0) && (pcIndex !== undefined) && (pIndex !== undefined)){
  42595. let hit = {
  42596. pIndex: pIndex,
  42597. pcIndex: pcIndex,
  42598. distanceToCenter: distance
  42599. };
  42600. if(params.all){
  42601. hits.push(hit);
  42602. }else {
  42603. if(hits.length > 0){
  42604. if(distance < hits[0].distanceToCenter){
  42605. hits[0] = hit;
  42606. }
  42607. }else {
  42608. hits.push(hit);
  42609. }
  42610. }
  42611. }
  42612. }
  42613. }
  42614. for(let hit of hits){
  42615. let point = {};
  42616. if (!nodes[hit.pcIndex]) {
  42617. return null;
  42618. }
  42619. let node = nodes[hit.pcIndex];
  42620. let pc = node.sceneNode;
  42621. let geometry = node.geometryNode.geometry;
  42622. for(let attributeName in geometry.attributes){
  42623. let attribute = geometry.attributes[attributeName];
  42624. if (attributeName === 'position') {
  42625. let x = attribute.array[3 * hit.pIndex + 0];
  42626. let y = attribute.array[3 * hit.pIndex + 1];
  42627. let z = attribute.array[3 * hit.pIndex + 2];
  42628. let position = new Vector3(x, y, z);
  42629. position.applyMatrix4(pc.matrixWorld);
  42630. point[attributeName] = position;
  42631. } else if (attributeName === 'indices') {
  42632. } else {
  42633. //if (values.itemSize === 1) {
  42634. // point[attribute.name] = values.array[hit.pIndex];
  42635. //} else {
  42636. // let value = [];
  42637. // for (let j = 0; j < values.itemSize; j++) {
  42638. // value.push(values.array[values.itemSize * hit.pIndex + j]);
  42639. // }
  42640. // point[attribute.name] = value;
  42641. //}
  42642. }
  42643. }
  42644. hit.point = point;
  42645. }
  42646. performance.mark("pick-end");
  42647. performance.measure("pick", "pick-start", "pick-end");
  42648. if(params.all){
  42649. return hits.map(hit => hit.point);
  42650. }else {
  42651. if(hits.length === 0){
  42652. return null;
  42653. }else {
  42654. return hits[0].point;
  42655. }
  42656. }
  42657. }
  42658. computeVisibilityTextureData(nodes){
  42659. if(exports.measureTimings) performance.mark("computeVisibilityTextureData-start");
  42660. let data = new Uint8Array(nodes.length * 3);
  42661. let visibleNodeTextureOffsets = new Map();
  42662. // copy array
  42663. nodes = nodes.slice();
  42664. // sort by level and number
  42665. let sort = function (a, b) {
  42666. let la = a.geometryNode.level;
  42667. let lb = b.geometryNode.level;
  42668. let na = a.geometryNode.number;
  42669. let nb = b.geometryNode.number;
  42670. if (la !== lb) return la - lb;
  42671. if (na < nb) return -1;
  42672. if (na > nb) return 1;
  42673. return 0;
  42674. };
  42675. nodes.sort(sort);
  42676. let visibleNodeNames = [];
  42677. for (let i = 0; i < nodes.length; i++) {
  42678. visibleNodeNames.push(nodes[i].geometryNode.number);
  42679. }
  42680. for (let i = 0; i < nodes.length; i++) {
  42681. let node = nodes[i];
  42682. visibleNodeTextureOffsets.set(node, i);
  42683. let b1 = 0; // children
  42684. let b2 = 0; // offset to first child
  42685. let b3 = 0; // split
  42686. if (node.geometryNode.left && visibleNodeNames.indexOf(node.geometryNode.left.number) > 0) {
  42687. b1 += 1;
  42688. b2 = visibleNodeNames.indexOf(node.geometryNode.left.number) - i;
  42689. }
  42690. if (node.geometryNode.right && visibleNodeNames.indexOf(node.geometryNode.right.number) > 0) {
  42691. b1 += 2;
  42692. b2 = (b2 === 0) ? visibleNodeNames.indexOf(node.geometryNode.right.number) - i : b2;
  42693. }
  42694. if (node.geometryNode.split === 'X') {
  42695. b3 = 1;
  42696. } else if (node.geometryNode.split === 'Y') {
  42697. b3 = 2;
  42698. } else if (node.geometryNode.split === 'Z') {
  42699. b3 = 4;
  42700. }
  42701. data[i * 3 + 0] = b1;
  42702. data[i * 3 + 1] = b2;
  42703. data[i * 3 + 2] = b3;
  42704. }
  42705. if(exports.measureTimings){
  42706. performance.mark("computeVisibilityTextureData-end");
  42707. performance.measure("render.computeVisibilityTextureData", "computeVisibilityTextureData-start", "computeVisibilityTextureData-end");
  42708. }
  42709. return {
  42710. data: data,
  42711. offsets: visibleNodeTextureOffsets
  42712. };
  42713. }
  42714. get progress () {
  42715. if (this.pcoGeometry.root) {
  42716. return exports.numNodesLoading > 0 ? 0 : 1;
  42717. } else {
  42718. return 0;
  42719. }
  42720. }
  42721. };
  42722. // Copied from three.js: WebGLRenderer.js
  42723. function paramThreeToGL(_gl, p) {
  42724. let extension;
  42725. if (p === RepeatWrapping) return _gl.REPEAT;
  42726. if (p === ClampToEdgeWrapping) return _gl.CLAMP_TO_EDGE;
  42727. if (p === MirroredRepeatWrapping) return _gl.MIRRORED_REPEAT;
  42728. if (p === NearestFilter) return _gl.NEAREST;
  42729. if (p === NearestMipMapNearestFilter) return _gl.NEAREST_MIPMAP_NEAREST;
  42730. if (p === NearestMipMapLinearFilter) return _gl.NEAREST_MIPMAP_LINEAR;
  42731. if (p === LinearFilter) return _gl.LINEAR;
  42732. if (p === LinearMipMapNearestFilter) return _gl.LINEAR_MIPMAP_NEAREST;
  42733. if (p === LinearMipMapLinearFilter) return _gl.LINEAR_MIPMAP_LINEAR;
  42734. if (p === UnsignedByteType) return _gl.UNSIGNED_BYTE;
  42735. if (p === UnsignedShort4444Type) return _gl.UNSIGNED_SHORT_4_4_4_4;
  42736. if (p === UnsignedShort5551Type) return _gl.UNSIGNED_SHORT_5_5_5_1;
  42737. if (p === UnsignedShort565Type) return _gl.UNSIGNED_SHORT_5_6_5;
  42738. if (p === ByteType) return _gl.BYTE;
  42739. if (p === ShortType) return _gl.SHORT;
  42740. if (p === UnsignedShortType) return _gl.UNSIGNED_SHORT;
  42741. if (p === IntType) return _gl.INT;
  42742. if (p === UnsignedIntType) return _gl.UNSIGNED_INT;
  42743. if (p === FloatType) return _gl.FLOAT;
  42744. if (p === HalfFloatType) {
  42745. extension = extensions.get('OES_texture_half_float');
  42746. if (extension !== null) return extension.HALF_FLOAT_OES;
  42747. }
  42748. if (p === AlphaFormat) return _gl.ALPHA;
  42749. if (p === RGBFormat) return _gl.RGB;
  42750. if (p === RGBAFormat) return _gl.RGBA;
  42751. if (p === LuminanceFormat) return _gl.LUMINANCE;
  42752. if (p === LuminanceAlphaFormat) return _gl.LUMINANCE_ALPHA;
  42753. if (p === DepthFormat) return _gl.DEPTH_COMPONENT;
  42754. if (p === DepthStencilFormat) return _gl.DEPTH_STENCIL;
  42755. if (p === AddEquation) return _gl.FUNC_ADD;
  42756. if (p === SubtractEquation) return _gl.FUNC_SUBTRACT;
  42757. if (p === ReverseSubtractEquation) return _gl.FUNC_REVERSE_SUBTRACT;
  42758. if (p === ZeroFactor) return _gl.ZERO;
  42759. if (p === OneFactor) return _gl.ONE;
  42760. if (p === SrcColorFactor) return _gl.SRC_COLOR;
  42761. if (p === OneMinusSrcColorFactor) return _gl.ONE_MINUS_SRC_COLOR;
  42762. if (p === SrcAlphaFactor) return _gl.SRC_ALPHA;
  42763. if (p === OneMinusSrcAlphaFactor) return _gl.ONE_MINUS_SRC_ALPHA;
  42764. if (p === DstAlphaFactor) return _gl.DST_ALPHA;
  42765. if (p === OneMinusDstAlphaFactor) return _gl.ONE_MINUS_DST_ALPHA;
  42766. if (p === DstColorFactor) return _gl.DST_COLOR;
  42767. if (p === OneMinusDstColorFactor) return _gl.ONE_MINUS_DST_COLOR;
  42768. if (p === SrcAlphaSaturateFactor) return _gl.SRC_ALPHA_SATURATE;
  42769. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  42770. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  42771. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  42772. if (extension !== null) {
  42773. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  42774. if (p === RGBA_S3TC_DXT1_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  42775. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  42776. if (p === RGBA_S3TC_DXT5_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  42777. }
  42778. }
  42779. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  42780. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  42781. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  42782. if (extension !== null) {
  42783. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  42784. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  42785. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  42786. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  42787. }
  42788. }
  42789. if (p === RGB_ETC1_Format) {
  42790. extension = extensions.get('WEBGL_compressed_texture_etc1');
  42791. if (extension !== null) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  42792. }
  42793. if (p === MinEquation || p === MaxEquation) {
  42794. extension = extensions.get('EXT_blend_minmax');
  42795. if (extension !== null) {
  42796. if (p === MinEquation) return extension.MIN_EXT;
  42797. if (p === MaxEquation) return extension.MAX_EXT;
  42798. }
  42799. }
  42800. if (p === UnsignedInt248Type) {
  42801. extension = extensions.get('WEBGL_depth_texture');
  42802. if (extension !== null) return extension.UNSIGNED_INT_24_8_WEBGL;
  42803. }
  42804. return 0;
  42805. };
  42806. let attributeLocations = {
  42807. "position": {name: "position", location: 0},
  42808. "color": {name: "color", location: 1},
  42809. "rgba": {name: "color", location: 1},
  42810. "intensity": {name: "intensity", location: 2},
  42811. "classification": {name: "classification", location: 3},
  42812. "returnNumber": {name: "returnNumber", location: 4},
  42813. "return number": {name: "returnNumber", location: 4},
  42814. "returns": {name: "returnNumber", location: 4},
  42815. "numberOfReturns": {name: "numberOfReturns", location: 5},
  42816. "number of returns": {name: "numberOfReturns", location: 5},
  42817. "pointSourceID": {name: "pointSourceID", location: 6},
  42818. "source id": {name: "pointSourceID", location: 6},
  42819. "point source id": {name: "pointSourceID", location: 6},
  42820. "indices": {name: "indices", location: 7},
  42821. "normal": {name: "normal", location: 8},
  42822. "spacing": {name: "spacing", location: 9},
  42823. "gps-time": {name: "gpsTime", location: 10},
  42824. "aExtra": {name: "aExtra", location: 11},
  42825. };
  42826. class Shader {
  42827. constructor(gl, name, vsSource, fsSource) {
  42828. this.gl = gl;
  42829. this.name = name;
  42830. this.vsSource = vsSource;
  42831. this.fsSource = fsSource;
  42832. this.cache = new Map();
  42833. this.vs = null;
  42834. this.fs = null;
  42835. this.program = null;
  42836. this.uniformLocations = {};
  42837. this.attributeLocations = {};
  42838. this.uniformBlockIndices = {};
  42839. this.uniformBlocks = {};
  42840. this.uniforms = {};
  42841. this.update(vsSource, fsSource);
  42842. }
  42843. update(vsSource, fsSource) {
  42844. this.vsSource = vsSource;
  42845. this.fsSource = fsSource;
  42846. this.linkProgram();
  42847. }
  42848. compileShader(shader, source){
  42849. let gl = this.gl;
  42850. gl.shaderSource(shader, source);
  42851. gl.compileShader(shader);
  42852. let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  42853. if (!success) {
  42854. let info = gl.getShaderInfoLog(shader);
  42855. let numberedSource = source.split("\n").map((a, i) => `${i + 1}`.padEnd(5) + a).join("\n");
  42856. throw `could not compile shader ${this.name}: ${info}, \n${numberedSource}`;
  42857. }
  42858. }
  42859. linkProgram() {
  42860. const tStart = performance.now();
  42861. let gl = this.gl;
  42862. this.uniformLocations = {};
  42863. this.attributeLocations = {};
  42864. this.uniforms = {};
  42865. gl.useProgram(null);
  42866. let cached = this.cache.get(`${this.vsSource}, ${this.fsSource}`);
  42867. if (cached) {
  42868. this.program = cached.program;
  42869. this.vs = cached.vs;
  42870. this.fs = cached.fs;
  42871. this.attributeLocations = cached.attributeLocations;
  42872. this.uniformLocations = cached.uniformLocations;
  42873. this.uniformBlocks = cached.uniformBlocks;
  42874. this.uniforms = cached.uniforms;
  42875. return;
  42876. } else {
  42877. this.vs = gl.createShader(gl.VERTEX_SHADER);
  42878. this.fs = gl.createShader(gl.FRAGMENT_SHADER);
  42879. this.program = gl.createProgram();
  42880. for(let name of Object.keys(attributeLocations)){
  42881. let location = attributeLocations[name].location;
  42882. let glslName = attributeLocations[name].name;
  42883. gl.bindAttribLocation(this.program, location, glslName);
  42884. }
  42885. this.compileShader(this.vs, this.vsSource);
  42886. this.compileShader(this.fs, this.fsSource);
  42887. let program = this.program;
  42888. gl.attachShader(program, this.vs);
  42889. gl.attachShader(program, this.fs);
  42890. gl.linkProgram(program);
  42891. gl.detachShader(program, this.vs);
  42892. gl.detachShader(program, this.fs);
  42893. let success = gl.getProgramParameter(program, gl.LINK_STATUS);
  42894. if (!success) {
  42895. let info = gl.getProgramInfoLog(program);
  42896. throw `could not link program ${this.name}: ${info}`;
  42897. }
  42898. { // attribute locations
  42899. let numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  42900. for (let i = 0; i < numAttributes; i++) {
  42901. let attribute = gl.getActiveAttrib(program, i);
  42902. let location = gl.getAttribLocation(program, attribute.name);
  42903. this.attributeLocations[attribute.name] = location;
  42904. }
  42905. }
  42906. { // uniform locations
  42907. let numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  42908. for (let i = 0; i < numUniforms; i++) {
  42909. let uniform = gl.getActiveUniform(program, i);
  42910. let location = gl.getUniformLocation(program, uniform.name);
  42911. this.uniformLocations[uniform.name] = location;
  42912. this.uniforms[uniform.name] = {
  42913. location: location,
  42914. value: null,
  42915. };
  42916. }
  42917. }
  42918. // uniform blocks
  42919. if(typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext){
  42920. let numBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
  42921. for (let i = 0; i < numBlocks; i++) {
  42922. let blockName = gl.getActiveUniformBlockName(program, i);
  42923. let blockIndex = gl.getUniformBlockIndex(program, blockName);
  42924. this.uniformBlockIndices[blockName] = blockIndex;
  42925. gl.uniformBlockBinding(program, blockIndex, blockIndex);
  42926. let dataSize = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE);
  42927. let uBuffer = gl.createBuffer();
  42928. gl.bindBuffer(gl.UNIFORM_BUFFER, uBuffer);
  42929. gl.bufferData(gl.UNIFORM_BUFFER, dataSize, gl.DYNAMIC_READ);
  42930. gl.bindBufferBase(gl.UNIFORM_BUFFER, blockIndex, uBuffer);
  42931. gl.bindBuffer(gl.UNIFORM_BUFFER, null);
  42932. this.uniformBlocks[blockName] = {
  42933. name: blockName,
  42934. index: blockIndex,
  42935. dataSize: dataSize,
  42936. buffer: uBuffer
  42937. };
  42938. }
  42939. }
  42940. let cached = {
  42941. program: this.program,
  42942. vs: this.vs,
  42943. fs: this.fs,
  42944. attributeLocations: this.attributeLocations,
  42945. uniformLocations: this.uniformLocations,
  42946. uniforms: this.uniforms,
  42947. uniformBlocks: this.uniformBlocks,
  42948. };
  42949. this.cache.set(`${this.vsSource}, ${this.fsSource}`, cached);
  42950. }
  42951. const tEnd = performance.now();
  42952. const duration = tEnd - tStart;
  42953. console.log(`shader compile duration: ${duration.toFixed(3)}`);
  42954. }
  42955. setUniformMatrix4(name, value) {
  42956. const gl = this.gl;
  42957. const location = this.uniformLocations[name];
  42958. if (location == null) {
  42959. return;
  42960. }
  42961. let tmp = new Float32Array(value.elements);
  42962. gl.uniformMatrix4fv(location, false, tmp);
  42963. }
  42964. setUniform1f(name, value) {
  42965. const gl = this.gl;
  42966. const uniform = this.uniforms[name];
  42967. if (uniform === undefined) {
  42968. return;
  42969. }
  42970. if(uniform.value === value){
  42971. return;
  42972. }
  42973. uniform.value = value;
  42974. gl.uniform1f(uniform.location, value);
  42975. }
  42976. setUniformBoolean(name, value) {
  42977. const gl = this.gl;
  42978. const uniform = this.uniforms[name];
  42979. if (uniform === undefined) {
  42980. return;
  42981. }
  42982. if(uniform.value === value){
  42983. return;
  42984. }
  42985. uniform.value = value;
  42986. gl.uniform1i(uniform.location, value);
  42987. }
  42988. setUniformTexture(name, value) {
  42989. const gl = this.gl;
  42990. const location = this.uniformLocations[name];
  42991. if (location == null) {
  42992. return;
  42993. }
  42994. gl.uniform1i(location, value);
  42995. }
  42996. setUniform2f(name, value) {
  42997. const gl = this.gl;
  42998. const location = this.uniformLocations[name];
  42999. if (location == null) {
  43000. return;
  43001. }
  43002. gl.uniform2f(location, value[0], value[1]);
  43003. }
  43004. setUniform3f(name, value) {
  43005. const gl = this.gl;
  43006. const location = this.uniformLocations[name];
  43007. if (location == null) {
  43008. return;
  43009. }
  43010. gl.uniform3f(location, value[0], value[1], value[2]);
  43011. }
  43012. setUniform(name, value) {
  43013. if (value.constructor === Matrix4) {
  43014. this.setUniformMatrix4(name, value);
  43015. } else if (typeof value === "number") {
  43016. this.setUniform1f(name, value);
  43017. } else if (typeof value === "boolean") {
  43018. this.setUniformBoolean(name, value);
  43019. } else if (value instanceof WebGLTexture) {
  43020. this.setUniformTexture(name, value);
  43021. } else if (value instanceof Array) {
  43022. if (value.length === 2) {
  43023. this.setUniform2f(name, value);
  43024. } else if (value.length === 3) {
  43025. this.setUniform3f(name, value);
  43026. }
  43027. } else {
  43028. console.error("unhandled uniform type: ", name, value);
  43029. }
  43030. }
  43031. setUniform1i(name, value) {
  43032. let gl = this.gl;
  43033. let location = this.uniformLocations[name];
  43034. if (location == null) {
  43035. return;
  43036. }
  43037. gl.uniform1i(location, value);
  43038. }
  43039. };
  43040. class WebGLTexture {
  43041. constructor(gl, texture) {
  43042. this.gl = gl;
  43043. this.texture = texture;
  43044. this.id = gl.createTexture();
  43045. this.target = gl.TEXTURE_2D;
  43046. this.version = -1;
  43047. this.update(texture);
  43048. }
  43049. update() {
  43050. if (!this.texture.image) {
  43051. this.version = this.texture.version;
  43052. return;
  43053. }
  43054. let gl = this.gl;
  43055. let texture = this.texture;
  43056. if (this.version === texture.version) {
  43057. return;
  43058. }
  43059. this.target = gl.TEXTURE_2D;
  43060. gl.bindTexture(this.target, this.id);
  43061. let level = 0;
  43062. let internalFormat = paramThreeToGL(gl, texture.format);
  43063. let width = texture.image.width;
  43064. let height = texture.image.height;
  43065. let border = 0;
  43066. let srcFormat = internalFormat;
  43067. let srcType = paramThreeToGL(gl, texture.type);
  43068. let data;
  43069. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
  43070. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha);
  43071. gl.pixelStorei(gl.UNPACK_ALIGNMENT, texture.unpackAlignment);
  43072. if (texture instanceof DataTexture) {
  43073. data = texture.image.data;
  43074. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  43075. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  43076. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL(gl, texture.magFilter));
  43077. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL(gl, texture.minFilter));
  43078. gl.texImage2D(this.target, level, internalFormat,
  43079. width, height, border, srcFormat, srcType,
  43080. data);
  43081. } else if ((texture instanceof CanvasTexture) || (texture instanceof Texture)) {
  43082. data = texture.image;
  43083. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, paramThreeToGL(gl, texture.wrapS));
  43084. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, paramThreeToGL(gl, texture.wrapT));
  43085. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL(gl, texture.magFilter));
  43086. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL(gl, texture.minFilter));
  43087. gl.texImage2D(this.target, level, internalFormat,
  43088. internalFormat, srcType, data);
  43089. if (texture instanceof Texture) {gl.generateMipmap(gl.TEXTURE_2D);}
  43090. }
  43091. gl.bindTexture(this.target, null);
  43092. this.version = texture.version;
  43093. }
  43094. };
  43095. class WebGLBuffer {
  43096. constructor() {
  43097. this.numElements = 0;
  43098. this.vao = null;
  43099. this.vbos = new Map();
  43100. }
  43101. };
  43102. class Renderer {
  43103. constructor(threeRenderer) {
  43104. this.threeRenderer = threeRenderer;
  43105. this.gl = this.threeRenderer.getContext();
  43106. this.buffers = new Map();
  43107. this.shaders = new Map();
  43108. this.textures = new Map();
  43109. this.glTypeMapping = new Map();
  43110. this.glTypeMapping.set(Float32Array, this.gl.FLOAT);
  43111. this.glTypeMapping.set(Uint8Array, this.gl.UNSIGNED_BYTE);
  43112. this.glTypeMapping.set(Uint16Array, this.gl.UNSIGNED_SHORT);
  43113. this.toggle = 0;
  43114. }
  43115. deleteBuffer(geometry) {
  43116. let gl = this.gl;
  43117. let webglBuffer = this.buffers.get(geometry);
  43118. if (webglBuffer != null) {
  43119. for (let attributeName in geometry.attributes) {
  43120. gl.deleteBuffer(webglBuffer.vbos.get(attributeName).handle);
  43121. }
  43122. this.buffers.delete(geometry);
  43123. }
  43124. }
  43125. createBuffer(geometry){
  43126. let gl = this.gl;
  43127. let webglBuffer = new WebGLBuffer();
  43128. webglBuffer.vao = gl.createVertexArray();
  43129. webglBuffer.numElements = geometry.attributes.position.count;
  43130. gl.bindVertexArray(webglBuffer.vao);
  43131. for(let attributeName in geometry.attributes){
  43132. let bufferAttribute = geometry.attributes[attributeName];
  43133. let vbo = gl.createBuffer();
  43134. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  43135. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  43136. let normalized = bufferAttribute.normalized;
  43137. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  43138. if(attributeLocations[attributeName] === undefined){
  43139. //attributeLocation = attributeLocations["aExtra"];
  43140. }else {
  43141. let attributeLocation = attributeLocations[attributeName].location;
  43142. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  43143. gl.enableVertexAttribArray(attributeLocation);
  43144. }
  43145. webglBuffer.vbos.set(attributeName, {
  43146. handle: vbo,
  43147. name: attributeName,
  43148. count: bufferAttribute.count,
  43149. itemSize: bufferAttribute.itemSize,
  43150. type: geometry.attributes.position.array.constructor,
  43151. version: 0
  43152. });
  43153. }
  43154. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  43155. gl.bindVertexArray(null);
  43156. let disposeHandler = (event) => {
  43157. this.deleteBuffer(geometry);
  43158. geometry.removeEventListener("dispose", disposeHandler);
  43159. };
  43160. geometry.addEventListener("dispose", disposeHandler);
  43161. return webglBuffer;
  43162. }
  43163. updateBuffer(geometry){
  43164. let gl = this.gl;
  43165. let webglBuffer = this.buffers.get(geometry);
  43166. gl.bindVertexArray(webglBuffer.vao);
  43167. for(let attributeName in geometry.attributes){
  43168. let bufferAttribute = geometry.attributes[attributeName];
  43169. let normalized = bufferAttribute.normalized;
  43170. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  43171. let vbo = null;
  43172. if(!webglBuffer.vbos.has(attributeName)){
  43173. vbo = gl.createBuffer();
  43174. webglBuffer.vbos.set(attributeName, {
  43175. handle: vbo,
  43176. name: attributeName,
  43177. count: bufferAttribute.count,
  43178. itemSize: bufferAttribute.itemSize,
  43179. type: geometry.attributes.position.array.constructor,
  43180. version: bufferAttribute.version
  43181. });
  43182. }else {
  43183. vbo = webglBuffer.vbos.get(attributeName).handle;
  43184. webglBuffer.vbos.get(attributeName).version = bufferAttribute.version;
  43185. }
  43186. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  43187. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  43188. if(attributeLocations[attributeName] === undefined){
  43189. //attributeLocation = attributeLocations["aExtra"];
  43190. }else {
  43191. let attributeLocation = attributeLocations[attributeName].location;
  43192. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  43193. gl.enableVertexAttribArray(attributeLocation);
  43194. }
  43195. }
  43196. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  43197. gl.bindVertexArray(null);
  43198. }
  43199. traverse(scene) {
  43200. let octrees = [];
  43201. let stack = [scene];
  43202. while (stack.length > 0) {
  43203. let node = stack.pop();
  43204. if (node instanceof PointCloudTree) {
  43205. octrees.push(node);
  43206. continue;
  43207. }
  43208. let visibleChildren = node.children.filter(c => c.visible);
  43209. stack.push(...visibleChildren);
  43210. }
  43211. let result = {
  43212. octrees: octrees
  43213. };
  43214. return result;
  43215. }
  43216. renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params) {
  43217. if (exports.measureTimings) performance.mark("renderNodes-start");
  43218. let gl = this.gl;
  43219. let material = params.material ? params.material : octree.material;
  43220. let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  43221. let view = camera.matrixWorldInverse;
  43222. if(params.viewOverride){
  43223. view = params.viewOverride;
  43224. }
  43225. let worldView = new Matrix4();
  43226. let mat4holder = new Float32Array(16);
  43227. let i = 0;
  43228. for (let node of nodes) {
  43229. if(exports.debug.allowedNodes !== undefined){
  43230. if(!exports.debug.allowedNodes.includes(node.name)){
  43231. continue;
  43232. }
  43233. }
  43234. let world = node.sceneNode.matrixWorld;
  43235. worldView.multiplyMatrices(view, world);
  43236. if (visibilityTextureData) {
  43237. let vnStart = visibilityTextureData.offsets.get(node);
  43238. shader.setUniform1f("uVNStart", vnStart);
  43239. }
  43240. let level = node.getLevel();
  43241. if(node.debug){
  43242. shader.setUniform("uDebug", true);
  43243. }else {
  43244. shader.setUniform("uDebug", false);
  43245. }
  43246. // let isLeaf = false;
  43247. // if(node instanceof PointCloudOctreeNode){
  43248. // isLeaf = Object.keys(node.children).length === 0;
  43249. // }else if(node instanceof PointCloudArena4DNode){
  43250. // isLeaf = node.geometryNode.isLeaf;
  43251. // }
  43252. // shader.setUniform("uIsLeafNode", isLeaf);
  43253. // let isLeaf = node.children.filter(n => n != null).length === 0;
  43254. // if(!isLeaf){
  43255. // continue;
  43256. // }
  43257. // TODO consider passing matrices in an array to avoid uniformMatrix4fv overhead
  43258. const lModel = shader.uniformLocations["modelMatrix"];
  43259. if (lModel) {
  43260. mat4holder.set(world.elements);
  43261. gl.uniformMatrix4fv(lModel, false, mat4holder);
  43262. }
  43263. const lModelView = shader.uniformLocations["modelViewMatrix"];
  43264. //mat4holder.set(worldView.elements);
  43265. // faster then set in chrome 63
  43266. for(let j = 0; j < 16; j++){
  43267. mat4holder[j] = worldView.elements[j];
  43268. }
  43269. gl.uniformMatrix4fv(lModelView, false, mat4holder);
  43270. { // Clip Polygons
  43271. if(material.clipPolygons && material.clipPolygons.length > 0){
  43272. let clipPolygonVCount = [];
  43273. let worldViewProjMatrices = [];
  43274. for(let clipPolygon of material.clipPolygons){
  43275. let view = clipPolygon.viewMatrix;
  43276. let proj = clipPolygon.projMatrix;
  43277. let worldViewProj = proj.clone().multiply(view).multiply(world);
  43278. clipPolygonVCount.push(clipPolygon.markers.length);
  43279. worldViewProjMatrices.push(worldViewProj);
  43280. }
  43281. let flattenedMatrices = [].concat(...worldViewProjMatrices.map(m => m.elements));
  43282. let flattenedVertices = new Array(8 * 3 * material.clipPolygons.length);
  43283. for(let i = 0; i < material.clipPolygons.length; i++){
  43284. let clipPolygon = material.clipPolygons[i];
  43285. for(let j = 0; j < clipPolygon.markers.length; j++){
  43286. flattenedVertices[i * 24 + (j * 3 + 0)] = clipPolygon.markers[j].position.x;
  43287. flattenedVertices[i * 24 + (j * 3 + 1)] = clipPolygon.markers[j].position.y;
  43288. flattenedVertices[i * 24 + (j * 3 + 2)] = clipPolygon.markers[j].position.z;
  43289. }
  43290. }
  43291. const lClipPolygonVCount = shader.uniformLocations["uClipPolygonVCount[0]"];
  43292. gl.uniform1iv(lClipPolygonVCount, clipPolygonVCount);
  43293. const lClipPolygonVP = shader.uniformLocations["uClipPolygonWVP[0]"];
  43294. gl.uniformMatrix4fv(lClipPolygonVP, false, flattenedMatrices);
  43295. const lClipPolygons = shader.uniformLocations["uClipPolygonVertices[0]"];
  43296. gl.uniform3fv(lClipPolygons, flattenedVertices);
  43297. }
  43298. }
  43299. //shader.setUniformMatrix4("modelMatrix", world);
  43300. //shader.setUniformMatrix4("modelViewMatrix", worldView);
  43301. shader.setUniform1f("uLevel", level);
  43302. shader.setUniform1f("uNodeSpacing", node.geometryNode.estimatedSpacing);
  43303. shader.setUniform1f("uPCIndex", i);
  43304. // uBBSize
  43305. if (shadowMaps.length > 0) {
  43306. const lShadowMap = shader.uniformLocations["uShadowMap[0]"];
  43307. shader.setUniform3f("uShadowColor", material.uniforms.uShadowColor.value);
  43308. let bindingStart = 5;
  43309. let bindingPoints = new Array(shadowMaps.length).fill(bindingStart).map((a, i) => (a + i));
  43310. gl.uniform1iv(lShadowMap, bindingPoints);
  43311. for (let i = 0; i < shadowMaps.length; i++) {
  43312. let shadowMap = shadowMaps[i];
  43313. let bindingPoint = bindingPoints[i];
  43314. let glTexture = this.threeRenderer.properties.get(shadowMap.target.texture).__webglTexture;
  43315. gl.activeTexture(gl[`TEXTURE${bindingPoint}`]);
  43316. gl.bindTexture(gl.TEXTURE_2D, glTexture);
  43317. }
  43318. {
  43319. let worldViewMatrices = shadowMaps
  43320. .map(sm => sm.camera.matrixWorldInverse)
  43321. .map(view => new Matrix4().multiplyMatrices(view, world));
  43322. let flattenedMatrices = [].concat(...worldViewMatrices.map(c => c.elements));
  43323. const lWorldView = shader.uniformLocations["uShadowWorldView[0]"];
  43324. gl.uniformMatrix4fv(lWorldView, false, flattenedMatrices);
  43325. }
  43326. {
  43327. let flattenedMatrices = [].concat(...shadowMaps.map(sm => sm.camera.projectionMatrix.elements));
  43328. const lProj = shader.uniformLocations["uShadowProj[0]"];
  43329. gl.uniformMatrix4fv(lProj, false, flattenedMatrices);
  43330. }
  43331. }
  43332. const geometry = node.geometryNode.geometry;
  43333. if(geometry.attributes["gps-time"]){
  43334. const bufferAttribute = geometry.attributes["gps-time"];
  43335. const attGPS = octree.getAttribute("gps-time");
  43336. let initialRange = attGPS.initialRange;
  43337. let initialRangeSize = initialRange[1] - initialRange[0];
  43338. let globalRange = attGPS.range;
  43339. let globalRangeSize = globalRange[1] - globalRange[0];
  43340. let scale = initialRangeSize / globalRangeSize;
  43341. let offset = -(globalRange[0] - initialRange[0]) / initialRangeSize;
  43342. scale = Number.isNaN(scale) ? 1 : scale;
  43343. offset = Number.isNaN(offset) ? 0 : offset;
  43344. shader.setUniform1f("uGpsScale", scale);
  43345. shader.setUniform1f("uGpsOffset", offset);
  43346. //shader.setUniform2f("uFilterGPSTimeClipRange", [-Infinity, Infinity]);
  43347. let uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  43348. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  43349. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  43350. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  43351. let normalizedClipRange = [
  43352. (uFilterGPSTimeClipRange[0] - globalRange[0]) / globalRangeSize,
  43353. (uFilterGPSTimeClipRange[1] - globalRange[0]) / globalRangeSize,
  43354. ];
  43355. shader.setUniform2f("uFilterGPSTimeClipRange", normalizedClipRange);
  43356. // // ranges in full gps coordinate system
  43357. // const globalRange = attGPS.range;
  43358. // const bufferRange = bufferAttribute.potree.range;
  43359. // // ranges in [0, 1]
  43360. // // normalizedGlobalRange = [0, 1]
  43361. // // normalizedBufferRange: norm buffer within norm global range e.g. [0.2, 0.8]
  43362. // const globalWidth = globalRange[1] - globalRange[0];
  43363. // const normalizedBufferRange = [
  43364. // (bufferRange[0] - globalRange[0]) / globalWidth,
  43365. // (bufferRange[1] - globalRange[0]) / globalWidth,
  43366. // ];
  43367. // shader.setUniform2f("uNormalizedGpsBufferRange", normalizedBufferRange);
  43368. // let uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  43369. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  43370. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  43371. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  43372. // shader.setUniform1f("uGpsScale", bufferAttribute.potree.scale);
  43373. // shader.setUniform1f("uGpsOffset", bufferAttribute.potree.offset);
  43374. }
  43375. {
  43376. let uFilterReturnNumberRange = material.uniforms.uFilterReturnNumberRange.value;
  43377. let uFilterNumberOfReturnsRange = material.uniforms.uFilterNumberOfReturnsRange.value;
  43378. let uFilterPointSourceIDClipRange = material.uniforms.uFilterPointSourceIDClipRange.value;
  43379. shader.setUniform2f("uFilterReturnNumberRange", uFilterReturnNumberRange);
  43380. shader.setUniform2f("uFilterNumberOfReturnsRange", uFilterNumberOfReturnsRange);
  43381. shader.setUniform2f("uFilterPointSourceIDClipRange", uFilterPointSourceIDClipRange);
  43382. }
  43383. let webglBuffer = null;
  43384. if(!this.buffers.has(geometry)){
  43385. webglBuffer = this.createBuffer(geometry);
  43386. this.buffers.set(geometry, webglBuffer);
  43387. }else {
  43388. webglBuffer = this.buffers.get(geometry);
  43389. for(let attributeName in geometry.attributes){
  43390. let attribute = geometry.attributes[attributeName];
  43391. if(attribute.version > webglBuffer.vbos.get(attributeName).version){
  43392. this.updateBuffer(geometry);
  43393. }
  43394. }
  43395. }
  43396. gl.bindVertexArray(webglBuffer.vao);
  43397. let isExtraAttribute =
  43398. attributeLocations[material.activeAttributeName] === undefined
  43399. && Object.keys(geometry.attributes).includes(material.activeAttributeName);
  43400. if(isExtraAttribute){
  43401. const attributeLocation = attributeLocations["aExtra"].location;
  43402. for(const attributeName in geometry.attributes){
  43403. const bufferAttribute = geometry.attributes[attributeName];
  43404. const vbo = webglBuffer.vbos.get(attributeName);
  43405. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  43406. gl.disableVertexAttribArray(attributeLocation);
  43407. }
  43408. const attName = material.activeAttributeName;
  43409. const bufferAttribute = geometry.attributes[attName];
  43410. const vbo = webglBuffer.vbos.get(attName);
  43411. if(bufferAttribute !== undefined && vbo !== undefined){
  43412. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  43413. let normalized = bufferAttribute.normalized;
  43414. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  43415. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  43416. gl.enableVertexAttribArray(attributeLocation);
  43417. }
  43418. {
  43419. const attExtra = octree.pcoGeometry.pointAttributes.attributes
  43420. .find(a => a.name === attName);
  43421. let range = material.getRange(attName);
  43422. if(!range){
  43423. range = attExtra.range;
  43424. }
  43425. if(!range){
  43426. range = [0, 1];
  43427. }
  43428. let initialRange = attExtra.initialRange;
  43429. let initialRangeSize = initialRange[1] - initialRange[0];
  43430. let globalRange = range;
  43431. let globalRangeSize = globalRange[1] - globalRange[0];
  43432. let scale = initialRangeSize / globalRangeSize;
  43433. let offset = -(globalRange[0] - initialRange[0]) / initialRangeSize;
  43434. scale = Number.isNaN(scale) ? 1 : scale;
  43435. offset = Number.isNaN(offset) ? 0 : offset;
  43436. shader.setUniform1f("uExtraScale", scale);
  43437. shader.setUniform1f("uExtraOffset", offset);
  43438. }
  43439. }else {
  43440. for(const attributeName in geometry.attributes){
  43441. const bufferAttribute = geometry.attributes[attributeName];
  43442. const vbo = webglBuffer.vbos.get(attributeName);
  43443. if(attributeLocations[attributeName] !== undefined){
  43444. const attributeLocation = attributeLocations[attributeName].location;
  43445. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  43446. let normalized = bufferAttribute.normalized;
  43447. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  43448. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  43449. gl.enableVertexAttribArray(attributeLocation);
  43450. }
  43451. }
  43452. }
  43453. let numPoints = webglBuffer.numElements;
  43454. gl.drawArrays(gl.POINTS, 0, numPoints);
  43455. i++;
  43456. }
  43457. gl.bindVertexArray(null);
  43458. if (exports.measureTimings) {
  43459. performance.mark("renderNodes-end");
  43460. performance.measure("render.renderNodes", "renderNodes-start", "renderNodes-end");
  43461. }
  43462. }
  43463. renderOctree(octree, nodes, camera, target, params = {}){
  43464. let gl = this.gl;
  43465. let material = params.material ? params.material : octree.material;
  43466. let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  43467. let view = camera.matrixWorldInverse;
  43468. let viewInv = camera.matrixWorld;
  43469. if(params.viewOverride){
  43470. view = params.viewOverride;
  43471. viewInv = view.clone().invert();
  43472. }
  43473. let proj = camera.projectionMatrix;
  43474. let projInv = proj.clone().invert();
  43475. //let worldView = new THREE.Matrix4();
  43476. let shader = null;
  43477. let visibilityTextureData = null;
  43478. let currentTextureBindingPoint = 0;
  43479. if (material.pointSizeType >= 0) {
  43480. if (material.pointSizeType === PointSizeType.ADAPTIVE ||
  43481. material.activeAttributeName === "level of detail") {
  43482. let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
  43483. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  43484. const vnt = material.visibleNodesTexture;
  43485. const data = vnt.image.data;
  43486. data.set(visibilityTextureData.data);
  43487. vnt.needsUpdate = true;
  43488. }
  43489. }
  43490. { // UPDATE SHADER AND TEXTURES
  43491. if (!this.shaders.has(material)) {
  43492. let [vs, fs] = [material.vertexShader, material.fragmentShader];
  43493. let shader = new Shader(gl, "pointcloud", vs, fs);
  43494. this.shaders.set(material, shader);
  43495. }
  43496. shader = this.shaders.get(material);
  43497. //if(material.needsUpdate){
  43498. {
  43499. let [vs, fs] = [material.vertexShader, material.fragmentShader];
  43500. let numSnapshots = material.snapEnabled ? material.numSnapshots : 0;
  43501. let numClipBoxes = (material.clipBoxes && material.clipBoxes.length) ? material.clipBoxes.length : 0;
  43502. let numClipSpheres = (params.clipSpheres && params.clipSpheres.length) ? params.clipSpheres.length : 0;
  43503. let numClipPolygons = (material.clipPolygons && material.clipPolygons.length) ? material.clipPolygons.length : 0;
  43504. let defines = [
  43505. `#define num_shadowmaps ${shadowMaps.length}`,
  43506. `#define num_snapshots ${numSnapshots}`,
  43507. `#define num_clipboxes ${numClipBoxes}`,
  43508. `#define num_clipspheres ${numClipSpheres}`,
  43509. `#define num_clippolygons ${numClipPolygons}`,
  43510. ];
  43511. if(octree.pcoGeometry.root.isLoaded()){
  43512. let attributes = octree.pcoGeometry.root.geometry.attributes;
  43513. if(attributes["gps-time"]){
  43514. defines.push("#define clip_gps_enabled");
  43515. }
  43516. if(attributes["return number"]){
  43517. defines.push("#define clip_return_number_enabled");
  43518. }
  43519. if(attributes["number of returns"]){
  43520. defines.push("#define clip_number_of_returns_enabled");
  43521. }
  43522. if(attributes["source id"] || attributes["point source id"]){
  43523. defines.push("#define clip_point_source_id_enabled");
  43524. }
  43525. }
  43526. let definesString = defines.join("\n");
  43527. let vsVersionIndex = vs.indexOf("#version ");
  43528. let fsVersionIndex = fs.indexOf("#version ");
  43529. if(vsVersionIndex >= 0){
  43530. vs = vs.replace(/(#version .*)/, `$1\n${definesString}`);
  43531. }else {
  43532. vs = `${definesString}\n${vs}`;
  43533. }
  43534. if(fsVersionIndex >= 0){
  43535. fs = fs.replace(/(#version .*)/, `$1\n${definesString}`);
  43536. }else {
  43537. fs = `${definesString}\n${fs}`;
  43538. }
  43539. shader.update(vs, fs);
  43540. material.needsUpdate = false;
  43541. }
  43542. for (let uniformName of Object.keys(material.uniforms)) {
  43543. let uniform = material.uniforms[uniformName];
  43544. if (uniform.type == "t") {
  43545. let texture = uniform.value;
  43546. if (!texture) {
  43547. continue;
  43548. }
  43549. if (!this.textures.has(texture)) {
  43550. let webglTexture = new WebGLTexture(gl, texture);
  43551. this.textures.set(texture, webglTexture);
  43552. }
  43553. let webGLTexture = this.textures.get(texture);
  43554. webGLTexture.update();
  43555. }
  43556. }
  43557. }
  43558. gl.useProgram(shader.program);
  43559. let transparent = false;
  43560. if(params.transparent !== undefined){
  43561. transparent = params.transparent && material.opacity < 1;
  43562. }else {
  43563. transparent = material.opacity < 1;
  43564. }
  43565. if (transparent){
  43566. gl.enable(gl.BLEND);
  43567. gl.blendFunc(gl.SRC_ALPHA, gl.ONE);
  43568. gl.depthMask(false);
  43569. gl.disable(gl.DEPTH_TEST);
  43570. } else {
  43571. gl.disable(gl.BLEND);
  43572. gl.depthMask(true);
  43573. gl.enable(gl.DEPTH_TEST);
  43574. }
  43575. if(params.blendFunc !== undefined){
  43576. gl.enable(gl.BLEND);
  43577. gl.blendFunc(...params.blendFunc);
  43578. }
  43579. if(params.depthTest !== undefined){
  43580. if(params.depthTest === true){
  43581. gl.enable(gl.DEPTH_TEST);
  43582. }else {
  43583. gl.disable(gl.DEPTH_TEST);
  43584. }
  43585. }
  43586. if(params.depthWrite !== undefined){
  43587. if(params.depthWrite === true){
  43588. gl.depthMask(true);
  43589. }else {
  43590. gl.depthMask(false);
  43591. }
  43592. }
  43593. { // UPDATE UNIFORMS
  43594. shader.setUniformMatrix4("projectionMatrix", proj);
  43595. shader.setUniformMatrix4("viewMatrix", view);
  43596. shader.setUniformMatrix4("uViewInv", viewInv);
  43597. shader.setUniformMatrix4("uProjInv", projInv);
  43598. let screenWidth = target ? target.width : material.screenWidth;
  43599. let screenHeight = target ? target.height : material.screenHeight;
  43600. shader.setUniform1f("uScreenWidth", screenWidth);
  43601. shader.setUniform1f("uScreenHeight", screenHeight);
  43602. shader.setUniform1f("fov", Math.PI * camera.fov / 180);
  43603. shader.setUniform1f("near", camera.near);
  43604. shader.setUniform1f("far", camera.far);
  43605. if(camera instanceof OrthographicCamera){
  43606. shader.setUniform("uUseOrthographicCamera", true);
  43607. shader.setUniform("uOrthoWidth", camera.right - camera.left);
  43608. shader.setUniform("uOrthoHeight", camera.top - camera.bottom);
  43609. }else {
  43610. shader.setUniform("uUseOrthographicCamera", false);
  43611. }
  43612. if(material.clipBoxes.length + material.clipPolygons.length === 0){
  43613. shader.setUniform1i("clipTask", ClipTask.NONE);
  43614. }else {
  43615. shader.setUniform1i("clipTask", material.clipTask);
  43616. }
  43617. shader.setUniform1i("clipMethod", material.clipMethod);
  43618. if (material.clipBoxes && material.clipBoxes.length > 0) {
  43619. //let flattenedMatrices = [].concat(...material.clipBoxes.map(c => c.inverse.elements));
  43620. //const lClipBoxes = shader.uniformLocations["clipBoxes[0]"];
  43621. //gl.uniformMatrix4fv(lClipBoxes, false, flattenedMatrices);
  43622. const lClipBoxes = shader.uniformLocations["clipBoxes[0]"];
  43623. gl.uniformMatrix4fv(lClipBoxes, false, material.uniforms.clipBoxes.value);
  43624. }
  43625. // TODO CLIPSPHERES
  43626. if(params.clipSpheres && params.clipSpheres.length > 0){
  43627. let clipSpheres = params.clipSpheres;
  43628. let matrices = [];
  43629. for(let clipSphere of clipSpheres){
  43630. //let mScale = new THREE.Matrix4().makeScale(...clipSphere.scale.toArray());
  43631. //let mTranslate = new THREE.Matrix4().makeTranslation(...clipSphere.position.toArray());
  43632. //let clipToWorld = new THREE.Matrix4().multiplyMatrices(mTranslate, mScale);
  43633. let clipToWorld = clipSphere.matrixWorld;
  43634. let viewToWorld = camera.matrixWorld;
  43635. let worldToClip = clipToWorld.clone().invert();
  43636. let viewToClip = new Matrix4().multiplyMatrices(worldToClip, viewToWorld);
  43637. matrices.push(viewToClip);
  43638. }
  43639. let flattenedMatrices = [].concat(...matrices.map(matrix => matrix.elements));
  43640. const lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  43641. gl.uniformMatrix4fv(lClipSpheres, false, flattenedMatrices);
  43642. //const lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  43643. //gl.uniformMatrix4fv(lClipSpheres, false, material.uniforms.clipSpheres.value);
  43644. }
  43645. shader.setUniform1f("size", material.size);
  43646. shader.setUniform1f("maxSize", material.uniforms.maxSize.value);
  43647. shader.setUniform1f("minSize", material.uniforms.minSize.value);
  43648. // uniform float uPCIndex
  43649. shader.setUniform1f("uOctreeSpacing", material.spacing);
  43650. shader.setUniform("uOctreeSize", material.uniforms.octreeSize.value);
  43651. //uniform vec3 uColor;
  43652. shader.setUniform3f("uColor", material.color.toArray());
  43653. //uniform float opacity;
  43654. shader.setUniform1f("uOpacity", material.opacity);
  43655. shader.setUniform2f("elevationRange", material.elevationRange);
  43656. shader.setUniform2f("intensityRange", material.intensityRange);
  43657. shader.setUniform3f("uIntensity_gbc", [
  43658. material.intensityGamma,
  43659. material.intensityBrightness,
  43660. material.intensityContrast
  43661. ]);
  43662. shader.setUniform3f("uRGB_gbc", [
  43663. material.rgbGamma,
  43664. material.rgbBrightness,
  43665. material.rgbContrast
  43666. ]);
  43667. shader.setUniform1f("uTransition", material.transition);
  43668. shader.setUniform1f("wRGB", material.weightRGB);
  43669. shader.setUniform1f("wIntensity", material.weightIntensity);
  43670. shader.setUniform1f("wElevation", material.weightElevation);
  43671. shader.setUniform1f("wClassification", material.weightClassification);
  43672. shader.setUniform1f("wReturnNumber", material.weightReturnNumber);
  43673. shader.setUniform1f("wSourceID", material.weightSourceID);
  43674. shader.setUniform("backfaceCulling", material.uniforms.backfaceCulling.value);
  43675. let vnWebGLTexture = this.textures.get(material.visibleNodesTexture);
  43676. if(vnWebGLTexture){
  43677. shader.setUniform1i("visibleNodesTexture", currentTextureBindingPoint);
  43678. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  43679. gl.bindTexture(vnWebGLTexture.target, vnWebGLTexture.id);
  43680. currentTextureBindingPoint++;
  43681. }
  43682. let gradientTexture = this.textures.get(material.gradientTexture);
  43683. shader.setUniform1i("gradient", currentTextureBindingPoint);
  43684. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  43685. gl.bindTexture(gradientTexture.target, gradientTexture.id);
  43686. const repeat = material.elevationGradientRepeat;
  43687. if(repeat === ElevationGradientRepeat.REPEAT){
  43688. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.REPEAT);
  43689. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.REPEAT);
  43690. }else if(repeat === ElevationGradientRepeat.MIRRORED_REPEAT){
  43691. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
  43692. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
  43693. }else {
  43694. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  43695. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  43696. }
  43697. currentTextureBindingPoint++;
  43698. let classificationTexture = this.textures.get(material.classificationTexture);
  43699. shader.setUniform1i("classificationLUT", currentTextureBindingPoint);
  43700. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  43701. gl.bindTexture(classificationTexture.target, classificationTexture.id);
  43702. currentTextureBindingPoint++;
  43703. let matcapTexture = this.textures.get(material.matcapTexture);
  43704. shader.setUniform1i("matcapTextureUniform", currentTextureBindingPoint);
  43705. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  43706. gl.bindTexture(matcapTexture.target, matcapTexture.id);
  43707. currentTextureBindingPoint++;
  43708. if (material.snapEnabled === true) {
  43709. {
  43710. const lSnapshot = shader.uniformLocations["uSnapshot[0]"];
  43711. const lSnapshotDepth = shader.uniformLocations["uSnapshotDepth[0]"];
  43712. let bindingStart = currentTextureBindingPoint;
  43713. let lSnapshotBindingPoints = new Array(5).fill(bindingStart).map((a, i) => (a + i));
  43714. let lSnapshotDepthBindingPoints = new Array(5)
  43715. .fill(1 + Math.max(...lSnapshotBindingPoints))
  43716. .map((a, i) => (a + i));
  43717. currentTextureBindingPoint = 1 + Math.max(...lSnapshotDepthBindingPoints);
  43718. gl.uniform1iv(lSnapshot, lSnapshotBindingPoints);
  43719. gl.uniform1iv(lSnapshotDepth, lSnapshotDepthBindingPoints);
  43720. for (let i = 0; i < 5; i++) {
  43721. let texture = material.uniforms[`uSnapshot`].value[i];
  43722. let textureDepth = material.uniforms[`uSnapshotDepth`].value[i];
  43723. if (!texture) {
  43724. break;
  43725. }
  43726. let snapTexture = this.threeRenderer.properties.get(texture).__webglTexture;
  43727. let snapTextureDepth = this.threeRenderer.properties.get(textureDepth).__webglTexture;
  43728. let bindingPoint = lSnapshotBindingPoints[i];
  43729. let depthBindingPoint = lSnapshotDepthBindingPoints[i];
  43730. gl.activeTexture(gl[`TEXTURE${bindingPoint}`]);
  43731. gl.bindTexture(gl.TEXTURE_2D, snapTexture);
  43732. gl.activeTexture(gl[`TEXTURE${depthBindingPoint}`]);
  43733. gl.bindTexture(gl.TEXTURE_2D, snapTextureDepth);
  43734. }
  43735. }
  43736. {
  43737. let flattenedMatrices = [].concat(...material.uniforms.uSnapView.value.map(c => c.elements));
  43738. const lSnapView = shader.uniformLocations["uSnapView[0]"];
  43739. gl.uniformMatrix4fv(lSnapView, false, flattenedMatrices);
  43740. }
  43741. {
  43742. let flattenedMatrices = [].concat(...material.uniforms.uSnapProj.value.map(c => c.elements));
  43743. const lSnapProj = shader.uniformLocations["uSnapProj[0]"];
  43744. gl.uniformMatrix4fv(lSnapProj, false, flattenedMatrices);
  43745. }
  43746. {
  43747. let flattenedMatrices = [].concat(...material.uniforms.uSnapProjInv.value.map(c => c.elements));
  43748. const lSnapProjInv = shader.uniformLocations["uSnapProjInv[0]"];
  43749. gl.uniformMatrix4fv(lSnapProjInv, false, flattenedMatrices);
  43750. }
  43751. {
  43752. let flattenedMatrices = [].concat(...material.uniforms.uSnapViewInv.value.map(c => c.elements));
  43753. const lSnapViewInv = shader.uniformLocations["uSnapViewInv[0]"];
  43754. gl.uniformMatrix4fv(lSnapViewInv, false, flattenedMatrices);
  43755. }
  43756. }
  43757. }
  43758. this.renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params);
  43759. gl.activeTexture(gl.TEXTURE2);
  43760. gl.bindTexture(gl.TEXTURE_2D, null);
  43761. gl.activeTexture(gl.TEXTURE0);
  43762. }
  43763. render(scene, camera, target = null, params = {}) {
  43764. const gl = this.gl;
  43765. // PREPARE
  43766. if (target != null) {
  43767. this.threeRenderer.setRenderTarget(target);
  43768. }
  43769. //camera.updateProjectionMatrix();
  43770. // camera.matrixWorldInverse.invert(camera.matrixWorld);
  43771. const traversalResult = this.traverse(scene);
  43772. // RENDER
  43773. for (const octree of traversalResult.octrees) {
  43774. let nodes = octree.visibleNodes;
  43775. this.renderOctree(octree, nodes, camera, target, params);
  43776. }
  43777. // CLEANUP
  43778. gl.activeTexture(gl.TEXTURE1);
  43779. gl.bindTexture(gl.TEXTURE_2D, null);
  43780. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  43781. gl.bindVertexArray(null);
  43782. this.threeRenderer.resetState();
  43783. }
  43784. };
  43785. function copyMaterial(source, target){
  43786. for(let name of Object.keys(target.uniforms)){
  43787. target.uniforms[name].value = source.uniforms[name].value;
  43788. }
  43789. target.gradientTexture = source.gradientTexture;
  43790. target.visibleNodesTexture = source.visibleNodesTexture;
  43791. target.classificationTexture = source.classificationTexture;
  43792. target.matcapTexture = source.matcapTexture;
  43793. target.activeAttributeName = source.activeAttributeName;
  43794. target.ranges = source.ranges;
  43795. //target.updateShaderSource();
  43796. }
  43797. class Batch{
  43798. constructor(geometry, material){
  43799. this.geometry = geometry;
  43800. this.material = material;
  43801. this.sceneNode = new Points(geometry, material);
  43802. this.geometryNode = {
  43803. estimatedSpacing: 1.0,
  43804. geometry: geometry,
  43805. };
  43806. }
  43807. getLevel(){
  43808. return 0;
  43809. }
  43810. }
  43811. class ProfileFakeOctree extends PointCloudTree{
  43812. constructor(octree){
  43813. super();
  43814. this.trueOctree = octree;
  43815. this.pcoGeometry = octree.pcoGeometry;
  43816. this.points = [];
  43817. this.visibleNodes = [];
  43818. //this.material = this.trueOctree.material;
  43819. this.material = new PointCloudMaterial$1();
  43820. //this.material.copy(this.trueOctree.material);
  43821. copyMaterial(this.trueOctree.material, this.material);
  43822. this.material.pointSizeType = PointSizeType.FIXED;
  43823. this.batchSize = 100 * 1000;
  43824. this.currentBatch = null;
  43825. }
  43826. getAttribute(name){
  43827. return this.trueOctree.getAttribute(name);
  43828. }
  43829. dispose(){
  43830. for(let node of this.visibleNodes){
  43831. node.geometry.dispose();
  43832. }
  43833. this.visibleNodes = [];
  43834. this.currentBatch = null;
  43835. this.points = [];
  43836. }
  43837. addPoints(data){
  43838. // since each call to addPoints can deliver very very few points,
  43839. // we're going to batch them into larger buffers for efficiency.
  43840. if(this.currentBatch === null){
  43841. this.currentBatch = this.createNewBatch(data);
  43842. }
  43843. this.points.push(data);
  43844. let updateRange = {
  43845. start: this.currentBatch.geometry.drawRange.count,
  43846. count: 0
  43847. };
  43848. let projectedBox = new Box3();
  43849. let truePos = new Vector3();
  43850. for(let i = 0; i < data.numPoints; i++){
  43851. if(updateRange.start + updateRange.count >= this.batchSize){
  43852. // current batch full, start new batch
  43853. for(let key of Object.keys(this.currentBatch.geometry.attributes)){
  43854. let attribute = this.currentBatch.geometry.attributes[key];
  43855. attribute.updateRange.offset = updateRange.start;
  43856. attribute.updateRange.count = updateRange.count;
  43857. attribute.needsUpdate = true;
  43858. }
  43859. this.currentBatch.geometry.computeBoundingBox();
  43860. this.currentBatch.geometry.computeBoundingSphere();
  43861. this.currentBatch = this.createNewBatch(data);
  43862. updateRange = {
  43863. start: 0,
  43864. count: 0
  43865. };
  43866. }
  43867. truePos.set(
  43868. data.data.position[3 * i + 0] + this.trueOctree.position.x,
  43869. data.data.position[3 * i + 1] + this.trueOctree.position.y,
  43870. data.data.position[3 * i + 2] + this.trueOctree.position.z,
  43871. );
  43872. let x = data.data.mileage[i];
  43873. let y = 0;
  43874. let z = truePos.z;
  43875. projectedBox.expandByPoint(new Vector3(x, y, z));
  43876. let index = updateRange.start + updateRange.count;
  43877. let geometry = this.currentBatch.geometry;
  43878. for(let attributeName of Object.keys(data.data)){
  43879. let source = data.data[attributeName];
  43880. let target = geometry.attributes[attributeName];
  43881. let numElements = target.itemSize;
  43882. for(let item = 0; item < numElements; item++){
  43883. target.array[numElements * index + item] = source[numElements * i + item];
  43884. }
  43885. }
  43886. {
  43887. let position = geometry.attributes.position;
  43888. position.array[3 * index + 0] = x;
  43889. position.array[3 * index + 1] = y;
  43890. position.array[3 * index + 2] = z;
  43891. }
  43892. updateRange.count++;
  43893. this.currentBatch.geometry.drawRange.count++;
  43894. }
  43895. for(let key of Object.keys(this.currentBatch.geometry.attributes)){
  43896. let attribute = this.currentBatch.geometry.attributes[key];
  43897. attribute.updateRange.offset = updateRange.start;
  43898. attribute.updateRange.count = updateRange.count;
  43899. attribute.needsUpdate = true;
  43900. }
  43901. data.projectedBox = projectedBox;
  43902. this.projectedBox = this.points.reduce( (a, i) => a.union(i.projectedBox), new Box3());
  43903. }
  43904. createNewBatch(data){
  43905. let geometry = new BufferGeometry();
  43906. // create new batches with batch_size elements of the same type as the attribute
  43907. for(let attributeName of Object.keys(data.data)){
  43908. let buffer = data.data[attributeName];
  43909. let numElements = buffer.length / data.numPoints; // 3 for pos, 4 for col, 1 for scalars
  43910. let constructor = buffer.constructor;
  43911. let normalized = false;
  43912. if(this.trueOctree.root.sceneNode){
  43913. if(this.trueOctree.root.sceneNode.geometry.attributes[attributeName]){
  43914. normalized = this.trueOctree.root.sceneNode.geometry.attributes[attributeName].normalized;
  43915. }
  43916. }
  43917. let batchBuffer = new constructor(numElements * this.batchSize);
  43918. let bufferAttribute = new BufferAttribute(batchBuffer, numElements, normalized);
  43919. bufferAttribute.potree = {
  43920. range: [0, 1],
  43921. };
  43922. geometry.setAttribute(attributeName, bufferAttribute);
  43923. }
  43924. geometry.drawRange.start = 0;
  43925. geometry.drawRange.count = 0;
  43926. let batch = new Batch(geometry, this.material);
  43927. this.visibleNodes.push(batch);
  43928. return batch;
  43929. }
  43930. computeVisibilityTextureData(){
  43931. let data = new Uint8Array(this.visibleNodes.length * 4);
  43932. let offsets = new Map();
  43933. for(let i = 0; i < this.visibleNodes.length; i++){
  43934. let node = this.visibleNodes[i];
  43935. offsets[node] = i;
  43936. }
  43937. return {
  43938. data: data,
  43939. offsets: offsets,
  43940. };
  43941. }
  43942. }
  43943. class ProfileWindow extends EventDispatcher$1 {
  43944. constructor (viewer) {
  43945. super();
  43946. this.viewer = viewer;
  43947. this.elRoot = $('#profile_window');
  43948. this.renderArea = this.elRoot.find('#profileCanvasContainer');
  43949. this.svg = d3.select('svg#profileSVG');
  43950. this.mouseIsDown = false;
  43951. this.projectedBox = new Box3();
  43952. this.pointclouds = new Map();
  43953. this.numPoints = 0;
  43954. this.lastAddPointsTimestamp = undefined;
  43955. this.mouse = new Vector2(0, 0);
  43956. this.scale = new Vector3(1, 1, 1);
  43957. this.autoFitEnabled = true; // completely disable/enable
  43958. this.autoFit = false; // internal
  43959. let cwIcon = `${exports.resourcePath}/icons/arrow_cw.svg`;
  43960. $('#potree_profile_rotate_cw').attr('src', cwIcon);
  43961. let ccwIcon = `${exports.resourcePath}/icons/arrow_ccw.svg`;
  43962. $('#potree_profile_rotate_ccw').attr('src', ccwIcon);
  43963. let forwardIcon = `${exports.resourcePath}/icons/arrow_up.svg`;
  43964. $('#potree_profile_move_forward').attr('src', forwardIcon);
  43965. let backwardIcon = `${exports.resourcePath}/icons/arrow_down.svg`;
  43966. $('#potree_profile_move_backward').attr('src', backwardIcon);
  43967. let csvIcon = `${exports.resourcePath}/icons/file_csv_2d.svg`;
  43968. $('#potree_download_csv_icon').attr('src', csvIcon);
  43969. let lasIcon = `${exports.resourcePath}/icons/file_las_3d.svg`;
  43970. $('#potree_download_las_icon').attr('src', lasIcon);
  43971. let closeIcon = `${exports.resourcePath}/icons/close.svg`;
  43972. $('#closeProfileContainer').attr("src", closeIcon);
  43973. this.initTHREE();
  43974. this.initSVG();
  43975. this.initListeners();
  43976. this.pRenderer = new Renderer(this.renderer);
  43977. this.elRoot.i18n();
  43978. }
  43979. initListeners () {
  43980. $(window).resize(() => {
  43981. if (this.enabled) {
  43982. this.render();
  43983. }
  43984. });
  43985. this.renderArea.mousedown(e => {
  43986. this.mouseIsDown = true;
  43987. });
  43988. this.renderArea.mouseup(e => {
  43989. this.mouseIsDown = false;
  43990. });
  43991. let viewerPickSphereSizeHandler = () => {
  43992. let camera = this.viewer.scene.getActiveCamera();
  43993. let domElement = this.viewer.renderer.domElement;
  43994. let distance = this.viewerPickSphere.position.distanceTo(camera.position);
  43995. let pr = Utils.projectedRadius(1, camera, distance, domElement.clientWidth, domElement.clientHeight);
  43996. let scale = (10 / pr);
  43997. this.viewerPickSphere.scale.set(scale, scale, scale);
  43998. };
  43999. this.renderArea.mousemove(e => {
  44000. if (this.pointclouds.size === 0) {
  44001. return;
  44002. }
  44003. let rect = this.renderArea[0].getBoundingClientRect();
  44004. let x = e.clientX - rect.left;
  44005. let y = e.clientY - rect.top;
  44006. let newMouse = new Vector2(x, y);
  44007. if (this.mouseIsDown) {
  44008. // DRAG
  44009. this.autoFit = false;
  44010. this.lastDrag = new Date().getTime();
  44011. let cPos = [this.scaleX.invert(this.mouse.x), this.scaleY.invert(this.mouse.y)];
  44012. let ncPos = [this.scaleX.invert(newMouse.x), this.scaleY.invert(newMouse.y)];
  44013. this.camera.position.x -= ncPos[0] - cPos[0];
  44014. this.camera.position.z -= ncPos[1] - cPos[1];
  44015. this.render();
  44016. } else if (this.pointclouds.size > 0) {
  44017. // FIND HOVERED POINT
  44018. let radius = Math.abs(this.scaleX.invert(0) - this.scaleX.invert(40));
  44019. let mileage = this.scaleX.invert(newMouse.x);
  44020. let elevation = this.scaleY.invert(newMouse.y);
  44021. let closest = this.selectPoint(mileage, elevation, radius);
  44022. if (closest) {
  44023. let point = closest.point;
  44024. let position = new Float64Array([
  44025. point.position[0] + closest.pointcloud.position.x,
  44026. point.position[1] + closest.pointcloud.position.y,
  44027. point.position[2] + closest.pointcloud.position.z
  44028. ]);
  44029. this.elRoot.find('#profileSelectionProperties').fadeIn(200);
  44030. this.pickSphere.visible = true;
  44031. this.pickSphere.scale.set(0.5 * radius, 0.5 * radius, 0.5 * radius);
  44032. this.pickSphere.position.set(point.mileage, 0, position[2]);
  44033. this.viewerPickSphere.position.set(...position);
  44034. if(!this.viewer.scene.scene.children.includes(this.viewerPickSphere)){
  44035. this.viewer.scene.scene.add(this.viewerPickSphere);
  44036. if(!this.viewer.hasEventListener("update", viewerPickSphereSizeHandler)){
  44037. this.viewer.addEventListener("update", viewerPickSphereSizeHandler);
  44038. }
  44039. }
  44040. let info = this.elRoot.find('#profileSelectionProperties');
  44041. let html = '<table>';
  44042. for (let attributeName of Object.keys(point)) {
  44043. let value = point[attributeName];
  44044. let attribute = closest.pointcloud.getAttribute(attributeName);
  44045. let transform = value => value;
  44046. if(attribute && attribute.type.size > 4){
  44047. let range = attribute.initialRange;
  44048. let scale = 1 / (range[1] - range[0]);
  44049. let offset = range[0];
  44050. transform = value => value / scale + offset;
  44051. }
  44052. if (attributeName === 'position') {
  44053. let values = [...position].map(v => Utils.addCommas(v.toFixed(3)));
  44054. html += `
  44055. <tr>
  44056. <td>x</td>
  44057. <td>${values[0]}</td>
  44058. </tr>
  44059. <tr>
  44060. <td>y</td>
  44061. <td>${values[1]}</td>
  44062. </tr>
  44063. <tr>
  44064. <td>z</td>
  44065. <td>${values[2]}</td>
  44066. </tr>`;
  44067. } else if (attributeName === 'rgba') {
  44068. html += `
  44069. <tr>
  44070. <td>${attributeName}</td>
  44071. <td>${value.join(', ')}</td>
  44072. </tr>`;
  44073. } else if (attributeName === 'normal') {
  44074. continue;
  44075. } else if (attributeName === 'mileage') {
  44076. html += `
  44077. <tr>
  44078. <td>${attributeName}</td>
  44079. <td>${value.toFixed(3)}</td>
  44080. </tr>`;
  44081. } else {
  44082. html += `
  44083. <tr>
  44084. <td>${attributeName}</td>
  44085. <td>${transform(value)}</td>
  44086. </tr>`;
  44087. }
  44088. }
  44089. html += '</table>';
  44090. info.html(html);
  44091. this.selectedPoint = point;
  44092. } else {
  44093. // this.pickSphere.visible = false;
  44094. // this.selectedPoint = null;
  44095. this.viewer.scene.scene.add(this.viewerPickSphere);
  44096. let index = this.viewer.scene.scene.children.indexOf(this.viewerPickSphere);
  44097. if(index >= 0){
  44098. this.viewer.scene.scene.children.splice(index, 1);
  44099. }
  44100. this.viewer.removeEventListener("update", viewerPickSphereSizeHandler);
  44101. }
  44102. this.render();
  44103. }
  44104. this.mouse.copy(newMouse);
  44105. });
  44106. let onWheel = e => {
  44107. this.autoFit = false;
  44108. let delta = 0;
  44109. if (e.wheelDelta !== undefined) { // WebKit / Opera / Explorer 9
  44110. delta = e.wheelDelta;
  44111. } else if (e.detail !== undefined) { // Firefox
  44112. delta = -e.detail;
  44113. }
  44114. let ndelta = Math.sign(delta);
  44115. let cPos = [this.scaleX.invert(this.mouse.x), this.scaleY.invert(this.mouse.y)];
  44116. if (ndelta > 0) {
  44117. // + 10%
  44118. this.scale.multiplyScalar(1.1);
  44119. } else {
  44120. // - 10%
  44121. this.scale.multiplyScalar(100 / 110);
  44122. }
  44123. this.updateScales();
  44124. let ncPos = [this.scaleX.invert(this.mouse.x), this.scaleY.invert(this.mouse.y)];
  44125. this.camera.position.x -= ncPos[0] - cPos[0];
  44126. this.camera.position.z -= ncPos[1] - cPos[1];
  44127. this.render();
  44128. this.updateScales();
  44129. };
  44130. $(this.renderArea)[0].addEventListener('mousewheel', onWheel, false);
  44131. $(this.renderArea)[0].addEventListener('DOMMouseScroll', onWheel, false); // Firefox
  44132. $('#closeProfileContainer').click(() => {
  44133. this.hide();
  44134. });
  44135. let getProfilePoints = () => {
  44136. let points = new Points$1();
  44137. for(let [pointcloud, entry] of this.pointclouds){
  44138. for(let pointSet of entry.points){
  44139. let originPos = pointSet.data.position;
  44140. let trueElevationPosition = new Float32Array(originPos);
  44141. for(let i = 0; i < pointSet.numPoints; i++){
  44142. trueElevationPosition[3 * i + 2] += pointcloud.position.z;
  44143. }
  44144. pointSet.data.position = trueElevationPosition;
  44145. points.add(pointSet);
  44146. pointSet.data.position = originPos;
  44147. }
  44148. }
  44149. return points;
  44150. };
  44151. $('#potree_download_csv_icon').click(() => {
  44152. let points = getProfilePoints();
  44153. let string = CSVExporter.toString(points);
  44154. let blob = new Blob([string], {type: "text/string"});
  44155. $('#potree_download_profile_ortho_link').attr('href', URL.createObjectURL(blob));
  44156. });
  44157. $('#potree_download_las_icon').click(() => {
  44158. let points = getProfilePoints();
  44159. let buffer = LASExporter.toLAS(points);
  44160. let blob = new Blob([buffer], {type: "application/octet-binary"});
  44161. $('#potree_download_profile_link').attr('href', URL.createObjectURL(blob));
  44162. });
  44163. }
  44164. selectPoint (mileage, elevation, radius) {
  44165. let closest = {
  44166. distance: Infinity,
  44167. pointcloud: null,
  44168. points: null,
  44169. index: null
  44170. };
  44171. let pointBox = new Box2(
  44172. new Vector2(mileage - radius, elevation - radius),
  44173. new Vector2(mileage + radius, elevation + radius));
  44174. let numTested = 0;
  44175. let numSkipped = 0;
  44176. let numTestedPoints = 0;
  44177. let numSkippedPoints = 0;
  44178. for (let [pointcloud, entry] of this.pointclouds) {
  44179. for(let points of entry.points){
  44180. let collisionBox = new Box2(
  44181. new Vector2(points.projectedBox.min.x, points.projectedBox.min.z),
  44182. new Vector2(points.projectedBox.max.x, points.projectedBox.max.z)
  44183. );
  44184. let intersects = collisionBox.intersectsBox(pointBox);
  44185. if(!intersects){
  44186. numSkipped++;
  44187. numSkippedPoints += points.numPoints;
  44188. continue;
  44189. }
  44190. numTested++;
  44191. numTestedPoints += points.numPoints;
  44192. for (let i = 0; i < points.numPoints; i++) {
  44193. let m = points.data.mileage[i] - mileage;
  44194. let e = points.data.position[3 * i + 2] - elevation + pointcloud.position.z;
  44195. let r = Math.sqrt(m * m + e * e);
  44196. const withinDistance = r < radius && r < closest.distance;
  44197. let unfilteredClass = true;
  44198. if(points.data.classification){
  44199. const classification = pointcloud.material.classification;
  44200. const pointClassID = points.data.classification[i];
  44201. const pointClassValue = classification[pointClassID];
  44202. if(pointClassValue && (!pointClassValue.visible || pointClassValue.color.w === 0)){
  44203. unfilteredClass = false;
  44204. }
  44205. }
  44206. if (withinDistance && unfilteredClass) {
  44207. closest = {
  44208. distance: r,
  44209. pointcloud: pointcloud,
  44210. points: points,
  44211. index: i
  44212. };
  44213. }
  44214. }
  44215. }
  44216. }
  44217. //console.log(`nodes: ${numTested}, ${numSkipped} || points: ${numTestedPoints}, ${numSkippedPoints}`);
  44218. if (closest.distance < Infinity) {
  44219. let points = closest.points;
  44220. let point = {};
  44221. let attributes = Object.keys(points.data);
  44222. for (let attribute of attributes) {
  44223. let attributeData = points.data[attribute];
  44224. let itemSize = attributeData.length / points.numPoints;
  44225. let value = attributeData.subarray(itemSize * closest.index, itemSize * closest.index + itemSize);
  44226. if (value.length === 1) {
  44227. point[attribute] = value[0];
  44228. } else {
  44229. point[attribute] = value;
  44230. }
  44231. }
  44232. closest.point = point;
  44233. return closest;
  44234. } else {
  44235. return null;
  44236. }
  44237. }
  44238. initTHREE () {
  44239. this.renderer = new WebGLRenderer({alpha: true, premultipliedAlpha: false});
  44240. this.renderer.setClearColor(0x000000, 0);
  44241. this.renderer.setSize(10, 10);
  44242. this.renderer.autoClear = false;
  44243. this.renderArea.append($(this.renderer.domElement));
  44244. this.renderer.domElement.tabIndex = '2222';
  44245. $(this.renderer.domElement).css('width', '100%');
  44246. $(this.renderer.domElement).css('height', '100%');
  44247. {
  44248. let gl = this.renderer.getContext();
  44249. if(gl.createVertexArray == null){
  44250. let extVAO = gl.getExtension('OES_vertex_array_object');
  44251. if(!extVAO){
  44252. throw new Error("OES_vertex_array_object extension not supported");
  44253. }
  44254. gl.createVertexArray = extVAO.createVertexArrayOES.bind(extVAO);
  44255. gl.bindVertexArray = extVAO.bindVertexArrayOES.bind(extVAO);
  44256. }
  44257. }
  44258. this.camera = new OrthographicCamera(-1000, 1000, 1000, -1000, -1000, 1000);
  44259. this.camera.up.set(0, 0, 1);
  44260. this.camera.rotation.order = "ZXY";
  44261. this.camera.rotation.x = Math.PI / 2.0;
  44262. this.scene = new Scene();
  44263. this.profileScene = new Scene();
  44264. let sg = new SphereGeometry(1, 16, 16);
  44265. let sm = new MeshNormalMaterial();
  44266. this.pickSphere = new Mesh(sg, sm);
  44267. this.scene.add(this.pickSphere);
  44268. this.viewerPickSphere = new Mesh(sg, sm);
  44269. }
  44270. initSVG () {
  44271. let width = this.renderArea[0].clientWidth;
  44272. let height = this.renderArea[0].clientHeight;
  44273. let marginLeft = this.renderArea[0].offsetLeft;
  44274. this.svg.selectAll('*').remove();
  44275. this.scaleX = d3.scale.linear()
  44276. .domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x])
  44277. .range([0, width]);
  44278. this.scaleY = d3.scale.linear()
  44279. .domain([this.camera.bottom + this.camera.position.z, this.camera.top + this.camera.position.z])
  44280. .range([height, 0]);
  44281. this.xAxis = d3.svg.axis()
  44282. .scale(this.scaleX)
  44283. .orient('bottom')
  44284. .innerTickSize(-height)
  44285. .outerTickSize(1)
  44286. .tickPadding(10)
  44287. .ticks(width / 50);
  44288. this.yAxis = d3.svg.axis()
  44289. .scale(this.scaleY)
  44290. .orient('left')
  44291. .innerTickSize(-width)
  44292. .outerTickSize(1)
  44293. .tickPadding(10)
  44294. .ticks(height / 20);
  44295. this.elXAxis = this.svg.append('g')
  44296. .attr('class', 'x axis')
  44297. .attr('transform', `translate(${marginLeft}, ${height})`)
  44298. .call(this.xAxis);
  44299. this.elYAxis = this.svg.append('g')
  44300. .attr('class', 'y axis')
  44301. .attr('transform', `translate(${marginLeft}, 0)`)
  44302. .call(this.yAxis);
  44303. }
  44304. addPoints (pointcloud, points) {
  44305. if(points.numPoints === 0){
  44306. return;
  44307. }
  44308. let entry = this.pointclouds.get(pointcloud);
  44309. if(!entry){
  44310. entry = new ProfileFakeOctree(pointcloud);
  44311. this.pointclouds.set(pointcloud, entry);
  44312. this.profileScene.add(entry);
  44313. let materialChanged = () => {
  44314. this.render();
  44315. };
  44316. materialChanged();
  44317. pointcloud.material.addEventListener('material_property_changed', materialChanged);
  44318. this.addEventListener("on_reset_once", () => {
  44319. pointcloud.material.removeEventListener('material_property_changed', materialChanged);
  44320. });
  44321. }
  44322. entry.addPoints(points);
  44323. this.projectedBox.union(entry.projectedBox);
  44324. if (this.autoFit && this.autoFitEnabled) {
  44325. let width = this.renderArea[0].clientWidth;
  44326. let height = this.renderArea[0].clientHeight;
  44327. let size = this.projectedBox.getSize(new Vector3());
  44328. let sx = width / size.x;
  44329. let sy = height / size.z;
  44330. let scale = Math.min(sx, sy);
  44331. let center = this.projectedBox.getCenter(new Vector3());
  44332. this.scale.set(scale, scale, 1);
  44333. this.camera.position.copy(center);
  44334. //console.log("camera: ", this.camera.position.toArray().join(", "));
  44335. }
  44336. //console.log(entry);
  44337. this.render();
  44338. let numPoints = 0;
  44339. for (let [key, value] of this.pointclouds.entries()) {
  44340. numPoints += value.points.reduce( (a, i) => a + i.numPoints, 0);
  44341. }
  44342. $(`#profile_num_points`).html(Utils.addCommas(numPoints));
  44343. }
  44344. reset () {
  44345. this.lastReset = new Date().getTime();
  44346. this.dispatchEvent({type: "on_reset_once"});
  44347. this.removeEventListeners("on_reset_once");
  44348. this.autoFit = true;
  44349. this.projectedBox = new Box3();
  44350. for(let [key, entry] of this.pointclouds){
  44351. entry.dispose();
  44352. }
  44353. this.pointclouds.clear();
  44354. this.mouseIsDown = false;
  44355. this.mouse.set(0, 0);
  44356. if(this.autoFitEnabled){
  44357. this.scale.set(1, 1, 1);
  44358. }
  44359. this.pickSphere.visible = false;
  44360. this.elRoot.find('#profileSelectionProperties').hide();
  44361. this.render();
  44362. }
  44363. show () {
  44364. this.elRoot.fadeIn();
  44365. this.enabled = true;
  44366. }
  44367. hide () {
  44368. this.elRoot.fadeOut();
  44369. this.enabled = false;
  44370. }
  44371. updateScales () {
  44372. let width = this.renderArea[0].clientWidth;
  44373. let height = this.renderArea[0].clientHeight;
  44374. let left = (-width / 2) / this.scale.x;
  44375. let right = (+width / 2) / this.scale.x;
  44376. let top = (+height / 2) / this.scale.y;
  44377. let bottom = (-height / 2) / this.scale.y;
  44378. this.camera.left = left;
  44379. this.camera.right = right;
  44380. this.camera.top = top;
  44381. this.camera.bottom = bottom;
  44382. this.camera.updateProjectionMatrix();
  44383. this.scaleX.domain([this.camera.left + this.camera.position.x, this.camera.right + this.camera.position.x])
  44384. .range([0, width]);
  44385. this.scaleY.domain([this.camera.bottom + this.camera.position.z, this.camera.top + this.camera.position.z])
  44386. .range([height, 0]);
  44387. let marginLeft = this.renderArea[0].offsetLeft;
  44388. this.xAxis.scale(this.scaleX)
  44389. .orient('bottom')
  44390. .innerTickSize(-height)
  44391. .outerTickSize(1)
  44392. .tickPadding(10)
  44393. .ticks(width / 50);
  44394. this.yAxis.scale(this.scaleY)
  44395. .orient('left')
  44396. .innerTickSize(-width)
  44397. .outerTickSize(1)
  44398. .tickPadding(10)
  44399. .ticks(height / 20);
  44400. this.elXAxis
  44401. .attr('transform', `translate(${marginLeft}, ${height})`)
  44402. .call(this.xAxis);
  44403. this.elYAxis
  44404. .attr('transform', `translate(${marginLeft}, 0)`)
  44405. .call(this.yAxis);
  44406. }
  44407. requestScaleUpdate(){
  44408. let threshold = 100;
  44409. let allowUpdate = ((this.lastReset === undefined) || (this.lastScaleUpdate === undefined))
  44410. || ((new Date().getTime() - this.lastReset) > threshold && (new Date().getTime() - this.lastScaleUpdate) > threshold);
  44411. if(allowUpdate){
  44412. this.updateScales();
  44413. this.lastScaleUpdate = new Date().getTime();
  44414. this.scaleUpdatePending = false;
  44415. }else if(!this.scaleUpdatePending) {
  44416. setTimeout(this.requestScaleUpdate.bind(this), 100);
  44417. this.scaleUpdatePending = true;
  44418. }
  44419. }
  44420. render () {
  44421. let width = this.renderArea[0].clientWidth;
  44422. let height = this.renderArea[0].clientHeight;
  44423. let {renderer, pRenderer, camera, profileScene, scene} = this;
  44424. let {scaleX, pickSphere} = this;
  44425. renderer.setSize(width, height);
  44426. renderer.setClearColor(0x000000, 0);
  44427. renderer.clear(true, true, false);
  44428. for(let pointcloud of this.pointclouds.keys()){
  44429. let source = pointcloud.material;
  44430. let target = this.pointclouds.get(pointcloud).material;
  44431. copyMaterial(source, target);
  44432. target.size = 2;
  44433. }
  44434. pRenderer.render(profileScene, camera, null);
  44435. let radius = Math.abs(scaleX.invert(0) - scaleX.invert(5));
  44436. if (radius === 0) {
  44437. pickSphere.visible = false;
  44438. } else {
  44439. pickSphere.scale.set(radius, radius, radius);
  44440. pickSphere.visible = true;
  44441. }
  44442. renderer.render(scene, camera);
  44443. this.requestScaleUpdate();
  44444. }
  44445. };
  44446. class ProfileWindowController {
  44447. constructor (viewer) {
  44448. this.viewer = viewer;
  44449. this.profileWindow = viewer.profileWindow;
  44450. this.profile = null;
  44451. this.numPoints = 0;
  44452. this.threshold = 60 * 1000;
  44453. this.rotateAmount = 10;
  44454. this.scheduledRecomputeTime = null;
  44455. this.enabled = true;
  44456. this.requests = [];
  44457. this._recompute = () => { this.recompute(); };
  44458. this.viewer.addEventListener("scene_changed", e => {
  44459. e.oldScene.removeEventListener("pointcloud_added", this._recompute);
  44460. e.scene.addEventListener("pointcloud_added", this._recompute);
  44461. });
  44462. this.viewer.scene.addEventListener("pointcloud_added", this._recompute);
  44463. $("#potree_profile_rotate_amount").val(parseInt(this.rotateAmount));
  44464. $("#potree_profile_rotate_amount").on("input", (e) => {
  44465. const str = $("#potree_profile_rotate_amount").val();
  44466. if(!isNaN(str)){
  44467. const value = parseFloat(str);
  44468. this.rotateAmount = value;
  44469. $("#potree_profile_rotate_amount").css("background-color", "");
  44470. }else {
  44471. $("#potree_profile_rotate_amount").css("background-color", "#ff9999");
  44472. }
  44473. });
  44474. const rotate = (radians) => {
  44475. const profile = this.profile;
  44476. const points = profile.points;
  44477. const start = points[0];
  44478. const end = points[points.length - 1];
  44479. const center = start.clone().add(end).multiplyScalar(0.5);
  44480. const mMoveOrigin = new Matrix4().makeTranslation(-center.x, -center.y, -center.z);
  44481. const mRotate = new Matrix4().makeRotationZ(radians);
  44482. const mMoveBack = new Matrix4().makeTranslation(center.x, center.y, center.z);
  44483. //const transform = mMoveOrigin.multiply(mRotate).multiply(mMoveBack);
  44484. const transform = mMoveBack.multiply(mRotate).multiply(mMoveOrigin);
  44485. const rotatedPoints = points.map( point => point.clone().applyMatrix4(transform) );
  44486. this.profileWindow.autoFitEnabled = false;
  44487. for(let i = 0; i < points.length; i++){
  44488. profile.setPosition(i, rotatedPoints[i]);
  44489. }
  44490. };
  44491. $("#potree_profile_rotate_cw").click( () => {
  44492. const radians = MathUtils.degToRad(this.rotateAmount);
  44493. rotate(-radians);
  44494. });
  44495. $("#potree_profile_rotate_ccw").click( () => {
  44496. const radians = MathUtils.degToRad(this.rotateAmount);
  44497. rotate(radians);
  44498. });
  44499. $("#potree_profile_move_forward").click( () => {
  44500. const profile = this.profile;
  44501. const points = profile.points;
  44502. const start = points[0];
  44503. const end = points[points.length - 1];
  44504. const dir = end.clone().sub(start).normalize();
  44505. const up = new Vector3(0, 0, 1);
  44506. const forward = up.cross(dir);
  44507. const move = forward.clone().multiplyScalar(profile.width / 2);
  44508. this.profileWindow.autoFitEnabled = false;
  44509. for(let i = 0; i < points.length; i++){
  44510. profile.setPosition(i, points[i].clone().add(move));
  44511. }
  44512. });
  44513. $("#potree_profile_move_backward").click( () => {
  44514. const profile = this.profile;
  44515. const points = profile.points;
  44516. const start = points[0];
  44517. const end = points[points.length - 1];
  44518. const dir = end.clone().sub(start).normalize();
  44519. const up = new Vector3(0, 0, 1);
  44520. const forward = up.cross(dir);
  44521. const move = forward.clone().multiplyScalar(-profile.width / 2);
  44522. this.profileWindow.autoFitEnabled = false;
  44523. for(let i = 0; i < points.length; i++){
  44524. profile.setPosition(i, points[i].clone().add(move));
  44525. }
  44526. });
  44527. }
  44528. setProfile (profile) {
  44529. if (this.profile !== null && this.profile !== profile) {
  44530. this.profile.removeEventListener('marker_moved', this._recompute);
  44531. this.profile.removeEventListener('marker_added', this._recompute);
  44532. this.profile.removeEventListener('marker_removed', this._recompute);
  44533. this.profile.removeEventListener('width_changed', this._recompute);
  44534. }
  44535. this.profile = profile;
  44536. {
  44537. this.profile.addEventListener('marker_moved', this._recompute);
  44538. this.profile.addEventListener('marker_added', this._recompute);
  44539. this.profile.addEventListener('marker_removed', this._recompute);
  44540. this.profile.addEventListener('width_changed', this._recompute);
  44541. }
  44542. this.recompute();
  44543. }
  44544. reset () {
  44545. this.profileWindow.reset();
  44546. this.numPoints = 0;
  44547. if (this.profile) {
  44548. for (let request of this.requests) {
  44549. request.cancel();
  44550. }
  44551. }
  44552. }
  44553. progressHandler (pointcloud, progress) {
  44554. for (let segment of progress.segments) {
  44555. this.profileWindow.addPoints(pointcloud, segment.points);
  44556. this.numPoints += segment.points.numPoints;
  44557. }
  44558. }
  44559. cancel () {
  44560. for (let request of this.requests) {
  44561. request.cancel();
  44562. // request.finishLevelThenCancel();
  44563. }
  44564. this.requests = [];
  44565. };
  44566. finishLevelThenCancel(){
  44567. for (let request of this.requests) {
  44568. request.finishLevelThenCancel();
  44569. }
  44570. this.requests = [];
  44571. }
  44572. recompute () {
  44573. if (!this.profile) {
  44574. return;
  44575. }
  44576. if (this.scheduledRecomputeTime !== null && this.scheduledRecomputeTime > new Date().getTime()) {
  44577. return;
  44578. } else {
  44579. this.scheduledRecomputeTime = new Date().getTime() + 100;
  44580. }
  44581. this.scheduledRecomputeTime = null;
  44582. this.reset();
  44583. for (let pointcloud of this.viewer.scene.pointclouds.filter(p => p.visible)) {
  44584. let request = pointcloud.getPointsInProfile(this.profile, null, {
  44585. 'onProgress': (event) => {
  44586. if (!this.enabled) {
  44587. return;
  44588. }
  44589. this.progressHandler(pointcloud, event.points);
  44590. if (this.numPoints > this.threshold) {
  44591. this.finishLevelThenCancel();
  44592. }
  44593. },
  44594. 'onFinish': (event) => {
  44595. if (!this.enabled) {
  44596. }
  44597. },
  44598. 'onCancel': () => {
  44599. if (!this.enabled) {
  44600. }
  44601. }
  44602. });
  44603. this.requests.push(request);
  44604. }
  44605. }
  44606. };
  44607. //import { EventDispatcher } from "../EventDispatcher.js";
  44608. class VolumeTool extends EventDispatcher{
  44609. constructor (viewer) {
  44610. super();
  44611. this.viewer = viewer;
  44612. this.renderer = viewer.renderer;
  44613. this.addEventListener('start_inserting_volume', e => {
  44614. this.viewer.dispatchEvent({
  44615. type: 'cancel_insertions'
  44616. });
  44617. });
  44618. this.scene = new Scene();
  44619. this.scene.name = 'scene_volume';
  44620. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  44621. this.onRemove = e => {
  44622. this.scene.remove(e.volume);
  44623. };
  44624. this.onAdd = e => {
  44625. this.scene.add(e.volume);
  44626. };
  44627. for(let volume of viewer.scene.volumes){
  44628. this.onAdd({volume: volume});
  44629. }
  44630. this.viewer.inputHandler.addEventListener('delete', e => {
  44631. let volumes = e.selection.filter(e => (e instanceof Volume));
  44632. volumes.forEach(e => this.viewer.scene.removeVolume(e));
  44633. });
  44634. viewer.addEventListener("update", this.update.bind(this));
  44635. viewer.addEventListener("render.pass.scene", e => this.render(e));
  44636. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  44637. viewer.scene.addEventListener('volume_added', this.onAdd);
  44638. viewer.scene.addEventListener('volume_removed', this.onRemove);
  44639. }
  44640. onSceneChange(e){
  44641. if(e.oldScene){
  44642. e.oldScene.removeEventListeners('volume_added', this.onAdd);
  44643. e.oldScene.removeEventListeners('volume_removed', this.onRemove);
  44644. }
  44645. e.scene.addEventListener('volume_added', this.onAdd);
  44646. e.scene.addEventListener('volume_removed', this.onRemove);
  44647. }
  44648. startInsertion (args = {}) {
  44649. let volume;
  44650. if(args.type){
  44651. volume = new args.type();
  44652. }else {
  44653. volume = new BoxVolume();
  44654. }
  44655. volume.clip = args.clip || false;
  44656. volume.name = args.name || 'Volume';
  44657. this.dispatchEvent({
  44658. type: 'start_inserting_volume',
  44659. volume: volume
  44660. });
  44661. this.viewer.scene.addVolume(volume);
  44662. this.scene.add(volume);
  44663. let cancel = {
  44664. callback: null
  44665. };
  44666. let drag = e => {
  44667. let camera = this.viewer.scene.getActiveCamera();
  44668. let I = Utils.getMousePointCloudIntersection(
  44669. e.drag.end,
  44670. this.viewer.scene.getActiveCamera(),
  44671. this.viewer,
  44672. this.viewer.scene.pointclouds,
  44673. {pickClipped: false});
  44674. if (I) {
  44675. volume.position.copy(I.location);
  44676. let wp = volume.getWorldPosition(new Vector3()).applyMatrix4(camera.matrixWorldInverse);
  44677. // let pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
  44678. let w = Math.abs((wp.z / 5));
  44679. volume.scale.set(w, w, w);
  44680. }
  44681. };
  44682. let drop = e => {
  44683. volume.removeEventListener('drag', drag);
  44684. volume.removeEventListener('drop', drop);
  44685. cancel.callback();
  44686. };
  44687. cancel.callback = e => {
  44688. volume.removeEventListener('drag', drag);
  44689. volume.removeEventListener('drop', drop);
  44690. this.viewer.removeEventListener('cancel_insertions', cancel.callback);
  44691. };
  44692. volume.addEventListener('drag', drag);
  44693. volume.addEventListener('drop', drop);
  44694. this.viewer.addEventListener('cancel_insertions', cancel.callback);
  44695. this.viewer.inputHandler.startDragging(volume);
  44696. return volume;
  44697. }
  44698. update(){
  44699. if (!this.viewer.scene) {
  44700. return;
  44701. }
  44702. let camera = this.viewer.scene.getActiveCamera();
  44703. let renderAreaSize = this.viewer.renderer.getSize(new Vector2());
  44704. let clientWidth = renderAreaSize.width;
  44705. let clientHeight = renderAreaSize.height;
  44706. let volumes = this.viewer.scene.volumes;
  44707. for (let volume of volumes) {
  44708. let label = volume.label;
  44709. {
  44710. let distance = label.position.distanceTo(camera.position);
  44711. let pr = Utils.projectedRadius(1, camera, distance, clientWidth, clientHeight);
  44712. let scale = (70 / pr);
  44713. label.scale.set(scale, scale, scale);
  44714. }
  44715. let calculatedVolume = volume.getVolume();
  44716. 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
  44717. let text = Utils.addCommas(calculatedVolume.toFixed(3)) + ' ' + this.viewer.lengthUnitDisplay.code + '\u00B3';
  44718. label.setText(text);
  44719. }
  44720. }
  44721. render(params){
  44722. const renderer = this.viewer.renderer;
  44723. const oldTarget = renderer.getRenderTarget();
  44724. if(params.renderTarget){
  44725. renderer.setRenderTarget(params.renderTarget);
  44726. }
  44727. renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  44728. renderer.setRenderTarget(oldTarget);
  44729. }
  44730. }
  44731. /**
  44732. *
  44733. * code adapted from three.js BoxHelper.js
  44734. * https://github.com/mrdoob/three.js/blob/dev/src/helpers/BoxHelper.js
  44735. *
  44736. * @author mrdoob / http://mrdoob.com/
  44737. * @author Mugen87 / http://github.com/Mugen87
  44738. * @author mschuetz / http://potree.org
  44739. */
  44740. class Box3Helper$1 extends LineSegments {
  44741. constructor (box, color, depthTest = true) {
  44742. if (color === undefined) color = 0xffff00;
  44743. let 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 ]);
  44744. let positions = new Float32Array([
  44745. box.min.x, box.min.y, box.min.z,
  44746. box.max.x, box.min.y, box.min.z,
  44747. box.max.x, box.min.y, box.max.z,
  44748. box.min.x, box.min.y, box.max.z,
  44749. box.min.x, box.max.y, box.min.z,
  44750. box.max.x, box.max.y, box.min.z,
  44751. box.max.x, box.max.y, box.max.z,
  44752. box.min.x, box.max.y, box.max.z
  44753. ]);
  44754. let geometry = new BufferGeometry();
  44755. geometry.setIndex(new BufferAttribute(indices, 1));
  44756. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  44757. let material = new LineBasicMaterial({ color: color , depthTest});
  44758. super(geometry, material);
  44759. }
  44760. }
  44761. const KeyCodes = {
  44762. LEFT: 37,
  44763. UP: 38,
  44764. RIGHT: 39,
  44765. BOTTOM: 40,
  44766. DELETE: 46,
  44767. A: 'A'.charCodeAt(0),
  44768. S: 'S'.charCodeAt(0),
  44769. D: 'D'.charCodeAt(0),
  44770. W: 'W'.charCodeAt(0),
  44771. Q: 'Q'.charCodeAt(0),
  44772. E: 'E'.charCodeAt(0),
  44773. R: 'R'.charCodeAt(0),
  44774. F: 'F'.charCodeAt(0)
  44775. };
  44776. class NormalizationMaterial extends RawShaderMaterial{
  44777. constructor(parameters = {}){
  44778. super();
  44779. let uniforms = {
  44780. uDepthMap: { type: 't', value: null },
  44781. uWeightMap: { type: 't', value: null },
  44782. };
  44783. this.setValues({
  44784. uniforms: uniforms,
  44785. vertexShader: this.getDefines() + Shaders['normalize.vs'],
  44786. fragmentShader: this.getDefines() + Shaders['normalize.fs'],
  44787. });
  44788. }
  44789. getDefines() {
  44790. let defines = '';
  44791. return defines;
  44792. }
  44793. updateShaderSource() {
  44794. let vs = this.getDefines() + Shaders['normalize.vs'];
  44795. let fs = this.getDefines() + Shaders['normalize.fs'];
  44796. this.setValues({
  44797. vertexShader: vs,
  44798. fragmentShader: fs
  44799. });
  44800. this.needsUpdate = true;
  44801. }
  44802. }
  44803. class NormalizationEDLMaterial extends RawShaderMaterial{
  44804. constructor(parameters = {}){
  44805. super();
  44806. let uniforms = {
  44807. screenWidth: { type: 'f', value: 0 },
  44808. screenHeight: { type: 'f', value: 0 },
  44809. edlStrength: { type: 'f', value: 1.0 },
  44810. radius: { type: 'f', value: 1.0 },
  44811. neighbours: { type: '2fv', value: [] },
  44812. uEDLMap: { type: 't', value: null },
  44813. uDepthMap: { type: 't', value: null },
  44814. uWeightMap: { type: 't', value: null },
  44815. };
  44816. this.setValues({
  44817. uniforms: uniforms,
  44818. vertexShader: this.getDefines() + Shaders['normalize.vs'],
  44819. fragmentShader: this.getDefines() + Shaders['normalize_and_edl.fs'],
  44820. });
  44821. this.neighbourCount = 8;
  44822. }
  44823. getDefines() {
  44824. let defines = '';
  44825. defines += '#define NEIGHBOUR_COUNT ' + this.neighbourCount + '\n';
  44826. return defines;
  44827. }
  44828. updateShaderSource() {
  44829. let vs = this.getDefines() + Shaders['normalize.vs'];
  44830. let fs = this.getDefines() + Shaders['normalize_and_edl.fs'];
  44831. this.setValues({
  44832. vertexShader: vs,
  44833. fragmentShader: fs
  44834. });
  44835. this.uniforms.neighbours.value = this.neighbours;
  44836. this.needsUpdate = true;
  44837. }
  44838. get neighbourCount(){
  44839. return this._neighbourCount;
  44840. }
  44841. set neighbourCount(value){
  44842. if (this._neighbourCount !== value) {
  44843. this._neighbourCount = value;
  44844. this.neighbours = new Float32Array(this._neighbourCount * 2);
  44845. for (let c = 0; c < this._neighbourCount; c++) {
  44846. this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
  44847. this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
  44848. }
  44849. this.updateShaderSource();
  44850. }
  44851. }
  44852. }
  44853. //在potree.shim中修改。 。official中用不到且有bug
  44854. class HQSplatRenderer{
  44855. constructor(viewer){
  44856. this.viewer = viewer;
  44857. this.depthMaterials = new Map();
  44858. this.attributeMaterials = new Map();
  44859. this.normalizationMaterial = null;
  44860. this.rtDepth = null;
  44861. this.rtAttribute = null;
  44862. this.gl = viewer.renderer.getContext();
  44863. this.initialized = false;
  44864. }
  44865. init(){
  44866. if (this.initialized) {
  44867. return;
  44868. }
  44869. this.normalizationMaterial = new NormalizationMaterial();
  44870. this.normalizationMaterial.depthTest = true;
  44871. this.normalizationMaterial.depthWrite = true;
  44872. this.normalizationMaterial.transparent = true;
  44873. this.normalizationEDLMaterial = new NormalizationEDLMaterial();
  44874. this.normalizationEDLMaterial.depthTest = true;
  44875. this.normalizationEDLMaterial.depthWrite = true;
  44876. this.normalizationEDLMaterial.transparent = true;
  44877. this.rtDepth = new WebGLRenderTarget(1024, 1024, {
  44878. minFilter: NearestFilter,
  44879. magFilter: NearestFilter,
  44880. format: RGBAFormat,
  44881. type: FloatType,
  44882. depthTexture: new DepthTexture(undefined, undefined, UnsignedIntType)
  44883. });
  44884. this.rtAttribute = new WebGLRenderTarget(1024, 1024, {
  44885. minFilter: NearestFilter,
  44886. magFilter: NearestFilter,
  44887. format: RGBAFormat,
  44888. type: FloatType,
  44889. depthTexture: this.rtDepth.depthTexture,
  44890. });
  44891. this.initialized = true;
  44892. };
  44893. resize(width, height){
  44894. this.rtDepth.setSize(width, height);
  44895. this.rtAttribute.setSize(width, height);
  44896. }
  44897. clearTargets(){
  44898. const viewer = this.viewer;
  44899. const {renderer} = viewer;
  44900. const oldTarget = renderer.getRenderTarget();
  44901. renderer.setClearColor(0x000000, 0);
  44902. renderer.setRenderTarget( this.rtDepth );
  44903. renderer.clear( true, true, true );
  44904. renderer.setRenderTarget( this.rtAttribute );
  44905. renderer.clear( true, true, true );
  44906. renderer.setRenderTarget(oldTarget);
  44907. }
  44908. clear(){
  44909. this.init();
  44910. const {renderer, background} = this.viewer;
  44911. if(background === "skybox"){
  44912. renderer.setClearColor(0x000000, 0);
  44913. } else if (background === 'gradient') {
  44914. renderer.setClearColor(0x000000, 0);
  44915. } else if (background === 'black') {
  44916. renderer.setClearColor(0x000000, 1);
  44917. } else if (background === 'white') {
  44918. renderer.setClearColor(0xFFFFFF, 1);
  44919. } else {
  44920. renderer.setClearColor(0x000000, 0);
  44921. }
  44922. renderer.clear();
  44923. this.clearTargets();
  44924. }
  44925. render (params) {
  44926. this.init();
  44927. const viewer = this.viewer;
  44928. const camera = params.camera ? params.camera : viewer.scene.getActiveCamera();
  44929. const {width, height} = this.viewer.renderer.getSize(new Vector2());
  44930. viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
  44931. this.resize(width, height);
  44932. const visiblePointClouds = viewer.scene.pointclouds.filter(pc => pc.visible);
  44933. const originalMaterials = new Map();
  44934. for(let pointcloud of visiblePointClouds){
  44935. originalMaterials.set(pointcloud, pointcloud.material);
  44936. if(!this.attributeMaterials.has(pointcloud)){
  44937. let attributeMaterial = new PointCloudMaterial$1();
  44938. this.attributeMaterials.set(pointcloud, attributeMaterial);
  44939. }
  44940. if(!this.depthMaterials.has(pointcloud)){
  44941. let depthMaterial = new PointCloudMaterial$1();
  44942. depthMaterial.setDefine("depth_pass", "#define hq_depth_pass");
  44943. depthMaterial.setDefine("use_edl", "#define use_edl");
  44944. this.depthMaterials.set(pointcloud, depthMaterial);
  44945. }
  44946. }
  44947. { // DEPTH PASS
  44948. for (let pointcloud of visiblePointClouds) {
  44949. let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  44950. let material = originalMaterials.get(pointcloud);
  44951. let depthMaterial = this.depthMaterials.get(pointcloud);
  44952. depthMaterial.size = material.size;
  44953. depthMaterial.minSize = material.minSize;
  44954. depthMaterial.maxSize = material.maxSize;
  44955. depthMaterial.pointSizeType = material.pointSizeType;
  44956. depthMaterial.visibleNodesTexture = material.visibleNodesTexture;
  44957. depthMaterial.weighted = false;
  44958. depthMaterial.screenWidth = width;
  44959. depthMaterial.shape = PointShape$1.CIRCLE;
  44960. depthMaterial.screenHeight = height;
  44961. depthMaterial.uniforms.visibleNodes.value = material.visibleNodesTexture;
  44962. depthMaterial.uniforms.octreeSize.value = octreeSize;
  44963. depthMaterial.spacing = pointcloud.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  44964. depthMaterial.classification = material.classification;
  44965. depthMaterial.uniforms.classificationLUT.value.image.data = material.uniforms.classificationLUT.value.image.data;
  44966. depthMaterial.classificationTexture.needsUpdate = true;
  44967. depthMaterial.uniforms.uFilterReturnNumberRange.value = material.uniforms.uFilterReturnNumberRange.value;
  44968. depthMaterial.uniforms.uFilterNumberOfReturnsRange.value = material.uniforms.uFilterNumberOfReturnsRange.value;
  44969. depthMaterial.uniforms.uFilterGPSTimeClipRange.value = material.uniforms.uFilterGPSTimeClipRange.value;
  44970. depthMaterial.uniforms.uFilterPointSourceIDClipRange.value = material.uniforms.uFilterPointSourceIDClipRange.value;
  44971. depthMaterial.clipTask = material.clipTask;
  44972. depthMaterial.clipMethod = material.clipMethod;
  44973. depthMaterial.setClipBoxes(material.clipBoxes);
  44974. depthMaterial.setClipPolygons(material.clipPolygons);
  44975. pointcloud.material = depthMaterial;
  44976. }
  44977. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtDepth, {
  44978. clipSpheres: viewer.scene.volumes.filter(v => (v instanceof SphereVolume$1)),
  44979. });
  44980. }
  44981. { // ATTRIBUTE PASS
  44982. for (let pointcloud of visiblePointClouds) {
  44983. let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  44984. let material = originalMaterials.get(pointcloud);
  44985. let attributeMaterial = this.attributeMaterials.get(pointcloud);
  44986. attributeMaterial.size = material.size;
  44987. attributeMaterial.minSize = material.minSize;
  44988. attributeMaterial.maxSize = material.maxSize;
  44989. attributeMaterial.pointSizeType = material.pointSizeType;
  44990. attributeMaterial.activeAttributeName = material.activeAttributeName;
  44991. attributeMaterial.visibleNodesTexture = material.visibleNodesTexture;
  44992. attributeMaterial.weighted = true;
  44993. attributeMaterial.screenWidth = width;
  44994. attributeMaterial.screenHeight = height;
  44995. attributeMaterial.shape = PointShape$1.CIRCLE;
  44996. attributeMaterial.uniforms.visibleNodes.value = material.visibleNodesTexture;
  44997. attributeMaterial.uniforms.octreeSize.value = octreeSize;
  44998. attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  44999. attributeMaterial.classification = material.classification;
  45000. attributeMaterial.uniforms.classificationLUT.value.image.data = material.uniforms.classificationLUT.value.image.data;
  45001. attributeMaterial.classificationTexture.needsUpdate = true;
  45002. attributeMaterial.uniforms.uFilterReturnNumberRange.value = material.uniforms.uFilterReturnNumberRange.value;
  45003. attributeMaterial.uniforms.uFilterNumberOfReturnsRange.value = material.uniforms.uFilterNumberOfReturnsRange.value;
  45004. attributeMaterial.uniforms.uFilterGPSTimeClipRange.value = material.uniforms.uFilterGPSTimeClipRange.value;
  45005. attributeMaterial.uniforms.uFilterPointSourceIDClipRange.value = material.uniforms.uFilterPointSourceIDClipRange.value;
  45006. attributeMaterial.elevationGradientRepeat = material.elevationGradientRepeat;
  45007. attributeMaterial.elevationRange = material.elevationRange;
  45008. attributeMaterial.gradient = material.gradient;
  45009. attributeMaterial.matcap = material.matcap;
  45010. attributeMaterial.intensityRange = material.intensityRange;
  45011. attributeMaterial.intensityGamma = material.intensityGamma;
  45012. attributeMaterial.intensityContrast = material.intensityContrast;
  45013. attributeMaterial.intensityBrightness = material.intensityBrightness;
  45014. attributeMaterial.rgbGamma = material.rgbGamma;
  45015. attributeMaterial.rgbContrast = material.rgbContrast;
  45016. attributeMaterial.rgbBrightness = material.rgbBrightness;
  45017. attributeMaterial.weightRGB = material.weightRGB;
  45018. attributeMaterial.weightIntensity = material.weightIntensity;
  45019. attributeMaterial.weightElevation = material.weightElevation;
  45020. attributeMaterial.weightRGB = material.weightRGB;
  45021. attributeMaterial.weightClassification = material.weightClassification;
  45022. attributeMaterial.weightReturnNumber = material.weightReturnNumber;
  45023. attributeMaterial.weightSourceID = material.weightSourceID;
  45024. attributeMaterial.color = material.color;
  45025. attributeMaterial.clipTask = material.clipTask;
  45026. attributeMaterial.clipMethod = material.clipMethod;
  45027. attributeMaterial.setClipBoxes(material.clipBoxes);
  45028. attributeMaterial.setClipPolygons(material.clipPolygons);
  45029. pointcloud.material = attributeMaterial;
  45030. }
  45031. let gl = this.gl;
  45032. viewer.renderer.setRenderTarget(null);
  45033. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtAttribute, {
  45034. clipSpheres: viewer.scene.volumes.filter(v => (v instanceof SphereVolume$1)),
  45035. //material: this.attributeMaterial,
  45036. blendFunc: [gl.SRC_ALPHA, gl.ONE],
  45037. //depthTest: false,
  45038. depthWrite: false
  45039. });
  45040. }
  45041. for(let [pointcloud, material] of originalMaterials){
  45042. pointcloud.material = material;
  45043. }
  45044. viewer.renderer.setRenderTarget(null);
  45045. if(viewer.background === "skybox"){
  45046. viewer.renderer.setClearColor(0x000000, 0);
  45047. viewer.renderer.clear();
  45048. viewer.skybox.camera.rotation.copy(viewer.scene.cameraP.rotation);
  45049. viewer.skybox.camera.fov = viewer.scene.cameraP.fov;
  45050. viewer.skybox.camera.aspect = viewer.scene.cameraP.aspect;
  45051. viewer.skybox.parent.rotation.x = 0;
  45052. viewer.skybox.parent.updateMatrixWorld();
  45053. viewer.skybox.camera.updateProjectionMatrix();
  45054. viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera);
  45055. } else if (viewer.background === 'gradient') {
  45056. viewer.renderer.setClearColor(0x000000, 0);
  45057. viewer.renderer.clear();
  45058. viewer.renderer.render(viewer.scene.sceneBG, viewer.scene.cameraBG);
  45059. } else if (viewer.background === 'black') {
  45060. viewer.renderer.setClearColor(0x000000, 1);
  45061. viewer.renderer.clear();
  45062. } else if (viewer.background === 'white') {
  45063. viewer.renderer.setClearColor(0xFFFFFF, 1);
  45064. viewer.renderer.clear();
  45065. } else {
  45066. viewer.renderer.setClearColor(0x000000, 0);
  45067. viewer.renderer.clear();
  45068. }
  45069. { // NORMALIZATION PASS
  45070. let normalizationMaterial = this.useEDL ? this.normalizationEDLMaterial : this.normalizationMaterial;
  45071. if(this.useEDL){
  45072. normalizationMaterial.uniforms.edlStrength.value = viewer.edlStrength;
  45073. normalizationMaterial.uniforms.radius.value = viewer.edlRadius;
  45074. normalizationMaterial.uniforms.screenWidth.value = width;
  45075. normalizationMaterial.uniforms.screenHeight.value = height;
  45076. normalizationMaterial.uniforms.uEDLMap.value = this.rtDepth.texture;
  45077. }
  45078. normalizationMaterial.uniforms.uWeightMap.value = this.rtAttribute.texture;
  45079. normalizationMaterial.uniforms.uDepthMap.value = this.rtAttribute.depthTexture;
  45080. Utils.screenPass.render(viewer.renderer, normalizationMaterial);
  45081. }
  45082. viewer.renderer.render(viewer.scene.scene, camera);
  45083. viewer.dispatchEvent({type: "render.pass.scene", viewer: viewer});
  45084. viewer.renderer.clearDepth();
  45085. viewer.transformationTool.update();
  45086. viewer.dispatchEvent({type: "render.pass.perspective_overlay",viewer: viewer});
  45087. viewer.renderer.render(viewer.controls.sceneControls, camera);
  45088. viewer.renderer.render(viewer.clippingTool.sceneVolume, camera);
  45089. viewer.renderer.render(viewer.transformationTool.scene, camera);
  45090. viewer.renderer.setViewport(width - viewer.navigationCube.width,
  45091. height - viewer.navigationCube.width,
  45092. viewer.navigationCube.width, viewer.navigationCube.width);
  45093. viewer.renderer.render(viewer.navigationCube, viewer.navigationCube.camera);
  45094. viewer.renderer.setViewport(0, 0, width, height);
  45095. viewer.dispatchEvent({type: "render.pass.end",viewer: viewer});
  45096. }
  45097. }
  45098. class LRUItem{
  45099. constructor(node){
  45100. this.previous = null;
  45101. this.next = null;
  45102. this.node = node;
  45103. }
  45104. }
  45105. /**
  45106. *
  45107. * @class A doubly-linked-list of the least recently used elements.
  45108. */
  45109. class LRU{
  45110. constructor(){ //类似链表存储
  45111. // the least recently used item
  45112. this.first = null;
  45113. // the most recently used item
  45114. this.last = null;
  45115. // a list of all items in the lru list
  45116. this.items = {}; //按node的id存储。(id为0的就是root,name='r')
  45117. this.elements = 0;
  45118. this.numPoints = 0;
  45119. }
  45120. size(){
  45121. return this.elements;
  45122. }
  45123. contains(node){
  45124. return this.items[node.id] == null;
  45125. }
  45126. touch(node){//链接node,并且永远放在最后. (每次updatePointClouds都要刷新一次链表)
  45127. if (!node.loaded) {
  45128. return;
  45129. }
  45130. let item;
  45131. if (this.items[node.id] == null) {
  45132. // add to list
  45133. item = new LRUItem(node);
  45134. item.previous = this.last;
  45135. this.last = item;
  45136. if (item.previous !== null) {
  45137. item.previous.next = item;
  45138. }
  45139. this.items[node.id] = item;
  45140. this.elements++;
  45141. if (this.first === null) {
  45142. this.first = item;
  45143. }
  45144. this.numPoints += node.numPoints;
  45145. } else {
  45146. // update in list
  45147. item = this.items[node.id];
  45148. if (item.previous === null) {
  45149. // handle touch on first element
  45150. if (item.next !== null) {
  45151. this.first = item.next;
  45152. this.first.previous = null;
  45153. item.previous = this.last;
  45154. item.next = null;
  45155. this.last = item;
  45156. item.previous.next = item;
  45157. }
  45158. } else if (item.next === null) {
  45159. // handle touch on last element
  45160. } else {//从原来的位置挑出放最后
  45161. // handle touch on any other element
  45162. item.previous.next = item.next;
  45163. item.next.previous = item.previous;
  45164. item.previous = this.last;
  45165. item.next = null;
  45166. this.last = item;
  45167. item.previous.next = item;
  45168. }
  45169. }
  45170. }
  45171. //因为需要显示的都放末尾,所以不显示的部分都在前面,删除时从头删除。(但并不代表开头的一定是不显示的,所以如果第一个仍是显示的,它很可能是root,也就是name='r'的nodeGeo,删除它也就会删除全部)
  45172. remove(node){
  45173. let lruItem = this.items[node.id];
  45174. if (lruItem) {
  45175. if (this.elements === 1) {
  45176. this.first = null;
  45177. this.last = null;
  45178. } else {
  45179. if (!lruItem.previous) {
  45180. this.first = lruItem.next;
  45181. this.first.previous = null;
  45182. }
  45183. if (!lruItem.next) {
  45184. this.last = lruItem.previous;
  45185. this.last.next = null;
  45186. }
  45187. if (lruItem.previous && lruItem.next) {
  45188. lruItem.previous.next = lruItem.next;
  45189. lruItem.next.previous = lruItem.previous;
  45190. }
  45191. }
  45192. delete this.items[node.id];
  45193. this.elements--;
  45194. this.numPoints -= node.numPoints;
  45195. }
  45196. }
  45197. getLRUItem(){
  45198. if (this.first === null) {
  45199. return null;
  45200. }
  45201. let lru = this.first;
  45202. return lru.node;
  45203. }
  45204. toString(){
  45205. let string = '{ ';
  45206. let curr = this.first;
  45207. while (curr !== null) {
  45208. string += curr.node.id;
  45209. if (curr.next !== null) {
  45210. string += ', ';
  45211. }
  45212. curr = curr.next;
  45213. }
  45214. string += '}';
  45215. string += '(' + this.size() + ')';
  45216. return string;
  45217. }
  45218. freeMemory(){
  45219. if (this.elements <= 1) {
  45220. return;
  45221. }
  45222. while (this.numPoints > Potree.pointLoadLimit) {
  45223. let element = this.first;
  45224. let node = element.node;
  45225. this.disposeDescendants(node);
  45226. }
  45227. }
  45228. disposeDescendants(node){
  45229. let stack = [];
  45230. stack.push(node);
  45231. while (stack.length > 0) {
  45232. let current = stack.pop();
  45233. // console.log(current);
  45234. current.dispose(); //真正删除geometry等
  45235. this.remove(current);
  45236. for (let key in current.children) {
  45237. if (current.children.hasOwnProperty(key)) {
  45238. let child = current.children[key];
  45239. if (child.loaded) {
  45240. stack.push(current.children[key]);
  45241. }
  45242. }
  45243. }
  45244. }
  45245. }
  45246. }
  45247. //
  45248. // how to calculate the radius of a projected sphere in screen space
  45249. // http://stackoverflow.com/questions/21648630/radius-of-projected-sphere-in-screen-space
  45250. // http://stackoverflow.com/questions/3717226/radius-of-projected-sphere
  45251. //
  45252. class ExtendPointCloudMaterial extends PointCloudMaterial$1 {
  45253. constructor (parameters = {}) {
  45254. super(parameters);
  45255. let getValid = (a, b) => {
  45256. if(a !== undefined){
  45257. return a;
  45258. }else {
  45259. return b;
  45260. }
  45261. };
  45262. let maxSize = getValid(parameters.maxSize, 200.0);
  45263. let orthoMaxSize = getValid(parameters.orthoMaxSize, 3.0);
  45264. this._gradient = Gradients.RAINBOW;//Gradients.SPECTRAL;//海拔贴图种类
  45265. this.gradientTexture = ExtendPointCloudMaterial.generateGradientTexture(this._gradient);
  45266. //this.matcapTexture = ExtendPointCloudMaterial.generateMatcapTexture(this._matcap);
  45267. delete this.uniforms.screenWidth;
  45268. delete this.uniforms.screenHeight;
  45269. delete this.uniforms.clipBoxes;
  45270. delete this.uniforms.clipPolygons;
  45271. delete this.uniforms.clipPolygonVCount;
  45272. delete this.uniforms.clipPolygonVP;
  45273. delete this.uniforms.clipBoxCount;
  45274. //注意:这里修改了uniforms后,还需要在PotreeRender中手动传递到shader, like: gl.uniformMatrix4fv(....
  45275. Object.assign(this.uniforms,{
  45276. resolution: { type: 'v2', value: new Vector2() },
  45277. maxSize: { type: "f", value: maxSize },
  45278. orthoMaxSize: { type: "f", value: orthoMaxSize },
  45279. gradient: { type: "t", value: this.gradientTexture },
  45280. clipBoxes_in: { type: "Matrix4fv", value: [] },
  45281. clipBoxes_out: { type: "Matrix4fv", value: [] },
  45282. clipBoxBig_in: { type: "Matrix4fv", value: [] },
  45283. boxes_highlight: { type: "Matrix4fv", value: [] },
  45284. progress: {
  45285. type: "f",
  45286. value: 0
  45287. },
  45288. easeInOutRatio:{
  45289. type: "f",
  45290. value: 0.3
  45291. },
  45292. pano0Map: {
  45293. type: "t",
  45294. value: null
  45295. },
  45296. pano0Position: {
  45297. type: "v3",
  45298. value: new Vector3
  45299. },
  45300. pano0Matrix: {
  45301. type: "m4",
  45302. value: new Matrix4
  45303. },
  45304. pano1Map: {
  45305. type: "t",
  45306. value: null
  45307. },
  45308. pano1Position: {
  45309. type: "v3",
  45310. value: new Vector3
  45311. },
  45312. pano1Matrix: {
  45313. type: "m4",
  45314. value: new Matrix4
  45315. },
  45316. prismList: {
  45317. type: "Matrix3fv",
  45318. value: null
  45319. },
  45320. prismPoints: {
  45321. type: "vec2fv",
  45322. value: null
  45323. },
  45324. baseHeightAreaMap:{
  45325. type:'t',
  45326. value:null
  45327. },
  45328. baseHeightBoundZ:{
  45329. type:'vec2',
  45330. value:new Vector2
  45331. },
  45332. baseHeightBoundXY:{
  45333. type:'vec4',
  45334. value:new Vector4
  45335. },
  45336. });
  45337. delete this.clipBoxes;
  45338. this.clipBoxes_in = [];
  45339. this.clipBoxes_out = [];
  45340. this.highlightBoxes = [];
  45341. this.prisms = [];
  45342. let {vs, fs} = Common.changeShaderToWebgl2(Shaders['pointcloud_new.vs'],Shaders['pointcloud_new.fs'], 'selfBuild' );
  45343. Shaders['pointcloud_new.vs'] = vs;
  45344. Shaders['pointcloud_new.fs'] = fs;
  45345. this.updateShaderSource();
  45346. }
  45347. updateShaderSource () {
  45348. let vs = Shaders['pointcloud_new.vs']; //改
  45349. let fs = Shaders['pointcloud_new.fs']; //改
  45350. let definesString = this.getDefines();
  45351. let vsVersionIndex = vs.indexOf("#version ");
  45352. let fsVersionIndex = fs.indexOf("#version ");
  45353. if(vsVersionIndex >= 0){
  45354. vs = vs.replace(/(#version .*)/, `$1\n${definesString}`);
  45355. }else {
  45356. vs = `${definesString}\n${vs}`;
  45357. }
  45358. if(fsVersionIndex >= 0){
  45359. fs = fs.replace(/(#version .*)/, `$1\n${definesString}`);
  45360. }else {
  45361. fs = `${definesString}\n${fs}`;
  45362. }
  45363. this.vertexShader = vs;
  45364. this.fragmentShader = fs;
  45365. if (this.opacity === 1.0 && !this.useFilterByNormal) {//add useFilterByNormal
  45366. this.blending = NoBlending;
  45367. this.transparent = false;
  45368. this.depthTest = true;
  45369. this.depthWrite = true;
  45370. this.depthFunc = LessEqualDepth;
  45371. } else if ( (this.opacity < 1.0 ||this.useFilterByNormal) && !this.useEDL) {//add useFilterByNormal
  45372. this.blending = AdditiveBlending;
  45373. this.transparent = true;
  45374. this.depthTest = false;
  45375. this.depthWrite = true;
  45376. this.depthFunc = AlwaysDepth;
  45377. }
  45378. if (this.weighted) {
  45379. this.blending = AdditiveBlending;
  45380. this.transparent = true;
  45381. this.depthTest = true;
  45382. this.depthWrite = false;
  45383. }
  45384. this.shaderNeedsUpdate = true;
  45385. }
  45386. getDefines () {
  45387. let defines = [];
  45388. if (this.pointSizeType === PointSizeType.FIXED) {
  45389. defines.push('#define fixed_point_size');
  45390. } else if (this.pointSizeType === PointSizeType.ATTENUATED) {
  45391. defines.push('#define attenuated_point_size');
  45392. } else if (this.pointSizeType === PointSizeType.ADAPTIVE) {
  45393. defines.push('#define adaptive_point_size');
  45394. }
  45395. if(!Features.EXT_DEPTH.isSupported(viewer.renderer.getContext()) && this.shape === PointShape$1.PARABOLOID){
  45396. this.shape = PointShape$1.SQUARE ;//强行替换
  45397. }
  45398. if (this.shape === PointShape$1.SQUARE) {
  45399. defines.push('#define square_point_shape');
  45400. } else if (this.shape === PointShape$1.CIRCLE) {
  45401. defines.push('#define circle_point_shape');
  45402. } else if (this.shape === PointShape$1.PARABOLOID) {
  45403. defines.push('#define paraboloid_point_shape');
  45404. }
  45405. //console.log('this.shape PARABOLOID', this.shape, this.shape === PointShape.PARABOLOID)
  45406. if (this._useEDL || this.fakeEDL) {
  45407. defines.push('#define use_edl');
  45408. }
  45409. if(this.activeAttributeName){
  45410. let attributeName = this.activeAttributeName.replace(/[^a-zA-Z0-9]/g, '_');
  45411. defines.push(`#define color_type_${attributeName}`);
  45412. }
  45413. if(this._treeType === TreeType.OCTREE){
  45414. defines.push('#define tree_type_octree');
  45415. }else if(this._treeType === TreeType.KDTREE){
  45416. defines.push('#define tree_type_kdtree');
  45417. }
  45418. if (this.weighted) {
  45419. defines.push('#define weighted_splats');
  45420. }
  45421. for(let [key, value] of this.defines){
  45422. defines.push(value);
  45423. }
  45424. return defines.join("\n");
  45425. }
  45426. get pointSizeType () {
  45427. return this._pointSizeType;
  45428. }
  45429. set pointSizeType (value) {
  45430. if(typeof value == 'string' )value = PointSizeType[value];
  45431. super.pointSizeType = value;
  45432. /* if (this._pointSizeType !== value) {
  45433. this._pointSizeType = value;
  45434. this.updateShaderSource(); //这句表明这个属性频繁更改会卡顿
  45435. this.dispatchEvent({
  45436. type: 'point_size_type_changed',
  45437. target: this
  45438. });
  45439. this.dispatchEvent({
  45440. type: 'material_property_changed',
  45441. target: this
  45442. });
  45443. } */
  45444. }
  45445. get color () {
  45446. return this.uniforms.uColor.value;
  45447. }
  45448. set color (value) {//改
  45449. if(value == this.color_)return
  45450. let color = value;
  45451. //if (!this.uniforms.uColor.value.equals(value)) {
  45452. if(typeof value == 'string') {
  45453. var colorArr = Potree.config.colors[value];
  45454. if(!colorArr){
  45455. //console.warn('没找到该颜色值'+ value)
  45456. }else {
  45457. color = new Color().fromArray(colorArr).multiplyScalar(1/255);
  45458. }
  45459. }
  45460. this.uniforms.uColor.value.set(color);
  45461. //this.uniforms.uColor.value.copy(value);
  45462. this.dispatchEvent({
  45463. type: 'color_changed',
  45464. target: this
  45465. });
  45466. this.dispatchEvent({
  45467. type: 'material_property_changed',
  45468. target: this
  45469. });
  45470. //}
  45471. this.color_ = value; //记录下str
  45472. }
  45473. ////////////////////////add
  45474. setProjectedPanos(pano0, pano1, progressValue, easeInOutRatio){
  45475. //this.uniforms.usePanoMap.value = 1
  45476. this.usePanoMap = true;
  45477. progressValue!=void 0 && (this.uniforms.progress.value = progressValue);
  45478. //pano0.ensureSkyboxReadyForRender();
  45479. this.uniforms.pano0Map.value = pano0.getSkyboxTexture();
  45480. this.uniforms.pano0Position.value.copy(pano0.position);
  45481. this.uniforms.pano0Matrix.value.copy(pano0.panoMatrix );
  45482. //pano1.ensureSkyboxReadyForRender();
  45483. this.uniforms.easeInOutRatio.value = easeInOutRatio || 0; //之前做点云和全景混合时加的,为了让点云颜色柔和切换到全景颜色。如不混合就0
  45484. this.uniforms.pano1Map.value = pano1.getSkyboxTexture();
  45485. this.uniforms.pano1Position.value.copy(pano1.position);
  45486. this.uniforms.pano1Matrix.value.copy(pano1.panoMatrix );
  45487. //this.updateShaderSource()
  45488. //this.needsUpdate = true;
  45489. }
  45490. stopProjectedPanos(){
  45491. //this.uniforms.usePanoMap.value = 0
  45492. this.usePanoMap = false;
  45493. }
  45494. setClipBoxes (bigClipInBox, clipBoxes_in, clipBoxes_out, highlightBoxes, prismPolygons=[]) {
  45495. if (!clipBoxes_in || !clipBoxes_out) {
  45496. return;
  45497. }
  45498. this.uniforms.clipBoxBig_in.value = bigClipInBox && bigClipInBox.inverse;
  45499. this.uniforms.clipBoxes_in.value = new Float32Array(clipBoxes_in.length * 16);
  45500. this.uniforms.clipBoxes_out.value = new Float32Array(clipBoxes_out.length * 16);
  45501. this.uniforms.boxes_highlight.value = new Float32Array(highlightBoxes.length * 16);
  45502. for (let i = 0; i < clipBoxes_in.length; i++) {
  45503. let box = clipBoxes_in[i];
  45504. this.uniforms.clipBoxes_in.value.set(box.inverse.elements, 16 * i);
  45505. }
  45506. for (let i = 0; i < clipBoxes_out.length; i++) {
  45507. let box = clipBoxes_out[i];
  45508. this.uniforms.clipBoxes_out.value.set(box.inverse.elements, 16 * i);
  45509. }
  45510. for (let i = 0; i < highlightBoxes.length; i++) {
  45511. let box = highlightBoxes[i];
  45512. this.uniforms.boxes_highlight.value.set(box.inverse.elements, 16 * i);
  45513. }
  45514. /* for (let i = 0; i < this.uniforms.clipBoxes.value.length; i++) {??
  45515. if (Number.isNaN(this.uniforms.clipBoxes.value[i])) {
  45516. this.uniforms.clipBoxes.value[i] = Infinity;
  45517. }
  45518. } */
  45519. if(prismPolygons.length){
  45520. let pointsCount = prismPolygons.pointsCount = prismPolygons.reduce((w,c)=>{return w+c.points.length},0);
  45521. this.uniforms.prismList.value = new Float32Array(9 * prismPolygons.length);
  45522. this.uniforms.prismPoints.value = new Float32Array(2 * pointsCount);
  45523. prismPolygons.maxPointsCount = 0;//单个prism最大点个数
  45524. let pointIndex = 0;
  45525. for(let i=0;i<prismPolygons.length;i++ ){
  45526. let bound = prismPolygons[i].prismBound;
  45527. let z = prismPolygons[i].horizonZ;
  45528. //z = Potree.browser.urlHasValue('zmin',true) || zs[0]
  45529. 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[i].points.length ],9*i);
  45530. for(let j=0;j<prismPolygons[i].points.length;j++){
  45531. this.uniforms.prismPoints.value.set([prismPolygons[i].points[j].x, prismPolygons[i].points[j].y] , 2*j+pointIndex);
  45532. }
  45533. pointIndex += 2 * prismPolygons[i].points.length;
  45534. prismPolygons.maxPointsCount = Math.max(prismPolygons.maxPointsCount, prismPolygons[i].points.length);
  45535. }
  45536. }
  45537. let doUpdate = (this.clipBoxes_in.length !== clipBoxes_in.length) || (this.clipBoxes_out.length != clipBoxes_out.length)
  45538. || this.highlightBoxes.length !== highlightBoxes.length
  45539. || !this.bigClipInBox != !bigClipInBox
  45540. || (this.prisms.length != prismPolygons.length) || this.prisms.maxPointsCount != prismPolygons.maxPointsCount;
  45541. //this.clipBoxes = clipBoxes;
  45542. if (doUpdate){
  45543. this.shaderNeedsUpdate = true;
  45544. viewer.dispatchEvent('content_changed');
  45545. }
  45546. this.bigClipInBox = bigClipInBox;
  45547. this.clipBoxes_in = clipBoxes_in;
  45548. this.clipBoxes_out = clipBoxes_out;
  45549. this.highlightBoxes = highlightBoxes;
  45550. this.prisms = prismPolygons;
  45551. }
  45552. }
  45553. var defaultColor = new Color(1,1,1);//config.applicationName == "zhiHouse" ? Colors.zhiBlue : Colors.lightGreen;
  45554. function dealPosArr(points){//识别是否每个点都不一样,把连续点变为不连续的片段连接
  45555. let add = (points)=>{
  45556. let points2 = [] , len = points.length;
  45557. for(let i=0;i<len-1;i++){
  45558. points2.push(points[i], points[i+1]);
  45559. }
  45560. return points2
  45561. };
  45562. if(points[0] && points[0] instanceof Array){//多组,每组间连续,但组之间不连续
  45563. let points2 = [];
  45564. points.forEach(ps=>points2.push(...add(ps)));
  45565. return points2
  45566. }else if(points.length > 2 && !points[2].equals(points[1])){
  45567. return add(points)
  45568. }else return points
  45569. }
  45570. var LineDraw = {
  45571. createLine: function (posArr, o={}) {
  45572. //多段普通线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  45573. var mat;
  45574. if(o.mat){
  45575. mat = o.mat;
  45576. }else {
  45577. let prop = Object.assign({
  45578. lineWidth: o.lineWidth || 1,
  45579. //windows无效。 似乎mac/ios上粗细有效 ?
  45580. color: o.color || defaultColor
  45581. },o);
  45582. if(o.deshed ){
  45583. prop.dashSize = o.dashSize || 0.1,
  45584. prop.gapSize = o.gapSize || 0.1;
  45585. }
  45586. mat = new THREE$1[o.deshed ? "LineDashedMaterial" : "LineBasicMaterial"](prop);
  45587. }
  45588. var line = new LineSegments(new BufferGeometry, mat);
  45589. line.renderOrder = o.renderOrder || Potree.config.renderOrders.lines;
  45590. this.moveLine(line, posArr);
  45591. return line;
  45592. },
  45593. moveLine: function (line, posArr) {
  45594. //if(posArr.length == 0)return
  45595. if(!line.uncontinuous || posArr[0] && posArr[0] instanceof Array)posArr = dealPosArr(posArr);
  45596. let position = [];
  45597. posArr.forEach(e=>position.push(e.x,e.y,e.z));
  45598. line.geometry.setAttribute('position', new Float32BufferAttribute(/* new Float32Array( */position/* ) */, 3));
  45599. line.geometry.attributes.position.needsUpdate = true;
  45600. line.geometry.computeBoundingSphere();
  45601. if(line.material instanceof LineDashedMaterial){
  45602. line.computeLineDistances();
  45603. //line.geometry.attributes.lineDistance.needsUpdate = true;
  45604. line.geometry.verticesNeedUpdate = true; //没用
  45605. }
  45606. }
  45607. ,
  45608. createFatLineMat : function(o){
  45609. var supportExtDepth = !!Features.EXT_DEPTH.isSupported();
  45610. let params = $.extend({}, {
  45611. //默认
  45612. lineWidth : 5,
  45613. color:0xffffff,
  45614. transparent : true, depthWrite:false, depthTest:false,
  45615. dashSize : 0.1, gapSize:0.1,
  45616. }, o, {
  45617. //修正覆盖:
  45618. dashed: o.dashWithDepth ? supportExtDepth && !!o.dashed : !!o.dashed ,
  45619. dashWithDepth:!!o.dashWithDepth,//只在被遮住的部分显示虚线
  45620. useDepth: !!o.useDepth,
  45621. supportExtDepth,
  45622. });
  45623. var mat = new LineMaterial(params);
  45624. //if(o.dashed)(mat.defines.USE_DASH = "")
  45625. return mat;
  45626. },
  45627. /*
  45628. 创建可以改变粗细的线。
  45629. */
  45630. createFatLine : function(posArr, o){
  45631. var geometry = new LineGeometry();
  45632. geometry.setColors( o.color || [1,1,1]);
  45633. var matLine = o.mat || this.createFatLineMat(o);
  45634. var line = new Line2( geometry, matLine );
  45635. //line.computeLineDistances();
  45636. line.uncontinuous = o.uncontinuous; //线不连续,由线段组成
  45637. line.scale.set( 1, 1, 1 );
  45638. line.renderOrder = Potree.config.renderOrders.lines;
  45639. this.moveFatLine(line, posArr);
  45640. return line;
  45641. },
  45642. moveFatLine: function(line, posArr){
  45643. var geometry = line.geometry;
  45644. var positions = [];
  45645. if(!line.uncontinuous || posArr[0] && posArr[0] instanceof Array) posArr = dealPosArr(posArr);
  45646. posArr.forEach(e=>{positions.push(...e.toArray());});
  45647. if(!geometry){
  45648. geometry = line.geometry = new LineGeometry();
  45649. }
  45650. if(geometry.attributes.instanceEnd && geometry.attributes.instanceEnd.data.array.length != positions.length){//positions个数改变会有部分显示不出来,所以重建
  45651. geometry.dispose();
  45652. geometry = new LineGeometry();
  45653. line.geometry = geometry;
  45654. }
  45655. geometry.setPositions( positions );
  45656. if(line.material.defines.USE_DASH != void 0){
  45657. //line.geometry.verticesNeedUpdate = true; //没用
  45658. line.geometry.computeBoundingSphere(); //for raycaster
  45659. line.computeLineDistances();
  45660. }
  45661. },
  45662. updateLine: function(line, posArr){
  45663. if(line instanceof Line2){
  45664. LineDraw.moveFatLine(line,posArr);
  45665. }else {
  45666. LineDraw.moveLine(line,posArr);
  45667. }
  45668. },
  45669. /*
  45670. 为line创建用于检测鼠标的透明mesh,实际是个1-2段圆台。
  45671. 由于近大远小的原因,假设没有透视畸变、创建的是等粗的圆柱的话, 所看到的线上每个位置的粗细应该和距离成反比。所以将圆柱改为根据距离线性渐变其截面半径的圆台,在最近点(相机到线的垂足)最细。如果最近点在线段上,则分成两段圆台,否则一段。
  45672. */
  45673. createBoldLine:function(points, o){
  45674. o = o || {};
  45675. var cylinder = o && o.cylinder;
  45676. var CD = points[1].clone().sub(points[0]);
  45677. var rotate = function(){//根据端点旋转好模型
  45678. cylinder.lastVector = CD;//记录本次的端点向量
  45679. var AB = new Vector3(0,-1,0);
  45680. var axisVec = AB.clone().cross(CD).normalize(); //得到垂直于它们的向量,也就是旋转轴
  45681. var rotationAngle = AB.angleTo(CD);
  45682. cylinder.quaternion.setFromAxisAngle( axisVec, rotationAngle );
  45683. };
  45684. if(o && o.type == "init"){
  45685. cylinder = new Mesh();
  45686. cylinder.material = o.mat;
  45687. if(CD.length() == 0)return cylinder;
  45688. rotate();
  45689. }
  45690. if(CD.length() == 0)return cylinder;
  45691. if(o.type != "update"){
  45692. var CDcenter = points[0].clone().add(points[1]).multiplyScalar(.5);
  45693. cylinder.position.copy(CDcenter);
  45694. if(!cylinder.lastVector || o.type == "moveAndRotate")rotate();
  45695. else if(cylinder.lastVector && CD.angleTo(cylinder.lastVector)>0) rotate();//线方向改了or线反向了 重新旋转一下模型
  45696. if(config.isEdit && !objects.mainDesign.editing )return cylinder;//节省初始加载时间?
  45697. }
  45698. //为了保证线段任何地方的可检测点击范围看起来一样大,更新圆台的结构(但是在镜头边缘会比中心看起来大)
  45699. var height = points[0].distanceTo(points[1]);
  45700. var standPos = o && o.standPos || objects.player.position;
  45701. var k = config.isMobile ? 20 : 40;
  45702. var dis1 = points[0].distanceTo(standPos);
  45703. var dis2 = points[1].distanceTo(standPos);
  45704. var foot = math.getFootPoint(standPos, points[0], points[1]);//垂足
  45705. if(o.constantBold || objects.player.mode != "panorama"){
  45706. var width = 0.1;//0.08;
  45707. var pts = [new Vector2(width ,height/2),new Vector2(width ,-height/2)];
  45708. }else if(foot.clone().sub(points[0]).dot( foot.clone().sub(points[1]) ) > 0){//foot不在线段上
  45709. var pts = [new Vector2(dis1 / k,height/2),new Vector2(dis2 / k,-height/2)];
  45710. }else {//在线段上的话,要在垂足这加一个节点,因它距离站位最近,而两端较远
  45711. var dis3 = foot.distanceTo(standPos);
  45712. var len = foot.distanceTo(points[0]);
  45713. var pts = [new Vector2(dis1 / k,height/2), new Vector2(dis3 / k,height/2-len), new Vector2(dis2 / k,-height/2)];
  45714. }
  45715. cylinder.geometry && cylinder.geometry.dispose();//若不删除会占用内存
  45716. cylinder.geometry = new LatheBufferGeometry( pts, 4/* Math.min(dis1,dis2)<10?4:3 */ );
  45717. cylinder.renderOrder = 2;
  45718. return cylinder;
  45719. },
  45720. updateBoldLine:function(cylinder, points, type, standPos, constantBold){
  45721. this.createBoldLine(points,{type:type, cylinder : cylinder, standPos:standPos, constantBold}); //type:move:平移 会改长短 , type:update根据距离和角度更新 不改长短
  45722. },
  45723. };
  45724. var MeshDraw = {
  45725. getShape: function(shapes, holes){
  45726. //不一定闭合 暂时所有shapes共享holes。如果要单独的话, shapes改为[{shape:[],holes:[]},{}]的形式
  45727. if(shapes[0] && !(shapes[0] instanceof Array) ){//仅是一个shape的点
  45728. shapes = [shapes];
  45729. }
  45730. let holesArr = [];
  45731. if(holes){//挖空
  45732. holes.forEach((points)=>{
  45733. var holePath = new Path();
  45734. holePath.moveTo( points[0].x, points[0].y );
  45735. for(var i=1,len=points.length; i<len; i++){
  45736. holePath.lineTo(points[i].x, points[i].y );
  45737. }
  45738. holesArr.push( holePath );
  45739. });
  45740. }
  45741. let shapesArr = shapes.map(points=>{
  45742. var shape = new Shape();
  45743. shape.moveTo( points[0].x, points[0].y );
  45744. for(var i=1,len=points.length; i<len; i++){
  45745. shape.lineTo(points[i].x, points[i].y );
  45746. }
  45747. shape.holes.push(...holesArr);
  45748. shape.dontClose = points.dontClose; //add 有的shape不需要闭合
  45749. return shape
  45750. });
  45751. return shapesArr
  45752. },
  45753. /* getShape:function(shapes, holes){
  45754. var shape = new THREE.Shape();
  45755. if(shapes[0] && !(shapes[0] instanceof Array) ){//仅是一个shape的点
  45756. shapes = [shapes]
  45757. }
  45758. shapes.forEach((points)=>{
  45759. shape.moveTo( points[0].x, points[0].y );
  45760. for(var i=1,len=points.length; i<len; i++){
  45761. shape.lineTo(points[i].x, points[i].y )
  45762. }
  45763. })
  45764. //多个points的数组绘制在一个shape中,缺点是这些数组之间可能绘制出来会连在一起。
  45765. if(holes){//挖空
  45766. holes.forEach((points)=>{
  45767. var holePath = new THREE.Path()
  45768. holePath.moveTo( points[0].x, points[0].y )
  45769. for(var i=1,len=points.length; i<len; i++){
  45770. holePath.lineTo(points[i].x, points[i].y )
  45771. }
  45772. shape.holes.push( holePath );
  45773. })
  45774. }
  45775. return shape
  45776. }, */
  45777. getShapeGeo: function(shapes, holes){//获取任意形状(多边形或弧形)的形状面 //quadraticCurveTo() 这是弧形的含函数
  45778. var geometry = new ShapeBufferGeometry( this.getShape(shapes, holes) ); //ShapeGeometry
  45779. /* var matrix = new THREE.Matrix4();//将竖直的面变为水平
  45780. matrix.set(//z = y
  45781. 1, 0, 0, 0,
  45782. 0, 0, 0, 0,
  45783. 0, 1, 0, 0,
  45784. 0, 0, 0, 1
  45785. )
  45786. geometry.applyMatrix(matrix) */
  45787. //geometry.computeVertexNormals();//对于光照需要的是点法线
  45788. return geometry;
  45789. },
  45790. getExtrudeGeo: function(shapes, holes, options={openEnded:false, shapeDontClose:false}){//获得挤出棱柱,可以选择传递height,或者extrudePath
  45791. var shape = this.getShape(shapes, holes); //points是横截面 [vector2,...]
  45792. if(options.extrudePath ){// 路径 :[vector3,...]
  45793. var length = options.extrudePath.reduce((total, currentValue, currentIndex, arr)=>{
  45794. if(currentIndex == 0)return 0
  45795. return total + currentValue.distanceTo(arr[currentIndex-1]);
  45796. },0);
  45797. //options.extrudePath = new THREE.CatmullRomCurve3(options.extrudePath)
  45798. if(options.extrudePath.length == 2){
  45799. options.tension = 0 ;//否则一端扭曲
  45800. options.steps = 1;
  45801. }
  45802. {//去掉重复的点
  45803. let path = [];
  45804. const minDis = options.dontSmooth ? 0 : 0.2; //CatmullRomCurve3 经常扭曲,如果两个点靠得很近可能会扭曲,这里去除靠的太近的点。但去除后依旧会出现一定扭曲.
  45805. options.extrudePath.forEach((p,i)=>{
  45806. if(i==0 || i== options.extrudePath.length-1)return path.push(p) //首尾直接加入
  45807. let last = path[path.length-1];//和上一个比
  45808. let dis = last.distanceTo(p);
  45809. if(dis <= minDis){
  45810. console.log(`第${i}个点(${p.toArray()})因为和上一个数据(${last.toArray()})太接近(dis:${dis})所以删除`);
  45811. }else if(i == options.extrudePath.length - 2){//因为最后一个必定加入,所以倒数第二个还也不能太靠近最后一个
  45812. last = options.extrudePath[options.extrudePath.length-1]; //和下一个(最后一个比)
  45813. if(dis <= minDis){
  45814. console.log(`第${i}个点(${p.toArray()})因为和下一个数据(${last.toArray()})太接近(dis:${dis})所以删除`);
  45815. }else {
  45816. path.push(p);
  45817. }
  45818. }else {
  45819. path.push(p);
  45820. }
  45821. });
  45822. options.extrudePath = path;
  45823. }
  45824. if(options.dontSmooth){
  45825. let curvePath = new CurvePath();//通用的曲线路径对象,它可以包含直线段和曲线段。在这里只做折线
  45826. for (let i = 0; i < options.extrudePath.length - 1; i++){
  45827. let curve3 = new LineCurve3(options.extrudePath[i], options.extrudePath[i + 1]);//添加线段
  45828. curvePath.add(curve3);
  45829. }
  45830. options.extrudePath = curvePath;
  45831. }else {
  45832. //平滑连续的曲线(但经常会有扭曲的问题,tension:0能缓解, 另外shape和path都最好在原点附近,也就是点需减去bound.min )
  45833. options.extrudePath = new CatmullRomCurve3(options.extrudePath, options.closed , 'catmullrom' /* 'centripetal' */ , options.tension);//tension:拐弯剧烈程度,但随着长度增长,该值需要减小,否则会扭曲
  45834. }
  45835. }
  45836. var extrudeSettings = $.extend(options,{
  45837. steps: options.steps != void 0 ? options.steps : ( options.extrudePath ? Math.round(length/(options.spaceDis || 0.3)) : 1), //分成几段 spaceDis每段长度
  45838. bevelEnabled: false, //不加的话,height为0时会有圆弧高度
  45839. //openEnded默认false
  45840. });
  45841. var geometry = new ExtrudeBufferGeometry( shape, extrudeSettings ); //修改了three.js文件, buildLidFaces处,创建顶底面加了选项,可以选择开口。
  45842. return geometry;
  45843. },
  45844. getUnPosPlaneGeo : function(){//获取还没有赋值位置的plane geometry
  45845. var e = new Uint16Array([0, 1, 2, 0, 2, 3])
  45846. // , t = new Float32Array([-.5, -.5, 0, .5, -.5, 0, .5, .5, 0, -.5, .5, 0])
  45847. , i = new Float32Array([0, 0, 1, 0, 1, 1, 0, 1])
  45848. , g = new BufferGeometry;
  45849. g.setIndex(new BufferAttribute(e, 1)),
  45850. //g.addAttribute("position", new n.BufferAttribute(t, 3)),
  45851. g.setAttribute("uv", new BufferAttribute(i, 2));
  45852. return function(){
  45853. return g
  45854. }
  45855. }(),
  45856. getPlaneGeo : function(A,B,C,D){
  45857. var geo = this.getUnPosPlaneGeo().clone();
  45858. var pos = [
  45859. A.x, A.y, A.z,
  45860. B.x, B.y, B.z,
  45861. C.x, C.y, C.z,
  45862. D.x, D.y, D.z
  45863. ];
  45864. //geo.addAttribute("position", new THREE.BufferAttribute(pos, 3))
  45865. geo.setAttribute('position', new Float32BufferAttribute(pos, 3));
  45866. geo.computeVertexNormals();
  45867. geo.computeBoundingSphere(); //for raycaster
  45868. return geo;
  45869. },
  45870. drawPlane : function(A,B,C,D, material){
  45871. var wall = new Mesh(this.getPlaneGeo(A,B,C,D), material);
  45872. return wall;
  45873. },
  45874. movePlane: function(mesh, A,B,C,D){
  45875. var pos = new Float32Array([
  45876. A.x, A.y, A.z,
  45877. B.x, B.y, B.z,
  45878. C.x, C.y, C.z,
  45879. D.x, D.y, D.z
  45880. ]);
  45881. mesh.geometry.addAttribute("position", new BufferAttribute(pos, 3));
  45882. mesh.geometry.computeBoundingSphere();//for checkIntersect
  45883. }
  45884. ,
  45885. createGeometry:function(posArr, faceArr, uvArr, normalArr ){//创建复杂mesh. faceArr:[[0,1,2],[0,2,3]]
  45886. let geo = new BufferGeometry;
  45887. let positions = [];
  45888. posArr.forEach(p=>positions.push(p.x,p.y,p.z));
  45889. geo.setAttribute('position', new Float32BufferAttribute(positions, 3));
  45890. if(faceArr){
  45891. let indice = [];
  45892. faceArr.forEach(f=>indice.push(...f));
  45893. geo.setIndex(indice); // auto set Uint16BufferAttribute or Uint32BufferAttribute
  45894. }
  45895. if(uvArr){
  45896. let uvs = [];
  45897. uvArr.forEach(uv=>uvs.push(uv.x,uv.y));
  45898. geo.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
  45899. }
  45900. if(normalArr){
  45901. let normals = [];
  45902. normalArr.forEach(n=>normals.push(n.x,n.y,n.z));
  45903. geo.setAttribute("normal", new Float32BufferAttribute(normals, 3));
  45904. }
  45905. /*
  45906. geo.computeVertexNormals()
  45907. geo.computeBoundingSphere() //for raycaster
  45908. */
  45909. return geo
  45910. },
  45911. updateGeometry:function(geo, posArr, faceArr, uvArr, normalArr ){//创建复杂mesh. faceArr:[[0,1,2],[0,2,3]]
  45912. let positions = [];
  45913. posArr.forEach(p=>positions.push(p.x,p.y,p.z));
  45914. geo.setAttribute('position', new Float32BufferAttribute(positions, 3));
  45915. geo.attributes.position.needsUpdate = true;
  45916. if(faceArr){
  45917. let indice = [];
  45918. faceArr.forEach(f=>indice.push(...f));
  45919. geo.setIndex(indice); // auto set Uint16BufferAttribute or Uint32BufferAttribute
  45920. }
  45921. if(uvArr){
  45922. let uvs = [];
  45923. uvArr.forEach(uv=>uvs.push(uv.x,uv.y));
  45924. geo.setAttribute("uv", new Float32BufferAttribute(uvs, 2));
  45925. }
  45926. if(normalArr){
  45927. let normals = [];
  45928. normalArr.forEach(n=>normals.push(n.x,n.y,n.z));
  45929. geo.setAttribute("normal", new Float32BufferAttribute(normals, 3));
  45930. }
  45931. /*
  45932. geo.computeVertexNormals()
  45933. */
  45934. geo.computeBoundingSphere(); //for raycaster and visi
  45935. return geo
  45936. }
  45937. };
  45938. class DepthBasicMaterial extends ShaderMaterial{
  45939. constructor(o={}){
  45940. let {width, height} = viewer.renderer.getSize(new Vector2());
  45941. let uniforms = {
  45942. resolution: { type: 'v2', value: new Vector2(width, height ) },
  45943. viewportOffset: { type: 'v2', value: new Vector2(0, 0 ) }, //left, top
  45944. //uUseOrthographicCamera:{ type: "b", value: false },
  45945. nearPlane: { type: 'f', value: 0.1 },
  45946. farPlane: { type: 'f', value: 10000 },
  45947. depthTexture: { type: 't', value: null },
  45948. opacity: { type: 'f', value: 1 },
  45949. map: { type: 't', value: o.map },
  45950. baseColor: {type:'v3', value: o.color ? new Color(o.color) : new Color("#ffffff")},
  45951. backColor: {type:'v3', value: o.backColor ? new Color(o.backColor) : new Color("#ddd")},
  45952. clipDistance : { type: 'f', value: o.clipDistance || 4 }, //消失距离
  45953. occlusionDistance : { type: 'f', value: o.occlusionDistance || 1 }, //变为backColor距离
  45954. maxClipFactor : { type: 'f', value: o.maxClipFactor || 1 }, //0-1
  45955. maxOcclusionFactor : { type: 'f', value: o.maxOcclusionFactor || 1 }, //0-1
  45956. mapScale: { type: 'f', value: o.mapScale || 1 }, //0-1
  45957. };
  45958. let {vs,fs} = Common.changeShaderToWebgl2(Shaders['depthBasic.vs'], Shaders['depthBasic.fs'], 'ShaderMaterial');
  45959. super({
  45960. uniforms,
  45961. vertexShader: vs,
  45962. fragmentShader: fs,
  45963. depthWrite: false,
  45964. depthTest: false,
  45965. transparent: o.transparent == void 0 ? true : o.transparent,
  45966. side: o.side || 0 /* THREE.DoubleSide */,
  45967. });
  45968. this.events = {
  45969. setSize:(e)=>{//如果出现横条状的异常,往往是viewportOffset出错 //地图不需要
  45970. if(!this.realUseDepth || !e.viewport)return
  45971. let viewport = e.viewport;
  45972. let viewportOffset = viewport.offset || new Vector2();
  45973. this.uniforms.resolution.value.copy(viewport.resolution2); //2023.6.12突然发现ratio>1的用resolution不对,得用2才对。但是之前明明记得不是这样
  45974. this.uniforms.viewportOffset.value.copy(viewportOffset);
  45975. },
  45976. render:(e)=>{//before render 如果有大于两个viewport的话,不同viewport用不同的depthTex
  45977. this.updateDepthParams(e);
  45978. },
  45979. /* cameraChange:(e)=>{
  45980. if(e.changeInfo.projectionChanged){//resize时也会触发。虽然保守起见的话加上resize比较好//所以当时为何不用resize
  45981. //console.log('projectionChanged')
  45982. this.events.setSize(e)
  45983. }
  45984. } */
  45985. };
  45986. //-----其他----
  45987. this.autoDepthTest = o.autoDepthTest;
  45988. if(o.opacity != void 0){
  45989. this.opacity = o.opacity;
  45990. }
  45991. this.useDepth = o.useDepth;
  45992. this.map = o.map;
  45993. }
  45994. get useDepth(){
  45995. return this.useDepth_
  45996. }
  45997. set useDepth(value){
  45998. value = value && Features.EXT_DEPTH.isSupported(); //如果不支持 EXT_DEPTH 的话会失效
  45999. if(this.useDepth_ != value){
  46000. this.setRealDepth(value);
  46001. this.useDepth_ = value;
  46002. if(value){
  46003. viewer.addEventListener("render.begin", this.events.render);
  46004. //viewer.addEventListener('camera_changed', this.events.cameraChange)
  46005. viewer.addEventListener('resize', this.events.setSize);
  46006. this.updateDepthParams();
  46007. }else {
  46008. viewer.removeEventListener("render.begin", this.events.render);
  46009. viewer.removeEventListener('resize', this.events.setSize);
  46010. }
  46011. }
  46012. }
  46013. setRealDepth(useDepth, viewport){//确实使用到depthTex
  46014. if(this.realUseDepth != useDepth){
  46015. if(useDepth ){
  46016. this.defines.useDepth = '';
  46017. }else {
  46018. delete this.defines.useDepth;
  46019. }
  46020. this.realUseDepth = useDepth;
  46021. if(this.autoDepthTest)this.depthWrite = this.depthTest = !useDepth; //如果useDepth = false,使用原始的depthTest
  46022. this.needsUpdate = true;
  46023. if(!viewport)viewport = viewer.mainViewport; //暂时这么设置
  46024. useDepth && this.events.setSize({viewport});
  46025. }
  46026. }
  46027. get map(){
  46028. return this.uniforms.map.value
  46029. }
  46030. set map(map){
  46031. this.uniforms.map.value = map;
  46032. if(map){
  46033. this.defines.use_map = '';
  46034. }else {
  46035. delete this.defines.use_map;
  46036. }
  46037. }
  46038. get opacity(){
  46039. return this.uniforms.opacity.value
  46040. }
  46041. set opacity(o){
  46042. this.uniforms && (this.uniforms.opacity.value = o);
  46043. }
  46044. get color(){
  46045. return this.uniforms.baseColor.value
  46046. }
  46047. set color(c){
  46048. this.uniforms && (this.uniforms.baseColor.value.set(c));
  46049. }
  46050. /* dispose(){
  46051. super.dispose()
  46052. viewer.depthBasic
  46053. } */
  46054. copy(source){
  46055. super.copy(source);
  46056. this.useDepth = source.useDepth;
  46057. this.map = source.map;
  46058. return this
  46059. }
  46060. updateDepthParams(e={}){//主要用于点云遮住mesh
  46061. var viewport = e.viewport || viewer.mainViewport;
  46062. var camera = viewport.camera;
  46063. let hasDepth = this.useDepth && camera.isPerspectiveCamera &&
  46064. (Potree.settings.pointEnableRT || Potree.settings.displayMode == 'showPanos' || viewer.useEDL);
  46065. this.setRealDepth(hasDepth, viewport);
  46066. if(hasDepth){
  46067. this.uniforms.depthTexture.value = viewer.getPRenderer().getRtEDL(viewport).depthTexture; //其实只赋值一次就行
  46068. this.uniforms.nearPlane.value = camera.near;
  46069. this.uniforms.farPlane.value = camera.far;
  46070. }
  46071. //this.uniforms.uUseOrthographicCamera.value = !camera.isPerspectiveCamera
  46072. }
  46073. }
  46074. const geo = new PlaneBufferGeometry(1,1);
  46075. class Sprite$2 extends Mesh{
  46076. constructor(options={}){
  46077. super(geo, options.mat || new DepthBasicMaterial(options));/* ({map:options.map, useDepth:options.useDepth})) */
  46078. this.root = options.root || this;
  46079. this.renderOrder = options.renderOrder != void 0 ? options.renderOrder : 4;
  46080. this.pickOrder = options.pickOrder || 0;
  46081. this.sizeInfo = options.sizeInfo;
  46082. this.dontFixOrient = options.dontFixOrient;
  46083. this.options = options;
  46084. this.position.y = options.disToLine || 0; //离线距离
  46085. this.matrixAutoUpdate = false;
  46086. this.matrixMap = new Map();
  46087. if(this.root != this){
  46088. this.matrixMapRoot = new Map();
  46089. this.root.matrixAutoUpdate = false;
  46090. }
  46091. this.visiMap = new Map();
  46092. this.name = options.name || 'sprite';
  46093. this.useViewport = null;
  46094. this.viewports = options.viewports;//指定更新的viewports
  46095. this.visible_ = true;
  46096. let clear = (e)=>{
  46097. this.matrixMap.clear();//清空后在所有viewport上都必须更新才能渲染 //this.needsUpdate = true
  46098. };
  46099. viewer.mapViewer && viewer.mapViewer.addEventListener("camera_changed", clear);
  46100. viewer.addEventListener("camera_changed", clear);
  46101. /* if(viewer.viewports.length == 1){//直接更新。如果有多个不在这更新,在"render.begin"
  46102. this.update(e)
  46103. } */
  46104. let applyMatrix = (e)=>{
  46105. this.applyMatrix(e);
  46106. };
  46107. viewer.addEventListener("raycaster", applyMatrix); //before render
  46108. viewer.addEventListener("render.begin", applyMatrix); //before render
  46109. viewer.addEventListener("render.begin2", applyMatrix);
  46110. viewer.addEventListener("cameraSetLayers", applyMatrix);
  46111. this.addEventListener('dispose', ()=>{
  46112. viewer.mapViewer && viewer.mapViewer.removeEventListener("camera_changed", clear);
  46113. viewer.removeEventListener("camera_changed", clear);
  46114. viewer.removeEventListener("raycaster", applyMatrix); //before render
  46115. viewer.removeEventListener("render.begin", applyMatrix);
  46116. viewer.removeEventListener("render.begin2", applyMatrix);
  46117. });
  46118. }
  46119. set visible(v){
  46120. let oldV = this.visible_;
  46121. this.visible_ = v;
  46122. if(v && !oldV){
  46123. this.matrixMap && this.matrixMap.clear(); //this.update() //update内有unableCompute会无限回调
  46124. }
  46125. }
  46126. get visible(){
  46127. return this.visible_
  46128. }
  46129. realVisible(viewport, interactables/* , raycaster */){
  46130. if(interactables){
  46131. if(!interactables.some((object)=>{//interactables中是否能找到this
  46132. let finded;
  46133. object.traverse((object)=>{
  46134. if(object == this){
  46135. finded = true;
  46136. return {stopContinue:true}
  46137. }
  46138. });
  46139. return finded
  46140. }))return
  46141. }
  46142. /* if(interactables && viewport.name == 'mapViewport'){
  46143. console.log(this)
  46144. } */
  46145. if(!(/* raycaster || */viewport.camera).layers.test(this.layers)){//如地图上一般不可见测量线
  46146. return false
  46147. }
  46148. if(!this.visible && this.unvisibleReasons && this.unvisibleReasons.some(e=>e.reason != 'unableCompute')){
  46149. return false
  46150. }
  46151. let v = true;
  46152. let parent = this.parent;
  46153. let lastParent = this;
  46154. while(parent){
  46155. if(parent.visible === false){
  46156. v = false;
  46157. break;
  46158. }
  46159. lastParent = parent;
  46160. parent = parent.parent;
  46161. }
  46162. if(v && !(lastParent instanceof Scene)){//已被删除
  46163. v = false;
  46164. }
  46165. /* if(!this.latestRealVisi && v){//变为可见后先update
  46166. this.latestRealVisi = true
  46167. setTimeout(()=>{
  46168. this.update()
  46169. },1)//延迟 防止无限调用
  46170. return false
  46171. }
  46172. this.latestRealVisi = v */
  46173. return v;
  46174. }
  46175. waitUpdate(){
  46176. this.matrixMap.clear();//清空后在所有viewport上都必须更新才能渲染
  46177. //viewer.dispatchEvent('content_changed')
  46178. }
  46179. update(e={}){
  46180. if(!e.viewport){
  46181. let viewports = this.viewports || viewer.viewports;
  46182. if(!viewports)return
  46183. viewports.forEach(view=>{
  46184. this.update({viewport:view});
  46185. });
  46186. return;
  46187. }
  46188. if(!this.root || ! this.realVisible(e.viewport, e.interactables) /* this.visible */ )return
  46189. if(this.viewports && !this.viewports.includes(e.viewport) )return
  46190. if(e.viewport.name == 'magnifier')return
  46191. let camera = e.viewport.camera;
  46192. //rotation
  46193. if(!this.dontFixOrient){ //orthoCamera一般要加dontFixOrient
  46194. let orient2dAngle;
  46195. if(this.root.lineDir){
  46196. this.root.updateMatrix();//先更新,getWorldPosition才能得到正确的
  46197. this.root.updateMatrixWorld(true);
  46198. let center = this.root.getWorldPosition(new Vector3());
  46199. //由于两个端点容易在屏幕外,所以使用center和center加dir
  46200. let setVisi = (state)=>{
  46201. this.visiMap.set(e.viewport, state);
  46202. Potree.Utils.updateVisible(this, 'unableCompute', !!state);
  46203. };
  46204. let renderer = e.viewer ? e.viewer.renderer : e.renderer;
  46205. let r1 = Potree.Utils.getPos2d(center, e.viewport, renderer.domElement.parentElement, renderer);
  46206. //let r1 = Potree.Utils.getPos2d(center, e.viewport, viewer.renderArea, viewer.renderer);
  46207. if(!r1.trueSide)return setVisi(false);// 但这句会使realVisible为false从而无法更新//console.error('!r1.trueSide') //中心点如果在背面直接不渲染了
  46208. let r2, point2;
  46209. let p2State = '', len=1, p2StateHistory = [];
  46210. while(p2State != 'got' && p2StateHistory.length<10){
  46211. point2 = center.clone().add(this.root.lineDir.clone().multiplyScalar(len));
  46212. r2 = Potree.Utils.getPos2d(point2, e.viewport , renderer.domElement.parentElement, renderer );
  46213. if(!r2.trueSide){ //很少遇到点2在背面的
  46214. if(!p2StateHistory.includes('tooLong-reverse')){
  46215. p2State = 'tooLong-reverse'; //先尝试反向
  46216. len = -len;
  46217. }else {
  46218. p2State = 'tooLong';
  46219. len = len / 2;
  46220. }
  46221. }else {
  46222. let dis = r2.pos.distanceTo(r1.pos);
  46223. if(math.closeTo(dis,0)){
  46224. //console.log('dis == 0')
  46225. setVisi(false);
  46226. return
  46227. break
  46228. }
  46229. if(dis<10 && !p2StateHistory.includes('tooLong')){//和r1的屏幕距离太近,要加长,否则精度过低
  46230. p2State = 'tooShort';
  46231. len = 100/dis * len;
  46232. }else {
  46233. p2State = 'got'; break;
  46234. }
  46235. }
  46236. p2StateHistory.push(p2State);
  46237. }
  46238. //console.log(p2StateHistory,len)
  46239. if(!r2.trueSide){
  46240. return setVisi(false)//, console.log(' !r2.trueSide', )
  46241. }
  46242. let p1 = r1.pos, p2 = r2.pos;
  46243. if(p2StateHistory.filter(e=>e == 'tooLong-reverse').length%2 == 1){//反,for marker
  46244. p2 = r1.pos, p1 = r2.pos;
  46245. }
  46246. let vec = new Vector2().subVectors(p1,p2);
  46247. orient2dAngle = -vec.angle(); //根据测量线在屏幕上的角度在旋转label,使之和屏幕上的二维线平行。
  46248. let y = Math.abs(this.position.y);
  46249. let facePlane = this.root.measure && this.root.measure.facePlane;
  46250. let eyeDir = new Vector3().subVectors(center,camera.position);
  46251. let clockWise = facePlane && facePlane.normal.dot(eyeDir/* e.viewport.view.direction */) < 0;
  46252. if(p1.x < p2.x){
  46253. orient2dAngle += Math.PI; //避免字是倒着的情况。(使字一直在线的下方)
  46254. clockWise != void 0 && (this.position.y = clockWise ? y : -y);
  46255. }else {
  46256. clockWise != void 0 && (this.position.y = clockWise ? -y : y); //使area类型的edgeLabel都在外侧
  46257. }
  46258. //this.parent.text && console.log(this.parent.text, clockWise, this.position.y, e.viewport.name /* THREE.Math.radToDeg(angle), p1.x < p2.x */ )
  46259. setVisi(true);
  46260. }
  46261. let parentQua = this.root.parent.getWorldQuaternion(new Quaternion);
  46262. this.root.quaternion.multiplyQuaternions(parentQua.invert(),camera.quaternion); //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
  46263. if(orient2dAngle){
  46264. let qua = new Quaternion().setFromAxisAngle(new Vector3(0,0,1), orient2dAngle);
  46265. this.root.quaternion.multiply(qua);
  46266. }
  46267. }
  46268. //scale
  46269. var info = this.sizeInfo;
  46270. if(info){
  46271. this.root.updateMatrix();//先更新,getWorldPosition才能得到正确的
  46272. this.root.updateMatrixWorld(true);
  46273. var scale;
  46274. if(info.nearBound == void 0 && info.farBound != void 0 || info.nearBound != void 0 && info.farBound == void 0){//仅限制最大或最小的话,不判断像素大小,直接限制mesh的scale
  46275. //这个判断也可以写到getScaleForConstantSize里,可以更严谨控制像素宽度,这里只简单计算大小
  46276. var dis = camera.position.distanceTo(this.root.getWorldPosition(new Vector3()));
  46277. if(info.farBound == void 0 && dis < info.nearBound){
  46278. scale = info.scale * dis / info.nearBound;
  46279. }else if(info.nearBound == void 0 && dis > info.farBound){
  46280. scale = info.scale * dis / info.farBound;
  46281. }else {
  46282. scale = info.scale;
  46283. }
  46284. }else {
  46285. scale = math.getScaleForConstantSize($.extend(info,{//规定下最小最大像素
  46286. camera , position:this.root.getWorldPosition(new Vector3()) ,
  46287. resolution: e.viewport.resolution//2
  46288. }));
  46289. }
  46290. if(!isNaN(scale)){
  46291. this.root.scale.set(scale, scale, scale);
  46292. }
  46293. }
  46294. this.updateMatrix();
  46295. //this.root.updateMatrixWorld(true)
  46296. //console.log(this.root.text, this.root.matrix.elements)
  46297. this.matrixMap.set(e.viewport, this.matrix.clone());
  46298. if(this.root != this){
  46299. this.root.updateMatrix(); //因this.position可能在两个viewport不同
  46300. this.matrixMapRoot.set(e.viewport, this.root.matrix.clone());
  46301. }
  46302. this.needsUpdate = false;
  46303. this.useViewport = e.viewport;
  46304. }
  46305. applyMatrix(e){
  46306. if(!e)e = {viewport:viewer.mainViewport};//随便写一个viewport
  46307. let visi = this.visiMap.get(e.viewport); //还原可见性
  46308. Potree.Utils.updateVisible(this, 'unableCompute', visi == false ? false : true );
  46309. /* if(e.viewport.name == 'mapViewport' && visi && this.visiMap.get(viewer.mainViewport) == false){
  46310. console.log(1)
  46311. } */
  46312. if(e.viewport.name == 'magnifier')return
  46313. if(this.viewports && !this.viewports.includes(e.viewport) )return
  46314. if( !this.root || !this.realVisible(e.viewport, e.interactables) )return
  46315. var matrix = this.matrixMap.get(e.viewport);
  46316. if(!matrix){
  46317. this.update(e);
  46318. matrix = this.matrixMap.get(e.viewport);
  46319. if(!matrix)return
  46320. }
  46321. if(e.viewport == this.useViewport){
  46322. return
  46323. }
  46324. this.useViewport = e.viewport;
  46325. this.matrix.copy(matrix);
  46326. if(this.root != this){
  46327. var matrix2 = this.matrixMapRoot.get(e.viewport);
  46328. this.root.matrix.copy(matrix2);
  46329. }
  46330. e.raycaster && this.root.updateMatrixWorld(true);//渲染前会自动updateMatrixWorld,但raycaster不会
  46331. //console.log(this.root.name + e.viewport.name + " : "+this.root.matrixWorld.elements)
  46332. }
  46333. setUniforms(name,value){
  46334. this.material.setUniforms(name,value);
  46335. }
  46336. dispose(){
  46337. this.removeAllListeners();
  46338. this.parent && this.parent.remove(this);
  46339. this.dispatchEvent('dispose');
  46340. }
  46341. }
  46342. /*
  46343. let orient2d
  46344. if(this.lineDir){
  46345. this.root.updateMatrix();//先更新,getWorldPosition才能得到正确的
  46346. this.root.updateMatrixWorld(true)
  46347. let center = this.root.getWorldPosition(new THREE.Vector3())
  46348. //由于两个端点容易在屏幕外,所以使用center和center加dir
  46349. let lineDir = this.lineDir.clone();
  46350. let r1 = Potree.Utils.getPos2d(center, camera, viewer.renderArea, e.viewport);
  46351. if(!r1.trueSide)return Potree.Utils.updateVisible(this, 'unableCompute', false);// 但这句会使realVisible为false从而无法更新//console.error('!r1.trueSide') //中心点如果在背面直接不渲染了
  46352. let r2, point2
  46353. let p2State = '', len=1, p2StateHistory = []
  46354. while(p2State != 'got' && p2StateHistory.length<10){
  46355. point2 = center.clone().add(lineDir.multiplyScalar(len));
  46356. r2 = Potree.Utils.getPos2d(point2, camera, viewer.renderArea, e.viewport);
  46357. if(!r2.trueSide){ //很少遇到点2在背面的
  46358. if(!p2StateHistory.includes('tooLong-reverse')){
  46359. p2State = 'tooLong-reverse' //先尝试反向
  46360. len = -len
  46361. }else{
  46362. p2State = 'tooLong'
  46363. len = len / 2
  46364. }
  46365. }else{
  46366. let dis = r2.pos.distanceTo(r1.pos)
  46367. if(dis == 0){
  46368. //console.log('dis == 0')
  46369. Potree.Utils.updateVisible(this, 'unableCompute', false)
  46370. return
  46371. break
  46372. }
  46373. if(dis<10 && !p2StateHistory.includes('tooLong')){//和r1的屏幕距离太近,要加长,否则精度过低
  46374. p2State = 'tooShort'
  46375. len = 100/dis * len
  46376. }else{
  46377. p2State = 'got'; break;
  46378. }
  46379. }
  46380. p2StateHistory.push(p2State)
  46381. }
  46382. //console.log(p2StateHistory,len)
  46383. if(!r2.trueSide){
  46384. return Potree.Utils.updateVisible(this, 'unableCompute', false)//, console.log(' !r2.trueSide', )
  46385. }
  46386. Potree.Utils.updateVisible(this, 'unableCompute', true)
  46387. let p1 = r1.pos, p2 = r2.pos
  46388. let vec = new THREE.Vector2().subVectors(p1,p2);
  46389. let angle = -vec.angle() //根据测量线在屏幕上的角度在旋转label,使之和屏幕上的二维线平行。
  46390. if(p1.x < p2.x) angle += Math.PI //避免字是倒着的情况
  46391. orient2d = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), angle)
  46392. //console.log(this.parent.text, THREE.Math.radToDeg(angle), p1.x < p2.x )
  46393. }
  46394. let parentQua = this.root.parent.getWorldQuaternion(new THREE.Quaternion)
  46395. this.root.quaternion.multiplyQuaternions(parentQua.invert(),camera.quaternion) //乘上parentQua.invert()是为了中和掉父结点的qua,使只剩下camera.quaternion
  46396. if(this.lineDir){
  46397. this.root.quaternion.multiply(orient2d)
  46398. }
  46399. */
  46400. //可能还是要用html写,因为要加按钮和图片
  46401. class TextSprite$2 extends Object3D{
  46402. //注:为了分两层控制scale,不直接extend Sprite
  46403. constructor( options={}){
  46404. super();
  46405. let map = new Texture();
  46406. map.minFilter = LinearFilter;
  46407. map.magFilter = LinearFilter;
  46408. this.sprite = new Sprite$2( Object.assign({
  46409. root:this
  46410. }
  46411. ,options,
  46412. {
  46413. map,
  46414. })
  46415. );
  46416. this.add(this.sprite);
  46417. this.fontWeight = options.fontWeight == void 0 ? 'Bold' : options.fontWeight;
  46418. this.rectBorderThick = options.rectBorderThick || 0;
  46419. this.textBorderThick = options.textBorderThick || 0;
  46420. this.fontface = 'Arial';
  46421. this.fontsize = options.fontsize || 16;
  46422. this.textBorderColor = options.textBorderColor ? Common.CloneObject(options.textBorderColor):{ r: 0, g: 0, b: 0, a: 0.0 };
  46423. this.backgroundColor = options.backgroundColor ? Common.CloneObject(options.backgroundColor):{ r: 255, g: 255, b: 255, a: 1.0 };
  46424. this.textColor = options.textColor ? Common.CloneObject(options.textColor):{r: 0, g: 0, b: 0, a: 1.0};
  46425. this.borderColor = options.borderColor ? Common.CloneObject(options.borderColor):{ r: 0, g: 0, b: 0, a: 0.0 };
  46426. this.borderRadius = options.borderRadius || 6;
  46427. this.margin = options.margin;
  46428. this.setText(options.text);
  46429. this.name = options.name;
  46430. //this.setText(text);
  46431. }
  46432. setText(text){
  46433. if(text == void 0)text = '';
  46434. if (this.text !== text) {
  46435. if (!(text instanceof Array)) {
  46436. this.text = [text + ''];
  46437. } else this.text = text;
  46438. this.updateTexture();
  46439. this.sprite.waitUpdate(); //重新计算各个viewport的matrix
  46440. }
  46441. }
  46442. setTextColor(color){
  46443. this.textColor = Common.CloneObject(color);
  46444. this.updateTexture();
  46445. }
  46446. setBorderColor(color){
  46447. this.borderColor = Common.CloneObject(color);
  46448. this.updateTexture();
  46449. }
  46450. setBackgroundColor(color){
  46451. this.backgroundColor = Common.CloneObject(color);
  46452. this.updateTexture();
  46453. }
  46454. setPos(pos){
  46455. this.position.copy(pos);
  46456. this.sprite.waitUpdate();
  46457. }
  46458. update(){
  46459. this.sprite.waitUpdate();
  46460. }
  46461. /* setVisible(v){
  46462. Potree.Utils.updateVisible(this, 'setVisible', v)
  46463. } */
  46464. setUniforms(name,value){
  46465. this.sprite.setUniforms(name,value);
  46466. }
  46467. updateTexture1(){
  46468. let canvas = document.createElement('canvas');
  46469. let context = canvas.getContext('2d');
  46470. const r = window.devicePixelRatio;
  46471. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  46472. //context["font-weight"] = 100; //语法与 CSS font 属性相同。
  46473. //this.text = '啊啊啊啊啊啊fag'
  46474. let metrics = context.measureText(this.text );
  46475. let textWidth = metrics.width;
  46476. let margin = (this.margin ? new Vector2().copy(this.margin) : new Vector2(this.fontsize, Math.max( this.fontsize*0.4, 10) )).clone().multiplyScalar(r);
  46477. let spriteWidth = 2 * margin.x + textWidth + 2 * this.rectBorderThick * r ;
  46478. let spriteHeight = 2 * margin.y + this.fontsize * r + 2 * this.rectBorderThick * r;
  46479. context.canvas.width = spriteWidth;
  46480. context.canvas.height = spriteHeight;
  46481. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  46482. /* let diff = 2//针对英文大部分在baseLine之上所以降低一点(metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2
  46483. context.textBaseline = "middle"
  46484. */
  46485. let expand = Math.max(1, Math.pow(this.fontsize / 16, 1.3)) * r; // 针对英文大部分在baseLine之上所以降低一点,或者可以识别当不包含jgqp时才加这个值
  46486. //canvas原点在左上角
  46487. context.textBaseline = 'alphabetic'; // "middle" //设置文字基线。当起点y设置为0时,只有该线以下的部分被绘制出来。middle时文字显示一半(但是对该字体所有字的一半,有的字是不一定显示一半的,尤其汉字),alphabetic时是英文字母的那条基线。
  46488. //let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent; // 当前文本字符串在这个字体下用的实际高度
  46489. //文字y向距离从textBaseline向上算
  46490. let actualBoundingBoxAscent = metrics.actualBoundingBoxAscent == void 0 ? this.fontsize * r * 0.8 : metrics.actualBoundingBoxAscent; //有的流览器没有。只能大概给一个
  46491. let y = actualBoundingBoxAscent + margin.y + expand;
  46492. //console.log(this.text, 'y' , y, 'actualBoundingBoxAscent', metrics.actualBoundingBoxAscent,'expand',expand )
  46493. // border color
  46494. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' +
  46495. this.borderColor.b + ',' + this.borderColor.a + ')';
  46496. let rectBorderThick = this.rectBorderThick * r;
  46497. context.lineWidth = rectBorderThick;
  46498. // background color
  46499. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' +
  46500. this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
  46501. this.roundRect(context, rectBorderThick / 2 , rectBorderThick / 2,
  46502. spriteWidth - rectBorderThick, spriteHeight - rectBorderThick, this.borderRadius * r);
  46503. // text color
  46504. if(this.textBorderThick){
  46505. context.strokeStyle = 'rgba(' + this.textBorderColor.r + ',' + this.textBorderColor.g + ',' +
  46506. this.textBorderColor.b + ',' + this.textBorderColor.a + ')';
  46507. context.lineWidth = this.textBorderThick * r;
  46508. context.strokeText(this.text , rectBorderThick + margin.x, y /* spriteHeight/2 + diff */ );
  46509. }
  46510. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' +
  46511. this.textColor.b + ',' + this.textColor.a + ')';
  46512. context.fillText(this.text , rectBorderThick + margin.x, y/* spriteHeight/2 + diff */ );//x,y
  46513. let texture = new Texture(canvas);
  46514. texture.minFilter = LinearFilter;
  46515. texture.magFilter = LinearFilter;
  46516. texture.needsUpdate = true;
  46517. //this.material.needsUpdate = true;
  46518. if(this.sprite.material.map){
  46519. this.sprite.material.map.dispose();
  46520. }
  46521. this.sprite.material.map = texture;
  46522. this.sprite.scale.set(spriteWidth * 0.01 / r, spriteHeight * 0.01 / r, 1.0);
  46523. }
  46524. updateTexture(){
  46525. let canvas = document.createElement('canvas');
  46526. let context = canvas.getContext('2d');
  46527. const r = window.devicePixelRatio;
  46528. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  46529. //context["font-weight"] = 100; //语法与 CSS font 属性相同。
  46530. //this.text = '啊啊啊啊啊啊fag'
  46531. let textMaxWidth = 0,
  46532. infos = [];
  46533. for (let text of this.text) {
  46534. let metrics = context.measureText(text);
  46535. let textWidth = metrics.width;
  46536. infos.push(metrics);
  46537. textMaxWidth = Math.max(textMaxWidth, textWidth);
  46538. }
  46539. let margin = (this.margin ? new Vector2().copy(this.margin) : new Vector2(this.fontsize, Math.max( this.fontsize*0.4, 10) )).clone().multiplyScalar(r);
  46540. const lineSpace = (this.fontsize + margin.y) * 0.5;
  46541. let spriteWidth = 2 * margin.x + textMaxWidth + 2 * (this.rectBorderThick + this.textBorderThick)* r; //还要考虑this.textshadowColor,太麻烦了不写了
  46542. let spriteHeight = 2 * margin.y + (this.fontsize + this.textBorderThick*2)* r * this.text.length + 2 * this.rectBorderThick * r + lineSpace * (this.text.length - 1);
  46543. context.canvas.width = spriteWidth;
  46544. context.canvas.height = spriteHeight;
  46545. context.font = this.fontWeight + ' ' + this.fontsize * r + 'px ' + this.fontface;
  46546. if(spriteWidth>4000){
  46547. console.error('spriteWidth',spriteWidth,'spriteHeight',spriteHeight,this.fontsize,r,this.text,margin);
  46548. }
  46549. /* let diff = 2//针对英文大部分在baseLine之上所以降低一点(metrics.fontBoundingBoxAscent - metrics.fontBoundingBoxDescent) / 2
  46550. context.textBaseline = "middle"
  46551. */
  46552. let expand = Math.max(1, Math.pow(this.fontsize / 16, 1.3)) * r; // 针对英文大部分在baseLine之上所以降低一点,或者可以识别当不包含jgqp时才加这个值
  46553. //canvas原点在左上角
  46554. context.textBaseline = 'alphabetic'; // "middle" //设置文字基线。当起点y设置为0时,只有该线以下的部分被绘制出来。middle时文字显示一半(但是对该字体所有字的一半,有的字是不一定显示一半的,尤其汉字),alphabetic时是英文字母的那条基线。
  46555. // border color
  46556. context.strokeStyle = 'rgba(' + this.borderColor.r + ',' + this.borderColor.g + ',' + this.borderColor.b + ',' + this.borderColor.a + ')';
  46557. let rectBorderThick = this.rectBorderThick * r;
  46558. context.lineWidth = rectBorderThick;
  46559. // background color
  46560. context.fillStyle = 'rgba(' + this.backgroundColor.r + ',' + this.backgroundColor.g + ',' + this.backgroundColor.b + ',' + this.backgroundColor.a + ')';
  46561. this.roundRect(context, rectBorderThick / 2 , rectBorderThick / 2, spriteWidth - rectBorderThick, spriteHeight - rectBorderThick, this.borderRadius * r);
  46562. context.fillStyle = 'rgba(' + this.textColor.r + ',' + this.textColor.g + ',' + this.textColor.b + ',' + this.textColor.a + ')';
  46563. let y = margin.y;
  46564. for (let i = 0; i < this.text.length; i++) {
  46565. //let actualHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent // 当前文本字符串在这个字体下用的实际高度
  46566. //文字y向距离从textBaseline向上算
  46567. let actualBoundingBoxAscent = infos[i].actualBoundingBoxAscent == void 0 ? this.fontsize * r * 0.8 : infos[i].actualBoundingBoxAscent; //有的流览器没有。只能大概给一个
  46568. y += actualBoundingBoxAscent + expand + this.textBorderThick;
  46569. //console.log(actualBoundingBoxAscent)
  46570. //console.log(this.text, 'y' , y, 'actualBoundingBoxAscent', metrics.actualBoundingBoxAscent,'expand',expand )
  46571. let textLeftSpace = (textMaxWidth - infos[i].width) / 2;
  46572. let x = this.rectBorderThick + margin.x + textLeftSpace;
  46573. // text color
  46574. if (this.textBorderThick) {
  46575. context.strokeStyle = 'rgba(' + this.textBorderColor.r + ',' + this.textBorderColor.g + ',' + this.textBorderColor.b + ',' + this.textBorderColor.a + ')';
  46576. context.lineWidth = this.textBorderThick * r;
  46577. context.strokeText(this.text[i], x, y);
  46578. }
  46579. if (this.textshadowColor) {
  46580. context.shadowOffsetX = 0;
  46581. context.shadowOffsetY = 0;
  46582. context.shadowColor = this.textshadowColor;
  46583. context.shadowBlur = 12 * r;
  46584. }
  46585. context.fillText(this.text[i], x, y);
  46586. y += lineSpace;
  46587. }
  46588. let texture = new Texture(canvas);
  46589. texture.minFilter = LinearFilter;
  46590. texture.magFilter = LinearFilter;
  46591. texture.needsUpdate = true;
  46592. //this.material.needsUpdate = true;
  46593. if(this.sprite.material.map){
  46594. this.sprite.material.map.dispose();
  46595. }
  46596. this.sprite.material.map = texture;
  46597. this.sprite.scale.set(spriteWidth * 0.01 / r, spriteHeight * 0.01 / r, 1.0);
  46598. }
  46599. roundRect(ctx, x, y, w, h, r){
  46600. ctx.beginPath();
  46601. ctx.moveTo(x + r, y);
  46602. ctx.lineTo(x + w - r, y);
  46603. ctx.arcTo(x + w, y, x + w, y + r, r );//圆弧。前四个参数同quadraticCurveTo
  46604. //ctx.quadraticCurveTo(x + w, y, x + w, y + r); //二次贝塞尔曲线需要两个点。第一个点是用于二次贝塞尔计算中的控制点,第二个点是曲线的结束点。
  46605. ctx.lineTo(x + w, y + h - r);
  46606. ctx.arcTo(x + w, y + h, x + w - r, y + h, r );
  46607. ctx.lineTo(x + r, y + h);
  46608. ctx.arcTo(x, y + h, x, y + h - r, r );
  46609. ctx.lineTo(x, y + r);
  46610. ctx.arcTo(x, y, x + r, y, r );
  46611. ctx.closePath();
  46612. ctx.fill();
  46613. ctx.stroke();
  46614. }
  46615. dispose(){
  46616. this.sprite.material.uniforms.map.value.dispose();
  46617. this.parent && this.parent.remove(this);
  46618. this.sprite.dispose();
  46619. this.removeAllListeners();
  46620. this.dispatchEvent('dispose');
  46621. }
  46622. }
  46623. /*
  46624. z
  46625. |
  46626. |
  46627. |
  46628. |
  46629. x <-------| 中心为点云position加boudingbox中心
  46630. /
  46631. /
  46632. y
  46633. */
  46634. var lineLen$1 = 2, stemLen = 4, arrowLen = 2, lineDisToStem = 5;
  46635. var opacity = 0.5;
  46636. class Axis extends Object3D {// 坐标轴
  46637. constructor () {
  46638. super();
  46639. this.getArrow();
  46640. this.createArrows();
  46641. //this.position.copy(position) 点云的中心点就是在(0,0,0)
  46642. //this.scale.set(2,2,2)
  46643. /* viewer.addEventListener('camera_changed', e => {
  46644. if(e.viewport.name != 'MainView')return //只调整mainView,否则需要每次渲染前调整。缺点:地图上的大小变来变去
  46645. let s = Potree.math.getScaleForConstantSize( {//规定下最小最大像素
  46646. width2d:50, camera:e.camera , position:this.position,
  46647. resolution: e.viewport.resolution//2
  46648. })
  46649. this.scale.set(s,s,s)
  46650. }) */
  46651. }
  46652. getArrow(){
  46653. var arrowGroup = new Object3D();
  46654. var line = LineDraw.createLine([new Vector3, new Vector3(0,0,lineLen$1)]);
  46655. var stem = new Mesh(new BoxGeometry(0.3, 0.3, stemLen));
  46656. stem.position.set(0,0,lineLen$1+lineDisToStem+stemLen/2);
  46657. 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
  46658. arrow.position.set(0,0,lineLen$1+lineDisToStem+stemLen + arrowLen/2);
  46659. arrow.rotation.set(Math.PI/2,0,0);
  46660. arrowGroup.add(stem);
  46661. arrowGroup.add(line);
  46662. arrowGroup.add(arrow);
  46663. this.arrowGroup = arrowGroup;
  46664. }
  46665. createArrows(){
  46666. var material = new MeshBasicMaterial({color:"#00d7df",side:2,transparent:true,opacity:0.8, depthWrite:false});
  46667. ['x','y','z'].forEach((axisText)=>{
  46668. let color = new Color().set(Potree.config.axis[axisText].color);
  46669. var group = this.arrowGroup.clone();
  46670. group.children.forEach(e=>{
  46671. e.material = e.material.clone();
  46672. /* e.material.opacity = opacity
  46673. e.material.transparent = true */
  46674. e.material.color.copy(color);
  46675. });
  46676. var label = this.createLabel(axisText, color);
  46677. label.position.set(0, 0, lineLen$1 + stemLen + arrowLen + lineDisToStem + 3);
  46678. group.add(label);
  46679. if(axisText == 'y'){
  46680. group.rotation.x = -Math.PI / 2;
  46681. }else if(axisText == 'x'){
  46682. group.rotation.y = Math.PI / 2;
  46683. }
  46684. this.add(group);
  46685. });
  46686. }
  46687. createLabel(text,color){
  46688. let label = new TextSprite$2({ //无法解决 因其祖先有设定quaternion, 无法对着镜头
  46689. backgroundColor: {r: 0, g: 0, b: 0, a:0},
  46690. textColor: {r: color.r * 255, g: color.g*255, b: color.b*255, a:1},
  46691. fontsize:120,
  46692. //useDepth : true ,
  46693. renderOrder : 5,// pickOrder:5,
  46694. text, name:'axis'
  46695. });
  46696. label.scale.set(3,3,3);
  46697. return label
  46698. }
  46699. /* createLabel(text,color){
  46700. var canvas = document.createElement("canvas")
  46701. var context = canvas.getContext("2d");
  46702. canvas.width = 256,
  46703. canvas.height = 256;
  46704. var fontSize = 120
  46705. context.fillStyle = color //"#00ffee";
  46706. context.font = "normal " + fontSize + "px 微软雅黑"
  46707. var textWidth = context.measureText(text).width;
  46708. context.clearRect(0,0,canvas.width,canvas.height);
  46709. context.fillText(text, (canvas.width - textWidth) / 2 , (canvas.height + fontSize) / 2);
  46710. var tex = new THREE.Texture(canvas);
  46711. tex.needsUpdate = true
  46712. tex.minFilter = THREE.NearestFilter//防止边缘发黑
  46713. tex.magFilter = THREE.NearestFilter//防止边缘发黑
  46714. var sprite = new THREE.Sprite(new THREE.SpriteMaterial({
  46715. map: tex , // depthWrite:false,
  46716. }))
  46717. sprite.renderOrder = 1//防止在透明后还是出现白矩形挡住其他mesh
  46718. sprite.scale.set(3,3,3)
  46719. return sprite
  46720. } */
  46721. }
  46722. class Action extends EventDispatcher$1 {
  46723. constructor (args = {}) {
  46724. super();
  46725. this.icon = args.icon || '';
  46726. this.tooltip = args.tooltip;
  46727. if (args.onclick !== undefined) {
  46728. this.onclick = args.onclick;
  46729. }
  46730. }
  46731. onclick (event) {
  46732. }
  46733. pairWith (object) {
  46734. }
  46735. setIcon (newIcon) {
  46736. let oldIcon = this.icon;
  46737. if (newIcon === oldIcon) {
  46738. return;
  46739. }
  46740. this.icon = newIcon;
  46741. this.dispatchEvent({
  46742. type: 'icon_changed',
  46743. action: this,
  46744. icon: newIcon,
  46745. oldIcon: oldIcon
  46746. });
  46747. }
  46748. };
  46749. //Potree.Actions = {};
  46750. //
  46751. //Potree.Actions.ToggleAnnotationVisibility = class ToggleAnnotationVisibility extends Potree.Action {
  46752. // constructor (args = {}) {
  46753. // super(args);
  46754. //
  46755. // this.icon = Potree.resourcePath + '/icons/eye.svg';
  46756. // this.showIn = 'sidebar';
  46757. // this.tooltip = 'toggle visibility';
  46758. // }
  46759. //
  46760. // pairWith (annotation) {
  46761. // if (annotation.visible) {
  46762. // this.setIcon(Potree.resourcePath + '/icons/eye.svg');
  46763. // } else {
  46764. // this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
  46765. // }
  46766. //
  46767. // annotation.addEventListener('visibility_changed', e => {
  46768. // let annotation = e.annotation;
  46769. //
  46770. // if (annotation.visible) {
  46771. // this.setIcon(Potree.resourcePath + '/icons/eye.svg');
  46772. // } else {
  46773. // this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
  46774. // }
  46775. // });
  46776. // }
  46777. //
  46778. // onclick (event) {
  46779. // let annotation = event.annotation;
  46780. //
  46781. // annotation.visible = !annotation.visible;
  46782. //
  46783. // if (annotation.visible) {
  46784. // this.setIcon(Potree.resourcePath + '/icons/eye.svg');
  46785. // } else {
  46786. // this.setIcon(Potree.resourcePath + '/icons/eye_crossed.svg');
  46787. // }
  46788. // }
  46789. //};
  46790. class Annotation extends EventDispatcher$1 {
  46791. constructor (args = {}) {
  46792. super();
  46793. this.scene = null;
  46794. this._title = args.title || 'No Title';
  46795. this._description = args.description || '';
  46796. this.offset = new Vector3();
  46797. this.uuid = MathUtils.generateUUID();
  46798. if (!args.position) {
  46799. this.position = null;
  46800. } else if (args.position.x != null) {
  46801. this.position = args.position;
  46802. } else {
  46803. this.position = new Vector3(...args.position);
  46804. }
  46805. this.cameraPosition = (args.cameraPosition instanceof Array)
  46806. ? new Vector3().fromArray(args.cameraPosition) : args.cameraPosition;
  46807. this.cameraTarget = (args.cameraTarget instanceof Array)
  46808. ? new Vector3().fromArray(args.cameraTarget) : args.cameraTarget;
  46809. this.radius = args.radius;
  46810. this.view = args.view || null;
  46811. this.keepOpen = false;
  46812. this.descriptionVisible = false;
  46813. this.showDescription = true;
  46814. this.actions = args.actions || [];
  46815. this.isHighlighted = false;
  46816. this._visible = true;
  46817. this.__visible = true;
  46818. this._display = true;
  46819. this._expand = false;
  46820. this.collapseThreshold = [args.collapseThreshold, 100].find(e => e !== undefined);
  46821. this.children = [];
  46822. this.parent = null;
  46823. this.boundingBox = new Box3();
  46824. let iconClose = exports.resourcePath + '/icons/close.svg';
  46825. this.domElement = $(`
  46826. <div class="annotation" oncontextmenu="return false;">
  46827. <div class="annotation-titlebar">
  46828. <span class="annotation-label"></span>
  46829. </div>
  46830. <div class="annotation-description">
  46831. <span class="annotation-description-close">
  46832. <img src="${iconClose}" width="16px">
  46833. </span>
  46834. <span class="annotation-description-content">${this._description}</span>
  46835. </div>
  46836. </div>
  46837. `);
  46838. this.elTitlebar = this.domElement.find('.annotation-titlebar');
  46839. this.elTitle = this.elTitlebar.find('.annotation-label');
  46840. this.elTitle.append(this._title);
  46841. this.elDescription = this.domElement.find('.annotation-description');
  46842. this.elDescriptionClose = this.elDescription.find('.annotation-description-close');
  46843. // this.elDescriptionContent = this.elDescription.find(".annotation-description-content");
  46844. this.clickTitle = () => {
  46845. if(this.hasView()){
  46846. this.moveHere(this.scene.getActiveCamera());
  46847. }
  46848. this.dispatchEvent({type: 'click', target: this});
  46849. };
  46850. this.elTitle.click(this.clickTitle);
  46851. this.actions = this.actions.map(a => {
  46852. if (a instanceof Action) {
  46853. return a;
  46854. } else {
  46855. return new Action(a);
  46856. }
  46857. });
  46858. for (let action of this.actions) {
  46859. action.pairWith(this);
  46860. }
  46861. let actions = this.actions.filter(
  46862. a => a.showIn === undefined || a.showIn.includes('scene'));
  46863. for (let action of actions) {
  46864. let elButton = $(`<img src="${action.icon}" class="annotation-action-icon">`);
  46865. this.elTitlebar.append(elButton);
  46866. elButton.click(() => action.onclick({annotation: this}));
  46867. }
  46868. this.elDescriptionClose.hover(
  46869. e => this.elDescriptionClose.css('opacity', '1'),
  46870. e => this.elDescriptionClose.css('opacity', '0.5')
  46871. );
  46872. this.elDescriptionClose.click(e => this.setHighlighted(false));
  46873. // this.elDescriptionContent.html(this._description);
  46874. this.domElement.mouseenter(e => this.setHighlighted(true));
  46875. this.domElement.mouseleave(e => this.setHighlighted(false));
  46876. this.domElement.on('touchstart', e => {
  46877. this.setHighlighted(!this.isHighlighted);
  46878. });
  46879. this.display = false;
  46880. //this.display = true;
  46881. }
  46882. installHandles(viewer){
  46883. if(this.handles !== undefined){
  46884. return;
  46885. }
  46886. let domElement = $(`
  46887. <div style="position: absolute; left: 300; top: 200; pointer-events: none">
  46888. <svg width="300" height="600">
  46889. <line x1="0" y1="0" x2="1200" y2="200" style="stroke: black; stroke-width:2" />
  46890. <circle cx="50" cy="50" r="4" stroke="black" stroke-width="2" fill="gray" />
  46891. <circle cx="150" cy="50" r="4" stroke="black" stroke-width="2" fill="gray" />
  46892. </svg>
  46893. </div>
  46894. `);
  46895. let svg = domElement.find("svg")[0];
  46896. let elLine = domElement.find("line")[0];
  46897. let elStart = domElement.find("circle")[0];
  46898. let elEnd = domElement.find("circle")[1];
  46899. let setCoordinates = (start, end) => {
  46900. elStart.setAttribute("cx", `${start.x}`);
  46901. elStart.setAttribute("cy", `${start.y}`);
  46902. elEnd.setAttribute("cx", `${end.x}`);
  46903. elEnd.setAttribute("cy", `${end.y}`);
  46904. elLine.setAttribute("x1", start.x);
  46905. elLine.setAttribute("y1", start.y);
  46906. elLine.setAttribute("x2", end.x);
  46907. elLine.setAttribute("y2", end.y);
  46908. let box = svg.getBBox();
  46909. svg.setAttribute("width", `${box.width}`);
  46910. svg.setAttribute("height", `${box.height}`);
  46911. svg.setAttribute("viewBox", `${box.x} ${box.y} ${box.width} ${box.height}`);
  46912. let ya = start.y - end.y;
  46913. let xa = start.x - end.x;
  46914. if(ya > 0){
  46915. start.y = start.y - ya;
  46916. }
  46917. if(xa > 0){
  46918. start.x = start.x - xa;
  46919. }
  46920. domElement.css("left", `${start.x}px`);
  46921. domElement.css("top", `${start.y}px`);
  46922. };
  46923. $(viewer.renderArea).append(domElement);
  46924. let annotationStartPos = this.position.clone();
  46925. let annotationStartOffset = this.offset.clone();
  46926. $(this.domElement).draggable({
  46927. start: (event, ui) => {
  46928. annotationStartPos = this.position.clone();
  46929. annotationStartOffset = this.offset.clone();
  46930. $(this.domElement).find(".annotation-titlebar").css("pointer-events", "none");
  46931. console.log($(this.domElement).find(".annotation-titlebar"));
  46932. },
  46933. stop: () => {
  46934. $(this.domElement).find(".annotation-titlebar").css("pointer-events", "");
  46935. },
  46936. drag: (event, ui ) => {
  46937. let renderAreaWidth = viewer.renderer.getSize(new Vector2()).width;
  46938. //let renderAreaHeight = viewer.renderer.getSize().height;
  46939. let diff = {
  46940. x: ui.originalPosition.left - ui.position.left,
  46941. y: ui.originalPosition.top - ui.position.top
  46942. };
  46943. let nDiff = {
  46944. x: -(diff.x / renderAreaWidth) * 2,
  46945. y: (diff.y / renderAreaWidth) * 2
  46946. };
  46947. let camera = viewer.scene.getActiveCamera();
  46948. let oldScreenPos = new Vector3()
  46949. .addVectors(annotationStartPos, annotationStartOffset)
  46950. .project(camera);
  46951. let newScreenPos = oldScreenPos.clone();
  46952. newScreenPos.x += nDiff.x;
  46953. newScreenPos.y += nDiff.y;
  46954. let newPos = newScreenPos.clone();
  46955. newPos.unproject(camera);
  46956. let newOffset = new Vector3().subVectors(newPos, this.position);
  46957. this.offset.copy(newOffset);
  46958. }
  46959. });
  46960. let updateCallback = () => {
  46961. let position = this.position;
  46962. let scene = viewer.scene;
  46963. const renderAreaSize = viewer.renderer.getSize(new Vector2());
  46964. let renderAreaWidth = renderAreaSize.width;
  46965. let renderAreaHeight = renderAreaSize.height;
  46966. let start = this.position.clone();
  46967. let end = new Vector3().addVectors(this.position, this.offset);
  46968. let toScreen = (position) => {
  46969. let camera = scene.getActiveCamera();
  46970. let screenPos = new Vector3();
  46971. let worldView = new Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  46972. let ndc = new Vector4(position.x, position.y, position.z, 1.0).applyMatrix4(worldView);
  46973. // limit w to small positive value, in case position is behind the camera
  46974. ndc.w = Math.max(ndc.w, 0.1);
  46975. ndc.divideScalar(ndc.w);
  46976. screenPos.copy(ndc);
  46977. screenPos.x = renderAreaWidth * (screenPos.x + 1) / 2;
  46978. screenPos.y = renderAreaHeight * (1 - (screenPos.y + 1) / 2);
  46979. return screenPos;
  46980. };
  46981. start = toScreen(start);
  46982. end = toScreen(end);
  46983. setCoordinates(start, end);
  46984. };
  46985. viewer.addEventListener("update", updateCallback);
  46986. this.handles = {
  46987. domElement: domElement,
  46988. setCoordinates: setCoordinates,
  46989. updateCallback: updateCallback
  46990. };
  46991. }
  46992. removeHandles(viewer){
  46993. if(this.handles === undefined){
  46994. return;
  46995. }
  46996. //$(viewer.renderArea).remove(this.handles.domElement);
  46997. this.handles.domElement.remove();
  46998. viewer.removeEventListener("update", this.handles.updateCallback);
  46999. delete this.handles;
  47000. }
  47001. get visible () {
  47002. return this._visible;
  47003. }
  47004. set visible (value) {
  47005. if (this._visible === value) {
  47006. return;
  47007. }
  47008. this._visible = value;
  47009. //this.traverse(node => {
  47010. // node.display = value;
  47011. //});
  47012. this.dispatchEvent({
  47013. type: 'visibility_changed',
  47014. annotation: this
  47015. });
  47016. }
  47017. get display () {
  47018. return this._display;
  47019. }
  47020. set display (display) {
  47021. if (this._display === display) {
  47022. return;
  47023. }
  47024. this._display = display;
  47025. if (display) {
  47026. // this.domElement.fadeIn(200);
  47027. this.domElement.show();
  47028. } else {
  47029. // this.domElement.fadeOut(200);
  47030. this.domElement.hide();
  47031. }
  47032. }
  47033. get expand () {
  47034. return this._expand;
  47035. }
  47036. set expand (expand) {
  47037. if (this._expand === expand) {
  47038. return;
  47039. }
  47040. if (expand) {
  47041. this.display = false;
  47042. } else {
  47043. this.display = true;
  47044. this.traverseDescendants(node => {
  47045. node.display = false;
  47046. });
  47047. }
  47048. this._expand = expand;
  47049. }
  47050. get title () {
  47051. return this._title;
  47052. }
  47053. set title (title) {
  47054. if (this._title === title) {
  47055. return;
  47056. }
  47057. this._title = title;
  47058. this.elTitle.empty();
  47059. this.elTitle.append(this._title);
  47060. this.dispatchEvent({
  47061. type: "annotation_changed",
  47062. annotation: this,
  47063. });
  47064. }
  47065. get description () {
  47066. return this._description;
  47067. }
  47068. set description (description) {
  47069. if (this._description === description) {
  47070. return;
  47071. }
  47072. this._description = description;
  47073. const elDescriptionContent = this.elDescription.find(".annotation-description-content");
  47074. elDescriptionContent.empty();
  47075. elDescriptionContent.append(this._description);
  47076. this.dispatchEvent({
  47077. type: "annotation_changed",
  47078. annotation: this,
  47079. });
  47080. }
  47081. add (annotation) {
  47082. if (!this.children.includes(annotation)) {
  47083. this.children.push(annotation);
  47084. annotation.parent = this;
  47085. let descendants = [];
  47086. annotation.traverse(a => { descendants.push(a); });
  47087. for (let descendant of descendants) {
  47088. let c = this;
  47089. while (c !== null) {
  47090. c.dispatchEvent({
  47091. 'type': 'annotation_added',
  47092. 'annotation': descendant
  47093. });
  47094. c = c.parent;
  47095. }
  47096. }
  47097. }
  47098. }
  47099. level () {
  47100. if (this.parent === null) {
  47101. return 0;
  47102. } else {
  47103. return this.parent.level() + 1;
  47104. }
  47105. }
  47106. hasChild(annotation) {
  47107. return this.children.includes(annotation);
  47108. }
  47109. remove (annotation) {
  47110. if (this.hasChild(annotation)) {
  47111. annotation.removeAllChildren();
  47112. annotation.dispose();
  47113. this.children = this.children.filter(e => e !== annotation);
  47114. annotation.parent = null;
  47115. }
  47116. }
  47117. removeAllChildren() {
  47118. this.children.forEach((child) => {
  47119. if (child.children.length > 0) {
  47120. child.removeAllChildren();
  47121. }
  47122. this.remove(child);
  47123. });
  47124. }
  47125. updateBounds () {
  47126. let box = new Box3();
  47127. if (this.position) {
  47128. box.expandByPoint(this.position);
  47129. }
  47130. for (let child of this.children) {
  47131. child.updateBounds();
  47132. box.union(child.boundingBox);
  47133. }
  47134. this.boundingBox.copy(box);
  47135. }
  47136. traverse (handler) {
  47137. let expand = handler(this);
  47138. if (expand === undefined || expand === true) {
  47139. for (let child of this.children) {
  47140. child.traverse(handler);
  47141. }
  47142. }
  47143. }
  47144. traverseDescendants (handler) {
  47145. for (let child of this.children) {
  47146. child.traverse(handler);
  47147. }
  47148. }
  47149. flatten () {
  47150. let annotations = [];
  47151. this.traverse(annotation => {
  47152. annotations.push(annotation);
  47153. });
  47154. return annotations;
  47155. }
  47156. descendants () {
  47157. let annotations = [];
  47158. this.traverse(annotation => {
  47159. if (annotation !== this) {
  47160. annotations.push(annotation);
  47161. }
  47162. });
  47163. return annotations;
  47164. }
  47165. setHighlighted (highlighted) {
  47166. if (highlighted) {
  47167. this.domElement.css('opacity', '0.8');
  47168. this.elTitlebar.css('box-shadow', '0 0 5px #fff');
  47169. this.domElement.css('z-index', '1000');
  47170. if (this._description) {
  47171. this.descriptionVisible = true;
  47172. this.elDescription.fadeIn(200);
  47173. this.elDescription.css('position', 'relative');
  47174. }
  47175. } else {
  47176. this.domElement.css('opacity', '0.5');
  47177. this.elTitlebar.css('box-shadow', '');
  47178. this.domElement.css('z-index', '100');
  47179. this.descriptionVisible = false;
  47180. this.elDescription.css('display', 'none');
  47181. }
  47182. this.isHighlighted = highlighted;
  47183. }
  47184. hasView () {
  47185. let hasPosTargetView = this.cameraTarget.x != null;
  47186. hasPosTargetView = hasPosTargetView && this.cameraPosition.x != null;
  47187. let hasRadiusView = this.radius !== undefined;
  47188. let hasView = hasPosTargetView || hasRadiusView;
  47189. return hasView;
  47190. };
  47191. moveHere (camera) {
  47192. if (!this.hasView()) {
  47193. return;
  47194. }
  47195. let view = this.scene.view;
  47196. let animationDuration = 500;
  47197. let easing = TWEEN.Easing.Quartic.Out;
  47198. let endTarget;
  47199. if (this.cameraTarget) {
  47200. endTarget = this.cameraTarget;
  47201. } else if (this.position) {
  47202. endTarget = this.position;
  47203. } else {
  47204. endTarget = this.boundingBox.getCenter(new Vector3());
  47205. }
  47206. if (this.cameraPosition) {
  47207. let endPosition = this.cameraPosition;
  47208. Utils.moveTo(this.scene, endPosition, endTarget);
  47209. } else if (this.radius) {
  47210. let direction = view.direction;
  47211. let endPosition = endTarget.clone().add(direction.multiplyScalar(-this.radius));
  47212. let startRadius = view.radius;
  47213. let endRadius = this.radius;
  47214. { // animate camera position
  47215. let tween = new TWEEN.Tween(view.position).to(endPosition, animationDuration);
  47216. tween.easing(easing);
  47217. tween.start();
  47218. }
  47219. { // animate radius
  47220. let t = {x: 0};
  47221. let tween = new TWEEN.Tween(t)
  47222. .to({x: 1}, animationDuration)
  47223. .onUpdate(function () {
  47224. view.radius = this.x * endRadius + (1 - this.x) * startRadius;
  47225. });
  47226. tween.easing(easing);
  47227. tween.start();
  47228. }
  47229. }
  47230. };
  47231. dispose () {
  47232. if (this.domElement.parentElement) {
  47233. this.domElement.parentElement.removeChild(this.domElement);
  47234. }
  47235. };
  47236. toString () {
  47237. return 'Annotation: ' + this._title;
  47238. }
  47239. };
  47240. class Scene$1 extends EventDispatcher$1{//base
  47241. constructor(){
  47242. super();
  47243. this.annotations = new Annotation();
  47244. this.scene = new Scene();
  47245. this.sceneBG = new Scene();
  47246. this.scenePointCloud = new Scene();
  47247. this.cameraP = new PerspectiveCamera(this.fov, 1, 0.1, 1000*1000);
  47248. this.cameraO = new OrthographicCamera(-1, 1, 1, -1, 0.1, 1000*1000);
  47249. this.cameraVR = new PerspectiveCamera();
  47250. this.cameraBG = new Camera();
  47251. this.cameraScreenSpace = new OrthographicCamera(-1, 1, 1, -1, 0.1, 10);
  47252. this.cameraMode = CameraMode.PERSPECTIVE;
  47253. this.overrideCamera = null;
  47254. this.pointclouds = [];
  47255. this.measurements = [];
  47256. this.profiles = [];
  47257. this.volumes = [];
  47258. this.polygonClipVolumes = [];
  47259. this.cameraAnimations = [];
  47260. this.orientedImages = [];
  47261. this.images360 = [];
  47262. this.geopackages = [];
  47263. this.fpControls = null;
  47264. this.orbitControls = null;
  47265. this.earthControls = null;
  47266. this.geoControls = null;
  47267. this.deviceControls = null;
  47268. this.inputHandler = null;
  47269. this.view = new ExtendView();
  47270. this.directionalLight = null;
  47271. this.initialize();
  47272. }
  47273. estimateHeightAt (position) {
  47274. let height = null;
  47275. let fromSpacing = Infinity;
  47276. for (let pointcloud of this.pointclouds) {
  47277. if (pointcloud.root.geometryNode === undefined) {
  47278. continue;
  47279. }
  47280. let pHeight = null;
  47281. let pFromSpacing = Infinity;
  47282. let lpos = position.clone().sub(pointcloud.position);
  47283. lpos.z = 0;
  47284. let ray = new Ray(lpos, new Vector3(0, 0, 1));
  47285. let stack = [pointcloud.root];
  47286. while (stack.length > 0) {
  47287. let node = stack.pop();
  47288. let box = node.getBoundingBox();
  47289. let inside = ray.intersectBox(box);
  47290. if (!inside) {
  47291. continue;
  47292. }
  47293. let h = node.geometryNode.mean.z +
  47294. pointcloud.position.z +
  47295. node.geometryNode.boundingBox.min.z;
  47296. if (node.geometryNode.spacing <= pFromSpacing) {
  47297. pHeight = h;
  47298. pFromSpacing = node.geometryNode.spacing;
  47299. }
  47300. for (let index of Object.keys(node.children)) {
  47301. let child = node.children[index];
  47302. if (child.geometryNode) {
  47303. stack.push(node.children[index]);
  47304. }
  47305. }
  47306. }
  47307. if (height === null || pFromSpacing < fromSpacing) {
  47308. height = pHeight;
  47309. fromSpacing = pFromSpacing;
  47310. }
  47311. }
  47312. return height;
  47313. }
  47314. getBoundingBox(pointclouds = this.pointclouds){
  47315. let box = new Box3();
  47316. this.scenePointCloud.updateMatrixWorld(true);
  47317. this.referenceFrame.updateMatrixWorld(true);
  47318. for (let pointcloud of pointclouds) {
  47319. pointcloud.updateMatrixWorld(true);
  47320. let pointcloudBox = pointcloud.pcoGeometry.tightBoundingBox ? pointcloud.pcoGeometry.tightBoundingBox : pointcloud.boundingBox;
  47321. let boxWorld = Utils.computeTransformedBoundingBox(pointcloudBox, pointcloud.matrixWorld);
  47322. box.union(boxWorld);
  47323. }
  47324. return box;
  47325. }
  47326. addPointCloud (pointcloud) {
  47327. this.pointclouds.push(pointcloud);
  47328. this.scenePointCloud.add(pointcloud);
  47329. this.dispatchEvent({
  47330. type: 'pointcloud_added',
  47331. pointcloud: pointcloud
  47332. });
  47333. }
  47334. addVolume (volume) {
  47335. this.volumes.push(volume);
  47336. this.dispatchEvent({
  47337. 'type': 'volume_added',
  47338. 'scene': this,
  47339. 'volume': volume
  47340. });
  47341. viewer.dispatchEvent('content_changed');
  47342. }
  47343. addOrientedImages(images){
  47344. this.orientedImages.push(images);
  47345. this.scene.add(images.node);
  47346. this.dispatchEvent({
  47347. 'type': 'oriented_images_added',
  47348. 'scene': this,
  47349. 'images': images
  47350. });
  47351. };
  47352. removeOrientedImages(images){
  47353. let index = this.orientedImages.indexOf(images);
  47354. if (index > -1) {
  47355. this.orientedImages.splice(index, 1);
  47356. this.dispatchEvent({
  47357. 'type': 'oriented_images_removed',
  47358. 'scene': this,
  47359. 'images': images
  47360. });
  47361. }
  47362. };
  47363. add360Images(images){
  47364. this.images360.push(images);
  47365. this.scene.add(images.node);
  47366. this.dispatchEvent({
  47367. 'type': '360_images_added',
  47368. 'scene': this,
  47369. 'images': images
  47370. });
  47371. }
  47372. remove360Images(images){
  47373. let index = this.images360.indexOf(images);
  47374. if (index > -1) {
  47375. this.images360.splice(index, 1);
  47376. this.dispatchEvent({
  47377. 'type': '360_images_removed',
  47378. 'scene': this,
  47379. 'images': images
  47380. });
  47381. }
  47382. }
  47383. addGeopackage(geopackage){
  47384. this.geopackages.push(geopackage);
  47385. this.scene.add(geopackage.node);
  47386. this.dispatchEvent({
  47387. 'type': 'geopackage_added',
  47388. 'scene': this,
  47389. 'geopackage': geopackage
  47390. });
  47391. };
  47392. removeGeopackage(geopackage){
  47393. let index = this.geopackages.indexOf(geopackage);
  47394. if (index > -1) {
  47395. this.geopackages.splice(index, 1);
  47396. this.dispatchEvent({
  47397. 'type': 'geopackage_removed',
  47398. 'scene': this,
  47399. 'geopackage': geopackage
  47400. });
  47401. }
  47402. };
  47403. removeVolume (volume) {
  47404. let index = this.volumes.indexOf(volume);
  47405. if (index > -1) {
  47406. this.volumes.splice(index, 1);
  47407. this.dispatchEvent({
  47408. 'type': 'volume_removed',
  47409. 'scene': this,
  47410. 'volume': volume
  47411. });
  47412. }
  47413. viewer.dispatchEvent('content_changed');
  47414. };
  47415. addCameraAnimation(animation) {
  47416. this.cameraAnimations.push(animation);
  47417. this.dispatchEvent({
  47418. 'type': 'camera_animation_added',
  47419. 'scene': this,
  47420. 'animation': animation
  47421. });
  47422. };
  47423. removeCameraAnimation(animation){
  47424. let index = this.cameraAnimations.indexOf(volume);
  47425. if (index > -1) {
  47426. this.cameraAnimations.splice(index, 1);
  47427. this.dispatchEvent({
  47428. 'type': 'camera_animation_removed',
  47429. 'scene': this,
  47430. 'animation': animation
  47431. });
  47432. }
  47433. };
  47434. addPolygonClipVolume(volume){
  47435. this.polygonClipVolumes.push(volume);
  47436. this.dispatchEvent({
  47437. "type": "polygon_clip_volume_added",
  47438. "scene": this,
  47439. "volume": volume
  47440. });
  47441. };
  47442. removePolygonClipVolume(volume){
  47443. let index = this.polygonClipVolumes.indexOf(volume);
  47444. if (index > -1) {
  47445. this.polygonClipVolumes.splice(index, 1);
  47446. this.dispatchEvent({
  47447. "type": "polygon_clip_volume_removed",
  47448. "scene": this,
  47449. "volume": volume
  47450. });
  47451. }
  47452. };
  47453. addMeasurement(measurement){
  47454. measurement.lengthUnit = this.lengthUnit;
  47455. measurement.lengthUnitDisplay = this.lengthUnitDisplay;
  47456. this.measurements.push(measurement);
  47457. this.dispatchEvent({
  47458. 'type': 'measurement_added',
  47459. 'scene': this,
  47460. 'measurement': measurement
  47461. });
  47462. viewer.dispatchEvent('content_changed');
  47463. };
  47464. removeMeasurement (measurement) {
  47465. let index = this.measurements.indexOf(measurement);
  47466. if (index > -1) {
  47467. this.measurements.splice(index, 1);
  47468. this.dispatchEvent({
  47469. 'type': 'measurement_removed',
  47470. 'scene': this,
  47471. 'measurement': measurement
  47472. });
  47473. viewer.dispatchEvent('content_changed');
  47474. }
  47475. }
  47476. addProfile (profile) {
  47477. this.profiles.push(profile);
  47478. this.dispatchEvent({
  47479. 'type': 'profile_added',
  47480. 'scene': this,
  47481. 'profile': profile
  47482. });
  47483. }
  47484. removeProfile (profile) {
  47485. let index = this.profiles.indexOf(profile);
  47486. if (index > -1) {
  47487. this.profiles.splice(index, 1);
  47488. this.dispatchEvent({
  47489. 'type': 'profile_removed',
  47490. 'scene': this,
  47491. 'profile': profile
  47492. });
  47493. }
  47494. }
  47495. removeAllMeasurements () {
  47496. while (this.measurements.length > 0) {
  47497. this.removeMeasurement(this.measurements[0]);
  47498. }
  47499. while (this.profiles.length > 0) {
  47500. this.removeProfile(this.profiles[0]);
  47501. }
  47502. while (this.volumes.length > 0) {
  47503. this.removeVolume(this.volumes[0]);
  47504. }
  47505. }
  47506. removeAllClipVolumes(){
  47507. let clipVolumes = this.volumes.filter(volume => volume.clip === true);
  47508. for(let clipVolume of clipVolumes){
  47509. this.removeVolume(clipVolume);
  47510. }
  47511. while(this.polygonClipVolumes.length > 0){
  47512. this.removePolygonClipVolume(this.polygonClipVolumes[0]);
  47513. }
  47514. }
  47515. getActiveCamera() {
  47516. if(this.overrideCamera){
  47517. return this.overrideCamera;
  47518. }
  47519. if(this.cameraMode === CameraMode.PERSPECTIVE){
  47520. return this.cameraP;
  47521. }else if(this.cameraMode === CameraMode.ORTHOGRAPHIC){
  47522. return this.cameraO;
  47523. }else if(this.cameraMode === CameraMode.VR){
  47524. return this.cameraVR;
  47525. }
  47526. return null;
  47527. }
  47528. initialize(){
  47529. this.referenceFrame = new Object3D();
  47530. this.referenceFrame.matrixAutoUpdate = false;
  47531. this.scenePointCloud.add(this.referenceFrame);
  47532. this.cameraP.up.set(0, 0, 1);
  47533. this.cameraP.position.set(1000, 1000, 1000);
  47534. this.cameraO.up.set(0, 0, 1);
  47535. this.cameraO.position.set(1000, 1000, 1000);
  47536. //this.camera.rotation.y = -Math.PI / 4;
  47537. //this.camera.rotation.x = -Math.PI / 6;
  47538. this.cameraScreenSpace.lookAt(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0));
  47539. this.directionalLight = new DirectionalLight( 0xffffff, 0.5 );
  47540. this.directionalLight.position.set( 10, 10, 10 );
  47541. this.directionalLight.lookAt( new Vector3(0, 0, 0));
  47542. this.scenePointCloud.add( this.directionalLight );
  47543. let light = new AmbientLight( 0x555555 ); // soft white light
  47544. this.scenePointCloud.add( light );
  47545. { // background
  47546. let texture = Utils.createBackgroundTexture(512, 512);
  47547. texture.minFilter = texture.magFilter = NearestFilter;
  47548. texture.minFilter = texture.magFilter = LinearFilter;
  47549. let bg = new Mesh(
  47550. new PlaneBufferGeometry(2, 2, 1),
  47551. new MeshBasicMaterial({
  47552. map: texture
  47553. })
  47554. );
  47555. bg.material.depthTest = false;
  47556. bg.material.depthWrite = false;
  47557. this.sceneBG.add(bg);
  47558. }
  47559. // { // lights
  47560. // {
  47561. // let light = new THREE.DirectionalLight(0xffffff);
  47562. // light.position.set(10, 10, 1);
  47563. // light.target.position.set(0, 0, 0);
  47564. // this.scene.add(light);
  47565. // }
  47566. // {
  47567. // let light = new THREE.DirectionalLight(0xffffff);
  47568. // light.position.set(-10, 10, 1);
  47569. // light.target.position.set(0, 0, 0);
  47570. // this.scene.add(light);
  47571. // }
  47572. // {
  47573. // let light = new THREE.DirectionalLight(0xffffff);
  47574. // light.position.set(0, -10, 20);
  47575. // light.target.position.set(0, 0, 0);
  47576. // this.scene.add(light);
  47577. // }
  47578. // }
  47579. }
  47580. addAnnotation(position, args = {}){
  47581. if(position instanceof Array){
  47582. args.position = new Vector3().fromArray(position);
  47583. } else if (position.x != null) {
  47584. args.position = position;
  47585. }
  47586. let annotation = new Annotation(args);
  47587. this.annotations.add(annotation);
  47588. return annotation;
  47589. }
  47590. getAnnotations () {
  47591. return this.annotations;
  47592. };
  47593. removeAnnotation(annotationToRemove) {
  47594. this.annotations.remove(annotationToRemove);
  47595. }
  47596. };
  47597. class ExtendScene extends Scene$1{
  47598. constructor(){
  47599. super();
  47600. delete this.sceneBG;
  47601. this.cameraP = new PerspectiveCamera(this.fov, 1, Potree.config.view.near, Potree.config.view.near);
  47602. this.cameraO = new OrthographicCamera(-1, 1, 1, -1, Potree.config.view.near, Potree.settings.cameraFar);
  47603. this.cameraP.limitFar = true;//add
  47604. this.initializeExtend();
  47605. //-------------
  47606. this.axisArrow = new Axis();
  47607. this.scene.add(this.axisArrow);
  47608. if(!Potree.settings.isDebug && !Potree.settings.showAxis)this.axisArrow.visible = false;
  47609. Potree.Utils.setObjectLayers(this.axisArrow, 'bothMapAndScene' );
  47610. this.tags = new Object3D;
  47611. this.scene.add(this.tags);
  47612. }
  47613. estimateHeightAt (position) {
  47614. let height = null;
  47615. let fromSpacing = Infinity;
  47616. for (let pointcloud of this.pointclouds) {
  47617. if (pointcloud.root.geometryNode === undefined) {
  47618. continue;
  47619. }
  47620. let pHeight = null;
  47621. let pFromSpacing = Infinity;
  47622. let lpos = position.clone().sub(pointcloud.position);
  47623. lpos.z = 0;
  47624. let ray = new Ray(lpos, new Vector3(0, 0, 1));
  47625. let stack = [pointcloud.root];
  47626. while (stack.length > 0) {
  47627. let node = stack.pop();
  47628. let box = node.getBoundingBox();
  47629. let inside = ray.intersectBox(box);
  47630. if (!inside) {
  47631. continue;
  47632. }
  47633. let h = node.geometryNode.mean.z +
  47634. pointcloud.position.z +
  47635. node.geometryNode.boundingBox.min.z;
  47636. if (node.geometryNode.spacing <= pFromSpacing) {
  47637. pHeight = h;
  47638. pFromSpacing = node.geometryNode.spacing;
  47639. }
  47640. for (let index of Object.keys(node.children)) {
  47641. let child = node.children[index];
  47642. if (child.geometryNode) {
  47643. stack.push(node.children[index]);
  47644. }
  47645. }
  47646. }
  47647. if (height === null || pFromSpacing < fromSpacing) {
  47648. height = pHeight;
  47649. fromSpacing = pFromSpacing;
  47650. }
  47651. }
  47652. return height;
  47653. }
  47654. //add:
  47655. removePointCloud (pointcloud) {
  47656. let index = this.pointclouds.indexOf(pointcloud);
  47657. if(index == -1)return
  47658. this.pointclouds.splice(index, 1);
  47659. this.scenePointCloud.remove(pointcloud);
  47660. pointcloud.panos.forEach(pano=>{
  47661. pano.dispose();
  47662. });
  47663. }
  47664. removeCameraAnimation(animation){
  47665. let index = this.cameraAnimations.indexOf(animation);
  47666. if (index > -1) {
  47667. this.cameraAnimations.splice(index, 1);
  47668. this.dispatchEvent({
  47669. 'type': 'camera_animation_removed',
  47670. 'scene': this,
  47671. 'animation': animation
  47672. });
  47673. }
  47674. };
  47675. getActiveCamera() {
  47676. return viewer.mainViewport.camera
  47677. }
  47678. initialize(){//不用旧的 因为还没创建完变量
  47679. }
  47680. initializeExtend(){//add 新的initialize
  47681. this.referenceFrame = new Object3D();
  47682. this.referenceFrame.matrixAutoUpdate = false;
  47683. this.scenePointCloud.add(this.referenceFrame);
  47684. if(window.axisYup){
  47685. }else {
  47686. this.cameraP.up.set(0, 0, 1);
  47687. this.cameraO.up.set(0, 0, 1);
  47688. }
  47689. this.cameraP.position.set(1000, 1000, 1000);
  47690. this.cameraO.position.set(1000, 1000, 1000);
  47691. //this.camera.rotation.y = -Math.PI / 4;
  47692. //this.camera.rotation.x = -Math.PI / 6;
  47693. this.cameraScreenSpace.lookAt(new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 1, 0));
  47694. this.directionalLight = new DirectionalLight( 0xffffff, 0.5 );
  47695. this.directionalLight.position.set( 10, 10, 10 );
  47696. this.directionalLight.lookAt( new Vector3(0, 0, 0));
  47697. this.scenePointCloud.add( this.directionalLight );
  47698. let light = new AmbientLight( 0x555555 ); // soft white light
  47699. this.scenePointCloud.add( light );
  47700. //add:------给空间模型的box 或其他obj------
  47701. let light2 = new AmbientLight( 16777215, 0.5 );
  47702. Potree.Utils.setObjectLayers(light2, 'light'/* 'bothMapAndScene' */);
  47703. this.scene.add(light2);
  47704. let light3 = new DirectionalLight( 16777215, 0.7);
  47705. light3.position.set( 10, 10, 10 );
  47706. light3.lookAt( new Vector3(0, 0, 0));
  47707. Potree.Utils.setObjectLayers(light3, 'light');
  47708. this.scene.add(light3);
  47709. let light4 = new DirectionalLight( 16777215, 0.3); //补光
  47710. light4.position.set( -10, -5, -7 );
  47711. light4.lookAt( new Vector3(0, 0, 0));
  47712. Potree.Utils.setObjectLayers(light4, 'light');
  47713. this.scene.add(light4);
  47714. //--------------------------------------------
  47715. { // background
  47716. let texture = Utils.createBackgroundTexture(512, 512);
  47717. texture.minFilter = texture.magFilter = NearestFilter;
  47718. texture.minFilter = texture.magFilter = LinearFilter;
  47719. let bg = new Mesh(
  47720. new PlaneBufferGeometry(2, 2, 1),
  47721. new MeshBasicMaterial({
  47722. map: texture
  47723. })
  47724. );
  47725. bg.material.depthTest = false;
  47726. bg.material.depthWrite = false;
  47727. bg.name = 'bg';
  47728. //this.sceneBG.add(bg);
  47729. this.scene.add(bg);
  47730. bg.layers.set(Potree.config.renderLayers.bg);
  47731. }
  47732. { // background color
  47733. let bg2 = new Mesh(
  47734. new PlaneBufferGeometry(2, 2, 1),
  47735. new MeshBasicMaterial({
  47736. transparent : true
  47737. })
  47738. );
  47739. bg2.material.depthTest = false;
  47740. bg2.material.depthWrite = false;
  47741. bg2.name = 'bg2';
  47742. this.scene.add(bg2);
  47743. bg2.layers.set(Potree.config.renderLayers.bg2);
  47744. this.bg2 = bg2;
  47745. }
  47746. // { // lights
  47747. // {
  47748. // let light = new THREE.DirectionalLight(0xffffff);
  47749. // light.position.set(10, 10, 1);
  47750. // light.target.position.set(0, 0, 0);
  47751. // this.scene.add(light);
  47752. // }
  47753. // {
  47754. // let light = new THREE.DirectionalLight(0xffffff);
  47755. // light.position.set(-10, 10, 1);
  47756. // light.target.position.set(0, 0, 0);
  47757. // this.scene.add(light);
  47758. // }
  47759. // {
  47760. // let light = new THREE.DirectionalLight(0xffffff);
  47761. // light.position.set(0, -10, 20);
  47762. // light.target.position.set(0, 0, 0);
  47763. // this.scene.add(light);
  47764. // }
  47765. // }
  47766. }
  47767. };
  47768. KeyCodes.BACKSPACE = 8;
  47769. //注意,这时候Potree.js中export的内容还不在Potree变量中
  47770. var texLoader$1 = new TextureLoader();
  47771. texLoader$1.crossOrigin = "anonymous";
  47772. {//defines:
  47773. Potree.defines = {};
  47774. Potree.defines.Buttons = {// MouseEvent.buttons
  47775. //buttons,设置按下了鼠标哪些键,是一个3个比特位的二进制值,默认为0。1表示按下主键(通常是左键),2表示按下次要键(通常是右键),4表示按下辅助键(通常是中间的键)。
  47776. NONE:0,//add
  47777. LEFT: 0b0001,
  47778. RIGHT: 0b0010,
  47779. MIDDLE: 0b0100
  47780. };
  47781. /* 如果访问的是button, 用THREE.MOUSE来判断:
  47782. button,设置按下了哪一个鼠标按键,默认为0。-1表示没有按键,0表示按下主键(通常是左键),1表示按下辅助键(通常是中间的键),2表示按下次要键(通常是右键)
  47783. */
  47784. Potree.browser = browser;
  47785. /////////// add //////////////////////////////////
  47786. Potree.defines.GLCubeFaces = {
  47787. GL_TEXTURE_CUBE_MAP_POSITIVE_X: 0,
  47788. GL_TEXTURE_CUBE_MAP_NEGATIVE_X: 1,
  47789. GL_TEXTURE_CUBE_MAP_POSITIVE_Y: 2,
  47790. GL_TEXTURE_CUBE_MAP_NEGATIVE_Y: 3,
  47791. GL_TEXTURE_CUBE_MAP_POSITIVE_Z: 4,
  47792. GL_TEXTURE_CUBE_MAP_NEGATIVE_Z: 5
  47793. };
  47794. Potree.defines.PanoSizeClass = {
  47795. BASE: 1,
  47796. STANDARD: 2,
  47797. HIGH: 3,
  47798. ULTRAHIGH: 4
  47799. };
  47800. Potree.defines.PanoRendererEvents = {
  47801. PanoRenderComplete: "panorama.render.complete",
  47802. TileRenderFailure: "panorama.tile.render.failed",
  47803. TileRenderSuccess: "panorama.tile.render.success",
  47804. TileUploadAttempted: "panorama.tile.upload.attempted",
  47805. UploadAttemptedForAllTiles: "panorama.upload.attempted.all.tiles",
  47806. ZoomLevelRenderStarted: "panorama.zoom.render.started"
  47807. };
  47808. Potree.defines.SceneRendererEvents = {
  47809. ContextCreated: "scene-renderer-context-created",
  47810. AfterRender: "after-render",
  47811. MemoryUsageUpdated: "scene-renderer-memory-usage-updated"
  47812. };
  47813. Potree.defines.TileDownloaderEvents = {
  47814. TileDownloadSuccess: "tiledownloader.download.success",
  47815. TileDownloadFailure: "tiledownloader.download.failure",
  47816. PanoDownloadComplete: "tiledownloader.pano.download.complete"
  47817. };
  47818. Potree.defines.Vectors = {
  47819. UP: new Vector3(0,1,0),
  47820. DOWN: new Vector3(0,-1,0),
  47821. LEFT: new Vector3(-1,0,0),
  47822. RIGHT: new Vector3(1,0,0),
  47823. FORWARD: new Vector3(0,0,-1),
  47824. BACK: new Vector3(0,0,1)
  47825. };
  47826. /* var Vectors2 = {}
  47827. for(var i in Vectors){
  47828. Vectors2[i] = math.convertVector.YupToZup(Vectors[i])
  47829. }
  47830. */
  47831. Potree.defines.DownloadStatus = Object.freeze({
  47832. None: 0,
  47833. Queued: 1,
  47834. ForceQueued: 2,
  47835. Downloading: 3,
  47836. Downloaded: 4,
  47837. DownloadFailed: 5
  47838. });
  47839. Potree.defines.ModelManagerEvents = {
  47840. ModelAdded: "model-added",
  47841. ActiveModelChanged: "active-model-changed"
  47842. };
  47843. Potree.defines.PanoramaEvents = {
  47844. Enter: 'panorama.enter',
  47845. Exit: 'panorama.exit',
  47846. LoadComplete: "panorama.load.complete",
  47847. LoadFailed: "panorama.load.failed",
  47848. TileLoaded: "panorama.tile.loaded",
  47849. VideoRendered: "panorama.video.rendered"
  47850. };
  47851. ClipTask.SHOW_INSIDE_Big = 4;
  47852. }
  47853. {//Features
  47854. let gl_;
  47855. Features.EXT_DEPTH = {
  47856. isSupported: function (gl) {
  47857. gl = gl || gl_;
  47858. gl_ = gl;
  47859. if(browser.detectIOS()){
  47860. let {major,minor,patch} = browser.iosVersion();
  47861. //console.warn('iosVersion',major,minor,patch)
  47862. if(major == 15 && minor == 4 && patch == 1){
  47863. console.warn('检测到是ios15.4.1, 关闭EXT_frag_depth');//该版本ext_depth有问题,导致clear错乱。没有解决办法先关闭。
  47864. return false
  47865. }
  47866. }
  47867. return (typeof WebGL2RenderingContext != 'undefined' && gl instanceof WebGL2RenderingContext) || gl.getExtension('EXT_frag_depth'); //shader中的GL_EXT_frag_depth需要判断一下detectIOS吗。。
  47868. }
  47869. };
  47870. }
  47871. Utils.loadSkybox = function(path, oldSky, callback ) {
  47872. let camera, scene, parent , cameraOrtho;
  47873. if(!oldSky){
  47874. parent = new Object3D("skybox_root");
  47875. camera = new PerspectiveCamera(75, window.innerWidth / window.innerHeight, 1, 100000);
  47876. cameraOrtho = new OrthographicCamera(-1, 1, 1, -1, Potree.config.view.near, Potree.settings.cameraFar);
  47877. if(!window.axisYup) camera.up.set(0, 0, 1);//add
  47878. scene = new Scene();
  47879. let skyboxBgWidth = Potree.config.skyboxBgWidth;
  47880. let skyGeometry = new BoxBufferGeometry(skyboxBgWidth,skyboxBgWidth,skyboxBgWidth);
  47881. let skybox = new Mesh(skyGeometry, new ShaderMaterial({
  47882. vertexShader: Shaders['skybox.vs'],
  47883. fragmentShader: Shaders['skybox.fs'],
  47884. side: BackSide,
  47885. uniforms:{
  47886. tDiffuse: {
  47887. type: "t",
  47888. value: null
  47889. },
  47890. matrix:{
  47891. type: "m4",
  47892. value: new Matrix4
  47893. }
  47894. },
  47895. depthTest:false,
  47896. depthWrite:false
  47897. }) );
  47898. scene.add(skybox);
  47899. scene.traverse(n => n.frustumCulled = false);
  47900. // z up
  47901. //scene.rotation.x = Math.PI / 2;
  47902. parent.children.push(camera);
  47903. camera.parent = parent;
  47904. }else {
  47905. camera = oldSky.camera,
  47906. scene = oldSky.scene;
  47907. parent = oldSky.parent;
  47908. cameraOrtho = oldSky.cameraOrtho;
  47909. }
  47910. let texture = texLoader$1.load( path, ()=>{
  47911. console.log('loadSkybox成功',path);
  47912. texture.wrapS = RepeatWrapping;
  47913. texture.flipY = false;
  47914. texture.magFilter = LinearFilter;
  47915. texture.minFilter = LinearFilter;
  47916. scene.children[0].material.uniforms.tDiffuse.value = texture;
  47917. callback && callback();
  47918. viewer.dispatchEvent('content_changed');
  47919. },null,(e)=>{//error
  47920. console.error('loadSkybox失败',path);
  47921. });
  47922. return {camera, scene, parent, cameraOrtho};
  47923. };
  47924. Utils.getMousePointCloudIntersection = function(viewport, mouse, pointer, camera, viewer, pointclouds, pickParams = {} ) {
  47925. //getIntersectByDepthTex
  47926. /* let result = viewer.edlRenderer.depthTexSampler.sample(viewport, mouse)//add
  47927. if(result != 'unsupport')return result
  47928. */
  47929. if(!pointclouds || pointclouds.length == 0)return
  47930. //console.log('getMousePointCloudIntersection')
  47931. let renderer = viewer.renderer;
  47932. if(viewport){ //转换到类似整个画面时
  47933. /*let mouseInViewport = Utils.convertNDCToScreenPosition(pointer, null, viewport.resolution.x, viewport.resolution.y)
  47934. pickParams.x = mouseInViewport.x //mouse.x / viewport.width;
  47935. pickParams.y = mouseInViewport.y //renderer.domElement.clientHeight - mouse.y / viewport.height; */
  47936. pickParams.x = mouse.x;
  47937. pickParams.y = viewport.resolution.y - mouse.y;
  47938. }else {
  47939. pickParams.x = mouse.x;
  47940. pickParams.y = renderer.domElement.clientHeight - mouse.y;
  47941. }
  47942. //console.log('getMousePointCloudIntersection')
  47943. /* if(!raycaster){
  47944. raycaster = new THREE.Raycaster();
  47945. raycaster.setFromCamera(pointer, camera);
  47946. } */
  47947. let raycaster = new Raycaster();
  47948. raycaster.setFromCamera(pointer, camera);
  47949. let ray = raycaster.ray;
  47950. let selectedPointcloud = null;
  47951. let closestDistance = Infinity;
  47952. let closestIntersection = null;
  47953. let closestPoint = null;
  47954. //-----------add--------------------
  47955. let old_clipBoxes_in = new Map();
  47956. let old_clipBoxes_out = new Map();
  47957. let old_bigClipInBox = new Map();
  47958. let old_highlightBoxes = new Map();
  47959. let old_visibleNodes = new Map();
  47960. //bigClipInBox 最好也写下
  47961. let density;
  47962. let sizeType;
  47963. let size = new Map();
  47964. let visiMap = new Map();
  47965. let needsUpdate = false;
  47966. if(pickParams.measuring || Potree.settings.displayMode == 'showPanos') { //测量或无深度图时的全景模式提高精准度. (全景模式有深度图时不会执行到这)
  47967. density = Potree.settings.pointDensity;
  47968. Potree.settings.pointDensity = 'magnifier'; //加载最高level
  47969. pointclouds.forEach(e=>{//因为全景模式的pointSizeType是fixed所以要还原下
  47970. visiMap.set(e,e.visible);
  47971. e.visible = Potree.Utils.getObjVisiByReason(e, 'datasetSelection'); //先将隐藏的点云显示
  47972. if(!e.visible)return
  47973. size.set(e, e.temp.pointSize);
  47974. sizeType = e.material.pointSizeType;
  47975. e.material.pointSizeType = Potree.config.material.pointSizeType;
  47976. //e.changePointSize(Potree.config.material.realPointSize*2, true)//更改点云大小到能铺满为止,否则容易识别不到
  47977. });
  47978. needsUpdate = true;
  47979. }else {
  47980. if(viewer.viewports.filter(e=>!e.noPointcloud && e.active).length>1 || pickParams.cameraChanged){//在pick时相机和渲染时不一样的话
  47981. viewport.beforeRender && viewport.beforeRender();
  47982. needsUpdate = true; //不updatePointClouds的话hover久了会不准 因node是错的
  47983. //但依旧需要camera真的移动到那个位置才能加载出点云
  47984. }
  47985. }
  47986. if(!pickParams.pickClipped){// 无视clipBoxes
  47987. for(let pointcloud of pointclouds){
  47988. old_clipBoxes_in.set(pointcloud, pointcloud.clipBoxes_in);
  47989. old_clipBoxes_out.set(pointcloud, pointcloud.clipBoxes_out);
  47990. old_bigClipInBox.set(pointcloud, pointcloud.bigClipInBox);
  47991. old_highlightBoxes.set(pointcloud, pointcloud.highlightBoxes);
  47992. pointcloud.material.setClipBoxes(null, [],[],[]);
  47993. }
  47994. needsUpdate = true;
  47995. }
  47996. if(needsUpdate) {
  47997. for(let pointcloud of pointclouds){
  47998. old_visibleNodes.set(pointcloud, pointcloud.visibleNodes);
  47999. }
  48000. if(window.notViewOffset){
  48001. Potree.updatePointClouds(pointclouds, camera, viewport.resolution );
  48002. }else {
  48003. //尽量减少点云加载的范围,集中在pick的空间(这部分以外还是会加载一些散点的)
  48004. let viewWidth = 80; //viewer.magnifier ? viewer.magnifier.viewport.resolution.x : 200
  48005. let camera_ = camera.clone();
  48006. camera_.setViewOffset( viewport.resolution.x, viewport.resolution.y, pickParams.x-viewWidth/2, (viewport.resolution.y - pickParams.y)-viewWidth/2, viewWidth, viewWidth ); //注意offsetY是从上到下,和一般的不同
  48007. Potree.updatePointClouds(pointclouds, camera_, viewport.resolution );
  48008. }
  48009. }
  48010. //------------------------------------------------
  48011. let allPointclouds = [];
  48012. for(let pointcloud of pointclouds){
  48013. let point = pointcloud.pick(viewer, viewport, camera, ray, pickParams );
  48014. if(!point){
  48015. continue;
  48016. }
  48017. allPointclouds.push(pointcloud);
  48018. let distance = camera.position.distanceTo(point.position);
  48019. if (distance < closestDistance) {
  48020. closestDistance = distance;
  48021. selectedPointcloud = pointcloud;
  48022. closestIntersection = point.position;
  48023. closestPoint = point;
  48024. }
  48025. }
  48026. //恢复
  48027. if(pickParams.measuring || Potree.settings.displayMode == 'showPanos'){
  48028. Potree.settings.pointDensity = density;
  48029. pointclouds.forEach(e=>{
  48030. if(e.visible){
  48031. e.material.pointSizeType = sizeType;
  48032. //e.changePointSize(size.get(e))
  48033. }
  48034. e.visible = visiMap.get(e);
  48035. });
  48036. }else {
  48037. /* if(viewer.viewports.filter(e=>!e.noPointcloud).length>1){
  48038. viewport.afterRender && viewport.afterRender()
  48039. } */
  48040. }
  48041. if(!pickParams.pickClipped){//add
  48042. for(let pointcloud of pointclouds){
  48043. pointcloud.material.setClipBoxes(old_bigClipInBox.get(pointcloud), old_clipBoxes_in.get(pointcloud), old_clipBoxes_out.get(pointcloud), old_highlightBoxes.get(pointcloud));
  48044. }
  48045. }
  48046. if(needsUpdate){
  48047. for(let pointcloud of pointclouds){ //不恢复的话(尤其cameraChanged时),在下次render前,再次pick可能是错的。表现为多数据集刚开始reticule消失了,直到ifPointBlockedByIntersect停止
  48048. pointcloud.visibleNodes = old_visibleNodes.get(pointcloud);
  48049. }
  48050. }
  48051. if (selectedPointcloud) {
  48052. return {
  48053. location: closestIntersection,
  48054. distance: closestDistance,
  48055. pointcloud: selectedPointcloud,
  48056. point: closestPoint,
  48057. pointclouds: allPointclouds, //add
  48058. normal: closestPoint.normal && new Vector3().fromArray(closestPoint.normal ).applyMatrix4(selectedPointcloud.rotateMatrix)//add
  48059. };
  48060. } else {
  48061. return null;
  48062. }
  48063. };
  48064. Utils.pixelsArrayToDataUrl = function(pixels, width, height, compressRatio = 0.7) {
  48065. let canvas = document.createElement('canvas');
  48066. canvas.width = width;
  48067. canvas.height = height;
  48068. let context = canvas.getContext('2d');
  48069. pixels = new pixels.constructor(pixels);
  48070. /* for (let i = 0; i < pixels.length; i++) {
  48071. pixels[i * 4 + 3] = 255;
  48072. } */
  48073. // flip vertically
  48074. let bytesPerLine = width * 4;
  48075. for(let i = 0; i < parseInt(height / 2); i++){
  48076. let j = height - i - 1;
  48077. let lineI = pixels.slice(i * bytesPerLine, i * bytesPerLine + bytesPerLine);
  48078. let lineJ = pixels.slice(j * bytesPerLine, j * bytesPerLine + bytesPerLine);
  48079. pixels.set(lineJ, i * bytesPerLine);
  48080. pixels.set(lineI, j * bytesPerLine);
  48081. }
  48082. let imageData = context.createImageData(width, height);
  48083. imageData.data.set(pixels);
  48084. context.putImageData(imageData, 0, 0);
  48085. let dataURL = canvas.toDataURL(compressRatio);
  48086. return dataURL;
  48087. };
  48088. Utils.renderTargetToDataUrl = function(renderTarget, width, height, renderer, compressRatio = 0.7){
  48089. let pixelCount = width * height;
  48090. let buffer = new Uint8Array(4 * pixelCount);
  48091. renderer.readRenderTargetPixels(renderTarget, 0, 0, width, height, buffer);
  48092. var dataUrl = Utils.pixelsArrayToDataUrl(buffer, width, height, compressRatio);
  48093. return dataUrl
  48094. };
  48095. Utils.mouseToRay = function(pointer, camera ){
  48096. let vector = new Vector3(pointer.x, pointer.y, 1);
  48097. let origin = new Vector3(pointer.x, pointer.y, -1); //不能用camera.position,在orbitCamera时不准
  48098. vector.unproject(camera);
  48099. origin.unproject(camera);
  48100. let direction = new Vector3().subVectors(vector, origin).normalize();
  48101. let ray = new Ray(origin, direction);
  48102. return ray;
  48103. };
  48104. Utils.getPos2d = function(point, viewport , dom, renderer ){//获取一个三维坐标对应屏幕中的二维坐标
  48105. var pos;
  48106. if(math.closeTo(viewport.camera.position, point, 1e-5) ){ //和相机位置重合时显示会四处飘,看是要改成一直显示中间还是隐藏?
  48107. pos = new Vector3(0,0,1.5); //1.5是为了不可见
  48108. }else {
  48109. 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);
  48110. }
  48111. let size = renderer && renderer.getSize(new Vector2); //如果是渲染到renderTarget上,resolution和dom的大小不一致。如果输出的结果给前端2d用,就使用clinetWidth,如果自己场景用,用renderer.size
  48112. let w = renderer ? size.x : dom.clientWidth;
  48113. let h = renderer ? size.y : dom.clientHeight;
  48114. var x,y,left,top;
  48115. x = (pos.x + 1) / 2 * w * viewport.width;
  48116. y = (1 - (pos.y + 1) / 2) * h * viewport.height;
  48117. left = viewport.left * w;
  48118. top = (1- viewport.bottom - viewport.height) * h;
  48119. var inSight = pos.x <= 1 && pos.x >= -1 //是否在屏幕中
  48120. && pos.x <= 1 && pos.y >= -1;
  48121. return {
  48122. pos: new Vector2(left+x,top+y) ,// 屏幕像素坐标
  48123. vector: pos, //(范围 -1 ~ 1)
  48124. trueSide : pos.z<1, //trueSide为false时,即使在屏幕范围内可见,也是反方向的另一个不可以被渲染的点 参见Tag.update
  48125. inSight : inSight, //在屏幕范围内可见,
  48126. posInViewport: new Vector2(x,y),
  48127. };
  48128. };
  48129. Utils.screenPass = new function () {
  48130. this.screenScene = new Scene();
  48131. this.screenQuad = new Mesh(new PlaneBufferGeometry(2, 2, 1));
  48132. this.screenQuad.material.depthTest = true;
  48133. this.screenQuad.material.depthWrite = true;
  48134. this.screenQuad.material.transparent = true;
  48135. this.screenScene.add(this.screenQuad);
  48136. this.camera = new Camera();
  48137. this.render = function (renderer, material, target, composer) {
  48138. this.screenQuad.material = material;
  48139. if (typeof target === 'undefined') {
  48140. (composer || renderer).render(this.screenScene, this.camera);
  48141. } else {
  48142. let oldTarget = renderer.getRenderTarget();
  48143. renderer.setRenderTarget(target);
  48144. //renderer.clear(); //有时候不能clear,如renderBG后再
  48145. (composer || renderer).render(this.screenScene, this.camera);
  48146. renderer.setRenderTarget(oldTarget);
  48147. }
  48148. };
  48149. }();
  48150. //add
  48151. Utils.computePointcloudsBound = function(pointclouds){
  48152. var boundingBox = new Box3();
  48153. pointclouds.forEach(pointcloud=>{
  48154. pointcloud.updateBound();
  48155. boundingBox.union(pointcloud.bound2);
  48156. });
  48157. var boundSize = boundingBox.getSize(new Vector3);
  48158. var center = boundingBox.getCenter(new Vector3);
  48159. return {boundSize, center, boundingBox}
  48160. };
  48161. Utils.convertScreenPositionToNDC = function(pointer, mouse, width, height) {
  48162. return pointer = pointer || new Vector2,
  48163. pointer.x = mouse.x / width * 2 - 1,
  48164. pointer.y = 2 * -(mouse.y / height) + 1,
  48165. pointer
  48166. };
  48167. Utils.convertNDCToScreenPosition = function(pointer, mouse, width, height) {
  48168. return mouse = mouse || new Vector2,
  48169. mouse.x = Math.round((pointer.x + 1 ) / 2 * width),
  48170. mouse.y = Math.round(-(pointer.y - 1 ) / 2 * height),
  48171. mouse
  48172. };
  48173. Utils.getOrthoCameraMoveVec = function(pointerDelta, camera ){//获取当camera为Ortho型时 屏幕点1 到 屏幕点2 的三维距离
  48174. let cameraViewWidth = camera.right / camera.zoom;
  48175. let cameraViewHeight = camera.top / camera.zoom;
  48176. let moveVec = new Vector3;
  48177. moveVec.set( pointerDelta.x * cameraViewWidth , pointerDelta.y * cameraViewHeight , 0).applyQuaternion(camera.quaternion);
  48178. return moveVec
  48179. };
  48180. Utils.VectorFactory = {
  48181. fromArray : function(t) {
  48182. if (t) {
  48183. if (t.length < 2 || t.length > 3)
  48184. console.error("Wrong number of ordinates for a point!");
  48185. return 3 === t.length ? (new Vector3).fromArray(t) : (new Vector2).fromArray(t)
  48186. }
  48187. },
  48188. fromArray3 : function(t) {
  48189. if (t) {
  48190. if (3 !== t.length)
  48191. console.error("Wrong number of ordinates for a point!");
  48192. return (new Vector3).fromArray(t)
  48193. }
  48194. },
  48195. fromArray2 : function(t) {
  48196. if (t) {
  48197. if (2 !== t.length)
  48198. console.error("Wrong number of ordinates for a point!");
  48199. return (new Vector2).fromArray(t)
  48200. }
  48201. },
  48202. toString : function(t) {
  48203. return t.x.toFixed(8) + "," + t.y.toFixed(8) + "," + t.z.toFixed(3)
  48204. }
  48205. };
  48206. Utils.QuaternionFactory = {
  48207. rot90 : (new Quaternion).setFromAxisAngle(new Vector3(0,0,1), MathUtils.degToRad(-90)),
  48208. fromArray : function(t) {
  48209. if (t) {
  48210. if (4 !== t.length)
  48211. console.error("Wrong number of ordinates for a quaternion!");
  48212. return new Quaternion(t[1],t[2],t[3],t[0]).multiply(this.rot90)
  48213. }
  48214. }
  48215. ,
  48216. toArray : function(t) {
  48217. if (t) {
  48218. var e = t.clone().multiply(a).toArray();
  48219. return [e[3], e[0], e[1], e[2]]
  48220. }
  48221. }
  48222. ,
  48223. fromLonLat : function(t) {
  48224. if (t)
  48225. return (new Quaternion).setFromEuler(new Euler(t.lon,t.lat,0))
  48226. }
  48227. ,
  48228. toLonLat : function(t) {
  48229. if (t) {
  48230. var e = (new Euler).setFromQuaternion(t);
  48231. return {
  48232. lon: e.x,
  48233. lat: e.y
  48234. }
  48235. }
  48236. }
  48237. };
  48238. Utils.datasetPosTransform = function(o={}){
  48239. let pointcloud = o.pointcloud || viewer.scene.pointclouds.find(e=>e.dataset_id == o.datasetId);
  48240. let tranMatrix;
  48241. if(pointcloud){
  48242. if(Potree.settings.editType == 'merge'){
  48243. tranMatrix = o.fromDataset ? pointcloud.matrixWorld : new Matrix4().copy(pointcloud.matrixWorld).invert();
  48244. }else {
  48245. tranMatrix = o.fromDataset ? pointcloud.transformMatrix : pointcloud.transformInvMatrix;
  48246. }
  48247. }else {
  48248. if(Potree.settings.intersectOnObjs){
  48249. let object = o.object || viewer.objs.children.find(e=>e.dataset_id == o.datasetId);
  48250. if(object){
  48251. tranMatrix = o.fromDataset ? object.matrixWorld : new Matrix4().copy(object.matrixWorld).invert();
  48252. }
  48253. }
  48254. }
  48255. if(tranMatrix){
  48256. return (new Vector3).copy(o.position).applyMatrix4(tranMatrix)
  48257. }else {
  48258. if(o.datasetId != void 0){
  48259. console.error(`datasetPosTransform找不到datasetId为${o.datasetId}的数据集或模型,请检查数据, 模型未创建或删除`);
  48260. //很可能是旧的热点,需要删除
  48261. }
  48262. }
  48263. };
  48264. Utils.datasetRotTransform = function(o={}){
  48265. let pointcloud = o.pointcloud || viewer.scene.pointclouds.find(e=>e.dataset_id == o.datasetId);
  48266. if(pointcloud){
  48267. var matrix, newMatrix, result;
  48268. if(o.rotation){
  48269. matrix = new Matrix4().makeRotationFromEuler(o.rotation);
  48270. }else if(o.quaternion){
  48271. matrix = new Matrix4().makeRotationFromQuaternion(o.quaternion);
  48272. }else if(o.matrix){
  48273. matrix = o.matrix.clone();
  48274. }else {
  48275. return
  48276. }
  48277. let rotateMatrix = o.fromDataset ? pointcloud.rotateMatrix : pointcloud.rotateInvMatrix;
  48278. newMatrix = new Matrix4().multiplyMatrices(rotateMatrix, matrix );
  48279. if(o.getRotation){
  48280. result = new Euler().setFromRotationMatrix(newMatrix);
  48281. }else if(o.getQuaternion){
  48282. result = new Quaternion().setFromRotationMatrix(newMatrix);
  48283. }else if(o.getMatrix){
  48284. result = newMatrix;
  48285. }
  48286. return result
  48287. }
  48288. };
  48289. Utils.isInsideFrustum = function(bounding, camera){// bounding是否在视野范围内有可见部分(视野就是一个锥状box)
  48290. let frustumMatrix = new Matrix4;
  48291. frustumMatrix.multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse);
  48292. let frustum = new Frustum();
  48293. frustum.setFromProjectionMatrix(frustumMatrix);
  48294. if(bounding instanceof Sphere){
  48295. return frustum.intersectsSphere(bounding)
  48296. }else {
  48297. return frustum.intersectsBox(bounding)
  48298. }
  48299. };
  48300. Utils.isIntersectBox = function(object, boxMatrix){//object是否有在box中的部分。 object可以是点或者bounding, box原为1*1*1,但可能形变
  48301. //let frustum = new THREE.Frustum();
  48302. //frustum.setFromProjectionMatrix(boxMatrixInverse) --错
  48303. let px = new Vector3(+0.5, 0, 0).applyMatrix4(boxMatrix);
  48304. let nx = new Vector3(-0.5, 0, 0).applyMatrix4(boxMatrix);
  48305. let py = new Vector3(0, +0.5, 0).applyMatrix4(boxMatrix);
  48306. let ny = new Vector3(0, -0.5, 0).applyMatrix4(boxMatrix);
  48307. let pz = new Vector3(0, 0, +0.5).applyMatrix4(boxMatrix);
  48308. let nz = new Vector3(0, 0, -0.5).applyMatrix4(boxMatrix);
  48309. let pxN = new Vector3().subVectors(nx, px).normalize();
  48310. let nxN = pxN.clone().multiplyScalar(-1);
  48311. let pyN = new Vector3().subVectors(ny, py).normalize();
  48312. let nyN = pyN.clone().multiplyScalar(-1);
  48313. let pzN = new Vector3().subVectors(nz, pz).normalize();
  48314. let nzN = pzN.clone().multiplyScalar(-1);
  48315. let pxPlane = new Plane().setFromNormalAndCoplanarPoint(pxN, px);
  48316. let nxPlane = new Plane().setFromNormalAndCoplanarPoint(nxN, nx);
  48317. let pyPlane = new Plane().setFromNormalAndCoplanarPoint(pyN, py);
  48318. let nyPlane = new Plane().setFromNormalAndCoplanarPoint(nyN, ny);
  48319. let pzPlane = new Plane().setFromNormalAndCoplanarPoint(pzN, pz);
  48320. let nzPlane = new Plane().setFromNormalAndCoplanarPoint(nzN, nz);
  48321. let frustum = new Frustum(pxPlane, nxPlane, pyPlane, nyPlane, pzPlane, nzPlane);
  48322. if(object instanceof Box3){
  48323. var boxBound = new Box3(
  48324. new Vector3(-0.5,-0.5,-0.5), new Vector3(0.5,0.5,0.5),
  48325. ).applyMatrix4(boxMatrix); //large boundingbox
  48326. if(!object.intersectsBox(boxBound))return
  48327. return frustum.intersectsBox(object) //根据该函数, 若存在某个plane在box上的对应点都在plane背面,则不相交. 可得知在box构成的frustum倾斜时不准确,不相交也判断为相交,甚至不如bound相交准确。所以前面加步骤排除下,但仍不完全准确。(可在裁剪中将box放置到数据集上方旋转下校验)
  48328. }else if(object instanceof Array){//点合集, 只能粗略计算下
  48329. let sphere = new Sphere();
  48330. sphere.setFromPoints(object);
  48331. return this.isIntersectBox(sphere, boxMatrix)
  48332. }else if(object instanceof Sphere){
  48333. return frustum.intersectsSphere(object)
  48334. }else if(object instanceof Vector3){
  48335. return frustum.containsPoint(object)
  48336. }else if(object instanceof Matrix4){//第一个参数如果和第二个参数一样都是box的worldMatrix
  48337. }
  48338. /* containsPoint: ƒ containsPoint( point )
  48339. intersectsBox: ƒ intersectsBox( box )
  48340. intersectsObject: ƒ intersectsObject( object )//geo
  48341. intersectsSphere: ƒ intersectsSphere( sphere )
  48342. intersectsSprite: ƒ intersectsSprite( sprite )
  48343. */
  48344. };
  48345. Utils.getIntersect = function (camera, meshes, pointer, raycaster) {
  48346. //获取鼠标和meshes交点
  48347. if(!raycaster){//getMouseIntersect
  48348. camera.updateMatrixWorld();
  48349. raycaster = new Raycaster();
  48350. var origin = new Vector3(pointer.x, pointer.y, -1).unproject(camera),
  48351. end = new Vector3(pointer.x, pointer.y, 1).unproject(camera);
  48352. var dir = end.sub(origin).normalize();
  48353. raycaster.set(origin, dir);
  48354. }
  48355. meshes.forEach(e=>{
  48356. raycaster.layers.enable(math.getBaseLog(2,e.layers.mask));
  48357. });
  48358. var n = raycaster.intersectObjects(meshes);
  48359. if (0 === n.length) return null
  48360. return n[0]
  48361. };
  48362. Utils.addOrRemoveDefine = function(material, defineName, type, value=''){
  48363. let defines = material.defines;
  48364. if(type == 'add'){
  48365. if(defines[defineName] != void 0 && defines[defineName] == value)return
  48366. defines[defineName] = value;
  48367. }else {
  48368. if(defines[defineName] != void 0)return;
  48369. delete defines[defineName];
  48370. }
  48371. material.needsUpdate = true;
  48372. };
  48373. Utils.makeTexDontResize = function(map){//避免贴图因非2的次方而缩小。小心使用
  48374. if(!map || !map.image){
  48375. return console.log('!map || !map.image', map, map&&map.image)
  48376. }
  48377. if(MathUtils.isPowerOfTwo(map.image.width ) && MathUtils.isPowerOfTwo(map.image.height ))return
  48378. map.wrapS = map.wrapT = ClampToEdgeWrapping; //原默认 RepeatWrapping
  48379. map.minFilter = LinearFilter; // or THREE.NearestFilter 原默认 LinearMipmapLinearFilter
  48380. map.generateMipmaps = false;
  48381. map.needsUpdate = true;
  48382. };
  48383. Utils.updateVisible = function(object, reason, ifShow, level=0, type){//当所有加入的条件都不为false时才显示. reason='force'一般是强制、临时的
  48384. if(!object.unvisibleReasons) object.unvisibleReasons = []; //如果length>0代表不可见
  48385. if(!object.visibleReasons) object.visibleReasons = []; //在同级时,优先可见
  48386. var update = function(){
  48387. //先按从高到低的level排列
  48388. object.unvisibleReasons = object.unvisibleReasons.sort((a,b)=>b.level-a.level);
  48389. object.visibleReasons = object.visibleReasons.sort((a,b)=>b.level-a.level);
  48390. var maxVisiLevel = object.visibleReasons[0] ? object.visibleReasons[0].level : -1;
  48391. var maxunVisiLevel = object.unvisibleReasons[0] ? object.unvisibleReasons[0].level : -1;
  48392. var shouldVisi = maxVisiLevel >= maxunVisiLevel;
  48393. var visiBefore = object.visible;
  48394. if(visiBefore != shouldVisi){
  48395. object.visible = shouldVisi;
  48396. object.dispatchEvent({
  48397. type: 'isVisible',
  48398. visible: shouldVisi,
  48399. reason,
  48400. });
  48401. }
  48402. };
  48403. if(ifShow){
  48404. var index = object.unvisibleReasons.findIndex(e=>e.reason == reason);
  48405. if(index > -1){
  48406. type = 'cancel';
  48407. object.unvisibleReasons.splice(index, 1);
  48408. }
  48409. if(type == 'add' ){
  48410. if(!object.visibleReasons.some(e=>e.reason == reason)){
  48411. object.visibleReasons.push({reason,level});
  48412. }
  48413. }
  48414. }else {
  48415. var index = object.visibleReasons.findIndex(e=>e.reason == reason);
  48416. if(index > -1){
  48417. type = 'cancel';
  48418. object.visibleReasons.splice(index, 1);
  48419. }
  48420. if(type != 'cancel' ){
  48421. if(!object.unvisibleReasons.some(e=>e.reason == reason)){
  48422. object.unvisibleReasons.push({reason,level});
  48423. }
  48424. }
  48425. }
  48426. update();
  48427. };
  48428. /*
  48429. 复杂案例: 如果物体默认隐藏, 当符合任何一个其他条件时可见,则可:
  48430. Potree.Utils.updateVisible(this, "default", false, 0 ) //默认隐藏
  48431. Potree.Utils.updateVisible(this, 条件名, ifShow, 1, ifShow?'add':'cancel' ) //其他的条件
  48432. */
  48433. Utils.getObjVisiByReason = function(object,reason){//获取在某条件下是否可见. 注: 用户在数据集选择可不可见为"datasetSelection"
  48434. if(object.visible)return true
  48435. else {
  48436. return !object.unvisibleReasons || !object.unvisibleReasons.some(e=>e.reason == reason)
  48437. }
  48438. };
  48439. Utils.setCameraLayers = function(camera, enableLayers, extraEnableLayers=[]){//add
  48440. camera.layers.disableAll();
  48441. enableLayers.concat(extraEnableLayers).forEach(e=>{
  48442. let layer = Potree.config.renderLayers[e];
  48443. if(layer == void 0){
  48444. console.error('setCameraLayer没找到layer!');
  48445. return
  48446. }
  48447. camera.layers.enable(layer);
  48448. });
  48449. };
  48450. Utils.setObjectLayers = function(object, layerName){//add
  48451. let layer = Potree.config.renderLayers[layerName];
  48452. if(layer == void 0){
  48453. console.error('setObjectLayers没找到layer!',layerName);
  48454. return
  48455. }
  48456. object.traverse(e=>{
  48457. e.layers.set(layer);
  48458. });
  48459. };
  48460. Utils.imgAddText = async (img, text, labelInfo)=>{
  48461. let label = new Potree.TextSprite(Object.assign({//如果直接在canvas里写字,要另外写很多和canvas.drawText有关的,所以还是借助textSprite吧
  48462. backgroundColor: { r: 0, g: 0, b: 0, a: 0 },
  48463. textColor: { r: 255, g: 255, b: 255, a: 1 },
  48464. margin:{x:3,y:3},
  48465. renderOrder: 50, fontsize : 20,
  48466. text,
  48467. },labelInfo));
  48468. let labelImg = new Image;
  48469. labelImg.src = label.sprite.material.map.image.toDataURL('image/png');
  48470. return new Promise((resolve,reject)=>{
  48471. labelImg.onload = ()=>{
  48472. if(labelInfo.horizonCenter){//水平居中(对img来说)
  48473. labelInfo.leftRatioToImg = 0.5 - (labelImg.width / img.width)/2;
  48474. }
  48475. let result = Common.imgAddLabel(img,labelImg,labelInfo);
  48476. label.dispose();
  48477. resolve(result);
  48478. };
  48479. })
  48480. };
  48481. Utils.combineImgs = async (imgs, compressRatio, width, height)=>{//拼合图片,顺序从上到下从左到右, 每张图大小不一定一致,但同列的宽一致,同行宽一致
  48482. return new Promise((resolve,reject)=>{
  48483. let item = imgs[0][0];
  48484. let wc=imgs.length, hc=imgs[0].length, loadCount = 0, amount = wc * hc;
  48485. width = width || imgs.reduce((w,c)=>w + c[0].width, 0), //相加得到的可能比想要得到的大几个像素,之后会重叠
  48486. height = height || imgs[0].reduce((w,c)=>w + c.height, 0);
  48487. let canvas = document.createElement('canvas');
  48488. canvas.width = width;
  48489. canvas.height = height;
  48490. let context = canvas.getContext('2d');
  48491. for(let i=0;i<wc;i++){
  48492. for(let j=0;j<hc;j++){
  48493. let img = new Image;
  48494. img.src = imgs[i][j].dataUrl;
  48495. img.index = {i,j};
  48496. img.onload = ()=>{
  48497. loadCount++;
  48498. context.drawImage(img, img.index.i * img.width, img.index.j * img.height, img.width, img.height);
  48499. if(loadCount == amount){
  48500. var dataUrl = canvas.toDataURL('image/png',compressRatio);
  48501. context.clearRect(0,0,width,height);
  48502. resolve(dataUrl);
  48503. }
  48504. };
  48505. }
  48506. }
  48507. })
  48508. };
  48509. BinaryLoader.prototype.load = function(node, callback){//解析点云
  48510. if (node.loaded) {
  48511. return;
  48512. }
  48513. let url = node.getURL();
  48514. if (this.version.equalOrHigher('1.4')) {
  48515. url += '.bin';
  48516. }
  48517. url += '?m='+node.pcoGeometry.timeStamp; //add
  48518. let xhr = XHRFactory.createXMLHttpRequest();
  48519. xhr.open('GET', url, true);
  48520. xhr.responseType = 'arraybuffer';
  48521. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  48522. xhr.onreadystatechange = () => {
  48523. if (xhr.readyState === 4) {
  48524. if((xhr.status === 200 || xhr.status === 0) && xhr.response !== null){
  48525. let buffer = xhr.response;
  48526. this.parse(node, buffer, callback);
  48527. } else {
  48528. node.loadFailed = 'status:'+xhr.status+",url:"+url;
  48529. Potree.numNodesLoading--;
  48530. //console.error(`Failed to load file! HTTP status: ${xhr.status}, file: ${url}`);
  48531. throw new Error(`Failed to load file! HTTP status: ${xhr.status}, file: ${url}`);
  48532. }
  48533. }
  48534. };
  48535. try {
  48536. xhr.send(null);
  48537. } catch (e) {
  48538. node.loadFailed = 'catchError';
  48539. Potree.numNodesLoading--;
  48540. console.error('加载点云node出错 ', url, e );
  48541. }
  48542. };
  48543. PointAttribute.RGBA_PACKED = new PointAttribute("rgba", PointAttributeTypes.DATA_TYPE_INT8, 4);
  48544. PointAttribute.COLOR_PACKED = PointAttribute.RGBA_PACKED;
  48545. PointAttribute.INTENSITY = new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1);
  48546. PointAttribute.CLASSIFICATION = new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1);
  48547. PointAttribute.GPS_TIME = new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1);
  48548. ProfileWindow.prototype.initTHREE = function(){
  48549. this.renderer = new WebGLRenderer({alpha: true, premultipliedAlpha: false});
  48550. this.renderer.setClearColor(0x000000, 0);
  48551. this.renderer.setSize(10, 10);
  48552. this.renderer.autoClear = false;
  48553. this.renderArea.append($(this.renderer.domElement));
  48554. this.renderer.domElement.tabIndex = '2222';
  48555. $(this.renderer.domElement).css('width', '100%');
  48556. $(this.renderer.domElement).css('height', '100%');
  48557. {
  48558. let gl = this.renderer.getContext();
  48559. if(gl.createVertexArray == null){
  48560. let extVAO = gl.getExtension('OES_vertex_array_object');
  48561. if(!extVAO){
  48562. throw new Error("OES_vertex_array_object extension not supported");
  48563. }
  48564. gl.createVertexArray = extVAO.createVertexArrayOES.bind(extVAO);
  48565. gl.bindVertexArray = extVAO.bindVertexArrayOES.bind(extVAO);
  48566. }
  48567. }
  48568. this.camera = new OrthographicCamera(-1000, 1000, 1000, -1000, -1000, 1000);
  48569. this.camera.up.set(0, 0, 1);
  48570. this.camera.rotation.order = "ZXY";
  48571. this.camera.rotation.x = Math.PI / 2.0;
  48572. this.scene = new Scene();
  48573. this.profileScene = new Scene();
  48574. let sg = new SphereGeometry(1, 16, 16);
  48575. let sm = new MeshNormalMaterial();
  48576. this.pickSphere = new Mesh(sg, sm);
  48577. this.scene.add(this.pickSphere);
  48578. this.viewerPickSphere = new Mesh(sg, sm);
  48579. };
  48580. //Potree_update_visibility
  48581. Potree.updatePointClouds = function(pointclouds,camera, areaSize ){
  48582. viewer.addTimeMark('updateClouds','start');
  48583. for (let pointcloud of pointclouds) {
  48584. let start = performance.now();
  48585. for (let profileRequest of pointcloud.profileRequests) {
  48586. profileRequest.update();
  48587. let duration = performance.now() - start;
  48588. if(duration > 5){
  48589. break;
  48590. }
  48591. }
  48592. let duration = performance.now() - start;
  48593. }
  48594. let result = Potree.updateVisibility(pointclouds, camera, areaSize );
  48595. for (let pointcloud of pointclouds) {
  48596. //pointcloud.updateMaterial(pointcloud.material, pointcloud.visibleNodes, camera, renderer);//转移到渲染时
  48597. pointcloud.updateVisibleBounds();
  48598. }
  48599. Potree.lru.freeMemory();//即Potree.lru 能看到所有在加载的node
  48600. viewer.addTimeMark('updateClouds','end');
  48601. return result;
  48602. };
  48603. Potree.updateVisibilityStructures = function(pointclouds, camera, areaSize) {
  48604. let frustums = {};
  48605. let camObjPositions = {};
  48606. let camObjDirs = {}; //add
  48607. let priorityQueue = new BinaryHeap(function (x) { return -x.weight /* 1 / x.weight; */ });//二叉堆。 改,之前的weight不支持负数
  48608. viewer.addTimeMark('visiStructure','start');
  48609. //camera.updateMatrixWorld();
  48610. let viewI = camera.matrixWorldInverse;
  48611. let proj = camera.projectionMatrix;
  48612. let view = camera.matrixWorld;
  48613. let projViewI = new Matrix4().multiply(proj).multiply(viewI);
  48614. /* let list = pointclouds // stopWhenAllUsed = !viewer.lastFrameChanged
  48615. let min = 5, max = Math.max(20 , Math.round(list.length / 10 ))
  48616. let result = Common.batchHandling.getSlice('pcGetFrustum', list, { min,max, durBound1: 3, durBound2: 10} ) //iphonex稳定后大概在7-10。
  48617. */
  48618. for (let i = 0; i < pointclouds.length; i++) {
  48619. let pointcloud = pointclouds[i];
  48620. if (!pointcloud.initialized()) {
  48621. continue;
  48622. }
  48623. /* let info = history.get(pointcloud)
  48624. if() */
  48625. pointcloud.numVisibleNodes = 0;
  48626. pointcloud.numVisiblePoints = 0;
  48627. pointcloud.deepestVisibleLevel = 0;
  48628. pointcloud.visibleNodes = [];
  48629. pointcloud.visibleGeometry = [];
  48630. // 因漫游模式而隐藏的话 依旧需要加入visibleNodes,因为pick需要
  48631. /* if (pointcloud.visible && pointcloud.root !== null) {
  48632. priorityQueue.push({pointcloud: i, node: pointcloud.root, weight: Number.MAX_VALUE});
  48633. } */
  48634. if (pointcloud.visible || !pointcloud.hasDepthTex && pointcloud.unvisibleReasons && pointcloud.unvisibleReasons.length == 1 && pointcloud.unvisibleReasons[0].reason == 'displayMode' && pointcloud.root !== null) {//改 visible ->
  48635. priorityQueue.push({pointcloud: i, node: pointcloud.root, weight: Number.MAX_VALUE});
  48636. }else {
  48637. continue
  48638. }
  48639. // frustum in object space
  48640. let frustum = new Frustum();
  48641. let world = pointcloud.matrixWorld;
  48642. // use close near plane for frustum intersection
  48643. /* let frustumCam = camera.clone();
  48644. frustumCam.zoom = camera.zoom //add
  48645. frustumCam.near = Math.min(camera.near, 0.1);
  48646. frustumCam.updateProjectionMatrix(); */ //----没用到frustumCam,删了
  48647. let fm = new Matrix4().multiply(projViewI).multiply(world);
  48648. frustum.setFromProjectionMatrix(fm);
  48649. frustums[i] = frustum; //frustums.push(frustum);
  48650. // camera position in object space
  48651. let worldI = pointcloud.matrixWorldInverse;
  48652. let camMatrixObject = new Matrix4().multiply(worldI).multiply(view);//假设点云无变换的话,相机相对于点云的变换矩阵
  48653. let camObjPos = new Vector3().setFromMatrixPosition(camMatrixObject);
  48654. camObjPositions[i] = camObjPos;//camObjPositions.push(camObjPos);
  48655. let quaternion = new Quaternion().setFromRotationMatrix(camMatrixObject);
  48656. let camDir = (new Vector3(0,0,-1)).applyQuaternion(quaternion);
  48657. camObjDirs[i] = camDir;
  48658. // hide all previously visible nodes
  48659. // if(pointcloud.root instanceof PointCloudOctreeNode){
  48660. // pointcloud.hideDescendants(pointcloud.root.sceneNode);
  48661. // }
  48662. if (pointcloud.root.isTreeNode()) {
  48663. pointcloud.hideDescendants(pointcloud.root.sceneNode);
  48664. }
  48665. for (let j = 0; j < pointcloud.boundingBoxNodes.length; j++) {
  48666. pointcloud.boundingBoxNodes[j].visible = false;
  48667. }
  48668. }
  48669. viewer.addTimeMark('visiStructure','end');
  48670. return {
  48671. 'frustums': frustums,
  48672. 'camObjPositions': camObjPositions,
  48673. 'priorityQueue': priorityQueue,
  48674. camObjDirs
  48675. };
  48676. };
  48677. Potree.updateVisibility = function(pointclouds, camera, areaSize){
  48678. let numVisibleNodes = 0;
  48679. let numVisiblePoints = 0;
  48680. let numVisiblePointsInPointclouds = new Map(pointclouds.map(pc => [pc, 0]));
  48681. let visibleNodes = [];
  48682. let visibleGeometry = [];
  48683. let unloadedGeometry = [];
  48684. let lowestSpacing = Infinity;
  48685. // calculate object space frustum and cam pos and setup priority queue
  48686. let s = Potree.updateVisibilityStructures(pointclouds, camera, areaSize);//得到相机可见范围
  48687. let frustums = s.frustums;
  48688. let camObjPositions = s.camObjPositions;
  48689. let priorityQueue = s.priorityQueue;
  48690. let camObjDirs = s.camObjDirs;
  48691. let loadedToGPUThisFrame = 0;
  48692. let domWidth = areaSize.x; //renderer.domElement.clientWidth;
  48693. let domHeight = areaSize.y;//renderer.domElement.clientHeight;
  48694. let fov = (camera.fov * Math.PI) / 180;
  48695. let slope = Math.tan(fov / 2);
  48696. let projFactor0 = (0.5 * domHeight) / slope ;
  48697. // check if pointcloud has been transformed
  48698. // some code will only be executed if changes have been detected
  48699. if(!Potree._pointcloudTransformVersion){
  48700. Potree._pointcloudTransformVersion = new Map();
  48701. }
  48702. let pointcloudTransformVersion = Potree._pointcloudTransformVersion;
  48703. for(let pointcloud of pointclouds){
  48704. if(pointcloud.hasDepthTex ? !pointcloud.visible : !Potree.Utils.getObjVisiByReason(pointcloud, 'datasetSelection')){//改 visible ->
  48705. continue;
  48706. }
  48707. //if(!pointcloud.visible) continue
  48708. pointcloud.updateMatrixWorld();
  48709. if(!pointcloudTransformVersion.has(pointcloud)){
  48710. pointcloudTransformVersion.set(pointcloud, {number: 0, transform: pointcloud.matrixWorld.clone()});
  48711. }else {
  48712. let version = pointcloudTransformVersion.get(pointcloud);
  48713. if(!version.transform.equals(pointcloud.matrixWorld)){
  48714. version.number++;
  48715. version.transform.copy(pointcloud.matrixWorld);
  48716. pointcloud.dispatchEvent({
  48717. type: "transformation_changed",
  48718. target: pointcloud
  48719. });
  48720. }
  48721. }
  48722. }
  48723. while (priorityQueue.size() > 0) {
  48724. let element = priorityQueue.pop(); //取出权重最大的一个
  48725. let node = element.node;
  48726. let parent = element.parent;
  48727. let pointcloud = pointclouds[element.pointcloud];
  48728. // { // restrict to certain nodes for debugging
  48729. // let allowedNodes = ["r", "r0", "r4"];
  48730. // if(!allowedNodes.includes(node.name)){
  48731. // continue;
  48732. // }
  48733. // }
  48734. let box = node.getBoundingBox();
  48735. let frustum = frustums[element.pointcloud];
  48736. let camObjPos = camObjPositions[element.pointcloud];
  48737. if(!frustum) continue //add
  48738. let camObjDir = camObjDirs[element.pointcloud];
  48739. let insideFrustum = frustum.intersectsBox(box);
  48740. let maxLevel = pointcloud.maxLevel == void 0 ? Infinity : pointcloud.maxLevel;
  48741. let minLevel = pointcloud.minLevel == void 0 ? 0 : pointcloud.minLevel; //add
  48742. let level = node.getLevel();
  48743. let visible = insideFrustum;
  48744. visible = visible && !(numVisiblePoints + node.getNumPoints() > Potree.pointBudget);
  48745. visible = visible && !(numVisiblePointsInPointclouds.get(pointcloud) + node.getNumPoints() > pointcloud.pointBudget); // pointcloud.pointBudget一直是Infinity
  48746. visible = visible && level <= maxLevel /* && level >= minLevel */ ; //< 改为 <=
  48747. //visible = visible || node.getLevel() <= 2;
  48748. let pcWorldInverse = pointcloud.matrixWorld.clone().invert();
  48749. /* let m = pcWorldInverse.elements
  48750. 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的
  48751. */
  48752. //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的
  48753. let intersectBox = (clipBox)=>{
  48754. let toPCObject = pcWorldInverse.clone().multiply(clipBox.box.matrixWorld); //box乘上点云逆矩阵
  48755. return Potree.Utils.isIntersectBox(box, toPCObject)
  48756. };
  48757. //改 总共两种box : 可见和不可见(都是并集)
  48758. let clipBoxes_in = pointcloud.material.clipBoxes_in;
  48759. let clipBoxes_out = pointcloud.material.clipBoxes_out;
  48760. let bigClipInBox = pointcloud.material.bigClipInBox;
  48761. if(visible && bigClipInBox){//不在剪裁下载的框内
  48762. if(!intersectBox(bigClipInBox)){
  48763. visible = false;
  48764. }
  48765. }
  48766. if(visible && clipBoxes_in.length > 0){//当有可见box时,需要在任一可见box内才可见
  48767. let visi = false;
  48768. for(let i = 0, length=clipBoxes_in.length; i < length; i++){
  48769. if(intersectBox(clipBoxes_in[i])){
  48770. visi = true;
  48771. break;
  48772. }
  48773. }
  48774. if(!visi){
  48775. visible = false;
  48776. }
  48777. }
  48778. //outside不做处理。因为node必须完全在clipBox内才能完全隐藏,而这里的intersect只能识别出部分在clipBox内。因而只能说明不在任意一个box内绝对可见,没有意义,这里需要找出不可见的。
  48779. if(visible){
  48780. let prism = pointcloud.material.activeAttributeName == 'prismHeight' && pointcloud.material.prisms && pointcloud.material.prisms.find(e=>e.computing);
  48781. if(prism){
  48782. let bound = box.clone().applyMatrix4(pointcloud.matrixWorld);
  48783. if(bound.intersectsBox(prism.prismBound)){
  48784. /* //node box是否包含points中的一个点
  48785. let box2 = new THREE.Box2().copy(box)
  48786. let points2d = prisms.points.map(e=>new THREE.Vector2().copy(e).applyMatrix3(pcWorldInvM3))
  48787. let intersect = points2d.some(e=>{
  48788. return box2.containsPoint(e)
  48789. })
  48790. if(!intersect){
  48791. //或者多边形中是否包含node box中的一个点
  48792. intersect = [
  48793. new THREE.Vector2(box.min.x, box.min.y),
  48794. new THREE.Vector2(box.max.x, box.max.y),
  48795. new THREE.Vector2(box.min.x, box.max.y),
  48796. new THREE.Vector2(box.max.x, box.min.y),
  48797. ].some(e=>{
  48798. if(math.isPointInArea(points2d, null, e) ){
  48799. return true
  48800. }
  48801. })
  48802. //z是不是在外层已经判断好了?
  48803. if(!intersect){
  48804. visible = false
  48805. }
  48806. } */
  48807. //会有两个互不包含点但是交叉了的情况,所以就不仔细判断了(如横竖两个矩形构成十字架)
  48808. }else visible = false;
  48809. }
  48810. }
  48811. if (node.spacing) {
  48812. lowestSpacing = Math.min(lowestSpacing, node.spacing);
  48813. } else if (node.geometryNode && node.geometryNode.spacing) {
  48814. lowestSpacing = Math.min(lowestSpacing, node.geometryNode.spacing);
  48815. }
  48816. if (numVisiblePoints + node.getNumPoints() > Potree.pointBudget) {
  48817. viewer.dispatchEvent({type:'overPointBudget', restQueueSize: priorityQueue.size(), numVisiblePoints} );
  48818. break;
  48819. }
  48820. if (!visible) {
  48821. continue;
  48822. }
  48823. // TODO: not used, same as the declaration?
  48824. // numVisibleNodes++;
  48825. numVisiblePoints += node.getNumPoints();
  48826. let numVisiblePointsInPointcloud = numVisiblePointsInPointclouds.get(pointcloud);
  48827. numVisiblePointsInPointclouds.set(pointcloud, numVisiblePointsInPointcloud + node.getNumPoints());
  48828. pointcloud.numVisibleNodes++;
  48829. pointcloud.numVisiblePoints += node.getNumPoints();
  48830. if (node.isGeometryNode() && (!parent || parent.isTreeNode())) {
  48831. if (node.isLoaded() && loadedToGPUThisFrame < 2) {
  48832. node = pointcloud.toTreeNode(node, parent);
  48833. loadedToGPUThisFrame++;
  48834. } else {
  48835. //console.log('unloadedGeometry',node)
  48836. unloadedGeometry.push({pointcloud,node}); //加载点云。虽然还没加载,但也计入了visibleNodes,只是无children,numPoints=0
  48837. visibleGeometry.push(node);
  48838. }
  48839. }
  48840. if (node.isTreeNode()) {
  48841. Potree.lru.touch(node.geometryNode);//在缓存中计入点云
  48842. node.sceneNode.visible = true;
  48843. node.sceneNode.material = pointcloud.material;
  48844. /* level >= minLevel && */visibleNodes.push(node);
  48845. /* level >= minLevel && */pointcloud.visibleNodes.push(node);
  48846. if(node._transformVersion === undefined){
  48847. node._transformVersion = -1;
  48848. }
  48849. let transformVersion = pointcloudTransformVersion.get(pointcloud);
  48850. if(node._transformVersion !== transformVersion.number){
  48851. node.sceneNode.updateMatrix();
  48852. //node.sceneNode.matrixWorld.multiplyMatrices(pointcloud.matrixWorld, node.sceneNode.matrix);
  48853. node.sceneNode.matrixWorld.multiplyMatrices(pointcloud.matrixWorld, node.sceneNode.matrix);
  48854. node._transformVersion = transformVersion.number;
  48855. }
  48856. if (pointcloud.showBoundingBox && !node.boundingBoxNode && node.getBoundingBox) {
  48857. let colorHue = level / (maxLevel+1);
  48858. let s = 0.1 + level / (maxLevel+1);
  48859. let color = (new Color()).setHSL(colorHue, s, s);
  48860. let boxHelper = new Box3Helper$1(node.getBoundingBox(),color);
  48861. boxHelper.matrixAutoUpdate = false;
  48862. pointcloud.boundingBoxNodes.push(boxHelper);
  48863. node.boundingBoxNode = boxHelper;
  48864. node.boundingBoxNode.matrix.copy(pointcloud.matrixWorld);
  48865. } else if (pointcloud.showBoundingBox) {
  48866. node.boundingBoxNode.visible = true;
  48867. node.boundingBoxNode.matrix.copy(pointcloud.matrixWorld);
  48868. } else if (!pointcloud.showBoundingBox && node.boundingBoxNode) {
  48869. node.boundingBoxNode.visible = false;
  48870. }
  48871. // if(node.boundingBoxNode !== undefined && exports.debug.allowedNodes !== undefined){
  48872. // if(!exports.debug.allowedNodes.includes(node.name)){
  48873. // node.boundingBoxNode.visible = false;
  48874. // }
  48875. // }
  48876. }
  48877. // add child nodes to priorityQueue 由近及远、由大及小逐渐加载
  48878. let children = node.getChildren();
  48879. for (let i = 0; i < children.length; i++) {
  48880. let child = children[i];
  48881. let weight = 0;
  48882. if(camera.isPerspectiveCamera){
  48883. let sphere = child.getBoundingSphere();
  48884. let center = sphere.center;
  48885. let dd = sphere.center.distanceToSquared(camObjPos);
  48886. let addPow = 0.2;//viewer.mainViewport.view.isFlying() ? 0 : 0.5 //0-0.5,正常原本是0. 数字越大近处加载越快。但会造成远处加载慢甚至因pointBudge限制不加载。 isFlying:漫游时需要尽量加载一下远处的点云
  48887. //addPow *= window.devicePixelRatio //devicePixelRatio高的手机需要优先加载最近的高级点云,减少远处的中高级点云。
  48888. let distance = Math.pow(dd,0.5+addPow);//Math.sqrt(dd); //提高距离权重,为了提高近处加载速度。 某些场景近处加载慢优化明显,如SS-t-cqCAL6rJ5i
  48889. //let attenuateDis = 10;//add
  48890. let radius = sphere.radius;
  48891. let projFactor = projFactor0 / distance;
  48892. let screenPixelRadius = radius * projFactor;
  48893. /* if(distance > attenuateDis){
  48894. screenPixelRadius -= (distance - attenuateDis) * Math.sqrt(radius) * projFactor0 * 0.002
  48895. } */
  48896. //screenPixelRadius 和 domHeight 成正比,所以手机横屏后screenPixelRadius会变小。这是正常的,因为vhov不变,相同物体高度在横屏后高度变小,所需要的密度不需要那么高了。但hfov横屏后扩大,所以可见的node范围变大,又增加了一些可见node;只是总体的可见node还是减少了。
  48897. //使用hfov和domWidth计算结果相同。
  48898. if(screenPixelRadius < pointcloud.minimumNodePixelSize / Math.pow(dd,addPow)){ //理论上因手机像素小,更不容易堆叠铺满,minimumNodePixelSize应该除以window.deviceRatio 但会造成加载过多,而内存小
  48899. continue;
  48900. }
  48901. weight = screenPixelRadius;
  48902. if( !sphere.containsPoint(camObjPos) ){ //add 优先加载屏幕中央的点云(手机端缩小离远效果明显,不会那么稀疏)
  48903. let dir = new Vector3().subVectors(center, camObjPos).normalize();
  48904. let cos = 1+dir.dot(camObjDir); //0-2
  48905. weight *= cos/2;//Math.pow(cos,0.5) //幂越高,旁边的容易加载不到,出现缺块 如SS-t-7DUfWAUZ3V
  48906. }
  48907. if(distance - radius < 0){
  48908. weight = Number.MAX_VALUE;
  48909. }
  48910. //如果能得到每个方向上的密度,也就是node数量,密度大的远处少加载,因为被遮挡了显示也没有意义,就好了。
  48911. } else {
  48912. // TODO ortho visibility
  48913. //let bb = child.getBoundingBox();
  48914. let sphere = child.getBoundingSphere();
  48915. //let diagonal = bb.max.clone().sub(bb.min).length();
  48916. const reduce = 0; //0-0.5,正常原本是0.
  48917. if( sphere.radius * /* Math.pow( */camera.zoom/* ,1-reduce) */ < pointcloud.minimumNodePixelSize ){
  48918. continue;
  48919. }
  48920. let distance = sphere.center.distanceToSquared(camObjPos); //先加载中间然后四周
  48921. weight = sphere.radius / distance;
  48922. /* let vec = new THREE.Vector3().subVectors(sphere.center, camObjPos)
  48923. let disOnCamDir = vec.dot(camObjDir)
  48924. let vecOnCamDir = camObjDir.clone().multiplyScalar(disOnCamDir)
  48925. let vecSide = new THREE.Vector3().subVectors(vec, vecOnCamDir) //在屏幕上从中心到该node的向量
  48926. let disSide = vecSide.length()
  48927. //weight = sphere.radius / disSide * camera.zoom - disOnCamDir * 2; //如果用除的,ortho的camera离远了的话dis的影响就小了
  48928. weight = sphere.radius / ( disSide * 0.1 + disOnCamDir * 14 )
  48929. */
  48930. //weight = diagonal;
  48931. }
  48932. priorityQueue.push({pointcloud: element.pointcloud, node: child, parent: node, weight: weight}); //貌似好像二叉堆中子节点和父节点没什么关系,就只是为了方便排序层层遍历
  48933. }
  48934. //手机上像素点更小,所以远处感觉会更稀疏
  48935. }// end priority queue loop
  48936. { // update DEM 这是什么
  48937. let maxDEMLevel = 4;
  48938. let candidates = pointclouds.filter(p => (p.generateDEM && p.dem instanceof Potree.DEM));
  48939. for (let pointcloud of candidates) {
  48940. let updatingNodes = pointcloud.visibleNodes.filter(n => n.getLevel() <= maxDEMLevel);
  48941. pointcloud.dem.update(updatingNodes);
  48942. }
  48943. }
  48944. unloadedGeometry = unloadedGeometry.filter(e=>!e.loadFailed); //过滤加载失败的,否则有失败的就无法发送加载完成
  48945. if(unloadedGeometry.length){//加载点云
  48946. let maxNodesLoading = Common.getBestCount('unloadedGeometry', viewer.lastFrameChanged?1:3, 6, 4, 15 /* , true */ );//dur在iphoneX中静止有7,pc是2 //!lastFrameChanged静止时加速下载
  48947. //THREE.Math.clamp(Math.round(9 - dur), 1, 6 )
  48948. //console.log('unloadedGeometry', unloadedGeometry.length)
  48949. //主要在手机端有效果。不改之前在展示的点云较多时前进会卡。
  48950. for (let i = 0; i < Math.min(maxNodesLoading, unloadedGeometry.length); i++) {
  48951. unloadedGeometry[i].node.load(unloadedGeometry[i].pointcloud.pcoGeometry);
  48952. }
  48953. if(!Potree.pointsLoading){
  48954. Potree.pointsLoading = true;
  48955. //console.log('startLoad')
  48956. viewer.dispatchEvent('startLoadPoints');
  48957. }
  48958. }else {
  48959. if(Potree.pointsLoading){
  48960. Potree.pointsLoading = false;
  48961. //console.log('load done!')
  48962. setTimeout(()=>{
  48963. Potree.pointsLoading || viewer.dispatchEvent('pointsLoaded');
  48964. },document.hidden ? 3000 : 50); //hidden时可能好几秒才更新一次,所以这个并不准
  48965. }
  48966. }
  48967. Potree.unloadedGeometry = unloadedGeometry;
  48968. //add:
  48969. Potree.numVisiblePoints = numVisiblePoints;
  48970. return {
  48971. visibleNodes: visibleNodes,
  48972. numVisiblePoints: numVisiblePoints,
  48973. lowestSpacing: lowestSpacing
  48974. };
  48975. };
  48976. Potree.numVisiblePoints = 0;
  48977. /*
  48978. note:
  48979. 缓存中的点数 Potree.lru.numPoints 一般会 大于 每个点云显示点总数的numVisiblePoints
  48980. 当超出缓冲区最大点云数时,加载的点云节点会被dispose彻底消除;否则,隐藏的节点就会等待再次被使用显示
  48981. 由于加载按照由近及远、由大及小的顺序,要降低卡顿,就只需要降低Potree.pointBudget即可。但目前只设置了三个层次;另外提供maxLevel细节调节,能显示更均匀. 最好多一个调节pointBudge的滑动条
  48982. Potree.lru.numPoints
  48983. Potree.numVisiblePoints
  48984. viewer.scene.pointclouds[0].visibleNodes.length
  48985. */
  48986. {//HQSplatRenderer
  48987. let oldInit = HQSplatRenderer.prototype.init;
  48988. HQSplatRenderer.prototype.init = function(){
  48989. oldInit();
  48990. viewer.addEventListener('resize',this.resize.bind(this));
  48991. };
  48992. HQSplatRenderer.prototype.resize = function(e){
  48993. this.rtDepth.setSize(e.canvasWidth, e.canvasHeight);
  48994. this.rtAttribute.setSize(e.canvasWidth, e.canvasHeight);
  48995. };
  48996. HQSplatRenderer.prototype.clear = function(params={}){
  48997. this.init();
  48998. const {renderer, background} = this.viewer;
  48999. if(background === "skybox"){
  49000. renderer.setClearColor(0x000000, 0);
  49001. } else if (background === 'gradient') {
  49002. renderer.setClearColor(0x000000, 0);
  49003. } else if (background === 'black') {
  49004. renderer.setClearColor(0x000000, 1);
  49005. } else if (background === 'white') {
  49006. renderer.setClearColor(0xFFFFFF, 1);
  49007. } else {
  49008. renderer.setClearColor(0x000000, 0);
  49009. }
  49010. params.target || renderer.clear();
  49011. this.clearTargets(params);
  49012. };
  49013. HQSplatRenderer.prototype.render = function(params={}) {
  49014. this.init();
  49015. const viewer = this.viewer;
  49016. const camera = params.camera ? params.camera : viewer.scene.getActiveCamera();
  49017. const {width, height} = params.width ? params : this.viewer.renderer.getSize(new Vector2());
  49018. viewer.renderer.setRenderTarget(params.target||null);
  49019. viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
  49020. //params.target || this.resize(width, height);
  49021. const visiblePointClouds = viewer.scene.pointclouds.filter(pc => pc.visible);
  49022. const originalMaterials = new Map();
  49023. for(let pointcloud of visiblePointClouds){
  49024. originalMaterials.set(pointcloud, pointcloud.material);
  49025. if(!this.attributeMaterials.has(pointcloud)){
  49026. let attributeMaterial = new ExtendPointCloudMaterial();
  49027. this.attributeMaterials.set(pointcloud, attributeMaterial);
  49028. }
  49029. if(!this.depthMaterials.has(pointcloud)){
  49030. let depthMaterial = new ExtendPointCloudMaterial();
  49031. depthMaterial.setDefine("depth_pass", "#define hq_depth_pass");
  49032. depthMaterial.setDefine("use_edl", "#define use_edl");
  49033. this.depthMaterials.set(pointcloud, depthMaterial);
  49034. }
  49035. }
  49036. { // DEPTH PASS
  49037. for (let pointcloud of visiblePointClouds) {
  49038. let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  49039. let material = originalMaterials.get(pointcloud);
  49040. let depthMaterial = this.depthMaterials.get(pointcloud);
  49041. depthMaterial.size = material.size;
  49042. depthMaterial.minSize = material.minSize;
  49043. depthMaterial.maxSize = material.maxSize;
  49044. depthMaterial.pointSizeType = material.pointSizeType;
  49045. depthMaterial.visibleNodesTexture = material.visibleNodesTexture;
  49046. depthMaterial.weighted = false;
  49047. depthMaterial.screenWidth = width;
  49048. depthMaterial.shape = PointShape.CIRCLE;
  49049. depthMaterial.screenHeight = height;
  49050. depthMaterial.uniforms.visibleNodes.value = material.visibleNodesTexture;
  49051. depthMaterial.uniforms.octreeSize.value = octreeSize;
  49052. depthMaterial.spacing = pointcloud.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  49053. depthMaterial.classification = material.classification;
  49054. depthMaterial.uniforms.classificationLUT.value.image.data = material.uniforms.classificationLUT.value.image.data;
  49055. depthMaterial.classificationTexture.needsUpdate = true;
  49056. depthMaterial.uniforms.uFilterReturnNumberRange.value = material.uniforms.uFilterReturnNumberRange.value;
  49057. depthMaterial.uniforms.uFilterNumberOfReturnsRange.value = material.uniforms.uFilterNumberOfReturnsRange.value;
  49058. depthMaterial.uniforms.uFilterGPSTimeClipRange.value = material.uniforms.uFilterGPSTimeClipRange.value;
  49059. depthMaterial.uniforms.uFilterPointSourceIDClipRange.value = material.uniforms.uFilterPointSourceIDClipRange.value;
  49060. depthMaterial.clipTask = material.clipTask;
  49061. depthMaterial.clipMethod = material.clipMethod;
  49062. depthMaterial.setClipBoxes(material.clipBoxes);
  49063. depthMaterial.setClipPolygons(material.clipPolygons);
  49064. pointcloud.material = depthMaterial;
  49065. }
  49066. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, (params.rtEDL || this.rtDepth), {
  49067. clipSpheres: viewer.scene.volumes.filter(v => (v instanceof SphereVolume)),
  49068. });
  49069. }
  49070. { // ATTRIBUTE PASS
  49071. for (let pointcloud of visiblePointClouds) {
  49072. let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  49073. let material = originalMaterials.get(pointcloud);
  49074. let attributeMaterial = this.attributeMaterials.get(pointcloud);
  49075. attributeMaterial.size = material.size;
  49076. attributeMaterial.minSize = material.minSize;
  49077. attributeMaterial.maxSize = material.maxSize;
  49078. attributeMaterial.pointSizeType = material.pointSizeType;
  49079. attributeMaterial.activeAttributeName = material.activeAttributeName;
  49080. attributeMaterial.visibleNodesTexture = material.visibleNodesTexture;
  49081. attributeMaterial.weighted = true;
  49082. attributeMaterial.screenWidth = width;
  49083. attributeMaterial.screenHeight = height;
  49084. attributeMaterial.shape = PointShape.CIRCLE;
  49085. attributeMaterial.uniforms.visibleNodes.value = material.visibleNodesTexture;
  49086. attributeMaterial.uniforms.octreeSize.value = octreeSize;
  49087. attributeMaterial.spacing = pointcloud.pcoGeometry.spacing; // * Math.max(...pointcloud.scale.toArray());
  49088. attributeMaterial.classification = material.classification;
  49089. attributeMaterial.uniforms.classificationLUT.value.image.data = material.uniforms.classificationLUT.value.image.data;
  49090. attributeMaterial.classificationTexture.needsUpdate = true;
  49091. attributeMaterial.uniforms.uFilterReturnNumberRange.value = material.uniforms.uFilterReturnNumberRange.value;
  49092. attributeMaterial.uniforms.uFilterNumberOfReturnsRange.value = material.uniforms.uFilterNumberOfReturnsRange.value;
  49093. attributeMaterial.uniforms.uFilterGPSTimeClipRange.value = material.uniforms.uFilterGPSTimeClipRange.value;
  49094. attributeMaterial.uniforms.uFilterPointSourceIDClipRange.value = material.uniforms.uFilterPointSourceIDClipRange.value;
  49095. attributeMaterial.elevationGradientRepeat = material.elevationGradientRepeat;
  49096. attributeMaterial.elevationRange = material.elevationRange;
  49097. attributeMaterial.gradient = material.gradient;
  49098. attributeMaterial.matcap = material.matcap;
  49099. attributeMaterial.intensityRange = material.intensityRange;
  49100. attributeMaterial.intensityGamma = material.intensityGamma;
  49101. attributeMaterial.intensityContrast = material.intensityContrast;
  49102. attributeMaterial.intensityBrightness = material.intensityBrightness;
  49103. attributeMaterial.rgbGamma = material.rgbGamma;
  49104. attributeMaterial.rgbContrast = material.rgbContrast;
  49105. attributeMaterial.rgbBrightness = material.rgbBrightness;
  49106. attributeMaterial.weightRGB = material.weightRGB;
  49107. attributeMaterial.weightIntensity = material.weightIntensity;
  49108. attributeMaterial.weightElevation = material.weightElevation;
  49109. attributeMaterial.weightRGB = material.weightRGB;
  49110. attributeMaterial.weightClassification = material.weightClassification;
  49111. attributeMaterial.weightReturnNumber = material.weightReturnNumber;
  49112. attributeMaterial.weightSourceID = material.weightSourceID;
  49113. attributeMaterial.color = material.color;
  49114. attributeMaterial.clipTask = material.clipTask;
  49115. attributeMaterial.clipMethod = material.clipMethod;
  49116. attributeMaterial.setClipBoxes(material.clipBoxes);
  49117. attributeMaterial.setClipPolygons(material.clipPolygons);
  49118. pointcloud.material = attributeMaterial;
  49119. }
  49120. let gl = this.gl;
  49121. //viewer.renderer.setRenderTarget(null);
  49122. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, this.rtAttribute, {
  49123. clipSpheres: viewer.scene.volumes.filter(v => (v instanceof SphereVolume)),
  49124. //material: this.attributeMaterial,
  49125. blendFunc: [gl.SRC_ALPHA, gl.ONE],
  49126. //depthTest: false,
  49127. depthWrite: false
  49128. });
  49129. }
  49130. for(let [pointcloud, material] of originalMaterials){
  49131. pointcloud.material = material;
  49132. }
  49133. if(viewer.background === "skybox"){
  49134. viewer.renderer.setClearColor(0x000000, 0);
  49135. viewer.renderer.clear();
  49136. viewer.skybox.camera.rotation.copy(viewer.scene.cameraP.rotation);
  49137. viewer.skybox.camera.fov = viewer.scene.cameraP.fov;
  49138. viewer.skybox.camera.aspect = viewer.scene.cameraP.aspect;
  49139. viewer.skybox.parent.rotation.x = 0;
  49140. viewer.skybox.parent.updateMatrixWorld();
  49141. viewer.skybox.camera.updateProjectionMatrix();
  49142. viewer.renderer.render(viewer.skybox.scene, viewer.skybox.camera);
  49143. } else if (viewer.background === 'gradient') {
  49144. viewer.renderer.setClearColor(0x000000, 0);
  49145. viewer.renderer.clear();
  49146. viewer.renderer.render(viewer.scene.sceneBG, viewer.scene.cameraBG);
  49147. } else if (viewer.background === 'black') {
  49148. viewer.renderer.setClearColor(0x000000, 1);
  49149. viewer.renderer.clear();
  49150. } else if (viewer.background === 'white') {
  49151. viewer.renderer.setClearColor(0xFFFFFF, 1);
  49152. viewer.renderer.clear();
  49153. } else {
  49154. viewer.renderer.setClearColor(0x000000, 0);
  49155. viewer.renderer.clear();
  49156. }
  49157. { // NORMALIZATION PASS
  49158. let normalizationMaterial = this.useEDL ? this.normalizationEDLMaterial : this.normalizationMaterial;
  49159. if(this.useEDL){
  49160. normalizationMaterial.uniforms.edlStrength.value = viewer.edlStrength;
  49161. normalizationMaterial.uniforms.radius.value = viewer.edlRadius;
  49162. normalizationMaterial.uniforms.screenWidth.value = width;
  49163. normalizationMaterial.uniforms.screenHeight.value = height;
  49164. normalizationMaterial.uniforms.uEDLMap.value = (params.rtEDL || this.rtDepth).texture;
  49165. }
  49166. normalizationMaterial.uniforms.uWeightMap.value = this.rtAttribute.texture;
  49167. normalizationMaterial.uniforms.uDepthMap.value = this.rtAttribute.depthTexture;
  49168. Utils.screenPass.render(viewer.renderer, normalizationMaterial);
  49169. }
  49170. viewer.renderer.render(viewer.scene.scene, camera);
  49171. viewer.dispatchEvent({type: "render.pass.scene", viewer: viewer});
  49172. viewer.renderer.render(viewer.scene.sceneOverlay, camera);// add 透明贴图层
  49173. viewer.renderer.clearDepth();
  49174. viewer.transformationTool.update();
  49175. if(!params.target){
  49176. //测量线
  49177. viewer.dispatchEvent({type: "render.pass.perspective_overlay",viewer: viewer, camera});
  49178. viewer.renderer.render(viewer.overlay, camera);//从 viewer.renderDefault搬过来,为了reticule不遮住测量线
  49179. }
  49180. viewer.renderer.render(viewer.controls.sceneControls, camera);
  49181. viewer.renderer.render(viewer.clippingTool.sceneVolume, camera);
  49182. viewer.renderer.render(viewer.transformationTool.scene, camera);
  49183. viewer.renderer.setViewport(width - viewer.navigationCube.width,
  49184. height - viewer.navigationCube.width,
  49185. viewer.navigationCube.width, viewer.navigationCube.width);
  49186. viewer.renderer.render(viewer.navigationCube, viewer.navigationCube.camera);
  49187. viewer.renderer.setViewport(0, 0, width, height);
  49188. viewer.dispatchEvent({type: "render.pass.end",viewer: viewer});
  49189. viewer.renderer.setRenderTarget(null);
  49190. };
  49191. }
  49192. //PointCloudOctreeGeometry.js
  49193. PointCloudOctreeGeometryNode.prototype.loadHierachyThenPoints = function(pointcloud){
  49194. let node = this;
  49195. // load hierarchy
  49196. let callback = function (node, hbuffer) {
  49197. let tStart = performance.now();
  49198. let view = new DataView(hbuffer);
  49199. let stack = [];
  49200. let children = view.getUint8(0);
  49201. let numPoints = view.getUint32(1, true);
  49202. node.numPoints = numPoints;
  49203. stack.push({children: children, numPoints: numPoints, name: node.name});
  49204. let decoded = [];
  49205. let offset = 5;
  49206. while (stack.length > 0) {
  49207. let snode = stack.shift();
  49208. let mask = 1;
  49209. for (let i = 0; i < 8; i++) {
  49210. if ((snode.children & mask) !== 0) {
  49211. let childName = snode.name + i;
  49212. let childChildren = view.getUint8(offset);
  49213. let childNumPoints = view.getUint32(offset + 1, true);
  49214. stack.push({children: childChildren, numPoints: childNumPoints, name: childName});
  49215. decoded.push({children: childChildren, numPoints: childNumPoints, name: childName});
  49216. offset += 5;
  49217. }
  49218. mask = mask * 2;
  49219. }
  49220. if (offset === hbuffer.byteLength) {
  49221. break;
  49222. }
  49223. }
  49224. // console.log(decoded);
  49225. let nodes = {};
  49226. nodes[node.name] = node;
  49227. let pco = node.pcoGeometry;
  49228. let maxLevel_ = 0;
  49229. for (let i = 0; i < decoded.length; i++) {
  49230. let name = decoded[i].name;
  49231. let decodedNumPoints = decoded[i].numPoints;
  49232. let index = parseInt(name.charAt(name.length - 1));
  49233. let parentName = name.substring(0, name.length - 1);
  49234. let parentNode = nodes[parentName];
  49235. let level = name.length - 1;
  49236. maxLevel_ = Math.max(maxLevel_,level);//add
  49237. let boundingBox = Utils.createChildAABB(parentNode.boundingBox, index);
  49238. let currentNode = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  49239. currentNode.level = level;
  49240. currentNode.numPoints = decodedNumPoints;
  49241. currentNode.hasChildren = decoded[i].children > 0;
  49242. currentNode.spacing = pco.spacing / Math.pow(2, level);
  49243. parentNode.addChild(currentNode);
  49244. nodes[name] = currentNode;
  49245. }
  49246. pco.dispatchEvent({type:'updateNodeMaxLevel',level:maxLevel_});//add
  49247. let duration = performance.now() - tStart;
  49248. if(duration > 5){
  49249. /* let msg = `duration: ${duration}ms, numNodes: ${decoded.length}`;
  49250. console.log(msg); */
  49251. }
  49252. node.loadPoints();
  49253. };
  49254. if ((node.level % node.pcoGeometry.hierarchyStepSize) === 0) {
  49255. // let hurl = node.pcoGeometry.octreeDir + "/../hierarchy/" + node.name + ".hrc";
  49256. let hurl = node.pcoGeometry.octreeDir + '/' + node.getHierarchyPath() + '/' + node.name + '.hrc';
  49257. hurl += '?m='+node.pcoGeometry.timeStamp; //add
  49258. let xhr = XHRFactory.createXMLHttpRequest();
  49259. xhr.open('GET', hurl, true);
  49260. xhr.responseType = 'arraybuffer';
  49261. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  49262. xhr.onreadystatechange = () => {
  49263. if (xhr.readyState === 4) {
  49264. if (xhr.status === 200 || xhr.status === 0) {
  49265. let hbuffer = xhr.response;
  49266. callback(node, hbuffer);
  49267. } else {
  49268. console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + hurl);
  49269. Potree.numNodesLoading--;
  49270. }
  49271. }
  49272. };
  49273. try {
  49274. xhr.send(null);
  49275. } catch (e) {
  49276. console.log('fehler beim laden der punktwolke: ' + e);
  49277. }
  49278. }
  49279. };
  49280. PointCloudOctreeGeometryNode.prototype.loadPoints = function(){
  49281. let name = this.name;
  49282. this.pcoGeometry.loader.load(this, ()=>{//callback
  49283. viewer.dispatchEvent('pointcloud_changed');
  49284. //console.log('loadPoints success ', name)
  49285. });
  49286. };
  49287. //加载点云成功->准备渲染画面->更新点云可见性updateVisibility->请求加载新的点云
  49288. PointCloudOctreeGeometryNode.prototype.traverse = function(t, e){//add from navvis 25.js
  49289. void 0 === e && (e = !0);
  49290. for (var n, i = e ? [this] : []; void 0 !== (n = i.pop()); ) {
  49291. t(n);
  49292. for (var o = 0, r = n.children; o < r.length; o++) {
  49293. var a = r[o];
  49294. null !== a && i.push(a);
  49295. }
  49296. }
  49297. };
  49298. Object.assign( PointCloudOctreeGeometry.prototype, EventDispatcher.prototype );
  49299. LRU.prototype.freeMemory = function(){
  49300. if (this.elements <= 1) {
  49301. return;
  49302. }
  49303. let memoryRatio = browser.isMobile() ? 2 : 5;
  49304. //改成navvis的,使用pointBudget,否则四屏点云闪烁。 (似乎要比updateVisiblede的node时限制要宽些,作为缓存继续存着。否则会闪烁)
  49305. let max = MathUtils.clamp( viewer.viewports.length * memoryRatio * Potree.pointBudget, 0, 40e6);
  49306. for (; this.numPoints > max; ) {
  49307. var node = this.getLRUItem();
  49308. node && this.disposeDescendants(node);
  49309. }
  49310. };
  49311. VolumeTool.prototype.update = function(){};
  49312. VolumeTool.prototype.startInsertion = function(args = {}){
  49313. let volume;
  49314. if(args.type){
  49315. volume = new args.type();
  49316. }else {
  49317. volume = new Potree.BoxVolume(Object.assign(args,{clip:true}) );
  49318. }
  49319. volume.highlight = true;
  49320. volume.name = args.name || 'Volume-'+args.clipTask;
  49321. volume.isNew = true;
  49322. viewer.transformObject(null);//先清空
  49323. //console.log('startInsertion',volume.uuid)
  49324. let oldVisiBoxes;
  49325. if(args.clipTask == Potree.ClipTask.SHOW_INSIDE){ //如果是显示类型,需要将所有同类型的解除效果,否则看不到效果。 (或者可以在添加非第一个时去除highlight效果,会更自然,但看不清全貌)
  49326. oldVisiBoxes = viewer.scene.volumes.filter(v => v.clipTask == Potree.ClipTask.SHOW_INSIDE && !v.highlight );
  49327. oldVisiBoxes.forEach(box=>box.highlight = true);
  49328. }
  49329. let updatePose = ()=>{ //保证在视野中的大小一致:
  49330. let camera = this.viewer.scene.getActiveCamera();
  49331. let w = math.getScaleForConstantSize({
  49332. width2d: 300,
  49333. camera , position:volume.getWorldPosition(new Vector3()) ,
  49334. resolution: viewer.mainViewport.resolution//2
  49335. });
  49336. /* let wp = volume.getWorldPosition(new THREE.Vector3()).applyMatrix4(camera.matrixWorldInverse);
  49337. // let pp = new THREE.Vector4(wp.x, wp.y, wp.z).applyMatrix4(camera.projectionMatrix);
  49338. let w = Math.abs((wp.z / 3));*/
  49339. if(!isNaN(w))volume.scale.set(w, w, w);
  49340. {//使水平朝向与camera一致
  49341. let direction = viewer.mainViewport.view.direction.setZ(0);
  49342. volume.quaternion.copy(math.getQuaByAim(direction));
  49343. }
  49344. };
  49345. this.dispatchEvent({
  49346. type: 'start_inserting_volume',
  49347. volume: volume
  49348. });
  49349. updatePose();
  49350. this.viewer.scene.addVolume(volume);
  49351. this.scene.add(volume);
  49352. let drag = e => {
  49353. if(e.hoverViewport.name == 'mapViewport')return
  49354. let I = Utils.getMousePointCloudIntersection(
  49355. viewer.mainViewport,
  49356. viewer.inputHandler.mouse,
  49357. viewer.inputHandler.pointer,
  49358. this.viewer.scene.getActiveCamera(),
  49359. this.viewer,
  49360. this.viewer.scene.pointclouds,
  49361. {pickClipped: args.clipTask == Potree.ClipTask.SHOW_OUTSIDE } //无视clip状态
  49362. );
  49363. var worldPos = I && I.location;
  49364. if(!worldPos){
  49365. return
  49366. }
  49367. volume.position.copy(worldPos);
  49368. updatePose();
  49369. };
  49370. let cancel = ()=>{
  49371. end('remove');
  49372. };
  49373. let end = (e) => {
  49374. if(e.button == MOUSE.RIGHT && e.pressDistance<=Potree.config.clickMaxDragDis) {//remove
  49375. e = 'remove';
  49376. }
  49377. //console.log('end',volume.uuid, e)
  49378. if(e != 'remove' && (!e.isAtDomElement || e.pressDistance>Potree.config.clickMaxDragDis))return continueDrag()
  49379. volume.removeEventListener('drag', drag);
  49380. volume.removeEventListener('drop', end);
  49381. this.viewer.removeEventListener('cancel_insertions', cancel);
  49382. volume.isNew = false;
  49383. viewer.removeEventListener('camera_changed', updatePose);
  49384. if(e == 'remove'){
  49385. viewer.scene.removeVolume(volume); //删除没完成的
  49386. }else {
  49387. viewer.transformObject(volume);
  49388. volume.highlight = false;
  49389. }
  49390. volume.dispatchEvent({type:'createFinish', success:e != 'remove' });
  49391. oldVisiBoxes && oldVisiBoxes.forEach(box=>box.highlight = false);
  49392. };
  49393. let continueDrag = ( )=>{
  49394. //console.log('continueDrag',volume.uuid )
  49395. var timer = setTimeout(()=>{//等 drag=null之后 //右键拖拽结束后需要重新得到drag
  49396. if(volume.parent && volume.isNew){
  49397. viewer.inputHandler.startDragging( volume , {notPressMouse:true}
  49398. /* {endDragFun: e.drag.endDragFun, notPressMouse:e.drag.notPressMouse, dragViewport:e.drag.dragViewport} */
  49399. );
  49400. }
  49401. },1);
  49402. return timer
  49403. };
  49404. volume.addEventListener('drag', drag);
  49405. volume.addEventListener('drop', end);
  49406. this.viewer.addEventListener('cancel_insertions', cancel);
  49407. viewer.addEventListener('camera_changed', updatePose);
  49408. this.viewer.inputHandler.startDragging(volume, {notPressMouse:true});
  49409. return volume;
  49410. };
  49411. LineGeometry.prototype.setPositions = function( array ) { //xzw改成类似LineSegments的多段线 (第二个点和第三个点之间是没有线段的, 所以不用在意线段顺序)
  49412. const points = new Float32Array( array );
  49413. LineSegmentsGeometry.prototype.setPositions.call(this, points );
  49414. return this;
  49415. };
  49416. Object.assign(ExtendView.prototype, EventDispatcher.prototype);
  49417. Object.assign(ExtendScene.prototype, EventDispatcher.prototype );
  49418. function start(dom, mapDom, number ){ //t-Zvd3w0m
  49419. /* {
  49420. let obj = JSON.parse(localStorage.getItem('setting'))
  49421. for(let i in obj){
  49422. console.log(i + ': ' + obj[i])
  49423. }
  49424. }
  49425. */
  49426. Potree.settings.number = number || 't-o5YMR13';// 't-iksBApb'// 写在viewer前
  49427. if(!Potree.settings.isOfficial){
  49428. if(/* Potree.settings.isTest && */ browser.isMobile()){
  49429. changeLog();
  49430. }
  49431. }
  49432. if(browser.urlHasValue('google'))Potree.settings.mapCompany = 'google';
  49433. if(browser.urlHasValue('timing'))Potree.measureTimings = 1;
  49434. let viewer = new Potree.Viewer(dom , mapDom);
  49435. /* viewer.addEventListener('allLoaded',()=>{
  49436. const baseGeometry = new THREE.BufferGeometry();
  49437. baseGeometry.setIndex([0, 1, 2, 0, 2, 3]);
  49438. const positionsArray = new Float32Array(4 * 3);
  49439. const positions = new THREE.BufferAttribute(positionsArray, 3);
  49440. baseGeometry.setAttribute('position', positions);
  49441. positions.setXYZ(0, -1.0, -1.0, 0.0);
  49442. positions.setXYZ(1, -1.0, 1.0, 0.0);
  49443. positions.setXYZ(2, 1.0, 1.0, 0.0);
  49444. positions.setXYZ(3, 1.0, -1.0, 0.0);
  49445. positions.needsUpdate = true;
  49446. const geometry = new THREE.InstancedBufferGeometry().copy(baseGeometry);
  49447. let maxSplatCount = 8
  49448. // Splat index buffer
  49449. const splatIndexArray = new Uint32Array(maxSplatCount);
  49450. const splatIndexes = new THREE.InstancedBufferAttribute(splatIndexArray, 1, false);
  49451. splatIndexes.setUsage(THREE.DynamicDrawUsage);
  49452. geometry.setAttribute('splatIndex', splatIndexes);
  49453. const splatPosArray = new Float32Array(maxSplatCount*3);
  49454. const splatPoses = new THREE.InstancedBufferAttribute(splatPosArray, 3, false);
  49455. splatPoses.setUsage(THREE.DynamicDrawUsage);
  49456. geometry.setAttribute('splatCenter', splatPoses);
  49457. splatPosArray.set([0,0,0,
  49458. 1,1,1,
  49459. 2,2,2,
  49460. 3,3,3,
  49461. 4,4,4,
  49462. 5,5,5,
  49463. 6,6,6,
  49464. 7,7,7])
  49465. let vertexShaderSource = `
  49466. precision highp float;
  49467. #include <common>
  49468. attribute vec3 splatCenter;
  49469. attribute float splatIndex;
  49470. varying vec2 vPosition;
  49471. const float sqrt8 = sqrt(8.0);
  49472. const float minAlpha = 1.0 / 255.0;
  49473. void main () {
  49474. mat4 transformModelViewMatrix = modelViewMatrix;
  49475. vec4 viewCenter = transformModelViewMatrix * vec4(splatCenter, 1.0);
  49476. vec4 clipCenter = projectionMatrix * viewCenter;
  49477. float clip = 1.2 * clipCenter.w;
  49478. if (clipCenter.z < -clip || clipCenter.x < -clip || clipCenter.x > clip || clipCenter.y < -clip || clipCenter.y > clip) {
  49479. gl_Position = vec4(0.0, 0.0, 2.0, 1.0);
  49480. return;
  49481. }
  49482. vPosition = position.xy;
  49483. vec3 ndcCenter = clipCenter.xyz / clipCenter.w;
  49484. float eigenValue1 = 0.2;
  49485. float eigenValue2 = 0.2;
  49486. //vec2 eigenVector1 = normalize(vec2(b, eigenValue1 - a));
  49487. vec2 eigenVector1 = normalize(vec2(0.5, 0.5));
  49488. vec2 eigenVector2 = vec2(eigenVector1.y, -eigenVector1.x);
  49489. vec2 basisVector1 = eigenVector1 * min(sqrt8 * sqrt(eigenValue1), 2048.0);
  49490. vec2 basisVector2 = eigenVector2 * min(sqrt8 * sqrt(eigenValue2), 2048.0);
  49491. vec2 ndcOffset = vec2(vPosition.x * basisVector1 + vPosition.y * basisVector2) / viewport * 2.0 ;
  49492. gl_Position = vec4(ndcCenter.xy + ndcOffset, ndcCenter.z , 1.0);
  49493. vPosition *= sqrt8;
  49494. }`;
  49495. //面片模拟椭球,总是有厚度
  49496. const fragmentShaderSource = `
  49497. precision highp float;
  49498. #include <common>
  49499. uniform vec3 color;
  49500. varying vec2 vPosition;
  49501. void main () {
  49502. float A = dot(vPosition, vPosition);
  49503. if (A > 8.0) discard; //position的范围半径为1。指一个rectangle面中的范围。椭圆外的完全透明
  49504. float opacity = exp(-0.5 * A) * vColor.a; //周围的透明度降低
  49505. gl_FragColor = vec4(color.rgb, opacity);
  49506. }`;
  49507. const uniforms = {
  49508. 'viewport': {
  49509. 'type': 'v2',
  49510. 'value': new THREE.Vector2()
  49511. } ,
  49512. color:{
  49513. 'type': 'v3',
  49514. 'value': new THREE.Color()
  49515. }
  49516. };
  49517. const material = new THREE.ShaderMaterial({
  49518. uniforms: uniforms,
  49519. vertexShader: vertexShaderSource,
  49520. fragmentShader: fragmentShaderSource,
  49521. transparent: true,
  49522. alphaTest: 1.0,
  49523. blending: THREE.NormalBlending,
  49524. depthTest: true,
  49525. depthWrite: false,
  49526. side: THREE.DoubleSide
  49527. });
  49528. window.splatMesh = new THREE.Mesh(geometry, material)
  49529. viewer.scene.scene.add(window.splatMesh)
  49530. viewer.addEventListener('resize',(e)=>{
  49531. if(e.viewport.name == 'mainViewport'){
  49532. uniforms.viewport.copy(e.viewport.resolution)
  49533. }
  49534. })
  49535. window.setSplatIndexes = (globalIndexes)=>{
  49536. geometry.attributes.splatIndex.set(globalIndexes);
  49537. geometry.attributes.splatIndex.needsUpdate = true;
  49538. geometry.instanceCount = globalIndexes.length
  49539. }
  49540. })
  49541. */
  49542. let Alignment = viewer.modules.Alignment;
  49543. viewer.setEDLEnabled(false);
  49544. viewer.setFOV(Potree.config.view.fov);
  49545. //viewer.loadSettingsFromURL();
  49546. Potree.settings.cameraFar = Potree.config.view.far;
  49547. if(!Potree.settings.isOfficial){
  49548. viewer.loadGUI(() => {
  49549. viewer.setLanguage('en');
  49550. //$("#menu_appearance").next().show();
  49551. $("#menu_tools").next().show();
  49552. $("#menu_scene").next().show();
  49553. $("#siteModel").show();
  49554. //$("#alignment").show();
  49555. viewer.toggleSidebar();
  49556. });
  49557. Potree.settings.sizeFitToLevel = true;//当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  49558. Potree.settings.rotAroundPoint = false;
  49559. }
  49560. Potree.loadDatasetsCallback = function(data, ifReload){
  49561. if(!data || data.length == 0)return console.error('getDataSet加载的数据为空')
  49562. Potree.datasetData = data;
  49563. viewer.transform = null;
  49564. var datasetLength = data.length;
  49565. var pointcloudLoaded = 0;
  49566. var panosLoaded = 0;
  49567. var pointcloudLoadDone = function(){//点云cloud.js加载完毕后
  49568. };
  49569. var panosLoadDone = function(){
  49570. viewer.images360.loadDone();
  49571. viewer.scene.add360Images(viewer.images360);
  49572. viewer.mapViewer.addListener(viewer.images360);
  49573. viewer.updateModelBound(); //需等pano加载完
  49574. let {boundSize, center} = viewer.bound;
  49575. if(!Potree.settings.isOfficial){
  49576. Potree.loadMapEntity('all'); //加载floorplan
  49577. }
  49578. if(!ifReload){
  49579. viewer.dispatchEvent({type:'loadPointCloudDone'});
  49580. if(!Potree.settings.UserPointDensity){
  49581. Potree.settings.UserPointDensity = 'high';//'middle'
  49582. }
  49583. Potree.Log('loadPointCloudDone 点云加载完毕', {font:[null, 10]});
  49584. }
  49585. {//初始位置
  49586. var panoId = browser.urlHasValue('pano',true);
  49587. if(panoId !== ''){
  49588. var pos;
  49589. var pano = viewer.images360.panos.find(e=>e.id==panoId);
  49590. if(pano){
  49591. viewer.images360.focusPano({
  49592. pano,
  49593. duration:0,
  49594. callback:()=>{/* Potree.settings.displayMode = 'showPanos' */}
  49595. });
  49596. }
  49597. }else {//考虑到多数据集距离很远,或者像隧道那种场景,要使视野范围内一定能看到点云,最好初始点设置在漫游点上
  49598. let {boundSize, center} = viewer.bound;
  49599. let pano = viewer.images360.findNearestPano(center);
  49600. if(pano){
  49601. viewer.images360.flyToPano({
  49602. pano, duration:0,
  49603. target : viewer.images360.bound.center.setZ(pano.position.z) //平视中心区域(但也不能保证这个方向一定能看到点云密集区,如果在边缘的话)
  49604. });
  49605. }else {// 无漫游点 避免加载时看不到点云 SG-t-DXmdymgZ2sX SG-t-rVB03a5GXr8
  49606. //SG-t-XPf1k9pv3Zg 总有极端的场景,如这是倾斜的桥 - -, 只能调整为看到全局了
  49607. viewer.mainViewport.view.pitch = -0.7; //相对俯视
  49608. let bound = viewer.bound.boundingBox.clone();
  49609. viewer.focusOnObject({boundingBox:bound},'boundingBox',0,{dontChangeCamDir:true});
  49610. if(viewer.bound.boundSize.length() > 20){ //否则有可能超出far范围
  49611. viewer.mainViewport.camera.far = 10000;
  49612. viewer.mainViewport.camera.updateProjectionMatrix();
  49613. viewer.fixCamFar = true; //不允许修改camera.far
  49614. //等有点云加载出来后,再去focus其中一个,使camera.far不超过最大值
  49615. let count_ = 0;
  49616. let done = ()=>{
  49617. viewer.fixCamFar = false;
  49618. viewer.mainViewport.camera.far = Potree.settings.cameraFar;
  49619. viewer.mainViewport.camera.updateProjectionMatrix();
  49620. viewer.removeEventListener('pageVisible', focusPoint );
  49621. clearTimeout(timer);
  49622. };
  49623. let timer;
  49624. let focusPoint = (e)=>{//拉近到某个点
  49625. if(e && e.v === false)return
  49626. viewer.removeEventListener('pageVisible', focusPoint );
  49627. let pointcloud = viewer.scene.pointclouds.find(e=>e.root.geometryNode);
  49628. console.log('初始加载focus点云', e , pointcloud);
  49629. if(!pointcloud){
  49630. if(count_ < 10 ){//可能没加载到,可能被隐藏
  49631. if(document.hidden){//等回到页面再focus
  49632. console.log('focus hidden');
  49633. return viewer.addEventListener('pageVisible', focusPoint )
  49634. }
  49635. count_ ++; //如果在别的
  49636. timer = setTimeout(focusPoint, 200);
  49637. }else { //放弃
  49638. console.log('初始加载focus点云 放弃');
  49639. done();
  49640. }
  49641. return console.warn('no!!!!!!!!!!!!!!')
  49642. }
  49643. viewer.flyToDataset({focusOnPoint:true, pointcloud, duration:0, });
  49644. console.warn('ok!!!!!!!!!!!!!!!!');
  49645. done();
  49646. };
  49647. let focus = ()=>{
  49648. timer = setTimeout(focusPoint, 300);
  49649. };
  49650. viewer.addEventListener('setPose',()=>{//设置了初始画面
  49651. viewer.removeEventListener('pointcloud_changed',focus);
  49652. done();
  49653. });
  49654. viewer.addEventListener('pointcloud_changed',focus,{once:true});//加载了点之后
  49655. }
  49656. }
  49657. }
  49658. }
  49659. viewer.addVideo();//addFire()
  49660. viewer.scene.pointclouds.some(e=>!e.hasDepthTex) && (Potree.config.shelterMargin*=3); //没有深度图的话在全景模式测量有偏差
  49661. console.log('allLoaded');
  49662. viewer.addTube({
  49663. 't-8KbK1JjubE':[
  49664. {//地上管子 黄色
  49665. path:[{"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}
  49666. ,{"x":43.58,"y":27.7,"z":-0.97},{"x":40.22,"y":35.37,"z":-0.67}// 拐弯向右
  49667. ,{"x":39.18,"y":36.71,"z":0.35},{"x":38.69,"y":36.04,"z":18.04} // 拐弯向上 }
  49668. ],
  49669. color:'#b86', radius:0.08, height:0.13
  49670. },
  49671. {//地下管子 藍色
  49672. path:[{"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}
  49673. ],
  49674. color:'#48a', radius:0.08, height:-0.5
  49675. }
  49676. ] ,
  49677. /* 'SG-t-h0I7LnfGFwj':[ //港华M层
  49678. {
  49679. 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]]
  49680. ,color:'#8c99aa', radius:0.025, height:-0, fromDataset:true, tension:0.01, spaceDis:0.02,visiEntity:'厨房'
  49681. },
  49682. {
  49683. 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]]
  49684. ,color:'#8c99aa', radius:0.025, height:-0, fromDataset:true, tension:0.01, spaceDis:0.02,visiEntity:'厨房'
  49685. },
  49686. {
  49687. 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]]
  49688. ,color:'#8c99aa', radius:0.02, height:-0, fromDataset:true, tension:0.01, spaceDis:0.02,visiEntity:'厨房'
  49689. }
  49690. ],
  49691. 'SG-t-RGUFiJAoxvL':[ //济南工地覆土后
  49692. {//--旧的 整条
  49693. 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]]
  49694. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, tension:0.01,// spaceDis:0.1
  49695. },
  49696. {
  49697. path:[[22.726,22.678,-1.938],[-24.541,16.782,-1.319]]
  49698. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, tension:0,// spaceDis:0.1
  49699. },
  49700. {
  49701. path:[[23.519,-19.473,-1.744],[25.117,15.447,-1.783]]
  49702. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, tension:0,// spaceDis:0.1
  49703. }
  49704. ],
  49705. 'SG-t-TK0S5EqWBxd':[ //济南工地
  49706. {
  49707. 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]]
  49708. ,color:'#445', radius:0.08, height:-1.16, fromDataset:true, spaceDis:0.2// tension:0.01,
  49709. },
  49710. ],*/
  49711. });
  49712. viewer.dispatchEvent('allLoaded');
  49713. };
  49714. var transformPointcloud = (pointcloud, dataset)=>{
  49715. var locationLonLat = dataset.location.slice(0,3); // [lon,lat,高程海拔]
  49716. //当只有一个dataset时,无论如何transform 点云和漫游点都能对应上。
  49717. var location = viewer.transform.lonlatToLocal.forward(locationLonLat); //transform.inverse()
  49718. //初始化位置
  49719. viewer.sidebar && viewer.sidebar.addAlignmentButton(pointcloud);
  49720. //dataset.orientation = 0
  49721. Alignment.rotate(pointcloud, null, dataset.orientation);
  49722. Alignment.translate(pointcloud, new Vector3(location[0], location[1], dataset.location[2]-originDataset.location[2])); //要使初始数据集的z为0,所以要减去初始数据集的z
  49723. pointcloud.updateMatrixWorld();
  49724. Potree.Log(`点云${pointcloud.dataset_id}(${pointcloud.name})旋转值:${pointcloud.orientationUser}, 位置${math.toPrecision(pointcloud.translateUser.toArray(),3)}, 经纬度 ${dataset.location}, spacing ${pointcloud.material.spacing}`, {font:[null, 13]} );
  49725. };
  49726. if(!Potree.settings.originDatasetId)Potree.settings.originDatasetId = data[0].id;
  49727. var originDataset = data.find(e=>e.id == Potree.settings.originDatasetId);
  49728. /* originDataset.location[0] = 113.60608878174709
  49729. originDataset.location[1] = 22.381189423935155
  49730. let ano = data.find(e=>e.name == 'SG-t-Jw0xyhL6oSY')
  49731. ano.location[0] = 113.6060509967498
  49732. ano.location[1] = 22.381061273279244 */
  49733. {//拿初始数据集作为基准。它的位置要放到000
  49734. var locationLonLat = originDataset.location.slice(0,2);
  49735. if(window.AMapWith84){//需要转换为高德的,但该函数不准确,转入后再转出,和原来的有偏差. navvis的我看data中存的globalLocation直接输入到高德地图后的定位和其要展示的定位一致,而我们要转为高德后才一致,猜测是navvis后台转为了高德可用的经纬度。 若不转的话,其他看起来没问题,仅高德地图定位不准确,因其为被加密后的火星坐标系。
  49736. locationLonLat = AMapWith84.wgs84ToAMap({x:locationLonLat[0], y:locationLonLat[1]});
  49737. locationLonLat = [locationLonLat.x,locationLonLat.y];
  49738. }
  49739. proj4.defs("LOCAL", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //高德坐标系
  49740. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15)); //地图和本地一样
  49741. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  49742. let transform1 = proj4("WGS84", "LOCAL"); //这个ok 是展开的平面投影 LOCAL即NAVVIS:TMERC
  49743. 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;");
  49744. //注:转入后再转出,和原来的有偏差。如果输入是local坐标,数字越大偏差越大,当百万时就明显了。如果是lonlat,很奇怪经度小于50时就乱了。
  49745. viewer.transform = {
  49746. lonlatToLocal : transform1,
  49747. lonlatTo4550 : transform2 // 转大地坐标EPSG:4550
  49748. };
  49749. if(window.AMapWith84 && Potree.settings.mapCompany != 'google'){//需要转换, 因本地高德用的lonlat和数据里的84不一样. (google地图在国内也用的高德,国外84)
  49750. let change = (transform)=>{
  49751. let forward = transform.forward;
  49752. let inverse = transform.inverse;
  49753. transform.forward = function(e, not84){
  49754. let needTran = e.x == void 0;
  49755. if(needTran)var a1 = {x:e[0],y:e[1]};
  49756. else var a1 = e;
  49757. var a = not84 ? a1 : AMapWith84.wgs84ToAMap(a1);
  49758. if(needTran){
  49759. a = [a.x, a.y]; e[2] != void 0 && (a[2] = e[2]);
  49760. }else {
  49761. e.z != void 0 && (a.z = e.z);
  49762. }
  49763. return forward(a)
  49764. };
  49765. transform.inverse = function(e, not84){
  49766. let needTran = e.x == void 0;
  49767. var a = inverse(e);
  49768. needTran && (a = {x:a[0],y:a[1]});
  49769. a = not84 ? a : AMapWith84.aMapToWgs84(a);
  49770. if(needTran){
  49771. a = [a.x,a.y]; e[2] != void 0 && (a[2] = e[2]);
  49772. }else {
  49773. e.z != void 0 && (a.z = e.z);
  49774. }
  49775. return a
  49776. };
  49777. };
  49778. for(let f in viewer.transform){
  49779. change(viewer.transform[f]);
  49780. }
  49781. }
  49782. viewer.mapViewer && viewer.mapViewer.mapLayer.maps[0].updateProjection();
  49783. }
  49784. data.forEach((dataset,index)=>{
  49785. if(!ifReload){
  49786. var datasetCode = dataset.sceneCode || dataset.name; //对应4dkk的场景码
  49787. if(Potree.settings.isLocal && dataset.mapping){
  49788. var cloudPath = `${Potree.settings.urls.prefix1}/${dataset.mapping}/${dataset.webBin}`; //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  49789. }else {
  49790. var cloudPath = `${Potree.settings.urls.prefix1}/${dataset.webBin}`; //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  49791. }
  49792. //var cloudPath = `${Potree.scriptPath}/data/test/${dataset.name}/cloud.js`
  49793. var timeStamp = dataset.updateTime ? dataset.updateTime.replace(/[^0-9]/ig,'') : ''; //每重算一次后缀随updateTime更新一次
  49794. //console.warn(dataset.name, 'timeStamp', timeStamp)
  49795. Potree.loadPointCloud(cloudPath, dataset.name ,datasetCode, timeStamp, e => {
  49796. let scene = viewer.scene;
  49797. let pointcloud = e.pointcloud;
  49798. let config = Potree.config.material;
  49799. let material = pointcloud.material;
  49800. pointcloud.datasetData = dataset;
  49801. pointcloud.dataset_id = dataset.id;//供漫游点找到属于的dataset点云
  49802. pointcloud.hasDepthTex = Potree.settings.useDepthTex && (!!dataset.has_depth || Potree.settings.isLocalhost && Potree.settings.number == 'SS-t-7DUfWAUZ3V'); //test
  49803. material.minSize = config.minSize;
  49804. material.maxSize = config.maxSize;
  49805. material.pointSizeType =/* Potree.settings.isOfficial ? */ config.pointSizeType; /* : 'ADAPTIVE' */ //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
  49806. pointcloud.changePointSize(config.realPointSize); //material.size = config.pointSize;
  49807. pointcloud.changePointOpacity(1);
  49808. material.shape = Potree.PointShape.SQUARE;
  49809. pointcloud.color = pointcloud.material.color = dataset.color;
  49810. pointcloud.timeStamp = timeStamp;
  49811. transformPointcloud(pointcloud,dataset);
  49812. scene.addPointCloud(pointcloud);
  49813. if(!Potree.settings.isOfficial){
  49814. Potree.settings.floorplanEnables[dataset.id] = true;
  49815. Potree.settings.floorplanType[dataset.id] = 'default';
  49816. }
  49817. pointcloudLoaded ++;
  49818. if(pointcloudLoaded == datasetLength)pointcloudLoadDone();
  49819. Potree.loadPanos(dataset.id, (data) => {
  49820. //console.log('loadPanos',dataset.sceneCode, dataset.id, data)
  49821. viewer.images360.addPanoData(data, dataset.id );
  49822. panosLoaded ++;
  49823. if(panosLoaded == datasetLength){
  49824. Potree.loadImgVersion((e={})=>{
  49825. Potree.settings.panoVersion = e.imgVersion;//全景图被替换后
  49826. panosLoadDone();
  49827. });
  49828. }
  49829. });
  49830. });
  49831. }else {
  49832. let pointcloud = viewer.scene.pointclouds.find(p => p.dataset_id == dataset.id);
  49833. if(!pointcloud){
  49834. Potree.Log('数据集id变了,自动使用第一个', {font:['#500' ]} );
  49835. pointcloud = viewer.scene.pointclouds[0];
  49836. }
  49837. //先归零
  49838. Alignment.translate(pointcloud, pointcloud.translateUser.clone().negate());
  49839. Alignment.rotate(pointcloud, null, - pointcloud.orientationUser);
  49840. transformPointcloud(pointcloud, dataset);
  49841. }
  49842. });
  49843. if(ifReload){
  49844. //loadDone()
  49845. }
  49846. };
  49847. number && Potree.loadDatasets(Potree.loadDatasetsCallback);
  49848. /*
  49849. //调试用,加载多个本地
  49850. Potree.loadDatasetsCallback([
  49851. {name:'webcloud_0',id:0, orientation:0, location:[0,0,0]},
  49852. {name:'webcloud_1',id:1, orientation:0.047234761795199476, location:[-0.07925513345058573,-0.0010590072536559839,-2.403613132687564]},
  49853. {name:'webcloud_2',id:2, orientation:-1.5299545647758208, location:[1.5603736310030292, -0.0009340812579088904, -2.4464530770974139]},
  49854. ]) */
  49855. window.testTransform = function(locationLonLat, location1, location2){
  49856. proj4.defs("NAVVIS:test", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
  49857. let transform = proj4("WGS84", "NAVVIS:test"); //这个ok navvis里也是这两种转换 见proj4Factory
  49858. if(location1){//经纬度
  49859. return transform.forward(location1)
  49860. }else {
  49861. return transform.inverse(location2)
  49862. }
  49863. };
  49864. window.THREE = THREE$1;
  49865. window.buttonFunction = function(){
  49866. viewer.scene.pointclouds.forEach(e=>e.predictNodeMaxLevel());
  49867. /*
  49868. viewer.startScreenshot({type:'measure', measurement:viewer.scene.measurements[0]})
  49869. viewer.modules.RouteGuider.routeStart = new THREE.Vector3(0,0,-1.3)
  49870. viewer.modules.RouteGuider.routeEnd = new THREE.Vector3(-10,0,-1.3)
  49871. */
  49872. };
  49873. if(Potree.settings.isLocalhost){
  49874. let before = {};
  49875. viewer.inputHandler.addEventListener('keydown',e=>{ //测试的代码
  49876. if(e.event.key == 't'){
  49877. viewer.images360.cube.visible = true;
  49878. viewer.images360.cube.material.wireframe = true;
  49879. }else if(e.event.key == 'y'){
  49880. viewer.images360.cube.material.wireframe = false;
  49881. viewer.images360.cube.visible = Potree.settings.displayMode == 'showPanos';
  49882. }
  49883. });
  49884. //--------------------------------
  49885. /* if(!number){
  49886. Potree.settings.boundAddObjs = true
  49887. Potree.settings.intersectOnObjs = true
  49888. // Load untextured bunny from ply
  49889. viewer.loadModel({
  49890. fileType:'ply',
  49891. url:Potree.resourcePath + "/models/indoor.ply",
  49892. name:'test',
  49893. },
  49894. (object)=>{
  49895. object.isModel = true
  49896. viewer.updateModelBound()
  49897. }
  49898. )
  49899. } */
  49900. }
  49901. }
  49902. //=======================================================================
  49903. /*
  49904. 漫游点编辑
  49905. */
  49906. //=======================================================================
  49907. function panoEditStart(dom, number, fileServer){
  49908. Potree.settings.editType = 'pano';
  49909. Potree.settings.number = number;
  49910. Potree.settings.unableNavigate = true;
  49911. Potree.settings.sizeFitToLevel = true;//当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  49912. let viewer = new Potree.Viewer(dom);
  49913. let Alignment = viewer.modules.Alignment;
  49914. viewer.setEDLEnabled(false);
  49915. viewer.setFOV(Potree.config.view.fov);
  49916. //viewer.loadSettingsFromURL();
  49917. let datasetLoaded = 0;
  49918. if(!Potree.settings.isOfficial){
  49919. viewer.loadGUI(() => {
  49920. viewer.setLanguage('en');
  49921. $("#menu_tools").next().show();
  49922. $("#panos").show();
  49923. $("#alignment").show();
  49924. viewer.toggleSidebar();
  49925. });
  49926. Potree.settings.sizeFitToLevel = true;
  49927. }
  49928. var pointcloudLoadDone = function( ){//所有点云cloud.js加载完毕后
  49929. viewer.scene.pointclouds.forEach(c=>{
  49930. transformPointcloud(c);
  49931. });
  49932. viewer.images360.loadDone();
  49933. viewer.scene.add360Images(viewer.images360);
  49934. viewer.updateModelBound();
  49935. let {boundSize, center} = viewer.bound;
  49936. Potree.Log(`中心点: ${math.toPrecision(center.toArray(),2)}, boundSize: ${math.toPrecision(boundSize.toArray(),2)} ` , {font:[null, 12]} );
  49937. viewer.scene.view.setView({
  49938. position: center.clone().add(new Vector3(10,5,10)),
  49939. target: center
  49940. });
  49941. viewer.dispatchEvent({type:'loadPointCloudDone'});
  49942. if(!Potree.settings.UserPointDensity){
  49943. Potree.settings.UserPointDensity = 'panoEdit';//'middle'
  49944. }
  49945. Potree.Log('loadPointCloudDone 点云加载完毕',{font:[null, 10]});
  49946. viewer.dispatchEvent('allLoaded');
  49947. };
  49948. var transformPointcloud = (pointcloud )=>{ //初始化位置
  49949. viewer.sidebar && viewer.sidebar.addAlignmentButton(pointcloud);
  49950. let orientation = pointcloud.panos[0].dataRotation.z + Math.PI;
  49951. let location = pointcloud.panos[0].dataPosition.clone();//.negate()
  49952. Alignment.rotate(pointcloud, null, orientation );
  49953. Alignment.translate(pointcloud, location );
  49954. pointcloud.updateMatrixWorld();
  49955. };
  49956. let loadPanosDone = Potree.loadPanosDone = (datasetId, panoData )=>{ //一个数据集获取到它的panos后
  49957. Potree.settings.datasetsPanos[datasetId] = {panoData, panos:[]};
  49958. console.log('panoData', datasetId, panoData);
  49959. let panoCount = panoData.length;
  49960. let pointcloudLoaded = 0;
  49961. let datasetsCount = Object.keys(Potree.settings.datasetsPanos).length;
  49962. panoData.forEach((pano, index)=>{
  49963. //let cloudPath = `${Potree.scriptPath}/data/panoEdit/uuidcloud/${pano.uuid}/cloud.js`
  49964. let cloudPath = `${Potree.settings.urls.prefix1}/${Potree.settings.webSite}/${Potree.settings.number}/data/bundle_${Potree.settings.number}/building/uuidcloud/${pano.uuid}/cloud.js`;
  49965. /* if(Potree.settings.isLocal && dataset.mapping){
  49966. var cloudPath = `${Potree.settings.urls.prefix1}/${dataset.mapping}/${dataset.webBin}` //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  49967. }else{
  49968. var cloudPath = `${Potree.settings.urls.prefix1}/${dataset.webBin}` //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  49969. } */
  49970. let name = datasetId + '-'+pano.uuid;
  49971. let timeStamp = 0;
  49972. pano.index = index; //注意:index不等于uuid,因为有的uuid缺失。但是visibles中存的是下标!
  49973. Potree.loadPointCloud(cloudPath, name , name, timeStamp, e => { //开始加载点云
  49974. let scene = viewer.scene;
  49975. let pointcloud = e.pointcloud;
  49976. let config = Potree.config.material;
  49977. let material = pointcloud.material;
  49978. material.minSize = config.minSize;
  49979. material.maxSize = config.maxSize;
  49980. material.pointSizeType = /* 'ADAPTIVE'// */config.pointSizeType; //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
  49981. pointcloud.changePointSize( 0.1 /* config.realPointSize */ ); //material.size = config.pointSize;
  49982. pointcloud.changePointOpacity(1);
  49983. material.shape = Potree.PointShape.SQUARE;
  49984. pointcloud.color = config.pointColor;
  49985. pointcloud.dataset_id = datasetId; //多个点云指向一个datasetId
  49986. pointcloud.panoUuid = pano.uuid;
  49987. pointcloud.timeStamp = timeStamp;
  49988. //transformPointcloud(pointcloud, pano)
  49989. scene.addPointCloud(pointcloud);
  49990. pointcloudLoaded ++;
  49991. if(pointcloudLoaded == panoCount ){
  49992. datasetLoaded ++;
  49993. viewer.images360.addPanoData(panoData , datasetId );
  49994. if(datasetLoaded == datasetsCount){
  49995. pointcloudLoadDone();
  49996. }
  49997. }
  49998. });
  49999. });
  50000. };
  50001. if(!Potree.settings.isOfficial){
  50002. Potree.settings.datasetsPano = {'testDataset':null};
  50003. Potree.loadPanosInfo( data=>{loadPanosDone('testDataset', data.sweepLocations);} );
  50004. }
  50005. }
  50006. function mergeEditStart(dom, mapDom){
  50007. Potree.settings.editType = 'merge';
  50008. Potree.settings.intersectOnObjs = true;
  50009. Potree.settings.boundAddObjs = true;
  50010. Potree.settings.unableNavigate = true;
  50011. let viewer = new Potree.Viewer(dom, mapDom );
  50012. let Alignment = viewer.modules.Alignment;
  50013. viewer.setEDLEnabled(false);
  50014. viewer.setFOV(Potree.config.view.fov);
  50015. //viewer.loadSettingsFromURL();
  50016. {
  50017. viewer.mainViewport.view.position.set(30,30,30);
  50018. viewer.mainViewport.view.lookAt(0,0,0);
  50019. viewer.updateModelBound();//init
  50020. //this.bound = new THREE.Box3(new THREE.Vector3(-1,-1,-1),new THREE.Vector3(1,1,1))
  50021. viewer.transformationTool.setModeEnable(['translation','rotation'] );
  50022. //viewer.ssaaRenderPass.sampleLevel = 1 // sampleLevel为1 的话,ground就不会变黑
  50023. viewer.inputHandler.fixSelection = true; //不通过点击屏幕而切换transfrom选中状态
  50024. }
  50025. Potree.settings.sizeFitToLevel = true;//当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  50026. Potree.loadPointCloudScene = function(url, type, id, title, done, onError){//对应4dkk的场景码
  50027. let loadCloud = ({cloudPath, sceneName, sceneCode, timeStamp, color } )=>{
  50028. Potree.loadPointCloud(cloudPath, sceneName , sceneCode, timeStamp, e => {
  50029. let scene = viewer.scene;
  50030. let pointcloud = e.pointcloud;
  50031. let config = Potree.config.material;
  50032. let material = pointcloud.material;
  50033. material.minSize = config.minSize;
  50034. material.maxSize = config.maxSize;
  50035. material.pointSizeType = config.pointSizeType; //Potree.PointSizeType[config.pointSizeType]//Potree.PointSizeType.ADAPTIVE;//FIXED
  50036. pointcloud.changePointSize(config.realPointSize); //material.size = config.pointSize;
  50037. pointcloud.changePointOpacity(1);
  50038. material.shape = Potree.PointShape.SQUARE;
  50039. color && (pointcloud.color = pointcloud.material.color = color);
  50040. pointcloud.timeStamp = timeStamp;
  50041. //transformPointcloud(pointcloud, originDataset)
  50042. scene.addPointCloud(pointcloud);
  50043. {
  50044. viewer.updateModelBound();
  50045. let {boundSize, center} = viewer.bound;
  50046. viewer.dispatchEvent({type:'loadPointCloudDone'});
  50047. if(!Potree.settings.UserPointDensity){
  50048. Potree.settings.UserPointDensity = 'high';//'middle'
  50049. }
  50050. Potree.Log('loadPointCloudDone 点云加载完毕', {font:[null,10] });
  50051. }
  50052. /* Potree.loadPanos(dataset.id, (data) => { //暂时不加载panos了,因为没有id
  50053. //console.log('loadPanos',dataset.sceneCode, dataset.id, data)
  50054. viewer.images360.addPanoData(data, dataset.id )
  50055. viewer.images360.loadDone()
  50056. viewer.scene.add360Images(viewer.images360); */
  50057. viewer.dispatchEvent('allLoaded');
  50058. done(pointcloud);
  50059. },onError);
  50060. };
  50061. if(type == 'laser'){
  50062. let sceneCode = url;
  50063. Potree.loadDatasets((data)=>{
  50064. let originDataset = data.find(e=>e.sceneCode == sceneCode);//只加载初始数据集
  50065. let timeStamp = originDataset.updateTime ? originDataset.updateTime.replace(/[^0-9]/ig,'') : ''; //每重算一次后缀随updateTime更新一次
  50066. //let cloudPath = `${Potree.settings.urls.prefix1}/${Potree.settings.webSite}/${sceneCode}/data/${sceneCode}/webcloud/cloud.js`
  50067. let cloudPath = `${Potree.settings.urls.prefix1}/${originDataset.webBin}`; //webBin添加原因:每次裁剪之类的操作会换路径,因为oss文件缓存太严重,更新慢
  50068. loadCloud({cloudPath, sceneName:originDataset.sceneName, sceneCode, timeStamp, color:originDataset.color});
  50069. }, sceneCode, onError);
  50070. }else {//las or ply 直接用url
  50071. let name = type + '|' + id + '|' + title;
  50072. if(url instanceof Array){
  50073. if(url.length == 1){
  50074. url = url[0];
  50075. }else {
  50076. console.error('有多个点云?暂时还不支持', url, name);//多个点云要一起移动没想好怎么写
  50077. }
  50078. }
  50079. let cloudPath = url + '/cloud.js';
  50080. loadCloud({cloudPath, sceneName:name, sceneCode:name, timeStamp:'' });
  50081. }
  50082. };
  50083. let setMatrix = (pointcloud)=>{//为了漫游点变换,要算一下 类似setMatrix
  50084. /* pointcloud.transformMatrix = new THREE.Matrix4().multiplyMatrices(pointcloud.matrix, pointcloud.pos1MatrixInvert)//还原一点位移
  50085. pointcloud.transformInvMatrix.copy(pointcloud.transformMatrix).invert()
  50086. pointcloud.rotateMatrix = new THREE.Matrix4().makeRotationFromEuler(pointcloud.rotation);
  50087. pointcloud.rotateInvMatrix.copy(pointcloud.rotateMatrix).invert()
  50088. pointcloud.panos.forEach(e=>e.transformByPointcloud()) */
  50089. //pointcloud.updateBound()
  50090. //pointcloud.getPanosBound()
  50091. viewer.updateModelBound();
  50092. };
  50093. let moveModel = (e)=>{//根据鼠标移动的位置改变位置
  50094. let camera = viewer.mainViewport.camera;
  50095. var origin = new Vector3(e.pointer.x, e.pointer.y, -1).unproject(camera),
  50096. end = new Vector3(e.pointer.x, e.pointer.y, 1).unproject(camera);
  50097. var dir = end.sub(origin);
  50098. let planeZ = 0;
  50099. let r = (planeZ - origin.z)/dir.z;
  50100. let x = r * dir.x + origin.x;
  50101. let y = r * dir.y + origin.y;
  50102. //过后改为根据intersect的点来设置底部高度;这样的话,需要发送高度
  50103. /*let pos = new THREE.Vector3(x,y, planeZ )
  50104. modelEditing.updateMatrixWorld()
  50105. let boundCenter = modelEditing.boundingBox.getCenter(new THREE.Vector3).applyMatrix4(modelEditing.matrixWorld);
  50106. */
  50107. MergeEditor.moveBoundCenterTo(modelEditing,new Vector3(x,y, modelEditing.boundCenter.z)); //使模型中心的xy在鼠标所在位置
  50108. modelEditing.dispatchEvent("position_changed");
  50109. };
  50110. let cancelMove = ()=>{
  50111. modelEditing = null;
  50112. viewer.removeEventListener('global_mousemove', moveModel);
  50113. viewer.removeEventListener('global_click', confirmPos);
  50114. };
  50115. let confirmPos = ()=>{
  50116. MergeEditor.focusOn(modelEditing);
  50117. cancelMove();
  50118. return {stopContinue:true}
  50119. };
  50120. let modelType, modelEditing, MergeEditor = viewer.modules.MergeEditor;
  50121. Potree.addModel = function(prop, done, onProgress, onError){ //加载模型
  50122. let loadDone = (model)=>{
  50123. model.dataset_id = prop.id; //唯一标识
  50124. if(prop.position){
  50125. model.position.copy(prop.position);
  50126. }
  50127. if(prop.rotation){
  50128. //model.rotation.setFromVector3(prop.rotation)
  50129. model.rotation.copy(prop.rotation);
  50130. }
  50131. if(prop.scale){
  50132. model.scale.set(prop.scale,prop.scale,prop.scale);
  50133. }
  50134. if(model.isPointcloud){
  50135. model.renderOrder = Potree.config.renderOrders.model; //same as glb
  50136. }
  50137. if(Potree.settings.maintainBtmZ)
  50138. {//transform --------维持离地高度和中心点的版本(local ver)
  50139. let updateBound = ()=>{
  50140. model.updateMatrixWorld();
  50141. viewer.updateModelBound();
  50142. };
  50143. let maintainBtmZAndCenter = ()=>{
  50144. MergeEditor.maintainBoundXY(model);
  50145. MergeEditor.setModelBtmHeight(model);
  50146. updateBound();
  50147. model.dispatchEvent('transformChanged');
  50148. };
  50149. model.addEventListener('position_changed', ()=>{
  50150. updateBound();
  50151. MergeEditor.getBoundCenter(model);//更新boundcenter
  50152. MergeEditor.computeBtmHeight(model);
  50153. if(prop.bottomRange && (model.btmHeight > prop.bottomRange.max || model.btmHeight < prop.bottomRange.min)){
  50154. model.btmHeight = MathUtils.clamp(model.btmHeight, prop.bottomRange.min, prop.bottomRange.max);
  50155. MergeEditor.setModelBtmHeight(model);
  50156. updateBound();
  50157. }
  50158. model.dispatchEvent('transformChanged');
  50159. });
  50160. model.addEventListener("rotation_changed", maintainBtmZAndCenter );
  50161. model.addEventListener("scale_changed", maintainBtmZAndCenter );
  50162. model.addEventListener('transformChanged', ()=>{
  50163. MergeEditor.modelTransformCallback(model);
  50164. });
  50165. //离地高度只是boundingbox在transform后的最低点的高度,而非模型transform后的最低点的高度,所以旋转过后看起来不太准确
  50166. } else
  50167. {//transform --------维持中心点的版本
  50168. let updateBound = ()=>{
  50169. model.updateMatrixWorld();
  50170. viewer.updateModelBound();
  50171. };
  50172. let maintainCenter = ()=>{
  50173. //MergeEditor.maintainBoundXY(model)
  50174. MergeEditor.maintainBoundCenter(model);
  50175. updateBound();
  50176. model.dispatchEvent('transformChanged');
  50177. };
  50178. model.addEventListener('position_changed', ()=>{
  50179. updateBound();
  50180. MergeEditor.getBoundCenter(model);//更新boundcenter
  50181. model.dispatchEvent('transformChanged');
  50182. });
  50183. model.addEventListener("rotation_changed", maintainCenter );
  50184. model.addEventListener("scale_changed", maintainCenter );
  50185. model.addEventListener('transformChanged', ()=>{
  50186. MergeEditor.modelTransformCallback(model);
  50187. });
  50188. }
  50189. model.updateMatrixWorld();
  50190. viewer.updateModelBound();
  50191. MergeEditor.getBoundCenter(model); //初始化
  50192. model.lastMatrixWorld = model.matrixWorld.clone();
  50193. done(model); // 先发送成功,因为2d界面会随机执行changePosition等初始化,然后这边再将模型移到中心地面上
  50194. if(prop.isFirstLoad){
  50195. MergeEditor.moveBoundCenterTo(model, new Vector3(0,0,0));
  50196. MergeEditor.setModelBtmHeight(model, 0); //初始加载设置离地高度为0
  50197. if(prop.mode != 'single'){//如果不是模型展示页,模型会随着鼠标位置移动
  50198. modelEditing = model;
  50199. /* if(model.fileType == '3dTiles'){
  50200. setTimeout(()=>{
  50201. moveModel({pointer:{x:0,y:0}}) //3dTiles的移动会错乱,先默认放在当前视图中间吧
  50202. confirmPos()
  50203. },1)
  50204. }else{ */
  50205. viewer.addEventListener('global_mousemove', moveModel);
  50206. viewer.addEventListener('global_click', confirmPos, {importance:3});
  50207. //}
  50208. }
  50209. model.dispatchEvent("position_changed");
  50210. }else {
  50211. //MergeEditor.setModelBtmHeight(model, prop.bottom || 0) //默认离地高度为0
  50212. modelEditing = null;
  50213. }
  50214. MergeEditor.modelAdded(model);
  50215. };
  50216. if(prop.type == 'glb'){
  50217. let callback = (object)=>{
  50218. //focusOnSelect(object, 1000)
  50219. object.isModel = true;
  50220. //object.dataset_id = Date.now() //暂时
  50221. object.traverse(e=>e.material && (e.material.transparent = true));
  50222. /* object.addEventListener('click',(e)=>{
  50223. //只是为了能得到hoverElement识别才加这个侦听
  50224. }) */
  50225. loadDone(object);
  50226. };
  50227. let info = {
  50228. fileType: prop.type,
  50229. id: prop.id,
  50230. //unlit:true,
  50231. url : prop.url,
  50232. name : prop.title,
  50233. /* transform : {
  50234. position : prop.position,
  50235. rotation : new THREE.Euler().setFromVector3(prop.rotation),
  50236. scale: new THREE.Vector3(prop.scale,prop.scale,prop.scale),
  50237. } */
  50238. };
  50239. viewer.loadModel(info , callback, onProgress, onError);
  50240. }else if(prop.type == 'osgb' || prop.type == 'b3dm'){ //3d tiles
  50241. let callback = (object)=>{
  50242. object.isModel = true;
  50243. //透明度怎么办
  50244. //object.traverse(e=>e.material && (e.material.transparent = true))
  50245. loadDone(object);
  50246. };
  50247. viewer.loadModel({
  50248. fileType: '3dTiles',
  50249. id: prop.id,
  50250. name : prop.title,
  50251. maximumScreenSpaceError: prop.maximumScreenSpaceError,
  50252. /* tilesUrl: 'https://4dkk.4dage.com/scene_view_data/SS-Ds19qsmuFA/images/3dtiles/tileset.json',
  50253. transform : {
  50254. rotation : [Math.PI/2, 0, 0],
  50255. position : [0,0,0]
  50256. }
  50257. tilesUrl: 'https://testgis.4dage.com/LVBADUI_qp/tileset.json',
  50258. transform : {
  50259. rotation : [0, 0, 0],
  50260. position : [0,0,0]
  50261. } */
  50262. url:prop.url,
  50263. },callback,onprogress);
  50264. }else if(prop.type == 'shp'){
  50265. viewer.loadModel({
  50266. fileType: 'shp',
  50267. id: prop.id,
  50268. name : prop.title,
  50269. url:prop.url,
  50270. },callback,onprogress);
  50271. //shpModel.position.set(-330000, 900000,10)//尽量移动到原点。原位置在江门那
  50272. }else if(prop.type == '3dgs'){
  50273. let callback = (object)=>{
  50274. object.isModel = true;
  50275. loadDone(object);
  50276. };
  50277. viewer.loadModel({
  50278. fileType: '3dgs',
  50279. id: prop.id,
  50280. name : prop.title,
  50281. url:prop.url,
  50282. },callback,onprogress);
  50283. }else {
  50284. //else if(prop.type == 'las' || prop.type == 'ply' || prop.type == 'laz' )
  50285. Potree.loadPointCloudScene(prop.url, prop.type, prop.modelId, prop.title, (pointcloud)=>{
  50286. pointcloud.matrixAutoUpdate = true;
  50287. pointcloud.initialPosition = pointcloud.position.clone();
  50288. pointcloud.pos1MatrixInvert = new Matrix4().setPosition(pointcloud.initialPosition).invert();
  50289. /* let maintainBtmZ = ()=>{
  50290. MergeEditor.setModelBtmHeight(pointcloud)
  50291. updateMatrix()
  50292. }
  50293. let updateMatrix = ()=>{
  50294. setMatrix(pointcloud)
  50295. pointcloud.dispatchEvent('transformChanged')
  50296. }
  50297. pointcloud.addEventListener('position_changed', updateMatrix )
  50298. pointcloud.addEventListener("orientation_changed", maintainBtmZ )
  50299. pointcloud.addEventListener("scale_changed", maintainBtmZ ) */
  50300. loadDone(pointcloud);
  50301. /* pointcloud.addEventListener('select',(e)=>{
  50302. if(Potree.settings.displayMode == 'showPanos')return
  50303. console.log('select',e)
  50304. //viewer.setControls(viewer.orbitControls)
  50305. MergeEditor.focusOnSelect(pointcloud)
  50306. viewer.outlinePass.selectedObjects = [pointcloud]
  50307. return {stopContinue:true}
  50308. },{importance:1})
  50309. pointcloud.addEventListener('deselect',(e)=>{
  50310. console.log('deselect',e)
  50311. //viewer.setControls(viewer.fpControls)
  50312. viewer.outlinePass.selectedObjects = []
  50313. }) */
  50314. }, onError);
  50315. }
  50316. };
  50317. return {THREE: THREE$1}
  50318. }
  50319. var changeLog = ()=>{
  50320. var textarea = document.createElement('textarea');
  50321. textarea.id = "consoleLog";
  50322. textarea.style.width = '160px';
  50323. textarea.style.height = '200px';
  50324. textarea.style.position = 'fixed';
  50325. textarea.style.left = 0;
  50326. textarea.style.bottom = '50px';
  50327. textarea.style['z-index'] = 9999;
  50328. textarea.style.color = 'black';
  50329. textarea.style.opacity = 0.9;
  50330. textarea.style['font-size'] = '12px';
  50331. textarea.style['backgroundColor'] = '#ffffff';
  50332. document.getElementsByTagName("body")[0].appendChild(textarea);
  50333. var list = ["log", "error", "warn", "debug", "info", "time", "timeEnd"];
  50334. var exchange = function (o) {
  50335. console["old" + o] = console[o];
  50336. console[o] = function () {
  50337. var args = Array.from(arguments);
  50338. console["old" + o].apply(this, arguments);
  50339. var t = document.getElementById("consoleLog").innerHTML;
  50340. var str = '';
  50341. args.forEach(a=>{
  50342. str += a + ' ';
  50343. });
  50344. document.getElementById("consoleLog").innerHTML = str + "\n\n" + t;
  50345. };
  50346. };
  50347. for (var i = 0; i < list.length; i++) {
  50348. exchange(list[i]);
  50349. }
  50350. };
  50351. /*
  50352. 坐标转换问题:
  50353. 由于控制点可以随便输入,所以本地和地理位置的转换也是可拉伸的。而navvis的转换是等比由中心展开,
  50354. 所以对比两种转化方式时误差较大。
  50355. 另外地理注册控制点是有参考数据集的,若参考数据集和我放置在0,0,0的数据集一致,就可直接使用,否则要转换。
  50356. ---------
  50357. lonlat和空间坐标其实并非线性关系,因为lonlat其实是角度。当两个数据集在地球两端时,它们之间的夹角都相差180度了。
  50358. 所以若要准确展示的话,需要将点云内所有物体,如漫游点,都先获取lonlat再去算local。或者直接将点云整体的transformMatrix考虑上在地球上相对于初始数据集的偏转。
  50359. 支持ctrl+z、ctrl+Y 撤销回退的页面有:
  50360. 测量、土方量、空间模型 这三个页面的点线拖拽;点云裁剪、点云下载中的裁剪 的框; 点云编辑的变换; 数据集校准;
  50361. (所有数据一旦删除则无效 )
  50362. 其他快捷键:
  50363. 按alt鼠标滚轮或WS键放慢。
  50364. 测量or土方量: 按Alt键可以平行拖拽点。&dragPolyBeyondPoint 后缀则可平行拖拽到无点云区域 。
  50365. 按M键拖拽点可以复制出当前点
  50366. 点云按空格键+左键拖拽场景,可以不改相机位置的旋转视角
  50367. */
  50368. //xzw add
  50369. const config$1 = {//配置参数 不可修改
  50370. displayMode:{
  50371. showPointCloud:{
  50372. atPano:{
  50373. showPoint : true,
  50374. showSkybox: false,
  50375. pointUsePanoTex : false
  50376. },
  50377. transition:{
  50378. showPoint: true,
  50379. showSkybox: false,
  50380. pointUsePanoTex: false
  50381. },
  50382. canLeavePano: true //是否能离开pano位置
  50383. },
  50384. showPanos:{
  50385. atPano:{
  50386. showPoint : false,
  50387. showSkybox: true,
  50388. pointUsePanoTex : false
  50389. },
  50390. transition:{
  50391. //showPoint: true,
  50392. showSkybox: true,
  50393. //pointUsePanoTex: true //是否使用全景贴图
  50394. },
  50395. canLeavePano: false
  50396. },
  50397. showBoth:{
  50398. atPano:{
  50399. showPoint : true,
  50400. showSkybox: true,
  50401. pointUsePanoTex : false //?
  50402. },
  50403. transition:{
  50404. showPoint: true,
  50405. showSkybox: true,
  50406. pointUsePanoTex: true
  50407. },
  50408. canLeavePano: true //是否能离开pano位置 离开后自动变为showPointCloud
  50409. },
  50410. //test:
  50411. pointUsePanoTex:{ //---静止时调点云
  50412. atPano:{
  50413. showPoint : true,
  50414. showSkybox: false,
  50415. pointUsePanoTex : true
  50416. },
  50417. transition:{
  50418. showPoint: true,
  50419. showSkybox: true,
  50420. pointUsePanoTex: true //是否使用全景贴图
  50421. },
  50422. canLeavePano: false
  50423. },
  50424. },
  50425. urls:{
  50426. //localTextures:'../resources/textures/',
  50427. prefix1: 'https://laser-oss.4dkankan.com',//oss
  50428. prefix2: 'https://testlaser.4dkankan.com',
  50429. prefix3: 'https://4dkk.4dage.com',
  50430. prefix4: 'https://uat-laser.4dkankan.com',//test.4dkankan
  50431. prefix5: 'https://laser.4dkankan.com/backend',
  50432. prefix6: 'https://mix3d.4dkankan.com/backend', //融合
  50433. prefix7: 'https://xfhd.4dkankan.com/backend', //融合
  50434. },
  50435. transitionsTime:{
  50436. flyMinTime : 650 , // 毫秒/米
  50437. flytimeDistanceMultiplier: 120 ,
  50438. }
  50439. ,
  50440. view:{
  50441. fov:70, //navvis:50
  50442. near:0.1,
  50443. far: 10000,
  50444. },
  50445. map:{//mapViewer
  50446. mapHeight : -1000,//要比点云低。最低
  50447. cameraHeight : 1000, //最高 ,注意(如sitemodel)其他的物体不能超过这个高度
  50448. },
  50449. minNodeSize:30, // perspectiveCamera允许加载的node的最小可见像素宽度。越大越省性能
  50450. tiles3DMaxMemory: 100,//M. 最大支持3dTiles的内存大小 超出会崩溃。 改太小太大都会卡,太大崩溃
  50451. pointDensity:{
  50452. magnifier:{
  50453. maxLevelPercent: 1,
  50454. pointBudget : 1*1000*1000, //至少显示这么多
  50455. minNodeSize : 5, //pick时调高精度
  50456. },
  50457. panorama:{//显示全景时的漫游。因为点只能显示1个像素的大小,所以必须很密集,但又要限制点的数量
  50458. maxLevelPercent: 0.6,
  50459. pointBudget : /* 4*1000*1000// */browser.isMobile() ? 0.2*1000*1000 : 0.4*1000*1000, //点云总最大数
  50460. minNodeSize : 100,
  50461. },
  50462. fourViewports:{//分四屏时防止卡顿
  50463. maxLevelPercent: 0.9,
  50464. pointBudget :3*1000*1000, // 只要限制这个就足够 (为什么分屏focus区域不同会闪烁,navvis不会)(navvis:maxLevel:5,pointBudget:1*1000*1000)
  50465. minNodeSize : 70,
  50466. },
  50467. fourViewportsMain:{//分四屏时防止卡顿
  50468. maxLevelPercent: 0.9,
  50469. pointBudget :3*1000*1000, // 只要限制这个就足够 (为什么分屏focus区域不同会闪烁,navvis不会)(navvis:maxLevel:5,pointBudget:1*1000*1000)
  50470. minNodeSize : 70,
  50471. }
  50472. ,
  50473. panoEdit:{
  50474. maxLevelPercent: 1, //在远处时由于pointBudget限制而展示稀疏,凑近时就变为最高质量了
  50475. pointBudget :4*1000*1000, //要使点云达到200个以上时还不卡
  50476. percentByUser:true,
  50477. minNodeSize : 80 , //点云多的话远处的尽量就不可见吧
  50478. },
  50479. low:{//highPerformance
  50480. maxLevelPercent: 0.4, //最小为0
  50481. percentByUser:true, //如果用户定义了percent,使用用户的
  50482. pointBudget : browser.isMobile() ? 1*1000*1000 : 2*1000*1000,
  50483. minNodeSize : 40 / window.devicePixelRatio ,
  50484. },
  50485. middle:{//balanced //不同场景相同级别所产生的numVisibleNodes和numVisiblePoints不同,如果分层比较细,可能要到level8才能看清,那么level5看到的点就很大且很少,如隧道t-e2Kb2iU
  50486. maxLevelPercent: 0.7,
  50487. percentByUser:true,
  50488. pointBudget: browser.isMobile() ? 1.5*1000*1000 : 3.5*1000*1000,
  50489. minNodeSize : 30 / window.devicePixelRatio ,
  50490. },
  50491. high:{//highQuality
  50492. maxLevelPercent: 1,
  50493. percentByUser:true,
  50494. pointBudget:browser.isMobile() ? 3*1000*1000 : 6*1000*1000, //原本最高是8,但是大部分电脑都太卡了,降
  50495. minNodeSize : 20 / window.devicePixelRatio , //手机上因为像素点小,远一点的时候更需要加载密集的点云。(没事,有pointBudget限制着,会先从近处加载高级node,再远就不加载了)
  50496. },
  50497. screenshot:{
  50498. maxLevelPercent: 1,
  50499. pointBudget: browser.isMobile() ? 4*1000*1000 : 10*1000*1000, //一般只有电脑需要截图,手机的加载多会崩
  50500. minNodeSize : 40 / window.devicePixelRatio ,
  50501. },
  50502. screenshot2:{
  50503. maxLevelPercent: 1,
  50504. pointBudget: browser.isMobile() ? 8*1000*1000 : 15*1000*1000,
  50505. minNodeSize : 20 / window.devicePixelRatio ,
  50506. },
  50507. ultraHigh:{
  50508. maxLevelPercent: 1,
  50509. pointBudget: 20*1000*1000,
  50510. minNodeSize : 10 / window.devicePixelRatio,
  50511. }
  50512. //数值由testLevelSteps得来,其中nodeMaxLevel为2时,low和middle的都是1,如果真有这么低的点云就单独处理下。
  50513. //多个viewport尽量保证pointBudget一样,或者pointBudget不能太低于所需,否则会反复加载了又清除
  50514. },
  50515. clip:{
  50516. color: '#FFC266', //map
  50517. },
  50518. measure:{
  50519. color:'#00C8AF',
  50520. default:{
  50521. color:"#64C8BB",//"#00c7b2",
  50522. opacity:0.7
  50523. },
  50524. highlight:{
  50525. color:'#00C8AF',//"#00c7b2",
  50526. opacity:1,
  50527. labelOpacity:0.7//1会挡住线和端点
  50528. },
  50529. guide:{
  50530. color:'#FFFFFF',
  50531. opacity:0.8
  50532. }
  50533. ,
  50534. backColor:'#333333',
  50535. lineWidth: 3,
  50536. textColor: "#000000", //"#FFFFFF"
  50537. mulLabelHideFaraway : false ,// 多折线根据远近显示label
  50538. adsorptMinDis : 30, //最小吸附距离(像素)
  50539. },
  50540. material:{//初始化
  50541. pointSize: 0.1,
  50542. realPointSize : 0.1,//实际上的ui滑动条默认大小(兼容旧的版本)
  50543. minSize: 0.1,
  50544. maxSize: 10000,
  50545. pointSizeType: 'ATTENUATED', //'ADAPTIVE'//'ADAPTIVE' \ FIXED //ADAPTIVE的在小房间里大小会不太匹配,但在远景似乎更好
  50546. /*
  50547. ATTENUATED : 衰减 真实大小,靠近时感觉是点云一点点变多,缝隙变小
  50548. ADAPTIVE: 自适应 大小根据level变化,越高越小。靠近时感觉点云由大慢慢细分成小份。这个感觉更佳但是navvis为何不用这个
  50549. */
  50550. absolutePanoramaSize: 1.3 ,//全景漫游时的size 是fixed的模式
  50551. //sizeAtPanoRtEDL : 2000,
  50552. pointColor:'#ffffff',
  50553. //sizeAddAtPanoRtEDL : 0.5, //全景模式静止时的size
  50554. //ADAPTIVE : 字会失真扭曲
  50555. //'ATTENUATED' 往旁边看有缝隙、点在浮动
  50556. }
  50557. ,
  50558. skyboxBgWidth : 100 ,
  50559. renderLayers:{//渲染层,方便分批渲染管理,替代scene的创建。数字不代表顺序。(数字不能太大)
  50560. bg: 20,
  50561. bg2: 21,
  50562. skybox: 1,
  50563. pointcloud: 11,
  50564. sceneObjects:0,//default
  50565. model : 2,
  50566. light: 15,
  50567. measure:4,
  50568. magnifier:5,
  50569. magnifierContent:16,
  50570. volume:6,
  50571. transformationTool:7,
  50572. map:8,
  50573. mapObjects:9,//default
  50574. bothMapAndScene: 3,
  50575. siteModeOnlyMapVisi:12,//只能mapViewer可见
  50576. siteModelMapUnvisi:13,//只有mapViewer不可见
  50577. siteModeSideVisi:14,//只有侧面可见
  50578. layer1: 18,// 备用1
  50579. layer2: 17,// 备用2
  50580. },
  50581. renderOrders:{ //会影响到绘制、pick时的顺序。
  50582. model:10,
  50583. reticule:5,
  50584. measureMarker: 6,
  50585. measureLabelSub: 7,
  50586. measureLabel: 8,
  50587. sorptionSign:10,
  50588. model:10,
  50589. magnifier:50,
  50590. },
  50591. siteModel:{
  50592. names:{
  50593. 'building': '建筑',
  50594. 'floor':'楼层',
  50595. 'room':'房间'
  50596. },
  50597. floorHeightDefault: 5,//一层楼的高度
  50598. },
  50599. panosEdit:{
  50600. },
  50601. tiling: {
  50602. panoPreRenderRepeatDelay: 2500,
  50603. panoPreRenderDelay: 500,
  50604. preRenderTourPanos: browser.valueFromHash("tileprerender", 0),
  50605. tilingFlagNames: ["usetiles", "tiles"],
  50606. maxNavPanoQuality: browser.valueFromHash("maxtileq", null),
  50607. maxZoomPanoQuality: browser.valueFromHash("maxztileq", null),
  50608. overlayStyle: browser.valueFromHash("tileoverlay", 0),
  50609. uploadIntervalDelay: browser.valueFromHash("tileupdelay", 10 ),
  50610. initialIntervalDelay: browser.valueFromHash("itiledelay", 0),
  50611. maxNonBaseUploadsPerFrame: browser.valueFromHash("maxnbtpf", 1),
  50612. maxBaseUploadsPerFrame: browser.valueFromHash("maxbtpf",6),
  50613. customCompression: browser.valueFromHash("tilecustcomp", 0),
  50614. mobileHighQualityOverride: !1,
  50615. allowUltraHighResolution: !0
  50616. },
  50617. navigation: {
  50618. panoScores: !1,
  50619. mouseDirection: !0,
  50620. filterStrictness: .75,
  50621. angleFactor: -30,
  50622. directionFactor: 10,
  50623. distanceFactor: -1,
  50624. optionalityFactor: 3
  50625. }
  50626. ,
  50627. axis : { 'x':{color:'#ea3f3f'/* '#d0021b' */ /* 'red' */}, 'y':{ color:'#86c215' /* '#86c542' *//* 'green' */}, 'z': {color:'#3396f8'/* '#3399c8' */ /* 'blue' */}, 'xyz':{color:'#ccc',}},
  50628. shelterMargin:0.15, //多少米内不算遮挡 (有的场景深度图不准,和点云差别蛮大如SG-t-24F0iT3pKAO)
  50629. highQualityMaxZoom: 2,
  50630. ultraHighQualityMaxZoom: 3,
  50631. panoFieldRadius : 10, //当前位置多远范围内可以切全景模式
  50632. clickMaxDragDis:3,
  50633. clickMaxPressTime:200, //ms
  50634. doubleClickTime:300,//双击间隔时间
  50635. testNodeCount1: browser.isMobile() ? 6 : 4, //testMaxNode次数达到这个数字时,changePointSize才使用nodeMaxLevel。 (调试时比较卡,在线上实际只需要3)
  50636. background: '#232323',
  50637. mapBG:/* '#232323', */ '#F5F5F5', //地图的clearColor
  50638. pickFrontPointRatio:50,
  50639. colors: { //from navvis
  50640. red: [213,0,0],
  50641. pink: [197,17,98],
  50642. purple: [170,0,255],
  50643. "deep purple": [98,0,234],
  50644. blue: [ 41,98,255],
  50645. "light blue": [ 0,145,234],
  50646. cyan: [ 0,184,212],
  50647. teal: [ 0,191,165],
  50648. green: [0,200,83],
  50649. "light green": [ 100,221,23],
  50650. lime: [ 174,234,0],
  50651. yellow: [ 255,214,0],
  50652. amber: [ 255,171,0],
  50653. orange: [ 255,109,0],
  50654. "deep orange": [ 255,61,0],
  50655. },
  50656. depthTexUVyLimit: 0.141, // 在这个范围内是没有深度的,从图片算的0.14003, 设置为稍大于这个数值
  50657. };
  50658. config$1.OrthoCameraLimit = {
  50659. standard:{
  50660. zoom:{min:0.0004, max:500}, //如果camera缩太小,地图会因为数字边界问题而扭曲
  50661. latPad:20,
  50662. xBound:[-4e6, 4e6],
  50663. },
  50664. expand:{
  50665. zoom:{min:0.0004, max:500}, //如果camera缩太小,地图会因为数字边界问题而扭曲
  50666. latPad:20,
  50667. xBound:[-6e6, 6e6],
  50668. },
  50669. };
  50670. /* 显示模式:
  50671. 1只显示点云: 滚轮为前进后退,方向键可以行走。进入漫游点时自动变为混合(这样全景可以弥补缝隙),过渡时只显示点云。
  50672. 2只显示全景: 不能任意行走。 过渡时显示贴图材质非edl的点云(否则有折痕不贴合)。
  50673. 3混合:都显示。 不能任意行走。过渡时显示贴图材质非edl的点云(因为只显示点云的话不太美,点云很碎,不细腻)
  50674. */
  50675. window.testLevelSteps = function(steps){//[0.4,0.7,1]
  50676. if(!steps){
  50677. let s = Potree.config.pointDensity;
  50678. steps = [s.low.maxLevelPercent, s.middle.maxLevelPercent, s.high.maxLevelPercent, ];
  50679. }
  50680. let max = 1;
  50681. while(++max<=12){
  50682. let r1 = steps.map(e=>e * max);
  50683. let r2 = steps.map(e=>Math.round(e * max));
  50684. console.log(`当nodeMaxLevel为${max}时,每一级的level分别为${r2}, (小数:${r1})`);
  50685. }
  50686. console.log('请检查每一层的三个level是否有重复');
  50687. };
  50688. function getPrefix(){
  50689. let u = window.location.href.split('//');
  50690. let v = u[1].split('/');
  50691. return v[0]
  50692. }
  50693. let isTest = browser.urlHasValue('test');
  50694. let settings = {//设置 可修改
  50695. editType : '',
  50696. number: '', //场景序号
  50697. originDatasetId:'',//场景原本的数据集id,应该就是数据集第一个吧
  50698. isOfficial:false,
  50699. webSite:'testdata',//正式:'datav1', //不同环境对应的静态文件的地址不同
  50700. isLocal:false, //是否本地 局域网版本
  50701. libsUrl:'../libs/',
  50702. displayMode:'',
  50703. isTest ,
  50704. prefix: getPrefix(),
  50705. pointDensity: '', UserPointDensity:'',//pointDensity会随着进入不同的模块而自动改变,UserPointDensity记录了用户的设置
  50706. UserDensityPercent:null,//点云密度百分比
  50707. ifShowMarker:true,//显示漫游点
  50708. floorplanType:{},//平面图类型 'default' | 'diy' 不同数据集不同{datasetId:...}
  50709. floorplanEnable:false,
  50710. floorplanEnables:{},
  50711. floorplanRequests:{},//开始加载了的
  50712. mapEnable:true,//地图区域是否加载地图
  50713. cameraFar : config$1.view.far, //相机最远范围 1-300
  50714. //limitFar: true, //是否使用setting的cameraFar来限制(如在点云裁剪时为false)
  50715. showPanoMesh:false, //显示小球,
  50716. dblToFocusPoint:false,//调试时如果需要双击飞向某个点云的点,就打开。此时不在漫游点的话单击将无法漫游。//因和单击漫游冲突
  50717. unableNavigate : false,//进入如裁剪界面时 禁止漫游
  50718. sizeFitToLevel: false,//当type为衰减模式时自动根据level调节大小。每长一级,大小就除以2
  50719. zoom:{
  50720. enabled : true,
  50721. min:1,
  50722. max: config$1.highQualityMaxZoom
  50723. },
  50724. navConstantly:true,
  50725. navTileClass: /* browser.isMobile() ? '1k' : */ '2k', //默认加载到
  50726. tileClass:'4k', //最高可达
  50727. /* loadTilesWhenUnfocus:false, //页面unfocus时也仍在加载tiles
  50728. loadPointsWhenUnfocus:true, //页面unfocus时也仍在加载点云 */
  50729. //initialShowPano:true
  50730. drawEntityData: false, //包括marker、线
  50731. zoomFromPointert:{//定点缩放(包括点云模式、全景模式、地图)
  50732. whenPanos:true,
  50733. whenPointCloud:true,
  50734. map:true,
  50735. },
  50736. rotAroundPoint:true,//点云模式是否能绕intersectPoint旋转
  50737. tourTestCameraMove:false, //测试镜头时,不移动真实的镜头, 只移动frustum
  50738. cameraAniSmoothRatio : 20, //镜头动画平滑系数,越高越平滑
  50739. urls : $.extend({}, config$1.urls, {
  50740. prefix : config$1.urls.prefix4 //主要使用的 是测试环境,根据不同工程更改
  50741. }),
  50742. useDepthTex: true,//使用深度贴图,但不代表一定有(得到的intersect更快速准确和稳定) SS-t-7DUfWAUZ3V
  50743. //matUseDepth:false,
  50744. //panoEdit:
  50745. datasetsPanos:{},
  50746. //mergeModel:
  50747. boundAddObjs:false,
  50748. intersectOnObjs:false,
  50749. intersectWhenHover:true,
  50750. depTexLocBindDataset: true,//是否在pano模式下,使用深度图得到intersect的话,改intersect能属于该pano所在的点云。也就相当于在全景模式下intersect的点属于该全景图
  50751. notAdditiveBlending:false, //点云是否使用普通的blend, 否则会曝光过渡
  50752. precision:2, // 两位小数
  50753. unit: 'm',
  50754. useV4url:true, //v4的全景图等路径不一样 scene_view_data
  50755. useRTskybox:true, //直接使用rtEDL绘制到屏幕,当是全景模式时. 在降4倍时能给render节省1毫秒,gpu时间未测
  50756. useRTPoint:true, //直接使用rtEDL绘制到屏幕,当是点云模式时。可以大大节省gpu时间。但有锯齿
  50757. pointEnableRT:false,//点云模式时是否绘制到rtEDL。如果不需要遮挡效果就不需绘制
  50758. cloudSameMat:true, //因为点云个数较多,就使用相同的材质,可见降低绘制速度(要保证所有点云的maxNodelevel一样,且要算出 material.spacing的平均值)
  50759. showCompass : false,
  50760. showAxis : isTest,
  50761. //testCube : true,
  50762. // moveToCenter:true, //针对数据集间隔很远的场景 dis>5000 容易抖动
  50763. tiles3DMaxMemory: config$1.tiles3DMaxMemory,
  50764. adsorption:false,//测量时吸附点
  50765. pickFrontPointRatio:config$1.pickFrontPointRatio, //默认pick点云时选中靠近镜头的点的偏向
  50766. dragPolyBeyondPoint: browser.urlHasValue('dragPolyBeyondPoint'), //ctrlPolygon是否可以拖拽到没点云的地方
  50767. panoZoomByPointer: false,//全景图是否定点缩放
  50768. areaAtNotPlane: false,
  50769. fastTran: isTest
  50770. };
  50771. Potree.config = config$1;
  50772. Potree.settings = settings;
  50773. settings.isLocalhost = settings.prefix.includes('localhost:') || settings.prefix.includes('192.168.0.113:');
  50774. settings.isFormal = browser.urlHasValue('formal');//正式环境 本地测试
  50775. if(settings.isFormal){
  50776. settings.urls.prefix = settings.urls.prefix5;
  50777. settings.webSite = 'datav1';
  50778. }
  50779. let texLoader$2 = new TextureLoader();
  50780. texLoader$2.crossOrigin = "anonymous";
  50781. let createErrorMaterial = function() {
  50782. var t = new MeshBasicMaterial({
  50783. transparent: !0,
  50784. depthWrite: !1,
  50785. depthTest: !0,
  50786. opacity: 1,
  50787. side: DoubleSide
  50788. });
  50789. return t.color = new Color(3355443),
  50790. t
  50791. };
  50792. let tempVector = new Vector3, //sharedata
  50793. face1 = new Face3(0,1,2),
  50794. face2 = new Face3(2,3,0),
  50795. errorMaterial = createErrorMaterial(),
  50796. uv00 = new Vector2(0,0),
  50797. uv01 = new Vector2(0,1),
  50798. uv10 = new Vector2(1,0),
  50799. uv11 = new Vector2(1,1),
  50800. face1UV = [uv00, uv10, uv11],
  50801. face2UV = [uv11, uv01, uv00];
  50802. const HALF_WORLD_SIZE = 21e6; //略大于半个周长(mapSizeM/2)
  50803. const MAX_VERTICAL_DIST = 2;
  50804. const MAX_VERTICAL_DIST_TO_BEST = 1;
  50805. function defineLocalProj(locationLonLat){
  50806. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat[0].toPrecision(15) + " +lat_0=" + locationLonLat[1].toPrecision(15));
  50807. }
  50808. const getSid = (function(){
  50809. let sid = 0;
  50810. return function(){
  50811. return sid++
  50812. }
  50813. })();
  50814. //高德坐标拾取工具 : https://lbs.amap.com/tools/picker
  50815. class MapLayer extends EventDispatcher{ // 包括了 MapLayerBase SceneLayer
  50816. constructor(viewer_, viewport){
  50817. super();
  50818. this.sceneGroup = new Object3D;
  50819. this.sceneGroup.name = "MapLayer";
  50820. this.waitQueue = []; //等待加载的
  50821. this.loadingInProgress = 0;
  50822. this.maps = [];
  50823. this.frustum = new Frustum;
  50824. this.frustumMatrix = new Matrix4;
  50825. this.tileColor = new Color(16777215);
  50826. this.viewport = viewport;
  50827. this.changeViewer(viewer_);
  50828. //添加地图
  50829. var map = new TiledMapOpenStreetMap(this, this.tileColor );
  50830. this.addMap(map);
  50831. //map.setEnable(false)
  50832. this.sceneGroup.addEventListener('isVisible',()=>{
  50833. this.viewer.mapChanged = true;
  50834. });
  50835. }
  50836. addMapEntity(data, datasetId){
  50837. if(!data || !data[0]){
  50838. Potree.Log('平面图无数据',{font:'red'});
  50839. return
  50840. }
  50841. data[0].datasetId = datasetId;
  50842. var floorplan = new TiledMapFromEntity(this, this.tileColor, data[0] );//[0]?
  50843. if(floorplan){
  50844. floorplan.name += "_"+ datasetId;
  50845. this.addMap(floorplan);
  50846. floorplan.updateProjection();
  50847. floorplan.updateObjectGroup();
  50848. let visible = false;
  50849. if(datasetId in Potree.settings.floorplanEnables){
  50850. visible = Potree.settings.floorplanEnables[datasetId];
  50851. }else {
  50852. visible = Potree.settings.floorplanEnable;
  50853. }
  50854. if(visible){
  50855. this.needUpdate = true;
  50856. }else {
  50857. floorplan.setEnable(false);
  50858. }
  50859. this.dispatchEvent({type:'floorplanLoaded', floorplan});
  50860. }
  50861. return floorplan
  50862. }
  50863. getFloorplan(datasetId){
  50864. return this.maps.find(e=>e.name == 'floorplan'+"_"+ datasetId )
  50865. }
  50866. addMap(t){
  50867. this.maps.push(t);
  50868. //this.view.invalidateScene()
  50869. this.needUpdate = true;
  50870. this.viewer.mapChanged = true;
  50871. }
  50872. removeMap(t){
  50873. var e = this.maps.indexOf(t);
  50874. if(e >= 0){
  50875. t.removeFromSceneGroup(this.sceneGroup);
  50876. this.maps.splice(e, 1);
  50877. }
  50878. /* this.view.invalidateScene() */
  50879. this.needUpdate = true;
  50880. this.viewer.mapChanged = true;
  50881. }
  50882. changeViewer(viewer_){//add
  50883. this.viewer = viewer_;
  50884. }
  50885. initProjection(){
  50886. this.maps.forEach(map=>{
  50887. map.updateProjection();
  50888. map.updateObjectGroup();
  50889. });
  50890. }
  50891. visibilityChanged(){
  50892. if (!this.visible)
  50893. for (var t = 0, e = this.maps; t < e.length; t++){
  50894. e[t].removeFromSceneGroup(this.sceneGroup);
  50895. }
  50896. }
  50897. update(){
  50898. this.needUpdate = false;
  50899. if(this.disabled || !this.maps.find(e=>!e.disabled) || !this.maps.find(e=>e.objectGroup.visible) )return //add
  50900. this.viewer.mapChanged = true;
  50901. var e, n, i, r, o;
  50902. this.updateTimer = void 0,
  50903. e = this.viewport.camera,
  50904. n = e.projectionMatrix.clone();
  50905. let expandRatio = 1.3;
  50906. n.elements[0] /= expandRatio;
  50907. n.elements[5] /= expandRatio; // 为了缓存吗,使边界处也提前加载,扩大显示区域
  50908. this.frustumMatrix.multiplyMatrices(n, e.matrixWorldInverse),
  50909. this.frustum.setFromProjectionMatrix(this.frustumMatrix),
  50910. this.frustum.planes[4].setComponents(0, 0, 0, 0),
  50911. this.frustum.planes[5].setComponents(0, 0, 0, 0),
  50912. i = !0;
  50913. //console.log('-------------update-----------')
  50914. for (r = 0; r < this.maps.length; r++){
  50915. var map = this.maps[r];
  50916. i = map.update(this.frustum, this.sceneGroup) && i;
  50917. }
  50918. return [2, i]
  50919. }
  50920. updateProjection(){
  50921. for (var t = 0, e = this.maps; t < e.length; t++){
  50922. var n = e[t];
  50923. n.clearProjection(),
  50924. n.updateObjectGroup();
  50925. }
  50926. }
  50927. }
  50928. class TiledMapBase extends EventDispatcher{
  50929. constructor( name, mapLayer, tileColor, projection){
  50930. super();
  50931. this.name = name;
  50932. this.mapLayer = mapLayer,
  50933. this.tileColor = tileColor,
  50934. this.bias = 0;
  50935. this.zIndex = -1;
  50936. this.objectGroup = new Object3D;
  50937. this.objectGroup.name = name;
  50938. this.objectGroupAdded = !1,
  50939. this.baseTile = new MapTile(this, this.objectGroup, this.tileColor, null, '0'),
  50940. this.isTileVisibleBox = new Box3,
  50941. this.isTileVisibleVec = new Vector3;
  50942. this.projection = projection;
  50943. this._zoomLevel = 0;//1-20
  50944. this.objectGroup.addEventListener('isVisible',()=>{
  50945. this.mapLayer.viewer.mapChanged = true;
  50946. });
  50947. this.computeCount = 0;
  50948. this.maxLoading = 3;
  50949. this.loadFailCount = 0;
  50950. this.loadingInProgress = 0;
  50951. }
  50952. get zoomLevel(){
  50953. return this._zoomLevel
  50954. }
  50955. set zoomLevel(zoomLevel){
  50956. if(this._zoomLevel != zoomLevel){
  50957. this._zoomLevel = zoomLevel;
  50958. this.dispatchEvent({type:'zoomLevelChange',zoomLevel});
  50959. //if(this.name == 'map')console.log(zoomLevel,viewer.mapViewer.camera.zoom)
  50960. }
  50961. }
  50962. updateObjectGroup(){
  50963. this.position && this.objectGroup.position.copy(this.position).setZ(0),
  50964. this.quaternion && this.objectGroup.quaternion.copy(this.quaternion),
  50965. this.objectGroup.updateMatrixWorld(!0);
  50966. }
  50967. updateProjection(){
  50968. if(!this.transformMapToLocal){
  50969. this.transformMapToLocal = proj4(this.projection, "LOCAL_MAP");
  50970. }
  50971. }
  50972. clearProjection(){
  50973. this.transformMapToLocal = void 0;
  50974. this.projection !== 'LOCAL_MAP' && this.baseTile.remove();
  50975. }
  50976. setEnable(enable){//add
  50977. if(!this.disabled == enable)return
  50978. if(enable){
  50979. //console.log('setEnable',true)
  50980. }
  50981. this.disabled = !enable;
  50982. Potree.Utils.updateVisible(this.objectGroup, 'setEnable', enable);
  50983. if(!enable){
  50984. this.baseTile.remove();
  50985. }else {
  50986. this.mapLayer.needUpdate = true;
  50987. }
  50988. }
  50989. update(e, n){
  50990. this.computeCount = 0;
  50991. var unavailable = (this.disabled || !this.objectGroup.visible);//地图即使不显示也要获得zoomlevel
  50992. if(this.name != 'map' && unavailable)return
  50993. this.updateProjection();
  50994. if(!this.transformMapToLocal)return
  50995. if (!this.isTileVisible(new Vector3(0,0,0), this.mapSizeM, e))
  50996. return this.removeFromSceneGroup(n), !0;
  50997. let viewport = this.mapLayer.viewport;
  50998. var i = new Vector3(-.5 * this.mapSizeM,0,0);
  50999. i.applyMatrix4(this.objectGroup.matrixWorld),
  51000. i.project(viewport.camera);
  51001. var o = new Vector3(.5 * this.mapSizeM,0,0);
  51002. o.applyMatrix4(this.objectGroup.matrixWorld),
  51003. o.project(viewport.camera);
  51004. var a = viewport.resolution.x
  51005. , s = viewport.resolution.y;
  51006. if (a <= 0 || s <= 0 || isNaN(i.x) || isNaN(o.x)) return !1;
  51007. i.sub(o),
  51008. i.x *= a / 2,
  51009. i.y *= s / 2;
  51010. let scale;
  51011. if(this.name == 'map'){
  51012. //add 高纬度的因倾斜而造成tile较小,所以放大些,否则会造成显示的tile过多而卡
  51013. let lonlat = viewer.transform.lonlatToLocal.inverse(viewport.camera.position.clone());
  51014. let cos = Math.cos(MathUtils.degToRad(lonlat.y)); //越小就在纬度上越高,tile表现越小
  51015. //为什么lonlat.y会超出90?
  51016. /* if(lonlat.y>90){
  51017. console.log('lonlat.y>90',lonlat.y)
  51018. } */
  51019. cos = MathUtils.clamp(cos, 0,1);
  51020. let lonShift = Math.abs(viewer.mapViewer.camera.position.x / this.mapSizeM * 16 ); //越大就在经度离中心越远,tile表现越大 。
  51021. lonShift = MathUtils.clamp(lonShift, 0, Math.PI);
  51022. lonShift = (1 - Math.sin( 1/2 * lonShift + Math.PI/2 )) * Math.PI; // 0-Math.PI sin增速向上
  51023. scale = 0.5 * cos * (1+lonShift) + 0.5 * Math.pow(cos, lonShift);
  51024. }else {
  51025. scale = 1;
  51026. }
  51027. var c = this.tileSizePx / i.length() / scale //多除以一个scale缩放因子,scale越大level越小
  51028. , level = Math.ceil(-Math.log(c) / Math.log(2) - this.bias);
  51029. level = Math.max(level, 0);
  51030. level = Math.min(level, void 0 === this.maxDepth ? 1 / 0 : this.maxDepth);
  51031. this.zoomLevel = level;//add
  51032. /* if(isNaN(this.zoomLevel )){
  51033. console.log(level, cos , scale , lonlat )
  51034. } */
  51035. if(!unavailable){
  51036. this.addToSceneGroup(n);
  51037. return this.baseTile.update(this, e, level, this.mapSizeM, 0, 0, "")
  51038. }
  51039. }
  51040. isTileVisible(e, n, i){
  51041. if (n > HALF_WORLD_SIZE) return !0;
  51042. var r = .5 * n;
  51043. //简单版:
  51044. this.transformMapToLocal.forward(e); //e转化为local
  51045. this.isTileVisibleBox.makeEmpty();
  51046. this.isTileVisibleVec.set(e.x - r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  51047. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  51048. this.isTileVisibleVec.set(e.x - r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  51049. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  51050. this.isTileVisibleVec.set(e.x + r, e.y - r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  51051. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  51052. this.isTileVisibleVec.set(e.x + r, e.y + r, e.z).applyMatrix4(this.objectGroup.matrixWorld);
  51053. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec);
  51054. //仿造createMesh写的准确版,但会因为大的tile非矩形,而视口是矩形,若视口刚好在tile的曲线边缘外却识别为可见,就会创建冗余tile。 但上面那个简单版在zoomlevel低的时候地球边缘容易有识别不到的tile,造成黑色三角形。
  51055. //容易出现奇怪的mesh
  51056. /* this.isTileVisibleBox.makeEmpty()
  51057. this.isTileVisibleVec.set(e.x - r, e.y - r, e.z)
  51058. this.transformMapToLocal.forward(this.isTileVisibleVec)
  51059. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  51060. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
  51061. this.isTileVisibleVec.set(e.x - r, e.y + r, e.z)
  51062. this.transformMapToLocal.forward(this.isTileVisibleVec)
  51063. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  51064. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
  51065. this.isTileVisibleVec.set(e.x + r, e.y - r, e.z)
  51066. this.transformMapToLocal.forward(this.isTileVisibleVec)
  51067. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  51068. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec)
  51069. this.isTileVisibleVec.set(e.x + r, e.y + r, e.z)
  51070. this.transformMapToLocal.forward(this.isTileVisibleVec)
  51071. this.isTileVisibleVec.applyMatrix4(this.objectGroup.matrixWorld)
  51072. this.isTileVisibleBox.expandByPoint(this.isTileVisibleVec) */
  51073. return i.intersectsBox(this.isTileVisibleBox)
  51074. }
  51075. addToSceneGroup(t){
  51076. this.objectGroupAdded || (t.add(this.objectGroup),
  51077. this.objectGroupAdded = !0);
  51078. }
  51079. removeFromSceneGroup(t){
  51080. this.baseTile.remove(),
  51081. this.objectGroupAdded && (t.remove(this.objectGroup),
  51082. this.objectGroupAdded = !1);
  51083. }
  51084. }
  51085. const loadDone = (tile, success)=>{
  51086. tile.map.mapLayer.loadingInProgress--;
  51087. tile.map.loadingInProgress--;
  51088. //console.log('loaddone', tile.name, 'loadingInProgress',tile.map.mapLayer.loadingInProgress, Date.now())
  51089. tile.loading = false;
  51090. let next = tile.map.mapLayer.waitQueue[0];
  51091. if(next){
  51092. addLoadTile(next);
  51093. }else {
  51094. if(tile.map.mapLayer.loadingInProgress == 0){//注意这时候不一定就加载完了,300ms后可能还会有新的tile加载
  51095. //console.log('loadDone All ?', Date.now())
  51096. tile.map.mapLayer.dispatchEvent('loadDone');
  51097. }
  51098. }
  51099. tile.mesh && (tile.mesh.material.needsUpdate = true);
  51100. };
  51101. function addLoadTile(tile){
  51102. /* if(tile.texURL && tile.texURL.includes('testdata') ){
  51103. console.error('addLoadTile', tile.texURL.split('map_tiles/')[1] )
  51104. } */
  51105. if(tile.map.loadingInProgress < tile.map.maxLoading){
  51106. if(!tile.mesh)return; //有时候会遇到这种情况, 为什么没有被cancelLoad呢?
  51107. tile.map.mapLayer.loadingInProgress++;
  51108. tile.map.loadingInProgress ++;
  51109. tile.map.mapLayer.dispatchEvent('startLoad');
  51110. //console.log('addLoad', 'loadingInProgress',tile.map.mapLayer.loadingInProgress, Date.now())
  51111. //tile.texURL && tile.texURL.includes('testdata') && console.log('startloadTile ', tile.texURL.split('map_tiles/')[1] )
  51112. tile.loading = true;
  51113. let index = tile.map.mapLayer.waitQueue.indexOf(tile);
  51114. index > -1 && tile.map.mapLayer.waitQueue.splice(index,1);
  51115. let tex = tile.mesh.material.map = texLoader$2.load(tile.texURL, (tex)=>{ //如果一直加载不了会影响其他的加载,如google地图没有vpn会使全景图一直加载不了
  51116. if(tile.mesh){//如果还要显示的话
  51117. tile.textureLoaded = true;
  51118. tile.mesh.material.opacity = 1;
  51119. tile.map.mapLayer.viewer.mapChanged = true;
  51120. tile.map.mapLayer.needUpdate = true; //表示还要继续update(以removeChildren)
  51121. if(tile.map instanceof TiledMapOpenStreetMap){
  51122. tile.map.maxLoading = browser.isMobile() ? 5 : 10;
  51123. }
  51124. }else {
  51125. //tile.texURL && tile.texURL.includes('testdata') && console.log('loadDone and dispose', tile.texURL.split('map_tiles/')[1] )
  51126. tex.dispose();
  51127. }
  51128. loadDone(tile, true);
  51129. } , void 0, (()=>{//error
  51130. tile.textureLoaded = !0;
  51131. if(tile.mesh){
  51132. tile.mesh.material.dispose();
  51133. tile.mesh.material = errorMaterial;
  51134. tile.map.mapLayer.viewer.mapChanged = true;
  51135. }
  51136. loadDone(tile, false);
  51137. tile.map.loadFailCount ++ ;
  51138. if(tile.map instanceof TiledMapOpenStreetMap && Potree.settings.mapCompany == 'google' && tile.map.loadFailCount > 3){//极有可能没有vpn为了防止影响到其他资源加载,减少加载的个数
  51139. tile.map.maxLoading = 2;
  51140. }
  51141. }));
  51142. tex.anisotropy = 0;
  51143. tex.generateMipmaps = !1;
  51144. tex.minFilter = LinearFilter;
  51145. tex.magFilter = LinearFilter;
  51146. }else {
  51147. tile.map.mapLayer.waitQueue.includes(tile) || tile.map.mapLayer.waitQueue.push(tile);
  51148. }
  51149. }
  51150. function cancelLoad(tile,log){//如果等待加载,但还没开始加载,取消加载
  51151. if(!tile.loading){
  51152. let index = tile.map.mapLayer.waitQueue.indexOf(tile);
  51153. index > -1 && tile.map.mapLayer.waitQueue.splice(index,1);
  51154. //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 */ )
  51155. }
  51156. }
  51157. class MapTile{
  51158. constructor(map, e, n, parent, name){
  51159. this.map = map;
  51160. this.name = name;
  51161. this.parent = parent;
  51162. this.objectGroup = e,
  51163. this.tileColor = n,
  51164. this.meshAdded = !1,
  51165. this.textureLoaded = !1,
  51166. this.children = [];
  51167. this.id = getSid();
  51168. }
  51169. update(e, n, i, r, o, a, s){
  51170. return !!this.doesNotContainTilesToBeDisplayed(e) || (0 === i ? this.updateTile(e, r, o, a) : this.updateSubTiles(e, n, i, r, o, a, s))
  51171. }
  51172. doesNotContainTilesToBeDisplayed(t){
  51173. return t.tilePresenceMap && t.tilePresenceMap.empty
  51174. }
  51175. updateTile(t, e, n, i){ //真正显示mesh的是这一层,最高level
  51176. //if(this.map.name.includes('floorplan'))console.log('updateTile',this.name)
  51177. if(!this.mesh){
  51178. this.createTileObject(t, e, n, i);
  51179. }
  51180. if(!this.meshAdded){
  51181. this.objectGroup.add(this.mesh);
  51182. this.meshAdded = !0;
  51183. }
  51184. if(this.textureLoaded){//贴图加载完就不需要子集了
  51185. this.removeChildren();
  51186. }else {
  51187. this.cancelChildren(); //add 停止加载子集
  51188. }
  51189. return this.textureLoaded
  51190. }
  51191. updateSubTiles(entity, n, level, o, a, s, c){
  51192. //if(entity.name.includes('floorplan'))console.log('updateSubTiles',this.name) //名字越长代表level越高
  51193. 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){
  51194. var h = c + p.toString(10);
  51195. //一级(512):0 1 2 3分别为左上、右上、左下、右下。二级(1024)就是把一级的每一块分裂,如00 01 02 03分别是0的左上、右上、左下、右下……
  51196. if (!entity.tilePresenceMap || entity.tilePresenceMap[h]){
  51197. //去掉判断,直接显示
  51198. var f = a + u[p]
  51199. , m = s + d[p];
  51200. tempVector.set(f, m, 0);
  51201. this.map.computeCount ++;
  51202. //console.log(this.map.computeCount, this.name, 'level:',level)
  51203. if (entity.isTileVisible(tempVector, .5 * o, n)){
  51204. this.children[p] || (this.children[p] = new MapTile(this.map, this.objectGroup,this.tileColor, this, this.name+p ));
  51205. //childrenLoaded = childrenLoaded && this.children[p].update(entity, n, level - 1, .5 * o, f, m, h) //这句会使若有一个tile还在加载,就阻断了。原版是这么写的。但是为了加快加载速度,改成下面两行。感觉直接全部updateTile也没太卡,不知道很大的场景会不会卡,单帧updateTile次数超过100次的话(应该不会吧,地图大小会限制住个数) -- 2023.12
  51206. let childLoaded = this.children[p].update(entity, n, level - 1, .5 * o, f, m, h);
  51207. childrenLoaded = childrenLoaded && childLoaded;
  51208. } else {
  51209. if (this.children[p]){
  51210. this.children[p].remove();
  51211. delete this.children[p];
  51212. }
  51213. }
  51214. }
  51215. }
  51216. return childrenLoaded && this.removeObject3D(), childrenLoaded //子项加载完,母项mesh可以去除。(最后母项的母项以及前面的都会被删除,只留最后的叶子结点)
  51217. }
  51218. /*
  51219. 一层层往后加载。加入第一次加载到第4层(因为level精细度是第4层),给第4层可见tile加上mesh。
  51220. 然后下一次加载到第5层,那么第4层的mesh就要被清空(当它所属的第5层子集都加载完后)
  51221. */
  51222. createTileObject(t, e, n, a){
  51223. var s = this;
  51224. this.mesh = this.createMesh(t.transformMapToLocal, e, n, a),
  51225. this.textureLoaded = !1;
  51226. var c = t.mapSizeM / e
  51227. , l = Math.log(c) / Math.log(2)
  51228. , u = n / e + .5 * (c - 1)
  51229. , d = -a / e + .5 * (c - 1)
  51230. , p = t.getTileUrl(Math.round(l), Math.round(u), Math.round(d));
  51231. Potree.Utils.setObjectLayers(this.mesh, 'map' );
  51232. this.mesh.renderOrder = -(1e6 - l - 100 * (t.zIndex || 0));
  51233. this.mesh.name = this.name; //add
  51234. this.texURL = p;
  51235. /* let area = math.getArea(this.mesh.geometry.vertices.slice(0,3));
  51236. if(area >0){
  51237. this.mesh.visible = false
  51238. console.log('area>0',this.mesh.name)
  51239. } */
  51240. addLoadTile(this);
  51241. }
  51242. createMesh(t, e, n, o){
  51243. var a = new Geometry;
  51244. return tempVector.set(n - e / 2, o - e / 2, 0),
  51245. a.vertices.push(new Vector3().copy(t.forward(tempVector))),
  51246. tempVector.set(n + e / 2, o - e / 2, 0),
  51247. a.vertices.push(new Vector3().copy(t.forward(tempVector))),
  51248. tempVector.set(n + e / 2, o + e / 2, 0),
  51249. a.vertices.push(new Vector3().copy(t.forward(tempVector))),
  51250. tempVector.set(n - e / 2, o + e / 2, 0),
  51251. a.vertices.push(new Vector3().copy(t.forward(tempVector))),
  51252. a.faces.push(face1),
  51253. a.faces.push(face2),
  51254. a.faceVertexUvs[0].push(face1UV),
  51255. a.faceVertexUvs[0].push(face2UV),
  51256. new Mesh(a,this.createMaterial())
  51257. }
  51258. createMaterial(){
  51259. var t = new MeshBasicMaterial({
  51260. transparent: !0,
  51261. depthWrite: !1,
  51262. depthTest: !0,
  51263. opacity: 0,
  51264. side: DoubleSide,
  51265. });
  51266. if(Potree.settings.isTest) {
  51267. var colorHue = Math.random();
  51268. t.color = new Color().setHSL(colorHue, 0.6, 0.92);
  51269. }else {
  51270. t.color = this.tileColor ? this.tileColor : new Color(16777215);
  51271. }
  51272. return t
  51273. }
  51274. traverse(f){//add
  51275. return Mesh.prototype.traverse.call(this,f)
  51276. }
  51277. remove(){
  51278. this.removeObject3D(),
  51279. this.removeChildren();
  51280. }
  51281. removeObject3D(){
  51282. let hasMesh = !!this.mesh;
  51283. if (this.mesh){
  51284. this.objectGroup.remove(this.mesh);
  51285. if (this.textureLoaded){
  51286. var t = this.mesh.material.map;
  51287. t && t.dispose();
  51288. }else {
  51289. cancelLoad(this);
  51290. }
  51291. this.mesh.material.dispose(); //o.disposeMeshMaterial(this.mesh),
  51292. this.mesh.geometry.dispose();
  51293. this.mesh = void 0;
  51294. }
  51295. this.meshAdded = !1,
  51296. this.textureLoaded = !1;
  51297. //this.texURL && this.texURL.includes('testdata') && console.log('removeObject3D', this.id, 'hasMesh',hasMesh, this.texURL.split('map_tiles/')[1] )
  51298. }
  51299. removeChildren(){
  51300. for (var t = 0, e = this.children; t < e.length; t++){
  51301. var n = e[t];
  51302. n && (n.removeObject3D(),
  51303. n.removeChildren());
  51304. }
  51305. this.children.length = 0;
  51306. }
  51307. cancelChildren(){//子集全部停止加载
  51308. for (var t = 0, e = this.children; t < e.length; t++){
  51309. var n = e[t];
  51310. n && (cancelLoad(n, '提前'), n.cancelChildren());
  51311. }
  51312. }
  51313. }
  51314. 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");
  51315. //这里地图世界的中心是不是lon:0,lat:0
  51316. class TiledMapOpenStreetMap extends TiledMapBase{
  51317. constructor(mapLayer, tileColor){
  51318. //Potree.settings.mapCompany = 'google'
  51319. super('map', mapLayer, tileColor/* , projection */ ); //EPSG projection
  51320. //this.baseUrl = "https://wprd03.is.autonavi.com/appmaptile?style=7&x=${x}&y=${y}&z=${z}",
  51321. //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
  51322. this.switchStyle();
  51323. this.tileSizePx = 256;
  51324. this.mapSizeM = 40075017; //总占据多少米(地球赤道周长) 和三维空间的不一样 - -, 空间上的是直径,地图上的是半个圆周
  51325. this.bias = 0.5;
  51326. if(Potree.settings.mapCompany == 'google'){
  51327. this.attribution = "© PopSmart, © 谷歌地图";
  51328. this.projection = "EPSG:900913"; //"EPSG:4326"//4550
  51329. }else {
  51330. this.attribution = "© PopSmart, © 高德地图";
  51331. this.projection = "EPSG:3857";
  51332. }
  51333. }
  51334. getTileUrl(t, e, n){
  51335. return this.baseUrl.replace(/\${z}/, t.toString(10)).replace(/\${x}/, e.toString(10)).replace(/\${y}/, n.toString(10))
  51336. }
  51337. switchStyle(style = 'standard'){
  51338. //if(Potree.settings.mapCompany == 'google')return
  51339. if(style == this.style)return
  51340. if(Potree.settings.mapCompany == 'google'){
  51341. if(style == 'satellite'){//卫星
  51342. 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
  51343. this.maxDepth = 22;
  51344. }else {
  51345. 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
  51346. this.maxDepth = 22;
  51347. }
  51348. /* 1)lyrs= 表示的是图层类型,即瓦片类型,具体含义如下:
  51349. m:路线图
  51350. t:地形图
  51351. p:带标签的地形图
  51352. s:卫星图
  51353. y:带标签的卫星图
  51354. h:标签层(路名、地名等)
  51355. 2)& gl=CN
  51356. 谷歌地图针对中国有两套坐标,一套做了偏移,一套没有。经测试在url加入gl=cn地图会有偏移。
  51357. Tips:如果谷歌地图和RTK测量的WGS84坐标有偏差,可以尝试在url里去掉& gl=cn。
  51358. 5)&hl=
  51359. 设置地图注记文字语言类型,缺省默认为中文。
  51360. hl=nl 中英双语
  51361. hl=zh-CN 中文
  51362. */
  51363. }else {
  51364. //baseUrl = "https://webst01.is.autonavi.com/appmaptile?lang=zh_cn&style=6&yrs=m&x=${x}&y=${y}&z=${z}" //卫星 maxDepth = 18
  51365. //搜索高德地图瓦片url
  51366. if(Potree.settings.isJiangMen){
  51367. if(style == 'satellite'){//卫星
  51368. this.maxDepth = 18;
  51369. this.baseUrl = "http://a.map.jms.gd/tile/weixing/${z}/${x}/${y}.png";
  51370. }else {
  51371. this.maxDepth = 19;
  51372. this.baseUrl = "http://a.map.jms.gd/tile/gd_xiangtu/${z}/${x}/${y}.png";
  51373. }
  51374. }else {
  51375. if(style == 'satellite'){//卫星
  51376. this.maxDepth = 18;
  51377. this.baseUrl = "https://webst01.is.autonavi.com/appmaptile?lang=zh_cn&style=6&yrs=m&x=${x}&y=${y}&z=${z}";
  51378. }else {
  51379. this.maxDepth = 19;
  51380. this.baseUrl = "https://wprd04.is.autonavi.com/appmaptile?lang=zh_cn&style=7&yrs=m&x=${x}&y=${y}&z=${z}"; //
  51381. }
  51382. }
  51383. }
  51384. this.style = style;
  51385. this.setEnable(false);
  51386. this.setEnable(true);
  51387. viewer.dispatchEvent('content_changed');
  51388. }
  51389. }
  51390. class TiledMapFromEntity extends TiledMapBase{
  51391. constructor(mapLayer, tileColor, data){
  51392. super('floorplan', mapLayer, tileColor, "LOCAL" /* "EPSG:3857" *//* "WGS84" */); //直接就是本地坐标,没有projec
  51393. let entity = this.tiledMapEntity = this.fillFromData(data);
  51394. let time = entity.updateTime || entity.createTime;
  51395. this.tileSizePx = entity.tileSizePx,
  51396. this.mapSizeM = entity.mapSizeM,
  51397. this.maxDepth = entity.maxDepth;
  51398. this.postStamp = time ? time.replace(/[^0-9]/ig,'') : (new Date).getTime();
  51399. //this.projection = n.crsLocal,
  51400. this.zIndex = 0,
  51401. this.tilePresenceMap = this.decodeBitStream(this.tiledMapEntity.quadtree); //包含tile分裂信息,如果写错了会造成tile显示不全
  51402. this.maxLoading = 5;
  51403. this.bias = 0.5; //越大加载层级越低,越模糊
  51404. if(window.devicePixelRatio>=2 && window.innerHeight * window.innerWidth < 768*1024){ //手机还是加载高清点(反正也不需要截图等待),但平板太大了,要铺满屏幕可能慢,所以稍微模糊点?(反正可以继续放大去看)
  51405. this.bias = 0; //level更高些
  51406. }
  51407. }
  51408. fillFromData(e){
  51409. let data = {};
  51410. data.id = e.id;
  51411. data.globalLocation = Potree.Utils.VectorFactory.fromArray3(e.location);
  51412. data.orientation = Potree.Utils.QuaternionFactory.fromArray(e.orientation);
  51413. let pointcloud = viewer.scene.pointclouds.find(p=>p.dataset_id == e.datasetId);
  51414. if(pointcloud.datasetData.mapping){
  51415. data.filePath = `${Potree.settings.urls.prefix1}/${pointcloud.datasetData.mapping}${e.file_path}`;
  51416. }else {
  51417. data.filePath = `${Potree.settings.urls.prefix1}${e.file_path}`;
  51418. }
  51419. data.fileName = '$DEPTH/$X/$Y.png';
  51420. data.type = e.type,
  51421. data.mapSizeM = e.map_size_m,
  51422. data.tileSizePx = e.tile_size_px,
  51423. data.maxDepth = e.max_depth,
  51424. data.quadtree = e.quadtree,
  51425. data.floorId = e.floor_id,
  51426. data.bundleId = e.bundle_id;
  51427. //this.computeLocalCoordinates()
  51428. return data
  51429. }
  51430. computeLocalCoordinates(){
  51431. if(proj4.defs("LOCAL_MAP")){
  51432. let lonlat = this.tiledMapEntity.globalLocation;
  51433. /* if(window.AMapWith84){//需要转换
  51434. lonlat = AMapWith84.wgs84ToAMap(lonlat)
  51435. } */
  51436. lonlat = viewer.transform.lonlatToLocal.forward(lonlat);
  51437. this.tiledMapEntity.location = new Vector3().copy(lonlat);
  51438. }
  51439. }
  51440. updateProjection() {
  51441. super.updateProjection();
  51442. if(!this.position){
  51443. this.computeLocalCoordinates();
  51444. }
  51445. /* this.projection = this.TransformService.crsLocal,
  51446. t.prototype.updateProjection.call(this) */
  51447. }
  51448. get position(){
  51449. return this.tiledMapEntity.location
  51450. /* enumerable: !0,
  51451. configurable: !0 */
  51452. }
  51453. get quaternion(){
  51454. return this.tiledMapEntity.orientation
  51455. /* enumerable: !0,
  51456. configurable: !0 */
  51457. }
  51458. getTileUrl(t, e, n) {
  51459. 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));
  51460. return i += "?t=" + this.postStamp
  51461. //this.RestService.addAuthorizationQueryParameter(i) //????
  51462. }
  51463. decodeBitStream(t) {
  51464. if (!t)
  51465. return {
  51466. empty: !0
  51467. };
  51468. for (var e = {}, n = [e], i = 0; i < t.length; i++) {
  51469. var r = n.shift()
  51470. , o = parseInt(t.substr(i, 1), 16);
  51471. if (1 & o) {
  51472. var a = {};
  51473. r[0] = a,
  51474. n.push(a);
  51475. }
  51476. 2 & o && (a = {},
  51477. r[1] = a,
  51478. n.push(a)),
  51479. 4 & o && (a = {},
  51480. r[2] = a,
  51481. n.push(a)),
  51482. 8 & o && (a = {},
  51483. r[3] = a,
  51484. n.push(a));
  51485. }
  51486. var s = {
  51487. empty: !0
  51488. };
  51489. return this.computeHashes(s, e, ""),
  51490. s
  51491. }
  51492. computeHashes(t, e, n) {
  51493. for (var i = 0; i < 4; i++)
  51494. e[i] && (t[n + i.toString(10)] = !0,
  51495. t.empty = !1,
  51496. this.computeHashes(t, e[i], n + i.toString(10)));
  51497. }
  51498. }
  51499. /*
  51500. note:
  51501. 目前缩小了能看出形态是一个地球。相机在高空朝下观测,地球平放着。
  51502. 所以越靠近赤道和地球朝上的那面所在的中央经度(也就是local 0,0,0所对应的初始经度),tile越接近正方形。
  51503. 所以在两极地区要怎么显示?
  51504. 注册地理坐标时需要滚动地球吗?(修改初始经度、重定义NAVVIS:TMERC, 就需要更新所有三维世界中的物体位置)
  51505. 切换中心点:
  51506. var locationLonLat = viewer.transform.lonlatToLocal.inverse(viewer.mapViewer.camera.position.clone())
  51507. proj4.defs("LOCAL_MAP", "+proj=tmerc +ellps=WGS84 +lon_0=" + locationLonLat.x.toPrecision(15) + " +lat_0=" + locationLonLat.y.toPrecision(15));
  51508. viewer.mapViewer.mapLayer.maps[0].transformMapToLocal = null
  51509. 地理注册部分地图上的1和2标记有两层意思。当地图全屏展示时,标记的是当前右侧经纬度的位置;当地图为小窗时,标记的是对应场景里三维位置。(所以感觉最好换一个ui?)且在2023.2.1之前才改好,之前都是后者。
  51510. 为什么边缘总是有奇怪的mesh,是因为有顶点到背面了吗
  51511. https://lbs.amap.com/tools/picker 高德坐标拾取器(手机登录),但和这里展示的不一样, 要用AMapWith84.aMapToWgs84({x: ,y: })转成84。 (qq or 手机登录) 所以potree本地和有AMapWith84函数的laser地图展现不一样
  51512. https://www.google.com/maps/@77.7730021,-34.4952712,4z google取点
  51513. 打印所有mapTile的名字,字符串最长的代表有显示的mesh。
  51514. viewer.mapViewer.mapLayer.maps[0].baseTile.traverse(function(e){console.log(e.name)})
  51515. 能查看有几个显示的mesh
  51516. viewer.mapViewer.mapLayer.maps[0].objectGroup.children
  51517. 图片地址中 tiles/4/3/9.png 第一个数字越高代表level越高,放得越大 . (tile.name.length也能反映出
  51518. viewer.mapViewer.mapLayer.maps[1].objectGroup.children.map(e=>e.name.length-1)
  51519. 目前看的几个场景floorplan原图是1米=33.03个像素 图宽度= 512*2^(max_depth-1) , map_size_m 代表整个地图是多少米
  51520. 经纬度精度小数点后5位为米级别,6位为分米,7位是厘米
  51521. */
  51522. /**
  51523. * @author mschuetz / http://mschuetz.at
  51524. *
  51525. * adapted from THREE.OrbitControls by
  51526. *
  51527. * @author qiao / https://github.com/qiao
  51528. * @author mrdoob / http://mrdoob.com
  51529. * @author alteredq / http://alteredqualia.com/
  51530. * @author WestLangley / http://github.com/WestLangley
  51531. * @author erich666 / http://erichaines.com
  51532. *
  51533. *
  51534. *
  51535. */
  51536. let Buttons = Potree.defines.Buttons;
  51537. class FirstPersonControls extends EventDispatcher {
  51538. constructor (viewer, viewport) {
  51539. super();
  51540. this.viewer = viewer;
  51541. this.renderer = viewer.renderer;
  51542. this.scene = viewer.scene;
  51543. this.rotationSpeed = 200;
  51544. this.moveSpeed = 10;
  51545. this.setCurrentViewport({hoverViewport:viewport, force:true}); //this.currentViewport = viewport
  51546. this.keys = {
  51547. FORWARD: ['W'.charCodeAt(0), 38],
  51548. BACKWARD: ['S'.charCodeAt(0), 40],
  51549. LEFT: ['A'.charCodeAt(0), 37],
  51550. RIGHT: ['D'.charCodeAt(0), 39],
  51551. UP: ['Q'.charCodeAt(0)],
  51552. DOWN: ['E'.charCodeAt(0)],
  51553. //SHIFT : [16],
  51554. ALT : [18],
  51555. SPACE:[32],
  51556. Rotate_LEFT : ['L'.charCodeAt(0)],
  51557. Rotate_RIGHT : ['J'.charCodeAt(0)],
  51558. Rotate_UP : ['K'.charCodeAt(0)],
  51559. Rotate_DOWN : ['I'.charCodeAt(0)],
  51560. };
  51561. this.fadeFactor = 20;
  51562. this.yawDelta = 0;
  51563. this.pitchDelta = 0;
  51564. this.translationDelta = new Vector3(0, 0, 0);
  51565. this.translationWorldDelta = new Vector3(0, 0, 0);
  51566. this.tweens = [];
  51567. this.dollyStart = new Vector2;
  51568. this.dollyEnd = new Vector2;
  51569. //this.enableChangePos = true
  51570. this.viewer.addEventListener('camera_changed',(e)=>{
  51571. if(this.viewer.name == 'mapViewer' || e.changeInfo && e.changeInfo.positionChanged && !viewer.mainViewport.view.isFlying() ){
  51572. this.setFPCMoveSpeed(e.viewport);
  51573. }
  51574. });
  51575. let drag = (e) => {
  51576. if(!this.enabled)return
  51577. let viewport = e.dragViewport;
  51578. if(!viewport)return
  51579. let camera = viewport.camera;
  51580. let mode;
  51581. if(e.isTouch){
  51582. if(e.touches.length == 1){
  51583. mode = (!e.dragViewport || e.dragViewport.name == 'MainView') ? 'rotate' : 'pan';
  51584. }else if(e.touches.length == 2){
  51585. mode = Potree.settings.displayMode == 'showPanos' ? 'scale' : 'pan-scale';
  51586. }else {
  51587. mode = (!e.dragViewport || e.dragViewport.name == 'MainView') ? 'pan' : 'scale';
  51588. }
  51589. }else {
  51590. //mode = e.buttons === Buttons.LEFT && (!e.dragViewport || e.dragViewport.name == 'MainView') ? 'rotate' : 'pan'
  51591. mode = e.buttons === Buttons.LEFT && camera.type != 'OrthographicCamera' ? 'rotate' : 'pan';
  51592. }
  51593. //console.log('mode ', mode )
  51594. let moveSpeed = this.currentViewport.getMoveSpeed();
  51595. if (e.drag.startHandled === undefined) {///???????
  51596. e.drag.startHandled = true;
  51597. this.dispatchEvent({type: 'start'});
  51598. }
  51599. if (mode.includes('rotate')) {//旋转
  51600. //来自panoramaControl updateRotation
  51601. if(!this.pointerDragStart){
  51602. return this.pointerDragStart = e.pointer.clone()
  51603. }
  51604. let view = this.scene.view;
  51605. if(this.rotateStartInfo.rotAroundPoint){//定点旋转: 以当前intersect的点为target旋转,不改点在屏幕中的位置
  51606. let distance = camera.position.distanceTo(this.rotateStartInfo.rotCenter/* this.intersectStart.location */); //不按下ctrl的话
  51607. let posDir = new Vector3().subVectors(this.rotateStartInfo.rotCenter, view.position);
  51608. if(posDir.dot(view.direction) < 0 )distance *= -1; //在背面
  51609. //按照orbitControl的方式旋转:
  51610. let rotationSpeed = 2;
  51611. this.yawDelta -= e.drag.pointerDelta.x * rotationSpeed;
  51612. this.pitchDelta += e.drag.pointerDelta.y * rotationSpeed;
  51613. /* //旋转方向和偏移量尽量和在漫游点处旋转方式的一样
  51614. this.yawDelta += e.drag.pointerDelta.x / 500 * viewport.resolution.x
  51615. this.pitchDelta -= e.drag.pointerDelta.y / 500 * viewport.resolution.y */
  51616. //先更新一下相机:
  51617. this.update();
  51618. view.applyToCamera(camera);
  51619. //然后得到新的相机角度下,原先点在屏幕中的位置所对应的3d点现在的坐标。只需要平移一下新旧坐标差值即可。//感觉貌似也可以用project和unproject后的差值的方式,还不用判断z背面
  51620. let newPointerDir = viewer.inputHandler.getMouseDirection(this.rotateStartInfo.rotCenter2d).direction.clone().multiplyScalar(distance);
  51621. let pivot = new Vector3().addVectors(camera.position, newPointerDir); //新的3d点
  51622. let moveVec = new Vector3().subVectors(pivot, this.rotateStartInfo.rotCenter);
  51623. this.translationWorldDelta.copy(moveVec.negate());
  51624. //立即更新下,防止因update和此drag频率不同而打滑。
  51625. this.update();
  51626. view.applyToCamera(camera);
  51627. }else {
  51628. let _matrixWorld = camera.matrixWorld;
  51629. camera.matrixWorld = new Matrix4;//unproject 前先把相机置于原点
  51630. var e1 = new Vector3(this.pointerDragStart.x,this.pointerDragStart.y,-1).unproject(camera)
  51631. , t = new Vector3(e.pointer.x,e.pointer.y,-1).unproject(camera)
  51632. , i = Math.sqrt(e1.x * e1.x + e1.z * e1.z)
  51633. , n = Math.sqrt(t.x * t.x + t.z * t.z)
  51634. , o = Math.atan2(e1.y, i)
  51635. , a = Math.atan2(t.y, n);
  51636. this.pitchDelta += o - a; //上下旋转
  51637. e1.y = 0,
  51638. t.y = 0;
  51639. var s = Math.acos(e1.dot(t) / e1.length() / t.length());
  51640. if(!isNaN(s)){
  51641. var yawDelta = s; //左右旋转
  51642. this.pointerDragStart.x > e.pointer.x && (yawDelta *= -1);
  51643. this.yawDelta += yawDelta;
  51644. }
  51645. //console.log('rotate:', this.pitchDelta, e.pointer.toArray(), this.pointerDragStart.toArray())
  51646. this.pointerDragStart.copy(e.pointer);
  51647. camera.matrixWorld = _matrixWorld ;
  51648. }
  51649. }
  51650. if (mode.includes('pan')) {//平移
  51651. if(!this.canMovePos(viewport)){
  51652. return
  51653. }
  51654. if(camera.type == "OrthographicCamera"){
  51655. //console.log(e.drag.pointerDelta, e.pointer, e.drag.end)
  51656. let moveVec = Utils.getOrthoCameraMoveVec(e.drag.pointerDelta, camera );//最近一次移动向量
  51657. let pointclouds;
  51658. let Alignment = window.viewer.modules.Alignment;
  51659. let MergeEditor = window.viewer.modules.MergeEditor;
  51660. let handleState = Alignment.handleState;
  51661. //右键平移视图、左键操作点云
  51662. let a = e.buttons === Buttons.LEFT && viewport.alignment && handleState && viewport.alignment[handleState];
  51663. if(Potree.settings.editType == 'pano'){
  51664. let PanoEditor = window.viewer.modules.PanoEditor;
  51665. if(a && PanoEditor.selectedPano){
  51666. if(/* !PanoEditor.selectedGroup || */!PanoEditor.checkIfAllLinked({group:PanoEditor.selectedGroup}) ){
  51667. if(handleState == 'translate' && ( e.drag.intersectStart.pointclouds && Common.getMixedSet(PanoEditor.selectedClouds, e.drag.intersectStart.pointclouds).length || PanoEditor.selectedPano.hovered)//平移时 拖拽到点云上 或 circle。(其中点云只需要intersect的点云中包含选择的点云中之一即可)
  51668. || handleState == 'rotate' ) //旋转模式不需要intersect
  51669. {
  51670. pointclouds = PanoEditor.selectedClouds;
  51671. }
  51672. }else {
  51673. PanoEditor.dispatchEvent('needToDisConnect');
  51674. console.warn('选中的漫游点连通了整个数据集,不允许移动');
  51675. }
  51676. }
  51677. if(!pointclouds && e.buttons === Buttons.LEFT && viewport.rotateSide){//侧视图 (有时候会卡顿,是mousemove执行延迟了,一般发生在突然加载很多点云时)
  51678. //console.log('rotateSide', -e.drag.pointerDelta.x )
  51679. return PanoEditor.rotateSideCamera(-e.drag.pointerDelta.x)
  51680. }
  51681. }else if(Potree.settings.editType == 'merge'){
  51682. if(e.buttons === Buttons.LEFT && viewport.rotateSide){
  51683. return MergeEditor.rotateSideCamera(-e.drag.pointerDelta.x)
  51684. }
  51685. }else {
  51686. /* if(Alignment.selectedClouds && Alignment.selectedClouds.length){//多个点云
  51687. pointclouds = a && e.drag.intersectStart.pointclouds && Common.getMixedSet(Alignment.selectedClouds, e.drag.intersectStart.pointclouds).length && Alignment.selectedClouds
  51688. }else{ */
  51689. //pointclouds = a && e.drag.intersectStart.pointcloud && [e.drag.intersectStart.pointcloud]
  51690. //}
  51691. if(a && e.drag.intersectStart.pointcloud){
  51692. pointclouds = [e.drag.intersectStart.pointcloud];
  51693. if(e.drag.intersectStart.pointcloud.dataset_id == Potree.settings.originDatasetId){
  51694. let p = e.drag.intersectStart.pointclouds.find(p=>p.dataset_id != Potree.settings.originDatasetId);
  51695. if(p) pointclouds = [p];
  51696. }
  51697. }
  51698. }
  51699. if(pointclouds){
  51700. if(handleState == 'translate' && viewport.alignment.translateVec){//只能沿某个方向移动
  51701. moveVec.projectOnVector(viewport.alignment.translateVec);
  51702. }
  51703. this.dispatchEvent({
  51704. type : "transformPointcloud",
  51705. intersect: e.intersect.orthoIntersect,
  51706. intersectStart: e.drag.intersectStart.orthoIntersect,
  51707. moveVec,
  51708. pointclouds,
  51709. camera
  51710. });
  51711. }else {
  51712. this.translationWorldDelta.add(moveVec.negate());
  51713. }
  51714. }else { //perspectiveCamera:
  51715. if(e.drag.intersectStart){//如果拖拽着点云
  51716. let ifInit = e.drag.z == void 0;
  51717. let pointerStartPos2d = e.drag.intersectStart.location.clone().project(camera);//识别到的点云点的位置
  51718. e.drag.z = pointerStartPos2d.z; //记录z,保持拖拽物体到屏幕距离不变,所以z深度不变(如果拖拽过程中没有缩放,这个z其实不变)
  51719. if(ifInit){//拖拽开始
  51720. e.drag.projectionMatrixInverse = camera.projectionMatrixInverse.clone();
  51721. //防止吸附到最近点上(因为鼠标所在位置并非识别到的点云点的位置,需要得到鼠标所在位置的3d坐标。)
  51722. let pointerStartPos2dReal = new Vector3(this.pointerDragStart.x,this.pointerDragStart.y, e.drag.z);
  51723. e.drag.translateStartPos = pointerStartPos2dReal.clone().unproject(camera);
  51724. //console.log('开始拖拽', e.pointer.clone())
  51725. }
  51726. //拖拽的过程中将projectionMatrixInverse替换成开始拖拽时的,因为near、far一直在变,会导致unproject计算出的3d坐标改变很大而闪烁。
  51727. var _projectionMatrixInverse = camera.projectionMatrixInverse;
  51728. camera.projectionMatrixInverse = e.drag.projectionMatrixInverse;
  51729. let newPos2d = new Vector3(e.pointer.x,e.pointer.y, e.drag.z );
  51730. let newPos3d = newPos2d.clone().unproject(camera);
  51731. let moveVec = newPos3d.clone().sub( e.drag.translateStartPos /* e.drag.intersectStart.location */ );//移动相机,保持鼠标下的位置永远不变,所以用鼠标下的新位置减去鼠标下的原始位置
  51732. camera.projectionMatrixInverse = _projectionMatrixInverse;
  51733. this.translationWorldDelta.copy(moveVec.negate()); //这里没法用add,原因未知,打开console时会跳动
  51734. //console.log('pan 1', this.translationWorldDelta.clone())
  51735. //四指松开剩三指时会偏移一下,暂不知道哪里的问题,或许跟开头防止点云吸附有关?
  51736. }else { //如果鼠标没有找到和点云的交点,就假设移动整个模型(也可以去扩大范围寻找最近点云)
  51737. /* let center = viewer.scene.pointclouds[0].position;
  51738. let radius = camera.position.distanceTo(center);
  51739. let ratio = radius * Math.tan(THREE.Math.degToRad(camera.fov)/2) / 1000 */
  51740. /* let speed = this.currentViewport.getMoveSpeed()
  51741. if(FirstPersonControls.boundPlane){
  51742. speed = FirstPersonControls.boundPlane.distanceToPoint(this.currentViewport.position)
  51743. speed = Math.max(1 , speed)
  51744. } */
  51745. let lastIntersect = this.target || viewport.lastIntersect && (viewport.lastIntersect.location || viewport.lastIntersect);//该viewport的最近一次鼠标和点云的交点
  51746. if(!lastIntersect || !(lastIntersect instanceof Vector3))lastIntersect = viewer.bound.center;
  51747. let speed = camera.position.distanceTo(lastIntersect);
  51748. let fov = cameraLight.getHFOVForCamera(camera, true);
  51749. let ratio = speed * Math.tan(fov/2);
  51750. this.translationDelta.x -= e.drag.pointerDelta.x * ratio;
  51751. this.translationDelta.z -= e.drag.pointerDelta.y * ratio;
  51752. //console.log('pan2', e.drag.pointerDelta)
  51753. }
  51754. }
  51755. this.useAttenuation = false;
  51756. }
  51757. if(mode.includes('scale')){//触屏缩放
  51758. this.dollyEnd.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  51759. //if(!this.dollyStart)return
  51760. var scale = this.dollyEnd.length() / this.dollyStart.length();
  51761. let pointer = new Vector2().addVectors(e.touches[0].pointer, e.touches[1].pointer).multiplyScalar(0.5);//两个指头的中心点
  51762. dolly({
  51763. pointer,
  51764. scale, camera, drag:e.drag
  51765. });
  51766. this.dollyStart.copy(this.dollyEnd);
  51767. }
  51768. //最好按ctrl可以变为dollhouse的那种旋转
  51769. };
  51770. let drop = e => {
  51771. if(!this.enabled)return
  51772. this.dispatchEvent({type: 'end'});
  51773. };
  51774. let dolly = (e={})=>{
  51775. if(Potree.settings.displayMode == 'showPanos' && this.currentViewport == viewer.mainViewport/* this.currentViewport.unableChangePos */){//全景时
  51776. this.dispatchEvent({type:'dollyStopCauseUnable',delta:e.delta, scale:e.scale});
  51777. return
  51778. }
  51779. let camera = e.camera;
  51780. if(camera.type == "OrthographicCamera"){
  51781. let ratio;
  51782. if(e.delta != void 0){//滚轮缩放
  51783. if(e.delta == 0){//mac
  51784. return
  51785. }else if (e.delta < 0) {
  51786. ratio = 0.9;
  51787. } else if (e.delta > 0) {
  51788. ratio = 1.12; //增加的需要比减少的多一些,否则缩放相同次数下,r0 * ([1+s)(1-s)]^n = r0 * (1-s^2)^n < r0
  51789. }
  51790. }else {
  51791. ratio = e.scale; //触屏缩放
  51792. }
  51793. let zoom = camera.zoom * ratio;
  51794. let limit = camera.zoomLimit;
  51795. if(limit) zoom = MathUtils.clamp(zoom, limit.min,limit.max );
  51796. let pointerPos = new Vector3(e.pointer.x, e.pointer.y,0.5);
  51797. let oldPos = pointerPos.clone().unproject(camera);
  51798. if(camera.zoom != zoom){
  51799. camera.zoom = zoom;
  51800. camera.updateProjectionMatrix();
  51801. }
  51802. let newPos = pointerPos.clone().unproject(camera);
  51803. //定点缩放, 恢复一下鼠标所在位置的位置改变量
  51804. let moveVec = new Vector3().subVectors(newPos,oldPos);
  51805. this.translationWorldDelta.add(moveVec.negate());
  51806. this.useAttenuation = false;
  51807. }else {
  51808. let speed = this.currentViewport.getMoveSpeed() * 7, direction;
  51809. if(e.delta != void 0){//滚轮缩放
  51810. if(e.delta == 0)return //mac
  51811. /*if(this.target && !e.intersect){//如果没有intersect点云且有target的话,就朝target的方向. 但无限靠近时有问题,且到背面时前进却是后退
  51812. direction = new THREE.Vector3().subVectors(this.target, camera.position).normalize()
  51813. }else{ */
  51814. direction = this.viewer.inputHandler.getMouseDirection().direction; //定点缩放
  51815. if(e.intersect && e.intersect.location){//和intersect的墙越接近,速度越慢,便于focus细节
  51816. let dis = camera.position.distanceTo(e.intersect.location);
  51817. speed = MathUtils.clamp(dis * 0.1, 0.3, speed);
  51818. }
  51819. if (e.delta < 0) {
  51820. speed *= -1;
  51821. }
  51822. let slightly = this.keys.ALT.some(e => this.viewer.inputHandler.pressedKeys[e]);
  51823. slightly && (speed *= 0.2);
  51824. this.useAttenuation = true;
  51825. }else {//触屏缩放
  51826. direction = this.viewer.inputHandler.getMouseDirection(e.pointer).direction; //定点缩放
  51827. if(e.drag.intersectStart){//和intersect的墙越接近,速度越慢,便于focus细节
  51828. let dis = camera.position.distanceTo(e.drag.intersectStart.location);
  51829. let r = 1-1/e.scale;
  51830. let closeMin = 0.1, standardMin = 0.001, disBound1 = 2, disBound2 = 5;
  51831. if(math.closeTo(e.scale,1,0.03)){//如果偏差小于0.01,就不限制最小值,因为平移容易正负抖动,近距离有最小值的话抖动明显
  51832. closeMin = 0; //所以若缩放不明显(双指滑动慢),就不设置最低值。(这时候穿越障碍物会比较困难。)
  51833. }
  51834. //console.log('closeMin',closeMin)
  51835. let min = math.linearClamp(dis, [disBound1, disBound2], [closeMin, standardMin]); //触屏和滚轮不一样,触发较为连续,所以最小值设低一点。若要保持双指相对点云位置不变,理想最小值是0,但那样就无法穿越点云(最小值太小的话穿越密集点云如树丛很困难;太大会打滑)所以当离点云近时增大最小值
  51836. speed = Math.sign(r) * MathUtils.clamp(dis * Math.abs(r), min, speed);
  51837. //console.log(speed, dis, e.scale)
  51838. }else {
  51839. this.useAttenuation = true;
  51840. let accelerate = 40;
  51841. if(math.closeTo(e.scale,1,0.02)){//缩放小的时候很可能是双指平移时,容易抖动,所以降低移动速度
  51842. accelerate *= Math.min(40*Math.abs(e.scale-1), 0.8);
  51843. }
  51844. // console.log('accelerate',accelerate)
  51845. const constantDis = this.currentViewport.getMoveSpeed() * accelerate; //constantDis = 10;//常量系数,当放大一倍时前进的距离。可以调整
  51846. speed = (e.scale-1)*constantDis;
  51847. }
  51848. }
  51849. var vec = direction.multiplyScalar(speed );
  51850. //this.translationWorldDelta.copy(vec)
  51851. this.translationWorldDelta.add(vec);
  51852. //console.log(direction.toArray(), speed, e.scale)
  51853. }
  51854. return true
  51855. };
  51856. let scroll = (e) => {
  51857. if(!this.enabled || !e.hoverViewport)return
  51858. this.setCurrentViewport(e);
  51859. e.camera = e.hoverViewport.camera;
  51860. dolly(e);
  51861. };
  51862. let dblclick = (e) => {
  51863. if(!this.enabled)return
  51864. if(!Potree.settings.dblToFocusPoint)return;//调试时才可双击
  51865. if(Potree.settings.displayMode == 'showPointCloud'/* !viewer.images360.isAtPano() */) this.zoomToLocation(e.mouse);
  51866. };
  51867. this.viewer.addEventListener('global_drag', drag);
  51868. /* this.viewer.addEventListener('global_touchmove', (e)=>{
  51869. if(!this.enabled)return
  51870. if(e.touches.length>1){//单指的就触发上一句
  51871. //console.log('global_touchmove' )
  51872. drag(e)
  51873. }
  51874. }); */
  51875. this.viewer.addEventListener('global_drop', drop);
  51876. this.viewer.addEventListener('global_mousewheel', scroll);
  51877. this.viewer.addEventListener('global_dblclick', dblclick);
  51878. let prepareScale = (e)=>{//触屏的scale
  51879. this.dollyStart.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  51880. e.drag.camDisToPointStart = null;
  51881. };
  51882. let prepareRotate = (e)=>{
  51883. this.pointerDragStart = e.pointer.clone();
  51884. if(e.viewer.name != 'mainViewer' )return
  51885. let intersect = e.intersect || e.dragViewport.lastIntersect;
  51886. //在数据集外部时绕中心点旋转,在数据集内部时绕intersect点旋转(其他数据集的点也可以) 或者 原地旋转镜头
  51887. let 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];
  51888. let rotCenter2d, rotCenter;
  51889. if(rotAroundPoint){
  51890. let pivotType = this.target ? 'target' : viewer.atDatasets.length > 0 ? 'intersect' : viewer.inputHandler.selection.length ? 'selection' : this.target2 ? 'target2' : 'boundCenter';
  51891. 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;
  51892. if(rotCenter){
  51893. rotCenter2d = rotCenter.clone().project(e.dragViewport.camera); //点在屏幕中的位置。 若z>1 则在背面 或 超出far范围
  51894. }else {
  51895. rotAroundPoint = false;
  51896. }
  51897. }
  51898. this.rotateStartInfo = {
  51899. rotAroundPoint, //定点旋转
  51900. rotCenter,
  51901. rotCenter2d
  51902. };
  51903. //缺点:多数据集绕中心点转很难操作,感觉可以也改为绕lastIntersect
  51904. //console.log('prepareRotate' )
  51905. };
  51906. let preparePan = (e)=>{//触屏的pan点云 还是会偏移
  51907. this.pointerDragStart = e.pointer.clone();
  51908. e.drag.z = void 0; //清空
  51909. drag(e); //触屏点击时更新的pointer直接用一次drag
  51910. //console.log('preparePan ' )
  51911. };
  51912. this.viewer.addEventListener('global_mousedown'/* 'startDragging' */, (e)=>{
  51913. if(!this.enabled)return
  51914. this.setCurrentViewport(e);
  51915. prepareRotate(e);
  51916. });
  51917. //注意,每次增减指头都会修改pointer,需要更新下状态
  51918. this.viewer.addEventListener('global_touchstart', (e)=>{
  51919. if(!this.enabled)return
  51920. if(e.touches.length==2){//只监听开头两个指头
  51921. prepareScale(e);
  51922. preparePan(e);
  51923. }else if(e.touches.length>=3){
  51924. preparePan(e);
  51925. }
  51926. });
  51927. this.viewer.addEventListener('global_touchend', (e)=>{//e.touches是剩余的指头
  51928. if(!this.enabled)return
  51929. if(e.touches.length==2){//停止平移,开始scale
  51930. prepareScale(e);
  51931. preparePan(e);
  51932. }else if(e.touches.length==1){//停止scale,开始rotate
  51933. prepareRotate(e);
  51934. }else if(e.touches.length>=3){//重新准备下平移(因为抬起的指头可能包含平移使用的数据),否则抬起时漂移
  51935. preparePan(e);
  51936. }
  51937. });
  51938. /* this.viewer.addEventListener('enableChangePos', (e)=>{
  51939. if(!this.enabled)return
  51940. this.enableChangePos = e.canLeavePano
  51941. }) */
  51942. }
  51943. canMovePos(viewport){
  51944. if(viewport == viewer.mainViewport && (Potree.settings.displayMode == 'showPanos'
  51945. || viewer.images360.bumping || viewer.images360.latestToPano))return false
  51946. else return true
  51947. }
  51948. setEnable(enabled){
  51949. this.enabled = enabled;
  51950. }
  51951. setTarget(target, index){//绕该点旋转,类似orbitControl
  51952. if(index == 2)this.target2 = target;
  51953. else this.target = target;
  51954. }
  51955. setFPCMoveSpeed(viewport){
  51956. if(viewport.camera.type == 'OrthographicCamera'){
  51957. let s = 1 / viewport.camera.zoom;
  51958. viewport.setMoveSpeed(s);
  51959. }else {
  51960. //根据和漫游点的最短距离算moveSpeed。缺点:对于导入的无漫游点的数据集没有意义。
  51961. if(viewport == viewer.mainViewport && viewer.images360){
  51962. let position = viewer.mainViewport.view.position;
  51963. let speed;
  51964. let pano = viewer.images360.findNearestPano();
  51965. if(!pano){
  51966. if(!viewer.bound || viewer.bound.boundSize.x == 0)return
  51967. let boundFloor = viewer.bound.boundingBox.clone();
  51968. boundFloor.max.z = boundFloor.min.z;
  51969. speed = boundFloor.distanceToPoint(viewer.mainViewport.view.position);
  51970. speed = Math.sqrt(speed) / 50;
  51971. }else {
  51972. let dis = pano.position.distanceTo(position);
  51973. let minSpeed = 0.05, minDis = 3, multiplier = 0.005;
  51974. speed = dis <= minDis ? minSpeed : minSpeed + (dis-minDis) * multiplier;
  51975. //console.log('dis', dis, 'speed', speed, pano.id )
  51976. }
  51977. viewer.setMoveSpeed(speed*2);
  51978. }
  51979. //调试场景t-FhDWmV5xur 两个数据集,大的数据集没有漫游点。
  51980. }
  51981. }
  51982. setCurrentViewport(o={}){//add
  51983. if(!this.enabled && !o.force )return
  51984. if(o.hoverViewport && this.currentViewport != o.hoverViewport ){
  51985. this.currentViewport = o.hoverViewport;
  51986. //this.viewer.setMoveSpeed(this.currentViewport.radius/100);
  51987. this.setFPCMoveSpeed(this.currentViewport);
  51988. }
  51989. if(this.currentViewport.camera.type == 'OrthographicCamera'){
  51990. this.lockElevationOri = true;
  51991. this.lockRotation = true;
  51992. }else {
  51993. this.lockElevationOri = false;
  51994. this.lockRotation = false;
  51995. }
  51996. }
  51997. setScene (scene) {
  51998. this.scene = scene;
  51999. }
  52000. stop(){
  52001. this.yawDelta = 0;
  52002. this.pitchDelta = 0;
  52003. this.translationDelta.set(0, 0, 0);
  52004. }
  52005. zoomToLocation(mouse){
  52006. if(!this.enabled)return
  52007. let camera = this.scene.getActiveCamera();
  52008. /* let I = Utils.getMousePointCloudIntersection(
  52009. mouse,
  52010. camera,
  52011. this.viewer,
  52012. this.scene.pointclouds); */
  52013. var I = this.viewer.inputHandler.intersect;
  52014. if (!I) {
  52015. return;
  52016. }
  52017. let targetRadius = 0;
  52018. {
  52019. let minimumJumpDistance = 0.2;
  52020. let domElement = this.renderer.domElement;
  52021. let ray = Utils.mouseToRay(this.viewer.inputHandler.pointer, camera);
  52022. let {origin, direction} = this.viewer.inputHandler.getMouseDirection();
  52023. let raycaster = new Raycaster();
  52024. raycaster.ray.set(origin, direction);
  52025. let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  52026. let nodes2 = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, raycaster.ray);
  52027. let lastNode = nodes[nodes.length - 1];
  52028. let radius = lastNode.getBoundingSphere(new Sphere()).radius;
  52029. targetRadius = Math.min(this.scene.view.radius, radius);
  52030. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  52031. }
  52032. let d = this.scene.view.direction.multiplyScalar(-1);
  52033. let cameraTargetPosition = new Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  52034. // TODO Unused: let controlsTargetPosition = I.location;
  52035. let animationDuration = 600;
  52036. let easing = TWEEN.Easing.Quartic.Out;
  52037. { // animate
  52038. let value = {x: 0};
  52039. let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
  52040. tween.easing(easing);
  52041. this.tweens.push(tween);
  52042. let startPos = this.scene.view.position.clone();
  52043. let targetPos = cameraTargetPosition.clone();
  52044. let startRadius = this.scene.view.radius;
  52045. let targetRadius = cameraTargetPosition.distanceTo(I.location);
  52046. tween.onUpdate(() => {
  52047. let t = value.x;
  52048. this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  52049. this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  52050. this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  52051. this.scene.view.radius = (1 - t) * startRadius + t * targetRadius;
  52052. this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
  52053. });
  52054. tween.onComplete(() => {
  52055. this.tweens = this.tweens.filter(e => e !== tween);
  52056. });
  52057. tween.start();
  52058. }
  52059. }
  52060. update (delta=1) {
  52061. if(!this.enabled)return
  52062. //console.log('update')
  52063. let view = this.currentViewport.view;
  52064. { // cancel move animations on user input
  52065. let changes = [ this.yawDelta,
  52066. this.pitchDelta,
  52067. this.translationDelta.length(),
  52068. this.translationWorldDelta.length() ];
  52069. let changeHappens = changes.some(e => Math.abs(e) > 0.001);
  52070. if (changeHappens && this.tweens.length > 0) {
  52071. this.tweens.forEach(e => e.stop());
  52072. this.tweens = [];
  52073. }
  52074. }
  52075. { // accelerate while input is given
  52076. let ih = this.viewer.inputHandler;
  52077. let moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
  52078. let moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
  52079. let moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
  52080. let moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
  52081. let moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
  52082. let moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
  52083. let rotateLeft = this.keys.Rotate_LEFT.some(e => ih.pressedKeys[e]);
  52084. let rotateRight = this.keys.Rotate_RIGHT.some(e => ih.pressedKeys[e]);
  52085. let rotateUp = this.keys.Rotate_UP.some(e => ih.pressedKeys[e]);
  52086. let rotateDown = this.keys.Rotate_DOWN.some(e => ih.pressedKeys[e]);
  52087. this.lockElevation = this.lockElevationOri || this.keys.SPACE.some(e => ih.pressedKeys[e]);
  52088. let slightly = this.keys.ALT.some(e => ih.pressedKeys[e]);
  52089. if(!this.lockRotation){
  52090. if(rotateLeft){
  52091. this.yawDelta -= 0.01;
  52092. }else if(rotateRight){
  52093. this.yawDelta += 0.01;
  52094. }
  52095. if(rotateUp){
  52096. this.pitchDelta -= 0.01;
  52097. }else if(rotateDown){
  52098. this.pitchDelta += 0.01;
  52099. }
  52100. }
  52101. if(this.canMovePos(this.currentViewport) && !this.lockKey){
  52102. if(this.lockElevation){
  52103. let dir = view.direction;
  52104. dir.z = 0;
  52105. dir.normalize();
  52106. if (moveForward && moveBackward) {
  52107. this.translationWorldDelta.set(0, 0, 0);
  52108. } else if (moveForward) {
  52109. this.translationWorldDelta.copy(dir.multiplyScalar(this.currentViewport.getMoveSpeed()));
  52110. } else if (moveBackward) {
  52111. this.translationWorldDelta.copy(dir.multiplyScalar(-this.currentViewport.getMoveSpeed()));
  52112. }
  52113. }else {
  52114. if (moveForward && moveBackward) {
  52115. this.translationDelta.y = 0;
  52116. } else if (moveForward) {
  52117. this.translationDelta.y = this.currentViewport.getMoveSpeed() * (slightly ? 0.2 : 1);
  52118. } else if (moveBackward) {
  52119. this.translationDelta.y = -this.currentViewport.getMoveSpeed() * (slightly ? 0.2 : 1);
  52120. }
  52121. }
  52122. if (moveLeft && moveRight) {
  52123. this.translationDelta.x = 0;
  52124. } else if (moveLeft) {
  52125. this.translationDelta.x = -this.currentViewport.getMoveSpeed();
  52126. } else if (moveRight) {
  52127. this.translationDelta.x = this.currentViewport.getMoveSpeed();
  52128. }
  52129. if (moveUp && moveDown) {
  52130. this.translationWorldDelta.z = 0;
  52131. } else if (moveUp) {
  52132. this.translationWorldDelta.z = this.currentViewport.getMoveSpeed();
  52133. } else if (moveDown) {
  52134. this.translationWorldDelta.z = -this.currentViewport.getMoveSpeed();
  52135. }
  52136. if(moveUp || moveDown || moveForward || moveBackward){
  52137. this.useAttenuation = false;
  52138. }
  52139. }
  52140. }
  52141. { // apply rotation
  52142. let yaw = view.yaw;
  52143. let pitch = view.pitch;
  52144. yaw += this.yawDelta; /* * delta; */
  52145. pitch += this.pitchDelta;/* * delta; */
  52146. view.yaw = yaw;
  52147. view.pitch = pitch;
  52148. if(this.yawDelta || this.pitchDelta){
  52149. view.cancelFlying('rotate');
  52150. }
  52151. this.yawDelta = 0;
  52152. this.pitchDelta = 0;
  52153. }
  52154. /* if(this.translationWorldDelta.length()>0) {
  52155. // console.log('translationDelta')
  52156. } */
  52157. { // apply translation
  52158. view.translate(
  52159. this.translationDelta.x, /* * delta, */
  52160. this.translationDelta.y, /* * delta, */
  52161. this.translationDelta.z, /* * delta */
  52162. );
  52163. this.translationDelta.set(0,0,0);
  52164. //if(this.translationWorldDelta.length())console.log(translationWorldDelta)
  52165. view.translateWorld(
  52166. this.translationWorldDelta.x /* * delta */,
  52167. this.translationWorldDelta.y /* * delta */,
  52168. this.translationWorldDelta.z /* * delta */
  52169. );
  52170. //this.translationWorldDelta.set(0,0,0)
  52171. }
  52172. { // set view target according to speed
  52173. //view.radius = 1 * this.currentViewport.getMoveSpeed();
  52174. /* if(viewer.bound) view.radius = view.position.distanceTo(viewer.bound.center)
  52175. let speed = view.radius/100;
  52176. this.viewer.setMoveSpeed(speed); */
  52177. //this.setMoveSpeed()
  52178. }
  52179. if(this.useAttenuation){ //只有滚轮缩放时开启
  52180. let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  52181. /*this.yawDelta *= attenuation;
  52182. this.pitchDelta *= attenuation;
  52183. this.translationDelta.multiplyScalar(attenuation);*/
  52184. this.translationWorldDelta.multiplyScalar(attenuation);
  52185. }else {
  52186. this.translationWorldDelta.set(0,0,0);
  52187. }
  52188. }
  52189. };
  52190. /**
  52191. * @author mschuetz / http://mschuetz.at
  52192. *
  52193. *
  52194. */
  52195. let {Buttons: Buttons$1} = Potree.defines;
  52196. class InputHandler extends EventDispatcher {
  52197. constructor (viewer,scene) {
  52198. super();
  52199. this.viewer = viewer;
  52200. this.renderer = viewer.renderer;
  52201. this.domElement = this.renderer.domElement;
  52202. this.enabled = true;
  52203. this.scene = scene;
  52204. this.interactiveScenes = [];
  52205. this.interactiveObjects = new Set();
  52206. this.inputListeners = [];
  52207. this.blacklist = new Set();
  52208. this.drag = null;
  52209. this.mouse = new Vector2(0, 0);
  52210. //add:
  52211. this.pointer = new Vector2(0, 0); //交互点的屏幕坐标,有别于DOM坐标,在此存放NDC坐标。(NDC,三维常用坐标系,二维坐标,整个屏幕映射范围(-1,1),屏幕中心为原点,+Y朝上,+X朝右)
  52212. this.mouseDownMouse = new Vector2(0, 0);
  52213. this.selection = [];
  52214. this.hoveredElements = [];
  52215. this.pressedKeys = {};
  52216. this.wheelDelta = 0;
  52217. this.speed = 1;
  52218. this.logMessages = false;
  52219. if (this.domElement.tabIndex === -1) {
  52220. this.domElement.tabIndex = 2222;
  52221. }
  52222. this.lastPointerUpTime = 0;
  52223. this.touches = [];
  52224. this.interactHistory = {move:0}; //add
  52225. this.hoverViewport = viewer.viewports[0];
  52226. this.domElement.addEventListener('contextmenu', (event) => { event.preventDefault(); }, false);
  52227. this.domElement.addEventListener('click', this.onMouseClick.bind(this), false);
  52228. this.domElement.addEventListener('mousedown', this.onMouseDown.bind(this), false);
  52229. window.addEventListener('mouseup', this.onMouseUp.bind(this), false);
  52230. if(Potree.isIframeChild){//子页面的话在父页面也要加侦听(应该不会有多层吧?否则要一直加到最外层)
  52231. //window.parent.addEventListener('mouseup', this.onMouseUp.bind(this), false); //可能跨域
  52232. //window.parent.postMessage('listenMouseup', '*');
  52233. window.addEventListener('mouseout', this.onMouseUp.bind(this), false); //cancel drag
  52234. }
  52235. this.domElement.addEventListener('mouseout', ()=>{
  52236. this.containsMouse = false;
  52237. }, false);
  52238. this.domElement.addEventListener('mousemove', this.onMouseMove.bind(this), false);
  52239. //add
  52240. /* this.domElement.addEventListener("pointerout", this.onMouseUp.bind(this)),
  52241. this.domElement.addEventListener("pointercancel", this.onMouseUp.bind(this)),
  52242. */
  52243. this.domElement.addEventListener('mousewheel', this.onMouseWheel.bind(this), false);
  52244. this.domElement.addEventListener('DOMMouseScroll', this.onMouseWheel.bind(this), false); // Firefox
  52245. //this.domElement.addEventListener('dblclick', this.onDoubleClick.bind(this)); //因为双击时间间隔是跟随系统的所以不好判断
  52246. window.addEventListener('keydown', this.onKeyDown.bind(this));//原先是this.domElement,这样的话一开始要点击屏幕后才能监听到
  52247. window.addEventListener('keyup', this.onKeyUp.bind(this));
  52248. window.addEventListener('blur',this.onKeyUp.bind(this)); //add
  52249. this.domElement.addEventListener('touchstart', this.onTouchStart.bind(this));
  52250. this.domElement.addEventListener('touchend', this.onTouchEnd.bind(this));
  52251. this.domElement.addEventListener('touchmove', this.onTouchMove.bind(this));
  52252. {
  52253. this.measuring = []; //正在编辑的measure
  52254. //let mesureInfo = new THREE.EventDispatcher()
  52255. this.addEventListener('measuring',(e)=>{
  52256. //true优先级高于false, 正在添加时dropMarker也不会停止
  52257. //Potree.Utils.updateVisible(mesureInfo, e.situation, e.v, 0, e.v?'add':'cancel' )//借用该函数,使true优先级高于false,防止正在添加时dropMarker而停止
  52258. if(e.v){
  52259. this.measuring.includes(e.object) || this.measuring.push(e.object);
  52260. }else {
  52261. let index = this.measuring.indexOf(e.object);
  52262. index > -1 && this.measuring.splice(index, 1);
  52263. }
  52264. if(this.measuring.length == 0 && this.measuring.length>0 ){
  52265. this.viewer.viewports.forEach((viewport)=>{
  52266. this.collectClosePoints(viewport, true );//forceUpdate
  52267. });
  52268. }
  52269. //console.log('measuring',e.v, e.cause, e.situation, this.measuring.length )
  52270. });
  52271. }
  52272. window.viewer.addEventListener('loopStart',()=>{
  52273. this.interactHistory = {}; //清空
  52274. });
  52275. }
  52276. /* addInputListener (listener) {
  52277. this.inputListeners.push(listener);
  52278. }
  52279. removeInputListener (listener) {
  52280. this.inputListeners = this.inputListeners.filter(e => e !== listener);
  52281. }
  52282. getSortedListeners(){
  52283. return this.inputListeners.sort( (a, b) => {
  52284. let ia = (a.importance !== undefined) ? a.importance : 0;
  52285. let ib = (b.importance !== undefined) ? b.importance : 0;
  52286. return ib - ia;
  52287. });
  52288. } */
  52289. //统一跟第一个触碰的viewport相同
  52290. updateTouchesInfo(e){
  52291. var viewport, pointer, camera;
  52292. let oldTouches = this.touches;
  52293. let changedTouches = Array.from(e.changedTouches);
  52294. let touches = Array.from(e.touches);
  52295. this.touches = touches.map(touch=>{
  52296. let touch_ = oldTouches.find(a=>a.touch.identifier == touch.identifier);
  52297. let pointer = touch_ && touch_.pointer; //复制原先的值
  52298. return {
  52299. touch, pointer,
  52300. }
  52301. });
  52302. if(e.touches.length > 0){
  52303. let newTouches = touches.filter(e=>!
  52304. oldTouches.some(a=>a.touch.identifier == e.identifier) && !changedTouches.some(a=>a.identifier == e.identifier)
  52305. ); //从按钮处划过时e.touches中会出现this.touches和changedTouches中都没有的identifier
  52306. if(newTouches.length>0){
  52307. console.warn('has new',newTouches.map(e=>e.identifier));
  52308. }
  52309. newTouches.concat(changedTouches).forEach(touch=>{ //修改changedTouches的
  52310. let touch_ = this.touches.find(a=>a.touch.identifier == touch.identifier);
  52311. if(touch_){
  52312. let a = this.getPointerInViewport(touch.pageX, touch.pageY, this.dragViewport||viewport, new Vector2);
  52313. touch_.pointer = a.pointer.clone();
  52314. viewport = a.viewport; camera = a.camera;
  52315. }
  52316. });
  52317. //使用当前touches的平均
  52318. if(e.touches.length > 1){
  52319. let pageX = Common.average(e.touches, "pageX");
  52320. let pageY = Common.average(e.touches, "pageY");
  52321. let a = this.getPointerInViewport(pageX, pageY, viewport, new Vector2);
  52322. this.pointer.copy(a.pointer);
  52323. //console.log('updateTouchesInfo', this.pointer.clone())
  52324. }else {
  52325. this.pointer = this.touches[0].pointer.clone(); //更新,使用当前touches中的第一个
  52326. }
  52327. /* if(this.touches.find(e=>!e.pointer)){
  52328. console.error(' touches has no pointer', oldTouches.map(e=>e.touch.identifier),
  52329. Array.from(e.touches).map(e=>e.identifier), Array.from(e.changedTouches).map(e=>e.identifier) )
  52330. } */
  52331. //console.log(this.touches)
  52332. //console.log('更新pointer1',this.pointer.toArray())
  52333. return {viewport, camera/* , pointer:this.pointer */}
  52334. }
  52335. }
  52336. onTouchStart (e) {
  52337. if (this.logMessages) console.log(this.constructor.name + ': onTouchStart');
  52338. e.preventDefault();
  52339. /* if (e.touches.length === 1 || !this.drag) { //!this.drag代表一次性下了两个指头
  52340. let rect = this.domElement.getBoundingClientRect();
  52341. let x = e.touches[0].pageX
  52342. let y = e.touches[0].pageY
  52343. this.dealPointerDown(x,y,e,true)
  52344. }else{
  52345. this.updateTouchesInfo(e)
  52346. this.drag.end.copy(this.pointer)
  52347. } */
  52348. this.dealPointerDown(e,true);
  52349. this.viewer.dispatchEvent($.extend(
  52350. this.getEventDesc(e,true),
  52351. {
  52352. type: 'global_' + e.type,
  52353. changedTouches: e.changedTouches
  52354. }
  52355. ));
  52356. /* console.log('targetTouches :', Array.from(e.targetTouches).map(e=>'| identifier: '+ e.identifier),
  52357. 'changedTouches :', Array.from(e.changedTouches).map(e=>'| identifier: '+ e.identifier)
  52358. ) */
  52359. //console.log('')
  52360. }
  52361. onTouchMove (e) {
  52362. if (this.logMessages) console.log(this.constructor.name + ': onTouchMove');
  52363. e.preventDefault();
  52364. /* if (e.touches.length === 1) {
  52365. let rect = this.domElement.getBoundingClientRect();
  52366. let x = e.touches[0].pageX;
  52367. let y = e.touches[0].pageY;
  52368. }else{
  52369. this.updateTouchesInfo(e)
  52370. this.drag.pointerDelta.subVectors(this.pointer, this.drag.end)
  52371. this.drag.end.copy(this.pointer)
  52372. }
  52373. */
  52374. this.dealPointerMove(e, true);
  52375. this.viewer.dispatchEvent($.extend(
  52376. this.getEventDesc(e,true),
  52377. {
  52378. type: 'global_' + e.type,
  52379. changedTouches: e.changedTouches
  52380. }
  52381. ));
  52382. /* console.log('targetTouches :', Array.from(e.targetTouches).map(e=>'| identifier: '+ e.identifier),
  52383. 'changedTouches :', Array.from(e.changedTouches).map(e=>'| identifier: '+ e.identifier)
  52384. ) */
  52385. }
  52386. onTouchEnd (e) {
  52387. if (this.logMessages) console.log(this.constructor.name + ': onTouchEnd');
  52388. e.preventDefault();
  52389. //console.log('onTouchEnd')
  52390. this.updateTouchesInfo(e);
  52391. /* if (e.touches.length === 0) {
  52392. let rect = this.domElement.getBoundingClientRect();
  52393. let x = e.changedTouches[0].pageX //万一一次松开两个指头的怎么办
  52394. let y = e.changedTouches[0].pageY
  52395. this.dealPointerUp(x,y,e,true)
  52396. }else {
  52397. this.drag.end.copy(this.pointer)
  52398. } */
  52399. this.dealPointerUp(e,true);
  52400. this.viewer.dispatchEvent($.extend(
  52401. this.getEventDesc(e,true),
  52402. {
  52403. type: 'global_' + e.type,
  52404. }
  52405. ));
  52406. //console.log('touchend length '+e.touches.length, this.touches.length)
  52407. }
  52408. onKeyDown (e) {
  52409. if (this.logMessages) console.log(this.constructor.name + ': onKeyDown');
  52410. if(e.target.nodeName == 'INPUT' || e.target.nodeName == 'TEXTAREA') return //正在输入文字 或e.srcElement
  52411. if(!this.containsMouse)return //在别的ui上无效
  52412. // DELETE
  52413. /* if (e.keyCode === KeyCodes.DELETE && this.selection.length > 0) {
  52414. this.dispatchEvent({
  52415. type: 'delete',
  52416. selection: this.selection
  52417. });
  52418. this.deselectAll();
  52419. } */
  52420. this.dispatchEvent({
  52421. type: 'keydown',
  52422. keyCode: e.keyCode,
  52423. event: e
  52424. });
  52425. // for(let l of this.getSortedListeners()){
  52426. // l.dispatchEvent({
  52427. // type: "keydown",
  52428. // keyCode: e.keyCode,
  52429. // event: e
  52430. // });
  52431. // }
  52432. this.pressedKeys[e.keyCode] = true;
  52433. // e.preventDefault();
  52434. }
  52435. onKeyUp (e) {
  52436. if (this.logMessages) console.log(this.constructor.name + ': onKeyUp');
  52437. if(e.keyCode != void 0){
  52438. delete this.pressedKeys[e.keyCode];
  52439. }else {
  52440. this.pressedKeys = {};
  52441. }
  52442. e.preventDefault();
  52443. }
  52444. onDoubleClick (e) {
  52445. if (this.logMessages) console.log(this.constructor.name + ': onDoubleClick');
  52446. let consumed = false;
  52447. for (let hovered of this.hoveredElements) {
  52448. if (hovered._listeners && hovered._listeners['dblclick']) {
  52449. hovered.object.dispatchEvent({
  52450. type: 'dblclick',
  52451. mouse: this.mouse,
  52452. object: hovered.object
  52453. });
  52454. consumed = true;
  52455. break;
  52456. }
  52457. }
  52458. if (!consumed) {
  52459. /* for (let inputListener of this.getSortedListeners()) {
  52460. inputListener. */this.viewer.dispatchEvent({
  52461. type: 'global_dblclick',
  52462. mouse: this.mouse,
  52463. object: null
  52464. });
  52465. //}
  52466. }
  52467. this.needSingleClick = false;//add
  52468. e.preventDefault();
  52469. }
  52470. onMouseClick (e) {
  52471. if (this.logMessages) console.log(this.constructor.name + ': onMouseClick');
  52472. e.preventDefault();
  52473. }
  52474. dealPointerDown(e,isTouch){
  52475. e.preventDefault();
  52476. //重新获取一下pointer, 因点击了浏览器的按钮展开列表时 move回来不会触发onmousemove,所以pointer是旧的
  52477. if(isTouch){
  52478. var { camera, viewport } = this.updateTouchesInfo(e);
  52479. if(this.drag){
  52480. //因为触屏在按下前缺少pointermove所以要更新下
  52481. this.drag.end = this.pointer.clone();
  52482. }
  52483. }else {
  52484. var { camera, viewport } = this.getPointerInViewport(e.clientX, e.clientY );
  52485. }
  52486. this.dragViewport = this.hoverViewport = viewport;
  52487. //if(isTouch || !Potree.settings.intersectWhenHover ){
  52488. if(isTouch || !this.dragViewport.view.isFlying() && Potree.settings.intersectWhenHover && Potree.settings.editType != 'pano' ){//漫游点编辑如果拖拽前getIntersect旋转会延迟
  52489. //isTouch必须更新 否则是旧的
  52490. this.hoveredElements = this.getHoveredElements();
  52491. let dontIntersect = false;
  52492. this.intersect = this.getIntersect({viewport, dontIntersect, clientX:e.clientX, clientY:e.clientY}); //更新intersect,避免在没有mousemove但flyToPano后intersect未更新。
  52493. //this.intersect = this.getWholeIntersect()
  52494. }
  52495. if(!viewport)return //why add this?
  52496. if (!this.drag) {
  52497. let target = (isTouch||e.button == MOUSE.LEFT) && this.hoveredElements.find(el => (//只有左键能拖拽
  52498. el.object._listeners &&
  52499. el.object._listeners['drag'] &&
  52500. el.object._listeners['drag'].length > 0));
  52501. if (target) {
  52502. this.startDragging(target.object, {location: target.point});
  52503. } else {
  52504. this.startDragging(null);
  52505. }
  52506. }
  52507. this.drag.intersectStart = this.intersect;
  52508. if(!isTouch || e.touches.length == 1){
  52509. let consumed = false;
  52510. let consume = () => { return consumed = true; };
  52511. //if (this.hoveredElements.length === 0) {
  52512. this.viewer.dispatchEvent($.extend(
  52513. this.getEventDesc(e,isTouch),
  52514. {
  52515. type: 'global_mousedown'
  52516. }
  52517. ));
  52518. for(let hovered of this.hoveredElements){
  52519. let object = hovered.object;
  52520. object.dispatchEvent({
  52521. type: 'mousedown',
  52522. viewer: this.viewer,
  52523. consume: consume
  52524. });
  52525. if(consumed){
  52526. break;
  52527. }
  52528. }
  52529. }
  52530. this.mouseDownMouse = this.mouse.clone();
  52531. this.pointerDownTime = Date.now();
  52532. }
  52533. onMouseDown (e) {
  52534. if (this.logMessages) console.log(this.constructor.name + ': onMouseDown');
  52535. this.dealPointerDown(e);
  52536. }
  52537. /* getWholeIntersect(hoveredElements, intersectPoint){//add
  52538. hoveredElements = hoveredElements || this.hoveredElements
  52539. intersectPoint = intersectPoint || this.intersectPoint
  52540. if(Potree.settings.intersectOnObjs && hoveredElements[0] && hoveredElements[0].object.isModel){
  52541. return {//模拟点云的intersectPoint的结构写法
  52542. hoveredElement : hoveredElements[0] ,
  52543. location: hoveredElements[0].point,
  52544. point: {normal: hoveredElements[0].face.normal },
  52545. distance: hoveredElements[0].distance,
  52546. object: hoveredElements[0].object
  52547. }
  52548. }else return intersectPoint
  52549. } */
  52550. getEventDesc(e,isTouch){//搜集dispatchEvent要给的一般数据
  52551. let o = {
  52552. viewer: this.viewer,
  52553. mouse: this.mouse,
  52554. pointer:this.pointer,
  52555. drag :this.drag,
  52556. isTouch,
  52557. dragViewport : this.dragViewport,
  52558. hoverViewport: this.hoverViewport,
  52559. // button: isTouch ? 0 : e.button,
  52560. //intersectPoint:this.intersectPoint,
  52561. hoveredElement: this.hoveredElements[0],
  52562. intersect: this.intersect//this.getWholeIntersect() , //可能包含mesh上的,针对融合页面
  52563. };
  52564. if(e){
  52565. o.isAtDomElement = e.target == this.domElement;
  52566. }
  52567. if(isTouch){
  52568. o.touches = this.touches;
  52569. }else if(e){
  52570. o.button = e.button;
  52571. o.buttons = e.buttons;
  52572. }
  52573. return o;
  52574. }
  52575. dealPointerUp(e,isTouch){
  52576. if(!this.drag){// 在canvas外mousedown
  52577. return
  52578. }
  52579. this.drag.end.copy(this.pointer);
  52580. if(isTouch && e.touches.length >= 1){
  52581. return
  52582. }
  52583. let now = Date.now();
  52584. if (this.logMessages) console.log(this.constructor.name + ': onMouseUp');
  52585. e.preventDefault();
  52586. let pressDistance = this.mouseDownMouse.distanceTo(this.mouse);
  52587. let pressTime = now - this.pointerDownTime;
  52588. let noMovement = this.drag.pointerDelta.length() == 0;//this.getNormalizedDrag().length() === 0;
  52589. let consumed = false;
  52590. let consume = () => { return consumed = true; };
  52591. //if (this.hoveredElements.length === 0) {
  52592. /* for (let inputListener of this.getSortedListeners()) {
  52593. inputListener */this.viewer.dispatchEvent($.extend(
  52594. this.getEventDesc(e,isTouch),
  52595. {
  52596. type: 'global_mouseup',
  52597. pressDistance,
  52598. consume,
  52599. }
  52600. ));
  52601. /* if(consumed){//??
  52602. break;
  52603. } */
  52604. //}
  52605. //}
  52606. if (this.hoveredElements.length > 0) {
  52607. let hovered = this.hoveredElements
  52608. .map(e => e.object)
  52609. .find(e => (e._listeners && e._listeners['mouseup']));
  52610. if(hovered){
  52611. hovered.dispatchEvent({
  52612. type: 'mouseup',
  52613. viewer: this.viewer,
  52614. consume: consume
  52615. });
  52616. }
  52617. }
  52618. if (this.drag) {
  52619. //拖拽结束
  52620. if (this.drag.object/* && e.button == THREE.MOUSE.LEFT */) {//add LEFT
  52621. if (this.logMessages) console.log(`${this.constructor.name}: drop ${this.drag.object.name}`);
  52622. this.drag.object.dispatchEvent($.extend(
  52623. this.getEventDesc(e,isTouch),
  52624. {
  52625. type: 'drop',
  52626. pressDistance,
  52627. }
  52628. ));
  52629. } else {
  52630. this.viewer.dispatchEvent($.extend(
  52631. this.getEventDesc(e,isTouch),
  52632. {
  52633. type: 'global_drop',
  52634. pressDistance
  52635. }
  52636. ));
  52637. }
  52638. // check for a click
  52639. if(pressDistance < Potree.config.clickMaxDragDis && pressTime<Potree.config.clickMaxPressTime && !e.unableClick){
  52640. let clickElement, consumed = false;
  52641. if(this.hoveredElements){
  52642. clickElement = this.hoveredElements.find(e=>e.object._listeners['click']);
  52643. if(clickElement){
  52644. let canceled;
  52645. let cancel = () => { return canceled = true; };
  52646. //console.log('clickElement',clickElement)
  52647. if (this.logMessages) console.log(`${this.constructor.name}: click ${clickElement.name}`);
  52648. clickElement.object.dispatchEvent($.extend(
  52649. this.getEventDesc(e,isTouch),
  52650. {
  52651. type: 'click',
  52652. pressDistance ,
  52653. cancel
  52654. }
  52655. ));
  52656. if(canceled){//比如只需要右键的话,可以忽视左键的点击
  52657. clickElement = null;
  52658. }
  52659. }
  52660. }
  52661. let selectable;
  52662. if(/* !consumed && */ !this.fixSelection){
  52663. if (e.button === MOUSE.LEFT) {
  52664. //if (noMovement) {
  52665. selectable = this.hoveredElements.find(el => el.object._listeners && el.object._listeners['select']);
  52666. if (selectable) {
  52667. selectable = selectable.object;
  52668. if (this.isSelected(selectable)) {
  52669. this.deselectAll();
  52670. } else {
  52671. this.deselectAll();
  52672. this.toggleSelection(selectable);
  52673. }
  52674. consumed = true; //add
  52675. } else {
  52676. if(this.selection.length>0)consumed = true; //add 取消选择后,阻断后续
  52677. this.deselectAll();
  52678. }
  52679. //}
  52680. } else if ((e.button === MOUSE.RIGHT) /* && noMovement */) {
  52681. this.deselectAll();
  52682. }
  52683. }
  52684. let consume = () => { return consumed = true; };
  52685. let desc = this.getEventDesc(e,isTouch);
  52686. if(!consumed){
  52687. this.viewer.dispatchEvent($.extend(
  52688. desc,
  52689. {
  52690. type: 'global_click',
  52691. pressDistance,
  52692. clickElement:clickElement/* || selectable */,
  52693. consume
  52694. }
  52695. ));
  52696. }
  52697. //增加 单击:
  52698. this.needSingleClick = true;
  52699. consumed || setTimeout(()=>{
  52700. if(this.needSingleClick){
  52701. this.viewer.dispatchEvent($.extend(
  52702. desc,
  52703. {
  52704. type: 'global_single_click',
  52705. pressDistance,
  52706. clickElement
  52707. }
  52708. ));
  52709. }
  52710. }, Potree.config.doubleClickTime+1);
  52711. //自行执行双击:
  52712. if(now - this.lastClickTime < Potree.config.doubleClickTime){
  52713. this.onDoubleClick(e);
  52714. }
  52715. this.lastClickTime = now;
  52716. }
  52717. this.drag = null;
  52718. }
  52719. this.dragViewport = null;
  52720. }
  52721. onMouseUp (e) {
  52722. this.dealPointerUp( e );
  52723. }
  52724. getPointerInViewport(clientX, clientY, viewForceAt, pointer ){
  52725. let rect = this.domElement.getBoundingClientRect();
  52726. let x = clientX - rect.left;
  52727. let y = clientY - rect.top;
  52728. let camera;
  52729. let viewport;
  52730. pointer = pointer ||this.pointer;
  52731. //if(this.viewer.viewports || viewForceAt){
  52732. var getDimension = (view)=>{
  52733. var left = Math.ceil(this.domElement.clientWidth * view.left)
  52734. , bottom = Math.ceil(this.domElement.clientHeight * view.bottom)
  52735. , width = Math.ceil(this.domElement.clientWidth * view.width)
  52736. , height = Math.ceil(this.domElement.clientHeight * view.height)
  52737. , top = this.domElement.clientHeight - bottom - height;
  52738. return {left, bottom, width, height, top}
  52739. };
  52740. var getView = (view, left, bottom, width, height, top)=>{
  52741. this.mouse.set(x-left, y - top );
  52742. Utils.convertScreenPositionToNDC(pointer, this.mouse, width, height);
  52743. //console.log('更新pointer2',this.pointer.toArray())
  52744. camera = view.camera;
  52745. viewport = view;
  52746. };
  52747. if(viewForceAt){
  52748. let {left, bottom, width, height, top} = getDimension(viewForceAt);
  52749. getView(viewForceAt, left, bottom, width, height, top);
  52750. }else {
  52751. var length = this.viewer.viewports.length;
  52752. //var getif = false
  52753. for(var i=0;i<length;i++){
  52754. var view = this.viewer.viewports[i];
  52755. if(!view.active)continue
  52756. var {left, bottom, width, height, top} = getDimension(view);
  52757. if(x >= left && x <= left + width && y >= top && y <= top + height){
  52758. getView(view, left, bottom, width, height, top);
  52759. //getif = true
  52760. break;
  52761. }
  52762. }
  52763. }
  52764. return {
  52765. camera, viewport, pointer
  52766. }
  52767. }
  52768. ifBlockedByIntersect({point, margin=0, cameraPos, pickWindowSize, pano, useDepthTex, viewport}={}){//某点是否被遮挡(不允许camera修改位置, 因为depthTex不好置换)
  52769. viewport = viewport || this.hoverViewport || viewer.mainViewport;
  52770. let intersect = this.getIntersect({viewport, onlyGetIntersect:true, pickWindowSize, useDepthTex, point, cameraPos, pano });
  52771. let cameraPos_ = (!cameraPos && pano) ? pano.position : (cameraPos||viewport.view.position);
  52772. if(intersect && intersect.distance+margin <= point.distanceTo(cameraPos_)){
  52773. return intersect //被遮挡
  52774. }
  52775. //点云模式,对没加载出的点云不准确。 尤其是需要修改相机位置时,因临时修改并不能使点云加载。
  52776. }
  52777. collectClosePoints(viewport, forceUpdate){//获取吸附点
  52778. if(!Potree.settings.adsorption)return
  52779. let point2ds = [];
  52780. //吸附测量线端点
  52781. viewer.scene.measurements.forEach(e=>{
  52782. if(this.measuring.includes(e)) return//不吸附到正在拖拽的自身
  52783. point2ds.push(...e.getPointsPos2d(viewport, forceUpdate));
  52784. });
  52785. return point2ds
  52786. }
  52787. getIntersect({viewport, onlyGetIntersect, pickWindowSize, dontIntersect, usePointcloud, useDepthTex, cameraPos, point, pano, clientX, clientY}={}){// usePointcloud:必须使用点云
  52788. let intersect, intersectPoint, intersectOnModel, allElements;
  52789. let camera = viewport.camera;
  52790. let raycaster;
  52791. viewer.addTimeMark('getIntersect','start');
  52792. let getByDepthTex = ()=>{
  52793. let intersect;
  52794. if(point){
  52795. let cameraPos = pano ? pano.position : camera.position;
  52796. let dir = new Vector3().subVectors(point, cameraPos).normalize();
  52797. intersect = {dir};
  52798. }else {
  52799. intersect = Utils.getIntersect(camera, [viewer.images360.cube], this.pointer, raycaster);
  52800. }
  52801. intersectPoint = viewer.images360.depthSampler.sample(intersect, pano, !!point); //可能不准确, 因pano可能未加载depthTex
  52802. if(intersectPoint && Potree.settings.depTexLocBindDataset){
  52803. intersectPoint.pointcloud = ( pano || viewer.images360.currentPano).pointcloud;
  52804. //在全景模式下,虽然深度图上的点可能对应别的pointcloud,但因为是在当前全景图处得到的,所以即使将原本对应的点云移走,该点也不移动是有道理的。它可以永远跟着该全景图。
  52805. }
  52806. };
  52807. let getByCloud = ()=>{
  52808. let pointer, mouse;
  52809. if(point){//指定了目标点,而非只是用pointer所在位置
  52810. cameraPos && camera.position.copy( cameraPos);
  52811. camera.lookAt(point);
  52812. camera.updateMatrixWorld();
  52813. pointer = this.pointer.clone();
  52814. mouse = this.mouse.clone();
  52815. this.pointer.set(0,0); //画布中心
  52816. this.mouse.set(Math.round(viewport.resolution.x/2), Math.round(viewport.resolution.y/2));
  52817. }
  52818. intersectPoint = (viewport.noPointcloud || dontIntersect)? null : Utils.getMousePointCloudIntersection(
  52819. viewport,
  52820. this.mouse,
  52821. this.pointer,
  52822. camera,
  52823. this.viewer,
  52824. this.viewer.scene.pointclouds,
  52825. {pickClipped: true, measuring: this.measuring.length>0, pickWindowSize, cameraChanged: !!point }
  52826. );
  52827. //恢复
  52828. if(point){
  52829. viewport.view.applyToCamera(camera);
  52830. this.pointer.copy(pointer);
  52831. this.mouse.copy(mouse);
  52832. }
  52833. };
  52834. if(this.measuring.length && Potree.settings.adsorption ){//吸附
  52835. let points = this.collectClosePoints(viewport);
  52836. let points2 = points.filter(e=>e.trueSide && e.inSight
  52837. && math.closeTo(this.mouse, e.posInViewport, Potree.config.measure.adsorptMinDis)
  52838. );
  52839. let disArr = points2.map(e=> e.pos.distanceToSquared(this.mouse) );
  52840. let min = points2.slice().sort((a,b)=>disArr[points.indexOf(a)] - disArr[points.indexOf(b)]);
  52841. if(min[0]){
  52842. intersect = {
  52843. //hoveredElement
  52844. location: min[0].pos3d,
  52845. //point: {normal: allElements[0].face.normal },
  52846. //normal
  52847. //distance
  52848. object: min[0].object,
  52849. adsorption:true
  52850. };
  52851. console.log('找到吸附点', min[0].pos3d, min[0].object.uuid);
  52852. }
  52853. }
  52854. if(!intersect){
  52855. let canUseDepthTex = (Potree.settings.displayMode == 'showPanos' || useDepthTex)
  52856. && viewer.images360.currentPano.pointcloud.hasDepthTex && viewport == viewer.mainViewport && !usePointcloud;
  52857. if(canUseDepthTex)getByDepthTex();
  52858. else getByCloud();
  52859. /* if(canUseDepthTex && this.measuring.length){
  52860. getByDepthTex()
  52861. }else{
  52862. getByCloud()
  52863. if(!intersectPoint && canUseDepthTex ){ //若在测量,先尝试点云,再用全景 //后来发现有深度图的点云全景visibleNode为空,pick不到的
  52864. getByDepthTex()
  52865. }
  52866. } */
  52867. //console.log(viewport.name , intersectPoint && intersectPoint.location )
  52868. if(Potree.settings.intersectOnObjs && !dontIntersect){
  52869. if(point){
  52870. raycaster = new Raycaster();
  52871. var dir = new Vector3().subVectors(point, camera.position).normalize();
  52872. raycaster.set(camera.position, dir); //var origin = new THREE.Vector3(pointer.x, pointer.y, -1).unproject(camera),
  52873. }
  52874. allElements = this.getHoveredElements(viewer.objs.children, true, raycaster);
  52875. if(allElements[0]){
  52876. let quaternion = new Quaternion;
  52877. let nor = allElements[0].face && allElements[0].face.normal;
  52878. nor && allElements[0].oriObject.matrixWorld.decompose( new Vector3, quaternion, new Vector3 );
  52879. intersectOnModel = {//模拟点云的intersectPoint的结构写法
  52880. hoveredElement : allElements[0] ,
  52881. location: allElements[0].point,
  52882. //point: {normal: allElements[0].face.normal },
  52883. normal: nor && nor.applyQuaternion(quaternion),
  52884. distance: allElements[0].distance,
  52885. object: allElements[0].object
  52886. };
  52887. }
  52888. }
  52889. if(intersectPoint && intersectOnModel){
  52890. if(intersectPoint.distance < intersectOnModel.distance){
  52891. intersect = intersectPoint;
  52892. }else {
  52893. intersect = intersectOnModel;
  52894. }
  52895. }else {
  52896. intersect = intersectOnModel || intersectPoint;
  52897. }
  52898. }
  52899. if(viewport.camera.type == 'OrthographicCamera'/* == 'mapViewport' */){
  52900. let pos3d = new Vector3(this.pointer.x,this.pointer.y,-1).unproject(viewport.camera); //z:-1朝外
  52901. if(!intersect){
  52902. intersect = {};
  52903. }
  52904. intersect.orthoIntersect = pos3d.clone();
  52905. }
  52906. //记录全部hover到的:
  52907. if(intersect){
  52908. intersect.allElements = allElements;
  52909. intersect.pointclouds = intersectPoint ? intersectPoint.pointclouds : [];
  52910. }
  52911. viewer.addTimeMark('getIntersect','end');
  52912. //点云费时:2-15ms
  52913. //深度图费时: 0.1-0.2ms
  52914. /*
  52915. intersect && intersect.location && intersect.location.applyMatrix4(viewer.scene.scene.matrix)//add
  52916. */
  52917. if(onlyGetIntersect){
  52918. return intersect
  52919. }
  52920. if (intersect) {
  52921. if(viewer.showCoordType){ //显示坐标位置时
  52922. let pos = intersect.point.position.toArray();
  52923. if(viewer.showCoordType == "local"){
  52924. }else if(viewer.showCoordType == "lonlat"){
  52925. pos = viewer.transform.lonlatToLocal.inverse(pos);
  52926. }else {
  52927. pos = viewer.transform.lonlatToLocal.inverse(pos);
  52928. pos = viewer.transform.lonlatTo4550.forward(pos);
  52929. }
  52930. viewer.dispatchEvent({
  52931. type : "coordinateChange", pos
  52932. });
  52933. }
  52934. }
  52935. //console.log('getIntersect', !!intersectPoint)
  52936. this.intersect = intersect;
  52937. intersect && (this.hoverViewport.lastIntersect = intersect);
  52938. return intersect
  52939. }
  52940. onMouseMove (e) {
  52941. return this.dealPointerMove( e )
  52942. }
  52943. dealPointerMove(e, isTouch){
  52944. if(this.interactHistory.move) return //一帧只触发一次
  52945. this.interactHistory.move = 1;
  52946. if(isTouch){
  52947. var { camera, viewport } = this.updateTouchesInfo(e);
  52948. }else {
  52949. var { camera, viewport } = this.getPointerInViewport(e.clientX, e.clientY, this.dragViewport);
  52950. }
  52951. this.hoverViewport = viewport;
  52952. if(!viewport)return//刚变化viewport时会找不到
  52953. let isFlying = this.viewer.viewports.some(e=>e.view.isFlying()) || viewer.scene.cameraAnimations.some(c=>c.onUpdate);
  52954. let intersect;
  52955. if(e.onlyGetIntersect || (!this.drag || this.drag.object || viewport.alignment ) ){ //没有拖拽物体,但按下鼠标了的话,不intersect。触屏的就能直接避免intersect
  52956. let dontIntersect = this.drag && viewport.alignment || isFlying || !Potree.settings.intersectWhenHover; // flying 时可能卡顿
  52957. //console.log('dontIntersectPointcloud',dontIntersectPointcloud)
  52958. intersect = this.getIntersect(Object.assign({}, e, {viewport, dontIntersect, clientX:e.clientX, clientY:e.clientY })); //数据集多的时候卡顿
  52959. }
  52960. if(e.onlyGetIntersect){
  52961. return intersect
  52962. }
  52963. e.preventDefault();
  52964. if (this.drag) {//有拖拽(不一定拖拽了物体, 也不一定按下了鼠标)
  52965. this.drag.mouse = isTouch ? 1 : e.buttons;
  52966. //add:
  52967. //this.drag.pointer = this.pointer.clone();
  52968. //this.drag.hoverViewport = this.hoverViewport
  52969. this.drag.pointerDelta.subVectors(this.pointer, this.drag.end);
  52970. this.drag.end.copy(this.pointer);
  52971. let dragConsumed = false;
  52972. if (this.drag.object && (e.buttons == Buttons$1.NONE || !this.drag.notPressMouse )){//如果是本不需要按鼠标的拖拽,但按下了鼠标,就不执行这段(改为拖拽场景,如添加测量时突然拖拽画面)
  52973. if (this.logMessages) console.log(this.constructor.name + ': drag: ' + this.drag.object.name);
  52974. let refused;
  52975. this.drag.object.dispatchEvent($.extend(
  52976. this.getEventDesc(e,isTouch),
  52977. {
  52978. type: 'drag', //拖拽物体
  52979. refuse: () => {refused = true;}
  52980. }
  52981. ));
  52982. if(!refused)dragConsumed = true;
  52983. viewer.dispatchEvent('content_changed');
  52984. }
  52985. if(!dragConsumed){
  52986. if (this.logMessages) console.log(this.constructor.name + ': drag: ');
  52987. this.viewer.dispatchEvent($.extend(
  52988. this.getEventDesc(e,isTouch),
  52989. {
  52990. type: 'global_drag', //拖拽画面
  52991. //consume: () => {dragConsumed = true;}
  52992. }
  52993. ));
  52994. }
  52995. }
  52996. if(!isTouch || e.touches.length == 1){
  52997. if((!this.drag || this.drag.notPressMouse || Potree.settings.intersectOnObjs && this.drag.object) && !isFlying){
  52998. /* let blacklist = this.drag && this.drag */
  52999. let hoveredElements = this.getHoveredElements( );
  53000. if(hoveredElements.length > 0){
  53001. let names = hoveredElements.map(h => h.object.name).join(", ");
  53002. if (this.logMessages) console.log(`${this.constructor.name}: onMouseMove; hovered: '${names}'`);
  53003. }
  53004. let cur = hoveredElements.find(a => a.object);
  53005. let curr = cur && cur.object;//hoveredElements.map(a => a.object).find(a => true);//只取第一个
  53006. let prev = this.lastMouseoverElement; //this.hoveredElements.map(a => a.object).find(a => true);
  53007. if(curr !== prev){
  53008. if(curr){
  53009. if (this.logMessages) console.log(`${this.constructor.name}: mouseover: ${curr.name}`);
  53010. curr.dispatchEvent({
  53011. type: 'mouseover',
  53012. object: curr,
  53013. hoveredElement:cur
  53014. });
  53015. }
  53016. if(prev){
  53017. if (this.logMessages) console.log(`${this.constructor.name}: mouseleave: ${prev.name}`);
  53018. prev.dispatchEvent({
  53019. type: 'mouseleave',
  53020. object: prev,
  53021. });
  53022. }
  53023. this.lastMouseoverElement = curr;
  53024. viewer.dispatchEvent('content_changed');
  53025. }
  53026. if(hoveredElements.length > 0){
  53027. let object = hoveredElements
  53028. .map(e => e.object)
  53029. .find(e => (e._listeners && e._listeners['mousemove']));
  53030. if(object){
  53031. object.dispatchEvent({
  53032. type: 'mousemove',
  53033. object: object
  53034. });
  53035. }
  53036. }
  53037. this.hoveredElements = hoveredElements;
  53038. }
  53039. //this.intersect = this.getWholeIntersect()
  53040. this.viewer.dispatchEvent($.extend(
  53041. this.getEventDesc(e,isTouch),
  53042. {
  53043. type: 'global_mousemove',
  53044. }
  53045. ));
  53046. this.containsMouse = true;
  53047. }
  53048. }
  53049. onMouseWheel(e){
  53050. if(!this.enabled) return;
  53051. if(this.logMessages) console.log(this.constructor.name + ": onMouseWheel");
  53052. e.preventDefault();
  53053. let delta = 0;
  53054. if (e.wheelDelta !== undefined) { // WebKit / Opera / Explorer 9
  53055. delta = e.wheelDelta;
  53056. } else if (e.detail !== undefined) { // Firefox
  53057. delta = -e.detail;
  53058. }
  53059. let ndelta = Math.sign(delta);
  53060. // this.wheelDelta += Math.sign(delta);
  53061. if(!this.hoverViewport){//调试手机版时会无
  53062. var { viewport } = this.getPointerInViewport(e.clientX, e.clientY );
  53063. this.hoverViewport = viewport;
  53064. }
  53065. if (this.hoveredElement) {
  53066. this.hoveredElement.object.dispatchEvent($.extend(
  53067. this.getEventDesc(e,isTouch),
  53068. {
  53069. type: 'mousewheel',
  53070. delta: ndelta,
  53071. object: this.hoveredElement.object
  53072. }
  53073. ));
  53074. } else {
  53075. this.viewer.dispatchEvent($.extend(
  53076. this.getEventDesc(e),
  53077. {
  53078. type: 'global_mousewheel',
  53079. delta: ndelta,
  53080. }
  53081. ));
  53082. }
  53083. setTimeout(()=>{
  53084. this.dealPointerMove(e );//add 在更新完view后重新获取intersect 和 drag
  53085. },1);//只延迟1会崩溃吗
  53086. }
  53087. startDragging (object, args = null) {
  53088. let name = object ? object.name : "no name";
  53089. if (this.logMessages) console.log(`${this.constructor.name}: startDragging: '${name}'`);
  53090. this.drag = {
  53091. start: this.pointer.clone(),
  53092. end: this.pointer.clone(),
  53093. pointerDelta: new Vector2(0, 0),
  53094. object: object,
  53095. hoverViewport: this.hoverViewport, //会变化
  53096. dragViewport: this.hoverViewport, //不变
  53097. };
  53098. if (args) {
  53099. for (let key of Object.keys(args)) {
  53100. this.drag[key] = args[key];
  53101. }
  53102. }
  53103. if(object){
  53104. object.dispatchEvent($.extend(
  53105. this.getEventDesc(),
  53106. {
  53107. type: 'startDragging'
  53108. }
  53109. ));
  53110. }
  53111. }
  53112. /* getMousePointCloudIntersection (mouse) {
  53113. return Utils.getMousePointCloudIntersection(
  53114. this.mouse,
  53115. this.scene.getActiveCamera(),
  53116. this.viewer,
  53117. this.scene.pointclouds);
  53118. } */
  53119. toggleSelection (object) {
  53120. let oldSelection = this.selection;
  53121. let index = this.selection.indexOf(object);
  53122. if (index === -1) {
  53123. this.selection.push(object);
  53124. object.dispatchEvent({
  53125. type: 'select'
  53126. });
  53127. } else {
  53128. this.selection.splice(index, 1);
  53129. object.dispatchEvent({
  53130. type: 'deselect'
  53131. });
  53132. }
  53133. this.dispatchEvent({
  53134. type: 'selection_changed',
  53135. oldSelection: oldSelection,
  53136. selection: this.selection
  53137. });
  53138. viewer.dispatchEvent('content_changed');
  53139. }
  53140. deselect(object){
  53141. let oldSelection = this.selection;
  53142. let index = this.selection.indexOf(object);
  53143. if(index >= 0){
  53144. this.selection.splice(index, 1);
  53145. object.dispatchEvent({
  53146. type: 'deselect'
  53147. });
  53148. this.dispatchEvent({
  53149. type: 'selection_changed',
  53150. oldSelection: oldSelection,
  53151. selection: this.selection
  53152. });
  53153. }
  53154. viewer.dispatchEvent('content_changed');
  53155. }
  53156. deselectAll () {
  53157. for (let object of this.selection) {
  53158. object.dispatchEvent({
  53159. type: 'deselect'
  53160. });
  53161. }
  53162. let oldSelection = this.selection;
  53163. if (this.selection.length > 0) {
  53164. this.selection = [];
  53165. this.dispatchEvent({
  53166. type: 'selection_changed',
  53167. oldSelection: oldSelection,
  53168. selection: this.selection
  53169. });
  53170. }
  53171. viewer.dispatchEvent('content_changed');
  53172. }
  53173. isSelected (object) {
  53174. let index = this.selection.indexOf(object);
  53175. return index !== -1;
  53176. }
  53177. registerInteractiveObject(object){
  53178. this.interactiveObjects.add(object);
  53179. }
  53180. removeInteractiveObject(object){
  53181. this.interactiveObjects.delete(object);
  53182. }
  53183. registerInteractiveScene (scene) {
  53184. let index = this.interactiveScenes.indexOf(scene);
  53185. if (index === -1) {
  53186. this.interactiveScenes.push(scene);
  53187. }
  53188. }
  53189. unregisterInteractiveScene (scene) {
  53190. let index = this.interactiveScenes.indexOf(scene);
  53191. if (index > -1) {
  53192. this.interactiveScenes.splice(index, 1);
  53193. }
  53194. }
  53195. getHoveredElement () {
  53196. let hoveredElements = this.getHoveredElements();
  53197. if (hoveredElements.length > 0) {
  53198. return hoveredElements[0];
  53199. } else {
  53200. return null;
  53201. }
  53202. }
  53203. getHoveredElements (interactables, dontCheckDis, raycaster) {
  53204. if(!interactables){
  53205. let scenes = this.hoverViewport.interactiveScenes || this.interactiveScenes.concat(this.scene);
  53206. let interactableListeners = ['mouseup', 'mousemove', 'mouseover', 'mouseleave', 'drag', 'drop', 'click', 'select', 'deselect'];
  53207. interactables = [];
  53208. for (let scene of scenes) {
  53209. scene.traverseVisible(node => {//检测加了侦听的object
  53210. if (node._listeners && node.visible && !this.blacklist.has(node) ) {
  53211. let hasInteractableListener = interactableListeners.filter((e) => {
  53212. return node._listeners[e] !== undefined;
  53213. }).length > 0;
  53214. if (hasInteractableListener) {
  53215. interactables.push(node);
  53216. }
  53217. }
  53218. });
  53219. }
  53220. }else interactables = interactables.filter(e=>e.visible);
  53221. let camera = this.hoverViewport.camera;
  53222. if(!raycaster){
  53223. let ray = Utils.mouseToRay(this.pointer, camera );
  53224. raycaster = new Raycaster();
  53225. raycaster.ray.set(ray.origin, ray.direction);
  53226. raycaster.camera = camera; //add
  53227. }
  53228. if(camera.type == "OrthographicCamera"){//使无论多远,threshold区域都是一样宽的
  53229. raycaster.params.Line.threshold = 20/camera.zoom;
  53230. }else {
  53231. raycaster.params.Line.threshold = 0.04; //相对长度
  53232. }
  53233. raycaster.params.Line2 = {threshold : browser.isMobile()?100:20 }; //拓宽的lineWidth
  53234. //raycaster.layers.enableAll()//add
  53235. Potree.Utils.setCameraLayers(raycaster, //设置能识别到的layers(如空间模型里只有mapViewer能识别到marker)
  53236. ['sceneObjects','mapObjects','measure', 'transformationTool', 'model', 'bothMapAndScene'],
  53237. this.hoverViewport && this.hoverViewport.extraEnableLayers
  53238. );
  53239. //this.hoverViewport.beforeRender && this.hoverViewport.beforeRender()
  53240. viewer.dispatchEvent( {type:'raycaster', viewport: this.hoverViewport, raycaster, viewer:this.viewer, interactables });//add
  53241. let intersections = raycaster.intersectObjects(interactables , true, null, true); //原本是false 检测不到children
  53242. let intersectionsCopy = intersections.slice();
  53243. if(this.intersect && this.intersect.distance != void 0 && !dontCheckDis){//add
  53244. intersections = intersections.filter(e=>{
  53245. if( this.intersect.hoveredElement && this.intersect.hoveredElement.oriObject == e.object)return true
  53246. let material = e.object.material;
  53247. return e.object.pickDontCheckDis || ( material.depthTest == false || material.depthWrite == false) && !material.realUseDepth //!material.depthTestWhenPick
  53248. || ( material.useDepth ? e.distance <= this.intersect.distance + material.uniforms.clipDistance.value : e.distance <= this.intersect.distance )
  53249. //maxClipFactor是否需要考虑?
  53250. });
  53251. }
  53252. intersections = intersections.map(e=>{//add 转化为interactables
  53253. var object = e.object;
  53254. do{
  53255. if(interactables.includes(object)) {
  53256. e.oriObject = e.object;
  53257. e.object = object;
  53258. break
  53259. }
  53260. object = object.parent;
  53261. }while(object)
  53262. return e
  53263. });
  53264. //add for测量线,在检测到sphere时优先选中sphere而非线
  53265. //intersections = intersections.sort(function(a,b){return b.object.renderOrder-a.object.renderOrder}) // 降序
  53266. intersections = intersections.sort(function(a,b){
  53267. let order2 = b.object.pickOrder || 0;
  53268. let order1 = a.object.pickOrder || 0;
  53269. return order2-order1
  53270. }); // 降序
  53271. //console.log('getHoveredElement ', intersections)
  53272. return intersections;
  53273. }
  53274. /* setScene (scene) {
  53275. this.deselectAll();
  53276. this.scene = scene;
  53277. } */
  53278. update (delta) {
  53279. }
  53280. /*getNormalizedDrag () {
  53281. if (!this.drag) {
  53282. return new THREE.Vector2(0, 0);
  53283. }
  53284. let diff = new THREE.Vector2().subVectors(this.drag.end, this.drag.start);
  53285. diff.x = diff.x / this.domElement.clientWidth;
  53286. diff.y = diff.y / this.domElement.clientHeight;
  53287. return diff;
  53288. }
  53289. getNormalizedLastDrag () {
  53290. if (!this.drag) {
  53291. return new THREE.Vector2(0, 0);
  53292. }
  53293. let mouseDelta = this.drag.mouseDelta.clone();
  53294. mouseDelta.x = mouseDelta.x / this.domElement.clientWidth;
  53295. mouseDelta.y = mouseDelta.y / this.domElement.clientHeight;
  53296. return mouseDelta;
  53297. } */
  53298. getMouseDirection(pointer) {//add
  53299. pointer = pointer || this.pointer;
  53300. let camera = this.hoverViewport.camera;
  53301. var t = new Vector3(pointer.x, pointer.y, -1).unproject(camera),
  53302. i = new Vector3(pointer.x, pointer.y, 1).unproject(camera);
  53303. return {origin: t, direction:i.clone().sub(t).normalize() }
  53304. }
  53305. }
  53306. class ViewerBase extends EventDispatcher{
  53307. constructor(domElement, args = {}){
  53308. super();
  53309. this.name = args.name;
  53310. this.renderArea = domElement;
  53311. this.oldResolution = new Vector2();
  53312. this.oldResolution2 = new Vector2();
  53313. this.screenSizeInfo = {
  53314. W:0, H:0, pixelRatio:1 , windowWidth:0, windowHeight:0
  53315. };
  53316. this.initContext(args);
  53317. this.addEventListener('content_changed', ()=>{//画面改变,需要渲染
  53318. this.needRender = true;
  53319. //console.log('needRender')
  53320. });
  53321. }
  53322. initContext(args){
  53323. //console.log(`initializing three.js ${THREE.REVISION}`);
  53324. let width = this.renderArea.clientWidth;
  53325. let height = this.renderArea.clientHeight;
  53326. let contextAttributes = {
  53327. alpha: true,//支持透明
  53328. depth: true,
  53329. stencil: false,
  53330. antialias: !!args.antialias,
  53331. preserveDrawingBuffer: args.preserveDrawingBuffer || false ,
  53332. powerPreference: "high-performance",
  53333. };
  53334. let canvas = document.createElement("canvas");
  53335. let context = canvas.getContext('webgl2', contextAttributes ); //不用webgl2是因为有的写法在webgl2不支持 如gl_FragDepthEXT
  53336. if(context){
  53337. Potree.settings.isWebgl2 = true;
  53338. }
  53339. this.renderer = new WebGLRenderer({
  53340. premultipliedAlpha: false,
  53341. canvas: canvas,
  53342. context: context,
  53343. });
  53344. this.renderer.sortObjects = true; //原先false 打开了renderOrder才奏效
  53345. //this.renderer.setSize(width, height);
  53346. this.renderer.autoClear = args.autoClear || false;
  53347. //args.clearColor = args.clearColor || '#aa0033'
  53348. args.clearColor && this.renderer.setClearColor(args.clearColor);
  53349. this.renderArea.appendChild(this.renderer.domElement);
  53350. this.renderer.domElement.tabIndex = '2222';
  53351. this.renderer.domElement.style.position = 'absolute';
  53352. this.renderer.domElement.addEventListener('mousedown', () => {
  53353. this.renderer.domElement.focus();
  53354. });
  53355. //this.renderer.domElement.focus();
  53356. // NOTE: If extension errors occur, pass the string into this.renderer.extensions.get(x) before enabling
  53357. // enable frag_depth extension for the interpolation shader, if available
  53358. let gl = this.renderer.getContext();
  53359. gl.getExtension('EXT_frag_depth');
  53360. gl.getExtension('WEBGL_depth_texture');
  53361. gl.getExtension('WEBGL_color_buffer_float'); // Enable explicitly for more portability, EXT_color_buffer_float is the proper name in WebGL 2
  53362. if(gl.createVertexArray == null){
  53363. let extVAO = gl.getExtension('OES_vertex_array_object');
  53364. if(!extVAO){
  53365. throw new Error("OES_vertex_array_object extension not supported");
  53366. }
  53367. gl.createVertexArray = extVAO.createVertexArrayOES.bind(extVAO);
  53368. gl.bindVertexArray = extVAO.bindVertexArrayOES.bind(extVAO);
  53369. }
  53370. /* let oldClear = gl.clear;
  53371. gl.clear = (bits)=>{
  53372. console.error('clear')
  53373. }
  53374. */
  53375. }
  53376. updateScreenSize(o={}) { //有可能需要让viewport来判断,当窗口大小不变但viewport大小变时
  53377. if(this.screenshoting && !o.forceUpdateSize) return //截图时不允许因窗口改变大小而updateScreenSize
  53378. var render = false, ratio, w, h;
  53379. //记录应当render的大小
  53380. if (o.width != void 0 && o.height != void 0) {
  53381. w = o.width;
  53382. h = o.height;
  53383. render = true;
  53384. ratio = 1;
  53385. }else {
  53386. w = this.renderArea.clientWidth;
  53387. h = this.renderArea.clientHeight;
  53388. if(w !== this.screenSizeInfo.W || h !== this.screenSizeInfo.H || o.forceUpdateSize || this.screenSizeInfo.pixelRatio != window.devicePixelRatio){
  53389. this.screenSizeInfo.W = w;
  53390. this.screenSizeInfo.H = h;
  53391. render = true;
  53392. this.screenSizeInfo.pixelRatio = window.devicePixelRatio; //如果player放在小窗口了,也要监测devicePixelRatio,因为缩放时client宽高不会改变
  53393. //config.isMobile ? (ratio = Math.min(window.devicePixelRatio, 2)) : (ratio = window.devicePixelRatio)
  53394. ratio = window.devicePixelRatio;
  53395. }
  53396. }
  53397. if (render) {
  53398. this.setSize(w, h, ratio, o.forTarget );
  53399. }
  53400. }
  53401. setSize(width, height, devicePixelRatio, onlyForTarget){
  53402. //console.log('setSize', width)
  53403. if(!onlyForTarget){//onlyForTarget表示不更改当前renderer,只是为了rendertarget才要改变viewport
  53404. this.renderer.setPixelRatio(devicePixelRatio);
  53405. this.renderer.setSize(width, height ); // resize之后会自动clear(似乎因为setScissor ),所以一定要立刻绘制,所以setSize要在cameraChanged、update之前
  53406. }
  53407. //this.composer && this.composer.setSize(width, height);
  53408. if(this.viewports){
  53409. this.viewports.forEach((view,i)=>{
  53410. //if(!view.active)return
  53411. var width_ = width * view.width;
  53412. var height_ = height * view.height;
  53413. view.setResolution(Math.ceil(width_), Math.ceil(height_), width, height );
  53414. if(height_ == 0)return //avoid NAN
  53415. let aspect = width_ / height_; //camera的参数精确些,不用视口的归整的resolution像素值,否则hasChange无法为true, 导致canvasResize了但map没update从而闪烁
  53416. view.camera.aspect = aspect;
  53417. if(view.camera.type == "OrthographicCamera"){
  53418. /* //不改宽度 同4dkk
  53419. var heightHalf = view.camera.right / aspect
  53420. view.camera.top = heightHalf
  53421. view.camera.bottom = -heightHalf */
  53422. //高宽都改 使大小不随视口大小改变 navvis (直接和视口大小一致即可,通过zoom来定大小)
  53423. view.camera.left = -width_/2;
  53424. view.camera.right = width_/2;
  53425. view.camera.bottom = -height_/2;
  53426. view.camera.top = height_/2;
  53427. }else {
  53428. }
  53429. view.camera.updateProjectionMatrix();
  53430. });
  53431. }
  53432. if(!onlyForTarget){//因为onlyForTarget不传递devicePixelRatio所以不发送了
  53433. this.dispatchEvent('viewerResize');
  53434. this.viewports.forEach(e=>{
  53435. this.ifEmitResize({viewport:e, deviceRatio:devicePixelRatio});
  53436. });
  53437. }
  53438. }
  53439. ifEmitResize(e){//切换viewport渲染时, 若这些viewport大小不同就发送一次, 通知一些材质更新resolution。
  53440. //console.log('ifEmitResize',e.viewport.name,e.viewport.resolution2 )
  53441. if(!e.viewport.resolution.equals(this.oldResolution)||!e.viewport.resolution2.equals(this.oldResolution2)){
  53442. this.dispatchEvent($.extend(e, {type:'resize'}));
  53443. this.oldResolution.copy(e.viewport.resolution);
  53444. this.oldResolution2.copy(e.viewport.resolution2);
  53445. }
  53446. }
  53447. cameraChanged() {//判断相机是否改变
  53448. var changed = false;
  53449. /* if(this.needRender){
  53450. this.needRender = false
  53451. return true
  53452. } */
  53453. for(let i=0,j=this.viewports.length;i<j;i++){
  53454. let viewport = this.viewports[i];
  53455. let changeInfo = viewport.cameraChanged();
  53456. if(changeInfo.changed){
  53457. changed = true;
  53458. //if(!this.changeTime ||this.changeTime<100){
  53459. this.dispatchEvent({
  53460. type: "camera_changed",
  53461. camera: viewport.camera,
  53462. viewport ,
  53463. changeInfo
  53464. });
  53465. //this.changeTime = (this.changeTime || 0) +1
  53466. //}
  53467. viewport.needRender = true; //直接写这咯
  53468. if(changeInfo.resolutionChanged){
  53469. this.ifEmitResize({viewport}); //for map
  53470. }
  53471. }
  53472. }
  53473. return changed
  53474. }
  53475. makeScreenshot( size, viewports, compressRatio){//暂时不要指定viewports渲染,但也可以
  53476. let {width, height} = size;
  53477. /* let oldBudget = Potree.pointBudget;
  53478. Potree.pointBudget = Math.max(10 * 1000 * 1000, 2 * oldBudget);
  53479. let result = Potree.updatePointClouds(this.scene.pointclouds, camera, size );
  53480. Potree.pointBudget = oldBudget;
  53481. this.dispatchEvent({ //resize everything such as lines targets
  53482. type: 'resize',
  53483. resolution: new THREE.Vector2(width,height),
  53484. });*/
  53485. let target = new WebGLRenderTarget(width, height, {
  53486. format: RGBAFormat,
  53487. });
  53488. this.setSize(width, height,1,true);
  53489. this.render({
  53490. target ,
  53491. //camera ,
  53492. viewports: viewports || this.viewports,
  53493. screenshot : true,
  53494. width ,
  53495. height,
  53496. resize :true //需要resize
  53497. });
  53498. let dataUrl = Potree.Utils.renderTargetToDataUrl(target, width, height, this.renderer, compressRatio);
  53499. /* let pixelCount = width * height;
  53500. let buffer = new Uint8Array(4 * pixelCount);
  53501. this.renderer.readRenderTargetPixels(target, 0, 0, width, height, buffer);
  53502. let dataUrl = Potree.Utils.pixelsArrayToDataUrl(buffer, width, height, compressRatio) */
  53503. target.dispose();
  53504. //resize back
  53505. //this.updateScreenSize({forceUpdateSize:true})
  53506. return {
  53507. width,
  53508. height,
  53509. dataUrl
  53510. };
  53511. }
  53512. dispose(scene=this.scene){
  53513. scene.clear();
  53514. this.renderer.dispose();
  53515. this.renderer.forceContextLoss();
  53516. let gl = this.renderer.getContext();
  53517. gl.getExtension("WEBGL_lose_context") && gl.getExtension("WEBGL_lose_context").loseContext();
  53518. this.renderArea.removeChild(this.renderer.domElement);
  53519. this.dispatchEvent('dispose');
  53520. }
  53521. }
  53522. class Viewport extends EventDispatcher{
  53523. constructor( view, camera, prop={}){//目前不支持换camera
  53524. super();
  53525. this.left = prop.left;
  53526. this.bottom = prop.bottom;
  53527. this.width = prop.width;
  53528. this.height = prop.height;
  53529. this.name = prop.name;
  53530. this.view = view;
  53531. this.camera = camera;
  53532. this.active = true;
  53533. this.unableChangePos = false;
  53534. this.noPointcloud;
  53535. //this.keys = [...] firstPersonCtl....
  53536. this.resolution = new Vector2;
  53537. this.resolution2 = new Vector2;
  53538. this.offset = new Vector2; //viewportOffset 范围从0-整个画布的像素
  53539. this.extraEnableLayers = prop.extraEnableLayers || [];//额外可展示的层
  53540. this.cameraLayers = prop.cameraLayers;
  53541. this.pixelRatio = prop.pixelRatio; //如果规定pixelRatio的话要传,这样就覆盖devicePicelRatio, 如magnifier
  53542. }
  53543. clone(){
  53544. return Common.CloneClassObject(this)
  53545. }
  53546. getMoveSpeed(){
  53547. return this.moveSpeed
  53548. }
  53549. setMoveSpeed(e){
  53550. this.moveSpeed = e;
  53551. }
  53552. layersAdd(name){
  53553. this.extraEnableLayers.includes(name) || this.extraEnableLayers.push(name);
  53554. }
  53555. layersRemove(name){
  53556. let index = this.extraEnableLayers.indexOf(name);
  53557. if(index > -1){
  53558. this.extraEnableLayers.splice(index, 1);
  53559. }
  53560. }
  53561. cameraChanged() {
  53562. var copy = ()=>{
  53563. this.previousState = {
  53564. projectionMatrix: this.camera.projectionMatrix.clone(),//worldMatrix在this.control时归零了所以不用了吧,用position和qua也一样
  53565. position: this.camera.position.clone(),
  53566. quaternion: this.camera.quaternion.clone(),
  53567. active:this.active,
  53568. resolution:this.resolution.clone(),
  53569. resolution2:this.resolution2.clone(), //有时clientWidth没变但是ratio缩放了
  53570. };
  53571. };
  53572. let projectionChanged = true, positionChanged = true, quaternionChanged = true, activeChanged = true, resolutionChanged = true;
  53573. let getChanged = ()=>{
  53574. return {
  53575. projectionChanged,positionChanged,quaternionChanged, activeChanged, resolutionChanged,
  53576. changed:projectionChanged || positionChanged || quaternionChanged || activeChanged || resolutionChanged
  53577. }
  53578. };
  53579. if (this.previousState){
  53580. projectionChanged = !this.camera.projectionMatrix.equals(this.previousState.projectionMatrix);
  53581. positionChanged = !this.camera.position.equals(this.previousState.position);
  53582. quaternionChanged = !this.camera.quaternion.equals(this.previousState.quaternion);
  53583. activeChanged = this.active != this.previousState.active;
  53584. resolutionChanged = !this.resolution.equals(this.previousState.resolution) || !this.resolution2.equals(this.previousState.resolution2);
  53585. }
  53586. copy();
  53587. return getChanged()
  53588. }
  53589. setResolution(w,h, wholeW=0, wholeH=0){
  53590. this.resolution.set(w,h);//是client的width height
  53591. this.resolution2.copy(this.resolution).multiplyScalar(this.pixelRatio || window.devicePixelRatio);
  53592. this.offset.set(wholeW,wholeH).multiply(new Vector2(this.left,this.bottom));//.multiplyScalar(window.devicePixelRatio)
  53593. this.dispatchEvent({type:'resize'});
  53594. }
  53595. }
  53596. const 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";
  53597. const prefixFragment ="precision highp float;\nprecision highp int;\n\nuniform mat4 viewMatrix;\nuniform vec3 cameraPosition;\n";
  53598. let shader = {
  53599. uniforms: {
  53600. opacity: {
  53601. type: "f",
  53602. // value: 1
  53603. },
  53604. progress: {
  53605. type: "f",
  53606. value: 0
  53607. },
  53608. pano0Map: {
  53609. type: "t",
  53610. value: null
  53611. },
  53612. pano1Map: {
  53613. type: "t",
  53614. value: null
  53615. },
  53616. depthMap0: {
  53617. type: "t",
  53618. value: null
  53619. },
  53620. depthMap1: {
  53621. type: "t",
  53622. value: null
  53623. },
  53624. pano0Position: {
  53625. type: "v3",
  53626. value: new Vector3
  53627. },
  53628. pano0Matrix: {
  53629. type: "m4",
  53630. value: new Matrix4
  53631. },
  53632. pano1Position: {
  53633. type: "v3",
  53634. value: new Vector3
  53635. },
  53636. pano1Matrix: {
  53637. type: "m4",
  53638. value: new Matrix4
  53639. },
  53640. /* pano1Matrix2: {
  53641. type: "m4",
  53642. value: new THREE.Matrix4
  53643. },
  53644. */
  53645. inverseProjectionMatrix: {
  53646. value: new Matrix4
  53647. },
  53648. /* projectionMatrix:{//需要再写一遍吗
  53649. value: new THREE.Matrix4
  53650. }, */
  53651. viewport: {
  53652. value: new Vector4
  53653. },
  53654. //如 {x: 0, y: 0, z: 428, w: 969} xy应该是offset, zw是宽高
  53655. cameraHeight0: {
  53656. type: "f",
  53657. value: 1
  53658. },
  53659. cameraHeight1: {
  53660. type: "f",
  53661. value: 1
  53662. },
  53663. ceilHeight0:{
  53664. type: "f",
  53665. value: 2
  53666. },
  53667. ceilHeight1:{
  53668. type: "f",
  53669. value: 2
  53670. },
  53671. },
  53672. vertexShader: prefixVertex + `
  53673. uniform vec3 pano0Position;
  53674. uniform mat4 pano0Matrix;
  53675. uniform vec3 pano1Position;
  53676. uniform mat4 pano1Matrix;
  53677. varying vec2 vUv;
  53678. varying vec3 vWorldPosition0;
  53679. varying vec3 vWorldPosition1;
  53680. varying vec3 vWorldPosition12;
  53681. vec3 transformAxis( vec3 direction ) //navvis->4dkk
  53682. {
  53683. float y = direction.y;
  53684. direction.y = direction.z;
  53685. direction.z = -y;
  53686. return direction;
  53687. }
  53688. void main() {
  53689. vUv = uv;
  53690. vec4 worldPosition = modelMatrix * vec4(position, 1.0);
  53691. vec3 positionLocalToPanoCenter0 = worldPosition.xyz - pano0Position;
  53692. vWorldPosition0 = (vec4(positionLocalToPanoCenter0, 1.0) * pano0Matrix).xyz;
  53693. vWorldPosition0.x *= -1.0;
  53694. vWorldPosition0 = transformAxis(vWorldPosition0);
  53695. vec3 positionLocalToPanoCenter1 = worldPosition.xyz - pano1Position;
  53696. vWorldPosition1 = (vec4(positionLocalToPanoCenter1, 1.0) * pano1Matrix).xyz;
  53697. vWorldPosition1.x *= -1.0;
  53698. vWorldPosition1 = transformAxis(vWorldPosition1);
  53699. /*
  53700. vec3 positionLocalToPanoCenter12 = worldPosition.xyz - pano1Position;
  53701. vWorldPosition12 = (vec4(positionLocalToPanoCenter12, 1.0) * pano1Matrix2).xyz;
  53702. vWorldPosition12.x *= -1.0;
  53703. vWorldPosition12 = transformAxis(vWorldPosition12);
  53704. */
  53705. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  53706. }
  53707. `,
  53708. fragmentShader: prefixFragment + `
  53709. #extension GL_EXT_frag_depth : enable // otherwise error: 'GL_EXT_frag_depth' : extension is disabled
  53710. #define PI 3.141592653
  53711. uniform float modelAlpha;
  53712. uniform float opacity;
  53713. uniform float progress;
  53714. uniform int tranType;
  53715. uniform vec3 pano0Position;
  53716. uniform vec3 pano1Position;
  53717. uniform float maxDistance;
  53718. uniform float minDistance;
  53719. uniform float minOpa;
  53720. uniform samplerCube pano0Map;
  53721. uniform samplerCube pano1Map;
  53722. varying vec2 vUv;
  53723. varying vec3 vWorldPosition0;
  53724. varying vec3 vWorldPosition1;
  53725. /* vec2 getSamplerCoord( vec3 direction )
  53726. {
  53727. direction = normalize(direction);
  53728. float tx=atan(direction.x,-direction.y)/(PI*2.0)+0.5;
  53729. float ty=acos(direction.z)/PI;
  53730. return vec2(tx,ty);
  53731. } */
  53732. vec2 getSamplerCoord2( vec3 direction )
  53733. {
  53734. direction = normalize(direction);
  53735. float tx=atan(direction.x,direction.z)/(PI*2.0)+0.5;
  53736. float ty=acos(direction.y)/PI;
  53737. return vec2(tx,ty);
  53738. }
  53739. #if defined(GL_EXT_frag_depth) && defined(hasDepthTex)
  53740. uniform sampler2D depthMap0;
  53741. uniform sampler2D depthMap1;
  53742. uniform mat4 inverseProjectionMatrix;
  53743. uniform mat4 projectionMatrix;
  53744. uniform vec4 viewport;
  53745. uniform float cameraHeight0;
  53746. uniform float cameraHeight1;
  53747. uniform float ceilHeight0;
  53748. uniform float ceilHeight1;
  53749. vec2 getDepth(vec3 dir, sampler2D depthMap, float heightDown, float heightUp, vec4 eyePos){
  53750. vec2 depthValue = vec2(0.0, 0.0);
  53751. vec2 uv2 = getSamplerCoord2( dir.xyz); //暂时只用基于目标漫游点的方向
  53752. uv2.x -= 0.25; //全景图和Cube的水平采样起始坐标相差90度,这里矫正 0.25 个采样偏移
  53753. vec4 depth = texture2D(depthMap, uv2);
  53754. //float distance = depth.r + 256. * (depth.g + 256. * depth.b);
  53755. //distance *= 255. * .001; // distance is now in meters
  53756. //更改
  53757. float distance = (depth.g + depth.r / 256.) * 255.;
  53758. if(distance == 0.0){//漫游点底部识别不到的区域,给一个地板高度
  53759. if(uv2.y < depthTexUVyLimit) distance = heightUp / dir.y;
  53760. else if(uv2.y > 1.0 - depthTexUVyLimit) distance = heightDown / -dir.y;
  53761. else distance = 100000.0;//给个超级远的值
  53762. }
  53763. if(distance == 0.0)distance = 100000.0;//给个超级远的值
  53764. depthValue.x = distance;
  53765. distance += .1; // add a safety margin
  53766. vec4 eyePos2 = vec4(normalize(eyePos.xyz) * distance, 1.);
  53767. vec4 clipPos2 = projectionMatrix * eyePos2;
  53768. vec4 ndcPos2 = clipPos2 * 1. / clipPos2.w;
  53769. depthValue.y = 0.5 * ((gl_DepthRange.far - gl_DepthRange.near) * ndcPos2.z
  53770. + gl_DepthRange.near + gl_DepthRange.far);
  53771. return depthValue;
  53772. }
  53773. //注:未加载好的话,depth为0,导致第一次漫游过去的时候许多mesh会立刻被遮挡,所以要确保加载完
  53774. #endif
  53775. void main()
  53776. {
  53777. vec3 vWorldPosition0N = normalize(vWorldPosition0);
  53778. vec3 vWorldPosition1N = normalize(vWorldPosition1);
  53779. float progress_ = progress;
  53780. vec4 colorFromPano0 = vec4(0.0,0.0,0.0,0.0);
  53781. #if defined(usePanoMap0)
  53782. //即progress < 1.0 通常是1
  53783. colorFromPano0=textureCube(pano0Map,vWorldPosition0N.xyz);
  53784. #else
  53785. progress_ = 1.0;
  53786. #endif
  53787. vec4 colorFromPano1=textureCube(pano1Map,vWorldPosition1N.xyz);
  53788. gl_FragColor = mix(colorFromPano0,colorFromPano1,progress_);
  53789. //深度图修改深度
  53790. #if defined(GL_EXT_frag_depth) && defined(hasDepthTex)
  53791. vec4 ndcPos;
  53792. ndcPos.xy = ((2.0 * gl_FragCoord.xy) - (2.0 * viewport.xy)) / (viewport.zw) - 1.;
  53793. ndcPos.z = (2.0 * gl_FragCoord.z - gl_DepthRange.near - gl_DepthRange.far) /
  53794. (gl_DepthRange.far - gl_DepthRange.near);
  53795. ndcPos.w = 1.0;
  53796. vec4 clipPos = ndcPos / gl_FragCoord.w;
  53797. vec4 eyePos = inverseProjectionMatrix * clipPos;
  53798. vec2 depth0 = vec2(0.0,0.0);
  53799. #if defined(usePanoMap0)
  53800. depth0 = getDepth(vWorldPosition0N, depthMap0, cameraHeight0, ceilHeight0, eyePos);
  53801. #endif
  53802. vec2 depth1 = getDepth(vWorldPosition1N, depthMap1, cameraHeight1, ceilHeight1, eyePos);
  53803. gl_FragDepthEXT = mix(depth0.y,depth1.y,progress_);
  53804. gl_FragDepthEXT = clamp(gl_FragDepthEXT, 0.0, 1.0); //防止部分手机出现黑块。ios 16 。 因为我给的超远值超出范围
  53805. #endif
  53806. }
  53807. `
  53808. };
  53809. //注:gl_FragDepthEXT 修改了确实能像真实mesh那样遮挡住在后面的物体。但是为过渡时不能直接像有模型那样,和角度有关。
  53810. class ModelTextureMaterial extends RawShaderMaterial {
  53811. constructor( ){
  53812. let defines = {depthTexUVyLimit: Potree.config.depthTexUVyLimit};
  53813. let {vs,fs} = Common.changeShaderToWebgl2(shader.vertexShader, shader.fragmentShader, 'RawShaderMaterial');
  53814. super({
  53815. fragmentShader: fs,
  53816. vertexShader: vs,
  53817. uniforms: UniformsUtils.clone(shader.uniforms),
  53818. side:DoubleSide,
  53819. name: "ModelTextureMaterial",
  53820. defines,
  53821. });
  53822. this.glslVersion = Potree.settings.isWebgl2 && '300 es';
  53823. let setSize = (e)=>{
  53824. let viewport = e.viewport;
  53825. //let viewportOffset = viewport.offset || new Vector2()
  53826. let resolution = viewport.resolution2;
  53827. //this.uniforms.viewport.value.set(viewportOffset.x, viewportOffset.y, resolution.x, resolution.y)
  53828. this.uniforms.viewport.value.set(0,0, resolution.x, resolution.y);// xy是在viewport中的left和bottom,和整个窗口没有关系,所以不是viewportOffset。几乎都是0,0
  53829. };
  53830. let viewport = viewer.mainViewport;
  53831. setSize({viewport});
  53832. viewer.addEventListener('resize',(e)=>{
  53833. if(e.viewport.name != "MainView")return
  53834. setSize(e);
  53835. });
  53836. //var supportExtDepth = !!Features.EXT_DEPTH.isSupported()
  53837. {
  53838. //add
  53839. viewer.addEventListener('camera_changed', (e)=>{
  53840. if(e.viewport.name != "MainView")return
  53841. //this.uniforms.projectionMatrix.value.copy(e.camera.projectionMatrix)
  53842. e.camera && this.uniforms.inverseProjectionMatrix.value.copy(e.camera.projectionMatrixInverse);
  53843. });
  53844. }
  53845. let progress = 0;
  53846. Object.defineProperty(this.uniforms.progress, 'value', {
  53847. get: function () {
  53848. return progress
  53849. },
  53850. set: e => {
  53851. if (e < 1 && !Potree.settings.fastTran ) {
  53852. if (!('usePanoMap0' in this.defines)) {
  53853. this.defines.usePanoMap0 = '';
  53854. this.needsUpdate = true;
  53855. }
  53856. } else {
  53857. if ('usePanoMap0' in this.defines) {
  53858. delete this.defines.usePanoMap0;
  53859. this.needsUpdate = true;
  53860. }
  53861. }
  53862. progress = e;
  53863. },
  53864. });
  53865. //-------------------------------------
  53866. }
  53867. /**
  53868. *
  53869. * @param {Panorama} pano0
  53870. * @param {Panorama} pano1
  53871. * @param {boolean} flag
  53872. 更新全景图的材质uniforms
  53873. */
  53874. setProjectedPanos(pano0, pano1, progressValue ){
  53875. progressValue!=void 0 && (this.uniforms.progress.value = progressValue);
  53876. //pano0.ensureSkyboxReadyForRender();
  53877. if(pano0){
  53878. this.uniforms.pano0Map.value = pano0.getSkyboxTexture();//pano0.texture
  53879. this.uniforms.pano0Position.value.copy(pano0.position);
  53880. this.uniforms.pano0Matrix.value.copy(pano0.panoMatrix/* pano0.mesh.matrixWorld */ );
  53881. //pano1.ensureSkyboxReadyForRender();
  53882. }
  53883. this.uniforms.pano1Map.value = pano1.getSkyboxTexture();//pano1.texture;
  53884. this.uniforms.pano1Position.value.copy(pano1.position);
  53885. this.uniforms.pano1Matrix.value.copy(pano1.panoMatrix /* pano1.mesh.matrixWorld */ );
  53886. this.pano0 = pano0;
  53887. this.pano1 = pano1;
  53888. this.updateDepthTex(pano0);
  53889. this.updateDepthTex(pano1);
  53890. //console.log('setProjectedPanos', pano0&&pano0.id, pano1&&pano1.id)
  53891. this.needsUpdate = true;
  53892. }
  53893. updateDepthTex(pano, extra){
  53894. if( !Potree.settings.useDepthTex || !pano || !pano.depthTex || pano!=this.pano0 && pano!=this.pano1)return
  53895. //console.log('updateDepthTex', pano.id, this.pano0 && this.pano0.id, this.pano1 && this.pano1.id)
  53896. if(this.pano0){
  53897. this.uniforms.depthMap0.value = this.pano0.entered ? this.pano0.depthTex : null; //dispose了就不要赋值否则dispose会失败
  53898. this.uniforms.cameraHeight0.value = this.pano0.floorPosition.distanceTo(this.pano0.position);
  53899. this.uniforms.ceilHeight0.value = this.pano0.getCeilHeight() - this.pano0.position.z;
  53900. }
  53901. if(this.pano1){
  53902. this.uniforms.depthMap1.value = this.pano1.depthTex; //pano1还没entered时也需要,可能在飞入
  53903. this.uniforms.cameraHeight1.value = this.pano1.floorPosition.distanceTo(this.pano1.position);
  53904. this.uniforms.ceilHeight1.value = this.pano1.getCeilHeight() - this.pano1.position.z;
  53905. }
  53906. this.updateDepthTexEnable();
  53907. }
  53908. updateDepthTexEnable(){
  53909. let hasDepthTex = this.pano0 && this.pano1 && this.pano0.pointcloud.hasDepthTex && this.pano1.pointcloud.hasDepthTex; //暂时不知道一个有图一个没图怎么写所以
  53910. Potree.Utils.addOrRemoveDefine(this, 'hasDepthTex', hasDepthTex?'add':'remove' );
  53911. }
  53912. /* EnableDepthTex(){//开启DepthTex
  53913. if(this.defines['hasDepthTex']){
  53914. return
  53915. }
  53916. this.defines['hasDepthTex'] = ''
  53917. this.needsUpdate = true;
  53918. } */
  53919. }
  53920. class FastTranPass {
  53921. constructor(renderer){
  53922. this.renderer = renderer;
  53923. this.coverRenderTarget = new WebGLRenderTarget( 100, 100, {
  53924. minFilter: LinearFilter, magFilter: LinearFilter,
  53925. format: RGBAFormat
  53926. });
  53927. this.coverTex = this.coverRenderTarget.texture;
  53928. this.enabled = false;
  53929. /* this.oldClearColor = new THREE.Color();
  53930. this.oldClearAlpha = 1;
  53931. this.camera = new THREE.OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  53932. this.scene = new THREE.Scene(); */
  53933. this.material = this.getMaskMaterial();
  53934. /* var copyShader = THREE.CopyShader;
  53935. this.materialCopy = new THREE.ShaderMaterial( {
  53936. uniforms: this.copyUniforms,
  53937. vertexShader: copyShader.vertexShader,
  53938. fragmentShader: copyShader.fragmentShader,
  53939. blending: THREE.NoBlending,
  53940. depthTest: false,
  53941. depthWrite: false,
  53942. transparent: true
  53943. } );
  53944. this.quad = new THREE.Mesh( new THREE.PlaneBufferGeometry( 2, 2 ), this.material);
  53945. this.quad.frustumCulled = false; // Avoid getting clipped
  53946. this.scene.add( this.quad );
  53947. this.renderToScreen = true*/
  53948. }
  53949. setSize( width, height ) {
  53950. this.coverRenderTarget.setSize( width, height );
  53951. }
  53952. start(){
  53953. this.enabled = true;
  53954. let {x,y} = viewer.mainViewport.resolution2;
  53955. this.setSize(x,y);
  53956. //draw coverTex
  53957. let oldTarget = this.renderer.getRenderTarget();
  53958. //let oldClearColor = this.renderer.getClearColor()
  53959. this.renderer.setRenderTarget(this.coverRenderTarget);
  53960. //this.renderer.setClearColor( 0x000000, 0)
  53961. let oldLayer = viewer.mainViewport.camera.layers.mask;
  53962. Potree.Utils.setCameraLayers(viewer.mainViewport.camera, ['skybox']);
  53963. this.renderer.render( viewer.scene.scene, viewer.mainViewport.camera );
  53964. //this.renderer.setClearColor( 0x000000, 0)
  53965. this.renderer.setRenderTarget(oldTarget);
  53966. viewer.mainViewport.camera.layers.mask = oldLayer;
  53967. this.material.uniforms.progress.value = 1;
  53968. console.log('start111');
  53969. }
  53970. render( scene, camera, viewports, renderer, writeBuffer, readBuffer ) {
  53971. /* var oldAutoClear = renderer.autoClear;
  53972. renderer.autoClear = false;
  53973. */
  53974. let {x,y} = viewer.mainViewport.resolution2;
  53975. var uniforms = this.material.uniforms;
  53976. //uniforms.bgTex.value = readBuffer.texture; //更新
  53977. uniforms.coverTex.value = this.coverTex;
  53978. uniforms.progress.value = viewer.images360.cube.material.uniforms.progress.value;
  53979. uniforms.screenRatio.value = x / y; // 使波纹为圆形
  53980. uniforms.screenRatio.value *= uniforms.screenRatio.value;
  53981. Potree.Utils.screenPass.render(viewer.renderer, viewer.images360.fastTranMaskPass.material);
  53982. //renderer.autoClear = oldAutoClear;
  53983. }
  53984. stop(){
  53985. this.enabled = false;
  53986. console.log('stop111');
  53987. }
  53988. getMaskMaterial(){
  53989. return new ShaderMaterial( {
  53990. uniforms: {
  53991. coverTex: {
  53992. type: "t",
  53993. value: null
  53994. },
  53995. progress:{
  53996. type: "f",
  53997. value: 0
  53998. },
  53999. screenRatio:{
  54000. type: "f",
  54001. value: 1
  54002. }
  54003. },
  54004. vertexShader: `
  54005. varying vec2 vUv;
  54006. void main()
  54007. {
  54008. vUv = uv;
  54009. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  54010. }
  54011. `,
  54012. fragmentShader: `
  54013. uniform sampler2D coverTex;
  54014. uniform float progress;
  54015. uniform float screenRatio;
  54016. varying vec2 vUv;
  54017. void main() {
  54018. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  54019. const float minRadius = 0.0 ;
  54020. 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));
  54021. float diff = 0.292; //1.0-maxRadius;
  54022. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  54023. float radiusOut = radiusIn + diff;
  54024. if(radius < radiusIn) {
  54025. discard;
  54026. }else if(radius>radiusOut){
  54027. gl_FragColor = texture2D(coverTex, vUv) ;
  54028. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  54029. }else{
  54030. /* vec4 color1 = texture2D(bgTex, vUv);
  54031. vec4 color2 = texture2D(coverTex, vUv);
  54032. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  54033. gl_FragColor = mix(color1, color2, rotio); */
  54034. float rotio = smoothstep(radiusIn ,radiusOut, radius);
  54035. vec4 color2 = texture2D(coverTex, vUv);
  54036. color2.a = rotio;
  54037. }
  54038. }
  54039. `
  54040. } );
  54041. }
  54042. /* getMaskMaterial(){
  54043. return new THREE.ShaderMaterial( {
  54044. uniforms: {
  54045. coverTex: {
  54046. type: "t",
  54047. value: null
  54048. },
  54049. bgTex: {
  54050. type: "t",
  54051. value: null
  54052. },
  54053. progress:{
  54054. type: "f",
  54055. value: 0
  54056. },
  54057. screenRatio:{
  54058. type: "f",
  54059. value: 1
  54060. }
  54061. },
  54062. vertexShader: `
  54063. varying vec2 vUv;
  54064. void main()
  54065. {
  54066. vUv = uv;
  54067. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  54068. }
  54069. `,
  54070. fragmentShader: `
  54071. uniform sampler2D coverTex;
  54072. uniform sampler2D bgTex;
  54073. uniform float progress;
  54074. uniform float screenRatio;
  54075. varying vec2 vUv;
  54076. void main() {
  54077. const float maxRadius = 0.708; // sqrt(0.5^2+0.5^2)
  54078. const float minRadius = 0.0 ;
  54079. 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));
  54080. float diff = 0.292; //1.0-maxRadius;
  54081. float radiusIn = maxRadius * progress + minRadius * (1.0-progress);
  54082. float radiusOut = radiusIn + diff;
  54083. if(radius < radiusIn) {
  54084. gl_FragColor = texture2D(bgTex, vUv);
  54085. //gl_FragColor = vec4(0.0,0.0,1.0,1.0);//
  54086. }else if(radius>radiusOut){
  54087. gl_FragColor = texture2D(coverTex, vUv) ;
  54088. //gl_FragColor = vec4(1.0,1.0,0.0,1.0);//
  54089. }else{
  54090. vec4 color1 = texture2D(bgTex, vUv);
  54091. vec4 color2 = texture2D(coverTex, vUv);
  54092. float rotio = smoothstep(radiusIn ,radiusOut,radius);
  54093. gl_FragColor = mix(color1, color2, rotio);
  54094. }
  54095. }
  54096. `
  54097. } );
  54098. } */
  54099. }
  54100. let GLCubeFaces$1 = Potree.defines.GLCubeFaces;
  54101. var TileUtils = {};
  54102. TileUtils.TILE_SIZE = 512,
  54103. TileUtils.FACES_PER_PANO = 6,
  54104. TileUtils.LocationOnTile = {
  54105. Center: 0,
  54106. UpperLeft: 1,
  54107. UpperRight: 2,
  54108. LowerRight: 3,
  54109. LowerLeft: 4
  54110. },
  54111. /*
  54112. * 获取某tile在cube中的方向 direction (向量起点在cube中心,终点在tile图的指定位置)。spherical通过先求uv,再直接得到dir
  54113. * @param {*} size 面分辨率
  54114. * @param {*} cubeFace 所在面
  54115. * @param {*} Center 在tile上的目标位置,默认为中心,其他位置就是四个顶点
  54116. * @param {*} c 似乎是在tile的缩进百分比,根据所在面的不同,分别向不同方向缩进,但都是向tile的中心
  54117. * @param {*} dir 所求方向
  54118. */
  54119. TileUtils.getTileVector = function() {//获取某tile在cube中的方向 direction (向量起点在cube中心,终点在tile图的中心)
  54120. return function(size, tileSize, cubeFace, tileX, tileY, Center, c, dir) {//c似乎是缩进百分比
  54121. Center = Center || TileUtils.LocationOnTile.Center;
  54122. //假设该cube边长为2:
  54123. var u = size / tileSize
  54124. , d = tileX / u;
  54125. tileY = -tileY + (u - 1);
  54126. var p = tileY / u
  54127. , f = tileSize / size
  54128. , g = 2 * f //一个tile的宽度 (乘以2是因为cube边长是2)
  54129. , m = g / 2
  54130. , v = 2 * d - 1 + m
  54131. , A = 2 * p - 1 + m;
  54132. switch (Center) {//计算在tile中指定位置带来的偏移
  54133. case TileUtils.LocationOnTile.UpperLeft: //1
  54134. v -= m,
  54135. A += m,
  54136. v += c * g; //似乎是向内缩进
  54137. break;
  54138. case TileUtils.LocationOnTile.UpperRight:
  54139. v += m,
  54140. A += m,
  54141. A -= c * g;
  54142. break;
  54143. case TileUtils.LocationOnTile.LowerRight:
  54144. v += m,
  54145. A -= m,
  54146. v -= c * g;
  54147. break;
  54148. case TileUtils.LocationOnTile.LowerLeft:
  54149. v -= m,
  54150. A -= m,
  54151. A += c * g;
  54152. break;
  54153. case TileUtils.LocationOnTile.Center: //0
  54154. }
  54155. switch (cubeFace) {
  54156. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  54157. MathLight.setVector(dir, -1, A, -v);
  54158. break;
  54159. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  54160. MathLight.setVector(dir, 1, A, v);
  54161. break;
  54162. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Y: //顶面
  54163. MathLight.setVector(dir, -v, 1, -A);
  54164. break;
  54165. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  54166. MathLight.setVector(dir, -v, -1, A);
  54167. break;
  54168. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  54169. MathLight.setVector(dir, -v, A, 1);
  54170. break;
  54171. case GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  54172. MathLight.setVector(dir, v, A, -1);
  54173. }
  54174. MathLight.normalize(dir);
  54175. }
  54176. }(),
  54177. /*
  54178. * 获取该tile在第几个面(简易装载法)
  54179. */
  54180. TileUtils.getFaceForTile = function(size, index) {//获取该tile在第几个面
  54181. var tileSize = TileUtils.TILE_SIZE;
  54182. size < TileUtils.TILE_SIZE && (tileSize = size);
  54183. var n = Math.floor(size / tileSize)
  54184. , sum = n * n; //得每个面tile总数
  54185. return Math.floor(index / sum)
  54186. }
  54187. ,
  54188. TileUtils.getTileLocation = function(size, t, result) {
  54189. var tileSize = TileUtils.TILE_SIZE;
  54190. size < TileUtils.TILE_SIZE && (tileSize = size);
  54191. var r = TileUtils.getFaceForTile(size, t)
  54192. , a = Math.floor(size / tileSize)
  54193. , s = a * a
  54194. , l = t - r * s;
  54195. result.tileX = l % a;
  54196. result.tileY = Math.floor(l / a);
  54197. result.face = r;
  54198. result.faceTileIndex = l;
  54199. return result
  54200. }
  54201. ,
  54202. /*
  54203. * 求size分辨率需要多少张tile
  54204. */
  54205. TileUtils.getTileCountForSize = function(e) {
  54206. if (e <= TileUtils.TILE_SIZE)
  54207. return TileUtils.FACES_PER_PANO;
  54208. var t = Math.floor(e / TileUtils.TILE_SIZE)
  54209. , i = t * t
  54210. , n = i * TileUtils.FACES_PER_PANO;
  54211. return n
  54212. }
  54213. ,
  54214. TileUtils.getRelativeDirection = function() {
  54215. var e = new MathLight.Matrix4
  54216. , t = new MathLight.Quaternion;
  54217. return function(i, n) {//i是pano.quaternion, n是camera的direction
  54218. t.copy(i),
  54219. t.inverse(),
  54220. e.makeRotationFromQuaternion(t),
  54221. e.applyToVector3(n),
  54222. MathLight.normalize(n);
  54223. }
  54224. }(),
  54225. /*
  54226. * 根据方向寻找合适的tile加载
  54227. */
  54228. TileUtils.matchingTilesInDirection = function() {
  54229. var e = new MathLight.Vector3
  54230. , t = new MathLight.Vector3(0,0,-1)
  54231. , i = new MathLight.Quaternion
  54232. , n = function(e, t) {
  54233. e.push({
  54234. face: t.face,
  54235. faceTileIndex: t.faceTileIndex,
  54236. tileX: t.tileX,
  54237. tileY: t.tileY
  54238. });
  54239. }
  54240. , a = function() {
  54241. var e = {
  54242. face: -1,
  54243. faceTileIndex: -1,
  54244. tileX: -1,
  54245. tileY: -1
  54246. };
  54247. return function(size, i, r) {
  54248. for (var a = TileUtils.getTileCountForSize(size), s = 0, l = 0; l < a; l++)
  54249. TileUtils.getTileLocation(size, l, e),
  54250. i && !i(e) || (s++,
  54251. r && n(r, e));
  54252. return s
  54253. }
  54254. }();
  54255. return function(pano, size, dir, hFov, vFov, result) {
  54256. var d = size < TileUtils.TILE_SIZE ? size : TileUtils.TILE_SIZE;
  54257. //TileUtils.getTileCountForSize(size);
  54258. if (!hFov && !vFov)
  54259. return a(size, null, result);
  54260. var p = !!vFov;
  54261. vFov = vFov || hFov,
  54262. vFov = Math.max(0, Math.min(vFov, 360)),
  54263. hFov = Math.max(0, Math.min(hFov, 360)),
  54264. MathLight.copyVector(dir, e),
  54265. TileUtils.getRelativeDirection(pano.quaternion4dkk, e);
  54266. if(p){//如果有vFov hFov
  54267. i.setFromUnitVectors(e, t);
  54268. var f = function(e) {
  54269. return TileUtils.isTileWithinFrustum(size, d, e.face, e.tileX, e.tileY, i, hFov, vFov)//在视野中的
  54270. };
  54271. return a(size, f, result)
  54272. }
  54273. var g = function(t) {//如果仅有hFov
  54274. return TileUtils.isTileWithinFOV(size, d, t.face, t.tileX, t.tileY, e, hFov)
  54275. };
  54276. return a(size, g, result)
  54277. }
  54278. }(),
  54279. /*
  54280. * 是否在屏幕范围内
  54281. */
  54282. TileUtils.isTileWithinFrustum = function() {
  54283. var e = new MathLight.Vector3
  54284. , t = 1e-5;
  54285. return function(i, n, a, s, l, c, h, u) {
  54286. 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++){
  54287. TileUtils.getTileVector(i, n, m, s, l, b, 0, e),//get e // size, tileSize, cubeFace, tileX, tileY, Center, c, dir
  54288. MathLight.applyQuaternionToVector(c, e);
  54289. if (e.z >= -t)//似乎是在相机背面
  54290. I++;
  54291. else {
  54292. var w = -1 / e.z
  54293. , _ = e.x * w
  54294. , T = e.y * w;
  54295. T > d ? v++ : T < p && A++, //这四种似乎代表在这个画框之外,如在左、在上、在下、在右
  54296. _ > f ? y++ : _ < g && C++,
  54297. E++;
  54298. }
  54299. }
  54300. return A !== E && v !== E && y !== E && C !== E //如果有一项和E相等代表要么是在相机背面要么是tile的四个顶点都画在画布的同一边,所以肯定不在画布上
  54301. }
  54302. }(),
  54303. /*
  54304. * 是否在FOV范围内
  54305. */
  54306. TileUtils.isTileWithinFOV = function() {
  54307. var e = new MathLight.Vector3
  54308. , t = new MathLight.Vector3(0,1,0)
  54309. , i = new MathLight.Vector3(1,0,0);
  54310. return function(panoSize, tileSize, face, tileX, tileY, direction, fov) {//direction是作用了pano.quaternion的camera.direction
  54311. var d = TileUtils.mapFaceToCubemapFace(face);
  54312. MathLight.cross(direction, t, i); //get i 好像没用到
  54313. TileUtils.getTileVector(panoSize, tileSize, d, tileX, tileY, TileUtils.LocationOnTile.Center, 0, e);
  54314. if (TileUtils.isWithinFOV(e, direction, fov, null))//先判断tile中心在不在FOV内
  54315. return !0;
  54316. for (var p = fov / 360, f = Math.floor(1 / p), g = 0, m = 0; m < f; m++) {
  54317. for (var v = TileUtils.LocationOnTile.UpperLeft; v <= TileUtils.LocationOnTile.LowerLeft; v++)
  54318. if (TileUtils.getTileVector(panoSize, tileSize, d, tileX, tileY, v, g, e),
  54319. TileUtils.isWithinFOV(e, direction, fov, null))
  54320. return !0;
  54321. g += p; //可能是考虑到有可能tile比fov覆盖了fov(虽然一般不可能,除非fov特别小),所以将tile分成若干段,取tile中的点再检测下
  54322. }
  54323. return !1
  54324. }
  54325. }(),
  54326. TileUtils.isWithinFOV = function() {
  54327. var e = new MathLight.Vector3
  54328. , t = new MathLight.Vector3;
  54329. return function(dir, cameraDir, fov, a) {
  54330. if (MathLight.copyVector(dir, t),
  54331. a) {
  54332. MathLight.copyVector(a, e),
  54333. MathLight.normalize(e);
  54334. var s = MathLight.dot(e, dir);
  54335. e.x *= s,
  54336. e.y *= s,
  54337. e.z *= s,
  54338. MathLight.subVector(t, e);
  54339. }
  54340. var l = fov / 2 * MathLight.RADIANS_PER_DEGREE
  54341. , c = Math.cos(l)
  54342. , h = MathLight.dot(t, cameraDir);
  54343. return h >= c
  54344. }
  54345. }(),
  54346. TileUtils.mapFaceToCubemapFace = function() {
  54347. var e = {
  54348. 0: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
  54349. 1: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
  54350. 2: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_POSITIVE_X,
  54351. 3: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
  54352. 4: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
  54353. 5: GLCubeFaces$1.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
  54354. };
  54355. return function(t) {
  54356. return e[t]
  54357. }
  54358. }();
  54359. let { PanoRendererEvents, PanoramaEvents, PanoSizeClass} = Potree.defines;
  54360. var texLoader$3 = new TextureLoader();
  54361. const markerOpacitys ={
  54362. default : 0.4,
  54363. hovered : 1,
  54364. };
  54365. const labelProp = {
  54366. sizeInfo: {minSize : 200 , maxSize : 250, nearBound : 0.8, farBound : 10},
  54367. backgroundColor:{r: 255, g: 255, b: 255, a: 0.4 },
  54368. textColor:{r: 0, g: 0, b: 0, a: 1 },
  54369. borderRadius: 15,
  54370. renderOrder:10,
  54371. useDepth:true,
  54372. clipDistance: 30, maxClipFactor:0.3, occlusionDistance:3,
  54373. };
  54374. const labelProp2 = {
  54375. //sizeInfo: {minSize : 200 , maxSize : 250, nearBound : 0.8, farBound : 10},
  54376. backgroundColor:{r: 255, g: 255, b: 255, a: 0 },
  54377. textColor:{r:255 , g: 255, b: 255, a: 1 },
  54378. textBorderColor:{r:30 , g:30, b: 30, a: 1 },
  54379. textBorderThick:3,
  54380. dontFixOrient:true,
  54381. renderOrder:10,
  54382. fontsize:30,
  54383. };
  54384. let markerTex;
  54385. //显示全景图时marker没有被遮挡,如果需要,要换成depthBasicMaterial 或者直接把skybox的深度修改(拿到深度贴图后更如此)
  54386. let planeGeo = new PlaneBufferGeometry(0.2,0.2);
  54387. let sg = new SphereGeometry(0.1, 8, 8);
  54388. let smHovered = new MeshBasicMaterial({/* side: THREE.BackSide, */color: 0xff0000});
  54389. let sm = new MeshBasicMaterial({/* side: THREE.BackSide */});
  54390. var rot90 = new Quaternion().setFromAxisAngle(new Vector3(0,0,1), Math.PI/2 ); //使用的是刚好适合全景图的,给cube贴图需要转90°
  54391. //var rot90 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(1,0,0), -Math.PI/2 ); //4dkk->navvis
  54392. //var rot901 = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,1,0), -Math.PI/2 ); //整张球幕图要旋转下
  54393. //rot90 = new THREE.Quaternion().multiplyQuaternions( rot901, rot90)
  54394. var old = null;
  54395. /*
  54396. 转成四维看看的axis:
  54397. var a = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0,0,1), THREE.Math.degToRad(-90)) 因为四维的要绕y转90
  54398. 这里的quaternion.multiply(a);
  54399. 先乘再换顺序 w : q.w, x:q.x , y:-q.z, z:q.y
  54400. */
  54401. //暂时直接用4dkkconsole输出的数据
  54402. class Panorama extends EventDispatcher{
  54403. constructor(o, images360){//file, time, longitude, latitude, altitude, course, pitch, roll
  54404. super();
  54405. this.id = o.id; //唯一标识
  54406. this.images360 = images360;
  54407. this.visible = true; //for updateVisible
  54408. this.enabled = true;//是否可以走
  54409. this.addEventListener('isVisible',(e)=>{//是否显示该点的mesh(不显示也能走)
  54410. //console.log('pano isVisible', this.id, e.visible)
  54411. Potree.Utils.updateVisible(this.marker, 'panoVisi', e.visible);
  54412. Potree.settings.showPanoMesh && (this.mesh.visible = e.visible);
  54413. if(e.reason == 'screenshot' || e.visible){
  54414. this.label && (this.label.visible = e.visible);//截图时隐藏下
  54415. }
  54416. this.label2 && Potree.Utils.updateVisible(this.label2, 'panoVisi', e.visible);
  54417. });
  54418. /*
  54419. 漫游点可见性:旧
  54420. level reason 类型
  54421. 2(最高)buildingChange(不在此楼层) unvisible
  54422. 1 modeIsShowPanos(漫游模式) visible //不记得为什么加这个了,所以重写
  54423. 0 pointcloudVisi(隐藏了数据集) unvisible
  54424. */
  54425. /*
  54426. 漫游点可见性:新
  54427. level reason 类型
  54428. 2(最高)buildingChange(不在此楼层) unvisible
  54429. 1 ifShowMarker(marker显示开关) unvisible
  54430. 0 pointcloudVisi(隐藏了数据集) unvisible
  54431. */
  54432. if(Potree.settings.editType == 'pano'){//漫游点拼合编辑
  54433. this.uuid = o.uuid; //因为有多个数据集 所以会重复
  54434. this.index = this.originID = o.index; //下标, 用于visibles
  54435. this.pointcloud = viewer.scene.pointclouds.find(e=>e.panoUuid == o.uuid);
  54436. this.pointcloud.panos.push(this);
  54437. this.sid = this.pointcloud.dataset_id + '|' + this.uuid; //不会更改的标记 用于entity.panos里的标记
  54438. this.panosData = o;
  54439. //数据中原本的位置朝向
  54440. this.dataPosition = new Vector3().copy(o.pose.translation);
  54441. this.dataQuaternion = new Quaternion().copy(o.pose.rotation);
  54442. this.dataRotation = new Euler().setFromQuaternion(this.dataQuaternion);
  54443. //因为位置朝向随着点云位置改变,所以直接运用到点云上,这里清零
  54444. this.originPosition = new Vector3(); //{x: 0, y: 0, z: 0}
  54445. this.quaternion = new Quaternion(); //{w: 0, x: 0, y: 0, z: 1}
  54446. //this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion)//4dkk内使用的quaternion
  54447. this.visibles = o.visibles;
  54448. this.rtkState = o.has_rtk ? o.use_rtk : null;
  54449. const height = 1.4; //相机高度
  54450. this.originFloorPosition = this.originPosition.clone();
  54451. this.originFloorPosition.z -= height;
  54452. /* this.originPosition = new THREE.Vector3().copy(o.pose.translation) //{x: 0, y: 0, z: 0}
  54453. this.quaternion = new THREE.Quaternion().copy(o.pose.rotation) //{w: 0, x: 0, y: 0, z: 1}
  54454. //this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion)//4dkk内使用的quaternion
  54455. this.visibles = o.visibles
  54456. this.pointcloud = viewer.scene.pointclouds.find(e=>e.dataset_id == o.uuid)
  54457. this.pointcloud.panos.push(this)
  54458. const height = 1.5; //相机高度
  54459. this.originFloorPosition = this.originPosition.clone()
  54460. this.originFloorPosition.z -= height
  54461. */
  54462. }else {
  54463. this.originPosition = new Vector3().fromArray(o.dataset_location); //完全对应vision.txt的translation
  54464. this.originFloorPosition = new Vector3().fromArray(o.dataset_floor_location);
  54465. this.originID = parseInt(o.file_id);//"file_id":"00022"对应是原本的4dkk的id --来自vision.txt
  54466. this.pointcloud = viewer.scene.pointclouds.find(e=>e.dataset_id == o.dataset_id) || viewer.scene.pointclouds[0];
  54467. this.pointcloud.panos.push(this);
  54468. //this.sid = this.pointcloud.sceneCode + '|' + this.originID //不会更改的标记
  54469. this.sid = this.pointcloud.dataset_id + '|' + this.originID; //不会更改的标记
  54470. //全景图和Cube的水平采样起始坐标相差90度
  54471. /* if(from4dkk){
  54472. var qua = o.dataset_orientation
  54473. var quaternion = new THREE.Quaternion().fromArray(qua)
  54474. quaternion = new THREE.Quaternion().multiplyQuaternions(quaternion, rot901);//整张球幕图要旋转下 因为在4dkk里转过,还原。如果是tiles的不用
  54475. this.quaternion = new THREE.Quaternion(quaternion.x, -quaternion.z, quaternion.y, quaternion.w) //转化坐标
  54476. }else{ */
  54477. var qua = o.dataset_orientation; //完全对应vision.txt的rotation
  54478. qua = [qua[1], qua[2], qua[3], qua[0]];
  54479. this.quaternion = new Quaternion().fromArray(qua);
  54480. this.quaternion4dkk = math.convertVisionQuaternion(this.quaternion);//4dkk内使用的quaternion
  54481. this.quaternion2 = this.quaternion.clone();
  54482. this.quaternion = new Quaternion().multiplyQuaternions(this.quaternion, rot90);//全景图和Cube的水平采样起始坐标相差90度,cubeTex转90度
  54483. this.rotation4dkk = new Euler().setFromQuaternion(this.quaternion4dkk);
  54484. //}
  54485. //this.quaternion1 = Potree.Utils.QuaternionFactory.fromArray(o.dataset_orientation)
  54486. //同quaternion
  54487. //let xy = this.transform.forward([this.longitude, this.latitude]);
  54488. //this.file = `https://4dkk.4dage.com/images/images${Potree.settings.number}/pan/high/${this.id}.jpg`
  54489. this.neighbours = [];
  54490. }
  54491. this.rotation = new Euler().setFromQuaternion(this.quaternion);
  54492. this.build();
  54493. this.transformByPointcloud(); //初始化位移
  54494. {//tile
  54495. this.minimumTiledPanoLoaded = !1;
  54496. this.highestPartialTileRenderOpCompleted = 0;
  54497. this.highestFullTileRenderOpCompleted = 0;
  54498. this.shouldRedrawOnBaseLoaded = !1;
  54499. this.resolutionPromise = {};
  54500. this.tiledPanoRenderTarget = null;
  54501. this.zoomed = !1;
  54502. images360.panoRenderer.addEventListener(PanoRendererEvents.TileRenderSuccess, this.onTileRendered.bind(this));
  54503. images360.panoRenderer.addEventListener(PanoRendererEvents.PanoRenderComplete, this.onPanoRendered.bind(this));
  54504. images360.panoRenderer.addEventListener(PanoRendererEvents.TileRenderFailure, this.onTileRenderFail.bind(this));
  54505. images360.panoRenderer.addEventListener(PanoRendererEvents.UploadAttemptedForAllTiles, this.onUploadAttemptedForAllTiles.bind(this));
  54506. }
  54507. this.addEventListener('hoverOn', (e)=>{//from Map
  54508. if(!e.byMainView){
  54509. this.hoverOn(e);
  54510. }
  54511. });
  54512. this.addEventListener('hoverOff', (e)=>{
  54513. if(!e.byMainView){
  54514. this.hoverOff(e);
  54515. }
  54516. });
  54517. }
  54518. get noNeighbour(){//是否绝对到不到的孤立点
  54519. for(let i=0,j=this.images360.panos.length; i<j; i++){
  54520. if(this.images360.neighbourMap[this.id][i] !== false ){
  54521. return false
  54522. }
  54523. }
  54524. return true
  54525. //return this.neighbours.length == 0
  54526. }
  54527. setEnable(enable){//是否可以走
  54528. Potree.Utils.updateVisible(this, 'isEnabled', enable); //令所有marker不可见
  54529. this.enabled = enable;
  54530. //如果当前在全景模式且在这个点,需要切换显示吗? 目前用不到
  54531. }
  54532. loadDepthImg(){
  54533. if(!this.pointcloud.hasDepthTex || this.depthTex || this.depthTexLoading)return
  54534. this.depthTexLoading = true;
  54535. let mapping = Potree.settings.isLocal2 ? '' : this.pointcloud.datasetData.mapping; //非离线包的话加mapping
  54536. let src = `${Potree.settings.urls.prefix1}/${mapping?(mapping+'/'):''}${Potree.settings.webSite}/${this.pointcloud.sceneCode}/data/${this.pointcloud.sceneCode}/depthmap/${this.originID}.png`;
  54537. // `${Potree.settings.urls.prefix1}/${Potree.settings.webSite}/${this.pointcloud.sceneCode}/data/${this.pointcloud.sceneCode}/depthmap/${this.originID}.png`
  54538. //console.log('开始下载depthImg', this.id)
  54539. let texture = texLoader$3.load( src, ()=>{
  54540. this.depthTex = texture;
  54541. this.dispatchEvent({type:'loadedDepthImg', loaded:true});
  54542. this.images360.dispatchEvent({type:'loadedDepthImg', pano:this});
  54543. this.depthTexLoading = false;
  54544. this.images360.updateDepthTex(this);
  54545. },null,(e)=>{//error
  54546. console.error('loadDepthImg失败, 数据集sceneCode'+ this.pointcloud.sceneCode, this.id );
  54547. this.pointcloud.hasDepthTex = false;
  54548. this.dispatchEvent({type:'loadedDepthImg' });
  54549. });
  54550. texture.wrapS = RepeatWrapping;
  54551. texture.flipY = false;
  54552. texture.magFilter = LinearFilter;
  54553. texture.minFilter = LinearFilter;
  54554. texture.generateMipmaps = false;
  54555. }
  54556. build(){
  54557. { // orientation
  54558. //add
  54559. //var quaternion = new THREE.Quaternion().multiplyQuaternions(this.quaternion, rot901);//改 为球目全
  54560. //quaternion.premultiply(rot90)
  54561. this.panoMatrix = new Matrix4().makeRotationFromQuaternion(this.quaternion);
  54562. this.oriPanoMatrix = this.panoMatrix.clone();
  54563. if(this.quaternion2)this.oriPanoMatrix2 = new Matrix4().makeRotationFromQuaternion(this.quaternion2);
  54564. //console.log(this.quaternion)
  54565. //this.quaternion = quaternion
  54566. }
  54567. /* let marker = new THREE.Mesh(planeGeo, this.getMarkerMat() )
  54568. //marker.lookAt(marker.up)
  54569. marker.scale.set(2,2,2) */
  54570. let marker = new Mesh(planeGeo, this.getMarkerMat() ); //new Sprite({mat:this.getMarkerMat(), dontFixOrient:true })
  54571. marker.scale.set(2,2,2);//marker.scale.set(0.4,0.4,0.4)
  54572. marker.name = 'marker_'+this.id;
  54573. marker.up.set(0,0,1);
  54574. this.addEventListener('changeMarkerTex',(e)=>{
  54575. marker.material.map = markerTex[e.name];
  54576. });
  54577. this.marker = marker;
  54578. marker.pano = this;
  54579. this.images360.node.add(marker);
  54580. Potree.settings.isTest && this.addLabel();
  54581. //this.addLabel2()
  54582. marker.addEventListener('mouseover', this.hoverOn.bind(this));
  54583. marker.addEventListener('mouseleave', this.hoverOff.bind(this));
  54584. }
  54585. transformByPointcloud(){
  54586. let position = this.originPosition.clone().applyMatrix4(this.pointcloud.transformMatrix);//也可以用datasetPosTransform算
  54587. let floorPosition = this.originFloorPosition.clone().applyMatrix4(this.pointcloud.transformMatrix);
  54588. this.setPosition(position, floorPosition);
  54589. this.panoMatrix = new Matrix4().multiplyMatrices(this.pointcloud.rotateMatrix, this.oriPanoMatrix );
  54590. //this.panoMatrix2 = Potree.Utils.datasetRotTransform({fromDataset:true, pointcloud:this.pointcloud, matrix:this.oriPanoMatrix, getMatrix:true}) //和上一行结果一样
  54591. //quaternion也变下
  54592. if(this.oriPanoMatrix2){
  54593. this.panoMatrix2 = new Matrix4().multiplyMatrices(this.pointcloud.rotateMatrix, this.oriPanoMatrix2 );//供DepthImageSampler使用
  54594. this.panoMatrix2Inverse = this.panoMatrix2.clone().invert();
  54595. }
  54596. this.dispatchEvent('rePos');
  54597. }
  54598. setPosition(position, floorPosition){
  54599. this.position = position;
  54600. this.floorPosition = floorPosition;
  54601. //this.mesh.position.copy(this.position)
  54602. this.marker.position.copy(this.floorPosition);
  54603. this.marker.position.z+=0.04;//会被点云遮住
  54604. if(this.label){
  54605. if(Potree.settings.editType == 'pano'){
  54606. this.label.position.copy(this.position);
  54607. }else {
  54608. this.label.position.copy(this.floorPosition);
  54609. }
  54610. this.label.position.z+=0.14;
  54611. this.label.update();
  54612. }
  54613. /* if(this.label2){
  54614. if(Potree.settings.editType == 'pano'){
  54615. this.label2.position.copy(this.position)
  54616. }else{
  54617. this.label2.position.copy(this.floorPosition)
  54618. }
  54619. this.label2.position.copy(this.marker.position)
  54620. this.label2.update()
  54621. } */
  54622. }
  54623. /* getRealPos(){//当整体移动以后
  54624. return this.position.clone().applyMatrix4(viewer.scene.scene.matrix)
  54625. } */
  54626. getMarkerMat(){
  54627. if(!markerTex) {
  54628. markerTex = {
  54629. default:texLoader$3.load( Potree.resourcePath+'/textures/marker.png' ),
  54630. ring:texLoader$3.load( Potree.resourcePath+'/textures/marker2.png' )
  54631. };
  54632. markerTex.default.anisotropy = 4; // 各向异性过滤 .防止倾斜模糊
  54633. markerTex.ring.anisotropy = 4;
  54634. //有可能被点云遮住吗。
  54635. }
  54636. return new DepthBasicMaterial({opacity: markerOpacitys.default, side: DoubleSide , map:markerTex.default ,transparent:true,
  54637. clipDistance: 2, occlusionDistance:1, //不能设置太短,因为过渡时深度不准确
  54638. useDepth: !!(Potree.settings.useDepthTex && this.pointcloud.hasDepthTex),
  54639. autoDepthTest:true
  54640. //改为DepthBasicMaterial是因为原Basic的材质在有深度图时过渡会先隐藏后出现。 注:没有深度图时全景模式的marker无法遮挡
  54641. })
  54642. }
  54643. hoverOn(e={}) {
  54644. //console.log("hoverOn " + this.id )
  54645. transitions.start(lerp.property(this.marker.material, "opacity", markerOpacitys.hovered,()=>{
  54646. viewer.dispatchEvent('content_changed');
  54647. }), this.marker.visible ? 250 : 0);
  54648. if(!e.byMap) this.dispatchEvent({type:'hoverOn', byMainView:true});
  54649. if(!e.byImages360) this.images360.dispatchEvent({type:'markerHover', hovered:true, pano:this});
  54650. }
  54651. hoverOff(e={}){
  54652. //console.log("hoverOff " + this.id )
  54653. transitions.start(lerp.property(this.marker.material, "opacity", markerOpacitys.default,()=>{
  54654. viewer.dispatchEvent('content_changed');
  54655. }), this.marker.visible ? 250 : 0);
  54656. if(!e.byMap) this.dispatchEvent({type:'hoverOff', byMainView:true});
  54657. if(!e.byImages360) this.images360.dispatchEvent({type:'markerHover', hovered:false, pano:this});
  54658. }
  54659. setZoomed(zoomed){
  54660. this.zoomed = zoomed;
  54661. Potree.settings.displayMode == 'showPanos' && this.updateSkyboxForZoomLevel(); //放大后换成zoomTarget贴图
  54662. viewer.dispatchEvent({type:'panoSetZoom', zoomed});
  54663. }
  54664. enter(){
  54665. this.entered = true;
  54666. this.setZoomed(!1);
  54667. viewer.dispatchEvent({type:PanoramaEvents.Enter, oldPano:old, newPano:this } );
  54668. old = this;
  54669. //console.log("enter pano "+ this.id)
  54670. }
  54671. exit(){
  54672. this.clearWaitDeferreds();
  54673. this.minimumTiledPanoLoaded = !1;
  54674. this.tiledPanoRenderTarget = null;
  54675. this.setZoomed(!1);
  54676. this.images360.panoRenderer.deactivateTiledPano(this);
  54677. this.highestPartialTileRenderOpCompleted = 0;
  54678. this.highestFullTileRenderOpCompleted = 0;
  54679. this.depthTex && this.depthTex.dispose(); //贴图不使用后先dispose,下次到该点时会自动还原
  54680. this.entered = false; //add
  54681. //console.log("exit pano "+ this.id)
  54682. viewer.dispatchEvent({type:PanoramaEvents.Exit, pano:this});
  54683. }
  54684. updateSkyboxForZoomLevel(){
  54685. if(this.minimumTiledPanoLoaded){
  54686. this.images360.updateProjectedPanos();
  54687. }
  54688. }
  54689. getSkyboxTexture(){
  54690. if(this.minimumTiledPanoLoaded)
  54691. {
  54692. if(this.zoomed && this.images360.qualityManager.maxRenderTargetSize > this.images360.qualityManager.maxNavPanoSize)//change 如果放大后和不放大都是2k就不用这个
  54693. {
  54694. return this.images360.panoRenderer.zoomRenderTarget.texture;
  54695. }
  54696. else
  54697. {
  54698. this.tiledPanoRenderTarget.texture.mapping = UVMapping;//add
  54699. return this.tiledPanoRenderTarget.texture;
  54700. }
  54701. }
  54702. else
  54703. {
  54704. return null;
  54705. }
  54706. }
  54707. isLoaded(e){
  54708. if (e && "string" == typeof e)
  54709. console.error("Wrong panoSize given to Panorama.isLoaded(); a tiled pano uses PanoSizeClass");
  54710. return !!this.minimumTiledPanoLoaded && (!e || this.highestFullTileRenderOpCompleted >= e)//改:原本是:this.highestPartialTileRenderOpCompleted >= e, 希望这代表全部加载完
  54711. }
  54712. getWaitDeferred(size){//获取不同size的tile贴图的promiss
  54713. var t = this.resolutionPromise[this.id];
  54714. t || (t = {}, this.resolutionPromise[this.id] = t);
  54715. var i = t[size];
  54716. return i || (i = {
  54717. deferred: $.Deferred(),
  54718. active: !1
  54719. },
  54720. t[size] = i),
  54721. i
  54722. }
  54723. clearWaitDeferreds(){
  54724. var e = this.resolutionPromise[this.id];
  54725. e || (e = {},
  54726. this.resolutionPromise[this.id] = e);
  54727. for (var t in e)
  54728. if (e.hasOwnProperty(t)) {
  54729. var i = e[t];
  54730. i.active = !1,
  54731. i.deferred = $.Deferred();
  54732. }
  54733. }
  54734. resetWaitDeferred(e){
  54735. var t = this.getWaitDeferred(e);
  54736. t.active = !1;
  54737. t.deferred = $.Deferred();
  54738. }
  54739. onTileRendered(ev){
  54740. ev.id === this.id && this.dispatchEvent({
  54741. type:PanoramaEvents.TileLoaded,
  54742. size:ev.panoSize, index:ev.tileIndex, count:ev.totalTiles
  54743. });
  54744. }
  54745. onPanoRendered(ev) {
  54746. if(ev.id === this.id)
  54747. {
  54748. this.minimumTiledPanoLoaded = !0;
  54749. this.updateSkyboxForZoomLevel();//更新贴图 setProjected
  54750. ev.panoSize > this.highestPartialTileRenderOpCompleted && (this.highestPartialTileRenderOpCompleted = ev.panoSize);//应该是更新最高获取到的Partial size
  54751. ev.updateFullComplete && ev.panoSize > this.highestFullTileRenderOpCompleted && (this.highestFullTileRenderOpCompleted = ev.panoSize); //应该是更新最高获取到的Full size
  54752. //this.dispatchEvent("load", ev.panoSize);
  54753. viewer.ifAllLoaded( this);
  54754. this.dispatchEvent({type:PanoramaEvents.LoadComplete, size:ev.panoSize, count:ev.totalTiles});
  54755. }
  54756. }
  54757. onTileRenderFail(ev) {
  54758. ev.id === this.id && this.dispatchEvent({type:PanoramaEvents.LoadFailed });
  54759. }
  54760. onUploadAttemptedForAllTiles(ev) {
  54761. if (ev.id === this.id) {
  54762. var n = this.images360.qualityManager.getPanoSize(PanoSizeClass.BASE);
  54763. if(ev.panoSize === n && this.shouldRedrawOnBaseLoaded) //shouldRedrawOnBaseLoaded一直是false。在4dkk里只有初始点在quickstart后变为true。
  54764. {
  54765. this.shouldRedrawOnBaseLoaded = !1;
  54766. this.panoRenderer.resetRenderStatus(this.id, !0, !1);
  54767. this.panoRenderer.renderPanoTiles(this.id, null, !0, !0);
  54768. }
  54769. }
  54770. }
  54771. addLabel(){
  54772. this.removeTextLabel();
  54773. this.label = new TextSprite$2(Object.assign({},
  54774. labelProp, {text: this.id + "("+this.originID+")"}) //{text: `id:${this.id}, dataset:${this.pointcloud.name}, 4dkkId:${this.originID}`}
  54775. );
  54776. this.images360.node.add(this.label);
  54777. this.floorPosition && this.label.position.copy(this.floorPosition);
  54778. }
  54779. addLabel2(){
  54780. if(this.label2)return
  54781. this.label2 = new TextSprite$2(Object.assign({},
  54782. labelProp2, {text: /* this.originID */ parseInt(this.id)+1 }) //{text: `id:${this.id}, dataset:${this.pointcloud.name}, 4dkkId:${this.originID}`}
  54783. );
  54784. //this.images360.node.add(this.label2);
  54785. this.marker.add(this.label2);
  54786. //this.floorPosition && this.label2.position.copy(this.floorPosition)
  54787. let s = 0.2;
  54788. this.label2.scale.set(s,s,s);
  54789. Potree.Utils.updateVisible(this.label2, 'notDisplay', false);
  54790. Potree.Utils.updateVisible(this.label2, 'panoVisi', this.visible);
  54791. //Potree.Utils.setObjectLayers(this.label2, 'bothMapAndScene')
  54792. }
  54793. removeTextLabel(){
  54794. if(this.label){
  54795. this.label.parent.remove(this.label);
  54796. }
  54797. }
  54798. dispose(){
  54799. let i = viewer.images360.panos.indexOf(this);
  54800. if(i==-1)return
  54801. this.marker.parent.remove(this.marker);
  54802. this.removeTextLabel();
  54803. if(this.depthTex) this.depthTex.dispose();
  54804. viewer.images360.panos.splice(i,1);
  54805. this.dispatchEvent('dispose');
  54806. //删除tile贴图、depthTex等以后再写
  54807. }
  54808. getCeilHeight(){//天花板高度值 (假设不存在depth为0的点,所有为0的要么是在盲区,要么是无穷远。)
  54809. if(this.ceilZ == void 0){
  54810. //const depthTiming = Potree.timeCollect.depthSampler.median //pc firefox达到4. chrome为0.01
  54811. //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
  54812. let rotMat = new Matrix4().makeRotationX((Potree.config.depthTexUVyLimit+0.01)*Math.PI);// 角度不能小于天花板中空的半径
  54813. let dir0 = new Vector3(0,0,1).applyMatrix4(rotMat);
  54814. let dirs = [
  54815. dir0,
  54816. dir0.clone().applyMatrix4(new Matrix4().makeRotationZ(Math.PI*2 / 3)),
  54817. dir0.clone().applyMatrix4(new Matrix4().makeRotationZ(-Math.PI*2 / 3))
  54818. ];
  54819. /* if(depthTiming < 1){
  54820. let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
  54821. dirs.push(dirs[0].clone().applyMatrix4(rotMat1))
  54822. }
  54823. if(depthTiming < 0.3){
  54824. let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
  54825. dirs.push(dirs[0].clone().applyMatrix4(rotMat2));
  54826. } */
  54827. let zs = dirs.map(dir_=>{
  54828. let dir = dir_.clone().applyMatrix4(this.panoMatrix2); //pano不一定是垂直的, 需要把之前的dirInPano先转成真实的dir,防止超出角度限制
  54829. let intersect = viewer.images360.getIntersect(this, dir);
  54830. let z = intersect ? intersect.location.z : Infinity;/* this.position.z+skyHeight */ //没有intersect代表可能是天空
  54831. return z
  54832. });
  54833. zs.sort((a,b)=>{return b-a});//得最大值 (不用中位数的原因:在屋檐处,如果仅有一个intersect是天空,因到了室外所以也用天空高度)
  54834. this.ceilZ = zs[0];
  54835. let min = this.position.z + 1; // 防止意外太低
  54836. this.ceilZ = Math.max(min, this.ceilZ);
  54837. //console.log(this.id, 'ceilZ:', this.ceilZ )
  54838. }
  54839. return this.ceilZ
  54840. }
  54841. };
  54842. Panorama.prototype.loadTiledPano = function() {
  54843. //var downloads = [] , t = [];
  54844. var downloaded = {} , eventAdded = {}, latestPartialRequest = {}; //每个pano对应一组这些
  54845. return function(size, dirs, fov, o, a, download) {
  54846. var dir = dirs.datasetsLocal.find(e=>e.datasetId == this.pointcloud.dataset_id).direction;
  54847. //var dir = dirs
  54848. null !== o && void 0 !== o || (o = !0),
  54849. null !== a && void 0 !== a || (a = !0);
  54850. var l = this.getWaitDeferred(size)
  54851. , c = l.deferred
  54852. , h = null
  54853. , u = null;
  54854. fov && ("number" == typeof fov ? h = fov : (h = fov.hFov, u = fov.vFov));
  54855. if (!this.isLoaded(size)) {
  54856. //console.log('loadTiledPano', this.id, size, fov)
  54857. if (!l.active) {
  54858. l.active = !0;
  54859. let name = this.id + ":" + size;
  54860. downloaded[name] = downloaded[name] || [];
  54861. /*
  54862. this.downloaded = downloaded
  54863. this.latestPartialRequest = latestPartialRequest
  54864. */
  54865. latestPartialRequest[name] = null;
  54866. if (fov) {
  54867. let tileArr = [];//add
  54868. var d = TileUtils.matchingTilesInDirection(this, size, dir, h, u, tileArr);
  54869. latestPartialRequest[name] = tileArr;
  54870. downloaded[name].forEach((e)=>{
  54871. let item = latestPartialRequest[name].find(a=>e.faceTileIndex == a.faceTileIndex && e.face == a.face);
  54872. if(item){
  54873. item.loaded = true;
  54874. }
  54875. });
  54876. if(!latestPartialRequest[name].some(e=>!e.loaded)){//所需要的全部加载成功
  54877. //let total = TileUtils.getTileCountForSize(size)
  54878. //this.onPanoRendered(this.id, size, total, !0);
  54879. c.resolve(size/* , total */);
  54880. this.resetWaitDeferred(size);
  54881. //console.log('该部分早已经加载好了'+size, this.id)
  54882. latestPartialRequest[name] = null;
  54883. }
  54884. //console.log("Loading partial pano: " + this.id + " with " + d + " tiles")
  54885. }
  54886. if(!eventAdded[this.id]) {
  54887. eventAdded[this.id] = !0;
  54888. this.addEventListener(PanoramaEvents.LoadComplete, function(ev/* e, t */) {//本次任务全部加载完毕
  54889. //console.warn('点位(可能部分)下载完成 ', 'id:'+this.id, 'size:'+ev.size )
  54890. var i = this.getWaitDeferred(ev.size).deferred;//"pending"为还未完成
  54891. i && "pending" === i.state() && this.highestPartialTileRenderOpCompleted >= ev.size && (i.resolve(ev.size, ev.count),
  54892. this.resetWaitDeferred(ev.size));//恢复active为false
  54893. }.bind(this));
  54894. this.addEventListener(PanoramaEvents.LoadFailed, function(ev) {
  54895. var t = this.getWaitDeferred(e).deferred;
  54896. t && "pending" === t.state() && this.highestPartialTileRenderOpCompleted >= ev.t && (t.reject(ev.t),
  54897. this.resetWaitDeferred(ev.t));//恢复active为false
  54898. }.bind(this));
  54899. this.addEventListener(PanoramaEvents.TileLoaded, function(ev/* t, i, n */) {//每张加载完时
  54900. //console.log('tileLoaded', 'id:'+this.id, 'size:'+ev.size, 'tileIndex:'+ev.index )
  54901. let tileIndex = ev.index;
  54902. let total = ev.count;
  54903. let size = ev.size;
  54904. let name = this.id + ":" + size;
  54905. downloaded[name] = downloaded[name] || []; //不是所有的加载都是从loadTiledPano获取的所以会有未定义的情况
  54906. let {faceTileIndex,face} = TileUtils.getTileLocation(size, tileIndex, {});
  54907. downloaded[name].push({faceTileIndex,face});
  54908. var r = this.getWaitDeferred(size).deferred;
  54909. if (r && "pending" === r.state()) {
  54910. r.notify(size, tileIndex, total);
  54911. if(latestPartialRequest[name]){
  54912. let item = latestPartialRequest[name].find(e=>e.faceTileIndex == faceTileIndex && e.face == face);
  54913. item && (item.loaded = true );
  54914. if(!latestPartialRequest[name].some(e=>!e.loaded)){//所需要的局部tiles全部加载成功
  54915. this.onPanoRendered(this.id, size, total, !0); //onPanoRendered还会触发 PanoramaEvents.LoadComplete
  54916. r.resolve(size, total);
  54917. this.resetWaitDeferred(size);
  54918. //console.log('该部分加载好了'+size, this.id)
  54919. latestPartialRequest[name] = null;
  54920. }
  54921. }
  54922. }
  54923. viewer.dispatchEvent('content_changed');
  54924. /* var r = this.getWaitDeferred(ev.size).deferred;
  54925. if (r && "pending" === r.state()) {
  54926. r.notify(ev.size, ev.index, ev.count);
  54927. var o = downloads[this.id + ":" + ev.size];
  54928. if(o){//如果有规定下载哪些tile,只需要下载这些tile则LoadComplete
  54929. o.tileCount++
  54930. if(o.tileCount === o.targetTileCount){//达到下载目标数
  54931. this.onPanoRendered(this.id, ev.size, ev.count, !0);
  54932. r.resolve(ev.size, ev.count);
  54933. this.resetWaitDeferred(ev.size)
  54934. }
  54935. }
  54936. } */
  54937. }.bind(this));
  54938. }
  54939. }
  54940. this.images360.tileDownloader.clearForceQueue();
  54941. this.images360.tileDownloader.forceQueueTilesForPano(this, size, dir, h, u, download);
  54942. this.tiledPanoRenderTarget = this.images360.panoRenderer.activateTiledPano(this, this.images360.qualityManager.getMaxNavPanoSize(), o);
  54943. this.images360.panoRenderer.renderPanoTiles(this.id, dirs, a);
  54944. }else {
  54945. //console.log('早已经全加载好了' +size, this.id)
  54946. c.resolve(size);
  54947. }
  54948. return c.promise()
  54949. }
  54950. }();
  54951. let {ModelManagerEvents,PanoSizeClass: PanoSizeClass$1} = Potree.defines;
  54952. class QualityManager {
  54953. constructor(e, t, i) {
  54954. this.maxNavPanoSize = -1;
  54955. this.maxZoomPanoSize = -1;
  54956. this.devicePixelDensity = e;
  54957. this.deviceScreenSize = t;
  54958. this.clientBandwidth = i;
  54959. this.panoSizeClassMap = {};
  54960. this.useHighResolutionPanos = !0; //是否能够使用2k及以上图
  54961. this.useUltraHighResolutionPanos = !1;
  54962. this.modelHasUltraHighPanos = !1;
  54963. this.qualityManager = this;
  54964. this.maxRenderTargetSize = browser.isMobile() ? 2048 : 4096; //add
  54965. this.init();
  54966. }
  54967. init(e ) {
  54968. //var metadata = store.getters['scene/metadata'] ;//有时候请求不到
  54969. //if(metadata.sceneSource == 11 || metadata.sceneScheme == 12){
  54970. /* if(config.tileClass == '1k'){
  54971. this.useHighResolutionPanos = false //xzw add 只加载1k
  54972. } */
  54973. this.buildPanoSizeClassMap(this.devicePixelDensity, this.deviceScreenSize, this.clientBandwidth);
  54974. this.ultraHighSize = this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  54975. this.highSize = this.getPanoSize(PanoSizeClass$1.HIGH);
  54976. this.standardSize = this.getPanoSize(PanoSizeClass$1.STANDARD);
  54977. this.baseSize = this.getPanoSize(PanoSizeClass$1.BASE);
  54978. config$1.tiling.maxZoomPanoQuality && this.ultraHighSize <= config$1.tiling.maxZoomPanoQuality && (config$1.tiling.allowUltraHighResolution = !0);
  54979. this.highQualityThreshold = browser.valueFromHash("threshold2k", config$1.windowHeightHighQualityThreshold);
  54980. this.updateMaximums();
  54981. //e.on(ModelManagerEvents.ActiveModelChanged, this.onModelChanged.bind(this));
  54982. }
  54983. updateFromModel(e) {
  54984. //this.updateHighResolutionSettings(e)
  54985. this.updateUltraHighResolutionSettings(e);
  54986. }
  54987. /* updateHighResolutionSettings(e) {
  54988. this.useHighResolutionPanos = !0
  54989. this.updateMaximums()
  54990. } */
  54991. updateUltraHighResolutionSettings(e) {
  54992. if (config$1.tiling.allowUltraHighResolution && this.modelHasUltraHighPanos) {
  54993. this.useUltraHighResolutionPanos = !0;
  54994. } else {
  54995. this.useUltraHighResolutionPanos = !1;
  54996. }
  54997. this.updateMaximums();
  54998. }
  54999. enableUltraHighQualityMode() {
  55000. this.modelHasUltraHighPanos = !0;
  55001. this.updateUltraHighResolutionSettings(null);
  55002. }
  55003. ultraHighQualityModeEnabled() {
  55004. return this.modelHasUltraHighPanos
  55005. }
  55006. onModelChanged(e) {
  55007. this.updateFromModel(e.model),
  55008. this.updateMaximums();
  55009. }
  55010. updateMaximums() {
  55011. this.maxNavPanoSize = config$1.tiling.maxNavPanoQuality || this.detectMaxNavPanoSize(),
  55012. this.maxZoomPanoSize = config$1.tiling.maxZoomPanoQuality || this.detectMaxZoomPanoSize(),
  55013. this.maxZoomPanoSize < this.maxNavPanoSize && (this.maxNavPanoSize = this.maxZoomPanoSize);
  55014. }
  55015. buildPanoSizeClassMap() {
  55016. this.panoSizeClassMap[PanoSizeClass$1.BASE] = 512,
  55017. this.panoSizeClassMap[PanoSizeClass$1.STANDARD] = 1024,
  55018. this.panoSizeClassMap[PanoSizeClass$1.HIGH] = 2048,
  55019. this.panoSizeClassMap[PanoSizeClass$1.ULTRAHIGH] = 4096;
  55020. }
  55021. getPanoSize(e) {
  55022. return this.panoSizeClassMap[e]
  55023. }
  55024. getMaxPossiblePanoSize() {
  55025. return this.getPanoSize(PanoSizeClass$1.ULTRAHIGH)
  55026. }
  55027. getMaxPanoSize() {
  55028. return this.maxZoomPanoSize
  55029. }
  55030. getMaxNavPanoSize() {
  55031. return this.maxNavPanoSize
  55032. }
  55033. getMaxZoomPanoSize() {
  55034. return this.maxZoomPanoSize
  55035. }
  55036. detectMaxNavPanoSizeClass() {
  55037. //return this.useHighResolutionPanos ? browser.isMobile() ? PanoSizeClass.STANDARD : window.innerHeight < this.highQualityThreshold ? PanoSizeClass.STANDARD : PanoSizeClass.HIGH : PanoSizeClass.STANDARD
  55038. /* if(config.name == 'decor'){
  55039. return PanoSizeClass.STANDARD
  55040. }
  55041. return PanoSizeClass.HIGH */
  55042. switch(Potree.settings.navTileClass){
  55043. case '1k':
  55044. return PanoSizeClass$1.STANDARD;
  55045. break;
  55046. case '2k':
  55047. default:
  55048. return PanoSizeClass$1.HIGH;
  55049. }
  55050. }
  55051. detectMaxNavPanoSize() {
  55052. var e = this.detectMaxNavPanoSizeClass();
  55053. return this.getPanoSize(e)
  55054. }
  55055. detectMaxZoomPanoSize() { //获取当前zoomRenderTarget应下载的最高级别
  55056. //若是有三个级别,每次只需要加载到当前的zoomLevel;而两级时因为有zoomed来判断是使用基本贴图还是zoomRenderTarget,所以只需要返回最大的即可
  55057. if(this.zoomLevelResolution){//有三个级别
  55058. if(this.zoomLevelResolution == '4k' && this.useUltraHighResolutionPanos){
  55059. return this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  55060. }else if(this.zoomLevelResolution == '1k' || !this.useHighResolutionPanos){
  55061. return this.getPanoSize(PanoSizeClass$1.STANDARD);
  55062. }else {
  55063. return this.getPanoSize(PanoSizeClass$1.HIGH);
  55064. }
  55065. }else {
  55066. if (this.useHighResolutionPanos) {
  55067. /* if (browser.isMobile()) {//手机版如果要2k的将这里去掉
  55068. if (settings.tiling.mobileHighQualityOverride) {
  55069. return this.getPanoSize(PanoSizeClass.HIGH);
  55070. } else {
  55071. return this.getPanoSize(PanoSizeClass.STANDARD);
  55072. }
  55073. } else */if (this.useUltraHighResolutionPanos ) {
  55074. return this.getPanoSize(PanoSizeClass$1.ULTRAHIGH);
  55075. } else {
  55076. return this.getPanoSize(PanoSizeClass$1.HIGH);
  55077. }
  55078. } else {
  55079. return this.getPanoSize(PanoSizeClass$1.STANDARD);
  55080. }
  55081. }
  55082. }
  55083. }
  55084. let {DownloadStatus} = Potree.defines;
  55085. var h = Object.freeze({
  55086. None: 0,
  55087. DirectionalFOV: 1
  55088. });
  55089. var u = function () {
  55090. var e = function e(t, i) {
  55091. var n = e._panoSpaceDir,
  55092. r = e._fovThreshold,
  55093. o = e._fovThresholdNarrow,
  55094. a = Math.max(Math.min(n.dot(t.direction), 1), -1),
  55095. s = Math.max(Math.min(n.dot(i.direction), 1), -1);
  55096. return t._dot = a,
  55097. i._dot = s,
  55098. 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)
  55099. };
  55100. return e._panoSpaceDir = new Vector3,
  55101. e._fovThreshold = -1,
  55102. e._fovThresholdNarrow = -1,
  55103. e
  55104. }();
  55105. class TilePrioritizer {//优先级处理序列
  55106. constructor(e,t, i, o, a) {
  55107. this.qualityManager = e;
  55108. this.maxNavQuality = this.qualityManager.getMaxNavPanoSize();
  55109. this.maxZoomQuality = this.qualityManager.getMaxZoomPanoSize();
  55110. this.baseSize = t;
  55111. this.standardSize = i;
  55112. this.highSize = o;
  55113. this.ultraHighSize = a;
  55114. this.priorityCriteria = new TilePrioritizer.PriorityCriteria(null, new Vector3(0, 0, 0), new Vector3(0, 0, -1), new Vector3(0, 0, -1));
  55115. }
  55116. updateCriteria(e, t, i, n) {//由player更新
  55117. this.priorityCriteria.pano = e,
  55118. this.priorityCriteria.cameraPosition.copy(t),
  55119. //this.priorityCriteria.cameraDir.copy(i),
  55120. this.priorityCriteria.cameraDirs = i;
  55121. this.priorityCriteria.upcomingPanos = n,
  55122. this.maxNavQuality = this.qualityManager.getMaxNavPanoSize(),
  55123. this.maxZoomQuality = this.qualityManager.getMaxZoomPanoSize();
  55124. }
  55125. canDownloadSize(e) {
  55126. return this.maxNavQuality >= e || this.maxZoomQuality >= e && this.zoomingActive
  55127. }
  55128. /* populateNeighborPanos(e, t, i) {
  55129. i = i || [],
  55130. i.length = 0;
  55131. var n = t.getNeighbours(e);
  55132. for (var r in n)
  55133. if (n.hasOwnProperty(r)) {
  55134. var o = t.get(r);
  55135. if(!o){
  55136. console.log(1)
  55137. }
  55138. i.push(o)
  55139. }
  55140. return i
  55141. } */
  55142. populateScoredPanos(e, t, i, dirs, a, dontFilterDir) {
  55143. i = i || [],
  55144. i.length = 0;
  55145. var s = [Images360.filters.not(e)],
  55146. l = [Images360.scoreFunctions.distanceSquared(e), Images360.scoreFunctions.direction(e.position, dirs)],
  55147. c = Common.sortByScore(t, s, l);
  55148. if(!dontFilterDir){
  55149. s.push(Images360.filters.inPanoDirection(e.position, dirs, TilePrioritizer.DIRECTION_SCORE_STRICTNESS),);
  55150. }
  55151. if (c)
  55152. for (var h = 0; h < c.length && h < a; h++) {
  55153. var u = c[h].item;
  55154. i.push(u);
  55155. }
  55156. return i
  55157. }
  55158. queueTilesForPanos(e, t, i, n, r) {
  55159. for (var o = 0, a = 0; a < t.length; a++) {
  55160. var s = t[a],
  55161. l = this.queueTilesForPano(e, i, s, n);
  55162. if (o += l > 0 ? 1 : 0,
  55163. r && o >= r)
  55164. break
  55165. }
  55166. return o
  55167. }
  55168. /* queueTilesInDirectionForPanos(e, t, i, n, r, o, a, s) {//没用到
  55169. for (var l = 0, c = 0; c < i.length; c++) {
  55170. var h = i[c],
  55171. u = this.queueTilesInDirectionForPano(e, t, h, n, o, a);
  55172. if (l += u > 0 ? 1 : 0,
  55173. s && l >= s)
  55174. break
  55175. }
  55176. return l
  55177. }
  55178. */
  55179. canIncludeDescriptor(e) {
  55180. return e.status !== DownloadStatus.Downloading && e.status !== DownloadStatus.Downloaded
  55181. }
  55182. canIncludePano(e, t) {
  55183. return !e.isLoaded(t)
  55184. }
  55185. getFOVDotThreshold(e) {
  55186. return Math.cos(MathUtils.degToRad(e / 2))
  55187. }
  55188. setZoomingActive(e) {
  55189. e !== this.zoomingActive && (this.zoomingActive = e);
  55190. }
  55191. }
  55192. TilePrioritizer.PriorityCriteria = function (e, t, i, n, o) {
  55193. this.pano = e,
  55194. this.cameraPosition = (new Vector3).copy(t),
  55195. //this.cameraDir = (new THREE.Vector3).copy(i),
  55196. this.cameraDirs = [], //
  55197. this.panoSpaceDir = (new Vector3).copy(n),
  55198. this.upcomingPanos = o,
  55199. this.copy = function (e) {
  55200. this.pano = e.pano,
  55201. this.cameraPosition.copy(e.cameraPosition),
  55202. //this.cameraDir.copy(e.cameraDir),
  55203. this.cameraDirs = e.cameraDirs;
  55204. this.panoSpaceDir.copy(e.panoSpaceDir),
  55205. this.upcomingPanos = o;
  55206. },
  55207. this.zoomingActive = !1;
  55208. };
  55209. TilePrioritizer.DIRECTIONAL_FOV = 180;
  55210. TilePrioritizer.DIRECTIONAL_FOV_NARROW = 120;
  55211. TilePrioritizer.MAX_SCORED_PANOS_TOCONSIDER = 6;
  55212. TilePrioritizer.MAX_SCORED_PANOS_TOADD = 2;
  55213. TilePrioritizer.MAX_UPCOMING_PANOS_TOADD = 3;
  55214. TilePrioritizer.DIRECTION_SCORE_STRICTNESS = .75;
  55215. TilePrioritizer.appendQueue = function (e, t) {
  55216. if (e && t)
  55217. for (var i = 0; i < t.length; i++){
  55218. e.push(t[i]);
  55219. //console.log(t[i])
  55220. }
  55221. };
  55222. TilePrioritizer.sortPanoTiles = function (descriptors, pano, dir) {
  55223. if(dir.datasetsLocal) dir = dir.datasetsLocal.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction;//add
  55224. u._panoSpaceDir.copy(dir);
  55225. TileUtils.getRelativeDirection(pano.quaternion4dkk, u._panoSpaceDir); //应该是将dir根据quaternion转化下
  55226. u._fovThresholdNarrow = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  55227. u._fovThreshold = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV);
  55228. descriptors.sort(u);
  55229. };
  55230. TilePrioritizer.insertSortedPanoTile = function (e, t, pano, dir) {
  55231. if(dir.datasetsLocal) dir = dir.datasetsLocal.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction;//add
  55232. u._panoSpaceDir.copy(dir),
  55233. TileUtils.getRelativeDirection(pano.quaternion4dkk, u._panoSpaceDir),
  55234. u._fovThresholdNarrow = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV_NARROW),
  55235. u._fovThreshold = math.getFOVDotThreshold(TilePrioritizer.DIRECTIONAL_FOV);
  55236. for (var o = -1, a = 0; a < e.length; a++) {
  55237. var s = u(t, e[a]);
  55238. if (s <= 0) {
  55239. o = a;
  55240. break
  55241. }
  55242. }
  55243. if (o === -1)
  55244. e[e.length] = t;
  55245. else {
  55246. for (var h = e.length; h > o; h--)
  55247. e[h] = e[h - 1];
  55248. e[o] = t;
  55249. }
  55250. };
  55251. TilePrioritizer.prototype.filterDepthTex = function (panos ) {// 下载depthTex
  55252. if(!Potree.settings.useDepthTex || !this.priorityCriteria.pano || viewer.mainViewport.view.isFlying())return
  55253. let cameraDirLocals = this.priorityCriteria.cameraDirs.vectorForward;
  55254. let nearPanos = []; //用于获得邻近点位序列
  55255. this.populateScoredPanos(this.priorityCriteria.pano, panos, nearPanos, cameraDirLocals , Infinity, true);
  55256. let dlCount = browser.isMobile() ? 1 : 2;
  55257. let loadingCount = panos.filter(p=>p.depthTexLoading).length;
  55258. if(viewer.mapViewer){
  55259. let mapLayer = viewer.mapViewer.mapLayer;
  55260. loadingCount += mapLayer.loadingInProgress * 1.5 + mapLayer.waitQueue.length;
  55261. }
  55262. if(loadingCount<dlCount){
  55263. nearPanos.filter(p=>!p.depthTex).slice(0, dlCount-loadingCount).forEach(p=>p.loadDepthImg());
  55264. }
  55265. this.nearPanos = nearPanos;
  55266. };
  55267. TilePrioritizer.prototype.filterAndPrioritize = function () {//挑选出优先加载的 pano和tile (有点复杂,没看很懂)
  55268. var e = [],
  55269. t = [],
  55270. i = [];
  55271. return function (queue, panos, tileDownloader) {
  55272. //this.populateNeighborPanos(this.priorityCriteria.pano, panos, e);
  55273. /* let cameraDirLocals = this.priorityCriteria.cameraDirs.map(e=>{ //add
  55274. var dataset = viewer.scene.pointclouds.find(u=>u.dataset_id == e.datasetId)
  55275. var matrix = new THREE.Matrix4().copy(dataset.rotateMatrix)
  55276. var direction = math.convertVector.YupToZup(e.direction)
  55277. return {
  55278. datasetId:e.datasetId,
  55279. direction: direction.clone().applyMatrix4(matrix)
  55280. }
  55281. }) */
  55282. let cameraDirLocals = this.priorityCriteria.cameraDirs.vectorForward;
  55283. //获得视野范围内的邻近点位序列t
  55284. this.populateScoredPanos(this.priorityCriteria.pano, panos, t, cameraDirLocals , TilePrioritizer.MAX_SCORED_PANOS_TOCONSIDER);
  55285. //t.filter(p=>!p.depthTex).slice(0, Potree.config.depTexDlCount).forEach(p=>p.loadDepthImg()) //add
  55286. var s = this.baseSize //512
  55287. ,
  55288. l = this.standardSize //1024
  55289. ,
  55290. c = this.highSize //2048
  55291. ,
  55292. h = this.ultraHighSize; //4096
  55293. this.queueTilesForPano(queue, tileDownloader, this.priorityCriteria.pano, s); //把当前pano的512下载了
  55294. if (this.priorityCriteria.upcomingPanos) {// 添加即将走到的点(之前用于导览路线)512 tiles
  55295. this.queueTilesForPanos(queue, this.priorityCriteria.upcomingPanos, tileDownloader, s, TilePrioritizer.MAX_UPCOMING_PANOS_TOADD);
  55296. }
  55297. i.length = 0;
  55298. //把当前pano角度范围内的tile按照分辨率从低到高加入队列
  55299. if (this.canDownloadSize(l)) {//1024如果在限制范围内的话
  55300. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, l, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  55301. }
  55302. TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs); //排序
  55303. TilePrioritizer.appendQueue(queue, i);
  55304. //添加邻近点t 512的tiles
  55305. this.queueTilesForPanos(queue, t, tileDownloader, s, TilePrioritizer.MAX_SCORED_PANOS_TOADD);
  55306. i.length = 0;
  55307. //NARROW :
  55308. if (this.canDownloadSize(c)) {//2048
  55309. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, c, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  55310. }
  55311. if (this.canDownloadSize(h)) {//4096
  55312. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, h, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV_NARROW);
  55313. }
  55314. TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs);//排序
  55315. TilePrioritizer.appendQueue(queue, i);
  55316. i.length = 0;
  55317. if (this.canDownloadSize(l)) {//1024
  55318. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, l, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
  55319. }
  55320. if (this.canDownloadSize(c)) {//2048
  55321. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, c, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
  55322. }
  55323. if (this.canDownloadSize(h)) {//4096
  55324. this.queueTilesInDirectionForPano(i, tileDownloader, this.priorityCriteria.pano, h, this.priorityCriteria.cameraPosition, this.priorityCriteria.cameraDirs, TilePrioritizer.DIRECTIONAL_FOV);
  55325. }
  55326. TilePrioritizer.sortPanoTiles(i, this.priorityCriteria.pano, this.priorityCriteria.cameraDirs);//排序
  55327. TilePrioritizer.appendQueue(queue, i);
  55328. this.queueTilesForPanos(queue, e, tileDownloader, s); // 如果前面有populateNeighborPanos的话,这步就是加neibour
  55329. }
  55330. }();
  55331. TilePrioritizer.prototype.queueTilesInDirectionForPano = function () {
  55332. var e = {
  55333. filter: h.DirectionalFOV,
  55334. direction: new Vector3,
  55335. fov: 60
  55336. },
  55337. t = new Vector3;
  55338. return function (i, n, pano, o, a, dirs, c) {
  55339. var dir = dirs.datasetsLocal.find(e=>e.datasetId == pano.pointcloud.dataset_id).direction;//add
  55340. //var dir = dirs
  55341. t.copy(dir);
  55342. TileUtils.getRelativeDirection(pano.quaternion4dkk, t);
  55343. e.direction.copy(t);
  55344. e.fov = c;
  55345. return this.filterAndQueueTileDownloadDescriptors(i, n, pano, o, e)
  55346. }
  55347. }();
  55348. TilePrioritizer.prototype.filterAndQueueTileDownloadDescriptors = function () {
  55349. var e = [];
  55350. return function (t, i, n, r, o) {
  55351. var a = i.getTileDownloadDescriptors(n, r);
  55352. e.length = 0,
  55353. this.filterTileDownloadDescriptors(n, a, e, o);
  55354. for (var s = 0, l = 0; l < e.length; l++) {
  55355. var c = e[l];
  55356. if (c) {
  55357. t.push(c);
  55358. s++;
  55359. }
  55360. }
  55361. return s
  55362. }
  55363. }();
  55364. TilePrioritizer.prototype.filterTileDownloadDescriptors = function () {
  55365. new Vector3;
  55366. return function (e, t, i, n) {
  55367. var r, o;
  55368. switch (n.filter) {
  55369. case h.DirectionalFOV:
  55370. for (r = 0; r < t.length; r++)
  55371. o = t[r],
  55372. TileUtils.isTileWithinFOV(o.panoSize, o.tileSize, o.face, o.tileX, o.tileY, n.direction, n.fov) && i.push(o);
  55373. break;
  55374. default:
  55375. for (r = 0; r < t.length; r++)
  55376. o = t[r],
  55377. i.push(o);
  55378. }
  55379. for (r = 0; r < i.length; r++)
  55380. o = i[r],
  55381. this.canIncludeDescriptor(o) || (i[r] = null);
  55382. }
  55383. }();
  55384. TilePrioritizer.prototype.queueTilesForPano = function () {
  55385. var e = {
  55386. filter: h.None
  55387. };
  55388. return function (t, i, n, r) {
  55389. return this.filterAndQueueTileDownloadDescriptors(t, i, n, r, e)
  55390. }
  55391. }();
  55392. /* TilePrioritizer.prototype.queueTilesForPanosInDirection = function () { //没用到
  55393. var e = new THREE.Vector3;
  55394. return function (t, i, n, r, o, a, s, l) {
  55395. for (var h = 0, u = 0; u < n.length; u++) {
  55396. var d = n[u];
  55397. e.copy(d.position),
  55398. e.sub(o),
  55399. e.normalize();
  55400. var p = Math.max(Math.min(a.dot(e), 1), -1),
  55401. f = c.getFOVDotThreshold(s);
  55402. if (p >= f) {
  55403. var g = this.queueTilesInDirectionForPano(t, i, d, r, o, a, s);
  55404. if (h += g > 0 ? 1 : 0,
  55405. l && h >= l)
  55406. break
  55407. }
  55408. }
  55409. return h
  55410. }
  55411. }() */
  55412. //import { i18n } from "@/lang/index"
  55413. // 媒体名称
  55414. /* export const mediaTypes = {
  55415. image: i18n.t("common.photo"),
  55416. video: i18n.t("common.video"),
  55417. audio: i18n.t("common.voice"),
  55418. } */
  55419. // 媒体扩展类型
  55420. const mediaMimes = {
  55421. image: ["jpg", "png", "jpeg", "bmp", "gif"],
  55422. audio: ["mp3", "aac", "ogg", "wav" /* , "m4a" */],
  55423. video: ["mp4", "mov", "quicktime", "webm" /* "rmvb", "wmv" */], //ios:mov
  55424. };
  55425. // 媒体大小显示(MB)
  55426. const mediaMaxSize = {
  55427. image: 10,
  55428. video: 20,
  55429. audio: 5,
  55430. };
  55431. /**
  55432. * 获取媒体扩展类型
  55433. * @param {Stirng} filename 文件名称
  55434. */
  55435. const getMime = filename => {
  55436. if (!filename || filename.indexOf(".") === -1) {
  55437. return ""
  55438. }
  55439. return filename
  55440. .split(".")
  55441. .pop()
  55442. .toLowerCase()
  55443. };
  55444. /**
  55445. * 在路径中获取文件名
  55446. * @param {*} path
  55447. */
  55448. const getFilename = path => {
  55449. const segment = (path || "").split("/");
  55450. return segment[segment.length - 1]
  55451. };
  55452. /**
  55453. * 检测媒体文件是否超过预设限制
  55454. * @param {String} type 媒体类型
  55455. * @param {Number} size 文件大小
  55456. */
  55457. const checkSizeLimit = (type, size) => {
  55458. size = size / 1024 / 1024;
  55459. return size <= mediaMaxSize[type]
  55460. };
  55461. const checkSizeLimitFree = (size, limit) => {
  55462. size = size / 1024 / 1024;
  55463. return size <= limit
  55464. };
  55465. /**
  55466. * 检测媒体类型
  55467. * @param {String} type 媒体类型
  55468. * @param {String} filename 文件名称
  55469. */
  55470. const checkMediaMime = (type, filename) => {
  55471. const mime = getMime(filename);
  55472. const find = mediaMimes[type];
  55473. if (!find) {
  55474. return false
  55475. }
  55476. return find.indexOf(mime) !== -1
  55477. };
  55478. const checkMediaMimeByAccept = (accept, filename) => {
  55479. let mime = getMime(filename);
  55480. let type = accept;
  55481. if (type && type.indexOf("jpg") == -1 && type.indexOf("jpeg") != -1) {
  55482. type += ",image/jpg";
  55483. }
  55484. return (type || "").indexOf(mime) != -1
  55485. };
  55486. const base64ToBlob = base64 => {
  55487. let arr = base64.split(","),
  55488. mime = arr[0].match(/:(.*?);/)[1],
  55489. bstr = atob(arr[1]),
  55490. n = bstr.length,
  55491. u8arr = new Uint8Array(n);
  55492. while (n--) {
  55493. u8arr[n] = bstr.charCodeAt(n);
  55494. }
  55495. return new Blob([u8arr], { type: mime })
  55496. };
  55497. const base64ToDataURL = base64 => {
  55498. return window.URL.createObjectURL(base64ToBlob(base64))
  55499. };
  55500. const blobToBase64 = function(blob) {
  55501. return new Promise(resolve => {
  55502. var reader = new FileReader();
  55503. reader.onload = function() {
  55504. resolve(reader.result);
  55505. };
  55506. reader.readAsDataURL(blob);
  55507. })
  55508. };
  55509. /*
  55510. * @Author: Rindy
  55511. * @Date: 2019-08-06 16:25:08
  55512. * @LastEditors: Rindy
  55513. * @LastEditTime: 2021-08-27 12:33:49
  55514. * @Description: Request
  55515. */
  55516. //import { $alert, $confirm, $loginTips } from "@/components/shared/message"
  55517. //import { $waiting } from "@/components/shared/loading"
  55518. //import { checkLogin } from "@/api"
  55519. //import { LoginDetector } from "@/core/starter"
  55520. //import { i18n } from "@/lang"
  55521. //import { password } from "@/utils/string"
  55522. //import store from "../Store"
  55523. // 空函数
  55524. const noop = function() {};
  55525. // 请求回调队列
  55526. let postQueue = [];
  55527. /**
  55528. * @property {number} NEXT - 继续执行
  55529. * @property {number} SUCCESS - 成功
  55530. * @property {number} EXCEPTION - 异常错误
  55531. * @property {number} FAILURE_CODE_3001 - 缺少必要参数
  55532. * @property {number} FAILURE_CODE_3002 - 访问异常
  55533. * @property {number} FAILURE_CODE_3003 - 非法访问
  55534. * @property {number} FAILURE_CODE_3004 - 用户未登录
  55535. * @property {number} FAILURE_CODE_3005 - 验证码已过期
  55536. * @property {number} FAILURE_CODE_3006 - 验证码错误
  55537. * @property {number} FAILURE_CODE_3007 - 昵称已存在
  55538. * @property {number} FAILURE_CODE_3008 - 该手机已被注册
  55539. * @property {number} FAILURE_CODE_3009 - 两次输入的密码不一致
  55540. * @property {number} FAILURE_CODE_3010 - 昵称长度错误
  55541. * @property {number} FAILURE_CODE_3011 - 密码长度错误
  55542. * @property {number} FAILURE_CODE_3012 - 昵称包含敏感词
  55543. * @property {number} FAILURE_CODE_3013 - 手机号码格式错误
  55544. * @property {number} FAILURE_CODE_3014 - 账号或密码不正确
  55545. * @property {number} FAILURE_CODE_3015 - 用户不存在
  55546. * @property {number} FAILURE_CODE_3016 - 您没有权限,请联系管理员
  55547. * @property {number} FAILURE_CODE_3017 - 空文件
  55548. * @property {number} FAILURE_CODE_3018 - 需要上传或使用的文件不存在
  55549. * @property {number} FAILURE_CODE_5010 - 找不到该场景对应的相机
  55550. * @property {number} FAILURE_CODE_5012 - 数据不正常
  55551. * @property {number} FAILURE_CODE_5014 - 无权操作该场景
  55552. * @property {number} FAILURE_CODE_5005 - 场景不存在
  55553. */
  55554. const statusCode = {
  55555. NEXT: -999,
  55556. SUCCESS: 0,
  55557. EXCEPTION: -1,
  55558. FAILURE_CODE_3001: 3001,
  55559. FAILURE_CODE_3002: 3002,
  55560. FAILURE_CODE_3003: 3003,
  55561. FAILURE_CODE_3004: 3004,
  55562. FAILURE_CODE_3005: 3005,
  55563. FAILURE_CODE_3006: 3006,
  55564. FAILURE_CODE_3007: 3007,
  55565. FAILURE_CODE_3008: 3008,
  55566. FAILURE_CODE_3009: 3009,
  55567. FAILURE_CODE_3010: 3010,
  55568. FAILURE_CODE_3011: 3011,
  55569. FAILURE_CODE_3012: 3012,
  55570. FAILURE_CODE_3013: 3013,
  55571. FAILURE_CODE_3014: 3014,
  55572. FAILURE_CODE_3015: 3015,
  55573. FAILURE_CODE_3016: 3016,
  55574. FAILURE_CODE_3017: 3017,
  55575. FAILURE_CODE_3018: 3018,
  55576. FAILURE_CODE_5010: 5010,
  55577. FAILURE_CODE_5012: 5012,
  55578. FAILURE_CODE_5014: 5014,
  55579. FAILURE_CODE_5005: 5005,
  55580. };
  55581. /**
  55582. * 获取Token
  55583. * @function
  55584. */
  55585. function getToken() {
  55586. var urlToken = browser.urlHasValue("token", true);
  55587. if (urlToken) {
  55588. // 设置token共享给用户中心
  55589. localStorage.setItem("token", urlToken);
  55590. }
  55591. return urlToken || localStorage.getItem("token") || ""
  55592. }
  55593. /**
  55594. * 根据状态码的结果处理后续操作
  55595. * @function
  55596. * @param {number} code - 状态码
  55597. * @param {function} callback - 回调
  55598. */
  55599. function statusCodesHandler(code, callback) {
  55600. if (code == statusCode.EXCEPTION) {
  55601. return $alert({ content: i18n.t("tips.exception") })
  55602. }
  55603. if (
  55604. code == statusCode.FAILURE_CODE_3002 ||
  55605. code == statusCode.FAILURE_CODE_3003 ||
  55606. code == statusCode.FAILURE_CODE_3004
  55607. ) {
  55608. callback(code);
  55609. return showLoginTips()
  55610. }
  55611. if (code == statusCode.FAILURE_CODE_3001) {
  55612. callback(code);
  55613. return $alert({ content: i18n.t("tips.params_notfound") })
  55614. }
  55615. if (code == statusCode.FAILURE_CODE_3017) {
  55616. callback(code);
  55617. return $alert({ content: i18n.t("tips.file_notfound") })
  55618. }
  55619. if (code == statusCode.FAILURE_CODE_5005) {
  55620. /* if (!config.isEdit) {
  55621. return (location.href = config.pages.NotFound)
  55622. } */
  55623. callback(code);
  55624. return $alert({ content: i18n.t("tips.scene_notfound") })
  55625. }
  55626. if (code == statusCode.FAILURE_CODE_5010) {
  55627. callback(code);
  55628. return $alert({ content: i18n.t("tips.camera_notfound") })
  55629. }
  55630. if (code == statusCode.FAILURE_CODE_5012) {
  55631. callback(code);
  55632. return $alert({ content: i18n.t("tips.data_error") })
  55633. }
  55634. if (code == statusCode.FAILURE_CODE_5014) {
  55635. callback(code);
  55636. return $alert({ content: i18n.t("tips.auth_deny") })
  55637. }
  55638. return statusCode.NEXT
  55639. }
  55640. $.ajaxSetup({
  55641. headers: {},
  55642. beforeSend: function(xhr) {
  55643. const token = getToken();
  55644. if (token) {
  55645. xhr.setRequestHeader("token", token);
  55646. } else if (!token && this.url.indexOf("isLogin") != -1) {
  55647. showLoginTips();
  55648. }
  55649. /* if (config.oem == "localshow") {
  55650. // 本地版本兼容当前目录
  55651. if (this.url.indexOf("http") == -1 && this.url.indexOf("/") == 0) {
  55652. this.url = this.url.substr(1)
  55653. }
  55654. } */
  55655. // if(this.url.indexOf('http')==-1 && this.url.indexOf('/') !=0){
  55656. // this.url = '/'+this.url
  55657. // }
  55658. },
  55659. error: function(xhr, status, error) {
  55660. // 出错时默认的处理函数
  55661. if (this.url.indexOf("/scene.json") != -1 && xhr.status == 404) {
  55662. return $alert({ content: i18n.t("tips.scene_notfound") })
  55663. } else if (this.type === "POST") {
  55664. return $alert({ content: i18n.t("tips.network_error") })
  55665. }
  55666. },
  55667. success: function(result) {},
  55668. complete: function() {
  55669. // Post类型请求无论成功或失败都关闭等待提示
  55670. if (this.type === "POST") {
  55671. http.__loading && $waiting.hide();
  55672. }
  55673. http.__loading = true;
  55674. },
  55675. });
  55676. /**
  55677. * @namespace http
  55678. * @type {Object}
  55679. */
  55680. const http = {
  55681. statusCode,
  55682. __loading: true,
  55683. __request(xhr, method, url, data, done, fail) {
  55684. if (typeof done != "function") {
  55685. done = noop;
  55686. }
  55687. if (typeof fail != "function") {
  55688. fail = noop;
  55689. }
  55690. xhr.done(result => {
  55691. if (typeof result.code !== "undefined") {
  55692. const flag = statusCodesHandler(result.code, function(code) {
  55693. // 需要登录的状态
  55694. if (
  55695. code == statusCode.FAILURE_CODE_3001 ||
  55696. code == statusCode.FAILURE_CODE_3002 ||
  55697. code == statusCode.FAILURE_CODE_3003 ||
  55698. code == statusCode.FAILURE_CODE_3004
  55699. ) {
  55700. if (url.indexOf("isLogin") == -1 && url.indexOf("openSceneBykey") == -1) {
  55701. postQueue.push(function() {
  55702. http[method](url, data, done, fail);
  55703. });
  55704. }
  55705. }
  55706. fail();
  55707. });
  55708. if (flag === statusCode.NEXT) {
  55709. done(result, result.code == 0);
  55710. }
  55711. } else {
  55712. done(result);
  55713. }
  55714. });
  55715. xhr.fail(fail);
  55716. xhr.always(() => (xhr = null));
  55717. return xhr
  55718. },
  55719. /**
  55720. * Get请求
  55721. * @param {String} url 请求地址
  55722. * @param {Object?} data 请求参数
  55723. * @param {Function?} done 成功回调
  55724. * @param {Function?} fail 失败回调
  55725. */
  55726. get(url, data = {}, done, fail) {
  55727. if (/\.json/.test(url)) {
  55728. // json文件格式自动调用getJson方法
  55729. return this.getJson(url, data, done, fail)
  55730. }
  55731. return this.__request($.get(url, data), "get", url, data, done, fail)
  55732. },
  55733. /**
  55734. * Get Blob请求
  55735. * @param {String} url 请求地址
  55736. * @param {Object?} data 请求参数
  55737. * @param {Function?} done 成功回调
  55738. * @param {Function?} fail 失败回调
  55739. */
  55740. getText(url, data = {}, done, fail) {
  55741. return this.__request(
  55742. $.ajax({
  55743. url: url,
  55744. dataType: "text",
  55745. }),
  55746. "getText",
  55747. url,
  55748. data,
  55749. done,
  55750. fail
  55751. )
  55752. },
  55753. /**
  55754. * GetJson请求 读取json文件数据
  55755. * @param {String} url 请求地址
  55756. * @param {Object?} data 请求参数
  55757. * @param {Function?} done 成功回调
  55758. * @param {Function?} fail 失败回调
  55759. */
  55760. getJson(url, data = {}, done, fail) {
  55761. return this.__request($.getJSON(url, data), "get", url, data, done, fail)
  55762. },
  55763. /**
  55764. * Get Blob请求
  55765. * @param {String} url 请求地址
  55766. * @param {Object?} data 请求参数
  55767. * @param {Function?} done 成功回调
  55768. * @param {Function?} fail 失败回调
  55769. */
  55770. getBlob(url, data = {}, done, fail) {
  55771. return this.__request(
  55772. $.ajax({
  55773. url: url,
  55774. dataType: "blob",
  55775. }),
  55776. "getBlob",
  55777. url,
  55778. data,
  55779. done,
  55780. fail
  55781. )
  55782. },
  55783. /**
  55784. * Get Arraybuffer请求
  55785. * @param {String} url 请求地址
  55786. * @param {Object?} data 请求参数
  55787. * @param {Function?} done 成功回调
  55788. * @param {Function?} fail 失败回调
  55789. */
  55790. getArraybuffer(url, data = {}, done, fail) {
  55791. return this.__request(
  55792. $.ajax({
  55793. url: url,
  55794. dataType: "arraybuffer",
  55795. }),
  55796. "getArraybuffer",
  55797. url,
  55798. data,
  55799. done,
  55800. fail
  55801. )
  55802. },
  55803. /**
  55804. * Post 请求
  55805. * @param {String} url 请求地址
  55806. * @param {Object?} data 请求参数
  55807. * @param {Function?} done 成功回调
  55808. * @param {Function?} fail 失败回调
  55809. */
  55810. post(url, data = {}, done, fail) {
  55811. if (url.indexOf("isLogin") == -1) {
  55812. http.__loading && $waiting.show();
  55813. }
  55814. return this.__request($.post(url, data), "post", url, data, done, fail)
  55815. },
  55816. /**
  55817. * PostJson 请求
  55818. * @param {String} url 请求地址
  55819. * @param {Object?} data 请求参数
  55820. * @param {Function?} done 成功回调
  55821. * @param {Function?} fail 失败回调
  55822. */
  55823. postJson(url, data = {}, done, fail) {
  55824. http.__loading && $waiting.show();
  55825. return this.__request(
  55826. $.ajax({
  55827. type: "POST",
  55828. url: url,
  55829. contentType: "application/json",
  55830. data: JSON.stringify(data),
  55831. }),
  55832. "postJson",
  55833. url,
  55834. data,
  55835. done,
  55836. fail
  55837. )
  55838. },
  55839. /**
  55840. * Post 表单 支持文件上传
  55841. * @param {String} url 请求地址
  55842. * @param {FormData?} formData 请求参数
  55843. * @param {Function?} done 成功回调
  55844. * @param {Function?} fail 失败回调
  55845. */
  55846. postForm(url, formData, done, fail, onProgress) {
  55847. if (typeof onProgress === "function") {
  55848. return this.__request(
  55849. $.ajax({
  55850. type: "POST",
  55851. url: url,
  55852. processData: false,
  55853. contentType: false,
  55854. data: formData,
  55855. xhr: function() {
  55856. const xhr = new XMLHttpRequest();
  55857. xhr.upload.addEventListener("progress", function(e) {
  55858. onProgress((e.loaded / e.total) * 100 + "%");
  55859. });
  55860. return xhr
  55861. },
  55862. }),
  55863. "postForm",
  55864. url,
  55865. formData,
  55866. done,
  55867. fail
  55868. )
  55869. } else {
  55870. http.__loading && $waiting.show();
  55871. return this.__request(
  55872. $.ajax({
  55873. type: "POST",
  55874. url: url,
  55875. processData: false,
  55876. contentType: false,
  55877. data: formData,
  55878. }),
  55879. "postForm",
  55880. url,
  55881. formData,
  55882. done,
  55883. fail
  55884. )
  55885. }
  55886. },
  55887. /**
  55888. * 加载图片
  55889. * @param {String} url 请求地址
  55890. * @param {Number?} retry 重试次数,默认为3
  55891. */
  55892. loadImage(url, retry = 3) {
  55893. const def = $.Deferred();
  55894. const img = new Image();
  55895. /* if (process.env.VUE_APP_REGION == "AWS" && url.indexOf("x-oss-process=image") != -1) {
  55896. var arr = url.split("?")
  55897. url = arr[0] + encodeURIComponent("?" + arr[1].replace(/\//g, "@"))
  55898. } */
  55899. const load = () => {
  55900. console.warn("Retrying load image: " + url);
  55901. this.loadImage(url, retry - 1)
  55902. .done(def.resolve.bind(def))
  55903. .progress(def.notify.bind(def))
  55904. .fail(def.reject.bind(def));
  55905. };
  55906. img.onerror = function() {
  55907. retry > 0 ? setTimeout(() => load(), 1e3) : def.reject(`[${url}]加载失败`);
  55908. };
  55909. img.onload = function() {
  55910. def.resolve(img);
  55911. };
  55912. img.crossOrigin = "anonymous";
  55913. img.src = url;
  55914. return def
  55915. },
  55916. /**
  55917. * 上传文件
  55918. * @param {String} url 请求地址
  55919. * @param {Object?} data 请求参数
  55920. * @param {Function?} done 成功回调
  55921. * @param {Function?} fail 失败回调
  55922. */
  55923. uploadFile(url, data = {}, done, fail, onProgress) {
  55924. const form = new FormData();
  55925. // if (file.needTransfer) { //ie和苹果都不支持dataURLtoFile得传送,所以只能用blob
  55926. // form.append("file", common.dataURLtoBlob(file.file), file.name || file.file.name);
  55927. // } else {
  55928. // form.append("file", file.file, file.name || file.file.name);
  55929. // }
  55930. for (let key in data) {
  55931. if (key == "file") {
  55932. form.append("file", data[key], data.filename || data[key].name);
  55933. } else if (key != "filename") {
  55934. form.append(key, data[key]);
  55935. }
  55936. }
  55937. return this.postForm(url, form, done, fail, onProgress)
  55938. },
  55939. /**
  55940. * 上传文件
  55941. * @param {String} url 请求地址
  55942. * @param {Object?} data 请求参数 {file:'base64 string',filename:'image.jpg',...}
  55943. * @param {Function?} done 成功回调
  55944. * @param {Function?} fail 失败回调
  55945. */
  55946. uploadBlobFile(url, data = {}, done, fail) {
  55947. const form = new FormData();
  55948. for (let key in data) {
  55949. if (key === "file") {
  55950. form.append("file", base64ToBlob(data.file), data.filename);
  55951. } else if (key != "filename") {
  55952. form.append(key, data[key]);
  55953. }
  55954. }
  55955. return this.postForm(url, form, done, fail)
  55956. },
  55957. };
  55958. let {TileDownloaderEvents, DownloadStatus: DownloadStatus$1} = Potree.defines;
  55959. window.downloaded = {};
  55960. window.startdownloads = [];
  55961. class TileDownloader extends EventDispatcher{
  55962. constructor( ) {
  55963. super();
  55964. this.panos = null;
  55965. this.retryMinimumTime = 1e4;
  55966. this.panoLoadCallbacks = {};
  55967. this.downloadDescriptors = {};
  55968. this.priorityQueue = [];
  55969. this.forceQueue = [];
  55970. this.activeDownloads = [];
  55971. this.tilePrioritizer = null;
  55972. this.refreshInterval = null;
  55973. this.processPriorityQueue = !1;
  55974. this.concurrentDownloads = 6;//e.concurrentDownloads || 1;
  55975. this.downloadTestResults = {};
  55976. this.freeze = Object.freeze({
  55977. Testing: 1,
  55978. Success: 2,
  55979. Fail: 3
  55980. });
  55981. /* viewer.addEventListener('pageVisible', (e)=>{//不可见时不refreshUpdateInterval
  55982. //console.log('visibilitychange:', state)
  55983. Potree.Utils.updateVisible(this, 'pageVisible', e.v)
  55984. this.judgeStart()
  55985. })
  55986. this.visible = true //add 借用Potree.Utils.updateVisible来判断是否start
  55987. if(Potree.settings.useDepthTex){
  55988. this.judgeStart() //开始下载depthTex
  55989. }else{
  55990. Potree.Utils.updateVisible(this,'showPanos', false ) //默认visible = false
  55991. } */
  55992. }
  55993. setPanoData(e, t /* , i */) {
  55994. this.panos = e,
  55995. this.imagePanos = t;
  55996. // this.panoGroupId = i
  55997. }
  55998. start() {
  55999. this.downloadCubeTex = true;
  56000. /* if(!Potree.settings.useDepthTex){
  56001. Potree.Utils.updateVisible(this,'showPanos', true )
  56002. this.judgeStart()
  56003. }else{
  56004. //this.refreshInterval || this.judgeStart()
  56005. } */
  56006. }
  56007. stop() {
  56008. this.downloadCubeTex = false;
  56009. /* if(!Potree.settings.useDepthTex){
  56010. Potree.Utils.updateVisible(this,'showPanos', false )
  56011. this.judgeStart()
  56012. } */
  56013. }
  56014. /* judgeStart(){//add
  56015. if(this.visible){
  56016. //console.log('judgeStart true')
  56017. this.started = true
  56018. //this.refreshUpdateInterval(0)
  56019. }else{
  56020. //console.log('judgeStart false')
  56021. this.started = false
  56022. //window.clearTimeout(this.refreshInterval)
  56023. }
  56024. } */
  56025. /* refreshUpdateInterval(e) {
  56026. e || (e = 0),
  56027. this.refreshInterval = window.setTimeout(function() {
  56028. var e = this.update();
  56029. e ? this.refreshUpdateInterval(TileDownloader.ACTIVE_REFRESH_DELAY) : this.refreshUpdateInterval(TileDownloader.IDLE_REFRESH_DELAY)
  56030. }
  56031. .bind(this), e)
  56032. } */
  56033. update() {
  56034. if(this.downloadCubeTex){ //可以下载贴图
  56035. var e = this.forceQueue.length > 0;
  56036. this.processQueueForDownloading(this.forceQueue);
  56037. if (this.processPriorityQueue) {
  56038. Potree.Common.intervalTool.isWaiting('processPriorityQueue', ()=>{ //延时update,防止崩溃 , 未到时间就拦截(第一次直接执行)
  56039. this.queuePrioritizedTilesForPanos(this.panos); //这句比较耗时 降四倍时大概1-2毫秒
  56040. }, 66);
  56041. this.priorityQueue.length > 0 && (e = !0);
  56042. this.processQueueForDownloading(this.priorityQueue);
  56043. }
  56044. //return e
  56045. }
  56046. Potree.Common.intervalTool.isWaiting('filterDepthTex', ()=>{
  56047. this.tilePrioritizer.filterDepthTex(this.panos);//下载深度图
  56048. }, 77);
  56049. }
  56050. queuePrioritizedTilesForPanos(e) {
  56051. this.tilePrioritizer && (this.clearQueue(this.priorityQueue),
  56052. this.tilePrioritizer.filterAndPrioritize(this.priorityQueue, e, this),
  56053. this.clearFromQueue(this.priorityQueue, DownloadStatus$1.None, !0), //去除state为DownloadStatus.None的(可能是去除已经在下载的)
  56054. this.setStatusOrRemoveForAllDescriptors(this.priorityQueue, DownloadStatus$1.Queued));
  56055. }
  56056. clearQueue(e) {//停止下载并清空
  56057. this.setStatusForAllDescriptors(e, DownloadStatus$1.None),
  56058. e.length = 0;
  56059. }
  56060. clearForceQueue() {
  56061. this.clearQueue(this.forceQueue);
  56062. }
  56063. clearFromQueue(e, t, i) {
  56064. for (var n = 0; n < e.length; n++) {
  56065. var r = e[n];
  56066. r && (t === r.status && !i || t !== r.status && i) && (e[n] = null);
  56067. }
  56068. }
  56069. setStatusForAllDescriptors(e, t) {
  56070. for (var i = 0; i < e.length; i++) {
  56071. var n = e[i];
  56072. n && (n.status = t);
  56073. }
  56074. }
  56075. setStatusOrRemoveForAllDescriptors(e, t) {
  56076. for (var i = 0; i < e.length; i++) {
  56077. var n = e[i];
  56078. n && (n.status !== t ? n.status = t : e[i] = null);
  56079. }
  56080. }
  56081. getTileDownloadDescriptors(pano, size) {//获取该pano的该size的全部的tile的descriptor
  56082. var i = this.getAllTileDownloadDescriptorsForPano(pano),
  56083. n = i[size];
  56084. return n || (n = this.buildDownloadDescriptorArray(size),//创建的全部是空的
  56085. i[size] = n,
  56086. this.initTileDownloadDescriptors(n, pano, size)),//绑定到该pano size
  56087. n
  56088. }
  56089. getAllTileDownloadDescriptorsForPano(pano) {//新建空Descriptors
  56090. var t = this.downloadDescriptors[pano.id];
  56091. return t || (t = {},
  56092. this.downloadDescriptors[pano.id] = t),
  56093. t
  56094. }
  56095. processQueueForDownloading(e, t) {//执行下载任务
  56096. this.cleanupActiveDownloads();
  56097. if(e.length){
  56098. let concurrentDownloads = Potree.Common.getBestCount('concurrentDownloads',1,6, 1.8, 14/* ,true */); //flying ? (isMobile ? 2 : 3) : 6
  56099. if (this.activeDownloads.length < concurrentDownloads || t) {
  56100. var i = t ? e.length : concurrentDownloads - this.activeDownloads.length;
  56101. for (var n = 0, r = 0; n < i && e.length > 0; r++) {
  56102. var o = e.shift();
  56103. if(o){
  56104. //add 为了防止1024的在512前下载完,这里强行等待512下载完毕再开始下载
  56105. if(o.panoSize > 512 && !this.isPanoDownloaded(o.pano, 512) ){
  56106. //console.log('512的还没下载好呢!')
  56107. e.push(o);
  56108. break;//一般512的都是连续下载的,所以后面就都不是512了直接中断
  56109. }
  56110. this.startDownload(o);
  56111. n++;
  56112. }
  56113. }
  56114. }
  56115. }
  56116. }
  56117. testDownload(panoSize, tileSize, callback) {
  56118. var n = this.downloadTestResults[panoSize];
  56119. if (n)
  56120. return void(n === this.freeze.Success ? callback(!0) : n === this.freeze.Fail && callback(!1));
  56121. this.downloadTestResults[panoSize] = this.freeze.Testing;
  56122. var r = this.panos[0],
  56123. o = this.getTileUrl({pano:r, panoSize, tileSize, tileIndex:0} /* r.id, panoSize, tileSize, 0 */),
  56124. a = function(t) {
  56125. this.downloadTestResults[panoSize] = this.freeze.Success,
  56126. callback(!0);
  56127. }
  56128. .bind(this),
  56129. s = function() {
  56130. this.downloadTestResults[panoSize] = this.freeze.Fail,
  56131. callback(!1);
  56132. }
  56133. .bind(this);
  56134. this.loadImage(o, 0, a, s);
  56135. }
  56136. startDownload(e) {//开始下载啦
  56137. //console.log('startDownload')
  56138. startdownloads.push(e);
  56139. e.local2SrcFailed = this.local2SrcFailed;
  56140. e.status = DownloadStatus$1.Downloading;
  56141. var t = this.getTileUrl(e/* e.pano.id, e.panoSize, e.tileSize, e.tileIndex, e.pano.alignmentType */);//xzw add alignmentType
  56142. if(!t)return;
  56143. this.activeDownloads.push(e);
  56144. this.loadImage(t, TileDownloader.DOWNLOAD_RETRIES, this.downloadComplete.bind(this, e), this.downloadFailed.bind(this, e));
  56145. }
  56146. downloadFailed(e, t) {
  56147. //add
  56148. if(Potree.settings.isLocal2 && !e.local2SrcFailed){//为了兼容旧的数据src,如果新src没加载成功,就加载旧的
  56149. e.local2SrcFailed = this.local2SrcFailed = true;
  56150. //this.startDownload(e)//重新下载
  56151. var t = this.getTileUrl(e);
  56152. this.loadImage(t, TileDownloader.DOWNLOAD_RETRIES, this.downloadComplete.bind(this, e), this.downloadFailed.bind(this, e));
  56153. }
  56154. }
  56155. downloadComplete(e, t) {//下载成功时
  56156. //if (e.panoGroupId === this.panoGroupId) {
  56157. var i = this.getPanoLoadCallbacks(e.pano, e.panoSize);
  56158. e.status = DownloadStatus$1.Downloaded,
  56159. i && i.onProgress && i.onProgress(e.pano, e.panoSize);
  56160. var n = {
  56161. panoId: e.pano.id,
  56162. image: t,
  56163. tileSize: e.tileSize,
  56164. panoSize: e.panoSize,
  56165. tileIndex: e.tileIndex,
  56166. faceTileIndex: e.faceTileIndex,
  56167. totalTiles: e.totalTiles,
  56168. face: e.face,
  56169. tileX: e.tileX,
  56170. tileY: e.tileY,
  56171. direction: e.direction
  56172. };
  56173. downloaded[e.pano.id] || (downloaded[e.pano.id]={512:[],1024:[],2048:[]});
  56174. downloaded[e.pano.id][e.panoSize] || (downloaded[e.pano.id][e.panoSize] = []);
  56175. downloaded[e.pano.id][e.panoSize].push(e);
  56176. if(e.panoSize != 512 && downloaded[e.pano.id][512].length<6){
  56177. console.warn('没下完');
  56178. }
  56179. e.image = t,
  56180. this.dispatchEvent({type:TileDownloaderEvents.TileDownloadSuccess, desc:n} );
  56181. this.isPanoDownloaded(e.pano, e.panoSize) && (n = {
  56182. panoId: e.pano.id,
  56183. tileSize: e.tileSize,
  56184. panoSize: e.panoSize
  56185. },
  56186. this.dispatchEvent({type:TileDownloaderEvents.PanoDownloadComplete, desc:n}),
  56187. i && i.onLoad && i.onLoad(e.pano, e.panoSize));
  56188. //}
  56189. }
  56190. isPanoDownloaded(e, t) {
  56191. var i = this.getTileDownloadDescriptors(e, t);
  56192. if (i.length <= 0)
  56193. return !1;
  56194. for (var n = 0; n < i.length; n++) {
  56195. var r = i[n];
  56196. if (r.status !== DownloadStatus$1.Downloaded)
  56197. return !1
  56198. }
  56199. return !0
  56200. }
  56201. setPanoLoadCallbacks(e, t, i, n, r) {
  56202. var o = e.id + ":" + this.qualityManager.getPanoSize(t);
  56203. this.panoLoadCallbacks[o] = {
  56204. onLoad: i,
  56205. onFail: n,
  56206. onProgress: r
  56207. };
  56208. }
  56209. getPanoLoadCallbacks(e, t) {
  56210. var i = e.id + ":" + t;
  56211. return this.panoLoadCallbacks[i]
  56212. }
  56213. buildDownloadDescriptorArray(e) {
  56214. for (var t = TileUtils.getTileCountForSize(e), i = [], n = 0; n < t; n++) {
  56215. var r = this.buildDownloadDescriptor();
  56216. i.push(r);
  56217. }
  56218. return i
  56219. }
  56220. buildDownloadDescriptor() {//Descriptor!
  56221. var e = {
  56222. panoGroupId: null,
  56223. pano: null,
  56224. panoSize: -1,
  56225. tileSize: -1,
  56226. tileIndex: -1,
  56227. totalTiles: -1,
  56228. faceTileIndex: -1,
  56229. status: DownloadStatus$1.None,
  56230. url: null,
  56231. image: null,
  56232. direction: new Vector3, //该tile在cube中的方向
  56233. face: -1,
  56234. cubeFace: -1,
  56235. tileX: -1,
  56236. tileY: -1
  56237. };
  56238. return e
  56239. }
  56240. initTileDownloadDescriptors(e, t, i) {
  56241. for (var n = 0; n < e.length; n++) {
  56242. var r = e[n];
  56243. this.initTileDownloadDescriptor(r, t, i, n);
  56244. }
  56245. }
  56246. initTileDownloadDescriptor(desc, pano, size, index) {
  56247. var r = size >= TileUtils.TILE_SIZE ? TileUtils.TILE_SIZE : size;
  56248. desc.face = TileUtils.getFaceForTile(size, index);//根据顺序得到的face的index
  56249. desc.cubeFace = TileUtils.mapFaceToCubemapFace(desc.face);//为了贴图而转化的face index
  56250. //desc.panoGroupId = this.panoGroupId;//就是场景号
  56251. desc.pano = pano;
  56252. desc.panoSize = size;
  56253. desc.tileSize = r; //瓦片图size 512
  56254. desc.tileIndex = index;
  56255. desc.totalTiles = TileUtils.getTileCountForSize(size);
  56256. desc.status = DownloadStatus$1.None;
  56257. desc.image = null;
  56258. TileUtils.getTileLocation(desc.panoSize, desc.tileIndex, desc);//得到该tile在这个face中的具体位置(tileX等)
  56259. TileUtils.getTileVector(desc.panoSize, desc.tileSize, desc.cubeFace, desc.tileX, desc.tileY, TileUtils.LocationOnTile.Center, 0, desc.direction);
  56260. }
  56261. getTiles(d, sceneNum, useV4url, pointcloud){
  56262. let v3OrV4Str = useV4url ? `/scene_view_data/${sceneNum}/images/` : `/images/images${sceneNum}/`;
  56263. if(Potree.settings.isLocal && !this.local2SrcFailed && pointcloud.datasetData.mapping && !Potree.settings.isLocal2){ //非离线包的话加mapping
  56264. return `${Potree.settings.urls.prefix3}/${pointcloud.datasetData.mapping}${v3OrV4Str}${d}`
  56265. }
  56266. return `${Potree.settings.urls.prefix3}${v3OrV4Str}${d}`
  56267. /*
  56268. if(Potree.settings.isLocal && !this.local2SrcFailed || useV4url){//新的地址 scene_view_data/场景码/images/tiles
  56269. if(pointcloud.datasetData.mapping && !Potree.settings.isLocal2){//非离线包的话加mapping
  56270. return `${Potree.settings.urls.prefix3}/${pointcloud.datasetData.mapping}/scene_view_data/${sceneNum}/images/${d}`
  56271. }else{
  56272. return `${Potree.settings.urls.prefix3}/scene_view_data/${sceneNum}/images/${d}`
  56273. }
  56274. }
  56275. return `${Potree.settings.urls.prefix3}/images/images${sceneNum}/${d}`
  56276. */
  56277. }
  56278. loadImage(e, t, i, n) {
  56279. //自己修改了ajax,把getImage改成了loadImg
  56280. http.loadImage(e, t).then(function(e) {
  56281. i(e);
  56282. }).fail(n);
  56283. }
  56284. }
  56285. TileDownloader.prototype.forceQueueTilesForPano = function() {//根据条件开始加载tile
  56286. var e = [],
  56287. t = [];
  56288. return function(pano, size, dir, hFov, vFov, download) {
  56289. e.length = 0;
  56290. for (var u = this.getTileDownloadDescriptors(pano, size), d = 0; d < u.length; d++) {
  56291. var p = u[d];
  56292. p.status !== DownloadStatus$1.None && p.status !== DownloadStatus$1.Queued || e.push(p);
  56293. }
  56294. if (dir && e.length > 0) {
  56295. TilePrioritizer.sortPanoTiles(e, pano, dir); //按最佳方向排序e
  56296. t.length = 0;
  56297. TileUtils.matchingTilesInDirection(pano, size, dir, hFov, vFov, t);//得到在符合视野标准的集合t
  56298. for (var f = 0, g = function(e) {
  56299. return e.face === m.face && e.faceTileIndex === m.faceTileIndex
  56300. }; f < e.length;) { //过滤掉不符合角度要求的
  56301. var m = e[f],
  56302. v = t.findIndex(g);
  56303. v < 0 ? e.splice(f, 1) : f++;
  56304. }
  56305. }
  56306. for (var A = 0; A < e.length; A++){
  56307. this.forceQueue.push(e[A]); //装载
  56308. }
  56309. /* if(e.length){
  56310. console.log(e)
  56311. } */
  56312. this.setStatusForAllDescriptors(this.forceQueue, DownloadStatus$1.ForceQueued);
  56313. this.clearFromQueue(this.priorityQueue, DownloadStatus$1.ForceQueued, !1);
  56314. download && this.processQueueForDownloading(this.forceQueue, !0);
  56315. }
  56316. }();
  56317. TileDownloader.prototype.cleanupActiveDownloads = function() {
  56318. var e = [];
  56319. return function() {
  56320. e.length = 0;
  56321. for (var t = 0; t < this.activeDownloads.length; t++) {
  56322. var i = this.activeDownloads[t];
  56323. i.status !== DownloadStatus$1.Downloaded && i.status !== DownloadStatus$1.Failed && e.push(i);
  56324. }
  56325. this.activeDownloads.length = 0,
  56326. this.activeDownloads.push.apply(this.activeDownloads, e);
  56327. }
  56328. }();
  56329. TileDownloader.prototype.getTileUrl = function() {
  56330. var e = {
  56331. 256: "256",
  56332. 512: "512",
  56333. 1024: "1k",
  56334. 2048: "2k",
  56335. 4096: "4k"
  56336. },
  56337. t = {
  56338. face: -1,
  56339. faceTileIndex: -1,
  56340. tileX: -1,
  56341. tileY: -1
  56342. };
  56343. return function(o={} ) {
  56344. var id = o.pano.originID, ////////
  56345. panoSize = o.panoSize,
  56346. tileSize = o.tileSize,
  56347. tileIndex = o.tileIndex,
  56348. sceneCode = o.pano.pointcloud.sceneCode,
  56349. useV4url = Potree.settings.useV4url && o.pano.pointcloud.datasetData.sceneVersion == 'V4'; //v4的全景图等路径不一样
  56350. var metadata = {sceneScheme:10};
  56351. TileUtils.getTileLocation(panoSize, tileIndex, t);
  56352. var s = Math.floor(panoSize / tileSize),
  56353. l = s * s,
  56354. h = Math.floor(tileIndex / l),
  56355. u = "",
  56356. d = '', g = '';
  56357. if(Potree.settings.tileOriginUrl){//原始规则
  56358. //1 === config.tiling.customCompression && (u = "_" + config.tiling["q" + e[panoSize]]);
  56359. //1 === o.tiling.customCompression && (u = "_" + o.tiling["q" + e[n]]);
  56360. d = "tiles/" + id + "/" + e[panoSize] + u + "_face" + h + "_" + t.tileX + "_" + t.tileY + ".jpg";
  56361. d = this.getTiles(d, sceneCode, useV4url, o.pano.pointcloud);
  56362. g = "?";
  56363. }else {//阿里云oss的规则 if (metadata.sceneScheme == 10)
  56364. d = 'tiles/4k/' + id + '_skybox' + h + '.jpg?x-oss-process=';
  56365. if (e[panoSize] == '512') {
  56366. d += 'image/resize,h_512';
  56367. } else {
  56368. //4k的图,移动端是1k,pc端是2k,放大才是4k
  56369. if (e[panoSize] == '1k' || e[panoSize] == '2k') { //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
  56370. d += 'image/resize,m_lfit,w_' + panoSize + '/crop,w_512,h_512,';
  56371. } else {
  56372. d = 'tiles/4k/' + id + '_skybox' + h + '.jpg?x-oss-process=image/crop,w_512,h_512,';
  56373. }
  56374. //起始位置
  56375. if (t.tileX == 0) {
  56376. d += 'x_0,';
  56377. } else {
  56378. d += 'x_' + (512 * t.tileX /* - 1 */) + ',';
  56379. }
  56380. if (t.tileY == 0) {
  56381. d += 'y_0';
  56382. } else {
  56383. d += 'y_' + (512 * t.tileY /* - 1 */);
  56384. }
  56385. }
  56386. d = this.getTiles(d, sceneCode, useV4url, o.pano.pointcloud);
  56387. g = "&";
  56388. }
  56389. //Potree.settings.panoVersion = 4
  56390. d += g + (Potree.settings.panoVersion ? 'version='+Potree.settings.panoVersion : 'time='+o.pano.pointcloud.timeStamp ); //加后缀
  56391. return d;
  56392. /* 4dkk
  56393. getViewImagesURL(url) {
  56394. if (url.indexOf('&_=') !== -1) {
  56395. return url
  56396. }
  56397. let version = url.indexOf('/panorama/') !== -1 ? this.linkVersion : this.imageVersion
  56398. if (url.indexOf('?') !== -1) {
  56399. return this.$app.config.resource + `scene_view_data/${this.num}/images/${url}&_=${version}`
  56400. }
  56401. return this.$app.config.resource + `scene_view_data/${this.num}/images/${url}?_=${version}`
  56402. }
  56403. /**
  56404. */
  56405. }
  56406. }();
  56407. TileDownloader.tilegen = true;
  56408. TileDownloader.IDLE_REFRESH_DELAY = 500;
  56409. TileDownloader.ACTIVE_REFRESH_DELAY = 16;
  56410. TileDownloader.DOWNLOAD_RETRIES = 4;
  56411. function Node$1(e, t) {
  56412. this.tree = e, //所属树(TileTree)
  56413. this.parent = t,
  56414. this.children = [],
  56415. this.id = ++u$1;
  56416. }
  56417. function o(e, t, i, r, a, s, l, h) {
  56418. if (e) {
  56419. l = l || TileTree.TraversalType.PreOrder;
  56420. var u = r * c + i;
  56421. if (l === TileTree.TraversalType.PreOrder && (a && a(e, t, u, i, r),
  56422. s && s.push(e)),
  56423. e.children && 0 !== e.children.length) {
  56424. for (var d = r * c, p = i * c, f = 0; f < c; f++)
  56425. for (var g = 0; g < c; g++)
  56426. o(e.children[g * c + f], t + 1, p + f, d + g, a, s, l, h);
  56427. l === TileTree.TraversalType.PostOrder && (a && a(e, t, u, i, r),
  56428. s && s.push(e));
  56429. }
  56430. }
  56431. }
  56432. function Plant(seed) {
  56433. seed.root = Branch(seed, null, 0);
  56434. }
  56435. function Branch(seed, parent, level) {
  56436. if (level > seed.levels)
  56437. return null;
  56438. var node = new Node$1(seed, parent);
  56439. seed.allNodes.push(node);
  56440. for (var o = 0; o < h$1; o++)
  56441. node.children[o] = Branch(seed, node, level + 1);
  56442. return node
  56443. }
  56444. function l(parent, t, level, n, r) {
  56445. if (!parent)
  56446. return null;
  56447. if (0 === level)
  56448. return parent;
  56449. if (!parent.children || 0 === parent.children.length)
  56450. return null;
  56451. var o = Math.pow(c, level),
  56452. a = o / c,
  56453. s = n % a,
  56454. h = r % a,
  56455. u = Math.floor(r / a),
  56456. d = Math.floor(n / a),
  56457. p = u * c + d,
  56458. f = parent.children[p];
  56459. return l(f, t + 1, level - 1, s, h)
  56460. }
  56461. /* cube每个面都有一个分层树 用于代表瓦片图的细分?
  56462. 树4096的分为三层,每层有4个子节点。(最后一层的四个子节点都是null)
  56463. */
  56464. var c = 2,
  56465. h$1 = c * c; //4个子节点
  56466. var u$1 = 0;
  56467. class TileTree {
  56468. constructor(e, t) {
  56469. this.levels = t,
  56470. this.tileSize = e,
  56471. this.root = null,
  56472. this.allNodes = [],
  56473. Plant(this);
  56474. }
  56475. getSubNode(e, t, i) {
  56476. (!t || e < this.tileSize) && (t = 0),
  56477. (!i || e < this.tileSize) && (i = 0),
  56478. e < this.tileSize && (e = this.tileSize);
  56479. var level = TileTree.getLevelCountForSize(this.tileSize, e),
  56480. o = l(this.root, 0, level, t, i);
  56481. return o
  56482. }
  56483. breadthFirst(e) {//广度优先搜索
  56484. e = e || {};
  56485. var t = !!e.nullLevelEnd,
  56486. i = e.maxLevel,
  56487. n = e.minLevel,
  56488. r = e.callback,
  56489. o = e.saveVisited,
  56490. a = [],
  56491. s = {},
  56492. l = 0,
  56493. c = 0;
  56494. for (a.push(this.root),
  56495. a.push(s); a.length > 0 && !(i && l > i);) {
  56496. var h = a.shift();
  56497. if (h === s)
  56498. (!n || l >= n) && (r && t && r(null),
  56499. o && t && o.push(null)),
  56500. a.length > 0 && a.push(s),
  56501. l++,
  56502. c = 0;
  56503. else {
  56504. if (h.children)
  56505. for (var u = 0; u < h.children.length; u++) {
  56506. var d = h.children[u];
  56507. d && a.push(h.children[u]);
  56508. }
  56509. var p = this.getFaceIndexFromNode(h);
  56510. (!n || l >= n) && (r && r(h, l, p),
  56511. o && o.push(h)),
  56512. c++;
  56513. }
  56514. }
  56515. }
  56516. getFaceIndexFromNode(e) {
  56517. if (!e)
  56518. return -1;
  56519. for (var t = 1, i = e, n = 0, r = 0;;) {
  56520. var o = i.parent;
  56521. if (!o)
  56522. break;
  56523. for (var a = -1, s = 0; s < o.children.length; s++)
  56524. o.children[s] === i && (a = s);
  56525. var l = a % c,
  56526. h = Math.floor(a / c);
  56527. n = l * t + n,
  56528. r = h * t + r,
  56529. t *= c,
  56530. i = o;
  56531. }
  56532. return r * t + n
  56533. }
  56534. depthFirst(e, t, i) {
  56535. o(this.root, 0, 0, 0, e, t, i, this.tileSize);
  56536. }
  56537. }
  56538. TileTree.TraversalType = Object.freeze({
  56539. PreOrder: 0,
  56540. PostOrder: 1
  56541. });
  56542. TileTree.getLevelCountForSize = function(tileSize, size) {//512->0 2024->1
  56543. var i = 0;
  56544. for (size < tileSize && (size = tileSize);;) {
  56545. if (size /= c,
  56546. size < tileSize)
  56547. break;
  56548. i++;
  56549. }
  56550. return i
  56551. };
  56552. TileTree.getSizeForLevel = function(e, t) {
  56553. return Math.pow(c, t) * e
  56554. };
  56555. /* let sid = 0
  56556. let getName = ()=>{
  56557. return sid ++
  56558. } */
  56559. class BasicMaterial extends ShaderMaterial{
  56560. constructor(o={}){
  56561. super( Object.assign({},{
  56562. uniforms:{
  56563. color: {type:'v3', value: o.color || new Color("#FFF")} ,
  56564. map: {type: 't', value: o.map },
  56565. opacity : {type:'f', value : o.opacity == void 0 ? 1 : o.opacity }
  56566. },
  56567. vertexShader: Shaders['basicTextured.vs'],
  56568. fragmentShader: Shaders['basicTextured.fs'],
  56569. defines:{HasColor:'' }
  56570. },o));
  56571. //this.name111 = getName()
  56572. }
  56573. copy(source){
  56574. super.copy(source);
  56575. //console.log('copy', source.name111, this.name111, !!source.map )
  56576. this.map = source.map;
  56577. return this
  56578. }
  56579. set opacity(o){
  56580. this.uniforms && (this.uniforms.opacity.value = o);
  56581. }
  56582. get opacity(){
  56583. return this.uniforms.opacity.value
  56584. }
  56585. set map(o){
  56586. this.uniforms.map.value = o;
  56587. if(o){
  56588. this.defines.HasMap = '';
  56589. }else {
  56590. delete this.defines.HasMap;
  56591. }
  56592. //可能需要needsUpdate
  56593. //console.log('hasMap', !!o, this.name111 )
  56594. }
  56595. get map(){
  56596. return this.uniforms.map.value
  56597. }
  56598. }
  56599. let {PanoSizeClass: PanoSizeClass$2, PanoRendererEvents: PanoRendererEvents$1 , Vectors,SceneRendererEvents,TileDownloaderEvents: TileDownloaderEvents$1, GLCubeFaces: GLCubeFaces$2} = Potree.defines;
  56600. function createDescriptor() {
  56601. var e = {
  56602. renderTarget: null,
  56603. inUse: !1,
  56604. size: -1,
  56605. pano: null
  56606. };
  56607. return e
  56608. }
  56609. /* function upload() {
  56610. if (!this.uploadIntervalCancelled) {
  56611. if (this.overlayTilesLoaded || !this.usingTileOverlay) {
  56612. b = !0
  56613. let maxNonBaseUploadsPerFrame = viewer.mainViewport.view.isFlying() ? 1 : this.maxNonBaseUploadsPerFrame //原先2。这是每帧uploadTile非512的瓦片tex的数量。之前的2太卡了,降为1。(检测卡顿方法:在一个pano点旋转至所有2048的tile都加载完,然后之后到这个点看看卡不卡。因为该点tiles都下载完了所以会在飞过来时陆续都加载,所以容易卡)
  56614. this.updateUploadQueue(maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame)
  56615. let time = viewer.mainViewport.view.isFlying() ? 60 : w //add 飞行有时候会卡,增长间隔
  56616. this.peekNextFromUploadQueue() ? this.refreshUploadInterval(time) : this.uploadInterval = null //定时下一次更新
  56617. } else {
  56618. this.refreshUploadInterval(this.uploadIntervalDelay)
  56619. }
  56620. }
  56621. } */
  56622. var b = !1,
  56623. w = config$1.tiling.uploadIntervalDelay,
  56624. _ = config$1.tiling.initialIntervalDelay,
  56625. T = config$1.tiling.maxNonBaseUploadsPerFrame,//2 size>512的每次只upload这么多个
  56626. x$1 = config$1.tiling.maxBaseUploadsPerFrame,//6
  56627. S = {
  56628. Base: 0,
  56629. Remaining: 1
  56630. };/* ,
  56631. M = []; */
  56632. class PanoRenderer extends EventDispatcher{
  56633. constructor(viewer, tileDownloader, qualityManager) {
  56634. super();
  56635. this.tileDirectory = {};
  56636. this.activeRenderTargetDescriptors = {};
  56637. this.activePanos = [];
  56638. this.panoLODDescriptors = {};
  56639. this.panoDescriptors = {};
  56640. this.tileTrees = {};
  56641. this.forceQueue = [];
  56642. this.uploadQueues = {};
  56643. this.uploadInterval = null;
  56644. this.uploadIntervalCancelled = true;//!1;
  56645. this.usingTileOverlay = !1;
  56646. this.overlayTilesLoaded = !1;
  56647. this.overlayTileBase = null;
  56648. this.overlayTilesBasic = {};
  56649. this.overlayTilesEnhanced = {};
  56650. this.zoomRenderTarget = null; //用于缩放的rendertarget
  56651. this.zoomPano = null;
  56652. this.zoomingActive = !1;
  56653. this.zoomPanoId = null;
  56654. this.zoomPanoRenderingDisabled = !1;
  56655. this.direction = [];//new THREE.Vector3;
  56656. this.maxBaseUploadsPerFrame = x$1;
  56657. this.maxNonBaseUploadsPerFrame = T;
  56658. this.M = [];//move M to here 似乎列表里会有两个
  56659. this.viewer = viewer;
  56660. this.tileDownloader = tileDownloader;
  56661. this.qualityManager = qualityManager;
  56662. this.initTime = performance.now();
  56663. this.bindEvents();
  56664. }
  56665. getActivePanoTextures(e) {
  56666. e = e || [];
  56667. for (var t = 0; t < M.length; t++) {
  56668. var i = M[t];
  56669. i.renderTarget && i.renderTarget.texture && e.push(i.renderTarget.texture);
  56670. }
  56671. }
  56672. hasQueuedTiles() {
  56673. var e = this.peekNextFromUploadQueue();
  56674. return null !== e && void 0 !== e
  56675. }
  56676. getActiveRenderTargetDescriptor(e) {
  56677. return this.activeRenderTargetDescriptors[e]
  56678. }
  56679. setActiveRenderTargetDescriptor(e, t) {
  56680. this.activeRenderTargetDescriptors[e] = t;
  56681. }
  56682. bindEvents() {
  56683. this.tileDownloader.addEventListener(TileDownloaderEvents$1.TileDownloadSuccess, this.onTileDownloaded.bind(this));
  56684. }
  56685. enableUltraHighQualityMode(e) {
  56686. if(config$1.tileClass == "2k"||config$1.tileClass == "1k")return this.enableHighQuality(e)//xzw add 濡傛灉鏈€澶氬彧瑕?k鐨勮瘽
  56687. if (!this.qualityManager.ultraHighQualityModeEnabled()) {
  56688. var t = this.qualityManager.getPanoSize(PanoSizeClass$2.ULTRAHIGH);
  56689. this.tileDownloader.testDownload(t, TileUtils.TILE_SIZE, function (t) {
  56690. t && (this.qualityManager.enableUltraHighQualityMode(),
  56691. this.setupZoomRenderTarget(),
  56692. e());
  56693. }
  56694. .bind(this));
  56695. }
  56696. }
  56697. activateTiledPano(pano, size, i) {
  56698. i && this.clearAllQueuedUploads();
  56699. for (var n = 0; n < TileUtils.FACES_PER_PANO; n++)
  56700. this.initTileTree(pano.id, n, this.qualityManager.getMaxPossiblePanoSize()); //得到this.tileTrees[pano.id],arr[6]
  56701. this.linkAllTilesAndNodes(pano);
  56702. var r = this.getActiveRenderTargetDescriptor(pano.id),
  56703. l = size;
  56704. l > this.qualityManager.getMaxNavPanoSize() && (l = this.qualityManager.getMaxNavPanoSize());
  56705. if ( !r || l !== r.size) {
  56706. r && this.deactiveDescripor(r.renderTarget);
  56707. r = this.activeDescripor(l);
  56708. if (!r) {
  56709. var ren = this.initTiledPano(l, Potree.settings.disableAATarget ? false : !browser.isMobile() ); //有的老设备如果抗锯齿打开场景时要多花五秒
  56710. r = this.initDescriptor(ren.width);
  56711. r.renderTarget = ren;
  56712. }
  56713. r.pano = pano;
  56714. this.resetPanoDescriptor(pano.id);
  56715. this.resetPanoLODDescriptors(pano.id);
  56716. this.resetRenderStatus(pano.id, !0, !0);
  56717. }
  56718. this.setActiveRenderTargetDescriptor(pano.id, r);
  56719. var h = i ? 0 : 1;
  56720. this.updateActivePanos(pano, h);
  56721. //console.log(`index:${this.viewer.index} ${r.renderTarget.texture.id} ${pano.id}`)
  56722. return r.renderTarget
  56723. }
  56724. deactivateTiledPano(pano) {
  56725. var t = this.getActiveRenderTargetDescriptor(pano.id);
  56726. if(this.isRenderTargetDescriptorValid(t)){
  56727. this.deactiveDescripor(t.renderTarget);
  56728. this.setActiveRenderTargetDescriptor(pano.id, null);
  56729. }
  56730. var i = this.getUploadQueueForPano(pano.id);
  56731. this.clearUploadQueue(i);
  56732. this.updateActivePanos();
  56733. viewer.cancelLoad(pano);//add
  56734. }
  56735. getActivePanoCount() {
  56736. return this.activePanos.length
  56737. }
  56738. resetRenderStatus(e, t, i, n) {
  56739. var r = null;
  56740. n && (r = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, n) + 1);
  56741. for (var o = function (e, n, r, o) {
  56742. i && (n.tile.zoomUploaded = !1),
  56743. t && (n.tile.uploaded = !1);
  56744. }, a = 0; a < TileUtils.FACES_PER_PANO; a++) {
  56745. var s = this.getTileTree(e, a);
  56746. s.breadthFirst({
  56747. callback: o.bind(this, a),
  56748. minLevel: r
  56749. });
  56750. }
  56751. }
  56752. copyBaseRenderStatusToZoomed(e) {
  56753. for (var t = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, this.qualityManager.getMaxNavPanoSize()), i = function (e, t, i, n) {
  56754. t.tile.zoomUploaded = t.tile.uploaded,
  56755. t.zoomCovered = t.covered;
  56756. }, n = 0; n < TileUtils.FACES_PER_PANO; n++) {
  56757. var r = this.getTileTree(e, n);
  56758. r.breadthFirst({
  56759. callback: i.bind(this, n),
  56760. maxLevel: t
  56761. });
  56762. }
  56763. }
  56764. isRenderTargetDescriptorValid(e) {
  56765. return e && e.renderTarget
  56766. }
  56767. isPanoActive(e) {
  56768. var t = this.getActiveRenderTargetDescriptor(e);
  56769. return this.isRenderTargetDescriptorValid(t)
  56770. }
  56771. isPanoZoomed(e) {
  56772. return this.zoomingActive && this.zoomPanoId === e
  56773. }
  56774. initTileTree(e, t, i) {
  56775. var n = this.tileTrees[e];
  56776. n || (n = [],
  56777. this.tileTrees[e] = n);
  56778. var r = n[t];
  56779. if (!r) {
  56780. var o = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, i);
  56781. r = new TileTree(TileUtils.TILE_SIZE, o),
  56782. n[t] = r;
  56783. }
  56784. }
  56785. getTileTree(e, t) {
  56786. var i = this.tileTrees[e];
  56787. if (!i)
  56788. console.error("PanoRenderer.getTileTree() -> Tree array not yet initialized!");
  56789. var n = i[t];
  56790. if (!n)
  56791. console.error("PanoRenderer.getTileTree() -> Tree not yet initialized!");
  56792. return n
  56793. }
  56794. /*
  56795. * 创建tile的renderTarget, 包括pano.tiledPanoRenderTarget和zoomRenderTarget
  56796. * @param {number} size 当前的panoSize,每个面的分辨率
  56797. */
  56798. initTiledPano(size, ifNormalFilter) {//创建 RenderTargetCube
  56799. var renderer = this.viewer.renderer;
  56800. var renderTarget, texture;
  56801. renderTarget = new WebGLCubeRenderTarget(size,{ //THREE.WebGLRenderTargetCube(size, size, {
  56802. stencilBuffer: !1
  56803. });
  56804. texture = new CubeTexture([]);
  56805. texture.image = [null, null, null, null, null, null];
  56806. texture.flipY = !0,
  56807. texture.format = RGBAFormat;
  56808. ifNormalFilter ? (texture.generateMipmaps = !0,
  56809. texture.magFilter = LinearFilter,
  56810. texture.minFilter = LinearMipMapLinearFilter)
  56811. : (texture.generateMipmaps = !1,
  56812. texture.magFilter = LinearFilter, //LinearFilter更清晰,但锯齿噪点严重,相当于锐化,其实失真了。对于条纹状的画面移动镜头时锯齿明显 眩晕
  56813. texture.minFilter = LinearFilter);
  56814. //平时还是直接用LinearMipMapLinearFilter,其实并非不清晰,只是没有加锐化,像加了层柔光和抗锯齿,观感更好。放大后使用LinearFilter
  56815. // 如果抗锯齿的话,采用mipmap,会增加一倍的存储消耗。原版本都是不抗锯齿的。但是抗锯齿效果更柔和
  56816. renderTarget.texture = texture; //居然漏了一句,2022.10.9补
  56817. renderer.setRenderTarget(renderTarget);
  56818. renderer.setRenderTarget(null);
  56819. var o = renderer.properties.get(texture);
  56820. o.__image__webglTextureCube = o.__webglTexture;
  56821. //window.tex[r.id] = {texture:r, index:this.viewer.index }
  56822. return renderTarget
  56823. }
  56824. getUploadQueueForPano(e) {
  56825. var t = this.uploadQueues[e];
  56826. return t || (t = [],
  56827. this.uploadQueues[e] = t),
  56828. t
  56829. }
  56830. isTileUploaded(e) {
  56831. return this.isPanoZoomed(e.panoId) ? e.zoomUploaded : e.uploaded
  56832. }
  56833. setUploaded(e, t) {
  56834. this.isPanoZoomed(e.panoId) ? e.zoomUploaded = t : e.uploaded = t;
  56835. }
  56836. queueTileUpload(e, t, i) {
  56837. var n = this.getActiveRenderTargetDescriptor(e.panoId);
  56838. if (this.isRenderTargetDescriptorValid(n) && e.downloaded && !this.isTileUploaded(e) && (!e.uploadQueued || i)
  56839. && (!(e.panoSize > this.qualityManager.getMaxNavPanoSize())|| this.zoomingActive)) {
  56840. var r = this.getUploadQueueForPano(e.panoId);
  56841. //console.log(window.sceneName, 'queueTileUpload: ', e.panoId, e.tileIndex, i)
  56842. if(i){
  56843. //console.log('512下载好了直接uploadTile')
  56844. this.uploadTile(e, !1);//提交后该tile直接loaded了,无需等待
  56845. }else {
  56846. if(this.shoulPushToFrontOfQueue(e)){//如果是512的优先
  56847. this.forceQueue.push(e);
  56848. }else {
  56849. if(t && this.direction){
  56850. TilePrioritizer.insertSortedPanoTile(r, e, n.pano, this.direction);
  56851. }else r.push(e);
  56852. }
  56853. e.uploadQueued = !0;
  56854. this.uploadInterval || this.uploadIntervalCancelled || this.refreshUploadInterval(0);
  56855. }
  56856. }
  56857. }
  56858. shoulPushToFrontOfQueue(e) {
  56859. return 0 === TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, e.panoSize)
  56860. }
  56861. getTopUploadQueue() {
  56862. for (var e = null, t = null, i = S.Base; i <= S.Remaining; i++)
  56863. for (var n = 0; n < this.activePanos.length; n++)
  56864. if (e = this.activePanos[n],
  56865. t = this.getUploadQueueForPano(e.id),
  56866. t.length > 0)
  56867. switch (i) {
  56868. case S.Base:
  56869. if (0 === t[0].level)
  56870. return t;
  56871. break;
  56872. case S.Remaining:
  56873. return t
  56874. }
  56875. return null
  56876. }
  56877. peekNextFromUploadQueue() {
  56878. if (this.forceQueue.length > 0)
  56879. return this.forceQueue[0];
  56880. var e = this.getTopUploadQueue();
  56881. return e && e.length > 0 ? e[0] : null
  56882. }
  56883. clearAllQueuedUploads() {
  56884. this.clearAllUploadQueues(null, 0);
  56885. }
  56886. clearAllQueuedUploadsForPano(e) {
  56887. this.clearAllUploadQueues(e, 0);
  56888. }
  56889. clearAllUploadQueues(e, t) {
  56890. if (e)
  56891. this.clearUploadQueue(this.getUploadQueueForPano(e), t),
  56892. this.clearUploadQueue(this.forceQueue, t, e);
  56893. else {
  56894. for (var i = 0; i < this.activePanos.length; i++) {
  56895. var n = this.activePanos[i];
  56896. this.clearUploadQueue(this.getUploadQueueForPano(n.id), t);
  56897. }
  56898. this.clearUploadQueue(this.forceQueue, t);
  56899. }
  56900. }
  56901. clearUploadQueue(e, t, i) {
  56902. void 0 !== t && null !== t || (t = 0);
  56903. for (var n = 0; n < e.length;) {
  56904. var r = e[n];
  56905. (!i || i && i === r.tile.panoId) && r.level >= t ? (r.uploadQueued = !1,
  56906. e.splice(n, 1)) : n++;
  56907. }
  56908. //若报错, r.tile.panoId改为 r.panoId
  56909. }
  56910. updateUploadQueue(maxNPF,maxPF/* e, t */) {//参数是 maxNonBaseUploadsPerFrame and maxBaseUploadsPerFrame, 优先上传512
  56911. //maxNPF || (maxNPF = 1);
  56912. for (var i = 0, n = 0;;) {
  56913. //let old = this.forceQueue.slice(0)
  56914. if (n >= maxPF || i >= maxNPF)
  56915. break;
  56916. var r = this.getNextFromUploadQueue();
  56917. if (!r)
  56918. break;
  56919. //r.panoSize <2048 && console.log('panoId', r.panoId, 'panoSize', r.panoSize , old)
  56920. 0 !== r.level ? i++ : n++;
  56921. if (!(r.panoSize > this.qualityManager.getMaxNavPanoSize()) || this.zoomingActive) {
  56922. var o = this.getActiveRenderTargetDescriptor(r.panoId);
  56923. this.isRenderTargetDescriptorValid(o) && this.uploadTile(r, r.forceUpload);
  56924. }
  56925. }
  56926. }
  56927. updateDirection(e) {
  56928. if (e = e || this.direction) {
  56929. this.direction = e;
  56930. for (var t = 0; t < this.activePanos.length; t++) {
  56931. var i = this.activePanos[t],
  56932. n = this.getUploadQueueForPano(i.id);
  56933. TilePrioritizer.sortPanoTiles(n, i, this.direction);
  56934. }
  56935. }
  56936. }
  56937. anyUploaded(e) {
  56938. if (!e)
  56939. return !1;
  56940. if (e.tile && this.isTileUploaded(e.tile))
  56941. return !0;
  56942. if (e.children)
  56943. for (var t = 0; t < e.children.length; t++) {
  56944. var i = e.children[t];
  56945. if (this.anyUploaded(i))
  56946. return !0
  56947. }
  56948. return !1
  56949. }
  56950. setNodeCovered(e, t) {
  56951. this.isPanoZoomed(e.tile.panoId) ? e.zoomCovered = t : e.covered = t;
  56952. }
  56953. isNodeCovered(e) {
  56954. return !!e && (this.isPanoZoomed(e.tile.panoId) ? e.zoomCovered : e.covered)
  56955. }
  56956. addCoverageForNode(e) {
  56957. if (this.setNodeCovered(e, !0),
  56958. e.parent && e.covered) {
  56959. var t = e.parent;
  56960. this.nodeSubcovered(t) && this.addCoverageForNode(t, !0);
  56961. }
  56962. }
  56963. calcFullCoverage(e) {
  56964. var t = !1;
  56965. if (e.children)
  56966. for (var i = 0; i < e.children.length; i++) {
  56967. var n = e.children[i];
  56968. t = t || this.calcFullCoverage(n);
  56969. }
  56970. e.covered = e.tile.uploaded || t;
  56971. }
  56972. nodeSubcovered(e) {
  56973. if (!e.children)
  56974. return !1;
  56975. for (var t = 0; t < e.children.length; t++)
  56976. if (!e.children[t] || !this.isNodeCovered(e.children[t]))
  56977. return !1;
  56978. return !0
  56979. }
  56980. resetPanoDescriptor(e) {
  56981. this.getPanoDescriptor(e);
  56982. }
  56983. getPanoDescriptor(e) {
  56984. var t = this.panoDescriptors[e];
  56985. return t || (t = {},
  56986. this.panoDescriptors[e] = t),
  56987. t
  56988. }
  56989. resetPanoLODDescriptors(e) {
  56990. var t = this.getPanoLODDescriptors(e);
  56991. for (var i in t)
  56992. if (t.hasOwnProperty(i)) {
  56993. var n = t[i];
  56994. n.uploadCount = 0,
  56995. n.uploadAttempts = 0;
  56996. n.uploaded = [];
  56997. }
  56998. }
  56999. getPanoLODDescriptor(e, t) {
  57000. var i = this.getPanoLODDescriptors(e),
  57001. n = i[t];
  57002. return n || (n = {
  57003. uploadCount: 0,
  57004. uploadAttempts: 0,
  57005. uploaded:[],//add
  57006. },
  57007. i[t] = n),
  57008. n
  57009. }
  57010. getPanoLODDescriptors(e) {
  57011. var t = this.panoLODDescriptors[e];
  57012. return t || (t = {},
  57013. this.panoLODDescriptors[e] = t),
  57014. t
  57015. }
  57016. onTileDownloaded(o) {
  57017. var e = o.desc;
  57018. var t = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, e.panoSize),
  57019. i = this.getTileDirectoryEntry(e.panoId, e.face, t, e.faceTileIndex);
  57020. i.downloaded = !0;
  57021. i.image = e.image;
  57022. i.panoSize = e.panoSize;
  57023. i.tileX = e.tileX;
  57024. i.tileY = e.tileY;
  57025. i.totalTiles = e.totalTiles;
  57026. i.tileIndex = e.tileIndex;
  57027. i.faceTileIndex = e.faceTileIndex;
  57028. i.face = e.face;
  57029. i.cubeFace = TileUtils.mapFaceToCubemapFace(e.face);
  57030. i.panoId = e.panoId;
  57031. i.tileSize = e.tileSize;
  57032. i.direction = (new Vector3).copy(e.direction);
  57033. i.node = null;
  57034. i.level = TileTree.getLevelCountForSize(TileUtils.TILE_SIZE, i.panoSize);
  57035. if (this.isPanoActive(i.panoId)) {
  57036. var n = this.getTileTree(i.panoId, i.face);
  57037. var r = n.getSubNode(i.panoSize, i.tileX, i.tileY);
  57038. this.linkTileAndNode(i, r);
  57039. this.queueTileUpload(i, !0);
  57040. }
  57041. }
  57042. getTileDirectoryEntry(panoId, t, i, n) {
  57043. var r = this.tileDirectory[panoId];
  57044. r || (r = {}, this.tileDirectory[panoId] = r);
  57045. var o = 16384 * t + 1024 * i + n, //t:4096级别
  57046. a = r[o];
  57047. return a || (a = {
  57048. downloaded: !1,
  57049. uploaded: !1,
  57050. zoomUploaded: !1
  57051. },
  57052. r[o] = a),
  57053. a._key = panoId + ":" + t + ":" + i + ":" + n,//panoId : face : level : faceTileIndex
  57054. a._tileKey = o,
  57055. a
  57056. }
  57057. setZoomingActive(active, pano, i) {//设置当前正在zoom的pano
  57058. this.zoomPanoRenderingDisabled || active === this.zoomingActive && this.zoomPanoId === pano.id || (this.zoomingActive = active,
  57059. this.zoomPanoId = pano.id,
  57060. this.zoomingActive && (this.zoomPanoId !== pano.id || i) && this.updateZoomedPanoFromBase(pano));
  57061. }
  57062. updateZoomedPanoFromBase(pano) {//因更换pano所以将pano的rendertarget渲染到panoRenderer的zoomRenderTarget上
  57063. if (!this.zoomPanoRenderingDisabled) {
  57064. var t = this.getActiveRenderTargetDescriptor(pano.id);
  57065. if (t && t.renderTarget ) {
  57066. if(this.zoomRenderTarget){
  57067. var i = Math.min(this.qualityManager.maxRenderTargetSize, this.qualityManager.getMaxZoomPanoSize()), //change
  57068. n = t.renderTarget,
  57069. r = t.size;
  57070. this.copyCubeMap(n.texture, this.zoomRenderTarget, r, r, i, i);
  57071. }
  57072. this.copyBaseRenderStatusToZoomed(pano.id);
  57073. }
  57074. }
  57075. }
  57076. add(e) {
  57077. this.M.push(e);
  57078. }
  57079. initDescriptor(size) {
  57080. var t = createDescriptor();
  57081. t.inUse = !0;
  57082. t.size = size;
  57083. this.add(t);
  57084. return t
  57085. }
  57086. activeDescripor(e) {
  57087. for (var t = 0; t < this.M.length; t++) {
  57088. var i = this.M[t];
  57089. if (!i.inUse && i.size === e){
  57090. i.inUse = !0;
  57091. return i
  57092. }
  57093. }
  57094. return null
  57095. }
  57096. deactiveDescripor(e) {
  57097. for (var t = 0; t < this.M.length; t++) {
  57098. var i = this.M[t];
  57099. if (i.renderTarget === e){
  57100. i.inUse = !1;
  57101. return !0
  57102. }
  57103. }
  57104. return !1
  57105. }
  57106. enableHighQuality(e){//xzw add 如果最多只要2k图的话enableUltraHighQualityMode替换成这个
  57107. if (!this.qualityManager.highQualityModeStarted) {
  57108. this.setupZoomRenderTarget();
  57109. e();
  57110. //this.qualityManager.updateHighResolutionSettings(e)////////?
  57111. this.qualityManager.highQualityModeStarted = true;
  57112. }
  57113. }
  57114. linkTileAndNode(e, t) {
  57115. t.tile = e,
  57116. e.node = t;
  57117. }
  57118. linkAllTilesAndNodes(e) {
  57119. var t = function (t, i, n, r, o) {
  57120. var a = this.getTileDirectoryEntry(e.id, i, r, o);
  57121. this.linkTileAndNode(a, n);
  57122. };
  57123. for (var i = 0; i < TileUtils.FACES_PER_PANO; i++) {
  57124. var n = this.getTileTree(e.id, i);
  57125. n.breadthFirst({
  57126. callback: t.bind(this, n, i)
  57127. });
  57128. }
  57129. }
  57130. //--------------sceneRenderer
  57131. initSizedTexture2D(e, t, i) {
  57132. var renderer = this.viewer.renderer,
  57133. o = renderer.getContext(),
  57134. a = renderer.state,
  57135. s = new Texture(null);
  57136. s.flipY = !1,
  57137. i !== !0 && (i = !1),
  57138. s.generateMipmaps = i;
  57139. var l = renderer.paramThreeToGL(s.format),
  57140. c = renderer.paramThreeToGL(s.type),
  57141. h = renderer.properties.get(s),
  57142. u = o.createTexture();
  57143. a.bindTexture(o.TEXTURE_2D, u),
  57144. o.pixelStorei(o.UNPACK_FLIP_Y_WEBGL, s.flipY),
  57145. o.texImage2D(o.TEXTURE_2D, 0, l, e, e, 0, l, c, null),
  57146. s.wrapS = t,
  57147. s.wrapT = t;
  57148. var d = renderer.paramThreeToGL(t);
  57149. return o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_S, d),
  57150. o.texParameteri(o.TEXTURE_2D, o.TEXTURE_WRAP_T, d),
  57151. i ? (s.magFilter = LinearFilter,
  57152. s.minFilter = LinearMipMapLinearFilter,
  57153. o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR),
  57154. o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR_MIPMAP_NEAREST),
  57155. o.generateMipmap(o.TEXTURE_2D)) : (s.magFilter = LinearFilter,
  57156. s.minFilter = LinearFilter,
  57157. o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MAG_FILTER, o.LINEAR),
  57158. o.texParameteri(o.TEXTURE_2D, o.TEXTURE_MIN_FILTER, o.LINEAR)),
  57159. a.bindTexture(o.TEXTURE_2D, null),
  57160. h.__webglTexture = u,
  57161. s
  57162. }
  57163. deallocateCubeTexture(e) {
  57164. var t = this.viewer.renderer,
  57165. i = t.getContext(),
  57166. renderer = t.properties.get(e);
  57167. i.deleteTexture(renderer.__image__webglTextureCube);
  57168. }
  57169. uploadTexture2D(img, tex, startX, startY, width, height) {
  57170. var renderer = this.viewer.renderer,
  57171. gl = renderer.getContext(),
  57172. webglState = renderer.state,
  57173. c = renderer.properties.get(tex);
  57174. webglState.bindTexture(gl.TEXTURE_2D, c.__webglTexture),
  57175. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, tex.flipY),
  57176. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, tex.premultiplyAlpha),
  57177. gl.pixelStorei(gl.UNPACK_ALIGNMENT, tex.unpackAlignment),
  57178. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, renderer.paramThreeToGL(tex.wrapS)),
  57179. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, renderer.paramThreeToGL(tex.wrapT)),
  57180. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, renderer.paramThreeToGL(tex.magFilter)),
  57181. gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, renderer.paramThreeToGL(tex.minFilter)),
  57182. gl.texSubImage2D(gl.TEXTURE_2D, 0, startX, startY, gl.RGBA, gl.UNSIGNED_BYTE, img),
  57183. tex.generateMipmaps && gl.generateMipmap(gl.TEXTURE_2D),
  57184. webglState.bindTexture(gl.TEXTURE_2D, null);
  57185. }
  57186. getCubeOrientationForCubeFace(e, t) {
  57187. switch (e) {
  57188. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  57189. t.set(0, -Math.PI / 2, 0);
  57190. break;
  57191. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  57192. t.set(0, Math.PI / 2, 0);
  57193. break;
  57194. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  57195. t.set(Math.PI / 2, Math.PI, 0);
  57196. break;
  57197. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  57198. t.set(-Math.PI / 2, Math.PI, 0);
  57199. break;
  57200. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  57201. t.set(0, -Math.PI, 0);
  57202. break;
  57203. case GLCubeFaces$2.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  57204. t.set(0, 0, 0);
  57205. }
  57206. }
  57207. //dispose所有cubeRenderTarget
  57208. disposeIdelTargets() {
  57209. let disposeCount = 0;
  57210. for (var t = 0; t < this.M.length; t++) {
  57211. var i = this.M[t];
  57212. if (!i.inUse) {
  57213. disposeCount++;
  57214. i.renderTarget.dispose();
  57215. }
  57216. }
  57217. //console.log('disposeIdelTargets ', disposeCount, 'of', this.M.length)
  57218. }
  57219. }
  57220. PanoRenderer.prototype.setupZoomRenderTarget = function(){
  57221. var targets = {};
  57222. return function(){
  57223. if(this.qualityManager.maxRenderTargetSize == 2048 && this.qualityManager.getMaxNavPanoSize()==2048)return; //不使用zoomTarget 直接用pano的tiledPanoRenderTarget,防崩溃
  57224. if (this.qualityManager.getMaxZoomPanoSize() >= this.qualityManager.getMaxNavPanoSize() ) {
  57225. //部分手机2k时copyCubeMap会重载 , 所以如果没有超出当前分辨率,就不使用zoomRenderTarget。但在微信依旧会重载,只是优化了些,safari几乎不会。
  57226. if (this.zoomRenderTarget && this.zoomRenderTarget.width === this.qualityManager.getMaxZoomPanoSize())
  57227. return;
  57228. var e = this.zoomRenderTarget;
  57229. var size = this.qualityManager.getMaxZoomPanoSize();
  57230. if(size > this.qualityManager.maxRenderTargetSize){
  57231. return
  57232. }
  57233. if(targets[size]){
  57234. this.zoomRenderTarget = targets[size];
  57235. }else {
  57236. this.zoomRenderTarget = this.initTiledPano(size, false ); //放大后不使用抗锯齿,否则消
  57237. targets[size] = this.zoomRenderTarget;
  57238. }
  57239. if (e) {//将旧的zoomRenderTarget渲染到新zoomRenderTarget上
  57240. var t = e.width,
  57241. i = this.zoomRenderTarget.width;
  57242. this.copyCubeMap(e.texture, this.zoomRenderTarget, t, t, i, i),
  57243. e.texture.dispose(),
  57244. e.texture.loaded = !1,
  57245. e.texture.version = 0,
  57246. this.deallocateCubeTexture(e.texture),
  57247. e.texture = null;
  57248. }
  57249. this.zoomPanoRenderingDisabled = !1;
  57250. } else
  57251. this.zoomPanoRenderingDisabled = !0;
  57252. }
  57253. }();
  57254. PanoRenderer.prototype.updateActivePanos = function () {
  57255. var e = [];
  57256. return function (t, i) {
  57257. e.length = 0;
  57258. for (var n = 0; n < this.activePanos.length; n++) {
  57259. t && e.length === i && e.push(t);
  57260. var r = this.activePanos[n],
  57261. o = this.getActiveRenderTargetDescriptor(r.id);
  57262. t && r.id === t.id || !this.isRenderTargetDescriptorValid(o) || e.push(r);
  57263. }
  57264. t && i >= e.length && e.push(t),
  57265. this.activePanos.length = 0,
  57266. this.activePanos.push.apply(this.activePanos, e);
  57267. }
  57268. }();
  57269. PanoRenderer.prototype.renderPanoTiles = function () {
  57270. var e = [];
  57271. return function (panoId, i, n, r) {
  57272. this.zoomRenderTarget && this.zoomRenderTarget.width === this.qualityManager.getMaxZoomPanoSize() || this.zoomPanoRenderingDisabled || this.setupZoomRenderTarget(),//如果ZoomRenderTarget大小需要变动就重新创建
  57273. i = i || this.direction || Vectors.FORWARD; // [{1:Vectors.FORWARD}]?
  57274. var o = this.getActiveRenderTargetDescriptor(panoId);
  57275. if (!this.isRenderTargetDescriptorValid(o))
  57276. console.error("PanoRenderer.renderPanoTiles() -> Cannot render to a pano that is not activated.");
  57277. for (var a = 0; a < TileUtils.FACES_PER_PANO; a++) {
  57278. var s = this.getTileTree(panoId, a);
  57279. e.length = 0;
  57280. s.breadthFirst({//获取该面所有node 85个 = 1+4+16+64
  57281. saveVisited: e
  57282. });
  57283. for (var l = 0; l < e.length; l++) {
  57284. var c = e[l];
  57285. this.queueTileUpload(c.tile, !1, r || 0 === l && n);// 第0个是512的,会直接uploadTile
  57286. }
  57287. }
  57288. this.updateDirection(i);
  57289. }
  57290. }();
  57291. PanoRenderer.prototype.getNextFromUploadQueue = function () {
  57292. var e = function (e) {
  57293. var t = e.shift();
  57294. return t.uploadQueued = !1,
  57295. t
  57296. };
  57297. return function () {
  57298. if (this.forceQueue.length > 0)
  57299. return e(this.forceQueue);
  57300. var t = this.getTopUploadQueue();
  57301. return t && t.length > 0 ? e(t) : null
  57302. }
  57303. }();
  57304. /* PanoRenderer.prototype.refreshUploadInterval = function () {
  57305. var e = null;
  57306. return function (t) {
  57307. this.uploadIntervalCancelled || (e || (e = upload.bind(this)),
  57308. null !== t && void 0 !== t || (t = w),
  57309. b || (t = _),
  57310. this.uploadInterval = window.setTimeout(e, t),
  57311. this.uploadIntervalDelay = t)
  57312. }
  57313. }()
  57314. PanoRenderer.prototype.update = function () {
  57315. var e = performance.now(),
  57316. t = 0;
  57317. return function () {
  57318. this.uploadIntervalCancelled = !0;
  57319. window.clearTimeout(this.uploadInterval);
  57320. this.uploadInterval = null;
  57321. var i = performance.now() - e;
  57322. //!(i > w || 0 === t) || !this.overlayTilesLoaded && this.usingTileOverlay || (this.updateUploadQueue(this.maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame),
  57323. //e = performance.now()),
  57324. if (!(i > w || 0 === t) || !this.overlayTilesLoaded && this.usingTileOverlay) {} else {
  57325. this.updateUploadQueue(this.maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame);
  57326. e = performance.now();
  57327. }
  57328. t++;
  57329. }
  57330. }() */
  57331. PanoRenderer.prototype.update = function () {
  57332. //this.uploadIntervalCancelled = true ; //不使用setTimeout,而是在sceneRenderer每帧都update
  57333. if(viewer.images360.latestRequestMode == 'showPanos'){
  57334. let maxNonBaseUploadsPerFrame = viewer.lastFrameChanged ? Common.getBestCount('maxStandard', 0, 2, 1, 10 /* ,true */ ) : 2; // 这是每帧uploadTile非512的瓦片tex的数量。 手机在前进时可能会总是0,直到到漫游点后为2
  57335. let maxBaseUploadsPerFrame = viewer.lastFrameChanged ? Common.getBestCount('maxBase',1,6, 1, 14 /* ,true */ ) : 6; //this.maxBaseUploadsPerFrame //原先6. 但持续前进过程中会请求加载下一个漫游图,一次加6张会卡的。
  57336. this.updateUploadQueue(maxNonBaseUploadsPerFrame, maxBaseUploadsPerFrame);
  57337. //注:静止时看不出卡顿所以全速加载
  57338. }
  57339. };
  57340. /* function upload() {
  57341. if (!this.uploadIntervalCancelled) {
  57342. if (this.overlayTilesLoaded || !this.usingTileOverlay) {
  57343. b = !0
  57344. let maxNonBaseUploadsPerFrame = viewer.mainViewport.view.isFlying() ? 1 : this.maxNonBaseUploadsPerFrame //原先2。这是每帧uploadTile非512的瓦片tex的数量。之前的2太卡了,降为1。(检测卡顿方法:在一个pano点旋转至所有2048的tile都加载完,然后之后到这个点看看卡不卡。因为该点tiles都下载完了所以会在飞过来时陆续都加载,所以容易卡)
  57345. this.updateUploadQueue(maxNonBaseUploadsPerFrame, this.maxBaseUploadsPerFrame)
  57346. let time = viewer.mainViewport.view.isFlying() ? 60 : w //add 飞行有时候会卡,增长间隔
  57347. this.peekNextFromUploadQueue() ? this.refreshUploadInterval(time) : this.uploadInterval = null //定时下一次更新
  57348. } else {
  57349. this.refreshUploadInterval(this.uploadIntervalDelay)
  57350. }
  57351. }
  57352. } */
  57353. PanoRenderer.prototype.uploadTile = function () {//重写
  57354. var collection = {},
  57355. overlayStyle = config$1.tiling.overlayStyle;
  57356. var failHistory = {};
  57357. return function (info, n) {
  57358. var id = info.panoId,
  57359. img = info.image,
  57360. tileSize = info.tileSize,
  57361. panoSize = info.panoSize,
  57362. tileIndex = info.tileIndex,
  57363. totalTiles = info.totalTiles,
  57364. tileX = info.tileX,
  57365. tileY = info.tileY,
  57366. p = !0,
  57367. g = !1,
  57368. ignore = false, //add
  57369. LodDescripor = (this.getPanoDescriptor(id), this.getPanoLODDescriptor(id, panoSize)),
  57370. activeDescripor = this.getActiveRenderTargetDescriptor(id),
  57371. renderTarget = activeDescripor.renderTarget,
  57372. size = activeDescripor.size;//当前要渲染的面的分辨率,也就是MaxNavPanoSize
  57373. if (this.isPanoZoomed(id) && this.zoomRenderTarget) {
  57374. renderTarget = this.zoomRenderTarget;
  57375. size = this.zoomRenderTarget.width; //this.qualityManager.getMaxZoomPanoSize(); //放大后可能2048或4096
  57376. }
  57377. //console.log(window.sceneName, 'uploadTile ', id, tileIndex)
  57378. let done = ()=>{
  57379. if(!LodDescripor.uploaded.includes(tileIndex)){//已经upload过(本来这时候直接返回,但发现缩放后这不会归零,导致清晰度不更新,所以还是redraw且emit吧)
  57380. //console.log('try to reupload and return',tileIndex)
  57381. LodDescripor.uploaded.push(tileIndex);
  57382. LodDescripor.uploadCount++;
  57383. }
  57384. this.dispatchEvent({type:PanoRendererEvents$1.TileRenderSuccess, id, panoSize, tileIndex, totalTiles});
  57385. LodDescripor.uploadCount === totalTiles && this.dispatchEvent({type:PanoRendererEvents$1.PanoRenderComplete, id, panoSize, totalTiles, updateFullComplete:true});
  57386. this.setUploaded(info, !0);
  57387. this.addCoverageForNode(info.node);
  57388. };
  57389. {//已经uploadTile过了不再uploadTile
  57390. if(!this.isRenderTargetDescriptorValid(activeDescripor)){
  57391. p = !1; g = !1;
  57392. }
  57393. if(!n){
  57394. this.anyUploaded(info.node) && (p = !1, g = !0,ignore = true ); //包括子集也uploadTile了
  57395. this.isTileUploaded(info) && (p = !1, g = !1,ignore = true ); //当前tile uploadTile了
  57396. }
  57397. }
  57398. if (p) {
  57399. /*if(failHistory[id+':'+ panoSize+ ':' +tileIndex]){
  57400. console.log('uploadTile retry',id, panoSize, tileIndex)
  57401. }
  57402. console.log('uploadTile 成功', id, panoSize, tileIndex) */
  57403. var C = tileX * tileSize,
  57404. I = tileY * tileSize,
  57405. E = tileSize / panoSize * size, // tile在renderTarget上渲染出的宽度
  57406. b = C / panoSize * size, // tile在renderTarget上渲染的startX
  57407. w = I / panoSize * size; // tile在renderTarget上渲染的startY
  57408. if(panoSize > this.qualityManager.maxRenderTargetSize ){ //4096 改
  57409. /* var tex = this.initSizedTexture2D(tileSize, THREE.ClampToEdgeWrapping);
  57410. var loaded = this.viewer.images360.isHighMapLoaded(info.cubeFace, tileX,tileY) */
  57411. this.viewer.images360.getHighImage(img, info.cubeFace, tileX, tileY);
  57412. }else {
  57413. collection[tileSize] || (collection[tileSize] = this.initSizedTexture2D(tileSize, ClampToEdgeWrapping));
  57414. var tex = collection[tileSize];
  57415. this.uploadTexture2D(img, tex, 0, 0, tileSize, tileSize);//只替换tex对应的img,不新建
  57416. if(panoSize > this.qualityManager.maxRenderTargetSize){
  57417. loaded || this.viewer.images360.updateHighMap(tex, info.cubeFace, tileX,tileY);
  57418. }else {
  57419. if (1 === overlayStyle || 2 === overlayStyle) {
  57420. var T = 1 === overlayStyle ? this.overlayTilesBasic : this.overlayTilesEnhanced;
  57421. this.renderToCubeMap(tex, renderTarget, tileSize, tileSize, 0, 0, tileSize, tileSize, b, w, E, E, info.cubeFace);
  57422. this.renderToCubeMap(T[panoSize], renderTarget, tileSize, tileSize, 0, 0, tileSize, tileSize, b, w, E, E, info.cubeFace, NormalBlending, !0, .5);
  57423. } else {
  57424. this.renderToCubeMap(tex, renderTarget, tileSize, tileSize, 0, 0, tileSize, tileSize, b, w, E, E, info.cubeFace);
  57425. }
  57426. }
  57427. }
  57428. done();
  57429. }else if(ignore){
  57430. //console.log('finish because anyUploaded',id,panoSize,tileIndex)
  57431. done(); //改: 如果因为这部分更高清的贴图已加载所以才不绘制的话,直接完成
  57432. }else {
  57433. //console.log('uploadTile 失败', id, panoSize, tileIndex)
  57434. if(panoSize == 512){
  57435. //console.log("!!!!!!!!!!!!!")
  57436. }
  57437. failHistory[id+':'+ panoSize+ ':' +tileIndex] = true;
  57438. this.setUploaded(info, !1);
  57439. }
  57440. info.uploadAttempted || (LodDescripor.uploadAttempts++, this.dispatchEvent({type:PanoRendererEvents$1.TileUploadAttempted, id, panoSize, tileIndex, totalTiles})),
  57441. info.uploadAttempted = !0;
  57442. LodDescripor.uploadAttempts === totalTiles && this.dispatchEvent({type:PanoRendererEvents$1.UploadAttemptedForAllTiles, id, panoSize, totalTiles});
  57443. return g;
  57444. }
  57445. }();
  57446. /*
  57447. 注:tileY的方向同UV,从下到上
  57448. renderToCubeMap里的画布or镜头的xy范围是-0.5到0.5
  57449. */
  57450. PanoRenderer.prototype.renderToCubeMap = function() {
  57451. var inited = !1,
  57452. scene = null,
  57453. camera = null,
  57454. material = null,
  57455. geo = null,
  57456. plane = null,
  57457. l = 1;
  57458. return function(texture, renderTarget, tileWidth, tileHeight, startXinTile, startYinTile, widthinTile, heightinTile, startX, startY, width, height, cubeFace, E, b, w) {
  57459. var renderer = this.viewer.renderer;
  57460. inited || (camera = new OrthographicCamera(l / -2, l / 2, l / 2, l / -2, -200, 200),
  57461. camera.position.z = 150,
  57462. scene = new Scene,
  57463. scene.add(camera),
  57464. material = new BasicMaterial({ depthWrite: !1, depthTest: !1, side: 0,}),
  57465. geo = new PlaneBufferGeometry(l, l),
  57466. plane = new Mesh(geo, material),
  57467. plane.position.z = 0,
  57468. scene.add(plane),
  57469. inited = !0);
  57470. var uv = geo.getAttribute("uv");
  57471. uv.setDynamic(!0), //setUsage
  57472. uv.needsUpdate = !0;
  57473. var uvArr = uv.array,
  57474. S = startXinTile / tileWidth, //uv这几个值基本是固定的startXinTile:0,startYinTile:0,widthinTile:512,widthinTile:512,tileWidth:512,tileHeight:512 也就是说uv不会变、每张tile的有效范围是100%
  57475. M = startYinTile / tileHeight,
  57476. R = widthinTile / tileWidth,
  57477. P = heightinTile / tileHeight;
  57478. uvArr[0] = S,
  57479. uvArr[1] = M + P,
  57480. uvArr[2] = S + R,
  57481. uvArr[3] = M + P,
  57482. uvArr[4] = S,
  57483. uvArr[5] = M,
  57484. uvArr[6] = S + R,
  57485. uvArr[7] = M;
  57486. //修改posistion,使该plane只占据需要绘制的部分。类似拼图。
  57487. //startX startY width height 都是在画布上的大小,比如画布大小为2048*2048,此tile为16分之一,tileX是1,tileY是1,则startX=2048/4,startY=2048/4
  57488. var pos = geo.getAttribute("position");
  57489. pos.setDynamic(!0),
  57490. pos.needsUpdate = !0;
  57491. var posArr = pos.array,
  57492. D = startX / renderTarget.width - l / 2 // 起始x
  57493. ,
  57494. N = startY / renderTarget.height - l / 2 // 起始y
  57495. ,
  57496. B = width / renderTarget.width // 宽
  57497. ,
  57498. F = height / renderTarget.height; // 高
  57499. posArr[0] = D,
  57500. posArr[1] = N + F,
  57501. posArr[3] = D + B,
  57502. posArr[4] = N + F,
  57503. posArr[6] = D,
  57504. posArr[7] = N,
  57505. posArr[9] = D + B,
  57506. posArr[10] = N;
  57507. //renderer.properties.get(scene);
  57508. material.map = texture;//material.uniforms.map.value = texture;
  57509. material.blending = E || NoBlending,
  57510. material.transparent = !!b;
  57511. void 0 !== w && null !== w || (w = 1),
  57512. material.uniforms.opacity.value = w,
  57513. // material.needUpdate = !0
  57514. //renderTarget.activeCubeFace = cubeFace, //0-5 应该是指定渲染h中的面 失效
  57515. /* renderer.setScissorTest(!0)
  57516. //指定绘制区域,类似遮罩(相对于屏幕)
  57517. renderer.setScissor(startX,startY,width,height) //加上这个会不会快一些,尤其是spherical
  57518. //指定绘制视口位置和大小(相对于屏幕)
  57519. */
  57520. renderTarget.viewport.set(0, 0, renderTarget.width, renderTarget.height);
  57521. var V = renderer.autoClear;
  57522. var oldTarget = renderer.getRenderTarget();
  57523. renderer.autoClear = !1;
  57524. renderer.setRenderTarget(renderTarget, cubeFace);
  57525. renderer.render(scene, camera/* , renderTarget, !1 */);
  57526. renderer.setRenderTarget(oldTarget);
  57527. renderer.autoClear = V;
  57528. //renderer.setScissorTest(!1)
  57529. /* this.renderer.render(scene, camera, this.planeTargets[cubeFace], !1),//针对有的场景app第一个点图加载不成功的问题
  57530. console.log(`图index ${cubeFace} , ${startX}, ${startY}, ${width}, ${height}`)
  57531. this.targetList[cubeFace] || (this.targetList[cubeFace] = [])
  57532. this.targetList[cubeFace].push([startX,startY,width,height])*/
  57533. }
  57534. }();
  57535. /*
  57536. * 将texture渲染到zoomRenderTarget上(目的是复制贴图到zoomRenderTarget)
  57537. */
  57538. PanoRenderer.prototype.copyCubeMap = function() {//将texture渲染到zoomRenderTarget上
  57539. var inited = !1,
  57540. scene = null,
  57541. camera = null,
  57542. material = null,
  57543. geo = null,
  57544. mesh = null,
  57545. testCube = null, //add
  57546. c = new Euler;
  57547. return function(texture, renderTarget, tWidth, tHeight, rWidth, rHeight, m, v, A) {
  57548. if(rWidth > this.qualityManager.maxRenderTargetSize) return; //add
  57549. if (!inited) {
  57550. var w = 2;
  57551. camera = new OrthographicCamera(w / -2, w / 2, w / 2, w / -2, 0, 200),
  57552. camera.position.set(0, 0, 0),
  57553. scene = new Scene,
  57554. scene.add(camera);
  57555. material = new ShaderMaterial({
  57556. uniforms: {
  57557. tDiffuse: {
  57558. type: "t",
  57559. value: null
  57560. },
  57561. alpha: {
  57562. type: "f",
  57563. value: 1
  57564. }
  57565. },
  57566. vertexShader: Shaders['copyCubeMap.vs'],
  57567. fragmentShader:Shaders['copyCubeMap.fs'],
  57568. depthWrite: !1,
  57569. depthTest: !1,
  57570. side: DoubleSide
  57571. });
  57572. geo = new BoxGeometry(w, w, w),
  57573. mesh = new Mesh(geo, material),
  57574. scene.add(mesh);
  57575. inited = !0;
  57576. /* testCube = mesh.clone();
  57577. viewer.scene.scene.add(testCube);
  57578. Potree.Utils.setObjectLayers(testCube, 'sceneObjects')
  57579. */
  57580. }
  57581. let autoClear = this.viewer.renderer.autoClear;
  57582. let oldTarget = this.viewer.renderer.getRenderTarget();
  57583. this.viewer.renderer.autoClear = false;
  57584. material.uniforms.tDiffuse.value = texture;
  57585. material.blending = m || NoBlending;
  57586. material.transparent = !!v;
  57587. void 0 !== A && null !== A || (A = 1);
  57588. material.uniforms.alpha.value = A;
  57589. material.needUpdate = !0;
  57590. for (var C = 0; C < 6; C++){
  57591. this.getCubeOrientationForCubeFace(C, c);
  57592. mesh.rotation.copy(c);
  57593. mesh.matrixWorldNeedsUpdate = !0;
  57594. mesh.updateMatrixWorld();
  57595. renderTarget.viewport.set(0, 0, rWidth, rHeight);
  57596. this.viewer.renderer.setRenderTarget(renderTarget, C ); //renderTarget.activeCubeFace = C//失效
  57597. this.viewer.renderer.render(scene, camera);
  57598. }
  57599. //console.warn('copyCubeMap' + rWidth)
  57600. this.viewer.renderer.autoClear = autoClear;
  57601. this.viewer.renderer.setRenderTarget(oldTarget);
  57602. }
  57603. }();
  57604. class DepthImageSampler extends EventDispatcher{
  57605. constructor(){
  57606. super();
  57607. var canvas = document.createElement("canvas");
  57608. this.canvas = canvas;
  57609. this.context = canvas.getContext("2d", {willReadFrequently: true});
  57610. this.imgDatas = [];
  57611. /* document.getElementsByTagName('body')[0].appendChild(canvas);
  57612. canvas.style.position = 'fixed';
  57613. canvas.style.width = '1024px';
  57614. canvas.style.top = canvas.style.left = 0
  57615. canvas.style['z-index'] = 100
  57616. */
  57617. this.maxDataCount = browser.isMobile() ? 6 : 20; //手机会崩溃. 平均每张图为8M数据量(以200个点的园区为例,加载时间久一些后,总内存=700 + 每张图的8M * maxDataCount)
  57618. this.maxNeighCount = browser.isMobile() ? 3 : 14; //包含在maxDataCount内的nearPanos最大个数.至少比maxDataCount少3个,留出空位给最近更新的pano
  57619. this.nearPanos = [];
  57620. }
  57621. updateNearPanos(panos){
  57622. this.nearPanos = panos.slice(0,this.maxNeighCount);
  57623. }
  57624. changeImg(img, pano){
  57625. this.pano = pano;
  57626. let item = this.imgDatas.find(p=>p.pano == pano);
  57627. if(/* this.img == img || */item){
  57628. //最新的在末尾,所以换到末尾
  57629. let index = this.imgDatas.indexOf(item);
  57630. this.imgDatas.splice(index,1);
  57631. this.imgDatas.push(item);
  57632. //console.log('重复使用',item.pano.id)
  57633. return
  57634. }
  57635. Potree.timeCollect.depthSamChangeImg.start = true; //不过在刚启动时得到的用时较大
  57636. try{
  57637. viewer.addTimeMark('depthSamChangeImg','start');
  57638. this.canvas.width = img.width;
  57639. this.canvas.height = img.height;
  57640. this.context.drawImage(img, 0, 0);
  57641. let o = this.context.getImageData(0, 0, img.width , img.height );
  57642. let data = o && o.data; //getImageData 1px时 : pc chrome 耗时0.01毫秒左右(排除第一次的50) , 但firefox: 4。但换贴图之后就多达5甚至几十
  57643. //console.log('changeImg',pano.id )
  57644. //this.img = img
  57645. if(!data){
  57646. console.error('getImageData 得不到?!why!');
  57647. return false
  57648. }
  57649. if(this.imgDatas.length >= this.maxDataCount){
  57650. let old = this.imgDatas.find(e=>!this.nearPanos.includes(e.pano));
  57651. //console.log('推出',old.pano.id)
  57652. this.imgDatas.splice(this.imgDatas.indexOf(old), 1);//推出使用时间最早的一个非nearPano
  57653. }
  57654. this.imgDatas.push({pano, data});
  57655. this.dispatchEvent({type:'changeImg',pano});
  57656. viewer.addTimeMark('depthSamChangeImg','end'); //耗时chrome 25ms,firefox: 38ms, iphoneX:33ms
  57657. }catch(e){
  57658. console.error(e ); //内存不足 Failed to execute 'getImageData' on 'CanvasRenderingContext2D': Out of memory at ImageData creation
  57659. return false
  57660. }
  57661. /* pano.depthData = {}
  57662. for(let h=0; h<img.height; h++){
  57663. for(let w=0; w<img.width; w++){
  57664. let blockIndex = img.width * h + w
  57665. let r = data.slice(blockIndex*4, (blockIndex+1)*4)
  57666. let depth = r[1] + r[0] / 256
  57667. if(depth>0) pano.depthData[h+'|'+w] = depth
  57668. }
  57669. } */
  57670. }
  57671. clearTexData(){
  57672. this.imgDatas.length = 0;
  57673. }
  57674. getDepth( UVx, UVy, useNeighIfZero) {//根据图片像素获取深度值
  57675. var x = Math.round(UVx * (this.canvas.width - 1))
  57676. , y = Math.round(UVy * (this.canvas.height - 1));
  57677. let imgData = this.imgDatas.find(p=>p.pano == this.pano);
  57678. let get = (x,y,)=>{
  57679. if (!(x < 0 || y < 0 || x >= this.canvas.width || y >= this.canvas.height)){
  57680. let blockIndex = this.canvas.width * y + x;
  57681. let color = imgData.data.slice(blockIndex*4, (blockIndex+1)*4);
  57682. return color[1] + color[0] / 256 //为什么不是除以255见聊天记录.(验证过比点云的远一点点)
  57683. }
  57684. };
  57685. /* viewer.addTimeMark('depthSampler','start')
  57686. var r = this.context.getImageData(x, y, 1, 1).data; //pc chrome 耗时0.01毫秒左右(排除第一次的50) , 但firefox: 4。但换贴图之后就多达5甚至几十
  57687. viewer.addTimeMark('depthSampler','end')
  57688. */
  57689. let depth = get(x,y);
  57690. if(!depth && useNeighIfZero){ //遇到过有的相隔很远且有阻挡的两个漫游点间居然depth为0,没有阻挡?但是周围点有四个非零。所以为了修正会飞到很远的点加个识别周围像素的depth 。 2024.3.19
  57691. let results = [];
  57692. let d = 0, sum = 0, count = 0, maxResDis = 1;
  57693. while(d++<maxResDis){
  57694. for(let i=-d;i<=d;i++){
  57695. for(let j=-d;j<=d;j++){
  57696. if(i==-d || i==d || j==-d || j==d ){//外围
  57697. let depth1 = get(x+i,y+j);
  57698. if(depth1!=0){
  57699. results.push(depth1);
  57700. }
  57701. }
  57702. }
  57703. }
  57704. }
  57705. if(results.length){
  57706. depth = results.reduce((w,c)=>{return w+c},0) / results.length;
  57707. //console.error('useNeighIfZero', results, depth)
  57708. }
  57709. //console.log('useNeighIfZero', results, depth)
  57710. }
  57711. return depth
  57712. }
  57713. sample( intersect, currentPano, onlyPos, useNeighIfZero ) {//通过和skybox的intersect得到真实的intersect的位置
  57714. if(!intersect)return
  57715. let location = new Vector3;
  57716. let normal;
  57717. currentPano = currentPano || viewer.images360.currentPano;
  57718. if(currentPano != this.currentPano || !this.imgDatas.find(p=>p.pano == currentPano) ){
  57719. if(!currentPano.depthTex/* || !currentPano.depthTex.image */) return //未加载
  57720. if(this.changeImg(currentPano.depthTex.image, currentPano) === false){
  57721. console.log('失败', currentPano.id);
  57722. return false //失败
  57723. }
  57724. this.currentPano = currentPano;
  57725. }
  57726. let origin = currentPano.position;
  57727. let dir = intersect.dir || new Vector3().subVectors(intersect.point, origin).normalize();
  57728. //var uv = intersect.uv
  57729. //let dirInPano = math.getNormalDir(dir, currentPano)//转化为考虑漫游点旋转的方向
  57730. let dirInPano = dir.clone().applyMatrix4(currentPano.panoMatrix2Inverse).normalize(); //转化为考虑漫游点旋转的方向
  57731. let uv = math.getUVfromDir(dirInPano);//转化为uv
  57732. let distance = this.getDepth( uv.x, uv.y, useNeighIfZero);
  57733. //viewer.addTimeMark(markName,'end')
  57734. if (!distance){
  57735. const margin = 0.1;
  57736. if(uv.y > 1-Potree.config.depthTexUVyLimit){//漫游点底部识别不到的区域,给一个地板高度
  57737. distance = (currentPano.floorPosition.z - origin.z - margin) / dir.z;
  57738. location.copy(dir).multiplyScalar(distance).add(origin);
  57739. let normal = new Vector3(0,0,1);
  57740. return {location, normal, distance}
  57741. }else if(uv.y < Potree.config.depthTexUVyLimit){
  57742. let ceilZ = currentPano.getCeilHeight();
  57743. if(ceilZ == Infinity)return !1
  57744. else {
  57745. distance = (ceilZ - origin.z - margin) / dir.z;
  57746. location.copy(dir).multiplyScalar(distance).add(origin);
  57747. let normal = new Vector3(0,0,-1);
  57748. return {location, normal, distance}
  57749. }
  57750. }
  57751. //console.log('无穷远')
  57752. return !1; //应该是天空或模型外 , 因为很少有漫游点的地方还拍不到地板
  57753. }
  57754. //console.log('distance', distance, dirInPano.clone().multiplyScalar(distance))
  57755. location.copy(dir).multiplyScalar(distance).add(origin);
  57756. if(!onlyPos){
  57757. var pL = this.getNearbyPoint(origin, uv, -1, 0)
  57758. , pR = this.getNearbyPoint(origin, uv, 1, 0)
  57759. , pB = this.getNearbyPoint(origin, uv, 0, -1)
  57760. , pT = this.getNearbyPoint(origin, uv, 0, 1);
  57761. normal = this.planeFit(dir,location, pL,pR,pB,pT );
  57762. }
  57763. /* if(normal.x != normal.x ){
  57764. console.log('NAN', normal)
  57765. var pL = this.getNearbyPoint(origin, uv, -1, 0)
  57766. , pR = this.getNearbyPoint(origin, uv, 1, 0)
  57767. , pB = this.getNearbyPoint(origin, uv, 0, -1)
  57768. , pT = this.getNearbyPoint(origin, uv, 0, 1);
  57769. } */
  57770. //console.log(location, normal, distance)
  57771. return {location, normal, distance}
  57772. }
  57773. getNearbyPoint( origin, uv, x, y) { //获取附近的若干像素距离的点
  57774. let uv2 = uv.clone();
  57775. uv2.x += x/(this.canvas.width-1);
  57776. uv2.x = this.clampUV(uv2.x);
  57777. uv2.y += y/(this.canvas.height-1);
  57778. uv2.y = this.clampUV(uv2.y);
  57779. /* if(uv2.x < 0 || uv2.y < 0 || uv2.x > 1 || uv2.y > 1){
  57780. console.log('will nan')
  57781. } */
  57782. let dir = math.getDirFromUV(uv2);//从uv获取到方向
  57783. dir.applyMatrix4(viewer.images360.currentPano.panoMatrix2);
  57784. let depth = this.getDepth(uv2.x, uv2.y);
  57785. /* if(Math.abs(depth - this.mainDepth) > 0.3){
  57786. console.log('Math.abs(depth - this.mainDepth) > 0.3')
  57787. } */
  57788. //let dir = new THREE.Vector3().subVectors(intersect.point, origin).normalize()
  57789. let position = new Vector3().copy(dir).multiplyScalar(depth).add(origin);
  57790. //console.log('getNearbyPoint', uv2, depth, dir, position )
  57791. return position
  57792. }
  57793. clampUV(v){
  57794. return (v + 1) % 1; // 使输出在 0-1
  57795. }
  57796. planeFit(dir, position, pL,pR,pB,pT ) {//求平均法线
  57797. let normal = new Vector3;
  57798. let plane = new Plane;
  57799. function addNormal(p1, p2) {//根据临接的四个点,分别求法线,然后法线相加能得到平均法线
  57800. if(!p1 || !p2)return
  57801. plane.setFromCoplanarPoints(position, p1, p2);
  57802. //console.log('normalSub', plane.normal)
  57803. normal.addScaledVector(plane.normal, dir.dot(plane.normal) < 0 ? 1 : -1);//根据面的朝向判断加还是减
  57804. }
  57805. addNormal(pL, pB);
  57806. addNormal(pL, pT);
  57807. addNormal(pR, pB);
  57808. addNormal(pR, pT);
  57809. if(0 !== normal.x || 0 !== normal.y || 0 !== normal.z){
  57810. normal.normalize();
  57811. //console.log(normal)
  57812. return normal
  57813. }
  57814. /* 四个面拼成一个菱形 */
  57815. }
  57816. }
  57817. let {PanoSizeClass: PanoSizeClass$3,Vectors: Vectors$1,GLCubeFaces: GLCubeFaces$3, PanoramaEvents: PanoramaEvents$1} = Potree.defines;
  57818. var rot90$1 = new Quaternion().setFromAxisAngle(new Vector3(0,0,1), Math.PI/2 ); //使用的是刚好适合全景图的,给cube贴图需要转90°
  57819. let raycaster = new Raycaster();
  57820. //let currentlyHovered = null;
  57821. let texLoader$4 = new TextureLoader();
  57822. let addLine = (origin, dir, len, color='#fff') => {
  57823. var line1 = LineDraw.createLine([origin, origin.clone().add(dir.clone().multiplyScalar(len || 1))], { color });
  57824. //console.log(origin.toArray(), dir.toArray())
  57825. viewer.scene.scene.add(line1);
  57826. return line1
  57827. };
  57828. let tileArr = [];
  57829. let previousView = {
  57830. controls: null,
  57831. position: null,
  57832. target: null,
  57833. };
  57834. const HighMapCubeWidth = 1;
  57835. const directionFactor = 400; //原先10,几乎只往距离近的走了;设置太大容易略过近处漫游点走向下坡,因为鼠标一般在地面,下坡的漫游点更有利
  57836. class Images360 extends EventDispatcher{
  57837. constructor(viewer ){
  57838. super();
  57839. this.viewer = viewer;
  57840. this.panos = [];
  57841. this.neighbourMap = {};
  57842. this.node = new Object3D();
  57843. this.node.name = 'ImagesNode';
  57844. this.cubePanos = [];
  57845. this.fastTranMaskPass = new FastTranPass(viewer.renderer);
  57846. {
  57847. this.cube = new Mesh(new BoxBufferGeometry(1,1,1,1),new ModelTextureMaterial());
  57848. Potree.Utils.updateVisible(this.cube,'showSkybox', false );
  57849. this.cube.layers.set(Potree.config.renderLayers.skybox);
  57850. this.cube.name = 'skyboxCube';
  57851. viewer.scene.scene.add(this.cube);
  57852. }
  57853. if(Potree.settings.testCube){
  57854. this.cubeTest = this.cube.clone();
  57855. this.cubeTest.material = new MeshBasicMaterial({
  57856. wireframe:true,
  57857. color:'#FF3377',
  57858. transparent:true,
  57859. opacity:0.7,
  57860. depthWrite:false,
  57861. depthTest:false,
  57862. });
  57863. viewer.scene.scene.add(this.cubeTest);
  57864. this.cubeTest.visible = true;
  57865. }
  57866. this.flying_ = false;
  57867. this.currentPano = null;
  57868. this.mouseLastMoveTime = Date.now();
  57869. this.scrollZoomSpeed = 0.06;
  57870. this.zoomLevel = 1;
  57871. this.tileDownloader = new TileDownloader;
  57872. this.qualityManager = new QualityManager;
  57873. this.panoRenderer = new PanoRenderer(viewer, this.tileDownloader, this.qualityManager);
  57874. this.basePanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.BASE);
  57875. this.standardPanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.STANDARD);
  57876. this.highPanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.HIGH);
  57877. this.ultraHighPanoSize = this.qualityManager.getPanoSize(PanoSizeClass$3.ULTRAHIGH);
  57878. this.tileDownloader.processPriorityQueue = !1;
  57879. this.tileDownloader.tilePrioritizer = new TilePrioritizer(this.qualityManager, this.basePanoSize, this.standardPanoSize, this.highPanoSize, this.ultraHighPanoSize);
  57880. {//高分辨率cube 放大
  57881. this.addHighMapCube();
  57882. viewer.addEventListener(PanoramaEvents$1.Enter,(e)=>{
  57883. this.setHighMap(e.newPano);
  57884. });
  57885. viewer.addEventListener('panoSetZoom',(e)=>{
  57886. if(Potree.settings.displayMode == 'showPanos'){
  57887. e.zoomed ? this.showHighMap() : this.hideHighMap(); //add
  57888. }
  57889. });
  57890. }
  57891. this.depthSampler = new DepthImageSampler();
  57892. viewer.fpControls.addEventListener('dollyStopCauseUnable',(e)=>{
  57893. if(/* e.hoverViewport != viewer.mainViewport || */!Potree.settings.zoom.enabled)return
  57894. if(e.scale != void 0){//触屏
  57895. this.zoomBy(e.scale, e.pointer);
  57896. }else {//滚轮
  57897. let zoom;
  57898. if(e.delta > 0){
  57899. zoom = 1 + this.scrollZoomSpeed;
  57900. }else {
  57901. zoom = 1 - this.scrollZoomSpeed;
  57902. }
  57903. e.delta != 0 && this.zoomBy(zoom);
  57904. }
  57905. });
  57906. let click = (e) => {//不用"mouseup" 是因为 mouseup有drag object时也会触发
  57907. if(e.clickElement ||
  57908. Potree.settings.unableNavigate || this.flying || !e.isTouch && e.button != MOUSE.LEFT || e.drag && e.drag.object //拖拽结束时不算
  57909. || Potree.settings.editType == 'pano' && viewer.modules.PanoEditor.activeViewName != 'mainView'
  57910. || Potree.settings.editType == 'merge' && !e.intersectPoint || viewer.inputHandler.hoveredElements[0] && viewer.inputHandler.hoveredElements[0].isModel && e.intersectPoint.distance > viewer.inputHandler.hoveredElements[0].distance
  57911. ) return
  57912. if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
  57913. if( e.hoverViewport == viewer.mapViewer.viewports[0]){
  57914. return viewer.mapViewer.dispatchEvent(e/* {type:'global_click',e } */)
  57915. }else if(e.hoverViewport != viewer.mainViewport){ //如数据集校准其他viewport
  57916. return
  57917. }
  57918. }
  57919. if(!Potree.settings.dblToFocusPoint/* && this.currentPano */){//双击不会focus点云 或者 已经focusPano了
  57920. this.flyToPanoClosestToMouse();
  57921. }
  57922. };
  57923. viewer.addEventListener('global_click' , click);
  57924. viewer.addEventListener("global_mousemove", (e) => {
  57925. if(!Potree.settings.unableNavigate && Potree.settings.ifShowMarker && e.hoverViewport == viewer.mainViewport){//如果不显示marker,就在点击时再更新
  57926. this.updateClosestPano(e.intersect);
  57927. }
  57928. });
  57929. this.addEventListener('markerHover',(e)=>{
  57930. this.updateClosestPano(e.pano, e.hovered);
  57931. });
  57932. if(!Potree.settings.isOfficial){
  57933. this.domRoot = viewer.renderer.domElement.parentElement;
  57934. let elUnfocus = $("<input type='button' value='unfocus'></input>");
  57935. elUnfocus.css({
  57936. position : "absolute",
  57937. right : '25%',
  57938. bottom: '20px',
  57939. zIndex: "10000",
  57940. fontSize:'1em', color:"black",
  57941. display:'none',
  57942. background:'rgba(255,255,255,0.8)',
  57943. });
  57944. elUnfocus.on("click", () => this.unfocus());
  57945. this.elUnfocus = elUnfocus;
  57946. this.domRoot.appendChild(elUnfocus[0]);
  57947. if(Potree.settings.editType != 'merge'){
  57948. let elHide = $("<input type='button' value='隐藏点云'></input>");
  57949. elHide.css({
  57950. position : "absolute",
  57951. right : '40%',
  57952. bottom: '20px',
  57953. zIndex: "10000",
  57954. fontSize:'1em' ,color:"black",
  57955. width : '100px',
  57956. background:'rgba(255,255,255,0.8)',
  57957. });
  57958. this.domRoot.appendChild(elHide[0]);
  57959. elHide.on("click", (e) => {
  57960. let visi = Potree.Utils.getObjVisiByReason(viewer.scene.pointclouds[0], 'force');
  57961. viewer.scene.pointclouds.forEach(e=>{
  57962. Potree.Utils.updateVisible(e, 'force', !visi);
  57963. });
  57964. elHide.val(!visi ? "隐藏点云" : "显示点云");
  57965. });
  57966. }
  57967. let elDisplayModel = $("<input type='button' value='>>全景'></input>");
  57968. elDisplayModel.css({
  57969. position : "absolute",
  57970. right : '65%',
  57971. bottom: '20px',
  57972. zIndex: "10000",
  57973. fontSize:'1em',color:"black",
  57974. width : '100px',
  57975. background:'rgba(255,255,255,0.8)',
  57976. });
  57977. this.domRoot.appendChild(elDisplayModel[0]);
  57978. elDisplayModel.on("click", (e) => {
  57979. if(Potree.settings.displayMode == 'showPointCloud' && this.panos.length == 0)return
  57980. Potree.settings.displayMode = Potree.settings.displayMode == 'showPointCloud' ? 'showPanos' : 'showPointCloud';
  57981. });
  57982. this.elDisplayModel = elDisplayModel;
  57983. if(viewer.mapViewer){
  57984. let mapStyleBtn = $("<input type='button' value='普通'></input>");
  57985. mapStyleBtn.css({
  57986. position : "absolute",
  57987. right : '50%',
  57988. bottom: '20px',
  57989. zIndex: "10000",
  57990. fontSize:'1em' ,color:"black",
  57991. width : '100px',
  57992. background:'rgba(255,255,255,0.8)',
  57993. });
  57994. this.domRoot.appendChild(mapStyleBtn[0]);
  57995. let map = viewer.mapViewer.mapLayer.maps.find(e=>e.name == 'map');
  57996. mapStyleBtn.on("click", (e) => {
  57997. map.switchStyle(map.style == 'satellite' ? 'standard' : 'satellite');
  57998. mapStyleBtn.val(map.style == 'satellite' ? '卫星' : '普通');
  57999. });
  58000. }
  58001. }
  58002. {//切换模式
  58003. let displayMode = '';
  58004. this.latestRequestMode = '';//因为可能延迟,所以记录下每次的请求模式,延迟后判断这个
  58005. Object.defineProperty(Potree.settings , "displayMode",{
  58006. get: function() {
  58007. return displayMode
  58008. },
  58009. set: (mode)=> {
  58010. this.latestRequestMode = mode;
  58011. console.warn('Request setMode: ' + mode);
  58012. this.dispatchEvent({type:'requestMode',mode});
  58013. let config2;
  58014. let config = Potree.config.displayMode[mode];
  58015. if(this.isAtPano() && !this.latestToPano){
  58016. config2 = config.atPano;
  58017. }else {
  58018. config2 = config.transition;
  58019. }
  58020. let changeTileDownload = ()=>{
  58021. if(config2.showSkybox || config2.showPoint && config2.pointUsePanoTex){
  58022. this.tileDownloader.start();
  58023. this.currentPano && this.currentPano.enter();
  58024. }else {
  58025. this.tileDownloader.stop();
  58026. this.currentPano && this.currentPano.exit();
  58027. this.nextPano && (viewer.cancelLoad(this.nextPano));
  58028. }
  58029. };
  58030. if(mode != displayMode){
  58031. let camera = viewer.scene.getActiveCamera();
  58032. if(mode == 'showPanos' && viewer.mainViewport.view.isFlying()){//飞完才能切换全景
  58033. let f = ()=>{
  58034. if(this.latestRequestMode == mode){//如果ui还是停在这个模式的话
  58035. Potree.settings.displayMode = mode;
  58036. }
  58037. viewer.mainViewport.view.removeEventListener('flyingDone', f);
  58038. };
  58039. viewer.mainViewport.view.addEventListener('flyingDone', f); //once
  58040. return
  58041. }
  58042. if(this.isAtPano() && !this.latestToPano){
  58043. config2 = config.atPano;
  58044. }else {
  58045. config2 = config.transition;
  58046. if(mode == 'showPanos'){//自动飞入一个pano
  58047. //要改成飞进最近的。。。
  58048. if(this.panos.length == 0)return
  58049. //this.modeChanging = true //主要是因为到全景图不会立刻成功
  58050. let wait = (e)=>{
  58051. console.log('flyToPanoDone');
  58052. this.removeEventListener('flyToPanoDone',wait);
  58053. setTimeout(()=>{
  58054. if(this.latestRequestMode == mode ){
  58055. Potree.settings.displayMode = mode;
  58056. }
  58057. },e.makeIt ? 1 : 50);
  58058. };
  58059. this.addEventListener('flyToPanoDone',wait); //等待飞行完毕。flyToPano的callback可能不执行所以换这个。但也可能被cancel
  58060. this.flyToPano({
  58061. pano: this.findNearestPano(),
  58062. //dealDoneWhenCancel:true,
  58063. /* callback: ()=>{
  58064. setTimeout(()=>{ //防止循环,所以延迟
  58065. if(this.latestRequestMode == mode ){
  58066. Potree.settings.displayMode = mode
  58067. }
  58068. },1)
  58069. } */
  58070. });
  58071. return;
  58072. }else {
  58073. }
  58074. }
  58075. changeTileDownload();
  58076. if(config2.showSkybox || config2.pointUsePanoTex){
  58077. let wait = ( )=> {
  58078. //console.log('waitdone')
  58079. //if(e.pano && e.pano != this.currentPano)return //loadedDepthImg
  58080. setTimeout( ()=>{
  58081. if(this.latestRequestMode == mode ){
  58082. Potree.settings.displayMode = mode;
  58083. }
  58084. },1);
  58085. };
  58086. //this.updateDepthTex()
  58087. if(this.checkAndWaitForPanoLoad(this.currentPano, this.basePanoSize, wait)){
  58088. //console.log('等待贴图加载2', this.currentPano.id)
  58089. return
  58090. }
  58091. }
  58092. viewer.scene.pointclouds.forEach(e=>{
  58093. Potree.Utils.updateVisible(e, 'displayMode', config2.showPoint, 2 );
  58094. });
  58095. if(config2.pointUsePanoTex){
  58096. viewer.scene.pointclouds.forEach(e=>{
  58097. e.material.setProjectedPanos(this.currentPano,this.currentPano, 1);
  58098. });
  58099. }else {
  58100. viewer.scene.pointclouds.forEach(e=>{
  58101. e.material.stopProjectedPanos();
  58102. });
  58103. }
  58104. Potree.Utils.updateVisible(this.cube,'showSkybox',config2.showSkybox );// this.cube.visible = config2.showSkybox
  58105. //this.cube.visible = config.atPano.showSkybox
  58106. if(this.cube.visible){
  58107. //this.cube.material.setProjectedPanos(this.currentPano, this.currentPano, 1)
  58108. this.setProjectedPanos({
  58109. progress:1,
  58110. ifSkybox: true,
  58111. ifPointcloud : false,
  58112. easeInOutRatio : 0,
  58113. pano0:this.currentPano,
  58114. pano1:this.currentPano
  58115. });
  58116. }else {
  58117. this.smoothZoomTo(1);
  58118. this.resetHighMap();
  58119. this.hideHighMap();
  58120. }
  58121. /* viewer.dispatchEvent({
  58122. type: "enableChangePos",
  58123. canLeavePano : config.canLeavePano ,
  58124. viewport:
  58125. }) */
  58126. //viewer.mainViewport.unableChangePos = !config.canLeavePano
  58127. displayMode = mode;
  58128. if(mode == 'showPanos'){
  58129. camera.far = viewer.farWhenShowPano; //修改far
  58130. Potree.settings.pointDensity = 'panorama';
  58131. if(Potree.config.displayMode.showPanos.transition.pointUsePanoTex){
  58132. viewer.scene.pointclouds.forEach(e=>{
  58133. e.material.pointSizeType = 'FIXED';
  58134. });
  58135. }
  58136. this.updateCube(this.currentPano);
  58137. }else {
  58138. if(camera.limitFar) camera.far = Potree.settings.cameraFar;//修改far
  58139. Potree.settings.pointDensity = Potree.settings.UserPointDensity;
  58140. //Potree.sdk && Potree.sdk.scene.changePointOpacity()
  58141. if(Potree.config.displayMode.showPanos.transition.pointUsePanoTex){
  58142. viewer.scene.pointclouds.forEach(e=>{
  58143. e.material.pointSizeType = Potree.config.material.pointSizeType;
  58144. });
  58145. }
  58146. }
  58147. camera.updateProjectionMatrix();
  58148. if(this.elDisplayModel){
  58149. this.elDisplayModel.val( mode == 'showPointCloud' ? ">>全景" : '>>点云');
  58150. }
  58151. /* this.panos.forEach(e=>{
  58152. Potree.Utils.updateVisible(e, 'modeIsShowPanos', mode == 'showPanos', 1, mode == 'showPanos' ? 'add':'cancel') //
  58153. }) */
  58154. this.dispatchEvent({type:'endChangeMode',mode});
  58155. console.log('setModeSuccess: ' + mode);
  58156. }else {
  58157. changeTileDownload();
  58158. //this.dispatchEvent({type:'endChangeMode',mode})
  58159. }
  58160. }
  58161. });
  58162. Potree.settings.displayMode = 'showPointCloud';
  58163. }// 切换模式 end
  58164. {//
  58165. let currentPano = null;
  58166. Object.defineProperty(this , "currentPano",{
  58167. get: function() {
  58168. return currentPano
  58169. },
  58170. set: function(e) {
  58171. if(e != currentPano){
  58172. //console.log('set currentPano ', e.id)
  58173. currentPano && currentPano.exit();
  58174. e && e.enter();
  58175. currentPano = e;
  58176. }
  58177. }
  58178. });
  58179. }
  58180. {//是否显示marker
  58181. let ifShowMarker = true;
  58182. Object.defineProperty(Potree.settings, "ifShowMarker",{
  58183. get: function() {
  58184. return ifShowMarker
  58185. },
  58186. set: (show)=>{
  58187. show = !!show;
  58188. if(show != ifShowMarker){
  58189. this.panos.forEach(pano=>{
  58190. Potree.Utils.updateVisible(pano, 'ifShowMarker', show, 1 );
  58191. });
  58192. //this.emit('markersDisplayChange', show)
  58193. ifShowMarker = show;
  58194. viewer.dispatchEvent('showMarkerChanged');
  58195. viewer.dispatchEvent('content_changed');
  58196. }
  58197. }
  58198. });
  58199. }
  58200. viewer.addEventListener("update", () => {
  58201. this.update(viewer);
  58202. });
  58203. //viewer.inputHandler.addInputListener(this);
  58204. var keys = {
  58205. FORWARD: ['W'.charCodeAt(0), 38],
  58206. BACKWARD: ['S'.charCodeAt(0), 40],
  58207. LEFT: ['A'.charCodeAt(0), 37],
  58208. RIGHT: ['D'.charCodeAt(0), 39],
  58209. };
  58210. viewer.inputHandler.addEventListener('keydown',(e)=>{
  58211. if(Potree.settings.displayMode == 'showPanos'){
  58212. for(let i in keys){
  58213. if(keys[i].some(a => a == e.keyCode)){
  58214. switch(i){
  58215. case 'FORWARD':
  58216. this.flyLocalDirection(Vectors$1.FORWARD.clone());
  58217. break;
  58218. case 'BACKWARD':
  58219. this.flyLocalDirection(Vectors$1.BACK.clone());
  58220. break;
  58221. case 'LEFT':
  58222. this.flyLocalDirection(Vectors$1.LEFT.clone());
  58223. break;
  58224. case 'RIGHT':
  58225. this.flyLocalDirection(Vectors$1.RIGHT.clone());
  58226. break;
  58227. }
  58228. break;
  58229. }
  58230. }
  58231. }
  58232. });
  58233. };
  58234. updateDepthTex(pano){
  58235. if(this.currentPano != pano || !pano.depthTex)return
  58236. //this.depthSampler.changeImg(pano.depthTex.image); //pick sampler要飞到了才能切换图,而skybox贴图是随着全景图切换而切换的
  58237. this.cube.material.updateDepthTex(pano); //确保一下
  58238. }
  58239. findNearestPano(pos){
  58240. pos = pos ? new Vector3().copy(pos) : this.position;
  58241. let result = Common.sortByScore(this.panos,[Images360.filters.isEnabled()],[e=>-e.position.distanceTo(pos)]);
  58242. let pano = result[0] && result[0].item;
  58243. return pano
  58244. }
  58245. /* set flying(v){//正在飞向pano
  58246. this.flying_ = !!v
  58247. //console.log('this.flying_ ', !!v )
  58248. //this.emit('flying', this.flying_)
  58249. let config = Potree.config.displayMode[Potree.settings.displayMode]
  58250. viewer.mainViewport.unableChangePos = !config.canLeavePano || !!v
  58251. }
  58252. get flying(){
  58253. return this.flying_
  58254. } */
  58255. flyLocalDirection(dir) {
  58256. var direction = this.getDirection(dir),
  58257. option1 = 1 === dir.y ? .4 : .75,
  58258. option2 = 1 === Math.abs(dir.x);
  58259. return this.flyDirection(direction, option1, option2, true)
  58260. }
  58261. getDirection(e) {
  58262. if(!e){
  58263. return viewer.scene.view.direction
  58264. }else {
  58265. return e = e ? e : (new Vector3).copy(Vectors$1.FORWARD),
  58266. e.applyQuaternion(viewer.mainViewport.camera.quaternion)
  58267. }
  58268. }
  58269. get position(){
  58270. return this.viewer.scene.view.position.clone()
  58271. }
  58272. isAtPano(precision){//是否在某个漫游点上
  58273. if(precision){
  58274. return this.currentPano && math.closeTo(viewer.scene.view.position, this.currentPano.position, precision)
  58275. }
  58276. return this.currentPano && viewer.scene.view.position.equals(this.currentPano.position)
  58277. }
  58278. updateProjectedPanos(){//更新材质贴图
  58279. //console.warn('updateProjectedPanos')
  58280. this.projectedPano0 && this.projectedPano1 && this.setProjectedPanos({pano0:this.projectedPano0, pano1:this.projectedPano1});
  58281. }
  58282. setProjectedPanos(o={}){//设置cube和点云的材质贴图
  58283. this.cube.material.setProjectedPanos(o.pano0, o.pano1, o.progress);
  58284. if(o.ifPointcloud){
  58285. viewer.scene.pointclouds.forEach(e=>{
  58286. e.material.setProjectedPanos(o.pano0, o.pano1, o.progress, o.easeInOutRatio);
  58287. });
  58288. }
  58289. //console.warn('setProjectedPanos ', o.pano0.id , o.pano1.id)
  58290. this.projectedPano0 = o.pano0;
  58291. this.projectedPano1 = o.pano1;
  58292. }
  58293. cancelFlyToPano(toPano){//取消当前已有的飞行准备,前提是相机还未移动
  58294. if(viewer.mainViewport.view.isFlying() || toPano && this.latestToPano != toPano)return
  58295. //Potree.Log('cancelFlyToPano', this.latestToPano && this.latestToPano.pano.id)
  58296. this.nextPano = null;
  58297. this.latestToPano = null;
  58298. }
  58299. flyToPano(toPano) { //飞向漫游点
  58300. if(!toPano)return
  58301. if(typeof toPano == 'number')toPano = this.panos[toPano];
  58302. if(toPano instanceof Panorama){
  58303. toPano = {pano: toPano};
  58304. }
  58305. let done = (makeIt, disturb)=>{
  58306. //console.log('flyToPano done ', toPano.pano.id, makeIt, disturb )
  58307. if(makeIt || disturb) { // disturb已经开始飞行但中途取消
  58308. toPano.callback && toPano.callback(makeIt);
  58309. //this.flying = false
  58310. this.cancelFlyToPano(toPano);
  58311. this.updateClosestPano(this.closestPano,false); //飞行结束后取消点击漫游点时得到的closestPano
  58312. }else {
  58313. }
  58314. this.dispatchEvent({type:'flyToPanoDone', makeIt, disturb});
  58315. this.fastTranMaskPass.stop();
  58316. toPano.deferred && toPano.deferred.resolve(makeIt); //测量线截图时发现,resolve需要写在flying=false 后才行。
  58317. };
  58318. if(!toPano.pano.enabled)return done(false,true);
  58319. //Potree.Log('hope flyToPano: '+toPano.pano.id, toPano.pano.position.toArray() )
  58320. if(this.latestToPano && this.latestToPano != toPano && (//还在飞
  58321. this.latestToPano.pano != this.currentPano || !this.isAtPano())){//如果旧的toPano只在pano旋转镜头,就直接取消旧的,继续执行
  58322. return done(false)
  58323. }
  58324. if(this.currentPano == toPano.pano && this.isAtPano() && !toPano.target && !toPano.quaternion ){
  58325. //已在该pano
  58326. this.dispatchEvent({type:'flyToPano', toPano});
  58327. return done(true);
  58328. }
  58329. //Potree.Log('flyToPano: '+toPano.pano.id, toPano.pano.position.toArray() /* this.latestToPano && this.latestToPano.pano.id */ )
  58330. let target = toPano.target;
  58331. let config = Potree.config.displayMode[Potree.settings.displayMode];
  58332. let pano = toPano.pano;
  58333. let dis = pano.position.distanceTo(this.position);
  58334. this.nextPano = pano;
  58335. this.latestToPano = toPano;
  58336. //this.flying = true //防止新的请求
  58337. //Potree.Log('flyToPano:'+pano.id + ' , duration:'+toPano.duration, null, 12)
  58338. {//不飞的话是否不要执行这段?
  58339. let wait = (e)=> {
  58340. //console.log('wait done', pano.id)
  58341. if(/* e.pano && */this.latestToPano && pano != this.latestToPano.pano)return//loadedDepthImg
  58342. if(this.latestToPano != toPano)return Potree.Log('已经取消', pano.id) //如果取消了
  58343. setTimeout(()=>{
  58344. if(this.latestToPano != toPano)return
  58345. this.flyToPano(toPano);
  58346. },1);
  58347. };
  58348. if(!pano.depthTex && pano.pointcloud.hasDepthTex){ //点云模式也要加载depthTex,因获取neighbour需要用到
  58349. console.log('等待加载depthtex', pano.id);
  58350. pano.addEventListener('loadedDepthImg', wait, {once:true});
  58351. return pano.loadDepthImg()
  58352. }
  58353. if(config.atPano.showSkybox || config.atPano.pointUsePanoTex){
  58354. let a = this.updateCube(this.currentPano, toPano.pano);
  58355. if(a == 'useBound'){
  58356. toPano.useBound = true;
  58357. }
  58358. if(this.checkAndWaitForPanoLoad(pano, toPano.basePanoSize || this.basePanoSize, wait )){
  58359. //console.log('等待贴图加载',pano.id)
  58360. return
  58361. }
  58362. }
  58363. }
  58364. config = Potree.config.displayMode[Potree.settings.displayMode]; //可能换了
  58365. let pointcloudVisi = config.atPano.showPoint; //viewer.scene.pointclouds[0].visible
  58366. Potree.Utils.updateVisible(this.cube,'showSkybox', config.atPano.showSkybox ); // this.cube.visible = config.atPano.showSkybox
  58367. //console.log('开始飞1')
  58368. if(config.transition.showPoint){
  58369. viewer.scene.pointclouds.forEach(e=>{
  58370. Potree.Utils.updateVisible(e, 'displayMode', true);
  58371. });
  58372. }
  58373. const endPosition = pano.position.clone();
  58374. let T = Potree.config.transitionsTime;
  58375. /* let maxTime = this.isAtPano() ? T.panoToPanoMax : T.flyIn
  58376. let duration = toPano.duration == void 0 ? (T.flyMinTime+Math.min(T.flytimeDistanceMultiplier * dis, maxTime)) : toPano.duration
  58377. */
  58378. /* let maxDis = this.isAtPano() ? T.maxDistanceThreshold : T.maxDistanceThresholdFlyIn
  58379. let duration = toPano.duration == void 0 ? Math.min(dis, T.maxDistanceThreshold) * T.flytimeDistanceMultiplier + T.flyMinTime : toPano.duration
  58380. */
  58381. let maxDis = 7;
  58382. let duration = toPano.duration == void 0 ? Math.min(dis, maxDis) * T.flytimeDistanceMultiplier + T.flyMinTime : toPano.duration;
  58383. if(config.transition.showSkybox || config.transition.pointUsePanoTex){
  58384. if(Potree.settings.fastTran ){
  58385. this.fastTranMaskPass.start(); //截图当前画面
  58386. viewer.scene.view.position.copy(endPosition);
  58387. }
  58388. this.setProjectedPanos({
  58389. progress: 0,
  58390. ifSkybox: this.cube.visible,
  58391. ifPointcloud : config.transition.pointUsePanoTex,
  58392. easeInOutRatio : pointcloudVisi ? 0.3 : 0,
  58393. pano0:this.currentPano,
  58394. pano1:pano
  58395. });
  58396. }
  58397. if(toPano.useBound){
  58398. duration = Math.min(1500, duration);
  58399. toPano.easeName = 'easeInOutQuad';
  58400. }else {
  58401. if(endPosition.equals(this.position))toPano.easeName = 'easeOutSine';
  58402. }
  58403. {
  58404. toPano.easeName = toPano.easeName || 'linearTween';
  58405. toPano.duration = duration;
  58406. this.beforeFlyToPano(toPano);
  58407. }
  58408. /* let fly = ()=>{
  58409. this.dispatchEvent({type:'flyToPano', toPano})
  58410. viewer.scene.view.setView({position:endPosition, target, quaternion:toPano.quaternion , duration,
  58411. callback:()=>{
  58412. if(!config.atPano.pointUsePanoTex){
  58413. viewer.scene.pointclouds.forEach(e=>{
  58414. e.material.stopProjectedPanos()
  58415. })
  58416. }
  58417. this.currentPano = pano;
  58418. this.nextPano = null;
  58419. if(Potree.settings.displayMode == 'showPanos'){
  58420. viewer.scene.pointclouds.forEach(e=>{
  58421. Potree.Utils.updateVisible(e, 'displayMode',pointcloudVisi)
  58422. })
  58423. }
  58424. done(true);
  58425. this.updateDepthTex(this.currentPano)
  58426. }, onUpdate:(progress)=>{
  58427. //console.log('uniforms progress',progress)
  58428. this.cube.material.uniforms.progress.value = progress
  58429. viewer.scene.pointclouds.forEach(e=>{
  58430. e.material.uniforms.progress.value = progress
  58431. })
  58432. },
  58433. cancelFun:()=>{ done(false, true) },
  58434. Easing:easeName
  58435. })
  58436. //duration > 0 && (this.flying = true) //再写一遍 防止cancel其他项目导致flying为false
  58437. } */
  58438. let onUpdate = (progress)=>{
  58439. this.cube.material.uniforms.progress.value = progress;
  58440. viewer.scene.pointclouds.forEach(e=>{
  58441. e.material.uniforms.progress.value = progress;
  58442. });
  58443. };
  58444. let fly = ()=>{
  58445. let startProgress = toPano.progress = toPano.progress || 0;
  58446. let loadNextProgress = MathUtils.clamp(1 - 2.5 / dis, 0.3, 0.8);
  58447. //console.log(loadNextProgress, (1-loadNextProgress) * dis )
  58448. this.dispatchEvent({type:'flyToPano', toPano});
  58449. viewer.scene.view.setView({position:endPosition, target, quaternion:toPano.quaternion , duration:toPano.duration,
  58450. onUpdate:(progress_, delta)=>{
  58451. let progress = startProgress + progress_ * (1 - startProgress);
  58452. let currentSpeed;
  58453. if (progress_ != 1 && progress_ != 0) { // 1的时候不准,往往偏小, 0的时候速度为0,也不记录
  58454. currentSpeed = ((progress - toPano.progress) * dis) / delta; //记录下当前速度,当变为匀速时可以过渡到flySpeed
  58455. } else {
  58456. currentSpeed = toPano.currentSpeed || 0;
  58457. }
  58458. toPano.currentSpeed = currentSpeed;
  58459. toPano.progress = progress;
  58460. //console.log('progress_', progress_, 'delta',delta , 'progress', progress/*, 'currentSpeed', currentSpeed, */ )
  58461. if (progress > loadNextProgress && toPano.easeName == 'linearTween' && currentSpeed){// 减速. 如果仅旋转就不停止
  58462. //console.log('减速', /* currentSpeed , */progress_ )
  58463. toPano.easeName = 'easeOutSine';
  58464. let restDis = (1 - progress) * dis;
  58465. toPano.duration = (Math.PI / 2 * restDis) / currentSpeed; // 这样能保证初始速度为currentSpeed
  58466. viewer.scene.view.cancelFlying('all',false); //为了防止执行cancelFun先主动cancel
  58467. toPano.flyCount = 2;
  58468. fly(toPano);
  58469. }
  58470. onUpdate(progress);
  58471. },
  58472. callback:()=>{
  58473. if(!config.atPano.pointUsePanoTex){
  58474. viewer.scene.pointclouds.forEach(e=>{
  58475. e.material.stopProjectedPanos();
  58476. });
  58477. }
  58478. this.lastPano = this.currentPano; //记录,调试
  58479. this.currentPano = pano;
  58480. this.nextPano = null;
  58481. if(Potree.settings.displayMode == 'showPanos'){
  58482. viewer.scene.pointclouds.forEach(e=>{
  58483. Potree.Utils.updateVisible(e, 'displayMode',pointcloudVisi);
  58484. });
  58485. }
  58486. done(true);
  58487. this.updateDepthTex(this.currentPano); //删除dispose的depthTex
  58488. },
  58489. cancelFun:()=>{ done(false, true); },
  58490. Easing:toPano.easeName,
  58491. ignoreFirstFrame : toPano.flyCount != 2 //变换transition时不停一帧
  58492. });
  58493. };
  58494. if(Potree.settings.displayMode == 'showPanos'){
  58495. setTimeout(fly, 40); //更新geo后缓冲
  58496. }else {
  58497. fly();
  58498. }
  58499. //console.log('flyToPano:', toPano.pano.id)
  58500. }
  58501. beforeFlyToPano(toPano){
  58502. if(this.currentPano != toPano.pano) {
  58503. if(Potree.settings.displayMode == 'showPanos'){
  58504. this.resetHighMap();
  58505. }
  58506. this.smoothZoomTo(toPano.zoomLevel || 1, toPano.duration / 2);
  58507. }
  58508. }
  58509. /* updateCube(pano0, pano1){
  58510. if(Potree.settings.displayMode != 'showPanos')return
  58511. if(!viewer.scene.pointclouds.some(e=>!e.hasDepthTex)) return this.updateCube2(pano0, pano1) //都hasDepthTex的话
  58512. let useBound = (bound, size)=>{
  58513. size = size || bound.getSize(new THREE.Vector3)
  58514. let center = bound.getCenter(new THREE.Vector3)
  58515. size.max(new THREE.Vector3(HighMapCubeWidth,HighMapCubeWidth,HighMapCubeWidth))
  58516. this.cube.scale.copy(size)
  58517. this.cube.position.copy(center)
  58518. }
  58519. let getPanoBound = (pano)=>{//因漫游点可能在点云外部,如室外平地,所以需要union进漫游点
  58520. let panoBound = new THREE.Box3
  58521. panoBound.expandByPoint(pano.position)
  58522. panoBound.expandByVector(new THREE.Vector3(10,10,10));//give pano a margin
  58523. return pano.pointcloud.bound.clone().union(panoBound)
  58524. }
  58525. let getDis = (bound1, bound2)=>{ //获取bound1边界到bound2边界距离
  58526. if(bound1.intersectsBox(bound2))return 0
  58527. let center1 = bound1.getCenter(new THREE.Vector3)
  58528. let center2 = bound2.getCenter(new THREE.Vector3)
  58529. let dis = center1.distanceTo(center2)
  58530. let dis1 = bound1.distanceToPoint(center2)
  58531. let dis2 = bound2.distanceToPoint(center1)
  58532. return dis1 + dis2 - dis
  58533. }
  58534. if(pano1){//过渡
  58535. if(pano0.pointcloud == pano1.pointcloud){//同一个数据集内的过渡
  58536. useBound(getPanoBound(pano0))
  58537. }else{//非同一个数据集内的过渡
  58538. let bound = getPanoBound(pano0).union(getPanoBound(pano1))
  58539. if(getDis(pano0.pointcloud.bound, pano1.pointcloud.bound) < 100){
  58540. useBound(bound)
  58541. }else{//如果两个数据集boundingbox距离大于这个距离,扩大一下,防止精度问题导致失真//对很远的数据集似乎没有什么用
  58542. let size = bound.getSize(new THREE.Vector3)
  58543. let max = Math.max(size.x, size.y, size.z)
  58544. size.set(max,max,max)
  58545. useBound(pano0.pointcloud.bound.clone().union(pano1.pointcloud.bound), size)
  58546. }
  58547. }
  58548. }else{
  58549. useBound(getPanoBound(pano0)) //假定一个数据集不会太大,否则会造成失真,且bump时移动距离看起来很小。或者可以考虑用固定大小
  58550. }
  58551. } */
  58552. getIntersect(pano, dir, origin){
  58553. if(pano && pano.pointcloud.hasDepthTex ){
  58554. return this.depthSampler.sample( {dir }, pano, true )
  58555. }else {
  58556. origin = origin || pano.position;
  58557. return viewer.inputHandler.getIntersect({
  58558. viewport:viewer.inputHandler.hoverViewport,
  58559. onlyGetIntersect:true, usePointcloud:true,
  58560. point: origin.clone().add(dir),
  58561. cameraPos: origin
  58562. })
  58563. }
  58564. }
  58565. /* updateCube(pano0, pano1){//增加细分的版本,且垂直方向上也分多个
  58566. if(Potree.settings.displayMode != 'showPanos')return
  58567. console.log('updateCube',pano0.id, pano1&&pano1.id)
  58568. let f = (bound, size)=>{
  58569. size = size || bound.getSize(new THREE.Vector3)
  58570. let center = bound.getCenter(new THREE.Vector3)
  58571. size.max(new THREE.Vector3(HighMapCubeWidth,HighMapCubeWidth,HighMapCubeWidth))
  58572. this.cube.scale.copy(size)
  58573. this.cube.position.copy(center)
  58574. }
  58575. this.cube.geometry.dispose();
  58576. if(pano1){//过渡
  58577. let count1, count2;
  58578. let panoIndex = 0
  58579. let add = (pano, dir )=>{
  58580. let getPI = function(index, panoIndex_){
  58581. if(panoIndex_ == void 0) panoIndex_ = panoIndex
  58582. return (count1 * count2 + 2 ) * panoIndex_ + index + 2
  58583. }
  58584. let minZ, maxZ
  58585. minZ = pano.floorPosition.z
  58586. {//天花板高度值
  58587. //用三个间隔120度散开,和中心垂直线成一定夹角的三个向量去求 最高高度 (不求平均的原因:万一是0不好算)
  58588. let rotMat = new THREE.Matrix4().makeRotationX(THREE.Math.degToRad(40))// 角度不能小于天花板中空的半径,大概就是0.2*Math.PI=36度
  58589. let dir1 = new THREE.Vector3(0,0,1).applyMatrix4(rotMat)
  58590. let rotMat1 = new THREE.Matrix4().makeRotationZ(Math.PI*2 / 3);
  58591. let rotMat2 = new THREE.Matrix4().makeRotationZ(-Math.PI*2 / 3);
  58592. let dir2 = dir1.clone().applyMatrix4(rotMat1)
  58593. let dir3 = dir1.clone().applyMatrix4(rotMat2)
  58594. let zs = [dir1,dir2,dir3].map(dir_=>{
  58595. let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
  58596. let z = intersect ? intersect.location.z : pano.position.z
  58597. return z
  58598. })
  58599. zs.sort((a,b)=>{return b-a});//得最大值
  58600. maxZ = zs[0]
  58601. let min = pano.position.z + 1
  58602. if(maxZ < pano.position.z + 0.04){//户外
  58603. maxZ = pano.position.z + 50
  58604. }
  58605. maxZ = Math.max(min,maxZ)
  58606. console.log(pano.id, 'maxZ:',maxZ )
  58607. console.log(pano.id, 'minZ:',minZ )
  58608. }
  58609. [maxZ, minZ ].forEach(z=>{
  58610. posArr.push(pano.position.clone().setZ(z))
  58611. })
  58612. const angle = Math.PI/8
  58613. let getDir = (angle_)=>{
  58614. let rotMat = new THREE.Matrix4().makeRotationZ(angle_)
  58615. return dir.clone().applyMatrix4(rotMat)
  58616. }
  58617. 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度
  58618. count1 = dirs.length
  58619. dirs.forEach((dir, index)=>{//获取在这个方向上和墙体intersect的最远距离,使用中、上、下三个方向
  58620. let dirs_ = [
  58621. dir.clone().setZ(Math.tan(THREE.Math.degToRad(30))).normalize(),
  58622. dir.clone().setZ(Math.tan(THREE.Math.degToRad(15))).normalize(),
  58623. dir.clone(), // 水平方向
  58624. dir.clone().setZ(-Math.tan(THREE.Math.degToRad(15))).normalize(),
  58625. dir.clone().setZ(-Math.tan(THREE.Math.degToRad(30))).normalize(),
  58626. ];
  58627. count2 = dirs_.length
  58628. dirs_.forEach((dir_, i) =>{
  58629. let intersect = this.depthSampler.sample( {dir: dir_}, pano, true )
  58630. let location
  58631. if(!intersect){ //超级远
  58632. let distance = 100
  58633. location = dir_.clone().multiplyScalar(distance).add(pano.position)
  58634. intersect = {distance,location}
  58635. }
  58636. //intersect.distance
  58637. location = intersect.location.clone()
  58638. let shouldZ// = THREE.Math.clamp(intersect.location.z, minZ, maxZ);
  58639. let needShrink = false
  58640. if(i == 0){//最上方的点高度直接等于天花板
  58641. shouldZ = maxZ
  58642. if(location.z<maxZ)location.z = maxZ
  58643. else needShrink = true
  58644. }else if(i == count2-1){//最下方的点高度直接等于地板
  58645. shouldZ = minZ
  58646. if(location.z>minZ)location.z = minZ
  58647. else needShrink = true
  58648. }
  58649. if(needShrink ){//需要在保持dir_不变的情况下修改z
  58650. let len = (shouldZ - pano.position.z) / (intersect.location.z - pano.position.z) * intersect.distance
  58651. location = dir_.clone().multiplyScalar(len).add(pano.position)
  58652. }
  58653. posArr.push(location)
  58654. if(index!=0 && i!=0){//加入一块四方面
  58655. let curIndex = getPI(count2 * index + i);
  58656. faceArr.push([curIndex-1, curIndex-count2-1, curIndex-count2],
  58657. [curIndex-1, curIndex, curIndex-count2])
  58658. }
  58659. })
  58660. if(index!=0){
  58661. let top = -2;
  58662. let btm = -1
  58663. faceArr.push([getPI(count2*(index-1) ), getPI(count2*index ), getPI(top) ])//天花板扇形
  58664. faceArr.push([getPI(count2*index-1), getPI(count2*(index+1)-1), getPI(btm) ] )//地板扇形
  58665. }else{
  58666. //加入和另一个pano连接的其中一个侧边
  58667. let panoIndex2 = (panoIndex + 1) % 2;
  58668. for(let i=1;i<count2;i++){
  58669. faceArr.push([getPI(i-1), getPI(i), getPI((count1-1)*count2 +i, panoIndex2)],
  58670. [getPI(i-1), getPI((count1-1)*count2+i , panoIndex2) , getPI((count1-1)*count2+i-1 ,panoIndex2)])
  58671. }
  58672. faceArr.push([getPI(0), getPI((count1-1)*count2), getPI(0, panoIndex2)])//加入顶部的一半
  58673. faceArr.push([getPI(count2-1), getPI(count1*count2-1), getPI(count2-1, panoIndex2)])//加入底部的一半
  58674. }
  58675. });
  58676. panoIndex ++
  58677. }
  58678. let posArr = [];
  58679. let faceArr = []
  58680. //两点连线的水平向量
  58681. let vec = new THREE.Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize()
  58682. add(pano0, vec)
  58683. add(pano1, vec.negate())
  58684. let geo = MeshDraw.createGeometry(posArr, faceArr)
  58685. this.cube.geometry = geo
  58686. this.cube.scale.set(1,1,1);
  58687. this.cube.position.set(0,0,0)
  58688. }else{
  58689. this.cube.geometry = new THREE.BoxBufferGeometry(1,1,1,1)
  58690. f(pano0.pointcloud.bound)
  58691. }
  58692. } */
  58693. isNeighbour(pano0, pano1, {dontCompute, onlyUseTex, computeDirFirst, computeTwoDir}={}){//是否之间没有遮挡(在加载visibles之前,自己算) 最好pano0是currentPano
  58694. if(!pano0 || !pano1 )return
  58695. let margin = 0.1;
  58696. let map0 = this.neighbourMap[pano0.id]; //主
  58697. let map1 = this.neighbourMap[pano1.id]; //副
  58698. /* if(map0[pano1.id] != void 0){
  58699. ifNeighbour = map0[pano1.id]
  58700. }
  58701. if(!ifNeighbour && map1[pano0.id] != void 0){
  58702. ifNeighbour = map1[pano0.id]
  58703. } */
  58704. let ifNeighbour = map1[pano0.id] == void 0 ? map0[pano1.id] : map0[pano1.id] && map1[pano0.id]; //如果map1没计算就只要返回map0
  58705. let dis = pano0.position.distanceTo(pano1.position);
  58706. if(math.closeTo(dis,0) ){//两个点相同
  58707. ifNeighbour = map1[pano0.id] = map0[pano1.id] = true;
  58708. return true
  58709. }
  58710. if(dontCompute) return ifNeighbour
  58711. let logSids = [/* '1739923562316697600|3','1739923562316697600|2' */];
  58712. let ifLog = pano0.sid == logSids[0] && pano1.sid == logSids[1] || pano0.sid == logSids[1] && pano1.sid == logSids[0];
  58713. if(ifLog){
  58714. console.log(2);
  58715. }
  58716. let ifSheltered = (mainPano, subPano )=>{ //该点前方近处是否都被遮挡 。 为了防止杂点干扰,多个方向探测
  58717. let vec = new Vector3().subVectors(subPano.position, mainPano.position).normalize();
  58718. let getDir = (angle_, upDown)=>{ //基于vec的方向 向左向右旋转
  58719. //if(upDown) vec.clone().applyAxisAngle(new THREE.Vector3(1, 0, 0), upDown);
  58720. return vec.clone().applyAxisAngle(new Vector3(0, 0, 1), angle_);
  58721. };
  58722. let minScore = 0.25;
  58723. let 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以外一部分有较大概率有空隙所以紧凑点
  58724. let wellCount = 0;
  58725. let seccess = [];
  58726. for(let i=0; i<angles.length; i++){
  58727. let rad = MathUtils.degToRad(angles[i]);
  58728. let dir = getDir(rad);
  58729. let color;
  58730. let intersectPoint = viewer.images360.depthSampler.sample({dir}, mainPano, true);
  58731. if(!intersectPoint || intersectPoint.distance * Math.cos(Math.abs(rad)) /* + margin */ > dis ){//投影在vec方向的长度不超过漫游点间距
  58732. wellCount ++ ; seccess.push(angles[i]); color = new Color('#0f8');
  58733. }
  58734. ifLog && addLine(mainPano.position, dir, dis, color);
  58735. }
  58736. //console.log('ifSheltered')
  58737. if(ifLog){
  58738. console.log('ifSheltered seccess', seccess, 'id:', mainPano.originID, subPano.originID);
  58739. }
  58740. let score = wellCount / angles.length;
  58741. if(score >= minScore){//合格个数
  58742. return score
  58743. }
  58744. };
  58745. /*
  58746. 识别一定角度范围内是否有遮挡时
  58747. 几种奇葩的情况:
  58748. 1 在墙的两边的但是墙是倾斜的漫游点:
  58749. A /
  58750. /
  58751. / B
  58752. 从B出发和BA成20度的射线和墙面的交点会远于A,导致识别为无遮挡。
  58753. 所以还是改为识别范围内多个深度图像素, 合格像素个数占比 至少要大于50%,因为半边墙壁是50%
  58754. 如SG-9UsbysDufBw&formal&test 的 6、9点。 而SS-GTmFBp1JN8k&formal&test的 2、3两点是人物遮挡
  58755. 2 可以通行,但是右边是墙,右边的都检测失败,左侧的又有一些杂点,导致成功dir个数很低。
  58756. 所以minRatio 要降低于0.5
  58757. */
  58758. //三个方向 : position0到position1, position0到floorPosition1, position1到floorPosition0。 只要有一个满足ifNeighbour就为true。 不过为了不使sampler总换图,先只考虑从主pano到副pano的方向
  58759. let getNeighbour = (mainPano, subPano )=>{
  58760. let dirPoints = [[subPano.position, mainPano.position]]; //注: 点A能到B不代表点B能到A,因为拍摄时物体会移动,或点位相对位置不对,无论是否是意外遮挡都且记下来,反正最后只要有一方可行就算相邻。
  58761. if(dis < 20){//在远处去掉对floorPosition的判断
  58762. dirPoints.push([subPano.floorPosition.clone().add(new Vector3(0,0,0.1)), mainPano.position]);
  58763. }
  58764. if(dis < 12){//为了防止楼梯拐角、杂点遮挡。 尽量只在穿墙时不可通行
  58765. dirPoints.push([subPano.position.clone().add(new Vector3(0,0,0.8)), mainPano.position]);
  58766. let normal = math.getNormal2d({p1:subPano.position, p2:mainPano.position}).multiplyScalar(0.3); //左右方向
  58767. dirPoints.push([subPano.position.clone().add(new Vector3(normal.x,normal.y,0.1)), mainPano.position]);
  58768. dirPoints.push([subPano.position.clone().add(new Vector3(-normal.x,-normal.y,0.1)), mainPano.position]);
  58769. }
  58770. //console.warn('getNeighbour', mainPano.id,subPano.id)
  58771. for(let i=0; i<dirPoints.length; i++){
  58772. let dir = new Vector3().subVectors(dirPoints[i][0], dirPoints[i][1]).normalize();
  58773. let intersectPoint = viewer.images360.depthSampler.sample({dir}, mainPano, true, true);
  58774. if(!intersectPoint || intersectPoint.distance+margin > dirPoints[i][0].distanceTo(dirPoints[i][1])){
  58775. //if(i>2)console.log('haha',i,'id:',mainPano.id,subPano.id)
  58776. return true
  58777. }
  58778. }
  58779. };
  58780. //if(!ifNeighbour && (map0[pano1.id] == void 0 || computeTwoDir && !map0[pano1.id] && map1[pano0.id] == void 0 )) {//主方向为空且不为邻居
  58781. if(pano0.pointcloud.hasDepthTex || pano1.pointcloud.hasDepthTex){
  58782. if(computeTwoDir ? (map0[pano1.id] == void 0 || map1[pano0.id] == void 0) : (map0[pano1.id] == void 0 && map1[pano0.id] !== false) ){
  58783. //2024.3.20改为必须两个方向都为true才行。 因为如果两个点分别在两个数据集相距很远,A确定有墙无法到B,B朝A看 没有B所在的数据集点云遮挡,因深度图不会包含别的数据集的点,故深度图探测到A处为无遮挡,就会导致会飞到遥远的A。 即使在同一个数据集,因为点云可以编辑位置,导致AB相对位置错误,也要避免这种情况可以互相乱走。 缺点是更容易被杂点阻挡,所以需要ifShelter降低阈值。
  58784. if(map0[pano1.id] == void 0 && pano0.depthTex){
  58785. let is = getNeighbour(pano0, pano1);
  58786. map0[pano1.id] = !!is;
  58787. }
  58788. if(computeTwoDir && map0[pano1.id] && pano1.depthTex && map1[pano0.id] == void 0 ){ //computeTwoDir : 允许反向计算,即可以读取另一张的深度图 。 如果map0为false,map1就不用计算,只需要等待计算ifShelter
  58789. let is = getNeighbour(pano1, pano0);
  58790. map1[pano0.id] = !!is;
  58791. }
  58792. if( map0[pano1.id] === false || map1[pano0.id] === false){
  58793. if(dis<20) {//再检查下 只要两方都没有被完全遮挡就算可通行 针对杂点较多的情况
  58794. if(pano0.depthTex && pano1.depthTex){
  58795. ifNeighbour = false;
  58796. let a = ifSheltered(pano0,pano1);
  58797. if(a){
  58798. let b = ifSheltered(pano1,pano0);
  58799. if(b && (a+b >= 0.6)){
  58800. ifNeighbour = true;
  58801. }
  58802. }
  58803. map0[pano1.id] = map1[pano0.id] = ifNeighbour;
  58804. }
  58805. }else {
  58806. //标记为无需再计算, 因已经失败。 当map0和map1都不为void 0后就无法再计算了。
  58807. if(map0[pano1.id] === void 0) map0[pano1.id] = 0 ;
  58808. if(map1[pano0.id] === void 0) map1[pano0.id] = 0 ;
  58809. }
  58810. }
  58811. ifNeighbour = map1[pano0.id] == void 0 ? map0[pano1.id] : map0[pano1.id] && map1[pano0.id]; //如果map1没计算就只要返回map0
  58812. if(ifLog){
  58813. console.log('isNeighbour', pano0.id+"("+pano0.originID+")", pano1.id+"("+pano1.originID+")", map0[pano1.id], map1[pano0.id]);
  58814. }
  58815. }
  58816. }else if(!onlyUseTex && !ifNeighbour){//使用点云判断(有深度贴图时不会执行到这)
  58817. let inDirection = ()=>{
  58818. let dir = new Vector3().subVectors(pano1.position,pano0.position).normalize();
  58819. let dis = pano1.position.distanceTo(pano0.position);
  58820. let fov = MathUtils.degToRad(viewer.mainViewport.camera.fov);
  58821. let hfov = cameraLight.getHFOVForCamera(viewer.mainViewport.camera , true );
  58822. let hov = Math.min(fov, hfov);
  58823. let max = Math.cos(MathUtils.degToRad(10));
  58824. let min = Math.cos(MathUtils.degToRad(40));
  58825. if(this.getDirection().dot(dir) > MathUtils.clamp(Math.cos(hov/2 ) * dis / 10, min, max )){//距离越远要求和视线角度越接近
  58826. return true
  58827. }
  58828. };
  58829. if(computeDirFirst){//先计算方向,防止重复计算ifBlockedByIntersect
  58830. if(inDirection()){
  58831. ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({point:pano1.position, margin, cameraPos:pano0.position});
  58832. }
  58833. }else {
  58834. ifNeighbour = !viewer.inputHandler.ifBlockedByIntersect({point:pano1.position, margin, cameraPos:pano0.position});
  58835. if(ifNeighbour && !inDirection()){
  58836. ifNeighbour = undefined; //不确定
  58837. }
  58838. }
  58839. map0[pano1.id] = map1[pano0.id] = ifNeighbour ? 'byCloud' : ifNeighbour;//写简单点
  58840. }
  58841. if(map0[pano1.id] && map1[pano0.id]){
  58842. pano0.neighbours.includes(pano1) || pano0.neighbours.push(pano1);
  58843. pano1.neighbours.includes(pano0) || pano1.neighbours.push(pano0);
  58844. }
  58845. return ifNeighbour
  58846. }
  58847. bump(direction) {//撞墙弹回效果
  58848. if (!this.bumping && !this.latestToPano) {
  58849. let distance = Potree.settings.displayMode == 'showPanos' ? 0.15 : 0.12;//感觉点云模式比全景模式更明显,所以降低
  58850. let currentPos = this.position.clone();
  58851. let endPosition = new Vector3().addVectors(this.position, direction.clone().multiplyScalar(distance));
  58852. let duration = 150;
  58853. viewer.scene.view.setView({position:endPosition, duration,
  58854. callback:()=>{
  58855. viewer.scene.view.setView({position:currentPos, duration: duration*5,
  58856. callback: ()=>{
  58857. this.bumping = false;
  58858. //this.dispatchEvent('cameraMoveDone')
  58859. },
  58860. Easing:'easeInOutSine',
  58861. cancelFun:()=>{this.bumping = false;}
  58862. });
  58863. this.bumping = true;
  58864. },
  58865. cancelFun:()=>{this.bumping = false;},
  58866. Easing:'easeInOutSine'
  58867. });
  58868. this.bumping = true;
  58869. }
  58870. //备注:将4dkk中的‘前后方向变化fov、左右方向移动镜头’ 都改为移动镜头。 因为这里无法判断左右离壁距离。
  58871. }
  58872. flyToPanoClosestToMouse() {
  58873. /* if (Date.now() - this.mouseLastMoveTime > 50) {
  58874. //this.intersect = this.getMouseIntersect();
  58875. this.intersect && this.updateClosestPano(this.intersect);
  58876. } */
  58877. if(!Potree.settings.ifShowMarker){//不显示marker的时候mousemove没更新鼠标最近点所以更新
  58878. this.updateClosestPano(viewer.inputHandler.intersect);
  58879. }
  58880. //console.log('flyToPanoClosestToMouse',this.closestPano)
  58881. if (this.closestPano) {
  58882. let pano = this.closestPano;
  58883. return this.flyToPano({
  58884. pano, easeName: this.isAtPano() ? 'linearTween' : 'easeInOutQuad'
  58885. });
  58886. }
  58887. var direction = this.viewer.inputHandler.getMouseDirection().direction;
  58888. this.flyDirection(direction);
  58889. }
  58890. flyDirection(direction, option1, option2, byKey) {
  58891. if(viewer.mainViewport.view.isFlying()){// closestPanoInDirection函数耗时长,飞行时运行会卡顿(如果以后加无缝过渡再说)
  58892. return
  58893. }
  58894. var deferred = $.Deferred();
  58895. //this.history.invalidate();
  58896. var panoSet = this.closestPanoInDirection(direction, option1, option2, byKey);
  58897. if (panoSet) {
  58898. this.flyToPano({
  58899. pano: panoSet,
  58900. callback: deferred.resolve.bind(deferred, !0)
  58901. } );
  58902. } else {
  58903. //如果离数据集较远,转动也很难找到点云,就飞到就近点:
  58904. if(Potree.settings.displayMode == 'showPointcloud'){
  58905. let po = viewer.scene.pointclouds.find(e=>e.visibleNodes.some(a=>a.getLevel() > Math.ceil(e.maxLevel * 0.15) )); //虽然当点云在前方很远的地方也可能符合
  58906. if(!po){//无可见点云
  58907. //console.log('no visi cloud')
  58908. if(!this.panos.length){//如果场景中没有漫游点,如SG-t-XPf1k9pv3Zg 点击后回到可见区域
  58909. if(viewer.scene.pointclouds.length == 0)return
  58910. let map = new Map();
  58911. let clouds = viewer.scene.pointclouds.filter(e=>e.root.geometryNode);
  58912. clouds.forEach(e=>map.set(e, e.bound.distanceToPoint(this.position)));
  58913. clouds.sort((a,b)=>map.get(a) - map.get(b));
  58914. viewer.flyToDataset({focusOnPoint:true, pointcloud:clouds[0], duration:500 });//飞最近的一个点云
  58915. return deferred.promise();
  58916. }
  58917. this.flyToPano({
  58918. pano: this.findNearestPano(),
  58919. duration:500,
  58920. callback: deferred.resolve.bind(deferred, !0)
  58921. });
  58922. return deferred.promise();
  58923. }
  58924. }
  58925. this.bump(direction);
  58926. deferred.resolve(!1);
  58927. }
  58928. return deferred.promise();
  58929. }
  58930. closestPanoInDirection(direction, option1, option2, byKey) {
  58931. return this.rankedPanoInDirection(0, direction, option1, option2, byKey)
  58932. }
  58933. rankedPanoInDirection(t, direction, option1, option2, byKey){
  58934. //此direction为mouseDirection,是否需要加上相机角度的权重
  58935. let startTime = Date.now();
  58936. var panoSet = {
  58937. pano: null,
  58938. candidates: [] //缓存顺序--如果需要打印的话
  58939. };
  58940. t || (t = 0);
  58941. option1 = void 0 !== option1 ? option1 : 0.6; //.75; 2024.3.22改小,也就是可以走的角度范围增加,主要针对像山野那种很大的场景,不知道可以走哪,容易因角度范围内无近点而飞到远处的情况。但不能太小,总是横着走路
  58942. var o = option2 ? "angle" : "direction";
  58943. var floor = viewer.modules.SiteModel.currentFloor;
  58944. var entity = viewer.modules.SiteModel.inEntity;
  58945. var getHeightDis = (pano)=>{
  58946. if(floor && !floor.panos.includes(pano) && pano.position.z < this.position.z){ //若是上方的漫游点,就正常走。因为一般不会点击天花板。
  58947. return this.position.z - pano.position.z
  58948. }else {
  58949. return 0
  58950. }
  58951. };
  58952. let disSquareMap = new Map();
  58953. this.panos.forEach(pano=>{
  58954. let dis2 = pano.position.distanceToSquared(this.position); //距离目标点
  58955. disSquareMap.set(pano, dis2);
  58956. });
  58957. let changeTexCount = 0, maxWaitDur = 300;
  58958. //maxSamplerChangeTex = THREE.Math.clamp( maxWaitDur / Potree.timeCollect.depthSampler.median, 2, 10) //计算换贴图最大数目
  58959. var request = [//必要条件
  58960. Images360.filters.not(this.currentPano),
  58961. Images360.filters.isEnabled(),
  58962. //Images360.filters.inFloorDirection( this.position, direction, option1 ), //原先用inPanoDirection,但容易穿楼层,当mouse较低或较高 //因不束缚纵向所以可能往相反反向
  58963. (pano)=>{
  58964. /* let isNeighbour = this.isNeighbour(this.currentPano, pano, true, true); //不计算的
  58965. if(isNeighbour == void 0){
  58966. let willChangeTex = pano.depthTex && !this.depthSampler.imgDatas.some(e=>e.pano == pano)
  58967. if(changeTexCount < maxSamplerChangeTex || !willChangeTex ){
  58968. isNeighbour = this.isNeighbour(this.currentPano, pano, false, true);//计算
  58969. if(willChangeTex && isNeighbour != void 0) changeTexCount++
  58970. }else{
  58971. if(disSquareMap.get(pano) < 500)return true //因为费时,超过一定个数就不计算了,距离近的话先可通行。
  58972. }
  58973. } */
  58974. // 不会再changeTex了
  58975. let isNeighbour = this.isNeighbour(this.currentPano, pano, {onlyUseTex:true});
  58976. if(isNeighbour || pano.noNeighbour && disSquareMap.get(pano) < 200){//在靠近孤立点时可以通行。但是不好把握这个距离,太远的话很多地方都会不小心到孤立点,太近的话可能永远到不了。
  58977. return true
  58978. }
  58979. },
  58980. /* (pano)=>{ //防止不小心穿越地板到下一层, 尽量走楼梯,实在没有楼梯或楼梯漫游点稀疏的话就通过楼层按钮。
  58981. let dis = getHeightDis(pano)
  58982. //console.log('getHeightDis',pano.id,dis)
  58983. if(dis < 3){//不能超过最大高度差( 最大高度差暂定为接近一层楼的高度。)(最好的解决方案是设置漫游可行)
  58984. return true
  58985. }else{
  58986. return this.isNeighbour(this.currentPano, pano)
  58987. }
  58988. } */
  58989. ];
  58990. if(!byKey){
  58991. request.push(Images360.filters.inPanoDirection( this.position, this.getDirection(), option1/* , true */)); //垂直方向上再稍微限制一下, 要接近视线方向,避免点击前方时因无路而到下一楼。但不能太高,否则楼梯上稍微朝下点击都到不了上方。之所以使用视线方向是因为镜头方向比鼠标方向目的性更强。
  58992. }
  58993. var list = [//决胜项目
  58994. (pano)=>{
  58995. return -disSquareMap.get(pano)
  58996. },
  58997. Images360.scoreFunctions[o]( this.position, direction, true),
  58998. (pano)=>{
  58999. let neighbour = this.isNeighbour(this.currentPano, pano, {dontCompute:true, isNeighbour:true}); //不计算的
  59000. return neighbour ? directionFactor : 0;
  59001. } ,
  59002. /* (pano)=>{//尽量不穿越地板到下一层
  59003. let dis = getHeightDis(pano)
  59004. return -dis * directionFactor * 0.1;
  59005. }, */
  59006. /* (pano)=>{ //尽量在一个建筑内行走,这样不易穿墙
  59007. let score = 0
  59008. if(entity ){
  59009. if(!entity.panos.includes(pano) ) score -= directionFactor * 0.01; //不能设置太高,否则会走不进大房间的小房间中,因为容易穿过小房间的一个门到另一个门外
  59010. if(!floor.panos.includes(pano)) {//避免穿楼层
  59011. let heightDiff = Math.abs(pano.position.z - this.position.z);
  59012. if(heightDiff > 2){
  59013. score -= directionFactor * 0.1 * heightDiff;
  59014. }
  59015. }
  59016. }
  59017. return score
  59018. } */
  59019. ];
  59020. if(!byKey && viewer.inputHandler.intersect && this.currentPano ){//方便上下楼, 考虑panos之间的角度差
  59021. let pos1 = this.currentPano.floorPosition;
  59022. let vec1 = new Vector3().subVectors(viewer.inputHandler.intersect.location, pos1 ).normalize();//应该只有atPano时才会执行到这吧?
  59023. list.push( function(pano) {
  59024. var pos2 = pano.floorPosition;
  59025. var vec2 = pos2.clone().sub(pos1).normalize();
  59026. return vec2.dot(vec1) * directionFactor * 4
  59027. });
  59028. }
  59029. this.findRankedByScore(t,request,list,panoSet);
  59030. //console.log( 'costTime:',Date.now() - startTime)
  59031. return panoSet.pano;
  59032. }
  59033. findRankedByScore(e, t, i, n) {
  59034. n && (n.candidates = null, //candidates 缓存顺序--如果需要打印的话
  59035. n.pano = null),
  59036. e || (e = 0);
  59037. var r = Common.sortByScore(this.panos, t, i);
  59038. //console.log('findRankedByScore', r && r.map(u=>u.item.id + '| ' + math.toPrecision(u.score,4) + " | " + math.toPrecision(u.scores,4)))
  59039. return !r || 0 === r.length || e >= r.length ? null : (n && (n.candidates = r,
  59040. n.pano = r[e].item),
  59041. r[e].item)
  59042. }
  59043. updateClosestPano(intersect, state) {//hover到的pano 大多数时候是null
  59044. var pano;
  59045. if(intersect instanceof Panorama){ //漫游模式
  59046. pano = state ? intersect : null;
  59047. }else {
  59048. if(this.isAtPano() || this.bumping){
  59049. return
  59050. }else {
  59051. var filterFuncs = [];
  59052. intersect = intersect && intersect.location;
  59053. if(!intersect)return
  59054. let sortFuncs = Potree.settings.editType != 'pano'? [Images360.sortFunctions.floorDisSquaredToPoint(intersect)] : [Images360.sortFunctions.disSquaredToPoint(intersect)];
  59055. pano = Common.find(this.panos, filterFuncs, sortFuncs);
  59056. }
  59057. }
  59058. if (pano != this.closestPano) {
  59059. pano && (this.isPanoHover = !0);
  59060. this.closestPanoChanging(this.closestPano, pano); // 高亮marker
  59061. //console.log('closestPano '+ (pano ? pano.id : 'null' ))
  59062. this.closestPano = pano;
  59063. } else {
  59064. this.isPanoHover = !1;
  59065. }
  59066. }
  59067. closestPanoChanging(oldPano, newPano){
  59068. if(!Potree.settings.ifShowMarker)return
  59069. oldPano && oldPano.hoverOff({byImages360:true});
  59070. newPano && newPano.hoverOn({byImages360:true});
  59071. }
  59072. getTileDirection(){//根据不同dataset的来存储
  59073. var vectorForward = viewer.scene.view.direction.clone();
  59074. var vectorForwards = viewer.scene.pointclouds.map(e=>{
  59075. var inv = new Matrix4().copy(e.rotateMatrix).invert();//乘上dataset的旋转的反转
  59076. var direction = vectorForward.clone().applyMatrix4(inv);
  59077. return {
  59078. datasetId: e.dataset_id,
  59079. direction: math.convertVector.ZupToYup(direction)
  59080. }
  59081. });
  59082. //return vectorForwards[0].direction
  59083. return {
  59084. datasetsLocal: vectorForwards,
  59085. vectorForward
  59086. }
  59087. }
  59088. update(){
  59089. //if(this.tileDownloader.started){
  59090. var vectorForwards = this.getTileDirection();
  59091. //vectorForwards = vectorForwards[0].direction
  59092. this.updateTileDownloader(tileArr, vectorForwards);
  59093. this.updatePanoRenderer(vectorForwards);
  59094. //}
  59095. this.updateZoomPano();
  59096. }
  59097. updateTileDownloader(t, vectorForward) {
  59098. var i = this.nextPano || this.currentPano;
  59099. if(i){
  59100. this.tileDownloader.tilePrioritizer.updateCriteria(i, viewer.scene.view.position.clone() , vectorForward, t.length > 0 ? t : null),
  59101. this.tileDownloader.processPriorityQueue = !0;
  59102. }
  59103. }
  59104. updatePanoRenderer(vectorForward) {
  59105. var i = this.nextPano || this.currentPano;
  59106. if(i){
  59107. if (this.panoRenderer.hasQueuedTiles() && i) {
  59108. this.panoRenderer.updateDirection(vectorForward);
  59109. }
  59110. }
  59111. }
  59112. //等待部分加载完
  59113. checkAndWaitForTiledPanoLoad(pano, basePanoSize, callback1, callback2, progressCallback, iswait, isclear, l) {
  59114. //console.log('checkAndWaitForTiledPanoLoad',pano.id)
  59115. if (!pano) {
  59116. console.error("Player.checkAndWaitForTiledPanoLoad() -> Cannot load texture for null pano.");
  59117. }
  59118. var vectorForward = this.getTileDirection();
  59119. if (!pano.isLoaded(basePanoSize)) {
  59120. iswait && viewer.waitForLoad(pano, function() {//发送loading
  59121. return pano.isLoaded(basePanoSize)
  59122. });
  59123. /* var fov = {//test for direction 预加载的边缘有一丢丢不准确,尤其在相机倾斜时(4dkk也是)。
  59124. hFov: cameraLight.getHFOVForCamera(viewer.scene.getActiveCamera() ),
  59125. vFov: viewer.scene.getActiveCamera().fov
  59126. }//原先是null,不要求方向 */
  59127. var fov = null; //若不为null的话,因为可能可见范围的tile下载过了从而无法触发下载,然后得不到下载成功的消息,怎么办
  59128. pano.loadTiledPano(/* 1024 */ basePanoSize , vectorForward, fov, isclear, l, null).done(function(e, t) {
  59129. callback1 && callback1(e, t);
  59130. }
  59131. .bind(this)).fail(function(msg) {
  59132. callback2 && callback2(msg);
  59133. }
  59134. .bind(this)).progress(function(e, t, i) {
  59135. progressCallback && progressCallback(e, t, i);
  59136. }
  59137. .bind(this));
  59138. return !0;
  59139. }
  59140. }
  59141. fitPanoTowardPoint(o){ //寻找最适合的点位
  59142. var point = o.point, //相机最佳位置
  59143. target = o.target || o.point, //实际要看的位置
  59144. require = o.require || [],
  59145. rank = o.rank || [],
  59146. force = o.force,
  59147. getAll = o.getAll,
  59148. bestDistance = o.bestDistance || 0,
  59149. sameFloor = o.sameFloor,
  59150. maxDis = o.maxDis,
  59151. dir = o.dir;
  59152. let camera = viewer.scene.getActiveCamera();
  59153. if(target && !dir){
  59154. dir = new Vector3().subVectors(target,point).normalize();
  59155. }
  59156. let atFloor = sameFloor && viewer.modules.SiteModel.pointInWhichEntity(point, 'floor');
  59157. //if(o.floor)require.push(Panorama.filters.atFloor(o.floor))
  59158. let checkIntersect = o.checkIntersect;
  59159. let base = Math.max(300, viewer.bound.boundSize.length()*3);
  59160. if(o.boundSphere){//只接受boundSphere
  59161. let aspect = 1;//size.x / size.y
  59162. let dis;
  59163. if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
  59164. dis = /* size.y */o.boundSphere.radius/* / 2 *// MathUtils.degToRad(camera.fov / 2);
  59165. }else {
  59166. let hfov = cameraLight.getHFOVForCamera(camera , true );
  59167. dis = /* size.x */ o.boundSphere.radius /* / 2 */ / (hfov / 2);
  59168. }
  59169. bestDistance = dis;//*0.8
  59170. }
  59171. let disSquareMap = new Map();
  59172. let bestDisSquared = bestDistance * bestDistance;
  59173. let maxDisSquared = maxDis && (maxDis * maxDis);
  59174. this.panos.forEach(pano=>{
  59175. let dis2 = pano.position.distanceToSquared(target); //距离目标点
  59176. disSquareMap.set(pano, dis2);
  59177. });
  59178. let panos = this.panos.sort((p1,p2)=>{return disSquareMap.get(p1)-disSquareMap.get(p2)});
  59179. if(maxDisSquared){//热点超过最大距离不可见的
  59180. let panos2 = [], pano, i=0;
  59181. while(pano = panos[i], disSquareMap.get(pano) < maxDisSquared){
  59182. panos2.push(pano);
  59183. i++;
  59184. }
  59185. if(panos2.length == 0)return {pano, msg:'tooFar'} //全部都大于maxDis, 就返回最近的
  59186. panos = panos2;
  59187. }
  59188. rank.push((pano)=>{
  59189. let dis1 = Math.abs(pano.position.distanceToSquared(point) - bestDisSquared); //距离最佳位置
  59190. disSquareMap.set(pano, dis1);
  59191. if(!target){
  59192. return -dis1
  59193. }else {
  59194. let dis2 = disSquareMap.get(pano);
  59195. if(o.gotoBestView){//忽略和当前视线的角度
  59196. return -(dis1 + dis2*0.3)
  59197. }
  59198. let vec2 = new Vector3().subVectors(target,pano.position).normalize();
  59199. let cos = dir.dot(vec2);
  59200. //let result = (- dis1 - Math.pow(dis2 , 1.5)) / (cos + 2) // cos+2是为了调整到1-3,
  59201. let result = (dis1 + dis2*0.3) * ( -1 + cos*0.9 ); //尽量贴近最佳位置的角度, 或贴近相机原来的角度 。尽量靠近最佳观测点,并且优先选择靠近目标点的位置.(注意cos的乘数不能太接近1,否则容易只考虑角度)
  59202. //Potree.Log(pano.id, dis1, dis2, cos, result,{font:{toFixed:2,fontSize:10}})
  59203. return result
  59204. }
  59205. //注:热点最好加上法线信息,这样可以多加一个限制,尽量顺着热点像展示的方向。
  59206. },
  59207. (pano)=>{
  59208. let score = 0;
  59209. if(pano.depthTex && checkIntersect){
  59210. let intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true); //viewer.inputHandler.ifBlockedByIntersect({point:target, margin:0.1, cameraPos:pano})
  59211. if(intersect){
  59212. score = 0;
  59213. }else {
  59214. score = base * 2;
  59215. }
  59216. }else {
  59217. score = base * 1.5; //没加载好的话,不管了 , 几乎当做无遮挡,否则容易到不了最近点
  59218. }
  59219. return score
  59220. }
  59221. );
  59222. var g = Common.sortByScore(panos, require, rank);
  59223. // console.log(g)
  59224. /* let result1 = g && g.slice(0, 10)
  59225. if(result1){
  59226. g = Common.sortByScore(result1, [], [(e)=>{//避免遮挡
  59227. let pano = e.item;
  59228. let score = 0, log = ''
  59229. if(atFloor && atFloor.panos.includes(pano)){//如果不在任何一楼呢?
  59230. score += 600, log+='atFloor'
  59231. }
  59232. return {score, log}
  59233. }]);
  59234. if(g){
  59235. g.forEach(e=>{e.item = e.item.item})
  59236. }
  59237. console.log(g)
  59238. } */
  59239. let pano = g && g.length > 0 && g[0].item;
  59240. if(pano && checkIntersect){
  59241. let intersect = !!viewer.ifPointBlockedByIntersect(target, pano.id, true);
  59242. if(intersect){
  59243. return {pano, msg : 'sheltered'}
  59244. }
  59245. }
  59246. //if(getAll)return g;
  59247. return pano
  59248. //注:深度图有的位置会不准确,以至于会算出错误的遮挡、选择错误的pano,解决办法只能是移动下热点到更好的位置
  59249. }
  59250. //---------------scroll zoom ------------------------------------------
  59251. /* zoomIn = function() { //放大
  59252. this.zoomBy(1 + this.zoomSpeed);
  59253. }
  59254. zoomOut = function() {//缩小
  59255. this.zoomBy(1 - this.zoomSpeed);
  59256. } */
  59257. zoomBy(e, pointer) {//以倍数
  59258. this.zoomTo(this.zoomLevel * e, pointer);
  59259. }
  59260. zoomTo(zoomLevel, pointer) {//缩放到某绝对zoomLevel
  59261. let zoom = Potree.settings.zoom;
  59262. if (zoom.enabled) {
  59263. zoomLevel = MathUtils.clamp(zoomLevel, zoom.min, zoom.max);
  59264. //console.log(zoomLevel)
  59265. if(zoomLevel == this.zoomLevel) return;
  59266. this.zoomLevel = zoomLevel;
  59267. if(Potree.settings.panoZoomByPointer){
  59268. //定点缩放:使当前鼠标所在的位置缩放后不变
  59269. let view = viewer.scene.view;
  59270. let originDir = viewer.scene.view.direction;
  59271. let oldPointerDir = viewer.inputHandler.getMouseDirection(pointer).direction;
  59272. viewer.setFOV(Potree.config.view.fov * (1 / this.zoomLevel));
  59273. let newPointerDir = viewer.inputHandler.getMouseDirection(pointer).direction;
  59274. view.direction = oldPointerDir; //获取一下鼠标所在位置的yaw 和 pitch
  59275. let oldPitch = view.pitch, oldYaw = view.yaw;
  59276. view.direction = newPointerDir;
  59277. let newPitch = view.pitch, newYaw = view.yaw;
  59278. view.direction = originDir; //还原
  59279. viewer.scene.view.pitch -= newPitch - oldPitch;
  59280. viewer.scene.view.yaw -= newYaw - oldYaw;
  59281. }else {
  59282. viewer.setFOV(Potree.config.view.fov * (1 / this.zoomLevel));
  59283. }
  59284. }
  59285. }
  59286. zoomFovTo( fov ) { //通过fov来算zoomLevel
  59287. let zoomLevel = Potree.config.view.fov /* this.baseFov */ / fov;
  59288. this.zoomTo( zoomLevel );
  59289. }
  59290. smoothZoomTo(aimLevel, dur=0) {
  59291. var currentLevel = this.zoomLevel;
  59292. if(currentLevel == aimLevel)return;
  59293. var fun = (progress)=>{
  59294. //progress > 1 && (progress = 1)
  59295. let level = currentLevel * (1 - progress) + aimLevel * progress;
  59296. this.zoomTo(level, !0);
  59297. };
  59298. transitions.start(fun, dur, null, null, 0 , easing['easeInOutQuad'] );
  59299. }
  59300. updateZoomPano() {
  59301. if (!this.panoRenderer.zoomPanoRenderingDisabled && Potree.settings.displayMode == 'showPanos') {
  59302. var currentPano = this.currentPano;
  59303. if (currentPano) {
  59304. let levelThreshold1 = Potree.settings.navTileClass == '1k' ? 1.3 : 1.7 , levelThreshold2 = 2;
  59305. var t = this.zoomLevel > levelThreshold1,
  59306. n = !(this.flying && this.nextPano && this.nextPano !== this.currentPano),
  59307. r = t && n;
  59308. this.tileDownloader.tilePrioritizer.setZoomingActive(r);
  59309. this.panoRenderer.setZoomingActive(r, currentPano, !0);
  59310. var o = (pano, ifZoom)=>{
  59311. this.panoRenderer.resetRenderStatus(pano.id, !1, !0, this.qualityManager.getMaxNavPanoSize());
  59312. this.panoRenderer.clearAllQueuedUploadsForPano(pano.id);
  59313. this.panoRenderer.renderPanoTiles(pano.id, null, !1, !1);
  59314. pano.setZoomed(ifZoom);
  59315. };
  59316. if (r && (!currentPano.zoomed || this.qualityManager.zoomLevelResolution && this.qualityManager.zoomLevelResolution != '4k')) {//needZoom
  59317. currentPano.zoomed || o(currentPano, !0);
  59318. if(Potree.settings.navTileClass == '1k' && Potree.settings.tileClass != '1k' && this.zoomLevel < levelThreshold2){
  59319. this.panoRenderer.enableHighQuality( function() {//开启2k
  59320. if(Potree.settings.tileClass != '4k') o(currentPano, !0);
  59321. }.bind(this));
  59322. }else {
  59323. this.panoRenderer.enableUltraHighQualityMode(function() {//开启4k getMaxZoomPanoSize
  59324. this.qualityManager.useUltraHighResolutionPanos && (Potree.settings.zoom.max = Potree.config.ultraHighQualityMaxZoom);
  59325. o(currentPano, !0);
  59326. }.bind(this));
  59327. }
  59328. } else {
  59329. !t && currentPano.zoomed && o(currentPano, !1);
  59330. }
  59331. if(r && Potree.settings.navTileClass == '1k' && Potree.settings.tileClass == '4k' ){ //目前只有手机端navTileClass == '1k' (分三个梯度)
  59332. var change = (zoomedFlag)=>{
  59333. this.qualityManager.updateMaximums();//更新maxZoomPanoSize
  59334. this.panoRenderer.setupZoomRenderTarget(); //更新renderTarget
  59335. //currentPano.setZoomed(t);//更新uniforms贴图
  59336. };
  59337. this.qualityManager.zoomLevelResolution = this.zoomLevel >= levelThreshold2 ? '4k' : this.zoomLevel > levelThreshold1 ? '2k' : '1k';
  59338. if(this.oldZoomLevel < levelThreshold2 && this.zoomLevel >= levelThreshold2){//1k/2k-4k
  59339. change();
  59340. o(currentPano, t);
  59341. }else if(this.oldZoomLevel <= levelThreshold1 && this.zoomLevel > levelThreshold1){//1k-2k
  59342. change();
  59343. }else if(this.oldZoomLevel > levelThreshold2 && this.zoomLevel <= levelThreshold2){//4k-2k/1k
  59344. change();
  59345. o(currentPano, t);
  59346. }else if(this.oldZoomLevel > levelThreshold1 && this.zoomLevel <= levelThreshold1){//2k-1k
  59347. change();
  59348. }
  59349. this.oldZoomLevel = this.zoomLevel;
  59350. }
  59351. }
  59352. }
  59353. }
  59354. //--------------------
  59355. addHighMapCube(){//创建8*8的tile cube 主要因手机版崩溃 要在电脑端测试得设置maxRenderTargetSize
  59356. if( Potree.settings.tileClass == '4k' && this.qualityManager.maxRenderTargetSize == 2048){
  59357. var geo = new PlaneGeometry(1, 1, 1, 1);
  59358. var cube = new Object3D;
  59359. cube.tiles = [];
  59360. for(var cubeIndex=0; cubeIndex<6; cubeIndex++){
  59361. var face = new Object3D;
  59362. for(var i=0;i<8;i++){
  59363. for(var j=0;j<8;j++){
  59364. var tile = new Mesh(geo, new MeshBasicMaterial({
  59365. //side:THREE.DoubleSide
  59366. transparent:true,
  59367. opacity : 0.4,
  59368. depthTest:false,
  59369. }));
  59370. tile.position.set(i-3.5, j-3.5, -4);
  59371. if(Potree.settings.isTest){
  59372. var colorHue = Math.random();
  59373. tile.material.color = (new Color()).setHSL(colorHue, 0.6, 0.7);
  59374. /* tile.scoreLabel = new TextSprite( {
  59375. backgroundColor: { r: 0, g: 0, b: 0, a: 0 },
  59376. textColor: { r: 0, g: 0, b: 0, a: 1 },
  59377. borderRadius: 15,
  59378. renderOrder: 50, fontsize : 13,
  59379. text: '' ,
  59380. dontFixOrient:true
  59381. })
  59382. tile.scoreLabel.sprite.material.side = 2;
  59383. tile.scoreLabel.rotation.x = Math.PI
  59384. tile.add(tile.scoreLabel) */
  59385. }
  59386. tile.visible = false;
  59387. tile.tileX = i;
  59388. tile.tileY = j;
  59389. tile.cubeFace = cubeIndex;
  59390. //tile.renderOrder = RenderOrder.highTileCube
  59391. cube.tiles.push(tile);
  59392. face.add(tile);
  59393. }
  59394. }
  59395. switch(cubeIndex){
  59396. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_POSITIVE_X:
  59397. face.rotation.set(0,Math.PI/2,0);
  59398. break;
  59399. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
  59400. face.rotation.set(0,-Math.PI/2,0);
  59401. break;
  59402. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
  59403. var rot1 = new Quaternion().setFromAxisAngle(new Vector3(0,1,0),Math.PI);
  59404. var rot2 = new Quaternion().setFromAxisAngle(new Vector3(1,0,0),Math.PI/2);
  59405. face.quaternion.copy(rot1).multiply(rot2);
  59406. //face.rotation.set(Math.PI/2,0,0);
  59407. break;
  59408. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
  59409. //face.rotation.set(-Math.PI/2,0,0);
  59410. var rot1 = new Quaternion().setFromAxisAngle(new Vector3(0,1,0),Math.PI);
  59411. var rot2 = new Quaternion().setFromAxisAngle(new Vector3(1,0,0),-Math.PI/2);
  59412. face.quaternion.copy(rot1).multiply(rot2);
  59413. break;
  59414. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
  59415. face.rotation.set(0,Math.PI,0);
  59416. break;
  59417. case GLCubeFaces$3.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
  59418. face.rotation.set(0,0,0);
  59419. }
  59420. face.scale.set(1,-1,1);
  59421. face.cubeFace = cubeIndex;
  59422. cube.add(face);
  59423. }
  59424. cube.name = 'highMapCube';
  59425. this.highMapCube = cube;
  59426. viewer.scene.scene.add(cube);
  59427. {
  59428. let s = 0.1;
  59429. cube.scale.set(s,s,s);
  59430. }//注:由于原本的mesh上加了深度贴图,可能距离镜头比这里的近。凡是在cube以内的部分都会挡住cube导致模糊。但是应该不常见吧(另外到天空的边缘也是很近)。姑且depthTest=false
  59431. this.highMapCube.visible = false;
  59432. Potree.Utils.setObjectLayers(this.highMapCube, 'sceneObjects'/* 'skybox' */); //因它的深度是错误的,故不在skybox层渲染,影响edlRT, 而在renderOverlay时渲染覆盖。
  59433. //console.warn('addHighMapCube')
  59434. viewer.addEventListener('update',()=>{
  59435. if (this.highMapCube.visibleTiles) {
  59436. this.updateTiles(); //逐步将visibleTiles加载完
  59437. }
  59438. });
  59439. viewer.addEventListener('camera_changed',(e)=>{
  59440. if(e.viewport == viewer.mainViewport){
  59441. //重新获取visibleTiles
  59442. Common.intervalTool.isWaiting(
  59443. 'update4kTiles',
  59444. () => {
  59445. let vectorForward = this.getDirection();
  59446. this.updateTiles(vectorForward);
  59447. },
  59448. 500
  59449. );
  59450. }
  59451. });
  59452. }
  59453. }
  59454. isHighMapLoaded( cubeFace, tileX, tileY){
  59455. var tile = this.highMapCube.children[cubeFace].children[tileX*8+tileY];
  59456. return !!tile.material.map
  59457. }
  59458. updateTiles(direction) {
  59459. if (!this.highMapCube || !this.highMapCube.visible) return
  59460. if (this.highMapCube.tiles.filter(e => e.image).length <= 10) return //加载的太少了
  59461. //performance.mark('updateTiles-start')
  59462. if (direction) {
  59463. let camera = viewer.mainViewport.camera;
  59464. let hfov = cameraLight.getHFOVForCamera(camera, true) / 2;
  59465. let vfov = MathUtils.degToRad(camera.fov) / 2;
  59466. /* let hcos = Math.cos(hfov / 2)
  59467. let vcos = Math.cos(vfov / 2) */
  59468. let list = this.highMapCube.tiles;
  59469. list.forEach(e => {
  59470. //屏幕外的不显示
  59471. let pos = e.getWorldPosition(new Vector3());
  59472. let dir = new Vector3().subVectors(pos, this.highMapCube.position).normalize();
  59473. let hcos_ = dir.clone().setZ(direction.z).normalize().dot(direction); //在direction的斜面上水平角度差
  59474. let hRad = Math.acos(hcos_);
  59475. let vRad = -200;
  59476. if (/* hRad > hfov + 0.08 */ hRad / hfov > 1.5 ) {
  59477. e.score = -100;
  59478. } else {
  59479. vRad = Math.abs(Math.acos(dir.z) - Math.acos(direction.z));
  59480. if (/* vRad > vfov + 0.08 */ vRad / vfov > 1.5 ) {
  59481. e.score = -100;
  59482. } else {
  59483. e.score = -(hRad / hfov + vRad / vfov);
  59484. }
  59485. }
  59486. e.scores = hRad.toFixed(3) + ', ' + vRad.toFixed(3);
  59487. if (e.score == -100) {
  59488. this.resetTile(e);
  59489. }
  59490. });
  59491. this.highMapCube.visibleTiles = list.filter(e => e.score > -100);
  59492. //list.forEach(e=>e.scoreLabel.setText(e.scores))
  59493. }
  59494. let needRecover = this.highMapCube.visibleTiles.filter(e => !e.material.map);
  59495. if (needRecover.length) {
  59496. let maxCount = Common.getBestCount( '4kmaxTileRecover', 0, 2, 1.5, 6, false, 2 );
  59497. let count = 0;
  59498. console.log(maxCount);
  59499. needRecover.forEach((e, i) => {
  59500. //只更新若干个,因为太耗时了, 其余的等下帧更新
  59501. if (count >= maxCount) return
  59502. let r = this.recoverTile(e);
  59503. if (r) count++;
  59504. });
  59505. }
  59506. }
  59507. getHighImage(image, cubeFace, tileX, tileY) {
  59508. let tile = this.highMapCube.children[cubeFace].children[tileX * 8 + tileY];
  59509. tile.image = image; //先记录下来
  59510. }
  59511. updateHighMap(image, cubeFace, tileX, tileY){
  59512. //console.warn('updateHighMap')
  59513. var tile = this.highMapCube.children[cubeFace].children[tileX*8+tileY];
  59514. if (image) tile.image = image; //先记录下来
  59515. if(tile.material.map)return
  59516. if (this.highMapCube.visibleTiles && !this.highMapCube.visibleTiles.includes(tile) /* this.highMapCube.texLoadedCount >= this.getMaxTileCount() */) {
  59517. return
  59518. }
  59519. //简易创建贴图
  59520. /* var tex = this.$app.core.get('SceneRenderer').initSizedTexture2D(512, THREE.ClampToEdgeWrapping)
  59521. //var loaded = this.$app.core.get('Player').model.isHighMapLoaded(tile.cubeFace, tile.tileX, tile.tileY)
  59522. this.$app.core.get('SceneRenderer').uploadTexture2D(image, tex, 0, 0, 512, 512) //只替换tex对应的img,不新建
  59523. */
  59524. var tex = new Texture();
  59525. tex.image = image;
  59526. tex.flipY = false;
  59527. tex.wrapS = tex.wrapT = ClampToEdgeWrapping;
  59528. tex.generateMipmaps = false;
  59529. tex.minFilter = LinearFilter;
  59530. tex.needsUpdate = true;
  59531. tile.material.map = tex;
  59532. tile.material.opacity = 1;
  59533. tile.material.transparent = false;
  59534. tile.visible = true;
  59535. tile.material.needsUpdate = true; //发现每次开始放大但还未放大到4k时也会把之前加载过的4k加载
  59536. }
  59537. recoverTile(tile) {
  59538. if (tile.material.map) return
  59539. if (tile.image) {
  59540. this.updateHighMap(tile.image, tile.cubeFace, tile.tileX, tile.tileY);
  59541. return true
  59542. } else {
  59543. //console.log('no image')
  59544. }
  59545. }
  59546. resetTile(tile, kill) {
  59547. if (kill) {
  59548. //完全消灭
  59549. tile.image = null;
  59550. }
  59551. let map = tile.material.map;
  59552. if (map) {
  59553. map.dispose(); //这句执行了以后,h.__webglTexture一直就是undefined
  59554. map.loaded = !1;
  59555. map.version = 0;
  59556. //保底再执行一下这个,类似app.sceneRenderer.deallocateCubeTexture(tile.material.map)
  59557. var h = viewer.renderer.properties.get(map);
  59558. //console.log('__webglTexture',!!h.__webglTexture)
  59559. viewer.renderer.getContext().deleteTexture(h.__webglTexture);
  59560. tile.material.map = null;
  59561. tile.material.needsUpdate = true;
  59562. tile.visible = false;
  59563. //this.highMapCube.texLoadedCount --
  59564. //console.log('resetTile'/* , tile.cubeFace, tile.tileX, tile.tileY */)
  59565. }
  59566. }
  59567. resetHighMap() {
  59568. if (!this.highMapCube) return
  59569. this.highMapCube.children.forEach(e =>
  59570. e.children.forEach(tile => {
  59571. this.resetTile(tile, true);
  59572. })
  59573. );
  59574. //this.highMapCube.texLoadedCount = 0
  59575. this.highMapCube.visibleTiles = null;
  59576. this.hideHighMap();
  59577. //console.log('resetHighMap')
  59578. }
  59579. setHighMap(pano){
  59580. if(!this.highMapCube) return
  59581. this.highMapCube.position.copy(pano.position);
  59582. //可以利用第0个pano查看,其 rotation4dkk是(_x: 0, _y: -1.5707963267948966, _z: 0 )而手动旋转至(_x:1.5707963, _y: -1.57079, _z: 0)时才正确,说明要在4dkk的旋转基础上,绕x轴转90度,(也就是转成navvis坐标系), 然后得到YupToZup的函数写法的
  59583. this.highMapCube.quaternion.copy( math.convertQuaternion.YupToZup( pano.quaternion4dkk ) );
  59584. //乘上数据集整体的旋转:
  59585. let modelRotQua = new Quaternion().setFromRotationMatrix(pano.pointcloud.rotateMatrix);
  59586. this.highMapCube.quaternion.premultiply(modelRotQua);
  59587. }
  59588. showHighMap(){
  59589. if(!this.highMapCube) return
  59590. //console.warn('showHighMap')
  59591. this.highMapCube.visible = true;
  59592. }
  59593. hideHighMap(){
  59594. if(!this.highMapCube) return
  59595. //console.warn('hideHighMap')
  59596. this.highMapCube.visible = false;
  59597. }
  59598. //缩小后继续显示cube呢还是不显示? 不显示的话,就要把cube上的复制到renderTarget上……会不会又崩溃,or没加载的显示???
  59599. addPanoData(data, datasetId ){//加载漫游点
  59600. //data[0].file_id = '00019'
  59601. if(data.data) data = data.data;
  59602. if(data.length == 0)console.error(datasetId + ' 没有漫游点');
  59603. //data = data.sort(function(a,b){return a.id-b.id})
  59604. data.forEach((info)=>{
  59605. //if(Potree.fileServer){
  59606. info.id = this.panos.length; //把info的id的一长串数字改简单点
  59607. //}
  59608. let pano = new Panorama( info, this );
  59609. pano.addEventListener('dispose',(e)=>{
  59610. if(this.closestPano == pano) this.closestPano = null;
  59611. });
  59612. this.panos.push(pano);
  59613. if(Potree.settings.editType == 'pano'){
  59614. Potree.settings.datasetsPanos[datasetId].panos.push(pano);
  59615. }
  59616. });
  59617. }
  59618. loadDone(){
  59619. Potree.Utils.setObjectLayers(this.node, 'sceneObjects');
  59620. //this.updateCube(/* viewer.bound */)
  59621. this.panos.forEach(e=>{
  59622. this.neighbourMap[e.id] = {};
  59623. e.label && Potree.Utils.setObjectLayers(e.label, 'bothMapAndScene');
  59624. e.label2 && Potree.Utils.setObjectLayers(e.label2, 'bothMapAndScene');
  59625. });
  59626. this.tileDownloader.setPanoData(this.panos, [] /* , Potree.settings.number */);
  59627. {
  59628. let minSize = new Vector3(1,1,1);
  59629. this.bound = math.getBoundByPoints(this.panos.map(e=>e.position), minSize);
  59630. viewer.scene.pointclouds.forEach(pointcloud=>pointcloud.getPanosBound());
  59631. }
  59632. if(viewer.scene.pointclouds.some(e=>e.panos.length == 0)){
  59633. //console.warn('存在数据集没有pano');
  59634. viewer.hasNoPanoDataset = true;
  59635. }
  59636. }
  59637. getPano(value, typeName='id'){ //默认找的是id,也可以是sid、uuid
  59638. return this.panos.find(p=>p[typeName] == value)
  59639. }
  59640. };
  59641. //判断当前点是否加载了全景图
  59642. Images360.prototype.checkAndWaitForPanoLoad = function() {
  59643. var isLoadedPanos = {},
  59644. LoadedTimePanos = {},
  59645. loadedCallback = {}, //add
  59646. maxTime = 5e3;
  59647. var withinTime = function() {
  59648. for (var panoId in isLoadedPanos)
  59649. if (isLoadedPanos.hasOwnProperty(panoId) && isLoadedPanos[panoId]) {
  59650. var differTime = performance.now() - LoadedTimePanos[panoId];
  59651. if (differTime < maxTime)
  59652. return !0
  59653. }
  59654. return !1
  59655. };
  59656. return function(pano, basePanoSize, doneFun1, doneFun2, progressCallback, iswait, isclear, p ) {
  59657. loadedCallback[pano.id] = doneFun1;//add 因为有可能之前请求的没加doneFun1, 如果加载好就执行最新的doneFun1
  59658. if (withinTime()){//距离上次请求时间很近
  59659. //console.log(11)
  59660. return !0; //这里感觉应该是!1
  59661. }
  59662. let changeMode = (e)=>{
  59663. if(e.mode == 'showPointCloud'){
  59664. console.warn('切到点云模式了,就删除loadedCallback记录',pano.id);//否则再次转为showPanos会被withinTime阻拦
  59665. delete isLoadedPanos[pano.id];
  59666. viewer.cancelLoad(pano);
  59667. loadedCallback[pano.id] && loadedCallback[pano.id](); //可以飞行了
  59668. doneFun2 && doneFun2();
  59669. this.removeEventListener('requestMode', changeMode);
  59670. }
  59671. };
  59672. this.addEventListener('requestMode', changeMode);
  59673. var callback1 = (param1, param2)=>{
  59674. setTimeout(()=>{
  59675. isLoadedPanos[pano.id] = !1;
  59676. loadedCallback[pano.id] && loadedCallback[pano.id](param1, param2);
  59677. this.removeEventListener('requestMode', changeMode);
  59678. },1);
  59679. };
  59680. var callback2 = (param)=>{//没有看到有传doneFun2的
  59681. setTimeout(()=>{
  59682. isLoadedPanos[pano.id] = !1;
  59683. doneFun2 && doneFun2(param);
  59684. },1);
  59685. };
  59686. try {
  59687. null !== iswait && void 0 !== iswait || (iswait = !0);
  59688. isLoadedPanos[pano.id] = this.checkAndWaitForTiledPanoLoad(pano, basePanoSize, callback1, callback2, progressCallback, iswait, isclear, p );
  59689. //true代表没加载好
  59690. isLoadedPanos[pano.id] && (LoadedTimePanos[pano.id] = performance.now());
  59691. return isLoadedPanos[pano.id];
  59692. } catch (msg) {
  59693. isLoadedPanos[pano.id] = !1;
  59694. LoadedTimePanos[pano.id] = performance.now() - maxTime;
  59695. throw msg;
  59696. }
  59697. }
  59698. }();//加载全景图的流程:请求下载当前点的最低分辨率图(不过有可能已经下载了),并且请求uploadTile渲染当前漫游点,若tile都upload完(先6个)会发送消息,LoadComplete 从而回调成功。
  59699. Images360.prototype.getNeighbours = function(){ //逐渐自动获取neighbours。 200个点差不多在半分钟内算完
  59700. let lastIndex, inited;//标记上次查询到哪,防止重新sortByScore
  59701. return function( interacted){
  59702. if(!this.currentPano || viewer.mainViewport.view.isFlying() || viewer.lastFrameChanged || viewer.inputHandler.drag /* interacted */){ //拖拽时不更新,否则移动端卡
  59703. return lastIndex = 0;
  59704. }
  59705. let nearPanos = this.tileDownloader.tilePrioritizer.nearPanos;
  59706. if(!nearPanos)return;
  59707. //let startTime = Date.now()
  59708. let panos = [this.currentPano, ...nearPanos ];
  59709. this.depthSampler.updateNearPanos(panos);
  59710. let maxWaitDur = browser.isMobile() ? 40 : 60;
  59711. let changeCount = 0, maxChangeTex = browser.isMobile() ? 1 : 3, getCount = 0;
  59712. let changeTexCount = ()=>{
  59713. changeCount ++;
  59714. };
  59715. let median = Potree.timeCollect.depthSamChangeImg.median;
  59716. let ifOverTime = ()=>{
  59717. let is = changeCount >= maxChangeTex || changeCount * median + getCount * 0.01 > maxWaitDur;//不换贴图也要一丢丢计算时间
  59718. /* if(is){
  59719. console.log('OverTime, changeCount', changeCount)
  59720. } */
  59721. return is
  59722. };
  59723. this.depthSampler.addEventListener('changeImg', changeTexCount);
  59724. outer: for(let i=lastIndex,j=panos.length; i<j; i++){
  59725. let pano = panos[i];
  59726. let others = panos.slice(i+1, j);
  59727. lastIndex = i;
  59728. if(!pano.pointcloud.hasDepthTex && i>0)break; //点云的情况下最好不改相机位置,因为其他位置点云还没加载完,所以不判断当前点以外的漫游点
  59729. var g = Common.sortByScore(others, [ ], [
  59730. Images360.scoreFunctions.distanceSquared(pano.position)
  59731. ]);
  59732. for(let a=0, b=g.length; a<b; a++){
  59733. let item = g[a];
  59734. if(item.item == pano)continue
  59735. 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 //确定结果了就不需要算
  59736. //console.log('check isNeighbour', pano.id, item.item.id)
  59737. let byCloud = !pano.pointcloud.hasDepthTex;
  59738. let result = this.isNeighbour(pano, item.item, {onlyUseTex: !byCloud, computeDirFirst:true, computeTwoDir:true});//计算
  59739. if(result != void 0){//计算了 (byTex时其实并不一定)
  59740. //console.log('提前计算neighbor', pano.id, item.item.id)
  59741. this.dispatchEvent({type:'getNeighbourAuto', panos:[pano,item.item]});
  59742. if(byCloud){ //只计算一次
  59743. //console.log('提前计算neighbor byCloud', result, pano.id, item.item.id)
  59744. break outer;
  59745. }
  59746. getCount ++;
  59747. if(ifOverTime()){
  59748. break outer
  59749. }
  59750. }
  59751. }
  59752. lastIndex = i+1; //这轮结束
  59753. }
  59754. /* if(changeCount){
  59755. console.log( 'changeCount', changeCount)
  59756. } */
  59757. this.depthSampler.removeEventListener('changeImg', changeTexCount);
  59758. if(!inited){
  59759. inited = true;
  59760. this.addEventListener('loadedDepthImg',(e)=>{
  59761. //console.log('loadedDepthImg',e.pano)
  59762. lastIndex = 0; //主要针对刚打开场景第一个点有杂点时单向不成功,要立即进一步双向计算ifShelter
  59763. });
  59764. }
  59765. /* let costTime = Date.now() - startTime
  59766. costTime > maxWaitDur && console.log( 'costTime:',costTime) */
  59767. }
  59768. }();
  59769. Images360.filters = {
  59770. inPanoDirection : function(pos, dir, i, log) { //pano在mouse的方向上
  59771. return function(pano) {
  59772. var r = pano.floorPosition.clone().sub(pos).normalize();
  59773. var o = pano.position.clone().sub(pos).normalize();
  59774. log && console.log('dire',pano.id, r.dot(dir), o.dot(dir) );
  59775. return r.dot(dir) > i || o.dot(dir) > i
  59776. }
  59777. },
  59778. inFloorDirection: function(pos, dir, min, log) { //pano在mouse的水平方向上
  59779. return function(pano) {
  59780. var vec = new Vector2().subVectors(pano.floorPosition, pos).normalize();
  59781. var dir_ = new Vector2().copy(dir).normalize();
  59782. log && console.log('dire', pano.id, vec.dot(dir_) );
  59783. return vec.dot(dir_) > min
  59784. /* var i = pano.floorPosition.clone().sub(pos).setZ(0).normalize();//改成在xz方向上,否则点击墙面不会移动
  59785. return i.dot(dir.clone().setZ(0)) > min */
  59786. }
  59787. },
  59788. isNotBehindNormal: function(e, t) {
  59789. var i = new Vector3;
  59790. return t = t.clone(),
  59791. function(n) {
  59792. var r = i.copy(n.position).sub(e).normalize();
  59793. return r.dot(t) > 0
  59794. }
  59795. },
  59796. isCloseEnoughTo: function(e, t) {
  59797. return function(i) {//因为marker可能比地面高,所以识别范围要比marker看起来更近一些。(因为投影到地板的位置比marker更近)
  59798. return e.distanceTo(i.floorPosition) < t //许钟文
  59799. }
  59800. },
  59801. not: function(e) {
  59802. return function(t) {
  59803. return t !== e
  59804. }
  59805. } ,
  59806. isEnabled:function() {
  59807. return function(t) {
  59808. return t.enabled
  59809. }
  59810. },
  59811. isVisible:function() {
  59812. return function(t) {
  59813. return t.visible
  59814. }
  59815. }
  59816. };
  59817. Images360.scoreFunctions = {
  59818. direction: function(curPos, dir, ifLog) {
  59819. return function(pano) {
  59820. var pos1 = /* pano.floorPosition */ pano.position; //旧:改为权重放在marker上,这样对有斜坡的更准确,如上楼, 但这样近距离的pano角度就会向下了,以致于走不到
  59821. var n = pos1.clone().sub(curPos).normalize();
  59822. //ifLog && console.log('direction', pano.id, n.dot(dir) * directionFactor )
  59823. return n.dot(dir) * directionFactor
  59824. }
  59825. },
  59826. distance: function(pos1, r=1, ifLog) {
  59827. if(pos1.position)pos1 = pos1.position;
  59828. return function(pano) {//许钟文 改
  59829. var pos2 = pano.position.clone();
  59830. //ifLog && console.log('distance', pano.id, pos1.distance(pos2) * -1 )
  59831. return pos1.distanceTo(pos2) * -1 * r;
  59832. }
  59833. },
  59834. distanceSquared: function(pos1, r=1 ) {
  59835. if(pos1.position)pos1 = pos1.position;
  59836. return function(pano) {//许钟文 改
  59837. var pos2 = pano.position.clone();
  59838. return pos1.distanceToSquared(pos2) * -1 * r;
  59839. }
  59840. },
  59841. angle: function(e, t) {
  59842. return function(i) {
  59843. var n = i.position.clone().sub(e).normalize();
  59844. return n.angleTo(t) * Potree.config.navigation.angleFactor
  59845. }
  59846. },
  59847. };
  59848. Images360.sortFunctions = {//排序函数,涉及到两个item相减
  59849. floorDisSquaredToPoint: function(e) {
  59850. return function(t, i) {
  59851. return t.floorPosition.distanceToSquared(e) - i.floorPosition.distanceToSquared(e)
  59852. }
  59853. },
  59854. disSquaredToPoint: function(e) {
  59855. return function(t, i) {
  59856. return t.position.distanceToSquared(e) - i.position.distanceToSquared(e)
  59857. }
  59858. },
  59859. };
  59860. Images360.prototype.updateCube = (function(){//增加细分的版本,且垂直方向上取中位数 侧边多条
  59861. const minDis = 0.2; //pano和墙距离不能小于相机的near
  59862. const height = 1; //准确计算的话要分别计算两个pano的地面、天花板之间的俯仰角,和pano之间的还不一样。这里统一假设一个比较小的高度,因高度越大 maxSinAlpha 越大
  59863. let minTanBeta = minDis / height; /* (pano0.position.z - pano0.floorPosition.z) */
  59864. let minBeta = Math.atan(minTanBeta);
  59865. const maxSinAlpha = Math.cos(minBeta); // 注:beta = Math/2 - alpha
  59866. const skyHeight = 50;
  59867. return function(pano0, pano1){
  59868. if(Potree.settings.displayMode != 'showPanos' || pano0 == pano1
  59869. || this.cubePanos.includes(pano0) && this.cubePanos.includes(pano1)
  59870. ) return
  59871. this.cubePanos = [pano0, pano1];
  59872. viewer.addTimeMark('updateCube','start');
  59873. //console.log('updateCube',pano0.id, pano1&&pano1.id)
  59874. let useBound = (bound, size)=>{
  59875. size = size || bound.getSize(new Vector3);
  59876. let center = bound.getCenter(new Vector3);
  59877. size.max(new Vector3(HighMapCubeWidth,HighMapCubeWidth,HighMapCubeWidth));
  59878. this.cube.geometry = new BoxBufferGeometry(1,1,1,1);
  59879. this.cube.scale.copy(size);
  59880. this.cube.position.copy(center);
  59881. if(Potree.settings.testCube){
  59882. this.cubeTest.geometry = this.cube.geometry;
  59883. this.cubeTest.scale.copy(size);
  59884. this.cubeTest.position.copy(center);
  59885. }
  59886. return 'useBound'
  59887. };
  59888. let getPanoBound = (pano, dis)=>{//因漫游点可能在点云外部,如室外平地,所以需要union进漫游点
  59889. let panoBound = new Box3;
  59890. panoBound.expandByPoint(pano.position);
  59891. let margin = dis ? Math.max(dis * 0.1, 10) : 10;
  59892. panoBound.expandByVector(new Vector3(margin,margin,margin)); //give pano a margin 。 随着bound扩大,margin要相应扩大,否则当距离很远时看起来就像没有
  59893. return pano.pointcloud.bound.clone().union(panoBound)
  59894. };
  59895. this.cube.geometry.dispose();
  59896. if(pano1){//过渡
  59897. let dontAddSides;
  59898. let dis = pano0.position.distanceTo(pano1.position);
  59899. if(dis == 0)return
  59900. let sinAlpha = Math.abs(pano0.position.z - pano1.position.z) / dis; //俯仰角的sin,随角度增大而增大 0-1
  59901. let score = (1+sinAlpha*20) * dis; //score越大创建的mesh越不适合
  59902. let isNeighbour = this.isNeighbour(pano0, pano1);
  59903. //console.log(pano0.id, pano1.id, maxSinAlpha.toFixed(2), sinAlpha.toFixed(2), score.toFixed(2), isNeighbour)
  59904. if(sinAlpha>maxSinAlpha || !pano0.pointcloud.hasDepthTex || !pano1.pointcloud.hasDepthTex || (isNeighbour ? score > 100 : score > 50 ) ){
  59905. let bound = getPanoBound(pano0, dis).union(getPanoBound(pano1, dis));
  59906. let size = bound.getSize(new Vector3);
  59907. let max = Math.max(size.x, size.y, size.z);
  59908. size.set(max,max,max); //距离太远的数据集,过渡会畸变。所以扩大skybox,且为立方体
  59909. return useBound(bound, size)
  59910. }else if( isNeighbour ? score > 70 : score > 15 ){
  59911. dontAddSides = true; //pano间有阻挡时得到的side点可能使通道变窄,所以去掉。
  59912. }
  59913. //俯仰角增大时可能不在同一楼层,算出来的mesh不太好,所以更倾向直接使用cube,或去除side。
  59914. let half = browser.isMobile() ? 4 : 8; //自行输入 (点云计算的慢,还不准)
  59915. let count1 = 2*half;//偶数个 每个pano向 外dir 个数
  59916. //奇数个的好处:在窄空间内能探测到最远距离,坏处是前方有尖角。偶数个的坏处就是可能检测距离太近。
  59917. let getDir = (angle_, vec)=>{ //旋转获得水平向量
  59918. let rotMat = new Matrix4().makeRotationZ(angle_);
  59919. return vec.clone().applyMatrix4(rotMat)
  59920. };
  59921. let getFar = (dir, pano, origin, height)=>{//获取在这个方向上和墙体intersect的距离
  59922. //在垂直方向上分出多个方向,取一个最可能的接近真实的距离
  59923. let maxH = 40, minH = 2, minR = 0.5, maxR = 2;
  59924. height = height == void 0 ? Math.min(skyHeight, pano.ceilZ - pano.floorPosition.z) : height;
  59925. //let r = height (maxH - minH)* 0.14 // 高度越小,角度越小
  59926. //let r = minR + ( maxR - minR) * THREE.Math.clamp((height - minH) / (maxH - minH),0,1) //THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  59927. let r = math.linearClamp(height, [minH,maxH], [minR, maxR]);
  59928. let getZ = (deg)=>{
  59929. deg *= r;
  59930. deg = MathUtils.clamp(deg, 1, 80);
  59931. return Math.tan(MathUtils.degToRad(deg))
  59932. };
  59933. let dirs_; //注意:角度太大会碰到天花板或地板,越远越容易碰到, 在地下停车场就会伸展不开。 更多取接近0度的,否则围墙矮一点就会取到远处。
  59934. dirs_ = [15, 8, 3, -1, -5];
  59935. dirs_ = dirs_.map(deg=> dir.clone().setZ(getZ(deg)).normalize() );
  59936. let max = 50;
  59937. let count2 = dirs_.length;
  59938. let disArr = dirs_.map((dir_, i) =>{
  59939. let intersect = this.getIntersect(pano, dir_, origin);
  59940. let projectLen = intersect && intersect.distance ? dir_.dot(dir)*intersect.distance : max; //得到project在dir的长度
  59941. return projectLen //得水平距离
  59942. });
  59943. //console.log(pano ? pano.id : 'side','disArr', disArr.slice(0))
  59944. disArr.sort((a,b)=>{return b-a}); //从大到小
  59945. //console.log(pano ? pano.id : 'side','disArr', disArr)
  59946. let dis = disArr[Math.floor(count2/2-0.5)]; //对半、取前(中位数)
  59947. return dis
  59948. };
  59949. let sideCount = [0,0];
  59950. let addPos = (pano, vec )=>{//添加这个pano这一侧向外半圆的顶点
  59951. //添加pano位置对应的最高点最低点:
  59952. let minZ, maxZ;
  59953. minZ = pano.floorPosition.z;
  59954. maxZ = pano.getCeilHeight();
  59955. if(maxZ == Infinity) maxZ = skyHeight + pano.position.z; //maxZ = Math.max(skyHeight, maxZ)
  59956. [maxZ, minZ ].forEach(z=>{
  59957. posArr.push(pano.position.clone().setZ(z));
  59958. });
  59959. //在画面上线条从左往右数
  59960. const angle = Math.PI/(count1-1);
  59961. const dirs = []; //平分这半边180度
  59962. for(let i=0;i<count1;i++){
  59963. dirs.push(getDir(Math.PI/2-i*angle, vec));//正的在左边
  59964. }
  59965. let dirs2 = dirs.map((dir)=>{
  59966. return {
  59967. dir,
  59968. dis: getFar(dir, pano)
  59969. }
  59970. });
  59971. //剔除那些突然间离相机很近的dir。有可能是拍摄的人、或者杆子、树
  59972. /* dirs2.forEach((e,i)=>{
  59973. console.log(i, e.dis)
  59974. let smallThanBefore = ()=>{
  59975. return dirs2[i-1].dis / e.dis > maxRatio
  59976. }
  59977. let smallThanAfter = ()=>{
  59978. return dirs2[i+1].dis / e.dis > maxRatio
  59979. }
  59980. if(i>0 && i<count1-1 && smallThanBefore() && smallThanAfter()){//比左右两边都小很多
  59981. e.disB = (dirs2[i-1].dis + dirs2[i+1].dis) / 2 //平均数
  59982. console.log('两者之间',i,e.disB)
  59983. }else if(i==count1-1 && smallThanBefore() ) {//比前者小很多
  59984. e.disB = dirs2[i-1].dis * 0.8
  59985. console.log('smallThanBefore', i, e.disB)
  59986. }else if(i==0 && smallThanAfter() ){//比后者小很多
  59987. e.disB = dirs2[i+1].dis * 0.8
  59988. console.log('smallThanAftere', i, e.disB)
  59989. }
  59990. }) */
  59991. const maxRatio1 = 3 , maxRatio2 = 8; //超过maxRatio1就要加入判断,而最终结果的设限其实是maxRatio2
  59992. const minWidth = 0.5;
  59993. let computeWidth = (start,end)=>{
  59994. start+=1; //不包含start和end
  59995. let count = end - start ;
  59996. let dis = 0;
  59997. for(let m=start;m<end;m++){//得平均数
  59998. dis += dirs2[m].dis;
  59999. }
  60000. dis /= count;
  60001. let angle = Math.PI / (count1-1) * count / 2;
  60002. let width = dis * Math.tan(angle); //得到block的半宽度
  60003. return width
  60004. };
  60005. let changeDis = (start,end )=>{ //不包含start
  60006. start+=1; //不包含start和end
  60007. for(let m=start;m<end;m++){
  60008. dirs2[m].disB = dirs2[end].dis * 0.8;
  60009. //console.log('changeDis', m, dirs2[m].disB)
  60010. }
  60011. };
  60012. let start = -1;
  60013. for(let i=0;i<count1;i++){//遍历时将左边dis比之小很多且宽度较小的改大
  60014. //console.log(i, dirs2[i].dis)
  60015. let j = i-1;
  60016. let ratios = 0;
  60017. while(j>start && dirs2[i].dis / dirs2[j].dis > maxRatio1){
  60018. ratios += dirs2[i].dis / dirs2[j].dis;
  60019. j--;
  60020. }
  60021. let count = i-j-1;
  60022. ratios /= count;
  60023. if(count > 0 && computeWidth(j,i)< minWidth * ratios / maxRatio2 ){ //怎么感觉好像改成了视觉宽度小于某个值即可,那直接用count好了?
  60024. changeDis(j,i);
  60025. start = i; //在此之前的修改过,之后不用再判断
  60026. }
  60027. /* if(count > 0 && (count == 1 || computeWidth(j,i)<minWidth)){//若只有一个不用判断宽度直接修改
  60028. changeDis(j,i)
  60029. start = i //在此之前的修改过,之后不用再判断
  60030. } */
  60031. }
  60032. dirs2.forEach((e, index)=>{
  60033. let dir = e.dir.clone().multiplyScalar(e.disB || e.dis);
  60034. [maxZ,minZ].forEach(z=>{
  60035. posArr.push(pano.position.clone().setZ(z).add(dir)); //获取到外墙点
  60036. });
  60037. });
  60038. };
  60039. let addSide = ()=>{//两个漫游点间两边各加一些侧线
  60040. //中点处的
  60041. let top0 = pano0.ceilZ == Infinity ? pano0.position.z+skyHeight : pano0.ceilZ;
  60042. let top1 = pano1.ceilZ == Infinity ? pano1.position.z+skyHeight : pano1.ceilZ;
  60043. let midMaxZ = (top0 + top1)/2;
  60044. let midMinZ = (pano0.floorPosition.z+pano1.floorPosition.z)/2;
  60045. let mid = new Vector3().addVectors(pano0.position, pano1.position).multiplyScalar(0.5);
  60046. if(!dontAddSides){
  60047. if( pano0.pointcloud.hasDepthTex && pano0.pointcloud.hasDepthTex){
  60048. let panos = [pano0,pano1];
  60049. let vecs = [vec.clone().negate(), vec];
  60050. let axis = [[-1,1],[1,-1]];
  60051. let dis2d = new Vector2().subVectors(pano0.position, pano1.position).length();//水平上的距离
  60052. let maxDis = 50, minDis = 0.5, minR = 0.2, maxR = 1.2;
  60053. //let r = maxR - ( maxR - minR) * THREE.Math.clamp((dis2d - minDis) / (maxDis - minDis),0,1) //dis2d越大,角度要越小 //THREE.Math.smoothstep(currentDis, op.nearBound, op.farBound);
  60054. let r = math.linearClamp(dis2d, [minDis,maxDis], [maxR, minR]);
  60055. //console.log('dis2d',dis2d,'r',r)
  60056. let angles = ((browser.isMobile()/* || dis2d<4 */)? [60] : [50,70] /* [35,65] */).map(deg=>{ //正的在左边 尽量能够平分中间这段墙体。 (角度为从中心向外)
  60057. let angle = MathUtils.clamp(deg * r, 5, 80);
  60058. //console.log('angle',angle)
  60059. return MathUtils.degToRad(angle)
  60060. });
  60061. axis.forEach((axis_, index0)=>{
  60062. let disToSides = [];
  60063. let accordingPano = index0 == 0 ? pano0 : pano1; //根据离该点在vec方向上的距离顺序来存顶点
  60064. panos.forEach((pano,index)=>{
  60065. let dirs = angles.map(angle=>getDir(axis_[index]*angle, vecs[index]));//一侧的若干角度
  60066. dirs.forEach((dir_,i)=>{
  60067. let dis1 = getFar(dir_, pano);
  60068. let disToPano2d = dis1 * Math.cos(angles[i]);
  60069. if(disToPano2d<dis2d){//超过的话都到另一半pano的半圆了,不计入。(角度越小越容易超过)
  60070. let disToSide = dis1 * Math.sin(angles[i]);
  60071. if(pano != accordingPano){
  60072. disToPano2d = dis2d - disToPano2d; //反一下
  60073. }
  60074. dir_.multiplyScalar( dis1 );
  60075. disToSides.push({disToSide,disToPano2d, pano, dir_});
  60076. }else {
  60077. //console.log('超过',index0,index,i)
  60078. }
  60079. });
  60080. });
  60081. if(disToSides.length){
  60082. //disToSides.sort((a,b)=>{return b-a});//从大到小
  60083. //由距离accordingPano的近到远:
  60084. disToSides.sort((a,b)=>{return a.disToPano2d-b.disToPano2d});
  60085. //console.log('disToSides', index0, disToSides)
  60086. if(disToSides.length == 1 && disToSides[0].disToSide < 0.5){
  60087. disToSides = []; //如果太近直接去除
  60088. }
  60089. disToSides.forEach(e=>{//求z
  60090. let ratio = e.disToPano2d / dis2d;
  60091. let r = accordingPano == pano0 ? (1-ratio) : ratio;
  60092. let sideMaxZ_ = top0 * r + top1 * (1-r);
  60093. let sideMinZ_ = pano0.floorPosition.z * r + pano1.floorPosition.z * (1-r);
  60094. [sideMaxZ_,sideMinZ_].forEach(z=>{
  60095. posArr.push(e.pano.position.clone().setZ(z).add(e.dir_)); //是直接使用最长dis的那个intersect点好还是mid
  60096. });
  60097. });
  60098. }
  60099. sideCount[index0] = disToSides.length; //记录侧边个数
  60100. });
  60101. }else {
  60102. //这段针对点云时,仅测试才会执行到
  60103. sideCount = [1,1];
  60104. let sideDirs = [getDir(Math.PI/2, vec), getDir(-Math.PI/2, vec)];
  60105. sideDirs.forEach((dir_ ,index)=>{
  60106. let dis = getFar(dir_, null, mid, midMaxZ-midMinZ); //直接从中点求两侧的距离
  60107. dir_.multiplyScalar( /* Math.max( */dis/* , sideDis[index]) */ );
  60108. [midMaxZ,midMinZ].forEach(z=>{
  60109. posArr.push(mid.clone().setZ(z).add(dir_));
  60110. });
  60111. });
  60112. }
  60113. }
  60114. //中心:
  60115. [midMaxZ,midMinZ].forEach(z=>{
  60116. posArr.push(mid.clone().setZ(z));
  60117. });
  60118. };
  60119. //positions存放顺序:pano的每边的 zMax和zMin 、count1个dir的点 ;侧边的点 ;连接处顶底的中点
  60120. let addFaces = ()=>{
  60121. let getPI = function(index, posType, panoIndex){//获取顶点序号
  60122. return 2 + (count1*2 + 2 ) * panoIndex + index*2 + (posType == 'top' ? 0 : 1)
  60123. };
  60124. let getSidePI = function(index, posType, panoIndex){//获取侧边顶点序号
  60125. if(panoIndex == 1) index += sideCount[0];
  60126. return getPI(index, posType, 2)-2
  60127. };
  60128. let getPanoPI = function(posType, panoIndex){//获取pano处对应的点序号
  60129. return getPI(-1, posType, panoIndex)
  60130. };
  60131. let topCenter = posArr.length-2; //最后添加的两个中心点
  60132. let btmCenter = posArr.length-1;
  60133. for(let i=0;i<2;i++){
  60134. for(let index=1; index<count1; index++){
  60135. //pano外侧半圆围墙
  60136. faceArr.push([getPI(index,'top',i), getPI(index-1,'btm',i), getPI(index-1,'top',i)],//加入一块四方面
  60137. [getPI(index,'top',i), getPI(index,'btm',i), getPI(index-1,'btm',i)]);
  60138. faceArr.push([getPI(index,'top',i), getPI(index-1,'top',i), getPanoPI('top',i)]);//天花板扇形
  60139. faceArr.push([getPI(index,'btm',i), getPI(index-1,'btm',i), getPanoPI('btm',i)]);//地板扇形
  60140. }
  60141. let j = (i + 1) % 2; //另一个pano
  60142. //侧边
  60143. for(let u=0; u<=sideCount[i]; u++){
  60144. //侧边每个四方的左上右上左下右下四个点
  60145. let pLT = u == 0 ? getPI(0,'top',i) : getSidePI(u-1, 'top',i);
  60146. let pRT = u == sideCount[i] ? getPI(count1-1,'top',j) : getSidePI(u, 'top',i);
  60147. let pLB = u == 0 ? getPI(0,'btm',i) : getSidePI(u-1, 'btm',i);
  60148. let pRB = u == sideCount[i] ? getPI(count1-1,'btm',j) : getSidePI(u, 'btm',i);
  60149. faceArr.push([pLT,pLB,pRB],[pLT,pRB,pRT]);//外侧四方面
  60150. faceArr.push([pLT,topCenter,pRT] ,[pLB,btmCenter,pRB] );//顶部和底部到整体中心的扇形(由于点的顺序是根据和两个pano的距离,因此到中心的夹角并没按顺序排列,所以可能会重叠)
  60151. if(i==0){//只需要算一次
  60152. //顶部和底部中心与两个pano边构成的三角形
  60153. if(u == 0){
  60154. faceArr.push([pLT,getPI(count1-1,'top',i),topCenter],
  60155. [pLB,getPI(count1-1,'btm',i),btmCenter],
  60156. );
  60157. }
  60158. //不能用else 因为当length==0时u==0也==sideCount[i],此时就是要两个面
  60159. if(u == sideCount[i]){
  60160. faceArr.push([pRT,getPI(0,'top',j),topCenter],
  60161. [pRB,getPI(0,'btm',j),btmCenter],
  60162. );
  60163. }
  60164. }
  60165. }
  60166. }
  60167. };
  60168. let posArr = [];
  60169. let faceArr = [];
  60170. //两点连线的水平向量
  60171. let vec = new Vector3().subVectors(pano0.position, pano1.position).setZ(0).normalize();
  60172. /* let sideDis0 = */addPos(pano0, vec);
  60173. /* let sideDis1 = */addPos(pano1, vec.clone().negate());
  60174. addSide();
  60175. addFaces();
  60176. //MeshDraw.updateGeometry(this.cube.geometry, posArr, faceArr)
  60177. let geo = MeshDraw.createGeometry(posArr, faceArr);
  60178. this.cube.geometry = geo;
  60179. this.cube.scale.set(1,1,1);
  60180. this.cube.position.set(0,0,0);
  60181. if(Potree.settings.testCube){
  60182. this.cubeTest.geometry = geo;
  60183. this.cubeTest.scale.set(1,1,1);
  60184. this.cubeTest.position.set(0,0,0);
  60185. }
  60186. }else {
  60187. useBound(getPanoBound(pano0));
  60188. }
  60189. viewer.addTimeMark('updateCube','end');
  60190. return true
  60191. /*
  60192. 关于卡顿:
  60193. 即使使用cube,若scale设置为只容纳两个pano,也会卡顿。但也是有的卡有的不卡。
  60194. 若按照原先的复杂geo,一般在平直的街道上行走流畅,经过拐弯或者复杂区域较卡。减小geo复杂度没有什么作用。
  60195. 注: 修改skybox,若不准的话,会遮住其他mesh,比如marker。尤其在没有深度贴图时。
  60196. 耗时: chrome: 20+ ,但是firefox:500+ 咋回事 ? iphonex safari: 40+
  60197. */
  60198. }
  60199. })();
  60200. /*
  60201. viewer.images360.flyToPano(viewer.images360.getPano('1765955963253690368|70','sid'))
  60202. viewer.images360.flyToPano(viewer.images360.lastPano)
  60203. */
  60204. /**
  60205. * @author alteredq / http://alteredqualia.com/
  60206. *
  60207. * Full-screen textured quad shader
  60208. */
  60209. let CopyShader = {
  60210. uniforms: {
  60211. "tDiffuse": { value: null },
  60212. "opacity": { value: 1.0 }
  60213. },
  60214. vertexShader: [
  60215. "varying vec2 vUv;",
  60216. "void main() {",
  60217. "vUv = uv;",
  60218. "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  60219. "}"
  60220. ].join( "\n" ),
  60221. fragmentShader: [
  60222. "uniform float opacity;",
  60223. "uniform sampler2D tDiffuse;",
  60224. "varying vec2 vUv;",
  60225. "void main() {",
  60226. "vec4 texel = texture2D( tDiffuse, vUv );", //如果开启premultipliedAlpha用这个,否则用注释的
  60227. "gl_FragColor = opacity * texel;",
  60228. //"gl_FragColor = texture2D( tDiffuse, vUv );",
  60229. //"gl_FragColor.a *= opacity;",
  60230. "}"
  60231. ].join( "\n" )
  60232. };
  60233. /**
  60234. * @author alteredq / http://alteredqualia.com/
  60235. */
  60236. let Pass = function () {
  60237. // if set to true, the pass is processed by the composer
  60238. this.enabled = true;
  60239. // if set to true, the pass indicates to swap read and write buffer after rendering
  60240. this.needsSwap = true;
  60241. // if set to true, the pass clears its buffer before rendering
  60242. this.clear = false;
  60243. // if set to true, the result of the pass is rendered to screen
  60244. this.renderToScreen = false;
  60245. };
  60246. Object.assign( Pass.prototype, {
  60247. setSize: function ( width, height ) {},
  60248. render: function ( renderer, writeBuffer, readBuffer, delta, maskActive ) {
  60249. console.error( 'THREE.Pass: .render() must be implemented in derived pass.' );
  60250. }
  60251. } );
  60252. let ShaderPass = function ( shader, textureID ) {
  60253. Pass.call( this );
  60254. this.textureID = ( textureID !== undefined ) ? textureID : "tDiffuse";
  60255. if ( shader instanceof ShaderMaterial ) {
  60256. this.uniforms = shader.uniforms;
  60257. this.material = shader;
  60258. } else if ( shader ) {
  60259. this.uniforms = UniformsUtils.clone( shader.uniforms );
  60260. this.material = new ShaderMaterial( {
  60261. defines: Object.assign( {}, shader.defines ),
  60262. uniforms: this.uniforms,
  60263. vertexShader: shader.vertexShader,
  60264. fragmentShader: shader.fragmentShader,
  60265. transparent:true,//add
  60266. } );
  60267. }
  60268. this.camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  60269. this.scene = new Scene();
  60270. this.quad = new Mesh( new PlaneBufferGeometry( 2, 2 ), null );
  60271. this.quad.frustumCulled = false; // Avoid getting clipped
  60272. this.scene.add( this.quad );
  60273. };
  60274. ShaderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
  60275. constructor: ShaderPass,
  60276. render: function(scene,camera, viewports, renderer, writeBuffer, readBuffer, delta, maskActive ) {
  60277. let oldTarget = renderer.getRenderTarget();
  60278. /* if(this.readTarget){ //add
  60279. readBuffer = oldTarget
  60280. } */
  60281. if ( this.uniforms[ this.textureID ] ) {
  60282. this.uniforms[ this.textureID ].value = readBuffer.texture;
  60283. }
  60284. this.quad.material = this.material;
  60285. if ( this.renderToScreen ) {
  60286. renderer.render( this.scene, this.camera );
  60287. } else {
  60288. renderer.setRenderTarget(writeBuffer);
  60289. if(this.clear) renderer.clear();
  60290. renderer.render( this.scene, this.camera );
  60291. renderer.setRenderTarget(oldTarget);
  60292. }
  60293. }
  60294. } );
  60295. /* const mapHeight = -1000;//要比点云低。最低
  60296. const cameraHeight = 1000; //最高 */
  60297. const panosHeight = config$1.map.mapHeight + 100; //要比点云低 (marker)
  60298. const cursorHeight = 0;//比地图高就行
  60299. const routeLayerHeight = config$1.map.mapHeight + 105;
  60300. const texLoader$5 = new TextureLoader();
  60301. const planeGeo$1 = new PlaneBufferGeometry(1,1);
  60302. const markerSize = 1;
  60303. var initCameraFeildWidth = 50;
  60304. var panoMarkerMats;
  60305. class MapViewer extends ViewerBase{
  60306. constructor(dom){
  60307. super(dom, {
  60308. clearColor: Potree.config.mapBG,
  60309. name: 'mapViewer',
  60310. antialias:true
  60311. });
  60312. this.visible = true;
  60313. this.initScene();
  60314. this.needRender_ = false;
  60315. this.mapLayer = new MapLayer(this, this.viewports[0]);
  60316. this.scene.add(this.mapLayer.sceneGroup);
  60317. this.mapLayer.sceneGroup.position.setZ(Potree.config.map.mapHeight);
  60318. this.mapRatio = 0.5;
  60319. this.splitDir = 'leftRight';
  60320. this.renderMeasure = false;
  60321. //因context的preserveDrawingBuffer为false之后,canvas渲染多个viewport时会自动clear,所以若不渲染就会是空的。所以没有变化时就直接拷贝buffer好了。
  60322. this.copyPass = new ShaderPass( CopyShader );
  60323. this.copyBuffer = new WebGLRenderTarget( 100, 100 , {
  60324. minFilter: LinearFilter,
  60325. magFilter: LinearFilter,
  60326. format: RGBAFormat,
  60327. stencilBuffer: false,
  60328. });
  60329. viewer.addEventListener("camera_changed", (e)=>{
  60330. let needUpdateCursor;
  60331. if(e.viewport == viewer.mainViewport){
  60332. needUpdateCursor = true;
  60333. }else if(e.viewport == this.viewports[0]){//attachedToViewer
  60334. needUpdateCursor = true;
  60335. this.mapChanged = true;
  60336. this.updateWhenAtViewer();
  60337. e.changeInfo.projectionChanged && this.setViewLimit();
  60338. }
  60339. needUpdateCursor && this.updateCursor();
  60340. });
  60341. this.addEventListener("camera_changed", (e)=>{
  60342. e.changeInfo.projectionChanged && this.setViewLimit();
  60343. });
  60344. //viewer.addEventListener("global_mousemove", this.updateWhenAtViewer.bind(this)) //鼠标移动时reticule也动,所以直接就needRender
  60345. /* viewer.reticule.addEventListener('update',(e)=>{
  60346. if(this.attachedToViewer)this.needRender = true
  60347. }) */
  60348. viewer.scene.addEventListener("360_images_added", this.addPanos.bind(this));
  60349. viewer.addEventListener("loadPointCloudDone", this.initProjection.bind(this));
  60350. this.addEventListener('global_click',(e)=>{
  60351. if(!e.isTouch && e.button != MOUSE.LEFT)return
  60352. this.updateClosestPano(e.intersect);
  60353. });
  60354. this.addEventListener('add',(e)=>{//添加其他mesh
  60355. this.scene.add(e.object);
  60356. if(e.name == 'route'){
  60357. e.object.position.z = routeLayerHeight;
  60358. }
  60359. Potree.Utils.setObjectLayers(e.object, 'mapObjects' );
  60360. });
  60361. viewer.addEventListener('allLoaded',()=>{
  60362. this.setViewLimit('standard');
  60363. });
  60364. if(!Potree.settings.isOfficial){
  60365. let domRoot = viewer.renderer.domElement.parentElement;
  60366. let elAttach = $("<input type='button' value='map绑定'></input>");
  60367. elAttach.css({
  60368. position : "absolute",
  60369. right : '80%',
  60370. bottom: '20px',
  60371. zIndex: "10000",
  60372. fontSize:'1em', color:"black",
  60373. background:'rgba(255,255,255,0.8)',
  60374. });
  60375. let state = false;
  60376. elAttach.on("click", () => {
  60377. state = !state;
  60378. this.attachToMainViewer(state, 'measure');
  60379. elAttach.val(state ? 'map分离':'map绑定');
  60380. });
  60381. domRoot.appendChild(elAttach[0]);
  60382. }
  60383. }
  60384. get needRender(){
  60385. return this.needRender_
  60386. }
  60387. set needRender(n){
  60388. this.needRender_ = n;
  60389. n && (this.viewports[0].needRender = true); //使attachedToViewer时在renderDefault中可渲染
  60390. }
  60391. get mapChanged(){
  60392. return this.mapChanged_
  60393. }
  60394. set mapChanged(c){//镜头移动、地图内容改变都会为true
  60395. this.mapChanged_ = c;
  60396. c && (this.needRender = true);
  60397. }
  60398. waitLoadDone(callback){//确保加载完后执行
  60399. let timer; //等待一段时间看有没有新加载的tile,如果超过这个时间没有就不等了,算加载结束
  60400. let pauseCountDown = ()=>{//重新等待加载结束,中断倒计时
  60401. clearTimeout(timer);
  60402. //console.log('pauseCountDown')
  60403. };
  60404. let freshCountDown = ()=>{//刷新倒计时
  60405. //console.log('freshCountDown')
  60406. clearTimeout(timer);
  60407. timer = setTimeout(()=>{
  60408. this.mapLayer.removeEventListener('loadDone', freshCountDown);
  60409. this.mapLayer.removeEventListener('startLoad', pauseCountDown);
  60410. callback();
  60411. }, document.hidden ? 5000 : 500);
  60412. };
  60413. this.mapLayer.addEventListener('loadDone', freshCountDown);
  60414. this.mapLayer.addEventListener('startLoad', pauseCountDown);
  60415. if(this.mapLayer.loadingInProgress == 0){
  60416. freshCountDown();
  60417. }
  60418. }
  60419. addListener(images360){
  60420. images360.addEventListener('flyToPano',e=>{
  60421. let toPano = e.toPano;
  60422. if(toPano.dontMoveMap) return
  60423. /* transitions.start(lerp.vector(this.view.position, toPano.pano.position.clone().setZ(cameraHeight),
  60424. (pos, progress)=>{
  60425. }), toPano.duration, null, 0, easing[toPano.easeName] ); */
  60426. let boundSize;// = new THREE.Vector2(10,10)
  60427. this.moveTo(toPano.pano.position.clone().setZ(Potree.config.map.cameraHeight), boundSize, toPano.duration, null, toPano.easeName);
  60428. });
  60429. }
  60430. initProjection(){
  60431. this.started = true;
  60432. this.mapLayer.initProjection();
  60433. }
  60434. initScene(){
  60435. let w = initCameraFeildWidth;
  60436. let width = this.renderArea.clientWidth;
  60437. let height = this.renderArea.clientHeight;
  60438. //let aspect = width / height
  60439. 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);
  60440. this.camera.zoom = width / w; //zoom越大视野越小
  60441. //this.camera.position.set(0,0,10);
  60442. this.camera.up.set(0,0,1);
  60443. //this.camera.lookAt(new THREE.Vector3())
  60444. //this.camera.updateMatrixWorld()
  60445. this.view = new ExtendView();
  60446. this.view.position.set(0,0,Potree.config.map.cameraHeight);
  60447. this.view.lookAt(0,0,0);
  60448. let viewport = new Viewport( this.view, this.camera, {
  60449. left:0, bottom:0, width:1, height: 1, name:'mapViewport'
  60450. });
  60451. viewport.axis = ["x","y"];
  60452. viewport.axisSign = [1,1];
  60453. viewport.noPointcloud = true; //不要渲染点云
  60454. viewport.render = this.render.bind(this);//标志给mainView渲染
  60455. //viewport.unableDepth = true //depthBasicMaterial等在此viewport中不开启depth
  60456. viewport.addEventListener('resize',()=>{
  60457. this.copyBuffer.setSize(viewport.resolution2.x, viewport.resolution2.y);
  60458. });
  60459. this.viewports = [viewport];
  60460. this.controls = new FirstPersonControls(this, this.viewports[0]);
  60461. this.controls.setEnable(true);
  60462. this.scene = new Scene();
  60463. this.inputHandler = new InputHandler(this, this.scene);
  60464. this.inputHandler.name = 'mapInputHandler';
  60465. //this.inputHandler.addInputListener(this.controls);
  60466. this.inputHandler.registerInteractiveScene(this.scene);//interactiveScenes
  60467. this.viewports[0].interactiveScenes = this.inputHandler.interactiveScenes;//供viewer的inputHandler使用
  60468. var cursor = new Mesh(planeGeo$1, new MeshBasicMaterial({
  60469. transparent:true,
  60470. opacity:0.9,
  60471. depthTest : false, //防止透明冲突
  60472. map: texLoader$5.load(Potree.resourcePath+'/textures/pic_location128.png' )
  60473. }));
  60474. cursor.position.set(0,0,cursorHeight);
  60475. this.cursor = cursor;
  60476. this.scene.add(cursor);
  60477. Potree.Utils.setObjectLayers(this.scene, 'mapObjects' );
  60478. }
  60479. setViewLimit(state){//设置边界,当编辑空间模型等时要解禁
  60480. if(!state)state = this.limitBoundState;
  60481. if(!state)return
  60482. this.limitBoundState = state;
  60483. let setting = Potree.config.OrthoCameraLimit[state];
  60484. if(setting){
  60485. this.camera.zoomLimit = $.extend({},setting.zoom);
  60486. let lonlatCenter = viewer.transform.lonlatToLocal.inverse([0,0]);
  60487. let minY = viewer.transform.lonlatToLocal.forward([lonlatCenter[0], -90+setting.latPad])[1]; //屏幕边界的bound
  60488. let maxY = viewer.transform.lonlatToLocal.forward([lonlatCenter[0], 90-setting.latPad])[1];
  60489. /*this.view.limitBound = new THREE.Box3(
  60490. new THREE.Vector3(setting.xBound[0], minY, Potree.config.map.cameraHeight),
  60491. new THREE.Vector3(setting.xBound[1], maxY, 1 / 0)
  60492. ) */
  60493. let halfHeight = this.viewports[0].resolution.y / 2 / this.camera.zoom;//屏幕所占高度的一半
  60494. let halfWidth = this.viewports[0].resolution.x / 2 / this.camera.zoom;
  60495. this.view.limitBound = new Box3(
  60496. new Vector3(setting.xBound[0]+halfWidth, minY+halfHeight, Potree.config.map.cameraHeight),
  60497. new Vector3(setting.xBound[1]-halfWidth, maxY-halfHeight, 1 / 0)
  60498. );
  60499. }else {
  60500. this.view.limitBound = null;
  60501. this.camera.zoomLimit = null;
  60502. }
  60503. }
  60504. updateCursor(){
  60505. //console.log('pos', viewer.mainViewport.camera.position.toArray() )
  60506. var scale = math.getScaleForConstantSize( {//规定下最小最大像素
  60507. minSize : 80, maxSize : 200, nearBound : initCameraFeildWidth*0.1 , farBound : initCameraFeildWidth*2,
  60508. camera:this.camera , position: this.cursor.getWorldPosition(new Vector3()),
  60509. resolution: this.viewports[0].resolution//2
  60510. });
  60511. this.cursor.scale.set(scale, scale, scale);//当地图缩放时
  60512. this.cursor.position.copy(viewer.mainViewport.camera.position).setZ(cursorHeight);//当场景镜头旋转移动时
  60513. this.cursor.rotation.z = viewer.mainViewport.view.yaw;
  60514. this.needRender = true;
  60515. }
  60516. addPanos(e){
  60517. var panosGroup = new Object3D; panosGroup.name = 'markers';
  60518. panoMarkerMats = {
  60519. default: new MeshBasicMaterial({
  60520. transparent:true,
  60521. opacity: 0.5,
  60522. map: texLoader$5.load(Potree.resourcePath+'/textures/map_marker.png' ),
  60523. }),
  60524. selected: new MeshBasicMaterial({
  60525. transparent:true,
  60526. opacity: 1,
  60527. map: texLoader$5.load(Potree.resourcePath+'/textures/map_marker.png' ),
  60528. })
  60529. };
  60530. e.images.panos.forEach(pano=>{
  60531. pano.mapMarker = new Mesh(planeGeo$1, panoMarkerMats.default);
  60532. pano.mapMarker.position.copy(pano.position).setZ(0);
  60533. pano.mapMarker.scale.set(markerSize,markerSize,markerSize);
  60534. pano.mapMarker.name = 'mapMarker';
  60535. panosGroup.add(pano.mapMarker);
  60536. let mouseover = (e)=>{
  60537. if(!e.byMap){
  60538. pano.mapMarker.material = panoMarkerMats.selected;
  60539. if(!e.byMainView) pano.dispatchEvent({type: "hoverOn", byMap:true});
  60540. this.needRender = true;
  60541. }
  60542. };
  60543. let mouseleave = (e)=>{
  60544. if(!e.byMap){
  60545. pano.mapMarker.material = panoMarkerMats.default;
  60546. if(!e.byMainView) pano.dispatchEvent({type: "hoverOff", byMap:true});
  60547. this.needRender = true;
  60548. }
  60549. };
  60550. pano.mapMarker.addEventListener('mouseover', mouseover);
  60551. pano.mapMarker.addEventListener('mouseleave', mouseleave);
  60552. pano.addEventListener('hoverOn', mouseover);
  60553. pano.addEventListener('hoverOff', mouseleave);
  60554. let onclick = (e)=>{
  60555. viewer.images360.flyToPano(pano);
  60556. };
  60557. pano.mapMarker.addEventListener('click', onclick);
  60558. pano.addEventListener('isVisible',(e)=>{//是否显示该点的mesh(不显示也能走)
  60559. //console.log('panoMarker isVisible', pano.id, e.visible)
  60560. Potree.Utils.updateVisible(pano.mapMarker, 'panoVisible', e.visible );
  60561. this.needRender = true;
  60562. });
  60563. pano.addEventListener('rePos',(e)=>{
  60564. pano.mapMarker.position.copy(pano.position).setZ(0);
  60565. });
  60566. });
  60567. this.scene.add(panosGroup);
  60568. panosGroup.position.z = panosHeight;
  60569. this.panosGroup = panosGroup;
  60570. Potree.Utils.setObjectLayers(panosGroup, 'mapObjects' );
  60571. /* e.images.on('markersDisplayChange', (show)=>{
  60572. panosGroup.visible = show
  60573. this.needRender = true
  60574. }) */
  60575. //-------
  60576. //this.fitPanosToViewport()
  60577. this.initFitView();
  60578. }
  60579. updateClosestPano(intersect){
  60580. if(viewer.images360.flying)return;
  60581. intersect = intersect && intersect.orthoIntersect;
  60582. if(!intersect)return
  60583. intersect = intersect.clone().setZ(0);
  60584. const minDis = 20; //距离鼠标不能太远
  60585. var filterFuncs = [
  60586. Images360.filters.isEnabled(),
  60587. Images360.filters.isVisible(),//只走显示的点,否则会走到别的层
  60588. (pano)=>{
  60589. return pano.position.clone().setZ(0).distanceTo(intersect) < minDis
  60590. },
  60591. ];
  60592. var pano = Common.find(viewer.images360.panos, filterFuncs, [Images360.sortFunctions.floorDisSquaredToPoint(intersect)]);
  60593. if (pano && pano != viewer.images360.currentPano ) {
  60594. viewer.images360.flyToPano(pano);
  60595. }
  60596. }
  60597. fitPanosToViewport(){//使所有漫游点占满viewport
  60598. //var w = viewer.bound.boundSize.x;
  60599. var boundSize = viewer.images360.bound.size.clone().multiplyScalar(1.1);
  60600. boundSize.max(new Vector3(4,4,4));
  60601. let endPosition = viewer.images360.bound.center.clone();
  60602. this.moveTo(endPosition, boundSize, 0);
  60603. }
  60604. fitToPointcloud(pointcloud, duration=400){
  60605. var boundSize = pointcloud.bound.getSize(new Vector3);/* .multiplyScalar(1.1); */
  60606. boundSize.max(new Vector3(4,4,4));
  60607. let endPosition = pointcloud.bound.getCenter(new Vector3);
  60608. this.moveTo(endPosition, boundSize, duration); //给点duration去变化 否则地图放大后所占的还是很小
  60609. }
  60610. initFitView(){
  60611. let dis = 5 , px = 70; //地图上px像素长度代表的距离为dis //px是手动缩放到5m后发现是这个长度
  60612. let zoom = px / dis;
  60613. this.camera.zoom = zoom;
  60614. this.moveTo(viewer.images360.position/* viewer.images360.bound.center */);
  60615. this.camera.updateProjectionMatrix();
  60616. }
  60617. fitToDatasets(datasets){
  60618. let bound = new Box3;
  60619. datasets.forEach(e=>bound.union(e.bound));
  60620. let center = bound.getCenter(new Vector3);
  60621. let size = bound.getSize(new Vector3);
  60622. this.moveTo(center, size, 200 ); //给duration是为了顺应视口大小改变,缓冲
  60623. }
  60624. moveTo(endPosition, boundSize, duration=0, margin, easeName, callback ){//前两个参数有xy即可
  60625. endPosition = new Vector3(endPosition.x,endPosition.y,Potree.config.map.cameraHeight);
  60626. this.view.moveOrthoCamera(this.viewports[0], {endPosition, boundSize, margin, callback}, duration, easeName);
  60627. /* let endZoom, startZoom = this.camera.zoom
  60628. //修改相机为bound中心,这样能看到全部(宽度范围内)
  60629. this.view.setView({ position:endPosition, duration,
  60630. callback:()=>{//done
  60631. },
  60632. onUpdate:(progress)=>{
  60633. if(boundSize){
  60634. let aspect = boundSize.x / boundSize.y
  60635. let w, h;
  60636. if(this.camera.aspect > aspect){//视野更宽则用bound的纵向来决定
  60637. h = boundSize.y
  60638. //w = h * this.camera.aspect
  60639. endZoom = this.viewports[0].resolution.y / h
  60640. }else{
  60641. w = boundSize.x;
  60642. //h = w / this.camera.aspect
  60643. endZoom = this.viewports[0].resolution.x / w
  60644. }
  60645. //onUpdate时更新endzoom是因为画布大小可能更改
  60646. this.camera.zoom = endZoom * progress + startZoom * (1 - progress)
  60647. this.camera.updateProjectionMatrix()
  60648. }
  60649. },
  60650. Easing:easeName
  60651. }) */
  60652. }
  60653. updateWhenAtViewer(e){//两个触发来源: 1 camera_changed时 2 mapLayer.needUpdate时。 render在viewer中执行
  60654. if(this.attachedToViewer){
  60655. if(this.started) this.mapLayer.update();
  60656. this.needRender = true;
  60657. }
  60658. }
  60659. update(delta, areaSize ){
  60660. if(!this.visible && !this.attachedToViewer )return
  60661. if(this.attachedToViewer){
  60662. if(this.mapLayer.needUpdate){
  60663. this.updateWhenAtViewer();
  60664. }
  60665. return
  60666. }
  60667. this.updateScreenSize();
  60668. this.controls.update(delta);
  60669. this.view.applyToCamera(this.camera);
  60670. let changed = this.cameraChanged();
  60671. if(this.started && (changed || this.mapLayer.needUpdate))this.mapLayer.update();
  60672. if(changed /*|| || this.needRender */){
  60673. /* this.dispatchEvent({
  60674. type: "camera_changed",
  60675. camera: this.camera,
  60676. viewport : this.viewports[0]
  60677. }) */
  60678. this.mapChanged = true;
  60679. this.needRender = true;
  60680. this.updateCursor();//更改大小
  60681. }
  60682. this.render();
  60683. }
  60684. attachToMainViewer(state, desc, mapRatio=0.5, options={}){//转移到viewer中。测量时展示or截图需要
  60685. if(!Potree.settings.isOfficial)this.renderArea.style.display = state ? 'none':'block';
  60686. if(state){
  60687. this.enabledOld = this.enabled;
  60688. this.enabled = true;
  60689. if(mapRatio != 'dontSet'){
  60690. this.changeSplitScreenDir(options.dir, mapRatio);
  60691. if(this.attachedToViewer){
  60692. //this.fitPanosToViewport()
  60693. viewer.updateScreenSize({forceUpdateSize:true});
  60694. return
  60695. }
  60696. viewer.viewports = [viewer.mainViewport, viewer.mapViewer.viewports[0] ];//因为mainViewer的相机变化会触发map的变化,所以先渲染mainViewer
  60697. }
  60698. if(desc == 'measure') this.inputHandler.registerInteractiveScene(viewer.measuringTool.scene);//虽然用的是viewer的inputHandler,但借用了this.inputHandler的interactiveScenes
  60699. else if(desc == 'split4Screens') {
  60700. this.inputHandler.registerInteractiveScene(viewer.scene.scene);
  60701. }
  60702. }else {
  60703. if(!this.attachedToViewer)return
  60704. viewer.mainViewport.left = 0;
  60705. viewer.mainViewport.bottom = 0;
  60706. viewer.mainViewport.width = 1;
  60707. viewer.mainViewport.height = 1;
  60708. this.viewports[0].width = 1;
  60709. this.viewports[0].bottom = 0;
  60710. this.viewports[0].height = 1;
  60711. this.viewports[0].left = 0;
  60712. this.renderMeasure || this.inputHandler.unregisterInteractiveScene(viewer.measuringTool.scene);
  60713. this.inputHandler.unregisterInteractiveScene(viewer.scene.scene);
  60714. viewer.viewports = [viewer.mainViewport];
  60715. this.updateScreenSize({forceUpdateSize:true}); //更新相机projectionMatrix
  60716. }
  60717. //if(desc == 'measure')this.renderMeasure = state
  60718. this.attachedToViewer = state;
  60719. viewer.updateScreenSize({forceUpdateSize:true});
  60720. //mapRatio != 'dontSet' && !options.dontFit && this.moveTo(...)//要写在updateScreenSize后面,因为要根据视图大小来fit
  60721. if(options.moveToCurrentPos){
  60722. let boundSize = new Vector2(10,10);
  60723. let duration = 1000;
  60724. this.moveTo(viewer.images360.position.clone(), boundSize, duration);
  60725. }
  60726. this.needRender = true;
  60727. }
  60728. setDrawMeasure(draw){
  60729. this.renderMeasure = !!draw;
  60730. if(draw){
  60731. this.inputHandler.registerInteractiveScene(viewer.measuringTool.scene);
  60732. }else {
  60733. this.inputHandler.unregisterInteractiveScene(viewer.measuringTool.scene);
  60734. }
  60735. }
  60736. changeSplitScreenDir(dir, mapRatio){//左右 | 上下
  60737. //if(!dir || dir == this.dir)return
  60738. if(dir )this.splitDir = dir;
  60739. this.updateSplitSize(mapRatio);
  60740. /* if(this.attachedToViewer){ //如果已经分屏了,中途修改方向的话……
  60741. this.updateSplitSize()
  60742. } */
  60743. }
  60744. updateSplitSize(mapRatio){
  60745. if(mapRatio != void 0) this.mapRatio = mapRatio;
  60746. //console.log(this.mapRatio)
  60747. if(this.splitDir == 'leftRight'){//地图在左方
  60748. viewer.mainViewport.left = this.mapRatio;
  60749. viewer.mainViewport.width = 1-this.mapRatio;
  60750. this.viewports[0].width = this.mapRatio;
  60751. viewer.mainViewport.bottom = this.viewports[0].bottom = 0;
  60752. viewer.mainViewport.height = this.viewports[0].height = 1;
  60753. }else if(this.splitDir == 'upDown'){ //地图在下方
  60754. viewer.mainViewport.bottom = this.mapRatio;
  60755. viewer.mainViewport.height = 1-this.mapRatio;
  60756. this.viewports[0].height = this.mapRatio;
  60757. viewer.mainViewport.left = this.viewports[0].left = 0;
  60758. viewer.mainViewport.width = this.viewports[0].width = 1;
  60759. }
  60760. if(this.attachedToViewer){
  60761. viewer.updateScreenSize({forceUpdateSize:true});
  60762. }
  60763. }
  60764. render1(params={}){//viewer的preserveDrawingBuffer为false时的版本
  60765. let needCopy, waitCopy;
  60766. if(!this.visible && !this.attachedToViewer || !this.needRender && !params.force){
  60767. if(this.attachedToViewer ){
  60768. needCopy = true;
  60769. }else {
  60770. return
  60771. }
  60772. }
  60773. waitCopy = this.attachedToViewer && this.needRender && !params.force;//是否写入到copyBuffer。双屏时,若needRender就拷贝到copyBuffer中,双屏时就直接使用copyBuffer。 四屏时因渲染点云会每帧都渲染,所以不需要缓存。
  60774. let renderer = params.renderer || this.renderer;
  60775. if(waitCopy){
  60776. this.copyBuffer.setSize(params.viewport.resolution2.x, params.viewport.resolution2.y);
  60777. renderer.setRenderTarget(this.copyBuffer);
  60778. }else if(params.target){
  60779. renderer.setRenderTarget(params.target);
  60780. }
  60781. /* if(params.resize){
  60782. this.emitResizeMsg(new THREE.Vector2(params.width,params.height, viewport:params.viewport))
  60783. } */
  60784. params.clear ? params.clear() : renderer.clear();
  60785. if(!needCopy || waitCopy){//重绘
  60786. viewer.dispatchEvent({type: "render.begin", viewer: this, viewport:this.viewports[0], params });
  60787. Potree.Utils.setCameraLayers(this.camera, ['map','mapObjects' , 'bothMapAndScene' ]);
  60788. if(this.mapGradientBG){//渲染背景
  60789. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg);
  60790. renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  60791. }
  60792. renderer.render(this.scene, this.camera);
  60793. renderer.render(viewer.scene.scene, this.camera);
  60794. //测量线等
  60795. //params.renderOverlay && params.renderOverlay( $.extend({}, params, { isMap:true }))
  60796. renderer.setRenderTarget(params.target||null);
  60797. }
  60798. if(needCopy || waitCopy){//使用缓存 ----当viewer的preserveDrawingBuffer为false的话,使用buffer
  60799. this.copyPass.render(null,null, null, renderer, params.target||null, this.copyBuffer);
  60800. }
  60801. this.needRender = false;
  60802. return true
  60803. }
  60804. clear(params){
  60805. if(this.transparentBG){
  60806. this.renderer.setClearColor( 0x000000, 0 );
  60807. }else {
  60808. this.renderer.setClearColor( Potree.config.mapBG, 1 );
  60809. }
  60810. (params.renderer || this.renderer).clear();
  60811. }
  60812. //拆成两次渲染,一个地图一个其他物体,且地图渲染后保存在buffer中,只有当地图变化后才重渲染。
  60813. render(params={}){
  60814. if(!this.visible && !this.attachedToViewer || !this.needRender && !params.force){ //注意:mapViewer.needRender的权重高于它的viewport的needRender,也就是说,当attachedToViewer时,viewer即使needRender, mapViewer也不一定会渲染。
  60815. return
  60816. }
  60817. viewer.addTimeMark('mapRender','start');
  60818. let renderer = params.renderer || this.renderer;
  60819. if(this.mapChanged){ //渲染地图背景
  60820. renderer.setRenderTarget(this.copyBuffer);
  60821. params.clear ? params.clear(params) : this.clear(params);
  60822. if(this.mapGradientBG){//渲染背景
  60823. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg);
  60824. renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  60825. }
  60826. Potree.Utils.setCameraLayers(this.camera, ['map']);
  60827. renderer.render(this.scene, this.camera);
  60828. params.renderBG && params.renderBG(this.viewports[0]);
  60829. this.mapChanged = false;
  60830. renderer.setRenderTarget(params.target||null);
  60831. }
  60832. params.clear ? params.clear(params) : this.clear(params);
  60833. this.copyPass.render(null,null, null,renderer, params.target||null, this.copyBuffer); //拷贝地图背景
  60834. renderer.clearDepth(); //防止地图遮挡其他物体
  60835. //绘制其他物体
  60836. Potree.Utils.setCameraLayers(this.camera, ['mapObjects' , 'bothMapAndScene' ]);
  60837. viewer.dispatchEvent({type: "render.begin", viewer: this, viewport:this.viewports[0], params });
  60838. this.attachedToViewer || renderer.render(viewer.scene.scene, this.camera); //类同renderOverlay
  60839. renderer.render(this.scene, this.camera);
  60840. if(!this.attachedToViewer && this.renderMeasure){//在未attach到主页面时也要渲染测量线
  60841. viewer.dispatchEvent({type: "render.pass.perspective_overlay", camera:this.camera, /* screenshot:params.screenshot, */viewport:this.viewports[0], renderer});
  60842. }
  60843. renderer.setRenderTarget(null);
  60844. this.needRender = false;
  60845. viewer.addTimeMark('mapRender','end');
  60846. return true
  60847. }
  60848. renderOverlay(){//偶尔需要绘制测量线
  60849. viewer.renderOverlay({
  60850. camera: this.camera, viewport:this.viewports[0], renderer:this.renderer
  60851. });
  60852. }
  60853. }
  60854. /*
  60855. 渲染顺序:
  60856. 地图
  60857. 背景Overlay
  60858. 地图scene的物体,如cursor、 marker
  60859. 点云(如果有)
  60860. overlay,两层:第一层:viewer的scene中bothMapAndScene的如reticule. 第二层:如测量线(attachToMainViewer时才渲染)
  60861. */
  60862. //本地调试地图白屏是因为代码自动更新了 但没刷新
  60863. class U {
  60864. static toVector3(v, offset) {
  60865. return new Vector3().fromArray(v, offset || 0);
  60866. }
  60867. static toBox3(b) {
  60868. return new Box3(U.toVector3(b), U.toVector3(b, 3));
  60869. };
  60870. static findDim(schema, name) {
  60871. var dim = schema.find((dim) => dim.name == name);
  60872. if (!dim) throw new Error('Failed to find ' + name + ' in schema');
  60873. return dim;
  60874. }
  60875. static sphereFrom(b) {
  60876. return b.getBoundingSphere(new Sphere());
  60877. }
  60878. };
  60879. class PointCloudEptGeometry {
  60880. constructor(url, info) {
  60881. let version = info.version;
  60882. let schema = info.schema;
  60883. let bounds = info.bounds;
  60884. let boundsConforming = info.boundsConforming;
  60885. let xyz = [
  60886. U.findDim(schema, 'X'),
  60887. U.findDim(schema, 'Y'),
  60888. U.findDim(schema, 'Z')
  60889. ];
  60890. let scale = xyz.map((d) => d.scale || 1);
  60891. let offset = xyz.map((d) => d.offset || 0);
  60892. this.eptScale = U.toVector3(scale);
  60893. this.eptOffset = U.toVector3(offset);
  60894. this.url = url;
  60895. this.info = info;
  60896. this.type = 'ept';
  60897. this.schema = schema;
  60898. this.span = info.span || info.ticks;
  60899. this.boundingBox = U.toBox3(bounds);
  60900. this.tightBoundingBox = U.toBox3(boundsConforming);
  60901. this.offset = U.toVector3([0, 0, 0]);
  60902. this.boundingSphere = U.sphereFrom(this.boundingBox);
  60903. this.tightBoundingSphere = U.sphereFrom(this.tightBoundingBox);
  60904. this.version = new Potree.Version('1.7');
  60905. this.projection = null;
  60906. this.fallbackProjection = null;
  60907. if (info.srs && info.srs.horizontal) {
  60908. this.projection = info.srs.authority + ':' + info.srs.horizontal;
  60909. }
  60910. if (info.srs.wkt) {
  60911. if (!this.projection) this.projection = info.srs.wkt;
  60912. else this.fallbackProjection = info.srs.wkt;
  60913. }
  60914. {
  60915. // TODO [mschuetz]: named projections that proj4 can't handle seem to cause problems.
  60916. // remove them for now
  60917. try{
  60918. proj4(this.projection);
  60919. }catch(e){
  60920. this.projection = null;
  60921. }
  60922. }
  60923. {
  60924. const attributes = new PointAttributes();
  60925. attributes.add(PointAttribute.POSITION_CARTESIAN);
  60926. attributes.add(new PointAttribute("rgba", PointAttributeTypes.DATA_TYPE_UINT8, 4));
  60927. attributes.add(new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  60928. attributes.add(new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  60929. attributes.add(new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1));
  60930. attributes.add(new PointAttribute("returnNumber", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  60931. attributes.add(new PointAttribute("number of returns", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  60932. attributes.add(new PointAttribute("return number", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  60933. attributes.add(new PointAttribute("source id", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  60934. this.pointAttributes = attributes;
  60935. }
  60936. this.spacing =
  60937. (this.boundingBox.max.x - this.boundingBox.min.x) / this.span;
  60938. let hierarchyType = info.hierarchyType || 'json';
  60939. const dataType = info.dataType;
  60940. if (dataType == 'laszip') {
  60941. this.loader = new Potree.EptLaszipLoader();
  60942. }
  60943. else if (dataType == 'binary') {
  60944. this.loader = new Potree.EptBinaryLoader();
  60945. }
  60946. else if (dataType == 'zstandard') {
  60947. this.loader = new Potree.EptZstandardLoader();
  60948. }
  60949. else {
  60950. throw new Error('Could not read data type: ' + dataType);
  60951. }
  60952. }
  60953. };
  60954. class EptKey {
  60955. constructor(ept, b, d, x, y, z) {
  60956. this.ept = ept;
  60957. this.b = b;
  60958. this.d = d;
  60959. this.x = x || 0;
  60960. this.y = y || 0;
  60961. this.z = z || 0;
  60962. }
  60963. name() {
  60964. return this.d + '-' + this.x + '-' + this.y + '-' + this.z;
  60965. }
  60966. step(a, b, c) {
  60967. let min = this.b.min.clone();
  60968. let max = this.b.max.clone();
  60969. let dst = new Vector3().subVectors(max, min);
  60970. if (a) min.x += dst.x / 2;
  60971. else max.x -= dst.x / 2;
  60972. if (b) min.y += dst.y / 2;
  60973. else max.y -= dst.y / 2;
  60974. if (c) min.z += dst.z / 2;
  60975. else max.z -= dst.z / 2;
  60976. return new Potree.EptKey(
  60977. this.ept,
  60978. new Box3(min, max),
  60979. this.d + 1,
  60980. this.x * 2 + a,
  60981. this.y * 2 + b,
  60982. this.z * 2 + c);
  60983. }
  60984. children() {
  60985. var result = [];
  60986. for (var a = 0; a < 2; ++a) {
  60987. for (var b = 0; b < 2; ++b) {
  60988. for (var c = 0; c < 2; ++c) {
  60989. var add = this.step(a, b, c).name();
  60990. if (!result.includes(add)) result = result.concat(add);
  60991. }
  60992. }
  60993. }
  60994. return result;
  60995. }
  60996. }
  60997. class PointCloudEptGeometryNode extends PointCloudTreeNode {
  60998. constructor(ept, b, d, x, y, z) {
  60999. super();
  61000. this.ept = ept;
  61001. this.key = new Potree.EptKey(
  61002. this.ept,
  61003. b || this.ept.boundingBox,
  61004. d || 0,
  61005. x,
  61006. y,
  61007. z);
  61008. this.id = PointCloudEptGeometryNode.IDCount++;
  61009. this.geometry = null;
  61010. this.boundingBox = this.key.b;
  61011. this.tightBoundingBox = this.boundingBox;
  61012. this.spacing = this.ept.spacing / Math.pow(2, this.key.d);
  61013. this.boundingSphere = U.sphereFrom(this.boundingBox);
  61014. // These are set during hierarchy loading.
  61015. this.hasChildren = false;
  61016. this.children = { };
  61017. this.numPoints = -1;
  61018. this.level = this.key.d;
  61019. this.loaded = false;
  61020. this.loading = false;
  61021. this.oneTimeDisposeHandlers = [];
  61022. let k = this.key;
  61023. this.name = this.toPotreeName(k.d, k.x, k.y, k.z);
  61024. this.index = parseInt(this.name.charAt(this.name.length - 1));
  61025. }
  61026. isGeometryNode() { return true; }
  61027. getLevel() { return this.level; }
  61028. isTreeNode() { return false; }
  61029. isLoaded() { return this.loaded; }
  61030. getBoundingSphere() { return this.boundingSphere; }
  61031. getBoundingBox() { return this.boundingBox; }
  61032. url() { return this.ept.url + 'ept-data/' + this.filename(); }
  61033. getNumPoints() { return this.numPoints; }
  61034. filename() { return this.key.name(); }
  61035. getChildren() {
  61036. let children = [];
  61037. for (let i = 0; i < 8; i++) {
  61038. if (this.children[i]) {
  61039. children.push(this.children[i]);
  61040. }
  61041. }
  61042. return children;
  61043. }
  61044. addChild(child) {
  61045. this.children[child.index] = child;
  61046. child.parent = this;
  61047. }
  61048. load() {
  61049. if (this.loaded || this.loading) return;
  61050. if (Potree.numNodesLoading >= Potree.maxNodesLoading) return;
  61051. this.loading = true;
  61052. ++Potree.numNodesLoading;
  61053. if (this.numPoints == -1) this.loadHierarchy();
  61054. this.loadPoints();
  61055. }
  61056. loadPoints(){
  61057. this.ept.loader.load(this);
  61058. }
  61059. async loadHierarchy() {
  61060. let nodes = { };
  61061. nodes[this.filename()] = this;
  61062. this.hasChildren = false;
  61063. let eptHierarchyFile =
  61064. `${this.ept.url}ept-hierarchy/${this.filename()}.json`;
  61065. let response = await fetch(eptHierarchyFile);
  61066. let hier = await response.json();
  61067. // Since we want to traverse top-down, and 10 comes
  61068. // lexicographically before 9 (for example), do a deep sort.
  61069. var keys = Object.keys(hier).sort((a, b) => {
  61070. let [da, xa, ya, za] = a.split('-').map((n) => parseInt(n, 10));
  61071. let [db, xb, yb, zb] = b.split('-').map((n) => parseInt(n, 10));
  61072. if (da < db) return -1; if (da > db) return 1;
  61073. if (xa < xb) return -1; if (xa > xb) return 1;
  61074. if (ya < yb) return -1; if (ya > yb) return 1;
  61075. if (za < zb) return -1; if (za > zb) return 1;
  61076. return 0;
  61077. });
  61078. keys.forEach((v) => {
  61079. let [d, x, y, z] = v.split('-').map((n) => parseInt(n, 10));
  61080. let a = x & 1, b = y & 1, c = z & 1;
  61081. let parentName =
  61082. (d - 1) + '-' + (x >> 1) + '-' + (y >> 1) + '-' + (z >> 1);
  61083. let parentNode = nodes[parentName];
  61084. if (!parentNode) return;
  61085. parentNode.hasChildren = true;
  61086. let key = parentNode.key.step(a, b, c);
  61087. let node = new Potree.PointCloudEptGeometryNode(
  61088. this.ept,
  61089. key.b,
  61090. key.d,
  61091. key.x,
  61092. key.y,
  61093. key.z);
  61094. node.level = d;
  61095. node.numPoints = hier[v];
  61096. parentNode.addChild(node);
  61097. nodes[key.name()] = node;
  61098. });
  61099. }
  61100. doneLoading(bufferGeometry, tightBoundingBox, np, mean) {
  61101. bufferGeometry.boundingBox = this.boundingBox;
  61102. this.geometry = bufferGeometry;
  61103. this.tightBoundingBox = tightBoundingBox;
  61104. this.numPoints = np;
  61105. this.mean = mean;
  61106. this.loaded = true;
  61107. this.loading = false;
  61108. --Potree.numNodesLoading;
  61109. }
  61110. toPotreeName(d, x, y, z) {
  61111. var name = 'r';
  61112. for (var i = 0; i < d; ++i) {
  61113. var shift = d - i - 1;
  61114. var mask = 1 << shift;
  61115. var step = 0;
  61116. if (x & mask) step += 4;
  61117. if (y & mask) step += 2;
  61118. if (z & mask) step += 1;
  61119. name += step;
  61120. }
  61121. return name;
  61122. }
  61123. dispose() {
  61124. if (this.geometry && this.parent != null) {
  61125. this.geometry.dispose();
  61126. this.geometry = null;
  61127. this.loaded = false;
  61128. // this.dispatchEvent( { type: 'dispose' } );
  61129. for (let i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
  61130. let handler = this.oneTimeDisposeHandlers[i];
  61131. handler();
  61132. }
  61133. this.oneTimeDisposeHandlers = [];
  61134. }
  61135. }
  61136. }
  61137. PointCloudEptGeometryNode.IDCount = 0;
  61138. class ExtendPointCloudOctree extends PointCloudOctree{
  61139. constructor(geometry, material){
  61140. material = material || new ExtendPointCloudMaterial();
  61141. super(geometry, material);
  61142. //xzw move from material 。 adaptive_point_size才使用
  61143. /* this.visibleNodesTexture = Utils.generateDataTexture(2048, 1, new THREE.Color(0xffffff));
  61144. this.visibleNodesTexture.minFilter = THREE.NearestFilter;
  61145. this.visibleNodesTexture.magFilter = THREE.NearestFilter; */
  61146. this.boundingBox = this.pcoGeometry.tightBoundingBox;//this.pcoGeometry.boundingBox; //boundingBox是正方体,所以换掉
  61147. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  61148. this.nodeMaxLevel = 0;//add
  61149. if (!this.pcoGeometry.loader.version.equalOrHigher('1.5')) {//las 一级一级增长的,但是testNodeMaxLevel时需要大于0
  61150. this.nodeMaxLevel = 1;//add
  61151. }
  61152. this.maxLevel = Infinity;
  61153. this.temp = { sizeFitToLevel:{}, opacity:{}};//add
  61154. //add
  61155. this.panos = [];
  61156. this.matrixAutoUpdate = false; //最好禁止updateMatrix 直接使用matrixWorld
  61157. this.orientationUser = 0;
  61158. this.translateUser = new Vector3;
  61159. this.rotateMatrix = new Matrix4;
  61160. this.transformMatrix = new Matrix4;// 数据集的变化矩阵
  61161. this.transformInvMatrix = new Matrix4;
  61162. /* this.transformMatrix2 = new THREE.Matrix4;// 数据集的变化矩阵
  61163. this.transformInvMatrix2 = new THREE.Matrix4; */
  61164. this.rotateInvMatrix = new Matrix4;
  61165. this.material.spacing = this.pcoGeometry.spacing;//初始化一下 以便于设置pointsize
  61166. this.nodeMaxLevelPredict = this.predictNodeMaxLevel();//预测maxNodeLevel
  61167. this.testMaxNodeCount = this.testMaxNodeCount2 = 0;
  61168. this._visible = true;
  61169. this.pcoGeometry.addEventListener('updateNodeMaxLevel', this.updateNodeMaxLevel.bind(this));
  61170. this.isPointcloud = true; //add
  61171. }
  61172. /*
  61173. 注释:node的level从最大的box 0开始。
  61174. 且加载任意一个node必定也会加载它的所有祖先。(如visibleNodes中有一个level为4,则一定有3,2,1,0)
  61175. visibleNodes就是所有可见的node,比如:
  61176. 如果相机在0这个位置朝下,这时候的visibleNodes中只有一个level为0的node;
  61177. 而如果朝上看,上方的几个node如果在视野中占据足够大的位置的话,就会加载。
  61178. 如果相机在2这个位置朝上,这时候的visibleNodes中所包含的level为: 0,1,2
  61179. ________________
  61180. | | | |
  61181. |__2| | |
  61182. | 1 | 1 |
  61183. |_______|_______|
  61184. | |
  61185. | |
  61186. | 0 |
  61187. |_______________|
  61188. 查看box可在potree中开启
  61189. */
  61190. updateNodeMaxLevel(e){//目前点云包含node的最高level
  61191. var level = Math.max(e.level, this.nodeMaxLevel);
  61192. if(level != this.nodeMaxLevel){
  61193. this.nodeMaxLevel = level;
  61194. //viewer.dispatchEvent({type:'updateNodeMaxLevel', pointcloud: this, nodeMaxLevel:level})
  61195. console.log('updateNodeMaxLevel ' + this.dataset_id + " : "+ this.nodeMaxLevel);
  61196. setTimeout(()=>{
  61197. this.setPointLevel();//重新计算 延迟是因为testNodeMax会变回旧的
  61198. },1);
  61199. if(!Potree.settings.sizeFitToLevel){
  61200. this.changePointSize();
  61201. }
  61202. }
  61203. }//注:在没有加载到真实的 nodeMaxLevel之前,点云会显示得偏大
  61204. //panoEdit时比预测值小很多?
  61205. testMaxNodeLevel(camera){//手动使maxLevel达到最高,从而迫使updateNodeMaxLevel。 因为Potree.settings.pointDensity 不为 'high'时,maxLevel不是所加载的最高,就很容易加载不出下一个层级,导致无法知道nodeMaxLevel
  61206. if(this.testMaxNodeLevelDone ) return
  61207. //if(this.nodeMaxLevel > this.nodeMaxLevelPredict.min )return
  61208. if( this.nodeMaxLevel==0 )return true
  61209. if(camera.type == "OrthographicCamera" || this.testMaxNodeCount < 50){
  61210. if(!Potree.Utils.isInsideFrustum(this.bound, camera)){
  61211. return true
  61212. }
  61213. }else if( !viewer.atDatasets.includes(this))return true //否则老远就count++
  61214. let levels = this.visibleNodes.map(e=>e.getLevel());
  61215. let actMaxLevel = Math.max.apply(null, levels); //实际加载到的最高的node level
  61216. if(actMaxLevel < this.maxLevel)return true// 还没加载到能加载到的最高。 但在细节设置较低时,排除作用微弱。
  61217. //尝试加载出更高级的level
  61218. let old = this.maxLevel;
  61219. this.maxLevel = 12;
  61220. //var visibleNodes1 = this.visibleNodes.map(e=>e.getLevel())
  61221. //console.log('visibleNodes1',visibleNodes1)
  61222. Potree.updatePointClouds([this], viewer.scene.getActiveCamera(), viewer.mainViewport.resolution );
  61223. //不在camera可视范围内还是加载不出来。即使临时修改位置
  61224. var visibleNodes2 = this.visibleNodes.map(e=>e.getLevel());
  61225. //console.log('visibleNodes2',visibleNodes2)
  61226. this.maxLevel = old;
  61227. this.testMaxNodeCount ++;
  61228. viewer.testMaxNodeCount ++;
  61229. //console.log('testMaxNodeCount', this.dataset_id, this.testMaxNodeCount, 'nodeMaxLevel', this.nodeMaxLevel )
  61230. if( this.testMaxNodeCount == Potree.config.testNodeCount1 ){//差不多等当前所在数据集nodeMaxLevel加载出来
  61231. this.changePointSize(); //重新更新一下大小。因之前用的是nodeMaxLevelPredict (防止刚开始因nodeMaxLevel没涨完,导致过大的点云突然出现
  61232. }
  61233. if(this.testMaxNodeCount > 100){
  61234. console.log('testMaxNodeLevel次数超出,强制结束:',this.dataset_id, this.nodeMaxLevel, this.nodeMaxLevelPredict.min);
  61235. this.testMaxNodeLevelDone = 'moreThanMaxCount';
  61236. return; //在可以看见点云的情况下,超时,有可能是预测的max是错的
  61237. }
  61238. if(this.nodeMaxLevel < this.nodeMaxLevelPredict.min) return true //仍需要继续testMaxNodeLevel
  61239. this.testMaxNodeCount2 ++; // 已经> this.nodeMaxLevelPredict.min 后,开始计数。因为min可能低于真实nodeMaxLevel所以要再试几次
  61240. if(this.testMaxNodeCount2 < 50) return true //再试几次 ( 主要是细节调得低时需要多测几次才加载到
  61241. this.testMaxNodeLevelDone = true;
  61242. }
  61243. updateMatrixWorld(force){//add
  61244. super.updateMatrixWorld(force);
  61245. this.matrixWorldInverse = this.matrixWorld.clone().invert();
  61246. }
  61247. setPointLevel(){
  61248. var pointDensity = Potree.settings.pointDensity;
  61249. var config = Potree.config.pointDensity[pointDensity];
  61250. if(!config)return
  61251. /* if(this.testingMaxLevel){
  61252. this.maxLevel = 12;//先加载到最大的直到测试完毕。由于5个level为一组来加载,所以如果写4最高能加载到5,如果写5最高能加载到下一个级别的最高也就是10
  61253. //console.log('maxLevel: '+e.maxLevel + ' testingMaxLevel中 ' )
  61254. }else{ */
  61255. let percent = config.percentByUser && Potree.settings.UserDensityPercent != void 0 ? Potree.settings.UserDensityPercent : config.maxLevelPercent;
  61256. this.maxLevel = Math.round( percent * this.nodeMaxLevel);
  61257. //console.log('maxLevel: '+e.maxLevel + ', density : '+Potree.settings.pointDensity, ", percent :"+percent);
  61258. if(Potree.settings.sizeFitToLevel){
  61259. this.changePointSize();
  61260. }
  61261. this.changePointOpacity();
  61262. //}
  61263. viewer.dealBeforeRender || viewer.dispatchEvent('content_changed');
  61264. }
  61265. //预测可能的nodeMaxLevel:
  61266. predictNodeMaxLevel(){//预测maxNodeLevel。 可能只适用于我们相机拍的点云
  61267. let spacing = {min:0.005, max:0.014};//最小节的两点间的距离 ,获得方法:spacing / Math.pow(2, nodeMaxLevel)。 目前观测的我们自己拍的这个数值的范围大概是这样
  61268. let min = Math.log2(this.material.spacing / spacing.max); //有见过最大是0.01368
  61269. let max = Math.log2(this.material.spacing / spacing.min); //大部分是 0.006
  61270. //console.log('predictNodeMaxLevel:', this.name , min, max )
  61271. //只对深时相机,其他相机不准
  61272. return {min, max}
  61273. }
  61274. getHighestNodeSpacing(){
  61275. return this.material.spacing / Math.pow(2, this.nodeMaxLevel) //前提是这个nodeMaxLevel是准确的
  61276. }
  61277. updateMaterial (material, visibleNodes, camera, renderer, resolution) {//改
  61278. material.fov = camera.fov * (Math.PI / 180);
  61279. /* material.screenWidth = renderer.domElement.clientWidth;
  61280. material.screenHeight = renderer.domElement.clientHeight; */
  61281. material.resolution = resolution;
  61282. material.spacing = this.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z);
  61283. material.near = camera.near;
  61284. material.far = camera.far;
  61285. material.uniforms.octreeSize.value = this.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  61286. }
  61287. pick(viewer, viewport, camera, ray, params = {}){//改
  61288. let renderer = viewer.renderer;
  61289. let pRenderer = viewer.pRenderer;
  61290. viewer.addTimeMark('pick','start');
  61291. let getVal = (a, b) => a != void 0 ? a : b;
  61292. let pickWindowSize = params.pickWindowSize; //拾取像素边长,越小越精准,但点云稀疏的话可能容易出现识别不到的情况。 另外左下侧会有缝隙无法识别到,缝隙大小和这个值有关//突然发现pickWindowSize在一百以内的变化对pick费时影响甚微,1和100差1毫秒不到,但400时会多4毫秒
  61293. if(pickWindowSize == void 0){
  61294. if(Potree.settings.displayMode == 'showPanos'){
  61295. pickWindowSize = 50;
  61296. }else {
  61297. let r0 = this.nodeMaxLevel > 0 ? this.maxLevel/this.nodeMaxLevel : 0.5;
  61298. pickWindowSize = MathUtils.clamp( Math.round((1.1-r0)*80), 15, 100);
  61299. }
  61300. }
  61301. if(camera.type == 'OrthographicCamera'){
  61302. var cameraDir = new Vector3(0,0,-1).applyQuaternion(camera.quaternion);
  61303. pickWindowSize *= 4; //pointsize比较大时截取太小会没多少点可以选
  61304. }
  61305. let pickOutsideClipRegion = getVal(params.pickOutsideClipRegion, false);
  61306. let size = viewport ? viewport.resolution : renderer.getSize(new Vector2());
  61307. let width = Math.ceil(getVal(params.width, size.width)); //renderTarget大小。影响识别精度
  61308. let height = Math.ceil(getVal(params.height, size.height));
  61309. let screenshot = ()=>{
  61310. if(window.testScreen){
  61311. let dataUrl = Potree.Utils.renderTargetToDataUrl(pickState.renderTarget, width, height, renderer);
  61312. Potree.Common.downloadFile(dataUrl, 'screenshot.png');
  61313. window.testScreen = 0;
  61314. }
  61315. };
  61316. let pointSizeType = getVal(params.pointSizeType, this.material.pointSizeType);
  61317. let pointSize = getVal(params.pointSize, this.material.size);
  61318. let nodes = this.nodesOnRay(this.visibleNodes, ray);
  61319. if (nodes.length === 0) {
  61320. return null;
  61321. }
  61322. //console.log('nodes.length != 0', this.name)
  61323. if (!this.pickState) {
  61324. let scene = new Scene();
  61325. let material = new ExtendPointCloudMaterial();
  61326. material.activeAttributeName = "indices";//indices
  61327. let renderTarget = new WebGLRenderTarget(
  61328. 1, 1,
  61329. { minFilter: LinearFilter,
  61330. magFilter: NearestFilter,
  61331. format: RGBAFormat }
  61332. );
  61333. this.pickState = {
  61334. renderTarget: renderTarget,
  61335. material: material,
  61336. scene: scene
  61337. };
  61338. };
  61339. let pickState = this.pickState;
  61340. let pickMaterial = pickState.material;
  61341. { // update pick material
  61342. pickMaterial.pointSizeType = pointSizeType;
  61343. //pickMaterial.shape = this.material.shape;
  61344. pickMaterial.shape = Potree.PointShape.PARABOLOID;
  61345. pickMaterial.uniforms.uFilterReturnNumberRange.value = this.material.uniforms.uFilterReturnNumberRange.value;
  61346. pickMaterial.uniforms.uFilterNumberOfReturnsRange.value = this.material.uniforms.uFilterNumberOfReturnsRange.value;
  61347. pickMaterial.uniforms.uFilterGPSTimeClipRange.value = this.material.uniforms.uFilterGPSTimeClipRange.value;
  61348. pickMaterial.uniforms.uFilterPointSourceIDClipRange.value = this.material.uniforms.uFilterPointSourceIDClipRange.value;
  61349. pickMaterial.size = pointSize;
  61350. pickMaterial.uniforms.minSize.value = this.material.uniforms.minSize.value;
  61351. pickMaterial.uniforms.maxSize.value = this.material.uniforms.maxSize.value;
  61352. pickMaterial.classification = this.material.classification;
  61353. pickMaterial.recomputeClassification();
  61354. //pickClipped判断转移到上一层函数
  61355. let {bigClipInBox,clipBoxes_in,clipBoxes_out} = this.material;
  61356. pickMaterial.setClipBoxes(bigClipInBox, clipBoxes_in, clipBoxes_out, []);
  61357. this.updateMaterial(pickMaterial, nodes, camera, renderer, new Vector2(width, height));
  61358. }
  61359. pickState.renderTarget.setSize(width, height); //仅绘制屏幕大小的,而不乘以devicePixelRatio
  61360. let pixelPos = new Vector2(params.x, params.y);
  61361. let gl = renderer.getContext();
  61362. //规定渲染范围,只渲染一小块
  61363. /* renderer.setScissorTest(true);
  61364. gl.enable(gl.SCISSOR_TEST);
  61365. gl.scissor(
  61366. parseInt(pixelPos.x - (pickWindowSize - 1) / 2),
  61367. parseInt(pixelPos.y - (pickWindowSize - 1) / 2),
  61368. parseInt(pickWindowSize), parseInt(pickWindowSize));
  61369. */ //---这段没用
  61370. pickState.renderTarget.scissor.set(parseInt(pixelPos.x - (pickWindowSize - 1) / 2), parseInt(pixelPos.y - (pickWindowSize - 1) / 2),parseInt(pickWindowSize), parseInt(pickWindowSize));
  61371. pickState.renderTarget.scissorTest = true;
  61372. renderer.state.buffers.depth.setTest(pickMaterial.depthTest);
  61373. renderer.state.buffers.depth.setMask(pickMaterial.depthWrite);
  61374. renderer.state.setBlending(NoBlending);
  61375. { // RENDER
  61376. renderer.setRenderTarget(pickState.renderTarget);
  61377. gl.clearColor(0, 0, 0, 0);
  61378. //renderer.clear(true, true, true);
  61379. let tmp = this.material;
  61380. this.material = pickMaterial;
  61381. pRenderer.renderOctree(this, nodes, camera, pickState.renderTarget); //只绘制ray pick到的部分nodes
  61382. screenshot();
  61383. this.material = tmp;
  61384. }
  61385. let clamp = (number, min, max) => Math.min(Math.max(min, number), max);
  61386. let x = parseInt(clamp(pixelPos.x - (pickWindowSize - 1) / 2, 0, width));
  61387. let y = parseInt(clamp(pixelPos.y - (pickWindowSize - 1) / 2, 0, height));
  61388. /* let w = parseInt(Math.min(x + pickWindowSize, width) - x);
  61389. let h = parseInt(Math.min(y + pickWindowSize, height) - y); */
  61390. let pixelCount = pickWindowSize * pickWindowSize;//w * h;
  61391. let buffer = new Uint8Array(4 * pixelCount);
  61392. //w<pickWindowSize会报错
  61393. gl.readPixels(x, y, pickWindowSize, pickWindowSize, gl.RGBA, gl.UNSIGNED_BYTE, buffer); //这句花费最多时间 pc:2-4, 即使只有1*1像素
  61394. renderer.clear(true, true, true); //绘制完就clear否则download的图会有上次的轨迹
  61395. renderer.setRenderTarget(null);
  61396. renderer.state.reset();
  61397. renderer.setScissorTest(false);
  61398. gl.disable(gl.SCISSOR_TEST);
  61399. let pixels = buffer;
  61400. let ibuffer = new Uint32Array(buffer.buffer); //四个数整合成一个
  61401. // find closest hit inside pixelWindow boundaries
  61402. let min = Number.MAX_VALUE;
  61403. let hits = [], hits2 = [], rSquare;
  61404. if(!params.all){
  61405. let r = MathUtils.clamp(Math.floor(pickWindowSize / 2),1, 40);
  61406. rSquare = r * r;
  61407. }
  61408. for (let u = 0; u < pickWindowSize; u++) {
  61409. for (let v = 0; v < pickWindowSize; v++) {
  61410. let offset = (u + v * pickWindowSize);
  61411. let distance = Math.pow(u - (pickWindowSize - 1) / 2, 2) + Math.pow(v - (pickWindowSize - 1) / 2, 2);
  61412. let pcIndex = pixels[4 * offset + 3];//nodes index(第四位)
  61413. pixels[4 * offset + 3] = 0; //去除nodes index后剩下的是index(前三位)
  61414. let pIndex = ibuffer[offset]; //index
  61415. if(!(pcIndex === 0 && pIndex === 0) && (pcIndex !== undefined) && (pIndex !== undefined)){
  61416. let hit = {
  61417. pIndex: pIndex,
  61418. pcIndex: pcIndex,
  61419. distanceToCenter: distance
  61420. };
  61421. if(params.all){
  61422. hits.push(hit);
  61423. }else {
  61424. if(hits.length > 0){//最后选取的是最靠近鼠标的那个pick
  61425. if(distance < hits[0].distanceToCenter){
  61426. hits[0] = hit;
  61427. }
  61428. }else {
  61429. hits.push(hit);
  61430. }
  61431. if(distance < rSquare) hits2.push(hit); //add
  61432. }
  61433. }
  61434. }
  61435. }
  61436. if(!params.all && Potree.settings.pickFrontPointRatio){
  61437. if(hits2.length){//add
  61438. hits = hits2;
  61439. }
  61440. }
  61441. // { // DEBUG: show panel with pick image
  61442. // let img = Utils.pixelsArrayToImage(buffer, w, h);
  61443. // let screenshot = img.src;
  61444. // if(!this.debugDIV){
  61445. // this.debugDIV = $(`
  61446. // <div id="pickDebug"
  61447. // style="position: absolute;
  61448. // right: 400px; width: 300px;
  61449. // bottom: 44px; width: 300px;
  61450. // z-index: 1000;
  61451. // "></div>`);
  61452. // $(document.body).append(this.debugDIV);
  61453. // }
  61454. // this.debugDIV.empty();
  61455. // this.debugDIV.append($(`<img src="${screenshot}"
  61456. // style="transform: scaleY(-1); width: 300px"/>`));
  61457. // //$(this.debugWindow.document).append($(`<img src="${screenshot}"/>`));
  61458. // //this.debugWindow.document.write('<img src="'+screenshot+'"/>');
  61459. // }
  61460. for(let hit of hits){
  61461. let point = {};
  61462. if (!nodes[hit.pcIndex]) {
  61463. return null;
  61464. }
  61465. let node = nodes[hit.pcIndex];
  61466. let pc = node.sceneNode;
  61467. let geometry = node.geometryNode.geometry;
  61468. for(let attributeName in geometry.attributes){
  61469. let attribute = geometry.attributes[attributeName];
  61470. if (attributeName === 'position') {
  61471. let x = attribute.array[3 * hit.pIndex + 0];
  61472. let y = attribute.array[3 * hit.pIndex + 1];
  61473. let z = attribute.array[3 * hit.pIndex + 2];
  61474. let position = new Vector3(x, y, z);
  61475. position.applyMatrix4( pc.matrixWorld );
  61476. point[attributeName] = position;
  61477. //add
  61478. if(!params.all && Potree.settings.pickFrontPointRatio ){
  61479. if(camera.type == 'OrthographicCamera'){
  61480. let vec = new Vector3().subVectors(position, camera.position);
  61481. hit.disSquare = vec.projectOnVector( cameraDir ).length(); //只考虑到相机的垂直距离
  61482. }else {
  61483. hit.disSquare = camera.position.distanceTo(position);
  61484. }
  61485. }
  61486. } else if (attributeName === 'indices') {
  61487. } else {
  61488. let values = attribute.array.slice(attribute.itemSize * hit.pIndex, attribute.itemSize * (hit.pIndex + 1)) ;
  61489. if(attribute.potree){
  61490. const {scale, offset} = attribute.potree;
  61491. values = values.map(v => v / scale + offset);
  61492. }
  61493. point[attributeName] = values;
  61494. //debugger;
  61495. //if (values.itemSize === 1) {
  61496. // point[attribute.name] = values.array[hit.pIndex];
  61497. //} else {
  61498. // let value = [];
  61499. // for (let j = 0; j < values.itemSize; j++) {
  61500. // value.push(values.array[values.itemSize * hit.pIndex + j]);
  61501. // }
  61502. // point[attribute.name] = value;
  61503. //}
  61504. }
  61505. }
  61506. hit.point = point;
  61507. }
  61508. viewer.addTimeMark('pick','end');
  61509. if(params.all){
  61510. return hits.map(hit => hit.point);
  61511. }else {
  61512. if(hits.length === 0){
  61513. return null;
  61514. }else {
  61515. if(Potree.settings.pickFrontPointRatio == 0){//如果不需要选偏离镜头近的,就要离中心近的即可
  61516. //console.log(hits[0], hits2, pixelPos)
  61517. return hits[0].point;
  61518. }
  61519. //为了防止透过点云缝隙,选到后排的点云,将选取的位置离相机的距离考虑进去。倾向选择离相机近、且离鼠标位置近的点。(否则按照原方案只选离鼠标位置最近的,可能从高楼不小心走到下层,导航选点也是)
  61520. let sorted1 = hits.sort( (a, b) => a.disSquare - b.disSquare ).slice();
  61521. let nearest = sorted1[0]; //return nearest.point; //直接用最近点 在点云稀疏时不太跟手,如地面上,最近点往往在鼠标下方
  61522. hits.forEach( hit=>{
  61523. let disDiff = hit.disSquare - nearest.disSquare; //和最近点的偏差
  61524. hit.disDiff = disDiff;
  61525. hit.score = -hit.distanceToCenter - disDiff * Potree.settings.pickFrontPointRatio;
  61526. });
  61527. let sorted2 = hits.sort( (a, b) => b.score - a.score );
  61528. //console.log(sorted2[0].point.position.z )
  61529. return sorted2[0].point;
  61530. }
  61531. }
  61532. }
  61533. // 设置点大小
  61534. changePointSize(num, sizeFitToLevel) {
  61535. let size, nodeMaxLevel;
  61536. let dontRender = viewer.dealBeforeRender;
  61537. if(this.material.pointSizeType != PointSizeType.ATTENUATED){
  61538. num && (size = num / Potree.config.material.realPointSize / 1.3);
  61539. }else {
  61540. let num_ = num;
  61541. if (num_ == void 0) {
  61542. num_ = this.temp.pointSize;
  61543. } else {
  61544. this.temp.pointSize = num_;
  61545. }
  61546. num_ = num_ / (Potree.config.material.realPointSize / Potree.config.material.pointSize); //兼容
  61547. //num_ = Math.pow(num_, 1.05) * 5
  61548. nodeMaxLevel = this.testMaxNodeCount >= Potree.config.testNodeCount1 ? this.nodeMaxLevel : Math.max(this.nodeMaxLevel, this.nodeMaxLevelPredict.max );//防止刚开始因nodeMaxLevel没涨完,导致过大的点云突然出现
  61549. if(sizeFitToLevel || Potree.settings.sizeFitToLevel){//按照点云质量来调整的版本: 近似将pointSizeType换成ADAPTIVE
  61550. let str = this.temp.pointSize+':'+this.maxLevel+':'+ nodeMaxLevel;
  61551. let value = this.temp.sizeFitToLevel[str]; //储存。防止每次渲染(反复切换density)都要算。
  61552. if(value){
  61553. size = value;
  61554. }else {
  61555. if(this.maxLevel == Infinity)return
  61556. let base = this.material.spacing / Math.pow(2, this.maxLevel); //点云大小在level为0时设置为spacing,每长一级,大小就除以2. (不同场景还是会有偏差)
  61557. let r = nodeMaxLevel > 0 ? this.maxLevel / nodeMaxLevel : 0.5; //越大,越精细,需要越缩小
  61558. base *= nodeMaxLevel > 0 ? Math.max(0.1, Math.pow(r, 3*r+0.3 )) : 0.1; //低质量的缩小点,因为视觉上看太大了。navvis是不铺满的,我们也留一点缝隙(但是ortho是不用缩小的,如果能分开判断就好了)
  61559. //base *= nodeMaxLevel > 0 ? Math.max(0.1, Math.pow(this.maxLevel / nodeMaxLevel, 1.1)) : 0.1 //低质量的缩小点,因为视觉上看太大了。navvis是不铺满的,我们也留一点缝隙(但是ortho是不用缩小的,如果能分开判断就好了)
  61560. size = base * 20 * num_;/* * window.devicePixelRatio */
  61561. //在t-8BCqxQAr93 会议室 和 t-e2Kb2iU 隧道 两个场景里调节,因为它们的spacing相差较大,观察会议室墙壁的龟裂程度
  61562. this.temp.sizeFitToLevel[str] = size;
  61563. }
  61564. }else {
  61565. /* let base = 0.007; */ let base = this.material.spacing / Math.pow(2, nodeMaxLevel); //点云大小在level为0时设置为spacing,每长一级,大小就除以2
  61566. //base的数值理论上应该是右侧算出来的,但发现有的场景nodeMaxLevel和nodeMaxLevelPredict差别较大的点云显示也过大,而直接换成固定值反而可以适应所有场景。该固定值来源于 getHighestNodeSpacing 最小值,修改了下。(会不会是我们的相机其实该值是固定的,根据该值算出的spacing才是有误差的? 如果换了相机是否要改值?)
  61567. //2022-12-21又换回非固定值。因为有的场景如SS-t-t01myDqnfE的两个数据集密集程度差别很大,应该将稀疏点云的大小设置的大些。 但是这样的缺点是两个数据集因相接处有大有小无法融合。
  61568. size = base * 20 * num_; /* * window.devicePixelRatio */
  61569. }
  61570. }
  61571. //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 */)
  61572. if(size){
  61573. if(Potree.settings.sortCloudMat){//被废弃,不给material分组了
  61574. this.size = size;this.material.size = size;
  61575. }else {
  61576. this.material.size = size;
  61577. }
  61578. }
  61579. dontRender || viewer.dispatchEvent('content_changed');
  61580. }
  61581. // 设置点透明度
  61582. changePointOpacity(num, canMoreThanOne ) {
  61583. //num:0-1 navvis用的是亮度
  61584. if (num == void 0) {
  61585. num = this.temp.pointOpacity;
  61586. } else {
  61587. this.temp.pointOpacity = num;
  61588. }
  61589. let dontRender = viewer.dealBeforeRender; //在执行beforeRender时更改的话不要发送content_changed 尤其分屏
  61590. if(Potree.settings.notAdditiveBlending){
  61591. return this.material.opacity = num
  61592. }
  61593. let opacity;
  61594. if (num == 1) {
  61595. opacity = 1;
  61596. } else {
  61597. let str = (Potree.settings.sizeFitToLevel?'sizeFit:':'')+ (canMoreThanOne ? 'canMoreThanOne:':'') +this.temp.pointOpacity+':'+this.maxLevel+':'+this.nodeMaxLevel;
  61598. let value = this.temp.opacity[str]; //储存。防止每次渲染(反复切换density)都要算。
  61599. if(value){
  61600. opacity = value;
  61601. }else {
  61602. if(Potree.settings.sizeFitToLevel){//按照点云质量来调整的版本:
  61603. let base = this.material.spacing / Math.pow(1.7, this.maxLevel); //随着level提高,点云重叠几率增多
  61604. let minBase = this.material.spacing / Math.pow(1.7, this.nodeMaxLevel);
  61605. let ratio = Math.min(1 / base, 1 / minBase / 3); //ratio为一个能使opacity不大于1 的 乘量,minBase要除以一个数,该数调越大减弱效果越强。level越低opacity和面板越接,level越高效果越弱,以减免过度重叠后的亮度。
  61606. opacity = base * ratio * num;
  61607. if(!canMoreThanOne){
  61608. opacity = MathUtils.clamp(opacity, 0, 0.999); //到1就不透明了(可能出现一段一样)
  61609. }
  61610. }else {
  61611. let base = this.material.spacing / Math.pow(2, this.maxLevel);
  61612. let minBase = this.material.spacing / Math.pow(2, this.nodeMaxLevel);
  61613. //console.log(1 / base, 1 / minBase / 6)
  61614. let ratio = Math.min(1 / base, 1 / minBase / 3); //ratio为一个能使opacity不大于1 的 乘量,minBase要除以一个数,该数调越大减弱效果越强。level越低opacity和面板越接,level越高效果越弱,以减免过度重叠后的亮度。
  61615. opacity = base * ratio * num;
  61616. if(!canMoreThanOne){
  61617. opacity = MathUtils.clamp(opacity, 0, 0.999); //到1就不透明了(可能出现一段一样)
  61618. }
  61619. }
  61620. this.temp.opacity[str] = opacity;
  61621. }
  61622. //缺点:防止颜色过亮主要是相机离远时,当在漫游点处由于离点云太近,可能会导致高质量点云看起来很暗。
  61623. }
  61624. //console.log('changePointOpacity ' + this.dataset_id + ', num : ' + num + ' , opacity : ' + this.material.opacity) //检查是否做到了低质量时num==opacity,中质量opacity稍小于num,高质量更小
  61625. if(Potree.settings.sortCloudMat){
  61626. this.opacity = opacity; this.material.opacity = opacity;
  61627. }else {
  61628. this.material.opacity = opacity;
  61629. }
  61630. dontRender || viewer.dispatchEvent('content_changed');
  61631. }
  61632. updateBound(){
  61633. var boundingBox_ = this.pcoGeometry.tightBoundingBox.clone().applyMatrix4(this.matrixWorld);//tightBoundingBox是点云原始的bound,但经过(绕z)旋转后bound有所改变,比之前体积更大。
  61634. this.bound = boundingBox_;
  61635. this.bound2 = this.getBoundWithPanos();
  61636. }
  61637. getBoundWithPanos(){//确保panoBound在内的bound
  61638. let bound = this.bound.clone();
  61639. this.panos.forEach(pano=>{
  61640. let panoBound = new Box3;
  61641. panoBound.expandByPoint(pano.position);
  61642. panoBound.expandByVector(new Vector3(1,1,1));//give pano a margin
  61643. bound.union(panoBound);
  61644. });
  61645. return bound
  61646. }
  61647. getPanosBound(){//仅由所有pano构成的bound
  61648. if(this.panos.length > 0){
  61649. let minSize = new Vector3(1,1,1);
  61650. this.panosBound = math.getBoundByPoints(this.panos.map(e=>e.position), minSize);
  61651. }else {
  61652. this.panosBound = null;
  61653. }
  61654. }
  61655. getUnrotBoundPoint(type){//获取没有旋转的tightBounding的水平四个点
  61656. //如果alighment支持任意轴旋转,水平面上看到的可能就是六边形了,失去意义,到时候不能用这个。也可以若只绕z旋转, 使用tightBoundingBox,否则bound
  61657. let bound = this.pcoGeometry.tightBoundingBox;
  61658. if(type == 'all'){
  61659. return [new Vector3(bound.min.x, bound.min.y, bound.min.z),
  61660. new Vector3(bound.max.x, bound.min.y, bound.min.z),
  61661. new Vector3(bound.max.x, bound.max.y,bound.min.z),
  61662. new Vector3(bound.min.x, bound.max.y,bound.min.z),
  61663. new Vector3(bound.min.x, bound.min.y, bound.max.z),
  61664. new Vector3(bound.max.x, bound.min.y, bound.max.z),
  61665. new Vector3(bound.max.x, bound.max.y,bound.max.z),
  61666. new Vector3(bound.min.x, bound.max.y,bound.max.z),
  61667. ].map(e=>e.applyMatrix4(this.matrixWorld))
  61668. }else
  61669. return [new Vector3(bound.min.x, bound.min.y,0),
  61670. new Vector3(bound.max.x, bound.min.y,0),
  61671. new Vector3(bound.max.x, bound.max.y,0),
  61672. new Vector3(bound.min.x, bound.max.y,0),
  61673. ].map(e=>e.applyMatrix4(this.matrixWorld))
  61674. }
  61675. getVolume(){
  61676. /* var points = this.getUnrotBoundPoint() -----在只绕z轴旋转时这么写也行
  61677. var area = Math.abs(math.getArea(points))
  61678. return area * (this.bound.max.z - this.bound.min.z) */
  61679. let bound = this.pcoGeometry.tightBoundingBox.clone();
  61680. let size = bound.getSize(new Vector3);
  61681. return size.x * size.y * size.z
  61682. }
  61683. ifContainsPoint(pos){//pos是否坐落于tightBound内
  61684. /* if(!this.bound || !this.bound.containsPoint(pos))return ---这样写也行
  61685. var points = this.getUnrotBoundPoint()
  61686. return math.isPointInArea(points, null, pos) */
  61687. //要把tightBoundingBox想象成一个volumeBox
  61688. let box = this.pcoGeometry.tightBoundingBox;
  61689. let center = box.getCenter(new Vector3);
  61690. let size = box.getSize(new Vector3);
  61691. let boxMatrix = new Matrix4().setPosition(center.x,center.y,center.z);
  61692. boxMatrix.scale(size);
  61693. boxMatrix.premultiply(this.matrixWorld);
  61694. return Potree.Utils.isIntersectBox(pos, boxMatrix)
  61695. }
  61696. intersectBox(boxWorldMatrix){
  61697. let boxM = boxWorldMatrix.clone().premultiply(this.matrixWorld.clone().invert()); //box乘上点云逆矩阵 (因为点云的忽略掉其matrixWorld, 为了保持相对位置不变,box要左乘matrixWorld的逆)(因第一个参数bound不好变形,第二个参数box可以)
  61698. return Potree.Utils.isIntersectBox(this.pcoGeometry.tightBoundingBox, boxM)
  61699. }
  61700. }
  61701. class ProfileData {
  61702. constructor (profile) {
  61703. this.profile = profile;
  61704. this.segments = [];
  61705. this.boundingBox = new Box3();
  61706. for (let i = 0; i < profile.points.length - 1; i++) {
  61707. let start = profile.points[i];
  61708. let end = profile.points[i + 1];
  61709. let startGround = new Vector3(start.x, start.y, 0);
  61710. let endGround = new Vector3(end.x, end.y, 0);
  61711. let center = new Vector3().addVectors(endGround, startGround).multiplyScalar(0.5);
  61712. let length = startGround.distanceTo(endGround);
  61713. let side = new Vector3().subVectors(endGround, startGround).normalize();
  61714. let up = new Vector3(0, 0, 1);
  61715. let forward = new Vector3().crossVectors(side, up).normalize();
  61716. let N = forward;
  61717. let cutPlane = new Plane().setFromNormalAndCoplanarPoint(N, startGround);
  61718. let halfPlane = new Plane().setFromNormalAndCoplanarPoint(side, center);
  61719. let segment = {
  61720. start: start,
  61721. end: end,
  61722. cutPlane: cutPlane,
  61723. halfPlane: halfPlane,
  61724. length: length,
  61725. points: new Points$1()
  61726. };
  61727. this.segments.push(segment);
  61728. }
  61729. }
  61730. size () {
  61731. let size = 0;
  61732. for (let segment of this.segments) {
  61733. size += segment.points.numPoints;
  61734. }
  61735. return size;
  61736. }
  61737. };
  61738. class ProfileRequest {
  61739. constructor (pointcloud, profile, maxDepth, callback) {
  61740. this.pointcloud = pointcloud;
  61741. this.profile = profile;
  61742. this.maxDepth = maxDepth || Number.MAX_VALUE;
  61743. this.callback = callback;
  61744. this.temporaryResult = new ProfileData(this.profile);
  61745. this.pointsServed = 0;
  61746. this.highestLevelServed = 0;
  61747. this.priorityQueue = new BinaryHeap(function (x) { return 1 / x.weight; });
  61748. this.initialize();
  61749. }
  61750. initialize () {
  61751. this.priorityQueue.push({node: this.pointcloud.pcoGeometry.root, weight: Infinity});
  61752. };
  61753. // traverse the node and add intersecting descendants to queue
  61754. traverse (node) {
  61755. let stack = [];
  61756. for (let i = 0; i < 8; i++) {
  61757. let child = node.children[i];
  61758. if (child && this.pointcloud.nodeIntersectsProfile(child, this.profile)) {
  61759. stack.push(child);
  61760. }
  61761. }
  61762. while (stack.length > 0) {
  61763. let node = stack.pop();
  61764. let weight = node.boundingSphere.radius;
  61765. this.priorityQueue.push({node: node, weight: weight});
  61766. // add children that intersect the cutting plane
  61767. if (node.level < this.maxDepth) {
  61768. for (let i = 0; i < 8; i++) {
  61769. let child = node.children[i];
  61770. if (child && this.pointcloud.nodeIntersectsProfile(child, this.profile)) {
  61771. stack.push(child);
  61772. }
  61773. }
  61774. }
  61775. }
  61776. }
  61777. update(){
  61778. if(!this.updateGeneratorInstance){
  61779. this.updateGeneratorInstance = this.updateGenerator();
  61780. }
  61781. let result = this.updateGeneratorInstance.next();
  61782. if(result.done){
  61783. this.updateGeneratorInstance = null;
  61784. }
  61785. }
  61786. * updateGenerator(){
  61787. // load nodes in queue
  61788. // if hierarchy expands, also load nodes from expanded hierarchy
  61789. // once loaded, add data to this.points and remove node from queue
  61790. // only evaluate 1-50 nodes per frame to maintain responsiveness
  61791. let start = performance.now();
  61792. let maxNodesPerUpdate = 1;
  61793. let intersectedNodes = [];
  61794. for (let i = 0; i < Math.min(maxNodesPerUpdate, this.priorityQueue.size()); i++) {
  61795. let element = this.priorityQueue.pop();
  61796. let node = element.node;
  61797. if(node.level > this.maxDepth){
  61798. continue;
  61799. }
  61800. if (node.loaded) {
  61801. // add points to result
  61802. intersectedNodes.push(node);
  61803. exports.lru.touch(node);
  61804. this.highestLevelServed = Math.max(node.getLevel(), this.highestLevelServed);
  61805. var geom = node.pcoGeometry;
  61806. var hierarchyStepSize = geom ? geom.hierarchyStepSize : 1;
  61807. var doTraverse = node.getLevel() === 0 ||
  61808. (node.level % hierarchyStepSize === 0 && node.hasChildren);
  61809. if (doTraverse) {
  61810. this.traverse(node);
  61811. }
  61812. } else {
  61813. node.load();
  61814. this.priorityQueue.push(element);
  61815. }
  61816. }
  61817. if (intersectedNodes.length > 0) {
  61818. for(let done of this.getPointsInsideProfile(intersectedNodes, this.temporaryResult)){
  61819. if(!done){
  61820. //console.log("updateGenerator yields");
  61821. yield false;
  61822. }
  61823. }
  61824. if (this.temporaryResult.size() > 100) {
  61825. this.pointsServed += this.temporaryResult.size();
  61826. this.callback.onProgress({request: this, points: this.temporaryResult});
  61827. this.temporaryResult = new ProfileData(this.profile);
  61828. }
  61829. }
  61830. if (this.priorityQueue.size() === 0) {
  61831. // we're done! inform callback and remove from pending requests
  61832. if (this.temporaryResult.size() > 0) {
  61833. this.pointsServed += this.temporaryResult.size();
  61834. this.callback.onProgress({request: this, points: this.temporaryResult});
  61835. this.temporaryResult = new ProfileData(this.profile);
  61836. }
  61837. this.callback.onFinish({request: this});
  61838. let index = this.pointcloud.profileRequests.indexOf(this);
  61839. if (index >= 0) {
  61840. this.pointcloud.profileRequests.splice(index, 1);
  61841. }
  61842. }
  61843. yield true;
  61844. };
  61845. * getAccepted(numPoints, node, matrix, segment, segmentDir, points, totalMileage){
  61846. let checkpoint = performance.now();
  61847. let accepted = new Uint32Array(numPoints);
  61848. let mileage = new Float64Array(numPoints);
  61849. let acceptedPositions = new Float32Array(numPoints * 3);
  61850. let numAccepted = 0;
  61851. let pos = new Vector3();
  61852. let svp = new Vector3();
  61853. let view = new Float32Array(node.geometry.attributes.position.array);
  61854. for (let i = 0; i < numPoints; i++) {
  61855. pos.set(
  61856. view[i * 3 + 0],
  61857. view[i * 3 + 1],
  61858. view[i * 3 + 2]);
  61859. pos.applyMatrix4(matrix);
  61860. let distance = Math.abs(segment.cutPlane.distanceToPoint(pos));
  61861. let centerDistance = Math.abs(segment.halfPlane.distanceToPoint(pos));
  61862. if (distance < this.profile.width / 2 && centerDistance < segment.length / 2) {
  61863. svp.subVectors(pos, segment.start);
  61864. let localMileage = segmentDir.dot(svp);
  61865. accepted[numAccepted] = i;
  61866. mileage[numAccepted] = localMileage + totalMileage;
  61867. points.boundingBox.expandByPoint(pos);
  61868. pos.sub(this.pointcloud.position);
  61869. acceptedPositions[3 * numAccepted + 0] = pos.x;
  61870. acceptedPositions[3 * numAccepted + 1] = pos.y;
  61871. acceptedPositions[3 * numAccepted + 2] = pos.z;
  61872. numAccepted++;
  61873. }
  61874. if((i % 1000) === 0){
  61875. let duration = performance.now() - checkpoint;
  61876. if(duration > 4){
  61877. //console.log(`getAccepted yield after ${duration}ms`);
  61878. yield false;
  61879. checkpoint = performance.now();
  61880. }
  61881. }
  61882. }
  61883. accepted = accepted.subarray(0, numAccepted);
  61884. mileage = mileage.subarray(0, numAccepted);
  61885. acceptedPositions = acceptedPositions.subarray(0, numAccepted * 3);
  61886. //let end = performance.now();
  61887. //let duration = end - start;
  61888. //console.log("accepted duration ", duration)
  61889. //console.log(`getAccepted finished`);
  61890. yield [accepted, mileage, acceptedPositions];
  61891. }
  61892. * getPointsInsideProfile(nodes, target){
  61893. let checkpoint = performance.now();
  61894. let totalMileage = 0;
  61895. let pointsProcessed = 0;
  61896. for (let segment of target.segments) {
  61897. for (let node of nodes) {
  61898. let numPoints = node.numPoints;
  61899. let geometry = node.geometry;
  61900. if(!numPoints){
  61901. continue;
  61902. }
  61903. { // skip if current node doesn't intersect current segment
  61904. let bbWorld = node.boundingBox.clone().applyMatrix4(this.pointcloud.matrixWorld);
  61905. let bsWorld = bbWorld.getBoundingSphere(new Sphere());
  61906. let start = new Vector3(segment.start.x, segment.start.y, bsWorld.center.z);
  61907. let end = new Vector3(segment.end.x, segment.end.y, bsWorld.center.z);
  61908. let closest = new Line3(start, end).closestPointToPoint(bsWorld.center, true, new Vector3());
  61909. let distance = closest.distanceTo(bsWorld.center);
  61910. let intersects = (distance < (bsWorld.radius + target.profile.width));
  61911. if(!intersects){
  61912. continue;
  61913. }
  61914. }
  61915. //{// DEBUG
  61916. // console.log(node.name);
  61917. // let boxHelper = new Potree.Box3Helper(node.getBoundingBox());
  61918. // boxHelper.matrixAutoUpdate = false;
  61919. // boxHelper.matrix.copy(viewer.scene.pointclouds[0].matrixWorld);
  61920. // viewer.scene.scene.add(boxHelper);
  61921. //}
  61922. let sv = new Vector3().subVectors(segment.end, segment.start).setZ(0);
  61923. let segmentDir = sv.clone().normalize();
  61924. let points = new Points$1();
  61925. let nodeMatrix = new Matrix4().makeTranslation(...node.boundingBox.min.toArray());
  61926. let matrix = new Matrix4().multiplyMatrices(
  61927. this.pointcloud.matrixWorld, nodeMatrix);
  61928. pointsProcessed = pointsProcessed + numPoints;
  61929. let accepted = null;
  61930. let mileage = null;
  61931. let acceptedPositions = null;
  61932. for(let result of this.getAccepted(numPoints, node, matrix, segment, segmentDir, points,totalMileage)){
  61933. if(!result){
  61934. let duration = performance.now() - checkpoint;
  61935. //console.log(`getPointsInsideProfile yield after ${duration}ms`);
  61936. yield false;
  61937. checkpoint = performance.now();
  61938. }else {
  61939. [accepted, mileage, acceptedPositions] = result;
  61940. }
  61941. }
  61942. let duration = performance.now() - checkpoint;
  61943. if(duration > 4){
  61944. //console.log(`getPointsInsideProfile yield after ${duration}ms`);
  61945. yield false;
  61946. checkpoint = performance.now();
  61947. }
  61948. points.data.position = acceptedPositions;
  61949. let relevantAttributes = Object.keys(geometry.attributes).filter(a => !["position", "indices"].includes(a));
  61950. for(let attributeName of relevantAttributes){
  61951. let attribute = geometry.attributes[attributeName];
  61952. let numElements = attribute.array.length / numPoints;
  61953. if(numElements !== parseInt(numElements)){
  61954. debugger;
  61955. }
  61956. let Type = attribute.array.constructor;
  61957. let filteredBuffer = new Type(numElements * accepted.length);
  61958. let source = attribute.array;
  61959. let target = filteredBuffer;
  61960. for(let i = 0; i < accepted.length; i++){
  61961. let index = accepted[i];
  61962. let start = index * numElements;
  61963. let end = start + numElements;
  61964. let sub = source.subarray(start, end);
  61965. target.set(sub, i * numElements);
  61966. }
  61967. points.data[attributeName] = filteredBuffer;
  61968. }
  61969. points.data['mileage'] = mileage;
  61970. points.numPoints = accepted.length;
  61971. segment.points.add(points);
  61972. }
  61973. totalMileage += segment.length;
  61974. }
  61975. for (let segment of target.segments) {
  61976. target.boundingBox.union(segment.points.boundingBox);
  61977. }
  61978. //console.log(`getPointsInsideProfile finished`);
  61979. yield true;
  61980. };
  61981. finishLevelThenCancel () {
  61982. if (this.cancelRequested) {
  61983. return;
  61984. }
  61985. this.maxDepth = this.highestLevelServed;
  61986. this.cancelRequested = true;
  61987. //console.log(`maxDepth: ${this.maxDepth}`);
  61988. };
  61989. cancel () {
  61990. this.callback.onCancel();
  61991. this.priorityQueue = new BinaryHeap(function (x) { return 1 / x.weight; });
  61992. let index = this.pointcloud.profileRequests.indexOf(this);
  61993. if (index >= 0) {
  61994. this.pointcloud.profileRequests.splice(index, 1);
  61995. }
  61996. };
  61997. }
  61998. class WorkerPool{
  61999. constructor(){
  62000. this.workers = {};
  62001. }
  62002. getWorker(url){
  62003. if (!this.workers[url]){
  62004. this.workers[url] = [];
  62005. }
  62006. if (this.workers[url].length === 0){
  62007. let worker = new Worker(url);
  62008. this.workers[url].push(worker);
  62009. }
  62010. let worker = this.workers[url].pop();
  62011. return worker;
  62012. }
  62013. returnWorker(url, worker){
  62014. this.workers[url].push(worker);
  62015. }
  62016. };
  62017. function createPointcloudData(pointcloud) {
  62018. let material = pointcloud.material;
  62019. let ranges = [];
  62020. for(let [name, value] of material.ranges){
  62021. ranges.push({
  62022. name: name,
  62023. value: value,
  62024. });
  62025. }
  62026. if(typeof material.elevationRange[0] === "number"){
  62027. ranges.push({
  62028. name: "elevationRange",
  62029. value: material.elevationRange,
  62030. });
  62031. }
  62032. if(typeof material.intensityRange[0] === "number"){
  62033. ranges.push({
  62034. name: "intensityRange",
  62035. value: material.intensityRange,
  62036. });
  62037. }
  62038. let pointSizeTypeName = Object.entries(Potree.PointSizeType).find(e => e[1] === material.pointSizeType)[0];
  62039. let jsonMaterial = {
  62040. activeAttributeName: material.activeAttributeName,
  62041. ranges: ranges,
  62042. size: material.size,
  62043. minSize: material.minSize,
  62044. pointSizeType: pointSizeTypeName,
  62045. matcap: material.matcap,
  62046. };
  62047. const pcdata = {
  62048. name: pointcloud.name,
  62049. url: pointcloud.pcoGeometry.url,
  62050. position: pointcloud.position.toArray(),
  62051. rotation: pointcloud.rotation.toArray(),
  62052. scale: pointcloud.scale.toArray(),
  62053. material: jsonMaterial,
  62054. };
  62055. return pcdata;
  62056. }
  62057. function createProfileData(profile){
  62058. const data = {
  62059. uuid: profile.uuid,
  62060. name: profile.name,
  62061. points: profile.points.map(p => p.toArray()),
  62062. height: profile.height,
  62063. width: profile.width,
  62064. };
  62065. return data;
  62066. }
  62067. function createVolumeData(volume){
  62068. const data = {
  62069. uuid: volume.uuid,
  62070. type: volume.constructor.name,
  62071. name: volume.name,
  62072. position: volume.position.toArray(),
  62073. rotation: volume.rotation.toArray(),
  62074. scale: volume.scale.toArray(),
  62075. visible: volume.visible,
  62076. clip: volume.clip,
  62077. };
  62078. return data;
  62079. }
  62080. function createCameraAnimationData(animation){
  62081. const controlPoints = animation.controlPoints.map( cp => {
  62082. const cpdata = {
  62083. position: cp.position.toArray(),
  62084. target: cp.target.toArray(),
  62085. };
  62086. return cpdata;
  62087. });
  62088. const data = {
  62089. uuid: animation.uuid,
  62090. name: animation.name,
  62091. duration: animation.duration,
  62092. t: animation.t,
  62093. curveType: animation.curveType,
  62094. visible: animation.visible,
  62095. controlPoints: controlPoints,
  62096. };
  62097. return data;
  62098. }
  62099. function createMeasurementData(measurement){
  62100. const data = {
  62101. uuid: measurement.uuid,
  62102. name: measurement.name,
  62103. points: measurement.points.map(p => p.position.toArray()),
  62104. showDistances: measurement.showDistances,
  62105. showCoordinates: measurement.showCoordinates,
  62106. showArea: measurement.showArea,
  62107. closed: measurement.closed,
  62108. showAngles: measurement.showAngles,
  62109. showHeight: measurement.showHeight,
  62110. showCircle: measurement.showCircle,
  62111. showAzimuth: measurement.showAzimuth,
  62112. showEdges: measurement.showEdges,
  62113. color: measurement.color.toArray(),
  62114. };
  62115. return data;
  62116. }
  62117. function createOrientedImagesData(images){
  62118. const data = {
  62119. cameraParamsPath: images.cameraParamsPath,
  62120. imageParamsPath: images.imageParamsPath,
  62121. };
  62122. return data;
  62123. }
  62124. function createGeopackageData(geopackage){
  62125. const data = {
  62126. path: geopackage.path,
  62127. };
  62128. return data;
  62129. }
  62130. function createAnnotationData(annotation){
  62131. const data = {
  62132. uuid: annotation.uuid,
  62133. title: annotation.title.toString(),
  62134. description: annotation.description,
  62135. position: annotation.position.toArray(),
  62136. offset: annotation.offset.toArray(),
  62137. children: [],
  62138. };
  62139. if(annotation.cameraPosition){
  62140. data.cameraPosition = annotation.cameraPosition.toArray();
  62141. }
  62142. if(annotation.cameraTarget){
  62143. data.cameraTarget = annotation.cameraTarget.toArray();
  62144. }
  62145. if(typeof annotation.radius !== "undefined"){
  62146. data.radius = annotation.radius;
  62147. }
  62148. return data;
  62149. }
  62150. function createAnnotationsData(viewer){
  62151. const map = new Map();
  62152. viewer.scene.annotations.traverseDescendants(a => {
  62153. const aData = createAnnotationData(a);
  62154. map.set(a, aData);
  62155. });
  62156. for(const [annotation, data] of map){
  62157. for(const child of annotation.children){
  62158. const childData = map.get(child);
  62159. data.children.push(childData);
  62160. }
  62161. }
  62162. const annotations = viewer.scene.annotations.children.map(a => map.get(a));
  62163. return annotations;
  62164. }
  62165. function createSettingsData(viewer){
  62166. return {
  62167. pointBudget: viewer.getPointBudget(),
  62168. fov: viewer.getFOV(),
  62169. edlEnabled: viewer.getEDLEnabled(),
  62170. edlRadius: viewer.getEDLRadius(),
  62171. edlStrength: viewer.getEDLStrength(),
  62172. background: viewer.getBackground(),
  62173. minNodeSize: viewer.getMinNodeSize(),
  62174. showBoundingBoxes: viewer.getShowBoundingBox(),
  62175. };
  62176. }
  62177. function createSceneContentData(viewer){
  62178. const data = [];
  62179. const potreeObjects = [];
  62180. viewer.scene.scene.traverse(node => {
  62181. if(node.potree){
  62182. potreeObjects.push(node);
  62183. }
  62184. });
  62185. for(const object of potreeObjects){
  62186. if(object.potree.file){
  62187. const saveObject = {
  62188. file: object.potree.file,
  62189. };
  62190. data.push(saveObject);
  62191. }
  62192. }
  62193. return data;
  62194. }
  62195. function createViewData(viewer){
  62196. const view = viewer.scene.view;
  62197. const data = {
  62198. position: view.position.toArray(),
  62199. target: view.getPivot().toArray(),
  62200. };
  62201. return data;
  62202. }
  62203. function createClassificationData(viewer){
  62204. const classifications = viewer.classifications;
  62205. const data = classifications;
  62206. return data;
  62207. }
  62208. function saveProject(viewer) {
  62209. const scene = viewer.scene;
  62210. const data = {
  62211. type: "Potree",
  62212. version: 1.7,
  62213. settings: createSettingsData(viewer),
  62214. view: createViewData(viewer),
  62215. classification: createClassificationData(viewer),
  62216. pointclouds: scene.pointclouds.map(createPointcloudData),
  62217. measurements: scene.measurements.map(createMeasurementData),
  62218. volumes: scene.volumes.map(createVolumeData),
  62219. cameraAnimations: scene.cameraAnimations.map(createCameraAnimationData),
  62220. profiles: scene.profiles.map(createProfileData),
  62221. annotations: createAnnotationsData(viewer),
  62222. orientedImages: scene.orientedImages.map(createOrientedImagesData),
  62223. geopackages: scene.geopackages.map(createGeopackageData),
  62224. // objects: createSceneContentData(viewer),
  62225. };
  62226. return data;
  62227. }
  62228. class ControlPoint{
  62229. constructor(){
  62230. this.position = new Vector3(0, 0, 0);
  62231. this.target = new Vector3(0, 0, 0);
  62232. this.positionHandle = null;
  62233. this.targetHandle = null;
  62234. }
  62235. };
  62236. class CameraAnimation extends EventDispatcher$1{
  62237. constructor(viewer){
  62238. super();
  62239. this.viewer = viewer;
  62240. this.selectedElement = null;
  62241. this.controlPoints = [];
  62242. this.uuid = MathUtils.generateUUID();
  62243. this.node = new Object3D();
  62244. this.node.name = "camera animation";
  62245. this.viewer.scene.scene.add(this.node);
  62246. this.frustum = this.createFrustum();
  62247. this.node.add(this.frustum);
  62248. this.name = "Camera Animation";
  62249. this.duration = 5;
  62250. this.t = 0;
  62251. // "centripetal", "chordal", "catmullrom"
  62252. this.curveType = "centripetal";
  62253. this.visible = true;
  62254. this.createUpdateHook();
  62255. this.createPath();
  62256. }
  62257. static defaultFromView(viewer){
  62258. const animation = new CameraAnimation(viewer);
  62259. const camera = viewer.scene.getActiveCamera();
  62260. const target = viewer.scene.view.getPivot();
  62261. const cpCenter = new Vector3(
  62262. 0.3 * camera.position.x + 0.7 * target.x,
  62263. 0.3 * camera.position.y + 0.7 * target.y,
  62264. 0.3 * camera.position.z + 0.7 * target.z,
  62265. );
  62266. const targetCenter = new Vector3(
  62267. 0.05 * camera.position.x + 0.95 * target.x,
  62268. 0.05 * camera.position.y + 0.95 * target.y,
  62269. 0.05 * camera.position.z + 0.95 * target.z,
  62270. );
  62271. const r = camera.position.distanceTo(target) * 0.3;
  62272. //const dir = target.clone().sub(camera.position).normalize();
  62273. const angle = Utils.computeAzimuth(camera.position, target);
  62274. const n = 5;
  62275. for(let i = 0; i < n; i++){
  62276. let u = 1.5 * Math.PI * (i / n) + angle;
  62277. const dx = r * Math.cos(u);
  62278. const dy = r * Math.sin(u);
  62279. const cpPos = [
  62280. cpCenter.x + dx,
  62281. cpCenter.y + dy,
  62282. cpCenter.z,
  62283. ];
  62284. const targetPos = [
  62285. targetCenter.x + dx * 0.1,
  62286. targetCenter.y + dy * 0.1,
  62287. targetCenter.z,
  62288. ];
  62289. const cp = animation.createControlPoint();
  62290. cp.position.set(...cpPos);
  62291. cp.target.set(...targetPos);
  62292. }
  62293. return animation;
  62294. }
  62295. createUpdateHook(){
  62296. const viewer = this.viewer;
  62297. viewer.addEventListener("update", () => {
  62298. const camera = viewer.scene.getActiveCamera();
  62299. const {width, height} = viewer.renderer.getSize(new Vector2());
  62300. this.node.visible = this.visible;
  62301. for(const cp of this.controlPoints){
  62302. { // position
  62303. const projected = cp.position.clone().project(camera);
  62304. const visible = this.visible && (projected.z < 1 && projected.z > -1);
  62305. if(visible){
  62306. const x = width * (projected.x * 0.5 + 0.5);
  62307. const y = height - height * (projected.y * 0.5 + 0.5);
  62308. cp.positionHandle.svg.style.left = x - cp.positionHandle.svg.clientWidth / 2;
  62309. cp.positionHandle.svg.style.top = y - cp.positionHandle.svg.clientHeight / 2;
  62310. cp.positionHandle.svg.style.display = "";
  62311. }else {
  62312. cp.positionHandle.svg.style.display = "none";
  62313. }
  62314. }
  62315. { // target
  62316. const projected = cp.target.clone().project(camera);
  62317. const visible = this.visible && (projected.z < 1 && projected.z > -1);
  62318. if(visible){
  62319. const x = width * (projected.x * 0.5 + 0.5);
  62320. const y = height - height * (projected.y * 0.5 + 0.5);
  62321. cp.targetHandle.svg.style.left = x - cp.targetHandle.svg.clientWidth / 2;
  62322. cp.targetHandle.svg.style.top = y - cp.targetHandle.svg.clientHeight / 2;
  62323. cp.targetHandle.svg.style.display = "";
  62324. }else {
  62325. cp.targetHandle.svg.style.display = "none";
  62326. }
  62327. }
  62328. }
  62329. this.line.material.resolution.set(width, height);
  62330. this.updatePath();
  62331. { // frustum
  62332. const frame = this.at(this.t);
  62333. const frustum = this.frustum;
  62334. frustum.position.copy(frame.position);
  62335. frustum.lookAt(...frame.target.toArray());
  62336. frustum.scale.set(20, 20, 20);
  62337. frustum.material.resolution.set(width, height);
  62338. }
  62339. });
  62340. }
  62341. createControlPoint(index){
  62342. if(index === undefined){
  62343. index = this.controlPoints.length;
  62344. }
  62345. const cp = new ControlPoint();
  62346. if(this.controlPoints.length >= 2 && index === 0){
  62347. const cp1 = this.controlPoints[0];
  62348. const cp2 = this.controlPoints[1];
  62349. const dir = cp1.position.clone().sub(cp2.position).multiplyScalar(0.5);
  62350. cp.position.copy(cp1.position).add(dir);
  62351. const tDir = cp1.target.clone().sub(cp2.target).multiplyScalar(0.5);
  62352. cp.target.copy(cp1.target).add(tDir);
  62353. }else if(this.controlPoints.length >= 2 && index === this.controlPoints.length){
  62354. const cp1 = this.controlPoints[this.controlPoints.length - 2];
  62355. const cp2 = this.controlPoints[this.controlPoints.length - 1];
  62356. const dir = cp2.position.clone().sub(cp1.position).multiplyScalar(0.5);
  62357. cp.position.copy(cp1.position).add(dir);
  62358. const tDir = cp2.target.clone().sub(cp1.target).multiplyScalar(0.5);
  62359. cp.target.copy(cp2.target).add(tDir);
  62360. }else if(this.controlPoints.length >= 2){
  62361. const cp1 = this.controlPoints[index - 1];
  62362. const cp2 = this.controlPoints[index];
  62363. cp.position.copy(cp1.position.clone().add(cp2.position).multiplyScalar(0.5));
  62364. cp.target.copy(cp1.target.clone().add(cp2.target).multiplyScalar(0.5));
  62365. }
  62366. // cp.position.copy(viewer.scene.view.position);
  62367. // cp.target.copy(viewer.scene.view.getPivot());
  62368. cp.positionHandle = this.createHandle(cp.position);
  62369. cp.targetHandle = this.createHandle(cp.target);
  62370. this.controlPoints.splice(index, 0, cp);
  62371. this.dispatchEvent({
  62372. type: "controlpoint_added",
  62373. controlpoint: cp,
  62374. });
  62375. return cp;
  62376. }
  62377. removeControlPoint(cp){
  62378. this.controlPoints = this.controlPoints.filter(_cp => _cp !== cp);
  62379. this.dispatchEvent({
  62380. type: "controlpoint_removed",
  62381. controlpoint: cp,
  62382. });
  62383. cp.positionHandle.svg.remove();
  62384. cp.targetHandle.svg.remove();
  62385. // TODO destroy cp
  62386. }
  62387. createPath(){
  62388. { // position
  62389. const geometry = new LineGeometry();
  62390. let material = new LineMaterial({
  62391. color: 0x00ff00,
  62392. dashSize: 5,
  62393. gapSize: 2,
  62394. linewidth: 2,
  62395. resolution: new Vector2(1000, 1000),
  62396. });
  62397. const line = new Line2(geometry, material);
  62398. this.line = line;
  62399. this.node.add(line);
  62400. }
  62401. { // target
  62402. const geometry = new LineGeometry();
  62403. let material = new LineMaterial({
  62404. color: 0x0000ff,
  62405. dashSize: 5,
  62406. gapSize: 2,
  62407. linewidth: 2,
  62408. resolution: new Vector2(1000, 1000),
  62409. });
  62410. const line = new Line2(geometry, material);
  62411. this.targetLine = line;
  62412. this.node.add(line);
  62413. }
  62414. }
  62415. createFrustum(){
  62416. const f = 0.3;
  62417. const positions = [
  62418. 0, 0, 0,
  62419. -f, -f, +1,
  62420. 0, 0, 0,
  62421. f, -f, +1,
  62422. 0, 0, 0,
  62423. f, f, +1,
  62424. 0, 0, 0,
  62425. -f, f, +1,
  62426. -f, -f, +1,
  62427. f, -f, +1,
  62428. f, -f, +1,
  62429. f, f, +1,
  62430. f, f, +1,
  62431. -f, f, +1,
  62432. -f, f, +1,
  62433. -f, -f, +1,
  62434. ];
  62435. const geometry = new LineGeometry();
  62436. geometry.setPositions(positions);
  62437. geometry.verticesNeedUpdate = true;
  62438. geometry.computeBoundingSphere();
  62439. let material = new LineMaterial({
  62440. color: 0xff0000,
  62441. linewidth: 2,
  62442. resolution: new Vector2(1000, 1000),
  62443. });
  62444. const line = new Line2(geometry, material);
  62445. line.computeLineDistances();
  62446. return line;
  62447. }
  62448. updatePath(){
  62449. { // positions
  62450. const positions = this.controlPoints.map(cp => cp.position);
  62451. const first = positions[0];
  62452. const curve = new CatmullRomCurve3(positions);
  62453. curve.curveType = this.curveType;
  62454. const n = 100;
  62455. const curvePositions = [];
  62456. for(let k = 0; k <= n; k++){
  62457. const t = k / n;
  62458. const position = curve.getPoint(t).sub(first);
  62459. curvePositions.push(position.x, position.y, position.z);
  62460. }
  62461. this.line.geometry.setPositions(curvePositions);
  62462. this.line.geometry.verticesNeedUpdate = true;
  62463. this.line.geometry.computeBoundingSphere();
  62464. this.line.position.copy(first);
  62465. this.line.computeLineDistances();
  62466. this.cameraCurve = curve;
  62467. }
  62468. { // targets
  62469. const positions = this.controlPoints.map(cp => cp.target);
  62470. const first = positions[0];
  62471. const curve = new CatmullRomCurve3(positions);
  62472. curve.curveType = this.curveType;
  62473. const n = 100;
  62474. const curvePositions = [];
  62475. for(let k = 0; k <= n; k++){
  62476. const t = k / n;
  62477. const position = curve.getPoint(t).sub(first);
  62478. curvePositions.push(position.x, position.y, position.z);
  62479. }
  62480. this.targetLine.geometry.setPositions(curvePositions);
  62481. this.targetLine.geometry.verticesNeedUpdate = true;
  62482. this.targetLine.geometry.computeBoundingSphere();
  62483. this.targetLine.position.copy(first);
  62484. this.targetLine.computeLineDistances();
  62485. this.targetCurve = curve;
  62486. }
  62487. }
  62488. at(t){
  62489. if(t > 1){
  62490. t = 1;
  62491. }else if(t < 0){
  62492. t = 0;
  62493. }
  62494. const camPos = this.cameraCurve.getPointAt(t);
  62495. const target = this.targetCurve.getPointAt(t);
  62496. const frame = {
  62497. position: camPos,
  62498. target: target,
  62499. };
  62500. return frame;
  62501. }
  62502. set(t){
  62503. this.t = t;
  62504. }
  62505. createHandle(vector){
  62506. const svgns = "http://www.w3.org/2000/svg";
  62507. const svg = document.createElementNS(svgns, "svg");
  62508. svg.setAttribute("width", "2em");
  62509. svg.setAttribute("height", "2em");
  62510. svg.setAttribute("position", "absolute");
  62511. svg.style.left = "50px";
  62512. svg.style.top = "50px";
  62513. svg.style.position = "absolute";
  62514. svg.style.zIndex = "10000";
  62515. const circle = document.createElementNS(svgns, 'circle');
  62516. circle.setAttributeNS(null, 'cx', "1em");
  62517. circle.setAttributeNS(null, 'cy', "1em");
  62518. circle.setAttributeNS(null, 'r', "0.5em");
  62519. circle.setAttributeNS(null, 'style', 'fill: red; stroke: black; stroke-width: 0.2em;' );
  62520. svg.appendChild(circle);
  62521. const element = this.viewer.renderer.domElement.parentElement;
  62522. element.appendChild(svg);
  62523. const startDrag = (evt) => {
  62524. this.selectedElement = svg;
  62525. document.addEventListener("mousemove", drag);
  62526. };
  62527. const endDrag = (evt) => {
  62528. this.selectedElement = null;
  62529. document.removeEventListener("mousemove", drag);
  62530. };
  62531. const drag = (evt) => {
  62532. if (this.selectedElement) {
  62533. evt.preventDefault();
  62534. const rect = viewer.renderer.domElement.getBoundingClientRect();
  62535. const x = evt.clientX - rect.x;
  62536. const y = evt.clientY - rect.y;
  62537. const {width, height} = this.viewer.renderer.getSize(new Vector2());
  62538. const camera = this.viewer.scene.getActiveCamera();
  62539. //const cp = this.controlPoints.find(cp => cp.handle.svg === svg);
  62540. const projected = vector.clone().project(camera);
  62541. projected.x = ((x / width) - 0.5) / 0.5;
  62542. projected.y = (-(y - height) / height - 0.5) / 0.5;
  62543. const unprojected = projected.clone().unproject(camera);
  62544. vector.set(unprojected.x, unprojected.y, unprojected.z);
  62545. }
  62546. };
  62547. svg.addEventListener('mousedown', startDrag);
  62548. svg.addEventListener('mouseup', endDrag);
  62549. const handle = {
  62550. svg: svg,
  62551. };
  62552. return handle;
  62553. }
  62554. setVisible(visible){
  62555. this.node.visible = visible;
  62556. const display = visible ? "" : "none";
  62557. for(const cp of this.controlPoints){
  62558. cp.positionHandle.svg.style.display = display;
  62559. cp.targetHandle.svg.style.display = display;
  62560. }
  62561. this.visible = visible;
  62562. }
  62563. setDuration(duration){
  62564. this.duration = duration;
  62565. }
  62566. getDuration(duration){
  62567. return this.duration;
  62568. }
  62569. play(){
  62570. const tStart = performance.now();
  62571. const duration = this.duration;
  62572. const originalyVisible = this.visible;
  62573. this.setVisible(false);
  62574. const onUpdate = (delta) => {
  62575. let tNow = performance.now();
  62576. let elapsed = (tNow - tStart) / 1000;
  62577. let t = elapsed / duration;
  62578. this.set(t);
  62579. const frame = this.at(t);
  62580. viewer.scene.view.position.copy(frame.position);
  62581. viewer.scene.view.lookAt(frame.target);
  62582. if(t > 1){
  62583. this.setVisible(originalyVisible);
  62584. this.viewer.removeEventListener("update", onUpdate);
  62585. }
  62586. };
  62587. this.viewer.addEventListener("update", onUpdate);
  62588. }
  62589. }
  62590. function loadPointCloud(viewer, data){
  62591. let loadMaterial = (target) => {
  62592. if(data.material){
  62593. if(data.material.activeAttributeName != null){
  62594. target.activeAttributeName = data.material.activeAttributeName;
  62595. }
  62596. if(data.material.ranges != null){
  62597. for(let range of data.material.ranges){
  62598. if(range.name === "elevationRange"){
  62599. target.elevationRange = range.value;
  62600. }else if(range.name === "intensityRange"){
  62601. target.intensityRange = range.value;
  62602. }else {
  62603. target.setRange(range.name, range.value);
  62604. }
  62605. }
  62606. }
  62607. if(data.material.size != null){
  62608. target.size = data.material.size;
  62609. }
  62610. if(data.material.minSize != null){
  62611. target.minSize = data.material.minSize;
  62612. }
  62613. if(data.material.pointSizeType != null){
  62614. target.pointSizeType = PointSizeType[data.material.pointSizeType];
  62615. }
  62616. if(data.material.matcap != null){
  62617. target.matcap = data.material.matcap;
  62618. }
  62619. }else if(data.activeAttributeName != null){
  62620. target.activeAttributeName = data.activeAttributeName;
  62621. }else {
  62622. // no material data
  62623. }
  62624. };
  62625. const promise = new Promise((resolve) => {
  62626. const names = viewer.scene.pointclouds.map(p => p.name);
  62627. const alreadyExists = names.includes(data.name);
  62628. if(alreadyExists){
  62629. resolve();
  62630. return;
  62631. }
  62632. Potree.loadPointCloud(data.url, data.name, (e) => {
  62633. const {pointcloud} = e;
  62634. pointcloud.position.set(...data.position);
  62635. pointcloud.rotation.set(...data.rotation);
  62636. pointcloud.scale.set(...data.scale);
  62637. loadMaterial(pointcloud.material);
  62638. viewer.scene.addPointCloud(pointcloud);
  62639. resolve(pointcloud);
  62640. });
  62641. });
  62642. return promise;
  62643. }
  62644. function loadMeasurement(viewer, data){
  62645. const duplicate = viewer.scene.measurements.find(measure => measure.uuid === data.uuid);
  62646. if(duplicate){
  62647. return;
  62648. }
  62649. const measure = new Measure();
  62650. measure.uuid = data.uuid;
  62651. measure.name = data.name;
  62652. measure.showDistances = data.showDistances;
  62653. measure.showCoordinates = data.showCoordinates;
  62654. measure.showArea = data.showArea;
  62655. measure.closed = data.closed;
  62656. measure.showAngles = data.showAngles;
  62657. measure.showHeight = data.showHeight;
  62658. measure.showCircle = data.showCircle;
  62659. measure.showAzimuth = data.showAzimuth;
  62660. measure.showEdges = data.showEdges;
  62661. // color
  62662. for(const point of data.points){
  62663. const pos = new Vector3(...point);
  62664. measure.addMarker(pos);
  62665. }
  62666. viewer.scene.addMeasurement(measure);
  62667. }
  62668. function loadVolume(viewer, data){
  62669. const duplicate = viewer.scene.volumes.find(volume => volume.uuid === data.uuid);
  62670. if(duplicate){
  62671. return;
  62672. }
  62673. let volume = new Potree[data.type];
  62674. volume.uuid = data.uuid;
  62675. volume.name = data.name;
  62676. volume.position.set(...data.position);
  62677. volume.rotation.set(...data.rotation);
  62678. volume.scale.set(...data.scale);
  62679. volume.visible = data.visible;
  62680. volume.clip = data.clip;
  62681. viewer.scene.addVolume(volume);
  62682. }
  62683. function loadCameraAnimation(viewer, data){
  62684. const duplicate = viewer.scene.cameraAnimations.find(a => a.uuid === data.uuid);
  62685. if(duplicate){
  62686. return;
  62687. }
  62688. const animation = new CameraAnimation(viewer);
  62689. animation.uuid = data.uuid;
  62690. animation.name = data.name;
  62691. animation.duration = data.duration;
  62692. animation.t = data.t;
  62693. animation.curveType = data.curveType;
  62694. animation.visible = data.visible;
  62695. animation.controlPoints = [];
  62696. for(const cpdata of data.controlPoints){
  62697. const cp = animation.createControlPoint();
  62698. cp.position.set(...cpdata.position);
  62699. cp.target.set(...cpdata.target);
  62700. }
  62701. viewer.scene.addCameraAnimation(animation);
  62702. }
  62703. function loadOrientedImages(viewer, images){
  62704. const {cameraParamsPath, imageParamsPath} = images;
  62705. const duplicate = viewer.scene.orientedImages.find(i => i.imageParamsPath === imageParamsPath);
  62706. if(duplicate){
  62707. return;
  62708. }
  62709. Potree.OrientedImageLoader.load(cameraParamsPath, imageParamsPath, viewer).then( images => {
  62710. viewer.scene.addOrientedImages(images);
  62711. });
  62712. }
  62713. function loadGeopackage(viewer, geopackage){
  62714. const path = geopackage.path;
  62715. const duplicate = viewer.scene.geopackages.find(i => i.path === path);
  62716. if(duplicate){
  62717. return;
  62718. }
  62719. const projection = viewer.getProjection();
  62720. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  62721. proj4.defs("pointcloud", projection);
  62722. const transform = proj4("WGS84", "pointcloud");
  62723. const params = {
  62724. transform: transform,
  62725. };
  62726. Potree.GeoPackageLoader.loadUrl(path, params).then(data => {
  62727. viewer.scene.addGeopackage(data);
  62728. });
  62729. }
  62730. function loadSettings(viewer, data){
  62731. if(!data){
  62732. return;
  62733. }
  62734. viewer.setPointBudget(data.pointBudget);
  62735. viewer.setFOV(data.fov);
  62736. viewer.setEDLEnabled(data.edlEnabled);
  62737. viewer.setEDLRadius(data.edlRadius);
  62738. viewer.setEDLStrength(data.edlStrength);
  62739. viewer.setBackground(data.background);
  62740. viewer.setMinNodeSize(data.minNodeSize);
  62741. viewer.setShowBoundingBox(data.showBoundingBoxes);
  62742. }
  62743. function loadView(viewer, view){
  62744. viewer.scene.view.position.set(...view.position);
  62745. viewer.scene.view.lookAt(...view.target);
  62746. }
  62747. function loadAnnotationItem(item){
  62748. const annotation = new Annotation({
  62749. position: item.position,
  62750. title: item.title,
  62751. cameraPosition: item.cameraPosition,
  62752. cameraTarget: item.cameraTarget,
  62753. });
  62754. annotation.description = item.description;
  62755. annotation.uuid = item.uuid;
  62756. if(item.offset){
  62757. annotation.offset.set(...item.offset);
  62758. }
  62759. return annotation;
  62760. }
  62761. function loadAnnotations(viewer, data){
  62762. if(!data){
  62763. return;
  62764. }
  62765. const findDuplicate = (item) => {
  62766. let duplicate = null;
  62767. viewer.scene.annotations.traverse( a => {
  62768. if(a.uuid === item.uuid){
  62769. duplicate = a;
  62770. }
  62771. });
  62772. return duplicate;
  62773. };
  62774. const traverse = (item, parent) => {
  62775. const duplicate = findDuplicate(item);
  62776. if(duplicate){
  62777. return;
  62778. }
  62779. const annotation = loadAnnotationItem(item);
  62780. for(const childItem of item.children){
  62781. traverse(childItem, annotation);
  62782. }
  62783. parent.add(annotation);
  62784. };
  62785. for(const item of data){
  62786. traverse(item, viewer.scene.annotations);
  62787. }
  62788. }
  62789. function loadProfile(viewer, data){
  62790. const {name, points} = data;
  62791. const duplicate = viewer.scene.profiles.find(profile => profile.uuid === data.uuid);
  62792. if(duplicate){
  62793. return;
  62794. }
  62795. let profile = new Potree.Profile();
  62796. profile.name = name;
  62797. profile.uuid = data.uuid;
  62798. profile.setWidth(data.width);
  62799. for(const point of points){
  62800. profile.addMarker(new Vector3(...point));
  62801. }
  62802. viewer.scene.addProfile(profile);
  62803. }
  62804. function loadClassification(viewer, data){
  62805. if(!data){
  62806. return;
  62807. }
  62808. const classifications = data;
  62809. viewer.setClassifications(classifications);
  62810. }
  62811. async function loadProject(viewer, data){
  62812. if(data.type !== "Potree"){
  62813. console.error("not a valid Potree project");
  62814. return;
  62815. }
  62816. loadSettings(viewer, data.settings);
  62817. loadView(viewer, data.view);
  62818. const pointcloudPromises = [];
  62819. for(const pointcloud of data.pointclouds){
  62820. const promise = loadPointCloud(viewer, pointcloud);
  62821. pointcloudPromises.push(promise);
  62822. }
  62823. for(const measure of data.measurements){
  62824. loadMeasurement(viewer, measure);
  62825. }
  62826. for(const volume of data.volumes){
  62827. loadVolume(viewer, volume);
  62828. }
  62829. for(const animation of data.cameraAnimations){
  62830. loadCameraAnimation(viewer, animation);
  62831. }
  62832. for(const profile of data.profiles){
  62833. loadProfile(viewer, profile);
  62834. }
  62835. if(data.orientedImages){
  62836. for(const images of data.orientedImages){
  62837. loadOrientedImages(viewer, images);
  62838. }
  62839. }
  62840. loadAnnotations(viewer, data.annotations);
  62841. loadClassification(viewer, data.classification);
  62842. // need to load at least one point cloud that defines the scene projection,
  62843. // before we can load stuff in other projections such as geopackages
  62844. //await Promise.any(pointcloudPromises); // (not yet supported)
  62845. Utils.waitAny(pointcloudPromises).then( () => {
  62846. if(data.geopackages){
  62847. for(const geopackage of data.geopackages){
  62848. loadGeopackage(viewer, geopackage);
  62849. }
  62850. }
  62851. });
  62852. await Promise.all(pointcloudPromises);
  62853. }
  62854. //
  62855. // Algorithm by Christian Boucheny
  62856. // shader code taken and adapted from CloudCompare
  62857. //
  62858. // see
  62859. // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
  62860. // http://www.kitware.com/source/home/post/9
  62861. // https://tel.archives-ouvertes.fr/tel-00438464/document p. 115+ (french)
  62862. class EyeDomeLightingMaterial extends RawShaderMaterial{//base
  62863. constructor(parameters = {}){
  62864. super();
  62865. let uniforms = {
  62866. screenWidth: { type: 'f', value: 0 },
  62867. screenHeight: { type: 'f', value: 0 },
  62868. edlStrength: { type: 'f', value: 1.0 },
  62869. uNear: { type: 'f', value: 1.0 },
  62870. uFar: { type: 'f', value: 1.0 },
  62871. radius: { type: 'f', value: 1.0 },
  62872. neighbours: { type: '2fv', value: [] },
  62873. depthMap: { type: 't', value: null },
  62874. uEDLColor: { type: 't', value: null },
  62875. uEDLDepth: { type: 't', value: null },
  62876. opacity: { type: 'f', value: 1.0 },
  62877. uProj: { type: "Matrix4fv", value: [] },
  62878. };
  62879. this.setValues({
  62880. uniforms: uniforms,
  62881. vertexShader: this.getDefines() + Shaders['edl.vs'],
  62882. fragmentShader: this.getDefines() + Shaders['edl.fs'],
  62883. lights: false
  62884. });
  62885. this.neighbourCount = 8;
  62886. }
  62887. getDefines() {
  62888. let defines = '';
  62889. defines += '#define NEIGHBOUR_COUNT ' + this.neighbourCount + '\n';
  62890. return defines;
  62891. }
  62892. updateShaderSource() {
  62893. let vs = this.getDefines() + Shaders['edl.vs'];
  62894. let fs = this.getDefines() + Shaders['edl.fs'];
  62895. this.setValues({
  62896. vertexShader: vs,
  62897. fragmentShader: fs
  62898. });
  62899. this.uniforms.neighbours.value = this.neighbours;
  62900. this.needsUpdate = true;
  62901. }
  62902. get neighbourCount(){
  62903. return this._neighbourCount;
  62904. }
  62905. set neighbourCount(value){
  62906. if (this._neighbourCount !== value) {//周围八个格子
  62907. this._neighbourCount = value;
  62908. this.neighbours = new Float32Array(this._neighbourCount * 2);
  62909. for (let c = 0; c < this._neighbourCount; c++) {
  62910. this.neighbours[2 * c + 0] = Math.cos(2 * c * Math.PI / this._neighbourCount);
  62911. this.neighbours[2 * c + 1] = Math.sin(2 * c * Math.PI / this._neighbourCount);
  62912. }
  62913. this.updateShaderSource();
  62914. }
  62915. }
  62916. }
  62917. /**
  62918. * laslaz code taken and adapted from plas.io js-laslaz
  62919. * http://plas.io/
  62920. * https://github.com/verma/plasio
  62921. *
  62922. * Thanks to Uday Verma and Howard Butler
  62923. *
  62924. */
  62925. class LasLazLoader {
  62926. constructor (version, extension) {
  62927. if (typeof (version) === 'string') {
  62928. this.version = new Version(version);
  62929. } else {
  62930. this.version = version;
  62931. }
  62932. this.extension = extension;
  62933. }
  62934. static progressCB () {
  62935. }
  62936. load (node, callback) {
  62937. if (node.loaded) {
  62938. return;
  62939. }
  62940. let url = node.getURL();
  62941. if (this.version.equalOrHigher('1.4')) {
  62942. url += `.${this.extension}`;
  62943. }
  62944. let xhr = XHRFactory.createXMLHttpRequest();
  62945. xhr.open('GET', url, true);
  62946. xhr.responseType = 'arraybuffer';
  62947. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  62948. xhr.onreadystatechange = () => {
  62949. if (xhr.readyState === 4) {
  62950. if (xhr.status === 200 || xhr.status === 0) {
  62951. let buffer = xhr.response;
  62952. this.parse(node, buffer, callback);
  62953. } else {
  62954. console.log('Failed to load file! HTTP status: ' + xhr.status + ', file: ' + url);
  62955. }
  62956. }
  62957. };
  62958. xhr.send(null);
  62959. }
  62960. async parse(node, buffer, callback){//add callback
  62961. let lf = new LASFile(buffer);
  62962. let handler = new LasLazBatcher(node);
  62963. try{
  62964. await lf.open();
  62965. lf.isOpen = true;
  62966. }catch(e){
  62967. console.log("failed to open file. :(");
  62968. return;
  62969. }
  62970. let header = await lf.getHeader();
  62971. let skip = 1;
  62972. let totalRead = 0;
  62973. let totalToRead = (skip <= 1 ? header.pointsCount : header.pointsCount / skip);
  62974. let hasMoreData = true;
  62975. while(hasMoreData){
  62976. let data = await lf.readData(1000 * 1000, 0, skip);
  62977. handler.push(new LASDecoder(data.buffer,
  62978. header.pointsFormatId,
  62979. header.pointsStructSize,
  62980. data.count,
  62981. header.scale,
  62982. header.offset,
  62983. header.mins, header.maxs));
  62984. totalRead += data.count;
  62985. LasLazLoader.progressCB(totalRead / totalToRead);
  62986. hasMoreData = data.hasMoreData;
  62987. }
  62988. header.totalRead = totalRead;
  62989. header.versionAsString = lf.versionAsString;
  62990. header.isCompressed = lf.isCompressed;
  62991. LasLazLoader.progressCB(1);
  62992. try{
  62993. await lf.close();
  62994. lf.isOpen = false;
  62995. }catch(e){
  62996. console.error("failed to close las/laz file!!!");
  62997. throw e;
  62998. }
  62999. callback(); //add
  63000. }
  63001. handle (node, url) {
  63002. }
  63003. };
  63004. class LasLazBatcher{
  63005. constructor (node) {
  63006. this.node = node;
  63007. }
  63008. push (lasBuffer) {
  63009. const workerPath = Potree.scriptPath + '/workers/LASDecoderWorker.js';
  63010. const worker = Potree.workerPool.getWorker(workerPath);
  63011. const node = this.node;
  63012. const pointAttributes = node.pcoGeometry.pointAttributes;
  63013. worker.onmessage = (e) => {
  63014. let geometry = new BufferGeometry();
  63015. let numPoints = lasBuffer.pointsCount;
  63016. let positions = new Float32Array(e.data.position);
  63017. let colors = new Uint8Array(e.data.color);
  63018. let intensities = new Float32Array(e.data.intensity);
  63019. let classifications = new Uint8Array(e.data.classification);
  63020. let returnNumbers = new Uint8Array(e.data.returnNumber);
  63021. let numberOfReturns = new Uint8Array(e.data.numberOfReturns);
  63022. let pointSourceIDs = new Uint16Array(e.data.pointSourceID);
  63023. let indices = new Uint8Array(e.data.indices);
  63024. geometry.setAttribute('position', new BufferAttribute(positions, 3));
  63025. geometry.setAttribute('color', new BufferAttribute(colors, 4, true));
  63026. geometry.setAttribute('intensity', new BufferAttribute(intensities, 1));
  63027. geometry.setAttribute('classification', new BufferAttribute(classifications, 1));
  63028. geometry.setAttribute('return number', new BufferAttribute(returnNumbers, 1));
  63029. geometry.setAttribute('number of returns', new BufferAttribute(numberOfReturns, 1));
  63030. geometry.setAttribute('source id', new BufferAttribute(pointSourceIDs, 1));
  63031. geometry.setAttribute('indices', new BufferAttribute(indices, 4));
  63032. geometry.attributes.indices.normalized = true;
  63033. for(const key in e.data.ranges){
  63034. const range = e.data.ranges[key];
  63035. const attribute = pointAttributes.attributes.find(a => a.name === key);
  63036. attribute.range[0] = Math.min(attribute.range[0], range[0]);
  63037. attribute.range[1] = Math.max(attribute.range[1], range[1]);
  63038. }
  63039. let tightBoundingBox = new Box3(
  63040. new Vector3().fromArray(e.data.tightBoundingBox.min),
  63041. new Vector3().fromArray(e.data.tightBoundingBox.max)
  63042. );
  63043. geometry.boundingBox = this.node.boundingBox;
  63044. this.node.tightBoundingBox = tightBoundingBox;
  63045. this.node.geometry = geometry;
  63046. this.node.numPoints = numPoints;
  63047. this.node.loaded = true;
  63048. this.node.loading = false;
  63049. Potree.numNodesLoading--;
  63050. this.node.mean = new Vector3(...e.data.mean);
  63051. Potree.workerPool.returnWorker(workerPath, worker);
  63052. };
  63053. let message = {
  63054. buffer: lasBuffer.arrayb,
  63055. numPoints: lasBuffer.pointsCount,
  63056. pointSize: lasBuffer.pointSize,
  63057. pointFormatID: 2,
  63058. scale: lasBuffer.scale,
  63059. offset: lasBuffer.offset,
  63060. mins: lasBuffer.mins,
  63061. maxs: lasBuffer.maxs
  63062. };
  63063. worker.postMessage(message, [message.buffer]);
  63064. };
  63065. }
  63066. function parseAttributes(cloudjs){
  63067. let version = new Version(cloudjs.version);
  63068. const replacements = {
  63069. "COLOR_PACKED": "rgba",
  63070. "RGBA": "rgba",
  63071. "INTENSITY": "intensity",
  63072. "CLASSIFICATION": "classification",
  63073. "GPS_TIME": "gps-time",
  63074. };
  63075. const replaceOldNames = (old) => {
  63076. if(replacements[old]){
  63077. return replacements[old];
  63078. }else {
  63079. return old;
  63080. }
  63081. };
  63082. const pointAttributes = [];
  63083. if(version.upTo('1.7')){
  63084. for(let attributeName of cloudjs.pointAttributes){
  63085. const oldAttribute = PointAttribute[attributeName];
  63086. const attribute = {
  63087. name: oldAttribute.name,
  63088. size: oldAttribute.byteSize,
  63089. elements: oldAttribute.numElements,
  63090. elementSize: oldAttribute.byteSize / oldAttribute.numElements,
  63091. type: oldAttribute.type.name,
  63092. description: "",
  63093. };
  63094. pointAttributes.push(attribute);
  63095. }
  63096. }else {
  63097. pointAttributes.push(...cloudjs.pointAttributes);
  63098. }
  63099. {
  63100. const attributes = new PointAttributes();
  63101. const typeConversion = {
  63102. int8: PointAttributeTypes.DATA_TYPE_INT8,
  63103. int16: PointAttributeTypes.DATA_TYPE_INT16,
  63104. int32: PointAttributeTypes.DATA_TYPE_INT32,
  63105. int64: PointAttributeTypes.DATA_TYPE_INT64,
  63106. uint8: PointAttributeTypes.DATA_TYPE_UINT8,
  63107. uint16: PointAttributeTypes.DATA_TYPE_UINT16,
  63108. uint32: PointAttributeTypes.DATA_TYPE_UINT32,
  63109. uint64: PointAttributeTypes.DATA_TYPE_UINT64,
  63110. double: PointAttributeTypes.DATA_TYPE_DOUBLE,
  63111. float: PointAttributeTypes.DATA_TYPE_FLOAT,
  63112. };
  63113. for(let jsAttribute of pointAttributes){
  63114. if(jsAttribute.name == void 0){ //add 有的是这个,也有的不是(点云编辑页的)
  63115. var attribute_ = PointAttribute[jsAttribute];
  63116. attributes.add(attribute_);
  63117. continue;
  63118. }
  63119. const name = replaceOldNames(jsAttribute.name);
  63120. const type = typeConversion[jsAttribute.type];
  63121. const numElements = jsAttribute.elements;
  63122. const description = jsAttribute.description;
  63123. const attribute = new PointAttribute(name, type, numElements);
  63124. attributes.add(attribute);
  63125. }
  63126. {
  63127. // check if it has normals
  63128. let hasNormals =
  63129. pointAttributes.find(a => a.name === "NormalX") !== undefined &&
  63130. pointAttributes.find(a => a.name === "NormalY") !== undefined &&
  63131. pointAttributes.find(a => a.name === "NormalZ") !== undefined;
  63132. if(hasNormals){
  63133. let vector = {
  63134. name: "NORMAL",
  63135. attributes: ["NormalX", "NormalY", "NormalZ"],
  63136. };
  63137. attributes.addVector(vector);
  63138. }
  63139. }
  63140. return attributes;
  63141. }
  63142. }
  63143. function lasLazAttributes(fMno){
  63144. const attributes = new PointAttributes();
  63145. attributes.add(PointAttribute.POSITION_CARTESIAN);
  63146. attributes.add(new PointAttribute("rgba", PointAttributeTypes.DATA_TYPE_UINT8, 4));
  63147. attributes.add(new PointAttribute("intensity", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  63148. attributes.add(new PointAttribute("classification", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  63149. attributes.add(new PointAttribute("gps-time", PointAttributeTypes.DATA_TYPE_DOUBLE, 1));
  63150. attributes.add(new PointAttribute("number of returns", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  63151. attributes.add(new PointAttribute("return number", PointAttributeTypes.DATA_TYPE_UINT8, 1));
  63152. attributes.add(new PointAttribute("source id", PointAttributeTypes.DATA_TYPE_UINT16, 1));
  63153. //attributes.add(new PointAttribute("pointSourceID", PointAttributeTypes.DATA_TYPE_INT8, 4));
  63154. return attributes;
  63155. }
  63156. class POCLoader {
  63157. static load(url, timeStamp, callback){ //add timeStamp
  63158. try {
  63159. let pco = new PointCloudOctreeGeometry();
  63160. pco.timeStamp = timeStamp;
  63161. pco.url = url;
  63162. let xhr = XHRFactory.createXMLHttpRequest();
  63163. xhr.open('GET', url+'?m='+timeStamp, true);
  63164. xhr.onreadystatechange = function () {
  63165. if (xhr.readyState === 4 && (xhr.status === 200 || xhr.status === 0)) {
  63166. let fMno = JSON.parse(xhr.responseText);
  63167. let version = new Version(fMno.version);
  63168. // assume octreeDir is absolute if it starts with http
  63169. if (fMno.octreeDir.indexOf('http') === 0) {
  63170. pco.octreeDir = fMno.octreeDir;
  63171. } else {
  63172. pco.octreeDir = url + '/../' + fMno.octreeDir;
  63173. }
  63174. pco.spacing = fMno.spacing;
  63175. pco.hierarchyStepSize = fMno.hierarchyStepSize;
  63176. pco.pointAttributes = fMno.pointAttributes;
  63177. let min = new Vector3(fMno.boundingBox.lx, fMno.boundingBox.ly, fMno.boundingBox.lz);
  63178. let max = new Vector3(fMno.boundingBox.ux, fMno.boundingBox.uy, fMno.boundingBox.uz);
  63179. let boundingBox = new Box3(min, max);
  63180. let tightBoundingBox = boundingBox.clone();
  63181. if (fMno.tightBoundingBox) {//这个才是真实的bounding,前面那个bounding的size是个正方体,似乎取了最长边作为边长
  63182. tightBoundingBox.min.copy(new Vector3(fMno.tightBoundingBox.lx, fMno.tightBoundingBox.ly, fMno.tightBoundingBox.lz));
  63183. tightBoundingBox.max.copy(new Vector3(fMno.tightBoundingBox.ux, fMno.tightBoundingBox.uy, fMno.tightBoundingBox.uz));
  63184. }
  63185. let offset = min.clone(); //将成为点云的position,被我用作旋转中心(但在点云中不那么居中,navvis也是这样, 这样可能是为了让模型在这数据的bounding上)
  63186. boundingBox.min.sub(offset); //点云的真实坐标的min都是0,0,0吗(我看案例是,因绕角落旋转,也就是原点)
  63187. boundingBox.max.sub(offset);
  63188. tightBoundingBox.min.sub(offset);
  63189. tightBoundingBox.max.sub(offset);
  63190. //改
  63191. //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 ",
  63192. //"+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs" //给地图
  63193. pco.boundingBox = boundingBox;
  63194. pco.tightBoundingBox = tightBoundingBox;
  63195. pco.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  63196. pco.tightBoundingSphere = tightBoundingBox.getBoundingSphere(new Sphere());
  63197. pco.offset = offset;
  63198. if (fMno.pointAttributes === 'LAS') {
  63199. pco.loader = new LasLazLoader(fMno.version, "las");
  63200. pco.pointAttributes = lasLazAttributes(fMno);
  63201. } else if (fMno.pointAttributes === 'LAZ') {
  63202. pco.loader = new LasLazLoader(fMno.version, "laz");
  63203. pco.pointAttributes = lasLazAttributes(fMno);
  63204. } else {
  63205. pco.loader = new BinaryLoader(fMno.version, boundingBox, fMno.scale);
  63206. pco.pointAttributes = parseAttributes(fMno);
  63207. }
  63208. let nodes = {};
  63209. { // load root
  63210. let name = 'r';
  63211. let root = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  63212. root.level = 0;
  63213. root.hasChildren = true;
  63214. root.spacing = pco.spacing;
  63215. if (version.upTo('1.5')) {
  63216. root.numPoints = fMno.hierarchy[0][1];
  63217. } else {
  63218. root.numPoints = 0;
  63219. }
  63220. pco.root = root;
  63221. pco.root.load();
  63222. nodes[name] = root;
  63223. }
  63224. // load remaining hierarchy
  63225. if (version.upTo('1.4')) {
  63226. for (let i = 1; i < fMno.hierarchy.length; i++) {
  63227. let name = fMno.hierarchy[i][0];
  63228. let numPoints = fMno.hierarchy[i][1];
  63229. let index = parseInt(name.charAt(name.length - 1));
  63230. let parentName = name.substring(0, name.length - 1);
  63231. let parentNode = nodes[parentName];
  63232. let level = name.length - 1;
  63233. //let boundingBox = POCLoader.createChildAABB(parentNode.boundingBox, index);
  63234. let boundingBox = Utils.createChildAABB(parentNode.boundingBox, index);
  63235. let node = new PointCloudOctreeGeometryNode(name, pco, boundingBox);
  63236. node.level = level;
  63237. node.numPoints = numPoints;
  63238. node.spacing = pco.spacing / Math.pow(2, level);
  63239. parentNode.addChild(node);
  63240. nodes[name] = node;
  63241. }
  63242. }
  63243. pco.nodes = nodes;
  63244. callback(pco);
  63245. }
  63246. };
  63247. xhr.send(null);
  63248. } catch (e) {
  63249. console.log("loading failed: '" + url + "'");
  63250. console.log(e);
  63251. callback();
  63252. }
  63253. }
  63254. loadPointAttributes(mno){
  63255. let fpa = mno.pointAttributes;
  63256. let pa = new PointAttributes();
  63257. for (let i = 0; i < fpa.length; i++) {
  63258. let pointAttribute = PointAttribute[fpa[i]];
  63259. pa.add(pointAttribute);
  63260. }
  63261. return pa;
  63262. }
  63263. createChildAABB(aabb, index){
  63264. let min = aabb.min.clone();
  63265. let max = aabb.max.clone();
  63266. let size = new Vector3().subVectors(max, min);
  63267. if ((index & 0b0001) > 0) {
  63268. min.z += size.z / 2;
  63269. } else {
  63270. max.z -= size.z / 2;
  63271. }
  63272. if ((index & 0b0010) > 0) {
  63273. min.y += size.y / 2;
  63274. } else {
  63275. max.y -= size.y / 2;
  63276. }
  63277. if ((index & 0b0100) > 0) {
  63278. min.x += size.x / 2;
  63279. } else {
  63280. max.x -= size.x / 2;
  63281. }
  63282. return new Box3(min, max);
  63283. }
  63284. }
  63285. class OctreeGeometry{
  63286. constructor(){
  63287. this.url = null;
  63288. this.spacing = 0;
  63289. this.boundingBox = null;
  63290. this.root = null;
  63291. this.pointAttributes = null;
  63292. this.loader = null;
  63293. }
  63294. };
  63295. class OctreeGeometryNode{
  63296. constructor(name, octreeGeometry, boundingBox){
  63297. this.id = OctreeGeometryNode.IDCount++;
  63298. this.name = name;
  63299. this.index = parseInt(name.charAt(name.length - 1));
  63300. this.octreeGeometry = octreeGeometry;
  63301. this.boundingBox = boundingBox;
  63302. this.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  63303. this.children = {};
  63304. this.numPoints = 0;
  63305. this.level = null;
  63306. this.oneTimeDisposeHandlers = [];
  63307. }
  63308. isGeometryNode(){
  63309. return true;
  63310. }
  63311. getLevel(){
  63312. return this.level;
  63313. }
  63314. isTreeNode(){
  63315. return false;
  63316. }
  63317. isLoaded(){
  63318. return this.loaded;
  63319. }
  63320. getBoundingSphere(){
  63321. return this.boundingSphere;
  63322. }
  63323. getBoundingBox(){
  63324. return this.boundingBox;
  63325. }
  63326. getChildren(){
  63327. let children = [];
  63328. for (let i = 0; i < 8; i++) {
  63329. if (this.children[i]) {
  63330. children.push(this.children[i]);
  63331. }
  63332. }
  63333. return children;
  63334. }
  63335. getBoundingBox(){
  63336. return this.boundingBox;
  63337. }
  63338. load(){
  63339. if (Potree.numNodesLoading >= Potree.maxNodesLoading) {
  63340. return;
  63341. }
  63342. this.octreeGeometry.loader.load(this);
  63343. }
  63344. getNumPoints(){
  63345. return this.numPoints;
  63346. }
  63347. dispose(){
  63348. if (this.geometry && this.parent != null) {
  63349. this.geometry.dispose();
  63350. this.geometry = null;
  63351. this.loaded = false;
  63352. // this.dispatchEvent( { type: 'dispose' } );
  63353. for (let i = 0; i < this.oneTimeDisposeHandlers.length; i++) {
  63354. let handler = this.oneTimeDisposeHandlers[i];
  63355. handler();
  63356. }
  63357. this.oneTimeDisposeHandlers = [];
  63358. }
  63359. }
  63360. };
  63361. OctreeGeometryNode.IDCount = 0;
  63362. // let loadedNodes = new Set();
  63363. class NodeLoader{
  63364. constructor(url){
  63365. this.url = url;
  63366. }
  63367. async load(node){
  63368. if(node.loaded || node.loading){
  63369. return;
  63370. }
  63371. node.loading = true;
  63372. Potree.numNodesLoading++;
  63373. // console.log(node.name, node.numPoints);
  63374. // if(loadedNodes.has(node.name)){
  63375. // // debugger;
  63376. // }
  63377. // loadedNodes.add(node.name);
  63378. try{
  63379. if(node.nodeType === 2){
  63380. await this.loadHierarchy(node);
  63381. }
  63382. let {byteOffset, byteSize} = node;
  63383. let urlOctree = `${this.url}/../octree.bin`;
  63384. let first = byteOffset;
  63385. let last = byteOffset + byteSize - 1n;
  63386. let buffer;
  63387. if(byteSize === 0n){
  63388. buffer = new ArrayBuffer(0);
  63389. console.warn(`loaded node with 0 bytes: ${node.name}`);
  63390. }else {
  63391. let response = await fetch(urlOctree, {
  63392. headers: {
  63393. 'content-type': 'multipart/byteranges',
  63394. 'Range': `bytes=${first}-${last}`,
  63395. },
  63396. });
  63397. buffer = await response.arrayBuffer();
  63398. }
  63399. let workerPath;
  63400. if(this.metadata.encoding === "BROTLI"){
  63401. workerPath = Potree.scriptPath + '/workers/2.0/DecoderWorker_brotli.js';
  63402. }else {
  63403. workerPath = Potree.scriptPath + '/workers/2.0/DecoderWorker.js';
  63404. }
  63405. let worker = Potree.workerPool.getWorker(workerPath);
  63406. worker.onmessage = function (e) {
  63407. let data = e.data;
  63408. let buffers = data.attributeBuffers;
  63409. Potree.workerPool.returnWorker(workerPath, worker);
  63410. let geometry = new BufferGeometry();
  63411. for(let property in buffers){
  63412. let buffer = buffers[property].buffer;
  63413. if(property === "position"){
  63414. geometry.setAttribute('position', new BufferAttribute(new Float32Array(buffer), 3));
  63415. }else if(property === "rgba"){
  63416. geometry.setAttribute('rgba', new BufferAttribute(new Uint8Array(buffer), 4, true));
  63417. }else if(property === "NORMAL"){
  63418. //geometry.setAttribute('rgba', new THREE.BufferAttribute(new Uint8Array(buffer), 4, true));
  63419. geometry.setAttribute('normal', new BufferAttribute(new Float32Array(buffer), 3));
  63420. }else if (property === "INDICES") {
  63421. let bufferAttribute = new BufferAttribute(new Uint8Array(buffer), 4);
  63422. bufferAttribute.normalized = true;
  63423. geometry.setAttribute('indices', bufferAttribute);
  63424. }else {
  63425. const bufferAttribute = new BufferAttribute(new Float32Array(buffer), 1);
  63426. let batchAttribute = buffers[property].attribute;
  63427. bufferAttribute.potree = {
  63428. offset: buffers[property].offset,
  63429. scale: buffers[property].scale,
  63430. preciseBuffer: buffers[property].preciseBuffer,
  63431. range: batchAttribute.range,
  63432. };
  63433. geometry.setAttribute(property, bufferAttribute);
  63434. }
  63435. }
  63436. // indices ??
  63437. node.density = data.density;
  63438. node.geometry = geometry;
  63439. node.loaded = true;
  63440. node.loading = false;
  63441. Potree.numNodesLoading--;
  63442. };
  63443. let pointAttributes = node.octreeGeometry.pointAttributes;
  63444. let scale = node.octreeGeometry.scale;
  63445. let box = node.boundingBox;
  63446. let min = node.octreeGeometry.offset.clone().add(box.min);
  63447. let size = box.max.clone().sub(box.min);
  63448. let max = min.clone().add(size);
  63449. let numPoints = node.numPoints;
  63450. let offset = node.octreeGeometry.loader.offset;
  63451. let message = {
  63452. name: node.name,
  63453. buffer: buffer,
  63454. pointAttributes: pointAttributes,
  63455. scale: scale,
  63456. min: min,
  63457. max: max,
  63458. size: size,
  63459. offset: offset,
  63460. numPoints: numPoints
  63461. };
  63462. worker.postMessage(message, [message.buffer]);
  63463. }catch(e){
  63464. node.loaded = false;
  63465. node.loading = false;
  63466. Potree.numNodesLoading--;
  63467. console.log(`failed to load ${node.name}`);
  63468. console.log(e);
  63469. console.log(`trying again!`);
  63470. }
  63471. }
  63472. parseHierarchy(node, buffer){
  63473. let view = new DataView(buffer);
  63474. let tStart = performance.now();
  63475. let bytesPerNode = 22;
  63476. let numNodes = buffer.byteLength / bytesPerNode;
  63477. let octree = node.octreeGeometry;
  63478. // let nodes = [node];
  63479. let nodes = new Array(numNodes);
  63480. nodes[0] = node;
  63481. let nodePos = 1;
  63482. for(let i = 0; i < numNodes; i++){
  63483. let current = nodes[i];
  63484. let type = view.getUint8(i * bytesPerNode + 0);
  63485. let childMask = view.getUint8(i * bytesPerNode + 1);
  63486. let numPoints = view.getUint32(i * bytesPerNode + 2, true);
  63487. let byteOffset = view.getBigInt64(i * bytesPerNode + 6, true);
  63488. let byteSize = view.getBigInt64(i * bytesPerNode + 14, true);
  63489. // if(byteSize === 0n){
  63490. // // debugger;
  63491. // }
  63492. if(current.nodeType === 2){
  63493. // replace proxy with real node
  63494. current.byteOffset = byteOffset;
  63495. current.byteSize = byteSize;
  63496. current.numPoints = numPoints;
  63497. }else if(type === 2){
  63498. // load proxy
  63499. current.hierarchyByteOffset = byteOffset;
  63500. current.hierarchyByteSize = byteSize;
  63501. current.numPoints = numPoints;
  63502. }else {
  63503. // load real node
  63504. current.byteOffset = byteOffset;
  63505. current.byteSize = byteSize;
  63506. current.numPoints = numPoints;
  63507. }
  63508. if(current.byteSize === 0n){
  63509. // workaround for issue #1125
  63510. // some inner nodes erroneously report >0 points even though have 0 points
  63511. // however, they still report a byteSize of 0, so based on that we now set node.numPoints to 0
  63512. current.numPoints = 0;
  63513. }
  63514. current.nodeType = type;
  63515. if(current.nodeType === 2){
  63516. continue;
  63517. }
  63518. for(let childIndex = 0; childIndex < 8; childIndex++){
  63519. let childExists = ((1 << childIndex) & childMask) !== 0;
  63520. if(!childExists){
  63521. continue;
  63522. }
  63523. let childName = current.name + childIndex;
  63524. let childAABB = createChildAABB(current.boundingBox, childIndex);
  63525. let child = new OctreeGeometryNode(childName, octree, childAABB);
  63526. child.name = childName;
  63527. child.spacing = current.spacing / 2;
  63528. child.level = current.level + 1;
  63529. current.children[childIndex] = child;
  63530. child.parent = current;
  63531. // nodes.push(child);
  63532. nodes[nodePos] = child;
  63533. nodePos++;
  63534. }
  63535. // if((i % 500) === 0){
  63536. // yield;
  63537. // }
  63538. }
  63539. let duration = (performance.now() - tStart);
  63540. // if(duration > 20){
  63541. // let msg = `duration: ${duration}ms, numNodes: ${numNodes}`;
  63542. // console.log(msg);
  63543. // }
  63544. }
  63545. async loadHierarchy(node){
  63546. let {hierarchyByteOffset, hierarchyByteSize} = node;
  63547. let hierarchyPath = `${this.url}/../hierarchy.bin`;
  63548. let first = hierarchyByteOffset;
  63549. let last = first + hierarchyByteSize - 1n;
  63550. let response = await fetch(hierarchyPath, {
  63551. headers: {
  63552. 'content-type': 'multipart/byteranges',
  63553. 'Range': `bytes=${first}-${last}`,
  63554. },
  63555. });
  63556. let buffer = await response.arrayBuffer();
  63557. this.parseHierarchy(node, buffer);
  63558. // let promise = new Promise((resolve) => {
  63559. // let generator = this.parseHierarchy(node, buffer);
  63560. // let repeatUntilDone = () => {
  63561. // let result = generator.next();
  63562. // if(result.done){
  63563. // resolve();
  63564. // }else{
  63565. // requestAnimationFrame(repeatUntilDone);
  63566. // }
  63567. // };
  63568. // repeatUntilDone();
  63569. // });
  63570. // await promise;
  63571. }
  63572. }
  63573. let tmpVec3 = new Vector3();
  63574. function createChildAABB(aabb, index){
  63575. let min = aabb.min.clone();
  63576. let max = aabb.max.clone();
  63577. let size = tmpVec3.subVectors(max, min);
  63578. if ((index & 0b0001) > 0) {
  63579. min.z += size.z / 2;
  63580. } else {
  63581. max.z -= size.z / 2;
  63582. }
  63583. if ((index & 0b0010) > 0) {
  63584. min.y += size.y / 2;
  63585. } else {
  63586. max.y -= size.y / 2;
  63587. }
  63588. if ((index & 0b0100) > 0) {
  63589. min.x += size.x / 2;
  63590. } else {
  63591. max.x -= size.x / 2;
  63592. }
  63593. return new Box3(min, max);
  63594. }
  63595. let typenameTypeattributeMap = {
  63596. "double": PointAttributeTypes.DATA_TYPE_DOUBLE,
  63597. "float": PointAttributeTypes.DATA_TYPE_FLOAT,
  63598. "int8": PointAttributeTypes.DATA_TYPE_INT8,
  63599. "uint8": PointAttributeTypes.DATA_TYPE_UINT8,
  63600. "int16": PointAttributeTypes.DATA_TYPE_INT16,
  63601. "uint16": PointAttributeTypes.DATA_TYPE_UINT16,
  63602. "int32": PointAttributeTypes.DATA_TYPE_INT32,
  63603. "uint32": PointAttributeTypes.DATA_TYPE_UINT32,
  63604. "int64": PointAttributeTypes.DATA_TYPE_INT64,
  63605. "uint64": PointAttributeTypes.DATA_TYPE_UINT64,
  63606. };
  63607. class OctreeLoader{
  63608. static parseAttributes(jsonAttributes){
  63609. let attributes = new PointAttributes();
  63610. let replacements = {
  63611. "rgb": "rgba",
  63612. };
  63613. for (const jsonAttribute of jsonAttributes) {
  63614. let {name, description, size, numElements, elementSize, min, max} = jsonAttribute;
  63615. let type = typenameTypeattributeMap[jsonAttribute.type];
  63616. let potreeAttributeName = replacements[name] ? replacements[name] : name;
  63617. let attribute = new PointAttribute(potreeAttributeName, type, numElements);
  63618. if(numElements === 1){
  63619. attribute.range = [min[0], max[0]];
  63620. }else {
  63621. attribute.range = [min, max];
  63622. }
  63623. if (name === "gps-time") { // HACK: Guard against bad gpsTime range in metadata, see potree/potree#909
  63624. if (attribute.range[0] === attribute.range[1]) {
  63625. attribute.range[1] += 1;
  63626. }
  63627. }
  63628. attribute.initialRange = attribute.range;
  63629. attributes.add(attribute);
  63630. }
  63631. {
  63632. // check if it has normals
  63633. let hasNormals =
  63634. attributes.attributes.find(a => a.name === "NormalX") !== undefined &&
  63635. attributes.attributes.find(a => a.name === "NormalY") !== undefined &&
  63636. attributes.attributes.find(a => a.name === "NormalZ") !== undefined;
  63637. if(hasNormals){
  63638. let vector = {
  63639. name: "NORMAL",
  63640. attributes: ["NormalX", "NormalY", "NormalZ"],
  63641. };
  63642. attributes.addVector(vector);
  63643. }
  63644. }
  63645. return attributes;
  63646. }
  63647. static async load(url){
  63648. let response = await fetch(url);
  63649. let metadata = await response.json();
  63650. let attributes = OctreeLoader.parseAttributes(metadata.attributes);
  63651. let loader = new NodeLoader(url);
  63652. loader.metadata = metadata;
  63653. loader.attributes = attributes;
  63654. loader.scale = metadata.scale;
  63655. loader.offset = metadata.offset;
  63656. let octree = new OctreeGeometry();
  63657. octree.url = url;
  63658. octree.spacing = metadata.spacing;
  63659. octree.scale = metadata.scale;
  63660. // let aPosition = metadata.attributes.find(a => a.name === "position");
  63661. // octree
  63662. let min = new Vector3(...metadata.boundingBox.min);
  63663. let max = new Vector3(...metadata.boundingBox.max);
  63664. let boundingBox = new Box3(min, max);
  63665. let offset = min.clone();
  63666. boundingBox.min.sub(offset);
  63667. boundingBox.max.sub(offset);
  63668. octree.projection = metadata.projection;
  63669. octree.boundingBox = boundingBox;
  63670. octree.tightBoundingBox = boundingBox.clone();
  63671. octree.boundingSphere = boundingBox.getBoundingSphere(new Sphere());
  63672. octree.tightBoundingSphere = boundingBox.getBoundingSphere(new Sphere());
  63673. octree.offset = offset;
  63674. octree.pointAttributes = OctreeLoader.parseAttributes(metadata.attributes);
  63675. octree.loader = loader;
  63676. let root = new OctreeGeometryNode("r", octree, boundingBox);
  63677. root.level = 0;
  63678. root.nodeType = 2;
  63679. root.hierarchyByteOffset = 0n;
  63680. root.hierarchyByteSize = BigInt(metadata.hierarchy.firstChunkSize);
  63681. root.hasChildren = false;
  63682. root.spacing = octree.spacing;
  63683. root.byteOffset = 0;
  63684. octree.root = root;
  63685. loader.load(root);
  63686. let result = {
  63687. geometry: octree,
  63688. };
  63689. return result;
  63690. }
  63691. };
  63692. /**
  63693. * @author Connor Manning
  63694. */
  63695. class EptLoader {
  63696. static async load(file, callback) {
  63697. let response = await fetch(file);
  63698. let json = await response.json();
  63699. let url = file.substr(0, file.lastIndexOf('ept.json'));
  63700. let geometry = new Potree.PointCloudEptGeometry(url, json);
  63701. let root = new Potree.PointCloudEptGeometryNode(geometry);
  63702. geometry.root = root;
  63703. geometry.root.load();
  63704. callback(geometry);
  63705. }
  63706. };
  63707. class EptBinaryLoader {
  63708. extension() {
  63709. return '.bin';
  63710. }
  63711. workerPath() {
  63712. return Potree.scriptPath + '/workers/EptBinaryDecoderWorker.js';
  63713. }
  63714. load(node) {
  63715. if (node.loaded) return;
  63716. let url = node.url() + this.extension();
  63717. let xhr = XHRFactory.createXMLHttpRequest();
  63718. xhr.open('GET', url, true);
  63719. xhr.responseType = 'arraybuffer';
  63720. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  63721. xhr.onreadystatechange = () => {
  63722. if (xhr.readyState === 4) {
  63723. if (xhr.status === 200) {
  63724. let buffer = xhr.response;
  63725. this.parse(node, buffer);
  63726. } else {
  63727. console.log('Failed ' + url + ': ' + xhr.status);
  63728. }
  63729. }
  63730. };
  63731. try {
  63732. xhr.send(null);
  63733. }
  63734. catch (e) {
  63735. console.log('Failed request: ' + e);
  63736. }
  63737. }
  63738. parse(node, buffer) {
  63739. let workerPath = this.workerPath();
  63740. let worker = Potree.workerPool.getWorker(workerPath);
  63741. worker.onmessage = function(e) {
  63742. let g = new BufferGeometry();
  63743. let numPoints = e.data.numPoints;
  63744. let position = new Float32Array(e.data.position);
  63745. g.setAttribute('position', new BufferAttribute(position, 3));
  63746. let indices = new Uint8Array(e.data.indices);
  63747. g.setAttribute('indices', new BufferAttribute(indices, 4));
  63748. if (e.data.color) {
  63749. let color = new Uint8Array(e.data.color);
  63750. g.setAttribute('color', new BufferAttribute(color, 4, true));
  63751. }
  63752. if (e.data.intensity) {
  63753. let intensity = new Float32Array(e.data.intensity);
  63754. g.setAttribute('intensity',
  63755. new BufferAttribute(intensity, 1));
  63756. }
  63757. if (e.data.classification) {
  63758. let classification = new Uint8Array(e.data.classification);
  63759. g.setAttribute('classification',
  63760. new BufferAttribute(classification, 1));
  63761. }
  63762. if (e.data.returnNumber) {
  63763. let returnNumber = new Uint8Array(e.data.returnNumber);
  63764. g.setAttribute('return number',
  63765. new BufferAttribute(returnNumber, 1));
  63766. }
  63767. if (e.data.numberOfReturns) {
  63768. let numberOfReturns = new Uint8Array(e.data.numberOfReturns);
  63769. g.setAttribute('number of returns',
  63770. new BufferAttribute(numberOfReturns, 1));
  63771. }
  63772. if (e.data.pointSourceId) {
  63773. let pointSourceId = new Uint16Array(e.data.pointSourceId);
  63774. g.setAttribute('source id',
  63775. new BufferAttribute(pointSourceId, 1));
  63776. }
  63777. g.attributes.indices.normalized = true;
  63778. let tightBoundingBox = new Box3(
  63779. new Vector3().fromArray(e.data.tightBoundingBox.min),
  63780. new Vector3().fromArray(e.data.tightBoundingBox.max)
  63781. );
  63782. node.doneLoading(
  63783. g,
  63784. tightBoundingBox,
  63785. numPoints,
  63786. new Vector3(...e.data.mean));
  63787. Potree.workerPool.returnWorker(workerPath, worker);
  63788. };
  63789. let toArray = (v) => [v.x, v.y, v.z];
  63790. let message = {
  63791. buffer: buffer,
  63792. schema: node.ept.schema,
  63793. scale: node.ept.eptScale,
  63794. offset: node.ept.eptOffset,
  63795. mins: toArray(node.key.b.min)
  63796. };
  63797. worker.postMessage(message, [message.buffer]);
  63798. }
  63799. };
  63800. /**
  63801. * laslaz code taken and adapted from plas.io js-laslaz
  63802. * http://plas.io/
  63803. * https://github.com/verma/plasio
  63804. *
  63805. * Thanks to Uday Verma and Howard Butler
  63806. *
  63807. */
  63808. class EptLaszipLoader {
  63809. load(node) {
  63810. if (node.loaded) return;
  63811. let url = node.url() + '.laz';
  63812. let xhr = XHRFactory.createXMLHttpRequest();
  63813. xhr.open('GET', url, true);
  63814. xhr.responseType = 'arraybuffer';
  63815. xhr.overrideMimeType('text/plain; charset=x-user-defined');
  63816. xhr.onreadystatechange = () => {
  63817. if (xhr.readyState === 4) {
  63818. if (xhr.status === 200) {
  63819. let buffer = xhr.response;
  63820. this.parse(node, buffer);
  63821. } else {
  63822. console.log('Failed ' + url + ': ' + xhr.status);
  63823. }
  63824. }
  63825. };
  63826. xhr.send(null);
  63827. }
  63828. async parse(node, buffer){
  63829. let lf = new LASFile(buffer);
  63830. let handler = new EptLazBatcher(node);
  63831. try{
  63832. await lf.open();
  63833. lf.isOpen = true;
  63834. const header = await lf.getHeader();
  63835. {
  63836. let i = 0;
  63837. let toArray = (v) => [v.x, v.y, v.z];
  63838. let mins = toArray(node.key.b.min);
  63839. let maxs = toArray(node.key.b.max);
  63840. let hasMoreData = true;
  63841. while(hasMoreData){
  63842. const data = await lf.readData(1000000, 0, 1);
  63843. let d = new LASDecoder(
  63844. data.buffer,
  63845. header.pointsFormatId,
  63846. header.pointsStructSize,
  63847. data.count,
  63848. header.scale,
  63849. header.offset,
  63850. mins,
  63851. maxs);
  63852. d.extraBytes = header.extraBytes;
  63853. d.pointsFormatId = header.pointsFormatId;
  63854. handler.push(d);
  63855. i += data.count;
  63856. hasMoreData = data.hasMoreData;
  63857. }
  63858. header.totalRead = i;
  63859. header.versionAsString = lf.versionAsString;
  63860. header.isCompressed = lf.isCompressed;
  63861. await lf.close();
  63862. lf.isOpen = false;
  63863. }
  63864. }catch(err){
  63865. console.error('Error reading LAZ:', err);
  63866. if (lf.isOpen) {
  63867. await lf.close();
  63868. lf.isOpen = false;
  63869. }
  63870. throw err;
  63871. }
  63872. }
  63873. };
  63874. class EptLazBatcher {
  63875. constructor(node) { this.node = node; }
  63876. push(las) {
  63877. let workerPath = Potree.scriptPath +
  63878. '/workers/EptLaszipDecoderWorker.js';
  63879. let worker = Potree.workerPool.getWorker(workerPath);
  63880. worker.onmessage = (e) => {
  63881. let g = new BufferGeometry();
  63882. let numPoints = las.pointsCount;
  63883. let positions = new Float32Array(e.data.position);
  63884. let colors = new Uint8Array(e.data.color);
  63885. let intensities = new Float32Array(e.data.intensity);
  63886. let classifications = new Uint8Array(e.data.classification);
  63887. let returnNumbers = new Uint8Array(e.data.returnNumber);
  63888. let numberOfReturns = new Uint8Array(e.data.numberOfReturns);
  63889. let pointSourceIDs = new Uint16Array(e.data.pointSourceID);
  63890. let indices = new Uint8Array(e.data.indices);
  63891. let gpsTime = new Float32Array(e.data.gpsTime);
  63892. g.setAttribute('position',
  63893. new BufferAttribute(positions, 3));
  63894. g.setAttribute('rgba',
  63895. new BufferAttribute(colors, 4, true));
  63896. g.setAttribute('intensity',
  63897. new BufferAttribute(intensities, 1));
  63898. g.setAttribute('classification',
  63899. new BufferAttribute(classifications, 1));
  63900. g.setAttribute('return number',
  63901. new BufferAttribute(returnNumbers, 1));
  63902. g.setAttribute('number of returns',
  63903. new BufferAttribute(numberOfReturns, 1));
  63904. g.setAttribute('source id',
  63905. new BufferAttribute(pointSourceIDs, 1));
  63906. g.setAttribute('indices',
  63907. new BufferAttribute(indices, 4));
  63908. g.setAttribute('gpsTime',
  63909. new BufferAttribute(gpsTime, 1));
  63910. this.node.gpsTime = e.data.gpsMeta;
  63911. g.attributes.indices.normalized = true;
  63912. let tightBoundingBox = new Box3(
  63913. new Vector3().fromArray(e.data.tightBoundingBox.min),
  63914. new Vector3().fromArray(e.data.tightBoundingBox.max)
  63915. );
  63916. this.node.doneLoading(
  63917. g,
  63918. tightBoundingBox,
  63919. numPoints,
  63920. new Vector3(...e.data.mean));
  63921. Potree.workerPool.returnWorker(workerPath, worker);
  63922. };
  63923. let message = {
  63924. buffer: las.arrayb,
  63925. numPoints: las.pointsCount,
  63926. pointSize: las.pointSize,
  63927. pointFormatID: las.pointsFormatId,
  63928. scale: las.scale,
  63929. offset: las.offset,
  63930. mins: las.mins,
  63931. maxs: las.maxs
  63932. };
  63933. worker.postMessage(message, [message.buffer]);
  63934. };
  63935. };
  63936. class EptZstandardLoader extends EptBinaryLoader {
  63937. extension() {
  63938. return '.zst';
  63939. }
  63940. workerPath() {
  63941. return Potree.scriptPath + '/workers/EptZstandardDecoderWorker.js';
  63942. }
  63943. };
  63944. class ShapefileLoader{
  63945. constructor(){
  63946. this.transform = null;
  63947. }
  63948. async load(path, color){
  63949. const matLine = new LineMaterial( {
  63950. color: color || 0xff0000,
  63951. lineWidth: 3, // in pixels
  63952. resolution: new Vector2(1000, 1000),
  63953. dashed: false
  63954. } );
  63955. const features = await this.loadShapefileFeatures(path);
  63956. const node = new Object3D();
  63957. let jump = 0;
  63958. for(const feature of features){//5是碎的
  63959. //if(feature.geometry.type!= 'MultiLineString' || ++jump != 5) continue
  63960. const fnode = this.featureToSceneNode(feature, matLine);
  63961. fnode && node.add(fnode);
  63962. }
  63963. let setResolution = (x, y) => {
  63964. matLine.resolution.set(x, y);
  63965. };
  63966. const result = {
  63967. features: features,
  63968. node: node,
  63969. setResolution: setResolution,
  63970. };
  63971. return result;
  63972. }
  63973. featureToSceneNode(feature, matLine){
  63974. //console.log(feature)
  63975. let geometry = feature.geometry;
  63976. let color = new Color(1, 1, 1);
  63977. let transform = this.transform;
  63978. if(transform === null){
  63979. transform = {forward: (v) => v};
  63980. }
  63981. if(geometry.type === "Point"){
  63982. let sg = new SphereGeometry(1, 18, 18);
  63983. let sm = new MeshNormalMaterial();
  63984. let s = new Mesh(sg, sm);
  63985. let [long, lat] = geometry.coordinates;
  63986. let pos = transform.forward([long, lat]);
  63987. s.position.set(...pos, 20);
  63988. s.scale.set(10, 10, 10);
  63989. return s;
  63990. }else if(geometry.type === "LineString"){
  63991. let coordinates = [];
  63992. let min = new Vector3(Infinity, Infinity, Infinity);
  63993. for(let i = 0; i < geometry.coordinates.length; i++){
  63994. let [long, lat] = geometry.coordinates[i];
  63995. let pos = transform.forward([long, lat]);
  63996. min.x = Math.min(min.x, pos[0]);
  63997. min.y = Math.min(min.y, pos[1]);
  63998. min.z = Math.min(min.z, 20);
  63999. coordinates.push(...pos, 20);
  64000. if(i > 0 && i < geometry.coordinates.length - 1){
  64001. coordinates.push(...pos, 20);
  64002. }
  64003. }
  64004. for(let i = 0; i < coordinates.length; i += 3){
  64005. coordinates[i+0] -= min.x;
  64006. coordinates[i+1] -= min.y;
  64007. coordinates[i+2] -= min.z;
  64008. }
  64009. const lineGeometry = new LineGeometry();
  64010. lineGeometry.setPositions( coordinates );
  64011. const line = new Line2( lineGeometry, matLine );
  64012. line.computeLineDistances();
  64013. line.scale.set( 1, 1, 1 );
  64014. line.position.copy(min);
  64015. return line;
  64016. }else if(geometry.type === "MultiLineString"){//xzw add 江门的那个文件
  64017. let coordinates = [];
  64018. //console.warn('MultiLineString') //多组连续线段,组之间不连续
  64019. let min = new Vector3(Infinity, Infinity, Infinity);
  64020. for(let i = 0; i < geometry.coordinates.length; i++){
  64021. let points = geometry.coordinates[i]; //有时候是两个点有时候多个
  64022. let coordinateSlice = [];
  64023. points.forEach(point=>{
  64024. let [long, lat] = point;
  64025. let pos = transform.forward([long, lat]);
  64026. min.x = Math.min(min.x, pos[0]);
  64027. min.y = Math.min(min.y, pos[1]);
  64028. min.z = Math.min(min.z, 20);
  64029. coordinateSlice.push(new Vector3(pos[0], pos[1], 20));
  64030. });
  64031. coordinates.push(coordinateSlice);
  64032. }
  64033. coordinates.forEach(coordinateSlice=> coordinateSlice.forEach(point=>point.sub(min) ));
  64034. let line = LineDraw.createFatLine(coordinates,{
  64035. uncontinuous: true,
  64036. mat:matLine
  64037. /* color: 0xff0000,
  64038. dashSize: 0.5,
  64039. gapSize: 0.2,
  64040. lineWidth: config$1.measure.lineWidth, */
  64041. });
  64042. line.position.copy(min);
  64043. return line;
  64044. }else if(geometry.type === "Polygon"){
  64045. for(let pc of geometry.coordinates){
  64046. let coordinates = [];
  64047. let min = new Vector3(Infinity, Infinity, Infinity);
  64048. for(let i = 0; i < pc.length; i++){
  64049. let [long, lat] = pc[i];
  64050. let pos = transform.forward([long, lat]);
  64051. min.x = Math.min(min.x, pos[0]);
  64052. min.y = Math.min(min.y, pos[1]);
  64053. min.z = Math.min(min.z, 20);
  64054. coordinates.push(...pos, 20);
  64055. if(i > 0 && i < pc.length - 1){
  64056. coordinates.push(...pos, 20);
  64057. }
  64058. }
  64059. for(let i = 0; i < coordinates.length; i += 3){
  64060. coordinates[i+0] -= min.x;
  64061. coordinates[i+1] -= min.y;
  64062. coordinates[i+2] -= min.z;
  64063. }
  64064. const lineGeometry = new LineGeometry();
  64065. lineGeometry.setPositions( coordinates );
  64066. const line = new Line2( lineGeometry, matLine );
  64067. line.computeLineDistances();
  64068. line.scale.set( 1, 1, 1 );
  64069. line.position.copy(min);
  64070. return line;
  64071. }
  64072. }else {
  64073. console.log("unhandled feature: ", geometry.type);
  64074. }
  64075. function getLine(coordinates){
  64076. }
  64077. }
  64078. async loadShapefileFeatures(file){
  64079. let features = [];
  64080. if(file.split('.').pop() == 'shp'){
  64081. let source = await shapefile.open(file);
  64082. while(true){
  64083. let result = await source.read();
  64084. if (result.done) {
  64085. break;
  64086. }
  64087. if (result.value && result.value.type === 'Feature' && result.value.geometry !== undefined) {
  64088. features.push(result.value);
  64089. }
  64090. }
  64091. return features;
  64092. }else if(file.split('.').pop() == 'json'){
  64093. return new Promise((resolve,reject)=>{
  64094. Potree.loadFile(file, {/* returnText:true */} , (data)=>{
  64095. console.log(data);
  64096. resolve(data.features);
  64097. });
  64098. })
  64099. }
  64100. }
  64101. };
  64102. const defaultColors = {
  64103. "landuse": [0.5, 0.5, 0.5],
  64104. "natural": [0.0, 1.0, 0.0],
  64105. "places": [1.0, 0.0, 1.0],
  64106. "points": [0.0, 1.0, 1.0],
  64107. "roads": [1.0, 1.0, 0.0],
  64108. "waterways": [0.0, 0.0, 1.0],
  64109. "default": [0.9, 0.6, 0.1],
  64110. };
  64111. function getColor(feature){
  64112. let color = defaultColors[feature];
  64113. if(!color){
  64114. color = defaultColors["default"];
  64115. }
  64116. return color;
  64117. }
  64118. class Geopackage$1{
  64119. constructor(){
  64120. this.path = null;
  64121. this.node = null;
  64122. }
  64123. };
  64124. class GeoPackageLoader{
  64125. constructor(){
  64126. }
  64127. static async loadUrl(url, params){
  64128. await Promise.all([
  64129. Utils.loadScript(`${Potree.scriptPath}/lazylibs/geopackage/geopackage.js`),
  64130. Utils.loadScript(`${Potree.scriptPath}/lazylibs/sql.js/sql-wasm.js`),
  64131. ]);
  64132. const result = await fetch(url);
  64133. const buffer = await result.arrayBuffer();
  64134. params = params || {};
  64135. params.source = url;
  64136. return GeoPackageLoader.loadBuffer(buffer, params);
  64137. }
  64138. static async loadBuffer(buffer, params){
  64139. await Promise.all([
  64140. Utils.loadScript(`${Potree.scriptPath}/lazylibs/geopackage/geopackage.js`),
  64141. Utils.loadScript(`${Potree.scriptPath}/lazylibs/sql.js/sql-wasm.js`),
  64142. ]);
  64143. params = params || {};
  64144. const resolver = async (resolve) => {
  64145. let transform = params.transform;
  64146. if(!transform){
  64147. transform = {forward: (arg) => arg};
  64148. }
  64149. const wasmPath = `${Potree.scriptPath}/lazylibs/sql.js/sql-wasm.wasm`;
  64150. const SQL = await initSqlJs({ locateFile: filename => wasmPath});
  64151. const u8 = new Uint8Array(buffer);
  64152. const data = await geopackage.open(u8);
  64153. window.data = data;
  64154. const geopackageNode = new Object3D();
  64155. geopackageNode.name = params.source;
  64156. geopackageNode.potree = {
  64157. source: params.source,
  64158. };
  64159. const geo = new Geopackage$1();
  64160. geo.path = params.source;
  64161. geo.node = geopackageNode;
  64162. const tables = data.getTables();
  64163. for(const table of tables.features){
  64164. const dao = data.getFeatureDao(table);
  64165. let boundingBox = dao.getBoundingBox();
  64166. boundingBox = boundingBox.projectBoundingBox(dao.projection, 'EPSG:4326');
  64167. const geoJson = data.queryForGeoJSONFeaturesInTable(table, boundingBox);
  64168. const matLine = new LineMaterial( {
  64169. color: new Color().setRGB(...getColor(table)),
  64170. linewidth: 2,
  64171. resolution: new Vector2(1000, 1000),
  64172. dashed: false
  64173. } );
  64174. const node = new Object3D();
  64175. node.name = table;
  64176. geo.node.add(node);
  64177. for(const [index, feature] of Object.entries(geoJson)){
  64178. //const featureNode = GeoPackageLoader.featureToSceneNode(feature, matLine, transform);
  64179. const featureNode = GeoPackageLoader.featureToSceneNode(feature, matLine, dao.projection, transform);
  64180. node.add(featureNode);
  64181. }
  64182. }
  64183. resolve(geo);
  64184. };
  64185. return new Promise(resolver);
  64186. }
  64187. static featureToSceneNode(feature, matLine, geopackageProjection, transform){
  64188. let geometry = feature.geometry;
  64189. let color = new Color(1, 1, 1);
  64190. if(feature.geometry.type === "Point"){
  64191. let sg = new SphereGeometry(1, 18, 18);
  64192. let sm = new MeshNormalMaterial();
  64193. let s = new Mesh(sg, sm);
  64194. let [long, lat] = geometry.coordinates;
  64195. let pos = transform.forward(geopackageProjection.forward([long, lat]));
  64196. s.position.set(...pos, 20);
  64197. s.scale.set(10, 10, 10);
  64198. return s;
  64199. }else if(geometry.type === "LineString"){
  64200. let coordinates = [];
  64201. let min = new Vector3(Infinity, Infinity, Infinity);
  64202. for(let i = 0; i < geometry.coordinates.length; i++){
  64203. let [long, lat] = geometry.coordinates[i];
  64204. let pos = transform.forward(geopackageProjection.forward([long, lat]));
  64205. min.x = Math.min(min.x, pos[0]);
  64206. min.y = Math.min(min.y, pos[1]);
  64207. min.z = Math.min(min.z, 20);
  64208. coordinates.push(...pos, 20);
  64209. if(i > 0 && i < geometry.coordinates.length - 1){
  64210. coordinates.push(...pos, 20);
  64211. }
  64212. }
  64213. for(let i = 0; i < coordinates.length; i += 3){
  64214. coordinates[i+0] -= min.x;
  64215. coordinates[i+1] -= min.y;
  64216. coordinates[i+2] -= min.z;
  64217. }
  64218. const lineGeometry = new LineGeometry();
  64219. lineGeometry.setPositions( coordinates );
  64220. const line = new Line2( lineGeometry, matLine );
  64221. line.computeLineDistances();
  64222. line.scale.set( 1, 1, 1 );
  64223. line.position.copy(min);
  64224. return line;
  64225. }else if(geometry.type === "Polygon"){
  64226. for(let pc of geometry.coordinates){
  64227. let coordinates = [];
  64228. let min = new Vector3(Infinity, Infinity, Infinity);
  64229. for(let i = 0; i < pc.length; i++){
  64230. let [long, lat] = pc[i];
  64231. let pos = transform.forward(geopackageProjection.forward([long, lat]));
  64232. min.x = Math.min(min.x, pos[0]);
  64233. min.y = Math.min(min.y, pos[1]);
  64234. min.z = Math.min(min.z, 20);
  64235. coordinates.push(...pos, 20);
  64236. if(i > 0 && i < pc.length - 1){
  64237. coordinates.push(...pos, 20);
  64238. }
  64239. }
  64240. for(let i = 0; i < coordinates.length; i += 3){
  64241. coordinates[i+0] -= min.x;
  64242. coordinates[i+1] -= min.y;
  64243. coordinates[i+2] -= min.z;
  64244. }
  64245. const lineGeometry = new LineGeometry();
  64246. lineGeometry.setPositions( coordinates );
  64247. const line = new Line2( lineGeometry, matLine );
  64248. line.computeLineDistances();
  64249. line.scale.set( 1, 1, 1 );
  64250. line.position.copy(min);
  64251. return line;
  64252. }
  64253. }else {
  64254. console.log("unhandled feature: ", feature);
  64255. }
  64256. }
  64257. };
  64258. class ClipVolume extends Object3D{
  64259. constructor(args){
  64260. super();
  64261. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  64262. this.name = "clip_volume_" + this.constructor.counter;
  64263. let alpha = args.alpha || 0;
  64264. let beta = args.beta || 0;
  64265. let gamma = args.gamma || 0;
  64266. this.rotation.x = alpha;
  64267. this.rotation.y = beta;
  64268. this.rotation.z = gamma;
  64269. this.clipOffset = 0.001;
  64270. this.clipRotOffset = 1;
  64271. let boxGeometry = new BoxGeometry(1, 1, 1);
  64272. boxGeometry.computeBoundingBox();
  64273. let boxFrameGeometry = new Geometry();
  64274. {
  64275. // bottom
  64276. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  64277. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  64278. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  64279. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  64280. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  64281. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  64282. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  64283. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  64284. // top
  64285. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  64286. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  64287. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  64288. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  64289. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  64290. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  64291. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  64292. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  64293. // sides
  64294. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  64295. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  64296. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  64297. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  64298. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  64299. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  64300. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  64301. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  64302. boxFrameGeometry.colors.push(new Vector3(1, 1, 1));
  64303. }
  64304. let planeFrameGeometry = new Geometry();
  64305. {
  64306. // middle line
  64307. planeFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.0));
  64308. planeFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.0));
  64309. planeFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.0));
  64310. planeFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.0));
  64311. planeFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.0));
  64312. planeFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.0));
  64313. planeFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.0));
  64314. planeFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.0));
  64315. }
  64316. this.dimension = new Vector3(1, 1, 1);
  64317. this.material = new MeshBasicMaterial( {
  64318. color: 0x00ff00,
  64319. transparent: true,
  64320. opacity: 0.3,
  64321. depthTest: true,
  64322. depthWrite: false} );
  64323. this.box = new Mesh(boxGeometry, this.material);
  64324. this.box.geometry.computeBoundingBox();
  64325. this.boundingBox = this.box.geometry.boundingBox;
  64326. this.add(this.box);
  64327. this.frame = new LineSegments( boxFrameGeometry, new LineBasicMaterial({color: 0x000000}));
  64328. this.add(this.frame);
  64329. this.planeFrame = new LineSegments( planeFrameGeometry, new LineBasicMaterial({color: 0xff0000}));
  64330. this.add(this.planeFrame);
  64331. // set default thickness
  64332. this.setScaleZ(0.1);
  64333. // create local coordinate system
  64334. let createArrow = (name, direction, color) => {
  64335. let material = new MeshBasicMaterial({
  64336. color: color,
  64337. depthTest: false,
  64338. depthWrite: false});
  64339. let shaftGeometry = new Geometry();
  64340. shaftGeometry.vertices.push(new Vector3(0, 0, 0));
  64341. shaftGeometry.vertices.push(new Vector3(0, 1, 0));
  64342. let shaftMaterial = new LineBasicMaterial({
  64343. color: color,
  64344. depthTest: false,
  64345. depthWrite: false,
  64346. transparent: true
  64347. });
  64348. let shaft = new Line(shaftGeometry, shaftMaterial);
  64349. shaft.name = name + "_shaft";
  64350. let headGeometry = new CylinderGeometry(0, 0.04, 0.1, 10, 1, false);
  64351. let headMaterial = material;
  64352. let head = new Mesh(headGeometry, headMaterial);
  64353. head.name = name + "_head";
  64354. head.position.y = 1;
  64355. let arrow = new Object3D();
  64356. arrow.name = name;
  64357. arrow.add(shaft);
  64358. arrow.add(head);
  64359. return arrow;
  64360. };
  64361. this.arrowX = createArrow("arrow_x", new Vector3(1, 0, 0), 0xFF0000);
  64362. this.arrowY = createArrow("arrow_y", new Vector3(0, 1, 0), 0x00FF00);
  64363. this.arrowZ = createArrow("arrow_z", new Vector3(0, 0, 1), 0x0000FF);
  64364. this.arrowX.rotation.z = -Math.PI / 2;
  64365. this.arrowZ.rotation.x = Math.PI / 2;
  64366. this.arrowX.visible = false;
  64367. this.arrowY.visible = false;
  64368. this.arrowZ.visible = false;
  64369. this.add(this.arrowX);
  64370. this.add(this.arrowY);
  64371. this.add(this.arrowZ);
  64372. { // event listeners
  64373. this.addEventListener("ui_select", e => {
  64374. this.arrowX.visible = true;
  64375. this.arrowY.visible = true;
  64376. this.arrowZ.visible = true;
  64377. });
  64378. this.addEventListener("ui_deselect", e => {
  64379. this.arrowX.visible = false;
  64380. this.arrowY.visible = false;
  64381. this.arrowZ.visible = false;
  64382. });
  64383. this.addEventListener("select", e => {
  64384. let scene_header = $("#" + this.name + " .scene_header");
  64385. if(!scene_header.next().is(":visible")) {
  64386. scene_header.click();
  64387. }
  64388. });
  64389. this.addEventListener("deselect", e => {
  64390. let scene_header = $("#" + this.name + " .scene_header");
  64391. if(scene_header.next().is(":visible")) {
  64392. scene_header.click();
  64393. }
  64394. });
  64395. }
  64396. this.update();
  64397. };
  64398. setClipOffset(offset) {
  64399. this.clipOffset = offset;
  64400. }
  64401. setClipRotOffset(offset) {
  64402. this.clipRotOffset = offset;
  64403. }
  64404. setScaleX(x) {
  64405. this.box.scale.x = x;
  64406. this.frame.scale.x = x;
  64407. this.planeFrame.scale.x = x;
  64408. }
  64409. setScaleY(y) {
  64410. this.box.scale.y = y;
  64411. this.frame.scale.y = y;
  64412. this.planeFrame.scale.y = y;
  64413. }
  64414. setScaleZ(z) {
  64415. this.box.scale.z = z;
  64416. this.frame.scale.z = z;
  64417. this.planeFrame.scale.z = z;
  64418. }
  64419. offset(args) {
  64420. let cs = args.cs || null;
  64421. let axis = args.axis || null;
  64422. let dir = args.dir || null;
  64423. if(!cs || !axis || !dir) return;
  64424. if(axis === "x") {
  64425. if(cs === "local") {
  64426. this.position.add(this.localX.clone().multiplyScalar(dir * this.clipOffset));
  64427. } else if(cs === "global") {
  64428. this.position.x = this.position.x + dir * this.clipOffset;
  64429. }
  64430. }else if(axis === "y") {
  64431. if(cs === "local") {
  64432. this.position.add(this.localY.clone().multiplyScalar(dir * this.clipOffset));
  64433. } else if(cs === "global") {
  64434. this.position.y = this.position.y + dir * this.clipOffset;
  64435. }
  64436. }else if(axis === "z") {
  64437. if(cs === "local") {
  64438. this.position.add(this.localZ.clone().multiplyScalar(dir * this.clipOffset));
  64439. } else if(cs === "global") {
  64440. this.position.z = this.position.z + dir * this.clipOffset;
  64441. }
  64442. }
  64443. this.dispatchEvent({"type": "clip_volume_changed", "viewer": viewer, "volume": this});
  64444. }
  64445. rotate(args) {
  64446. let cs = args.cs || null;
  64447. let axis = args.axis || null;
  64448. let dir = args.dir || null;
  64449. if(!cs || !axis || !dir) return;
  64450. if(cs === "local") {
  64451. if(axis === "x") {
  64452. this.rotateOnAxis(new Vector3(1, 0, 0), dir * this.clipRotOffset * Math.PI / 180);
  64453. } else if(axis === "y") {
  64454. this.rotateOnAxis(new Vector3(0, 1, 0), dir * this.clipRotOffset * Math.PI / 180);
  64455. } else if(axis === "z") {
  64456. this.rotateOnAxis(new Vector3(0, 0, 1), dir * this.clipRotOffset * Math.PI / 180);
  64457. }
  64458. } else if(cs === "global") {
  64459. let rotaxis = new Vector4(1, 0, 0, 0);
  64460. if(axis === "y") {
  64461. rotaxis = new Vector4(0, 1, 0, 0);
  64462. } else if(axis === "z") {
  64463. rotaxis = new Vector4(0, 0, 1, 0);
  64464. }
  64465. this.updateMatrixWorld();
  64466. let invM = newthis.matrixWorld.clone().invert();
  64467. rotaxis = rotaxis.applyMatrix4(invM).normalize();
  64468. rotaxis = new Vector3(rotaxis.x, rotaxis.y, rotaxis.z);
  64469. this.rotateOnAxis(rotaxis, dir * this.clipRotOffset * Math.PI / 180);
  64470. }
  64471. this.updateLocalSystem();
  64472. this.dispatchEvent({"type": "clip_volume_changed", "viewer": viewer, "volume": this});
  64473. }
  64474. update(){
  64475. this.boundingBox = this.box.geometry.boundingBox;
  64476. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  64477. this.box.visible = false;
  64478. this.updateLocalSystem();
  64479. };
  64480. updateLocalSystem() {
  64481. // extract local coordinate axes
  64482. let rotQuat = this.getWorldQuaternion();
  64483. this.localX = new Vector3(1, 0, 0).applyQuaternion(rotQuat).normalize();
  64484. this.localY = new Vector3(0, 1, 0).applyQuaternion(rotQuat).normalize();
  64485. this.localZ = new Vector3(0, 0, 1).applyQuaternion(rotQuat).normalize();
  64486. }
  64487. raycast(raycaster, intersects){
  64488. let is = [];
  64489. this.box.raycast(raycaster, is);
  64490. if(is.length > 0){
  64491. let I = is[0];
  64492. intersects.push({
  64493. distance: I.distance,
  64494. object: this,
  64495. point: I.point.clone()
  64496. });
  64497. }
  64498. };
  64499. };
  64500. //这个文件只是clipping polygon的,没用到
  64501. class ClippingTool extends EventDispatcher$1{
  64502. constructor(viewer){
  64503. super();
  64504. this.viewer = viewer;
  64505. this.maxPolygonVertices = 8;
  64506. this.addEventListener("start_inserting_clipping_volume", e => {
  64507. this.viewer.dispatchEvent({
  64508. type: "cancel_insertions"
  64509. });
  64510. });
  64511. this.sceneMarker = new Scene();
  64512. this.sceneVolume = new Scene();
  64513. this.sceneVolume.name = "scene_clip_volume";
  64514. this.viewer.inputHandler.registerInteractiveScene(this.sceneVolume);
  64515. this.onRemove = e => {
  64516. this.sceneVolume.remove(e.volume);
  64517. };
  64518. this.onAdd = e => {
  64519. this.sceneVolume.add(e.volume);
  64520. };
  64521. this.viewer.inputHandler.addEventListener("delete", e => {
  64522. let volumes = e.selection.filter(e => (e instanceof ClipVolume));
  64523. volumes.forEach(e => this.viewer.scene.removeClipVolume(e));
  64524. let polyVolumes = e.selection.filter(e => (e instanceof PolygonClipVolume));
  64525. polyVolumes.forEach(e => this.viewer.scene.removePolygonClipVolume(e));
  64526. });
  64527. }
  64528. setScene(scene){
  64529. if(this.scene === scene){
  64530. return;
  64531. }
  64532. if(this.scene){
  64533. this.scene.removeEventListeners("clip_volume_added", this.onAdd);
  64534. this.scene.removeEventListeners("clip_volume_removed", this.onRemove);
  64535. this.scene.removeEventListeners("polygon_clip_volume_added", this.onAdd);
  64536. this.scene.removeEventListeners("polygon_clip_volume_removed", this.onRemove);
  64537. }
  64538. this.scene = scene;
  64539. this.scene.addEventListener("clip_volume_added", this.onAdd);
  64540. this.scene.addEventListener("clip_volume_removed", this.onRemove);
  64541. this.scene.addEventListener("polygon_clip_volume_added", this.onAdd);
  64542. this.scene.addEventListener("polygon_clip_volume_removed", this.onRemove);
  64543. }
  64544. startInsertion(args = {}) {
  64545. let type = args.type || null;
  64546. if(!type) return null;
  64547. let domElement = this.viewer.renderer.domElement;
  64548. let canvasSize = this.viewer.renderer.getSize(new Vector2());
  64549. let svg = $(`
  64550. <svg height="${canvasSize.height}" width="${canvasSize.width}" style="position:absolute; pointer-events: none">
  64551. <defs>
  64552. <marker id="diamond" markerWidth="24" markerHeight="24" refX="12" refY="12"
  64553. markerUnits="userSpaceOnUse">
  64554. <circle cx="12" cy="12" r="6" fill="white" stroke="black" stroke-width="3"/>
  64555. </marker>
  64556. </defs>
  64557. <polyline fill="none" stroke="black"
  64558. style="stroke:rgb(0, 0, 0);
  64559. stroke-width:6;"
  64560. stroke-dasharray="9, 6"
  64561. stroke-dashoffset="2"
  64562. />
  64563. <polyline fill="none" stroke="black"
  64564. style="stroke:rgb(255, 255, 255);
  64565. stroke-width:2;"
  64566. stroke-dasharray="5, 10"
  64567. marker-start="url(#diamond)"
  64568. marker-mid="url(#diamond)"
  64569. marker-end="url(#diamond)"
  64570. />
  64571. </svg>`);
  64572. $(domElement.parentElement).append(svg);
  64573. let polyClipVol = new PolygonClipVolume(this.viewer.scene.getActiveCamera().clone());
  64574. this.dispatchEvent({"type": "start_inserting_clipping_volume"});
  64575. this.viewer.scene.addPolygonClipVolume(polyClipVol);
  64576. this.sceneMarker.add(polyClipVol);
  64577. let cancel = {
  64578. callback: null
  64579. };
  64580. let insertionCallback = (e) => {
  64581. if(e.button === MOUSE.LEFT){
  64582. polyClipVol.addMarker();
  64583. // SVC Screen Line
  64584. svg.find("polyline").each((index, target) => {
  64585. let newPoint = svg[0].createSVGPoint();
  64586. newPoint.x = e.offsetX;
  64587. newPoint.y = e.offsetY;
  64588. let polyline = target.points.appendItem(newPoint);
  64589. });
  64590. if(polyClipVol.markers.length > this.maxPolygonVertices){
  64591. cancel.callback();
  64592. }
  64593. this.viewer.inputHandler.startDragging(
  64594. polyClipVol.markers[polyClipVol.markers.length - 1]);
  64595. }else if(e.button === MOUSE.RIGHT){
  64596. cancel.callback(e);
  64597. }
  64598. };
  64599. cancel.callback = e => {
  64600. //let first = svg.find("polyline")[0].points[0];
  64601. //svg.find("polyline").each((index, target) => {
  64602. // let newPoint = svg[0].createSVGPoint();
  64603. // newPoint.x = first.x;
  64604. // newPoint.y = first.y;
  64605. // let polyline = target.points.appendItem(newPoint);
  64606. //});
  64607. svg.remove();
  64608. if(polyClipVol.markers.length > 3) {
  64609. polyClipVol.removeLastMarker();
  64610. polyClipVol.initialized = true;
  64611. } else {
  64612. this.viewer.scene.removePolygonClipVolume(polyClipVol);
  64613. }
  64614. this.viewer.renderer.domElement.removeEventListener("mouseup", insertionCallback, true);
  64615. this.viewer.removeEventListener("cancel_insertions", cancel.callback);
  64616. this.viewer.inputHandler.enabled = true;
  64617. };
  64618. this.viewer.addEventListener("cancel_insertions", cancel.callback);
  64619. this.viewer.renderer.domElement.addEventListener("mouseup", insertionCallback , true);
  64620. this.viewer.inputHandler.enabled = false;
  64621. polyClipVol.addMarker();
  64622. this.viewer.inputHandler.startDragging(
  64623. polyClipVol.markers[polyClipVol.markers.length - 1]);
  64624. return polyClipVol;
  64625. }
  64626. update() {
  64627. }
  64628. };
  64629. var GeoTIFF = (function (exports) {
  64630. 'use strict';
  64631. const Endianness = new Enum({
  64632. LITTLE: "II",
  64633. BIG: "MM",
  64634. });
  64635. const Type = new Enum({
  64636. BYTE: {value: 1, bytes: 1},
  64637. ASCII: {value: 2, bytes: 1},
  64638. SHORT: {value: 3, bytes: 2},
  64639. LONG: {value: 4, bytes: 4},
  64640. RATIONAL: {value: 5, bytes: 8},
  64641. SBYTE: {value: 6, bytes: 1},
  64642. UNDEFINED: {value: 7, bytes: 1},
  64643. SSHORT: {value: 8, bytes: 2},
  64644. SLONG: {value: 9, bytes: 4},
  64645. SRATIONAL: {value: 10, bytes: 8},
  64646. FLOAT: {value: 11, bytes: 4},
  64647. DOUBLE: {value: 12, bytes: 8},
  64648. });
  64649. const Tag = new Enum({
  64650. IMAGE_WIDTH: 256,
  64651. IMAGE_HEIGHT: 257,
  64652. BITS_PER_SAMPLE: 258,
  64653. COMPRESSION: 259,
  64654. PHOTOMETRIC_INTERPRETATION: 262,
  64655. STRIP_OFFSETS: 273,
  64656. ORIENTATION: 274,
  64657. SAMPLES_PER_PIXEL: 277,
  64658. ROWS_PER_STRIP: 278,
  64659. STRIP_BYTE_COUNTS: 279,
  64660. X_RESOLUTION: 282,
  64661. Y_RESOLUTION: 283,
  64662. PLANAR_CONFIGURATION: 284,
  64663. RESOLUTION_UNIT: 296,
  64664. SOFTWARE: 305,
  64665. COLOR_MAP: 320,
  64666. SAMPLE_FORMAT: 339,
  64667. MODEL_PIXEL_SCALE: 33550, // [GeoTIFF] TYPE: double N: 3
  64668. MODEL_TIEPOINT: 33922, // [GeoTIFF] TYPE: double N: 6 * NUM_TIEPOINTS
  64669. GEO_KEY_DIRECTORY: 34735, // [GeoTIFF] TYPE: short N: >= 4
  64670. GEO_DOUBLE_PARAMS: 34736, // [GeoTIFF] TYPE: short N: variable
  64671. GEO_ASCII_PARAMS: 34737, // [GeoTIFF] TYPE: ascii N: variable
  64672. });
  64673. const typeMapping = new Map([
  64674. [Type.BYTE, Uint8Array],
  64675. [Type.ASCII, Uint8Array],
  64676. [Type.SHORT, Uint16Array],
  64677. [Type.LONG, Uint32Array],
  64678. [Type.RATIONAL, Uint32Array],
  64679. [Type.SBYTE, Int8Array],
  64680. [Type.UNDEFINED, Uint8Array],
  64681. [Type.SSHORT, Int16Array],
  64682. [Type.SLONG, Int32Array],
  64683. [Type.SRATIONAL, Int32Array],
  64684. [Type.FLOAT, Float32Array],
  64685. [Type.DOUBLE, Float64Array],
  64686. ]);
  64687. class IFDEntry{
  64688. constructor(tag, type, count, offset, value){
  64689. this.tag = tag;
  64690. this.type = type;
  64691. this.count = count;
  64692. this.offset = offset;
  64693. this.value = value;
  64694. }
  64695. }
  64696. class Image{
  64697. constructor(){
  64698. this.width = 0;
  64699. this.height = 0;
  64700. this.buffer = null;
  64701. this.metadata = [];
  64702. }
  64703. }
  64704. class Reader{
  64705. constructor(){
  64706. }
  64707. static read(data){
  64708. let endiannessTag = String.fromCharCode(...Array.from(data.slice(0, 2)));
  64709. let endianness = Endianness.fromValue(endiannessTag);
  64710. let tiffCheckTag = data.readUInt8(2);
  64711. if(tiffCheckTag !== 42){
  64712. throw new Error("not a valid tiff file");
  64713. }
  64714. let offsetToFirstIFD = data.readUInt32LE(4);
  64715. console.log("offsetToFirstIFD", offsetToFirstIFD);
  64716. let ifds = [];
  64717. let IFDsRead = false;
  64718. let currentIFDOffset = offsetToFirstIFD;
  64719. let i = 0;
  64720. while(IFDsRead || i < 100){
  64721. console.log("currentIFDOffset", currentIFDOffset);
  64722. let numEntries = data.readUInt16LE(currentIFDOffset);
  64723. let nextIFDOffset = data.readUInt32LE(currentIFDOffset + 2 + numEntries * 12);
  64724. console.log("next offset: ", currentIFDOffset + 2 + numEntries * 12);
  64725. let entryBuffer = data.slice(currentIFDOffset + 2, currentIFDOffset + 2 + 12 * numEntries);
  64726. for(let i = 0; i < numEntries; i++){
  64727. let tag = Tag.fromValue(entryBuffer.readUInt16LE(i * 12));
  64728. let type = Type.fromValue(entryBuffer.readUInt16LE(i * 12 + 2));
  64729. let count = entryBuffer.readUInt32LE(i * 12 + 4);
  64730. let offsetOrValue = entryBuffer.readUInt32LE(i * 12 + 8);
  64731. let valueBytes = type.bytes * count;
  64732. let value;
  64733. if(valueBytes <= 4){
  64734. value = offsetOrValue;
  64735. }else {
  64736. let valueBuffer = new Uint8Array(valueBytes);
  64737. valueBuffer.set(data.slice(offsetOrValue, offsetOrValue + valueBytes));
  64738. let ArrayType = typeMapping.get(type);
  64739. value = new ArrayType(valueBuffer.buffer);
  64740. if(type === Type.ASCII){
  64741. value = String.fromCharCode(...value);
  64742. }
  64743. }
  64744. let ifd = new IFDEntry(tag, type, count, offsetOrValue, value);
  64745. ifds.push(ifd);
  64746. }
  64747. console.log("nextIFDOffset", nextIFDOffset);
  64748. if(nextIFDOffset === 0){
  64749. break;
  64750. }
  64751. currentIFDOffset = nextIFDOffset;
  64752. i++;
  64753. }
  64754. let ifdForTag = (tag) => {
  64755. for(let entry of ifds){
  64756. if(entry.tag === tag){
  64757. return entry;
  64758. }
  64759. }
  64760. return null;
  64761. };
  64762. let width = ifdForTag(Tag.IMAGE_WIDTH, ifds).value;
  64763. let height = ifdForTag(Tag.IMAGE_HEIGHT, ifds).value;
  64764. let compression = ifdForTag(Tag.COMPRESSION, ifds).value;
  64765. let rowsPerStrip = ifdForTag(Tag.ROWS_PER_STRIP, ifds).value;
  64766. let ifdStripOffsets = ifdForTag(Tag.STRIP_OFFSETS, ifds);
  64767. let ifdStripByteCounts = ifdForTag(Tag.STRIP_BYTE_COUNTS, ifds);
  64768. let numStrips = Math.ceil(height / rowsPerStrip);
  64769. let stripByteCounts = [];
  64770. for(let i = 0; i < ifdStripByteCounts.count; i++){
  64771. let type = ifdStripByteCounts.type;
  64772. let offset = ifdStripByteCounts.offset + i * type.bytes;
  64773. let value;
  64774. if(type === Type.SHORT){
  64775. value = data.readUInt16LE(offset);
  64776. }else if(type === Type.LONG){
  64777. value = data.readUInt32LE(offset);
  64778. }
  64779. stripByteCounts.push(value);
  64780. }
  64781. let stripOffsets = [];
  64782. for(let i = 0; i < ifdStripOffsets.count; i++){
  64783. let type = ifdStripOffsets.type;
  64784. let offset = ifdStripOffsets.offset + i * type.bytes;
  64785. let value;
  64786. if(type === Type.SHORT){
  64787. value = data.readUInt16LE(offset);
  64788. }else if(type === Type.LONG){
  64789. value = data.readUInt32LE(offset);
  64790. }
  64791. stripOffsets.push(value);
  64792. }
  64793. let imageBuffer = new Uint8Array(width * height * 3);
  64794. let linesProcessed = 0;
  64795. for(let i = 0; i < numStrips; i++){
  64796. let stripOffset = stripOffsets[i];
  64797. let stripBytes = stripByteCounts[i];
  64798. let stripData = data.slice(stripOffset, stripOffset + stripBytes);
  64799. let lineBytes = width * 3;
  64800. for(let y = 0; y < rowsPerStrip; y++){
  64801. let line = stripData.slice(y * lineBytes, y * lineBytes + lineBytes);
  64802. imageBuffer.set(line, linesProcessed * lineBytes);
  64803. if(line.length === lineBytes){
  64804. linesProcessed++;
  64805. }else {
  64806. break;
  64807. }
  64808. }
  64809. }
  64810. console.log(`width: ${width}`);
  64811. console.log(`height: ${height}`);
  64812. console.log(`numStrips: ${numStrips}`);
  64813. console.log("stripByteCounts", stripByteCounts.join(", "));
  64814. console.log("stripOffsets", stripOffsets.join(", "));
  64815. let image = new Image();
  64816. image.width = width;
  64817. image.height = height;
  64818. image.buffer = imageBuffer;
  64819. image.metadata = ifds;
  64820. return image;
  64821. }
  64822. }
  64823. class Exporter{
  64824. constructor(){
  64825. }
  64826. static toTiffBuffer(image, params = {}){
  64827. let offsetToFirstIFD = 8;
  64828. let headerBuffer = new Uint8Array([0x49, 0x49, 42, 0, offsetToFirstIFD, 0, 0, 0]);
  64829. let [width, height] = [image.width, image.height];
  64830. let ifds = [
  64831. new IFDEntry(Tag.IMAGE_WIDTH, Type.SHORT, 1, null, width),
  64832. new IFDEntry(Tag.IMAGE_HEIGHT, Type.SHORT, 1, null, height),
  64833. new IFDEntry(Tag.BITS_PER_SAMPLE, Type.SHORT, 4, null, new Uint16Array([8, 8, 8, 8])),
  64834. new IFDEntry(Tag.COMPRESSION, Type.SHORT, 1, null, 1),
  64835. new IFDEntry(Tag.PHOTOMETRIC_INTERPRETATION, Type.SHORT, 1, null, 2),
  64836. new IFDEntry(Tag.ORIENTATION, Type.SHORT, 1, null, 1),
  64837. new IFDEntry(Tag.SAMPLES_PER_PIXEL, Type.SHORT, 1, null, 4),
  64838. new IFDEntry(Tag.ROWS_PER_STRIP, Type.LONG, 1, null, height),
  64839. new IFDEntry(Tag.STRIP_BYTE_COUNTS, Type.LONG, 1, null, width * height * 3),
  64840. new IFDEntry(Tag.PLANAR_CONFIGURATION, Type.SHORT, 1, null, 1),
  64841. new IFDEntry(Tag.RESOLUTION_UNIT, Type.SHORT, 1, null, 1),
  64842. new IFDEntry(Tag.SOFTWARE, Type.ASCII, 6, null, "......"),
  64843. new IFDEntry(Tag.STRIP_OFFSETS, Type.LONG, 1, null, null),
  64844. new IFDEntry(Tag.X_RESOLUTION, Type.RATIONAL, 1, null, new Uint32Array([1, 1])),
  64845. new IFDEntry(Tag.Y_RESOLUTION, Type.RATIONAL, 1, null, new Uint32Array([1, 1])),
  64846. ];
  64847. if(params.ifdEntries){
  64848. ifds.push(...params.ifdEntries);
  64849. }
  64850. let valueOffset = offsetToFirstIFD + 2 + ifds.length * 12 + 4;
  64851. // create 12 byte buffer for each ifd and variable length buffers for ifd values
  64852. let ifdEntryBuffers = new Map();
  64853. let ifdValueBuffers = new Map();
  64854. for(let ifd of ifds){
  64855. let entryBuffer = new ArrayBuffer(12);
  64856. let entryView = new DataView(entryBuffer);
  64857. let valueBytes = ifd.type.bytes * ifd.count;
  64858. entryView.setUint16(0, ifd.tag.value, true);
  64859. entryView.setUint16(2, ifd.type.value, true);
  64860. entryView.setUint32(4, ifd.count, true);
  64861. if(ifd.count === 1 && ifd.type.bytes <= 4){
  64862. entryView.setUint32(8, ifd.value, true);
  64863. }else {
  64864. entryView.setUint32(8, valueOffset, true);
  64865. let valueBuffer = new Uint8Array(ifd.count * ifd.type.bytes);
  64866. if(ifd.type === Type.ASCII){
  64867. valueBuffer.set(new Uint8Array(ifd.value.split("").map(c => c.charCodeAt(0))));
  64868. }else {
  64869. valueBuffer.set(new Uint8Array(ifd.value.buffer));
  64870. }
  64871. ifdValueBuffers.set(ifd.tag, valueBuffer);
  64872. valueOffset = valueOffset + valueBuffer.byteLength;
  64873. }
  64874. ifdEntryBuffers.set(ifd.tag, entryBuffer);
  64875. }
  64876. let imageBufferOffset = valueOffset;
  64877. new DataView(ifdEntryBuffers.get(Tag.STRIP_OFFSETS)).setUint32(8, imageBufferOffset, true);
  64878. let concatBuffers = (buffers) => {
  64879. let totalLength = buffers.reduce( (sum, buffer) => (sum + buffer.byteLength), 0);
  64880. let merged = new Uint8Array(totalLength);
  64881. let offset = 0;
  64882. for(let buffer of buffers){
  64883. merged.set(new Uint8Array(buffer), offset);
  64884. offset += buffer.byteLength;
  64885. }
  64886. return merged;
  64887. };
  64888. let ifdBuffer = concatBuffers([
  64889. new Uint16Array([ifds.length]),
  64890. ...ifdEntryBuffers.values(),
  64891. new Uint32Array([0])]);
  64892. let ifdValueBuffer = concatBuffers([...ifdValueBuffers.values()]);
  64893. let tiffBuffer = concatBuffers([
  64894. headerBuffer,
  64895. ifdBuffer,
  64896. ifdValueBuffer,
  64897. image.buffer
  64898. ]);
  64899. return {width: width, height: height, buffer: tiffBuffer};
  64900. }
  64901. }
  64902. exports.Tag = Tag;
  64903. exports.Type = Type;
  64904. exports.IFDEntry = IFDEntry;
  64905. exports.Image = Image;
  64906. exports.Reader = Reader;
  64907. exports.Exporter = Exporter;
  64908. return exports;
  64909. }({}));
  64910. class Message{
  64911. constructor(content){
  64912. this.content = content;
  64913. let closeIcon = `${exports.resourcePath}/icons/close.svg`;
  64914. this.element = $(`
  64915. <div class="potree_message">
  64916. <span name="content_container" style="flex-grow: 1; padding: 5px"></span>
  64917. <img name="close" src="${closeIcon}" class="button-icon" style="width: 16px; height: 16px;">
  64918. </div>`);
  64919. this.elClose = this.element.find("img[name=close]");
  64920. this.elContainer = this.element.find("span[name=content_container]");
  64921. if(typeof content === "string"){
  64922. this.elContainer.append($(`<span>${content}</span>`));
  64923. }else {
  64924. this.elContainer.append(content);
  64925. }
  64926. }
  64927. setMessage(content){
  64928. this.elContainer.empty();
  64929. if(typeof content === "string"){
  64930. this.elContainer.append($(`<span>${content}</span>`));
  64931. }else {
  64932. this.elContainer.append(content);
  64933. }
  64934. }
  64935. }
  64936. class PointCloudSM{
  64937. constructor(potreeRenderer){
  64938. this.potreeRenderer = potreeRenderer;
  64939. this.threeRenderer = this.potreeRenderer.threeRenderer;
  64940. this.target = new WebGLRenderTarget(2 * 1024, 2 * 1024, {
  64941. minFilter: LinearFilter,
  64942. magFilter: LinearFilter,
  64943. format: RGBAFormat,
  64944. type: FloatType
  64945. });
  64946. this.target.depthTexture = new DepthTexture();
  64947. this.target.depthTexture.type = UnsignedIntType;
  64948. //this.threeRenderer.setClearColor(0x000000, 1);
  64949. this.threeRenderer.setClearColor(0xff0000, 1);
  64950. //HACK? removed while moving to three.js 109
  64951. //this.threeRenderer.clearTarget(this.target, true, true, true);
  64952. {
  64953. const oldTarget = this.threeRenderer.getRenderTarget();
  64954. this.threeRenderer.setRenderTarget(this.target);
  64955. this.threeRenderer.clear(true, true, true);
  64956. this.threeRenderer.setRenderTarget(oldTarget);
  64957. }
  64958. }
  64959. setLight(light){
  64960. this.light = light;
  64961. let fov = (180 * light.angle) / Math.PI;
  64962. let aspect = light.shadow.mapSize.width / light.shadow.mapSize.height;
  64963. let near = 0.1;
  64964. let far = light.distance === 0 ? 10000 : light.distance;
  64965. this.camera = new PerspectiveCamera(fov, aspect, near, far);
  64966. this.camera.up.set(0, 0, 1);
  64967. this.camera.position.copy(light.position);
  64968. let target = new Vector3().subVectors(light.position, light.getWorldDirection(new Vector3()));
  64969. this.camera.lookAt(target);
  64970. this.camera.updateProjectionMatrix();
  64971. this.camera.updateMatrix();
  64972. this.camera.updateMatrixWorld();
  64973. this.camera.matrixWorldInverse.copy(this.camera.matrixWorld).invert();
  64974. }
  64975. setSize(width, height){
  64976. if(this.target.width !== width || this.target.height !== height){
  64977. this.target.dispose();
  64978. }
  64979. this.target.setSize(width, height);
  64980. }
  64981. render(scene, camera){
  64982. this.threeRenderer.setClearColor(0x000000, 1);
  64983. const oldTarget = this.threeRenderer.getRenderTarget();
  64984. this.threeRenderer.setRenderTarget(this.target);
  64985. this.threeRenderer.clear(true, true, true);
  64986. this.potreeRenderer.render(scene, this.camera, this.target, {});
  64987. this.threeRenderer.setRenderTarget(oldTarget);
  64988. }
  64989. }
  64990. class Label extends EventDispatcher{
  64991. constructor(o={}){
  64992. super();
  64993. this.position = o.pos;
  64994. this.text = o.text || '';
  64995. this.elem = $('<div class="hide"><a></a></div>');
  64996. o.className && this.elem.addClass(o.className);
  64997. this.elem.find('a').html(this.text);
  64998. $("#potree_labels").append(this.elem);
  64999. this.pos2d = new Vector3;
  65000. this.dom = o.dom || viewer.renderArea;
  65001. this.camera = o.camera || viewer.scene.getActiveCamera();
  65002. let update = (e)=>{
  65003. this.update(e);
  65004. };
  65005. viewer.addEventListener('camera_changed', update);
  65006. this.addEventListener('dispose', ()=>{
  65007. viewer.removeEventListener('camera_changed', update);
  65008. this.dispose();
  65009. });
  65010. }
  65011. update(){
  65012. if(!this.position || this.elem.hasClass('unvisible'))return
  65013. var p = Utils.getPos2d(this.position, viewer.mainViewport,this.dom);
  65014. if(!p.trueSide){
  65015. this.elem.addClass("hide"); return;
  65016. }
  65017. this.elem.css({
  65018. left: p.pos.x +'px',
  65019. top: p.pos.y +'px'
  65020. });
  65021. this.elem.removeClass("hide");
  65022. this.pos2d = p.vector;
  65023. }
  65024. setVisible(visi){
  65025. if(!visi){
  65026. this.elem.addClass("unvisible");
  65027. }else {
  65028. this.elem.removeClass("unvisible");
  65029. this.update();
  65030. }
  65031. }
  65032. setText(text){
  65033. this.text = text || '';
  65034. this.elem.find('a').html(this.text);
  65035. }
  65036. setPos(pos){
  65037. this.position = pos;
  65038. }
  65039. dispose(){
  65040. this.elem.remove();
  65041. this.removeAllListeners();
  65042. }
  65043. }
  65044. //THREE.Vector2.name1 = 'ctrlPolygon'
  65045. const verticalLine = new Line3();
  65046. //控制点和边的合集。具有可以拖拽修改的功能,拖拽时能防止线相交。
  65047. class ctrlPolygon extends Object3D {
  65048. constructor (type, prop) {
  65049. super();
  65050. this.type = type;
  65051. this.maxMarkers = Number.MAX_SAFE_INTEGER;
  65052. this.transformData(prop);
  65053. for(let i in prop){
  65054. this[i] = prop[i];
  65055. }
  65056. if((this.atPlane || this.showArea ) && this.closed && this.dimension == '2d'){
  65057. this.areaPlane = this.createAreaPlane();
  65058. this.add(this.areaPlane);
  65059. }
  65060. //数据--刚开始一定是空的
  65061. this.points = [];
  65062. //mesh 不一定有
  65063. this.markers = [];
  65064. this.edges = [];
  65065. this.center;
  65066. }
  65067. initData(prop){
  65068. //开始加数据
  65069. prop.dataset_points && (this.dataset_points = prop.dataset_points);
  65070. prop.datasetId && (this.datasetId = prop.datasetId);
  65071. prop.points_datasets && (this.points_datasets = prop.points_datasets);
  65072. if(Potree.settings.editType == 'merge' || this.measureType == 'MulDistance Ring'){ //融合页面没有地图,measure的不需要指定datasetId,每个点都有各自的datasetId,跟着各自的模型走
  65073. if(this.dataset_points){
  65074. this.dataset_points = this.dataset_points.map(e=>{
  65075. return e && new Vector3().copy(e)
  65076. });
  65077. prop.points = this.dataset_points.map((p,i)=>{
  65078. return Potree.Utils.datasetPosTransform({fromDataset:true, datasetId:this.points_datasets[i], position: p})
  65079. });
  65080. if(prop.points.some(e=>e == void 0)){
  65081. return false
  65082. }
  65083. }else {
  65084. this.dataset_points = [];
  65085. }
  65086. }
  65087. if(prop.points){
  65088. for(const p of prop.points){
  65089. const pos = new Vector3().copy(p);
  65090. this.addMarker({point:pos});
  65091. }
  65092. if(Potree.settings.editType != 'merge' && this.measureType != 'MulDistance Ring'){
  65093. if(this.datasetId != void 0){//初始化位置
  65094. if(this.dataset_points){
  65095. this.dataset_points = this.dataset_points.map(e=>{
  65096. return e && new Vector3().copy(e)
  65097. });
  65098. this.transformByPointcloud(); //根据dataset_points和this.datasetId生成points
  65099. }
  65100. }else {
  65101. if(prop.dataset_points && prop.dataset_points.some(e=>e != void 0)){
  65102. console.error('存在测量线的datasetId为空而dataset_points有值,请检查并删除:'+this.sid);//存在过的bug,原因未知,可能是后台处理dataset时替换的错误:http://192.168.0.21/index.php?m=bug&f=view&bugID=23601
  65103. console.log(this);
  65104. }
  65105. }
  65106. }
  65107. this.facePlane = this.getFacePlane();
  65108. this.getPoint2dInfo(this.points);
  65109. this.update({ifUpdateMarkers:true});
  65110. //this.dragChange(new THREE.Vector3().copy(prop.points[prop.points.length-1]), prop.points.length-1);
  65111. this.setSelected(false );
  65112. this.markers.forEach(marker=>{marker.dispatchEvent('addHoverEvent'); });
  65113. return true
  65114. }
  65115. }
  65116. addMarker(o={}){
  65117. var index = o.index == void 0 ? this.points.length : o.index; //要当第几个
  65118. this.points = [...this.points.slice(0,index), o.point.clone(), ...this.points.slice(index,this.points.length)];
  65119. //this.points.push(o.point);
  65120. if('dataset_point' in o){//需要增加,可能是null
  65121. 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,新加的应该也是
  65122. }
  65123. if('points_dataset' in o){
  65124. this.points_datasets = [...this.points_datasets.slice(0,index), o.points_dataset, ...this.points_datasets.slice(index,this.points_datasets.length)];
  65125. }
  65126. if(o.marker){
  65127. this.add(o.marker);
  65128. this.markers = [...this.markers.slice(0,index), o.marker, ...this.markers.slice(index,this.markers.length)];
  65129. this.updateMarker(o.marker, o.point);
  65130. o.marker.addEventListener('drag', this.dragMarker.bind(this),{importance:2});
  65131. o.marker.addEventListener('drop', this.dropMarker.bind(this),{importance:2});
  65132. o.marker.createTime = Date.now();
  65133. let addHoverEvent = (e)=>{
  65134. let mouseover = (e) => {
  65135. this.setMarkerSelected(e.object, 'hover', 'single');
  65136. viewer.dispatchEvent({
  65137. type : "CursorChange", action : "add", name:"markerMove"
  65138. });
  65139. };
  65140. let mouseleave = (e) => {
  65141. this.setMarkerSelected(e.object, 'unhover', 'single');
  65142. viewer.dispatchEvent({
  65143. type : "CursorChange", action : "remove", name:"markerMove"
  65144. });
  65145. };
  65146. o.marker.addEventListener('mouseover', mouseover);
  65147. o.marker.addEventListener('mouseleave', mouseleave);
  65148. o.marker.addEventListener('startDragging', (e)=>{//for mobile
  65149. this.setMarkerSelected(o.marker, 'hover', 'single');
  65150. this.dispatchEvent('startDragging');
  65151. });
  65152. o.marker.addEventListener('drop', (e)=>{//for mobile
  65153. this.setMarkerSelected(o.marker, 'unhover', 'single');
  65154. });
  65155. o.marker.removeEventListener('addHoverEvent',addHoverEvent);
  65156. };
  65157. o.marker.addEventListener('addHoverEvent',addHoverEvent);//当非isNew时才添加事件
  65158. if(!this.isNew){
  65159. o.marker.dispatchEvent('addHoverEvent');
  65160. }
  65161. }
  65162. if(o.edge){
  65163. this.add(o.edge);
  65164. this.edges = [...this.edges.slice(0,index), o.edge, ...this.edges.slice(index,this.edges.length)];
  65165. }
  65166. }
  65167. dragMarker(e){
  65168. var I, atMap;
  65169. if(e.hoverViewport != e.drag.dragViewport){//不能使用e.dragViewport,要使用drag中的,因为drag中存储的要一直继承下来,不因mouseup了而改变。
  65170. viewer.dispatchEvent({
  65171. type : "CursorChange", action : "add", name:"polygon_AtWrongPlace"
  65172. });
  65173. return
  65174. }
  65175. if(e.drag.pointerDelta.length() == 0 && !this.isNew){ //部分设备(华为matePad11)在touchstart后立即执行了touchmove,导致marker立即移动,需要屏蔽..(刚创建时也会是0)
  65176. return
  65177. }
  65178. viewer.dispatchEvent({
  65179. type : "CursorChange", action : "remove", name:"polygon_AtWrongPlace"
  65180. });
  65181. atMap = e.drag.dragViewport.name == 'mapViewport';
  65182. if(atMap && this.unableDragAtMap){
  65183. e.drag.object = null; //取消拖拽
  65184. return
  65185. }
  65186. e.drag.object.isDragging = true;
  65187. I = e.intersect && (e.intersect.adsorption ? e.intersect.location : (e.intersect.orthoIntersect || e.intersect.location));
  65188. if(viewer.inputHandler.pressedKeys[18] || Potree.settings.dragPolyBeyondPoint&&!I ){//alt dragPolyBeyondPoint可以平移拖拽到无点的地方---测试用
  65189. let i = this.markers.indexOf(e.drag.object);
  65190. I = this.points[i].clone();
  65191. const projected = I.clone().project(e.drag.dragViewport.camera);
  65192. projected.x = e.pointer.x;
  65193. projected.y = e.pointer.y;
  65194. const unprojected = projected.clone().unproject(e.drag.dragViewport.camera);
  65195. I.copy(unprojected);
  65196. }
  65197. if (I) {
  65198. let i = this.markers.indexOf(e.drag.object);
  65199. if (i !== -1) {
  65200. this.dragChange(I.clone(), i, atMap);
  65201. if(this.points_datasets){
  65202. if(e.intersect){
  65203. if(e.intersect.pointcloud) this.points_datasets[i] = e.intersect.pointcloud.dataset_id;
  65204. else if(e.intersect.object) this.points_datasets[i] = e.intersect.object.dataset_id;
  65205. else { //地图
  65206. if(this.measureType == 'MulDistance Ring'){//因为它的每个point跟着各自的dataset走,而不是整体的dataset
  65207. let pointcloud = viewer.findClosestDatasetOnMap(I) || viewer.scene.pointclouds[0];
  65208. this.points_datasets[i] = pointcloud.dataset_id;
  65209. }else this.points_datasets[i] = null;
  65210. }
  65211. }
  65212. }
  65213. }
  65214. this.editStateChange(true);
  65215. return true
  65216. }
  65217. };
  65218. dragChange(intersectPos, i, atMap){
  65219. let len = this.markers.length;
  65220. let oldPoint = this.points[i];
  65221. if(atMap){
  65222. intersectPos.setZ(oldPoint.z); //在地图上拖拽,不改变其高度。
  65223. }
  65224. let location = intersectPos.clone();
  65225. if(this.faceDirection && this.maxMarkers == 2 && len == 2){//add 固定方向的点不直接拖拽
  65226. var p1 = this.markers[0].position;
  65227. if(this.faceDirection == 'horizontal'){
  65228. var projectPos = location.clone().setZ(p1.z);
  65229. }else {
  65230. var projectPos = p1.clone().setZ(location.z);
  65231. }
  65232. //var p2 = p1.clone().add(this.direction)
  65233. //var projectPos = math.getFootPoint(location, p1, p2)
  65234. LineDraw.updateLine(this.guideLine, [location, projectPos]);
  65235. location = projectPos;
  65236. this.guideLine.visible = true;
  65237. }else if( len > 1 ){
  65238. var points = this.points.map(e=>e.clone());
  65239. points[i].copy(location); //算normal需要提前确认point
  65240. //若为定义了面朝向的矩形
  65241. if(this.faceDirection == 'horizontal'){
  65242. if(len == 2){
  65243. location.setZ(points[0].z);
  65244. }
  65245. if(!this.facePlane){//一个点就能确定面
  65246. this.facePlane = new Plane().setFromNormalAndCoplanarPoint( new Vector3(0,0,1), this.points[0] );
  65247. }
  65248. }else if(this.faceDirection == 'vertical'){//当有两个点时, 有两个方向的可能
  65249. if(len == 2){
  65250. if(this.isRect){
  65251. let vec = points[0].clone().sub(location);
  65252. if(Math.sqrt(vec.x*vec.x+vec.y*vec.y) > Math.abs(vec.z) ){//水平(高度差小于水平距离时)
  65253. location.setZ(points[0].z);
  65254. //this.cannotConfirmNormal = false;//能确定面为水平方向
  65255. }else {//垂直 (当两点一样时也属于这种)
  65256. location.setX(points[0].x);
  65257. location.setY(points[0].y);
  65258. //this.cannotConfirmNormal = true; //不能确定面,因第三点可绕着纵轴线自由移动
  65259. }
  65260. }
  65261. }else {
  65262. {//判断cannotConfirmNormal. 如果前几段都在竖直线上,就不能固定出面方向。
  65263. this.cannotConfirmNormal = true;
  65264. let max = this.isRect ? 1 : len-2;
  65265. for(let i=0;i<max;i++){
  65266. let p1 = points[i].clone();
  65267. let p2 = points[i+1].clone();
  65268. let vec = p1.sub(p2);
  65269. if(vec.x != 0 || vec.y != 0){
  65270. this.cannotConfirmNormal = false;
  65271. break;
  65272. }
  65273. }
  65274. }
  65275. if(!this.facePlane || this.cannotConfirmNormal){//三个点且为水平方向时,计算面
  65276. var points_ = points.map(e=>new Vector2(e.x,e.y));
  65277. var points2 = getDifferentPoint(points_, 2);
  65278. if(points2){
  65279. let normal = math.getNormal2d({p1:points2[0], p2:points2[1]});
  65280. normal = new Vector3(normal.x, normal.y, 0);
  65281. this.facePlane = new Plane().setFromNormalAndCoplanarPoint( normal, this.points[0] );
  65282. }
  65283. }
  65284. }
  65285. }
  65286. if(len > 2){
  65287. if(!this.faceDirection && this.showArea){
  65288. if(len == 3 || this.isRect) this.cannotConfirmNormal = true; //当第三个点固定后(有四个点时)才能固定面
  65289. if(!this.facePlane || this.cannotConfirmNormal){
  65290. var points3 = getDifferentPoint(points, 3);//只有找到三个不同的点算拥有面和area
  65291. if(points3){
  65292. this.facePlane = new Plane().setFromCoplanarPoints(...points3 );
  65293. }
  65294. }
  65295. }
  65296. if(this.atPlane && this.facePlane && !this.cannotConfirmNormal ){//之后加的点一定要在面上
  65297. if(atMap){
  65298. //地图上用垂直线,得到和面的交点。
  65299. verticalLine.set(location.clone().setZ(100000), location.clone().setZ(-100000));//确保长度范围覆盖所有测量面
  65300. location = this.facePlane.intersectLine(verticalLine, new Vector3() );
  65301. if(!location) return;
  65302. }else {
  65303. location = this.facePlane.projectPoint(intersectPos, new Vector3() );
  65304. }
  65305. }
  65306. points[i].copy(location);//再copy确认一次
  65307. if(len == 3 && this.faceDirection == 'horizontal' && this.closed){ //normal方向还不确定 会影响label在里侧还是外侧
  65308. let facePlane = new Plane().setFromCoplanarPoints(...points);
  65309. if(facePlane.normal.z && facePlane.normal.z * this.facePlane.normal.z < 0){
  65310. this.facePlane.normal.z *= -1, this.facePlane.constant *= -1;
  65311. //console.log(this.facePlane.normal, this.facePlane.constant)
  65312. }
  65313. }
  65314. if(this.isRect){ //是矩形 (即使没有faceDirection也能执行)
  65315. //根据前两个点计算当前和下一个点
  65316. var p1 = points[(i-2+len)%len];
  65317. var p2 = points[(i-1+len)%len];
  65318. if(p1.equals(p2)){//意外情况:重复点两次 ( bug点,改了好多遍)
  65319. if(this.faceDirection == 'vertical'){
  65320. p2.add(new Vector3(0,0,0.0001));
  65321. }else {
  65322. p2.add(new Vector3(0,0.0001,0));
  65323. }
  65324. }
  65325. //p3 : location
  65326. var foot = math.getFootPoint(location, p1, p2);//p2 修改p2到垂足的位置
  65327. var vec = foot.clone().sub(location);
  65328. var p4 = p1.clone().sub(vec);
  65329. points[(i-1+len)%len].copy(foot);
  65330. points[(i+1)%len].copy(p4);
  65331. this.setPosition((i-1+len)%len, foot);//p2
  65332. this.setPosition((i+1)%len, p4);
  65333. }
  65334. this.getPoint2dInfo(points);
  65335. var isIntersectSelf = this.atPlane && this.closed && !this.isRect && this.point2dInfo && this.intersectSelf(this.point2dInfo.points2d);//检测相交
  65336. this.isIntersectSelf = isIntersectSelf;
  65337. if(isIntersectSelf){//not-allowed
  65338. if(!this.isNew && isIntersectSelf == 'lastLine') this.isIntersectSelf = 'all'; //已经画好了就不用特别对待最后一条线
  65339. if(this.isIntersectSelf == 'lastLine'){
  65340. Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', false);
  65341. Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', false);
  65342. }else {
  65343. viewer.dispatchEvent({
  65344. type : "CursorChange", action : "add", name:"polygon_isIntersectSelf"
  65345. });
  65346. return
  65347. }
  65348. }
  65349. if(!this.isIntersectSelf){
  65350. this.areaPlane && Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', true);
  65351. this.areaLabel && Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', true);
  65352. }
  65353. if(!this.isIntersectSelf || this.isIntersectSelf == 'lastLine' ){
  65354. viewer.dispatchEvent({
  65355. type : "CursorChange", action : "remove", name:"polygon_isIntersectSelf"
  65356. });
  65357. }
  65358. }
  65359. var showGuideLine = len>1 && (this.faceDirection || len > 3);
  65360. if(showGuideLine && this.guideLine){
  65361. LineDraw.updateLine(this.guideLine, [intersectPos, location]);
  65362. this.guideLine.visible = true;
  65363. }
  65364. //console.log(this.points.map(e=>e.toArray()))
  65365. }
  65366. if(this.restrictArea){
  65367. let holes = this.restrictArea.holes.concat(this.restrictArea.parentHoles);
  65368. let holesPoints = holes.filter(e=>e!=this && e.points.length>2).map(e=>e.points);
  65369. if(!math.isPointInArea(this.restrictArea.points, holesPoints, location)){
  65370. viewer.dispatchEvent({
  65371. type : "CursorChange", action : "add", name:"polygon_AtWrongPlace"
  65372. });
  65373. this.isAtWrongPlace = true;
  65374. return
  65375. }
  65376. //就不处理相交线了。 有个缺点:floor上的hole可以限制room,但hole不受room限制,会导致room的marker被框在hole里而动不了。只能去调整hole了
  65377. }
  65378. viewer.dispatchEvent({
  65379. type : "CursorChange", action : "remove", name:"polygon_AtWrongPlace"
  65380. });
  65381. this.isAtWrongPlace = false;
  65382. this.setPosition(i, location);
  65383. this.update({index: this.isRect ? null : i});
  65384. this.dispatchEvent({type:'dragChange', index:i});
  65385. }
  65386. dropMarker(e){
  65387. //console.log('dropMarker')
  65388. if (this.isNew && e.pressDistance>Potree.config.clickMaxDragDis){//拖拽的话返回
  65389. return this.continueDrag(null,e)
  65390. }
  65391. if(e.hoverViewport != e.drag.dragViewport){//copy from dragMarker, for sitemodel, only mapViewport can be dropped
  65392. return this.continueDrag(null,e)
  65393. }
  65394. if(e.isTouch){
  65395. if(e.hoverViewport != viewer.mainViewport && this.unableDragAtMap){
  65396. viewer.dispatchEvent({type:'reticule_forbit', v:true});
  65397. //console.log('reticule_forbit',true)
  65398. return this.continueDrag(null,e)
  65399. }else {
  65400. viewer.dispatchEvent({type:'reticule_forbit', v:false});
  65401. //console.log('reticule_forbit',false)
  65402. }
  65403. this.isNew && this.dragMarker(e); //isNew触屏点击时必须先更新下点,因为指尖不在屏幕上时没更新。但对已经创建的marker点击时不应该更新
  65404. }
  65405. if (e.button != MOUSE.RIGHT && (//右键click的话继续执行,因为会停止
  65406. this.isIntersectSelf == 'all' && this.isNew //有线相交了
  65407. || this.isAtWrongPlace && this.isNew
  65408. || !e.isAtDomElement && this.isNew//如果是刚添加时在其他dom点击, 不要响应
  65409. || e.hoverViewport != viewer.mainViewport && this.unableDragAtMap //垂直的测量线不允许在地图上放点
  65410. || this.isNew && !getDifferentPoint(this.points, this.points.length ) //不允许和之前的点相同, 但这句在点云稀疏时会导致难结束
  65411. )
  65412. ){
  65413. return this.continueDrag(null,e)
  65414. }
  65415. //console.log('drop marker' )
  65416. let i = this.markers.indexOf(e.drag.object);
  65417. if (i !== -1) {
  65418. this.dispatchEvent({
  65419. 'type': 'marker_dropped',
  65420. 'index': i
  65421. });
  65422. if(this.markers.length>2 && this.facePlane)this.cannotConfirmNormal = false;
  65423. this.guideLine &&(this.guideLine.visible = false);
  65424. }
  65425. this.setMarkerSelected(e.drag.object, 'unhover', 'single');
  65426. this.editStateChange(false);
  65427. e.drag.endDragFun && e.drag.endDragFun(e);// addmarker
  65428. //if(this.changeCallBack)this.changeCallBack()
  65429. return true
  65430. };
  65431. getFacePlane(){//最普通一种get方法,根据顶点。且假设所有点已经共面,且不重合
  65432. if(/* !this.atPlane || */this.points.length<3) return
  65433. /* this.facePlane = new THREE.Plane().setFromCoplanarPoints(...this.points.slice(0,3) ) */
  65434. let facePlane = this.facePlane;
  65435. if(!this.atPlane || !facePlane){//多折线 没有实时更新facePlane所以重新算
  65436. let normal = new Vector3, len = this.points.length - 2;
  65437. for(let i=0;i<len;i++){ //获取normal的顺序方法必须和setFromCoplanarPoints一致
  65438. let vec0 = new Vector3().subVectors(this.points[i+2], this.points[i+1], );
  65439. let vec1 = new Vector3().subVectors(this.points[i], this.points[i+1]);
  65440. let nor = vec0.cross(vec1).normalize();
  65441. normal.add(nor);
  65442. }
  65443. normal.normalize();
  65444. facePlane = new Plane().setFromNormalAndCoplanarPoint(normal, this.points[0]);
  65445. }
  65446. return facePlane
  65447. }
  65448. getPoint2dInfo(points){ //在更新areaplane之前必须更新过point2dInfo (针对所有点在同一平面上的)
  65449. if(this.facePlane && (this.atPlane || Potree.settings.areaAtNotPlane)){
  65450. let facePlane = this.getFacePlane();
  65451. var originPoint0 = points[0].clone();
  65452. var qua = math.getQuaBetween2Vector(facePlane.normal, new Vector3(0,0,1), new Vector3(0,0,1));
  65453. let points2d = points.map(e=>e.clone().applyQuaternion(qua));
  65454. this.point2dInfo = {
  65455. originPoint0 ,
  65456. points2d,
  65457. quaInverse : qua.clone().invert()
  65458. };
  65459. }
  65460. }
  65461. setPosition (index, position) {//拖拽后设置位置
  65462. let point = this.points[index];
  65463. point.copy(position);
  65464. /* if(this.datasetId){
  65465. this.dataset_points[index] = Potree.Utils.datasetPosTransform({toDataset:true, datasetId:this.datasetId, position:point.clone()})
  65466. } */
  65467. /* if(Potree.settings.editType == 'merge'){
  65468. this.dataset_points[index] = Potree.Utils.datasetPosTransform({toDataset:true,this.points_datasets[i], position:point.clone()})
  65469. } */
  65470. let marker = this.markers[index];
  65471. this.updateMarker(marker, point);
  65472. }
  65473. updateMarker(marker, pos){
  65474. marker.position.copy(pos);
  65475. marker.waitUpdate();
  65476. }
  65477. intersectSelf(points2d){//add
  65478. var len = points2d.length;
  65479. for(var i=0;i<len;i++){
  65480. for(var j=i+2;j<len;j++){
  65481. if(Math.abs(j-len-i)<2)continue;//不和邻边比
  65482. var p1 = points2d[i];
  65483. var p2 = points2d[i+1];
  65484. var p3 = points2d[j];
  65485. var p4 = points2d[(j+1)%len];
  65486. if(p1.equals(p2) || p3.equals(p4) || p1.equals(p3) || p2.equals(p3) || p1.equals(p4) || p2.equals(p4))continue
  65487. var line1 = [p1,p2];
  65488. var line2 = [p3,p4];
  65489. var intersect = math.isLineIntersect(line1, line2, false, 0.001);
  65490. if(intersect){
  65491. if(i==len-1 || j==len-1){//最后一条线。如果还没绘制完,最后的线还没定下,可被允许继续绘制,但无法显示面积。
  65492. return 'lastLine'
  65493. }else {
  65494. return 'all'
  65495. }
  65496. break
  65497. }
  65498. }
  65499. }
  65500. }
  65501. removeMarker (index) {
  65502. this.points.splice(index, 1);
  65503. const marker = this.markers[index];
  65504. //this.remove(marker);
  65505. this.markers.splice(index, 1);
  65506. marker.dispose();
  65507. let edgeIndex = index; //(index === 0) ? 0 : (index - 1);
  65508. const edge = this.edges[edgeIndex];
  65509. if(edge){
  65510. this.remove(edge);
  65511. this.edges.splice(edgeIndex, 1);
  65512. edge.geometry.dispose();
  65513. }
  65514. this.point2dInfo && this.point2dInfo.points2d.splice(index, 1); //add
  65515. this.dispatchEvent({type:'removeMarker',index,marker});
  65516. }
  65517. createAreaPlane(mat){
  65518. var geometry = new Geometry();
  65519. var mesh = new Mesh(geometry, mat);
  65520. return mesh
  65521. }
  65522. updateAreaPlane(){
  65523. this.areaPlane.geometry.dispose();
  65524. if(this.points.length>2){
  65525. if(this.isPrism){
  65526. let z = this.horizonZ || 0;
  65527. let points2d = this.points.map(e=>e.clone().setZ(z));
  65528. this.areaPlane.geometry = MeshDraw.getShapeGeo(points2d); //z=0
  65529. let center = math.getCenterOfGravityPoint(points2d); //重心
  65530. this.areaPlaneCenter = new Vector3(center.x, center.y, z);
  65531. this.areaPlane.position.z = z;
  65532. }else if(this.point2dInfo){
  65533. if(Potree.settings.areaAtNotPlane){
  65534. //测点不在同一平面的面积. (缺点:容易出现三角缺块, 以及搭错线导致超出理想边界外。在平面上n个点能构成n-2个三角形,但空间中更多个,所以若要指定出类似平面那样n-2个三角形是有多种可能的。故暂不开放。 用d3.Delaunay结果更差) //测试桥面 SG-arqnGgAR7om&formal
  65535. //参考 http://indoor.popsmart.cn:8084/sxswsw-sx/ 找到场景中面积测量线的方法:window.scene.children[18].children[0].material.color.r = 1
  65536. let geometry = new Geometry;
  65537. let faceArray = [], triangles = ShapeUtils.triangulateShape(this.point2dInfo.points2d, [] ); //因为它只关注xy平面,垂直画就容易错,所以用转到平面的points2d来识别三角。
  65538. if(triangles.length == 0)return
  65539. this._area = 0;
  65540. for( var i = 0; i < triangles.length; i++ ){
  65541. faceArray[i] = new Face3( triangles[i][0], triangles[i][1], triangles[i][2] );
  65542. let nor = new Vector3().crossVectors(
  65543. new Vector3().subVectors(this.points[triangles[i][0]], this.points[triangles[i][2]] ),
  65544. new Vector3().subVectors(this.points[triangles[i][1]], this.points[triangles[i][2]])
  65545. );
  65546. this._area += nor.length() / 2;
  65547. nor.normalize();
  65548. faceArray[i].normal.copy(nor);
  65549. }
  65550. geometry.vertices = this.points;
  65551. geometry.faces = faceArray;
  65552. this.areaPlane.geometry = new BufferGeometry().fromGeometry(geometry); //不知道为何不转为bufferGeometry显示不出
  65553. //this.center
  65554. //参考getFacePlane 在这里建立_normal?
  65555. }else {
  65556. //if(this.point2dInfo){//旧的。 之前的规定点要在同一平面
  65557. this.areaPlane.geometry = MeshDraw.getShapeGeo(this.point2dInfo.points2d);
  65558. let center = math.getCenterOfGravityPoint(this.point2dInfo.points2d); //重心
  65559. let firstPos = this.point2dInfo.points2d[0].clone();
  65560. firstPos.z = 0; //因为shape只读取了xy,所以位移下, 再算出最终位置,得到差距
  65561. firstPos.applyQuaternion(this.point2dInfo.quaInverse);
  65562. let vec = this.point2dInfo.originPoint0.clone().sub(firstPos);
  65563. center = new Vector3(center.x, center.y, 0);
  65564. center.applyQuaternion(this.point2dInfo.quaInverse);
  65565. this.areaPlane.quaternion.copy(this.point2dInfo.quaInverse);
  65566. this.areaPlane.position.copy(vec);
  65567. center.add(vec);
  65568. this.center = center;
  65569. //}
  65570. }
  65571. }
  65572. }else {
  65573. this.areaPlane.geometry = new Geometry();
  65574. }
  65575. }
  65576. getIndex(index, add){
  65577. let lastIndex = this.points.length - 1;
  65578. if(add == -1) return (index === 0) ? lastIndex : index - 1;
  65579. else if(add == 1) return (index + 1 > lastIndex) ? 0 : index + 1;
  65580. }
  65581. update(options={}){
  65582. if(this.points.length === 0){
  65583. return;
  65584. }
  65585. //performance.mark('measureUpdate-start')
  65586. let lastIndex = this.points.length - 1;
  65587. if(options.index != void 0){//更新第几个点
  65588. this.updateMarker(this.markers[options.index], this.points[options.index]);
  65589. let previousIndex = this.getIndex(options.index, -1);
  65590. let nextIndex = this.getIndex(options.index, +1);
  65591. if( this.closed || nextIndex != 0 ) LineDraw.updateLine( this.edges[options.index], [this.points[options.index], this.points[nextIndex]]);
  65592. if( this.closed || previousIndex != lastIndex ) LineDraw.updateLine( this.edges[previousIndex], [this.points[options.index], this.points[previousIndex]]);
  65593. }else {
  65594. for (let index = 0; index <= lastIndex; index++) {
  65595. let nextIndex = this.getIndex(index, +1);
  65596. let previousIndex = this.getIndex(index, -1);
  65597. let point = this.points[index];
  65598. let nextPoint = this.points[nextIndex];
  65599. let previousPoint = this.points[previousIndex];
  65600. if(options.ifUpdateMarkers){
  65601. this.updateMarker(this.markers[index], point);
  65602. }
  65603. if(!this.closed && nextIndex == 0 )break; //add
  65604. {
  65605. let edge = this.edges[index];
  65606. if(edge){
  65607. LineDraw.updateLine(edge, [point, nextPoint]);
  65608. }
  65609. }
  65610. }
  65611. }
  65612. if(this.areaPlane){
  65613. this.updateAreaPlane();
  65614. }
  65615. //this.dispatchEvent({type:'update'})
  65616. viewer.dispatchEvent('content_changed');
  65617. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed'); //暂时先这么都通知
  65618. //performance.mark('measureUpdate-end')
  65619. //let measure = performance.measure('measure-','measureUpdate-start', 'measureUpdate-end' );
  65620. //console.log('update-time', measure.duration)
  65621. }
  65622. createPrismLines(color){
  65623. this.lineMesh = LineDraw.createLine([],{color});
  65624. this.lineMesh.name = 'PrismLines';
  65625. this.add(this.lineMesh);
  65626. }
  65627. updatePrismLines(){
  65628. if(!this.lineMesh)return
  65629. let positions = [];
  65630. let length = this.points.length;
  65631. this.points.forEach((point, index)=>{
  65632. //竖线:
  65633. positions.push(point.clone().setZ(this.zMin), point.clone().setZ(this.zMax));
  65634. //横线
  65635. let nextPoint = this.points[(index+1)%length];
  65636. if(!nextPoint)return;//when length==1
  65637. positions.push(point.clone().setZ(this.zMax), nextPoint.clone().setZ(this.zMax));//上横线
  65638. positions.push(point.clone().setZ(this.zMin), nextPoint.clone().setZ(this.zMin));//下横线
  65639. });
  65640. LineDraw.moveLine(this.lineMesh,positions);
  65641. viewer.dispatchEvent('content_changed');
  65642. }
  65643. dispose(){//add
  65644. this.parent.remove(this);
  65645. this.markers.forEach(e=>e.dispose());
  65646. this.edges.forEach(e=>e.geometry.dispose());
  65647. }
  65648. reDraw(restMarkerCount=0){//重新开始画
  65649. let pointCount = this.points.length - restMarkerCount; // restMarkerCount为需要留下的marker数量
  65650. while(pointCount > 0){
  65651. this.removeMarker(--pointCount);
  65652. }
  65653. this.point2dInfo = null;
  65654. this.facePlane = null;
  65655. }
  65656. setMarkerSelected(){}
  65657. editStateChange(state){
  65658. if(!state){
  65659. viewer.dispatchEvent({
  65660. type : "CursorChange", action : "remove", name:"polygon_isIntersectSelf"
  65661. });
  65662. viewer.dispatchEvent({
  65663. type : "CursorChange", action : "remove", name:"polygon_AtWrongPlace"
  65664. });
  65665. viewer.dispatchEvent({type:'reticule_forbit', v:false});
  65666. this.markers.forEach(e=>e.isDragging = false );
  65667. }
  65668. }
  65669. transformData(prop){
  65670. const pick = (defaul, alternative) => {
  65671. if(defaul != null){
  65672. return defaul;
  65673. }else {
  65674. return alternative;
  65675. }
  65676. };
  65677. prop.showDistances = (prop.showDistances === null) ? true : prop.showDistances;
  65678. prop.showArea = pick(prop.showArea, false);
  65679. prop.showAngles = pick(prop.showAngles, false);
  65680. prop.showCoordinates = pick(prop.showCoordinates, false);
  65681. prop.showHeight = pick(prop.showHeight, false);
  65682. prop.showCircle = pick(prop.showCircle, false);
  65683. prop.showAzimuth = pick(prop.showAzimuth, false);
  65684. prop.showEdges = pick(prop.showEdges, true);
  65685. prop.closed = pick(prop.closed, false);
  65686. prop.maxMarkers = pick(prop.maxMarkers, Infinity);
  65687. prop.direction = prop.direction;//add
  65688. prop.type = prop.type;
  65689. prop.showGuideLine = pick(prop.showGuideLine, false);
  65690. prop.isRect = pick(prop.isRect, false);
  65691. }
  65692. setSelected(){}
  65693. continueDrag(marker, e){
  65694. let object = marker || e.drag.object;
  65695. object.isDragging = true;
  65696. this.editStateChange(true);
  65697. var timer = setTimeout(()=>{//等 drag=null之后 //右键拖拽结束后需要重新得到drag
  65698. if(this.parent && object.parent && object.isDragging){
  65699. //console.log('continueDrag')
  65700. viewer.inputHandler.startDragging( object ,
  65701. {endDragFun: e.drag.endDragFun, notPressMouse:e.drag.notPressMouse, dragViewport:e.drag.dragViewport}
  65702. );
  65703. }
  65704. },1);
  65705. return timer
  65706. }
  65707. }
  65708. function getDifferentPoint(points, count){//for facePlane
  65709. var result = [];
  65710. for(let i=0;i<points.length;i++){
  65711. var p = points[i];
  65712. if(result.find(e=>e.equals(p)))continue;
  65713. else result.push(p);
  65714. if(result.length == count)break
  65715. }
  65716. if(result.length == count)return result
  65717. }
  65718. let texLoader$6 = new TextureLoader();
  65719. let defaultColor$1 = new Color(config$1.measure.default.color);
  65720. let highlightColor = new Color(config$1.measure.highlight.color);
  65721. let color = new Color(config$1.measure.color);
  65722. let textColor = new Color(config$1.measure.textColor);
  65723. var markerMats;
  65724. var lineMats;
  65725. var planeMats;
  65726. const textSizeRatio = math.linearClamp(window.outerWidth * window.outerHeight , [360*720, 1920*1080], [0.7, 1]); //pc字显示大一些 用
  65727. const lineDepthInfo = {
  65728. clipDistance : 15,//4,//消失距离
  65729. occlusionDistance: 3,//1,//变为backColor距离
  65730. };
  65731. const markerMapShrink = browser.isMobile() ? 0.4 : 0.8; //触屏需要更大的热区
  65732. const markerSizeInfo = {
  65733. width2d : 18 / markerMapShrink , // nearBound : 1.5, farBound : 15,
  65734. };
  65735. /* const markerSizeInfo = {
  65736. minSize : 10 , maxSize : 15 , nearBound : 1.5, farBound : 15,
  65737. } */
  65738. const labelSizeInfo = {width2d:200};
  65739. const mainLabelProp = {
  65740. //backgroundColor: {r: defaultColor.r*255, g: defaultColor.g*255, b: defaultColor.b*255, a:config.measure.default.opacity},
  65741. backgroundColor: {r: 0, g: 0, b: 0, a:0},
  65742. textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
  65743. textBorderColor: {r:255, g: 255, b:255, a: 1.0},
  65744. textBorderThick:3 ,
  65745. fontsize: 15 * textSizeRatio,
  65746. borderRadius : 12, margin:{x:20,y:4},
  65747. renderOrder : Potree.config.renderOrders.measureLabel,
  65748. pickOrder: Potree.config.renderOrders.measureLabel,
  65749. disToLine:-0.15,
  65750. useDepth : true ,
  65751. // 2023.10 尽量不让数字被挡住
  65752. clipDistance : 10,//消失距离
  65753. occlusionDistance: 10,//变为backColor距离
  65754. maxOcclusionFactor:0.3,
  65755. maxClipFactor:0.8
  65756. };
  65757. const subLabelProp = {
  65758. backgroundColor: {r: 255, g: 255, b: 255, a:0},
  65759. textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
  65760. textBorderColor: {r:255, g: 255, b:255, a: 1.0},
  65761. textBorderThick:3 ,
  65762. fontsize: 14 * textSizeRatio,
  65763. renderOrder : Potree.config.renderOrders.measureLabelSub,
  65764. pickOrder: Potree.config.renderOrders.measureLabelSub,
  65765. disToLine:-0.13,
  65766. };
  65767. const angle = MathUtils.degToRad(5);//显示水平垂直辅助线的最小角度
  65768. const guideShowMinAngle = {min: angle, max: Math.PI/2 - angle};
  65769. class Measure$1 extends ctrlPolygon{
  65770. constructor (prop) {
  65771. prop.dimension = '2d';
  65772. super('measure',prop);
  65773. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  65774. this.name = this.measureType + this.constructor.counter; //'Measure_' + this.constructor.counter;
  65775. this.markerLabels = [];
  65776. this.edgeLabels = [];
  65777. this.angleLabels = [];
  65778. this.coordinateLabels = [];
  65779. this.area = {value:0,string:''};
  65780. if( this.showArea ){
  65781. this.areaLabel = this.createAreaLabel();
  65782. this.add(this.areaLabel);
  65783. }
  65784. //add:
  65785. if(this.atPlane || this.faceDirection){ //是一个平面上的话
  65786. this.createGuideLine();
  65787. }
  65788. if(this.measureType == 'Distance' /* || this.measureType.includes('MulDistance') */){
  65789. this.createHorVerGuideLine();
  65790. }
  65791. this.selectStates = {};
  65792. this.setUnitSystem(prop.unit || viewer.unitConvert.UnitService.defaultSystem);
  65793. Potree.Utils.setObjectLayers(this, 'measure' );
  65794. if(this.measureType == 'MulDistance' || this.measureType == 'Hor MulDistance' || this.measureType == 'Ver MulDistance'){
  65795. //this.showTotalDis = true
  65796. this.totalDisLabel = this.createTotalDisLabel();
  65797. this.add(this.totalDisLabel);
  65798. }
  65799. //addMarkers:
  65800. this.initData(prop);
  65801. this.pointsPos2d = new Map; //屏幕上的二维坐标
  65802. this.points_datasets || (this.points_datasets = []); //存每个点是哪个数据集
  65803. this.addEventListener('marker_dropped',(e)=>{
  65804. this.updateDatasetBelong(e.index);
  65805. });
  65806. this.addEventListener('isVisible', ()=>{
  65807. viewer.mapViewer && viewer.mapViewer.dispatchEvent({type:'content_changed'});
  65808. });
  65809. this.lastDropTime = 0;
  65810. }
  65811. initData(prop){
  65812. let makeIt = super.initData(prop);
  65813. if(makeIt){
  65814. this.edges.forEach(edge=>{edge.dispatchEvent('addHoverEvent'); });
  65815. }else {
  65816. this.failBuilded = true;
  65817. }
  65818. }
  65819. updateDatasetBelong(changeIndex){//更新所属数据集
  65820. if(Potree.settings.editType == "merge" || this.measureType == 'MulDistance Ring'){//点直接跟着数据集走,不用找整体的datasetId
  65821. this.dataset_points[changeIndex] = Potree.Utils.datasetPosTransform({toDataset:true, datasetId:this.points_datasets[changeIndex], position:this.points[changeIndex].clone()});
  65822. return
  65823. }
  65824. let old = this.datasetId;
  65825. let maxCount = {id:null,count:0};
  65826. let datasets = {};
  65827. this.points_datasets.forEach(e=>{
  65828. if(e == void 0)return
  65829. if(datasets[e]){
  65830. datasets[e] ++;
  65831. }else {
  65832. datasets[e] = 1;
  65833. }
  65834. });
  65835. for(let i in datasets) {
  65836. if(datasets[i]>maxCount.count){
  65837. maxCount = {id:i, count:datasets[i]};
  65838. }
  65839. }
  65840. this.datasetId = maxCount.count > 0 ? maxCount.id : null;
  65841. //if(this.datasetId != old){
  65842. //this.dispatchEvent({type:'changeDatasetId'})
  65843. if(this.datasetId == void 0){
  65844. this.dataset_points = null; //可能为空或[null,null...]
  65845. }else {
  65846. this.dataset_points = this.points.map(e=>{
  65847. return Potree.Utils.datasetPosTransform({toDataset:true,datasetId:this.datasetId, position:e.clone()})
  65848. });
  65849. }
  65850. //}
  65851. }
  65852. transformByPointcloud(){//每次移动点云 or 加载测量线时要获取一下当前position //有地图时
  65853. if(this.datasetId == void 0)return
  65854. this.points = this.dataset_points.map(e=>{
  65855. return Potree.Utils.datasetPosTransform({fromDataset:true, datasetId:this.datasetId, position:e.clone()})
  65856. });
  65857. this.getPoint2dInfo(this.points);
  65858. this.update({ifUpdateMarkers:true});
  65859. this.setSelected(false);//隐藏edgelabel
  65860. }
  65861. update(options={}) {
  65862. if(options.index == -1)return
  65863. super.update(options);
  65864. if(this.showCoordinates && this.points.length>0){
  65865. let position = this.points[0];
  65866. this.markers[0].position.copy(position);
  65867. { // coordinate labels
  65868. let coordinateLabel = this.coordinateLabels[0];
  65869. let pos = [
  65870. position.toArray()
  65871. ];
  65872. if(viewer.transform){
  65873. let lonlat = viewer.transform.lonlatToLocal.inverse(position.toArray());
  65874. let EPSG4550 = viewer.transform.lonlatTo4550.forward(lonlat);
  65875. pos.push(lonlat,EPSG4550);
  65876. }
  65877. //let msg = position.toArray().map(p => Utils.addCommas(p.toFixed(2))).join(" / ");
  65878. let msg = pos.map(a=>
  65879. a.map(p => Utils.addCommas(p.toFixed(10))).join(", ")
  65880. ).join("<br>");
  65881. coordinateLabel.setText(msg);
  65882. coordinateLabel.setPos(position);
  65883. coordinateLabel.setVisible(true);//this.showCoordinates;
  65884. }
  65885. return
  65886. }
  65887. let setEdgeLabel = (label,p1,p2,distance)=>{//设置label位置和字
  65888. this.setEdgeLabelPos(label,p1,p2);
  65889. distance = distance == void 0 ? p1.distanceTo(p2) : distance;
  65890. //var text = viewer.unitConvert.convert(distance, 'distance', Potree.settings.precision, this.unitSystem, 1 , true)//distance要传0.1 这个factor
  65891. var text = this.getConvertString(distance, 'distance');
  65892. label.setText(text);
  65893. return distance
  65894. };
  65895. /* let setEdgeLabel = (label,p1,p2,distance)=>{//设置label位置和字
  65896. this.setEdgeLabelPos(label,p1,p2)
  65897. distance = distance == void 0 ? p1.distanceTo(p2) : distance;
  65898. var text = this.labelText || viewer.unitConvert.convert(distance, 'distance', Potree.settings.precision , this.unitSystem, 0.001 , true, true)//distance要传0.1 这个factor
  65899. label.setText(text)
  65900. } */
  65901. let lastIndex = this.points.length - 1;
  65902. let setLabel = (index)=>{
  65903. let previousIndex = this.getIndex(index, -1);
  65904. let nextIndex = this.getIndex(index, +1);
  65905. let previousPoint = this.points[previousIndex];
  65906. let point = this.points[index];
  65907. let nextPoint = this.points[nextIndex];
  65908. if(this.showDistances){ // edge labels
  65909. let edgeLabel = this.edgeLabels[index];
  65910. let distance = point.distanceTo(nextPoint);
  65911. this.edges[index].distance_ = distance;
  65912. edgeLabel.shouldVisi = (index < lastIndex || this.isRect || this.closed && !this.isNew ) && distance>0;
  65913. //this.closed || edgeLabel.setVisible(edgeLabel.shouldVisi) //closed的在setEdgesDisplay中设置
  65914. Utils.updateVisible(edgeLabel, 'shouldVisi', edgeLabel.shouldVisi, 2);
  65915. if(edgeLabel.shouldVisi){
  65916. edgeLabel.lineDir = new Vector3().subVectors(point,nextPoint).normalize(); //[point,nextPoint]
  65917. setEdgeLabel(edgeLabel,point,nextPoint,distance);
  65918. }
  65919. }
  65920. };
  65921. if(options.index != void 0){//更新第几个点
  65922. setLabel(options.index);
  65923. let previousIndex = this.getIndex(options.index, -1);
  65924. setLabel(previousIndex);
  65925. }else {
  65926. for (let index = 0; index <= lastIndex; index++) {
  65927. setLabel(index);
  65928. }
  65929. }
  65930. if(Potree.config.measure.mulLabelHideFaraway ){
  65931. this.measureType == 'MulDistance' && this.clearEdgeLabelVisi();
  65932. }
  65933. if(this.measureType == 'Distance' && this.points.length>1){//设置水平垂直辅助线
  65934. var pTop, pBtm;
  65935. if(this.points[0].z > this.points[1].z ){
  65936. pTop = this.points[0];
  65937. pBtm = this.points[1];
  65938. }else {
  65939. pTop = this.points[1];
  65940. pBtm = this.points[0];
  65941. }
  65942. let projectPos = new Vector3(pTop.x, pTop.y, pBtm.z);//两条guideline的交点
  65943. {//倾斜角度太小的时候不显示
  65944. let tan = pTop.distanceTo(projectPos) / pBtm.distanceTo(projectPos);
  65945. let angle = Math.atan(tan);
  65946. this.shouldShowHorVerGuide = angle > guideShowMinAngle.min && angle < guideShowMinAngle.max;
  65947. }
  65948. LineDraw.updateLine(this.verGuideEdge, [pTop, projectPos]);
  65949. LineDraw.updateLine(this.horGuideEdge, [pBtm, projectPos]);
  65950. setEdgeLabel(this.verEdgeLabel,pTop,projectPos);
  65951. setEdgeLabel(this.horEdgeLabel,pBtm,projectPos);
  65952. this.verGuideEdge.visible = this.horGuideEdge.visible = this.shouldShowHorVerGuide;
  65953. this.verEdgeLabel.visible = this.horEdgeLabel.visible = this.shouldShowHorVerGuide;
  65954. }
  65955. if(this.showArea && this.points.length > 2){ // update area
  65956. let msg = this.getArea().string;
  65957. this.areaLabel.setPos(this.getCenter('areaPlaneCenter'));
  65958. this.areaLabel.setText(msg);
  65959. Utils.updateVisible(this.areaLabel, 'setVisible', true); //this.areaLabel.setVisible(true)
  65960. }
  65961. if(this.totalDisLabel){
  65962. this.ifShowTotalDis();
  65963. Utils.updateVisible(this.totalDisLabel,'setVisible', this.showTotalDis);
  65964. this.edgeLabels.forEach(e=> Utils.updateVisible(e, 'showTotalDis', !this.showTotalDis));
  65965. if(this.showTotalDis){
  65966. let dis = this.getTotalDistance();
  65967. let msg = this.getConvertString(dis, 'distance');
  65968. this.center = null;
  65969. this.center = this.getCenter();
  65970. this.totalDisLabel.setPos(this.center);
  65971. this.totalDisLabel.setText(msg);
  65972. }
  65973. }
  65974. };
  65975. getArea(){
  65976. let area;
  65977. if(this._area != void 0){
  65978. area = this._area;
  65979. }else if(this.point2dInfo){
  65980. area = Math.abs(math.getArea(this.point2dInfo.points2d));//this.getArea();
  65981. }else {//mulDistance Ring 2d面
  65982. area = Math.abs(math.getArea(this.points));
  65983. }
  65984. let msg = this.getConvertString(area, 'area');
  65985. //let msg = viewer.unitConvert.convert(area, 'area', Potree.settings.precision, this.unitSystem/* , 0.1 */ )
  65986. this.area = {value:area, string:msg};
  65987. return this.area
  65988. }
  65989. getConvertString(num, type){
  65990. return viewer.unitConvert.convert(num, type, Potree.settings.precision, this.unitSystem, true ,
  65991. {
  65992. 'imperial': {minFactor: 0.01 },
  65993. 'metric': {minFactor: 0.01}
  65994. }
  65995. )
  65996. }
  65997. ifShowTotalDis(){
  65998. let show = this.points.length > 2;
  65999. if(show){
  66000. let maxDis = 0.15;
  66001. let lastIndex = this.points.length - 1;
  66002. for(let i=0;i<lastIndex;i++){
  66003. let len = this.edges[i].distance_;
  66004. if(len > maxDis){
  66005. show = false; break;
  66006. }
  66007. }
  66008. }
  66009. this.showTotalDis = show;
  66010. /* 连续测量:
  66011. 1. ≥2次测量,单个距离<15cm时,居中显示总长, hover、选中时显示每段长度
  66012. 2. 若连续测量的线段中,大于等于1段超出15cm,所有线段均显示长度
  66013. -------------------
  66014. */
  66015. }
  66016. clearEdgeLabelVisi(){//修改点位置后清空,下次render时会自动getEdgeLabelVisi
  66017. let lastIndex = this.points.length - 1;
  66018. for (let index = 0; index <= lastIndex; index++) {
  66019. if(!this.closed && index == lastIndex)continue
  66020. let edgeLabel = this.edgeLabels[index];
  66021. edgeLabel.visiMap.clear();
  66022. }
  66023. }
  66024. getEdgeLabelVisi(viewport){//获取多折线的edgelabel在不同视图里的可见性。要保证任何时候label能出现的线最小二维长度一致
  66025. let camera = viewport.camera;
  66026. let lastIndex = this.points.length - 1;
  66027. /* let pos2ds = this.points.map(point=> point.clone().project(camera) ) //即使只是旋转也会变动,尤其是转到屏幕外后变为显示。所以不用这种
  66028. let minDis = 0.01; */
  66029. let minDis = 0.02 , minAngleRatio = 0.07, minAngle;
  66030. let vecs;
  66031. let forceShow;
  66032. if(camera.type == 'OrthographicCamera'){
  66033. minDis *= Math.pow(camera.top / camera.zoom, 2);
  66034. //console.log(minDis)
  66035. }else {
  66036. if(Potree.settings.displayMode == 'showPanos' && viewer.images360.zoomLevel == Potree.settings.zoom.max){
  66037. forceShow = true; //当zoom到最大时强制显示,避免有的线太短永远显示不出长度
  66038. }else {
  66039. vecs = this.points.map(point=> new Vector3().subVectors(point, camera.position).normalize());
  66040. minAngleRatio /= viewport.resolution.y / 1000 / textSizeRatio; //角度占fov最小比率
  66041. minAngle = minAngleRatio * MathUtils.degToRad(camera.fov);
  66042. }
  66043. }
  66044. for (let index = 0; index <= lastIndex; index++) {
  66045. if(!this.closed && index == lastIndex)continue
  66046. let edgeLabel = this.edgeLabels[index];
  66047. let nextIndex = (index + 1 > lastIndex) ? 0 : index + 1;
  66048. let previousIndex = (index === 0) ? lastIndex : index - 1;
  66049. let point = this.points[index];
  66050. let nextPoint = this.points[nextIndex];
  66051. /* let point2d = pos2ds[index];
  66052. let nextPoint2d = pos2ds[nextIndex];
  66053. let dis2d = point2d.distanceToSquared(nextPoint2d)
  66054. let v = dis2d > minDis //可见长度太小,为避免拥挤,不显示
  66055. edgeLabel.visiMap.set(camera, v) */
  66056. let v;
  66057. if(forceShow){
  66058. v = true;
  66059. }else if(camera.type == 'OrthographicCamera'){
  66060. let vec = new Vector3().subVectors(point,nextPoint);
  66061. let projVec = vec.projectOnPlane(viewport.view.direction);
  66062. v = projVec.lengthSq() > minDis;
  66063. }else {
  66064. let vec0 = vecs[index];
  66065. let vec1 = vecs[nextIndex];
  66066. v = Math.acos(vec0.dot(vec1)) > minAngle; //角度过小代表可见长度太小,为避免拥挤,不显示
  66067. }
  66068. edgeLabel.visiMap.set(camera, v);
  66069. }
  66070. }
  66071. setEdgeLabelPos(label,p1,p2){ //调整label的位置,使倾斜后看起来在线的中心,而不要挡住端点
  66072. let center = new Vector3().addVectors(p1,p2).multiplyScalar(0.5);
  66073. return label.setPos(center)
  66074. if(label.lineDir && label.lineDir.length() > 0){
  66075. if(viewer.mainViewport.camera.type == 'OrthographicCamera'){
  66076. label.setPos(center);
  66077. }else {
  66078. //根据视线和线的夹角(后又加入相机和两个端点距离差)来决定标签偏移位置。+
  66079. let eyePos = viewer.mainViewport.camera.position;
  66080. let dir = viewer.mainViewport.view.direction; //new THREE.Vector3().subVectors(center,eyePos).normalize()
  66081. /*let centerDir = new THREE.Vector3().subVectors(center,eyePos).normalize()
  66082. if(centerDir.dot(dir)<0){//中点在相机后方,就不设置
  66083. label.setPos(center)
  66084. return
  66085. } */
  66086. let cos = dir.dot(label.lineDir);
  66087. let nearPoint = cos > 0 ? p2 : p1; //近端点。
  66088. let far = cos > 0 ? p1 : p2; //远端点。
  66089. let nearPointDir = new Vector3().subVectors(nearPoint,eyePos);//.normalize()
  66090. //使label在中点和近端点中变化, 近端点可能到了相机后方,需要投影到相机所在平面上
  66091. if(nearPointDir.dot(dir)<0){//近端点到了相机后方,前移。
  66092. //let hfov = cameraLight.getHFOVForCamera(viewer.mainViewport.camera , true ); //暂且只看水平fov
  66093. //if(nearPointDir.dot(dir)<Math.cos(hfov/2)){//近端点在镜头外,前移。 --但是这个就得把点转化成在镜头边缘而非左右两边(camDirPlane上)
  66094. let ray = new Raycaster();
  66095. ray.set(nearPoint, cos>0?label.lineDir:label.lineDir.clone().negate());
  66096. let camDirPlane = new Plane().setFromNormalAndCoplanarPoint(dir, eyePos);
  66097. nearPoint = ray.ray.intersectPlane(camDirPlane, new Vector3());
  66098. if(!nearPoint){//线是垂直的,视线是水平的时候
  66099. return label.setPos(center)
  66100. }
  66101. }
  66102. //防止离远了之后也偏移很多,但远了之后相机到端点vec和到中点的vec的夹角接近,不需要怎么偏移的。
  66103. let dis1 = nearPoint.distanceToSquared(eyePos);
  66104. let dis2 = far.distanceToSquared(eyePos);
  66105. let diff = Math.abs(dis1/dis2);
  66106. diff<1 && (diff = 1/diff);
  66107. diff = math.linearClamp(diff,[0, 30], [ 0,1 ]);
  66108. let efficiency = 0.7; // 0-1 数值越高,r越容易接近1或-1,label越容易在倾斜后靠近近端点。
  66109. //let r = 0.5*efficiency*cos + 0.5
  66110. let r = 0.5*efficiency*diff*cos + 0.5;
  66111. r = MathUtils.clamp(r,0.1,0.9);
  66112. //视线越接近线的方向,标签应该越往近端点偏移,防止看起来几乎在远端。
  66113. if(cos > 0){
  66114. center = p1.clone().multiplyScalar(1-r).add(nearPoint.clone().multiplyScalar(r)); //label在线上滑动,使尽量保持在视觉中心
  66115. }else {
  66116. center = nearPoint.clone().multiplyScalar(1-r).add(p2.clone().multiplyScalar(r)); //label在线上滑动,使尽量保持在视觉中心
  66117. }
  66118. label.setPos(center);
  66119. }
  66120. //归零
  66121. //this.orient2dInfo = null
  66122. //this.markers.forEach(e=>e.needsUpdate=true)
  66123. }else {
  66124. label.setPos(center);
  66125. }
  66126. }
  66127. cloneMarker(cloneIndex, index){
  66128. return this.addMarker({
  66129. index,
  66130. point: this.points[cloneIndex],
  66131. dataset_point:this.dataset_points && this.dataset_points[cloneIndex],
  66132. points_dataset:this.points_datasets[cloneIndex]
  66133. })
  66134. }
  66135. addMarker (o={}) {
  66136. var index = o.index == void 0 ? this.points.length : o.index; //要当第几个
  66137. let marker = new Sprite$2({mat:this.getMarkerMaterial('default'), sizeInfo: markerSizeInfo, name:"measure_point"} );
  66138. Potree.Utils.setObjectLayers(marker, 'measure' );
  66139. marker.pickOrder = marker.renderOrder = Potree.config.renderOrders.measureMarker;
  66140. marker.markerSelectStates = {};
  66141. marker.addEventListener('startDragging',(e)=>{
  66142. /* if(e.drag.dragViewport.name == 'MainView') */viewer.inputHandler.dispatchEvent( {type: 'measuring',v:true, cause:'startDragging', situation:'dragging', object:this});
  66143. //add for 调试,方便后期增加点
  66144. if(!this.isNew && viewer.inputHandler.pressedKeys['M'.charCodeAt(0)] && this.points.length<this.maxMarkers){
  66145. viewer.measuringTool.history.beforeChange(this);
  66146. let curIndex = this.markers.indexOf(marker);
  66147. this.cloneMarker(curIndex, curIndex+1);
  66148. }
  66149. this.isNew || viewer.measuringTool.history.beforeChange(this);
  66150. });
  66151. marker.addEventListener('drop',(e)=>{
  66152. if( e.button != MOUSE.LEFT )return
  66153. viewer.inputHandler.dispatchEvent({type: 'measuring', v:false, cause:'stopDragging', situation:'dragging', object:this} );
  66154. this.lastDropTime = Date.now();
  66155. if(Potree.settings.adsorption){
  66156. this.isNew || viewer.viewports.forEach((viewport)=>{
  66157. this.getPointsPos2d(viewport, true );//forceUpdate
  66158. });
  66159. }
  66160. this.isNew || viewer.measuringTool.history.afterChange(this);
  66161. });
  66162. marker.addEventListener('click',()=>{
  66163. if(viewer.measuringTool.editMode == 'delPoint' ){
  66164. /* if(this.points.length == this.minMarkers){//--前端去重绘
  66165. viewer.scene.removeMeasurement(this)
  66166. }else{ */
  66167. viewer.measuringTool.history.beforeChange(this);
  66168. let index = this.markers.indexOf(marker);
  66169. this.removeMarker(index);
  66170. viewer.measuringTool.history.afterChange(this);
  66171. this.dispatchEvent('changed');
  66172. //}
  66173. }
  66174. });
  66175. //marker.measure = this
  66176. let edge;
  66177. { // edges
  66178. edge = LineDraw.createFatLine( [ ],{mat:this.getLineMat('edgeDefault')} );
  66179. edge.pickOrder = 0;
  66180. Potree.Utils.setObjectLayers(edge, 'measure' );
  66181. let addHoverEvent = ()=>{ //当非isNew时才添加事件
  66182. let mouseover = (e) => {
  66183. /* if(this.measureType == 'MulDistance'){
  66184. } */
  66185. this.setSelected(true, 'edge');
  66186. };
  66187. let mouseleave = (e) => {
  66188. this.setSelected(false, 'edge');
  66189. };
  66190. edge.addEventListener('mouseover', mouseover);
  66191. edge.addEventListener('mouseleave', mouseleave);
  66192. edge.removeEventListener('addHoverEvent', addHoverEvent);
  66193. edge.addEventListener('click',(e)=>{
  66194. let now = Date.now();
  66195. if(now - this.lastDropTime<100)return ;//防止拖拽marker时误触导致focus, 以及点到marker不focus
  66196. if(viewer.measuringTool.editMode == 'addPoint' && this.points.length < this.maxMarkers){
  66197. viewer.measuringTool.history.beforeChange(this);
  66198. let index = this.edges.indexOf(edge) + 1;
  66199. let nextIndex = index % this.edges.length;
  66200. let point = math.getFootPoint(e.hoveredElement.point, this.points[index-1], this.points[nextIndex] );
  66201. this.addMarker({
  66202. index,
  66203. point,
  66204. dataset_point: this.dataset_points && new Vector3 , //初始化
  66205. points_dataset : this.points_datasets[index-1] //使用前一个的
  66206. });
  66207. this.updateDatasetBelong(index); //获取dataset_point
  66208. viewer.measuringTool.history.afterChange(this);
  66209. this.dispatchEvent('changed');
  66210. //this.update({})
  66211. }else {
  66212. this.isNew || viewer.measuringTool.isAdding || viewer.focusOnObject(this, 'measure'); //正在添加测量线时不要focus其他线(容易误触)
  66213. }
  66214. });
  66215. };
  66216. edge.addEventListener('addHoverEvent', addHoverEvent);
  66217. if(!this.isNew){
  66218. edge.dispatchEvent('addHoverEvent');
  66219. }
  66220. }
  66221. super.addMarker(Object.assign(o, {index, marker, edge}));
  66222. if(this.showEdges){ // edge labels
  66223. const edgeLabel = this.createEdgeLabel('edgeLabel', !this.closed);
  66224. this.edgeLabels = [...this.edgeLabels.slice(0,index), edgeLabel, ...this.edgeLabels.slice(index,this.edgeLabels.length)];
  66225. }
  66226. if(this.showCoordinates){ // coordinate labels
  66227. let coordinateLabel = new Label({
  66228. className:'measure_pointPos',
  66229. camera: viewer.scene.getActiveCamera()
  66230. });
  66231. coordinateLabel.setVisible(false);
  66232. this.coordinateLabels.push(coordinateLabel);
  66233. }
  66234. let event = {
  66235. type: 'marker_added',
  66236. measurement: this,
  66237. marker: marker
  66238. };
  66239. this.dispatchEvent(event);
  66240. //this.setMarker(this.points.length - 1, point);
  66241. this.update({index});//更新一下倒数第二条线
  66242. return marker;//add
  66243. };
  66244. editStateChange(state){ //主要针对edgeLabels显示切换,编辑时显示
  66245. super.editStateChange(state);
  66246. if(!state){
  66247. this.editStateTimer = setTimeout(()=>{
  66248. if(!this.isEditing){
  66249. this.dispatchEvent({type:'editStateChange',state:false});
  66250. this.setEdgesDisplay(false);
  66251. this.areaPlane && Potree.Utils.updateVisible(this.areaPlane, 'intersectLastLine', true);
  66252. this.areaLabel && Potree.Utils.updateVisible(this.areaLabel, 'intersectLastLine', true);
  66253. }
  66254. },100);
  66255. }else {
  66256. if(!this.isEditing){
  66257. this.dispatchEvent({type:'editStateChange',state:true});
  66258. this.setEdgesDisplay(true);
  66259. clearTimeout(this.editStateTimer);
  66260. }
  66261. }
  66262. this.isEditing = state;
  66263. }
  66264. setMarkerSelected(marker, state, hoverObject){
  66265. //console.warn(marker.id , state, hoverObject)
  66266. marker.markerSelectStates[hoverObject] = state;
  66267. let absoluteState = false;
  66268. for(var i in marker.markerSelectStates){
  66269. if(marker.markerSelectStates[i] == 'hover'){
  66270. absoluteState = true; break;
  66271. }
  66272. }
  66273. if(absoluteState){
  66274. marker.material = this.getMarkerMaterial('select');
  66275. marker.renderOrder = marker.pickOrder = Potree.config.renderOrders.measureMarker+1;
  66276. }else {
  66277. marker.material = this.getMarkerMaterial('default');
  66278. marker.renderOrder = marker.pickOrder = Potree.config.renderOrders.measureMarker;
  66279. }
  66280. marker.selected = absoluteState;
  66281. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed');
  66282. viewer.dispatchEvent('content_changed');
  66283. }
  66284. setEdgesDisplay(state, ignoreGuideLine){
  66285. this.closed && this.edgeLabels.forEach(e=>Utils.updateVisible(e,'hover',state));
  66286. if(this.totalDisLabel && !viewer.screenshoting){
  66287. this.edgeLabels.forEach(e=> Utils.updateVisible(e, 'hover', state, 1, state ? 'add' : 'cancel'));
  66288. Utils.updateVisible(this.totalDisLabel,'hover', !state );
  66289. }
  66290. if(!ignoreGuideLine && this.measureType == 'Distance'){
  66291. this.horEdgeLabel.visible = this.verEdgeLabel.visible = this.horGuideEdge.visible = this.verGuideEdge.visible = !!(state && this.shouldShowHorVerGuide);
  66292. }
  66293. }
  66294. setSelected(state, hoverObject){//add
  66295. //console.log('setSelected',state, hoverObject)
  66296. let absoluteState = !!state;
  66297. if(hoverObject){//如果没有hoverObject且state为false 就强制取消选中态
  66298. this.selectStates[hoverObject] = state;
  66299. for(var i in this.selectStates){
  66300. if(this.selectStates[i]){
  66301. absoluteState = true; break;
  66302. }
  66303. }
  66304. }
  66305. if(absoluteState){
  66306. this.markers.forEach(e=>this.setMarkerSelected(e, 'hover', 'selectAll' ) );
  66307. this.edges.forEach(e=>{
  66308. e.renderOrder = Potree.config.renderOrders.lines + 1;
  66309. e.material = this.getLineMat('edgeSelect');
  66310. });
  66311. this.areaPlane && (this.areaPlane.material = planeMats.selected);
  66312. //this.areaLabel && this.areaLabel.elem.addClass('highLight')
  66313. //this.closed || this.edgeLabels.forEach(e=>e.elem.addClass('highLight') )
  66314. this.setEdgesDisplay(true, hoverObject=="screenshot");
  66315. this.areaLabel && setLabelHightState(this.areaLabel, true);
  66316. this.closed || this.edgeLabels.forEach(e=>setLabelHightState(e, true) );
  66317. }else {
  66318. this.markers.forEach(e=>this.setMarkerSelected(e, 'unhover', 'selectAll' ));
  66319. this.edges.forEach(e=>e.material = this.getLineMat('edgeDefault') );
  66320. this.areaPlane && (this.areaPlane.material = planeMats.default);
  66321. this.setEdgesDisplay(false, hoverObject=="screenshot");
  66322. //this.areaLabel && this.areaLabel.elem.removeClass('highLight')
  66323. //this.closed || this.edgeLabels.forEach(e=>e.elem.removeClass('highLight') )
  66324. this.areaLabel && setLabelHightState(this.areaLabel, false);
  66325. this.closed || this.edgeLabels.forEach(e=>setLabelHightState(e, false) );
  66326. }
  66327. this.selected = absoluteState;
  66328. if(hoverObject != 'byList'){
  66329. //this.bus && this.bus.emit('highlight', this.selected)
  66330. this.dispatchEvent({type:'highlight',state:this.selected});//列表高亮
  66331. }
  66332. viewer.dispatchEvent('content_changed');
  66333. viewer.mapViewer && viewer.mapViewer.dispatchEvent('content_changed');
  66334. }
  66335. removeMarker(index ){
  66336. super.removeMarker(index);
  66337. this.points_datasets.splice(index, 1);
  66338. this.dataset_points && this.dataset_points.splice(index, 1);
  66339. this.coordinateLabels.splice(index, 1);
  66340. let edgeIndex = index;//(index === 0) ? 0 : (index - 1);
  66341. if(this.edgeLabels[edgeIndex]){
  66342. this.edgeLabels[edgeIndex].dispose();
  66343. this.edgeLabels.splice(edgeIndex, 1);
  66344. }
  66345. this.update({index: this.getIndex(index, -1)});
  66346. this.dispatchEvent({type: 'marker_removed', measurement: this});
  66347. }
  66348. setPosition(index, position) {
  66349. super.setPosition(index, position);
  66350. let event = {
  66351. type: 'marker_moved',
  66352. measure: this,
  66353. index: index,
  66354. position: position.clone()
  66355. };
  66356. this.dispatchEvent(event);
  66357. }
  66358. dispose(){//add
  66359. var labels = this.edgeLabels.concat(this.coordinateLabels);
  66360. this.areaLabel && labels.push(this.areaLabel);
  66361. labels.forEach(e=>e.dispose());
  66362. super.dispose();
  66363. this.dispatchEvent('disposed');
  66364. }
  66365. getTotalDistance () {
  66366. if (this.points.length === 0) {
  66367. return 0;
  66368. }
  66369. let distance = 0;
  66370. for (let i = 1; i < this.points.length; i++) {
  66371. let prev = this.points[i - 1];
  66372. let curr = this.points[i];
  66373. let d = prev.distanceTo(curr);
  66374. distance += d;
  66375. }
  66376. if (this.closed && this.points.length > 1) {
  66377. let first = this.points[0];
  66378. let last = this.points[this.points.length - 1];
  66379. let d = last.distanceTo(first);
  66380. distance += d;
  66381. }
  66382. return distance;
  66383. }
  66384. getAngleBetweenLines (cornerPoint, point1, point2) {
  66385. let v1 = new Vector3().subVectors(point1, cornerPoint);
  66386. let v2 = new Vector3().subVectors(point2, cornerPoint);
  66387. // avoid the error printed by threejs if denominator is 0
  66388. const denominator = Math.sqrt( v1.lengthSq() * v2.lengthSq() );
  66389. if(denominator === 0){
  66390. return 0;
  66391. }else {
  66392. return v1.angleTo(v2);
  66393. }
  66394. };
  66395. getAngle (index) {
  66396. if (this.points.length < 3 || index >= this.points.length) {
  66397. return 0;
  66398. }
  66399. let previous = (index === 0) ? this.points[this.points.length - 1] : this.points[index - 1];
  66400. let point = this.points[index];
  66401. let next = this.points[(index + 1) % (this.points.length)];
  66402. return this.getAngleBetweenLines(point, previous, next);
  66403. }
  66404. getCenter(type){
  66405. if(this.center){
  66406. return this.center.clone()
  66407. }else {
  66408. let center = this.points.reduce(function(total, currentValue ){
  66409. return total.add(currentValue)
  66410. }, new Vector3 );
  66411. this.points.length && center.multiplyScalar(1/this.points.length);
  66412. return center //求不出重心呜呜
  66413. }
  66414. }
  66415. // updateAzimuth(){
  66416. // // if(this.points.length !== 2){
  66417. // // return;
  66418. // // }
  66419. // // const azimuth = this.azimuth;
  66420. // // const [p0, p1] = this.points;
  66421. // // const r = p0.distanceTo(p1);
  66422. // }
  66423. createGuideLine(){//add 辅助线
  66424. var guideLine = LineDraw.createFatLine([ ],{mat:this.getLineMat('guide')} );
  66425. guideLine.visible = false;
  66426. this.guideLine = guideLine;
  66427. this.add(guideLine);
  66428. }
  66429. createHorVerGuideLine(){//创建水平与垂直辅助线,仅距离测量有。
  66430. var verGuideEdge = LineDraw.createFatLine([ ],{mat:this.getLineMat('guide')} );
  66431. verGuideEdge.visible = false;
  66432. this.verGuideEdge = verGuideEdge;
  66433. verGuideEdge.name = 'verGuideEdge';
  66434. var horGuideEdge = LineDraw.createFatLine([ ],{mat:this.getLineMat('guide')} );
  66435. horGuideEdge.visible = false;
  66436. horGuideEdge.name = 'horGuideEdge';
  66437. this.horGuideEdge = horGuideEdge;
  66438. this.add(this.verGuideEdge);
  66439. this.add(this.horGuideEdge);
  66440. //label:
  66441. this.verEdgeLabel = this.createEdgeLabel('verGuideEdge');
  66442. this.horEdgeLabel = this.createEdgeLabel('horGuideEdge');
  66443. }
  66444. createEdgeLabel(name, hasHoverEvent){
  66445. let inf = {
  66446. sizeInfo: labelSizeInfo, name:name||'edgeLabel',
  66447. };
  66448. if(name && name.includes('Guide')){
  66449. inf.fontsize = 12;
  66450. }
  66451. const edgeLabel = new TextSprite$2(
  66452. $.extend({}, hasHoverEvent ? mainLabelProp : subLabelProp, inf)
  66453. );
  66454. if(hasHoverEvent){
  66455. edgeLabel.addEventListener('mouseover',()=>{
  66456. this.setSelected(true, 'edgeLabel');
  66457. });
  66458. edgeLabel.addEventListener('mouseleave',()=>{
  66459. this.setSelected(false, 'edgeLabel');
  66460. });
  66461. edgeLabel.addEventListener('click',()=>{
  66462. this.isNew || viewer.measuringTool.isAdding || viewer.focusOnObject(this, 'measure');
  66463. });
  66464. }
  66465. edgeLabel.visible = false;
  66466. edgeLabel.measure = this;
  66467. edgeLabel.sprite.material.depthTestWhenPick = true;
  66468. Potree.Utils.setObjectLayers(edgeLabel, 'measure' );
  66469. this.add(edgeLabel);
  66470. if(this.measureType == 'MulDistance'){
  66471. edgeLabel.visiMap = new Map();
  66472. }
  66473. return edgeLabel
  66474. }
  66475. createAreaLabel(){
  66476. const areaLabel = this.createCenterLabel('areaLabel');
  66477. return areaLabel;
  66478. }
  66479. createTotalDisLabel(){
  66480. const totalDisLabel = this.createCenterLabel('totalDisLabel');
  66481. return totalDisLabel;
  66482. }
  66483. createCenterLabel(name){
  66484. const centerLabel = new TextSprite$2(
  66485. $.extend({},mainLabelProp,{sizeInfo: labelSizeInfo, name, disToLine:0, fontsize:16*textSizeRatio} )
  66486. );
  66487. centerLabel.addEventListener('mouseover',()=>{
  66488. this.isNew || this.setSelected(true, 'centerLabel');
  66489. });
  66490. centerLabel.addEventListener('mouseleave',()=>{
  66491. this.isNew || this.setSelected(false, 'centerLabel');
  66492. });
  66493. centerLabel.addEventListener('click',()=>{
  66494. this.isNew || viewer.measuringTool.isAdding || viewer.focusOnObject(this, 'measure');
  66495. });
  66496. Potree.Utils.setObjectLayers(centerLabel, 'measure' );
  66497. Utils.updateVisible(centerLabel, 'setVisible', false);
  66498. return centerLabel;
  66499. }
  66500. getMarkerMaterial(type) {
  66501. if(!markerMats){
  66502. markerMats = {
  66503. default: new DepthBasicMaterial($.extend({},lineDepthInfo,{
  66504. transparent: !0,
  66505. opacity: 1,
  66506. map: texLoader$6.load(Potree.resourcePath+'/textures/pic_point_s32.png' ),
  66507. useDepth:true ,
  66508. mapScale: markerMapShrink
  66509. })),
  66510. select: new MeshBasicMaterial({
  66511. transparent: !0,
  66512. opacity: 1,
  66513. depthTest:false,
  66514. map: texLoader$6.load(Potree.resourcePath+'/textures/pic_point32.png'/* , null, null, { antialias: false } */),
  66515. }),
  66516. };
  66517. Measure$1.markerMats = markerMats;
  66518. markerMats.select.map.repeat.set(1/markerMapShrink,1/markerMapShrink);
  66519. markerMats.select.map.offset.set((markerMapShrink-1)/2/markerMapShrink, (markerMapShrink-1)/2/markerMapShrink);
  66520. //markerMats.select.map.offset.set( -1.1 , -1.1 )
  66521. }
  66522. return markerMats[type]
  66523. }
  66524. getLineMat(type) {
  66525. if(!Measure$1.lineMats){
  66526. Measure$1.lineMats = {
  66527. edgeDefault: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
  66528. color: config$1.measure.default.color,
  66529. lineWidth: config$1.measure.lineWidth,
  66530. useDepth :true,
  66531. dashWithDepth :true, // 只在被遮住的部分显示虚线,因为实线容易挡住label
  66532. dashed :true,
  66533. dashSize : 0.04,
  66534. gapSize: 0.04,
  66535. transparent: true,
  66536. opacity: config$1.measure.default.opacity,
  66537. depthTestWhenPick:true,
  66538. })),
  66539. edgeSelect: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
  66540. color: config$1.measure.highlight.color,//'#f0ff00',
  66541. dashSize: 0.5,
  66542. gapSize: 0.2,
  66543. lineWidth: config$1.measure.lineWidth ,
  66544. transparent: true,
  66545. opacity: config$1.measure.highlight.opacity
  66546. })),
  66547. guide: LineDraw.createFatLineMat($.extend({},lineDepthInfo,{
  66548. color:config$1.measure.guide.color,
  66549. dashSize: 0.1,
  66550. gapSize: 0.02,
  66551. dashed: true,
  66552. lineWidth: config$1.measure.lineWidth/2
  66553. })),
  66554. };
  66555. }
  66556. return Measure$1.lineMats[type]
  66557. }
  66558. createAreaPlane(){
  66559. planeMats || (planeMats = {
  66560. default: new DepthBasicMaterial( $.extend({},lineDepthInfo,{
  66561. color:color,
  66562. side:DoubleSide,
  66563. opacity:0.2,
  66564. transparent:true,
  66565. useDepth:true,
  66566. })),
  66567. selected: new MeshBasicMaterial({
  66568. color: color ,
  66569. side:DoubleSide,
  66570. opacity:0.3,
  66571. transparent:true,
  66572. //wireframe:true
  66573. })
  66574. },Measure$1.planeMats = planeMats);
  66575. return super.createAreaPlane(planeMats.default)
  66576. }
  66577. raycast (raycaster, intersects) {
  66578. for (let i = 0; i < this.points.length; i++) {
  66579. let marker = this.markers[i];
  66580. marker.raycast(raycaster, intersects);
  66581. }
  66582. // recalculate distances because they are not necessarely correct
  66583. // for scaled objects.
  66584. // see https://github.com/mrdoob/three.js/issues/5827
  66585. // TODO: remove this once the bug has been fixed
  66586. for (let i = 0; i < intersects.length; i++) {
  66587. let I = intersects[i];
  66588. I.distance = raycaster.ray.origin.distanceTo(I.point);
  66589. }
  66590. intersects.sort(function (a, b) { return a.distance - b.distance; });
  66591. };
  66592. getPointsPos2d(viewport, update){//获取屏幕上的二维坐标
  66593. let ps = this.pointsPos2d.get(viewport);
  66594. if(update || !ps){
  66595. let points = this.points.map(e=>{
  66596. let p = Potree.Utils.getPos2d(e, viewport, viewer.renderArea );
  66597. p.pos3d = e.clone(), p.object = this;
  66598. return p
  66599. });
  66600. this.pointsPos2d.set(viewport, points);
  66601. console.log('updatePointsPos2d',this.uuid,viewport.name);
  66602. }
  66603. return this.pointsPos2d.get(viewport)
  66604. }
  66605. transformData(prop){
  66606. if(prop.measureType == 'Point'){
  66607. prop.showCoordinates = true,
  66608. prop.closed = true,
  66609. prop.maxMarkers = 1,
  66610. prop.minMarkers = 1;
  66611. }else if(prop.measureType == 'Distance'){
  66612. prop.showDistances = true,
  66613. prop.showEdges = true,
  66614. prop.maxMarkers = 2,
  66615. prop.minMarkers = 2;
  66616. }else if(prop.measureType == 'MulDistance'){
  66617. prop.showDistances = true,
  66618. prop.showEdges = true,
  66619. prop.minMarkers = 2;
  66620. }else if(prop.measureType == 'MulDistance Ring'){
  66621. prop.showDistances = true,
  66622. prop.showEdges = true,
  66623. prop.showArea = true,
  66624. prop.closed = true,
  66625. prop.minMarkers = 3;
  66626. }else if(prop.measureType == 'Ver MulDistance'){
  66627. prop.showDistances = true,
  66628. prop.atPlane = true,
  66629. prop.showEdges = true,
  66630. prop.minMarkers = 2;
  66631. prop.faceDirection = "vertical";
  66632. prop.unableDragAtMap = true;
  66633. }else if(prop.measureType == 'Hor MulDistance'){
  66634. prop.showDistances = true,
  66635. prop.atPlane = true,
  66636. prop.showEdges = true,
  66637. prop.minMarkers = 2;
  66638. prop.faceDirection = "horizontal";
  66639. }else if(prop.measureType == 'Ver Distance'){
  66640. prop.showDistances = true,
  66641. prop.showEdges = true,
  66642. prop.maxMarkers = 2,
  66643. prop.minMarkers = 2,
  66644. prop.faceDirection = "vertical";
  66645. prop.unableDragAtMap = true;
  66646. }else if(prop.measureType == 'Hor Distance'){
  66647. prop.showDistances = true,
  66648. prop.showEdges = true,
  66649. prop.maxMarkers = 2,
  66650. prop.minMarkers = 2,
  66651. prop.faceDirection = "horizontal";
  66652. }else if(prop.measureType == 'Area'){
  66653. prop.showDistances = true,
  66654. Potree.settings.areaAtNotPlane || (prop.atPlane = true);
  66655. prop.showEdges = true,
  66656. prop.closed = true,
  66657. prop.minMarkers = 3;
  66658. }else if(prop.measureType == 'Hor Area'){
  66659. prop.showDistances = true,
  66660. prop.atPlane = true,
  66661. prop.showEdges = true,
  66662. prop.closed = true,
  66663. prop.minMarkers = 3;
  66664. prop.faceDirection = "horizontal";
  66665. }else if(prop.measureType == 'Ver Area'){
  66666. prop.showDistances = true,
  66667. prop.atPlane = true,
  66668. prop.showEdges = true,
  66669. prop.closed = true,
  66670. prop.minMarkers = 3;
  66671. prop.faceDirection = "vertical";
  66672. prop.unableDragAtMap = true;
  66673. }else if(prop.measureType == 'Rect Area'){
  66674. prop.showDistances = true,
  66675. prop.atPlane = true,
  66676. prop.showEdges = true,
  66677. prop.closed = true,
  66678. prop.minMarkers = 4;
  66679. prop.maxMarkers = 4;
  66680. }else if(prop.measureType == 'Hor Rect Area'){
  66681. prop.showDistances = true,
  66682. prop.atPlane = true,
  66683. prop.showEdges = true,
  66684. prop.closed = true,
  66685. prop.minMarkers = 4;
  66686. prop.maxMarkers = 4;
  66687. prop.isRect = true;
  66688. prop.faceDirection = "horizontal";
  66689. }else if(prop.measureType == 'Ver Rect Area'){
  66690. prop.showDistances = true,
  66691. prop.atPlane = true,
  66692. prop.showEdges = true,
  66693. prop.closed = true,
  66694. prop.minMarkers = 4;
  66695. prop.maxMarkers = 4;
  66696. prop.isRect = true;
  66697. prop.faceDirection = "vertical";
  66698. prop.unableDragAtMap = true;
  66699. }
  66700. if(prop.atPlane && prop.closed){ //atPlane在同一平面上
  66701. prop.showArea = true;
  66702. }
  66703. super.transformData(prop);
  66704. }
  66705. setUnitSystem(unitSystem){
  66706. //console.log(this.name +':' +this.unitSystem)
  66707. if(unitSystem != this.unitSystem){
  66708. if(unitSystem == "metric"){
  66709. }else if(unitSystem == 'imperial'){
  66710. }
  66711. this.unitSystem = unitSystem;
  66712. this.update();
  66713. }
  66714. }
  66715. reDraw(restMarkerCount=0){//重新开始画
  66716. super.reDraw(restMarkerCount);
  66717. if(this.measureType == 'Distance'){
  66718. this.shouldShowHorVerGuide = false;
  66719. this.setEdgesDisplay(false);
  66720. }
  66721. if(this.showArea){
  66722. this.area = {value:0};
  66723. this.areaLabel && Utils.updateVisible(this.areaLabel, 'setVisible', false );
  66724. }
  66725. if(this.totalDisLabel && this.showTotalDis){
  66726. Utils.updateVisible(this.totalDisLabel, 'setVisible', false );
  66727. }
  66728. viewer.inputHandler.dispatchEvent( {type:'measuring', v:true, cause:'reDraw',object:this, situation:'dragging'} );
  66729. }
  66730. }
  66731. function setLabelHightState(label, state){
  66732. if(state){
  66733. let color = new Color(Potree.config.measure.highlight.color);
  66734. //label.sprite.material.opacity = config.measure.highlight.opacity
  66735. //label.setBackgroundColor({r:255*color.r, g:255*color.g, b:255*color.b, a:config.measure.highlight.opacity})
  66736. label.sprite.material.useDepth = false;
  66737. //label.textColor = {r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a: 1}
  66738. }else {
  66739. //label.setBackgroundColor({r: this.color.r*255, g: this.color.g*255, b: this.color.b*255, a:config.measure.default.opacity})
  66740. label.sprite.material.useDepth = true;
  66741. //label.sprite.material.opacity = 0.98
  66742. //label.textColor = {r: 255, g: 255, b: 255, a: 1}
  66743. }
  66744. label.updateTexture();
  66745. }
  66746. /* function setLabelHightState(label, state){
  66747. if(state){
  66748. label.setBackgroundColor({r: highlightColor.r*255, g: highlightColor.g*255, b: highlightColor.b*255, a:config.measure.highlight.labelOpacity})
  66749. label.sprite.material.useDepth = false;
  66750. }else{
  66751. label.setBackgroundColor(mainLabelProp.backgroundColor)
  66752. label.sprite.material.useDepth = true
  66753. }
  66754. label.updateTexture()
  66755. //label.sprite.material.needsUpdate = true
  66756. }
  66757. */
  66758. function createCircleRadiusLabel$1(){
  66759. const circleRadiusLabel = new TextSprite$2("");
  66760. circleRadiusLabel.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  66761. circleRadiusLabel.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  66762. circleRadiusLabel.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  66763. circleRadiusLabel.fontsize = 16;
  66764. circleRadiusLabel.material.depthTest = false;
  66765. circleRadiusLabel.material.opacity = 1;
  66766. circleRadiusLabel.visible = false;
  66767. return circleRadiusLabel;
  66768. }
  66769. function createCircleRadiusLine$1(){
  66770. /* const lineGeometry = new LineGeometry();
  66771. lineGeometry.setPositions([
  66772. 0, 0, 0,
  66773. 0, 0, 0,
  66774. ]);
  66775. const lineMaterial = new LineMaterial({
  66776. color: 0xff0000,
  66777. lineWidth: 2,
  66778. resolution: new THREE.Vector2(1000, 1000),
  66779. gapSize: 1,
  66780. dashed: true,
  66781. });
  66782. lineMaterial.depthTest = false;
  66783. const circleRadiusLine = new Line2(lineGeometry, lineMaterial);*/
  66784. var circleRadiusLine = LineDraw.createFatLine([ ],{
  66785. color:0xff0000,
  66786. dashSize: 0.5,
  66787. gapSize: 0.2,
  66788. lineWidth: config$1.measure.lineWidth
  66789. });
  66790. circleRadiusLine.visible = false;
  66791. return circleRadiusLine;
  66792. }
  66793. function createCircleLine$1(){
  66794. const coordinates = [];
  66795. let n = 128;
  66796. for(let i = 0; i <= n; i++){
  66797. let u0 = 2 * Math.PI * (i / n);
  66798. let u1 = 2 * Math.PI * (i + 1) / n;
  66799. let p0 = new Vector3(
  66800. Math.cos(u0),
  66801. Math.sin(u0),
  66802. 0
  66803. );
  66804. let p1 = new Vector3(
  66805. Math.cos(u1),
  66806. Math.sin(u1),
  66807. 0
  66808. );
  66809. coordinates.push(
  66810. p0,
  66811. p1
  66812. );
  66813. }
  66814. /* const geometry = new LineGeometry();
  66815. geometry.setPositions(coordinates);
  66816. const material = new LineMaterial({
  66817. color: 0xff0000,
  66818. dashSize: 5,
  66819. gapSize: 2,
  66820. lineWidth: 2,
  66821. resolution: new THREE.Vector2(1000, 1000),
  66822. });
  66823. material.depthTest = false;
  66824. const circleLine = new Line2(geometry, material);
  66825. circleLine.visible = false;
  66826. circleLine.computeLineDistances();*/
  66827. var circleLine = LineDraw.createFatLine(coordinates,{
  66828. color: 0xff0000,
  66829. dashSize: 0.5,
  66830. gapSize: 0.2,
  66831. lineWidth: config$1.measure.lineWidth
  66832. });
  66833. return circleLine;
  66834. }
  66835. /* function createCircleCenter(){
  66836. const sg = new THREE.markerGeometry(1, 32, 32);
  66837. const sm = new THREE.MeshNormalMaterial();
  66838. const circleCenter = new THREE.Mesh(sg, sm);
  66839. circleCenter.visible = false;
  66840. return circleCenter;
  66841. } */
  66842. function createLine$1(){
  66843. const line = LineDraw.createFatLine([ ],{
  66844. color: 0xff0000,
  66845. dashSize: 0.5,
  66846. gapSize: 0.2,
  66847. lineWidth: config$1.measure.lineWidth
  66848. });
  66849. return line;
  66850. }
  66851. function createCircle$1(){
  66852. const coordinates = [];
  66853. let n = 128;
  66854. for(let i = 0; i <= n; i++){
  66855. let u0 = 2 * Math.PI * (i / n);
  66856. let u1 = 2 * Math.PI * (i + 1) / n;
  66857. let p0 = new Vector3(
  66858. Math.cos(u0),
  66859. Math.sin(u0),
  66860. 0
  66861. );
  66862. let p1 = new Vector3(
  66863. Math.cos(u1),
  66864. Math.sin(u1),
  66865. 0
  66866. );
  66867. coordinates.push(
  66868. p0,
  66869. p1
  66870. );
  66871. }
  66872. var line = LineDraw.createFatLine(coordinates,{
  66873. color: 0xff0000,
  66874. dashSize: 0.5,
  66875. gapSize: 0.2,
  66876. lineWidth: config$1.measure.lineWidth
  66877. });
  66878. return line;
  66879. }
  66880. /* function createAzimuth(){
  66881. const azimuth = {
  66882. label: null,
  66883. center: null,
  66884. target: null,
  66885. north: null,
  66886. centerToNorth: null,
  66887. centerToTarget: null,
  66888. centerToTargetground: null,
  66889. targetgroundToTarget: null,
  66890. circle: null,
  66891. node: null,
  66892. };
  66893. const sg = new THREE.markerGeometry(1, 32, 32);
  66894. const sm = new THREE.MeshNormalMaterial();
  66895. {
  66896. const label = new TextSprite("");
  66897. label.setTextColor({r: 140, g: 250, b: 140, a: 1.0});
  66898. label.setBorderColor({r: 0, g: 0, b: 0, a: 1.0});
  66899. label.setBackgroundColor({r: 0, g: 0, b: 0, a: 1.0});
  66900. label.fontsize = 16;
  66901. label.material.depthTest = false;
  66902. label.material.opacity = 1;
  66903. azimuth.label = label;
  66904. }
  66905. azimuth.center = new THREE.Mesh(sg, sm);
  66906. azimuth.target = new THREE.Mesh(sg, sm);
  66907. azimuth.north = new THREE.Mesh(sg, sm);
  66908. azimuth.centerToNorth = createLine();
  66909. azimuth.centerToTarget = createLine();
  66910. azimuth.centerToTargetground = createLine();
  66911. azimuth.targetgroundToTarget = createLine();
  66912. azimuth.circle = createCircle();
  66913. azimuth.node = new THREE.Object3D();
  66914. azimuth.node.add(
  66915. azimuth.centerToNorth,
  66916. azimuth.centerToTarget,
  66917. azimuth.centerToTargetground,
  66918. azimuth.targetgroundToTarget,
  66919. azimuth.circle,
  66920. azimuth.label,
  66921. azimuth.center,
  66922. azimuth.target,
  66923. azimuth.north,
  66924. );
  66925. return azimuth;
  66926. } */
  66927. /*
  66928. 按alt鼠标滚轮或WS键放慢。
  66929. 按Alt键可以平行屏幕拖拽点。&dragPolyBeyondPoint 后缀在拖拽到无点云区域也是此效果。
  66930. 按M键拖拽点可以复制出当前点
  66931. */
  66932. class History extends EventDispatcher{
  66933. constructor(o){
  66934. super();
  66935. this.undoList = [];
  66936. this.redoList = [];
  66937. this.applyData = o.applyData; //应用数据的方法
  66938. this.getData = o.getData; //获取数据的方法
  66939. this.dataBefore
  66940. ;(o.viewer || viewer).inputHandler.addEventListener('keydown', (e)=>{
  66941. if(e.keyCode == 90 && e.event.ctrlKey){//Z
  66942. this.undo();
  66943. }else if(e.keyCode == 89 && e.event.ctrlKey){//Y
  66944. this.redo();
  66945. }
  66946. });
  66947. }
  66948. undo(){//回退
  66949. let length = this.undoList.length;
  66950. if(length>0){
  66951. let unExist;
  66952. let last = this.undoList.pop();
  66953. this.applyData && (unExist = !this.applyData(last.before));
  66954. unExist || this.redoList.push(last);
  66955. unExist && this.undo();//找不到就回退下一个。
  66956. this.dispatchEvent('undo');
  66957. //console.log('undo',last)
  66958. }
  66959. }
  66960. redo(){//撤销回退
  66961. let length = this.undoList.length;
  66962. let last = this.redoList.pop();
  66963. if(last){
  66964. //注意:每行的顺序不能乱
  66965. this.undoList.push(last);
  66966. this.applyData && this.applyData(last.after);
  66967. this.dispatchEvent('redo');
  66968. //console.log('redo',last)
  66969. }
  66970. }
  66971. beforeChange(o){//在变化之前(可能执行好几次直到变化完,但只有第一次有效)。 o的内容完全根据getData怎么定义
  66972. if(!this.dataBefore){
  66973. let data = this.getData(o);
  66974. data && (this.dataBefore = data);
  66975. }
  66976. }
  66977. afterChange(o){//变化结束,从beforeChange到此算一次操作。
  66978. if(this.dataBefore){
  66979. this.writeIn({before:this.dataBefore, after:this.getData(o)} ); //写入某物体变化前和变化后的状态
  66980. this.dataBefore = null;
  66981. }
  66982. }
  66983. writeIn(data ){
  66984. this.redoList.length = 0; //一旦录入新的操作,就不允许undo了
  66985. this.undoList.push(data );
  66986. //console.log('新增undo', data)
  66987. }
  66988. clear(){
  66989. this.redoList.length = 0;
  66990. this.undoList.length = 0;
  66991. this.dataBefore = null;
  66992. }
  66993. }
  66994. let areaPlaneMats = {
  66995. };
  66996. class Prism extends Measure$1{
  66997. constructor(args){
  66998. super(args);
  66999. this.isPrism = true;
  67000. this.volumeInfo = {};
  67001. this.needsCompute = true;
  67002. /*this.createPrismLines(new THREE.Color('#FFF') )
  67003. this.lineMesh.material.transparent = true
  67004. this.lineMesh.material.opacity = 0.5
  67005. Potree.Utils.setObjectLayers(this.lineMesh, 'measure' ) */
  67006. this.setClipBox();
  67007. this.setTopOrBtm('zMin');
  67008. this.setTopOrBtm('zMax');
  67009. this.setHorizonHeight('btm');
  67010. let update =()=>{
  67011. this.setHorizonHeight(this.horizonType, true);//更新
  67012. this.needsCompute = true;
  67013. this.getBound();
  67014. this.dispatchEvent('updated');
  67015. };
  67016. this.addEventListener('marker_dropped'/* 'marker_moved' */,update);
  67017. this.addEventListener('changeByHistory',update);
  67018. this.addEventListener('changed',update);
  67019. /* this.addEventListener('createDone',()=>{
  67020. this.setHorizonHeight()//更新
  67021. this.updateAreaPlane()
  67022. }) */
  67023. this.updateAreaPlane();
  67024. this.getBound();
  67025. this.addEventListener('needsCompute',()=>{
  67026. this.needsCompute = true;
  67027. },10);
  67028. //Potree.Utils.setObjectLayers(this.lineMesh, 'bothMapAndScene' )
  67029. }
  67030. set needsCompute(state){
  67031. if(state == 'byVolume'){
  67032. this.needsCompute_ = this.volumeInfo.Vupper == void 0;
  67033. }else {
  67034. this.needsCompute_ = !!state;
  67035. //console.error('needsCompute', state)
  67036. }
  67037. }
  67038. get needsCompute(){
  67039. return this.needsCompute_
  67040. }
  67041. setHorizonHeight(v){
  67042. let old = this.horizonZ;
  67043. if(typeof v == 'number'){
  67044. this.horizonType = 'number';
  67045. this.horizonZ = v;
  67046. }else {
  67047. if(v){
  67048. this.horizonType = v;
  67049. }
  67050. if(!this.horizonType) this.horizonType = 'btm';
  67051. if(this.horizonType == 'number')return
  67052. let zs = this.points.map(p=>p.z).sort((a,b)=>a-b);
  67053. this.horizonZ = this.horizonType == 'btm' ? zs[0] : zs[this.points.length-1];
  67054. }
  67055. //this.horizonZ = THREE.Math.clamp(this.horizonZ, this.zMin, this.zMax )
  67056. if(this.horizonZ != old ){
  67057. this.needsCompute = true;
  67058. this.update(); //update areaPlane and areaLabel pos
  67059. this.dispatchEvent('horizonZChanged');
  67060. }
  67061. //console.log(this.horizonZ)
  67062. }
  67063. setBaseModel(model, modelHaventLoad){//三种状态:使用model、使用基准高度、 什么都没有(不允许计算、不高亮、等待模型上传)
  67064. this.baseModel = model;
  67065. this.modelHaventLoad = modelHaventLoad;
  67066. Potree.Utils.updateVisible(this.areaPlane,'unuseHorizonH',!model && !modelHaventLoad);
  67067. }
  67068. setClipBox(boxes){//clipBoxes_out
  67069. this.clipBoxes = boxes || [];
  67070. }
  67071. setTopOrBtm(name,v){
  67072. if(v != void 0 ){
  67073. this[name] = v;
  67074. this.updatePrismLines();
  67075. }else {
  67076. this[name] = viewer.bound.boundingBox[name == 'zMin' ? 'min' : 'max'].z;
  67077. }
  67078. this.getBound();
  67079. this.needsCompute = true;
  67080. }
  67081. getBound(){
  67082. let bound = Potree.math.getBound(this.points);
  67083. bound.min.z = this.zMin;
  67084. bound.max.z = this.zMax;
  67085. this.prismBound = bound;
  67086. }
  67087. setVolumeInfo(volumeInfo){
  67088. this.volumeInfo = volumeInfo;
  67089. this.getVolumeString();
  67090. this.needsCompute = false; //但得到的不一定是对的可能 检查下
  67091. }
  67092. getVolumeString(){
  67093. if(!this.volumeInfo || this.volumeInfo.Vupper == void 0)return;
  67094. this.VupperString = this.getConvertString(this.volumeInfo.Vupper, 'volume', true);
  67095. this.VlowerString = this.getConvertString(this.volumeInfo.Vlower, 'volume', true);
  67096. this.highestString = this.getConvertString(this.volumeInfo.highest, 'distance', true);
  67097. this.lowestString = this.getConvertString(this.volumeInfo.lowest, 'distance', true);
  67098. }
  67099. getConvertString(num, type, restrictUnit){
  67100. if(!restrictUnit)return super.getConvertString(num, type)
  67101. return viewer.unitConvert.convert(num, type, Potree.settings.precision, this.unitSystem, null ,
  67102. {//在pdf里的高度要统一单位
  67103. 'imperial': {restrictUnit: 'Foot'}, //ft
  67104. 'metric': {restrictUnit: 'Meter'}
  67105. }
  67106. )
  67107. }
  67108. setUnitSystem(unitSystem){
  67109. let old = this.unitSystem;
  67110. super.setUnitSystem(unitSystem);
  67111. if(unitSystem != old){
  67112. this.getVolumeString();
  67113. }
  67114. }
  67115. getCenter(type){
  67116. if(type == 'areaPlaneCenter'){//areaPlane中心
  67117. return this.areaPlaneCenter
  67118. }
  67119. return super.getCenter() //点的中心
  67120. }
  67121. update(){
  67122. super.update.apply(this, arguments);
  67123. this.updatePrismLines();
  67124. }
  67125. getTransformationMatrix(pointcloud) {//剪裁矩阵
  67126. let invMatrix = new Matrix4;
  67127. //把当前z移动到-0.5 ~ 0.5所需要的变换
  67128. let minZ = this.zMin;//viewer.bound.boundingBox.min.z
  67129. let maxZ = this.zMax;//viewer.bound.boundingBox.max.z
  67130. let s = 1/(maxZ-minZ);
  67131. let pos = new Vector3(0,0, -0.5 - minZ * s ),
  67132. scale = new Vector3(1,1,s);
  67133. invMatrix.compose( pos, new Quaternion, scale ); //先缩放后位移
  67134. return (new Matrix4).multiplyMatrices(invMatrix, pointcloud.transformMatrix).transpose()
  67135. }
  67136. changeStyleForScreenshot(state, {hideLabel,showName}={}){//截图前变一下外观。根据高度变化颜色
  67137. let config = Potree.settings.prismHeightColor;
  67138. let color;//, lineWidth = this.edges[0].material.lineWidth
  67139. if(this.volumeInfo.Vupper > 0.01 && this.volumeInfo.Vlower > 0.01){
  67140. color = config.every.color;
  67141. }else if(this.volumeInfo.Vupper > this.volumeInfo.Vlower){
  67142. for(let i = config.dig.length-1; i>=0; i--){
  67143. if(this.volumeInfo.Vupper >= config.dig[i].min){
  67144. color = config.dig[i].color;
  67145. break
  67146. }
  67147. }
  67148. }else {
  67149. for(let i = config.fill.length-1; i>=0; i--){
  67150. if(this.volumeInfo.Vlower >= config.fill[i].min){
  67151. color = config.fill[i].color;
  67152. break
  67153. }
  67154. }
  67155. }
  67156. color = new Color(color[0]/255,color[1]/255,color[2]/255);
  67157. let name = color.getHexString();
  67158. if(state){
  67159. Potree.Utils.updateVisible(this.areaPlane,'screenshot', true, 2, 'add'); //强制显示
  67160. let mat = areaPlaneMats[name];
  67161. if(!mat){
  67162. mat = new MeshBasicMaterial({
  67163. color, transparent:true, opacity:0.6,
  67164. side:DoubleSide,
  67165. });
  67166. areaPlaneMats[name] = mat;
  67167. }
  67168. this.oldAreaPlaneMat = this.areaPlane.material;
  67169. this.areaPlane.material = mat;
  67170. if(hideLabel){
  67171. Potree.Utils.updateVisible(this.areaLabel, 'screenshot-single',false);
  67172. }
  67173. if(showName){
  67174. this.areaLabel.setText([this.name, this.area.string]);
  67175. /* let btm = this.areaPlaneCenter.clone().setY(this.prismBound.min.y) //置于土方2d块底部
  67176. this.areaLabel.setPos(btm)
  67177. this.areaLabel.sprite.position.y = -0.25 */
  67178. }
  67179. this.markers.forEach(marker=>Potree.Utils.updateVisible(marker,'screenshot-Prism',false));
  67180. this.edges.forEach(edge=>Potree.Utils.updateVisible(edge,'screenshot-Prism',false));
  67181. //Potree.Utils.updateVisible(this.lineMesh,'screenshot-Prism',false)
  67182. this.styleRecover = ()=>{
  67183. this.areaPlane.material = this.oldAreaPlaneMat;
  67184. if(hideLabel){
  67185. Potree.Utils.updateVisible(this.areaLabel, 'screenshot-single', true);
  67186. }
  67187. if(showName){
  67188. this.areaLabel.setText(this.area.string);
  67189. /* this.areaLabel.setPos(this.areaPlaneCenter)
  67190. this.areaLabel.sprite.position.y = 0 */
  67191. }
  67192. this.markers.forEach(marker=>Potree.Utils.updateVisible(marker,'screenshot-Prism',true));
  67193. this.edges.forEach(edge=>Potree.Utils.updateVisible(edge,'screenshot-Prism',true));
  67194. //Potree.Utils.updateVisible(this.lineMesh,'screenshot-Prism',true)
  67195. this.styleRecover = null;
  67196. };
  67197. }else {
  67198. this.styleRecover && this.styleRecover();
  67199. Potree.Utils.updateVisible(this.areaPlane, 'screenshot', false, 2, 'cancel');
  67200. }
  67201. }
  67202. dispose(){
  67203. super.dispose();
  67204. this.clipBoxes.forEach(e=>viewer.scene.removeVolume(e));
  67205. }
  67206. setEditState(state){//编辑页面or截图
  67207. state = !!state;
  67208. this.editing = state;
  67209. this.dontHighlight = !state;
  67210. this.clipBoxes.forEach(box=>{
  67211. Potree.Utils.updateVisible(box,'hidden',state), box.clip = state;
  67212. });
  67213. }
  67214. /* {
  67215. fill: [
  67216. {color: [236, 213, 143, 1], min: 0, max: 5},
  67217. {color: [223, 118, 21, 1], min: 5, max: 10},
  67218. // 没有min表示大于
  67219. {color: [186, 57, 57, 1], min: 10}
  67220. ],
  67221. dig: [
  67222. {color: [144, 193, 190, 1], min: 0, max: 5},
  67223. {color: [76, 155, 211, 1], min: 5, max: 10},
  67224. // 没有min表示大于
  67225. {color: [79, 76, 211, 1], min: 10}
  67226. ],
  67227. // 填挖并存
  67228. every: { color: [49, 200, 181, 1] }
  67229. } */
  67230. }
  67231. class MeasuringTool extends EventDispatcher{
  67232. constructor (viewer) {
  67233. super();
  67234. this.viewer = viewer;
  67235. this.renderer = viewer.renderer;
  67236. this.viewer.addEventListener('start_inserting_measurement', e => {
  67237. this.viewer.dispatchEvent({
  67238. type: 'cancel_insertions'
  67239. });
  67240. });
  67241. this.showLabels = true;
  67242. this.scene = new Scene();
  67243. this.scene.name = 'scene_measurement';
  67244. //this.light = new THREE.PointLight(0xffffff, 1.0);
  67245. //this.scene.add(this.light);
  67246. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  67247. this.history = new History({
  67248. applyData: (data)=>{
  67249. if(data.measure.parent && data.measure.visible){
  67250. data = Potree.Common.CloneObject(data); //避免使用后更改数据又被使用
  67251. data.measure.reDraw();
  67252. data.measure.initData(data);
  67253. data.measure.isNew = data.isNew;
  67254. data.measure.dispatchEvent('changeByHistory');
  67255. /* if(data.measure.isPrism){
  67256. data.measure.needsCompute = data.needsCompute
  67257. } */
  67258. data.measure.facePlane = data.facePlane && data.facePlane.clone();
  67259. data.measure.cannotConfirmNormal = data.cannotConfirmNormal;
  67260. return true
  67261. }
  67262. },
  67263. getData:(measure)=>{
  67264. let data = {
  67265. measure,
  67266. points: measure.points.map(e=>e.clone()),
  67267. dataset_points: measure.dataset_points ? measure.dataset_points.map(e=>e&&e.clone()) : null,
  67268. points_datasets: measure.points_datasets.slice(),
  67269. datasetId: measure.datasetId,
  67270. isNew: measure.isNew,
  67271. facePlane: measure.facePlane && measure.facePlane.clone(),
  67272. cannotConfirmNormal: measure.cannotConfirmNormal
  67273. };
  67274. /* if(measure.isPrism){ //没用
  67275. data.volumeInfo = measure.volumeInfo
  67276. data.needsCompute = measure.needsCompute
  67277. //但不记录其他信息
  67278. } */
  67279. return data
  67280. }
  67281. }),
  67282. //this.scene = viewer.overlay//
  67283. this.onRemove = (e) => { e.measurement.dispose();/* this.scene.remove(e.measurement); */};
  67284. this.onAdd = e => {this.scene.add(e.measurement);};
  67285. for(let measurement of viewer.scene.measurements){
  67286. this.onAdd({measurement: measurement});
  67287. }
  67288. viewer.addEventListener('camera_changed', this.update.bind(this),{importance:10});//优先级高于sprite
  67289. if(Potree.config.measure.mulLabelHideFaraway ){
  67290. viewer.addEventListener("raycaster", this.beforeDraw.bind(this),{importance:10}); //before render
  67291. viewer.addEventListener("render.begin", this.beforeDraw.bind(this),{importance:10}); //before render
  67292. viewer.addEventListener("render.begin2", this.beforeDraw.bind(this),{importance:10});
  67293. }
  67294. //viewer.addEventListener("update", this.update.bind(this));
  67295. viewer.addEventListener("render.pass.perspective_overlay", this.render.bind(this));
  67296. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  67297. viewer.scene.addEventListener('measurement_added', this.onAdd);
  67298. viewer.scene.addEventListener('measurement_removed', this.onRemove);
  67299. viewer.addEventListener('resize',this.setSize.bind(this));
  67300. }
  67301. onSceneChange(e){
  67302. if(e.oldScene){
  67303. e.oldScene.removeEventListener('measurement_added', this.onAdd);
  67304. e.oldScene.removeEventListener('measurement_removed', this.onRemove);
  67305. }
  67306. e.scene.addEventListener('measurement_added', this.onAdd);
  67307. e.scene.addEventListener('measurement_removed', this.onRemove);
  67308. }
  67309. createMeasureFromData(data){//add
  67310. const measure = data.measureType == 'MulDistance Ring' ? new Prism(data) : new Measure$1(data);
  67311. if(measure.failBuilded){
  67312. return
  67313. }
  67314. viewer.scene.addMeasurement(measure);
  67315. if(measure.guideLine)measure.guideLine.visible = false;
  67316. return measure
  67317. }
  67318. beforeDraw(e){
  67319. if(e.viewport.name == 'mapViewport' && !viewer.mapViewer.attachedToViewer)return //no measures
  67320. viewer.scene.measurements.forEach(measure=>{
  67321. if(measure.measureType != 'MulDistance' || (measure.isNew ? measure.points.length<4 : measure.points.length<3)) return
  67322. let lastIndex = measure.points.length - 1;
  67323. for (let index = 0; index <= lastIndex; index++) {
  67324. if(!measure.closed && index == lastIndex)continue
  67325. let edgeLabel = measure.edgeLabels[index];
  67326. let v = edgeLabel.visiMap.get(e.viewport.camera);
  67327. if(v == void 0){
  67328. return measure.getEdgeLabelVisi(e.viewport)
  67329. }
  67330. Potree.Utils.updateVisible(edgeLabel, 'tooFar', v === false ? false : true);
  67331. }
  67332. });
  67333. }
  67334. update(e){
  67335. /* viewer.scene.measurements.forEach(measure=>{
  67336. if(measure.measureType != 'MulDistance' || (measure.isNew ? measure.points.length<4 : measure.points.length<3)) return
  67337. }) */
  67338. if(viewer.inputHandler.measuring && Potree.settings.adsorption){
  67339. viewer.scene.measurements.forEach(measure=>{
  67340. measure.getPointsPos2d(e.viewport, true);
  67341. });
  67342. }
  67343. if(Potree.config.measure.mulLabelHideFaraway){
  67344. if(e.changeInfo.projectionChanged || e.viewport.camera.type == 'PerspectiveCamera' && e.changeInfo.positionChanged){//for MulDistance
  67345. viewer.scene.measurements.forEach(measure=>{
  67346. if(measure.measureType != 'MulDistance' || (measure.isNew ? measure.points.length<4 : measure.points.length<3)) return
  67347. measure.getEdgeLabelVisi(e.viewport);
  67348. return
  67349. let lastIndex = measure.points.length - 1;
  67350. for (let index = 0; index <= lastIndex; index++) {
  67351. if(!measure.closed && index == lastIndex)continue
  67352. let nextIndex = (index + 1 > lastIndex) ? 0 : index + 1;
  67353. let previousIndex = (index === 0) ? lastIndex : index - 1;
  67354. let point = measure.points[index];
  67355. let nextPoint = measure.points[nextIndex];
  67356. let previousPoint = measure.points[previousIndex];
  67357. let point2d = new Vector2().copy(pos2ds[index]);
  67358. let nextPoint2d = new Vector2().copy(pos2ds[nextIndex]);
  67359. if(measure.showDistances || measure.labelText){ // edge labels
  67360. let edgeLabel = measure.edgeLabels[index];
  67361. if(edgeLabel.visible){
  67362. measure.setEdgeLabelPos(edgeLabel, point, nextPoint );
  67363. }
  67364. }
  67365. }
  67366. });
  67367. }
  67368. }
  67369. return;
  67370. let camera = this.viewer.scene.getActiveCamera();
  67371. let domElement = this.renderer.domElement;
  67372. let measurements = this.viewer.scene.measurements;
  67373. // make size independant of distance
  67374. let mainLabels = [], subLabels = [];
  67375. for (let measure of measurements) {
  67376. measure.lengthUnit = this.viewer.lengthUnit;
  67377. measure.lengthUnitDisplay = this.viewer.lengthUnitDisplay;
  67378. //measure.update();
  67379. updateAzimuth(this.viewer, measure);
  67380. /* [...measure.markers, ...measure.edgeLabels, measure.areaLabel].forEach(e=>{
  67381. e && e.update()
  67382. }); */
  67383. // labels
  67384. /* let labels = measure.edgeLabels.concat(measure.angleLabels);
  67385. for(let label of labels){
  67386. label.update()
  67387. if(label.elem.hasClass('sub')){
  67388. subLabels.push(label)
  67389. }else{
  67390. mainLabels.push(label)
  67391. }
  67392. }
  67393. // coordinate labels
  67394. for (let j = 0; j < measure.coordinateLabels.length; j++) {
  67395. let label = measure.coordinateLabels[j];
  67396. label.update()
  67397. mainLabels.push(label)
  67398. }
  67399. if(measure.showArea){ // area label
  67400. let label = measure.areaLabel;
  67401. label.update()
  67402. mainLabels.push(label)
  67403. } */
  67404. /* if(measure.showCircle){ // radius label
  67405. let label = measure.circleRadiusLabel;
  67406. let distance = label.position.distanceTo(camera.position);
  67407. let pr = Utils.projectedRadius(1, camera, distance, clientWidth, clientHeight);
  67408. let scale = (70 / pr);
  67409. label.scale.set(scale, scale, scale);
  67410. } */
  67411. if(!this.showLabels){
  67412. const labels = [
  67413. ...measure.sphereLabels,
  67414. ...measure.angleLabels,
  67415. measure.circleRadiusLabel,
  67416. ];
  67417. for(const label of labels){
  67418. label.visible = false;
  67419. }
  67420. }
  67421. }
  67422. //this.updateLabelZIndex([{labels:subLabels},{labels:mainLabels}])
  67423. }
  67424. setSize(e){ //e.resolution
  67425. /* if(Measure.lineMats){
  67426. for(var m in Measure.lineMats){
  67427. Measure.lineMats[m].resolution.set(e.canvasWidth, e.canvasHeight);
  67428. }
  67429. }
  67430. if(Measure.sphereMats){
  67431. for(var s in Measure.sphereMats){
  67432. Measure.sphereMats[s].uniforms.resolution.value.set(e.canvasWidth, e.canvasHeight);
  67433. }
  67434. }
  67435. for (let measure of this.viewer.scene.measurements) {
  67436. measure.edgeLabels.concat(measure.areaLabel).forEach(label=>{
  67437. label.sprite.material.uniforms.resolution.value.set(e.canvasWidth, e.canvasHeight);
  67438. })
  67439. } */
  67440. }
  67441. updateLabelZIndex(group){//[{labels:[]},{}] 顺序按照z-index低到高
  67442. group.forEach((e,i)=>{
  67443. e.base = group[i-1] ? group[i-1].base + group[i-1].labels.length : 0;
  67444. var labels = e.labels.sort((a,b)=>{
  67445. return b.pos2d.z - a.pos2d.z
  67446. });
  67447. labels.forEach((label,index)=>{
  67448. $(label.elem).css('z-index', e.base+index);
  67449. });
  67450. });
  67451. }
  67452. changeEditMode(mode){
  67453. viewer.dispatchEvent({type : "CursorChange", action : "remove", name:"addPoint"});
  67454. viewer.dispatchEvent({type : "CursorChange", action : "remove", name:"delPoint"});
  67455. if(mode){
  67456. if(mode == 'addPoint'){
  67457. viewer.dispatchEvent({type : "CursorChange", action : "add", name:"addPoint"});
  67458. }else {
  67459. viewer.dispatchEvent({type : "CursorChange", action : "add", name:"delPoint"});
  67460. }
  67461. }
  67462. this.editMode = mode;
  67463. }
  67464. editStateChange(e){
  67465. //console.log("editStateChange" , e.state)
  67466. let state = e.state;
  67467. if(!state){
  67468. state = viewer.scene.measurements.some(e=>e.isEditing);
  67469. }
  67470. if(state){
  67471. viewer.dispatchEvent({type:"measureMovePoint"});//重新激活reticule状态
  67472. }else {
  67473. viewer.dispatchEvent({type:"endMeasureMove"});
  67474. }
  67475. //this.editing =
  67476. }
  67477. startInsertion (args = {}, callback, cancelFun) {
  67478. let domElement = this.viewer.renderer.domElement;
  67479. let measure = args.measureType == 'MulDistance Ring' ? new Prism(args) : new Measure$1(args);
  67480. this.scene.add(measure);
  67481. measure.isNew = true;
  67482. this.viewer.dispatchEvent({
  67483. type: 'start_inserting_measurement',
  67484. measure: measure
  67485. });
  67486. measure.addEventListener('editStateChange', this.editStateChange.bind(this));
  67487. measure.editStateChange(true);
  67488. let timer;
  67489. this.isAdding = true;
  67490. let endDragFun = (e) => {
  67491. let length = measure.points.length;
  67492. if (e.button == MOUSE.LEFT || e.isTouch) {
  67493. if (length >= measure.maxMarkers) {
  67494. end({finish:true});
  67495. }else {
  67496. this.history.beforeChange(measure);
  67497. let marker = measure.cloneMarker(length - 1, length);
  67498. if(args.isRect && measure.markers.length == 3){//marker全可见
  67499. measure.cloneMarker(0, 3);
  67500. }else {
  67501. measure.markers[length].visible = false;
  67502. measure.edges[length].visible = false;
  67503. }
  67504. measure.edges[length-1].visible = true;
  67505. measure.markers[length-1].visible = true;
  67506. marker.isDragging = true;
  67507. this.history.afterChange(measure);
  67508. measure.continueDrag(marker, e);
  67509. }
  67510. } else if (e.button === MOUSE.RIGHT ) { //触屏怎么取消?
  67511. if(e.pressDistance < Potree.config.clickMaxDragDis){//非拖拽的话
  67512. var isIntersectSelf = measure.atPlane && measure.closed && !measure.isRect && measure.point2dInfo && measure.intersectSelf(measure.point2dInfo.points2d.slice(0,measure.point2dInfo.points2d.length-1));//检测除了最后一个点的相交情况
  67513. if(!isIntersectSelf)end(e);
  67514. else measure.continueDrag(null, e);
  67515. }else measure.continueDrag(null, e);
  67516. }
  67517. };
  67518. let end = (e={}) => {//确定、结束
  67519. if(!measure.isNew )return
  67520. if(args.minMarkers != void 0 ){
  67521. if(!e.finish && measure.markers.length<=args.minMarkers ){//右键 当个数不够时取消
  67522. //this.viewer.scene.removeMeasurement(measure)
  67523. //重新开始画
  67524. if(measure.markers.length>0){
  67525. measure.markers[0].removeEventListener('mousedown',end);
  67526. measure.reDraw();
  67527. this.viewer.addEventListener('global_click', click, {importance:10});
  67528. measure.editStateChange(true);
  67529. }
  67530. return
  67531. /* if(!Potree.settings.isOfficial) this.viewer.scene.removeMeasurement(measure)
  67532. else if(e.drag){ //正式版本不允许右键退出, 继续
  67533. continueDrag(e.drag.object)
  67534. measure.editStateChange(true)
  67535. return
  67536. } */
  67537. }
  67538. }
  67539. let lastMarker = measure.markers[measure.markers.length-1];
  67540. if (/* !e.finish&& */ measure.markers.length > args.minMarkers) {
  67541. measure.removeMarker(measure.points.length - 1);
  67542. measure.markers[0].removeEventListener('mouseover', mouseover);
  67543. measure.markers[0].removeEventListener('mouseleave', mouseleave);
  67544. measure.markers[0].removeEventListener('click'/* 'mousedown' */,Exit);
  67545. if(e.byClickMarker && measure.markers.length > args.minMarkers ){//通过点击第一个marker而结束的话,会多一个marker。但点击marker后可能会因为和它坐标一致而没有添加成功,就不删,根据添加的时间来判断。
  67546. let delta = Date.now() - lastMarker.createTime;
  67547. //console.log('delta',delta)
  67548. if(delta < 10){//刚生成的,说明点击后新增了一个marker
  67549. measure.removeMarker(measure.points.length - 1);
  67550. }
  67551. }
  67552. }
  67553. measure.isNew = false;
  67554. let length = measure.points.length;
  67555. if(length){
  67556. measure.markers[length-1].visible = true;
  67557. measure.edges[length-1].visible = !!measure.closed;
  67558. measure.markers.forEach(marker=>{marker.dispatchEvent('addHoverEvent'); });
  67559. measure.edges.forEach(edge=>{edge.dispatchEvent('addHoverEvent'); });
  67560. measure.update();//update last edgeLabel
  67561. }
  67562. clearTimeout(timer);
  67563. this.viewer.removeEventListener('cancel_insertions', Exit);
  67564. //pressExit && this.viewer.inputHandler.removeEventListener('keydown', pressExit);
  67565. this.viewer.removeEventListener('global_click', click);
  67566. this.viewer.removeEventListener('global_mousemove', ifAtWrongPlace);
  67567. viewer.dispatchEvent({
  67568. type : "CursorChange", action : "remove", name:"polygon_AtWrongPlace"
  67569. });
  67570. viewer.inputHandler.dispatchEvent({type:'measuring', v:false, cause:'stopInsertion', situation:'adding', object:measure} );
  67571. //var isIntersectSelf = measure.atPlane && measure.closed && !measure.isRect && measure.point2dInfo && measure.intersectSelf(measure.point2dInfo.points2d.slice(0,measure.point2dInfo.points2d.length-1))//检测除了最后一个点的相交情况
  67572. var isIntersectSelf = measure.atPlane && measure.closed && !measure.isRect && measure.point2dInfo && measure.intersectSelf(measure.point2dInfo.points2d);
  67573. if(isIntersectSelf) return cancelFun && cancelFun() //请求删除,不重建
  67574. e.remove || callback && callback();
  67575. /* this.viewer.dispatchEvent({
  67576. type: 'finish_inserting_measurement',
  67577. measure: measure
  67578. }); */
  67579. this.isAdding = false;
  67580. measure.dispatchEvent('createDone');
  67581. };
  67582. measure.addEventListener('finish', end); //完成
  67583. let Exit = (e)=>{//强制退出
  67584. if(e.measure && e.measure != measure || !viewer.scene.measurements.includes(measure) || !measure.isNew){
  67585. return;//若指定了退出的measure但和该measure不一致,就返回
  67586. }
  67587. if(e.remove || e.type == 'cancel_insertions'){
  67588. viewer.scene.removeMeasurement(measure);
  67589. }
  67590. measure.editStateChange(false);
  67591. measure.cannotConfirmNormal = false; //一些dropMarker中的句子
  67592. measure.guideLine && (measure.guideLine.visible = false);
  67593. /*
  67594. if(this.viewer.inputHandler.drag && !e.remove ){//还未触发drop的话
  67595. this.viewer.inputHandler.drag.object.dispatchEvent({ //这句会导致又增一个marker
  67596. type: 'drop',
  67597. drag: this.viewer.inputHandler.drag,
  67598. viewer: this.viewer,
  67599. pressDistance:0,
  67600. button : THREE.MOUSE.RIGHT
  67601. });
  67602. } else {*///未结束时添加新的measure时会触发
  67603. end({finish:true, remove:e.remove, byClickMarker: e.type == 'click'});
  67604. //}
  67605. this.viewer.inputHandler.drag && (this.viewer.inputHandler.drag.object = null);
  67606. };
  67607. this.viewer.addEventListener('cancel_insertions', Exit);
  67608. /*let pressExit
  67609. if(!Potree.settings.isOfficial){
  67610. pressExit = (e)=>{
  67611. if(e.keyCode == 27){//Esc
  67612. //Exit()
  67613. //怎么模拟右键???//现由前端发出
  67614. }
  67615. }
  67616. this.viewer.inputHandler.addEventListener('keydown', pressExit)
  67617. } */
  67618. let mouseover = (e) => {
  67619. measure.setMarkerSelected(e.object, 'hover', 'single');
  67620. };
  67621. let mouseleave = (e) => {
  67622. measure.setMarkerSelected(e.object, 'unhover', 'single');
  67623. };
  67624. let click = (e)=>{//一旦点击就立刻增加两marker
  67625. if(ifAtWrongPlace(e))return
  67626. if(e.clickElement)return //如点击label时focusOnObject
  67627. if(e.button === MOUSE.RIGHT)return
  67628. //console.log('measure clicked33', !!e.intersectPoint)
  67629. //var I = e.intersectPoint && (e.intersectPoint.orthoIntersect || e.intersectPoint.location)
  67630. var I = e.intersect && (e.intersect.orthoIntersect || e.intersect.location);
  67631. if(!I){
  67632. return measure.dispatchEvent('intersectNoPointcloud')
  67633. }
  67634. var atMap = e.drag.dragViewport.name == 'mapViewport';
  67635. //在地图上测量的首个点按楼层高度(暂时先只按mainViewport相机高度吧,但navvis是按楼层,画在楼层的地面上,可能因为平面图显示的是楼层近地面),
  67636. if(atMap){
  67637. I = I.clone().setZ(viewer.mainViewport.camera.position.z );
  67638. }
  67639. var marker = measure.addMarker({point:I});
  67640. marker.isDragging = true;
  67641. this.viewer.inputHandler.startDragging(marker , {endDragFun, notPressMouse:true} ); //notPressMouse代表不是通过按下鼠标来拖拽
  67642. e.drag = this.viewer.inputHandler.drag;
  67643. /* e.drag.endDragFun = endDragFun
  67644. e.drag.notPressMouse = true */
  67645. //if(!measure.dragMarker(e) || !measure.dropMarker(e))return
  67646. measure.dragMarker(e);
  67647. measure.dropMarker(e);
  67648. if(measure.maxMarkers > 1 ){
  67649. measure.markers[1].visible = false;
  67650. measure.edges[1].visible = false;
  67651. }
  67652. if(measure.closed && !measure.isRect){
  67653. measure.markers[0].addEventListener('mouseover', mouseover);
  67654. measure.markers[0].addEventListener('mouseleave', mouseleave);
  67655. measure.markers[0].addEventListener('click'/* 'mousedown' */,Exit); //点击到第一个marker就结束
  67656. }
  67657. this.viewer.removeEventListener('global_click', click);///* global_drop */
  67658. //console.log('measure clicked')
  67659. e.consume && e.consume();
  67660. return {stopContinue:true}//防止继续执行别的侦听,如flytopano
  67661. };
  67662. //点击第n下拥有n+1个marker, n>0
  67663. viewer.inputHandler.dispatchEvent({type: 'measuring', v: true, cause:'startInsertion', situation:'adding', object:measure});
  67664. this.viewer.addEventListener('global_click', click, {importance:10});//add importance
  67665. let ifAtWrongPlace = (e)=>{
  67666. if(measure.unableDragAtMap && e.hoverViewport.name == 'mapViewport' ){
  67667. if(e.isTouch){
  67668. viewer.dispatchEvent({type:'reticule_forbit', v:true});
  67669. }else {
  67670. viewer.dispatchEvent({
  67671. type : "CursorChange", action : "add", name:"polygon_AtWrongPlace"
  67672. });
  67673. }
  67674. return true
  67675. }else {
  67676. if(e.isTouch){
  67677. viewer.dispatchEvent({type:'reticule_forbit',v:false});
  67678. }else {
  67679. viewer.dispatchEvent({
  67680. type : "CursorChange", action : "remove", name:"polygon_AtWrongPlace"
  67681. });
  67682. }
  67683. }
  67684. };
  67685. if(measure.unableDragAtMap){
  67686. this.viewer.addEventListener('global_mousemove', ifAtWrongPlace);
  67687. }
  67688. let changeByHistory = (e)=>{
  67689. if(!measure.isNew)return
  67690. let marker = measure.markers[measure.points.length-1];
  67691. this.viewer.inputHandler.startDragging(marker , {endDragFun, notPressMouse:true} );
  67692. var I = viewer.inputHandler.intersect && (viewer.inputHandler.intersect.orthoIntersect || viewer.inputHandler.intersect.location);
  67693. if(I){
  67694. measure.dragChange(I.clone(), measure.points.length-1 ); //使最后一个点在鼠标处
  67695. }
  67696. /* if(measure.markers.length == 1){
  67697. Common.updateVisible(marker, ,false)
  67698. } */
  67699. args.isRect || ( measure.edges[measure.points.length-1].visible = false);
  67700. //measure.continueDrag(measure.markers[measure.points.length-1], o )
  67701. };
  67702. measure.addEventListener('changeByHistory',changeByHistory);
  67703. this.viewer.scene.addMeasurement(measure);
  67704. return measure;
  67705. }
  67706. render(o={}){
  67707. if(this.scene.children.filter(e=>e.visible).length == 0)return
  67708. let renderer = o.renderer || this.viewer.renderer;
  67709. Potree.Utils.setCameraLayers(o.camera, ['measure']);
  67710. /* if(o.screenshot && this.viewer.fxaaPass.enabled){ //抗锯齿
  67711. this.viewer.ssaaRenderPass.sampleLevel = 4
  67712. this.viewer.composer.render(this.scene, o.camera );
  67713. }else{ */
  67714. viewer.dispatchEvent({type: "render.begin2" , name:'measure', viewport:o.viewport, renderer:o.renderer });
  67715. renderer.render(this.scene, o.camera );
  67716. //}
  67717. }
  67718. };
  67719. function updateAzimuth(viewer, measure){
  67720. if(!measure.showAzimuth)return
  67721. const azimuth = measure.azimuth;
  67722. const isOkay = measure.points.length === 2;
  67723. azimuth.node.visible = isOkay;
  67724. if(!azimuth.node.visible){
  67725. return;
  67726. }
  67727. const camera = viewer.scene.getActiveCamera();
  67728. const renderAreaSize = viewer.renderer.getSize(new Vector2());
  67729. const width = renderAreaSize.width;
  67730. const height = renderAreaSize.height;
  67731. const [p0, p1] = measure.points;
  67732. const r = p0.position.distanceTo(p1.position);
  67733. const northVec = Utils.getNorthVec(p0.position, r, viewer.getProjection());
  67734. const northPos = p0.position.clone().add(northVec);
  67735. azimuth.center.position.copy(p0.position);
  67736. azimuth.center.scale.set(2, 2, 2);
  67737. azimuth.center.visible = false;
  67738. // azimuth.target.visible = false;
  67739. { // north
  67740. azimuth.north.position.copy(northPos);
  67741. azimuth.north.scale.set(2, 2, 2);
  67742. let distance = azimuth.north.position.distanceTo(camera.position);
  67743. let pr = Utils.projectedRadius(1, camera, distance, width, height);
  67744. let scale = (5 / pr);
  67745. azimuth.north.scale.set(scale, scale, scale);
  67746. }
  67747. { // target
  67748. azimuth.target.position.copy(p1.position);
  67749. azimuth.target.position.z = azimuth.north.position.z;
  67750. let distance = azimuth.target.position.distanceTo(camera.position);
  67751. let pr = Utils.projectedRadius(1, camera, distance, width, height);
  67752. let scale = (5 / pr);
  67753. azimuth.target.scale.set(scale, scale, scale);
  67754. }
  67755. azimuth.circle.position.copy(p0.position);
  67756. azimuth.circle.scale.set(r, r, r);
  67757. azimuth.circle.material.resolution.set(width, height);
  67758. // to target
  67759. azimuth.centerToTarget.geometry.setPositions([
  67760. 0, 0, 0,
  67761. ...p1.position.clone().sub(p0.position).toArray(),
  67762. ]);
  67763. azimuth.centerToTarget.position.copy(p0.position);
  67764. azimuth.centerToTarget.geometry.verticesNeedUpdate = true;
  67765. azimuth.centerToTarget.geometry.computeBoundingSphere();
  67766. azimuth.centerToTarget.computeLineDistances();
  67767. azimuth.centerToTarget.material.resolution.set(width, height);
  67768. // to target ground
  67769. azimuth.centerToTargetground.geometry.setPositions([
  67770. 0, 0, 0,
  67771. p1.position.x - p0.position.x,
  67772. p1.position.y - p0.position.y,
  67773. 0,
  67774. ]);
  67775. azimuth.centerToTargetground.position.copy(p0.position);
  67776. azimuth.centerToTargetground.geometry.verticesNeedUpdate = true;
  67777. azimuth.centerToTargetground.geometry.computeBoundingSphere();
  67778. azimuth.centerToTargetground.computeLineDistances();
  67779. azimuth.centerToTargetground.material.resolution.set(width, height);
  67780. // to north
  67781. azimuth.centerToNorth.geometry.setPositions([
  67782. 0, 0, 0,
  67783. northPos.x - p0.position.x,
  67784. northPos.y - p0.position.y,
  67785. 0,
  67786. ]);
  67787. azimuth.centerToNorth.position.copy(p0.position);
  67788. azimuth.centerToNorth.geometry.verticesNeedUpdate = true;
  67789. azimuth.centerToNorth.geometry.computeBoundingSphere();
  67790. azimuth.centerToNorth.computeLineDistances();
  67791. azimuth.centerToNorth.material.resolution.set(width, height);
  67792. // label
  67793. const radians = Utils.computeAzimuth(p0.position, p1.position, viewer.getProjection());
  67794. let degrees = MathUtils.radToDeg(radians);
  67795. if(degrees < 0){
  67796. degrees = 360 + degrees;
  67797. }
  67798. const txtDegrees = `${degrees.toFixed(2)}°`;
  67799. const labelDir = northPos.clone().add(p1.position).multiplyScalar(0.5).sub(p0.position);
  67800. if(labelDir.length() > 0){
  67801. labelDir.z = 0;
  67802. labelDir.normalize();
  67803. const labelVec = labelDir.clone().multiplyScalar(r);
  67804. const labelPos = p0.position.clone().add(labelVec);
  67805. azimuth.label.position.copy(labelPos);
  67806. }
  67807. azimuth.label.setText(txtDegrees);
  67808. let distance = azimuth.label.position.distanceTo(camera.position);
  67809. let pr = Utils.projectedRadius(1, camera, distance, width, height);
  67810. let scale = (70 / pr);
  67811. azimuth.label.scale.set(scale, scale, scale);
  67812. }
  67813. class ProfileTool extends EventDispatcher$1 {
  67814. constructor (viewer) {
  67815. super();
  67816. this.viewer = viewer;
  67817. this.renderer = viewer.renderer;
  67818. this.addEventListener('start_inserting_profile', e => {
  67819. this.viewer.dispatchEvent({
  67820. type: 'cancel_insertions'
  67821. });
  67822. });
  67823. this.scene = new Scene();
  67824. this.scene.name = 'scene_profile';
  67825. this.light = new PointLight(0xffffff, 1.0);
  67826. this.scene.add(this.light);
  67827. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  67828. this.onRemove = e => this.scene.remove(e.profile);
  67829. this.onAdd = e => this.scene.add(e.profile);
  67830. for(let profile of viewer.scene.profiles){
  67831. this.onAdd({profile: profile});
  67832. }
  67833. viewer.addEventListener("update", this.update.bind(this));
  67834. viewer.addEventListener("render.pass.perspective_overlay", this.render.bind(this));
  67835. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  67836. viewer.scene.addEventListener('profile_added', this.onAdd);
  67837. viewer.scene.addEventListener('profile_removed', this.onRemove);
  67838. }
  67839. onSceneChange(e){
  67840. if(e.oldScene){
  67841. e.oldScene.removeEventListeners('profile_added', this.onAdd);
  67842. e.oldScene.removeEventListeners('profile_removed', this.onRemove);
  67843. }
  67844. e.scene.addEventListener('profile_added', this.onAdd);
  67845. e.scene.addEventListener('profile_removed', this.onRemove);
  67846. }
  67847. startInsertion (args = {}) {
  67848. let domElement = this.viewer.renderer.domElement;
  67849. let profile = new Profile();
  67850. profile.name = args.name || 'Profile';
  67851. this.dispatchEvent({
  67852. type: 'start_inserting_profile',
  67853. profile: profile
  67854. });
  67855. this.scene.add(profile);
  67856. let cancel = {
  67857. callback: null
  67858. };
  67859. let insertionCallback = (e) => {
  67860. if(e.button === MOUSE.LEFT){
  67861. if(profile.points.length <= 1){
  67862. let camera = this.viewer.scene.getActiveCamera();
  67863. let distance = camera.position.distanceTo(profile.points[0]);
  67864. let clientSize = this.viewer.renderer.getSize(new Vector2());
  67865. let pr = Utils.projectedRadius(1, camera, distance, clientSize.width, clientSize.height);
  67866. let width = (10 / pr);
  67867. profile.setWidth(width);
  67868. }
  67869. profile.addMarker(profile.points[profile.points.length - 1].clone());
  67870. this.viewer.inputHandler.startDragging(
  67871. profile.spheres[profile.spheres.length - 1]);
  67872. } else if (e.button === MOUSE.RIGHT) {
  67873. cancel.callback();
  67874. }
  67875. };
  67876. cancel.callback = e => {
  67877. profile.removeMarker(profile.points.length - 1);
  67878. domElement.removeEventListener('mouseup', insertionCallback, false);
  67879. this.viewer.removeEventListener('cancel_insertions', cancel.callback);
  67880. };
  67881. this.viewer.addEventListener('cancel_insertions', cancel.callback);
  67882. domElement.addEventListener('mouseup', insertionCallback, false);
  67883. profile.addMarker(new Vector3(0, 0, 0));
  67884. this.viewer.inputHandler.startDragging(
  67885. profile.spheres[profile.spheres.length - 1]);
  67886. this.viewer.scene.addProfile(profile);
  67887. return profile;
  67888. }
  67889. update(){
  67890. let camera = this.viewer.scene.getActiveCamera();
  67891. let profiles = this.viewer.scene.profiles;
  67892. let renderAreaSize = this.viewer.renderer.getSize(new Vector2());
  67893. let clientWidth = renderAreaSize.width;
  67894. let clientHeight = renderAreaSize.height;
  67895. this.light.position.copy(camera.position);
  67896. // make size independant of distance
  67897. for(let profile of profiles){
  67898. for(let sphere of profile.spheres){
  67899. let distance = camera.position.distanceTo(sphere.getWorldPosition(new Vector3()));
  67900. let pr = Utils.projectedRadius(1, camera, distance, clientWidth, clientHeight);
  67901. let scale = (15 / pr);
  67902. sphere.scale.set(scale, scale, scale);
  67903. }
  67904. }
  67905. }
  67906. render(){
  67907. this.viewer.renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  67908. }
  67909. }
  67910. class ScreenBoxSelectTool extends EventDispatcher$1{
  67911. constructor(viewer){
  67912. super();
  67913. this.viewer = viewer;
  67914. this.scene = new Scene();
  67915. viewer.addEventListener("update", this.update.bind(this));
  67916. viewer.addEventListener("render.pass.perspective_overlay", this.render.bind(this));
  67917. viewer.addEventListener("scene_changed", this.onSceneChange.bind(this));
  67918. }
  67919. onSceneChange(scene){
  67920. console.log("scene changed");
  67921. }
  67922. startInsertion(){
  67923. let domElement = this.viewer.renderer.domElement;
  67924. let volume = new BoxVolume();
  67925. volume.position.set(12345, 12345, 12345);
  67926. volume.showVolumeLabel = false;
  67927. volume.visible = false;
  67928. volume.update();
  67929. this.viewer.scene.addVolume(volume);
  67930. this.importance = 10;
  67931. let selectionBox = $(`<div style="position: absolute; border: 2px solid white; pointer-events: none; border-style:dashed"></div>`);
  67932. $(domElement.parentElement).append(selectionBox);
  67933. selectionBox.css("right", "10px");
  67934. selectionBox.css("bottom", "10px");
  67935. let drag = e =>{
  67936. volume.visible = true;
  67937. let mStart = e.drag.start;
  67938. let mEnd = e.drag.end;
  67939. let box2D = new Box2();
  67940. box2D.expandByPoint(mStart);
  67941. box2D.expandByPoint(mEnd);
  67942. selectionBox.css("left", `${box2D.min.x}px`);
  67943. selectionBox.css("top", `${box2D.min.y}px`);
  67944. selectionBox.css("width", `${box2D.max.x - box2D.min.x}px`);
  67945. selectionBox.css("height", `${box2D.max.y - box2D.min.y}px`);
  67946. let camera = e.viewer.scene.getActiveCamera();
  67947. let size = e.viewer.renderer.getSize(new Vector2());
  67948. let frustumSize = new Vector2(
  67949. camera.right - camera.left,
  67950. camera.top - camera.bottom);
  67951. let screenCentroid = new Vector2().addVectors(e.drag.end, e.drag.start).multiplyScalar(0.5);
  67952. let ray = Utils.mouseToRay(screenCentroid, camera, size.width, size.height);
  67953. let diff = new Vector2().subVectors(e.drag.end, e.drag.start);
  67954. diff.divide(size).multiply(frustumSize);
  67955. volume.position.copy(ray.origin);
  67956. volume.up.copy(camera.up);
  67957. volume.rotation.copy(camera.rotation);
  67958. volume.scale.set(diff.x, diff.y, 1000 * 100);
  67959. e.consume();
  67960. };
  67961. let drop = e => {
  67962. this.importance = 0;
  67963. $(selectionBox).remove();
  67964. this.viewer.inputHandler.deselectAll();
  67965. this.viewer.inputHandler.toggleSelection(volume);
  67966. let camera = e.viewer.scene.getActiveCamera();
  67967. let size = e.viewer.renderer.getSize(new Vector2());
  67968. let screenCentroid = new Vector2().addVectors(e.drag.end, e.drag.start).multiplyScalar(0.5);
  67969. let ray = Utils.mouseToRay(screenCentroid, camera, size.width, size.height);
  67970. let line = new Line3(ray.origin, new Vector3().addVectors(ray.origin, ray.direction));
  67971. this.removeEventListener("drag", drag);
  67972. this.removeEventListener("drop", drop);
  67973. let allPointsNear = [];
  67974. let allPointsFar = [];
  67975. // TODO support more than one point cloud
  67976. for(let pointcloud of this.viewer.scene.pointclouds){
  67977. if(!pointcloud.visible){
  67978. continue;
  67979. }
  67980. let volCam = camera.clone();
  67981. volCam.left = -volume.scale.x / 2;
  67982. volCam.right = +volume.scale.x / 2;
  67983. volCam.top = +volume.scale.y / 2;
  67984. volCam.bottom = -volume.scale.y / 2;
  67985. volCam.near = -volume.scale.z / 2;
  67986. volCam.far = +volume.scale.z / 2;
  67987. volCam.rotation.copy(volume.rotation);
  67988. volCam.position.copy(volume.position);
  67989. volCam.updateMatrix();
  67990. volCam.updateMatrixWorld();
  67991. volCam.updateProjectionMatrix();
  67992. volCam.matrixWorldInverse.copy(volCam.matrixWorld).invert();
  67993. let ray = new Ray(volCam.getWorldPosition(new Vector3()), volCam.getWorldDirection(new Vector3()));
  67994. let rayInverse = new Ray(
  67995. ray.origin.clone().add(ray.direction.clone().multiplyScalar(volume.scale.z)),
  67996. ray.direction.clone().multiplyScalar(-1));
  67997. let pickerSettings = {
  67998. width: 8,
  67999. height: 8,
  68000. pickWindowSize: 8,
  68001. all: true,
  68002. pickClipped: true,
  68003. pointSizeType: PointSizeType.FIXED,
  68004. pointSize: 1};
  68005. let pointsNear = pointcloud.pick(viewer, volCam, ray, pickerSettings);
  68006. volCam.rotateX(Math.PI);
  68007. volCam.updateMatrix();
  68008. volCam.updateMatrixWorld();
  68009. volCam.updateProjectionMatrix();
  68010. volCam.matrixWorldInverse.copy(volCam.matrixWorld).invert();
  68011. let pointsFar = pointcloud.pick(viewer, volCam, rayInverse, pickerSettings);
  68012. allPointsNear.push(...pointsNear);
  68013. allPointsFar.push(...pointsFar);
  68014. }
  68015. if(allPointsNear.length > 0 && allPointsFar.length > 0){
  68016. let viewLine = new Line3(ray.origin, new Vector3().addVectors(ray.origin, ray.direction));
  68017. let closestOnLine = allPointsNear.map(p => viewLine.closestPointToPoint(p.position, false, new Vector3()));
  68018. let closest = closestOnLine.sort( (a, b) => ray.origin.distanceTo(a) - ray.origin.distanceTo(b))[0];
  68019. let farthestOnLine = allPointsFar.map(p => viewLine.closestPointToPoint(p.position, false, new Vector3()));
  68020. let farthest = farthestOnLine.sort( (a, b) => ray.origin.distanceTo(b) - ray.origin.distanceTo(a))[0];
  68021. let distance = closest.distanceTo(farthest);
  68022. let centroid = new Vector3().addVectors(closest, farthest).multiplyScalar(0.5);
  68023. volume.scale.z = distance * 1.1;
  68024. volume.position.copy(centroid);
  68025. }
  68026. volume.clip = true;
  68027. };
  68028. this.addEventListener("drag", drag);
  68029. this.addEventListener("drop", drop);
  68030. viewer.inputHandler.addInputListener(this);
  68031. return volume;
  68032. }
  68033. update(e){
  68034. //console.log(e.delta)
  68035. }
  68036. render(){
  68037. this.viewer.renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  68038. }
  68039. }
  68040. class SpotLightHelper$1 extends Object3D{
  68041. constructor(light, color){
  68042. super();
  68043. this.light = light;
  68044. this.color = color;
  68045. //this.up.set(0, 0, 1);
  68046. this.updateMatrix();
  68047. this.updateMatrixWorld();
  68048. { // SPHERE
  68049. let sg = new SphereGeometry(1, 32, 32);
  68050. let sm = new MeshNormalMaterial();
  68051. this.sphere = new Mesh(sg, sm);
  68052. this.sphere.scale.set(0.5, 0.5, 0.5);
  68053. this.add(this.sphere);
  68054. }
  68055. { // LINES
  68056. let positions = new Float32Array([
  68057. +0, +0, +0, +0, +0, -1,
  68058. +0, +0, +0, -1, -1, -1,
  68059. +0, +0, +0, +1, -1, -1,
  68060. +0, +0, +0, +1, +1, -1,
  68061. +0, +0, +0, -1, +1, -1,
  68062. -1, -1, -1, +1, -1, -1,
  68063. +1, -1, -1, +1, +1, -1,
  68064. +1, +1, -1, -1, +1, -1,
  68065. -1, +1, -1, -1, -1, -1,
  68066. ]);
  68067. let geometry = new BufferGeometry();
  68068. geometry.setAttribute("position", new BufferAttribute(positions, 3));
  68069. let material = new LineBasicMaterial();
  68070. this.frustum = new LineSegments(geometry, material);
  68071. this.add(this.frustum);
  68072. }
  68073. this.update();
  68074. }
  68075. update(){
  68076. this.light.updateMatrix();
  68077. this.light.updateMatrixWorld();
  68078. let position = this.light.position;
  68079. let target = new Vector3().addVectors(
  68080. this.light.position, this.light.getWorldDirection(new Vector3()).multiplyScalar(-1));
  68081. let quat = new Quaternion().setFromRotationMatrix(
  68082. new Matrix4().lookAt( position, target, new Vector3( 0, 0, 1 ) )
  68083. );
  68084. this.setRotationFromQuaternion(quat);
  68085. this.position.copy(position);
  68086. let coneLength = (this.light.distance > 0) ? this.light.distance : 1000;
  68087. let coneWidth = coneLength * Math.tan( this.light.angle * 0.5 );
  68088. this.frustum.scale.set(coneWidth, coneWidth, coneLength);
  68089. }
  68090. }
  68091. //问题:如何转换到世界坐标?(缩放方向有bug。)
  68092. //add-------------------------------------
  68093. const OpaWhenNotSelect = 0.6;
  68094. const ScaleRatio = 3;
  68095. const OutlineColor = 0x666666;
  68096. //----------------------------------------
  68097. const hideFocusHandles = true;//add
  68098. class TransformationTool extends EventDispatcher{
  68099. constructor(viewer ) {
  68100. super();
  68101. this.viewer = viewer;
  68102. this.modesEnabled = {};//add
  68103. this.style = 'singleMode'; //建mesh时按照singleModes建的
  68104. this.scene = new Scene();
  68105. this.selection = [];
  68106. this.pivot = new Vector3();
  68107. this.dragging = false;
  68108. this.showPickVolumes = false;
  68109. this.viewer.inputHandler.registerInteractiveScene(this.scene);
  68110. this.viewer.inputHandler.addEventListener('selection_changed', (e) => {
  68111. /* for(let selected of this.selection){ //若不删除,应该会穿过选中的物体选到别的而不是取消选择
  68112. this.viewer.inputHandler.blacklist.delete(selected);
  68113. } */
  68114. this.selection = e.selection;
  68115. /* for(let selected of this.selection){
  68116. this.viewer.inputHandler.blacklist.add(selected);
  68117. } */
  68118. });
  68119. this.viewer.addEventListener('global_touchstart',(e)=>{ //add
  68120. this.update();
  68121. });
  68122. this.viewer.addEventListener('global_mousemove',(e)=>{ //add
  68123. this.onPointerMove();
  68124. });
  68125. let red = Potree.config.axis.x.color;
  68126. let green = Potree.config.axis.y.color;
  68127. let blue = Potree.config.axis.z.color;
  68128. let white = Potree.config.axis.xyz.color;
  68129. this.activeHandle = null;
  68130. this.scaleHandles = {
  68131. "scale.x+": {name: "scale.x+", node: new Object3D(), color: red, alignment: [+1, +0, +0]},
  68132. "scale.x-": {name: "scale.x-", node: new Object3D(), color: red, alignment: [-1, +0, +0]},
  68133. "scale.y+": {name: "scale.y+", node: new Object3D(), color: green, alignment: [+0, +1, +0]},
  68134. "scale.y-": {name: "scale.y-", node: new Object3D(), color: green, alignment: [+0, -1, +0]},
  68135. "scale.z+": {name: "scale.z+", node: new Object3D(), color: blue, alignment: [+0, +0, +1]},
  68136. "scale.z-": {name: "scale.z-", node: new Object3D(), color: blue, alignment: [+0, +0, -1]},
  68137. "lines": {name:'lines', node: new Object3D(), dontScale:true }//add
  68138. };
  68139. this.focusHandles = {
  68140. "focus.x+": {name: "focus.x+", node: new Object3D(), color: red, alignment: [+1, +0, +0]},
  68141. "focus.x-": {name: "focus.x-", node: new Object3D(), color: red, alignment: [-1, +0, +0]},
  68142. "focus.y+": {name: "focus.y+", node: new Object3D(), color: green, alignment: [+0, +1, +0]},
  68143. "focus.y-": {name: "focus.y-", node: new Object3D(), color: green, alignment: [+0, -1, +0]},
  68144. "focus.z+": {name: "focus.z+", node: new Object3D(), color: blue, alignment: [+0, +0, +1]},
  68145. "focus.z-": {name: "focus.z-", node: new Object3D(), color: blue, alignment: [+0, +0, -1]},
  68146. };
  68147. this.translationHandles = {
  68148. "translation.x": {name: "translation.x", node: new Object3D(), color: red, alignment: [1, 0, 0]},
  68149. "translation.y": {name: "translation.y", node: new Object3D(), color: green, alignment: [0, 1, 0]},
  68150. "translation.z": {name: "translation.z", node: new Object3D(), color: blue, alignment: [0, 0, 1]},
  68151. //add
  68152. 'translation.xyz':{name: "translation.xyz", node: new Object3D(),color: white, alignment: [0, 0, 0], alignment2: [1, 1, 1]},
  68153. 'translation.plane.xy':{name: "translation.plane.xy", node: new Object3D(),color: blue,alignment: [0, 0, 1], alignment2: [1, 1, 0]},
  68154. 'translation.plane.yz':{name: "translation.plane.yz", node: new Object3D(),color: red, alignment: [1, 0, 0], alignment2: [0, 1, 1]},
  68155. 'translation.plane.xz':{name: "translation.plane.xz", node: new Object3D(),color: green, alignment: [0, 1, 0], alignment2: [1, 0, 1]},
  68156. };
  68157. this.rotationHandles = {
  68158. "rotation.x": {name: "rotation.x", node: new Object3D(), color: red, alignment: [1, 0, 0]},
  68159. "rotation.y": {name: "rotation.y", node: new Object3D(), color: green, alignment: [0, 1, 0]},
  68160. "rotation.z": {name: "rotation.z", node: new Object3D(), color: blue, alignment: [0, 0, 1]},
  68161. };
  68162. this.handles = Object.assign({}, this.scaleHandles, hideFocusHandles?{}:this.focusHandles, this.translationHandles, this.rotationHandles);
  68163. this.pickVolumes = [];
  68164. this.initializeScaleHandles();
  68165. this.initializeFocusHandles();
  68166. this.initializeTranslationHandles();
  68167. this.initializeRotationHandles();
  68168. let boxFrameGeometry = new Geometry();
  68169. {
  68170. // bottom
  68171. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  68172. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  68173. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  68174. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  68175. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  68176. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  68177. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  68178. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  68179. // top
  68180. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  68181. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  68182. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  68183. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  68184. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  68185. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  68186. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  68187. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  68188. // sides
  68189. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, 0.5));
  68190. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, 0.5));
  68191. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, 0.5));
  68192. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, 0.5));
  68193. boxFrameGeometry.vertices.push(new Vector3(0.5, -0.5, -0.5));
  68194. boxFrameGeometry.vertices.push(new Vector3(0.5, 0.5, -0.5));
  68195. boxFrameGeometry.vertices.push(new Vector3(-0.5, -0.5, -0.5));
  68196. boxFrameGeometry.vertices.push(new Vector3(-0.5, 0.5, -0.5));
  68197. }
  68198. this.frame = new LineSegments(boxFrameGeometry, new LineBasicMaterial({color: 0xffff00}));
  68199. this.scene.add(this.frame);
  68200. //------------------add-----------------------
  68201. this.setModeEnable(['scale','translation','rotation']);
  68202. Potree.Utils.setObjectLayers(this.scene, 'transformationTool' );
  68203. this.scene.traverse(e=>{
  68204. e.pickDontCheckDis = true; //pick时不需要识别是否在点云之上
  68205. });
  68206. {
  68207. let exist = (object)=>{//是否没被删除(暂时不考虑换了parent)
  68208. while(object.parent){
  68209. object = object.parent;
  68210. }
  68211. if(object instanceof Scene){
  68212. return true
  68213. }
  68214. };
  68215. this.history = new History({ //也可以写到全局,但需要加个判断物品是否存在的函数
  68216. applyData: (data)=>{
  68217. if(exist(data.object)){//viewer.scene.volumes.includes(data.box) //或许还要识别是否matrixAuto
  68218. data.matrix.decompose( data.object.position, data.object.quaternion, data.object.scale );
  68219. this.dispatchEvent('changeByHistory');
  68220. viewer.dispatchEvent('content_changed');
  68221. return true
  68222. }
  68223. } ,
  68224. getData:(data)=>{
  68225. return data
  68226. }
  68227. });
  68228. this.addEventListener('transformed', (e)=>{
  68229. let object = viewer.transformationTool.selection[0];
  68230. this.history.beforeChange({object, matrix:e.matrixBefore.clone()} );
  68231. this.viewer.dispatchEvent('content_changed');
  68232. });
  68233. this.addEventListener('stopDrag', (e)=>{
  68234. let object = viewer.transformationTool.selection[0];
  68235. object && this.history.afterChange({object, matrix:object.matrix.clone()} );
  68236. });
  68237. /* viewer.inputHandler.addEventListener('keydown', (e)=>{
  68238. if(e.keyCode == 90 && e.event.ctrlKey){//Z
  68239. this.history.undo()
  68240. }else if(e.keyCode == 89 && e.event.ctrlKey){//Y
  68241. this.history.redo()
  68242. }
  68243. }) */
  68244. }
  68245. }
  68246. setModeEnable(enableModes=[] ){//xzw add
  68247. let length=0;
  68248. ['translation','scale','rotation'].forEach(mode=>{
  68249. let handels = this[mode + 'Handles'];
  68250. let enable = enableModes.includes(mode);
  68251. for(let o in handels){
  68252. Potree.Utils.updateVisible(handels[o].node,'modeForce', !!enable);
  68253. }
  68254. this.modesEnabled[mode] = !!enable;
  68255. enable && length++;
  68256. });
  68257. if(this.style == 'singleMode' && length > 1){
  68258. this.changeStyle('mixedModes');
  68259. }else if(this.style == 'mixedModes' && length == 1){
  68260. this.changeStyle('singleMode');
  68261. }
  68262. }
  68263. changeStyle(style){// 切换单个mode & 多个mode混合 风格(因多个混合比较拥挤,需要做调整)
  68264. let s1 = style == 'singleMode' ? 30 : 25;
  68265. let s2 = style == 'singleMode' ? 15 : 10
  68266. ;['x','y','z'].forEach(axis=>{
  68267. this.translationHandles['translation.'+axis].node.children.forEach(mesh=>{
  68268. if(mesh.name.includes('arrow')){
  68269. Potree.Utils.updateVisible(mesh, 'modeStyle', style == 'singleMode');
  68270. }else if(mesh.name.includes('handle')){
  68271. mesh.material.lineWidth = style == 'singleMode' ? 5 : 7;
  68272. }
  68273. });
  68274. this.rotationHandles['rotation.'+axis].translateNode.scale.set(s1,s1,s1);
  68275. });
  68276. ['xy','yz','xz'].forEach(axis=>{
  68277. let handle = this.translationHandles['translation.plane.'+axis];
  68278. handle.node.children[0].scale.set(s2,s2,s2);
  68279. handle.node.children[0].position.fromArray(handle.alignment2).multiplyScalar(s2*1.5);
  68280. });
  68281. Potree.Utils.updateVisible(this.scaleHandles['lines'].node, 'modeStyle', style == 'singleMode');
  68282. this.style = style;
  68283. }
  68284. initializeTranslationHandles(){//大改
  68285. let boxGeometry = new BoxGeometry(1, 1, 1);
  68286. let length = 100 , arrowRadius = 4, arrowHeight = 10;
  68287. let arrowGeometry = new CylinderBufferGeometry( 0, arrowRadius, arrowHeight, 12, 1, false );//add 箭头朝(0,1,0)
  68288. let arrowInitialQua = new Quaternion().setFromAxisAngle(new Vector3(1,0,0), -Math.PI/2 );//先将qua旋转到朝向0,0,-1, 因为一般quaternion不设置时默认表示朝向0,0,-1,
  68289. let octahedronGeometry = new OctahedronBufferGeometry( 5, 0 );
  68290. let planeGeometry = new PlaneBufferGeometry( 1, 1 );
  68291. for(let handleName of Object.keys(this.translationHandles)){
  68292. let handle = this.handles[handleName];
  68293. let node = handle.node;
  68294. this.scene.add(node);
  68295. node.name = handleName;//add
  68296. let alignment = new Vector3(...handle.alignment);
  68297. let geometry , mesh, pickVolume, meshScale, pickScale, rotation, position, lookAtPoint, hasPick = true, meshPickable = false, renderOrder;
  68298. let matProp = {
  68299. color: handle.color,
  68300. opacity: OpaWhenNotSelect,
  68301. transparent: true,
  68302. side: handleName.includes('plane') ? DoubleSide : FrontSide
  68303. };
  68304. let material = new MeshBasicMaterial(matProp);
  68305. let pickMaterial = new MeshNormalMaterial({
  68306. opacity: 0.2,
  68307. transparent: true,
  68308. visible: this.showPickVolumes
  68309. });
  68310. if(handleName.includes('xyz') ){
  68311. geometry = octahedronGeometry;
  68312. meshPickable = true;
  68313. renderOrder = 12;
  68314. }else if(handleName.includes('plane') ){
  68315. geometry = planeGeometry;
  68316. meshPickable = true;
  68317. position = new Vector3(...handle.alignment2);
  68318. lookAtPoint = alignment;
  68319. if(handleName.includes('xy') ) {
  68320. }else if(handleName.includes('yz')){
  68321. }else if(handleName.includes('xz')){
  68322. }
  68323. }else {
  68324. geometry = boxGeometry;
  68325. let point = new Vector3(0,0,length/2);//new THREE.Vector3().copy(alignment).multiplyScalar(length/2)
  68326. mesh = LineDraw.createFatLine([point, point.clone().negate()],{lineWidth:6, mat : new LineDraw.createFatLineMat(matProp)});
  68327. lookAtPoint = alignment;
  68328. renderOrder = 10;
  68329. pickScale = new Vector3(4, 4, length+arrowHeight*2); //pickScale = new THREE.Vector3(4, 4, 1.2)
  68330. {
  68331. let arrow = new Mesh(arrowGeometry, material);
  68332. arrow.name = `${handleName}.arrow`;
  68333. arrow.renderOrder = 11;
  68334. arrow.position.set( ...handle.alignment).multiplyScalar(length/2+arrowHeight/2);
  68335. arrow.lookAt(0,0,0);
  68336. node.add(arrow);
  68337. let arrow2 = arrow.clone();
  68338. arrow2.position.negate();
  68339. arrow2.lookAt(0,0,0);
  68340. node.add(arrow2);
  68341. arrow.quaternion.multiply(arrowInitialQua); //乘上初始旋转
  68342. arrow2.quaternion.multiply(arrowInitialQua);
  68343. }
  68344. }
  68345. mesh || (mesh = new Mesh(geometry,material));
  68346. mesh.name = `${handleName}.handle`;
  68347. node.add(mesh);
  68348. renderOrder && (mesh.renderOrder = renderOrder);
  68349. meshScale && mesh.scale.copy(meshScale);
  68350. rotation && mesh.rotation.copy(rotation);
  68351. lookAtPoint && mesh.lookAt(lookAtPoint);
  68352. position && mesh.position.copy(position);
  68353. if(!meshPickable && hasPick){
  68354. pickVolume = new Mesh(geometry, pickMaterial);
  68355. pickScale && pickVolume.scale.copy(pickScale);
  68356. }else if(hasPick && meshPickable){
  68357. pickVolume = mesh;
  68358. }
  68359. if(pickVolume){
  68360. if(mesh != pickVolume){
  68361. mesh.add(pickVolume);
  68362. pickVolume.name = `${handleName}.pick_volume`;
  68363. }else {
  68364. pickVolume.name += ' & pick_volume';
  68365. }
  68366. pickVolume.handle = handleName;
  68367. this.pickVolumes.push(pickVolume);
  68368. }
  68369. node.setOpacity = (target) => {
  68370. if(handleName.includes('plane')){
  68371. let more = 1.5; //减掉更多,使min更低,max还是1
  68372. target = 1 - (1-target)*more;
  68373. }
  68374. let opacity = {x: material.opacity};
  68375. let t = new TWEEN.Tween(opacity).to({x: target}, 0);
  68376. t.onUpdate(() => {
  68377. mesh.visible = opacity.x > 0;
  68378. pickVolume && (pickVolume.visible = opacity.x > 0);
  68379. material.opacity = opacity.x;
  68380. mesh.material.opacity = opacity.x;
  68381. //outlineMaterial.opacity = opacity.x;
  68382. pickMaterial.opacity = opacity.x * 0.5;
  68383. });
  68384. t.start();
  68385. };
  68386. pickVolume.addEventListener("drag", (e) => {this.dragTranslationHandle(e);});
  68387. pickVolume.addEventListener("drop", (e) => {this.dropTranslationHandle(e);});
  68388. }
  68389. }
  68390. initializeScaleHandles(){
  68391. let sgSphere = new SphereGeometry(1, 32, 32);
  68392. let sgLowPolySphere = new SphereGeometry(1, 16, 16);
  68393. for(let handleName of Object.keys(this.scaleHandles)){
  68394. let handle = this.scaleHandles[handleName];
  68395. let node = handle.node;
  68396. node.name = handleName;//add
  68397. this.scene.add(node);
  68398. if(handleName == 'lines'){ //add
  68399. ['x','y','z'].forEach(axis=>{
  68400. let handle1_ = this.scaleHandles['scale.'+axis+'+'];
  68401. let handle2_ = this.scaleHandles['scale.'+axis+'-'];
  68402. let line = LineDraw.createFatLine([
  68403. new Vector3().fromArray(handle1_.alignment).multiplyScalar(0.5),
  68404. new Vector3().fromArray(handle2_.alignment).multiplyScalar(0.5) ],
  68405. {color:handle1_.color, lineWidth:4} // , dontAlwaysSeen:true
  68406. );
  68407. node.add(line);
  68408. });
  68409. node.setOpacity = (opacity) => {
  68410. opacity *= 0.6;
  68411. node.children.forEach(e=>e.material.opacity = opacity);
  68412. };
  68413. continue;
  68414. }
  68415. node.position.set(...handle.alignment).multiplyScalar(0.5);
  68416. let material = new MeshBasicMaterial({
  68417. color: handle.color,
  68418. side:DoubleSide,//xzw add
  68419. opacity: OpaWhenNotSelect,
  68420. transparent: true
  68421. });
  68422. let outlineMaterial = new MeshBasicMaterial({
  68423. color: OutlineColor,
  68424. side: BackSide,
  68425. opacity: OpaWhenNotSelect,
  68426. transparent: true});
  68427. let pickMaterial = new MeshNormalMaterial({
  68428. opacity: 0.2,
  68429. transparent: true,
  68430. side:DoubleSide,//xzw add for orthoCam, 缩小画面时因球体放大导致到相机背面去了而看不到球体正面
  68431. visible: this.showPickVolumes});
  68432. let sphere = new Mesh(sgSphere, material);
  68433. sphere.scale.set(5, 5, 5 );
  68434. sphere.name = `${handleName}.handle`;
  68435. node.add(sphere);
  68436. sphere.renderOrder = 10;
  68437. /* let outline = new THREE.Mesh(sgSphere, outlineMaterial);
  68438. outline.scale.set(1.1, 1.1, 1.1);
  68439. outline.name = `${handleName}.outline`;
  68440. sphere.add(outline); */
  68441. let pickSphere = new Mesh(sgLowPolySphere, pickMaterial);
  68442. pickSphere.name = `${handleName}.pick_volume`;
  68443. pickSphere.scale.set(1.5, 1.5, 1.5);
  68444. sphere.add(pickSphere);
  68445. pickSphere.handle = handleName;
  68446. this.pickVolumes.push(pickSphere);
  68447. node.setOpacity = (target) => {
  68448. let opacity = {x: material.opacity};
  68449. let t = new TWEEN.Tween(opacity).to({x: target}, 0); //xzw改 原100毫秒,因为太慢容易选错
  68450. t.onUpdate(() => {
  68451. sphere.visible = opacity.x > 0;
  68452. pickSphere.visible = opacity.x > 0;
  68453. material.opacity = opacity.x;
  68454. outlineMaterial.opacity = opacity.x;
  68455. pickSphere.material.opacity = opacity.x * 0.5;
  68456. });
  68457. t.start();
  68458. };
  68459. pickSphere.addEventListener("drag", (e) => this.dragScaleHandle(e));
  68460. pickSphere.addEventListener("drop", (e) => this.dropScaleHandle(e));
  68461. pickSphere.addEventListener("mouseover", e => {
  68462. //node.setOpacity(1);
  68463. });
  68464. pickSphere.addEventListener("click", e => {
  68465. //e.consume();
  68466. });
  68467. pickSphere.addEventListener("mouseleave", e => {
  68468. //node.setOpacity(OpaWhenNotSelect);
  68469. });
  68470. }
  68471. }
  68472. initializeRotationHandles(){
  68473. let boldAdjust = 2.3;
  68474. let torusGeometry = new TorusGeometry(1.3, boldAdjust * 0.015, 8, 64, Math.PI / 2);
  68475. //let outlineGeometry = new THREE.TorusGeometry(1, boldAdjust * 0.018, 8, 64, Math.PI / 2);
  68476. let pickGeometry = new TorusGeometry(1.3, boldAdjust * 0.06, 6, 4, Math.PI / 2);
  68477. for(let handleName of Object.keys(this.rotationHandles)){
  68478. let handle = this.handles[handleName];
  68479. let node = handle.node;
  68480. this.scene.add(node);
  68481. node.name = handleName;//add
  68482. let material = new MeshBasicMaterial({
  68483. color: handle.color,
  68484. opacity: OpaWhenNotSelect,
  68485. transparent: true
  68486. });
  68487. /* let outlineMaterial = new THREE.MeshBasicMaterial({
  68488. color: OutlineColor,
  68489. side: THREE.BackSide,
  68490. opacity: OpaWhenNotSelect,
  68491. transparent: true
  68492. }); */
  68493. let pickMaterial = new MeshNormalMaterial({
  68494. opacity: 0.2,
  68495. transparent: true,
  68496. visible: this.showPickVolumes
  68497. });
  68498. let box = new Mesh(torusGeometry, material);
  68499. box.name = `${handleName}.handle`;
  68500. box.scale.set(30, 30, 30);
  68501. box.lookAt(new Vector3(...handle.alignment));
  68502. node.add(box);
  68503. handle.translateNode = box;
  68504. /* let outline = new THREE.Mesh(outlineGeometry, outlineMaterial);
  68505. outline.name = `${handleName}.outline`;
  68506. outline.scale.set(1, 1, 1);
  68507. outline.renderOrder = 0;
  68508. box.add(outline);
  68509. */
  68510. let pickVolume = new Mesh(pickGeometry, pickMaterial);
  68511. pickVolume.name = `${handleName}.pick_volume`;
  68512. pickVolume.scale.set(1, 1, 1);
  68513. pickVolume.handle = handleName;
  68514. box.add(pickVolume);
  68515. this.pickVolumes.push(pickVolume);
  68516. node.setOpacity = (target) => {
  68517. let opacity = {x: material.opacity};
  68518. let t = new TWEEN.Tween(opacity).to({x: target}, 0);
  68519. t.onUpdate(() => {
  68520. box.visible = opacity.x > 0;
  68521. pickVolume.visible = opacity.x > 0;
  68522. material.opacity = opacity.x;
  68523. //outlineMaterial.opacity = opacity.x;
  68524. pickMaterial.opacity = opacity.x * 0.5;
  68525. });
  68526. t.start();
  68527. };
  68528. //pickVolume.addEventListener("mouseover", (e) => {
  68529. // //let a = this.viewer.scene.getActiveCamera().getWorldDirection(new THREE.Vector3()).dot(pickVolume.getWorldDirection(new THREE.Vector3()));
  68530. // console.log(pickVolume.getWorldDirection(new THREE.Vector3()));
  68531. //});
  68532. pickVolume.addEventListener("drag", (e) => {this.dragRotationHandle(e);});
  68533. pickVolume.addEventListener("drop", (e) => {this.dropRotationHandle(e);});
  68534. }
  68535. }
  68536. initializeFocusHandles(){
  68537. if(hideFocusHandles)return//add
  68538. //let sgBox = new THREE.BoxGeometry(1, 1, 1);
  68539. let sgPlane = new PlaneGeometry(4, 4, 1, 1);
  68540. let sgLowPolySphere = new SphereGeometry(1, 16, 16);
  68541. let texture = new TextureLoader().load(`${exports.resourcePath}/icons/eye_2.png`);
  68542. for(let handleName of Object.keys(this.focusHandles)){
  68543. let handle = this.focusHandles[handleName];
  68544. let node = handle.node;
  68545. this.scene.add(node);
  68546. let align = handle.alignment;
  68547. node.name = handleName;//add
  68548. //node.lookAt(new THREE.Vector3().addVectors(node.position, new THREE.Vector3(...align)));
  68549. node.lookAt(new Vector3(...align));
  68550. let off = 0.8;
  68551. if(align[0] === 1){
  68552. node.position.set(1, off, -off).multiplyScalar(0.5);
  68553. node.rotation.z = Math.PI / 2;
  68554. }else if(align[0] === -1){
  68555. node.position.set(-1, -off, -off).multiplyScalar(0.5);
  68556. node.rotation.z = Math.PI / 2;
  68557. }else if(align[1] === 1){
  68558. node.position.set(-off, 1, -off).multiplyScalar(0.5);
  68559. node.rotation.set(Math.PI / 2, Math.PI, 0.0);
  68560. }else if(align[1] === -1){
  68561. node.position.set(off, -1, -off).multiplyScalar(0.5);
  68562. node.rotation.set(Math.PI / 2, 0.0, 0.0);
  68563. }else if(align[2] === 1){
  68564. node.position.set(off, off, 1).multiplyScalar(0.5);
  68565. }else if(align[2] === -1){
  68566. node.position.set(-off, off, -1).multiplyScalar(0.5);
  68567. }
  68568. let material = new MeshBasicMaterial({
  68569. color: handle.color,
  68570. opacity: 0,
  68571. transparent: true,
  68572. map: texture
  68573. });
  68574. //let outlineMaterial = new THREE.MeshBasicMaterial({
  68575. // color: 0x000000,
  68576. // side: THREE.BackSide,
  68577. // opacity: 0,
  68578. // transparent: true});
  68579. let pickMaterial = new MeshNormalMaterial({
  68580. //opacity: 0,
  68581. transparent: true,
  68582. visible: this.showPickVolumes});
  68583. let box = new Mesh(sgPlane, material);
  68584. box.name = `${handleName}.handle`;
  68585. box.scale.set(1.5, 1.5, 1.5);
  68586. box.position.set(0, 0, 0);
  68587. box.visible = false;
  68588. node.add(box);
  68589. //handle.focusNode = box;
  68590. //let outline = new THREE.Mesh(sgPlane, outlineMaterial);
  68591. //outline.scale.set(1.4, 1.4, 1.4);
  68592. //outline.name = `${handleName}.outline`;
  68593. //box.add(outline);
  68594. let pickSphere = new Mesh(sgLowPolySphere, pickMaterial);
  68595. pickSphere.name = `${handleName}.pick_volume`;
  68596. pickSphere.scale.set(2, 2, 2);
  68597. box.add(pickSphere);
  68598. pickSphere.handle = handleName;
  68599. this.pickVolumes.push(pickSphere);
  68600. node.setOpacity = (target) => {
  68601. let opacity = {x: material.opacity};
  68602. let t = new TWEEN.Tween(opacity).to({x: target}, 0);
  68603. t.onUpdate(() => {
  68604. pickSphere.visible = opacity.x > 0;
  68605. box.visible = opacity.x > 0;
  68606. material.opacity = opacity.x;
  68607. //outlineMaterial.opacity = opacity.x;
  68608. pickSphere.material.opacity = opacity.x * 0.5;
  68609. });
  68610. t.start();
  68611. };
  68612. //pickSphere.addEventListener("drag", e => {});
  68613. pickSphere.addEventListener("mouseup", e => {
  68614. //e.consume();
  68615. });
  68616. pickSphere.addEventListener("mousedown", e => {
  68617. //e.consume();
  68618. });
  68619. pickSphere.addEventListener("click", e => {
  68620. //e.consume();
  68621. let selected = this.selection[0];
  68622. let maxScale = Math.max(...selected.scale.toArray());
  68623. let minScale = Math.min(...selected.scale.toArray());
  68624. let handleLength = Math.abs(selected.scale.dot(new Vector3(...handle.alignment)));
  68625. let alignment = new Vector3(...handle.alignment).multiplyScalar(2 * maxScale / handleLength);
  68626. alignment.applyMatrix4(selected.matrixWorld);
  68627. let newCamPos = alignment;
  68628. let newCamTarget = selected.getWorldPosition(new Vector3());
  68629. Utils.moveTo(this.viewer.scene, newCamPos, newCamTarget);
  68630. });
  68631. pickSphere.addEventListener("mouseover", e => {
  68632. //box.setOpacity(1);
  68633. });
  68634. pickSphere.addEventListener("mouseleave", e => {
  68635. //box.setOpacity(OpaWhenNotSelect);
  68636. });
  68637. }
  68638. }
  68639. dragRotationHandle(e){
  68640. let drag = e.drag;
  68641. let handle = this.activeHandle;
  68642. let camera = this.viewer.mainViewport.camera;//this.viewer.scene.getActiveCamera();
  68643. if(!handle || !handle.name.includes('rotation') ){
  68644. return
  68645. };
  68646. let localNormal = new Vector3(...handle.alignment);
  68647. let n = new Vector3();
  68648. n.copy(new Vector4(...localNormal.toArray(), 0).applyMatrix4(handle.node.matrixWorld));
  68649. n.normalize();
  68650. if (!drag.intersectionStart){
  68651. //this.viewer.scene.scene.remove(this.debug);
  68652. //this.debug = new THREE.Object3D();
  68653. //this.viewer.scene.scene.add(this.debug);
  68654. //Utils.debugSphere(this.debug, drag.location, 3, 0xaaaaaa);
  68655. //let debugEnd = drag.location.clone().add(n.clone().multiplyScalar(20));
  68656. //Utils.debugLine(this.debug, drag.location, debugEnd, 0xff0000);
  68657. drag.intersectionStart = drag.location;
  68658. drag.objectStart = drag.object.getWorldPosition(new Vector3());
  68659. drag.handle = handle;
  68660. let plane = new Plane().setFromNormalAndCoplanarPoint(n, drag.intersectionStart);
  68661. drag.dragPlane = plane;
  68662. drag.pivot = drag.intersectionStart;
  68663. }else {
  68664. handle = drag.handle;
  68665. }
  68666. if(!drag.dragPlane)return//xzw add 因有时候没有
  68667. this.dragging = true;
  68668. let pointer = this.viewer.inputHandler.pointer;
  68669. let domElement = this.viewer.renderer.domElement;
  68670. let ray = Utils.mouseToRay(pointer, camera, domElement.clientWidth, domElement.clientHeight);
  68671. let I = ray.intersectPlane(drag.dragPlane, new Vector3());
  68672. if (I) {
  68673. let center = this.scene.getWorldPosition(new Vector3()); //bounding中心
  68674. let from = drag.pivot;
  68675. let to = I;
  68676. let v1 = from.clone().sub(center).normalize();
  68677. let v2 = to.clone().sub(center).normalize();
  68678. let angle = Math.acos(v1.dot(v2));
  68679. let sign = Math.sign(v1.cross(v2).dot(n));
  68680. angle = angle * sign;
  68681. if (Number.isNaN(angle)) {
  68682. return;
  68683. }
  68684. let matrixBefore = this.selection[0].matrix.clone();
  68685. let normal = new Vector3(...handle.alignment);
  68686. for (let selection of this.selection) {
  68687. //直接修改matrix,使整体绕boundingBox中心旋转。 xzw
  68688. let quaternion = selection.quaternion.clone();
  68689. let diffQua = new Quaternion().setFromAxisAngle( normal, angle );//变化量,参考 selection.rotateOnAxis(normal, angle);
  68690. let moveToZero = new Matrix4().setPosition(center.clone().negate()); //先将boundingBox中心(整体)移动到原点
  68691. let rotM = new Matrix4().makeRotationFromQuaternion(quaternion.clone().inverse().premultiply(diffQua).premultiply(quaternion) );//再旋转。根据selection.rotateOnAxis,应该是旧的qua 右乘 diffQua,所以先用invert消掉旧的qua
  68692. let moveBack = new Matrix4().setPosition(center.clone());//移动回去,使boundingBox中心位置还原
  68693. selection.matrix.premultiply(moveToZero).premultiply(rotM).premultiply(moveBack);
  68694. selection.matrix.decompose(selection.position, selection.quaternion, selection.scale);//记录 (scale基本不变)
  68695. selection.updateMatrixWorld();//xzw add 保险起见立即update
  68696. selection.dispatchEvent({
  68697. type: "orientation_changed",
  68698. object: selection
  68699. });
  68700. selection.dispatchEvent({//当boundingBox中心不在原点时
  68701. type: "position_changed",
  68702. object: selection
  68703. });
  68704. }
  68705. this.dispatchEvent({type:'transformed', changeType: ['orientation'], matrixBefore });//add
  68706. drag.pivot = I;
  68707. }
  68708. }
  68709. dropRotationHandle(e){
  68710. this.dragging = false;
  68711. this.setActiveHandle(null);
  68712. this.dispatchEvent({type:'stopDrag', handle:'rotation'});//add
  68713. }
  68714. dragTranslationHandle(e){//---大改,参考transformControls,为了加上xyz xy yz xz 这四个方向的变换。 (但感觉好像plane上有丢丢延迟?是因为drag延迟还是worldmatrix没更新)
  68715. let drag = e.drag;
  68716. let handle = this.activeHandle;
  68717. let camera = this.viewer.mainViewport.camera;//this.viewer.scene.getActiveCamera();
  68718. if(handle && handle.name.includes('translation') && this.selection[0]){
  68719. let posWorld = this.scene.getWorldPosition(new Vector3());//bounding中心
  68720. if(!drag.intersectionStart){
  68721. drag.intersectionStart = drag.location;
  68722. drag.worldPositionStart = this.selection[0].getWorldPosition(new Vector3());
  68723. drag.objectQua = this.selection[0].quaternion.clone();//不考虑父级
  68724. drag.objectQuaInv = drag.objectQua.clone().invert();
  68725. this.dragging = true;
  68726. }
  68727. if(drag.intersectionStart){
  68728. let pointer = this.viewer.inputHandler.pointer;
  68729. let ray = Utils.mouseToRay(pointer, camera);
  68730. //方向滑动所在面
  68731. let normal;
  68732. let axisName = handle.name.split('.').pop();
  68733. if(axisName == 'xyz'){ // 平行于屏幕滑动
  68734. normal = viewer.mainViewport.view.direction;
  68735. }else {
  68736. var alignVector = new Vector3();
  68737. normal = new Vector3;
  68738. let unitX = new Vector3( 1, 0, 0 ).applyQuaternion(drag.objectQua);
  68739. let unitY = new Vector3( 0, 1, 0 ).applyQuaternion(drag.objectQua);
  68740. let unitZ = new Vector3( 0, 0, 1 ).applyQuaternion(drag.objectQua);
  68741. switch (axisName) {
  68742. case 'x':
  68743. alignVector.copy( viewer.mainViewport.view.direction ).cross( unitX );
  68744. normal.copy( unitX ).cross( alignVector );
  68745. break;
  68746. case 'y':
  68747. alignVector.copy( viewer.mainViewport.view.direction ).cross( unitY );
  68748. normal.copy( unitY ).cross( alignVector );
  68749. break;
  68750. case 'z':
  68751. alignVector.copy( viewer.mainViewport.view.direction ).cross( unitZ );
  68752. normal.copy( unitZ ).cross( alignVector );
  68753. break;
  68754. case 'xy':
  68755. normal.copy( unitZ );
  68756. break;
  68757. case 'yz':
  68758. normal.copy( unitX );
  68759. break;
  68760. case 'xz':
  68761. normal.copy( unitY );
  68762. break;
  68763. }//参考transformControls.使跟手
  68764. }
  68765. drag.dragPlane = new Plane().setFromNormalAndCoplanarPoint(normal, posWorld/* drag.worldPositionStart */);//过center的与视线垂直的平面
  68766. let I = ray.intersectPlane(drag.dragPlane, new Vector3());
  68767. if (I) {
  68768. let offset = new Vector3().subVectors( I , drag.worldPositionStart );
  68769. //let offset = new THREE.Vector3().subVectors(iOnLine, drag.worldPositionStart);
  68770. if(!drag.pointStart){
  68771. drag.pointStart = offset;
  68772. }else {
  68773. drag.pointEnd = offset;
  68774. let diff = new Vector3().subVectors(drag.pointEnd, drag.pointStart);
  68775. diff.applyQuaternion(drag.objectQuaInv); // 得到在该物体local空间上的offset
  68776. if(!handle.name.includes('x')) diff.x = 0;
  68777. if(!handle.name.includes('y')) diff.y = 0;
  68778. if(!handle.name.includes('z')) diff.z = 0;
  68779. //恢复为world offset
  68780. diff.applyQuaternion(drag.objectQua);
  68781. //-------------
  68782. let matrixBefore = this.selection[0].matrix.clone();
  68783. this.selection[0].position.copy( diff ).add( drag.worldPositionStart );
  68784. for (let selection of this.selection) {
  68785. selection.updateMatrixWorld();//xzw add 保险起见立即update
  68786. selection.dispatchEvent({
  68787. type: "position_changed",
  68788. object: selection
  68789. });
  68790. }
  68791. this.dispatchEvent({type:'transformed', changeType: ['position'], matrixBefore});//add
  68792. }
  68793. }
  68794. }
  68795. }
  68796. }
  68797. dropTranslationHandle(e){
  68798. this.dragging = false;
  68799. this.setActiveHandle(null);
  68800. this.dispatchEvent({type:'stopDrag', handle:'translation'});//add
  68801. }
  68802. dropScaleHandle(e){
  68803. this.dragging = false;
  68804. this.setActiveHandle(null);
  68805. this.dispatchEvent({type:'stopDrag', handle:'scale'});//add
  68806. }
  68807. dragScaleHandle(e){
  68808. let drag = e.drag;
  68809. let handle = this.activeHandle;
  68810. if(!handle || !handle.name.includes('scale'))return
  68811. let camera = this.viewer.mainViewport.camera;//this.viewer.scene.getActiveCamera();
  68812. if(!drag.intersectionStart){
  68813. drag.intersectionStart = drag.location;
  68814. drag.objectStart = drag.object.getWorldPosition(new Vector3());
  68815. drag.handle = handle;
  68816. let start = drag.intersectionStart;
  68817. let dir = new Vector4(...handle.alignment, 0).applyMatrix4(this.scene.matrixWorld);
  68818. let end = new Vector3().addVectors(start, dir);
  68819. let line = new Line3(start.clone(), end.clone());
  68820. drag.line = line;
  68821. let normal;
  68822. if(camera.type == 'OrthographicCamera'){//xzw add
  68823. normal = new Vector3(0,0,-1).applyQuaternion(camera.quaternion);
  68824. }else {
  68825. let camOnLine = line.closestPointToPoint(camera.position, false, new Vector3());
  68826. normal = new Vector3().subVectors(camera.position, camOnLine);
  68827. }
  68828. let plane = new Plane().setFromNormalAndCoplanarPoint(normal, drag.intersectionStart); //过轴线的一个能铺满屏幕的平面
  68829. drag.dragPlane = plane;
  68830. drag.pivot = drag.intersectionStart;
  68831. //Utils.debugSphere(viewer.scene.scene, drag.pivot, 0.05);
  68832. }else {
  68833. handle = drag.handle;
  68834. }
  68835. this.dragging = true;
  68836. if(drag.dragPlane){//xzw add 因有时候没有
  68837. let pointer = this.viewer.inputHandler.pointer;
  68838. let domElement = this.viewer.renderer.domElement;
  68839. let ray = Utils.mouseToRay(pointer, camera, domElement.clientWidth, domElement.clientHeight);
  68840. let I = ray.intersectPlane(drag.dragPlane, new Vector3());
  68841. if (I) {
  68842. let iOnLine = drag.line.closestPointToPoint(I, false, new Vector3());
  68843. let direction = handle.alignment.reduce( (a, v) => a + v, 0);
  68844. let toObjectSpace = this.selection[0].matrixWorld.clone().invert();
  68845. let iOnLineOS = iOnLine.clone().applyMatrix4(toObjectSpace);
  68846. let pivotOS = drag.pivot.clone().applyMatrix4(toObjectSpace);
  68847. let diffOS = new Vector3().subVectors(iOnLineOS, pivotOS);
  68848. let dragDirectionOS = diffOS.clone().normalize();
  68849. if(iOnLine.distanceTo(drag.pivot) === 0){
  68850. dragDirectionOS.set(0, 0, 0);
  68851. }
  68852. let dragDirection = dragDirectionOS.dot(new Vector3(...handle.alignment));
  68853. let alignment = new Vector3(...handle.alignment);
  68854. let diff = new Vector3().subVectors(iOnLine, drag.pivot);
  68855. let diffScale = alignment.clone().multiplyScalar(diff.length() * direction * dragDirection);
  68856. //let diffPosition = diff.clone().multiplyScalar(0.5); //这个仅当bound包含原点才准确。
  68857. let matrixBefore = this.selection[0].matrix.clone();
  68858. for (let selection of this.selection) {
  68859. //xzw 改:否则不跟手
  68860. let {min,max} = selection.boundingBox;
  68861. let fixPoint = alignment.x != 0 ? (alignment.x > 0 ? min : max).clone().setY(0).setZ(0) : //要保证另一边不能移动
  68862. alignment.y != 0 ? (alignment.y > 0 ? min : max).clone().setX(0).setZ(0) :
  68863. (alignment.z > 0 ? min : max).clone().setX(0).setY(0);
  68864. let fixPointBefore = fixPoint.clone().applyMatrix4(selection.matrixWorld);
  68865. let size = selection.boundingBox.getSize(new Vector3);
  68866. let diffScale_ = diffScale.clone().divide(size);
  68867. size.x == 0 && (diffScale_.x = 0); //add 若为0,不改此轴大小
  68868. size.y == 0 && (diffScale_.y = 0);
  68869. size.z == 0 && (diffScale_.z = 0);
  68870. selection.scale.add(diffScale_);
  68871. selection.scale.max(new Vector3(0.1,0.1,0.1));
  68872. //selection.position.add(diffPosition);
  68873. selection.updateMatrixWorld();
  68874. let fixPointAfter = fixPoint.clone().applyMatrix4(this.selection[0].matrixWorld);
  68875. selection.position.sub(new Vector3().subVectors(fixPointAfter,fixPointBefore));//保证另一边不能移动所需要的位移
  68876. selection.updateMatrixWorld();//xzw add 保险起见立即update
  68877. selection.dispatchEvent({
  68878. type: "position_changed",
  68879. object: selection
  68880. });
  68881. selection.dispatchEvent({
  68882. type: "scale_changed",
  68883. object: selection
  68884. });
  68885. }
  68886. this.dispatchEvent({type:'transformed', changeType: ['position','scale'], matrixBefore});//add
  68887. drag.pivot.copy(iOnLine);
  68888. //Utils.debugSphere(viewer.scene.scene, drag.pivot, 0.05);
  68889. }
  68890. }
  68891. }
  68892. setActiveHandle(handle){
  68893. if(this.dragging){
  68894. return;
  68895. }
  68896. if(this.activeHandle === handle){
  68897. return;
  68898. }
  68899. this.activeHandle = handle;
  68900. if(handle === null){
  68901. for(let handleName of Object.keys(this.handles)){
  68902. let handle = this.handles[handleName];
  68903. handle.node.setOpacity(0);
  68904. }
  68905. }
  68906. viewer.dispatchEvent({type:'CursorChange', action: this.activeHandle ? 'add' : 'remove', name:'hoverTranHandle'});
  68907. if(!hideFocusHandles){
  68908. for(let handleName of Object.keys(this.focusHandles)){
  68909. let handle = this.focusHandles[handleName];
  68910. if(this.activeHandle === handle){
  68911. handle.node.setOpacity(1.0);
  68912. }else {
  68913. handle.node.setOpacity(OpaWhenNotSelect);
  68914. }
  68915. }
  68916. }
  68917. for(let handleName of Object.keys(this.translationHandles)){
  68918. let handle = this.translationHandles[handleName];
  68919. if(this.activeHandle === handle){
  68920. handle.node.setOpacity(1.0);
  68921. }else {
  68922. handle.node.setOpacity(OpaWhenNotSelect);
  68923. }
  68924. }
  68925. for(let handleName of Object.keys(this.rotationHandles)){
  68926. let handle = this.rotationHandles[handleName];
  68927. //if(this.activeHandle === handle){
  68928. // handle.node.setOpacity(1.0);
  68929. //}else{
  68930. // handle.node.setOpacity(OpaWhenNotSelect)
  68931. //}
  68932. handle.node.setOpacity(OpaWhenNotSelect);
  68933. }
  68934. for(let handleName of Object.keys(this.scaleHandles)){
  68935. let handle = this.scaleHandles[handleName];
  68936. if(this.activeHandle === handle){
  68937. handle.node.setOpacity(1.0);
  68938. if(!hideFocusHandles){
  68939. let relatedFocusHandle = this.focusHandles[handle.name.replace("scale", "focus")];
  68940. let relatedFocusNode = relatedFocusHandle.node;
  68941. relatedFocusNode.setOpacity(OpaWhenNotSelect);
  68942. }
  68943. for(let translationHandleName of Object.keys(this.translationHandles)){
  68944. let translationHandle = this.translationHandles[translationHandleName];
  68945. translationHandle.node.setOpacity(OpaWhenNotSelect);
  68946. }
  68947. //let relatedTranslationHandle = this.translationHandles[
  68948. // handle.name.replace("scale", "translation").replace(/[+-]/g, "")];
  68949. //let relatedTranslationNode = relatedTranslationHandle.node;
  68950. //relatedTranslationNode.setOpacity(OpaWhenNotSelect);
  68951. }else {
  68952. handle.node.setOpacity(OpaWhenNotSelect);
  68953. }
  68954. }
  68955. if(handle){
  68956. handle.node.setOpacity(1.0);
  68957. }
  68958. viewer.dispatchEvent('content_changed');
  68959. }
  68960. update () {
  68961. if(this.selection.length === 1){
  68962. this.scene.visible = true;
  68963. this.scene.updateMatrix();
  68964. this.scene.updateMatrixWorld();
  68965. let selected = this.selection[0];
  68966. //selected.updateMatrixWorld();//add 否则scale的sphere抖动
  68967. let world = selected.matrixWorld;
  68968. let camera = this.viewer.mainViewport.camera;//this.viewer.scene.getActiveCamera();
  68969. let domElement = this.viewer.renderer.domElement;
  68970. let center = selected.boundingBox.getCenter(new Vector3()).clone().applyMatrix4(selected.matrixWorld);
  68971. let scale = selected.boundingBox.getSize(new Vector3()).multiply(selected.scale);
  68972. scale.max(new Vector3(.1,.1,.1)); //xzw add 如果是plane,没有厚度,会导致该tool消失
  68973. this.scene.scale.copy(scale);
  68974. this.scene.position.copy(center);
  68975. this.scene.rotation.copy(selected.rotation); //这里只考虑当前子级的scale rotation
  68976. //如果是世界坐标 (缩放方向有bug。)
  68977. /*
  68978. let boundingBox = selected.boundingBox.clone().applyMatrix4(selected.matrixWorld);
  68979. let center = boundingBox.getCenter(new THREE.Vector3())
  68980. this.scene.position.copy(center);
  68981. this.scene.scale.copy(boundingBox.getSize(new THREE.Vector3()));
  68982. */
  68983. this.scene.updateMatrixWorld();
  68984. {
  68985. // adjust rotation handles
  68986. if(!this.dragging){
  68987. if(this.modesEnabled.rotation || this.modesEnabled.translation){
  68988. let tWorld = this.scene.matrixWorld;
  68989. let tObject = tWorld.clone().invert();
  68990. let camObjectPos = camera.getWorldPosition(new Vector3()).applyMatrix4(tObject);
  68991. if(this.modesEnabled.translation){//add
  68992. ['xy','yz','xz'].forEach(axis=>{
  68993. let handle = this.translationHandles["translation.plane."+axis];
  68994. let pos = handle.node.children[0].position;
  68995. camObjectPos.x && (pos.x = Math.sign(camObjectPos.x) * Math.abs(pos.x));
  68996. camObjectPos.y && (pos.y = Math.sign(camObjectPos.y) * Math.abs(pos.y));
  68997. camObjectPos.z && (pos.z = Math.sign(camObjectPos.z) * Math.abs(pos.z));
  68998. });
  68999. }
  69000. if(this.modesEnabled.rotation){
  69001. let above = camObjectPos.z > 0;
  69002. let below = !above;
  69003. let PI_HALF = Math.PI / 2;
  69004. let x = this.rotationHandles["rotation.x"].node.rotation;
  69005. let y = this.rotationHandles["rotation.y"].node.rotation;
  69006. let z = this.rotationHandles["rotation.z"].node.rotation;
  69007. x.order = "ZYX";
  69008. y.order = "ZYX";
  69009. if(above){
  69010. if(camObjectPos.x > 0 && camObjectPos.y > 0){
  69011. x.x = 1 * PI_HALF;
  69012. y.y = 3 * PI_HALF;
  69013. z.z = 0 * PI_HALF;
  69014. }else if(camObjectPos.x < 0 && camObjectPos.y > 0){
  69015. x.x = 1 * PI_HALF;
  69016. y.y = 2 * PI_HALF;
  69017. z.z = 1 * PI_HALF;
  69018. }else if(camObjectPos.x < 0 && camObjectPos.y < 0){
  69019. x.x = 2 * PI_HALF;
  69020. y.y = 2 * PI_HALF;
  69021. z.z = 2 * PI_HALF;
  69022. }else if(camObjectPos.x > 0 && camObjectPos.y < 0){
  69023. x.x = 2 * PI_HALF;
  69024. y.y = 3 * PI_HALF;
  69025. z.z = 3 * PI_HALF;
  69026. }
  69027. }else if(below){
  69028. if(camObjectPos.x > 0 && camObjectPos.y > 0){
  69029. x.x = 0 * PI_HALF;
  69030. y.y = 0 * PI_HALF;
  69031. z.z = 0 * PI_HALF;
  69032. }else if(camObjectPos.x < 0 && camObjectPos.y > 0){
  69033. x.x = 0 * PI_HALF;
  69034. y.y = 1 * PI_HALF;
  69035. z.z = 1 * PI_HALF;
  69036. }else if(camObjectPos.x < 0 && camObjectPos.y < 0){
  69037. x.x = 3 * PI_HALF;
  69038. y.y = 1 * PI_HALF;
  69039. z.z = 2 * PI_HALF;
  69040. }else if(camObjectPos.x > 0 && camObjectPos.y < 0){
  69041. x.x = 3 * PI_HALF;
  69042. y.y = 0 * PI_HALF;
  69043. z.z = 3 * PI_HALF;
  69044. }
  69045. }
  69046. }
  69047. }
  69048. }
  69049. // adjust scale of components
  69050. for(let handleName of Object.keys(this.handles)){
  69051. let handle = this.handles[handleName];
  69052. let node = handle.node;
  69053. //xzw add:---- -当该轴正对相机时隐藏。(主要针对ortho类型camera。
  69054. if(!Potree.Utils.getObjVisiByReason(node,'modeForce') )continue;
  69055. let alignment = handle.alignment;
  69056. if(alignment && (!handleName.includes('rotation') || camera.type == 'OrthographicCamera')){//旋转的话正常都应该显示
  69057. let normal;
  69058. let dir = new Vector3(...alignment).applyQuaternion(this.scene.quaternion);
  69059. if(camera.type == 'OrthographicCamera'){
  69060. normal = new Vector3(0,0,-1).applyQuaternion(camera.quaternion);
  69061. }else {
  69062. normal = new Vector3().subVectors(center, camera.position).normalize();
  69063. }
  69064. let ifOnLine;
  69065. if(handleName.includes('rotation') || handleName.includes('plane')){ // 旋转轴和视线垂直时隐藏
  69066. ifOnLine = Math.abs(dir.dot(normal)) < 0.1;
  69067. }else {
  69068. ifOnLine = Math.abs(dir.dot(normal)) > 0.995;
  69069. }
  69070. Potree.Utils.updateVisible(node, 'faceToCamHide', !ifOnLine);
  69071. }else {
  69072. Potree.Utils.updateVisible(node, 'faceToCamHide', true);
  69073. }
  69074. if(!node.visible)continue;
  69075. //------------------------------------------------------------------------
  69076. if(handle.dontScale)continue; //add
  69077. let handlePos = node.getWorldPosition(new Vector3());
  69078. let distance = handlePos.distanceTo(camera.position);
  69079. let pr = Utils.projectedRadius(1, camera, distance, domElement.clientWidth, domElement.clientHeight);
  69080. let ws = node.parent.getWorldScale(new Vector3());
  69081. let s = (ScaleRatio / pr);
  69082. let scale = new Vector3(s, s, s).divide(ws);
  69083. let rot = new Matrix4().makeRotationFromEuler(node.rotation); //需要使用到旋转,所以我把设置scale的移到旋转后了,否则在视图上下旋转的分界线处rotateHandel会被拉长从而闪烁。
  69084. let rotInv = rot.clone().invert();
  69085. scale.applyMatrix4(rotInv);
  69086. scale.x = Math.abs(scale.x);
  69087. scale.y = Math.abs(scale.y);
  69088. scale.z = Math.abs(scale.z);
  69089. node.scale.copy(scale);
  69090. }
  69091. }
  69092. }else {
  69093. this.scene.visible = false;
  69094. }
  69095. }
  69096. onPointerMove(){
  69097. let pointer = this.viewer.inputHandler.pointer;
  69098. let camera = this.viewer.mainViewport.camera;
  69099. if( this.selection.length === 1 && !this.dragging ){ //xzw 添加dragging条件
  69100. let ray = Utils.mouseToRay(pointer, camera );
  69101. let raycaster = new Raycaster(ray.origin, ray.direction);
  69102. raycaster.layers.enableAll();//add
  69103. let pickVolumes = this.pickVolumes.filter(v=>{
  69104. let mode = v.handle.split('.')[0];
  69105. if(!this.modesEnabled[mode])return
  69106. return v.parent.parent.visible //可能被隐藏该轴
  69107. });
  69108. let intersects = raycaster.intersectObjects(pickVolumes, true);
  69109. intersects = intersects.sort(function(a,b){
  69110. let order2 = b.object.renderOrder || 0;
  69111. let order1 = a.object.renderOrder || 0;
  69112. return order2-order1
  69113. }); // 降序
  69114. if(intersects.length > 0){
  69115. let I = intersects[0];
  69116. let handleName = I.object.handle;
  69117. //console.log(handleName)
  69118. this.setActiveHandle(this.handles[handleName]);
  69119. }else {
  69120. this.setActiveHandle(null);
  69121. }
  69122. }
  69123. }
  69124. };
  69125. /*
  69126. note:
  69127. transformationTool.scene会跟随选中物体,其scale就是boundingbox的大小。因此transformationTool.frame这个框也会跟着缩放
  69128. */
  69129. const boxOpacity = {
  69130. hovered : 0.1,
  69131. selected : 0.2
  69132. };
  69133. const LineOpacity = {
  69134. default : 0.6,
  69135. selected: 1,
  69136. };
  69137. const colors = {
  69138. 2: 0x2ee4ce,//0x00ff80, //可见
  69139. 3: 0xffc23b,//0xff3158, //不可见
  69140. 4: 0xffffff, //
  69141. };
  69142. class Volume$1 extends Object3D {
  69143. constructor (args = {}) {
  69144. super();
  69145. if(this.constructor.name === "Volume"){
  69146. console.warn("Can't create object of class Volume directly. Use classes BoxVolume or SphereVolume instead.");
  69147. }
  69148. this._clip = args.clip || false;
  69149. this._visible = true;
  69150. //this.showVolumeLabel = true;
  69151. this._modifiable = args.modifiable || true;
  69152. { // event listeners
  69153. this.addEventListener('select', e => {
  69154. //console.log('select')
  69155. this.setSelected(true);
  69156. });
  69157. this.addEventListener('deselect', e => {
  69158. //console.log('deselect')
  69159. this.setSelected(false);
  69160. });
  69161. this.addEventListener('mouseover', e => {
  69162. this.hovered = true;
  69163. this.update();
  69164. });
  69165. this.addEventListener('mouseleave', e => {
  69166. this.hovered = false;
  69167. this.update();
  69168. });
  69169. }
  69170. }
  69171. setSelected(state){//add
  69172. this.selected = !!state;
  69173. this.update();
  69174. }
  69175. get visible(){
  69176. return this._visible;
  69177. }
  69178. set visible(value){
  69179. if(this._visible !== value){
  69180. this._visible = value;
  69181. this.dispatchEvent({type: "visibility_changed", object: this});
  69182. }
  69183. }
  69184. getVolume () {
  69185. console.warn("override this in subclass");
  69186. }
  69187. update () {
  69188. };
  69189. raycast (raycaster, intersects) {
  69190. }
  69191. get clip () {
  69192. return this._clip;
  69193. }
  69194. set clip (value) {
  69195. if(this._clip !== value){
  69196. this._clip = value;
  69197. this.update();
  69198. this.dispatchEvent({
  69199. type: "clip_changed",
  69200. object: this
  69201. });
  69202. }
  69203. }
  69204. get modifieable () {
  69205. return this._modifiable;
  69206. }
  69207. set modifieable (value) {
  69208. this._modifiable = value;
  69209. this.update();
  69210. }
  69211. };
  69212. class BoxVolume$1 extends Volume$1{
  69213. constructor(args = {}){
  69214. super(args);
  69215. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  69216. this.name = 'box_' + this.constructor.counter;
  69217. this.clipTask = args.clipTask || Potree.ClipTask.SHOW_INSIDE; //add
  69218. this.showBox = true;
  69219. let boxGeometry = new BoxGeometry(1, 1, 1);
  69220. boxGeometry.computeBoundingBox();
  69221. let boxFrameGeometry = new Geometry();
  69222. let Vector3$1 = Vector3;
  69223. {
  69224. boxFrameGeometry.vertices.push(
  69225. // bottom
  69226. new Vector3$1(-0.5, -0.5, 0.5),
  69227. new Vector3$1(0.5, -0.5, 0.5),
  69228. new Vector3$1(0.5, -0.5, 0.5),
  69229. new Vector3$1(0.5, -0.5, -0.5),
  69230. new Vector3$1(0.5, -0.5, -0.5),
  69231. new Vector3$1(-0.5, -0.5, -0.5),
  69232. new Vector3$1(-0.5, -0.5, -0.5),
  69233. new Vector3$1(-0.5, -0.5, 0.5),
  69234. // top
  69235. new Vector3$1(-0.5, 0.5, 0.5),
  69236. new Vector3$1(0.5, 0.5, 0.5),
  69237. new Vector3$1(0.5, 0.5, 0.5),
  69238. new Vector3$1(0.5, 0.5, -0.5),
  69239. new Vector3$1(0.5, 0.5, -0.5),
  69240. new Vector3$1(-0.5, 0.5, -0.5),
  69241. new Vector3$1(-0.5, 0.5, -0.5),
  69242. new Vector3$1(-0.5, 0.5, 0.5),
  69243. // sides
  69244. new Vector3$1(-0.5, -0.5, 0.5),
  69245. new Vector3$1(-0.5, 0.5, 0.5),
  69246. new Vector3$1(0.5, -0.5, 0.5),
  69247. new Vector3$1(0.5, 0.5, 0.5),
  69248. new Vector3$1(0.5, -0.5, -0.5),
  69249. new Vector3$1(0.5, 0.5, -0.5),
  69250. new Vector3$1(-0.5, -0.5, -0.5),
  69251. new Vector3$1(-0.5, 0.5, -0.5),
  69252. );
  69253. }
  69254. this.material = new DepthBasicMaterial({
  69255. color: colors[this.clipTask],
  69256. side:DoubleSide,
  69257. transparent: true,
  69258. opacity: boxOpacity.hovered,
  69259. depthTest: true,
  69260. depthWrite: false,
  69261. useDepth:true,
  69262. clipDistance : 2,//消失距离
  69263. occlusionDistance: 0.1,//变为backColor距离
  69264. maxClipFactor: 0.9,
  69265. });
  69266. this.box = new Mesh(boxGeometry, this.material);
  69267. this.box.geometry.computeBoundingBox();
  69268. this.boundingBox = this.box.geometry.boundingBox;
  69269. this.add(this.box);
  69270. //this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: colors[this.clipTask], opacity:LineOpacity.default/* 0xff2050 */}));
  69271. this.frame = LineDraw.createFatLine(
  69272. boxFrameGeometry.vertices,
  69273. { color: colors[this.clipTask], opacity:LineOpacity.default, lineWidth:1, dontAlwaysSeen:true} );
  69274. // this.frame.mode = THREE.Lines;
  69275. this.add(this.frame);
  69276. this.update();
  69277. }
  69278. update(){
  69279. this.boundingBox = this.box.geometry.boundingBox;
  69280. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  69281. Potree.Utils.updateVisible(this.box, 'selected', (this.selected || this.hovered) && this.showBox);
  69282. this.box.material.opacity = this.selected ? boxOpacity.selected : boxOpacity.hovered;
  69283. this.box.material.color.set(colors[this.clipTask]);
  69284. this.frame.material.color.set(colors[this.clipTask]);
  69285. this.frame.material.opacity = this.selected ? LineOpacity.selected : LineOpacity.default;
  69286. this.frame.material.lineWidth = this.selected ? 2 : 1;
  69287. }
  69288. raycast (raycaster, intersects) {
  69289. let is = [];
  69290. this.box.raycast(raycaster, is);
  69291. if (is.length > 0) {
  69292. let I = is[0];
  69293. intersects.push({
  69294. distance: I.distance,
  69295. object: this,
  69296. point: I.point.clone()
  69297. });
  69298. }
  69299. }
  69300. getVolume(){
  69301. return Math.abs(this.scale.x * this.scale.y * this.scale.z);
  69302. }
  69303. };
  69304. class SphereVolume$2 extends Volume$1{
  69305. constructor(args = {}){
  69306. super(args);
  69307. this.constructor.counter = (this.constructor.counter === undefined) ? 0 : this.constructor.counter + 1;
  69308. this.name = 'sphere_' + this.constructor.counter;
  69309. let sphereGeometry = new SphereGeometry(1, 32, 32);
  69310. sphereGeometry.computeBoundingBox();
  69311. this.material = new MeshBasicMaterial({
  69312. color: 0x00ff00,
  69313. transparent: true,
  69314. opacity: 0.3,
  69315. depthTest: true,
  69316. depthWrite: false});
  69317. this.sphere = new Mesh(sphereGeometry, this.material);
  69318. this.sphere.visible = false;
  69319. this.sphere.geometry.computeBoundingBox();
  69320. this.boundingBox = this.sphere.geometry.boundingBox;
  69321. this.add(this.sphere);
  69322. this.label.visible = false;
  69323. let frameGeometry = new Geometry();
  69324. {
  69325. let steps = 64;
  69326. let uSegments = 8;
  69327. let vSegments = 5;
  69328. let r = 1;
  69329. for(let uSegment = 0; uSegment < uSegments; uSegment++){
  69330. let alpha = (uSegment / uSegments) * Math.PI * 2;
  69331. let dirx = Math.cos(alpha);
  69332. let diry = Math.sin(alpha);
  69333. for(let i = 0; i <= steps; i++){
  69334. let v = (i / steps) * Math.PI * 2;
  69335. let vNext = v + 2 * Math.PI / steps;
  69336. let height = Math.sin(v);
  69337. let xyAmount = Math.cos(v);
  69338. let heightNext = Math.sin(vNext);
  69339. let xyAmountNext = Math.cos(vNext);
  69340. let vertex = new Vector3(dirx * xyAmount, diry * xyAmount, height);
  69341. frameGeometry.vertices.push(vertex);
  69342. let vertexNext = new Vector3(dirx * xyAmountNext, diry * xyAmountNext, heightNext);
  69343. frameGeometry.vertices.push(vertexNext);
  69344. }
  69345. }
  69346. // creates rings at poles, just because it's easier to implement
  69347. for(let vSegment = 0; vSegment <= vSegments + 1; vSegment++){
  69348. //let height = (vSegment / (vSegments + 1)) * 2 - 1; // -1 to 1
  69349. let uh = (vSegment / (vSegments + 1)); // -1 to 1
  69350. uh = (1 - uh) * (-Math.PI / 2) + uh *(Math.PI / 2);
  69351. let height = Math.sin(uh);
  69352. console.log(uh, height);
  69353. for(let i = 0; i <= steps; i++){
  69354. let u = (i / steps) * Math.PI * 2;
  69355. let uNext = u + 2 * Math.PI / steps;
  69356. let dirx = Math.cos(u);
  69357. let diry = Math.sin(u);
  69358. let dirxNext = Math.cos(uNext);
  69359. let diryNext = Math.sin(uNext);
  69360. let xyAmount = Math.sqrt(1 - height * height);
  69361. let vertex = new Vector3(dirx * xyAmount, diry * xyAmount, height);
  69362. frameGeometry.vertices.push(vertex);
  69363. let vertexNext = new Vector3(dirxNext * xyAmount, diryNext * xyAmount, height);
  69364. frameGeometry.vertices.push(vertexNext);
  69365. }
  69366. }
  69367. }
  69368. this.frame = new LineSegments(frameGeometry, new LineBasicMaterial({color: 0x000000}));
  69369. this.add(this.frame);
  69370. let frameMaterial = new MeshBasicMaterial({wireframe: true, color: 0x000000});
  69371. this.frame = new Mesh(sphereGeometry, frameMaterial);
  69372. //this.add(this.frame);
  69373. //this.frame = new THREE.LineSegments(boxFrameGeometry, new THREE.LineBasicMaterial({color: 0x000000}));
  69374. // this.frame.mode = THREE.Lines;
  69375. //this.add(this.frame);
  69376. this.update();
  69377. }
  69378. update(){
  69379. this.boundingBox = this.sphere.geometry.boundingBox;
  69380. this.boundingSphere = this.boundingBox.getBoundingSphere(new Sphere());
  69381. //if (this._clip) {
  69382. // this.sphere.visible = false;
  69383. // this.label.visible = false;
  69384. //} else {
  69385. // this.sphere.visible = true;
  69386. // this.label.visible = this.showVolumeLabel;
  69387. //}
  69388. }
  69389. raycast (raycaster, intersects) {
  69390. let is = [];
  69391. this.sphere.raycast(raycaster, is);
  69392. if (is.length > 0) {
  69393. let I = is[0];
  69394. intersects.push({
  69395. distance: I.distance,
  69396. object: this,
  69397. point: I.point.clone()
  69398. });
  69399. }
  69400. }
  69401. // see https://en.wikipedia.org/wiki/Ellipsoid#Volume
  69402. getVolume(){
  69403. return (4 / 3) * Math.PI * this.scale.x * this.scale.y * this.scale.z;
  69404. }
  69405. };
  69406. const renderOrders = {
  69407. line: 0 ,
  69408. spot: 15, //高过模型
  69409. };
  69410. const planeGeo$2 = new PlaneGeometry(1,1);
  69411. let texLoader$7 = new TextureLoader();
  69412. let lineMat = new LineBasicMaterial({
  69413. color: '#ffffff',
  69414. });
  69415. let spotMat;
  69416. const defaultLineLength = 0.6;
  69417. const defaultSpotScale = 0.4;
  69418. class Tag extends Object3D{
  69419. constructor(o){
  69420. super();
  69421. this.lineLength = o.lineLength != void 0 ? o.lineLength : defaultLineLength;
  69422. this.position.copy(o.position);
  69423. this.normal = o.normal != void 0 ? o.normal : new Vector3(0,0,-1);
  69424. this.root = o.root;
  69425. //this.matrixAutoUpdate = false
  69426. this.build();
  69427. /* this.spot.addEventListener('mouseover',()=>{
  69428. }) */
  69429. }
  69430. build(){
  69431. if(!spotMat){
  69432. spotMat = new MeshBasicMaterial({
  69433. transparent:true,
  69434. map: texLoader$7.load(Potree.resourcePath+'/textures/spot_default.png' ),
  69435. });
  69436. }
  69437. let endPos = this.normal.clone().multiplyScalar(this.lineLength);
  69438. this.line = LineDraw.createLine([
  69439. new Vector3(0,0,0),
  69440. endPos
  69441. ], {mat:lineMat});
  69442. let group = new Object3D();
  69443. this.spot = new Mesh(planeGeo$2, spotMat);
  69444. this.spot.scale.set(defaultSpotScale,defaultSpotScale,defaultSpotScale);
  69445. this.titleLabel = new TextSprite$2({root: group, text:'1', sizeInfo:{width2d:200},
  69446. textColor:{r:255,g:255,b:255,a:1.0},
  69447. backgroundColor:{r:0,g:0,b:0,a:0.8},
  69448. borderRadius: 6,
  69449. fontsize:13, fontWeight:'',//thick
  69450. renderOrder : renderOrders.spot, pickOrder:renderOrders.spot,
  69451. }); //更新sprite时,实际更新的是root: spot的矩阵
  69452. this.spot.renderOrder = renderOrders.spot;
  69453. /* const mainLabelProp = {
  69454. backgroundColor: {r: defaultColor.r*255, g: defaultColor.g*255, b: defaultColor.b*255, a:config.measure.default.opacity},
  69455. textColor: {r: textColor.r*255, g: textColor.g*255, b: textColor.b*255, a: 1.0},
  69456. fontsize:16,
  69457. useDepth : true ,
  69458. renderOrder : 5, pickOrder:5,
  69459. } */
  69460. this.titleLabel.position.set(0,0.4,0);
  69461. this.titleLabel.sprite.material.depthTest = this.titleLabel.sprite.material.depthWrite = true;
  69462. group.position.copy(endPos);
  69463. group.add(this.spot);
  69464. group.add(this.titleLabel);
  69465. this.add(group);
  69466. this.add(this.line);
  69467. viewer.scene.tags.add(this);
  69468. }
  69469. changeTitle(title){
  69470. this.titleLabel.changeText(title);
  69471. }
  69472. updateMatrixWorld(force){ //重写,只为了将root当做parent
  69473. this.updateMatrix();
  69474. this.matrixWorld.multiplyMatrices( this.root.matrixWorld, this.matrix );
  69475. const children = this.children;
  69476. for ( let i = 0, l = children.length; i < l; i ++ ) {
  69477. children[ i ].updateMatrixWorld( force );
  69478. }
  69479. }
  69480. updateWorldMatrix( updateParents, updateChildren ) {//重写,只为了将root当做parent
  69481. if ( updateParents === true && this.root !== null ) {
  69482. this.root.updateWorldMatrix( true, false );
  69483. }
  69484. if ( this.matrixAutoUpdate ) this.updateMatrix();
  69485. this.matrixWorld.multiplyMatrices( this.root.matrixWorld, this.matrix );
  69486. if ( updateChildren === true ) {
  69487. const children = this.children;
  69488. for ( let i = 0, l = children.length; i < l; i ++ ) {
  69489. children[ i ].updateWorldMatrix( false, true );
  69490. }
  69491. }
  69492. }
  69493. dispose(){
  69494. this.parent.remove(this);
  69495. this.titleLabel.dispose();
  69496. }
  69497. }
  69498. class TagTool extends EventDispatcher{
  69499. constructor (viewer) {
  69500. super();
  69501. this.viewer = viewer;
  69502. this.viewer.addEventListener('start_inserting_tag', e => {
  69503. this.viewer.dispatchEvent({
  69504. type: 'cancel_insertions'
  69505. });
  69506. });
  69507. }
  69508. createTagFromData(data){
  69509. let tag = new Tag({
  69510. title: data.title, position: data.position, normal: data.normal,
  69511. root: data.root //e.intersect.pointcloud || e.intersect.object
  69512. });
  69513. return tag
  69514. }
  69515. startInsertion (args = {}, callback, cancelFun) {
  69516. let deferred = $.Deferred();
  69517. this.viewer.dispatchEvent({
  69518. type: 'start_inserting_tag'
  69519. });
  69520. this.adding = true;
  69521. let cancel = ()=>{
  69522. end();
  69523. };
  69524. let end = ()=>{
  69525. this.adding = false;
  69526. viewer.dispatchEvent({type:"endTagMove"});
  69527. this.viewer.removeEventListener('global_click', click);
  69528. };
  69529. let click = (e)=>{
  69530. var worldPos = e.intersect && (/* e.intersect.orthoIntersect || */e.intersect.location);
  69531. if(!worldPos){
  69532. return
  69533. }
  69534. let localPos = Potree.Utils.datasetPosTransform({ toDataset: true, pointcloud:e.intersect.pointcloud, object:e.intersect.object, position:worldPos });
  69535. let tag = new Tag({
  69536. title: '1', position: localPos, normal:e.intersect.normal,
  69537. root: e.intersect.pointcloud || e.intersect.object
  69538. });
  69539. //pointcloud里加一个normal 的非float32
  69540. end();
  69541. e.consume && e.consume();
  69542. deferred.resolve(tag);
  69543. return {stopContinue:true}
  69544. };
  69545. this.viewer.addEventListener('global_click', click, {importance:10});
  69546. return deferred.promise()
  69547. }
  69548. }
  69549. const initDir = new Vector3(0,1,0);//指南针模型的北方向 向屏幕里
  69550. class Compass extends EventDispatcher{
  69551. constructor(dom, viewport){
  69552. super();
  69553. this.angle = 0;
  69554. this.show = false;
  69555. if(dom){
  69556. this.dom = $(dom);
  69557. }
  69558. this.viewport = viewport;
  69559. this.init();
  69560. }
  69561. init(){
  69562. var width = 100, height = 100;
  69563. if(!this.dom){
  69564. this.dom = $('<div name="compass"></div>');
  69565. $(viewer.renderArea).append(this.dom);
  69566. }
  69567. this.dom.css({ display:"none", position:"absolute",right:"1%",top: "60px",width:width+"px",height:height+"px", "z-index":100,"pointer-events":"none" });
  69568. let child = $("<div class='dirText north'><span>"+/* (config.lang=='zh'? */'北'/* :'N') */+"</span></div><div class='center'></div>");
  69569. this.dom.append(child);
  69570. this.dom.find(".dirText").css({textAlign:"center","font-size":"10px","position":"absolute",
  69571. width: "100%",
  69572. height: "25px",
  69573. "line-height": "25px"});
  69574. this.dom.find(".north").css({"color":"#02a0e9","top":"0"});
  69575. this.dom.find(".south").css({"color":"#ff1414","bottom":"0"});
  69576. this.dom.find(".center").css({
  69577. //"background":`url(${config.getStaticResource('img')}/dire.png)`,
  69578. width: width/2+"px",
  69579. height: height/2+"px",
  69580. "background-size": "contain",
  69581. "background-position": "center",
  69582. left: "50%",
  69583. top: "50%",
  69584. transform: "translate(-50%,-50%)",
  69585. position: "absolute"
  69586. });
  69587. this.dom.find(".dirText").css({
  69588. "text-align": "center",
  69589. "font-size": "10px",
  69590. "color": "rgb(255, 255, 255)",
  69591. "position": "absolute",
  69592. "top": "50%",
  69593. "left": "50%",
  69594. "width": "45%",
  69595. "height": "0px",
  69596. "transform-origin": "left center",
  69597. });
  69598. this.dom.find(".dirText span").css({
  69599. display: "block",
  69600. position: "absolute",
  69601. right: "5px",
  69602. top: "0",
  69603. width: "20px",
  69604. height: "20px",
  69605. "line-height": "20px",
  69606. // "font-size": ".75rem ",
  69607. "margin-top": "-10px",
  69608. });
  69609. try {
  69610. this.renderer = new WebGLRenderer({ antialias: true, alpha:true });//许钟文 添加个抗锯齿,否则添加的线条锯齿严重,
  69611. this.renderer.autoClear = !0;
  69612. this.renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
  69613. this.renderer.domElement.setAttribute('name','compass');
  69614. this.renderer.setClearAlpha(0.0);
  69615. //xst修改
  69616. //this.renderer.setSize(width/2, height/2, false, window.devicePixelRatio ? window.devicePixelRatio : 1);
  69617. //xst修改
  69618. //this.renderer.setPixelRatio(window.devicePixelRatio ? window.devicePixelRatio : 1);
  69619. //this.renderer.setSize(width/2, height/2);
  69620. //xst修改
  69621. this.renderer.setDrawingBufferSize( width/2, height/2, window.devicePixelRatio ? window.devicePixelRatio : 1 );
  69622. //this.emit(SceneRendererEvents.ContextCreated)
  69623. } catch (e) {
  69624. viewer.dispatchEvent('webglError', {msg:e});
  69625. }
  69626. this.dom.find(".center")[0].appendChild(this.renderer.domElement);
  69627. this.renderer.domElement.style.width = this.renderer.domElement.style.height = '100%';
  69628. this.camera = new PerspectiveCamera;
  69629. this.camera.fov = 50;
  69630. this.camera.updateProjectionMatrix();
  69631. this.scene = new Scene,
  69632. this.scene.add(this.camera);
  69633. this.createCompass();
  69634. viewer.addEventListener('camera_changed', e => {
  69635. if (e.viewport == this.viewport && (e.changeInfo.quaternionChanged /* || e.changeInfo.quaternionChanged */)) {
  69636. this.update();
  69637. }
  69638. });
  69639. this.setDomPos();
  69640. if(this.viewport)this.setDisplay(true);
  69641. }
  69642. createCompass(){
  69643. //ConeBufferGeometry(radius : Float, height : Float, radialSegments : Integer, heightSegments : Integer, openEnded : Boolean, thetaStart : Float, thetaLength : Float)
  69644. const height = 2;
  69645. const geometry1 = new ConeBufferGeometry( 0.7, height, 4, true );
  69646. const geometry2 = new ConeBufferGeometry( 0.7, height, 4, true );
  69647. const material = new MeshBasicMaterial({
  69648. vertexColors :true
  69649. });
  69650. //指南针由两个四棱锥拼成,为了渐变颜色,采用指定vertexColor的方式。
  69651. var setColor = function(geometry, color1,color2){
  69652. const colors = [];
  69653. for ( let i = 0, n = geometry.attributes.position.count; i < n; ++ i ) {
  69654. colors.push( 1, 1, 1 );
  69655. }
  69656. var set = function(index, color){//设置第index个点的颜色
  69657. colors[index*3+0] = color[0];
  69658. colors[index*3+1] = color[1];
  69659. colors[index*3+2] = color[2];
  69660. };
  69661. var mid = [(color1[0]+color2[0])/2, (color1[1]+color2[1])/2, (color1[2]+color2[2])/2 ];
  69662. set(1,color1); set(5,color1);set(6,color1);
  69663. set(2,mid); set(3,mid);set(7,mid);
  69664. set(4,color2); set(8,color2);set(9,color2);
  69665. geometry.setAttribute("color", new BufferAttribute(new Float32Array(colors), 3));
  69666. };
  69667. var blue1 = [1/255,238/255,245/255]; //逐渐变深
  69668. var blue2 = [20/255,146/255,170/255];
  69669. var blue3 = [40/255,60/255,103/255];
  69670. setColor(geometry1, blue1,blue2);
  69671. setColor(geometry2, blue2,blue3);
  69672. /* 朝箭头方向看点构成如下 虽然geometry.attributes.position.count = 19 只有1-9设置的颜色是有效的 另外为什么7决定了上下两边的颜色呢…… 5、9可将其分成上下两个颜色
  69673. 6
  69674. /|\
  69675. / | \
  69676. 7 /_2|1_\ 5
  69677. \ 3|4 / 9
  69678. \ | /
  69679. \|/
  69680. 8
  69681. */
  69682. const cone = new Mesh( geometry1, material );
  69683. cone.position.setY(height/2);
  69684. geometry1.computeVertexNormals();//computeFaceNormals
  69685. geometry2.computeVertexNormals();
  69686. const cones = new Object3D();
  69687. cones.add(cone);
  69688. let cone2 = new Mesh( geometry2, material );
  69689. cone2.rotation.x = Math.PI;
  69690. cone2.position.setY(-height/2);
  69691. cones.add(cone2);
  69692. //cones.rotation.x = Math.PI / 2;//转向initDir的方向
  69693. //cones.rotation.z = Math.PI / 2;
  69694. cones.rotation.z = Math.PI ;//转向initDir的方向
  69695. cones.scale.set(0.7,0.7,0.7);
  69696. this.scene.add(cones);
  69697. this.cones = cones;
  69698. }
  69699. setNorth(){ //设置北方向,这决定了指南针自身的朝向。
  69700. const floors = store.getters['scene/houstFloor'].floors;
  69701. if(!floors || !floors.length){
  69702. return
  69703. }
  69704. const floor = floors[0];
  69705. const metadata = app.store.getters['scene/metadata'] || {};
  69706. this.angle = (floor && floor.dire || 0) + MathUtils.radToDeg(parseFloat(metadata.floorPlanAngle || 0)); //基础朝向
  69707. this.cones.rotation.y = Math.PI / 2 - MathUtils.degToRad(this.angle);
  69708. //console.log("dir:"+floor.dire+", floorPlanAngle:"+metadata.floorPlanAngle)
  69709. this.update();
  69710. }
  69711. update(quaternion){
  69712. if(!this.show)return;
  69713. if(!quaternion) quaternion = this.viewport.camera.quaternion.clone();
  69714. this.updateCamera(quaternion);
  69715. this.updateLabel(quaternion);
  69716. this.render();
  69717. }
  69718. /*updateLabel(quaternion){//更新北标签
  69719. var dir = viewer.mainViewport.view.direction;
  69720. var oriDir = initDir.clone() //指南针最初始时的北方向
  69721. var extraQua
  69722. if(objects.player.mode == "transitioning"){//当transitioning时,相机的quaternion不是用control的lookAt算出来,而是直接由一个quaternion过渡到另一个,这样相机将会是歪的,投影面也就不会是原先的水平面。
  69723. var tempCamera = new THREE.Camera(); //借用camera的lookAt算出如果正视同样的target, quaternion会是什么值。 将它乘以当前相机quaternion,得到的就是相机歪的旋转值。
  69724. tempCamera.position.copy(this.camera.position);
  69725. tempCamera.lookAt(tempCamera.position.clone().add(dir))
  69726. var q = tempCamera.quaternion.inverse()
  69727. extraQua = q.premultiply(quaternion) //歪掉的额外旋转值
  69728. }
  69729. //北标签的方向为指南针轮盘方向,也就是要将camera的方向投影到水平面上。 但是如果相机歪了,看到的世界都会歪一定角度,投影面也要歪一定角度。
  69730. var up = new THREE.Vector3(0,0,1) //投影水平面的法线,也是相机的摆正的up方向
  69731. extraQua && up.applyQuaternion(extraQua)
  69732. dir.projectOnPlane(up) //将方向投影到水平面上; 如果相机不是正视(extraQua不为0001),就要将水平面也转动
  69733. oriDir.projectOnPlane(up)//为什么initDir投影了和没有投影angle结果一样
  69734. var angle = dir.angleTo(oriDir)
  69735. if(dir.cross(oriDir).y > 0)angle = -angle
  69736. var deg = this.angle - 90 + THREE.Math.radToDeg(angle) //因为css写的样式初始是指向右方,和initDir差了90°,所以减去。
  69737. this.dom.find(".dirText").css( "transform","rotate("+deg+"deg)" )
  69738. this.dom.find(".dirText span").css("transform","rotate("+(-deg)+"deg)")
  69739. } */
  69740. updateLabel(quaternion){//更新北标签
  69741. let deg = MathUtils.radToDeg(this.viewport.view.yaw) - 90;
  69742. this.dom.find(".dirText").css( "transform","rotate("+deg+"deg)" );
  69743. this.dom.find(".dirText span").css("transform","rotate("+(-deg)+"deg)");
  69744. }
  69745. updateCamera(quaternion){ //更新canvas中的指南针表现,也就是更新相机,和场景中的相机朝向一致。
  69746. const radius = 5; //相机距离
  69747. this.camera.quaternion.copy(quaternion);
  69748. var dir = this.viewport.view.direction; //相机朝向
  69749. this.camera.position.copy(dir.multiplyScalar(radius).negate()); //相机绕着指南针中心(000)转动
  69750. }
  69751. changeViewport(viewport){
  69752. this.viewport = viewport;
  69753. this.update(); //因相机更新了
  69754. }
  69755. render(){
  69756. this.renderer.render(this.scene, this.camera);
  69757. }
  69758. setDisplay(state){
  69759. this.show = !!state;
  69760. if(this.show){
  69761. this.update();
  69762. this.dom.fadeIn(100);
  69763. }else {
  69764. this.dom.fadeOut(100);
  69765. }
  69766. }
  69767. setAutoDisplay(state){//被直接改变了dom的显示
  69768. this.autoJudgeShow = state;
  69769. if(state){
  69770. this._autoDisplayEvent = ()=>{
  69771. let oldShow = this.show;
  69772. this.show = !!this.renderer.domElement.clientHeight;
  69773. if(oldShow != this.show){
  69774. this.update();
  69775. }
  69776. };
  69777. viewer.addEventListener('update_start',this._autoDisplayEvent);
  69778. }else {
  69779. viewer.removeEventListener('update_start',this._autoDisplayEvent);
  69780. }
  69781. }
  69782. setDomPos(){
  69783. if(!this.viewport)return
  69784. let right = this.viewport.left + this.viewport.width;
  69785. this.dom.css({'right':((1-right)*100 + 1) + '%'});
  69786. }
  69787. }
  69788. class AxisViewer extends ViewerBase{
  69789. constructor(listenViewport, parentArea, options={}){
  69790. let domElement = $(`<div name="Axisdom" viewport=${listenViewport.name}></div>`);
  69791. $(parentArea).append(domElement);
  69792. let posInfo = Object.assign({
  69793. //default:
  69794. right: 0, top:0, width:'100px', height:'100px'
  69795. },options.domStyle,{
  69796. position:'absolute'
  69797. });
  69798. if(options.domStyle){
  69799. if(options.domStyle.bottom != void 0){
  69800. delete posInfo.top;
  69801. }
  69802. if(options.domStyle.left != void 0){
  69803. delete posInfo.right;
  69804. }
  69805. }
  69806. domElement.css(posInfo);
  69807. super(domElement[0],{name:'axis', antialias:true } );
  69808. this.listenViewport = listenViewport;
  69809. Object.defineProperty(listenViewport, 'axis', {
  69810. value: this,
  69811. writable: true, // 可写(可选)
  69812. enumerable: false, // 不可枚举
  69813. configurable: true // 可配置(可选)
  69814. });
  69815. this.scene = new Scene;
  69816. //this.camera = new THREE.PerspectiveCamera(30, 1, 1, this.radius*3);
  69817. let w = 50;
  69818. this.camera = new OrthographicCamera(-w/2,w/2,w/2,-w/2 , 1, w*4);
  69819. this.camera.zoom = 2.7;//(domElement.clientWidth || 300) / w * 1.267//zoom越大视野越小
  69820. this.camera.updateProjectionMatrix();
  69821. this.view = new ExtendView();
  69822. this.view.radius = 70;
  69823. this.viewports = [new Viewport( this.view, this.camera, {
  69824. left:0, bottom:0, width:1, height: 1, name:'axis'
  69825. }) ];
  69826. this.updateScreenSize();
  69827. this.createAxis();
  69828. let updateCamera = e => {
  69829. if (e.viewport == listenViewport && e.changeInfo.quaternionChanged) {
  69830. this.update();
  69831. }
  69832. };
  69833. viewer.addEventListener('camera_changed', updateCamera);
  69834. let repos = ()=>{
  69835. if(!listenViewport.active || listenViewport.width == 0 || listenViewport.height == 0){
  69836. return domElement.css('visibility','hidden')
  69837. }
  69838. domElement.css('visibility','visible');
  69839. let props = [['left','right', 'width'],['bottom','top', 'height']];
  69840. let set = (prop)=>{
  69841. let str;
  69842. let name = posInfo[prop[1]] != void 0 ? prop[1] : prop[0];
  69843. let percent = posInfo[prop[1]] != void 0 ? (1-listenViewport[prop[0]] - listenViewport[prop[2]]) : listenViewport[prop[0]];
  69844. if(posInfo[name] == 0 || posInfo[name].includes('%')){
  69845. str = (parseFloat(posInfo[name]) + percent * 100) + '%';
  69846. }else {//px
  69847. str = 'calc('+(percent * 100) + '% + ' + posInfo[name] + ')';
  69848. }
  69849. domElement.css(name, str);
  69850. };
  69851. set(props[0]);
  69852. set(props[1]);
  69853. };
  69854. this.listenViewport.addEventListener('resize',repos);
  69855. this.addEventListener('dispose',()=>{
  69856. viewer.removeEventListener('camera_changed', updateCamera);
  69857. viewer.removeEventListener('resize', repos);
  69858. });
  69859. repos();
  69860. this.update();
  69861. }
  69862. createAxis(){
  69863. let axis = new Object3D
  69864. ;['x','y','z'].forEach((axisText)=>{
  69865. let color = new Color().set(Potree.config.axis[axisText].color);
  69866. let group = new Object3D;
  69867. let line = LineDraw.createLine([new Vector3, new Vector3(0,0,7)],{color});
  69868. let label = this.createLabel(axisText, color);
  69869. label.position.set(0,0,11 /* + this.renderArea.clientWidth/200 */);
  69870. if(axisText == 'y'){
  69871. group.rotation.x = -Math.PI / 2;
  69872. }else if(axisText == 'x'){
  69873. group.rotation.y = Math.PI / 2;
  69874. }
  69875. group.add(line);
  69876. group.add(label);
  69877. axis.add(group);
  69878. });
  69879. this.axis = axis;
  69880. this.scene.add(this.axis);
  69881. }
  69882. createLabel(text, color){
  69883. let fontsize = this.renderArea.clientWidth / 5; //20//Math.round( Potree.math.linearClamp(this.renderArea.clientWidth, [80,500],[12,50]))
  69884. let s = 3100 / this.renderArea.clientWidth;
  69885. console.log('fontsize',fontsize);
  69886. let label = new TextSprite$2({
  69887. backgroundColor: {r: 0, g: 0, b: 0, a:0},
  69888. textColor: {r: color.r * 255, g: color.g*255, b: color.b*255, a:1},
  69889. fontsize,
  69890. //useDepth : true ,
  69891. renderOrder : 5,// pickOrder:5,
  69892. fontWeight:'Lighter',
  69893. text, name:'axis' ,
  69894. viewports: this.viewports
  69895. });
  69896. label.scale.set(s,s,s);
  69897. return label
  69898. }
  69899. update(){
  69900. this.updateCamera();
  69901. this.render();
  69902. }
  69903. updateCamera(){
  69904. let view = this.listenViewport.view;
  69905. this.view.yaw = view.yaw;
  69906. this.view.pitch = view.pitch;
  69907. var dir = view.direction; //相机朝向
  69908. this.view.position.copy(dir.multiplyScalar(this.view.radius).negate()); //相机绕着指南针中心(000)转动
  69909. this.view.applyToCamera(this.camera);
  69910. }
  69911. render(){
  69912. viewer.dispatchEvent({type:"render.begin", viewport:this.viewports[0]}); //update sprite
  69913. this.renderer.render(this.scene, this.camera);
  69914. }
  69915. dispose(){
  69916. this.axis.traverse((child)=>{
  69917. if(child instanceof TextSprite$2){
  69918. child.dispose();
  69919. }else if(child instanceof LineSegments){
  69920. child.material.dispose();
  69921. child.geometry.dispose();
  69922. }
  69923. });
  69924. super.dispose();
  69925. delete this.listenViewport.axis;
  69926. }
  69927. }
  69928. // Copied from three.js: WebGLRenderer.js
  69929. function paramThreeToGL$1(_gl, p) {
  69930. let extension;
  69931. if (p === RepeatWrapping) return _gl.REPEAT;
  69932. if (p === ClampToEdgeWrapping) return _gl.CLAMP_TO_EDGE;
  69933. if (p === MirroredRepeatWrapping) return _gl.MIRRORED_REPEAT;
  69934. if (p === NearestFilter) return _gl.NEAREST;
  69935. if (p === NearestMipMapNearestFilter) return _gl.NEAREST_MIPMAP_NEAREST;
  69936. if (p === NearestMipMapLinearFilter) return _gl.NEAREST_MIPMAP_LINEAR;
  69937. if (p === LinearFilter) return _gl.LINEAR;
  69938. if (p === LinearMipMapNearestFilter) return _gl.LINEAR_MIPMAP_NEAREST;
  69939. if (p === LinearMipMapLinearFilter) return _gl.LINEAR_MIPMAP_LINEAR;
  69940. if (p === UnsignedByteType) return _gl.UNSIGNED_BYTE;
  69941. if (p === UnsignedShort4444Type) return _gl.UNSIGNED_SHORT_4_4_4_4;
  69942. if (p === UnsignedShort5551Type) return _gl.UNSIGNED_SHORT_5_5_5_1;
  69943. if (p === UnsignedShort565Type) return _gl.UNSIGNED_SHORT_5_6_5;
  69944. if (p === ByteType) return _gl.BYTE;
  69945. if (p === ShortType) return _gl.SHORT;
  69946. if (p === UnsignedShortType) return _gl.UNSIGNED_SHORT;
  69947. if (p === IntType) return _gl.INT;
  69948. if (p === UnsignedIntType) return _gl.UNSIGNED_INT;
  69949. if (p === FloatType) return _gl.FLOAT;
  69950. if (p === HalfFloatType) {
  69951. extension = extensions.get('OES_texture_half_float');
  69952. if (extension !== null) return extension.HALF_FLOAT_OES;
  69953. }
  69954. if (p === AlphaFormat) return _gl.ALPHA;
  69955. if (p === RGBFormat) return _gl.RGB;
  69956. if (p === RGBAFormat) return _gl.RGBA;
  69957. if (p === LuminanceFormat) return _gl.LUMINANCE;
  69958. if (p === LuminanceAlphaFormat) return _gl.LUMINANCE_ALPHA;
  69959. if (p === DepthFormat) return _gl.DEPTH_COMPONENT;
  69960. if (p === DepthStencilFormat) return _gl.DEPTH_STENCIL;
  69961. if (p === AddEquation) return _gl.FUNC_ADD;
  69962. if (p === SubtractEquation) return _gl.FUNC_SUBTRACT;
  69963. if (p === ReverseSubtractEquation) return _gl.FUNC_REVERSE_SUBTRACT;
  69964. if (p === ZeroFactor) return _gl.ZERO;
  69965. if (p === OneFactor) return _gl.ONE;
  69966. if (p === SrcColorFactor) return _gl.SRC_COLOR;
  69967. if (p === OneMinusSrcColorFactor) return _gl.ONE_MINUS_SRC_COLOR;
  69968. if (p === SrcAlphaFactor) return _gl.SRC_ALPHA;
  69969. if (p === OneMinusSrcAlphaFactor) return _gl.ONE_MINUS_SRC_ALPHA;
  69970. if (p === DstAlphaFactor) return _gl.DST_ALPHA;
  69971. if (p === OneMinusDstAlphaFactor) return _gl.ONE_MINUS_DST_ALPHA;
  69972. if (p === DstColorFactor) return _gl.DST_COLOR;
  69973. if (p === OneMinusDstColorFactor) return _gl.ONE_MINUS_DST_COLOR;
  69974. if (p === SrcAlphaSaturateFactor) return _gl.SRC_ALPHA_SATURATE;
  69975. if (p === RGB_S3TC_DXT1_Format || p === RGBA_S3TC_DXT1_Format ||
  69976. p === RGBA_S3TC_DXT3_Format || p === RGBA_S3TC_DXT5_Format) {
  69977. extension = extensions.get('WEBGL_compressed_texture_s3tc');
  69978. if (extension !== null) {
  69979. if (p === RGB_S3TC_DXT1_Format) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  69980. if (p === RGBA_S3TC_DXT1_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  69981. if (p === RGBA_S3TC_DXT3_Format) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  69982. if (p === RGBA_S3TC_DXT5_Format$1) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  69983. }
  69984. }
  69985. if (p === RGB_PVRTC_4BPPV1_Format || p === RGB_PVRTC_2BPPV1_Format ||
  69986. p === RGBA_PVRTC_4BPPV1_Format || p === RGBA_PVRTC_2BPPV1_Format) {
  69987. extension = extensions.get('WEBGL_compressed_texture_pvrtc');
  69988. if (extension !== null) {
  69989. if (p === RGB_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  69990. if (p === RGB_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  69991. if (p === RGBA_PVRTC_4BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  69992. if (p === RGBA_PVRTC_2BPPV1_Format) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  69993. }
  69994. }
  69995. if (p === RGB_ETC1_Format) {
  69996. extension = extensions.get('WEBGL_compressed_texture_etc1');
  69997. if (extension !== null) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  69998. }
  69999. if (p === MinEquation || p === MaxEquation) {
  70000. extension = extensions.get('EXT_blend_minmax');
  70001. if (extension !== null) {
  70002. if (p === MinEquation) return extension.MIN_EXT;
  70003. if (p === MaxEquation) return extension.MAX_EXT;
  70004. }
  70005. }
  70006. if (p === UnsignedInt248Type) {
  70007. extension = extensions.get('WEBGL_depth_texture');
  70008. if (extension !== null) return extension.UNSIGNED_INT_24_8_WEBGL;
  70009. }
  70010. return 0;
  70011. };
  70012. let attributeLocations$1 = {
  70013. "position": {name: "position", location: 0},
  70014. "color": {name: "color", location: 1},
  70015. "rgba": {name: "color", location: 1},
  70016. "intensity": {name: "intensity", location: 2},
  70017. "classification": {name: "classification", location: 3},
  70018. "returnNumber": {name: "returnNumber", location: 4},
  70019. "return number": {name: "returnNumber", location: 4},
  70020. "returns": {name: "returnNumber", location: 4},
  70021. "numberOfReturns": {name: "numberOfReturns", location: 5},
  70022. "number of returns": {name: "numberOfReturns", location: 5},
  70023. "pointSourceID": {name: "pointSourceID", location: 6},
  70024. "source id": {name: "pointSourceID", location: 6},
  70025. "point source id": {name: "pointSourceID", location: 6},
  70026. "indices": {name: "indices", location: 7},
  70027. "normal": {name: "normal", location: 8},
  70028. "spacing": {name: "spacing", location: 9},
  70029. "gps-time": {name: "gpsTime", location: 10},
  70030. "aExtra": {name: "aExtra", location: 11},
  70031. };
  70032. class Shader$1 {
  70033. constructor(gl, name, vsSource, fsSource) {
  70034. this.gl = gl;
  70035. this.name = name;
  70036. this.vsSource = vsSource;
  70037. this.fsSource = fsSource;
  70038. this.cache = new Map();
  70039. this.vs = null;
  70040. this.fs = null;
  70041. this.program = null;
  70042. this.uniformLocations = {};
  70043. this.attributeLocations = {};
  70044. this.uniformBlockIndices = {};
  70045. this.uniformBlocks = {};
  70046. this.uniforms = {};
  70047. this.update(vsSource, fsSource);
  70048. }
  70049. update(vsSource, fsSource) {
  70050. this.vsSource = vsSource;
  70051. this.fsSource = fsSource;
  70052. this.linkProgram();
  70053. }
  70054. compileShader(shader, source){
  70055. let gl = this.gl;
  70056. gl.shaderSource(shader, source);
  70057. gl.compileShader(shader);
  70058. let success = gl.getShaderParameter(shader, gl.COMPILE_STATUS);
  70059. if (!success) {
  70060. let info = gl.getShaderInfoLog(shader);
  70061. let numberedSource = source.split("\n").map((a, i) => `${i + 1}`.padEnd(5) + a).join("\n");
  70062. throw `could not compile shader ${this.name}: ${info}, \n${numberedSource}`;
  70063. }
  70064. }
  70065. linkProgram() {
  70066. const tStart = performance.now();
  70067. let gl = this.gl;
  70068. this.uniformLocations = {};
  70069. this.attributeLocations = {};
  70070. this.uniforms = {};
  70071. gl.useProgram(null);
  70072. let cached = this.cache.get(`${this.vsSource}, ${this.fsSource}`);
  70073. if (cached) {
  70074. this.program = cached.program;
  70075. this.vs = cached.vs;
  70076. this.fs = cached.fs;
  70077. this.attributeLocations = cached.attributeLocations;
  70078. this.uniformLocations = cached.uniformLocations;
  70079. this.uniformBlocks = cached.uniformBlocks;
  70080. this.uniforms = cached.uniforms;
  70081. return;
  70082. } else {
  70083. this.vs = gl.createShader(gl.VERTEX_SHADER);
  70084. this.fs = gl.createShader(gl.FRAGMENT_SHADER);
  70085. this.program = gl.createProgram();
  70086. if( !gl.isProgram(this.program )){//创建失败 开启多个页面可能会,原因是webglcontextlost
  70087. //console.error('创建program失败');
  70088. viewer.dispatchEvent('webglError', {msg: 'potreeRenderer创建program失败'});
  70089. console.log(this.vs);
  70090. console.log(this.fs);
  70091. return;
  70092. }
  70093. for(let name of Object.keys(attributeLocations$1)){
  70094. let location = attributeLocations$1[name].location;
  70095. let glslName = attributeLocations$1[name].name;
  70096. gl.bindAttribLocation(this.program, location, glslName);
  70097. }
  70098. this.compileShader(this.vs, this.vsSource);
  70099. this.compileShader(this.fs, this.fsSource);
  70100. let program = this.program;
  70101. gl.attachShader(program, this.vs);
  70102. gl.attachShader(program, this.fs);
  70103. gl.linkProgram(program);
  70104. gl.detachShader(program, this.vs);
  70105. gl.detachShader(program, this.fs);
  70106. // 检测当前程序链接状态
  70107. let success = gl.getProgramParameter(program, gl.LINK_STATUS);
  70108. if (!success) {
  70109. let info = gl.getProgramInfoLog(program);
  70110. throw `could not link program ${this.name}: ${info}`;
  70111. }
  70112. { // attribute locations
  70113. let numAttributes = gl.getProgramParameter(program, gl.ACTIVE_ATTRIBUTES);
  70114. for (let i = 0; i < numAttributes; i++) {
  70115. let attribute = gl.getActiveAttrib(program, i);
  70116. let location = gl.getAttribLocation(program, attribute.name);
  70117. this.attributeLocations[attribute.name] = location;
  70118. }
  70119. }
  70120. { // uniform locations
  70121. let numUniforms = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS);
  70122. for (let i = 0; i < numUniforms; i++) {
  70123. let uniform = gl.getActiveUniform(program, i);
  70124. let location = gl.getUniformLocation(program, uniform.name);
  70125. this.uniformLocations[uniform.name] = location;
  70126. this.uniforms[uniform.name] = {
  70127. location: location,
  70128. value: null,
  70129. };
  70130. }
  70131. }
  70132. // uniform blocks
  70133. if( typeof WebGL2RenderingContext !== 'undefined' && gl instanceof WebGL2RenderingContext){ //WebGL2RenderingContext在mac的safari14以下是没有定义的
  70134. let numBlocks = gl.getProgramParameter(program, gl.ACTIVE_UNIFORM_BLOCKS);
  70135. for (let i = 0; i < numBlocks; i++) {
  70136. let blockName = gl.getActiveUniformBlockName(program, i);
  70137. let blockIndex = gl.getUniformBlockIndex(program, blockName);
  70138. this.uniformBlockIndices[blockName] = blockIndex;
  70139. gl.uniformBlockBinding(program, blockIndex, blockIndex);
  70140. let dataSize = gl.getActiveUniformBlockParameter(program, blockIndex, gl.UNIFORM_BLOCK_DATA_SIZE);
  70141. let uBuffer = gl.createBuffer();
  70142. gl.bindBuffer(gl.UNIFORM_BUFFER, uBuffer);
  70143. gl.bufferData(gl.UNIFORM_BUFFER, dataSize, gl.DYNAMIC_READ);
  70144. gl.bindBufferBase(gl.UNIFORM_BUFFER, blockIndex, uBuffer);
  70145. gl.bindBuffer(gl.UNIFORM_BUFFER, null);
  70146. this.uniformBlocks[blockName] = {
  70147. name: blockName,
  70148. index: blockIndex,
  70149. dataSize: dataSize,
  70150. buffer: uBuffer
  70151. };
  70152. }
  70153. }
  70154. let cached = {
  70155. program: this.program,
  70156. vs: this.vs,
  70157. fs: this.fs,
  70158. attributeLocations: this.attributeLocations,
  70159. uniformLocations: this.uniformLocations,
  70160. uniforms: this.uniforms,
  70161. uniformBlocks: this.uniformBlocks,
  70162. };
  70163. this.cache.set(`${this.vsSource}, ${this.fsSource}`, cached);
  70164. }
  70165. const tEnd = performance.now();
  70166. const duration = tEnd - tStart;
  70167. //console.log(`shader compile duration: ${duration.toFixed(3)}`);
  70168. }
  70169. setUniformMatrix4(name, value) {
  70170. const gl = this.gl;
  70171. const location = this.uniformLocations[name];
  70172. if (location == null) {
  70173. return;
  70174. }
  70175. let tmp = new Float32Array(value.elements);
  70176. gl.uniformMatrix4fv(location, false, tmp);
  70177. }
  70178. setUniform1f(name, value) {
  70179. const gl = this.gl;
  70180. const uniform = this.uniforms[name];
  70181. if (uniform === undefined) {
  70182. return;
  70183. }
  70184. if(uniform.value === value){
  70185. return;
  70186. }
  70187. uniform.value = value;
  70188. gl.uniform1f(uniform.location, value);
  70189. }
  70190. setUniformBoolean(name, value) {
  70191. const gl = this.gl;
  70192. const uniform = this.uniforms[name];
  70193. if (uniform === undefined) {
  70194. return;
  70195. }
  70196. if(uniform.value === value){
  70197. return;
  70198. }
  70199. uniform.value = value;
  70200. gl.uniform1i(uniform.location, value);
  70201. }
  70202. setUniformTexture(name, value) {
  70203. const gl = this.gl;
  70204. const location = this.uniformLocations[name];
  70205. if (location == null) {
  70206. return;
  70207. }
  70208. gl.uniform1i(location, value);
  70209. }
  70210. setUniform2f(name, value) {
  70211. const gl = this.gl;
  70212. const location = this.uniformLocations[name];
  70213. if (location == null) {
  70214. return;
  70215. }
  70216. gl.uniform2f(location, value[0], value[1]);
  70217. }
  70218. setUniform3f(name, value) {
  70219. const gl = this.gl;
  70220. const location = this.uniformLocations[name];
  70221. if (location == null) {
  70222. return;
  70223. }
  70224. gl.uniform3f(location, value[0], value[1], value[2]);
  70225. }
  70226. setUniform(name, value) {
  70227. if (value.constructor === Matrix4) {
  70228. this.setUniformMatrix4(name, value);
  70229. } else if (typeof value === "number") {
  70230. this.setUniform1f(name, value);
  70231. } else if (typeof value === "boolean") {
  70232. this.setUniformBoolean(name, value);
  70233. } else if (value instanceof WebGLTexture$1) {
  70234. this.setUniformTexture(name, value);
  70235. } else if (value instanceof Array) {
  70236. if (value.length === 2) {
  70237. this.setUniform2f(name, value);
  70238. } else if (value.length === 3) {
  70239. this.setUniform3f(name, value);
  70240. }
  70241. } else {
  70242. console.error("unhandled uniform type: ", name, value);
  70243. }
  70244. }
  70245. setUniform1i(name, value) {
  70246. let gl = this.gl;
  70247. let location = this.uniformLocations[name];
  70248. if (location == null) {
  70249. return;
  70250. }
  70251. gl.uniform1i(location, value);
  70252. }
  70253. };
  70254. class WebGLTexture$1 {
  70255. constructor(gl, texture, threeRenderer) {
  70256. this.gl = gl;
  70257. this.texture = texture;
  70258. if(texture.image && !(texture.image instanceof Image) && !texture.isCanvasTexture && !texture.isDataTexture){
  70259. //renderTarget的texture在创建renderTarget时已经初始化过 见setupRenderTarget
  70260. this.id = threeRenderer.properties.get(texture).__webglTexture || gl.createTexture();
  70261. this.isFromRenderTarget = true;
  70262. }else {
  70263. this.id = gl.createTexture();
  70264. }
  70265. this.target = gl.TEXTURE_2D;
  70266. this.version = -1;
  70267. this.update(texture);
  70268. }
  70269. update() {
  70270. if (!this.texture.image) {
  70271. this.version = this.texture.version;
  70272. return;
  70273. }
  70274. //if(this.isFromRenderTarget)return //没找到怎么update。 在three.js里的uploadTexture没找到。 这里会报错,可能是 state.texImage2D( 3553, 0, glInternalFormat, image.width, image.height, 0, glFormat, glType, null ),类似depthTex的写法
  70275. let gl = this.gl;
  70276. let texture = this.texture;
  70277. if (this.version === texture.version) {
  70278. return;
  70279. }
  70280. this.target = gl.TEXTURE_2D;
  70281. gl.bindTexture(this.target, this.id);
  70282. let level = 0;
  70283. let internalFormat = paramThreeToGL$1(gl, texture.format);
  70284. let width = texture.image.width;
  70285. let height = texture.image.height;
  70286. let border = 0;
  70287. let srcFormat = internalFormat;
  70288. let srcType = paramThreeToGL$1(gl, texture.type);
  70289. let data;
  70290. gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, texture.flipY);
  70291. gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha);
  70292. gl.pixelStorei(gl.UNPACK_ALIGNMENT, texture.unpackAlignment);
  70293. if (texture instanceof DataTexture) {
  70294. data = texture.image.data;
  70295. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  70296. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  70297. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL$1(gl, texture.magFilter));
  70298. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL$1(gl, texture.minFilter));
  70299. gl.texImage2D(this.target, level, internalFormat,
  70300. width, height, border, srcFormat, srcType,
  70301. data);
  70302. } else if ((texture instanceof CanvasTexture) || (texture instanceof Texture)) {
  70303. data = texture.image;
  70304. gl.texParameteri(this.target, gl.TEXTURE_WRAP_S, paramThreeToGL$1(gl, texture.wrapS));
  70305. gl.texParameteri(this.target, gl.TEXTURE_WRAP_T, paramThreeToGL$1(gl, texture.wrapT));
  70306. gl.texParameteri(this.target, gl.TEXTURE_MAG_FILTER, paramThreeToGL$1(gl, texture.magFilter));
  70307. gl.texParameteri(this.target, gl.TEXTURE_MIN_FILTER, paramThreeToGL$1(gl, texture.minFilter));
  70308. if(this.isFromRenderTarget){
  70309. //咋写?
  70310. //gl.texImage2D( 3553, 0, internalFormat, width, height, 0, srcFormat, srcType, null )
  70311. //console.log('isFromRenderTarget')
  70312. }else {
  70313. gl.texImage2D(this.target, level, internalFormat, internalFormat, srcType, data); //这个参数怎么跟我查的不一样呢
  70314. }
  70315. if (texture instanceof Texture) {gl.generateMipmap(gl.TEXTURE_2D);}
  70316. }
  70317. gl.bindTexture(this.target, null);
  70318. this.version = texture.version;
  70319. }
  70320. };
  70321. class WebGLBuffer$1 {
  70322. constructor() {
  70323. this.numElements = 0;
  70324. this.vao = null;
  70325. this.vbos = new Map();
  70326. }
  70327. };
  70328. class Renderer$1 {
  70329. constructor(threeRenderer) {
  70330. this.threeRenderer = threeRenderer;
  70331. this.gl = this.threeRenderer.getContext();
  70332. this.buffers = new Map();
  70333. this.shaders = new Map();
  70334. this.textures = new Map();
  70335. this.glTypeMapping = new Map();
  70336. this.glTypeMapping.set(Float32Array, this.gl.FLOAT);
  70337. this.glTypeMapping.set(Uint8Array, this.gl.UNSIGNED_BYTE);
  70338. this.glTypeMapping.set(Uint16Array, this.gl.UNSIGNED_SHORT);
  70339. this.toggle = 0;
  70340. }
  70341. deleteBuffer(geometry) {
  70342. let gl = this.gl;
  70343. let webglBuffer = this.buffers.get(geometry);
  70344. if (webglBuffer != null) {
  70345. for (let attributeName in geometry.attributes) {
  70346. gl.deleteBuffer(webglBuffer.vbos.get(attributeName).handle);
  70347. }
  70348. this.buffers.delete(geometry);
  70349. }
  70350. }
  70351. createBuffer(geometry){
  70352. let gl = this.gl;
  70353. let webglBuffer = new WebGLBuffer$1();
  70354. webglBuffer.vao = gl.createVertexArray();
  70355. webglBuffer.numElements = geometry.attributes.position.count;
  70356. gl.bindVertexArray(webglBuffer.vao);
  70357. for(let attributeName in geometry.attributes){
  70358. let bufferAttribute = geometry.attributes[attributeName];
  70359. let vbo = gl.createBuffer();
  70360. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  70361. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  70362. let normalized = bufferAttribute.normalized;
  70363. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  70364. if(attributeLocations$1[attributeName] === undefined){
  70365. //attributeLocation = attributeLocations["aExtra"];
  70366. }else {
  70367. let attributeLocation = attributeLocations$1[attributeName].location;
  70368. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  70369. gl.enableVertexAttribArray(attributeLocation);
  70370. }
  70371. webglBuffer.vbos.set(attributeName, {
  70372. handle: vbo,
  70373. name: attributeName,
  70374. count: bufferAttribute.count,
  70375. itemSize: bufferAttribute.itemSize,
  70376. type: geometry.attributes.position.array.constructor,
  70377. version: 0
  70378. });
  70379. }
  70380. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  70381. gl.bindVertexArray(null);
  70382. let disposeHandler = (event) => {
  70383. this.deleteBuffer(geometry);
  70384. geometry.removeEventListener("dispose", disposeHandler);
  70385. };
  70386. geometry.addEventListener("dispose", disposeHandler);
  70387. return webglBuffer;
  70388. }
  70389. updateBuffer(geometry){
  70390. let gl = this.gl;
  70391. let webglBuffer = this.buffers.get(geometry);
  70392. gl.bindVertexArray(webglBuffer.vao);
  70393. for(let attributeName in geometry.attributes){
  70394. let bufferAttribute = geometry.attributes[attributeName];
  70395. let normalized = bufferAttribute.normalized;
  70396. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  70397. let vbo = null;
  70398. if(!webglBuffer.vbos.has(attributeName)){
  70399. vbo = gl.createBuffer();
  70400. webglBuffer.vbos.set(attributeName, {
  70401. handle: vbo,
  70402. name: attributeName,
  70403. count: bufferAttribute.count,
  70404. itemSize: bufferAttribute.itemSize,
  70405. type: geometry.attributes.position.array.constructor,
  70406. version: bufferAttribute.version
  70407. });
  70408. }else {
  70409. vbo = webglBuffer.vbos.get(attributeName).handle;
  70410. webglBuffer.vbos.get(attributeName).version = bufferAttribute.version;
  70411. }
  70412. gl.bindBuffer(gl.ARRAY_BUFFER, vbo);
  70413. gl.bufferData(gl.ARRAY_BUFFER, bufferAttribute.array, gl.STATIC_DRAW);
  70414. if(attributeLocations$1[attributeName] === undefined){
  70415. //attributeLocation = attributeLocations["aExtra"];
  70416. }else {
  70417. let attributeLocation = attributeLocations$1[attributeName].location;
  70418. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  70419. gl.enableVertexAttribArray(attributeLocation);
  70420. }
  70421. }
  70422. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  70423. gl.bindVertexArray(null);
  70424. }
  70425. traverse(scene) {
  70426. let octrees = [];
  70427. let stack = [scene];
  70428. while (stack.length > 0) {
  70429. let node = stack.pop();
  70430. if (node instanceof PointCloudTree) {
  70431. octrees.push(node);
  70432. continue;
  70433. }
  70434. let visibleChildren = node.children.filter(c => c.visible);
  70435. stack.push(...visibleChildren);
  70436. }
  70437. let result = {
  70438. octrees: octrees
  70439. };
  70440. return result;
  70441. }
  70442. renderNodes(octree, nodes, visibilityTextureData, camera, target, shader, params) {
  70443. viewer.addTimeMark('renderNodes','start');
  70444. let gl = this.gl;
  70445. let material = params.material ? params.material : octree.material;
  70446. let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  70447. let view = camera.matrixWorldInverse;
  70448. if(params.viewOverride){
  70449. view = params.viewOverride;
  70450. }
  70451. let worldView = new Matrix4();
  70452. let mat4holder = new Float32Array(16);
  70453. let i = 0;
  70454. //---------从renderOctree搬到这----
  70455. shader.setUniform1f("size", material.usePanoMap ? Potree.config.material.absolutePanoramaSize * Math.min(window.devicePixelRatio,2) : material.size);//usePanoMap时控制在不大不小的范围内感觉较好,考虑到有的点云稀疏,用大一点的点
  70456. shader.setUniform1f("uOpacity", material.usePanoMap ? 1: material.opacity);
  70457. shader.setUniform3f("uColor", material.color.toArray());
  70458. let currentTextureBindingPoint = params.currentTextureBindingPoint;
  70459. if (material.pointSizeType >= 0/* && window.needvisibilityTexture */) {
  70460. if (material.pointSizeType === PointSizeType.ADAPTIVE ||
  70461. material.activeAttributeName === "level of detail") {
  70462. let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
  70463. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  70464. const vnt = material.visibleNodesTexture;
  70465. const data = vnt.image.data;
  70466. data.set(visibilityTextureData.data);
  70467. vnt.needsUpdate = true;
  70468. let webGLTexture = this.textures.get(vnt);
  70469. webGLTexture.update(); //不加这个会闪烁
  70470. let vnWebGLTexture = this.textures.get(material.visibleNodesTexture); //不知道为什么这段从renderOctree中移过来,会崩溃。暂时不移动了
  70471. if(vnWebGLTexture){
  70472. shader.setUniform1i("visibleNodes", currentTextureBindingPoint);
  70473. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  70474. gl.bindTexture(vnWebGLTexture.target, vnWebGLTexture.id);
  70475. currentTextureBindingPoint++;
  70476. }
  70477. }
  70478. }
  70479. /* if (material.pointSizeType >= 0) {
  70480. if (material.pointSizeType === PointSizeType.ADAPTIVE ||
  70481. material.activeAttributeName === "level of detail") {
  70482. let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
  70483. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  70484. const vnt = material.visibleNodesTexture;
  70485. const data = vnt.image.data;
  70486. data.set(visibilityTextureData.data);
  70487. vnt.needsUpdate = true;
  70488. }
  70489. } */
  70490. let transparent = false;
  70491. if(params.transparent !== undefined){
  70492. transparent = params.transparent && material.opacity < 1;
  70493. }else {
  70494. transparent = material.usePanoMap ? false : (material.useFilterByNormal || material.opacity < 1); //add useFilterByNormal
  70495. }
  70496. if (transparent){
  70497. gl.enable(gl.BLEND);
  70498. if(params.notAdditiveBlending){
  70499. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); //NormalBlending
  70500. /* gl.enable(gl.DEPTH_TEST);
  70501. gl.depthMask(true); //如果不开启depthWrite, 深度会错乱。 */ //无解
  70502. gl.disable(gl.DEPTH_TEST);
  70503. gl.depthMask(true);
  70504. }else {
  70505. gl.blendFunc(gl.SRC_ALPHA, gl.ONE); //AdditiveBlending 原本
  70506. gl.disable(gl.DEPTH_TEST);
  70507. gl.depthMask(false);
  70508. }
  70509. } else {
  70510. gl.disable(gl.BLEND);
  70511. gl.depthMask(true);
  70512. gl.enable(gl.DEPTH_TEST);
  70513. }
  70514. if(params.blendFunc !== undefined){
  70515. gl.enable(gl.BLEND);
  70516. gl.blendFunc(...params.blendFunc);
  70517. }
  70518. if(params.depthTest !== undefined){
  70519. if(params.depthTest === true){
  70520. gl.enable(gl.DEPTH_TEST);
  70521. }else {
  70522. gl.disable(gl.DEPTH_TEST);
  70523. }
  70524. }
  70525. if(params.depthWrite !== undefined){
  70526. if(params.depthWrite === true){
  70527. gl.depthMask(true);
  70528. }else {
  70529. gl.depthMask(false);
  70530. }
  70531. }
  70532. //---------------------------------
  70533. for (let node of nodes) {
  70534. if(exports.debug.allowedNodes !== undefined){
  70535. if(!exports.debug.allowedNodes.includes(node.name)){
  70536. continue;
  70537. }
  70538. }
  70539. let world = node.sceneNode.matrixWorld;
  70540. worldView.multiplyMatrices(view, world);
  70541. if (visibilityTextureData) {
  70542. let vnStart = visibilityTextureData.offsets.get(node);
  70543. //console.log('vnStart',vnStart)
  70544. shader.setUniform1f("uVNStart", vnStart);
  70545. }
  70546. let level = node.getLevel();
  70547. if(node.debug){
  70548. shader.setUniform("uDebug", true);
  70549. }else {
  70550. shader.setUniform("uDebug", false);
  70551. }
  70552. // let isLeaf = false;
  70553. // if(node instanceof PointCloudOctreeNode){
  70554. // isLeaf = Object.keys(node.children).length === 0;
  70555. // }else if(node instanceof PointCloudArena4DNode){
  70556. // isLeaf = node.geometryNode.isLeaf;
  70557. // }
  70558. // shader.setUniform("uIsLeafNode", isLeaf);
  70559. // let isLeaf = node.children.filter(n => n != null).length === 0;
  70560. // if(!isLeaf){
  70561. // continue;
  70562. // }
  70563. // TODO consider passing matrices in an array to avoid uniformMatrix4fv overhead
  70564. const lModel = shader.uniformLocations["modelMatrix"];
  70565. if (lModel) {
  70566. mat4holder.set(world.elements);
  70567. gl.uniformMatrix4fv(lModel, false, mat4holder);
  70568. }
  70569. const lModelView = shader.uniformLocations["modelViewMatrix"];
  70570. //mat4holder.set(worldView.elements);
  70571. // faster then set in chrome 63
  70572. for(let j = 0; j < 16; j++){
  70573. mat4holder[j] = worldView.elements[j];
  70574. }
  70575. gl.uniformMatrix4fv(lModelView, false, mat4holder);
  70576. { // Clip Polygons
  70577. if(material.clipPolygons && material.clipPolygons.length > 0){
  70578. let clipPolygonVCount = [];
  70579. let worldViewProjMatrices = [];
  70580. for(let clipPolygon of material.clipPolygons){
  70581. let view = clipPolygon.viewMatrix;
  70582. let proj = clipPolygon.projMatrix;
  70583. let worldViewProj = proj.clone().multiply(view).multiply(world);
  70584. clipPolygonVCount.push(clipPolygon.markers.length);
  70585. worldViewProjMatrices.push(worldViewProj);
  70586. }
  70587. let flattenedMatrices = [].concat(...worldViewProjMatrices.map(m => m.elements));
  70588. let flattenedVertices = new Array(8 * 3 * material.clipPolygons.length);
  70589. for(let i = 0; i < material.clipPolygons.length; i++){
  70590. let clipPolygon = material.clipPolygons[i];
  70591. for(let j = 0; j < clipPolygon.markers.length; j++){
  70592. flattenedVertices[i * 24 + (j * 3 + 0)] = clipPolygon.markers[j].position.x;
  70593. flattenedVertices[i * 24 + (j * 3 + 1)] = clipPolygon.markers[j].position.y;
  70594. flattenedVertices[i * 24 + (j * 3 + 2)] = clipPolygon.markers[j].position.z;
  70595. }
  70596. }
  70597. const lClipPolygonVCount = shader.uniformLocations["uClipPolygonVCount[0]"];
  70598. gl.uniform1iv(lClipPolygonVCount, clipPolygonVCount);
  70599. const lClipPolygonVP = shader.uniformLocations["uClipPolygonWVP[0]"];
  70600. gl.uniformMatrix4fv(lClipPolygonVP, false, flattenedMatrices);
  70601. const lClipPolygons = shader.uniformLocations["uClipPolygonVertices[0]"];
  70602. gl.uniform3fv(lClipPolygons, flattenedVertices);
  70603. }
  70604. }
  70605. //shader.setUniformMatrix4("modelMatrix", world);
  70606. //shader.setUniformMatrix4("modelViewMatrix", worldView);
  70607. shader.setUniform1f("uLevel", level);
  70608. shader.setUniform1f("levelPercent", octree.nodeMaxLevel ? level / octree.nodeMaxLevel : 0.5);//xzw add
  70609. shader.setUniform1f("uNodeSpacing", node.geometryNode.estimatedSpacing);
  70610. shader.setUniform1f("uPCIndex", i);
  70611. // uBBSize
  70612. if (shadowMaps.length > 0) {
  70613. const lShadowMap = shader.uniformLocations["uShadowMap[0]"];
  70614. shader.setUniform3f("uShadowColor", material.uniforms.uShadowColor.value);
  70615. let bindingStart = 5;
  70616. let bindingPoints = new Array(shadowMaps.length).fill(bindingStart).map((a, i) => (a + i));
  70617. gl.uniform1iv(lShadowMap, bindingPoints);
  70618. for (let i = 0; i < shadowMaps.length; i++) {
  70619. let shadowMap = shadowMaps[i];
  70620. let bindingPoint = bindingPoints[i];
  70621. let glTexture = this.threeRenderer.properties.get(shadowMap.target.texture).__webglTexture;
  70622. gl.activeTexture(gl[`TEXTURE${bindingPoint}`]);
  70623. gl.bindTexture(gl.TEXTURE_2D, glTexture);
  70624. }
  70625. {
  70626. let worldViewMatrices = shadowMaps
  70627. .map(sm => sm.camera.matrixWorldInverse)
  70628. .map(view => new Matrix4().multiplyMatrices(view, world));
  70629. let flattenedMatrices = [].concat(...worldViewMatrices.map(c => c.elements));
  70630. const lWorldView = shader.uniformLocations["uShadowWorldView[0]"];
  70631. gl.uniformMatrix4fv(lWorldView, false, flattenedMatrices);
  70632. }
  70633. {
  70634. let flattenedMatrices = [].concat(...shadowMaps.map(sm => sm.camera.projectionMatrix.elements));
  70635. const lProj = shader.uniformLocations["uShadowProj[0]"];
  70636. gl.uniformMatrix4fv(lProj, false, flattenedMatrices);
  70637. }
  70638. }
  70639. const geometry = node.geometryNode.geometry;
  70640. if(geometry.attributes["gps-time"]){
  70641. const bufferAttribute = geometry.attributes["gps-time"];
  70642. const attGPS = octree.getAttribute("gps-time");
  70643. let initialRange = attGPS.initialRange;
  70644. let initialRangeSize = initialRange[1] - initialRange[0];
  70645. let globalRange = attGPS.range;
  70646. let globalRangeSize = globalRange[1] - globalRange[0];
  70647. let scale = initialRangeSize / globalRangeSize;
  70648. let offset = -(globalRange[0] - initialRange[0]) / initialRangeSize;
  70649. scale = Number.isNaN(scale) ? 1 : scale;
  70650. offset = Number.isNaN(offset) ? 0 : offset;
  70651. shader.setUniform1f("uGpsScale", scale);
  70652. shader.setUniform1f("uGpsOffset", offset);
  70653. //shader.setUniform2f("uFilterGPSTimeClipRange", [-Infinity, Infinity]);
  70654. let uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  70655. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  70656. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  70657. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  70658. let normalizedClipRange = [
  70659. (uFilterGPSTimeClipRange[0] - globalRange[0]) / globalRangeSize,
  70660. (uFilterGPSTimeClipRange[1] - globalRange[0]) / globalRangeSize,
  70661. ];
  70662. shader.setUniform2f("uFilterGPSTimeClipRange", normalizedClipRange);
  70663. // // ranges in full gps coordinate system
  70664. // const globalRange = attGPS.range;
  70665. // const bufferRange = bufferAttribute.potree.range;
  70666. // // ranges in [0, 1]
  70667. // // normalizedGlobalRange = [0, 1]
  70668. // // normalizedBufferRange: norm buffer within norm global range e.g. [0.2, 0.8]
  70669. // const globalWidth = globalRange[1] - globalRange[0];
  70670. // const normalizedBufferRange = [
  70671. // (bufferRange[0] - globalRange[0]) / globalWidth,
  70672. // (bufferRange[1] - globalRange[0]) / globalWidth,
  70673. // ];
  70674. // shader.setUniform2f("uNormalizedGpsBufferRange", normalizedBufferRange);
  70675. // let uFilterGPSTimeClipRange = material.uniforms.uFilterGPSTimeClipRange.value;
  70676. // let gpsCliPRangeMin = uFilterGPSTimeClipRange[0]
  70677. // let gpsCliPRangeMax = uFilterGPSTimeClipRange[1]
  70678. // shader.setUniform2f("uFilterGPSTimeClipRange", [gpsCliPRangeMin, gpsCliPRangeMax]);
  70679. // shader.setUniform1f("uGpsScale", bufferAttribute.potree.scale);
  70680. // shader.setUniform1f("uGpsOffset", bufferAttribute.potree.offset);
  70681. }
  70682. {
  70683. let uFilterReturnNumberRange = material.uniforms.uFilterReturnNumberRange.value;
  70684. let uFilterNumberOfReturnsRange = material.uniforms.uFilterNumberOfReturnsRange.value;
  70685. let uFilterPointSourceIDClipRange = material.uniforms.uFilterPointSourceIDClipRange.value;
  70686. shader.setUniform2f("uFilterReturnNumberRange", uFilterReturnNumberRange);
  70687. shader.setUniform2f("uFilterNumberOfReturnsRange", uFilterNumberOfReturnsRange);
  70688. shader.setUniform2f("uFilterPointSourceIDClipRange", uFilterPointSourceIDClipRange);
  70689. }
  70690. let webglBuffer = null;
  70691. if(!this.buffers.has(geometry)){
  70692. webglBuffer = this.createBuffer(geometry);
  70693. this.buffers.set(geometry, webglBuffer);
  70694. }else {
  70695. webglBuffer = this.buffers.get(geometry);
  70696. for(let attributeName in geometry.attributes){
  70697. let attribute = geometry.attributes[attributeName];
  70698. if(attribute.version > webglBuffer.vbos.get(attributeName).version){
  70699. this.updateBuffer(geometry);
  70700. }
  70701. }
  70702. }
  70703. gl.bindVertexArray(webglBuffer.vao);
  70704. let isExtraAttribute =
  70705. attributeLocations$1[material.activeAttributeName] === undefined
  70706. && Object.keys(geometry.attributes).includes(material.activeAttributeName);
  70707. if(isExtraAttribute){
  70708. const attributeLocation = attributeLocations$1["aExtra"].location;
  70709. for(const attributeName in geometry.attributes){
  70710. const bufferAttribute = geometry.attributes[attributeName];
  70711. const vbo = webglBuffer.vbos.get(attributeName);
  70712. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  70713. gl.disableVertexAttribArray(attributeLocation);
  70714. }
  70715. const attName = material.activeAttributeName;
  70716. const bufferAttribute = geometry.attributes[attName];
  70717. const vbo = webglBuffer.vbos.get(attName);
  70718. if(bufferAttribute !== undefined && vbo !== undefined){
  70719. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  70720. let normalized = bufferAttribute.normalized;
  70721. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  70722. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  70723. gl.enableVertexAttribArray(attributeLocation);
  70724. }
  70725. {
  70726. const attExtra = octree.pcoGeometry.pointAttributes.attributes
  70727. .find(a => a.name === attName);
  70728. let range = material.getRange(attName);
  70729. if(!range){
  70730. range = attExtra.range;
  70731. }
  70732. if(!range){
  70733. range = [0, 1];
  70734. }
  70735. let initialRange = attExtra.initialRange;
  70736. let initialRangeSize = initialRange[1] - initialRange[0];
  70737. let globalRange = range;
  70738. let globalRangeSize = globalRange[1] - globalRange[0];
  70739. let scale = initialRangeSize / globalRangeSize;
  70740. let offset = -(globalRange[0] - initialRange[0]) / initialRangeSize;
  70741. scale = Number.isNaN(scale) ? 1 : scale;
  70742. offset = Number.isNaN(offset) ? 0 : offset;
  70743. shader.setUniform1f("uExtraScale", scale);
  70744. shader.setUniform1f("uExtraOffset", offset);
  70745. }
  70746. }else {
  70747. for(const attributeName in geometry.attributes){
  70748. const bufferAttribute = geometry.attributes[attributeName];
  70749. const vbo = webglBuffer.vbos.get(attributeName);
  70750. if(attributeLocations$1[attributeName] !== undefined){
  70751. const attributeLocation = attributeLocations$1[attributeName].location;
  70752. let type = this.glTypeMapping.get(bufferAttribute.array.constructor);
  70753. let normalized = bufferAttribute.normalized;
  70754. gl.bindBuffer(gl.ARRAY_BUFFER, vbo.handle);
  70755. gl.vertexAttribPointer(attributeLocation, bufferAttribute.itemSize, type, normalized, 0, 0);
  70756. gl.enableVertexAttribArray(attributeLocation);
  70757. }
  70758. }
  70759. }
  70760. let numPoints = webglBuffer.numElements;
  70761. gl.drawArrays(gl.POINTS, 0, numPoints);
  70762. //gl.drawArrays(gl.TRIANGLES, 0, numPoints);
  70763. i++;
  70764. }
  70765. gl.bindVertexArray(null);
  70766. viewer.addTimeMark('renderNodes','end');
  70767. }
  70768. renderOctree(octrees, nodes, camera, target, params = {}){
  70769. viewer.addTimeMark('renderOctree','start');
  70770. let octree;
  70771. if(octrees instanceof Array){
  70772. octree = octrees[0];
  70773. }else {
  70774. octree = octrees; octrees = [octree];
  70775. }
  70776. let gl = this.gl;
  70777. let material = params.material ? params.material : octree.material;
  70778. let shadowMaps = params.shadowMaps == null ? [] : params.shadowMaps;
  70779. let view = camera.matrixWorldInverse;
  70780. let viewInv = camera.matrixWorld;
  70781. if(params.viewOverride){
  70782. view = params.viewOverride;
  70783. viewInv = view.clone().invert();
  70784. }
  70785. let proj = camera.projectionMatrix;
  70786. let projInv = proj.clone().invert();
  70787. //let worldView = new THREE.Matrix4();
  70788. let shader = null;
  70789. let visibilityTextureData = null;
  70790. let currentTextureBindingPoint = 0;
  70791. /* if (material.pointSizeType >= 0) {//最好搬到renderNodes
  70792. if (material.pointSizeType === PointSizeType.ADAPTIVE ||
  70793. material.activeAttributeName === "level of detail") {
  70794. let vnNodes = (params.vnTextureNodes != null) ? params.vnTextureNodes : nodes;
  70795. visibilityTextureData = octree.computeVisibilityTextureData(vnNodes, camera);
  70796. const vnt = material.visibleNodesTexture;
  70797. const data = vnt.image.data;
  70798. data.set(visibilityTextureData.data);
  70799. vnt.needsUpdate = true;
  70800. }
  70801. }
  70802. */
  70803. { // UPDATE SHADER AND TEXTURES
  70804. if (!this.shaders.has(material)) {
  70805. let [vs, fs] = [material.vertexShader, material.fragmentShader];
  70806. let shader = new Shader$1(gl, "pointcloud", vs, fs);
  70807. this.shaders.set(material, shader);
  70808. }
  70809. shader = this.shaders.get(material);
  70810. if(material.shaderNeedsUpdate)
  70811. {
  70812. let [vs, fs] = [material.vertexShader, material.fragmentShader];
  70813. let numSnapshots = material.snapEnabled ? material.numSnapshots : 0;
  70814. let num_in_clipboxes = (material.clipBoxes_in && material.clipBoxes_in.length) ? material.clipBoxes_in.length : 0;
  70815. let num_out_clipboxes = (material.clipBoxes_out && material.clipBoxes_out.length) ? material.clipBoxes_out.length : 0;
  70816. let num_highlightBox = (material.highlightBoxes && material.highlightBoxes.length) ? material.highlightBoxes.length : 0;
  70817. let numClipSpheres = (params.clipSpheres && params.clipSpheres.length) ? params.clipSpheres.length : 0;
  70818. let numClipPolygons = (material.clipPolygons && material.clipPolygons.length) ? material.clipPolygons.length : 0;
  70819. let defines = [
  70820. `#define num_shadowmaps ${shadowMaps.length}`,
  70821. `#define num_snapshots ${numSnapshots}`,
  70822. `#define num_in_clipboxes ${num_in_clipboxes}`, //改
  70823. `#define num_out_clipboxes ${num_out_clipboxes}`, //改
  70824. `#define num_highlightBox ${num_highlightBox}`, //改
  70825. `#define num_clipspheres ${numClipSpheres}`,
  70826. `#define num_prism ${material.prisms.pointsCount ? material.prisms.length : 0}`, //土方量数 如果num_prism>0,prismPointCountSum为0 会报错 :array size must be greater than zero
  70827. `#define prismPointCountSum ${material.prisms.pointsCount}`,//点总个数
  70828. `#define prism_maxPointsCount ${material.prisms.maxPointsCount}`, //单个prism最大点个数 (如果define也能传递个数数组,就不用再uniform里传了,呜 )
  70829. ];
  70830. //add:-----------
  70831. if(material.bigClipInBox ){//裁剪下载
  70832. defines.push('#define bigClipInBox');
  70833. }
  70834. if(material.usePanoMap){
  70835. defines.push("#define usePanoMap");
  70836. }
  70837. if(material.useFilterByNormal){
  70838. defines.push("#define use_filter_by_normal");
  70839. //Potree.settings.editType == 'pano' ? defines.push("#define attenuated_opacity2") : defines.push("#define attenuated_opacity");
  70840. }
  70841. if(material.uniforms.baseHeightAreaMap.value){//根据模型高亮土方
  70842. defines.push('#define showBaseHeight');
  70843. }
  70844. //---------------
  70845. if(octree.pcoGeometry.root.isLoaded()){
  70846. let attributes = octree.pcoGeometry.root.geometry.attributes;
  70847. if(attributes["gps-time"]){
  70848. defines.push("#define clip_gps_enabled");
  70849. }
  70850. if(attributes["return number"]){
  70851. defines.push("#define clip_return_number_enabled");
  70852. }
  70853. if(attributes["number of returns"]){
  70854. defines.push("#define clip_number_of_returns_enabled");
  70855. }
  70856. if(attributes["source id"] || attributes["point source id"]){
  70857. defines.push("#define clip_point_source_id_enabled");
  70858. }
  70859. }
  70860. let definesString = defines.join("\n");
  70861. let vsVersionIndex = vs.indexOf("#version ");
  70862. let fsVersionIndex = fs.indexOf("#version ");
  70863. if(vsVersionIndex >= 0){
  70864. vs = vs.replace(/(#version .*)/, `$1\n${definesString}`);
  70865. }else {
  70866. vs = `${definesString}\n${vs}`;
  70867. }
  70868. if(fsVersionIndex >= 0){
  70869. fs = fs.replace(/(#version .*)/, `$1\n${definesString}`);
  70870. }else {
  70871. fs = `${definesString}\n${fs}`;
  70872. }
  70873. shader.update(vs, fs);
  70874. material.shaderNeedsUpdate = false;
  70875. }
  70876. for (let uniformName of Object.keys(material.uniforms)) {
  70877. let uniform = material.uniforms[uniformName];
  70878. if (uniform.type == "t") {
  70879. let texture = uniform.value;
  70880. if (!texture) {
  70881. continue;
  70882. }
  70883. //add
  70884. if(uniformName == 'pano0Map' || uniformName == 'pano1Map' ){ //属于cubeTex,另外设置
  70885. continue
  70886. }
  70887. /* if(texture.image && !(texture.image instanceof Image) && !(texture instanceof THREE.CanvasTexture)){
  70888. //renderTarget的texture在创建renderTarget时已经初始化过 见setupRenderTarget
  70889. continue
  70890. } */
  70891. if (!this.textures.has(texture) || texture.needsRebuild) {
  70892. let webglTexture = new WebGLTexture$1(gl, texture, this.threeRenderer);
  70893. this.textures.set(texture, webglTexture);
  70894. delete texture.needsRebuild; //renderTarget在resize后会触发dispose, 然后 _gl.deleteTexture( textureProperties.__webglTexture )所以需要重新建立
  70895. }
  70896. let webGLTexture = this.textures.get(texture);
  70897. webGLTexture.update();
  70898. }
  70899. }
  70900. }
  70901. gl.useProgram(shader.program);
  70902. /* let transparent = false;
  70903. if(params.transparent !== undefined){
  70904. transparent = params.transparent && material.opacity < 1;
  70905. }else{
  70906. transparent = material.usePanoMap ? false : (material.useFilterByNormal || material.opacity < 1); //add useFilterByNormal
  70907. }
  70908. if (transparent){
  70909. gl.enable(gl.BLEND);
  70910. if(params.notAdditiveBlending){
  70911. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA ); //NormalBlending
  70912. gl.enable(gl.DEPTH_TEST);
  70913. gl.depthMask(true); //如果不开启depthWrite,深度会错乱。
  70914. }else{
  70915. gl.blendFunc(gl.SRC_ALPHA, gl.ONE); //AdditiveBlending 原本
  70916. gl.disable(gl.DEPTH_TEST);
  70917. gl.depthMask(false);
  70918. }
  70919. } else {
  70920. gl.disable(gl.BLEND);
  70921. gl.depthMask(true);
  70922. gl.enable(gl.DEPTH_TEST);
  70923. }
  70924. if(params.blendFunc !== undefined){
  70925. gl.enable(gl.BLEND);
  70926. gl.blendFunc(...params.blendFunc);
  70927. }
  70928. if(params.depthTest !== undefined){
  70929. if(params.depthTest === true){
  70930. gl.enable(gl.DEPTH_TEST);
  70931. }else{
  70932. gl.disable(gl.DEPTH_TEST);
  70933. }
  70934. }
  70935. if(params.depthWrite !== undefined){
  70936. if(params.depthWrite === true){
  70937. gl.depthMask(true);
  70938. }else{
  70939. gl.depthMask(false);
  70940. }
  70941. } */
  70942. { // UPDATE UNIFORMS
  70943. shader.setUniformMatrix4("projectionMatrix", proj);
  70944. shader.setUniformMatrix4("viewMatrix", view);
  70945. shader.setUniformMatrix4("uViewInv", viewInv);
  70946. shader.setUniformMatrix4("uProjInv", projInv);
  70947. /* let screenWidth = target ? target.width : material.screenWidth;
  70948. let screenHeight = target ? target.height : material.screenHeight;
  70949. shader.setUniform1f("uScreenWidth", screenWidth);
  70950. shader.setUniform1f("uScreenHeight", screenHeight); */
  70951. shader.setUniform2f('resolution', material.resolution.toArray());
  70952. shader.setUniform1f("fov", Math.PI * camera.fov / 180);
  70953. shader.setUniform1f("near", camera.near);
  70954. shader.setUniform1f("far", camera.far);
  70955. if(camera instanceof OrthographicCamera){
  70956. shader.setUniform("uUseOrthographicCamera", true);
  70957. shader.setUniform("uOrthoWidth", (camera.right - camera.left) / camera.zoom); //改
  70958. shader.setUniform("uOrthoHeight", camera.top - camera.bottom);
  70959. }else {
  70960. shader.setUniform("uUseOrthographicCamera", false);
  70961. }
  70962. /* if(material.clipBoxes.length + material.clipPolygons.length === 0){//改
  70963. shader.setUniform1i("clipTask", ClipTask.NONE);
  70964. }else{
  70965. shader.setUniform1i("clipTask", material.clipTask);
  70966. }
  70967. shader.setUniform1i("clipMethod", material.clipMethod);*/
  70968. //改
  70969. if (material.clipBoxes_in && material.clipBoxes_in.length > 0) {
  70970. //let flattenedMatrices = [].concat(...material.clipBoxes.map(c => c.inverse.elements));
  70971. const lClipBoxes = shader.uniformLocations["clipBoxes_in[0]"];
  70972. gl.uniformMatrix4fv(lClipBoxes, false, material.uniforms.clipBoxes_in.value);
  70973. }
  70974. if (material.clipBoxes_out && material.clipBoxes_out.length > 0) {//add
  70975. const lClipBoxes2 = shader.uniformLocations["clipBoxes_out[0]"];
  70976. gl.uniformMatrix4fv(lClipBoxes2, false, material.uniforms.clipBoxes_out.value);
  70977. }
  70978. if (material.highlightBoxes && material.highlightBoxes.length > 0) {//add
  70979. const boxes_highlight = shader.uniformLocations["boxes_highlight[0]"];
  70980. gl.uniformMatrix4fv(boxes_highlight, false, material.uniforms.boxes_highlight.value);
  70981. }
  70982. if (material.bigClipInBox ) {//add
  70983. shader.setUniformMatrix4("clipBoxBig_in", material.uniforms.clipBoxBig_in.value);
  70984. }
  70985. if(material.uniforms.baseHeightAreaMap.value ){//根据模型高亮土方
  70986. const baseHeightBoundZ = shader.uniformLocations["baseHeightBoundZ"];
  70987. gl.uniform2f(baseHeightBoundZ, ...material.uniforms.baseHeightBoundZ.value.toArray());
  70988. const baseHeightBoundXY = shader.uniformLocations["baseHeightBoundXY"];
  70989. gl.uniform4f(baseHeightBoundXY, ...material.uniforms.baseHeightBoundXY.value.toArray());
  70990. }
  70991. if(material.prisms.length){
  70992. const prismList = shader.uniformLocations["prismList[0]"];
  70993. gl.uniformMatrix3fv(prismList, false, material.uniforms.prismList.value);
  70994. const prismPoints = shader.uniformLocations["prismPoints[0]"];
  70995. gl.uniform2fv(prismPoints, material.uniforms.prismPoints.value);
  70996. }
  70997. // TODO CLIPSPHERES
  70998. if(params.clipSpheres && params.clipSpheres.length > 0){
  70999. let clipSpheres = params.clipSpheres;
  71000. let matrices = [];
  71001. for(let clipSphere of clipSpheres){
  71002. //let mScale = new THREE.Matrix4().makeScale(...clipSphere.scale.toArray());
  71003. //let mTranslate = new THREE.Matrix4().makeTranslation(...clipSphere.position.toArray());
  71004. //let clipToWorld = new THREE.Matrix4().multiplyMatrices(mTranslate, mScale);
  71005. let clipToWorld = clipSphere.matrixWorld;
  71006. let viewToWorld = camera.matrixWorld;
  71007. let worldToClip = clipToWorld.clone().invert();
  71008. let viewToClip = new Matrix4().multiplyMatrices(worldToClip, viewToWorld);
  71009. matrices.push(viewToClip);
  71010. }
  71011. let flattenedMatrices = [].concat(...matrices.map(matrix => matrix.elements));
  71012. const lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  71013. gl.uniformMatrix4fv(lClipSpheres, false, flattenedMatrices);
  71014. //const lClipSpheres = shader.uniformLocations["uClipSpheres[0]"];
  71015. //gl.uniformMatrix4fv(lClipSpheres, false, material.uniforms.clipSpheres.value);
  71016. }
  71017. shader.setUniform1f("orthoMaxSize", material.uniforms.orthoMaxSize.value);
  71018. shader.setUniform1f("maxSize", material.uniforms.maxSize.value);
  71019. shader.setUniform1f("minSize", material.uniforms.minSize.value);
  71020. // uniform float uPCIndex
  71021. shader.setUniform1f("uOctreeSpacing", material.spacing);
  71022. shader.setUniform("uOctreeSize", material.uniforms.octreeSize.value);
  71023. shader.setUniform2f("elevationRange", material.elevationRange);
  71024. shader.setUniform2f("intensityRange", material.intensityRange);
  71025. shader.setUniform3f("uIntensity_gbc", [
  71026. material.intensityGamma,
  71027. material.intensityBrightness,
  71028. material.intensityContrast
  71029. ]);
  71030. shader.setUniform3f("uRGB_gbc", [
  71031. material.rgbGamma,
  71032. material.rgbBrightness,
  71033. material.rgbContrast
  71034. ]);
  71035. shader.setUniform1f("uTransition", material.transition);
  71036. shader.setUniform1f("wRGB", material.weightRGB);
  71037. shader.setUniform1f("wIntensity", material.weightIntensity);
  71038. shader.setUniform1f("wElevation", material.weightElevation);
  71039. shader.setUniform1f("wClassification", material.weightClassification);
  71040. shader.setUniform1f("wReturnNumber", material.weightReturnNumber);
  71041. shader.setUniform1f("wSourceID", material.weightSourceID);
  71042. shader.setUniform("backfaceCulling", material.uniforms.backfaceCulling.value);
  71043. //==========================
  71044. //gl.TEXTURE_CUBE_MAP: 34067
  71045. //gl.TEXTURE0=33984 , vnWebGLTexture.target=gl.TEXTURE_2D = 3353
  71046. /* let vnWebGLTexture = this.textures.get(material.visibleNodesTexture);//最好搬到renderNodes
  71047. if(vnWebGLTexture){
  71048. shader.setUniform1i("visibleNodes", currentTextureBindingPoint); //为何之前写的是"visibleNodesTexture",但和"visibleNodes"效果相同?可shader里只有"visibleNodes"
  71049. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  71050. gl.bindTexture(vnWebGLTexture.target, vnWebGLTexture.id);
  71051. currentTextureBindingPoint++;
  71052. } */
  71053. let gradientTexture = this.textures.get(material.gradientTexture);
  71054. shader.setUniform1i("gradient", currentTextureBindingPoint);
  71055. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  71056. gl.bindTexture(gradientTexture.target, gradientTexture.id);
  71057. currentTextureBindingPoint++;
  71058. const repeat = material.elevationGradientRepeat;
  71059. if(repeat === ElevationGradientRepeat.REPEAT){
  71060. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.REPEAT);
  71061. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.REPEAT);
  71062. }else if(repeat === ElevationGradientRepeat.MIRRORED_REPEAT){
  71063. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.MIRRORED_REPEAT);
  71064. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.MIRRORED_REPEAT);
  71065. }else {
  71066. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
  71067. gl.texParameteri(gradientTexture.target, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
  71068. }
  71069. currentTextureBindingPoint++;
  71070. let classificationTexture = this.textures.get(material.classificationTexture);
  71071. shader.setUniform1i("classificationLUT", currentTextureBindingPoint);
  71072. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  71073. gl.bindTexture(classificationTexture.target, classificationTexture.id);
  71074. currentTextureBindingPoint++;
  71075. /* let matcapTexture = this.textures.get(material.matcapTexture);
  71076. shader.setUniform1i("matcapTextureUniform", currentTextureBindingPoint);
  71077. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  71078. gl.bindTexture(matcapTexture.target, matcapTexture.id);
  71079. currentTextureBindingPoint++; */
  71080. let baseHeightAreaMap = material.uniforms.baseHeightAreaMap.value;
  71081. if(baseHeightAreaMap){//根据模型高亮土方
  71082. let map = this.textures.get(baseHeightAreaMap);
  71083. shader.setUniform1i("baseHeightAreaMap", currentTextureBindingPoint);
  71084. gl.activeTexture(gl.TEXTURE0 + currentTextureBindingPoint);
  71085. gl.bindTexture(map.target, map.id);
  71086. currentTextureBindingPoint++;
  71087. }
  71088. if (material.snapEnabled === true) {
  71089. {
  71090. const lSnapshot = shader.uniformLocations["uSnapshot[0]"];
  71091. const lSnapshotDepth = shader.uniformLocations["uSnapshotDepth[0]"];
  71092. let bindingStart = currentTextureBindingPoint;
  71093. let lSnapshotBindingPoints = new Array(5).fill(bindingStart).map((a, i) => (a + i));
  71094. let lSnapshotDepthBindingPoints = new Array(5)
  71095. .fill(1 + Math.max(...lSnapshotBindingPoints))
  71096. .map((a, i) => (a + i));
  71097. currentTextureBindingPoint = 1 + Math.max(...lSnapshotDepthBindingPoints);
  71098. gl.uniform1iv(lSnapshot, lSnapshotBindingPoints);
  71099. gl.uniform1iv(lSnapshotDepth, lSnapshotDepthBindingPoints);
  71100. for (let i = 0; i < 5; i++) {
  71101. let texture = material.uniforms[`uSnapshot`].value[i];
  71102. let textureDepth = material.uniforms[`uSnapshotDepth`].value[i];
  71103. if (!texture) {
  71104. break;
  71105. }
  71106. let snapTexture = this.threeRenderer.properties.get(texture).__webglTexture;
  71107. let snapTextureDepth = this.threeRenderer.properties.get(textureDepth).__webglTexture;
  71108. let bindingPoint = lSnapshotBindingPoints[i];
  71109. let depthBindingPoint = lSnapshotDepthBindingPoints[i];
  71110. gl.activeTexture(gl[`TEXTURE${bindingPoint}`]);
  71111. gl.bindTexture(gl.TEXTURE_2D, snapTexture);
  71112. gl.activeTexture(gl[`TEXTURE${depthBindingPoint}`]);
  71113. gl.bindTexture(gl.TEXTURE_2D, snapTextureDepth);
  71114. }
  71115. }
  71116. {
  71117. let flattenedMatrices = [].concat(...material.uniforms.uSnapView.value.map(c => c.elements));
  71118. const lSnapView = shader.uniformLocations["uSnapView[0]"];
  71119. gl.uniformMatrix4fv(lSnapView, false, flattenedMatrices);
  71120. }
  71121. {
  71122. let flattenedMatrices = [].concat(...material.uniforms.uSnapProj.value.map(c => c.elements));
  71123. const lSnapProj = shader.uniformLocations["uSnapProj[0]"];
  71124. gl.uniformMatrix4fv(lSnapProj, false, flattenedMatrices);
  71125. }
  71126. {
  71127. let flattenedMatrices = [].concat(...material.uniforms.uSnapProjInv.value.map(c => c.elements));
  71128. const lSnapProjInv = shader.uniformLocations["uSnapProjInv[0]"];
  71129. gl.uniformMatrix4fv(lSnapProjInv, false, flattenedMatrices);
  71130. }
  71131. {
  71132. let flattenedMatrices = [].concat(...material.uniforms.uSnapViewInv.value.map(c => c.elements));
  71133. const lSnapViewInv = shader.uniformLocations["uSnapViewInv[0]"];
  71134. gl.uniformMatrix4fv(lSnapViewInv, false, flattenedMatrices);
  71135. }
  71136. }
  71137. //=============add===========
  71138. if(material.usePanoMap){//为什么pointsize失效
  71139. shader.setUniform1f("progress", material.uniforms.progress.value);
  71140. shader.setUniform1f("easeInOutRatio", material.uniforms.easeInOutRatio.value);
  71141. shader.setUniform3f("pano0Position", material.uniforms.pano0Position.value.toArray());
  71142. shader.setUniform3f("pano1Position", material.uniforms.pano1Position.value.toArray());
  71143. shader.setUniform('pano0Matrix', material.uniforms.pano0Matrix.value);
  71144. shader.setUniform('pano1Matrix', material.uniforms.pano1Matrix.value);
  71145. let pano0Map = material.uniforms.pano0Map.value;
  71146. if(pano0Map){
  71147. this.threeRenderer._textures.safeSetTextureCube( pano0Map, ++currentTextureBindingPoint );
  71148. shader.setUniform1i('pano0Map', currentTextureBindingPoint);
  71149. }
  71150. let pano1Map = material.uniforms.pano1Map.value;
  71151. if(pano1Map){
  71152. this.threeRenderer._textures.safeSetTextureCube( pano1Map, ++currentTextureBindingPoint );
  71153. shader.setUniform1i('pano1Map', currentTextureBindingPoint);
  71154. }
  71155. //注: three.js我添加了个 _textures, safeSetTextureCube里主要就是activeTexture和bindTexture
  71156. }
  71157. }
  71158. viewer.addTimeMark('renderOctree','end');
  71159. params.currentTextureBindingPoint = ++currentTextureBindingPoint;
  71160. octrees.forEach(octree=>{
  71161. this.renderNodes(octree, nodes || octree.visibleNodes, visibilityTextureData, camera, target, shader, params);
  71162. });
  71163. gl.activeTexture(gl.TEXTURE2);
  71164. gl.bindTexture(gl.TEXTURE_2D, null);
  71165. gl.activeTexture(gl.TEXTURE0);
  71166. //gl.bindTexture(gl.TEXTURE_2D, null); //add
  71167. //add 恢复为不透明(否则renderToCubeMap时的贴图会被渲染成高亮的颜色)
  71168. gl.disable(gl.BLEND);
  71169. gl.depthMask(true);
  71170. gl.enable(gl.DEPTH_TEST);
  71171. //DEPTH_TEST等需要恢复吗
  71172. }
  71173. render(scene, camera, target = null, params = {}) {
  71174. const gl = this.gl;
  71175. // PREPARE
  71176. if (target != null) {
  71177. this.threeRenderer.setRenderTarget(target);
  71178. }
  71179. //camera.updateProjectionMatrix();
  71180. // camera.matrixWorldInverse.invert(camera.matrixWorld);
  71181. const traversalResult = this.traverse(scene);
  71182. //排序
  71183. if(params.notAdditiveBlending){//add
  71184. traversalResult.octrees.forEach(tree=>{
  71185. if(tree.material.opacity==1){
  71186. tree._z = Infinity; //不透明的先渲染
  71187. }else {
  71188. let center = tree.boundCenter ? tree.boundCenter.clone() : tree.boundingBox.getCenter(tree.boundCenter).applyMatrix4(tree.matrixWorld);
  71189. center.project(camera);
  71190. tree._z = center.z;
  71191. }
  71192. });
  71193. traversalResult.octrees.sort((tree1,tree2)=>{
  71194. return tree2._z - tree1._z //降序 (-1 朝外)。 离屏幕近的后渲染
  71195. });
  71196. }
  71197. // RENDER
  71198. let mat = params.material || traversalResult.octrees[0].material;
  71199. if(Potree.settings.cloudSameMat && viewer.scene.volumes.length == 0 && mat.pointSizeType != PointSizeType.ADAPTIVE && mat.activeAttributeName != "level of detail"){
  71200. this.renderOctree(traversalResult.octrees, null, camera, target, params); //所有点云除了个别属性需要在shader中更新,其他都使用第一个点云的材质
  71201. }else for (const octree of traversalResult.octrees) {
  71202. for (const octree of traversalResult.octrees) {
  71203. this.renderOctree(octree, octree.visibleNodes, camera, target, params);
  71204. }
  71205. }
  71206. //if (octree material.pointSizeType === PointSizeType.ADAPTIVE || material.activeAttributeName === "level of detail") {
  71207. // CLEANUP
  71208. gl.activeTexture(gl.TEXTURE1);
  71209. gl.bindTexture(gl.TEXTURE_2D, null);
  71210. gl.bindBuffer(gl.ARRAY_BUFFER, null);
  71211. gl.bindVertexArray(null);
  71212. this.threeRenderer.resetState();
  71213. }
  71214. };
  71215. /*
  71216. 中东的链接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
  71217. geometry: 有的attributes: 属性是:
  71218. classification:
  71219. color:
  71220. indices:
  71221. normal:
  71222. position:
  71223. 最好有个spacing
  71224. */
  71225. //
  71226. // Algorithm by Christian Boucheny
  71227. // shader code taken and adapted from CloudCompare
  71228. //
  71229. // see
  71230. // https://github.com/cloudcompare/trunk/tree/master/plugins/qEDL/shaders/EDL
  71231. // http://www.kitware.com/source/home/post/9
  71232. // https://tel.archives-ouvertes.fr/tel-00438464/document p. 115+ (french)
  71233. class ExtendEyeDomeLightingMaterial extends EyeDomeLightingMaterial{
  71234. constructor(parameters = {}){
  71235. super(parameters);
  71236. delete this.uniforms.screenWidth;
  71237. delete this.uniforms.screenHeight;
  71238. this.uniforms.resolution = { type: 'v2', value: new Vector2()};
  71239. this.uniforms.useEDL = { type: 'i', value: 1 };
  71240. this.vertexShader = this.getDefines() + Shaders['edl_new.vs']; //改
  71241. this.fragmentShader = this.getDefines() + Shaders['edl_new.fs']; //改
  71242. }
  71243. }
  71244. const copyShader = {
  71245. uniforms: {
  71246. tDiffuse: {
  71247. type: "t",
  71248. value: null
  71249. },
  71250. opacity: {
  71251. type: "f",
  71252. value: 1
  71253. },
  71254. depthTex: {
  71255. type: "t",
  71256. value: null
  71257. }
  71258. },
  71259. vertexShader: `
  71260. varying vec2 vUv;
  71261. void main() {
  71262. vUv = uv;
  71263. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  71264. }
  71265. `,
  71266. fragmentShader: `
  71267. #extension GL_EXT_frag_depth : enable
  71268. uniform float opacity;
  71269. uniform sampler2D tDiffuse;
  71270. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  71271. uniform sampler2D depthTex;
  71272. #endif
  71273. varying vec2 vUv;
  71274. void main() {
  71275. #if defined(GL_EXT_frag_depth) && defined(useDepth)
  71276. float depth = texture2D(depthTex, vUv).r;
  71277. /* if(depth >= 1.0){ //超级远(但是在modelTex里我把天空距离超出far了,所以不删)
  71278. discard;
  71279. } */
  71280. gl_FragDepthEXT = depth;
  71281. #endif
  71282. vec4 texel = texture2D( tDiffuse, vUv );
  71283. gl_FragColor = opacity * texel;
  71284. }
  71285. `
  71286. };
  71287. //import DepthTexSampler from "../custom/utils/DepthTexSampler.js";
  71288. class EDLRenderer{//Eye-Dome Lighting 眼罩照明
  71289. constructor(viewer){
  71290. this.viewer = viewer;
  71291. this.edlMaterial = null;
  71292. //this.rtRegular;
  71293. this.rtEDLs = new Map;
  71294. this.gl = viewer.renderer.getContext();
  71295. //反正也没用到,注释了:
  71296. //this.shadowMap = new PointCloudSM(this.viewer.pRenderer);
  71297. viewer.addEventListener('resize',this.resize.bind(this));
  71298. this.initEDL(viewer);
  71299. }
  71300. initEDL(viewer){
  71301. if (this.edlMaterial != null || !Features.EXT_DEPTH.isSupported()){
  71302. return;
  71303. }
  71304. this.edlMaterial = new ExtendEyeDomeLightingMaterial();
  71305. this.edlMaterial.depthTest = true;
  71306. this.edlMaterial.depthWrite = true;
  71307. this.edlMaterial.transparent = true;
  71308. let copyUniforms = UniformsUtils.clone( copyShader.uniforms );
  71309. let {vs,fs} = Common.changeShaderToWebgl2(copyShader.vertexShader, copyShader.fragmentShader, 'ShaderMaterial');
  71310. this.recoverToScreenMat = new ShaderMaterial({
  71311. uniforms: copyUniforms,
  71312. vertexShader: vs,
  71313. fragmentShader: fs,
  71314. transparent: true,
  71315. defines:{
  71316. useDepth: true //开启后,其他物体才能被遮挡
  71317. }
  71318. });
  71319. /* let copyUniforms = THREE.UniformsUtils.clone( copyShader.uniforms );
  71320. this.copyMaterial = new THREE.ShaderMaterial( {
  71321. uniforms: copyUniforms,
  71322. vertexShader: copyShader.vertexShader,
  71323. fragmentShader: copyShader.fragmentShader,
  71324. //premultipliedAlpha: true,
  71325. transparent: true,
  71326. //blending: THREE.AdditiveBlending,
  71327. depthTest: false,
  71328. depthWrite: false
  71329. }); */
  71330. if(Potree.settings.useRTskybox != Potree.settings.useRTPoint){//如果两个只开了一个
  71331. viewer.images360.addEventListener('endChangeMode',()=>{
  71332. this.resize({viewport:viewer.mainViewport});
  71333. });
  71334. }
  71335. //this.depthTexSampler = new DepthTexSampler(this);
  71336. };
  71337. resize(e){
  71338. if(Features.EXT_DEPTH.isSupported()){
  71339. let viewport = e.viewport;
  71340. let size = ( Potree.settings.displayMode == 'showPanos' ? Potree.settings.useRTskybox : Potree.settings.useRTPoint) ? viewport.resolution2 : viewport.resolution; //若要渲染skybox,需要和设备一样精度的rt
  71341. this.getRtEDL(viewport).setSize( size.x, size.y ); //理论上可以是任意尺寸,但会影响精度,且aspect最好和渲染的一致
  71342. }
  71343. }
  71344. clearTargets(params={}){
  71345. const viewer = this.viewer;
  71346. const {renderer} = viewer;
  71347. const oldTarget = renderer.getRenderTarget();
  71348. if(params.target){//add
  71349. renderer.setRenderTarget( params.target);
  71350. renderer.clear();
  71351. }
  71352. if(Features.EXT_DEPTH.isSupported()){
  71353. if(params.rtEDL){
  71354. renderer.setRenderTarget( params.rtEDL);
  71355. renderer.clear();
  71356. }else {
  71357. var rtEDL = this.getRtEDL(params.viewport);
  71358. if(rtEDL){
  71359. renderer.setRenderTarget( rtEDL );
  71360. renderer.setClearAlpha(0);
  71361. renderer.clear( true, true, true );
  71362. }
  71363. }
  71364. }
  71365. //renderer.setRenderTarget( this.rtRegular );
  71366. //renderer.clear( true, true, false );
  71367. renderer.setRenderTarget(oldTarget);
  71368. }
  71369. getRtEDL(viewport){//根据不同viewport返回rtEDL的texture
  71370. if(!viewport){
  71371. console.warn('getRtEDL没传viewport!!!! !!!!!!!!!!');
  71372. viewport = viewer.mainViewport;
  71373. }
  71374. var rtEDL = this.rtEDLs.get(viewport);
  71375. if(!rtEDL){
  71376. if(Features.EXT_DEPTH.isSupported()){
  71377. rtEDL = new WebGLRenderTarget(viewport.resolution.x, viewport.resolution.y, {
  71378. minFilter: NearestFilter,
  71379. magFilter: NearestFilter,
  71380. format: RGBAFormat,
  71381. type: FloatType,
  71382. depthTexture: new DepthTexture(undefined, undefined, UnsignedIntType)
  71383. });
  71384. //注: 部分手机在resize时会崩溃,经检验去掉rtEDL的resize可以解决,所以更应该注释掉这个
  71385. this.rtEDLs.set(viewport, rtEDL);
  71386. }
  71387. }
  71388. //注:当pc窗口缩小,deviceRatio变小后,resolution2会小于resolution,然后遮挡会出现精度损失而有细微不准,是正常现象。
  71389. return rtEDL
  71390. }
  71391. renderShadowMap(visiblePointClouds, camera, lights){
  71392. const {viewer} = this;
  71393. const doShadows = lights.length > 0 && !(lights[0].disableShadowUpdates);
  71394. if(doShadows){
  71395. let light = lights[0];
  71396. this.shadowMap.setLight(light);
  71397. let originalAttributes = new Map();
  71398. for(let pointcloud of viewer.scene.pointclouds){
  71399. // TODO IMPORTANT !!! check
  71400. originalAttributes.set(pointcloud, pointcloud.material.activeAttributeName);
  71401. pointcloud.material.disableEvents();
  71402. pointcloud.material.activeAttributeName = "depth";
  71403. //pointcloud.material.pointColorType = PointColorType.DEPTH;
  71404. }
  71405. this.shadowMap.render(viewer.scene.scenePointCloud, camera);
  71406. for(let pointcloud of visiblePointClouds){
  71407. let originalAttribute = originalAttributes.get(pointcloud);
  71408. // TODO IMPORTANT !!! check
  71409. pointcloud.material.activeAttributeName = originalAttribute;
  71410. pointcloud.material.enableEvents();
  71411. }
  71412. viewer.shadowTestCam.updateMatrixWorld();
  71413. viewer.shadowTestCam.matrixWorldInverse.copy(viewer.shadowTestCam.matrixWorld).invert();
  71414. viewer.shadowTestCam.updateProjectionMatrix();
  71415. }
  71416. }
  71417. render(params={}){
  71418. const viewer = this.viewer;
  71419. let camera = params.camera ? params.camera : viewer.scene.getActiveCamera();
  71420. let rtEDL = (Potree.settings.pointEnableRT || Potree.settings.displayMode == 'showPanos' || viewer.useEDL) &&
  71421. Features.EXT_DEPTH.isSupported() && camera.type != "OrthographicCamera" && !params.dontRenderRtEDL && (params.rtEDL || this.getRtEDL(params.viewport)); // 平面相机不用depthTex直接打开depthTest?且不使用edl
  71422. let useEDL = viewer.useEDL && rtEDL && Potree.settings.displayMode != 'showPanos';
  71423. let target = params.target || null;
  71424. const 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的大小
  71425. viewer.renderer.setRenderTarget(target);
  71426. //viewer.dispatchEvent({type: "render.pass.begin",viewer: viewer});
  71427. let lights = [];
  71428. /* viewer.scene.scene.traverse(node => {
  71429. if(node.type === "SpotLight"){
  71430. lights.push(node);
  71431. }
  71432. }); */
  71433. //skybox 全景图
  71434. if(!params.magnifier){
  71435. if(Potree.settings.displayMode == 'showPanos' || Potree.settings.testCube ){
  71436. Potree.Utils.setCameraLayers(camera, ['skybox']);
  71437. if((Potree.settings.displayMode == 'showPanos' )&& viewer.images360.currentPano.pointcloud.hasDepthTex && rtEDL){//渲染深度图
  71438. viewer.renderer.setRenderTarget(rtEDL); //将带有深度图的skybox画在rtEDL一下,这样就不需要绘制后边的点云了
  71439. viewer.renderer.render(viewer.scene.scene, camera);
  71440. viewer.renderer.setRenderTarget(target);
  71441. if(Potree.settings.useRTskybox){//直接使用rtEDL,但是会失去抗锯齿,不知在skybox上需要抗锯齿吗
  71442. this.recoverToScreenMat.uniforms.depthTex.value = rtEDL.depthTexture;
  71443. this.recoverToScreenMat.uniforms.tDiffuse.value = rtEDL.texture;
  71444. Utils.screenPass.render(viewer.renderer, this.recoverToScreenMat, target);
  71445. }else {
  71446. viewer.renderer.render(viewer.scene.scene, camera);
  71447. }
  71448. }else {
  71449. viewer.renderer.render(viewer.scene.scene, camera);
  71450. }
  71451. if(Potree.settings.displayMode == 'showPanos' ){
  71452. if(Potree.settings.fastTran && viewer.images360.fastTranMaskPass.enabled){
  71453. viewer.images360.fastTranMaskPass.render();
  71454. }
  71455. return
  71456. }
  71457. }
  71458. }
  71459. const visiblePointClouds2 = viewer.scene.pointclouds.filter(pc => Potree.Utils.getObjVisiByReason(pc,'datasetSelection') ); //需要绘制到rtEDL的
  71460. const showPointClouds = params.magnifier ? visiblePointClouds2.length>0 : viewer.scene.pointclouds.some(e=>e.visible); //是否有需要绘制到屏幕的
  71461. visiblePointClouds2.forEach(e=>{//为了绘制到depthTexture,先显示(展示全景图时隐藏了点云,所以需要显示下。且放大镜需要绘制点云)
  71462. e.oldVisi = e.visible;
  71463. e.visible = true;
  71464. });
  71465. Potree.Utils.setCameraLayers(camera, ['pointcloud']); //设置多少都会渲染出来,因为渲染里没有sort
  71466. //camera.layers.set(Potree.config.renderLayers.pointcloud);
  71467. //TODO adapt to multiple lights
  71468. //this.renderShadowMap(visiblePointClouds2, camera, lights); //???????
  71469. {
  71470. for (let pointcloud of visiblePointClouds2) {
  71471. let material = pointcloud.material;
  71472. let octreeSize = pointcloud.pcoGeometry.boundingBox.getSize(new Vector3()).x;
  71473. material.fov = MathUtils.degToRad(camera.fov);
  71474. material.resolution = resolution;
  71475. material.spacing = pointcloud.pcoGeometry.spacing; // * Math.max(this.scale.x, this.scale.y, this.scale.z);
  71476. material.near = camera.near;
  71477. material.far = camera.far;
  71478. material.uniforms.octreeSize.value = octreeSize;
  71479. if(useEDL ){
  71480. material.useEDL = true;
  71481. //material.fakeEDL = false; //add
  71482. }else {
  71483. material.useEDL = false;
  71484. //material.fakeEDL = true; //add 使也输出深度
  71485. }
  71486. }
  71487. if(rtEDL ){ //借用rtEDL存储深度信息
  71488. viewer.renderer.setRenderTarget( rtEDL );
  71489. if(visiblePointClouds2.length>0){ //渲染scenePointCloud到rtEDL
  71490. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, rtEDL, {
  71491. shadowMaps: lights.length > 0 ? [this.shadowMap] : null,
  71492. clipSpheres: viewer.scene.volumes.filter(v => (v instanceof SphereVolume$1)),
  71493. transparent: true, //如果点云透明需要透明
  71494. notAdditiveBlending: Potree.settings.notAdditiveBlending
  71495. });
  71496. }
  71497. if(Potree.settings.intersectOnObjs){// model也要渲染到rtEDL
  71498. Potree.Utils.setCameraLayers(camera, ['model','light']);
  71499. viewer.objs.traverse(e=>{if(e.material)e._OlddepthWrite = e.material.depthWrite, e.material.depthWrite = true;}); //否则半透明的mesh无法遮住测量线
  71500. viewer.renderer.render(viewer.scene.scene, camera);
  71501. viewer.objs.traverse(e=>{if(e.material)e.material.depthWrite = e._OlddepthWrite;});
  71502. //缺点:半透明的model 就算完全透明, 也会遮住测量线
  71503. }
  71504. }
  71505. }
  71506. //渲染到rtEDL完毕
  71507. viewer.dispatchEvent({type: "render.pass.scene", viewer: viewer });
  71508. viewer.renderer.setRenderTarget( target );
  71509. if(!params.magnifier)visiblePointClouds2.forEach(e=>{//放大镜显示点云
  71510. e.visible = e.oldVisi;
  71511. });
  71512. if(showPointClouds){ //绘制点云到画布
  71513. if(useEDL){ //设置edlMaterial //Features.EXT_DEPTH不支持的话不会到这一块
  71514. const uniforms = this.edlMaterial.uniforms;
  71515. uniforms.resolution.value.copy(resolution);
  71516. uniforms.edlStrength.value = viewer.edlStrength;
  71517. uniforms.radius.value = viewer.edlRadius;
  71518. uniforms.useEDL.value = 1;//add
  71519. let proj = camera.projectionMatrix;
  71520. let projArray = new Float32Array(16);
  71521. projArray.set(proj.elements);
  71522. uniforms.uProj.value = projArray;
  71523. uniforms.uEDLColor.value = rtEDL.texture;
  71524. uniforms.opacity.value = viewer.edlOpacity; // HACK
  71525. Utils.screenPass.render(viewer.renderer, this.edlMaterial, target); //相当于一个描边后期特效。 缺点: 因为target上的没有抗锯齿,所以点云在晃动镜头时会不稳定地闪烁1px位置。优点:比不打开edl少绘制一次点云,更流畅了?!
  71526. }else if(Potree.settings.useRTPoint && rtEDL){
  71527. this.recoverToScreenMat.uniforms.tDiffuse.value = rtEDL.texture;
  71528. if(this.recoverToScreenMat.defines.useDepth){
  71529. this.recoverToScreenMat.uniforms.depthTex.value = rtEDL.depthTexture;
  71530. }
  71531. Utils.screenPass.render(viewer.renderer, this.recoverToScreenMat, target/* , Potree.settings.useFxaa && viewer.composer2 */);
  71532. params.drawedModelOnRT = Potree.settings.intersectOnObjs;
  71533. }else {
  71534. //渲染点云 (直接用rtEDL上的会失去抗锯齿, 导致频闪、密集时出现条纹, 自己写抗锯齿也要渲染好几次。另外透明度也要处理下)
  71535. let prop = {
  71536. shadowMaps: lights.length > 0 ? [this.shadowMap] : null,
  71537. clipSpheres: viewer.scene.volumes.filter(v => (v instanceof SphereVolume$1)) ,
  71538. notAdditiveBlending: Potree.settings.notAdditiveBlending//add 否则透明的点云会挡住后面的模型。 加上这句后竟然透明不会叠加了!
  71539. };
  71540. viewer.pRenderer.render(viewer.scene.scenePointCloud, camera, null , prop);
  71541. }
  71542. }
  71543. visiblePointClouds2.forEach(e=>{
  71544. e.visible = e.oldVisi;
  71545. });
  71546. //viewer.dispatchEvent({type: "render.pass.end",viewer: viewer});
  71547. }
  71548. /*
  71549. 渲染顺序:
  71550. 底层:背景 -> skybox(也可中间)
  71551. 中间层(含有深度信息):1 点云、marker等mesh,
  71552. 2 测量线(现在被做成借用depthTex
  71553. 顶层:maginifier
  71554. magnifier的贴图渲染不需要顶层、中间层只需要点云。
  71555. */
  71556. }
  71557. class NavigationCube extends Object3D {
  71558. constructor(viewer){
  71559. super();
  71560. this.viewer = viewer;
  71561. let createPlaneMaterial = (img) => {
  71562. let material = new MeshBasicMaterial( {
  71563. depthTest: true,
  71564. depthWrite: true,
  71565. side: DoubleSide
  71566. });
  71567. new TextureLoader().load(
  71568. exports.resourcePath + '/textures/navigation/' + img,
  71569. function(texture) {
  71570. texture.anisotropy = viewer.renderer.capabilities.getMaxAnisotropy();
  71571. material.map = texture;
  71572. material.needsUpdate = true;
  71573. });
  71574. return material;
  71575. };
  71576. let planeGeometry = new PlaneGeometry(1, 1);
  71577. this.front = new Mesh(planeGeometry, createPlaneMaterial('F.png'));
  71578. this.front.position.y = -0.5;
  71579. this.front.rotation.x = Math.PI / 2.0;
  71580. this.front.updateMatrixWorld();
  71581. this.front.name = "F";
  71582. this.add(this.front);
  71583. this.back = new Mesh(planeGeometry, createPlaneMaterial('B.png'));
  71584. this.back.position.y = 0.5;
  71585. this.back.rotation.x = Math.PI / 2.0;
  71586. this.back.updateMatrixWorld();
  71587. this.back.name = "B";
  71588. this.add(this.back);
  71589. this.left = new Mesh(planeGeometry, createPlaneMaterial('L.png'));
  71590. this.left.position.x = -0.5;
  71591. this.left.rotation.y = Math.PI / 2.0;
  71592. this.left.updateMatrixWorld();
  71593. this.left.name = "L";
  71594. this.add(this.left);
  71595. this.right = new Mesh(planeGeometry, createPlaneMaterial('R.png'));
  71596. this.right.position.x = 0.5;
  71597. this.right.rotation.y = Math.PI / 2.0;
  71598. this.right.updateMatrixWorld();
  71599. this.right.name = "R";
  71600. this.add(this.right);
  71601. this.bottom = new Mesh(planeGeometry, createPlaneMaterial('D.png'));
  71602. this.bottom.position.z = -0.5;
  71603. this.bottom.updateMatrixWorld();
  71604. this.bottom.name = "D";
  71605. this.add(this.bottom);
  71606. this.top = new Mesh(planeGeometry, createPlaneMaterial('U.png'));
  71607. this.top.position.z = 0.5;
  71608. this.top.updateMatrixWorld();
  71609. this.top.name = "U";
  71610. this.add(this.top);
  71611. this.width = 150; // in px
  71612. this.camera = new OrthographicCamera(-1, 1, 1, -1, -1, 1);
  71613. this.camera.position.copy(new Vector3(0, 0, 0));
  71614. this.camera.lookAt(new Vector3(0, 1, 0));
  71615. this.camera.updateMatrixWorld();
  71616. this.camera.rotation.order = "ZXY";
  71617. let onMouseDown = (event) => {
  71618. if (!this.visible) {
  71619. return;
  71620. }
  71621. this.pickedFace = null;
  71622. let mouse = new Vector2();
  71623. mouse.x = event.clientX - (window.innerWidth - this.width);
  71624. mouse.y = event.clientY;
  71625. if(mouse.x < 0 || mouse.y > this.width) return;
  71626. mouse.x = (mouse.x / this.width) * 2 - 1;
  71627. mouse.y = -(mouse.y / this.width) * 2 + 1;
  71628. let raycaster = new Raycaster();
  71629. raycaster.setFromCamera(mouse, this.camera);
  71630. raycaster.ray.origin.sub(this.camera.getWorldDirection(new Vector3()));
  71631. let intersects = raycaster.intersectObjects(this.children);
  71632. let minDistance = 1000;
  71633. for (let i = 0; i < intersects.length; i++) {
  71634. if(intersects[i].distance < minDistance) {
  71635. this.pickedFace = intersects[i].object.name;
  71636. minDistance = intersects[i].distance;
  71637. }
  71638. }
  71639. if(this.pickedFace) {
  71640. this.viewer.setView(this.pickedFace);
  71641. }
  71642. };
  71643. this.viewer.renderer.domElement.addEventListener('mousedown', onMouseDown, false);
  71644. }
  71645. update(rotation) {
  71646. this.camera.rotation.copy(rotation);
  71647. this.visible && this.camera.updateMatrixWorld();
  71648. }
  71649. }
  71650. /**
  71651. *
  71652. * @author sigeom sa / http://sigeom.ch
  71653. * @author Ioda-Net Sàrl / https://www.ioda-net.ch/
  71654. * @author Markus Schütz / http://potree.org
  71655. *
  71656. */
  71657. class GeoJSONExporter{
  71658. static measurementToFeatures (measurement) {
  71659. let coords = measurement.points.map(e => e.position.toArray());
  71660. let features = [];
  71661. if (coords.length === 1) {
  71662. let feature = {
  71663. type: 'Feature',
  71664. geometry: {
  71665. type: 'Point',
  71666. coordinates: coords[0]
  71667. },
  71668. properties: {
  71669. name: measurement.name
  71670. }
  71671. };
  71672. features.push(feature);
  71673. } else if (coords.length > 1 && !measurement.closed) {
  71674. let object = {
  71675. 'type': 'Feature',
  71676. 'geometry': {
  71677. 'type': 'LineString',
  71678. 'coordinates': coords
  71679. },
  71680. 'properties': {
  71681. name: measurement.name
  71682. }
  71683. };
  71684. features.push(object);
  71685. } else if (coords.length > 1 && measurement.closed) {
  71686. let object = {
  71687. 'type': 'Feature',
  71688. 'geometry': {
  71689. 'type': 'Polygon',
  71690. 'coordinates': [[...coords, coords[0]]]
  71691. },
  71692. 'properties': {
  71693. name: measurement.name
  71694. }
  71695. };
  71696. features.push(object);
  71697. }
  71698. if (measurement.showDistances) {
  71699. measurement.edgeLabels.forEach((label) => {
  71700. let labelPoint = {
  71701. type: 'Feature',
  71702. geometry: {
  71703. type: 'Point',
  71704. coordinates: label.position.toArray()
  71705. },
  71706. properties: {
  71707. distance: label.text
  71708. }
  71709. };
  71710. features.push(labelPoint);
  71711. });
  71712. }
  71713. if (measurement.showArea) {
  71714. let point = measurement.areaLabel.position;
  71715. let labelArea = {
  71716. type: 'Feature',
  71717. geometry: {
  71718. type: 'Point',
  71719. coordinates: point.toArray()
  71720. },
  71721. properties: {
  71722. area: measurement.areaLabel.text
  71723. }
  71724. };
  71725. features.push(labelArea);
  71726. }
  71727. return features;
  71728. }
  71729. static toString (measurements) {
  71730. if (!(measurements instanceof Array)) {
  71731. measurements = [measurements];
  71732. }
  71733. measurements = measurements.filter(m => m instanceof Measure);
  71734. let features = [];
  71735. for (let measure of measurements) {
  71736. let f = GeoJSONExporter.measurementToFeatures(measure);
  71737. features = features.concat(f);
  71738. }
  71739. let geojson = {
  71740. 'type': 'FeatureCollection',
  71741. 'features': features
  71742. };
  71743. return JSON.stringify(geojson, null, '\t');
  71744. }
  71745. }
  71746. /**
  71747. *
  71748. * @author sigeom sa / http://sigeom.ch
  71749. * @author Ioda-Net Sàrl / https://www.ioda-net.ch/
  71750. * @author Markus Schuetz / http://potree.org
  71751. *
  71752. */
  71753. class DXFExporter {
  71754. static measurementPointSection (measurement) {
  71755. let position = measurement.points[0].position;
  71756. if (!position) {
  71757. return '';
  71758. }
  71759. let dxfSection = `0
  71760. CIRCLE
  71761. 8
  71762. layer_point
  71763. 10
  71764. ${position.x}
  71765. 20
  71766. ${position.y}
  71767. 30
  71768. ${position.z}
  71769. 40
  71770. 1.0
  71771. `;
  71772. return dxfSection;
  71773. }
  71774. static measurementPolylineSection (measurement) {
  71775. // bit code for polygons/polylines:
  71776. // https://www.autodesk.com/techpubs/autocad/acad2000/dxf/polyline_dxf_06.htm
  71777. let geomCode = 8;
  71778. if (measurement.closed) {
  71779. geomCode += 1;
  71780. }
  71781. let dxfSection = `0
  71782. POLYLINE
  71783. 8
  71784. layer_polyline
  71785. 62
  71786. 1
  71787. 66
  71788. 1
  71789. 10
  71790. 0.0
  71791. 20
  71792. 0.0
  71793. 30
  71794. 0.0
  71795. 70
  71796. ${geomCode}
  71797. `;
  71798. let xMax = 0.0;
  71799. let yMax = 0.0;
  71800. let zMax = 0.0;
  71801. for (let point of measurement.points) {
  71802. point = point.position;
  71803. xMax = Math.max(xMax, point.x);
  71804. yMax = Math.max(yMax, point.y);
  71805. zMax = Math.max(zMax, point.z);
  71806. dxfSection += `0
  71807. VERTEX
  71808. 8
  71809. 0
  71810. 10
  71811. ${point.x}
  71812. 20
  71813. ${point.y}
  71814. 30
  71815. ${point.z}
  71816. 70
  71817. 32
  71818. `;
  71819. }
  71820. dxfSection += `0
  71821. SEQEND
  71822. `;
  71823. return dxfSection;
  71824. }
  71825. static measurementSection (measurement) {
  71826. // if(measurement.points.length <= 1){
  71827. // return "";
  71828. // }
  71829. if (measurement.points.length === 0) {
  71830. return '';
  71831. } else if (measurement.points.length === 1) {
  71832. return DXFExporter.measurementPointSection(measurement);
  71833. } else if (measurement.points.length >= 2) {
  71834. return DXFExporter.measurementPolylineSection(measurement);
  71835. }
  71836. }
  71837. static toString(measurements){
  71838. if (!(measurements instanceof Array)) {
  71839. measurements = [measurements];
  71840. }
  71841. measurements = measurements.filter(m => m instanceof Measure);
  71842. let points = measurements.filter(m => (m instanceof Measure))
  71843. .map(m => m.points)
  71844. .reduce((a, v) => a.concat(v))
  71845. .map(p => p.position);
  71846. let min = new Vector3(Infinity, Infinity, Infinity);
  71847. let max = new Vector3(-Infinity, -Infinity, -Infinity);
  71848. for (let point of points) {
  71849. min.min(point);
  71850. max.max(point);
  71851. }
  71852. let dxfHeader = `999
  71853. DXF created from potree
  71854. 0
  71855. SECTION
  71856. 2
  71857. HEADER
  71858. 9
  71859. $ACADVER
  71860. 1
  71861. AC1006
  71862. 9
  71863. $INSBASE
  71864. 10
  71865. 0.0
  71866. 20
  71867. 0.0
  71868. 30
  71869. 0.0
  71870. 9
  71871. $EXTMIN
  71872. 10
  71873. ${min.x}
  71874. 20
  71875. ${min.y}
  71876. 30
  71877. ${min.z}
  71878. 9
  71879. $EXTMAX
  71880. 10
  71881. ${max.x}
  71882. 20
  71883. ${max.y}
  71884. 30
  71885. ${max.z}
  71886. 0
  71887. ENDSEC
  71888. `;
  71889. let dxfBody = `0
  71890. SECTION
  71891. 2
  71892. ENTITIES
  71893. `;
  71894. for (let measurement of measurements) {
  71895. dxfBody += DXFExporter.measurementSection(measurement);
  71896. }
  71897. dxfBody += `0
  71898. ENDSEC
  71899. `;
  71900. let dxf = dxfHeader + dxfBody + '0\nEOF';
  71901. return dxf;
  71902. }
  71903. }
  71904. class HandleSvg extends EventDispatcher{
  71905. constructor(position, color){
  71906. super();
  71907. this.position = position;
  71908. this.color = '#'+new Color(color).getHexString();
  71909. this.svg = this.create();
  71910. this.visible_ = true;
  71911. let update = ()=>{
  71912. this.update();
  71913. };
  71914. viewer.addEventListener("camera_changed", update);
  71915. this.addEventListener('dispose', ()=>{
  71916. viewer.removeEventListener("camera_changed", update);
  71917. });
  71918. }
  71919. create(){
  71920. const svgns = "http://www.w3.org/2000/svg";
  71921. const svg = document.createElementNS(svgns, "svg");
  71922. svg.setAttribute("width", "2em");
  71923. svg.setAttribute("height", "2em");
  71924. svg.setAttribute("position", "absolute");
  71925. svg.style.left = "50px";
  71926. svg.style.top = "50px";
  71927. svg.style.position = "absolute";
  71928. svg.style.zIndex = "10000";
  71929. svg.style.cursor = 'grab';
  71930. svg.style.transform = 'translate(-50%,-50%)';
  71931. const circle = document.createElementNS(svgns, 'circle');
  71932. circle.setAttributeNS(null, 'cx', "1em");
  71933. circle.setAttributeNS(null, 'cy', "1em");
  71934. circle.setAttributeNS(null, 'r', "0.5em");
  71935. circle.setAttributeNS(null, 'style', 'fill: '+this.color+'; stroke: black; stroke-width: 0.2em;' );
  71936. svg.appendChild(circle);
  71937. const element = viewer.renderer.domElement.parentElement;
  71938. element.appendChild(svg);
  71939. const startDrag = (evt) => {
  71940. /* if(evt.button === THREE.MOUSE.RIGHT){
  71941. return
  71942. } */
  71943. this.selectedElement = svg;
  71944. document.addEventListener("mousemove", drag);
  71945. };
  71946. const endDrag = (evt) => {
  71947. this.selectedElement = null;
  71948. document.removeEventListener("mousemove", drag);
  71949. };
  71950. const drag = (evt) => {
  71951. if (this.selectedElement) {
  71952. evt.preventDefault();
  71953. const rect = viewer.renderer.domElement.getBoundingClientRect();
  71954. const x = evt.clientX - rect.x;
  71955. const y = evt.clientY - rect.y;
  71956. const {width, height} = viewer.renderer.getSize(new Vector2());
  71957. const camera = viewer.scene.getActiveCamera();
  71958. const projected = this.position.clone().project(camera);
  71959. projected.x = ((x / width) - 0.5) / 0.5;
  71960. projected.y = (-(y - height) / height - 0.5) / 0.5;
  71961. const unprojected = projected.clone().unproject(camera);
  71962. this.position.set(unprojected.x, unprojected.y, unprojected.z);
  71963. this.update();
  71964. this.dispatchEvent({type:'dragged', position: this.position});
  71965. }
  71966. };
  71967. svg.addEventListener('mousedown', startDrag);
  71968. svg.addEventListener('mouseup', endDrag);
  71969. svg.style.display = this.visible ? "" : "none";
  71970. this.addEventListener('dispose',()=>{
  71971. svg.removeEventListener('mousedown', startDrag);
  71972. svg.removeEventListener('mouseup', endDrag);
  71973. });
  71974. return svg
  71975. }
  71976. set visible(v){
  71977. this.visible_ = v;
  71978. if(v){
  71979. this.update();
  71980. }else {
  71981. this.svg.style.display = "none";
  71982. }
  71983. }
  71984. get visible(){
  71985. return this.visible_
  71986. }
  71987. update(){
  71988. if(!this.visible)return
  71989. let camera = viewer.scene.getActiveCamera();
  71990. var p = Potree.Utils.getPos2d( this.position, viewer.mainViewport, viewer.renderArea);
  71991. if(!p.trueSide){
  71992. return this.svg.style.display = 'none';
  71993. }
  71994. this.svg.style.left = p.posInViewport.x;
  71995. this.svg.style.top = p.posInViewport.y;
  71996. this.svg.style.display = '';
  71997. }
  71998. dispose(){
  71999. this.svg.remove();
  72000. this.dispatchEvent('dispose');
  72001. }
  72002. }
  72003. /*
  72004. 两种拖拽方式:
  72005. 1 只依附在点云上
  72006. 2 平行于镜头view移动 */
  72007. const geo$1 = new PlaneBufferGeometry(1,1);
  72008. class HandleSprite extends Sprite$2{
  72009. constructor(position,options={}){
  72010. options.sizeInfo = {width2d:60};
  72011. super(options);
  72012. this.position.copy(position);
  72013. this.dragStyle = options.dragStyle || 'default'; //'default'||'onPointCloud'
  72014. this.bindEvent();
  72015. }
  72016. bindEvent(){
  72017. let projectedStart, pointerStart;
  72018. const drag = (e)=>{
  72019. /* if(e.hoverViewport != e.drag.dragViewport){//不能使用e.dragViewport,要使用drag中的,因为drag中存储的要一直继承下来,不因mouseup了而改变。
  72020. viewer.dispatchEvent({
  72021. type : "CursorChange", action : "add", name:"polygon_AtWrongPlace"
  72022. })
  72023. return
  72024. } */
  72025. const camera = viewer.scene.getActiveCamera();
  72026. if(projectedStart){
  72027. let move2d = new Vector2().subVectors(e.pointer, pointerStart);
  72028. let projectNow = projectedStart.clone();
  72029. projectNow.x += move2d.x;
  72030. projectNow.y += move2d.y;
  72031. let unprojected = projectNow.clone().unproject(camera);
  72032. this.position.set(unprojected.x, unprojected.y, unprojected.z);
  72033. }else {
  72034. projectedStart = this.position.clone().project(camera);
  72035. pointerStart = e.pointer.clone();
  72036. }
  72037. this.update();
  72038. this.dispatchEvent({type:'dragged', position: this.position });
  72039. };
  72040. const drop = (e)=>{
  72041. projectedStart = null, pointerStart = null;
  72042. };
  72043. const mouseover = (e) => {
  72044. viewer.dispatchEvent({
  72045. type : "CursorChange", action : "add", name:"markerMove"
  72046. });
  72047. };
  72048. const mouseleave = (e) => {
  72049. viewer.dispatchEvent({
  72050. type : "CursorChange", action : "remove", name:"markerMove"
  72051. });
  72052. };
  72053. this.addEventListener('drag', drag);
  72054. this.addEventListener('drop', drop);
  72055. this.addEventListener('mouseover', mouseover);
  72056. this.addEventListener('mouseleave', mouseleave);
  72057. }
  72058. }
  72059. const sphere = new Mesh(new SphereBufferGeometry(0.08,0.08,3,2), new MeshBasicMaterial({color:'#f88'}));
  72060. class CurveCtrl extends Object3D {
  72061. constructor(points, lineMat, color, name, options={}){
  72062. super();
  72063. this.curve = new CatmullRomCurve3(points, false, "centripetal" /* , tension */);
  72064. this.name = name || 'curveNode';
  72065. this.handleMat = options.handleMat;
  72066. this.lineMat = lineMat;
  72067. this.createPath();
  72068. this.color = color;
  72069. this.handles = [];
  72070. this.wholeLength = 0;
  72071. this.viewports = options.viewports || [viewer.mainViewport]; //for HandleSprite
  72072. for(let i=0,j=this.points.length; i<j;i++){
  72073. this.handles.push(this.createHandle(this.points[i]));
  72074. }
  72075. this.visible_ = true;
  72076. if(Potree.settings.isTest){
  72077. this.spheres = new Object3D;
  72078. /* let i = Count+1;
  72079. while(i>0){
  72080. this.spheres.add(sphere.clone());
  72081. i--;
  72082. } */
  72083. this.add(this.spheres);
  72084. }
  72085. this.updatePath();
  72086. }
  72087. addPoint(position, index, ifUpdate){
  72088. let length = this.points.length;
  72089. if(index == void 0 ){
  72090. index = length;
  72091. }
  72092. let handle = this.createHandle(position);
  72093. this.handles = [...this.handles.slice(0,index), handle, ...this.handles.slice(index,length)];
  72094. this.points = [...this.points.slice(0,index), position, ...this.points.slice(index,length)];
  72095. ifUpdate && (this.updatePath(), this.updateHandle(index));
  72096. }
  72097. removePoint(index){
  72098. let handle = this.handles[index];
  72099. handle.dispose();
  72100. this.handles.splice(index,1);
  72101. this.points.splice(index,1);
  72102. this.updatePath();
  72103. }
  72104. createPath(){
  72105. const line = LineDraw.createFatLine( [ ],this.lineMat);
  72106. this.line = line;
  72107. this.add(line);
  72108. }
  72109. updatePath(){
  72110. this.curve.needsUpdate = true; //如果不更新,得到的点不均匀,开头点少。
  72111. let points, length = this.points.length;
  72112. this.wholeLength = this.points.reduce((total, currentValue, currentIndex, arr)=>{ //所有端点的距离总和
  72113. if(currentIndex == 0)return 0
  72114. return total + currentValue.distanceTo(arr[currentIndex-1]);
  72115. },0);
  72116. if(length > 1){
  72117. const count = MathUtils.clamp(Math.ceil(this.wholeLength * 5), 30, 500);
  72118. points = this.curve.getSpacedPoints( count );
  72119. if(this.needsPercent){ //获取每个节点在整条中的百分比,便于定位(但不精确)
  72120. this.pointsPercent = [0];
  72121. let sums = [0];
  72122. let sum = 0, last = points[0];
  72123. for(let i=1;i<length;i++){
  72124. let point = this.points[i];
  72125. sum += point.distanceTo(last); //参考getLengths函数,根据长度得到百分比
  72126. last = point;
  72127. sums.push(sum);
  72128. }
  72129. for(let i=1;i<length;i++){
  72130. this.pointsPercent.push(sum == 0 ? i/length : sums[i] / sum);
  72131. }
  72132. }
  72133. if(Potree.settings.isTest){
  72134. this.spheres.children.forEach(e=>e.visible = false);
  72135. points.forEach((e,i)=>{
  72136. let sphere1 = this.spheres.children[i];
  72137. if(!sphere1){
  72138. sphere1 = sphere.clone();
  72139. this.spheres.add(sphere1);
  72140. }
  72141. sphere1.position.copy(e);
  72142. sphere1.visible = true;
  72143. });
  72144. }
  72145. }else {
  72146. points = [];
  72147. }
  72148. LineDraw.updateLine(this.line, points);
  72149. this.dispatchEvent('updatePath');
  72150. }
  72151. createHandle(position){
  72152. if(this.handleMat){
  72153. var handle = new HandleSprite(position, {mat:this.handleMat, viewports:this.viewports});
  72154. this.add(handle);
  72155. }else {
  72156. var handle = new HandleSvg(position, this.color);
  72157. }
  72158. handle.visible = this.visible;
  72159. handle.addEventListener('dragged',(e)=>{
  72160. let index = this.handles.indexOf(handle);
  72161. this.points[index].copy(e.position);
  72162. this.updatePath();
  72163. this.dispatchEvent({type:'dragCurvePoint', index});
  72164. });
  72165. return handle
  72166. }
  72167. updateHandle(index){
  72168. if(!this.visible)return
  72169. this.handles[index].update();
  72170. }
  72171. updateHandles(){
  72172. this.handles.forEach((handle,index)=>{
  72173. this.updateHandle(index);
  72174. });
  72175. }
  72176. update(){
  72177. this.updateHandles();
  72178. this.updatePath();
  72179. }
  72180. set visible(v){
  72181. if(v != this.visible_ ){
  72182. this.visible_ = v;
  72183. this.visible = v;
  72184. if(this.handles){
  72185. this.handles.forEach(e=>e.visible = v );
  72186. if(v) this.updateHandles(); //因为不可见时没更新位置
  72187. }
  72188. }
  72189. }
  72190. get visible(){
  72191. return this.visible_
  72192. }
  72193. /* set visible(v){
  72194. this.handles.forEach(e=>e.svg.style.display = v ? "" : "none" )
  72195. if(v) this.updateHandles() //因为不可见时没更新位置
  72196. } */
  72197. get points(){
  72198. return this.curve.points;
  72199. }
  72200. set points(points){
  72201. this.curve.points = points;
  72202. }
  72203. getPointAt(t){
  72204. return this.curve.getPointAt(t)
  72205. }
  72206. getSpacedPoints(t){
  72207. return this.curve.getSpacedPoints(t)
  72208. }
  72209. dispose(){
  72210. this.parent && this.parent.remove(this);
  72211. this.handles.forEach(e=>e.dispose() );
  72212. this.line.geometry && this.line.geometry.dispose();
  72213. }
  72214. }
  72215. const colors$1 = {
  72216. position: 'red',
  72217. target : 'blue'
  72218. };
  72219. let lineMats$1;
  72220. const getLineMat = function(name){
  72221. if(!lineMats$1){
  72222. lineMats$1 = {
  72223. position: LineDraw.createFatLineMat({
  72224. color: colors$1.position,
  72225. lineWidth: 3
  72226. }),
  72227. target : LineDraw.createFatLineMat({
  72228. color: colors$1.target,
  72229. lineWidth: 3
  72230. }),
  72231. frustum: LineDraw.createFatLineMat({
  72232. color: colors$1.position,
  72233. lineWidth: 2
  72234. }),
  72235. aimAtTarget: new LineBasicMaterial({color:colors$1.target, depthTest:false})
  72236. };
  72237. }
  72238. return lineMats$1[name]
  72239. };
  72240. class CameraAnimation$1 extends EventDispatcher{
  72241. constructor(viewer){
  72242. super();
  72243. this.viewer = viewer;
  72244. this.selectedElement = null;
  72245. //this.controlPoints = [];
  72246. this.uuid = MathUtils.generateUUID();
  72247. this.node = new Object3D();
  72248. this.node.name = "camera animation";
  72249. this.viewer.scene.scene.add(this.node);
  72250. this.frustum = this.createFrustum();
  72251. this.node.add(this.frustum);
  72252. this.name = "Camera Animation";
  72253. // "centripetal", "chordal", "catmullrom"
  72254. this.curveType = "centripetal";
  72255. this.visible = true;
  72256. this.targets = [];
  72257. this.createPath();
  72258. this.duration = 5;
  72259. this.percent = 0;
  72260. this.currentIndex = 0;
  72261. this.durations = [];
  72262. this.quaternions = [];
  72263. if(!Potree.settings.isTest && Potree.settings.isOfficial ){
  72264. this.setVisible(false);
  72265. }
  72266. this.addEventListener('dispose', ()=>{
  72267. this.dispose();
  72268. });
  72269. this.targetLines = new Object3D;
  72270. this.node.add(this.targetLines);
  72271. }
  72272. static defaultFromView(viewer){
  72273. const animation = new CameraAnimation$1(viewer);
  72274. const camera = viewer.scene.getActiveCamera();
  72275. const target = viewer.scene.view.getPivot();
  72276. const cpCenter = new Vector3(
  72277. 0.3 * camera.position.x + 0.7 * target.x,
  72278. 0.3 * camera.position.y + 0.7 * target.y,
  72279. 0.3 * camera.position.z + 0.7 * target.z,
  72280. );
  72281. const targetCenter = new Vector3(
  72282. 0.05 * camera.position.x + 0.95 * target.x,
  72283. 0.05 * camera.position.y + 0.95 * target.y,
  72284. 0.05 * camera.position.z + 0.95 * target.z,
  72285. );
  72286. const r = 2;//camera.position.distanceTo(target) * 0.3;
  72287. //const dir = target.clone().sub(camera.position).normalize();
  72288. const angle = Utils.computeAzimuth(camera.position, target);
  72289. const n = 5;
  72290. for(let i = 0; i < n; i++){
  72291. let u = 1.5 * Math.PI * (i / n) + angle;
  72292. const dx = r * Math.cos(u);
  72293. const dy = r * Math.sin(u);
  72294. const cpPos = new Vector3(
  72295. cpCenter.x + dx,
  72296. cpCenter.y + dy,
  72297. cpCenter.z,
  72298. );
  72299. const targetPos = new Vector3(
  72300. targetCenter.x + dx * 0.1,
  72301. targetCenter.y + dy * 0.1,
  72302. targetCenter.z,
  72303. );
  72304. animation.createControlPoint(null,{position:cpPos, target:targetPos});
  72305. }
  72306. animation.changeCallback();
  72307. return animation;
  72308. }
  72309. createControlPoint(index, posInfo ){
  72310. const length = this.posCurve.points.length;
  72311. const position = new Vector3;
  72312. const target = new Vector3;
  72313. if(index == void 0 ){
  72314. index = length;
  72315. }
  72316. if(!posInfo){
  72317. if(length >= 2 && index === 0){
  72318. const dir = new Vector3().subVectors(this.posCurve.points[0], this.posCurve.points[1] );
  72319. position.copy(this.posCurve.points[0]).add(dir);
  72320. const tDir = new Vector3().subVectors(this.targets[0].position, this.targets[1].position );
  72321. target.copy(this.targets[0].position).add(dir);
  72322. }else if(length >= 2 && index === length){
  72323. const dir = new Vector3().subVectors(this.posCurve.points[length-1], this.posCurve.points[length-2] );
  72324. position.copy(this.posCurve.points[length-2]).add(dir);
  72325. const tDir = new Vector3().subVectors(this.targets[length-1].position, this.targets[length-2].position );
  72326. target.copy(this.targets[length-2].position).add(dir);
  72327. }else if(length >= 2){
  72328. position.copy(this.posCurve.points[index-1].clone().add(this.posCurve.points[index]).multiplyScalar(0.5));
  72329. target.copy(this.targets[index-1].position.clone().add(this.targets[index].position).multiplyScalar(0.5));
  72330. }
  72331. }else {
  72332. position.copy(posInfo.position);
  72333. target.copy(posInfo.target);
  72334. }
  72335. this.posCurve.addPoint(position, index/* , true */);
  72336. //this.targetCurve.addPoint(target, index/* , true */)
  72337. let targetSvg = new HandleSvg(target, colors$1.target);
  72338. targetSvg.visible = this.visible;
  72339. this.targets = [...this.targets.slice(0,index), targetSvg, ...this.targets.slice(index,length)];
  72340. if(this.useDurSlice){//不使用全局的duration,而是分段的
  72341. this.durations = [...this.durations.slice(0,index), posInfo.duration, ...this.durations.slice(index,length)];
  72342. }
  72343. this.dispatchEvent({
  72344. type: "controlpoint_added",
  72345. index
  72346. });
  72347. {
  72348. let targetLine = LineDraw.createLine([position,target] ,{mat: getLineMat('aimAtTarget')});
  72349. this.targetLines.children = [...this.targetLines.children.slice(0,index), targetLine, ...this.targetLines.children.slice(index,length)];
  72350. this.targets[index].addEventListener('dragged', (e)=>{
  72351. this.updatePathCallback();
  72352. this.dragPointCallback(e);
  72353. });
  72354. }
  72355. }
  72356. dragPointCallback(e){
  72357. let index = e.index;
  72358. if(e.index == void 0){
  72359. index = this.targets.indexOf(e.target);
  72360. }
  72361. LineDraw.moveLine(this.targetLines.children[index], [this.posCurve.points[index], this.targets[index].position] );
  72362. viewer.dispatchEvent('content_changed');
  72363. this.updateFrustum();
  72364. }
  72365. updatePathCallback(){
  72366. {
  72367. this.quaternions = [];
  72368. let length = this.posCurve.points.length;
  72369. for(let i=0; i<length; i++){
  72370. let quaternion = math.getQuaFromPosAim(this.posCurve.points[i], this.targets[i].position);
  72371. this.quaternions.push( quaternion);
  72372. }
  72373. }
  72374. this.reMapCurvePercent();
  72375. }
  72376. removeControlPoint(index){
  72377. this.posCurve.removePoint(index);
  72378. //this.targetCurve.removePoint(index)
  72379. this.targets[index].dispose();
  72380. this.targets.splice(index, 1);
  72381. this.dispatchEvent({
  72382. type: "controlpoint_removed",
  72383. index
  72384. });
  72385. this.targetLines.remove(this.targetLines.children[index]);
  72386. if(this.useDurSlice){
  72387. this.durations.splice(index, 1);
  72388. }
  72389. }
  72390. createPath(){
  72391. this.posCurve = new CurveCtrl([],getLineMat('position'), colors$1.position, 'posCurve');
  72392. //this.targetCurve = new CurveCtrl([], getLineMat('target'), colors.target, 'targetCurve', {noLine:true});
  72393. this.posCurve.needsPercent = true;
  72394. this.node.add(this.posCurve);
  72395. //this.node.add(this.targetCurve)
  72396. this.posCurve.addEventListener('dragCurvePoint', this.dragPointCallback.bind(this));
  72397. this.posCurve.addEventListener('updatePath', this.updatePathCallback.bind(this));
  72398. }
  72399. createFrustum(){
  72400. const f = 0.3;
  72401. const positions = [
  72402. new Vector3( 0, 0, 0),
  72403. new Vector3(-f, -f, +1),
  72404. new Vector3( 0, 0, 0),
  72405. new Vector3( f, -f, +1),
  72406. new Vector3( 0, 0, 0),
  72407. new Vector3( f, f, +1),
  72408. new Vector3( 0, 0, 0),
  72409. new Vector3(-f, f, +1),
  72410. new Vector3(-f, -f, +1),
  72411. new Vector3( f, -f, +1),
  72412. new Vector3( f, -f, +1),
  72413. new Vector3( f, f, +1),
  72414. new Vector3( f, f, +1),
  72415. new Vector3(-f, f, +1),
  72416. new Vector3(-f, f, +1),
  72417. new Vector3(-f, -f, +1),
  72418. ];
  72419. positions.forEach(e=>e.z *= -1); //因为得到的rotation是camera的,作用在物体上要反向,所以这里反向一下
  72420. //geometry.computeBoundingSphere();//?
  72421. const line = LineDraw.createFatLine( positions, {mat:getLineMat('frustum')});
  72422. //line.scale.set(20, 20, 20);
  72423. line.visible = false;
  72424. return line;
  72425. }
  72426. reMapCurvePercent(){ //因在不同点在相同位置旋转,由于间隔仅和位置距离相关,导致时间间隔为0,采取重新调整间隔的策略。
  72427. var length = this.posCurve.points.length;
  72428. if(length<2){
  72429. return this.newPointsPercents = []
  72430. }
  72431. var newPercents = [0];
  72432. if(this.useDurSlice){ //已经设定好了每一段的duration的话
  72433. let sums = [0];
  72434. let sum = 0, last;
  72435. for(let i=0;i<length-1;i++){ //去掉最后一个duration,因为已到终点
  72436. let duration = this.durations[i];
  72437. sum += duration;
  72438. last = duration;
  72439. sums.push(sum);
  72440. }
  72441. for(let i=1;i<length;i++){
  72442. newPercents.push(sum == 0 ? i/length : sums[i] / sum);
  72443. }
  72444. }else {
  72445. const maxSpaceDur = this.duration / length; //每两点之间修改间隔时间后,最大时间
  72446. const durPerRad = 0.8; //每弧度应该占用的时间
  72447. const minSpaceDur = Math.min(0.8, maxSpaceDur);//每两点之间修改间隔时间后,最小时间
  72448. const maxAngleSpaceDur = MathUtils.clamp(durPerRad * Math.PI, minSpaceDur, maxSpaceDur );// 最大可能差距是180度
  72449. var percents = this.posCurve.pointsPercent;
  72450. for(let i=1;i<length;i++){
  72451. let diff = (percents[i] - percents[i-1]) * this.duration; //间隔时间
  72452. let percent;
  72453. let curMin = minSpaceDur;
  72454. if(diff < maxAngleSpaceDur){ //若小于最大旋转时间
  72455. let rad = this.quaternions[i].angleTo(this.quaternions[i-1]);
  72456. curMin = MathUtils.clamp(rad * durPerRad, minSpaceDur, maxSpaceDur);
  72457. }
  72458. diff = Math.max(diff, curMin);
  72459. percent = newPercents[i-1] + (diff / this.duration); //得到新的percent
  72460. newPercents.push(percent);
  72461. }
  72462. let maxPercent = newPercents[length-1]; //最后一个,若扩充过时间,就会>1
  72463. if( !math.closeTo(maxPercent, 1)){
  72464. let scale = 1 / maxPercent; //需要压缩的比例 <1 这一步会让实际得到的间隔更小
  72465. newPercents = newPercents.map(e=> e*=scale );
  72466. }
  72467. }
  72468. this.newPointsPercents = newPercents;
  72469. //console.log(newPercents)
  72470. }
  72471. at(originPercent, delta, transitionRatio){
  72472. originPercent = MathUtils.clamp(originPercent, 0, 1);
  72473. //修改第一层:起始时间
  72474. let percent = originPercent;
  72475. /* const easePercent = 0.3; //缓动占比 //如果能在所有从静止到运动的中间加缓动就好了呀:lastPos * 0.9 + currentPos * 0.1 ?
  72476. if(originPercent < easePercent){
  72477. console.log('easeIn')
  72478. percent = easing.easeInSine(originPercent, 0, easePercent, easePercent) //currentTime, startY, wholeY, duration 选了一个衔接时接近斜率1的缓动函数
  72479. }else if(originPercent > 1-easePercent){
  72480. console.log('easeOut')
  72481. percent = easing.easeOutSine(originPercent-(1-easePercent), 1-easePercent, easePercent, easePercent)
  72482. } */
  72483. let quaternion;
  72484. if(percent < 1){
  72485. //修改第二层:使用每个点的重定位的 newPointsPercents
  72486. this.currentIndex = this.newPointsPercents.findIndex(e=> e>percent ) - 1;
  72487. //假设每个节点的百分比是精确的,那么:
  72488. let curIndexPercent = this.newPointsPercents[this.currentIndex];
  72489. let nextIndexPercent = this.newPointsPercents[this.currentIndex+1];
  72490. let progress = (percent - curIndexPercent) / (nextIndexPercent - curIndexPercent);//在这两个节点间的百分比
  72491. //投影到原本的 posCurve.pointsPercent上:
  72492. let curIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex];
  72493. let nextIndexOriPercent = this.posCurve.pointsPercent[this.currentIndex+1];
  72494. percent = curIndexOriPercent + (nextIndexOriPercent - curIndexOriPercent) * progress;
  72495. let endQuaternion = this.quaternions[this.currentIndex+1];
  72496. let startQuaternion = this.quaternions[this.currentIndex];
  72497. quaternion = (new Quaternion()).copy(startQuaternion);
  72498. lerp.quaternion(quaternion, endQuaternion)(progress);
  72499. }else {
  72500. this.currentIndex = this.posCurve.points.length - 1;
  72501. quaternion = math.getQuaFromPosAim(this.posCurve.points[this.currentIndex], this.targets[this.currentIndex].position);
  72502. }
  72503. const position = this.posCurve.getPointAt(percent); // 需要this.posCurve.points.length>1 否则报错
  72504. //console.log(this.currentIndex, originPercent)
  72505. //缓动:
  72506. var aimQua, aimPos;
  72507. if(delta != void 0 ){
  72508. if(Potree.settings.tourTestCameraMove){
  72509. aimQua = this.frustum.quaternion.clone();
  72510. aimPos = this.frustum.position.clone();
  72511. }else {
  72512. var camera = viewer.scene.getActiveCamera();
  72513. aimQua = camera.quaternion.clone();
  72514. aimPos = camera.position.clone();
  72515. }
  72516. transitionRatio = transitionRatio || 1 / Potree.settings.cameraAniSmoothRatio;//渐变系数,越小缓动程度越高,越平滑
  72517. transitionRatio *= delta * 60; //假设标准帧率为60fps,当帧率低时(delta大时)要降低缓动
  72518. //console.log(transitionRatio, delta) //画面ui变化会使delta变大
  72519. transitionRatio = MathUtils.clamp(transitionRatio, 0, 1);
  72520. lerp.quaternion(aimQua, quaternion)(transitionRatio); //每次只改变一点点
  72521. lerp.vector(aimPos, position)(transitionRatio);
  72522. }else {
  72523. aimQua = quaternion; aimPos = position;
  72524. }
  72525. let rotation = new Euler().setFromQuaternion(aimQua );
  72526. const frame = {
  72527. position: aimPos,
  72528. rotation
  72529. };
  72530. return frame;
  72531. }
  72532. set(percent){
  72533. this.percent = percent;
  72534. }
  72535. setVisible(visible){
  72536. this.node.visible = visible;
  72537. this.posCurve.visible = visible;
  72538. this.targets.forEach(e=>e.visible = visible );
  72539. this.visible = visible;
  72540. }
  72541. setDuration(duration){
  72542. if(duration != this.duration){
  72543. this.duration = duration;
  72544. if(this.quaternions.length == this.posCurve.points.length)this.reMapCurvePercent();
  72545. }
  72546. }
  72547. getDuration(duration){
  72548. return this.duration;
  72549. }
  72550. play(startOptions={}){
  72551. if(this.onUpdate){
  72552. return console.error('已经开始播放')
  72553. }
  72554. let startPercent = 0, currentIndex = 0;
  72555. if(startOptions.percent != void 0 ){
  72556. startPercent = startOptions.percent;
  72557. }else if(startOptions.index){
  72558. currentIndex = index;
  72559. //startPercent = index/(this.posCurve.points.length-1)
  72560. startPercent = this.posCurve.pointsPercent[index];
  72561. }
  72562. //const tStart = performance.now();
  72563. const duration = this.duration;
  72564. this.originalyVisible = this.visible;
  72565. Potree.settings.tourTestCameraMove || this.setVisible(false);
  72566. let tStart, startTransitionRatio = 0.2;
  72567. let startDelay = 1/startTransitionRatio / 20 ;//因为缓动所以延迟开始,前面前都是at(0),使过渡到开始点位(但是依旧不能准确停在起始点,因为缓动是乘百分比有残留。所以直接平滑衔接到开始后的位置)
  72568. let hasPlayedTime = 0;
  72569. let finishDelay = Potree.settings.cameraAniSmoothRatio / 60 * 3;//结束后还需要多久时间才能大致达到缓动的最终目标
  72570. let hasStoppedTime = 0;
  72571. this.onUpdate = (e) => {
  72572. if(this.posCurve.points.length<2){
  72573. if(this.posCurve.points.length == 1){
  72574. viewer.scene.view.position.copy(this.posCurve.points[0]);
  72575. viewer.scene.view.rotation = new Euler().setFromQuaternion(this.quaternions[0]);
  72576. }
  72577. this.pause();
  72578. return
  72579. }
  72580. let percent, transitionRatio;
  72581. if(tStart){
  72582. let tNow = performance.now();
  72583. let elapsed = (tNow - tStart) / 1000;
  72584. percent = elapsed / duration + startPercent;
  72585. }else {//从当前位置过渡到开始位置
  72586. percent = 0;
  72587. hasPlayedTime += e.delta;
  72588. transitionRatio = startTransitionRatio;
  72589. //console.log('延迟开始')
  72590. if(hasPlayedTime > startDelay){
  72591. tStart = performance.now();
  72592. }
  72593. }
  72594. this.set(percent);
  72595. const frame = this.at(percent, e.delta, transitionRatio);
  72596. if(currentIndex != this.currentIndex){
  72597. currentIndex = this.currentIndex;
  72598. console.log('updateCurrentIndex', currentIndex);
  72599. this.dispatchEvent({type:'updateCurrentIndex', currentIndex });
  72600. }
  72601. if(!Potree.settings.tourTestCameraMove){
  72602. viewer.scene.view.position.copy(frame.position);
  72603. //viewer.scene.view.lookAt(frame.target);
  72604. viewer.scene.view.rotation = frame.rotation;
  72605. }
  72606. this.updateFrustum(frame);
  72607. if(percent >= 1){
  72608. if(hasStoppedTime > finishDelay){
  72609. this.pause();
  72610. }else {
  72611. hasStoppedTime += e.delta;
  72612. //console.log('延迟结束')
  72613. }
  72614. }
  72615. };
  72616. this.viewer.addEventListener("update", this.onUpdate);
  72617. }
  72618. pause(){
  72619. this.setVisible(this.originalyVisible);
  72620. this.viewer.removeEventListener("update", this.onUpdate);
  72621. this.dispatchEvent('playDone');
  72622. this.onUpdate = null;
  72623. }
  72624. updateFrustum(frame){
  72625. const frustum = this.frustum;
  72626. if(this.posCurve.points.length>1){
  72627. frustum.visible = true;
  72628. }else {
  72629. frustum.visible = false;
  72630. return
  72631. }
  72632. frame = frame || this.at(this.percent);
  72633. frustum.position.copy(frame.position);
  72634. //frustum.lookAt(...frame.target.toArray());
  72635. frustum.rotation.copy(frame.rotation);
  72636. viewer.dispatchEvent('content_changed');
  72637. }
  72638. changeCallback(i){
  72639. this.posCurve.update();
  72640. //this.targets.forEach(e=>e.update())
  72641. this.updatePathCallback();
  72642. if(i==void 0){
  72643. let length = this.posCurve.points.length;
  72644. for(let i=0; i<length; i++){
  72645. this.dragPointCallback({index:i});
  72646. }
  72647. }else this.dragPointCallback({index:i});
  72648. this.updateFrustum();
  72649. }
  72650. dispose(){//add
  72651. this.posCurve.dispose();
  72652. //this.targetCurve.dispatchEvent({type:'dispose'})
  72653. this.targets.forEach(e=>e.dispose());
  72654. this.durations = [];
  72655. this.node.parent.remove(this.node);
  72656. }
  72657. }
  72658. //scene.removeCameraAnimation
  72659. //修改:不使用targetCurve作为target曲线,因为播放时posCuve的节点和targetCurve并没有对应,且使用target的曲线会使角度变化大的情况过渡生硬。
  72660. // 改完旋转了。但是位置也有问题。速度完全和路程相关,当在同一位置设置多点时,这段的总时长为0. (是否要设置最小时长?不过也做不到 - -)
  72661. class MeasurePanel{
  72662. constructor(viewer, measurement, propertiesPanel){
  72663. this.viewer = viewer;
  72664. this.measurement = measurement;
  72665. this.propertiesPanel = propertiesPanel;
  72666. this._update = () => { this.update(); };
  72667. }
  72668. createCoordinatesTable(points){
  72669. let table = $(`
  72670. <table class="measurement_value_table">
  72671. <tr>
  72672. <th>x</th>
  72673. <th>y</th>
  72674. <th>z</th>
  72675. <th></th>
  72676. </tr>
  72677. </table>
  72678. `);
  72679. let copyIconPath = Potree.resourcePath + '/icons/copy.svg';
  72680. for (let point of points) {
  72681. let x = Utils.addCommas(point.x.toFixed(3));
  72682. let y = Utils.addCommas(point.y.toFixed(3));
  72683. let z = Utils.addCommas(point.z.toFixed(3));
  72684. let row = $(`
  72685. <tr>
  72686. <td><span>${x}</span></td>
  72687. <td><span>${y}</span></td>
  72688. <td><span>${z}</span></td>
  72689. <td align="right" style="width: 25%">
  72690. <img name="copy" title="copy" class="button-icon" src="${copyIconPath}" style="width: 16px; height: 16px"/>
  72691. </td>
  72692. </tr>
  72693. `);
  72694. this.elCopy = row.find("img[name=copy]");
  72695. this.elCopy.click( () => {
  72696. let msg = point.toArray().map(c => c.toFixed(3)).join(", ");
  72697. Utils.clipboardCopy(msg);
  72698. this.viewer.postMessage(
  72699. `Copied value to clipboard: <br>'${msg}'`,
  72700. {duration: 3000});
  72701. });
  72702. table.append(row);
  72703. }
  72704. return table;
  72705. };
  72706. createAttributesTable(){
  72707. let elTable = $('<table class="measurement_value_table"></table>');
  72708. let point = this.measurement.points[0];
  72709. /* for(let attributeName of Object.keys(point)){
  72710. if(attributeName === "position"){
  72711. }else if(attributeName === "rgba"){
  72712. let color = point.rgba;
  72713. let text = color.join(', ');
  72714. elTable.append($(`
  72715. <tr>
  72716. <td>rgb</td>
  72717. <td>${text}</td>
  72718. </tr>
  72719. `));
  72720. }else{
  72721. let value = point[attributeName];
  72722. let text = value.join(', ');
  72723. elTable.append($(`
  72724. <tr>
  72725. <td>${attributeName}</td>
  72726. <td>${text}</td>
  72727. </tr>
  72728. `));
  72729. }
  72730. } */
  72731. return elTable;
  72732. }
  72733. update(){
  72734. }
  72735. };
  72736. class DistancePanel extends MeasurePanel{
  72737. constructor(viewer, measurement, propertiesPanel){
  72738. super(viewer, measurement, propertiesPanel);
  72739. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  72740. this.elContent = $(`
  72741. <div class="measurement_content selectable">
  72742. <span class="coordinates_table_container"></span>
  72743. <br>
  72744. <table id="distances_table" class="measurement_value_table"></table>
  72745. <!-- ACTIONS -->
  72746. <div style="display: flex; margin-top: 12px">
  72747. <span>
  72748. <input type="button" name="make_profile" value="profile from measure" />
  72749. </span>
  72750. <span style="flex-grow: 1"></span>
  72751. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  72752. </div>
  72753. </div>
  72754. `);
  72755. this.elRemove = this.elContent.find("img[name=remove]");
  72756. this.elRemove.click( () => {
  72757. this.viewer.scene.removeMeasurement(measurement);
  72758. });
  72759. this.elMakeProfile = this.elContent.find("input[name=make_profile]");
  72760. this.elMakeProfile.click( () => {
  72761. //measurement.points;
  72762. const profile = new Profile();
  72763. profile.name = measurement.name;
  72764. profile.width = measurement.getTotalDistance() / 50;
  72765. for(const point of measurement.points){
  72766. profile.addMarker(point.position.clone());
  72767. }
  72768. this.viewer.scene.addProfile(profile);
  72769. });
  72770. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  72771. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  72772. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  72773. this.update();
  72774. }
  72775. update(){
  72776. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  72777. elCoordiantesContainer.empty();
  72778. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  72779. let positions = this.measurement.points.map(p => p.position);
  72780. let distances = [];
  72781. for (let i = 0; i < positions.length - 1; i++) {
  72782. let d = positions[i].distanceTo(positions[i + 1]);
  72783. distances.push(d.toFixed(3));
  72784. }
  72785. let totalDistance = this.measurement.getTotalDistance().toFixed(3);
  72786. let elDistanceTable = this.elContent.find(`#distances_table`);
  72787. elDistanceTable.empty();
  72788. for (let i = 0; i < distances.length; i++) {
  72789. let label = (i === 0) ? 'Distances: ' : '';
  72790. let distance = distances[i];
  72791. let elDistance = $(`
  72792. <tr>
  72793. <th>${label}</th>
  72794. <td style="width: 100%; padding-left: 10px">${distance}</td>
  72795. </tr>`);
  72796. elDistanceTable.append(elDistance);
  72797. }
  72798. let elTotal = $(`
  72799. <tr>
  72800. <th>Total: </td><td style="width: 100%; padding-left: 10px">${totalDistance}</th>
  72801. </tr>`);
  72802. elDistanceTable.append(elTotal);
  72803. }
  72804. };
  72805. class PointPanel extends MeasurePanel{
  72806. constructor(viewer, measurement, propertiesPanel){
  72807. super(viewer, measurement, propertiesPanel);
  72808. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  72809. this.elContent = $(`
  72810. <div class="measurement_content selectable">
  72811. <span class="coordinates_table_container"></span>
  72812. <br>
  72813. <span class="attributes_table_container"></span>
  72814. <!-- ACTIONS -->
  72815. <div style="display: flex; margin-top: 12px">
  72816. <span></span>
  72817. <span style="flex-grow: 1"></span>
  72818. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  72819. </div>
  72820. </div>
  72821. `);
  72822. this.elRemove = this.elContent.find("img[name=remove]");
  72823. this.elRemove.click( () => {
  72824. this.viewer.scene.removeMeasurement(measurement);
  72825. });
  72826. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  72827. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  72828. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  72829. this.update();
  72830. }
  72831. update(){
  72832. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  72833. elCoordiantesContainer.empty();
  72834. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points));
  72835. let elAttributesContainer = this.elContent.find('.attributes_table_container');
  72836. elAttributesContainer.empty();
  72837. elAttributesContainer.append(this.createAttributesTable());
  72838. }
  72839. };
  72840. class AreaPanel extends MeasurePanel{
  72841. constructor(viewer, measurement, propertiesPanel){
  72842. super(viewer, measurement, propertiesPanel);
  72843. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  72844. this.elContent = $(`
  72845. <div class="measurement_content selectable">
  72846. <span class="coordinates_table_container"></span>
  72847. <br>
  72848. <span style="font-weight: bold">Area: </span>
  72849. <span id="measurement_area"></span>
  72850. <!-- ACTIONS -->
  72851. <div style="display: flex; margin-top: 12px">
  72852. <span></span>
  72853. <span style="flex-grow: 1"></span>
  72854. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  72855. </div>
  72856. </div>
  72857. `);
  72858. this.elRemove = this.elContent.find("img[name=remove]");
  72859. this.elRemove.click( () => {
  72860. this.viewer.scene.removeMeasurement(measurement);
  72861. });
  72862. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  72863. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  72864. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  72865. this.update();
  72866. }
  72867. update(){
  72868. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  72869. elCoordiantesContainer.empty();
  72870. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points));
  72871. let elArea = this.elContent.find(`#measurement_area`);
  72872. elArea.html(this.measurement.area.value.toFixed(3));
  72873. }
  72874. };
  72875. class AnglePanel extends MeasurePanel{
  72876. constructor(viewer, measurement, propertiesPanel){
  72877. super(viewer, measurement, propertiesPanel);
  72878. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  72879. this.elContent = $(`
  72880. <div class="measurement_content selectable">
  72881. <span class="coordinates_table_container"></span>
  72882. <br>
  72883. <table class="measurement_value_table">
  72884. <tr>
  72885. <th>\u03b1</th>
  72886. <th>\u03b2</th>
  72887. <th>\u03b3</th>
  72888. </tr>
  72889. <tr>
  72890. <td align="center" id="angle_cell_alpha" style="width: 33%"></td>
  72891. <td align="center" id="angle_cell_betta" style="width: 33%"></td>
  72892. <td align="center" id="angle_cell_gamma" style="width: 33%"></td>
  72893. </tr>
  72894. </table>
  72895. <!-- ACTIONS -->
  72896. <div style="display: flex; margin-top: 12px">
  72897. <span></span>
  72898. <span style="flex-grow: 1"></span>
  72899. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  72900. </div>
  72901. </div>
  72902. `);
  72903. this.elRemove = this.elContent.find("img[name=remove]");
  72904. this.elRemove.click( () => {
  72905. this.viewer.scene.removeMeasurement(measurement);
  72906. });
  72907. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  72908. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  72909. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  72910. this.update();
  72911. }
  72912. update(){
  72913. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  72914. elCoordiantesContainer.empty();
  72915. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  72916. let angles = [];
  72917. for(let i = 0; i < this.measurement.points.length; i++){
  72918. angles.push(this.measurement.getAngle(i) * (180.0 / Math.PI));
  72919. }
  72920. angles = angles.map(a => a.toFixed(1) + '\u00B0');
  72921. let elAlpha = this.elContent.find(`#angle_cell_alpha`);
  72922. let elBetta = this.elContent.find(`#angle_cell_betta`);
  72923. let elGamma = this.elContent.find(`#angle_cell_gamma`);
  72924. elAlpha.html(angles[0]);
  72925. elBetta.html(angles[1]);
  72926. elGamma.html(angles[2]);
  72927. }
  72928. };
  72929. class CirclePanel extends MeasurePanel{
  72930. constructor(viewer, measurement, propertiesPanel){
  72931. super(viewer, measurement, propertiesPanel);
  72932. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  72933. this.elContent = $(`
  72934. <div class="measurement_content selectable">
  72935. <span class="coordinates_table_container"></span>
  72936. <br>
  72937. <table id="infos_table" class="measurement_value_table"></table>
  72938. <!-- ACTIONS -->
  72939. <div style="display: flex; margin-top: 12px">
  72940. <span></span>
  72941. <span style="flex-grow: 1"></span>
  72942. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  72943. </div>
  72944. </div>
  72945. `);
  72946. this.elRemove = this.elContent.find("img[name=remove]");
  72947. this.elRemove.click( () => {
  72948. this.viewer.scene.removeMeasurement(measurement);
  72949. });
  72950. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  72951. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  72952. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  72953. this.update();
  72954. }
  72955. update(){
  72956. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  72957. elCoordiantesContainer.empty();
  72958. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  72959. const elInfos = this.elContent.find(`#infos_table`);
  72960. if(this.measurement.points.length !== 3){
  72961. elInfos.empty();
  72962. return;
  72963. }
  72964. const A = this.measurement.points[0].position;
  72965. const B = this.measurement.points[1].position;
  72966. const C = this.measurement.points[2].position;
  72967. const center = Potree.Utils.computeCircleCenter(A, B, C);
  72968. const radius = center.distanceTo(A);
  72969. const circumference = 2 * Math.PI * radius;
  72970. const format = (number) => {
  72971. return Potree.Utils.addCommas(number.toFixed(3));
  72972. };
  72973. const txtCenter = `${format(center.x)} ${format(center.y)} ${format(center.z)}`;
  72974. const txtRadius = format(radius);
  72975. const txtCircumference = format(circumference);
  72976. const thStyle = `style="text-align: left"`;
  72977. const tdStyle = `style="width: 100%; padding: 5px;"`;
  72978. elInfos.html(`
  72979. <tr>
  72980. <th ${thStyle}>Center: </th>
  72981. <td ${tdStyle}></td>
  72982. </tr>
  72983. <tr>
  72984. <td ${tdStyle} colspan="2">
  72985. ${txtCenter}
  72986. </td>
  72987. </tr>
  72988. <tr>
  72989. <th ${thStyle}>Radius: </th>
  72990. <td ${tdStyle}>${txtRadius}</td>
  72991. </tr>
  72992. <tr>
  72993. <th ${thStyle}>Circumference: </th>
  72994. <td ${tdStyle}>${txtCircumference}</td>
  72995. </tr>
  72996. `);
  72997. }
  72998. };
  72999. class HeightPanel extends MeasurePanel{
  73000. constructor(viewer, measurement, propertiesPanel){
  73001. super(viewer, measurement, propertiesPanel);
  73002. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  73003. this.elContent = $(`
  73004. <div class="measurement_content selectable">
  73005. <span class="coordinates_table_container"></span>
  73006. <br>
  73007. <span id="height_label">Height: </span><br>
  73008. <!-- ACTIONS -->
  73009. <div style="display: flex; margin-top: 12px">
  73010. <span></span>
  73011. <span style="flex-grow: 1"></span>
  73012. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  73013. </div>
  73014. </div>
  73015. `);
  73016. this.elRemove = this.elContent.find("img[name=remove]");
  73017. this.elRemove.click( () => {
  73018. this.viewer.scene.removeMeasurement(measurement);
  73019. });
  73020. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  73021. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  73022. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  73023. this.update();
  73024. }
  73025. update(){
  73026. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  73027. elCoordiantesContainer.empty();
  73028. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points.map(p => p.position)));
  73029. {
  73030. let points = this.measurement.points;
  73031. let sorted = points.slice().sort((a, b) => a.position.z - b.position.z);
  73032. let lowPoint = sorted[0].position.clone();
  73033. let highPoint = sorted[sorted.length - 1].position.clone();
  73034. let min = lowPoint.z;
  73035. let max = highPoint.z;
  73036. let height = max - min;
  73037. height = height.toFixed(3);
  73038. this.elHeightLabel = this.elContent.find(`#height_label`);
  73039. this.elHeightLabel.html(`<b>Height:</b> ${height}`);
  73040. }
  73041. }
  73042. };
  73043. class VolumePanel extends MeasurePanel{
  73044. constructor(viewer, measurement, propertiesPanel){
  73045. super(viewer, measurement, propertiesPanel);
  73046. let copyIconPath = Potree.resourcePath + '/icons/copy.svg';
  73047. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  73048. let lblLengthText = new Map([
  73049. [BoxVolume, "length"],
  73050. [SphereVolume$1, "rx"],
  73051. ]).get(measurement.constructor);
  73052. let lblWidthText = new Map([
  73053. [BoxVolume, "width"],
  73054. [SphereVolume$1, "ry"],
  73055. ]).get(measurement.constructor);
  73056. let lblHeightText = new Map([
  73057. [BoxVolume, "height"],
  73058. [SphereVolume$1, "rz"],
  73059. ]).get(measurement.constructor);
  73060. this.elContent = $(`
  73061. <div class="measurement_content selectable">
  73062. <span class="coordinates_table_container"></span>
  73063. <table class="measurement_value_table">
  73064. <tr>
  73065. <th>\u03b1</th>
  73066. <th>\u03b2</th>
  73067. <th>\u03b3</th>
  73068. <th></th>
  73069. </tr>
  73070. <tr>
  73071. <td align="center" id="angle_cell_alpha" style="width: 33%"></td>
  73072. <td align="center" id="angle_cell_betta" style="width: 33%"></td>
  73073. <td align="center" id="angle_cell_gamma" style="width: 33%"></td>
  73074. <td align="right" style="width: 25%">
  73075. <img name="copyRotation" title="copy" class="button-icon" src="${copyIconPath}" style="width: 16px; height: 16px"/>
  73076. </td>
  73077. </tr>
  73078. </table>
  73079. <table class="measurement_value_table">
  73080. <tr>
  73081. <th>${lblLengthText}</th>
  73082. <th>${lblWidthText}</th>
  73083. <th>${lblHeightText}</th>
  73084. <th></th>
  73085. </tr>
  73086. <tr>
  73087. <td align="center" id="cell_length" style="width: 33%"></td>
  73088. <td align="center" id="cell_width" style="width: 33%"></td>
  73089. <td align="center" id="cell_height" style="width: 33%"></td>
  73090. <td align="right" style="width: 25%">
  73091. <img name="copyScale" title="copy" class="button-icon" src="${copyIconPath}" style="width: 16px; height: 16px"/>
  73092. </td>
  73093. </tr>
  73094. </table>
  73095. <br>
  73096. <span style="font-weight: bold">Volume: </span>
  73097. <span id="measurement_volume"></span>
  73098. <!--
  73099. <li>
  73100. <label style="whitespace: nowrap">
  73101. <input id="volume_show" type="checkbox"/>
  73102. <span>show volume</span>
  73103. </label>
  73104. </li>-->
  73105. <li>
  73106. <label style="whitespace: nowrap">
  73107. <input id="volume_clip" type="checkbox"/>
  73108. <span>make clip volume</span>
  73109. </label>
  73110. </li>
  73111. <li style="margin-top: 10px">
  73112. <input name="download_volume" type="button" value="prepare download" style="width: 100%" />
  73113. <div name="download_message"></div>
  73114. </li>
  73115. <!-- ACTIONS -->
  73116. <li style="display: grid; grid-template-columns: auto auto; grid-column-gap: 5px; margin-top: 10px">
  73117. <input id="volume_reset_orientation" type="button" value="reset orientation"/>
  73118. <input id="volume_make_uniform" type="button" value="make uniform"/>
  73119. </li>
  73120. <div style="display: flex; margin-top: 12px">
  73121. <span></span>
  73122. <span style="flex-grow: 1"></span>
  73123. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  73124. </div>
  73125. </div>
  73126. `);
  73127. { // download
  73128. this.elDownloadButton = this.elContent.find("input[name=download_volume]");
  73129. if(this.propertiesPanel.viewer.server){
  73130. this.elDownloadButton.click(() => this.download());
  73131. } else {
  73132. this.elDownloadButton.hide();
  73133. }
  73134. }
  73135. this.elCopyRotation = this.elContent.find("img[name=copyRotation]");
  73136. this.elCopyRotation.click( () => {
  73137. let rotation = this.measurement.rotation.toArray().slice(0, 3);
  73138. let msg = rotation.map(c => c.toFixed(3)).join(", ");
  73139. Utils.clipboardCopy(msg);
  73140. this.viewer.postMessage(
  73141. `Copied value to clipboard: <br>'${msg}'`,
  73142. {duration: 3000});
  73143. });
  73144. this.elCopyScale = this.elContent.find("img[name=copyScale]");
  73145. this.elCopyScale.click( () => {
  73146. let scale = this.measurement.scale.toArray();
  73147. let msg = scale.map(c => c.toFixed(3)).join(", ");
  73148. Utils.clipboardCopy(msg);
  73149. this.viewer.postMessage(
  73150. `Copied value to clipboard: <br>'${msg}'`,
  73151. {duration: 3000});
  73152. });
  73153. this.elRemove = this.elContent.find("img[name=remove]");
  73154. this.elRemove.click( () => {
  73155. this.viewer.scene.removeVolume(measurement);
  73156. });
  73157. this.elContent.find("#volume_reset_orientation").click(() => {
  73158. measurement.rotation.set(0, 0, 0);
  73159. });
  73160. this.elContent.find("#volume_make_uniform").click(() => {
  73161. let mean = (measurement.scale.x + measurement.scale.y + measurement.scale.z) / 3;
  73162. measurement.scale.set(mean, mean, mean);
  73163. });
  73164. this.elCheckClip = this.elContent.find('#volume_clip');
  73165. this.elCheckClip.click(event => {
  73166. this.measurement.clip = event.target.checked;
  73167. });
  73168. this.elCheckShow = this.elContent.find('#volume_show');
  73169. this.elCheckShow.click(event => {
  73170. this.measurement.visible = event.target.checked;
  73171. });
  73172. this.propertiesPanel.addVolatileListener(measurement, "position_changed", this._update);
  73173. this.propertiesPanel.addVolatileListener(measurement, "orientation_changed", this._update);
  73174. this.propertiesPanel.addVolatileListener(measurement, "scale_changed", this._update);
  73175. this.propertiesPanel.addVolatileListener(measurement, "clip_changed", this._update);
  73176. this.update();
  73177. }
  73178. async download(){
  73179. let clipBox = this.measurement;
  73180. let regions = [];
  73181. //for(let clipBox of boxes){
  73182. {
  73183. let toClip = clipBox.matrixWorld;
  73184. let px = new Vector3(+0.5, 0, 0).applyMatrix4(toClip);
  73185. let nx = new Vector3(-0.5, 0, 0).applyMatrix4(toClip);
  73186. let py = new Vector3(0, +0.5, 0).applyMatrix4(toClip);
  73187. let ny = new Vector3(0, -0.5, 0).applyMatrix4(toClip);
  73188. let pz = new Vector3(0, 0, +0.5).applyMatrix4(toClip);
  73189. let nz = new Vector3(0, 0, -0.5).applyMatrix4(toClip);
  73190. let pxN = new Vector3().subVectors(nx, px).normalize();
  73191. let nxN = pxN.clone().multiplyScalar(-1);
  73192. let pyN = new Vector3().subVectors(ny, py).normalize();
  73193. let nyN = pyN.clone().multiplyScalar(-1);
  73194. let pzN = new Vector3().subVectors(nz, pz).normalize();
  73195. let nzN = pzN.clone().multiplyScalar(-1);
  73196. let planes = [
  73197. new Plane().setFromNormalAndCoplanarPoint(pxN, px),
  73198. new Plane().setFromNormalAndCoplanarPoint(nxN, nx),
  73199. new Plane().setFromNormalAndCoplanarPoint(pyN, py),
  73200. new Plane().setFromNormalAndCoplanarPoint(nyN, ny),
  73201. new Plane().setFromNormalAndCoplanarPoint(pzN, pz),
  73202. new Plane().setFromNormalAndCoplanarPoint(nzN, nz),
  73203. ];
  73204. let planeQueryParts = [];
  73205. for(let plane of planes){
  73206. let part = [plane.normal.toArray(), plane.constant].join(",");
  73207. part = `[${part}]`;
  73208. planeQueryParts.push(part);
  73209. }
  73210. let region = "[" + planeQueryParts.join(",") + "]";
  73211. regions.push(region);
  73212. }
  73213. let regionsArg = regions.join(",");
  73214. let pointcloudArgs = [];
  73215. for(let pointcloud of this.viewer.scene.pointclouds){
  73216. if(!pointcloud.visible){
  73217. continue;
  73218. }
  73219. let offset = pointcloud.pcoGeometry.offset.clone();
  73220. let negateOffset = new Matrix4().makeTranslation(...offset.multiplyScalar(-1).toArray());
  73221. let matrixWorld = pointcloud.matrixWorld;
  73222. let transform = new Matrix4().multiplyMatrices(matrixWorld, negateOffset);
  73223. let path = `${window.location.pathname}/../${pointcloud.pcoGeometry.url}`;
  73224. let arg = {
  73225. path: path,
  73226. transform: transform.elements,
  73227. };
  73228. let argString = JSON.stringify(arg);
  73229. pointcloudArgs.push(argString);
  73230. }
  73231. let pointcloudsArg = pointcloudArgs.join(",");
  73232. let elMessage = this.elContent.find("div[name=download_message]");
  73233. let error = (message) => {
  73234. elMessage.html(`<div style="color: #ff0000">ERROR: ${message}</div>`);
  73235. };
  73236. let info = (message) => {
  73237. elMessage.html(`${message}`);
  73238. };
  73239. let handle = null;
  73240. { // START FILTER
  73241. let url = `${viewer.server}/create_regions_filter?pointclouds=[${pointcloudsArg}]&regions=[${regionsArg}]`;
  73242. //console.log(url);
  73243. info("estimating results ...");
  73244. let response = await fetch(url);
  73245. let jsResponse = await response.json();
  73246. //console.log(jsResponse);
  73247. if(!jsResponse.handle){
  73248. error(jsResponse.message);
  73249. return;
  73250. }else {
  73251. handle = jsResponse.handle;
  73252. }
  73253. }
  73254. { // WAIT, CHECK PROGRESS, HANDLE FINISH
  73255. let url = `${viewer.server}/check_regions_filter?handle=${handle}`;
  73256. let sleep = (function(duration){
  73257. return new Promise( (res, rej) => {
  73258. setTimeout(() => {
  73259. res();
  73260. }, duration);
  73261. });
  73262. });
  73263. let handleFiltering = (jsResponse) => {
  73264. let {progress, estimate} = jsResponse;
  73265. let progressFract = progress["processed points"] / estimate.points;
  73266. let progressPercents = parseInt(progressFract * 100);
  73267. info(`progress: ${progressPercents}%`);
  73268. };
  73269. let handleFinish = (jsResponse) => {
  73270. let message = "downloads ready: <br>";
  73271. message += "<ul>";
  73272. for(let i = 0; i < jsResponse.pointclouds.length; i++){
  73273. let url = `${viewer.server}/download_regions_filter_result?handle=${handle}&index=${i}`;
  73274. message += `<li><a href="${url}">result_${i}.las</a> </li>\n`;
  73275. }
  73276. let reportURL = `${viewer.server}/download_regions_filter_report?handle=${handle}`;
  73277. message += `<li> <a href="${reportURL}">report.json</a> </li>\n`;
  73278. message += "</ul>";
  73279. info(message);
  73280. };
  73281. let handleUnexpected = (jsResponse) => {
  73282. let message = `Unexpected Response. <br>status: ${jsResponse.status} <br>message: ${jsResponse.message}`;
  73283. info(message);
  73284. };
  73285. let handleError = (jsResponse) => {
  73286. let message = `ERROR: ${jsResponse.message}`;
  73287. error(message);
  73288. throw new Error(message);
  73289. };
  73290. let start = Date.now();
  73291. while(true){
  73292. let response = await fetch(url);
  73293. let jsResponse = await response.json();
  73294. if(jsResponse.status === "ERROR"){
  73295. handleError(jsResponse);
  73296. }else if(jsResponse.status === "FILTERING"){
  73297. handleFiltering(jsResponse);
  73298. }else if(jsResponse.status === "FINISHED"){
  73299. handleFinish(jsResponse);
  73300. break;
  73301. }else {
  73302. handleUnexpected(jsResponse);
  73303. }
  73304. let durationS = (Date.now() - start) / 1000;
  73305. let sleepAmountMS = durationS < 10 ? 100 : 1000;
  73306. await sleep(sleepAmountMS);
  73307. }
  73308. }
  73309. }
  73310. update(){
  73311. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  73312. elCoordiantesContainer.empty();
  73313. elCoordiantesContainer.append(this.createCoordinatesTable([this.measurement.position]));
  73314. {
  73315. let angles = this.measurement.rotation.toVector3();
  73316. angles = angles.toArray();
  73317. //angles = [angles.z, angles.x, angles.y];
  73318. angles = angles.map(v => 180 * v / Math.PI);
  73319. angles = angles.map(a => a.toFixed(1) + '\u00B0');
  73320. let elAlpha = this.elContent.find(`#angle_cell_alpha`);
  73321. let elBetta = this.elContent.find(`#angle_cell_betta`);
  73322. let elGamma = this.elContent.find(`#angle_cell_gamma`);
  73323. elAlpha.html(angles[0]);
  73324. elBetta.html(angles[1]);
  73325. elGamma.html(angles[2]);
  73326. }
  73327. {
  73328. let dimensions = this.measurement.scale.toArray();
  73329. dimensions = dimensions.map(v => Utils.addCommas(v.toFixed(2)));
  73330. let elLength = this.elContent.find(`#cell_length`);
  73331. let elWidth = this.elContent.find(`#cell_width`);
  73332. let elHeight = this.elContent.find(`#cell_height`);
  73333. elLength.html(dimensions[0]);
  73334. elWidth.html(dimensions[1]);
  73335. elHeight.html(dimensions[2]);
  73336. }
  73337. {
  73338. let elVolume = this.elContent.find(`#measurement_volume`);
  73339. let volume = this.measurement.getVolume();
  73340. elVolume.html(Utils.addCommas(volume.toFixed(2)));
  73341. }
  73342. this.elCheckClip.prop("checked", this.measurement.clip);
  73343. this.elCheckShow.prop("checked", this.measurement.visible);
  73344. }
  73345. };
  73346. class ProfilePanel extends MeasurePanel{
  73347. constructor(viewer, measurement, propertiesPanel){
  73348. super(viewer, measurement, propertiesPanel);
  73349. let removeIconPath = Potree.resourcePath + '/icons/remove.svg';
  73350. this.elContent = $(`
  73351. <div class="measurement_content selectable">
  73352. <span class="coordinates_table_container"></span>
  73353. <br>
  73354. <span style="display:flex">
  73355. <span style="display:flex; align-items: center; padding-right: 10px">Width: </span>
  73356. <input id="sldProfileWidth" name="sldProfileWidth" value="5.06" style="flex-grow: 1; width:100%">
  73357. </span>
  73358. <br>
  73359. <li style="margin-top: 10px">
  73360. <input name="download_profile" type="button" value="prepare download" style="width: 100%" />
  73361. <div name="download_message"></div>
  73362. </li>
  73363. <br>
  73364. <input type="button" id="show_2d_profile" value="show 2d profile" style="width: 100%"/>
  73365. <!-- ACTIONS -->
  73366. <div style="display: flex; margin-top: 12px">
  73367. <span></span>
  73368. <span style="flex-grow: 1"></span>
  73369. <img name="remove" class="button-icon" src="${removeIconPath}" style="width: 16px; height: 16px"/>
  73370. </div>
  73371. </div>
  73372. `);
  73373. this.elRemove = this.elContent.find("img[name=remove]");
  73374. this.elRemove.click( () => {
  73375. this.viewer.scene.removeProfile(measurement);
  73376. });
  73377. { // download
  73378. this.elDownloadButton = this.elContent.find(`input[name=download_profile]`);
  73379. if(this.propertiesPanel.viewer.server){
  73380. this.elDownloadButton.click(() => this.download());
  73381. } else {
  73382. this.elDownloadButton.hide();
  73383. }
  73384. }
  73385. { // width spinner
  73386. let elWidthSlider = this.elContent.find(`#sldProfileWidth`);
  73387. elWidthSlider.spinner({
  73388. min: 0, max: 10 * 1000 * 1000, step: 0.01,
  73389. numberFormat: 'n',
  73390. start: () => {},
  73391. spin: (event, ui) => {
  73392. let value = elWidthSlider.spinner('value');
  73393. measurement.setWidth(value);
  73394. },
  73395. change: (event, ui) => {
  73396. let value = elWidthSlider.spinner('value');
  73397. measurement.setWidth(value);
  73398. },
  73399. stop: (event, ui) => {
  73400. let value = elWidthSlider.spinner('value');
  73401. measurement.setWidth(value);
  73402. },
  73403. incremental: (count) => {
  73404. let value = elWidthSlider.spinner('value');
  73405. let step = elWidthSlider.spinner('option', 'step');
  73406. let delta = value * 0.05;
  73407. let increments = Math.max(1, parseInt(delta / step));
  73408. return increments;
  73409. }
  73410. });
  73411. elWidthSlider.spinner('value', measurement.getWidth());
  73412. elWidthSlider.spinner('widget').css('width', '100%');
  73413. let widthListener = (event) => {
  73414. let value = elWidthSlider.spinner('value');
  73415. if (value !== measurement.getWidth()) {
  73416. elWidthSlider.spinner('value', measurement.getWidth());
  73417. }
  73418. };
  73419. this.propertiesPanel.addVolatileListener(measurement, "width_changed", widthListener);
  73420. }
  73421. let elShow2DProfile = this.elContent.find(`#show_2d_profile`);
  73422. elShow2DProfile.click(() => {
  73423. this.propertiesPanel.viewer.profileWindow.show();
  73424. this.propertiesPanel.viewer.profileWindowController.setProfile(measurement);
  73425. });
  73426. this.propertiesPanel.addVolatileListener(measurement, "marker_added", this._update);
  73427. this.propertiesPanel.addVolatileListener(measurement, "marker_removed", this._update);
  73428. this.propertiesPanel.addVolatileListener(measurement, "marker_moved", this._update);
  73429. this.update();
  73430. }
  73431. update(){
  73432. let elCoordiantesContainer = this.elContent.find('.coordinates_table_container');
  73433. elCoordiantesContainer.empty();
  73434. elCoordiantesContainer.append(this.createCoordinatesTable(this.measurement.points));
  73435. }
  73436. async download(){
  73437. let profile = this.measurement;
  73438. let regions = [];
  73439. {
  73440. let segments = profile.getSegments();
  73441. let width = profile.width;
  73442. for(let segment of segments){
  73443. let start = segment.start.clone().multiply(new Vector3(1, 1, 0));
  73444. let end = segment.end.clone().multiply(new Vector3(1, 1, 0));
  73445. let center = new Vector3().addVectors(start, end).multiplyScalar(0.5);
  73446. let startEndDir = new Vector3().subVectors(end, start).normalize();
  73447. let endStartDir = new Vector3().subVectors(start, end).normalize();
  73448. let upDir = new Vector3(0, 0, 1);
  73449. let rightDir = new Vector3().crossVectors(startEndDir, upDir);
  73450. let leftDir = new Vector3().crossVectors(endStartDir, upDir);
  73451. console.log(leftDir);
  73452. let right = rightDir.clone().multiplyScalar(width * 0.5).add(center);
  73453. let left = leftDir.clone().multiplyScalar(width * 0.5).add(center);
  73454. let planes = [
  73455. new Plane().setFromNormalAndCoplanarPoint(startEndDir, start),
  73456. new Plane().setFromNormalAndCoplanarPoint(endStartDir, end),
  73457. new Plane().setFromNormalAndCoplanarPoint(leftDir, right),
  73458. new Plane().setFromNormalAndCoplanarPoint(rightDir, left),
  73459. ];
  73460. let planeQueryParts = [];
  73461. for(let plane of planes){
  73462. let part = [plane.normal.toArray(), plane.constant].join(",");
  73463. part = `[${part}]`;
  73464. planeQueryParts.push(part);
  73465. }
  73466. let region = "[" + planeQueryParts.join(",") + "]";
  73467. regions.push(region);
  73468. }
  73469. }
  73470. let regionsArg = regions.join(",");
  73471. let pointcloudArgs = [];
  73472. for(let pointcloud of this.viewer.scene.pointclouds){
  73473. if(!pointcloud.visible){
  73474. continue;
  73475. }
  73476. let offset = pointcloud.pcoGeometry.offset.clone();
  73477. let negateOffset = new Matrix4().makeTranslation(...offset.multiplyScalar(-1).toArray());
  73478. let matrixWorld = pointcloud.matrixWorld;
  73479. let transform = new Matrix4().multiplyMatrices(matrixWorld, negateOffset);
  73480. let path = `${window.location.pathname}/../${pointcloud.pcoGeometry.url}`;
  73481. let arg = {
  73482. path: path,
  73483. transform: transform.elements,
  73484. };
  73485. let argString = JSON.stringify(arg);
  73486. pointcloudArgs.push(argString);
  73487. }
  73488. let pointcloudsArg = pointcloudArgs.join(",");
  73489. let elMessage = this.elContent.find("div[name=download_message]");
  73490. let error = (message) => {
  73491. elMessage.html(`<div style="color: #ff0000">ERROR: ${message}</div>`);
  73492. };
  73493. let info = (message) => {
  73494. elMessage.html(`${message}`);
  73495. };
  73496. let handle = null;
  73497. { // START FILTER
  73498. let url = `${viewer.server}/create_regions_filter?pointclouds=[${pointcloudsArg}]&regions=[${regionsArg}]`;
  73499. //console.log(url);
  73500. info("estimating results ...");
  73501. let response = await fetch(url);
  73502. let jsResponse = await response.json();
  73503. //console.log(jsResponse);
  73504. if(!jsResponse.handle){
  73505. error(jsResponse.message);
  73506. return;
  73507. }else {
  73508. handle = jsResponse.handle;
  73509. }
  73510. }
  73511. { // WAIT, CHECK PROGRESS, HANDLE FINISH
  73512. let url = `${viewer.server}/check_regions_filter?handle=${handle}`;
  73513. let sleep = (function(duration){
  73514. return new Promise( (res, rej) => {
  73515. setTimeout(() => {
  73516. res();
  73517. }, duration);
  73518. });
  73519. });
  73520. let handleFiltering = (jsResponse) => {
  73521. let {progress, estimate} = jsResponse;
  73522. let progressFract = progress["processed points"] / estimate.points;
  73523. let progressPercents = parseInt(progressFract * 100);
  73524. info(`progress: ${progressPercents}%`);
  73525. };
  73526. let handleFinish = (jsResponse) => {
  73527. let message = "downloads ready: <br>";
  73528. message += "<ul>";
  73529. for(let i = 0; i < jsResponse.pointclouds.length; i++){
  73530. let url = `${viewer.server}/download_regions_filter_result?handle=${handle}&index=${i}`;
  73531. message += `<li><a href="${url}">result_${i}.las</a> </li>\n`;
  73532. }
  73533. let reportURL = `${viewer.server}/download_regions_filter_report?handle=${handle}`;
  73534. message += `<li> <a href="${reportURL}">report.json</a> </li>\n`;
  73535. message += "</ul>";
  73536. info(message);
  73537. };
  73538. let handleUnexpected = (jsResponse) => {
  73539. let message = `Unexpected Response. <br>status: ${jsResponse.status} <br>message: ${jsResponse.message}`;
  73540. info(message);
  73541. };
  73542. let handleError = (jsResponse) => {
  73543. let message = `ERROR: ${jsResponse.message}`;
  73544. error(message);
  73545. throw new Error(message);
  73546. };
  73547. let start = Date.now();
  73548. while(true){
  73549. let response = await fetch(url);
  73550. let jsResponse = await response.json();
  73551. if(jsResponse.status === "ERROR"){
  73552. handleError(jsResponse);
  73553. }else if(jsResponse.status === "FILTERING"){
  73554. handleFiltering(jsResponse);
  73555. }else if(jsResponse.status === "FINISHED"){
  73556. handleFinish(jsResponse);
  73557. break;
  73558. }else {
  73559. handleUnexpected(jsResponse);
  73560. }
  73561. let durationS = (Date.now() - start) / 1000;
  73562. let sleepAmountMS = durationS < 10 ? 100 : 1000;
  73563. await sleep(sleepAmountMS);
  73564. }
  73565. }
  73566. }
  73567. };
  73568. class CameraPanel{
  73569. constructor(viewer, propertiesPanel){
  73570. this.viewer = viewer;
  73571. this.propertiesPanel = propertiesPanel;
  73572. this._update = () => { this.update(); };
  73573. let copyIconPath = Potree.resourcePath + '/icons/copy.svg';
  73574. this.elContent = $(`
  73575. <div class="propertypanel_content">
  73576. <table>
  73577. <tr>
  73578. <th colspan="3">position</th>
  73579. <th></th>
  73580. </tr>
  73581. <tr>
  73582. <td align="center" id="camera_position_x" style="width: 25%"></td>
  73583. <td align="center" id="camera_position_y" style="width: 25%"></td>
  73584. <td align="center" id="camera_position_z" style="width: 25%"></td>
  73585. <td align="right" id="copy_camera_position" style="width: 25%">
  73586. <img name="copyPosition" title="copy" class="button-icon" src="${copyIconPath}" style="width: 16px; height: 16px"/>
  73587. </td>
  73588. </tr>
  73589. <tr>
  73590. <th colspan="3">target</th>
  73591. <th></th>
  73592. </tr>
  73593. <tr>
  73594. <td align="center" id="camera_target_x" style="width: 25%"></td>
  73595. <td align="center" id="camera_target_y" style="width: 25%"></td>
  73596. <td align="center" id="camera_target_z" style="width: 25%"></td>
  73597. <td align="right" id="copy_camera_target" style="width: 25%">
  73598. <img name="copyTarget" title="copy" class="button-icon" src="${copyIconPath}" style="width: 16px; height: 16px"/>
  73599. </td>
  73600. </tr>
  73601. </table>
  73602. </div>
  73603. `);
  73604. this.elCopyPosition = this.elContent.find("img[name=copyPosition]");
  73605. this.elCopyPosition.click( () => {
  73606. let pos = this.viewer.scene.getActiveCamera().position.toArray();
  73607. let msg = pos.map(c => c.toFixed(3)).join(", ");
  73608. Utils.clipboardCopy(msg);
  73609. this.viewer.postMessage(
  73610. `Copied value to clipboard: <br>'${msg}'`,
  73611. {duration: 3000});
  73612. });
  73613. this.elCopyTarget = this.elContent.find("img[name=copyTarget]");
  73614. this.elCopyTarget.click( () => {
  73615. let pos = this.viewer.scene.view.getPivot().toArray();
  73616. let msg = pos.map(c => c.toFixed(3)).join(", ");
  73617. Utils.clipboardCopy(msg);
  73618. this.viewer.postMessage(
  73619. `Copied value to clipboard: <br>'${msg}'`,
  73620. {duration: 3000});
  73621. });
  73622. this.propertiesPanel.addVolatileListener(viewer, "camera_changed", this._update);
  73623. this.update();
  73624. }
  73625. update(){
  73626. //console.log("updating camera panel");
  73627. let camera = this.viewer.scene.getActiveCamera();
  73628. let view = this.viewer.scene.view;
  73629. let pos = camera.position.toArray().map(c => Utils.addCommas(c.toFixed(3)));
  73630. this.elContent.find("#camera_position_x").html(pos[0]);
  73631. this.elContent.find("#camera_position_y").html(pos[1]);
  73632. this.elContent.find("#camera_position_z").html(pos[2]);
  73633. let target = view.getPivot().toArray().map(c => Utils.addCommas(c.toFixed(3)));
  73634. this.elContent.find("#camera_target_x").html(target[0]);
  73635. this.elContent.find("#camera_target_y").html(target[1]);
  73636. this.elContent.find("#camera_target_z").html(target[2]);
  73637. }
  73638. };
  73639. class AnnotationPanel{
  73640. constructor(viewer, propertiesPanel, annotation){
  73641. this.viewer = viewer;
  73642. this.propertiesPanel = propertiesPanel;
  73643. this.annotation = annotation;
  73644. this._update = () => { this.update(); };
  73645. let copyIconPath = `${Potree.resourcePath}/icons/copy.svg`;
  73646. this.elContent = $(`
  73647. <div class="propertypanel_content">
  73648. <table>
  73649. <tr>
  73650. <th colspan="3">position</th>
  73651. <th></th>
  73652. </tr>
  73653. <tr>
  73654. <td align="center" id="annotation_position_x" style="width: 25%"></td>
  73655. <td align="center" id="annotation_position_y" style="width: 25%"></td>
  73656. <td align="center" id="annotation_position_z" style="width: 25%"></td>
  73657. <td align="right" id="copy_annotation_position" style="width: 25%">
  73658. <img name="copyPosition" title="copy" class="button-icon" src="${copyIconPath}" style="width: 16px; height: 16px"/>
  73659. </td>
  73660. </tr>
  73661. </table>
  73662. <div>
  73663. <div class="heading">Title</div>
  73664. <div id="annotation_title" contenteditable="true">
  73665. Annotation Title
  73666. </div>
  73667. <div class="heading">Description</div>
  73668. <div id="annotation_description" contenteditable="true">
  73669. A longer description of this annotation.
  73670. Can be multiple lines long. TODO: the user should be able
  73671. to modify title and description.
  73672. </div>
  73673. </div>
  73674. </div>
  73675. `);
  73676. this.elCopyPosition = this.elContent.find("img[name=copyPosition]");
  73677. this.elCopyPosition.click( () => {
  73678. let pos = this.annotation.position.toArray();
  73679. let msg = pos.map(c => c.toFixed(3)).join(", ");
  73680. Utils.clipboardCopy(msg);
  73681. this.viewer.postMessage(
  73682. `Copied value to clipboard: <br>'${msg}'`,
  73683. {duration: 3000});
  73684. });
  73685. this.elTitle = this.elContent.find("#annotation_title").html(annotation.title);
  73686. this.elDescription = this.elContent.find("#annotation_description").html(annotation.description);
  73687. this.elTitle[0].addEventListener("input", () => {
  73688. const title = this.elTitle.html();
  73689. annotation.title = title;
  73690. }, false);
  73691. this.elDescription[0].addEventListener("input", () => {
  73692. const description = this.elDescription.html();
  73693. annotation.description = description;
  73694. }, false);
  73695. this.update();
  73696. }
  73697. update(){
  73698. const {annotation, elContent, elTitle, elDescription} = this;
  73699. let pos = annotation.position.toArray().map(c => Utils.addCommas(c.toFixed(3)));
  73700. elContent.find("#annotation_position_x").html(pos[0]);
  73701. elContent.find("#annotation_position_y").html(pos[1]);
  73702. elContent.find("#annotation_position_z").html(pos[2]);
  73703. elTitle.html(annotation.title);
  73704. elDescription.html(annotation.description);
  73705. }
  73706. };
  73707. class CameraAnimationPanel{
  73708. constructor(viewer, propertiesPanel, animation){
  73709. this.viewer = viewer;
  73710. this.propertiesPanel = propertiesPanel;
  73711. this.animation = animation;
  73712. this.elContent = $(`
  73713. <div class="propertypanel_content">
  73714. <span id="animation_keyframes"></span>
  73715. <span>
  73716. <span style="display:flex">
  73717. <span style="display:flex; align-items: center; padding-right: 10px">Duration: </span>
  73718. <input name="spnDuration" value="5.0" style="flex-grow: 1; width:100%">
  73719. </span>
  73720. <span>Time: </span><span id="lblTime"></span> <div id="sldTime"></div>
  73721. <input name="play" type="button" value="play"/>
  73722. <input name="pause" type="button" value="pause"/>
  73723. </span>
  73724. </div>
  73725. `);
  73726. const elPlay = this.elContent.find("input[name=play]");
  73727. elPlay.click( () => {
  73728. animation.play();
  73729. });
  73730. const elPause = this.elContent.find("input[name=pause]");
  73731. elPause.click( () => {
  73732. animation.pause();
  73733. });
  73734. const elSlider = this.elContent.find('#sldTime');
  73735. elSlider.slider({
  73736. value: 0,
  73737. min: 0,
  73738. max: 1,
  73739. step: 0.001,
  73740. slide: (event, ui) => {
  73741. animation.set(ui.value);
  73742. animation.updateFrustum();
  73743. }
  73744. });
  73745. let elDuration = this.elContent.find(`input[name=spnDuration]`);
  73746. elDuration.spinner({
  73747. min: 0, max: 300, step: 0.01,
  73748. numberFormat: 'n',
  73749. start: () => {},
  73750. spin: (event, ui) => {
  73751. let value = elDuration.spinner('value');
  73752. animation.setDuration(value);
  73753. },
  73754. change: (event, ui) => {
  73755. let value = elDuration.spinner('value');
  73756. animation.setDuration(value);
  73757. },
  73758. stop: (event, ui) => {
  73759. let value = elDuration.spinner('value');
  73760. animation.setDuration(value);
  73761. },
  73762. incremental: (count) => {
  73763. let value = elDuration.spinner('value');
  73764. let step = elDuration.spinner('option', 'step');
  73765. let delta = value * 0.05;
  73766. let increments = Math.max(1, parseInt(delta / step));
  73767. return increments;
  73768. }
  73769. });
  73770. elDuration.spinner('value', animation.getDuration());
  73771. elDuration.spinner('widget').css('width', '100%');
  73772. const elKeyframes = this.elContent.find("#animation_keyframes");
  73773. const updateKeyframes = () => {
  73774. elKeyframes.empty();
  73775. //let index = 0;
  73776. // <span style="flex-grow: 0;">
  73777. // <img name="add" src="${Potree.resourcePath}/icons/add.svg" style="width: 1.5em; height: 1.5em"/>
  73778. // </span>
  73779. const addNewKeyframeItem = (index) => {
  73780. let elNewKeyframe = $(`
  73781. <div style="display: flex; margin: 0.2em 0em">
  73782. <span style="flex-grow: 1"></span>
  73783. <input type="button" name="add" value="insert control point" />
  73784. <span style="flex-grow: 1"></span>
  73785. </div>
  73786. `);
  73787. const elAdd = elNewKeyframe.find("input[name=add]");
  73788. elAdd.click( () => {
  73789. animation.createControlPoint(index,
  73790. { position: viewer.scene.view.position,
  73791. target: viewer.scene.view.getPivot()
  73792. });
  73793. animation.changeCallback();
  73794. });
  73795. elKeyframes.append(elNewKeyframe);
  73796. };
  73797. const addKeyframeItem = (index) => {
  73798. let elKeyframe = $(`
  73799. <div style="display: flex; margin: 0.2em 0em">
  73800. <span style="flex-grow: 0;">
  73801. <img name="assign" src="${Potree.resourcePath}/icons/assign.svg" style="width: 1.5em; height: 1.5em"/>
  73802. </span>
  73803. <span style="flex-grow: 0;">
  73804. <img name="move" src="${Potree.resourcePath}/icons/circled_dot.svg" style="width: 1.5em; height: 1.5em"/>
  73805. </span>
  73806. <span style="flex-grow: 0; width: 1.5em; height: 1.5em"></span>
  73807. <span style="flex-grow: 0; font-size: 1.5em">keyframe</span>
  73808. <span style="flex-grow: 1"></span>
  73809. <span style="flex-grow: 0;">
  73810. <img name="delete" src="${Potree.resourcePath}/icons/remove.svg" style="width: 1.5em; height: 1.5em"/>
  73811. </span>
  73812. </div>
  73813. `);
  73814. const elAssign = elKeyframe.find("img[name=assign]");
  73815. const elMove = elKeyframe.find("img[name=move]");
  73816. const elDelete = elKeyframe.find("img[name=delete]");
  73817. elAssign.click( () => { //修改
  73818. animation.posCurve.points[index].copy(viewer.scene.view.position);
  73819. animation.targets[index].position.copy(viewer.scene.view.getPivot());
  73820. animation.changeCallback(index);
  73821. });
  73822. elMove.click( () => {
  73823. viewer.scene.view.position.copy(animation.posCurve.points[index]);
  73824. viewer.scene.view.lookAt(animation.targets[index].position);
  73825. });
  73826. elDelete.click( () => {
  73827. animation.removeControlPoint(index);
  73828. animation.changeCallback();
  73829. });
  73830. elKeyframes.append(elKeyframe);
  73831. };
  73832. let index = 0;
  73833. addNewKeyframeItem(index);
  73834. animation.posCurve.points.forEach(e=>{
  73835. addKeyframeItem(index);
  73836. index++;
  73837. addNewKeyframeItem(index);
  73838. });
  73839. };
  73840. updateKeyframes();
  73841. animation.addEventListener("controlpoint_added", updateKeyframes);
  73842. animation.addEventListener("controlpoint_removed", updateKeyframes);
  73843. // this._update = () => { this.update(); };
  73844. // this.update();
  73845. }
  73846. update(){
  73847. }
  73848. };
  73849. class PropertiesPanel{
  73850. constructor(container, viewer){
  73851. this.container = container;
  73852. this.viewer = viewer;
  73853. this.object = null;
  73854. this.cleanupTasks = [];
  73855. this.scene = null;
  73856. }
  73857. setScene(scene){
  73858. this.scene = scene;
  73859. }
  73860. set(object){
  73861. if(this.object === object){
  73862. return;
  73863. }
  73864. this.object = object;
  73865. for(let task of this.cleanupTasks){
  73866. task();
  73867. }
  73868. this.cleanupTasks = [];
  73869. this.container.empty();
  73870. if(object instanceof PointCloudTree){
  73871. this.setPointCloud(object);
  73872. }else if(object instanceof Measure || object instanceof Profile || object instanceof Volume){
  73873. this.setMeasurement(object);
  73874. }else if(object instanceof Camera){
  73875. this.setCamera(object);
  73876. }else if(object instanceof Annotation){
  73877. this.setAnnotation(object);
  73878. }else if(object instanceof CameraAnimation$1){//改
  73879. this.setCameraAnimation(object);
  73880. }
  73881. }
  73882. //
  73883. // Used for events that should be removed when the property object changes.
  73884. // This is for listening to materials, scene, point clouds, etc.
  73885. // not required for DOM listeners, since they are automatically cleared by removing the DOM subtree.
  73886. //
  73887. addVolatileListener(target, type, callback){
  73888. target.addEventListener(type, callback);
  73889. this.cleanupTasks.push(() => {
  73890. target.removeEventListener(type, callback);
  73891. });
  73892. }
  73893. setPointCloud(pointcloud){
  73894. let material = pointcloud.material;
  73895. let panel = $(`
  73896. <div class="scene_content selectable">
  73897. <ul class="pv-menu-list">
  73898. <li>
  73899. <span data-i18n="appearance.point_size"></span>:&nbsp;<span id="lblPointSize"></span> <div id="sldPointSize"></div>
  73900. </li>
  73901. <li>
  73902. <span data-i18n="appearance.min_point_size"></span>:&nbsp;<span id="lblMinPointSize"></span> <div id="sldMinPointSize"></div>
  73903. </li>
  73904. <!-- SIZE TYPE -->
  73905. <li>
  73906. <label for="optPointSizing" class="pv-select-label" data-i18n="appearance.point_size_type">Point Sizing </label>
  73907. <select id="optPointSizing" name="optPointSizing">
  73908. <option>FIXED</option>
  73909. <option>ATTENUATED</option>
  73910. <option>ADAPTIVE</option>
  73911. </select>
  73912. </li>
  73913. <!-- SHAPE -->
  73914. <li>
  73915. <label for="optShape" class="pv-select-label" data-i18n="appearance.point_shape"></label><br>
  73916. <select id="optShape" name="optShape">
  73917. <option>SQUARE</option>
  73918. <option>CIRCLE</option>
  73919. <option>PARABOLOID</option>
  73920. </select>
  73921. </li>
  73922. <li id="materials_backface_container">
  73923. <label><input id="set_backface_culling" type="checkbox" /><span data-i18n="appearance.backface_culling"></span></label>
  73924. </li>
  73925. <!-- OPACITY -->
  73926. <li><span data-i18n="appearance.point_opacity"></span>:<span id="lblOpacity"></span><div id="sldOpacity"></div></li>
  73927. <div class="divider">
  73928. <span>Attribute</span>
  73929. </div>
  73930. <li>
  73931. <select id="optMaterial" name="optMaterial"></select>
  73932. </li>
  73933. <div id="materials.composite_weight_container">
  73934. <div class="divider">
  73935. <span>Attribute Weights</span>
  73936. </div>
  73937. <li>RGB: <span id="lblWeightRGB"></span> <div id="sldWeightRGB"></div> </li>
  73938. <li>Intensity: <span id="lblWeightIntensity"></span> <div id="sldWeightIntensity"></div> </li>
  73939. <li>Elevation: <span id="lblWeightElevation"></span> <div id="sldWeightElevation"></div> </li>
  73940. <li>Classification: <span id="lblWeightClassification"></span> <div id="sldWeightClassification"></div> </li>
  73941. <li>Return Number: <span id="lblWeightReturnNumber"></span> <div id="sldWeightReturnNumber"></div> </li>
  73942. <li>Source ID: <span id="lblWeightSourceID"></span> <div id="sldWeightSourceID"></div> </li>
  73943. </div>
  73944. <div id="materials.rgb_container">
  73945. <div class="divider">
  73946. <span>RGB</span>
  73947. </div>
  73948. <li>Gamma: <span id="lblRGBGamma"></span> <div id="sldRGBGamma"></div> </li>
  73949. <li>Brightness: <span id="lblRGBBrightness"></span> <div id="sldRGBBrightness"></div> </li>
  73950. <li>Contrast: <span id="lblRGBContrast"></span> <div id="sldRGBContrast"></div> </li>
  73951. </div>
  73952. <div id="materials.extra_container">
  73953. <div class="divider">
  73954. <span>Extra Attribute</span>
  73955. </div>
  73956. <li><span data-i18n="appearance.extra_range"></span>: <span id="lblExtraRange"></span> <div id="sldExtraRange"></div></li>
  73957. <li>Gamma: <span id="lblExtraGamma"></span> <div id="sldExtraGamma"></div></li>
  73958. <li>Brightness: <span id="lblExtraBrightness"></span> <div id="sldExtraBrightness"></div></li>
  73959. <li>Contrast: <span id="lblExtraContrast"></span> <div id="sldExtraContrast"></div></li>
  73960. </div>
  73961. <div id="materials.matcap_container">
  73962. <div class="divider">
  73963. <span>MATCAP</span>
  73964. </div>
  73965. <li>
  73966. <div id="matcap_scheme_selection" style="display: flex; flex-wrap: wrap;"> </div>
  73967. </li>
  73968. </div>
  73969. <div id="materials.color_container">
  73970. <div class="divider">
  73971. <span>Color</span>
  73972. </div>
  73973. <input id="materials.color.picker" />
  73974. </div>
  73975. <div id="materials.elevation_container">
  73976. <div class="divider">
  73977. <span>Elevation</span>
  73978. </div>
  73979. <li><span data-i18n="appearance.elevation_range"></span>: <span id="lblHeightRange"></span> <div id="sldHeightRange"></div> </li>
  73980. <li>
  73981. <selectgroup id="gradient_repeat_option">
  73982. <option id="gradient_repeat_clamp" value="CLAMP">Clamp</option>
  73983. <option id="gradient_repeat_repeat" value="REPEAT">Repeat</option>
  73984. <option id="gradient_repeat_mirrored_repeat" value="MIRRORED_REPEAT">Mirrored Repeat</option>
  73985. </selectgroup>
  73986. </li>
  73987. <li>
  73988. <span>Gradient Scheme:</span>
  73989. <div id="elevation_gradient_scheme_selection" style="display: flex; padding: 1em 0em">
  73990. </div>
  73991. </li>
  73992. </div>
  73993. <div id="materials.transition_container">
  73994. <div class="divider">
  73995. <span>Transition</span>
  73996. </div>
  73997. <li>transition: <span id="lblTransition"></span> <div id="sldTransition"></div> </li>
  73998. </div>
  73999. <div id="materials.intensity_container">
  74000. <div class="divider">
  74001. <span>Intensity</span>
  74002. </div>
  74003. <li>Range: <span id="lblIntensityRange"></span> <div id="sldIntensityRange"></div> </li>
  74004. <li>Gamma: <span id="lblIntensityGamma"></span> <div id="sldIntensityGamma"></div> </li>
  74005. <li>Brightness: <span id="lblIntensityBrightness"></span> <div id="sldIntensityBrightness"></div> </li>
  74006. <li>Contrast: <span id="lblIntensityContrast"></span> <div id="sldIntensityContrast"></div> </li>
  74007. </div>
  74008. <div id="materials.gpstime_container">
  74009. <div class="divider">
  74010. <span>GPS Time</span>
  74011. </div>
  74012. </div>
  74013. <div id="materials.index_container">
  74014. <div class="divider">
  74015. <span>Indices</span>
  74016. </div>
  74017. </div>
  74018. </ul>
  74019. </div>
  74020. `);
  74021. panel.i18n();
  74022. this.container.append(panel);
  74023. { // POINT SIZE
  74024. let sldPointSize = panel.find(`#sldPointSize`);
  74025. let lblPointSize = panel.find(`#lblPointSize`);
  74026. sldPointSize.slider({
  74027. value: material.size,
  74028. min: 0,
  74029. max: 3,
  74030. step: 0.01,
  74031. slide: function (event, ui) { material.size = ui.value; }
  74032. });
  74033. let update = (e) => {
  74034. lblPointSize.html(material.size.toFixed(2));
  74035. sldPointSize.slider({value: material.size});
  74036. };
  74037. this.addVolatileListener(material, "point_size_changed", update);
  74038. update();
  74039. }
  74040. { // MINIMUM POINT SIZE
  74041. let sldMinPointSize = panel.find(`#sldMinPointSize`);
  74042. let lblMinPointSize = panel.find(`#lblMinPointSize`);
  74043. sldMinPointSize.slider({
  74044. value: material.size,
  74045. min: 0,
  74046. max: 3,
  74047. step: 0.01,
  74048. slide: function (event, ui) { material.minSize = ui.value; }
  74049. });
  74050. let update = (e) => {
  74051. lblMinPointSize.html(material.minSize.toFixed(2));
  74052. sldMinPointSize.slider({value: material.minSize});
  74053. };
  74054. this.addVolatileListener(material, "point_size_changed", update);
  74055. update();
  74056. }
  74057. { // POINT SIZING
  74058. let strSizeType = Object.keys(PointSizeType)[material.pointSizeType];
  74059. let opt = panel.find(`#optPointSizing`);
  74060. opt.selectmenu();
  74061. opt.val(strSizeType).selectmenu('refresh');
  74062. opt.selectmenu({
  74063. change: (event, ui) => {
  74064. material.pointSizeType = PointSizeType[ui.item.value];
  74065. }
  74066. });
  74067. }
  74068. { // SHAPE
  74069. let opt = panel.find(`#optShape`);
  74070. opt.selectmenu({
  74071. change: (event, ui) => {
  74072. let value = ui.item.value;
  74073. material.shape = PointShape$1[value];
  74074. }
  74075. });
  74076. let update = () => {
  74077. let typename = Object.keys(PointShape$1)[material.shape];
  74078. opt.selectmenu().val(typename).selectmenu('refresh');
  74079. };
  74080. this.addVolatileListener(material, "point_shape_changed", update);
  74081. update();
  74082. }
  74083. { // BACKFACE CULLING
  74084. let opt = panel.find(`#set_backface_culling`);
  74085. opt.click(() => {
  74086. material.backfaceCulling = opt.prop("checked");
  74087. });
  74088. let update = () => {
  74089. let value = material.backfaceCulling;
  74090. opt.prop("checked", value);
  74091. };
  74092. this.addVolatileListener(material, "backface_changed", update);
  74093. update();
  74094. let blockBackface = $('#materials_backface_container');
  74095. blockBackface.css('display', 'none');
  74096. const pointAttributes = pointcloud.pcoGeometry.pointAttributes;
  74097. const hasNormals = pointAttributes.hasNormals ? pointAttributes.hasNormals() : false;
  74098. if(hasNormals) {
  74099. blockBackface.css('display', 'block');
  74100. }
  74101. /*
  74102. opt.checkboxradio({
  74103. clicked: (event, ui) => {
  74104. // let value = ui.item.value;
  74105. let value = ui.item.checked;
  74106. console.log(value);
  74107. material.backfaceCulling = value; // $('#set_freeze').prop("checked");
  74108. }
  74109. });
  74110. */
  74111. }
  74112. { // OPACITY
  74113. let sldOpacity = panel.find(`#sldOpacity`);
  74114. let lblOpacity = panel.find(`#lblOpacity`);
  74115. sldOpacity.slider({
  74116. value: material.opacity,
  74117. min: 0,
  74118. max: 1,
  74119. step: 0.001,
  74120. slide: function (event, ui) {
  74121. material.opacity = ui.value;
  74122. }
  74123. });
  74124. let update = (e) => {
  74125. lblOpacity.html(material.opacity.toFixed(2));
  74126. sldOpacity.slider({value: material.opacity});
  74127. };
  74128. this.addVolatileListener(material, "opacity_changed", update);
  74129. update();
  74130. }
  74131. {
  74132. const attributes = pointcloud.pcoGeometry.pointAttributes.attributes;
  74133. let options = [];
  74134. options.push(...attributes.map(a => a.name));
  74135. const intensityIndex = options.indexOf("intensity");
  74136. if(intensityIndex >= 0){
  74137. options.splice(intensityIndex + 1, 0, "intensity gradient");
  74138. }
  74139. options.push(
  74140. "elevation",
  74141. "color",
  74142. 'matcap',
  74143. 'indices',
  74144. 'level of detail',
  74145. 'composite'
  74146. );
  74147. const blacklist = [
  74148. "POSITION_CARTESIAN",
  74149. "position",
  74150. ];
  74151. options = options.filter(o => !blacklist.includes(o));
  74152. let attributeSelection = panel.find('#optMaterial');
  74153. for(let option of options){
  74154. let elOption = $(`<option>${option}</option>`);
  74155. attributeSelection.append(elOption);
  74156. }
  74157. let updateMaterialPanel = (event, ui) => {
  74158. let selectedValue = attributeSelection.selectmenu().val();
  74159. material.activeAttributeName = selectedValue;
  74160. let attribute = pointcloud.getAttribute(selectedValue);
  74161. if(selectedValue === "intensity gradient"){
  74162. attribute = pointcloud.getAttribute("intensity");
  74163. }
  74164. const isIntensity = attribute ? ["intensity", "intensity gradient"].includes(attribute.name) : false;
  74165. if(isIntensity){
  74166. if(pointcloud.material.intensityRange[0] === Infinity){
  74167. pointcloud.material.intensityRange = attribute.range;
  74168. }
  74169. const [min, max] = attribute.range;
  74170. panel.find('#sldIntensityRange').slider({
  74171. range: true,
  74172. min: min, max: max, step: 0.01,
  74173. values: [min, max],
  74174. slide: (event, ui) => {
  74175. let min = ui.values[0];
  74176. let max = ui.values[1];
  74177. material.intensityRange = [min, max];
  74178. }
  74179. });
  74180. } else if(attribute){
  74181. const [min, max] = attribute.range;
  74182. let selectedRange = material.getRange(attribute.name);
  74183. if(!selectedRange){
  74184. selectedRange = [...attribute.range];
  74185. }
  74186. let minMaxAreNumbers = typeof min === "number" && typeof max === "number";
  74187. if(minMaxAreNumbers){
  74188. panel.find('#sldExtraRange').slider({
  74189. range: true,
  74190. min: min,
  74191. max: max,
  74192. step: 0.01,
  74193. values: selectedRange,
  74194. slide: (event, ui) => {
  74195. let [a, b] = ui.values;
  74196. material.setRange(attribute.name, [a, b]);
  74197. }
  74198. });
  74199. }
  74200. }
  74201. let blockWeights = $('#materials\\.composite_weight_container');
  74202. let blockElevation = $('#materials\\.elevation_container');
  74203. let blockRGB = $('#materials\\.rgb_container');
  74204. let blockExtra = $('#materials\\.extra_container');
  74205. let blockColor = $('#materials\\.color_container');
  74206. let blockIntensity = $('#materials\\.intensity_container');
  74207. let blockIndex = $('#materials\\.index_container');
  74208. let blockTransition = $('#materials\\.transition_container');
  74209. let blockGps = $('#materials\\.gpstime_container');
  74210. let blockMatcap = $('#materials\\.matcap_container');
  74211. blockIndex.css('display', 'none');
  74212. blockIntensity.css('display', 'none');
  74213. blockElevation.css('display', 'none');
  74214. blockRGB.css('display', 'none');
  74215. blockExtra.css('display', 'none');
  74216. blockColor.css('display', 'none');
  74217. blockWeights.css('display', 'none');
  74218. blockTransition.css('display', 'none');
  74219. blockMatcap.css('display', 'none');
  74220. blockGps.css('display', 'none');
  74221. if (selectedValue === 'composite') {
  74222. blockWeights.css('display', 'block');
  74223. blockElevation.css('display', 'block');
  74224. blockRGB.css('display', 'block');
  74225. blockIntensity.css('display', 'block');
  74226. } else if (selectedValue === 'elevation') {
  74227. blockElevation.css('display', 'block');
  74228. } else if (selectedValue === 'RGB and Elevation') {
  74229. blockRGB.css('display', 'block');
  74230. blockElevation.css('display', 'block');
  74231. } else if (selectedValue === 'rgba') {
  74232. blockRGB.css('display', 'block');
  74233. } else if (selectedValue === 'color') {
  74234. blockColor.css('display', 'block');
  74235. } else if (selectedValue === 'intensity') {
  74236. blockIntensity.css('display', 'block');
  74237. } else if (selectedValue === 'intensity gradient') {
  74238. blockIntensity.css('display', 'block');
  74239. } else if (selectedValue === "indices" ){
  74240. blockIndex.css('display', 'block');
  74241. } else if (selectedValue === "matcap" ){
  74242. blockMatcap.css('display', 'block');
  74243. } else if (selectedValue === "classification" ){
  74244. // add classification color selctor?
  74245. } else if (selectedValue === "gps-time" ){
  74246. blockGps.css('display', 'block');
  74247. } else if(selectedValue === "number of returns"){
  74248. } else if(selectedValue === "return number"){
  74249. } else if(["source id", "point source id"].includes(selectedValue)){
  74250. } else {
  74251. blockExtra.css('display', 'block');
  74252. }
  74253. };
  74254. attributeSelection.selectmenu({change: updateMaterialPanel});
  74255. let update = () => {
  74256. attributeSelection.val(material.activeAttributeName).selectmenu('refresh');
  74257. };
  74258. this.addVolatileListener(material, "point_color_type_changed", update);
  74259. this.addVolatileListener(material, "active_attribute_changed", update);
  74260. update();
  74261. updateMaterialPanel();
  74262. }
  74263. {
  74264. const schemes = Object.keys(Potree.Gradients).map(name => ({name: name, values: Gradients[name]}));
  74265. let elSchemeContainer = panel.find("#elevation_gradient_scheme_selection");
  74266. for(let scheme of schemes){
  74267. let elScheme = $(`
  74268. <span style="flex-grow: 1;">
  74269. </span>
  74270. `);
  74271. const svg = Potree.Utils.createSvgGradient(scheme.values);
  74272. svg.setAttributeNS(null, "class", `button-icon`);
  74273. elScheme.append($(svg));
  74274. elScheme.click( () => {
  74275. material.gradient = Gradients[scheme.name];
  74276. });
  74277. elSchemeContainer.append(elScheme);
  74278. }
  74279. }
  74280. {
  74281. let matcaps = [
  74282. {name: "Normals", icon: `${Potree.resourcePath}/icons/matcap/check_normal+y.jpg`},
  74283. {name: "Basic 1", icon: `${Potree.resourcePath}/icons/matcap/basic_1.jpg`},
  74284. {name: "Basic 2", icon: `${Potree.resourcePath}/icons/matcap/basic_2.jpg`},
  74285. {name: "Basic Dark", icon: `${Potree.resourcePath}/icons/matcap/basic_dark.jpg`},
  74286. {name: "Basic Side", icon: `${Potree.resourcePath}/icons/matcap/basic_side.jpg`},
  74287. {name: "Ceramic Dark", icon: `${Potree.resourcePath}/icons/matcap/ceramic_dark.jpg`},
  74288. {name: "Ceramic Lightbulb", icon: `${Potree.resourcePath}/icons/matcap/ceramic_lightbulb.jpg`},
  74289. {name: "Clay Brown", icon: `${Potree.resourcePath}/icons/matcap/clay_brown.jpg`},
  74290. {name: "Clay Muddy", icon: `${Potree.resourcePath}/icons/matcap/clay_muddy.jpg`},
  74291. {name: "Clay Studio", icon: `${Potree.resourcePath}/icons/matcap/clay_studio.jpg`},
  74292. {name: "Resin", icon: `${Potree.resourcePath}/icons/matcap/resin.jpg`},
  74293. {name: "Skin", icon: `${Potree.resourcePath}/icons/matcap/skin.jpg`},
  74294. {name: "Jade", icon: `${Potree.resourcePath}/icons/matcap/jade.jpg`},
  74295. {name: "Metal_ Anisotropic", icon: `${Potree.resourcePath}/icons/matcap/metal_anisotropic.jpg`},
  74296. {name: "Metal Carpaint", icon: `${Potree.resourcePath}/icons/matcap/metal_carpaint.jpg`},
  74297. {name: "Metal Lead", icon: `${Potree.resourcePath}/icons/matcap/metal_lead.jpg`},
  74298. {name: "Metal Shiny", icon: `${Potree.resourcePath}/icons/matcap/metal_shiny.jpg`},
  74299. {name: "Pearl", icon: `${Potree.resourcePath}/icons/matcap/pearl.jpg`},
  74300. {name: "Toon", icon: `${Potree.resourcePath}/icons/matcap/toon.jpg`},
  74301. {name: "Check Rim Light", icon: `${Potree.resourcePath}/icons/matcap/check_rim_light.jpg`},
  74302. {name: "Check Rim Dark", icon: `${Potree.resourcePath}/icons/matcap/check_rim_dark.jpg`},
  74303. {name: "Contours 1", icon: `${Potree.resourcePath}/icons/matcap/contours_1.jpg`},
  74304. {name: "Contours 2", icon: `${Potree.resourcePath}/icons/matcap/contours_2.jpg`},
  74305. {name: "Contours 3", icon: `${Potree.resourcePath}/icons/matcap/contours_3.jpg`},
  74306. {name: "Reflection Check Horizontal", icon: `${Potree.resourcePath}/icons/matcap/reflection_check_horizontal.jpg`},
  74307. {name: "Reflection Check Vertical", icon: `${Potree.resourcePath}/icons/matcap/reflection_check_vertical.jpg`},
  74308. ];
  74309. let elMatcapContainer = panel.find("#matcap_scheme_selection");
  74310. for(let matcap of matcaps){
  74311. let elMatcap = $(`
  74312. <img src="${matcap.icon}" class="button-icon" style="width: 25%;" />
  74313. `);
  74314. elMatcap.click( () => {
  74315. material.matcap = matcap.icon.substring(matcap.icon.lastIndexOf('/'));
  74316. });
  74317. elMatcapContainer.append(elMatcap);
  74318. }
  74319. }
  74320. {
  74321. panel.find('#sldRGBGamma').slider({
  74322. value: material.rgbGamma,
  74323. min: 0, max: 4, step: 0.01,
  74324. slide: (event, ui) => {material.rgbGamma = ui.value;}
  74325. });
  74326. panel.find('#sldRGBContrast').slider({
  74327. value: material.rgbContrast,
  74328. min: -1, max: 1, step: 0.01,
  74329. slide: (event, ui) => {material.rgbContrast = ui.value;}
  74330. });
  74331. panel.find('#sldRGBBrightness').slider({
  74332. value: material.rgbBrightness,
  74333. min: -1, max: 1, step: 0.01,
  74334. slide: (event, ui) => {material.rgbBrightness = ui.value;}
  74335. });
  74336. panel.find('#sldExtraGamma').slider({
  74337. value: material.extraGamma,
  74338. min: 0, max: 4, step: 0.01,
  74339. slide: (event, ui) => {material.extraGamma = ui.value;}
  74340. });
  74341. panel.find('#sldExtraBrightness').slider({
  74342. value: material.extraBrightness,
  74343. min: -1, max: 1, step: 0.01,
  74344. slide: (event, ui) => {material.extraBrightness = ui.value;}
  74345. });
  74346. panel.find('#sldExtraContrast').slider({
  74347. value: material.extraContrast,
  74348. min: -1, max: 1, step: 0.01,
  74349. slide: (event, ui) => {material.extraContrast = ui.value;}
  74350. });
  74351. panel.find('#sldHeightRange').slider({
  74352. range: true,
  74353. min: 0, max: 1000, step: 0.01,
  74354. values: [0, 1000],
  74355. slide: (event, ui) => {
  74356. material.heightMin = ui.values[0];
  74357. material.heightMax = ui.values[1];
  74358. }
  74359. });
  74360. panel.find('#sldIntensityGamma').slider({
  74361. value: material.intensityGamma,
  74362. min: 0, max: 4, step: 0.01,
  74363. slide: (event, ui) => {material.intensityGamma = ui.value;}
  74364. });
  74365. panel.find('#sldIntensityContrast').slider({
  74366. value: material.intensityContrast,
  74367. min: -1, max: 1, step: 0.01,
  74368. slide: (event, ui) => {material.intensityContrast = ui.value;}
  74369. });
  74370. panel.find('#sldIntensityBrightness').slider({
  74371. value: material.intensityBrightness,
  74372. min: -1, max: 1, step: 0.01,
  74373. slide: (event, ui) => {material.intensityBrightness = ui.value;}
  74374. });
  74375. panel.find('#sldWeightRGB').slider({
  74376. value: material.weightRGB,
  74377. min: 0, max: 1, step: 0.01,
  74378. slide: (event, ui) => {material.weightRGB = ui.value;}
  74379. });
  74380. panel.find('#sldWeightIntensity').slider({
  74381. value: material.weightIntensity,
  74382. min: 0, max: 1, step: 0.01,
  74383. slide: (event, ui) => {material.weightIntensity = ui.value;}
  74384. });
  74385. panel.find('#sldWeightElevation').slider({
  74386. value: material.weightElevation,
  74387. min: 0, max: 1, step: 0.01,
  74388. slide: (event, ui) => {material.weightElevation = ui.value;}
  74389. });
  74390. panel.find('#sldWeightClassification').slider({
  74391. value: material.weightClassification,
  74392. min: 0, max: 1, step: 0.01,
  74393. slide: (event, ui) => {material.weightClassification = ui.value;}
  74394. });
  74395. panel.find('#sldWeightReturnNumber').slider({
  74396. value: material.weightReturnNumber,
  74397. min: 0, max: 1, step: 0.01,
  74398. slide: (event, ui) => {material.weightReturnNumber = ui.value;}
  74399. });
  74400. panel.find('#sldWeightSourceID').slider({
  74401. value: material.weightSourceID,
  74402. min: 0, max: 1, step: 0.01,
  74403. slide: (event, ui) => {material.weightSourceID = ui.value;}
  74404. });
  74405. panel.find(`#materials\\.color\\.picker`).spectrum({
  74406. flat: true,
  74407. showInput: true,
  74408. preferredFormat: 'rgb',
  74409. cancelText: '',
  74410. chooseText: 'Apply',
  74411. color: `#${material.color.getHexString()}`,
  74412. move: color => {
  74413. let cRGB = color.toRgb();
  74414. let tc = new Color().setRGB(cRGB.r / 255, cRGB.g / 255, cRGB.b / 255);
  74415. material.color = tc;
  74416. },
  74417. change: color => {
  74418. let cRGB = color.toRgb();
  74419. let tc = new Color().setRGB(cRGB.r / 255, cRGB.g / 255, cRGB.b / 255);
  74420. material.color = tc;
  74421. }
  74422. });
  74423. this.addVolatileListener(material, "color_changed", () => {
  74424. panel.find(`#materials\\.color\\.picker`)
  74425. .spectrum('set', `#${material.color.getHexString()}`);
  74426. });
  74427. let updateHeightRange = function () {
  74428. let aPosition = pointcloud.getAttribute("position");
  74429. let bMin, bMax;
  74430. if(aPosition){
  74431. // for new format 2.0 and loader that contain precomputed min/max of attributes
  74432. let min = aPosition.range[0][2];
  74433. let max = aPosition.range[1][2];
  74434. let width = max - min;
  74435. bMin = min - 0.2 * width;
  74436. bMax = max + 0.2 * width;
  74437. }else {
  74438. // for format up until exlusive 2.0
  74439. let box = [pointcloud.pcoGeometry.tightBoundingBox, pointcloud.getBoundingBoxWorld()]
  74440. .find(v => v !== undefined);
  74441. pointcloud.updateMatrixWorld(true);
  74442. box = Utils.computeTransformedBoundingBox(box, pointcloud.matrixWorld);
  74443. let bWidth = box.max.z - box.min.z;
  74444. bMin = box.min.z - 0.2 * bWidth;
  74445. bMax = box.max.z + 0.2 * bWidth;
  74446. }
  74447. let range = material.elevationRange;
  74448. panel.find('#lblHeightRange').html(`${range[0].toFixed(2)} to ${range[1].toFixed(2)}`);
  74449. panel.find('#sldHeightRange').slider({min: bMin, max: bMax, values: range});
  74450. };
  74451. let updateExtraRange = function () {
  74452. let attributeName = material.activeAttributeName;
  74453. let attribute = pointcloud.getAttribute(attributeName);
  74454. if(attribute == null){
  74455. return;
  74456. }
  74457. let range = material.getRange(attributeName);
  74458. if(range == null){
  74459. range = attribute.range;
  74460. }
  74461. // currently only supporting scalar ranges.
  74462. // rgba, normals, positions, etc have vector ranges, however
  74463. let isValidRange = (typeof range[0] === "number") && (typeof range[1] === "number");
  74464. if(!isValidRange){
  74465. return;
  74466. }
  74467. if(range){
  74468. let msg = `${range[0].toFixed(2)} to ${range[1].toFixed(2)}`;
  74469. panel.find('#lblExtraRange').html(msg);
  74470. }else {
  74471. panel.find("could not deduce range");
  74472. }
  74473. };
  74474. let updateIntensityRange = function () {
  74475. let range = material.intensityRange;
  74476. panel.find('#lblIntensityRange').html(`${parseInt(range[0])} to ${parseInt(range[1])}`);
  74477. };
  74478. {
  74479. updateHeightRange();
  74480. panel.find(`#sldHeightRange`).slider('option', 'min');
  74481. panel.find(`#sldHeightRange`).slider('option', 'max');
  74482. }
  74483. {
  74484. let elGradientRepeat = panel.find("#gradient_repeat_option");
  74485. elGradientRepeat.selectgroup({title: "Gradient"});
  74486. elGradientRepeat.find("input").click( (e) => {
  74487. this.viewer.setElevationGradientRepeat(ElevationGradientRepeat[e.target.value]);
  74488. });
  74489. let current = Object.keys(ElevationGradientRepeat)
  74490. .filter(key => ElevationGradientRepeat[key] === this.viewer.elevationGradientRepeat);
  74491. elGradientRepeat.find(`input[value=${current}]`).trigger("click");
  74492. }
  74493. let onIntensityChange = () => {
  74494. let gamma = material.intensityGamma;
  74495. let contrast = material.intensityContrast;
  74496. let brightness = material.intensityBrightness;
  74497. updateIntensityRange();
  74498. panel.find('#lblIntensityGamma').html(gamma.toFixed(2));
  74499. panel.find('#lblIntensityContrast').html(contrast.toFixed(2));
  74500. panel.find('#lblIntensityBrightness').html(brightness.toFixed(2));
  74501. panel.find('#sldIntensityGamma').slider({value: gamma});
  74502. panel.find('#sldIntensityContrast').slider({value: contrast});
  74503. panel.find('#sldIntensityBrightness').slider({value: brightness});
  74504. };
  74505. let onRGBChange = () => {
  74506. let gamma = material.rgbGamma;
  74507. let contrast = material.rgbContrast;
  74508. let brightness = material.rgbBrightness;
  74509. panel.find('#lblRGBGamma').html(gamma.toFixed(2));
  74510. panel.find('#lblRGBContrast').html(contrast.toFixed(2));
  74511. panel.find('#lblRGBBrightness').html(brightness.toFixed(2));
  74512. panel.find('#sldRGBGamma').slider({value: gamma});
  74513. panel.find('#sldRGBContrast').slider({value: contrast});
  74514. panel.find('#sldRGBBrightness').slider({value: brightness});
  74515. };
  74516. this.addVolatileListener(material, "material_property_changed", updateExtraRange);
  74517. this.addVolatileListener(material, "material_property_changed", updateHeightRange);
  74518. this.addVolatileListener(material, "material_property_changed", onIntensityChange);
  74519. this.addVolatileListener(material, "material_property_changed", onRGBChange);
  74520. updateExtraRange();
  74521. updateHeightRange();
  74522. onIntensityChange();
  74523. onRGBChange();
  74524. }
  74525. }
  74526. setMeasurement(object){
  74527. let TYPE = {
  74528. DISTANCE: {panel: DistancePanel},
  74529. AREA: {panel: AreaPanel},
  74530. POINT: {panel: PointPanel},
  74531. ANGLE: {panel: AnglePanel},
  74532. HEIGHT: {panel: HeightPanel},
  74533. PROFILE: {panel: ProfilePanel},
  74534. VOLUME: {panel: VolumePanel},
  74535. CIRCLE: {panel: CirclePanel},
  74536. OTHER: {panel: PointPanel},
  74537. };
  74538. let getType = (measurement) => {
  74539. if (measurement instanceof Measure) {
  74540. if (measurement.showDistances && !measurement.showArea && !measurement.showAngles) {
  74541. return TYPE.DISTANCE;
  74542. } else if (measurement.showDistances && measurement.showArea && !measurement.showAngles) {
  74543. return TYPE.AREA;
  74544. } else if (measurement.maxMarkers === 1) {
  74545. return TYPE.POINT;
  74546. } else if (!measurement.showDistances && !measurement.showArea && measurement.showAngles) {
  74547. return TYPE.ANGLE;
  74548. } else if (measurement.showHeight) {
  74549. return TYPE.HEIGHT;
  74550. } else if (measurement.showCircle) {
  74551. return TYPE.CIRCLE;
  74552. } else {
  74553. return TYPE.OTHER;
  74554. }
  74555. } else if (measurement instanceof Profile) {
  74556. return TYPE.PROFILE;
  74557. } else if (measurement instanceof Volume) {
  74558. return TYPE.VOLUME;
  74559. }
  74560. };
  74561. //this.container.html("measurement");
  74562. let type = getType(object);
  74563. let Panel = type.panel;
  74564. let panel = new Panel(this.viewer, object, this);
  74565. this.container.append(panel.elContent);
  74566. }
  74567. setCamera(camera){
  74568. let panel = new CameraPanel(this.viewer, this);
  74569. this.container.append(panel.elContent);
  74570. }
  74571. setAnnotation(annotation){
  74572. let panel = new AnnotationPanel(this.viewer, this, annotation);
  74573. this.container.append(panel.elContent);
  74574. }
  74575. setCameraAnimation(animation){
  74576. let panel = new CameraAnimationPanel(this.viewer, this, animation);
  74577. this.container.append(panel.elContent);
  74578. }
  74579. }
  74580. function addCommas(nStr){
  74581. nStr += '';
  74582. let x = nStr.split('.');
  74583. let x1 = x[0];
  74584. let x2 = x.length > 1 ? '.' + x[1] : '';
  74585. let rgx = /(\d+)(\d{3})/;
  74586. while (rgx.test(x1)) {
  74587. x1 = x1.replace(rgx, '$1' + ',' + '$2');
  74588. }
  74589. return x1 + x2;
  74590. };
  74591. function format(value){
  74592. return addCommas(value.toFixed(3));
  74593. };
  74594. class HierarchicalSlider{
  74595. constructor(params = {}){
  74596. this.element = document.createElement("div");
  74597. this.labels = [];
  74598. this.sliders = [];
  74599. this.range = params.range != null ? params.range : [0, 1];
  74600. this.slide = params.slide != null ? params.slide : null;
  74601. this.step = params.step != null ? params.step : 0.0001;
  74602. let levels = params.levels != null ? params.levels : 1;
  74603. for(let level = 0; level < levels; level++){
  74604. this.addLevel();
  74605. }
  74606. }
  74607. setRange(range){
  74608. this.range = [...range];
  74609. { // root slider
  74610. let slider = this.sliders[0];
  74611. $(slider).slider({
  74612. min: range[0],
  74613. max: range[1],
  74614. });
  74615. }
  74616. for(let i = 1; i < this.sliders.length; i++){
  74617. let parentSlider = this.sliders[i - 1];
  74618. let slider = this.sliders[i];
  74619. let parentValues = $(parentSlider).slider("option", "values");
  74620. let childRange = [...parentValues];
  74621. $(slider).slider({
  74622. min: childRange[0],
  74623. max: childRange[1],
  74624. });
  74625. }
  74626. this.updateLabels();
  74627. }
  74628. setValues(values){
  74629. for(let slider of this.sliders){
  74630. $(slider).slider({
  74631. values: [...values],
  74632. });
  74633. }
  74634. this.updateLabels();
  74635. }
  74636. addLevel(){
  74637. const elLevel = document.createElement("li");
  74638. const elRange = document.createTextNode("Range: ");
  74639. const label = document.createElement("span");
  74640. const slider = document.createElement("div");
  74641. let level = this.sliders.length;
  74642. let [min, max] = [0, 0];
  74643. if(this.sliders.length === 0){
  74644. [min, max] = this.range;
  74645. }else {
  74646. let parentSlider = this.sliders[this.sliders.length - 1];
  74647. [min, max] = $(parentSlider).slider("option", "values");
  74648. }
  74649. $(slider).slider({
  74650. range: true,
  74651. min: min,
  74652. max: max,
  74653. step: this.step,
  74654. values: [min, max],
  74655. slide: (event, ui) => {
  74656. // set all descendants to same range
  74657. let levels = this.sliders.length;
  74658. for(let i = level + 1; i < levels; i++){
  74659. let descendant = this.sliders[i];
  74660. $(descendant).slider({
  74661. range: true,
  74662. min: ui.values[0],
  74663. max: ui.values[1],
  74664. values: [...ui.values],
  74665. });
  74666. }
  74667. if(this.slide){
  74668. let values = [...ui.values];
  74669. this.slide({
  74670. target: this,
  74671. range: this.range,
  74672. values: values,
  74673. });
  74674. }
  74675. this.updateLabels();
  74676. },
  74677. });
  74678. elLevel.append(elRange, label, slider);
  74679. this.sliders.push(slider);
  74680. this.labels.push(label);
  74681. this.element.append(elLevel);
  74682. this.updateLabels();
  74683. }
  74684. removeLevel(){
  74685. }
  74686. updateSliders(){
  74687. }
  74688. updateLabels(){
  74689. let levels = this.sliders.length;
  74690. for(let i = 0; i < levels; i++){
  74691. let slider = this.sliders[i];
  74692. let label = this.labels[i];
  74693. let [min, max] = $(slider).slider("option", "values");
  74694. let strMin = format(min);
  74695. let strMax = format(max);
  74696. let strLabel = `${strMin} to ${strMax}`;
  74697. label.innerHTML = strLabel;
  74698. }
  74699. }
  74700. }
  74701. class OrientedImageControls extends EventDispatcher$1{
  74702. constructor(viewer){
  74703. super();
  74704. this.viewer = viewer;
  74705. this.renderer = viewer.renderer;
  74706. this.originalCam = viewer.scene.getActiveCamera();
  74707. this.shearCam = viewer.scene.getActiveCamera().clone();
  74708. this.shearCam.rotation.set(this.originalCam.rotation.toArray());
  74709. this.shearCam.updateProjectionMatrix();
  74710. this.shearCam.updateProjectionMatrix = () => {
  74711. return this.shearCam.projectionMatrix;
  74712. };
  74713. this.image = null;
  74714. this.fadeFactor = 20;
  74715. this.fovDelta = 0;
  74716. this.fovMin = 0.1;
  74717. this.fovMax = 120;
  74718. this.shear = [0, 0];
  74719. // const style = ``;
  74720. this.elUp = $(`<input type="button" value="🡅" style="position: absolute; top: 10px; left: calc(50%); z-index: 1000" />`);
  74721. this.elRight = $(`<input type="button" value="🡆" style="position: absolute; top: calc(50%); right: 10px; z-index: 1000" />`);
  74722. this.elDown = $(`<input type="button" value="🡇" style="position: absolute; bottom: 10px; left: calc(50%); z-index: 1000" />`);
  74723. this.elLeft = $(`<input type="button" value="🡄" style="position: absolute; top: calc(50%); left: 10px; z-index: 1000" />`);
  74724. this.elExit = $(`<input type="button" value="Back to 3D view" style="position: absolute; bottom: 10px; right: 10px; z-index: 1000" />`);
  74725. this.elExit.click( () => {
  74726. this.release();
  74727. });
  74728. this.elUp.click(() => {
  74729. const fovY = viewer.getFOV();
  74730. const top = Math.tan(MathUtils.degToRad(fovY / 2));
  74731. this.shear[1] += 0.1 * top;
  74732. });
  74733. this.elRight.click(() => {
  74734. const fovY = viewer.getFOV();
  74735. const top = Math.tan(MathUtils.degToRad(fovY / 2));
  74736. this.shear[0] += 0.1 * top;
  74737. });
  74738. this.elDown.click(() => {
  74739. const fovY = viewer.getFOV();
  74740. const top = Math.tan(MathUtils.degToRad(fovY / 2));
  74741. this.shear[1] -= 0.1 * top;
  74742. });
  74743. this.elLeft.click(() => {
  74744. const fovY = viewer.getFOV();
  74745. const top = Math.tan(MathUtils.degToRad(fovY / 2));
  74746. this.shear[0] -= 0.1 * top;
  74747. });
  74748. this.scene = null;
  74749. this.sceneControls = new Scene();
  74750. let scroll = (e) => {
  74751. this.fovDelta += -e.delta * 1.0;
  74752. };
  74753. this.addEventListener('mousewheel', scroll);
  74754. //this.addEventListener("mousemove", onMove);
  74755. }
  74756. hasSomethingCaptured(){
  74757. return this.image !== null;
  74758. }
  74759. capture(image){
  74760. if(this.hasSomethingCaptured()){
  74761. return;
  74762. }
  74763. this.image = image;
  74764. this.originalFOV = this.viewer.getFOV();
  74765. this.originalControls = this.viewer.getControls();
  74766. this.viewer.setControls(this);
  74767. this.viewer.scene.overrideCamera = this.shearCam;
  74768. const elCanvas = this.viewer.renderer.domElement;
  74769. const elRoot = $(elCanvas.parentElement);
  74770. this.shear = [0, 0];
  74771. elRoot.append(this.elUp);
  74772. elRoot.append(this.elRight);
  74773. elRoot.append(this.elDown);
  74774. elRoot.append(this.elLeft);
  74775. elRoot.append(this.elExit);
  74776. }
  74777. release(){
  74778. this.image = null;
  74779. this.viewer.scene.overrideCamera = null;
  74780. this.elUp.detach();
  74781. this.elRight.detach();
  74782. this.elDown.detach();
  74783. this.elLeft.detach();
  74784. this.elExit.detach();
  74785. this.viewer.setFOV(this.originalFOV);
  74786. this.viewer.setControls(this.originalControls);
  74787. }
  74788. setScene (scene) {
  74789. this.scene = scene;
  74790. }
  74791. update (delta) {
  74792. // const view = this.scene.view;
  74793. // let prevTotal = this.shearCam.projectionMatrix.elements.reduce( (a, i) => a + i, 0);
  74794. //const progression = Math.min(1, this.fadeFactor * delta);
  74795. //const attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  74796. const progression = 1;
  74797. const attenuation = 0;
  74798. const oldFov = this.viewer.getFOV();
  74799. let fovProgression = progression * this.fovDelta;
  74800. let newFov = oldFov * ((1 + fovProgression / 10));
  74801. newFov = Math.max(this.fovMin, newFov);
  74802. newFov = Math.min(this.fovMax, newFov);
  74803. let diff = newFov / oldFov;
  74804. const mouse = this.viewer.inputHandler.mouse;
  74805. const canvasSize = this.viewer.renderer.getSize(new Vector2());
  74806. const uv = [
  74807. (mouse.x / canvasSize.x),
  74808. ((canvasSize.y - mouse.y) / canvasSize.y)
  74809. ];
  74810. const fovY = newFov;
  74811. const aspect = canvasSize.x / canvasSize.y;
  74812. const top = Math.tan(MathUtils.degToRad(fovY / 2));
  74813. const height = 2 * top;
  74814. const width = aspect * height;
  74815. const shearRangeX = [
  74816. this.shear[0] - 0.5 * width,
  74817. this.shear[0] + 0.5 * width,
  74818. ];
  74819. const shearRangeY = [
  74820. this.shear[1] - 0.5 * height,
  74821. this.shear[1] + 0.5 * height,
  74822. ];
  74823. const shx = (1 - uv[0]) * shearRangeX[0] + uv[0] * shearRangeX[1];
  74824. const shy = (1 - uv[1]) * shearRangeY[0] + uv[1] * shearRangeY[1];
  74825. const shu = (1 - diff);
  74826. const newShear = [
  74827. (1 - shu) * this.shear[0] + shu * shx,
  74828. (1 - shu) * this.shear[1] + shu * shy,
  74829. ];
  74830. this.shear = newShear;
  74831. this.viewer.setFOV(newFov);
  74832. const {originalCam, shearCam} = this;
  74833. originalCam.fov = newFov;
  74834. originalCam.updateMatrixWorld();
  74835. originalCam.updateProjectionMatrix();
  74836. shearCam.copy(originalCam);
  74837. shearCam.rotation.set(...originalCam.rotation.toArray());
  74838. shearCam.updateMatrixWorld();
  74839. shearCam.projectionMatrix.copy(originalCam.projectionMatrix);
  74840. const [sx, sy] = this.shear;
  74841. const mShear = new Matrix4().set(
  74842. 1, 0, sx, 0,
  74843. 0, 1, sy, 0,
  74844. 0, 0, 1, 0,
  74845. 0, 0, 0, 1,
  74846. );
  74847. const proj = shearCam.projectionMatrix;
  74848. proj.multiply(mShear);
  74849. shearCam.projectionMatrixInverse.copy(proj).invert();
  74850. let total = shearCam.projectionMatrix.elements.reduce( (a, i) => a + i, 0);
  74851. this.fovDelta *= attenuation;
  74852. }
  74853. };
  74854. // https://support.pix4d.com/hc/en-us/articles/205675256-How-are-yaw-pitch-roll-defined
  74855. // https://support.pix4d.com/hc/en-us/articles/202558969-How-are-omega-phi-kappa-defined
  74856. function createMaterial(){
  74857. let vertexShader = `
  74858. uniform float uNear;
  74859. varying vec2 vUV;
  74860. varying vec4 vDebug;
  74861. void main(){
  74862. vDebug = vec4(0.0, 1.0, 0.0, 1.0);
  74863. vec4 modelViewPosition = modelViewMatrix * vec4(position, 1.0);
  74864. // make sure that this mesh is at least in front of the near plane
  74865. modelViewPosition.xyz += normalize(modelViewPosition.xyz) * uNear;
  74866. gl_Position = projectionMatrix * modelViewPosition;
  74867. vUV = uv;
  74868. }
  74869. `;
  74870. let fragmentShader = `
  74871. uniform sampler2D tColor;
  74872. uniform float uOpacity;
  74873. varying vec2 vUV;
  74874. varying vec4 vDebug;
  74875. void main(){
  74876. vec4 color = texture2D(tColor, vUV);
  74877. gl_FragColor = color;
  74878. gl_FragColor.a = uOpacity;
  74879. }
  74880. `;
  74881. const material = new ShaderMaterial( {
  74882. uniforms: {
  74883. // time: { value: 1.0 },
  74884. // resolution: { value: new THREE.Vector2() }
  74885. tColor: {value: new Texture() },
  74886. uNear: {value: 0.0},
  74887. uOpacity: {value: 1.0},
  74888. },
  74889. vertexShader: vertexShader,
  74890. fragmentShader: fragmentShader,
  74891. side: DoubleSide,
  74892. } );
  74893. material.side = DoubleSide;
  74894. return material;
  74895. }
  74896. const planeGeometry = new PlaneGeometry(1, 1);
  74897. const lineGeometry = new Geometry();
  74898. lineGeometry.vertices.push(
  74899. new Vector3(-0.5, -0.5, 0),
  74900. new Vector3( 0.5, -0.5, 0),
  74901. new Vector3( 0.5, 0.5, 0),
  74902. new Vector3(-0.5, 0.5, 0),
  74903. new Vector3(-0.5, -0.5, 0),
  74904. );
  74905. class OrientedImage{
  74906. constructor(id){
  74907. this.id = id;
  74908. this.fov = 1.0;
  74909. this.position = new Vector3();
  74910. this.rotation = new Vector3();
  74911. this.width = 0;
  74912. this.height = 0;
  74913. this.fov = 1.0;
  74914. const material = createMaterial();
  74915. const lineMaterial = new LineBasicMaterial( { color: 0x00ff00 } );
  74916. this.mesh = new Mesh(planeGeometry, material);
  74917. this.line = new Line(lineGeometry, lineMaterial);
  74918. this.texture = null;
  74919. this.mesh.orientedImage = this;
  74920. }
  74921. set(position, rotation, dimension, fov){
  74922. let radians = rotation.map(MathUtils.degToRad);
  74923. this.position.set(...position);
  74924. this.mesh.position.set(...position);
  74925. this.rotation.set(...radians);
  74926. this.mesh.rotation.set(...radians);
  74927. [this.width, this.height] = dimension;
  74928. this.mesh.scale.set(this.width / this.height, 1, 1);
  74929. this.fov = fov;
  74930. this.updateTransform();
  74931. }
  74932. updateTransform(){
  74933. let {mesh, line, fov} = this;
  74934. mesh.updateMatrixWorld();
  74935. const dir = mesh.getWorldDirection();
  74936. const alpha = MathUtils.degToRad(fov / 2);
  74937. const d = -0.5 / Math.tan(alpha);
  74938. const move = dir.clone().multiplyScalar(d);
  74939. mesh.position.add(move);
  74940. line.position.copy(mesh.position);
  74941. line.scale.copy(mesh.scale);
  74942. line.rotation.copy(mesh.rotation);
  74943. }
  74944. };
  74945. class OrientedImages extends EventDispatcher$1{
  74946. constructor(){
  74947. super();
  74948. this.node = null;
  74949. this.cameraParams = null;
  74950. this.imageParams = null;
  74951. this.images = null;
  74952. this._visible = true;
  74953. }
  74954. set visible(visible){
  74955. if(this._visible === visible){
  74956. return;
  74957. }
  74958. for(const image of this.images){
  74959. image.mesh.visible = visible;
  74960. image.line.visible = visible;
  74961. }
  74962. this._visible = visible;
  74963. this.dispatchEvent({
  74964. type: "visibility_changed",
  74965. images: this,
  74966. });
  74967. }
  74968. get visible(){
  74969. return this._visible;
  74970. }
  74971. };
  74972. class OrientedImageLoader{
  74973. static async loadCameraParams(path){
  74974. const res = await fetch(path);
  74975. const text = await res.text();
  74976. const parser = new DOMParser();
  74977. const doc = parser.parseFromString(text, "application/xml");
  74978. const width = parseInt(doc.getElementsByTagName("width")[0].textContent);
  74979. const height = parseInt(doc.getElementsByTagName("height")[0].textContent);
  74980. const f = parseFloat(doc.getElementsByTagName("f")[0].textContent);
  74981. let a = (height / 2) / f;
  74982. let fov = 2 * MathUtils.radToDeg(Math.atan(a));
  74983. const params = {
  74984. path: path,
  74985. width: width,
  74986. height: height,
  74987. f: f,
  74988. fov: fov,
  74989. };
  74990. return params;
  74991. }
  74992. static async loadImageParams(path){
  74993. const response = await fetch(path);
  74994. if(!response.ok){
  74995. console.error(`failed to load ${path}`);
  74996. return;
  74997. }
  74998. const content = await response.text();
  74999. const lines = content.split(/\r?\n/);
  75000. const imageParams = [];
  75001. for(let i = 1; i < lines.length; i++){
  75002. const line = lines[i];
  75003. if(line.startsWith("#")){
  75004. continue;
  75005. }
  75006. const tokens = line.split(/\s+/);
  75007. if(tokens.length < 6){
  75008. continue;
  75009. }
  75010. const params = {
  75011. id: tokens[0],
  75012. x: Number.parseFloat(tokens[1]),
  75013. y: Number.parseFloat(tokens[2]),
  75014. z: Number.parseFloat(tokens[3]),
  75015. omega: Number.parseFloat(tokens[4]),
  75016. phi: Number.parseFloat(tokens[5]),
  75017. kappa: Number.parseFloat(tokens[6]),
  75018. };
  75019. // const whitelist = ["47518.jpg"];
  75020. // if(whitelist.includes(params.id)){
  75021. // imageParams.push(params);
  75022. // }
  75023. imageParams.push(params);
  75024. }
  75025. // debug
  75026. //return [imageParams[50]];
  75027. return imageParams;
  75028. }
  75029. static async load(cameraParamsPath, imageParamsPath, viewer){
  75030. const tStart = performance.now();
  75031. const [cameraParams, imageParams] = await Promise.all([
  75032. OrientedImageLoader.loadCameraParams(cameraParamsPath),
  75033. OrientedImageLoader.loadImageParams(imageParamsPath),
  75034. ]);
  75035. const orientedImageControls = new OrientedImageControls(viewer);
  75036. const raycaster = new Raycaster();
  75037. const tEnd = performance.now();
  75038. console.log(tEnd - tStart);
  75039. // const sp = new THREE.PlaneGeometry(1, 1);
  75040. // const lg = new THREE.Geometry();
  75041. // lg.vertices.push(
  75042. // new THREE.Vector3(-0.5, -0.5, 0),
  75043. // new THREE.Vector3( 0.5, -0.5, 0),
  75044. // new THREE.Vector3( 0.5, 0.5, 0),
  75045. // new THREE.Vector3(-0.5, 0.5, 0),
  75046. // new THREE.Vector3(-0.5, -0.5, 0),
  75047. // );
  75048. const {width, height} = cameraParams;
  75049. const orientedImages = [];
  75050. const sceneNode = new Object3D();
  75051. sceneNode.name = "oriented_images";
  75052. for(const params of imageParams){
  75053. // const material = createMaterial();
  75054. // const lm = new THREE.LineBasicMaterial( { color: 0x00ff00 } );
  75055. // const mesh = new THREE.Mesh(sp, material);
  75056. const {x, y, z, omega, phi, kappa} = params;
  75057. // const [rx, ry, rz] = [omega, phi, kappa]
  75058. // .map(THREE.Math.degToRad);
  75059. // mesh.position.set(x, y, z);
  75060. // mesh.scale.set(width / height, 1, 1);
  75061. // mesh.rotation.set(rx, ry, rz);
  75062. // {
  75063. // mesh.updateMatrixWorld();
  75064. // const dir = mesh.getWorldDirection();
  75065. // const alpha = THREE.Math.degToRad(cameraParams.fov / 2);
  75066. // const d = -0.5 / Math.tan(alpha);
  75067. // const move = dir.clone().multiplyScalar(d);
  75068. // mesh.position.add(move);
  75069. // }
  75070. // sceneNode.add(mesh);
  75071. // const line = new THREE.Line(lg, lm);
  75072. // line.position.copy(mesh.position);
  75073. // line.scale.copy(mesh.scale);
  75074. // line.rotation.copy(mesh.rotation);
  75075. // sceneNode.add(line);
  75076. let orientedImage = new OrientedImage(params.id);
  75077. // orientedImage.setPosition(x, y, z);
  75078. // orientedImage.setRotation(omega, phi, kappa);
  75079. // orientedImage.setDimension(width, height);
  75080. let position = [x, y, z];
  75081. let rotation = [omega, phi, kappa];
  75082. let dimension = [width, height];
  75083. orientedImage.set(position, rotation, dimension, cameraParams.fov);
  75084. sceneNode.add(orientedImage.mesh);
  75085. sceneNode.add(orientedImage.line);
  75086. orientedImages.push(orientedImage);
  75087. }
  75088. let hoveredElement = null;
  75089. let clipVolume = null;
  75090. const onMouseMove = (evt) => {
  75091. const tStart = performance.now();
  75092. if(hoveredElement){
  75093. hoveredElement.line.material.color.setRGB(0, 1, 0);
  75094. }
  75095. evt.preventDefault();
  75096. //var array = getMousePosition( container, evt.clientX, evt.clientY );
  75097. const rect = viewer.renderer.domElement.getBoundingClientRect();
  75098. const [x, y] = [evt.clientX, evt.clientY];
  75099. const array = [
  75100. ( x - rect.left ) / rect.width,
  75101. ( y - rect.top ) / rect.height
  75102. ];
  75103. const onClickPosition = new Vector2(...array);
  75104. //const intersects = getIntersects(onClickPosition, scene.children);
  75105. const camera = viewer.scene.getActiveCamera();
  75106. const mouse = new Vector3(
  75107. + ( onClickPosition.x * 2 ) - 1,
  75108. - ( onClickPosition.y * 2 ) + 1 );
  75109. const objects = orientedImages.map(i => i.mesh);
  75110. raycaster.setFromCamera( mouse, camera );
  75111. const intersects = raycaster.intersectObjects( objects );
  75112. let selectionChanged = false;
  75113. if ( intersects.length > 0){
  75114. //console.log(intersects);
  75115. const intersection = intersects[0];
  75116. const orientedImage = intersection.object.orientedImage;
  75117. orientedImage.line.material.color.setRGB(1, 0, 0);
  75118. selectionChanged = hoveredElement !== orientedImage;
  75119. hoveredElement = orientedImage;
  75120. }else {
  75121. hoveredElement = null;
  75122. }
  75123. let shouldRemoveClipVolume = clipVolume !== null && hoveredElement === null;
  75124. let shouldAddClipVolume = clipVolume === null && hoveredElement !== null;
  75125. if(clipVolume !== null && (hoveredElement === null || selectionChanged)){
  75126. // remove existing
  75127. viewer.scene.removePolygonClipVolume(clipVolume);
  75128. clipVolume = null;
  75129. }
  75130. if(shouldAddClipVolume || selectionChanged){
  75131. const img = hoveredElement;
  75132. const fov = cameraParams.fov;
  75133. const aspect = cameraParams.width / cameraParams.height;
  75134. const near = 1.0;
  75135. const far = 1000 * 1000;
  75136. const camera = new PerspectiveCamera(fov, aspect, near, far);
  75137. camera.rotation.order = viewer.scene.getActiveCamera().rotation.order;
  75138. camera.rotation.copy(img.mesh.rotation);
  75139. {
  75140. const mesh = img.mesh;
  75141. const dir = mesh.getWorldDirection();
  75142. const pos = mesh.position;
  75143. const alpha = MathUtils.degToRad(fov / 2);
  75144. const d = 0.5 / Math.tan(alpha);
  75145. const newCamPos = pos.clone().add(dir.clone().multiplyScalar(d));
  75146. const newCamDir = pos.clone().sub(newCamPos);
  75147. const newCamTarget = new Vector3().addVectors(
  75148. newCamPos,
  75149. newCamDir.clone().multiplyScalar(viewer.getMoveSpeed()));
  75150. camera.position.copy(newCamPos);
  75151. }
  75152. let volume = new Potree.PolygonClipVolume(camera);
  75153. let m0 = new Mesh();
  75154. let m1 = new Mesh();
  75155. let m2 = new Mesh();
  75156. let m3 = new Mesh();
  75157. m0.position.set(-1, -1, 0);
  75158. m1.position.set( 1, -1, 0);
  75159. m2.position.set( 1, 1, 0);
  75160. m3.position.set(-1, 1, 0);
  75161. volume.markers.push(m0, m1, m2, m3);
  75162. volume.initialized = true;
  75163. viewer.scene.addPolygonClipVolume(volume);
  75164. clipVolume = volume;
  75165. }
  75166. const tEnd = performance.now();
  75167. //console.log(tEnd - tStart);
  75168. };
  75169. const moveToImage = (image) => {
  75170. console.log("move to image " + image.id);
  75171. const mesh = image.mesh;
  75172. const newCamPos = image.position.clone();
  75173. const newCamTarget = mesh.position.clone();
  75174. viewer.scene.view.setView(newCamPos, newCamTarget, 500, () => {
  75175. orientedImageControls.capture(image);
  75176. });
  75177. if(image.texture === null){
  75178. const target = image;
  75179. const tmpImagePath = `${Potree.resourcePath}/images/loading.jpg`;
  75180. new TextureLoader().load(tmpImagePath,
  75181. (texture) => {
  75182. if(target.texture === null){
  75183. target.texture = texture;
  75184. target.mesh.material.uniforms.tColor.value = texture;
  75185. mesh.material.needsUpdate = true;
  75186. }
  75187. }
  75188. );
  75189. const imagePath = `${imageParamsPath}/../${target.id}`;
  75190. new TextureLoader().load(imagePath,
  75191. (texture) => {
  75192. target.texture = texture;
  75193. target.mesh.material.uniforms.tColor.value = texture;
  75194. mesh.material.needsUpdate = true;
  75195. }
  75196. );
  75197. }
  75198. };
  75199. const onMouseClick = (evt) => {
  75200. if(orientedImageControls.hasSomethingCaptured()){
  75201. return;
  75202. }
  75203. if(hoveredElement){
  75204. moveToImage(hoveredElement);
  75205. }
  75206. };
  75207. viewer.renderer.domElement.addEventListener( 'mousemove', onMouseMove, false );
  75208. viewer.renderer.domElement.addEventListener( 'mousedown', onMouseClick, false );
  75209. viewer.addEventListener("update", () => {
  75210. for(const image of orientedImages){
  75211. const world = image.mesh.matrixWorld;
  75212. const {width, height} = image;
  75213. const aspect = width / height;
  75214. const camera = viewer.scene.getActiveCamera();
  75215. const imgPos = image.mesh.getWorldPosition(new Vector3());
  75216. const camPos = camera.position;
  75217. const d = camPos.distanceTo(imgPos);
  75218. const minSize = 1; // in degrees of fov
  75219. const a = MathUtils.degToRad(minSize);
  75220. let r = d * Math.tan(a);
  75221. r = Math.max(r, 1);
  75222. image.mesh.scale.set(r * aspect, r, 1);
  75223. image.line.scale.set(r * aspect, r, 1);
  75224. image.mesh.material.uniforms.uNear.value = camera.near;
  75225. }
  75226. });
  75227. const images = new OrientedImages();
  75228. images.node = sceneNode;
  75229. images.cameraParamsPath = cameraParamsPath;
  75230. images.imageParamsPath = imageParamsPath;
  75231. images.cameraParams = cameraParams;
  75232. images.imageParams = imageParams;
  75233. images.images = orientedImages;
  75234. Potree.debug.moveToImage = moveToImage;
  75235. return images;
  75236. }
  75237. }
  75238. // This is a generated file. Do not edit.
  75239. var Space_Separator = /[\u1680\u2000-\u200A\u202F\u205F\u3000]/;
  75240. 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]/;
  75241. 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]/;
  75242. var unicode = {
  75243. Space_Separator: Space_Separator,
  75244. ID_Start: ID_Start,
  75245. ID_Continue: ID_Continue
  75246. };
  75247. var util = {
  75248. isSpaceSeparator (c) {
  75249. return typeof c === 'string' && unicode.Space_Separator.test(c)
  75250. },
  75251. isIdStartChar (c) {
  75252. return typeof c === 'string' && (
  75253. (c >= 'a' && c <= 'z') ||
  75254. (c >= 'A' && c <= 'Z') ||
  75255. (c === '$') || (c === '_') ||
  75256. unicode.ID_Start.test(c)
  75257. )
  75258. },
  75259. isIdContinueChar (c) {
  75260. return typeof c === 'string' && (
  75261. (c >= 'a' && c <= 'z') ||
  75262. (c >= 'A' && c <= 'Z') ||
  75263. (c >= '0' && c <= '9') ||
  75264. (c === '$') || (c === '_') ||
  75265. (c === '\u200C') || (c === '\u200D') ||
  75266. unicode.ID_Continue.test(c)
  75267. )
  75268. },
  75269. isDigit (c) {
  75270. return typeof c === 'string' && /[0-9]/.test(c)
  75271. },
  75272. isHexDigit (c) {
  75273. return typeof c === 'string' && /[0-9A-Fa-f]/.test(c)
  75274. },
  75275. };
  75276. let source;
  75277. let parseState;
  75278. let stack$1;
  75279. let pos;
  75280. let line;
  75281. let column;
  75282. let token;
  75283. let key;
  75284. let root;
  75285. var parse = function parse (text, reviver) {
  75286. source = String(text);
  75287. parseState = 'start';
  75288. stack$1 = [];
  75289. pos = 0;
  75290. line = 1;
  75291. column = 0;
  75292. token = undefined;
  75293. key = undefined;
  75294. root = undefined;
  75295. do {
  75296. token = lex();
  75297. // This code is unreachable.
  75298. // if (!parseStates[parseState]) {
  75299. // throw invalidParseState()
  75300. // }
  75301. parseStates[parseState]();
  75302. } while (token.type !== 'eof')
  75303. if (typeof reviver === 'function') {
  75304. return internalize({'': root}, '', reviver)
  75305. }
  75306. return root
  75307. };
  75308. function internalize (holder, name, reviver) {
  75309. const value = holder[name];
  75310. if (value != null && typeof value === 'object') {
  75311. for (const key in value) {
  75312. const replacement = internalize(value, key, reviver);
  75313. if (replacement === undefined) {
  75314. delete value[key];
  75315. } else {
  75316. value[key] = replacement;
  75317. }
  75318. }
  75319. }
  75320. return reviver.call(holder, name, value)
  75321. }
  75322. let lexState;
  75323. let buffer;
  75324. let doubleQuote;
  75325. let sign$1;
  75326. let c$1;
  75327. function lex () {
  75328. lexState = 'default';
  75329. buffer = '';
  75330. doubleQuote = false;
  75331. sign$1 = 1;
  75332. for (;;) {
  75333. c$1 = peek();
  75334. // This code is unreachable.
  75335. // if (!lexStates[lexState]) {
  75336. // throw invalidLexState(lexState)
  75337. // }
  75338. const token = lexStates[lexState]();
  75339. if (token) {
  75340. return token
  75341. }
  75342. }
  75343. }
  75344. function peek () {
  75345. if (source[pos]) {
  75346. return String.fromCodePoint(source.codePointAt(pos))
  75347. }
  75348. }
  75349. function read () {
  75350. const c = peek();
  75351. if (c === '\n') {
  75352. line++;
  75353. column = 0;
  75354. } else if (c) {
  75355. column += c.length;
  75356. } else {
  75357. column++;
  75358. }
  75359. if (c) {
  75360. pos += c.length;
  75361. }
  75362. return c
  75363. }
  75364. const lexStates = {
  75365. default () {
  75366. switch (c$1) {
  75367. case '\t':
  75368. case '\v':
  75369. case '\f':
  75370. case ' ':
  75371. case '\u00A0':
  75372. case '\uFEFF':
  75373. case '\n':
  75374. case '\r':
  75375. case '\u2028':
  75376. case '\u2029':
  75377. read();
  75378. return
  75379. case '/':
  75380. read();
  75381. lexState = 'comment';
  75382. return
  75383. case undefined:
  75384. read();
  75385. return newToken('eof')
  75386. }
  75387. if (util.isSpaceSeparator(c$1)) {
  75388. read();
  75389. return
  75390. }
  75391. // This code is unreachable.
  75392. // if (!lexStates[parseState]) {
  75393. // throw invalidLexState(parseState)
  75394. // }
  75395. return lexStates[parseState]()
  75396. },
  75397. comment () {
  75398. switch (c$1) {
  75399. case '*':
  75400. read();
  75401. lexState = 'multiLineComment';
  75402. return
  75403. case '/':
  75404. read();
  75405. lexState = 'singleLineComment';
  75406. return
  75407. }
  75408. throw invalidChar(read())
  75409. },
  75410. multiLineComment () {
  75411. switch (c$1) {
  75412. case '*':
  75413. read();
  75414. lexState = 'multiLineCommentAsterisk';
  75415. return
  75416. case undefined:
  75417. throw invalidChar(read())
  75418. }
  75419. read();
  75420. },
  75421. multiLineCommentAsterisk () {
  75422. switch (c$1) {
  75423. case '*':
  75424. read();
  75425. return
  75426. case '/':
  75427. read();
  75428. lexState = 'default';
  75429. return
  75430. case undefined:
  75431. throw invalidChar(read())
  75432. }
  75433. read();
  75434. lexState = 'multiLineComment';
  75435. },
  75436. singleLineComment () {
  75437. switch (c$1) {
  75438. case '\n':
  75439. case '\r':
  75440. case '\u2028':
  75441. case '\u2029':
  75442. read();
  75443. lexState = 'default';
  75444. return
  75445. case undefined:
  75446. read();
  75447. return newToken('eof')
  75448. }
  75449. read();
  75450. },
  75451. value () {
  75452. switch (c$1) {
  75453. case '{':
  75454. case '[':
  75455. return newToken('punctuator', read())
  75456. case 'n':
  75457. read();
  75458. literal('ull');
  75459. return newToken('null', null)
  75460. case 't':
  75461. read();
  75462. literal('rue');
  75463. return newToken('boolean', true)
  75464. case 'f':
  75465. read();
  75466. literal('alse');
  75467. return newToken('boolean', false)
  75468. case '-':
  75469. case '+':
  75470. if (read() === '-') {
  75471. sign$1 = -1;
  75472. }
  75473. lexState = 'sign';
  75474. return
  75475. case '.':
  75476. buffer = read();
  75477. lexState = 'decimalPointLeading';
  75478. return
  75479. case '0':
  75480. buffer = read();
  75481. lexState = 'zero';
  75482. return
  75483. case '1':
  75484. case '2':
  75485. case '3':
  75486. case '4':
  75487. case '5':
  75488. case '6':
  75489. case '7':
  75490. case '8':
  75491. case '9':
  75492. buffer = read();
  75493. lexState = 'decimalInteger';
  75494. return
  75495. case 'I':
  75496. read();
  75497. literal('nfinity');
  75498. return newToken('numeric', Infinity)
  75499. case 'N':
  75500. read();
  75501. literal('aN');
  75502. return newToken('numeric', NaN)
  75503. case '"':
  75504. case "'":
  75505. doubleQuote = (read() === '"');
  75506. buffer = '';
  75507. lexState = 'string';
  75508. return
  75509. }
  75510. throw invalidChar(read())
  75511. },
  75512. identifierNameStartEscape () {
  75513. if (c$1 !== 'u') {
  75514. throw invalidChar(read())
  75515. }
  75516. read();
  75517. const u = unicodeEscape();
  75518. switch (u) {
  75519. case '$':
  75520. case '_':
  75521. break
  75522. default:
  75523. if (!util.isIdStartChar(u)) {
  75524. throw invalidIdentifier()
  75525. }
  75526. break
  75527. }
  75528. buffer += u;
  75529. lexState = 'identifierName';
  75530. },
  75531. identifierName () {
  75532. switch (c$1) {
  75533. case '$':
  75534. case '_':
  75535. case '\u200C':
  75536. case '\u200D':
  75537. buffer += read();
  75538. return
  75539. case '\\':
  75540. read();
  75541. lexState = 'identifierNameEscape';
  75542. return
  75543. }
  75544. if (util.isIdContinueChar(c$1)) {
  75545. buffer += read();
  75546. return
  75547. }
  75548. return newToken('identifier', buffer)
  75549. },
  75550. identifierNameEscape () {
  75551. if (c$1 !== 'u') {
  75552. throw invalidChar(read())
  75553. }
  75554. read();
  75555. const u = unicodeEscape();
  75556. switch (u) {
  75557. case '$':
  75558. case '_':
  75559. case '\u200C':
  75560. case '\u200D':
  75561. break
  75562. default:
  75563. if (!util.isIdContinueChar(u)) {
  75564. throw invalidIdentifier()
  75565. }
  75566. break
  75567. }
  75568. buffer += u;
  75569. lexState = 'identifierName';
  75570. },
  75571. sign () {
  75572. switch (c$1) {
  75573. case '.':
  75574. buffer = read();
  75575. lexState = 'decimalPointLeading';
  75576. return
  75577. case '0':
  75578. buffer = read();
  75579. lexState = 'zero';
  75580. return
  75581. case '1':
  75582. case '2':
  75583. case '3':
  75584. case '4':
  75585. case '5':
  75586. case '6':
  75587. case '7':
  75588. case '8':
  75589. case '9':
  75590. buffer = read();
  75591. lexState = 'decimalInteger';
  75592. return
  75593. case 'I':
  75594. read();
  75595. literal('nfinity');
  75596. return newToken('numeric', sign$1 * Infinity)
  75597. case 'N':
  75598. read();
  75599. literal('aN');
  75600. return newToken('numeric', NaN)
  75601. }
  75602. throw invalidChar(read())
  75603. },
  75604. zero () {
  75605. switch (c$1) {
  75606. case '.':
  75607. buffer += read();
  75608. lexState = 'decimalPoint';
  75609. return
  75610. case 'e':
  75611. case 'E':
  75612. buffer += read();
  75613. lexState = 'decimalExponent';
  75614. return
  75615. case 'x':
  75616. case 'X':
  75617. buffer += read();
  75618. lexState = 'hexadecimal';
  75619. return
  75620. }
  75621. return newToken('numeric', sign$1 * 0)
  75622. },
  75623. decimalInteger () {
  75624. switch (c$1) {
  75625. case '.':
  75626. buffer += read();
  75627. lexState = 'decimalPoint';
  75628. return
  75629. case 'e':
  75630. case 'E':
  75631. buffer += read();
  75632. lexState = 'decimalExponent';
  75633. return
  75634. }
  75635. if (util.isDigit(c$1)) {
  75636. buffer += read();
  75637. return
  75638. }
  75639. return newToken('numeric', sign$1 * Number(buffer))
  75640. },
  75641. decimalPointLeading () {
  75642. if (util.isDigit(c$1)) {
  75643. buffer += read();
  75644. lexState = 'decimalFraction';
  75645. return
  75646. }
  75647. throw invalidChar(read())
  75648. },
  75649. decimalPoint () {
  75650. switch (c$1) {
  75651. case 'e':
  75652. case 'E':
  75653. buffer += read();
  75654. lexState = 'decimalExponent';
  75655. return
  75656. }
  75657. if (util.isDigit(c$1)) {
  75658. buffer += read();
  75659. lexState = 'decimalFraction';
  75660. return
  75661. }
  75662. return newToken('numeric', sign$1 * Number(buffer))
  75663. },
  75664. decimalFraction () {
  75665. switch (c$1) {
  75666. case 'e':
  75667. case 'E':
  75668. buffer += read();
  75669. lexState = 'decimalExponent';
  75670. return
  75671. }
  75672. if (util.isDigit(c$1)) {
  75673. buffer += read();
  75674. return
  75675. }
  75676. return newToken('numeric', sign$1 * Number(buffer))
  75677. },
  75678. decimalExponent () {
  75679. switch (c$1) {
  75680. case '+':
  75681. case '-':
  75682. buffer += read();
  75683. lexState = 'decimalExponentSign';
  75684. return
  75685. }
  75686. if (util.isDigit(c$1)) {
  75687. buffer += read();
  75688. lexState = 'decimalExponentInteger';
  75689. return
  75690. }
  75691. throw invalidChar(read())
  75692. },
  75693. decimalExponentSign () {
  75694. if (util.isDigit(c$1)) {
  75695. buffer += read();
  75696. lexState = 'decimalExponentInteger';
  75697. return
  75698. }
  75699. throw invalidChar(read())
  75700. },
  75701. decimalExponentInteger () {
  75702. if (util.isDigit(c$1)) {
  75703. buffer += read();
  75704. return
  75705. }
  75706. return newToken('numeric', sign$1 * Number(buffer))
  75707. },
  75708. hexadecimal () {
  75709. if (util.isHexDigit(c$1)) {
  75710. buffer += read();
  75711. lexState = 'hexadecimalInteger';
  75712. return
  75713. }
  75714. throw invalidChar(read())
  75715. },
  75716. hexadecimalInteger () {
  75717. if (util.isHexDigit(c$1)) {
  75718. buffer += read();
  75719. return
  75720. }
  75721. return newToken('numeric', sign$1 * Number(buffer))
  75722. },
  75723. string () {
  75724. switch (c$1) {
  75725. case '\\':
  75726. read();
  75727. buffer += escape$1();
  75728. return
  75729. case '"':
  75730. if (doubleQuote) {
  75731. read();
  75732. return newToken('string', buffer)
  75733. }
  75734. buffer += read();
  75735. return
  75736. case "'":
  75737. if (!doubleQuote) {
  75738. read();
  75739. return newToken('string', buffer)
  75740. }
  75741. buffer += read();
  75742. return
  75743. case '\n':
  75744. case '\r':
  75745. throw invalidChar(read())
  75746. case '\u2028':
  75747. case '\u2029':
  75748. separatorChar(c$1);
  75749. break
  75750. case undefined:
  75751. throw invalidChar(read())
  75752. }
  75753. buffer += read();
  75754. },
  75755. start () {
  75756. switch (c$1) {
  75757. case '{':
  75758. case '[':
  75759. return newToken('punctuator', read())
  75760. // This code is unreachable since the default lexState handles eof.
  75761. // case undefined:
  75762. // return newToken('eof')
  75763. }
  75764. lexState = 'value';
  75765. },
  75766. beforePropertyName () {
  75767. switch (c$1) {
  75768. case '$':
  75769. case '_':
  75770. buffer = read();
  75771. lexState = 'identifierName';
  75772. return
  75773. case '\\':
  75774. read();
  75775. lexState = 'identifierNameStartEscape';
  75776. return
  75777. case '}':
  75778. return newToken('punctuator', read())
  75779. case '"':
  75780. case "'":
  75781. doubleQuote = (read() === '"');
  75782. lexState = 'string';
  75783. return
  75784. }
  75785. if (util.isIdStartChar(c$1)) {
  75786. buffer += read();
  75787. lexState = 'identifierName';
  75788. return
  75789. }
  75790. throw invalidChar(read())
  75791. },
  75792. afterPropertyName () {
  75793. if (c$1 === ':') {
  75794. return newToken('punctuator', read())
  75795. }
  75796. throw invalidChar(read())
  75797. },
  75798. beforePropertyValue () {
  75799. lexState = 'value';
  75800. },
  75801. afterPropertyValue () {
  75802. switch (c$1) {
  75803. case ',':
  75804. case '}':
  75805. return newToken('punctuator', read())
  75806. }
  75807. throw invalidChar(read())
  75808. },
  75809. beforeArrayValue () {
  75810. if (c$1 === ']') {
  75811. return newToken('punctuator', read())
  75812. }
  75813. lexState = 'value';
  75814. },
  75815. afterArrayValue () {
  75816. switch (c$1) {
  75817. case ',':
  75818. case ']':
  75819. return newToken('punctuator', read())
  75820. }
  75821. throw invalidChar(read())
  75822. },
  75823. end () {
  75824. // This code is unreachable since it's handled by the default lexState.
  75825. // if (c === undefined) {
  75826. // read()
  75827. // return newToken('eof')
  75828. // }
  75829. throw invalidChar(read())
  75830. },
  75831. };
  75832. function newToken (type, value) {
  75833. return {
  75834. type,
  75835. value,
  75836. line,
  75837. column,
  75838. }
  75839. }
  75840. function literal (s) {
  75841. for (const c of s) {
  75842. const p = peek();
  75843. if (p !== c) {
  75844. throw invalidChar(read())
  75845. }
  75846. read();
  75847. }
  75848. }
  75849. function escape$1 () {
  75850. const c = peek();
  75851. switch (c) {
  75852. case 'b':
  75853. read();
  75854. return '\b'
  75855. case 'f':
  75856. read();
  75857. return '\f'
  75858. case 'n':
  75859. read();
  75860. return '\n'
  75861. case 'r':
  75862. read();
  75863. return '\r'
  75864. case 't':
  75865. read();
  75866. return '\t'
  75867. case 'v':
  75868. read();
  75869. return '\v'
  75870. case '0':
  75871. read();
  75872. if (util.isDigit(peek())) {
  75873. throw invalidChar(read())
  75874. }
  75875. return '\0'
  75876. case 'x':
  75877. read();
  75878. return hexEscape()
  75879. case 'u':
  75880. read();
  75881. return unicodeEscape()
  75882. case '\n':
  75883. case '\u2028':
  75884. case '\u2029':
  75885. read();
  75886. return ''
  75887. case '\r':
  75888. read();
  75889. if (peek() === '\n') {
  75890. read();
  75891. }
  75892. return ''
  75893. case '1':
  75894. case '2':
  75895. case '3':
  75896. case '4':
  75897. case '5':
  75898. case '6':
  75899. case '7':
  75900. case '8':
  75901. case '9':
  75902. throw invalidChar(read())
  75903. case undefined:
  75904. throw invalidChar(read())
  75905. }
  75906. return read()
  75907. }
  75908. function hexEscape () {
  75909. let buffer = '';
  75910. let c = peek();
  75911. if (!util.isHexDigit(c)) {
  75912. throw invalidChar(read())
  75913. }
  75914. buffer += read();
  75915. c = peek();
  75916. if (!util.isHexDigit(c)) {
  75917. throw invalidChar(read())
  75918. }
  75919. buffer += read();
  75920. return String.fromCodePoint(parseInt(buffer, 16))
  75921. }
  75922. function unicodeEscape () {
  75923. let buffer = '';
  75924. let count = 4;
  75925. while (count-- > 0) {
  75926. const c = peek();
  75927. if (!util.isHexDigit(c)) {
  75928. throw invalidChar(read())
  75929. }
  75930. buffer += read();
  75931. }
  75932. return String.fromCodePoint(parseInt(buffer, 16))
  75933. }
  75934. const parseStates = {
  75935. start () {
  75936. if (token.type === 'eof') {
  75937. throw invalidEOF()
  75938. }
  75939. push();
  75940. },
  75941. beforePropertyName () {
  75942. switch (token.type) {
  75943. case 'identifier':
  75944. case 'string':
  75945. key = token.value;
  75946. parseState = 'afterPropertyName';
  75947. return
  75948. case 'punctuator':
  75949. // This code is unreachable since it's handled by the lexState.
  75950. // if (token.value !== '}') {
  75951. // throw invalidToken()
  75952. // }
  75953. pop();
  75954. return
  75955. case 'eof':
  75956. throw invalidEOF()
  75957. }
  75958. // This code is unreachable since it's handled by the lexState.
  75959. // throw invalidToken()
  75960. },
  75961. afterPropertyName () {
  75962. // This code is unreachable since it's handled by the lexState.
  75963. // if (token.type !== 'punctuator' || token.value !== ':') {
  75964. // throw invalidToken()
  75965. // }
  75966. if (token.type === 'eof') {
  75967. throw invalidEOF()
  75968. }
  75969. parseState = 'beforePropertyValue';
  75970. },
  75971. beforePropertyValue () {
  75972. if (token.type === 'eof') {
  75973. throw invalidEOF()
  75974. }
  75975. push();
  75976. },
  75977. beforeArrayValue () {
  75978. if (token.type === 'eof') {
  75979. throw invalidEOF()
  75980. }
  75981. if (token.type === 'punctuator' && token.value === ']') {
  75982. pop();
  75983. return
  75984. }
  75985. push();
  75986. },
  75987. afterPropertyValue () {
  75988. // This code is unreachable since it's handled by the lexState.
  75989. // if (token.type !== 'punctuator') {
  75990. // throw invalidToken()
  75991. // }
  75992. if (token.type === 'eof') {
  75993. throw invalidEOF()
  75994. }
  75995. switch (token.value) {
  75996. case ',':
  75997. parseState = 'beforePropertyName';
  75998. return
  75999. case '}':
  76000. pop();
  76001. }
  76002. // This code is unreachable since it's handled by the lexState.
  76003. // throw invalidToken()
  76004. },
  76005. afterArrayValue () {
  76006. // This code is unreachable since it's handled by the lexState.
  76007. // if (token.type !== 'punctuator') {
  76008. // throw invalidToken()
  76009. // }
  76010. if (token.type === 'eof') {
  76011. throw invalidEOF()
  76012. }
  76013. switch (token.value) {
  76014. case ',':
  76015. parseState = 'beforeArrayValue';
  76016. return
  76017. case ']':
  76018. pop();
  76019. }
  76020. // This code is unreachable since it's handled by the lexState.
  76021. // throw invalidToken()
  76022. },
  76023. end () {
  76024. // This code is unreachable since it's handled by the lexState.
  76025. // if (token.type !== 'eof') {
  76026. // throw invalidToken()
  76027. // }
  76028. },
  76029. };
  76030. function push () {
  76031. let value;
  76032. switch (token.type) {
  76033. case 'punctuator':
  76034. switch (token.value) {
  76035. case '{':
  76036. value = {};
  76037. break
  76038. case '[':
  76039. value = [];
  76040. break
  76041. }
  76042. break
  76043. case 'null':
  76044. case 'boolean':
  76045. case 'numeric':
  76046. case 'string':
  76047. value = token.value;
  76048. break
  76049. // This code is unreachable.
  76050. // default:
  76051. // throw invalidToken()
  76052. }
  76053. if (root === undefined) {
  76054. root = value;
  76055. } else {
  76056. const parent = stack$1[stack$1.length - 1];
  76057. if (Array.isArray(parent)) {
  76058. parent.push(value);
  76059. } else {
  76060. parent[key] = value;
  76061. }
  76062. }
  76063. if (value !== null && typeof value === 'object') {
  76064. stack$1.push(value);
  76065. if (Array.isArray(value)) {
  76066. parseState = 'beforeArrayValue';
  76067. } else {
  76068. parseState = 'beforePropertyName';
  76069. }
  76070. } else {
  76071. const current = stack$1[stack$1.length - 1];
  76072. if (current == null) {
  76073. parseState = 'end';
  76074. } else if (Array.isArray(current)) {
  76075. parseState = 'afterArrayValue';
  76076. } else {
  76077. parseState = 'afterPropertyValue';
  76078. }
  76079. }
  76080. }
  76081. function pop () {
  76082. stack$1.pop();
  76083. const current = stack$1[stack$1.length - 1];
  76084. if (current == null) {
  76085. parseState = 'end';
  76086. } else if (Array.isArray(current)) {
  76087. parseState = 'afterArrayValue';
  76088. } else {
  76089. parseState = 'afterPropertyValue';
  76090. }
  76091. }
  76092. // This code is unreachable.
  76093. // function invalidParseState () {
  76094. // return new Error(`JSON5: invalid parse state '${parseState}'`)
  76095. // }
  76096. // This code is unreachable.
  76097. // function invalidLexState (state) {
  76098. // return new Error(`JSON5: invalid lex state '${state}'`)
  76099. // }
  76100. function invalidChar (c) {
  76101. if (c === undefined) {
  76102. return syntaxError(`JSON5: invalid end of input at ${line}:${column}`)
  76103. }
  76104. return syntaxError(`JSON5: invalid character '${formatChar(c)}' at ${line}:${column}`)
  76105. }
  76106. function invalidEOF () {
  76107. return syntaxError(`JSON5: invalid end of input at ${line}:${column}`)
  76108. }
  76109. // This code is unreachable.
  76110. // function invalidToken () {
  76111. // if (token.type === 'eof') {
  76112. // return syntaxError(`JSON5: invalid end of input at ${line}:${column}`)
  76113. // }
  76114. // const c = String.fromCodePoint(token.value.codePointAt(0))
  76115. // return syntaxError(`JSON5: invalid character '${formatChar(c)}' at ${line}:${column}`)
  76116. // }
  76117. function invalidIdentifier () {
  76118. column -= 5;
  76119. return syntaxError(`JSON5: invalid identifier character at ${line}:${column}`)
  76120. }
  76121. function separatorChar (c) {
  76122. console.warn(`JSON5: '${formatChar(c)}' in strings is not valid ECMAScript; consider escaping`);
  76123. }
  76124. function formatChar (c) {
  76125. const replacements = {
  76126. "'": "\\'",
  76127. '"': '\\"',
  76128. '\\': '\\\\',
  76129. '\b': '\\b',
  76130. '\f': '\\f',
  76131. '\n': '\\n',
  76132. '\r': '\\r',
  76133. '\t': '\\t',
  76134. '\v': '\\v',
  76135. '\0': '\\0',
  76136. '\u2028': '\\u2028',
  76137. '\u2029': '\\u2029',
  76138. };
  76139. if (replacements[c]) {
  76140. return replacements[c]
  76141. }
  76142. if (c < ' ') {
  76143. const hexString = c.charCodeAt(0).toString(16);
  76144. return '\\x' + ('00' + hexString).substring(hexString.length)
  76145. }
  76146. return c
  76147. }
  76148. function syntaxError (message) {
  76149. const err = new SyntaxError(message);
  76150. err.lineNumber = line;
  76151. err.columnNumber = column;
  76152. return err
  76153. }
  76154. var stringify = function stringify (value, replacer, space) {
  76155. const stack = [];
  76156. let indent = '';
  76157. let propertyList;
  76158. let replacerFunc;
  76159. let gap = '';
  76160. let quote;
  76161. if (
  76162. replacer != null &&
  76163. typeof replacer === 'object' &&
  76164. !Array.isArray(replacer)
  76165. ) {
  76166. space = replacer.space;
  76167. quote = replacer.quote;
  76168. replacer = replacer.replacer;
  76169. }
  76170. if (typeof replacer === 'function') {
  76171. replacerFunc = replacer;
  76172. } else if (Array.isArray(replacer)) {
  76173. propertyList = [];
  76174. for (const v of replacer) {
  76175. let item;
  76176. if (typeof v === 'string') {
  76177. item = v;
  76178. } else if (
  76179. typeof v === 'number' ||
  76180. v instanceof String ||
  76181. v instanceof Number
  76182. ) {
  76183. item = String(v);
  76184. }
  76185. if (item !== undefined && propertyList.indexOf(item) < 0) {
  76186. propertyList.push(item);
  76187. }
  76188. }
  76189. }
  76190. if (space instanceof Number) {
  76191. space = Number(space);
  76192. } else if (space instanceof String) {
  76193. space = String(space);
  76194. }
  76195. if (typeof space === 'number') {
  76196. if (space > 0) {
  76197. space = Math.min(10, Math.floor(space));
  76198. gap = ' '.substr(0, space);
  76199. }
  76200. } else if (typeof space === 'string') {
  76201. gap = space.substr(0, 10);
  76202. }
  76203. return serializeProperty('', {'': value})
  76204. function serializeProperty (key, holder) {
  76205. let value = holder[key];
  76206. if (value != null) {
  76207. if (typeof value.toJSON5 === 'function') {
  76208. value = value.toJSON5(key);
  76209. } else if (typeof value.toJSON === 'function') {
  76210. value = value.toJSON(key);
  76211. }
  76212. }
  76213. if (replacerFunc) {
  76214. value = replacerFunc.call(holder, key, value);
  76215. }
  76216. if (value instanceof Number) {
  76217. value = Number(value);
  76218. } else if (value instanceof String) {
  76219. value = String(value);
  76220. } else if (value instanceof Boolean) {
  76221. value = value.valueOf();
  76222. }
  76223. switch (value) {
  76224. case null: return 'null'
  76225. case true: return 'true'
  76226. case false: return 'false'
  76227. }
  76228. if (typeof value === 'string') {
  76229. return quoteString(value, false)
  76230. }
  76231. if (typeof value === 'number') {
  76232. return String(value)
  76233. }
  76234. if (typeof value === 'object') {
  76235. return Array.isArray(value) ? serializeArray(value) : serializeObject(value)
  76236. }
  76237. return undefined
  76238. }
  76239. function quoteString (value) {
  76240. const quotes = {
  76241. "'": 0.1,
  76242. '"': 0.2,
  76243. };
  76244. const replacements = {
  76245. "'": "\\'",
  76246. '"': '\\"',
  76247. '\\': '\\\\',
  76248. '\b': '\\b',
  76249. '\f': '\\f',
  76250. '\n': '\\n',
  76251. '\r': '\\r',
  76252. '\t': '\\t',
  76253. '\v': '\\v',
  76254. '\0': '\\0',
  76255. '\u2028': '\\u2028',
  76256. '\u2029': '\\u2029',
  76257. };
  76258. let product = '';
  76259. for (let i = 0; i < value.length; i++) {
  76260. const c = value[i];
  76261. switch (c) {
  76262. case "'":
  76263. case '"':
  76264. quotes[c]++;
  76265. product += c;
  76266. continue
  76267. case '\0':
  76268. if (util.isDigit(value[i + 1])) {
  76269. product += '\\x00';
  76270. continue
  76271. }
  76272. }
  76273. if (replacements[c]) {
  76274. product += replacements[c];
  76275. continue
  76276. }
  76277. if (c < ' ') {
  76278. let hexString = c.charCodeAt(0).toString(16);
  76279. product += '\\x' + ('00' + hexString).substring(hexString.length);
  76280. continue
  76281. }
  76282. product += c;
  76283. }
  76284. const quoteChar = quote || Object.keys(quotes).reduce((a, b) => (quotes[a] < quotes[b]) ? a : b);
  76285. product = product.replace(new RegExp(quoteChar, 'g'), replacements[quoteChar]);
  76286. return quoteChar + product + quoteChar
  76287. }
  76288. function serializeObject (value) {
  76289. if (stack.indexOf(value) >= 0) {
  76290. throw TypeError('Converting circular structure to JSON5')
  76291. }
  76292. stack.push(value);
  76293. let stepback = indent;
  76294. indent = indent + gap;
  76295. let keys = propertyList || Object.keys(value);
  76296. let partial = [];
  76297. for (const key of keys) {
  76298. const propertyString = serializeProperty(key, value);
  76299. if (propertyString !== undefined) {
  76300. let member = serializeKey(key) + ':';
  76301. if (gap !== '') {
  76302. member += ' ';
  76303. }
  76304. member += propertyString;
  76305. partial.push(member);
  76306. }
  76307. }
  76308. let final;
  76309. if (partial.length === 0) {
  76310. final = '{}';
  76311. } else {
  76312. let properties;
  76313. if (gap === '') {
  76314. properties = partial.join(',');
  76315. final = '{' + properties + '}';
  76316. } else {
  76317. let separator = ',\n' + indent;
  76318. properties = partial.join(separator);
  76319. final = '{\n' + indent + properties + ',\n' + stepback + '}';
  76320. }
  76321. }
  76322. stack.pop();
  76323. indent = stepback;
  76324. return final
  76325. }
  76326. function serializeKey (key) {
  76327. if (key.length === 0) {
  76328. return quoteString(key, true)
  76329. }
  76330. const firstChar = String.fromCodePoint(key.codePointAt(0));
  76331. if (!util.isIdStartChar(firstChar)) {
  76332. return quoteString(key, true)
  76333. }
  76334. for (let i = firstChar.length; i < key.length; i++) {
  76335. if (!util.isIdContinueChar(String.fromCodePoint(key.codePointAt(i)))) {
  76336. return quoteString(key, true)
  76337. }
  76338. }
  76339. return key
  76340. }
  76341. function serializeArray (value) {
  76342. if (stack.indexOf(value) >= 0) {
  76343. throw TypeError('Converting circular structure to JSON5')
  76344. }
  76345. stack.push(value);
  76346. let stepback = indent;
  76347. indent = indent + gap;
  76348. let partial = [];
  76349. for (let i = 0; i < value.length; i++) {
  76350. const propertyString = serializeProperty(String(i), value);
  76351. partial.push((propertyString !== undefined) ? propertyString : 'null');
  76352. }
  76353. let final;
  76354. if (partial.length === 0) {
  76355. final = '[]';
  76356. } else {
  76357. if (gap === '') {
  76358. let properties = partial.join(',');
  76359. final = '[' + properties + ']';
  76360. } else {
  76361. let separator = ',\n' + indent;
  76362. let properties = partial.join(separator);
  76363. final = '[\n' + indent + properties + ',\n' + stepback + ']';
  76364. }
  76365. }
  76366. stack.pop();
  76367. indent = stepback;
  76368. return final
  76369. }
  76370. };
  76371. const JSON5$1 = {
  76372. parse,
  76373. stringify,
  76374. };
  76375. var lib = JSON5$1;
  76376. class Sidebar{
  76377. constructor(viewer){
  76378. this.viewer = viewer;
  76379. this.measuringTool = viewer.measuringTool;
  76380. this.profileTool = viewer.profileTool;
  76381. this.volumeTool = viewer.volumeTool;
  76382. this.dom = $("#sidebar_root");
  76383. }
  76384. createToolIcon(icon, title, callback){
  76385. let element = $(`
  76386. <img src="${icon}"
  76387. style="width: 32px; height: 32px"
  76388. class="button-icon"
  76389. data-i18n="${title}" />
  76390. `);
  76391. element.click(callback);
  76392. return element;
  76393. }
  76394. init(){
  76395. if(Potree.settings.editType == 'merge'){
  76396. this.initMergeBar();
  76397. this.initToolbar();
  76398. this.initScene();
  76399. this.initNavigation();
  76400. }else {
  76401. this.initAccordion();
  76402. this.initAppearance();
  76403. this.initToolbar();
  76404. this.initScene();
  76405. this.initNavigation();
  76406. this.initFilters();
  76407. //this.initClippingTool(); //因为修改了clipping,所以这项有bug不能使用
  76408. this.initSettings();
  76409. if(Potree.settings.editType != 'pano'){
  76410. this.initAlignment();
  76411. this.initClipModel();
  76412. this.initSiteModel();
  76413. this.initParitcle();
  76414. this.initClippingModel();
  76415. }else {
  76416. this.initPanosEdit();
  76417. }
  76418. }
  76419. $('#potree_version_number').html(Potree.version.major + "." + Potree.version.minor + Potree.version.suffix);
  76420. }
  76421. initAlignment(){
  76422. let Alignment = viewer.modules.Alignment;
  76423. var pannel = $('#alignment');
  76424. var buttons = pannel.find('[name="transform"] button');
  76425. var applyToPointcloud = (fun, value)=>{
  76426. return function(){
  76427. var selected = $('#alignment li[name="selectPointCloud"] input:checked' );
  76428. Array.from(selected).forEach(e=>{
  76429. var pointcloud = viewer.scene.pointclouds.find(p=>p.name == e.name);
  76430. fun(pointcloud, value);
  76431. });
  76432. }
  76433. };
  76434. //逆时针是正数
  76435. buttons.eq(0).on('click', applyToPointcloud(Alignment.rotate, 10));
  76436. //viewer.scene.pointclouds[0].rotation.z += THREE.Math.degToRad(10)
  76437. buttons.eq(1).on('click' ,applyToPointcloud(Alignment.rotate, 1));
  76438. buttons.eq(2).on('click', applyToPointcloud(Alignment.rotate, 0.1));
  76439. buttons.eq(3).on('click', applyToPointcloud(Alignment.rotate, -10));
  76440. buttons.eq(4).on('click',applyToPointcloud(Alignment.rotate, -1));
  76441. buttons.eq(5).on('click',applyToPointcloud(Alignment.rotate, -0.1));
  76442. buttons.eq(6).on('click', applyToPointcloud(Alignment.translate, new Vector3(-1,0,0)));
  76443. buttons.eq(7).on('click', applyToPointcloud(Alignment.translate, new Vector3(1,0,0)));
  76444. buttons.eq(8).on('click', applyToPointcloud(Alignment.translate, new Vector3(0,-1,0)));
  76445. buttons.eq(9).on('click', applyToPointcloud(Alignment.translate, new Vector3(0,1,0)));
  76446. buttons.eq(10).on('click', applyToPointcloud(Alignment.translate, new Vector3(0,0,-1)));
  76447. buttons.eq(11).on('click', applyToPointcloud(Alignment.translate, new Vector3(0,0,1)));
  76448. pannel.find('#startAlignment').on('click', ()=>{
  76449. Alignment.enter();
  76450. });
  76451. pannel.find('#exitAlignment').on('click', ()=>{
  76452. Alignment.save();
  76453. Alignment.leave();
  76454. });
  76455. pannel.find('#rotTool').on('click', ()=>{
  76456. Alignment.switchHandle('rotate');
  76457. });
  76458. pannel.find('#moveTool').on('click', ()=>{
  76459. Alignment.switchHandle('translate');
  76460. });
  76461. }
  76462. initMergeBar(){//多元融合模块
  76463. var pannel = $('#mergeModel');
  76464. var buttons = pannel.find('button');
  76465. let MergeEditor = viewer.modules.MergeEditor;
  76466. let loading = false;
  76467. pannel.find('ul[name="model"] li button').on('click',(e)=>{
  76468. if(loading)return console.log('还在加载', loading)
  76469. let $elem = $(e.target);
  76470. let parent = $elem.parent();
  76471. let name = parent.attr('name');
  76472. if($elem.attr('name') == 'select'){
  76473. return Potree.selectModel(name)
  76474. }
  76475. if($elem.text() == '添加'){
  76476. let startTime = Date.now();
  76477. Potree.addModel(name,()=>{
  76478. loading = false;
  76479. //$elem.text('删除')
  76480. let now = Date.now();
  76481. console.log('加载完毕', name, '用时', (now-startTime)/1000, 's');
  76482. });
  76483. loading = name;
  76484. }else {
  76485. Potree.removeModel(name);
  76486. $elem.text('添加');
  76487. }
  76488. });
  76489. pannel.find('li button[name="splitScreen"]').on('click',(e)=>{
  76490. let $elem = $(e.target);
  76491. if($elem.text() == '分屏'){
  76492. $elem.text('恢复');
  76493. MergeEditor.enterSplit();
  76494. }else {
  76495. $elem.text('分屏');
  76496. MergeEditor.leaveSplit();
  76497. }
  76498. });
  76499. let addingTag = false;
  76500. pannel.find('li button[name="tag"]').on('click',(e)=>{
  76501. let $elem = $(e.target);
  76502. viewer.tagTool.startInsertion();
  76503. });
  76504. }
  76505. initClippingModel(){//实时裁剪
  76506. /* 总共两种box : 可见和不可见(都是并集)
  76507. 当有可见box时,需要在任一可见box内才可见
  76508. 当有不可见box时,不在所有不可见box内才可见 */
  76509. var clipping = viewer.modules.clipping;
  76510. var pannel = $('#clipping');
  76511. var addBtn = pannel.find('[name="operation"] button[name="add"] ');
  76512. var switchBtn = pannel.find('[name="operation"] button[name="switchView"] ');
  76513. var enterBtn = pannel.find(' button[name="enter"] ');
  76514. var exitBtn = pannel.find(' button[name="exit"] ');
  76515. let list = pannel.find('[name="list"] ul ');
  76516. enterBtn.on('click',()=>{
  76517. clipping.enter();
  76518. pannel.find('li[name=operation]').css('display','block');
  76519. pannel.find('li[name=list]').css('display','block');
  76520. });
  76521. exitBtn.on('click',()=>{
  76522. clipping.leave();
  76523. pannel.find('li[name=operation]').css('display','none');
  76524. pannel.find('li[name=list]').css('display','none');
  76525. });
  76526. switchBtn.on('click',()=>{
  76527. clipping.switchView(clipping.activeViewName == 'top' ? 'mainView' : 'top');
  76528. });
  76529. pannel.find('[name="operation"] button[name="translation"] ').on('click',()=>{
  76530. clipping.setTranMode('translation');
  76531. });
  76532. pannel.find('[name="operation"] button[name="rotation"] ').on('click',()=>{
  76533. clipping.setTranMode('rotation');
  76534. });
  76535. pannel.find('[name="operation"] button[name="scale"] ').on('click',()=>{
  76536. clipping.setTranMode('scale');
  76537. });
  76538. addBtn.on('click',()=>{
  76539. let volumeBox = this.volumeTool.startInsertion({clip: true, clipTask:Potree.ClipTask.SHOW_OUTSIDE});
  76540. let li = $("<li><button name='changeTask'>不可见</button><button name='chose'>选择</button><button name='delete'>删除</button></li>");
  76541. list.append(li);
  76542. li.find('button[name=changeTask]').on('click',(e)=>{
  76543. if(e.target.innerText == '不可见'){
  76544. volumeBox.clipTask = Potree.ClipTask.SHOW_INSIDE;
  76545. e.target.innerText = '可见';
  76546. }else {
  76547. volumeBox.clipTask = Potree.ClipTask.SHOW_OUTSIDE;
  76548. e.target.innerText = '不可见';
  76549. }
  76550. volumeBox.update();
  76551. });
  76552. li.find('button[name=chose]').on('click',(e)=>{
  76553. viewer.transformObject(volumeBox);//viewer.inputHandler.toggleSelection(volumeBox)
  76554. });
  76555. li.find('button[name=delete]').on('click',(e)=>{
  76556. li.remove();
  76557. viewer.scene.removeVolume(volumeBox);
  76558. });
  76559. });
  76560. pannel.find('button[name=save]').on('click',(e)=>{
  76561. let data = clipping.saveClipData();
  76562. });
  76563. }
  76564. addAlignmentButton(pointcloud){
  76565. var pannel = $('#alignment li[name="selectPointCloud"]>div');
  76566. var option = $(` <input name="${pointcloud.name}" class="editCheckbox" type="checkbox" >
  76567. <label for="showingLabels">${pointcloud.name}</label>`);
  76568. pannel.append(option);
  76569. /* option.find("input").on('change',function(){
  76570. })
  76571. */
  76572. }
  76573. initClipModel(){
  76574. let Clip = viewer.modules.Clip;
  76575. var pannel = $('#clipModel');
  76576. var buttons = pannel.find('button');
  76577. buttons.eq(0).on('click', Clip.enter.bind(Clip));
  76578. buttons.eq(1).on('click', Clip.download.bind(Clip));
  76579. buttons.eq(2).on('click', Clip.leave.bind(Clip));
  76580. }
  76581. initSiteModel(){
  76582. let SiteModel = viewer.modules.SiteModel;
  76583. var pannel = $('#siteModel');
  76584. pannel.find('button[name="start"] ').on('click', SiteModel.enter.bind(SiteModel));
  76585. pannel.find('button[name="exit"] ').on('click', SiteModel.leave.bind(SiteModel));
  76586. pannel.find('button[name="building"] ').on('click', SiteModel.startInsertion.bind(SiteModel,'building'));
  76587. pannel.find('button[name="floor"] ').on('click', ()=>{
  76588. SiteModel.addFloor(SiteModel.buildings[0], 'top');
  76589. } );
  76590. pannel.find('button[name="room"] ').on('click', ()=>{
  76591. SiteModel.startInsertion('room', SiteModel.buildings[0].buildChildren[0]);
  76592. });
  76593. pannel.find('button[name="digHole"] ').on('click', ()=>{
  76594. SiteModel.selected && SiteModel.startInsertion('hole', SiteModel.selected);
  76595. });
  76596. pannel.find('button[name="selectBuilding"] ').on('click', ()=>{
  76597. SiteModel.selectEntity(SiteModel.buildings[0] );
  76598. } );
  76599. pannel.find('button[name="selectFloor"] ').on('click', ()=>{
  76600. SiteModel.selectEntity(SiteModel.buildings[0].buildChildren[0]);
  76601. } );
  76602. pannel.find('button[name="selectRoom"] ').on('click', ()=>{
  76603. SiteModel.selectEntity(SiteModel.buildings[0].buildChildren[0].buildChildren[0]);
  76604. });
  76605. pannel.find('button[name="removeFirstBuilding"] ').on('click', ()=>{
  76606. SiteModel.removeEntity(SiteModel.buildings[0]);
  76607. });
  76608. pannel.find('button[name="removeFirstFloor"] ').on('click', ()=>{
  76609. SiteModel.removeEntity(SiteModel.buildings[0].buildChildren[0]);
  76610. });
  76611. pannel.find('button[name="removeFirstRoom"] ').on('click', ()=>{
  76612. SiteModel.removeEntity(SiteModel.buildings[0].buildChildren[0].buildChildren[0]);
  76613. });
  76614. pannel.find('button[name="removeFirstHole"] ').on('click', ()=>{
  76615. SiteModel.selected.removeHole(SiteModel.selected.holes[0]);
  76616. });
  76617. pannel.find('button[name="removeFirstMarker"] ').on('click', ()=>{
  76618. //SiteModel.removeMarker(SiteModel.selected.markers[0])
  76619. SiteModel.selected.removeMarker(0);
  76620. });
  76621. }
  76622. initParitcle(){
  76623. let ParticleEditor = viewer.modules.ParticleEditor;
  76624. var pannel = $('#particle');
  76625. pannel.find('button[name="addFire"] ').on('click', ()=>{
  76626. ParticleEditor.startInsertion('fire+smoke');
  76627. });
  76628. pannel.find('button[name="addExplode"] ').on('click', ()=>{
  76629. ParticleEditor.startInsertion('explode');
  76630. });
  76631. }
  76632. initPanosEdit(){
  76633. let PanoEditor = viewer.modules.PanoEditor;
  76634. let Alignment = viewer.modules.Alignment;
  76635. var pannel = $('#panos');
  76636. pannel.find('button[name="save"] ').on('click', ()=>{
  76637. console.log('saveData',PanoEditor.exportSavingData());
  76638. });
  76639. pannel.find('button[name="translate"] ').on('click', ()=>{
  76640. Alignment.switchHandle('translate');
  76641. });
  76642. pannel.find('button[name="rotate"] ').on('click', ()=>{
  76643. Alignment.switchHandle('rotate');
  76644. });
  76645. pannel.find('button[name="topView"] ').on('click', ()=>{
  76646. PanoEditor.switchView('top');
  76647. });
  76648. pannel.find('button[name="sideView"] ').on('click', ()=>{
  76649. PanoEditor.switchView('right');
  76650. });
  76651. pannel.find('button[name="3DView"] ').on('click', ()=>{
  76652. PanoEditor.switchView('mainView');
  76653. });
  76654. pannel.find('button[name="addLink"] ').on('click', ()=>{
  76655. PanoEditor.setLinkOperateState('addLink', true);
  76656. });
  76657. pannel.find('button[name="removeLink"] ').on('click', ()=>{
  76658. PanoEditor.setLinkOperateState('removeLink', true);
  76659. });
  76660. pannel.find('button[name="getCloser"] ').on('click', ()=>{
  76661. PanoEditor.setZoomInState(true);
  76662. });
  76663. }
  76664. initToolbar(){
  76665. // ANGLE
  76666. let elToolbar = $('#tools');
  76667. elToolbar.append(this.createToolIcon(
  76668. Potree.resourcePath + '/icons/angle.png',
  76669. '[title]tt.angle_measurement',
  76670. () => {
  76671. $('#menu_measurements').next().slideDown();
  76672. let measurement = this.measuringTool.startInsertion({
  76673. showDistances: false,
  76674. showAngles: true,
  76675. showArea: false,
  76676. closed: true,
  76677. maxMarkers: 3,
  76678. minMarkers:3,
  76679. measureType: 'Angle'});
  76680. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76681. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76682. $.jstree.reference(jsonNode.id).deselect_all();
  76683. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76684. }
  76685. ));
  76686. // POINT
  76687. elToolbar.append(this.createToolIcon(
  76688. Potree.resourcePath + '/icons/point.svg',
  76689. '[title]tt.point_measurement',
  76690. () => {
  76691. $('#menu_measurements').next().slideDown();
  76692. let measurement = this.measuringTool.startInsertion({
  76693. showDistances: false,
  76694. showAngles: false,
  76695. showCoordinates: true,
  76696. showEdges:false,
  76697. showArea: false,
  76698. closed: true,
  76699. maxMarkers: 1,
  76700. minMarkers:1,
  76701. measureType: 'Point'});
  76702. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76703. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76704. $.jstree.reference(jsonNode.id).deselect_all();
  76705. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76706. }
  76707. ));
  76708. // DISTANCE
  76709. elToolbar.append(this.createToolIcon(
  76710. Potree.resourcePath + '/icons/distance.svg',
  76711. '[title]tt.distance_measurement',
  76712. () => {
  76713. $('#menu_measurements').next().slideDown();
  76714. let measurement = this.measuringTool.startInsertion({
  76715. showDistances: true,
  76716. showArea: false,
  76717. closed: false,
  76718. minMarkers:2,
  76719. maxMarkers: 2,
  76720. measureType: 'Distance'
  76721. });
  76722. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76723. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76724. $.jstree.reference(jsonNode.id).deselect_all();
  76725. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76726. }
  76727. ));
  76728. // DISTANCE2
  76729. elToolbar.append(this.createToolIcon(
  76730. Potree.resourcePath + '/icons/distance.svg',
  76731. '[title]MulDistance',
  76732. () => {
  76733. $('#menu_measurements').next().slideDown();
  76734. let measurement = this.measuringTool.startInsertion({
  76735. showDistances: true,
  76736. showArea: false,
  76737. closed: false,
  76738. minMarkers:2,
  76739. measureType: 'MulDistance'
  76740. });
  76741. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76742. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76743. $.jstree.reference(jsonNode.id).deselect_all();
  76744. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76745. }
  76746. ));
  76747. // DISTANCE2
  76748. elToolbar.append(this.createToolIcon(
  76749. Potree.resourcePath + '/icons/distance.svg',
  76750. '[title]MulDistance Ring',
  76751. () => {
  76752. $('#menu_measurements').next().slideDown();
  76753. let measurement = this.measuringTool.startInsertion({
  76754. //showArea: false,
  76755. closed: true,
  76756. minMarkers:3,
  76757. measureType: 'MulDistance Ring'
  76758. });
  76759. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76760. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76761. $.jstree.reference(jsonNode.id).deselect_all();
  76762. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76763. }
  76764. ));
  76765. elToolbar.append(this.createToolIcon(
  76766. Potree.resourcePath + '/icons/distance.svg',
  76767. '[title]Ver MulDistance',
  76768. () => {
  76769. $('#menu_measurements').next().slideDown();
  76770. let measurement = this.measuringTool.startInsertion({
  76771. measureType: 'Ver MulDistance'
  76772. });
  76773. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76774. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76775. $.jstree.reference(jsonNode.id).deselect_all();
  76776. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76777. }
  76778. ));
  76779. elToolbar.append(this.createToolIcon(
  76780. Potree.resourcePath + '/icons/distance.svg',
  76781. '[title]Hor MulDistance',
  76782. () => {
  76783. $('#menu_measurements').next().slideDown();
  76784. let measurement = this.measuringTool.startInsertion({
  76785. measureType: 'Hor MulDistance'
  76786. });
  76787. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76788. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76789. $.jstree.reference(jsonNode.id).deselect_all();
  76790. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76791. }
  76792. ));
  76793. // HEIGHT
  76794. elToolbar.append(this.createToolIcon(
  76795. Potree.resourcePath + '/icons/height.svg',
  76796. '[title]tt.height_measurement',
  76797. () => {
  76798. $('#menu_measurements').next().slideDown();
  76799. let measurement = this.measuringTool.startInsertion({
  76800. showDistances: true,//false,
  76801. showHeight: true,
  76802. showArea: false,
  76803. closed: false,
  76804. maxMarkers: 2,
  76805. minMarkers:2,
  76806. //showGuideLine: true: true
  76807. measureType: 'Ver Distance',
  76808. });
  76809. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76810. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76811. $.jstree.reference(jsonNode.id).deselect_all();
  76812. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76813. }
  76814. ));
  76815. // CIRCLE
  76816. elToolbar.append(this.createToolIcon(
  76817. Potree.resourcePath + '/icons/circle.svg',
  76818. '[title]tt.circle_measurement',
  76819. () => {
  76820. $('#menu_measurements').next().slideDown();
  76821. let measurement = this.measuringTool.startInsertion({
  76822. showDistances: false,
  76823. showHeight: false,
  76824. showArea: false,
  76825. showCircle: true,
  76826. showEdges: false,
  76827. closed: false,
  76828. maxMarkers: 3,
  76829. minMarkers:3,
  76830. measureType: 'Circle'
  76831. });
  76832. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76833. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76834. $.jstree.reference(jsonNode.id).deselect_all();
  76835. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76836. }
  76837. ));
  76838. // AZIMUTH
  76839. elToolbar.append(this.createToolIcon(
  76840. Potree.resourcePath + '/icons/azimuth.svg',
  76841. 'Azimuth',
  76842. () => {
  76843. $('#menu_measurements').next().slideDown();
  76844. let measurement = this.measuringTool.startInsertion({
  76845. showDistances: false,
  76846. showHeight: false,
  76847. showArea: false,
  76848. showCircle: false,
  76849. showEdges: false,
  76850. showAzimuth: true,
  76851. closed: false,
  76852. maxMarkers: 2,
  76853. minMarkers:2,
  76854. measureType: 'Azimuth'});
  76855. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76856. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76857. $.jstree.reference(jsonNode.id).deselect_all();
  76858. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76859. }
  76860. ));
  76861. // AREA
  76862. elToolbar.append(this.createToolIcon(
  76863. Potree.resourcePath + '/icons/area.svg',
  76864. '[title]tt.area_measurement',
  76865. () => {
  76866. $('#menu_measurements').next().slideDown();
  76867. let measurement = this.measuringTool.startInsertion({
  76868. showDistances: true,
  76869. showArea: true,
  76870. closed: true,
  76871. minMarkers:3,
  76872. //showGuideLine: true: true,
  76873. measureType: 'Area'});
  76874. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76875. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76876. $.jstree.reference(jsonNode.id).deselect_all();
  76877. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76878. }
  76879. ));
  76880. //Hor AREA
  76881. elToolbar.append(this.createToolIcon(
  76882. Potree.resourcePath + '/icons/area.svg',
  76883. '[title]Hor Area',
  76884. () => {
  76885. $('#menu_measurements').next().slideDown();
  76886. let measurement = this.measuringTool.startInsertion({
  76887. showDistances: true,
  76888. showArea: true,
  76889. closed: true,
  76890. minMarkers:3,
  76891. measureType: 'Hor Area'});
  76892. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76893. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76894. $.jstree.reference(jsonNode.id).deselect_all();
  76895. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76896. }
  76897. ));
  76898. // Ver Area
  76899. elToolbar.append(this.createToolIcon(
  76900. Potree.resourcePath + '/icons/area.svg',
  76901. '[title]Ver Area',
  76902. () => {
  76903. $('#menu_measurements').next().slideDown();
  76904. let measurement = this.measuringTool.startInsertion({
  76905. showDistances: true,
  76906. showArea: true,
  76907. closed: true,
  76908. minMarkers:3,
  76909. measureType: 'Ver Area'});
  76910. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76911. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76912. $.jstree.reference(jsonNode.id).deselect_all();
  76913. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76914. }
  76915. ));
  76916. // rect area freedom direction
  76917. elToolbar.append(this.createToolIcon(
  76918. Potree.resourcePath + '/icons/area.svg',
  76919. '[title]area_freedom_rect',
  76920. () => {
  76921. $('#menu_measurements').next().slideDown();
  76922. let measurement = this.measuringTool.startInsertion({
  76923. showDistances: true,
  76924. showArea: true,
  76925. closed: true,
  76926. minMarkers:4,
  76927. maxMarkers:4,
  76928. //showGuideLine: true: true,
  76929. isRect:true,
  76930. measureType: 'Rect Area'});
  76931. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76932. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76933. $.jstree.reference(jsonNode.id).deselect_all();
  76934. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76935. }
  76936. ));
  76937. // rect area horizontal
  76938. elToolbar.append(this.createToolIcon(
  76939. Potree.resourcePath + '/icons/area.svg',
  76940. '[title]area_horizontal_rect',
  76941. () => {
  76942. $('#menu_measurements').next().slideDown();
  76943. let measurement = this.measuringTool.startInsertion({
  76944. showDistances: true,
  76945. showArea: true,
  76946. closed: true,
  76947. minMarkers:4,
  76948. maxMarkers:4,
  76949. //showGuideLine: true: true,
  76950. isRect:true,
  76951. faceDirection:"horizontal",
  76952. measureType: 'Hor Rect Area'});
  76953. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76954. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76955. $.jstree.reference(jsonNode.id).deselect_all();
  76956. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76957. }
  76958. ));
  76959. // rect area vertical
  76960. elToolbar.append(this.createToolIcon(
  76961. Potree.resourcePath + '/icons/area.svg',
  76962. '[title]area_vertical_rect',
  76963. () => {
  76964. $('#menu_measurements').next().slideDown();
  76965. let measurement = this.measuringTool.startInsertion({
  76966. showDistances: true,
  76967. showArea: true,
  76968. closed: true,
  76969. minMarkers:4,
  76970. maxMarkers:4,
  76971. //showGuideLine: true: true,
  76972. isRect:true,
  76973. faceDirection:"vertical",
  76974. measureType: 'Ver Rect Area'});
  76975. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76976. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76977. $.jstree.reference(jsonNode.id).deselect_all();
  76978. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76979. }
  76980. ));
  76981. // AREA
  76982. elToolbar.append(this.createToolIcon(
  76983. Potree.resourcePath + '/icons/area.svg',
  76984. '[title]prism',
  76985. () => {
  76986. $('#menu_measurements').next().slideDown();
  76987. let measurement = this.measuringTool.startInsertion({
  76988. measureType: 'MulDistance Ring', unit : 'metric'
  76989. });
  76990. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  76991. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === measurement.uuid);
  76992. $.jstree.reference(jsonNode.id).deselect_all();
  76993. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  76994. }
  76995. ));
  76996. // VOLUME
  76997. elToolbar.append(this.createToolIcon(
  76998. Potree.resourcePath + '/icons/volume.svg',
  76999. '[title]tt.volume_measurement',
  77000. () => {
  77001. let volume = this.volumeTool.startInsertion();
  77002. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77003. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === volume.uuid);
  77004. $.jstree.reference(jsonNode.id).deselect_all();
  77005. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77006. }
  77007. ));
  77008. // SPHERE VOLUME
  77009. elToolbar.append(this.createToolIcon(
  77010. Potree.resourcePath + '/icons/sphere_distances.svg',
  77011. '[title]tt.volume_measurement',
  77012. () => {
  77013. let volume = this.volumeTool.startInsertion({type: SphereVolume$2});
  77014. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77015. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === volume.uuid);
  77016. $.jstree.reference(jsonNode.id).deselect_all();
  77017. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77018. }
  77019. ));
  77020. // PROFILE
  77021. elToolbar.append(this.createToolIcon(
  77022. Potree.resourcePath + '/icons/profile.svg',
  77023. '[title]tt.height_profile',
  77024. () => {
  77025. $('#menu_measurements').next().slideDown(); ;
  77026. let profile = this.profileTool.startInsertion();
  77027. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77028. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === profile.uuid);
  77029. $.jstree.reference(jsonNode.id).deselect_all();
  77030. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77031. }
  77032. ));
  77033. // ANNOTATION
  77034. elToolbar.append(this.createToolIcon(
  77035. Potree.resourcePath + '/icons/annotation.svg',
  77036. '[title]tt.annotation',
  77037. () => {
  77038. $('#menu_measurements').next().slideDown(); ;
  77039. let annotation = this.viewer.annotationTool.startInsertion();
  77040. let annotationsRoot = $("#jstree_scene").jstree().get_json("annotations");
  77041. let jsonNode = annotationsRoot.children.find(child => child.data.uuid === annotation.uuid);
  77042. $.jstree.reference(jsonNode.id).deselect_all();
  77043. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77044. }
  77045. ));
  77046. // REMOVE ALL
  77047. elToolbar.append(this.createToolIcon(
  77048. Potree.resourcePath + '/icons/reset_tools.svg',
  77049. '[title]tt.remove_all_measurement',
  77050. () => {
  77051. this.viewer.scene.removeAllMeasurements();
  77052. }
  77053. ));
  77054. { // SHOW / HIDE Measurements
  77055. let elShow = $("#measurement_options_show");
  77056. elShow.selectgroup({title: "Show/Hide labels"});
  77057. elShow.find("input").click( (e) => {
  77058. const show = e.target.value === "SHOW";
  77059. this.measuringTool.showLabels = show;
  77060. });
  77061. let currentShow = this.measuringTool.showLabels ? "SHOW" : "HIDE";
  77062. elShow.find(`input[value=${currentShow}]`).trigger("click");
  77063. }
  77064. }
  77065. initScene(){
  77066. let elScene = $("#menu_scene");
  77067. let elObjects = elScene.next().find("#scene_objects");
  77068. let elProperties = elScene.next().find("#scene_object_properties");
  77069. {
  77070. let elExport = elScene.next().find("#scene_export");
  77071. let geoJSONIcon = `${Potree.resourcePath}/icons/file_geojson.svg`;
  77072. let dxfIcon = `${Potree.resourcePath}/icons/file_dxf.svg`;
  77073. let potreeIcon = `${Potree.resourcePath}/icons/file_potree.svg`;
  77074. elExport.append(`
  77075. Export: <br>
  77076. <a href="#" download="measure.json"><img name="geojson_export_button" src="${geoJSONIcon}" class="button-icon" style="height: 24px" /></a>
  77077. <a href="#" download="measure.dxf"><img name="dxf_export_button" src="${dxfIcon}" class="button-icon" style="height: 24px" /></a>
  77078. <a href="#" download="potree.json5"><img name="potree_export_button" src="${potreeIcon}" class="button-icon" style="height: 24px" /></a>
  77079. `);
  77080. let elDownloadJSON = elExport.find("img[name=geojson_export_button]").parent();
  77081. elDownloadJSON.click( (event) => {
  77082. let scene = this.viewer.scene;
  77083. let measurements = [...scene.measurements, ...scene.profiles, ...scene.volumes];
  77084. if(measurements.length > 0){
  77085. let geoJson = GeoJSONExporter.toString(measurements);
  77086. let url = window.URL.createObjectURL(new Blob([geoJson], {type: 'data:application/octet-stream'}));
  77087. elDownloadJSON.attr('href', url);
  77088. }else {
  77089. this.viewer.postError("nothing to export");
  77090. event.preventDefault();
  77091. }
  77092. });
  77093. let elDownloadDXF = elExport.find("img[name=dxf_export_button]").parent();
  77094. elDownloadDXF.click( (event) => {
  77095. let scene = this.viewer.scene;
  77096. let measurements = [...scene.measurements, ...scene.profiles, ...scene.volumes];
  77097. if(measurements.length > 0){
  77098. let dxf = DXFExporter.toString(measurements);
  77099. let url = window.URL.createObjectURL(new Blob([dxf], {type: 'data:application/octet-stream'}));
  77100. elDownloadDXF.attr('href', url);
  77101. }else {
  77102. this.viewer.postError("no measurements to export");
  77103. event.preventDefault();
  77104. }
  77105. });
  77106. let elDownloadPotree = elExport.find("img[name=potree_export_button]").parent();
  77107. elDownloadPotree.click( (event) => {
  77108. let data = Potree.saveProject(this.viewer);
  77109. let dataString = lib.stringify(data, null, "\t");
  77110. let url = window.URL.createObjectURL(new Blob([dataString], {type: 'data:application/octet-stream'}));
  77111. elDownloadPotree.attr('href', url);
  77112. });
  77113. }
  77114. let propertiesPanel = new PropertiesPanel(elProperties, this.viewer);
  77115. propertiesPanel.setScene(this.viewer.scene);
  77116. localStorage.removeItem('jstree');
  77117. let tree = $(`<div id="jstree_scene"></div>`);
  77118. elObjects.append(tree);
  77119. tree.jstree({
  77120. 'plugins': ["checkbox", "state"],
  77121. 'core': {
  77122. "dblclick_toggle": false,
  77123. "state": {
  77124. "checked" : true
  77125. },
  77126. 'check_callback': true,
  77127. "expand_selected_onload": true
  77128. },
  77129. "checkbox" : {
  77130. "keep_selected_style": true,
  77131. "three_state": false,
  77132. "whole_node": false,
  77133. "tie_selection": false,
  77134. },
  77135. });
  77136. let createNode = (parent, text, icon, object) => {
  77137. let nodeID = tree.jstree('create_node', parent, {
  77138. "text": text,
  77139. "icon": icon,
  77140. "data": object
  77141. },
  77142. "last", false, false);
  77143. if(object.visible){
  77144. tree.jstree('check_node', nodeID);
  77145. }else {
  77146. tree.jstree('uncheck_node', nodeID);
  77147. }
  77148. return nodeID;
  77149. };
  77150. let pcID = tree.jstree('create_node', "#", { "text": "<b>Point Clouds</b>", "id": "pointclouds"}, "last", false, false);
  77151. let measurementID = tree.jstree('create_node', "#", { "text": "<b>Measurements</b>", "id": "measurements" }, "last", false, false);
  77152. let annotationsID = tree.jstree('create_node', "#", { "text": "<b>Annotations</b>", "id": "annotations" }, "last", false, false);
  77153. let otherID = tree.jstree('create_node', "#", { "text": "<b>Other</b>", "id": "other" }, "last", false, false);
  77154. let vectorsID = tree.jstree('create_node', "#", { "text": "<b>Vectors</b>", "id": "vectors" }, "last", false, false);
  77155. let imagesID = tree.jstree('create_node', "#", { "text": "<b> Images</b>", "id": "images" }, "last", false, false);
  77156. tree.jstree("check_node", pcID);
  77157. tree.jstree("check_node", measurementID);
  77158. tree.jstree("check_node", annotationsID);
  77159. tree.jstree("check_node", otherID);
  77160. tree.jstree("check_node", vectorsID);
  77161. tree.jstree("check_node", imagesID);
  77162. tree.on('create_node.jstree', (e, data) => {
  77163. tree.jstree("open_all");
  77164. });
  77165. tree.on("select_node.jstree", (e, data) => {
  77166. let object = data.node.data;
  77167. propertiesPanel.set(object);
  77168. this.viewer.inputHandler.deselectAll();
  77169. if(object instanceof Volume$1){
  77170. this.viewer.inputHandler.toggleSelection(object);
  77171. }
  77172. $(this.viewer.renderer.domElement).focus();
  77173. });
  77174. tree.on("deselect_node.jstree", (e, data) => {
  77175. propertiesPanel.set(null);
  77176. });
  77177. tree.on("delete_node.jstree", (e, data) => {
  77178. propertiesPanel.set(null);
  77179. });
  77180. tree.on('dblclick','.jstree-anchor', (e) => {
  77181. let instance = $.jstree.reference(e.target);
  77182. let node = instance.get_node(e.target);
  77183. let object = node.data;
  77184. // ignore double click on checkbox
  77185. if(e.target.classList.contains("jstree-checkbox")){
  77186. return;
  77187. }
  77188. if(object instanceof PointCloudTree){
  77189. let box = this.viewer.getBoundingBox([object]);
  77190. let node = new Object3D();
  77191. node.boundingBox = box;
  77192. this.viewer.zoomTo(node, 1, 500);
  77193. }else if(object instanceof Measure$1){
  77194. let points = object.points.map(p => p.position);
  77195. let box = new Box3().setFromPoints(points);
  77196. if(box.getSize(new Vector3()).length() == 0){
  77197. box.min = box.max.clone();//禁止相同
  77198. box.expandByVector(new Vector3(1,1,1));
  77199. }
  77200. let node = new Object3D();
  77201. node.boundingBox = box;
  77202. this.viewer.zoomTo(node, 2, 500);
  77203. }else if(object instanceof Profile){
  77204. let points = object.points;
  77205. let box = new Box3().setFromPoints(points);
  77206. if(box.getSize(new Vector3()).length() > 0){
  77207. let node = new Object3D();
  77208. node.boundingBox = box;
  77209. this.viewer.zoomTo(node, 1, 500);
  77210. }
  77211. }else if(object instanceof Volume$1){
  77212. let box = object.boundingBox.clone().applyMatrix4(object.matrixWorld);
  77213. if(box.getSize(new Vector3()).length() > 0){
  77214. let node = new Object3D();
  77215. node.boundingBox = box;
  77216. this.viewer.zoomTo(node, 1, 500);
  77217. }
  77218. }else if(object instanceof Annotation){
  77219. object.moveHere(this.viewer.scene.getActiveCamera());
  77220. }else if(object instanceof PolygonClipVolume){
  77221. let dir = object.camera.getWorldDirection(new Vector3());
  77222. let target;
  77223. if(object.camera instanceof OrthographicCamera){
  77224. dir.multiplyScalar(object.camera.right);
  77225. target = new Vector3().addVectors(object.camera.position, dir);
  77226. this.viewer.setCameraMode(CameraMode.ORTHOGRAPHIC);
  77227. }else if(object.camera instanceof PerspectiveCamera){
  77228. dir.multiplyScalar(this.viewer.scene.view.radius);
  77229. target = new Vector3().addVectors(object.camera.position, dir);
  77230. this.viewer.setCameraMode(CameraMode.PERSPECTIVE);
  77231. }
  77232. this.viewer.scene.view.position.copy(object.camera.position);
  77233. this.viewer.scene.view.lookAt(target);
  77234. }else if(object.type === "SpotLight"){
  77235. let distance = (object.distance > 0) ? object.distance / 4 : 5 * 1000;
  77236. let position = object.position;
  77237. let target = new Vector3().addVectors(
  77238. position,
  77239. object.getWorldDirection(new Vector3()).multiplyScalar(distance));
  77240. this.viewer.scene.view.position.copy(object.position);
  77241. this.viewer.scene.view.lookAt(target);
  77242. }else if(object instanceof Object3D){
  77243. let box = new Box3().setFromObject(object);
  77244. if(box.getSize(new Vector3()).length() > 0){
  77245. let node = new Object3D();
  77246. node.boundingBox = box;
  77247. this.viewer.zoomTo(node, 1, 500);
  77248. }
  77249. }else if(object instanceof OrientedImage){
  77250. // TODO zoom to images
  77251. // let box = new THREE.Box3().setFromObject(object);
  77252. // if(box.getSize(new THREE.Vector3()).length() > 0){
  77253. // let node = new THREE.Object3D();
  77254. // node.boundingBox = box;
  77255. // this.viewer.zoomTo(node, 1, 500);
  77256. // }
  77257. }else if(object instanceof Images360){
  77258. // TODO
  77259. }else if(object instanceof Geopackage){
  77260. // TODO
  77261. }
  77262. });
  77263. tree.on("uncheck_node.jstree", (e, data) => {
  77264. let object = data.node.data;
  77265. if(object){
  77266. object.visible = false;
  77267. }
  77268. });
  77269. tree.on("check_node.jstree", (e, data) => {
  77270. let object = data.node.data;
  77271. if(object){
  77272. object.visible = true;
  77273. }
  77274. });
  77275. let onPointCloudAdded = (e) => {
  77276. let pointcloud = e.pointcloud;
  77277. let cloudIcon = `${Potree.resourcePath}/icons/cloud.svg`;
  77278. let node = createNode(pcID, pointcloud.name, cloudIcon, pointcloud);
  77279. pointcloud.addEventListener("visibility_changed", () => {
  77280. if(pointcloud.visible){
  77281. tree.jstree('check_node', node);
  77282. }else {
  77283. tree.jstree('uncheck_node', node);
  77284. }
  77285. });
  77286. };
  77287. let onMeasurementAdded = (e) => {
  77288. let measurement = e.measurement;
  77289. let icon = Utils.getMeasurementIcon(measurement);
  77290. createNode(measurementID, measurement.name, icon, measurement);
  77291. };
  77292. let onVolumeAdded = (e) => {
  77293. let volume = e.volume;
  77294. let icon = Utils.getMeasurementIcon(volume);
  77295. let node = createNode(measurementID, volume.name, icon, volume);
  77296. volume.addEventListener("visibility_changed", () => {
  77297. if(volume.visible){
  77298. tree.jstree('check_node', node);
  77299. }else {
  77300. tree.jstree('uncheck_node', node);
  77301. }
  77302. });
  77303. };
  77304. let onProfileAdded = (e) => {
  77305. let profile = e.profile;
  77306. let icon = Utils.getMeasurementIcon(profile);
  77307. createNode(measurementID, profile.name, icon, profile);
  77308. };
  77309. let onAnnotationAdded = (e) => {
  77310. let annotation = e.annotation;
  77311. let annotationIcon = `${Potree.resourcePath}/icons/annotation.svg`;
  77312. let parentID = this.annotationMapping.get(annotation.parent);
  77313. let annotationID = createNode(parentID, annotation.title, annotationIcon, annotation);
  77314. this.annotationMapping.set(annotation, annotationID);
  77315. annotation.addEventListener("annotation_changed", (e) => {
  77316. let annotationsRoot = $("#jstree_scene").jstree().get_json("annotations");
  77317. let jsonNode = annotationsRoot.children.find(child => child.data.uuid === annotation.uuid);
  77318. $.jstree.reference(jsonNode.id).rename_node(jsonNode.id, annotation.title);
  77319. });
  77320. };
  77321. let onCameraAnimationAdded = (e) => {
  77322. const animation = e.animation;
  77323. const animationIcon = `${Potree.resourcePath}/icons/camera_animation.svg`;
  77324. createNode(otherID, "animation", animationIcon, animation);
  77325. };
  77326. let onOrientedImagesAdded = (e) => {
  77327. const images = e.images;
  77328. const imagesIcon = `${Potree.resourcePath}/icons/picture.svg`;
  77329. const node = createNode(imagesID, "images", imagesIcon, images);
  77330. images.addEventListener("visibility_changed", () => {
  77331. if(images.visible){
  77332. tree.jstree('check_node', node);
  77333. }else {
  77334. tree.jstree('uncheck_node', node);
  77335. }
  77336. });
  77337. };
  77338. let onImages360Added = (e) => {
  77339. const images = e.images;
  77340. const imagesIcon = `${Potree.resourcePath}/icons/picture.svg`;
  77341. const node = createNode(imagesID, "360° images", imagesIcon, images);
  77342. images.addEventListener("visibility_changed", () => {
  77343. if(images.visible){
  77344. tree.jstree('check_node', node);
  77345. }else {
  77346. tree.jstree('uncheck_node', node);
  77347. }
  77348. });
  77349. };
  77350. const onGeopackageAdded = (e) => {
  77351. const geopackage = e.geopackage;
  77352. const geopackageIcon = `${Potree.resourcePath}/icons/triangle.svg`;
  77353. const tree = $(`#jstree_scene`);
  77354. const parentNode = "vectors";
  77355. for(const layer of geopackage.node.children){
  77356. const name = layer.name;
  77357. let shpPointsID = tree.jstree('create_node', parentNode, {
  77358. "text": name,
  77359. "icon": geopackageIcon,
  77360. "object": layer,
  77361. "data": layer,
  77362. },
  77363. "last", false, false);
  77364. tree.jstree(layer.visible ? "check_node" : "uncheck_node", shpPointsID);
  77365. }
  77366. };
  77367. this.viewer.scene.addEventListener("pointcloud_added", onPointCloudAdded);
  77368. this.viewer.scene.addEventListener("measurement_added", onMeasurementAdded);
  77369. this.viewer.scene.addEventListener("profile_added", onProfileAdded);
  77370. this.viewer.scene.addEventListener("volume_added", onVolumeAdded);
  77371. this.viewer.scene.addEventListener("camera_animation_added", onCameraAnimationAdded);
  77372. this.viewer.scene.addEventListener("oriented_images_added", onOrientedImagesAdded);
  77373. this.viewer.scene.addEventListener("360_images_added", onImages360Added);
  77374. this.viewer.scene.addEventListener("geopackage_added", onGeopackageAdded);
  77375. this.viewer.scene.addEventListener("polygon_clip_volume_added", onVolumeAdded);
  77376. this.viewer.scene.annotations.addEventListener("annotation_added", onAnnotationAdded);
  77377. let onMeasurementRemoved = (e) => {
  77378. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77379. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.measurement.uuid);
  77380. tree.jstree("delete_node", jsonNode.id);
  77381. };
  77382. let onVolumeRemoved = (e) => {
  77383. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77384. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.volume.uuid);
  77385. tree.jstree("delete_node", jsonNode.id);
  77386. };
  77387. let onPolygonClipVolumeRemoved = (e) => {
  77388. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77389. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.volume.uuid);
  77390. tree.jstree("delete_node", jsonNode.id);
  77391. };
  77392. let onProfileRemoved = (e) => {
  77393. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77394. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === e.profile.uuid);
  77395. tree.jstree("delete_node", jsonNode.id);
  77396. };
  77397. this.viewer.scene.addEventListener("measurement_removed", onMeasurementRemoved);
  77398. this.viewer.scene.addEventListener("volume_removed", onVolumeRemoved);
  77399. this.viewer.scene.addEventListener("polygon_clip_volume_removed", onPolygonClipVolumeRemoved);
  77400. this.viewer.scene.addEventListener("profile_removed", onProfileRemoved);
  77401. {
  77402. let annotationIcon = `${Potree.resourcePath}/icons/annotation.svg`;
  77403. this.annotationMapping = new Map();
  77404. this.annotationMapping.set(this.viewer.scene.annotations, annotationsID);
  77405. this.viewer.scene.annotations.traverseDescendants(annotation => {
  77406. let parentID = this.annotationMapping.get(annotation.parent);
  77407. let annotationID = createNode(parentID, annotation.title, annotationIcon, annotation);
  77408. this.annotationMapping.set(annotation, annotationID);
  77409. });
  77410. }
  77411. const scene = this.viewer.scene;
  77412. for(let pointcloud of scene.pointclouds){
  77413. onPointCloudAdded({pointcloud: pointcloud});
  77414. }
  77415. for(let measurement of scene.measurements){
  77416. onMeasurementAdded({measurement: measurement});
  77417. }
  77418. for(let volume of [...scene.volumes, ...scene.polygonClipVolumes]){
  77419. onVolumeAdded({volume: volume});
  77420. }
  77421. for(let animation of scene.cameraAnimations){
  77422. onCameraAnimationAdded({animation: animation});
  77423. }
  77424. for(let images of scene.orientedImages){
  77425. onOrientedImagesAdded({images: images});
  77426. }
  77427. for(let images of scene.images360){
  77428. onImages360Added({images: images});
  77429. }
  77430. for(const geopackage of scene.geopackages){
  77431. onGeopackageAdded({geopackage: geopackage});
  77432. }
  77433. for(let profile of scene.profiles){
  77434. onProfileAdded({profile: profile});
  77435. }
  77436. {
  77437. createNode(otherID, "Camera", null, new Camera());
  77438. }
  77439. this.viewer.addEventListener("scene_changed", (e) => {
  77440. propertiesPanel.setScene(e.scene);
  77441. e.oldScene.removeEventListener("pointcloud_added", onPointCloudAdded);
  77442. e.oldScene.removeEventListener("measurement_added", onMeasurementAdded);
  77443. e.oldScene.removeEventListener("profile_added", onProfileAdded);
  77444. e.oldScene.removeEventListener("volume_added", onVolumeAdded);
  77445. e.oldScene.removeEventListener("polygon_clip_volume_added", onVolumeAdded);
  77446. e.oldScene.removeEventListener("measurement_removed", onMeasurementRemoved);
  77447. e.scene.addEventListener("pointcloud_added", onPointCloudAdded);
  77448. e.scene.addEventListener("measurement_added", onMeasurementAdded);
  77449. e.scene.addEventListener("profile_added", onProfileAdded);
  77450. e.scene.addEventListener("volume_added", onVolumeAdded);
  77451. e.scene.addEventListener("polygon_clip_volume_added", onVolumeAdded);
  77452. e.scene.addEventListener("measurement_removed", onMeasurementRemoved);
  77453. });
  77454. }
  77455. initClippingTool(){
  77456. this.viewer.addEventListener("cliptask_changed", (event) => {
  77457. console.log("TODO");
  77458. });
  77459. this.viewer.addEventListener("clipmethod_changed", (event) => {
  77460. console.log("TODO");
  77461. });
  77462. {
  77463. let elClipTask = $("#cliptask_options");
  77464. elClipTask.selectgroup({title: "Clip Task"});
  77465. elClipTask.find("input").click( (e) => {
  77466. this.viewer.setClipTask(ClipTask[e.target.value]);
  77467. });
  77468. let currentClipTask = Object.keys(ClipTask)
  77469. .filter(key => ClipTask[key] === this.viewer.clipTask);
  77470. elClipTask.find(`input[value=${currentClipTask}]`).trigger("click");
  77471. }
  77472. {
  77473. let elClipMethod = $("#clipmethod_options");
  77474. elClipMethod.selectgroup({title: "Clip Method"});
  77475. elClipMethod.find("input").click( (e) => {
  77476. this.viewer.setClipMethod(ClipMethod[e.target.value]);
  77477. });
  77478. let currentClipMethod = Object.keys(ClipMethod)
  77479. .filter(key => ClipMethod[key] === this.viewer.clipMethod);
  77480. elClipMethod.find(`input[value=${currentClipMethod}]`).trigger("click");
  77481. }
  77482. let clippingToolBar = $("#clipping_tools");
  77483. // CLIP VOLUME
  77484. clippingToolBar.append(this.createToolIcon(
  77485. Potree.resourcePath + '/icons/clip_volume.svg',
  77486. '[title]tt.clip_volume',
  77487. () => {
  77488. let item = this.volumeTool.startInsertion({clip: true});
  77489. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77490. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid);
  77491. $.jstree.reference(jsonNode.id).deselect_all();
  77492. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77493. }
  77494. ));
  77495. // CLIP POLYGON
  77496. clippingToolBar.append(this.createToolIcon(
  77497. Potree.resourcePath + "/icons/clip-polygon.svg",
  77498. "[title]tt.clip_polygon",
  77499. () => {
  77500. let item = this.viewer.clippingTool.startInsertion({type: "polygon"});
  77501. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77502. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid);
  77503. $.jstree.reference(jsonNode.id).deselect_all();
  77504. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77505. }
  77506. ));
  77507. {// SCREEN BOX SELECT
  77508. let boxSelectTool = new ScreenBoxSelectTool(this.viewer);
  77509. clippingToolBar.append(this.createToolIcon(
  77510. Potree.resourcePath + "/icons/clip-screen.svg",
  77511. "[title]tt.screen_clip_box",
  77512. () => {
  77513. if(!(this.viewer.scene.getActiveCamera() instanceof OrthographicCamera)){
  77514. this.viewer.postMessage(`Switch to Orthographic Camera Mode before using the Screen-Box-Select tool.`,
  77515. {duration: 2000});
  77516. return;
  77517. }
  77518. let item = boxSelectTool.startInsertion();
  77519. let measurementsRoot = $("#jstree_scene").jstree().get_json("measurements");
  77520. let jsonNode = measurementsRoot.children.find(child => child.data.uuid === item.uuid);
  77521. $.jstree.reference(jsonNode.id).deselect_all();
  77522. $.jstree.reference(jsonNode.id).select_node(jsonNode.id);
  77523. }
  77524. ));
  77525. }
  77526. { // REMOVE CLIPPING TOOLS
  77527. clippingToolBar.append(this.createToolIcon(
  77528. Potree.resourcePath + "/icons/remove.svg",
  77529. "[title]tt.remove_all_clipping_volumes",
  77530. () => {
  77531. this.viewer.scene.removeAllClipVolumes();
  77532. }
  77533. ));
  77534. }
  77535. }
  77536. initFilters(){
  77537. this.initClassificationList();
  77538. this.initReturnFilters();
  77539. this.initGPSTimeFilters();
  77540. this.initPointSourceIDFilters();
  77541. }
  77542. initReturnFilters(){
  77543. let elReturnFilterPanel = $('#return_filter_panel');
  77544. { // RETURN NUMBER
  77545. let sldReturnNumber = elReturnFilterPanel.find('#sldReturnNumber');
  77546. let lblReturnNumber = elReturnFilterPanel.find('#lblReturnNumber');
  77547. sldReturnNumber.slider({
  77548. range: true,
  77549. min: 0, max: 7, step: 1,
  77550. values: [0, 7],
  77551. slide: (event, ui) => {
  77552. this.viewer.setFilterReturnNumberRange(ui.values[0], ui.values[1]);
  77553. }
  77554. });
  77555. let onReturnNumberChanged = (event) => {
  77556. let [from, to] = this.viewer.filterReturnNumberRange;
  77557. lblReturnNumber[0].innerHTML = `${from} to ${to}`;
  77558. sldReturnNumber.slider({values: [from, to]});
  77559. };
  77560. this.viewer.addEventListener('filter_return_number_range_changed', onReturnNumberChanged);
  77561. onReturnNumberChanged();
  77562. }
  77563. { // NUMBER OF RETURNS
  77564. let sldNumberOfReturns = elReturnFilterPanel.find('#sldNumberOfReturns');
  77565. let lblNumberOfReturns = elReturnFilterPanel.find('#lblNumberOfReturns');
  77566. sldNumberOfReturns.slider({
  77567. range: true,
  77568. min: 0, max: 7, step: 1,
  77569. values: [0, 7],
  77570. slide: (event, ui) => {
  77571. this.viewer.setFilterNumberOfReturnsRange(ui.values[0], ui.values[1]);
  77572. }
  77573. });
  77574. let onNumberOfReturnsChanged = (event) => {
  77575. let [from, to] = this.viewer.filterNumberOfReturnsRange;
  77576. lblNumberOfReturns[0].innerHTML = `${from} to ${to}`;
  77577. sldNumberOfReturns.slider({values: [from, to]});
  77578. };
  77579. this.viewer.addEventListener('filter_number_of_returns_range_changed', onNumberOfReturnsChanged);
  77580. onNumberOfReturnsChanged();
  77581. }
  77582. }
  77583. initGPSTimeFilters(){
  77584. let elGPSTimeFilterPanel = $('#gpstime_filter_panel');
  77585. {
  77586. let slider = new HierarchicalSlider({
  77587. levels: 4,
  77588. slide: (event) => {
  77589. this.viewer.setFilterGPSTimeRange(...event.values);
  77590. },
  77591. });
  77592. let initialized = false;
  77593. let initialize = () => {
  77594. let elRangeContainer = $("#gpstime_multilevel_range_container");
  77595. elRangeContainer[0].prepend(slider.element);
  77596. let extent = this.viewer.getGpsTimeExtent();
  77597. slider.setRange(extent);
  77598. slider.setValues(extent);
  77599. initialized = true;
  77600. };
  77601. this.viewer.addEventListener("update", (e) => {
  77602. let extent = this.viewer.getGpsTimeExtent();
  77603. let gpsTimeAvailable = extent[0] !== Infinity;
  77604. if(!initialized && gpsTimeAvailable){
  77605. initialize();
  77606. }
  77607. slider.setRange(extent); //高耗cpu
  77608. });
  77609. }
  77610. {
  77611. const txtGpsTime = elGPSTimeFilterPanel.find("#txtGpsTime");
  77612. const btnFindGpsTime = elGPSTimeFilterPanel.find("#btnFindGpsTime");
  77613. let targetTime = null;
  77614. txtGpsTime.on("input", (e) => {
  77615. const str = txtGpsTime.val();
  77616. if(!isNaN(str)){
  77617. const value = parseFloat(str);
  77618. targetTime = value;
  77619. txtGpsTime.css("background-color", "");
  77620. }else {
  77621. targetTime = null;
  77622. txtGpsTime.css("background-color", "#ff9999");
  77623. }
  77624. });
  77625. btnFindGpsTime.click( () => {
  77626. if(targetTime !== null){
  77627. viewer.moveToGpsTimeVicinity(targetTime);
  77628. }
  77629. });
  77630. }
  77631. }
  77632. initPointSourceIDFilters() {
  77633. let elPointSourceIDFilterPanel = $('#pointsourceid_filter_panel');
  77634. {
  77635. let slider = new HierarchicalSlider({
  77636. levels: 4,
  77637. range: [0, 65535],
  77638. precision: 1,
  77639. slide: (event) => {
  77640. let values = event.values;
  77641. this.viewer.setFilterPointSourceIDRange(values[0], values[1]);
  77642. }
  77643. });
  77644. let initialized = false;
  77645. let initialize = () => {
  77646. elPointSourceIDFilterPanel[0].prepend(slider.element);
  77647. initialized = true;
  77648. };
  77649. this.viewer.addEventListener("update", (e) => {
  77650. let extent = this.viewer.filterPointSourceIDRange;
  77651. if(!initialized){
  77652. initialize();
  77653. slider.setValues(extent);
  77654. }
  77655. });
  77656. }
  77657. // let lblPointSourceID = elPointSourceIDFilterPanel.find("#lblPointSourceID");
  77658. // let elPointSourceID = elPointSourceIDFilterPanel.find("#spnPointSourceID");
  77659. // let slider = new ZoomableSlider();
  77660. // elPointSourceID[0].appendChild(slider.element);
  77661. // slider.update();
  77662. // slider.change( () => {
  77663. // let range = slider.chosenRange;
  77664. // this.viewer.setFilterPointSourceIDRange(range[0], range[1]);
  77665. // });
  77666. // let onPointSourceIDExtentChanged = (event) => {
  77667. // let range = this.viewer.filterPointSourceIDExtent;
  77668. // slider.setVisibleRange(range);
  77669. // };
  77670. // let onPointSourceIDChanged = (event) => {
  77671. // let range = this.viewer.filterPointSourceIDRange;
  77672. // let precision = 1;
  77673. // let from = `${Utils.addCommas(range[0].toFixed(precision))}`;
  77674. // let to = `${Utils.addCommas(range[1].toFixed(precision))}`;
  77675. // lblPointSourceID[0].innerHTML = `${from} to ${to}`;
  77676. // slider.setRange(range);
  77677. // };
  77678. // this.viewer.addEventListener('filter_point_source_id_range_changed', onPointSourceIDChanged);
  77679. // this.viewer.addEventListener('filter_point_source_id_extent_changed', onPointSourceIDExtentChanged);
  77680. }
  77681. initClassificationList(){
  77682. let elClassificationList = $('#classificationList');
  77683. let addClassificationItem = (code, name) => {
  77684. const classification = this.viewer.classifications[code];
  77685. const inputID = 'chkClassification_' + code;
  77686. const colorPickerID = 'colorPickerClassification_' + code;
  77687. const checked = classification.visible ? "checked" : "";
  77688. let element = $(`
  77689. <li>
  77690. <label style="whitespace: nowrap; display: flex">
  77691. <input id="${inputID}" type="checkbox" ${checked}/>
  77692. <span style="flex-grow: 1">${name}</span>
  77693. <input id="${colorPickerID}" style="zoom: 0.5" />
  77694. </label>
  77695. </li>
  77696. `);
  77697. const elInput = element.find('input');
  77698. const elColorPicker = element.find(`#${colorPickerID}`);
  77699. elInput.click(event => {
  77700. this.viewer.setClassificationVisibility(code, event.target.checked);
  77701. });
  77702. let defaultColor = classification.color.map(c => c * 255).join(", ");
  77703. defaultColor = `rgb(${defaultColor})`;
  77704. elColorPicker.spectrum({
  77705. // flat: true,
  77706. color: defaultColor,
  77707. showInput: true,
  77708. preferredFormat: 'rgb',
  77709. cancelText: '',
  77710. chooseText: 'Apply',
  77711. move: color => {
  77712. let rgb = color.toRgb();
  77713. const c = [rgb.r / 255, rgb.g / 255, rgb.b / 255, 1];
  77714. classification.color = c;
  77715. },
  77716. change: color => {
  77717. let rgb = color.toRgb();
  77718. const c = [rgb.r / 255, rgb.g / 255, rgb.b / 255, 1];
  77719. classification.color = c;
  77720. }
  77721. });
  77722. elClassificationList.append(element);
  77723. };
  77724. const addToggleAllButton = () => { // toggle all button
  77725. const element = $(`
  77726. <li>
  77727. <label style="whitespace: nowrap">
  77728. <input id="toggleClassificationFilters" type="checkbox" checked/>
  77729. <span>show/hide all</span>
  77730. </label>
  77731. </li>
  77732. `);
  77733. let elInput = element.find('input');
  77734. elInput.click(event => {
  77735. this.viewer.toggleAllClassificationsVisibility();
  77736. });
  77737. elClassificationList.append(element);
  77738. };
  77739. const addInvertButton = () => {
  77740. const element = $(`
  77741. <li>
  77742. <input type="button" value="invert" />
  77743. </li>
  77744. `);
  77745. let elInput = element.find('input');
  77746. elInput.click( () => {
  77747. const classifications = this.viewer.classifications;
  77748. for(let key of Object.keys(classifications)){
  77749. let value = classifications[key];
  77750. this.viewer.setClassificationVisibility(key, !value.visible);
  77751. }
  77752. });
  77753. elClassificationList.append(element);
  77754. };
  77755. const populate = () => {
  77756. addToggleAllButton();
  77757. for (let classID in this.viewer.classifications) {
  77758. addClassificationItem(classID, this.viewer.classifications[classID].name);
  77759. }
  77760. addInvertButton();
  77761. };
  77762. populate();
  77763. this.viewer.addEventListener("classifications_changed", () => {
  77764. elClassificationList.empty();
  77765. populate();
  77766. });
  77767. this.viewer.addEventListener("classification_visibility_changed", () => {
  77768. { // set checked state of classification buttons
  77769. for(const classID of Object.keys(this.viewer.classifications)){
  77770. const classValue = this.viewer.classifications[classID];
  77771. let elItem = elClassificationList.find(`#chkClassification_${classID}`);
  77772. elItem.prop("checked", classValue.visible);
  77773. }
  77774. }
  77775. { // set checked state of toggle button based on state of all other buttons
  77776. let numVisible = 0;
  77777. let numItems = 0;
  77778. for(const key of Object.keys(this.viewer.classifications)){
  77779. if(this.viewer.classifications[key].visible){
  77780. numVisible++;
  77781. }
  77782. numItems++;
  77783. }
  77784. const allVisible = numVisible === numItems;
  77785. let elToggle = elClassificationList.find("#toggleClassificationFilters");
  77786. elToggle.prop("checked", allVisible);
  77787. }
  77788. });
  77789. }
  77790. initAccordion(){
  77791. $('.accordion > h3').each(function(){
  77792. let header = $(this);
  77793. let content = $(this).next();
  77794. //header.addClass('accordion-header ui-widget');
  77795. //content.addClass('accordion-content ui-widget');
  77796. content.hide();
  77797. header.click(() => {
  77798. content.slideToggle();
  77799. });
  77800. });
  77801. let languages = [
  77802. ["EN", "en"],
  77803. ["FR", "fr"],
  77804. ["DE", "de"],
  77805. ["JP", "jp"],
  77806. ["ES", "es"],
  77807. ["SE", "se"],
  77808. ["ZH", "zh"]
  77809. ];
  77810. let elLanguages = $('#potree_languages');
  77811. for(let i = 0; i < languages.length; i++){
  77812. let [key, value] = languages[i];
  77813. let element = $(`<a>${key}</a>`);
  77814. element.click(() => this.viewer.setLanguage(value));
  77815. if(i === 0){
  77816. element.css("margin-left", "30px");
  77817. }
  77818. elLanguages.append(element);
  77819. if(i < languages.length - 1){
  77820. elLanguages.append($(document.createTextNode(' - ')));
  77821. }
  77822. }
  77823. // to close all, call
  77824. // $(".accordion > div").hide()
  77825. // to open the, for example, tool menu, call:
  77826. // $("#menu_tools").next().show()
  77827. }
  77828. initAppearance(){
  77829. const sldPointBudget = this.dom.find('#sldPointBudget');
  77830. sldPointBudget.slider({
  77831. value: this.viewer.getPointBudget(),
  77832. min: 100 * 1000,
  77833. max: 10 * 1000 * 1000,
  77834. step: 1000,
  77835. slide: (event, ui) => { this.viewer.setPointBudget(ui.value); }
  77836. });
  77837. this.dom.find('#sldFOV').slider({
  77838. value: this.viewer.getFOV(),
  77839. min: 20,
  77840. max: 100,
  77841. step: 1,
  77842. slide: (event, ui) => { this.viewer.setFOV(ui.value); }
  77843. });
  77844. $('#sldEDLRadius').slider({
  77845. value: this.viewer.getEDLRadius(),
  77846. min: 1,
  77847. max: 4,
  77848. step: 0.01,
  77849. slide: (event, ui) => { this.viewer.setEDLRadius(ui.value); }
  77850. });
  77851. $('#sldEDLStrength').slider({
  77852. value: this.viewer.getEDLStrength(),
  77853. min: 0,
  77854. max: 5,
  77855. step: 0.01,
  77856. slide: (event, ui) => { this.viewer.setEDLStrength(ui.value); }
  77857. });
  77858. $('#sldEDLOpacity').slider({
  77859. value: this.viewer.getEDLOpacity(),
  77860. min: 0,
  77861. max: 1,
  77862. step: 0.01,
  77863. slide: (event, ui) => { this.viewer.setEDLOpacity(ui.value); }
  77864. });
  77865. this.viewer.addEventListener('point_budget_changed', (event) => {
  77866. $('#lblPointBudget')[0].innerHTML = Utils.addCommas(this.viewer.getPointBudget());
  77867. sldPointBudget.slider({value: this.viewer.getPointBudget()});
  77868. });
  77869. this.viewer.addEventListener('fov_changed', (event) => {
  77870. $('#lblFOV')[0].innerHTML = parseInt(this.viewer.getFOV());
  77871. $('#sldFOV').slider({value: this.viewer.getFOV()});
  77872. });
  77873. this.viewer.addEventListener('use_edl_changed', (event) => {
  77874. $('#chkEDLEnabled')[0].checked = this.viewer.getEDLEnabled();
  77875. });
  77876. this.viewer.addEventListener('edl_radius_changed', (event) => {
  77877. $('#lblEDLRadius')[0].innerHTML = this.viewer.getEDLRadius().toFixed(1);
  77878. $('#sldEDLRadius').slider({value: this.viewer.getEDLRadius()});
  77879. });
  77880. this.viewer.addEventListener('edl_strength_changed', (event) => {
  77881. $('#lblEDLStrength')[0].innerHTML = this.viewer.getEDLStrength().toFixed(1);
  77882. $('#sldEDLStrength').slider({value: this.viewer.getEDLStrength()});
  77883. });
  77884. this.viewer.addEventListener('background_changed', (event) => {
  77885. $("input[name=background][value='" + this.viewer.getBackground() + "']").prop('checked', true);
  77886. });
  77887. $('#lblPointBudget')[0].innerHTML = Utils.addCommas(this.viewer.getPointBudget());
  77888. $('#lblFOV')[0].innerHTML = parseInt(this.viewer.getFOV());
  77889. $('#lblEDLRadius')[0].innerHTML = this.viewer.getEDLRadius().toFixed(1);
  77890. $('#lblEDLStrength')[0].innerHTML = this.viewer.getEDLStrength().toFixed(1);
  77891. $('#chkEDLEnabled')[0].checked = this.viewer.getEDLEnabled();
  77892. {
  77893. let elBackground = $(`#background_options`);
  77894. elBackground.selectgroup();
  77895. elBackground.find("input").click( (e) => {
  77896. this.viewer.setBackground(e.target.value);
  77897. });
  77898. let currentBackground = this.viewer.getBackground();
  77899. try{
  77900. $(`input[name=background_options][value=${currentBackground}]`).trigger("click");
  77901. }catch(e){}
  77902. }
  77903. $('#chkEDLEnabled').click( () => {
  77904. this.viewer.setEDLEnabled($('#chkEDLEnabled').prop("checked"));
  77905. });
  77906. }
  77907. initNavigation(){
  77908. let elNavigation = $('#navigation');
  77909. let sldMoveSpeed = $('#sldMoveSpeed');
  77910. let lblMoveSpeed = $('#lblMoveSpeed');
  77911. elNavigation.append(this.createToolIcon(
  77912. Potree.resourcePath + '/icons/earth_controls_1.png',
  77913. '[title]tt.earth_control',
  77914. () => { this.viewer.setControls(this.viewer.earthControls); }
  77915. ));
  77916. elNavigation.append(this.createToolIcon(
  77917. Potree.resourcePath + '/icons/fps_controls.svg',
  77918. '[title]tt.flight_control',
  77919. () => {
  77920. this.viewer.setControls(this.viewer.fpControls);
  77921. this.viewer.fpControls.lockElevation = false;
  77922. }
  77923. ));
  77924. elNavigation.append(this.createToolIcon(
  77925. Potree.resourcePath + '/icons/helicopter_controls.svg',
  77926. '[title]tt.heli_control',
  77927. () => {
  77928. this.viewer.setControls(this.viewer.fpControls);
  77929. this.viewer.fpControls.lockElevation = true;
  77930. }
  77931. ));
  77932. elNavigation.append(this.createToolIcon(
  77933. Potree.resourcePath + '/icons/orbit_controls.svg',
  77934. '[title]tt.orbit_control',
  77935. () => { this.viewer.setControls(this.viewer.orbitControls); }
  77936. ));
  77937. elNavigation.append(this.createToolIcon(
  77938. Potree.resourcePath + '/icons/focus.svg',
  77939. '[title]tt.focus_control',
  77940. () => { this.viewer.fitToScreen(); }
  77941. ));
  77942. elNavigation.append(this.createToolIcon(
  77943. Potree.resourcePath + "/icons/navigation_cube.svg",
  77944. "[title]tt.navigation_cube_control",
  77945. () => {this.viewer.toggleNavigationCube();}
  77946. ));
  77947. elNavigation.append(this.createToolIcon(
  77948. Potree.resourcePath + "/images/compas.svg",
  77949. "[title]tt.compass",
  77950. () => {
  77951. const visible = !this.viewer.compass.isVisible();
  77952. this.viewer.compass.setVisible(visible);
  77953. }
  77954. ));
  77955. elNavigation.append(this.createToolIcon(
  77956. Potree.resourcePath + "/icons/camera_animation.svg",
  77957. "[title]tt.camera_animation",
  77958. () => {
  77959. const animation = CameraAnimation$1.defaultFromView(this.viewer);
  77960. viewer.scene.addCameraAnimation(animation);
  77961. }
  77962. ));
  77963. elNavigation.append("<br>");
  77964. elNavigation.append(this.createToolIcon(
  77965. Potree.resourcePath + "/icons/left.svg",
  77966. "[title]tt.left_view_control",
  77967. () => {this.viewer.setLeftView();}
  77968. ));
  77969. elNavigation.append(this.createToolIcon(
  77970. Potree.resourcePath + "/icons/right.svg",
  77971. "[title]tt.right_view_control",
  77972. () => {this.viewer.setRightView();}
  77973. ));
  77974. elNavigation.append(this.createToolIcon(
  77975. Potree.resourcePath + "/icons/front.svg",
  77976. "[title]tt.front_view_control",
  77977. () => {this.viewer.setFrontView();}
  77978. ));
  77979. elNavigation.append(this.createToolIcon(
  77980. Potree.resourcePath + "/icons/back.svg",
  77981. "[title]tt.back_view_control",
  77982. () => {this.viewer.setBackView();}
  77983. ));
  77984. elNavigation.append(this.createToolIcon(
  77985. Potree.resourcePath + "/icons/top.svg",
  77986. "[title]tt.top_view_control",
  77987. () => {this.viewer.setTopView();}
  77988. ));
  77989. elNavigation.append(this.createToolIcon(
  77990. Potree.resourcePath + "/icons/bottom.svg",
  77991. "[title]tt.bottom_view_control",
  77992. () => {this.viewer.setBottomView();}
  77993. ));
  77994. let elCameraProjection = $(`
  77995. <selectgroup id="camera_projection_options">
  77996. <option id="camera_projection_options_perspective" value="PERSPECTIVE">Perspective</option>
  77997. <option id="camera_projection_options_orthigraphic" value="ORTHOGRAPHIC">Orthographic</option>
  77998. </selectgroup>
  77999. `);
  78000. elNavigation.append(elCameraProjection);
  78001. elCameraProjection.selectgroup({title: "Camera Projection"});
  78002. elCameraProjection.find("input").click( (e) => {
  78003. this.viewer.setCameraMode(CameraMode[e.target.value]);
  78004. });
  78005. let cameraMode = Object.keys(CameraMode)
  78006. .filter(key => CameraMode[key] === this.viewer.scene.cameraMode);
  78007. elCameraProjection.find(`input[value=${cameraMode}]`).trigger("click");
  78008. let speedRange = new Vector2(1, 10 * 1000);
  78009. let toLinearSpeed = (value) => {
  78010. return Math.pow(value, 4) * speedRange.y + speedRange.x;
  78011. };
  78012. let toExpSpeed = (value) => {
  78013. return Math.pow((value - speedRange.x) / speedRange.y, 1 / 4);
  78014. };
  78015. sldMoveSpeed.slider({
  78016. value: toExpSpeed(this.viewer.getMoveSpeed()),
  78017. min: 0,
  78018. max: 1,
  78019. step: 0.01,
  78020. slide: (event, ui) => { this.viewer.setMoveSpeed(toLinearSpeed(ui.value)); }
  78021. });
  78022. this.viewer.addEventListener('move_speed_changed', (event) => {
  78023. lblMoveSpeed.html(this.viewer.getMoveSpeed().toFixed(1));
  78024. sldMoveSpeed.slider({value: toExpSpeed(this.viewer.getMoveSpeed())});
  78025. });
  78026. lblMoveSpeed.html(this.viewer.getMoveSpeed().toFixed(1));
  78027. }
  78028. initSettings(){
  78029. {
  78030. $('#sldMinNodeSize').slider({
  78031. value: this.viewer.getMinNodeSize(),
  78032. min: 0,
  78033. max: 1000,
  78034. step: 0.01,
  78035. slide: (event, ui) => { this.viewer.setMinNodeSize(ui.value); }
  78036. });
  78037. this.viewer.addEventListener('minnodesize_changed', (event) => {
  78038. $('#lblMinNodeSize').html(parseInt(this.viewer.getMinNodeSize()));
  78039. $('#sldMinNodeSize').slider({value: this.viewer.getMinNodeSize()});
  78040. });
  78041. $('#lblMinNodeSize').html(parseInt(this.viewer.getMinNodeSize()));
  78042. }
  78043. {
  78044. let elSplatQuality = $("#splat_quality_options");
  78045. elSplatQuality.selectgroup({title: "Splat Quality"});
  78046. elSplatQuality.find("input").click( (e) => {
  78047. if(e.target.value === "standard"){
  78048. this.viewer.useHQ = false;
  78049. }else if(e.target.value === "hq"){
  78050. this.viewer.useHQ = true;
  78051. }
  78052. });
  78053. let currentQuality = this.viewer.useHQ ? "hq" : "standard";
  78054. elSplatQuality.find(`input[value=${currentQuality}]`).trigger("click");
  78055. }
  78056. $('#show_bounding_box').click(() => {
  78057. this.viewer.setShowBoundingBox($('#show_bounding_box').prop("checked"));
  78058. });
  78059. $('#set_freeze').click(() => {
  78060. this.viewer.setFreeze($('#set_freeze').prop("checked"));
  78061. });
  78062. }
  78063. }
  78064. class AnnotationTool extends EventDispatcher$1{
  78065. constructor (viewer) {
  78066. super();
  78067. this.viewer = viewer;
  78068. this.renderer = viewer.renderer;
  78069. this.sg = new SphereGeometry(0.1);
  78070. this.sm = new MeshNormalMaterial();
  78071. this.s = new Mesh(this.sg, this.sm);
  78072. }
  78073. startInsertion (args = {}) {
  78074. let domElement = this.viewer.renderer.domElement;
  78075. let annotation = new Annotation({
  78076. position: [589748.270, 231444.540, 753.675],
  78077. title: "Annotation Title",
  78078. description: `Annotation Description`
  78079. });
  78080. this.dispatchEvent({type: 'start_inserting_annotation', annotation: annotation});
  78081. const annotations = this.viewer.scene.annotations;
  78082. annotations.add(annotation);
  78083. let callbacks = {
  78084. cancel: null,
  78085. finish: null,
  78086. };
  78087. let insertionCallback = (e) => {
  78088. if (e.button === MOUSE.LEFT) {
  78089. callbacks.finish();
  78090. } else if (e.button === MOUSE.RIGHT) {
  78091. callbacks.cancel();
  78092. }
  78093. };
  78094. callbacks.cancel = e => {
  78095. annotations.remove(annotation);
  78096. domElement.removeEventListener('mouseup', insertionCallback, true);
  78097. };
  78098. callbacks.finish = e => {
  78099. domElement.removeEventListener('mouseup', insertionCallback, true);
  78100. };
  78101. domElement.addEventListener('mouseup', insertionCallback, true);
  78102. let drag = (e) => {
  78103. let I = Utils.getMousePointCloudIntersection(
  78104. e.drag.end,
  78105. e.viewer.scene.getActiveCamera(),
  78106. e.viewer,
  78107. e.viewer.scene.pointclouds,
  78108. {pickClipped: true});
  78109. if (I) {
  78110. this.s.position.copy(I.location);
  78111. annotation.position.copy(I.location);
  78112. }
  78113. };
  78114. let drop = (e) => {
  78115. viewer.scene.scene.remove(this.s);
  78116. this.s.removeEventListener("drag", drag);
  78117. this.s.removeEventListener("drop", drop);
  78118. };
  78119. this.s.addEventListener('drag', drag);
  78120. this.s.addEventListener('drop', drop);
  78121. this.viewer.scene.scene.add(this.s);
  78122. this.viewer.inputHandler.startDragging(this.s);
  78123. return annotation;
  78124. }
  78125. update(){
  78126. // let camera = this.viewer.scene.getActiveCamera();
  78127. // let domElement = this.renderer.domElement;
  78128. // let measurements = this.viewer.scene.measurements;
  78129. // const renderAreaSize = this.renderer.getSize(new THREE.Vector2());
  78130. // let clientWidth = renderAreaSize.width;
  78131. // let clientHeight = renderAreaSize.height;
  78132. }
  78133. render(){
  78134. //this.viewer.renderer.render(this.scene, this.viewer.scene.getActiveCamera());
  78135. }
  78136. };
  78137. //处理cursor优先级
  78138. var CursorDeal = {
  78139. priorityEvent : [//在前面的优先级高
  78140. {'zoomInCloud':'zoom-in'},
  78141. {'hoverPano':'pointer'},
  78142. {'connectPano':`url({Potree.resourcePath}/images/connect.png),auto`},
  78143. {'disconnectPano':`url({Potree.resourcePath}/images/connect-dis.png),auto`},
  78144. {'hoverLine':'pointer'},
  78145. {'hoverTranHandle':'grab'},
  78146. {"movePointcloud":'move'},
  78147. {"polygon_isIntersectSelf":'not-allowed'},
  78148. {"polygon_AtWrongPlace":'not-allowed'},
  78149. {'delPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_sub.png"), auto'},
  78150. {"markerMove":'grab'},
  78151. {'addPoint':'url("https://4dkk.4dage.com/v4-test/www/sdk/images/polygon_mark/pic_pen_add.png"), auto'},
  78152. {'mapClipMove':'move'},
  78153. {'mapClipRotate':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  78154. {'rotatePointcloud':`url({Potree.resourcePath}/images/rotate-cursor.png),auto`},
  78155. {'siteModelFloorDrag':'row-resize'},
  78156. {'addSth':'cell'},//or crosshair
  78157. ],
  78158. list:[], //当前存在的cursor状态
  78159. currentCursorIndex:null,
  78160. init : function(viewer, viewers){
  78161. this.priorityEvent.forEach(e=>{//刚开始Potree.resourcePath没值,现在换
  78162. for(let i in e){
  78163. e[i] = Common.replaceAll(e[i],'{Potree.resourcePath}',Potree.resourcePath);
  78164. }
  78165. });
  78166. this.domElements = viewers.map(e=>e.renderArea);
  78167. viewer.addEventListener("CursorChange",(e)=>{
  78168. if(e.action == 'add'){
  78169. this.add(e.name);
  78170. }else {
  78171. this.remove(e.name);
  78172. }
  78173. });
  78174. },
  78175. add : function(name){
  78176. var priorityItem = this.priorityEvent.find(e=>e[name]);
  78177. if(!priorityItem){
  78178. console.error('CursorDeal 未定义优先级 name:'+ name);
  78179. return
  78180. }
  78181. if(!this.list.includes(name)){
  78182. this.judge({addItem: priorityItem, name});
  78183. this.list.push(name);
  78184. }
  78185. },
  78186. remove : function(name){
  78187. var index = this.list.indexOf(name);
  78188. if(index > -1){
  78189. this.list.splice(index, 1);
  78190. this.judge();
  78191. }
  78192. },
  78193. judge:function(o={}){
  78194. //console.log(o,this.list)
  78195. if(o.addItem){
  78196. var addIndex = this.priorityEvent.indexOf(o.addItem);
  78197. if(addIndex < this.currentCursorIndex || this.currentCursorIndex == void 0){
  78198. this.domElements.forEach(e=>e.style.cursor = o.addItem[o.name] );
  78199. this.currentCursorIndex = addIndex;
  78200. }
  78201. }else {
  78202. var levelMax = {index:Infinity, cursor:null };
  78203. this.list.forEach(name=>{
  78204. var priorityItem = this.priorityEvent.find(e=>e[name]);
  78205. var index = this.priorityEvent.indexOf(priorityItem);
  78206. if(index < levelMax.index){
  78207. levelMax.index = index;
  78208. levelMax.cursor = priorityItem[name];
  78209. }
  78210. });
  78211. this.currentCursorIndex = levelMax.index;
  78212. this.domElements.forEach(e=>e.style.cursor = levelMax.cursor || '');
  78213. }
  78214. }
  78215. };
  78216. class SplitScreen extends EventDispatcher{
  78217. constructor (args = {}) {
  78218. super();
  78219. }
  78220. /*
  78221. viewport.targetPlane // bound中心点处的plane,方向和view一致
  78222. viewport.shiftTarget // camera的位置project在targetPlane上的位置
  78223. 这两个参数的主要目的是为了getPosOutOfModel,以及rotateSideCamera时保持相对位置
  78224. */
  78225. splitStart(cameraProps){
  78226. this.splited = true;
  78227. let viewports = [];
  78228. let subViewports = [viewer.mainViewport];
  78229. if(viewer.mapViewer){
  78230. subViewports.push(viewer.mapViewer.viewports[0]);
  78231. }
  78232. let length = cameraProps.length;
  78233. for(let i=0;i<length;i++){
  78234. let prop = cameraProps[i];
  78235. let viewport;
  78236. let v = subViewports.find(e=>e.name == (prop.name2||prop.name));
  78237. if(v){
  78238. viewport = v;
  78239. viewport.left = prop.left; viewport.bottom = prop.bottom; viewport.width = prop.width; viewport.height = prop.height;
  78240. }
  78241. if(!viewport){
  78242. let view = new ExtendView();
  78243. if(prop.limitBound)view.limitBound = prop.limitBound;
  78244. prop.direction && (view.direction = prop.direction);
  78245. viewport = new Viewport(view , this.getOrthoCamera(), prop );
  78246. if(prop.viewContainsPoints)viewport.viewContainsPoints = prop.viewContainsPoints;
  78247. //viewport.unableDepth = true //depthBasicMaterial等在此viewport中不开启depth
  78248. }
  78249. if(viewport.camera.type == 'OrthographicCamera' ){
  78250. viewport.targetPlane = new Plane();
  78251. viewport.shiftTarget = new Vector3; //project在targetPlane上的位置
  78252. }
  78253. viewport.fitMargin = prop.margin;
  78254. viewports.push(viewport);
  78255. }
  78256. viewer.viewports = viewports;
  78257. viewer.updateScreenSize({forceUpdateSize:true});
  78258. viewports.forEach(viewport=>{
  78259. if(viewport.name == 'MainView')return
  78260. this.viewportFitBound(viewport, viewer.bound.boundingBox , viewer.bound.center , 0, viewport.fitMargin);
  78261. });
  78262. return viewports
  78263. }
  78264. unSplit(){
  78265. this.splited = false;
  78266. this.unfocusViewport();
  78267. viewer.inputHandler.hoverViewport = null; //清空
  78268. viewer.viewports = [viewer.mainViewport];
  78269. viewer.mainViewport.width = 1;
  78270. viewer.mainViewport.height = 1;
  78271. viewer.mainViewport.left = 0;
  78272. viewer.mainViewport.bottom = 0;
  78273. viewer.updateScreenSize({forceUpdateSize:true});
  78274. }
  78275. viewportFitBound(viewport, bound, center, duration=0, margin){
  78276. let view = viewport.view;
  78277. let info = {bound};
  78278. let {boundSize, boundCenter} = this.getViewBound(viewport, bound );
  78279. //this.setShiftTarget(viewport, boundCenter)
  78280. viewport.targetPlane.setFromNormalAndCoplanarPoint( view.direction.clone(), boundCenter );
  78281. viewport.targetPlane.projectPoint(center, viewport.shiftTarget); //target转换到过模型中心的平面,以保证镜头一定在模型外 this.shiftTarget是得到的
  78282. info.endPosition = this.getPosOutOfModel(viewport, boundSize);
  78283. //if(viewport.name == 'mapViewport')info.endPosition.z = Math.max(Potree.config.map.cameraHeight, info.endPosition.z)
  78284. info.margin = margin || {x:30, y:30};
  78285. view.moveOrthoCamera(viewport, info , duration );
  78286. }
  78287. getViewBound(viewport, boundingBox){
  78288. if(boundingBox){
  78289. boundSize = boundingBox.getSize(new Vector3);
  78290. center = boundingBox.getCenter(new Vector3);
  78291. }else {
  78292. var {boundSize, center, boundingBox} = viewer.bound;
  78293. }
  78294. let containsPoints = [];
  78295. this.focusCenter && containsPoints.push(this.focusCenter);
  78296. viewport.viewContainsPoints && containsPoints.push(...viewport.viewContainsPoints);
  78297. if(containsPoints.length){//视野范围内必须要包含的点,直接算入模型区域。这时候得到的boundCenter和模型中心不重合
  78298. boundingBox = boundingBox.clone();
  78299. containsPoints.forEach(point=>{
  78300. boundingBox.expandByPoint(point);
  78301. });
  78302. boundSize = boundingBox.getSize(new Vector3);
  78303. center = boundingBox.getCenter(new Vector3);
  78304. }
  78305. return {boundSize, boundCenter:center }
  78306. }
  78307. getPosOutOfModel(viewport, boundSize){
  78308. //let {boundSize, center} = viewer.bound
  78309. boundSize = boundSize || this.getViewBound(viewport).boundSize;
  78310. let expand = 10;
  78311. let radius = boundSize.length() * 2;
  78312. let position = viewport.shiftTarget.clone().sub(viewport.view.direction.clone().multiplyScalar(radius + expand));
  78313. return position
  78314. }
  78315. updateCameraOutOfModel(){//因为移动模型导致模型超出相机外,所以更新位置
  78316. viewer.viewports.forEach((viewport, i )=>{
  78317. if(viewport.camera.isOrthographicCamera){ //or if(viewport.targetPlane)
  78318. let {boundSize, boundCenter} = this.getViewBound(viewport);
  78319. /* viewport.targetPlane.setFromNormalAndCoplanarPoint( viewport.view.direction.clone(), boundCenter)
  78320. viewport.targetPlane.projectPoint(viewport.view.position, viewport.shiftTarget) //target转换到过模型中心的平面,以保证镜头一定在模型外 this.shiftTarget是得到的
  78321. */
  78322. this.setShiftTarget(viewport, boundCenter);
  78323. let endPosition = this.getPosOutOfModel(viewport, boundSize);
  78324. //if(viewport.name == 'mapViewport')endPosition.z = Math.max(Potree.config.map.cameraHeight, endPosition.z)
  78325. viewport.view.position.copy(endPosition);
  78326. }
  78327. });
  78328. }
  78329. setShiftTarget(viewport, center){
  78330. if(!viewport.targetPlane ){
  78331. viewport.targetPlane = new Plane();
  78332. viewport.shiftTarget = new Vector3; //project在targetPlane上的位置
  78333. }
  78334. viewport.targetPlane.setFromNormalAndCoplanarPoint(viewport.view.direction, center );
  78335. viewport.targetPlane.projectPoint(viewport.view.position, viewport.shiftTarget ); //target转换到过模型中心的平面,以保证镜头一定在模型外
  78336. }
  78337. rotateSideCamera(viewport, angle){//侧视图或俯视图绕模型中心水平旋转
  78338. //let {boundSize, center} = viewer.bound
  78339. let {boundSize, boundCenter } = this.getViewBound(viewport);
  78340. let center = this.focusCenter || boundCenter; //旋转中心,一般是所有模型的中心,除非想指定中心点
  78341. this.setShiftTarget(viewport, center);
  78342. //找到平移向量
  78343. let vec = new Vector3().subVectors(center, viewport.shiftTarget);//相对于中心的偏移值,旋转后偏移值也旋转
  78344. //旋转
  78345. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0,0,1), angle);
  78346. viewport.view.direction = viewport.view.direction.applyMatrix4(rotMatrix);
  78347. vec.applyMatrix4(rotMatrix);
  78348. viewport.shiftTarget.subVectors(center,vec); //新的
  78349. viewport.view.position = this.getPosOutOfModel(viewport, boundSize);
  78350. }
  78351. getOrthoCamera(){
  78352. let camera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  78353. camera.up.set(0,0,1);
  78354. return camera
  78355. }
  78356. focusOnViewport(name){//全屏
  78357. viewer.viewports.forEach((viewport, i )=>{
  78358. if(viewport.name == name){
  78359. this.focusInfo = {
  78360. name,
  78361. left : viewport.left, bottom : viewport.bottom, height : viewport.height, width : viewport.width
  78362. };
  78363. viewport.left = 0; viewport.bottom = 0; viewport.height = 1; viewport.width = 1;
  78364. }else {
  78365. viewport.active = false;
  78366. }
  78367. });
  78368. viewer.updateScreenSize({forceUpdateSize:true});
  78369. }
  78370. unfocusViewport(){
  78371. if(!this.focusInfo)return
  78372. viewer.viewports.forEach((viewport, i )=>{
  78373. if(this.focusInfo.name == viewport.name){//全屏的恢复
  78374. viewport.left = this.focusInfo.left;
  78375. viewport.bottom = this.focusInfo.bottom;
  78376. viewport.height = this.focusInfo.height;
  78377. viewport.width = this.focusInfo.width;
  78378. }
  78379. viewport.active = true;
  78380. });
  78381. viewer.updateScreenSize({forceUpdateSize:true});
  78382. this.focusInfo = null;
  78383. }
  78384. }
  78385. const FEET_TO_INCHES_FACTOR = 12;
  78386. const EIGHTHS_SYMBOLS = ["", "⅛", "¼", "⅜", "½", "⅝", "¾", "⅞"];//eighths 八分之……
  78387. class UnitOfMeasurement{//转化单位工具
  78388. constructor(t, e, n, i){
  78389. this.name = t,
  78390. this.symbol = e,
  78391. this.base = n,
  78392. this.factor = i;
  78393. }
  78394. toBase(t) {//换算到base
  78395. return t * this.factor
  78396. }
  78397. fromBase(t) {//换算到当前
  78398. return t / this.factor
  78399. }
  78400. }
  78401. /* var o = function t(e) {
  78402. this.gettext = e,
  78403. t.METRIC = this.gettext("metric", void 0, "measurement system"),
  78404. t.IMPERIAL = this.gettext("imperial", void 0, "measurement system")
  78405. };
  78406. e.UoMSystem = o;
  78407. let UoMSystem = {
  78408. } */
  78409. /* var MeasurementDomain = {
  78410. DISTANCE : "DISTANCE",
  78411. t.AREA = "AREA",
  78412. t.VOLUME = "VOLUME",
  78413. t.DATA = "DATA",
  78414. t
  78415. }
  78416. */
  78417. var UnitsOfMeasurement = {
  78418. MILLIMETER : ["Millimeter", "mm"],
  78419. CENTIMETER : ["Centimeter", "cm"],
  78420. METER : ["Meter", "m"],
  78421. KILOMETER : ["Kilometer", "km"],
  78422. INCH : ["Inch", "in"],
  78423. FOOT : ["Foot", "ft"],
  78424. MILE : ["Mile", "mi"],
  78425. SQUAREMETER : ["SquareMeter", "m²"],
  78426. SQUAREFOOT : ["SquareFoot", "ft²"],
  78427. CUBICMETER : ["CubicMeter", "m³"],
  78428. CUBICFOOT : ["CubicFoot", "ft³"],
  78429. BYTE : ["Byte", "B"],
  78430. KILOBYTE : ["Kilobyte", "kB"],
  78431. MEGABYTE : ["Megabyte", "MB"],
  78432. GIGABYTE : ["Gigabyte", "GB"],
  78433. TERABYTE : ["Terabyte", "TB"],
  78434. PETABYTE : ["Petabyte", "PB"],
  78435. init : function() {
  78436. var e, n, i, a, s, c, l, u, d, p, h,
  78437. f = new UnitOfMeasurement(UnitsOfMeasurement.METER[0],UnitsOfMeasurement.METER[1],void 0,1),
  78438. g = new UnitOfMeasurement(UnitsOfMeasurement.SQUAREMETER[0],UnitsOfMeasurement.SQUAREMETER[1],void 0,1),
  78439. m = new UnitOfMeasurement(UnitsOfMeasurement.CUBICMETER[0],UnitsOfMeasurement.CUBICMETER[1],void 0,1),
  78440. v = new UnitOfMeasurement(UnitsOfMeasurement.BYTE[0],UnitsOfMeasurement.BYTE[1],void 0,1);
  78441. UnitsOfMeasurement.DISTANCE = (
  78442. (e = {})['metric'] = ((n = {})[UnitsOfMeasurement.MILLIMETER[0]] = new UnitOfMeasurement(UnitsOfMeasurement.MILLIMETER[0],UnitsOfMeasurement.MILLIMETER[1],f,.001),
  78443. n[UnitsOfMeasurement.CENTIMETER[0]] = new UnitOfMeasurement(UnitsOfMeasurement.CENTIMETER[0],UnitsOfMeasurement.CENTIMETER[1],f,.01),
  78444. n[UnitsOfMeasurement.METER[0]] = f,
  78445. n[UnitsOfMeasurement.KILOMETER[0]] = new UnitOfMeasurement(UnitsOfMeasurement.KILOMETER[0],UnitsOfMeasurement.KILOMETER[1],f,1e3),
  78446. n),
  78447. e['imperial'] = ((i = {})[UnitsOfMeasurement.INCH[0]] = new UnitOfMeasurement(UnitsOfMeasurement.INCH[0],UnitsOfMeasurement.INCH[1],f,.0254),
  78448. i[UnitsOfMeasurement.FOOT[0]] = new UnitOfMeasurement(UnitsOfMeasurement.FOOT[0],UnitsOfMeasurement.FOOT[1],f,.3048),
  78449. i[UnitsOfMeasurement.MILE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.MILE[0],UnitsOfMeasurement.MILE[1],f,1609.344),
  78450. i),
  78451. e);
  78452. UnitsOfMeasurement.AREA = ((a = {})['metric'] = ((s = {})[UnitsOfMeasurement.SQUAREMETER[0]] = g,
  78453. s),
  78454. a['imperial'] = ((c = {})[UnitsOfMeasurement.SQUAREFOOT[0]] = new UnitOfMeasurement(UnitsOfMeasurement.SQUAREFOOT[0],UnitsOfMeasurement.SQUAREFOOT[1],g,.092903),
  78455. c),
  78456. a);
  78457. UnitsOfMeasurement.VOLUME = ((l = {})['metric'] = ((u = {})[UnitsOfMeasurement.CUBICMETER[0]] = m,
  78458. u),
  78459. l['imperial'] = ((d = {})[UnitsOfMeasurement.CUBICFOOT[0]] = new UnitOfMeasurement(UnitsOfMeasurement.CUBICFOOT[0],UnitsOfMeasurement.CUBICFOOT[1],m,.0283168),
  78460. d),
  78461. l);
  78462. //数据大小
  78463. var y = ((p = {})[UnitsOfMeasurement.BYTE[0]] = v,
  78464. p[UnitsOfMeasurement.KILOBYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.KILOBYTE[0],UnitsOfMeasurement.KILOBYTE[1],v,1e3),
  78465. p[UnitsOfMeasurement.MEGABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.MEGABYTE[0],UnitsOfMeasurement.MEGABYTE[1],v,1e6),
  78466. p[UnitsOfMeasurement.GIGABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.GIGABYTE[0],UnitsOfMeasurement.GIGABYTE[1],v,1e9),
  78467. p[UnitsOfMeasurement.TERABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.TERABYTE[0],UnitsOfMeasurement.TERABYTE[1],v,1e12),
  78468. p[UnitsOfMeasurement.PETABYTE[0]] = new UnitOfMeasurement(UnitsOfMeasurement.PETABYTE[0],UnitsOfMeasurement.PETABYTE[1],v,1e15),
  78469. p);
  78470. UnitsOfMeasurement.DATA = ((h = {})['metric'] = y,
  78471. h['imperial'] = y,
  78472. h);
  78473. }
  78474. ,
  78475. getUnitsOfMeasurementByDomain : function(e) {
  78476. return this[e.toUpperCase()]
  78477. /* switch (e.toUpperCase()) {
  78478. case a.DISTANCE:
  78479. return t.DISTANCE;
  78480. case a.AREA:
  78481. return t.AREA;
  78482. case a.VOLUME:
  78483. return t.VOLUME;
  78484. case a.DATA:
  78485. return t.DATA;
  78486. default:
  78487. console.error(e + " measurement domain is not supported.")
  78488. } */
  78489. }
  78490. ,
  78491. getUnitsOfMeasurementByDomainAndSystem : function(domain, system) {
  78492. var r = this.getUnitsOfMeasurementByDomain(domain);
  78493. if (r.hasOwnProperty(system.toLowerCase()))
  78494. return r[system.toLowerCase()];
  78495. console.error(n + " measurement system is not supported.");
  78496. }
  78497. ,
  78498. getDefaultUnitByDomainAndSystem : function(e, n) {
  78499. switch (e.toUpperCase()) {
  78500. case 'DISTANCE':
  78501. switch (n.toLowerCase()) {
  78502. case 'metric':
  78503. return this.DISTANCE['metric'][this.METER[0]];
  78504. case 'imperial':
  78505. return this.DISTANCE['imperial'][this.FOOT[0]];
  78506. default:
  78507. console.error(n + " measurement system is not supported.");
  78508. }
  78509. case 'AREA':
  78510. switch (n.toLowerCase()) {
  78511. case 'metric':
  78512. return this.AREA['metric'][this.SQUAREMETER[0]];
  78513. case 'imperial':
  78514. return this.AREA['imperial'][this.SQUAREFOOT[0]];
  78515. default:
  78516. console.error(n + " measurement system is not supported.");
  78517. }
  78518. case 'VOLUME':
  78519. switch (n.toLowerCase()) {
  78520. case 'metric':
  78521. return this.VOLUME['metric'][this.CUBICMETER[0]];
  78522. case 'imperial':
  78523. return this.VOLUME['imperial'][this.CUBICFOOT[0]];
  78524. default:
  78525. console.error(n + " measurement system is not supported.");
  78526. }
  78527. case 'DATA':
  78528. switch (n.toLowerCase()) {
  78529. case 'metric':
  78530. return this.DATA['metric'][this.BYTE[0]];
  78531. case 'imperial':
  78532. return this.DATA['imperial'][this.BYTE[0]];
  78533. default:
  78534. console.error(n + " measurement system is not supported.");
  78535. }
  78536. default:
  78537. console.error(e + " measurement domain is not supported.");
  78538. }
  78539. }
  78540. };
  78541. class UnitService{
  78542. constructor(/* e, n, i */){
  78543. //this.LanguageService = e,
  78544. //this.localStorageService = n,
  78545. //this.gettext = i,
  78546. //this.unitChanged = new r.Signal,
  78547. this.LOCAL_STORAGE_KEY = "iv_unit_key";//?
  78548. UnitsOfMeasurement.init();
  78549. this.unitSystems = ['metric', 'imperial'];//[o.UoMSystem.METRIC, o.UoMSystem.IMPERIAL],
  78550. this.defaultSystem = 'metric';//'imperial'
  78551. //var a = this.LanguageService.getBrowserLocaleString().toLowerCase();
  78552. //this.defaultSystem = t.isLocaleImperial(a) ? o.UoMSystem.IMPERIAL : o.UoMSystem.METRIC,
  78553. //this.initUnit()
  78554. }
  78555. /* initUnit() {
  78556. var t = this.localStorageService.get(this.LOCAL_STORAGE_KEY);
  78557. if (t)
  78558. for (var e = 0, n = this.unitSystems; e < n.length; e++) {
  78559. var i = n[e];
  78560. if (i === t)
  78561. return void this.setUnit(i, !0)
  78562. }
  78563. this.setUnit(this.defaultSystem, !1)
  78564. }
  78565. setUnit(t, e) {
  78566. this.currentSystem !== t && (this.currentSystem = t,
  78567. this.unitChanged.emit()),
  78568. e && this.localStorageService.set(this.LOCAL_STORAGE_KEY, t)
  78569. } */
  78570. /*isLocaleImperial(e) {
  78571. return t.IMPERIAL_LOCALES.indexOf(e.toLowerCase()) >= 0
  78572. }
  78573. ,
  78574. t.IMPERIAL_LOCALES = ["en_us"],
  78575. t.ɵfac(e) {
  78576. return new (e || t)(c.ɵɵinject(l.LanguageService),
  78577. c.ɵɵinject("localStorageService"),c.ɵɵinject("gettext"))
  78578. }
  78579. ,
  78580. t.ɵprov = c.ɵɵdefineInjectable({
  78581. token: t,
  78582. factory: t.ɵfac,
  78583. providedIn: "root"
  78584. }), */
  78585. }
  78586. class UoMService{
  78587. constructor(/* UnitService */){
  78588. this.UnitService = new UnitService();/* UnitService */
  78589. }
  78590. scopedConvert (t, n, precision = 2, r, minFactor) {
  78591. return this.convert(t, n, precision, r, minFactor)
  78592. }
  78593. convert(number, domain, precision = 2, system, ifEighths = !1, o /* minFactor, ifRestrict */) {
  78594. let {minFactor, restrictUnit} = o[system];
  78595. //if (!number) return "";
  78596. var s = this.getMostRelevantMeasurement(domain, system || this.UnitService.currentSystem, number, minFactor, restrictUnit);
  78597. return this.getFormattedMeasurementString(s[0], s[1], precision, ifEighths)
  78598. }
  78599. convertBack(number, domain, precision = 2, fromSystem, minFactor ) { //从英制转到'metric'
  78600. if (!number) return "";
  78601. var d = UnitsOfMeasurement.getDefaultUnitByDomainAndSystem(domain,'metric');
  78602. var s = this.getMostRelevantMeasurement2(domain, fromSystem, number, minFactor);
  78603. return this.getFormattedMeasurementString(s[0], d, precision )
  78604. /* 栗子:
  78605. viewer.unitConvert.convertBack(1, 'area', 5, 'imperial')
  78606. '0.09290 m²'
  78607. viewer.unitConvert.convertBack(1, 'Distance', 2, 'imperial')
  78608. '0.03 m'
  78609. */
  78610. }
  78611. getFormattedMeasurementString(number, unit, precision, ifEighths) {
  78612. var result;
  78613. if(ifEighths && unit.name === UnitsOfMeasurement.FOOT[0]){
  78614. result = this.formatImperialDistance(number * FEET_TO_INCHES_FACTOR);
  78615. }else if(ifEighths && unit.name === UnitsOfMeasurement.INCH[0]){
  78616. result = this.formatImperialDistance(number);
  78617. }else {
  78618. result = number.toLocaleString(void 0, {
  78619. minimumFractionDigits: precision,
  78620. maximumFractionDigits: precision
  78621. }) + " " + unit.symbol;
  78622. }
  78623. return result
  78624. }
  78625. formatImperialDistance(e) {
  78626. var n = Math.round(8 * e)
  78627. , i = Math.floor(n / 8)
  78628. , r = Math.floor(i / FEET_TO_INCHES_FACTOR)
  78629. , o = i - r * FEET_TO_INCHES_FACTOR
  78630. , a = EIGHTHS_SYMBOLS[Math.abs(n % 8)]
  78631. , s = 0 === o && "" !== a ? "" : o;
  78632. "" !== s && "" !== a && (a = " " + a);
  78633. return 0 !== r ? r + "' " + s + a + '"' : "" + s + a + '"'
  78634. }
  78635. getMostRelevantMeasurement(domain, system, number, minFactor=0, restrictUnit) {
  78636. /* var a = r.values(UnitsOfMeasurement.getUnitsOfMeasurementByDomainAndSystem(domain, system))
  78637. , s = r.filter(a, function(t) {
  78638. return t.factor >= i
  78639. })
  78640. , c = r.reduce(s, function(t, e) {
  78641. return e.fromBase(number) < t.fromBase(number) && e.fromBase(number) >= 1 ? e : t
  78642. }); */
  78643. let a = [];
  78644. let u = UnitsOfMeasurement.getUnitsOfMeasurementByDomainAndSystem(domain, system);
  78645. for(let i in u){a.push(u[i]);}
  78646. let s = a;
  78647. if(s.length > 1){
  78648. if(restrictUnit){//是否只用这一单位,如只用mm。如果不是,就会寻找最大的接近的单位,如设置最小为mmminFactor=0.001),则1.2米时是'1.2m'、0.2米时是'20cm'、0.002米时是'2mm'
  78649. s = a.filter(m=>m.name == restrictUnit);
  78650. }else {
  78651. s = a.filter(m=>m.factor >= minFactor);
  78652. }
  78653. }
  78654. let c = s.reduce(function(prev, currentValue) {//reduce最终值是最后一次return的值 ( 没看懂这句话作用)
  78655. return currentValue.fromBase(number) < prev.fromBase(number) && currentValue.fromBase(number) >= 1 ? currentValue : prev
  78656. });
  78657. return c ? [c.fromBase(number), c] : void 0
  78658. }
  78659. getMostRelevantMeasurement2(domain, system, number, minFactor=0) {//add
  78660. let a = [];
  78661. let u = UnitsOfMeasurement.getUnitsOfMeasurementByDomainAndSystem(domain, system);
  78662. for(let i in u){a.push(u[i]);}
  78663. let s = a.filter(m=>m.factor >= minFactor);
  78664. let c = s.reduce(function(prev, currentValue) {//reduce最终值是最后一次return的值 ( 没看懂这句话作用)
  78665. return currentValue.toBase(number) < prev.toBase(number) && currentValue.toBase(number) >= 1 ? currentValue : prev
  78666. });
  78667. return c ? [c.toBase(number), c] : void 0
  78668. }
  78669. /* ɵfac(e){
  78670. return new (e || t)(c.ɵɵinject(l.UnitService))
  78671. }
  78672. ɵprov = c.ɵɵdefineInjectable({
  78673. token: t,
  78674. factory: t.ɵfac,
  78675. providedIn: "root"
  78676. }) */
  78677. }
  78678. let texLoader$8 = new TextureLoader();
  78679. let color$1 = new Color(config$1.clip.color);
  78680. let markerMats$1;
  78681. let markerSizeInfo$1 = {width2d: 40};
  78682. const pickOrders = {
  78683. marker:1,
  78684. area: 0,
  78685. };
  78686. class mapClipBox extends ctrlPolygon {
  78687. constructor (center, scale) {
  78688. center = center.clone().setZ(0);//所有Z都为0
  78689. let prop = {
  78690. points : getPoints(center, scale, 0),
  78691. closed : true,
  78692. atPlane: true,
  78693. isRect : true,
  78694. dimension : '2d'
  78695. };
  78696. super('mapClipBox', prop);
  78697. this.angle = 0;
  78698. this.createRotateBar();
  78699. this.edgeMarkers = [];
  78700. //addMarkers:
  78701. this.initData(prop);
  78702. {//areaPlane event 能拖动
  78703. this.areaPlane.addEventListener('mouseover',()=>{
  78704. viewer.dispatchEvent({
  78705. type : "CursorChange", action : "add", name:"mapClipMove"
  78706. });
  78707. });
  78708. this.areaPlane.addEventListener('mouseleave',()=>{
  78709. viewer.dispatchEvent({
  78710. type : "CursorChange", action : "remove", name:"mapClipMove"
  78711. });
  78712. });
  78713. let lastPos;
  78714. let drag = (e)=>{
  78715. let intersect = e.intersect.orthoIntersect;
  78716. if(lastPos){
  78717. let moveVec = new Vector3().subVectors(intersect, lastPos).setZ(0);
  78718. this.center.add(moveVec);
  78719. this.updatePoints();
  78720. this.dispatchEvent({type:'repos'});
  78721. }
  78722. lastPos = intersect.clone();
  78723. };
  78724. let drop = (e)=>{
  78725. lastPos = null;
  78726. };
  78727. this.areaPlane.addEventListener('drag', drag);
  78728. this.areaPlane.addEventListener('drop', drop);
  78729. }
  78730. /* this.addEventListener('dragChange',()=>{
  78731. this.updateTwoMidMarker(index+1)
  78732. }) */
  78733. Potree.Utils.setObjectLayers(this, 'mapObjects' );
  78734. }
  78735. getScale(){
  78736. return new Vector3(this.points[0].distanceTo(this.points[1]), this.points[1].distanceTo(this.points[2]) ,1)
  78737. }
  78738. addMarker(o={} ){
  78739. let marker = new Sprite$2({mat:this.getMarkerMaterial('default'), pickOrder:pickOrders.marker, sizeInfo: markerSizeInfo$1, dontFixOrient: true, viewports:viewer.mapViewer.viewports, name:"mapClipBox_marker", } );
  78740. marker.renderOrder = 3;
  78741. //marker.markerSelectStates = {}
  78742. let edge = LineDraw.createLine([new Vector3,new Vector3],{color: color$1 });
  78743. let edgeMarker = new Sprite$2({mat:this.getMarkerMaterial('default'), pickOrder:pickOrders.marker, sizeInfo: markerSizeInfo$1, dontFixOrient: true, viewports:viewer.mapViewer.viewports, name:"mapClipBox_edgePoint"} );
  78744. let mouseover = (e) => {
  78745. this.setMarkerSelected(e.object, true, 'single');
  78746. viewer.dispatchEvent({
  78747. type : "CursorChange", action : "add", name:"markerMove"
  78748. });
  78749. };
  78750. let mouseleave = (e) => {
  78751. this.setMarkerSelected(e.object, false, 'single');
  78752. viewer.dispatchEvent({
  78753. type : "CursorChange", action : "remove", name:"markerMove"
  78754. });
  78755. };
  78756. edgeMarker.addEventListener('mouseover', mouseover);
  78757. edgeMarker.addEventListener('mouseleave', mouseleave);
  78758. let dragInfo = {lastPos:null};
  78759. edgeMarker.addEventListener('drag', this.dragEdge.bind(this,dragInfo));
  78760. edgeMarker.addEventListener('drop', this.dropEdge.bind(this,dragInfo));
  78761. this.edgeMarkers.push(edgeMarker);
  78762. this.add(edgeMarker);
  78763. marker.dispatchEvent('addHoverEvent');
  78764. super.addMarker({point:o.point, marker:marker, edge});
  78765. }
  78766. dragEdge(dragInfo, e){//拖拽一个边(或一个边类型的marker),带动它的两个端点。 可以转化为拖拽marker往法线方向
  78767. var I, atMap;
  78768. atMap = e.dragViewport.name == 'mapViewport';
  78769. I = e.intersect.orthoIntersect;
  78770. if (I && dragInfo.lastPos) {
  78771. let i = this.edgeMarkers.indexOf(e.drag.object);
  78772. if (i !== -1) {
  78773. let lineNormal = math.getNormal2d({p1:this.points[i], p2:this.points[(i+1)%4]});
  78774. let moveVec = new Vector3().subVectors(I, dragInfo.lastPos).setZ(0);//移动的向量
  78775. let dragVec = moveVec.projectOnVector(lineNormal).setZ(0);//在法线上移动的向量
  78776. let newPos = new Vector3().addVectors(this.points[i], dragVec); //marker应到的位置
  78777. this.dragChange(newPos, i, atMap); //转化为这个marker的拖拽
  78778. }
  78779. }
  78780. dragInfo.lastPos = I.clone();
  78781. }
  78782. dropEdge(dragInfo, e){
  78783. dragInfo.lastPos = null;
  78784. this.setMarkerSelected(e.drag.object, false, 'single'); //拖拽时似乎没有触发mouseout
  78785. }
  78786. createAreaPlane(){
  78787. var planeMat = new MeshBasicMaterial({
  78788. color: color$1,//"#00eeff",
  78789. side:DoubleSide,
  78790. opacity:0.3,
  78791. transparent:true,
  78792. depthTest:false
  78793. });
  78794. return super.createAreaPlane(planeMat)
  78795. }
  78796. getMarkerMaterial(type) {
  78797. if(!markerMats$1){
  78798. markerMats$1 = {
  78799. default: new MeshBasicMaterial({
  78800. transparent: !0,
  78801. color: color$1,
  78802. opacity: 0.8,
  78803. map: texLoader$8.load(Potree.resourcePath+'/textures/whiteCircle.png' ),
  78804. }),
  78805. select: new MeshBasicMaterial({
  78806. transparent: !0,
  78807. color: color$1,
  78808. opacity: 1,
  78809. map: texLoader$8.load(Potree.resourcePath+'/textures/whiteCircle.png' ),
  78810. }),
  78811. };
  78812. mapClipBox.markerMats = markerMats$1;
  78813. }
  78814. return markerMats$1[type]
  78815. }
  78816. setMarkerSelected(marker, state, hoverObject){
  78817. //console.warn(marker.id , state, hoverObject)
  78818. if(state == 'hover'){
  78819. marker.material = this.getMarkerMaterial('select');
  78820. }else {
  78821. marker.material = this.getMarkerMaterial('default');
  78822. }
  78823. /* marker.markerSelectStates[hoverObject] = state
  78824. let absoluteState = false
  78825. for(var i in marker.markerSelectStates){
  78826. if(marker.markerSelectStates[i]){
  78827. absoluteState = true; break;
  78828. }
  78829. }
  78830. if(absoluteState){
  78831. marker.material = this.getMarkerMaterial('select')
  78832. }else{
  78833. marker.material = this.getMarkerMaterial('default')
  78834. }
  78835. marker.selected = absoluteState */
  78836. viewer.mapViewer.dispatchEvent('content_changed');
  78837. }
  78838. createRotateBar(){
  78839. //中心点在线的一端,整体初始在box上方
  78840. const lineLen = 1.5, circleWidth = 2, barOpacity = 0.7;
  78841. let object = new Object3D;
  78842. let bar = new Sprite$2({mat:new MeshBasicMaterial({
  78843. side:DoubleSide,
  78844. opacity: barOpacity,
  78845. transparent:true,
  78846. depthTest:false,
  78847. map: texLoader$8.load(Potree.resourcePath+'/textures/rotation_circle.png' ),
  78848. }) ,
  78849. root:object,
  78850. sizeInfo: markerSizeInfo$1,
  78851. dontFixOrient: true,
  78852. viewports:viewer.mapViewer.viewports,
  78853. name:"mapClipRotateBar"
  78854. });
  78855. bar.position.set(0,lineLen+circleWidth/2,0);
  78856. bar.scale.set(circleWidth,circleWidth,circleWidth);
  78857. bar.addEventListener('mouseover',()=>{
  78858. bar.material.opacity = 1;
  78859. viewer.dispatchEvent({
  78860. type : "CursorChange", action : "add", name:"mapClipRotate"
  78861. });
  78862. viewer.mapViewer.dispatchEvent('content_changed');
  78863. });
  78864. let leave = ()=>{
  78865. bar.material.opacity = barOpacity;
  78866. viewer.dispatchEvent({
  78867. type : "CursorChange", action : "remove", name:"mapClipRotate"
  78868. });
  78869. viewer.mapViewer.dispatchEvent('content_changed');
  78870. };
  78871. bar.addEventListener('mouseleave',leave);
  78872. this.addEventListener('dispose', leave);
  78873. let lastPos;
  78874. bar.addEventListener('drag',(e)=>{
  78875. var intersect = e.intersect.orthoIntersect;
  78876. if(lastPos){
  78877. let vec1 = new Vector3().subVectors(lastPos, this.center).setZ(0);
  78878. let vec2 = new Vector3().subVectors(intersect, this.center).setZ(0);
  78879. let angle = math.getAngle(vec1,vec2,'z');
  78880. this.angle += angle;
  78881. this.rotateBar.rotation.z = this.angle;
  78882. this.updatePoints();
  78883. this.dispatchEvent({type:'rotate', angle: this.angle});
  78884. }
  78885. lastPos = intersect.clone();
  78886. });
  78887. bar.addEventListener('drop',()=>{
  78888. lastPos = null;
  78889. viewer.dispatchEvent({
  78890. type : "CursorChange", action : "remove", name:"mapClipRotate"
  78891. });
  78892. });
  78893. let line = LineDraw.createLine([new Vector3, new Vector3(0,lineLen,0)],{color: color$1});
  78894. object.add(bar);
  78895. object.add(line);
  78896. this.add(object);
  78897. this.rotateBar = object;
  78898. this.rotateBar.bar = bar;
  78899. }
  78900. updatePoints(scale){
  78901. this.points = getPoints(this.center, scale || this.getScale(), this.angle);
  78902. this.getPoint2dInfo(this.points);
  78903. this.update({ifUpdateMarkers:true});
  78904. }
  78905. update(options={}){
  78906. super.update(options);
  78907. {//update rotateBar
  78908. let center = new Vector3().addVectors(this.points[0], this.points[1]).multiplyScalar(0.5);
  78909. this.rotateBar.position.copy(center);
  78910. this.rotateBar.bar.waitUpdate();//更新sprite matrix
  78911. }
  78912. {
  78913. for(let i=0;i<4;i++){
  78914. let current = this.points[i];
  78915. let next = this.points[(i+1)%4];
  78916. let mid = new Vector3().addVectors(current, next).multiplyScalar(0.5);
  78917. this.updateMarker(this.edgeMarkers[i], mid);
  78918. }
  78919. }
  78920. }
  78921. dispose(){
  78922. super.dispose();
  78923. this.dispatchEvent('dispose');
  78924. this.rotateBar.bar.dispose();
  78925. }
  78926. }
  78927. function getPoints(center, scale, angle=0){
  78928. let points = [
  78929. new Vector3(-scale.x/2, +scale.y/2, 0),
  78930. new Vector3(+scale.x/2, +scale.y/2, 0),
  78931. new Vector3(+scale.x/2, -scale.y/2, 0),
  78932. new Vector3(-scale.x/2, -scale.y/2, 0),
  78933. ];
  78934. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0,0,1), angle);//再旋转
  78935. points.forEach(e=>{
  78936. e.applyMatrix4(rotMatrix);
  78937. e.add(center);
  78938. });
  78939. return points
  78940. }
  78941. const defaultBoxWidth = 16; //navvis: 10
  78942. //navvis position: si {x: 0, y: 0, z: 0}
  78943. const cameraProps = [
  78944. {
  78945. name : 'top',
  78946. axis:["x","y"],
  78947. direction : new Vector3(0,0,-1), //镜头朝向
  78948. openCount:0,
  78949. },
  78950. {
  78951. name : 'front',
  78952. axis:["x","z"],
  78953. direction : new Vector3(0,1,0),
  78954. openCount:0,
  78955. },
  78956. {
  78957. name : 'mainView',
  78958. openCount:0,
  78959. }
  78960. ];
  78961. var Clip = {
  78962. bus : new EventDispatcher,
  78963. selectedDatasets : [],
  78964. changeCallback(force){
  78965. if(this.activeViewName != 'mainView'){
  78966. this.splitScreenTool.updateCameraOutOfModel(); //更新相机位置
  78967. }
  78968. if(Potree.settings.isOfficial && this.showMap){
  78969. let fun = ()=>{
  78970. let pointclouds = this.getIntersectPointcloud();
  78971. if( Common.getDifferenceSet(pointclouds,this.selectedDatasets).length){
  78972. this.selectedDatasets = pointclouds;
  78973. //console.error('clipSelectedDatasets',selectedDatasets)
  78974. this.bus.dispatchEvent({type:'updateSelectedDatasets', selectedDatasets:pointclouds.map(e=>e.dataset_id) });
  78975. }
  78976. };
  78977. if(force)fun();
  78978. else Common.intervalTool.isWaiting('clipSelectedDatasets', fun , 300);
  78979. }
  78980. },
  78981. enter:function(){
  78982. this.initViews();
  78983. this.previousView = {
  78984. position: viewer.images360.position,
  78985. target: viewer.scene.view.getPivot(),
  78986. displayMode : Potree.settings.displayMode,
  78987. //---
  78988. ifShowMarker : Potree.settings.ifShowMarker,
  78989. };
  78990. let pointcloud = this.getPointcloud();
  78991. let bound = pointcloud.bound; //只选取其中一个数据集的bound,而非整体,是因为担心两个数据集中间有空隙,于是刚好落在没有点云的地方。
  78992. let boundSize = bound.getSize(new Vector3());
  78993. let target = this.getTarget(bound.getCenter(new Vector3())); //navvis的位置xy是用相机位置 this.ViewService.mainView.getCamera().position 我觉得也可以用第一个漫游点的,或者最接近bound中心的漫游点
  78994. let scale = new Vector3(defaultBoxWidth,defaultBoxWidth, boundSize.z);//z和navvis一样
  78995. let eyeDir = viewer.scene.view.direction.clone().setZ(0/* -boundSize.z/3 */).multiplyScalar(-defaultBoxWidth); //为了使所在楼层不变,不修改z
  78996. //let eyeDir = scale.clone().setZ(boundSize.z/3).multiplyScalar(1.3)
  78997. let position = new Vector3().addVectors(target, eyeDir);
  78998. Potree.settings.displayMode = 'showPointCloud';
  78999. viewer.setView({
  79000. position ,
  79001. target,
  79002. duration:300,
  79003. callback:function(){
  79004. }
  79005. });
  79006. //viewer.setControls(viewer.orbitControls);
  79007. viewer.setLimitFar(false);
  79008. //viewer.setClipState(false) //暂时关闭旧的clipping
  79009. /* new AxisViewer(viewer.mainViewport, viewer.renderArea,{domStyle:{
  79010. bottom: '2px',right: '20px', width:'80px',height:'80px'}
  79011. }) */
  79012. {
  79013. this.box = new BoxVolume$1({
  79014. clip:true
  79015. });
  79016. this.box.clipTask = ClipTask['SHOW_INSIDE_Big' /* "SHOW_INSIDE" */];
  79017. this.box.showBox = false;
  79018. this.box.name = "ClipBox";
  79019. this.box.position.copy(target);
  79020. this.box.scale.copy(scale);
  79021. viewer.controls.setTarget(this.box.position);//绕其旋转
  79022. this.splitScreenTool.focusCenter = this.box.position;
  79023. //带动mapBox
  79024. this.box.addEventListener('position_changed',e=>{
  79025. if(this.showMap){
  79026. this.mapBox.center.setX(this.box.position.x);
  79027. this.mapBox.center.setY(this.box.position.y);
  79028. this.mapBox.updatePoints();
  79029. }
  79030. this.changeCallback();
  79031. });
  79032. this.box.addEventListener('scale_changed',e=>{
  79033. if(this.showMap){
  79034. var scale = this.box.scale;
  79035. this.mapBox.updatePoints(scale);
  79036. }
  79037. this.changeCallback();
  79038. });
  79039. this.box.addEventListener('orientation_changed',e=>{
  79040. if(this.showMap){
  79041. this.mapBox.angle = this.box.rotation.z;
  79042. this.mapBox.rotateBar.rotation.z = this.mapBox.angle;
  79043. this.mapBox.updatePoints();
  79044. }
  79045. this.changeCallback();
  79046. });
  79047. viewer.scene.addVolume(this.box);
  79048. }
  79049. if(this.showMap){//map
  79050. let boxRotateBack = ()=>{//不知道是不是这么写。 因为可能z的旋转不一定都在z
  79051. this.box.rotation.x = 0;
  79052. this.box.rotation.y = 0;
  79053. };
  79054. this.mapBox = new mapClipBox(target, scale);
  79055. viewer.mapViewer.scene.add(this.mapBox);
  79056. //带动box
  79057. this.mapBox.addEventListener('repos',e=>{
  79058. this.box.position.setX(this.mapBox.center.x);
  79059. this.box.position.setY(this.mapBox.center.y);
  79060. boxRotateBack();
  79061. this.changeCallback();
  79062. });
  79063. this.mapBox.addEventListener('dragChange',e=>{
  79064. var scale = this.mapBox.getScale();
  79065. this.box.scale.setX(scale.x);
  79066. this.box.scale.setY(scale.y);
  79067. this.box.position.setX(this.mapBox.center.x);
  79068. this.box.position.setY(this.mapBox.center.y);
  79069. boxRotateBack();
  79070. this.changeCallback();
  79071. });
  79072. this.mapBox.addEventListener('rotate',e=>{
  79073. this.box.rotation.z = this.mapBox.angle;
  79074. boxRotateBack();
  79075. this.changeCallback();
  79076. });
  79077. }
  79078. this.switchView('mainView');
  79079. {
  79080. //viewer.setClipTask(ClipTask["SHOW_INSIDE"])
  79081. }
  79082. Potree.settings.unableNavigate = true;
  79083. Potree.settings.ifShowMarker = false;
  79084. Potree.Utils.updateVisible(viewer.measuringTool.scene, 'clipModel', false);
  79085. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'clipModel', false)//隐藏地图游标
  79086. viewer.inputHandler.toggleSelection(this.box);
  79087. viewer.inputHandler.fixSelection = true;
  79088. viewer.transformationTool.setModeEnable(['scale', 'translation', 'rotation'] );
  79089. viewer.transformationTool.frame.material.color.set(Potree.config.clip.color);//navvis 15899953
  79090. viewer.setPointStandardMat(true);
  79091. if(this.showMap){
  79092. let mapVisi = false;
  79093. this.events = {
  79094. flyToPos : (e)=>{
  79095. let dis = 2;
  79096. let target = e.position;
  79097. target = this.box.position;
  79098. position = e.position;
  79099. //为了方便缩放操作,直接使用box中心作为target
  79100. let duration = e.duration == void 0 ? 1000 : e.duration;
  79101. viewer.scene.view.setView({position, duration, target});
  79102. },
  79103. mapVisiChange(e){
  79104. mapVisi = e.visible;
  79105. let delay = 100; //因resize了camera需要时间更新projectionMatrix
  79106. setTimeout(()=>{
  79107. let boundingBox = Clip.box.boundingBox.clone().applyMatrix4(Clip.box.matrixWorld);
  79108. if(mapVisi){//切换地图
  79109. if(viewer.fpVisiDatasets.length == 0){//不会显示任何一个floorplan图,就要就近移动到一个可见数据集里
  79110. let clouds = viewer.scene.pointclouds.filter(e=>e.visible);
  79111. if(clouds.length == 0)clouds = viewer.scene.pointclouds;
  79112. let scores = clouds.map((e,i)=>{
  79113. return [ -viewer.scene.view.position.distanceToSquared(e.bound2) , i]
  79114. });
  79115. scores = scores.sort((a,b)=> a[0] - b[0]);
  79116. let neareast = clouds[scores[0][1]];
  79117. viewer.flyToDataset({ pointcloud : neareast, duration:0});
  79118. }
  79119. if(Clip.switchMapCount == 0 || !Potree.Utils.getPos2d(viewer.scene.view.position, viewer.mapViewer.viewports[0], viewer.mapViewer.renderArea).inSight
  79120. || !Potree.Utils.isInsideFrustum(boundingBox, viewer.mapViewer.camera)){ //要使box框和游标都在屏幕内。因为游标是3d的当前位置,很可能是准备去框住的位置
  79121. let bound = boundingBox.clone();
  79122. bound.expandByPoint(viewer.scene.view.position);
  79123. let size = bound.getSize(new Vector3);
  79124. let center = bound.getCenter(new Vector3);
  79125. let margin = viewer.mainViewport.resolution.clone().multiplyScalar(0.3);
  79126. viewer.mapViewer.moveTo(center, size, 100, margin);
  79127. }
  79128. Clip.switchMapCount++;
  79129. //关于究竟是focus box还是dataset有点纠结,又或是两个的union。box和数据集可能离得很远,且无法确定当前想选择的数据集,且数据集可能无floorplan, 即使有可能也不展示……
  79130. }else {//切换3d
  79131. if(!Potree.Utils.isInsideFrustum(boundingBox, viewer.scene.getActiveCamera())){//屏幕上没有box的话
  79132. viewer.focusOnObject({boundingBox}, 'boundingBox', 100 );
  79133. }
  79134. }
  79135. },delay);
  79136. }
  79137. };
  79138. this.switchMapCount = 0;
  79139. this.bus.addEventListener('flyToPos',this.events.flyToPos);
  79140. viewer.mapViewer.addEventListener('forceVisible',this.events.mapVisiChange);
  79141. }
  79142. this.editing = true;
  79143. setTimeout(()=>{this.changeCallback(true);},1);
  79144. },
  79145. leave:function(){
  79146. viewer.inputHandler.fixSelection = false;
  79147. viewer.scene.removeVolume(this.box);
  79148. this.showMap && this.mapBox.dispose();
  79149. //viewer.setControls(viewer.fpControls);
  79150. this.switchView('mainView');
  79151. Potree.settings.unableNavigate = false;
  79152. Potree.settings.ifShowMarker = this.previousView.ifShowMarker;
  79153. Potree.Utils.updateVisible(viewer.measuringTool.scene, 'clipModel', true);
  79154. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'clipModel', true)
  79155. viewer.setView(this.previousView);
  79156. viewer.setLimitFar(true);
  79157. viewer.setPointStandardMat(false);
  79158. //viewer.setClipState(true)
  79159. viewer.controls.setTarget(null);
  79160. this.splitScreenTool.focusCenter = null;
  79161. //viewer.mainViewport.axis.dispose()
  79162. cameraProps.forEach(e=>e.openCount = 0);
  79163. if(this.showMap){
  79164. this.bus.removeEventListener('flyToPos',this.events.flyToPos);
  79165. viewer.mapViewer.removeEventListener('forceVisible',this.events.mapVisiChange);
  79166. this.events = null;
  79167. }
  79168. this.editing = false;
  79169. },
  79170. initViews(){
  79171. if(this.views){
  79172. this.views.top.pitch = -Math.PI;
  79173. this.views.top.yaw = 0;
  79174. this.views.front.pitch = 0;
  79175. this.views.front.yaw = 0; //--还原for bugID 44757
  79176. return
  79177. }
  79178. this.views = {};
  79179. this.cameras = {};
  79180. this.orthoCamera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  79181. this.orthoCamera.up.set(0,0,1);
  79182. this.splitScreenTool = new SplitScreen;
  79183. this.targetPlane = viewer.mainViewport.targetPlane = new Plane();
  79184. this.shiftTarget = viewer.mainViewport.shiftTarget = new Vector3; //project在targetPlane上的位置
  79185. for(let i=0;i<2;i++){
  79186. let prop = cameraProps[i];
  79187. let view = new ExtendView();
  79188. this.views[prop.name] = view;
  79189. this.cameras[prop.name] = this.orthoCamera;
  79190. view.name = prop.name;
  79191. view.direction = prop.direction;
  79192. }
  79193. this.views.mainView = viewer.mainViewport.view;
  79194. this.cameras.mainView = viewer.mainViewport.camera;
  79195. },
  79196. switchView(name ){//替换view和camera到mainViewport
  79197. if(this.activeViewName == name)return
  79198. let view = this.views[name];
  79199. let camera = this.cameras[name];
  79200. let prop = cameraProps.find(e=>e.name == name);
  79201. let {boundSize, center, boundingBox} = viewer.bound;
  79202. this.lastViewName = this.activeViewName;
  79203. this.activeViewName = name;
  79204. let lastView = this.views[this.lastViewName];
  79205. let lastCamera = this.cameras[this.lastViewName];
  79206. viewer.mainViewport.view = view;
  79207. viewer.mainViewport.camera = camera;
  79208. if(lastCamera)lastView.zoom = lastCamera.zoom;
  79209. view.zoom && (camera.zoom = view.zoom);
  79210. viewer.updateScreenSize({forceUpdateSize:true});//更新camera aspect left等
  79211. view.applyToCamera(camera);
  79212. let ifFocus;
  79213. let boxBound = Clip.box.boundingBox.clone().applyMatrix4(Clip.box.matrixWorld);
  79214. if(!Potree.Utils.isInsideFrustum(boxBound, camera)){//屏幕上没有box的话
  79215. ifFocus = true;
  79216. }
  79217. if(name == 'mainView'){
  79218. if(lastView){//2d->3d
  79219. }
  79220. if(prop.openCount == 0) ifFocus = false;
  79221. //viewer.fpControls.lockKey = false
  79222. }else {
  79223. this.targetPlane.setFromNormalAndCoplanarPoint( view.direction.clone(), center );
  79224. this.targetPlane.projectPoint(view.position, this.shiftTarget ); //target转换到过模型中心的平面,以保证镜头一定在模型外
  79225. //view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport))
  79226. //if(view.zoom)camera.zoom = view.zoom//恢复上次的zoom
  79227. if(prop.openCount == 0){//至多执行一次
  79228. ifFocus = true;
  79229. }
  79230. if(this.lastViewName == 'mainView'){//3d->2d
  79231. }else {
  79232. }
  79233. ifFocus || this.splitScreenTool.updateCameraOutOfModel(); //更新相机位置
  79234. //if(name == 'top') viewer.mainViewport.alignment = {rotate:true,translate:true};
  79235. if(name == 'front'){
  79236. //viewer.mainViewport.alignment = {translate:true, rotateSide:true, translateVec:new THREE.Vector3(0,0,1)}; //只能上下移动
  79237. viewer.mainViewport.rotateSide = true;
  79238. }else {
  79239. viewer.mainViewport.rotateSide = false;
  79240. }
  79241. //viewer.fpControls.lockKey = true
  79242. }
  79243. ifFocus && this.focusOnObject(this.box);
  79244. //首次到front最好能自动对准box的长边的角度上
  79245. prop.openCount ++;
  79246. },
  79247. focusOnObject(box, duration=0){
  79248. if(this.activeViewName == 'mainView'){
  79249. viewer.focusOnObject({boundingBox:box.boundingBox.clone().applyMatrix4(box.matrixWorld)}, 'boundingBox', duration);
  79250. }else {
  79251. this.orthoMoveFit(box.position, {bound:box.boundingBox.clone().applyMatrix4(box.matrixWorld)}, duration);
  79252. }
  79253. },
  79254. transform(type, axis, value ){//使用按键微调
  79255. this.box[type][axis] += value;
  79256. },
  79257. setModeEnable(type, enable){
  79258. let modes = []
  79259. ;['scale', 'translation', 'rotation'].forEach(e=>{
  79260. if(e == type){
  79261. enable && modes.push(e);
  79262. }else {
  79263. viewer.transformationTool.modesEnabled[e] && modes.push(e);
  79264. }
  79265. });
  79266. viewer.transformationTool.setModeEnable(modes);
  79267. viewer.dispatchEvent('content_changed');
  79268. },
  79269. rotateSideCamera(angle){//侧视图绕模型中心水平旋转到的角度 angle: -180 ~ 180
  79270. let diff = MathUtils.degToRad(angle) - viewer.mainViewport.view.yaw;
  79271. this.splitScreenTool.rotateSideCamera(viewer.mainViewport, diff);
  79272. },
  79273. orthoMoveFit(pos, info, duration){
  79274. var margin = {x:viewer.mainViewport.resolution.x*0.4, y:viewer.mainViewport.resolution.y*0.4};
  79275. this.splitScreenTool.viewportFitBound(viewer.mainViewport, info.bound, pos, duration, margin );
  79276. },
  79277. getPointcloud:function(){ //找一个离当前最近的点云,且最好有漫游点
  79278. let pointclouds = viewer.scene.pointclouds.filter(e=>e.panos.length>0);
  79279. if(pointclouds.length == 0)pointclouds = viewer.scene.pointclouds;
  79280. let result = Common.sortByScore(pointclouds,[],[e=>{
  79281. let center = e.bound.getCenter(new Vector3);
  79282. let size = e.bound.getSize(new Vector3).length() / 2;
  79283. let posToCenter = viewer.images360.position.distanceTo(center);
  79284. return size / posToCenter
  79285. }]);
  79286. return result[0].item
  79287. },
  79288. getTarget:function(boundCenter){//box位置。要找一个有点云的地方。方案1相机位置, 方案2接近相机的漫游点, 方案3接近中心的漫游点。选择方案2,因最大概率有点云
  79289. var target = new Vector3();
  79290. var cameraPos = viewer.images360.position;
  79291. var pano = Common.find(viewer.images360.panos , [], [Images360.sortFunctions.floorDisSquaredToPoint(cameraPos)]);
  79292. if(pano){
  79293. target.copy(pano.position);
  79294. target.setZ(boundCenter.z);
  79295. }else {
  79296. target.copy(boundCenter);
  79297. }
  79298. return target
  79299. },
  79300. /* switchMap:function(state){
  79301. }, */
  79302. download:function( ){
  79303. if(this.getIntersectPointcloud().length == 0){
  79304. return null
  79305. }
  79306. var visiPointclouds = viewer.scene.pointclouds.filter(e=> Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  79307. visiPointclouds.sort((a,b)=>{return a.dataset_id-b.dataset_id});//缓存需要固定排序好比较
  79308. let data = {
  79309. transformation_matrix: visiPointclouds.map((cloud)=>{
  79310. let data = {
  79311. id: cloud.dataset_id,
  79312. matrix : this.getTransformationMatrix(cloud).elements, //剪裁大框
  79313. visiMatrixes: cloud.material.clipBoxes_in.map(e=>this.getTransformationMatrix(cloud, e.inverse).elements), //若干个可见型小框(虽然现在用不到了,因为普通界面不展示这些剪裁区域)
  79314. unVisiMatrixes: cloud.material.clipBoxes_out.map(e=>this.getTransformationMatrix(cloud, e.inverse).elements), //若干个不可见型小框
  79315. modelMatrix:(new Matrix4).copy(cloud.transformMatrix).transpose().elements
  79316. };
  79317. return data
  79318. }) ,
  79319. aabb: "b-0.5 -0.5 -0.5 0.5 0.5 0.5" //剪裁空间( 所有点在乘上这个矩阵后, 还能落在 1 * 1 * 1的box内的点就是所裁剪的
  79320. };
  79321. return data
  79322. },
  79323. downloadNoCrop(){//不剪裁 下载整个点云
  79324. var visiPointclouds = viewer.scene.pointclouds.filter(e=> Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  79325. visiPointclouds.sort((a,b)=>{return a.dataset_id-b.dataset_id});//缓存需要固定排序好比较
  79326. let data = {
  79327. transformation_matrix: visiPointclouds.map((cloud)=>{
  79328. let data = {
  79329. id: cloud.dataset_id,
  79330. matrix : new Matrix4().elements, //固定值
  79331. modelMatrix:(new Matrix4).copy(cloud.transformMatrix).transpose().elements
  79332. };
  79333. return data
  79334. }) ,
  79335. aabb: "b-12742000 -12742000 -12742000 12742000 12742000 12742000" //固定剪裁空间
  79336. };
  79337. console.log(data);
  79338. return data
  79339. },
  79340. getTransformationMatrix:function(pointcloud, invMatrix) {//剪裁矩阵
  79341. var invMatrix = invMatrix || this.box.matrixWorld.clone().invert();
  79342. return (new Matrix4).multiplyMatrices(invMatrix, pointcloud.transformMatrix).transpose()
  79343. },
  79344. getIntersectPointcloud(){
  79345. var intersect = (pointcloud)=>{
  79346. if(pointcloud.intersectBox(this.box.matrixWorld))return true
  79347. };
  79348. return viewer.scene.pointclouds.filter(e=>intersect(e))
  79349. },
  79350. getRulerBound(){//坐标尺边界
  79351. let camera = viewer.mainViewport.camera;
  79352. if(!camera.isOrthographicCamera)return
  79353. let w = camera.right / camera.zoom; //half
  79354. let h = camera.top / camera.zoom;
  79355. let points = [];
  79356. var boundAtCamera = new Box3();
  79357. Clip.box.children[0].geometry.vertices.forEach(e=>{ //模仿getPosWithFullBound
  79358. let p = e.clone().applyMatrix4(Clip.box.matrixWorld);
  79359. points.push(p);
  79360. let p1 = p.clone().applyMatrix4(camera.matrixWorldInverse);
  79361. boundAtCamera.expandByPoint(p1);
  79362. });
  79363. //需要找出clipbox的bound的左上角,它在标尺中是原点
  79364. let ClipBoxLeftTop = new Vector2(boundAtCamera.min.x, boundAtCamera.max.y); //相对于相机的位置
  79365. let camPos = new Vector2(-ClipBoxLeftTop.x, ClipBoxLeftTop.y);//由于ClipBoxLeftTop要变换到原点,所以相机位置就成了ClipBoxLeftTop的相反数, 但因是从上到下所以y再乘-1
  79366. let bound_ = {
  79367. left: camPos.x - w,
  79368. right: camPos.x + w,
  79369. bottom: camPos.y + h, //注意从上到下增大
  79370. top: camPos.y - h,
  79371. };
  79372. //console.log(bound)
  79373. return bound_
  79374. },
  79375. screenshot: async (rulerBound, rulerMargin, unitText='像素 : 米' )=>{ //测绘图下载。顶视图|侧视图
  79376. return new Promise((resolve,reject)=>{
  79377. if(Clip.screenshoting )return reject()
  79378. let visiPointclouds = viewer.scene.pointclouds.filter(e=> Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  79379. let camera = viewer.mainViewport.camera;
  79380. //if(Clip.activeViewName == 'mainView')return reject()
  79381. const maxWidth = 8192, minWidth = Potree.browser.urlHasValue('clipMinWidth',true) || 1024; //图片尺寸最大最小值。
  79382. //Potree.settings.pointDensity = 'ultraHigh'
  79383. viewer.inputHandler.deselectAll();
  79384. Clip.box.visible = false;
  79385. Clip.screenshoting = true;
  79386. let material = new ExtendPointCloudMaterial;
  79387. material.pointSizeType = Potree.PointSizeType.FIXED; //Potree.PointSizeType
  79388. material.size = Potree.browser.urlHasValue('clipPointSize',true) || 1;
  79389. material.uniforms.minSize.value = 0.1;
  79390. material.activeAttributeName = 'rgba';
  79391. //material.classification = pointcloud.material.classification;
  79392. material.clipBoxBig_in = visiPointclouds[0].material.clipBoxBig_in;
  79393. material.shaderNeedsUpdate = true;
  79394. material.bigClipInBox = visiPointclouds[0].material.bigClipInBox;
  79395. let materials = visiPointclouds.map(e=>{
  79396. let mat = e.material;
  79397. e.material = material;
  79398. return mat
  79399. });
  79400. //根据boundingBox尺寸来定图片尺寸
  79401. let boundingBox = Clip.box.boundingBox.clone().applyMatrix4(Clip.box.matrixWorld);
  79402. let points = [];
  79403. var bound = new Box3();
  79404. Clip.box.children[0].geometry.vertices.forEach(e=>{ //模仿getPosWithFullBound
  79405. let p = e.clone().applyMatrix4(Clip.box.matrixWorld);
  79406. points.push(p);
  79407. let p1 = p.clone().applyMatrix4(camera.matrixWorldInverse);
  79408. bound.expandByPoint(p1);
  79409. });
  79410. let boundSize = bound.getSize(new Vector3);
  79411. let minZoom = Potree.browser.urlHasValue('clipZoom',true) || 80; //1px = 1个点 = 1cm , 如果一个点都是1cm的话
  79412. //zoom不宜过大或过小,过小点云重叠、画面模糊;过大点云有间隙,纹理就看不清
  79413. //中间部分75-80为佳,文字100,边缘50. 最好支持调节 . 且当下载尺寸变大往往点云也多,可能冲破pointbudget限制
  79414. //let text = `1 : ${(1 / camera.zoom).toFixed(4)}(像素 : 米)`
  79415. let w = boundSize.x * minZoom;
  79416. let h = boundSize.y * minZoom;
  79417. let max = Math.max(w,h);
  79418. let s = 1;
  79419. if(max > maxWidth){
  79420. s = maxWidth/max;
  79421. }else if(max < minWidth){
  79422. s = minWidth/max;
  79423. }
  79424. w *= s, h *= s;
  79425. material.size *= s;
  79426. s != 1 && console.log('宽度缩放倍数',s);
  79427. //虽然size>1就是浪费像素,但是太小了视觉效果有点差……可能因为fov不真实。 点云大就像是老式电视机虽然显示像素量少但感觉不出画面模糊,且边缘锐利。
  79428. w = Math.round(w);
  79429. h = Math.round(h);
  79430. let focusObjectInfo = [{boundingBox, points}, 'boundingBox', 0, { dontChangeCamDir:true, dontMoveMap:true, boundScale:1 }];
  79431. //分块渲染截图,最后拼合图片。需要使每一块的点数不超过pointBudget, 且尺寸不超过4096(会崩溃),过小的话一般不会超过pointBudget,除非是深度较大后排点云多。
  79432. let 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,就是括号里的数字,给大概值)
  79433. //let r = THREE.Math.clamp(1024 / boundSize.z, 256, 4096);
  79434. let wc = w / r; //横向块数
  79435. let hc = h / r; //纵向块数
  79436. let splitRenderInfo = (wc > 1 || hc > 1) && {wc: Math.ceil(wc), hc:Math.ceil(hc)}; //因为结果需要化为整数所以可能不太理想, 分割数过多。 另外如果面积小但是因z过长而超出pointBudget没关系,因后排点云无需绘制
  79437. console.log({wc,hc,w,h});
  79438. let meterPerPixel = boundSize.x / w;
  79439. let text = `1 : ${(meterPerPixel).toFixed(4)}(${unitText})`;
  79440. let beforeScreenshot = ()=>{
  79441. if(rulerBound){
  79442. let ruler = Clip.getRulerBound();
  79443. Object.assign(rulerBound,ruler);
  79444. }
  79445. };
  79446. let {getImagePromise, finishPromise} = viewer.startScreenshot({ type: 'default', bgOpacity:0, focusObjectInfo, maxTimeForPointLoad : 3e5, pointDensity:'screenshot2', splitRenderInfo, beforeScreenshot }, w, h, 1 );
  79447. finishPromise.done(({dataUrl}) => {
  79448. viewer.inputHandler.toggleSelection(Clip.box);
  79449. Clip.box.visible = true;
  79450. let img = new Image;
  79451. img.src = dataUrl;
  79452. img.onload = async ()=>{//加上标尺比例水印
  79453. //固定文字大小和边距像素 //如果有一边过小,可能超出画面外,暂时不管这种可能
  79454. const fontsize = math.linearClamp(w, [100, 700, 8000], [12, 20, 30]);
  79455. const marginSelf = {//img外的margin(标尺内)
  79456. left : rulerBound ? 76 : 40,
  79457. right : rulerBound ? 30 : 40,
  79458. bottom : rulerBound ? 20 + fontsize*2 : 40 + fontsize*2,
  79459. top : rulerBound ? 60 : 40,
  79460. };
  79461. //const Margin = rulerMargin + marginSelf
  79462. //文字的边距
  79463. let bottomRatioToImg = - Math.min(fontsize*2.5, rulerBound ? marginSelf.bottom : marginSelf.bottom*0.9 ) / h;//- (marginSelf.bottom - fontsize)/ h //在img之下. text底部到img底部的距离
  79464. //let leftRatioToImg = Margin / w
  79465. let labelInfo = {
  79466. bottomRatioToImg, horizonCenter:true,//leftRatioToImg,
  79467. textColor: rulerBound ? {r: 0, g: 0, b: 0, a: 1} : { r: 255, g: 255, b: 255, a: 1 },
  79468. textBorderColor : { r: 30, g: 30, b: 30, a: 1 },
  79469. textBorderThick : rulerBound ? 0 : 1 ,
  79470. fontsize,
  79471. fontWeight: rulerBound ? 'normal':'Bold',
  79472. outputCanvas : !!rulerBound,
  79473. bgColor: rulerBound ? {r:255,g:255,b:255,a:255}:null
  79474. };
  79475. labelInfo.bgMargin = {//img外需要多少margin
  79476. left: marginSelf.left + rulerMargin, //rulerMargin是在标尺外的margin
  79477. bottom : marginSelf.bottom + rulerMargin,
  79478. right: marginSelf.right + rulerMargin,
  79479. top: marginSelf.top + rulerMargin
  79480. };
  79481. if(rulerBound){//因为margin 扩大bound
  79482. rulerBound.left -= marginSelf.left * meterPerPixel;
  79483. rulerBound.right += marginSelf.right * meterPerPixel;
  79484. rulerBound.top -= marginSelf.top * meterPerPixel;
  79485. rulerBound.bottom += marginSelf.bottom * meterPerPixel;
  79486. }
  79487. //console.log('topRatioToImg',topRatioToImg,'leftRatioToImg',leftRatioToImg,'fontsize', labelInfo.fontsize)
  79488. let result = await Potree.Utils.imgAddText(img, text , labelInfo );
  79489. //Common.downloadFile(finalDataUrl, 'screenshot11.png')
  79490. visiPointclouds.forEach((e,i)=>e.material = materials[i]);
  79491. Clip.screenshoting = false;
  79492. viewer.viewports = [viewer.mainViewport];
  79493. resolve(result);
  79494. };
  79495. });
  79496. })
  79497. /*
  79498. 隐患:无法获知最大可加载的点的数量,也未知需要加载的点的数量。需要掌控好分块数量,避免因pointBudget限制造成周围的点稀疏。
  79499. 加载点云时间过久
  79500. */
  79501. return finishPromise
  79502. }
  79503. };
  79504. /*
  79505. 裁剪点云时,2D界面显示全部平面图,按楼层切换显示。
  79506. 所有点云下载后点云所带的本地坐标都是场景显示的local坐标,这样才能看起来一样。
  79507. 且为了使之和坐标页面对应,坐标页面的本地坐标也是local,而非mesh_local.
  79508. //保存box
  79509. viewer.modules.Clip.box.matrix
  79510. //恢复box
  79511. let a = new THREE.Matrix4().fromArray([
  79512. 14.189120116830964,
  79513. 0,
  79514. 0,
  79515. 0,
  79516. 0,
  79517. 9.924790069368392,
  79518. 0,
  79519. 0,
  79520. 0,
  79521. 0,
  79522. 0.8751009568437951,
  79523. 0,
  79524. -7.433819981633984,
  79525. 1.528696446650445,
  79526. 2.9412375879215977,
  79527. 1
  79528. ])
  79529. a.decompose(viewer.modules.Clip.box.position,viewer.modules.Clip.box.quaternion,viewer.modules.Clip.box.scale)
  79530. viewer.modules.Clip.rotateSideCamera(-93)
  79531. */
  79532. const viewportProps = [
  79533. {
  79534. left:0.5,
  79535. bottom:0.5,
  79536. width: 0.5,height:0.5,
  79537. name : 'MainView',
  79538. //view: viewer.scene.view,
  79539. active: true,
  79540. },
  79541. {
  79542. left:0,
  79543. bottom:0.5,
  79544. width: 0.5,height:0.5,
  79545. name : 'top',
  79546. name2 : 'mapViewport',
  79547. axis:["x","y"],
  79548. direction : new Vector3(0,0,-1), //镜头朝向
  79549. //axisSign:[1,1],
  79550. active: true,
  79551. //相机位置在z轴正向
  79552. },
  79553. {
  79554. left:0.5,
  79555. bottom:0,
  79556. width: 0.5,height:0.5,
  79557. name : 'right',
  79558. axis:["y","z"],
  79559. direction : new Vector3(1,0,0),
  79560. //axisSign:[1,1],
  79561. active: true,
  79562. //相机位置在x轴负向 右下角屏
  79563. },
  79564. {
  79565. left:0,
  79566. bottom:0,
  79567. width: 0.5,height:0.5,
  79568. name : 'back',
  79569. axis:["x","z"],
  79570. direction : new Vector3(0,-1,0),
  79571. //axisSign:[-1,1], // 从镜头方向看 x向左 所以取负
  79572. active: true,
  79573. //相机位置在y轴正向 左下角屏
  79574. },
  79575. ];
  79576. var SplitScreen4Views = new SplitScreen();
  79577. SplitScreen4Views.split = function(o={}){
  79578. var defaultCamera = viewer.scene.getActiveCamera();
  79579. let {boundSize, center} = viewer.bound;
  79580. viewer.setLimitFar(false);
  79581. viewer.mapViewer.attachToMainViewer(true,'split4Screens','dontSet');
  79582. viewer.renderer.clear(); //clear back的viewport左边的1px宽的部分,因setScissor的bug
  79583. let viewports = this.splitStart(viewportProps);
  79584. //覆盖在map上、点云等其他物体之下的一层背景
  79585. let mapViewport = viewer.mapViewer.viewports[0];
  79586. mapViewport.noPointcloud = false;
  79587. //隐藏地图游标
  79588. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'split4Screens', false)
  79589. /* viewer.images360.panos.forEach(pano=>{
  79590. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', false) //希望这时候mapMarker已经建好了吧
  79591. }) */
  79592. /* viewer.images360.panos.forEach(pano=>{
  79593. pano.addLabel2()
  79594. Potree.Utils.updateVisible(pano.label2, 'notDisplay', true)
  79595. pano.dispatchEvent({type:'changeMarkerTex',name:'ring'})
  79596. }) */
  79597. //材质
  79598. this.statesBefore = {
  79599. pointDensity : Potree.settings.pointDensity,
  79600. displayMode : Potree.settings.displayMode,
  79601. position: viewer.images360.position,
  79602. target: viewer.scene.view.getPivot(),
  79603. currentPano: viewer.images360.currentPano,
  79604. //---
  79605. //ifShowMarker : Potree.settings.ifShowMarker,
  79606. };
  79607. viewer.setPointStandardMat(true,null,true); //切换到标准模式(主要为了mainViewport) 点云使用标准大小
  79608. var matBefore = {
  79609. opacity : new Map()
  79610. };
  79611. var newOpacityMap = new Map();
  79612. viewer.scene.pointclouds.forEach(e=>{
  79613. matBefore.opacity.set(e, e.temp.pointOpacity);
  79614. matBefore.colorType = e.material.activeAttributeName;
  79615. /* {
  79616. var map = new Map()
  79617. newOpacityMap.set(e, map )
  79618. var size = e.bound.getSize()
  79619. viewports.forEach(viewport=>{//根据bound设置opacity,越小的要靠越近,需要大的opacity。但似乎影响太大了
  79620. if(viewport.name == 'MainView')return;
  79621. var prop = viewportProps.find(v => viewport.name == v.name2||viewport.name == v.name)
  79622. let axis = prop.axis
  79623. var width = size[axis[0]]
  79624. var height = size[axis[1]]
  79625. var area = width * height
  79626. map.set(viewport, 5000/area);
  79627. })
  79628. } */
  79629. });
  79630. let beforeRender = function(){
  79631. viewer.dealBeforeRender = true; //使不全部渲染
  79632. viewer.scene.pointclouds.forEach(e=>{
  79633. if(this.name == "MainView"){
  79634. e.material.activeAttributeName = matBefore.colorType; // 'rgba'
  79635. e.material.useFilterByNormal = false;
  79636. //e.material.pointSizeType = Potree.config.material.pointSizeType
  79637. e.changePointOpacity(matBefore.opacity.get(e)); //1 //恢复下 e.temp.pointOpacity 其实就是1
  79638. Potree.settings.pointDensity = 'fourViewportsMain';/* 'fourViewports' */ //本来想比另外三屏高一点质量,结果发现会闪烁,因为点云加载需要时间 (navvis仿版也是一样,以后看看能否优化)
  79639. }else {
  79640. e.material.activeAttributeName = "color";
  79641. e.material.useFilterByNormal = true;
  79642. //e.material.pointSizeType = 'ADAPTIVE'
  79643. Potree.settings.pointDensity = 'fourViewports'; //强制降低点云质量
  79644. //侧面重叠概率更大,所以透明度调小
  79645. e.changePointOpacity(this.name == "mapViewport" ? 0.5 : 0.1/* newOpacityMap.get(e).get(viewport), true */); //多数据集有的数据集很小,放大后显示特别淡
  79646. //console.log(e.name, viewport.name, e.temp.pointOpacity, e.material.opacity)
  79647. }
  79648. viewer.images360.panos.forEach(pano=>{
  79649. if(this.name == 'mapViewport'){
  79650. Potree.Utils.updateVisible(pano.marker, 'showOnMap', true, 1, 'add' );
  79651. }else {
  79652. Potree.Utils.updateVisible(pano.marker, 'showOnMap', false, 1, 'cancel' );
  79653. }
  79654. });
  79655. });
  79656. viewer.dealBeforeRender = false;
  79657. };
  79658. viewports.forEach(viewport=>{
  79659. viewport.beforeRender = beforeRender;
  79660. new AxisViewer(viewport, viewer.renderArea,{domStyle:{
  79661. top: '22px',//viewport.name == 'mapViewport' ? '2px' : '-25px',
  79662. right: (viewport.name == 'mapViewport') ? '30px' : '2px',
  79663. width:'80px',height:'80px'}
  79664. });
  79665. });
  79666. this.enableMap(false);
  79667. this.enableFloorplan(false);
  79668. viewer.mapViewer.setViewLimit('null'); //多数据集距离远时可以任意远,所以不限制了。但是这样就会看到地图边界了怎么办?超出后让地图隐藏?
  79669. //viewer.dispatchEvent({'type': 'beginSplitView' })
  79670. //viewer.updateScreenSize({forceUpdateSize:true})
  79671. //this.viewportFitBound(mapViewport, boundSize, center)
  79672. //Potree.settings.ifShowMarker = false
  79673. Potree.settings.displayMode = 'showPointCloud';
  79674. };
  79675. SplitScreen4Views.recover = function(){
  79676. viewer.viewports.forEach(e=>{e.axis.dispose();});
  79677. this.unSplit();
  79678. viewer.mapViewer.viewports[0].beforeRender = null;
  79679. /* const {width, height} = viewer.renderer.getSize(new THREE.Vector2());
  79680. viewer.renderer.setViewport(0,0,width,height)
  79681. viewer.renderer.setScissorTest( false ); */
  79682. viewer.setView({
  79683. position: this.statesBefore.position,
  79684. target: this.statesBefore.target,
  79685. currentPano: this.statesBefore.currentPano,
  79686. duration:300,
  79687. callback:function(){
  79688. }
  79689. });
  79690. viewer.mainViewport.beforeRender = null;
  79691. viewer.setLimitFar(true);
  79692. let mapViewport = viewer.mapViewer.viewports[0];
  79693. viewer.mapViewer.attachToMainViewer(false);
  79694. //Potree.Utils.updateVisible(viewer.mapViewer.cursor, 'split4Screens', true)
  79695. /* viewer.images360.panos.forEach(pano=>{
  79696. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', true)
  79697. }) */
  79698. /* viewer.images360.panos.forEach(pano=>{
  79699. Potree.Utils.updateVisible(pano.label2, 'notDisplay', false )
  79700. pano.dispatchEvent({type:'changeMarkerTex',name:'default'})
  79701. }) */
  79702. mapViewport.noPointcloud = true;
  79703. {
  79704. this.enableMap(Potree.settings.mapEnable);
  79705. this.enableFloorplan(Potree.settings.floorplanEnable);
  79706. if(this.floorplanListener){
  79707. viewer.mapViewer.mapLayer.removeEventListener( 'floorplanLoaded', this.floorplanListener );
  79708. this.floorplanListener = null;
  79709. }
  79710. }
  79711. Potree.settings.pointDensity = this.statesBefore.pointDensity;
  79712. if(!Potree.settings.isOfficial){
  79713. Potree.settings.displayMode = this.statesBefore.displayMode;
  79714. }
  79715. viewer.scene.pointclouds.forEach(e=>{
  79716. e.material.useFilterByNormal = false;
  79717. //e.material.pointSizeType = Potree.config.material.pointSizeType
  79718. });
  79719. viewer.setPointStandardMat(false);
  79720. viewer.mapViewer.setViewLimit('standard');
  79721. viewer.images360.panos.forEach(pano=>{
  79722. Potree.Utils.updateVisible(pano.marker, 'showOnMap', false, 1, 'cancel' );
  79723. });
  79724. //Potree.settings.ifShowMarker = this.statesBefore.ifShowMarker
  79725. //viewer.dispatchEvent({'type': 'finishSplitView' })
  79726. //viewer.updateScreenSize({forceUpdateSize:true})
  79727. };
  79728. SplitScreen4Views.updateMapViewerBG = function(){
  79729. let mapViewport = viewer.mapViewer.viewports[0];
  79730. if(this.splited && (this.floorplanEnabled || this.mapEnabled)){
  79731. mapViewport.background = 'overlayColor';
  79732. mapViewport.backgroundColor = new Color(0,0,0);
  79733. mapViewport.backgroundOpacity = 0.5;
  79734. }else {
  79735. mapViewport.background = null;
  79736. mapViewport.backgroundColor = null;
  79737. mapViewport.backgroundOpacity = null;
  79738. }
  79739. viewer.mapViewer.mapChanged = true;
  79740. viewer.mapViewer.needUpdate = true;
  79741. };
  79742. SplitScreen4Views.setFloorplanDisplay = function(e, show=false){
  79743. e.floorplan.setEnable(show);
  79744. };
  79745. SplitScreen4Views.enableMap = function(enable){
  79746. let map = viewer.mapViewer.mapLayer.maps.find(e=>e.name == 'map');
  79747. map.setEnable(!!enable);
  79748. //viewer.mapViewer.mapGradientBG = viewer.background == 'gradient' && !enable
  79749. this.mapEnabled = enable;
  79750. this.updateMapViewerBG();
  79751. },
  79752. //直接覆盖原设置
  79753. SplitScreen4Views.enableFloorplan = function(enable){ //是否让自定义的平面图显示
  79754. let floorplans = viewer.mapViewer.mapLayer.maps.filter(e=>e.name.includes('floorplan'));
  79755. if(this.floorplanListener){
  79756. viewer.mapViewer.mapLayer.removeEventListener( 'floorplanLoaded', this.floorplanListener );
  79757. }
  79758. this.floorplanListener = (e)=>{
  79759. this.setFloorplanDisplay(e, enable);
  79760. };
  79761. viewer.mapViewer.mapLayer.addEventListener( 'floorplanLoaded', this.floorplanListener ); //万一之后才加载
  79762. if(!enable){
  79763. //隐藏平面图
  79764. floorplans.forEach(floorplan=>this.setFloorplanDisplay({floorplan},false));
  79765. }else {
  79766. floorplans.forEach(floorplan=>this.setFloorplanDisplay({floorplan},true));
  79767. }
  79768. if (enable && floorplans.length == 0) Potree.loadMapEntity('all',true);
  79769. this.floorplanEnabled = enable;
  79770. this.updateMapViewerBG();
  79771. },
  79772. /* viewportFitBound:function(viewport, boundSize, center){ //使一个viewport聚焦在某个范围
  79773. var prop = viewportProps.find(v => viewport.name == v.name2||viewport.name == v.name)
  79774. let axis = prop.axis
  79775. let expand = 10;
  79776. let position = center.clone()
  79777. var moveAtAxis = ['x','y','z'].find(e=>!(axis.includes(e)))
  79778. if(viewport.name == 'mapViewport'){
  79779. let ori = viewport.view.position[moveAtAxis]
  79780. position[moveAtAxis] = ori //不改变这个值,尤其是mapViewer中的z
  79781. }else{
  79782. position[moveAtAxis] += boundSize[moveAtAxis]/2+expand//移动到bounding边缘外
  79783. }
  79784. viewport.view.position.copy(position)
  79785. var width = Math.max(boundSize[axis[0]], boundSize[axis[1]] * viewport.camera.aspect)//视口宽度(米)
  79786. var margin = 50 //px
  79787. viewport.camera.zoom = (viewport.resolution.x - margin) / width
  79788. viewport.camera.updateProjectionMatrix()
  79789. },
  79790. */
  79791. SplitScreen4Views.focusOnPointCloud = function(pointcloud){//三个屏都聚焦在这个点云
  79792. var boundSize = pointcloud.bound.getSize(new Vector3);
  79793. var center = pointcloud.bound.getCenter(new Vector3);
  79794. let target = pointcloud.panosBound && pointcloud.panosBound.center; //看向pano集中的地方,也就是真正有点云的地方。(因为需要展示所有点云,所以没办法用这个做为center)
  79795. this.focusOnObject(pointcloud.bound, center,target);
  79796. viewer.flyToDataset({pointcloud, dontMoveMap:true, duration:0});
  79797. };
  79798. SplitScreen4Views.focusOnObject = function(bound, center, target, duration=0){
  79799. viewer.viewports.forEach(e=>{
  79800. if(e.name == 'MainView'){
  79801. /* let len = boundSize.length()
  79802. let distance = THREE.Math.clamp(e.view.position.distanceTo(center), len * 0.01, len*0.3 ) //距离限制
  79803. //viewer.focusOnObject({position:center}, 'point', duration, {distance, direction: e.view.direction,dontMoveMap:true} )//平移镜头
  79804. //为了方便定位,直接飞到中心位置:
  79805. e.view.setView({
  79806. position:center, duration, target
  79807. }) */
  79808. }else {
  79809. this.viewportFitBound(e, bound, center);
  79810. }
  79811. });
  79812. };
  79813. var Alignment = {
  79814. SplitScreen: SplitScreen4Views,
  79815. handleState:null, //操作状态 'translate'|'rotate'
  79816. bus: new EventDispatcher(),
  79817. /* prepareRecord : true,
  79818. writeToHistory(pointclouds){
  79819. if(!this.prepareRecord)return;
  79820. this.prepareRecord = false
  79821. let content = this.getTemp(pointclouds)
  79822. this.history.writeIn(content)
  79823. },
  79824. undo(){//撤销一步
  79825. let last = this.history.pop();
  79826. last && last.forEach(item=>{
  79827. this.applyTemp(item)
  79828. })
  79829. }, */
  79830. applyTemp(item){
  79831. var pointcloud = viewer.scene.pointclouds.find(p=>p.dataset_id+p.name == item.sid);
  79832. pointcloud.orientationUser = item.orientationUser;
  79833. pointcloud.translateUser = item.translateUser;
  79834. this.setMatrix( pointcloud );
  79835. },
  79836. getTemp(pointclouds){//记录最近一次保存后的状态,便于恢复
  79837. pointclouds = pointclouds || viewer.scene.pointclouds;
  79838. return pointclouds.map(e=>{
  79839. return {
  79840. sid : e.dataset_id+e.name,
  79841. orientationUser : e.orientationUser,
  79842. translateUser : e.translateUser.clone(),
  79843. }
  79844. } )
  79845. },
  79846. init:function(){
  79847. let transfromInfo;
  79848. this.history = new History({
  79849. applyData: (data)=>{
  79850. data.forEach(item=>{
  79851. Alignment.applyTemp(item);
  79852. });
  79853. return true
  79854. },
  79855. getData:(pointclouds)=>{
  79856. return Alignment.getTemp(pointclouds)
  79857. }
  79858. });
  79859. viewer.fpControls.addEventListener("transformPointcloud",(e)=>{
  79860. if(e.pointclouds[0].dataset_id == Potree.settings.originDatasetId){//禁止手动移动初始数据集
  79861. return this.bus.dispatchEvent('forbitMoveOriginDataset')
  79862. }
  79863. this.history.beforeChange(e.pointclouds);
  79864. //this.writeToHistory( e.pointclouds )
  79865. if(!transfromInfo){
  79866. transfromInfo = {pointclouds:e.pointclouds};
  79867. }
  79868. if(this.handleState == 'translate'){
  79869. e.pointclouds.forEach(cloud=>Alignment.translate(cloud, e.moveVec));
  79870. }else if(this.handleState == 'rotate'){
  79871. if(Potree.settings.editType == 'pano'){
  79872. //旋转中心是intersectStart的版本
  79873. /* let center = e.intersectStart //旋转中心是mousedown的位置
  79874. if(e.intersect.equals(center))return
  79875. if(!transfromInfo){
  79876. transfromInfo = {
  79877. orientationUser : e.pointclouds[0].orientationUser,
  79878. //vecStart : e.moveVec, // 首次移动向量 只有八个方向,精度太小,所以延迟
  79879. pointclouds: e.pointclouds
  79880. }
  79881. this.bus.dispatchEvent({type:'rotateStart', startPoint:center})
  79882. return
  79883. }else if(!transfromInfo.vecStart){
  79884. let vec = new THREE.Vector3().subVectors(e.intersect, center).setZ(0)
  79885. if(vec.length() * e.camera.zoom > 30){ //在屏幕上距离初始点有一定距离后开始算
  79886. //console.log('moveVec',vec)
  79887. transfromInfo.vecStart = vec
  79888. } */
  79889. let center = e.pointclouds[0].translateUser; //旋转中心是第一个点云的位置
  79890. if(e.intersect.equals(center))return
  79891. if(!transfromInfo.vecStart){
  79892. transfromInfo.orientationUser = e.pointclouds[0].orientationUser;
  79893. transfromInfo.vecStart = new Vector3().subVectors(e.intersectStart, center).setZ(0);
  79894. }else {
  79895. let vec = new Vector3().subVectors(e.intersect, center).setZ(0);
  79896. let angle = math.getAngle(transfromInfo.vecStart,vec,'z');
  79897. let diffAngle = transfromInfo.orientationUser + angle - transfromInfo.pointclouds[0].orientationUser;
  79898. transfromInfo.pointclouds.forEach(cloud=>{
  79899. /* let centerNoTranfrom = Potree.Utils.datasetPosTransform({ toDataset: true, pointcloud:cloud, position: center }) //中心点在数据集中的位置
  79900. Alignment.rotate(cloud, null, diffAngle)
  79901. let centerNow = Potree.Utils.datasetPosTransform({ fromDataset: true, pointcloud:cloud, position: centerNoTranfrom }) //中心点的现在位置
  79902. let shift = new THREE.Vector3().subVectors( center, centerNow); //偏移量
  79903. Alignment.translate(cloud,shift) //使center还保留在原位
  79904. //let centerNow1 = Potree.Utils.datasetPosTransform({ fromDataset: true, pointcloud:transfromInfo.pointcloud, position: centerNoTranfrom }) //中心点的现在位置
  79905. */
  79906. Alignment.rotateAround(center, cloud, null, diffAngle);
  79907. });
  79908. }
  79909. //this.bus.dispatchEvent({type:'rotate', endPoint: e.intersect})
  79910. }else {
  79911. let center = e.pointclouds[0].translateUser; //移动到的位置就是中心
  79912. if(e.intersect.equals(center))return
  79913. if(!transfromInfo.vecStart){
  79914. transfromInfo.orientationUser = e.pointclouds[0].orientationUser;
  79915. transfromInfo.vecStart = new Vector3().subVectors(e.intersectStart, center).setZ(0);
  79916. }else {
  79917. let vec = new Vector3().subVectors(e.intersect, center).setZ(0);
  79918. let angle = math.getAngle(transfromInfo.vecStart,vec,'z');
  79919. let diffAngle = transfromInfo.orientationUser + angle - transfromInfo.pointclouds[0].orientationUser;
  79920. Alignment.rotate(transfromInfo.pointclouds[0], null, diffAngle);
  79921. }
  79922. }
  79923. }
  79924. });
  79925. viewer.fpControls.addEventListener("end",(e)=>{
  79926. transfromInfo && this.history.afterChange(transfromInfo.pointclouds );
  79927. transfromInfo = null;
  79928. });
  79929. // cursor:
  79930. let updateCursor = (e)=>{
  79931. if(e.drag || !this.editing)return //仅在鼠标不按下时更新:
  79932. let handleState = Alignment.handleState;
  79933. if(e.hoverViewport.alignment && handleState && e.hoverViewport.alignment[handleState]){
  79934. if(handleState == 'translate'){
  79935. if( e.intersect && e.intersect.location ){
  79936. viewer.dispatchEvent({
  79937. type : "CursorChange", action : "add", name:"movePointcloud"
  79938. });
  79939. }else {
  79940. viewer.dispatchEvent({
  79941. type : "CursorChange", action : "remove", name:"movePointcloud"
  79942. });
  79943. }
  79944. }else if(handleState == 'rotate'){
  79945. if( e.intersect && e.intersect.location ){
  79946. viewer.dispatchEvent({
  79947. type : "CursorChange", action : "add", name:"rotatePointcloud"
  79948. });
  79949. }else {
  79950. viewer.dispatchEvent({
  79951. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  79952. });
  79953. }
  79954. }
  79955. }else {
  79956. //清空:
  79957. viewer.dispatchEvent({
  79958. type : "CursorChange", action : "remove", name:"movePointcloud"
  79959. });
  79960. viewer.dispatchEvent({
  79961. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  79962. });
  79963. }
  79964. };
  79965. viewer.addEventListener('global_mousemove',updateCursor);
  79966. viewer.addEventListener('global_drop',updateCursor);//拖拽结束
  79967. viewer.addEventListener('updateModelBound', (e)=>{
  79968. if(this.editing){
  79969. this.SplitScreen.updateCameraOutOfModel();
  79970. }
  79971. });
  79972. },
  79973. setMatrix : function(pointcloud){
  79974. var vec1 = pointcloud.position; //position为数据集内部的偏移,在navvis中对应的是dataset.pointCloudSceneNode的children[0].position
  79975. var vec2 = pointcloud.translateUser;
  79976. var angle = pointcloud.orientationUser;
  79977. var pos1Matrix = new Matrix4().setPosition(vec1);//先移动到点云本身应该在的初始位置(在4dkk里和其他应用中都是在这个位置的,也能和漫游点对应上)
  79978. var rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0,0,1), angle);//再旋转
  79979. var pos2Matrix = new Matrix4().setPosition(vec2);//最后是平移
  79980. var matrix = new Matrix4().multiplyMatrices(pos2Matrix, rotMatrix);
  79981. pointcloud.transformMatrix = matrix.clone();//为该数据集的变化矩阵。 对应navvis的m2w_
  79982. pointcloud.transformInvMatrix.copy(pointcloud.transformMatrix).invert();
  79983. pointcloud.rotateMatrix = rotMatrix;
  79984. pointcloud.rotateInvMatrix.copy(rotMatrix).invert();
  79985. pointcloud.panos.forEach(e=>e.transformByPointcloud());
  79986. matrix = new Matrix4().multiplyMatrices(matrix, pos1Matrix);
  79987. //matrix.premultiply(viewer.scene.scene.matrix);////////////////////////add
  79988. pointcloud.matrix = matrix;
  79989. //pointcloud.matrixWorldNeedsUpdate = true //更新matrixWorld (非计算,直接赋值)
  79990. pointcloud.updateMatrixWorld(true);
  79991. if(this.editing){
  79992. Alignment.changeCallBack && Alignment.changeCallBack();
  79993. }
  79994. if(pointcloud.spriteNodeRoot){
  79995. pointcloud.spriteNodeRoot.matrixWorld.copy(pointcloud.matrixWorld);//.multiplyMatrices(pointcloud.matrixWorld, pointcloud.matrixWorld);
  79996. }
  79997. viewer.boundNeedUpdate = true;
  79998. //pointcloud.updateBound()
  79999. pointcloud.getPanosBound();
  80000. viewer.dispatchEvent('content_changed');
  80001. },
  80002. rotateAround(center, pointcloud, deg, angle){//绕center点转动
  80003. var angle = angle != void 0 ? angle : MathUtils.degToRad(deg);
  80004. let vec1 = new Vector3().subVectors(pointcloud.translateUser, center);
  80005. let rotMatrix = new Matrix4().makeRotationAxis(new Vector3(0,0,1), angle);
  80006. let vec2 = vec1.clone().applyMatrix4(rotMatrix); //将到旋转中心的偏差也转动
  80007. let vec3 = new Vector3().subVectors(vec2,vec1); //这个就是多出来的一步translateUser
  80008. this.rotate(pointcloud, deg, angle);
  80009. this.translate(pointcloud, vec3);
  80010. //绕点转动就是比普通转动多一步移动到相对center的某个位置。 1 初始点云移动到自己的position; 2 移动一个vec1 3绕原点旋转 4再移动一个原本的translateUser。 绘制出来后发现移动量就是第二步vec旋转后的偏移
  80011. },
  80012. rotate:function(pointcloud, deg, angle){//绕各自中心转动(各自的position) 假设点云位移position后0,0,0就是它的中心了(根据navvis观察这样做是绕同一个点旋转的)
  80013. var angle = angle != void 0 ? angle : MathUtils.degToRad(deg); //正逆负顺
  80014. pointcloud.orientationUser += angle;
  80015. Alignment.setMatrix(pointcloud);
  80016. },
  80017. translate:function(pointcloud, vec){
  80018. pointcloud.translateUser.add(vec);
  80019. Alignment.setMatrix(pointcloud);
  80020. },
  80021. enter:function(){
  80022. //this.saveTemp()
  80023. this.originData = this.getTemp();
  80024. this.SplitScreen.split({alignment:true});
  80025. /* viewer.images360.panos.forEach(pano=>{
  80026. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', false)
  80027. }) */
  80028. viewer.viewports.find(e=>e.name == 'mapViewport').alignment = {rotate:true,translate:true};
  80029. viewer.viewports.find(e=>e.name == 'right').alignment = {translate:true, translateVec:new Vector3(0,0,1)}; //只能上下移动
  80030. viewer.viewports.find(e=>e.name == 'back').alignment = {translate:true, translateVec:new Vector3(0,0,1)}; //只能上下移动
  80031. this.editing = true;
  80032. viewer.updateFpVisiDatasets();
  80033. },
  80034. leave:function(){
  80035. this.switchHandle(null);
  80036. /* this.originData.forEach(e=>{//恢复
  80037. var pointcloud = viewer.scene.pointclouds.find(p=>p.dataset_id == e.id)
  80038. this.translate(pointcloud, new THREE.Vector3().subVectors(e.translateUser , pointcloud.translateUser))
  80039. this.rotate(pointcloud, null, e.orientationUser - pointcloud.orientationUser)
  80040. }) */
  80041. this.originData.forEach(e=>{//恢复
  80042. this.applyTemp(e);
  80043. });
  80044. this.SplitScreen.recover();
  80045. /* viewer.images360.panos.forEach(pano=>{
  80046. Potree.Utils.updateVisible(pano.mapMarker, 'split4Screens', true)
  80047. }) */
  80048. this.editing = false;
  80049. this.history.clear();
  80050. viewer.updateFpVisiDatasets();
  80051. viewer.dispatchEvent({
  80052. type : "CursorChange", action : "remove", name:"movePointcloud"
  80053. });
  80054. viewer.dispatchEvent({
  80055. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  80056. });
  80057. }
  80058. ,
  80059. switchHandle:function(state){
  80060. this.handleState = state;
  80061. //清空:
  80062. viewer.dispatchEvent({
  80063. type : "CursorChange", action : "remove", name:"movePointcloud"
  80064. });
  80065. viewer.dispatchEvent({
  80066. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  80067. });
  80068. this.bus.dispatchEvent({type:'switchHandle' , state });
  80069. },
  80070. save: function(){//保存所有数据集的位置和旋转
  80071. let callback = ()=>{//保存成功后
  80072. this.originData = this.getTemp(); //this.saveTemp();
  80073. //需要修改 测量线的position。漫游点已经实时修改了
  80074. viewer.scene.measurements.forEach(e=>e.transformByPointcloud());
  80075. viewer.images360.updateCube(viewer.bound);
  80076. };
  80077. var data = viewer.scene.pointclouds.map(e=>{
  80078. let pos = viewer.transform.lonlatToLocal.inverse(e.translateUser.clone());
  80079. let initialPointcloud = viewer.scene.pointclouds.find(e=>e.dataset_id == Potree.settings.originDatasetId);
  80080. return {
  80081. id: e.dataset_id,
  80082. orientation : e.orientationUser,
  80083. location:[pos.x, pos.y, pos.z + initialPointcloud.datasetData.location[2]],
  80084. //transformMatrix: e.transformMatrix.elements,
  80085. }
  80086. });
  80087. //data = JSON.stringify(data)
  80088. //test: 退出后保留结果
  80089. if(!Potree.settings.isOfficial){
  80090. callback();
  80091. }
  80092. return {data, callback}
  80093. }
  80094. };
  80095. let texLoader$9 = new TextureLoader();
  80096. let markerMats$2;
  80097. let markerSizeInfo$2 = {width2d:35};
  80098. let color$2 = new Color('#FFF');
  80099. let faceMats;
  80100. let getFaceMat = (name)=>{
  80101. if(!faceMats){ //navvis材质可以搜gridTexture
  80102. let gridTex = texLoader$9.load( Potree.resourcePath+'/textures/gridmap.png' );
  80103. gridTex.wrapS = gridTex.wrapT = RepeatWrapping;
  80104. //gridTex.repeat.set(0.5,0.5)//放大一些
  80105. faceMats = {
  80106. dataset: new MeshStandardMaterial({
  80107. color:812922,
  80108. side:DoubleSide,
  80109. opacity:0.2,
  80110. transparent:true,
  80111. depthTest:false,
  80112. wireframe:true
  80113. }),
  80114. building: new MeshStandardMaterial({
  80115. color:812922, metalness: 0.2, roughness:0.8,
  80116. side:DoubleSide,
  80117. opacity:0.1,
  80118. transparent:true,
  80119. depthTest:true
  80120. }),
  80121. buildingSelect: new MeshStandardMaterial({
  80122. color:36582, metalness: 0, roughness:1,
  80123. side:DoubleSide,
  80124. opacity:0.1,
  80125. transparent:true,
  80126. depthTest:true
  80127. }),
  80128. floor: new MeshStandardMaterial({
  80129. color:11708469, metalness: 0.1, roughness:1,
  80130. side:DoubleSide,//BackSide,
  80131. opacity:0.05,
  80132. transparent:true,
  80133. depthTest:true,
  80134. }),
  80135. floorSelect: new DepthBasicMaterial({
  80136. map: gridTex,
  80137. color:16707151,
  80138. side:DoubleSide,//BackSide,
  80139. opacity:1,
  80140. transparent:true,
  80141. useDepth : true,
  80142. clipDistance : 1, occlusionDistance:1, /* occlusionDistance:变为backColor距离, clipDistance:opacity到达0或者1-maxClipFactor时的距离 */
  80143. maxClipFactor:0.9, backColor:'#efe' //backColor:"#669988" ,
  80144. }),
  80145. room: new MeshStandardMaterial({
  80146. color:"#ff44ee", metalness: 0, roughness:1,
  80147. side:DoubleSide,//BackSide,
  80148. opacity:0.08,
  80149. transparent:true,
  80150. depthTest:false,
  80151. }),
  80152. roomSelect: new DepthBasicMaterial({
  80153. map: gridTex,
  80154. color:"#ff44ee",
  80155. side:DoubleSide,//BackSide,
  80156. opacity:1,
  80157. transparent:true,
  80158. useDepth : true,
  80159. clipDistance : 1, occlusionDistance:0.5, /* occlusionDistance:变为backColor距离, clipDistance:opacity到达0或者1-maxClipFactor时的距离 */
  80160. maxClipFactor:0.8, backColor:'#ff88dd'//"#cc99c2" ,
  80161. })
  80162. };
  80163. }
  80164. return faceMats[name]
  80165. };
  80166. class BuildingBox extends ctrlPolygon{//建筑实体,包括building, floor, room
  80167. constructor(prop) {
  80168. prop.dimension = '3d';
  80169. //prop.name = Potree.config.siteModel.names[prop.buildType] +
  80170. super('siteModel_'+prop.buildType, prop);
  80171. this.midMarkers = [];
  80172. this.buildChildren = [];//子实体
  80173. this.holes = []; //在这创建的hole
  80174. this.parentHoles = [];//floor从building那得到的当层holes
  80175. this.mats = {}; //材质
  80176. this.panos = this.panos || [];
  80177. this.center; //中心点
  80178. if(this.buildType=='floor'){
  80179. this.points = prop.points = this.buildParent.points;//完全等于建筑的点
  80180. this.buildParent.holes.forEach(hole=>{//从building获取holes
  80181. let floorHole = new BuildingBox({
  80182. buildType : 'hole',
  80183. buildParent:this,
  80184. originHole : hole, //整栋大楼在当层的hole
  80185. ifDraw: this.ifDraw || Potree.settings.drawEntityData
  80186. });
  80187. this.parentHoles.push(floorHole);
  80188. this.add(floorHole);
  80189. floorHole.points = hole.points;//完全等于建筑的点
  80190. });
  80191. }
  80192. if(this.buildType == 'room' || this.buildType == 'hole'){
  80193. this.restrictArea = this.buildParent; //不能超出的区域
  80194. }
  80195. if(this.buildParent)this.dontDragFloorHeight = this.buildParent.dontDragFloorHeight;
  80196. if(this.buildType != 'hole'){
  80197. this.box = this.createBox(); //无论是否edit都绘制的原因:为了将在外的点移到在内,需要用mesh来获取intersect
  80198. this.add(this.box);
  80199. this.box.visible = !!this.ifDraw;
  80200. }
  80201. if(this.ifDraw){ //只存储空间模型信息,不绘制
  80202. {
  80203. this.createPrismLines(color$2);
  80204. this.lineMesh.visible = false;
  80205. Potree.Utils.setObjectLayers(this.lineMesh, 'bothMapAndScene' );
  80206. }
  80207. this.addEventListener('dragChange',(e)=>{ //修改中点
  80208. this.updateTwoMidMarker(e.index);
  80209. });
  80210. }
  80211. this.initData(prop);
  80212. }
  80213. initData(prop){
  80214. if(prop.ifDraw){
  80215. super.initData(prop);
  80216. }else {
  80217. if(prop.points){
  80218. this.points = prop.points;
  80219. }
  80220. }
  80221. }
  80222. intersectPointcloudVolume(pointcloud){//和pointcloud的重叠体积
  80223. return this.intersectPointcloudArea(pointcloud) * this.coverPointcloudHeight(pointcloud)
  80224. }
  80225. coverPointcloudHeight(pointcloud, getPercent){
  80226. let bound2 = pointcloud.bound;
  80227. let {zMin , zMax} = this.getRealZ();
  80228. let min = Math.min(zMin, bound2.min.z);
  80229. let max = Math.max(zMax, bound2.max.z);
  80230. let height1 = zMax - zMin;
  80231. let height2 = bound2.max.z-bound2.min.z;
  80232. let coverHeight = height1 + height2 - (max-min);//重叠高度 <=0是没重叠
  80233. if(getPercent){
  80234. return coverHeight / height1
  80235. }
  80236. return coverHeight
  80237. }
  80238. intersectPointcloudArea(pointcloud, getPercent){//和pointcloud的重叠面积
  80239. var bound = this.getBound();
  80240. let bound2 = pointcloud.bound;
  80241. if(!bound.intersectsBox(bound2)) return 0;
  80242. let boxPoints = pointcloud.getUnrotBoundPoint(); //获取tightBound的四个点。 如果是有旋转角度的点云,这个和pointcloud.bound的四个点是不一致的,覆盖面积小于pointcloud.bound
  80243. let areaWhole = 0;
  80244. let area1 = this.getArea();
  80245. let area2 = Math.abs(math.getArea(boxPoints));
  80246. {//计算points与点云总面积 (但是把hole也加入了面积)(并集,重叠部分只算一次)
  80247. let rings = math.getPolygonsMixedRings([this.points, boxPoints] );
  80248. rings.forEach(e=>{
  80249. areaWhole+=e.area;
  80250. });
  80251. }
  80252. let coverHoleArea = 0; //holes与数据集重叠的部分
  80253. let holes = this.holes.concat(this.parentHoles);
  80254. let holesArea = 0; //所有holes面积相加
  80255. let areaHoleWithPointcloud = 0; //hole和点云的面积并集
  80256. if(holes.length>0){//还要再扣除holes与数据集重叠的部分。其中holes为mix轮廓
  80257. let outHoles = [];//没有重合的holes的外轮廓
  80258. /* if(holes.length>=2){//合并holes。如果能在绘制时直接合并holes就好啦,这步就转移到那去,但是要删除hole好麻烦
  80259. let holes_ = holes.map(e=>e.points)
  80260. outHoles = math.getPolygonsMixedRings(holes_, true )
  80261. outHoles.forEach(e=>{
  80262. holesArea+=e.area
  80263. })
  80264. outHoles = outHoles.map(e=>e.points)
  80265. }else{
  80266. outHoles = holes.map(e=>e.points)
  80267. outHoles.forEach(e=> holesArea += Math.abs(math.getArea(e)))
  80268. } */
  80269. holesArea = this.getHolesArea();
  80270. //holes与数据集重叠的部分
  80271. {
  80272. let polygons = outHoles.concat([boxPoints]);
  80273. let rings = math.getPolygonsMixedRings(polygons);
  80274. rings.forEach(e=>{
  80275. areaHoleWithPointcloud+=e.area;
  80276. });
  80277. coverHoleArea = holesArea + area2 - areaHoleWithPointcloud;//hole和点云的交集
  80278. }
  80279. }
  80280. let coverArea = area1 + area2 - areaWhole - coverHoleArea; //重叠面积
  80281. if(getPercent){
  80282. return {
  80283. toEntity:coverArea / this.getArea(true), //占entity
  80284. toPointcloud:coverArea / area2 //占点云
  80285. }
  80286. }
  80287. return coverArea
  80288. }
  80289. addHole(points=[]){
  80290. let prop = {
  80291. buildType : 'hole',
  80292. zMin : this.zMin,
  80293. zMax : this.zMax,
  80294. points,
  80295. buildParent:this,
  80296. ifDraw: this.ifDraw || Potree.settings.drawEntityData
  80297. };
  80298. //hole的zMin zMax跟随buildParent
  80299. var hole = new BuildingBox(prop);
  80300. this.holes.push(hole);
  80301. if(this.buildType == 'building'){//为每一层添加对应的hole
  80302. this.buildChildren.forEach(floor=>{
  80303. let floorHole = new BuildingBox({
  80304. buildType : 'hole',
  80305. zMin : this.zMin,
  80306. zMax : this.zMax,
  80307. buildParent:floor,
  80308. originHole : hole, //整栋大楼在当层的hole
  80309. ifDraw: this.ifDraw || Potree.settings.drawEntityData
  80310. });
  80311. floor.parentHoles.push(floorHole);
  80312. floor.add(floorHole);
  80313. floorHole.points = hole.points;//完全等于建筑的点
  80314. });
  80315. }
  80316. this.add(hole);//直接加在这,不加meshGroup了
  80317. this.update(); //update box mesh
  80318. return hole
  80319. //hole不创建box,只有它的buildParent需要更新box。 但有线条和marker. hole不在buildChildren里,但有buildParent
  80320. }
  80321. removeHole(hole){// 这个hole不会是parentHoles里的。
  80322. hole.dispose();
  80323. if(this.buildType == 'building'){ //若是整栋大楼的hole,在每层去除它的对应hole
  80324. this.buildChildren.forEach(floor=>{
  80325. let holeAtFloor = floor.parentHoles.find(e=>e.originHole == this );
  80326. let index = floor.parentHoles.indexOf(holeAtFloor);
  80327. index > -1 && floor.parentHoles.splice(index, 1);
  80328. holeAtFloor.dispose();
  80329. });
  80330. }
  80331. let index = this.holes.indexOf(hole);
  80332. if(index>-1){
  80333. this.holes.splice(index, 1);
  80334. }
  80335. this.remove(hole);
  80336. this.update();
  80337. }
  80338. createBox(){
  80339. var geometry = new Geometry();
  80340. this.mats.boxDefault = getFaceMat(this.buildType);
  80341. this.mats.boxSelected = getFaceMat(this.buildType+'Select');
  80342. var mesh = new Mesh(geometry, this.mats.boxDefault);
  80343. mesh.name = 'buildingBox';
  80344. if(this.buildType == 'floor'){
  80345. Potree.Utils.setObjectLayers(mesh, 'siteModelMapUnvisi' ); //楼层默认在地图不显示,为了不会叠加透明度
  80346. //mesh.renderOrder = 1
  80347. }else {
  80348. /* if(this.buildType == 'room'){
  80349. mesh.renderOrder = 2
  80350. } */
  80351. Potree.Utils.setObjectLayers(mesh, 'bothMapAndScene' );
  80352. }
  80353. //mesh.frustumCulled = false;
  80354. return mesh
  80355. }
  80356. addMarker(o={} ){
  80357. if(this.buildType=='floor')return; //楼层不需要marker
  80358. let marker = new Sprite$2({mat:this.getMarkerMaterial('default'), renderOrder : 3, sizeInfo: markerSizeInfo$2, dontFixOrient: true, name:"building_marker"} );
  80359. Potree.Utils.setObjectLayers(marker, 'siteModeOnlyMapVisi' );
  80360. o.marker = marker;
  80361. super.addMarker(o);
  80362. if(!this.selected)Potree.Utils.updateVisible(marker,'select',false);
  80363. let addClickEvent = (e)=>{
  80364. let click = (e) => {
  80365. this.dispatchEvent({type:'clickMarker', marker } ); //由entity发送给sitemodel统一处理
  80366. };
  80367. marker.addEventListener('click', click);
  80368. marker.addEventListener('clickSelect', (e)=>{
  80369. this.setMarkerSelected(marker, e.state ? 'select' : 'unselect' );
  80370. });
  80371. marker.removeEventListener('addHoverEvent',addClickEvent);
  80372. };
  80373. marker.addEventListener('addHoverEvent',addClickEvent);//当非isNew时才添加事件
  80374. if(!this.isNew){
  80375. marker.dispatchEvent('addHoverEvent');
  80376. }
  80377. return marker
  80378. }
  80379. removeMarker(index){
  80380. super.removeMarker(index);
  80381. if(!this.isNew){
  80382. //重新添加midMarkers
  80383. this.midMarkers.forEach(e=>this.remove(e));
  80384. this.midMarkers = [];
  80385. this.addMidMarkers();
  80386. }
  80387. this.update();
  80388. if(this.points.length == 2 && this.box){//清除原先length>=3时候的
  80389. this.box.geometry = new Geometry();
  80390. }
  80391. }
  80392. addMidMarker(index, point){
  80393. if(this.buildType=='floor')return; //楼层不需要marker
  80394. let marker = new Sprite$2({mat:this.getMarkerMaterial('midPrepare'), sizeInfo: markerSizeInfo$2, dontFixOrient: true, name:"building_midMarker"} );
  80395. this.midMarkers = [...this.midMarkers.slice(0,index), marker, ...this.midMarkers.slice(index,this.midMarkers.length)];
  80396. marker.renderOrder = 3;
  80397. Potree.Utils.setObjectLayers(marker, 'siteModeOnlyMapVisi' );
  80398. { // Event Listeners
  80399. let mouseover = (e) => {
  80400. this.setMarkerSelected(e.object, 'hover', 'single');
  80401. viewer.dispatchEvent({
  80402. type : "CursorChange", action : "add", name:"markerMove"
  80403. });
  80404. };
  80405. let mouseleave = (e) => {
  80406. this.setMarkerSelected(e.object, 'unhover', 'single');
  80407. viewer.dispatchEvent({
  80408. type : "CursorChange", action : "remove", name:"markerMove"
  80409. });
  80410. };
  80411. let drag = (e) => {
  80412. this.dispatchEvent('startDragging');
  80413. let index = this.midMarkers.indexOf(marker);
  80414. let newMarker = this.addMarker({index:(index+1), point:marker.position.clone() });
  80415. this.addMidMarker(index+1, new Vector3 );
  80416. this.updateTwoMidMarker(index+1);
  80417. this.setMarkerSelected(marker, 'unhover');
  80418. viewer.inputHandler.startDragging(newMarker , {/* dragViewport:viewer.mapViewer.viewports[0], */ } ); //notPressMouse代表不是通过按下鼠标来拖拽. dragViewport指定了只能在地图上拖拽
  80419. };
  80420. marker.addEventListener('drag', drag );
  80421. marker.addEventListener('mouseover', mouseover);
  80422. marker.addEventListener('mouseleave', mouseleave);
  80423. }
  80424. this.add(marker);
  80425. this.updateMarker(marker, point);
  80426. if(!this.selected)Potree.Utils.updateVisible(marker,'select',false);
  80427. return marker
  80428. }
  80429. addMidMarkers(){//第一次画好所有marker后,一次性为线段增加中点marker
  80430. let length = this.points.length;
  80431. this.points.forEach((point,index)=>{
  80432. let nextPoint = this.points[(index+1)%length];
  80433. let midPoint = new Vector3().addVectors(point, nextPoint).multiplyScalar(0.5);
  80434. this.addMidMarker(index, midPoint );
  80435. });
  80436. }
  80437. updateTwoMidMarker(index){//更新第index个marker两边的midMarker
  80438. if(!this.midMarkers.length)return
  80439. let length = this.points.length;
  80440. let last = this.points[(index-1+length)%length]; //它之前的marker位置
  80441. let next = this.points[(index+1)%length];//它之后的marker位置
  80442. let current = this.points[index];//当前位置
  80443. let lastMid = new Vector3().addVectors(last, current).multiplyScalar(0.5);//上一个中点
  80444. let nextMid = new Vector3().addVectors(next, current).multiplyScalar(0.5);//下一个中点
  80445. let lastMidMarker = this.midMarkers[(index-1+length)%length];
  80446. let nextMidMarker = this.midMarkers[index];
  80447. this.updateMarker(lastMidMarker, lastMid);
  80448. this.updateMarker(nextMidMarker, nextMid);
  80449. }
  80450. dispose(){//销毁geo、remove from parent
  80451. super.dispose();
  80452. this.box && this.box.geometry.dispose();
  80453. this.lineMesh && this.lineMesh.geometry.dispose();
  80454. this.holes.forEach(e=>e.dispose());
  80455. this.parentHoles.forEach(e=>e.dispose());
  80456. //this.buildChildren.forEach(e=>e.dispose())
  80457. this.dispatchEvent('dispose');
  80458. }
  80459. updateBox(){
  80460. if(!this.box)return
  80461. this.box.geometry.dispose();
  80462. var shrink = this.buildType == 'room' ? 0.11 : this.buildType == 'floor' ? 0.082 : 0.2 ;//防止mesh重叠冲突(给一个不寻常的数字) 但离远了还是会有点闪烁
  80463. if(this.points.length >= 3){
  80464. let holes = this.holes.concat(this.parentHoles);
  80465. let holesPoints = holes.filter(e=>e.points.length>2).map(e=>e.points);
  80466. this.box.geometry = MeshDraw.getExtrudeGeo(this.points, holesPoints, {
  80467. depth:this.zMax-this.zMin-shrink,
  80468. UVGenerator: new MetricUVGenerator()
  80469. });
  80470. if(this.buildType == 'building' ){
  80471. this.box.position.z = this.zMin - shrink / 2;
  80472. }else {
  80473. this.box.position.z = this.zMin + shrink / 2;
  80474. }
  80475. }
  80476. }
  80477. update(options={}){
  80478. super.update(this.buildType != 'floor' && options.ifUpdateMarkers);
  80479. let length = this.points.length;
  80480. {//确保一下一样
  80481. if(this.originHole){
  80482. this.points = this.originHole.points; //完全等于building的hole
  80483. }
  80484. if(this.buildType == 'hole'){
  80485. this.zMin = this.buildParent.zMin;
  80486. this.zMax = this.buildParent.zMax;
  80487. }
  80488. }
  80489. if(!options.dontUpdateBox){
  80490. let boxOwner;
  80491. if(this.buildType == 'hole'){
  80492. if(this.buildParent.buildType == 'building'){ //若是整栋大楼的hole,在每层都要更新下它的对应hole
  80493. this.buildParent.buildChildren.forEach(floor=>{
  80494. let holeAtFloor = floor.parentHoles.find(e=>e.originHole == this );
  80495. holeAtFloor && holeAtFloor.update(); //刚开始创建时还没创建对应的 holeAtFloor会为null
  80496. });
  80497. }
  80498. boxOwner = this.buildParent;
  80499. }else {
  80500. boxOwner = this;
  80501. }
  80502. boxOwner.updateBox();
  80503. }
  80504. this.updatePrismLines();//update lines
  80505. if(!options.dontUpdateChildren){
  80506. if(this.buildType == 'building' ){
  80507. this.buildChildren.forEach(floor=>{
  80508. floor.points = this.points;
  80509. floor.update();
  80510. });
  80511. }
  80512. {
  80513. let holes = this.holes.concat(this.parentHoles);
  80514. holes.forEach(hole=> {
  80515. hole.update({dontUpdateBox:true});//父级更新了box,hole就不需要更新box了
  80516. });
  80517. }
  80518. }
  80519. }
  80520. getHolesArea(){
  80521. let holes = this.holes.concat(this.parentHoles);
  80522. let outHoles, holesArea = 0;
  80523. if(holes.length>=2){//合并holes。如果能在绘制时直接合并holes就好啦,这步就转移到那去,但是要删除hole好麻烦
  80524. let holes_ = holes.map(e=>e.points);
  80525. outHoles = math.getPolygonsMixedRings(holes_, true );
  80526. outHoles.forEach(e=>{
  80527. holesArea+=e.area;
  80528. });
  80529. outHoles = outHoles.map(e=>e.points);
  80530. }else {
  80531. outHoles = holes.map(e=>e.points);
  80532. outHoles.forEach(e=> holesArea += Math.abs(math.getArea(e)));
  80533. }
  80534. return holesArea
  80535. }
  80536. getArea(ifRidOfHoles){//面积
  80537. //不排除hole
  80538. return Math.abs(math.getArea(this.points)) - (ifRidOfHoles ? this.getHolesArea() : 0)
  80539. }
  80540. getVolume(ifRidOfHoles){//体积
  80541. let {zMin , zMax} = this.getRealZ();
  80542. let height = zMax - zMin;
  80543. if(isNaN(height))height = 0;
  80544. return this.getArea(ifRidOfHoles) * height
  80545. }
  80546. getRealZ(){//求真实高度时用到的
  80547. let zMin , zMax;
  80548. if (this.buildType == 'building') {
  80549. //因为building只有一个地基平面 所以自身的zMin == 自身的zMax 所以要算
  80550. let top = this.buildChildren[this.buildChildren.length - 1];
  80551. let btm = this.buildChildren[0];
  80552. zMin = btm ? btm.zMin : 0; //建好的建筑不加楼的话是0。
  80553. zMax = top ? top.zMax : 0;
  80554. }else if(this.buildType == 'hole'){
  80555. return this.buildParent.getRealZ()
  80556. }else {
  80557. zMin = this.zMin, zMax = this.zMax;
  80558. }
  80559. return {zMin,zMax}
  80560. }
  80561. //架站式多楼层SG-t-ihjV2cDVFlE 有初始的z, 但是总高度范围小于数据集。 不允许修改高度。
  80562. /* getDrawZ(){ //画线和box时用到的z
  80563. let zMin , zMax
  80564. if(this.buildType == 'hole'){
  80565. if(this.buildParent.buildType == 'building' && atFloor){
  80566. zMin = atFloor.zMin, zMax = atFloor.zMax
  80567. }else{
  80568. zMin = this.buildParent.zMin, zMax = this.buildParent.zMax
  80569. }
  80570. }else{
  80571. zMin = this.zMin, zMax = this.zMax
  80572. }
  80573. return {zMin, zMax}
  80574. } */
  80575. getBound(){
  80576. let bound = new Box3;
  80577. let {zMin , zMax} = this.getRealZ();
  80578. let points = this.buildType == 'floor' ? this.buildParent.points : this.points;
  80579. points.forEach(p=>{
  80580. bound.expandByPoint(p.clone().setZ(zMin));
  80581. bound.expandByPoint(p.clone().setZ(zMax));
  80582. });
  80583. return bound
  80584. }
  80585. getMarkerMaterial(type) {
  80586. if(!markerMats$2){
  80587. markerMats$2 = {
  80588. default: new MeshBasicMaterial({
  80589. transparent: !0,
  80590. color: color$2,
  80591. opacity: 0.8,
  80592. map: texLoader$9.load(Potree.resourcePath+'/textures/whiteCircle.png' ),
  80593. depthTest:false,
  80594. }),
  80595. midPrepare: new MeshBasicMaterial({ //线中心的半透明点
  80596. transparent: !0,
  80597. color: color$2,
  80598. opacity: 0.4,
  80599. map: texLoader$9.load(Potree.resourcePath+'/textures/whiteCircle.png' ),
  80600. depthTest:false,
  80601. }),
  80602. hover: new MeshBasicMaterial({
  80603. transparent: !0,
  80604. color: color$2,
  80605. opacity: 1,
  80606. map: texLoader$9.load(Potree.resourcePath+'/textures/whiteCircle.png' ),
  80607. depthTest:false,
  80608. }),
  80609. select: new MeshBasicMaterial({
  80610. transparent: !0,
  80611. color:new Color('#00C8AF'),
  80612. opacity: 1,
  80613. map: texLoader$9.load(Potree.resourcePath+'/textures/whiteCircle.png' ),
  80614. depthTest:false,
  80615. }),
  80616. };
  80617. }
  80618. return markerMats$2[type]
  80619. }
  80620. setMarkerSelected(marker, state, hoverObject){
  80621. //console.warn(marker.id , state, hoverObject)
  80622. if(state == 'select'){
  80623. marker.selected = true;
  80624. marker.material = this.getMarkerMaterial('select');
  80625. }else if(state == 'unselect'){
  80626. marker.selected = false;
  80627. marker.material = this.getMarkerMaterial('default');
  80628. }else {
  80629. if(marker.selected)return //选中时不允许修改为除了'unselect'以外的状态
  80630. if(state == 'hover'){
  80631. marker.material = this.getMarkerMaterial('hover');
  80632. }else if(state == 'unhover'){
  80633. if(marker.name.includes('mid')){
  80634. marker.material = this.getMarkerMaterial('midPrepare');
  80635. }else {
  80636. marker.material = this.getMarkerMaterial('default');
  80637. }
  80638. }
  80639. }
  80640. }
  80641. select(){
  80642. //最多再显示一层子级的线,如building不会显示room中的hole的线
  80643. //box是一直显示的,但会切换材质
  80644. /*
  80645. 选中 box 线
  80646. building 自己(底盘)选中 自己, floor不带hole
  80647. floor 自己选中 自己, room不带hole
  80648. room 自己选中 自己
  80649. */ //注:自己的就代表定包括hole,如果有parentHoles的也(building上的hole的对应)
  80650. //console.log('select '+this.name, this.selected)
  80651. if(this.selected)return
  80652. if(this.box){
  80653. this.box.material = this.mats.boxSelected;
  80654. }
  80655. if(this.buildType == 'building'|| this.buildType == 'floor'){
  80656. this.buildChildren.forEach(e=>{
  80657. e.lineMesh.visible = true;
  80658. });
  80659. if(this.buildType == 'floor'){
  80660. Potree.Utils.setObjectLayers(this.box, 'bothMapAndScene' );
  80661. Potree.Utils.setObjectLayers(this.buildParent.box, 'siteModelMapUnvisi' ); //当选中floor或room时,building在地图不可见
  80662. }
  80663. }else if(this.buildType == 'room'){
  80664. Potree.Utils.setObjectLayers(this.buildParent.box, 'bothMapAndScene' );
  80665. Potree.Utils.setObjectLayers(this.buildParent.buildParent.box, 'siteModelMapUnvisi' );
  80666. }
  80667. this.lineMesh.visible = true;
  80668. this.markers && this.markers.forEach(e=>Potree.Utils.updateVisible(e,'select',true) );
  80669. this.midMarkers && this.midMarkers.forEach(e=>Potree.Utils.updateVisible(e,'select',true) );
  80670. let holes = this.holes.concat(this.parentHoles);
  80671. holes.forEach(e=>e.select());
  80672. this.selected = true;
  80673. this.dispatchEvent({type:'select'});
  80674. }
  80675. unselect(){
  80676. if(!this.selected)return
  80677. //console.log('unselect '+this.name )
  80678. if(this.box){
  80679. this.box.material = this.mats.boxDefault;
  80680. }
  80681. if(this.buildType == 'building' || this.buildType == 'floor'){
  80682. this.buildChildren.forEach(e=>{ //(这里要保证选中前要先取消选中,否则如选中房间后取消了楼层,房间线就隐藏了)
  80683. e.lineMesh.visible = false;
  80684. });
  80685. if(this.buildType == 'floor'){
  80686. Potree.Utils.setObjectLayers(this.box, 'siteModelMapUnvisi' );
  80687. Potree.Utils.setObjectLayers(this.buildParent.box, 'bothMapAndScene' );
  80688. }
  80689. }else if(this.buildType == 'room'){
  80690. Potree.Utils.setObjectLayers(this.buildParent.box, 'siteModelMapUnvisi' );
  80691. Potree.Utils.setObjectLayers(this.buildParent.buildParent.box, 'bothMapAndScene' );
  80692. }
  80693. this.lineMesh.visible = false;
  80694. this.markers && this.markers.forEach(e=>Potree.Utils.updateVisible(e,'select',false) );
  80695. this.midMarkers && this.midMarkers.forEach(e=>Potree.Utils.updateVisible(e,'select',false) );
  80696. let holes = this.holes.concat(this.parentHoles);
  80697. holes.forEach(e=>e.unselect());
  80698. this.selected = false;
  80699. this.dispatchEvent({type:'unselect'});
  80700. }
  80701. ifContainsPoint(position){//看它所定义的空间是否包含某个坐标(要排除hole)
  80702. let {zMin , zMax} = this.getRealZ();
  80703. if(position.z < zMin || position.z > zMax ) return
  80704. let holes = this.holes.concat(this.parentHoles);
  80705. let holesPoints = holes.filter(e=>e!=this && e.points.length>2).map(e=>e.points);
  80706. let inShape = math.isPointInArea(this.points, holesPoints, position);
  80707. return !!inShape
  80708. }
  80709. }
  80710. class MetricUVGenerator{
  80711. constructor(){
  80712. this.a = new Vector3,
  80713. this.b = new Vector3,
  80714. this.c = new Vector3,
  80715. this.d = new Vector3;
  80716. }
  80717. generateTopUV(t, e, n, r, o) {
  80718. 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])]
  80719. }
  80720. generateSideWallUV(t, e, n, r, o, a) {
  80721. var s = e;
  80722. this.a.set(s[3 * n], s[3 * n + 1], s[3 * n + 2]),
  80723. this.b.set(s[3 * r], s[3 * r + 1], s[3 * r + 2]),
  80724. this.c.set(s[3 * o], s[3 * o + 1], s[3 * o + 2]),
  80725. this.d.set(s[3 * a], s[3 * a + 1], s[3 * a + 2]);
  80726. var c = this.a.x !== this.b.x
  80727. , l = c ? this.b : this.d
  80728. , u = this.a.distanceTo(l)
  80729. , d = l.distanceTo(this.c);
  80730. 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)]
  80731. }
  80732. }
  80733. const minFloorHeight = 0.5;
  80734. const ifDrawDatasetBound = true; //显示一下数据集的tightBound线框
  80735. const minMarkers = 3;
  80736. const Limit = {zMin:-config$1.map.cameraHeight, zMax:config$1.map.cameraHeight,}; //不能超过camera的高度,为了对称所以也限制了最低
  80737. var SiteModel = {
  80738. bus: new EventDispatcher(),
  80739. entities:[], //所有实体
  80740. buildings:[], //所有建筑父集
  80741. meshGroup: new Object3D,
  80742. inEntity : null,
  80743. lastPos: new Vector3(Infinity,Infinity,Infinity),
  80744. init: function(){
  80745. viewer.scene.scene.add(this.meshGroup);
  80746. this.meshGroup.name = 'siteModel';
  80747. this.SplitScreen = SplitScreen4Views;
  80748. if(Potree.settings.editType == 'pano'){
  80749. return
  80750. }
  80751. this.createHeightPull();
  80752. this.history = new History({
  80753. applyData: (data)=>{
  80754. if(data.entity.parent && data.entity.selected ){
  80755. data = Potree.Common.CloneObject(data); //避免使用后更改数据又被使用
  80756. data.entity.reDraw();
  80757. data.entity.initData(data);
  80758. data.isNew || data.entity.addMidMarkers();
  80759. data.entity.isNew = data.isNew;
  80760. data.entity.dispatchEvent('changeByHistory');
  80761. return true
  80762. }
  80763. },
  80764. getData:(entity)=>{
  80765. //if(entity.isNew)return
  80766. return {
  80767. entity,
  80768. points: entity.points.map(e=>e.clone()),
  80769. ifDraw: true,
  80770. isNew : entity.isNew,
  80771. }
  80772. }
  80773. });
  80774. if(Potree.settings.isTest && ifDrawDatasetBound){
  80775. viewer.addEventListener('allLoaded',()=>{
  80776. viewer.scene.pointclouds.forEach(pointcloud=>{
  80777. let boxPoints = pointcloud.getUnrotBoundPoint();
  80778. let boundingBox = new BuildingBox({
  80779. name: '数据集tightBound_'+pointcloud.dataset_id,
  80780. points: boxPoints,
  80781. buildType : 'dataset',
  80782. zMax: pointcloud.bound.max.z,
  80783. zMin: pointcloud.bound.min.z,
  80784. ifDraw:true
  80785. });
  80786. this.meshGroup.add(boundingBox);
  80787. //boundingBox.markers.forEach(e=>e.visible = false)
  80788. });
  80789. });
  80790. }
  80791. if(Potree.settings.isOfficial){
  80792. viewer.addEventListener('camera_changed', e => {
  80793. if(e.changeInfo && e.changeInfo.positionChanged){
  80794. this.updateEntityAt();
  80795. }
  80796. });
  80797. }
  80798. {
  80799. let pressDelete = (e)=>{
  80800. if(e.keyCode == KeyCodes.BACKSPACE || e.keyCode == KeyCodes.DELETE){
  80801. if(this.selectedMarker){
  80802. let entity = this.selectedMarker.parent;
  80803. let index = entity.markers.indexOf(this.selectedMarker);
  80804. entity.removeMarker(index);
  80805. if(entity.points.length<2){//删到只剩一个点时重新画(如果是hole的点,直接删除hole吧?)
  80806. this.startInsertion('resume',entity);
  80807. }
  80808. }
  80809. }
  80810. };
  80811. viewer.inputHandler.addEventListener('keydown', pressDelete);
  80812. }
  80813. {
  80814. let updated = false;
  80815. this.bus.addEventListener('updated',()=>{
  80816. Common.intervalTool.isWaiting('siteModelUpdated', ()=>{
  80817. this.changedCallback();
  80818. },500);
  80819. });
  80820. }
  80821. },
  80822. changedCallback(){
  80823. this.findPanos();
  80824. this.findEntityForDataset();
  80825. this.updateEntityAt(true); //更新所在建筑,更新marker显示
  80826. //console.log('changedCallback')
  80827. },
  80828. updateEntityAt(force,{measure}={}){
  80829. //if(!this.entities.length || this.editing) return //编辑时也要根据位置显示不同楼层的漫游点与cad
  80830. let fun = ()=>{ //延时update,防止卡顿
  80831. let currPos = viewer.mainViewport.view.position;
  80832. if(this.pauseUpdateEntity)return // console.error('pauseUpdateEntity')
  80833. //if(force || !currPos.equals(this.lastPos) ){
  80834. //console.log('currPos ', currPos.toArray())
  80835. this.lastPos.copy(currPos);
  80836. let entity;
  80837. if(measure){//因为测量线的点可能在多个房间,所以干脆直接找在哪个楼层
  80838. let list = [];
  80839. measure.points.forEach(e=>{
  80840. let entity = this.pointInWhichEntity(e, 'floor' );//每个点都找到其所在楼层
  80841. let item = list.find(e=>e.entity == entity);
  80842. if(item){
  80843. item.count ++;
  80844. }else {
  80845. list.push({entity, count:1});
  80846. }
  80847. });
  80848. list.sort((a,b)=>{return b.count-a.count});//找出出现次数最多的楼层
  80849. if(list[0]){
  80850. entity = list[0].entity;
  80851. }
  80852. }else {
  80853. let searchPos = Potree.settings.displayMode == 'showPanos' ? viewer.images360.currentPano : currPos;
  80854. entity = this.pointInWhichEntity(searchPos, 'room');
  80855. }
  80856. if(force || this.inEntity != entity ){
  80857. let oldEntity = this.inEntity;
  80858. this.inEntity = entity;
  80859. //console.log('buildingChange', entity)
  80860. this.bus.dispatchEvent({type:'buildingChange',entity});
  80861. //this.updatePanosVisible(oldEntity, this.inEntity)
  80862. let lastFloor = this.currentFloor; //oldEntity ? oldEntity.buildType == 'floor' ? oldEntity : oldEntity.buildType == 'room' ? oldEntity.buildParent : null : null; //基本只会是floor或room
  80863. let currentFloor = entity ? entity.buildType == 'floor' ? entity : entity.buildType == 'room' ? entity.buildParent : null : null; //基本只会是floor或room
  80864. if(force || currentFloor != lastFloor){
  80865. //console.log('改变了floor',lastFloor,currentFloor)
  80866. this.currentFloor = currentFloor;
  80867. this.bus.dispatchEvent({type:'FloorChange',currentFloor});
  80868. }
  80869. }
  80870. force = false;
  80871. //}
  80872. };
  80873. if(force)fun();
  80874. else Common.intervalTool.isWaiting('sitemodelCameraInterval', fun , 500);
  80875. },
  80876. enter:function(){
  80877. Potree.Log('sitemodel enter');
  80878. this.clear(); //确保全部清空
  80879. this.editing = true;
  80880. //this.updatePanosVisible(null, null, true)//show all
  80881. viewer.updateFpVisiDatasets();
  80882. let mapViewport = viewer.mapViewer.viewports[0];
  80883. this.SplitScreen.split({siteModel:true/* , viewports:[{name:'Top',viewport : mapViewport }] */});
  80884. viewer.viewports.forEach(e=>{
  80885. if(e.name != 'mapViewport'){
  80886. e.layersAdd('siteModelMapUnvisi');
  80887. }
  80888. if(e.name == 'right' || e.name == 'back'){
  80889. e.layersAdd('siteModeSideVisi');
  80890. }
  80891. });
  80892. viewer.images360.panos.forEach(pano=>{
  80893. Potree.Utils.setObjectLayers(pano.marker, 'siteModelMapUnvisi' );
  80894. //Potree.Utils.setObjectLayers(pano.label2, 'bothMapAndScene')
  80895. });
  80896. mapViewport.layersAdd('siteModeOnlyMapVisi'); //只有mapViewport能看到marker
  80897. },
  80898. leave:function(){
  80899. Potree.Log('sitemodel leave');
  80900. let mapViewport = viewer.mapViewer.viewports[0];
  80901. this.SplitScreen.recover();
  80902. viewer.viewports.forEach(e=>{
  80903. if(e.name != 'mapViewport'){
  80904. e.layersRemove('siteModelMapUnvisi');
  80905. }
  80906. if(e.name == 'right' || e.name == 'back'){
  80907. e.layersRemove('siteModeSideVisi');
  80908. }
  80909. });
  80910. viewer.images360.panos.forEach(pano=>{
  80911. Potree.Utils.setObjectLayers(pano.marker, 'sceneObjects' );
  80912. //Potree.Utils.setObjectLayers(pano.label2, 'bothMapAndScene')
  80913. });
  80914. mapViewport.layersRemove('siteModeOnlyMapVisi');
  80915. this.clear();
  80916. this.editing = false;
  80917. this.updateEntityAt(true);
  80918. viewer.updateFpVisiDatasets();
  80919. } ,
  80920. addFloor:function(parent, dirType, sid, name){//dirType:'top'|'bottom'在上方建还是下方。如果建筑中没有楼层,默认在基底建一个
  80921. let buildType = 'floor';
  80922. let zMin, zMax;
  80923. if(parent.buildChildren.length == 0){
  80924. zMin = parent.zMin;
  80925. zMax = zMin + Potree.config.siteModel.floorHeightDefault;
  80926. }else {
  80927. if(dirType == 'bottom'){
  80928. //var btm = Common.find(parent.buildChildren,null,[e=>e.zMin])
  80929. var btm = parent.buildChildren[0];
  80930. zMax = btm.zMin;
  80931. zMin = zMax - Potree.config.siteModel.floorHeightDefault;
  80932. }else {
  80933. //var top = Common.find(parent.buildChildren,null,[e=>e.zMax])
  80934. var top = parent.buildChildren[parent.buildChildren.length - 1];
  80935. zMin = top.zMax;
  80936. zMax = zMin + Potree.config.siteModel.floorHeightDefault;
  80937. }
  80938. }
  80939. let prop = {
  80940. buildType,
  80941. //name : Potree.config.siteModel.names[buildType],
  80942. zMin,
  80943. zMax,
  80944. buildParent:parent,
  80945. sid, name,
  80946. ifDraw:true
  80947. };
  80948. var floor = new BuildingBox(prop);
  80949. /* parent.buildChildren.push(floor)
  80950. this.meshGroup.add(floor);
  80951. this.entities.push(floor) */
  80952. floor.update();
  80953. this.addEntity(floor,parent);
  80954. //this.selectEntity(floor)
  80955. if(this.selected == parent){//重新选择下,为了显示新楼层线框
  80956. parent.unselect();
  80957. parent.select();
  80958. }
  80959. this.bus.dispatchEvent('updated');
  80960. return floor
  80961. },
  80962. startInsertion:function(buildType, parent, sid, name, callback, cancelFun){
  80963. let zMin, zMax, entity, resume;
  80964. let mapViewport = viewer.mapViewer.viewports[0];
  80965. if(buildType == 'resume'){//继续画(使用最后一个点或者新加的点)
  80966. resume = true;
  80967. entity = parent;
  80968. buildType = parent.buildType;
  80969. //删除原先所有的点,因为它们已经添加了事件,会很麻烦:
  80970. entity.reDraw(0);
  80971. entity.isNew = true; //当作新的来画
  80972. }
  80973. if(!resume){
  80974. if(buildType == 'hole' || buildType == 'room'){
  80975. zMin = parent.zMin;
  80976. zMax = parent.zMax;
  80977. }else if(buildType == 'building'){
  80978. parent = null;
  80979. zMin = viewer.bound.boundingBox.min.z;
  80980. zMax = viewer.bound.boundingBox.min.z;
  80981. }
  80982. if(buildType == 'hole'){
  80983. entity = parent.addHole();
  80984. entity.isNew = true;
  80985. this.selectEntity(parent);
  80986. entity.select();
  80987. console.log('挖洞 ',entity.uuid);
  80988. }else {
  80989. let prop = {
  80990. buildType,
  80991. //name : Potree.config.siteModel.names[buildType],//'building',
  80992. zMin,
  80993. zMax,
  80994. buildParent:parent,
  80995. sid, name,
  80996. ifDraw:true
  80997. };
  80998. entity = new BuildingBox(prop);
  80999. entity.isNew = true;
  81000. this.selectEntity(entity);
  81001. }
  81002. this.addEntity(entity, parent);
  81003. }
  81004. let timer;
  81005. let endDragFun = (e) => {
  81006. if (e.button == MOUSE.LEFT ) {
  81007. this.history.beforeChange(entity);
  81008. var marker = entity.addMarker({point:entity.points[entity.points.length - 1].clone()});
  81009. this.history.afterChange(entity);
  81010. //entity.editStateChange(true) //重新激活reticule状态
  81011. entity.continueDrag(marker, e);
  81012. } else if (e.button === MOUSE.RIGHT ) {
  81013. if(e.pressDistance < Potree.config.clickMaxDragDis )end(e);//非拖拽的话
  81014. else entity.continueDrag(null, e/* .drag.object */);
  81015. }
  81016. };
  81017. let finish = ()=>{//结束绘画
  81018. viewer.removeEventListener('cancel_insertions', Exit);
  81019. entity.removeEventListener('unselect', Exit);
  81020. clearTimeout(timer);
  81021. entity.editStateChange(false);
  81022. //pressExit && viewer.inputHandler.removeEventListener('keydown', pressExit);
  81023. callback && callback(entity);
  81024. viewer.dispatchEvent('endBuildEntity');
  81025. };
  81026. let end = (e={}) => {//尝试结束
  81027. /* 退出的三种形式:
  81028. 1 普通:如果大于三个marker,结束且保留;否则重新画。()
  81029. 2 删除:直接结束且删除。(remove)
  81030. 3 结束:如果大于三个marker,结束且保留;否则结束且删除。 (finish)
  81031. 4 保留:无论几个marker,都保留着,结束。(remain)
  81032. */
  81033. if(e.remove){
  81034. finish();
  81035. return this.removeEntity(entity)
  81036. }
  81037. if(!e.remain && !e.finish && !e.remove && entity.markers.length<=minMarkers){//右键 当个数不够时取消
  81038. //重新开始画
  81039. entity.reDraw(1);
  81040. Potree.Utils.updateVisible(entity.markers[0],'unMove',false);
  81041. var f = ()=>{
  81042. Potree.Utils.updateVisible(entity.markers[0],'unMove',true);
  81043. entity.removeEventListener('dragChange',f);
  81044. };
  81045. entity.addEventListener('dragChange',f);
  81046. //console.log('waitcontinue')
  81047. entity.continueDrag(entity.markers[0], e);
  81048. return
  81049. }
  81050. finish();
  81051. if (e.remain || !e.remove && entity.markers.length > 3) {//保留
  81052. entity.removeMarker(entity.points.length - 1);
  81053. entity.markers.forEach(marker=>{marker.dispatchEvent('addHoverEvent'); });
  81054. if(buildType == 'room'){
  81055. this.fitPullBox();
  81056. }
  81057. entity.isNew = false;
  81058. entity.addMidMarkers();
  81059. let boundingBox = entity.getBound();
  81060. let center = boundingBox.getCenter(new Vector3());
  81061. viewer.controls.setTarget(center,2);
  81062. }else {
  81063. this.removeEntity(entity); //直接删除没画好的,比较简单。这样就不用担心旧的continueDrag仍旧触发了
  81064. }
  81065. return entity
  81066. };
  81067. let Exit = (e)=>{ //强制结束
  81068. entity.removeEventListener('unselect', Exit);
  81069. if(viewer.inputHandler.drag){//还未触发drop的话
  81070. viewer.inputHandler.drag.object.dispatchEvent({
  81071. type: 'drop',
  81072. drag: viewer.inputHandler.drag,
  81073. viewer: viewer,
  81074. pressDistance:0,
  81075. button : MOUSE.RIGHT
  81076. });
  81077. viewer.inputHandler.drag.object.isDragging = false;
  81078. }else {
  81079. end({remain:true});
  81080. }
  81081. viewer.inputHandler.drag = null;
  81082. };
  81083. viewer.dispatchEvent( 'cancel_insertions' );//取消之前的
  81084. viewer.addEventListener('cancel_insertions', Exit);
  81085. setTimeout(()=>{
  81086. entity.isNew && entity.addEventListener('unselect', Exit);
  81087. },1);//因为刚创建会unselect一下所以延迟
  81088. var marker = entity.addMarker({point:new Vector3(0, 0, 0)});
  81089. Potree.Utils.updateVisible(marker,'unMove',false);//这时候的位置是假的(0,0,0)所以先不可见
  81090. var f = ()=>{
  81091. Potree.Utils.updateVisible(marker,'unMove',true);
  81092. entity.removeEventListener('dragChange',f);
  81093. };
  81094. entity.addEventListener('dragChange',f);
  81095. marker.isDragging = true;
  81096. viewer.inputHandler.startDragging(marker , {dragViewport:mapViewport, endDragFun, notPressMouse:true} ); //notPressMouse代表不是通过按下鼠标来拖拽. dragViewport指定了只能在地图上拖拽
  81097. viewer.dispatchEvent('startBuildEntity');
  81098. let changeByHistory = (e)=>{
  81099. if(!entity.isNew)return
  81100. let marker = entity.markers[entity.points.length-1];
  81101. viewer.inputHandler.startDragging(marker , {dragViewport:mapViewport, endDragFun, notPressMouse:true} );
  81102. var I = viewer.inputHandler.intersect && (viewer.inputHandler.intersect.orthoIntersect || viewer.inputHandler.intersect.location);
  81103. if(I){
  81104. entity.dragChange(I.clone(), entity.points.length-1 ); //使最后一个点在鼠标处
  81105. }
  81106. };
  81107. entity.addEventListener('changeByHistory',changeByHistory);
  81108. return entity;
  81109. },
  81110. getPreDealData(points, zMin, zMax, initial, buildType, parent){
  81111. /* if( buildType == 'building' ){
  81112. zMax = zMin //强制变得一样,作为基底。如果有必要,保存时再算真实的zMax。目前zMin没有保存所以数据是错的,会直接根据floor计算
  81113. } */
  81114. var bound = viewer.bound.boundingBox;
  81115. if(buildType == 'building' && initial){//初始数据错的,要自己建(只有一个building和floor) 原posIsLonlat
  81116. console.log('空间模型未编辑过, 初始化了一个');
  81117. points = [
  81118. new Vector3(bound.min.x, bound.min.y,0),
  81119. new Vector3(bound.max.x, bound.min.y,0),
  81120. new Vector3(bound.max.x, bound.max.y,0),
  81121. new Vector3(bound.min.x, bound.max.y,0),
  81122. ];
  81123. zMin = bound.min.z;
  81124. zMax = bound.max.z;
  81125. /* points = points.map(e=>{
  81126. return viewer.transform.lonlatToLocal.forward(e)
  81127. }) */
  81128. }else {//相对于初始数据集的模型内坐标
  81129. points = points.map(e=> this.transform(e, 'fromDataset'));
  81130. if(buildType == 'floor' && initial){
  81131. zMin = bound.min.z;
  81132. zMax = bound.max.z;
  81133. }
  81134. }
  81135. return {points, zMax, zMin }
  81136. },
  81137. resetFromData:function(entity, points=[], holes=[], zMin, zMax ){
  81138. var {points, zMax, zMin} = this.getPreDealData(points, zMin, zMax , this.autoBuild , entity.buildType, entity.buildParent );
  81139. if(entity.buildType != 'floor' )entity.points = points;
  81140. if(entity.buildType == 'room'){
  81141. entity.zMin = zMin;
  81142. entity.zMax = zMax;
  81143. }else if(entity.buildType == 'floor'){//改楼高
  81144. let height = zMax - zMin;
  81145. let zMax2 = entity.zMin + height;
  81146. SiteModel.changeZ(entity, 'zMax', zMax2);
  81147. }
  81148. {
  81149. //删除旧的holes重新添加
  81150. let holesOld = entity.holes;
  81151. holesOld.forEach(e=>{
  81152. entity.removeHole(e);
  81153. });
  81154. holes.forEach(points =>{
  81155. let ps = points.map(e=> this.transform(e, 'fromDataset'));
  81156. let hole = entity.addHole(ps);
  81157. hole.addMidMarkers();
  81158. });
  81159. }
  81160. entity.update();
  81161. return entity
  81162. }
  81163. ,
  81164. createFromData:function( buildType, parent ,sid, name, points=[], holes=[], zMin, zMax, initial,panos_,flagPano){
  81165. if(buildType != 'building' && buildType != 'floor' && buildType != 'room' ) return
  81166. var {points, zMax, zMin} = this.getPreDealData(points, zMin, zMax , initial, buildType, parent );
  81167. let panos = [];
  81168. {
  81169. if(panos_){
  81170. panos_.forEach(sid=>{
  81171. let pano = viewer.images360.getPano(sid,'sid');
  81172. if(pano)panos.push(pano);
  81173. });
  81174. }
  81175. flagPano = flagPano != void 0 ? viewer.images360.getPano(flagPano,'sid') : null ; //最中心的pano 或者 最靠近该实体的pano(当panos为空时)
  81176. if(!this.editing && buildType == 'floor' && !flagPano){//没有的话可能是自动添加的floor,直接用parent的吧
  81177. panos = parent.panos;
  81178. flagPano = parent.flagPano;
  81179. }
  81180. }
  81181. let prop = {
  81182. buildType,
  81183. points,
  81184. name,
  81185. sid,
  81186. zMin,
  81187. zMax,
  81188. buildParent:parent,
  81189. ifDraw:this.editing || Potree.settings.drawEntityData,
  81190. panos, flagPano,
  81191. autoBuild : initial
  81192. };
  81193. let entity = new BuildingBox(prop);
  81194. SiteModel.addEntity(entity, parent );
  81195. if(this.editing){
  81196. if(buildType == 'building'|| buildType == 'room'){
  81197. entity.addMidMarkers();
  81198. }
  81199. }
  81200. holes.forEach(points =>{
  81201. let ps = points.map(e=> this.transform(e, 'fromDataset'));
  81202. let hole = entity.addHole(ps);
  81203. this.editing && hole.addMidMarkers();
  81204. });
  81205. /* if(buildType == 'floor'){
  81206. this.updateBuildingZ(parent)
  81207. } */
  81208. return entity
  81209. },
  81210. transform:function(pos, type){
  81211. if(Potree.settings.editType == 'pano'){ // 模型不经转换
  81212. return new Vector3().copy(pos).setZ(0);
  81213. }
  81214. if(type == 'toDataset'){
  81215. let point = Potree.Utils.datasetPosTransform({ toDataset: true, position: pos.clone(), datasetId: Potree.settings.originDatasetId });
  81216. return new Vector2().copy(point)
  81217. }else {
  81218. let position = new Vector3().copy(pos).setZ(0);
  81219. return Potree.Utils.datasetPosTransform({ fromDataset: true, position, datasetId: Potree.settings.originDatasetId })
  81220. }
  81221. },
  81222. addEntity:function(entity, parent){
  81223. if(entity.buildType != 'hole'){
  81224. this.meshGroup.add(entity);
  81225. this.entities.push(entity);
  81226. if(entity.buildType == 'building'){
  81227. this.buildings.push(entity);
  81228. }else {
  81229. parent.buildChildren.push(entity);
  81230. }
  81231. }
  81232. if(entity.buildType == 'room'){
  81233. entity.addEventListener('marker_dropped',()=>{
  81234. this.fitPullBox();
  81235. });
  81236. }else if(entity.buildType == 'floor'){
  81237. this.updateBuildingZ(parent);
  81238. parent.dispatchEvent({type:'addFloor'});
  81239. }
  81240. {//仅能存在一个marker被选中。选中的点可以被删除
  81241. entity.addEventListener('clickMarker', (e)=>{
  81242. if(this.selectedMarker == e.marker){
  81243. this.selectedMarker.dispatchEvent({type:'clickSelect',state:false});
  81244. this.selectedMarker = null;
  81245. }else {
  81246. if(this.selectedMarker){
  81247. this.selectedMarker.dispatchEvent({type:'clickSelect',state:false});
  81248. }
  81249. this.selectedMarker = e.marker;
  81250. this.selectedMarker.dispatchEvent({type:'clickSelect',state:true});
  81251. }
  81252. });
  81253. entity.addEventListener('removeMarker', (e)=>{
  81254. if(this.selectedMarker == e.marker){
  81255. this.selectedMarker = null;
  81256. }
  81257. });
  81258. let unselect = (e)=>{//取消选中实体或删除后
  81259. if(this.selectedMarker && entity.markers.includes(this.selectedMarker)){
  81260. this.selectedMarker.dispatchEvent({type:'clickSelect',state:false});
  81261. this.selectedMarker = null;
  81262. }
  81263. };
  81264. entity.addEventListener('dispose', unselect);
  81265. entity.addEventListener('unselect', unselect);
  81266. }
  81267. //console.log('添加实体:', entity.buildType, entity.sid, entity.uuid)
  81268. this.bus.dispatchEvent('updated');
  81269. entity.addEventListener('startDragging',()=>{
  81270. this.history.beforeChange(entity);
  81271. });
  81272. entity.addEventListener('marker_dropped',()=>{
  81273. this.bus.dispatchEvent('updated');
  81274. this.history.afterChange(entity);
  81275. });
  81276. },
  81277. removeEntity : function(entity){
  81278. if(!this.entities.includes(entity))return
  81279. console.log('删除实体:', entity.buildType, entity.sid);
  81280. if(this.selected == entity){
  81281. this.height_pull_box && (this.height_pull_box.visible = false);
  81282. this.selectEntity(null);
  81283. }
  81284. if(entity.buildType == 'building'){
  81285. var index = this.buildings.indexOf(entity);
  81286. if(index>-1){
  81287. this.buildings.splice(index,1);
  81288. }
  81289. }else {
  81290. var index = entity.buildParent.buildChildren.indexOf(entity);
  81291. if(index>-1){
  81292. entity.buildParent.buildChildren.splice(index,1);
  81293. if(entity.buildType == 'floor' && index == 0){
  81294. this.updateBuildingZ(entity.buildParent);
  81295. }
  81296. }
  81297. }
  81298. var index = this.entities.indexOf(entity);
  81299. if(index>-1){
  81300. this.entities.splice(index,1);
  81301. }
  81302. entity.dispose();
  81303. let buildChildren = entity.buildChildren.slice();
  81304. buildChildren.forEach(e=>this.removeEntity(e));
  81305. this.bus.dispatchEvent('updated');
  81306. },
  81307. updateBuildingZ:function(building){
  81308. building.buildChildren = building.buildChildren.sort((e,a)=>e.zMin-a.zMin);//从低到高排序
  81309. building.buildChildren[0] && (building.zMin = building.zMax = building.buildChildren[0].zMin); //基底高度
  81310. //building.zMax = building.buildChildren[building.buildChildren.length-1].zMax
  81311. if(this.editing) building.update({dontUpdateChildren:true});
  81312. building.dispatchEvent('updateBuildingZ');
  81313. },
  81314. selectEntity : function(entity, state=true){
  81315. viewer.dispatchEvent('content_changed');
  81316. if(state === false){
  81317. entity.unselect();
  81318. if(this.selected == entity)this.selected = null;
  81319. viewer.controls.setTarget(null,2);
  81320. return
  81321. }
  81322. if(this.selected == entity || entity && entity.buildType == 'hole')return
  81323. //this.buildings.forEach(e=>e.unselect())
  81324. this.selected && this.selected.unselect();
  81325. this.height_pull_box && (this.height_pull_box.visible = false);
  81326. if(entity){
  81327. entity.select();
  81328. if(!entity.isNew){
  81329. let boundingBox = entity.getBound();
  81330. let center = boundingBox.getCenter(new Vector3()); //中心点不一定在entity中,比如半环形建筑(所以要不要改成到漫游点呢)
  81331. viewer.controls.setTarget(center,2);
  81332. }
  81333. }else {
  81334. viewer.controls.setTarget(null,2);
  81335. }
  81336. this.selected = entity;
  81337. if(entity && !entity.dontDragFloorHeight && (entity.buildType == 'floor' || entity.buildType == 'room' )){
  81338. this.height_pull_box && (this.height_pull_box.visible = true);
  81339. this.fitPullBox();
  81340. }
  81341. if(entity && !entity.isNew && (entity.buildType == 'building' || entity.buildType == 'room' ) && entity.points.length<2){
  81342. this.startInsertion('resume',entity); //继续画
  81343. }
  81344. },
  81345. fitPullBox: function(){ //自适应拖拽楼层的pullMesh
  81346. if(!this.height_pull_box || !this.selected || this.selected.buildType!= 'floor' && this.selected.buildType!= 'room')return
  81347. let bound = new Box3();
  81348. bound.expandByObject(this.selected.box);
  81349. let center = bound.getCenter(new Vector3() );
  81350. let size = bound.getSize(new Vector3() );
  81351. this.height_pull_box.scale.copy(size);
  81352. this.height_pull_box.position.copy(center);
  81353. },
  81354. changeZ:function(entity, dirType, value){ // floor or room 修改zMin or zMax
  81355. let max, min; //limit
  81356. if(entity.buildType == 'floor'){//楼层
  81357. let index = entity.buildParent.buildChildren.indexOf(entity);
  81358. if(dirType == 'zMax'){
  81359. let upper = entity.buildParent.buildChildren[index+1];
  81360. entity.zMax = Math.min(Limit.zMax, value);
  81361. min = entity.zMin + minFloorHeight;
  81362. if(entity.zMax < min){
  81363. entity.zMax = min;
  81364. }else {
  81365. if(upper){
  81366. max = upper.zMax - minFloorHeight;
  81367. if(entity.zMax > max){
  81368. entity.zMax = max;
  81369. }
  81370. }
  81371. }
  81372. if(upper){
  81373. upper.zMin = entity.zMax;
  81374. upper.update();
  81375. upper.dispatchEvent({type:'changeHeight'});
  81376. }
  81377. }else {
  81378. let lower = entity.buildParent.buildChildren[index-1];
  81379. entity.zMin = Math.max(Limit.zMin, value);
  81380. max = entity.zMax - minFloorHeight;
  81381. if(entity.zMin > max){
  81382. entity.zMin = max;
  81383. }else {
  81384. if(lower){
  81385. min = lower.zMin + minFloorHeight;
  81386. if(entity.zMin < min){
  81387. entity.zMin = min;
  81388. }
  81389. }
  81390. }
  81391. if(lower){
  81392. lower.zMax = entity.zMin;
  81393. lower.update();
  81394. lower.dispatchEvent({type:'changeHeight'});
  81395. }
  81396. if(index == 0)this.updateBuildingZ(entity.buildParent);
  81397. }
  81398. }else if(entity.buildType == 'room'){//房间
  81399. //按照navvis的是不一定限制在当前楼层,只要高度不超过当前楼层即可。
  81400. let maxHeight = entity.buildParent.zMax - entity.buildParent.zMin;
  81401. if(dirType == 'zMax'){
  81402. min = entity.zMin + minFloorHeight;
  81403. max = entity.zMin + maxHeight;
  81404. entity.zMax = MathUtils.clamp(value, min, max);
  81405. }else {
  81406. min = entity.zMax - maxHeight;
  81407. max = entity.zMax - minFloorHeight;
  81408. entity.zMin = MathUtils.clamp(value, min, max);
  81409. }
  81410. }
  81411. entity.update();
  81412. entity.dispatchEvent({type:'changeHeight'});
  81413. //this.selected.emit('update')
  81414. this.fitPullBox();
  81415. this.bus.dispatchEvent('updated');
  81416. },
  81417. createHeightPull:function(){ //拖拽楼层的bounding box
  81418. let boxGeo = new BoxBufferGeometry( 1, 1, 1/4 );
  81419. let boxMat = new MeshBasicMaterial({
  81420. color:"#F00",
  81421. opacity:0,
  81422. transparent:true,
  81423. depthTest:false,
  81424. side:2
  81425. });
  81426. let height_pull_box_up = new Mesh(boxGeo,boxMat);
  81427. let height_pull_box_down = new Mesh(boxGeo,boxMat);
  81428. height_pull_box_up.name = 'height_pull_box_up';
  81429. height_pull_box_down.name = 'height_pull_box_down';
  81430. this.height_pull_box = new Object3D();
  81431. this.height_pull_box.name = 'height_pull_box';
  81432. this.height_pull_box.add(height_pull_box_up);
  81433. this.height_pull_box.add(height_pull_box_down);
  81434. this.height_pull_box.visible = false;
  81435. this.meshGroup.add(this.height_pull_box);
  81436. height_pull_box_up.position.set(0,0,1/2/* 3/8 */);
  81437. height_pull_box_down.position.set(0,0,-1/2/* -3/8 */);
  81438. Potree.Utils.setObjectLayers(this.height_pull_box, 'siteModeSideVisi' );
  81439. let mouseover = (e)=>{
  81440. viewer.dispatchEvent({
  81441. type : "CursorChange", action : "add", name:"siteModelFloorDrag"
  81442. });
  81443. };
  81444. let mouseleave = (e)=>{
  81445. viewer.dispatchEvent({
  81446. type : "CursorChange", action : "remove", name:"siteModelFloorDrag"
  81447. });
  81448. };
  81449. let firstZ, firstIntersect;
  81450. let drag = (e)=>{
  81451. var intersect = e.intersect.orthoIntersect; //不要点云的intersect,只要orthocamera算出的平面intersect
  81452. if(firstIntersect != void 0){
  81453. let moveZ = intersect.z - firstIntersect;
  81454. if(this.selected.buildType == 'floor'){//楼层
  81455. //限制高度不能超过上下
  81456. if(e.target == height_pull_box_up){
  81457. if(firstZ == void 0)firstZ = this.selected.zMax;
  81458. this.changeZ(this.selected, 'zMax', firstZ + moveZ);
  81459. }else {
  81460. if(firstZ == void 0)firstZ = this.selected.zMin;
  81461. this.changeZ(this.selected, 'zMin', firstZ + moveZ);
  81462. }
  81463. }else if(this.selected.buildType == 'room'){//房屋
  81464. if(e.target == height_pull_box_up){
  81465. if(firstZ == void 0)firstZ = this.selected.zMax;
  81466. this.changeZ(this.selected, 'zMax', firstZ + moveZ);
  81467. }else {
  81468. if(firstZ == void 0)firstZ = this.selected.zMin;
  81469. this.changeZ(this.selected, 'zMin', firstZ + moveZ);
  81470. }
  81471. }
  81472. }else {
  81473. firstIntersect = intersect.z;
  81474. }
  81475. };
  81476. let drop = (e)=>{
  81477. firstZ = firstIntersect = null;
  81478. };
  81479. height_pull_box_up.addEventListener('mousemove',mouseover);
  81480. height_pull_box_down.addEventListener('mousemove',mouseover);
  81481. height_pull_box_up.addEventListener('mouseleave',mouseleave);
  81482. height_pull_box_down.addEventListener('mouseleave',mouseleave);
  81483. height_pull_box_up.addEventListener('drag',drag);
  81484. height_pull_box_down.addEventListener('drag',drag);
  81485. height_pull_box_up.addEventListener('drop',drop);
  81486. height_pull_box_down.addEventListener('drop',drop);
  81487. },
  81488. pointInWhichEntity(location, buildType, ifIgnoreHole){//buildType是要找的建筑类型
  81489. //location 可以是pano或者坐标
  81490. //由于房间可能在building外,所以房间要另外单独识别。
  81491. let lastResult; //最接近的上一层结果,如果没有result返回这个
  81492. let result;
  81493. let level = {
  81494. building: 0, floor: 1, room: 2
  81495. };
  81496. let traverse = (parent, buildType)=>{//返回第一个符合标准的实体
  81497. let contains;
  81498. if(location instanceof Vector3){
  81499. contains = parent.ifContainsPoint(location);
  81500. }else {//is pano
  81501. contains = parent.panos.includes(location);
  81502. }
  81503. if(contains){
  81504. if(!lastResult || level[lastResult.buildType] < level[parent.buildType] )lastResult = parent;
  81505. if(parent.buildType == buildType){
  81506. return parent
  81507. }else {
  81508. for(let i=0,len=parent.buildChildren.length; i<len; i++){
  81509. let result1 = traverse(parent.buildChildren[i]);
  81510. if(result1) return result1
  81511. }
  81512. }
  81513. }
  81514. };
  81515. //因为建筑可能重叠,所以需要先找到最接近其中心的建筑物
  81516. result = Common.sortByScore(this.buildings, [(building)=>{
  81517. return traverse(building, 'building') //在building中
  81518. }], [(building)=>{ //写法类似pointInWhichPointcloud
  81519. let boundingBox = building.getBound();
  81520. let center = boundingBox.getCenter(new Vector3());
  81521. let position = location instanceof Vector3 ? location : location.position;
  81522. let dis = position.distanceTo(center);
  81523. let size = boundingBox.getSize(new Vector3());
  81524. let length = size.length() / 2;
  81525. return length / dis
  81526. }]);
  81527. let building = result && result[0] && result[0].score > 1 && result[0].item;
  81528. if(buildType == 'building' || !building)return building
  81529. result = traverse(building, buildType);
  81530. /* if(!result && buildType == 'room'){//如果要找的是room, 且按刚才的顺序找不到的话,就单独从所有rooms中找一遍。因为room可能不在floor和building内。
  81531. let rooms = this.entities.filter(e=>e.buildType == 'room');
  81532. result = rooms.find(e=>e.ifContainsPoint(position))
  81533. }*/
  81534. //虽然房间可以画到上级之外,但是为了方便起见,假定房间绝对在楼层之内。找不到的话要调整空间模型了。
  81535. return result || lastResult
  81536. }
  81537. ,
  81538. findPanos: function(){
  81539. {
  81540. this.entities.forEach(entity=>{
  81541. //清空:
  81542. entity.panos = [];
  81543. entity.flagPano = null;
  81544. viewer.images360.panos.forEach(pano=>{
  81545. if(entity.ifContainsPoint(pano.position)){
  81546. entity.panos.push(pano);
  81547. }
  81548. });
  81549. });
  81550. }
  81551. /* viewer.images360.panos.forEach(pano=>{ //一个漫游点只对应一个实体的话
  81552. let result = this.pointInWhichEntity(pano.position, 'room');
  81553. {//get panos for every entities
  81554. let entity = result
  81555. while(entity){
  81556. entity.panos.push(pano);
  81557. entity = entity.buildParent
  81558. }
  81559. }
  81560. }) */
  81561. {//search center pano
  81562. this.entities.forEach(entity=>{
  81563. let panos = entity.panos;
  81564. if(panos.length == 0)return
  81565. let bound = entity.getBound();
  81566. let center = bound.getCenter(new Vector3);
  81567. let request = [];
  81568. let rank = [
  81569. Images360.scoreFunctions.distanceSquared({position: center})
  81570. ];
  81571. //let panos = entity.panos && entity.panos.length ? entity.panos : viewer.images360.panos //entity没有panos的话,就扩大到所有panos
  81572. let r = Common.sortByScore(panos, request, rank);
  81573. if(r && r.length){
  81574. entity.flagPano = r[0].item;
  81575. }else {
  81576. console.error('no flagPano??');
  81577. }
  81578. });
  81579. }
  81580. }
  81581. ,
  81582. findEntityForDataset:function(){//为每一个数据集寻找它所属的最小实体
  81583. /* var entities = this.entities.filter(e=>e.buildType == 'room' || e.buildType == 'floor' && e.buildChildren.length == 0)
  81584. viewer.scene.pointclouds.forEach(pointcloud=>{
  81585. let cloudVolume = pointcloud.getVolume()
  81586. let scores = []
  81587. entities.forEach(entity=>{
  81588. let volume = entity.intersectPointcloudVolume(pointcloud)
  81589. //注:默认已经findPanos过
  81590. let panos = entity.panos.filter(e=>pointcloud.panos.includes(e));
  81591. let panoCount = panos.length
  81592. let score = volume / cloudVolume + panoCount / pointcloud.panos.length
  81593. scores.push({entity, volume, panoCount, score})
  81594. })
  81595. scores.sort((a,b)=>{ return b.score-a.score })
  81596. if(scores.length == 0 || scores[0].volume/cloudVolume < 0.0001 && scores[0].volume < 3 ){//如果约等于0
  81597. pointcloud.belongToEntity = null
  81598. }else{
  81599. pointcloud.belongToEntity = scores[0].entity;
  81600. }
  81601. }) */
  81602. let getScores = (pointcloud, entities, cloudVolume)=>{
  81603. let scores = [];
  81604. entities.forEach(entity=>{
  81605. let volume = entity.intersectPointcloudVolume(pointcloud);
  81606. //注:默认已经findPanos过
  81607. let panos = entity.panos.filter(e=>pointcloud.panos.includes(e));
  81608. let panoCount = panos.length;
  81609. let score = volume / cloudVolume;
  81610. if(pointcloud.panos.length > 0){
  81611. score += panoCount / pointcloud.panos.length;
  81612. }else {
  81613. //score += 1
  81614. }
  81615. scores.push({entity, volume, panoCount, score});
  81616. });
  81617. scores.sort((a,b)=>{ return b.score-a.score });
  81618. return scores
  81619. };
  81620. viewer.scene.pointclouds.forEach(pointcloud=>{ //先判断父级,如果父集不通过就不判断子级。
  81621. let cloudVolume = pointcloud.getVolume();
  81622. let entities = this.buildings;
  81623. while(1){
  81624. let scores = getScores(pointcloud, entities, cloudVolume);
  81625. if(scores.length == 0 || scores[0].volume/cloudVolume < 0.0001 && scores[0].volume < 3 ){//如果约等于0
  81626. if(scores[0] && scores[0].entity.buildType == 'room'){
  81627. pointcloud.belongToEntity = scores[0].entity; //当该数据集在楼层中,但不在楼层中的任意一个房间时,任意挂载在其中一个房间上。
  81628. break
  81629. }
  81630. pointcloud.belongToEntity = null;
  81631. break;
  81632. }else {
  81633. entities = scores[0].entity.buildChildren;
  81634. if(entities.length == 0){
  81635. pointcloud.belongToEntity = scores[0].entity;
  81636. break;
  81637. }
  81638. }
  81639. }
  81640. });
  81641. /*
  81642. 旧版:
  81643. 只需要考虑 floor 和 room, 因为building的只有一个基底没高度
  81644. floor 和 room 在空间中没有完全的从属关系,因为room可以超出floor之外。所以直接混在一起来查找,但要排除有房间的楼层。
  81645. (现在改为层层递进查找,否则数据集包含entity多的,会直接挂载到体积最大的房间里,即使看起来主体点云并不在该房间)
  81646. 有的数据集虽然很高,但只有近地面的部分才是主体,这部分一般含有全部漫游点。为了防止上层的实体因体积较大而分数高,就把包含漫游点的个数也加入考虑。
  81647. 重叠体积大、且包含漫游点最多的最小实体将会拥有该点云。
  81648. 期望: 最好不挂载到最小子级,因为现在有房间都到房间里了。
  81649. */
  81650. }
  81651. ,
  81652. clear:function(){//清空
  81653. /* entities:[], //所有实体
  81654. buildings:[], //所有建筑父集
  81655. meshGroup: new THREE.Object3D, */
  81656. this.selectEntity(null);
  81657. let length = this.entities.length;
  81658. for(let i=0;i<length;i++){
  81659. this.entities[i].dispose();
  81660. }
  81661. this.entities = [];
  81662. this.buildings = [];
  81663. this.inEntity = null;
  81664. }
  81665. ,
  81666. gotoEntity(id, isNearBy, duration=1000) {
  81667. var entity = this.entities.find(e => e.sid == id);
  81668. let aimPano;
  81669. if (!entity) {
  81670. return console.error('没找到entity ')
  81671. }
  81672. if(Potree.settings.displayMode == 'showPanos'){
  81673. if (isNearBy && entity.panos.length) {
  81674. if(entity.panos.includes(viewer.images360.currentPano)) return 'posNoChange' //已在当前实体中
  81675. let position = viewer.scene.getActiveCamera().position;
  81676. let request = [];
  81677. let rank = [Images360.scoreFunctions.distanceSquared({ position })];
  81678. let r = Common.sortByScore(entity.panos, request, rank);
  81679. aimPano = r[0].item;
  81680. } else {
  81681. if (!entity.flagPano) {
  81682. return console.log('没有flagPano')
  81683. }
  81684. aimPano = entity.flagPano;
  81685. }
  81686. if(aimPano == viewer.images360.currentPano) return 'posNoChange'
  81687. viewer.images360.flyToPano(aimPano);
  81688. }else {
  81689. if(isNearBy && entity.ifContainsPoint(viewer.images360.position) ){
  81690. return 'posNoChange' //已在当前实体中
  81691. }
  81692. let boundingBox = entity.getBound();
  81693. let position = boundingBox.getCenter(new Vector3()); //中心点不一定在entity中,比如半环形建筑(所以要不要改成到漫游点呢)
  81694. let size = boundingBox.getSize(new Vector3());
  81695. if(viewer.modules.Clip && viewer.modules.Clip.editing){
  81696. viewer.modules.Clip.bus.dispatchEvent({type:'flyToPos', position});
  81697. }else {
  81698. if(math.closeTo(position, viewer.images360.position)) return 'posNoChange'
  81699. viewer.scene.view.setView({position, duration});
  81700. }
  81701. viewer.mapViewer.moveTo(position, size, duration);
  81702. }
  81703. return true
  81704. },
  81705. focusEntity(id){
  81706. var entity = this.entities.find(e => e.sid == id);
  81707. let boundingBox = entity.getBound();
  81708. //let boundSize = boundingBox.getSize(new THREE.Vector3())
  81709. let center = boundingBox.getCenter(new Vector3());
  81710. this.SplitScreen.focusOnObject(boundingBox, center);
  81711. this.gotoEntity(id, false, 0);
  81712. },
  81713. removeIlligalArchi(){//删除marker数量小于3个的建筑,当保存时
  81714. let needDelete = [];
  81715. this.entities.forEach(e=>{
  81716. if(e.points.length<3){
  81717. needDelete.push(e);
  81718. }
  81719. });
  81720. needDelete.forEach(e=>this.removeEntity(e));
  81721. },
  81722. };
  81723. // Author: Fyrestar https://mevedia.com (https://github.com/Fyrestar/THREE.InfiniteGridHelper)
  81724. class InfiniteGridHelper extends Mesh{
  81725. constructor(size1, size2, color, distance, opacity1=0.2, opacity2=1){
  81726. color = color || new Color('white');
  81727. size1 = size1 || 10;
  81728. size2 = size2 || 100;
  81729. distance = distance || 8000; //可视距离?越远越模糊
  81730. const geometry = new PlaneBufferGeometry(2, 2, 1, 1);
  81731. const material = new ShaderMaterial({
  81732. side: DoubleSide,
  81733. uniforms: {
  81734. uSize1: {
  81735. value: size1
  81736. },
  81737. uSize2: {
  81738. value: size2
  81739. },
  81740. opacity1:{//线条1的 小格子
  81741. value: opacity1
  81742. },
  81743. opacity2:{//线条2的
  81744. value: opacity2
  81745. },
  81746. uColor: {
  81747. value: color
  81748. },
  81749. uDistance: {
  81750. value: distance
  81751. }
  81752. },
  81753. transparent: true,
  81754. vertexShader: `
  81755. varying vec3 worldPosition;
  81756. uniform float uDistance;
  81757. void main() {
  81758. vec3 pos = position.xyz * uDistance;
  81759. pos.xy += cameraPosition.xy;
  81760. worldPosition = pos;
  81761. gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
  81762. }
  81763. `,
  81764. fragmentShader: `
  81765. varying vec3 worldPosition;
  81766. uniform float uSize1;
  81767. uniform float uSize2;
  81768. uniform float opacity1;
  81769. uniform float opacity2;
  81770. uniform vec3 uColor;
  81771. uniform float uDistance;
  81772. float getGrid(float size) {
  81773. vec2 r = worldPosition.xy / size;
  81774. vec2 grid = abs(fract(r - 0.5) - 0.5) / fwidth(r);
  81775. float line = min(grid.x, grid.y);
  81776. return 1.0 - min(line, 1.0);
  81777. }
  81778. //为何侧面看不到线,因为mesh的正侧面都看不到?
  81779. void main() {
  81780. float d = 1.0 - min(distance(cameraPosition.xy, worldPosition.xy) / uDistance, 1.0);
  81781. float g1 = getGrid(uSize1);
  81782. float g2 = getGrid(uSize2);
  81783. gl_FragColor = vec4(uColor.rgb, mix(g2, g1, g1) * pow(d, 3.0));
  81784. //gl_FragColor.a = mix(0.5 * gl_FragColor.a, gl_FragColor.a, g2);
  81785. gl_FragColor.a = mix(opacity1 * gl_FragColor.a, opacity2 * gl_FragColor.a, g2);
  81786. if ( gl_FragColor.a <= 0.0 ) discard;
  81787. }
  81788. `,
  81789. extensions: {
  81790. derivatives: true
  81791. }
  81792. });
  81793. super(geometry, material);
  81794. this.frustumCulled = false;
  81795. }
  81796. };
  81797. /*
  81798. THREE.InfiniteGridHelper.prototype = {
  81799. ...THREE.Mesh.prototype,
  81800. ...THREE.Object3D.prototype,
  81801. ...THREE.EventDispatcher.prototype
  81802. };
  81803. */
  81804. var TransformControls = function ( camera, domElement, options ) {
  81805. if ( domElement === undefined ) {
  81806. console.warn( 'THREE.TransformControls: The second parameter "domElement" is now mandatory.' );
  81807. domElement = document;
  81808. }
  81809. Object3D.call( this );
  81810. this.visible = false;
  81811. this.domElement = domElement;
  81812. var _gizmo = new TransformControlsGizmo(options);
  81813. this.add( _gizmo );
  81814. this._gizmo = _gizmo;
  81815. var _plane = new TransformControlsPlane(options);
  81816. this.add( _plane );
  81817. /* this.linesAssistance = new TransformControlsLines(options); //水平 垂直 辅助
  81818. this.add( this.linesAssistance ); */
  81819. var scope = this;
  81820. //this.player = options.player;//xzw add
  81821. this.options = options;//xzw add
  81822. // Define properties with getters/setter
  81823. // Setting the defined property will automatically trigger change event
  81824. // Defined properties are passed down to gizmo and plane
  81825. defineProperty( "camera", camera );
  81826. defineProperty( "object", undefined );
  81827. defineProperty( "enabled", true );
  81828. defineProperty( "axis", null );
  81829. defineProperty( "mode", "translate" );
  81830. defineProperty( "translationSnap", null );
  81831. defineProperty( "rotationSnap", null );
  81832. defineProperty( "scaleSnap", null );
  81833. defineProperty( "space", "world" );
  81834. defineProperty( "size", 1 );
  81835. defineProperty( "dragging", false );
  81836. defineProperty( "showX", true );
  81837. defineProperty( "showY", true );
  81838. defineProperty( "showZ", true );
  81839. var changeEvent = { type: "change" };
  81840. var mouseDownEvent = { type: "mouseDown" };
  81841. var mouseUpEvent = { type: "mouseUp", mode: scope.mode };
  81842. var objectChangeEvent = { type: "objectChange" };
  81843. // Reusable utility variables
  81844. var ray = new Raycaster();
  81845. var _tempVector = new Vector3();
  81846. var _tempVector2 = new Vector3();
  81847. var _tempQuaternion = new Quaternion();
  81848. var _unit = {
  81849. X: new Vector3( 1, 0, 0 ),
  81850. Y: new Vector3( 0, 1, 0 ),
  81851. Z: new Vector3( 0, 0, 1 )
  81852. };
  81853. var pointStart = new Vector3();
  81854. var pointEnd = new Vector3();
  81855. var offset = new Vector3();
  81856. var rotationAxis = new Vector3();
  81857. var startNorm = new Vector3();
  81858. var endNorm = new Vector3();
  81859. var rotationAngle = 0;
  81860. var cameraPosition = new Vector3();
  81861. var cameraQuaternion = new Quaternion();
  81862. var cameraScale = new Vector3();
  81863. var parentPosition = new Vector3();
  81864. var parentQuaternion = new Quaternion();
  81865. var parentQuaternionInv = new Quaternion();
  81866. var parentScale = new Vector3();
  81867. var worldPositionStart = new Vector3();
  81868. var worldQuaternionStart = new Quaternion();
  81869. var worldScaleStart = new Vector3();
  81870. var worldPosition = new Vector3();
  81871. var worldQuaternion = new Quaternion();
  81872. var worldQuaternionInv = new Quaternion();
  81873. var worldScale = new Vector3();
  81874. var eye = new Vector3();
  81875. var positionStart = new Vector3();
  81876. var quaternionStart = new Quaternion();
  81877. var scaleStart = new Vector3();
  81878. // TODO: remove properties unused in plane and gizmo
  81879. defineProperty( "worldPosition", worldPosition );
  81880. defineProperty( "worldPositionStart", worldPositionStart );
  81881. defineProperty( "worldQuaternion", worldQuaternion );
  81882. defineProperty( "worldQuaternionStart", worldQuaternionStart );
  81883. defineProperty( "cameraPosition", cameraPosition );
  81884. defineProperty( "cameraQuaternion", cameraQuaternion );
  81885. defineProperty( "pointStart", pointStart );
  81886. defineProperty( "pointEnd", pointEnd );
  81887. defineProperty( "rotationAxis", rotationAxis );
  81888. defineProperty( "rotationAngle", rotationAngle );
  81889. defineProperty( "eye", eye );
  81890. {
  81891. domElement.addEventListener( "mousedown", onPointerDown, false );
  81892. domElement.addEventListener( "touchstart", onPointerDown, false );
  81893. domElement.addEventListener( "mousemove", onPointerHover, false );
  81894. domElement.addEventListener( "touchmove", onPointerHover, false );
  81895. domElement.addEventListener( "touchmove", onPointerMove, false );
  81896. document.addEventListener( "mouseup", onPointerUp, false );
  81897. domElement.addEventListener( "touchend", onPointerUp, false );
  81898. domElement.addEventListener( "touchcancel", onPointerUp, false );
  81899. domElement.addEventListener( "touchleave", onPointerUp, false );
  81900. let drag = ()=>{
  81901. if(this.dragging){
  81902. this.pointerMove();
  81903. return {stopContinue:true}
  81904. }
  81905. };
  81906. this.addEventListener('dragging',drag,{importance:10});
  81907. viewer.addEventListener('global_drag',drag,{importance:10});
  81908. }
  81909. this.setRotateMethod = function(number){//add 注意为2时 旋转期间不能改变位置 space可能不能为local ._gizmo.hideAxis = { rotate:[这里必须包含'e' ] }
  81910. this.rotateMethod = number;
  81911. };
  81912. this.dispose = function () {
  81913. domElement.removeEventListener( "mousedown", onPointerDown );
  81914. domElement.removeEventListener( "touchstart", onPointerDown );
  81915. domElement.removeEventListener( "mousemove", onPointerHover );
  81916. domElement.removeEventListener( "mousemove", onPointerMove );
  81917. domElement.removeEventListener( "touchmove", onPointerHover );
  81918. domElement.removeEventListener( "touchmove", onPointerMove );
  81919. document.removeEventListener( "mouseup", onPointerUp );
  81920. domElement.removeEventListener( "touchend", onPointerUp );
  81921. domElement.removeEventListener( "touchcancel", onPointerUp );
  81922. domElement.removeEventListener( "touchleave", onPointerUp );
  81923. this.traverse( function ( child ) {
  81924. if ( child.geometry ) child.geometry.dispose();
  81925. if ( child.material ) child.material.dispose();
  81926. } );
  81927. };
  81928. // Set current object
  81929. this.attach = function ( object ) {
  81930. this.object = object;
  81931. this.visible = true;
  81932. //Config.keyCon = false;//add
  81933. //this.linesAssistance.setVisible(true)
  81934. viewer.dispatchEvent('content_changed');
  81935. return this;
  81936. };
  81937. // Detatch from object
  81938. this.detach = function () {
  81939. this.object = undefined;
  81940. this.visible = false;
  81941. this.axis = null;
  81942. //Config.keyCon = true;//add
  81943. //this.linesAssistance.setVisible(false)
  81944. viewer.dispatchEvent('content_changed');
  81945. return this;
  81946. };
  81947. //this.space = 'local'
  81948. /* this.hideAxis = function ( mode, axis=[] ) {//xzw add 设置不可见的axis
  81949. var handles = [];
  81950. handles = handles.concat( this._gizmo.picker[ mode ].children );
  81951. handles = handles.concat( this._gizmo.gizmo[ mode ].children );
  81952. handles = handles.concat( this._gizmo.helper[ mode ].children );
  81953. handles.forEach(e=>e.visible = false)
  81954. axis.forEach(name=>{
  81955. handles.filter(handle =>!handle.name.includes(name))
  81956. })
  81957. handles.forEach(e=>e.visible = true)
  81958. }; */
  81959. // Defined getter, setter and store for a property
  81960. function defineProperty( propName, defaultValue ) {
  81961. var propValue = defaultValue;
  81962. Object.defineProperty( scope, propName, {
  81963. get: function () {
  81964. return propValue !== undefined ? propValue : defaultValue;
  81965. },
  81966. set: function ( value ) {
  81967. if ( propValue !== value ) {
  81968. propValue = value;
  81969. _plane[ propName ] = value;
  81970. _gizmo[ propName ] = value;
  81971. scope.dispatchEvent( { type: propName + "-changed", value: value } );
  81972. scope.dispatchEvent( changeEvent );
  81973. }
  81974. }
  81975. } );
  81976. scope[ propName ] = defaultValue;
  81977. _plane[ propName ] = defaultValue;
  81978. _gizmo[ propName ] = defaultValue;
  81979. }
  81980. // updateMatrixWorld updates key transformation variables
  81981. this.updateMatrixWorld = function () {
  81982. if(!this.visible)return//add
  81983. if ( this.object !== undefined ) {
  81984. this.object.updateMatrixWorld();
  81985. this.object.parent.matrixWorld.decompose( parentPosition, parentQuaternion, parentScale );
  81986. this.object.matrixWorld.decompose( worldPosition, worldQuaternion, worldScale );
  81987. //add
  81988. if(this.object.boundingBox){
  81989. let boundingBox = this.object.boundingBox.clone().applyMatrix4(this.object.matrixWorld);
  81990. boundingBox.getCenter(worldPosition); //bound中心
  81991. if(this.pivotOnBottom){
  81992. worldPosition.setZ(boundingBox.min.z); //中心点居于模型bound底部,因固定离地高度,旋转时旋转中心在地面上就不会变位置
  81993. }
  81994. }
  81995. parentQuaternionInv.copy( parentQuaternion ).invert();
  81996. worldQuaternionInv.copy( worldQuaternion ).invert();
  81997. }
  81998. this.camera.updateMatrixWorld();
  81999. this.camera.matrixWorld.decompose( cameraPosition, cameraQuaternion, cameraScale );
  82000. if(this.camera.type == "OrthographicCamera"){//xzw add
  82001. eye.copy( this.view.direction);
  82002. }else {
  82003. eye.copy( cameraPosition ).sub( worldPosition ).normalize();
  82004. }
  82005. Object3D.prototype.updateMatrixWorld.call( this );
  82006. };
  82007. this.pointerHover = function () {
  82008. let pointer = viewer.inputHandler.pointer;
  82009. if ( this.object === undefined)return
  82010. //if(this.dragging === true /* || ( pointer.button !== undefined && pointer.button !== 0 ) */) return;
  82011. if(!this.dragging){
  82012. let oldAxis = this.axis;
  82013. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  82014. let {origin, direction} = viewer.inputHandler.getMouseDirection();
  82015. ray.set(origin, direction);
  82016. Potree.Utils.setCameraLayers(ray, //设置能识别到的layers
  82017. ['sceneObjects','mapObjects','measure', 'transformationTool', 'model'],
  82018. viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers
  82019. );
  82020. var intersect = ray.intersectObjects( _gizmo.picker[ this.mode ].children.filter(e=>e.visible), true )[ 0 ] || false;
  82021. if ( intersect ) {
  82022. this.axis = intersect.object.name;
  82023. } else {
  82024. this.axis = null;
  82025. }
  82026. if(oldAxis != this.axis){
  82027. viewer.dispatchEvent('content_changed');
  82028. }
  82029. }else {
  82030. //this.pointerMove()
  82031. }
  82032. };
  82033. this.pointerDown = function ( /* pointer */ ) {
  82034. let pointer = viewer.inputHandler.pointer;
  82035. if ( this.object === undefined || this.dragging === true /* || ( pointer.button !== undefined && pointer.button !== 0 ) */ ) return;
  82036. if ( /* ( pointer.button === 0 || pointer.button === undefined ) && */ this.axis !== null ) {
  82037. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  82038. let {origin, direction} = viewer.inputHandler.getMouseDirection();
  82039. ray.set(origin, direction);
  82040. Potree.Utils.setCameraLayers(ray, //设置能识别到的layers
  82041. ['sceneObjects','mapObjects','measure', 'transformationTool', 'model'],
  82042. viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers
  82043. );
  82044. var planeIntersect = ray.intersectObjects( [ _plane ], true )[ 0 ] || false;
  82045. if ( planeIntersect ) {
  82046. var space = this.space;
  82047. if ( this.mode === 'scale' ) {
  82048. space = 'local';
  82049. } else if ( this.axis === 'E' || this.axis === 'XYZE' || this.axis === 'XYZ' ) {
  82050. space = 'world';
  82051. }
  82052. if ( space === 'local' && this.mode === 'rotate' ) {
  82053. var snap = this.rotationSnap;
  82054. if ( this.axis === 'X' && snap ) this.object.rotation.x = Math.round( this.object.rotation.x / snap ) * snap;
  82055. if ( this.axis === 'Y' && snap ) this.object.rotation.y = Math.round( this.object.rotation.y / snap ) * snap;
  82056. if ( this.axis === 'Z' && snap ) this.object.rotation.z = Math.round( this.object.rotation.z / snap ) * snap;
  82057. }
  82058. this.object.updateMatrixWorld();
  82059. this.object.parent.updateMatrixWorld();
  82060. positionStart.copy( this.object.position );
  82061. quaternionStart.copy( this.object.quaternion );
  82062. scaleStart.copy( this.object.scale );
  82063. this.object.matrixWorld.decompose( worldPositionStart, worldQuaternionStart, worldScaleStart );
  82064. //add: 使坐标轴在boundingBox中心
  82065. this.object.boundingBox && this.object.boundingBox.getCenter(worldPositionStart).applyMatrix4(this.object.matrixWorld);
  82066. pointStart.copy( planeIntersect.point ).sub( worldPositionStart );
  82067. /* if(this.player.cameraControls.activeControl){
  82068. //this.player.cameraControls.activeControl.locked = true; //add
  82069. this.player.cameraControls.activeControl.enabled = false; //add
  82070. } */
  82071. }
  82072. this.dragging = true;
  82073. mouseDownEvent.mode = this.mode;
  82074. this.dispatchEvent( mouseDownEvent );
  82075. }
  82076. };
  82077. this.pointerMove = function ( /* pointer */ ) {
  82078. let pointer = viewer.inputHandler.pointer;
  82079. var axis = this.axis;
  82080. var mode = this.mode;
  82081. var object = this.object;
  82082. var space = this.space;
  82083. if ( mode === 'scale' ) {
  82084. space = 'local';
  82085. } else if ( axis === 'E' || axis === 'XYZE' || axis === 'XYZ' ) {
  82086. space = 'world';
  82087. }
  82088. if ( object === undefined || axis === null || this.dragging === false || ( pointer.button !== undefined && pointer.button !== 0 ) ) return;
  82089. //ray.setFromCamera( pointer, this.camera ); //这句会在floorplan模式get不到intersect
  82090. let {origin, direction} = viewer.inputHandler.getMouseDirection();
  82091. ray.set(origin, direction);
  82092. Potree.Utils.setCameraLayers(ray, //设置能识别到的layers
  82093. ['sceneObjects','mapObjects','measure', 'transformationTool', 'model'],
  82094. viewer.inputHandler.hoverViewport && viewer.inputHandler.hoverViewport.extraEnableLayers
  82095. );
  82096. var planeIntersect = ray.intersectObjects( [ _plane ], true )[ 0 ] || false;
  82097. if ( planeIntersect === false ) return;
  82098. pointEnd.copy( planeIntersect.point ).sub( worldPositionStart );
  82099. if ( mode === 'translate' ) {
  82100. // Apply translate
  82101. offset.copy( pointEnd ).sub( pointStart );
  82102. if ( space === 'local' && axis !== 'XYZ' ) {
  82103. offset.applyQuaternion( worldQuaternionInv );
  82104. }
  82105. if ( axis.indexOf( 'X' ) === - 1 ) offset.x = 0;
  82106. if ( axis.indexOf( 'Y' ) === - 1 ) offset.y = 0;
  82107. if ( axis.indexOf( 'Z' ) === - 1 ) offset.z = 0;
  82108. if ( space === 'local' && axis !== 'XYZ' ) {
  82109. //xzw 加,否则会反向---------------
  82110. object.scale.x < 0 && (offset.x *= -1);
  82111. object.scale.y < 0 && (offset.y *= -1);
  82112. object.scale.z < 0 && (offset.z *= -1);
  82113. //---------------------------------
  82114. offset.applyQuaternion( quaternionStart ).divide( parentScale );
  82115. } else {
  82116. offset.applyQuaternion( parentQuaternionInv ).divide( parentScale );
  82117. }
  82118. object.position.copy( offset ).add( positionStart );
  82119. // Apply translation snap
  82120. if ( this.translationSnap ) {
  82121. if ( space === 'local' ) {
  82122. object.position.applyQuaternion( _tempQuaternion.copy( quaternionStart ).invert() );
  82123. if ( axis.search( 'X' ) !== - 1 ) {
  82124. object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
  82125. }
  82126. if ( axis.search( 'Y' ) !== - 1 ) {
  82127. object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
  82128. }
  82129. if ( axis.search( 'Z' ) !== - 1 ) {
  82130. object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
  82131. }
  82132. object.position.applyQuaternion( quaternionStart );
  82133. }
  82134. if ( space === 'world' ) {
  82135. if ( object.parent ) {
  82136. object.position.add( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
  82137. }
  82138. if ( axis.search( 'X' ) !== - 1 ) {
  82139. object.position.x = Math.round( object.position.x / this.translationSnap ) * this.translationSnap;
  82140. }
  82141. if ( axis.search( 'Y' ) !== - 1 ) {
  82142. object.position.y = Math.round( object.position.y / this.translationSnap ) * this.translationSnap;
  82143. }
  82144. if ( axis.search( 'Z' ) !== - 1 ) {
  82145. object.position.z = Math.round( object.position.z / this.translationSnap ) * this.translationSnap;
  82146. }
  82147. if ( object.parent ) {
  82148. object.position.sub( _tempVector.setFromMatrixPosition( object.parent.matrixWorld ) );
  82149. }
  82150. }
  82151. }
  82152. //add:
  82153. object.dispatchEvent({
  82154. type: "position_changed"
  82155. });
  82156. } else if ( mode === 'scale' ) {
  82157. if ( axis.search( 'XYZ' ) !== - 1 ) {
  82158. var d = pointEnd.length() / pointStart.length();
  82159. if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
  82160. if(options.NoScaleZ){//xzw add
  82161. _tempVector2.set( d, d, 1 );
  82162. }else {
  82163. _tempVector2.set( d, d, d );
  82164. }
  82165. }else if ( axis.search( 'XY' ) !== - 1 ) { //add 等比例for plane
  82166. var d = pointEnd.length() / pointStart.length();
  82167. if ( pointEnd.dot( pointStart ) < 0 ) d *= - 1;
  82168. _tempVector2.set( d, d, 1 );
  82169. }else {
  82170. _tempVector.copy( pointStart );
  82171. _tempVector2.copy( pointEnd );
  82172. _tempVector.applyQuaternion( worldQuaternionInv );
  82173. _tempVector2.applyQuaternion( worldQuaternionInv );
  82174. _tempVector2.divide( _tempVector );
  82175. if ( axis.search( 'X' ) === - 1 ) {
  82176. _tempVector2.x = 1;
  82177. }
  82178. if ( axis.search( 'Y' ) === - 1 ) {
  82179. _tempVector2.y = 1;
  82180. }
  82181. if ( axis.search( 'Z' ) === - 1 ) {
  82182. _tempVector2.z = 1;
  82183. }
  82184. }
  82185. // Apply scale
  82186. object.scale.copy( scaleStart ).multiply( _tempVector2 );
  82187. if ( this.scaleSnap ) {
  82188. if ( axis.search( 'X' ) !== - 1 ) {
  82189. object.scale.x = Math.round( object.scale.x / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
  82190. }
  82191. if ( axis.search( 'Y' ) !== - 1 ) {
  82192. object.scale.y = Math.round( object.scale.y / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
  82193. }
  82194. if ( axis.search( 'Z' ) !== - 1 ) {
  82195. object.scale.z = Math.round( object.scale.z / this.scaleSnap ) * this.scaleSnap || this.scaleSnap;
  82196. }
  82197. }
  82198. //add:
  82199. object.dispatchEvent({
  82200. type: "scale_changed"
  82201. });
  82202. } else if ( mode === 'rotate' ) {
  82203. if(this.rotateMethod == 2){//新版参照transfromTool的写法,更跟手,但是有bug,在同时移动位置时或e轴上有问题
  82204. if ( axis === 'E' ) {//绕着视线转
  82205. rotationAxis.copy( eye );//旋转轴
  82206. rotationAngle = pointEnd.angleTo( pointStart );
  82207. startNorm.copy( pointStart ).normalize();
  82208. endNorm.copy( pointEnd ).normalize();
  82209. rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 ); //角度
  82210. }else {
  82211. if ( axis === 'XYZE' ) {//像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
  82212. offset.copy( pointEnd ).sub( pointStart );
  82213. rotationAxis.copy( offset ).cross( eye ).normalize();
  82214. }else {
  82215. rotationAxis.copy( _unit[ axis ] );
  82216. }
  82217. let center = new Vector3;//坐标轴位置
  82218. /* if(this.object.boundingBox){
  82219. center.copy(worldPosition) //center设置为boundingbox的中心。但center一直更改会导致虽然在按某个时针旋转,但v2相对v1可能会时不时逆向,导致闪烁。所以固定住center,虽然这样计算的角度和绕模型中心的感觉偏颇
  82220. }else{ */
  82221. center.copy(worldPositionStart);
  82222. //}
  82223. let rotationAxis_ = space === 'local' ? rotationAxis.clone().applyQuaternion(worldQuaternion) : rotationAxis;
  82224. let plane = new Plane().setFromNormalAndCoplanarPoint(rotationAxis_, center);//旋转过程中rotationAxis不会变化,但center可能会
  82225. let {origin, direction} = viewer.inputHandler.getMouseDirection();
  82226. ray.set(origin, direction);
  82227. let I = ray.ray.intersectPlane(plane, new Vector3());
  82228. if (I) {
  82229. let v2 = I.clone().sub(center);//.normalize();
  82230. if(!this.rotateStart){
  82231. this.rotateStart = {
  82232. v1: v2
  82233. };
  82234. return
  82235. }
  82236. let v1 = this.rotateStart.v1;
  82237. rotationAngle = math.getAngle( v1, v2, rotationAxis_);
  82238. //console.log('rot', rotationAngle, center.toArray())
  82239. if (Number.isNaN(rotationAngle)) {
  82240. return;
  82241. }
  82242. this.rotateStart.v1 = v2;
  82243. }
  82244. }
  82245. }else {
  82246. //pointStart 是起始intersect - object中心的向量
  82247. //pointEnd 是当前intersect - object中心的向量
  82248. offset.copy( pointEnd ).sub( pointStart );
  82249. var ROTATION_SPEED = 2 / worldPosition.distanceTo( _tempVector.setFromMatrixPosition( this.camera.matrixWorld ) );
  82250. if ( axis === 'E' ) {//绕着视线转
  82251. rotationAxis.copy( eye );//旋转轴
  82252. rotationAngle = pointEnd.angleTo( pointStart );
  82253. startNorm.copy( pointStart ).normalize();
  82254. endNorm.copy( pointEnd ).normalize();
  82255. rotationAngle *= ( endNorm.cross( startNorm ).dot( eye ) < 0 ? 1 : - 1 ); //角度
  82256. } else if ( axis === 'XYZE' ) {//像滚球一样拨动,鼠标滑动方向为拨动方向,在plane面上滚动
  82257. rotationAxis.copy( offset ).cross( eye ).normalize();
  82258. rotationAngle = offset.dot( _tempVector.copy( rotationAxis ).cross( this.eye ) ) * ROTATION_SPEED;
  82259. } else if ( axis === 'X' || axis === 'Y' || axis === 'Z' ) {
  82260. rotationAxis.copy( _unit[ axis ] );
  82261. _tempVector.copy( _unit[ axis ] );
  82262. if ( space === 'local' ) {
  82263. _tempVector.applyQuaternion( worldQuaternion );
  82264. }
  82265. rotationAngle = offset.dot( _tempVector.cross( eye ).normalize() ) * ROTATION_SPEED;
  82266. }
  82267. // Apply rotation snap
  82268. if ( this.rotationSnap ) rotationAngle = Math.round( rotationAngle / this.rotationSnap ) * this.rotationSnap;
  82269. this.rotationAngle = rotationAngle;
  82270. }
  82271. // Apply rotate
  82272. if ( space === 'local' && axis !== 'E' && axis !== 'XYZE' ) {
  82273. object.scale[axis.toLowerCase()] < 0 && (rotationAngle *= -1); //xzw 加,否则会反向
  82274. object.quaternion.copy( quaternionStart );
  82275. object.quaternion.multiply( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) ).normalize();
  82276. } else {
  82277. rotationAxis.applyQuaternion( parentQuaternionInv );
  82278. object.quaternion.copy( _tempQuaternion.setFromAxisAngle( rotationAxis, rotationAngle ) );
  82279. object.quaternion.multiply( quaternionStart ).normalize();
  82280. }
  82281. if ( this.rotateMethod == 2 && axis != 'E' ) {
  82282. quaternionStart.copy(object.quaternion);
  82283. }
  82284. //add:
  82285. object.dispatchEvent({
  82286. type: "rotation_changed"
  82287. });
  82288. }
  82289. this.dispatchEvent( changeEvent );
  82290. this.dispatchEvent( objectChangeEvent );
  82291. viewer.dispatchEvent('content_changed');
  82292. };
  82293. this.pointerUp = function ( pointer ) {
  82294. //if ( pointer.button !== undefined && pointer.button !== 0 ) return;
  82295. if ( this.dragging && ( this.axis !== null ) ) {
  82296. mouseUpEvent.mode = this.mode;
  82297. this.dispatchEvent( mouseUpEvent );
  82298. /* if(this.player.cameraControls.activeControl){
  82299. //this.player.cameraControls.activeControl.locked = false; //add
  82300. this.player.cameraControls.activeControl.pointerDragOn = false //add
  82301. this.player.cameraControls.activeControl.enabled = true
  82302. } */
  82303. this.rotateStart = null;//add
  82304. }
  82305. this.dragging = false;
  82306. //if ( pointer.button === undefined ) this.axis = null;
  82307. /* if(this.player.cameraControls.activeControl){
  82308. //this.player.cameraControls.activeControl.locked = false; //add
  82309. this.player.cameraControls.activeControl.pointerDragOn = false //add
  82310. this.player.cameraControls.activeControl.enabled = true
  82311. } */
  82312. };
  82313. // normalize mouse / touch pointer and remap {x,y} to view space.
  82314. function getPointer( event ) {
  82315. if(!event){
  82316. console.log('hhahhhahah');
  82317. return;
  82318. }
  82319. if ( document.pointerLockElement ) {
  82320. return {
  82321. x: 0,
  82322. y: 0,
  82323. button: event.button
  82324. };
  82325. } else {
  82326. var pointer = event.changedTouches ? event.changedTouches[ 0 ] : event;
  82327. var rect = domElement.getBoundingClientRect();
  82328. return {
  82329. x: ( pointer.clientX - rect.left ) / rect.width * 2 - 1,
  82330. y: - ( pointer.clientY - rect.top ) / rect.height * 2 + 1,
  82331. button: event.button
  82332. };
  82333. }
  82334. }
  82335. // mouse / touch event handlers
  82336. function onPointerHover( event ) {
  82337. if ( ! scope.enabled ) return;
  82338. //scope.pointerHover( getPointer( event ) );
  82339. scope.pointerHover( );
  82340. }
  82341. function onPointerDown( event ) {
  82342. if ( ! scope.enabled ) return;
  82343. //document.addEventListener( "mousemove", onPointerMove, false );
  82344. /* scope.pointerHover( getPointer( event ) );
  82345. scope.pointerDown( getPointer( event ) ); */
  82346. scope.pointerHover( );
  82347. scope.pointerDown();
  82348. }
  82349. this.onPointerDown = onPointerDown;
  82350. function onPointerMove( event ) {
  82351. if ( ! scope.enabled || !this.dragging) return; //xzw change
  82352. //scope.pointerMove( getPointer( event ) );
  82353. scope.pointerMove( );
  82354. }
  82355. this.onPointerMove = onPointerMove;
  82356. function onPointerUp( event ) {
  82357. if ( ! scope.enabled ) return;
  82358. //document.removeEventListener( "mousemove", onPointerMove, false );
  82359. //scope.pointerUp( getPointer( event ) );
  82360. scope.pointerUp( );
  82361. }
  82362. this.onPointerUp = onPointerUp;
  82363. // TODO: deprecate
  82364. this.getMode = function () {
  82365. return scope.mode;
  82366. };
  82367. this.setMode = function ( mode ) {
  82368. scope.mode = mode;
  82369. };
  82370. this.setTranslationSnap = function ( translationSnap ) {
  82371. scope.translationSnap = translationSnap;
  82372. };
  82373. this.setRotationSnap = function ( rotationSnap ) {
  82374. scope.rotationSnap = rotationSnap;
  82375. };
  82376. this.setScaleSnap = function ( scaleSnap ) {
  82377. scope.scaleSnap = scaleSnap;
  82378. };
  82379. this.setSize = function ( size ) {
  82380. scope.size = size;
  82381. };
  82382. this.setSpace = function ( space ) {
  82383. scope.space = space;
  82384. };
  82385. this.update = function () {
  82386. console.warn( 'THREE.TransformControls: update function has no more functionality and therefore has been deprecated.' );
  82387. };
  82388. };
  82389. var TransformControlsGizmo = function (options) {
  82390. 'use strict';
  82391. Object3D.call( this );
  82392. this.type = 'TransformControlsGizmo';
  82393. // shared materials
  82394. this.hideAxis = {};
  82395. var gizmoMaterial = new MeshBasicMaterial( {
  82396. depthTest: false,
  82397. depthWrite: false,
  82398. transparent: true,
  82399. side: DoubleSide,
  82400. fog: false
  82401. } );
  82402. var gizmoLineMaterial = new LineBasicMaterial( {
  82403. depthTest: false,
  82404. depthWrite: false,
  82405. transparent: true,
  82406. fog: false
  82407. } );
  82408. // Make unique material for each axis/color
  82409. var matInvisible = gizmoMaterial.clone();
  82410. matInvisible.opacity = 0.15;
  82411. var matHelper = gizmoMaterial.clone();
  82412. matHelper.opacity = 0.1;
  82413. var matRed = gizmoMaterial.clone();
  82414. matRed.color.set( 0xff0000 );
  82415. var matGreen = gizmoMaterial.clone();
  82416. matGreen.color.set( 0x00ff00 );
  82417. var matBlue = gizmoMaterial.clone();
  82418. matBlue.color.set( 0x0000ff );
  82419. var matWhiteTransparent = gizmoMaterial.clone();
  82420. matWhiteTransparent.opacity = 0.35;
  82421. matWhiteTransparent.color.set( 0x00d0fd );//xzw add
  82422. var matYellowTransparent = matWhiteTransparent.clone();
  82423. matYellowTransparent.color.set( 0xffff00 );
  82424. var matCyanTransparent = matWhiteTransparent.clone();
  82425. matCyanTransparent.color.set( 0x00ffff );
  82426. var matMagentaTransparent = matWhiteTransparent.clone();
  82427. matMagentaTransparent.color.set( 0xff00ff );
  82428. var matYellow = gizmoMaterial.clone();
  82429. matYellow.color.set( 0xffff00 );
  82430. var matLineRed = gizmoLineMaterial.clone();
  82431. matLineRed.color.set( 0xff0000 );
  82432. var matLineGreen = gizmoLineMaterial.clone();
  82433. matLineGreen.color.set( 0x00ff00 );
  82434. var matLineBlue = gizmoLineMaterial.clone();
  82435. matLineBlue.color.set( 0x0000ff );
  82436. var matLineCyan = gizmoLineMaterial.clone();
  82437. matLineCyan.color.set( 0x00ffff );
  82438. var matLineMagenta = gizmoLineMaterial.clone();
  82439. matLineMagenta.color.set( 0xff00ff );
  82440. var matLineYellow = gizmoLineMaterial.clone();
  82441. matLineYellow.color.set( 0xffff00 );
  82442. var matLineGray = gizmoLineMaterial.clone();
  82443. matLineGray.color.set( 0x787878 );
  82444. var matLineYellowTransparent = matLineYellow.clone();
  82445. matLineYellowTransparent.opacity = 0.25;
  82446. // reusable geometry
  82447. var arrowGeometry = new CylinderBufferGeometry( 0, 0.05, 0.2, 12, 1, false );
  82448. var scaleHandleGeometry = new BoxBufferGeometry( 0.125, 0.125, 0.125 );
  82449. var lineGeometry = new BufferGeometry( );
  82450. //lineGeometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 0, 0 ], 3 ) );
  82451. lineGeometry.setAttribute("position", new BufferAttribute(new Float32Array([ 0, 0, 0, 1, 0, 0]), 3 ));
  82452. var CircleGeometry = function ( radius, arc ) {
  82453. var geometry = new BufferGeometry( );
  82454. var vertices = [];
  82455. for ( var i = 0; i <= 64 * arc; ++ i ) {
  82456. vertices.push( 0, Math.cos( i / 32 * Math.PI ) * radius, Math.sin( i / 32 * Math.PI ) * radius );
  82457. }
  82458. //geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
  82459. geometry.setAttribute("position", new BufferAttribute(new Float32Array(vertices), 3 ));
  82460. return geometry;
  82461. };
  82462. // Special geometry for transform helper. If scaled with position vector it spans from [0,0,0] to position
  82463. var TranslateHelperGeometry = function () {
  82464. var geometry = new BufferGeometry();
  82465. //geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( [ 0, 0, 0, 1, 1, 1 ], 3 ) );
  82466. geometry.setAttribute("position", new BufferAttribute(new Float32Array([ 0, 0, 0, 1, 1, 1 ]), 3 ));
  82467. return geometry;
  82468. };
  82469. // Gizmo definitions - custom hierarchy definitions for setupGizmo() function
  82470. var gizmoTranslate = {
  82471. X: [
  82472. [ new Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, - Math.PI / 2 ], null, 'fwd' ],
  82473. //[ new THREE.Mesh( arrowGeometry, matRed ), [ 1, 0, 0 ], [ 0, 0, Math.PI / 2 ], null, 'bwd' ],
  82474. [ new Line( lineGeometry, matLineRed ) ]
  82475. ],
  82476. Y: [
  82477. [ new Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], null, null, 'fwd' ],
  82478. //[ new THREE.Mesh( arrowGeometry, matGreen ), [ 0, 1, 0 ], [ Math.PI, 0, 0 ], null, 'bwd' ],
  82479. [ new Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ]]
  82480. ],
  82481. Z: [
  82482. [ new Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ Math.PI / 2, 0, 0 ], null, 'fwd' ],
  82483. //[ new THREE.Mesh( arrowGeometry, matBlue ), [ 0, 0, 1 ], [ - Math.PI / 2, 0, 0 ], null, 'bwd' ],
  82484. [ new Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ]]
  82485. ],
  82486. /* XYZ: [
  82487. [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.1, 0 ), matWhiteTransparent.clone() ), [ 0, 0, 0 ], [ 0, 0, 0 ]]
  82488. ], */
  82489. XY: [
  82490. [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matYellowTransparent.clone() ), [ 0.15, 0.15, 0 ]],
  82491. [ new Line( lineGeometry, matLineYellow ), [ 0.18, 0.3, 0 ], null, [ 0.125, 1, 1 ]],
  82492. [ new Line( lineGeometry, matLineYellow ), [ 0.3, 0.18, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
  82493. ],
  82494. YZ: [
  82495. [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matCyanTransparent.clone() ), [ 0, 0.15, 0.15 ], [ 0, Math.PI / 2, 0 ]],
  82496. [ new Line( lineGeometry, matLineCyan ), [ 0, 0.18, 0.3 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
  82497. [ new Line( lineGeometry, matLineCyan ), [ 0, 0.3, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  82498. ],
  82499. XZ: [
  82500. [ new Mesh( new PlaneBufferGeometry( 0.295, 0.295 ), matMagentaTransparent.clone() ), [ 0.15, 0, 0.15 ], [ - Math.PI / 2, 0, 0 ]],
  82501. [ new Line( lineGeometry, matLineMagenta ), [ 0.18, 0, 0.3 ], null, [ 0.125, 1, 1 ]],
  82502. [ new Line( lineGeometry, matLineMagenta ), [ 0.3, 0, 0.18 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  82503. ]
  82504. };
  82505. var pickerTranslate = {
  82506. X: [
  82507. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0.6, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
  82508. ],
  82509. Y: [
  82510. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0.6, 0 ]]
  82511. ],
  82512. Z: [
  82513. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 1, 4, 1, false ), matInvisible ), [ 0, 0, 0.6 ], [ Math.PI / 2, 0, 0 ]]
  82514. ],
  82515. /* XYZ: [
  82516. [ new THREE.Mesh( new THREE.OctahedronBufferGeometry( 0.2, 0 ), matInvisible ) ]
  82517. ], */
  82518. XY: [
  82519. [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0.2, 0 ]]
  82520. ],
  82521. YZ: [
  82522. [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0, 0.2, 0.2 ], [ 0, Math.PI / 2, 0 ]]
  82523. ],
  82524. XZ: [
  82525. [ new Mesh( new PlaneBufferGeometry( 0.4, 0.4 ), matInvisible ), [ 0.2, 0, 0.2 ], [ - Math.PI / 2, 0, 0 ]]
  82526. ]
  82527. };
  82528. var helperTranslate = {
  82529. START: [
  82530. [ new Mesh( new OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
  82531. ],
  82532. END: [
  82533. [ new Mesh( new OctahedronBufferGeometry( 0.01, 2 ), matHelper ), null, null, null, 'helper' ]
  82534. ],
  82535. DELTA: [
  82536. [ new Line( TranslateHelperGeometry(), matHelper ), null, null, null, 'helper' ]
  82537. ],
  82538. X: [
  82539. [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
  82540. ],
  82541. Y: [
  82542. [ new Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
  82543. ],
  82544. Z: [
  82545. [ new Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
  82546. ]
  82547. };
  82548. let arc = options.rotFullCircle ? 1 : 0.5;//add
  82549. var gizmoRotate = {
  82550. X: [
  82551. [ new Line( CircleGeometry( 1, arc ), matLineRed ) ],
  82552. [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matRed ), [ 0, 0, 0.99 ], null, [ 1, 3, 1 ]],
  82553. ],
  82554. Y: [
  82555. [ new Line( CircleGeometry( 1, arc ), matLineGreen ), null, [ 0, 0, - Math.PI / 2 ]],
  82556. [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matGreen ), [ 0, 0, 0.99 ], null, [ 3, 1, 1 ]],
  82557. ],
  82558. Z: [
  82559. [ new Line( CircleGeometry( 1, arc ), matLineBlue ), null, [ 0, Math.PI / 2, 0 ]],
  82560. [ new Mesh( new OctahedronBufferGeometry( 0.04, 0 ), matBlue ), [ 0.99, 0, 0 ], null, [ 1, 3, 1 ]],
  82561. ],
  82562. E: [
  82563. [ new Line( CircleGeometry( 1.25, 1 ), matLineYellowTransparent ), null, [ 0, Math.PI / 2, 0 ]],
  82564. [ 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 ]],
  82565. [ 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 ]],
  82566. [ 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 ]],
  82567. [ new Mesh( new CylinderBufferGeometry( 0.03, 0, 0.15, 4, 1, false ), matLineYellowTransparent ), [ 0, 1.17, 0 ], [ 0, 0, 0 ], [ 1, 1, 0.001 ]],
  82568. ],
  82569. XYZE: [
  82570. [ new Line( CircleGeometry( 1, 1 ), matLineGray ), null, [ 0, Math.PI / 2, 0 ]]
  82571. ]
  82572. };
  82573. var helperRotate = {
  82574. AXIS: [
  82575. [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
  82576. ]
  82577. };
  82578. var pickerRotate = {
  82579. X: [
  82580. [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, - Math.PI / 2, - Math.PI / 2 ]],
  82581. ],
  82582. Y: [
  82583. [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ Math.PI / 2, 0, 0 ]],
  82584. ],
  82585. Z: [
  82586. [ new Mesh( new TorusBufferGeometry( 1, 0.1, 4, 24 ), matInvisible ), [ 0, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
  82587. ],
  82588. E: [
  82589. [ new Mesh( new TorusBufferGeometry( 1.25, 0.1, 2, 24 ), matInvisible ) ]
  82590. ],
  82591. XYZE: [
  82592. [ new Mesh( new SphereBufferGeometry( 0.7, 10, 8 ), matInvisible ) ]
  82593. ]
  82594. };
  82595. var gizmoScale = {
  82596. X: [
  82597. [ new Mesh( scaleHandleGeometry, matRed ), [ 0.8, 0, 0 ], [ 0, 0, - Math.PI / 2 ]],
  82598. [ new Line( lineGeometry, matLineRed ), null, null, [ 0.8, 1, 1 ]]
  82599. ],
  82600. Y: [
  82601. [ new Mesh( scaleHandleGeometry, matGreen ), [ 0, 0.8, 0 ]],
  82602. [ new Line( lineGeometry, matLineGreen ), null, [ 0, 0, Math.PI / 2 ], [ 0.8, 1, 1 ]]
  82603. ],
  82604. Z: [
  82605. [ new Mesh( scaleHandleGeometry, matBlue ), [ 0, 0, 0.8 ], [ Math.PI / 2, 0, 0 ]],
  82606. [ new Line( lineGeometry, matLineBlue ), null, [ 0, - Math.PI / 2, 0 ], [ 0.8, 1, 1 ]]
  82607. ],
  82608. XY: [
  82609. [ new Mesh( scaleHandleGeometry, matYellowTransparent ), [ 0.85, 0.85, 0 ], null, [ 2, 2, 0.2 ]],
  82610. [ new Line( lineGeometry, matLineYellow ), [ 0.855, 0.98, 0 ], null, [ 0.125, 1, 1 ]],
  82611. [ new Line( lineGeometry, matLineYellow ), [ 0.98, 0.855, 0 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]]
  82612. ],
  82613. /* YZ: [
  82614. [ new THREE.Mesh( scaleHandleGeometry, matCyanTransparent ), [ 0, 0.85, 0.85 ], null, [ 0.2, 2, 2 ]],
  82615. [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.855, 0.98 ], [ 0, 0, Math.PI / 2 ], [ 0.125, 1, 1 ]],
  82616. [ new THREE.Line( lineGeometry, matLineCyan ), [ 0, 0.98, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  82617. ],
  82618. XZ: [
  82619. [ new THREE.Mesh( scaleHandleGeometry, matMagentaTransparent ), [ 0.85, 0, 0.85 ], null, [ 2, 0.2, 2 ]],
  82620. [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.855, 0, 0.98 ], null, [ 0.125, 1, 1 ]],
  82621. [ new THREE.Line( lineGeometry, matLineMagenta ), [ 0.98, 0, 0.855 ], [ 0, - Math.PI / 2, 0 ], [ 0.125, 1, 1 ]]
  82622. ],
  82623. XYZX: [
  82624. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 1.1, 0, 0 ]],
  82625. ],*/
  82626. XYZY: [
  82627. [ new Mesh( new BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 1.1, 0 ]],
  82628. ]/* ,
  82629. XYZZ: [
  82630. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.125, 0.125, 0.125 ), matWhiteTransparent.clone() ), [ 0, 0, 1.1 ]],
  82631. ] */
  82632. };
  82633. var pickerScale = {
  82634. X: [
  82635. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0.5, 0, 0 ], [ 0, 0, - Math.PI / 2 ]]
  82636. ],
  82637. Y: [
  82638. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0.5, 0 ]]
  82639. ],
  82640. Z: [
  82641. [ new Mesh( new CylinderBufferGeometry( 0.2, 0, 0.8, 4, 1, false ), matInvisible ), [ 0, 0, 0.5 ], [ Math.PI / 2, 0, 0 ]]
  82642. ],
  82643. XY: [
  82644. [ new Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0.85, 0 ], null, [ 3, 3, 0.2 ]],
  82645. ],
  82646. /*YZ: [
  82647. [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0, 0.85, 0.85 ], null, [ 0.2, 3, 3 ]],
  82648. ],
  82649. XZ: [
  82650. [ new THREE.Mesh( scaleHandleGeometry, matInvisible ), [ 0.85, 0, 0.85 ], null, [ 3, 0.2, 3 ]],
  82651. ],
  82652. XYZX: [
  82653. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 1.1, 0, 0 ]],
  82654. ],*/
  82655. XYZY: [
  82656. [ new Mesh( new BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 1.1, 0 ]],
  82657. ]/* ,
  82658. XYZZ: [
  82659. [ new THREE.Mesh( new THREE.BoxBufferGeometry( 0.2, 0.2, 0.2 ), matInvisible ), [ 0, 0, 1.1 ]],
  82660. ] */
  82661. };
  82662. var helperScale = {
  82663. X: [
  82664. [ new Line( lineGeometry, matHelper.clone() ), [ - 1e3, 0, 0 ], null, [ 1e6, 1, 1 ], 'helper' ]
  82665. ],
  82666. Y: [
  82667. [ new Line( lineGeometry, matHelper.clone() ), [ 0, - 1e3, 0 ], [ 0, 0, Math.PI / 2 ], [ 1e6, 1, 1 ], 'helper' ]
  82668. ],
  82669. Z: [
  82670. [ new Line( lineGeometry, matHelper.clone() ), [ 0, 0, - 1e3 ], [ 0, - Math.PI / 2, 0 ], [ 1e6, 1, 1 ], 'helper' ]
  82671. ]
  82672. };
  82673. // Creates an THREE.Object3D with gizmos described in custom hierarchy definition.
  82674. var setupGizmo = function ( gizmoMap ) {
  82675. var gizmo = new Object3D();
  82676. for ( var name in gizmoMap ) {
  82677. for ( var i = gizmoMap[ name ].length; i --; ) {
  82678. var object = gizmoMap[ name ][ i ][ 0 ].clone();
  82679. var position = gizmoMap[ name ][ i ][ 1 ];
  82680. var rotation = gizmoMap[ name ][ i ][ 2 ];
  82681. var scale = gizmoMap[ name ][ i ][ 3 ];
  82682. var tag = gizmoMap[ name ][ i ][ 4 ];
  82683. // name and tag properties are essential for picking and updating logic.
  82684. object.name = name;
  82685. object.tag = tag;
  82686. if ( position ) {
  82687. object.position.set( position[ 0 ], position[ 1 ], position[ 2 ] );
  82688. }
  82689. if ( rotation ) {
  82690. object.rotation.set( rotation[ 0 ], rotation[ 1 ], rotation[ 2 ] );
  82691. }
  82692. if ( scale ) {
  82693. object.scale.set( scale[ 0 ], scale[ 1 ], scale[ 2 ] );
  82694. }
  82695. object.updateMatrix();
  82696. var tempGeometry = object.geometry.clone();
  82697. tempGeometry.applyMatrix4( object.matrix );
  82698. object.geometry = tempGeometry;
  82699. object.renderOrder = Infinity;
  82700. object.position.set( 0, 0, 0 );
  82701. object.rotation.set( 0, 0, 0 );
  82702. object.scale.set( 1, 1, 1 );
  82703. gizmo.add( object );
  82704. }
  82705. }
  82706. return gizmo;
  82707. };
  82708. // Reusable utility variables
  82709. var tempVector = new Vector3( 0, 0, 0 );
  82710. var tempEuler = new Euler();
  82711. var alignVector = new Vector3( 0, 1, 0 );
  82712. var zeroVector = new Vector3( 0, 0, 0 );
  82713. var lookAtMatrix = new Matrix4();
  82714. var tempQuaternion = new Quaternion();
  82715. var tempQuaternion2 = new Quaternion();
  82716. var identityQuaternion = new Quaternion();
  82717. var unitX = new Vector3( 1, 0, 0 );
  82718. var unitY = new Vector3( 0, 1, 0 );
  82719. var unitZ = new Vector3( 0, 0, 1 );
  82720. // Gizmo creation
  82721. this.gizmo = {};
  82722. this.picker = {};
  82723. this.helper = {};
  82724. this.add( this.gizmo[ "translate" ] = setupGizmo( gizmoTranslate ) );
  82725. this.add( this.gizmo[ "rotate" ] = setupGizmo( gizmoRotate ) );
  82726. this.add( this.gizmo[ "scale" ] = setupGizmo( gizmoScale ) );
  82727. this.add( this.picker[ "translate" ] = setupGizmo( pickerTranslate ) );
  82728. this.add( this.picker[ "rotate" ] = setupGizmo( pickerRotate ) );
  82729. this.add( this.picker[ "scale" ] = setupGizmo( pickerScale ) );
  82730. this.add( this.helper[ "translate" ] = setupGizmo( helperTranslate ) );
  82731. this.add( this.helper[ "rotate" ] = setupGizmo( helperRotate ) );
  82732. this.add( this.helper[ "scale" ] = setupGizmo( helperScale ) );
  82733. // Pickers should be hidden always
  82734. this.picker[ "translate" ].visible = false;
  82735. this.picker[ "rotate" ].visible = false;
  82736. this.picker[ "scale" ].visible = false;
  82737. // updateMatrixWorld will update transformations and appearance of individual handles
  82738. this.updateMatrixWorld = function () {
  82739. if(!this.parent.visible)return //add
  82740. var space = this.space;
  82741. if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
  82742. var quaternion = space === "local" ? this.worldQuaternion : identityQuaternion;
  82743. // Show only gizmos for current transform mode
  82744. this.gizmo[ "translate" ].visible = this.mode === "translate";
  82745. this.gizmo[ "rotate" ].visible = this.mode === "rotate";
  82746. this.gizmo[ "scale" ].visible = this.mode === "scale";
  82747. this.helper[ "translate" ].visible = this.mode === "translate";
  82748. this.helper[ "rotate" ].visible = this.mode === "rotate";
  82749. this.helper[ "scale" ].visible = this.mode === "scale";
  82750. var handles = [];
  82751. handles = handles.concat( this.picker[ this.mode ].children );
  82752. handles = handles.concat( this.gizmo[ this.mode ].children );
  82753. handles = handles.concat( this.helper[ this.mode ].children );
  82754. for ( var i = 0; i < handles.length; i ++ ) {
  82755. var handle = handles[ i ];
  82756. //add
  82757. if(this.hideAxis[this.mode] && this.hideAxis[this.mode].some(e=>handle.name.includes(e.toUpperCase()))){
  82758. Potree.Utils.updateVisible(handle, 'hidden', false);
  82759. continue
  82760. }
  82761. let visible = true;
  82762. // hide aligned to camera
  82763. handle.rotation.set( 0, 0, 0 );
  82764. handle.position.copy( this.worldPosition );
  82765. if(this.camera.type == "OrthographicCamera"){
  82766. var eyeDistance = 800 / this.camera.zoom;
  82767. }else {
  82768. var eyeDistance = this.worldPosition.distanceTo( this.cameraPosition );
  82769. }
  82770. handle.scale.set( 1, 1, 1 ).multiplyScalar( eyeDistance * this.size / 7 );
  82771. // TODO: simplify helpers and consider decoupling from gizmo
  82772. if ( handle.tag === 'helper' ) {
  82773. visible = false;
  82774. if ( handle.name === 'AXIS' ) {
  82775. handle.position.copy( this.worldPositionStart );
  82776. visible = !!this.axis;
  82777. if ( this.axis === 'X' ) {
  82778. tempQuaternion.setFromEuler( tempEuler.set( 0, 0, 0 ) );
  82779. handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
  82780. if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
  82781. visible = false;
  82782. }
  82783. }
  82784. if ( this.axis === 'Y' ) {
  82785. tempQuaternion.setFromEuler( tempEuler.set( 0, 0, Math.PI / 2 ) );
  82786. handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
  82787. if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
  82788. visible = false;
  82789. }
  82790. }
  82791. if ( this.axis === 'Z' ) {
  82792. tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
  82793. handle.quaternion.copy( quaternion ).multiply( tempQuaternion );
  82794. if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > 0.9 ) {
  82795. visible = false;
  82796. }
  82797. }
  82798. if ( this.axis === 'XYZE' ) {
  82799. tempQuaternion.setFromEuler( tempEuler.set( 0, Math.PI / 2, 0 ) );
  82800. alignVector.copy( this.rotationAxis );
  82801. handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( zeroVector, alignVector, unitY ) );
  82802. handle.quaternion.multiply( tempQuaternion );
  82803. visible = this.dragging;
  82804. }
  82805. if ( this.axis === 'E' ) {
  82806. visible = false;
  82807. }
  82808. } else if ( handle.name === 'START' ) {
  82809. handle.position.copy( this.worldPositionStart );
  82810. visible = this.dragging;
  82811. } else if ( handle.name === 'END' ) {
  82812. handle.position.copy( this.worldPosition );
  82813. visible = this.dragging;
  82814. } else if ( handle.name === 'DELTA' ) {
  82815. handle.position.copy( this.worldPositionStart );
  82816. handle.quaternion.copy( this.worldQuaternionStart );
  82817. tempVector.set( 1e-10, 1e-10, 1e-10 ).add( this.worldPositionStart ).sub( this.worldPosition ).multiplyScalar( - 1 );
  82818. tempVector.applyQuaternion( this.worldQuaternionStart.clone().invert() );
  82819. handle.scale.copy( tempVector );
  82820. visible = this.dragging;
  82821. } else {
  82822. handle.quaternion.copy( quaternion );
  82823. if ( this.dragging ) {
  82824. handle.position.copy( this.worldPositionStart );
  82825. } else {
  82826. handle.position.copy( this.worldPosition );
  82827. }
  82828. if ( this.axis ) {
  82829. visible = this.axis.search( handle.name ) !== - 1;
  82830. }
  82831. }
  82832. // If updating helper, skip rest of the loop
  82833. Potree.Utils.updateVisible(handle, 'hidden', !!visible);
  82834. continue;
  82835. }
  82836. // Align handles to current local or world rotation
  82837. handle.quaternion.copy( quaternion );
  82838. if ( this.mode === 'translate' || this.mode === 'scale' ) {
  82839. // Hide translate and scale axis facing the camera
  82840. var AXIS_HIDE_TRESHOLD = 0.99;
  82841. var PLANE_HIDE_TRESHOLD = 0.2;
  82842. var AXIS_FLIP_TRESHOLD = 0.0;
  82843. if(options.dontHideWhenFaceCamera){//xzw add
  82844. //正对镜头时不隐藏箭头
  82845. }else {
  82846. if ( handle.name === 'X' || handle.name === 'XYZX' ) {
  82847. if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
  82848. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  82849. visible = false;
  82850. }
  82851. }
  82852. if ( handle.name === 'Y' || handle.name === 'XYZY' ) {
  82853. if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
  82854. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  82855. visible = false;
  82856. }
  82857. }
  82858. if ( handle.name === 'Z' || handle.name === 'XYZZ' ) {
  82859. if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) > AXIS_HIDE_TRESHOLD ) {
  82860. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  82861. visible = false;
  82862. }
  82863. }
  82864. if ( handle.name === 'XY' ) {
  82865. if ( Math.abs( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
  82866. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  82867. visible = false;
  82868. }
  82869. }
  82870. if ( handle.name === 'YZ' ) {
  82871. if ( Math.abs( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
  82872. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  82873. visible = false;
  82874. }
  82875. }
  82876. if ( handle.name === 'XZ' ) {
  82877. if ( Math.abs( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) ) < PLANE_HIDE_TRESHOLD ) {
  82878. handle.scale.set( 1e-10, 1e-10, 1e-10 );
  82879. visible = false;
  82880. }
  82881. }
  82882. }
  82883. // Flip translate and scale axis ocluded behind another axis
  82884. //xzw 改 去掉反向箭头
  82885. if ( handle.name.search( 'X' ) !== - 1 ) {
  82886. if ( alignVector.copy( unitX ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
  82887. /* if ( handle.tag === 'fwd' ) {
  82888. handle.visible = false;
  82889. } else {
  82890. handle.scale.x *= - 1;
  82891. }
  82892. } else if ( handle.tag === 'bwd' ) {
  82893. handle.visible = false;*/
  82894. handle.scale.x *= - 1;
  82895. }
  82896. }
  82897. if ( handle.name.search( 'Y' ) !== - 1 ) {
  82898. if ( alignVector.copy( unitY ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
  82899. /* if ( handle.tag === 'fwd' ) {
  82900. handle.visible = false;
  82901. } else {
  82902. handle.scale.y *= - 1;
  82903. }
  82904. } else if ( handle.tag === 'bwd' ) {
  82905. handle.visible = false;
  82906. */
  82907. handle.scale.y *= - 1;
  82908. }
  82909. }
  82910. if ( handle.name.search( 'Z' ) !== - 1 ) {
  82911. if ( alignVector.copy( unitZ ).applyQuaternion( quaternion ).dot( this.eye ) < AXIS_FLIP_TRESHOLD ) {
  82912. /* if ( handle.tag === 'fwd' ) {
  82913. handle.visible = false;
  82914. } else {
  82915. handle.scale.z *= - 1;
  82916. }
  82917. } else if ( handle.tag === 'bwd' ) {
  82918. handle.visible = false; */
  82919. handle.scale.z *= - 1;
  82920. }
  82921. }
  82922. } else if ( this.mode === 'rotate' ) {
  82923. // Align handles to current local or world rotation
  82924. tempQuaternion2.copy( quaternion );
  82925. alignVector.copy( this.eye ).applyQuaternion( tempQuaternion.copy( quaternion ).invert() );
  82926. if ( handle.name.search( "E" ) !== - 1 ) {
  82927. handle.quaternion.setFromRotationMatrix( lookAtMatrix.lookAt( this.eye, zeroVector, unitY ) );
  82928. }
  82929. if ( handle.name === 'X' ) {
  82930. tempQuaternion.setFromAxisAngle( unitX, Math.atan2( - alignVector.y, alignVector.z ) );
  82931. tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
  82932. handle.quaternion.copy( tempQuaternion );
  82933. }
  82934. if ( handle.name === 'Y' ) {
  82935. tempQuaternion.setFromAxisAngle( unitY, Math.atan2( alignVector.x, alignVector.z ) );
  82936. tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
  82937. handle.quaternion.copy( tempQuaternion );
  82938. }
  82939. if ( handle.name === 'Z' ) {
  82940. tempQuaternion.setFromAxisAngle( unitZ, Math.atan2( alignVector.y, alignVector.x ) );
  82941. tempQuaternion.multiplyQuaternions( tempQuaternion2, tempQuaternion );
  82942. handle.quaternion.copy( tempQuaternion );
  82943. }
  82944. }
  82945. // Hide disabled axes
  82946. visible = visible && ( handle.name.indexOf( "X" ) === - 1 || this.showX );
  82947. visible = visible && ( handle.name.indexOf( "Y" ) === - 1 || this.showY );
  82948. visible = visible && ( handle.name.indexOf( "Z" ) === - 1 || this.showZ );
  82949. visible = visible && ( handle.name.indexOf( "E" ) === - 1 || ( this.showX && this.showY && this.showZ ) );
  82950. Potree.Utils.updateVisible(handle, 'hidden', !!visible);
  82951. // highlight selected axis
  82952. handle.material._opacity = handle.material._opacity || handle.material.opacity;
  82953. handle.material._color = handle.material._color || handle.material.color.clone();
  82954. handle.material.color.copy( handle.material._color );
  82955. handle.material.opacity = handle.material._opacity;
  82956. if ( ! this.enabled ) {
  82957. handle.material.opacity *= 0.5;
  82958. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  82959. } else if ( this.axis ) {
  82960. if ( handle.name === this.axis ) {
  82961. handle.material.opacity = 1.0;
  82962. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  82963. } else if ( this.axis.split( '' ).some( function ( a ) {
  82964. return handle.name === a;
  82965. } ) ) {
  82966. handle.material.opacity = 1.0;
  82967. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  82968. } else {
  82969. handle.material.opacity *= 0.25;
  82970. handle.material.color.lerp( new Color( 1, 1, 1 ), 0.5 );
  82971. }
  82972. }
  82973. }
  82974. Object3D.prototype.updateMatrixWorld.call( this );
  82975. };
  82976. };
  82977. /* var TransformControlsLines = function (options) {
  82978. THREE.Object3D.call( this)
  82979. let label1 = new Label2D({ innerHTML:`<div>与相机水平距离</div>` , domElement:$("#otherLabels")[0] ,autoUpdate:true })
  82980. let label2 = new Label2D({ innerHTML:`<div>与相机高度差</div>` , domElement:$("#otherLabels")[0] ,autoUpdate:true })
  82981. let css = {'opacity': 0.7, 'color': '#07fceb', transform:'translate(-50%, -50%)'}
  82982. label1.elem.css(css);
  82983. label2.elem.css(css)
  82984. //for(let i=0;i<2;i++){
  82985. // let line = LineDraw.createLine([new THREE.THREE.Vector3, new THREE.THREE.Vector3],{color:'#07fceb', opacity:0.7 })
  82986. // this.add(line)
  82987. //}
  82988. this.updateTransform = function(object){
  82989. object = object || this.parent.object;
  82990. let A = player.position.clone(); //当前相机位置
  82991. let B = object.position //物体位置
  82992. let C = B.clone().setY(A.y); //物体在相机的高度的位置
  82993. let D = A.clone().setY(B.y); //相机在物体的高度的位置
  82994. //LineDraw.moveLine(this.children[0], [B, C]) // 垂直线
  82995. //LineDraw.moveLine(this.children[1], [D, B]) // 水平线
  82996. let dis1 = toPrecision(D.distanceTo(B),1)
  82997. let dis2 = C.y - B.y
  82998. label1.elem.text('与相机水平距离: '+dis1+'米')
  82999. label2.elem.text('在相机之'+ (dis2>0?'下' : '上') +' :'+ toPrecision(dis2 , 1) +'米')
  83000. label1.setPos(new THREE.THREE.Vector3().addVectors(D,B).multiplyScalar(0.5))
  83001. label2.setPos(new THREE.THREE.Vector3().addVectors(B,C).multiplyScalar(0.5))
  83002. }
  83003. this.setVisible = (v,reason)=>{
  83004. label1.setVisible(v, reason || 'unvisi')
  83005. label2.setVisible(v, reason || 'unvisi')
  83006. this.visible = label1.visible
  83007. if(this.visible){
  83008. this.updateTransform()
  83009. }
  83010. }
  83011. this.setVisible(false)
  83012. player.on("mode.changing",(currentMode, mode, pano, duration)=>{
  83013. if(mode != 'panorama'){
  83014. this.setVisible(false, 'isPanorama')
  83015. }else{
  83016. this.setVisible(true, 'isPanorama')
  83017. }
  83018. })
  83019. player.on("flying.started",( )=>{
  83020. this.setVisible(false, 'flying')
  83021. })
  83022. player.on("flying.ended",( )=>{
  83023. this.setVisible(true, 'flying')
  83024. })
  83025. }
  83026. */
  83027. var TransformControlsPlane = function (options) {
  83028. 'use strict';
  83029. Mesh.call( this,
  83030. new PlaneBufferGeometry( 100000, 100000, 2, 2 ),
  83031. new MeshBasicMaterial( { color: "#ff0000", visible: false, wireframe: false, side: DoubleSide, transparent: true, opacity: 0.2 } )
  83032. );
  83033. this.type = 'TransformControlsPlane';
  83034. var unitX = new Vector3( 1, 0, 0 );
  83035. var unitY = new Vector3( 0, 1, 0 );
  83036. var unitZ = new Vector3( 0, 0, 1 );
  83037. var tempVector = new Vector3();
  83038. var dirVector = new Vector3();
  83039. var alignVector = new Vector3();
  83040. var tempMatrix = new Matrix4();
  83041. var identityQuaternion = new Quaternion();
  83042. this.updateMatrixWorld = function () {
  83043. if(!this.visible)return//add
  83044. var space = this.space;
  83045. this.position.copy( this.worldPosition );
  83046. if ( this.mode === 'scale' ) space = 'local'; // scale always oriented to local rotation
  83047. unitX.set( 1, 0, 0 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
  83048. unitY.set( 0, 1, 0 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
  83049. unitZ.set( 0, 0, 1 ).applyQuaternion( space === "local" ? this.worldQuaternion : identityQuaternion );
  83050. // Align the plane for current transform mode, axis and space.
  83051. alignVector.copy( unitY );
  83052. switch ( this.mode ) {
  83053. case 'translate':
  83054. case 'scale':
  83055. switch ( this.axis ) {
  83056. case 'X':
  83057. alignVector.copy( this.eye ).cross( unitX );
  83058. dirVector.copy( unitX ).cross( alignVector );
  83059. break;
  83060. case 'Y':
  83061. alignVector.copy( this.eye ).cross( unitY );
  83062. dirVector.copy( unitY ).cross( alignVector );
  83063. break;
  83064. case 'Z':
  83065. alignVector.copy( this.eye ).cross( unitZ );
  83066. dirVector.copy( unitZ ).cross( alignVector );
  83067. break;
  83068. case 'XY':
  83069. dirVector.copy( unitZ );
  83070. break;
  83071. case 'YZ':
  83072. dirVector.copy( unitX );
  83073. break;
  83074. case 'XZ':
  83075. alignVector.copy( unitZ );
  83076. dirVector.copy( unitY );
  83077. break;
  83078. case 'XYZ':
  83079. case 'E':
  83080. default: //xzw add for scale xyzz
  83081. dirVector.set( 0, 0, 0 );
  83082. break;
  83083. }
  83084. break;
  83085. case 'rotate':
  83086. default:
  83087. // special case for rotate
  83088. dirVector.set( 0, 0, 0 );
  83089. }
  83090. if ( dirVector.length() === 0 ) {//使物体在视线中平移
  83091. // If in rotate mode, make the plane parallel to camera
  83092. this.quaternion.copy( this.cameraQuaternion );
  83093. } else {//方向滑动所在面
  83094. tempMatrix.lookAt( tempVector.set( 0, 0, 0 ), dirVector, alignVector );
  83095. this.quaternion.setFromRotationMatrix( tempMatrix );
  83096. }
  83097. Object3D.prototype.updateMatrixWorld.call( this );
  83098. };
  83099. };
  83100. TransformControls.prototype = Object.assign( Object.create( Object3D.prototype ), {
  83101. constructor: TransformControls,
  83102. isTransformControls: true
  83103. } );
  83104. TransformControlsGizmo.prototype = Object.assign( Object.create( Object3D.prototype ), {
  83105. constructor: TransformControlsGizmo,
  83106. isTransformControlsGizmo: true
  83107. } );
  83108. TransformControlsPlane.prototype = Object.assign( Object.create( Mesh.prototype ), {
  83109. constructor: TransformControlsPlane,
  83110. isTransformControlsPlane: true
  83111. } );
  83112. /*
  83113. 备注:
  83114. //这里虽然 使坐标轴在boundingBox中心
  83115. boundingBox && this.object.boundingBox.getCenter(worldPosition).applyMatrix4(this.object.matrixWorld);
  83116. 但是旋转中心并不是这个坐标轴显示的位置,需要再执行 MergeEditor.maintainBoundXY()才能维持在这个中心
  83117. */
  83118. const texLoader$a = new TextureLoader();
  83119. texLoader$a.crossOrigin = "anonymous";
  83120. const edgeStrengths = {
  83121. pointcloud: 4,
  83122. glb: 100
  83123. };
  83124. const viewportProps$1 = [{
  83125. left:0,
  83126. bottom:0,
  83127. width: 0.5,height:1,
  83128. name : 'top',
  83129. axis:["x","y"],
  83130. direction : new Vector3(0,0,-1), //镜头朝向
  83131. active: true,
  83132. //相机位置在z轴正向
  83133. limitBound: new Box3(new Vector3(-Infinity,-Infinity, 1),new Vector3(Infinity,Infinity,5000)), //在地面以上
  83134. margin:{x:50, y:150} ,
  83135. },
  83136. {
  83137. left:0.5,
  83138. bottom:0,
  83139. width: 0.5,height:1,
  83140. name : 'right',
  83141. axis:["y","z"],
  83142. direction : new Vector3(1,0,0),
  83143. active: true,
  83144. //相机位置在x轴负向 右下角屏
  83145. viewContainsPoints:[new Vector3(0,0,0)],
  83146. margin:{x:300, y:250} ,
  83147. } ];
  83148. let cylinderSkyGeo, oldSkyGeo;
  83149. let MergeEditor = {
  83150. bus:new EventDispatcher(),
  83151. SplitScreen : new SplitScreen(),
  83152. init(){
  83153. this.history = new History({
  83154. applyData: (data)=>{
  83155. if(data.object.parent /* && data.object == this.selected */){
  83156. data = Potree.Common.CloneObject(data); //避免使用后更改数据又被使用
  83157. data.matrix.decompose( data.object.position, data.object.quaternion, data.object.scale );
  83158. data.object.boundCenter.copy(data.boundCenter);
  83159. data.object.dispatchEvent('changeByHistory');
  83160. data.object.dispatchEvent('transformChanged');
  83161. viewer.dispatchEvent('content_changed');
  83162. return true
  83163. }
  83164. },
  83165. getData:(object)=>{
  83166. return {
  83167. object,
  83168. matrix: object.matrixWorld.clone(),
  83169. boundCenter: object.boundCenter.clone()
  83170. }
  83171. }
  83172. });
  83173. {
  83174. Potree.settings.notAdditiveBlending = true;
  83175. let ground = this.ground = new InfiniteGridHelper(1, 10000, new Color('#eee'), 10000, 0.2, 0.3);
  83176. viewer.scene.scene.add(ground);
  83177. //再加两条线否则在正侧边看不到
  83178. let line1 = LineDraw.createLine([new Vector3(-10000, 0, 0),new Vector3(10000, 0, 0) ], {color:'#aaa', });
  83179. let line2 = LineDraw.createLine([new Vector3(0, -10000, 0),new Vector3(0, 10000, 0) ], {mat:line1.material});
  83180. ground.renderOrder = Potree.config.renderOrders.model + 1;//line1.renderOrder + 1 //要比模型低,否则模型透明时效果不对
  83181. ground.add(line1);
  83182. ground.add(line2);
  83183. ground.material.opacity = 0.9; //为了滞后渲染,否则被rt遮住
  83184. ground.material.polygonOffset = true; //多边形偏移(视觉上没有移动模型位置),防止闪烁
  83185. ground.material.polygonOffsetFactor = 100; //多边形偏移因子
  83186. ground.material.polygonOffsetUnits = 10; //多边形偏移单位
  83187. ground.material.depthWrite = false;
  83188. //ground.material.depthTest = false
  83189. line1.material.polygonOffset = true;
  83190. line1.material.polygonOffsetFactor = 130;
  83191. line1.material.polygonOffsetUnits = 10;
  83192. line1.material.depthWrite = false;
  83193. //见笔记:透明物体的材质设置
  83194. }
  83195. let oriEdgeStrength = viewer.outlinePass.edgeStrength;
  83196. {
  83197. this.transformControls = new TransformControls(viewer.mainViewport.camera, viewer.renderArea,{
  83198. dontHideWhenFaceCamera: true,
  83199. });
  83200. //this.transformControls.space = 'local'//为了在当前方向上平移
  83201. this.transformControls.setSize(1.5);
  83202. viewer.scene.scene.add(this.transformControls);
  83203. this.transformControls._gizmo.hideAxis = {rotate:['e']};
  83204. this.transformControls.setRotateMethod(2);
  83205. //右屏
  83206. this.transformControls2 = new TransformControls(viewer.mainViewport.camera, viewer.renderArea,{
  83207. dontHideWhenFaceCamera: true,
  83208. });
  83209. this.transformControls2.setSize(1.5);
  83210. viewer.scene.scene.add(this.transformControls2);
  83211. Potree.Utils.setObjectLayers(this.transformControls2, 'layer2' );
  83212. let mouseDown = (e)=>{
  83213. viewer.outlinePass.edgeStrength = 0;//暂时消失线
  83214. };
  83215. let mouseUp = (e)=>{
  83216. //this.updateEdgeStrength()
  83217. viewer.outlinePass.edgeStrength = oriEdgeStrength;
  83218. };
  83219. this.transformControls.addEventListener('mouseDown',mouseDown);
  83220. this.transformControls2.addEventListener('mouseDown',mouseDown);
  83221. this.transformControls.addEventListener('mouseUp',mouseUp);
  83222. this.transformControls2.addEventListener('mouseUp',mouseUp);
  83223. this.transformControls.addEventListener('mouseDown', ()=>{ //dragstart
  83224. this.history.beforeChange(this.selected);
  83225. });
  83226. this.transformControls.addEventListener('mouseUp',()=>{
  83227. this.history.afterChange(this.selected);
  83228. });
  83229. }
  83230. {
  83231. this.secondCompass = new Compass(null);
  83232. }
  83233. viewer.setControls(viewer.orbitControls);
  83234. //viewer.mainViewport.view.fixZWhenPan = true
  83235. viewer.orbitControls.constantlyForward = true;
  83236. viewer.addEventListener('global_single_click',(e)=>{
  83237. if(
  83238. this.noNeedSelection //如模型查看页
  83239. || viewer.scene.cameraAnimations.some(c=>c.onUpdate) //正在播放
  83240. || e.drag && e.drag.notPressMouse //在加测量线
  83241. || viewer.mainViewport.view.isFlying() //有其他校准
  83242. || this.split //分屏中
  83243. || e.clickElement //触发别的点击事件,如测量时click marker /* && e.clickElement != e.intersect.object */
  83244. ){
  83245. return
  83246. }
  83247. if(e.intersect){
  83248. let object = e.intersect.object || e.intersect.pointcloud;
  83249. let objects = this.getAllObjects();
  83250. if(objects.includes(object) && this.selected != object){
  83251. this.selectModel(object);
  83252. }else {
  83253. //if(!viewer.inputHandler.selection[0]){//正在平移和旋转,不允许取消
  83254. this.selectModel(null);
  83255. //}
  83256. }
  83257. }else {
  83258. //if(!viewer.inputHandler.selection[0]){
  83259. this.selectModel(null);
  83260. //}
  83261. }
  83262. });
  83263. viewer.inputHandler.addEventListener('keydown', (e)=>{
  83264. if((e.event.key).toLowerCase() == "h" ){
  83265. this.fadeOutlineAuto = !this.fadeOutlineAuto;
  83266. this.showModelOutline(this.selected,!!this.selected);
  83267. }
  83268. });
  83269. //viewer.fxaaPass.enabled = false//viewer.ssaaRenderPass.enabled = false
  83270. viewer.outlinePass.enabled = true;
  83271. //Potree.settings.intersectWhenHover = false
  83272. //Potree.Utils.updateVisible(viewer.reticule, 'force', false)
  83273. viewer.composer.scaleRatio = 1;
  83274. viewer.composer.readTarget = false;
  83275. viewer.mainViewport.camera.near = 0.05; // too small will result in z-fighting
  83276. viewer.addEventListener('updateModelBound', (e)=>{
  83277. if(this.split){
  83278. this.SplitScreen.updateCameraOutOfModel(/* this.selected && [this.selected] */);
  83279. }
  83280. });
  83281. {//校准页面拖拽
  83282. //左右屏都可以拖拽模型,旋转只能左屏
  83283. let dragInfo;
  83284. let drag = (e)=>{
  83285. if(this.split && this.selected && this.transformState && (e.dragViewport.name == 'top' || this.transformState == 'translate') ){
  83286. if(e.type == 'global_mousedown' ){ //开始
  83287. //if((e.intersect.object || e.intersect.pointcloud) == this.selected){
  83288. if(e.intersect.pointclouds.includes(this.selected) || e.intersect.allElements.some(e=>e.object == this.selected)){
  83289. dragInfo = {};
  83290. //if(this.selected.isPointcloud){
  83291. viewer.outlinePass.edgeStrength = 0;//暂时消失线
  83292. //}
  83293. }
  83294. }
  83295. if(e.type == 'global_drag' && dragInfo ){
  83296. if(this.transformState == 'translate'){
  83297. let moveVec = Potree.Utils.getOrthoCameraMoveVec(e.drag.pointerDelta, e.dragViewport.camera );//最近一次移动向量
  83298. this.selected.position.add(moveVec);
  83299. this.selected.dispatchEvent("position_changed");
  83300. }else if(this.transformState == 'rotate'){
  83301. let vec = new Vector3().subVectors(e.intersect.orthoIntersect || e.intersect.location, this.selected.boundCenter).setZ(0);
  83302. if(dragInfo.lastVec == void 0){//global_mousedown
  83303. dragInfo.lastVec = vec;
  83304. return
  83305. }
  83306. let angle = math.getAngle(dragInfo.lastVec, vec, 'z');
  83307. dragInfo.lastVec = vec;
  83308. //this.selected.rotation.z += angle //局部
  83309. /* object.quaternion.copy( .setFromAxisAngle( new THREE.Vector3(0,0,1), angle ) );
  83310. object.quaternion.multiply( quaternionStart ).normalize(); */
  83311. let diffQua = new Quaternion().setFromAxisAngle( new Vector3(0,0,1), angle );
  83312. this.selected.quaternion.premultiply(diffQua); //世界
  83313. this.selected.dispatchEvent("rotation_changed");
  83314. }
  83315. return {stopContinue:true}
  83316. }
  83317. }
  83318. };
  83319. viewer.addEventListener('global_mousedown', drag);
  83320. viewer.addEventListener('global_drag', drag, {importance:10});
  83321. viewer.addEventListener('global_mousemove', (e)=>{
  83322. if(this.split && this.transformState && !e.drag && (e.hoverViewport.name == 'top' || this.transformState == 'translate')){
  83323. /* if(this.lastHoverViewport != e.hoverViewport){
  83324. this.lastHoverViewport = e.hoverViewport
  83325. this.transformControls.view = e.hoverViewport.view
  83326. this.transformControls.camera = e.hoverViewport.camera
  83327. this.transformControls.hideAxis( this.transformState, e.hoverViewport.name == 'top' ? [z] : [x,y]);
  83328. } */
  83329. let mouseover = e.intersect.pointclouds.includes(this.selected) || e.intersect.allElements.some(e=>e.object == this.selected);
  83330. //let mouseover = (e.intersect.object || e.intersect.pointcloud) == this.selected
  83331. if(mouseover){
  83332. if(this.transformState == 'translate'){
  83333. viewer.dispatchEvent({
  83334. type : "CursorChange", action : "add", name:"movePointcloud"
  83335. });
  83336. }else {
  83337. viewer.dispatchEvent({
  83338. type : "CursorChange", action : "add", name:"rotatePointcloud"
  83339. });
  83340. }
  83341. }else {
  83342. this.clearTranCursor();
  83343. }
  83344. }
  83345. });
  83346. viewer.addEventListener('global_drop', (e)=>{
  83347. dragInfo = null;
  83348. this.clearTranCursor();
  83349. //this.updateEdgeStrength()
  83350. viewer.outlinePass.edgeStrength = oriEdgeStrength;
  83351. });
  83352. }
  83353. /* viewer.addEventListener('background_changed',()=>{
  83354. }) */
  83355. viewer.addEventListener('camera_changed',()=>{
  83356. Common.intervalTool.isWaiting('updateMemoryUsage', ()=>{
  83357. this.updateMemoryUsage();
  83358. }, 1000);
  83359. });
  83360. viewer.addEventListener('setDisplay',this.updateMemoryUsage.bind(this));
  83361. },
  83362. clearTranCursor(){
  83363. viewer.dispatchEvent({
  83364. type : "CursorChange", action : "remove", name:"movePointcloud"
  83365. });
  83366. viewer.dispatchEvent({
  83367. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  83368. });
  83369. },
  83370. enterSplit(){
  83371. this.split = true;
  83372. if(this.selected) this.SplitScreen.focusCenter = this.selected.boundCenter; //旋转中心。注意 boundCenter不能直接赋值,否则改变后focusCenter也要改
  83373. else this.SplitScreen.focusCenter = null;
  83374. this.SplitScreen.splitStart(viewportProps$1);
  83375. this.beforeSplit = {
  83376. pointDensity: Potree.settings.pointDensity,
  83377. };
  83378. Potree.settings.pointDensity = 'fourViewports'; //强制降低点云质量
  83379. viewer.setControls(viewer.fpControls);
  83380. let rightViewport = viewer.viewports.find(e=>e.name == 'right');
  83381. let topViewport = viewer.viewports.find(e=>e.name == 'top');
  83382. topViewport.alignment = true;
  83383. rightViewport.rotateSide = true;
  83384. rightViewport.skyboxFixPos = true;
  83385. rightViewport.skyboxMinZoom = 10;
  83386. rightViewport.skyboxRenderFun = ()=>{// 使cube的一面永远正向镜头。 因侧视图的camera是ortho类型,需要平视mesh才不会拉伸
  83387. viewer.skybox.scene.children[0].rotation.copy(rightViewport.camera.rotation);
  83388. };
  83389. topViewport.skyboxRenderFun = ()=>{
  83390. viewer.skybox.scene.children[0].rotation.set(0,0,0);
  83391. };
  83392. viewer.viewports[1].layersAdd('layer2');
  83393. viewer.viewports[0].layersAdd('layer1');
  83394. Potree.Utils.setObjectLayers(this.transformControls, 'layer1' );
  83395. this.transformControls.view = viewer.viewports[0].view;
  83396. this.transformControls.camera = viewer.viewports[0].camera;
  83397. this.transformControls._gizmo.hideAxis = {translate:['z'], rotate:['x','y','z'] };
  83398. this.transformControls2.view = viewer.viewports[1].view;
  83399. this.transformControls2.camera = viewer.viewports[1].camera;
  83400. this.transformControls2._gizmo.hideAxis = {translate:['x','y'], rotate:['x','y','z'] };
  83401. this.secondCompass.changeViewport(viewer.viewports[0]);
  83402. this.secondCompass.setDomPos();
  83403. this.secondCompass.setDisplay(true);
  83404. viewer.compass.changeViewport(viewer.viewports[1]);
  83405. viewer.compass.setDomPos();
  83406. //this.changeSkyboxGeo(true)
  83407. },
  83408. leaveSplit(){
  83409. this.split = false;
  83410. this.SplitScreen.unSplit();
  83411. viewer.setControls(viewer.orbitControls);
  83412. Potree.settings.pointDensity = this.beforeSplit.pointDensity;
  83413. /* if(this.selected && this.selected.isPointcloud){
  83414. this.showModelOutline(this.selected, true)
  83415. this.selected.material.activeAttributeName = "rgba"
  83416. } */
  83417. this.transformControls.camera = viewer.viewports[0].camera;
  83418. this.transformControls.view = viewer.viewports[0].view;
  83419. this.transformControls._gizmo.hideAxis = {rotate:['e']};
  83420. Potree.Utils.setObjectLayers(this.transformControls, 'sceneObjects' ); //恢复
  83421. viewer.compass.changeViewport(viewer.viewports[0]); //恢复
  83422. viewer.compass.setDomPos();
  83423. this.secondCompass.setDisplay(false);
  83424. },
  83425. rotateSideCamera(angle){
  83426. this.SplitScreen.rotateSideCamera(viewer.viewports.find(e=>e.name == 'right'), angle);
  83427. },
  83428. setTransformState(state){//校准时
  83429. this.transformState = state;
  83430. this.clearTranCursor();
  83431. },
  83432. //---------------------------
  83433. getAllObjects(){
  83434. return viewer.objs.children.concat(viewer.scene.pointclouds)
  83435. },
  83436. getModel(id){
  83437. let models = this.getAllObjects();
  83438. return models.find(e=>e.dataset_id == id)
  83439. },
  83440. removeModel(model){
  83441. if(this.selected == model) this.selectModel(null);
  83442. let dispose = (e)=>{
  83443. e.geometry && e.geometry.dispose();
  83444. e.material && e.material.dispose();
  83445. };
  83446. if(model.isPointcloud){
  83447. dispose(model);
  83448. viewer.scene.removePointCloud(model);
  83449. }else {
  83450. model.traverse(e=>{
  83451. dispose(e);
  83452. });
  83453. viewer.objs.remove(model);
  83454. this.updateMemoryUsage();
  83455. }
  83456. },
  83457. selectModel(model, state=true, fitBound, by2d){
  83458. if(!model) {
  83459. model = this.selected;
  83460. state = false;
  83461. }
  83462. if(state){
  83463. if(this.selected){
  83464. if(this.selected == model) return
  83465. else {
  83466. let transToolAttached = !!this.transformControls.object;
  83467. this.selectModel(this.selected, false, fitBound, by2d);
  83468. transToolAttached && this.transformControls.attach(model);
  83469. }
  83470. }
  83471. this.selected = model;
  83472. MergeEditor.focusOn(model, 500, !!fitBound); //通过在场景里点击模型的话,不focus
  83473. this.showModelOutline(model);
  83474. //this.updateEdgeStrength()
  83475. //console.log('selectModel', model)
  83476. }else {
  83477. if(this.selected != model)return //model本来就没选中,不需要处理(防止2d先选中新的再取消旧的)
  83478. this.showModelOutline(model, false);
  83479. this.selected = null;
  83480. this.transformControls.detach(); //viewer.transformObject(null);
  83481. //console.log('selectModel', null)
  83482. }
  83483. if(!by2d && model){
  83484. model.dispatchEvent({type:'changeSelect', selected : state});
  83485. }
  83486. },
  83487. showModelOutline(model, state){
  83488. if(this.fadeOutlineAuto){
  83489. if(state === false){
  83490. viewer.outlinePass.selectedObjects = [];
  83491. clearTimeout(this.timer);
  83492. return
  83493. }
  83494. viewer.outlinePass.selectedObjects = [model];
  83495. if(this.timer){
  83496. clearTimeout(this.timer);
  83497. }
  83498. this.timer = setTimeout(()=>{
  83499. viewer.outlinePass.selectedObjects = [];
  83500. viewer.dispatchEvent('content_changed');
  83501. }, 1000);
  83502. }else {
  83503. if(state === false){
  83504. viewer.outlinePass.selectedObjects = [];
  83505. }else {
  83506. viewer.outlinePass.selectedObjects = [model];
  83507. }
  83508. }
  83509. viewer.dispatchEvent('content_changed');
  83510. },
  83511. /*updateEdgeStrength(){
  83512. if(!this.selected)return
  83513. if(this.selected.isPointcloud){
  83514. viewer.outlinePass.edgeStrength = edgeStrengths.pointcloud// / this.selected.material.opacity
  83515. }else{
  83516. viewer.outlinePass.edgeStrength = edgeStrengths.glb
  83517. }
  83518. },*/
  83519. focusOn(objects, duration = 400, fitBound=true, dontLookUp){
  83520. if(!(objects instanceof Array)){
  83521. objects = [objects];
  83522. }
  83523. let boundingBox = new Box3;
  83524. objects.forEach(object=>{
  83525. boundingBox.union(object.boundingBox.clone().applyMatrix4(object.matrixWorld));
  83526. });
  83527. let len = boundingBox.getSize(new Vector3).length();
  83528. Potree.settings.cameraFar = Math.max( Potree.settings.cameraFar, len*3 );
  83529. if(fitBound){
  83530. viewer.focusOnObject({boundingBox}, 'boundingBox', duration, {dontLookUp, dontChangeCamDir:true});
  83531. }else {
  83532. /*
  83533. let position = viewer.inputHandler.intersect ? viewer.inputHandler.intersect.location : boundingBox.getCenter(new THREE.Vector3)
  83534. position && viewer.focusOnObject({position}, 'point', duration, {dontChangePos: true})
  83535. */
  83536. let position = viewer.inputHandler.intersect ? viewer.inputHandler.intersect.location : boundingBox.getCenter(new Vector3);
  83537. if(!position)return
  83538. /* let targetOld = viewer.mainViewport.view.getPivot()
  83539. let projected1 = targetOld.clone().project(viewer.mainViewport.camera);
  83540. let projected2 = position.clone().project(viewer.mainViewport.camera); //使用其z
  83541. let targetNew = projected1.clone().setZ(projected2.z).unproject(viewer.mainViewport.camera);
  83542. viewer.mainViewport.view.lookAt(targetNew) */
  83543. viewer.mainViewport.view.radius = viewer.mainViewport.camera.position.distanceTo(position);
  83544. //为了不改画面,不调节方向了,只能调调radius,一定程度将target靠近model
  83545. }
  83546. },
  83547. moveBoundCenterTo(model,pos){ //使boundCenter在所要的位置
  83548. let diff = new Vector3().subVectors(pos, model.boundCenter);
  83549. model.position.add(diff);
  83550. },
  83551. getBoundCenter(model){
  83552. if(!model.boundCenter) model.boundCenter = new Vector3;
  83553. model.boundingBox.getCenter(model.boundCenter).applyMatrix4(model.matrixWorld);
  83554. },
  83555. setModelBtmHeight(model, z ){
  83556. //无论模型怎么缩放、旋转,都使最低点为z
  83557. if(z == void 0) z = model.btmHeight; //维持离地高度
  83558. else model.btmHeight = z;
  83559. if(model.btmHeight == void 0)return
  83560. model.updateMatrixWorld();
  83561. let boundingBox2 = model.boundingBox.clone().applyMatrix4(model.matrixWorld);
  83562. let size = boundingBox2.getSize(new Vector3);
  83563. let center = boundingBox2.getCenter(new Vector3);
  83564. let hopeZ = z + size.z / 2;
  83565. //model.position.z = z + size.z / 2 - center.z
  83566. model.position.z += (hopeZ - center.z);
  83567. },
  83568. computeBtmHeight(model){ //位移之后重新计算btmHeight
  83569. model.updateMatrixWorld();
  83570. let boundingBox2 = model.boundingBox.clone().applyMatrix4(model.matrixWorld);
  83571. let size = boundingBox2.getSize(new Vector3);
  83572. let center = boundingBox2.getCenter(new Vector3);
  83573. model.btmHeight = center.z - size.z / 2;
  83574. },
  83575. maintainBoundXY(model){ //在旋转和缩放后,立即执行这个函数,使boundCenter保持原位
  83576. model.updateMatrixWorld();
  83577. let center1 = model.boundCenter.clone();//还未更新的
  83578. this.getBoundCenter(model);//更新
  83579. let center2 = model.boundCenter.clone();
  83580. let diff = new Vector2().subVectors(center1,center2);
  83581. model.position.x += diff.x;
  83582. model.position.y += diff.y;
  83583. model.boundCenter.copy(center1);
  83584. },
  83585. maintainBoundCenter(model){
  83586. model.updateMatrixWorld();
  83587. let center1 = model.boundCenter.clone();//还未更新的
  83588. this.getBoundCenter(model);//更新
  83589. let center2 = model.boundCenter.clone();
  83590. let diff = new Vector3().subVectors(center1,center2);
  83591. model.position.add(diff);
  83592. model.boundCenter.copy(center1);
  83593. },
  83594. modelTransformCallback(model){
  83595. model.updateMatrixWorld();
  83596. if(model.matrixWorld.equals(model.lastMatrixWorld))return
  83597. viewer.scene.measurements.forEach(measure=>{
  83598. let changed;
  83599. measure.points_datasets.forEach((dataset_id,i)=>{
  83600. if(dataset_id == model.dataset_id){
  83601. changed = true;
  83602. measure.points[i] = Potree.Utils.datasetPosTransform({fromDataset:true,datasetId:dataset_id, position:measure.dataset_points[i].clone()});
  83603. measure.updateMarker(measure.markers[i], measure.points[i]);
  83604. }
  83605. });
  83606. if(changed){//仿transformByPointcloud
  83607. measure.getPoint2dInfo(measure.points);
  83608. measure.update();
  83609. measure.setSelected(false);//隐藏edgelabel
  83610. }
  83611. });
  83612. model.lastMatrixWorld = model.matrixWorld.clone();
  83613. viewer.dispatchEvent('content_changed');
  83614. viewer.mapViewer && Potree.settings.showObjectsOnMap && viewer.mapViewer.dispatchEvent('content_changed');
  83615. },
  83616. changeOpacity(model, opacity){
  83617. let isRoot = model.dataset_id != void 0; //是否是最外层
  83618. if(model.isPointcloud){
  83619. model.changePointOpacity(opacity);
  83620. //MergeEditor.updateEdgeStrength()
  83621. }else {
  83622. //model.traverse(e=>e.material && setOp(e, opacity))
  83623. model.traverse(mesh=>{
  83624. if(mesh.material){
  83625. if(mesh.material.originOpacity == void 0 ){
  83626. mesh.material.originOpacity = mesh.material.opacity;
  83627. }
  83628. mesh.material.opacity = mesh.material.originOpacity * opacity;
  83629. if(mesh.material.opacity<1){
  83630. mesh.material.transparent = true;
  83631. /* if(model.isPointcloud){
  83632. mesh.changePointOpacity(realOpacity)
  83633. }else{
  83634. mesh.material.opacity = realOpacity
  83635. } */
  83636. mesh.renderOrder = Potree.config.renderOrders.model+1;
  83637. //mesh.material.depthWrite = false
  83638. }else {
  83639. mesh.material.transparent = false;
  83640. mesh.renderOrder = Potree.config.renderOrders.model;
  83641. //mesh.material.depthWrite = true
  83642. }
  83643. mesh.material.depthWrite = mesh.material.opacity>0.3;
  83644. }
  83645. });
  83646. }
  83647. isRoot && (model.opacity = opacity);//记录在最外层
  83648. viewer.dispatchEvent('content_changed');
  83649. },
  83650. modelAdded(model){
  83651. model.addEventListener('isVisible',(e)=>{
  83652. if(e.reason == "overlinePass")return
  83653. //console.log(e)
  83654. viewer.addEventListener('update',()=>{ //下一次更新结束后
  83655. this.updateMemoryUsage();
  83656. },{once:true});
  83657. });
  83658. this.updateMemoryUsage();
  83659. },
  83660. updateMemoryUsage(){
  83661. //obj暂时不管其贴图大小, 因为顶点造成的不仅是内存还有卡顿所以先只看顶点
  83662. const maxMemory = Potree.config.tiles3DMaxMemory + 100; //M 实际估计是这个的10倍
  83663. const eachObjPosWeight = 100/1000/1000; //M 每个顶点pos是3*4个字节?法线3*4和uv2*4 其实还有贴图
  83664. const eachCloudPointWeight = 12/1000/1000; //M 每个点 pos + 颜色 + 法线 大概
  83665. const eachVisiCPointWeight = eachCloudPointWeight * 5; // 或 maxMemory / (6*1000*1000) 大概值接近 (再除以一个数是因为显示的要比内存中的耗更多资源
  83666. const eachGltfPosWeight = 100/1000/1000; //M 每个顶点pos是3*4个字节?法线3*4和uv2*4 其实还有贴图
  83667. let posCount=0;
  83668. viewer.objs.children.forEach(e=>{
  83669. if(e.fileType == 'glb' || e.fileType == 'obj'){
  83670. e.traverse((mesh)=>{
  83671. if(mesh.geometry){
  83672. posCount += mesh.geometry.attributes.position.count;
  83673. }
  83674. });
  83675. }else if(e.fileType == '3dTiles'){
  83676. }
  83677. });
  83678. //获取点云的内存限制
  83679. let objWeight = posCount*eachObjPosWeight;
  83680. let laserWeight = Potree.numVisiblePoints * eachCloudPointWeight; //点云实际显示所占大小
  83681. let laserMemoryWeight = Potree.lru.numPoints * eachCloudPointWeight; //点云所使用内存大小
  83682. let tiles3DWeight = viewer.tiles3dVisiVCount * eachGltfPosWeight; //M 3dTiles所占内存大小
  83683. let tiles3DMemoryWeight = viewer.tiles3dMemoryUsage / 1000 / 1000; //M 3dTiles显示的所占内存大小
  83684. /* let min = 0.1, max = 6, minP = 100, maxP = 1000000;
  83685. let ratio = Math.round(math.linearClamp(score, minP, maxP, max, min )); */
  83686. let rest = maxMemory - objWeight - tiles3DWeight;
  83687. Potree.pointBudget = Math.max(30000, Math.round(rest/eachVisiCPointWeight));
  83688. //获取3dTiles的内存限制
  83689. let tiles3DMaxMemory = maxMemory - Math.round(objWeight + laserWeight);
  83690. Potree.settings.tiles3DMaxMemory = MathUtils.clamp(tiles3DMaxMemory , 30, Potree.config.tiles3DMaxMemory );
  83691. //还存在的问题:仍然有隐患,因为没用到真实缓存的大小: tiles3DMemoryWeight laserMemoryWeight, 它们比真实可见的要多。不使用是因为它们无法反应出实际需要的内存量,缓存是只增不减
  83692. //obj等普通mesh限制不了
  83693. //console.log('objWeight',objWeight.toFixed(1), 'laserMemoryWeight',laserMemoryWeight.toFixed(1), 'tiles3DWeight',tiles3DWeight.toFixed(1), 'pointBudget',Potree.pointBudget, 'tiles3DMaxMemory',tiles3DMaxMemory)
  83694. //总内存 = 内存占用空间+图片缓存 , obj的缓存比较多在图片中
  83695. },
  83696. setGroundPlaneImg(src,scale,angle){//设置地面图
  83697. this.goundScale = scale || 1, this.goundAngle = angle || 0;
  83698. let oldSrc = this.curGroundImgSrc;
  83699. this.curGroundImgSrc = src;
  83700. const ratio = 0.03;
  83701. if(src){
  83702. if(oldSrc == src && this.groundPlane.material.map.image){ //仅修改大小
  83703. const s = ratio * this.goundScale;
  83704. let {width, height} = this.groundPlane.material.map.image;
  83705. this.groundPlane.scale.set(width*s, height*s);
  83706. viewer.dispatchEvent('content_changed');
  83707. this.groundPlane.rotation.z = MathUtils.degToRad(this.goundAngle);
  83708. return
  83709. }
  83710. let map = texLoader$a.load(src,(tex)=>{
  83711. if(this.curGroundImgSrc == src){
  83712. const s = ratio * this.goundScale;
  83713. this.groundPlane.scale.set(tex.image.width*s, tex.image.height*s);
  83714. this.groundPlane.rotation.z = MathUtils.degToRad(this.goundAngle);
  83715. viewer.dispatchEvent('content_changed');
  83716. }
  83717. });
  83718. Potree.Utils.makeTexDontResize(map);
  83719. if(!this.groundPlane){
  83720. this.groundPlane = new Mesh(new PlaneBufferGeometry(1,1,1), new MeshBasicMaterial({
  83721. map,
  83722. side : 2,
  83723. }));
  83724. viewer.scene.scene.add(this.groundPlane);
  83725. this.groundPlane.position.z = 0.1;
  83726. }else {
  83727. this.groundPlane.material.map = map;
  83728. }
  83729. Potree.Utils.updateVisible(this.groundPlane,'show',true );
  83730. }else {
  83731. this.groundPlane && Potree.Utils.updateVisible(this.groundPlane,'show',false );
  83732. }
  83733. }
  83734. };
  83735. /*
  83736. note:
  83737. 要注意getHoveredElements只在getIntersect时才使interactables包含加载的model, 也就是model上不能有使之成为interactables的事件,否则在鼠标hover到模型上开始转动的一瞬间很卡。
  83738. */
  83739. const texLoader$b = new TextureLoader();
  83740. const arrowSpacing = 1; //间隔
  83741. const arrowSize = arrowSpacing * 0.5;
  83742. const planeGeo$3 = new PlaneBufferGeometry(1,1);
  83743. const sphereSizeInfo = {
  83744. nearBound : 0.1, farBound:25, minSize : 50, maxSize : 200 //scale:arrowSize, restricMeshScale : true,
  83745. };
  83746. //const arrowsShowingCount = 25; //场景里最多展示多少个箭头
  83747. const arrowShowMinDis = 10;
  83748. class RouteGuider extends EventDispatcher{
  83749. constructor () {
  83750. super();
  83751. this.route = [];
  83752. this.curve = [];
  83753. this.scenePoints = [];
  83754. this.sceneMeshGroup = new Object3D;
  83755. this.mapMeshGroup = new Object3D;
  83756. this.generateDeferred;
  83757. viewer.addEventListener('loadPointCloudDone',this.init.bind(this));
  83758. this.lastResult;//保存上一个的结果,以便于反向
  83759. this.datasetIds = [];//起始和终点的datasetId
  83760. }
  83761. init(){
  83762. if(this.inited) return;
  83763. let zoom, resolution=new Vector2;
  83764. viewer.mapViewer.addEventListener('camera_changed', e => {
  83765. if(!this.routeStart || !this.routeEnd) return
  83766. var camera = e.viewport.camera;
  83767. if(camera.zoom != zoom || !resolution.equals(e.viewport.resolution)){
  83768. Common.intervalTool.isWaiting('routeCameraInterval', ()=>{ //延时update,防止卡顿
  83769. if(camera.zoom != zoom || !resolution.equals(e.viewport.resolution)){
  83770. //console.log('updateMapArrows')
  83771. this.updateMapArrows(true);
  83772. zoom = camera.zoom; resolution.copy(e.viewport.resolution);
  83773. }
  83774. }, browser.isMobile()?500:200);
  83775. }
  83776. });
  83777. viewer.addEventListener('camera_changed', e => {
  83778. if(!this.routeStart || !this.routeEnd || !e.changeInfo.positionChanged ) return
  83779. Common.intervalTool.isWaiting('routeCameraInterval2', ()=>{ //延时update,防止卡顿
  83780. this.updateArrowDisplay();
  83781. }, 1000);
  83782. });
  83783. var polesMats = {
  83784. shadowMat: new MeshBasicMaterial({
  83785. transparent:true, depthTest:false,
  83786. map: texLoader$b.load(Potree.resourcePath+'/textures/pano_instruction_bottomMarker.png' )
  83787. }),
  83788. sphereMat : new MeshBasicMaterial({
  83789. transparent:true, depthTest:false,
  83790. map: texLoader$b.load(Potree.resourcePath+'/textures/whiteCircle.png' )
  83791. }),
  83792. hatMats:{
  83793. start: new MeshBasicMaterial({
  83794. transparent:true, depthTest:false,
  83795. map: texLoader$b.load(Potree.resourcePath+'/textures/pano_instruction_start_route.png' )
  83796. }),
  83797. end: new MeshBasicMaterial({
  83798. transparent:true, depthTest:false,
  83799. map: texLoader$b.load(Potree.resourcePath+'/textures/pano_instruction_target_reached.png' )
  83800. })
  83801. }
  83802. };
  83803. polesMats.shadowMat.map.anisotropy = 4;
  83804. this.poleStart = this.createPole(polesMats, 'start');
  83805. this.poleEnd = this.createPole(polesMats, 'end');
  83806. this.sceneMeshGroup.add(this.poleStart);
  83807. this.sceneMeshGroup.add(this.poleEnd);
  83808. let map = texLoader$b.load(Potree.resourcePath+'/textures/routePoint_panorama.png' );
  83809. map.anisotropy = 4; // 各向异性过滤 .防止倾斜模糊
  83810. this.arrow = new Mesh(planeGeo$3, new MeshBasicMaterial({
  83811. transparent:true,
  83812. depthTest:false,
  83813. map
  83814. }));
  83815. this.arrow.scale.set(arrowSize,arrowSize,arrowSize);
  83816. Potree.Utils.setObjectLayers(this.arrow, 'sceneObjects' );
  83817. /* this.testArrow = this.arrow.clone();
  83818. this.testArrow.material = this.arrow.material.clone()
  83819. this.testArrow.material.color = 'red' */
  83820. this.arrows = new Object3D;
  83821. this.sceneMeshGroup.add(this.arrows);
  83822. Potree.Utils.setObjectLayers(this.sceneMeshGroup, 'sceneObjects' );
  83823. //this.sceneMeshGroup.traverse(e=>e.renderOrder = 90)
  83824. viewer.scene.scene.add(this.sceneMeshGroup);
  83825. this.sceneMeshGroup.visible = false;
  83826. this.poleStart.visible = false;
  83827. this.poleEnd.visible = false;
  83828. //-------------map---------------------
  83829. /* this.mapMarkStart = new THREE.Mesh( planeGeo, new THREE.MeshBasicMaterial({
  83830. transparent:true, depthTest:false,
  83831. map: texLoader.load(Potree.resourcePath+'/textures/map_instruction_start_route.png' )
  83832. }))
  83833. this.mapMarkEnd = new THREE.Mesh( planeGeo, new THREE.MeshBasicMaterial({
  83834. transparent:true, depthTest:false,
  83835. map: texLoader.load(Potree.resourcePath+'/textures/map_instruction_target_reached.png' )
  83836. }))
  83837. this.mapMarkStart.renderOrder = this.mapMarkEnd.renderOrder = 2//在箭头之上 */
  83838. let map2 = texLoader$b.load(Potree.resourcePath+'/textures/routePoint_map_fsna.png' );
  83839. this.mapArrowMats = {
  83840. default: new MeshBasicMaterial({
  83841. transparent:true, depthTest:false,
  83842. map:map2,
  83843. }),
  83844. fade: new MeshBasicMaterial({
  83845. transparent:true, depthTest:false,
  83846. map:map2,
  83847. opacity:0.4
  83848. }),
  83849. };
  83850. this.mapArrow = new Mesh( planeGeo$3, this.mapArrowMats.default);
  83851. this.mapArrow.scale.set(arrowSize,arrowSize,arrowSize);
  83852. this.mapArrows = new Object3D;
  83853. this.mapArrows.name = 'mapArrows';
  83854. this.mapMeshGroup.add(this.mapArrows);
  83855. this.mapMeshGroup.name = 'mapRouteLayer';
  83856. this.mapMeshGroup.visible = false;
  83857. viewer.mapViewer.dispatchEvent({type:'add', object:this.mapMeshGroup, name:'route'});
  83858. this.mapArrow.layers.mask = this.mapArrows.layers.mask; // 修改成和map中的layer一样的
  83859. viewer.modules.SiteModel.bus.addEventListener('FloorChange',()=>{
  83860. if(this.routeStart && this.routeEnd){
  83861. this.updateOpacityAtMap();
  83862. }
  83863. });
  83864. this.inited = true;
  83865. }
  83866. updateOpacityAtMap(){//只有当前楼层的透明度为1
  83867. var currentFloor = viewer.modules.SiteModel.currentFloor;
  83868. //console.log('updateOpacityAtMap', currentFloor && currentFloor.name)
  83869. const lift = 0.3; // 因为发送请求时用的是floorPosition的高度,而它可能会到画好的floor之下,所以有误差
  83870. this.mapArrows.children.forEach((arrow,index)=>{
  83871. let pos = this.mapPoints[index].clone();
  83872. pos.z += lift;
  83873. let inSide = currentFloor && currentFloor.ifContainsPoint(pos);
  83874. arrow.material = inSide ? this.mapArrowMats.default : this.mapArrowMats.fade;
  83875. //console.log('arrow',index, arrow.material.opacity)
  83876. });
  83877. viewer.mapViewer.dispatchEvent('content_changed');
  83878. }//但是如果楼层刚好只框柱相机位置而没框住地面位置就不好了……
  83879. createPole(polesMats, name){
  83880. const height = 1.5, sphereCount = 6, shadowSize = 0.5 /* sphereSizeInfo.scale */, sphereSize = 0.05;
  83881. var group = new Object3D;
  83882. group.name = 'pole_'+name;
  83883. var shadow = new Mesh(planeGeo$3, polesMats.shadowMat);
  83884. shadow.scale.set(shadowSize,shadowSize,shadowSize);
  83885. var sliceDis = height / (sphereCount+1);
  83886. group.add(shadow);
  83887. for(let i=0;i<sphereCount;i++){
  83888. var sphere = new Sprite$2({mat: polesMats.sphereMat, renderOrder:3});
  83889. sphere.position.set(0,0,sliceDis*(i+1));
  83890. sphere.scale.set(sphereSize,sphereSize,sphereSize);
  83891. //sphere.visible = false
  83892. group.add(sphere);
  83893. }
  83894. var hatSphere = new Sprite$2({mat: polesMats.hatMats[name], sizeInfo:sphereSizeInfo, renderOrder:4});
  83895. //sphere.visible = false
  83896. hatSphere.position.set(0,0,height);
  83897. hatSphere.scale.copy(shadow.scale);
  83898. group.add(hatSphere);
  83899. group.hatSphere = hatSphere;
  83900. return group
  83901. }
  83902. addTestArrow(){
  83903. }
  83904. addArrow(position){
  83905. var arrow = this.arrow.clone();
  83906. arrow.position.copy(position);
  83907. this.arrows.add(arrow);
  83908. }
  83909. addMapArrow(position){
  83910. var mapArrow = this.mapArrow.clone();
  83911. mapArrow.position.copy(position).setZ(0);
  83912. this.mapArrows.add(mapArrow);
  83913. }
  83914. setArrowDir(arrows,index){
  83915. let arrow = arrows[index];
  83916. var nextOne = arrows[index+1];
  83917. var nextPos = nextOne ? nextOne.position : this.endPolePos; //routeEnd
  83918. var direction = new Vector3().subVectors(arrow.position, nextPos).setZ(0);
  83919. //direction.normalize();
  83920. //console.log(direction.toArray())
  83921. var angle = Math.atan2(direction.y, direction.x ) + Math.PI/2; //Math.PI/2是因为贴图本身箭头方向不朝x
  83922. arrow.rotation.z = angle;
  83923. //console.log(angle)
  83924. }
  83925. setRouteStart(pos, dealZ , datasetId ){
  83926. if(this.routeStart && pos && this.routeStart.equals(pos)) return //可能重复设置
  83927. this.routeStart = pos && new Vector3().copy(pos);
  83928. if(dealZ && this.routeStart){
  83929. this.routeStart.setZ(this.getZAtMap());
  83930. this.bus && this.bus.emit('reposStartMarker', this.routeStart);
  83931. }
  83932. console.log('setRouteStart',this.routeStart&&this.routeStart.toArray());
  83933. this.datasetIds[0] = datasetId;
  83934. //this.setStartPole(pos)
  83935. this.poleStart.visible = !!pos;
  83936. pos && this.poleStart.position.copy(this.routeStart);
  83937. pos && this.poleStart.hatSphere.waitUpdate();
  83938. this.generateRoute();
  83939. viewer.dispatchEvent('content_changed');
  83940. }
  83941. setStartPole(pos){
  83942. this.startPolePos = pos;
  83943. this.bus && this.bus.emit('reposStartMarker', pos);
  83944. }
  83945. setRouteEnd(pos, dealZ , datasetId ){
  83946. if(this.routeEnd && pos && this.routeEnd.equals(pos)) return
  83947. this.routeEnd = pos && new Vector3().copy(pos);
  83948. if(dealZ && this.routeEnd){
  83949. this.routeEnd.setZ(this.getZAtMap());
  83950. this.bus && this.bus.emit('reposEndMarker', this.routeEnd);
  83951. }
  83952. console.log('setRouteEnd',this.routeEnd&&this.routeEnd.toArray());
  83953. this.datasetIds[1] = datasetId;
  83954. //this.setEndPole(pos)
  83955. this.poleEnd.visible = !!pos;
  83956. pos && this.poleEnd.position.copy(this.routeEnd);
  83957. pos && this.poleEnd.hatSphere.waitUpdate();
  83958. this.generateRoute();
  83959. viewer.dispatchEvent('content_changed');
  83960. }
  83961. getZAtMap(){
  83962. //找到position.z与当前高度最接近的漫游点
  83963. let result = Common.sortByScore(viewer.images360.panos,[],[e=> -(Math.abs(e.position.z - viewer.images360.position.z)) ]);
  83964. let pano = result && result[0] && result[0].item;
  83965. return pano ? pano.floorPosition.z : viewer.bound.boundingBox.min.z + 1
  83966. //若在平面图上画实在得不到当前楼层的,大概率是楼层画得不好,那就只能去获取当前楼层的了
  83967. //navvis的高度取的是主视图所在楼层的中心高度(可能再高些)
  83968. }
  83969. setEndPole(pos){
  83970. this.endPolePos = pos;
  83971. this.bus && this.bus.emit('reposEndMarker', pos);
  83972. }
  83973. getSourceProjectionIndex(route) {//真正的起始
  83974. var e = route.findIndex(function(t) {
  83975. return t.instruction && t.instruction.type === 'source_projection_to_navgraph'
  83976. });
  83977. return e < 0 ? 0 : e
  83978. }
  83979. getDestinationProjectionIndex(route) {//真正的终点
  83980. var e = route.findIndex(function(t) {
  83981. return t.instruction && t.instruction.type === "destination_projection_to_navgraph"
  83982. });
  83983. return e < 0 ? route.length - 1 : e
  83984. }
  83985. generateRoute(){
  83986. this.sceneMeshGroup.visible = true;
  83987. if(!this.routeStart || !this.routeEnd){
  83988. return
  83989. }
  83990. let initialPointcloud = viewer.scene.pointclouds.find(e=>e.dataset_id == Potree.settings.originDatasetId);
  83991. //array.reduce(function(total, currentValue, currentIndex, arr), initialValue)
  83992. let create = ()=>{
  83993. this.routeLength = this.route.reduce((total, currentValue, currentIndex, arr)=>{
  83994. if(currentIndex == 0)return 0
  83995. return total + currentValue.distanceTo(arr[currentIndex-1]);
  83996. },0);
  83997. let count = Math.max(2,Math.round(this.routeLength / arrowSpacing));//点数
  83998. const curve = new CatmullRomCurve3( this.route );
  83999. curve.curveType = 'chordal';//'centripetal' 'catmullrom'这个可能会超出路径外
  84000. this.curve = curve;
  84001. const scenePoints = curve.getSpacedPoints( count );//更平均
  84002. //const scenePoints = curve.getPoints( count );
  84003. scenePoints.splice(0,1);//去掉首尾
  84004. scenePoints.pop();
  84005. this.scenePoints = scenePoints;
  84006. this.updateMapArrows();
  84007. this.displayRoute();
  84008. {//map focus on this area
  84009. const minBound = new Vector2(1,1);//针对垂直线,在地图上只有一个点
  84010. let bound = new Box2;
  84011. this.route.forEach(e=>{
  84012. bound.expandByPoint(e);
  84013. });
  84014. let size = bound.getSize(new Vector2);
  84015. let markerSize = new Vector2(115,40); //起始和终点的标识呈长方形
  84016. let areaSize = viewer.mapViewer.viewports[0].resolution2;
  84017. let areaArea = areaSize.x * areaSize.y;
  84018. if(areaArea> 800 * 400){//是放大的
  84019. markerSize.multiplyScalar(areaArea / (800 * 400) /* / (size.x * size.y) */);
  84020. }
  84021. let margin = size.clone().divide(viewer.mapViewer.viewports[0].resolution2).multiply(markerSize); ///边距 重点是起始和终点的标识占据较大
  84022. size.add(margin);
  84023. let center = bound.getCenter(new Vector2);
  84024. size.x = Math.max(size.x, minBound.x );
  84025. size.y = Math.max(size.y, minBound.y );
  84026. let duration = 1000;
  84027. viewer.mapViewer.moveTo(center, size, duration);
  84028. }
  84029. this.bus.emit('gotResult', {dis:this.routeLength});
  84030. /* this.generateDeferred && this.generateDeferred.resolve({dis:this.routeLength})
  84031. this.generateDeferred = null */
  84032. };
  84033. if(Potree.fileServer){
  84034. let dealData = (data)=>{
  84035. if(!data.data){
  84036. console.log('没有数据');
  84037. let result;
  84038. if(data && data.code == 4002){
  84039. result = data;//正被修改数据集
  84040. }else if(this.routeStart.distanceTo(this.routeEnd) < 1){
  84041. result = { code: 500, msg: '距离太短,无法规划路线' };
  84042. }else {
  84043. result = { code: 500, msg: '超出数据集范围,无法规划路线' };
  84044. }
  84045. this.clearRoute();
  84046. this.setStartPole(this.routeStart);
  84047. this.setEndPole(this.routeEnd);
  84048. this.displayRoute(); //还是要显示一下起始
  84049. this.bus && this.bus.emit('gotResult', result );
  84050. return //this.generateDeferred && this.generateDeferred.resolve()
  84051. }
  84052. data = data.data;
  84053. this.clearRoute();
  84054. let length = data.length;
  84055. if(length < 2){//可能距离太短
  84056. console.log('路径点数为'+length+',直接取起点和终点连线');
  84057. this.route = [this.routeStart, this.routeEnd];
  84058. }else {
  84059. let startIndex = this.getSourceProjectionIndex(data);
  84060. let endIndex = this.getDestinationProjectionIndex(data);
  84061. let effectiveItems = data.slice(startIndex, endIndex + 1 );//只要点云范围内的点
  84062. effectiveItems.forEach((item,i)=>{
  84063. //let pos = viewer.transform.lonlatToLocal.forward(item.location.slice(0)/* ,true */)
  84064. let pos = item.location.slice(0);
  84065. pos = new Vector3().fromArray(pos);//.setZ(item.z)
  84066. pos.z -= initialPointcloud.datasetData.location[2];
  84067. this.route.push(pos);
  84068. });
  84069. //console.log('route', this.route)
  84070. }
  84071. this.setStartPole(this.route[0]);
  84072. this.setEndPole(this.route[this.route.length-1]);
  84073. create();
  84074. /*
  84075. distance: 0.17581000000000116
  84076. distance_to_previous: 0.17581000000000116
  84077. id: 567
  84078. instruction: {type: 'source_projection_to_navgraph'}
  84079. latitude: 22.366605927999238
  84080. location: (3) [113.5957510575092, 22.366605927999238, -1.12419]
  84081. longitude: 113.5957510575092
  84082. z: -1.12419
  84083. */
  84084. };
  84085. if(this.lastResult && (this.lastResult.data || this.lastResult.data.code != 4002)){//正被修改数据集的话要重新计算
  84086. let data = Common.CloneObject(this.lastResult.data) , use; //直接用上次的结果
  84087. if(this.lastResult.routeStart.equals(this.routeStart) && this.lastResult.routeEnd.equals(this.routeEnd)){//和上次请求相同
  84088. use = true;
  84089. }else if(this.lastResult.routeStart.equals(this.routeEnd) && this.lastResult.routeEnd.equals(this.routeStart)){//..反向
  84090. use = true;
  84091. if(data.data){
  84092. data.data = this.lastResult.data.data.slice(0).reverse();
  84093. }
  84094. }
  84095. if(use){
  84096. console.log('直接用上次的结果');
  84097. return setTimeout(()=>{dealData(data);}, 1)//延迟是为了等待获得 RouteGuider.generateDeferred
  84098. }
  84099. }
  84100. let start = this.routeStart.clone();
  84101. let end = this.routeEnd.clone();
  84102. //let startLonlat = viewer.transform.lonlatToLocal.inverse(start/* , true */)
  84103. //let endLonlat = viewer.transform.lonlatToLocal.inverse(end/* , true */)
  84104. /* var query = {
  84105. source_longitude: start.x,
  84106. source_latitude: start.y,
  84107. source_z: start.z,
  84108. destination_longitude: end.x,
  84109. destination_latitude: end.y,
  84110. destination_z: end.z
  84111. }; */
  84112. var query = {
  84113. source_longitude: start.x,
  84114. source_latitude: start.y,
  84115. source_z: start.z+initialPointcloud.datasetData.location[2],
  84116. destination_longitude: end.x,
  84117. destination_latitude: end.y,
  84118. destination_z: end.z+initialPointcloud.datasetData.location[2]
  84119. };
  84120. /* var query = {
  84121. source_longitude: startLonlat.x,
  84122. source_latitude: startLonlat.y,
  84123. source_z: start.z,
  84124. destination_longitude: endLonlat.x,
  84125. destination_latitude: endLonlat.y,
  84126. destination_z: end.z
  84127. }; */
  84128. //let url = `/laser/route/${Potree.settings.number}/getRoute/${this.datasetIds[0]}/${this.datasetIds[1]}?`
  84129. let url = `/laser/route/${Potree.settings.number}/getRoute/${Potree.settings.originDatasetId}?`;
  84130. for(let i in query){
  84131. url+= (i + '='+ query[i] +'&');
  84132. }
  84133. Potree.fileServer.get(url).then((data)=>{
  84134. //console.log('data', data.data)
  84135. if(!this.routeStart || !this.routeEnd)return
  84136. this.lastResult = {//保存数据
  84137. routeStart : this.routeStart.clone(),
  84138. routeEnd: this.routeEnd.clone(),
  84139. data,
  84140. };
  84141. dealData(data);
  84142. });
  84143. }else {
  84144. //创个直线
  84145. /* const sliceDis = 1
  84146. let dis = this.routeStart.distanceTo(this.routeEnd);
  84147. let count = Math.max(2,Math.round(dis / sliceDis))//点数
  84148. let realSlideDis = dis / (count-1);
  84149. let dir = new THREE.Vector3().subVectors(this.routeEnd, this.routeStart).normalize().multiplyScalar(realSlideDis);
  84150. this.route = [this.routeStart];
  84151. for(let i=0;i<count-1;i++){
  84152. let lastOne = this.route[i];
  84153. this.route.push(new THREE.Vector3().addVectors(lastOne,dir))
  84154. }
  84155. this.route.splice(0,1) //route不用包含收尾 */
  84156. this.clearRoute();
  84157. this.route = [this.routeStart, this.routeEnd];
  84158. create();
  84159. }
  84160. }
  84161. updateMapArrows(ifReset){
  84162. if(this.route.length == 0)return
  84163. var zoom = viewer.mapViewer.camera.zoom;
  84164. let isBig = viewer.mapViewer.viewports[0].resolution.y > 300;
  84165. let count = Math.max(2,Math.round(this.routeLength * zoom / arrowSpacing / (isBig?35:30)));//点数
  84166. if(count == this.mapPoints.length+1)return//没变
  84167. const mapPoints = this.curve.getSpacedPoints( count );
  84168. mapPoints.splice(0,1);//去掉首尾
  84169. mapPoints.pop();
  84170. this.mapPoints = mapPoints;
  84171. var scale = (isBig ? 26 : 22)/zoom;
  84172. this.mapArrow.scale.set(scale,scale,scale);
  84173. /* this.mapMarkStart.scale.set(scale,scale,scale)
  84174. this.mapMarkEnd.scale.set(scale,scale,scale) */
  84175. if(ifReset){//因为缩放而重新排布箭头
  84176. this.clearRoute({resetMap:true});
  84177. this.displayRoute({resetMap:true});
  84178. }
  84179. this.updateOpacityAtMap();
  84180. }
  84181. updateArrowDisplay(){//根据当前位置更新显示一定范围内的箭头
  84182. if(this.scenePoints.length == 0)return
  84183. /* var a = Common.sortByScore(this.scenePoints , null, [(point)=>{ //是否还要再requires里限制最远距离?
  84184. var playerPos = viewer.scene.getActiveCamera().position.clone().setZ(0)
  84185. var pos = point.clone().setZ(0)
  84186. return -pos.distanceTo(playerPos);
  84187. }]);
  84188. //获得展示的起始点
  84189. let start = a[0].item
  84190. let startIndex = this.scenePoints.indexOf(start)
  84191. this.arrows.children.forEach((e,i)=>{
  84192. if(i<startIndex || i>startIndex+arrowsShowingCount)e.visible = false
  84193. else e.visible = true
  84194. }) */
  84195. let cameraPos = viewer.scene.getActiveCamera().position;
  84196. this.arrows.children.forEach((e,i)=>{
  84197. if(e.position.distanceTo(cameraPos) < arrowShowMinDis) e.visible = true;
  84198. else e.visible = false;
  84199. });
  84200. viewer.dispatchEvent('content_changed');
  84201. }
  84202. displayRoute(o={}){
  84203. if(!o.resetMap){
  84204. this.poleStart.position.copy(this.startPolePos || this.routeStart);
  84205. this.poleEnd.position.copy(this.endPolePos || this.routeEnd);
  84206. /* this.mapMarkStart.position.copy(this.routeStart).setZ(0)
  84207. this.mapMarkEnd.position.copy(this.routeEnd).setZ(0) */
  84208. this.scenePoints.forEach(e=>this.addArrow(e));
  84209. this.arrows.children.forEach((e,i)=>this.setArrowDir(this.arrows.children,i));
  84210. }
  84211. this.sceneMeshGroup.visible = true;//.traverse(e=>e.visible = true)
  84212. this.mapMeshGroup.visible = true;
  84213. this.mapPoints.forEach(e=>this.addMapArrow(e));
  84214. this.mapArrows.children.forEach((e,i)=>this.setArrowDir(this.mapArrows.children,i));
  84215. viewer.mapViewer.dispatchEvent({'type':'content_changed'});
  84216. this.updateArrowDisplay();
  84217. }
  84218. clearRoute(o={}){
  84219. if(!o.resetMap){
  84220. this.routeLength = 0;
  84221. this.route = [];
  84222. this.scenePoints = [];
  84223. this.mapPoints = [];
  84224. let arrows = this.arrows.children.slice(0);
  84225. arrows.forEach(e=>{
  84226. this.arrows.remove(e);
  84227. });
  84228. }
  84229. let mapArrows = this.mapArrows.children.slice(0);
  84230. mapArrows.forEach(e=>{
  84231. this.mapArrows.remove(e);
  84232. });
  84233. this.sceneMeshGroup.visible = false;
  84234. //this.sceneMeshGroup.traverse(e=>e.visible = false) //包括sprite也要设置,防止update
  84235. this.mapMeshGroup.visible = false;
  84236. viewer.mapViewer.dispatchEvent({'type':'content_changed'});
  84237. viewer.dispatchEvent('content_changed');
  84238. }
  84239. clear(){//退出
  84240. console.log('导航clear');
  84241. this.routeStart = null;
  84242. this.routeEnd = null;
  84243. this.clearRoute();
  84244. }
  84245. }
  84246. //大概每十米要花一秒
  84247. /*
  84248. 存在的问题:
  84249. 路径不准确。起始点和终点偏移。
  84250. https://uat-laser.4dkankan.com/routeDebug/ 可查整个map的通路点位图
  84251. */
  84252. //import History from "../../utils/History.js"
  84253. const cameraProps$1 = [
  84254. {
  84255. name : 'top',
  84256. axis:["x","y"],
  84257. direction : new Vector3(0,0,-1), //镜头朝向
  84258. openCount:0,
  84259. }
  84260. ];
  84261. class Clipping extends EventDispatcher{ //实时剪裁
  84262. constructor(){
  84263. super();
  84264. this.views = {};
  84265. this.cameras = {};
  84266. this.orthoCamera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  84267. this.orthoCamera.up.set(0,0,1);
  84268. }
  84269. init(){
  84270. if(this.inited)return
  84271. this.initViews();
  84272. this.inited = true;
  84273. this.prepareRecord = true;
  84274. this.activeViewName = 'mainView';
  84275. this.events = {
  84276. transfromCallback:(e)=>{//拖拽变化时
  84277. this.adjustCamHeight();
  84278. //检测漫游点、回退等
  84279. /* if(this.prepareRecord){
  84280. let box = viewer.transformationTool.selection[0]
  84281. this.history.writeIn({box, matrix:box.matrix.clone()})
  84282. this.prepareRecord = false
  84283. } */
  84284. },
  84285. /* onTransfromEnd:(e)=>{//拖拽结束、松开
  84286. this.prepareRecord = true
  84287. }, */
  84288. selectCallback:(e)=>{
  84289. this.adjustCamHeight();
  84290. let unableNavigate = this.activeViewName != 'mainView' || e.selection.length > 0;
  84291. if(Potree.settings.unableNavigate && !unableNavigate){
  84292. setTimeout(()=>{
  84293. Potree.settings.unableNavigate = this.activeViewName != 'mainView' || e.selection.length > 0;
  84294. },300);//延迟是因为点击时取消选择后可能立即就会触发flyToPano。 而且有的人喜欢点两下
  84295. }else Potree.settings.unableNavigate = unableNavigate;
  84296. },
  84297. onkeydown:(e)=>{
  84298. if(e.keyCode == 8 || e.keyCode == 46){// Backspace or Delete
  84299. viewer.inputHandler.selection[0] && viewer.scene.removeVolume(viewer.inputHandler.selection[0]);
  84300. }
  84301. }
  84302. };
  84303. /* this.history = new History({ //也可以写到全局,但需要加个判断物品是否存在的函数
  84304. applyData: (data)=>{
  84305. if(viewer.scene.volumes.includes(data.box)){
  84306. data.matrix.decompose( data.box.position, data.box.quaternion, data.box.scale );
  84307. }else{
  84308. this.history.undo()//找不到就回退下一个。(直接写这?)
  84309. }
  84310. }
  84311. }) */
  84312. }
  84313. initViews(){
  84314. this.splitScreenTool = new SplitScreen;
  84315. for(let i=0;i<1;i++){
  84316. let prop = cameraProps$1[i];
  84317. let view = new ExtendView();
  84318. this.views[prop.name] = view;
  84319. this.cameras[prop.name] = this.orthoCamera;
  84320. view.direction = prop.direction;
  84321. }
  84322. this.views.mainView = viewer.mainViewport.view;
  84323. this.cameras.mainView = viewer.mainViewport.camera;
  84324. }
  84325. switchView(name){//替换view和camera到mainViewport
  84326. if(this.activeViewName == name)return
  84327. let view = this.views[name];
  84328. let camera = this.cameras[name];
  84329. let prop = cameraProps$1.find(e=>e.name == name);
  84330. let {boundSize, center, boundingBox} = viewer.bound;
  84331. this.lastViewName = this.activeViewName;
  84332. this.activeViewName = name;
  84333. let lastView = this.views[this.lastViewName];
  84334. let lastCamera = this.cameras[this.lastViewName];
  84335. viewer.mainViewport.view = view;
  84336. viewer.mainViewport.camera = camera;
  84337. if(lastCamera)lastView.zoom = lastCamera.zoom;
  84338. /* if(lastView){//2d->3d
  84339. view.copy(lastView)
  84340. } */
  84341. if(name == 'mainView'){
  84342. Potree.settings.unableNavigate = false;
  84343. /* viewer.transformationTool.handles['scale.z+'].node.visible = true
  84344. viewer.transformationTool.handles['scale.z-'].node.visible = true */
  84345. }else {
  84346. Potree.settings.unableNavigate = true;
  84347. /* viewer.transformationTool.handles['scale.z+'].node.visible = false
  84348. viewer.transformationTool.handles['scale.z-'].node.visible = false */
  84349. if(prop.openCount == 0){//至多执行一次
  84350. //this.viewportFitBound(name, boundSize, center)
  84351. this.orthoMoveFit(center, {bound:boundingBox}, 0);
  84352. this.camHeightOutOfModel = view.position.z; //记录下此刻相机高度。
  84353. }
  84354. prop.openCount++;
  84355. this.adjustCamHeight();
  84356. /* this.targetPlane.setFromNormalAndCoplanarPoint( view.direction.clone(), center )
  84357. this.targetPlane.projectPoint(view.position, this.shiftTarget ) //target转换到过模型中心的平面,以保证镜头一定在模型外
  84358. view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport)) */
  84359. if(view.zoom)camera.zoom = view.zoom;//恢复上次的zoom
  84360. }
  84361. viewer.updateScreenSize({forceUpdateSize:true});//更新camera aspect left等
  84362. if(viewer.inputHandler.selection.length){
  84363. this.focusOnObject(viewer.inputHandler.selection[0]);
  84364. }
  84365. }
  84366. focusOnObject(box, duration=0){
  84367. if(this.activeViewName == 'mainView'){
  84368. viewer.focusOnObject({boundingBox:box.boundingBox.clone().applyMatrix4(box.matrixWorld)}, 'boundingBox', duration);
  84369. }else {
  84370. this.orthoMoveFit(box.position, {bound:box.boundingBox.clone().applyMatrix4(box.matrixWorld)}, duration);
  84371. }
  84372. this.adjustCamHeight();
  84373. }
  84374. orthoMoveFit(pos, info, duration){
  84375. var margin = {x:viewer.mainViewport.resolution.x*0.4, y:viewer.mainViewport.resolution.y*0.4};
  84376. this.splitScreenTool.viewportFitBound(viewer.mainViewport, info.bound, pos, duration, margin );
  84377. }
  84378. adjustCamHeight(){
  84379. if(this.activeViewName != 'top')return
  84380. let view = this.views.top;
  84381. let height;
  84382. if(viewer.inputHandler.selection.length){ //相机高度位于选中的box的顶部
  84383. let box = viewer.inputHandler.selection[0];
  84384. height = box.boundingBox.clone().applyMatrix4(box.matrixWorld).max.z;
  84385. }else {
  84386. height = this.camHeightOutOfModel; //显示全部点云
  84387. }
  84388. view.position.z = height;
  84389. //console.log('adjustCamHeight',height)
  84390. //缺点:1 会导致缩放很小的时候,transformationTool的轴因放大到了相机背面。(只有scale轴做了处理)
  84391. //2 无法直接切换 看不到的box,但可以先取消选择
  84392. //3 但是俯视图中无法切换到被上层盖住的box(不过把俯视图作为辅助,只针对单个box调动的话,问题不大)
  84393. }
  84394. enter(){
  84395. this.init();
  84396. viewer.transformationTool.setModeEnable(['translation']);
  84397. //viewer.transformationTool.handles['rotation.x'].node.visible = false
  84398. viewer.transformationTool.frame.material.visible = false; //不盖住boxVolume的frame
  84399. this.targetPlane = viewer.mainViewport.targetPlane = new Plane();
  84400. this.shiftTarget = viewer.mainViewport.shiftTarget = new Vector3; //project在targetPlane上的位置
  84401. this.getAllBoxes().forEach(box=>{
  84402. Potree.Utils.updateVisible(box,'hidden',true); //显现
  84403. });
  84404. viewer.transformationTool.history.clear();
  84405. viewer.transformationTool.addEventListener('transformed', this.events.transfromCallback);
  84406. //viewer.transformationTool.addEventListener('stopDrag', this.events.onTransfromEnd)
  84407. viewer.inputHandler.addEventListener('selection_changed', this.events.selectCallback);
  84408. viewer.inputHandler.addEventListener('keydown', this.events.onkeydown);
  84409. this.setPointLevelAuto();
  84410. var initialPointcloud = viewer.scene.pointclouds.find(p => p.dataset_id == Potree.settings.originDatasetId);
  84411. //隐藏 初始数据集以外的数据集
  84412. viewer.scene.pointclouds.forEach(e=>{
  84413. if(e.dataset_id!=Potree.settings.originDatasetId){
  84414. Potree.Utils.updateVisible(e,'enterClipping',false);
  84415. //Potree.settings.floorplanEnables[e.dataset_id] = false
  84416. e.panos.forEach(pano=>pano.setEnable(false)); //禁止漫游
  84417. }else {
  84418. Potree.Utils.updateVisible(e,'enterClipping',true, 1, 'add');
  84419. //Potree.settings.floorplanEnables[e.dataset_id] = true
  84420. }
  84421. });
  84422. viewer.flyToDataset({ pointcloud : initialPointcloud, duration:0});
  84423. }
  84424. enter2(){//在土方量界面的
  84425. viewer.transformationTool.setModeEnable(['translation']);
  84426. viewer.transformationTool.frame.material.visible = false; //不盖住boxVolume的frame
  84427. viewer.transformationTool.history.clear();
  84428. //viewer.inputHandler.addEventListener('keydown', this.events.onkeydown)
  84429. }
  84430. leave(){
  84431. viewer.transformationTool.setModeEnable(['scale', 'translation', 'rotation'] );
  84432. viewer.transformationTool.frame.material.visible = true; //恢复
  84433. this.switchView( 'mainView' );
  84434. this.getAllBoxes().forEach(box=>{
  84435. Potree.Utils.updateVisible(box,'hidden',false);//隐身
  84436. });
  84437. viewer.transformationTool.removeEventListener('transformed', this.events.transfromCallback);
  84438. //viewer.transformationTool.removeEventListener('stopDrag', this.events.onTransfromEnd)
  84439. viewer.inputHandler.removeEventListener('selection_changed', this.events.selectCallback);
  84440. //viewer.inputHandler.removeEventListener('keydown', this.events.onkeydown)
  84441. viewer.transformObject(null);
  84442. viewer.transformationTool.history.clear();
  84443. //恢复 初始数据集以外的数据集
  84444. viewer.scene.pointclouds.forEach(e=>{
  84445. if(e.dataset_id!=Potree.settings.originDatasetId){
  84446. Potree.Utils.updateVisible(e,'enterClipping',true);
  84447. e.panos.forEach(pano=>pano.setEnable(true));
  84448. }else {
  84449. Potree.Utils.updateVisible(e,'enterClipping',false, 0, 'cancel');
  84450. }
  84451. });
  84452. }
  84453. setTranMode(mode){//rotate or translate
  84454. this.tranMode = mode;
  84455. viewer.transformationTool.setModeEnable([mode]);
  84456. viewer.dispatchEvent('content_changed');
  84457. }
  84458. //问:是否要显示其他数据集
  84459. setPointLevelAuto(){
  84460. /*
  84461. let visiCount = viewer.images360.panos.length
  84462. let maxCount = 200, minCount = 20, minPer = 0.7, maxPer = 1
  84463. let percent = maxPer - ( maxPer - minPer) * THREE.Math.clamp((visiCount - minCount) / (maxCount - minCount),0,1)
  84464. Potree.settings.UserDensityPercent = percent ---还是不限制了,尤其是平面图希望更细致点,毕竟剪裁主要要看清剪裁的部位。
  84465. */
  84466. viewer.setPointBudget(5*1000*1000); //给个中等到高等之间的质量
  84467. Potree.settings.sizeFitToLevel = true;
  84468. viewer.setPointLevels();
  84469. }
  84470. getAllBoxes(){
  84471. return viewer.scene.volumes.filter(v=>v.clip && v instanceof Potree.BoxVolume )
  84472. }
  84473. getCalcData(){//给后台矩阵数据,以裁剪点云。
  84474. let Clip = viewer.modules.Clip; //裁剪下载模块
  84475. let data = {
  84476. transformation_matrix: viewer.scene.pointclouds.filter(p=>p.dataset_id == Potree.settings.originDatasetId).map((cloud)=>{
  84477. let data = {
  84478. id: cloud.dataset_id,
  84479. matrix : new Matrix4().elements, //参照downloadNoCrop,给默认值,表示没有最外层裁剪
  84480. visiMatrixes: cloud.material.clipBoxes_in.filter(e=>!e.box.isNew).map(e=>Clip.getTransformationMatrix(cloud, e.inverse).elements),
  84481. unVisiMatrixes: cloud.material.clipBoxes_out.filter(e=>!e.box.isNew).map(e=>Clip.getTransformationMatrix(cloud, e.inverse).elements),
  84482. modelMatrix: new Matrix4().elements //(new THREE.Matrix4).copy(cloud.transformMatrix).transpose().elements //需要保证没有位移,否则剪裁后的模型位置会变化
  84483. };
  84484. return data
  84485. }) ,
  84486. aabb: "b-12742000 -12742000 -12742000 12742000 12742000 12742000" //剪裁空间
  84487. };
  84488. return data
  84489. }
  84490. saveClipData(boxes){//输出所有的clip volumeBox
  84491. let oldState = !viewer.clipUnabled;
  84492. //viewer.setClipState(true)
  84493. let data = (boxes || this.getAllBoxes()).filter(e=>!e.isNew).map(volume=>{
  84494. return {
  84495. clipTask: volume.clipTask,
  84496. position: Potree.Utils.datasetPosTransform({position:volume.position, toDataset: true, datasetId: Potree.settings.originDatasetId}).toArray(),
  84497. rotation: Potree.Utils.datasetRotTransform({rotation:volume.rotation, toDataset: true, datasetId: Potree.settings.originDatasetId, getRotation:true}).toArray().slice(0,3),
  84498. scale: volume.scale.toArray(),
  84499. }
  84500. });
  84501. //console.log(data)
  84502. //console.log(JSON.stringify(data))
  84503. //viewer.setClipState(oldState)
  84504. return data
  84505. }
  84506. loadFromData(data=[]){
  84507. data.forEach(v=>{
  84508. let volume = new Potree.BoxVolume({clip:true, clipTask:v.clipTask});
  84509. volume.scale.fromArray(v.scale);
  84510. volume.position.fromArray(v.position);
  84511. volume.rotation.fromArray(v.rotation);
  84512. volume.position.copy(Potree.Utils.datasetPosTransform({position:volume.position, fromDataset: true, datasetId:Potree.settings.originDatasetId}));
  84513. volume.rotation.copy(Potree.Utils.datasetRotTransform({rotation:volume.rotation, fromDataset: true, datasetId:Potree.settings.originDatasetId, getRotation:true}));
  84514. viewer.scene.addVolume(volume);
  84515. viewer.volumeTool.scene.add(volume);
  84516. });
  84517. }
  84518. }
  84519. //注意:实时裁剪只对初始数据集有效,其他数据集已经隐藏
  84520. /*
  84521. 备注:
  84522. 2023
  84523. 发送给后台数据样例:
  84524. {"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"}
  84525. 发送给算法部的数据样例:
  84526. {
  84527. "model": [
  84528. {
  84529. "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",
  84530. "file": "/mnt/data/pvt000004/1079784714115481600/pvt000004_202302271512444930_laserData/laserData/laser.las",
  84531. "visiMatrixes": [[..],[..]],
  84532. "dataSetId": "1630105213031026688",
  84533. "sceneCode": "SS-t-MVQ1Jb80oMG",
  84534. "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",
  84535. "unVisiMatrixes": [[..],[..]]
  84536. }
  84537. ],
  84538. "aabb": "b-12742000 -12742000 -12742000 12742000 12742000 12742000"
  84539. }
  84540. */
  84541. const vertexShader = `
  84542. attribute float randam;
  84543. attribute float sprite;
  84544. attribute float centerHeight; //add
  84545. //uniform float fireHeight; //add
  84546. uniform float time;
  84547. uniform float size;
  84548. uniform float heightOfNearPlane;
  84549. //varying float heightRatio;
  84550. varying float vSprite;
  84551. varying float vOpacity;
  84552. float PI = 3.14;
  84553. float quadraticIn( float t )
  84554. {
  84555. float tt = t * t;
  84556. return tt * tt;
  84557. //变化曲线 越来越快
  84558. }
  84559. void main() {
  84560. float progress = fract( time + ( 2.0 * randam - 1.0 ) );
  84561. float progressNeg = 1.0 - progress;
  84562. float ease = quadraticIn( progress );
  84563. float influence = sin( PI * ease );
  84564. //vec3 newPosition = position * vec3( 1.0, 1.0 , ease);
  84565. vec3 newPosition = position;
  84566. newPosition.z = (newPosition.z - centerHeight) * ease + centerHeight;
  84567. gl_Position = projectionMatrix * modelViewMatrix * vec4( newPosition, 1.0 );
  84568. gl_PointSize = ( heightOfNearPlane * size ) / gl_Position.w;
  84569. vOpacity = min( influence * 4.0, 1.0 ) * progressNeg;
  84570. vSprite = sprite;
  84571. //heightRatio = (newPosition.z - centerHeight) / fireHeight ;
  84572. }
  84573. `;
  84574. const fragmentShader = `
  84575. uniform vec3 color;
  84576. uniform sampler2D u_sampler;
  84577. varying float vSprite;
  84578. varying float vOpacity;
  84579. //varying float heightRatio;
  84580. void main()
  84581. {
  84582. vec2 texCoord = vec2(gl_PointCoord.x * 0.25 + vSprite, gl_PointCoord.y);
  84583. gl_FragColor = vec4( texture2D( u_sampler, texCoord ).xyz * color * vOpacity, 1.0 );
  84584. }
  84585. `;
  84586. // import { vertexShader, fragmentShader } from './shaders'
  84587. let ONE_SPRITE_ROW_LENGTH = 0.25; //对应着色器的0.25
  84588. let texture;
  84589. const getTexture = ()=>{
  84590. if(!texture){
  84591. texture = new TextureLoader().load( Potree.resourcePath+'/textures/fire.png');
  84592. }
  84593. return texture
  84594. };
  84595. const boxGeo = new BoxBufferGeometry(1,1,1,1);
  84596. const boxMat = new MeshBasicMaterial({wireframe:true, color:"#ffffff"});
  84597. class FireParticle extends Points{
  84598. constructor (prop) {
  84599. super();
  84600. for ( var key in prop ){
  84601. this[key] = prop[key];
  84602. }
  84603. this.strength = this.strength || 1;
  84604. this.radius = prop.radius || 1;
  84605. this.height = prop.height || 5;
  84606. this.computeParams();
  84607. this.geometry = this.createGeometry( this.radius, this.height, this.particleCount );
  84608. if(this.color == void 0) this.color = 0xff3200;
  84609. this.createMaterial( ); //小蓝火:0x00338f
  84610. //---?:
  84611. this.velocity = new Vector3();
  84612. this.acceleration = new Vector3();
  84613. this.angle = 0;
  84614. this.angleVelocity = 0;
  84615. this.angleAcceleration = 0;
  84616. this.size = 16;
  84617. this.opacity = 1;
  84618. this.age = 0;
  84619. this.alive = 0;
  84620. this.sizeTween = null;
  84621. this.colorTween = null;
  84622. this.opacityTween = null;
  84623. this.setSize({viewport:viewer.mainViewport});
  84624. this.setFov(viewer.fov);
  84625. let setSize = (e)=>{
  84626. if(e.viewport.name != "MainView")return
  84627. this.setSize(e);
  84628. };
  84629. let setFov = (e)=>{
  84630. this.setFov(e.fov);
  84631. };
  84632. viewer.addEventListener('resize',setSize);
  84633. viewer.addEventListener('fov_changed',setFov);
  84634. this.addEventListener('dispose',()=>{
  84635. viewer.removeEventListener('resize',setSize);
  84636. viewer.removeEventListener('fov_changed',setFov);
  84637. });
  84638. }
  84639. computeParams(){
  84640. let length = (this.curve ? this.curve.wholeLength : 0) + this.radius * 2; //加上首尾的半径
  84641. const minSize = 0.3, maxSize = 3, minRadiusBound = 0.3, maxRadiusBound = 10;
  84642. this.size = minSize + (maxSize - minSize) * MathUtils.smoothstep(this.radius, minRadiusBound, maxRadiusBound);
  84643. //console.log('fire material particle size:', size )
  84644. this.particleCount = Math.ceil( length * Math.sqrt(this.strength * this.height ) * this.radius / (this.size * this.size) * 25 );
  84645. //console.log('fire particleCount',this.particleCount)
  84646. }
  84647. getPointsForBound(){
  84648. return this.boundPoints; //可以用于expand实时bound的点, 不含particle的size等边距
  84649. }
  84650. getBound(points){ // points为生成点(圆心)
  84651. this.boundPoints = [];
  84652. let boundingBox = new Box3();
  84653. let margin = this.size * 0.13 + 0.3;
  84654. points.forEach(bottom=>{
  84655. let top = bottom.clone();
  84656. top.z += this.height;
  84657. boundingBox.expandByPoint(bottom);
  84658. boundingBox.expandByPoint(top);
  84659. this.boundPoints.push(bottom,top);
  84660. });
  84661. let xyExpand = this.radius+margin;
  84662. boundingBox.expandByVector(new Vector3(xyExpand,xyExpand,margin));
  84663. this.boundingBox = boundingBox;
  84664. /* if(!this.debugBox){
  84665. this.debugBox = new THREE.Mesh(boxGeo, boxMat)
  84666. this.add(this.debugBox)
  84667. }
  84668. this.debugBox.scale.copy(boundingBox.getSize(new THREE.Vector3))
  84669. this.debugBox.position.copy(boundingBox.getCenter(new THREE.Vector3)) */
  84670. }
  84671. createGeometry( radius, height, particleCount){
  84672. let geometry = new BufferGeometry();
  84673. let count , points;
  84674. if(this.positions.length>1){
  84675. const spaceDis = 0.2;//间隔距离
  84676. count = Math.ceil(this.curve.wholeLength / spaceDis) + 1;
  84677. //console.log('count', count)
  84678. points = this.curve.getSpacedPoints( count ); //得到的数量会比count多一个
  84679. count = points.length;
  84680. //得到的点不太均匀,两端容易点少。
  84681. this.getBound(points);
  84682. }else {
  84683. this.getBound(this.positions);
  84684. }
  84685. var position = new Float32Array(particleCount * 3);
  84686. var randam = new Float32Array(particleCount);
  84687. var sprite = new Float32Array(particleCount);
  84688. var centerHeight = new Float32Array(particleCount);
  84689. for (var i = 0; i < particleCount; i++) {
  84690. var center = new Vector3().copy(this.positions.length>1 ? points[Math.floor(i/particleCount * count)] : this.positions[0]);
  84691. centerHeight[i] = center.z;
  84692. if (i === 0) {
  84693. // to avoid going out of Frustum
  84694. position[i * 3 + 0] = center.x;
  84695. position[i * 3 + 1] = center.y;
  84696. position[i * 3 + 2] = center.z;
  84697. }else {
  84698. var r = Math.sqrt(Math.random()) * radius;
  84699. var angle = Math.random() * 2 * Math.PI;
  84700. position[i * 3 + 0] = center.x + Math.cos(angle) * r;
  84701. position[i * 3 + 1] = center.y + Math.sin(angle) * r;
  84702. position[i * 3 + 2] = center.z + (radius - r) / radius * height/2 + height/2; //不太明白这句为什么能达到height高度
  84703. sprite[i] = 0.25 * (Math.random() * 4 | 0);
  84704. randam[i] = Math.random();
  84705. //center在底部
  84706. }
  84707. }
  84708. geometry.setAttribute('centerHeight', new BufferAttribute(centerHeight, 1));
  84709. geometry.setAttribute('position', new BufferAttribute(position, 3));
  84710. geometry.setAttribute('randam', new BufferAttribute(randam, 1));
  84711. geometry.setAttribute('sprite', new BufferAttribute(sprite, 1));
  84712. return geometry;
  84713. }
  84714. updateGeometry(){
  84715. this.computeParams();
  84716. this.geometry.dispose();
  84717. this.geometry = this.createGeometry( this.radius, this.height, this.particleCount );
  84718. this.material.uniforms.size.value = this.size;
  84719. }
  84720. createMaterial(){
  84721. const material = new ShaderMaterial( {
  84722. uniforms:{
  84723. color: { type: "c", value: new Color(this.color) },
  84724. size: { type: "f", value: this.size},
  84725. u_sampler: { type: "t", value: getTexture() },
  84726. time: { type: "f", value: 0.0 },
  84727. heightOfNearPlane: { type: "f", value:0}, //相对far ,以确保画面缩放时点的大小也会缩放
  84728. height :{ type: "f", value:this.height} ,
  84729. },
  84730. vertexShader,
  84731. fragmentShader,
  84732. blending: AdditiveBlending, //加法融合模式 glBlendFunc(GL_ONE, GL_ONE)
  84733. depthTest: true,
  84734. depthWrite: false,
  84735. transparent: true
  84736. } );
  84737. this.material = material;
  84738. this.setPerspective(this.fov, this.screenHeight);
  84739. }
  84740. setSize(e){
  84741. let viewport = e.viewport;
  84742. this.screenHeight = viewport.resolution.y;
  84743. this.setPerspective(this.fov, this.screenHeight);
  84744. }
  84745. setFov(fov){
  84746. this.fov = fov;
  84747. this.setPerspective(this.fov, this.screenHeight);
  84748. }
  84749. setPerspective(fov, height){
  84750. //this.uniforms.heightOfNearPlane.value = Math.abs(height / (2 * Math.tan(THREE.Math.degToRad(fov * 0.5))));
  84751. let far = Math.abs(height / (2 * Math.tan(MathUtils.degToRad(fov * 0.5))));
  84752. this.material.uniforms.heightOfNearPlane.value = far;
  84753. }
  84754. update(delta){
  84755. if(!Potree.Utils.getObjVisiByReason(this,'force')){//被手动隐藏了
  84756. return
  84757. }
  84758. if(!Potree.Utils.isInsideFrustum(this.boundingBox, viewer.scene.getActiveCamera())){
  84759. Potree.Utils.updateVisible(this,'isInsideFrustum', false ); //不在视野范围
  84760. //console.log('unvi')
  84761. return
  84762. }else {
  84763. Potree.Utils.updateVisible(this,'isInsideFrustum', true );
  84764. }
  84765. delta *= 1;//更改速度
  84766. this.material.uniforms.time.value = (this.material.uniforms.time.value + delta) % 1;
  84767. viewer.dispatchEvent('content_changed');
  84768. }
  84769. dispose(){
  84770. this.geometry.dispose();
  84771. this.material.dispose();
  84772. this.dispatchEvent('dispose');
  84773. }
  84774. }
  84775. class Tween {
  84776. constructor(times, values) {
  84777. this.times = times || [];
  84778. this.values = values || [];
  84779. }
  84780. lerp(t) {
  84781. if(this.times.length == 0) return
  84782. let i = 0, n = this.times.length;
  84783. while(i < n && t > this.times[i]) i++;
  84784. if(i == 0) return this.values[0]
  84785. if(i == n) return this.values[n-1]
  84786. const ratio = (t - this.times[i-1]) / (this.times[i] - this.times[i-1]);
  84787. if(this.values[0] instanceof Vector3) {
  84788. return this.values[i-1].clone().lerp(this.values[i], ratio)
  84789. } else {
  84790. return this.values[i-1] + ratio * (this.values[i] - this.values[i-1])
  84791. }
  84792. }
  84793. clone () {
  84794. return Common.CloneClassObject(this)
  84795. }
  84796. }
  84797. class Particle$1{
  84798. constructor(prop={}){
  84799. this.position = new Vector3();
  84800. this.velocity = new Vector3(); // units per second
  84801. this.angle = 0;
  84802. this.angleVelocity = 0; // degrees per second
  84803. this.angleAcceleration = 0; // degrees per second, per second
  84804. this.size = 16.0;
  84805. this.color = new Color();
  84806. this.opacity = 1.0;
  84807. this.age = 0;
  84808. this.alive = 0; // use float instead of boolean for shader purposes
  84809. this.lastChangeVage = 0; //add
  84810. this.sizeTween = prop.sizeTween || new Tween( [0, 1], [32, 128] );
  84811. this.opacityTween = prop.opacityTween || new Tween( [0.8, 2], [0.5, 0] );
  84812. this.colorTween = prop.colorTween || new Tween( [0.4, 1], [ new Vector3(0,0,0.2), new Vector3(0, 0, 0.5) ] );
  84813. }
  84814. update(dt)
  84815. {
  84816. this.position.add(this.velocity.clone().multiplyScalar(dt));
  84817. this.velocity.multiplyScalar( 1+this.acceleration*dt );
  84818. // convert from degrees to radians: 0.01745329251 = Math.PI/180
  84819. this.angle += this.angleVelocity * 0.01745329251 * dt;
  84820. this.angleVelocity += this.angleAcceleration * 0.01745329251 * dt;
  84821. this.age += dt;
  84822. // if the tween for a given attribute is nonempty,
  84823. // then use it to update the attribute's value
  84824. if ( this.sizeTween.times.length > 0 )
  84825. this.size = this.sizeTween.lerp( this.age/this.deathAge );
  84826. if ( this.colorTween.times.length > 0 )
  84827. {
  84828. var colorHSL = this.colorTween.lerp( this.age/this.deathAge );
  84829. this.color = new Color().setHSL( colorHSL.x, colorHSL.y, colorHSL.z );
  84830. }
  84831. if ( this.opacityTween.times.length > 0 )
  84832. {
  84833. this.opacity = this.opacityTween.lerp( this.age/this.deathAge);
  84834. }
  84835. viewer.dispatchEvent('content_changed');
  84836. }
  84837. }
  84838. const vertexShader$1 = `
  84839. attribute vec3 customColor;
  84840. attribute float customOpacity;
  84841. attribute float customSize;
  84842. attribute float customAngle;
  84843. attribute float customVisible;
  84844. uniform float heightOfNearPlane;
  84845. varying vec4 vColor;
  84846. varying float vAngle;
  84847. void main()
  84848. {
  84849. if ( customVisible > 0.5 )
  84850. vColor = vec4( customColor, customOpacity );
  84851. else
  84852. vColor = vec4(0.0, 0.0, 0.0, 0.0);
  84853. vAngle = customAngle;
  84854. vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );
  84855. //gl_PointSize = customSize * ( 300.0 / length( mvPosition.xyz ) );
  84856. gl_Position = projectionMatrix * mvPosition;
  84857. gl_PointSize = ( heightOfNearPlane * customSize ) / gl_Position.w;
  84858. }
  84859. `;
  84860. const fragmentShader$1 = `
  84861. uniform sampler2D u_sampler;
  84862. varying vec4 vColor;
  84863. varying float vAngle;
  84864. void main()
  84865. {
  84866. gl_FragColor = vColor;
  84867. float c = cos(vAngle);
  84868. float s = sin(vAngle);
  84869. 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);
  84870. vec4 rotatedTexture = texture2D( u_sampler, rotatedUV );
  84871. gl_FragColor = gl_FragColor * rotatedTexture;
  84872. }
  84873. `;
  84874. const Type = Object.freeze({ "CUBE":1, "SPHERE":2 });
  84875. let particleTexture;
  84876. const getTexture$1 = ()=>{
  84877. if(!particleTexture){
  84878. particleTexture = new TextureLoader().load( Potree.resourcePath+'/textures/smokeparticle.png');
  84879. }
  84880. return particleTexture
  84881. };
  84882. const boxGeo$1 = new BoxBufferGeometry(1,1,1,1);
  84883. const boxMat$1 = new MeshBasicMaterial({wireframe:true, color:"#ffffff"});
  84884. const defaults =
  84885. {
  84886. positions: [],
  84887. positionStyle : "sphere",
  84888. positionBase : new Vector3( 0, 0, 0 ),
  84889. positionSpread : new Vector3( 1, 1, 0), //cube
  84890. radius : 1, // sphere
  84891. velocityStyle : 'cube',
  84892. velocityBase : new Vector3( 0, 0, 0.5), // cube 基础速度
  84893. velocitySpread : new Vector3( 1, 1, 0.3),
  84894. accelerationBase : 0.3, //基础加速度
  84895. accelerationSpread : 0.6,
  84896. //没使用
  84897. speedBase : 0.1, //sphere
  84898. speedSpread : 0.5,
  84899. angleBase : 0,
  84900. angleSpread : 360,
  84901. angleVelocityBase : 1,
  84902. angleVelocitySpread : 30,
  84903. angleAccelerationBase : 1,
  84904. angleAccelerationSpread : 5,
  84905. sizeBase : 0,
  84906. sizeSpread : 0,
  84907. sizeTween : [[0, 0.3, 1], [0.3, 1.4, 6 ]],
  84908. colorBase : new Vector3(0.0, 1.0, 0.5),
  84909. colorSpread : new Vector3(0.0, 0.0, 0.0),
  84910. colorTween : new Tween( [0.2, 1], [ new Vector3(0,0,0.4), new Vector3(0, 0, 0.1) ] ),
  84911. opacityBase : 0.1,//1.0,
  84912. opacitySpread : 0.2,
  84913. opacityTween :[ [0, 0.1, 0.9, 1], [0.1, 0.4 , 0.03, 0 ] ],
  84914. //particlesPerSecond : 20,
  84915. strength : 1,
  84916. particleDeathAge : 3, //从底下升起后能持续的时间
  84917. //emitterDeathAge : 60 // time (seconds) at which to stop creating particles.
  84918. height : 3,
  84919. };
  84920. const debugSphere = new Mesh(new SphereBufferGeometry(0.03, 5,5), new MeshBasicMaterial({color:'white',depthTest:false}));
  84921. class SmokeParticle extends Points{
  84922. constructor(prop={}) {
  84923. super();
  84924. this.blendStyle = NormalBlending; // false;
  84925. this.emitterAge = 0.0;
  84926. //this.emitterAlive = true;
  84927. prop = $.extend({}, defaults, prop);
  84928. for ( var key in prop ){
  84929. let value = prop[key];
  84930. if(value instanceof Array && value[0] instanceof Array ) this[ key ] = new Tween(...value);
  84931. else if(value instanceof Vector3 || value instanceof Color){
  84932. this[ key ] = value.clone();
  84933. }else {
  84934. this[ key ] = value;
  84935. }
  84936. }
  84937. this.defaultSizeTween = this.sizeTween.clone();
  84938. this.defaultOpacityTween = this.opacityTween.clone();
  84939. this.geometry = new BufferGeometry();
  84940. this.computeParams();
  84941. this.createMaterial();
  84942. this.createGeometry();
  84943. this.dynamic = true;
  84944. this.sortParticles = true;
  84945. this.frustumCulled = false;//似乎是禁止相机裁剪,否则会在某些角度消失。但是会不会更耗性能呢?
  84946. prop.position && this.position.copy(prop.position);
  84947. //---------------------------------------
  84948. this.setSize({viewport:viewer.mainViewport});
  84949. this.setFov(viewer.fov);
  84950. let setSize = (e)=>{
  84951. if(e.viewport.name != "MainView")return
  84952. this.setSize(e);
  84953. };
  84954. let setFov = (e)=>{
  84955. this.setFov(e.fov);
  84956. };
  84957. /* let reStart = (e)=>{
  84958. if(e.v){//重新一个个放出粒子,否则会一股脑儿全部出来,因为同时大于粒子周期了一起重新生成出现。
  84959. setTimeout(()=>{//会先update一次delta为pageUnvisile的时间才触发
  84960. //console.log('归零')
  84961. //this.reStart()
  84962. },1)
  84963. }
  84964. } */
  84965. viewer.addEventListener('resize',setSize);
  84966. viewer.addEventListener('fov_changed',setFov);
  84967. //viewer.addEventListener('pageVisible', reStart)
  84968. this.addEventListener('dispose',()=>{
  84969. viewer.removeEventListener('resize',setSize);
  84970. viewer.removeEventListener('fov_changed',setFov);
  84971. //viewer.removeEventListener('pageVisible', reStart)
  84972. });
  84973. }
  84974. computeParams(){
  84975. let length = (this.curve ? this.curve.wholeLength : 0) + this.radius * 2; //加上首尾的半径
  84976. //注意:烟最低高度一米, 0<strength<1
  84977. if(this.positionStyle == 'cube'){
  84978. this.positionSpread.set(this.radius,this.radius,0);
  84979. }
  84980. this.velocityBase.set(0,0, (this.height - 0.5 * this.accelerationBase * this.particleDeathAge * this.particleDeathAge) / this.particleDeathAge );
  84981. //let height = this.velocityBase.z * this.particleDeathAge + 0.5 * this.accelerationBase * this.particleDeathAge * this.particleDeathAge;//s = V0 * t + 0.5 * a * t*t ;
  84982. this.velocityBase.z = Math.max(0,this.velocityBase.z);
  84983. this.particleCount = Math.ceil( length * Math.sqrt(this.strength * this.height * this.radius ) );
  84984. this.particleCount = Math.max(5,this.particleCount);
  84985. {
  84986. const minSize = 1, maxSize = 2, minBound = 0.01, maxBound = 1;
  84987. let size = minSize + (maxSize - minSize) * MathUtils.smoothstep( this.strength, minBound, maxBound);
  84988. this.sizeTween.values = this.defaultSizeTween.values.map(e=> e*size);
  84989. }
  84990. {
  84991. const minSize = 1 , maxSize = 1.5, minBound = 0.01, maxBound = 1;
  84992. let opac = minSize + (maxSize - minSize) * MathUtils.smoothstep( this.strength, minBound, maxBound);
  84993. this.opacityTween.values = this.defaultOpacityTween.values.map(e=> e*opac );
  84994. }
  84995. //console.log('smoke particleCount',this.particleCount)
  84996. }
  84997. reStart(){
  84998. this.emitterAge = 0;
  84999. this.createGeometry();
  85000. }
  85001. updateGeometry(){
  85002. this.computeParams();
  85003. this.reStart();
  85004. }
  85005. createParticle(center)
  85006. {
  85007. var particle = new Particle$1({
  85008. sizeTween : this.sizeTween,
  85009. opacityTween : this.opacityTween,
  85010. colorTween : this.colorTween,
  85011. });
  85012. particle.deathAge = this.particleDeathAge;
  85013. particle.center = center;
  85014. if (this.positionStyle == 'cube')
  85015. particle.position = this.randomVector3( this.positionBase, this.positionSpread );
  85016. if (this.positionStyle == 'sphere')
  85017. {
  85018. /* var z = 2 * Math.random() - 1
  85019. var t = Math.PI * 2 * Math.random();
  85020. var r = Math.sqrt( 1 - z*z ) ;
  85021. var vec3 = new THREE.Vector3( r * Math.cos(t), r * Math.sin(t), z );
  85022. particle.position = new THREE.Vector3().addVectors( this.positionBase, vec3.multiplyScalar( this.radius ) );
  85023. */
  85024. //怎么改半径
  85025. let y = 2 * Math.random() - 1;
  85026. let t = Math.PI * 2 * Math.random();
  85027. let r = Math.sqrt( 1 - y*y ) ; //因为 r*r = 1-y*y = x*x + z*z = r*r(cos^2 + sin^2 );
  85028. let lowDownRatio = 0.2; //压低近平面
  85029. let vec3 = new Vector3( r * Math.cos(t), y, Math.abs(r * Math.sin(t) ) * lowDownRatio);
  85030. particle.position = new Vector3().addVectors( this.positionBase, vec3.multiplyScalar( this.radius ) );
  85031. }
  85032. particle.position.add(center);//add
  85033. if ( this.velocityStyle == 'cube' )
  85034. {
  85035. particle.velocity = this.randomVector3( this.velocityBase, this.velocitySpread );
  85036. }
  85037. if ( this.velocityStyle == 'sphere' )
  85038. {
  85039. //var direction = particle.position.clone()
  85040. var direction = new Vector3(0,0,1); //烟应该都是向上的
  85041. var speed = this.randomValue( this.speedBase, this.speedSpread );
  85042. particle.velocity = direction.normalize().multiplyScalar( speed );
  85043. }
  85044. particle.acceleration = this.randomValue( this.accelerationBase, this.accelerationSpread );
  85045. particle.angle = this.randomValue( this.angleBase, this.angleSpread );
  85046. particle.angleVelocity = this.randomValue( this.angleVelocityBase, this.angleVelocitySpread );
  85047. particle.angleAcceleration = this.randomValue( this.angleAccelerationBase, this.angleAccelerationSpread );
  85048. particle.size = this.randomValue( this.sizeBase, this.sizeSpread );
  85049. var color = this.randomVector3( this.colorBase, this.colorSpread );
  85050. particle.color = new Color().setHSL( color.x, color.y, color.z );
  85051. particle.opacity = this.randomValue( this.opacityBase, this.opacitySpread );
  85052. particle.age = 0;
  85053. particle.alive = 0; // particles initialize as inactive
  85054. return particle;
  85055. }
  85056. getPointsForBound(){
  85057. return this.boundPoints; //可以用于expand实时bound的点, 不含particle的size等边距
  85058. }
  85059. getBound(points){ // points为生成点(圆心)
  85060. this.boundPoints = [];
  85061. let boundingBox = new Box3();
  85062. let maxSize = this.sizeTween.values.slice().sort((a,b)=>b-a)[0];
  85063. let margin0 = maxSize * 0.11;
  85064. let margin1 = margin0 + 0.5 ;//保守估计还会飘出这么多距离吧: size + 飘动
  85065. points.forEach(bottom=>{
  85066. let top = bottom.clone();
  85067. top.z += this.height;
  85068. boundingBox.expandByPoint(bottom);
  85069. boundingBox.expandByPoint(top);
  85070. this.boundPoints.push(bottom,top);
  85071. });
  85072. let xyExpand = this.radius+margin1;
  85073. boundingBox.expandByVector(new Vector3(xyExpand,xyExpand,0));
  85074. boundingBox.min.z -= margin0;
  85075. boundingBox.max.z += margin1;
  85076. this.boundingBox = boundingBox;
  85077. /* if(!this.debugBox){
  85078. this.debugBox = new THREE.Mesh(boxGeo, boxMat)
  85079. this.add(this.debugBox)
  85080. }
  85081. this.debugBox.scale.copy(boundingBox.getSize(new THREE.Vector3))
  85082. this.debugBox.position.copy(boundingBox.getCenter(new THREE.Vector3)) */
  85083. }
  85084. createGeometry(){
  85085. this.particleArray = [];
  85086. const positions = [];
  85087. const colors = [];
  85088. const alives = [];
  85089. const opacitys = [];
  85090. const sizes = [];
  85091. const angles = [];
  85092. let count, points;
  85093. if(this.positions.length>1){
  85094. const spaceDis = 0.6;//间隔距离
  85095. count = Math.ceil(this.curve.wholeLength / spaceDis) + 1;
  85096. points = this.curve.getSpacedPoints( count );
  85097. count = points.length;
  85098. /* points.forEach(e=> {
  85099. var sphere = debugSphere.clone();
  85100. sphere.position.copy(e)
  85101. viewer.scene.scene.add(sphere)
  85102. }) */
  85103. let haventGetPoints = points.slice();
  85104. var getRanPoints = function(i){
  85105. var a = Math.random();
  85106. let choseIndex = Math.floor(haventGetPoints.length * a);
  85107. var point = haventGetPoints[choseIndex];
  85108. if(haventGetPoints.length == 1){
  85109. haventGetPoints = points.slice();
  85110. }else {
  85111. haventGetPoints.splice(choseIndex, 1);
  85112. }
  85113. return point
  85114. };
  85115. this.getBound(points);
  85116. }else {
  85117. this.getBound(this.positions);
  85118. }
  85119. for (var i = 0; i < this.particleCount; i++)
  85120. {
  85121. var center = new Vector3().copy(this.positions.length>1 ? getRanPoints(i) : this.positions[0]);
  85122. //var center = new THREE.Vector3().copy(this.positions.length>1 ? points[Math.floor(i/this.particleCount * count)] : this.positions[0])
  85123. // remove duplicate code somehow, here and in update function below.
  85124. this.particleArray[i] = this.createParticle(center);
  85125. positions[3*i] = this.particleArray[i].position.x;
  85126. positions[3*i+1] = this.particleArray[i].position.y;
  85127. positions[3*i+2] = this.particleArray[i].position.z;
  85128. colors[3*i] = this.particleArray[i].color.r;
  85129. colors[3*i+1] = this.particleArray[i].color.g;
  85130. colors[3*i+2] = this.particleArray[i].color.b;
  85131. alives[i] = this.particleArray[i].alive;
  85132. opacitys[i] = this.particleArray[i].opacity;
  85133. sizes[i] = this.particleArray[i].size;
  85134. angles[i] = this.particleArray[i].angle;
  85135. }
  85136. this.geometry.setAttribute( 'position', new BufferAttribute( new Float32Array(positions), 3 ));
  85137. this.geometry.setAttribute( 'customColor', new BufferAttribute( new Float32Array(colors), 3 ) );
  85138. this.geometry.setAttribute( 'customVisible', new BufferAttribute( new Float32Array(alives), 1 ) );
  85139. this.geometry.setAttribute( 'customOpacity', new BufferAttribute( new Float32Array(opacitys), 1 ) );
  85140. this.geometry.setAttribute( 'customSize', new BufferAttribute( new Float32Array(sizes), 1 ) );
  85141. this.geometry.setAttribute( 'customAngle', new BufferAttribute( new Float32Array(angles), 1 ) );
  85142. }
  85143. createMaterial(){
  85144. this.material = new ShaderMaterial(
  85145. {
  85146. uniforms:
  85147. {
  85148. u_sampler: { type: "t", value: getTexture$1() },
  85149. heightOfNearPlane: { type: "f", value:0} //相对far ,以确保画面缩放时点的大小也会缩放
  85150. },
  85151. vertexShader: vertexShader$1,vertexShader: vertexShader$1,
  85152. fragmentShader: fragmentShader$1,
  85153. transparent: true,
  85154. alphaTest: 0.5, // if having transparency issues, try including: alphaTest: 0.5,
  85155. blending: this.blendStyle,
  85156. depthTest: this.blendStyle != NormalBlending
  85157. });
  85158. this.setPerspective(this.fov, this.screenHeight);
  85159. }
  85160. update(dt){
  85161. if(!Potree.Utils.getObjVisiByReason(this,'force')){//被手动隐藏了
  85162. return
  85163. }
  85164. if(!Potree.Utils.isInsideFrustum(this.boundingBox, viewer.scene.getActiveCamera())){
  85165. Potree.Utils.updateVisible(this,'isInsideFrustum', false ); //不在视野范围
  85166. //console.log('unvi')
  85167. return
  85168. }else {
  85169. Potree.Utils.updateVisible(this,'isInsideFrustum', true );
  85170. }
  85171. if(dt > 1){
  85172. console.log('update dt>1', dt);
  85173. }
  85174. //dt *= 0.5;
  85175. const recycleIndices = [];
  85176. const recycleAges = [];
  85177. const positions = [];
  85178. const colors = [];
  85179. const alives = [];
  85180. const opacitys = [];
  85181. const sizes = [];
  85182. const angles = [];
  85183. for (var i = 0; i < this.particleCount; i++)
  85184. {
  85185. if ( this.particleArray[i].alive )
  85186. {
  85187. if ( this.velocityStyle == 'cube' )
  85188. { //一定几率改变下方向
  85189. let ratio = Math.random();
  85190. if(this.particleArray[i].age - this.particleArray[i].lastChangeVage > this.particleDeathAge*ratio ){
  85191. this.particleArray[i].velocity = this.randomVector3( this.velocityBase, this.velocitySpread );
  85192. this.particleArray[i].lastChangeVage = this.particleArray[i].age;
  85193. }
  85194. }else {
  85195. /* if(this.particleArray[i].age - this.particleArray[i].lastChangeVage > this.particleDeathAge*0.3 ){
  85196. if( Math.random()>0.1){//一定几率改变下方向
  85197. var speed = this.randomValue( this.speedBase, this.speedSpread );
  85198. this.particleArray[i].velocity = this.randomVector3( new THREE.Vector3, new THREE.Vector3(1,1,1) );
  85199. this.particleArray[i].velocity.normalize().multiplyScalar( speed );
  85200. }
  85201. this.particleArray[i].lastChangeVage = this.particleArray[i].age
  85202. } */
  85203. }
  85204. this.particleArray[i].update(dt);
  85205. // check if particle should expire
  85206. // could also use: death by size<0 or alpha<0.
  85207. if ( this.particleArray[i].age > this.particleDeathAge )
  85208. {
  85209. this.particleArray[i].alive = 0.0;
  85210. recycleIndices.push(i);
  85211. recycleAges.push((this.particleArray[i].age - this.particleDeathAge)%(this.particleDeathAge ));
  85212. }
  85213. // update particle properties in shader
  85214. positions[3*i] = this.particleArray[i].position.x;
  85215. positions[3*i+1] = this.particleArray[i].position.y;
  85216. positions[3*i+2] = this.particleArray[i].position.z;
  85217. colors[3*i] = this.particleArray[i].color.r;
  85218. colors[3*i+1] = this.particleArray[i].color.g;
  85219. colors[3*i+2] = this.particleArray[i].color.b;
  85220. alives[i] = this.particleArray[i].alive;
  85221. opacitys[i] = this.particleArray[i].opacity;
  85222. sizes[i] = this.particleArray[i].size;
  85223. angles[i] = this.particleArray[i].angle;
  85224. }
  85225. }
  85226. // check if particle emitter is still running
  85227. //if ( !this.emitterAlive ) return;
  85228. this.geometry.setAttribute( 'position', new BufferAttribute( new Float32Array(positions), 3 ) );
  85229. this.geometry.setAttribute( 'customColor', new BufferAttribute( new Float32Array(colors), 3 ) );
  85230. this.geometry.setAttribute( 'customVisible', new BufferAttribute( new Float32Array(alives), 1 ) );
  85231. this.geometry.setAttribute( 'customOpacity', new BufferAttribute( new Float32Array(opacitys), 1 ) );
  85232. this.geometry.setAttribute( 'customSize', new BufferAttribute( new Float32Array(sizes), 1 ) );
  85233. this.geometry.setAttribute( 'customAngle', new BufferAttribute( new Float32Array(angles), 1 ) );
  85234. this.geometry.attributes.customColor.needsUpdate = true;
  85235. this.geometry.attributes.customVisible.needsUpdate = true;
  85236. this.geometry.attributes.customOpacity.needsUpdate = true;
  85237. this.geometry.attributes.customSize.needsUpdate = true;
  85238. this.geometry.attributes.customAngle.needsUpdate = true;
  85239. // if no particles have died yet, then there are still particles to activate
  85240. if ( this.emitterAge < this.particleDeathAge ) //开始时一个个放出来
  85241. {
  85242. let particlesPerSecond = this.particleCount / this.particleDeathAge;
  85243. // determine indices of particles to activate
  85244. var startIndex = Math.round( particlesPerSecond * (this.emitterAge + 0) );
  85245. var endIndex = Math.round( particlesPerSecond * (this.emitterAge + dt) );
  85246. if ( endIndex > this.particleCount )
  85247. endIndex = this.particleCount;
  85248. for (var i = startIndex; i < endIndex; i++)
  85249. this.particleArray[i].alive = 1.0;
  85250. }
  85251. // if any particles have died while the emitter is still running, we imediately recycle them
  85252. for (var j = 0; j < recycleIndices.length; j++)
  85253. {
  85254. var i = recycleIndices[j];
  85255. this.particleArray[i] = this.createParticle(this.particleArray[i].center);
  85256. this.particleArray[i].alive = 1.0; // activate right away
  85257. this.particleArray[i].age = recycleAges[j];
  85258. positions[3*i] = this.particleArray[i].position.x;
  85259. positions[3*i+1] = this.particleArray[i].position.y;
  85260. positions[3*i+2] = this.particleArray[i].position.z;
  85261. }
  85262. this.geometry.setAttribute( 'position', new BufferAttribute( new Float32Array(positions), 3 ) );
  85263. this.geometry.attributes.position.needsUpdate = true;
  85264. // stop emitter?
  85265. this.emitterAge += dt;
  85266. //if ( this.emitterAge > this.emitterDeathAge ) this.emitterAlive = false;
  85267. }
  85268. randomValue(base, spread)
  85269. {
  85270. //return base + spread * (Math.random() - 0.5);
  85271. let p = Math.random();
  85272. return base * p + spread * (1-p)
  85273. }
  85274. randomVector3(base, spread)
  85275. {
  85276. var rand3 = new Vector3( Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5 );
  85277. return new Vector3().addVectors( base, new Vector3().multiplyVectors( spread, rand3 ) );
  85278. }
  85279. setSize(e){
  85280. let viewport = e.viewport;
  85281. this.screenHeight = viewport.resolution.y;
  85282. this.setPerspective(this.fov, this.screenHeight);
  85283. }
  85284. setFov(fov){
  85285. this.fov = fov;
  85286. this.setPerspective(this.fov, this.screenHeight);
  85287. }
  85288. setPerspective(fov, height){
  85289. //this.uniforms.heightOfNearPlane.value = Math.abs(height / (2 * Math.tan(THREE.Math.degToRad(fov * 0.5))));
  85290. let far = Math.abs(height / (2 * Math.tan(MathUtils.degToRad(fov * 0.5))));
  85291. this.material.uniforms.heightOfNearPlane.value = far;
  85292. }
  85293. dispose(){
  85294. this.geometry.dispose();
  85295. this.material.dispose();
  85296. this.dispatchEvent('dispose');
  85297. }
  85298. }
  85299. /*
  85300. 改进:如果有必要
  85301. 根据curve中分成的点,分成多个簇,每个簇掌管该部分的可见性和particle的数量。
  85302. 在camera_changed时根据远近修改每个簇的particle的数量,当然不会大于初始创建的个数。多出的随机隐藏。
  85303. */
  85304. const vertexShader$2 = `
  85305. attribute vec3 color;
  85306. attribute float size;
  85307. attribute float angle;
  85308. attribute float opacity;
  85309. attribute float visible;
  85310. varying vec4 vColor;
  85311. varying float vAngle;
  85312. uniform float heightOfNearPlane;
  85313. void main() {
  85314. if(visible > 0.5) {
  85315. vColor = vec4(color, opacity);
  85316. } else {
  85317. vColor = vec4(0.0, 0.0, 0.0, 0.0);
  85318. }
  85319. vAngle = angle;
  85320. vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
  85321. gl_Position = projectionMatrix * mvPosition;
  85322. gl_PointSize = ( heightOfNearPlane * size ) / gl_Position.w;
  85323. }
  85324. `;
  85325. const fragmentShader$2 = `
  85326. uniform sampler2D u_sampler;
  85327. varying vec4 vColor;
  85328. varying float vAngle;
  85329. void main() {
  85330. gl_FragColor = vColor;
  85331. float u = cos(vAngle);
  85332. float v = sin(vAngle);
  85333. vec2 uv = vec2(
  85334. u * (gl_PointCoord.x - 0.5) + v * (gl_PointCoord.y - 0.5) + 0.5,
  85335. u * (gl_PointCoord.y - 0.5) - v * (gl_PointCoord.x - 0.5) + 0.5
  85336. );
  85337. vec4 texture = texture2D(u_sampler, uv);
  85338. gl_FragColor = gl_FragColor * texture;
  85339. }
  85340. `;
  85341. // import { vertexShader, fragmentShader } from './shader'
  85342. const DEG2RAD = Math.PI / 180;
  85343. class Particle$2 {
  85344. constructor() {
  85345. this.position = new Vector3();
  85346. this.velocity = new Vector3();
  85347. this.angle = 0;
  85348. this.angleVelocity = 0;
  85349. this.angleAcceleration = 0;
  85350. this.size = 16;
  85351. this.color = new Color();
  85352. this.opacity = 1;
  85353. this.rebornCount = 0;//重生次数
  85354. this.age = 0;
  85355. this.alive = 0; //注意,一开始时是未出生的
  85356. this.deadAge = 0;//已死亡时间
  85357. this.sizeTween = null;
  85358. this.colorTween = null;
  85359. this.opacityTween = null;
  85360. }
  85361. update(dt) {
  85362. //s = s0 + (v0 + at) * t 或 lastS + delta(vt)
  85363. this.position.add(this.velocity.clone().multiplyScalar(dt));
  85364. this.velocity.multiplyScalar( 1+this.acceleration*dt );
  85365. this.angle += this.angleVelocity * DEG2RAD * dt;
  85366. this.angleVelocity += this.angleAcceleration * DEG2RAD * dt;
  85367. this.age += dt;
  85368. if(this.sizeTween.times.length > 0) {
  85369. this.size = this.sizeTween.lerp(this.age/this.deathAge);
  85370. }
  85371. if(this.colorTween.times.length > 0) {
  85372. const colorHSL = this.colorTween.lerp(this.age/this.deathAge);
  85373. this.color = new Color().setHSL(colorHSL.x, colorHSL.y, colorHSL.z);
  85374. }
  85375. if(this.opacityTween.times.length > 0) {
  85376. this.opacity = this.opacityTween.lerp(this.age/this.deathAge);
  85377. }
  85378. viewer.dispatchEvent('content_changed');
  85379. }
  85380. }
  85381. class Util {
  85382. constructor() {}
  85383. randomValue(min, max) {
  85384. //return min + max * (Math.random() - 0.5)
  85385. let p = Math.random();
  85386. return min * p + max * (1-p)
  85387. }
  85388. randomVector3(min, max) {
  85389. const rand3 = new Vector3(Math.random() - 0.5, Math.random() - 0.5, Math.random() - 0.5);
  85390. return new Vector3().addVectors(min, new Vector3().multiplyVectors(max, rand3))
  85391. }
  85392. }
  85393. const util$1 = new Util();
  85394. const Shape$1 = {
  85395. CUBE: 1,
  85396. SPHERE: 2
  85397. };
  85398. let particleTexture$1;
  85399. const getTexture$2 = ()=>{
  85400. if (!particleTexture$1) {
  85401. particleTexture$1 = new TextureLoader().load(Potree.resourcePath + '/textures/explode.png');
  85402. }
  85403. return particleTexture$1
  85404. };
  85405. const sphereGeo = new SphereBufferGeometry(1, 10,4);
  85406. const sphereMat = new MeshBasicMaterial({wireframe:true, color:"#ffffff"});
  85407. const defaults$1 = {
  85408. position: new Vector3(0,0,1),
  85409. positionShape: Shape$1.SPHERE,
  85410. positionRange: new Vector3(1,1,1),
  85411. //cube
  85412. radius: 1.3,
  85413. //sphere
  85414. velocityShape: Shape$1.SPHERE,
  85415. velocity: new Vector3(0,0,2),
  85416. //cube
  85417. velocityRange: new Vector3(0,0,3),
  85418. //sphere
  85419. speed: 0.4,
  85420. speedRange: 1,
  85421. size: 0.4,
  85422. sizeRange: 2,
  85423. //sizeTween: new Tween( [0, 0.05, 0.3, 0.45], [0, 1, 3, 0.1] ),
  85424. sizeTween: [[0, 0.04, 0.2, 1],[0.1, 1, 6, 8]] ,
  85425. color: new Vector3(1.0,1.0,1.0),
  85426. colorRange: new Vector3(0,0,0),
  85427. colorTween: new Tween(),
  85428. opacity: 1.0,
  85429. opacityRange: 0.0,
  85430. opacityTween: new Tween([0, 0.06, 0.3, 0.8, 1],[0, 1, 0.3, 0.05, 0]),
  85431. blendMode: AdditiveBlending,
  85432. acceleration: 0.5,
  85433. accelerationRange: 0,
  85434. angle: 0,
  85435. angleRange: 0,
  85436. angleVelocity: 0,
  85437. angleVelocityRange: 0,
  85438. angleAcceleration: 0,
  85439. angleAccelerationRange: 0,
  85440. strength:1,
  85441. //particlesPerSecond: 8,
  85442. particleDeathAge: 0.7 ,
  85443. recycleTimes : 3 , //每个粒子在一次爆炸后循环次数,循环完毕进入particleSpaceTime,等待下一次爆炸.
  85444. //爆炸时长: particleDeathAge * (recycleTimes+1)
  85445. particleSpaceTime: 3, //间隔
  85446. };
  85447. class ExplodeParticle extends Points {
  85448. constructor(params) {
  85449. super();
  85450. this.age = 0;
  85451. this.alive = true;
  85452. //this.deathAge = 60
  85453. this.loop = true;
  85454. this.blendMode = NormalBlending;
  85455. this.setParameters(params);
  85456. this.createParticles();
  85457. this.frustumCulled = false;//似乎是禁止相机裁剪,否则会在某些角度消失。但是会不会更耗性能呢?
  85458. //------------------------------------
  85459. this.setSize({viewport:viewer.mainViewport});
  85460. this.setFov(viewer.fov);
  85461. let setSize = (e)=>{
  85462. if(e.viewport.name != "MainView")return
  85463. this.setSize(e);
  85464. };
  85465. let setFov = (e)=>{
  85466. this.setFov(e.fov);
  85467. };
  85468. /* let reStart = (e)=>{
  85469. if(e.v){//重新一个个放出粒子,否则会一股脑儿全部出来,因为同时大于粒子周期了一起重新生成出现。
  85470. setTimeout(()=>{//会先update一次delta为pageUnvisile的时间才触发
  85471. //console.log('归零')
  85472. //this.reStart()
  85473. },1)
  85474. }
  85475. } */
  85476. viewer.addEventListener('resize',setSize);
  85477. viewer.addEventListener('fov_changed',setFov);
  85478. //viewer.addEventListener('pageVisible', reStart)
  85479. this.addEventListener('dispose',()=>{
  85480. viewer.removeEventListener('resize',setSize);
  85481. viewer.removeEventListener('fov_changed',setFov);
  85482. //viewer.removeEventListener('pageVisible', reStart)
  85483. });
  85484. }
  85485. computeParams(){
  85486. if(this.curve){
  85487. this.position.copy(this.curve.points[0]);
  85488. }
  85489. const minSize = 0.8, maxSize = 10, minRadiusBound = 0.2, maxRadiusBound = 20;
  85490. let size = minSize + (maxSize - minSize) * MathUtils.smoothstep(this.radius*this.strength , minRadiusBound, maxRadiusBound);
  85491. this.sizeTween.values = this.defaultSizeTween.values.map(e=> e*size);
  85492. this.particleCount = Math.ceil( this.strength * this.radius * 5 /* * this.radius * this.radius */ );
  85493. this.speed = defaults$1.speed * this.radius;
  85494. this.speedRange = defaults$1.speedRange * this.radius;
  85495. console.log(this.particleCount);
  85496. {
  85497. this.boundPoints = [];
  85498. this.boundPoints.push(this.position.clone());
  85499. let maxSize = this.sizeTween.values.slice().sort((a,b)=>b-a)[0];
  85500. let margin = maxSize * 0.35 + 0.5;
  85501. let scale = this.radius+margin;
  85502. let sphere = new Sphere(this.position, scale);//加上防止剪裁
  85503. this.boundingSphere = sphere; //虽然还是会有一些后续移动的会超出
  85504. this.boundingBox = new Box3().setFromCenterAndSize(this.position, new Vector3(scale*2,scale*2,scale*2));
  85505. /* if(!this.debugSphere){
  85506. this.debugSphere = new THREE.Mesh(sphereGeo, sphereMat)
  85507. this.add(this.debugSphere)
  85508. }
  85509. this.debugSphere.scale.set(scale,scale,scale) */
  85510. }
  85511. }
  85512. getPointsForBound(){
  85513. return this.boundPoints; //可以用于expand实时bound的点, 不含particle的size等边距
  85514. }
  85515. reStart(){
  85516. this.age = 0;
  85517. this.createParticles();
  85518. }
  85519. setParameters(params) {
  85520. params = $.extend({}, defaults$1, params);
  85521. for (var key in params) {
  85522. let value = params[key];
  85523. if (key == 'position')
  85524. this.position.copy(value);
  85525. else if (value instanceof Array && value[0]instanceof Array){
  85526. this[key] = new Tween(...value);
  85527. }else if(value instanceof Vector3 || value instanceof Color){
  85528. this[ key ] = value.clone();
  85529. }else {
  85530. this[key] = value;
  85531. }
  85532. }
  85533. this.defaultSizeTween = this.sizeTween.clone();
  85534. //Object.assign(this, params)
  85535. this.particles = [];
  85536. this.age = 0.0;
  85537. this.alive = true;
  85538. this.geometry = new BufferGeometry();
  85539. this.computeParams();
  85540. this.material = new ShaderMaterial({
  85541. uniforms: {
  85542. u_sampler: {
  85543. value: this.texture || getTexture$2()
  85544. },
  85545. heightOfNearPlane: {
  85546. type: "f",
  85547. value: 0
  85548. }//相对far ,以确保画面缩放时点的大小也会缩放
  85549. },
  85550. vertexShader: vertexShader$2,
  85551. fragmentShader: fragmentShader$2,
  85552. transparent: true,
  85553. alphaTest: 0.5,
  85554. depthTest: this.blendMode == NormalBlending,
  85555. blending: this.blendMode
  85556. });
  85557. }
  85558. createParticles() {
  85559. this.particles = [];
  85560. const count = this.particleCount;
  85561. const positionArray = new Float32Array(count * 3);
  85562. const colorArray = new Float32Array(count * 3);
  85563. const sizeArray = new Float32Array(count);
  85564. const angleArray = new Float32Array(count);
  85565. const opacityArray = new Float32Array(count);
  85566. const visibleArray = new Float32Array(count);
  85567. for (let i = 0; i < count; i++) {
  85568. const particle = this.createParticle();
  85569. /* positionArray[i * 3] = particle.position.x
  85570. positionArray[i * 3 + 1] = particle.position.y
  85571. positionArray[i * 3 + 2] = particle.position.z
  85572. colorArray[i * 3] = particle.color.r
  85573. colorArray[i * 3 + 1] = particle.color.g
  85574. colorArray[i * 3 + 2] = particle.color.b
  85575. sizeArray[i] = particle.size
  85576. angleArray[i] = particle.angel
  85577. opacityArray[i] = particle.opacity
  85578. visibleArray[i] = particle.alive */
  85579. this.particles[i] = particle;
  85580. }
  85581. this.geometry.setAttribute('position', new BufferAttribute(positionArray,3));
  85582. this.geometry.setAttribute('color', new BufferAttribute(colorArray,3));
  85583. this.geometry.setAttribute('angle', new BufferAttribute(angleArray,1));
  85584. this.geometry.setAttribute('size', new BufferAttribute(sizeArray,1));
  85585. this.geometry.setAttribute('visible', new BufferAttribute(visibleArray,1));
  85586. this.geometry.setAttribute('opacity', new BufferAttribute(opacityArray,1));
  85587. }
  85588. createParticle() {
  85589. const particle = new Particle$2();
  85590. particle.sizeTween = this.sizeTween;
  85591. particle.colorTween = this.colorTween;
  85592. particle.opacityTween = this.opacityTween;
  85593. particle.deathAge = this.particleDeathAge;
  85594. if (this.positionShape == Shape$1.CUBE) {
  85595. particle.position = util$1.randomVector3(new Vector3, this.positionRange);
  85596. }
  85597. if (this.positionShape == Shape$1.SPHERE) {
  85598. /* const z = 2 * Math.random() - 1
  85599. const t = Math.PI * 2 * Math.random()
  85600. const r = Math.sqrt(1 - z*z)
  85601. const vec3 = new THREE.Vector3(r * Math.cos(t), r * Math.sin(t), z)
  85602. particle.position = vec3.multiplyScalar(this.radius) */
  85603. const y = 2 * Math.random() - 1;
  85604. const t = Math.PI * 2 * Math.random();
  85605. const r = Math.sqrt(1 - y * y);
  85606. const vec3 = new Vector3(r * Math.cos(t),y,r * Math.sin(t));
  85607. particle.position = vec3.multiplyScalar(this.radius);
  85608. }
  85609. if (this.velocityShape == Shape$1.CUBE) {
  85610. particle.velocity = util$1.randomVector3(this.velocity, this.velocityRange);
  85611. }
  85612. if (this.velocityShape == Shape$1.SPHERE) {
  85613. const direction = new Vector3().addVectors(particle.position, new Vector3(0,0,this.radius*2));//向上升?
  85614. const speed = util$1.randomValue(this.speed, this.speedRange);
  85615. particle.velocity = direction.normalize().multiplyScalar(speed);
  85616. }
  85617. particle.acceleration = util$1.randomValue(this.acceleration, this.accelerationRange);
  85618. particle.angle = util$1.randomValue(this.angle, this.angleRange);
  85619. particle.angleVelocity = util$1.randomValue(this.angleVelocity, this.angleVelocityRange);
  85620. particle.angleAcceleration = util$1.randomValue(this.angleAcceleration, this.angleAccelerationRange);
  85621. particle.size = util$1.randomValue(this.size, this.sizeRange);
  85622. const color = util$1.randomVector3(this.color, this.colorRange);
  85623. particle.color = new Color().setHSL(color.x, color.y, color.z);
  85624. particle.opacity = util$1.randomValue(this.opacity, this.opacityRange);
  85625. return particle
  85626. }
  85627. update(dt) {
  85628. if(!Potree.Utils.getObjVisiByReason(this,'force')){//被手动隐藏了
  85629. return
  85630. }
  85631. if(this.delayStartTime>0){ // 爆炸延迟
  85632. return this.delayStartTime -= dt
  85633. }
  85634. if(!Potree.Utils.isInsideFrustum(this.boundingSphere, viewer.scene.getActiveCamera())){
  85635. Potree.Utils.updateVisible(this,'isInsideFrustum', false ); //不在视野范围
  85636. return
  85637. }else {
  85638. Potree.Utils.updateVisible(this,'isInsideFrustum', true );
  85639. }
  85640. //const timeRatio = 0.5
  85641. if(dt > 1){
  85642. console.log('update dt>1', dt);
  85643. }
  85644. //dt *= timeRatio
  85645. let particleDeathAge = this.particleDeathAge;/* * timeRatio */
  85646. let particleSpaceTime = this.particleSpaceTime; /* * timeRatio */
  85647. const recycleIndices = [];
  85648. const recycleAges = [];
  85649. const recycleRebornCount = [];
  85650. const positionArray = this.geometry.attributes.position.array;
  85651. const opacityArray = this.geometry.attributes.opacity.array;
  85652. const visibleArray = this.geometry.attributes.visible.array;
  85653. const colorArray = this.geometry.attributes.color.array;
  85654. const angleArray = this.geometry.attributes.angle.array;
  85655. const sizeArray = this.geometry.attributes.size.array;
  85656. for (let i = 0; i < this.particleCount; i++) {
  85657. const particle = this.particles[i];
  85658. if (particle.alive) {
  85659. particle.update(dt);
  85660. if (particle.age > particleDeathAge) {
  85661. particle.alive = 0.0;
  85662. if(particle.rebornCount >= this.recycleTimes){
  85663. particle.deadAge = particle.age - particleDeathAge; //已死亡时间
  85664. }else {//直接循环
  85665. recycleIndices.push(i);
  85666. recycleAges.push(/* ( */particle.age - particleDeathAge/* )%(this.particleDeathAge ) */);
  85667. recycleRebornCount.push(particle.rebornCount+1);
  85668. }
  85669. }
  85670. positionArray[i * 3] = particle.position.x;
  85671. positionArray[i * 3 + 1] = particle.position.y;
  85672. positionArray[i * 3 + 2] = particle.position.z;
  85673. colorArray[i * 3] = particle.color.r;
  85674. colorArray[i * 3 + 1] = particle.color.g;
  85675. colorArray[i * 3 + 2] = particle.color.b;
  85676. visibleArray[i] = particle.alive;
  85677. opacityArray[i] = particle.opacity;
  85678. angleArray[i] = particle.angle;
  85679. sizeArray[i] = particle.size;
  85680. }else {
  85681. if(particle.rebornCount >= this.recycleTimes){
  85682. if(particle.age > particleDeathAge) {//其他已经死亡的粒子的时间继续增加
  85683. particle.deadAge += dt;
  85684. }
  85685. }
  85686. }
  85687. if (particle.rebornCount >= this.recycleTimes && particle.age > particleDeathAge) {//已经死亡
  85688. if(particle.deadAge >= particleSpaceTime){//死亡时间超过设定的间隔时间后重启
  85689. recycleIndices.push(i);
  85690. let wholeTime = particleDeathAge * (this.recycleTimes+1) + particleSpaceTime;
  85691. recycleAges.push((particle.deadAge - particleSpaceTime)% wholeTime ); //剩余时间就是重生后的age
  85692. recycleRebornCount.push(0);
  85693. }
  85694. }
  85695. }
  85696. this.geometry.attributes.size.needsUpdate = true;
  85697. this.geometry.attributes.color.needsUpdate = true;
  85698. this.geometry.attributes.angle.needsUpdate = true;
  85699. this.geometry.attributes.visible.needsUpdate = true;
  85700. this.geometry.attributes.opacity.needsUpdate = true;
  85701. this.geometry.attributes.position.needsUpdate = true;
  85702. if (!this.alive)
  85703. return
  85704. if (this.age < particleDeathAge) {
  85705. let startIndex = Math.round(this.particleCount * (this.age + 0)/ particleDeathAge);
  85706. let endIndex = Math.round(this.particleCount * (this.age + dt)/ particleDeathAge);
  85707. if (endIndex > this.particleCount) {
  85708. endIndex = this.particleCount;
  85709. }
  85710. for (let i = startIndex; i < endIndex; i++) {
  85711. this.particles[i].alive = 1.0;
  85712. }
  85713. }
  85714. for (let j = 0; j < recycleIndices.length; j++) {
  85715. let i = recycleIndices[j];
  85716. this.particles[i] = this.createParticle();
  85717. this.particles[i].alive = 1.0; //出生
  85718. this.particles[i].age = recycleAges[j];
  85719. this.particles[i].rebornCount= recycleRebornCount[j];
  85720. /* if(this.particles[i].age < particleDeathAge){
  85721. positionArray[i * 3] = this.particles[i].position.x
  85722. positionArray[i * 3 + 1] = this.particles[i].position.y
  85723. positionArray[i * 3 + 2] = this.particles[i].position.z
  85724. visibleArray[i] = particle.alive?
  85725. } */
  85726. }
  85727. this.geometry.attributes.position.needsUpdate = true;
  85728. this.age += dt;
  85729. if (this.age > this.deathAge && !this.loop) {
  85730. this.alive = false;
  85731. }
  85732. }
  85733. setSize(e) {
  85734. let viewport = e.viewport;
  85735. this.screenHeight = viewport.resolution.y;
  85736. this.setPerspective(this.fov, this.screenHeight);
  85737. }
  85738. setFov(fov) {
  85739. this.fov = fov;
  85740. this.setPerspective(this.fov, this.screenHeight);
  85741. }
  85742. setPerspective(fov, height) {
  85743. //this.uniforms.heightOfNearPlane.value = Math.abs(height / (2 * Math.tan(THREE.Math.degToRad(fov * 0.5))));
  85744. let far = Math.abs(height / (2 * Math.tan(MathUtils.degToRad(fov * 0.5))));
  85745. this.material.uniforms.heightOfNearPlane.value = far;
  85746. }
  85747. updateGeometry(){
  85748. this.computeParams();
  85749. this.reStart();
  85750. }
  85751. dispose(){
  85752. this.geometry.dispose();
  85753. this.material.dispose();
  85754. this.dispatchEvent('dispose');
  85755. }
  85756. }
  85757. const colors$2 = {
  85758. 'fire+smoke':0xffffff,
  85759. 'smoke': 0xffffff,
  85760. 'explode':0xffffff,
  85761. };
  85762. let depthMatPrefix = {
  85763. clipDistance : 100, occlusionDistance:60, /* 变为backColor距离 */
  85764. maxClipFactor:0.5, backColor:"#777" ,
  85765. useDepth:true, transparent: !0,
  85766. };
  85767. let lineMats$2;
  85768. let getLineMat$1 = function(type){
  85769. if(!lineMats$2){
  85770. lineMats$2 = {
  85771. 'fire+smoke':LineDraw.createFatLineMat($.extend(depthMatPrefix,{
  85772. color: colors$2['fire+smoke'],
  85773. lineWidth: 2
  85774. })),
  85775. 'smoke' :LineDraw.createFatLineMat($.extend(depthMatPrefix,{
  85776. color: colors$2['smoke'],
  85777. lineWidth: 2
  85778. })),
  85779. 'explode' :LineDraw.createFatLineMat($.extend(depthMatPrefix,{
  85780. color: colors$2['explode'],
  85781. lineWidth: 2
  85782. })),
  85783. };
  85784. }
  85785. return lineMats$2[type]
  85786. };
  85787. let handleMats;
  85788. let getHandleMat = function(type){
  85789. if(!handleMats){
  85790. let texLoader = new TextureLoader();
  85791. handleMats = {
  85792. "fire+smoke" : new DepthBasicMaterial($.extend(depthMatPrefix,{
  85793. map: texLoader.load(Potree.resourcePath+'/textures/icon-fire.png' ),
  85794. color: colors$2['fire+smoke'],
  85795. })),
  85796. "smoke" : new DepthBasicMaterial($.extend(depthMatPrefix,{
  85797. map: texLoader.load(Potree.resourcePath+'/textures/icon-smoke.png' ),
  85798. color: colors$2['smoke'],
  85799. })),
  85800. "explode" : new DepthBasicMaterial($.extend(depthMatPrefix,{
  85801. map: texLoader.load(Potree.resourcePath+'/textures/icon-explode.png' ),
  85802. color: colors$2['explode'],
  85803. })),
  85804. };
  85805. }
  85806. return handleMats[type]
  85807. };
  85808. let ParticleEditor = {
  85809. bus: new EventDispatcher,
  85810. particleGroup : new Object3D ,
  85811. curveGroup:new Object3D ,
  85812. init:function(){
  85813. this.particleGroup.name = 'particles';
  85814. viewer.scene.scene.add( this.particleGroup );
  85815. this.curveGroup.name = 'particles-curves';
  85816. viewer.scene.scene.add( this.curveGroup );
  85817. },
  85818. addParticle : function(prop={}){
  85819. let particle;
  85820. if(prop.type == 'fire'){
  85821. particle = new FireParticle(prop);
  85822. }else if(prop.type == 'smoke'){
  85823. particle = new SmokeParticle(prop);
  85824. }else if(prop.type == 'explode'){
  85825. particle = new ExplodeParticle(prop);
  85826. }
  85827. this.particleGroup.add(particle);
  85828. return particle
  85829. }
  85830. ,
  85831. removeParticle(particle){
  85832. //particle.dispatchEvent('delete')
  85833. particle.dispose();
  85834. this.particleGroup.remove(particle);
  85835. particle.curve.dispose();
  85836. }
  85837. ,
  85838. update(delta){
  85839. this.particleGroup.children.forEach(e=>e.update(delta));
  85840. }
  85841. ,
  85842. startInsertion(type = 'fire', prop={}){ //viewer.modules.ParticleEditor.startInsertion()
  85843. let deferred = $.Deferred();
  85844. let particles = [];
  85845. let finish = (ifDone)=>{
  85846. if(ifDone){
  85847. deferred.resolve(particles);
  85848. }
  85849. viewer.dispatchEvent({
  85850. type : "CursorChange", action : "remove", name:"addSth"
  85851. });
  85852. viewer.removeEventListener('global_click', click);
  85853. this.bus.removeEventListener('cancel_insertions',cancel);
  85854. };
  85855. let curve = new CurveCtrl([], getLineMat$1(type), colors$2[type], type+'_curve', {handleMat:getHandleMat(type)} );
  85856. this.curveGroup.add(curve);
  85857. prop.curve = curve;
  85858. prop.type = type;
  85859. //console.log('创建curve',type,curve.uuid)
  85860. let cancel = ()=>{
  85861. console.log('cancel_insertions', curve.uuid );
  85862. curve.dispose();
  85863. finish(false);
  85864. };
  85865. this.bus.dispatchEvent('cancel_insertions');//删除旧的
  85866. this.bus.addEventListener('cancel_insertions',cancel);
  85867. var click = (e)=>{
  85868. if(e.button === MOUSE.RIGHT){
  85869. if(curve.points.length>=1){ //if(type.includes('fire') || type.includes('smoke') ){
  85870. particles = this.createFromData(prop);
  85871. finish(true);
  85872. }
  85873. return
  85874. }
  85875. var I = e.intersect && (e.intersect.orthoIntersect || e.intersect.location);
  85876. if(!I)return
  85877. curve.addPoint(I, null, true);
  85878. if(type == 'explode'){
  85879. particles = this.createFromData(prop);
  85880. finish(true);
  85881. }
  85882. return {stopContinue:true}//防止继续执行别的侦听,如flytopano
  85883. };
  85884. viewer.addEventListener('global_click', click, {importance:10});//add importance
  85885. viewer.dispatchEvent({
  85886. type : "CursorChange", action : "add", name:"addSth"
  85887. });
  85888. return deferred.promise()
  85889. },
  85890. createFromData(prop){
  85891. const type = prop.type;
  85892. var particles = [];
  85893. let curve = prop.curve;
  85894. if(!curve){
  85895. curve = new CurveCtrl(prop.points, getLineMat$1(type), colors$2[type], type+'_curve', {handleMat:getHandleMat(type)} );
  85896. this.curveGroup.add(curve);
  85897. }
  85898. if(type.includes('fire') || type.includes('smoke') ){
  85899. if(type.includes('fire')){
  85900. var fire = this.addParticle({
  85901. type : 'fire',
  85902. positions : curve.points,
  85903. curve,
  85904. radius : prop.radius,
  85905. height: prop.height,
  85906. strength : prop.strength,
  85907. });
  85908. particles.push(fire);
  85909. }
  85910. if(type.includes('smoke')){
  85911. var smoke = this.addParticle({
  85912. type : 'smoke',
  85913. positions : curve.points,
  85914. curve,
  85915. positionStyle : 'sphere' ,
  85916. strength : prop.smokeStrength,
  85917. radius: prop.smokeRadius,
  85918. height: prop.smokeHeight,
  85919. });
  85920. particles.push(smoke);
  85921. }
  85922. }else if(type == 'explode'){
  85923. var explode = this.addParticle({
  85924. type : 'explode',
  85925. position : curve.points[0],
  85926. strength: prop.strength,
  85927. radius : prop.radius,
  85928. particleSpaceTime: prop.particleSpaceTime,
  85929. curve,
  85930. delayStartTime:prop.delayStartTime,
  85931. });
  85932. particles.push(explode);
  85933. }
  85934. curve.addEventListener('dragCurvePoint',()=>{
  85935. Common.intervalTool.isWaiting('particlePointChange', ()=>{ //延时update,防止卡顿
  85936. particles.forEach(e=>e.updateGeometry());
  85937. //geoNeedsUpdate = false
  85938. curve.dispatchEvent('sendUpdatePoints');
  85939. }, 400);
  85940. });
  85941. return particles
  85942. }
  85943. };
  85944. let CamAniEditor = {
  85945. createAnimation(data){
  85946. let animation = new CameraAnimation$1(viewer);
  85947. if(data) {
  85948. animation.name = data.name;
  85949. animation.duration = data.duration;
  85950. animation.useDurSlice = data.useDurSlice;
  85951. for(const cpdata of data.points){
  85952. /* const position = Potree.Utils.datasetPosTransform({ fromDataset: true, position: cpdata.position, datasetId: Potree.settings.originDatasetId })
  85953. const target = Potree.Utils.datasetPosTransform({ fromDataset: true, position: cpdata.target, datasetId: Potree.settings.originDatasetId })
  85954. */
  85955. const position = new Vector3().copy(cpdata.position);
  85956. const target = new Vector3().copy(cpdata.target);
  85957. const duration = cpdata.time;
  85958. const cp = animation.createControlPoint(null, {position, target, duration});
  85959. }
  85960. }
  85961. animation.changeCallback();
  85962. viewer.scene.addCameraAnimation(animation);
  85963. return animation
  85964. },
  85965. removeAnimation(animation){
  85966. animation.dispatchEvent('dispose');
  85967. viewer.scene.removeCameraAnimation(animation);
  85968. }
  85969. };
  85970. const clickPanoToDisLink = false;//是否在编辑漫游点连接时,通过点击漫游点能断开连接
  85971. let images360, Alignment$1, SiteModel$1, suggestCircleMat;
  85972. const texLoader$c = new TextureLoader();
  85973. texLoader$c.crossOrigin = "anonymous";
  85974. const rotQua = new Quaternion().setFromAxisAngle(new Vector3(0,0,1), Math.PI);
  85975. const lineMats$3 = {};
  85976. const circleMats = {};
  85977. const renderOrders$1 = {
  85978. circleSelected:3,
  85979. circle:2,
  85980. line:1,
  85981. };
  85982. const pointColor = {
  85983. /* selected:"#c80",
  85984. default:'#1ac' */
  85985. selected:"#c60",
  85986. default:'#17c'
  85987. };
  85988. const opacitys = {//点云透明度
  85989. 'topView':{
  85990. default:0.4,
  85991. selected: 0.6
  85992. },
  85993. 'sideView':{//侧面重叠概率高
  85994. default:0.2,
  85995. selected: 0.5
  85996. },
  85997. };//调这么低是因为有的重叠边缘太亮了
  85998. const cameraProps$2 = [
  85999. {
  86000. name : 'top',
  86001. axis:["x","y"],
  86002. direction : new Vector3(0,0,-1), //镜头朝向
  86003. openCount:0,
  86004. },
  86005. {
  86006. name : 'right',
  86007. axis:["y","z"],
  86008. direction : new Vector3(1,0,0),
  86009. openCount:0,
  86010. },
  86011. {
  86012. name : 'mainView',
  86013. openCount:0,
  86014. }
  86015. ];
  86016. class PanoEditor extends EventDispatcher{
  86017. constructor(){
  86018. super();
  86019. this.panoGroup = [], //分组
  86020. this.viewports = {},
  86021. this.panoLink = {},
  86022. this.panoMeshs = new Object3D,
  86023. this.lineMeshes = new Object3D;
  86024. this.views = {};
  86025. this.cameras = {};
  86026. this.orthoCamera = new OrthographicCamera(-100, 100, 100, 100, 0.01, 10000);
  86027. this.orthoCamera.up.set(0,0,1);
  86028. this.selectedPano;
  86029. this.selectedGroup;
  86030. this.operation;
  86031. this.visiblePanos = [];
  86032. this.suggestLines = [];
  86033. }
  86034. init(){
  86035. {//init lineMats
  86036. lineMats$3.default = LineDraw.createFatLineMat({
  86037. color: '#eeeeee',
  86038. lineWidth: 2,
  86039. depthTest:false
  86040. });
  86041. lineMats$3.hovered = LineDraw.createFatLineMat({
  86042. color: '#00c8af',
  86043. lineWidth: 2,
  86044. depthTest:false
  86045. });
  86046. lineMats$3.selected = LineDraw.createFatLineMat({
  86047. color: '#00c8af',
  86048. lineWidth: 3,
  86049. depthTest:false
  86050. });
  86051. lineMats$3.suggestLink = LineDraw.createFatLineMat({
  86052. color: '#ff2222',
  86053. lineWidth: 4, dashed:true,
  86054. depthTest:false
  86055. });
  86056. }
  86057. suggestCircleMat = new MeshBasicMaterial({
  86058. map: texLoader$c.load(Potree.resourcePath+'/textures/whiteCircle.png' ) ,
  86059. color:'#ff2222', transparent:true,
  86060. depthTest:false, depthWrite:false
  86061. });
  86062. this.initViews();
  86063. /* {
  86064. this.box = new BoxVolume({
  86065. clip:true
  86066. })
  86067. this.box.clipTask = ClipTask['SHOW_INSIDE_Big' ]
  86068. this.box.name = "panoEditClipBox";
  86069. } */
  86070. viewer.addEventListener('allLoaded',()=>{
  86071. images360 = viewer.images360;
  86072. Alignment$1 = viewer.modules.Alignment;
  86073. SiteModel$1 = viewer.modules.SiteModel;
  86074. this.panoMeshs.name = 'panoMeshs';
  86075. viewer.scene.scene.add(this.panoMeshs);
  86076. this.lineMeshes.name = 'lineMeshes';
  86077. viewer.scene.scene.add(this.lineMeshes);
  86078. Potree.settings.ifShowMarker = false;
  86079. {
  86080. this.transformControls = new TransformControls(viewer.mainViewport.camera, viewer.renderArea,{
  86081. dontHideWhenFaceCamera: true,
  86082. rotFullCircle:true
  86083. });
  86084. this.transformControls.setSize(1.5);
  86085. viewer.scene.scene.add(this.transformControls);
  86086. this.transformControls._gizmo.hideAxis = {/* translate:['x','y'], */ rotate:['x','y','e'] };
  86087. this.transformControls.setRotateMethod(2);
  86088. this.fakeMarkerForTran = new Mesh(new BoxBufferGeometry(0.3,0.3,0.3) , new MeshBasicMaterial({
  86089. color:"#FFFFFF", opacity:0.4, transparent:true, visible:false
  86090. }));//一个看不见的mesh,只是为了让transformControls移动点云
  86091. viewer.scene.scene.add(this.fakeMarkerForTran);
  86092. let afterMoveCircle = (type)=>{
  86093. if(type == 'position'){
  86094. let moveVec = new Vector3().subVectors(this.fakeMarkerForTran.position, this.fakeMarkerForTran.oldState.position);
  86095. this.selectedClouds.forEach(cloud=>Alignment$1.translate(cloud, moveVec));
  86096. }else {
  86097. let center = this.selectedPano.position;
  86098. let forward = new Vector3(0,1,0);
  86099. let vec1 = forward.clone().applyQuaternion(this.fakeMarkerForTran.oldState.quaternion);
  86100. let vec2 = forward.clone().applyQuaternion(this.fakeMarkerForTran.quaternion);
  86101. let diffAngle = math.getAngle(vec1,vec2,'z');
  86102. this.selectedClouds.forEach(cloud=>{
  86103. Alignment$1.rotateAround(center, cloud, null, diffAngle);
  86104. });
  86105. }
  86106. this.fakeMarkerForTran.oldState = {
  86107. position: this.fakeMarkerForTran.position.clone(),
  86108. quaternion: this.fakeMarkerForTran.quaternion.clone(),
  86109. };
  86110. Alignment$1.history.beforeChange(this.selectedClouds);
  86111. };
  86112. this.fakeMarkerForTran.addEventListener('position_changed', afterMoveCircle.bind(this,'position'));
  86113. this.fakeMarkerForTran.addEventListener("rotation_changed", afterMoveCircle.bind(this,'rotation') );
  86114. this.transformControls.addEventListener('mouseUp',()=>{
  86115. Alignment$1.history.afterChange(this.selectedClouds);
  86116. });
  86117. Alignment$1.history.addEventListener('undo',()=>{
  86118. this.updateTranCtl();
  86119. });
  86120. }
  86121. this.initPanoLink();
  86122. this.addPanoMesh();
  86123. viewer.scene.pointclouds.forEach(e=>{
  86124. e.material.color = pointColor.default;
  86125. });
  86126. viewer.setEDLEnabled(true); //为了降一倍的绘制. 同时用描边增强立体感,弥补点云稀疏
  86127. viewer.setEDLRadius(3);
  86128. viewer.setEDLStrength(0.02);
  86129. this.switchView('top');
  86130. {//默认选择一个楼层
  86131. let panoVisiReady, siteModelReady;
  86132. let floorInit = ()=>{
  86133. if(!panoVisiReady || !siteModelReady)return
  86134. setTimeout(()=>{
  86135. if(this.currentFloor == 'all'){//还未选择楼层的话
  86136. let floor = SiteModel$1.entities.find(e=>e.buildType == 'floor' && e.panos.length); //选择有漫游点的一层
  86137. if(!floor){
  86138. floor = 'all'; //SiteModel.entities.find(e=>e.buildType == 'floor')
  86139. console.log('没有一层有漫游点?!');
  86140. }
  86141. console.log('initDataDone');
  86142. console.log('gotoFloor 1');
  86143. this.gotoFloor(floor);
  86144. }
  86145. },1); //2d那边用了nextTick ,so setTimeout here
  86146. };
  86147. SiteModel$1.bus.addEventListener('initDataDone',()=>{
  86148. siteModelReady = true;
  86149. floorInit();
  86150. },{once:true});
  86151. this.addEventListener('panoVisiReady',()=>{//2d初始化完成,才可以由3d修改pano显示 (因为在之前2d会给每个pano传来显示的消息,在这之前的修改都会别覆盖)
  86152. panoVisiReady = true;
  86153. floorInit();
  86154. },{once:true});
  86155. }
  86156. Alignment$1.bus.addEventListener('switchHandle', this.updateCursor.bind(this));
  86157. viewer.addEventListener('global_click',(e)=>{
  86158. if(e.button === MOUSE.RIGHT){//取消旋转和平移
  86159. //console.log('right click',e)
  86160. this.setLinkOperateState('addLink',false);
  86161. this.setLinkOperateState('removeLink',false);
  86162. }else if(this.clickToZoomInEnabled){
  86163. if(this.activeViewName == 'mainView'){
  86164. viewer.controls.zoomToLocation(e.mouse);
  86165. }else {
  86166. this.zoomIn(e.intersect.orthoIntersect, e.pointer);
  86167. }
  86168. this.setZoomInState(false);
  86169. }
  86170. });
  86171. /* {//旋转时的辅助线--绕某个点旋转的版本
  86172. this.rotGuideLine = LineDraw.createLine([], {color:'#aaffee'})
  86173. this.rotGuideLine.visible = false
  86174. this.rotGuideLine.name = 'rotGuideLine'
  86175. this.rotGuideLine.renderOrder = renderOrders.line
  86176. viewer.scene.scene.add(this.rotGuideLine)
  86177. let startPoint
  86178. Alignment.bus.addEventListener('rotateStart', (e)=>{
  86179. startPoint = e.startPoint
  86180. })
  86181. Alignment.bus.addEventListener('rotate', (e)=>{
  86182. LineDraw.updateLine(this.rotGuideLine, [startPoint, e.endPoint] )
  86183. this.rotGuideLine.visible = true
  86184. })
  86185. viewer.fpControls.addEventListener("end",(e)=>{
  86186. startPoint = null
  86187. this.rotGuideLine.visible = false
  86188. })
  86189. } */
  86190. {//连接时的辅助线
  86191. this.linkGuideLine = LineDraw.createLine([], {color:'#ddd', deshed:true, dashSize:0.1,gapSize:0.05, depthTest:false});
  86192. this.linkGuideLine.visible = false;
  86193. this.linkGuideLine.name = 'linkGuideLine';
  86194. viewer.scene.scene.add(this.linkGuideLine);
  86195. this.linkGuideLine.renderOrder = renderOrders$1.line;
  86196. let update = (e)=>{
  86197. if(this.operation != 'addLink' || this.activeViewName != 'top' && this.activeViewName != 'mainView' ||!this.selectedPano){
  86198. return this.linkGuideLine.visible = false
  86199. }
  86200. let endPos;
  86201. if(this.activeViewName == 'top' ){
  86202. endPos = e.intersect.orthoIntersect.clone().setZ(this.selectedPano.position.z);
  86203. }else if(this.activeViewName == 'mainView' ){
  86204. if(!e.intersect || !e.intersect.point)return
  86205. endPos = e.intersect.point.position;
  86206. }
  86207. LineDraw.updateLine(this.linkGuideLine, [this.selectedPano.position, endPos] );
  86208. this.linkGuideLine.visible = true;
  86209. viewer.dispatchEvent('content_changed');
  86210. };
  86211. viewer.addEventListener('global_mousemove', (e)=>{
  86212. update(e);
  86213. });
  86214. //this.addEventListener('updateLinkGuideLine', update)
  86215. }
  86216. /*
  86217. viewer.inputHandler.addEventListener('keydown', (e)=>{
  86218. if(e.event.key == "r" ){
  86219. this.setTranMode('rotate')
  86220. }else if(e.event.key == "t"){
  86221. this.setTranMode('translate')
  86222. }
  86223. }) */
  86224. /* {
  86225. viewer.addEventListener('camera_changed', (e)=>{
  86226. Common.intervalTool.isWaiting('updatePointLevels', ()=>{
  86227. this.updatePointLevels()
  86228. }, 1050)
  86229. })
  86230. setTimeout(()=>{
  86231. this.updatePointLevels()
  86232. }, viewer.scene.pointclouds.length*150) //等待差不多updat出了正确的visibleNode时
  86233. } */
  86234. this.panoReposCallback = ()=>{
  86235. viewer.controls.setTarget(this.selectedPano.position); //3d时绕其为中心转动
  86236. };
  86237. });
  86238. }
  86239. setTranMode(mode){//rotate or translate
  86240. console.log('setTranMode',mode);
  86241. this.tranMode = mode;
  86242. if(this.activeViewName == 'mainView'){
  86243. mode && this.transformControls.setMode(mode);
  86244. this.updateTranCtl();
  86245. }else {
  86246. Alignment$1.switchHandle(mode);
  86247. }
  86248. this.updateIntersectEnable();
  86249. }
  86250. updateIntersectEnable(){
  86251. //侧面容易因intersect卡住, 如果非必要关闭intersect. 3d页面也会卡,但controls需要所以不能去掉
  86252. Potree.settings.intersectWhenHover = !!(this.activeViewName == 'mainView' || this.selectedPano && this.tranMode );
  86253. }
  86254. updateTranCtl(){// 设置3D页面的transformControls相关
  86255. if(!this.tranMode || !this.selectedPano || this.activeViewName != 'mainView' ) {
  86256. return this.transformControls.detach()
  86257. }else if(this.checkIfAllLinked({group:this.selectedGroup})){
  86258. this.dispatchEvent('needToDisConnect');
  86259. return this.transformControls.detach()
  86260. }
  86261. this.transformControls.attach(this.fakeMarkerForTran);
  86262. let {position, quaternion} = this.getPanoPose(this.selectedPano);
  86263. this.fakeMarkerForTran.position.copy(position);
  86264. this.fakeMarkerForTran.quaternion.copy(quaternion);
  86265. this.fakeMarkerForTran.oldState = {
  86266. position: position.clone(),
  86267. quaternion: quaternion.clone(),
  86268. };
  86269. }
  86270. //////////////////////////////////
  86271. initViews(){
  86272. this.splitScreenTool = new SplitScreen;
  86273. this.targetPlane = viewer.mainViewport.targetPlane = new Plane();
  86274. this.shiftTarget = viewer.mainViewport.shiftTarget = new Vector3; //project在targetPlane上的位置
  86275. for(let i=0;i<2;i++){
  86276. let prop = cameraProps$2[i];
  86277. let view = new ExtendView();
  86278. this.views[prop.name] = view;
  86279. this.cameras[prop.name] = this.orthoCamera;
  86280. view.name = prop.name;
  86281. view.direction = prop.direction;
  86282. }
  86283. this.views.mainView = viewer.mainViewport.view;
  86284. this.cameras.mainView = viewer.mainViewport.camera;
  86285. }
  86286. switchView(name ){//替换view和camera到mainViewport
  86287. let view = this.views[name];
  86288. let camera = this.cameras[name];
  86289. let prop = cameraProps$2.find(e=>e.name == name);
  86290. let {boundSize, center} = viewer.bound;
  86291. this.lastViewName = this.activeViewName;
  86292. this.activeViewName = name;
  86293. let lastView = this.views[this.lastViewName];
  86294. let lastCamera = this.cameras[this.lastViewName];
  86295. viewer.mainViewport.view = view;
  86296. viewer.mainViewport.camera = camera;
  86297. if(lastCamera)lastView.zoom = lastCamera.zoom;
  86298. this.targetPlane.setFromNormalAndCoplanarPoint( view.direction.clone(), center );
  86299. this.targetPlane.projectPoint(view.position, this.shiftTarget ); //target转换到过模型中心的平面,以保证镜头一定在模型外
  86300. view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport));
  86301. if(view.zoom)camera.zoom = view.zoom;//恢复上次的zoom
  86302. viewer.updateScreenSize({forceUpdateSize:true});//更新camera aspect left等
  86303. this.updateCursor();
  86304. if(name == 'mainView'){
  86305. viewer.mainViewport.alignment = null;
  86306. let changeMat = ()=>{
  86307. viewer.scene.pointclouds.forEach(e=>{
  86308. e.material.activeAttributeName = 'rgba';
  86309. e.material.useFilterByNormal = false;
  86310. e.changePointOpacity(1 );
  86311. });
  86312. };
  86313. /* if(prop.openCount == 0){ //点数较多时,首次转到3D视角会卡顿,因为要切换材质。
  86314. let delay1 = THREE.Math.clamp(viewer.scene.pointclouds.length*0.5, 1, 200)
  86315. setTimeout(()=>{
  86316. this.activeViewName == 'mainView' && changeMat()
  86317. },delay1)
  86318. //console.log('switchview',delay1 )
  86319. }else{ */
  86320. changeMat();
  86321. //}
  86322. Potree.Utils.updateVisible(viewer.reticule, 'force', true);
  86323. if(lastView){//2d->3d
  86324. view.copy(lastView);
  86325. let direction = view.direction;
  86326. let panos = images360.panos.filter(e=>e.circle.visible);
  86327. let nearestPano = Common.sortByScore(panos , [], [(pano)=>{
  86328. let vec = new Vector3().subVectors(pano.position, view.position);
  86329. return -vec.dot(direction);
  86330. }], true);
  86331. //console.log('最近',nearestPano )
  86332. if(nearestPano && nearestPano[0] ){ //尽量不变画面范围,使pano点保持原位,转换到mainView
  86333. let halfHeight = lastCamera.top/lastCamera.zoom;
  86334. let dis = halfHeight / Math.tan( MathUtils.degToRad(camera.fov/2));
  86335. view.position.add(direction.clone().multiplyScalar(-nearestPano[0].score - dis));
  86336. //console.log('getCloser', -nearestPano[0].score - dis)
  86337. this.lastDisToPano = dis; //记录一下
  86338. }
  86339. }
  86340. viewer.fpControls.lockKey = false;
  86341. }else {
  86342. if(this.lastViewName == 'mainView'){//3d->2d
  86343. let direction = lastView.direction;
  86344. let panos = images360.panos.filter(e=>e.circle.visible);
  86345. //尽量靠近画布中心,且距离相机较近
  86346. let nearestPano = Common.sortByScore(panos , [], [(pano)=>{
  86347. let vec = new Vector3().subVectors(pano.position, lastView.position);
  86348. let dis = vec.dot(direction);
  86349. return dis < 0 ? dis * 10 : - dis
  86350. },(pano)=>{
  86351. let vec = new Vector3().subVectors(pano.position, lastView.position);
  86352. let angle = vec.angleTo(direction);
  86353. return - angle * 70
  86354. }], true);
  86355. //目前还存在的问题就是不知selectedPano和最近点的取舍
  86356. //console.log('panos',nearestPano )
  86357. if(nearestPano && nearestPano[0] ){
  86358. //console.log('nearestPano',nearestPano[0].item.id )
  86359. let pos1 = nearestPano[0].item.position.clone();
  86360. let pos2 = pos1.clone();
  86361. let dis = new Vector3().subVectors(nearestPano[0].item.position, lastView.position).dot(direction); //-nearestPano[0].score
  86362. //根据2d->3d的式子逆求zoom
  86363. let halfHeight = Math.abs(dis) * Math.tan( MathUtils.degToRad(lastCamera.fov/2));
  86364. camera.zoom = camera.top / halfHeight;
  86365. camera.updateProjectionMatrix();
  86366. if(name == 'right'){//侧视图
  86367. view.direction = direction.clone().setZ(0); //水平方向设定为3d的方向
  86368. this.targetPlane.setFromNormalAndCoplanarPoint( view.direction.clone(), center );
  86369. this.targetPlane.projectPoint(view.position, this.shiftTarget ); //target转换到过模型中心的平面,以保证镜头一定在模型外
  86370. view.position.copy(this.splitScreenTool.getPosOutOfModel(viewer.mainViewport));
  86371. }
  86372. view.applyToCamera(camera);//update
  86373. pos1.project(lastCamera);
  86374. pos2.project(camera);
  86375. //目标是找到画面上最接近中心的一点(最好是漫游点,不然就是点云),让其在转换画面后在画面上的位置不变。万一找到的点不在屏幕中(比如当屏幕中没点云时),就默认让那个点移动到屏幕中央,也就是假设当前它pos1在屏幕中央位置。
  86376. //
  86377. if(pos1.z>1){
  86378. console.warn('选取的点在相机背后了!?');
  86379. }
  86380. //如果最近点超出屏幕范围 (-1,1), 最好将其拉到边缘,甚至居中 。这样屏幕上就不会没有漫游点了
  86381. let bound = 0.9;
  86382. pos1.x = MathUtils.clamp(pos1.x, -bound, bound);
  86383. pos1.y = MathUtils.clamp(pos1.y, -bound, bound);
  86384. let vecOnscreen = new Vector3().subVectors(pos1,pos2);
  86385. let moveVec = Potree.Utils.getOrthoCameraMoveVec(vecOnscreen, camera );
  86386. //console.log('pos1', pos1)
  86387. view.position.sub(moveVec);
  86388. }
  86389. }else {
  86390. if(prop.openCount == 0){//至多执行一次
  86391. this.viewportFitBound(name, boundSize, center);
  86392. }
  86393. }
  86394. viewer.scene.pointclouds.forEach(e=>{
  86395. e.material.activeAttributeName = 'color';
  86396. e.material.useFilterByNormal = true;
  86397. let opaProp = name == 'top' ? opacitys.topView : opacitys.sideView;
  86398. if(this.selectedPano && this.selectedClouds.includes(e) ){
  86399. e.changePointOpacity(opaProp.selected,true);
  86400. e.material.color = pointColor.selected;
  86401. }else {
  86402. e.changePointOpacity(opaProp.default,true);
  86403. e.material.color = pointColor.default;
  86404. }
  86405. });
  86406. Potree.Utils.updateVisible(viewer.reticule, 'force', false);
  86407. if(name == 'top') viewer.mainViewport.alignment = {rotate:true,translate:true};
  86408. if(name == 'right'){
  86409. viewer.mainViewport.alignment = {translate:true, rotateSide:true, translateVec:new Vector3(0,0,1)}; //只能上下移动
  86410. viewer.mainViewport.rotateSide = true;
  86411. }else {
  86412. viewer.mainViewport.rotateSide = false;
  86413. }
  86414. viewer.fpControls.lockKey = true;
  86415. }
  86416. this.updateTranCtl();
  86417. this.setTranMode(this.tranMode); // update
  86418. this.setZoomInState(false); //取消放大模式
  86419. //this.updatePointLevels()
  86420. this.updateIntersectEnable();
  86421. prop.openCount ++;
  86422. }
  86423. viewportFitBound(){ //使一个viewport聚焦在某个范围
  86424. if(viewer.mainViewport.resolution.x == 0 || viewer.mainViewport.resolution.y == 0){
  86425. return setTimeout(()=>{
  86426. this.viewportFitBound();
  86427. },10)
  86428. }
  86429. this.gotoFloor(this.currentFloor, true, 0, null, true);
  86430. }
  86431. rotateSideCamera(angle){//侧视图绕模型中心水平旋转
  86432. this.splitScreenTool.rotateSideCamera(viewer.mainViewport, angle);
  86433. }
  86434. zoomIn(intersect, pointer){
  86435. let camera = viewer.mainViewport.camera;
  86436. let endZoom = 200;
  86437. //this.orthoMoveFit(intersect, {endZoom:viewer.mainViewport.camera.zoom < aimZoom ? aimZoom : null} , 300)
  86438. let startZoom = camera.zoom;
  86439. if(startZoom >= endZoom){return}
  86440. viewer.mainViewport.view.zoomOrthoCamera(camera, endZoom, pointer, 300);
  86441. }
  86442. orthoMoveFit(pos, info, duration){
  86443. var margin = {x:200, y:230};
  86444. this.splitScreenTool.viewportFitBound(viewer.mainViewport, info.bound, pos, duration, margin );
  86445. }
  86446. setZoomInState(state, informinformBy2d){//是否点击后可放大
  86447. //if(state && this.activeViewName == 'mainView')return console.log('3D不可放大')
  86448. this.clickToZoomInEnabled = !!state;
  86449. if(state){
  86450. viewer.dispatchEvent({type : "CursorChange", action : "add", name:"zoomInCloud"} );
  86451. }else {
  86452. viewer.dispatchEvent({type : "CursorChange", action : "remove", name:"zoomInCloud" });
  86453. }
  86454. if(!state && !informinformBy2d){
  86455. this.dispatchEvent({type:'operationCancel', operation: 'zoomIn'});
  86456. }
  86457. }
  86458. gotoFloor(floor, force, duration = 600, informBy2d, fitBound=true){// 选择不同楼层, 切换点位显示。 'all'为全部显示
  86459. floor = floor || 'all';
  86460. if(this.currentFloor == floor && !force)return
  86461. if(this.currentFloor != floor){//如果楼层没变,不修改可视
  86462. //let pointclouds = viewer.findPointcloudsAtFloor(floor)
  86463. let panos = floor == 'all' ? viewer.images360.panos : floor.panos;
  86464. viewer.images360.panos.forEach(pano=>{
  86465. let v = panos.includes(pano);
  86466. this.switchPanoVisible(pano,v);
  86467. });
  86468. }
  86469. this.updateLinesVisible();
  86470. //切换楼层时清空选择状态
  86471. if(this.selectedPano && floor != 'all' && !floor.panos.includes(this.selectedPano)){
  86472. this.selectedPano.circle.dispatchEvent('click');
  86473. }
  86474. if(this.selectedLine){
  86475. this.selectedLine.dispatchEvent('click');
  86476. }
  86477. let bound, center;
  86478. if(floor == 'all'){
  86479. bound = viewer.images360.bound.bounding;
  86480. center = viewer.images360.bound.center;
  86481. }else {
  86482. bound = this.getPanosBound(floor);
  86483. center = bound.getCenter(new Vector3());
  86484. if(floor.panos.length == 0)console.log(floor.name, 'floor无漫游点' );
  86485. }
  86486. if(this.activeViewName != 'mainView' ){
  86487. fitBound && this.orthoMoveFit(center, {bound}, duration);
  86488. }else if(this.activeViewName == 'mainView'){
  86489. //if(floor != 'all'){ //切换一下位置,因为原处点云会消失
  86490. //viewer.scene.view.setView({position:center, duration })
  86491. viewer.focusOnObject({boundingBox:bound},'boundingBox');
  86492. //}
  86493. }
  86494. this.currentFloor = floor;
  86495. //if(!informBy2d){ //注释原因:2d居然不会自己变
  86496. this.dispatchEvent({type:'changeFloor', floor});
  86497. //}
  86498. }
  86499. getPanosBound(floor){
  86500. if(!floor.panosBound){
  86501. if(floor.panos.length == 0){
  86502. floor.panosBound = viewer.images360.bound.bounding.clone();
  86503. }else {
  86504. let minSize = new Vector3(10,10,10);
  86505. let bound = math.getBoundByPoints(floor.panos.map(e=>e.position), minSize);
  86506. floor.panosBound = bound.bounding;
  86507. }
  86508. }
  86509. return floor.panosBound
  86510. }
  86511. switchPanoVisible(pano, v, informBy2d){
  86512. //console.log(pano.id,v)
  86513. Potree.Utils.updateVisible(pano.circle , 'panoEditor', v);
  86514. Potree.Utils.updateVisible(pano, 'panoEditor', v);
  86515. Potree.Utils.updateVisible(pano.pointcloud, 'panoEditor', v);
  86516. if(v){
  86517. this.visiblePanos.includes(pano) || this.visiblePanos.push(pano);
  86518. }else {
  86519. let index = this.visiblePanos.indexOf(pano);
  86520. index>-1 && this.visiblePanos.splice(index,1);
  86521. }
  86522. if(informBy2d){
  86523. this.dispatchEvent('panoVisiReady');
  86524. this.updateLinesVisible();
  86525. }
  86526. informBy2d || this.dispatchEvent({type:"switchPanoVisible", pano, v});
  86527. /* {
  86528. setTimeout(()=>{
  86529. Common.intervalTool.isWaiting('updatePointLevels2', ()=>{
  86530. this.updatePointLevels()
  86531. }, 50)
  86532. },1)//等update过visibleNodes
  86533. } */
  86534. }
  86535. updateLinesVisible(){
  86536. this.lineMeshes.children.forEach(line=>{
  86537. let names = line.name.split('-');
  86538. var pano0 = images360.getPano(names[0]);
  86539. var pano1 = images360.getPano(names[1]);
  86540. line.visible = this.visiblePanos.includes(pano0) || this.visiblePanos.includes(pano1);
  86541. });
  86542. }
  86543. updateCursor(){
  86544. let cursor;
  86545. if(this.activeViewName == 'mainView' || !this.selectedPano){
  86546. cursor = null;
  86547. }else {
  86548. cursor = Alignment$1.handleState;
  86549. }
  86550. if(cursor == 'rotate'){
  86551. viewer.dispatchEvent({
  86552. type : "CursorChange", action : "add", name:"rotatePointcloud"
  86553. });
  86554. viewer.dispatchEvent({
  86555. type : "CursorChange", action : "remove", name:"movePointcloud"
  86556. });
  86557. }else if(cursor == 'translate'){
  86558. viewer.dispatchEvent({
  86559. type : "CursorChange", action : "add", name:"movePointcloud"
  86560. });
  86561. viewer.dispatchEvent({
  86562. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  86563. });
  86564. }else {
  86565. viewer.dispatchEvent({
  86566. type : "CursorChange", action : "remove", name:"movePointcloud"
  86567. });
  86568. viewer.dispatchEvent({
  86569. type : "CursorChange", action : "remove", name:"rotatePointcloud"
  86570. });
  86571. }
  86572. //this.cursorState = cursor
  86573. }
  86574. setLinkOperateState(name, state, informinformBy2d){
  86575. if(state && name == this.operation || !state && name != this.operation)return
  86576. let old = this.operation;
  86577. this.operation = state ? name : null;
  86578. if(this.operation == 'removeLink'){
  86579. if(this.selectedLine){
  86580. this.selectedLine.dispatchEvent('click');//删除
  86581. }
  86582. if(this.selectedPano && clickPanoToDisLink){
  86583. this.selectedPano.circle.dispatchEvent('click');//删除
  86584. }
  86585. }
  86586. if(this.operation != 'addLink'){
  86587. this.linkGuideLine.visible = false;
  86588. }
  86589. if(!state && !informinformBy2d){
  86590. this.dispatchEvent({type: "operationCancel", operation: old});
  86591. }
  86592. if(this.operation == 'addLink'){
  86593. viewer.dispatchEvent({type : "CursorChange", action : "add", name:"connectPano"} );
  86594. }else {
  86595. viewer.dispatchEvent({type : "CursorChange", action : "remove", name:"connectPano"} );
  86596. }
  86597. if(this.operation == 'removeLink'){
  86598. viewer.dispatchEvent({type : "CursorChange", action : "add", name:"disconnectPano"} );
  86599. }else {
  86600. viewer.dispatchEvent({type : "CursorChange", action : "remove", name:"disconnectPano"} );
  86601. }
  86602. viewer.dispatchEvent('content_changed');
  86603. }
  86604. /////////////////////////////////
  86605. initPanoLink(){
  86606. images360.panos.forEach((pano)=>{
  86607. this.panoLink[pano.id] = {};
  86608. this.panoGroup.push([pano]);
  86609. });
  86610. images360.panos.forEach((pano)=>{
  86611. pano.visibles.forEach(index=>{//visibles中存的是下标!
  86612. this.linkChange(pano, images360.getPano(index,'index'), 'add');
  86613. });
  86614. });
  86615. //console.log('panoLink',this.panoLink)
  86616. }
  86617. linkChange(pano0, pano1, type){//修改link (type == 'remove'时,pano1可以为空)
  86618. let temp = [];
  86619. if(type == 'add'){
  86620. if(!pano1)return console.error('不支持add时pano1为空')
  86621. this.panoLink[pano0.id][pano1.id] = this.panoLink[pano0.id][pano1.id] || {};
  86622. this.panoLink[pano1.id][pano0.id] = this.panoLink[pano1.id][pano0.id] || {};
  86623. }else {
  86624. if(!pano1){
  86625. for(let id in this.panoLink[pano0.id]){
  86626. if(this.panoLink[pano0.id][id]){
  86627. this.panoLink[id][pano0.id] = false;
  86628. temp.push(id);
  86629. }
  86630. }
  86631. this.panoLink[pano0.id] = {}; //全部断连
  86632. }else {
  86633. this.panoLink[pano0.id][pano1.id] = false;
  86634. this.panoLink[pano1.id][pano0.id] = false;
  86635. }
  86636. }
  86637. if(!pano1){ //全部断连
  86638. temp.forEach(id=>{
  86639. this.lineChange(pano0, images360.getPano(id) , type);
  86640. });
  86641. }else {
  86642. this.lineChange(pano0, pano1, type);
  86643. }
  86644. this.groupChange(pano0, pano1, type);
  86645. //this.updateSelectGroup()
  86646. this.selectPano(this.selectedPano, false,true); //更新选中点云显示
  86647. }
  86648. lineChange(pano0, pano1, type){//修改line
  86649. if(type == 'add'){
  86650. if(this.panoLink[pano0.id][pano1.id].line) return
  86651. let line = LineDraw.createFatLine([pano0.position, pano1.position], {mat:lineMats$3.default});
  86652. line.name = `${pano0.id}-${pano1.id}`;
  86653. line.renderOrder = line.pickOrder = renderOrders$1.line;
  86654. this.lineMeshes.add(line);
  86655. this.panoLink[pano0.id][pano1.id].line = this.panoLink[pano1.id][pano0.id].line = line;
  86656. line.addEventListener('mouseover', ()=>{
  86657. if(this.clickToZoomInEnabled)return
  86658. //if(this.activeViewName == 'mainView')return
  86659. if(this.selectedLine != line)line.material = lineMats$3.hovered;
  86660. viewer.dispatchEvent({
  86661. type : "CursorChange", action : "add", name:"hoverLine"
  86662. });
  86663. });
  86664. line.addEventListener('mouseleave', ()=>{
  86665. if(this.clickToZoomInEnabled)return
  86666. //if(this.activeViewName == 'mainView')return
  86667. if(this.selectedLine != line)line.material = lineMats$3.default;
  86668. viewer.dispatchEvent({
  86669. type : "CursorChange", action : "remove", name:"hoverLine"
  86670. });
  86671. });
  86672. line.addEventListener('click', (e)=>{
  86673. if(this.clickToZoomInEnabled)return
  86674. //if(this.activeViewName == 'mainView')return
  86675. if(this.operation == 'removeLink'){
  86676. if(this.selectedLine == line) this.selectLine(null);
  86677. return this.linkChange(pano0, pano1, 'remove')
  86678. }
  86679. this.selectLine(line);
  86680. });
  86681. }else {
  86682. let line = this.lineMeshes.children.find(e=>e.name == `${pano0.id}-${pano1.id}` || e.name == `${pano1.id}-${pano0.id}` );
  86683. if(line){
  86684. this.lineMeshes.remove(line);
  86685. line.geometry.dispose();
  86686. }
  86687. }
  86688. }
  86689. groupChange(pano0, pano1, type){//修改group (type == 'remove'时,pano1可以为空)
  86690. if(type == 'add'){
  86691. Common.pushToGroupAuto([pano0, pano1], this.panoGroup );
  86692. }else {
  86693. let atGroup = this.panoGroup.find(e=>e.includes(pano0) && (e.includes(pano1) || !pano1));//所在组
  86694. if(!atGroup){
  86695. if(pano1){
  86696. console.log('这两个pano原本就不在一个组', pano0.id, pano1.id);
  86697. }else {
  86698. console.log('pano0不在任何组', pano0);
  86699. }
  86700. return
  86701. }
  86702. //断开连接时,因为组内没有其他成员的连接信息,所以需要清除整组,并将剩余的一个个重新连接
  86703. this.panoGroup.splice(this.panoGroup.indexOf(atGroup),1); //删除
  86704. atGroup.forEach(pano=>{//然后再重新生成这两个和组的关系,各自分组
  86705. this.panoGroup.push([pano]);
  86706. for(let id in this.panoLink[pano.id]){
  86707. if(this.panoLink[pano.id][id]){
  86708. let pano_ = images360.getPano(id);
  86709. Common.pushToGroupAuto([pano, pano_], this.panoGroup );
  86710. }
  86711. }
  86712. });
  86713. }
  86714. }
  86715. selectLine(line){
  86716. if(this.selectedLine == line)return
  86717. if(this.selectedLine){
  86718. this.selectedLine.material = lineMats$3.default;
  86719. }
  86720. if(line){
  86721. line.material = lineMats$3.selected;
  86722. }
  86723. this.selectedLine = line;
  86724. }
  86725. addPanoMesh(){
  86726. let map = texLoader$c.load(Potree.resourcePath+'/textures/correct_n.png' );
  86727. /* circleMats.default_normal = new THREE.MeshBasicMaterial({
  86728. map,
  86729. color: 0xffffff,
  86730. transparent: true,
  86731. depthTest: false,
  86732. depthWrite: false,
  86733. }) */
  86734. window.circleMats = circleMats;
  86735. circleMats.default_normal = new DepthBasicMaterial({
  86736. map,
  86737. color: 0xffffff,
  86738. transparent: true,
  86739. useDepth:true,
  86740. backColor: 0x33ffdd,
  86741. occlusionDistance: 10,//变为backColor距离
  86742. clipDistance : 5,//消失距离
  86743. maxClipFactor: 0.8,
  86744. maxOcclusionFactor: 0.8,
  86745. });
  86746. circleMats.default_rtk_on = circleMats.default_normal.clone();
  86747. circleMats.default_rtk_on.map = texLoader$c.load(Potree.resourcePath+'/textures/rtk-y-n.png' );
  86748. circleMats.default_rtk_off = circleMats.default_normal.clone();
  86749. circleMats.default_rtk_off.map = texLoader$c.load(Potree.resourcePath+'/textures/rtk-f-n.png' );
  86750. circleMats.selected_normal = circleMats.default_normal.clone();
  86751. circleMats.selected_normal.map = texLoader$c.load(Potree.resourcePath+'/textures/correct_s.png' );
  86752. circleMats.selected_normal.useDepth = false;
  86753. circleMats.selected_rtk_on = circleMats.selected_normal.clone();
  86754. circleMats.selected_rtk_on.map = texLoader$c.load(Potree.resourcePath+'/textures/rtk-y-s.png' );
  86755. circleMats.selected_rtk_off = circleMats.selected_normal.clone();
  86756. circleMats.selected_rtk_off.map = texLoader$c.load(Potree.resourcePath+'/textures/rtk-f-s.png' );
  86757. circleMats.hovered_normal = circleMats.default_normal.clone();
  86758. circleMats.hovered_normal.color.set(0x00ff00);
  86759. circleMats.hovered_normal.useDepth = false;
  86760. circleMats.hovered_rtk_on = circleMats.default_rtk_on.clone();
  86761. circleMats.hovered_rtk_on.color.set(0x00ff00);
  86762. circleMats.hovered_rtk_on.useDepth = false;
  86763. circleMats.hovered_rtk_off = circleMats.default_rtk_off.clone();
  86764. circleMats.hovered_rtk_off.color.set(0x00ff00);
  86765. circleMats.hovered_rtk_off.useDepth = false;
  86766. let setPos = (circle)=>{
  86767. circle.position.copy(circle.pano.position);
  86768. for(let id in this.panoLink[circle.pano.id]){
  86769. let linkInfo = this.panoLink[circle.pano.id][id];
  86770. if(linkInfo){
  86771. LineDraw.updateLine(linkInfo.line, [circle.pano.position, images360.getPano(id).position] );
  86772. }
  86773. }
  86774. circle.waitUpdate(); //update sprite Matrix
  86775. };
  86776. images360.panos.forEach(pano=>{
  86777. var circle = new Sprite$2({mat: circleMats['default' + '_'+ this.getPanoRtkState(pano) ] , sizeInfo:{
  86778. minSize : 50 , maxSize : 120, nearBound : 2, farBound : 10,
  86779. },
  86780. renderOrder : renderOrders$1.circle,
  86781. pickOrder: renderOrders$1.circle
  86782. });
  86783. circle.pickDontCheckDis = true;
  86784. circle.name = 'panoCircle';
  86785. circle.sid = pano.id;
  86786. circle.pano = pano;
  86787. pano.circle = circle;
  86788. this.panoMeshs.add(circle);
  86789. setPos(circle);
  86790. pano.addEventListener('rePos', setPos.bind(this,circle));
  86791. let drag = (e)=>{
  86792. /* if(this.activeViewName == 'mainView' && this.tranMode == 'translate'){//如果3d页不禁止xy的话,这段打开
  86793. this.transformControls.dispatchEvent('dragging')//触发拖拽
  86794. return
  86795. } */
  86796. if(this.tranMode != 'translate' || this.activeViewName == 'mainView')return e.refuse()
  86797. this.selectPano(circle.pano); //为了方便拖拽点云,拖动circle就直接选中
  86798. viewer.inputHandler.drag.object = null; //取消拖拽状态,否则不触发点云拖动
  86799. };
  86800. circle.addEventListener('drag', drag);
  86801. circle.addEventListener('mouseover', ()=>{
  86802. this.hoverPano(pano,true);
  86803. });
  86804. circle.addEventListener('mouseleave', ()=>{
  86805. this.hoverPano(pano,false);
  86806. });
  86807. circle.addEventListener('click', ()=>{
  86808. //if(this.activeViewName == 'mainView')return
  86809. if(this.clickToZoomInEnabled)return
  86810. if(clickPanoToDisLink && this.operation == 'removeLink'){
  86811. this.linkChange(pano, null, 'remove'); //删除所有连接
  86812. }
  86813. if(this.selectedPano == circle.pano) return this.selectPano(null)
  86814. if(this.operation == 'addLink' && this.selectedPano){
  86815. this.linkChange(this.selectedPano, circle.pano, 'add');
  86816. //this.setLinkOperateState('addLink',false)
  86817. return
  86818. }
  86819. //if(this.operation == 'removeLink' && this.selectedPano){ //和选择中心点冲突
  86820. // this.linkChange(this.selectedPano, circle.pano, 'remove')
  86821. // //this.setLinkOperateState('removeLink',false)
  86822. // return
  86823. // }
  86824. this.selectPano(circle.pano);
  86825. });
  86826. });
  86827. }
  86828. hoverPano(pano, state){
  86829. if(this.clickToZoomInEnabled)return
  86830. if(pano && state){ //在hover一个pano之前,一定会先取消已经hover的pano, 最多存在一个hovered的pano
  86831. if(this.hoveredPano == pano)return
  86832. if(this.hoveredPano){
  86833. this.hoverPano(this.hoveredPano,false);
  86834. }
  86835. this.hoveredPano = pano;
  86836. pano.hovered = true;
  86837. if(/* this.activeViewName == 'mainView' || */Alignment$1.handleState && this.selectedPano && this.selectedPano == pano)return
  86838. if(this.operation != 'addLink' || !this.selectedPano || this.selectedPano == pano){ // this.selectedPano == pano?
  86839. viewer.dispatchEvent({
  86840. type : "CursorChange", action : "add", name:"hoverPano"
  86841. });
  86842. }
  86843. if(this.selectedPano != pano) pano.circle.material = circleMats['hovered' + '_'+ this.getPanoRtkState(pano) ];
  86844. }else if(pano && !state){//unhover
  86845. if(this.hoveredPano != pano)return
  86846. pano.hovered = false;
  86847. viewer.dispatchEvent({
  86848. type : "CursorChange", action : "remove", name:"hoverPano"
  86849. });
  86850. if(this.selectedPano != pano) pano.circle.material = circleMats['default' + '_'+ this.getPanoRtkState(pano) ];
  86851. this.hoveredPano = null;
  86852. }else {//unhover any
  86853. if(this.hoveredPano){
  86854. this.hoverPano(this.hoveredPano, false);
  86855. }
  86856. }
  86857. }
  86858. selectPano(pano, informinformBy2d, force){
  86859. if(this.selectedPano == pano && !force)return
  86860. let lastSeletedPano = this.selectedPano;
  86861. let opaProp = this.activeViewName == 'top' ? opacitys.topView : opacitys.sideView;
  86862. if(this.selectedPano){
  86863. this.selectedPano.circle.material = circleMats['default' + '_'+ this.getPanoRtkState(this.selectedPano) ];
  86864. this.selectedPano.circle.renderOrder = renderOrders$1.circle;
  86865. this.selectedPano.removeEventListener('rePos',this.panoReposCallback);
  86866. if(this.activeViewName == 'mainView'){
  86867. }else {
  86868. this.selectedClouds.forEach(e=>{
  86869. e.changePointOpacity(opaProp.default,true);
  86870. e.material.color = pointColor.default;
  86871. });
  86872. }
  86873. }
  86874. this.selectedPano = pano || null;
  86875. this.updateSelectGroup();
  86876. if(pano){
  86877. this.selectedPano.circle.material = circleMats['selected' + '_'+ this.getPanoRtkState(this.selectedPano) ];
  86878. this.selectedPano.circle.renderOrder = this.selectedPano.circle.pickOrder = renderOrders$1.circleSelected; //侧视图能显示在最前
  86879. viewer.controls.setTarget(this.selectedPano.position); //3d时绕其为中心转动
  86880. this.selectedPano.addEventListener('rePos',this.panoReposCallback);
  86881. if(this.activeViewName == 'mainView'){
  86882. }else {
  86883. this.selectedClouds.forEach(e=>{
  86884. e.changePointOpacity(opaProp.selected,true);
  86885. e.material.color = pointColor.selected;
  86886. });
  86887. }
  86888. if(this.currentFloor != 'all'){//如果原本不是展示全部楼层的话,自动切换楼层
  86889. let atFloor = SiteModel$1.entities.find(e=>e.buildType == 'floor' && e.panos.includes(pano));
  86890. if(!atFloor){
  86891. atFloor = 'all';
  86892. }else {
  86893. }
  86894. this.gotoFloor(atFloor, false, 600 );
  86895. }
  86896. }else {
  86897. viewer.controls.setTarget(null);
  86898. }
  86899. this.updateCursor();
  86900. this.updateTranCtl();
  86901. if(informinformBy2d){
  86902. if(this.selectedPano){
  86903. if(this.activeViewName == 'mainView'){ //平移,focus选中的pano
  86904. let distance = this.lastDisToPano || 5;
  86905. if(lastSeletedPano){
  86906. distance = viewer.mainViewport.camera.position.distanceTo(lastSeletedPano.position);
  86907. }
  86908. viewer.focusOnObject({ position:this.selectedPano.position}, 'point', null, {distance });
  86909. }else {
  86910. this.orthoMoveFit(this.selectedPano.position, {}, 500);
  86911. }
  86912. }
  86913. }else {
  86914. this.dispatchEvent({type:'panoSelect', pano });
  86915. }
  86916. this.updateIntersectEnable();
  86917. viewer.dispatchEvent('content_changed');
  86918. }
  86919. /* updatePointLevels(){
  86920. if(this.pauseUpdateLevels)return
  86921. let maxBudget = Potree.config.pointDensity.panoEdit.pointBudget
  86922. let visiCount1 = viewer.scene.pointclouds.filter(e=>e.visible).length
  86923. let visiCount2 = viewer.scene.pointclouds.filter(e=>e.visibleNodes.length>0).length //屏幕范围内可见的个数
  86924. let maxCount = 200, minCount = 1, minPer = 0.45 , maxPer = 1
  86925. let percent1 = maxPer - ( maxPer - minPer) * THREE.Math.clamp((visiCount1 - minCount) / (maxCount - minCount),0,1)
  86926. let percent2 = maxPer - ( maxPer - minPer) * THREE.Math.clamp((visiCount2 - minCount) / (maxCount - minCount),0,1)
  86927. let percent = percent1*percent2
  86928. if(this.activeViewName == 'mainView' ){
  86929. //假设每个pointcloud所带的点个数大致相同,那么当可见点云个数越多,所能展示的level越低,否则因总个数超过budget的话密度会参差不齐。
  86930. //pointcloud.changePointSize()
  86931. //console.log('updatePointLevels', percent, visiCount)
  86932. Potree.settings.UserDensityPercent = Math.sqrt(percent2)
  86933. viewer.setPointBudget(maxBudget * percent2)
  86934. }else{
  86935. Potree.settings.UserDensityPercent = 1
  86936. viewer.setPointBudget(maxBudget * percent)
  86937. }
  86938. viewer.setPointBudget(maxBudget * percent)
  86939. viewer.setPointLevels()
  86940. //侧面容易卡顿,但和显示的点数无关,似乎是因加载点云多而卡?为何正面不会
  86941. //console.warn('setPointBudget', Potree.pointBudget, visiCount1,visiCount2, Potree.settings.UserDensityPercent)
  86942. } */
  86943. getPanoRtkState(pano){
  86944. return pano.panosData.has_rtk ? pano.rtkState ? 'rtk_on' : 'rtk_off' : 'normal'
  86945. }
  86946. setPanoRtkState(pano,state){
  86947. pano.rtkState = state;
  86948. pano.circle.material = circleMats[(this.selectedPano == pano ? 'selected' : 'default') + '_'+ this.getPanoRtkState(pano) ];
  86949. }
  86950. updateSelectGroup(){//更新选中的组
  86951. this.selectedGroup = this.panoGroup.find(e=>e.includes(this.selectedPano));
  86952. if(this.selectedGroup){
  86953. this.selectedGroup = [this.selectedPano, ...this.selectedGroup.filter(e=>e != this.selectedPano)];//将选中的放第一个,便于旋转时绕其旋转。
  86954. }
  86955. //this.selectedClouds = this.selectedPano ? (this.selectedGroup || [this.selectedPano]).map(e=>e.pointcloud) : []
  86956. this.selectedClouds = this.selectedPano ? this.selectedGroup.map(e=>e.pointcloud) : [];
  86957. }
  86958. checkIfCanSave(){//如果未全部相连,不能保存
  86959. for(let datasetId in Potree.settings.datasetsPanos ) {
  86960. if(!this.checkIfAllLinked({datasetId})){
  86961. console.log('没有全部连通,不能保存。其中一个:', datasetId);
  86962. return
  86963. }
  86964. }
  86965. return true
  86966. }
  86967. checkIfAllLinked(o){//某个(or组所在的)数据集是否全部连通
  86968. let datasetId, group;
  86969. if(o.group){
  86970. group = o.group;
  86971. let pano = o.group[0];
  86972. if(!pano)return //会有没有漫游点的点云来编辑吗
  86973. datasetId = pano.pointcloud.dataset_id;
  86974. }else if(o.datasetId){
  86975. datasetId = o.datasetId;
  86976. group = this.panoGroup.find(panos=>panos[0].pointcloud.dataset_id == datasetId );
  86977. if(!group)return //要找的数据集的pano全部都孤立了
  86978. }
  86979. if(datasetId == void 0)return
  86980. let panos = Potree.settings.datasetsPanos[datasetId].panos;
  86981. return panos.length == group.length
  86982. }
  86983. getSuggestLinkPanos(){//给出建议连接的点
  86984. let panos = [];
  86985. let startTime = Date.now();
  86986. for(let datasetId in Potree.settings.datasetsPanos ) {
  86987. if(!this.checkIfAllLinked({datasetId})){
  86988. let groups = this.panoGroup.filter(panos=>panos[0].pointcloud.dataset_id == datasetId );
  86989. groups = groups.sort((a,b)=>{return b.length - a.length});//找出个数最多的一组来连接其他组
  86990. let mainGroup = groups[0].slice(), subGroup;
  86991. for(let i=1,len=groups.length;i<len;i++){
  86992. subGroup = groups[i];
  86993. let minDis = {dis:Infinity, panos:[]};
  86994. for(let a=0, len1=mainGroup.length; a<len1; a++){
  86995. for(let b=0, len2=subGroup.length; b<len2; b++){
  86996. let dis = mainGroup[a].position.distanceToSquared(subGroup[b].position);
  86997. if(dis<minDis.dis){
  86998. minDis.dis = dis; minDis.panos = [mainGroup[a], subGroup[b]];
  86999. }
  87000. }
  87001. }
  87002. panos.push(minDis.panos);
  87003. //console.log('第i次',minDis)
  87004. mainGroup.push(...subGroup);//连接后,加入集合
  87005. }
  87006. }
  87007. }
  87008. //console.log('cost', Date.now() - startTime)
  87009. return panos
  87010. }
  87011. showSuggestLinkPanos(){
  87012. let groups = this.getSuggestLinkPanos();
  87013. let s = 0.7;
  87014. let createCircle = (pano)=>{
  87015. let circle = new Mesh(pano.circle.geometry, suggestCircleMat);
  87016. circle.name = 'suggest-circle';
  87017. circle.scale.set(s,s,s);
  87018. circle.renderOrder = 100;
  87019. pano.circle.add(circle);
  87020. };
  87021. groups.forEach(panos=>{
  87022. createCircle(panos[0]);
  87023. createCircle(panos[1]);
  87024. let line = LineDraw.createFatLine([panos[0].position, panos[1].position], {mat: lineMats$3.suggestLink});
  87025. this.suggestLines.push(line);
  87026. line.renderOrder = renderOrders$1.line;
  87027. viewer.scene.scene.add(line);
  87028. });
  87029. }
  87030. getPanoPose(pano){
  87031. let pose = {
  87032. position: pano.position.clone(),
  87033. quaternion: new Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua) ,
  87034. };
  87035. return pose
  87036. }
  87037. exportSavingData(){//输出漫游点新的坐标和朝向、以及连接信息
  87038. let sweepLocations = {};
  87039. for(let datasetId in Potree.settings.datasetsPanos ) {
  87040. let {panos} = Potree.settings.datasetsPanos[datasetId];
  87041. let data = panos.map(pano=>{
  87042. let visibles = [];
  87043. for(let id in this.panoLink[pano.id]){
  87044. if(this.panoLink[pano.id][id]){
  87045. visibles.push(viewer.images360.getPano(id).index);
  87046. }
  87047. }
  87048. let {position, quaternion} = this.getPanoPose(pano);
  87049. return Object.assign({}, pano.panosData, {
  87050. uuid: pano.uuid,
  87051. /* pose:{
  87052. translation: dealData(pano.position.clone() ),
  87053. rotation: dealData(new THREE.Quaternion().setFromRotationMatrix(pano.panoMatrix).premultiply(rotQua) ),
  87054. }, */
  87055. pose : {
  87056. translation : dealData(position),
  87057. rotation : dealData(quaternion)
  87058. },
  87059. visibles,
  87060. use_rtk : !!pano.rtkState
  87061. //subgroup: 0,group: 1, "id_view":..
  87062. })
  87063. });
  87064. sweepLocations[datasetId] = {sweepLocations:data};
  87065. }
  87066. /* this.lineMeshes.children.forEach(e=>{//从line中搜集连接信息,而不从linkInfo,这样visibles不会重复一次
  87067. let names = e.name.split('-') //是不是该转成数字
  87068. var pano0 = names[0]
  87069. var pano1 = names[1]
  87070. sweepLocations.find(s=>s.uuid == pano0).visibles.push(pano1)
  87071. }) */
  87072. function dealData(value){
  87073. let v = math.toPrecision(value, 6);
  87074. if(v instanceof Quaternion){
  87075. return {x:v.x, y:v.y, z:v.z, w:v.w}
  87076. }else if(v instanceof Vector3){
  87077. return {x:v.x, y:v.y, z:v.z}
  87078. }
  87079. }
  87080. //console.log(sweepLocations)
  87081. return sweepLocations
  87082. }
  87083. }
  87084. /*
  87085. 不同数据集之间不能连线
  87086. 不同楼层可能也不能
  87087. 如果楼层在不同建筑物怎么办? 楼层切换按钮只能在一个建筑内切换。
  87088. 全部相连时不能移动和旋转
  87089. 如果未全部相连,不能保存
  87090. */
  87091. var PanoEditor$1 = new PanoEditor();
  87092. //import {Prism} from './Prism.js'
  87093. const maxWidth = 4096;
  87094. const surfaceThick = 0.1 ;//最大表面厚度
  87095. const pointDensity = 'screenshot';
  87096. const maxPointBudge = Potree.config.pointDensity[pointDensity].pointBudget;
  87097. const Shaders$1 = {
  87098. 'modelHeight.vs':`
  87099. precision highp float;
  87100. uniform vec2 boundZ;
  87101. varying float heightPercent;
  87102. float round(float number){
  87103. return floor(number + 0.5);
  87104. }
  87105. void main()
  87106. {
  87107. vec3 worldPos = (modelMatrix * vec4(position, 1.0)).xyz;
  87108. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  87109. float zMin = boundZ.x, zMax = boundZ.y ;
  87110. heightPercent = (worldPos.z - zMin) / (zMax - zMin);
  87111. }
  87112. `
  87113. ,
  87114. 'modelHeight.fs': `
  87115. precision highp float;
  87116. varying float heightPercent;
  87117. vec3 percentToByte(float num){
  87118. //输出是0-1, shader精度不够,只够存3个数,因第四位总是0
  87119. float a = 1.0;
  87120. float result[4];
  87121. for(int i=0;i<3;i++){
  87122. a = i == 2 ? a/255.0 : a / 256.0 ;
  87123. //分成256份,其中255份给当前位置,最后一份给后一个位置,而到了最后一个位置时没有下一个位置了所以只分成255份
  87124. if(num > a){
  87125. float c = num / a;
  87126. float r = floor(c);
  87127. r = min(255.0, r);
  87128. result[i] = r;
  87129. num -= r * a;
  87130. }else{
  87131. result[i] = 0.0;
  87132. }
  87133. }
  87134. return vec3(result[0]/255.0, result[1]/255.0,result[2]/255.0);
  87135. }
  87136. void main() {
  87137. gl_FragColor = vec4(percentToByte(heightPercent),1.0);
  87138. }
  87139. `
  87140. };
  87141. let horizonZ, zMin, zMax, lowest, highest, wDelta, sDelta, deferred, interrupt, timestamp,
  87142. buffer1, buffer2, modelZs = [];
  87143. let testPoint$1 = false;
  87144. //const asyncTimeout = (delay) => new Promise(resolve => setTimeout(resolve, delay))
  87145. const delayForNotify = 5, notifyInterval = 500;
  87146. let lastNotifyTime = Date.now();
  87147. let curPercent;
  87148. const notify = (areas, num, str )=>{ //num: 0-1
  87149. return new Promise(resolve => {
  87150. if(!deferred)return resolve()
  87151. let now = Date.now();
  87152. if(now - lastNotifyTime < notifyInterval){
  87153. return resolve()
  87154. }
  87155. lastNotifyTime = now;
  87156. if(num == void 0){
  87157. num = curPercent;
  87158. }else {
  87159. let s = 0, e = 1;
  87160. if(num instanceof Function ){
  87161. num = num();
  87162. }
  87163. areas.forEach((area)=>{
  87164. let s_ = e * area[0] + s * (1-area[0]);
  87165. let e_ = e * area[1] + s * (1-area[1]);
  87166. s = s_, e = e_;
  87167. });
  87168. let p = e * num + s * (1-num);
  87169. str == 'loadpoints' && Potree.settings.isTest && console.log('notify pro', p, str);
  87170. deferred.notify(p);
  87171. curPercent = p;
  87172. if(isNaN(p)){
  87173. console.log('nan');
  87174. }
  87175. }
  87176. setTimeout(resolve, delayForNotify);
  87177. })
  87178. };
  87179. class VolumeComputer extends EventDispatcher{
  87180. constructor(){
  87181. super();
  87182. this.camera = new OrthographicCamera(-100,100,-100,100 , 0.01, 100);
  87183. this.camera.up.set(0,0,1);
  87184. Potree.Utils.setCameraLayers(this.camera, ['model']);
  87185. this.view = new ExtendView;
  87186. this.viewport = new Viewport(this.view,this.camera,{left:0,bottom:0,width:1,height:1});
  87187. this.renderTarget = new WebGLRenderTarget(
  87188. 1, 1,
  87189. { minFilter: LinearFilter,
  87190. magFilter: NearestFilter,
  87191. format: RGBAFormat }
  87192. );
  87193. this.renderTarget2 = new WebGLRenderTarget(
  87194. 1, 1,
  87195. { minFilter: LinearFilter,
  87196. magFilter: NearestFilter,
  87197. format: RGBAFormat }
  87198. );
  87199. this.renderTarget2.texture.name = 'volumeCptModelTex';
  87200. this.material = new ExtendPointCloudMaterial();
  87201. this.material.activeAttributeName = testPoint$1 ? "rgba" : 'heightCpt' ;// 'rgba' indices prismHeight
  87202. this.prisms = [];
  87203. this.modelMat = new ShaderMaterial({
  87204. uniforms:{
  87205. boundZ: {
  87206. type: "vec2",
  87207. value: new Vector2
  87208. }
  87209. },
  87210. vertexShader: Shaders$1['modelHeight.vs'],
  87211. fragmentShader: Shaders$1['modelHeight.fs'],
  87212. depthWrite: true,
  87213. depthTest: true,
  87214. transparent: false,
  87215. side: DoubleSide
  87216. });
  87217. this.scene = new Scene;
  87218. }
  87219. init(){
  87220. viewer.scene.addEventListener('measurement_added',(e)=>{
  87221. if(e.measurement.isPrism) this.add(e.measurement);
  87222. });
  87223. viewer.scene.addEventListener('measurement_removed',(e)=>{
  87224. if(e.measurement.isPrism) this.remove(e.measurement);
  87225. });
  87226. let this_ = this;
  87227. this.events = {
  87228. transformCallback: ()=>{
  87229. if(!this_.currentPrism)return
  87230. //Common.intervalTool.isWaiting('volCptTransformed', ()=>{ //延时update,防止卡顿
  87231. let object = viewer.transformationTool.selection[0];
  87232. if(object == this_.currentPrism.baseModel ){
  87233. this.updateModelBound({modelChange:true});
  87234. }
  87235. this_.currentPrism.dispatchEvent('needsCompute'); //模型变动或clipBox变动后要重算
  87236. //}, 1000)
  87237. },
  87238. };
  87239. }
  87240. enter(){
  87241. this.entered = true;
  87242. viewer.measuringTool.history.clear(); //避免撤销到测量线去
  87243. this.oldStates = {
  87244. rotAroundPoint : Potree.settings.rotAroundPoint
  87245. };
  87246. Potree.settings.rotAroundPoint = false;
  87247. //viewer.objs.traverse(e=>e.material && ( e.material = this.material))
  87248. viewer.transformationTool.addEventListener('stopDrag', this.events.transformCallback);
  87249. viewer.transformationTool.addEventListener('changeByHistory', this.events.transformCallback);
  87250. }
  87251. leave(){
  87252. this.entered = false;
  87253. Potree.settings.rotAroundPoint = this.oldStates.rotAroundPoint;
  87254. this.setCurrentPrism(null);
  87255. viewer.transformationTool.removeEventListener('stopDrag', this.events.transformCallback);
  87256. viewer.transformationTool.removeEventListener('changeByHistory', this.events.transformCallback);
  87257. }
  87258. add(prism){
  87259. this.prisms.push(prism);
  87260. }
  87261. remove(prism){
  87262. let i = this.prisms.indexOf(prism);
  87263. i>-1 && this.prisms.splice(i,1);
  87264. }
  87265. cancel(){
  87266. if(this.computingObject){
  87267. interrupt = true;
  87268. }
  87269. }
  87270. startCompute(model,dontCompute){//test
  87271. this.enter();
  87272. let deferred = $.Deferred();
  87273. deferred.done((e)=>{
  87274. console.log('done', e);
  87275. });
  87276. deferred.fail((e)=>{
  87277. console.log('?fail????', e);
  87278. });
  87279. /* deferred.progress((e)=>{
  87280. console.log('progress', e)
  87281. }) */
  87282. if(model){
  87283. this.prisms[this.prisms.length-1].setBaseModel(model);
  87284. this.setCurrentPrism(this.prisms[this.prisms.length-1]);
  87285. dontCompute || this.compute(this.prisms[this.prisms.length-1]);
  87286. }else {
  87287. this.compute(this.prisms[this.prisms.length-1], deferred );
  87288. }
  87289. }
  87290. setCurrentPrism(prism ){//当进入单个prism编辑后才会高亮点云
  87291. if(this.currentPrism){
  87292. this.currentPrism.removeEventListeners('updated');
  87293. }
  87294. this.currentPrism = prism; //允许没有model
  87295. if(!prism || !prism.baseModel/* || !prism.baseModel.visible */){
  87296. viewer.scene.pointclouds.forEach(e=>{
  87297. this.updateMatForModel(e.material ); //取消高亮
  87298. });
  87299. return
  87300. }
  87301. prism.addEventListener('updated',()=>{
  87302. if(this.currentPrism != prism){
  87303. return console.log('currentPrism changed? 侦听没删除')
  87304. }
  87305. this.updateModelBound();
  87306. });
  87307. this.updateModelBound({regetMap:true});
  87308. }
  87309. setModelMat(model, type){
  87310. if(type == 'recover'){
  87311. model.traverse(e=>e.originMat_ && (e.material = e.originMat_ ));
  87312. }else {
  87313. model.traverse(e=>e.material && e.material != this.modelMat && ( e.originMat_ = e.material, e.material = this.modelMat ));
  87314. }
  87315. }
  87316. updateModelBound({modelChange, regetMap}={}){ //regetMap是在更换currentPrism必须重绘map,但不需要needUpdate
  87317. let prism = this.currentPrism;
  87318. let model = this.currentPrism.baseModel;
  87319. if(!model)return
  87320. model.currentBound = model.boundingBox.clone().applyMatrix4(model.matrixWorld); //作用同prismBound
  87321. let oldBound = model.clipBound && model.clipBound.clone();
  87322. model.clipBound = model.currentBound.clone();//高亮范围
  87323. model.clipBound.min.max(prism.prismBound.min);//xy为交集
  87324. model.clipBound.max.min(prism.prismBound.max);
  87325. model.clipBound.min.z = Math.min(model.currentBound.min.z, prism.prismBound.min.z);//z为并集,范围覆盖prism点、点云、model三者
  87326. model.clipBound.max.z = Math.max(model.currentBound.max.z, prism.prismBound.max.z);
  87327. this.modelMat.uniforms.boundZ.value.set(model.clipBound.min.z,model.clipBound.max.z);
  87328. let boundChanged = !oldBound || !oldBound.equals(model.clipBound);
  87329. let boundSize = this.currentPrism.baseModel.clipBound.getSize(new Vector3);
  87330. 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.
  87331. if( (modelChange || regetMap || boundChanged) && !this.boundSizeZero){
  87332. this.setModelHeightMap();//包含cad在俯视中的范围 + 高度信息
  87333. //this.setModelMat(model,this.boundSizeZero ? 'recover' : null)
  87334. }
  87335. viewer.scene.pointclouds.forEach(e=>{//暂时先只支持一个高亮区域
  87336. this.updateMatForModel(e.material, model);
  87337. });
  87338. //需要重新渲染modelHeightmap的情况:bound改变、模型变动、更换currentPrism后
  87339. //注意,即使上传几种都没发生,仅仅移动prism的marker也要重算,假设一个marker在model范围内,移动后bound可能不变但体积肯定变。
  87340. /* if(boundChanged){
  87341. if(prism.recoverNeedCptNextTime){
  87342. prism.needsCompute = 'byVolume' //初始化,有volume就不用重算
  87343. prism.recoverNeedCptNextTime = false
  87344. }else{
  87345. prism.dispatchEvent('needsCompute')
  87346. }
  87347. } */
  87348. }
  87349. updateMatForModel(material, model){
  87350. let oldMap = material.uniforms.baseHeightAreaMap.value;
  87351. if(model){
  87352. material.uniforms.baseHeightAreaMap.value = this.renderTarget2.texture; //model.baseHeightAreaMap ;
  87353. material.uniforms.baseHeightBoundZ.value.set(model.clipBound.min.z,model.clipBound.max.z);
  87354. material.uniforms.baseHeightBoundXY.value.set(model.clipBound.min.x, model.clipBound.max.x, model.clipBound.min.y, model.clipBound.max.y);
  87355. }else {
  87356. material.uniforms.baseHeightAreaMap.value = null;
  87357. }
  87358. if(oldMap != material.uniforms.baseHeightAreaMap.value ){
  87359. material.shaderNeedsUpdate = true;
  87360. }
  87361. }
  87362. setModelHeightMap(){
  87363. let oldTarget = viewer.renderer.getRenderTarget();
  87364. let oldParent = this.currentPrism.baseModel.parent;
  87365. let oldVisi = this.currentPrism.baseModel.visible;
  87366. let boundSize = this.currentPrism.baseModel.clipBound.getSize(new Vector3);
  87367. let boundCenter = this.currentPrism.baseModel.clipBound.getCenter(new Vector3);
  87368. let {w, h} = this.getResByBound(boundSize,'forModel');
  87369. if(w<=0 || h<=0){
  87370. return console.error('w<=0 || h<=0!!!!!!!!!', w,h)
  87371. }
  87372. /* w = THREE.Math.floorPowerOfTwo( w );
  87373. h = THREE.Math.floorPowerOfTwo( h ); */ //for warning:The texture is a non-power-of-two texture
  87374. this.camera.far = boundSize.z + 10;
  87375. this.camera.right = w / 2;
  87376. this.camera.left = -this.camera.right;
  87377. this.camera.top = h / 2;
  87378. this.camera.bottom = -this.camera.top;
  87379. this.viewport.resolution.set(w , h);
  87380. this.renderTarget2.setSize(w, h);
  87381. viewer.renderer.setRenderTarget(this.renderTarget2);
  87382. console.log('setModelHeightMap');
  87383. //最高处朝下看
  87384. let endPosition = new Vector3;
  87385. endPosition.copy(boundCenter).setZ(this.currentPrism.baseModel.clipBound.max.z + this.camera.near+0.1);
  87386. this.view.pitch = -Math.PI / 2;
  87387. this.view.moveOrthoCamera(this.viewport, {boundSize , endPosition }, 0);
  87388. this.view.applyToCamera(this.camera);
  87389. this.scene.add(this.currentPrism.baseModel);
  87390. this.setModelMat(this.currentPrism.baseModel);
  87391. this.currentPrism.baseModel.visible = true;
  87392. let gl = viewer.renderer.getContext();
  87393. viewer.renderer.setClearColor(new Color('#000'), 0);
  87394. viewer.renderer.clear();
  87395. viewer.renderer.render(this.scene,this.camera);
  87396. this.setModelMat(this.currentPrism.baseModel, 'recover');
  87397. let pixelCount = this.renderTarget2.width * this.renderTarget2.height;
  87398. buffer2 = new Uint8Array(4 * pixelCount);
  87399. //因为需要渲染完立即readPixels才能获取到,所以只能这时候就read了
  87400. gl.readPixels(0, 0, this.renderTarget2.width , this.renderTarget2.height, gl.RGBA, gl.UNSIGNED_BYTE, buffer2); //这句花费最多时间 pc:2-4, 即使只有1*1像素
  87401. modelZs = []; //等待计算
  87402. if(window.needDownload) {
  87403. let dataUrl = Potree.Utils.renderTargetToDataUrl(this.renderTarget2, this.renderTarget2.width, this.renderTarget2.height, viewer.renderer);
  87404. Common.downloadFile(dataUrl, (name || 'screenshot') + '-' + Date.now() +'.png');
  87405. }
  87406. oldParent.add(this.currentPrism.baseModel);
  87407. this.currentPrism.baseModel.visible = oldVisi;
  87408. viewer.renderer.setRenderTarget(oldTarget);
  87409. this.renderTarget2.texture.needsRebuild = true; //renderTarget在resize后会触发dispose, 然后 _gl.deleteTexture( textureProperties.__webglTexture )所以需要重新建立 否则图片变黑
  87410. return this.renderTarget2.texture
  87411. }
  87412. getResByBound(boundSize, type){
  87413. //let pxPerMetric = math.linearClamp(Math.max(boundSize.x,boundSize.y), [4, 10, 20, 80, 500, 2000], [300, 200, 100, 30, 6, 3])
  87414. let pxPerMetric = math.linearClamp(Math.max(boundSize.x,boundSize.y), [ 10, 60, 100, 500, 2000], [150, 60, 40, 6, 3]);
  87415. let w = pxPerMetric * boundSize.x, h = boundSize.y * pxPerMetric;
  87416. let cW = 1 , cH = 1; //横向纵向渲染次数 超过maxWidth时分批渲染
  87417. if(w > maxWidth || h > maxWidth){
  87418. /* if(){//多数据集判断是否间隔过远,是的话返回
  87419. } */
  87420. if(type == 'forCompute'){//计算可以分多次渲染
  87421. cW = Math.ceil(w / maxWidth), cH = Math.ceil(h / maxWidth);
  87422. w /= cW, h /= cH;
  87423. }else if(type == 'forModel'){//但是model的贴图只能有一个
  87424. if(w>h){
  87425. w = maxWidth, h = w * boundSize.y / boundSize.x;
  87426. }else {
  87427. h = maxWidth, w = h * boundSize.x / boundSize.y;
  87428. }
  87429. }
  87430. }
  87431. w = Math.round(w);
  87432. h = Math.round(h);
  87433. return {w,h,pxPerMetric, cW,cH}
  87434. }
  87435. //法1:只用一个顶部相机(当挖方遮挡填方时不准,但好算)
  87436. async compute(prism, deferred_, getResolveResult){
  87437. if(!prism || prism.modelHaventLoad){
  87438. console.log('prism有问题');
  87439. return deferred_.reject()
  87440. }
  87441. if(this.computingObject) return console.log('正在计算,请稍等')
  87442. let oldCurPrism = this.currentPrism;
  87443. if(prism != this.currentPrism){//在列表外点击计算
  87444. this.setCurrentPrism(prism);
  87445. }
  87446. let computeDone = ({highest,lowest,Vupper,Vlower}, deferred )=>{
  87447. prism && prism.setVolumeInfo({
  87448. highest,lowest,Vupper,Vlower
  87449. });
  87450. if(oldCurPrism != prism){
  87451. this.setCurrentPrism(oldCurPrism);
  87452. }
  87453. deferred && deferred.resolve(getResolveResult && getResolveResult());
  87454. };
  87455. if(prism.baseModel && this.boundSizeZero){ //bound没有交集 或 prism的boundsize为0
  87456. return computeDone({highest:0,lowest:0,Vupper:0,Vlower:0}, deferred_ )
  87457. }
  87458. this.computingObject = {prism, model: prism.baseModel};
  87459. deferred = deferred_;
  87460. let computeFinish = (debugStr, makeit)=>{
  87461. makeit || deferred.reject(interrupt ? '主动取消' : (debugStr || ''));
  87462. this.computingObject = null;
  87463. deferred = null;
  87464. interrupt = false;
  87465. debugStr && console.log('computeFinish',debugStr);
  87466. Potree.settings.displayMode = statesBefore.mode;
  87467. Potree.settings.pointDensity = statesBefore.pointDensity;
  87468. viewer.renderer.setRenderTarget(null);
  87469. viewer.renderer.state.reset();
  87470. viewer.renderer.setScissorTest(false);
  87471. gl.disable(gl.SCISSOR_TEST);
  87472. viewer.screenshoting = false;
  87473. viewer.mainViewport.active = true;
  87474. viewer.mapViewer && (viewer.mapViewer.viewports[0].active = true );
  87475. viewer.magnifier.viewport.active = true;
  87476. viewer.pauseTestMaxLevel = false;
  87477. };
  87478. let pointcloud = viewer.scene.pointclouds[0];
  87479. let center = new Vector3;
  87480. let boundSize = new Vector3;
  87481. let bound;
  87482. let gl = viewer.renderer.getContext();
  87483. let statesBefore = {
  87484. mode: Potree.settings.displayMode,
  87485. pointDensity:Potree.settings.pointDensity
  87486. };
  87487. timestamp = Date.now();
  87488. if(!this.computingObject.model){
  87489. horizonZ = prism.horizonZ;
  87490. zMin = prism.zMin;
  87491. zMax = prism.zMax;
  87492. bound = new Box3;
  87493. for(let i=0;i<prism.points.length;i++){
  87494. bound.expandByPoint(prism.points[i]);
  87495. }
  87496. }else {
  87497. zMin = this.computingObject.model.clipBound.min.z;
  87498. zMax = this.computingObject.model.clipBound.max.z;
  87499. bound = this.computingObject.model.clipBound;
  87500. //读取model的高度
  87501. for (let u = 0; u < this.renderTarget2.width; u++) {
  87502. let col = [];
  87503. for (let v = 0; v < this.renderTarget2.height; v++) {
  87504. let offset = (u + v * this.renderTarget2.width);
  87505. let rgb = buffer2.slice(4 * offset, 4 * offset+3), a = buffer2[4 * offset+3];
  87506. if(a == 0 ){ //无点
  87507. col.push(null);
  87508. }else {
  87509. let z = this.convertColorToHeight(rgb, zMin, zMax);
  87510. col.push(z);
  87511. }
  87512. }
  87513. modelZs.push(col);
  87514. }
  87515. }
  87516. lowest = zMax, highest = zMin; //init. to store pixel lowest and highest
  87517. bound.getCenter(center);
  87518. bound.getSize(boundSize);
  87519. this.boundSizeZero = boundSize.x<=0 ||boundSize.y<=0 || boundSize.z<=0; //prism的问题
  87520. if(this.boundSizeZero){
  87521. computeDone({highest:0,lowest:0,Vupper:0,Vlower:0}, deferred );
  87522. return computeFinish('finish', true)
  87523. }
  87524. center.z = zMax + this.camera.near + 0.1;
  87525. this.camera.far = zMax - zMin + 10;
  87526. viewer.screenshoting = true;
  87527. viewer.pauseTestMaxLevel = true;
  87528. let {w, h, pxPerMetric, cW,cH } = this.getResByBound(boundSize, 'forCompute');
  87529. this.camera.right = w / 2;
  87530. this.camera.left = -this.camera.right;
  87531. this.camera.top = h / 2;
  87532. this.camera.bottom = -this.camera.top;
  87533. this.viewport.resolution.set(w , h);
  87534. this.renderTarget.setSize(w, h);
  87535. wDelta = boundSize.x / (w * cW );
  87536. sDelta = Math.pow(wDelta, 2);
  87537. //准备
  87538. Potree.settings.displayMode = 'showPointCloud';
  87539. Potree.settings.pointDensity = 'screenshot';
  87540. viewer.mainViewport.active = false; //暂停渲染,否则影响这边点云的加载
  87541. viewer.mapViewer && (viewer.mapViewer.viewports[0].active = false );
  87542. viewer.magnifier.viewport.active = false; //防止页面变白(似乎mainViewport被clear)
  87543. {//material
  87544. if(!this.computingObject.model){
  87545. //this.material.shape = Potree.PointShape.PARABOLOID;//加上之后depth出错,后排点云会挡前排,可pick时为什么不会?
  87546. this.updateMatForModel(this.material, null); //计算时的shader这两种类型只能选一个,要么prism要么model,只能渲染一块区域
  87547. //this.material.opacity = 1;
  87548. }else {
  87549. this.updateMatForModel(this.material, this.computingObject.model);
  87550. //this.material.opacity = 0.9; //为了输出透明度,负数高度的alpha是0.5
  87551. }
  87552. let clipBoxes_out = prism.clipBoxes.map(box=>{return {inverse:box.matrixWorld.clone().invert(), box}} );
  87553. this.material.setClipBoxes(null,[], clipBoxes_out,[],[prism]);
  87554. this.material.pointSizeType = 'FIXED'; //'ADAPTIVE' //node会自动根据的其level更改点大小 使用ADAPTIVE后会使baseModelMap整片是黑的,原因未知
  87555. this.material.uniforms.minSize.value = 0.1;
  87556. this.material.uniforms.orthoMaxSize.value = 5; //px
  87557. this.material.classification = pointcloud.material.classification;
  87558. this.material.recomputeClassification();
  87559. this.material.shaderNeedsUpdate = true;
  87560. pointcloud.updateMaterial(this.material, null, this.camera, viewer.renderer, this.viewport.resolution);
  87561. this.material.size = 1;//this.getPointsize(pointcloud.maxLevel) //0.025 米 //视图缩小(截图面积变大)后点会自动缩小,但至少是1个像素大小
  87562. }
  87563. viewer.renderer.state.buffers.depth.setTest(this.material.depthTest);
  87564. viewer.renderer.state.buffers.depth.setMask(this.material.depthWrite);
  87565. viewer.renderer.state.setBlending(NoBlending); //只需要设置不透明即可(使alpha不混合,后方不会影响前方的alpha,否则输出的a通道将没法用)
  87566. let pixelCount = this.renderTarget.width * this.renderTarget.height;
  87567. buffer1 = new Uint8Array(4 * pixelCount);
  87568. viewer.renderer.setRenderTarget(this.renderTarget);
  87569. let results = [];
  87570. let boundSize_ = boundSize.clone();
  87571. boundSize_.x /= cW, boundSize_.y /= cH;
  87572. //分批渲染:从左到右 从下到上
  87573. for(let i=0; i<cW; i++){
  87574. for(let j=0; j<cH; j++){
  87575. let infos = [];
  87576. let progressStart = (i*cH + j) / (cW * cH) , progressEnd = (i*cH + j+1) / (cW * cH);
  87577. if(interrupt){
  87578. return computeFinish('23')
  87579. }
  87580. Potree.settings.pointDensity = 'screenshot'; //恢复为nodeMaxLevel
  87581. //最高处朝下看,找挖方的顶部
  87582. this.view.pitch = -Math.PI / 2;
  87583. let endPosition = new Vector3(center.x + (i-cW/2+0.5) * boundSize_.x, center.y + (j-cH/2+0.5) * boundSize_.y, center.z);
  87584. this.view.moveOrthoCamera(this.viewport, {boundSize: boundSize_, endPosition }, 0);
  87585. let endPercent = this.computingObject.model ? 0.7 : 0.4;
  87586. await this.render({i,j,index:1,cW,cH, infos, /* maxLevels, */ notifyArea:[[progressStart, progressEnd],[0,endPercent]], computeFinish });
  87587. if(interrupt){
  87588. return computeFinish('2123')
  87589. }
  87590. if(!this.computingObject.model){
  87591. //水平面朝下看,找填方
  87592. this.view.position.z = horizonZ + this.camera.near;
  87593. await this.render({i,j,index:2, cW,cH, infos, /* maxLevels, */ notifyArea:[[progressStart, progressEnd], [0.4, 0.7]], computeFinish});
  87594. }
  87595. //水平面朝上看,找挖方的底部
  87596. /* this.view.position.z = horizonZ + surfaceThick //排除地面(水平面)上的点
  87597. this.view.pitch = Math.PI / 2;
  87598. await this.render({reverseRow:true,name:'第3张-'+i+'-'+j, infos, buffer,maxLevels }) *///---土堆上有草地有厚度,还是去掉吧
  87599. let result = {
  87600. index : {i,j},
  87601. allFills:[],
  87602. fillVupper:0 ,
  87603. fillVlower:0 ,
  87604. Vupper : 0,
  87605. Vlower : infos[1] ? infos[1].Vlower : infos[0].Vlower , // >= infos[0].Vlower 因能找到被上方遮挡住的凹槽
  87606. allDiffHeights : [],
  87607. fillVupperCount:0,
  87608. fillVlowerCount:0,
  87609. infos
  87610. };
  87611. let waitFill = [];
  87612. waitFill.count = 0;
  87613. let isNeighbor = (a,b)=>{
  87614. return Math.abs(a.u - b.u ) <= 1 && Math.abs(a.v - b.v ) <= 1
  87615. };
  87616. let isBelongToGroup = (group, item)=>{
  87617. if(item[0])item = item[0];
  87618. let i=group.length;
  87619. while(--i >=0){//从后往前
  87620. if(item.u-group[i].u > 1 && Math.abs(item.v-group[i].v) > 1) break //距离超出,前面肯定不相邻了
  87621. if(isNeighbor(group[i], item)){
  87622. return true
  87623. }
  87624. }
  87625. };
  87626. //计算挖方(但是边缘附近垂直方向上很多点云,体积被削皮,最终得到的会比infos[0]少)
  87627. let getValue = (u,v)=>{//当到了左上边界是否需要向前几批的查找?
  87628. if(infos[0].allHeights[u] && infos[0].allHeights[u][v] != void 0 )return infos[0].allHeights[u][v]
  87629. return result.allFills[u] && result.allFills[u][v]
  87630. };
  87631. let hasValue = (u,v)=>{//在边界内
  87632. return u >= 0 && u < infos[0].allHeights.length && v >= 0 && v < infos[0].allHeights[0].length
  87633. };
  87634. let getFill = (u,v)=>{//使用周围的八个点的平均值补洞
  87635. let neighbours = [ [-1,0],[0,1],[1,0],[0,-1], [-1,-1], [1,-1], [-1,1],[1,1]];//先左右右先上后下
  87636. let i=0, c=0, sum=0;
  87637. while(c<4 && i<8){
  87638. let x = neighbours[i][0]+u, y = neighbours[i][1]+v;
  87639. if(hasValue(x,y)){
  87640. let neigh = getValue(x,y);
  87641. if(neigh != void 0){
  87642. c++;
  87643. sum += neigh;
  87644. }else if(i>=3){
  87645. //add 2024.5.27
  87646. if(c == 0)break //节省时间,主要为了大片透明区域
  87647. }
  87648. }
  87649. i++;
  87650. }
  87651. if(c>0){
  87652. sum /= c;
  87653. result.allFills[u] || (result.allFills[u] = []);
  87654. result.allFills[u][v] = sum;
  87655. return sum
  87656. }
  87657. };
  87658. let add = (v, fill, count)=>{
  87659. if(v > 0){
  87660. result.Vupper += v;
  87661. fill && (result.fillVupper+=v, result.fillVupperCount += count);
  87662. }else {//fill的话才会有
  87663. fill && (result.fillVlower-=v, result.fillVlowerCount += count);
  87664. }
  87665. };
  87666. let compute = async (u,v)=>{
  87667. let top = infos[0].allHeights[u][v];
  87668. //let btm = infos[2].allHeights[u][v]
  87669. let fill;
  87670. if(top == void 0){
  87671. if(prism){
  87672. let x = endPosition.x - boundSize_.x /2 + wDelta * (u + 0.5);
  87673. let y = endPosition.y - boundSize_.y /2 + wDelta * (v + 0.5);
  87674. if(!math.isPointInArea(prism.points, null, {x,y}) ){
  87675. return //出界
  87676. }
  87677. }else {
  87678. if(this.getModelZByRes(u,v,cW,cH,i,j) == void 0){
  87679. return //出界
  87680. }
  87681. }
  87682. fill = true;
  87683. top = getFill(u,v);
  87684. if(top == void 0){ //左侧边缘有缺口时会出现
  87685. if(waitFill.cancel || waitFill.count > 1000 && waitFill[waitFill.length-1][waitFill[waitFill.length-1].length-1].u - waitFill[0][0].u > 4){ //跨度超过4列
  87686. waitFill.cancel = true; //丢弃,不加入补洞, 降低耗时
  87687. }else {
  87688. Common.pushToGroupAuto([{u,v}], waitFill, null, isBelongToGroup); //按邻近点分组
  87689. }
  87690. waitFill.count ++; //当数量达到几万以上会在这个地方花很长时间,不过很少出现这种情况
  87691. return
  87692. }
  87693. }
  87694. /* let diff = top-btm
  87695. let useDiff
  87696. if(btm != void 0 && diff > surfaceThick ){
  87697. useDiff = diff
  87698. result.allDiffHeights.push(useDiff)
  87699. }else{
  87700. useDiff = top //从顶部一直到水平
  87701. }*/
  87702. if(waitFill.length){//补 之前没有值的邻居重新获取
  87703. if(interrupt){
  87704. return computeFinish('12312')
  87705. }
  87706. if(waitFill.cancel){
  87707. //console.log('直接清空waitFill', waitFill.count, waitFill.map(list=>[list[0], list[list.length-1]]))
  87708. waitFill.count = 0;
  87709. waitFill.length = 0;
  87710. waitFill.cancel = false;
  87711. }else {
  87712. ///* //Potree.settings.isTest && */ waitFill.count>1000 && console.log('waitFill.count', waitFill.count, 'groupLen', waitFill.length, waitFill[0][0], waitFill[0][waitFill[0].length-1])
  87713. waitFill.slice().forEach(group=>{ //每个组都看看是否跟它相邻
  87714. if(isBelongToGroup(group, {u,v})){
  87715. let index = waitFill.indexOf(group);
  87716. waitFill.splice(index,1);
  87717. waitFill.count -= group.length;
  87718. group.forEach(e=>{
  87719. result.allFills[e.u] || (result.allFills[e.u] = []);
  87720. result.allFills[e.u][e.v] = top; //该组全部都使用该体积
  87721. });
  87722. let sum = top * group.length;
  87723. add(sum, fill, group.length);
  87724. }
  87725. });
  87726. }
  87727. }
  87728. add(top, fill, 1);
  87729. };
  87730. let lastNotifyTime = Date.now();
  87731. //从左到右,从下到上一列列扫描
  87732. for (let u = 0; u < this.renderTarget.width; u++) {
  87733. for (let v = 0; v < this.renderTarget.height; v++) { //数据是从图的下到上存储的
  87734. if(interrupt){
  87735. return computeFinish('1121')
  87736. }
  87737. compute(u,v);
  87738. }
  87739. await notify([[progressStart, progressEnd], [0.7, 1]] , ()=>{return u / this.renderTarget.width }, 'compute');
  87740. }
  87741. if(waitFill.length){
  87742. console.log('waitFill怎么还有??', waitFill);//如果是模型的话是有剩的可能,当它的周围刚好是模型的hole时,就被断开在孤立的组里了,如"回"字型,中间的口是有model但无点云处,外面的口是无model处。
  87743. }
  87744. result.Vupper *= sDelta;
  87745. result.fillVlower *= sDelta;
  87746. result.fillVupper *= sDelta;
  87747. result.Vlower += result.fillVlower;
  87748. results.push(result);
  87749. deferred && deferred.notify(progressEnd);
  87750. }
  87751. }
  87752. let Vupper = 0, Vlower = 0, fillVlower = 0, fillVupper = 0;
  87753. results.forEach((c)=>{
  87754. Vupper += c.Vupper; Vlower += c.Vlower;
  87755. fillVlower += c.fillVlower; fillVupper += c.fillVupper;
  87756. });
  87757. computeDone({
  87758. highest,lowest,Vupper,Vlower,
  87759. }, deferred);
  87760. computeFinish('finish', true);
  87761. console.log( {Vupper,Vlower, oldVupper: Vupper - fillVupper, oldVlower: Vlower - fillVlower, highest,lowest, horizonZ, wDelta}, results, this.viewport.resolution, {cW,cH}, 'cost:', Date.now()-timestamp, 'pxPerMetric', pxPerMetric, 'boundSize',boundSize );//firefox用时是chrome两倍,edge和chrome差不多
  87762. }
  87763. getModelZByRes(u,v, cW,cH,wIndex,hIndex){ //传入renderTarget2的像素index
  87764. //如果两个map的尺寸不同
  87765. let x = Math.round(wIndex/cW + u/this.renderTarget.width * this.renderTarget2.width);
  87766. let y = Math.round(hIndex/cH + v/this.renderTarget.height * this.renderTarget2.height);
  87767. let z0 = modelZs[x][y];
  87768. return z0
  87769. //return modelZs[u][v]
  87770. }
  87771. async render({i,j, index, cW,cH, reverseRow, infos, /* maxLevels, */ notifyArea, computeFinish}={}){
  87772. this.view.applyToCamera(this.camera);
  87773. Potree.updatePointClouds(viewer.scene.pointclouds, this.camera, this.viewport.resolution );
  87774. let gl = viewer.renderer.getContext();
  87775. let screenshot = (name)=>{
  87776. //if(window.testScreen){
  87777. let dataUrl = Potree.Utils.renderTargetToDataUrl(this.renderTarget, this.renderTarget.width, this.renderTarget.height, viewer.renderer);
  87778. Common.downloadFile(dataUrl, (name || 'screenshot') + '-' + timestamp +'.png'); //为什么图片上不是只有pickWindowSize区域有颜色??
  87779. //}
  87780. };
  87781. let name = i+'-'+j+'-第'+index+'张';
  87782. console.log('开始渲染', name);
  87783. let camera = this.camera;
  87784. let viewport = this.viewport;
  87785. return new Promise((resolve, reject)=>{
  87786. let done = async ()=>{
  87787. gl.clearColor(0, 0, 0, 0);
  87788. viewer.renderer.clear(true, true, true);
  87789. //viewer.pRenderer.renderOctree(pointcloud, nodes, this.camera, this.renderTarget ,{material:this.material});
  87790. viewer.pRenderer.render(viewer.scene.scenePointCloud, this.camera, this.renderTarget ,{material:this.material , /* transparent:!this.computingObject.isPrism */ });
  87791. if(interrupt){
  87792. return (reject(), computeFinish('re 23'))
  87793. }
  87794. Potree.settings.isTest && screenshot(name);
  87795. gl.readPixels(0, 0, this.renderTarget.width , this.renderTarget.height, gl.RGBA, gl.UNSIGNED_BYTE, buffer1); //这句花费最多时间 pc:2-4, 即使只有1*1像素
  87796. notifyArea.push([progressEnd1,1]);
  87797. let Vupper = 0, Vlower = 0;
  87798. let upperHeights = [],lowerHeights = [], allHeights = [];
  87799. for (let u = 0; u < this.renderTarget.width; u++) {
  87800. let col = [];
  87801. for (let v = 0; v < this.renderTarget.height; v++) {
  87802. let _v = reverseRow ? this.renderTarget.height - v - 1: v;
  87803. let offset = (u + _v * this.renderTarget.width);
  87804. let rgb = buffer1.slice(4 * offset, 4 * offset+3), a = buffer1[4 * offset+3];
  87805. if(a == 0 /* rgb[0] == 0 && rgb[1] == 0 && rgb[2] == 0 */){ //无点
  87806. col.push(null);
  87807. }else {
  87808. let z = this.convertColorToHeight(rgb, zMin, zMax);
  87809. let h;
  87810. if(!this.computingObject.model){
  87811. h = z - horizonZ;
  87812. }else { //和baseModel标准面之间的高度差
  87813. /* if(a == 128){//负数
  87814. h = -h
  87815. } ///如果这个也要lowest 那需改shader ,shader不计算高度差
  87816. */
  87817. let z0 = this.getModelZByRes(u,v, cW,cH,i,j);
  87818. h = z - z0;
  87819. }
  87820. z < lowest && (lowest = z); //上表面最低点
  87821. z > highest && (highest = z); //上表面最高点
  87822. if(h>0){
  87823. Vupper += h;
  87824. upperHeights.push(h); //
  87825. }else {
  87826. Vlower += -h;
  87827. lowerHeights.push(h);
  87828. }
  87829. col.push(h);
  87830. }
  87831. if(interrupt){
  87832. return (reject(), computeFinish('re 023'))
  87833. }
  87834. //notify(notifyArea, (u*this.renderTarget.height + v) /(this.renderTarget.width*this.renderTarget.height))
  87835. }
  87836. allHeights.push(col);
  87837. await notify(notifyArea, ()=>{return u / this.renderTarget.width}, 'readPixels get');
  87838. }
  87839. Vupper*=sDelta;
  87840. Vlower*=sDelta;
  87841. infos.push({Vupper,Vlower,sDelta,upperHeights,lowerHeights,allHeights});
  87842. resolve();
  87843. };
  87844. //let finish , maxTime = 1e6
  87845. let progressEnd1 = math.linearClamp( this.camera.zoom, [1,1000], [0.8,0.2]); //放得越大,实际加载的点云相对越少,费时越少
  87846. let notifyArea_ = [...notifyArea, [0, progressEnd1]];
  87847. if(Potree.pointsLoading ){ //如果有要加载的node
  87848. let curProgress = 0, beginTime = Date.now(), unloadBefore,
  87849. tryPreLoadTime = Math.round(math.linearClamp(buffer1.length/this.camera.zoom/this.camera.zoom, [50,10000],[1000,15000]));
  87850. //console.log('tryPreLoadTime',tryPreLoadTime)
  87851. let decreaseLevel = ()=>{ //降点云level
  87852. //暂时先都一起降1
  87853. let pointclouds = viewer.scene.pointclouds.filter(e=>e.visibleNodes.length);
  87854. console.log('准备decreaseLevel, numVisiblePoints', Potree.numVisiblePoints, '最小numVisiblePoints占比', 1/pointclouds.length );
  87855. pointclouds.forEach(e=>{
  87856. let percent = e.numVisiblePoints / Potree.numVisiblePoints;
  87857. console.log('numVisiblePoints占总比', e.dataset_id, percent );
  87858. if(percent < 1/pointclouds.length)return
  87859. let old = e.maxLevel;
  87860. let levels = e.visibleNodes.map(e=>e.getLevel());
  87861. let actMaxLevel = Math.max.apply(null, levels); //实际加载到的最高的node level
  87862. e.maxLevel = actMaxLevel - 1;
  87863. console.warn(e.dataset_id,'decreaseLevel,新maxLevel', actMaxLevel - 1, '原maxlevel', old );
  87864. //this.material.size = this.getPointsize(e.maxLevel)
  87865. //this.material.size *= 2
  87866. });
  87867. };
  87868. let finish = (makeit)=>{
  87869. //viewer.removeEventListener('overPointBudget',decreaseLevel)
  87870. makeit && done();
  87871. viewer.removeEventListener('update',update);
  87872. viewer.removeEventListener('pointsLoaded',loaded);
  87873. };
  87874. let update = ()=>{
  87875. Potree.updatePointClouds(viewer.scene.pointclouds, camera, viewport.resolution );
  87876. /* if( Potree.numVisiblePoints > maxPointBudge * 0.9){
  87877. decreaseLevel()
  87878. */
  87879. notify(notifyArea_, ()=>{
  87880. /* console.log('unloadedGeometry',Potree.unloadedGeometry.length)
  87881. return curProgress */
  87882. /* curProgress = THREE.Math.clamp(Potree.numVisiblePoints/predictPointCount,curProgress,1) //如果decreaseLevel了点会减少,也不管它,就停住吧,反正很快就加载好了
  87883. return curProgress */
  87884. if(!unloadBefore && Date.now() - beginTime < tryPreLoadTime){
  87885. curProgress = (Date.now() - beginTime) / tryPreLoadTime * 0.5;
  87886. }else {
  87887. if(!unloadBefore){
  87888. unloadBefore = Potree.unloadedGeometry.length;
  87889. //console.log('unloadBefore', unloadBefore)
  87890. }
  87891. unloadBefore = Math.max(Potree.unloadedGeometry.length, unloadBefore); //unloadedGeometry 刚开始可能越涨越多 - - 所以进度条会卡住
  87892. let curProgress_ = 0.5 + 0.5 * (1 - Potree.unloadedGeometry.length / unloadBefore );
  87893. curProgress = Math.max(curProgress,curProgress_);
  87894. }
  87895. //console.log('curProgress ', curProgress, 'numVisiblePoints', Potree.numVisiblePoints, 'unloadedGeometry',Potree.unloadedGeometry.length)
  87896. return curProgress
  87897. }, 'loadpoints');
  87898. interrupt && (finish(false), reject(), computeFinish('正在loadPoints,unloadedGeometry个数'+Potree.unloadedGeometry.length )); //曾经遇到遇到bug 不发送pointsLoaded 一直update 一直有3个unloadedGeometry加载不了。。 是否为每个加载的node加个计时?
  87899. };
  87900. viewer.addEventListener('update',update);
  87901. let loaded = ()=>{ //点云加载完时(不一定准确)
  87902. console.warn('加载完毕', ' numVisiblePoints', Potree.numVisiblePoints );
  87903. finish(true);
  87904. };
  87905. viewer.addEventListener('pointsLoaded', loaded);
  87906. /* let predictPointCount = Math.round(math.linearClamp(buffer.length, [1e5, maxWidth*maxWidth*4],[1e6, maxPointBudge ]))//最终要加载到的数目
  87907. */
  87908. /* let overTime = ()=>{
  87909. if(document.hidden){
  87910. return setTimeout(overTime, maxTime)
  87911. }
  87912. if(!finish)console.warn('超时, numVisiblePoints', Potree.numVisiblePoints)
  87913. dealDone()
  87914. }
  87915. setTimeout(overTime, maxTime) */
  87916. }else {
  87917. notify(notifyArea_, 1);
  87918. done();
  87919. }
  87920. })
  87921. }
  87922. convertColorToHeight(color, zMin, zMax){
  87923. let percent = 0;
  87924. let a = 1;
  87925. for(let i=0;i<3;i++){
  87926. a = i == 2 ? a/255 : a / 256;
  87927. percent += a * color[i];
  87928. }
  87929. let height = (zMax - zMin) * percent;
  87930. return height + zMin;
  87931. }
  87932. getPointsize(maxLevel){//尽量铺满 size单位是米,需要和点云缝隙同宽
  87933. return 0.01 /* adaptive:0.2 */
  87934. let s = /* this.material.spacing */ 100 / Math.pow(2, maxLevel - 1); //adaptive的话在shader中已经乘了spacing
  87935. console.log('getPointsize', s, 'maxLevel',maxLevel);
  87936. return s //会不会直接返回1就好?
  87937. //不能太小。假如gl_pointsize计算结果是0.1,那么显示就是1px;当level将级后,放大2倍为0.2,也还是1px,看起来就稀疏了。所以要保证这个数在最大level时gl_pointsize计算结果差不多是1px.(虽然我会在渲染大尺寸面积时降画布尺寸,但不能保证刚刚好,且因点云个数不可控不会降尺寸太狠)
  87938. }
  87939. download(prisms){
  87940. if(this.prisms.length == 0){
  87941. return null
  87942. }
  87943. var visiPointclouds = viewer.scene.pointclouds.filter(e=> Potree.Utils.getObjVisiByReason(e, 'datasetSelection'));
  87944. visiPointclouds.sort((a,b)=>{return a.dataset_id-b.dataset_id});//缓存需要固定排序好比较
  87945. let data = {
  87946. transformation_matrix: visiPointclouds.map((cloud)=>{
  87947. let data = {
  87948. id: cloud.dataset_id,
  87949. matrix: new Matrix4().elements, //参照downloadNoCrop,给默认值,表示没有最外层裁剪
  87950. visiMatrixes: prisms.map(prism=>{return {
  87951. matrix: prism.getTransformationMatrix(cloud).elements,//剪裁框
  87952. points: prism.points.map(p=>{return {x:p.x, y:p.y}})
  87953. }}),
  87954. modelMatrix:(new Matrix4).copy(cloud.transformMatrix).transpose().elements
  87955. };
  87956. return data
  87957. }) ,
  87958. aabb: "b-12742000 -12742000 -12742000 12742000 12742000 12742000" //剪裁空间
  87959. };
  87960. return data
  87961. }
  87962. //体积多边形棱柱,z需要变换到-0.5 ~ 0.5
  87963. }
  87964. /* VolumeComputer.prototype.setClipBoxes = function(){
  87965. let lastPrisms = []
  87966. return function(){
  87967. let prismPolygons = this.prisms.filter(e=>!e.isNew && e.visible)
  87968. let prismList = [], prismPoints = [], maxPointsCount
  87969. if(prismPolygons.length){
  87970. let pointsCount = prismPolygons.pointsCount = prismPolygons.reduce((w,c)=>{return w+c.points.length},0)
  87971. prismList = new Float32Array(9 * prismPolygons.length);
  87972. prismPoints = new Float32Array(2 * pointsCount);
  87973. prismPolygons.maxPointsCount = 0//单个prism最大点个数
  87974. if(!this.entered)this.enter()
  87975. let pointIndex = 0
  87976. for(let i=0;i<prismPolygons.length;i++ ){
  87977. let bound = prismPolygons[i].prismBound
  87978. let z = prismPolygons[i].horizonZ
  87979. //z = Potree.browser.urlHasValue('zmin',true) || zs[0]
  87980. 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);
  87981. //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 ]))
  87982. for(let j=0;j<prismPolygons[i].points.length;j++){
  87983. prismPoints.set([prismPolygons[i].points[j].x, prismPolygons[i].points[j].y] , 2*j+pointIndex);
  87984. //prismPoints.push( new THREE.Vector2().copy(prismPolygons[i].points[j]))
  87985. }
  87986. pointIndex += 2 * prismPolygons[i].points.length
  87987. prismPolygons.maxPointsCount = Math.max(prismPolygons.maxPointsCount, prismPolygons[i].points.length)
  87988. }
  87989. }
  87990. let doUpdate = ( lastPrisms.length != prismPolygons.length) || lastPrisms.maxPointsCount != prismPolygons.maxPointsCount
  87991. let materials = viewer.scene.pointclouds.map(e=>e.material).concat([this.material])
  87992. materials.forEach(e=>{
  87993. e.uniforms.prismList.value = prismList
  87994. e.uniforms.prismPoints.value = prismPoints
  87995. e.shaderNeedsUpdate = e.shaderNeedsUpdate || doUpdate
  87996. e.prisms = prismPolygons
  87997. })
  87998. //修改obj材质
  87999. this.material.defines.num_prism = this.material.prisms.length//土方量数
  88000. this.material.defines.prismPointCountSum = this.material.prisms.pointsCount //点总个数
  88001. this.material.defines.prism_maxPointsCount = this.material.prisms.maxPointsCount //单个prism最大点个数
  88002. if(doUpdate){
  88003. this.material.needsUpdate = true
  88004. viewer.dispatchEvent('content_changed')
  88005. }
  88006. lastPrisms = prismPolygons
  88007. }
  88008. }(); */
  88009. /*
  88010. 渲染像素pxPerMetric越高,边缘越细腻、准确; 点size越小,越不容易遮盖住下方点云,造成体积偏大。但会不会有底部点云透出来?
  88011. 该版本计算用到两张截图,第一张为整体的俯视图,包括挖方和填方;第二张仅包含填方。
  88012. 缺陷:在补洞时,只利用第一张图的结果,所以整体的挖方会偏多,填方偏少(因为在挖方填方同时存在时,没有分别补挖方和填方,而是放在一起,而上方可能遮盖下方的)
  88013. 尝试过第一张只绘制挖方部分,但是在遍历时就需要多遍历一次,测得的用时更多一些,结果却没变化
  88014. 也尝试过补洞时挖方填方分别补各自的,但这样要考虑更多的东西,用时多了两倍以上。(因为目前规定无论范围内实际有没有点云都补上,非挖即填;如果分开的话,填方边缘也都补上肯定是错的,无法找到挖和填的界限,无法分清是只有挖还是填还是两者均有。如果要探测周围点,耗时很多)
  88015. 如果数据集修改了,土方量需要手动重算。所以场景刷新后显示的体积有可能是错的。
  88016. 之前记的,太麻烦了,延期处理:
  88017. 1 一般情况:我需要记录每个土方量范围内存在的数据集的位置,如
  88018. {datasetId:"1745733728954093568", location:[113.59550104511611, 22.36677932324081, 0] ,orientation: 0.1}
  88019. 如果刷新后土方量范围内存在的数据集发生改变,将重算。
  88020. 数据集也可能显示或隐藏
  88021. 2 其他特殊情况,如裁剪,难以知道裁剪了哪块,所以只能全部重算
  88022. ------------------
  88023. baseModel 基于模型的挖方填方
  88024. 由于模型高度不一致,只能把相机放最高处朝下看,而无法像prism那样在horizonZ处再渲染一张,所以更加不能有多层点云干扰。
  88025. 如模型在一个房间屋顶上方,那么填方会得到两个高度,屋顶和地板的高度,地板是从屋顶的点云缝隙而得。
  88026. 如果模型放房间中间,并不能按理想的那样得到其上的挖方和其下的填方,因为相机朝下看时屋顶会遮住屋底,导致填方减少挖方增多。虽然能在bound底部朝上再拍一张,但若是有更复杂的情况依旧不能保证正确。
  88027. 故需要设置好zMin zMax
  88028. 如果模型有可能很大,但数据集不大,可以将bound只取交集
  88029. */
  88030. const texLoader$d = new TextureLoader();
  88031. const circleGeo = new CircleGeometry(1.45,100);
  88032. const sphereGeo$1 = new SphereBufferGeometry(0.008,8,8);
  88033. const magDisMin = 1;//相机离目标位置的距离的分界线,当离得远时要缩小fov以使看到的视野固定(望远镜效果)
  88034. const magDisMax = 20;
  88035. /* const radius_ = 0.2; //当相机离目标位置的距离>magDistance_时,希望看到的视野的半径
  88036. const maxFov = THREE.Math.radToDeg(Math.atan(radius_ / magDisMin )) * 2//提前计算出当相机离目标位置的距离<magDisMin时的fov,均使用=magDisMin时的fov。只要保证该fov大于主相机的fov就会有放大效果
  88037. */
  88038. let w$1 = 230/1.43;
  88039. let maxPX = 1366*1024; //ipad pro. 大于这个分辨率的就直接用devicePixelRatio, 如macbook也是
  88040. const width2dPX = Math.round(window.devicePixelRatio >= 2 ? ( window.screen.width * window.screen.height >= maxPX ? window.devicePixelRatio/1.2 : window.devicePixelRatio/1.5)*w$1 : w$1); //触屏或高分辨率的可能要放大些。但在手机上不能太大
  88041. //console.log('width2dPX', width2dPX)
  88042. const orthoView = new ExtendView();
  88043. class Magnifier extends Object3D {//放大镜or望远镜
  88044. constructor (viewer) {
  88045. super();
  88046. this.width = this.height = width2dPX/* * window.devicePixelRatio */;
  88047. this.camera = new PerspectiveCamera(50, 1, 0.01, 10000); //fov aspect near far
  88048. this.camera.up = new Vector3(0,0,1);
  88049. this.viewport = new Viewport( null, this.camera, {
  88050. left:0, bottom:0, width:1, height: 1, name:'magnifier' , cameraLayers:['magnifierContent'],
  88051. pixelRatio:1
  88052. });
  88053. this.viewport.setResolution(this.width, this.height,0,0);
  88054. {
  88055. let density;
  88056. let sizeType;
  88057. let colorType;
  88058. let opacityBefore = new Map();
  88059. let sizeBefore = new Map();
  88060. let visiMap = new Map();
  88061. this.viewport.beforeRender = ()=>{
  88062. viewer.scene.pointclouds.forEach(e=>{//因为更改pointDensity时会自动变opacity,所以这项最先获取
  88063. visiMap.set(e,e.visible);
  88064. e.visible = Potree.Utils.getObjVisiByReason(e, 'datasetSelection'); //先将隐藏的点云显示
  88065. opacityBefore.set(e,e.temp.pointOpacity);
  88066. sizeBefore.set(e,e.temp.pointSize);
  88067. });
  88068. //使放大镜里的pointDensity是'magnifier' 最高质量。
  88069. density = Potree.settings.pointDensity;
  88070. Potree.settings.pointDensity = 'magnifier';
  88071. viewer.scene.pointclouds.forEach(e=>{//因为全景模式的pointSizeType是fixed所以要还原下
  88072. sizeType = e.material.pointSizeType;
  88073. e.material.pointSizeType = Potree.config.material.pointSizeType;
  88074. //材质
  88075. colorType = e.material.activeAttributeName;
  88076. e.material.activeAttributeName = 'rgba';
  88077. e.changePointOpacity(1);
  88078. //e.changePointSize(Potree.config.material.realPointSize, true)
  88079. });
  88080. };
  88081. this.viewport.afterRender = ()=>{
  88082. Potree.settings.pointDensity = density;
  88083. viewer.scene.pointclouds.forEach(e=>{
  88084. e.visible = visiMap.get(e);
  88085. e.material.pointSizeType = sizeType;
  88086. e.material.activeAttributeName = colorType;
  88087. e.changePointOpacity(opacityBefore.get(e));
  88088. //e.changePointSize(sizeBefore.get(e))
  88089. });
  88090. };
  88091. }
  88092. this.renderTarget = new WebGLRenderTarget(this.width,this.height, {
  88093. minFilter: LinearFilter, magFilter: LinearFilter,
  88094. format: RGBAFormat ,
  88095. /* type: THREE.FloatType,
  88096. minFilter: THREE.NearestFilter,
  88097. magFilter: THREE.NearestFilter,
  88098. */
  88099. } );
  88100. this.rtEDL = new WebGLRenderTarget(this.width, this.height, { //好像没用到? 因为这里不绘制测量线
  88101. minFilter: NearestFilter,
  88102. magFilter: NearestFilter,
  88103. format: RGBAFormat,
  88104. type: FloatType,
  88105. depthTexture: new DepthTexture(undefined, undefined, UnsignedIntType)
  88106. });
  88107. this.mesh = new Mesh(circleGeo, new MeshBasicMaterial({
  88108. side: DoubleSide ,
  88109. map: this.renderTarget.texture ,
  88110. transparent:true,
  88111. depthTest: !1,
  88112. //depthWrite: !1,
  88113. }));
  88114. this.overlayMesh = new Mesh(circleGeo, new MeshBasicMaterial({
  88115. side: DoubleSide ,
  88116. map:texLoader$d.load(Potree.resourcePath+'/textures/crosshair.png') ,
  88117. transparent:true,
  88118. depthTest: !1,
  88119. //depthWrite: !1,
  88120. }));
  88121. this.targetPoint = new Object3D;
  88122. this.targetPoint.add(new Mesh(sphereGeo$1, new MeshBasicMaterial({
  88123. color:"#ff0000",
  88124. transparent:true,
  88125. opacity:0.7,
  88126. })));
  88127. this.targetPoint.add(new Mesh(sphereGeo$1, new MeshBasicMaterial({
  88128. color:"#ff0000",
  88129. transparent:true,
  88130. opacity:0.3,
  88131. depthTest:false //被遮挡层
  88132. })));
  88133. this.targetPoint.name = 'magnifierPointTarget';
  88134. viewer.scene.scene.add(this.targetPoint);
  88135. Potree.Utils.setObjectLayers(this.targetPoint, 'magnifierContent' );
  88136. this.add(this.mesh);
  88137. this.add(this.overlayMesh);
  88138. this.position.set(-1000,-1000,-100000);//令它看不见
  88139. this.mesh.renderOrder = Potree.config.renderOrders.magnifier;
  88140. this.overlayMesh.renderOrder = Potree.config.renderOrders.magnifier+1;
  88141. this.aimPos;
  88142. Potree.Utils.setObjectLayers(this, 'magnifier' );
  88143. //viewer.inputHandler.addInputListener(this)
  88144. viewer.addEventListener('camera_changed',(e)=>{ // 平移、滚轮时更新
  88145. if(e.viewport == viewer.mainViewport) this.update(); //不过intersectPoint没更新
  88146. });
  88147. this.mesh.layers.set(Potree.config.renderLayers.magnifier);
  88148. this.overlayMesh.layers.set(Potree.config.renderLayers.magnifier);
  88149. //this.layers.set(Potree.config.renderLayers.magnifier);//这句在外层写没用
  88150. this.dontRender = false;
  88151. viewer.addEventListener('global_drag', (e)=>{//拖拽时不渲染。主要是右键平移时渲染延迟了,会闪烁。
  88152. this.dontRender = true;
  88153. });
  88154. viewer.addEventListener('global_drop', (e)=>{
  88155. this.dontRender = false;
  88156. });
  88157. viewer.addEventListener('global_mouseup', (e)=>{//测量时拖拽场景再mouseup
  88158. this.dontRender = false;
  88159. });
  88160. var updateVisi = (e)=>{
  88161. if(e.hoverViewport == viewer.mainViewport){
  88162. Potree.Utils.updateVisible(this,"atViewport", true);
  88163. this.update(e.intersect && e.intersect.location);
  88164. }else {
  88165. Potree.Utils.updateVisible(this,"atViewport", false); //小地图不显示
  88166. }
  88167. };
  88168. viewer.addEventListener('global_mousemove', updateVisi);
  88169. viewer.addEventListener('global_touchstart', updateVisi);
  88170. viewer.addEventListener('updateMagnifier', updateVisi);
  88171. /* viewer.addEventListener("beginSplitView",()=>{
  88172. this.updateVisible("splitView", false)
  88173. })
  88174. viewer.addEventListener("finishSplitView",()=>{
  88175. this.updateVisible("splitView", true)
  88176. }) */
  88177. this.addEventListener("setEnable",(e)=>{
  88178. Potree.Utils.updateVisible(this, "enable", e.value); //界面开关
  88179. /* if(Potree.settings.displayMode == 'showPanos') && e.value){
  88180. Potree.settings.pointDensity = 'magnifier'
  88181. }else if() */
  88182. viewer.dispatchEvent('content_changed');
  88183. });
  88184. if(Potree.settings.isOfficial){
  88185. Potree.Utils.updateVisible(this, "enable", false);
  88186. }else {
  88187. Potree.Utils.updateVisible(this, "measure", false);
  88188. viewer.addEventListener("measureMovePoint",()=>{//测量开始
  88189. //Potree.Utils.updateVisible(this, "measure", true)
  88190. });
  88191. viewer.addEventListener("endMeasureMove",()=>{
  88192. Potree.Utils.updateVisible(this, "measure", false);
  88193. viewer.dispatchEvent('content_changed');
  88194. });
  88195. }
  88196. this.addEventListener('isVisible',(e)=>{
  88197. if(!this.visible) Potree.settings.pointDensity = Potree.settings.pointDensity; //恢复pointBudget
  88198. });
  88199. viewer.scene.view.addEventListener('flyingDone',()=>{
  88200. if(!this.visible)return
  88201. let pickWindowSize = 100;
  88202. let intersect = viewer.inputHandler.getIntersect({viewport:viewer.mainViewport, usePointcloud:true, pickWindowSize} );
  88203. this.update(intersect && intersect.location);
  88204. });
  88205. }
  88206. //注意:在鼠标没有移动的时候,无法获取到最新的intersect, 放大镜内的内容可能是错误的。全景模式下更奇怪,原因未知
  88207. update(aimPos){//相机靠近 navvis的做法
  88208. var dontRender = this.dontRender || !(aimPos instanceof Vector3) || Potree.settings.displayMode == 'showPanos' && viewer.images360.flying;
  88209. aimPos = aimPos instanceof Vector3 ? aimPos : this.aimPos;
  88210. if(!aimPos || !this.visible)return
  88211. var playerCamera = viewer.scene.getActiveCamera();
  88212. var playerPos = playerCamera.position;//viewer.scene.view.getPivot()
  88213. var dis = playerPos.distanceTo(aimPos);
  88214. var dirToCamera = new Vector3().subVectors(playerPos, aimPos ).normalize();
  88215. const fareast = 300;
  88216. //相机位置
  88217. if(playerCamera.type == 'OrthographicCamera'){
  88218. var finalDisToAim = 2;
  88219. }else {
  88220. var finalDisToAim = dis>magDisMin ? dis > fareast ? magDisMax : (dis-magDisMin) / (fareast-magDisMin) * (magDisMax-magDisMin) + magDisMin : dis / 2; //dis>magDistance_ ? magDistance_ : dis / 2;
  88221. }
  88222. this.camera.fov = playerCamera.type == 'OrthographicCamera' ? 30 : playerCamera.fov / 2;
  88223. this.camera.updateProjectionMatrix();
  88224. if(playerCamera.type == 'OrthographicCamera'){
  88225. orthoView.position.copy(aimPos).sub(viewer.mainViewport.view.direction.multiplyScalar(finalDisToAim));
  88226. orthoView.yaw = viewer.mainViewport.view.yaw;
  88227. orthoView.pitch = viewer.mainViewport.view.pitch;
  88228. orthoView.applyToCamera(this.camera);
  88229. }else {
  88230. this.camera.position.copy(aimPos).add(dirToCamera.multiplyScalar(finalDisToAim));
  88231. this.camera.lookAt(aimPos);
  88232. }
  88233. //自身位置
  88234. //let pos2d = viewer.inputHandler.pointer.clone(); //跟随鼠标
  88235. let pos2d_ = Potree.Utils.getPos2d(aimPos, viewer.mainViewport, viewer.renderArea); //更新目标点的实时二维位置
  88236. let pos2d = pos2d_.vector;
  88237. let margin = width2dPX*1.1 / viewer.mainViewport.resolution2.y * 2; //确保到鼠标的间距占放大镜的比例不变(检查mobile、上下分屏后的变化)
  88238. let screenPos = pos2d.clone().setY(pos2d.y + (pos2d.y >0 ? -margin : margin ));
  88239. let newPos = new Vector3(screenPos.x,screenPos.y,0.8).unproject(playerCamera); //z:-1朝外
  88240. if(playerCamera.type != 'OrthographicCamera'){
  88241. let dir = newPos.clone().sub(playerPos).normalize().multiplyScalar(10);//这个数值要大于playerCamera.near
  88242. this.position.copy(playerPos.clone().add(dir));
  88243. }else {
  88244. viewer.navCubeViewer.splitScreen.setShiftTarget(viewer.mainViewport, viewer.bound.center);
  88245. viewer.mainViewport.targetPlane.setFromNormalAndCoplanarPoint( viewer.mainViewport.view.direction.clone(), viewer.bound.center );
  88246. viewer.mainViewport.targetPlane.projectPoint(newPos, viewer.mainViewport.shiftTarget );
  88247. this.position.copy(viewer.mainViewport.shiftTarget.clone() );
  88248. //this.position.copy(playerPos.clone().add(dir))
  88249. }
  88250. let s = finalDisToAim * this.camera.fov / 30;
  88251. this.quaternion.copy(playerCamera.quaternion);
  88252. this.targetPoint.position.copy(aimPos);
  88253. this.targetPoint.scale.set(s,s,s);
  88254. this.aimPos = aimPos;
  88255. var scale = math.getScaleForConstantSize({//
  88256. width2d : width2dPX,
  88257. camera:viewer.scene.getActiveCamera(), position: this.getWorldPosition(new Vector3()),
  88258. resolution: viewer.mainViewport.resolution2
  88259. });
  88260. this.scale.set(scale, scale, scale);
  88261. if(!dontRender){
  88262. this.waitRender = true;
  88263. }
  88264. viewer.dispatchEvent('content_changed');
  88265. }
  88266. /* update(aimPos){ //仅改fov的版本
  88267. aimPos = aimPos instanceof THREE.Vector3 ? aimPos : this.aimPos
  88268. if(!aimPos || !this.visible)return
  88269. //相机位置
  88270. var playerCamera = viewer.scene.getActiveCamera()
  88271. var playerPos = playerCamera.position;//viewer.scene.view.getPivot()
  88272. var dis = playerPos.distanceTo(aimPos);
  88273. if(dis<magDisMin){
  88274. this.camera.fov = maxFov
  88275. }else{
  88276. this.camera.fov = THREE.Math.radToDeg(Math.atan(radius_ / dis )) * 2 //radius_是能看到的范围半径。当dis大于magDisMin时就放大,否则维持fov为maxFov
  88277. }
  88278. this.camera.updateProjectionMatrix()
  88279. this.camera.position.copy(playerPos)
  88280. this.camera.lookAt(aimPos)
  88281. this.quaternion.copy(playerCamera.quaternion);
  88282. let pointer = viewer.inputHandler.pointer.clone();
  88283. let margin = 0.4, maxY = 0.4
  88284. let screenPos = pointer.clone().setY(pointer.y + (pointer.y>maxY ? -margin : margin ))
  88285. let newPos = new THREE.Vector3(screenPos.x,screenPos.y,0.8).unproject(playerCamera); //z:-1朝外
  88286. let dir = newPos.clone().sub(playerPos).normalize().multiplyScalar(10);//这个数值要大于playerCamera.near
  88287. this.position.copy(playerPos.clone().add(dir))
  88288. this.aimPos = aimPos
  88289. this.targetPoint.position.copy(aimPos);
  88290. var scale = math.getScaleForConstantSize({//
  88291. width2d : width2dPX,
  88292. camera:viewer.scene.getActiveCamera(), position: this.getWorldPosition(new THREE.Vector3()),
  88293. resolution: viewer.mainViewport.resolution2
  88294. })
  88295. this.scale.set(scale, scale, scale);
  88296. if(!this.dontRender){
  88297. this.waitRender = true
  88298. }
  88299. }//位置需要计算,不仅仅是点云,所以需要深度图
  88300. */
  88301. render(){
  88302. if(!this.visible || !this.waitRender && !viewer.needRender)return //viewer.needRender为true要渲染是因为可能是点云node加载完
  88303. viewer.render({
  88304. target : this.renderTarget,
  88305. viewports : [this.viewport],
  88306. camera : this.camera,
  88307. magnifier : true,
  88308. rtEDL: this.rtEDL
  88309. /* width :this.renderTarget.width,
  88310. height: this.renderTarget.height, */
  88311. });
  88312. this.waitRender = false;
  88313. viewer.dispatchEvent('content_changed');
  88314. }
  88315. }
  88316. /*
  88317. 如果遇到放大镜内点云很不正常,应该是深度图错误(可能全景和点云没匹配上)。
  88318. */
  88319. let texLoader$e = new TextureLoader();
  88320. let defaultOpacity = 0.6;
  88321. let Buttons$2 = Potree.defines.Buttons;
  88322. //鼠标指示小圆片
  88323. class Reticule extends Mesh{
  88324. constructor(viewer){
  88325. var defaultTex = texLoader$e.load(Potree.resourcePath+'/textures/whiteCircle.png'/* reticule-256x256.png' */);
  88326. super(new PlaneBufferGeometry(0.11,0.11,1,1),new MeshBasicMaterial({
  88327. side: DoubleSide ,
  88328. map: defaultTex,
  88329. transparent:true,
  88330. depthTest: !1,
  88331. opacity: defaultOpacity,
  88332. //depthWrite: !1,
  88333. }));
  88334. this.name = 'reticule';
  88335. this.defaultTex = defaultTex;
  88336. this.crosshairTex = texLoader$e.load(Potree.resourcePath+'/textures/reticule_cross_hair.png');
  88337. this.forbitTex = texLoader$e.load(Potree.resourcePath+'/textures/pic-forbid.png');
  88338. this.defaultTex.anisotropy = 4;
  88339. this.crosshairTex.anisotropy = 4;
  88340. this.forbitTex.anisotropy = 4;
  88341. //this.layers.set(0/* RenderLayers.RETICULE */);
  88342. this.renderOrder = Potree.config.renderOrders.reticule;
  88343. this.layers.set(Potree.config.renderLayers.marker);
  88344. this.direction = new Vector3;
  88345. this.mouseLastMoveTime = Date.now();
  88346. this.hoverViewport;
  88347. this.matrixMap = new Map;
  88348. this.matrixAutoUpdate = false;
  88349. this.hide(0);
  88350. //viewer.inputHandler.addInputListener(this);
  88351. Potree.settings.intersectWhenHover && viewer.addEventListener('global_mousemove',this.move.bind(this));
  88352. //viewer.addEventListener('global_click',this.move.bind(this))
  88353. viewer.addEventListener('global_mousedown',this.move.bind(this));//主要针对触屏
  88354. this.state = {};
  88355. let startCrossStyle = ()=>{
  88356. this.state.cross = true;
  88357. this.judgeTex();
  88358. };
  88359. let endCrossStyle = ()=>{
  88360. this.state.cross = false;
  88361. this.judgeTex();
  88362. };
  88363. viewer.addEventListener('measureMovePoint',startCrossStyle);
  88364. viewer.addEventListener('endMeasureMove',endCrossStyle);
  88365. viewer.addEventListener('startBuildEntity',startCrossStyle);
  88366. viewer.addEventListener('endBuildEntity',endCrossStyle);
  88367. viewer.addEventListener('start_inserting_tag',startCrossStyle);
  88368. viewer.addEventListener('endTagMove',endCrossStyle);
  88369. viewer.addEventListener('reticule_forbit',(e)=>{
  88370. if(this.state.forbit != e.v){
  88371. console.log('change forbit ',e.v);
  88372. }
  88373. this.state.forbit = e.v;
  88374. this.judgeTex();
  88375. });
  88376. Potree.Utils.setObjectLayers(this, 'sceneObjects' );
  88377. }
  88378. judgeTex(){
  88379. if(this.state.forbit){
  88380. this.material.map = this.forbitTex;
  88381. }else if(this.state.cross){
  88382. this.material.map = this.crosshairTex;
  88383. }else {
  88384. this.material.map = this.defaultTex;
  88385. }
  88386. viewer.mapViewer && viewer.mapViewer.dispatchEvent({type:'content_changed'});
  88387. }
  88388. move(e){
  88389. if(e.type == "global_mousemove" && (e.isTouch || e.buttons != Buttons$2.NONE) && !this.state.cross){
  88390. return//按下时不更新,除非拖拽测量
  88391. }
  88392. this.mouseLastMoveTime = Date.now();
  88393. this.updatePosition(e.intersect, e.hoverViewport);
  88394. }
  88395. hide(duration = 500){
  88396. if(this.hidden)return
  88397. this.hidden = !0;
  88398. transitions.start(lerp.property(this.material , "opacity", 0, ()=>{//progress
  88399. this.dispatchEvent({type:'update' });
  88400. //viewer.dispatchEvent('content_changed')
  88401. }), duration,()=>{//done
  88402. this.dispatchEvent({type:'update', visible:false});
  88403. });
  88404. this.dispatchEvent({type:'update', visible:false});
  88405. setTimeout(()=>{
  88406. },duration);
  88407. }
  88408. show(duration = 300){
  88409. if(!Potree.Utils.getObjVisiByReason(this, 'force'))return
  88410. //console.log("show Reticule")
  88411. this.hidden = !1;
  88412. if(this.material.opacity <= 0){
  88413. transitions.start(lerp.property(this.material, "opacity", defaultOpacity, ()=>{//progress
  88414. this.dispatchEvent({type:'update' });
  88415. //viewer.dispatchEvent('content_changed')
  88416. }), duration,()=>{//done
  88417. this.dispatchEvent({type:'update', visible:false});
  88418. });
  88419. this.dispatchEvent({type:'update', visible:true});
  88420. }
  88421. }
  88422. //鼠标静止一段时间它就会消失
  88423. updateVisible(){
  88424. Date.now() - this.mouseLastMoveTime > 1500 && !this.hidden && this.hide();
  88425. }
  88426. updateScale(viewport){
  88427. let s, camera = viewport.camera;
  88428. if(camera.type == "OrthographicCamera"){
  88429. var sizeInfo = this.state.cross ? {width2d:500} : {minSize : 100, maxSize : 400, nearBound : 100 , farBound : 700};
  88430. s = math.getScaleForConstantSize($.extend( sizeInfo ,
  88431. {position:this.position, camera, resolution:viewport.resolution/* 2 */} ));
  88432. }else {
  88433. let n = camera.position.distanceTo(this.position);
  88434. s = 0.8 * Math.log2(n+1); //底数为2 ( Math.log()底数为e )
  88435. if(this.state.cross ){ //测量时更精细些
  88436. s /= viewer.images360.zoomLevel;
  88437. }
  88438. }
  88439. this.scale.set(s, s, s);
  88440. }
  88441. updateAtViewports(viewport){//当多个viewports时更新。更新大小等
  88442. if(viewport.name == 'magnifier' )return
  88443. if(this.orthoPos && this.hoverViewport && this.hoverViewport.name == 'mapViewport' && viewport != this.hoverViewport){
  88444. //若是在地图上更新,在其他viewport要隐藏。因为在地图上无法得知高度。
  88445. Potree.Utils.updateVisible(this, 'hoverMap', false);
  88446. return;
  88447. }
  88448. Potree.Utils.updateVisible(this, 'hoverMap', true);
  88449. if(viewport.name == 'mapViewport'){
  88450. Potree.Utils.setObjectLayers(this, "bothMapAndScene");
  88451. }else {//通常地图不显示reticule,只有在特殊编辑时才显示
  88452. Potree.Utils.setObjectLayers(this, 'sceneObjects');
  88453. }
  88454. var matrix = this.matrixMap.get(viewport);
  88455. if(!matrix){
  88456. this.updateScale(viewport);
  88457. this.updateMatrix();
  88458. //this.updateMatrixWorld()
  88459. this.matrixMap.set(viewport, this.matrix.clone());
  88460. }else {
  88461. this.matrix.copy(matrix);
  88462. //this.updateMatrixWorld()
  88463. }
  88464. }
  88465. updatePosition(intersect, viewport ){ //在地图(当地图融合到viewer时)和场景里都显示且完全相同(大小可能不同)
  88466. if (Potree.Utils.getObjVisiByReason(this, 'force')) {//没有被强制隐藏,如进入某个页面后强制不显示
  88467. if (!intersect /* || !intersect.point.normal */){
  88468. return //this.hide();
  88469. }
  88470. var atMap = !intersect.location;
  88471. let location = intersect.location || intersect.orthoIntersect.clone();
  88472. let normal;
  88473. this.orthoPos = atMap;
  88474. //地图上要瞬间变化 , 因为要使needRender为true很麻烦
  88475. this.show(atMap ? 0 : 300);
  88476. if(atMap){
  88477. normal = new Vector3(0,0,1);//地图无normal
  88478. location.setZ(0);//低于相机高度即可
  88479. this.direction = normal.clone();
  88480. }else {
  88481. /* if(intersect.point){
  88482. if(intersect.pointcloud){
  88483. normal = new THREE.Vector3().fromArray(intersect.point.normal ).applyMatrix4( intersect.pointcloud.rotateMatrix );
  88484. }else{//mesh
  88485. normal = new THREE.Vector3().copy(intersect.point.normal).applyQuaternion(intersect.object.quaternion)
  88486. }
  88487. }else{
  88488. normal = intersect.normal //when showPanos
  88489. } */
  88490. normal = intersect.normal;
  88491. if(normal){
  88492. let ratio = /* Potree.settings.useDepthTex ? 1 : */ 0.2;
  88493. this.direction = this.direction.multiplyScalar(1-ratio);
  88494. this.direction.add(normal.clone().multiplyScalar(ratio));
  88495. }
  88496. //this.direction = normal.clone() //改为瞬间变化,否则刚hover上某个点时看起来不太对
  88497. }
  88498. this.position.copy(location);/* .add(normal.clone().multiplyScalar(.01)); */
  88499. this.updateMatrix(); //lookAt之前要保证得到matrix
  88500. this.lookAt(this.position.clone().add(this.direction));
  88501. this.hoverViewport = viewport; //记录下最近一次hover过的viewport
  88502. this.updateScale(viewport);
  88503. {//存储matrix,节省计算
  88504. this.updateMatrix();
  88505. //this.updateMatrixWorld()
  88506. this.matrixMap.clear();//重新计算
  88507. this.matrixMap.set(viewport, this.matrix.clone());
  88508. //别处会updateMatrixWorld
  88509. }
  88510. this.dispatchEvent({type:'update'});
  88511. //为什么navvis在校准数据集时每个viewport里reticule的朝向都刚好垂直于屏幕,似乎限定在了一定范围内,还是在pick时就只pick范围内的点?
  88512. }
  88513. }
  88514. //navvis在地图等地方看reticule是有厚度的
  88515. /* updateMatrixWorld(force){
  88516. console.log('updateMatrixWorld', force)
  88517. super.updateMatrixWorld(force)
  88518. } */
  88519. }
  88520. var OBJLoader = ( function () {
  88521. // o object_name | g group_name
  88522. var object_pattern = /^[og]\s*(.+)?/;
  88523. // mtllib file_reference
  88524. var material_library_pattern = /^mtllib /;
  88525. // usemtl material_name
  88526. var material_use_pattern = /^usemtl /;
  88527. // usemap map_name
  88528. var map_use_pattern = /^usemap /;
  88529. var vA = new Vector3();
  88530. var vB = new Vector3();
  88531. var vC = new Vector3();
  88532. var ab = new Vector3();
  88533. var cb = new Vector3();
  88534. function ParserState() {
  88535. var state = {
  88536. objects: [],
  88537. object: {},
  88538. vertices: [],
  88539. normals: [],
  88540. colors: [],
  88541. uvs: [],
  88542. materials: {},
  88543. materialLibraries: [],
  88544. startObject: function ( name, fromDeclaration ) {
  88545. // If the current object (initial from reset) is not from a g/o declaration in the parsed
  88546. // file. We need to use it for the first parsed g/o to keep things in sync.
  88547. if ( this.object && this.object.fromDeclaration === false ) {
  88548. this.object.name = name;
  88549. this.object.fromDeclaration = ( fromDeclaration !== false );
  88550. return;
  88551. }
  88552. var previousMaterial = ( this.object && typeof this.object.currentMaterial === 'function' ? this.object.currentMaterial() : undefined );
  88553. if ( this.object && typeof this.object._finalize === 'function' ) {
  88554. this.object._finalize( true );
  88555. }
  88556. this.object = {
  88557. name: name || '',
  88558. fromDeclaration: ( fromDeclaration !== false ),
  88559. geometry: {
  88560. vertices: [],
  88561. normals: [],
  88562. colors: [],
  88563. uvs: [],
  88564. hasUVIndices: false
  88565. },
  88566. materials: [],
  88567. smooth: true,
  88568. startMaterial: function ( name, libraries ) {
  88569. var previous = this._finalize( false );
  88570. // New usemtl declaration overwrites an inherited material, except if faces were declared
  88571. // after the material, then it must be preserved for proper MultiMaterial continuation.
  88572. if ( previous && ( previous.inherited || previous.groupCount <= 0 ) ) {
  88573. this.materials.splice( previous.index, 1 );
  88574. }
  88575. var material = {
  88576. index: this.materials.length,
  88577. name: name || '',
  88578. mtllib: ( Array.isArray( libraries ) && libraries.length > 0 ? libraries[ libraries.length - 1 ] : '' ),
  88579. smooth: ( previous !== undefined ? previous.smooth : this.smooth ),
  88580. groupStart: ( previous !== undefined ? previous.groupEnd : 0 ),
  88581. groupEnd: - 1,
  88582. groupCount: - 1,
  88583. inherited: false,
  88584. clone: function ( index ) {
  88585. var cloned = {
  88586. index: ( typeof index === 'number' ? index : this.index ),
  88587. name: this.name,
  88588. mtllib: this.mtllib,
  88589. smooth: this.smooth,
  88590. groupStart: 0,
  88591. groupEnd: - 1,
  88592. groupCount: - 1,
  88593. inherited: false
  88594. };
  88595. cloned.clone = this.clone.bind( cloned );
  88596. return cloned;
  88597. }
  88598. };
  88599. this.materials.push( material );
  88600. return material;
  88601. },
  88602. currentMaterial: function () {
  88603. if ( this.materials.length > 0 ) {
  88604. return this.materials[ this.materials.length - 1 ];
  88605. }
  88606. return undefined;
  88607. },
  88608. _finalize: function ( end ) {
  88609. var lastMultiMaterial = this.currentMaterial();
  88610. if ( lastMultiMaterial && lastMultiMaterial.groupEnd === - 1 ) {
  88611. lastMultiMaterial.groupEnd = this.geometry.vertices.length / 3;
  88612. lastMultiMaterial.groupCount = lastMultiMaterial.groupEnd - lastMultiMaterial.groupStart;
  88613. lastMultiMaterial.inherited = false;
  88614. }
  88615. // Ignore objects tail materials if no face declarations followed them before a new o/g started.
  88616. if ( end && this.materials.length > 1 ) {
  88617. for ( var mi = this.materials.length - 1; mi >= 0; mi -- ) {
  88618. if ( this.materials[ mi ].groupCount <= 0 ) {
  88619. this.materials.splice( mi, 1 );
  88620. }
  88621. }
  88622. }
  88623. // Guarantee at least one empty material, this makes the creation later more straight forward.
  88624. if ( end && this.materials.length === 0 ) {
  88625. this.materials.push( {
  88626. name: '',
  88627. smooth: this.smooth
  88628. } );
  88629. }
  88630. return lastMultiMaterial;
  88631. }
  88632. };
  88633. // Inherit previous objects material.
  88634. // Spec tells us that a declared material must be set to all objects until a new material is declared.
  88635. // If a usemtl declaration is encountered while this new object is being parsed, it will
  88636. // overwrite the inherited material. Exception being that there was already face declarations
  88637. // to the inherited material, then it will be preserved for proper MultiMaterial continuation.
  88638. if ( previousMaterial && previousMaterial.name && typeof previousMaterial.clone === 'function' ) {
  88639. var declared = previousMaterial.clone( 0 );
  88640. declared.inherited = true;
  88641. this.object.materials.push( declared );
  88642. }
  88643. this.objects.push( this.object );
  88644. },
  88645. finalize: function () {
  88646. if ( this.object && typeof this.object._finalize === 'function' ) {
  88647. this.object._finalize( true );
  88648. }
  88649. },
  88650. parseVertexIndex: function ( value, len ) {
  88651. var index = parseInt( value, 10 );
  88652. return ( index >= 0 ? index - 1 : index + len / 3 ) * 3;
  88653. },
  88654. parseNormalIndex: function ( value, len ) {
  88655. var index = parseInt( value, 10 );
  88656. return ( index >= 0 ? index - 1 : index + len / 3 ) * 3;
  88657. },
  88658. parseUVIndex: function ( value, len ) {
  88659. var index = parseInt( value, 10 );
  88660. return ( index >= 0 ? index - 1 : index + len / 2 ) * 2;
  88661. },
  88662. addVertex: function ( a, b, c ) {
  88663. var src = this.vertices;
  88664. var dst = this.object.geometry.vertices;
  88665. dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
  88666. dst.push( src[ b + 0 ], src[ b + 1 ], src[ b + 2 ] );
  88667. dst.push( src[ c + 0 ], src[ c + 1 ], src[ c + 2 ] );
  88668. },
  88669. addVertexPoint: function ( a ) {
  88670. var src = this.vertices;
  88671. var dst = this.object.geometry.vertices;
  88672. dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
  88673. },
  88674. addVertexLine: function ( a ) {
  88675. var src = this.vertices;
  88676. var dst = this.object.geometry.vertices;
  88677. dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
  88678. },
  88679. addNormal: function ( a, b, c ) {
  88680. var src = this.normals;
  88681. var dst = this.object.geometry.normals;
  88682. dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
  88683. dst.push( src[ b + 0 ], src[ b + 1 ], src[ b + 2 ] );
  88684. dst.push( src[ c + 0 ], src[ c + 1 ], src[ c + 2 ] );
  88685. },
  88686. addFaceNormal: function ( a, b, c ) {
  88687. var src = this.vertices;
  88688. var dst = this.object.geometry.normals;
  88689. vA.fromArray( src, a );
  88690. vB.fromArray( src, b );
  88691. vC.fromArray( src, c );
  88692. cb.subVectors( vC, vB );
  88693. ab.subVectors( vA, vB );
  88694. cb.cross( ab );
  88695. cb.normalize();
  88696. dst.push( cb.x, cb.y, cb.z );
  88697. dst.push( cb.x, cb.y, cb.z );
  88698. dst.push( cb.x, cb.y, cb.z );
  88699. },
  88700. addColor: function ( a, b, c ) {
  88701. var src = this.colors;
  88702. var dst = this.object.geometry.colors;
  88703. if ( src[ a ] !== undefined ) dst.push( src[ a + 0 ], src[ a + 1 ], src[ a + 2 ] );
  88704. if ( src[ b ] !== undefined ) dst.push( src[ b + 0 ], src[ b + 1 ], src[ b + 2 ] );
  88705. if ( src[ c ] !== undefined ) dst.push( src[ c + 0 ], src[ c + 1 ], src[ c + 2 ] );
  88706. },
  88707. addUV: function ( a, b, c ) {
  88708. var src = this.uvs;
  88709. var dst = this.object.geometry.uvs;
  88710. dst.push( src[ a + 0 ], src[ a + 1 ] );
  88711. dst.push( src[ b + 0 ], src[ b + 1 ] );
  88712. dst.push( src[ c + 0 ], src[ c + 1 ] );
  88713. },
  88714. addDefaultUV: function () {
  88715. var dst = this.object.geometry.uvs;
  88716. dst.push( 0, 0 );
  88717. dst.push( 0, 0 );
  88718. dst.push( 0, 0 );
  88719. },
  88720. addUVLine: function ( a ) {
  88721. var src = this.uvs;
  88722. var dst = this.object.geometry.uvs;
  88723. dst.push( src[ a + 0 ], src[ a + 1 ] );
  88724. },
  88725. addFace: function ( a, b, c, ua, ub, uc, na, nb, nc ) {
  88726. var vLen = this.vertices.length;
  88727. var ia = this.parseVertexIndex( a, vLen );
  88728. var ib = this.parseVertexIndex( b, vLen );
  88729. var ic = this.parseVertexIndex( c, vLen );
  88730. this.addVertex( ia, ib, ic );
  88731. this.addColor( ia, ib, ic );
  88732. // normals
  88733. if ( na !== undefined && na !== '' ) {
  88734. var nLen = this.normals.length;
  88735. ia = this.parseNormalIndex( na, nLen );
  88736. ib = this.parseNormalIndex( nb, nLen );
  88737. ic = this.parseNormalIndex( nc, nLen );
  88738. this.addNormal( ia, ib, ic );
  88739. } else {
  88740. this.addFaceNormal( ia, ib, ic );
  88741. }
  88742. // uvs
  88743. if ( ua !== undefined && ua !== '' ) {
  88744. var uvLen = this.uvs.length;
  88745. ia = this.parseUVIndex( ua, uvLen );
  88746. ib = this.parseUVIndex( ub, uvLen );
  88747. ic = this.parseUVIndex( uc, uvLen );
  88748. this.addUV( ia, ib, ic );
  88749. this.object.geometry.hasUVIndices = true;
  88750. } else {
  88751. // add placeholder values (for inconsistent face definitions)
  88752. this.addDefaultUV();
  88753. }
  88754. },
  88755. addPointGeometry: function ( vertices ) {
  88756. this.object.geometry.type = 'Points';
  88757. var vLen = this.vertices.length;
  88758. for ( var vi = 0, l = vertices.length; vi < l; vi ++ ) {
  88759. var index = this.parseVertexIndex( vertices[ vi ], vLen );
  88760. this.addVertexPoint( index );
  88761. this.addColor( index );
  88762. }
  88763. },
  88764. addLineGeometry: function ( vertices, uvs ) {
  88765. this.object.geometry.type = 'Line';
  88766. var vLen = this.vertices.length;
  88767. var uvLen = this.uvs.length;
  88768. for ( var vi = 0, l = vertices.length; vi < l; vi ++ ) {
  88769. this.addVertexLine( this.parseVertexIndex( vertices[ vi ], vLen ) );
  88770. }
  88771. for ( var uvi = 0, l = uvs.length; uvi < l; uvi ++ ) {
  88772. this.addUVLine( this.parseUVIndex( uvs[ uvi ], uvLen ) );
  88773. }
  88774. }
  88775. };
  88776. state.startObject( '', false );
  88777. return state;
  88778. }
  88779. //
  88780. function OBJLoader( manager ) {
  88781. Loader.call( this, manager );
  88782. this.materials = null;
  88783. }
  88784. OBJLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  88785. constructor: OBJLoader,
  88786. load: function ( url, onLoad, onProgress, onError ) {
  88787. var scope = this;
  88788. var loader = new FileLoader( this.manager );
  88789. loader.setPath( this.path );
  88790. loader.setRequestHeader( this.requestHeader );
  88791. loader.setWithCredentials( this.withCredentials );
  88792. loader.load( url, function ( text , total ) {// xzw add total
  88793. try {
  88794. onLoad( scope.parse( text ) , total );
  88795. } catch ( e ) {
  88796. if ( onError ) {
  88797. onError( e );
  88798. } else {
  88799. console.error( e );
  88800. }
  88801. scope.manager.itemError( url );
  88802. }
  88803. }, onProgress, onError );
  88804. },
  88805. setMaterials: function ( materials ) {
  88806. this.materials = materials;
  88807. return this;
  88808. },
  88809. parse: function ( text ) {
  88810. var state = new ParserState();
  88811. if ( text.indexOf( '\r\n' ) !== - 1 ) {
  88812. // This is faster than String.split with regex that splits on both
  88813. text = text.replace( /\r\n/g, '\n' );
  88814. }
  88815. if ( text.indexOf( '\\\n' ) !== - 1 ) {
  88816. // join lines separated by a line continuation character (\)
  88817. text = text.replace( /\\\n/g, '' );
  88818. }
  88819. var lines = text.split( '\n' );
  88820. var line = '', lineFirstChar = '';
  88821. var lineLength = 0;
  88822. var result = [];
  88823. // Faster to just trim left side of the line. Use if available.
  88824. var trimLeft = ( typeof ''.trimLeft === 'function' );
  88825. for ( var i = 0, l = lines.length; i < l; i ++ ) {
  88826. line = lines[ i ];
  88827. line = trimLeft ? line.trimLeft() : line.trim();
  88828. lineLength = line.length;
  88829. if ( lineLength === 0 ) continue;
  88830. lineFirstChar = line.charAt( 0 );
  88831. // @todo invoke passed in handler if any
  88832. if ( lineFirstChar === '#' ) continue;
  88833. if ( lineFirstChar === 'v' ) {
  88834. var data = line.split( /\s+/ );
  88835. switch ( data[ 0 ] ) {
  88836. case 'v':
  88837. state.vertices.push(
  88838. parseFloat( data[ 1 ] ),
  88839. parseFloat( data[ 2 ] ),
  88840. parseFloat( data[ 3 ] )
  88841. );
  88842. if ( data.length >= 7 ) {
  88843. state.colors.push(
  88844. parseFloat( data[ 4 ] ),
  88845. parseFloat( data[ 5 ] ),
  88846. parseFloat( data[ 6 ] )
  88847. );
  88848. } else {
  88849. // if no colors are defined, add placeholders so color and vertex indices match
  88850. state.colors.push( undefined, undefined, undefined );
  88851. }
  88852. break;
  88853. case 'vn':
  88854. state.normals.push(
  88855. parseFloat( data[ 1 ] ),
  88856. parseFloat( data[ 2 ] ),
  88857. parseFloat( data[ 3 ] )
  88858. );
  88859. break;
  88860. case 'vt':
  88861. state.uvs.push(
  88862. parseFloat( data[ 1 ] ),
  88863. parseFloat( data[ 2 ] )
  88864. );
  88865. break;
  88866. }
  88867. } else if ( lineFirstChar === 'f' ) {
  88868. var lineData = line.substr( 1 ).trim();
  88869. var vertexData = lineData.split( /\s+/ );
  88870. var faceVertices = [];
  88871. // Parse the face vertex data into an easy to work with format
  88872. for ( var j = 0, jl = vertexData.length; j < jl; j ++ ) {
  88873. var vertex = vertexData[ j ];
  88874. if ( vertex.length > 0 ) {
  88875. var vertexParts = vertex.split( '/' );
  88876. faceVertices.push( vertexParts );
  88877. }
  88878. }
  88879. // Draw an edge between the first vertex and all subsequent vertices to form an n-gon
  88880. var v1 = faceVertices[ 0 ];
  88881. for ( var j = 1, jl = faceVertices.length - 1; j < jl; j ++ ) {
  88882. var v2 = faceVertices[ j ];
  88883. var v3 = faceVertices[ j + 1 ];
  88884. state.addFace(
  88885. v1[ 0 ], v2[ 0 ], v3[ 0 ],
  88886. v1[ 1 ], v2[ 1 ], v3[ 1 ],
  88887. v1[ 2 ], v2[ 2 ], v3[ 2 ]
  88888. );
  88889. }
  88890. } else if ( lineFirstChar === 'l' ) {
  88891. var lineParts = line.substring( 1 ).trim().split( ' ' );
  88892. var lineVertices = [], lineUVs = [];
  88893. if ( line.indexOf( '/' ) === - 1 ) {
  88894. lineVertices = lineParts;
  88895. } else {
  88896. for ( var li = 0, llen = lineParts.length; li < llen; li ++ ) {
  88897. var parts = lineParts[ li ].split( '/' );
  88898. if ( parts[ 0 ] !== '' ) lineVertices.push( parts[ 0 ] );
  88899. if ( parts[ 1 ] !== '' ) lineUVs.push( parts[ 1 ] );
  88900. }
  88901. }
  88902. state.addLineGeometry( lineVertices, lineUVs );
  88903. } else if ( lineFirstChar === 'p' ) {
  88904. var lineData = line.substr( 1 ).trim();
  88905. var pointData = lineData.split( ' ' );
  88906. state.addPointGeometry( pointData );
  88907. } else if ( ( result = object_pattern.exec( line ) ) !== null ) {
  88908. // o object_name
  88909. // or
  88910. // g group_name
  88911. // WORKAROUND: https://bugs.chromium.org/p/v8/issues/detail?id=2869
  88912. // var name = result[ 0 ].substr( 1 ).trim();
  88913. var name = ( ' ' + result[ 0 ].substr( 1 ).trim() ).substr( 1 );
  88914. state.startObject( name );
  88915. } else if ( material_use_pattern.test( line ) ) {
  88916. // material
  88917. state.object.startMaterial( line.substring( 7 ).trim(), state.materialLibraries );
  88918. } else if ( material_library_pattern.test( line ) ) {
  88919. // mtl file
  88920. state.materialLibraries.push( line.substring( 7 ).trim() );
  88921. } else if ( map_use_pattern.test( line ) ) {
  88922. // the line is parsed but ignored since the loader assumes textures are defined MTL files
  88923. // (according to https://www.okino.com/conv/imp_wave.htm, 'usemap' is the old-style Wavefront texture reference method)
  88924. console.warn( 'THREE.OBJLoader: Rendering identifier "usemap" not supported. Textures must be defined in MTL files.' );
  88925. } else if ( lineFirstChar === 's' ) {
  88926. result = line.split( ' ' );
  88927. // smooth shading
  88928. // @todo Handle files that have varying smooth values for a set of faces inside one geometry,
  88929. // but does not define a usemtl for each face set.
  88930. // This should be detected and a dummy material created (later MultiMaterial and geometry groups).
  88931. // This requires some care to not create extra material on each smooth value for "normal" obj files.
  88932. // where explicit usemtl defines geometry groups.
  88933. // Example asset: examples/models/obj/cerberus/Cerberus.obj
  88934. /*
  88935. * http://paulbourke.net/dataformats/obj/
  88936. * or
  88937. * http://www.cs.utah.edu/~boulos/cs3505/obj_spec.pdf
  88938. *
  88939. * From chapter "Grouping" Syntax explanation "s group_number":
  88940. * "group_number is the smoothing group number. To turn off smoothing groups, use a value of 0 or off.
  88941. * Polygonal elements use group numbers to put elements in different smoothing groups. For free-form
  88942. * surfaces, smoothing groups are either turned on or off; there is no difference between values greater
  88943. * than 0."
  88944. */
  88945. if ( result.length > 1 ) {
  88946. var value = result[ 1 ].trim().toLowerCase();
  88947. state.object.smooth = ( value !== '0' && value !== 'off' );
  88948. } else {
  88949. // ZBrush can produce "s" lines #11707
  88950. state.object.smooth = true;
  88951. }
  88952. var material = state.object.currentMaterial();
  88953. if ( material ) material.smooth = state.object.smooth;
  88954. } else {
  88955. // Handle null terminated files without exception
  88956. if ( line === '\0' ) continue;
  88957. console.warn( 'THREE.OBJLoader: Unexpected line: "' + line + '"' );
  88958. }
  88959. }
  88960. state.finalize();
  88961. var container = new Group();
  88962. container.materialLibraries = [].concat( state.materialLibraries );
  88963. var hasPrimitives = ! ( state.objects.length === 1 && state.objects[ 0 ].geometry.vertices.length === 0 );
  88964. if ( hasPrimitives === true ) {
  88965. for ( var i = 0, l = state.objects.length; i < l; i ++ ) {
  88966. var object = state.objects[ i ];
  88967. var geometry = object.geometry;
  88968. var materials = object.materials;
  88969. var isLine = ( geometry.type === 'Line' );
  88970. var isPoints = ( geometry.type === 'Points' );
  88971. var hasVertexColors = false;
  88972. // Skip o/g line declarations that did not follow with any faces
  88973. if ( geometry.vertices.length === 0 ) continue;
  88974. var buffergeometry = new BufferGeometry();
  88975. buffergeometry.setAttribute( 'position', new Float32BufferAttribute( geometry.vertices, 3 ) );
  88976. if ( geometry.normals.length > 0 ) {
  88977. buffergeometry.setAttribute( 'normal', new Float32BufferAttribute( geometry.normals, 3 ) );
  88978. }
  88979. if ( geometry.colors.length > 0 ) {
  88980. hasVertexColors = true;
  88981. buffergeometry.setAttribute( 'color', new Float32BufferAttribute( geometry.colors, 3 ) );
  88982. }
  88983. if ( geometry.hasUVIndices === true ) {
  88984. buffergeometry.setAttribute( 'uv', new Float32BufferAttribute( geometry.uvs, 2 ) );
  88985. }
  88986. // Create materials
  88987. var createdMaterials = [];
  88988. for ( var mi = 0, miLen = materials.length; mi < miLen; mi ++ ) {
  88989. var sourceMaterial = materials[ mi ];
  88990. var materialHash = sourceMaterial.name + '_' + sourceMaterial.smooth + '_' + hasVertexColors;
  88991. var material = state.materials[ materialHash ];
  88992. if ( this.materials !== null ) {
  88993. material = this.materials.create( sourceMaterial.name );
  88994. // mtl etc. loaders probably can't create line materials correctly, copy properties to a line material.
  88995. if ( isLine && material && ! ( material instanceof LineBasicMaterial ) ) {
  88996. var materialLine = new LineBasicMaterial();
  88997. Material.prototype.copy.call( materialLine, material );
  88998. materialLine.color.copy( material.color );
  88999. material = materialLine;
  89000. } else if ( isPoints && material && ! ( material instanceof PointsMaterial ) ) {
  89001. var materialPoints = new PointsMaterial( { size: 10, sizeAttenuation: false } );
  89002. Material.prototype.copy.call( materialPoints, material );
  89003. materialPoints.color.copy( material.color );
  89004. materialPoints.map = material.map;
  89005. material = materialPoints;
  89006. }
  89007. }
  89008. if ( material === undefined ) {
  89009. if ( isLine ) {
  89010. material = new LineBasicMaterial();
  89011. } else if ( isPoints ) {
  89012. material = new PointsMaterial( { size: 1, sizeAttenuation: false } );
  89013. } else {
  89014. material = new MeshPhongMaterial();
  89015. }
  89016. material.name = sourceMaterial.name;
  89017. material.flatShading = sourceMaterial.smooth ? false : true;
  89018. material.vertexColors = hasVertexColors;
  89019. state.materials[ materialHash ] = material;
  89020. }
  89021. createdMaterials.push( material );
  89022. }
  89023. // Create mesh
  89024. var mesh;
  89025. if ( createdMaterials.length > 1 ) {
  89026. for ( var mi = 0, miLen = materials.length; mi < miLen; mi ++ ) {
  89027. var sourceMaterial = materials[ mi ];
  89028. buffergeometry.addGroup( sourceMaterial.groupStart, sourceMaterial.groupCount, mi );
  89029. }
  89030. if ( isLine ) {
  89031. mesh = new LineSegments( buffergeometry, createdMaterials );
  89032. } else if ( isPoints ) {
  89033. mesh = new Points( buffergeometry, createdMaterials );
  89034. } else {
  89035. mesh = new Mesh( buffergeometry, createdMaterials );
  89036. }
  89037. } else {
  89038. if ( isLine ) {
  89039. mesh = new LineSegments( buffergeometry, createdMaterials[ 0 ] );
  89040. } else if ( isPoints ) {
  89041. mesh = new Points( buffergeometry, createdMaterials[ 0 ] );
  89042. } else {
  89043. mesh = new Mesh( buffergeometry, createdMaterials[ 0 ] );
  89044. }
  89045. }
  89046. mesh.name = object.name;
  89047. container.add( mesh );
  89048. }
  89049. } else {
  89050. // if there is only the default parser state object with no geometry data, interpret data as point cloud
  89051. if ( state.vertices.length > 0 ) {
  89052. var material = new PointsMaterial( { size: 1, sizeAttenuation: false } );
  89053. var buffergeometry = new BufferGeometry();
  89054. buffergeometry.setAttribute( 'position', new Float32BufferAttribute( state.vertices, 3 ) );
  89055. if ( state.colors.length > 0 && state.colors[ 0 ] !== undefined ) {
  89056. buffergeometry.setAttribute( 'color', new Float32BufferAttribute( state.colors, 3 ) );
  89057. material.vertexColors = true;
  89058. }
  89059. var points = new Points( buffergeometry, material );
  89060. container.add( points );
  89061. }
  89062. }
  89063. return container;
  89064. }
  89065. } );
  89066. return OBJLoader;
  89067. } )();
  89068. /**
  89069. * Loads a Wavefront .mtl file specifying materials
  89070. */
  89071. var MTLLoader = function ( manager ) {
  89072. Loader.call( this, manager );
  89073. };
  89074. MTLLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  89075. constructor: MTLLoader,
  89076. /**
  89077. * Loads and parses a MTL asset from a URL.
  89078. *
  89079. * @param {String} url - URL to the MTL file.
  89080. * @param {Function} [onLoad] - Callback invoked with the loaded object.
  89081. * @param {Function} [onProgress] - Callback for download progress.
  89082. * @param {Function} [onError] - Callback for download errors.
  89083. *
  89084. * @see setPath setResourcePath
  89085. *
  89086. * @note In order for relative texture references to resolve correctly
  89087. * you must call setResourcePath() explicitly prior to load.
  89088. */
  89089. load: function ( url, onLoad, onProgress, onError ) {
  89090. var scope = this;
  89091. var path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  89092. var loader = new FileLoader( this.manager );
  89093. loader.setPath( this.path );
  89094. loader.setRequestHeader( this.requestHeader );
  89095. loader.setWithCredentials( this.withCredentials );
  89096. loader.load( url, function ( text ) {
  89097. try {
  89098. onLoad( scope.parse( text, path ) );
  89099. } catch ( e ) {
  89100. if ( onError ) {
  89101. onError( e );
  89102. } else {
  89103. console.error( e );
  89104. }
  89105. scope.manager.itemError( url );
  89106. }
  89107. }, onProgress, onError );
  89108. },
  89109. setMaterialOptions: function ( value ) {
  89110. this.materialOptions = value;
  89111. return this;
  89112. },
  89113. /**
  89114. * Parses a MTL file.
  89115. *
  89116. * @param {String} text - Content of MTL file
  89117. * @return {MTLLoader.MaterialCreator}
  89118. *
  89119. * @see setPath setResourcePath
  89120. *
  89121. * @note In order for relative texture references to resolve correctly
  89122. * you must call setResourcePath() explicitly prior to parse.
  89123. */
  89124. parse: function ( text, path ) {
  89125. var lines = text.split( '\n' );
  89126. var info = {};
  89127. var delimiter_pattern = /\s+/;
  89128. var materialsInfo = {};
  89129. for ( var i = 0; i < lines.length; i ++ ) {
  89130. var line = lines[ i ];
  89131. line = line.trim();
  89132. if ( line.length === 0 || line.charAt( 0 ) === '#' ) {
  89133. // Blank line or comment ignore
  89134. continue;
  89135. }
  89136. var pos = line.indexOf( ' ' );
  89137. var key = ( pos >= 0 ) ? line.substring( 0, pos ) : line;
  89138. key = key.toLowerCase();
  89139. var value = ( pos >= 0 ) ? line.substring( pos + 1 ) : '';
  89140. value = value.trim();
  89141. if ( key === 'newmtl' ) {
  89142. // New material
  89143. info = { name: value };
  89144. materialsInfo[ value ] = info;
  89145. } else {
  89146. if ( key === 'ka' || key === 'kd' || key === 'ks' || key === 'ke' ) {
  89147. var ss = value.split( delimiter_pattern, 3 );
  89148. info[ key ] = [ parseFloat( ss[ 0 ] ), parseFloat( ss[ 1 ] ), parseFloat( ss[ 2 ] ) ];
  89149. } else {
  89150. info[ key ] = value;
  89151. }
  89152. }
  89153. }
  89154. var materialCreator = new MTLLoader.MaterialCreator( this.resourcePath || path, this.materialOptions );
  89155. materialCreator.setCrossOrigin( this.crossOrigin );
  89156. materialCreator.setManager( this.manager );
  89157. materialCreator.setMaterials( materialsInfo );
  89158. return materialCreator;
  89159. }
  89160. } );
  89161. /**
  89162. * Create a new MTLLoader.MaterialCreator
  89163. * @param baseUrl - Url relative to which textures are loaded
  89164. * @param options - Set of options on how to construct the materials
  89165. * side: Which side to apply the material
  89166. * FrontSide (default), THREE.BackSide, THREE.DoubleSide
  89167. * wrap: What type of wrapping to apply for textures
  89168. * RepeatWrapping (default), THREE.ClampToEdgeWrapping, THREE.MirroredRepeatWrapping
  89169. * normalizeRGB: RGBs need to be normalized to 0-1 from 0-255
  89170. * Default: false, assumed to be already normalized
  89171. * ignoreZeroRGBs: Ignore values of RGBs (Ka,Kd,Ks) that are all 0's
  89172. * Default: false
  89173. * @constructor
  89174. */
  89175. MTLLoader.MaterialCreator = function ( baseUrl, options ) {
  89176. this.baseUrl = baseUrl || '';
  89177. this.options = options;
  89178. this.materialsInfo = {};
  89179. this.materials = {};
  89180. this.materialsArray = [];
  89181. this.nameLookup = {};
  89182. this.side = ( this.options && this.options.side ) ? this.options.side : FrontSide;
  89183. this.wrap = ( this.options && this.options.wrap ) ? this.options.wrap : RepeatWrapping;
  89184. };
  89185. MTLLoader.MaterialCreator.prototype = {
  89186. constructor: MTLLoader.MaterialCreator,
  89187. crossOrigin: 'anonymous',
  89188. setCrossOrigin: function ( value ) {
  89189. this.crossOrigin = value;
  89190. return this;
  89191. },
  89192. setManager: function ( value ) {
  89193. this.manager = value;
  89194. },
  89195. setMaterials: function ( materialsInfo ) {
  89196. this.materialsInfo = this.convert( materialsInfo );
  89197. this.materials = {};
  89198. this.materialsArray = [];
  89199. this.nameLookup = {};
  89200. },
  89201. convert: function ( materialsInfo ) {
  89202. if ( ! this.options ) return materialsInfo;
  89203. var converted = {};
  89204. for ( var mn in materialsInfo ) {
  89205. // Convert materials info into normalized form based on options
  89206. var mat = materialsInfo[ mn ];
  89207. var covmat = {};
  89208. converted[ mn ] = covmat;
  89209. for ( var prop in mat ) {
  89210. var save = true;
  89211. var value = mat[ prop ];
  89212. var lprop = prop.toLowerCase();
  89213. switch ( lprop ) {
  89214. case 'kd':
  89215. case 'ka':
  89216. case 'ks':
  89217. // Diffuse color (color under white light) using RGB values
  89218. if ( this.options && this.options.normalizeRGB ) {
  89219. value = [ value[ 0 ] / 255, value[ 1 ] / 255, value[ 2 ] / 255 ];
  89220. }
  89221. if ( this.options && this.options.ignoreZeroRGBs ) {
  89222. if ( value[ 0 ] === 0 && value[ 1 ] === 0 && value[ 2 ] === 0 ) {
  89223. // ignore
  89224. save = false;
  89225. }
  89226. }
  89227. break;
  89228. default:
  89229. break;
  89230. }
  89231. if ( save ) {
  89232. covmat[ lprop ] = value;
  89233. }
  89234. }
  89235. }
  89236. return converted;
  89237. },
  89238. preload: function () {
  89239. for ( var mn in this.materialsInfo ) {
  89240. this.create( mn );
  89241. }
  89242. },
  89243. getIndex: function ( materialName ) {
  89244. return this.nameLookup[ materialName ];
  89245. },
  89246. getAsArray: function () {
  89247. var index = 0;
  89248. for ( var mn in this.materialsInfo ) {
  89249. this.materialsArray[ index ] = this.create( mn );
  89250. this.nameLookup[ mn ] = index;
  89251. index ++;
  89252. }
  89253. return this.materialsArray;
  89254. },
  89255. create: function ( materialName ) {
  89256. if ( this.materials[ materialName ] === undefined ) {
  89257. this.createMaterial_( materialName );
  89258. }
  89259. return this.materials[ materialName ];
  89260. },
  89261. createMaterial_: function ( materialName ) {
  89262. // Create material
  89263. var scope = this;
  89264. var mat = this.materialsInfo[ materialName ];
  89265. var params = {
  89266. name: materialName,
  89267. side: this.side
  89268. };
  89269. function resolveURL( baseUrl, url ) {
  89270. if ( typeof url !== 'string' || url === '' )
  89271. return '';
  89272. // Absolute URL
  89273. if ( /^https?:\/\//i.test( url ) ) return url;
  89274. return baseUrl + url;
  89275. }
  89276. function setMapForType( mapType, value ) {
  89277. if ( params[ mapType ] ) return; // Keep the first encountered texture
  89278. var texParams = scope.getTextureParams( value, params );
  89279. var map = scope.loadTexture( resolveURL( scope.baseUrl, texParams.url ) );
  89280. map.repeat.copy( texParams.scale );
  89281. map.offset.copy( texParams.offset );
  89282. map.wrapS = scope.wrap;
  89283. map.wrapT = scope.wrap;
  89284. params[ mapType ] = map;
  89285. }
  89286. for ( var prop in mat ) {
  89287. var value = mat[ prop ];
  89288. var n;
  89289. if ( value === '' ) continue;
  89290. switch ( prop.toLowerCase() ) {
  89291. // Ns is material specular exponent
  89292. case 'kd':
  89293. // Diffuse color (color under white light) using RGB values
  89294. params.color = new Color().fromArray( value );
  89295. break;
  89296. case 'ks':
  89297. // Specular color (color when light is reflected from shiny surface) using RGB values
  89298. //params.specular = new Color().fromArray( value );
  89299. //console.log('specular',value)
  89300. break;
  89301. case 'ke':
  89302. // Emissive using RGB values
  89303. params.emissive = new Color().fromArray( value );
  89304. break;
  89305. case 'map_kd':
  89306. // Diffuse texture map
  89307. setMapForType( 'map', value );
  89308. break;
  89309. case 'map_ks':
  89310. // Specular map
  89311. setMapForType( 'specularMap', value );
  89312. break;
  89313. case 'map_ke':
  89314. // Emissive map
  89315. setMapForType( 'emissiveMap', value );
  89316. break;
  89317. case 'norm':
  89318. setMapForType( 'normalMap', value );
  89319. break;
  89320. case 'map_bump':
  89321. case 'bump':
  89322. // Bump texture map
  89323. setMapForType( 'bumpMap', value );
  89324. break;
  89325. case 'map_d':
  89326. // Alpha map
  89327. setMapForType( 'alphaMap', value );
  89328. params.transparent = true;
  89329. break;
  89330. case 'ns':
  89331. // The specular exponent (defines the focus of the specular highlight)
  89332. // A high exponent results in a tight, concentrated highlight. Ns values normally range from 0 to 1000.
  89333. //params.shininess = parseFloat( value );
  89334. //console.log('shininess',value)
  89335. break;
  89336. case 'd':
  89337. n = parseFloat( value );
  89338. if ( n < 1 ) {
  89339. params.opacity = n;
  89340. params.transparent = true;
  89341. }
  89342. break;
  89343. case 'tr':
  89344. n = parseFloat( value );
  89345. if ( this.options && this.options.invertTrProperty ) n = 1 - n;
  89346. if ( n > 0 ) {
  89347. params.opacity = 1 - n;
  89348. params.transparent = true;
  89349. }
  89350. break;
  89351. default:
  89352. break;
  89353. }
  89354. }
  89355. this.materials[ materialName ] = new MeshStandardMaterial( params );//MeshPhongMaterial( params );
  89356. return this.materials[ materialName ];
  89357. },
  89358. getTextureParams: function ( value, matParams ) {
  89359. var texParams = {
  89360. scale: new Vector2( 1, 1 ),
  89361. offset: new Vector2( 0, 0 )
  89362. };
  89363. var items = value.split( /\s+/ );
  89364. var pos;
  89365. pos = items.indexOf( '-bm' );
  89366. if ( pos >= 0 ) {
  89367. matParams.bumpScale = parseFloat( items[ pos + 1 ] );
  89368. items.splice( pos, 2 );
  89369. }
  89370. pos = items.indexOf( '-s' );
  89371. if ( pos >= 0 ) {
  89372. texParams.scale.set( parseFloat( items[ pos + 1 ] ), parseFloat( items[ pos + 2 ] ) );
  89373. items.splice( pos, 4 ); // we expect 3 parameters here!
  89374. }
  89375. pos = items.indexOf( '-o' );
  89376. if ( pos >= 0 ) {
  89377. texParams.offset.set( parseFloat( items[ pos + 1 ] ), parseFloat( items[ pos + 2 ] ) );
  89378. items.splice( pos, 4 ); // we expect 3 parameters here!
  89379. }
  89380. texParams.url = items.join( ' ' ).trim();
  89381. return texParams;
  89382. },
  89383. loadTexture: function ( url, mapping, onLoad, onProgress, onError ) {
  89384. var texture;
  89385. var manager = ( this.manager !== undefined ) ? this.manager : DefaultLoadingManager;
  89386. var loader = manager.getHandler( url );
  89387. if ( loader === null ) {
  89388. loader = new TextureLoader( manager );
  89389. }
  89390. if ( loader.setCrossOrigin ) loader.setCrossOrigin( this.crossOrigin );
  89391. texture = loader.load( url, onLoad, onProgress, onError );
  89392. if ( mapping !== undefined ) texture.mapping = mapping;
  89393. return texture;
  89394. }
  89395. };
  89396. //2022.11.11 copyfrom : https://unpkg.com/three@0.146.0/examples/jsm/loaders/DRACOLoader.js
  89397. const _taskCache = new WeakMap();
  89398. class DRACOLoader extends Loader {
  89399. constructor( manager ) {
  89400. super( manager );
  89401. this.decoderPath = '';
  89402. this.decoderConfig = {};
  89403. this.decoderBinary = null;
  89404. this.decoderPending = null;
  89405. this.workerLimit = 4;
  89406. this.workerPool = [];
  89407. this.workerNextTaskID = 1;
  89408. this.workerSourceURL = '';
  89409. this.defaultAttributeIDs = {
  89410. position: 'POSITION',
  89411. normal: 'NORMAL',
  89412. color: 'COLOR',
  89413. uv: 'TEX_COORD'
  89414. };
  89415. this.defaultAttributeTypes = {
  89416. position: 'Float32Array',
  89417. normal: 'Float32Array',
  89418. color: 'Float32Array',
  89419. uv: 'Float32Array'
  89420. };
  89421. }
  89422. setDecoderPath( path ) {
  89423. this.decoderPath = path;
  89424. return this;
  89425. }
  89426. setDecoderConfig( config ) {
  89427. this.decoderConfig = config;
  89428. return this;
  89429. }
  89430. setWorkerLimit( workerLimit ) {
  89431. this.workerLimit = workerLimit;
  89432. return this;
  89433. }
  89434. load( url, onLoad, onProgress, onError ) {
  89435. const loader = new FileLoader( this.manager );
  89436. loader.setPath( this.path );
  89437. loader.setResponseType( 'arraybuffer' );
  89438. loader.setRequestHeader( this.requestHeader );
  89439. loader.setWithCredentials( this.withCredentials );
  89440. loader.load( url, ( buffer ) => {
  89441. this.decodeDracoFile( buffer, onLoad ).catch( onError );
  89442. }, onProgress, onError );
  89443. }
  89444. decodeDracoFile( buffer, callback, attributeIDs, attributeTypes ) {
  89445. const taskConfig = {
  89446. attributeIDs: attributeIDs || this.defaultAttributeIDs,
  89447. attributeTypes: attributeTypes || this.defaultAttributeTypes,
  89448. useUniqueIDs: !! attributeIDs
  89449. };
  89450. return this.decodeGeometry( buffer, taskConfig ).then( callback );
  89451. }
  89452. decodeGeometry( buffer, taskConfig ) {
  89453. const taskKey = JSON.stringify( taskConfig );
  89454. // Check for an existing task using this buffer. A transferred buffer cannot be transferred
  89455. // again from this thread.
  89456. if ( _taskCache.has( buffer ) ) {
  89457. const cachedTask = _taskCache.get( buffer );
  89458. if ( cachedTask.key === taskKey ) {
  89459. return cachedTask.promise;
  89460. } else if ( buffer.byteLength === 0 ) {
  89461. // Technically, it would be possible to wait for the previous task to complete,
  89462. // transfer the buffer back, and decode again with the second configuration. That
  89463. // is complex, and I don't know of any reason to decode a Draco buffer twice in
  89464. // different ways, so this is left unimplemented.
  89465. throw new Error(
  89466. 'THREE.DRACOLoader: Unable to re-decode a buffer with different ' +
  89467. 'settings. Buffer has already been transferred.'
  89468. );
  89469. }
  89470. }
  89471. //
  89472. let worker;
  89473. const taskID = this.workerNextTaskID ++;
  89474. const taskCost = buffer.byteLength;
  89475. // Obtain a worker and assign a task, and construct a geometry instance
  89476. // when the task completes.
  89477. const geometryPending = this._getWorker( taskID, taskCost )
  89478. .then( ( _worker ) => {
  89479. worker = _worker;
  89480. return new Promise( ( resolve, reject ) => {
  89481. worker._callbacks[ taskID ] = { resolve, reject };
  89482. worker.postMessage( { type: 'decode', id: taskID, taskConfig, buffer }, [ buffer ] );
  89483. // this.debug();
  89484. } );
  89485. } )
  89486. .then( ( message ) => this._createGeometry( message.geometry ) );
  89487. // Remove task from the task list.
  89488. // Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
  89489. geometryPending
  89490. .catch( () => true )
  89491. .then( () => {
  89492. if ( worker && taskID ) {
  89493. this._releaseTask( worker, taskID );
  89494. // this.debug();
  89495. }
  89496. } );
  89497. // Cache the task result.
  89498. _taskCache.set( buffer, {
  89499. key: taskKey,
  89500. promise: geometryPending
  89501. } );
  89502. return geometryPending;
  89503. }
  89504. _createGeometry( geometryData ) {
  89505. const geometry = new BufferGeometry();
  89506. if ( geometryData.index ) {
  89507. geometry.setIndex( new BufferAttribute( geometryData.index.array, 1 ) );
  89508. }
  89509. for ( let i = 0; i < geometryData.attributes.length; i ++ ) {
  89510. const attribute = geometryData.attributes[ i ];
  89511. const name = attribute.name;
  89512. const array = attribute.array;
  89513. const itemSize = attribute.itemSize;
  89514. geometry.setAttribute( name, new BufferAttribute( array, itemSize ) );
  89515. }
  89516. return geometry;
  89517. }
  89518. _loadLibrary( url, responseType ) {
  89519. const loader = new FileLoader( this.manager );
  89520. loader.setPath( this.decoderPath );
  89521. loader.setResponseType( responseType );
  89522. loader.setWithCredentials( this.withCredentials );
  89523. return new Promise( ( resolve, reject ) => {
  89524. loader.load( url, resolve, undefined, reject );
  89525. } );
  89526. }
  89527. preload() {
  89528. this._initDecoder();
  89529. return this;
  89530. }
  89531. _initDecoder() {
  89532. if ( this.decoderPending ) return this.decoderPending;
  89533. const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
  89534. const librariesPending = [];
  89535. if ( useJS ) {
  89536. librariesPending.push( this._loadLibrary( 'draco_decoder.js', 'text' ) );
  89537. } else {
  89538. librariesPending.push( this._loadLibrary( 'draco_wasm_wrapper.js', 'text' ) );
  89539. librariesPending.push( this._loadLibrary( 'draco_decoder.wasm', 'arraybuffer' ) );
  89540. }
  89541. this.decoderPending = Promise.all( librariesPending )
  89542. .then( ( libraries ) => {
  89543. const jsContent = libraries[ 0 ];
  89544. if ( ! useJS ) {
  89545. this.decoderConfig.wasmBinary = libraries[ 1 ];
  89546. }
  89547. const fn = DRACOWorker.toString();
  89548. const body = [
  89549. '/* draco decoder */',
  89550. jsContent,
  89551. '',
  89552. '/* worker */',
  89553. fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
  89554. ].join( '\n' );
  89555. this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
  89556. } );
  89557. return this.decoderPending;
  89558. }
  89559. _getWorker( taskID, taskCost ) {
  89560. return this._initDecoder().then( () => {
  89561. if ( this.workerPool.length < this.workerLimit ) {
  89562. const worker = new Worker( this.workerSourceURL );
  89563. worker._callbacks = {};
  89564. worker._taskCosts = {};
  89565. worker._taskLoad = 0;
  89566. worker.postMessage( { type: 'init', decoderConfig: this.decoderConfig } );
  89567. worker.onmessage = function ( e ) {
  89568. const message = e.data;
  89569. switch ( message.type ) {
  89570. case 'decode':
  89571. worker._callbacks[ message.id ].resolve( message );
  89572. break;
  89573. case 'error':
  89574. worker._callbacks[ message.id ].reject( message );
  89575. break;
  89576. default:
  89577. console.error( 'THREE.DRACOLoader: Unexpected message, "' + message.type + '"' );
  89578. }
  89579. };
  89580. this.workerPool.push( worker );
  89581. } else {
  89582. this.workerPool.sort( function ( a, b ) {
  89583. return a._taskLoad > b._taskLoad ? - 1 : 1;
  89584. } );
  89585. }
  89586. const worker = this.workerPool[ this.workerPool.length - 1 ];
  89587. worker._taskCosts[ taskID ] = taskCost;
  89588. worker._taskLoad += taskCost;
  89589. return worker;
  89590. } );
  89591. }
  89592. _releaseTask( worker, taskID ) {
  89593. worker._taskLoad -= worker._taskCosts[ taskID ];
  89594. delete worker._callbacks[ taskID ];
  89595. delete worker._taskCosts[ taskID ];
  89596. }
  89597. debug() {
  89598. console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
  89599. }
  89600. dispose() {
  89601. for ( let i = 0; i < this.workerPool.length; ++ i ) {
  89602. this.workerPool[ i ].terminate();
  89603. }
  89604. this.workerPool.length = 0;
  89605. return this;
  89606. }
  89607. }
  89608. /* WEB WORKER */
  89609. function DRACOWorker() {
  89610. let decoderConfig;
  89611. let decoderPending;
  89612. onmessage = function ( e ) {
  89613. const message = e.data;
  89614. switch ( message.type ) {
  89615. case 'init':
  89616. decoderConfig = message.decoderConfig;
  89617. decoderPending = new Promise( function ( resolve/*, reject*/ ) {
  89618. decoderConfig.onModuleLoaded = function ( draco ) {
  89619. // Module is Promise-like. Wrap before resolving to avoid loop.
  89620. resolve( { draco: draco } );
  89621. };
  89622. DracoDecoderModule( decoderConfig ); // eslint-disable-line no-undef
  89623. } );
  89624. break;
  89625. case 'decode':
  89626. const buffer = message.buffer;
  89627. const taskConfig = message.taskConfig;
  89628. decoderPending.then( ( module ) => {
  89629. const draco = module.draco;
  89630. const decoder = new draco.Decoder();
  89631. const decoderBuffer = new draco.DecoderBuffer();
  89632. decoderBuffer.Init( new Int8Array( buffer ), buffer.byteLength );
  89633. try {
  89634. const geometry = decodeGeometry( draco, decoder, decoderBuffer, taskConfig );
  89635. const buffers = geometry.attributes.map( ( attr ) => attr.array.buffer );
  89636. if ( geometry.index ) buffers.push( geometry.index.array.buffer );
  89637. self.postMessage( { type: 'decode', id: message.id, geometry }, buffers );
  89638. } catch ( error ) {
  89639. console.error( error );
  89640. self.postMessage( { type: 'error', id: message.id, error: error.message } );
  89641. } finally {
  89642. draco.destroy( decoderBuffer );
  89643. draco.destroy( decoder );
  89644. }
  89645. } );
  89646. break;
  89647. }
  89648. };
  89649. function decodeGeometry( draco, decoder, decoderBuffer, taskConfig ) {
  89650. const attributeIDs = taskConfig.attributeIDs;
  89651. const attributeTypes = taskConfig.attributeTypes;
  89652. let dracoGeometry;
  89653. let decodingStatus;
  89654. const geometryType = decoder.GetEncodedGeometryType( decoderBuffer );
  89655. if ( geometryType === draco.TRIANGULAR_MESH ) {
  89656. dracoGeometry = new draco.Mesh();
  89657. decodingStatus = decoder.DecodeBufferToMesh( decoderBuffer, dracoGeometry );
  89658. } else if ( geometryType === draco.POINT_CLOUD ) {
  89659. dracoGeometry = new draco.PointCloud();
  89660. decodingStatus = decoder.DecodeBufferToPointCloud( decoderBuffer, dracoGeometry );
  89661. } else {
  89662. throw new Error( 'THREE.DRACOLoader: Unexpected geometry type.' );
  89663. }
  89664. if ( ! decodingStatus.ok() || dracoGeometry.ptr === 0 ) {
  89665. throw new Error( 'THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg() );
  89666. }
  89667. const geometry = { index: null, attributes: [] };
  89668. // Gather all vertex attributes.
  89669. for ( const attributeName in attributeIDs ) {
  89670. const attributeType = self[ attributeTypes[ attributeName ] ];
  89671. let attribute;
  89672. let attributeID;
  89673. // A Draco file may be created with default vertex attributes, whose attribute IDs
  89674. // are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
  89675. // a Draco file may contain a custom set of attributes, identified by known unique
  89676. // IDs. glTF files always do the latter, and `.drc` files typically do the former.
  89677. if ( taskConfig.useUniqueIDs ) {
  89678. attributeID = attributeIDs[ attributeName ];
  89679. attribute = decoder.GetAttributeByUniqueId( dracoGeometry, attributeID );
  89680. } else {
  89681. attributeID = decoder.GetAttributeId( dracoGeometry, draco[ attributeIDs[ attributeName ] ] );
  89682. if ( attributeID === - 1 ) continue;
  89683. attribute = decoder.GetAttribute( dracoGeometry, attributeID );
  89684. }
  89685. geometry.attributes.push( decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ) );
  89686. }
  89687. // Add index.
  89688. if ( geometryType === draco.TRIANGULAR_MESH ) {
  89689. geometry.index = decodeIndex( draco, decoder, dracoGeometry );
  89690. }
  89691. draco.destroy( dracoGeometry );
  89692. return geometry;
  89693. }
  89694. function decodeIndex( draco, decoder, dracoGeometry ) {
  89695. const numFaces = dracoGeometry.num_faces();
  89696. const numIndices = numFaces * 3;
  89697. const byteLength = numIndices * 4;
  89698. const ptr = draco._malloc( byteLength );
  89699. decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
  89700. const index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
  89701. draco._free( ptr );
  89702. return { array: index, itemSize: 1 };
  89703. }
  89704. function decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ) {
  89705. const numComponents = attribute.num_components();
  89706. const numPoints = dracoGeometry.num_points();
  89707. const numValues = numPoints * numComponents;
  89708. const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
  89709. const dataType = getDracoDataType( draco, attributeType );
  89710. const ptr = draco._malloc( byteLength );
  89711. decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr );
  89712. const array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
  89713. draco._free( ptr );
  89714. return {
  89715. name: attributeName,
  89716. array: array,
  89717. itemSize: numComponents
  89718. };
  89719. }
  89720. function getDracoDataType( draco, attributeType ) {
  89721. switch ( attributeType ) {
  89722. case Float32Array: return draco.DT_FLOAT32;
  89723. case Int8Array: return draco.DT_INT8;
  89724. case Int16Array: return draco.DT_INT16;
  89725. case Int32Array: return draco.DT_INT32;
  89726. case Uint8Array: return draco.DT_UINT8;
  89727. case Uint16Array: return draco.DT_UINT16;
  89728. case Uint32Array: return draco.DT_UINT32;
  89729. }
  89730. }
  89731. }
  89732. /**
  89733. * @author Deepkolos / https://github.com/deepkolos
  89734. */
  89735. //用于KTX2Loader
  89736. class WorkerPool$1 {
  89737. constructor( pool = 4 ) {
  89738. this.pool = pool;
  89739. this.queue = [];
  89740. this.workers = [];
  89741. this.workersResolve = [];
  89742. this.workerStatus = 0;
  89743. }
  89744. _initWorker( workerId ) {
  89745. if ( ! this.workers[ workerId ] ) {
  89746. const worker = this.workerCreator();
  89747. worker.addEventListener( 'message', this._onMessage.bind( this, workerId ) );
  89748. this.workers[ workerId ] = worker;
  89749. }
  89750. }
  89751. _getIdleWorker() {
  89752. for ( let i = 0; i < this.pool; i ++ )
  89753. if ( ! ( this.workerStatus & ( 1 << i ) ) ) return i;
  89754. return - 1;
  89755. }
  89756. _onMessage( workerId, msg ) {
  89757. const resolve = this.workersResolve[ workerId ];
  89758. resolve && resolve( msg );
  89759. if ( this.queue.length ) {
  89760. const { resolve, msg, transfer } = this.queue.shift();
  89761. this.workersResolve[ workerId ] = resolve;
  89762. this.workers[ workerId ].postMessage( msg, transfer );
  89763. } else {
  89764. this.workerStatus ^= 1 << workerId;
  89765. }
  89766. }
  89767. setWorkerCreator( workerCreator ) {
  89768. this.workerCreator = workerCreator;
  89769. }
  89770. setWorkerLimit( pool ) {
  89771. this.pool = pool;
  89772. }
  89773. postMessage( msg, transfer ) {
  89774. return new Promise( ( resolve ) => {
  89775. const workerId = this._getIdleWorker();
  89776. if ( workerId !== - 1 ) {
  89777. this._initWorker( workerId );
  89778. this.workerStatus |= 1 << workerId;
  89779. this.workersResolve[ workerId ] = resolve;
  89780. this.workers[ workerId ].postMessage( msg, transfer );
  89781. } else {
  89782. this.queue.push( { resolve, msg, transfer } );
  89783. }
  89784. } );
  89785. }
  89786. dispose() {
  89787. this.workers.forEach( ( worker ) => worker.terminate() );
  89788. this.workersResolve.length = 0;
  89789. this.workers.length = 0;
  89790. this.queue.length = 0;
  89791. this.workerStatus = 0;
  89792. }
  89793. }
  89794. const t=0,e$1=1,n$1=2,i$1=3,s=0,a$1=0,r=2,o$1=0,l$1=1,f=160,U$1=161,c$2=162,h$2=163,_$1=0,p=1,g=0,y=1,x$2=2,u$2=3,b$1=4,d=5,m=6,w$2=7,D=8,B=9,L=10,A=11,k=12,v=13,S$1=14,I=15,O=16,T$1=17,V=18,E=0,F=1,P=2,C=3,z=4,M$1=5,W=6,N=7,H=8,K=9,X=10,j=11,R=0,Y=1,q=2,G=13,J=14,Q=15,Z=128,$$1=64,tt=32,et=16,nt=0,it=1,st=2,at=3,rt=4,ot=5,lt=6,ft=7,Ut=8,ct=9,ht=10,_t=13,pt=14,gt=15,yt=16,xt=17,ut=20,bt=21,dt=22,mt=23,wt=24,Dt=27,Bt=28,Lt=29,At=30,kt=31,vt=34,St=35,It=36,Ot=37,Tt=38,Vt=41,Et=42,Ft=43,Pt=44,Ct=45,zt=48,Mt=49,Wt=50,Nt=58,Ht=59,Kt=62,Xt=63,jt=64,Rt=65,Yt=68,qt=69,Gt=70,Jt=71,Qt=74,Zt=75,$t=76,te=77,ee=78,ne=81,ie=82,se=83,ae=84,re=85,oe=88,le=89,fe=90,Ue=91,ce=92,he=95,_e=96,pe=97,ge=98,ye=99,xe=100,ue=101,be=102,de=103,me=104,we=105,De=106,Be=107,Le=108,Ae=109,ke=110,ve=111,Se=112,Ie=113,Oe=114,Te=115,Ve=116,Ee=117,Fe=118,Pe=119,Ce=120,ze=121,Me=122,We=123,Ne=124,He=125,Ke=126,Xe=127,je=128,Re=129,Ye=130,qe=131,Ge=132,Je=133,Qe=134,Ze=135,$e=136,tn=137,en=138,nn=139,sn=140,an=141,rn=142,on=143,ln=144,fn=145,Un=146,cn=147,hn=148,_n=149,pn=150,gn=151,yn=152,xn=153,un=154,bn=155,dn=156,mn=157,wn=158,Dn=159,Bn=160,Ln=161,An=162,kn=163,vn=164,Sn=165,In=166,On=167,Tn=168,Vn=169,En=170,Fn=171,Pn=172,Cn=173,zn=174,Mn=175,Wn=176,Nn=177,Hn=178,Kn=179,Xn=180,jn=181,Rn=182,Yn=183,qn=184,Gn=1000156007,Jn=1000156008,Qn=1000156009,Zn=1000156010,$n=1000156011,ti=1000156017,ei=1000156018,ni=1000156019,ii=1000156020,si=1000156021,ai=1000054e3,ri=1000054001,oi=1000054002,li=1000054003,fi=1000054004,Ui=1000054005,ci=1000054006,hi=1000054007,_i=1000066e3,pi=1000066001,gi=1000066002,yi=1000066003,xi=1000066004,ui=1000066005,bi=1000066006,di=1000066007,mi=1000066008,wi=1000066009,Di=1000066010,Bi=1000066011,Li=1000066012,Ai=1000066013,ki=100034e4,vi=1000340001;class Si{constructor(){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=[{vendorId:0,descriptorType:0,descriptorBlockSize:0,versionNumber:2,colorModel:0,colorPrimaries:1,transferFunction:2,flags:0,texelBlockDimension:[0,0,0,0],bytesPlane:[0,0,0,0,0,0,0,0],samples:[]}],this.keyValue={},this.globalData=null;}}class Ii{constructor(t,e,n,i){this._dataView=new DataView(t.buffer,t.byteOffset+e,n),this._littleEndian=i,this._offset=0;}_nextUint8(){const t=this._dataView.getUint8(this._offset);return this._offset+=1,t}_nextUint16(){const t=this._dataView.getUint16(this._offset,this._littleEndian);return this._offset+=2,t}_nextUint32(){const t=this._dataView.getUint32(this._offset,this._littleEndian);return this._offset+=4,t}_nextUint64(){const t=this._dataView.getUint32(this._offset,this._littleEndian)+2**32*this._dataView.getUint32(this._offset+4,this._littleEndian);return this._offset+=8,t}_nextInt32(){const t=this._dataView.getInt32(this._offset,this._littleEndian);return this._offset+=4,t}_skip(t){return this._offset+=t,this}_scan(t,e=0){const n=this._offset;let i=0;for(;this._dataView.getUint8(this._offset)!==e&&i<t;)i++,this._offset++;return i<t&&this._offset++,new Uint8Array(this._dataView.buffer,this._dataView.byteOffset+n,i)}}const Oi=new Uint8Array([0]),Ti=[171,75,84,88,32,50,48,187,13,10,26,10];function Vi(t){return "undefined"!=typeof TextEncoder?(new TextEncoder).encode(t):Buffer.from(t)}function Ei(t){return "undefined"!=typeof TextDecoder?(new TextDecoder).decode(t):Buffer.from(t).toString("utf8")}function Fi(t){let e=0;for(const n of t)e+=n.byteLength;const n=new Uint8Array(e);let i=0;for(const e of t)n.set(new Uint8Array(e),i),i+=e.byteLength;return n}function Pi(t){const e=new Uint8Array(t.buffer,t.byteOffset,Ti.length);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.");const n=new Si,i=17*Uint32Array.BYTES_PER_ELEMENT,s=new Ii(t,Ti.length,i,!0);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();const a=s._nextUint32();n.supercompressionScheme=s._nextUint32();const r=s._nextUint32(),o=s._nextUint32(),l=s._nextUint32(),f=s._nextUint32(),U=s._nextUint64(),c=s._nextUint64(),h=new Ii(t,Ti.length+i,3*a*8,!0);for(let e=0;e<a;e++)n.levels.push({levelData:new Uint8Array(t.buffer,t.byteOffset+h._nextUint64(),h._nextUint64()),uncompressedByteLength:h._nextUint64()});const _=new Ii(t,r,o,!0),p={vendorId:_._skip(4)._nextUint16(),descriptorType:_._nextUint16(),versionNumber:_._nextUint16(),descriptorBlockSize:_._nextUint16(),colorModel:_._nextUint8(),colorPrimaries:_._nextUint8(),transferFunction:_._nextUint8(),flags:_._nextUint8(),texelBlockDimension:[_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8()],bytesPlane:[_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8()],samples:[]},g=(p.descriptorBlockSize/4-6)/4;for(let t=0;t<g;t++){const e={bitOffset:_._nextUint16(),bitLength:_._nextUint8(),channelType:_._nextUint8(),samplePosition:[_._nextUint8(),_._nextUint8(),_._nextUint8(),_._nextUint8()],sampleLower:-Infinity,sampleUpper:Infinity};64&e.channelType?(e.sampleLower=_._nextInt32(),e.sampleUpper=_._nextInt32()):(e.sampleLower=_._nextUint32(),e.sampleUpper=_._nextUint32()),p.samples[t]=e;}n.dataFormatDescriptor.length=0,n.dataFormatDescriptor.push(p);const y=new Ii(t,l,f,!0);for(;y._offset<f;){const t=y._nextUint32(),e=y._scan(t),i=Ei(e),s=y._scan(t-e.byteLength);n.keyValue[i]=i.match(/^ktx/i)?Ei(s):s,y._offset%4&&y._skip(4-y._offset%4);}if(c<=0)return n;const x=new Ii(t,U,c,!0),u=x._nextUint16(),b=x._nextUint16(),d=x._nextUint32(),m=x._nextUint32(),w=x._nextUint32(),D=x._nextUint32(),B=[];for(let t=0;t<a;t++)B.push({imageFlags:x._nextUint32(),rgbSliceByteOffset:x._nextUint32(),rgbSliceByteLength:x._nextUint32(),alphaSliceByteOffset:x._nextUint32(),alphaSliceByteLength:x._nextUint32()});const L=U+x._offset,A=L+d,k=A+m,v=k+w,S=new Uint8Array(t.buffer,t.byteOffset+L,d),I=new Uint8Array(t.buffer,t.byteOffset+A,m),O=new Uint8Array(t.buffer,t.byteOffset+k,w),T=new Uint8Array(t.buffer,t.byteOffset+v,D);return n.globalData={endpointCount:u,selectorCount:b,imageDescs:B,endpointsData:S,selectorsData:I,tablesData:O,extendedData:T},n}function Ci(){return (Ci=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var i in n)Object.prototype.hasOwnProperty.call(n,i)&&(t[i]=n[i]);}return t}).apply(this,arguments)}const zi={keepWriter:!1};function Mi(t,e={}){e=Ci({},zi,e);let n=new ArrayBuffer(0);if(t.globalData){const e=new ArrayBuffer(20+5*t.globalData.imageDescs.length*4),i=new DataView(e);i.setUint16(0,t.globalData.endpointCount,!0),i.setUint16(2,t.globalData.selectorCount,!0),i.setUint32(4,t.globalData.endpointsData.byteLength,!0),i.setUint32(8,t.globalData.selectorsData.byteLength,!0),i.setUint32(12,t.globalData.tablesData.byteLength,!0),i.setUint32(16,t.globalData.extendedData.byteLength,!0);for(let e=0;e<t.globalData.imageDescs.length;e++){const n=t.globalData.imageDescs[e];i.setUint32(20+5*e*4+0,n.imageFlags,!0),i.setUint32(20+5*e*4+4,n.rgbSliceByteOffset,!0),i.setUint32(20+5*e*4+8,n.rgbSliceByteLength,!0),i.setUint32(20+5*e*4+12,n.alphaSliceByteOffset,!0),i.setUint32(20+5*e*4+16,n.alphaSliceByteLength,!0);}n=Fi([e,t.globalData.endpointsData,t.globalData.selectorsData,t.globalData.tablesData,t.globalData.extendedData]);}const i=[];let s=t.keyValue;e.keepWriter||(s=Ci({},t.keyValue,{KTXwriter:"KTX-Parse v0.3.1"}));for(const t in s){const e=s[t],n=Vi(t),a="string"==typeof e?Vi(e):e,r=n.byteLength+1+a.byteLength+1,o=r%4?4-r%4:0;i.push(Fi([new Uint32Array([r]),n,Oi,a,Oi,new Uint8Array(o).fill(0)]));}const a=Fi(i);if(1!==t.dataFormatDescriptor.length||0!==t.dataFormatDescriptor[0].descriptorType)throw new Error("Only BASICFORMAT Data Format Descriptor output supported.");const r=t.dataFormatDescriptor[0],o=new ArrayBuffer(28+16*r.samples.length),l=new DataView(o),f=24+16*r.samples.length;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`.");l.setUint8(16,r.texelBlockDimension[0]),l.setUint8(17,r.texelBlockDimension[1]),l.setUint8(18,r.texelBlockDimension[2]),l.setUint8(19,r.texelBlockDimension[3]);for(let t=0;t<8;t++)l.setUint8(20+t,r.bytesPlane[t]);for(let t=0;t<r.samples.length;t++){const e=r.samples[t],n=28+16*t;if(e.channelID)throw new Error("channelID has been renamed to channelType.");l.setUint16(n+0,e.bitOffset,!0),l.setUint8(n+2,e.bitLength),l.setUint8(n+3,e.channelType),l.setUint8(n+4,e.samplePosition[0]),l.setUint8(n+5,e.samplePosition[1]),l.setUint8(n+6,e.samplePosition[2]),l.setUint8(n+7,e.samplePosition[3]),64&e.channelType?(l.setInt32(n+8,e.sampleLower,!0),l.setInt32(n+12,e.sampleUpper,!0)):(l.setUint32(n+8,e.sampleLower,!0),l.setUint32(n+12,e.sampleUpper,!0));}const U=Ti.length+68+3*t.levels.length*8,c=U+o.byteLength;let h=n.byteLength>0?c+a.byteLength:0;h%8&&(h+=8-h%8);const _=[],p=new DataView(new ArrayBuffer(3*t.levels.length*8));let g=(h||c+a.byteLength)+n.byteLength;for(let e=0;e<t.levels.length;e++){const n=t.levels[e];_.push(n.levelData),p.setBigUint64(24*e+0,BigInt(g),!0),p.setBigUint64(24*e+8,BigInt(n.levelData.byteLength),!0),p.setBigUint64(24*e+16,BigInt(n.uncompressedByteLength),!0),g+=n.levelData.byteLength;}const y=new ArrayBuffer(68),x=new DataView(y);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,..._]))}
  89795. /**
  89796. * @author Don McCurdy / https://www.donmccurdy.com
  89797. */
  89798. let init, instance, heap;
  89799. const importObject = {
  89800. env: {
  89801. emscripten_notify_memory_growth: function ( index ) {
  89802. heap = new Uint8Array( instance.exports.memory.buffer );
  89803. }
  89804. }
  89805. };
  89806. /**
  89807. * ZSTD (Zstandard) decoder.
  89808. *
  89809. * Compiled from https://github.com/facebook/zstd/tree/dev/contrib/single_file_libs, with the
  89810. * following steps:
  89811. *
  89812. * ```
  89813. * ./combine.sh -r ../../lib -o zstddeclib.c zstddeclib-in.c
  89814. * 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
  89815. * base64 zstddec.wasm > zstddec.txt
  89816. * ```
  89817. *
  89818. * The base64 string written to `zstddec.txt` is embedded as the `wasm` variable at the bottom
  89819. * of this file. The rest of this file is written by hand, in order to avoid an additional JS
  89820. * wrapper generated by Emscripten.
  89821. */
  89822. class ZSTDDecoder {
  89823. init () {
  89824. if ( ! init ) {
  89825. init = fetch( 'data:application/wasm;base64,' + wasm )
  89826. .then( ( response ) => response.arrayBuffer() )
  89827. .then( ( arrayBuffer ) => WebAssembly.instantiate( arrayBuffer, importObject ) )
  89828. .then( ( result ) => {
  89829. instance = result.instance;
  89830. importObject.env.emscripten_notify_memory_growth( 0 ); // initialize heap.
  89831. });
  89832. }
  89833. return init;
  89834. }
  89835. decode ( array, uncompressedSize = 0 ) {
  89836. // Write compressed data into WASM memory.
  89837. const compressedSize = array.byteLength;
  89838. const compressedPtr = instance.exports.malloc( compressedSize );
  89839. heap.set( array, compressedPtr );
  89840. // Decompress into WASM memory.
  89841. uncompressedSize = uncompressedSize || Number( instance.exports.ZSTD_findDecompressedSize( compressedPtr, compressedSize ) );
  89842. const uncompressedPtr = instance.exports.malloc( uncompressedSize );
  89843. const actualSize = instance.exports.ZSTD_decompress( uncompressedPtr, uncompressedSize, compressedPtr, compressedSize );
  89844. // Read decompressed data and free WASM memory.
  89845. const dec = heap.slice( uncompressedPtr, uncompressedPtr + actualSize );
  89846. instance.exports.free( compressedPtr );
  89847. instance.exports.free( uncompressedPtr );
  89848. return dec;
  89849. }
  89850. }
  89851. /**
  89852. * BSD License
  89853. *
  89854. * For Zstandard software
  89855. *
  89856. * Copyright (c) 2016-present, Yann Collet, Facebook, Inc. All rights reserved.
  89857. *
  89858. * Redistribution and use in source and binary forms, with or without modification,
  89859. * are permitted provided that the following conditions are met:
  89860. *
  89861. * * Redistributions of source code must retain the above copyright notice, this
  89862. * list of conditions and the following disclaimer.
  89863. *
  89864. * * Redistributions in binary form must reproduce the above copyright notice,
  89865. * this list of conditions and the following disclaimer in the documentation
  89866. * and/or other materials provided with the distribution.
  89867. *
  89868. * * Neither the name Facebook nor the names of its contributors may be used to
  89869. * endorse or promote products derived from this software without specific
  89870. * prior written permission.
  89871. *
  89872. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  89873. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  89874. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  89875. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  89876. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  89877. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  89878. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  89879. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  89880. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  89881. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  89882. */
  89883. const 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';
  89884. /**
  89885. * Loader for KTX 2.0 GPU Texture containers.
  89886. *
  89887. * KTX 2.0 is a container format for various GPU texture formats. The loader
  89888. * supports Basis Universal GPU textures, which can be quickly transcoded to
  89889. * a wide variety of GPU texture compression formats, as well as some
  89890. * uncompressed DataTexture and Data3DTexture formats.
  89891. *
  89892. * References:
  89893. * - KTX: http://github.khronos.org/KTX-Specification/
  89894. * - DFD: https://www.khronos.org/registry/DataFormat/specs/1.3/dataformat.1.3.html#basicdescriptor
  89895. */
  89896. const _taskCache$1 = new WeakMap();
  89897. let _activeLoaders = 0;
  89898. let _zstd;
  89899. class KTX2Loader extends Loader {
  89900. constructor( manager ) {
  89901. super( manager );
  89902. this.transcoderPath = '';
  89903. this.transcoderBinary = null;
  89904. this.transcoderPending = null;
  89905. this.workerPool = new WorkerPool$1();
  89906. this.workerSourceURL = '';
  89907. this.workerConfig = null;
  89908. if ( typeof MSC_TRANSCODER !== 'undefined' ) {
  89909. console.warn(
  89910. 'THREE.KTX2Loader: Please update to latest "basis_transcoder".'
  89911. + ' "msc_basis_transcoder" is no longer supported in three.js r125+.'
  89912. );
  89913. }
  89914. }
  89915. setTranscoderPath( path ) {
  89916. this.transcoderPath = path;
  89917. return this;
  89918. }
  89919. setWorkerLimit( num ) {
  89920. this.workerPool.setWorkerLimit( num );
  89921. return this;
  89922. }
  89923. detectSupport( renderer ) {
  89924. this.workerConfig = {
  89925. astcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_astc' ),
  89926. etc1Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc1' ),
  89927. etc2Supported: renderer.extensions.has( 'WEBGL_compressed_texture_etc' ),
  89928. dxtSupported: renderer.extensions.has( 'WEBGL_compressed_texture_s3tc' ),
  89929. bptcSupported: renderer.extensions.has( 'EXT_texture_compression_bptc' ),
  89930. pvrtcSupported: renderer.extensions.has( 'WEBGL_compressed_texture_pvrtc' )
  89931. || renderer.extensions.has( 'WEBKIT_WEBGL_compressed_texture_pvrtc' )
  89932. };
  89933. if ( renderer.capabilities.isWebGL2 ) {
  89934. // https://github.com/mrdoob/three.js/pull/22928
  89935. this.workerConfig.etc1Supported = false;
  89936. }
  89937. return this;
  89938. }
  89939. init() {
  89940. if ( ! this.transcoderPending ) {
  89941. // Load transcoder wrapper.
  89942. const jsLoader = new FileLoader( this.manager );
  89943. jsLoader.setPath( this.transcoderPath );
  89944. jsLoader.setWithCredentials( this.withCredentials );
  89945. const jsContent = jsLoader.loadAsync( 'basis_transcoder.js' );
  89946. // Load transcoder WASM binary.
  89947. const binaryLoader = new FileLoader( this.manager );
  89948. binaryLoader.setPath( this.transcoderPath );
  89949. binaryLoader.setResponseType( 'arraybuffer' );
  89950. binaryLoader.setWithCredentials( this.withCredentials );
  89951. const binaryContent = binaryLoader.loadAsync( 'basis_transcoder.wasm' );
  89952. this.transcoderPending = Promise.all( [ jsContent, binaryContent ] )
  89953. .then( ( [ jsContent, binaryContent ] ) => {
  89954. const fn = KTX2Loader.BasisWorker.toString();
  89955. const body = [
  89956. '/* constants */',
  89957. 'let _EngineFormat = ' + JSON.stringify( KTX2Loader.EngineFormat ),
  89958. 'let _TranscoderFormat = ' + JSON.stringify( KTX2Loader.TranscoderFormat ),
  89959. 'let _BasisFormat = ' + JSON.stringify( KTX2Loader.BasisFormat ),
  89960. '/* basis_transcoder.js */',
  89961. jsContent,
  89962. '/* worker */',
  89963. fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
  89964. ].join( '\n' );
  89965. this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
  89966. this.transcoderBinary = binaryContent;
  89967. this.workerPool.setWorkerCreator( () => {
  89968. const worker = new Worker( this.workerSourceURL );
  89969. const transcoderBinary = this.transcoderBinary.slice( 0 );
  89970. worker.postMessage( { type: 'init', config: this.workerConfig, transcoderBinary }, [ transcoderBinary ] );
  89971. return worker;
  89972. } );
  89973. } );
  89974. if ( _activeLoaders > 0 ) {
  89975. // Each instance loads a transcoder and allocates workers, increasing network and memory cost.
  89976. console.warn(
  89977. 'THREE.KTX2Loader: Multiple active KTX2 loaders may cause performance issues.'
  89978. + ' Use a single KTX2Loader instance, or call .dispose() on old instances.'
  89979. );
  89980. }
  89981. _activeLoaders ++;
  89982. }
  89983. return this.transcoderPending;
  89984. }
  89985. load( url, onLoad, onProgress, onError ) {
  89986. if ( this.workerConfig === null ) {
  89987. throw new Error( 'THREE.KTX2Loader: Missing initialization with `.detectSupport( renderer )`.' );
  89988. }
  89989. const loader = new FileLoader( this.manager );
  89990. loader.setResponseType( 'arraybuffer' );
  89991. loader.setWithCredentials( this.withCredentials );
  89992. loader.load( url, ( buffer ) => {
  89993. // Check for an existing task using this buffer. A transferred buffer cannot be transferred
  89994. // again from this thread.
  89995. if ( _taskCache$1.has( buffer ) ) {
  89996. const cachedTask = _taskCache$1.get( buffer );
  89997. return cachedTask.promise.then( onLoad ).catch( onError );
  89998. }
  89999. this._createTexture( buffer )
  90000. .then( ( texture ) => onLoad ? onLoad( texture ) : null )
  90001. .catch( onError );
  90002. }, onProgress, onError );
  90003. }
  90004. _createTextureFrom( transcodeResult, container ) {
  90005. const { mipmaps, width, height, format, type, error, dfdTransferFn, dfdFlags } = transcodeResult;
  90006. if ( type === 'error' ) return Promise.reject( error );
  90007. const texture = container.layerCount > 1
  90008. ? new CompressedArrayTexture( mipmaps, width, height, container.layerCount, format, UnsignedByteType )
  90009. : new CompressedTexture( mipmaps, width, height, format, UnsignedByteType );
  90010. texture.minFilter = mipmaps.length === 1 ? LinearFilter : LinearMipmapLinearFilter;
  90011. texture.magFilter = LinearFilter;
  90012. texture.generateMipmaps = false;
  90013. texture.needsUpdate = true;
  90014. texture.encoding = dfdTransferFn === x$2 ? sRGBEncoding : LinearEncoding;
  90015. texture.premultiplyAlpha = !! ( dfdFlags & p );
  90016. return texture;
  90017. }
  90018. /**
  90019. * @param {ArrayBuffer} buffer
  90020. * @param {object?} config
  90021. * @return {Promise<CompressedTexture|CompressedArrayTexture|DataTexture|Data3DTexture>}
  90022. */
  90023. async _createTexture( buffer, config = {} ) {
  90024. const container = Pi( new Uint8Array( buffer ) );
  90025. if ( container.vkFormat !== nt ) {
  90026. return createDataTexture( container );
  90027. }
  90028. //
  90029. const taskConfig = config;
  90030. const texturePending = this.init().then( () => {
  90031. return this.workerPool.postMessage( { type: 'transcode', buffer, taskConfig: taskConfig }, [ buffer ] );
  90032. } ).then( ( e ) => this._createTextureFrom( e.data, container ) );
  90033. // Cache the task result.
  90034. _taskCache$1.set( buffer, { promise: texturePending } );
  90035. return texturePending;
  90036. }
  90037. dispose() {
  90038. this.workerPool.dispose();
  90039. if ( this.workerSourceURL ) URL.revokeObjectURL( this.workerSourceURL );
  90040. _activeLoaders --;
  90041. return this;
  90042. }
  90043. }
  90044. /* CONSTANTS */
  90045. KTX2Loader.BasisFormat = {
  90046. ETC1S: 0,
  90047. UASTC_4x4: 1,
  90048. };
  90049. KTX2Loader.TranscoderFormat = {
  90050. ETC1: 0,
  90051. ETC2: 1,
  90052. BC1: 2,
  90053. BC3: 3,
  90054. BC4: 4,
  90055. BC5: 5,
  90056. BC7_M6_OPAQUE_ONLY: 6,
  90057. BC7_M5: 7,
  90058. PVRTC1_4_RGB: 8,
  90059. PVRTC1_4_RGBA: 9,
  90060. ASTC_4x4: 10,
  90061. ATC_RGB: 11,
  90062. ATC_RGBA_INTERPOLATED_ALPHA: 12,
  90063. RGBA32: 13,
  90064. RGB565: 14,
  90065. BGR565: 15,
  90066. RGBA4444: 16,
  90067. };
  90068. KTX2Loader.EngineFormat = {
  90069. RGBAFormat: RGBAFormat,
  90070. RGBA_ASTC_4x4_Format: RGBA_ASTC_4x4_Format,
  90071. RGBA_BPTC_Format: RGBA_BPTC_Format,
  90072. RGBA_ETC2_EAC_Format: RGBA_ETC2_EAC_Format,
  90073. RGBA_PVRTC_4BPPV1_Format: RGBA_PVRTC_4BPPV1_Format,
  90074. RGBA_S3TC_DXT5_Format: RGBA_S3TC_DXT5_Format$1,
  90075. RGB_ETC1_Format: RGB_ETC1_Format,
  90076. RGB_ETC2_Format: RGB_ETC2_Format,
  90077. RGB_PVRTC_4BPPV1_Format: RGB_PVRTC_4BPPV1_Format,
  90078. RGB_S3TC_DXT1_Format: RGB_S3TC_DXT1_Format,
  90079. };
  90080. /* WEB WORKER */
  90081. KTX2Loader.BasisWorker = function () {
  90082. let config;
  90083. let transcoderPending;
  90084. let BasisModule;
  90085. const EngineFormat = _EngineFormat; // eslint-disable-line no-undef
  90086. const TranscoderFormat = _TranscoderFormat; // eslint-disable-line no-undef
  90087. const BasisFormat = _BasisFormat; // eslint-disable-line no-undef
  90088. self.addEventListener( 'message', function ( e ) {
  90089. const message = e.data;
  90090. switch ( message.type ) {
  90091. case 'init':
  90092. config = message.config;
  90093. init( message.transcoderBinary );
  90094. break;
  90095. case 'transcode':
  90096. transcoderPending.then( () => {
  90097. try {
  90098. const { width, height, hasAlpha, mipmaps, format, dfdTransferFn, dfdFlags } = transcode( message.buffer );
  90099. const buffers = [];
  90100. for ( let i = 0; i < mipmaps.length; ++ i ) {
  90101. buffers.push( mipmaps[ i ].data.buffer );
  90102. }
  90103. self.postMessage( { type: 'transcode', id: message.id, width, height, hasAlpha, mipmaps, format, dfdTransferFn, dfdFlags }, buffers );
  90104. } catch ( error ) {
  90105. console.error( error );
  90106. self.postMessage( { type: 'error', id: message.id, error: error.message } );
  90107. }
  90108. } );
  90109. break;
  90110. }
  90111. } );
  90112. function init( wasmBinary ) {
  90113. transcoderPending = new Promise( ( resolve ) => {
  90114. BasisModule = { wasmBinary, onRuntimeInitialized: resolve };
  90115. BASIS( BasisModule ); // eslint-disable-line no-undef
  90116. } ).then( () => {
  90117. BasisModule.initializeBasis();
  90118. if ( BasisModule.KTX2File === undefined ) {
  90119. console.warn( 'THREE.KTX2Loader: Please update Basis Universal transcoder.' );
  90120. }
  90121. } );
  90122. }
  90123. function transcode( buffer ) {
  90124. const ktx2File = new BasisModule.KTX2File( new Uint8Array( buffer ) );
  90125. function cleanup() {
  90126. ktx2File.close();
  90127. ktx2File.delete();
  90128. }
  90129. if ( ! ktx2File.isValid() ) {
  90130. cleanup();
  90131. throw new Error( 'THREE.KTX2Loader: Invalid or unsupported .ktx2 file' );
  90132. }
  90133. const basisFormat = ktx2File.isUASTC() ? BasisFormat.UASTC_4x4 : BasisFormat.ETC1S;
  90134. const width = ktx2File.getWidth();
  90135. const height = ktx2File.getHeight();
  90136. const layers = ktx2File.getLayers() || 1;
  90137. const levels = ktx2File.getLevels();
  90138. const hasAlpha = ktx2File.getHasAlpha();
  90139. const dfdTransferFn = ktx2File.getDFDTransferFunc();
  90140. const dfdFlags = ktx2File.getDFDFlags();
  90141. const { transcoderFormat, engineFormat } = getTranscoderFormat( basisFormat, width, height, hasAlpha );
  90142. if ( ! width || ! height || ! levels ) {
  90143. cleanup();
  90144. throw new Error( 'THREE.KTX2Loader: Invalid texture' );
  90145. }
  90146. if ( ! ktx2File.startTranscoding() ) {
  90147. cleanup();
  90148. throw new Error( 'THREE.KTX2Loader: .startTranscoding failed' );
  90149. }
  90150. const mipmaps = [];
  90151. for ( let mip = 0; mip < levels; mip ++ ) {
  90152. const layerMips = [];
  90153. let mipWidth, mipHeight;
  90154. for ( let layer = 0; layer < layers; layer ++ ) {
  90155. const levelInfo = ktx2File.getImageLevelInfo( mip, layer, 0 );
  90156. mipWidth = levelInfo.origWidth;
  90157. mipHeight = levelInfo.origHeight;
  90158. const dst = new Uint8Array( ktx2File.getImageTranscodedSizeInBytes( mip, layer, 0, transcoderFormat ) );
  90159. const status = ktx2File.transcodeImage(
  90160. dst,
  90161. mip,
  90162. layer,
  90163. 0,
  90164. transcoderFormat,
  90165. 0,
  90166. - 1,
  90167. - 1,
  90168. );
  90169. if ( ! status ) {
  90170. cleanup();
  90171. throw new Error( 'THREE.KTX2Loader: .transcodeImage failed.' );
  90172. }
  90173. layerMips.push( dst );
  90174. }
  90175. mipmaps.push( { data: concat( layerMips ), width: mipWidth, height: mipHeight } );
  90176. }
  90177. cleanup();
  90178. return { width, height, hasAlpha, mipmaps, format: engineFormat, dfdTransferFn, dfdFlags };
  90179. }
  90180. //
  90181. // Optimal choice of a transcoder target format depends on the Basis format (ETC1S or UASTC),
  90182. // device capabilities, and texture dimensions. The list below ranks the formats separately
  90183. // for ETC1S and UASTC.
  90184. //
  90185. // In some cases, transcoding UASTC to RGBA32 might be preferred for higher quality (at
  90186. // significant memory cost) compared to ETC1/2, BC1/3, and PVRTC. The transcoder currently
  90187. // chooses RGBA32 only as a last resort and does not expose that option to the caller.
  90188. const FORMAT_OPTIONS = [
  90189. {
  90190. if: 'astcSupported',
  90191. basisFormat: [ BasisFormat.UASTC_4x4 ],
  90192. transcoderFormat: [ TranscoderFormat.ASTC_4x4, TranscoderFormat.ASTC_4x4 ],
  90193. engineFormat: [ EngineFormat.RGBA_ASTC_4x4_Format, EngineFormat.RGBA_ASTC_4x4_Format ],
  90194. priorityETC1S: Infinity,
  90195. priorityUASTC: 1,
  90196. needsPowerOfTwo: false,
  90197. },
  90198. {
  90199. if: 'bptcSupported',
  90200. basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
  90201. transcoderFormat: [ TranscoderFormat.BC7_M5, TranscoderFormat.BC7_M5 ],
  90202. engineFormat: [ EngineFormat.RGBA_BPTC_Format, EngineFormat.RGBA_BPTC_Format ],
  90203. priorityETC1S: 3,
  90204. priorityUASTC: 2,
  90205. needsPowerOfTwo: false,
  90206. },
  90207. {
  90208. if: 'dxtSupported',
  90209. basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
  90210. transcoderFormat: [ TranscoderFormat.BC1, TranscoderFormat.BC3 ],
  90211. engineFormat: [ EngineFormat.RGB_S3TC_DXT1_Format, EngineFormat.RGBA_S3TC_DXT5_Format ],
  90212. priorityETC1S: 4,
  90213. priorityUASTC: 5,
  90214. needsPowerOfTwo: false,
  90215. },
  90216. {
  90217. if: 'etc2Supported',
  90218. basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
  90219. transcoderFormat: [ TranscoderFormat.ETC1, TranscoderFormat.ETC2 ],
  90220. engineFormat: [ EngineFormat.RGB_ETC2_Format, EngineFormat.RGBA_ETC2_EAC_Format ],
  90221. priorityETC1S: 1,
  90222. priorityUASTC: 3,
  90223. needsPowerOfTwo: false,
  90224. },
  90225. {
  90226. if: 'etc1Supported',
  90227. basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
  90228. transcoderFormat: [ TranscoderFormat.ETC1 ],
  90229. engineFormat: [ EngineFormat.RGB_ETC1_Format ],
  90230. priorityETC1S: 2,
  90231. priorityUASTC: 4,
  90232. needsPowerOfTwo: false,
  90233. },
  90234. {
  90235. if: 'pvrtcSupported',
  90236. basisFormat: [ BasisFormat.ETC1S, BasisFormat.UASTC_4x4 ],
  90237. transcoderFormat: [ TranscoderFormat.PVRTC1_4_RGB, TranscoderFormat.PVRTC1_4_RGBA ],
  90238. engineFormat: [ EngineFormat.RGB_PVRTC_4BPPV1_Format, EngineFormat.RGBA_PVRTC_4BPPV1_Format ],
  90239. priorityETC1S: 5,
  90240. priorityUASTC: 6,
  90241. needsPowerOfTwo: true,
  90242. },
  90243. ];
  90244. const ETC1S_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
  90245. return a.priorityETC1S - b.priorityETC1S;
  90246. } );
  90247. const UASTC_OPTIONS = FORMAT_OPTIONS.sort( function ( a, b ) {
  90248. return a.priorityUASTC - b.priorityUASTC;
  90249. } );
  90250. function getTranscoderFormat( basisFormat, width, height, hasAlpha ) {
  90251. let transcoderFormat;
  90252. let engineFormat;
  90253. const options = basisFormat === BasisFormat.ETC1S ? ETC1S_OPTIONS : UASTC_OPTIONS;
  90254. for ( let i = 0; i < options.length; i ++ ) {
  90255. const opt = options[ i ];
  90256. if ( ! config[ opt.if ] ) continue;
  90257. if ( ! opt.basisFormat.includes( basisFormat ) ) continue;
  90258. if ( hasAlpha && opt.transcoderFormat.length < 2 ) continue;
  90259. if ( opt.needsPowerOfTwo && ! ( isPowerOfTwo( width ) && isPowerOfTwo( height ) ) ) continue;
  90260. transcoderFormat = opt.transcoderFormat[ hasAlpha ? 1 : 0 ];
  90261. engineFormat = opt.engineFormat[ hasAlpha ? 1 : 0 ];
  90262. return { transcoderFormat, engineFormat };
  90263. }
  90264. console.warn( 'THREE.KTX2Loader: No suitable compressed texture format found. Decoding to RGBA32.' );
  90265. transcoderFormat = TranscoderFormat.RGBA32;
  90266. engineFormat = EngineFormat.RGBAFormat;
  90267. return { transcoderFormat, engineFormat };
  90268. }
  90269. function isPowerOfTwo( value ) {
  90270. if ( value <= 2 ) return true;
  90271. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  90272. }
  90273. /** Concatenates N byte arrays. */
  90274. function concat( arrays ) {
  90275. let totalByteLength = 0;
  90276. for ( const array of arrays ) {
  90277. totalByteLength += array.byteLength;
  90278. }
  90279. const result = new Uint8Array( totalByteLength );
  90280. let byteOffset = 0;
  90281. for ( const array of arrays ) {
  90282. result.set( array, byteOffset );
  90283. byteOffset += array.byteLength;
  90284. }
  90285. return result;
  90286. }
  90287. };
  90288. //
  90289. // DataTexture and Data3DTexture parsing.
  90290. const FORMAT_MAP = {
  90291. [ Ae ]: RGBAFormat,
  90292. [ pe ]: RGBAFormat,
  90293. [ Ot ]: RGBAFormat,
  90294. [ Ft ]: RGBAFormat,
  90295. [ de ]: RGFormat,
  90296. [ se ]: RGFormat,
  90297. [ yt ]: RGFormat,
  90298. [ dt ]: RGFormat,
  90299. [ xe ]: RedFormat,
  90300. [ $t ]: RedFormat,
  90301. [ gt ]: RedFormat,
  90302. [ ct ]: RedFormat,
  90303. };
  90304. const TYPE_MAP = {
  90305. [ Ae ]: FloatType,
  90306. [ pe ]: HalfFloatType,
  90307. [ Ot ]: UnsignedByteType,
  90308. [ Ft ]: UnsignedByteType,
  90309. [ de ]: FloatType,
  90310. [ se ]: HalfFloatType,
  90311. [ yt ]: UnsignedByteType,
  90312. [ dt ]: UnsignedByteType,
  90313. [ xe ]: FloatType,
  90314. [ $t ]: HalfFloatType,
  90315. [ gt ]: UnsignedByteType,
  90316. [ ct ]: UnsignedByteType,
  90317. };
  90318. const ENCODING_MAP = {
  90319. [ Ft ]: sRGBEncoding,
  90320. [ dt ]: sRGBEncoding,
  90321. [ gt ]: sRGBEncoding,
  90322. };
  90323. async function createDataTexture( container ) {
  90324. const { vkFormat, pixelWidth, pixelHeight, pixelDepth } = container;
  90325. if ( FORMAT_MAP[ vkFormat ] === undefined ) {
  90326. throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' );
  90327. }
  90328. const level = container.levels[ 0 ];
  90329. let levelData;
  90330. let view;
  90331. if ( container.supercompressionScheme === t ) {
  90332. levelData = level.levelData;
  90333. } else if ( container.supercompressionScheme === n$1 ) {
  90334. if ( ! _zstd ) {
  90335. _zstd = new Promise( async ( resolve ) => {
  90336. const zstd = new ZSTDDecoder();
  90337. await zstd.init();
  90338. resolve( zstd );
  90339. } );
  90340. }
  90341. levelData = ( await _zstd ).decode( level.levelData, level.uncompressedByteLength );
  90342. } else {
  90343. throw new Error( 'THREE.KTX2Loader: Unsupported supercompressionScheme.' );
  90344. }
  90345. if ( TYPE_MAP[ vkFormat ] === FloatType ) {
  90346. view = new Float32Array(
  90347. levelData.buffer,
  90348. levelData.byteOffset,
  90349. levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
  90350. );
  90351. } else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
  90352. view = new Uint16Array(
  90353. levelData.buffer,
  90354. levelData.byteOffset,
  90355. levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT
  90356. );
  90357. } else {
  90358. view = levelData;
  90359. }
  90360. //
  90361. const texture = pixelDepth === 0
  90362. ? new DataTexture( view, pixelWidth, pixelHeight )
  90363. : new Data3DTexture( view, pixelWidth, pixelHeight, pixelDepth );
  90364. texture.type = TYPE_MAP[ vkFormat ];
  90365. texture.format = FORMAT_MAP[ vkFormat ];
  90366. texture.encoding = ENCODING_MAP[ vkFormat ] || LinearEncoding;
  90367. texture.needsUpdate = true;
  90368. //
  90369. return Promise.resolve( texture );
  90370. }
  90371. // This file is part of meshoptimizer library and is distributed under the terms of MIT License.
  90372. // Copyright (C) 2016-2020, by Arseny Kapoulkine (arseny.kapoulkine@gmail.com)
  90373. var MeshoptDecoder = (function() {
  90374. "use strict";
  90375. // Built with clang version 11.0.0 (https://github.com/llvm/llvm-project.git 0160ad802e899c2922bc9b29564080c22eb0908c)
  90376. // Built from meshoptimizer 0.14
  90377. 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";
  90378. 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";
  90379. // Uses bulk-memory and simd extensions
  90380. 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]);
  90381. // Used to unpack wasm
  90382. 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]);
  90383. if (typeof WebAssembly !== 'object') {
  90384. // This module requires WebAssembly to function
  90385. return {
  90386. supported: false,
  90387. };
  90388. }
  90389. var wasm = wasm_base;
  90390. if (WebAssembly.validate(detector)) {
  90391. wasm = wasm_simd;
  90392. console.log("Warning: meshopt_decoder is using experimental SIMD support");
  90393. }
  90394. var instance;
  90395. var promise =
  90396. WebAssembly.instantiate(unpack(wasm), {})
  90397. .then(function(result) {
  90398. instance = result.instance;
  90399. instance.exports.__wasm_call_ctors();
  90400. });
  90401. function unpack(data) {
  90402. var result = new Uint8Array(data.length);
  90403. for (var i = 0; i < data.length; ++i) {
  90404. var ch = data.charCodeAt(i);
  90405. result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62;
  90406. }
  90407. var write = 0;
  90408. for (var i = 0; i < data.length; ++i) {
  90409. result[write++] = (result[i] < 60) ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];
  90410. }
  90411. return result.buffer.slice(0, write);
  90412. }
  90413. function decode(fun, target, count, size, source, filter) {
  90414. var sbrk = instance.exports.sbrk;
  90415. var count4 = (count + 3) & ~3; // pad for SIMD filter
  90416. var tp = sbrk(count4 * size);
  90417. var sp = sbrk(source.length);
  90418. var heap = new Uint8Array(instance.exports.memory.buffer);
  90419. heap.set(source, sp);
  90420. var res = fun(tp, count, size, sp, source.length);
  90421. if (res == 0 && filter) {
  90422. filter(tp, count4, size);
  90423. }
  90424. target.set(heap.subarray(tp, tp + count * size));
  90425. sbrk(tp - sbrk(0));
  90426. if (res != 0) {
  90427. throw new Error("Malformed buffer data: " + res);
  90428. }
  90429. };
  90430. var filters = {
  90431. // legacy index-based enums for glTF
  90432. 0: "",
  90433. 1: "meshopt_decodeFilterOct",
  90434. 2: "meshopt_decodeFilterQuat",
  90435. 3: "meshopt_decodeFilterExp",
  90436. // string-based enums for glTF
  90437. NONE: "",
  90438. OCTAHEDRAL: "meshopt_decodeFilterOct",
  90439. QUATERNION: "meshopt_decodeFilterQuat",
  90440. EXPONENTIAL: "meshopt_decodeFilterExp",
  90441. };
  90442. var decoders = {
  90443. // legacy index-based enums for glTF
  90444. 0: "meshopt_decodeVertexBuffer",
  90445. 1: "meshopt_decodeIndexBuffer",
  90446. 2: "meshopt_decodeIndexSequence",
  90447. // string-based enums for glTF
  90448. ATTRIBUTES: "meshopt_decodeVertexBuffer",
  90449. TRIANGLES: "meshopt_decodeIndexBuffer",
  90450. INDICES: "meshopt_decodeIndexSequence",
  90451. };
  90452. return {
  90453. ready: promise,
  90454. supported: true,
  90455. decodeVertexBuffer: function(target, count, size, source, filter) {
  90456. decode(instance.exports.meshopt_decodeVertexBuffer, target, count, size, source, instance.exports[filters[filter]]);
  90457. },
  90458. decodeIndexBuffer: function(target, count, size, source) {
  90459. decode(instance.exports.meshopt_decodeIndexBuffer, target, count, size, source);
  90460. },
  90461. decodeIndexSequence: function(target, count, size, source) {
  90462. decode(instance.exports.meshopt_decodeIndexSequence, target, count, size, source);
  90463. },
  90464. decodeGltfBuffer: function(target, count, size, source, mode, filter) {
  90465. decode(instance.exports[decoders[mode]], target, count, size, source, instance.exports[filters[filter]]);
  90466. }
  90467. };
  90468. })();
  90469. var DDSLoader = function ( manager ) {
  90470. CompressedTextureLoader.call( this, manager );
  90471. };
  90472. DDSLoader.prototype = Object.assign( Object.create( CompressedTextureLoader.prototype ), {
  90473. constructor: DDSLoader,
  90474. parse: function ( buffer, loadMipmaps ) {
  90475. var dds = { mipmaps: [], width: 0, height: 0, format: null, mipmapCount: 1 };
  90476. // Adapted from @toji's DDS utils
  90477. // https://github.com/toji/webgl-texture-utils/blob/master/texture-util/dds.js
  90478. // All values and structures referenced from:
  90479. // http://msdn.microsoft.com/en-us/library/bb943991.aspx/
  90480. var DDS_MAGIC = 0x20534444;
  90481. // var DDSD_CAPS = 0x1;
  90482. // var DDSD_HEIGHT = 0x2;
  90483. // var DDSD_WIDTH = 0x4;
  90484. // var DDSD_PITCH = 0x8;
  90485. // var DDSD_PIXELFORMAT = 0x1000;
  90486. var DDSD_MIPMAPCOUNT = 0x20000;
  90487. // var DDSD_LINEARSIZE = 0x80000;
  90488. // var DDSD_DEPTH = 0x800000;
  90489. // var DDSCAPS_COMPLEX = 0x8;
  90490. // var DDSCAPS_MIPMAP = 0x400000;
  90491. // var DDSCAPS_TEXTURE = 0x1000;
  90492. var DDSCAPS2_CUBEMAP = 0x200;
  90493. var DDSCAPS2_CUBEMAP_POSITIVEX = 0x400;
  90494. var DDSCAPS2_CUBEMAP_NEGATIVEX = 0x800;
  90495. var DDSCAPS2_CUBEMAP_POSITIVEY = 0x1000;
  90496. var DDSCAPS2_CUBEMAP_NEGATIVEY = 0x2000;
  90497. var DDSCAPS2_CUBEMAP_POSITIVEZ = 0x4000;
  90498. var DDSCAPS2_CUBEMAP_NEGATIVEZ = 0x8000;
  90499. // var DDSCAPS2_VOLUME = 0x200000;
  90500. // var DDPF_ALPHAPIXELS = 0x1;
  90501. // var DDPF_ALPHA = 0x2;
  90502. var DDPF_FOURCC = 0x4;
  90503. // var DDPF_RGB = 0x40;
  90504. // var DDPF_YUV = 0x200;
  90505. // var DDPF_LUMINANCE = 0x20000;
  90506. function fourCCToInt32( value ) {
  90507. return value.charCodeAt( 0 ) +
  90508. ( value.charCodeAt( 1 ) << 8 ) +
  90509. ( value.charCodeAt( 2 ) << 16 ) +
  90510. ( value.charCodeAt( 3 ) << 24 );
  90511. }
  90512. function int32ToFourCC( value ) {
  90513. return String.fromCharCode(
  90514. value & 0xff,
  90515. ( value >> 8 ) & 0xff,
  90516. ( value >> 16 ) & 0xff,
  90517. ( value >> 24 ) & 0xff
  90518. );
  90519. }
  90520. function loadARGBMip( buffer, dataOffset, width, height ) {
  90521. var dataLength = width * height * 4;
  90522. var srcBuffer = new Uint8Array( buffer, dataOffset, dataLength );
  90523. var byteArray = new Uint8Array( dataLength );
  90524. var dst = 0;
  90525. var src = 0;
  90526. for ( var y = 0; y < height; y ++ ) {
  90527. for ( var x = 0; x < width; x ++ ) {
  90528. var b = srcBuffer[ src ]; src ++;
  90529. var g = srcBuffer[ src ]; src ++;
  90530. var r = srcBuffer[ src ]; src ++;
  90531. var a = srcBuffer[ src ]; src ++;
  90532. byteArray[ dst ] = r; dst ++; //r
  90533. byteArray[ dst ] = g; dst ++; //g
  90534. byteArray[ dst ] = b; dst ++; //b
  90535. byteArray[ dst ] = a; dst ++; //a
  90536. }
  90537. }
  90538. return byteArray;
  90539. }
  90540. var FOURCC_DXT1 = fourCCToInt32( 'DXT1' );
  90541. var FOURCC_DXT3 = fourCCToInt32( 'DXT3' );
  90542. var FOURCC_DXT5 = fourCCToInt32( 'DXT5' );
  90543. var FOURCC_ETC1 = fourCCToInt32( 'ETC1' );
  90544. var headerLengthInt = 31; // The header length in 32 bit ints
  90545. // Offsets into the header array
  90546. var off_magic = 0;
  90547. var off_size = 1;
  90548. var off_flags = 2;
  90549. var off_height = 3;
  90550. var off_width = 4;
  90551. var off_mipmapCount = 7;
  90552. var off_pfFlags = 20;
  90553. var off_pfFourCC = 21;
  90554. var off_RGBBitCount = 22;
  90555. var off_RBitMask = 23;
  90556. var off_GBitMask = 24;
  90557. var off_BBitMask = 25;
  90558. var off_ABitMask = 26;
  90559. // var off_caps = 27;
  90560. var off_caps2 = 28;
  90561. // var off_caps3 = 29;
  90562. // var off_caps4 = 30;
  90563. // Parse header
  90564. var header = new Int32Array( buffer, 0, headerLengthInt );
  90565. if ( header[ off_magic ] !== DDS_MAGIC ) {
  90566. console.error( 'THREE.DDSLoader.parse: Invalid magic number in DDS header.' );
  90567. return dds;
  90568. }
  90569. if ( ! header[ off_pfFlags ] & DDPF_FOURCC ) {
  90570. console.error( 'THREE.DDSLoader.parse: Unsupported format, must contain a FourCC code.' );
  90571. return dds;
  90572. }
  90573. var blockBytes;
  90574. var fourCC = header[ off_pfFourCC ];
  90575. var isRGBAUncompressed = false;
  90576. switch ( fourCC ) {
  90577. case FOURCC_DXT1:
  90578. blockBytes = 8;
  90579. dds.format = RGB_S3TC_DXT1_Format;
  90580. break;
  90581. case FOURCC_DXT3:
  90582. blockBytes = 16;
  90583. dds.format = RGBA_S3TC_DXT3_Format;
  90584. break;
  90585. case FOURCC_DXT5:
  90586. blockBytes = 16;
  90587. dds.format = RGBA_S3TC_DXT5_Format$1;
  90588. break;
  90589. case FOURCC_ETC1:
  90590. blockBytes = 8;
  90591. dds.format = RGB_ETC1_Format;
  90592. break;
  90593. default:
  90594. if ( header[ off_RGBBitCount ] === 32
  90595. && header[ off_RBitMask ] & 0xff0000
  90596. && header[ off_GBitMask ] & 0xff00
  90597. && header[ off_BBitMask ] & 0xff
  90598. && header[ off_ABitMask ] & 0xff000000 ) {
  90599. isRGBAUncompressed = true;
  90600. blockBytes = 64;
  90601. dds.format = RGBAFormat;
  90602. } else {
  90603. console.error( 'THREE.DDSLoader.parse: Unsupported FourCC code ', int32ToFourCC( fourCC ) );
  90604. return dds;
  90605. }
  90606. }
  90607. dds.mipmapCount = 1;
  90608. if ( header[ off_flags ] & DDSD_MIPMAPCOUNT && loadMipmaps !== false ) {
  90609. dds.mipmapCount = Math.max( 1, header[ off_mipmapCount ] );
  90610. }
  90611. var caps2 = header[ off_caps2 ];
  90612. dds.isCubemap = caps2 & DDSCAPS2_CUBEMAP ? true : false;
  90613. if ( dds.isCubemap && (
  90614. ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEX ) ||
  90615. ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEX ) ||
  90616. ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEY ) ||
  90617. ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEY ) ||
  90618. ! ( caps2 & DDSCAPS2_CUBEMAP_POSITIVEZ ) ||
  90619. ! ( caps2 & DDSCAPS2_CUBEMAP_NEGATIVEZ )
  90620. ) ) {
  90621. console.error( 'THREE.DDSLoader.parse: Incomplete cubemap faces' );
  90622. return dds;
  90623. }
  90624. dds.width = header[ off_width ];
  90625. dds.height = header[ off_height ];
  90626. var dataOffset = header[ off_size ] + 4;
  90627. // Extract mipmaps buffers
  90628. var faces = dds.isCubemap ? 6 : 1;
  90629. for ( var face = 0; face < faces; face ++ ) {
  90630. var width = dds.width;
  90631. var height = dds.height;
  90632. for ( var i = 0; i < dds.mipmapCount; i ++ ) {
  90633. if ( isRGBAUncompressed ) {
  90634. var byteArray = loadARGBMip( buffer, dataOffset, width, height );
  90635. var dataLength = byteArray.length;
  90636. } else {
  90637. var dataLength = Math.max( 4, width ) / 4 * Math.max( 4, height ) / 4 * blockBytes;
  90638. var byteArray = new Uint8Array( buffer, dataOffset, dataLength );
  90639. }
  90640. var mipmap = { 'data': byteArray, 'width': width, 'height': height };
  90641. dds.mipmaps.push( mipmap );
  90642. dataOffset += dataLength;
  90643. width = Math.max( width >> 1, 1 );
  90644. height = Math.max( height >> 1, 1 );
  90645. }
  90646. }
  90647. return dds;
  90648. }
  90649. } );
  90650. //xzw add:----
  90651. let unknownExtensions = {};
  90652. let oldSet = MeshBasicMaterial.prototype.setValues;
  90653. MeshBasicMaterial.prototype.setValues = function(values){
  90654. return oldSet.call(this,values)
  90655. };
  90656. class GLTFLoader extends Loader {
  90657. constructor( manager, renderer, urlPrefix ) {
  90658. super( manager );
  90659. //xzw add:
  90660. this.dracoLoader = new DRACOLoader;
  90661. this.ktx2Loader = new KTX2Loader;
  90662. this.meshoptDecoder = MeshoptDecoder;
  90663. this.ddsLoader = new DDSLoader; //这个没测过
  90664. //路径相对于index.html
  90665. this.dracoLoader.setDecoderPath( urlPrefix + 'three.js/loaders/draco/' /*or 'https://unpkg.com/three@0.144.0/examples/js/libs/draco/gltf/' 版本可升级 */); //这两个路径可以自己改。在laser的环境也要放一份这个路径
  90666. this.ktx2Loader.setTranscoderPath(urlPrefix + 'three.js/loaders/basis/' /*or 'https://unpkg.com/three@0.144.0/examples/js/libs/basis/' 版本可升级 */).detectSupport( renderer );
  90667. this.pluginCallbacks = [];
  90668. this.register( function ( parser ) {
  90669. return new GLTFMaterialsClearcoatExtension( parser );
  90670. } );
  90671. this.register( function ( parser ) {
  90672. return new GLTFTextureBasisUExtension( parser );
  90673. } );
  90674. this.register( function ( parser ) {
  90675. return new GLTFTextureWebPExtension( parser );
  90676. } );
  90677. this.register( function ( parser ) {
  90678. return new GLTFMaterialsSheenExtension( parser );
  90679. } );
  90680. this.register( function ( parser ) {
  90681. return new GLTFMaterialsTransmissionExtension( parser );
  90682. } );
  90683. this.register( function ( parser ) {
  90684. return new GLTFMaterialsVolumeExtension( parser );
  90685. } );
  90686. this.register( function ( parser ) {
  90687. return new GLTFMaterialsIorExtension( parser );
  90688. } );
  90689. this.register( function ( parser ) {
  90690. return new GLTFMaterialsEmissiveStrengthExtension( parser );
  90691. } );
  90692. this.register( function ( parser ) {
  90693. return new GLTFMaterialsSpecularExtension( parser );
  90694. } );
  90695. this.register( function ( parser ) {
  90696. return new GLTFMaterialsIridescenceExtension( parser );
  90697. } );
  90698. this.register( function ( parser ) {
  90699. return new GLTFLightsExtension( parser );
  90700. } );
  90701. this.register( function ( parser ) {
  90702. return new GLTFMeshoptCompression( parser );
  90703. } );
  90704. this.register( function ( parser ) {
  90705. return new GLTFMeshGpuInstancing( parser );
  90706. } );
  90707. }
  90708. load( url, onLoad, onProgress, onError ) {
  90709. const scope = this;
  90710. let resourcePath;
  90711. if ( this.resourcePath !== '' ) {
  90712. resourcePath = this.resourcePath;
  90713. } else if ( this.path !== '' ) {
  90714. resourcePath = this.path;
  90715. } else {
  90716. resourcePath = LoaderUtils.extractUrlBase( url );
  90717. }
  90718. // Tells the LoadingManager to track an extra item, which resolves after
  90719. // the model is fully loaded. This means the count of items loaded will
  90720. // be incorrect, but ensures manager.onLoad() does not fire early.
  90721. this.manager.itemStart( url );
  90722. const _onError = function ( e ) {
  90723. if ( onError ) {
  90724. onError( e );
  90725. } else {
  90726. console.error( e );
  90727. }
  90728. scope.manager.itemError( url );
  90729. scope.manager.itemEnd( url );
  90730. };
  90731. const loader = new FileLoader( this.manager );
  90732. loader.setPath( this.path );
  90733. loader.setResponseType( 'arraybuffer' );
  90734. loader.setRequestHeader( this.requestHeader );
  90735. loader.setWithCredentials( this.withCredentials );
  90736. loader.load( url, function ( data ) {
  90737. try {
  90738. scope.parse( data, resourcePath, function ( gltf ) {
  90739. onLoad( gltf );
  90740. scope.manager.itemEnd( url );
  90741. }, _onError );
  90742. } catch ( e ) {
  90743. _onError( e );
  90744. }
  90745. }, onProgress, _onError );
  90746. }
  90747. setDRACOLoader( dracoLoader ) {
  90748. this.dracoLoader = dracoLoader;
  90749. return this;
  90750. }
  90751. setDDSLoader() {
  90752. throw new Error(
  90753. 'THREE.GLTFLoader: "MSFT_texture_dds" no longer supported. Please update to "KHR_texture_basisu".'
  90754. );
  90755. }
  90756. setKTX2Loader( ktx2Loader ) {
  90757. this.ktx2Loader = ktx2Loader;
  90758. return this;
  90759. }
  90760. setMeshoptDecoder( meshoptDecoder ) {
  90761. this.meshoptDecoder = meshoptDecoder;
  90762. return this;
  90763. }
  90764. register( callback ) {
  90765. if ( this.pluginCallbacks.indexOf( callback ) === - 1 ) {
  90766. this.pluginCallbacks.push( callback );
  90767. }
  90768. return this;
  90769. }
  90770. unregister( callback ) {
  90771. if ( this.pluginCallbacks.indexOf( callback ) !== - 1 ) {
  90772. this.pluginCallbacks.splice( this.pluginCallbacks.indexOf( callback ), 1 );
  90773. }
  90774. return this;
  90775. }
  90776. parse( data, path, onLoad, onError ) {
  90777. let json;
  90778. const extensions = {};
  90779. const plugins = {};
  90780. if ( typeof data === 'string' ) {
  90781. json = JSON.parse( data );
  90782. } else if ( data instanceof ArrayBuffer ) {
  90783. const magic = LoaderUtils.decodeText( new Uint8Array( data, 0, 4 ) );
  90784. if ( magic === BINARY_EXTENSION_HEADER_MAGIC ) {
  90785. try {
  90786. extensions[ EXTENSIONS.KHR_BINARY_GLTF ] = new GLTFBinaryExtension( data );
  90787. } catch ( error ) {
  90788. if ( onError ) onError( error );
  90789. return;
  90790. }
  90791. json = JSON.parse( extensions[ EXTENSIONS.KHR_BINARY_GLTF ].content );
  90792. } else {
  90793. json = JSON.parse( LoaderUtils.decodeText( new Uint8Array( data ) ) );
  90794. }
  90795. } else {
  90796. json = data;
  90797. }
  90798. if ( json.asset === undefined || json.asset.version[ 0 ] < 2 ) {
  90799. if ( onError ) onError( new Error( 'THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.' ) );
  90800. return;
  90801. }
  90802. const parser = new GLTFParser( json, {
  90803. path: path || this.resourcePath || '',
  90804. crossOrigin: this.crossOrigin,
  90805. requestHeader: this.requestHeader,
  90806. manager: this.manager,
  90807. ktx2Loader: this.ktx2Loader,
  90808. meshoptDecoder: this.meshoptDecoder
  90809. } );
  90810. parser.fileLoader.setRequestHeader( this.requestHeader );
  90811. for ( let i = 0; i < this.pluginCallbacks.length; i ++ ) {
  90812. const plugin = this.pluginCallbacks[ i ]( parser );
  90813. plugins[ plugin.name ] = plugin;
  90814. // Workaround to avoid determining as unknown extension
  90815. // in addUnknownExtensionsToUserData().
  90816. // Remove this workaround if we move all the existing
  90817. // extension handlers to plugin system
  90818. extensions[ plugin.name ] = true;
  90819. }
  90820. if ( json.extensionsUsed ) {
  90821. for ( let i = 0; i < json.extensionsUsed.length; ++ i ) {
  90822. const extensionName = json.extensionsUsed[ i ];
  90823. const extensionsRequired = json.extensionsRequired || [];
  90824. switch ( extensionName ) {
  90825. case EXTENSIONS.KHR_MATERIALS_UNLIT:
  90826. extensions[ extensionName ] = new GLTFMaterialsUnlitExtension();
  90827. break;
  90828. case EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS:
  90829. extensions[ extensionName ] = new GLTFMaterialsPbrSpecularGlossinessExtension();
  90830. break;
  90831. case EXTENSIONS.KHR_DRACO_MESH_COMPRESSION:
  90832. extensions[ extensionName ] = new GLTFDracoMeshCompressionExtension( json, this.dracoLoader );
  90833. break;
  90834. case EXTENSIONS.KHR_TEXTURE_TRANSFORM:
  90835. extensions[ extensionName ] = new GLTFTextureTransformExtension();
  90836. break;
  90837. case EXTENSIONS.KHR_MESH_QUANTIZATION:
  90838. extensions[ extensionName ] = new GLTFMeshQuantizationExtension();
  90839. break;
  90840. default:
  90841. if ( extensionsRequired.indexOf( extensionName ) >= 0 && plugins[ extensionName ] === undefined ) {
  90842. if(!unknownExtensions[extensionName]){
  90843. console.warn( 'GLTFLoader: Unknown extension "' + extensionName + '".' ,'使用默认的KHR_materials_unlit材质' );
  90844. unknownExtensions[extensionName] = 1;
  90845. }
  90846. //xzw add: 默认
  90847. json.extensionsRequired = 'KHR_materials_unlit';
  90848. json.materials = [{
  90849. extensions: {KHR_materials_unlit: {}},
  90850. pbrMetallicRoughness:{
  90851. baseColorFactor:[1, 1, 1, 1],
  90852. baseColorTexture: {index: 0, texCoord: 0},
  90853. metallicFactor: 0,
  90854. roughnessFactor: 0.5,
  90855. }
  90856. }];
  90857. extensions[ json.extensionsRequired ] = new GLTFMaterialsUnlitExtension();
  90858. }
  90859. /*
  90860. 如原先:
  90861. json.materials = KHR_techniques_webgl:{
  90862. technique: 0,
  90863. values:{u_diffuse:{index: 0,texCoord: 0}}
  90864. }
  90865. */
  90866. }
  90867. }
  90868. }
  90869. parser.setExtensions( extensions );
  90870. parser.setPlugins( plugins );
  90871. parser.parse( onLoad, onError );
  90872. }
  90873. parseAsync( data, path ) {
  90874. const scope = this;
  90875. return new Promise( function ( resolve, reject ) {
  90876. scope.parse( data, path, resolve, reject );
  90877. } );
  90878. }
  90879. }
  90880. /* GLTFREGISTRY */
  90881. function GLTFRegistry() {
  90882. let objects = {};
  90883. return {
  90884. get: function ( key ) {
  90885. return objects[ key ];
  90886. },
  90887. add: function ( key, object ) {
  90888. objects[ key ] = object;
  90889. },
  90890. remove: function ( key ) {
  90891. delete objects[ key ];
  90892. },
  90893. removeAll: function () {
  90894. objects = {};
  90895. }
  90896. };
  90897. }
  90898. /*********************************/
  90899. /********** EXTENSIONS ***********/
  90900. /*********************************/
  90901. const EXTENSIONS = {
  90902. KHR_BINARY_GLTF: 'KHR_binary_glTF',
  90903. KHR_DRACO_MESH_COMPRESSION: 'KHR_draco_mesh_compression',
  90904. KHR_LIGHTS_PUNCTUAL: 'KHR_lights_punctual',
  90905. KHR_MATERIALS_CLEARCOAT: 'KHR_materials_clearcoat',
  90906. KHR_MATERIALS_IOR: 'KHR_materials_ior',
  90907. KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS: 'KHR_materials_pbrSpecularGlossiness',
  90908. KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
  90909. KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
  90910. KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
  90911. KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
  90912. KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
  90913. KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
  90914. KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
  90915. KHR_TEXTURE_TRANSFORM: 'KHR_texture_transform',
  90916. KHR_MESH_QUANTIZATION: 'KHR_mesh_quantization',
  90917. KHR_MATERIALS_EMISSIVE_STRENGTH: 'KHR_materials_emissive_strength',
  90918. EXT_TEXTURE_WEBP: 'EXT_texture_webp',
  90919. EXT_MESHOPT_COMPRESSION: 'EXT_meshopt_compression',
  90920. EXT_MESH_GPU_INSTANCING: 'EXT_mesh_gpu_instancing'
  90921. };
  90922. /**
  90923. * Punctual Lights Extension
  90924. *
  90925. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_lights_punctual
  90926. */
  90927. class GLTFLightsExtension {
  90928. constructor( parser ) {
  90929. this.parser = parser;
  90930. this.name = EXTENSIONS.KHR_LIGHTS_PUNCTUAL;
  90931. // Object3D instance caches
  90932. this.cache = { refs: {}, uses: {} };
  90933. }
  90934. _markDefs() {
  90935. const parser = this.parser;
  90936. const nodeDefs = this.parser.json.nodes || [];
  90937. for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
  90938. const nodeDef = nodeDefs[ nodeIndex ];
  90939. if ( nodeDef.extensions
  90940. && nodeDef.extensions[ this.name ]
  90941. && nodeDef.extensions[ this.name ].light !== undefined ) {
  90942. parser._addNodeRef( this.cache, nodeDef.extensions[ this.name ].light );
  90943. }
  90944. }
  90945. }
  90946. _loadLight( lightIndex ) {
  90947. const parser = this.parser;
  90948. const cacheKey = 'light:' + lightIndex;
  90949. let dependency = parser.cache.get( cacheKey );
  90950. if ( dependency ) return dependency;
  90951. const json = parser.json;
  90952. const extensions = ( json.extensions && json.extensions[ this.name ] ) || {};
  90953. const lightDefs = extensions.lights || [];
  90954. const lightDef = lightDefs[ lightIndex ];
  90955. let lightNode;
  90956. const color = new Color( 0xffffff );
  90957. if ( lightDef.color !== undefined ) color.fromArray( lightDef.color );
  90958. const range = lightDef.range !== undefined ? lightDef.range : 0;
  90959. switch ( lightDef.type ) {
  90960. case 'directional':
  90961. lightNode = new DirectionalLight( color );
  90962. lightNode.target.position.set( 0, 0, - 1 );
  90963. lightNode.add( lightNode.target );
  90964. break;
  90965. case 'point':
  90966. lightNode = new PointLight( color );
  90967. lightNode.distance = range;
  90968. break;
  90969. case 'spot':
  90970. lightNode = new SpotLight( color );
  90971. lightNode.distance = range;
  90972. // Handle spotlight properties.
  90973. lightDef.spot = lightDef.spot || {};
  90974. lightDef.spot.innerConeAngle = lightDef.spot.innerConeAngle !== undefined ? lightDef.spot.innerConeAngle : 0;
  90975. lightDef.spot.outerConeAngle = lightDef.spot.outerConeAngle !== undefined ? lightDef.spot.outerConeAngle : Math.PI / 4.0;
  90976. lightNode.angle = lightDef.spot.outerConeAngle;
  90977. lightNode.penumbra = 1.0 - lightDef.spot.innerConeAngle / lightDef.spot.outerConeAngle;
  90978. lightNode.target.position.set( 0, 0, - 1 );
  90979. lightNode.add( lightNode.target );
  90980. break;
  90981. default:
  90982. throw new Error( 'THREE.GLTFLoader: Unexpected light type: ' + lightDef.type );
  90983. }
  90984. // Some lights (e.g. spot) default to a position other than the origin. Reset the position
  90985. // here, because node-level parsing will only override position if explicitly specified.
  90986. lightNode.position.set( 0, 0, 0 );
  90987. lightNode.decay = 2;
  90988. if ( lightDef.intensity !== undefined ) lightNode.intensity = lightDef.intensity;
  90989. lightNode.name = parser.createUniqueName( lightDef.name || ( 'light_' + lightIndex ) );
  90990. dependency = Promise.resolve( lightNode );
  90991. parser.cache.add( cacheKey, dependency );
  90992. return dependency;
  90993. }
  90994. createNodeAttachment( nodeIndex ) {
  90995. const self = this;
  90996. const parser = this.parser;
  90997. const json = parser.json;
  90998. const nodeDef = json.nodes[ nodeIndex ];
  90999. const lightDef = ( nodeDef.extensions && nodeDef.extensions[ this.name ] ) || {};
  91000. const lightIndex = lightDef.light;
  91001. if ( lightIndex === undefined ) return null;
  91002. return this._loadLight( lightIndex ).then( function ( light ) {
  91003. return parser._getNodeRef( self.cache, lightIndex, light );
  91004. } );
  91005. }
  91006. }
  91007. /**
  91008. * Unlit Materials Extension
  91009. *
  91010. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_unlit
  91011. */
  91012. class GLTFMaterialsUnlitExtension {
  91013. constructor() {
  91014. this.name = EXTENSIONS.KHR_MATERIALS_UNLIT;
  91015. }
  91016. getMaterialType() {
  91017. return MeshBasicMaterial;
  91018. }
  91019. extendParams( materialParams, materialDef, parser ) {
  91020. const pending = [];
  91021. materialParams.color = new Color( 1.0, 1.0, 1.0 );
  91022. materialParams.opacity = 1.0;
  91023. const metallicRoughness = materialDef.pbrMetallicRoughness;
  91024. if ( metallicRoughness ) {
  91025. if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
  91026. const array = metallicRoughness.baseColorFactor;
  91027. materialParams.color.fromArray( array );
  91028. materialParams.opacity = array[ 3 ];
  91029. }
  91030. if ( metallicRoughness.baseColorTexture !== undefined ) {
  91031. pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, sRGBEncoding ) );
  91032. }
  91033. }
  91034. return Promise.all( pending );
  91035. }
  91036. }
  91037. /**
  91038. * Materials Emissive Strength Extension
  91039. *
  91040. * Specification: https://github.com/KhronosGroup/glTF/blob/5768b3ce0ef32bc39cdf1bef10b948586635ead3/extensions/2.0/Khronos/KHR_materials_emissive_strength/README.md
  91041. */
  91042. class GLTFMaterialsEmissiveStrengthExtension {
  91043. constructor( parser ) {
  91044. this.parser = parser;
  91045. this.name = EXTENSIONS.KHR_MATERIALS_EMISSIVE_STRENGTH;
  91046. }
  91047. extendMaterialParams( materialIndex, materialParams ) {
  91048. const parser = this.parser;
  91049. const materialDef = parser.json.materials[ materialIndex ] || parser.json.materials; //xzw change
  91050. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91051. return Promise.resolve();
  91052. }
  91053. const emissiveStrength = materialDef.extensions[ this.name ].emissiveStrength;
  91054. if ( emissiveStrength !== undefined ) {
  91055. materialParams.emissiveIntensity = emissiveStrength;
  91056. }
  91057. return Promise.resolve();
  91058. }
  91059. }
  91060. /**
  91061. * Clearcoat Materials Extension
  91062. *
  91063. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_clearcoat
  91064. */
  91065. class GLTFMaterialsClearcoatExtension {
  91066. constructor( parser ) {
  91067. this.parser = parser;
  91068. this.name = EXTENSIONS.KHR_MATERIALS_CLEARCOAT;
  91069. }
  91070. getMaterialType( materialIndex ) {
  91071. const parser = this.parser;
  91072. const materialDef = parser.json.materials[ materialIndex ] || parser.json.materials;
  91073. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91074. return MeshPhysicalMaterial;
  91075. }
  91076. extendMaterialParams( materialIndex, materialParams ) {
  91077. const parser = this.parser;
  91078. const materialDef = parser.json.materials[ materialIndex ]; //曾因这里报错加了一句 || parser.json.materials; 但是加载的图会先变白
  91079. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91080. return Promise.resolve();
  91081. }
  91082. const pending = [];
  91083. const extension = materialDef.extensions[ this.name ];
  91084. if ( extension.clearcoatFactor !== undefined ) {
  91085. materialParams.clearcoat = extension.clearcoatFactor;
  91086. }
  91087. if ( extension.clearcoatTexture !== undefined ) {
  91088. pending.push( parser.assignTexture( materialParams, 'clearcoatMap', extension.clearcoatTexture ) );
  91089. }
  91090. if ( extension.clearcoatRoughnessFactor !== undefined ) {
  91091. materialParams.clearcoatRoughness = extension.clearcoatRoughnessFactor;
  91092. }
  91093. if ( extension.clearcoatRoughnessTexture !== undefined ) {
  91094. pending.push( parser.assignTexture( materialParams, 'clearcoatRoughnessMap', extension.clearcoatRoughnessTexture ) );
  91095. }
  91096. if ( extension.clearcoatNormalTexture !== undefined ) {
  91097. pending.push( parser.assignTexture( materialParams, 'clearcoatNormalMap', extension.clearcoatNormalTexture ) );
  91098. if ( extension.clearcoatNormalTexture.scale !== undefined ) {
  91099. const scale = extension.clearcoatNormalTexture.scale;
  91100. materialParams.clearcoatNormalScale = new Vector2( scale, scale );
  91101. }
  91102. }
  91103. return Promise.all( pending );
  91104. }
  91105. }
  91106. /**
  91107. * Iridescence Materials Extension
  91108. *
  91109. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
  91110. */
  91111. class GLTFMaterialsIridescenceExtension {
  91112. constructor( parser ) {
  91113. this.parser = parser;
  91114. this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
  91115. }
  91116. getMaterialType( materialIndex ) {
  91117. const parser = this.parser;
  91118. const materialDef = parser.json.materials[ materialIndex ];
  91119. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91120. return MeshPhysicalMaterial;
  91121. }
  91122. extendMaterialParams( materialIndex, materialParams ) {
  91123. const parser = this.parser;
  91124. const materialDef = parser.json.materials[ materialIndex ];
  91125. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91126. return Promise.resolve();
  91127. }
  91128. const pending = [];
  91129. const extension = materialDef.extensions[ this.name ];
  91130. if ( extension.iridescenceFactor !== undefined ) {
  91131. materialParams.iridescence = extension.iridescenceFactor;
  91132. }
  91133. if ( extension.iridescenceTexture !== undefined ) {
  91134. pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
  91135. }
  91136. if ( extension.iridescenceIor !== undefined ) {
  91137. materialParams.iridescenceIOR = extension.iridescenceIor;
  91138. }
  91139. if ( materialParams.iridescenceThicknessRange === undefined ) {
  91140. materialParams.iridescenceThicknessRange = [ 100, 400 ];
  91141. }
  91142. if ( extension.iridescenceThicknessMinimum !== undefined ) {
  91143. materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
  91144. }
  91145. if ( extension.iridescenceThicknessMaximum !== undefined ) {
  91146. materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
  91147. }
  91148. if ( extension.iridescenceThicknessTexture !== undefined ) {
  91149. pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
  91150. }
  91151. return Promise.all( pending );
  91152. }
  91153. }
  91154. /**
  91155. * Sheen Materials Extension
  91156. *
  91157. * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Khronos/KHR_materials_sheen
  91158. */
  91159. class GLTFMaterialsSheenExtension {
  91160. constructor( parser ) {
  91161. this.parser = parser;
  91162. this.name = EXTENSIONS.KHR_MATERIALS_SHEEN;
  91163. }
  91164. getMaterialType( materialIndex ) {
  91165. const parser = this.parser;
  91166. const materialDef = parser.json.materials[ materialIndex ];
  91167. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91168. return MeshPhysicalMaterial;
  91169. }
  91170. extendMaterialParams( materialIndex, materialParams ) {
  91171. const parser = this.parser;
  91172. const materialDef = parser.json.materials[ materialIndex ];
  91173. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91174. return Promise.resolve();
  91175. }
  91176. const pending = [];
  91177. materialParams.sheenColor = new Color( 0, 0, 0 );
  91178. materialParams.sheenRoughness = 0;
  91179. materialParams.sheen = 1;
  91180. const extension = materialDef.extensions[ this.name ];
  91181. if ( extension.sheenColorFactor !== undefined ) {
  91182. materialParams.sheenColor.fromArray( extension.sheenColorFactor );
  91183. }
  91184. if ( extension.sheenRoughnessFactor !== undefined ) {
  91185. materialParams.sheenRoughness = extension.sheenRoughnessFactor;
  91186. }
  91187. if ( extension.sheenColorTexture !== undefined ) {
  91188. pending.push( parser.assignTexture( materialParams, 'sheenColorMap', extension.sheenColorTexture, sRGBEncoding ) );
  91189. }
  91190. if ( extension.sheenRoughnessTexture !== undefined ) {
  91191. pending.push( parser.assignTexture( materialParams, 'sheenRoughnessMap', extension.sheenRoughnessTexture ) );
  91192. }
  91193. return Promise.all( pending );
  91194. }
  91195. }
  91196. /**
  91197. * Transmission Materials Extension
  91198. *
  91199. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_transmission
  91200. * Draft: https://github.com/KhronosGroup/glTF/pull/1698
  91201. */
  91202. class GLTFMaterialsTransmissionExtension {
  91203. constructor( parser ) {
  91204. this.parser = parser;
  91205. this.name = EXTENSIONS.KHR_MATERIALS_TRANSMISSION;
  91206. }
  91207. getMaterialType( materialIndex ) {
  91208. const parser = this.parser;
  91209. const materialDef = parser.json.materials[ materialIndex ];
  91210. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91211. return MeshPhysicalMaterial;
  91212. }
  91213. extendMaterialParams( materialIndex, materialParams ) {
  91214. const parser = this.parser;
  91215. const materialDef = parser.json.materials[ materialIndex ];
  91216. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91217. return Promise.resolve();
  91218. }
  91219. const pending = [];
  91220. const extension = materialDef.extensions[ this.name ];
  91221. if ( extension.transmissionFactor !== undefined ) {
  91222. materialParams.transmission = extension.transmissionFactor;
  91223. }
  91224. if ( extension.transmissionTexture !== undefined ) {
  91225. pending.push( parser.assignTexture( materialParams, 'transmissionMap', extension.transmissionTexture ) );
  91226. }
  91227. return Promise.all( pending );
  91228. }
  91229. }
  91230. /**
  91231. * Materials Volume Extension
  91232. *
  91233. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_volume
  91234. */
  91235. class GLTFMaterialsVolumeExtension {
  91236. constructor( parser ) {
  91237. this.parser = parser;
  91238. this.name = EXTENSIONS.KHR_MATERIALS_VOLUME;
  91239. }
  91240. getMaterialType( materialIndex ) {
  91241. const parser = this.parser;
  91242. const materialDef = parser.json.materials[ materialIndex ];
  91243. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91244. return MeshPhysicalMaterial;
  91245. }
  91246. extendMaterialParams( materialIndex, materialParams ) {
  91247. const parser = this.parser;
  91248. const materialDef = parser.json.materials[ materialIndex ];
  91249. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91250. return Promise.resolve();
  91251. }
  91252. const pending = [];
  91253. const extension = materialDef.extensions[ this.name ];
  91254. materialParams.thickness = extension.thicknessFactor !== undefined ? extension.thicknessFactor : 0;
  91255. if ( extension.thicknessTexture !== undefined ) {
  91256. pending.push( parser.assignTexture( materialParams, 'thicknessMap', extension.thicknessTexture ) );
  91257. }
  91258. materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
  91259. const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
  91260. materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
  91261. return Promise.all( pending );
  91262. }
  91263. }
  91264. /**
  91265. * Materials ior Extension
  91266. *
  91267. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_ior
  91268. */
  91269. class GLTFMaterialsIorExtension {
  91270. constructor( parser ) {
  91271. this.parser = parser;
  91272. this.name = EXTENSIONS.KHR_MATERIALS_IOR;
  91273. }
  91274. getMaterialType( materialIndex ) {
  91275. const parser = this.parser;
  91276. const materialDef = parser.json.materials[ materialIndex ];
  91277. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91278. return MeshPhysicalMaterial;
  91279. }
  91280. extendMaterialParams( materialIndex, materialParams ) {
  91281. const parser = this.parser;
  91282. const materialDef = parser.json.materials[ materialIndex ];
  91283. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91284. return Promise.resolve();
  91285. }
  91286. const extension = materialDef.extensions[ this.name ];
  91287. materialParams.ior = extension.ior !== undefined ? extension.ior : 1.5;
  91288. return Promise.resolve();
  91289. }
  91290. }
  91291. /**
  91292. * Materials specular Extension
  91293. *
  91294. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_specular
  91295. */
  91296. class GLTFMaterialsSpecularExtension {
  91297. constructor( parser ) {
  91298. this.parser = parser;
  91299. this.name = EXTENSIONS.KHR_MATERIALS_SPECULAR;
  91300. }
  91301. getMaterialType( materialIndex ) {
  91302. const parser = this.parser;
  91303. const materialDef = parser.json.materials[ materialIndex ];
  91304. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
  91305. return MeshPhysicalMaterial;
  91306. }
  91307. extendMaterialParams( materialIndex, materialParams ) {
  91308. const parser = this.parser;
  91309. const materialDef = parser.json.materials[ materialIndex ];
  91310. if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
  91311. return Promise.resolve();
  91312. }
  91313. const pending = [];
  91314. const extension = materialDef.extensions[ this.name ];
  91315. materialParams.specularIntensity = extension.specularFactor !== undefined ? extension.specularFactor : 1.0;
  91316. if ( extension.specularTexture !== undefined ) {
  91317. pending.push( parser.assignTexture( materialParams, 'specularIntensityMap', extension.specularTexture ) );
  91318. }
  91319. const colorArray = extension.specularColorFactor || [ 1, 1, 1 ];
  91320. materialParams.specularColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
  91321. if ( extension.specularColorTexture !== undefined ) {
  91322. pending.push( parser.assignTexture( materialParams, 'specularColorMap', extension.specularColorTexture, sRGBEncoding ) );
  91323. }
  91324. return Promise.all( pending );
  91325. }
  91326. }
  91327. /**
  91328. * BasisU Texture Extension
  91329. *
  91330. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_basisu
  91331. */
  91332. class GLTFTextureBasisUExtension {
  91333. constructor( parser ) {
  91334. this.parser = parser;
  91335. this.name = EXTENSIONS.KHR_TEXTURE_BASISU;
  91336. }
  91337. loadTexture( textureIndex ) {
  91338. const parser = this.parser;
  91339. const json = parser.json;
  91340. const textureDef = json.textures[ textureIndex ];
  91341. if ( ! textureDef.extensions || ! textureDef.extensions[ this.name ] ) {
  91342. return null;
  91343. }
  91344. const extension = textureDef.extensions[ this.name ];
  91345. const loader = parser.options.ktx2Loader;
  91346. if ( ! loader ) {
  91347. if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
  91348. throw new Error( 'THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures' );
  91349. } else {
  91350. // Assumes that the extension is optional and that a fallback texture is present
  91351. return null;
  91352. }
  91353. }
  91354. return parser.loadTextureImage( textureIndex, extension.source, loader );
  91355. }
  91356. }
  91357. /**
  91358. * WebP Texture Extension
  91359. *
  91360. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_texture_webp
  91361. */
  91362. class GLTFTextureWebPExtension {
  91363. constructor( parser ) {
  91364. this.parser = parser;
  91365. this.name = EXTENSIONS.EXT_TEXTURE_WEBP;
  91366. this.isSupported = null;
  91367. }
  91368. loadTexture( textureIndex ) {
  91369. const name = this.name;
  91370. const parser = this.parser;
  91371. const json = parser.json;
  91372. const textureDef = json.textures[ textureIndex ];
  91373. if ( ! textureDef.extensions || ! textureDef.extensions[ name ] ) {
  91374. return null;
  91375. }
  91376. const extension = textureDef.extensions[ name ];
  91377. const source = json.images[ extension.source ];
  91378. let loader = parser.textureLoader;
  91379. if ( source.uri ) {
  91380. const handler = parser.options.manager.getHandler( source.uri );
  91381. if ( handler !== null ) loader = handler;
  91382. }
  91383. return this.detectSupport().then( function ( isSupported ) {
  91384. if ( isSupported ) return parser.loadTextureImage( textureIndex, extension.source, loader );
  91385. if ( json.extensionsRequired && json.extensionsRequired.indexOf( name ) >= 0 ) {
  91386. throw new Error( 'THREE.GLTFLoader: WebP required by asset but unsupported.' );
  91387. }
  91388. // Fall back to PNG or JPEG.
  91389. return parser.loadTexture( textureIndex );
  91390. } );
  91391. }
  91392. detectSupport() {
  91393. if ( ! this.isSupported ) {
  91394. this.isSupported = new Promise( function ( resolve ) {
  91395. const image = new Image();
  91396. // Lossy test image. Support for lossy images doesn't guarantee support for all
  91397. // WebP images, unfortunately.
  91398. image.src = 'data:image/webp;base64,UklGRiIAAABXRUJQVlA4IBYAAAAwAQCdASoBAAEADsD+JaQAA3AAAAAA';
  91399. image.onload = image.onerror = function () {
  91400. resolve( image.height === 1 );
  91401. };
  91402. } );
  91403. }
  91404. return this.isSupported;
  91405. }
  91406. }
  91407. /**
  91408. * meshopt BufferView Compression Extension
  91409. *
  91410. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_meshopt_compression
  91411. */
  91412. class GLTFMeshoptCompression {
  91413. constructor( parser ) {
  91414. this.name = EXTENSIONS.EXT_MESHOPT_COMPRESSION;
  91415. this.parser = parser;
  91416. }
  91417. loadBufferView( index ) {
  91418. const json = this.parser.json;
  91419. const bufferView = json.bufferViews[ index ];
  91420. if ( bufferView.extensions && bufferView.extensions[ this.name ] ) {
  91421. const extensionDef = bufferView.extensions[ this.name ];
  91422. const buffer = this.parser.getDependency( 'buffer', extensionDef.buffer );
  91423. const decoder = this.parser.options.meshoptDecoder;
  91424. if ( ! decoder || ! decoder.supported ) {
  91425. if ( json.extensionsRequired && json.extensionsRequired.indexOf( this.name ) >= 0 ) {
  91426. throw new Error( 'THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files' );
  91427. } else {
  91428. // Assumes that the extension is optional and that fallback buffer data is present
  91429. return null;
  91430. }
  91431. }
  91432. return buffer.then( function ( res ) {
  91433. const byteOffset = extensionDef.byteOffset || 0;
  91434. const byteLength = extensionDef.byteLength || 0;
  91435. const count = extensionDef.count;
  91436. const stride = extensionDef.byteStride;
  91437. const source = new Uint8Array( res, byteOffset, byteLength );
  91438. if ( decoder.decodeGltfBufferAsync ) {
  91439. return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
  91440. return res.buffer;
  91441. } );
  91442. } else {
  91443. // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync
  91444. return decoder.ready.then( function () {
  91445. const result = new ArrayBuffer( count * stride );
  91446. decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
  91447. return result;
  91448. } );
  91449. }
  91450. } );
  91451. } else {
  91452. return null;
  91453. }
  91454. }
  91455. }
  91456. /**
  91457. * GPU Instancing Extension
  91458. *
  91459. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Vendor/EXT_mesh_gpu_instancing
  91460. *
  91461. */
  91462. class GLTFMeshGpuInstancing {
  91463. constructor( parser ) {
  91464. this.name = EXTENSIONS.EXT_MESH_GPU_INSTANCING;
  91465. this.parser = parser;
  91466. }
  91467. createNodeMesh( nodeIndex ) {
  91468. const json = this.parser.json;
  91469. const nodeDef = json.nodes[ nodeIndex ];
  91470. if ( ! nodeDef.extensions || ! nodeDef.extensions[ this.name ] ||
  91471. nodeDef.mesh === undefined ) {
  91472. return null;
  91473. }
  91474. const meshDef = json.meshes[ nodeDef.mesh ];
  91475. // No Points or Lines + Instancing support yet
  91476. for ( const primitive of meshDef.primitives ) {
  91477. if ( primitive.mode !== WEBGL_CONSTANTS.TRIANGLES &&
  91478. primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_STRIP &&
  91479. primitive.mode !== WEBGL_CONSTANTS.TRIANGLE_FAN &&
  91480. primitive.mode !== undefined ) {
  91481. return null;
  91482. }
  91483. }
  91484. const extensionDef = nodeDef.extensions[ this.name ];
  91485. const attributesDef = extensionDef.attributes;
  91486. // @TODO: Can we support InstancedMesh + SkinnedMesh?
  91487. const pending = [];
  91488. const attributes = {};
  91489. for ( const key in attributesDef ) {
  91490. pending.push( this.parser.getDependency( 'accessor', attributesDef[ key ] ).then( accessor => {
  91491. attributes[ key ] = accessor;
  91492. return attributes[ key ];
  91493. } ) );
  91494. }
  91495. if ( pending.length < 1 ) {
  91496. return null;
  91497. }
  91498. pending.push( this.parser.createNodeMesh( nodeIndex ) );
  91499. return Promise.all( pending ).then( results => {
  91500. const nodeObject = results.pop();
  91501. const meshes = nodeObject.isGroup ? nodeObject.children : [ nodeObject ];
  91502. const count = results[ 0 ].count; // All attribute counts should be same
  91503. const instancedMeshes = [];
  91504. for ( const mesh of meshes ) {
  91505. // Temporal variables
  91506. const m = new Matrix4();
  91507. const p = new Vector3();
  91508. const q = new Quaternion();
  91509. const s = new Vector3( 1, 1, 1 );
  91510. const instancedMesh = new InstancedMesh( mesh.geometry, mesh.material, count );
  91511. for ( let i = 0; i < count; i ++ ) {
  91512. if ( attributes.TRANSLATION ) {
  91513. p.fromBufferAttribute( attributes.TRANSLATION, i );
  91514. }
  91515. if ( attributes.ROTATION ) {
  91516. q.fromBufferAttribute( attributes.ROTATION, i );
  91517. }
  91518. if ( attributes.SCALE ) {
  91519. s.fromBufferAttribute( attributes.SCALE, i );
  91520. }
  91521. instancedMesh.setMatrixAt( i, m.compose( p, q, s ) );
  91522. }
  91523. // Add instance attributes to the geometry, excluding TRS.
  91524. for ( const attributeName in attributes ) {
  91525. if ( attributeName !== 'TRANSLATION' &&
  91526. attributeName !== 'ROTATION' &&
  91527. attributeName !== 'SCALE' ) {
  91528. mesh.geometry.setAttribute( attributeName, attributes[ attributeName ] );
  91529. }
  91530. }
  91531. // Just in case
  91532. Object3D.prototype.copy.call( instancedMesh, mesh );
  91533. // https://github.com/mrdoob/three.js/issues/18334
  91534. instancedMesh.frustumCulled = false;
  91535. this.parser.assignFinalMaterial( instancedMesh );
  91536. instancedMeshes.push( instancedMesh );
  91537. }
  91538. if ( nodeObject.isGroup ) {
  91539. nodeObject.clear();
  91540. nodeObject.add( ... instancedMeshes );
  91541. return nodeObject;
  91542. }
  91543. return instancedMeshes[ 0 ];
  91544. } );
  91545. }
  91546. }
  91547. /* BINARY EXTENSION */
  91548. const BINARY_EXTENSION_HEADER_MAGIC = 'glTF';
  91549. const BINARY_EXTENSION_HEADER_LENGTH = 12;
  91550. const BINARY_EXTENSION_CHUNK_TYPES = { JSON: 0x4E4F534A, BIN: 0x004E4942 };
  91551. class GLTFBinaryExtension {
  91552. constructor( data ) {
  91553. this.name = EXTENSIONS.KHR_BINARY_GLTF;
  91554. this.content = null;
  91555. this.body = null;
  91556. const headerView = new DataView( data, 0, BINARY_EXTENSION_HEADER_LENGTH );
  91557. this.header = {
  91558. magic: LoaderUtils.decodeText( new Uint8Array( data.slice( 0, 4 ) ) ),
  91559. version: headerView.getUint32( 4, true ),
  91560. length: headerView.getUint32( 8, true )
  91561. };
  91562. if ( this.header.magic !== BINARY_EXTENSION_HEADER_MAGIC ) {
  91563. throw new Error( 'THREE.GLTFLoader: Unsupported glTF-Binary header.' );
  91564. } else if ( this.header.version < 2.0 ) {
  91565. throw new Error( 'THREE.GLTFLoader: Legacy binary file detected.' );
  91566. }
  91567. const chunkContentsLength = this.header.length - BINARY_EXTENSION_HEADER_LENGTH;
  91568. const chunkView = new DataView( data, BINARY_EXTENSION_HEADER_LENGTH );
  91569. let chunkIndex = 0;
  91570. while ( chunkIndex < chunkContentsLength ) {
  91571. const chunkLength = chunkView.getUint32( chunkIndex, true );
  91572. chunkIndex += 4;
  91573. const chunkType = chunkView.getUint32( chunkIndex, true );
  91574. chunkIndex += 4;
  91575. if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.JSON ) {
  91576. const contentArray = new Uint8Array( data, BINARY_EXTENSION_HEADER_LENGTH + chunkIndex, chunkLength );
  91577. this.content = LoaderUtils.decodeText( contentArray );
  91578. } else if ( chunkType === BINARY_EXTENSION_CHUNK_TYPES.BIN ) {
  91579. const byteOffset = BINARY_EXTENSION_HEADER_LENGTH + chunkIndex;
  91580. this.body = data.slice( byteOffset, byteOffset + chunkLength );
  91581. }
  91582. // Clients must ignore chunks with unknown types.
  91583. chunkIndex += chunkLength;
  91584. }
  91585. if ( this.content === null ) {
  91586. throw new Error( 'THREE.GLTFLoader: JSON content not found.' );
  91587. }
  91588. }
  91589. }
  91590. /**
  91591. * DRACO Mesh Compression Extension
  91592. *
  91593. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_draco_mesh_compression
  91594. */
  91595. class GLTFDracoMeshCompressionExtension {
  91596. constructor( json, dracoLoader ) {
  91597. if ( ! dracoLoader ) {
  91598. throw new Error( 'THREE.GLTFLoader: No DRACOLoader instance provided.' );
  91599. }
  91600. this.name = EXTENSIONS.KHR_DRACO_MESH_COMPRESSION;
  91601. this.json = json;
  91602. this.dracoLoader = dracoLoader;
  91603. this.dracoLoader.preload();
  91604. }
  91605. decodePrimitive( primitive, parser ) {
  91606. const json = this.json;
  91607. const dracoLoader = this.dracoLoader;
  91608. const bufferViewIndex = primitive.extensions[ this.name ].bufferView;
  91609. const gltfAttributeMap = primitive.extensions[ this.name ].attributes;
  91610. const threeAttributeMap = {};
  91611. const attributeNormalizedMap = {};
  91612. const attributeTypeMap = {};
  91613. for ( const attributeName in gltfAttributeMap ) {
  91614. const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
  91615. threeAttributeMap[ threeAttributeName ] = gltfAttributeMap[ attributeName ];
  91616. }
  91617. for ( const attributeName in primitive.attributes ) {
  91618. const threeAttributeName = ATTRIBUTES[ attributeName ] || attributeName.toLowerCase();
  91619. if ( gltfAttributeMap[ attributeName ] !== undefined ) {
  91620. const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
  91621. const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
  91622. attributeTypeMap[ threeAttributeName ] = componentType.name;
  91623. attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
  91624. }
  91625. }
  91626. return parser.getDependency( 'bufferView', bufferViewIndex ).then( function ( bufferView ) {
  91627. return new Promise( function ( resolve ) {
  91628. dracoLoader.decodeDracoFile( bufferView, function ( geometry ) {
  91629. for ( const attributeName in geometry.attributes ) {
  91630. const attribute = geometry.attributes[ attributeName ];
  91631. const normalized = attributeNormalizedMap[ attributeName ];
  91632. if ( normalized !== undefined ) attribute.normalized = normalized;
  91633. }
  91634. resolve( geometry );
  91635. }, threeAttributeMap, attributeTypeMap );
  91636. } );
  91637. } );
  91638. }
  91639. }
  91640. /**
  91641. * Texture Transform Extension
  91642. *
  91643. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_texture_transform
  91644. */
  91645. class GLTFTextureTransformExtension {
  91646. constructor() {
  91647. this.name = EXTENSIONS.KHR_TEXTURE_TRANSFORM;
  91648. }
  91649. extendTexture( texture, transform ) {
  91650. if ( transform.texCoord !== undefined ) {
  91651. console.warn( 'THREE.GLTFLoader: Custom UV sets in "' + this.name + '" extension not yet supported.' );
  91652. }
  91653. if ( transform.offset === undefined && transform.rotation === undefined && transform.scale === undefined ) {
  91654. // See https://github.com/mrdoob/three.js/issues/21819.
  91655. return texture;
  91656. }
  91657. texture = texture.clone();
  91658. if ( transform.offset !== undefined ) {
  91659. texture.offset.fromArray( transform.offset );
  91660. }
  91661. if ( transform.rotation !== undefined ) {
  91662. texture.rotation = transform.rotation;
  91663. }
  91664. if ( transform.scale !== undefined ) {
  91665. texture.repeat.fromArray( transform.scale );
  91666. }
  91667. texture.needsUpdate = true;
  91668. return texture;
  91669. }
  91670. }
  91671. /**
  91672. * Specular-Glossiness Extension
  91673. *
  91674. * Specification: https://github.com/KhronosGroup/glTF/tree/main/extensions/2.0/Archived/KHR_materials_pbrSpecularGlossiness
  91675. */
  91676. /**
  91677. * A sub class of StandardMaterial with some of the functionality
  91678. * changed via the `onBeforeCompile` callback
  91679. * @pailhead
  91680. */
  91681. class GLTFMeshStandardSGMaterial extends MeshStandardMaterial {
  91682. constructor( params ) {
  91683. super();
  91684. this.isGLTFSpecularGlossinessMaterial = true;
  91685. //various chunks that need replacing
  91686. const specularMapParsFragmentChunk = [
  91687. '#ifdef USE_SPECULARMAP',
  91688. ' uniform sampler2D specularMap;',
  91689. '#endif'
  91690. ].join( '\n' );
  91691. const glossinessMapParsFragmentChunk = [
  91692. '#ifdef USE_GLOSSINESSMAP',
  91693. ' uniform sampler2D glossinessMap;',
  91694. '#endif'
  91695. ].join( '\n' );
  91696. const specularMapFragmentChunk = [
  91697. 'vec3 specularFactor = specular;',
  91698. '#ifdef USE_SPECULARMAP',
  91699. ' vec4 texelSpecular = texture2D( specularMap, vUv );',
  91700. ' // reads channel RGB, compatible with a glTF Specular-Glossiness (RGBA) texture',
  91701. ' specularFactor *= texelSpecular.rgb;',
  91702. '#endif'
  91703. ].join( '\n' );
  91704. const glossinessMapFragmentChunk = [
  91705. 'float glossinessFactor = glossiness;',
  91706. '#ifdef USE_GLOSSINESSMAP',
  91707. ' vec4 texelGlossiness = texture2D( glossinessMap, vUv );',
  91708. ' // reads channel A, compatible with a glTF Specular-Glossiness (RGBA) texture',
  91709. ' glossinessFactor *= texelGlossiness.a;',
  91710. '#endif'
  91711. ].join( '\n' );
  91712. const lightPhysicalFragmentChunk = [
  91713. 'PhysicalMaterial material;',
  91714. 'material.diffuseColor = diffuseColor.rgb * ( 1. - max( specularFactor.r, max( specularFactor.g, specularFactor.b ) ) );',
  91715. 'vec3 dxy = max( abs( dFdx( geometryNormal ) ), abs( dFdy( geometryNormal ) ) );',
  91716. 'float geometryRoughness = max( max( dxy.x, dxy.y ), dxy.z );',
  91717. 'material.roughness = max( 1.0 - glossinessFactor, 0.0525 ); // 0.0525 corresponds to the base mip of a 256 cubemap.',
  91718. 'material.roughness += geometryRoughness;',
  91719. 'material.roughness = min( material.roughness, 1.0 );',
  91720. 'material.specularColor = specularFactor;',
  91721. ].join( '\n' );
  91722. const uniforms = {
  91723. specular: { value: new Color().setHex( 0xffffff ) },
  91724. glossiness: { value: 1 },
  91725. specularMap: { value: null },
  91726. glossinessMap: { value: null }
  91727. };
  91728. this._extraUniforms = uniforms;
  91729. this.onBeforeCompile = function ( shader ) {
  91730. for ( const uniformName in uniforms ) {
  91731. shader.uniforms[ uniformName ] = uniforms[ uniformName ];
  91732. }
  91733. shader.fragmentShader = shader.fragmentShader
  91734. .replace( 'uniform float roughness;', 'uniform vec3 specular;' )
  91735. .replace( 'uniform float metalness;', 'uniform float glossiness;' )
  91736. .replace( '#include <roughnessmap_pars_fragment>', specularMapParsFragmentChunk )
  91737. .replace( '#include <metalnessmap_pars_fragment>', glossinessMapParsFragmentChunk )
  91738. .replace( '#include <roughnessmap_fragment>', specularMapFragmentChunk )
  91739. .replace( '#include <metalnessmap_fragment>', glossinessMapFragmentChunk )
  91740. .replace( '#include <lights_physical_fragment>', lightPhysicalFragmentChunk );
  91741. };
  91742. Object.defineProperties( this, {
  91743. specular: {
  91744. get: function () {
  91745. return uniforms.specular.value;
  91746. },
  91747. set: function ( v ) {
  91748. uniforms.specular.value = v;
  91749. }
  91750. },
  91751. specularMap: {
  91752. get: function () {
  91753. return uniforms.specularMap.value;
  91754. },
  91755. set: function ( v ) {
  91756. uniforms.specularMap.value = v;
  91757. if ( v ) {
  91758. this.defines.USE_SPECULARMAP = ''; // USE_UV is set by the renderer for specular maps
  91759. } else {
  91760. delete this.defines.USE_SPECULARMAP;
  91761. }
  91762. }
  91763. },
  91764. glossiness: {
  91765. get: function () {
  91766. return uniforms.glossiness.value;
  91767. },
  91768. set: function ( v ) {
  91769. uniforms.glossiness.value = v;
  91770. }
  91771. },
  91772. glossinessMap: {
  91773. get: function () {
  91774. return uniforms.glossinessMap.value;
  91775. },
  91776. set: function ( v ) {
  91777. uniforms.glossinessMap.value = v;
  91778. if ( v ) {
  91779. this.defines.USE_GLOSSINESSMAP = '';
  91780. this.defines.USE_UV = '';
  91781. } else {
  91782. delete this.defines.USE_GLOSSINESSMAP;
  91783. delete this.defines.USE_UV;
  91784. }
  91785. }
  91786. }
  91787. } );
  91788. delete this.metalness;
  91789. delete this.roughness;
  91790. delete this.metalnessMap;
  91791. delete this.roughnessMap;
  91792. this.setValues( params );
  91793. }
  91794. copy( source ) {
  91795. super.copy( source );
  91796. this.specularMap = source.specularMap;
  91797. this.specular.copy( source.specular );
  91798. this.glossinessMap = source.glossinessMap;
  91799. this.glossiness = source.glossiness;
  91800. delete this.metalness;
  91801. delete this.roughness;
  91802. delete this.metalnessMap;
  91803. delete this.roughnessMap;
  91804. return this;
  91805. }
  91806. }
  91807. class GLTFMaterialsPbrSpecularGlossinessExtension {
  91808. constructor() {
  91809. this.name = EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS;
  91810. this.specularGlossinessParams = [
  91811. 'color',
  91812. 'map',
  91813. 'lightMap',
  91814. 'lightMapIntensity',
  91815. 'aoMap',
  91816. 'aoMapIntensity',
  91817. 'emissive',
  91818. 'emissiveIntensity',
  91819. 'emissiveMap',
  91820. 'bumpMap',
  91821. 'bumpScale',
  91822. 'normalMap',
  91823. 'normalMapType',
  91824. 'displacementMap',
  91825. 'displacementScale',
  91826. 'displacementBias',
  91827. 'specularMap',
  91828. 'specular',
  91829. 'glossinessMap',
  91830. 'glossiness',
  91831. 'alphaMap',
  91832. 'envMap',
  91833. 'envMapIntensity'
  91834. ];
  91835. }
  91836. getMaterialType() {
  91837. return GLTFMeshStandardSGMaterial;
  91838. }
  91839. extendParams( materialParams, materialDef, parser ) {
  91840. const pbrSpecularGlossiness = materialDef.extensions[ this.name ];
  91841. materialParams.color = new Color( 1.0, 1.0, 1.0 );
  91842. materialParams.opacity = 1.0;
  91843. const pending = [];
  91844. if ( Array.isArray( pbrSpecularGlossiness.diffuseFactor ) ) {
  91845. const array = pbrSpecularGlossiness.diffuseFactor;
  91846. materialParams.color.fromArray( array );
  91847. materialParams.opacity = array[ 3 ];
  91848. }
  91849. if ( pbrSpecularGlossiness.diffuseTexture !== undefined ) {
  91850. pending.push( parser.assignTexture( materialParams, 'map', pbrSpecularGlossiness.diffuseTexture, sRGBEncoding ) );
  91851. }
  91852. materialParams.emissive = new Color( 0.0, 0.0, 0.0 );
  91853. materialParams.glossiness = pbrSpecularGlossiness.glossinessFactor !== undefined ? pbrSpecularGlossiness.glossinessFactor : 1.0;
  91854. materialParams.specular = new Color( 1.0, 1.0, 1.0 );
  91855. if ( Array.isArray( pbrSpecularGlossiness.specularFactor ) ) {
  91856. materialParams.specular.fromArray( pbrSpecularGlossiness.specularFactor );
  91857. }
  91858. if ( pbrSpecularGlossiness.specularGlossinessTexture !== undefined ) {
  91859. const specGlossMapDef = pbrSpecularGlossiness.specularGlossinessTexture;
  91860. pending.push( parser.assignTexture( materialParams, 'glossinessMap', specGlossMapDef ) );
  91861. pending.push( parser.assignTexture( materialParams, 'specularMap', specGlossMapDef, sRGBEncoding ) );
  91862. }
  91863. return Promise.all( pending );
  91864. }
  91865. createMaterial( materialParams ) {
  91866. const material = new GLTFMeshStandardSGMaterial( materialParams );
  91867. material.fog = true;
  91868. material.color = materialParams.color;
  91869. material.map = materialParams.map === undefined ? null : materialParams.map;
  91870. material.lightMap = null;
  91871. material.lightMapIntensity = 1.0;
  91872. material.aoMap = materialParams.aoMap === undefined ? null : materialParams.aoMap;
  91873. material.aoMapIntensity = 1.0;
  91874. material.emissive = materialParams.emissive;
  91875. material.emissiveIntensity = materialParams.emissiveIntensity === undefined ? 1.0 : materialParams.emissiveIntensity;
  91876. material.emissiveMap = materialParams.emissiveMap === undefined ? null : materialParams.emissiveMap;
  91877. material.bumpMap = materialParams.bumpMap === undefined ? null : materialParams.bumpMap;
  91878. material.bumpScale = 1;
  91879. material.normalMap = materialParams.normalMap === undefined ? null : materialParams.normalMap;
  91880. material.normalMapType = TangentSpaceNormalMap;
  91881. if ( materialParams.normalScale ) material.normalScale = materialParams.normalScale;
  91882. material.displacementMap = null;
  91883. material.displacementScale = 1;
  91884. material.displacementBias = 0;
  91885. material.specularMap = materialParams.specularMap === undefined ? null : materialParams.specularMap;
  91886. material.specular = materialParams.specular;
  91887. material.glossinessMap = materialParams.glossinessMap === undefined ? null : materialParams.glossinessMap;
  91888. material.glossiness = materialParams.glossiness;
  91889. material.alphaMap = null;
  91890. material.envMap = materialParams.envMap === undefined ? null : materialParams.envMap;
  91891. material.envMapIntensity = 1.0;
  91892. return material;
  91893. }
  91894. }
  91895. /**
  91896. * Mesh Quantization Extension
  91897. *
  91898. * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization
  91899. */
  91900. class GLTFMeshQuantizationExtension {
  91901. constructor() {
  91902. this.name = EXTENSIONS.KHR_MESH_QUANTIZATION;
  91903. }
  91904. }
  91905. /*********************************/
  91906. /********** INTERPOLATION ********/
  91907. /*********************************/
  91908. // Spline Interpolation
  91909. // Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#appendix-c-spline-interpolation
  91910. class GLTFCubicSplineInterpolant extends Interpolant {
  91911. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  91912. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  91913. }
  91914. copySampleValue_( index ) {
  91915. // Copies a sample value to the result buffer. See description of glTF
  91916. // CUBICSPLINE values layout in interpolate_() function below.
  91917. const result = this.resultBuffer,
  91918. values = this.sampleValues,
  91919. valueSize = this.valueSize,
  91920. offset = index * valueSize * 3 + valueSize;
  91921. for ( let i = 0; i !== valueSize; i ++ ) {
  91922. result[ i ] = values[ offset + i ];
  91923. }
  91924. return result;
  91925. }
  91926. interpolate_( i1, t0, t, t1 ) {
  91927. const result = this.resultBuffer;
  91928. const values = this.sampleValues;
  91929. const stride = this.valueSize;
  91930. const stride2 = stride * 2;
  91931. const stride3 = stride * 3;
  91932. const td = t1 - t0;
  91933. const p = ( t - t0 ) / td;
  91934. const pp = p * p;
  91935. const ppp = pp * p;
  91936. const offset1 = i1 * stride3;
  91937. const offset0 = offset1 - stride3;
  91938. const s2 = - 2 * ppp + 3 * pp;
  91939. const s3 = ppp - pp;
  91940. const s0 = 1 - s2;
  91941. const s1 = s3 - pp + p;
  91942. // Layout of keyframe output values for CUBICSPLINE animations:
  91943. // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
  91944. for ( let i = 0; i !== stride; i ++ ) {
  91945. const p0 = values[ offset0 + i + stride ]; // splineVertex_k
  91946. const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
  91947. const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
  91948. const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
  91949. result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
  91950. }
  91951. return result;
  91952. }
  91953. }
  91954. const _q = new Quaternion();
  91955. class GLTFCubicSplineQuaternionInterpolant extends GLTFCubicSplineInterpolant {
  91956. interpolate_( i1, t0, t, t1 ) {
  91957. const result = super.interpolate_( i1, t0, t, t1 );
  91958. _q.fromArray( result ).normalize().toArray( result );
  91959. return result;
  91960. }
  91961. }
  91962. /*********************************/
  91963. /********** INTERNALS ************/
  91964. /*********************************/
  91965. /* CONSTANTS */
  91966. const WEBGL_CONSTANTS = {
  91967. FLOAT: 5126,
  91968. //FLOAT_MAT2: 35674,
  91969. FLOAT_MAT3: 35675,
  91970. FLOAT_MAT4: 35676,
  91971. FLOAT_VEC2: 35664,
  91972. FLOAT_VEC3: 35665,
  91973. FLOAT_VEC4: 35666,
  91974. LINEAR: 9729,
  91975. REPEAT: 10497,
  91976. SAMPLER_2D: 35678,
  91977. POINTS: 0,
  91978. LINES: 1,
  91979. LINE_LOOP: 2,
  91980. LINE_STRIP: 3,
  91981. TRIANGLES: 4,
  91982. TRIANGLE_STRIP: 5,
  91983. TRIANGLE_FAN: 6,
  91984. UNSIGNED_BYTE: 5121,
  91985. UNSIGNED_SHORT: 5123
  91986. };
  91987. const WEBGL_COMPONENT_TYPES = {
  91988. 5120: Int8Array,
  91989. 5121: Uint8Array,
  91990. 5122: Int16Array,
  91991. 5123: Uint16Array,
  91992. 5125: Uint32Array,
  91993. 5126: Float32Array
  91994. };
  91995. const WEBGL_FILTERS = {
  91996. 9728: NearestFilter,
  91997. 9729: LinearFilter,
  91998. 9984: NearestMipmapNearestFilter,
  91999. 9985: LinearMipmapNearestFilter,
  92000. 9986: NearestMipmapLinearFilter,
  92001. 9987: LinearMipmapLinearFilter
  92002. };
  92003. const WEBGL_WRAPPINGS = {
  92004. 33071: ClampToEdgeWrapping,
  92005. 33648: MirroredRepeatWrapping,
  92006. 10497: RepeatWrapping
  92007. };
  92008. const WEBGL_TYPE_SIZES = {
  92009. 'SCALAR': 1,
  92010. 'VEC2': 2,
  92011. 'VEC3': 3,
  92012. 'VEC4': 4,
  92013. 'MAT2': 4,
  92014. 'MAT3': 9,
  92015. 'MAT4': 16
  92016. };
  92017. const ATTRIBUTES = {
  92018. POSITION: 'position',
  92019. NORMAL: 'normal',
  92020. TANGENT: 'tangent',
  92021. TEXCOORD_0: 'uv',
  92022. TEXCOORD_1: 'uv2',
  92023. COLOR_0: 'color',
  92024. WEIGHTS_0: 'skinWeight',
  92025. JOINTS_0: 'skinIndex',
  92026. };
  92027. const PATH_PROPERTIES = {
  92028. scale: 'scale',
  92029. translation: 'position',
  92030. rotation: 'quaternion',
  92031. weights: 'morphTargetInfluences'
  92032. };
  92033. const INTERPOLATION = {
  92034. CUBICSPLINE: undefined, // We use a custom interpolant (GLTFCubicSplineInterpolation) for CUBICSPLINE tracks. Each
  92035. // keyframe track will be initialized with a default interpolation type, then modified.
  92036. LINEAR: InterpolateLinear,
  92037. STEP: InterpolateDiscrete
  92038. };
  92039. const ALPHA_MODES = {
  92040. OPAQUE: 'OPAQUE',
  92041. MASK: 'MASK',
  92042. BLEND: 'BLEND'
  92043. };
  92044. /**
  92045. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#default-material
  92046. */
  92047. function createDefaultMaterial( cache ) {
  92048. if ( cache[ 'DefaultMaterial' ] === undefined ) {
  92049. cache[ 'DefaultMaterial' ] = new MeshStandardMaterial( {
  92050. color: 0xFFFFFF,
  92051. emissive: 0x000000,
  92052. metalness: 1,
  92053. roughness: 1,
  92054. transparent: false,
  92055. depthTest: true,
  92056. side: FrontSide
  92057. } );
  92058. }
  92059. return cache[ 'DefaultMaterial' ];
  92060. }
  92061. function addUnknownExtensionsToUserData( knownExtensions, object, objectDef ) {
  92062. // Add unknown glTF extensions to an object's userData.
  92063. for ( const name in objectDef.extensions ) {
  92064. if ( knownExtensions[ name ] === undefined ) {
  92065. object.userData.gltfExtensions = object.userData.gltfExtensions || {};
  92066. object.userData.gltfExtensions[ name ] = objectDef.extensions[ name ];
  92067. }
  92068. }
  92069. }
  92070. /**
  92071. * @param {Object3D|Material|BufferGeometry} object
  92072. * @param {GLTF.definition} gltfDef
  92073. */
  92074. function assignExtrasToUserData( object, gltfDef ) {
  92075. if ( gltfDef.extras !== undefined ) {
  92076. if ( typeof gltfDef.extras === 'object' ) {
  92077. Object.assign( object.userData, gltfDef.extras );
  92078. } else {
  92079. console.warn( 'THREE.GLTFLoader: Ignoring primitive type .extras, ' + gltfDef.extras );
  92080. }
  92081. }
  92082. }
  92083. /**
  92084. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#morph-targets
  92085. *
  92086. * @param {BufferGeometry} geometry
  92087. * @param {Array<GLTF.Target>} targets
  92088. * @param {GLTFParser} parser
  92089. * @return {Promise<BufferGeometry>}
  92090. */
  92091. function addMorphTargets( geometry, targets, parser ) {
  92092. let hasMorphPosition = false;
  92093. let hasMorphNormal = false;
  92094. let hasMorphColor = false;
  92095. for ( let i = 0, il = targets.length; i < il; i ++ ) {
  92096. const target = targets[ i ];
  92097. if ( target.POSITION !== undefined ) hasMorphPosition = true;
  92098. if ( target.NORMAL !== undefined ) hasMorphNormal = true;
  92099. if ( target.COLOR_0 !== undefined ) hasMorphColor = true;
  92100. if ( hasMorphPosition && hasMorphNormal && hasMorphColor ) break;
  92101. }
  92102. if ( ! hasMorphPosition && ! hasMorphNormal && ! hasMorphColor ) return Promise.resolve( geometry );
  92103. const pendingPositionAccessors = [];
  92104. const pendingNormalAccessors = [];
  92105. const pendingColorAccessors = [];
  92106. for ( let i = 0, il = targets.length; i < il; i ++ ) {
  92107. const target = targets[ i ];
  92108. if ( hasMorphPosition ) {
  92109. const pendingAccessor = target.POSITION !== undefined
  92110. ? parser.getDependency( 'accessor', target.POSITION )
  92111. : geometry.attributes.position;
  92112. pendingPositionAccessors.push( pendingAccessor );
  92113. }
  92114. if ( hasMorphNormal ) {
  92115. const pendingAccessor = target.NORMAL !== undefined
  92116. ? parser.getDependency( 'accessor', target.NORMAL )
  92117. : geometry.attributes.normal;
  92118. pendingNormalAccessors.push( pendingAccessor );
  92119. }
  92120. if ( hasMorphColor ) {
  92121. const pendingAccessor = target.COLOR_0 !== undefined
  92122. ? parser.getDependency( 'accessor', target.COLOR_0 )
  92123. : geometry.attributes.color;
  92124. pendingColorAccessors.push( pendingAccessor );
  92125. }
  92126. }
  92127. return Promise.all( [
  92128. Promise.all( pendingPositionAccessors ),
  92129. Promise.all( pendingNormalAccessors ),
  92130. Promise.all( pendingColorAccessors )
  92131. ] ).then( function ( accessors ) {
  92132. const morphPositions = accessors[ 0 ];
  92133. const morphNormals = accessors[ 1 ];
  92134. const morphColors = accessors[ 2 ];
  92135. if ( hasMorphPosition ) geometry.morphAttributes.position = morphPositions;
  92136. if ( hasMorphNormal ) geometry.morphAttributes.normal = morphNormals;
  92137. if ( hasMorphColor ) geometry.morphAttributes.color = morphColors;
  92138. geometry.morphTargetsRelative = true;
  92139. return geometry;
  92140. } );
  92141. }
  92142. /**
  92143. * @param {Mesh} mesh
  92144. * @param {GLTF.Mesh} meshDef
  92145. */
  92146. function updateMorphTargets( mesh, meshDef ) {
  92147. mesh.updateMorphTargets();
  92148. if ( meshDef.weights !== undefined ) {
  92149. for ( let i = 0, il = meshDef.weights.length; i < il; i ++ ) {
  92150. mesh.morphTargetInfluences[ i ] = meshDef.weights[ i ];
  92151. }
  92152. }
  92153. // .extras has user-defined data, so check that .extras.targetNames is an array.
  92154. if ( meshDef.extras && Array.isArray( meshDef.extras.targetNames ) ) {
  92155. const targetNames = meshDef.extras.targetNames;
  92156. if ( mesh.morphTargetInfluences.length === targetNames.length ) {
  92157. mesh.morphTargetDictionary = {};
  92158. for ( let i = 0, il = targetNames.length; i < il; i ++ ) {
  92159. mesh.morphTargetDictionary[ targetNames[ i ] ] = i;
  92160. }
  92161. } else {
  92162. console.warn( 'THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.' );
  92163. }
  92164. }
  92165. }
  92166. function createPrimitiveKey( primitiveDef ) {
  92167. const dracoExtension = primitiveDef.extensions && primitiveDef.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ];
  92168. let geometryKey;
  92169. if ( dracoExtension ) {
  92170. geometryKey = 'draco:' + dracoExtension.bufferView
  92171. + ':' + dracoExtension.indices
  92172. + ':' + createAttributesKey( dracoExtension.attributes );
  92173. } else {
  92174. geometryKey = primitiveDef.indices + ':' + createAttributesKey( primitiveDef.attributes ) + ':' + primitiveDef.mode;
  92175. }
  92176. return geometryKey;
  92177. }
  92178. function createAttributesKey( attributes ) {
  92179. let attributesKey = '';
  92180. const keys = Object.keys( attributes ).sort();
  92181. for ( let i = 0, il = keys.length; i < il; i ++ ) {
  92182. attributesKey += keys[ i ] + ':' + attributes[ keys[ i ] ] + ';';
  92183. }
  92184. return attributesKey;
  92185. }
  92186. function getNormalizedComponentScale( constructor ) {
  92187. // Reference:
  92188. // https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_mesh_quantization#encoding-quantized-data
  92189. switch ( constructor ) {
  92190. case Int8Array:
  92191. return 1 / 127;
  92192. case Uint8Array:
  92193. return 1 / 255;
  92194. case Int16Array:
  92195. return 1 / 32767;
  92196. case Uint16Array:
  92197. return 1 / 65535;
  92198. default:
  92199. throw new Error( 'THREE.GLTFLoader: Unsupported normalized accessor component type.' );
  92200. }
  92201. }
  92202. function getImageURIMimeType( uri ) {
  92203. if ( uri.search( /\.jpe?g($|\?)/i ) > 0 || uri.search( /^data\:image\/jpeg/ ) === 0 ) return 'image/jpeg';
  92204. if ( uri.search( /\.webp($|\?)/i ) > 0 || uri.search( /^data\:image\/webp/ ) === 0 ) return 'image/webp';
  92205. return 'image/png';
  92206. }
  92207. /* GLTF PARSER */
  92208. class GLTFParser {
  92209. constructor( json = {}, options = {} ) {
  92210. this.json = json;
  92211. this.extensions = {};
  92212. this.plugins = {};
  92213. this.options = options;
  92214. // loader object cache
  92215. this.cache = new GLTFRegistry();
  92216. // associations between Three.js objects and glTF elements
  92217. this.associations = new Map();
  92218. // BufferGeometry caching
  92219. this.primitiveCache = {};
  92220. // Object3D instance caches
  92221. this.meshCache = { refs: {}, uses: {} };
  92222. this.cameraCache = { refs: {}, uses: {} };
  92223. this.lightCache = { refs: {}, uses: {} };
  92224. this.sourceCache = {};
  92225. this.textureCache = {};
  92226. // Track node names, to ensure no duplicates
  92227. this.nodeNamesUsed = {};
  92228. // Use an ImageBitmapLoader if imageBitmaps are supported. Moves much of the
  92229. // expensive work of uploading a texture to the GPU off the main thread.
  92230. const isSafari = /^((?!chrome|android).)*safari/i.test( navigator.userAgent ) === true;
  92231. const isFirefox = navigator.userAgent.indexOf( 'Firefox' ) > - 1;
  92232. const firefoxVersion = isFirefox ? navigator.userAgent.match( /Firefox\/([0-9]+)\./ )[ 1 ] : - 1;
  92233. // if ( typeof createImageBitmap === 'undefined' || isSafari || ( isFirefox && firefoxVersion < 98 ) ) {
  92234. this.textureLoader = new TextureLoader( this.options.manager );
  92235. /*} else {
  92236. //为了防止chrome出现报错 The source image could not be decoded. 导致reject,改用TextureLoader by xzw
  92237. this.textureLoader = new ImageBitmapLoader( this.options.manager );
  92238. }
  92239. */
  92240. this.textureLoader.setCrossOrigin( this.options.crossOrigin );
  92241. this.textureLoader.setRequestHeader( this.options.requestHeader );
  92242. this.fileLoader = new FileLoader( this.options.manager );
  92243. this.fileLoader.setResponseType( 'arraybuffer' );
  92244. if ( this.options.crossOrigin === 'use-credentials' ) {
  92245. this.fileLoader.setWithCredentials( true );
  92246. }
  92247. }
  92248. setExtensions( extensions ) {
  92249. this.extensions = extensions;
  92250. }
  92251. setPlugins( plugins ) {
  92252. this.plugins = plugins;
  92253. }
  92254. parse( onLoad, onError ) {
  92255. const parser = this;
  92256. const json = this.json;
  92257. const extensions = this.extensions;
  92258. // Clear the loader cache
  92259. this.cache.removeAll();
  92260. // Mark the special nodes/meshes in json for efficient parse
  92261. this._invokeAll( function ( ext ) {
  92262. return ext._markDefs && ext._markDefs();
  92263. } );
  92264. Promise.all( this._invokeAll( function ( ext ) {
  92265. return ext.beforeRoot && ext.beforeRoot();
  92266. } ) ).then( function () {
  92267. return Promise.all( [
  92268. parser.getDependencies( 'scene' ),
  92269. parser.getDependencies( 'animation' ),
  92270. parser.getDependencies( 'camera' ),
  92271. ] );
  92272. } ).then( function ( dependencies ) {
  92273. const result = {
  92274. scene: dependencies[ 0 ][ json.scene || 0 ],
  92275. scenes: dependencies[ 0 ],
  92276. animations: dependencies[ 1 ],
  92277. cameras: dependencies[ 2 ],
  92278. asset: json.asset,
  92279. parser: parser,
  92280. userData: {}
  92281. };
  92282. addUnknownExtensionsToUserData( extensions, result, json );
  92283. assignExtrasToUserData( result, json );
  92284. Promise.all( parser._invokeAll( function ( ext ) {
  92285. return ext.afterRoot && ext.afterRoot( result );
  92286. } ) ).then( function () {
  92287. onLoad( result );
  92288. } );
  92289. } ).catch( onError );
  92290. }
  92291. /**
  92292. * Marks the special nodes/meshes in json for efficient parse.
  92293. */
  92294. _markDefs() {
  92295. const nodeDefs = this.json.nodes || [];
  92296. const skinDefs = this.json.skins || [];
  92297. const meshDefs = this.json.meshes || [];
  92298. // Nothing in the node definition indicates whether it is a Bone or an
  92299. // Object3D. Use the skins' joint references to mark bones.
  92300. for ( let skinIndex = 0, skinLength = skinDefs.length; skinIndex < skinLength; skinIndex ++ ) {
  92301. const joints = skinDefs[ skinIndex ].joints;
  92302. for ( let i = 0, il = joints.length; i < il; i ++ ) {
  92303. nodeDefs[ joints[ i ] ].isBone = true;
  92304. }
  92305. }
  92306. // Iterate over all nodes, marking references to shared resources,
  92307. // as well as skeleton joints.
  92308. for ( let nodeIndex = 0, nodeLength = nodeDefs.length; nodeIndex < nodeLength; nodeIndex ++ ) {
  92309. const nodeDef = nodeDefs[ nodeIndex ];
  92310. if ( nodeDef.mesh !== undefined ) {
  92311. this._addNodeRef( this.meshCache, nodeDef.mesh );
  92312. // Nothing in the mesh definition indicates whether it is
  92313. // a SkinnedMesh or Mesh. Use the node's mesh reference
  92314. // to mark SkinnedMesh if node has skin.
  92315. if ( nodeDef.skin !== undefined ) {
  92316. meshDefs[ nodeDef.mesh ].isSkinnedMesh = true;
  92317. }
  92318. }
  92319. if ( nodeDef.camera !== undefined ) {
  92320. this._addNodeRef( this.cameraCache, nodeDef.camera );
  92321. }
  92322. }
  92323. }
  92324. /**
  92325. * Counts references to shared node / Object3D resources. These resources
  92326. * can be reused, or "instantiated", at multiple nodes in the scene
  92327. * hierarchy. Mesh, Camera, and Light instances are instantiated and must
  92328. * be marked. Non-scenegraph resources (like Materials, Geometries, and
  92329. * Textures) can be reused directly and are not marked here.
  92330. *
  92331. * Example: CesiumMilkTruck sample model reuses "Wheel" meshes.
  92332. */
  92333. _addNodeRef( cache, index ) {
  92334. if ( index === undefined ) return;
  92335. if ( cache.refs[ index ] === undefined ) {
  92336. cache.refs[ index ] = cache.uses[ index ] = 0;
  92337. }
  92338. cache.refs[ index ] ++;
  92339. }
  92340. /** Returns a reference to a shared resource, cloning it if necessary. */
  92341. _getNodeRef( cache, index, object ) {
  92342. if ( cache.refs[ index ] <= 1 ) return object;
  92343. const ref = object.clone();
  92344. // Propagates mappings to the cloned object, prevents mappings on the
  92345. // original object from being lost.
  92346. const updateMappings = ( original, clone ) => {
  92347. const mappings = this.associations.get( original );
  92348. if ( mappings != null ) {
  92349. this.associations.set( clone, mappings );
  92350. }
  92351. for ( const [ i, child ] of original.children.entries() ) {
  92352. updateMappings( child, clone.children[ i ] );
  92353. }
  92354. };
  92355. updateMappings( object, ref );
  92356. ref.name += '_instance_' + ( cache.uses[ index ] ++ );
  92357. return ref;
  92358. }
  92359. _invokeOne( func ) {
  92360. const extensions = Object.values( this.plugins );
  92361. extensions.push( this );
  92362. for ( let i = 0; i < extensions.length; i ++ ) {
  92363. const result = func( extensions[ i ] );
  92364. if ( result ) return result;
  92365. }
  92366. return null;
  92367. }
  92368. _invokeAll( func ) {
  92369. const extensions = Object.values( this.plugins );
  92370. extensions.unshift( this );
  92371. const pending = [];
  92372. for ( let i = 0; i < extensions.length; i ++ ) {
  92373. const result = func( extensions[ i ] );
  92374. if ( result ) pending.push( result );
  92375. }
  92376. return pending;
  92377. }
  92378. /**
  92379. * Requests the specified dependency asynchronously, with caching.
  92380. * @param {string} type
  92381. * @param {number} index
  92382. * @return {Promise<Object3D|Material|THREE.Texture|AnimationClip|ArrayBuffer|Object>}
  92383. */
  92384. getDependency( type, index ) {
  92385. const cacheKey = type + ':' + index;
  92386. let dependency = this.cache.get( cacheKey );
  92387. if ( ! dependency ) {
  92388. switch ( type ) {
  92389. case 'scene':
  92390. dependency = this.loadScene( index );
  92391. break;
  92392. case 'node':
  92393. dependency = this.loadNode( index );
  92394. break;
  92395. case 'mesh':
  92396. dependency = this._invokeOne( function ( ext ) {
  92397. return ext.loadMesh && ext.loadMesh( index );
  92398. } );
  92399. break;
  92400. case 'accessor':
  92401. dependency = this.loadAccessor( index );
  92402. break;
  92403. case 'bufferView':
  92404. dependency = this._invokeOne( function ( ext ) {
  92405. return ext.loadBufferView && ext.loadBufferView( index );
  92406. } );
  92407. break;
  92408. case 'buffer':
  92409. dependency = this.loadBuffer( index );
  92410. break;
  92411. case 'material':
  92412. dependency = this._invokeOne( function ( ext ) {
  92413. return ext.loadMaterial && ext.loadMaterial( index );
  92414. } );
  92415. break;
  92416. case 'texture':
  92417. dependency = this._invokeOne( function ( ext ) {
  92418. return ext.loadTexture && ext.loadTexture( index );
  92419. } );
  92420. break;
  92421. case 'skin':
  92422. dependency = this.loadSkin( index );
  92423. break;
  92424. case 'animation':
  92425. dependency = this._invokeOne( function ( ext ) {
  92426. return ext.loadAnimation && ext.loadAnimation( index );
  92427. } );
  92428. break;
  92429. case 'camera':
  92430. dependency = this.loadCamera( index );
  92431. break;
  92432. default:
  92433. throw new Error( 'Unknown type: ' + type );
  92434. }
  92435. this.cache.add( cacheKey, dependency );
  92436. }
  92437. return dependency;
  92438. }
  92439. /**
  92440. * Requests all dependencies of the specified type asynchronously, with caching.
  92441. * @param {string} type
  92442. * @return {Promise<Array<Object>>}
  92443. */
  92444. getDependencies( type ) {
  92445. let dependencies = this.cache.get( type );
  92446. if ( ! dependencies ) {
  92447. const parser = this;
  92448. const defs = this.json[ type + ( type === 'mesh' ? 'es' : 's' ) ] || [];
  92449. dependencies = Promise.all( defs.map( function ( def, index ) {
  92450. return parser.getDependency( type, index );
  92451. } ) );
  92452. this.cache.add( type, dependencies );
  92453. }
  92454. return dependencies;
  92455. }
  92456. /**
  92457. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
  92458. * @param {number} bufferIndex
  92459. * @return {Promise<ArrayBuffer>}
  92460. */
  92461. loadBuffer( bufferIndex ) {
  92462. const bufferDef = this.json.buffers[ bufferIndex ];
  92463. const loader = this.fileLoader;
  92464. if ( bufferDef.type && bufferDef.type !== 'arraybuffer' ) {
  92465. throw new Error( 'THREE.GLTFLoader: ' + bufferDef.type + ' buffer type is not supported.' );
  92466. }
  92467. // If present, GLB container is required to be the first buffer.
  92468. if ( bufferDef.uri === undefined && bufferIndex === 0 ) {
  92469. return Promise.resolve( this.extensions[ EXTENSIONS.KHR_BINARY_GLTF ].body );
  92470. }
  92471. const options = this.options;
  92472. return new Promise( function ( resolve, reject ) {
  92473. loader.load( LoaderUtils.resolveURL( bufferDef.uri, options.path ), resolve, undefined, function () {
  92474. reject( new Error( 'THREE.GLTFLoader: Failed to load buffer "' + bufferDef.uri + '".' ) );
  92475. } );
  92476. } );
  92477. }
  92478. /**
  92479. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#buffers-and-buffer-views
  92480. * @param {number} bufferViewIndex
  92481. * @return {Promise<ArrayBuffer>}
  92482. */
  92483. loadBufferView( bufferViewIndex ) {
  92484. const bufferViewDef = this.json.bufferViews[ bufferViewIndex ];
  92485. return this.getDependency( 'buffer', bufferViewDef.buffer ).then( function ( buffer ) {
  92486. const byteLength = bufferViewDef.byteLength || 0;
  92487. const byteOffset = bufferViewDef.byteOffset || 0;
  92488. return buffer.slice( byteOffset, byteOffset + byteLength );
  92489. } );
  92490. }
  92491. /**
  92492. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#accessors
  92493. * @param {number} accessorIndex
  92494. * @return {Promise<BufferAttribute|InterleavedBufferAttribute>}
  92495. */
  92496. loadAccessor( accessorIndex ) {
  92497. const parser = this;
  92498. const json = this.json;
  92499. const accessorDef = this.json.accessors[ accessorIndex ];
  92500. if ( accessorDef.bufferView === undefined && accessorDef.sparse === undefined ) {
  92501. // Ignore empty accessors, which may be used to declare runtime
  92502. // information about attributes coming from another source (e.g. Draco
  92503. // compression extension).
  92504. return Promise.resolve( null );
  92505. }
  92506. const pendingBufferViews = [];
  92507. if ( accessorDef.bufferView !== undefined ) {
  92508. pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.bufferView ) );
  92509. } else {
  92510. pendingBufferViews.push( null );
  92511. }
  92512. if ( accessorDef.sparse !== undefined ) {
  92513. pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.indices.bufferView ) );
  92514. pendingBufferViews.push( this.getDependency( 'bufferView', accessorDef.sparse.values.bufferView ) );
  92515. }
  92516. return Promise.all( pendingBufferViews ).then( function ( bufferViews ) {
  92517. const bufferView = bufferViews[ 0 ];
  92518. const itemSize = WEBGL_TYPE_SIZES[ accessorDef.type ];
  92519. const TypedArray = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
  92520. // For VEC3: itemSize is 3, elementBytes is 4, itemBytes is 12.
  92521. const elementBytes = TypedArray.BYTES_PER_ELEMENT;
  92522. const itemBytes = elementBytes * itemSize;
  92523. const byteOffset = accessorDef.byteOffset || 0;
  92524. const byteStride = accessorDef.bufferView !== undefined ? json.bufferViews[ accessorDef.bufferView ].byteStride : undefined;
  92525. const normalized = accessorDef.normalized === true;
  92526. let array, bufferAttribute;
  92527. // The buffer is not interleaved if the stride is the item size in bytes.
  92528. if ( byteStride && byteStride !== itemBytes ) {
  92529. // Each "slice" of the buffer, as defined by 'count' elements of 'byteStride' bytes, gets its own InterleavedBuffer
  92530. // This makes sure that IBA.count reflects accessor.count properly
  92531. const ibSlice = Math.floor( byteOffset / byteStride );
  92532. const ibCacheKey = 'InterleavedBuffer:' + accessorDef.bufferView + ':' + accessorDef.componentType + ':' + ibSlice + ':' + accessorDef.count;
  92533. let ib = parser.cache.get( ibCacheKey );
  92534. if ( ! ib ) {
  92535. array = new TypedArray( bufferView, ibSlice * byteStride, accessorDef.count * byteStride / elementBytes );
  92536. // Integer parameters to IB/IBA are in array elements, not bytes.
  92537. ib = new InterleavedBuffer( array, byteStride / elementBytes );
  92538. parser.cache.add( ibCacheKey, ib );
  92539. }
  92540. bufferAttribute = new InterleavedBufferAttribute( ib, itemSize, ( byteOffset % byteStride ) / elementBytes, normalized );
  92541. } else {
  92542. if ( bufferView === null ) {
  92543. array = new TypedArray( accessorDef.count * itemSize );
  92544. } else {
  92545. array = new TypedArray( bufferView, byteOffset, accessorDef.count * itemSize );
  92546. }
  92547. bufferAttribute = new BufferAttribute( array, itemSize, normalized );
  92548. }
  92549. // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#sparse-accessors
  92550. if ( accessorDef.sparse !== undefined ) {
  92551. const itemSizeIndices = WEBGL_TYPE_SIZES.SCALAR;
  92552. const TypedArrayIndices = WEBGL_COMPONENT_TYPES[ accessorDef.sparse.indices.componentType ];
  92553. const byteOffsetIndices = accessorDef.sparse.indices.byteOffset || 0;
  92554. const byteOffsetValues = accessorDef.sparse.values.byteOffset || 0;
  92555. const sparseIndices = new TypedArrayIndices( bufferViews[ 1 ], byteOffsetIndices, accessorDef.sparse.count * itemSizeIndices );
  92556. const sparseValues = new TypedArray( bufferViews[ 2 ], byteOffsetValues, accessorDef.sparse.count * itemSize );
  92557. if ( bufferView !== null ) {
  92558. // Avoid modifying the original ArrayBuffer, if the bufferView wasn't initialized with zeroes.
  92559. bufferAttribute = new BufferAttribute( bufferAttribute.array.slice(), bufferAttribute.itemSize, bufferAttribute.normalized );
  92560. }
  92561. for ( let i = 0, il = sparseIndices.length; i < il; i ++ ) {
  92562. const index = sparseIndices[ i ];
  92563. bufferAttribute.setX( index, sparseValues[ i * itemSize ] );
  92564. if ( itemSize >= 2 ) bufferAttribute.setY( index, sparseValues[ i * itemSize + 1 ] );
  92565. if ( itemSize >= 3 ) bufferAttribute.setZ( index, sparseValues[ i * itemSize + 2 ] );
  92566. if ( itemSize >= 4 ) bufferAttribute.setW( index, sparseValues[ i * itemSize + 3 ] );
  92567. if ( itemSize >= 5 ) throw new Error( 'THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.' );
  92568. }
  92569. }
  92570. return bufferAttribute;
  92571. } );
  92572. }
  92573. /**
  92574. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#textures
  92575. * @param {number} textureIndex
  92576. * @return {Promise<THREE.Texture>}
  92577. */
  92578. loadTexture( textureIndex ) {
  92579. const json = this.json;
  92580. const options = this.options;
  92581. const textureDef = json.textures[ textureIndex ];
  92582. const sourceIndex = textureDef.source;
  92583. const sourceDef = json.images[ sourceIndex ];
  92584. let loader = this.textureLoader;
  92585. if ( sourceDef.uri ) {
  92586. const handler = options.manager.getHandler( sourceDef.uri );
  92587. if ( handler !== null ) loader = handler;
  92588. }
  92589. return this.loadTextureImage( textureIndex, sourceIndex, loader );
  92590. }
  92591. loadTextureImage( textureIndex, sourceIndex, loader ) {
  92592. const parser = this;
  92593. const json = this.json;
  92594. const textureDef = json.textures[ textureIndex ];
  92595. const sourceDef = json.images[ sourceIndex ];
  92596. const cacheKey = ( sourceDef.uri || sourceDef.bufferView ) + ':' + textureDef.sampler;
  92597. if ( this.textureCache[ cacheKey ] ) {
  92598. // See https://github.com/mrdoob/three.js/issues/21559.
  92599. return this.textureCache[ cacheKey ];
  92600. }
  92601. const promise = this.loadImageSource( sourceIndex, loader ).then( function ( texture ) {
  92602. texture.flipY = false;
  92603. texture.name = textureDef.name || sourceDef.name || '';
  92604. const samplers = json.samplers || {};
  92605. const sampler = samplers[ textureDef.sampler ] || {};
  92606. Potree.Utils.makeTexDontResize(texture); //add
  92607. /* //xzw 删除设置,因为已经makeTexDontResize
  92608. texture.magFilter = WEBGL_FILTERS[ sampler.magFilter ] || LinearFilter;
  92609. texture.minFilter = WEBGL_FILTERS[ sampler.minFilter ] || LinearMipmapLinearFilter;
  92610. texture.wrapS = WEBGL_WRAPPINGS[ sampler.wrapS ] || RepeatWrapping;
  92611. texture.wrapT = WEBGL_WRAPPINGS[ sampler.wrapT ] || RepeatWrapping;
  92612. */
  92613. parser.associations.set( texture, { textures: textureIndex } );
  92614. return texture;
  92615. } ).catch( function () {
  92616. return null;
  92617. } );
  92618. this.textureCache[ cacheKey ] = promise;
  92619. return promise;
  92620. }
  92621. loadImageSource( sourceIndex, loader ) {
  92622. const parser = this;
  92623. const json = this.json;
  92624. const options = this.options;
  92625. if ( this.sourceCache[ sourceIndex ] !== undefined ) {
  92626. return this.sourceCache[ sourceIndex ].then( ( texture ) => texture.clone() );
  92627. }
  92628. const sourceDef = json.images[ sourceIndex ];
  92629. const URL = self.URL || self.webkitURL;
  92630. let sourceURI = sourceDef.uri || '';
  92631. let isObjectURL = false;
  92632. if ( sourceDef.bufferView !== undefined ) {
  92633. // Load binary image data from bufferView, if provided.
  92634. sourceURI = parser.getDependency( 'bufferView', sourceDef.bufferView ).then( function ( bufferView ) {
  92635. isObjectURL = true;
  92636. const blob = new Blob( [ bufferView ], { type: sourceDef.mimeType } );
  92637. sourceURI = URL.createObjectURL( blob );
  92638. return sourceURI;
  92639. } );
  92640. } else if ( sourceDef.uri === undefined ) {
  92641. throw new Error( 'THREE.GLTFLoader: Image ' + sourceIndex + ' is missing URI and bufferView' );
  92642. }
  92643. const promise = Promise.resolve( sourceURI ).then( function ( sourceURI ) {
  92644. return new Promise( function ( resolve, reject ) {
  92645. if(json.asset.generator == 'gltfpack 0.18'){ //4dkk场景的模型
  92646. let onLoad = resolve;
  92647. if ( loader.isImageBitmapLoader === true ) {
  92648. onLoad = function ( imageBitmap ) {
  92649. const texture = new Texture( imageBitmap );
  92650. texture.needsUpdate = true;
  92651. resolve( texture );
  92652. };
  92653. }
  92654. //loader.load( LoaderUtils.resolveURL( sourceURI, options.path ), onLoad, undefined, reject );
  92655. let url = parser.textureLoader.manager.resolveURL( sourceURI, options.path );
  92656. loader.load(url, onLoad, undefined, reject );
  92657. }else {
  92658. //为了防止chrome出现报错 The source image could not be decoded. 导致reject,重新写贴图加载方式: xzw //但不知道为何有的场景(如4dkk的)不成功
  92659. parser.textureLoader.load(sourceURI, (tex)=>{
  92660. THREE.LinearMipmapLinearFilter; //原本:NearestMipMapNearestFilter 闪烁 有一个block文件离远了有裂缝,只能使用LinearFilter,但是这样似乎更卡,且锯齿
  92661. /* tex.minFilter = THREE.LinearFilter
  92662. tex.generateMipmaps = false */
  92663. //console.log(tex.image.width, tex.image.height)
  92664. resolve(tex);
  92665. },null,(e)=>{
  92666. console.log('error load tex',e);
  92667. });
  92668. }
  92669. } );
  92670. } ).then( function ( texture ) {
  92671. // Clean up resources and configure Texture.
  92672. if ( isObjectURL === true ) {
  92673. URL.revokeObjectURL( sourceURI );
  92674. }
  92675. texture.userData = {};//xzw add
  92676. texture.userData.mimeType = sourceDef.mimeType || getImageURIMimeType( sourceDef.uri || sourceDef.mimeType );
  92677. return texture;
  92678. } ).catch( function ( error ) {
  92679. console.error( 'THREE.GLTFLoader: Couldn\'t load texture', sourceURI );
  92680. throw error;
  92681. } );
  92682. this.sourceCache[ sourceIndex ] = promise;
  92683. return promise;
  92684. }
  92685. /**
  92686. * Asynchronously assigns a texture to the given material parameters.
  92687. * @param {Object} materialParams
  92688. * @param {string} mapName
  92689. * @param {Object} mapDef
  92690. * @return {Promise<Texture>}
  92691. */
  92692. assignTexture( materialParams, mapName, mapDef, encoding ) {
  92693. const parser = this;
  92694. return this.getDependency( 'texture', mapDef.index ).then( function ( texture ) {
  92695. // Materials sample aoMap from UV set 1 and other maps from UV set 0 - this can't be configured
  92696. // However, we will copy UV set 0 to UV set 1 on demand for aoMap
  92697. if ( mapDef.texCoord !== undefined && mapDef.texCoord != 0 && ! ( mapName === 'aoMap' && mapDef.texCoord == 1 ) ) {
  92698. console.warn( 'THREE.GLTFLoader: Custom UV set ' + mapDef.texCoord + ' for texture ' + mapName + ' not yet supported.' );
  92699. }
  92700. if ( parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] ) {
  92701. const transform = mapDef.extensions !== undefined ? mapDef.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ] : undefined;
  92702. if ( transform ) {
  92703. const gltfReference = parser.associations.get( texture );
  92704. texture = parser.extensions[ EXTENSIONS.KHR_TEXTURE_TRANSFORM ].extendTexture( texture, transform );
  92705. parser.associations.set( texture, gltfReference );
  92706. }
  92707. }
  92708. if ( encoding !== undefined ) {
  92709. texture.encoding = encoding;
  92710. }
  92711. materialParams[ mapName ] = texture;
  92712. return texture;
  92713. } );
  92714. }
  92715. /**
  92716. * Assigns final material to a Mesh, Line, or Points instance. The instance
  92717. * already has a material (generated from the glTF material options alone)
  92718. * but reuse of the same glTF material may require multiple threejs materials
  92719. * to accommodate different primitive types, defines, etc. New materials will
  92720. * be created if necessary, and reused from a cache.
  92721. * @param {Object3D} mesh Mesh, Line, or Points instance.
  92722. */
  92723. assignFinalMaterial( mesh ) {
  92724. const geometry = mesh.geometry;
  92725. let material = mesh.material;
  92726. const useDerivativeTangents = geometry.attributes.tangent === undefined;
  92727. const useVertexColors = geometry.attributes.color !== undefined;
  92728. const useFlatShading = geometry.attributes.normal === undefined;
  92729. if ( mesh.isPoints ) {
  92730. const cacheKey = 'PointsMaterial:' + material.uuid;
  92731. let pointsMaterial = this.cache.get( cacheKey );
  92732. if ( ! pointsMaterial ) {
  92733. pointsMaterial = new PointsMaterial();
  92734. Material.prototype.copy.call( pointsMaterial, material );
  92735. pointsMaterial.color.copy( material.color );
  92736. pointsMaterial.map = material.map;
  92737. pointsMaterial.sizeAttenuation = false; // glTF spec says points should be 1px
  92738. this.cache.add( cacheKey, pointsMaterial );
  92739. }
  92740. material = pointsMaterial;
  92741. } else if ( mesh.isLine ) {
  92742. const cacheKey = 'LineBasicMaterial:' + material.uuid;
  92743. let lineMaterial = this.cache.get( cacheKey );
  92744. if ( ! lineMaterial ) {
  92745. lineMaterial = new LineBasicMaterial();
  92746. Material.prototype.copy.call( lineMaterial, material );
  92747. lineMaterial.color.copy( material.color );
  92748. this.cache.add( cacheKey, lineMaterial );
  92749. }
  92750. material = lineMaterial;
  92751. }
  92752. // Clone the material if it will be modified
  92753. if ( useDerivativeTangents || useVertexColors || useFlatShading ) {
  92754. let cacheKey = 'ClonedMaterial:' + material.uuid + ':';
  92755. if ( material.isGLTFSpecularGlossinessMaterial ) cacheKey += 'specular-glossiness:';
  92756. if ( useDerivativeTangents ) cacheKey += 'derivative-tangents:';
  92757. if ( useVertexColors ) cacheKey += 'vertex-colors:';
  92758. if ( useFlatShading ) cacheKey += 'flat-shading:';
  92759. let cachedMaterial = this.cache.get( cacheKey );
  92760. if ( ! cachedMaterial ) {
  92761. cachedMaterial = material.clone();
  92762. if ( useVertexColors ) cachedMaterial.vertexColors = true;
  92763. if ( useFlatShading ) cachedMaterial.flatShading = true;
  92764. if ( useDerivativeTangents ) {
  92765. // https://github.com/mrdoob/three.js/issues/11438#issuecomment-507003995
  92766. if ( cachedMaterial.normalScale ) cachedMaterial.normalScale.y *= - 1;
  92767. if ( cachedMaterial.clearcoatNormalScale ) cachedMaterial.clearcoatNormalScale.y *= - 1;
  92768. }
  92769. this.cache.add( cacheKey, cachedMaterial );
  92770. this.associations.set( cachedMaterial, this.associations.get( material ) );
  92771. }
  92772. material = cachedMaterial;
  92773. }
  92774. // workarounds for mesh and geometry
  92775. if ( material.aoMap && geometry.attributes.uv2 === undefined && geometry.attributes.uv !== undefined ) {
  92776. geometry.setAttribute( 'uv2', geometry.attributes.uv );
  92777. }
  92778. mesh.material = material;
  92779. }
  92780. getMaterialType( /* materialIndex */ ) {
  92781. return MeshStandardMaterial;
  92782. }
  92783. /**
  92784. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#materials
  92785. * @param {number} materialIndex
  92786. * @return {Promise<Material>}
  92787. */
  92788. loadMaterial( materialIndex ) {
  92789. const parser = this;
  92790. const json = this.json;
  92791. const extensions = this.extensions;
  92792. const materialDef = json.materials[ materialIndex ];
  92793. let materialType;
  92794. const materialParams = {};
  92795. const materialExtensions = materialDef.extensions || {};
  92796. const pending = [];
  92797. if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ] ) {
  92798. const sgExtension = extensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ];
  92799. materialType = BasicMaterial;//sgExtension.getMaterialType(); //xzw 改
  92800. pending.push( sgExtension.extendParams( materialParams, materialDef, parser ) );
  92801. } else if ( materialExtensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ] ) {
  92802. const kmuExtension = extensions[ EXTENSIONS.KHR_MATERIALS_UNLIT ];
  92803. materialType = BasicMaterial;//kmuExtension.getMaterialType(); //xzw 改
  92804. pending.push( kmuExtension.extendParams( materialParams, materialDef, parser ) );
  92805. } else {
  92806. // Specification:
  92807. // https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#metallic-roughness-material
  92808. const metallicRoughness = materialDef.pbrMetallicRoughness || {};
  92809. materialParams.color = new Color( 1.0, 1.0, 1.0 );
  92810. materialParams.opacity = 1.0;
  92811. if ( Array.isArray( metallicRoughness.baseColorFactor ) ) {
  92812. const array = metallicRoughness.baseColorFactor;
  92813. materialParams.color.fromArray( array );
  92814. materialParams.opacity = array[ 3 ];
  92815. }
  92816. if ( metallicRoughness.baseColorTexture !== undefined ) {
  92817. pending.push( parser.assignTexture( materialParams, 'map', metallicRoughness.baseColorTexture, sRGBEncoding ) );
  92818. }
  92819. materialParams.metalness = metallicRoughness.metallicFactor !== undefined ? metallicRoughness.metallicFactor : 1.0;
  92820. materialParams.roughness = metallicRoughness.roughnessFactor !== undefined ? metallicRoughness.roughnessFactor : 1.0;
  92821. if ( metallicRoughness.metallicRoughnessTexture !== undefined ) {
  92822. pending.push( parser.assignTexture( materialParams, 'metalnessMap', metallicRoughness.metallicRoughnessTexture ) );
  92823. pending.push( parser.assignTexture( materialParams, 'roughnessMap', metallicRoughness.metallicRoughnessTexture ) );
  92824. }
  92825. materialType = this._invokeOne( function ( ext ) {
  92826. //return BasicMaterial //2024.7放弃使用这个,因为纯色的看上去连成一片
  92827. //kmuExtension.getMaterialType(); //xzw 改
  92828. return ext.getMaterialType && ext.getMaterialType( materialIndex );
  92829. } );
  92830. pending.push( Promise.all( this._invokeAll( function ( ext ) {
  92831. return ext.extendMaterialParams && ext.extendMaterialParams( materialIndex, materialParams );
  92832. } ) ) );
  92833. }
  92834. if ( materialDef.doubleSided === true ) {
  92835. materialParams.side = DoubleSide;
  92836. }
  92837. const alphaMode = materialDef.alphaMode || ALPHA_MODES.OPAQUE;
  92838. if ( alphaMode === ALPHA_MODES.BLEND ) {
  92839. materialParams.transparent = true;
  92840. // See: https://github.com/mrdoob/three.js/issues/17706
  92841. materialParams.depthWrite = false;
  92842. } else {
  92843. materialParams.transparent = false;
  92844. if ( alphaMode === ALPHA_MODES.MASK ) {
  92845. materialParams.alphaTest = materialDef.alphaCutoff !== undefined ? materialDef.alphaCutoff : 0.5;
  92846. }
  92847. }
  92848. if ( materialDef.normalTexture !== undefined && materialType !== MeshBasicMaterial ) {
  92849. pending.push( parser.assignTexture( materialParams, 'normalMap', materialDef.normalTexture ) );
  92850. materialParams.normalScale = new Vector2( 1, 1 );
  92851. if ( materialDef.normalTexture.scale !== undefined ) {
  92852. const scale = materialDef.normalTexture.scale;
  92853. materialParams.normalScale.set( scale, scale );
  92854. }
  92855. }
  92856. if ( materialDef.occlusionTexture !== undefined && materialType !== MeshBasicMaterial ) {
  92857. pending.push( parser.assignTexture( materialParams, 'aoMap', materialDef.occlusionTexture ) );
  92858. if ( materialDef.occlusionTexture.strength !== undefined ) {
  92859. materialParams.aoMapIntensity = materialDef.occlusionTexture.strength;
  92860. }
  92861. }
  92862. if ( materialDef.emissiveFactor !== undefined && materialType !== MeshBasicMaterial ) {
  92863. materialParams.emissive = new Color().fromArray( materialDef.emissiveFactor );
  92864. }
  92865. if ( materialDef.emissiveTexture !== undefined && materialType !== MeshBasicMaterial ) {
  92866. pending.push( parser.assignTexture( materialParams, 'emissiveMap', materialDef.emissiveTexture, sRGBEncoding ) );
  92867. }
  92868. return Promise.all( pending ).then( function () {
  92869. let material;
  92870. if ( materialType === GLTFMeshStandardSGMaterial ) {
  92871. material = extensions[ EXTENSIONS.KHR_MATERIALS_PBR_SPECULAR_GLOSSINESS ].createMaterial( materialParams );
  92872. } else {
  92873. material = new materialType( materialParams );
  92874. }
  92875. if ( materialDef.name ) material.name = materialDef.name;
  92876. assignExtrasToUserData( material, materialDef );
  92877. parser.associations.set( material, { materials: materialIndex } );
  92878. if ( materialDef.extensions ) addUnknownExtensionsToUserData( extensions, material, materialDef );
  92879. return material;
  92880. } );
  92881. }
  92882. /** When Object3D instances are targeted by animation, they need unique names. */
  92883. createUniqueName( originalName ) {
  92884. const sanitizedName = PropertyBinding.sanitizeNodeName( originalName || '' );
  92885. let name = sanitizedName;
  92886. for ( let i = 1; this.nodeNamesUsed[ name ]; ++ i ) {
  92887. name = sanitizedName + '_' + i;
  92888. }
  92889. this.nodeNamesUsed[ name ] = true;
  92890. return name;
  92891. }
  92892. /**
  92893. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#geometry
  92894. *
  92895. * Creates BufferGeometries from primitives.
  92896. *
  92897. * @param {Array<GLTF.Primitive>} primitives
  92898. * @return {Promise<Array<BufferGeometry>>}
  92899. */
  92900. loadGeometries( primitives ) {
  92901. const parser = this;
  92902. const extensions = this.extensions;
  92903. const cache = this.primitiveCache;
  92904. function createDracoPrimitive( primitive ) {
  92905. return extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ]
  92906. .decodePrimitive( primitive, parser )
  92907. .then( function ( geometry ) {
  92908. return addPrimitiveAttributes( geometry, primitive, parser );
  92909. } );
  92910. }
  92911. const pending = [];
  92912. for ( let i = 0, il = primitives.length; i < il; i ++ ) {
  92913. const primitive = primitives[ i ];
  92914. const cacheKey = createPrimitiveKey( primitive );
  92915. // See if we've already created this geometry
  92916. const cached = cache[ cacheKey ];
  92917. if ( cached ) {
  92918. // Use the cached geometry if it exists
  92919. pending.push( cached.promise );
  92920. } else {
  92921. let geometryPromise;
  92922. if ( primitive.extensions && primitive.extensions[ EXTENSIONS.KHR_DRACO_MESH_COMPRESSION ] ) {
  92923. // Use DRACO geometry if available
  92924. geometryPromise = createDracoPrimitive( primitive );
  92925. } else {
  92926. // Otherwise create a new geometry
  92927. geometryPromise = addPrimitiveAttributes( new BufferGeometry(), primitive, parser );
  92928. }
  92929. // Cache this geometry
  92930. cache[ cacheKey ] = { primitive: primitive, promise: geometryPromise };
  92931. pending.push( geometryPromise );
  92932. }
  92933. }
  92934. return Promise.all( pending );
  92935. }
  92936. /**
  92937. * Specification: https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/README.md#meshes
  92938. * @param {number} meshIndex
  92939. * @return {Promise<Group|Mesh|SkinnedMesh>}
  92940. */
  92941. loadMesh( meshIndex ) {
  92942. const parser = this;
  92943. const json = this.json;
  92944. const extensions = this.extensions;
  92945. const meshDef = json.meshes[ meshIndex ];
  92946. const primitives = meshDef.primitives;
  92947. const pending = [];
  92948. for ( let i = 0, il = primitives.length; i < il; i ++ ) {
  92949. const material = primitives[ i ].material === undefined
  92950. ? createDefaultMaterial( this.cache )
  92951. : this.getDependency( 'material', primitives[ i ].material );
  92952. pending.push( material );
  92953. }
  92954. pending.push( parser.loadGeometries( primitives ) );
  92955. return Promise.all( pending ).then( function ( results ) {
  92956. const materials = results.slice( 0, results.length - 1 );
  92957. const geometries = results[ results.length - 1 ];
  92958. const meshes = [];
  92959. for ( let i = 0, il = geometries.length; i < il; i ++ ) {
  92960. const geometry = geometries[ i ];
  92961. const primitive = primitives[ i ];
  92962. // 1. create Mesh
  92963. let mesh;
  92964. const material = materials[ i ];
  92965. if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLES ||
  92966. primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ||
  92967. primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ||
  92968. primitive.mode === undefined ) {
  92969. // .isSkinnedMesh isn't in glTF spec. See ._markDefs()
  92970. mesh = meshDef.isSkinnedMesh === true
  92971. ? new SkinnedMesh( geometry, material )
  92972. : new Mesh( geometry, material );
  92973. if ( mesh.isSkinnedMesh === true && ! mesh.geometry.attributes.skinWeight.normalized ) {
  92974. // we normalize floating point skin weight array to fix malformed assets (see #15319)
  92975. // it's important to skip this for non-float32 data since normalizeSkinWeights assumes non-normalized inputs
  92976. mesh.normalizeSkinWeights();
  92977. }
  92978. if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_STRIP ) {
  92979. mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleStripDrawMode );
  92980. } else if ( primitive.mode === WEBGL_CONSTANTS.TRIANGLE_FAN ) {
  92981. mesh.geometry = toTrianglesDrawMode( mesh.geometry, TriangleFanDrawMode );
  92982. }
  92983. } else if ( primitive.mode === WEBGL_CONSTANTS.LINES ) {
  92984. mesh = new LineSegments( geometry, material );
  92985. } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_STRIP ) {
  92986. mesh = new Line( geometry, material );
  92987. } else if ( primitive.mode === WEBGL_CONSTANTS.LINE_LOOP ) {
  92988. mesh = new LineLoop( geometry, material );
  92989. } else if ( primitive.mode === WEBGL_CONSTANTS.POINTS ) {
  92990. mesh = new Points( geometry, material );
  92991. } else {
  92992. throw new Error( 'THREE.GLTFLoader: Primitive mode unsupported: ' + primitive.mode );
  92993. }
  92994. if ( Object.keys( mesh.geometry.morphAttributes ).length > 0 ) {
  92995. updateMorphTargets( mesh, meshDef );
  92996. }
  92997. mesh.name = parser.createUniqueName( meshDef.name || ( 'mesh_' + meshIndex ) );
  92998. assignExtrasToUserData( mesh, meshDef );
  92999. if ( primitive.extensions ) addUnknownExtensionsToUserData( extensions, mesh, primitive );
  93000. parser.assignFinalMaterial( mesh );
  93001. meshes.push( mesh );
  93002. }
  93003. for ( let i = 0, il = meshes.length; i < il; i ++ ) {
  93004. parser.associations.set( meshes[ i ], {
  93005. meshes: meshIndex,
  93006. primitives: i
  93007. } );
  93008. }
  93009. if ( meshes.length === 1 ) {
  93010. return meshes[ 0 ];
  93011. }
  93012. const group = new Group();
  93013. parser.associations.set( group, { meshes: meshIndex } );
  93014. for ( let i = 0, il = meshes.length; i < il; i ++ ) {
  93015. group.add( meshes[ i ] );
  93016. }
  93017. return group;
  93018. } );
  93019. }
  93020. /**
  93021. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#cameras
  93022. * @param {number} cameraIndex
  93023. * @return {Promise<THREE.Camera>}
  93024. */
  93025. loadCamera( cameraIndex ) {
  93026. let camera;
  93027. const cameraDef = this.json.cameras[ cameraIndex ];
  93028. const params = cameraDef[ cameraDef.type ];
  93029. if ( ! params ) {
  93030. console.warn( 'THREE.GLTFLoader: Missing camera parameters.' );
  93031. return;
  93032. }
  93033. if ( cameraDef.type === 'perspective' ) {
  93034. camera = new PerspectiveCamera( MathUtils.radToDeg( params.yfov ), params.aspectRatio || 1, params.znear || 1, params.zfar || 2e6 );
  93035. } else if ( cameraDef.type === 'orthographic' ) {
  93036. camera = new OrthographicCamera( - params.xmag, params.xmag, params.ymag, - params.ymag, params.znear, params.zfar );
  93037. }
  93038. if ( cameraDef.name ) camera.name = this.createUniqueName( cameraDef.name );
  93039. assignExtrasToUserData( camera, cameraDef );
  93040. return Promise.resolve( camera );
  93041. }
  93042. /**
  93043. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#skins
  93044. * @param {number} skinIndex
  93045. * @return {Promise<Object>}
  93046. */
  93047. loadSkin( skinIndex ) {
  93048. const skinDef = this.json.skins[ skinIndex ];
  93049. const skinEntry = { joints: skinDef.joints };
  93050. if ( skinDef.inverseBindMatrices === undefined ) {
  93051. return Promise.resolve( skinEntry );
  93052. }
  93053. return this.getDependency( 'accessor', skinDef.inverseBindMatrices ).then( function ( accessor ) {
  93054. skinEntry.inverseBindMatrices = accessor;
  93055. return skinEntry;
  93056. } );
  93057. }
  93058. /**
  93059. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#animations
  93060. * @param {number} animationIndex
  93061. * @return {Promise<AnimationClip>}
  93062. */
  93063. loadAnimation( animationIndex ) {
  93064. const json = this.json;
  93065. const animationDef = json.animations[ animationIndex ];
  93066. const pendingNodes = [];
  93067. const pendingInputAccessors = [];
  93068. const pendingOutputAccessors = [];
  93069. const pendingSamplers = [];
  93070. const pendingTargets = [];
  93071. for ( let i = 0, il = animationDef.channels.length; i < il; i ++ ) {
  93072. const channel = animationDef.channels[ i ];
  93073. const sampler = animationDef.samplers[ channel.sampler ];
  93074. const target = channel.target;
  93075. const name = target.node;
  93076. const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
  93077. const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
  93078. pendingNodes.push( this.getDependency( 'node', name ) );
  93079. pendingInputAccessors.push( this.getDependency( 'accessor', input ) );
  93080. pendingOutputAccessors.push( this.getDependency( 'accessor', output ) );
  93081. pendingSamplers.push( sampler );
  93082. pendingTargets.push( target );
  93083. }
  93084. return Promise.all( [
  93085. Promise.all( pendingNodes ),
  93086. Promise.all( pendingInputAccessors ),
  93087. Promise.all( pendingOutputAccessors ),
  93088. Promise.all( pendingSamplers ),
  93089. Promise.all( pendingTargets )
  93090. ] ).then( function ( dependencies ) {
  93091. const nodes = dependencies[ 0 ];
  93092. const inputAccessors = dependencies[ 1 ];
  93093. const outputAccessors = dependencies[ 2 ];
  93094. const samplers = dependencies[ 3 ];
  93095. const targets = dependencies[ 4 ];
  93096. const tracks = [];
  93097. for ( let i = 0, il = nodes.length; i < il; i ++ ) {
  93098. const node = nodes[ i ];
  93099. const inputAccessor = inputAccessors[ i ];
  93100. const outputAccessor = outputAccessors[ i ];
  93101. const sampler = samplers[ i ];
  93102. const target = targets[ i ];
  93103. if ( node === undefined ) continue;
  93104. node.updateMatrix();
  93105. let TypedKeyframeTrack;
  93106. switch ( PATH_PROPERTIES[ target.path ] ) {
  93107. case PATH_PROPERTIES.weights:
  93108. TypedKeyframeTrack = NumberKeyframeTrack;
  93109. break;
  93110. case PATH_PROPERTIES.rotation:
  93111. TypedKeyframeTrack = QuaternionKeyframeTrack;
  93112. break;
  93113. case PATH_PROPERTIES.position:
  93114. case PATH_PROPERTIES.scale:
  93115. default:
  93116. TypedKeyframeTrack = VectorKeyframeTrack;
  93117. break;
  93118. }
  93119. const targetName = node.name ? node.name : node.uuid;
  93120. const interpolation = sampler.interpolation !== undefined ? INTERPOLATION[ sampler.interpolation ] : InterpolateLinear;
  93121. const targetNames = [];
  93122. if ( PATH_PROPERTIES[ target.path ] === PATH_PROPERTIES.weights ) {
  93123. node.traverse( function ( object ) {
  93124. if ( object.morphTargetInfluences ) {
  93125. targetNames.push( object.name ? object.name : object.uuid );
  93126. }
  93127. } );
  93128. } else {
  93129. targetNames.push( targetName );
  93130. }
  93131. let outputArray = outputAccessor.array;
  93132. if ( outputAccessor.normalized ) {
  93133. const scale = getNormalizedComponentScale( outputArray.constructor );
  93134. const scaled = new Float32Array( outputArray.length );
  93135. for ( let j = 0, jl = outputArray.length; j < jl; j ++ ) {
  93136. scaled[ j ] = outputArray[ j ] * scale;
  93137. }
  93138. outputArray = scaled;
  93139. }
  93140. for ( let j = 0, jl = targetNames.length; j < jl; j ++ ) {
  93141. const track = new TypedKeyframeTrack(
  93142. targetNames[ j ] + '.' + PATH_PROPERTIES[ target.path ],
  93143. inputAccessor.array,
  93144. outputArray,
  93145. interpolation
  93146. );
  93147. // Override interpolation with custom factory method.
  93148. if ( sampler.interpolation === 'CUBICSPLINE' ) {
  93149. track.createInterpolant = function InterpolantFactoryMethodGLTFCubicSpline( result ) {
  93150. // A CUBICSPLINE keyframe in glTF has three output values for each input value,
  93151. // representing inTangent, splineVertex, and outTangent. As a result, track.getValueSize()
  93152. // must be divided by three to get the interpolant's sampleSize argument.
  93153. const interpolantType = ( this instanceof QuaternionKeyframeTrack ) ? GLTFCubicSplineQuaternionInterpolant : GLTFCubicSplineInterpolant;
  93154. return new interpolantType( this.times, this.values, this.getValueSize() / 3, result );
  93155. };
  93156. // Mark as CUBICSPLINE. `track.getInterpolation()` doesn't support custom interpolants.
  93157. track.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline = true;
  93158. }
  93159. tracks.push( track );
  93160. }
  93161. }
  93162. const name = animationDef.name ? animationDef.name : 'animation_' + animationIndex;
  93163. return new AnimationClip( name, undefined, tracks );
  93164. } );
  93165. }
  93166. createNodeMesh( nodeIndex ) {
  93167. const json = this.json;
  93168. const parser = this;
  93169. const nodeDef = json.nodes[ nodeIndex ];
  93170. if ( nodeDef.mesh === undefined ) return null;
  93171. return parser.getDependency( 'mesh', nodeDef.mesh ).then( function ( mesh ) {
  93172. const node = parser._getNodeRef( parser.meshCache, nodeDef.mesh, mesh );
  93173. // if weights are provided on the node, override weights on the mesh.
  93174. if ( nodeDef.weights !== undefined ) {
  93175. node.traverse( function ( o ) {
  93176. if ( ! o.isMesh ) return;
  93177. for ( let i = 0, il = nodeDef.weights.length; i < il; i ++ ) {
  93178. o.morphTargetInfluences[ i ] = nodeDef.weights[ i ];
  93179. }
  93180. } );
  93181. }
  93182. return node;
  93183. } );
  93184. }
  93185. /**
  93186. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#nodes-and-hierarchy
  93187. * @param {number} nodeIndex
  93188. * @return {Promise<Object3D>}
  93189. */
  93190. loadNode( nodeIndex ) {
  93191. const json = this.json;
  93192. const extensions = this.extensions;
  93193. const parser = this;
  93194. const nodeDef = json.nodes[ nodeIndex ];
  93195. // reserve node's name before its dependencies, so the root has the intended name.
  93196. const nodeName = nodeDef.name ? parser.createUniqueName( nodeDef.name ) : '';
  93197. return ( function () {
  93198. const pending = [];
  93199. const meshPromise = parser._invokeOne( function ( ext ) {
  93200. return ext.createNodeMesh && ext.createNodeMesh( nodeIndex );
  93201. } );
  93202. if ( meshPromise ) {
  93203. pending.push( meshPromise );
  93204. }
  93205. if ( nodeDef.camera !== undefined ) {
  93206. pending.push( parser.getDependency( 'camera', nodeDef.camera ).then( function ( camera ) {
  93207. return parser._getNodeRef( parser.cameraCache, nodeDef.camera, camera );
  93208. } ) );
  93209. }
  93210. parser._invokeAll( function ( ext ) {
  93211. return ext.createNodeAttachment && ext.createNodeAttachment( nodeIndex );
  93212. } ).forEach( function ( promise ) {
  93213. pending.push( promise );
  93214. } );
  93215. return Promise.all( pending );
  93216. }() ).then( function ( objects ) {
  93217. let node;
  93218. // .isBone isn't in glTF spec. See ._markDefs
  93219. if ( nodeDef.isBone === true ) {
  93220. node = new Bone();
  93221. } else if ( objects.length > 1 ) {
  93222. node = new Group();
  93223. } else if ( objects.length === 1 ) {
  93224. node = objects[ 0 ];
  93225. } else {
  93226. node = new Object3D();
  93227. }
  93228. if ( node !== objects[ 0 ] ) {
  93229. for ( let i = 0, il = objects.length; i < il; i ++ ) {
  93230. node.add( objects[ i ] );
  93231. }
  93232. }
  93233. if ( nodeDef.name ) {
  93234. node.userData.name = nodeDef.name;
  93235. node.name = nodeName;
  93236. }
  93237. assignExtrasToUserData( node, nodeDef );
  93238. if ( nodeDef.extensions ) addUnknownExtensionsToUserData( extensions, node, nodeDef );
  93239. if ( nodeDef.matrix !== undefined ) {
  93240. const matrix = new Matrix4();
  93241. matrix.fromArray( nodeDef.matrix );
  93242. node.applyMatrix4( matrix );
  93243. } else {
  93244. if ( nodeDef.translation !== undefined ) {
  93245. node.position.fromArray( nodeDef.translation );
  93246. }
  93247. if ( nodeDef.rotation !== undefined ) {
  93248. node.quaternion.fromArray( nodeDef.rotation );
  93249. }
  93250. if ( nodeDef.scale !== undefined ) {
  93251. node.scale.fromArray( nodeDef.scale );
  93252. }
  93253. }
  93254. if ( ! parser.associations.has( node ) ) {
  93255. parser.associations.set( node, {} );
  93256. }
  93257. parser.associations.get( node ).nodes = nodeIndex;
  93258. return node;
  93259. } );
  93260. }
  93261. /**
  93262. * Specification: https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#scenes
  93263. * @param {number} sceneIndex
  93264. * @return {Promise<Group>}
  93265. */
  93266. loadScene( sceneIndex ) {
  93267. const json = this.json;
  93268. const extensions = this.extensions;
  93269. const sceneDef = this.json.scenes[ sceneIndex ];
  93270. const parser = this;
  93271. // Loader returns Group, not Scene.
  93272. // See: https://github.com/mrdoob/three.js/issues/18342#issuecomment-578981172
  93273. const scene = new Group();
  93274. if ( sceneDef.name ) scene.name = parser.createUniqueName( sceneDef.name );
  93275. assignExtrasToUserData( scene, sceneDef );
  93276. if ( sceneDef.extensions ) addUnknownExtensionsToUserData( extensions, scene, sceneDef );
  93277. const nodeIds = sceneDef.nodes || [];
  93278. const pending = [];
  93279. for ( let i = 0, il = nodeIds.length; i < il; i ++ ) {
  93280. pending.push( buildNodeHierarchy( nodeIds[ i ], scene, json, parser ) );
  93281. }
  93282. return Promise.all( pending ).then( function () {
  93283. // Removes dangling associations, associations that reference a node that
  93284. // didn't make it into the scene.
  93285. const reduceAssociations = ( node ) => {
  93286. const reducedAssociations = new Map();
  93287. for ( const [ key, value ] of parser.associations ) {
  93288. if ( key instanceof Material || key instanceof Texture ) {
  93289. reducedAssociations.set( key, value );
  93290. }
  93291. }
  93292. node.traverse( ( node ) => {
  93293. const mappings = parser.associations.get( node );
  93294. if ( mappings != null ) {
  93295. reducedAssociations.set( node, mappings );
  93296. }
  93297. } );
  93298. return reducedAssociations;
  93299. };
  93300. parser.associations = reduceAssociations( scene );
  93301. return scene;
  93302. } );
  93303. }
  93304. }
  93305. function buildNodeHierarchy( nodeId, parentObject, json, parser ) {
  93306. const nodeDef = json.nodes[ nodeId ];
  93307. return parser.getDependency( 'node', nodeId ).then( function ( node ) {
  93308. if ( nodeDef.skin === undefined ) return node;
  93309. // build skeleton here as well
  93310. let skinEntry;
  93311. return parser.getDependency( 'skin', nodeDef.skin ).then( function ( skin ) {
  93312. skinEntry = skin;
  93313. const pendingJoints = [];
  93314. for ( let i = 0, il = skinEntry.joints.length; i < il; i ++ ) {
  93315. pendingJoints.push( parser.getDependency( 'node', skinEntry.joints[ i ] ) );
  93316. }
  93317. return Promise.all( pendingJoints );
  93318. } ).then( function ( jointNodes ) {
  93319. node.traverse( function ( mesh ) {
  93320. if ( ! mesh.isMesh ) return;
  93321. const bones = [];
  93322. const boneInverses = [];
  93323. for ( let j = 0, jl = jointNodes.length; j < jl; j ++ ) {
  93324. const jointNode = jointNodes[ j ];
  93325. if ( jointNode ) {
  93326. bones.push( jointNode );
  93327. const mat = new Matrix4();
  93328. if ( skinEntry.inverseBindMatrices !== undefined ) {
  93329. mat.fromArray( skinEntry.inverseBindMatrices.array, j * 16 );
  93330. }
  93331. boneInverses.push( mat );
  93332. } else {
  93333. console.warn( 'THREE.GLTFLoader: Joint "%s" could not be found.', skinEntry.joints[ j ] );
  93334. }
  93335. }
  93336. mesh.bind( new Skeleton( bones, boneInverses ), mesh.matrixWorld );
  93337. } );
  93338. return node;
  93339. } );
  93340. } ).then( function ( node ) {
  93341. // build node hierachy
  93342. parentObject.add( node );
  93343. const pending = [];
  93344. if ( nodeDef.children ) {
  93345. const children = nodeDef.children;
  93346. for ( let i = 0, il = children.length; i < il; i ++ ) {
  93347. const child = children[ i ];
  93348. pending.push( buildNodeHierarchy( child, node, json, parser ) );
  93349. }
  93350. }
  93351. return Promise.all( pending );
  93352. } );
  93353. }
  93354. /**
  93355. * @param {BufferGeometry} geometry
  93356. * @param {GLTF.Primitive} primitiveDef
  93357. * @param {GLTFParser} parser
  93358. */
  93359. function computeBounds( geometry, primitiveDef, parser ) {
  93360. const attributes = primitiveDef.attributes;
  93361. const box = new Box3();
  93362. if ( attributes.POSITION !== undefined ) {
  93363. const accessor = parser.json.accessors[ attributes.POSITION ];
  93364. const min = accessor.min;
  93365. const max = accessor.max;
  93366. // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
  93367. if ( min !== undefined && max !== undefined ) {
  93368. box.set(
  93369. new Vector3( min[ 0 ], min[ 1 ], min[ 2 ] ),
  93370. new Vector3( max[ 0 ], max[ 1 ], max[ 2 ] )
  93371. );
  93372. if ( accessor.normalized ) {
  93373. const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
  93374. box.min.multiplyScalar( boxScale );
  93375. box.max.multiplyScalar( boxScale );
  93376. }
  93377. } else {
  93378. console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
  93379. return;
  93380. }
  93381. } else {
  93382. return;
  93383. }
  93384. const targets = primitiveDef.targets;
  93385. if ( targets !== undefined ) {
  93386. const maxDisplacement = new Vector3();
  93387. const vector = new Vector3();
  93388. for ( let i = 0, il = targets.length; i < il; i ++ ) {
  93389. const target = targets[ i ];
  93390. if ( target.POSITION !== undefined ) {
  93391. const accessor = parser.json.accessors[ target.POSITION ];
  93392. const min = accessor.min;
  93393. const max = accessor.max;
  93394. // glTF requires 'min' and 'max', but VRM (which extends glTF) currently ignores that requirement.
  93395. if ( min !== undefined && max !== undefined ) {
  93396. // we need to get max of absolute components because target weight is [-1,1]
  93397. vector.setX( Math.max( Math.abs( min[ 0 ] ), Math.abs( max[ 0 ] ) ) );
  93398. vector.setY( Math.max( Math.abs( min[ 1 ] ), Math.abs( max[ 1 ] ) ) );
  93399. vector.setZ( Math.max( Math.abs( min[ 2 ] ), Math.abs( max[ 2 ] ) ) );
  93400. if ( accessor.normalized ) {
  93401. const boxScale = getNormalizedComponentScale( WEBGL_COMPONENT_TYPES[ accessor.componentType ] );
  93402. vector.multiplyScalar( boxScale );
  93403. }
  93404. // Note: this assumes that the sum of all weights is at most 1. This isn't quite correct - it's more conservative
  93405. // to assume that each target can have a max weight of 1. However, for some use cases - notably, when morph targets
  93406. // are used to implement key-frame animations and as such only two are active at a time - this results in very large
  93407. // boxes. So for now we make a box that's sometimes a touch too small but is hopefully mostly of reasonable size.
  93408. maxDisplacement.max( vector );
  93409. } else {
  93410. console.warn( 'THREE.GLTFLoader: Missing min/max properties for accessor POSITION.' );
  93411. }
  93412. }
  93413. }
  93414. // As per comment above this box isn't conservative, but has a reasonable size for a very large number of morph targets.
  93415. box.expandByVector( maxDisplacement );
  93416. }
  93417. geometry.boundingBox = box;
  93418. const sphere = new Sphere();
  93419. box.getCenter( sphere.center );
  93420. sphere.radius = box.min.distanceTo( box.max ) / 2;
  93421. geometry.boundingSphere = sphere;
  93422. }
  93423. /**
  93424. * @param {BufferGeometry} geometry
  93425. * @param {GLTF.Primitive} primitiveDef
  93426. * @param {GLTFParser} parser
  93427. * @return {Promise<BufferGeometry>}
  93428. */
  93429. function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
  93430. const attributes = primitiveDef.attributes;
  93431. const pending = [];
  93432. function assignAttributeAccessor( accessorIndex, attributeName ) {
  93433. return parser.getDependency( 'accessor', accessorIndex )
  93434. .then( function ( accessor ) {
  93435. geometry.setAttribute( attributeName, accessor );
  93436. } );
  93437. }
  93438. for ( const gltfAttributeName in attributes ) {
  93439. const threeAttributeName = ATTRIBUTES[ gltfAttributeName ] || gltfAttributeName.toLowerCase();
  93440. // Skip attributes already provided by e.g. Draco extension.
  93441. if ( threeAttributeName in geometry.attributes ) continue;
  93442. pending.push( assignAttributeAccessor( attributes[ gltfAttributeName ], threeAttributeName ) );
  93443. }
  93444. if ( primitiveDef.indices !== undefined && ! geometry.index ) {
  93445. const accessor = parser.getDependency( 'accessor', primitiveDef.indices ).then( function ( accessor ) {
  93446. geometry.setIndex( accessor );
  93447. } );
  93448. pending.push( accessor );
  93449. }
  93450. assignExtrasToUserData( geometry, primitiveDef );
  93451. computeBounds( geometry, primitiveDef, parser );
  93452. return Promise.all( pending ).then( function () {
  93453. return primitiveDef.targets !== undefined
  93454. ? addMorphTargets( geometry, primitiveDef.targets, parser )
  93455. : geometry;
  93456. } );
  93457. }
  93458. /**
  93459. * @param {BufferGeometry} geometry
  93460. * @param {Number} drawMode
  93461. * @return {BufferGeometry}
  93462. */
  93463. function toTrianglesDrawMode( geometry, drawMode ) {
  93464. let index = geometry.getIndex();
  93465. // generate index if not present
  93466. if ( index === null ) {
  93467. const indices = [];
  93468. const position = geometry.getAttribute( 'position' );
  93469. if ( position !== undefined ) {
  93470. for ( let i = 0; i < position.count; i ++ ) {
  93471. indices.push( i );
  93472. }
  93473. geometry.setIndex( indices );
  93474. index = geometry.getIndex();
  93475. } else {
  93476. console.error( 'THREE.GLTFLoader.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.' );
  93477. return geometry;
  93478. }
  93479. }
  93480. //
  93481. const numberOfTriangles = index.count - 2;
  93482. const newIndices = [];
  93483. if ( drawMode === TriangleFanDrawMode ) {
  93484. // gl.TRIANGLE_FAN
  93485. for ( let i = 1; i <= numberOfTriangles; i ++ ) {
  93486. newIndices.push( index.getX( 0 ) );
  93487. newIndices.push( index.getX( i ) );
  93488. newIndices.push( index.getX( i + 1 ) );
  93489. }
  93490. } else {
  93491. // gl.TRIANGLE_STRIP
  93492. for ( let i = 0; i < numberOfTriangles; i ++ ) {
  93493. if ( i % 2 === 0 ) {
  93494. newIndices.push( index.getX( i ) );
  93495. newIndices.push( index.getX( i + 1 ) );
  93496. newIndices.push( index.getX( i + 2 ) );
  93497. } else {
  93498. newIndices.push( index.getX( i + 2 ) );
  93499. newIndices.push( index.getX( i + 1 ) );
  93500. newIndices.push( index.getX( i ) );
  93501. }
  93502. }
  93503. }
  93504. if ( ( newIndices.length / 3 ) !== numberOfTriangles ) {
  93505. console.error( 'THREE.GLTFLoader.toTrianglesDrawMode(): Unable to generate correct amount of triangles.' );
  93506. }
  93507. // build final geometry
  93508. const newGeometry = geometry.clone();
  93509. newGeometry.setIndex( newIndices );
  93510. return newGeometry;
  93511. }
  93512. let globalThis = window; //add 有的app没有globalThis. 2023.1
  93513. let rtcCenterGlobal = false;//默认false,也就是scale.z要乘以-1
  93514. /*! *****************************************************************************
  93515. github: https://github.com/nytimes/three-loader-3dtiles
  93516. Copyright (c) Microsoft Corporation.
  93517. Permission to use, copy, modify, and/or distribute this software for any
  93518. purpose with or without fee is hereby granted.
  93519. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
  93520. REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  93521. AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
  93522. INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  93523. LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  93524. OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  93525. PERFORMANCE OF THIS SOFTWARE.
  93526. ***************************************************************************** */
  93527. let visiGeoCount = 0;
  93528. const maxVertexVisi = 5e6;
  93529. const maxTexVisi = 500;
  93530. let maxDepth = 100;
  93531. function getGpuMemoryUsage(win = window){//总的
  93532. let c = 0;
  93533. viewer.objs.children.filter(e=>{
  93534. if(e.fileType == '3dTiles'){
  93535. e.traverse(child=>{
  93536. if(child.runtime){
  93537. let tileset3D = child.runtime.getTileset();
  93538. c += tileset3D.gpuMemoryUsageInBytes;
  93539. return {stopContinue:true}
  93540. }
  93541. });
  93542. }
  93543. });
  93544. if(win.parent != win){//还有父级页面。 暂时只有子级需要考虑父级,假设父级在前台时子级已经销毁
  93545. c += getGpuMemoryUsage(win.parent);
  93546. }
  93547. viewer.tiles3dMemoryUsage = c;
  93548. return c
  93549. }
  93550. function __awaiter(thisArg, _arguments, P, generator) {
  93551. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  93552. return new (P || (P = Promise))(function (resolve, reject) {
  93553. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  93554. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  93555. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  93556. step((generator = generator.apply(thisArg, _arguments || [])).next());
  93557. });
  93558. }
  93559. function assert$7(condition, message) {
  93560. if (!condition) {
  93561. throw new Error(message || 'loader assertion failed.');
  93562. }
  93563. }
  93564. const isBrowser$2 = Boolean(typeof process !== 'object' || String(process) !== '[object process]' || process.browser);
  93565. const matches$1 = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
  93566. matches$1 && parseFloat(matches$1[1]) || 0;
  93567. const VERSION$8 = "3.1.4" ;
  93568. function assert$6(condition, message) {
  93569. if (!condition) {
  93570. throw new Error(message || 'loaders.gl assertion failed.');
  93571. }
  93572. }
  93573. const globals$1 = {
  93574. self: typeof self !== 'undefined' && self,
  93575. window: typeof window !== 'undefined' && window,
  93576. global: typeof global !== 'undefined' && global,
  93577. document: typeof document !== 'undefined' && document
  93578. };
  93579. const global_ = globals$1.global || globals$1.self || globals$1.window || {};
  93580. const isBrowser$1 = typeof process !== 'object' || String(process) !== '[object process]' || process.browser;
  93581. const isWorker = typeof importScripts === 'function';
  93582. const isMobile = typeof window !== 'undefined' && typeof window.orientation !== 'undefined';
  93583. const matches = typeof process !== 'undefined' && process.version && /v([0-9]*)/.exec(process.version);
  93584. matches && parseFloat(matches[1]) || 0;
  93585. function _defineProperty(obj, key, value) {
  93586. if (key in obj) {
  93587. Object.defineProperty(obj, key, {
  93588. value: value,
  93589. enumerable: true,
  93590. configurable: true,
  93591. writable: true
  93592. });
  93593. } else {
  93594. obj[key] = value;
  93595. }
  93596. return obj;
  93597. }
  93598. class WorkerJob {
  93599. constructor(jobName, workerThread) {
  93600. _defineProperty(this, "name", void 0);
  93601. _defineProperty(this, "workerThread", void 0);
  93602. _defineProperty(this, "isRunning", void 0);
  93603. _defineProperty(this, "result", void 0);
  93604. _defineProperty(this, "_resolve", void 0);
  93605. _defineProperty(this, "_reject", void 0);
  93606. this.name = jobName;
  93607. this.workerThread = workerThread;
  93608. this.isRunning = true;
  93609. this._resolve = () => {};
  93610. this._reject = () => {};
  93611. this.result = new Promise((resolve, reject) => {
  93612. this._resolve = resolve;
  93613. this._reject = reject;
  93614. });
  93615. }
  93616. postMessage(type, payload) {
  93617. this.workerThread.postMessage({
  93618. source: 'loaders.gl',
  93619. type,
  93620. payload
  93621. });
  93622. }
  93623. done(value) {
  93624. assert$6(this.isRunning);
  93625. this.isRunning = false;
  93626. this._resolve(value);
  93627. }
  93628. error(error) {
  93629. assert$6(this.isRunning);
  93630. this.isRunning = false;
  93631. this._reject(error);
  93632. }
  93633. }
  93634. const workerURLCache = new Map();
  93635. function getLoadableWorkerURL(props) {
  93636. assert$6(props.source && !props.url || !props.source && props.url);
  93637. let workerURL = workerURLCache.get(props.source || props.url);
  93638. if (!workerURL) {
  93639. if (props.url) {
  93640. workerURL = getLoadableWorkerURLFromURL(props.url);
  93641. workerURLCache.set(props.url, workerURL);
  93642. }
  93643. if (props.source) {
  93644. workerURL = getLoadableWorkerURLFromSource(props.source);
  93645. workerURLCache.set(props.source, workerURL);
  93646. }
  93647. }
  93648. assert$6(workerURL);
  93649. return workerURL;
  93650. }
  93651. function getLoadableWorkerURLFromURL(url) {
  93652. if (!url.startsWith('http')) {
  93653. return url;
  93654. }
  93655. const workerSource = buildScriptSource(url);
  93656. return getLoadableWorkerURLFromSource(workerSource);
  93657. }
  93658. function getLoadableWorkerURLFromSource(workerSource) {
  93659. const blob = new Blob([workerSource], {
  93660. type: 'application/javascript'
  93661. });
  93662. return URL.createObjectURL(blob);
  93663. }
  93664. function buildScriptSource(workerUrl) {
  93665. return "try {\n importScripts('".concat(workerUrl, "');\n} catch (error) {\n console.error(error);\n throw error;\n}");
  93666. }
  93667. function getTransferList(object, recursive = true, transfers) {
  93668. const transfersSet = transfers || new Set();
  93669. if (!object) ; else if (isTransferable(object)) {
  93670. transfersSet.add(object);
  93671. } else if (isTransferable(object.buffer)) {
  93672. transfersSet.add(object.buffer);
  93673. } else if (ArrayBuffer.isView(object)) ; else if (recursive && typeof object === 'object') {
  93674. for (const key in object) {
  93675. getTransferList(object[key], recursive, transfersSet);
  93676. }
  93677. }
  93678. return transfers === undefined ? Array.from(transfersSet) : [];
  93679. }
  93680. function isTransferable(object) {
  93681. if (!object) {
  93682. return false;
  93683. }
  93684. if (object instanceof ArrayBuffer) {
  93685. return true;
  93686. }
  93687. if (typeof MessagePort !== 'undefined' && object instanceof MessagePort) {
  93688. return true;
  93689. }
  93690. if (typeof ImageBitmap !== 'undefined' && object instanceof ImageBitmap) {
  93691. return true;
  93692. }
  93693. if (typeof OffscreenCanvas !== 'undefined' && object instanceof OffscreenCanvas) {
  93694. return true;
  93695. }
  93696. return false;
  93697. }
  93698. const NOOP = () => {};
  93699. class WorkerThread {
  93700. static isSupported() {
  93701. return typeof Worker !== 'undefined';
  93702. }
  93703. constructor(props) {
  93704. _defineProperty(this, "name", void 0);
  93705. _defineProperty(this, "source", void 0);
  93706. _defineProperty(this, "url", void 0);
  93707. _defineProperty(this, "terminated", false);
  93708. _defineProperty(this, "worker", void 0);
  93709. _defineProperty(this, "onMessage", void 0);
  93710. _defineProperty(this, "onError", void 0);
  93711. _defineProperty(this, "_loadableURL", '');
  93712. const {
  93713. name,
  93714. source,
  93715. url
  93716. } = props;
  93717. assert$6(source || url);
  93718. this.name = name;
  93719. this.source = source;
  93720. this.url = url;
  93721. this.onMessage = NOOP;
  93722. this.onError = error => console.log(error);
  93723. this.worker = this._createBrowserWorker();
  93724. }
  93725. destroy() {
  93726. this.onMessage = NOOP;
  93727. this.onError = NOOP;
  93728. this.worker.terminate();
  93729. this.terminated = true;
  93730. }
  93731. get isRunning() {
  93732. return Boolean(this.onMessage);
  93733. }
  93734. postMessage(data, transferList) {
  93735. transferList = transferList || getTransferList(data);
  93736. this.worker.postMessage(data, transferList);
  93737. }
  93738. _getErrorFromErrorEvent(event) {
  93739. let message = 'Failed to load ';
  93740. message += "worker ".concat(this.name, " from ").concat(this.url, ". ");
  93741. if (event.message) {
  93742. message += "".concat(event.message, " in ");
  93743. }
  93744. if (event.lineno) {
  93745. message += ":".concat(event.lineno, ":").concat(event.colno);
  93746. }
  93747. return new Error(message);
  93748. }
  93749. _createBrowserWorker() {
  93750. this._loadableURL = getLoadableWorkerURL({
  93751. source: this.source,
  93752. url: this.url
  93753. });
  93754. const worker = new Worker(this._loadableURL, {
  93755. name: this.name
  93756. });
  93757. worker.onmessage = event => {
  93758. if (!event.data) {
  93759. this.onError(new Error('No data received'));
  93760. } else {
  93761. this.onMessage(event.data);
  93762. }
  93763. };
  93764. worker.onerror = error => {
  93765. this.onError(this._getErrorFromErrorEvent(error));
  93766. this.terminated = true;
  93767. };
  93768. worker.onmessageerror = event => console.error(event);
  93769. return worker;
  93770. }
  93771. }
  93772. class WorkerPool$2 {
  93773. constructor(props) {
  93774. _defineProperty(this, "name", 'unnamed');
  93775. _defineProperty(this, "source", void 0);
  93776. _defineProperty(this, "url", void 0);
  93777. _defineProperty(this, "maxConcurrency", 1);
  93778. _defineProperty(this, "maxMobileConcurrency", 1);
  93779. _defineProperty(this, "onDebug", () => {});
  93780. _defineProperty(this, "reuseWorkers", true);
  93781. _defineProperty(this, "props", {});
  93782. _defineProperty(this, "jobQueue", []);
  93783. _defineProperty(this, "idleQueue", []);
  93784. _defineProperty(this, "count", 0);
  93785. _defineProperty(this, "isDestroyed", false);
  93786. this.source = props.source;
  93787. this.url = props.url;
  93788. this.setProps(props);
  93789. }
  93790. destroy() {
  93791. this.idleQueue.forEach(worker => worker.destroy());
  93792. this.isDestroyed = true;
  93793. }
  93794. setProps(props) {
  93795. this.props = { ...this.props,
  93796. ...props
  93797. };
  93798. if (props.name !== undefined) {
  93799. this.name = props.name;
  93800. }
  93801. if (props.maxConcurrency !== undefined) {
  93802. this.maxConcurrency = props.maxConcurrency;
  93803. }
  93804. if (props.maxMobileConcurrency !== undefined) {
  93805. this.maxMobileConcurrency = props.maxMobileConcurrency;
  93806. }
  93807. if (props.reuseWorkers !== undefined) {
  93808. this.reuseWorkers = props.reuseWorkers;
  93809. }
  93810. if (props.onDebug !== undefined) {
  93811. this.onDebug = props.onDebug;
  93812. }
  93813. }
  93814. async startJob(name, onMessage = (job, type, data) => job.done(data), onError = (job, error) => job.error(error)) {
  93815. const startPromise = new Promise(onStart => {
  93816. this.jobQueue.push({
  93817. name,
  93818. onMessage,
  93819. onError,
  93820. onStart
  93821. });
  93822. return this;
  93823. });
  93824. this._startQueuedJob();
  93825. return await startPromise;
  93826. }
  93827. async _startQueuedJob() {
  93828. if (!this.jobQueue.length) {
  93829. return;
  93830. }
  93831. const workerThread = this._getAvailableWorker();
  93832. if (!workerThread) {
  93833. return;
  93834. }
  93835. const queuedJob = this.jobQueue.shift();
  93836. if (queuedJob) {
  93837. this.onDebug({
  93838. message: 'Starting job',
  93839. name: queuedJob.name,
  93840. workerThread,
  93841. backlog: this.jobQueue.length
  93842. });
  93843. const job = new WorkerJob(queuedJob.name, workerThread);
  93844. workerThread.onMessage = data => queuedJob.onMessage(job, data.type, data.payload);
  93845. workerThread.onError = error => queuedJob.onError(job, error);
  93846. queuedJob.onStart(job);
  93847. try {
  93848. await job.result;
  93849. } finally {
  93850. this.returnWorkerToQueue(workerThread);
  93851. }
  93852. }
  93853. }
  93854. returnWorkerToQueue(worker) {
  93855. const shouldDestroyWorker = this.isDestroyed || !this.reuseWorkers || this.count > this._getMaxConcurrency();
  93856. if (shouldDestroyWorker) {
  93857. worker.destroy();
  93858. this.count--;
  93859. } else {
  93860. this.idleQueue.push(worker);
  93861. }
  93862. if (!this.isDestroyed) {
  93863. this._startQueuedJob();
  93864. }
  93865. }
  93866. _getAvailableWorker() {
  93867. if (this.idleQueue.length > 0) {
  93868. return this.idleQueue.shift() || null;
  93869. }
  93870. if (this.count < this._getMaxConcurrency()) {
  93871. this.count++;
  93872. const name = "".concat(this.name.toLowerCase(), " (#").concat(this.count, " of ").concat(this.maxConcurrency, ")");
  93873. return new WorkerThread({
  93874. name,
  93875. source: this.source,
  93876. url: this.url
  93877. });
  93878. }
  93879. return null;
  93880. }
  93881. _getMaxConcurrency() {
  93882. return isMobile ? this.maxMobileConcurrency : this.maxConcurrency;
  93883. }
  93884. }
  93885. const DEFAULT_PROPS$3 = {
  93886. maxConcurrency: 3,
  93887. maxMobileConcurrency: 1,
  93888. onDebug: () => {},
  93889. reuseWorkers: true
  93890. };
  93891. class WorkerFarm {
  93892. static isSupported() {
  93893. return WorkerThread.isSupported();
  93894. }
  93895. static getWorkerFarm(props = {}) {
  93896. WorkerFarm._workerFarm = WorkerFarm._workerFarm || new WorkerFarm({});
  93897. WorkerFarm._workerFarm.setProps(props);
  93898. return WorkerFarm._workerFarm;
  93899. }
  93900. constructor(props) {
  93901. _defineProperty(this, "props", void 0);
  93902. _defineProperty(this, "workerPools", new Map());
  93903. this.props = { ...DEFAULT_PROPS$3
  93904. };
  93905. this.setProps(props);
  93906. this.workerPools = new Map();
  93907. }
  93908. destroy() {
  93909. for (const workerPool of this.workerPools.values()) {
  93910. workerPool.destroy();
  93911. }
  93912. }
  93913. setProps(props) {
  93914. this.props = { ...this.props,
  93915. ...props
  93916. };
  93917. for (const workerPool of this.workerPools.values()) {
  93918. workerPool.setProps(this._getWorkerPoolProps());
  93919. }
  93920. }
  93921. getWorkerPool(options) {
  93922. const {
  93923. name,
  93924. source,
  93925. url
  93926. } = options;
  93927. let workerPool = this.workerPools.get(name);
  93928. if (!workerPool) {
  93929. workerPool = new WorkerPool$2({
  93930. name,
  93931. source,
  93932. url
  93933. });
  93934. workerPool.setProps(this._getWorkerPoolProps());
  93935. this.workerPools.set(name, workerPool);
  93936. }
  93937. return workerPool;
  93938. }
  93939. _getWorkerPoolProps() {
  93940. return {
  93941. maxConcurrency: this.props.maxConcurrency,
  93942. maxMobileConcurrency: this.props.maxMobileConcurrency,
  93943. reuseWorkers: this.props.reuseWorkers,
  93944. onDebug: this.props.onDebug
  93945. };
  93946. }
  93947. }
  93948. _defineProperty(WorkerFarm, "_workerFarm", void 0);
  93949. const NPM_TAG = 'latest';
  93950. function getWorkerURL(worker, options = {}) {
  93951. const workerOptions = options[worker.id] || {};
  93952. const workerFile = "".concat(worker.id, "-worker.js");
  93953. let url = workerOptions.workerUrl;
  93954. if (!url && worker.id === 'compression') {
  93955. url = options.workerUrl;
  93956. }
  93957. if (options._workerType === 'test') {
  93958. url = "modules/".concat(worker.module, "/dist/").concat(workerFile);
  93959. }
  93960. if (!url) {
  93961. let version = worker.version;
  93962. if (version === 'latest') {
  93963. version = NPM_TAG;
  93964. }
  93965. const versionTag = version ? "@".concat(version) : '';
  93966. url = "https://unpkg.com/@loaders.gl/".concat(worker.module).concat(versionTag, "/dist/").concat(workerFile);
  93967. }
  93968. assert$6(url);
  93969. return url;
  93970. }
  93971. function validateWorkerVersion(worker, coreVersion = VERSION$8) {
  93972. assert$6(worker, 'no worker provided');
  93973. const workerVersion = worker.version;
  93974. if (!coreVersion || !workerVersion) {
  93975. return false;
  93976. }
  93977. return true;
  93978. }
  93979. var ChildProcessProxy = {};
  93980. var node = /*#__PURE__*/Object.freeze(/*#__PURE__*/Object.assign(/*#__PURE__*/Object.create(null), ChildProcessProxy, {
  93981. 'default': ChildProcessProxy
  93982. }));
  93983. const VERSION$7 = "3.1.4" ;
  93984. const loadLibraryPromises = {};
  93985. async function loadLibrary(libraryUrl, moduleName = null, options = {}) {
  93986. if (moduleName) {
  93987. libraryUrl = getLibraryUrl(libraryUrl, moduleName, options);
  93988. }
  93989. loadLibraryPromises[libraryUrl] = loadLibraryPromises[libraryUrl] || loadLibraryFromFile(libraryUrl);
  93990. return await loadLibraryPromises[libraryUrl];
  93991. }
  93992. function getLibraryUrl(library, moduleName, options) {
  93993. if (library.startsWith('http')) {
  93994. return library;
  93995. }
  93996. const modules = options.modules || {};
  93997. if (modules[library]) {
  93998. return modules[library];
  93999. }
  94000. if (!isBrowser$1) {
  94001. return "modules/".concat(moduleName, "/dist/libs/").concat(library);
  94002. }
  94003. if (options.CDN) {
  94004. assert$6(options.CDN.startsWith('http'));
  94005. return "".concat(options.CDN, "/").concat(moduleName, "@").concat(VERSION$7, "/dist/libs/").concat(library);
  94006. }
  94007. if (isWorker) {
  94008. return "../src/libs/".concat(library);
  94009. }
  94010. return "modules/".concat(moduleName, "/src/libs/").concat(library);
  94011. }
  94012. async function loadLibraryFromFile(libraryUrl) {
  94013. if (libraryUrl.endsWith('wasm')) {
  94014. const response = await fetch(libraryUrl);
  94015. return await response.arrayBuffer();
  94016. }
  94017. if (!isBrowser$1) {
  94018. try {
  94019. return node && ChildProcessProxy.requireFromFile && (await ChildProcessProxy.requireFromFile(libraryUrl));
  94020. } catch {
  94021. return null;
  94022. }
  94023. }
  94024. if (isWorker) {
  94025. return importScripts(libraryUrl);
  94026. }
  94027. const response = await fetch(libraryUrl);
  94028. const scriptSource = await response.text();
  94029. return loadLibraryFromString(scriptSource, libraryUrl);
  94030. }
  94031. function loadLibraryFromString(scriptSource, id) {
  94032. if (!isBrowser$1) {
  94033. return ChildProcessProxy.requireFromString && ChildProcessProxy.requireFromString(scriptSource, id);
  94034. }
  94035. if (isWorker) {
  94036. eval.call(global_, scriptSource);
  94037. return null;
  94038. }
  94039. const script = document.createElement('script');
  94040. script.id = id;
  94041. try {
  94042. script.appendChild(document.createTextNode(scriptSource));
  94043. } catch (e) {
  94044. script.text = scriptSource;
  94045. }
  94046. document.body.appendChild(script);
  94047. return null;
  94048. }
  94049. function canParseWithWorker(loader, options) {
  94050. if (!WorkerFarm.isSupported()) {
  94051. return false;
  94052. }
  94053. return loader.worker && (options === null || options === void 0 ? void 0 : options.worker);
  94054. }
  94055. async function parseWithWorker(loader, data, options, context, parseOnMainThread) {
  94056. const name = loader.id;
  94057. const url = getWorkerURL(loader, options);
  94058. const workerFarm = WorkerFarm.getWorkerFarm(options);
  94059. const workerPool = workerFarm.getWorkerPool({
  94060. name,
  94061. url
  94062. });
  94063. options = JSON.parse(JSON.stringify(options));
  94064. const job = await workerPool.startJob('process-on-worker', onMessage.bind(null, parseOnMainThread));
  94065. job.postMessage('process', {
  94066. input: data,
  94067. options
  94068. });
  94069. const result = await job.result;
  94070. return await result.result;
  94071. }
  94072. async function onMessage(parseOnMainThread, job, type, payload) {
  94073. switch (type) {
  94074. case 'done':
  94075. job.done(payload);
  94076. break;
  94077. case 'error':
  94078. job.error(new Error(payload.error));
  94079. break;
  94080. case 'process':
  94081. const {
  94082. id,
  94083. input,
  94084. options
  94085. } = payload;
  94086. try {
  94087. const result = await parseOnMainThread(input, options);
  94088. job.postMessage('done', {
  94089. id,
  94090. result
  94091. });
  94092. } catch (error) {
  94093. const message = error instanceof Error ? error.message : 'unknown error';
  94094. job.postMessage('error', {
  94095. id,
  94096. error: message
  94097. });
  94098. }
  94099. break;
  94100. default:
  94101. console.warn("parse-with-worker unknown message ".concat(type));
  94102. }
  94103. }
  94104. function getFirstCharacters$1(data, length = 5) {
  94105. if (typeof data === 'string') {
  94106. return data.slice(0, length);
  94107. } else if (ArrayBuffer.isView(data)) {
  94108. return getMagicString$3(data.buffer, data.byteOffset, length);
  94109. } else if (data instanceof ArrayBuffer) {
  94110. const byteOffset = 0;
  94111. return getMagicString$3(data, byteOffset, length);
  94112. }
  94113. return '';
  94114. }
  94115. function getMagicString$3(arrayBuffer, byteOffset, length) {
  94116. if (arrayBuffer.byteLength <= byteOffset + length) {
  94117. return '';
  94118. }
  94119. const dataView = new DataView(arrayBuffer);
  94120. let magic = '';
  94121. for (let i = 0; i < length; i++) {
  94122. magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
  94123. }
  94124. return magic;
  94125. }
  94126. function parseJSON(string) {
  94127. try {
  94128. return JSON.parse(string);
  94129. } catch (_) {
  94130. throw new Error("Failed to parse JSON from data starting with \"".concat(getFirstCharacters$1(string), "\""));
  94131. }
  94132. }
  94133. function isBuffer$1(value) {
  94134. return value && typeof value === 'object' && value.isBuffer;
  94135. }
  94136. function bufferToArrayBuffer(buffer) {
  94137. if (isBuffer$1(buffer)) {
  94138. const typedArray = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.length);
  94139. return typedArray.slice().buffer;
  94140. }
  94141. return buffer;
  94142. }
  94143. function toArrayBuffer(data) {
  94144. if (isBuffer$1(data)) {
  94145. return bufferToArrayBuffer(data);
  94146. }
  94147. if (data instanceof ArrayBuffer) {
  94148. return data;
  94149. }
  94150. if (ArrayBuffer.isView(data)) {
  94151. if (data.byteOffset === 0 && data.byteLength === data.buffer.byteLength) {
  94152. return data.buffer;
  94153. }
  94154. return data.buffer.slice(data.byteOffset, data.byteOffset + data.byteLength);
  94155. }
  94156. if (typeof data === 'string') {
  94157. const text = data;
  94158. const uint8Array = new TextEncoder().encode(text);
  94159. return uint8Array.buffer;
  94160. }
  94161. if (data && typeof data === 'object' && data._toArrayBuffer) {
  94162. return data._toArrayBuffer();
  94163. }
  94164. throw new Error('toArrayBuffer');
  94165. }
  94166. function compareArrayBuffers(arrayBuffer1, arrayBuffer2, byteLength) {
  94167. byteLength = byteLength || arrayBuffer1.byteLength;
  94168. if (arrayBuffer1.byteLength < byteLength || arrayBuffer2.byteLength < byteLength) {
  94169. return false;
  94170. }
  94171. const array1 = new Uint8Array(arrayBuffer1);
  94172. const array2 = new Uint8Array(arrayBuffer2);
  94173. for (let i = 0; i < array1.length; ++i) {
  94174. if (array1[i] !== array2[i]) {
  94175. return false;
  94176. }
  94177. }
  94178. return true;
  94179. }
  94180. function concatenateArrayBuffers(...sources) {
  94181. const sourceArrays = sources.map(source2 => source2 instanceof ArrayBuffer ? new Uint8Array(source2) : source2);
  94182. const byteLength = sourceArrays.reduce((length, typedArray) => length + typedArray.byteLength, 0);
  94183. const result = new Uint8Array(byteLength);
  94184. let offset = 0;
  94185. for (const sourceArray of sourceArrays) {
  94186. result.set(sourceArray, offset);
  94187. offset += sourceArray.byteLength;
  94188. }
  94189. return result.buffer;
  94190. }
  94191. function sliceArrayBuffer(arrayBuffer, byteOffset, byteLength) {
  94192. const subArray = byteLength !== undefined ? new Uint8Array(arrayBuffer).subarray(byteOffset, byteOffset + byteLength) : new Uint8Array(arrayBuffer).subarray(byteOffset);
  94193. const arrayCopy = new Uint8Array(subArray);
  94194. return arrayCopy.buffer;
  94195. }
  94196. function padToNBytes(byteLength, padding) {
  94197. assert$7(byteLength >= 0);
  94198. assert$7(padding > 0);
  94199. return byteLength + (padding - 1) & ~(padding - 1);
  94200. }
  94201. function copyToArray(source, target, targetOffset) {
  94202. let sourceArray;
  94203. if (source instanceof ArrayBuffer) {
  94204. sourceArray = new Uint8Array(source);
  94205. } else {
  94206. const srcByteOffset = source.byteOffset;
  94207. const srcByteLength = source.byteLength;
  94208. sourceArray = new Uint8Array(source.buffer || source.arrayBuffer, srcByteOffset, srcByteLength);
  94209. }
  94210. target.set(sourceArray, targetOffset);
  94211. return targetOffset + padToNBytes(sourceArray.byteLength, 4);
  94212. }
  94213. async function concatenateArrayBuffersAsync(asyncIterator) {
  94214. const arrayBuffers = [];
  94215. for await (const chunk of asyncIterator) {
  94216. arrayBuffers.push(chunk);
  94217. }
  94218. return concatenateArrayBuffers(...arrayBuffers);
  94219. }
  94220. function getHiResTimestamp$1() {
  94221. let timestamp;
  94222. if (typeof window !== 'undefined' && window.performance) {
  94223. timestamp = window.performance.now();
  94224. } else if (typeof process !== 'undefined' && process.hrtime) {
  94225. const timeParts = process.hrtime();
  94226. timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;
  94227. } else {
  94228. timestamp = Date.now();
  94229. }
  94230. return timestamp;
  94231. }
  94232. class Stat {
  94233. constructor(name, type) {
  94234. _defineProperty(this, "name", void 0);
  94235. _defineProperty(this, "type", void 0);
  94236. _defineProperty(this, "sampleSize", 1);
  94237. _defineProperty(this, "time", void 0);
  94238. _defineProperty(this, "count", void 0);
  94239. _defineProperty(this, "samples", void 0);
  94240. _defineProperty(this, "lastTiming", void 0);
  94241. _defineProperty(this, "lastSampleTime", void 0);
  94242. _defineProperty(this, "lastSampleCount", void 0);
  94243. _defineProperty(this, "_count", 0);
  94244. _defineProperty(this, "_time", 0);
  94245. _defineProperty(this, "_samples", 0);
  94246. _defineProperty(this, "_startTime", 0);
  94247. _defineProperty(this, "_timerPending", false);
  94248. this.name = name;
  94249. this.type = type;
  94250. this.reset();
  94251. }
  94252. setSampleSize(samples) {
  94253. this.sampleSize = samples;
  94254. return this;
  94255. }
  94256. incrementCount() {
  94257. this.addCount(1);
  94258. return this;
  94259. }
  94260. decrementCount() {
  94261. this.subtractCount(1);
  94262. return this;
  94263. }
  94264. addCount(value) {
  94265. this._count += value;
  94266. this._samples++;
  94267. this._checkSampling();
  94268. return this;
  94269. }
  94270. subtractCount(value) {
  94271. this._count -= value;
  94272. this._samples++;
  94273. this._checkSampling();
  94274. return this;
  94275. }
  94276. addTime(time) {
  94277. this._time += time;
  94278. this.lastTiming = time;
  94279. this._samples++;
  94280. this._checkSampling();
  94281. return this;
  94282. }
  94283. timeStart() {
  94284. this._startTime = getHiResTimestamp$1();
  94285. this._timerPending = true;
  94286. return this;
  94287. }
  94288. timeEnd() {
  94289. if (!this._timerPending) {
  94290. return this;
  94291. }
  94292. this.addTime(getHiResTimestamp$1() - this._startTime);
  94293. this._timerPending = false;
  94294. this._checkSampling();
  94295. return this;
  94296. }
  94297. getSampleAverageCount() {
  94298. return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
  94299. }
  94300. getSampleAverageTime() {
  94301. return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
  94302. }
  94303. getSampleHz() {
  94304. return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1000) : 0;
  94305. }
  94306. getAverageCount() {
  94307. return this.samples > 0 ? this.count / this.samples : 0;
  94308. }
  94309. getAverageTime() {
  94310. return this.samples > 0 ? this.time / this.samples : 0;
  94311. }
  94312. getHz() {
  94313. return this.time > 0 ? this.samples / (this.time / 1000) : 0;
  94314. }
  94315. reset() {
  94316. this.time = 0;
  94317. this.count = 0;
  94318. this.samples = 0;
  94319. this.lastTiming = 0;
  94320. this.lastSampleTime = 0;
  94321. this.lastSampleCount = 0;
  94322. this._count = 0;
  94323. this._time = 0;
  94324. this._samples = 0;
  94325. this._startTime = 0;
  94326. this._timerPending = false;
  94327. return this;
  94328. }
  94329. _checkSampling() {
  94330. if (this._samples === this.sampleSize) {
  94331. this.lastSampleTime = this._time;
  94332. this.lastSampleCount = this._count;
  94333. this.count += this._count;
  94334. this.time += this._time;
  94335. this.samples += this._samples;
  94336. this._time = 0;
  94337. this._count = 0;
  94338. this._samples = 0;
  94339. }
  94340. }
  94341. }
  94342. class Stats$1 {
  94343. constructor(options) {
  94344. _defineProperty(this, "id", void 0);
  94345. _defineProperty(this, "stats", {});
  94346. this.id = options.id;
  94347. this.stats = {};
  94348. this._initializeStats(options.stats);
  94349. Object.seal(this);
  94350. }
  94351. get(name) {
  94352. let type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'count';
  94353. return this._getOrCreate({
  94354. name,
  94355. type
  94356. });
  94357. }
  94358. get size() {
  94359. return Object.keys(this.stats).length;
  94360. }
  94361. reset() {
  94362. for (const key in this.stats) {
  94363. this.stats[key].reset();
  94364. }
  94365. return this;
  94366. }
  94367. forEach(fn) {
  94368. for (const key in this.stats) {
  94369. fn(this.stats[key]);
  94370. }
  94371. }
  94372. getTable() {
  94373. const table = {};
  94374. this.forEach(stat => {
  94375. table[stat.name] = {
  94376. time: stat.time || 0,
  94377. count: stat.count || 0,
  94378. average: stat.getAverageTime() || 0,
  94379. hz: stat.getHz() || 0
  94380. };
  94381. });
  94382. return table;
  94383. }
  94384. _initializeStats() {
  94385. let stats = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
  94386. stats.forEach(stat => this._getOrCreate(stat));
  94387. }
  94388. _getOrCreate(stat) {
  94389. if (!stat || !stat.name) {
  94390. return null;
  94391. }
  94392. const {
  94393. name,
  94394. type
  94395. } = stat;
  94396. if (!this.stats[name]) {
  94397. if (stat instanceof Stat) {
  94398. this.stats[name] = stat;
  94399. } else {
  94400. this.stats[name] = new Stat(name, type);
  94401. }
  94402. }
  94403. return this.stats[name];
  94404. }
  94405. }
  94406. const STAT_QUEUED_REQUESTS = 'Queued Requests';
  94407. const STAT_ACTIVE_REQUESTS = 'Active Requests';
  94408. const STAT_CANCELLED_REQUESTS = 'Cancelled Requests';
  94409. const STAT_QUEUED_REQUESTS_EVER = 'Queued Requests Ever';
  94410. const STAT_ACTIVE_REQUESTS_EVER = 'Active Requests Ever';
  94411. const DEFAULT_PROPS$2 = {
  94412. id: 'request-scheduler',
  94413. throttleRequests: true,
  94414. maxRequests: 6
  94415. };
  94416. class RequestScheduler {
  94417. constructor(props = {}) {
  94418. _defineProperty(this, "props", void 0);
  94419. _defineProperty(this, "stats", void 0);
  94420. _defineProperty(this, "activeRequestCount", 0);
  94421. _defineProperty(this, "requestQueue", []);
  94422. _defineProperty(this, "requestMap", new Map());
  94423. _defineProperty(this, "deferredUpdate", null);
  94424. this.props = { ...DEFAULT_PROPS$2,
  94425. ...props
  94426. };
  94427. this.stats = new Stats$1({
  94428. id: this.props.id
  94429. });
  94430. this.stats.get(STAT_QUEUED_REQUESTS);
  94431. this.stats.get(STAT_ACTIVE_REQUESTS);
  94432. this.stats.get(STAT_CANCELLED_REQUESTS);
  94433. this.stats.get(STAT_QUEUED_REQUESTS_EVER);
  94434. this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
  94435. }
  94436. scheduleRequest(handle, getPriority = () => 0) {
  94437. if (!this.props.throttleRequests) {
  94438. return Promise.resolve({
  94439. done: () => {}
  94440. });
  94441. }
  94442. if (this.requestMap.has(handle)) {
  94443. return this.requestMap.get(handle);
  94444. }
  94445. const request = {
  94446. handle,
  94447. priority: 0,
  94448. getPriority
  94449. };
  94450. const promise = new Promise(resolve => {
  94451. request.resolve = resolve;
  94452. return request;
  94453. });
  94454. this.requestQueue.push(request);
  94455. this.requestMap.set(handle, promise);
  94456. this._issueNewRequests();
  94457. return promise;
  94458. }
  94459. _issueRequest(request) {
  94460. const {
  94461. handle,
  94462. resolve
  94463. } = request;
  94464. let isDone = false;
  94465. const done = () => {
  94466. if (!isDone) {
  94467. isDone = true;
  94468. this.requestMap.delete(handle);
  94469. this.activeRequestCount--;
  94470. this._issueNewRequests();
  94471. }
  94472. };
  94473. this.activeRequestCount++;
  94474. return resolve ? resolve({
  94475. done
  94476. }) : Promise.resolve({
  94477. done
  94478. });
  94479. }
  94480. _issueNewRequests() {
  94481. if (!this.deferredUpdate) {
  94482. this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);
  94483. }
  94484. }
  94485. _issueNewRequestsAsync() {
  94486. this.deferredUpdate = null;
  94487. const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
  94488. if (freeSlots === 0) {
  94489. return;
  94490. }
  94491. this._updateAllRequests();
  94492. for (let i = 0; i < freeSlots; ++i) {
  94493. const request = this.requestQueue.shift();
  94494. if (request) {
  94495. this._issueRequest(request);
  94496. }
  94497. }
  94498. }
  94499. _updateAllRequests() {
  94500. const requestQueue = this.requestQueue;
  94501. for (let i = 0; i < requestQueue.length; ++i) {
  94502. const request = requestQueue[i];
  94503. if (!this._updateRequest(request)) {
  94504. requestQueue.splice(i, 1);
  94505. this.requestMap.delete(request.handle);
  94506. i--;
  94507. }
  94508. }
  94509. requestQueue.sort((a, b) => a.priority - b.priority);
  94510. }
  94511. _updateRequest(request) {
  94512. request.priority = request.getPriority(request.handle);
  94513. if (request.priority < 0) {
  94514. request.resolve(null);
  94515. return false;
  94516. }
  94517. return true;
  94518. }
  94519. }
  94520. let pathPrefix = '';
  94521. const fileAliases = {};
  94522. function resolvePath(filename) {
  94523. for (const alias in fileAliases) {
  94524. if (filename.startsWith(alias)) {
  94525. const replacement = fileAliases[alias];
  94526. filename = filename.replace(alias, replacement);
  94527. }
  94528. }
  94529. if (!filename.startsWith('http://') && !filename.startsWith('https://')) {
  94530. filename = "".concat(pathPrefix).concat(filename);
  94531. }
  94532. return filename;
  94533. }
  94534. function filename(url) {
  94535. const slashIndex = url && url.lastIndexOf('/');
  94536. return slashIndex >= 0 ? url.substr(slashIndex + 1) : '';
  94537. }
  94538. function dirname(url) {
  94539. const slashIndex = url && url.lastIndexOf('/');
  94540. return slashIndex >= 0 ? url.substr(0, slashIndex) : '';
  94541. }
  94542. const isBoolean = x => typeof x === 'boolean';
  94543. const isFunction = x => typeof x === 'function';
  94544. const isObject = x => x !== null && typeof x === 'object';
  94545. const isPureObject = x => isObject(x) && x.constructor === {}.constructor;
  94546. const isIterable = x => x && typeof x[Symbol.iterator] === 'function';
  94547. const isAsyncIterable = x => x && typeof x[Symbol.asyncIterator] === 'function';
  94548. const isResponse = x => typeof Response !== 'undefined' && x instanceof Response || x && x.arrayBuffer && x.text && x.json;
  94549. const isBlob = x => typeof Blob !== 'undefined' && x instanceof Blob;
  94550. const isBuffer = x => x && typeof x === 'object' && x.isBuffer;
  94551. const isReadableDOMStream = x => typeof ReadableStream !== 'undefined' && x instanceof ReadableStream || isObject(x) && isFunction(x.tee) && isFunction(x.cancel) && isFunction(x.getReader);
  94552. const isReadableNodeStream = x => isObject(x) && isFunction(x.read) && isFunction(x.pipe) && isBoolean(x.readable);
  94553. const isReadableStream = x => isReadableDOMStream(x) || isReadableNodeStream(x);
  94554. const DATA_URL_PATTERN = /^data:([-\w.]+\/[-\w.+]+)(;|,)/;
  94555. const MIME_TYPE_PATTERN = /^([-\w.]+\/[-\w.+]+)/;
  94556. function parseMIMEType(mimeString) {
  94557. const matches = MIME_TYPE_PATTERN.exec(mimeString);
  94558. if (matches) {
  94559. return matches[1];
  94560. }
  94561. return mimeString;
  94562. }
  94563. function parseMIMETypeFromURL(url) {
  94564. const matches = DATA_URL_PATTERN.exec(url);
  94565. if (matches) {
  94566. return matches[1];
  94567. }
  94568. return '';
  94569. }
  94570. const QUERY_STRING_PATTERN = /\?.*/;
  94571. function getResourceUrlAndType(resource) {
  94572. if (isResponse(resource)) {
  94573. const url = stripQueryString(resource.url || '');
  94574. const contentTypeHeader = resource.headers.get('content-type') || '';
  94575. return {
  94576. url,
  94577. type: parseMIMEType(contentTypeHeader) || parseMIMETypeFromURL(url)
  94578. };
  94579. }
  94580. if (isBlob(resource)) {
  94581. return {
  94582. url: stripQueryString(resource.name || ''),
  94583. type: resource.type || ''
  94584. };
  94585. }
  94586. if (typeof resource === 'string') {
  94587. return {
  94588. url: stripQueryString(resource),
  94589. type: parseMIMETypeFromURL(resource)
  94590. };
  94591. }
  94592. return {
  94593. url: '',
  94594. type: ''
  94595. };
  94596. }
  94597. function getResourceContentLength(resource) {
  94598. if (isResponse(resource)) {
  94599. return resource.headers['content-length'] || -1;
  94600. }
  94601. if (isBlob(resource)) {
  94602. return resource.size;
  94603. }
  94604. if (typeof resource === 'string') {
  94605. return resource.length;
  94606. }
  94607. if (resource instanceof ArrayBuffer) {
  94608. return resource.byteLength;
  94609. }
  94610. if (ArrayBuffer.isView(resource)) {
  94611. return resource.byteLength;
  94612. }
  94613. return -1;
  94614. }
  94615. function stripQueryString(url) {
  94616. return url.replace(QUERY_STRING_PATTERN, '');
  94617. }
  94618. async function makeResponse(resource) {
  94619. if (isResponse(resource)) {
  94620. return resource;
  94621. }
  94622. const headers = {};
  94623. const contentLength = getResourceContentLength(resource);
  94624. if (contentLength >= 0) {
  94625. headers['content-length'] = String(contentLength);
  94626. }
  94627. const {
  94628. url,
  94629. type
  94630. } = getResourceUrlAndType(resource);
  94631. if (type) {
  94632. headers['content-type'] = type;
  94633. }
  94634. const initialDataUrl = await getInitialDataUrl(resource);
  94635. if (initialDataUrl) {
  94636. headers['x-first-bytes'] = initialDataUrl;
  94637. }
  94638. if (typeof resource === 'string') {
  94639. resource = new TextEncoder().encode(resource);
  94640. }
  94641. const response = new Response(resource, {
  94642. headers
  94643. });
  94644. Object.defineProperty(response, 'url', {
  94645. value: url
  94646. });
  94647. return response;
  94648. }
  94649. async function checkResponse(response) {
  94650. if (!response.ok) {
  94651. const message = await getResponseError(response);
  94652. throw new Error(message);
  94653. }
  94654. }
  94655. async function getResponseError(response) {
  94656. let message = "Failed to fetch resource ".concat(response.url, " (").concat(response.status, "): ");
  94657. try {
  94658. const contentType = response.headers.get('Content-Type');
  94659. let text = response.statusText;
  94660. if (contentType.includes('application/json')) {
  94661. text += " ".concat(await response.text());
  94662. }
  94663. message += text;
  94664. message = message.length > 60 ? "".concat(message.slice(60), "...") : message;
  94665. } catch (error) {}
  94666. return message;
  94667. }
  94668. async function getInitialDataUrl(resource) {
  94669. const INITIAL_DATA_LENGTH = 5;
  94670. if (typeof resource === 'string') {
  94671. return "data:,".concat(resource.slice(0, INITIAL_DATA_LENGTH));
  94672. }
  94673. if (resource instanceof Blob) {
  94674. const blobSlice = resource.slice(0, 5);
  94675. return await new Promise(resolve => {
  94676. const reader = new FileReader();
  94677. reader.onload = event => {
  94678. var _event$target;
  94679. return resolve(event === null || event === void 0 ? void 0 : (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result);
  94680. };
  94681. reader.readAsDataURL(blobSlice);
  94682. });
  94683. }
  94684. if (resource instanceof ArrayBuffer) {
  94685. const slice = resource.slice(0, INITIAL_DATA_LENGTH);
  94686. const base64 = arrayBufferToBase64(slice);
  94687. return "data:base64,".concat(base64);
  94688. }
  94689. return null;
  94690. }
  94691. function arrayBufferToBase64(buffer) {
  94692. let binary = '';
  94693. const bytes = new Uint8Array(buffer);
  94694. for (let i = 0; i < bytes.byteLength; i++) {
  94695. binary += String.fromCharCode(bytes[i]);
  94696. }
  94697. return btoa(binary);
  94698. }
  94699. async function fetchFile(url, options) {
  94700. if (typeof url === 'string') {
  94701. url = resolvePath(url);
  94702. let fetchOptions = options;
  94703. if (options !== null && options !== void 0 && options.fetch && typeof (options === null || options === void 0 ? void 0 : options.fetch) !== 'function') {
  94704. fetchOptions = options.fetch;
  94705. }
  94706. return await fetch(url, fetchOptions);
  94707. }
  94708. return await makeResponse(url);
  94709. }
  94710. function isElectron(mockUserAgent) {
  94711. if (typeof window !== 'undefined' && typeof window.process === 'object' && window.process.type === 'renderer') {
  94712. return true;
  94713. }
  94714. if (typeof process !== 'undefined' && typeof process.versions === 'object' && Boolean(process.versions.electron)) {
  94715. return true;
  94716. }
  94717. const realUserAgent = typeof navigator === 'object' && typeof navigator.userAgent === 'string' && navigator.userAgent;
  94718. const userAgent = mockUserAgent || realUserAgent;
  94719. if (userAgent && userAgent.indexOf('Electron') >= 0) {
  94720. return true;
  94721. }
  94722. return false;
  94723. }
  94724. function isBrowser() {
  94725. const isNode = typeof process === 'object' && String(process) === '[object process]' && !process.browser;
  94726. return !isNode || isElectron();
  94727. }
  94728. const globals = {
  94729. self: typeof self !== 'undefined' && self,
  94730. window: typeof window !== 'undefined' && window,
  94731. global: typeof global !== 'undefined' && global,
  94732. document: typeof document !== 'undefined' && document,
  94733. process: typeof process === 'object' && process
  94734. };
  94735. const window_ = globals.window || globals.self || globals.global;
  94736. const process_ = globals.process || {};
  94737. const VERSION$6 = typeof __VERSION__ !== 'undefined' ? __VERSION__ : 'untranspiled source';
  94738. isBrowser();
  94739. function getStorage(type) {
  94740. try {
  94741. const storage = window[type];
  94742. const x = '__storage_test__';
  94743. storage.setItem(x, x);
  94744. storage.removeItem(x);
  94745. return storage;
  94746. } catch (e) {
  94747. return null;
  94748. }
  94749. }
  94750. class LocalStorage {
  94751. constructor(id) {
  94752. let defaultSettings = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  94753. let type = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'sessionStorage';
  94754. _defineProperty(this, "storage", void 0);
  94755. _defineProperty(this, "id", void 0);
  94756. _defineProperty(this, "config", {});
  94757. this.storage = getStorage(type);
  94758. this.id = id;
  94759. this.config = {};
  94760. Object.assign(this.config, defaultSettings);
  94761. this._loadConfiguration();
  94762. }
  94763. getConfiguration() {
  94764. return this.config;
  94765. }
  94766. setConfiguration(configuration) {
  94767. this.config = {};
  94768. return this.updateConfiguration(configuration);
  94769. }
  94770. updateConfiguration(configuration) {
  94771. Object.assign(this.config, configuration);
  94772. if (this.storage) {
  94773. const serialized = JSON.stringify(this.config);
  94774. this.storage.setItem(this.id, serialized);
  94775. }
  94776. return this;
  94777. }
  94778. _loadConfiguration() {
  94779. let configuration = {};
  94780. if (this.storage) {
  94781. const serializedConfiguration = this.storage.getItem(this.id);
  94782. configuration = serializedConfiguration ? JSON.parse(serializedConfiguration) : {};
  94783. }
  94784. Object.assign(this.config, configuration);
  94785. return this;
  94786. }
  94787. }
  94788. function formatTime(ms) {
  94789. let formatted;
  94790. if (ms < 10) {
  94791. formatted = "".concat(ms.toFixed(2), "ms");
  94792. } else if (ms < 100) {
  94793. formatted = "".concat(ms.toFixed(1), "ms");
  94794. } else if (ms < 1000) {
  94795. formatted = "".concat(ms.toFixed(0), "ms");
  94796. } else {
  94797. formatted = "".concat((ms / 1000).toFixed(2), "s");
  94798. }
  94799. return formatted;
  94800. }
  94801. function leftPad(string) {
  94802. let length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 8;
  94803. const padLength = Math.max(length - string.length, 0);
  94804. return "".concat(' '.repeat(padLength)).concat(string);
  94805. }
  94806. function formatImage(image, message, scale) {
  94807. let maxWidth = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 600;
  94808. const imageUrl = image.src.replace(/\(/g, '%28').replace(/\)/g, '%29');
  94809. if (image.width > maxWidth) {
  94810. scale = Math.min(scale, maxWidth / image.width);
  94811. }
  94812. const width = image.width * scale;
  94813. const height = image.height * scale;
  94814. const 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('');
  94815. return ["".concat(message, " %c+"), style];
  94816. }
  94817. let COLOR;
  94818. (function (COLOR) {
  94819. COLOR[COLOR["BLACK"] = 30] = "BLACK";
  94820. COLOR[COLOR["RED"] = 31] = "RED";
  94821. COLOR[COLOR["GREEN"] = 32] = "GREEN";
  94822. COLOR[COLOR["YELLOW"] = 33] = "YELLOW";
  94823. COLOR[COLOR["BLUE"] = 34] = "BLUE";
  94824. COLOR[COLOR["MAGENTA"] = 35] = "MAGENTA";
  94825. COLOR[COLOR["CYAN"] = 36] = "CYAN";
  94826. COLOR[COLOR["WHITE"] = 37] = "WHITE";
  94827. COLOR[COLOR["BRIGHT_BLACK"] = 90] = "BRIGHT_BLACK";
  94828. COLOR[COLOR["BRIGHT_RED"] = 91] = "BRIGHT_RED";
  94829. COLOR[COLOR["BRIGHT_GREEN"] = 92] = "BRIGHT_GREEN";
  94830. COLOR[COLOR["BRIGHT_YELLOW"] = 93] = "BRIGHT_YELLOW";
  94831. COLOR[COLOR["BRIGHT_BLUE"] = 94] = "BRIGHT_BLUE";
  94832. COLOR[COLOR["BRIGHT_MAGENTA"] = 95] = "BRIGHT_MAGENTA";
  94833. COLOR[COLOR["BRIGHT_CYAN"] = 96] = "BRIGHT_CYAN";
  94834. COLOR[COLOR["BRIGHT_WHITE"] = 97] = "BRIGHT_WHITE";
  94835. })(COLOR || (COLOR = {}));
  94836. function getColor$1(color) {
  94837. return typeof color === 'string' ? COLOR[color.toUpperCase()] || COLOR.WHITE : color;
  94838. }
  94839. function addColor(string, color, background) {
  94840. if (!isBrowser && typeof string === 'string') {
  94841. if (color) {
  94842. color = getColor$1(color);
  94843. string = "\x1B[".concat(color, "m").concat(string, "\x1B[39m");
  94844. }
  94845. if (background) {
  94846. color = getColor$1(background);
  94847. string = "\x1B[".concat(background + 10, "m").concat(string, "\x1B[49m");
  94848. }
  94849. }
  94850. return string;
  94851. }
  94852. function autobind(obj) {
  94853. let predefined = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['constructor'];
  94854. const proto = Object.getPrototypeOf(obj);
  94855. const propNames = Object.getOwnPropertyNames(proto);
  94856. for (const key of propNames) {
  94857. if (typeof obj[key] === 'function') {
  94858. if (!predefined.find(name => key === name)) {
  94859. obj[key] = obj[key].bind(obj);
  94860. }
  94861. }
  94862. }
  94863. }
  94864. function assert$5(condition, message) {
  94865. if (!condition) {
  94866. throw new Error(message || 'Assertion failed');
  94867. }
  94868. }
  94869. function getHiResTimestamp() {
  94870. let timestamp;
  94871. if (isBrowser && 'performance' in window_) {
  94872. var _window$performance, _window$performance$n;
  94873. 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);
  94874. } else if ('hrtime' in process_) {
  94875. var _process$hrtime;
  94876. const timeParts = process_ === null || process_ === void 0 ? void 0 : (_process$hrtime = process_.hrtime) === null || _process$hrtime === void 0 ? void 0 : _process$hrtime.call(process_);
  94877. timestamp = timeParts[0] * 1000 + timeParts[1] / 1e6;
  94878. } else {
  94879. timestamp = Date.now();
  94880. }
  94881. return timestamp;
  94882. }
  94883. const originalConsole = {
  94884. debug: isBrowser ? console.debug || console.log : console.log,
  94885. log: console.log,
  94886. info: console.info,
  94887. warn: console.warn,
  94888. error: console.error
  94889. };
  94890. const DEFAULT_SETTINGS = {
  94891. enabled: true,
  94892. level: 0
  94893. };
  94894. function noop$1() {}
  94895. const cache = {};
  94896. const ONCE = {
  94897. once: true
  94898. };
  94899. class Log {
  94900. constructor() {
  94901. let {
  94902. id
  94903. } = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
  94904. id: ''
  94905. };
  94906. _defineProperty(this, "id", void 0);
  94907. _defineProperty(this, "VERSION", VERSION$6);
  94908. _defineProperty(this, "_startTs", getHiResTimestamp());
  94909. _defineProperty(this, "_deltaTs", getHiResTimestamp());
  94910. _defineProperty(this, "_storage", void 0);
  94911. _defineProperty(this, "userData", {});
  94912. _defineProperty(this, "LOG_THROTTLE_TIMEOUT", 0);
  94913. this.id = id;
  94914. this._storage = new LocalStorage("__probe-".concat(this.id, "__"), DEFAULT_SETTINGS);
  94915. this.userData = {};
  94916. this.timeStamp("".concat(this.id, " started"));
  94917. autobind(this);
  94918. Object.seal(this);
  94919. }
  94920. set level(newLevel) {
  94921. this.setLevel(newLevel);
  94922. }
  94923. get level() {
  94924. return this.getLevel();
  94925. }
  94926. isEnabled() {
  94927. return this._storage.config.enabled;
  94928. }
  94929. getLevel() {
  94930. return this._storage.config.level;
  94931. }
  94932. getTotal() {
  94933. return Number((getHiResTimestamp() - this._startTs).toPrecision(10));
  94934. }
  94935. getDelta() {
  94936. return Number((getHiResTimestamp() - this._deltaTs).toPrecision(10));
  94937. }
  94938. set priority(newPriority) {
  94939. this.level = newPriority;
  94940. }
  94941. get priority() {
  94942. return this.level;
  94943. }
  94944. getPriority() {
  94945. return this.level;
  94946. }
  94947. enable() {
  94948. let enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
  94949. this._storage.updateConfiguration({
  94950. enabled
  94951. });
  94952. return this;
  94953. }
  94954. setLevel(level) {
  94955. this._storage.updateConfiguration({
  94956. level
  94957. });
  94958. return this;
  94959. }
  94960. get(setting) {
  94961. return this._storage.config[setting];
  94962. }
  94963. set(setting, value) {
  94964. this._storage.updateConfiguration({
  94965. [setting]: value
  94966. });
  94967. }
  94968. settings() {
  94969. if (console.table) {
  94970. console.table(this._storage.config);
  94971. } else {
  94972. console.log(this._storage.config);
  94973. }
  94974. }
  94975. assert(condition, message) {
  94976. assert$5(condition, message);
  94977. }
  94978. warn(message) {
  94979. return this._getLogFunction(0, message, originalConsole.warn, arguments, ONCE);
  94980. }
  94981. error(message) {
  94982. return this._getLogFunction(0, message, originalConsole.error, arguments);
  94983. }
  94984. deprecated(oldUsage, newUsage) {
  94985. return this.warn("`".concat(oldUsage, "` is deprecated and will be removed in a later version. Use `").concat(newUsage, "` instead"));
  94986. }
  94987. removed(oldUsage, newUsage) {
  94988. return this.error("`".concat(oldUsage, "` has been removed. Use `").concat(newUsage, "` instead"));
  94989. }
  94990. probe(logLevel, message) {
  94991. return this._getLogFunction(logLevel, message, originalConsole.log, arguments, {
  94992. time: true,
  94993. once: true
  94994. });
  94995. }
  94996. log(logLevel, message) {
  94997. return this._getLogFunction(logLevel, message, originalConsole.debug, arguments);
  94998. }
  94999. info(logLevel, message) {
  95000. return this._getLogFunction(logLevel, message, console.info, arguments);
  95001. }
  95002. once(logLevel, message) {
  95003. for (var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
  95004. args[_key - 2] = arguments[_key];
  95005. }
  95006. return this._getLogFunction(logLevel, message, originalConsole.debug || originalConsole.info, arguments, ONCE);
  95007. }
  95008. table(logLevel, table, columns) {
  95009. if (table) {
  95010. return this._getLogFunction(logLevel, table, console.table || noop$1, columns && [columns], {
  95011. tag: getTableHeader(table)
  95012. });
  95013. }
  95014. return noop$1;
  95015. }
  95016. image(_ref) {
  95017. let {
  95018. logLevel,
  95019. priority,
  95020. image,
  95021. message = '',
  95022. scale = 1
  95023. } = _ref;
  95024. if (!this._shouldLog(logLevel || priority)) {
  95025. return noop$1;
  95026. }
  95027. return isBrowser ? logImageInBrowser({
  95028. image,
  95029. message,
  95030. scale
  95031. }) : logImageInNode({
  95032. image,
  95033. message,
  95034. scale
  95035. });
  95036. }
  95037. time(logLevel, message) {
  95038. return this._getLogFunction(logLevel, message, console.time ? console.time : console.info);
  95039. }
  95040. timeEnd(logLevel, message) {
  95041. return this._getLogFunction(logLevel, message, console.timeEnd ? console.timeEnd : console.info);
  95042. }
  95043. timeStamp(logLevel, message) {
  95044. return this._getLogFunction(logLevel, message, console.timeStamp || noop$1);
  95045. }
  95046. group(logLevel, message) {
  95047. let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
  95048. collapsed: false
  95049. };
  95050. const options = normalizeArguments({
  95051. logLevel,
  95052. message,
  95053. opts
  95054. });
  95055. const {
  95056. collapsed
  95057. } = opts;
  95058. options.method = (collapsed ? console.groupCollapsed : console.group) || console.info;
  95059. return this._getLogFunction(options);
  95060. }
  95061. groupCollapsed(logLevel, message) {
  95062. let opts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  95063. return this.group(logLevel, message, Object.assign({}, opts, {
  95064. collapsed: true
  95065. }));
  95066. }
  95067. groupEnd(logLevel) {
  95068. return this._getLogFunction(logLevel, '', console.groupEnd || noop$1);
  95069. }
  95070. withGroup(logLevel, message, func) {
  95071. this.group(logLevel, message)();
  95072. try {
  95073. func();
  95074. } finally {
  95075. this.groupEnd(logLevel)();
  95076. }
  95077. }
  95078. trace() {
  95079. if (console.trace) {
  95080. console.trace();
  95081. }
  95082. }
  95083. _shouldLog(logLevel) {
  95084. return this.isEnabled() && this.getLevel() >= normalizeLogLevel(logLevel);
  95085. }
  95086. _getLogFunction(logLevel, message, method, args, opts) {
  95087. if (this._shouldLog(logLevel)) {
  95088. opts = normalizeArguments({
  95089. logLevel,
  95090. message,
  95091. args,
  95092. opts
  95093. });
  95094. method = method || opts.method;
  95095. assert$5(method);
  95096. opts.total = this.getTotal();
  95097. opts.delta = this.getDelta();
  95098. this._deltaTs = getHiResTimestamp();
  95099. const tag = opts.tag || opts.message;
  95100. if (opts.once) {
  95101. if (!cache[tag]) {
  95102. cache[tag] = getHiResTimestamp();
  95103. } else {
  95104. return noop$1;
  95105. }
  95106. }
  95107. message = decorateMessage(this.id, opts.message, opts);
  95108. return method.bind(console, message, ...opts.args);
  95109. }
  95110. return noop$1;
  95111. }
  95112. }
  95113. _defineProperty(Log, "VERSION", VERSION$6);
  95114. function normalizeLogLevel(logLevel) {
  95115. if (!logLevel) {
  95116. return 0;
  95117. }
  95118. let resolvedLevel;
  95119. switch (typeof logLevel) {
  95120. case 'number':
  95121. resolvedLevel = logLevel;
  95122. break;
  95123. case 'object':
  95124. resolvedLevel = logLevel.logLevel || logLevel.priority || 0;
  95125. break;
  95126. default:
  95127. return 0;
  95128. }
  95129. assert$5(Number.isFinite(resolvedLevel) && resolvedLevel >= 0);
  95130. return resolvedLevel;
  95131. }
  95132. function normalizeArguments(opts) {
  95133. const {
  95134. logLevel,
  95135. message
  95136. } = opts;
  95137. opts.logLevel = normalizeLogLevel(logLevel);
  95138. const args = opts.args ? Array.from(opts.args) : [];
  95139. while (args.length && args.shift() !== message) {}
  95140. switch (typeof logLevel) {
  95141. case 'string':
  95142. case 'function':
  95143. if (message !== undefined) {
  95144. args.unshift(message);
  95145. }
  95146. opts.message = logLevel;
  95147. break;
  95148. case 'object':
  95149. Object.assign(opts, logLevel);
  95150. break;
  95151. }
  95152. if (typeof opts.message === 'function') {
  95153. opts.message = opts.message();
  95154. }
  95155. const messageType = typeof opts.message;
  95156. assert$5(messageType === 'string' || messageType === 'object');
  95157. return Object.assign(opts, {
  95158. args
  95159. }, opts.opts);
  95160. }
  95161. function decorateMessage(id, message, opts) {
  95162. if (typeof message === 'string') {
  95163. const time = opts.time ? leftPad(formatTime(opts.total)) : '';
  95164. message = opts.time ? "".concat(id, ": ").concat(time, " ").concat(message) : "".concat(id, ": ").concat(message);
  95165. message = addColor(message, opts.color, opts.background);
  95166. }
  95167. return message;
  95168. }
  95169. function logImageInNode(_ref2) {
  95170. let {
  95171. image,
  95172. message = '',
  95173. scale = 1
  95174. } = _ref2;
  95175. let asciify = null;
  95176. try {
  95177. asciify = module.require('asciify-image');
  95178. } catch (error) {}
  95179. if (asciify) {
  95180. return () => asciify(image, {
  95181. fit: 'box',
  95182. width: "".concat(Math.round(80 * scale), "%")
  95183. }).then(data => console.log(data));
  95184. }
  95185. return noop$1;
  95186. }
  95187. function logImageInBrowser(_ref3) {
  95188. let {
  95189. image,
  95190. message = '',
  95191. scale = 1
  95192. } = _ref3;
  95193. if (typeof image === 'string') {
  95194. const img = new Image();
  95195. img.onload = () => {
  95196. const args = formatImage(img, message, scale);
  95197. console.log(...args);
  95198. };
  95199. img.src = image;
  95200. return noop$1;
  95201. }
  95202. const element = image.nodeName || '';
  95203. if (element.toLowerCase() === 'img') {
  95204. console.log(...formatImage(image, message, scale));
  95205. return noop$1;
  95206. }
  95207. if (element.toLowerCase() === 'canvas') {
  95208. const img = new Image();
  95209. img.onload = () => console.log(...formatImage(img, message, scale));
  95210. img.src = image.toDataURL();
  95211. return noop$1;
  95212. }
  95213. return noop$1;
  95214. }
  95215. function getTableHeader(table) {
  95216. for (const key in table) {
  95217. for (const title in table[key]) {
  95218. return title || 'untitled';
  95219. }
  95220. }
  95221. return 'empty';
  95222. }
  95223. const probeLog = new Log({
  95224. id: 'loaders.gl'
  95225. });
  95226. class NullLog {
  95227. log() {
  95228. return () => {};
  95229. }
  95230. info() {
  95231. return () => {};
  95232. }
  95233. warn() {
  95234. return () => {};
  95235. }
  95236. error() {
  95237. return () => {};
  95238. }
  95239. }
  95240. class ConsoleLog {
  95241. constructor() {
  95242. _defineProperty(this, "console", void 0);
  95243. this.console = console;
  95244. }
  95245. log(...args) {
  95246. return this.console.log.bind(this.console, ...args);
  95247. }
  95248. info(...args) {
  95249. return this.console.info.bind(this.console, ...args);
  95250. }
  95251. warn(...args) {
  95252. return this.console.warn.bind(this.console, ...args);
  95253. }
  95254. error(...args) {
  95255. return this.console.error.bind(this.console, ...args);
  95256. }
  95257. }
  95258. const DEFAULT_LOADER_OPTIONS = {
  95259. fetch: null,
  95260. mimeType: undefined,
  95261. nothrow: false,
  95262. log: new ConsoleLog(),
  95263. CDN: 'https://unpkg.com/@loaders.gl',
  95264. worker: true,
  95265. maxConcurrency: 3,
  95266. maxMobileConcurrency: 1,
  95267. reuseWorkers: true,
  95268. _workerType: '',
  95269. limit: 0,
  95270. _limitMB: 0,
  95271. batchSize: 'auto',
  95272. batchDebounceMs: 0,
  95273. metadata: false,
  95274. transforms: []
  95275. };
  95276. const REMOVED_LOADER_OPTIONS = {
  95277. throws: 'nothrow',
  95278. dataType: '(no longer used)',
  95279. uri: 'baseUri',
  95280. method: 'fetch.method',
  95281. headers: 'fetch.headers',
  95282. body: 'fetch.body',
  95283. mode: 'fetch.mode',
  95284. credentials: 'fetch.credentials',
  95285. cache: 'fetch.cache',
  95286. redirect: 'fetch.redirect',
  95287. referrer: 'fetch.referrer',
  95288. referrerPolicy: 'fetch.referrerPolicy',
  95289. integrity: 'fetch.integrity',
  95290. keepalive: 'fetch.keepalive',
  95291. signal: 'fetch.signal'
  95292. };
  95293. function getGlobalLoaderState() {
  95294. globalThis.loaders = globalThis.loaders || {};
  95295. const {
  95296. loaders
  95297. } = globalThis;
  95298. loaders._state = loaders._state || {};
  95299. return loaders._state;
  95300. }
  95301. const getGlobalLoaderOptions = () => {
  95302. const state = getGlobalLoaderState();
  95303. state.globalOptions = state.globalOptions || { ...DEFAULT_LOADER_OPTIONS
  95304. };
  95305. return state.globalOptions;
  95306. };
  95307. function normalizeOptions(options, loader, loaders, url) {
  95308. loaders = loaders || [];
  95309. loaders = Array.isArray(loaders) ? loaders : [loaders];
  95310. validateOptions(options, loaders);
  95311. return normalizeOptionsInternal(loader, options, url);
  95312. }
  95313. function getFetchFunction(options, context) {
  95314. const globalOptions = getGlobalLoaderOptions();
  95315. const fetchOptions = options || globalOptions;
  95316. if (typeof fetchOptions.fetch === 'function') {
  95317. return fetchOptions.fetch;
  95318. }
  95319. if (isObject(fetchOptions.fetch)) {
  95320. return url => fetchFile(url, fetchOptions);
  95321. }
  95322. if (context !== null && context !== void 0 && context.fetch) {
  95323. return context === null || context === void 0 ? void 0 : context.fetch;
  95324. }
  95325. return fetchFile;
  95326. }
  95327. function validateOptions(options, loaders) {
  95328. validateOptionsObject(options, null, DEFAULT_LOADER_OPTIONS, REMOVED_LOADER_OPTIONS, loaders);
  95329. for (const loader of loaders) {
  95330. const idOptions = options && options[loader.id] || {};
  95331. const loaderOptions = loader.options && loader.options[loader.id] || {};
  95332. const deprecatedOptions = loader.deprecatedOptions && loader.deprecatedOptions[loader.id] || {};
  95333. validateOptionsObject(idOptions, loader.id, loaderOptions, deprecatedOptions, loaders);
  95334. }
  95335. }
  95336. function validateOptionsObject(options, id, defaultOptions, deprecatedOptions, loaders) {
  95337. const loaderName = id || 'Top level';
  95338. const prefix = id ? "".concat(id, ".") : '';
  95339. for (const key in options) {
  95340. const isSubOptions = !id && isObject(options[key]);
  95341. const isBaseUriOption = key === 'baseUri' && !id;
  95342. const isWorkerUrlOption = key === 'workerUrl' && id;
  95343. if (!(key in defaultOptions) && !isBaseUriOption && !isWorkerUrlOption) {
  95344. if (key in deprecatedOptions) {
  95345. probeLog.warn("".concat(loaderName, " loader option '").concat(prefix).concat(key, "' no longer supported, use '").concat(deprecatedOptions[key], "'"))();
  95346. } else if (!isSubOptions) {
  95347. const suggestion = findSimilarOption(key, loaders);
  95348. probeLog.warn("".concat(loaderName, " loader option '").concat(prefix).concat(key, "' not recognized. ").concat(suggestion))();
  95349. }
  95350. }
  95351. }
  95352. }
  95353. function findSimilarOption(optionKey, loaders) {
  95354. const lowerCaseOptionKey = optionKey.toLowerCase();
  95355. let bestSuggestion = '';
  95356. for (const loader of loaders) {
  95357. for (const key in loader.options) {
  95358. if (optionKey === key) {
  95359. return "Did you mean '".concat(loader.id, ".").concat(key, "'?");
  95360. }
  95361. const lowerCaseKey = key.toLowerCase();
  95362. const isPartialMatch = lowerCaseOptionKey.startsWith(lowerCaseKey) || lowerCaseKey.startsWith(lowerCaseOptionKey);
  95363. if (isPartialMatch) {
  95364. bestSuggestion = bestSuggestion || "Did you mean '".concat(loader.id, ".").concat(key, "'?");
  95365. }
  95366. }
  95367. }
  95368. return bestSuggestion;
  95369. }
  95370. function normalizeOptionsInternal(loader, options, url) {
  95371. const loaderDefaultOptions = loader.options || {};
  95372. const mergedOptions = { ...loaderDefaultOptions
  95373. };
  95374. addUrlOptions(mergedOptions, url);
  95375. if (mergedOptions.log === null) {
  95376. mergedOptions.log = new NullLog();
  95377. }
  95378. mergeNestedFields(mergedOptions, getGlobalLoaderOptions());
  95379. mergeNestedFields(mergedOptions, options);
  95380. return mergedOptions;
  95381. }
  95382. function mergeNestedFields(mergedOptions, options) {
  95383. for (const key in options) {
  95384. if (key in options) {
  95385. const value = options[key];
  95386. if (isPureObject(value) && isPureObject(mergedOptions[key])) {
  95387. mergedOptions[key] = { ...mergedOptions[key],
  95388. ...options[key]
  95389. };
  95390. } else {
  95391. mergedOptions[key] = options[key];
  95392. }
  95393. }
  95394. }
  95395. }
  95396. function addUrlOptions(options, url) {
  95397. if (url && !('baseUri' in options)) {
  95398. options.baseUri = url;
  95399. }
  95400. }
  95401. function isLoaderObject(loader) {
  95402. var _loader;
  95403. if (!loader) {
  95404. return false;
  95405. }
  95406. if (Array.isArray(loader)) {
  95407. loader = loader[0];
  95408. }
  95409. const hasExtensions = Array.isArray((_loader = loader) === null || _loader === void 0 ? void 0 : _loader.extensions);
  95410. return hasExtensions;
  95411. }
  95412. function normalizeLoader(loader) {
  95413. var _loader2, _loader3;
  95414. assert$7(loader, 'null loader');
  95415. assert$7(isLoaderObject(loader), 'invalid loader');
  95416. let options;
  95417. if (Array.isArray(loader)) {
  95418. options = loader[1];
  95419. loader = loader[0];
  95420. loader = { ...loader,
  95421. options: { ...loader.options,
  95422. ...options
  95423. }
  95424. };
  95425. }
  95426. if ((_loader2 = loader) !== null && _loader2 !== void 0 && _loader2.parseTextSync || (_loader3 = loader) !== null && _loader3 !== void 0 && _loader3.parseText) {
  95427. loader.text = true;
  95428. }
  95429. if (!loader.text) {
  95430. loader.binary = true;
  95431. }
  95432. return loader;
  95433. }
  95434. const getGlobalLoaderRegistry = () => {
  95435. const state = getGlobalLoaderState();
  95436. state.loaderRegistry = state.loaderRegistry || [];
  95437. return state.loaderRegistry;
  95438. };
  95439. function getRegisteredLoaders() {
  95440. return getGlobalLoaderRegistry();
  95441. }
  95442. const EXT_PATTERN = /\.([^.]+)$/;
  95443. async function selectLoader(data, loaders = [], options, context) {
  95444. if (!validHTTPResponse(data)) {
  95445. return null;
  95446. }
  95447. let loader = selectLoaderSync(data, loaders, { ...options,
  95448. nothrow: true
  95449. }, context);
  95450. if (loader) {
  95451. return loader;
  95452. }
  95453. if (isBlob(data)) {
  95454. data = await data.slice(0, 10).arrayBuffer();
  95455. loader = selectLoaderSync(data, loaders, options, context);
  95456. }
  95457. if (!loader && !(options !== null && options !== void 0 && options.nothrow)) {
  95458. throw new Error(getNoValidLoaderMessage(data));
  95459. }
  95460. return loader;
  95461. }
  95462. function selectLoaderSync(data, loaders = [], options, context) {
  95463. if (!validHTTPResponse(data)) {
  95464. return null;
  95465. }
  95466. if (loaders && !Array.isArray(loaders)) {
  95467. return normalizeLoader(loaders);
  95468. }
  95469. let candidateLoaders = [];
  95470. if (loaders) {
  95471. candidateLoaders = candidateLoaders.concat(loaders);
  95472. }
  95473. if (!(options !== null && options !== void 0 && options.ignoreRegisteredLoaders)) {
  95474. candidateLoaders.push(...getRegisteredLoaders());
  95475. }
  95476. normalizeLoaders(candidateLoaders);
  95477. const loader = selectLoaderInternal(data, candidateLoaders, options, context);
  95478. if (!loader && !(options !== null && options !== void 0 && options.nothrow)) {
  95479. throw new Error(getNoValidLoaderMessage(data));
  95480. }
  95481. return loader;
  95482. }
  95483. function selectLoaderInternal(data, loaders, options, context) {
  95484. const {
  95485. url,
  95486. type
  95487. } = getResourceUrlAndType(data);
  95488. const testUrl = url || (context === null || context === void 0 ? void 0 : context.url);
  95489. let loader = null;
  95490. if (options !== null && options !== void 0 && options.mimeType) {
  95491. loader = findLoaderByMIMEType(loaders, options === null || options === void 0 ? void 0 : options.mimeType);
  95492. }
  95493. loader = loader || findLoaderByUrl(loaders, testUrl);
  95494. loader = loader || findLoaderByMIMEType(loaders, type);
  95495. loader = loader || findLoaderByInitialBytes(loaders, data);
  95496. loader = loader || findLoaderByMIMEType(loaders, options === null || options === void 0 ? void 0 : options.fallbackMimeType);
  95497. return loader;
  95498. }
  95499. function validHTTPResponse(data) {
  95500. if (data instanceof Response) {
  95501. if (data.status === 204) {
  95502. return false;
  95503. }
  95504. }
  95505. return true;
  95506. }
  95507. function getNoValidLoaderMessage(data) {
  95508. const {
  95509. url,
  95510. type
  95511. } = getResourceUrlAndType(data);
  95512. let message = 'No valid loader found (';
  95513. message += url ? "".concat(filename(url), ", ") : 'no url provided, ';
  95514. message += "MIME type: ".concat(type ? "\"".concat(type, "\"") : 'not provided', ", ");
  95515. const firstCharacters = data ? getFirstCharacters(data) : '';
  95516. message += firstCharacters ? " first bytes: \"".concat(firstCharacters, "\"") : 'first bytes: not available';
  95517. message += ')';
  95518. return message;
  95519. }
  95520. function normalizeLoaders(loaders) {
  95521. for (const loader of loaders) {
  95522. normalizeLoader(loader);
  95523. }
  95524. }
  95525. function findLoaderByUrl(loaders, url) {
  95526. const match = url && EXT_PATTERN.exec(url);
  95527. const extension = match && match[1];
  95528. return extension ? findLoaderByExtension(loaders, extension) : null;
  95529. }
  95530. function findLoaderByExtension(loaders, extension) {
  95531. extension = extension.toLowerCase();
  95532. for (const loader of loaders) {
  95533. for (const loaderExtension of loader.extensions) {
  95534. if (loaderExtension.toLowerCase() === extension) {
  95535. return loader;
  95536. }
  95537. }
  95538. }
  95539. return null;
  95540. }
  95541. function findLoaderByMIMEType(loaders, mimeType) {
  95542. for (const loader of loaders) {
  95543. if (loader.mimeTypes && loader.mimeTypes.includes(mimeType)) {
  95544. return loader;
  95545. }
  95546. if (mimeType === "application/x.".concat(loader.id)) {
  95547. return loader;
  95548. }
  95549. }
  95550. return null;
  95551. }
  95552. function findLoaderByInitialBytes(loaders, data) {
  95553. if (!data) {
  95554. return null;
  95555. }
  95556. for (const loader of loaders) {
  95557. if (typeof data === 'string') {
  95558. if (testDataAgainstText(data, loader)) {
  95559. return loader;
  95560. }
  95561. } else if (ArrayBuffer.isView(data)) {
  95562. if (testDataAgainstBinary(data.buffer, data.byteOffset, loader)) {
  95563. return loader;
  95564. }
  95565. } else if (data instanceof ArrayBuffer) {
  95566. const byteOffset = 0;
  95567. if (testDataAgainstBinary(data, byteOffset, loader)) {
  95568. return loader;
  95569. }
  95570. }
  95571. }
  95572. return null;
  95573. }
  95574. function testDataAgainstText(data, loader) {
  95575. if (loader.testText) {
  95576. return loader.testText(data);
  95577. }
  95578. const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
  95579. return tests.some(test => data.startsWith(test));
  95580. }
  95581. function testDataAgainstBinary(data, byteOffset, loader) {
  95582. const tests = Array.isArray(loader.tests) ? loader.tests : [loader.tests];
  95583. return tests.some(test => testBinary(data, byteOffset, loader, test));
  95584. }
  95585. function testBinary(data, byteOffset, loader, test) {
  95586. if (test instanceof ArrayBuffer) {
  95587. return compareArrayBuffers(test, data, test.byteLength);
  95588. }
  95589. switch (typeof test) {
  95590. case 'function':
  95591. return test(data, loader);
  95592. case 'string':
  95593. const magic = getMagicString$2(data, byteOffset, test.length);
  95594. return test === magic;
  95595. default:
  95596. return false;
  95597. }
  95598. }
  95599. function getFirstCharacters(data, length = 5) {
  95600. if (typeof data === 'string') {
  95601. return data.slice(0, length);
  95602. } else if (ArrayBuffer.isView(data)) {
  95603. return getMagicString$2(data.buffer, data.byteOffset, length);
  95604. } else if (data instanceof ArrayBuffer) {
  95605. const byteOffset = 0;
  95606. return getMagicString$2(data, byteOffset, length);
  95607. }
  95608. return '';
  95609. }
  95610. function getMagicString$2(arrayBuffer, byteOffset, length) {
  95611. if (arrayBuffer.byteLength < byteOffset + length) {
  95612. return '';
  95613. }
  95614. const dataView = new DataView(arrayBuffer);
  95615. let magic = '';
  95616. for (let i = 0; i < length; i++) {
  95617. magic += String.fromCharCode(dataView.getUint8(byteOffset + i));
  95618. }
  95619. return magic;
  95620. }
  95621. const DEFAULT_CHUNK_SIZE$2 = 256 * 1024;
  95622. function* makeStringIterator(string, options) {
  95623. const chunkSize = (options === null || options === void 0 ? void 0 : options.chunkSize) || DEFAULT_CHUNK_SIZE$2;
  95624. let offset = 0;
  95625. const textEncoder = new TextEncoder();
  95626. while (offset < string.length) {
  95627. const chunkLength = Math.min(string.length - offset, chunkSize);
  95628. const chunk = string.slice(offset, offset + chunkLength);
  95629. offset += chunkLength;
  95630. yield textEncoder.encode(chunk);
  95631. }
  95632. }
  95633. const DEFAULT_CHUNK_SIZE$1 = 256 * 1024;
  95634. function* makeArrayBufferIterator(arrayBuffer, options = {}) {
  95635. const {
  95636. chunkSize = DEFAULT_CHUNK_SIZE$1
  95637. } = options;
  95638. let byteOffset = 0;
  95639. while (byteOffset < arrayBuffer.byteLength) {
  95640. const chunkByteLength = Math.min(arrayBuffer.byteLength - byteOffset, chunkSize);
  95641. const chunk = new ArrayBuffer(chunkByteLength);
  95642. const sourceArray = new Uint8Array(arrayBuffer, byteOffset, chunkByteLength);
  95643. const chunkArray = new Uint8Array(chunk);
  95644. chunkArray.set(sourceArray);
  95645. byteOffset += chunkByteLength;
  95646. yield chunk;
  95647. }
  95648. }
  95649. const DEFAULT_CHUNK_SIZE = 1024 * 1024;
  95650. async function* makeBlobIterator(blob, options) {
  95651. const chunkSize = (options === null || options === void 0 ? void 0 : options.chunkSize) || DEFAULT_CHUNK_SIZE;
  95652. let offset = 0;
  95653. while (offset < blob.size) {
  95654. const end = offset + chunkSize;
  95655. const chunk = await blob.slice(offset, end).arrayBuffer();
  95656. offset = end;
  95657. yield chunk;
  95658. }
  95659. }
  95660. function makeStreamIterator(stream, options) {
  95661. return isBrowser$2 ? makeBrowserStreamIterator(stream, options) : makeNodeStreamIterator(stream);
  95662. }
  95663. async function* makeBrowserStreamIterator(stream, options) {
  95664. const reader = stream.getReader();
  95665. let nextBatchPromise;
  95666. try {
  95667. while (true) {
  95668. const currentBatchPromise = nextBatchPromise || reader.read();
  95669. if (options !== null && options !== void 0 && options._streamReadAhead) {
  95670. nextBatchPromise = reader.read();
  95671. }
  95672. const {
  95673. done,
  95674. value
  95675. } = await currentBatchPromise;
  95676. if (done) {
  95677. return;
  95678. }
  95679. yield toArrayBuffer(value);
  95680. }
  95681. } catch (error) {
  95682. reader.releaseLock();
  95683. }
  95684. }
  95685. async function* makeNodeStreamIterator(stream, options) {
  95686. for await (const chunk of stream) {
  95687. yield toArrayBuffer(chunk);
  95688. }
  95689. }
  95690. function makeIterator(data, options) {
  95691. if (typeof data === 'string') {
  95692. return makeStringIterator(data, options);
  95693. }
  95694. if (data instanceof ArrayBuffer) {
  95695. return makeArrayBufferIterator(data, options);
  95696. }
  95697. if (isBlob(data)) {
  95698. return makeBlobIterator(data, options);
  95699. }
  95700. if (isReadableStream(data)) {
  95701. return makeStreamIterator(data, options);
  95702. }
  95703. if (isResponse(data)) {
  95704. const response = data;
  95705. return makeStreamIterator(response.body, options);
  95706. }
  95707. throw new Error('makeIterator');
  95708. }
  95709. const ERR_DATA = 'Cannot convert supplied data type';
  95710. function getArrayBufferOrStringFromDataSync(data, loader, options) {
  95711. if (loader.text && typeof data === 'string') {
  95712. return data;
  95713. }
  95714. if (isBuffer(data)) {
  95715. data = data.buffer;
  95716. }
  95717. if (data instanceof ArrayBuffer) {
  95718. const arrayBuffer = data;
  95719. if (loader.text && !loader.binary) {
  95720. const textDecoder = new TextDecoder('utf8');
  95721. return textDecoder.decode(arrayBuffer);
  95722. }
  95723. return arrayBuffer;
  95724. }
  95725. if (ArrayBuffer.isView(data)) {
  95726. if (loader.text && !loader.binary) {
  95727. const textDecoder = new TextDecoder('utf8');
  95728. return textDecoder.decode(data);
  95729. }
  95730. let arrayBuffer = data.buffer;
  95731. const byteLength = data.byteLength || data.length;
  95732. if (data.byteOffset !== 0 || byteLength !== arrayBuffer.byteLength) {
  95733. arrayBuffer = arrayBuffer.slice(data.byteOffset, data.byteOffset + byteLength);
  95734. }
  95735. return arrayBuffer;
  95736. }
  95737. throw new Error(ERR_DATA);
  95738. }
  95739. async function getArrayBufferOrStringFromData(data, loader, options) {
  95740. const isArrayBuffer = data instanceof ArrayBuffer || ArrayBuffer.isView(data);
  95741. if (typeof data === 'string' || isArrayBuffer) {
  95742. return getArrayBufferOrStringFromDataSync(data, loader);
  95743. }
  95744. if (isBlob(data)) {
  95745. data = await makeResponse(data);
  95746. }
  95747. if (isResponse(data)) {
  95748. const response = data;
  95749. await checkResponse(response);
  95750. return loader.binary ? await response.arrayBuffer() : await response.text();
  95751. }
  95752. if (isReadableStream(data)) {
  95753. data = makeIterator(data, options);
  95754. }
  95755. if (isIterable(data) || isAsyncIterable(data)) {
  95756. return concatenateArrayBuffersAsync(data);
  95757. }
  95758. throw new Error(ERR_DATA);
  95759. }
  95760. function getLoaderContext(context, options, previousContext = null) {
  95761. if (previousContext) {
  95762. return previousContext;
  95763. }
  95764. const resolvedContext = {
  95765. fetch: getFetchFunction(options, context),
  95766. ...context
  95767. };
  95768. if (!Array.isArray(resolvedContext.loaders)) {
  95769. resolvedContext.loaders = null;
  95770. }
  95771. return resolvedContext;
  95772. }
  95773. function getLoadersFromContext(loaders, context) {
  95774. if (!context && loaders && !Array.isArray(loaders)) {
  95775. return loaders;
  95776. }
  95777. let candidateLoaders;
  95778. if (loaders) {
  95779. candidateLoaders = Array.isArray(loaders) ? loaders : [loaders];
  95780. }
  95781. if (context && context.loaders) {
  95782. const contextLoaders = Array.isArray(context.loaders) ? context.loaders : [context.loaders];
  95783. candidateLoaders = candidateLoaders ? [...candidateLoaders, ...contextLoaders] : contextLoaders;
  95784. }
  95785. return candidateLoaders && candidateLoaders.length ? candidateLoaders : null;
  95786. }
  95787. async function parse$3(data, loaders, options, context) {
  95788. assert$6(!context || typeof context === 'object');
  95789. if (loaders && !Array.isArray(loaders) && !isLoaderObject(loaders)) {
  95790. context = undefined;
  95791. options = loaders;
  95792. loaders = undefined;
  95793. }
  95794. data = await data;
  95795. options = options || {};
  95796. const {
  95797. url
  95798. } = getResourceUrlAndType(data);
  95799. const typedLoaders = loaders;
  95800. const candidateLoaders = getLoadersFromContext(typedLoaders, context);
  95801. const loader = await selectLoader(data, candidateLoaders, options);
  95802. if (!loader) {
  95803. return null;
  95804. }
  95805. options = normalizeOptions(options, loader, candidateLoaders, url);
  95806. context = getLoaderContext({
  95807. url,
  95808. parse: parse$3,
  95809. loaders: candidateLoaders
  95810. }, options, context);
  95811. return await parseWithLoader(loader, data, options, context);
  95812. }
  95813. async function parseWithLoader(loader, data, options, context) {
  95814. validateWorkerVersion(loader);
  95815. data = await getArrayBufferOrStringFromData(data, loader, options);
  95816. if (loader.parseTextSync && typeof data === 'string') {
  95817. options.dataType = 'text';
  95818. return loader.parseTextSync(data, options, context, loader);
  95819. }
  95820. if (canParseWithWorker(loader, options)) {
  95821. return await parseWithWorker(loader, data, options, context, parse$3);
  95822. }
  95823. if (loader.parseText && typeof data === 'string') {
  95824. return await loader.parseText(data, options, context, loader);
  95825. }
  95826. if (loader.parse) {
  95827. return await loader.parse(data, options, context, loader);
  95828. }
  95829. assert$6(!loader.parseSync);
  95830. throw new Error("".concat(loader.id, " loader - no parser found and worker is disabled"));
  95831. }
  95832. async function load(url, loaders, options, context) {
  95833. if (!Array.isArray(loaders) && !isLoaderObject(loaders)) {
  95834. options = loaders;
  95835. loaders = undefined;
  95836. }
  95837. const fetch = getFetchFunction(options);
  95838. let data = url;
  95839. if (typeof url === 'string') {
  95840. data = await fetch(url);
  95841. }
  95842. if (isBlob(url)) {
  95843. data = await fetch(url);
  95844. }
  95845. return await parse$3(data, loaders, options);
  95846. }
  95847. function assert$4(condition, message) {
  95848. if (!condition) {
  95849. throw new Error("math.gl assertion ".concat(message));
  95850. }
  95851. }
  95852. const RADIANS_TO_DEGREES = 1 / Math.PI * 180;
  95853. const DEGREES_TO_RADIANS = 1 / 180 * Math.PI;
  95854. const config$2 = {};
  95855. config$2.EPSILON = 1e-12;
  95856. config$2.debug = false;
  95857. config$2.precision = 4;
  95858. config$2.printTypes = false;
  95859. config$2.printDegrees = false;
  95860. config$2.printRowMajor = true;
  95861. function round(value) {
  95862. return Math.round(value / config$2.EPSILON) * config$2.EPSILON;
  95863. }
  95864. function formatValue(value, {
  95865. precision = config$2.precision || 4
  95866. } = {}) {
  95867. value = round(value);
  95868. return "".concat(parseFloat(value.toPrecision(precision)));
  95869. }
  95870. function isArray(value) {
  95871. return Array.isArray(value) || ArrayBuffer.isView(value) && !(value instanceof DataView);
  95872. }
  95873. function duplicateArray(array) {
  95874. return array.clone ? array.clone() : new Array(array.length);
  95875. }
  95876. function map$1(value, func, result) {
  95877. if (isArray(value)) {
  95878. result = result || duplicateArray(value);
  95879. for (let i = 0; i < result.length && i < value.length; ++i) {
  95880. result[i] = func(value[i], i, result);
  95881. }
  95882. return result;
  95883. }
  95884. return func(value);
  95885. }
  95886. function toRadians(degrees) {
  95887. return radians(degrees);
  95888. }
  95889. function toDegrees(radians) {
  95890. return degrees(radians);
  95891. }
  95892. function radians(degrees, result) {
  95893. return map$1(degrees, degrees => degrees * DEGREES_TO_RADIANS, result);
  95894. }
  95895. function degrees(radians, result) {
  95896. return map$1(radians, radians => radians * RADIANS_TO_DEGREES, result);
  95897. }
  95898. function clamp(value, min, max) {
  95899. return map$1(value, value => Math.max(min, Math.min(max, value)));
  95900. }
  95901. function equals$1(a, b, epsilon) {
  95902. const oldEpsilon = config$2.EPSILON;
  95903. if (epsilon) {
  95904. config$2.EPSILON = epsilon;
  95905. }
  95906. try {
  95907. if (a === b) {
  95908. return true;
  95909. }
  95910. if (isArray(a) && isArray(b)) {
  95911. if (a.length !== b.length) {
  95912. return false;
  95913. }
  95914. for (let i = 0; i < a.length; ++i) {
  95915. if (!equals$1(a[i], b[i])) {
  95916. return false;
  95917. }
  95918. }
  95919. return true;
  95920. }
  95921. if (a && a.equals) {
  95922. return a.equals(b);
  95923. }
  95924. if (b && b.equals) {
  95925. return b.equals(a);
  95926. }
  95927. if (Number.isFinite(a) && Number.isFinite(b)) {
  95928. return Math.abs(a - b) <= config$2.EPSILON * Math.max(1.0, Math.abs(a), Math.abs(b));
  95929. }
  95930. return false;
  95931. } finally {
  95932. config$2.EPSILON = oldEpsilon;
  95933. }
  95934. }
  95935. function _extendableBuiltin(cls) {
  95936. function ExtendableBuiltin() {
  95937. var instance = Reflect.construct(cls, Array.from(arguments));
  95938. Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
  95939. return instance;
  95940. }
  95941. ExtendableBuiltin.prototype = Object.create(cls.prototype, {
  95942. constructor: {
  95943. value: cls,
  95944. enumerable: false,
  95945. writable: true,
  95946. configurable: true
  95947. }
  95948. });
  95949. if (Object.setPrototypeOf) {
  95950. Object.setPrototypeOf(ExtendableBuiltin, cls);
  95951. } else {
  95952. ExtendableBuiltin.__proto__ = cls;
  95953. }
  95954. return ExtendableBuiltin;
  95955. }
  95956. class MathArray extends _extendableBuiltin(Array) {
  95957. get ELEMENTS() {
  95958. assert$4(false);
  95959. return 0;
  95960. }
  95961. clone() {
  95962. return new this.constructor().copy(this);
  95963. }
  95964. from(arrayOrObject) {
  95965. return Array.isArray(arrayOrObject) ? this.copy(arrayOrObject) : this.fromObject(arrayOrObject);
  95966. }
  95967. fromArray(array, offset = 0) {
  95968. for (let i = 0; i < this.ELEMENTS; ++i) {
  95969. this[i] = array[i + offset];
  95970. }
  95971. return this.check();
  95972. }
  95973. to(arrayOrObject) {
  95974. if (arrayOrObject === this) {
  95975. return this;
  95976. }
  95977. return isArray(arrayOrObject) ? this.toArray(arrayOrObject) : this.toObject(arrayOrObject);
  95978. }
  95979. toTarget(target) {
  95980. return target ? this.to(target) : this;
  95981. }
  95982. toArray(array = [], offset = 0) {
  95983. for (let i = 0; i < this.ELEMENTS; ++i) {
  95984. array[offset + i] = this[i];
  95985. }
  95986. return array;
  95987. }
  95988. toFloat32Array() {
  95989. return new Float32Array(this);
  95990. }
  95991. toString() {
  95992. return this.formatString(config$2);
  95993. }
  95994. formatString(opts) {
  95995. let string = '';
  95996. for (let i = 0; i < this.ELEMENTS; ++i) {
  95997. string += (i > 0 ? ', ' : '') + formatValue(this[i], opts);
  95998. }
  95999. return "".concat(opts.printTypes ? this.constructor.name : '', "[").concat(string, "]");
  96000. }
  96001. equals(array) {
  96002. if (!array || this.length !== array.length) {
  96003. return false;
  96004. }
  96005. for (let i = 0; i < this.ELEMENTS; ++i) {
  96006. if (!equals$1(this[i], array[i])) {
  96007. return false;
  96008. }
  96009. }
  96010. return true;
  96011. }
  96012. exactEquals(array) {
  96013. if (!array || this.length !== array.length) {
  96014. return false;
  96015. }
  96016. for (let i = 0; i < this.ELEMENTS; ++i) {
  96017. if (this[i] !== array[i]) {
  96018. return false;
  96019. }
  96020. }
  96021. return true;
  96022. }
  96023. negate() {
  96024. for (let i = 0; i < this.ELEMENTS; ++i) {
  96025. this[i] = -this[i];
  96026. }
  96027. return this.check();
  96028. }
  96029. lerp(a, b, t) {
  96030. if (t === undefined) {
  96031. t = b;
  96032. b = a;
  96033. a = this;
  96034. }
  96035. for (let i = 0; i < this.ELEMENTS; ++i) {
  96036. const ai = a[i];
  96037. this[i] = ai + t * (b[i] - ai);
  96038. }
  96039. return this.check();
  96040. }
  96041. min(vector) {
  96042. for (let i = 0; i < this.ELEMENTS; ++i) {
  96043. this[i] = Math.min(vector[i], this[i]);
  96044. }
  96045. return this.check();
  96046. }
  96047. max(vector) {
  96048. for (let i = 0; i < this.ELEMENTS; ++i) {
  96049. this[i] = Math.max(vector[i], this[i]);
  96050. }
  96051. return this.check();
  96052. }
  96053. clamp(minVector, maxVector) {
  96054. for (let i = 0; i < this.ELEMENTS; ++i) {
  96055. this[i] = Math.min(Math.max(this[i], minVector[i]), maxVector[i]);
  96056. }
  96057. return this.check();
  96058. }
  96059. add(...vectors) {
  96060. for (const vector of vectors) {
  96061. for (let i = 0; i < this.ELEMENTS; ++i) {
  96062. this[i] += vector[i];
  96063. }
  96064. }
  96065. return this.check();
  96066. }
  96067. subtract(...vectors) {
  96068. for (const vector of vectors) {
  96069. for (let i = 0; i < this.ELEMENTS; ++i) {
  96070. this[i] -= vector[i];
  96071. }
  96072. }
  96073. return this.check();
  96074. }
  96075. scale(scale) {
  96076. if (Array.isArray(scale)) {
  96077. return this.multiply(scale);
  96078. }
  96079. for (let i = 0; i < this.ELEMENTS; ++i) {
  96080. this[i] *= scale;
  96081. }
  96082. return this.check();
  96083. }
  96084. sub(a) {
  96085. return this.subtract(a);
  96086. }
  96087. setScalar(a) {
  96088. for (let i = 0; i < this.ELEMENTS; ++i) {
  96089. this[i] = a;
  96090. }
  96091. return this.check();
  96092. }
  96093. addScalar(a) {
  96094. for (let i = 0; i < this.ELEMENTS; ++i) {
  96095. this[i] += a;
  96096. }
  96097. return this.check();
  96098. }
  96099. subScalar(a) {
  96100. return this.addScalar(-a);
  96101. }
  96102. multiplyScalar(scalar) {
  96103. for (let i = 0; i < this.ELEMENTS; ++i) {
  96104. this[i] *= scalar;
  96105. }
  96106. return this.check();
  96107. }
  96108. divideScalar(a) {
  96109. return this.scale(1 / a);
  96110. }
  96111. clampScalar(min, max) {
  96112. for (let i = 0; i < this.ELEMENTS; ++i) {
  96113. this[i] = Math.min(Math.max(this[i], min), max);
  96114. }
  96115. return this.check();
  96116. }
  96117. multiplyByScalar(scalar) {
  96118. return this.scale(scalar);
  96119. }
  96120. get elements() {
  96121. return this;
  96122. }
  96123. check() {
  96124. if (config$2.debug && !this.validate()) {
  96125. throw new Error("math.gl: ".concat(this.constructor.name, " some fields set to invalid numbers'"));
  96126. }
  96127. return this;
  96128. }
  96129. validate() {
  96130. let valid = this.length === this.ELEMENTS;
  96131. for (let i = 0; i < this.ELEMENTS; ++i) {
  96132. valid = valid && Number.isFinite(this[i]);
  96133. }
  96134. return valid;
  96135. }
  96136. }
  96137. function validateVector(v, length) {
  96138. if (v.length !== length) {
  96139. return false;
  96140. }
  96141. for (let i = 0; i < v.length; ++i) {
  96142. if (!Number.isFinite(v[i])) {
  96143. return false;
  96144. }
  96145. }
  96146. return true;
  96147. }
  96148. function checkNumber(value) {
  96149. if (!Number.isFinite(value)) {
  96150. throw new Error("Invalid number ".concat(value));
  96151. }
  96152. return value;
  96153. }
  96154. function checkVector(v, length, callerName = '') {
  96155. if (config$2.debug && !validateVector(v, length)) {
  96156. throw new Error("math.gl: ".concat(callerName, " some fields set to invalid numbers'"));
  96157. }
  96158. return v;
  96159. }
  96160. const map = {};
  96161. function deprecated(method, version) {
  96162. if (!map[method]) {
  96163. map[method] = true;
  96164. console.warn("".concat(method, " has been removed in version ").concat(version, ", see upgrade guide for more information"));
  96165. }
  96166. }
  96167. class Vector extends MathArray {
  96168. get ELEMENTS() {
  96169. assert$4(false);
  96170. return 0;
  96171. }
  96172. copy(vector) {
  96173. assert$4(false);
  96174. return this;
  96175. }
  96176. get x() {
  96177. return this[0];
  96178. }
  96179. set x(value) {
  96180. this[0] = checkNumber(value);
  96181. }
  96182. get y() {
  96183. return this[1];
  96184. }
  96185. set y(value) {
  96186. this[1] = checkNumber(value);
  96187. }
  96188. len() {
  96189. return Math.sqrt(this.lengthSquared());
  96190. }
  96191. magnitude() {
  96192. return this.len();
  96193. }
  96194. lengthSquared() {
  96195. let length = 0;
  96196. for (let i = 0; i < this.ELEMENTS; ++i) {
  96197. length += this[i] * this[i];
  96198. }
  96199. return length;
  96200. }
  96201. magnitudeSquared() {
  96202. return this.lengthSquared();
  96203. }
  96204. distance(mathArray) {
  96205. return Math.sqrt(this.distanceSquared(mathArray));
  96206. }
  96207. distanceSquared(mathArray) {
  96208. let length = 0;
  96209. for (let i = 0; i < this.ELEMENTS; ++i) {
  96210. const dist = this[i] - mathArray[i];
  96211. length += dist * dist;
  96212. }
  96213. return checkNumber(length);
  96214. }
  96215. dot(mathArray) {
  96216. let product = 0;
  96217. for (let i = 0; i < this.ELEMENTS; ++i) {
  96218. product += this[i] * mathArray[i];
  96219. }
  96220. return checkNumber(product);
  96221. }
  96222. normalize() {
  96223. const length = this.magnitude();
  96224. if (length !== 0) {
  96225. for (let i = 0; i < this.ELEMENTS; ++i) {
  96226. this[i] /= length;
  96227. }
  96228. }
  96229. return this.check();
  96230. }
  96231. multiply(...vectors) {
  96232. for (const vector of vectors) {
  96233. for (let i = 0; i < this.ELEMENTS; ++i) {
  96234. this[i] *= vector[i];
  96235. }
  96236. }
  96237. return this.check();
  96238. }
  96239. divide(...vectors) {
  96240. for (const vector of vectors) {
  96241. for (let i = 0; i < this.ELEMENTS; ++i) {
  96242. this[i] /= vector[i];
  96243. }
  96244. }
  96245. return this.check();
  96246. }
  96247. lengthSq() {
  96248. return this.lengthSquared();
  96249. }
  96250. distanceTo(vector) {
  96251. return this.distance(vector);
  96252. }
  96253. distanceToSquared(vector) {
  96254. return this.distanceSquared(vector);
  96255. }
  96256. getComponent(i) {
  96257. assert$4(i >= 0 && i < this.ELEMENTS, 'index is out of range');
  96258. return checkNumber(this[i]);
  96259. }
  96260. setComponent(i, value) {
  96261. assert$4(i >= 0 && i < this.ELEMENTS, 'index is out of range');
  96262. this[i] = value;
  96263. return this.check();
  96264. }
  96265. addVectors(a, b) {
  96266. return this.copy(a).add(b);
  96267. }
  96268. subVectors(a, b) {
  96269. return this.copy(a).subtract(b);
  96270. }
  96271. multiplyVectors(a, b) {
  96272. return this.copy(a).multiply(b);
  96273. }
  96274. addScaledVector(a, b) {
  96275. return this.add(new this.constructor(a).multiplyScalar(b));
  96276. }
  96277. }
  96278. /**
  96279. * Common utilities
  96280. * @module glMatrix
  96281. */
  96282. // Configuration Constants
  96283. var EPSILON = 0.000001;
  96284. var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
  96285. if (!Math.hypot) Math.hypot = function () {
  96286. var y = 0,
  96287. i = arguments.length;
  96288. while (i--) {
  96289. y += arguments[i] * arguments[i];
  96290. }
  96291. return Math.sqrt(y);
  96292. };
  96293. /**
  96294. * 2 Dimensional Vector
  96295. * @module vec2
  96296. */
  96297. /**
  96298. * Creates a new, empty vec2
  96299. *
  96300. * @returns {vec2} a new 2D vector
  96301. */
  96302. function create$4() {
  96303. var out = new ARRAY_TYPE(2);
  96304. if (ARRAY_TYPE != Float32Array) {
  96305. out[0] = 0;
  96306. out[1] = 0;
  96307. }
  96308. return out;
  96309. }
  96310. /**
  96311. * Transforms the vec2 with a mat2
  96312. *
  96313. * @param {vec2} out the receiving vector
  96314. * @param {ReadonlyVec2} a the vector to transform
  96315. * @param {ReadonlyMat2} m matrix to transform with
  96316. * @returns {vec2} out
  96317. */
  96318. function transformMat2(out, a, m) {
  96319. var x = a[0],
  96320. y = a[1];
  96321. out[0] = m[0] * x + m[2] * y;
  96322. out[1] = m[1] * x + m[3] * y;
  96323. return out;
  96324. }
  96325. /**
  96326. * Transforms the vec2 with a mat2d
  96327. *
  96328. * @param {vec2} out the receiving vector
  96329. * @param {ReadonlyVec2} a the vector to transform
  96330. * @param {ReadonlyMat2d} m matrix to transform with
  96331. * @returns {vec2} out
  96332. */
  96333. function transformMat2d(out, a, m) {
  96334. var x = a[0],
  96335. y = a[1];
  96336. out[0] = m[0] * x + m[2] * y + m[4];
  96337. out[1] = m[1] * x + m[3] * y + m[5];
  96338. return out;
  96339. }
  96340. /**
  96341. * Transforms the vec2 with a mat3
  96342. * 3rd vector component is implicitly '1'
  96343. *
  96344. * @param {vec2} out the receiving vector
  96345. * @param {ReadonlyVec2} a the vector to transform
  96346. * @param {ReadonlyMat3} m matrix to transform with
  96347. * @returns {vec2} out
  96348. */
  96349. function transformMat3$1(out, a, m) {
  96350. var x = a[0],
  96351. y = a[1];
  96352. out[0] = m[0] * x + m[3] * y + m[6];
  96353. out[1] = m[1] * x + m[4] * y + m[7];
  96354. return out;
  96355. }
  96356. /**
  96357. * Transforms the vec2 with a mat4
  96358. * 3rd vector component is implicitly '0'
  96359. * 4th vector component is implicitly '1'
  96360. *
  96361. * @param {vec2} out the receiving vector
  96362. * @param {ReadonlyVec2} a the vector to transform
  96363. * @param {ReadonlyMat4} m matrix to transform with
  96364. * @returns {vec2} out
  96365. */
  96366. function transformMat4$2(out, a, m) {
  96367. var x = a[0];
  96368. var y = a[1];
  96369. out[0] = m[0] * x + m[4] * y + m[12];
  96370. out[1] = m[1] * x + m[5] * y + m[13];
  96371. return out;
  96372. }
  96373. /**
  96374. * Perform some operation over an array of vec2s.
  96375. *
  96376. * @param {Array} a the array of vectors to iterate over
  96377. * @param {Number} stride Number of elements between the start of each vec2. If 0 assumes tightly packed
  96378. * @param {Number} offset Number of elements to skip at the beginning of the array
  96379. * @param {Number} count Number of vec2s to iterate over. If 0 iterates over entire array
  96380. * @param {Function} fn Function to call for each vector in the array
  96381. * @param {Object} [arg] additional argument to pass to fn
  96382. * @returns {Array} a
  96383. * @function
  96384. */
  96385. (function () {
  96386. var vec = create$4();
  96387. return function (a, stride, offset, count, fn, arg) {
  96388. var i, l;
  96389. if (!stride) {
  96390. stride = 2;
  96391. }
  96392. if (!offset) {
  96393. offset = 0;
  96394. }
  96395. if (count) {
  96396. l = Math.min(count * stride + offset, a.length);
  96397. } else {
  96398. l = a.length;
  96399. }
  96400. for (i = offset; i < l; i += stride) {
  96401. vec[0] = a[i];
  96402. vec[1] = a[i + 1];
  96403. fn(vec, vec, arg);
  96404. a[i] = vec[0];
  96405. a[i + 1] = vec[1];
  96406. }
  96407. return a;
  96408. };
  96409. })();
  96410. function vec2_transformMat4AsVector(out, a, m) {
  96411. const x = a[0];
  96412. const y = a[1];
  96413. const w = m[3] * x + m[7] * y || 1.0;
  96414. out[0] = (m[0] * x + m[4] * y) / w;
  96415. out[1] = (m[1] * x + m[5] * y) / w;
  96416. return out;
  96417. }
  96418. function vec3_transformMat4AsVector(out, a, m) {
  96419. const x = a[0];
  96420. const y = a[1];
  96421. const z = a[2];
  96422. const w = m[3] * x + m[7] * y + m[11] * z || 1.0;
  96423. out[0] = (m[0] * x + m[4] * y + m[8] * z) / w;
  96424. out[1] = (m[1] * x + m[5] * y + m[9] * z) / w;
  96425. out[2] = (m[2] * x + m[6] * y + m[10] * z) / w;
  96426. return out;
  96427. }
  96428. function vec3_transformMat2(out, a, m) {
  96429. const x = a[0];
  96430. const y = a[1];
  96431. out[0] = m[0] * x + m[2] * y;
  96432. out[1] = m[1] * x + m[3] * y;
  96433. out[2] = a[2];
  96434. return out;
  96435. }
  96436. function vec4_transformMat3(out, a, m) {
  96437. const x = a[0];
  96438. const y = a[1];
  96439. const z = a[2];
  96440. out[0] = m[0] * x + m[3] * y + m[6] * z;
  96441. out[1] = m[1] * x + m[4] * y + m[7] * z;
  96442. out[2] = m[2] * x + m[5] * y + m[8] * z;
  96443. out[3] = a[3];
  96444. return out;
  96445. }
  96446. class Vector2$1 extends Vector {
  96447. constructor(x = 0, y = 0) {
  96448. super(2);
  96449. if (isArray(x) && arguments.length === 1) {
  96450. this.copy(x);
  96451. } else {
  96452. if (config$2.debug) {
  96453. checkNumber(x);
  96454. checkNumber(y);
  96455. }
  96456. this[0] = x;
  96457. this[1] = y;
  96458. }
  96459. }
  96460. set(x, y) {
  96461. this[0] = x;
  96462. this[1] = y;
  96463. return this.check();
  96464. }
  96465. copy(array) {
  96466. this[0] = array[0];
  96467. this[1] = array[1];
  96468. return this.check();
  96469. }
  96470. fromObject(object) {
  96471. if (config$2.debug) {
  96472. checkNumber(object.x);
  96473. checkNumber(object.y);
  96474. }
  96475. this[0] = object.x;
  96476. this[1] = object.y;
  96477. return this.check();
  96478. }
  96479. toObject(object) {
  96480. object.x = this[0];
  96481. object.y = this[1];
  96482. return object;
  96483. }
  96484. get ELEMENTS() {
  96485. return 2;
  96486. }
  96487. horizontalAngle() {
  96488. return Math.atan2(this.y, this.x);
  96489. }
  96490. verticalAngle() {
  96491. return Math.atan2(this.x, this.y);
  96492. }
  96493. transform(matrix4) {
  96494. return this.transformAsPoint(matrix4);
  96495. }
  96496. transformAsPoint(matrix4) {
  96497. transformMat4$2(this, this, matrix4);
  96498. return this.check();
  96499. }
  96500. transformAsVector(matrix4) {
  96501. vec2_transformMat4AsVector(this, this, matrix4);
  96502. return this.check();
  96503. }
  96504. transformByMatrix3(matrix3) {
  96505. transformMat3$1(this, this, matrix3);
  96506. return this.check();
  96507. }
  96508. transformByMatrix2x3(matrix2x3) {
  96509. transformMat2d(this, this, matrix2x3);
  96510. return this.check();
  96511. }
  96512. transformByMatrix2(matrix2) {
  96513. transformMat2(this, this, matrix2);
  96514. return this.check();
  96515. }
  96516. }
  96517. /**
  96518. * 3 Dimensional Vector
  96519. * @module vec3
  96520. */
  96521. /**
  96522. * Creates a new, empty vec3
  96523. *
  96524. * @returns {vec3} a new 3D vector
  96525. */
  96526. function create$3() {
  96527. var out = new ARRAY_TYPE(3);
  96528. if (ARRAY_TYPE != Float32Array) {
  96529. out[0] = 0;
  96530. out[1] = 0;
  96531. out[2] = 0;
  96532. }
  96533. return out;
  96534. }
  96535. /**
  96536. * Calculates the length of a vec3
  96537. *
  96538. * @param {ReadonlyVec3} a vector to calculate length of
  96539. * @returns {Number} length of a
  96540. */
  96541. function length$2(a) {
  96542. var x = a[0];
  96543. var y = a[1];
  96544. var z = a[2];
  96545. return Math.hypot(x, y, z);
  96546. }
  96547. /**
  96548. * Creates a new vec3 initialized with the given values
  96549. *
  96550. * @param {Number} x X component
  96551. * @param {Number} y Y component
  96552. * @param {Number} z Z component
  96553. * @returns {vec3} a new 3D vector
  96554. */
  96555. function fromValues(x, y, z) {
  96556. var out = new ARRAY_TYPE(3);
  96557. out[0] = x;
  96558. out[1] = y;
  96559. out[2] = z;
  96560. return out;
  96561. }
  96562. /**
  96563. * Normalize a vec3
  96564. *
  96565. * @param {vec3} out the receiving vector
  96566. * @param {ReadonlyVec3} a vector to normalize
  96567. * @returns {vec3} out
  96568. */
  96569. function normalize$2(out, a) {
  96570. var x = a[0];
  96571. var y = a[1];
  96572. var z = a[2];
  96573. var len = x * x + y * y + z * z;
  96574. if (len > 0) {
  96575. //TODO: evaluate use of glm_invsqrt here?
  96576. len = 1 / Math.sqrt(len);
  96577. }
  96578. out[0] = a[0] * len;
  96579. out[1] = a[1] * len;
  96580. out[2] = a[2] * len;
  96581. return out;
  96582. }
  96583. /**
  96584. * Calculates the dot product of two vec3's
  96585. *
  96586. * @param {ReadonlyVec3} a the first operand
  96587. * @param {ReadonlyVec3} b the second operand
  96588. * @returns {Number} dot product of a and b
  96589. */
  96590. function dot$2(a, b) {
  96591. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
  96592. }
  96593. /**
  96594. * Computes the cross product of two vec3's
  96595. *
  96596. * @param {vec3} out the receiving vector
  96597. * @param {ReadonlyVec3} a the first operand
  96598. * @param {ReadonlyVec3} b the second operand
  96599. * @returns {vec3} out
  96600. */
  96601. function cross(out, a, b) {
  96602. var ax = a[0],
  96603. ay = a[1],
  96604. az = a[2];
  96605. var bx = b[0],
  96606. by = b[1],
  96607. bz = b[2];
  96608. out[0] = ay * bz - az * by;
  96609. out[1] = az * bx - ax * bz;
  96610. out[2] = ax * by - ay * bx;
  96611. return out;
  96612. }
  96613. /**
  96614. * Transforms the vec3 with a mat4.
  96615. * 4th vector component is implicitly '1'
  96616. *
  96617. * @param {vec3} out the receiving vector
  96618. * @param {ReadonlyVec3} a the vector to transform
  96619. * @param {ReadonlyMat4} m matrix to transform with
  96620. * @returns {vec3} out
  96621. */
  96622. function transformMat4$1(out, a, m) {
  96623. var x = a[0],
  96624. y = a[1],
  96625. z = a[2];
  96626. var w = m[3] * x + m[7] * y + m[11] * z + m[15];
  96627. w = w || 1.0;
  96628. out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
  96629. out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
  96630. out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
  96631. return out;
  96632. }
  96633. /**
  96634. * Transforms the vec3 with a mat3.
  96635. *
  96636. * @param {vec3} out the receiving vector
  96637. * @param {ReadonlyVec3} a the vector to transform
  96638. * @param {ReadonlyMat3} m the 3x3 matrix to transform with
  96639. * @returns {vec3} out
  96640. */
  96641. function transformMat3(out, a, m) {
  96642. var x = a[0],
  96643. y = a[1],
  96644. z = a[2];
  96645. out[0] = x * m[0] + y * m[3] + z * m[6];
  96646. out[1] = x * m[1] + y * m[4] + z * m[7];
  96647. out[2] = x * m[2] + y * m[5] + z * m[8];
  96648. return out;
  96649. }
  96650. /**
  96651. * Transforms the vec3 with a quat
  96652. * Can also be used for dual quaternions. (Multiply it with the real part)
  96653. *
  96654. * @param {vec3} out the receiving vector
  96655. * @param {ReadonlyVec3} a the vector to transform
  96656. * @param {ReadonlyQuat} q quaternion to transform with
  96657. * @returns {vec3} out
  96658. */
  96659. function transformQuat$1(out, a, q) {
  96660. // benchmarks: https://jsperf.com/quaternion-transform-vec3-implementations-fixed
  96661. var qx = q[0],
  96662. qy = q[1],
  96663. qz = q[2],
  96664. qw = q[3];
  96665. var x = a[0],
  96666. y = a[1],
  96667. z = a[2]; // var qvec = [qx, qy, qz];
  96668. // var uv = vec3.cross([], qvec, a);
  96669. var uvx = qy * z - qz * y,
  96670. uvy = qz * x - qx * z,
  96671. uvz = qx * y - qy * x; // var uuv = vec3.cross([], qvec, uv);
  96672. var uuvx = qy * uvz - qz * uvy,
  96673. uuvy = qz * uvx - qx * uvz,
  96674. uuvz = qx * uvy - qy * uvx; // vec3.scale(uv, uv, 2 * w);
  96675. var w2 = qw * 2;
  96676. uvx *= w2;
  96677. uvy *= w2;
  96678. uvz *= w2; // vec3.scale(uuv, uuv, 2);
  96679. uuvx *= 2;
  96680. uuvy *= 2;
  96681. uuvz *= 2; // return vec3.add(out, a, vec3.add(out, uv, uuv));
  96682. out[0] = x + uvx + uuvx;
  96683. out[1] = y + uvy + uuvy;
  96684. out[2] = z + uvz + uuvz;
  96685. return out;
  96686. }
  96687. /**
  96688. * Rotate a 3D vector around the x-axis
  96689. * @param {vec3} out The receiving vec3
  96690. * @param {ReadonlyVec3} a The vec3 point to rotate
  96691. * @param {ReadonlyVec3} b The origin of the rotation
  96692. * @param {Number} rad The angle of rotation in radians
  96693. * @returns {vec3} out
  96694. */
  96695. function rotateX$2(out, a, b, rad) {
  96696. var p = [],
  96697. r = []; //Translate point to the origin
  96698. p[0] = a[0] - b[0];
  96699. p[1] = a[1] - b[1];
  96700. p[2] = a[2] - b[2]; //perform rotation
  96701. r[0] = p[0];
  96702. r[1] = p[1] * Math.cos(rad) - p[2] * Math.sin(rad);
  96703. r[2] = p[1] * Math.sin(rad) + p[2] * Math.cos(rad); //translate to correct position
  96704. out[0] = r[0] + b[0];
  96705. out[1] = r[1] + b[1];
  96706. out[2] = r[2] + b[2];
  96707. return out;
  96708. }
  96709. /**
  96710. * Rotate a 3D vector around the y-axis
  96711. * @param {vec3} out The receiving vec3
  96712. * @param {ReadonlyVec3} a The vec3 point to rotate
  96713. * @param {ReadonlyVec3} b The origin of the rotation
  96714. * @param {Number} rad The angle of rotation in radians
  96715. * @returns {vec3} out
  96716. */
  96717. function rotateY$2(out, a, b, rad) {
  96718. var p = [],
  96719. r = []; //Translate point to the origin
  96720. p[0] = a[0] - b[0];
  96721. p[1] = a[1] - b[1];
  96722. p[2] = a[2] - b[2]; //perform rotation
  96723. r[0] = p[2] * Math.sin(rad) + p[0] * Math.cos(rad);
  96724. r[1] = p[1];
  96725. r[2] = p[2] * Math.cos(rad) - p[0] * Math.sin(rad); //translate to correct position
  96726. out[0] = r[0] + b[0];
  96727. out[1] = r[1] + b[1];
  96728. out[2] = r[2] + b[2];
  96729. return out;
  96730. }
  96731. /**
  96732. * Rotate a 3D vector around the z-axis
  96733. * @param {vec3} out The receiving vec3
  96734. * @param {ReadonlyVec3} a The vec3 point to rotate
  96735. * @param {ReadonlyVec3} b The origin of the rotation
  96736. * @param {Number} rad The angle of rotation in radians
  96737. * @returns {vec3} out
  96738. */
  96739. function rotateZ$2(out, a, b, rad) {
  96740. var p = [],
  96741. r = []; //Translate point to the origin
  96742. p[0] = a[0] - b[0];
  96743. p[1] = a[1] - b[1];
  96744. p[2] = a[2] - b[2]; //perform rotation
  96745. r[0] = p[0] * Math.cos(rad) - p[1] * Math.sin(rad);
  96746. r[1] = p[0] * Math.sin(rad) + p[1] * Math.cos(rad);
  96747. r[2] = p[2]; //translate to correct position
  96748. out[0] = r[0] + b[0];
  96749. out[1] = r[1] + b[1];
  96750. out[2] = r[2] + b[2];
  96751. return out;
  96752. }
  96753. /**
  96754. * Get the angle between two 3D vectors
  96755. * @param {ReadonlyVec3} a The first operand
  96756. * @param {ReadonlyVec3} b The second operand
  96757. * @returns {Number} The angle in radians
  96758. */
  96759. function angle$1(a, b) {
  96760. var ax = a[0],
  96761. ay = a[1],
  96762. az = a[2],
  96763. bx = b[0],
  96764. by = b[1],
  96765. bz = b[2],
  96766. mag1 = Math.sqrt(ax * ax + ay * ay + az * az),
  96767. mag2 = Math.sqrt(bx * bx + by * by + bz * bz),
  96768. mag = mag1 * mag2,
  96769. cosine = mag && dot$2(a, b) / mag;
  96770. return Math.acos(Math.min(Math.max(cosine, -1), 1));
  96771. }
  96772. /**
  96773. * Alias for {@link vec3.length}
  96774. * @function
  96775. */
  96776. var len = length$2;
  96777. /**
  96778. * Perform some operation over an array of vec3s.
  96779. *
  96780. * @param {Array} a the array of vectors to iterate over
  96781. * @param {Number} stride Number of elements between the start of each vec3. If 0 assumes tightly packed
  96782. * @param {Number} offset Number of elements to skip at the beginning of the array
  96783. * @param {Number} count Number of vec3s to iterate over. If 0 iterates over entire array
  96784. * @param {Function} fn Function to call for each vector in the array
  96785. * @param {Object} [arg] additional argument to pass to fn
  96786. * @returns {Array} a
  96787. * @function
  96788. */
  96789. (function () {
  96790. var vec = create$3();
  96791. return function (a, stride, offset, count, fn, arg) {
  96792. var i, l;
  96793. if (!stride) {
  96794. stride = 3;
  96795. }
  96796. if (!offset) {
  96797. offset = 0;
  96798. }
  96799. if (count) {
  96800. l = Math.min(count * stride + offset, a.length);
  96801. } else {
  96802. l = a.length;
  96803. }
  96804. for (i = offset; i < l; i += stride) {
  96805. vec[0] = a[i];
  96806. vec[1] = a[i + 1];
  96807. vec[2] = a[i + 2];
  96808. fn(vec, vec, arg);
  96809. a[i] = vec[0];
  96810. a[i + 1] = vec[1];
  96811. a[i + 2] = vec[2];
  96812. }
  96813. return a;
  96814. };
  96815. })();
  96816. const ORIGIN = [0, 0, 0];
  96817. const constants$2 = {};
  96818. class Vector3$1 extends Vector {
  96819. static get ZERO() {
  96820. return constants$2.ZERO = constants$2.ZERO || Object.freeze(new Vector3$1(0, 0, 0, 0));
  96821. }
  96822. constructor(x = 0, y = 0, z = 0) {
  96823. super(-0, -0, -0);
  96824. if (arguments.length === 1 && isArray(x)) {
  96825. this.copy(x);
  96826. } else {
  96827. if (config$2.debug) {
  96828. checkNumber(x);
  96829. checkNumber(y);
  96830. checkNumber(z);
  96831. }
  96832. this[0] = x;
  96833. this[1] = y;
  96834. this[2] = z;
  96835. }
  96836. }
  96837. set(x, y, z) {
  96838. this[0] = x;
  96839. this[1] = y;
  96840. this[2] = z;
  96841. return this.check();
  96842. }
  96843. copy(array) {
  96844. this[0] = array[0];
  96845. this[1] = array[1];
  96846. this[2] = array[2];
  96847. return this.check();
  96848. }
  96849. fromObject(object) {
  96850. if (config$2.debug) {
  96851. checkNumber(object.x);
  96852. checkNumber(object.y);
  96853. checkNumber(object.z);
  96854. }
  96855. this[0] = object.x;
  96856. this[1] = object.y;
  96857. this[2] = object.z;
  96858. return this.check();
  96859. }
  96860. toObject(object) {
  96861. object.x = this[0];
  96862. object.y = this[1];
  96863. object.z = this[2];
  96864. return object;
  96865. }
  96866. get ELEMENTS() {
  96867. return 3;
  96868. }
  96869. get z() {
  96870. return this[2];
  96871. }
  96872. set z(value) {
  96873. this[2] = checkNumber(value);
  96874. }
  96875. angle(vector) {
  96876. return angle$1(this, vector);
  96877. }
  96878. cross(vector) {
  96879. cross(this, this, vector);
  96880. return this.check();
  96881. }
  96882. rotateX({
  96883. radians,
  96884. origin = ORIGIN
  96885. }) {
  96886. rotateX$2(this, this, origin, radians);
  96887. return this.check();
  96888. }
  96889. rotateY({
  96890. radians,
  96891. origin = ORIGIN
  96892. }) {
  96893. rotateY$2(this, this, origin, radians);
  96894. return this.check();
  96895. }
  96896. rotateZ({
  96897. radians,
  96898. origin = ORIGIN
  96899. }) {
  96900. rotateZ$2(this, this, origin, radians);
  96901. return this.check();
  96902. }
  96903. transform(matrix4) {
  96904. return this.transformAsPoint(matrix4);
  96905. }
  96906. transformAsPoint(matrix4) {
  96907. transformMat4$1(this, this, matrix4);
  96908. return this.check();
  96909. }
  96910. transformAsVector(matrix4) {
  96911. vec3_transformMat4AsVector(this, this, matrix4);
  96912. return this.check();
  96913. }
  96914. transformByMatrix3(matrix3) {
  96915. transformMat3(this, this, matrix3);
  96916. return this.check();
  96917. }
  96918. transformByMatrix2(matrix2) {
  96919. vec3_transformMat2(this, this, matrix2);
  96920. return this.check();
  96921. }
  96922. transformByQuaternion(quaternion) {
  96923. transformQuat$1(this, this, quaternion);
  96924. return this.check();
  96925. }
  96926. }
  96927. class Matrix extends MathArray {
  96928. get ELEMENTS() {
  96929. assert$4(false);
  96930. return 0;
  96931. }
  96932. get RANK() {
  96933. assert$4(false);
  96934. return 0;
  96935. }
  96936. toString() {
  96937. let string = '[';
  96938. if (config$2.printRowMajor) {
  96939. string += 'row-major:';
  96940. for (let row = 0; row < this.RANK; ++row) {
  96941. for (let col = 0; col < this.RANK; ++col) {
  96942. string += " ".concat(this[col * this.RANK + row]);
  96943. }
  96944. }
  96945. } else {
  96946. string += 'column-major:';
  96947. for (let i = 0; i < this.ELEMENTS; ++i) {
  96948. string += " ".concat(this[i]);
  96949. }
  96950. }
  96951. string += ']';
  96952. return string;
  96953. }
  96954. getElementIndex(row, col) {
  96955. return col * this.RANK + row;
  96956. }
  96957. getElement(row, col) {
  96958. return this[col * this.RANK + row];
  96959. }
  96960. setElement(row, col, value) {
  96961. this[col * this.RANK + row] = checkNumber(value);
  96962. return this;
  96963. }
  96964. getColumn(columnIndex, result = new Array(this.RANK).fill(-0)) {
  96965. const firstIndex = columnIndex * this.RANK;
  96966. for (let i = 0; i < this.RANK; ++i) {
  96967. result[i] = this[firstIndex + i];
  96968. }
  96969. return result;
  96970. }
  96971. setColumn(columnIndex, columnVector) {
  96972. const firstIndex = columnIndex * this.RANK;
  96973. for (let i = 0; i < this.RANK; ++i) {
  96974. this[firstIndex + i] = columnVector[i];
  96975. }
  96976. return this;
  96977. }
  96978. }
  96979. /**
  96980. * 3x3 Matrix
  96981. * @module mat3
  96982. */
  96983. /**
  96984. * Creates a new identity mat3
  96985. *
  96986. * @returns {mat3} a new 3x3 matrix
  96987. */
  96988. function create$2() {
  96989. var out = new ARRAY_TYPE(9);
  96990. if (ARRAY_TYPE != Float32Array) {
  96991. out[1] = 0;
  96992. out[2] = 0;
  96993. out[3] = 0;
  96994. out[5] = 0;
  96995. out[6] = 0;
  96996. out[7] = 0;
  96997. }
  96998. out[0] = 1;
  96999. out[4] = 1;
  97000. out[8] = 1;
  97001. return out;
  97002. }
  97003. /**
  97004. * Transpose the values of a mat3
  97005. *
  97006. * @param {mat3} out the receiving matrix
  97007. * @param {ReadonlyMat3} a the source matrix
  97008. * @returns {mat3} out
  97009. */
  97010. function transpose$1(out, a) {
  97011. // If we are transposing ourselves we can skip a few steps but have to cache some values
  97012. if (out === a) {
  97013. var a01 = a[1],
  97014. a02 = a[2],
  97015. a12 = a[5];
  97016. out[1] = a[3];
  97017. out[2] = a[6];
  97018. out[3] = a01;
  97019. out[5] = a[7];
  97020. out[6] = a02;
  97021. out[7] = a12;
  97022. } else {
  97023. out[0] = a[0];
  97024. out[1] = a[3];
  97025. out[2] = a[6];
  97026. out[3] = a[1];
  97027. out[4] = a[4];
  97028. out[5] = a[7];
  97029. out[6] = a[2];
  97030. out[7] = a[5];
  97031. out[8] = a[8];
  97032. }
  97033. return out;
  97034. }
  97035. /**
  97036. * Inverts a mat3
  97037. *
  97038. * @param {mat3} out the receiving matrix
  97039. * @param {ReadonlyMat3} a the source matrix
  97040. * @returns {mat3} out
  97041. */
  97042. function invert$2(out, a) {
  97043. var a00 = a[0],
  97044. a01 = a[1],
  97045. a02 = a[2];
  97046. var a10 = a[3],
  97047. a11 = a[4],
  97048. a12 = a[5];
  97049. var a20 = a[6],
  97050. a21 = a[7],
  97051. a22 = a[8];
  97052. var b01 = a22 * a11 - a12 * a21;
  97053. var b11 = -a22 * a10 + a12 * a20;
  97054. var b21 = a21 * a10 - a11 * a20; // Calculate the determinant
  97055. var det = a00 * b01 + a01 * b11 + a02 * b21;
  97056. if (!det) {
  97057. return null;
  97058. }
  97059. det = 1.0 / det;
  97060. out[0] = b01 * det;
  97061. out[1] = (-a22 * a01 + a02 * a21) * det;
  97062. out[2] = (a12 * a01 - a02 * a11) * det;
  97063. out[3] = b11 * det;
  97064. out[4] = (a22 * a00 - a02 * a20) * det;
  97065. out[5] = (-a12 * a00 + a02 * a10) * det;
  97066. out[6] = b21 * det;
  97067. out[7] = (-a21 * a00 + a01 * a20) * det;
  97068. out[8] = (a11 * a00 - a01 * a10) * det;
  97069. return out;
  97070. }
  97071. /**
  97072. * Calculates the determinant of a mat3
  97073. *
  97074. * @param {ReadonlyMat3} a the source matrix
  97075. * @returns {Number} determinant of a
  97076. */
  97077. function determinant$1(a) {
  97078. var a00 = a[0],
  97079. a01 = a[1],
  97080. a02 = a[2];
  97081. var a10 = a[3],
  97082. a11 = a[4],
  97083. a12 = a[5];
  97084. var a20 = a[6],
  97085. a21 = a[7],
  97086. a22 = a[8];
  97087. return a00 * (a22 * a11 - a12 * a21) + a01 * (-a22 * a10 + a12 * a20) + a02 * (a21 * a10 - a11 * a20);
  97088. }
  97089. /**
  97090. * Multiplies two mat3's
  97091. *
  97092. * @param {mat3} out the receiving matrix
  97093. * @param {ReadonlyMat3} a the first operand
  97094. * @param {ReadonlyMat3} b the second operand
  97095. * @returns {mat3} out
  97096. */
  97097. function multiply$2(out, a, b) {
  97098. var a00 = a[0],
  97099. a01 = a[1],
  97100. a02 = a[2];
  97101. var a10 = a[3],
  97102. a11 = a[4],
  97103. a12 = a[5];
  97104. var a20 = a[6],
  97105. a21 = a[7],
  97106. a22 = a[8];
  97107. var b00 = b[0],
  97108. b01 = b[1],
  97109. b02 = b[2];
  97110. var b10 = b[3],
  97111. b11 = b[4],
  97112. b12 = b[5];
  97113. var b20 = b[6],
  97114. b21 = b[7],
  97115. b22 = b[8];
  97116. out[0] = b00 * a00 + b01 * a10 + b02 * a20;
  97117. out[1] = b00 * a01 + b01 * a11 + b02 * a21;
  97118. out[2] = b00 * a02 + b01 * a12 + b02 * a22;
  97119. out[3] = b10 * a00 + b11 * a10 + b12 * a20;
  97120. out[4] = b10 * a01 + b11 * a11 + b12 * a21;
  97121. out[5] = b10 * a02 + b11 * a12 + b12 * a22;
  97122. out[6] = b20 * a00 + b21 * a10 + b22 * a20;
  97123. out[7] = b20 * a01 + b21 * a11 + b22 * a21;
  97124. out[8] = b20 * a02 + b21 * a12 + b22 * a22;
  97125. return out;
  97126. }
  97127. /**
  97128. * Translate a mat3 by the given vector
  97129. *
  97130. * @param {mat3} out the receiving matrix
  97131. * @param {ReadonlyMat3} a the matrix to translate
  97132. * @param {ReadonlyVec2} v vector to translate by
  97133. * @returns {mat3} out
  97134. */
  97135. function translate$1(out, a, v) {
  97136. var a00 = a[0],
  97137. a01 = a[1],
  97138. a02 = a[2],
  97139. a10 = a[3],
  97140. a11 = a[4],
  97141. a12 = a[5],
  97142. a20 = a[6],
  97143. a21 = a[7],
  97144. a22 = a[8],
  97145. x = v[0],
  97146. y = v[1];
  97147. out[0] = a00;
  97148. out[1] = a01;
  97149. out[2] = a02;
  97150. out[3] = a10;
  97151. out[4] = a11;
  97152. out[5] = a12;
  97153. out[6] = x * a00 + y * a10 + a20;
  97154. out[7] = x * a01 + y * a11 + a21;
  97155. out[8] = x * a02 + y * a12 + a22;
  97156. return out;
  97157. }
  97158. /**
  97159. * Rotates a mat3 by the given angle
  97160. *
  97161. * @param {mat3} out the receiving matrix
  97162. * @param {ReadonlyMat3} a the matrix to rotate
  97163. * @param {Number} rad the angle to rotate the matrix by
  97164. * @returns {mat3} out
  97165. */
  97166. function rotate$1(out, a, rad) {
  97167. var a00 = a[0],
  97168. a01 = a[1],
  97169. a02 = a[2],
  97170. a10 = a[3],
  97171. a11 = a[4],
  97172. a12 = a[5],
  97173. a20 = a[6],
  97174. a21 = a[7],
  97175. a22 = a[8],
  97176. s = Math.sin(rad),
  97177. c = Math.cos(rad);
  97178. out[0] = c * a00 + s * a10;
  97179. out[1] = c * a01 + s * a11;
  97180. out[2] = c * a02 + s * a12;
  97181. out[3] = c * a10 - s * a00;
  97182. out[4] = c * a11 - s * a01;
  97183. out[5] = c * a12 - s * a02;
  97184. out[6] = a20;
  97185. out[7] = a21;
  97186. out[8] = a22;
  97187. return out;
  97188. }
  97189. /**
  97190. * Scales the mat3 by the dimensions in the given vec2
  97191. *
  97192. * @param {mat3} out the receiving matrix
  97193. * @param {ReadonlyMat3} a the matrix to rotate
  97194. * @param {ReadonlyVec2} v the vec2 to scale the matrix by
  97195. * @returns {mat3} out
  97196. **/
  97197. function scale$3(out, a, v) {
  97198. var x = v[0],
  97199. y = v[1];
  97200. out[0] = x * a[0];
  97201. out[1] = x * a[1];
  97202. out[2] = x * a[2];
  97203. out[3] = y * a[3];
  97204. out[4] = y * a[4];
  97205. out[5] = y * a[5];
  97206. out[6] = a[6];
  97207. out[7] = a[7];
  97208. out[8] = a[8];
  97209. return out;
  97210. }
  97211. /**
  97212. * Calculates a 3x3 matrix from the given quaternion
  97213. *
  97214. * @param {mat3} out mat3 receiving operation result
  97215. * @param {ReadonlyQuat} q Quaternion to create matrix from
  97216. *
  97217. * @returns {mat3} out
  97218. */
  97219. function fromQuat$1(out, q) {
  97220. var x = q[0],
  97221. y = q[1],
  97222. z = q[2],
  97223. w = q[3];
  97224. var x2 = x + x;
  97225. var y2 = y + y;
  97226. var z2 = z + z;
  97227. var xx = x * x2;
  97228. var yx = y * x2;
  97229. var yy = y * y2;
  97230. var zx = z * x2;
  97231. var zy = z * y2;
  97232. var zz = z * z2;
  97233. var wx = w * x2;
  97234. var wy = w * y2;
  97235. var wz = w * z2;
  97236. out[0] = 1 - yy - zz;
  97237. out[3] = yx - wz;
  97238. out[6] = zx + wy;
  97239. out[1] = yx + wz;
  97240. out[4] = 1 - xx - zz;
  97241. out[7] = zy - wx;
  97242. out[2] = zx - wy;
  97243. out[5] = zy + wx;
  97244. out[8] = 1 - xx - yy;
  97245. return out;
  97246. }
  97247. const IDENTITY$1 = Object.freeze([1, 0, 0, 0, 1, 0, 0, 0, 1]);
  97248. const ZERO$1 = Object.freeze([0, 0, 0, 0, 0, 0, 0, 0, 0]);
  97249. const INDICES$1 = Object.freeze({
  97250. COL0ROW0: 0,
  97251. COL0ROW1: 1,
  97252. COL0ROW2: 2,
  97253. COL1ROW0: 3,
  97254. COL1ROW1: 4,
  97255. COL1ROW2: 5,
  97256. COL2ROW0: 6,
  97257. COL2ROW1: 7,
  97258. COL2ROW2: 8
  97259. });
  97260. const constants$1 = {};
  97261. class Matrix3$1 extends Matrix {
  97262. static get IDENTITY() {
  97263. constants$1.IDENTITY = constants$1.IDENTITY || Object.freeze(new Matrix3$1(IDENTITY$1));
  97264. return constants$1.IDENTITY;
  97265. }
  97266. static get ZERO() {
  97267. constants$1.ZERO = constants$1.ZERO || Object.freeze(new Matrix3$1(ZERO$1));
  97268. return constants$1.ZERO;
  97269. }
  97270. get ELEMENTS() {
  97271. return 9;
  97272. }
  97273. get RANK() {
  97274. return 3;
  97275. }
  97276. get INDICES() {
  97277. return INDICES$1;
  97278. }
  97279. constructor(array) {
  97280. super(-0, -0, -0, -0, -0, -0, -0, -0, -0);
  97281. if (arguments.length === 1 && Array.isArray(array)) {
  97282. this.copy(array);
  97283. } else {
  97284. this.identity();
  97285. }
  97286. }
  97287. copy(array) {
  97288. this[0] = array[0];
  97289. this[1] = array[1];
  97290. this[2] = array[2];
  97291. this[3] = array[3];
  97292. this[4] = array[4];
  97293. this[5] = array[5];
  97294. this[6] = array[6];
  97295. this[7] = array[7];
  97296. this[8] = array[8];
  97297. return this.check();
  97298. }
  97299. set(m00, m10, m20, m01, m11, m21, m02, m12, m22) {
  97300. this[0] = m00;
  97301. this[1] = m10;
  97302. this[2] = m20;
  97303. this[3] = m01;
  97304. this[4] = m11;
  97305. this[5] = m21;
  97306. this[6] = m02;
  97307. this[7] = m12;
  97308. this[8] = m22;
  97309. return this.check();
  97310. }
  97311. setRowMajor(m00, m01, m02, m10, m11, m12, m20, m21, m22) {
  97312. this[0] = m00;
  97313. this[1] = m10;
  97314. this[2] = m20;
  97315. this[3] = m01;
  97316. this[4] = m11;
  97317. this[5] = m21;
  97318. this[6] = m02;
  97319. this[7] = m12;
  97320. this[8] = m22;
  97321. return this.check();
  97322. }
  97323. determinant() {
  97324. return determinant$1(this);
  97325. }
  97326. identity() {
  97327. return this.copy(IDENTITY$1);
  97328. }
  97329. fromQuaternion(q) {
  97330. fromQuat$1(this, q);
  97331. return this.check();
  97332. }
  97333. transpose() {
  97334. transpose$1(this, this);
  97335. return this.check();
  97336. }
  97337. invert() {
  97338. invert$2(this, this);
  97339. return this.check();
  97340. }
  97341. multiplyLeft(a) {
  97342. multiply$2(this, a, this);
  97343. return this.check();
  97344. }
  97345. multiplyRight(a) {
  97346. multiply$2(this, this, a);
  97347. return this.check();
  97348. }
  97349. rotate(radians) {
  97350. rotate$1(this, this, radians);
  97351. return this.check();
  97352. }
  97353. scale(factor) {
  97354. if (Array.isArray(factor)) {
  97355. scale$3(this, this, factor);
  97356. } else {
  97357. scale$3(this, this, [factor, factor, factor]);
  97358. }
  97359. return this.check();
  97360. }
  97361. translate(vec) {
  97362. translate$1(this, this, vec);
  97363. return this.check();
  97364. }
  97365. transform(vector, result) {
  97366. switch (vector.length) {
  97367. case 2:
  97368. result = transformMat3$1(result || [-0, -0], vector, this);
  97369. break;
  97370. case 3:
  97371. result = transformMat3(result || [-0, -0, -0], vector, this);
  97372. break;
  97373. case 4:
  97374. result = vec4_transformMat3(result || [-0, -0, -0, -0], vector, this);
  97375. break;
  97376. default:
  97377. throw new Error('Illegal vector');
  97378. }
  97379. checkVector(result, vector.length);
  97380. return result;
  97381. }
  97382. transformVector(vector, result) {
  97383. deprecated('Matrix3.transformVector');
  97384. return this.transform(vector, result);
  97385. }
  97386. transformVector2(vector, result) {
  97387. deprecated('Matrix3.transformVector');
  97388. return this.transform(vector, result);
  97389. }
  97390. transformVector3(vector, result) {
  97391. deprecated('Matrix3.transformVector');
  97392. return this.transform(vector, result);
  97393. }
  97394. }
  97395. /**
  97396. * Set a mat4 to the identity matrix
  97397. *
  97398. * @param {mat4} out the receiving matrix
  97399. * @returns {mat4} out
  97400. */
  97401. function identity$1(out) {
  97402. out[0] = 1;
  97403. out[1] = 0;
  97404. out[2] = 0;
  97405. out[3] = 0;
  97406. out[4] = 0;
  97407. out[5] = 1;
  97408. out[6] = 0;
  97409. out[7] = 0;
  97410. out[8] = 0;
  97411. out[9] = 0;
  97412. out[10] = 1;
  97413. out[11] = 0;
  97414. out[12] = 0;
  97415. out[13] = 0;
  97416. out[14] = 0;
  97417. out[15] = 1;
  97418. return out;
  97419. }
  97420. /**
  97421. * Transpose the values of a mat4
  97422. *
  97423. * @param {mat4} out the receiving matrix
  97424. * @param {ReadonlyMat4} a the source matrix
  97425. * @returns {mat4} out
  97426. */
  97427. function transpose(out, a) {
  97428. // If we are transposing ourselves we can skip a few steps but have to cache some values
  97429. if (out === a) {
  97430. var a01 = a[1],
  97431. a02 = a[2],
  97432. a03 = a[3];
  97433. var a12 = a[6],
  97434. a13 = a[7];
  97435. var a23 = a[11];
  97436. out[1] = a[4];
  97437. out[2] = a[8];
  97438. out[3] = a[12];
  97439. out[4] = a01;
  97440. out[6] = a[9];
  97441. out[7] = a[13];
  97442. out[8] = a02;
  97443. out[9] = a12;
  97444. out[11] = a[14];
  97445. out[12] = a03;
  97446. out[13] = a13;
  97447. out[14] = a23;
  97448. } else {
  97449. out[0] = a[0];
  97450. out[1] = a[4];
  97451. out[2] = a[8];
  97452. out[3] = a[12];
  97453. out[4] = a[1];
  97454. out[5] = a[5];
  97455. out[6] = a[9];
  97456. out[7] = a[13];
  97457. out[8] = a[2];
  97458. out[9] = a[6];
  97459. out[10] = a[10];
  97460. out[11] = a[14];
  97461. out[12] = a[3];
  97462. out[13] = a[7];
  97463. out[14] = a[11];
  97464. out[15] = a[15];
  97465. }
  97466. return out;
  97467. }
  97468. /**
  97469. * Inverts a mat4
  97470. *
  97471. * @param {mat4} out the receiving matrix
  97472. * @param {ReadonlyMat4} a the source matrix
  97473. * @returns {mat4} out
  97474. */
  97475. function invert$1(out, a) {
  97476. var a00 = a[0],
  97477. a01 = a[1],
  97478. a02 = a[2],
  97479. a03 = a[3];
  97480. var a10 = a[4],
  97481. a11 = a[5],
  97482. a12 = a[6],
  97483. a13 = a[7];
  97484. var a20 = a[8],
  97485. a21 = a[9],
  97486. a22 = a[10],
  97487. a23 = a[11];
  97488. var a30 = a[12],
  97489. a31 = a[13],
  97490. a32 = a[14],
  97491. a33 = a[15];
  97492. var b00 = a00 * a11 - a01 * a10;
  97493. var b01 = a00 * a12 - a02 * a10;
  97494. var b02 = a00 * a13 - a03 * a10;
  97495. var b03 = a01 * a12 - a02 * a11;
  97496. var b04 = a01 * a13 - a03 * a11;
  97497. var b05 = a02 * a13 - a03 * a12;
  97498. var b06 = a20 * a31 - a21 * a30;
  97499. var b07 = a20 * a32 - a22 * a30;
  97500. var b08 = a20 * a33 - a23 * a30;
  97501. var b09 = a21 * a32 - a22 * a31;
  97502. var b10 = a21 * a33 - a23 * a31;
  97503. var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
  97504. var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  97505. if (!det) {
  97506. return null;
  97507. }
  97508. det = 1.0 / det;
  97509. out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
  97510. out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
  97511. out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
  97512. out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
  97513. out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
  97514. out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
  97515. out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
  97516. out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
  97517. out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
  97518. out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
  97519. out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
  97520. out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
  97521. out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
  97522. out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
  97523. out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
  97524. out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
  97525. return out;
  97526. }
  97527. /**
  97528. * Calculates the determinant of a mat4
  97529. *
  97530. * @param {ReadonlyMat4} a the source matrix
  97531. * @returns {Number} determinant of a
  97532. */
  97533. function determinant(a) {
  97534. var a00 = a[0],
  97535. a01 = a[1],
  97536. a02 = a[2],
  97537. a03 = a[3];
  97538. var a10 = a[4],
  97539. a11 = a[5],
  97540. a12 = a[6],
  97541. a13 = a[7];
  97542. var a20 = a[8],
  97543. a21 = a[9],
  97544. a22 = a[10],
  97545. a23 = a[11];
  97546. var a30 = a[12],
  97547. a31 = a[13],
  97548. a32 = a[14],
  97549. a33 = a[15];
  97550. var b00 = a00 * a11 - a01 * a10;
  97551. var b01 = a00 * a12 - a02 * a10;
  97552. var b02 = a00 * a13 - a03 * a10;
  97553. var b03 = a01 * a12 - a02 * a11;
  97554. var b04 = a01 * a13 - a03 * a11;
  97555. var b05 = a02 * a13 - a03 * a12;
  97556. var b06 = a20 * a31 - a21 * a30;
  97557. var b07 = a20 * a32 - a22 * a30;
  97558. var b08 = a20 * a33 - a23 * a30;
  97559. var b09 = a21 * a32 - a22 * a31;
  97560. var b10 = a21 * a33 - a23 * a31;
  97561. var b11 = a22 * a33 - a23 * a32; // Calculate the determinant
  97562. return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
  97563. }
  97564. /**
  97565. * Multiplies two mat4s
  97566. *
  97567. * @param {mat4} out the receiving matrix
  97568. * @param {ReadonlyMat4} a the first operand
  97569. * @param {ReadonlyMat4} b the second operand
  97570. * @returns {mat4} out
  97571. */
  97572. function multiply$1(out, a, b) {
  97573. var a00 = a[0],
  97574. a01 = a[1],
  97575. a02 = a[2],
  97576. a03 = a[3];
  97577. var a10 = a[4],
  97578. a11 = a[5],
  97579. a12 = a[6],
  97580. a13 = a[7];
  97581. var a20 = a[8],
  97582. a21 = a[9],
  97583. a22 = a[10],
  97584. a23 = a[11];
  97585. var a30 = a[12],
  97586. a31 = a[13],
  97587. a32 = a[14],
  97588. a33 = a[15]; // Cache only the current line of the second matrix
  97589. var b0 = b[0],
  97590. b1 = b[1],
  97591. b2 = b[2],
  97592. b3 = b[3];
  97593. out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  97594. out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  97595. out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  97596. out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  97597. b0 = b[4];
  97598. b1 = b[5];
  97599. b2 = b[6];
  97600. b3 = b[7];
  97601. out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  97602. out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  97603. out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  97604. out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  97605. b0 = b[8];
  97606. b1 = b[9];
  97607. b2 = b[10];
  97608. b3 = b[11];
  97609. out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  97610. out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  97611. out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  97612. out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  97613. b0 = b[12];
  97614. b1 = b[13];
  97615. b2 = b[14];
  97616. b3 = b[15];
  97617. out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
  97618. out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
  97619. out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
  97620. out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
  97621. return out;
  97622. }
  97623. /**
  97624. * Translate a mat4 by the given vector
  97625. *
  97626. * @param {mat4} out the receiving matrix
  97627. * @param {ReadonlyMat4} a the matrix to translate
  97628. * @param {ReadonlyVec3} v vector to translate by
  97629. * @returns {mat4} out
  97630. */
  97631. function translate(out, a, v) {
  97632. var x = v[0],
  97633. y = v[1],
  97634. z = v[2];
  97635. var a00, a01, a02, a03;
  97636. var a10, a11, a12, a13;
  97637. var a20, a21, a22, a23;
  97638. if (a === out) {
  97639. out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
  97640. out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
  97641. out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
  97642. out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
  97643. } else {
  97644. a00 = a[0];
  97645. a01 = a[1];
  97646. a02 = a[2];
  97647. a03 = a[3];
  97648. a10 = a[4];
  97649. a11 = a[5];
  97650. a12 = a[6];
  97651. a13 = a[7];
  97652. a20 = a[8];
  97653. a21 = a[9];
  97654. a22 = a[10];
  97655. a23 = a[11];
  97656. out[0] = a00;
  97657. out[1] = a01;
  97658. out[2] = a02;
  97659. out[3] = a03;
  97660. out[4] = a10;
  97661. out[5] = a11;
  97662. out[6] = a12;
  97663. out[7] = a13;
  97664. out[8] = a20;
  97665. out[9] = a21;
  97666. out[10] = a22;
  97667. out[11] = a23;
  97668. out[12] = a00 * x + a10 * y + a20 * z + a[12];
  97669. out[13] = a01 * x + a11 * y + a21 * z + a[13];
  97670. out[14] = a02 * x + a12 * y + a22 * z + a[14];
  97671. out[15] = a03 * x + a13 * y + a23 * z + a[15];
  97672. }
  97673. return out;
  97674. }
  97675. /**
  97676. * Scales the mat4 by the dimensions in the given vec3 not using vectorization
  97677. *
  97678. * @param {mat4} out the receiving matrix
  97679. * @param {ReadonlyMat4} a the matrix to scale
  97680. * @param {ReadonlyVec3} v the vec3 to scale the matrix by
  97681. * @returns {mat4} out
  97682. **/
  97683. function scale$2(out, a, v) {
  97684. var x = v[0],
  97685. y = v[1],
  97686. z = v[2];
  97687. out[0] = a[0] * x;
  97688. out[1] = a[1] * x;
  97689. out[2] = a[2] * x;
  97690. out[3] = a[3] * x;
  97691. out[4] = a[4] * y;
  97692. out[5] = a[5] * y;
  97693. out[6] = a[6] * y;
  97694. out[7] = a[7] * y;
  97695. out[8] = a[8] * z;
  97696. out[9] = a[9] * z;
  97697. out[10] = a[10] * z;
  97698. out[11] = a[11] * z;
  97699. out[12] = a[12];
  97700. out[13] = a[13];
  97701. out[14] = a[14];
  97702. out[15] = a[15];
  97703. return out;
  97704. }
  97705. /**
  97706. * Rotates a mat4 by the given angle around the given axis
  97707. *
  97708. * @param {mat4} out the receiving matrix
  97709. * @param {ReadonlyMat4} a the matrix to rotate
  97710. * @param {Number} rad the angle to rotate the matrix by
  97711. * @param {ReadonlyVec3} axis the axis to rotate around
  97712. * @returns {mat4} out
  97713. */
  97714. function rotate(out, a, rad, axis) {
  97715. var x = axis[0],
  97716. y = axis[1],
  97717. z = axis[2];
  97718. var len = Math.hypot(x, y, z);
  97719. var s, c, t;
  97720. var a00, a01, a02, a03;
  97721. var a10, a11, a12, a13;
  97722. var a20, a21, a22, a23;
  97723. var b00, b01, b02;
  97724. var b10, b11, b12;
  97725. var b20, b21, b22;
  97726. if (len < EPSILON) {
  97727. return null;
  97728. }
  97729. len = 1 / len;
  97730. x *= len;
  97731. y *= len;
  97732. z *= len;
  97733. s = Math.sin(rad);
  97734. c = Math.cos(rad);
  97735. t = 1 - c;
  97736. a00 = a[0];
  97737. a01 = a[1];
  97738. a02 = a[2];
  97739. a03 = a[3];
  97740. a10 = a[4];
  97741. a11 = a[5];
  97742. a12 = a[6];
  97743. a13 = a[7];
  97744. a20 = a[8];
  97745. a21 = a[9];
  97746. a22 = a[10];
  97747. a23 = a[11]; // Construct the elements of the rotation matrix
  97748. b00 = x * x * t + c;
  97749. b01 = y * x * t + z * s;
  97750. b02 = z * x * t - y * s;
  97751. b10 = x * y * t - z * s;
  97752. b11 = y * y * t + c;
  97753. b12 = z * y * t + x * s;
  97754. b20 = x * z * t + y * s;
  97755. b21 = y * z * t - x * s;
  97756. b22 = z * z * t + c; // Perform rotation-specific matrix multiplication
  97757. out[0] = a00 * b00 + a10 * b01 + a20 * b02;
  97758. out[1] = a01 * b00 + a11 * b01 + a21 * b02;
  97759. out[2] = a02 * b00 + a12 * b01 + a22 * b02;
  97760. out[3] = a03 * b00 + a13 * b01 + a23 * b02;
  97761. out[4] = a00 * b10 + a10 * b11 + a20 * b12;
  97762. out[5] = a01 * b10 + a11 * b11 + a21 * b12;
  97763. out[6] = a02 * b10 + a12 * b11 + a22 * b12;
  97764. out[7] = a03 * b10 + a13 * b11 + a23 * b12;
  97765. out[8] = a00 * b20 + a10 * b21 + a20 * b22;
  97766. out[9] = a01 * b20 + a11 * b21 + a21 * b22;
  97767. out[10] = a02 * b20 + a12 * b21 + a22 * b22;
  97768. out[11] = a03 * b20 + a13 * b21 + a23 * b22;
  97769. if (a !== out) {
  97770. // If the source and destination differ, copy the unchanged last row
  97771. out[12] = a[12];
  97772. out[13] = a[13];
  97773. out[14] = a[14];
  97774. out[15] = a[15];
  97775. }
  97776. return out;
  97777. }
  97778. /**
  97779. * Rotates a matrix by the given angle around the X axis
  97780. *
  97781. * @param {mat4} out the receiving matrix
  97782. * @param {ReadonlyMat4} a the matrix to rotate
  97783. * @param {Number} rad the angle to rotate the matrix by
  97784. * @returns {mat4} out
  97785. */
  97786. function rotateX$1(out, a, rad) {
  97787. var s = Math.sin(rad);
  97788. var c = Math.cos(rad);
  97789. var a10 = a[4];
  97790. var a11 = a[5];
  97791. var a12 = a[6];
  97792. var a13 = a[7];
  97793. var a20 = a[8];
  97794. var a21 = a[9];
  97795. var a22 = a[10];
  97796. var a23 = a[11];
  97797. if (a !== out) {
  97798. // If the source and destination differ, copy the unchanged rows
  97799. out[0] = a[0];
  97800. out[1] = a[1];
  97801. out[2] = a[2];
  97802. out[3] = a[3];
  97803. out[12] = a[12];
  97804. out[13] = a[13];
  97805. out[14] = a[14];
  97806. out[15] = a[15];
  97807. } // Perform axis-specific matrix multiplication
  97808. out[4] = a10 * c + a20 * s;
  97809. out[5] = a11 * c + a21 * s;
  97810. out[6] = a12 * c + a22 * s;
  97811. out[7] = a13 * c + a23 * s;
  97812. out[8] = a20 * c - a10 * s;
  97813. out[9] = a21 * c - a11 * s;
  97814. out[10] = a22 * c - a12 * s;
  97815. out[11] = a23 * c - a13 * s;
  97816. return out;
  97817. }
  97818. /**
  97819. * Rotates a matrix by the given angle around the Y axis
  97820. *
  97821. * @param {mat4} out the receiving matrix
  97822. * @param {ReadonlyMat4} a the matrix to rotate
  97823. * @param {Number} rad the angle to rotate the matrix by
  97824. * @returns {mat4} out
  97825. */
  97826. function rotateY$1(out, a, rad) {
  97827. var s = Math.sin(rad);
  97828. var c = Math.cos(rad);
  97829. var a00 = a[0];
  97830. var a01 = a[1];
  97831. var a02 = a[2];
  97832. var a03 = a[3];
  97833. var a20 = a[8];
  97834. var a21 = a[9];
  97835. var a22 = a[10];
  97836. var a23 = a[11];
  97837. if (a !== out) {
  97838. // If the source and destination differ, copy the unchanged rows
  97839. out[4] = a[4];
  97840. out[5] = a[5];
  97841. out[6] = a[6];
  97842. out[7] = a[7];
  97843. out[12] = a[12];
  97844. out[13] = a[13];
  97845. out[14] = a[14];
  97846. out[15] = a[15];
  97847. } // Perform axis-specific matrix multiplication
  97848. out[0] = a00 * c - a20 * s;
  97849. out[1] = a01 * c - a21 * s;
  97850. out[2] = a02 * c - a22 * s;
  97851. out[3] = a03 * c - a23 * s;
  97852. out[8] = a00 * s + a20 * c;
  97853. out[9] = a01 * s + a21 * c;
  97854. out[10] = a02 * s + a22 * c;
  97855. out[11] = a03 * s + a23 * c;
  97856. return out;
  97857. }
  97858. /**
  97859. * Rotates a matrix by the given angle around the Z axis
  97860. *
  97861. * @param {mat4} out the receiving matrix
  97862. * @param {ReadonlyMat4} a the matrix to rotate
  97863. * @param {Number} rad the angle to rotate the matrix by
  97864. * @returns {mat4} out
  97865. */
  97866. function rotateZ$1(out, a, rad) {
  97867. var s = Math.sin(rad);
  97868. var c = Math.cos(rad);
  97869. var a00 = a[0];
  97870. var a01 = a[1];
  97871. var a02 = a[2];
  97872. var a03 = a[3];
  97873. var a10 = a[4];
  97874. var a11 = a[5];
  97875. var a12 = a[6];
  97876. var a13 = a[7];
  97877. if (a !== out) {
  97878. // If the source and destination differ, copy the unchanged last row
  97879. out[8] = a[8];
  97880. out[9] = a[9];
  97881. out[10] = a[10];
  97882. out[11] = a[11];
  97883. out[12] = a[12];
  97884. out[13] = a[13];
  97885. out[14] = a[14];
  97886. out[15] = a[15];
  97887. } // Perform axis-specific matrix multiplication
  97888. out[0] = a00 * c + a10 * s;
  97889. out[1] = a01 * c + a11 * s;
  97890. out[2] = a02 * c + a12 * s;
  97891. out[3] = a03 * c + a13 * s;
  97892. out[4] = a10 * c - a00 * s;
  97893. out[5] = a11 * c - a01 * s;
  97894. out[6] = a12 * c - a02 * s;
  97895. out[7] = a13 * c - a03 * s;
  97896. return out;
  97897. }
  97898. /**
  97899. * Returns the scaling factor component of a transformation
  97900. * matrix. If a matrix is built with fromRotationTranslationScale
  97901. * with a normalized Quaternion paramter, the returned vector will be
  97902. * the same as the scaling vector
  97903. * originally supplied.
  97904. * @param {vec3} out Vector to receive scaling factor component
  97905. * @param {ReadonlyMat4} mat Matrix to be decomposed (input)
  97906. * @return {vec3} out
  97907. */
  97908. function getScaling(out, mat) {
  97909. var m11 = mat[0];
  97910. var m12 = mat[1];
  97911. var m13 = mat[2];
  97912. var m21 = mat[4];
  97913. var m22 = mat[5];
  97914. var m23 = mat[6];
  97915. var m31 = mat[8];
  97916. var m32 = mat[9];
  97917. var m33 = mat[10];
  97918. out[0] = Math.hypot(m11, m12, m13);
  97919. out[1] = Math.hypot(m21, m22, m23);
  97920. out[2] = Math.hypot(m31, m32, m33);
  97921. return out;
  97922. }
  97923. /**
  97924. * Calculates a 4x4 matrix from the given quaternion
  97925. *
  97926. * @param {mat4} out mat4 receiving operation result
  97927. * @param {ReadonlyQuat} q Quaternion to create matrix from
  97928. *
  97929. * @returns {mat4} out
  97930. */
  97931. function fromQuat(out, q) {
  97932. var x = q[0],
  97933. y = q[1],
  97934. z = q[2],
  97935. w = q[3];
  97936. var x2 = x + x;
  97937. var y2 = y + y;
  97938. var z2 = z + z;
  97939. var xx = x * x2;
  97940. var yx = y * x2;
  97941. var yy = y * y2;
  97942. var zx = z * x2;
  97943. var zy = z * y2;
  97944. var zz = z * z2;
  97945. var wx = w * x2;
  97946. var wy = w * y2;
  97947. var wz = w * z2;
  97948. out[0] = 1 - yy - zz;
  97949. out[1] = yx + wz;
  97950. out[2] = zx - wy;
  97951. out[3] = 0;
  97952. out[4] = yx - wz;
  97953. out[5] = 1 - xx - zz;
  97954. out[6] = zy + wx;
  97955. out[7] = 0;
  97956. out[8] = zx + wy;
  97957. out[9] = zy - wx;
  97958. out[10] = 1 - xx - yy;
  97959. out[11] = 0;
  97960. out[12] = 0;
  97961. out[13] = 0;
  97962. out[14] = 0;
  97963. out[15] = 1;
  97964. return out;
  97965. }
  97966. /**
  97967. * Generates a frustum matrix with the given bounds
  97968. *
  97969. * @param {mat4} out mat4 frustum matrix will be written into
  97970. * @param {Number} left Left bound of the frustum
  97971. * @param {Number} right Right bound of the frustum
  97972. * @param {Number} bottom Bottom bound of the frustum
  97973. * @param {Number} top Top bound of the frustum
  97974. * @param {Number} near Near bound of the frustum
  97975. * @param {Number} far Far bound of the frustum
  97976. * @returns {mat4} out
  97977. */
  97978. function frustum(out, left, right, bottom, top, near, far) {
  97979. var rl = 1 / (right - left);
  97980. var tb = 1 / (top - bottom);
  97981. var nf = 1 / (near - far);
  97982. out[0] = near * 2 * rl;
  97983. out[1] = 0;
  97984. out[2] = 0;
  97985. out[3] = 0;
  97986. out[4] = 0;
  97987. out[5] = near * 2 * tb;
  97988. out[6] = 0;
  97989. out[7] = 0;
  97990. out[8] = (right + left) * rl;
  97991. out[9] = (top + bottom) * tb;
  97992. out[10] = (far + near) * nf;
  97993. out[11] = -1;
  97994. out[12] = 0;
  97995. out[13] = 0;
  97996. out[14] = far * near * 2 * nf;
  97997. out[15] = 0;
  97998. return out;
  97999. }
  98000. /**
  98001. * Generates a perspective projection matrix with the given bounds.
  98002. * Passing null/undefined/no value for far will generate infinite projection matrix.
  98003. *
  98004. * @param {mat4} out mat4 frustum matrix will be written into
  98005. * @param {number} fovy Vertical field of view in radians
  98006. * @param {number} aspect Aspect ratio. typically viewport width/height
  98007. * @param {number} near Near bound of the frustum
  98008. * @param {number} far Far bound of the frustum, can be null or Infinity
  98009. * @returns {mat4} out
  98010. */
  98011. function perspective(out, fovy, aspect, near, far) {
  98012. var f = 1.0 / Math.tan(fovy / 2),
  98013. nf;
  98014. out[0] = f / aspect;
  98015. out[1] = 0;
  98016. out[2] = 0;
  98017. out[3] = 0;
  98018. out[4] = 0;
  98019. out[5] = f;
  98020. out[6] = 0;
  98021. out[7] = 0;
  98022. out[8] = 0;
  98023. out[9] = 0;
  98024. out[11] = -1;
  98025. out[12] = 0;
  98026. out[13] = 0;
  98027. out[15] = 0;
  98028. if (far != null && far !== Infinity) {
  98029. nf = 1 / (near - far);
  98030. out[10] = (far + near) * nf;
  98031. out[14] = 2 * far * near * nf;
  98032. } else {
  98033. out[10] = -1;
  98034. out[14] = -2 * near;
  98035. }
  98036. return out;
  98037. }
  98038. /**
  98039. * Generates a orthogonal projection matrix with the given bounds
  98040. *
  98041. * @param {mat4} out mat4 frustum matrix will be written into
  98042. * @param {number} left Left bound of the frustum
  98043. * @param {number} right Right bound of the frustum
  98044. * @param {number} bottom Bottom bound of the frustum
  98045. * @param {number} top Top bound of the frustum
  98046. * @param {number} near Near bound of the frustum
  98047. * @param {number} far Far bound of the frustum
  98048. * @returns {mat4} out
  98049. */
  98050. function ortho(out, left, right, bottom, top, near, far) {
  98051. var lr = 1 / (left - right);
  98052. var bt = 1 / (bottom - top);
  98053. var nf = 1 / (near - far);
  98054. out[0] = -2 * lr;
  98055. out[1] = 0;
  98056. out[2] = 0;
  98057. out[3] = 0;
  98058. out[4] = 0;
  98059. out[5] = -2 * bt;
  98060. out[6] = 0;
  98061. out[7] = 0;
  98062. out[8] = 0;
  98063. out[9] = 0;
  98064. out[10] = 2 * nf;
  98065. out[11] = 0;
  98066. out[12] = (left + right) * lr;
  98067. out[13] = (top + bottom) * bt;
  98068. out[14] = (far + near) * nf;
  98069. out[15] = 1;
  98070. return out;
  98071. }
  98072. /**
  98073. * Generates a look-at matrix with the given eye position, focal point, and up axis.
  98074. * If you want a matrix that actually makes an object look at another object, you should use targetTo instead.
  98075. *
  98076. * @param {mat4} out mat4 frustum matrix will be written into
  98077. * @param {ReadonlyVec3} eye Position of the viewer
  98078. * @param {ReadonlyVec3} center Point the viewer is looking at
  98079. * @param {ReadonlyVec3} up vec3 pointing up
  98080. * @returns {mat4} out
  98081. */
  98082. function lookAt(out, eye, center, up) {
  98083. var x0, x1, x2, y0, y1, y2, z0, z1, z2, len;
  98084. var eyex = eye[0];
  98085. var eyey = eye[1];
  98086. var eyez = eye[2];
  98087. var upx = up[0];
  98088. var upy = up[1];
  98089. var upz = up[2];
  98090. var centerx = center[0];
  98091. var centery = center[1];
  98092. var centerz = center[2];
  98093. if (Math.abs(eyex - centerx) < EPSILON && Math.abs(eyey - centery) < EPSILON && Math.abs(eyez - centerz) < EPSILON) {
  98094. return identity$1(out);
  98095. }
  98096. z0 = eyex - centerx;
  98097. z1 = eyey - centery;
  98098. z2 = eyez - centerz;
  98099. len = 1 / Math.hypot(z0, z1, z2);
  98100. z0 *= len;
  98101. z1 *= len;
  98102. z2 *= len;
  98103. x0 = upy * z2 - upz * z1;
  98104. x1 = upz * z0 - upx * z2;
  98105. x2 = upx * z1 - upy * z0;
  98106. len = Math.hypot(x0, x1, x2);
  98107. if (!len) {
  98108. x0 = 0;
  98109. x1 = 0;
  98110. x2 = 0;
  98111. } else {
  98112. len = 1 / len;
  98113. x0 *= len;
  98114. x1 *= len;
  98115. x2 *= len;
  98116. }
  98117. y0 = z1 * x2 - z2 * x1;
  98118. y1 = z2 * x0 - z0 * x2;
  98119. y2 = z0 * x1 - z1 * x0;
  98120. len = Math.hypot(y0, y1, y2);
  98121. if (!len) {
  98122. y0 = 0;
  98123. y1 = 0;
  98124. y2 = 0;
  98125. } else {
  98126. len = 1 / len;
  98127. y0 *= len;
  98128. y1 *= len;
  98129. y2 *= len;
  98130. }
  98131. out[0] = x0;
  98132. out[1] = y0;
  98133. out[2] = z0;
  98134. out[3] = 0;
  98135. out[4] = x1;
  98136. out[5] = y1;
  98137. out[6] = z1;
  98138. out[7] = 0;
  98139. out[8] = x2;
  98140. out[9] = y2;
  98141. out[10] = z2;
  98142. out[11] = 0;
  98143. out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
  98144. out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
  98145. out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
  98146. out[15] = 1;
  98147. return out;
  98148. }
  98149. /**
  98150. * 4 Dimensional Vector
  98151. * @module vec4
  98152. */
  98153. /**
  98154. * Creates a new, empty vec4
  98155. *
  98156. * @returns {vec4} a new 4D vector
  98157. */
  98158. function create$1() {
  98159. var out = new ARRAY_TYPE(4);
  98160. if (ARRAY_TYPE != Float32Array) {
  98161. out[0] = 0;
  98162. out[1] = 0;
  98163. out[2] = 0;
  98164. out[3] = 0;
  98165. }
  98166. return out;
  98167. }
  98168. /**
  98169. * Adds two vec4's
  98170. *
  98171. * @param {vec4} out the receiving vector
  98172. * @param {ReadonlyVec4} a the first operand
  98173. * @param {ReadonlyVec4} b the second operand
  98174. * @returns {vec4} out
  98175. */
  98176. function add$1(out, a, b) {
  98177. out[0] = a[0] + b[0];
  98178. out[1] = a[1] + b[1];
  98179. out[2] = a[2] + b[2];
  98180. out[3] = a[3] + b[3];
  98181. return out;
  98182. }
  98183. /**
  98184. * Scales a vec4 by a scalar number
  98185. *
  98186. * @param {vec4} out the receiving vector
  98187. * @param {ReadonlyVec4} a the vector to scale
  98188. * @param {Number} b amount to scale the vector by
  98189. * @returns {vec4} out
  98190. */
  98191. function scale$1(out, a, b) {
  98192. out[0] = a[0] * b;
  98193. out[1] = a[1] * b;
  98194. out[2] = a[2] * b;
  98195. out[3] = a[3] * b;
  98196. return out;
  98197. }
  98198. /**
  98199. * Calculates the length of a vec4
  98200. *
  98201. * @param {ReadonlyVec4} a vector to calculate length of
  98202. * @returns {Number} length of a
  98203. */
  98204. function length$1(a) {
  98205. var x = a[0];
  98206. var y = a[1];
  98207. var z = a[2];
  98208. var w = a[3];
  98209. return Math.hypot(x, y, z, w);
  98210. }
  98211. /**
  98212. * Calculates the squared length of a vec4
  98213. *
  98214. * @param {ReadonlyVec4} a vector to calculate squared length of
  98215. * @returns {Number} squared length of a
  98216. */
  98217. function squaredLength$1(a) {
  98218. var x = a[0];
  98219. var y = a[1];
  98220. var z = a[2];
  98221. var w = a[3];
  98222. return x * x + y * y + z * z + w * w;
  98223. }
  98224. /**
  98225. * Normalize a vec4
  98226. *
  98227. * @param {vec4} out the receiving vector
  98228. * @param {ReadonlyVec4} a vector to normalize
  98229. * @returns {vec4} out
  98230. */
  98231. function normalize$1(out, a) {
  98232. var x = a[0];
  98233. var y = a[1];
  98234. var z = a[2];
  98235. var w = a[3];
  98236. var len = x * x + y * y + z * z + w * w;
  98237. if (len > 0) {
  98238. len = 1 / Math.sqrt(len);
  98239. }
  98240. out[0] = x * len;
  98241. out[1] = y * len;
  98242. out[2] = z * len;
  98243. out[3] = w * len;
  98244. return out;
  98245. }
  98246. /**
  98247. * Calculates the dot product of two vec4's
  98248. *
  98249. * @param {ReadonlyVec4} a the first operand
  98250. * @param {ReadonlyVec4} b the second operand
  98251. * @returns {Number} dot product of a and b
  98252. */
  98253. function dot$1(a, b) {
  98254. return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
  98255. }
  98256. /**
  98257. * Performs a linear interpolation between two vec4's
  98258. *
  98259. * @param {vec4} out the receiving vector
  98260. * @param {ReadonlyVec4} a the first operand
  98261. * @param {ReadonlyVec4} b the second operand
  98262. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  98263. * @returns {vec4} out
  98264. */
  98265. function lerp$1(out, a, b, t) {
  98266. var ax = a[0];
  98267. var ay = a[1];
  98268. var az = a[2];
  98269. var aw = a[3];
  98270. out[0] = ax + t * (b[0] - ax);
  98271. out[1] = ay + t * (b[1] - ay);
  98272. out[2] = az + t * (b[2] - az);
  98273. out[3] = aw + t * (b[3] - aw);
  98274. return out;
  98275. }
  98276. /**
  98277. * Transforms the vec4 with a mat4.
  98278. *
  98279. * @param {vec4} out the receiving vector
  98280. * @param {ReadonlyVec4} a the vector to transform
  98281. * @param {ReadonlyMat4} m matrix to transform with
  98282. * @returns {vec4} out
  98283. */
  98284. function transformMat4(out, a, m) {
  98285. var x = a[0],
  98286. y = a[1],
  98287. z = a[2],
  98288. w = a[3];
  98289. out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
  98290. out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
  98291. out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
  98292. out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
  98293. return out;
  98294. }
  98295. /**
  98296. * Transforms the vec4 with a quat
  98297. *
  98298. * @param {vec4} out the receiving vector
  98299. * @param {ReadonlyVec4} a the vector to transform
  98300. * @param {ReadonlyQuat} q quaternion to transform with
  98301. * @returns {vec4} out
  98302. */
  98303. function transformQuat(out, a, q) {
  98304. var x = a[0],
  98305. y = a[1],
  98306. z = a[2];
  98307. var qx = q[0],
  98308. qy = q[1],
  98309. qz = q[2],
  98310. qw = q[3]; // calculate quat * vec
  98311. var ix = qw * x + qy * z - qz * y;
  98312. var iy = qw * y + qz * x - qx * z;
  98313. var iz = qw * z + qx * y - qy * x;
  98314. var iw = -qx * x - qy * y - qz * z; // calculate result * inverse quat
  98315. out[0] = ix * qw + iw * -qx + iy * -qz - iz * -qy;
  98316. out[1] = iy * qw + iw * -qy + iz * -qx - ix * -qz;
  98317. out[2] = iz * qw + iw * -qz + ix * -qy - iy * -qx;
  98318. out[3] = a[3];
  98319. return out;
  98320. }
  98321. /**
  98322. * Perform some operation over an array of vec4s.
  98323. *
  98324. * @param {Array} a the array of vectors to iterate over
  98325. * @param {Number} stride Number of elements between the start of each vec4. If 0 assumes tightly packed
  98326. * @param {Number} offset Number of elements to skip at the beginning of the array
  98327. * @param {Number} count Number of vec4s to iterate over. If 0 iterates over entire array
  98328. * @param {Function} fn Function to call for each vector in the array
  98329. * @param {Object} [arg] additional argument to pass to fn
  98330. * @returns {Array} a
  98331. * @function
  98332. */
  98333. (function () {
  98334. var vec = create$1();
  98335. return function (a, stride, offset, count, fn, arg) {
  98336. var i, l;
  98337. if (!stride) {
  98338. stride = 4;
  98339. }
  98340. if (!offset) {
  98341. offset = 0;
  98342. }
  98343. if (count) {
  98344. l = Math.min(count * stride + offset, a.length);
  98345. } else {
  98346. l = a.length;
  98347. }
  98348. for (i = offset; i < l; i += stride) {
  98349. vec[0] = a[i];
  98350. vec[1] = a[i + 1];
  98351. vec[2] = a[i + 2];
  98352. vec[3] = a[i + 3];
  98353. fn(vec, vec, arg);
  98354. a[i] = vec[0];
  98355. a[i + 1] = vec[1];
  98356. a[i + 2] = vec[2];
  98357. a[i + 3] = vec[3];
  98358. }
  98359. return a;
  98360. };
  98361. })();
  98362. const IDENTITY = Object.freeze([1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1]);
  98363. const ZERO = Object.freeze([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
  98364. const INDICES = Object.freeze({
  98365. COL0ROW0: 0,
  98366. COL0ROW1: 1,
  98367. COL0ROW2: 2,
  98368. COL0ROW3: 3,
  98369. COL1ROW0: 4,
  98370. COL1ROW1: 5,
  98371. COL1ROW2: 6,
  98372. COL1ROW3: 7,
  98373. COL2ROW0: 8,
  98374. COL2ROW1: 9,
  98375. COL2ROW2: 10,
  98376. COL2ROW3: 11,
  98377. COL3ROW0: 12,
  98378. COL3ROW1: 13,
  98379. COL3ROW2: 14,
  98380. COL3ROW3: 15
  98381. });
  98382. const constants = {};
  98383. class Matrix4$1 extends Matrix {
  98384. static get IDENTITY() {
  98385. constants.IDENTITY = constants.IDENTITY || Object.freeze(new Matrix4$1(IDENTITY));
  98386. return constants.IDENTITY;
  98387. }
  98388. static get ZERO() {
  98389. constants.ZERO = constants.ZERO || Object.freeze(new Matrix4$1(ZERO));
  98390. return constants.ZERO;
  98391. }
  98392. get INDICES() {
  98393. return INDICES;
  98394. }
  98395. get ELEMENTS() {
  98396. return 16;
  98397. }
  98398. get RANK() {
  98399. return 4;
  98400. }
  98401. constructor(array) {
  98402. super(-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0);
  98403. if (arguments.length === 1 && Array.isArray(array)) {
  98404. this.copy(array);
  98405. } else {
  98406. this.identity();
  98407. }
  98408. }
  98409. copy(array) {
  98410. this[0] = array[0];
  98411. this[1] = array[1];
  98412. this[2] = array[2];
  98413. this[3] = array[3];
  98414. this[4] = array[4];
  98415. this[5] = array[5];
  98416. this[6] = array[6];
  98417. this[7] = array[7];
  98418. this[8] = array[8];
  98419. this[9] = array[9];
  98420. this[10] = array[10];
  98421. this[11] = array[11];
  98422. this[12] = array[12];
  98423. this[13] = array[13];
  98424. this[14] = array[14];
  98425. this[15] = array[15];
  98426. return this.check();
  98427. }
  98428. set(m00, m10, m20, m30, m01, m11, m21, m31, m02, m12, m22, m32, m03, m13, m23, m33) {
  98429. this[0] = m00;
  98430. this[1] = m10;
  98431. this[2] = m20;
  98432. this[3] = m30;
  98433. this[4] = m01;
  98434. this[5] = m11;
  98435. this[6] = m21;
  98436. this[7] = m31;
  98437. this[8] = m02;
  98438. this[9] = m12;
  98439. this[10] = m22;
  98440. this[11] = m32;
  98441. this[12] = m03;
  98442. this[13] = m13;
  98443. this[14] = m23;
  98444. this[15] = m33;
  98445. return this.check();
  98446. }
  98447. setRowMajor(m00, m01, m02, m03, m10, m11, m12, m13, m20, m21, m22, m23, m30, m31, m32, m33) {
  98448. this[0] = m00;
  98449. this[1] = m10;
  98450. this[2] = m20;
  98451. this[3] = m30;
  98452. this[4] = m01;
  98453. this[5] = m11;
  98454. this[6] = m21;
  98455. this[7] = m31;
  98456. this[8] = m02;
  98457. this[9] = m12;
  98458. this[10] = m22;
  98459. this[11] = m32;
  98460. this[12] = m03;
  98461. this[13] = m13;
  98462. this[14] = m23;
  98463. this[15] = m33;
  98464. return this.check();
  98465. }
  98466. toRowMajor(result) {
  98467. result[0] = this[0];
  98468. result[1] = this[4];
  98469. result[2] = this[8];
  98470. result[3] = this[12];
  98471. result[4] = this[1];
  98472. result[5] = this[5];
  98473. result[6] = this[9];
  98474. result[7] = this[13];
  98475. result[8] = this[2];
  98476. result[9] = this[6];
  98477. result[10] = this[10];
  98478. result[11] = this[14];
  98479. result[12] = this[3];
  98480. result[13] = this[7];
  98481. result[14] = this[11];
  98482. result[15] = this[15];
  98483. return result;
  98484. }
  98485. identity() {
  98486. return this.copy(IDENTITY);
  98487. }
  98488. fromQuaternion(q) {
  98489. fromQuat(this, q);
  98490. return this.check();
  98491. }
  98492. frustum({
  98493. left,
  98494. right,
  98495. bottom,
  98496. top,
  98497. near,
  98498. far
  98499. }) {
  98500. if (far === Infinity) {
  98501. Matrix4$1._computeInfinitePerspectiveOffCenter(this, left, right, bottom, top, near);
  98502. } else {
  98503. frustum(this, left, right, bottom, top, near, far);
  98504. }
  98505. return this.check();
  98506. }
  98507. static _computeInfinitePerspectiveOffCenter(result, left, right, bottom, top, near) {
  98508. const column0Row0 = 2.0 * near / (right - left);
  98509. const column1Row1 = 2.0 * near / (top - bottom);
  98510. const column2Row0 = (right + left) / (right - left);
  98511. const column2Row1 = (top + bottom) / (top - bottom);
  98512. const column2Row2 = -1.0;
  98513. const column2Row3 = -1.0;
  98514. const column3Row2 = -2.0 * near;
  98515. result[0] = column0Row0;
  98516. result[1] = 0.0;
  98517. result[2] = 0.0;
  98518. result[3] = 0.0;
  98519. result[4] = 0.0;
  98520. result[5] = column1Row1;
  98521. result[6] = 0.0;
  98522. result[7] = 0.0;
  98523. result[8] = column2Row0;
  98524. result[9] = column2Row1;
  98525. result[10] = column2Row2;
  98526. result[11] = column2Row3;
  98527. result[12] = 0.0;
  98528. result[13] = 0.0;
  98529. result[14] = column3Row2;
  98530. result[15] = 0.0;
  98531. return result;
  98532. }
  98533. lookAt(eye, center, up) {
  98534. if (arguments.length === 1) {
  98535. ({
  98536. eye,
  98537. center,
  98538. up
  98539. } = eye);
  98540. }
  98541. center = center || [0, 0, 0];
  98542. up = up || [0, 1, 0];
  98543. lookAt(this, eye, center, up);
  98544. return this.check();
  98545. }
  98546. ortho({
  98547. left,
  98548. right,
  98549. bottom,
  98550. top,
  98551. near = 0.1,
  98552. far = 500
  98553. }) {
  98554. ortho(this, left, right, bottom, top, near, far);
  98555. return this.check();
  98556. }
  98557. orthographic({
  98558. fovy = 45 * Math.PI / 180,
  98559. aspect = 1,
  98560. focalDistance = 1,
  98561. near = 0.1,
  98562. far = 500
  98563. }) {
  98564. if (fovy > Math.PI * 2) {
  98565. throw Error('radians');
  98566. }
  98567. const halfY = fovy / 2;
  98568. const top = focalDistance * Math.tan(halfY);
  98569. const right = top * aspect;
  98570. return new Matrix4$1().ortho({
  98571. left: -right,
  98572. right,
  98573. bottom: -top,
  98574. top,
  98575. near,
  98576. far
  98577. });
  98578. }
  98579. perspective({
  98580. fovy = undefined,
  98581. fov = 45 * Math.PI / 180,
  98582. aspect = 1,
  98583. near = 0.1,
  98584. far = 500
  98585. } = {}) {
  98586. fovy = fovy || fov;
  98587. if (fovy > Math.PI * 2) {
  98588. throw Error('radians');
  98589. }
  98590. perspective(this, fovy, aspect, near, far);
  98591. return this.check();
  98592. }
  98593. determinant() {
  98594. return determinant(this);
  98595. }
  98596. getScale(result = [-0, -0, -0]) {
  98597. result[0] = Math.sqrt(this[0] * this[0] + this[1] * this[1] + this[2] * this[2]);
  98598. result[1] = Math.sqrt(this[4] * this[4] + this[5] * this[5] + this[6] * this[6]);
  98599. result[2] = Math.sqrt(this[8] * this[8] + this[9] * this[9] + this[10] * this[10]);
  98600. return result;
  98601. }
  98602. getTranslation(result = [-0, -0, -0]) {
  98603. result[0] = this[12];
  98604. result[1] = this[13];
  98605. result[2] = this[14];
  98606. return result;
  98607. }
  98608. getRotation(result = [-0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0, -0], scaleResult = null) {
  98609. const scale = this.getScale(scaleResult || [-0, -0, -0]);
  98610. const inverseScale0 = 1 / scale[0];
  98611. const inverseScale1 = 1 / scale[1];
  98612. const inverseScale2 = 1 / scale[2];
  98613. result[0] = this[0] * inverseScale0;
  98614. result[1] = this[1] * inverseScale1;
  98615. result[2] = this[2] * inverseScale2;
  98616. result[3] = 0;
  98617. result[4] = this[4] * inverseScale0;
  98618. result[5] = this[5] * inverseScale1;
  98619. result[6] = this[6] * inverseScale2;
  98620. result[7] = 0;
  98621. result[8] = this[8] * inverseScale0;
  98622. result[9] = this[9] * inverseScale1;
  98623. result[10] = this[10] * inverseScale2;
  98624. result[11] = 0;
  98625. result[12] = 0;
  98626. result[13] = 0;
  98627. result[14] = 0;
  98628. result[15] = 1;
  98629. return result;
  98630. }
  98631. getRotationMatrix3(result = [-0, -0, -0, -0, -0, -0, -0, -0, -0], scaleResult = null) {
  98632. const scale = this.getScale(scaleResult || [-0, -0, -0]);
  98633. const inverseScale0 = 1 / scale[0];
  98634. const inverseScale1 = 1 / scale[1];
  98635. const inverseScale2 = 1 / scale[2];
  98636. result[0] = this[0] * inverseScale0;
  98637. result[1] = this[1] * inverseScale1;
  98638. result[2] = this[2] * inverseScale2;
  98639. result[3] = this[4] * inverseScale0;
  98640. result[4] = this[5] * inverseScale1;
  98641. result[5] = this[6] * inverseScale2;
  98642. result[6] = this[8] * inverseScale0;
  98643. result[7] = this[9] * inverseScale1;
  98644. result[8] = this[10] * inverseScale2;
  98645. return result;
  98646. }
  98647. transpose() {
  98648. transpose(this, this);
  98649. return this.check();
  98650. }
  98651. invert() {
  98652. invert$1(this, this);
  98653. return this.check();
  98654. }
  98655. multiplyLeft(a) {
  98656. multiply$1(this, a, this);
  98657. return this.check();
  98658. }
  98659. multiplyRight(a) {
  98660. multiply$1(this, this, a);
  98661. return this.check();
  98662. }
  98663. rotateX(radians) {
  98664. rotateX$1(this, this, radians);
  98665. return this.check();
  98666. }
  98667. rotateY(radians) {
  98668. rotateY$1(this, this, radians);
  98669. return this.check();
  98670. }
  98671. rotateZ(radians) {
  98672. rotateZ$1(this, this, radians);
  98673. return this.check();
  98674. }
  98675. rotateXYZ([rx, ry, rz]) {
  98676. return this.rotateX(rx).rotateY(ry).rotateZ(rz);
  98677. }
  98678. rotateAxis(radians, axis) {
  98679. rotate(this, this, radians, axis);
  98680. return this.check();
  98681. }
  98682. scale(factor) {
  98683. if (Array.isArray(factor)) {
  98684. scale$2(this, this, factor);
  98685. } else {
  98686. scale$2(this, this, [factor, factor, factor]);
  98687. }
  98688. return this.check();
  98689. }
  98690. translate(vec) {
  98691. translate(this, this, vec);
  98692. return this.check();
  98693. }
  98694. transform(vector, result) {
  98695. if (vector.length === 4) {
  98696. result = transformMat4(result || [-0, -0, -0, -0], vector, this);
  98697. checkVector(result, 4);
  98698. return result;
  98699. }
  98700. return this.transformAsPoint(vector, result);
  98701. }
  98702. transformAsPoint(vector, result) {
  98703. const {
  98704. length
  98705. } = vector;
  98706. switch (length) {
  98707. case 2:
  98708. result = transformMat4$2(result || [-0, -0], vector, this);
  98709. break;
  98710. case 3:
  98711. result = transformMat4$1(result || [-0, -0, -0], vector, this);
  98712. break;
  98713. default:
  98714. throw new Error('Illegal vector');
  98715. }
  98716. checkVector(result, vector.length);
  98717. return result;
  98718. }
  98719. transformAsVector(vector, result) {
  98720. switch (vector.length) {
  98721. case 2:
  98722. result = vec2_transformMat4AsVector(result || [-0, -0], vector, this);
  98723. break;
  98724. case 3:
  98725. result = vec3_transformMat4AsVector(result || [-0, -0, -0], vector, this);
  98726. break;
  98727. default:
  98728. throw new Error('Illegal vector');
  98729. }
  98730. checkVector(result, vector.length);
  98731. return result;
  98732. }
  98733. makeRotationX(radians) {
  98734. return this.identity().rotateX(radians);
  98735. }
  98736. makeTranslation(x, y, z) {
  98737. return this.identity().translate([x, y, z]);
  98738. }
  98739. transformPoint(vector, result) {
  98740. deprecated('Matrix4.transformPoint', '3.0');
  98741. return this.transformAsPoint(vector, result);
  98742. }
  98743. transformVector(vector, result) {
  98744. deprecated('Matrix4.transformVector', '3.0');
  98745. return this.transformAsPoint(vector, result);
  98746. }
  98747. transformDirection(vector, result) {
  98748. deprecated('Matrix4.transformDirection', '3.0');
  98749. return this.transformAsVector(vector, result);
  98750. }
  98751. }
  98752. /**
  98753. * Quaternion
  98754. * @module quat
  98755. */
  98756. /**
  98757. * Creates a new identity quat
  98758. *
  98759. * @returns {quat} a new quaternion
  98760. */
  98761. function create() {
  98762. var out = new ARRAY_TYPE(4);
  98763. if (ARRAY_TYPE != Float32Array) {
  98764. out[0] = 0;
  98765. out[1] = 0;
  98766. out[2] = 0;
  98767. }
  98768. out[3] = 1;
  98769. return out;
  98770. }
  98771. /**
  98772. * Set a quat to the identity quaternion
  98773. *
  98774. * @param {quat} out the receiving quaternion
  98775. * @returns {quat} out
  98776. */
  98777. function identity(out) {
  98778. out[0] = 0;
  98779. out[1] = 0;
  98780. out[2] = 0;
  98781. out[3] = 1;
  98782. return out;
  98783. }
  98784. /**
  98785. * Sets a quat from the given angle and rotation axis,
  98786. * then returns it.
  98787. *
  98788. * @param {quat} out the receiving quaternion
  98789. * @param {ReadonlyVec3} axis the axis around which to rotate
  98790. * @param {Number} rad the angle in radians
  98791. * @returns {quat} out
  98792. **/
  98793. function setAxisAngle(out, axis, rad) {
  98794. rad = rad * 0.5;
  98795. var s = Math.sin(rad);
  98796. out[0] = s * axis[0];
  98797. out[1] = s * axis[1];
  98798. out[2] = s * axis[2];
  98799. out[3] = Math.cos(rad);
  98800. return out;
  98801. }
  98802. /**
  98803. * Multiplies two quat's
  98804. *
  98805. * @param {quat} out the receiving quaternion
  98806. * @param {ReadonlyQuat} a the first operand
  98807. * @param {ReadonlyQuat} b the second operand
  98808. * @returns {quat} out
  98809. */
  98810. function multiply(out, a, b) {
  98811. var ax = a[0],
  98812. ay = a[1],
  98813. az = a[2],
  98814. aw = a[3];
  98815. var bx = b[0],
  98816. by = b[1],
  98817. bz = b[2],
  98818. bw = b[3];
  98819. out[0] = ax * bw + aw * bx + ay * bz - az * by;
  98820. out[1] = ay * bw + aw * by + az * bx - ax * bz;
  98821. out[2] = az * bw + aw * bz + ax * by - ay * bx;
  98822. out[3] = aw * bw - ax * bx - ay * by - az * bz;
  98823. return out;
  98824. }
  98825. /**
  98826. * Rotates a quaternion by the given angle about the X axis
  98827. *
  98828. * @param {quat} out quat receiving operation result
  98829. * @param {ReadonlyQuat} a quat to rotate
  98830. * @param {number} rad angle (in radians) to rotate
  98831. * @returns {quat} out
  98832. */
  98833. function rotateX(out, a, rad) {
  98834. rad *= 0.5;
  98835. var ax = a[0],
  98836. ay = a[1],
  98837. az = a[2],
  98838. aw = a[3];
  98839. var bx = Math.sin(rad),
  98840. bw = Math.cos(rad);
  98841. out[0] = ax * bw + aw * bx;
  98842. out[1] = ay * bw + az * bx;
  98843. out[2] = az * bw - ay * bx;
  98844. out[3] = aw * bw - ax * bx;
  98845. return out;
  98846. }
  98847. /**
  98848. * Rotates a quaternion by the given angle about the Y axis
  98849. *
  98850. * @param {quat} out quat receiving operation result
  98851. * @param {ReadonlyQuat} a quat to rotate
  98852. * @param {number} rad angle (in radians) to rotate
  98853. * @returns {quat} out
  98854. */
  98855. function rotateY(out, a, rad) {
  98856. rad *= 0.5;
  98857. var ax = a[0],
  98858. ay = a[1],
  98859. az = a[2],
  98860. aw = a[3];
  98861. var by = Math.sin(rad),
  98862. bw = Math.cos(rad);
  98863. out[0] = ax * bw - az * by;
  98864. out[1] = ay * bw + aw * by;
  98865. out[2] = az * bw + ax * by;
  98866. out[3] = aw * bw - ay * by;
  98867. return out;
  98868. }
  98869. /**
  98870. * Rotates a quaternion by the given angle about the Z axis
  98871. *
  98872. * @param {quat} out quat receiving operation result
  98873. * @param {ReadonlyQuat} a quat to rotate
  98874. * @param {number} rad angle (in radians) to rotate
  98875. * @returns {quat} out
  98876. */
  98877. function rotateZ(out, a, rad) {
  98878. rad *= 0.5;
  98879. var ax = a[0],
  98880. ay = a[1],
  98881. az = a[2],
  98882. aw = a[3];
  98883. var bz = Math.sin(rad),
  98884. bw = Math.cos(rad);
  98885. out[0] = ax * bw + ay * bz;
  98886. out[1] = ay * bw - ax * bz;
  98887. out[2] = az * bw + aw * bz;
  98888. out[3] = aw * bw - az * bz;
  98889. return out;
  98890. }
  98891. /**
  98892. * Calculates the W component of a quat from the X, Y, and Z components.
  98893. * Assumes that quaternion is 1 unit in length.
  98894. * Any existing W component will be ignored.
  98895. *
  98896. * @param {quat} out the receiving quaternion
  98897. * @param {ReadonlyQuat} a quat to calculate W component of
  98898. * @returns {quat} out
  98899. */
  98900. function calculateW(out, a) {
  98901. var x = a[0],
  98902. y = a[1],
  98903. z = a[2];
  98904. out[0] = x;
  98905. out[1] = y;
  98906. out[2] = z;
  98907. out[3] = Math.sqrt(Math.abs(1.0 - x * x - y * y - z * z));
  98908. return out;
  98909. }
  98910. /**
  98911. * Performs a spherical linear interpolation between two quat
  98912. *
  98913. * @param {quat} out the receiving quaternion
  98914. * @param {ReadonlyQuat} a the first operand
  98915. * @param {ReadonlyQuat} b the second operand
  98916. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  98917. * @returns {quat} out
  98918. */
  98919. function slerp(out, a, b, t) {
  98920. // benchmarks:
  98921. // http://jsperf.com/quaternion-slerp-implementations
  98922. var ax = a[0],
  98923. ay = a[1],
  98924. az = a[2],
  98925. aw = a[3];
  98926. var bx = b[0],
  98927. by = b[1],
  98928. bz = b[2],
  98929. bw = b[3];
  98930. var omega, cosom, sinom, scale0, scale1; // calc cosine
  98931. cosom = ax * bx + ay * by + az * bz + aw * bw; // adjust signs (if necessary)
  98932. if (cosom < 0.0) {
  98933. cosom = -cosom;
  98934. bx = -bx;
  98935. by = -by;
  98936. bz = -bz;
  98937. bw = -bw;
  98938. } // calculate coefficients
  98939. if (1.0 - cosom > EPSILON) {
  98940. // standard case (slerp)
  98941. omega = Math.acos(cosom);
  98942. sinom = Math.sin(omega);
  98943. scale0 = Math.sin((1.0 - t) * omega) / sinom;
  98944. scale1 = Math.sin(t * omega) / sinom;
  98945. } else {
  98946. // "from" and "to" quaternions are very close
  98947. // ... so we can do a linear interpolation
  98948. scale0 = 1.0 - t;
  98949. scale1 = t;
  98950. } // calculate final values
  98951. out[0] = scale0 * ax + scale1 * bx;
  98952. out[1] = scale0 * ay + scale1 * by;
  98953. out[2] = scale0 * az + scale1 * bz;
  98954. out[3] = scale0 * aw + scale1 * bw;
  98955. return out;
  98956. }
  98957. /**
  98958. * Calculates the inverse of a quat
  98959. *
  98960. * @param {quat} out the receiving quaternion
  98961. * @param {ReadonlyQuat} a quat to calculate inverse of
  98962. * @returns {quat} out
  98963. */
  98964. function invert(out, a) {
  98965. var a0 = a[0],
  98966. a1 = a[1],
  98967. a2 = a[2],
  98968. a3 = a[3];
  98969. var dot = a0 * a0 + a1 * a1 + a2 * a2 + a3 * a3;
  98970. var invDot = dot ? 1.0 / dot : 0; // TODO: Would be faster to return [0,0,0,0] immediately if dot == 0
  98971. out[0] = -a0 * invDot;
  98972. out[1] = -a1 * invDot;
  98973. out[2] = -a2 * invDot;
  98974. out[3] = a3 * invDot;
  98975. return out;
  98976. }
  98977. /**
  98978. * Calculates the conjugate of a quat
  98979. * If the quaternion is normalized, this function is faster than quat.inverse and produces the same result.
  98980. *
  98981. * @param {quat} out the receiving quaternion
  98982. * @param {ReadonlyQuat} a quat to calculate conjugate of
  98983. * @returns {quat} out
  98984. */
  98985. function conjugate(out, a) {
  98986. out[0] = -a[0];
  98987. out[1] = -a[1];
  98988. out[2] = -a[2];
  98989. out[3] = a[3];
  98990. return out;
  98991. }
  98992. /**
  98993. * Creates a quaternion from the given 3x3 rotation matrix.
  98994. *
  98995. * NOTE: The resultant quaternion is not normalized, so you should be sure
  98996. * to renormalize the quaternion yourself where necessary.
  98997. *
  98998. * @param {quat} out the receiving quaternion
  98999. * @param {ReadonlyMat3} m rotation matrix
  99000. * @returns {quat} out
  99001. * @function
  99002. */
  99003. function fromMat3(out, m) {
  99004. // Algorithm in Ken Shoemake's article in 1987 SIGGRAPH course notes
  99005. // article "Quaternion Calculus and Fast Animation".
  99006. var fTrace = m[0] + m[4] + m[8];
  99007. var fRoot;
  99008. if (fTrace > 0.0) {
  99009. // |w| > 1/2, may as well choose w > 1/2
  99010. fRoot = Math.sqrt(fTrace + 1.0); // 2w
  99011. out[3] = 0.5 * fRoot;
  99012. fRoot = 0.5 / fRoot; // 1/(4w)
  99013. out[0] = (m[5] - m[7]) * fRoot;
  99014. out[1] = (m[6] - m[2]) * fRoot;
  99015. out[2] = (m[1] - m[3]) * fRoot;
  99016. } else {
  99017. // |w| <= 1/2
  99018. var i = 0;
  99019. if (m[4] > m[0]) i = 1;
  99020. if (m[8] > m[i * 3 + i]) i = 2;
  99021. var j = (i + 1) % 3;
  99022. var k = (i + 2) % 3;
  99023. fRoot = Math.sqrt(m[i * 3 + i] - m[j * 3 + j] - m[k * 3 + k] + 1.0);
  99024. out[i] = 0.5 * fRoot;
  99025. fRoot = 0.5 / fRoot;
  99026. out[3] = (m[j * 3 + k] - m[k * 3 + j]) * fRoot;
  99027. out[j] = (m[j * 3 + i] + m[i * 3 + j]) * fRoot;
  99028. out[k] = (m[k * 3 + i] + m[i * 3 + k]) * fRoot;
  99029. }
  99030. return out;
  99031. }
  99032. /**
  99033. * Adds two quat's
  99034. *
  99035. * @param {quat} out the receiving quaternion
  99036. * @param {ReadonlyQuat} a the first operand
  99037. * @param {ReadonlyQuat} b the second operand
  99038. * @returns {quat} out
  99039. * @function
  99040. */
  99041. var add = add$1;
  99042. /**
  99043. * Scales a quat by a scalar number
  99044. *
  99045. * @param {quat} out the receiving vector
  99046. * @param {ReadonlyQuat} a the vector to scale
  99047. * @param {Number} b amount to scale the vector by
  99048. * @returns {quat} out
  99049. * @function
  99050. */
  99051. var scale = scale$1;
  99052. /**
  99053. * Calculates the dot product of two quat's
  99054. *
  99055. * @param {ReadonlyQuat} a the first operand
  99056. * @param {ReadonlyQuat} b the second operand
  99057. * @returns {Number} dot product of a and b
  99058. * @function
  99059. */
  99060. var dot = dot$1;
  99061. /**
  99062. * Performs a linear interpolation between two quat's
  99063. *
  99064. * @param {quat} out the receiving quaternion
  99065. * @param {ReadonlyQuat} a the first operand
  99066. * @param {ReadonlyQuat} b the second operand
  99067. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  99068. * @returns {quat} out
  99069. * @function
  99070. */
  99071. var lerp$2 = lerp$1;
  99072. /**
  99073. * Calculates the length of a quat
  99074. *
  99075. * @param {ReadonlyQuat} a vector to calculate length of
  99076. * @returns {Number} length of a
  99077. */
  99078. var length = length$1;
  99079. /**
  99080. * Calculates the squared length of a quat
  99081. *
  99082. * @param {ReadonlyQuat} a vector to calculate squared length of
  99083. * @returns {Number} squared length of a
  99084. * @function
  99085. */
  99086. var squaredLength = squaredLength$1;
  99087. /**
  99088. * Normalize a quat
  99089. *
  99090. * @param {quat} out the receiving quaternion
  99091. * @param {ReadonlyQuat} a quaternion to normalize
  99092. * @returns {quat} out
  99093. * @function
  99094. */
  99095. var normalize = normalize$1;
  99096. /**
  99097. * Sets a quaternion to represent the shortest rotation from one
  99098. * vector to another.
  99099. *
  99100. * Both vectors are assumed to be unit length.
  99101. *
  99102. * @param {quat} out the receiving quaternion.
  99103. * @param {ReadonlyVec3} a the initial vector
  99104. * @param {ReadonlyVec3} b the destination vector
  99105. * @returns {quat} out
  99106. */
  99107. var rotationTo = function () {
  99108. var tmpvec3 = create$3();
  99109. var xUnitVec3 = fromValues(1, 0, 0);
  99110. var yUnitVec3 = fromValues(0, 1, 0);
  99111. return function (out, a, b) {
  99112. var dot = dot$2(a, b);
  99113. if (dot < -0.999999) {
  99114. cross(tmpvec3, xUnitVec3, a);
  99115. if (len(tmpvec3) < 0.000001) cross(tmpvec3, yUnitVec3, a);
  99116. normalize$2(tmpvec3, tmpvec3);
  99117. setAxisAngle(out, tmpvec3, Math.PI);
  99118. return out;
  99119. } else if (dot > 0.999999) {
  99120. out[0] = 0;
  99121. out[1] = 0;
  99122. out[2] = 0;
  99123. out[3] = 1;
  99124. return out;
  99125. } else {
  99126. cross(tmpvec3, a, b);
  99127. out[0] = tmpvec3[0];
  99128. out[1] = tmpvec3[1];
  99129. out[2] = tmpvec3[2];
  99130. out[3] = 1 + dot;
  99131. return normalize(out, out);
  99132. }
  99133. };
  99134. }();
  99135. /**
  99136. * Performs a spherical linear interpolation with two control points
  99137. *
  99138. * @param {quat} out the receiving quaternion
  99139. * @param {ReadonlyQuat} a the first operand
  99140. * @param {ReadonlyQuat} b the second operand
  99141. * @param {ReadonlyQuat} c the third operand
  99142. * @param {ReadonlyQuat} d the fourth operand
  99143. * @param {Number} t interpolation amount, in the range [0-1], between the two inputs
  99144. * @returns {quat} out
  99145. */
  99146. (function () {
  99147. var temp1 = create();
  99148. var temp2 = create();
  99149. return function (out, a, b, c, d, t) {
  99150. slerp(temp1, a, d, t);
  99151. slerp(temp2, b, c, t);
  99152. slerp(out, temp1, temp2, 2 * t * (1 - t));
  99153. return out;
  99154. };
  99155. })();
  99156. /**
  99157. * Sets the specified quaternion with values corresponding to the given
  99158. * axes. Each axis is a vec3 and is expected to be unit length and
  99159. * perpendicular to all other specified axes.
  99160. *
  99161. * @param {ReadonlyVec3} view the vector representing the viewing direction
  99162. * @param {ReadonlyVec3} right the vector representing the local "right" direction
  99163. * @param {ReadonlyVec3} up the vector representing the local "up" direction
  99164. * @returns {quat} out
  99165. */
  99166. (function () {
  99167. var matr = create$2();
  99168. return function (out, view, right, up) {
  99169. matr[0] = right[0];
  99170. matr[3] = right[1];
  99171. matr[6] = right[2];
  99172. matr[1] = up[0];
  99173. matr[4] = up[1];
  99174. matr[7] = up[2];
  99175. matr[2] = -view[0];
  99176. matr[5] = -view[1];
  99177. matr[8] = -view[2];
  99178. return normalize(out, fromMat3(out, matr));
  99179. };
  99180. })();
  99181. const IDENTITY_QUATERNION = [0, 0, 0, 1];
  99182. class Quaternion$1 extends MathArray {
  99183. constructor(x = 0, y = 0, z = 0, w = 1) {
  99184. super(-0, -0, -0, -0);
  99185. if (Array.isArray(x) && arguments.length === 1) {
  99186. this.copy(x);
  99187. } else {
  99188. this.set(x, y, z, w);
  99189. }
  99190. }
  99191. copy(array) {
  99192. this[0] = array[0];
  99193. this[1] = array[1];
  99194. this[2] = array[2];
  99195. this[3] = array[3];
  99196. return this.check();
  99197. }
  99198. set(x, y, z, w) {
  99199. this[0] = x;
  99200. this[1] = y;
  99201. this[2] = z;
  99202. this[3] = w;
  99203. return this.check();
  99204. }
  99205. fromMatrix3(m) {
  99206. fromMat3(this, m);
  99207. return this.check();
  99208. }
  99209. identity() {
  99210. identity(this);
  99211. return this.check();
  99212. }
  99213. fromAxisRotation(axis, rad) {
  99214. setAxisAngle(this, axis, rad);
  99215. return this.check();
  99216. }
  99217. setAxisAngle(axis, rad) {
  99218. return this.fromAxisRotation(axis, rad);
  99219. }
  99220. get ELEMENTS() {
  99221. return 4;
  99222. }
  99223. get x() {
  99224. return this[0];
  99225. }
  99226. set x(value) {
  99227. this[0] = checkNumber(value);
  99228. }
  99229. get y() {
  99230. return this[1];
  99231. }
  99232. set y(value) {
  99233. this[1] = checkNumber(value);
  99234. }
  99235. get z() {
  99236. return this[2];
  99237. }
  99238. set z(value) {
  99239. this[2] = checkNumber(value);
  99240. }
  99241. get w() {
  99242. return this[3];
  99243. }
  99244. set w(value) {
  99245. this[3] = checkNumber(value);
  99246. }
  99247. len() {
  99248. return length(this);
  99249. }
  99250. lengthSquared() {
  99251. return squaredLength(this);
  99252. }
  99253. dot(a, b) {
  99254. if (b !== undefined) {
  99255. throw new Error('Quaternion.dot only takes one argument');
  99256. }
  99257. return dot(this, a);
  99258. }
  99259. rotationTo(vectorA, vectorB) {
  99260. rotationTo(this, vectorA, vectorB);
  99261. return this.check();
  99262. }
  99263. add(a, b) {
  99264. if (b !== undefined) {
  99265. throw new Error('Quaternion.add only takes one argument');
  99266. }
  99267. add(this, this, a);
  99268. return this.check();
  99269. }
  99270. calculateW() {
  99271. calculateW(this, this);
  99272. return this.check();
  99273. }
  99274. conjugate() {
  99275. conjugate(this, this);
  99276. return this.check();
  99277. }
  99278. invert() {
  99279. invert(this, this);
  99280. return this.check();
  99281. }
  99282. lerp(a, b, t) {
  99283. lerp$2(this, a, b, t);
  99284. return this.check();
  99285. }
  99286. multiplyRight(a, b) {
  99287. assert$4(!b);
  99288. multiply(this, this, a);
  99289. return this.check();
  99290. }
  99291. multiplyLeft(a, b) {
  99292. assert$4(!b);
  99293. multiply(this, a, this);
  99294. return this.check();
  99295. }
  99296. normalize() {
  99297. const length = this.len();
  99298. const l = length > 0 ? 1 / length : 0;
  99299. this[0] = this[0] * l;
  99300. this[1] = this[1] * l;
  99301. this[2] = this[2] * l;
  99302. this[3] = this[3] * l;
  99303. if (length === 0) {
  99304. this[3] = 1;
  99305. }
  99306. return this.check();
  99307. }
  99308. rotateX(rad) {
  99309. rotateX(this, this, rad);
  99310. return this.check();
  99311. }
  99312. rotateY(rad) {
  99313. rotateY(this, this, rad);
  99314. return this.check();
  99315. }
  99316. rotateZ(rad) {
  99317. rotateZ(this, this, rad);
  99318. return this.check();
  99319. }
  99320. scale(b) {
  99321. scale(this, this, b);
  99322. return this.check();
  99323. }
  99324. slerp(start, target, ratio) {
  99325. switch (arguments.length) {
  99326. case 1:
  99327. ({
  99328. start = IDENTITY_QUATERNION,
  99329. target,
  99330. ratio
  99331. } = arguments[0]);
  99332. break;
  99333. case 2:
  99334. [target, ratio] = arguments;
  99335. start = this;
  99336. break;
  99337. }
  99338. slerp(this, start, target, ratio);
  99339. return this.check();
  99340. }
  99341. transformVector4(vector, result = vector) {
  99342. transformQuat(result, vector, this);
  99343. return checkVector(result, 4);
  99344. }
  99345. lengthSq() {
  99346. return this.lengthSquared();
  99347. }
  99348. setFromAxisAngle(axis, rad) {
  99349. return this.setAxisAngle(axis, rad);
  99350. }
  99351. premultiply(a, b) {
  99352. return this.multiplyLeft(a, b);
  99353. }
  99354. multiply(a, b) {
  99355. return this.multiplyRight(a, b);
  99356. }
  99357. }
  99358. var _MathUtils = {
  99359. EPSILON1: 1e-1,
  99360. EPSILON2: 1e-2,
  99361. EPSILON3: 1e-3,
  99362. EPSILON4: 1e-4,
  99363. EPSILON5: 1e-5,
  99364. EPSILON6: 1e-6,
  99365. EPSILON7: 1e-7,
  99366. EPSILON8: 1e-8,
  99367. EPSILON9: 1e-9,
  99368. EPSILON10: 1e-10,
  99369. EPSILON11: 1e-11,
  99370. EPSILON12: 1e-12,
  99371. EPSILON13: 1e-13,
  99372. EPSILON14: 1e-14,
  99373. EPSILON15: 1e-15,
  99374. EPSILON16: 1e-16,
  99375. EPSILON17: 1e-17,
  99376. EPSILON18: 1e-18,
  99377. EPSILON19: 1e-19,
  99378. EPSILON20: 1e-20,
  99379. PI_OVER_TWO: Math.PI / 2,
  99380. PI_OVER_FOUR: Math.PI / 4,
  99381. PI_OVER_SIX: Math.PI / 6,
  99382. TWO_PI: Math.PI * 2
  99383. };
  99384. const WGS84_RADIUS_X$1 = 6378137.0;
  99385. const WGS84_RADIUS_Y$1 = 6378137.0;
  99386. const WGS84_RADIUS_Z$1 = 6356752.3142451793;
  99387. const noop$2 = x => x;
  99388. const scratchVector$6 = new Vector3$1();
  99389. function fromCartographic(cartographic, result, map = noop$2) {
  99390. if (isArray(cartographic)) {
  99391. result[0] = map(cartographic[0]);
  99392. result[1] = map(cartographic[1]);
  99393. result[2] = cartographic[2];
  99394. } else if ('longitude' in cartographic) {
  99395. result[0] = map(cartographic.longitude);
  99396. result[1] = map(cartographic.latitude);
  99397. result[2] = cartographic.height;
  99398. } else {
  99399. result[0] = map(cartographic.x);
  99400. result[1] = map(cartographic.y);
  99401. result[2] = cartographic.z;
  99402. }
  99403. return result;
  99404. }
  99405. function fromCartographicToRadians(cartographic, vector = scratchVector$6) {
  99406. return fromCartographic(cartographic, vector, config$2._cartographicRadians ? noop$2 : toRadians);
  99407. }
  99408. function toCartographic(vector, cartographic, map = noop$2) {
  99409. if (isArray(cartographic)) {
  99410. cartographic[0] = map(vector[0]);
  99411. cartographic[1] = map(vector[1]);
  99412. cartographic[2] = vector[2];
  99413. } else if ('longitude' in cartographic) {
  99414. cartographic.longitude = map(vector[0]);
  99415. cartographic.latitude = map(vector[1]);
  99416. cartographic.height = vector[2];
  99417. } else {
  99418. cartographic.x = map(vector[0]);
  99419. cartographic.y = map(vector[1]);
  99420. cartographic.z = vector[2];
  99421. }
  99422. return cartographic;
  99423. }
  99424. function toCartographicFromRadians(vector, cartographic) {
  99425. return toCartographic(vector, cartographic, config$2._cartographicRadians ? noop$2 : toDegrees);
  99426. }
  99427. const scratchVector$5 = new Vector3$1();
  99428. const scaleToGeodeticSurfaceIntersection = new Vector3$1();
  99429. const scaleToGeodeticSurfaceGradient = new Vector3$1();
  99430. function scaleToGeodeticSurface(cartesian, ellipsoid, result = new Vector3$1()) {
  99431. const {
  99432. oneOverRadii,
  99433. oneOverRadiiSquared,
  99434. centerToleranceSquared
  99435. } = ellipsoid;
  99436. scratchVector$5.from(cartesian);
  99437. const positionX = cartesian.x;
  99438. const positionY = cartesian.y;
  99439. const positionZ = cartesian.z;
  99440. const oneOverRadiiX = oneOverRadii.x;
  99441. const oneOverRadiiY = oneOverRadii.y;
  99442. const oneOverRadiiZ = oneOverRadii.z;
  99443. const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
  99444. const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
  99445. const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
  99446. const squaredNorm = x2 + y2 + z2;
  99447. const ratio = Math.sqrt(1.0 / squaredNorm);
  99448. if (!Number.isFinite(ratio)) {
  99449. return undefined;
  99450. }
  99451. const intersection = scaleToGeodeticSurfaceIntersection;
  99452. intersection.copy(cartesian).scale(ratio);
  99453. if (squaredNorm < centerToleranceSquared) {
  99454. return intersection.to(result);
  99455. }
  99456. const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
  99457. const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
  99458. const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
  99459. const gradient = scaleToGeodeticSurfaceGradient;
  99460. gradient.set(intersection.x * oneOverRadiiSquaredX * 2.0, intersection.y * oneOverRadiiSquaredY * 2.0, intersection.z * oneOverRadiiSquaredZ * 2.0);
  99461. let lambda = (1.0 - ratio) * cartesian.len() / (0.5 * gradient.len());
  99462. let correction = 0.0;
  99463. let xMultiplier;
  99464. let yMultiplier;
  99465. let zMultiplier;
  99466. let func;
  99467. do {
  99468. lambda -= correction;
  99469. xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
  99470. yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
  99471. zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);
  99472. const xMultiplier2 = xMultiplier * xMultiplier;
  99473. const yMultiplier2 = yMultiplier * yMultiplier;
  99474. const zMultiplier2 = zMultiplier * zMultiplier;
  99475. const xMultiplier3 = xMultiplier2 * xMultiplier;
  99476. const yMultiplier3 = yMultiplier2 * yMultiplier;
  99477. const zMultiplier3 = zMultiplier2 * zMultiplier;
  99478. func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
  99479. const denominator = x2 * xMultiplier3 * oneOverRadiiSquaredX + y2 * yMultiplier3 * oneOverRadiiSquaredY + z2 * zMultiplier3 * oneOverRadiiSquaredZ;
  99480. const derivative = -2.0 * denominator;
  99481. correction = func / derivative;
  99482. } while (Math.abs(func) > _MathUtils.EPSILON12);
  99483. return scratchVector$5.scale([xMultiplier, yMultiplier, zMultiplier]).to(result);
  99484. }
  99485. const EPSILON14 = 1e-14;
  99486. const scratchOrigin = new Vector3$1();
  99487. const VECTOR_PRODUCT_LOCAL_FRAME = {
  99488. up: {
  99489. south: 'east',
  99490. north: 'west',
  99491. west: 'south',
  99492. east: 'north'
  99493. },
  99494. down: {
  99495. south: 'west',
  99496. north: 'east',
  99497. west: 'north',
  99498. east: 'south'
  99499. },
  99500. south: {
  99501. up: 'west',
  99502. down: 'east',
  99503. west: 'down',
  99504. east: 'up'
  99505. },
  99506. north: {
  99507. up: 'east',
  99508. down: 'west',
  99509. west: 'up',
  99510. east: 'down'
  99511. },
  99512. west: {
  99513. up: 'north',
  99514. down: 'south',
  99515. north: 'down',
  99516. south: 'up'
  99517. },
  99518. east: {
  99519. up: 'south',
  99520. down: 'north',
  99521. north: 'up',
  99522. south: 'down'
  99523. }
  99524. };
  99525. const degeneratePositionLocalFrame = {
  99526. north: [-1, 0, 0],
  99527. east: [0, 1, 0],
  99528. up: [0, 0, 1],
  99529. south: [1, 0, 0],
  99530. west: [0, -1, 0],
  99531. down: [0, 0, -1]
  99532. };
  99533. const scratchAxisVectors = {
  99534. east: new Vector3$1(),
  99535. north: new Vector3$1(),
  99536. up: new Vector3$1(),
  99537. west: new Vector3$1(),
  99538. south: new Vector3$1(),
  99539. down: new Vector3$1()
  99540. };
  99541. const scratchVector1 = new Vector3$1();
  99542. const scratchVector2$1 = new Vector3$1();
  99543. const scratchVector3$1 = new Vector3$1();
  99544. function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
  99545. const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
  99546. assert$4(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
  99547. let firstAxisVector;
  99548. let secondAxisVector;
  99549. let thirdAxisVector;
  99550. const origin = scratchOrigin.copy(cartesianOrigin);
  99551. const atPole = equals$1(origin.x, 0.0, EPSILON14) && equals$1(origin.y, 0.0, EPSILON14);
  99552. if (atPole) {
  99553. const sign = Math.sign(origin.z);
  99554. firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
  99555. if (firstAxis !== 'east' && firstAxis !== 'west') {
  99556. firstAxisVector.scale(sign);
  99557. }
  99558. secondAxisVector = scratchVector2$1.fromArray(degeneratePositionLocalFrame[secondAxis]);
  99559. if (secondAxis !== 'east' && secondAxis !== 'west') {
  99560. secondAxisVector.scale(sign);
  99561. }
  99562. thirdAxisVector = scratchVector3$1.fromArray(degeneratePositionLocalFrame[thirdAxis]);
  99563. if (thirdAxis !== 'east' && thirdAxis !== 'west') {
  99564. thirdAxisVector.scale(sign);
  99565. }
  99566. } else {
  99567. const {
  99568. up,
  99569. east,
  99570. north
  99571. } = scratchAxisVectors;
  99572. east.set(-origin.y, origin.x, 0.0).normalize();
  99573. ellipsoid.geodeticSurfaceNormal(origin, up);
  99574. north.copy(up).cross(east);
  99575. const {
  99576. down,
  99577. west,
  99578. south
  99579. } = scratchAxisVectors;
  99580. down.copy(up).scale(-1);
  99581. west.copy(east).scale(-1);
  99582. south.copy(north).scale(-1);
  99583. firstAxisVector = scratchAxisVectors[firstAxis];
  99584. secondAxisVector = scratchAxisVectors[secondAxis];
  99585. thirdAxisVector = scratchAxisVectors[thirdAxis];
  99586. }
  99587. result[0] = firstAxisVector.x;
  99588. result[1] = firstAxisVector.y;
  99589. result[2] = firstAxisVector.z;
  99590. result[3] = 0.0;
  99591. result[4] = secondAxisVector.x;
  99592. result[5] = secondAxisVector.y;
  99593. result[6] = secondAxisVector.z;
  99594. result[7] = 0.0;
  99595. result[8] = thirdAxisVector.x;
  99596. result[9] = thirdAxisVector.y;
  99597. result[10] = thirdAxisVector.z;
  99598. result[11] = 0.0;
  99599. result[12] = origin.x;
  99600. result[13] = origin.y;
  99601. result[14] = origin.z;
  99602. result[15] = 1.0;
  99603. return result;
  99604. }
  99605. const scratchVector$4 = new Vector3$1();
  99606. const scratchNormal$2 = new Vector3$1();
  99607. const scratchK = new Vector3$1();
  99608. const scratchPosition$2 = new Vector3$1();
  99609. const scratchHeight = new Vector3$1();
  99610. const scratchCartesian = new Vector3$1();
  99611. let wgs84;
  99612. class Ellipsoid {
  99613. static get WGS84() {
  99614. wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X$1, WGS84_RADIUS_Y$1, WGS84_RADIUS_Z$1);
  99615. return wgs84;
  99616. }
  99617. constructor(x = 0.0, y = 0.0, z = 0.0) {
  99618. assert$4(x >= 0.0);
  99619. assert$4(y >= 0.0);
  99620. assert$4(z >= 0.0);
  99621. this.radii = new Vector3$1(x, y, z);
  99622. this.radiiSquared = new Vector3$1(x * x, y * y, z * z);
  99623. this.radiiToTheFourth = new Vector3$1(x * x * x * x, y * y * y * y, z * z * z * z);
  99624. 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);
  99625. 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));
  99626. this.minimumRadius = Math.min(x, y, z);
  99627. this.maximumRadius = Math.max(x, y, z);
  99628. this.centerToleranceSquared = _MathUtils.EPSILON1;
  99629. if (this.radiiSquared.z !== 0) {
  99630. this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
  99631. }
  99632. Object.freeze(this);
  99633. }
  99634. equals(right) {
  99635. return this === right || Boolean(right && this.radii.equals(right.radii));
  99636. }
  99637. toString() {
  99638. return this.radii.toString();
  99639. }
  99640. cartographicToCartesian(cartographic, result = [0, 0, 0]) {
  99641. const normal = scratchNormal$2;
  99642. const k = scratchK;
  99643. const [,, height] = cartographic;
  99644. this.geodeticSurfaceNormalCartographic(cartographic, normal);
  99645. k.copy(this.radiiSquared).scale(normal);
  99646. const gamma = Math.sqrt(normal.dot(k));
  99647. k.scale(1 / gamma);
  99648. normal.scale(height);
  99649. k.add(normal);
  99650. return k.to(result);
  99651. }
  99652. cartesianToCartographic(cartesian, result = [0, 0, 0]) {
  99653. scratchCartesian.from(cartesian);
  99654. const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition$2);
  99655. if (!point) {
  99656. return undefined;
  99657. }
  99658. const normal = this.geodeticSurfaceNormal(point, scratchNormal$2);
  99659. const h = scratchHeight;
  99660. h.copy(scratchCartesian).subtract(point);
  99661. const longitude = Math.atan2(normal.y, normal.x);
  99662. const latitude = Math.asin(normal.z);
  99663. const height = Math.sign(dot$2(h, scratchCartesian)) * length$2(h);
  99664. return toCartographicFromRadians([longitude, latitude, height], result);
  99665. }
  99666. eastNorthUpToFixedFrame(origin, result = new Matrix4$1()) {
  99667. return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
  99668. }
  99669. localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4$1()) {
  99670. return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
  99671. }
  99672. geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
  99673. return scratchVector$4.from(cartesian).normalize().to(result);
  99674. }
  99675. geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
  99676. const cartographicVectorRadians = fromCartographicToRadians(cartographic);
  99677. const longitude = cartographicVectorRadians[0];
  99678. const latitude = cartographicVectorRadians[1];
  99679. const cosLatitude = Math.cos(latitude);
  99680. scratchVector$4.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude)).normalize();
  99681. return scratchVector$4.to(result);
  99682. }
  99683. geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
  99684. return scratchVector$4.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
  99685. }
  99686. scaleToGeodeticSurface(cartesian, result) {
  99687. return scaleToGeodeticSurface(cartesian, this, result);
  99688. }
  99689. scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
  99690. scratchPosition$2.from(cartesian);
  99691. const positionX = scratchPosition$2.x;
  99692. const positionY = scratchPosition$2.y;
  99693. const positionZ = scratchPosition$2.z;
  99694. const oneOverRadiiSquared = this.oneOverRadiiSquared;
  99695. const beta = 1.0 / Math.sqrt(positionX * positionX * oneOverRadiiSquared.x + positionY * positionY * oneOverRadiiSquared.y + positionZ * positionZ * oneOverRadiiSquared.z);
  99696. return scratchPosition$2.multiplyScalar(beta).to(result);
  99697. }
  99698. transformPositionToScaledSpace(position, result = [0, 0, 0]) {
  99699. return scratchPosition$2.from(position).scale(this.oneOverRadii).to(result);
  99700. }
  99701. transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
  99702. return scratchPosition$2.from(position).scale(this.radii).to(result);
  99703. }
  99704. getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {
  99705. assert$4(equals$1(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
  99706. assert$4(this.radii.z > 0);
  99707. scratchPosition$2.from(position);
  99708. const z = scratchPosition$2.z * (1 - this.squaredXOverSquaredZ);
  99709. if (Math.abs(z) >= this.radii.z - buffer) {
  99710. return undefined;
  99711. }
  99712. return scratchPosition$2.set(0.0, 0.0, z).to(result);
  99713. }
  99714. }
  99715. class DoublyLinkedListNode {
  99716. constructor(item, previous, next) {
  99717. _defineProperty(this, "item", void 0);
  99718. _defineProperty(this, "previous", void 0);
  99719. _defineProperty(this, "next", void 0);
  99720. this.item = item;
  99721. this.previous = previous;
  99722. this.next = next;
  99723. }
  99724. }
  99725. class DoublyLinkedList {
  99726. constructor() {
  99727. _defineProperty(this, "head", null);
  99728. _defineProperty(this, "tail", null);
  99729. _defineProperty(this, "_length", 0);
  99730. }
  99731. get length() {
  99732. return this._length;
  99733. }
  99734. add(item) {
  99735. const node = new DoublyLinkedListNode(item, this.tail, null);
  99736. if (this.tail) {
  99737. this.tail.next = node;
  99738. this.tail = node;
  99739. } else {
  99740. this.head = node;
  99741. this.tail = node;
  99742. }
  99743. ++this._length;
  99744. return node;
  99745. }
  99746. remove(node) {
  99747. if (!node) {
  99748. return;
  99749. }
  99750. if (node.previous && node.next) {
  99751. node.previous.next = node.next;
  99752. node.next.previous = node.previous;
  99753. } else if (node.previous) {
  99754. node.previous.next = null;
  99755. this.tail = node.previous;
  99756. } else if (node.next) {
  99757. node.next.previous = null;
  99758. this.head = node.next;
  99759. } else {
  99760. this.head = null;
  99761. this.tail = null;
  99762. }
  99763. node.next = null;
  99764. node.previous = null;
  99765. --this._length;
  99766. }
  99767. splice(node, nextNode) {
  99768. if (node === nextNode) {
  99769. return;
  99770. }
  99771. this.remove(nextNode);
  99772. this._insert(node, nextNode);
  99773. }
  99774. _insert(node, nextNode) {
  99775. const oldNodeNext = node.next;
  99776. node.next = nextNode;
  99777. if (this.tail === node) {
  99778. this.tail = nextNode;
  99779. } else {
  99780. oldNodeNext.previous = nextNode;
  99781. }
  99782. nextNode.next = oldNodeNext;
  99783. nextNode.previous = node;
  99784. ++this._length;
  99785. }
  99786. }
  99787. function defined$5(x) {
  99788. return x !== undefined && x !== null;
  99789. }
  99790. class TilesetCache {
  99791. constructor() {
  99792. _defineProperty(this, "_list", void 0);
  99793. _defineProperty(this, "_sentinel", void 0);
  99794. _defineProperty(this, "_trimTiles", void 0);
  99795. this._list = new DoublyLinkedList();
  99796. this._sentinel = this._list.add('sentinel');
  99797. this._trimTiles = false;
  99798. }
  99799. reset() {
  99800. this._list.splice(this._list.tail, this._sentinel);
  99801. }
  99802. touch(tile) {
  99803. const node = tile._cacheNode;
  99804. if (defined$5(node)) {
  99805. this._list.splice(this._sentinel, node);
  99806. }
  99807. }
  99808. add(tileset, tile, addCallback) {
  99809. if (!defined$5(tile._cacheNode)) {
  99810. tile._cacheNode = this._list.add(tile);
  99811. if (addCallback) {
  99812. addCallback(tileset, tile);
  99813. }
  99814. }
  99815. }
  99816. unloadTile(tileset, tile, unloadCallback) {
  99817. const node = tile._cacheNode;
  99818. if (!defined$5(node)) {
  99819. return;
  99820. }
  99821. this._list.remove(node);
  99822. tile._cacheNode = undefined;
  99823. if (unloadCallback) {
  99824. unloadCallback(tileset, tile);
  99825. }
  99826. }
  99827. unloadTiles(tileset, unloadCallback) {
  99828. const trimTiles = this._trimTiles;
  99829. this._trimTiles = false;
  99830. const list = this._list;
  99831. const maximumMemoryUsageInBytes = (Potree.settings.tiles3DMaxMemory || tileset.maximumMemoryUsage) * 1024 * 1024;
  99832. const sentinel = this._sentinel;
  99833. let node = list.head;
  99834. /* while (node !== sentinel && (tileset.gpuMemoryUsageInBytes > maximumMemoryUsageInBytes || trimTiles)) {
  99835. const tile = node.item;
  99836. node = node.next;
  99837. this.unloadTile(tileset, tile, unloadCallback);
  99838. } */
  99839. //改
  99840. while (node !== sentinel && ( getGpuMemoryUsage() > maximumMemoryUsageInBytes || trimTiles)) {
  99841. const tile = node.item;
  99842. node = node.next;
  99843. this.unloadTile(tileset, tile, unloadCallback);
  99844. if(viewer.visiVertexCount > 1500000){ //add: 针对部分特别精细的很卡如 https://4dkk.4dage.com/scene_view_data/SG-t-WReTBN204dQ/images/3dtiles/tileset.json
  99845. tileset.options.maximumScreenSpaceError *= 1.1;
  99846. tileset.options.maximumScreenSpaceError = Math.min(1000, tileset.options.maximumScreenSpaceError);
  99847. }
  99848. }
  99849. }
  99850. trim() {
  99851. this._trimTiles = true;
  99852. }
  99853. }
  99854. function calculateTransformProps(tileHeader, tile) {
  99855. assert$7(tileHeader);
  99856. assert$7(tile);
  99857. const {
  99858. rtcCenter,
  99859. gltfUpAxis
  99860. } = tile;
  99861. const {
  99862. computedTransform,
  99863. boundingVolume: {
  99864. center
  99865. }
  99866. } = tileHeader;
  99867. let modelMatrix = new Matrix4$1(computedTransform);
  99868. if (rtcCenter) {
  99869. modelMatrix.translate(rtcCenter);
  99870. }
  99871. switch (gltfUpAxis) {
  99872. case 'Z':
  99873. break;
  99874. case 'Y':
  99875. const rotationY = new Matrix4$1().rotateX(Math.PI / 2);
  99876. modelMatrix = modelMatrix.multiplyRight(rotationY);
  99877. break;
  99878. case 'X':
  99879. const rotationX = new Matrix4$1().rotateY(-Math.PI / 2);
  99880. modelMatrix = modelMatrix.multiplyRight(rotationX);
  99881. break;
  99882. }
  99883. if (tile.isQuantized) {
  99884. modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
  99885. }
  99886. const cartesianOrigin = new Vector3$1(center);
  99887. tile.cartesianModelMatrix = modelMatrix;
  99888. tile.cartesianOrigin = cartesianOrigin;
  99889. const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3$1());
  99890. const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
  99891. const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
  99892. tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
  99893. tile.cartographicOrigin = cartographicOrigin;
  99894. if (!tile.coordinateSystem) {
  99895. tile.modelMatrix = tile.cartographicModelMatrix;
  99896. }
  99897. }
  99898. const INTERSECTION = Object.freeze({
  99899. OUTSIDE: -1,
  99900. INTERSECTING: 0,
  99901. INSIDE: 1
  99902. });
  99903. new Vector3$1();
  99904. new Vector3$1();
  99905. const scratchVector$3 = new Vector3$1();
  99906. const scratchVector2 = new Vector3$1();
  99907. class BoundingSphere {
  99908. constructor(center = [0, 0, 0], radius = 0.0) {
  99909. this.radius = -0;
  99910. this.center = new Vector3$1();
  99911. this.fromCenterRadius(center, radius);
  99912. }
  99913. fromCenterRadius(center, radius) {
  99914. this.center.from(center);
  99915. this.radius = radius;
  99916. return this;
  99917. }
  99918. fromCornerPoints(corner, oppositeCorner) {
  99919. oppositeCorner = scratchVector$3.from(oppositeCorner);
  99920. this.center = new Vector3$1().from(corner).add(oppositeCorner).scale(0.5);
  99921. this.radius = this.center.distance(oppositeCorner);
  99922. return this;
  99923. }
  99924. equals(right) {
  99925. return this === right || Boolean(right) && this.center.equals(right.center) && this.radius === right.radius;
  99926. }
  99927. clone() {
  99928. return new BoundingSphere(this.center, this.radius);
  99929. }
  99930. union(boundingSphere) {
  99931. const leftCenter = this.center;
  99932. const leftRadius = this.radius;
  99933. const rightCenter = boundingSphere.center;
  99934. const rightRadius = boundingSphere.radius;
  99935. const toRightCenter = scratchVector$3.copy(rightCenter).subtract(leftCenter);
  99936. const centerSeparation = toRightCenter.magnitude();
  99937. if (leftRadius >= centerSeparation + rightRadius) {
  99938. return this.clone();
  99939. }
  99940. if (rightRadius >= centerSeparation + leftRadius) {
  99941. return boundingSphere.clone();
  99942. }
  99943. const halfDistanceBetweenTangentPoints = (leftRadius + centerSeparation + rightRadius) * 0.5;
  99944. scratchVector2.copy(toRightCenter).scale((-leftRadius + halfDistanceBetweenTangentPoints) / centerSeparation).add(leftCenter);
  99945. this.center.copy(scratchVector2);
  99946. this.radius = halfDistanceBetweenTangentPoints;
  99947. return this;
  99948. }
  99949. expand(point) {
  99950. point = scratchVector$3.from(point);
  99951. const radius = point.subtract(this.center).magnitude();
  99952. if (radius > this.radius) {
  99953. this.radius = radius;
  99954. }
  99955. return this;
  99956. }
  99957. transform(transform) {
  99958. this.center.transform(transform);
  99959. const scale = getScaling(scratchVector$3, transform);
  99960. this.radius = Math.max(scale[0], Math.max(scale[1], scale[2])) * this.radius;
  99961. return this;
  99962. }
  99963. distanceSquaredTo(point) {
  99964. const d = this.distanceTo(point);
  99965. return d * d;
  99966. }
  99967. distanceTo(point) {
  99968. point = scratchVector$3.from(point);
  99969. const delta = point.subtract(this.center);
  99970. return Math.max(0, delta.len() - this.radius);
  99971. }
  99972. intersectPlane(plane) {
  99973. const center = this.center;
  99974. const radius = this.radius;
  99975. const normal = plane.normal;
  99976. const distanceToPlane = normal.dot(center) + plane.distance;
  99977. if (distanceToPlane < -radius) {
  99978. return INTERSECTION.OUTSIDE;
  99979. }
  99980. if (distanceToPlane < radius) {
  99981. return INTERSECTION.INTERSECTING;
  99982. }
  99983. return INTERSECTION.INSIDE;
  99984. }
  99985. }
  99986. const scratchVector3 = new Vector3$1();
  99987. const scratchOffset = new Vector3$1();
  99988. const scratchVectorU = new Vector3$1();
  99989. const scratchVectorV = new Vector3$1();
  99990. const scratchVectorW = new Vector3$1();
  99991. const scratchCorner = new Vector3$1();
  99992. const scratchToCenter = new Vector3$1();
  99993. const MATRIX3 = {
  99994. COLUMN0ROW0: 0,
  99995. COLUMN0ROW1: 1,
  99996. COLUMN0ROW2: 2,
  99997. COLUMN1ROW0: 3,
  99998. COLUMN1ROW1: 4,
  99999. COLUMN1ROW2: 5,
  100000. COLUMN2ROW0: 6,
  100001. COLUMN2ROW1: 7,
  100002. COLUMN2ROW2: 8
  100003. };
  100004. class OrientedBoundingBox {
  100005. constructor(center = [0, 0, 0], halfAxes = [0, 0, 0, 0, 0, 0, 0, 0, 0]) {
  100006. this.center = new Vector3$1().from(center);
  100007. this.halfAxes = new Matrix3$1(halfAxes);
  100008. }
  100009. get halfSize() {
  100010. const xAxis = this.halfAxes.getColumn(0);
  100011. const yAxis = this.halfAxes.getColumn(1);
  100012. const zAxis = this.halfAxes.getColumn(2);
  100013. return [new Vector3$1(xAxis).len(), new Vector3$1(yAxis).len(), new Vector3$1(zAxis).len()];
  100014. }
  100015. get quaternion() {
  100016. const xAxis = this.halfAxes.getColumn(0);
  100017. const yAxis = this.halfAxes.getColumn(1);
  100018. const zAxis = this.halfAxes.getColumn(2);
  100019. const normXAxis = new Vector3$1(xAxis).normalize();
  100020. const normYAxis = new Vector3$1(yAxis).normalize();
  100021. const normZAxis = new Vector3$1(zAxis).normalize();
  100022. return new Quaternion$1().fromMatrix3(new Matrix3$1([...normXAxis, ...normYAxis, ...normZAxis]));
  100023. }
  100024. fromCenterHalfSizeQuaternion(center, halfSize, quaternion) {
  100025. const quaternionObject = new Quaternion$1(quaternion);
  100026. const directionsMatrix = new Matrix3$1().fromQuaternion(quaternionObject);
  100027. directionsMatrix[0] = directionsMatrix[0] * halfSize[0];
  100028. directionsMatrix[1] = directionsMatrix[1] * halfSize[0];
  100029. directionsMatrix[2] = directionsMatrix[2] * halfSize[0];
  100030. directionsMatrix[3] = directionsMatrix[3] * halfSize[1];
  100031. directionsMatrix[4] = directionsMatrix[4] * halfSize[1];
  100032. directionsMatrix[5] = directionsMatrix[5] * halfSize[1];
  100033. directionsMatrix[6] = directionsMatrix[6] * halfSize[2];
  100034. directionsMatrix[7] = directionsMatrix[7] * halfSize[2];
  100035. directionsMatrix[8] = directionsMatrix[8] * halfSize[2];
  100036. this.center = new Vector3$1().from(center);
  100037. this.halfAxes = directionsMatrix;
  100038. return this;
  100039. }
  100040. clone() {
  100041. return new OrientedBoundingBox(this.center, this.halfAxes);
  100042. }
  100043. equals(right) {
  100044. return this === right || Boolean(right) && this.center.equals(right.center) && this.halfAxes.equals(right.halfAxes);
  100045. }
  100046. getBoundingSphere(result = new BoundingSphere()) {
  100047. const halfAxes = this.halfAxes;
  100048. const u = halfAxes.getColumn(0, scratchVectorU);//前三个
  100049. const v = halfAxes.getColumn(1, scratchVectorV);
  100050. const w = halfAxes.getColumn(2, scratchVectorW);
  100051. const cornerVector = scratchVector3.copy(u).add(v).add(w);
  100052. result.center.copy(this.center);
  100053. result.radius = cornerVector.magnitude();
  100054. return result;
  100055. }
  100056. intersectPlane(plane) {
  100057. const center = this.center;
  100058. const normal = plane.normal;
  100059. const halfAxes = this.halfAxes;
  100060. const normalX = normal.x;
  100061. const normalY = normal.y;
  100062. const normalZ = normal.z;
  100063. const 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]);
  100064. const distanceToPlane = normal.dot(center) + plane.distance;
  100065. if (distanceToPlane <= -radEffective) {
  100066. return INTERSECTION.OUTSIDE;
  100067. } else if (distanceToPlane >= radEffective) {
  100068. return INTERSECTION.INSIDE;
  100069. }
  100070. return INTERSECTION.INTERSECTING; //在相机frustum内
  100071. }
  100072. distanceTo(point) {
  100073. return Math.sqrt(this.distanceSquaredTo(point));
  100074. }
  100075. /* distanceSquaredTo(point) {//相机到bound外壳的距离平方
  100076. let center = this.center.clone()
  100077. center.z *= -1
  100078. const offset = scratchOffset.from(point).subtract(center);
  100079. const halfAxes = this.halfAxes;
  100080. const u = halfAxes.getColumn(0, scratchVectorU);
  100081. const v = halfAxes.getColumn(1, scratchVectorV);
  100082. const w = halfAxes.getColumn(2, scratchVectorW);
  100083. u.z *= -1
  100084. v.z *= -1
  100085. w.z *= -1
  100086. const uHalf = u.magnitude();
  100087. const vHalf = v.magnitude();
  100088. const wHalf = w.magnitude();
  100089. u.normalize();
  100090. v.normalize();
  100091. w.normalize();
  100092. let distanceSquared = 0.0;
  100093. let d;
  100094. d = Math.abs(offset.dot(u)) - uHalf;
  100095. if (d > 0) {
  100096. distanceSquared += d * d;
  100097. }
  100098. d = Math.abs(offset.dot(v)) - vHalf;
  100099. if (d > 0) {
  100100. distanceSquared += d * d;
  100101. }
  100102. d = Math.abs(offset.dot(w)) - wHalf;
  100103. if (d > 0) {
  100104. distanceSquared += d * d;
  100105. }
  100106. return distanceSquared;
  100107. } */
  100108. distanceSquaredTo(point) {//相机到bound外壳的距离平方
  100109. const offset = scratchOffset.from(point).subtract(this.center);
  100110. const halfAxes = this.halfAxes;
  100111. const u = halfAxes.getColumn(0, scratchVectorU);
  100112. const v = halfAxes.getColumn(1, scratchVectorV);
  100113. const w = halfAxes.getColumn(2, scratchVectorW);
  100114. const uHalf = u.magnitude();
  100115. const vHalf = v.magnitude();
  100116. const wHalf = w.magnitude();
  100117. u.normalize();
  100118. v.normalize();
  100119. w.normalize();
  100120. let distanceSquared = 0.0;
  100121. let d;
  100122. d = Math.abs(offset.dot(u)) - uHalf;
  100123. if (d > 0) {
  100124. distanceSquared += d * d;
  100125. }
  100126. d = Math.abs(offset.dot(v)) - vHalf;
  100127. if (d > 0) {
  100128. distanceSquared += d * d;
  100129. }
  100130. d = Math.abs(offset.dot(w)) - wHalf;
  100131. if (d > 0) {
  100132. distanceSquared += d * d;
  100133. }
  100134. return distanceSquared;
  100135. }
  100136. computePlaneDistances(position, direction, result = [-0, -0]) {
  100137. let minDist = Number.POSITIVE_INFINITY;
  100138. let maxDist = Number.NEGATIVE_INFINITY;
  100139. const center = this.center;
  100140. const halfAxes = this.halfAxes;
  100141. const u = halfAxes.getColumn(0, scratchVectorU);
  100142. const v = halfAxes.getColumn(1, scratchVectorV);
  100143. const w = halfAxes.getColumn(2, scratchVectorW);
  100144. const corner = scratchCorner.copy(u).add(v).add(w).add(center);
  100145. const toCenter = scratchToCenter.copy(corner).subtract(position);
  100146. let mag = direction.dot(toCenter);
  100147. minDist = Math.min(mag, minDist);
  100148. maxDist = Math.max(mag, maxDist);
  100149. corner.copy(center).add(u).add(v).subtract(w);
  100150. toCenter.copy(corner).subtract(position);
  100151. mag = direction.dot(toCenter);
  100152. minDist = Math.min(mag, minDist);
  100153. maxDist = Math.max(mag, maxDist);
  100154. corner.copy(center).add(u).subtract(v).add(w);
  100155. toCenter.copy(corner).subtract(position);
  100156. mag = direction.dot(toCenter);
  100157. minDist = Math.min(mag, minDist);
  100158. maxDist = Math.max(mag, maxDist);
  100159. corner.copy(center).add(u).subtract(v).subtract(w);
  100160. toCenter.copy(corner).subtract(position);
  100161. mag = direction.dot(toCenter);
  100162. minDist = Math.min(mag, minDist);
  100163. maxDist = Math.max(mag, maxDist);
  100164. center.copy(corner).subtract(u).add(v).add(w);
  100165. toCenter.copy(corner).subtract(position);
  100166. mag = direction.dot(toCenter);
  100167. minDist = Math.min(mag, minDist);
  100168. maxDist = Math.max(mag, maxDist);
  100169. center.copy(corner).subtract(u).add(v).subtract(w);
  100170. toCenter.copy(corner).subtract(position);
  100171. mag = direction.dot(toCenter);
  100172. minDist = Math.min(mag, minDist);
  100173. maxDist = Math.max(mag, maxDist);
  100174. center.copy(corner).subtract(u).subtract(v).add(w);
  100175. toCenter.copy(corner).subtract(position);
  100176. mag = direction.dot(toCenter);
  100177. minDist = Math.min(mag, minDist);
  100178. maxDist = Math.max(mag, maxDist);
  100179. center.copy(corner).subtract(u).subtract(v).subtract(w);
  100180. toCenter.copy(corner).subtract(position);
  100181. mag = direction.dot(toCenter);
  100182. minDist = Math.min(mag, minDist);
  100183. maxDist = Math.max(mag, maxDist);
  100184. result[0] = minDist;
  100185. result[1] = maxDist;
  100186. return result;
  100187. }
  100188. transform(transformation) {
  100189. this.center.transformAsPoint(transformation);
  100190. const xAxis = this.halfAxes.getColumn(0, scratchVectorU);
  100191. xAxis.transformAsPoint(transformation);
  100192. const yAxis = this.halfAxes.getColumn(1, scratchVectorV);
  100193. yAxis.transformAsPoint(transformation);
  100194. const zAxis = this.halfAxes.getColumn(2, scratchVectorW);
  100195. zAxis.transformAsPoint(transformation);
  100196. this.halfAxes = new Matrix3$1([...xAxis, ...yAxis, ...zAxis]);
  100197. return this;
  100198. }
  100199. getTransform() {
  100200. throw new Error('not implemented');
  100201. }
  100202. }
  100203. const scratchPosition$1 = new Vector3$1();
  100204. const scratchNormal$1 = new Vector3$1();
  100205. class Plane$1 {
  100206. constructor(normal = [0, 0, 1], distance = 0) {
  100207. this.normal = new Vector3$1();
  100208. this.distance = -0;
  100209. this.fromNormalDistance(normal, distance);
  100210. }
  100211. fromNormalDistance(normal, distance) {
  100212. assert$4(Number.isFinite(distance));
  100213. this.normal.from(normal).normalize();
  100214. this.distance = distance;
  100215. return this;
  100216. }
  100217. fromPointNormal(point, normal) {
  100218. point = scratchPosition$1.from(point);
  100219. this.normal.from(normal).normalize();
  100220. const distance = -this.normal.dot(point);
  100221. this.distance = distance;
  100222. return this;
  100223. }
  100224. fromCoefficients(a, b, c, d) {
  100225. this.normal.set(a, b, c);
  100226. assert$4(equals$1(this.normal.len(), 1));
  100227. this.distance = d;
  100228. return this;
  100229. }
  100230. clone(plane) {
  100231. return new Plane$1(this.normal, this.distance);
  100232. }
  100233. equals(right) {
  100234. return equals$1(this.distance, right.distance) && equals$1(this.normal, right.normal);
  100235. }
  100236. getPointDistance(point) {
  100237. return this.normal.dot(point) + this.distance;
  100238. }
  100239. transform(matrix4) {
  100240. const normal = scratchNormal$1.copy(this.normal).transformAsVector(matrix4).normalize();
  100241. const point = this.normal.scale(-this.distance).transform(matrix4);
  100242. return this.fromPointNormal(point, normal);
  100243. }
  100244. projectPointOntoPlane(point, result = [0, 0, 0]) {
  100245. point = scratchPosition$1.from(point);
  100246. const pointDistance = this.getPointDistance(point);
  100247. const scaledNormal = scratchNormal$1.copy(this.normal).scale(pointDistance);
  100248. return point.subtract(scaledNormal).to(result);
  100249. }
  100250. }
  100251. const faces = [new Vector3$1([1, 0, 0]), new Vector3$1([0, 1, 0]), new Vector3$1([0, 0, 1])];
  100252. const scratchPlaneCenter = new Vector3$1();
  100253. const scratchPlaneNormal$1 = new Vector3$1();
  100254. new Plane$1(new Vector3$1(1.0, 0.0, 0.0), 0.0);
  100255. class CullingVolume {
  100256. static get MASK_OUTSIDE() {
  100257. return 0xffffffff;
  100258. }
  100259. static get MASK_INSIDE() {
  100260. return 0x00000000;
  100261. }
  100262. static get MASK_INDETERMINATE() {
  100263. return 0x7fffffff;
  100264. }
  100265. constructor(planes = []) {
  100266. this.planes = planes;
  100267. assert$4(this.planes.every(plane => plane instanceof Plane$1));
  100268. }
  100269. fromBoundingSphere(boundingSphere) {
  100270. this.planes.length = 2 * faces.length;
  100271. const center = boundingSphere.center;
  100272. const radius = boundingSphere.radius;
  100273. let planeIndex = 0;
  100274. for (const faceNormal of faces) {
  100275. let plane0 = this.planes[planeIndex];
  100276. let plane1 = this.planes[planeIndex + 1];
  100277. if (!plane0) {
  100278. plane0 = this.planes[planeIndex] = new Plane$1();
  100279. }
  100280. if (!plane1) {
  100281. plane1 = this.planes[planeIndex + 1] = new Plane$1();
  100282. }
  100283. const plane0Center = scratchPlaneCenter.copy(faceNormal).scale(-radius).add(center);
  100284. -faceNormal.dot(plane0Center);
  100285. plane0.fromPointNormal(plane0Center, faceNormal);
  100286. const plane1Center = scratchPlaneCenter.copy(faceNormal).scale(radius).add(center);
  100287. const negatedFaceNormal = scratchPlaneNormal$1.copy(faceNormal).negate();
  100288. -negatedFaceNormal.dot(plane1Center);
  100289. plane1.fromPointNormal(plane1Center, negatedFaceNormal);
  100290. planeIndex += 2;
  100291. }
  100292. return this;
  100293. }
  100294. computeVisibility(boundingVolume) {
  100295. assert$4(boundingVolume);
  100296. let intersect = INTERSECTION.INSIDE;
  100297. for (const plane of this.planes) {
  100298. const result = boundingVolume.intersectPlane(plane);
  100299. switch (result) {
  100300. case INTERSECTION.OUTSIDE:
  100301. return INTERSECTION.OUTSIDE;
  100302. case INTERSECTION.INTERSECTING:
  100303. intersect = INTERSECTION.INTERSECTING;
  100304. break;
  100305. }
  100306. }
  100307. return intersect;
  100308. }
  100309. computeVisibilityWithPlaneMask(boundingVolume, parentPlaneMask) {
  100310. assert$4(boundingVolume, 'boundingVolume is required.');
  100311. assert$4(Number.isFinite(parentPlaneMask), 'parentPlaneMask is required.');
  100312. if (parentPlaneMask === CullingVolume.MASK_OUTSIDE || parentPlaneMask === CullingVolume.MASK_INSIDE) {
  100313. return parentPlaneMask;
  100314. }
  100315. let mask = CullingVolume.MASK_INSIDE;
  100316. const planes = this.planes;
  100317. for (let k = 0; k < this.planes.length; ++k) {
  100318. const flag = k < 31 ? 1 << k : 0;
  100319. if (k < 31 && (parentPlaneMask & flag) === 0) {
  100320. continue;
  100321. }
  100322. const plane = planes[k];
  100323. const result = boundingVolume.intersectPlane(plane);
  100324. if (result === INTERSECTION.OUTSIDE) {
  100325. return CullingVolume.MASK_OUTSIDE;
  100326. } else if (result === INTERSECTION.INTERSECTING) {
  100327. mask |= flag;
  100328. }
  100329. }
  100330. return mask;
  100331. }
  100332. }
  100333. const scratchPlaneUpVector = new Vector3$1();
  100334. const scratchPlaneRightVector = new Vector3$1();
  100335. const scratchPlaneNearCenter = new Vector3$1();
  100336. const scratchPlaneFarCenter = new Vector3$1();
  100337. const scratchPlaneNormal = new Vector3$1();
  100338. class PerspectiveOffCenterFrustum {
  100339. constructor(options = {}) {
  100340. options = {
  100341. near: 1.0,
  100342. far: 500000000.0,
  100343. ...options
  100344. };
  100345. this.left = options.left;
  100346. this._left = undefined;
  100347. this.right = options.right;
  100348. this._right = undefined;
  100349. this.top = options.top;
  100350. this._top = undefined;
  100351. this.bottom = options.bottom;
  100352. this._bottom = undefined;
  100353. this.near = options.near;
  100354. this._near = this.near;
  100355. this.far = options.far;
  100356. this._far = this.far;
  100357. this._cullingVolume = new CullingVolume([new Plane$1(), new Plane$1(), new Plane$1(), new Plane$1(), new Plane$1(), new Plane$1()]);
  100358. this._perspectiveMatrix = new Matrix4$1();
  100359. this._infinitePerspective = new Matrix4$1();
  100360. }
  100361. clone() {
  100362. return new PerspectiveOffCenterFrustum({
  100363. right: this.right,
  100364. left: this.left,
  100365. top: this.top,
  100366. bottom: this.bottom,
  100367. near: this.near,
  100368. far: this.far
  100369. });
  100370. }
  100371. equals(other) {
  100372. 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;
  100373. }
  100374. get projectionMatrix() {
  100375. update$1(this);
  100376. return this._perspectiveMatrix;
  100377. }
  100378. get infiniteProjectionMatrix() {
  100379. update$1(this);
  100380. return this._infinitePerspective;
  100381. }
  100382. computeCullingVolume(position, direction, up) {
  100383. assert$4(position, 'position is required.');
  100384. assert$4(direction, 'direction is required.');
  100385. assert$4(up, 'up is required.');
  100386. const planes = this._cullingVolume.planes;
  100387. up = scratchPlaneUpVector.copy(up).normalize();
  100388. const right = scratchPlaneRightVector.copy(direction).cross(up).normalize();
  100389. const nearCenter = scratchPlaneNearCenter.copy(direction).multiplyByScalar(this.near).add(position);
  100390. const farCenter = scratchPlaneFarCenter.copy(direction).multiplyByScalar(this.far).add(position);
  100391. let normal = scratchPlaneNormal;
  100392. normal.copy(right).multiplyByScalar(this.left).add(nearCenter).subtract(position).cross(up);
  100393. planes[0].fromPointNormal(position, normal);
  100394. normal.copy(right).multiplyByScalar(this.right).add(nearCenter).subtract(position).cross(up).negate();
  100395. planes[1].fromPointNormal(position, normal);
  100396. normal.copy(up).multiplyByScalar(this.bottom).add(nearCenter).subtract(position).cross(right).negate();
  100397. planes[2].fromPointNormal(position, normal);
  100398. normal.copy(up).multiplyByScalar(this.top).add(nearCenter).subtract(position).cross(right);
  100399. planes[3].fromPointNormal(position, normal);
  100400. normal = new Vector3$1().copy(direction);
  100401. planes[4].fromPointNormal(nearCenter, normal);
  100402. normal.negate();
  100403. planes[5].fromPointNormal(farCenter, normal);
  100404. return this._cullingVolume;
  100405. }
  100406. getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
  100407. update$1(this);
  100408. assert$4(Number.isFinite(drawingBufferWidth) && Number.isFinite(drawingBufferHeight));
  100409. assert$4(drawingBufferWidth > 0);
  100410. assert$4(drawingBufferHeight > 0);
  100411. assert$4(distance > 0);
  100412. assert$4(result);
  100413. const inverseNear = 1.0 / this.near;
  100414. let tanTheta = this.top * inverseNear;
  100415. const pixelHeight = 2.0 * distance * tanTheta / drawingBufferHeight;
  100416. tanTheta = this.right * inverseNear;
  100417. const pixelWidth = 2.0 * distance * tanTheta / drawingBufferWidth;
  100418. result.x = pixelWidth;
  100419. result.y = pixelHeight;
  100420. return result;
  100421. }
  100422. }
  100423. function update$1(frustum) {
  100424. 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));
  100425. const {
  100426. top,
  100427. bottom,
  100428. right,
  100429. left,
  100430. near,
  100431. far
  100432. } = frustum;
  100433. if (top !== frustum._top || bottom !== frustum._bottom || left !== frustum._left || right !== frustum._right || near !== frustum._near || far !== frustum._far) {
  100434. assert$4(frustum.near > 0 && frustum.near < frustum.far, 'near must be greater than zero and less than far.');
  100435. frustum._left = left;
  100436. frustum._right = right;
  100437. frustum._top = top;
  100438. frustum._bottom = bottom;
  100439. frustum._near = near;
  100440. frustum._far = far;
  100441. frustum._perspectiveMatrix = new Matrix4$1().frustum({
  100442. left,
  100443. right,
  100444. bottom,
  100445. top,
  100446. near,
  100447. far
  100448. });
  100449. frustum._infinitePerspective = new Matrix4$1().frustum({
  100450. left,
  100451. right,
  100452. bottom,
  100453. top,
  100454. near,
  100455. far: Infinity
  100456. });
  100457. }
  100458. }
  100459. const defined$4 = val => val !== null && typeof val !== 'undefined';
  100460. class PerspectiveFrustum {
  100461. constructor(options = {}) {
  100462. options = {
  100463. near: 1.0,
  100464. far: 500000000.0,
  100465. xOffset: 0.0,
  100466. yOffset: 0.0,
  100467. ...options
  100468. };
  100469. this._offCenterFrustum = new PerspectiveOffCenterFrustum();
  100470. this.fov = options.fov;
  100471. this._fov = undefined;
  100472. this._fovy = undefined;
  100473. this._sseDenominator = undefined;
  100474. this.aspectRatio = options.aspectRatio;
  100475. this._aspectRatio = undefined;
  100476. this.near = options.near;
  100477. this._near = this.near;
  100478. this.far = options.far;
  100479. this._far = this.far;
  100480. this.xOffset = options.xOffset;
  100481. this._xOffset = this.xOffset;
  100482. this.yOffset = options.yOffset;
  100483. this._yOffset = this.yOffset;
  100484. }
  100485. clone() {
  100486. return new PerspectiveFrustum({
  100487. aspectRatio: this.aspectRatio,
  100488. fov: this.fov,
  100489. near: this.near,
  100490. far: this.far
  100491. });
  100492. }
  100493. equals(other) {
  100494. if (!defined$4(other) || !(other instanceof PerspectiveFrustum)) {
  100495. return false;
  100496. }
  100497. update(this);
  100498. update(other);
  100499. return this.fov === other.fov && this.aspectRatio === other.aspectRatio && this.near === other.near && this.far === other.far && this._offCenterFrustum.equals(other._offCenterFrustum);
  100500. }
  100501. get projectionMatrix() {
  100502. update(this);
  100503. return this._offCenterFrustum.projectionMatrix;
  100504. }
  100505. get infiniteProjectionMatrix() {
  100506. update(this);
  100507. return this._offCenterFrustum.infiniteProjectionMatrix;
  100508. }
  100509. get fovy() {
  100510. update(this);
  100511. return this._fovy;
  100512. }
  100513. get sseDenominator() {
  100514. update(this);
  100515. return this._sseDenominator;
  100516. }
  100517. computeCullingVolume(position, direction, up) {
  100518. update(this);
  100519. return this._offCenterFrustum.computeCullingVolume(position, direction, up);
  100520. }
  100521. getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result) {
  100522. update(this);
  100523. return this._offCenterFrustum.getPixelDimensions(drawingBufferWidth, drawingBufferHeight, distance, result);
  100524. }
  100525. }
  100526. function update(frustum) {
  100527. assert$4(Number.isFinite(frustum.fov) && Number.isFinite(frustum.aspectRatio) && Number.isFinite(frustum.near) && Number.isFinite(frustum.far));
  100528. const f = frustum._offCenterFrustum;
  100529. 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) {
  100530. assert$4(frustum.fov >= 0 && frustum.fov < Math.PI);
  100531. //assert$4(frustum.aspectRatio > 0);
  100532. if(frustum.aspectRatio == 0){
  100533. console.log(1);
  100534. }
  100535. assert$4(frustum.near >= 0 && frustum.near < frustum.far);
  100536. frustum._aspectRatio = Math.max(0.001, frustum.aspectRatio);
  100537. frustum._fov = frustum.fov;
  100538. frustum._fovy = frustum._aspectRatio <= 1 ? frustum.fov : Math.atan(Math.tan(frustum.fov * 0.5) / frustum._aspectRatio) * 2.0;
  100539. frustum._near = frustum.near;
  100540. frustum._far = frustum.far;
  100541. frustum._sseDenominator = 2.0 * Math.tan(0.5 * frustum._fovy);
  100542. frustum._xOffset = frustum.xOffset;
  100543. frustum._yOffset = frustum.yOffset;
  100544. f.top = frustum.near * Math.tan(0.5 * frustum._fovy);
  100545. f.bottom = -f.top;
  100546. f.right = frustum._aspectRatio * f.top;
  100547. f.left = -f.right;
  100548. f.near = frustum.near;
  100549. f.far = frustum.far;
  100550. f.right += frustum.xOffset;
  100551. f.left += frustum.xOffset;
  100552. f.top += frustum.yOffset;
  100553. f.bottom += frustum.yOffset;
  100554. }
  100555. }
  100556. new Vector3$1();
  100557. new Vector3$1();
  100558. new Vector3$1();
  100559. new Vector3$1();
  100560. new Vector3$1();
  100561. new Vector3$1();
  100562. new Vector3$1();
  100563. new Vector3$1();
  100564. new Vector3$1();
  100565. new Vector3$1();
  100566. new Vector3$1();
  100567. new Vector3$1();
  100568. new Matrix3$1();
  100569. new Matrix3$1();
  100570. new Matrix3$1();
  100571. new Matrix3$1();
  100572. new Matrix3$1();
  100573. new Vector3$1();
  100574. new Vector3$1();
  100575. new Vector3$1();
  100576. new Vector3$1();
  100577. new Vector3$1();
  100578. new Matrix3$1();
  100579. ({
  100580. diagonal: new Matrix3$1(),
  100581. unitary: new Matrix3$1()
  100582. });
  100583. const scratchVector$2 = new Vector3$1();
  100584. const scratchPosition = new Vector3$1();
  100585. const cullingVolume = new CullingVolume([new Plane$1(), new Plane$1(), new Plane$1(), new Plane$1(), new Plane$1(), new Plane$1()]);
  100586. function getFrameState(viewport, frameNumber) {
  100587. const {
  100588. cameraDirection,
  100589. cameraUp,
  100590. height
  100591. } = viewport;
  100592. const {
  100593. metersPerUnit
  100594. } = viewport.distanceScales;
  100595. const viewportCenterCartographic = viewport.unprojectPosition(viewport.center);
  100596. const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new Vector3$1());
  100597. const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
  100598. const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
  100599. const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3$1());
  100600. const cameraDirectionCartesian = new Vector3$1(enuToFixedTransform.transformAsVector(new Vector3$1(cameraDirection).scale(metersPerUnit))).normalize();
  100601. const cameraUpCartesian = new Vector3$1(enuToFixedTransform.transformAsVector(new Vector3$1(cameraUp).scale(metersPerUnit))).normalize();
  100602. commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);
  100603. return {
  100604. camera: {
  100605. position: cameraPositionCartesian,
  100606. direction: cameraDirectionCartesian,
  100607. up: cameraUpCartesian
  100608. },
  100609. viewport,
  100610. height,
  100611. cullingVolume,
  100612. frameNumber,
  100613. sseDenominator: 1.15
  100614. };
  100615. }
  100616. function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {
  100617. const frustumPlanes = viewport.getFrustumPlanes();
  100618. let i = 0;
  100619. for (const dir in frustumPlanes) {
  100620. const plane = frustumPlanes[dir];
  100621. const distanceToCenter = plane.normal.dot(viewport.center);
  100622. scratchPosition.copy(plane.normal).scale(plane.distance - distanceToCenter).add(viewport.center);
  100623. const cartographicPos = viewport.unprojectPosition(scratchPosition);
  100624. const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3$1());
  100625. cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector$2.copy(viewportCenterCartesian).subtract(cartesianPos));
  100626. }
  100627. }
  100628. const WGS84_RADIUS_X = 6378137.0;
  100629. const WGS84_RADIUS_Y = 6378137.0;
  100630. const WGS84_RADIUS_Z = 6356752.3142451793;
  100631. const scratchVector$1 = new Vector3$1();
  100632. function getZoomFromBoundingVolume(boundingVolume) {
  100633. const {
  100634. halfAxes,
  100635. radius,
  100636. width,
  100637. height
  100638. } = boundingVolume;
  100639. if (halfAxes) {
  100640. const obbSize = getObbSize(halfAxes);
  100641. return Math.log2(WGS84_RADIUS_Z / obbSize);
  100642. } else if (radius) {
  100643. return Math.log2(WGS84_RADIUS_Z / radius);
  100644. } else if (height && width) {
  100645. const zoomX = Math.log2(WGS84_RADIUS_X / width);
  100646. const zoomY = Math.log2(WGS84_RADIUS_Y / height);
  100647. return (zoomX + zoomY) / 2;
  100648. }
  100649. return 1;
  100650. }
  100651. function getObbSize(halfAxes) {
  100652. halfAxes.getColumn(0, scratchVector$1);
  100653. const axeY = halfAxes.getColumn(1);
  100654. const axeZ = halfAxes.getColumn(2);
  100655. const farthestVertex = scratchVector$1.add(axeY).add(axeZ);
  100656. const size = farthestVertex.len();
  100657. return size;
  100658. }
  100659. const TILE_CONTENT_STATE = {
  100660. UNLOADED: 0,
  100661. LOADING: 1,
  100662. PROCESSING: 2,
  100663. READY: 3,
  100664. EXPIRED: 4,
  100665. FAILED: 5
  100666. };
  100667. const TILE_REFINEMENT = {
  100668. ADD: 1,
  100669. REPLACE: 2
  100670. };
  100671. const TILE_TYPE = {
  100672. EMPTY: 'empty',
  100673. SCENEGRAPH: 'scenegraph',
  100674. POINTCLOUD: 'pointcloud',
  100675. MESH: 'mesh'
  100676. };
  100677. const TILESET_TYPE = {
  100678. I3S: 'I3S',
  100679. TILES3D: 'TILES3D'
  100680. };
  100681. const LOD_METRIC_TYPE = {
  100682. GEOMETRIC_ERROR: 'geometricError',
  100683. MAX_SCREEN_THRESHOLD: 'maxScreenThreshold'
  100684. };
  100685. const TILE3D_OPTIMIZATION_HINT = {
  100686. NOT_COMPUTED: -1,
  100687. USE_OPTIMIZATION: 1,
  100688. SKIP_OPTIMIZATION: 0
  100689. };
  100690. function defined$3(x) {
  100691. return x !== undefined && x !== null;
  100692. }
  100693. const scratchScale = new Vector3$1();
  100694. const scratchNorthWest = new Vector3$1();
  100695. const scratchSouthEast = new Vector3$1();
  100696. function createBoundingVolume(boundingVolumeHeader, transform, result) {
  100697. assert$7(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
  100698. if (boundingVolumeHeader.box) {
  100699. return createBox(boundingVolumeHeader.box, transform, result);
  100700. }
  100701. if (boundingVolumeHeader.region) {
  100702. const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
  100703. const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
  100704. const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
  100705. const centerInCartesian = new Vector3$1().addVectors(northWest, southEast).multiplyScalar(0.5);
  100706. const radius = new Vector3$1().subVectors(northWest, southEast).len() / 2.0;
  100707. return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new Matrix4$1());
  100708. }
  100709. if (boundingVolumeHeader.sphere) {
  100710. return createSphere(boundingVolumeHeader.sphere, transform, result);
  100711. }
  100712. throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
  100713. }
  100714. function createBox(box, transform, result) {
  100715. const center = new Vector3$1(box[0], box[1], box[2]);
  100716. result && (result.oriCenter = center);//add
  100717. transform.transform(center, center);
  100718. let origin = [];
  100719. if (box.length === 10) {
  100720. const halfSize = box.slice(3, 6);
  100721. const quaternion = new Quaternion$1();
  100722. quaternion.fromArray(box, 6);
  100723. const x = new Vector3$1([1, 0, 0]);
  100724. const y = new Vector3$1([0, 1, 0]);
  100725. const z = new Vector3$1([0, 0, 1]);
  100726. x.transformByQuaternion(quaternion);
  100727. x.scale(halfSize[0]);
  100728. y.transformByQuaternion(quaternion);
  100729. y.scale(halfSize[1]);
  100730. z.transformByQuaternion(quaternion);
  100731. z.scale(halfSize[2]);
  100732. origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
  100733. } else {
  100734. origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
  100735. }
  100736. const xAxis = transform.transformAsVector(origin.slice(0, 3));
  100737. const yAxis = transform.transformAsVector(origin.slice(3, 6));
  100738. const zAxis = transform.transformAsVector(origin.slice(6, 9));
  100739. const halfAxes = new Matrix3$1([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]);
  100740. //const halfAxes = new Matrix3([xAxis[0], xAxis[1], -xAxis[2], yAxis[0], yAxis[1], -yAxis[2], zAxis[0], zAxis[1], -zAxis[2]]);//改
  100741. //center.z *= -1//add
  100742. if (defined$3(result)) {
  100743. result.center = center;
  100744. result.halfAxes = halfAxes;
  100745. return result;
  100746. }
  100747. return new OrientedBoundingBox(center, halfAxes);
  100748. }
  100749. function createSphere(sphere, transform, result) {
  100750. const center = new Vector3$1(sphere[0], sphere[1], sphere[2]);
  100751. transform.transform(center, center);
  100752. const scale = transform.getScale(scratchScale);
  100753. const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
  100754. const radius = sphere[3] * uniformScale;
  100755. if (defined$3(result)) {
  100756. result.center = center;
  100757. result.radius = radius;
  100758. return result;
  100759. }
  100760. return new BoundingSphere(center, radius);
  100761. }
  100762. new Vector3$1();
  100763. new Vector3$1();
  100764. new Matrix4$1();
  100765. new Vector3$1();
  100766. new Vector3$1();
  100767. new Vector3$1();
  100768. function fog(distanceToCamera, density) {
  100769. const scalar = distanceToCamera * density;
  100770. return 1.0 - Math.exp(-(scalar * scalar));
  100771. }
  100772. function getDynamicScreenSpaceError(tileset, distanceToCamera) {
  100773. if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
  100774. const density = tileset.dynamicScreenSpaceErrorComputedDensity;
  100775. const factor = tileset.dynamicScreenSpaceErrorFactor;
  100776. const dynamicError = fog(distanceToCamera, density) * factor;
  100777. return dynamicError;
  100778. }
  100779. return 0;
  100780. }
  100781. function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
  100782. const tileset = tile.tileset;
  100783. const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
  100784. const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
  100785. if (lodMetricValue === 0.0) {
  100786. return 0.0;
  100787. }
  100788. const distance = Math.max(tile._distanceToCamera, 1e-7);
  100789. const {
  100790. height,
  100791. sseDenominator
  100792. } = frameState;
  100793. const {
  100794. viewDistanceScale
  100795. } = tileset.options;
  100796. let error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
  100797. error -= getDynamicScreenSpaceError(tileset, distance);
  100798. return error;
  100799. }
  100800. function getLodStatus(tile, frameState) {
  100801. if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
  100802. return 'DIG';
  100803. }
  100804. const screenSize = 2 * getProjectedRadius(tile, frameState);
  100805. if (screenSize < 2) {
  100806. return 'OUT';
  100807. }
  100808. if (!tile.header.children || screenSize <= tile.lodMetricValue) {
  100809. return 'DRAW';
  100810. } else if (tile.header.children) {
  100811. return 'DIG';
  100812. }
  100813. return 'OUT';
  100814. }
  100815. function getProjectedRadius(tile, frameState) {
  100816. const originalViewport = frameState.viewport;
  100817. const ViewportClass = originalViewport.constructor;
  100818. const {
  100819. longitude,
  100820. latitude,
  100821. height,
  100822. width,
  100823. bearing,
  100824. zoom
  100825. } = originalViewport;
  100826. const viewport = new ViewportClass({
  100827. longitude,
  100828. latitude,
  100829. height,
  100830. width,
  100831. bearing,
  100832. zoom,
  100833. pitch: 0
  100834. });
  100835. const mbsLat = tile.header.mbs[1];
  100836. const mbsLon = tile.header.mbs[0];
  100837. const mbsZ = tile.header.mbs[2];
  100838. const mbsR = tile.header.mbs[3];
  100839. const mbsCenterCartesian = [...tile.boundingVolume.center];
  100840. const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
  100841. const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3$1());
  100842. const toEye = new Vector3$1(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
  100843. const enuToCartesianMatrix = new Matrix4$1();
  100844. Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
  100845. const cartesianToEnuMatrix = new Matrix4$1(enuToCartesianMatrix).invert();
  100846. const cameraPositionEnu = new Vector3$1(cameraPositionCartesian).transform(cartesianToEnuMatrix);
  100847. const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
  100848. const extraZ = projection * projection / cameraPositionEnu[2];
  100849. const extraVertexEnu = new Vector3$1([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
  100850. const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
  100851. const extraVectorCartesian = new Vector3$1(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();
  100852. const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
  100853. const sphereMbsBorderVertexCartesian = new Vector3$1(mbsCenterCartesian).add(radiusVector);
  100854. const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
  100855. const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
  100856. const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
  100857. const projectedRadius = new Vector3$1(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
  100858. return projectedRadius;
  100859. }
  100860. function get3dTilesOptions(tileset) {
  100861. return {
  100862. assetGltfUpAxis: tileset.asset && tileset.asset.gltfUpAxis || 'Y'
  100863. };
  100864. }
  100865. class ManagedArray {
  100866. constructor(length = 0) {
  100867. _defineProperty(this, "_map", new Map());
  100868. _defineProperty(this, "_array", void 0);
  100869. _defineProperty(this, "_length", void 0);
  100870. this._array = new Array(length);
  100871. this._length = length;
  100872. }
  100873. get length() {
  100874. return this._length;
  100875. }
  100876. set length(length) {
  100877. this._length = length;
  100878. if (length > this._array.length) {
  100879. this._array.length = length;
  100880. }
  100881. }
  100882. get values() {
  100883. return this._array;
  100884. }
  100885. get(index) {
  100886. assert$7(index < this._array.length);
  100887. return this._array[index];
  100888. }
  100889. set(index, element) {
  100890. assert$7(index >= 0);
  100891. if (index >= this.length) {
  100892. this.length = index + 1;
  100893. }
  100894. if (this._map.has(this._array[index])) {
  100895. this._map.delete(this._array[index]);
  100896. }
  100897. this._array[index] = element;
  100898. this._map.set(element, index);
  100899. }
  100900. delete(element) {
  100901. const index = this._map.get(element);
  100902. if (index >= 0) {
  100903. this._array.splice(index, 1);
  100904. this._map.delete(element);
  100905. this.length--;
  100906. }
  100907. }
  100908. peek() {
  100909. return this._array[this._length - 1];
  100910. }
  100911. push(element) {
  100912. if (!this._map.has(element)) {
  100913. const index = this.length++;
  100914. this._array[index] = element;
  100915. this._map.set(element, index);
  100916. }
  100917. }
  100918. pop() {
  100919. const element = this._array[--this.length];
  100920. this._map.delete(element);
  100921. return element;
  100922. }
  100923. reserve(length) {
  100924. assert$7(length >= 0);
  100925. if (length > this._array.length) {
  100926. this._array.length = length;
  100927. }
  100928. }
  100929. resize(length) {
  100930. assert$7(length >= 0);
  100931. this.length = length;
  100932. }
  100933. trim(length) {
  100934. if (length === null || length === undefined) {
  100935. length = this.length;
  100936. }
  100937. this._array.length = length;
  100938. }
  100939. reset() {
  100940. this._array = [];
  100941. this._map = new Map();
  100942. this._length = 0;
  100943. }
  100944. find(target) {
  100945. return this._map.has(target);
  100946. }
  100947. }
  100948. const DEFAULT_PROPS$1 = {
  100949. loadSiblings: false,
  100950. skipLevelOfDetail: false,
  100951. maximumScreenSpaceError: 2,
  100952. updateTransforms: true,
  100953. onTraversalEnd: () => {},
  100954. viewportTraversersMap: {},
  100955. basePath: ''
  100956. };
  100957. class TilesetTraverser {
  100958. constructor(options) {
  100959. _defineProperty(this, "options", void 0);
  100960. _defineProperty(this, "root", void 0);
  100961. _defineProperty(this, "requestedTiles", void 0);
  100962. _defineProperty(this, "selectedTiles", void 0);
  100963. _defineProperty(this, "emptyTiles", void 0);
  100964. _defineProperty(this, "_traversalStack", void 0);
  100965. _defineProperty(this, "_emptyTraversalStack", void 0);
  100966. _defineProperty(this, "_frameNumber", void 0);
  100967. this.options = { ...DEFAULT_PROPS$1,
  100968. ...options
  100969. };
  100970. this._traversalStack = new ManagedArray();
  100971. this._emptyTraversalStack = new ManagedArray();
  100972. this._frameNumber = null;
  100973. this.root = null;
  100974. this.selectedTiles = {};
  100975. this.requestedTiles = {};
  100976. this.emptyTiles = {};
  100977. }
  100978. traverse(root, frameState, options) {
  100979. this.root = root;
  100980. this.options = { ...this.options,
  100981. ...options
  100982. };
  100983. this.reset();
  100984. this.updateTile(root, frameState);
  100985. this._frameNumber = frameState.frameNumber;
  100986. this.executeTraversal(root, frameState);
  100987. }
  100988. reset() {
  100989. this.requestedTiles = {};
  100990. this.selectedTiles = {};
  100991. this.emptyTiles = {};
  100992. this._traversalStack.reset();
  100993. this._emptyTraversalStack.reset();
  100994. }
  100995. executeTraversal(root, frameState) {// 遍历root
  100996. const stack = this._traversalStack;
  100997. root._selectionDepth = 1;
  100998. stack.push(root);
  100999. while (stack.length > 0) {
  101000. const tile = stack.pop();
  101001. let shouldRefine = false;
  101002. // !zeg改 循环遍历子tile, maxDepth用来限制可加载的最大深度
  101003. if (this.canTraverse(tile, frameState) && (tile.depth < /* this.options. */maxDepth || tile.type != 'scenegraph' )) {//add maxDepth 是否继续遍历子集
  101004. this.updateChildTiles(tile, frameState);
  101005. shouldRefine = this.updateAndPushChildren(tile, frameState, stack, tile.hasRenderContent ? tile._selectionDepth + 1 : tile._selectionDepth);
  101006. }
  101007. const parent = tile.parent;
  101008. const parentRefines = Boolean(!parent || parent._shouldRefine);
  101009. const stoppedRefining = !shouldRefine;
  101010. if (!tile.hasRenderContent) {
  101011. this.emptyTiles[tile.id] = tile;
  101012. this.loadTile(tile, frameState);
  101013. if (stoppedRefining) {
  101014. this.selectTile(tile, frameState);
  101015. }
  101016. } else if (tile.refine === TILE_REFINEMENT.ADD) {
  101017. this.loadTile(tile, frameState);
  101018. this.selectTile(tile, frameState);
  101019. } else if (tile.refine === TILE_REFINEMENT.REPLACE) {
  101020. this.loadTile(tile, frameState);
  101021. if (stoppedRefining) {
  101022. this.selectTile(tile, frameState);
  101023. }
  101024. }
  101025. this.touchTile(tile, frameState);
  101026. tile._shouldRefine = shouldRefine && parentRefines;
  101027. }
  101028. this.options.onTraversalEnd(frameState);
  101029. }
  101030. updateChildTiles(tile, frameState) {
  101031. const children = tile.children;
  101032. for (const child of children) {
  101033. this.updateTile(child, frameState);
  101034. }
  101035. return true;
  101036. }
  101037. updateAndPushChildren(tile, frameState, stack, depth) {
  101038. const {
  101039. loadSiblings,
  101040. skipLevelOfDetail
  101041. } = this.options;
  101042. const children = tile.children;
  101043. children.sort(this.compareDistanceToCamera.bind(this));
  101044. const checkRefines = tile.refine === TILE_REFINEMENT.REPLACE && tile.hasRenderContent && !skipLevelOfDetail;
  101045. let hasVisibleChild = false;
  101046. let refines = true;
  101047. for (const child of children) {
  101048. child._selectionDepth = depth;
  101049. if (child.isVisibleAndInRequestVolume) {
  101050. if (stack.find(child)) {
  101051. stack.delete(child);
  101052. }
  101053. stack.push(child);
  101054. hasVisibleChild = true;
  101055. } else if (checkRefines || loadSiblings) {
  101056. this.loadTile(child, frameState);
  101057. this.touchTile(child, frameState);
  101058. }
  101059. if (checkRefines) {
  101060. let childRefines;
  101061. if (!child._inRequestVolume) {
  101062. childRefines = false;
  101063. } else if (!child.hasRenderContent) {
  101064. childRefines = this.executeEmptyTraversal(child, frameState);
  101065. } else {
  101066. childRefines = child.contentAvailable;
  101067. }
  101068. refines = refines && childRefines;
  101069. if (!refines) {
  101070. return false;
  101071. }
  101072. }
  101073. }
  101074. if (!hasVisibleChild) {
  101075. refines = false;
  101076. }
  101077. return refines;
  101078. }
  101079. updateTile(tile, frameState) {
  101080. this.updateTileVisibility(tile, frameState);
  101081. }
  101082. selectTile(tile, frameState) {
  101083. if (this.shouldSelectTile(tile)) {
  101084. tile._selectedFrame = frameState.frameNumber;
  101085. this.selectedTiles[tile.id] = tile;
  101086. }
  101087. }
  101088. loadTile(tile, frameState) {
  101089. if (this.shouldLoadTile(tile)) {
  101090. tile._requestedFrame = frameState.frameNumber;
  101091. tile._priority = tile._getPriority();
  101092. this.requestedTiles[tile.id] = tile;
  101093. }
  101094. }
  101095. touchTile(tile, frameState) {
  101096. tile.tileset._cache.touch(tile);
  101097. tile._touchedFrame = frameState.frameNumber;
  101098. }
  101099. canTraverse(tile, frameState, useParentMetric = false, ignoreVisibility = false) {
  101100. if (!tile.hasChildren) {
  101101. return false;
  101102. }
  101103. if (tile.hasTilesetContent) {
  101104. return !tile.contentExpired;
  101105. }
  101106. if (!ignoreVisibility && !tile.isVisibleAndInRequestVolume) {
  101107. return false;
  101108. }
  101109. return this.shouldRefine(tile, frameState, useParentMetric);
  101110. }
  101111. shouldLoadTile(tile) {
  101112. return tile.hasUnloadedContent || tile.contentExpired;
  101113. }
  101114. shouldSelectTile(tile) {
  101115. return tile.contentAvailable && !this.options.skipLevelOfDetail;
  101116. }
  101117. shouldRefine(tile, frameState, useParentMetric) {
  101118. let screenSpaceError = tile._screenSpaceError;
  101119. if (useParentMetric) {
  101120. screenSpaceError = tile.getScreenSpaceError(frameState, true);
  101121. }
  101122. return screenSpaceError > this.options.maximumScreenSpaceError;
  101123. }
  101124. updateTileVisibility(tile, frameState) {
  101125. const viewportIds = [];
  101126. if (this.options.viewportTraversersMap) {
  101127. for (const key in this.options.viewportTraversersMap) {
  101128. const value = this.options.viewportTraversersMap[key];
  101129. if (value === frameState.viewport.id) {
  101130. viewportIds.push(key);
  101131. }
  101132. }
  101133. } else {
  101134. viewportIds.push(frameState.viewport.id);
  101135. }
  101136. tile.updateVisibility(frameState, viewportIds);
  101137. }
  101138. compareDistanceToCamera(b, a) {
  101139. return b._distanceToCamera - a._distanceToCamera;
  101140. }
  101141. anyChildrenVisible(tile, frameState) {
  101142. let anyVisible = false;
  101143. for (const child of tile.children) {
  101144. child.updateVisibility(frameState);
  101145. anyVisible = anyVisible || child.isVisibleAndInRequestVolume;
  101146. }
  101147. return anyVisible;
  101148. }
  101149. executeEmptyTraversal(root, frameState) {
  101150. let allDescendantsLoaded = true;
  101151. const stack = this._emptyTraversalStack;
  101152. stack.push(root);
  101153. while (stack.length > 0 && allDescendantsLoaded) {
  101154. const tile = stack.pop();
  101155. this.updateTile(tile, frameState);
  101156. if (!tile.isVisibleAndInRequestVolume) {
  101157. this.loadTile(tile, frameState);
  101158. }
  101159. this.touchTile(tile, frameState);
  101160. const traverse = !tile.hasRenderContent && this.canTraverse(tile, frameState, false, true);
  101161. if (traverse) {
  101162. const children = tile.children;
  101163. for (const child of children) {
  101164. if (stack.find(child)) {
  101165. stack.delete(child);
  101166. }
  101167. stack.push(child);
  101168. }
  101169. } else if (!tile.contentAvailable) {
  101170. allDescendantsLoaded = false;
  101171. }
  101172. }
  101173. return allDescendantsLoaded;
  101174. }
  101175. }
  101176. const scratchVector = new Vector3$1();
  101177. function defined$2(x) {
  101178. return x !== undefined && x !== null;
  101179. }
  101180. class TileHeader {
  101181. constructor(tileset, header, parentHeader, extendedId = '') {
  101182. _defineProperty(this, "tileset", void 0);
  101183. _defineProperty(this, "header", void 0);
  101184. _defineProperty(this, "id", void 0);
  101185. _defineProperty(this, "url", void 0);
  101186. _defineProperty(this, "parent", void 0);
  101187. _defineProperty(this, "refine", void 0);
  101188. _defineProperty(this, "type", void 0);
  101189. _defineProperty(this, "contentUrl", void 0);
  101190. _defineProperty(this, "lodMetricType", void 0);
  101191. _defineProperty(this, "lodMetricValue", void 0);
  101192. _defineProperty(this, "boundingVolume", void 0);
  101193. _defineProperty(this, "content", void 0);
  101194. _defineProperty(this, "contentState", void 0);
  101195. _defineProperty(this, "gpuMemoryUsageInBytes", void 0);
  101196. _defineProperty(this, "children", void 0);
  101197. _defineProperty(this, "depth", void 0);
  101198. _defineProperty(this, "viewportIds", void 0);
  101199. _defineProperty(this, "transform", void 0);
  101200. _defineProperty(this, "extensions", void 0);
  101201. _defineProperty(this, "userData", void 0);
  101202. _defineProperty(this, "computedTransform", void 0);
  101203. _defineProperty(this, "hasEmptyContent", void 0);
  101204. _defineProperty(this, "hasTilesetContent", void 0);
  101205. _defineProperty(this, "traverser", void 0);
  101206. _defineProperty(this, "_cacheNode", void 0);
  101207. _defineProperty(this, "_frameNumber", void 0);
  101208. _defineProperty(this, "_lodJudge", void 0);
  101209. _defineProperty(this, "_expireDate", void 0);
  101210. _defineProperty(this, "_expiredContent", void 0);
  101211. _defineProperty(this, "_shouldRefine", void 0);
  101212. _defineProperty(this, "_distanceToCamera", void 0);
  101213. _defineProperty(this, "_centerZDepth", void 0);
  101214. _defineProperty(this, "_screenSpaceError", void 0);
  101215. _defineProperty(this, "_visibilityPlaneMask", void 0);
  101216. _defineProperty(this, "_visible", void 0);
  101217. _defineProperty(this, "_inRequestVolume", void 0);
  101218. _defineProperty(this, "_stackLength", void 0);
  101219. _defineProperty(this, "_selectionDepth", void 0);
  101220. _defineProperty(this, "_touchedFrame", void 0);
  101221. _defineProperty(this, "_visitedFrame", void 0);
  101222. _defineProperty(this, "_selectedFrame", void 0);
  101223. _defineProperty(this, "_requestedFrame", void 0);
  101224. _defineProperty(this, "_priority", void 0);
  101225. _defineProperty(this, "_contentBoundingVolume", void 0);
  101226. _defineProperty(this, "_viewerRequestVolume", void 0);
  101227. _defineProperty(this, "_initialTransform", void 0);
  101228. _defineProperty(this, "tilesetMatrix", void 0);//add
  101229. _defineProperty(this, "tileContent", void 0);//add
  101230. _defineProperty(this, "contentTransform", void 0);//add
  101231. _defineProperty(this, "volumeBox", void 0);//add
  101232. _defineProperty(this, "boundUntransformed", void 0);//add
  101233. _defineProperty(this, "rtcCenterState", rtcCenterGlobal);//add 初始时的状态,当mesh加载完检查下
  101234. this.header = header;
  101235. this.tileset = tileset;
  101236. this.id = extendedId || header.id;
  101237. this.url = header.url;
  101238. this.parent = parentHeader;
  101239. this.refine = this._getRefine(header.refine);
  101240. this.type = header.type;
  101241. this.contentUrl = header.contentUrl;
  101242. this.lodMetricType = 'geometricError';
  101243. this.lodMetricValue = 0;
  101244. this.boundingVolume = null;
  101245. this.content = null;
  101246. this.contentState = TILE_CONTENT_STATE.UNLOADED;
  101247. this.gpuMemoryUsageInBytes = 0;
  101248. this.children = [];
  101249. this.hasEmptyContent = false;
  101250. this.hasTilesetContent = false;
  101251. this.depth = 0;
  101252. this.viewportIds = [];
  101253. this.userData = {};
  101254. this.extensions = null;
  101255. this._priority = 0;
  101256. this._touchedFrame = 0;
  101257. this._visitedFrame = 0;
  101258. this._selectedFrame = 0;
  101259. this._requestedFrame = 0;
  101260. this._screenSpaceError = 0;
  101261. this._cacheNode = null;
  101262. this._frameNumber = null;
  101263. this._cacheNode = null;
  101264. this.traverser = new TilesetTraverser({});
  101265. this._shouldRefine = false;
  101266. this._distanceToCamera = 0;
  101267. this._centerZDepth = 0;
  101268. this._visible = undefined;
  101269. this._inRequestVolume = false;
  101270. this._stackLength = 0;
  101271. this._selectionDepth = 0;
  101272. this._initialTransform = new Matrix4$1();
  101273. this.transform = new Matrix4$1();
  101274. this._initializeLodMetric(header);
  101275. this._initializeTransforms(header);
  101276. this._initializeBoundingVolumes(header);
  101277. this._initializeContent(header);
  101278. this._initializeRenderingState(header);
  101279. this._lodJudge = null;
  101280. this._expireDate = null;
  101281. this._expiredContent = null;
  101282. Object.seal(this);
  101283. }
  101284. destroy() {
  101285. this.header = null;
  101286. }
  101287. isDestroyed() {
  101288. return this.header === null;
  101289. }
  101290. get selected() {
  101291. return this._selectedFrame === this.tileset._frameNumber;
  101292. }
  101293. get isVisible() {
  101294. return this._visible;
  101295. }
  101296. get isVisibleAndInRequestVolume() {
  101297. let v = /* this._visible && */this.tileset.visible && this._inRequestVolume; //用_updateBoundingVolume这个算的在相机靠近时不准确,容易缺块
  101298. if(window.tileVisi2)v = this._visible && v;
  101299. return v
  101300. }
  101301. get hasRenderContent() {
  101302. return !this.hasEmptyContent && !this.hasTilesetContent;
  101303. }
  101304. get hasChildren() {
  101305. return this.children.length > 0 || this.header.children && this.header.children.length > 0;
  101306. }
  101307. get contentReady() {
  101308. return this.contentState === TILE_CONTENT_STATE.READY || this.hasEmptyContent;
  101309. }
  101310. get contentAvailable() {
  101311. return Boolean(this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed);
  101312. }
  101313. get hasUnloadedContent() {
  101314. return this.hasRenderContent && this.contentUnloaded;
  101315. }
  101316. get contentUnloaded() {
  101317. return this.contentState === TILE_CONTENT_STATE.UNLOADED;
  101318. }
  101319. get contentExpired() {
  101320. return this.contentState === TILE_CONTENT_STATE.EXPIRED;
  101321. }
  101322. get contentFailed() {
  101323. return this.contentState === TILE_CONTENT_STATE.FAILED;
  101324. }
  101325. getScreenSpaceError(frameState, useParentLodMetric) {
  101326. switch (this.tileset.type) {
  101327. case TILESET_TYPE.I3S:
  101328. return getProjectedRadius(this, frameState);
  101329. case TILESET_TYPE.TILES3D:
  101330. return getTiles3DScreenSpaceError(this, frameState, useParentLodMetric);
  101331. default:
  101332. throw new Error('Unsupported tileset type');
  101333. }
  101334. }
  101335. _getPriority() {
  101336. const traverser = this.tileset._traverser;
  101337. const {
  101338. skipLevelOfDetail
  101339. } = traverser.options;
  101340. const maySkipTile = this.refine === TILE_REFINEMENT.ADD || skipLevelOfDetail;
  101341. if (maySkipTile && !this.isVisible && this._visible !== undefined) {
  101342. return -1;
  101343. }
  101344. if (this.tileset._frameNumber - this._touchedFrame >= 1) {
  101345. return -1;
  101346. }
  101347. if (this.contentState === TILE_CONTENT_STATE.UNLOADED) {
  101348. return -1;
  101349. }
  101350. const parent = this.parent;
  101351. const useParentScreenSpaceError = parent && (!maySkipTile || this._screenSpaceError === 0.0 || parent.hasTilesetContent);
  101352. const screenSpaceError = useParentScreenSpaceError ? parent._screenSpaceError : this._screenSpaceError;
  101353. const rootScreenSpaceError = traverser.root ? traverser.root._screenSpaceError : 0.0;
  101354. let v = Math.max(rootScreenSpaceError - screenSpaceError, 0);
  101355. if(!this._visible){
  101356. v = THREE.Math.clamp(v * 0.1, -0.9, 100);//xzw add 因为this._visible我也令其显示所以这里降低这些的优先级
  101357. }
  101358. return v
  101359. }
  101360. async loadContent() {
  101361. if (this.hasEmptyContent) {
  101362. return false;
  101363. }
  101364. if (this.content) {
  101365. return true;
  101366. }
  101367. const expired = this.contentExpired;
  101368. if (expired) {
  101369. this._expireDate = null;
  101370. }
  101371. this.contentState = TILE_CONTENT_STATE.LOADING;
  101372. const requestToken = await this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority.bind(this));
  101373. if (!requestToken) {
  101374. this.contentState = TILE_CONTENT_STATE.UNLOADED;
  101375. return false;
  101376. }
  101377. try {
  101378. const contentUrl = this.tileset.getTileUrl(this.contentUrl)+ `?_=${this.tileset.options.updateTime}`; // !zeg改 添加version后缀 原:imageVersion
  101379. const loader = this.tileset.loader;
  101380. const options = { ...this.tileset.loadOptions,
  101381. [loader.id]: { ...this.tileset.loadOptions[loader.id],
  101382. isTileset: this.type === 'json',
  101383. ...this._getLoaderSpecificOptions(loader.id)
  101384. }
  101385. };
  101386. this.content = await load(contentUrl, loader, options);
  101387. // !zeg改
  101388. if (/* this.tileset.options. */maxDepth < this.depth && this.type == 'scenegraph') {//有的场景depth为1的不是mesh,只是json,即实际最低depth>1
  101389. this.unloadContent();
  101390. return false
  101391. }
  101392. if (this.tileset.options.contentLoader) {
  101393. await this.tileset.options.contentLoader(this);
  101394. }
  101395. if (this._isTileset()) {
  101396. this.tileset._initializeTileHeaders(this.content, this);
  101397. }
  101398. this.contentState = TILE_CONTENT_STATE.READY;
  101399. this._onContentLoaded();
  101400. return true;
  101401. } catch (error) {
  101402. this.contentState = TILE_CONTENT_STATE.FAILED;
  101403. throw error;
  101404. } finally {
  101405. requestToken.done();
  101406. }
  101407. }
  101408. unloadContent() {
  101409. if (this.content && this.content.destroy) {
  101410. this.content.destroy();
  101411. }
  101412. this.content = null;
  101413. if (this.header.content && this.header.content.destroy) {
  101414. this.header.content.destroy();
  101415. }
  101416. this.header.content = null;
  101417. this.contentState = TILE_CONTENT_STATE.UNLOADED;
  101418. return true;
  101419. }
  101420. updateVisibility(frameState, viewportIds) {
  101421. if (this._frameNumber === frameState.frameNumber) {
  101422. return;
  101423. }
  101424. const parent = this.parent;
  101425. const parentVisibilityPlaneMask = parent ? parent._visibilityPlaneMask : CullingVolume.MASK_INDETERMINATE;
  101426. if (this.tileset._traverser.options.updateTransforms) {
  101427. const parentTransform = parent ? parent.computedTransform : new Matrix4$1().elements; //this.tileset.modelMatrix; 改:去掉左乘modelMatrix
  101428. this._updateTransform(parentTransform);
  101429. }
  101430. this._distanceToCamera = this.distanceToTile(frameState);
  101431. this._screenSpaceError = this.getScreenSpaceError(frameState, false);
  101432. this._visibilityPlaneMask = this.visibility(frameState, parentVisibilityPlaneMask);
  101433. this._visible = this._visibilityPlaneMask !== CullingVolume.MASK_OUTSIDE;
  101434. this._inRequestVolume = this.insideViewerRequestVolume(frameState);
  101435. this._frameNumber = frameState.frameNumber;
  101436. this.viewportIds = viewportIds;
  101437. }
  101438. visibility(frameState, parentVisibilityPlaneMask) {
  101439. const {
  101440. cullingVolume
  101441. } = frameState;
  101442. const {
  101443. boundingVolume
  101444. } = this;
  101445. return cullingVolume.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask);
  101446. }
  101447. contentVisibility() {
  101448. return true;
  101449. }
  101450. distanceToTile(frameState) {
  101451. const boundingVolume = this.boundingVolume;
  101452. return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0));
  101453. }
  101454. cameraSpaceZDepth({
  101455. camera
  101456. }) {
  101457. const boundingVolume = this.boundingVolume;
  101458. scratchVector.subVectors(boundingVolume.center, camera.position);
  101459. return camera.direction.dot(scratchVector);
  101460. }
  101461. insideViewerRequestVolume(frameState) {
  101462. const viewerRequestVolume = this._viewerRequestVolume;
  101463. return !viewerRequestVolume || viewerRequestVolume.distanceSquaredTo(frameState.camera.position) <= 0;
  101464. }
  101465. updateExpiration() {
  101466. if (defined$2(this._expireDate) && this.contentReady && !this.hasEmptyContent) {
  101467. const now = Date.now();
  101468. if (Date.lessThan(this._expireDate, now)) {
  101469. this.contentState = TILE_CONTENT_STATE.EXPIRED;
  101470. this._expiredContent = this.content;
  101471. }
  101472. }
  101473. }
  101474. get extras() {
  101475. return this.header.extras;
  101476. }
  101477. _initializeLodMetric(header) {
  101478. if ('lodMetricType' in header) {
  101479. this.lodMetricType = header.lodMetricType;
  101480. } else {
  101481. this.lodMetricType = this.parent && this.parent.lodMetricType || this.tileset.lodMetricType;
  101482. console.warn("3D Tile: Required prop lodMetricType is undefined. Using parent lodMetricType");
  101483. }
  101484. if ('lodMetricValue' in header) {
  101485. this.lodMetricValue = header.lodMetricValue;
  101486. } else {
  101487. this.lodMetricValue = this.parent && this.parent.lodMetricValue || this.tileset.lodMetricValue;
  101488. console.warn('3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue');
  101489. }
  101490. }
  101491. _initializeTransforms(tileHeader) {
  101492. this.transform = tileHeader.transform ? new Matrix4$1(tileHeader.transform) : new Matrix4$1();
  101493. const parent = this.parent;
  101494. const tileset = this.tileset;
  101495. const parentTransform = parent && parent.computedTransform ? parent.computedTransform.clone() : new Matrix4$1().elements; // tileset.modelMatrix.clone(); 改:去掉左乘modelMatrix
  101496. this.computedTransform = new Matrix4$1(parentTransform).multiplyRight(this.transform);
  101497. const parentInitialTransform = parent && parent._initialTransform ? parent._initialTransform.clone() : new Matrix4$1();
  101498. this._initialTransform = new Matrix4$1(parentInitialTransform).multiplyRight(this.transform);
  101499. }
  101500. _initializeBoundingVolumes(tileHeader) {
  101501. this._contentBoundingVolume = null;
  101502. this._viewerRequestVolume = null;
  101503. this._updateBoundingVolume(tileHeader);
  101504. }
  101505. _initializeContent(tileHeader) {
  101506. this.content = {
  101507. _tileset: this.tileset,
  101508. _tile: this
  101509. };
  101510. this.hasEmptyContent = true;
  101511. this.contentState = TILE_CONTENT_STATE.UNLOADED;
  101512. this.hasTilesetContent = false;
  101513. if (tileHeader.contentUrl) {
  101514. this.content = null;
  101515. this.hasEmptyContent = false;
  101516. }
  101517. }
  101518. _initializeRenderingState(header) {
  101519. this.depth = header.level || (this.parent ? this.parent.depth + 1 : 0);
  101520. this._shouldRefine = false;
  101521. this._distanceToCamera = 0;
  101522. this._centerZDepth = 0;
  101523. this._screenSpaceError = 0;
  101524. this._visibilityPlaneMask = CullingVolume.MASK_INDETERMINATE;
  101525. this._visible = undefined;
  101526. this._inRequestVolume = false;
  101527. this._stackLength = 0;
  101528. this._selectionDepth = 0;
  101529. this._frameNumber = 0;
  101530. this._touchedFrame = 0;
  101531. this._visitedFrame = 0;
  101532. this._selectedFrame = 0;
  101533. this._requestedFrame = 0;
  101534. this._priority = 0.0;
  101535. }
  101536. _getRefine(refine) {
  101537. return refine || this.parent && this.parent.refine || TILE_REFINEMENT.REPLACE;
  101538. }
  101539. _isTileset() {
  101540. return this.contentUrl.indexOf('.json') !== -1;
  101541. }
  101542. _onContentLoaded() {
  101543. switch (this.content && this.content.type) {
  101544. case 'vctr':
  101545. case 'geom':
  101546. this.tileset._traverser.disableSkipLevelOfDetail = true;
  101547. break;
  101548. }
  101549. if (this._isTileset()) {
  101550. this.hasTilesetContent = true;
  101551. }
  101552. }
  101553. _updateBoundingVolume(header) {
  101554. let computedTransform;
  101555. if(header.id == 'root_0' || !header.id){
  101556. console.log('root_0');
  101557. }
  101558. if(!this.tileset.lastRootTransform){//没事过后会因_updateTransform重算
  101559. computedTransform = new Matrix4$1(this.tileset.modelMatrix).multiplyRight(this.computedTransform); //add
  101560. }else {
  101561. computedTransform = new Matrix4$1(new Matrix4().multiplyMatrices(this.tileset.lastRootTransform, this.getContentTransform()).elements);
  101562. }
  101563. this.boundingVolume = createBoundingVolume(header.boundingVolume, computedTransform/* this.computedTransform */, this.boundingVolume);
  101564. const content = header.content;
  101565. if (!content) {
  101566. return;
  101567. }
  101568. if (content.boundingVolume) {
  101569. this._contentBoundingVolume = createBoundingVolume(content.boundingVolume, computedTransform, this._contentBoundingVolume);
  101570. }
  101571. if (header.viewerRequestVolume) {
  101572. this._viewerRequestVolume = createBoundingVolume(header.viewerRequestVolume, computedTransform, this._viewerRequestVolume);
  101573. }
  101574. }
  101575. getBoundUntransformed(){//add 这个会在mesh加载好后才会执行
  101576. if(!this.contentTransform){
  101577. console.error('?');
  101578. }
  101579. this.getContentTransform();
  101580. let computedTransform2 = new Matrix4$1(this.contentTransform.elements);
  101581. this.boundUntransformed = createBoundingVolume(this.header.boundingVolume, computedTransform2 , this.boundUntransformed);//add
  101582. return this.boundUntransformed
  101583. }
  101584. getContentTransform(force){ //add 获取该tile在创建boundingVolume时需要的matrix,不包含最外层对整体模型的变换.
  101585. let rtcCenter, contentTransform;
  101586. if(this.contentTransform && !force){//无需更新
  101587. return this.contentTransform.clone()
  101588. }
  101589. if(!this.tileset.tileTransInvert){
  101590. this.tileset.tileTransInvert = new Matrix4$1();
  101591. }
  101592. this.contentTransform = new Matrix4().fromArray(this.computedTransform).premultiply(new Matrix4().fromArray(this.tileset.tileTransInvert));
  101593. if(this.tileContent){
  101594. rtcCenter = this.content.rtcCenter;
  101595. }else {
  101596. rtcCenter = this.rtcCenterState;
  101597. }
  101598. if(!rtcCenter) {
  101599. let tranM = new Matrix4();
  101600. tranM.makeScale(1,1,-1);//大部分是这种情况. 就是因为这个变换才加的这个函数,之前bounding没考虑这个不准。不知道为什么原生的代码不用scaleZ
  101601. this.contentTransform.premultiply(tranM);
  101602. }
  101603. //如果有rtcCenter的话一开始boundingVolume不准?会不会有显示问题?
  101604. return this.contentTransform.clone()
  101605. }
  101606. _updateTransform(parentTransform = new Matrix4$1()) {
  101607. const computedTransform = parentTransform.clone().multiplyRight(this.transform);
  101608. const didTransformChange = !computedTransform.equals(this.computedTransform) || !this.tilesetMatrix || !this.tilesetMatrix.equals(this.tileset.modelMatrix); //改 后面加了两个判断,为了在模型移动后更新_updateBoundingVolume
  101609. if (!didTransformChange) {
  101610. return;
  101611. }
  101612. this.tileset.modelMatrix;
  101613. this.computedTransform = computedTransform;
  101614. this.tilesetMatrix = this.tileset.modelMatrix; //add 标记
  101615. this._updateBoundingVolume(this.header);
  101616. }
  101617. _getLoaderSpecificOptions(loaderId) {
  101618. switch (loaderId) {
  101619. case 'i3s':
  101620. return { ...this.tileset.options.i3s,
  101621. tile: this.header,
  101622. tileset: this.tileset.tileset,
  101623. isTileHeader: false
  101624. };
  101625. case '3d-tiles':
  101626. case 'cesium-ion':
  101627. default:
  101628. return get3dTilesOptions(this.tileset.tileset);
  101629. }
  101630. }
  101631. }
  101632. class Tileset3DTraverser extends TilesetTraverser {
  101633. compareDistanceToCamera(a, b) {
  101634. return b._distanceToCamera === 0 && a._distanceToCamera === 0 ? b._centerZDepth - a._centerZDepth : b._distanceToCamera - a._distanceToCamera;
  101635. }
  101636. updateTileVisibility(tile, frameState) {
  101637. super.updateTileVisibility(tile, frameState);
  101638. if (!tile.isVisibleAndInRequestVolume) {
  101639. return;
  101640. }
  101641. const hasChildren = tile.children.length > 0;
  101642. if (tile.hasTilesetContent && hasChildren) {
  101643. const firstChild = tile.children[0];
  101644. this.updateTileVisibility(firstChild, frameState);
  101645. tile._visible = firstChild._visible;
  101646. return;
  101647. }
  101648. if (this.meetsScreenSpaceErrorEarly(tile, frameState)) {
  101649. tile._visible = false;
  101650. return;
  101651. }
  101652. const replace = tile.refine === TILE_REFINEMENT.REPLACE;
  101653. const useOptimization = tile._optimChildrenWithinParent === TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION;
  101654. if (replace && useOptimization && hasChildren) {
  101655. if (!this.anyChildrenVisible(tile, frameState)) {
  101656. tile._visible = false;
  101657. return;
  101658. }
  101659. }
  101660. }
  101661. meetsScreenSpaceErrorEarly(tile, frameState) {
  101662. const {
  101663. parent
  101664. } = tile;
  101665. if (!parent || parent.hasTilesetContent || parent.refine !== TILE_REFINEMENT.ADD) {
  101666. return false;
  101667. }
  101668. return !this.shouldRefine(tile, frameState, true);
  101669. }
  101670. }
  101671. const STATUS = {
  101672. REQUESTED: 'REQUESTED',
  101673. COMPLETED: 'COMPLETED',
  101674. ERROR: 'ERROR'
  101675. };
  101676. class I3STileManager {
  101677. constructor() {
  101678. _defineProperty(this, "_statusMap", void 0);
  101679. this._statusMap = {};
  101680. }
  101681. add(request, key, callback, frameState) {
  101682. if (!this._statusMap[key]) {
  101683. this._statusMap[key] = {
  101684. request,
  101685. callback,
  101686. key,
  101687. frameState,
  101688. status: STATUS.REQUESTED
  101689. };
  101690. request().then(data => {
  101691. this._statusMap[key].status = STATUS.COMPLETED;
  101692. this._statusMap[key].callback(data, frameState);
  101693. }).catch(error => {
  101694. this._statusMap[key].status = STATUS.ERROR;
  101695. callback(error);
  101696. });
  101697. }
  101698. }
  101699. update(key, frameState) {
  101700. if (this._statusMap[key]) {
  101701. this._statusMap[key].frameState = frameState;
  101702. }
  101703. }
  101704. find(key) {
  101705. return this._statusMap[key];
  101706. }
  101707. }
  101708. class I3STilesetTraverser extends TilesetTraverser {
  101709. constructor(options) {
  101710. super(options);
  101711. _defineProperty(this, "_tileManager", void 0);
  101712. this._tileManager = new I3STileManager();
  101713. }
  101714. shouldRefine(tile, frameState) {
  101715. tile._lodJudge = getLodStatus(tile, frameState);
  101716. return tile._lodJudge === 'DIG';
  101717. }
  101718. updateChildTiles(tile, frameState) {
  101719. const children = tile.header.children || [];
  101720. const childTiles = tile.children;
  101721. const tileset = tile.tileset;
  101722. for (const child of children) {
  101723. const extendedId = "".concat(child.id, "-").concat(frameState.viewport.id);
  101724. const childTile = childTiles && childTiles.find(t => t.id === extendedId);
  101725. if (!childTile) {
  101726. let request = () => this._loadTile(child.id, tileset);
  101727. const cachedRequest = this._tileManager.find(extendedId);
  101728. if (!cachedRequest) {
  101729. if (tileset.tileset.nodePages) {
  101730. request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);
  101731. }
  101732. this._tileManager.add(request, extendedId, header => this._onTileLoad(header, tile, extendedId), frameState);
  101733. } else {
  101734. this._tileManager.update(extendedId, frameState);
  101735. }
  101736. } else if (childTile) {
  101737. this.updateTile(childTile, frameState);
  101738. }
  101739. }
  101740. return false;
  101741. }
  101742. async _loadTile(nodeId, tileset) {
  101743. const {
  101744. loader
  101745. } = tileset;
  101746. const nodeUrl = tileset.getTileUrl("".concat(tileset.url, "/nodes/").concat(nodeId));
  101747. const options = { ...tileset.loadOptions,
  101748. i3s: { ...tileset.loadOptions.i3s,
  101749. isTileHeader: true,
  101750. loadContent: false
  101751. }
  101752. };
  101753. return await load(nodeUrl, loader, options);
  101754. }
  101755. _onTileLoad(header, tile, extendedId) {
  101756. const childTile = new TileHeader(tile.tileset, header, tile, extendedId);
  101757. tile.children.push(childTile);
  101758. const frameState = this._tileManager.find(childTile.id).frameState;
  101759. this.updateTile(childTile, frameState);
  101760. if (this._frameNumber === frameState.frameNumber) {
  101761. this.executeTraversal(childTile, frameState);
  101762. }
  101763. }
  101764. }
  101765. const DEFAULT_PROPS = {
  101766. description: '',
  101767. ellipsoid: Ellipsoid.WGS84,
  101768. modelMatrix: new Matrix4$1(),
  101769. throttleRequests: true,
  101770. maxRequests: 64,
  101771. maximumMemoryUsage: 32,
  101772. onTileLoad: () => {},
  101773. onTileUnload: () => {},
  101774. onTileError: () => {},
  101775. onTraversalComplete: selectedTiles => selectedTiles,
  101776. contentLoader: undefined,
  101777. viewDistanceScale: 1.0,
  101778. maximumScreenSpaceError: 8,
  101779. loadTiles: true,
  101780. updateTransforms: true,
  101781. viewportTraversersMap: null,
  101782. loadOptions: {
  101783. fetch: {}
  101784. },
  101785. attributions: [],
  101786. basePath: '',
  101787. i3s: {}
  101788. };
  101789. const TILES_TOTAL = 'Tiles In Tileset(s)';
  101790. const TILES_IN_MEMORY = 'Tiles In Memory';
  101791. const TILES_IN_VIEW = 'Tiles In View';
  101792. const TILES_RENDERABLE = 'Tiles To Render';
  101793. const TILES_LOADED = 'Tiles Loaded';
  101794. const TILES_LOADING = 'Tiles Loading';
  101795. const TILES_UNLOADED = 'Tiles Unloaded';
  101796. const TILES_LOAD_FAILED = 'Failed Tile Loads';
  101797. const POINTS_COUNT = 'Points';
  101798. const TILES_GPU_MEMORY = 'Tile Memory Use';
  101799. let tilesetSid = 0;//add
  101800. class Tileset3D extends EventDispatcher{//xzw add EventDispatcher
  101801. constructor(json, options) {
  101802. super();
  101803. viewer.visiVertexCount = viewer.visiVertexCount || 0;
  101804. _defineProperty(this, "options", void 0);
  101805. _defineProperty(this, "loadOptions", void 0);
  101806. _defineProperty(this, "type", void 0);
  101807. _defineProperty(this, "tileset", void 0);
  101808. _defineProperty(this, "loader", void 0);
  101809. _defineProperty(this, "url", void 0);
  101810. _defineProperty(this, "basePath", void 0);
  101811. _defineProperty(this, "modelMatrix", void 0);
  101812. _defineProperty(this, "ellipsoid", void 0);
  101813. _defineProperty(this, "lodMetricType", void 0);
  101814. _defineProperty(this, "lodMetricValue", void 0);
  101815. _defineProperty(this, "refine", void 0);
  101816. _defineProperty(this, "root", void 0);
  101817. _defineProperty(this, "roots", void 0);
  101818. _defineProperty(this, "asset", void 0);
  101819. _defineProperty(this, "description", void 0);
  101820. _defineProperty(this, "properties", void 0);
  101821. _defineProperty(this, "extras", void 0);
  101822. _defineProperty(this, "attributions", void 0);
  101823. _defineProperty(this, "credits", void 0);
  101824. _defineProperty(this, "stats", void 0);
  101825. _defineProperty(this, "traverseCounter", void 0);
  101826. _defineProperty(this, "geometricError", void 0);
  101827. _defineProperty(this, "selectedTiles", void 0);
  101828. _defineProperty(this, "cartographicCenter", void 0);
  101829. _defineProperty(this, "cartesianCenter", void 0);
  101830. _defineProperty(this, "zoom", void 0);
  101831. _defineProperty(this, "boundingVolume", void 0);
  101832. _defineProperty(this, "gpuMemoryUsageInBytes", void 0);
  101833. _defineProperty(this, "dynamicScreenSpaceErrorComputedDensity", void 0);
  101834. _defineProperty(this, "_traverser", void 0);
  101835. _defineProperty(this, "_cache", void 0);
  101836. _defineProperty(this, "_requestScheduler", void 0);
  101837. _defineProperty(this, "_frameNumber", void 0);
  101838. _defineProperty(this, "_queryParamsString", void 0);
  101839. _defineProperty(this, "_queryParams", void 0);
  101840. _defineProperty(this, "_extensionsUsed", void 0);
  101841. _defineProperty(this, "_tiles", void 0);
  101842. _defineProperty(this, "_pendingCount", void 0);
  101843. _defineProperty(this, "lastUpdatedVieports", void 0);
  101844. _defineProperty(this, "_requestedTiles", void 0);
  101845. _defineProperty(this, "_emptyTiles", void 0);
  101846. _defineProperty(this, "frameStateData", void 0);
  101847. _defineProperty(this, "maximumMemoryUsage", void 0);
  101848. _defineProperty(this, "visible", true);//add
  101849. assert$7(json);
  101850. this.options = { ...DEFAULT_PROPS,
  101851. ...options
  101852. };
  101853. this.tileset = json;
  101854. this.loader = json.loader;
  101855. this.type = json.type;
  101856. this.url = json.url;
  101857. this.basePath = json.basePath || dirname(this.url);
  101858. this.modelMatrix = this.options.modelMatrix;
  101859. this.ellipsoid = this.options.ellipsoid;
  101860. this.lodMetricType = json.lodMetricType;
  101861. this.lodMetricValue = json.lodMetricValue;
  101862. this.refine = json.root.refine;
  101863. this.loadOptions = this.options.loadOptions || {};
  101864. this.root = null;
  101865. this.roots = {};
  101866. this.cartographicCenter = null;
  101867. this.cartesianCenter = null;
  101868. this.zoom = 1;
  101869. this.boundingVolume = null;
  101870. this.traverseCounter = 0;
  101871. this.geometricError = 0;
  101872. this._traverser = this._initializeTraverser();
  101873. this._cache = new TilesetCache();
  101874. this._requestScheduler = new RequestScheduler({
  101875. throttleRequests: this.options.throttleRequests,
  101876. maxRequests: this.options.maxRequests
  101877. });
  101878. this._frameNumber = 0;
  101879. this._pendingCount = 0;
  101880. this._tiles = {};
  101881. this.selectedTiles = [];
  101882. this._emptyTiles = [];
  101883. this._requestedTiles = [];
  101884. this.frameStateData = {};
  101885. this.lastUpdatedVieports = null;
  101886. this._queryParams = {};
  101887. this._queryParamsString = '';
  101888. this.maximumMemoryUsage = this.options.maximumMemoryUsage || 32;
  101889. this.gpuMemoryUsageInBytes = 0;
  101890. this.stats = new Stats$1({
  101891. id: this.url
  101892. });
  101893. this._initializeStats();
  101894. this._extensionsUsed = undefined;
  101895. this.dynamicScreenSpaceErrorComputedDensity = 0.0;
  101896. this.extras = null;
  101897. this.asset = {};
  101898. this.credits = {};
  101899. this.description = this.options.description || '';
  101900. this._initializeTileSet(json);
  101901. }
  101902. destroy() {
  101903. this._destroy();
  101904. }
  101905. isLoaded() {
  101906. return this._pendingCount === 0 && this._frameNumber !== 0;
  101907. }
  101908. get tiles() {
  101909. return Object.values(this._tiles);
  101910. }
  101911. get frameNumber() {
  101912. return this._frameNumber;
  101913. }
  101914. get queryParams() {
  101915. if (!this._queryParamsString) {
  101916. this._queryParamsString = getQueryParamString(this._queryParams);
  101917. }
  101918. return this._queryParamsString;
  101919. }
  101920. setProps(props) {
  101921. this.options = { ...this.options,
  101922. ...props
  101923. };
  101924. }
  101925. setOptions(options) {
  101926. this.options = { ...this.options,
  101927. ...options
  101928. };
  101929. }
  101930. getTileUrl(tilePath) {
  101931. const isDataUrl = tilePath.startsWith('data:');
  101932. tilePath = Potree.Common.dealURL(tilePath); //add 去除'+'
  101933. if (isDataUrl) {
  101934. return tilePath;
  101935. }
  101936. return "".concat(tilePath).concat(this.queryParams);
  101937. }
  101938. hasExtension(extensionName) {
  101939. return Boolean(this._extensionsUsed && this._extensionsUsed.indexOf(extensionName) > -1);
  101940. }
  101941. update(viewports) {
  101942. if ('loadTiles' in this.options && !this.options.loadTiles) {
  101943. return;
  101944. }
  101945. if (this.traverseCounter > 0) {
  101946. return;
  101947. }
  101948. if (!viewports && this.lastUpdatedVieports) {
  101949. viewports = this.lastUpdatedVieports;
  101950. } else {
  101951. this.lastUpdatedVieports = viewports;
  101952. }
  101953. if (!(viewports instanceof Array)) {
  101954. viewports = [viewports];
  101955. }
  101956. this._cache.reset();
  101957. this._frameNumber++;
  101958. this.traverseCounter = viewports.length;
  101959. const viewportsToTraverse = [];
  101960. for (const viewport of viewports) {
  101961. const id = viewport.id;
  101962. if (this._needTraverse(id)) {
  101963. viewportsToTraverse.push(id);
  101964. } else {
  101965. this.traverseCounter--;
  101966. }
  101967. }
  101968. for (const viewport of viewports) {
  101969. const id = viewport.id;
  101970. if (!this.roots[id]) {
  101971. this.roots[id] = this._initializeTileHeaders(this.tileset, null);
  101972. }
  101973. if (!viewportsToTraverse.includes(id)) {
  101974. continue;
  101975. }
  101976. const frameState = getFrameState(viewport, this._frameNumber);
  101977. this._traverser.traverse(this.roots[id], frameState, this.options);
  101978. }
  101979. }
  101980. _needTraverse(viewportId) {
  101981. let traverserId = viewportId;
  101982. if (this.options.viewportTraversersMap) {
  101983. traverserId = this.options.viewportTraversersMap[viewportId];
  101984. }
  101985. if (traverserId !== viewportId) {
  101986. return false;
  101987. }
  101988. return true;
  101989. }
  101990. _onTraversalEnd(frameState) {
  101991. const id = frameState.viewport.id;
  101992. if (!this.frameStateData[id]) {
  101993. this.frameStateData[id] = {
  101994. selectedTiles: [],
  101995. _requestedTiles: [],
  101996. _emptyTiles: []
  101997. };
  101998. }
  101999. const currentFrameStateData = this.frameStateData[id];
  102000. const selectedTiles = Object.values(this._traverser.selectedTiles);
  102001. currentFrameStateData.selectedTiles = selectedTiles;
  102002. currentFrameStateData._requestedTiles = Object.values(this._traverser.requestedTiles);
  102003. currentFrameStateData._emptyTiles = Object.values(this._traverser.emptyTiles);
  102004. this.traverseCounter--;
  102005. if (this.traverseCounter > 0) {
  102006. return;
  102007. }
  102008. this._updateTiles();
  102009. }
  102010. _updateTiles() {
  102011. this.selectedTiles = [];
  102012. this._requestedTiles = [];
  102013. this._emptyTiles = [];
  102014. for (const frameStateKey in this.frameStateData) {
  102015. const frameStateDataValue = this.frameStateData[frameStateKey];
  102016. this.selectedTiles = this.selectedTiles.concat(frameStateDataValue.selectedTiles);
  102017. this._requestedTiles = this._requestedTiles.concat(frameStateDataValue._requestedTiles);
  102018. this._emptyTiles = this._emptyTiles.concat(frameStateDataValue._emptyTiles);
  102019. }
  102020. this.selectedTiles = this.options.onTraversalComplete(this.selectedTiles);
  102021. for (const tile of this.selectedTiles) {
  102022. this._tiles[tile.id] = tile;
  102023. }
  102024. this._loadTiles();
  102025. this._unloadTiles();
  102026. this._updateStats();
  102027. }
  102028. _tilesChanged(oldSelectedTiles, selectedTiles) {
  102029. if (oldSelectedTiles.length !== selectedTiles.length) {
  102030. return true;
  102031. }
  102032. const set1 = new Set(oldSelectedTiles.map(t => t.id));
  102033. const set2 = new Set(selectedTiles.map(t => t.id));
  102034. let changed = oldSelectedTiles.filter(x => !set2.has(x.id)).length > 0;
  102035. changed = changed || selectedTiles.filter(x => !set1.has(x.id)).length > 0;
  102036. return changed;
  102037. }
  102038. _loadTiles() {
  102039. for (const tile of this._requestedTiles) {
  102040. if (tile.contentUnloaded) {
  102041. this._loadTile(tile);
  102042. }
  102043. }
  102044. }
  102045. _unloadTiles() {
  102046. this._cache.unloadTiles(this, (tileset, tile) => tileset._unloadTile(tile));
  102047. }
  102048. _updateStats() {
  102049. let tilesRenderable = 0;
  102050. let pointsRenderable = 0;
  102051. for (const tile of this.selectedTiles) {
  102052. if (tile.contentAvailable && tile.content) {
  102053. tilesRenderable++;
  102054. if (tile.content.pointCount) {
  102055. pointsRenderable += tile.content.pointCount;
  102056. }
  102057. }
  102058. }
  102059. this.stats.get(TILES_IN_VIEW).count = this.selectedTiles.length;
  102060. this.stats.get(TILES_RENDERABLE).count = tilesRenderable;
  102061. this.stats.get(POINTS_COUNT).count = pointsRenderable;
  102062. }
  102063. _initializeTileSet(tilesetJson) {
  102064. this.root = this._initializeTileHeaders(tilesetJson, null);
  102065. if (this.type === TILESET_TYPE.TILES3D) {
  102066. this._initializeCesiumTileset(tilesetJson);
  102067. }
  102068. if (this.type === TILESET_TYPE.I3S) {
  102069. this._initializeI3STileset();
  102070. }
  102071. this._calculateViewProps();
  102072. }
  102073. _calculateViewProps() {
  102074. const root = this.root;
  102075. assert$7(root);
  102076. const {
  102077. center
  102078. } = root.boundingVolume;
  102079. if (!center) {
  102080. console.warn('center was not pre-calculated for the root tile');
  102081. this.cartographicCenter = new Vector3$1();
  102082. this.zoom = 1;
  102083. return;
  102084. }
  102085. this.cartographicCenter = Ellipsoid.WGS84.cartesianToCartographic(center, new Vector3$1());
  102086. this.cartesianCenter = center;
  102087. this.zoom = getZoomFromBoundingVolume(root.boundingVolume);
  102088. }
  102089. _initializeStats() {
  102090. this.stats.get(TILES_TOTAL);
  102091. this.stats.get(TILES_LOADING);
  102092. this.stats.get(TILES_IN_MEMORY);
  102093. this.stats.get(TILES_IN_VIEW);
  102094. this.stats.get(TILES_RENDERABLE);
  102095. this.stats.get(TILES_LOADED);
  102096. this.stats.get(TILES_UNLOADED);
  102097. this.stats.get(TILES_LOAD_FAILED);
  102098. this.stats.get(POINTS_COUNT, 'memory');
  102099. this.stats.get(TILES_GPU_MEMORY, 'memory');
  102100. }
  102101. _initializeTileHeaders(tilesetJson, parentTileHeader) {
  102102. const rootTile = new TileHeader(this, tilesetJson.root, parentTileHeader, parentTileHeader == void 0 && 'root_'+tilesetSid++);
  102103. if (parentTileHeader) {
  102104. parentTileHeader.children.push(rootTile);
  102105. rootTile.depth = parentTileHeader.depth + 1;
  102106. }
  102107. if (this.type === TILESET_TYPE.TILES3D) {
  102108. const stack = [];
  102109. stack.push(rootTile);
  102110. while (stack.length > 0) {
  102111. const tile = stack.pop();
  102112. this.stats.get(TILES_TOTAL).incrementCount();
  102113. const children = tile.header.children || [];
  102114. // !zeg改
  102115. if(tile.depth < /* this.options. */maxDepth){
  102116. for (const childHeader of children) {
  102117. const childTile = new TileHeader(this, childHeader, tile);
  102118. tile.children.push(childTile);
  102119. childTile.depth = tile.depth + 1;
  102120. stack.push(childTile);
  102121. }
  102122. }
  102123. window.maxTileDepth = Math.max(window.maxTileDepth||0, tile.depth);
  102124. }
  102125. }
  102126. return rootTile;
  102127. }
  102128. _initializeTraverser() {
  102129. let TraverserClass;
  102130. const type = this.type;
  102131. switch (type) {
  102132. case TILESET_TYPE.TILES3D:
  102133. TraverserClass = Tileset3DTraverser;
  102134. break;
  102135. case TILESET_TYPE.I3S:
  102136. TraverserClass = I3STilesetTraverser;
  102137. break;
  102138. default:
  102139. TraverserClass = TilesetTraverser;
  102140. }
  102141. return new TraverserClass({
  102142. basePath: this.basePath,
  102143. onTraversalEnd: this._onTraversalEnd.bind(this)
  102144. });
  102145. }
  102146. _destroyTileHeaders(parentTile) {
  102147. this._destroySubtree(parentTile);
  102148. }
  102149. async _loadTile(tile) {
  102150. let loaded;
  102151. try {
  102152. this._onStartTileLoading();
  102153. loaded = await tile.loadContent();
  102154. } catch (error) {
  102155. this._onTileLoadError(tile, error);
  102156. } finally {
  102157. this._onEndTileLoading(tile);//
  102158. this._onTileLoad(tile, loaded);
  102159. }
  102160. }
  102161. _onTileLoadError(tile, error) {
  102162. this.stats.get(TILES_LOAD_FAILED).incrementCount();
  102163. const message = error.message || error.toString();
  102164. const url = tile.url;
  102165. console.error("A 3D tile failed to load: ".concat(tile.url, " ").concat(message));
  102166. this.options.onTileError(tile, message, url);
  102167. }
  102168. _onTileLoad(tile, loaded) {
  102169. if (!loaded) {
  102170. return;
  102171. }
  102172. if (tile && tile.content) {
  102173. calculateTransformProps(tile, tile.content);
  102174. }
  102175. this._addTileToCache(tile);
  102176. this.options.onTileLoad(tile);
  102177. }
  102178. _onStartTileLoading() {
  102179. this._pendingCount++;
  102180. this.stats.get(TILES_LOADING).incrementCount();
  102181. }
  102182. _onEndTileLoading(tile) {
  102183. this._pendingCount--;
  102184. this.stats.get(TILES_LOADING).decrementCount();
  102185. this.dispatchEvent({type:'endTileLoading', tile, loadingCount: this._pendingCount }); // !zeg改
  102186. }
  102187. _addTileToCache(tile) {
  102188. this._cache.add(this, tile, tileset => tileset._updateCacheStats(tile));
  102189. }
  102190. _updateCacheStats(tile) {
  102191. this.stats.get(TILES_LOADED).incrementCount();
  102192. this.stats.get(TILES_IN_MEMORY).incrementCount();
  102193. this.gpuMemoryUsageInBytes += tile.content.byteLength || 0;
  102194. this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
  102195. }
  102196. _unloadTile(tile) {
  102197. this.gpuMemoryUsageInBytes -= tile.content && tile.content.byteLength || 0;
  102198. this.stats.get(TILES_IN_MEMORY).decrementCount();
  102199. this.stats.get(TILES_UNLOADED).incrementCount();
  102200. this.stats.get(TILES_GPU_MEMORY).count = this.gpuMemoryUsageInBytes;
  102201. this.options.onTileUnload(tile);
  102202. tile.unloadContent();
  102203. }
  102204. _destroy() {
  102205. const stack = [];
  102206. if (this.root) {
  102207. stack.push(this.root);
  102208. }
  102209. while (stack.length > 0) {
  102210. const tile = stack.pop();
  102211. for (const child of tile.children) {
  102212. stack.push(child);
  102213. }
  102214. this._destroyTile(tile);
  102215. }
  102216. this.root = null;
  102217. }
  102218. _destroySubtree(tile) {
  102219. const root = tile;
  102220. const stack = [];
  102221. stack.push(root);
  102222. while (stack.length > 0) {
  102223. tile = stack.pop();
  102224. for (const child of tile.children) {
  102225. stack.push(child);
  102226. }
  102227. if (tile !== root) {
  102228. this._destroyTile(tile);
  102229. }
  102230. }
  102231. root.children = [];
  102232. }
  102233. _destroyTile(tile) {
  102234. this._cache.unloadTile(this, tile);
  102235. this._unloadTile(tile);
  102236. tile.destroy();
  102237. }
  102238. _initializeCesiumTileset(tilesetJson) {
  102239. this.asset = tilesetJson.asset;
  102240. if (!this.asset) {
  102241. throw new Error('Tileset must have an asset property.');
  102242. }
  102243. if (this.asset.version !== '0.0' && this.asset.version !== '1.0') {
  102244. throw new Error('The tileset must be 3D Tiles version 0.0 or 1.0.');
  102245. }
  102246. if ('tilesetVersion' in this.asset) {
  102247. this._queryParams.v = this.asset.tilesetVersion;
  102248. }
  102249. this.credits = {
  102250. attributions: this.options.attributions || []
  102251. };
  102252. this.description = this.options.description || '';
  102253. this.properties = tilesetJson.properties;
  102254. this.geometricError = tilesetJson.geometricError;
  102255. this._extensionsUsed = tilesetJson.extensionsUsed;
  102256. this.extras = tilesetJson.extras;
  102257. }
  102258. _initializeI3STileset() {
  102259. if (this.loadOptions.i3s && 'token' in this.loadOptions.i3s) {
  102260. this._queryParams.token = this.loadOptions.i3s.token;
  102261. }
  102262. }
  102263. }
  102264. function getQueryParamString(queryParams) {
  102265. const queryParamStrings = [];
  102266. for (const key of Object.keys(queryParams)) {
  102267. queryParamStrings.push("".concat(key, "=").concat(queryParams[key]));
  102268. }
  102269. switch (queryParamStrings.length) {
  102270. case 0:
  102271. return '';
  102272. case 1:
  102273. return "?".concat(queryParamStrings[0]);
  102274. default:
  102275. return "?".concat(queryParamStrings.join('&'));
  102276. }
  102277. }
  102278. const VERSION$5 = "3.1.4" ;
  102279. const TILE3D_TYPE = {
  102280. COMPOSITE: 'cmpt',
  102281. POINT_CLOUD: 'pnts',
  102282. BATCHED_3D_MODEL: 'b3dm',
  102283. INSTANCED_3D_MODEL: 'i3dm',
  102284. GEOMETRY: 'geom',
  102285. VECTOR: 'vect',
  102286. GLTF: 'glTF'
  102287. };
  102288. function getStringFromArrayBuffer(arrayBuffer, byteOffset, byteLength) {
  102289. assert$7(arrayBuffer instanceof ArrayBuffer);
  102290. const textDecoder = new TextDecoder('utf8');
  102291. const typedArray = new Uint8Array(arrayBuffer, byteOffset, byteLength);
  102292. const string = textDecoder.decode(typedArray);
  102293. return string;
  102294. }
  102295. function getMagicString$1(arrayBuffer, byteOffset = 0) {
  102296. const dataView = new DataView(arrayBuffer);
  102297. 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)));
  102298. }
  102299. const VERSION$4 = "3.1.4" ;
  102300. const DEFAULT_DRACO_OPTIONS = {
  102301. draco: {
  102302. decoderType: typeof WebAssembly === 'object' ? 'wasm' : 'js',
  102303. libraryPath: 'libs/',
  102304. extraAttributes: {},
  102305. attributeNameEntry: undefined
  102306. }
  102307. };
  102308. const DracoLoader$1 = {
  102309. name: 'Draco',
  102310. id: 'draco',
  102311. module: 'draco',
  102312. shapes: ['mesh'],
  102313. version: VERSION$4,
  102314. worker: true,
  102315. extensions: ['drc'],
  102316. mimeTypes: ['application/octet-stream'],
  102317. binary: true,
  102318. tests: ['DRACO'],
  102319. options: DEFAULT_DRACO_OPTIONS
  102320. };
  102321. function getMeshBoundingBox(attributes) {
  102322. let minX = Infinity;
  102323. let minY = Infinity;
  102324. let minZ = Infinity;
  102325. let maxX = -Infinity;
  102326. let maxY = -Infinity;
  102327. let maxZ = -Infinity;
  102328. const positions = attributes.POSITION ? attributes.POSITION.value : [];
  102329. const len = positions && positions.length;
  102330. for (let i = 0; i < len; i += 3) {
  102331. const x = positions[i];
  102332. const y = positions[i + 1];
  102333. const z = positions[i + 2];
  102334. minX = x < minX ? x : minX;
  102335. minY = y < minY ? y : minY;
  102336. minZ = z < minZ ? z : minZ;
  102337. maxX = x > maxX ? x : maxX;
  102338. maxY = y > maxY ? y : maxY;
  102339. maxZ = z > maxZ ? z : maxZ;
  102340. }
  102341. return [[minX, minY, minZ], [maxX, maxY, maxZ]];
  102342. }
  102343. function assert$3(condition, message) {
  102344. if (!condition) {
  102345. throw new Error(message || 'loader assertion failed.');
  102346. }
  102347. }
  102348. class Schema {
  102349. constructor(fields, metadata) {
  102350. _defineProperty(this, "fields", void 0);
  102351. _defineProperty(this, "metadata", void 0);
  102352. assert$3(Array.isArray(fields));
  102353. checkNames(fields);
  102354. this.fields = fields;
  102355. this.metadata = metadata || new Map();
  102356. }
  102357. compareTo(other) {
  102358. if (this.metadata !== other.metadata) {
  102359. return false;
  102360. }
  102361. if (this.fields.length !== other.fields.length) {
  102362. return false;
  102363. }
  102364. for (let i = 0; i < this.fields.length; ++i) {
  102365. if (!this.fields[i].compareTo(other.fields[i])) {
  102366. return false;
  102367. }
  102368. }
  102369. return true;
  102370. }
  102371. select(...columnNames) {
  102372. const nameMap = Object.create(null);
  102373. for (const name of columnNames) {
  102374. nameMap[name] = true;
  102375. }
  102376. const selectedFields = this.fields.filter(field => nameMap[field.name]);
  102377. return new Schema(selectedFields, this.metadata);
  102378. }
  102379. selectAt(...columnIndices) {
  102380. const selectedFields = columnIndices.map(index => this.fields[index]).filter(Boolean);
  102381. return new Schema(selectedFields, this.metadata);
  102382. }
  102383. assign(schemaOrFields) {
  102384. let fields;
  102385. let metadata = this.metadata;
  102386. if (schemaOrFields instanceof Schema) {
  102387. const otherSchema = schemaOrFields;
  102388. fields = otherSchema.fields;
  102389. metadata = mergeMaps(mergeMaps(new Map(), this.metadata), otherSchema.metadata);
  102390. } else {
  102391. fields = schemaOrFields;
  102392. }
  102393. const fieldMap = Object.create(null);
  102394. for (const field of this.fields) {
  102395. fieldMap[field.name] = field;
  102396. }
  102397. for (const field of fields) {
  102398. fieldMap[field.name] = field;
  102399. }
  102400. const mergedFields = Object.values(fieldMap);
  102401. return new Schema(mergedFields, metadata);
  102402. }
  102403. }
  102404. function checkNames(fields) {
  102405. const usedNames = {};
  102406. for (const field of fields) {
  102407. if (usedNames[field.name]) {
  102408. console.warn('Schema: duplicated field name', field.name, field);
  102409. }
  102410. usedNames[field.name] = true;
  102411. }
  102412. }
  102413. function mergeMaps(m1, m2) {
  102414. return new Map([...(m1 || new Map()), ...(m2 || new Map())]);
  102415. }
  102416. class Field {
  102417. constructor(name, type, nullable = false, metadata = new Map()) {
  102418. _defineProperty(this, "name", void 0);
  102419. _defineProperty(this, "type", void 0);
  102420. _defineProperty(this, "nullable", void 0);
  102421. _defineProperty(this, "metadata", void 0);
  102422. this.name = name;
  102423. this.type = type;
  102424. this.nullable = nullable;
  102425. this.metadata = metadata;
  102426. }
  102427. get typeId() {
  102428. return this.type && this.type.typeId;
  102429. }
  102430. clone() {
  102431. return new Field(this.name, this.type, this.nullable, this.metadata);
  102432. }
  102433. compareTo(other) {
  102434. return this.name === other.name && this.type === other.type && this.nullable === other.nullable && this.metadata === other.metadata;
  102435. }
  102436. toString() {
  102437. return "".concat(this.type).concat(this.nullable ? ', nullable' : '').concat(this.metadata ? ", metadata: ".concat(this.metadata) : '');
  102438. }
  102439. }
  102440. let Type$1;
  102441. (function (Type) {
  102442. Type[Type["NONE"] = 0] = "NONE";
  102443. Type[Type["Null"] = 1] = "Null";
  102444. Type[Type["Int"] = 2] = "Int";
  102445. Type[Type["Float"] = 3] = "Float";
  102446. Type[Type["Binary"] = 4] = "Binary";
  102447. Type[Type["Utf8"] = 5] = "Utf8";
  102448. Type[Type["Bool"] = 6] = "Bool";
  102449. Type[Type["Decimal"] = 7] = "Decimal";
  102450. Type[Type["Date"] = 8] = "Date";
  102451. Type[Type["Time"] = 9] = "Time";
  102452. Type[Type["Timestamp"] = 10] = "Timestamp";
  102453. Type[Type["Interval"] = 11] = "Interval";
  102454. Type[Type["List"] = 12] = "List";
  102455. Type[Type["Struct"] = 13] = "Struct";
  102456. Type[Type["Union"] = 14] = "Union";
  102457. Type[Type["FixedSizeBinary"] = 15] = "FixedSizeBinary";
  102458. Type[Type["FixedSizeList"] = 16] = "FixedSizeList";
  102459. Type[Type["Map"] = 17] = "Map";
  102460. Type[Type["Dictionary"] = -1] = "Dictionary";
  102461. Type[Type["Int8"] = -2] = "Int8";
  102462. Type[Type["Int16"] = -3] = "Int16";
  102463. Type[Type["Int32"] = -4] = "Int32";
  102464. Type[Type["Int64"] = -5] = "Int64";
  102465. Type[Type["Uint8"] = -6] = "Uint8";
  102466. Type[Type["Uint16"] = -7] = "Uint16";
  102467. Type[Type["Uint32"] = -8] = "Uint32";
  102468. Type[Type["Uint64"] = -9] = "Uint64";
  102469. Type[Type["Float16"] = -10] = "Float16";
  102470. Type[Type["Float32"] = -11] = "Float32";
  102471. Type[Type["Float64"] = -12] = "Float64";
  102472. Type[Type["DateDay"] = -13] = "DateDay";
  102473. Type[Type["DateMillisecond"] = -14] = "DateMillisecond";
  102474. Type[Type["TimestampSecond"] = -15] = "TimestampSecond";
  102475. Type[Type["TimestampMillisecond"] = -16] = "TimestampMillisecond";
  102476. Type[Type["TimestampMicrosecond"] = -17] = "TimestampMicrosecond";
  102477. Type[Type["TimestampNanosecond"] = -18] = "TimestampNanosecond";
  102478. Type[Type["TimeSecond"] = -19] = "TimeSecond";
  102479. Type[Type["TimeMillisecond"] = -20] = "TimeMillisecond";
  102480. Type[Type["TimeMicrosecond"] = -21] = "TimeMicrosecond";
  102481. Type[Type["TimeNanosecond"] = -22] = "TimeNanosecond";
  102482. Type[Type["DenseUnion"] = -23] = "DenseUnion";
  102483. Type[Type["SparseUnion"] = -24] = "SparseUnion";
  102484. Type[Type["IntervalDayTime"] = -25] = "IntervalDayTime";
  102485. Type[Type["IntervalYearMonth"] = -26] = "IntervalYearMonth";
  102486. })(Type$1 || (Type$1 = {}));
  102487. let _Symbol$toStringTag, _Symbol$toStringTag2, _Symbol$toStringTag7;
  102488. class DataType {
  102489. static isNull(x) {
  102490. return x && x.typeId === Type$1.Null;
  102491. }
  102492. static isInt(x) {
  102493. return x && x.typeId === Type$1.Int;
  102494. }
  102495. static isFloat(x) {
  102496. return x && x.typeId === Type$1.Float;
  102497. }
  102498. static isBinary(x) {
  102499. return x && x.typeId === Type$1.Binary;
  102500. }
  102501. static isUtf8(x) {
  102502. return x && x.typeId === Type$1.Utf8;
  102503. }
  102504. static isBool(x) {
  102505. return x && x.typeId === Type$1.Bool;
  102506. }
  102507. static isDecimal(x) {
  102508. return x && x.typeId === Type$1.Decimal;
  102509. }
  102510. static isDate(x) {
  102511. return x && x.typeId === Type$1.Date;
  102512. }
  102513. static isTime(x) {
  102514. return x && x.typeId === Type$1.Time;
  102515. }
  102516. static isTimestamp(x) {
  102517. return x && x.typeId === Type$1.Timestamp;
  102518. }
  102519. static isInterval(x) {
  102520. return x && x.typeId === Type$1.Interval;
  102521. }
  102522. static isList(x) {
  102523. return x && x.typeId === Type$1.List;
  102524. }
  102525. static isStruct(x) {
  102526. return x && x.typeId === Type$1.Struct;
  102527. }
  102528. static isUnion(x) {
  102529. return x && x.typeId === Type$1.Union;
  102530. }
  102531. static isFixedSizeBinary(x) {
  102532. return x && x.typeId === Type$1.FixedSizeBinary;
  102533. }
  102534. static isFixedSizeList(x) {
  102535. return x && x.typeId === Type$1.FixedSizeList;
  102536. }
  102537. static isMap(x) {
  102538. return x && x.typeId === Type$1.Map;
  102539. }
  102540. static isDictionary(x) {
  102541. return x && x.typeId === Type$1.Dictionary;
  102542. }
  102543. get typeId() {
  102544. return Type$1.NONE;
  102545. }
  102546. compareTo(other) {
  102547. return this === other;
  102548. }
  102549. }
  102550. _Symbol$toStringTag = Symbol.toStringTag;
  102551. class Int extends DataType {
  102552. constructor(isSigned, bitWidth) {
  102553. super();
  102554. _defineProperty(this, "isSigned", void 0);
  102555. _defineProperty(this, "bitWidth", void 0);
  102556. this.isSigned = isSigned;
  102557. this.bitWidth = bitWidth;
  102558. }
  102559. get typeId() {
  102560. return Type$1.Int;
  102561. }
  102562. get [_Symbol$toStringTag]() {
  102563. return 'Int';
  102564. }
  102565. toString() {
  102566. return "".concat(this.isSigned ? 'I' : 'Ui', "nt").concat(this.bitWidth);
  102567. }
  102568. }
  102569. class Int8 extends Int {
  102570. constructor() {
  102571. super(true, 8);
  102572. }
  102573. }
  102574. class Int16 extends Int {
  102575. constructor() {
  102576. super(true, 16);
  102577. }
  102578. }
  102579. class Int32 extends Int {
  102580. constructor() {
  102581. super(true, 32);
  102582. }
  102583. }
  102584. class Uint8 extends Int {
  102585. constructor() {
  102586. super(false, 8);
  102587. }
  102588. }
  102589. class Uint16 extends Int {
  102590. constructor() {
  102591. super(false, 16);
  102592. }
  102593. }
  102594. class Uint32 extends Int {
  102595. constructor() {
  102596. super(false, 32);
  102597. }
  102598. }
  102599. const Precision = {
  102600. HALF: 16,
  102601. SINGLE: 32,
  102602. DOUBLE: 64
  102603. };
  102604. _Symbol$toStringTag2 = Symbol.toStringTag;
  102605. class Float extends DataType {
  102606. constructor(precision) {
  102607. super();
  102608. _defineProperty(this, "precision", void 0);
  102609. this.precision = precision;
  102610. }
  102611. get typeId() {
  102612. return Type$1.Float;
  102613. }
  102614. get [_Symbol$toStringTag2]() {
  102615. return 'Float';
  102616. }
  102617. toString() {
  102618. return "Float".concat(this.precision);
  102619. }
  102620. }
  102621. class Float32 extends Float {
  102622. constructor() {
  102623. super(Precision.SINGLE);
  102624. }
  102625. }
  102626. class Float64 extends Float {
  102627. constructor() {
  102628. super(Precision.DOUBLE);
  102629. }
  102630. }
  102631. _Symbol$toStringTag7 = Symbol.toStringTag;
  102632. class FixedSizeList extends DataType {
  102633. constructor(listSize, child) {
  102634. super();
  102635. _defineProperty(this, "listSize", void 0);
  102636. _defineProperty(this, "children", void 0);
  102637. this.listSize = listSize;
  102638. this.children = [child];
  102639. }
  102640. get typeId() {
  102641. return Type$1.FixedSizeList;
  102642. }
  102643. get valueType() {
  102644. return this.children[0].type;
  102645. }
  102646. get valueField() {
  102647. return this.children[0];
  102648. }
  102649. get [_Symbol$toStringTag7]() {
  102650. return 'FixedSizeList';
  102651. }
  102652. toString() {
  102653. return "FixedSizeList[".concat(this.listSize, "]<").concat(this.valueType, ">");
  102654. }
  102655. }
  102656. function getArrowTypeFromTypedArray(array) {
  102657. switch (array.constructor) {
  102658. case Int8Array:
  102659. return new Int8();
  102660. case Uint8Array:
  102661. return new Uint8();
  102662. case Int16Array:
  102663. return new Int16();
  102664. case Uint16Array:
  102665. return new Uint16();
  102666. case Int32Array:
  102667. return new Int32();
  102668. case Uint32Array:
  102669. return new Uint32();
  102670. case Float32Array:
  102671. return new Float32();
  102672. case Float64Array:
  102673. return new Float64();
  102674. default:
  102675. throw new Error('array type not supported');
  102676. }
  102677. }
  102678. function deduceMeshField(attributeName, attribute, optionalMetadata) {
  102679. const type = getArrowTypeFromTypedArray(attribute.value);
  102680. const metadata = optionalMetadata ? optionalMetadata : makeMeshAttributeMetadata(attribute);
  102681. const field = new Field(attributeName, new FixedSizeList(attribute.size, new Field('value', type)), false, metadata);
  102682. return field;
  102683. }
  102684. function makeMeshAttributeMetadata(attribute) {
  102685. const result = new Map();
  102686. if ('byteOffset' in attribute) {
  102687. result.set('byteOffset', attribute.byteOffset.toString(10));
  102688. }
  102689. if ('byteStride' in attribute) {
  102690. result.set('byteStride', attribute.byteStride.toString(10));
  102691. }
  102692. if ('normalized' in attribute) {
  102693. result.set('normalized', attribute.normalized.toString());
  102694. }
  102695. return result;
  102696. }
  102697. function getDracoSchema(attributes, loaderData, indices) {
  102698. const metadataMap = makeMetadata(loaderData.metadata);
  102699. const fields = [];
  102700. const namedLoaderDataAttributes = transformAttributesLoaderData(loaderData.attributes);
  102701. for (const attributeName in attributes) {
  102702. const attribute = attributes[attributeName];
  102703. const field = getArrowFieldFromAttribute(attributeName, attribute, namedLoaderDataAttributes[attributeName]);
  102704. fields.push(field);
  102705. }
  102706. if (indices) {
  102707. const indicesField = getArrowFieldFromAttribute('indices', indices);
  102708. fields.push(indicesField);
  102709. }
  102710. return new Schema(fields, metadataMap);
  102711. }
  102712. function transformAttributesLoaderData(loaderData) {
  102713. const result = {};
  102714. for (const key in loaderData) {
  102715. const dracoAttribute = loaderData[key];
  102716. result[dracoAttribute.name || 'undefined'] = dracoAttribute;
  102717. }
  102718. return result;
  102719. }
  102720. function getArrowFieldFromAttribute(attributeName, attribute, loaderData) {
  102721. const metadataMap = loaderData ? makeMetadata(loaderData.metadata) : undefined;
  102722. const field = deduceMeshField(attributeName, attribute, metadataMap);
  102723. return field;
  102724. }
  102725. function makeMetadata(metadata) {
  102726. const metadataMap = new Map();
  102727. for (const key in metadata) {
  102728. metadataMap.set("".concat(key, ".string"), JSON.stringify(metadata[key]));
  102729. }
  102730. return metadataMap;
  102731. }
  102732. const DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP = {
  102733. POSITION: 'POSITION',
  102734. NORMAL: 'NORMAL',
  102735. COLOR: 'COLOR_0',
  102736. TEX_COORD: 'TEXCOORD_0'
  102737. };
  102738. const DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP = {
  102739. 1: Int8Array,
  102740. 2: Uint8Array,
  102741. 3: Int16Array,
  102742. 4: Uint16Array,
  102743. 5: Int32Array,
  102744. 6: Uint32Array,
  102745. 9: Float32Array
  102746. };
  102747. const INDEX_ITEM_SIZE = 4;
  102748. class DracoParser {
  102749. constructor(draco) {
  102750. _defineProperty(this, "draco", void 0);
  102751. _defineProperty(this, "decoder", void 0);
  102752. _defineProperty(this, "metadataQuerier", void 0);
  102753. this.draco = draco;
  102754. this.decoder = new this.draco.Decoder();
  102755. this.metadataQuerier = new this.draco.MetadataQuerier();
  102756. }
  102757. destroy() {
  102758. this.draco.destroy(this.decoder);
  102759. this.draco.destroy(this.metadataQuerier);
  102760. }
  102761. parseSync(arrayBuffer, options = {}) {
  102762. const buffer = new this.draco.DecoderBuffer();
  102763. buffer.Init(new Int8Array(arrayBuffer), arrayBuffer.byteLength);
  102764. this._disableAttributeTransforms(options);
  102765. const geometry_type = this.decoder.GetEncodedGeometryType(buffer);
  102766. const dracoGeometry = geometry_type === this.draco.TRIANGULAR_MESH ? new this.draco.Mesh() : new this.draco.PointCloud();
  102767. try {
  102768. let dracoStatus;
  102769. switch (geometry_type) {
  102770. case this.draco.TRIANGULAR_MESH:
  102771. dracoStatus = this.decoder.DecodeBufferToMesh(buffer, dracoGeometry);
  102772. break;
  102773. case this.draco.POINT_CLOUD:
  102774. dracoStatus = this.decoder.DecodeBufferToPointCloud(buffer, dracoGeometry);
  102775. break;
  102776. default:
  102777. throw new Error('DRACO: Unknown geometry type.');
  102778. }
  102779. if (!dracoStatus.ok() || !dracoGeometry.ptr) {
  102780. const message = "DRACO decompression failed: ".concat(dracoStatus.error_msg());
  102781. throw new Error(message);
  102782. }
  102783. const loaderData = this._getDracoLoaderData(dracoGeometry, geometry_type, options);
  102784. const geometry = this._getMeshData(dracoGeometry, loaderData, options);
  102785. const boundingBox = getMeshBoundingBox(geometry.attributes);
  102786. const schema = getDracoSchema(geometry.attributes, loaderData, geometry.indices);
  102787. const data = {
  102788. loader: 'draco',
  102789. loaderData,
  102790. header: {
  102791. vertexCount: dracoGeometry.num_points(),
  102792. boundingBox
  102793. },
  102794. ...geometry,
  102795. schema
  102796. };
  102797. return data;
  102798. } finally {
  102799. this.draco.destroy(buffer);
  102800. if (dracoGeometry) {
  102801. this.draco.destroy(dracoGeometry);
  102802. }
  102803. }
  102804. }
  102805. _getDracoLoaderData(dracoGeometry, geometry_type, options) {
  102806. const metadata = this._getTopLevelMetadata(dracoGeometry);
  102807. const attributes = this._getDracoAttributes(dracoGeometry, options);
  102808. return {
  102809. geometry_type,
  102810. num_attributes: dracoGeometry.num_attributes(),
  102811. num_points: dracoGeometry.num_points(),
  102812. num_faces: dracoGeometry instanceof this.draco.Mesh ? dracoGeometry.num_faces() : 0,
  102813. metadata,
  102814. attributes
  102815. };
  102816. }
  102817. _getDracoAttributes(dracoGeometry, options) {
  102818. const dracoAttributes = {};
  102819. for (let attributeId = 0; attributeId < dracoGeometry.num_attributes(); attributeId++) {
  102820. const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attributeId);
  102821. const metadata = this._getAttributeMetadata(dracoGeometry, attributeId);
  102822. dracoAttributes[dracoAttribute.unique_id()] = {
  102823. unique_id: dracoAttribute.unique_id(),
  102824. attribute_type: dracoAttribute.attribute_type(),
  102825. data_type: dracoAttribute.data_type(),
  102826. num_components: dracoAttribute.num_components(),
  102827. byte_offset: dracoAttribute.byte_offset(),
  102828. byte_stride: dracoAttribute.byte_stride(),
  102829. normalized: dracoAttribute.normalized(),
  102830. attribute_index: attributeId,
  102831. metadata
  102832. };
  102833. const quantization = this._getQuantizationTransform(dracoAttribute, options);
  102834. if (quantization) {
  102835. dracoAttributes[dracoAttribute.unique_id()].quantization_transform = quantization;
  102836. }
  102837. const octahedron = this._getOctahedronTransform(dracoAttribute, options);
  102838. if (octahedron) {
  102839. dracoAttributes[dracoAttribute.unique_id()].octahedron_transform = octahedron;
  102840. }
  102841. }
  102842. return dracoAttributes;
  102843. }
  102844. _getMeshData(dracoGeometry, loaderData, options) {
  102845. const attributes = this._getMeshAttributes(loaderData, dracoGeometry, options);
  102846. const positionAttribute = attributes.POSITION;
  102847. if (!positionAttribute) {
  102848. throw new Error('DRACO: No position attribute found.');
  102849. }
  102850. if (dracoGeometry instanceof this.draco.Mesh) {
  102851. switch (options.topology) {
  102852. case 'triangle-strip':
  102853. return {
  102854. topology: 'triangle-strip',
  102855. mode: 4,
  102856. attributes,
  102857. indices: {
  102858. value: this._getTriangleStripIndices(dracoGeometry),
  102859. size: 1
  102860. }
  102861. };
  102862. case 'triangle-list':
  102863. default:
  102864. return {
  102865. topology: 'triangle-list',
  102866. mode: 5,
  102867. attributes,
  102868. indices: {
  102869. value: this._getTriangleListIndices(dracoGeometry),
  102870. size: 1
  102871. }
  102872. };
  102873. }
  102874. }
  102875. return {
  102876. topology: 'point-list',
  102877. mode: 0,
  102878. attributes
  102879. };
  102880. }
  102881. _getMeshAttributes(loaderData, dracoGeometry, options) {
  102882. const attributes = {};
  102883. for (const loaderAttribute of Object.values(loaderData.attributes)) {
  102884. const attributeName = this._deduceAttributeName(loaderAttribute, options);
  102885. loaderAttribute.name = attributeName;
  102886. const {
  102887. value,
  102888. size
  102889. } = this._getAttributeValues(dracoGeometry, loaderAttribute);
  102890. attributes[attributeName] = {
  102891. value,
  102892. size,
  102893. byteOffset: loaderAttribute.byte_offset,
  102894. byteStride: loaderAttribute.byte_stride,
  102895. normalized: loaderAttribute.normalized
  102896. };
  102897. }
  102898. return attributes;
  102899. }
  102900. _getTriangleListIndices(dracoGeometry) {
  102901. const numFaces = dracoGeometry.num_faces();
  102902. const numIndices = numFaces * 3;
  102903. const byteLength = numIndices * INDEX_ITEM_SIZE;
  102904. const ptr = this.draco._malloc(byteLength);
  102905. try {
  102906. this.decoder.GetTrianglesUInt32Array(dracoGeometry, byteLength, ptr);
  102907. return new Uint32Array(this.draco.HEAPF32.buffer, ptr, numIndices).slice();
  102908. } finally {
  102909. this.draco._free(ptr);
  102910. }
  102911. }
  102912. _getTriangleStripIndices(dracoGeometry) {
  102913. const dracoArray = new this.draco.DracoInt32Array();
  102914. try {
  102915. this.decoder.GetTriangleStripsFromMesh(dracoGeometry, dracoArray);
  102916. return getUint32Array(dracoArray);
  102917. } finally {
  102918. this.draco.destroy(dracoArray);
  102919. }
  102920. }
  102921. _getAttributeValues(dracoGeometry, attribute) {
  102922. const TypedArrayCtor = DRACO_DATA_TYPE_TO_TYPED_ARRAY_MAP[attribute.data_type];
  102923. const numComponents = attribute.num_components;
  102924. const numPoints = dracoGeometry.num_points();
  102925. const numValues = numPoints * numComponents;
  102926. const byteLength = numValues * TypedArrayCtor.BYTES_PER_ELEMENT;
  102927. const dataType = getDracoDataType(this.draco, TypedArrayCtor);
  102928. let value;
  102929. const ptr = this.draco._malloc(byteLength);
  102930. try {
  102931. const dracoAttribute = this.decoder.GetAttribute(dracoGeometry, attribute.attribute_index);
  102932. this.decoder.GetAttributeDataArrayForAllPoints(dracoGeometry, dracoAttribute, dataType, byteLength, ptr);
  102933. value = new TypedArrayCtor(this.draco.HEAPF32.buffer, ptr, numValues).slice();
  102934. } finally {
  102935. this.draco._free(ptr);
  102936. }
  102937. return {
  102938. value,
  102939. size: numComponents
  102940. };
  102941. }
  102942. _deduceAttributeName(attribute, options) {
  102943. const uniqueId = attribute.unique_id;
  102944. for (const [attributeName, attributeUniqueId] of Object.entries(options.extraAttributes || {})) {
  102945. if (attributeUniqueId === uniqueId) {
  102946. return attributeName;
  102947. }
  102948. }
  102949. const thisAttributeType = attribute.attribute_type;
  102950. for (const dracoAttributeConstant in DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP) {
  102951. const attributeType = this.draco[dracoAttributeConstant];
  102952. if (attributeType === thisAttributeType) {
  102953. return DRACO_TO_GLTF_ATTRIBUTE_NAME_MAP[dracoAttributeConstant];
  102954. }
  102955. }
  102956. const entryName = options.attributeNameEntry || 'name';
  102957. if (attribute.metadata[entryName]) {
  102958. return attribute.metadata[entryName].string;
  102959. }
  102960. return "CUSTOM_ATTRIBUTE_".concat(uniqueId);
  102961. }
  102962. _getTopLevelMetadata(dracoGeometry) {
  102963. const dracoMetadata = this.decoder.GetMetadata(dracoGeometry);
  102964. return this._getDracoMetadata(dracoMetadata);
  102965. }
  102966. _getAttributeMetadata(dracoGeometry, attributeId) {
  102967. const dracoMetadata = this.decoder.GetAttributeMetadata(dracoGeometry, attributeId);
  102968. return this._getDracoMetadata(dracoMetadata);
  102969. }
  102970. _getDracoMetadata(dracoMetadata) {
  102971. if (!dracoMetadata || !dracoMetadata.ptr) {
  102972. return {};
  102973. }
  102974. const result = {};
  102975. const numEntries = this.metadataQuerier.NumEntries(dracoMetadata);
  102976. for (let entryIndex = 0; entryIndex < numEntries; entryIndex++) {
  102977. const entryName = this.metadataQuerier.GetEntryName(dracoMetadata, entryIndex);
  102978. result[entryName] = this._getDracoMetadataField(dracoMetadata, entryName);
  102979. }
  102980. return result;
  102981. }
  102982. _getDracoMetadataField(dracoMetadata, entryName) {
  102983. const dracoArray = new this.draco.DracoInt32Array();
  102984. try {
  102985. this.metadataQuerier.GetIntEntryArray(dracoMetadata, entryName, dracoArray);
  102986. const intArray = getInt32Array(dracoArray);
  102987. return {
  102988. int: this.metadataQuerier.GetIntEntry(dracoMetadata, entryName),
  102989. string: this.metadataQuerier.GetStringEntry(dracoMetadata, entryName),
  102990. double: this.metadataQuerier.GetDoubleEntry(dracoMetadata, entryName),
  102991. intArray
  102992. };
  102993. } finally {
  102994. this.draco.destroy(dracoArray);
  102995. }
  102996. }
  102997. _disableAttributeTransforms(options) {
  102998. const {
  102999. quantizedAttributes = [],
  103000. octahedronAttributes = []
  103001. } = options;
  103002. const skipAttributes = [...quantizedAttributes, ...octahedronAttributes];
  103003. for (const dracoAttributeName of skipAttributes) {
  103004. this.decoder.SkipAttributeTransform(this.draco[dracoAttributeName]);
  103005. }
  103006. }
  103007. _getQuantizationTransform(dracoAttribute, options) {
  103008. const {
  103009. quantizedAttributes = []
  103010. } = options;
  103011. const attribute_type = dracoAttribute.attribute_type();
  103012. const skip = quantizedAttributes.map(type => this.decoder[type]).includes(attribute_type);
  103013. if (skip) {
  103014. const transform = new this.draco.AttributeQuantizationTransform();
  103015. try {
  103016. if (transform.InitFromAttribute(dracoAttribute)) {
  103017. return {
  103018. quantization_bits: transform.quantization_bits(),
  103019. range: transform.range(),
  103020. min_values: new Float32Array([1, 2, 3]).map(i => transform.min_value(i))
  103021. };
  103022. }
  103023. } finally {
  103024. this.draco.destroy(transform);
  103025. }
  103026. }
  103027. return null;
  103028. }
  103029. _getOctahedronTransform(dracoAttribute, options) {
  103030. const {
  103031. octahedronAttributes = []
  103032. } = options;
  103033. const attribute_type = dracoAttribute.attribute_type();
  103034. const octahedron = octahedronAttributes.map(type => this.decoder[type]).includes(attribute_type);
  103035. if (octahedron) {
  103036. const transform = new this.draco.AttributeQuantizationTransform();
  103037. try {
  103038. if (transform.InitFromAttribute(dracoAttribute)) {
  103039. return {
  103040. quantization_bits: transform.quantization_bits()
  103041. };
  103042. }
  103043. } finally {
  103044. this.draco.destroy(transform);
  103045. }
  103046. }
  103047. return null;
  103048. }
  103049. }
  103050. function getDracoDataType(draco, attributeType) {
  103051. switch (attributeType) {
  103052. case Float32Array:
  103053. return draco.DT_FLOAT32;
  103054. case Int8Array:
  103055. return draco.DT_INT8;
  103056. case Int16Array:
  103057. return draco.DT_INT16;
  103058. case Int32Array:
  103059. return draco.DT_INT32;
  103060. case Uint8Array:
  103061. return draco.DT_UINT8;
  103062. case Uint16Array:
  103063. return draco.DT_UINT16;
  103064. case Uint32Array:
  103065. return draco.DT_UINT32;
  103066. default:
  103067. return draco.DT_INVALID;
  103068. }
  103069. }
  103070. function getInt32Array(dracoArray) {
  103071. const numValues = dracoArray.size();
  103072. const intArray = new Int32Array(numValues);
  103073. for (let i = 0; i < numValues; i++) {
  103074. intArray[i] = dracoArray.GetValue(i);
  103075. }
  103076. return intArray;
  103077. }
  103078. function getUint32Array(dracoArray) {
  103079. const numValues = dracoArray.size();
  103080. const intArray = new Int32Array(numValues);
  103081. for (let i = 0; i < numValues; i++) {
  103082. intArray[i] = dracoArray.GetValue(i);
  103083. }
  103084. return intArray;
  103085. }
  103086. const DRACO_VERSION = '1.4.1';
  103087. const DRACO_JS_DECODER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_decoder.js");
  103088. const DRACO_WASM_WRAPPER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_wasm_wrapper.js");
  103089. const DRACO_WASM_DECODER_URL = "https://www.gstatic.com/draco/versioned/decoders/".concat(DRACO_VERSION, "/draco_decoder.wasm");
  103090. let loadDecoderPromise;
  103091. async function loadDracoDecoderModule(options) {
  103092. const modules = options.modules || {};
  103093. if (modules.draco3d) {
  103094. loadDecoderPromise = loadDecoderPromise || modules.draco3d.createDecoderModule({}).then(draco => {
  103095. return {
  103096. draco
  103097. };
  103098. });
  103099. } else {
  103100. loadDecoderPromise = loadDecoderPromise || loadDracoDecoder(options);
  103101. }
  103102. return await loadDecoderPromise;
  103103. }
  103104. async function loadDracoDecoder(options) {
  103105. let DracoDecoderModule;
  103106. let wasmBinary;
  103107. switch (options.draco && options.draco.decoderType) {
  103108. case 'js':
  103109. DracoDecoderModule = await loadLibrary(DRACO_JS_DECODER_URL, 'draco', options);
  103110. break;
  103111. case 'wasm':
  103112. default:
  103113. [DracoDecoderModule, wasmBinary] = await Promise.all([await loadLibrary(DRACO_WASM_WRAPPER_URL, 'draco', options), await loadLibrary(DRACO_WASM_DECODER_URL, 'draco', options)]);
  103114. }
  103115. DracoDecoderModule = DracoDecoderModule || globalThis.DracoDecoderModule;
  103116. return await initializeDracoDecoder(DracoDecoderModule, wasmBinary);
  103117. }
  103118. function initializeDracoDecoder(DracoDecoderModule, wasmBinary) {
  103119. const options = {};
  103120. if (wasmBinary) {
  103121. options.wasmBinary = wasmBinary;
  103122. }
  103123. return new Promise(resolve => {
  103124. DracoDecoderModule({ ...options,
  103125. onModuleLoaded: draco => resolve({
  103126. draco
  103127. })
  103128. });
  103129. });
  103130. }
  103131. const DracoLoader = { ...DracoLoader$1,
  103132. parse: parse$2
  103133. };
  103134. async function parse$2(arrayBuffer, options) {
  103135. const {
  103136. draco
  103137. } = await loadDracoDecoderModule(options);
  103138. const dracoParser = new DracoParser(draco);
  103139. try {
  103140. return dracoParser.parseSync(arrayBuffer, options === null || options === void 0 ? void 0 : options.draco);
  103141. } finally {
  103142. dracoParser.destroy();
  103143. }
  103144. }
  103145. const GL_PRIMITIVE_MODE = {
  103146. POINTS: 0x0000,
  103147. LINES: 0x0001,
  103148. LINE_LOOP: 0x0002,
  103149. LINE_STRIP: 0x0003,
  103150. TRIANGLES: 0x0004,
  103151. TRIANGLE_STRIP: 0x0005,
  103152. TRIANGLE_FAN: 0x0006
  103153. };
  103154. const GL_TYPE = {
  103155. BYTE: 5120,
  103156. UNSIGNED_BYTE: 5121,
  103157. SHORT: 5122,
  103158. UNSIGNED_SHORT: 5123,
  103159. INT: 5124,
  103160. UNSIGNED_INT: 5125,
  103161. FLOAT: 5126,
  103162. DOUBLE: 5130
  103163. };
  103164. const GL$1 = { ...GL_PRIMITIVE_MODE,
  103165. ...GL_TYPE
  103166. };
  103167. const GL_TYPE_TO_ARRAY_TYPE = {
  103168. [GL_TYPE.DOUBLE]: Float64Array,
  103169. [GL_TYPE.FLOAT]: Float32Array,
  103170. [GL_TYPE.UNSIGNED_SHORT]: Uint16Array,
  103171. [GL_TYPE.UNSIGNED_INT]: Uint32Array,
  103172. [GL_TYPE.UNSIGNED_BYTE]: Uint8Array,
  103173. [GL_TYPE.BYTE]: Int8Array,
  103174. [GL_TYPE.SHORT]: Int16Array,
  103175. [GL_TYPE.INT]: Int32Array
  103176. };
  103177. const NAME_TO_GL_TYPE = {
  103178. DOUBLE: GL_TYPE.DOUBLE,
  103179. FLOAT: GL_TYPE.FLOAT,
  103180. UNSIGNED_SHORT: GL_TYPE.UNSIGNED_SHORT,
  103181. UNSIGNED_INT: GL_TYPE.UNSIGNED_INT,
  103182. UNSIGNED_BYTE: GL_TYPE.UNSIGNED_BYTE,
  103183. BYTE: GL_TYPE.BYTE,
  103184. SHORT: GL_TYPE.SHORT,
  103185. INT: GL_TYPE.INT
  103186. };
  103187. const ERR_TYPE_CONVERSION = 'Failed to convert GL type';
  103188. class GLType {
  103189. static fromTypedArray(arrayOrType) {
  103190. arrayOrType = ArrayBuffer.isView(arrayOrType) ? arrayOrType.constructor : arrayOrType;
  103191. for (const glType in GL_TYPE_TO_ARRAY_TYPE) {
  103192. const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
  103193. if (ArrayType === arrayOrType) {
  103194. return glType;
  103195. }
  103196. }
  103197. throw new Error(ERR_TYPE_CONVERSION);
  103198. }
  103199. static fromName(name) {
  103200. const glType = NAME_TO_GL_TYPE[name];
  103201. if (!glType) {
  103202. throw new Error(ERR_TYPE_CONVERSION);
  103203. }
  103204. return glType;
  103205. }
  103206. static getArrayType(glType) {
  103207. switch (glType) {
  103208. case GL_TYPE.UNSIGNED_SHORT_5_6_5:
  103209. case GL_TYPE.UNSIGNED_SHORT_4_4_4_4:
  103210. case GL_TYPE.UNSIGNED_SHORT_5_5_5_1:
  103211. return Uint16Array;
  103212. default:
  103213. const ArrayType = GL_TYPE_TO_ARRAY_TYPE[glType];
  103214. if (!ArrayType) {
  103215. throw new Error(ERR_TYPE_CONVERSION);
  103216. }
  103217. return ArrayType;
  103218. }
  103219. }
  103220. static getByteSize(glType) {
  103221. const ArrayType = GLType.getArrayType(glType);
  103222. return ArrayType.BYTES_PER_ELEMENT;
  103223. }
  103224. static validate(glType) {
  103225. return Boolean(GLType.getArrayType(glType));
  103226. }
  103227. static createTypedArray(glType, buffer, byteOffset = 0, length) {
  103228. if (length === undefined) {
  103229. length = (buffer.byteLength - byteOffset) / GLType.getByteSize(glType);
  103230. }
  103231. const ArrayType = GLType.getArrayType(glType);
  103232. return new ArrayType(buffer, byteOffset, length);
  103233. }
  103234. }
  103235. function assert$2(condition, message) {
  103236. if (!condition) {
  103237. throw new Error("math.gl assertion failed. ".concat(message));
  103238. }
  103239. }
  103240. function decodeRGB565(rgb565, target = [0, 0, 0]) {
  103241. const r5 = rgb565 >> 11 & 31;
  103242. const g6 = rgb565 >> 5 & 63;
  103243. const b5 = rgb565 & 31;
  103244. target[0] = r5 << 3;
  103245. target[1] = g6 << 2;
  103246. target[2] = b5 << 3;
  103247. return target;
  103248. }
  103249. new Vector2$1();
  103250. new Vector3$1();
  103251. new Vector2$1();
  103252. new Vector2$1();
  103253. function fromSNorm(value, rangeMaximum = 255) {
  103254. return clamp(value, 0.0, rangeMaximum) / rangeMaximum * 2.0 - 1.0;
  103255. }
  103256. function signNotZero(value) {
  103257. return value < 0.0 ? -1.0 : 1.0;
  103258. }
  103259. function octDecodeInRange(x, y, rangeMax, result) {
  103260. assert$2(result);
  103261. if (x < 0 || x > rangeMax || y < 0 || y > rangeMax) {
  103262. throw new Error("x and y must be unsigned normalized integers between 0 and ".concat(rangeMax));
  103263. }
  103264. result.x = fromSNorm(x, rangeMax);
  103265. result.y = fromSNorm(y, rangeMax);
  103266. result.z = 1.0 - (Math.abs(result.x) + Math.abs(result.y));
  103267. if (result.z < 0.0) {
  103268. const oldVX = result.x;
  103269. result.x = (1.0 - Math.abs(result.y)) * signNotZero(oldVX);
  103270. result.y = (1.0 - Math.abs(oldVX)) * signNotZero(result.y);
  103271. }
  103272. return result.normalize();
  103273. }
  103274. function octDecode(x, y, result) {
  103275. return octDecodeInRange(x, y, 255, result);
  103276. }
  103277. class Tile3DFeatureTable {
  103278. constructor(featureTableJson, featureTableBinary) {
  103279. _defineProperty(this, "json", void 0);
  103280. _defineProperty(this, "buffer", void 0);
  103281. _defineProperty(this, "featuresLength", 0);
  103282. _defineProperty(this, "_cachedTypedArrays", {});
  103283. this.json = featureTableJson;
  103284. this.buffer = featureTableBinary;
  103285. }
  103286. getExtension(extensionName) {
  103287. return this.json.extensions && this.json.extensions[extensionName];
  103288. }
  103289. hasProperty(propertyName) {
  103290. return Boolean(this.json[propertyName]);
  103291. }
  103292. getGlobalProperty(propertyName, componentType = GL$1.UNSIGNED_INT, componentLength = 1) {
  103293. const jsonValue = this.json[propertyName];
  103294. if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
  103295. return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, 1, jsonValue.byteOffset);
  103296. }
  103297. return jsonValue;
  103298. }
  103299. getPropertyArray(propertyName, componentType, componentLength) {
  103300. const jsonValue = this.json[propertyName];
  103301. if (jsonValue && Number.isFinite(jsonValue.byteOffset)) {
  103302. if ('componentType' in jsonValue) {
  103303. componentType = GLType.fromName(jsonValue.componentType);
  103304. }
  103305. return this._getTypedArrayFromBinary(propertyName, componentType, componentLength, this.featuresLength, jsonValue.byteOffset);
  103306. }
  103307. return this._getTypedArrayFromArray(propertyName, componentType, jsonValue);
  103308. }
  103309. getProperty(propertyName, componentType, componentLength, featureId, result) {
  103310. const jsonValue = this.json[propertyName];
  103311. if (!jsonValue) {
  103312. return jsonValue;
  103313. }
  103314. const typedArray = this.getPropertyArray(propertyName, componentType, componentLength);
  103315. if (componentLength === 1) {
  103316. return typedArray[featureId];
  103317. }
  103318. for (let i = 0; i < componentLength; ++i) {
  103319. result[i] = typedArray[componentLength * featureId + i];
  103320. }
  103321. return result;
  103322. }
  103323. _getTypedArrayFromBinary(propertyName, componentType, componentLength, count, byteOffset) {
  103324. const cachedTypedArrays = this._cachedTypedArrays;
  103325. let typedArray = cachedTypedArrays[propertyName];
  103326. if (!typedArray) {
  103327. typedArray = GLType.createTypedArray(componentType, this.buffer.buffer, this.buffer.byteOffset + byteOffset, count * componentLength);
  103328. cachedTypedArrays[propertyName] = typedArray;
  103329. }
  103330. return typedArray;
  103331. }
  103332. _getTypedArrayFromArray(propertyName, componentType, array) {
  103333. const cachedTypedArrays = this._cachedTypedArrays;
  103334. let typedArray = cachedTypedArrays[propertyName];
  103335. if (!typedArray) {
  103336. typedArray = GLType.createTypedArray(componentType, array);
  103337. cachedTypedArrays[propertyName] = typedArray;
  103338. }
  103339. return typedArray;
  103340. }
  103341. }
  103342. const COMPONENTS_PER_ATTRIBUTE = {
  103343. SCALAR: 1,
  103344. VEC2: 2,
  103345. VEC3: 3,
  103346. VEC4: 4,
  103347. MAT2: 4,
  103348. MAT3: 9,
  103349. MAT4: 16
  103350. };
  103351. const UNPACKER = {
  103352. SCALAR: (values, i) => values[i],
  103353. VEC2: (values, i) => [values[2 * i + 0], values[2 * i + 1]],
  103354. VEC3: (values, i) => [values[3 * i + 0], values[3 * i + 1], values[3 * i + 2]],
  103355. VEC4: (values, i) => [values[4 * i + 0], values[4 * i + 1], values[4 * i + 2], values[4 * i + 3]],
  103356. MAT2: (values, i) => [values[4 * i + 0], values[4 * i + 1], values[4 * i + 2], values[4 * i + 3]],
  103357. 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]],
  103358. 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]]
  103359. };
  103360. const PACKER = {
  103361. SCALAR: (x, values, i) => {
  103362. values[i] = x;
  103363. },
  103364. VEC2: (x, values, i) => {
  103365. values[2 * i + 0] = x[0];
  103366. values[2 * i + 1] = x[1];
  103367. },
  103368. VEC3: (x, values, i) => {
  103369. values[3 * i + 0] = x[0];
  103370. values[3 * i + 1] = x[1];
  103371. values[3 * i + 2] = x[2];
  103372. },
  103373. VEC4: (x, values, i) => {
  103374. values[4 * i + 0] = x[0];
  103375. values[4 * i + 1] = x[1];
  103376. values[4 * i + 2] = x[2];
  103377. values[4 * i + 3] = x[3];
  103378. },
  103379. MAT2: (x, values, i) => {
  103380. values[4 * i + 0] = x[0];
  103381. values[4 * i + 1] = x[1];
  103382. values[4 * i + 2] = x[2];
  103383. values[4 * i + 3] = x[3];
  103384. },
  103385. MAT3: (x, values, i) => {
  103386. values[9 * i + 0] = x[0];
  103387. values[9 * i + 1] = x[1];
  103388. values[9 * i + 2] = x[2];
  103389. values[9 * i + 3] = x[3];
  103390. values[9 * i + 4] = x[4];
  103391. values[9 * i + 5] = x[5];
  103392. values[9 * i + 6] = x[6];
  103393. values[9 * i + 7] = x[7];
  103394. values[9 * i + 8] = x[8];
  103395. values[9 * i + 9] = x[9];
  103396. },
  103397. MAT4: (x, values, i) => {
  103398. values[16 * i + 0] = x[0];
  103399. values[16 * i + 1] = x[1];
  103400. values[16 * i + 2] = x[2];
  103401. values[16 * i + 3] = x[3];
  103402. values[16 * i + 4] = x[4];
  103403. values[16 * i + 5] = x[5];
  103404. values[16 * i + 6] = x[6];
  103405. values[16 * i + 7] = x[7];
  103406. values[16 * i + 8] = x[8];
  103407. values[16 * i + 9] = x[9];
  103408. values[16 * i + 10] = x[10];
  103409. values[16 * i + 11] = x[11];
  103410. values[16 * i + 12] = x[12];
  103411. values[16 * i + 13] = x[13];
  103412. values[16 * i + 14] = x[14];
  103413. values[16 * i + 15] = x[15];
  103414. }
  103415. };
  103416. function createTypedArrayFromAccessor(tile3DAccessor, buffer, byteOffset, length) {
  103417. const {
  103418. componentType
  103419. } = tile3DAccessor;
  103420. assert$7(tile3DAccessor.componentType);
  103421. const type = typeof componentType === 'string' ? GLType.fromName(componentType) : componentType;
  103422. const size = COMPONENTS_PER_ATTRIBUTE[tile3DAccessor.type];
  103423. const unpacker = UNPACKER[tile3DAccessor.type];
  103424. const packer = PACKER[tile3DAccessor.type];
  103425. byteOffset += tile3DAccessor.byteOffset;
  103426. const values = GLType.createTypedArray(type, buffer, byteOffset, size * length);
  103427. return {
  103428. values,
  103429. type,
  103430. size,
  103431. unpacker,
  103432. packer
  103433. };
  103434. }
  103435. const defined$1 = x => x !== undefined;
  103436. function initializeHierarchy(batchTable, jsonHeader, binaryBody) {
  103437. if (!jsonHeader) {
  103438. return null;
  103439. }
  103440. let hierarchy = batchTable.getExtension('3DTILES_batch_table_hierarchy');
  103441. const legacyHierarchy = jsonHeader.HIERARCHY;
  103442. if (legacyHierarchy) {
  103443. console.warn('3D Tile Parser: HIERARCHY is deprecated. Use 3DTILES_batch_table_hierarchy.');
  103444. jsonHeader.extensions = jsonHeader.extensions || {};
  103445. jsonHeader.extensions['3DTILES_batch_table_hierarchy'] = legacyHierarchy;
  103446. hierarchy = legacyHierarchy;
  103447. }
  103448. if (!hierarchy) {
  103449. return null;
  103450. }
  103451. return initializeHierarchyValues(hierarchy, binaryBody);
  103452. }
  103453. function initializeHierarchyValues(hierarchyJson, binaryBody) {
  103454. let i;
  103455. let classId;
  103456. let binaryAccessor;
  103457. const instancesLength = hierarchyJson.instancesLength;
  103458. const classes = hierarchyJson.classes;
  103459. let classIds = hierarchyJson.classIds;
  103460. let parentCounts = hierarchyJson.parentCounts;
  103461. let parentIds = hierarchyJson.parentIds;
  103462. let parentIdsLength = instancesLength;
  103463. if (defined$1(classIds.byteOffset)) {
  103464. classIds.componentType = defaultValue(classIds.componentType, GL.UNSIGNED_SHORT);
  103465. classIds.type = AttributeType.SCALAR;
  103466. binaryAccessor = getBinaryAccessor(classIds);
  103467. classIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + classIds.byteOffset, instancesLength);
  103468. }
  103469. let parentIndexes;
  103470. if (defined$1(parentCounts)) {
  103471. if (defined$1(parentCounts.byteOffset)) {
  103472. parentCounts.componentType = defaultValue(parentCounts.componentType, GL.UNSIGNED_SHORT);
  103473. parentCounts.type = AttributeType.SCALAR;
  103474. binaryAccessor = getBinaryAccessor(parentCounts);
  103475. parentCounts = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentCounts.byteOffset, instancesLength);
  103476. }
  103477. parentIndexes = new Uint16Array(instancesLength);
  103478. parentIdsLength = 0;
  103479. for (i = 0; i < instancesLength; ++i) {
  103480. parentIndexes[i] = parentIdsLength;
  103481. parentIdsLength += parentCounts[i];
  103482. }
  103483. }
  103484. if (defined$1(parentIds) && defined$1(parentIds.byteOffset)) {
  103485. parentIds.componentType = defaultValue(parentIds.componentType, GL.UNSIGNED_SHORT);
  103486. parentIds.type = AttributeType.SCALAR;
  103487. binaryAccessor = getBinaryAccessor(parentIds);
  103488. parentIds = binaryAccessor.createArrayBufferView(binaryBody.buffer, binaryBody.byteOffset + parentIds.byteOffset, parentIdsLength);
  103489. }
  103490. const classesLength = classes.length;
  103491. for (i = 0; i < classesLength; ++i) {
  103492. const classInstancesLength = classes[i].length;
  103493. const properties = classes[i].instances;
  103494. const binaryProperties = getBinaryProperties(classInstancesLength, properties, binaryBody);
  103495. classes[i].instances = combine(binaryProperties, properties);
  103496. }
  103497. const classCounts = new Array(classesLength).fill(0);
  103498. const classIndexes = new Uint16Array(instancesLength);
  103499. for (i = 0; i < instancesLength; ++i) {
  103500. classId = classIds[i];
  103501. classIndexes[i] = classCounts[classId];
  103502. ++classCounts[classId];
  103503. }
  103504. const hierarchy = {
  103505. classes,
  103506. classIds,
  103507. classIndexes,
  103508. parentCounts,
  103509. parentIndexes,
  103510. parentIds
  103511. };
  103512. validateHierarchy(hierarchy);
  103513. return hierarchy;
  103514. }
  103515. function traverseHierarchy(hierarchy, instanceIndex, endConditionCallback) {
  103516. if (!hierarchy) {
  103517. return;
  103518. }
  103519. const parentCounts = hierarchy.parentCounts;
  103520. const parentIds = hierarchy.parentIds;
  103521. if (parentIds) {
  103522. return endConditionCallback(hierarchy, instanceIndex);
  103523. }
  103524. if (parentCounts > 0) {
  103525. return traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback);
  103526. }
  103527. return traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback);
  103528. }
  103529. function traverseHierarchyMultipleParents(hierarchy, instanceIndex, endConditionCallback) {
  103530. const classIds = hierarchy.classIds;
  103531. const parentCounts = hierarchy.parentCounts;
  103532. const parentIds = hierarchy.parentIds;
  103533. const parentIndexes = hierarchy.parentIndexes;
  103534. const instancesLength = classIds.length;
  103535. const visited = scratchVisited;
  103536. visited.length = Math.max(visited.length, instancesLength);
  103537. const visitedMarker = ++marker;
  103538. const stack = scratchStack;
  103539. stack.length = 0;
  103540. stack.push(instanceIndex);
  103541. while (stack.length > 0) {
  103542. instanceIndex = stack.pop();
  103543. if (visited[instanceIndex] === visitedMarker) {
  103544. continue;
  103545. }
  103546. visited[instanceIndex] = visitedMarker;
  103547. const result = endConditionCallback(hierarchy, instanceIndex);
  103548. if (defined$1(result)) {
  103549. return result;
  103550. }
  103551. const parentCount = parentCounts[instanceIndex];
  103552. const parentIndex = parentIndexes[instanceIndex];
  103553. for (let i = 0; i < parentCount; ++i) {
  103554. const parentId = parentIds[parentIndex + i];
  103555. if (parentId !== instanceIndex) {
  103556. stack.push(parentId);
  103557. }
  103558. }
  103559. }
  103560. return null;
  103561. }
  103562. function traverseHierarchySingleParent(hierarchy, instanceIndex, endConditionCallback) {
  103563. let hasParent = true;
  103564. while (hasParent) {
  103565. const result = endConditionCallback(hierarchy, instanceIndex);
  103566. if (defined$1(result)) {
  103567. return result;
  103568. }
  103569. const parentId = hierarchy.parentIds[instanceIndex];
  103570. hasParent = parentId !== instanceIndex;
  103571. instanceIndex = parentId;
  103572. }
  103573. throw new Error('traverseHierarchySingleParent');
  103574. }
  103575. function validateHierarchy(hierarchy) {
  103576. const classIds = hierarchy.classIds;
  103577. const instancesLength = classIds.length;
  103578. for (let i = 0; i < instancesLength; ++i) {
  103579. validateInstance(hierarchy, i, stack);
  103580. }
  103581. }
  103582. function validateInstance(hierarchy, instanceIndex, stack) {
  103583. const parentCounts = hierarchy.parentCounts;
  103584. const parentIds = hierarchy.parentIds;
  103585. const parentIndexes = hierarchy.parentIndexes;
  103586. const classIds = hierarchy.classIds;
  103587. const instancesLength = classIds.length;
  103588. if (!defined$1(parentIds)) {
  103589. return;
  103590. }
  103591. assert(instanceIndex < instancesLength, "Parent index ".concat(instanceIndex, " exceeds the total number of instances: ").concat(instancesLength));
  103592. assert(stack.indexOf(instanceIndex) === -1, 'Circular dependency detected in the batch table hierarchy.');
  103593. stack.push(instanceIndex);
  103594. const parentCount = defined$1(parentCounts) ? parentCounts[instanceIndex] : 1;
  103595. const parentIndex = defined$1(parentCounts) ? parentIndexes[instanceIndex] : instanceIndex;
  103596. for (let i = 0; i < parentCount; ++i) {
  103597. const parentId = parentIds[parentIndex + i];
  103598. if (parentId !== instanceIndex) {
  103599. validateInstance(hierarchy, parentId, stack);
  103600. }
  103601. }
  103602. stack.pop(instanceIndex);
  103603. }
  103604. function defined(x) {
  103605. return x !== undefined && x !== null;
  103606. }
  103607. const clone = (x, y) => x;
  103608. const IGNORED_PROPERTY_FIELDS = {
  103609. HIERARCHY: true,
  103610. extensions: true,
  103611. extras: true
  103612. };
  103613. class Tile3DBatchTableParser {
  103614. constructor(json, binary, featureCount, options = {}) {
  103615. var _this$json;
  103616. _defineProperty(this, "json", void 0);
  103617. _defineProperty(this, "binary", void 0);
  103618. _defineProperty(this, "featureCount", void 0);
  103619. _defineProperty(this, "_extensions", void 0);
  103620. _defineProperty(this, "_properties", void 0);
  103621. _defineProperty(this, "_binaryProperties", void 0);
  103622. _defineProperty(this, "_hierarchy", void 0);
  103623. assert$7(featureCount >= 0);
  103624. this.json = json || {};
  103625. this.binary = binary;
  103626. this.featureCount = featureCount;
  103627. this._extensions = ((_this$json = this.json) === null || _this$json === void 0 ? void 0 : _this$json.extensions) || {};
  103628. this._properties = {};
  103629. for (const propertyName in this.json) {
  103630. if (!IGNORED_PROPERTY_FIELDS[propertyName]) {
  103631. this._properties[propertyName] = this.json[propertyName];
  103632. }
  103633. }
  103634. this._binaryProperties = this._initializeBinaryProperties();
  103635. if (options['3DTILES_batch_table_hierarchy']) {
  103636. this._hierarchy = initializeHierarchy(this, this.json, this.binary);
  103637. }
  103638. }
  103639. getExtension(extensionName) {
  103640. return this.json && this.json.extensions && this.json.extensions[extensionName];
  103641. }
  103642. memorySizeInBytes() {
  103643. return 0;
  103644. }
  103645. isClass(batchId, className) {
  103646. this._checkBatchId(batchId);
  103647. assert$7(typeof className === 'string', className);
  103648. if (this._hierarchy) {
  103649. const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
  103650. const classId = hierarchy.classIds[instanceIndex];
  103651. const instanceClass = hierarchy.classes[classId];
  103652. return instanceClass.name === className;
  103653. });
  103654. return defined(result);
  103655. }
  103656. return false;
  103657. }
  103658. isExactClass(batchId, className) {
  103659. assert$7(typeof className === 'string', className);
  103660. return this.getExactClassName(batchId) === className;
  103661. }
  103662. getExactClassName(batchId) {
  103663. this._checkBatchId(batchId);
  103664. if (this._hierarchy) {
  103665. const classId = this._hierarchy.classIds[batchId];
  103666. const instanceClass = this._hierarchy.classes[classId];
  103667. return instanceClass.name;
  103668. }
  103669. return undefined;
  103670. }
  103671. hasProperty(batchId, name) {
  103672. this._checkBatchId(batchId);
  103673. assert$7(typeof name === 'string', name);
  103674. return defined(this._properties[name]) || this._hasPropertyInHierarchy(batchId, name);
  103675. }
  103676. getPropertyNames(batchId, results) {
  103677. this._checkBatchId(batchId);
  103678. results = defined(results) ? results : [];
  103679. results.length = 0;
  103680. const propertyNames = Object.keys(this._properties);
  103681. results.push(...propertyNames);
  103682. if (this._hierarchy) {
  103683. this._getPropertyNamesInHierarchy(batchId, results);
  103684. }
  103685. return results;
  103686. }
  103687. getProperty(batchId, name) {
  103688. this._checkBatchId(batchId);
  103689. assert$7(typeof name === 'string', name);
  103690. if (this._binaryProperties) {
  103691. const binaryProperty = this._binaryProperties[name];
  103692. if (defined(binaryProperty)) {
  103693. return this._getBinaryProperty(binaryProperty, batchId);
  103694. }
  103695. }
  103696. const propertyValues = this._properties[name];
  103697. if (defined(propertyValues)) {
  103698. return clone(propertyValues[batchId]);
  103699. }
  103700. if (this._hierarchy) {
  103701. const hierarchyProperty = this._getHierarchyProperty(batchId, name);
  103702. if (defined(hierarchyProperty)) {
  103703. return hierarchyProperty;
  103704. }
  103705. }
  103706. return undefined;
  103707. }
  103708. setProperty(batchId, name, value) {
  103709. const featureCount = this.featureCount;
  103710. this._checkBatchId(batchId);
  103711. assert$7(typeof name === 'string', name);
  103712. if (this._binaryProperties) {
  103713. const binaryProperty = this._binaryProperties[name];
  103714. if (binaryProperty) {
  103715. this._setBinaryProperty(binaryProperty, batchId, value);
  103716. return;
  103717. }
  103718. }
  103719. if (this._hierarchy) {
  103720. if (this._setHierarchyProperty(this, batchId, name, value)) {
  103721. return;
  103722. }
  103723. }
  103724. let propertyValues = this._properties[name];
  103725. if (!defined(propertyValues)) {
  103726. this._properties[name] = new Array(featureCount);
  103727. propertyValues = this._properties[name];
  103728. }
  103729. propertyValues[batchId] = clone(value);
  103730. }
  103731. _checkBatchId(batchId) {
  103732. const valid = batchId >= 0 && batchId < this.featureCount;
  103733. if (!valid) {
  103734. throw new Error('batchId not in range [0, featureCount - 1].');
  103735. }
  103736. }
  103737. _getBinaryProperty(binaryProperty, index) {
  103738. return binaryProperty.unpack(binaryProperty.typedArray, index);
  103739. }
  103740. _setBinaryProperty(binaryProperty, index, value) {
  103741. binaryProperty.pack(value, binaryProperty.typedArray, index);
  103742. }
  103743. _initializeBinaryProperties() {
  103744. let binaryProperties = null;
  103745. for (const name in this._properties) {
  103746. const property = this._properties[name];
  103747. const binaryProperty = this._initializeBinaryProperty(name, property);
  103748. if (binaryProperty) {
  103749. binaryProperties = binaryProperties || {};
  103750. binaryProperties[name] = binaryProperty;
  103751. }
  103752. }
  103753. return binaryProperties;
  103754. }
  103755. _initializeBinaryProperty(name, property) {
  103756. if ('byteOffset' in property) {
  103757. const tile3DAccessor = property;
  103758. assert$7(this.binary, "Property ".concat(name, " requires a batch table binary."));
  103759. assert$7(tile3DAccessor.type, "Property ".concat(name, " requires a type."));
  103760. const accessor = createTypedArrayFromAccessor(tile3DAccessor, this.binary.buffer, this.binary.byteOffset | 0, this.featureCount);
  103761. return {
  103762. typedArray: accessor.values,
  103763. componentCount: accessor.size,
  103764. unpack: accessor.unpacker,
  103765. pack: accessor.packer
  103766. };
  103767. }
  103768. return null;
  103769. }
  103770. _hasPropertyInHierarchy(batchId, name) {
  103771. if (!this._hierarchy) {
  103772. return false;
  103773. }
  103774. const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
  103775. const classId = hierarchy.classIds[instanceIndex];
  103776. const instances = hierarchy.classes[classId].instances;
  103777. return defined(instances[name]);
  103778. });
  103779. return defined(result);
  103780. }
  103781. _getPropertyNamesInHierarchy(batchId, results) {
  103782. traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
  103783. const classId = hierarchy.classIds[instanceIndex];
  103784. const instances = hierarchy.classes[classId].instances;
  103785. for (const name in instances) {
  103786. if (instances.hasOwnProperty(name)) {
  103787. if (results.indexOf(name) === -1) {
  103788. results.push(name);
  103789. }
  103790. }
  103791. }
  103792. });
  103793. }
  103794. _getHierarchyProperty(batchId, name) {
  103795. return traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
  103796. const classId = hierarchy.classIds[instanceIndex];
  103797. const instanceClass = hierarchy.classes[classId];
  103798. const indexInClass = hierarchy.classIndexes[instanceIndex];
  103799. const propertyValues = instanceClass.instances[name];
  103800. if (defined(propertyValues)) {
  103801. if (defined(propertyValues.typedArray)) {
  103802. return this._getBinaryProperty(propertyValues, indexInClass);
  103803. }
  103804. return clone(propertyValues[indexInClass]);
  103805. }
  103806. return null;
  103807. });
  103808. }
  103809. _setHierarchyProperty(batchTable, batchId, name, value) {
  103810. const result = traverseHierarchy(this._hierarchy, batchId, (hierarchy, instanceIndex) => {
  103811. const classId = hierarchy.classIds[instanceIndex];
  103812. const instanceClass = hierarchy.classes[classId];
  103813. const indexInClass = hierarchy.classIndexes[instanceIndex];
  103814. const propertyValues = instanceClass.instances[name];
  103815. if (defined(propertyValues)) {
  103816. assert$7(instanceIndex === batchId, "Inherited property \"".concat(name, "\" is read-only."));
  103817. if (defined(propertyValues.typedArray)) {
  103818. this._setBinaryProperty(propertyValues, indexInClass, value);
  103819. } else {
  103820. propertyValues[indexInClass] = clone(value);
  103821. }
  103822. return true;
  103823. }
  103824. return false;
  103825. });
  103826. return defined(result);
  103827. }
  103828. }
  103829. const SIZEOF_UINT32$1 = 4;
  103830. function parse3DTileHeaderSync(tile, arrayBuffer, byteOffset = 0) {
  103831. const view = new DataView(arrayBuffer);
  103832. tile.magic = view.getUint32(byteOffset, true);
  103833. byteOffset += SIZEOF_UINT32$1;
  103834. tile.version = view.getUint32(byteOffset, true);
  103835. byteOffset += SIZEOF_UINT32$1;
  103836. tile.byteLength = view.getUint32(byteOffset, true);
  103837. byteOffset += SIZEOF_UINT32$1;
  103838. if (tile.version !== 1) {
  103839. throw new Error("3D Tile Version ".concat(tile.version, " not supported"));
  103840. }
  103841. return byteOffset;
  103842. }
  103843. const SIZEOF_UINT32 = 4;
  103844. const DEPRECATION_WARNING = 'b3dm tile in legacy format.';
  103845. function parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset) {
  103846. const view = new DataView(arrayBuffer);
  103847. let batchLength;
  103848. tile.header = tile.header || {};
  103849. let featureTableJsonByteLength = view.getUint32(byteOffset, true);
  103850. byteOffset += SIZEOF_UINT32;
  103851. let featureTableBinaryByteLength = view.getUint32(byteOffset, true);
  103852. byteOffset += SIZEOF_UINT32;
  103853. let batchTableJsonByteLength = view.getUint32(byteOffset, true);
  103854. byteOffset += SIZEOF_UINT32;
  103855. let batchTableBinaryByteLength = view.getUint32(byteOffset, true);
  103856. byteOffset += SIZEOF_UINT32;
  103857. if (batchTableJsonByteLength >= 570425344) {
  103858. byteOffset -= SIZEOF_UINT32 * 2;
  103859. batchLength = featureTableJsonByteLength;
  103860. batchTableJsonByteLength = featureTableBinaryByteLength;
  103861. batchTableBinaryByteLength = 0;
  103862. featureTableJsonByteLength = 0;
  103863. featureTableBinaryByteLength = 0;
  103864. console.warn(DEPRECATION_WARNING);
  103865. } else if (batchTableBinaryByteLength >= 570425344) {
  103866. byteOffset -= SIZEOF_UINT32;
  103867. batchLength = batchTableJsonByteLength;
  103868. batchTableJsonByteLength = featureTableJsonByteLength;
  103869. batchTableBinaryByteLength = featureTableBinaryByteLength;
  103870. featureTableJsonByteLength = 0;
  103871. featureTableBinaryByteLength = 0;
  103872. console.warn(DEPRECATION_WARNING);
  103873. }
  103874. tile.header.featureTableJsonByteLength = featureTableJsonByteLength;
  103875. tile.header.featureTableBinaryByteLength = featureTableBinaryByteLength;
  103876. tile.header.batchTableJsonByteLength = batchTableJsonByteLength;
  103877. tile.header.batchTableBinaryByteLength = batchTableBinaryByteLength;
  103878. tile.header.batchLength = batchLength;
  103879. return byteOffset;
  103880. }
  103881. function parse3DTileTablesSync(tile, arrayBuffer, byteOffset, options) {
  103882. byteOffset = parse3DTileFeatureTable(tile, arrayBuffer, byteOffset);
  103883. byteOffset = parse3DTileBatchTable(tile, arrayBuffer, byteOffset);
  103884. return byteOffset;
  103885. }
  103886. function parse3DTileFeatureTable(tile, arrayBuffer, byteOffset, options) {
  103887. const {
  103888. featureTableJsonByteLength,
  103889. featureTableBinaryByteLength,
  103890. batchLength
  103891. } = tile.header;
  103892. tile.featureTableJson = {
  103893. BATCH_LENGTH: batchLength || 0
  103894. };
  103895. if (featureTableJsonByteLength > 0) {
  103896. const featureTableString = getStringFromArrayBuffer(arrayBuffer, byteOffset, featureTableJsonByteLength);
  103897. tile.featureTableJson = JSON.parse(featureTableString);
  103898. }
  103899. byteOffset += featureTableJsonByteLength;
  103900. tile.featureTableBinary = new Uint8Array(arrayBuffer, byteOffset, featureTableBinaryByteLength);
  103901. byteOffset += featureTableBinaryByteLength;
  103902. return byteOffset;
  103903. }
  103904. function parse3DTileBatchTable(tile, arrayBuffer, byteOffset, options) {
  103905. const {
  103906. batchTableJsonByteLength,
  103907. batchTableBinaryByteLength
  103908. } = tile.header;
  103909. if (batchTableJsonByteLength > 0) {
  103910. const batchTableString = getStringFromArrayBuffer(arrayBuffer, byteOffset, batchTableJsonByteLength);
  103911. tile.batchTableJson = JSON.parse(batchTableString);
  103912. byteOffset += batchTableJsonByteLength;
  103913. if (batchTableBinaryByteLength > 0) {
  103914. tile.batchTableBinary = new Uint8Array(arrayBuffer, byteOffset, batchTableBinaryByteLength);
  103915. tile.batchTableBinary = new Uint8Array(tile.batchTableBinary);
  103916. byteOffset += batchTableBinaryByteLength;
  103917. }
  103918. }
  103919. return byteOffset;
  103920. }
  103921. function normalize3DTileColorAttribute(tile, colors, batchTable) {
  103922. if (!colors && (!tile || !tile.batchIds || !batchTable)) {
  103923. return null;
  103924. }
  103925. const {
  103926. batchIds,
  103927. isRGB565,
  103928. pointCount
  103929. } = tile;
  103930. if (batchIds && batchTable) {
  103931. const colorArray = new Uint8ClampedArray(pointCount * 3);
  103932. for (let i = 0; i < pointCount; i++) {
  103933. const batchId = batchIds[i];
  103934. const dimensions = batchTable.getProperty(batchId, 'dimensions');
  103935. const color = dimensions.map(d => d * 255);
  103936. colorArray[i * 3] = color[0];
  103937. colorArray[i * 3 + 1] = color[1];
  103938. colorArray[i * 3 + 2] = color[2];
  103939. }
  103940. return {
  103941. type: GL$1.UNSIGNED_BYTE,
  103942. value: colorArray,
  103943. size: 3,
  103944. normalized: true
  103945. };
  103946. }
  103947. if (isRGB565) {
  103948. const colorArray = new Uint8ClampedArray(pointCount * 3);
  103949. for (let i = 0; i < pointCount; i++) {
  103950. const color = decodeRGB565(colors[i]);
  103951. colorArray[i * 3] = color[0];
  103952. colorArray[i * 3 + 1] = color[1];
  103953. colorArray[i * 3 + 2] = color[2];
  103954. }
  103955. return {
  103956. type: GL$1.UNSIGNED_BYTE,
  103957. value: colorArray,
  103958. size: 3,
  103959. normalized: true
  103960. };
  103961. }
  103962. if (colors && colors.length === pointCount * 3) {
  103963. return {
  103964. type: GL$1.UNSIGNED_BYTE,
  103965. value: colors,
  103966. size: 3,
  103967. normalized: true
  103968. };
  103969. }
  103970. return {
  103971. type: GL$1.UNSIGNED_BYTE,
  103972. value: colors,
  103973. size: 4,
  103974. normalized: true
  103975. };
  103976. }
  103977. const scratchNormal = new Vector3$1();
  103978. function normalize3DTileNormalAttribute(tile, normals) {
  103979. if (!normals) {
  103980. return null;
  103981. }
  103982. if (tile.isOctEncoded16P) {
  103983. const decodedArray = new Float32Array(tile.pointsLength * 3);
  103984. for (let i = 0; i < tile.pointsLength; i++) {
  103985. octDecode(normals[i * 2], normals[i * 2 + 1], scratchNormal);
  103986. scratchNormal.toArray(decodedArray, i * 3);
  103987. }
  103988. return {
  103989. type: GL$1.FLOAT,
  103990. size: 2,
  103991. value: decodedArray
  103992. };
  103993. }
  103994. return {
  103995. type: GL$1.FLOAT,
  103996. size: 2,
  103997. value: normals
  103998. };
  103999. }
  104000. function normalize3DTilePositionAttribute(tile, positions, options) {
  104001. if (!tile.isQuantized) {
  104002. return positions;
  104003. }
  104004. if (options['3d-tiles'] && options['3d-tiles'].decodeQuantizedPositions) {
  104005. tile.isQuantized = false;
  104006. return decodeQuantizedPositions(tile, positions);
  104007. }
  104008. return {
  104009. type: GL$1.UNSIGNED_SHORT,
  104010. value: positions,
  104011. size: 3,
  104012. normalized: true
  104013. };
  104014. }
  104015. function decodeQuantizedPositions(tile, positions) {
  104016. const scratchPosition = new Vector3$1();
  104017. const decodedArray = new Float32Array(tile.pointCount * 3);
  104018. for (let i = 0; i < tile.pointCount; i++) {
  104019. scratchPosition.set(positions[i * 3], positions[i * 3 + 1], positions[i * 3 + 2]).scale(1 / tile.quantizedRange).multiply(tile.quantizedVolumeScale).add(tile.quantizedVolumeOffset).toArray(decodedArray, i * 3);
  104020. }
  104021. return decodedArray;
  104022. }
  104023. async function parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context) {
  104024. byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
  104025. byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
  104026. byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset);
  104027. initializeTile(tile);
  104028. const {
  104029. featureTable,
  104030. batchTable
  104031. } = parsePointCloudTables(tile);
  104032. await parseDraco(tile, featureTable, batchTable, options, context);
  104033. parsePositions(tile, featureTable, options);
  104034. parseColors(tile, featureTable, batchTable);
  104035. parseNormals(tile, featureTable);
  104036. return byteOffset;
  104037. }
  104038. function initializeTile(tile) {
  104039. tile.attributes = {
  104040. positions: null,
  104041. colors: null,
  104042. normals: null,
  104043. batchIds: null
  104044. };
  104045. tile.isQuantized = false;
  104046. tile.isTranslucent = false;
  104047. tile.isRGB565 = false;
  104048. tile.isOctEncoded16P = false;
  104049. }
  104050. function parsePointCloudTables(tile) {
  104051. const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
  104052. const pointsLength = featureTable.getGlobalProperty('POINTS_LENGTH');
  104053. if (!Number.isFinite(pointsLength)) {
  104054. throw new Error('POINTS_LENGTH must be defined');
  104055. }
  104056. featureTable.featuresLength = pointsLength;
  104057. tile.featuresLength = pointsLength;
  104058. tile.pointsLength = pointsLength;
  104059. tile.pointCount = pointsLength;
  104060. tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL$1.FLOAT, 3);
  104061. const batchTable = parseBatchIds(tile, featureTable);
  104062. return {
  104063. featureTable,
  104064. batchTable
  104065. };
  104066. }
  104067. function parsePositions(tile, featureTable, options) {
  104068. if (!tile.attributes.positions) {
  104069. if (featureTable.hasProperty('POSITION')) {
  104070. tile.attributes.positions = featureTable.getPropertyArray('POSITION', GL$1.FLOAT, 3);
  104071. } else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
  104072. const positions = featureTable.getPropertyArray('POSITION_QUANTIZED', GL$1.UNSIGNED_SHORT, 3);
  104073. tile.isQuantized = true;
  104074. tile.quantizedRange = (1 << 16) - 1;
  104075. tile.quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', GL$1.FLOAT, 3);
  104076. if (!tile.quantizedVolumeScale) {
  104077. throw new Error('QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
  104078. }
  104079. tile.quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', GL$1.FLOAT, 3);
  104080. if (!tile.quantizedVolumeOffset) {
  104081. throw new Error('QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
  104082. }
  104083. tile.attributes.positions = normalize3DTilePositionAttribute(tile, positions, options);
  104084. }
  104085. }
  104086. if (!tile.attributes.positions) {
  104087. throw new Error('Either POSITION or POSITION_QUANTIZED must be defined.');
  104088. }
  104089. }
  104090. function parseColors(tile, featureTable, batchTable) {
  104091. if (!tile.attributes.colors) {
  104092. let colors = null;
  104093. if (featureTable.hasProperty('RGBA')) {
  104094. colors = featureTable.getPropertyArray('RGBA', GL$1.UNSIGNED_BYTE, 4);
  104095. tile.isTranslucent = true;
  104096. } else if (featureTable.hasProperty('RGB')) {
  104097. colors = featureTable.getPropertyArray('RGB', GL$1.UNSIGNED_BYTE, 3);
  104098. } else if (featureTable.hasProperty('RGB565')) {
  104099. colors = featureTable.getPropertyArray('RGB565', GL$1.UNSIGNED_SHORT, 1);
  104100. tile.isRGB565 = true;
  104101. }
  104102. tile.attributes.colors = normalize3DTileColorAttribute(tile, colors, batchTable);
  104103. }
  104104. if (featureTable.hasProperty('CONSTANT_RGBA')) {
  104105. tile.constantRGBA = featureTable.getGlobalProperty('CONSTANT_RGBA', GL$1.UNSIGNED_BYTE, 4);
  104106. }
  104107. }
  104108. function parseNormals(tile, featureTable) {
  104109. if (!tile.attributes.normals) {
  104110. let normals = null;
  104111. if (featureTable.hasProperty('NORMAL')) {
  104112. normals = featureTable.getPropertyArray('NORMAL', GL$1.FLOAT, 3);
  104113. } else if (featureTable.hasProperty('NORMAL_OCT16P')) {
  104114. normals = featureTable.getPropertyArray('NORMAL_OCT16P', GL$1.UNSIGNED_BYTE, 2);
  104115. tile.isOctEncoded16P = true;
  104116. }
  104117. tile.attributes.normals = normalize3DTileNormalAttribute(tile, normals);
  104118. }
  104119. }
  104120. function parseBatchIds(tile, featureTable) {
  104121. let batchTable = null;
  104122. if (!tile.batchIds && featureTable.hasProperty('BATCH_ID')) {
  104123. tile.batchIds = featureTable.getPropertyArray('BATCH_ID', GL$1.UNSIGNED_SHORT, 1);
  104124. if (tile.batchIds) {
  104125. const batchFeatureLength = featureTable.getGlobalProperty('BATCH_LENGTH');
  104126. if (!batchFeatureLength) {
  104127. throw new Error('Global property: BATCH_LENGTH must be defined when BATCH_ID is defined.');
  104128. }
  104129. const {
  104130. batchTableJson,
  104131. batchTableBinary
  104132. } = tile;
  104133. batchTable = new Tile3DBatchTableParser(batchTableJson, batchTableBinary, batchFeatureLength);
  104134. }
  104135. }
  104136. return batchTable;
  104137. }
  104138. async function parseDraco(tile, featureTable, batchTable, options, context) {
  104139. let dracoBuffer;
  104140. let dracoFeatureTableProperties;
  104141. let dracoBatchTableProperties;
  104142. const batchTableDraco = tile.batchTableJson && tile.batchTableJson.extensions && tile.batchTableJson.extensions['3DTILES_draco_point_compression'];
  104143. if (batchTableDraco) {
  104144. dracoBatchTableProperties = batchTableDraco.properties;
  104145. }
  104146. const featureTableDraco = featureTable.getExtension('3DTILES_draco_point_compression');
  104147. if (featureTableDraco) {
  104148. dracoFeatureTableProperties = featureTableDraco.properties;
  104149. const dracoByteOffset = featureTableDraco.byteOffset;
  104150. const dracoByteLength = featureTableDraco.byteLength;
  104151. if (!dracoFeatureTableProperties || !Number.isFinite(dracoByteOffset) || !dracoByteLength) {
  104152. throw new Error('Draco properties, byteOffset, and byteLength must be defined');
  104153. }
  104154. dracoBuffer = tile.featureTableBinary.slice(dracoByteOffset, dracoByteOffset + dracoByteLength);
  104155. tile.hasPositions = Number.isFinite(dracoFeatureTableProperties.POSITION);
  104156. tile.hasColors = Number.isFinite(dracoFeatureTableProperties.RGB) || Number.isFinite(dracoFeatureTableProperties.RGBA);
  104157. tile.hasNormals = Number.isFinite(dracoFeatureTableProperties.NORMAL);
  104158. tile.hasBatchIds = Number.isFinite(dracoFeatureTableProperties.BATCH_ID);
  104159. tile.isTranslucent = Number.isFinite(dracoFeatureTableProperties.RGBA);
  104160. }
  104161. if (!dracoBuffer) {
  104162. return true;
  104163. }
  104164. const dracoData = {
  104165. buffer: dracoBuffer,
  104166. properties: { ...dracoFeatureTableProperties,
  104167. ...dracoBatchTableProperties
  104168. },
  104169. featureTableProperties: dracoFeatureTableProperties,
  104170. batchTableProperties: dracoBatchTableProperties,
  104171. dequantizeInShader: false
  104172. };
  104173. return await loadDraco(tile, dracoData, options, context);
  104174. }
  104175. async function loadDraco(tile, dracoData, options, context) {
  104176. const {
  104177. parse
  104178. } = context;
  104179. const dracoOptions = { ...options,
  104180. draco: { ...options.draco,
  104181. extraAttributes: dracoData.batchTableProperties || {}
  104182. }
  104183. };
  104184. delete dracoOptions['3d-tiles'];
  104185. const data = await parse(dracoData.buffer, DracoLoader, dracoOptions);
  104186. const decodedPositions = data.attributes.POSITION && data.attributes.POSITION.value;
  104187. const decodedColors = data.attributes.COLOR_0 && data.attributes.COLOR_0.value;
  104188. const decodedNormals = data.attributes.NORMAL && data.attributes.NORMAL.value;
  104189. const decodedBatchIds = data.attributes.BATCH_ID && data.attributes.BATCH_ID.value;
  104190. const isQuantizedDraco = decodedPositions && data.attributes.POSITION.value.quantization;
  104191. const isOctEncodedDraco = decodedNormals && data.attributes.NORMAL.value.quantization;
  104192. if (isQuantizedDraco) {
  104193. const quantization = data.POSITION.data.quantization;
  104194. const range = quantization.range;
  104195. tile.quantizedVolumeScale = new Vector3$1(range, range, range);
  104196. tile.quantizedVolumeOffset = new Vector3$1(quantization.minValues);
  104197. tile.quantizedRange = (1 << quantization.quantizationBits) - 1.0;
  104198. tile.isQuantizedDraco = true;
  104199. }
  104200. if (isOctEncodedDraco) {
  104201. tile.octEncodedRange = (1 << data.NORMAL.data.quantization.quantizationBits) - 1.0;
  104202. tile.isOctEncodedDraco = true;
  104203. }
  104204. const batchTableAttributes = {};
  104205. if (dracoData.batchTableProperties) {
  104206. for (const attributeName of Object.keys(dracoData.batchTableProperties)) {
  104207. if (data.attributes[attributeName] && data.attributes[attributeName].value) {
  104208. batchTableAttributes[attributeName.toLowerCase()] = data.attributes[attributeName].value;
  104209. }
  104210. }
  104211. }
  104212. tile.attributes = {
  104213. positions: decodedPositions,
  104214. colors: normalize3DTileColorAttribute(tile, decodedColors, undefined),
  104215. normals: decodedNormals,
  104216. batchIds: decodedBatchIds,
  104217. ...batchTableAttributes
  104218. };
  104219. }
  104220. const VERSION$3 = "3.1.4" ;
  104221. const VERSION$2 = "3.1.4" ;
  104222. const VERSION$1 = "3.1.4" ;
  104223. const BASIS_CDN_ENCODER_WASM = "https://unpkg.com/@loaders.gl/textures@".concat(VERSION$1, "/dist/libs/basis_encoder.wasm");
  104224. const BASIS_CDN_ENCODER_JS = "https://unpkg.com/@loaders.gl/textures@".concat(VERSION$1, "/dist/libs/basis_encoder.js");
  104225. let loadBasisTranscoderPromise;
  104226. async function loadBasisTrascoderModule(options) {
  104227. const modules = options.modules || {};
  104228. if (modules.basis) {
  104229. return modules.basis;
  104230. }
  104231. loadBasisTranscoderPromise = loadBasisTranscoderPromise || loadBasisTrascoder(options);
  104232. return await loadBasisTranscoderPromise;
  104233. }
  104234. async function loadBasisTrascoder(options) {
  104235. let BASIS = null;
  104236. let wasmBinary = null;
  104237. [BASIS, wasmBinary] = await Promise.all([await loadLibrary('basis_transcoder.js', 'textures', options), await loadLibrary('basis_transcoder.wasm', 'textures', options)]);
  104238. BASIS = BASIS || globalThis.BASIS;
  104239. return await initializeBasisTrascoderModule(BASIS, wasmBinary);
  104240. }
  104241. function initializeBasisTrascoderModule(BasisModule, wasmBinary) {
  104242. const options = {};
  104243. if (wasmBinary) {
  104244. options.wasmBinary = wasmBinary;
  104245. }
  104246. return new Promise(resolve => {
  104247. BasisModule(options).then(module => {
  104248. const {
  104249. BasisFile,
  104250. initializeBasis
  104251. } = module;
  104252. initializeBasis();
  104253. resolve({
  104254. BasisFile
  104255. });
  104256. });
  104257. });
  104258. }
  104259. let loadBasisEncoderPromise;
  104260. async function loadBasisEncoderModule(options) {
  104261. const modules = options.modules || {};
  104262. if (modules.basisEncoder) {
  104263. return modules.basisEncoder;
  104264. }
  104265. loadBasisEncoderPromise = loadBasisEncoderPromise || loadBasisEncoder(options);
  104266. return await loadBasisEncoderPromise;
  104267. }
  104268. async function loadBasisEncoder(options) {
  104269. let BASIS_ENCODER = null;
  104270. let wasmBinary = null;
  104271. [BASIS_ENCODER, wasmBinary] = await Promise.all([await loadLibrary(BASIS_CDN_ENCODER_JS, 'textures', options), await loadLibrary(BASIS_CDN_ENCODER_WASM, 'textures', options)]);
  104272. BASIS_ENCODER = BASIS_ENCODER || globalThis.BASIS;
  104273. return await initializeBasisEncoderModule(BASIS_ENCODER, wasmBinary);
  104274. }
  104275. function initializeBasisEncoderModule(BasisEncoderModule, wasmBinary) {
  104276. const options = {};
  104277. if (wasmBinary) {
  104278. options.wasmBinary = wasmBinary;
  104279. }
  104280. return new Promise(resolve => {
  104281. BasisEncoderModule(options).then(module => {
  104282. const {
  104283. BasisFile,
  104284. KTX2File,
  104285. initializeBasis,
  104286. BasisEncoder
  104287. } = module;
  104288. initializeBasis();
  104289. resolve({
  104290. BasisFile,
  104291. KTX2File,
  104292. BasisEncoder
  104293. });
  104294. });
  104295. });
  104296. }
  104297. const GL_EXTENSIONS_CONSTANTS = {
  104298. COMPRESSED_RGB_S3TC_DXT1_EXT: 0x83f0,
  104299. COMPRESSED_RGBA_S3TC_DXT1_EXT: 0x83f1,
  104300. COMPRESSED_RGBA_S3TC_DXT3_EXT: 0x83f2,
  104301. COMPRESSED_RGBA_S3TC_DXT5_EXT: 0x83f3,
  104302. COMPRESSED_R11_EAC: 0x9270,
  104303. COMPRESSED_SIGNED_R11_EAC: 0x9271,
  104304. COMPRESSED_RG11_EAC: 0x9272,
  104305. COMPRESSED_SIGNED_RG11_EAC: 0x9273,
  104306. COMPRESSED_RGB8_ETC2: 0x9274,
  104307. COMPRESSED_RGBA8_ETC2_EAC: 0x9275,
  104308. COMPRESSED_SRGB8_ETC2: 0x9276,
  104309. COMPRESSED_SRGB8_ALPHA8_ETC2_EAC: 0x9277,
  104310. COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9278,
  104311. COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2: 0x9279,
  104312. COMPRESSED_RGB_PVRTC_4BPPV1_IMG: 0x8c00,
  104313. COMPRESSED_RGBA_PVRTC_4BPPV1_IMG: 0x8c02,
  104314. COMPRESSED_RGB_PVRTC_2BPPV1_IMG: 0x8c01,
  104315. COMPRESSED_RGBA_PVRTC_2BPPV1_IMG: 0x8c03,
  104316. COMPRESSED_RGB_ETC1_WEBGL: 0x8d64,
  104317. COMPRESSED_RGB_ATC_WEBGL: 0x8c92,
  104318. COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL: 0x8c93,
  104319. COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL: 0x87ee,
  104320. COMPRESSED_RGBA_ASTC_4X4_KHR: 0x93b0,
  104321. COMPRESSED_RGBA_ASTC_5X4_KHR: 0x93b1,
  104322. COMPRESSED_RGBA_ASTC_5X5_KHR: 0x93b2,
  104323. COMPRESSED_RGBA_ASTC_6X5_KHR: 0x93b3,
  104324. COMPRESSED_RGBA_ASTC_6X6_KHR: 0x93b4,
  104325. COMPRESSED_RGBA_ASTC_8X5_KHR: 0x93b5,
  104326. COMPRESSED_RGBA_ASTC_8X6_KHR: 0x93b6,
  104327. COMPRESSED_RGBA_ASTC_8X8_KHR: 0x93b7,
  104328. COMPRESSED_RGBA_ASTC_10X5_KHR: 0x93b8,
  104329. COMPRESSED_RGBA_ASTC_10X6_KHR: 0x93b9,
  104330. COMPRESSED_RGBA_ASTC_10X8_KHR: 0x93ba,
  104331. COMPRESSED_RGBA_ASTC_10X10_KHR: 0x93bb,
  104332. COMPRESSED_RGBA_ASTC_12X10_KHR: 0x93bc,
  104333. COMPRESSED_RGBA_ASTC_12X12_KHR: 0x93bd,
  104334. COMPRESSED_SRGB8_ALPHA8_ASTC_4X4_KHR: 0x93d0,
  104335. COMPRESSED_SRGB8_ALPHA8_ASTC_5X4_KHR: 0x93d1,
  104336. COMPRESSED_SRGB8_ALPHA8_ASTC_5X5_KHR: 0x93d2,
  104337. COMPRESSED_SRGB8_ALPHA8_ASTC_6X5_KHR: 0x93d3,
  104338. COMPRESSED_SRGB8_ALPHA8_ASTC_6X6_KHR: 0x93d4,
  104339. COMPRESSED_SRGB8_ALPHA8_ASTC_8X5_KHR: 0x93d5,
  104340. COMPRESSED_SRGB8_ALPHA8_ASTC_8X6_KHR: 0x93d6,
  104341. COMPRESSED_SRGB8_ALPHA8_ASTC_8X8_KHR: 0x93d7,
  104342. COMPRESSED_SRGB8_ALPHA8_ASTC_10X5_KHR: 0x93d8,
  104343. COMPRESSED_SRGB8_ALPHA8_ASTC_10X6_KHR: 0x93d9,
  104344. COMPRESSED_SRGB8_ALPHA8_ASTC_10X8_KHR: 0x93da,
  104345. COMPRESSED_SRGB8_ALPHA8_ASTC_10X10_KHR: 0x93db,
  104346. COMPRESSED_SRGB8_ALPHA8_ASTC_12X10_KHR: 0x93dc,
  104347. COMPRESSED_SRGB8_ALPHA8_ASTC_12X12_KHR: 0x93dd,
  104348. COMPRESSED_RED_RGTC1_EXT: 0x8dbb,
  104349. COMPRESSED_SIGNED_RED_RGTC1_EXT: 0x8dbc,
  104350. COMPRESSED_RED_GREEN_RGTC2_EXT: 0x8dbd,
  104351. COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT: 0x8dbe,
  104352. COMPRESSED_SRGB_S3TC_DXT1_EXT: 0x8c4c,
  104353. COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 0x8c4d,
  104354. COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 0x8c4e,
  104355. COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 0x8c4f
  104356. };
  104357. const BROWSER_PREFIXES = ['', 'WEBKIT_', 'MOZ_'];
  104358. const WEBGL_EXTENSIONS = {
  104359. WEBGL_compressed_texture_s3tc: 'dxt',
  104360. WEBGL_compressed_texture_s3tc_srgb: 'dxt-srgb',
  104361. WEBGL_compressed_texture_etc1: 'etc1',
  104362. WEBGL_compressed_texture_etc: 'etc2',
  104363. WEBGL_compressed_texture_pvrtc: 'pvrtc',
  104364. WEBGL_compressed_texture_atc: 'atc',
  104365. WEBGL_compressed_texture_astc: 'astc',
  104366. EXT_texture_compression_rgtc: 'rgtc'
  104367. };
  104368. let formats = null;
  104369. function getSupportedGPUTextureFormats(gl) {
  104370. if (!formats) {
  104371. gl = gl || getWebGLContext() || undefined;
  104372. formats = new Set();
  104373. for (const prefix of BROWSER_PREFIXES) {
  104374. for (const extension in WEBGL_EXTENSIONS) {
  104375. if (gl && gl.getExtension("".concat(prefix).concat(extension))) {
  104376. const gpuTextureFormat = WEBGL_EXTENSIONS[extension];
  104377. formats.add(gpuTextureFormat);
  104378. }
  104379. }
  104380. }
  104381. }
  104382. return formats;
  104383. }
  104384. function getWebGLContext() {
  104385. try {
  104386. const canvas = document.createElement('canvas');
  104387. return canvas.getContext('webgl');
  104388. } catch (error) {
  104389. return null;
  104390. }
  104391. }
  104392. var n$2,i$2,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$2||(i$2={})),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={}));
  104393. const KTX2_ID = [0xab, 0x4b, 0x54, 0x58, 0x20, 0x32, 0x30, 0xbb, 0x0d, 0x0a, 0x1a, 0x0a];
  104394. function isKTX(data) {
  104395. const id = new Uint8Array(data);
  104396. const 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];
  104397. return !notKTX;
  104398. }
  104399. const OutputFormat = {
  104400. etc1: {
  104401. basisFormat: 0,
  104402. compressed: true,
  104403. format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_ETC1_WEBGL
  104404. },
  104405. etc2: {
  104406. basisFormat: 1,
  104407. compressed: true
  104408. },
  104409. bc1: {
  104410. basisFormat: 2,
  104411. compressed: true,
  104412. format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_S3TC_DXT1_EXT
  104413. },
  104414. bc3: {
  104415. basisFormat: 3,
  104416. compressed: true,
  104417. format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_S3TC_DXT5_EXT
  104418. },
  104419. bc4: {
  104420. basisFormat: 4,
  104421. compressed: true
  104422. },
  104423. bc5: {
  104424. basisFormat: 5,
  104425. compressed: true
  104426. },
  104427. 'bc7-m6-opaque-only': {
  104428. basisFormat: 6,
  104429. compressed: true
  104430. },
  104431. 'bc7-m5': {
  104432. basisFormat: 7,
  104433. compressed: true
  104434. },
  104435. 'pvrtc1-4-rgb': {
  104436. basisFormat: 8,
  104437. compressed: true,
  104438. format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGB_PVRTC_4BPPV1_IMG
  104439. },
  104440. 'pvrtc1-4-rgba': {
  104441. basisFormat: 9,
  104442. compressed: true,
  104443. format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
  104444. },
  104445. 'astc-4x4': {
  104446. basisFormat: 10,
  104447. compressed: true,
  104448. format: GL_EXTENSIONS_CONSTANTS.COMPRESSED_RGBA_ASTC_4X4_KHR
  104449. },
  104450. 'atc-rgb': {
  104451. basisFormat: 11,
  104452. compressed: true
  104453. },
  104454. 'atc-rgba-interpolated-alpha': {
  104455. basisFormat: 12,
  104456. compressed: true
  104457. },
  104458. rgba32: {
  104459. basisFormat: 13,
  104460. compressed: false
  104461. },
  104462. rgb565: {
  104463. basisFormat: 14,
  104464. compressed: false
  104465. },
  104466. bgr565: {
  104467. basisFormat: 15,
  104468. compressed: false
  104469. },
  104470. rgba4444: {
  104471. basisFormat: 16,
  104472. compressed: false
  104473. }
  104474. };
  104475. async function parseBasis(data, options) {
  104476. if (options.basis.containerFormat === 'auto') {
  104477. if (isKTX(data)) {
  104478. const fileConstructors = await loadBasisEncoderModule(options);
  104479. return parseKTX2File(fileConstructors.KTX2File, data, options);
  104480. }
  104481. const {
  104482. BasisFile
  104483. } = await loadBasisTrascoderModule(options);
  104484. return parseBasisFile(BasisFile, data, options);
  104485. }
  104486. switch (options.basis.module) {
  104487. case 'encoder':
  104488. const fileConstructors = await loadBasisEncoderModule(options);
  104489. switch (options.basis.containerFormat) {
  104490. case 'ktx2':
  104491. return parseKTX2File(fileConstructors.KTX2File, data, options);
  104492. case 'basis':
  104493. default:
  104494. return parseBasisFile(fileConstructors.BasisFile, data, options);
  104495. }
  104496. case 'transcoder':
  104497. default:
  104498. const {
  104499. BasisFile
  104500. } = await loadBasisTrascoderModule(options);
  104501. return parseBasisFile(BasisFile, data, options);
  104502. }
  104503. }
  104504. function parseBasisFile(BasisFile, data, options) {
  104505. const basisFile = new BasisFile(new Uint8Array(data));
  104506. try {
  104507. if (!basisFile.startTranscoding()) {
  104508. return null;
  104509. }
  104510. const imageCount = basisFile.getNumImages();
  104511. const images = [];
  104512. for (let imageIndex = 0; imageIndex < imageCount; imageIndex++) {
  104513. const levelsCount = basisFile.getNumLevels(imageIndex);
  104514. const levels = [];
  104515. for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
  104516. levels.push(transcodeImage(basisFile, imageIndex, levelIndex, options));
  104517. }
  104518. images.push(levels);
  104519. }
  104520. return images;
  104521. } finally {
  104522. basisFile.close();
  104523. basisFile.delete();
  104524. }
  104525. }
  104526. function transcodeImage(basisFile, imageIndex, levelIndex, options) {
  104527. const width = basisFile.getImageWidth(imageIndex, levelIndex);
  104528. const height = basisFile.getImageHeight(imageIndex, levelIndex);
  104529. const hasAlpha = basisFile.getHasAlpha();
  104530. const {
  104531. compressed,
  104532. format,
  104533. basisFormat
  104534. } = getBasisOptions(options, hasAlpha);
  104535. const decodedSize = basisFile.getImageTranscodedSizeInBytes(imageIndex, levelIndex, basisFormat);
  104536. const decodedData = new Uint8Array(decodedSize);
  104537. if (!basisFile.transcodeImage(decodedData, imageIndex, levelIndex, basisFormat, 0, 0)) {
  104538. return null;
  104539. }
  104540. return {
  104541. width,
  104542. height,
  104543. data: decodedData,
  104544. compressed,
  104545. hasAlpha,
  104546. format
  104547. };
  104548. }
  104549. function parseKTX2File(KTX2File, data, options) {
  104550. const ktx2File = new KTX2File(new Uint8Array(data));
  104551. try {
  104552. if (!ktx2File.startTranscoding()) {
  104553. return null;
  104554. }
  104555. const levelsCount = ktx2File.getLevels();
  104556. const levels = [];
  104557. for (let levelIndex = 0; levelIndex < levelsCount; levelIndex++) {
  104558. levels.push(transcodeKTX2Image(ktx2File, levelIndex, options));
  104559. break;
  104560. }
  104561. return levels;
  104562. } finally {
  104563. ktx2File.close();
  104564. ktx2File.delete();
  104565. }
  104566. }
  104567. function transcodeKTX2Image(ktx2File, levelIndex, options) {
  104568. const {
  104569. alphaFlag,
  104570. height,
  104571. width
  104572. } = ktx2File.getImageLevelInfo(levelIndex, 0, 0);
  104573. const {
  104574. compressed,
  104575. format,
  104576. basisFormat
  104577. } = getBasisOptions(options, alphaFlag);
  104578. const decodedSize = ktx2File.getImageTranscodedSizeInBytes(levelIndex, 0, 0, basisFormat);
  104579. const decodedData = new Uint8Array(decodedSize);
  104580. if (!ktx2File.transcodeImage(decodedData, levelIndex, 0, 0, basisFormat, 0, -1, -1)) {
  104581. return null;
  104582. }
  104583. return {
  104584. width,
  104585. height,
  104586. data: decodedData,
  104587. compressed,
  104588. alphaFlag,
  104589. format
  104590. };
  104591. }
  104592. function getBasisOptions(options, hasAlpha) {
  104593. let format = options && options.basis && options.basis.format;
  104594. if (format === 'auto') {
  104595. format = selectSupportedBasisFormat();
  104596. }
  104597. if (typeof format === 'object') {
  104598. format = hasAlpha ? format.alpha : format.noAlpha;
  104599. }
  104600. format = format.toLowerCase();
  104601. return OutputFormat[format];
  104602. }
  104603. function selectSupportedBasisFormat() {
  104604. const supportedFormats = getSupportedGPUTextureFormats();
  104605. if (supportedFormats.has('astc')) {
  104606. return 'astc-4x4';
  104607. } else if (supportedFormats.has('dxt')) {
  104608. return {
  104609. alpha: 'bc3',
  104610. noAlpha: 'bc1'
  104611. };
  104612. } else if (supportedFormats.has('pvrtc')) {
  104613. return {
  104614. alpha: 'pvrtc1-4-rgba',
  104615. noAlpha: 'pvrtc1-4-rgb'
  104616. };
  104617. } else if (supportedFormats.has('etc1')) {
  104618. return 'etc1';
  104619. } else if (supportedFormats.has('etc2')) {
  104620. return 'etc2';
  104621. }
  104622. return 'rgb565';
  104623. }
  104624. const BasisWorkerLoader = {
  104625. name: 'Basis',
  104626. id: 'basis',
  104627. module: 'textures',
  104628. version: VERSION$2,
  104629. worker: true,
  104630. extensions: ['basis', 'ktx2'],
  104631. mimeTypes: ['application/octet-stream', 'image/ktx2'],
  104632. tests: ['sB'],
  104633. binary: true,
  104634. options: {
  104635. basis: {
  104636. format: 'auto',
  104637. libraryPath: 'libs/',
  104638. containerFormat: 'auto',
  104639. module: 'transcoder'
  104640. }
  104641. }
  104642. };
  104643. const BasisLoader = { ...BasisWorkerLoader,
  104644. parse: parseBasis
  104645. };
  104646. const VERSION = "3.1.4" ;
  104647. const {
  104648. _parseImageNode
  104649. } = globalThis;
  104650. const IMAGE_SUPPORTED = typeof Image !== 'undefined';
  104651. const IMAGE_BITMAP_SUPPORTED = typeof ImageBitmap !== 'undefined';
  104652. const NODE_IMAGE_SUPPORTED = Boolean(_parseImageNode);
  104653. const DATA_SUPPORTED = isBrowser$2 ? true : NODE_IMAGE_SUPPORTED;
  104654. function isImageTypeSupported(type) {
  104655. switch (type) {
  104656. case 'auto':
  104657. return IMAGE_BITMAP_SUPPORTED || IMAGE_SUPPORTED || DATA_SUPPORTED;
  104658. case 'imagebitmap':
  104659. return IMAGE_BITMAP_SUPPORTED;
  104660. case 'image':
  104661. return IMAGE_SUPPORTED;
  104662. case 'data':
  104663. return DATA_SUPPORTED;
  104664. default:
  104665. throw new Error("@loaders.gl/images: image ".concat(type, " not supported in this environment"));
  104666. }
  104667. }
  104668. function getDefaultImageType() {
  104669. if (IMAGE_BITMAP_SUPPORTED) {
  104670. return 'imagebitmap';
  104671. }
  104672. if (IMAGE_SUPPORTED) {
  104673. return 'image';
  104674. }
  104675. if (DATA_SUPPORTED) {
  104676. return 'data';
  104677. }
  104678. throw new Error('Install \'@loaders.gl/polyfills\' to parse images under Node.js');
  104679. }
  104680. function getImageType(image) {
  104681. const format = getImageTypeOrNull(image);
  104682. if (!format) {
  104683. throw new Error('Not an image');
  104684. }
  104685. return format;
  104686. }
  104687. function getImageData(image) {
  104688. switch (getImageType(image)) {
  104689. case 'data':
  104690. return image;
  104691. case 'image':
  104692. case 'imagebitmap':
  104693. const canvas = document.createElement('canvas');
  104694. const context = canvas.getContext('2d');
  104695. if (!context) {
  104696. throw new Error('getImageData');
  104697. }
  104698. canvas.width = image.width;
  104699. canvas.height = image.height;
  104700. context.drawImage(image, 0, 0);
  104701. return context.getImageData(0, 0, image.width, image.height);
  104702. default:
  104703. throw new Error('getImageData');
  104704. }
  104705. }
  104706. function getImageTypeOrNull(image) {
  104707. if (typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap) {
  104708. return 'imagebitmap';
  104709. }
  104710. if (typeof Image !== 'undefined' && image instanceof Image) {
  104711. return 'image';
  104712. }
  104713. if (image && typeof image === 'object' && image.data && image.width && image.height) {
  104714. return 'data';
  104715. }
  104716. return null;
  104717. }
  104718. const SVG_DATA_URL_PATTERN = /^data:image\/svg\+xml/;
  104719. const SVG_URL_PATTERN = /\.svg((\?|#).*)?$/;
  104720. function isSVG(url) {
  104721. return url && (SVG_DATA_URL_PATTERN.test(url) || SVG_URL_PATTERN.test(url));
  104722. }
  104723. function getBlobOrSVGDataUrl(arrayBuffer, url) {
  104724. if (isSVG(url)) {
  104725. const textDecoder = new TextDecoder();
  104726. let xmlText = textDecoder.decode(arrayBuffer);
  104727. try {
  104728. if (typeof unescape === 'function' && typeof encodeURIComponent === 'function') {
  104729. xmlText = unescape(encodeURIComponent(xmlText));
  104730. }
  104731. } catch (error) {
  104732. throw new Error(error.message);
  104733. }
  104734. const src = "data:image/svg+xml;base64,".concat(btoa(xmlText));
  104735. return src;
  104736. }
  104737. return getBlob(arrayBuffer, url);
  104738. }
  104739. function getBlob(arrayBuffer, url) {
  104740. if (isSVG(url)) {
  104741. throw new Error('SVG cannot be parsed directly to imagebitmap');
  104742. }
  104743. return new Blob([new Uint8Array(arrayBuffer)]);
  104744. }
  104745. async function parseToImage(arrayBuffer, options, url) {
  104746. const blobOrDataUrl = getBlobOrSVGDataUrl(arrayBuffer, url);
  104747. const URL = self.URL || self.webkitURL;
  104748. const objectUrl = typeof blobOrDataUrl !== 'string' && URL.createObjectURL(blobOrDataUrl);
  104749. try {
  104750. return await loadToImage(objectUrl || blobOrDataUrl, options);
  104751. } finally {
  104752. if (objectUrl) {
  104753. URL.revokeObjectURL(objectUrl);
  104754. }
  104755. }
  104756. }
  104757. async function loadToImage(url, options) {
  104758. const image = new Image();
  104759. image.src = url;
  104760. if (options.image && options.image.decode && image.decode) {
  104761. await image.decode();
  104762. return image;
  104763. }
  104764. return await new Promise((resolve, reject) => {
  104765. try {
  104766. image.onload = () => resolve(image);
  104767. image.onerror = err => reject(new Error("Could not load image ".concat(url, ": ").concat(err)));
  104768. } catch (error) {
  104769. reject(error);
  104770. }
  104771. });
  104772. }
  104773. const EMPTY_OBJECT = {};
  104774. let imagebitmapOptionsSupported = true;
  104775. async function parseToImageBitmap(arrayBuffer, options, url) {
  104776. let blob;
  104777. if (isSVG(url)) {
  104778. const image = await parseToImage(arrayBuffer, options, url);
  104779. blob = image;
  104780. } else {
  104781. blob = getBlob(arrayBuffer, url);
  104782. }
  104783. const imagebitmapOptions = options && options.imagebitmap;
  104784. return await safeCreateImageBitmap(blob, imagebitmapOptions);
  104785. }
  104786. async function safeCreateImageBitmap(blob, imagebitmapOptions = null) {
  104787. if (isEmptyObject(imagebitmapOptions) || !imagebitmapOptionsSupported) {
  104788. imagebitmapOptions = null;
  104789. }
  104790. if (imagebitmapOptions) {
  104791. try {
  104792. return await createImageBitmap(blob, imagebitmapOptions);
  104793. } catch (error) {
  104794. console.warn(error);
  104795. imagebitmapOptionsSupported = false;
  104796. }
  104797. }
  104798. return await createImageBitmap(blob);
  104799. }
  104800. function isEmptyObject(object) {
  104801. for (const key in object || EMPTY_OBJECT) {
  104802. return false;
  104803. }
  104804. return true;
  104805. }
  104806. const BIG_ENDIAN = false;
  104807. const LITTLE_ENDIAN = true;
  104808. function getBinaryImageMetadata(binaryData) {
  104809. const dataView = toDataView(binaryData);
  104810. return getPngMetadata(dataView) || getJpegMetadata(dataView) || getGifMetadata(dataView) || getBmpMetadata(dataView);
  104811. }
  104812. function getPngMetadata(binaryData) {
  104813. const dataView = toDataView(binaryData);
  104814. const isPng = dataView.byteLength >= 24 && dataView.getUint32(0, BIG_ENDIAN) === 0x89504e47;
  104815. if (!isPng) {
  104816. return null;
  104817. }
  104818. return {
  104819. mimeType: 'image/png',
  104820. width: dataView.getUint32(16, BIG_ENDIAN),
  104821. height: dataView.getUint32(20, BIG_ENDIAN)
  104822. };
  104823. }
  104824. function getGifMetadata(binaryData) {
  104825. const dataView = toDataView(binaryData);
  104826. const isGif = dataView.byteLength >= 10 && dataView.getUint32(0, BIG_ENDIAN) === 0x47494638;
  104827. if (!isGif) {
  104828. return null;
  104829. }
  104830. return {
  104831. mimeType: 'image/gif',
  104832. width: dataView.getUint16(6, LITTLE_ENDIAN),
  104833. height: dataView.getUint16(8, LITTLE_ENDIAN)
  104834. };
  104835. }
  104836. function getBmpMetadata(binaryData) {
  104837. const dataView = toDataView(binaryData);
  104838. const isBmp = dataView.byteLength >= 14 && dataView.getUint16(0, BIG_ENDIAN) === 0x424d && dataView.getUint32(2, LITTLE_ENDIAN) === dataView.byteLength;
  104839. if (!isBmp) {
  104840. return null;
  104841. }
  104842. return {
  104843. mimeType: 'image/bmp',
  104844. width: dataView.getUint32(18, LITTLE_ENDIAN),
  104845. height: dataView.getUint32(22, LITTLE_ENDIAN)
  104846. };
  104847. }
  104848. function getJpegMetadata(binaryData) {
  104849. const dataView = toDataView(binaryData);
  104850. const isJpeg = dataView.byteLength >= 3 && dataView.getUint16(0, BIG_ENDIAN) === 0xffd8 && dataView.getUint8(2) === 0xff;
  104851. if (!isJpeg) {
  104852. return null;
  104853. }
  104854. const {
  104855. tableMarkers,
  104856. sofMarkers
  104857. } = getJpegMarkers();
  104858. let i = 2;
  104859. while (i + 9 < dataView.byteLength) {
  104860. const marker = dataView.getUint16(i, BIG_ENDIAN);
  104861. if (sofMarkers.has(marker)) {
  104862. return {
  104863. mimeType: 'image/jpeg',
  104864. height: dataView.getUint16(i + 5, BIG_ENDIAN),
  104865. width: dataView.getUint16(i + 7, BIG_ENDIAN)
  104866. };
  104867. }
  104868. if (!tableMarkers.has(marker)) {
  104869. return null;
  104870. }
  104871. i += 2;
  104872. i += dataView.getUint16(i, BIG_ENDIAN);
  104873. }
  104874. return null;
  104875. }
  104876. function getJpegMarkers() {
  104877. const tableMarkers = new Set([0xffdb, 0xffc4, 0xffcc, 0xffdd, 0xfffe]);
  104878. for (let i = 0xffe0; i < 0xfff0; ++i) {
  104879. tableMarkers.add(i);
  104880. }
  104881. const sofMarkers = new Set([0xffc0, 0xffc1, 0xffc2, 0xffc3, 0xffc5, 0xffc6, 0xffc7, 0xffc9, 0xffca, 0xffcb, 0xffcd, 0xffce, 0xffcf, 0xffde]);
  104882. return {
  104883. tableMarkers,
  104884. sofMarkers
  104885. };
  104886. }
  104887. function toDataView(data) {
  104888. if (data instanceof DataView) {
  104889. return data;
  104890. }
  104891. if (ArrayBuffer.isView(data)) {
  104892. return new DataView(data.buffer);
  104893. }
  104894. if (data instanceof ArrayBuffer) {
  104895. return new DataView(data);
  104896. }
  104897. throw new Error('toDataView');
  104898. }
  104899. async function parseToNodeImage(arrayBuffer, options) {
  104900. const {
  104901. mimeType
  104902. } = getBinaryImageMetadata(arrayBuffer) || {};
  104903. const _parseImageNode = globalThis._parseImageNode;
  104904. assert$7(_parseImageNode);
  104905. return await _parseImageNode(arrayBuffer, mimeType);
  104906. }
  104907. async function parseImage(arrayBuffer, options, context) {
  104908. options = options || {};
  104909. const imageOptions = options.image || {};
  104910. const imageType = imageOptions.type || 'auto';
  104911. const {
  104912. url
  104913. } = context || {};
  104914. const loadType = getLoadableImageType(imageType);
  104915. let image;
  104916. switch (loadType) {
  104917. case 'imagebitmap':
  104918. image = await parseToImageBitmap(arrayBuffer, options, url);
  104919. break;
  104920. case 'image':
  104921. image = await parseToImage(arrayBuffer, options, url);
  104922. break;
  104923. case 'data':
  104924. image = await parseToNodeImage(arrayBuffer);
  104925. break;
  104926. default:
  104927. assert$7(false);
  104928. }
  104929. if (imageType === 'data') {
  104930. image = getImageData(image);
  104931. }
  104932. return image;
  104933. }
  104934. function getLoadableImageType(type) {
  104935. switch (type) {
  104936. case 'auto':
  104937. case 'data':
  104938. return getDefaultImageType();
  104939. default:
  104940. isImageTypeSupported(type);
  104941. return type;
  104942. }
  104943. }
  104944. const EXTENSIONS$1 = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'svg'];
  104945. const MIME_TYPES = ['image/png', 'image/jpeg', 'image/gif', 'image/webp', 'image/bmp', 'image/vnd.microsoft.icon', 'image/svg+xml'];
  104946. const DEFAULT_IMAGE_LOADER_OPTIONS = {
  104947. image: {
  104948. type: 'auto',
  104949. decode: true
  104950. }
  104951. };
  104952. const ImageLoader$1 = {
  104953. id: 'image',
  104954. module: 'images',
  104955. name: 'Images',
  104956. version: VERSION,
  104957. mimeTypes: MIME_TYPES,
  104958. extensions: EXTENSIONS$1,
  104959. parse: parseImage,
  104960. tests: [arrayBuffer => Boolean(getBinaryImageMetadata(new DataView(arrayBuffer)))],
  104961. options: DEFAULT_IMAGE_LOADER_OPTIONS
  104962. };
  104963. const NODE_FORMAT_SUPPORT = ['image/png', 'image/jpeg', 'image/gif'];
  104964. const mimeTypeSupported = {};
  104965. function _isImageFormatSupported(mimeType) {
  104966. if (mimeTypeSupported[mimeType] === undefined) {
  104967. mimeTypeSupported[mimeType] = checkFormatSupport(mimeType);
  104968. }
  104969. return mimeTypeSupported[mimeType];
  104970. }
  104971. function checkFormatSupport(mimeType) {
  104972. switch (mimeType) {
  104973. case 'image/webp':
  104974. return checkWebPSupport();
  104975. case 'image/svg':
  104976. return isBrowser$2;
  104977. default:
  104978. if (!isBrowser$2) {
  104979. const {
  104980. _parseImageNode
  104981. } = globalThis;
  104982. return Boolean(_parseImageNode) && NODE_FORMAT_SUPPORT.includes(mimeType);
  104983. }
  104984. return true;
  104985. }
  104986. }
  104987. function checkWebPSupport() {
  104988. if (!isBrowser$2) {
  104989. return false;
  104990. }
  104991. try {
  104992. const element = document.createElement('canvas');
  104993. return element.toDataURL('image/webp').indexOf('data:image/webp') === 0;
  104994. } catch {
  104995. return false;
  104996. }
  104997. }
  104998. function assert$1(condition, message) {
  104999. if (!condition) {
  105000. throw new Error(message || 'assert failed: gltf');
  105001. }
  105002. }
  105003. function resolveUrl(url, options) {
  105004. const absolute = url.startsWith('data:') || url.startsWith('http:') || url.startsWith('https:');
  105005. if (absolute) {
  105006. return url;
  105007. }
  105008. const baseUrl = options.baseUri || options.uri;
  105009. if (!baseUrl) {
  105010. throw new Error("'baseUri' must be provided to resolve relative url ".concat(url));
  105011. }
  105012. return baseUrl.substr(0, baseUrl.lastIndexOf('/') + 1) + url;
  105013. }
  105014. function getTypedArrayForBufferView(json, buffers, bufferViewIndex) {
  105015. const bufferView = json.bufferViews[bufferViewIndex];
  105016. assert$1(bufferView);
  105017. const bufferIndex = bufferView.buffer;
  105018. const binChunk = buffers[bufferIndex];
  105019. assert$1(binChunk);
  105020. const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
  105021. return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
  105022. }
  105023. const TYPES = ['SCALAR', 'VEC2', 'VEC3', 'VEC4'];
  105024. const ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT = [[Int8Array, 5120], [Uint8Array, 5121], [Int16Array, 5122], [Uint16Array, 5123], [Uint32Array, 5125], [Float32Array, 5126], [Float64Array, 5130]];
  105025. const ARRAY_TO_COMPONENT_TYPE = new Map(ARRAY_CONSTRUCTOR_TO_WEBGL_CONSTANT);
  105026. const ATTRIBUTE_TYPE_TO_COMPONENTS = {
  105027. SCALAR: 1,
  105028. VEC2: 2,
  105029. VEC3: 3,
  105030. VEC4: 4,
  105031. MAT2: 4,
  105032. MAT3: 9,
  105033. MAT4: 16
  105034. };
  105035. const ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE = {
  105036. 5120: 1,
  105037. 5121: 1,
  105038. 5122: 2,
  105039. 5123: 2,
  105040. 5125: 4,
  105041. 5126: 4
  105042. };
  105043. const ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY = {
  105044. 5120: Int8Array,
  105045. 5121: Uint8Array,
  105046. 5122: Int16Array,
  105047. 5123: Uint16Array,
  105048. 5125: Uint32Array,
  105049. 5126: Float32Array
  105050. };
  105051. function getAccessorTypeFromSize(size) {
  105052. const type = TYPES[size - 1];
  105053. return type || TYPES[0];
  105054. }
  105055. function getComponentTypeFromArray(typedArray) {
  105056. const componentType = ARRAY_TO_COMPONENT_TYPE.get(typedArray.constructor);
  105057. if (!componentType) {
  105058. throw new Error('Illegal typed array');
  105059. }
  105060. return componentType;
  105061. }
  105062. function getAccessorArrayTypeAndLength(accessor, bufferView) {
  105063. const ArrayType = ATTRIBUTE_COMPONENT_TYPE_TO_ARRAY[accessor.componentType];
  105064. const components = ATTRIBUTE_TYPE_TO_COMPONENTS[accessor.type];
  105065. const bytesPerComponent = ATTRIBUTE_COMPONENT_TYPE_TO_BYTE_SIZE[accessor.componentType];
  105066. const length = accessor.count * components;
  105067. const byteLength = accessor.count * components * bytesPerComponent;
  105068. assert$1(byteLength >= 0 && byteLength <= bufferView.byteLength);
  105069. return {
  105070. ArrayType,
  105071. length,
  105072. byteLength
  105073. };
  105074. }
  105075. const DEFAULT_GLTF_JSON = {
  105076. asset: {
  105077. version: '2.0',
  105078. generator: 'loaders.gl'
  105079. },
  105080. buffers: []
  105081. };
  105082. class GLTFScenegraph {
  105083. constructor(gltf) {
  105084. _defineProperty(this, "gltf", void 0);
  105085. _defineProperty(this, "sourceBuffers", void 0);
  105086. _defineProperty(this, "byteLength", void 0);
  105087. this.gltf = gltf || {
  105088. json: { ...DEFAULT_GLTF_JSON
  105089. },
  105090. buffers: []
  105091. };
  105092. this.sourceBuffers = [];
  105093. this.byteLength = 0;
  105094. if (this.gltf.buffers && this.gltf.buffers[0]) {
  105095. this.byteLength = this.gltf.buffers[0].byteLength;
  105096. this.sourceBuffers = [this.gltf.buffers[0]];
  105097. }
  105098. }
  105099. get json() {
  105100. return this.gltf.json;
  105101. }
  105102. getApplicationData(key) {
  105103. const data = this.json[key];
  105104. return data;
  105105. }
  105106. getExtraData(key) {
  105107. const extras = this.json.extras || {};
  105108. return extras[key];
  105109. }
  105110. getExtension(extensionName) {
  105111. const isExtension = this.getUsedExtensions().find(name => name === extensionName);
  105112. const extensions = this.json.extensions || {};
  105113. return isExtension ? extensions[extensionName] || true : null;
  105114. }
  105115. getRequiredExtension(extensionName) {
  105116. const isRequired = this.getRequiredExtensions().find(name => name === extensionName);
  105117. return isRequired ? this.getExtension(extensionName) : null;
  105118. }
  105119. getRequiredExtensions() {
  105120. return this.json.extensionsRequired || [];
  105121. }
  105122. getUsedExtensions() {
  105123. return this.json.extensionsUsed || [];
  105124. }
  105125. getObjectExtension(object, extensionName) {
  105126. const extensions = object.extensions || {};
  105127. return extensions[extensionName];
  105128. }
  105129. getScene(index) {
  105130. return this.getObject('scenes', index);
  105131. }
  105132. getNode(index) {
  105133. return this.getObject('nodes', index);
  105134. }
  105135. getSkin(index) {
  105136. return this.getObject('skins', index);
  105137. }
  105138. getMesh(index) {
  105139. return this.getObject('meshes', index);
  105140. }
  105141. getMaterial(index) {
  105142. return this.getObject('materials', index);
  105143. }
  105144. getAccessor(index) {
  105145. return this.getObject('accessors', index);
  105146. }
  105147. getTexture(index) {
  105148. return this.getObject('textures', index);
  105149. }
  105150. getSampler(index) {
  105151. return this.getObject('samplers', index);
  105152. }
  105153. getImage(index) {
  105154. return this.getObject('images', index);
  105155. }
  105156. getBufferView(index) {
  105157. return this.getObject('bufferViews', index);
  105158. }
  105159. getBuffer(index) {
  105160. return this.getObject('buffers', index);
  105161. }
  105162. getObject(array, index) {
  105163. if (typeof index === 'object') {
  105164. return index;
  105165. }
  105166. const object = this.json[array] && this.json[array][index];
  105167. if (!object) {
  105168. throw new Error("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
  105169. }
  105170. return object;
  105171. }
  105172. getTypedArrayForBufferView(bufferView) {
  105173. bufferView = this.getBufferView(bufferView);
  105174. const bufferIndex = bufferView.buffer;
  105175. const binChunk = this.gltf.buffers[bufferIndex];
  105176. assert$1(binChunk);
  105177. const byteOffset = (bufferView.byteOffset || 0) + binChunk.byteOffset;
  105178. return new Uint8Array(binChunk.arrayBuffer, byteOffset, bufferView.byteLength);
  105179. }
  105180. getTypedArrayForAccessor(accessor) {
  105181. accessor = this.getAccessor(accessor);
  105182. const bufferView = this.getBufferView(accessor.bufferView);
  105183. const buffer = this.getBuffer(bufferView.buffer);
  105184. const arrayBuffer = buffer.data;
  105185. const {
  105186. ArrayType,
  105187. length
  105188. } = getAccessorArrayTypeAndLength(accessor, bufferView);
  105189. const byteOffset = bufferView.byteOffset + accessor.byteOffset;
  105190. return new ArrayType(arrayBuffer, byteOffset, length);
  105191. }
  105192. getTypedArrayForImageData(image) {
  105193. image = this.getAccessor(image);
  105194. const bufferView = this.getBufferView(image.bufferView);
  105195. const buffer = this.getBuffer(bufferView.buffer);
  105196. const arrayBuffer = buffer.data;
  105197. const byteOffset = bufferView.byteOffset || 0;
  105198. return new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
  105199. }
  105200. addApplicationData(key, data) {
  105201. this.json[key] = data;
  105202. return this;
  105203. }
  105204. addExtraData(key, data) {
  105205. this.json.extras = this.json.extras || {};
  105206. this.json.extras[key] = data;
  105207. return this;
  105208. }
  105209. addObjectExtension(object, extensionName, data) {
  105210. object.extensions = object.extensions || {};
  105211. object.extensions[extensionName] = data;
  105212. this.registerUsedExtension(extensionName);
  105213. return this;
  105214. }
  105215. setObjectExtension(object, extensionName, data) {
  105216. const extensions = object.extensions || {};
  105217. extensions[extensionName] = data;
  105218. }
  105219. removeObjectExtension(object, extensionName) {
  105220. const extensions = object.extensions || {};
  105221. const extension = extensions[extensionName];
  105222. delete extensions[extensionName];
  105223. return extension;
  105224. }
  105225. addExtension(extensionName, extensionData = {}) {
  105226. assert$1(extensionData);
  105227. this.json.extensions = this.json.extensions || {};
  105228. this.json.extensions[extensionName] = extensionData;
  105229. this.registerUsedExtension(extensionName);
  105230. return extensionData;
  105231. }
  105232. addRequiredExtension(extensionName, extensionData = {}) {
  105233. assert$1(extensionData);
  105234. this.addExtension(extensionName, extensionData);
  105235. this.registerRequiredExtension(extensionName);
  105236. return extensionData;
  105237. }
  105238. registerUsedExtension(extensionName) {
  105239. this.json.extensionsUsed = this.json.extensionsUsed || [];
  105240. if (!this.json.extensionsUsed.find(ext => ext === extensionName)) {
  105241. this.json.extensionsUsed.push(extensionName);
  105242. }
  105243. }
  105244. registerRequiredExtension(extensionName) {
  105245. this.registerUsedExtension(extensionName);
  105246. this.json.extensionsRequired = this.json.extensionsRequired || [];
  105247. if (!this.json.extensionsRequired.find(ext => ext === extensionName)) {
  105248. this.json.extensionsRequired.push(extensionName);
  105249. }
  105250. }
  105251. removeExtension(extensionName) {
  105252. if (this.json.extensionsRequired) {
  105253. this._removeStringFromArray(this.json.extensionsRequired, extensionName);
  105254. }
  105255. if (this.json.extensionsUsed) {
  105256. this._removeStringFromArray(this.json.extensionsUsed, extensionName);
  105257. }
  105258. if (this.json.extensions) {
  105259. delete this.json.extensions[extensionName];
  105260. }
  105261. }
  105262. setDefaultScene(sceneIndex) {
  105263. this.json.scene = sceneIndex;
  105264. }
  105265. addScene(scene) {
  105266. const {
  105267. nodeIndices
  105268. } = scene;
  105269. this.json.scenes = this.json.scenes || [];
  105270. this.json.scenes.push({
  105271. nodes: nodeIndices
  105272. });
  105273. return this.json.scenes.length - 1;
  105274. }
  105275. addNode(node) {
  105276. const {
  105277. meshIndex,
  105278. matrix
  105279. } = node;
  105280. this.json.nodes = this.json.nodes || [];
  105281. const nodeData = {
  105282. mesh: meshIndex
  105283. };
  105284. if (matrix) {
  105285. nodeData.matrix = matrix;
  105286. }
  105287. this.json.nodes.push(nodeData);
  105288. return this.json.nodes.length - 1;
  105289. }
  105290. addMesh(mesh) {
  105291. const {
  105292. attributes,
  105293. indices,
  105294. material,
  105295. mode = 4
  105296. } = mesh;
  105297. const accessors = this._addAttributes(attributes);
  105298. const glTFMesh = {
  105299. primitives: [{
  105300. attributes: accessors,
  105301. mode
  105302. }]
  105303. };
  105304. if (indices) {
  105305. const indicesAccessor = this._addIndices(indices);
  105306. glTFMesh.primitives[0].indices = indicesAccessor;
  105307. }
  105308. if (Number.isFinite(material)) {
  105309. glTFMesh.primitives[0].material = material;
  105310. }
  105311. this.json.meshes = this.json.meshes || [];
  105312. this.json.meshes.push(glTFMesh);
  105313. return this.json.meshes.length - 1;
  105314. }
  105315. addPointCloud(attributes) {
  105316. const accessorIndices = this._addAttributes(attributes);
  105317. const glTFMesh = {
  105318. primitives: [{
  105319. attributes: accessorIndices,
  105320. mode: 0
  105321. }]
  105322. };
  105323. this.json.meshes = this.json.meshes || [];
  105324. this.json.meshes.push(glTFMesh);
  105325. return this.json.meshes.length - 1;
  105326. }
  105327. addImage(imageData, mimeTypeOpt) {
  105328. const metadata = getBinaryImageMetadata(imageData);
  105329. const mimeType = mimeTypeOpt || (metadata === null || metadata === void 0 ? void 0 : metadata.mimeType);
  105330. const bufferViewIndex = this.addBufferView(imageData);
  105331. const glTFImage = {
  105332. bufferView: bufferViewIndex,
  105333. mimeType
  105334. };
  105335. this.json.images = this.json.images || [];
  105336. this.json.images.push(glTFImage);
  105337. return this.json.images.length - 1;
  105338. }
  105339. addBufferView(buffer) {
  105340. const byteLength = buffer.byteLength;
  105341. assert$1(Number.isFinite(byteLength));
  105342. this.sourceBuffers = this.sourceBuffers || [];
  105343. this.sourceBuffers.push(buffer);
  105344. const glTFBufferView = {
  105345. buffer: 0,
  105346. byteOffset: this.byteLength,
  105347. byteLength
  105348. };
  105349. this.byteLength += padToNBytes(byteLength, 4);
  105350. this.json.bufferViews = this.json.bufferViews || [];
  105351. this.json.bufferViews.push(glTFBufferView);
  105352. return this.json.bufferViews.length - 1;
  105353. }
  105354. addAccessor(bufferViewIndex, accessor) {
  105355. const glTFAccessor = {
  105356. bufferView: bufferViewIndex,
  105357. type: getAccessorTypeFromSize(accessor.size),
  105358. componentType: accessor.componentType,
  105359. count: accessor.count,
  105360. max: accessor.max,
  105361. min: accessor.min
  105362. };
  105363. this.json.accessors = this.json.accessors || [];
  105364. this.json.accessors.push(glTFAccessor);
  105365. return this.json.accessors.length - 1;
  105366. }
  105367. addBinaryBuffer(sourceBuffer, accessor = {
  105368. size: 3
  105369. }) {
  105370. const bufferViewIndex = this.addBufferView(sourceBuffer);
  105371. let minMax = {
  105372. min: accessor.min,
  105373. max: accessor.max
  105374. };
  105375. if (!minMax.min || !minMax.max) {
  105376. minMax = this._getAccessorMinMax(sourceBuffer, accessor.size);
  105377. }
  105378. const accessorDefaults = {
  105379. size: accessor.size,
  105380. componentType: getComponentTypeFromArray(sourceBuffer),
  105381. count: Math.round(sourceBuffer.length / accessor.size),
  105382. min: minMax.min,
  105383. max: minMax.max
  105384. };
  105385. return this.addAccessor(bufferViewIndex, Object.assign(accessorDefaults, accessor));
  105386. }
  105387. addTexture(texture) {
  105388. const {
  105389. imageIndex
  105390. } = texture;
  105391. const glTFTexture = {
  105392. source: imageIndex
  105393. };
  105394. this.json.textures = this.json.textures || [];
  105395. this.json.textures.push(glTFTexture);
  105396. return this.json.textures.length - 1;
  105397. }
  105398. addMaterial(pbrMaterialInfo) {
  105399. this.json.materials = this.json.materials || [];
  105400. this.json.materials.push(pbrMaterialInfo);
  105401. return this.json.materials.length - 1;
  105402. }
  105403. createBinaryChunk() {
  105404. var _this$json, _this$json$buffers;
  105405. this.gltf.buffers = [];
  105406. const totalByteLength = this.byteLength;
  105407. const arrayBuffer = new ArrayBuffer(totalByteLength);
  105408. const targetArray = new Uint8Array(arrayBuffer);
  105409. let dstByteOffset = 0;
  105410. for (const sourceBuffer of this.sourceBuffers || []) {
  105411. dstByteOffset = copyToArray(sourceBuffer, targetArray, dstByteOffset);
  105412. }
  105413. 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]) {
  105414. this.json.buffers[0].byteLength = totalByteLength;
  105415. } else {
  105416. this.json.buffers = [{
  105417. byteLength: totalByteLength
  105418. }];
  105419. }
  105420. this.gltf.binary = arrayBuffer;
  105421. this.sourceBuffers = [arrayBuffer];
  105422. }
  105423. _removeStringFromArray(array, string) {
  105424. let found = true;
  105425. while (found) {
  105426. const index = array.indexOf(string);
  105427. if (index > -1) {
  105428. array.splice(index, 1);
  105429. } else {
  105430. found = false;
  105431. }
  105432. }
  105433. }
  105434. _addAttributes(attributes = {}) {
  105435. const result = {};
  105436. for (const attributeKey in attributes) {
  105437. const attributeData = attributes[attributeKey];
  105438. const attrName = this._getGltfAttributeName(attributeKey);
  105439. const accessor = this.addBinaryBuffer(attributeData.value, attributeData);
  105440. result[attrName] = accessor;
  105441. }
  105442. return result;
  105443. }
  105444. _addIndices(indices) {
  105445. return this.addBinaryBuffer(indices, {
  105446. size: 1
  105447. });
  105448. }
  105449. _getGltfAttributeName(attributeName) {
  105450. switch (attributeName.toLowerCase()) {
  105451. case 'position':
  105452. case 'positions':
  105453. case 'vertices':
  105454. return 'POSITION';
  105455. case 'normal':
  105456. case 'normals':
  105457. return 'NORMAL';
  105458. case 'color':
  105459. case 'colors':
  105460. return 'COLOR_0';
  105461. case 'texcoord':
  105462. case 'texcoords':
  105463. return 'TEXCOORD_0';
  105464. default:
  105465. return attributeName;
  105466. }
  105467. }
  105468. _getAccessorMinMax(buffer, size) {
  105469. const result = {
  105470. min: null,
  105471. max: null
  105472. };
  105473. if (buffer.length < size) {
  105474. return result;
  105475. }
  105476. result.min = [];
  105477. result.max = [];
  105478. const initValues = buffer.subarray(0, size);
  105479. for (const value of initValues) {
  105480. result.min.push(value);
  105481. result.max.push(value);
  105482. }
  105483. for (let index = size; index < buffer.length; index += size) {
  105484. for (let componentIndex = 0; componentIndex < size; componentIndex++) {
  105485. result.min[0 + componentIndex] = Math.min(result.min[0 + componentIndex], buffer[index + componentIndex]);
  105486. result.max[0 + componentIndex] = Math.max(result.max[0 + componentIndex], buffer[index + componentIndex]);
  105487. }
  105488. }
  105489. return result;
  105490. }
  105491. }
  105492. const isWebAssemblySupported = typeof WebAssembly !== 'object';
  105493. const 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';
  105494. const 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';
  105495. const 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]);
  105496. const 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]);
  105497. const FILTERS = {
  105498. 0: '',
  105499. 1: 'meshopt_decodeFilterOct',
  105500. 2: 'meshopt_decodeFilterQuat',
  105501. 3: 'meshopt_decodeFilterExp',
  105502. NONE: '',
  105503. OCTAHEDRAL: 'meshopt_decodeFilterOct',
  105504. QUATERNION: 'meshopt_decodeFilterQuat',
  105505. EXPONENTIAL: 'meshopt_decodeFilterExp'
  105506. };
  105507. const DECODERS = {
  105508. 0: 'meshopt_decodeVertexBuffer',
  105509. 1: 'meshopt_decodeIndexBuffer',
  105510. 2: 'meshopt_decodeIndexSequence',
  105511. ATTRIBUTES: 'meshopt_decodeVertexBuffer',
  105512. TRIANGLES: 'meshopt_decodeIndexBuffer',
  105513. INDICES: 'meshopt_decodeIndexSequence'
  105514. };
  105515. function isMeshoptSupported() {
  105516. return isWebAssemblySupported;
  105517. }
  105518. async function meshoptDecodeGltfBuffer(target, count, size, source, mode, filter = 'NONE') {
  105519. const instance = await loadWasmInstance();
  105520. decode$5(instance, instance.exports[DECODERS[mode]], target, count, size, source, instance.exports[FILTERS[filter || 'NONE']]);
  105521. }
  105522. let wasmPromise;
  105523. async function loadWasmInstance() {
  105524. if (!wasmPromise) {
  105525. wasmPromise = loadWasmModule();
  105526. }
  105527. return wasmPromise;
  105528. }
  105529. async function loadWasmModule() {
  105530. let wasm = wasm_base;
  105531. if (WebAssembly.validate(detector)) {
  105532. wasm = wasm_simd;
  105533. console.log('Warning: meshopt_decoder is using experimental SIMD support');
  105534. }
  105535. const result = await WebAssembly.instantiate(unpack(wasm), {});
  105536. await result.instance.exports.__wasm_call_ctors();
  105537. return result.instance;
  105538. }
  105539. function unpack(data) {
  105540. const result = new Uint8Array(data.length);
  105541. for (let i = 0; i < data.length; ++i) {
  105542. const ch = data.charCodeAt(i);
  105543. result[i] = ch > 96 ? ch - 71 : ch > 64 ? ch - 65 : ch > 47 ? ch + 4 : ch > 46 ? 63 : 62;
  105544. }
  105545. let write = 0;
  105546. for (let i = 0; i < data.length; ++i) {
  105547. result[write++] = result[i] < 60 ? wasmpack[result[i]] : (result[i] - 60) * 64 + result[++i];
  105548. }
  105549. return result.buffer.slice(0, write);
  105550. }
  105551. function decode$5(instance, fun, target, count, size, source, filter) {
  105552. const sbrk = instance.exports.sbrk;
  105553. const count4 = count + 3 & ~3;
  105554. const tp = sbrk(count4 * size);
  105555. const sp = sbrk(source.length);
  105556. const heap = new Uint8Array(instance.exports.memory.buffer);
  105557. heap.set(source, sp);
  105558. const res = fun(tp, count, size, sp, source.length);
  105559. if (res === 0 && filter) {
  105560. filter(tp, count4, size);
  105561. }
  105562. target.set(heap.subarray(tp, tp + count * size));
  105563. sbrk(tp - sbrk(0));
  105564. if (res !== 0) {
  105565. throw new Error("Malformed buffer data: ".concat(res));
  105566. }
  105567. }
  105568. const EXT_MESHOPT_COMPRESSION = 'EXT_meshopt_compression';
  105569. const name$6 = EXT_MESHOPT_COMPRESSION;
  105570. function preprocess$4(gltfData) {
  105571. const scenegraph = new GLTFScenegraph(gltfData);
  105572. if (scenegraph.getRequiredExtensions().includes(EXT_MESHOPT_COMPRESSION) && !isMeshoptSupported()) {
  105573. throw new Error("gltf: Required extension ".concat(EXT_MESHOPT_COMPRESSION, " not supported by browser"));
  105574. }
  105575. }
  105576. async function decode$4(gltfData, options) {
  105577. var _options$gltf;
  105578. const scenegraph = new GLTFScenegraph(gltfData);
  105579. if (!(options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes)) {
  105580. return;
  105581. }
  105582. const promises = [];
  105583. for (const bufferViewIndex of gltfData.json.bufferViews || []) {
  105584. promises.push(decodeMeshoptBufferView(scenegraph, bufferViewIndex));
  105585. }
  105586. await Promise.all(promises);
  105587. scenegraph.removeExtension(EXT_MESHOPT_COMPRESSION);
  105588. }
  105589. async function decodeMeshoptBufferView(scenegraph, bufferView) {
  105590. const meshoptExtension = scenegraph.getObjectExtension(bufferView, EXT_MESHOPT_COMPRESSION);
  105591. if (meshoptExtension) {
  105592. const buffer = bufferView.buffer;
  105593. const {
  105594. byteOffset = 0,
  105595. byteLength = 0,
  105596. byteStride,
  105597. count,
  105598. mode,
  105599. filter = 'NONE'
  105600. } = meshoptExtension;
  105601. const source = new Uint8Array(buffer, byteOffset, byteLength);
  105602. const result = new ArrayBuffer(count * byteStride);
  105603. await meshoptDecodeGltfBuffer(new Uint8Array(result), count, byteStride, source, mode, filter);
  105604. return result;
  105605. }
  105606. return null;
  105607. }
  105608. var EXT_meshopt_compression = /*#__PURE__*/Object.freeze({
  105609. __proto__: null,
  105610. name: name$6,
  105611. preprocess: preprocess$4,
  105612. decode: decode$4
  105613. });
  105614. const EXT_TEXTURE_WEBP = 'EXT_texture_webp';
  105615. const name$5 = EXT_TEXTURE_WEBP;
  105616. function preprocess$3(gltfData, options) {
  105617. const scenegraph = new GLTFScenegraph(gltfData);
  105618. if (!_isImageFormatSupported('image/webp')) {
  105619. if (scenegraph.getRequiredExtensions().includes(EXT_TEXTURE_WEBP)) {
  105620. throw new Error("gltf: Required extension ".concat(EXT_TEXTURE_WEBP, " not supported by browser"));
  105621. }
  105622. return;
  105623. }
  105624. const {
  105625. json
  105626. } = scenegraph;
  105627. for (const texture of json.textures || []) {
  105628. const extension = scenegraph.getObjectExtension(texture, EXT_TEXTURE_WEBP);
  105629. if (extension) {
  105630. texture.source = extension.source;
  105631. }
  105632. scenegraph.removeObjectExtension(texture, EXT_TEXTURE_WEBP);
  105633. }
  105634. scenegraph.removeExtension(EXT_TEXTURE_WEBP);
  105635. }
  105636. var EXT_texture_webp = /*#__PURE__*/Object.freeze({
  105637. __proto__: null,
  105638. name: name$5,
  105639. preprocess: preprocess$3
  105640. });
  105641. const KHR_TEXTURE_BASISU = 'KHR_texture_basisu';
  105642. const name$4 = KHR_TEXTURE_BASISU;
  105643. function preprocess$2(gltfData, options) {
  105644. const scene = new GLTFScenegraph(gltfData);
  105645. const {
  105646. json
  105647. } = scene;
  105648. for (const texture of json.textures || []) {
  105649. const extension = scene.getObjectExtension(texture, KHR_TEXTURE_BASISU);
  105650. if (extension) {
  105651. texture.source = extension.source;
  105652. }
  105653. scene.removeObjectExtension(texture, KHR_TEXTURE_BASISU);
  105654. }
  105655. scene.removeExtension(KHR_TEXTURE_BASISU);
  105656. }
  105657. var KHR_texture_basisu = /*#__PURE__*/Object.freeze({
  105658. __proto__: null,
  105659. name: name$4,
  105660. preprocess: preprocess$2
  105661. });
  105662. function getGLTFAccessors(attributes) {
  105663. const accessors = {};
  105664. for (const name in attributes) {
  105665. const attribute = attributes[name];
  105666. if (name !== 'indices') {
  105667. const glTFAccessor = getGLTFAccessor(attribute);
  105668. accessors[name] = glTFAccessor;
  105669. }
  105670. }
  105671. return accessors;
  105672. }
  105673. function getGLTFAccessor(attribute) {
  105674. const {
  105675. buffer,
  105676. size,
  105677. count
  105678. } = getAccessorData(attribute);
  105679. const glTFAccessor = {
  105680. value: buffer,
  105681. size,
  105682. byteOffset: 0,
  105683. count,
  105684. type: getAccessorTypeFromSize(size),
  105685. componentType: getComponentTypeFromArray(buffer)
  105686. };
  105687. return glTFAccessor;
  105688. }
  105689. function getAccessorData(attribute) {
  105690. let buffer = attribute;
  105691. let size = 1;
  105692. let count = 0;
  105693. if (attribute && attribute.value) {
  105694. buffer = attribute.value;
  105695. size = attribute.size || 1;
  105696. }
  105697. if (buffer) {
  105698. if (!ArrayBuffer.isView(buffer)) {
  105699. buffer = toTypedArray(buffer, Float32Array);
  105700. }
  105701. count = buffer.length / size;
  105702. }
  105703. return {
  105704. buffer,
  105705. size,
  105706. count
  105707. };
  105708. }
  105709. function toTypedArray(array, ArrayType, convertTypedArrays = false) {
  105710. if (!array) {
  105711. return null;
  105712. }
  105713. if (Array.isArray(array)) {
  105714. return new ArrayType(array);
  105715. }
  105716. if (convertTypedArrays && !(array instanceof ArrayType)) {
  105717. return new ArrayType(array);
  105718. }
  105719. return array;
  105720. }
  105721. const KHR_DRACO_MESH_COMPRESSION = 'KHR_draco_mesh_compression';
  105722. const name$3 = KHR_DRACO_MESH_COMPRESSION;
  105723. function preprocess$1(gltfData, options, context) {
  105724. const scenegraph = new GLTFScenegraph(gltfData);
  105725. for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
  105726. if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) ;
  105727. }
  105728. }
  105729. async function decode$3(gltfData, options, context) {
  105730. var _options$gltf;
  105731. if (!(options !== null && options !== void 0 && (_options$gltf = options.gltf) !== null && _options$gltf !== void 0 && _options$gltf.decompressMeshes)) {
  105732. return;
  105733. }
  105734. const scenegraph = new GLTFScenegraph(gltfData);
  105735. const promises = [];
  105736. for (const primitive of makeMeshPrimitiveIterator(scenegraph)) {
  105737. if (scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION)) {
  105738. promises.push(decompressPrimitive(scenegraph, primitive, options, context));
  105739. }
  105740. }
  105741. await Promise.all(promises);
  105742. scenegraph.removeExtension(KHR_DRACO_MESH_COMPRESSION);
  105743. }
  105744. function encode$3(gltfData, options = {}) {
  105745. const scenegraph = new GLTFScenegraph(gltfData);
  105746. for (const mesh of scenegraph.json.meshes || []) {
  105747. compressMesh(mesh);
  105748. scenegraph.addRequiredExtension(KHR_DRACO_MESH_COMPRESSION);
  105749. }
  105750. }
  105751. async function decompressPrimitive(scenegraph, primitive, options, context) {
  105752. const dracoExtension = scenegraph.getObjectExtension(primitive, KHR_DRACO_MESH_COMPRESSION);
  105753. if (!dracoExtension) {
  105754. return;
  105755. }
  105756. const buffer = scenegraph.getTypedArrayForBufferView(dracoExtension.bufferView);
  105757. const bufferCopy = sliceArrayBuffer(buffer.buffer, buffer.byteOffset);
  105758. const {
  105759. parse
  105760. } = context;
  105761. const dracoOptions = { ...options
  105762. };
  105763. delete dracoOptions['3d-tiles'];
  105764. const decodedData = await parse(bufferCopy, DracoLoader, dracoOptions, context);
  105765. const decodedAttributes = getGLTFAccessors(decodedData.attributes);
  105766. for (const [attributeName, decodedAttribute] of Object.entries(decodedAttributes)) {
  105767. if (attributeName in primitive.attributes) {
  105768. const accessorIndex = primitive.attributes[attributeName];
  105769. const accessor = scenegraph.getAccessor(accessorIndex);
  105770. if (accessor !== null && accessor !== void 0 && accessor.min && accessor !== null && accessor !== void 0 && accessor.max) {
  105771. decodedAttribute.min = accessor.min;
  105772. decodedAttribute.max = accessor.max;
  105773. }
  105774. }
  105775. }
  105776. primitive.attributes = decodedAttributes;
  105777. if (decodedData.indices) {
  105778. primitive.indices = getGLTFAccessor(decodedData.indices);
  105779. }
  105780. checkPrimitive(primitive);
  105781. }
  105782. function compressMesh(attributes, indices, mode = 4, options, context) {
  105783. var _context$parseSync;
  105784. if (!options.DracoWriter) {
  105785. throw new Error('options.gltf.DracoWriter not provided');
  105786. }
  105787. const compressedData = options.DracoWriter.encodeSync({
  105788. attributes
  105789. });
  105790. const decodedData = context === null || context === void 0 ? void 0 : (_context$parseSync = context.parseSync) === null || _context$parseSync === void 0 ? void 0 : _context$parseSync.call(context, {
  105791. attributes
  105792. });
  105793. const fauxAccessors = options._addFauxAttributes(decodedData.attributes);
  105794. const bufferViewIndex = options.addBufferView(compressedData);
  105795. const glTFMesh = {
  105796. primitives: [{
  105797. attributes: fauxAccessors,
  105798. mode,
  105799. extensions: {
  105800. [KHR_DRACO_MESH_COMPRESSION]: {
  105801. bufferView: bufferViewIndex,
  105802. attributes: fauxAccessors
  105803. }
  105804. }
  105805. }]
  105806. };
  105807. return glTFMesh;
  105808. }
  105809. function checkPrimitive(primitive) {
  105810. if (!primitive.attributes && Object.keys(primitive.attributes).length > 0) {
  105811. throw new Error('glTF: Empty primitive detected: Draco decompression failure?');
  105812. }
  105813. }
  105814. function* makeMeshPrimitiveIterator(scenegraph) {
  105815. for (const mesh of scenegraph.json.meshes || []) {
  105816. for (const primitive of mesh.primitives) {
  105817. yield primitive;
  105818. }
  105819. }
  105820. }
  105821. var KHR_draco_mesh_compression = /*#__PURE__*/Object.freeze({
  105822. __proto__: null,
  105823. name: name$3,
  105824. preprocess: preprocess$1,
  105825. decode: decode$3,
  105826. encode: encode$3
  105827. });
  105828. const KHR_LIGHTS_PUNCTUAL = 'KHR_lights_punctual';
  105829. const name$2 = KHR_LIGHTS_PUNCTUAL;
  105830. async function decode$2(gltfData) {
  105831. const gltfScenegraph = new GLTFScenegraph(gltfData);
  105832. const {
  105833. json
  105834. } = gltfScenegraph;
  105835. const extension = gltfScenegraph.getExtension(KHR_LIGHTS_PUNCTUAL);
  105836. if (extension) {
  105837. gltfScenegraph.json.lights = extension.lights;
  105838. gltfScenegraph.removeExtension(KHR_LIGHTS_PUNCTUAL);
  105839. }
  105840. for (const node of json.nodes || []) {
  105841. const nodeExtension = gltfScenegraph.getObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
  105842. if (nodeExtension) {
  105843. node.light = nodeExtension.light;
  105844. }
  105845. gltfScenegraph.removeObjectExtension(node, KHR_LIGHTS_PUNCTUAL);
  105846. }
  105847. }
  105848. async function encode$2(gltfData) {
  105849. const gltfScenegraph = new GLTFScenegraph(gltfData);
  105850. const {
  105851. json
  105852. } = gltfScenegraph;
  105853. if (json.lights) {
  105854. const extension = gltfScenegraph.addExtension(KHR_LIGHTS_PUNCTUAL);
  105855. assert$1(!extension.lights);
  105856. extension.lights = json.lights;
  105857. delete json.lights;
  105858. }
  105859. if (gltfScenegraph.json.lights) {
  105860. for (const light of gltfScenegraph.json.lights) {
  105861. const node = light.node;
  105862. gltfScenegraph.addObjectExtension(node, KHR_LIGHTS_PUNCTUAL, light);
  105863. }
  105864. delete gltfScenegraph.json.lights;
  105865. }
  105866. }
  105867. var KHR_lights_punctual = /*#__PURE__*/Object.freeze({
  105868. __proto__: null,
  105869. name: name$2,
  105870. decode: decode$2,
  105871. encode: encode$2
  105872. });
  105873. const KHR_MATERIALS_UNLIT = 'KHR_materials_unlit';
  105874. const name$1 = KHR_MATERIALS_UNLIT;
  105875. async function decode$1(gltfData) {
  105876. const gltfScenegraph = new GLTFScenegraph(gltfData);
  105877. const {
  105878. json
  105879. } = gltfScenegraph;
  105880. gltfScenegraph.removeExtension(KHR_MATERIALS_UNLIT);
  105881. for (const material of json.materials || []) {
  105882. const extension = material.extensions && material.extensions.KHR_materials_unlit;
  105883. if (extension) {
  105884. material.unlit = true;
  105885. }
  105886. gltfScenegraph.removeObjectExtension(material, KHR_MATERIALS_UNLIT);
  105887. }
  105888. }
  105889. function encode$1(gltfData) {
  105890. const gltfScenegraph = new GLTFScenegraph(gltfData);
  105891. const {
  105892. json
  105893. } = gltfScenegraph;
  105894. if (gltfScenegraph.materials) {
  105895. for (const material of json.materials || []) {
  105896. if (material.unlit) {
  105897. delete material.unlit;
  105898. gltfScenegraph.addObjectExtension(material, KHR_MATERIALS_UNLIT, {});
  105899. gltfScenegraph.addExtension(KHR_MATERIALS_UNLIT);
  105900. }
  105901. }
  105902. }
  105903. }
  105904. var KHR_materials_unlit = /*#__PURE__*/Object.freeze({
  105905. __proto__: null,
  105906. name: name$1,
  105907. decode: decode$1,
  105908. encode: encode$1
  105909. });
  105910. const KHR_TECHNIQUES_WEBGL = 'KHR_techniques_webgl';
  105911. const name$7 = KHR_TECHNIQUES_WEBGL;
  105912. async function decode(gltfData) {
  105913. const gltfScenegraph = new GLTFScenegraph(gltfData);
  105914. const {
  105915. json
  105916. } = gltfScenegraph;
  105917. const extension = gltfScenegraph.getExtension(KHR_TECHNIQUES_WEBGL);
  105918. if (extension) {
  105919. const techniques = resolveTechniques(extension, gltfScenegraph);
  105920. for (const material of json.materials || []) {
  105921. const materialExtension = gltfScenegraph.getObjectExtension(material, KHR_TECHNIQUES_WEBGL);
  105922. if (materialExtension) {
  105923. material.technique = Object.assign({}, materialExtension, techniques[materialExtension.technique]);
  105924. material.technique.values = resolveValues(material.technique, gltfScenegraph);
  105925. }
  105926. gltfScenegraph.removeObjectExtension(material, KHR_TECHNIQUES_WEBGL);
  105927. }
  105928. gltfScenegraph.removeExtension(KHR_TECHNIQUES_WEBGL);
  105929. }
  105930. }
  105931. async function encode(gltfData, options) {}
  105932. function resolveTechniques(techniquesExtension, gltfScenegraph) {
  105933. const {
  105934. programs = [],
  105935. shaders = [],
  105936. techniques = []
  105937. } = techniquesExtension;
  105938. const textDecoder = new TextDecoder();
  105939. shaders.forEach(shader => {
  105940. if (Number.isFinite(shader.bufferView)) {
  105941. shader.code = textDecoder.decode(gltfScenegraph.getTypedArrayForBufferView(shader.bufferView));
  105942. } else {
  105943. throw new Error('KHR_techniques_webgl: no shader code');
  105944. }
  105945. });
  105946. programs.forEach(program => {
  105947. program.fragmentShader = shaders[program.fragmentShader];
  105948. program.vertexShader = shaders[program.vertexShader];
  105949. });
  105950. techniques.forEach(technique => {
  105951. technique.program = programs[technique.program];
  105952. });
  105953. return techniques;
  105954. }
  105955. function resolveValues(technique, gltfScenegraph) {
  105956. const values = Object.assign({}, technique.values);
  105957. Object.keys(technique.uniforms || {}).forEach(uniform => {
  105958. if (technique.uniforms[uniform].value && !(uniform in values)) {
  105959. values[uniform] = technique.uniforms[uniform].value;
  105960. }
  105961. });
  105962. Object.keys(values).forEach(uniform => {
  105963. if (typeof values[uniform] === 'object' && values[uniform].index !== undefined) {
  105964. values[uniform].texture = gltfScenegraph.getTexture(values[uniform].index);
  105965. }
  105966. });
  105967. return values;
  105968. }
  105969. var KHR_techniques_webgl = /*#__PURE__*/Object.freeze({
  105970. __proto__: null,
  105971. name: name$7,
  105972. decode: decode,
  105973. encode: encode
  105974. });
  105975. const EXTENSIONS$2 = [EXT_meshopt_compression, EXT_texture_webp, KHR_texture_basisu, KHR_draco_mesh_compression, KHR_lights_punctual, KHR_materials_unlit, KHR_techniques_webgl];
  105976. function preprocessExtensions(gltf, options = {}, context) {
  105977. const extensions = EXTENSIONS$2.filter(extension => useExtension(extension.name, options));
  105978. for (const extension of extensions) {
  105979. var _extension$preprocess;
  105980. (_extension$preprocess = extension.preprocess) === null || _extension$preprocess === void 0 ? void 0 : _extension$preprocess.call(extension, gltf, options, context);
  105981. }
  105982. }
  105983. async function decodeExtensions(gltf, options = {}, context) {
  105984. const extensions = EXTENSIONS$2.filter(extension => useExtension(extension.name, options));
  105985. for (const extension of extensions) {
  105986. var _extension$decode;
  105987. await ((_extension$decode = extension.decode) === null || _extension$decode === void 0 ? void 0 : _extension$decode.call(extension, gltf, options, context));
  105988. }
  105989. }
  105990. function useExtension(extensionName, options) {
  105991. var _options$gltf;
  105992. const excludes = (options === null || options === void 0 ? void 0 : (_options$gltf = options.gltf) === null || _options$gltf === void 0 ? void 0 : _options$gltf.excludeExtensions) || {};
  105993. const exclude = extensionName in excludes && !excludes[extensionName];
  105994. return !exclude;
  105995. }
  105996. const KHR_BINARY_GLTF = 'KHR_binary_glTF';
  105997. function preprocess(gltfData) {
  105998. const gltfScenegraph = new GLTFScenegraph(gltfData);
  105999. const {
  106000. json
  106001. } = gltfScenegraph;
  106002. for (const image of json.images || []) {
  106003. const extension = gltfScenegraph.getObjectExtension(image, KHR_BINARY_GLTF);
  106004. if (extension) {
  106005. Object.assign(image, extension);
  106006. }
  106007. gltfScenegraph.removeObjectExtension(image, KHR_BINARY_GLTF);
  106008. }
  106009. if (json.buffers && json.buffers[0]) {
  106010. delete json.buffers[0].uri;
  106011. }
  106012. gltfScenegraph.removeExtension(KHR_BINARY_GLTF);
  106013. }
  106014. const GLTF_ARRAYS = {
  106015. accessors: 'accessor',
  106016. animations: 'animation',
  106017. buffers: 'buffer',
  106018. bufferViews: 'bufferView',
  106019. images: 'image',
  106020. materials: 'material',
  106021. meshes: 'mesh',
  106022. nodes: 'node',
  106023. samplers: 'sampler',
  106024. scenes: 'scene',
  106025. skins: 'skin',
  106026. textures: 'texture'
  106027. };
  106028. const GLTF_KEYS = {
  106029. accessor: 'accessors',
  106030. animations: 'animation',
  106031. buffer: 'buffers',
  106032. bufferView: 'bufferViews',
  106033. image: 'images',
  106034. material: 'materials',
  106035. mesh: 'meshes',
  106036. node: 'nodes',
  106037. sampler: 'samplers',
  106038. scene: 'scenes',
  106039. skin: 'skins',
  106040. texture: 'textures'
  106041. };
  106042. class GLTFV1Normalizer {
  106043. constructor() {
  106044. _defineProperty(this, "idToIndexMap", {
  106045. animations: {},
  106046. accessors: {},
  106047. buffers: {},
  106048. bufferViews: {},
  106049. images: {},
  106050. materials: {},
  106051. meshes: {},
  106052. nodes: {},
  106053. samplers: {},
  106054. scenes: {},
  106055. skins: {},
  106056. textures: {}
  106057. });
  106058. _defineProperty(this, "json", void 0);
  106059. }
  106060. normalize(gltf, options) {
  106061. this.json = gltf.json;
  106062. const json = gltf.json;
  106063. switch (json.asset && json.asset.version) {
  106064. case '2.0':
  106065. return;
  106066. case undefined:
  106067. case '1.0':
  106068. break;
  106069. default:
  106070. console.warn("glTF: Unknown version ".concat(json.asset.version));
  106071. return;
  106072. }
  106073. if (!options.normalize) {
  106074. throw new Error('glTF v1 is not supported.');
  106075. }
  106076. console.warn('Converting glTF v1 to glTF v2 format. This is experimental and may fail.');
  106077. this._addAsset(json);
  106078. this._convertTopLevelObjectsToArrays(json);
  106079. preprocess(gltf);
  106080. this._convertObjectIdsToArrayIndices(json);
  106081. this._updateObjects(json);
  106082. this._updateMaterial(json);
  106083. }
  106084. _addAsset(json) {
  106085. json.asset = json.asset || {};
  106086. json.asset.version = '2.0';
  106087. json.asset.generator = json.asset.generator || 'Normalized to glTF 2.0 by loaders.gl';
  106088. }
  106089. _convertTopLevelObjectsToArrays(json) {
  106090. for (const arrayName in GLTF_ARRAYS) {
  106091. this._convertTopLevelObjectToArray(json, arrayName);
  106092. }
  106093. }
  106094. _convertTopLevelObjectToArray(json, mapName) {
  106095. const objectMap = json[mapName];
  106096. if (!objectMap || Array.isArray(objectMap)) {
  106097. return;
  106098. }
  106099. json[mapName] = [];
  106100. for (const id in objectMap) {
  106101. const object = objectMap[id];
  106102. object.id = object.id || id;
  106103. const index = json[mapName].length;
  106104. json[mapName].push(object);
  106105. this.idToIndexMap[mapName][id] = index;
  106106. }
  106107. }
  106108. _convertObjectIdsToArrayIndices(json) {
  106109. for (const arrayName in GLTF_ARRAYS) {
  106110. this._convertIdsToIndices(json, arrayName);
  106111. }
  106112. if ('scene' in json) {
  106113. json.scene = this._convertIdToIndex(json.scene, 'scene');
  106114. }
  106115. for (const texture of json.textures) {
  106116. this._convertTextureIds(texture);
  106117. }
  106118. for (const mesh of json.meshes) {
  106119. this._convertMeshIds(mesh);
  106120. }
  106121. for (const node of json.nodes) {
  106122. this._convertNodeIds(node);
  106123. }
  106124. for (const node of json.scenes) {
  106125. this._convertSceneIds(node);
  106126. }
  106127. }
  106128. _convertTextureIds(texture) {
  106129. if (texture.source) {
  106130. texture.source = this._convertIdToIndex(texture.source, 'image');
  106131. }
  106132. }
  106133. _convertMeshIds(mesh) {
  106134. for (const primitive of mesh.primitives) {
  106135. const {
  106136. attributes,
  106137. indices,
  106138. material
  106139. } = primitive;
  106140. for (const attributeName in attributes) {
  106141. attributes[attributeName] = this._convertIdToIndex(attributes[attributeName], 'accessor');
  106142. }
  106143. if (indices) {
  106144. primitive.indices = this._convertIdToIndex(indices, 'accessor');
  106145. }
  106146. if (material) {
  106147. primitive.material = this._convertIdToIndex(material, 'material');
  106148. }
  106149. }
  106150. }
  106151. _convertNodeIds(node) {
  106152. if (node.children) {
  106153. node.children = node.children.map(child => this._convertIdToIndex(child, 'node'));
  106154. }
  106155. if (node.meshes) {
  106156. node.meshes = node.meshes.map(mesh => this._convertIdToIndex(mesh, 'mesh'));
  106157. }
  106158. }
  106159. _convertSceneIds(scene) {
  106160. if (scene.nodes) {
  106161. scene.nodes = scene.nodes.map(node => this._convertIdToIndex(node, 'node'));
  106162. }
  106163. }
  106164. _convertIdsToIndices(json, topLevelArrayName) {
  106165. if (!json[topLevelArrayName]) {
  106166. console.warn("gltf v1: json doesn't contain attribute ".concat(topLevelArrayName));
  106167. json[topLevelArrayName] = [];
  106168. }
  106169. for (const object of json[topLevelArrayName]) {
  106170. for (const key in object) {
  106171. const id = object[key];
  106172. const index = this._convertIdToIndex(id, key);
  106173. object[key] = index;
  106174. }
  106175. }
  106176. }
  106177. _convertIdToIndex(id, key) {
  106178. const arrayName = GLTF_KEYS[key];
  106179. if (arrayName in this.idToIndexMap) {
  106180. const index = this.idToIndexMap[arrayName][id];
  106181. if (!Number.isFinite(index)) {
  106182. throw new Error("gltf v1: failed to resolve ".concat(key, " with id ").concat(id));
  106183. }
  106184. return index;
  106185. }
  106186. return id;
  106187. }
  106188. _updateObjects(json) {
  106189. for (const buffer of this.json.buffers) {
  106190. delete buffer.type;
  106191. }
  106192. }
  106193. _updateMaterial(json) {
  106194. for (const material of json.materials) {
  106195. material.pbrMetallicRoughness = {
  106196. baseColorFactor: [1, 1, 1, 1],
  106197. metallicFactor: 1,
  106198. roughnessFactor: 1
  106199. };
  106200. const textureId = material.values && material.values.tex;
  106201. const textureIndex = json.textures.findIndex(texture => texture.id === textureId);
  106202. if (textureIndex !== -1) {
  106203. material.pbrMetallicRoughness.baseColorTexture = {
  106204. index: textureIndex
  106205. };
  106206. }
  106207. }
  106208. }
  106209. }
  106210. function normalizeGLTFV1(gltf, options = {}) {
  106211. return new GLTFV1Normalizer().normalize(gltf, options);
  106212. }
  106213. const COMPONENTS = {
  106214. SCALAR: 1,
  106215. VEC2: 2,
  106216. VEC3: 3,
  106217. VEC4: 4,
  106218. MAT2: 4,
  106219. MAT3: 9,
  106220. MAT4: 16
  106221. };
  106222. const BYTES = {
  106223. 5120: 1,
  106224. 5121: 1,
  106225. 5122: 2,
  106226. 5123: 2,
  106227. 5125: 4,
  106228. 5126: 4
  106229. };
  106230. const GL_SAMPLER = {
  106231. TEXTURE_MAG_FILTER: 0x2800,
  106232. TEXTURE_MIN_FILTER: 0x2801,
  106233. TEXTURE_WRAP_S: 0x2802,
  106234. TEXTURE_WRAP_T: 0x2803,
  106235. REPEAT: 0x2901,
  106236. LINEAR: 0x2601,
  106237. NEAREST_MIPMAP_LINEAR: 0x2702
  106238. };
  106239. const SAMPLER_PARAMETER_GLTF_TO_GL = {
  106240. magFilter: GL_SAMPLER.TEXTURE_MAG_FILTER,
  106241. minFilter: GL_SAMPLER.TEXTURE_MIN_FILTER,
  106242. wrapS: GL_SAMPLER.TEXTURE_WRAP_S,
  106243. wrapT: GL_SAMPLER.TEXTURE_WRAP_T
  106244. };
  106245. const DEFAULT_SAMPLER = {
  106246. [GL_SAMPLER.TEXTURE_MAG_FILTER]: GL_SAMPLER.LINEAR,
  106247. [GL_SAMPLER.TEXTURE_MIN_FILTER]: GL_SAMPLER.NEAREST_MIPMAP_LINEAR,
  106248. [GL_SAMPLER.TEXTURE_WRAP_S]: GL_SAMPLER.REPEAT,
  106249. [GL_SAMPLER.TEXTURE_WRAP_T]: GL_SAMPLER.REPEAT
  106250. };
  106251. function getBytesFromComponentType(componentType) {
  106252. return BYTES[componentType];
  106253. }
  106254. function getSizeFromAccessorType(type) {
  106255. return COMPONENTS[type];
  106256. }
  106257. class GLTFPostProcessor {
  106258. constructor() {
  106259. _defineProperty(this, "baseUri", '');
  106260. _defineProperty(this, "json", {});
  106261. _defineProperty(this, "buffers", []);
  106262. _defineProperty(this, "images", []);
  106263. }
  106264. postProcess(gltf, options = {}) {
  106265. const {
  106266. json,
  106267. buffers = [],
  106268. images = [],
  106269. baseUri = ''
  106270. } = gltf;
  106271. assert$1(json);
  106272. this.baseUri = baseUri;
  106273. this.json = json;
  106274. this.buffers = buffers;
  106275. this.images = images;
  106276. this._resolveTree(this.json, options);
  106277. return this.json;
  106278. }
  106279. _resolveTree(json, options = {}) {
  106280. if (json.bufferViews) {
  106281. json.bufferViews = json.bufferViews.map((bufView, i) => this._resolveBufferView(bufView, i));
  106282. }
  106283. if (json.images) {
  106284. json.images = json.images.map((image, i) => this._resolveImage(image, i));
  106285. }
  106286. if (json.samplers) {
  106287. json.samplers = json.samplers.map((sampler, i) => this._resolveSampler(sampler, i));
  106288. }
  106289. if (json.textures) {
  106290. json.textures = json.textures.map((texture, i) => this._resolveTexture(texture, i));
  106291. }
  106292. if (json.accessors) {
  106293. json.accessors = json.accessors.map((accessor, i) => this._resolveAccessor(accessor, i));
  106294. }
  106295. if (json.materials) {
  106296. json.materials = json.materials.map((material, i) => this._resolveMaterial(material, i));
  106297. }
  106298. if (json.meshes) {
  106299. json.meshes = json.meshes.map((mesh, i) => this._resolveMesh(mesh, i));
  106300. }
  106301. if (json.nodes) {
  106302. json.nodes = json.nodes.map((node, i) => this._resolveNode(node, i));
  106303. }
  106304. if (json.skins) {
  106305. json.skins = json.skins.map((skin, i) => this._resolveSkin(skin, i));
  106306. }
  106307. if (json.scenes) {
  106308. json.scenes = json.scenes.map((scene, i) => this._resolveScene(scene, i));
  106309. }
  106310. if (json.scene !== undefined) {
  106311. json.scene = json.scenes[this.json.scene];
  106312. }
  106313. }
  106314. getScene(index) {
  106315. return this._get('scenes', index);
  106316. }
  106317. getNode(index) {
  106318. return this._get('nodes', index);
  106319. }
  106320. getSkin(index) {
  106321. return this._get('skins', index);
  106322. }
  106323. getMesh(index) {
  106324. return this._get('meshes', index);
  106325. }
  106326. getMaterial(index) {
  106327. return this._get('materials', index);
  106328. }
  106329. getAccessor(index) {
  106330. return this._get('accessors', index);
  106331. }
  106332. getCamera(index) {
  106333. return null;
  106334. }
  106335. getTexture(index) {
  106336. return this._get('textures', index);
  106337. }
  106338. getSampler(index) {
  106339. return this._get('samplers', index);
  106340. }
  106341. getImage(index) {
  106342. return this._get('images', index);
  106343. }
  106344. getBufferView(index) {
  106345. return this._get('bufferViews', index);
  106346. }
  106347. getBuffer(index) {
  106348. return this._get('buffers', index);
  106349. }
  106350. _get(array, index) {
  106351. if (typeof index === 'object') {
  106352. return index;
  106353. }
  106354. const object = this.json[array] && this.json[array][index];
  106355. if (!object) {
  106356. console.warn("glTF file error: Could not find ".concat(array, "[").concat(index, "]"));
  106357. }
  106358. return object;
  106359. }
  106360. _resolveScene(scene, index) {
  106361. scene.id = scene.id || "scene-".concat(index);
  106362. scene.nodes = (scene.nodes || []).map(node => this.getNode(node));
  106363. return scene;
  106364. }
  106365. _resolveNode(node, index) {
  106366. node.id = node.id || "node-".concat(index);
  106367. if (node.children) {
  106368. node.children = node.children.map(child => this.getNode(child));
  106369. }
  106370. if (node.mesh !== undefined) {
  106371. node.mesh = this.getMesh(node.mesh);
  106372. } else if (node.meshes !== undefined && node.meshes.length) {
  106373. node.mesh = node.meshes.reduce((accum, meshIndex) => {
  106374. const mesh = this.getMesh(meshIndex);
  106375. accum.id = mesh.id;
  106376. accum.primitives = accum.primitives.concat(mesh.primitives);
  106377. return accum;
  106378. }, {
  106379. primitives: []
  106380. });
  106381. }
  106382. if (node.camera !== undefined) {
  106383. node.camera = this.getCamera(node.camera);
  106384. }
  106385. if (node.skin !== undefined) {
  106386. node.skin = this.getSkin(node.skin);
  106387. }
  106388. return node;
  106389. }
  106390. _resolveSkin(skin, index) {
  106391. skin.id = skin.id || "skin-".concat(index);
  106392. skin.inverseBindMatrices = this.getAccessor(skin.inverseBindMatrices);
  106393. return skin;
  106394. }
  106395. _resolveMesh(mesh, index) {
  106396. mesh.id = mesh.id || "mesh-".concat(index);
  106397. if (mesh.primitives) {
  106398. mesh.primitives = mesh.primitives.map(primitive => {
  106399. primitive = { ...primitive
  106400. };
  106401. const attributes = primitive.attributes;
  106402. primitive.attributes = {};
  106403. for (const attribute in attributes) {
  106404. primitive.attributes[attribute] = this.getAccessor(attributes[attribute]);
  106405. }
  106406. if (primitive.indices !== undefined) {
  106407. primitive.indices = this.getAccessor(primitive.indices);
  106408. }
  106409. if (primitive.material !== undefined) {
  106410. primitive.material = this.getMaterial(primitive.material);
  106411. }
  106412. return primitive;
  106413. });
  106414. }
  106415. return mesh;
  106416. }
  106417. _resolveMaterial(material, index) {
  106418. material.id = material.id || "material-".concat(index);
  106419. if (material.normalTexture) {
  106420. material.normalTexture = { ...material.normalTexture
  106421. };
  106422. material.normalTexture.texture = this.getTexture(material.normalTexture.index);
  106423. }
  106424. if (material.occlusionTexture) {
  106425. material.occlustionTexture = { ...material.occlustionTexture
  106426. };
  106427. material.occlusionTexture.texture = this.getTexture(material.occlusionTexture.index);
  106428. }
  106429. if (material.emissiveTexture) {
  106430. material.emmisiveTexture = { ...material.emmisiveTexture
  106431. };
  106432. material.emissiveTexture.texture = this.getTexture(material.emissiveTexture.index);
  106433. }
  106434. if (!material.emissiveFactor) {
  106435. material.emissiveFactor = material.emmisiveTexture ? [1, 1, 1] : [0, 0, 0];
  106436. }
  106437. if (material.pbrMetallicRoughness) {
  106438. material.pbrMetallicRoughness = { ...material.pbrMetallicRoughness
  106439. };
  106440. const mr = material.pbrMetallicRoughness;
  106441. if (mr.baseColorTexture) {
  106442. mr.baseColorTexture = { ...mr.baseColorTexture
  106443. };
  106444. mr.baseColorTexture.texture = this.getTexture(mr.baseColorTexture.index);
  106445. }
  106446. if (mr.metallicRoughnessTexture) {
  106447. mr.metallicRoughnessTexture = { ...mr.metallicRoughnessTexture
  106448. };
  106449. mr.metallicRoughnessTexture.texture = this.getTexture(mr.metallicRoughnessTexture.index);
  106450. }
  106451. }
  106452. return material;
  106453. }
  106454. _resolveAccessor(accessor, index) {
  106455. accessor.id = accessor.id || "accessor-".concat(index);
  106456. if (accessor.bufferView !== undefined) {
  106457. accessor.bufferView = this.getBufferView(accessor.bufferView);
  106458. }
  106459. accessor.bytesPerComponent = getBytesFromComponentType(accessor.componentType);
  106460. accessor.components = getSizeFromAccessorType(accessor.type);
  106461. accessor.bytesPerElement = accessor.bytesPerComponent * accessor.components;
  106462. if (accessor.bufferView) {
  106463. const buffer = accessor.bufferView.buffer;
  106464. const {
  106465. ArrayType,
  106466. byteLength
  106467. } = getAccessorArrayTypeAndLength(accessor, accessor.bufferView);
  106468. const byteOffset = (accessor.bufferView.byteOffset || 0) + (accessor.byteOffset || 0) + buffer.byteOffset;
  106469. let cutBuffer = buffer.arrayBuffer.slice(byteOffset, byteOffset + byteLength);
  106470. if (accessor.bufferView.byteStride) {
  106471. cutBuffer = this._getValueFromInterleavedBuffer(buffer, byteOffset, accessor.bufferView.byteStride, accessor.bytesPerElement, accessor.count);
  106472. }
  106473. accessor.value = new ArrayType(cutBuffer);
  106474. }
  106475. return accessor;
  106476. }
  106477. _getValueFromInterleavedBuffer(buffer, byteOffset, byteStride, bytesPerElement, count) {
  106478. const result = new Uint8Array(count * bytesPerElement);
  106479. for (let i = 0; i < count; i++) {
  106480. const elementOffset = byteOffset + i * byteStride;
  106481. result.set(new Uint8Array(buffer.arrayBuffer.slice(elementOffset, elementOffset + bytesPerElement)), i * bytesPerElement);
  106482. }
  106483. return result.buffer;
  106484. }
  106485. _resolveTexture(texture, index) {
  106486. texture.id = texture.id || "texture-".concat(index);
  106487. texture.sampler = 'sampler' in texture ? this.getSampler(texture.sampler) : DEFAULT_SAMPLER;
  106488. texture.source = this.getImage(texture.source);
  106489. return texture;
  106490. }
  106491. _resolveSampler(sampler, index) {
  106492. sampler.id = sampler.id || "sampler-".concat(index);
  106493. sampler.parameters = {};
  106494. for (const key in sampler) {
  106495. const glEnum = this._enumSamplerParameter(key);
  106496. if (glEnum !== undefined) {
  106497. sampler.parameters[glEnum] = sampler[key];
  106498. }
  106499. }
  106500. return sampler;
  106501. }
  106502. _enumSamplerParameter(key) {
  106503. return SAMPLER_PARAMETER_GLTF_TO_GL[key];
  106504. }
  106505. _resolveImage(image, index) {
  106506. image.id = image.id || "image-".concat(index);
  106507. if (image.bufferView !== undefined) {
  106508. image.bufferView = this.getBufferView(image.bufferView);
  106509. }
  106510. const preloadedImage = this.images[index];
  106511. if (preloadedImage) {
  106512. image.image = preloadedImage;
  106513. }
  106514. return image;
  106515. }
  106516. _resolveBufferView(bufferView, index) {
  106517. const bufferIndex = bufferView.buffer;
  106518. const result = {
  106519. id: "bufferView-".concat(index),
  106520. ...bufferView,
  106521. buffer: this.buffers[bufferIndex]
  106522. };
  106523. const arrayBuffer = this.buffers[bufferIndex].arrayBuffer;
  106524. let byteOffset = this.buffers[bufferIndex].byteOffset || 0;
  106525. if ('byteOffset' in bufferView) {
  106526. byteOffset += bufferView.byteOffset;
  106527. }
  106528. result.data = new Uint8Array(arrayBuffer, byteOffset, bufferView.byteLength);
  106529. return result;
  106530. }
  106531. _resolveCamera(camera, index) {
  106532. camera.id = camera.id || "camera-".concat(index);
  106533. if (camera.perspective) ;
  106534. if (camera.orthographic) ;
  106535. return camera;
  106536. }
  106537. }
  106538. function postProcessGLTF(gltf, options) {
  106539. return new GLTFPostProcessor().postProcess(gltf, options);
  106540. }
  106541. const MAGIC_glTF = 0x676c5446;
  106542. const GLB_FILE_HEADER_SIZE = 12;
  106543. const GLB_CHUNK_HEADER_SIZE = 8;
  106544. const GLB_CHUNK_TYPE_JSON = 0x4e4f534a;
  106545. const GLB_CHUNK_TYPE_BIN = 0x004e4942;
  106546. const GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED = 0;
  106547. const GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED = 1;
  106548. const GLB_V1_CONTENT_FORMAT_JSON = 0x0;
  106549. const LE = true;
  106550. function getMagicString(dataView, byteOffset = 0) {
  106551. 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)));
  106552. }
  106553. function isGLB(arrayBuffer, byteOffset = 0, options = {}) {
  106554. const dataView = new DataView(arrayBuffer);
  106555. const {
  106556. magic = MAGIC_glTF
  106557. } = options;
  106558. const magic1 = dataView.getUint32(byteOffset, false);
  106559. return magic1 === magic || magic1 === MAGIC_glTF;
  106560. }
  106561. function parseGLBSync(glb, arrayBuffer, byteOffset = 0, options = {}) {
  106562. const dataView = new DataView(arrayBuffer);
  106563. const type = getMagicString(dataView, byteOffset + 0);
  106564. const version = dataView.getUint32(byteOffset + 4, LE);
  106565. const byteLength = dataView.getUint32(byteOffset + 8, LE);
  106566. Object.assign(glb, {
  106567. header: {
  106568. byteOffset,
  106569. byteLength,
  106570. hasBinChunk: false
  106571. },
  106572. type,
  106573. version,
  106574. json: {},
  106575. binChunks: []
  106576. });
  106577. byteOffset += GLB_FILE_HEADER_SIZE;
  106578. switch (glb.version) {
  106579. case 1:
  106580. return parseGLBV1(glb, dataView, byteOffset);
  106581. case 2:
  106582. return parseGLBV2(glb, dataView, byteOffset, options = {});
  106583. default:
  106584. throw new Error("Invalid GLB version ".concat(glb.version, ". Only supports v1 and v2."));
  106585. }
  106586. }
  106587. function parseGLBV1(glb, dataView, byteOffset) {
  106588. assert$7(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
  106589. const contentLength = dataView.getUint32(byteOffset + 0, LE);
  106590. const contentFormat = dataView.getUint32(byteOffset + 4, LE);
  106591. byteOffset += GLB_CHUNK_HEADER_SIZE;
  106592. assert$7(contentFormat === GLB_V1_CONTENT_FORMAT_JSON);
  106593. parseJSONChunk(glb, dataView, byteOffset, contentLength);
  106594. byteOffset += contentLength;
  106595. byteOffset += parseBINChunk(glb, dataView, byteOffset, glb.header.byteLength);
  106596. return byteOffset;
  106597. }
  106598. function parseGLBV2(glb, dataView, byteOffset, options) {
  106599. assert$7(glb.header.byteLength > GLB_FILE_HEADER_SIZE + GLB_CHUNK_HEADER_SIZE);
  106600. parseGLBChunksSync(glb, dataView, byteOffset, options);
  106601. return byteOffset + glb.header.byteLength;
  106602. }
  106603. function parseGLBChunksSync(glb, dataView, byteOffset, options) {
  106604. while (byteOffset + 8 <= glb.header.byteLength) {
  106605. const chunkLength = dataView.getUint32(byteOffset + 0, LE);
  106606. const chunkFormat = dataView.getUint32(byteOffset + 4, LE);
  106607. byteOffset += GLB_CHUNK_HEADER_SIZE;
  106608. switch (chunkFormat) {
  106609. case GLB_CHUNK_TYPE_JSON:
  106610. parseJSONChunk(glb, dataView, byteOffset, chunkLength);
  106611. break;
  106612. case GLB_CHUNK_TYPE_BIN:
  106613. parseBINChunk(glb, dataView, byteOffset, chunkLength);
  106614. break;
  106615. case GLB_CHUNK_TYPE_JSON_XVIZ_DEPRECATED:
  106616. if (!options.strict) {
  106617. parseJSONChunk(glb, dataView, byteOffset, chunkLength);
  106618. }
  106619. break;
  106620. case GLB_CHUNK_TYPE_BIX_XVIZ_DEPRECATED:
  106621. if (!options.strict) {
  106622. parseBINChunk(glb, dataView, byteOffset, chunkLength);
  106623. }
  106624. break;
  106625. }
  106626. byteOffset += padToNBytes(chunkLength, 4);
  106627. }
  106628. return byteOffset;
  106629. }
  106630. function parseJSONChunk(glb, dataView, byteOffset, chunkLength) {
  106631. const jsonChunk = new Uint8Array(dataView.buffer, byteOffset, chunkLength);
  106632. const textDecoder = new TextDecoder('utf8');
  106633. const jsonText = textDecoder.decode(jsonChunk);
  106634. glb.json = JSON.parse(jsonText);
  106635. return padToNBytes(chunkLength, 4);
  106636. }
  106637. function parseBINChunk(glb, dataView, byteOffset, chunkLength) {
  106638. glb.header.hasBinChunk = true;
  106639. glb.binChunks.push({
  106640. byteOffset,
  106641. byteLength: chunkLength,
  106642. arrayBuffer: dataView.buffer
  106643. });
  106644. return padToNBytes(chunkLength, 4);
  106645. }
  106646. async function parseGLTF(gltf, arrayBufferOrString, byteOffset = 0, options, context) {
  106647. var _options$gltf, _options$gltf2, _options$gltf3, _options$gltf4;
  106648. parseGLTFContainerSync(gltf, arrayBufferOrString, byteOffset, options);
  106649. normalizeGLTFV1(gltf, {
  106650. normalize: options === null || options === void 0 ? void 0 : (_options$gltf = options.gltf) === null || _options$gltf === void 0 ? void 0 : _options$gltf.normalize
  106651. });
  106652. preprocessExtensions(gltf, options, context);
  106653. const promises = [];
  106654. if (options !== null && options !== void 0 && (_options$gltf2 = options.gltf) !== null && _options$gltf2 !== void 0 && _options$gltf2.loadBuffers && gltf.json.buffers) {
  106655. await loadBuffers(gltf, options, context);
  106656. }
  106657. if (options !== null && options !== void 0 && (_options$gltf3 = options.gltf) !== null && _options$gltf3 !== void 0 && _options$gltf3.loadImages) {
  106658. const promise = loadImages(gltf, options, context);
  106659. promises.push(promise);
  106660. }
  106661. const promise = decodeExtensions(gltf, options, context);
  106662. promises.push(promise);
  106663. await Promise.all(promises);
  106664. gltf.json.gltfArrayBuffer = arrayBufferOrString; // !zeg add 兼容gltf
  106665. return options !== null && options !== void 0 && (_options$gltf4 = options.gltf) !== null && _options$gltf4 !== void 0 && _options$gltf4.postProcess ? postProcessGLTF(gltf, options) : gltf;
  106666. }
  106667. function parseGLTFContainerSync(gltf, data, byteOffset, options) {
  106668. if (options.uri) {
  106669. gltf.baseUri = options.uri;
  106670. }
  106671. if (data instanceof ArrayBuffer && !isGLB(data, byteOffset, options)) {
  106672. const textDecoder = new TextDecoder();
  106673. data = textDecoder.decode(data);
  106674. }
  106675. if (typeof data === 'string') {
  106676. gltf.json = parseJSON(data);
  106677. } else if (data instanceof ArrayBuffer) {
  106678. const glb = {};
  106679. byteOffset = parseGLBSync(glb, data, byteOffset, options.glb);
  106680. assert$1(glb.type === 'glTF', "Invalid GLB magic string ".concat(glb.type));
  106681. gltf._glb = glb;
  106682. gltf.json = glb.json;
  106683. } else {
  106684. assert$1(false, 'GLTF: must be ArrayBuffer or string');
  106685. }
  106686. const buffers = gltf.json.buffers || [];
  106687. gltf.buffers = new Array(buffers.length).fill(null);
  106688. if (gltf._glb && gltf._glb.header.hasBinChunk) {
  106689. const {
  106690. binChunks
  106691. } = gltf._glb;
  106692. gltf.buffers[0] = {
  106693. arrayBuffer: binChunks[0].arrayBuffer,
  106694. byteOffset: binChunks[0].byteOffset,
  106695. byteLength: binChunks[0].byteLength
  106696. };
  106697. }
  106698. const images = gltf.json.images || [];
  106699. gltf.images = new Array(images.length).fill({});
  106700. }
  106701. async function loadBuffers(gltf, options, context) {
  106702. const buffers = gltf.json.buffers || [];
  106703. for (let i = 0; i < buffers.length; ++i) {
  106704. const buffer = buffers[i];
  106705. if (buffer.uri) {
  106706. var _context$fetch, _response$arrayBuffer;
  106707. const {
  106708. fetch
  106709. } = context;
  106710. assert$1(fetch);
  106711. const uri = resolveUrl(buffer.uri, options);
  106712. const 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));
  106713. const arrayBuffer = await (response === null || response === void 0 ? void 0 : (_response$arrayBuffer = response.arrayBuffer) === null || _response$arrayBuffer === void 0 ? void 0 : _response$arrayBuffer.call(response));
  106714. gltf.buffers[i] = {
  106715. arrayBuffer,
  106716. byteOffset: 0,
  106717. byteLength: arrayBuffer.byteLength
  106718. };
  106719. delete buffer.uri;
  106720. }
  106721. }
  106722. }
  106723. async function loadImages(gltf, options, context) {
  106724. const imageIndices = getReferencesImageIndices(gltf);
  106725. const images = gltf.json.images || [];
  106726. const promises = [];
  106727. for (const imageIndex of imageIndices) {
  106728. promises.push(loadImage(gltf, images[imageIndex], imageIndex, options, context));
  106729. }
  106730. return await Promise.all(promises);
  106731. }
  106732. function getReferencesImageIndices(gltf) {
  106733. const imageIndices = new Set();
  106734. const textures = gltf.json.textures || [];
  106735. for (const texture of textures) {
  106736. if (texture.source !== undefined) {
  106737. imageIndices.add(texture.source);
  106738. }
  106739. }
  106740. return Array.from(imageIndices).sort();
  106741. }
  106742. async function loadImage(gltf, image, index, options, context) {
  106743. const {
  106744. fetch,
  106745. parse
  106746. } = context;
  106747. let arrayBuffer;
  106748. if (image.uri) {
  106749. const uri = resolveUrl(image.uri, options);
  106750. const response = await fetch(uri);
  106751. arrayBuffer = await response.arrayBuffer();
  106752. }
  106753. if (Number.isFinite(image.bufferView)) {
  106754. const array = getTypedArrayForBufferView(gltf.json, gltf.buffers, image.bufferView);
  106755. arrayBuffer = sliceArrayBuffer(array.buffer, array.byteOffset, array.byteLength);
  106756. }
  106757. assert$1(arrayBuffer, 'glTF image has no data');
  106758. let parsedImage = await parse(arrayBuffer, [ImageLoader$1, BasisLoader], {
  106759. mimeType: image.mimeType,
  106760. basis: options.basis || {
  106761. format: selectSupportedBasisFormat()
  106762. }
  106763. }, context);
  106764. if (parsedImage && parsedImage[0]) {
  106765. parsedImage = {
  106766. compressed: true,
  106767. mipmaps: false,
  106768. width: parsedImage[0].width,
  106769. height: parsedImage[0].height,
  106770. data: parsedImage
  106771. };
  106772. }
  106773. gltf.images = gltf.images || [];
  106774. gltf.images[index] = parsedImage;
  106775. }
  106776. const GLTFLoader$1 = {
  106777. name: 'glTF',
  106778. id: 'gltf',
  106779. module: 'gltf',
  106780. version: VERSION$3,
  106781. extensions: ['gltf', 'glb'],
  106782. mimeTypes: ['model/gltf+json', 'model/gltf-binary'],
  106783. text: true,
  106784. binary: true,
  106785. tests: ['glTF'],
  106786. parse: parse$1,
  106787. options: {
  106788. gltf: {
  106789. normalize: true,
  106790. loadBuffers: true,
  106791. loadImages: true,
  106792. decompressMeshes: true,
  106793. postProcess: true
  106794. },
  106795. log: console
  106796. },
  106797. deprecatedOptions: {
  106798. fetchImages: 'gltf.loadImages',
  106799. createImages: 'gltf.loadImages',
  106800. decompress: 'gltf.decompressMeshes',
  106801. postProcess: 'gltf.postProcess',
  106802. gltf: {
  106803. decompress: 'gltf.decompressMeshes'
  106804. }
  106805. }
  106806. };
  106807. async function parse$1(arrayBuffer, options = {}, context) {
  106808. options = { ...GLTFLoader$1.options,
  106809. ...options
  106810. };
  106811. options.gltf = { ...GLTFLoader$1.options.gltf,
  106812. ...options.gltf
  106813. };
  106814. const {
  106815. byteOffset = 0
  106816. } = options;
  106817. const gltf = {};
  106818. return await parseGLTF(gltf, arrayBuffer, byteOffset, options, context);
  106819. }
  106820. const GLTF_FORMAT = {
  106821. URI: 0,
  106822. EMBEDDED: 1
  106823. };
  106824. function parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options) {
  106825. tile.rotateYtoZ = true;
  106826. const gltfByteLength = tile.byteOffset + tile.byteLength - byteOffset;
  106827. if (gltfByteLength === 0) {
  106828. throw new Error('glTF byte length must be greater than 0.');
  106829. }
  106830. tile.gltfUpAxis = options['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis ? options['3d-tiles'].assetGltfUpAxis : 'Y';
  106831. tile.gltfArrayBuffer = sliceArrayBuffer(arrayBuffer, byteOffset, gltfByteLength);
  106832. tile.gltfByteOffset = 0;
  106833. tile.gltfByteLength = gltfByteLength;
  106834. if (byteOffset % 4 === 0) ; else {
  106835. console.warn("".concat(tile.type, ": embedded glb is not aligned to a 4-byte boundary."));
  106836. }
  106837. return tile.byteOffset + tile.byteLength;
  106838. }
  106839. async function extractGLTF(tile, gltfFormat, options, context) {
  106840. const tile3DOptions = options['3d-tiles'] || {};
  106841. extractGLTFBufferOrURL(tile, gltfFormat);
  106842. if (tile3DOptions.loadGLTF) {
  106843. const {
  106844. parse,
  106845. fetch
  106846. } = context;
  106847. if (tile.gltfUrl) {
  106848. tile.gltfArrayBuffer = await fetch(tile.gltfUrl, options);
  106849. tile.gltfByteOffset = 0;
  106850. }
  106851. if (tile.gltfArrayBuffer) {
  106852. tile.gltf = await parse(tile.gltfArrayBuffer, GLTFLoader$1, options, context);
  106853. delete tile.gltfArrayBuffer;
  106854. delete tile.gltfByteOffset;
  106855. delete tile.gltfByteLength;
  106856. }
  106857. }
  106858. }
  106859. function extractGLTFBufferOrURL(tile, gltfFormat, options) {
  106860. switch (gltfFormat) {
  106861. case GLTF_FORMAT.URI:
  106862. const gltfUrlBytes = new Uint8Array(tile.gltfArrayBuffer, tile.gltfByteOffset);
  106863. const textDecoder = new TextDecoder();
  106864. const gltfUrl = textDecoder.decode(gltfUrlBytes);
  106865. tile.gltfUrl = gltfUrl.replace(/[\s\0]+$/, '');
  106866. delete tile.gltfArrayBuffer;
  106867. delete tile.gltfByteOffset;
  106868. delete tile.gltfByteLength;
  106869. break;
  106870. case GLTF_FORMAT.EMBEDDED:
  106871. break;
  106872. default:
  106873. throw new Error('b3dm: Illegal glTF format field');
  106874. }
  106875. }
  106876. async function parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
  106877. var _tile$gltf;
  106878. byteOffset = parseBatchedModel(tile, arrayBuffer, byteOffset, options);
  106879. await extractGLTF(tile, GLTF_FORMAT.EMBEDDED, options, context);
  106880. const extensions = tile === null || tile === void 0 ? void 0 : (_tile$gltf = tile.gltf) === null || _tile$gltf === void 0 ? void 0 : _tile$gltf.extensions;
  106881. if (extensions && extensions.CESIUM_RTC) {
  106882. tile.rtcCenter = extensions.CESIUM_RTC.center;
  106883. }
  106884. return byteOffset;
  106885. }
  106886. function parseBatchedModel(tile, arrayBuffer, byteOffset, options, context) {
  106887. byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
  106888. byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
  106889. byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset);
  106890. byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
  106891. const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
  106892. tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL$1.FLOAT, 3);
  106893. return byteOffset;
  106894. }
  106895. async function parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context) {
  106896. byteOffset = parseInstancedModel(tile, arrayBuffer, byteOffset, options);
  106897. await extractGLTF(tile, tile.gltfFormat, options, context);
  106898. return byteOffset;
  106899. }
  106900. function parseInstancedModel(tile, arrayBuffer, byteOffset, options, context) {
  106901. byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
  106902. if (tile.version !== 1) {
  106903. throw new Error("Instanced 3D Model version ".concat(tile.version, " is not supported"));
  106904. }
  106905. byteOffset = parse3DTileTablesHeaderSync(tile, arrayBuffer, byteOffset);
  106906. const view = new DataView(arrayBuffer);
  106907. tile.gltfFormat = view.getUint32(byteOffset, true);
  106908. byteOffset += 4;
  106909. byteOffset = parse3DTileTablesSync(tile, arrayBuffer, byteOffset);
  106910. byteOffset = parse3DTileGLTFViewSync(tile, arrayBuffer, byteOffset, options);
  106911. if (tile.featureTableJsonByteLength === 0) {
  106912. throw new Error('i3dm parser: featureTableJsonByteLength is zero.');
  106913. }
  106914. const featureTable = new Tile3DFeatureTable(tile.featureTableJson, tile.featureTableBinary);
  106915. const instancesLength = featureTable.getGlobalProperty('INSTANCES_LENGTH');
  106916. featureTable.featuresLength = instancesLength;
  106917. if (!Number.isFinite(instancesLength)) {
  106918. throw new Error('i3dm parser: INSTANCES_LENGTH must be defined');
  106919. }
  106920. tile.eastNorthUp = featureTable.getGlobalProperty('EAST_NORTH_UP');
  106921. tile.rtcCenter = featureTable.getGlobalProperty('RTC_CENTER', GL$1.FLOAT, 3);
  106922. const batchTable = new Tile3DBatchTableParser(tile.batchTableJson, tile.batchTableBinary, instancesLength);
  106923. extractInstancedAttributes(tile, featureTable, batchTable, instancesLength);
  106924. return byteOffset;
  106925. }
  106926. function extractInstancedAttributes(tile, featureTable, batchTable, instancesLength) {
  106927. const collectionOptions = {
  106928. instances: new Array(instancesLength),
  106929. batchTable: tile._batchTable,
  106930. cull: false,
  106931. url: undefined,
  106932. gltf: undefined,
  106933. basePath: undefined,
  106934. incrementallyLoadTextures: false,
  106935. forwardAxis: [1, 0, 0]
  106936. };
  106937. const instances = collectionOptions.instances;
  106938. const instancePosition = new Vector3$1();
  106939. new Vector3$1();
  106940. new Vector3$1();
  106941. new Vector3$1();
  106942. const instanceRotation = new Matrix3$1();
  106943. const instanceQuaternion = new Quaternion$1();
  106944. const instanceScale = new Vector3$1();
  106945. const instanceTranslationRotationScale = {};
  106946. const instanceTransform = new Matrix4$1();
  106947. const scratch1 = [];
  106948. const scratch2 = [];
  106949. const scratchVector1 = new Vector3$1();
  106950. const scratchVector2 = new Vector3$1();
  106951. for (let i = 0; i < instancesLength; i++) {
  106952. let position;
  106953. if (featureTable.hasProperty('POSITION')) {
  106954. position = featureTable.getProperty('POSITION', GL$1.FLOAT, 3, i, instancePosition);
  106955. } else if (featureTable.hasProperty('POSITION_QUANTIZED')) {
  106956. position = featureTable.getProperty('POSITION_QUANTIZED', GL$1.UNSIGNED_SHORT, 3, i, instancePosition);
  106957. const quantizedVolumeOffset = featureTable.getGlobalProperty('QUANTIZED_VOLUME_OFFSET', GL$1.FLOAT, 3, scratchVector1);
  106958. if (!quantizedVolumeOffset) {
  106959. throw new Error('i3dm parser: QUANTIZED_VOLUME_OFFSET must be defined for quantized positions.');
  106960. }
  106961. const quantizedVolumeScale = featureTable.getGlobalProperty('QUANTIZED_VOLUME_SCALE', GL$1.FLOAT, 3, scratchVector2);
  106962. if (!quantizedVolumeScale) {
  106963. throw new Error('i3dm parser: QUANTIZED_VOLUME_SCALE must be defined for quantized positions.');
  106964. }
  106965. const MAX_UNSIGNED_SHORT = 65535.0;
  106966. for (let j = 0; j < 3; j++) {
  106967. position[j] = position[j] / MAX_UNSIGNED_SHORT * quantizedVolumeScale[j] + quantizedVolumeOffset[j];
  106968. }
  106969. }
  106970. if (!position) {
  106971. throw new Error('i3dm: POSITION or POSITION_QUANTIZED must be defined for each instance.');
  106972. }
  106973. instancePosition.copy(position);
  106974. instanceTranslationRotationScale.translation = instancePosition;
  106975. tile.normalUp = featureTable.getProperty('NORMAL_UP', GL$1.FLOAT, 3, i, scratch1);
  106976. tile.normalRight = featureTable.getProperty('NORMAL_RIGHT', GL$1.FLOAT, 3, i, scratch2);
  106977. if (tile.normalUp) {
  106978. if (!tile.normalRight) {
  106979. throw new Error('i3dm: Custom orientation requires both NORMAL_UP and NORMAL_RIGHT.');
  106980. }
  106981. tile.hasCustomOrientation = true;
  106982. } else {
  106983. tile.octNormalUp = featureTable.getProperty('NORMAL_UP_OCT32P', GL$1.UNSIGNED_SHORT, 2, scratch1);
  106984. tile.octNormalRight = featureTable.getProperty('NORMAL_RIGHT_OCT32P', GL$1.UNSIGNED_SHORT, 2, scratch2);
  106985. if (tile.octNormalUp) {
  106986. if (!tile.octNormalRight) {
  106987. throw new Error('i3dm: oct-encoded orientation requires NORMAL_UP_OCT32P and NORMAL_RIGHT_OCT32P');
  106988. }
  106989. throw new Error('i3dm: oct-encoded orientation not implemented');
  106990. } else if (tile.eastNorthUp) {
  106991. Ellipsoid.WGS84.eastNorthUpToFixedFrame(instancePosition, instanceTransform);
  106992. instanceTransform.getRotationMatrix3(instanceRotation);
  106993. } else {
  106994. instanceRotation.identity();
  106995. }
  106996. }
  106997. instanceQuaternion.fromMatrix3(instanceRotation);
  106998. instanceTranslationRotationScale.rotation = instanceQuaternion;
  106999. instanceScale.set(1.0, 1.0, 1.0);
  107000. const scale = featureTable.getProperty('SCALE', GL$1.FLOAT, 1, i);
  107001. if (Number.isFinite(scale)) {
  107002. instanceScale.multiplyByScalar(scale);
  107003. }
  107004. const nonUniformScale = featureTable.getProperty('SCALE_NON_UNIFORM', GL$1.FLOAT, 3, i, scratch1);
  107005. if (nonUniformScale) {
  107006. instanceScale.scale(nonUniformScale);
  107007. }
  107008. instanceTranslationRotationScale.scale = instanceScale;
  107009. let batchId = featureTable.getProperty('BATCH_ID', GL$1.UNSIGNED_SHORT, 1, i);
  107010. if (batchId === undefined) {
  107011. batchId = i;
  107012. }
  107013. const rotationMatrix = new Matrix4$1().fromQuaternion(instanceTranslationRotationScale.rotation);
  107014. instanceTransform.identity();
  107015. instanceTransform.translate(instanceTranslationRotationScale.translation);
  107016. instanceTransform.multiplyRight(rotationMatrix);
  107017. instanceTransform.scale(instanceTranslationRotationScale.scale);
  107018. const modelMatrix = instanceTransform.clone();
  107019. instances[i] = {
  107020. modelMatrix,
  107021. batchId
  107022. };
  107023. }
  107024. tile.instances = instances;
  107025. }
  107026. async function parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile) {
  107027. byteOffset = parse3DTileHeaderSync(tile, arrayBuffer, byteOffset);
  107028. const view = new DataView(arrayBuffer);
  107029. tile.tilesLength = view.getUint32(byteOffset, true);
  107030. byteOffset += 4;
  107031. tile.tiles = [];
  107032. while (tile.tiles.length < tile.tilesLength && tile.byteLength - byteOffset > 12) {
  107033. const subtile = {};
  107034. tile.tiles.push(subtile);
  107035. byteOffset = await parse3DTile(arrayBuffer, byteOffset, options, context, subtile);
  107036. }
  107037. return byteOffset;
  107038. }
  107039. async function parseGltf3DTile(tile, arrayBuffer, options, context) {
  107040. tile.rotateYtoZ = true;
  107041. tile.gltfUpAxis = options['3d-tiles'] && options['3d-tiles'].assetGltfUpAxis ? options['3d-tiles'].assetGltfUpAxis : 'Y';
  107042. const {
  107043. parse
  107044. } = context;
  107045. tile.gltf = await parse(arrayBuffer, GLTFLoader$1, options, context);
  107046. }
  107047. async function parse3DTile(arrayBuffer, byteOffset = 0, options, context, tile = {}) {
  107048. tile.byteOffset = byteOffset;
  107049. tile.type = getMagicString$1(arrayBuffer, byteOffset);
  107050. switch (tile.type) {
  107051. case TILE3D_TYPE.COMPOSITE:
  107052. return await parseComposite3DTile(tile, arrayBuffer, byteOffset, options, context, parse3DTile);
  107053. case TILE3D_TYPE.BATCHED_3D_MODEL:
  107054. return await parseBatchedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
  107055. case TILE3D_TYPE.GLTF:
  107056. return await parseGltf3DTile(tile, arrayBuffer, options, context);
  107057. case TILE3D_TYPE.INSTANCED_3D_MODEL:
  107058. return await parseInstancedModel3DTile(tile, arrayBuffer, byteOffset, options, context);
  107059. case TILE3D_TYPE.POINT_CLOUD:
  107060. return await parsePointCloud3DTile(tile, arrayBuffer, byteOffset, options, context);
  107061. default:
  107062. throw new Error("3DTileLoader: unknown type ".concat(tile.type));
  107063. }
  107064. }
  107065. const SUBTREE_FILE_MAGIC = 0x74627573;
  107066. const SUBTREE_FILE_VERSION = 1;
  107067. async function parse3DTilesSubtree(data) {
  107068. const magic = new Uint32Array(data.slice(0, 4));
  107069. if (magic[0] !== SUBTREE_FILE_MAGIC) {
  107070. throw new Error('Wrong subtree file magic number');
  107071. }
  107072. const version = new Uint32Array(data.slice(4, 8));
  107073. if (version[0] !== SUBTREE_FILE_VERSION) {
  107074. throw new Error('Wrong subtree file verson, must be 1');
  107075. }
  107076. const jsonByteLength = parseUint64Value(data.slice(8, 16));
  107077. const stringAttribute = new Uint8Array(data, 24, jsonByteLength);
  107078. const textDecoder = new TextDecoder('utf8');
  107079. const string = textDecoder.decode(stringAttribute);
  107080. const subtree = JSON.parse(string);
  107081. const binaryByteLength = parseUint64Value(data.slice(16, 24));
  107082. let internalBinaryBuffer = new ArrayBuffer(0);
  107083. if (binaryByteLength) {
  107084. internalBinaryBuffer = data.slice(24 + jsonByteLength);
  107085. }
  107086. if ('bufferView' in subtree.tileAvailability) {
  107087. subtree.tileAvailability.explicitBitstream = await getExplicitBitstream(subtree, 'tileAvailability', internalBinaryBuffer);
  107088. }
  107089. if ('bufferView' in subtree.contentAvailability) {
  107090. subtree.contentAvailability.explicitBitstream = await getExplicitBitstream(subtree, 'contentAvailability', internalBinaryBuffer);
  107091. }
  107092. if ('bufferView' in subtree.childSubtreeAvailability) {
  107093. subtree.childSubtreeAvailability.explicitBitstream = await getExplicitBitstream(subtree, 'childSubtreeAvailability', internalBinaryBuffer);
  107094. }
  107095. return subtree;
  107096. }
  107097. async function getExplicitBitstream(subtree, name, internalBinaryBuffer) {
  107098. const bufferViewIndex = subtree[name].bufferView;
  107099. const bufferView = subtree.bufferViews[bufferViewIndex];
  107100. const buffer = subtree.buffers[bufferView.buffer];
  107101. if (buffer.uri) {
  107102. const response = await fetchFile(buffer.uri);
  107103. const data = await response.arrayBuffer();
  107104. return new Uint8Array(data, bufferView.byteOffset, bufferView.byteLength);
  107105. }
  107106. return new Uint8Array(internalBinaryBuffer, bufferView.byteOffset, bufferView.byteLength);
  107107. }
  107108. function parseUint64Value(buffer) {
  107109. const dataView = new DataView(buffer);
  107110. const left = dataView.getUint32(0, true);
  107111. const right = dataView.getUint32(4, true);
  107112. return left + 2 ** 32 * right;
  107113. }
  107114. const Tile3DSubtreeLoader = {
  107115. id: '3d-tiles-subtree',
  107116. name: '3D Tiles Subtree',
  107117. module: '3d-tiles',
  107118. version: VERSION$5,
  107119. extensions: ['subtree'],
  107120. mimeTypes: ['application/octet-stream'],
  107121. tests: ['subtree'],
  107122. parse: parse3DTilesSubtree,
  107123. options: {}
  107124. };
  107125. const QUADTREE_DEVISION_COUNT = 4;
  107126. const OCTREE_DEVISION_COUNT = 8;
  107127. const SUBDIVISION_COUNT_MAP = {
  107128. QUADTREE: QUADTREE_DEVISION_COUNT,
  107129. OCTREE: OCTREE_DEVISION_COUNT
  107130. };
  107131. async function parseImplicitTiles(subtree, options, parentData = {
  107132. mortonIndex: 0,
  107133. x: 0,
  107134. y: 0,
  107135. z: 0
  107136. }, childIndex = 0, level = 0, globalData = {
  107137. level: 0,
  107138. mortonIndex: 0,
  107139. x: 0,
  107140. y: 0,
  107141. z: 0
  107142. }) {
  107143. const {
  107144. subdivisionScheme,
  107145. subtreeLevels,
  107146. maximumLevel,
  107147. contentUrlTemplate,
  107148. subtreesUriTemplate,
  107149. basePath
  107150. } = options;
  107151. const tile = {
  107152. children: [],
  107153. lodMetricValue: 0,
  107154. contentUrl: ''
  107155. };
  107156. const childrenPerTile = SUBDIVISION_COUNT_MAP[subdivisionScheme];
  107157. const childX = childIndex & 0b01;
  107158. const childY = childIndex >> 1 & 0b01;
  107159. const childZ = childIndex >> 2 & 0b01;
  107160. const levelOffset = (childrenPerTile ** level - 1) / (childrenPerTile - 1);
  107161. let childTileMortonIndex = concatBits(parentData.mortonIndex, childIndex);
  107162. let tileAvailabilityIndex = levelOffset + childTileMortonIndex;
  107163. let childTileX = concatBits(parentData.x, childX);
  107164. let childTileY = concatBits(parentData.y, childY);
  107165. let childTileZ = concatBits(parentData.z, childZ);
  107166. let isChildSubtreeAvailable = false;
  107167. if (level + 1 > subtreeLevels) {
  107168. isChildSubtreeAvailable = getAvailabilityResult(subtree.childSubtreeAvailability, childTileMortonIndex);
  107169. }
  107170. const x = concatBits(globalData.x, childTileX);
  107171. const y = concatBits(globalData.y, childTileY);
  107172. const z = concatBits(globalData.z, childTileZ);
  107173. const lev = level + globalData.level;
  107174. if (isChildSubtreeAvailable) {
  107175. const subtreePath = "".concat(basePath, "/").concat(subtreesUriTemplate);
  107176. const childSubtreeUrl = replaceContentUrlTemplate(subtreePath, lev, x, y, z);
  107177. const childSubtree = await load(childSubtreeUrl, Tile3DSubtreeLoader);
  107178. subtree = childSubtree;
  107179. globalData.mortonIndex = childTileMortonIndex;
  107180. globalData.x = childTileX;
  107181. globalData.y = childTileY;
  107182. globalData.z = childTileZ;
  107183. globalData.level = level;
  107184. childTileMortonIndex = 0;
  107185. tileAvailabilityIndex = 0;
  107186. childTileX = 0;
  107187. childTileY = 0;
  107188. childTileZ = 0;
  107189. level = 0;
  107190. }
  107191. const isTileAvailable = getAvailabilityResult(subtree.tileAvailability, tileAvailabilityIndex);
  107192. if (!isTileAvailable || level > maximumLevel) {
  107193. return tile;
  107194. }
  107195. const isContentAvailable = getAvailabilityResult(subtree.contentAvailability, tileAvailabilityIndex);
  107196. if (isContentAvailable) {
  107197. tile.contentUrl = replaceContentUrlTemplate(contentUrlTemplate, lev, x, y, z);
  107198. }
  107199. const childTileLevel = level + 1;
  107200. const pData = {
  107201. mortonIndex: childTileMortonIndex,
  107202. x: childTileX,
  107203. y: childTileY,
  107204. z: childTileZ
  107205. };
  107206. for (let index = 0; index < childrenPerTile; index++) {
  107207. const currentTile = await parseImplicitTiles(subtree, options, pData, index, childTileLevel, globalData);
  107208. if (currentTile.contentUrl || currentTile.children.length) {
  107209. const globalLevel = lev + 1;
  107210. const childCoordinates = {
  107211. childTileX,
  107212. childTileY,
  107213. childTileZ
  107214. };
  107215. const formattedTile = formatTileData(currentTile, globalLevel, childCoordinates, options);
  107216. tile.children.push(formattedTile);
  107217. }
  107218. }
  107219. return tile;
  107220. }
  107221. function getAvailabilityResult(availabilityData, index) {
  107222. if ('constant' in availabilityData) {
  107223. return Boolean(availabilityData.constant);
  107224. }
  107225. if (availabilityData.explicitBitstream) {
  107226. return getBooleanValueFromBitstream(index, availabilityData.explicitBitstream);
  107227. }
  107228. return false;
  107229. }
  107230. function formatTileData(tile, level, childCoordinates, options) {
  107231. const {
  107232. basePath,
  107233. refine,
  107234. getRefine,
  107235. lodMetricType,
  107236. getTileType,
  107237. rootLodMetricValue,
  107238. rootBoundingVolume
  107239. } = options;
  107240. const uri = tile.contentUrl && tile.contentUrl.replace("".concat(basePath, "/"), '');
  107241. const lodMetricValue = rootLodMetricValue / 2 ** level;
  107242. const boundingVolume = calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates);
  107243. return {
  107244. children: tile.children,
  107245. contentUrl: tile.contentUrl,
  107246. content: {
  107247. uri
  107248. },
  107249. id: tile.contentUrl,
  107250. refine: getRefine(refine),
  107251. type: getTileType(tile),
  107252. lodMetricType,
  107253. lodMetricValue,
  107254. boundingVolume
  107255. };
  107256. }
  107257. function calculateBoundingVolumeForChildTile(level, rootBoundingVolume, childCoordinates) {
  107258. if (rootBoundingVolume.region) {
  107259. const {
  107260. childTileX,
  107261. childTileY,
  107262. childTileZ
  107263. } = childCoordinates;
  107264. const [west, south, east, north, minimumHeight, maximumHeight] = rootBoundingVolume.region;
  107265. const boundingVolumesCount = 2 ** level;
  107266. const sizeX = (east - west) / boundingVolumesCount;
  107267. const sizeY = (north - south) / boundingVolumesCount;
  107268. const sizeZ = (maximumHeight - minimumHeight) / boundingVolumesCount;
  107269. const [childWest, childEast] = [west + sizeX * childTileX, west + sizeX * (childTileX + 1)];
  107270. const [childSouth, childNorth] = [south + sizeY * childTileY, south + sizeY * (childTileY + 1)];
  107271. const [childMinimumHeight, childMaximumHeight] = [minimumHeight + sizeZ * childTileZ, minimumHeight + sizeZ * (childTileZ + 1)];
  107272. return {
  107273. region: [childWest, childSouth, childEast, childNorth, childMinimumHeight, childMaximumHeight]
  107274. };
  107275. }
  107276. console.warn('Unsupported bounding volume type: ', rootBoundingVolume);
  107277. return null;
  107278. }
  107279. function concatBits(first, second) {
  107280. return parseInt(first.toString(2) + second.toString(2), 2);
  107281. }
  107282. function replaceContentUrlTemplate(templateUrl, level, x, y, z) {
  107283. const mapUrl = generateMapUrl({
  107284. level,
  107285. x,
  107286. y,
  107287. z
  107288. });
  107289. return templateUrl.replace(/{level}|{x}|{y}|{z}/gi, matched => mapUrl[matched]);
  107290. }
  107291. function generateMapUrl(items) {
  107292. const mapUrl = {};
  107293. for (const key in items) {
  107294. mapUrl["{".concat(key, "}")] = items[key];
  107295. }
  107296. return mapUrl;
  107297. }
  107298. function getBooleanValueFromBitstream(availabilityIndex, availabilityBuffer) {
  107299. const byteIndex = Math.floor(availabilityIndex / 8);
  107300. const bitIndex = availabilityIndex % 8;
  107301. const bitValue = availabilityBuffer[byteIndex] >> bitIndex & 1;
  107302. return bitValue === 1;
  107303. }
  107304. function getTileType(tile) {
  107305. if (!tile.contentUrl) {
  107306. return TILE_TYPE.EMPTY;
  107307. }
  107308. const contentUrl = tile.contentUrl;
  107309. const fileExtension = contentUrl.split('.').pop();
  107310. switch (fileExtension) {
  107311. case 'pnts':
  107312. return TILE_TYPE.POINTCLOUD;
  107313. case 'i3dm':
  107314. case 'b3dm':
  107315. case 'glb':
  107316. case 'gltf':
  107317. return TILE_TYPE.SCENEGRAPH;
  107318. default:
  107319. return fileExtension;
  107320. }
  107321. }
  107322. function getRefine(refine) {
  107323. switch (refine) {
  107324. case 'REPLACE':
  107325. case 'replace':
  107326. return TILE_REFINEMENT.REPLACE;
  107327. case 'ADD':
  107328. case 'add':
  107329. return TILE_REFINEMENT.ADD;
  107330. default:
  107331. return refine;
  107332. }
  107333. }
  107334. function normalizeTileData(tile, options) {
  107335. if (!tile) {
  107336. return null;
  107337. }
  107338. if (tile.content) {
  107339. const contentUri = tile.content.uri || tile.content.url;
  107340. tile.contentUrl = "".concat(options.basePath, "/").concat(contentUri);
  107341. }
  107342. tile.id = tile.contentUrl;
  107343. tile.lodMetricType = LOD_METRIC_TYPE.GEOMETRIC_ERROR;
  107344. tile.lodMetricValue = tile.geometricError;
  107345. tile.transformMatrix = tile.transform;
  107346. tile.type = getTileType(tile);
  107347. tile.refine = getRefine(tile.refine);
  107348. return tile;
  107349. }
  107350. function normalizeTileHeaders(tileset) {
  107351. const basePath = tileset.basePath;
  107352. const root = normalizeTileData(tileset.root, tileset);
  107353. const stack = [];
  107354. stack.push(root);
  107355. while (stack.length > 0) {
  107356. const tile = stack.pop() || {};
  107357. const children = tile.children || [];
  107358. for (const childHeader of children) {
  107359. normalizeTileData(childHeader, {
  107360. basePath
  107361. });
  107362. stack.push(childHeader);
  107363. }
  107364. }
  107365. return root;
  107366. }
  107367. async function normalizeImplicitTileHeaders(tileset) {
  107368. if (!tileset.root) {
  107369. return null;
  107370. }
  107371. const basePath = tileset.basePath;
  107372. const implicitTilingExtension = tileset.root.extensions['3DTILES_implicit_tiling'];
  107373. const {
  107374. subdivisionScheme,
  107375. maximumLevel,
  107376. subtreeLevels,
  107377. subtrees: {
  107378. uri: subtreesUriTemplate
  107379. }
  107380. } = implicitTilingExtension;
  107381. const subtreeUrl = replaceContentUrlTemplate(subtreesUriTemplate, 0, 0, 0, 0);
  107382. const rootSubtreeUrl = "".concat(basePath, "/").concat(subtreeUrl);
  107383. const rootSubtree = await load(rootSubtreeUrl, Tile3DSubtreeLoader);
  107384. const contentUrlTemplate = "".concat(basePath, "/").concat(tileset.root.content.uri);
  107385. const refine = tileset.root.refine;
  107386. const rootLodMetricValue = tileset.root.geometricError;
  107387. const rootBoundingVolume = tileset.root.boundingVolume;
  107388. const options = {
  107389. contentUrlTemplate,
  107390. subtreesUriTemplate,
  107391. subdivisionScheme,
  107392. subtreeLevels,
  107393. maximumLevel,
  107394. refine,
  107395. basePath,
  107396. lodMetricType: LOD_METRIC_TYPE.GEOMETRIC_ERROR,
  107397. rootLodMetricValue,
  107398. rootBoundingVolume,
  107399. getTileType,
  107400. getRefine
  107401. };
  107402. return await normalizeImplicitTileData(tileset.root, rootSubtree, options);
  107403. }
  107404. async function normalizeImplicitTileData(tile, rootSubtree, options) {
  107405. if (!tile) {
  107406. return null;
  107407. }
  107408. tile.lodMetricType = LOD_METRIC_TYPE.GEOMETRIC_ERROR;
  107409. tile.lodMetricValue = tile.geometricError;
  107410. tile.transformMatrix = tile.transform;
  107411. const {
  107412. children,
  107413. contentUrl
  107414. } = await parseImplicitTiles(rootSubtree, options);
  107415. if (contentUrl) {
  107416. tile.contentUrl = contentUrl;
  107417. tile.content = {
  107418. uri: contentUrl.replace("".concat(options.basePath, "/"), '')
  107419. };
  107420. }
  107421. tile.refine = getRefine(tile.refine);
  107422. tile.type = getTileType(tile);
  107423. tile.children = children;
  107424. tile.id = tile.contentUrl;
  107425. return tile;
  107426. }
  107427. const IMPLICIT_TILING_EXTENSION_NAME = '3DTILES_implicit_tiling';
  107428. const Tiles3DLoader = {
  107429. id: '3d-tiles',
  107430. name: '3D Tiles',
  107431. module: '3d-tiles',
  107432. version: VERSION$5,
  107433. extensions: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
  107434. mimeTypes: ['application/octet-stream'],
  107435. tests: ['cmpt', 'pnts', 'b3dm', 'i3dm'],
  107436. parse: parse$4,
  107437. options: {
  107438. '3d-tiles': {
  107439. loadGLTF: true,
  107440. decodeQuantizedPositions: false,
  107441. isTileset: 'auto',
  107442. assetGltfUpAxis: null
  107443. }
  107444. }
  107445. };
  107446. function getBaseUri(tileset) {
  107447. return dirname(tileset.url);
  107448. }
  107449. async function parseTile(arrayBuffer, options, context) {
  107450. const tile = {
  107451. content: {
  107452. featureIds: null
  107453. }
  107454. };
  107455. const byteOffset = 0;
  107456. await parse3DTile(arrayBuffer, byteOffset, options, context, tile.content);
  107457. return tile.content;
  107458. }
  107459. async function parseTileset(data, options, context) {
  107460. var _tilesetJson$root;
  107461. const tilesetJson = JSON.parse(new TextDecoder().decode(data));
  107462. tilesetJson.loader = options.loader || Tiles3DLoader;
  107463. tilesetJson.url = context.url;
  107464. tilesetJson.basePath = getBaseUri(tilesetJson);
  107465. tilesetJson.root = hasImplicitTilingExtension(tilesetJson) ? await normalizeImplicitTileHeaders(tilesetJson) : normalizeTileHeaders(tilesetJson);
  107466. tilesetJson.type = TILESET_TYPE.TILES3D;
  107467. tilesetJson.lodMetricType = LOD_METRIC_TYPE.GEOMETRIC_ERROR;
  107468. tilesetJson.lodMetricValue = ((_tilesetJson$root = tilesetJson.root) === null || _tilesetJson$root === void 0 ? void 0 : _tilesetJson$root.lodMetricValue) || 0;
  107469. return tilesetJson;
  107470. }
  107471. async function parse$4(data, options, context) {
  107472. const loaderOptions = options['3d-tiles'] || {};
  107473. let isTileset;
  107474. if (loaderOptions.isTileset === 'auto') {
  107475. isTileset = context.url && context.url.indexOf('.json') !== -1;
  107476. } else {
  107477. isTileset = loaderOptions.isTileset;
  107478. }
  107479. if (isTileset) {
  107480. data = await parseTileset(data, options, context);
  107481. } else {
  107482. data = await parseTile(data, options, context);
  107483. }
  107484. return data;
  107485. }
  107486. function hasImplicitTilingExtension(tilesetJson) {
  107487. var _tilesetJson$extensio, _tilesetJson$extensio2;
  107488. 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));
  107489. }
  107490. const CESIUM_ION_URL = 'https://api.cesium.com/v1/assets';
  107491. async function getIonTilesetMetadata(accessToken, assetId) {
  107492. if (!assetId) {
  107493. const assets = await getIonAssets(accessToken);
  107494. for (const item of assets.items) {
  107495. if (item.type === '3DTILES') {
  107496. assetId = item.id;
  107497. }
  107498. }
  107499. }
  107500. const ionAssetMetadata = await getIonAssetMetadata(accessToken, assetId);
  107501. const {
  107502. type,
  107503. url
  107504. } = ionAssetMetadata;
  107505. assert$7(type === '3DTILES' && url);
  107506. ionAssetMetadata.headers = {
  107507. Authorization: "Bearer ".concat(ionAssetMetadata.accessToken)
  107508. };
  107509. return ionAssetMetadata;
  107510. }
  107511. async function getIonAssets(accessToken) {
  107512. assert$7(accessToken);
  107513. const url = CESIUM_ION_URL;
  107514. const headers = {
  107515. Authorization: "Bearer ".concat(accessToken)
  107516. };
  107517. const response = await fetchFile(url, {
  107518. fetch: {
  107519. headers
  107520. }
  107521. });
  107522. if (!response.ok) {
  107523. throw new Error(response.statusText);
  107524. }
  107525. return await response.json();
  107526. }
  107527. async function getIonAssetMetadata(accessToken, assetId) {
  107528. assert$7(accessToken, assetId);
  107529. const headers = {
  107530. Authorization: "Bearer ".concat(accessToken)
  107531. };
  107532. const url = "".concat(CESIUM_ION_URL, "/").concat(assetId);
  107533. let response = await fetchFile("".concat(url), {
  107534. fetch: {
  107535. headers
  107536. }
  107537. });
  107538. if (!response.ok) {
  107539. throw new Error(response.statusText);
  107540. }
  107541. let metadata = await response.json();
  107542. response = await fetchFile("".concat(url, "/endpoint"), {
  107543. fetch: {
  107544. headers
  107545. }
  107546. });
  107547. if (!response.ok) {
  107548. throw new Error(response.statusText);
  107549. }
  107550. const tilesetInfo = await response.json();
  107551. metadata = { ...metadata,
  107552. ...tilesetInfo
  107553. };
  107554. return metadata;
  107555. }
  107556. async function preload(url, options = {}) {
  107557. options = options['cesium-ion'] || {};
  107558. const {
  107559. accessToken
  107560. } = options;
  107561. let assetId = options.assetId;
  107562. if (!Number.isFinite(assetId)) {
  107563. const matched = url.match(/\/([0-9]+)\/tileset.json/);
  107564. assetId = matched && matched[1];
  107565. }
  107566. return getIonTilesetMetadata(accessToken, assetId);
  107567. }
  107568. const CesiumIonLoader = { ...Tiles3DLoader,
  107569. id: 'cesium-ion',
  107570. name: 'Cesium Ion',
  107571. preload,
  107572. parse: async (data, options, context) => {
  107573. options = { ...options
  107574. };
  107575. options['3d-tiles'] = options['cesium-ion'];
  107576. options.loader = CesiumIonLoader;
  107577. return Tiles3DLoader.parse(data, options, context);
  107578. },
  107579. options: {
  107580. 'cesium-ion': { ...Tiles3DLoader.options['3d-tiles'],
  107581. accessToken: null
  107582. }
  107583. }
  107584. };
  107585. // From https://github.com/potree/potree/blob/master/src/materials/PointCloudMaterial.js
  107586. function generateGradientTexture(gradient) {
  107587. const size = 64;
  107588. // create canvas
  107589. const canvas = document.createElement('canvas');
  107590. canvas.width = size;
  107591. canvas.height = size;
  107592. // get context
  107593. const context = canvas.getContext('2d');
  107594. // draw gradient
  107595. context.rect(0, 0, size, size);
  107596. const ctxGradient = context.createLinearGradient(0, 0, size, size);
  107597. for (let i = 0; i < gradient.length; i++) {
  107598. const step = gradient[i];
  107599. ctxGradient.addColorStop(step[0], '#' + step[1].getHexString());
  107600. }
  107601. context.fillStyle = ctxGradient;
  107602. context.fill();
  107603. //let texture = new THREE.Texture(canvas);
  107604. const texture = new CanvasTexture(canvas);
  107605. texture.needsUpdate = true;
  107606. texture.minFilter = LinearFilter;
  107607. texture.wrapS = RepeatWrapping;
  107608. texture.wrapT = RepeatWrapping;
  107609. texture.repeat.set(2, 2);
  107610. // textureImage = texture.image;
  107611. return texture;
  107612. }
  107613. function getCameraFrustum(camera) {
  107614. camera.updateMatrix(); // make sure camera's local matrix is updated
  107615. camera.updateMatrixWorld(); // make sure camera's world matrix is updated
  107616. camera.matrixWorldInverse.copy(camera.matrixWorld).invert();
  107617. const frustum = new Frustum();
  107618. frustum.setFromProjectionMatrix(new Matrix4().multiplyMatrices(camera.projectionMatrix, camera.matrixWorldInverse));
  107619. return frustum;
  107620. }
  107621. function loadersPlaneToMesh(plane) {
  107622. const group = new Group();
  107623. // Create a basic rectangle geometry from math.gl plane
  107624. const planeGeometry = new PlaneGeometry(10, 5);
  107625. // Align the geometry to the plane
  107626. const coplanarPoint = new Vector3(...plane.projectPointOntoPlane([0, 0, 0]));
  107627. const normal = new Vector3(plane.normal.x, plane.normal.y, plane.normal.z);
  107628. const focalPoint = new Vector3().copy(coplanarPoint).add(normal);
  107629. planeGeometry.lookAt(focalPoint);
  107630. planeGeometry.translate(coplanarPoint.x, coplanarPoint.y, coplanarPoint.z);
  107631. // Edges
  107632. /*
  107633. const edges = new EdgesGeometry(planeGeometry)
  107634. var dispPlane = new LineSegments(edges, new LineBasicMaterial({ color: 0x00ffff }))*/
  107635. //plane
  107636. const material = new BasicMaterial({ color: 0x00ffff, side: DoubleSide });
  107637. const mesh = new Mesh(planeGeometry, material);
  107638. const arrowHelper = new ArrowHelper(normal, coplanarPoint, 5, 0xffff00);
  107639. group.add(arrowHelper);
  107640. group.add(mesh);
  107641. return group;
  107642. }
  107643. function loadersBoundingBoxToMesh(tile) {
  107644. // Create a basic rectangle geometry from math.gl half-axes
  107645. const boundUntransformed = tile.type == 'empty' ? tile.boundingVolume : tile.getBoundUntransformed(); //empty时没创建好,直接给boundingVolume一样
  107646. /* let redColor = 0;
  107647. if (tile.content) {
  107648. //redColor = Math.min((tile.content.byteLength != void 0 ? tile.content.byteLength : 0) / 500000, 1.0);
  107649. redColor = Math.min( tile.depth / 10 , 1.0); //改
  107650. } */
  107651. let hue = 0;
  107652. if(tile.content){
  107653. hue = Math.min( tile.depth / 10 , 1.0); //改
  107654. }
  107655. const boxColor = new THREE.Color().setHSL(hue, 0.9, 0.85);
  107656. //const boxColor = new Color(redColor, 1.0, 0.0);
  107657. const boxGeometry = new BoxGeometry(1, 1, 1);
  107658. const boxTransform = new Matrix4();
  107659. if (boundUntransformed.halfAxes) {
  107660. boxTransform.copy(getMatrix4FromHalfAxes(boundUntransformed.halfAxes));
  107661. }
  107662. else if (boundUntransformed.radius) {
  107663. boxGeometry.scale(boundUntransformed.radius * 2, boundUntransformed.radius * 2, boundUntransformed.radius * 2);
  107664. }
  107665. boxTransform.premultiply((new Matrix4()).setPosition(...boundUntransformed.center)); //add
  107666. /* if(tile.type != "empty"){ //root单独处理了
  107667. boxTransform.premultiply((new Matrix4$1()).makeScale(1,1,-1))//xzw 因为mesh倒转了所以box也
  107668. }else{
  107669. console.log('empty')
  107670. } */
  107671. boxGeometry.applyMatrix4(boxTransform);
  107672. const edges = new EdgesGeometry(boxGeometry);
  107673. const dispPlane = new LineSegments(edges, new LineBasicMaterial({ color: boxColor, transparent:true }));
  107674. //dispPlane.position.copy(new Vector3$1(...boundingVolume.center));
  107675. dispPlane.matrixAutoUpdate = false; //add
  107676. let label = new Potree.TextSprite({
  107677. mat: new THREE.MeshBasicMaterial({transparent:true }), //depthTest:false会导致经常显示不出
  107678. backgroundColor: {r: 0, g: 0, b: 0, a:0.1},
  107679. textColor: {r: boxColor.r*255, g: boxColor.g*255, b: boxColor.b*255, a:0.9},
  107680. fontsize:100,
  107681. //useDepth : true ,
  107682. renderOrder : 5,
  107683. text: tile.id.split('/').pop().split('.b3dm')[0], //Tile_+094_-010.b3dm'
  107684. name:'tile'
  107685. });
  107686. label.addEventListener('mouseover',()=>{
  107687. if(label.sprite.material.opacity < 1)return
  107688. window.hoverTile = tile;
  107689. console.log('hoverLabel',tile.id, tile._distanceToCamera);
  107690. });
  107691. /* let s = 0.6
  107692. label.scale.set(s,s,s) */
  107693. let s = tile.tileset.options.maximumScreenSpaceError / 400;
  107694. label.scale.set(s,s,s);
  107695. dispPlane.add(label);
  107696. label.position.set(...boundUntransformed.center);
  107697. //label.position.z *= -1
  107698. /* if(tile.content.byteLength == void 0){
  107699. let oldUpdate = dispPlane.updateMatrixWorld.bind(dispPlane)
  107700. dispPlane.updateMatrixWorld = (a,b)=>{
  107701. oldUpdate(a,b)
  107702. }
  107703. let oldU = dispPlane.updateMatrix.bind(dispPlane)
  107704. dispPlane.updateMatrix = (a,b)=>{
  107705. oldU(a,b)
  107706. }
  107707. } */
  107708. tile.volumeBox = dispPlane;
  107709. return dispPlane;
  107710. }
  107711. function getMatrix4FromHalfAxes(halfAxes) {
  107712. const m = halfAxes;
  107713. const rotateMatrix = new Matrix4().fromArray([
  107714. m[0] * 2,
  107715. m[1] * 2,
  107716. m[2] * 2,
  107717. 0,
  107718. m[3] * 2,
  107719. m[4] * 2,
  107720. m[5] * 2,
  107721. 0,
  107722. m[6] * 2,
  107723. m[7] * 2,
  107724. m[8] * 2,
  107725. 0,
  107726. 0,
  107727. 0,
  107728. 0,
  107729. 1,
  107730. ]);
  107731. return rotateMatrix;
  107732. }
  107733. /*
  107734. * from https://github.com/tentone/geo-three
  107735. * Tree-shaking did not work, probably due to static class methods
  107736. */
  107737. function datumsToSpherical(latitude, longitude) {
  107738. const EARTH_RADIUS = 6378137;
  107739. const EARTH_PERIMETER = 2 * Math.PI * EARTH_RADIUS;
  107740. const EARTH_ORIGIN = EARTH_PERIMETER / 2.0;
  107741. const x = longitude * EARTH_ORIGIN / 180.0;
  107742. let y = Math.log(Math.tan((90 + latitude) * Math.PI / 360.0)) / (Math.PI / 180.0);
  107743. y = y * EARTH_ORIGIN / 180.0;
  107744. return new Vector2(x, y);
  107745. }
  107746. const Gradients$1 = {
  107747. // From chroma spectral http://gka.github.io/chroma.js/
  107748. SPECTRAL: [
  107749. [0, new Color(0.3686, 0.3098, 0.6353)],
  107750. [0.1, new Color(0.1961, 0.5333, 0.7412)],
  107751. [0.2, new Color(0.4, 0.7608, 0.6471)],
  107752. [0.3, new Color(0.6706, 0.8667, 0.6431)],
  107753. [0.4, new Color(0.902, 0.9608, 0.5961)],
  107754. [0.5, new Color(1.0, 1.0, 0.749)],
  107755. [0.6, new Color(0.9961, 0.8784, 0.5451)],
  107756. [0.7, new Color(0.9922, 0.6824, 0.3804)],
  107757. [0.8, new Color(0.9569, 0.4275, 0.2627)],
  107758. [0.9, new Color(0.8353, 0.2431, 0.3098)],
  107759. [1, new Color(0.6196, 0.0039, 0.2588)],
  107760. ],
  107761. PLASMA: [
  107762. [0.0, new Color(0.241, 0.015, 0.61)],
  107763. [0.1, new Color(0.387, 0.001, 0.654)],
  107764. [0.2, new Color(0.524, 0.025, 0.653)],
  107765. [0.3, new Color(0.651, 0.125, 0.596)],
  107766. [0.4, new Color(0.752, 0.227, 0.513)],
  107767. [0.5, new Color(0.837, 0.329, 0.431)],
  107768. [0.6, new Color(0.907, 0.435, 0.353)],
  107769. [0.7, new Color(0.963, 0.554, 0.272)],
  107770. [0.8, new Color(0.992, 0.681, 0.195)],
  107771. [0.9, new Color(0.987, 0.822, 0.144)],
  107772. [1.0, new Color(0.94, 0.975, 0.131)],
  107773. ],
  107774. YELLOW_GREEN: [
  107775. [0, new Color(0.1647, 0.2824, 0.3451)],
  107776. [0.1, new Color(0.1338, 0.3555, 0.4227)],
  107777. [0.2, new Color(0.061, 0.4319, 0.4864)],
  107778. [0.3, new Color(0.0, 0.5099, 0.5319)],
  107779. [0.4, new Color(0.0, 0.5881, 0.5569)],
  107780. [0.5, new Color(0.137, 0.665, 0.5614)],
  107781. [0.6, new Color(0.2906, 0.7395, 0.5477)],
  107782. [0.7, new Color(0.4453, 0.8099, 0.5201)],
  107783. [0.8, new Color(0.6102, 0.8748, 0.485)],
  107784. [0.9, new Color(0.7883, 0.9323, 0.4514)],
  107785. [1, new Color(0.9804, 0.9804, 0.4314)],
  107786. ],
  107787. VIRIDIS: [
  107788. [0.0, new Color(0.267, 0.005, 0.329)],
  107789. [0.1, new Color(0.283, 0.141, 0.458)],
  107790. [0.2, new Color(0.254, 0.265, 0.53)],
  107791. [0.3, new Color(0.207, 0.372, 0.553)],
  107792. [0.4, new Color(0.164, 0.471, 0.558)],
  107793. [0.5, new Color(0.128, 0.567, 0.551)],
  107794. [0.6, new Color(0.135, 0.659, 0.518)],
  107795. [0.7, new Color(0.267, 0.749, 0.441)],
  107796. [0.8, new Color(0.478, 0.821, 0.318)],
  107797. [0.9, new Color(0.741, 0.873, 0.15)],
  107798. [1.0, new Color(0.993, 0.906, 0.144)],
  107799. ],
  107800. INFERNO: [
  107801. [0.0, new Color(0.077, 0.042, 0.206)],
  107802. [0.1, new Color(0.225, 0.036, 0.388)],
  107803. [0.2, new Color(0.373, 0.074, 0.432)],
  107804. [0.3, new Color(0.522, 0.128, 0.42)],
  107805. [0.4, new Color(0.665, 0.182, 0.37)],
  107806. [0.5, new Color(0.797, 0.255, 0.287)],
  107807. [0.6, new Color(0.902, 0.364, 0.184)],
  107808. [0.7, new Color(0.969, 0.516, 0.063)],
  107809. [0.8, new Color(0.988, 0.683, 0.072)],
  107810. [0.9, new Color(0.961, 0.859, 0.298)],
  107811. [1.0, new Color(0.988, 0.998, 0.645)],
  107812. ],
  107813. GRAYSCALE: [
  107814. [0, new Color(0, 0, 0)],
  107815. [1, new Color(1, 1, 1)],
  107816. ],
  107817. // 16 samples of the TURBU color scheme
  107818. // values taken from: https://gist.github.com/mikhailov-work/ee72ba4191942acecc03fe6da94fc73f
  107819. // original file licensed under Apache-2.0
  107820. TURBO: [
  107821. [0.0, new Color(0.18995, 0.07176, 0.23217)],
  107822. [0.07, new Color(0.25107, 0.25237, 0.63374)],
  107823. [0.13, new Color(0.27628, 0.42118, 0.89123)],
  107824. [0.2, new Color(0.25862, 0.57958, 0.99876)],
  107825. [0.27, new Color(0.15844, 0.73551, 0.92305)],
  107826. [0.33, new Color(0.09267, 0.86554, 0.7623)],
  107827. [0.4, new Color(0.19659, 0.94901, 0.59466)],
  107828. [0.47, new Color(0.42778, 0.99419, 0.38575)],
  107829. [0.53, new Color(0.64362, 0.98999, 0.23356)],
  107830. [0.6, new Color(0.80473, 0.92452, 0.20459)],
  107831. [0.67, new Color(0.93301, 0.81236, 0.22667)],
  107832. [0.73, new Color(0.99314, 0.67408, 0.20348)],
  107833. [0.8, new Color(0.9836, 0.49291, 0.12849)],
  107834. [0.87, new Color(0.92105, 0.31489, 0.05475)],
  107835. [0.93, new Color(0.81608, 0.18462, 0.01809)],
  107836. [1.0, new Color(0.66449, 0.08436, 0.00424)],
  107837. ],
  107838. RAINBOW: [
  107839. [0, new Color(0.278, 0, 0.714)],
  107840. [1 / 6, new Color(0, 0, 1)],
  107841. [2 / 6, new Color(0, 1, 1)],
  107842. [3 / 6, new Color(0, 1, 0)],
  107843. [4 / 6, new Color(1, 1, 0)],
  107844. [5 / 6, new Color(1, 0.64, 0)],
  107845. [1, new Color(1, 0, 0)],
  107846. ],
  107847. CONTOUR: [
  107848. [0.0, new Color(0, 0, 0)],
  107849. [0.03, new Color(0, 0, 0)],
  107850. [0.04, new Color(1, 1, 1)],
  107851. [1.0, new Color(1, 1, 1)],
  107852. ],
  107853. };
  107854. const PointCloudFS = `
  107855. varying vec3 vColor;
  107856. uniform float alpha;
  107857. void main() {
  107858. if (vColor == vec3(0.0, 0.0, 0.0)) {
  107859. discard;
  107860. } else {
  107861. gl_FragColor = vec4( vColor, alpha);
  107862. }
  107863. }
  107864. `;
  107865. const PointCloudVS = `
  107866. varying vec3 vColor;
  107867. uniform sampler2D gradient;
  107868. uniform sampler2D grayscale;
  107869. attribute float intensity;
  107870. attribute float classification;
  107871. uniform vec3 rootCenter;
  107872. uniform vec3 rootNormal;
  107873. uniform vec2 elevationRange;
  107874. uniform int coloring;
  107875. uniform bool hideGround;
  107876. uniform float maxIntensity;
  107877. uniform float intensityContrast;
  107878. uniform float pointSize;
  107879. #ifdef USE_COLOR
  107880. vec3 getRGB() {
  107881. vec3 rgb = color;
  107882. return rgb;
  107883. }
  107884. #endif
  107885. vec3 getElevation(){
  107886. vec4 world = modelMatrix * vec4( position, 1.0 );
  107887. float diff = abs(dot(rootNormal, (vec3(world) - rootCenter)));
  107888. float w = max(diff - elevationRange.x,0.0) / max(elevationRange.y - elevationRange.x,1.0);
  107889. vec3 cElevation = texture2D(gradient, vec2(w,1.0-w)).rgb;
  107890. return cElevation;
  107891. }
  107892. vec3 getIntensity(){
  107893. // TODO: real contrast enhancement. Check https://github.com/yuki-koyama/enhancer/blob/master/shaders/enhancer.fs
  107894. float intmod = pow(intensity, intensityContrast);
  107895. vec3 cIntensity = texture2D(grayscale, vec2(intmod / maxIntensity ,1.0-(intmod / maxIntensity))).rgb;
  107896. return cIntensity;
  107897. }
  107898. vec3 getClassification(){
  107899. float classNormalized = classification / 255.0;
  107900. vec3 cClassification = texture2D(gradient, vec2(classNormalized * 5.0,1.0-classNormalized * 5.0)).rgb;
  107901. return cClassification;
  107902. }
  107903. vec3 getColor(){
  107904. vec3 color;
  107905. if (hideGround && classification == 2.0) {
  107906. return vec3(0.0, 0.0, 0.0);
  107907. }
  107908. if (coloring == 1) {
  107909. color = getIntensity();
  107910. }
  107911. else if (coloring == 2) {
  107912. color = getClassification();
  107913. } else if (coloring == 3) {
  107914. color = getElevation();
  107915. }
  107916. #ifdef USE_COLOR
  107917. else if (coloring == 4) {
  107918. color = getRGB();
  107919. }
  107920. #endif
  107921. else {
  107922. color = vec3(1.0, 1.0, 1.0);
  107923. }
  107924. return color;
  107925. }
  107926. void main() {
  107927. vColor = getColor();
  107928. gl_PointSize = pointSize;
  107929. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  107930. }
  107931. `;
  107932. /** Types of coloring used when viewing point cloud tiles */
  107933. var PointCloudColoring;
  107934. (function (PointCloudColoring) {
  107935. PointCloudColoring[PointCloudColoring["Intensity"] = 1] = "Intensity";
  107936. PointCloudColoring[PointCloudColoring["Classification"] = 2] = "Classification";
  107937. PointCloudColoring[PointCloudColoring["Elevation"] = 3] = "Elevation";
  107938. PointCloudColoring[PointCloudColoring["RGB"] = 4] = "RGB";
  107939. PointCloudColoring[PointCloudColoring["White"] = 5] = "White";
  107940. })(PointCloudColoring || (PointCloudColoring = {}));
  107941. /** Types of shading used when viewing b3dm (mesh) tiles */
  107942. var Shading;
  107943. (function (Shading) {
  107944. Shading[Shading["FlatTexture"] = 1] = "FlatTexture";
  107945. Shading[Shading["ShadedTexture"] = 2] = "ShadedTexture";
  107946. Shading[Shading["ShadedNoTexture"] = 3] = "ShadedNoTexture";
  107947. })(Shading || (Shading = {}));
  107948. var GeoTransform;
  107949. (function (GeoTransform) {
  107950. GeoTransform[GeoTransform["Reset"] = 1] = "Reset";
  107951. GeoTransform[GeoTransform["Mercator"] = 2] = "Mercator";
  107952. GeoTransform[GeoTransform["WGS84Cartesian"] = 3] = "WGS84Cartesian";
  107953. })(GeoTransform || (GeoTransform = {}));
  107954. const gradient = Gradients$1.RAINBOW;
  107955. const gradientTexture = typeof document != 'undefined' ? generateGradientTexture(gradient) : null;
  107956. const grayscale = Gradients$1.GRAYSCALE;
  107957. const grayscaleTexture = typeof document != 'undefined' ? generateGradientTexture(grayscale) : null;
  107958. const defaultOptions = {
  107959. throttleRequests: true,
  107960. maxRequests: 64,
  107961. updateInterval: 0.1,
  107962. maxConcurrency: 1,
  107963. maximumScreenSpaceError: 16,
  107964. maximumMemoryUsage: 32,
  107965. viewDistanceScale: 1.0,
  107966. skipLevelOfDetail: false,
  107967. updateTransforms: true,
  107968. shading: Shading.FlatTexture,
  107969. transparent: false,
  107970. pointCloudColoring: PointCloudColoring.White,
  107971. pointSize: 1.0,
  107972. worker: true,
  107973. wireframe: false,
  107974. debug: false,
  107975. basisTranscoderPath: null,
  107976. dracoDecoderPath: null,
  107977. material: null,
  107978. computeNormals: false,
  107979. shaderCallback: null,
  107980. geoTransform: GeoTransform.Reset,
  107981. preloadTilesCount: null
  107982. };
  107983. /** 3D Tiles Loader */
  107984. class Loader3DTiles {
  107985. /**
  107986. * Loads a tileset of 3D Tiles according to the given {@link LoaderProps}
  107987. * @public
  107988. *
  107989. * @param props - Properties for this load call {@link LoaderProps}.
  107990. * @returns An object containing the 3D Model to be added to the scene
  107991. * and a runtime engine to be updated every frame.
  107992. */
  107993. static load(props) {
  107994. return __awaiter(this, void 0, void 0, function* () {
  107995. const options = Object.assign(Object.assign({}, defaultOptions), props.options);
  107996. const { url } = props;
  107997. const UPDATE_INTERVAL = options.updateInterval;
  107998. const MAX_DEPTH_FOR_ORIENTATION = 5;
  107999. const loadersGLOptions = {};
  108000. if (options.cesiumIONToken) {
  108001. loadersGLOptions['cesium-ion'] = {
  108002. accessToken: options.cesiumIONToken,
  108003. };
  108004. const metadata = yield CesiumIonLoader.preload(url, loadersGLOptions);
  108005. loadersGLOptions['fetch'] = { headers: metadata.headers };
  108006. }
  108007. if (props.loadingManager) {
  108008. props.loadingManager.itemStart(url);
  108009. }
  108010. const tilesetJson = yield load(url, Tiles3DLoader, Object.assign({}, loadersGLOptions));
  108011. const renderMap = {};
  108012. const boxMap = {};
  108013. const unloadQueue = [];
  108014. const root = new Group();
  108015. const tileBoxes = new Group();
  108016. tileBoxes.matrixAutoUpdate = false;//add
  108017. if (!options.debug) {
  108018. tileBoxes.visible = false;
  108019. }else {
  108020. options.parent.add(tileBoxes); //add
  108021. }
  108022. const pointcloudUniforms = {
  108023. pointSize: { type: 'f', value: options.pointSize },
  108024. gradient: { type: 't', value: gradientTexture },
  108025. grayscale: { type: 't', value: grayscaleTexture },
  108026. rootCenter: { type: 'vec3', value: new Vector3() },
  108027. rootNormal: { type: 'vec3', value: new Vector3() },
  108028. coloring: { type: 'i', value: options.pointCloudColoring },
  108029. hideGround: { type: 'b', value: true },
  108030. elevationRange: { type: 'vec2', value: new Vector2(0, 400) },
  108031. maxIntensity: { type: 'f', value: 1.0 },
  108032. intensityContrast: { type: 'f', value: 1.0 },
  108033. alpha: { type: 'f', value: 1.0 },
  108034. };
  108035. const pointcloudMaterial = new ShaderMaterial({
  108036. uniforms: pointcloudUniforms,
  108037. vertexShader: PointCloudVS,
  108038. fragmentShader: PointCloudFS,
  108039. transparent: options.transparent,
  108040. vertexColors: true
  108041. });
  108042. let cameraReference = null;
  108043. let rendererReference = null;
  108044. const gltfLoader = props.gltfLoader || new GLTFLoader(); //xzw改
  108045. let ktx2Loader = undefined;
  108046. let dracoLoader = undefined;
  108047. if (options.basisTranscoderPath) {
  108048. ktx2Loader = new KTX2Loader();
  108049. ktx2Loader.detectSupport(props.renderer);
  108050. ktx2Loader.setTranscoderPath(options.basisTranscoderPath + '/');
  108051. ktx2Loader.setWorkerLimit(1);
  108052. gltfLoader.setKTX2Loader(ktx2Loader);
  108053. }
  108054. if (options.dracoDecoderPath) {
  108055. dracoLoader = new DRACOLoader();
  108056. dracoLoader.setDecoderPath(options.dracoDecoderPath + '/');
  108057. dracoLoader.setWorkerLimit(options.maxConcurrency);
  108058. gltfLoader.setDRACOLoader(dracoLoader);
  108059. }
  108060. const unlitMaterial = new BasicMaterial({ transparent: options.transparent });
  108061. const tileOptions = {
  108062. maximumMemoryUsage: options.maximumMemoryUsage,
  108063. maximumScreenSpaceError: options.maximumScreenSpaceError,
  108064. viewDistanceScale: options.viewDistanceScale,
  108065. skipLevelOfDetail: options.skipLevelOfDetail,
  108066. updateTransforms: options.updateTransforms,
  108067. throttleRequests: options.throttleRequests,
  108068. maxRequests: options.maxRequests,
  108069. updateTime: options.updateTime || 0, //add
  108070. //maxDepth: options.maxDepth || 50, // !zeg改
  108071. contentLoader: (tile) => __awaiter(this, void 0, void 0, function* () {
  108072. let tileContent = null;
  108073. switch (tile.type) {
  108074. case TILE_TYPE.POINTCLOUD: {
  108075. tileContent = createPointNodes(tile, pointcloudMaterial, options, rootTransformInverse);
  108076. break;
  108077. }
  108078. case TILE_TYPE.SCENEGRAPH:
  108079. case TILE_TYPE.MESH: {
  108080. tileContent = yield createGLTFNodes(gltfLoader, tile, unlitMaterial, options, rootTransformInverse);
  108081. break;
  108082. }
  108083. }
  108084. if (tileContent) {
  108085. tileContent.visible = false;
  108086. renderMap[tile.id] = tileContent;
  108087. tileContent.name = tile.id; //add
  108088. tileContent.tile = tile; //add
  108089. root.add(renderMap[tile.id]);
  108090. if (options.debug) {
  108091. const box = loadersBoundingBoxToMesh(tile);
  108092. tileBoxes.add(box);
  108093. boxMap[tile.id] = box;
  108094. }
  108095. //xzw :
  108096. tileset.dispatchEvent({type:'tileLoaded',tileContent}); //每一个tile加载完要更改透明度等
  108097. }
  108098. }),
  108099. onTileLoad: (tile) => __awaiter(this, void 0, void 0, function* () {
  108100. if (tileset) {
  108101. if (!orientationDetected && (tile === null || tile === void 0 ? void 0 : tile.depth) <= MAX_DEPTH_FOR_ORIENTATION) {
  108102. detectOrientation(tile);
  108103. }
  108104. tileset._frameNumber++;
  108105. tilesetUpdate(tileset, renderMap, rendererReference, cameraReference);
  108106. }
  108107. }),
  108108. onTileUnload: (tile) => {
  108109. unloadQueue.push(tile);
  108110. },
  108111. onTileError: (tile, message) => {
  108112. console.error('Tile error', tile.id, message);
  108113. },
  108114. };
  108115. const tileset = new Tileset3D(tilesetJson, Object.assign(Object.assign({}, tileOptions), { loadOptions: Object.assign(Object.assign({}, loadersGLOptions), { maxConcurrency: options.maxConcurrency, worker: options.worker, gltf: {
  108116. loadImages: false,
  108117. }, '3d-tiles': {
  108118. loadGLTF: false
  108119. } }) }));
  108120. tileset.boxMap = boxMap; //add
  108121. // transformations
  108122. const threeMat = new Matrix4();
  108123. const tileTransform = new Matrix4();
  108124. const rootCenter = new Vector3();
  108125. let orientationDetected = false;
  108126. if (tileset.root.boundingVolume) {
  108127. if (tileset.root.header.boundingVolume.region) {
  108128. // TODO: Handle region type bounding volumes
  108129. // https://github.com/visgl/loaders.gl/issues/1994
  108130. console.warn("Cannot apply a model matrix to bounding volumes of type region. Tileset stays in original geo-coordinates.");
  108131. options.geoTransform = GeoTransform.WGS84Cartesian;
  108132. }
  108133. tileTransform.setPosition(tileset.root.boundingVolume.center[0], tileset.root.boundingVolume.center[1], tileset.root.boundingVolume.center[2]);
  108134. }
  108135. else {
  108136. console.warn("Bounding volume not found, no transformations applied");
  108137. }
  108138. if (options.debug) {
  108139. const box = loadersBoundingBoxToMesh(tileset.root);
  108140. tileBoxes.add(box);
  108141. boxMap[tileset.root.id] = box;
  108142. }
  108143. let disposeFlag = false;
  108144. let loadingEnded = false;
  108145. pointcloudUniforms.rootCenter.value.copy(rootCenter);
  108146. pointcloudUniforms.rootNormal.value.copy(new Vector3(0, 0, 1).normalize());
  108147. // Extra stats
  108148. tileset.stats.get('Loader concurrency').count = options.maxConcurrency;
  108149. tileset.stats.get('Maximum SSE').count = options.maximumScreenSpaceError;
  108150. tileset.stats.get('Maximum mem usage').count = options.maximumMemoryUsage;
  108151. let timer = 0;
  108152. let lastCameraTransform = null;
  108153. let lastCameraAspect = null;
  108154. const lastCameraPosition = new Vector3(Infinity, Infinity, Infinity);
  108155. let sseDenominator = null;
  108156. root.updateMatrixWorld(true);
  108157. const lastRootTransform = new Matrix4().copy(root.matrixWorld);
  108158. const rootTransformInverse = new Matrix4().copy(lastRootTransform).invert();
  108159. tileset.lastRootTransform = lastRootTransform; //add
  108160. detectOrientation(tileset.root);
  108161. updateResetTransform();
  108162. if (options.debug) {
  108163. boxMap[tileset.root.id].applyMatrix4(threeMat);
  108164. tileBoxes.matrixWorld.copy(root.matrixWorld);
  108165. }
  108166. if (options.geoTransform == GeoTransform.Mercator) {
  108167. const coords = datumsToSpherical(tileset.cartographicCenter[1], tileset.cartographicCenter[0]);
  108168. rootCenter.set(coords.x, 0, -coords.y);
  108169. root.position.copy(rootCenter);
  108170. root.rotation.set(-Math.PI / 2, 0, 0);
  108171. root.updateMatrixWorld(true);
  108172. }
  108173. else if (options.geoTransform == GeoTransform.WGS84Cartesian) {
  108174. root.applyMatrix4(tileTransform);
  108175. root.updateMatrixWorld(true);
  108176. rootCenter.copy(root.position);
  108177. }
  108178. function detectOrientation(tile) {
  108179. if (!tile.boundingVolume.halfAxes) {
  108180. return;
  108181. }
  108182. const halfAxes = tile.boundingVolume.halfAxes;
  108183. const orientationMatrix = new Matrix4()
  108184. .extractRotation(getMatrix4FromHalfAxes(halfAxes))
  108185. .premultiply(new Matrix4().extractRotation(rootTransformInverse));
  108186. const rotation = new Euler().setFromRotationMatrix(orientationMatrix);
  108187. if (!rotation.equals(new Euler())) {
  108188. orientationDetected = true;
  108189. const pos = new Vector3(tileTransform.elements[12], tileTransform.elements[13], tileTransform.elements[14]);
  108190. tileTransform.extractRotation(orientationMatrix);
  108191. tileTransform.setPosition(pos);
  108192. updateResetTransform();
  108193. }
  108194. }
  108195. function updateResetTransform() {
  108196. if (options.geoTransform != GeoTransform.WGS84Cartesian) {
  108197. // Reset the current model matrix and apply our own transformation
  108198. //threeMat.copy(tileTransform).invert();
  108199. //threeMat.premultiply(lastRootTransform); //xzw删 被下面copy这句覆盖了
  108200. let tileTransInvert = new Matrix4().copy(tileTransform).invert();
  108201. threeMat.copy(lastRootTransform).multiply(tileTransInvert);
  108202. tileset.modelMatrix = new Matrix4$1(threeMat.toArray());
  108203. //console.log('update tileset ModelMatrix', tileset.modelMatrix.elements)
  108204. tileset.tileTransInvert = tileTransInvert.toArray(); // add for volumebox
  108205. }
  108206. }
  108207. // 更新瓦片显隐和瓦片迭代更新
  108208. function tilesetUpdate(tileset, renderMap, renderer, camera) {
  108209. if (disposeFlag || options.pauseTilesetUpdate) {// !zeg改 pauseTilesetUpdate
  108210. return
  108211. }
  108212. // Assumes camera fov, near and far are not changing
  108213. if (!sseDenominator || camera.aspect != lastCameraAspect) {
  108214. const loadersFrustum = new PerspectiveFrustum({
  108215. fov: (camera.fov / 180) * Math.PI,
  108216. aspectRatio: camera.aspect,
  108217. near: camera.near,
  108218. far: camera.far,
  108219. });
  108220. sseDenominator = loadersFrustum.sseDenominator;
  108221. lastCameraAspect = camera.aspect;
  108222. if(camera.aspect == 0)return//add
  108223. if (options.debug) {
  108224. console.log('Updated sse denonimator:', sseDenominator);
  108225. }
  108226. }
  108227. const frustum = getCameraFrustum(camera);
  108228. const planes = frustum.planes.map((plane) => new Plane$1(plane.normal.toArray(), plane.constant));
  108229. const cullingVolume = new CullingVolume(planes);
  108230. const rendererSize = new Vector2();
  108231. renderer.getSize(rendererSize);
  108232. const frameState = {
  108233. camera: {
  108234. position: lastCameraPosition.toArray(),
  108235. },
  108236. height: rendererSize.y,
  108237. frameNumber: tileset._frameNumber,
  108238. sseDenominator: sseDenominator,
  108239. cullingVolume: cullingVolume,
  108240. viewport: {
  108241. id: 0,
  108242. },
  108243. };
  108244. tileset._cache.reset();
  108245. tileset._traverser.traverse(tileset.root, frameState, tileset.options);
  108246. for (const tile of tileset.tiles) {
  108247. if (tile.selected) {
  108248. if (!renderMap[tile.id]) {
  108249. console.error('TILE SELECTED BUT NOT LOADED!!', tile.id);
  108250. }
  108251. else {
  108252. // Make sure it's visible
  108253. if(!renderMap[tile.id].visible){
  108254. if(viewer.visiVertexCount<maxVertexVisi){
  108255. renderMap[tile.id].visible = true;
  108256. viewer.visiVertexCount += renderMap[tile.id].vertexCount; //xzw add
  108257. options.debug && (boxMap[tile.id].material.opacity = 1 , boxMap[tile.id].children[0].sprite.material.opacity = 1 );
  108258. }else {
  108259. //console.log('超出', visiVertexCount)
  108260. }
  108261. }
  108262. /* if(!renderMap[tile.id].realVisible()){
  108263. console.error('!realVisible')
  108264. } */
  108265. }
  108266. }
  108267. else {
  108268. if (renderMap[tile.id]) {
  108269. if(renderMap[tile.id].visible){
  108270. renderMap[tile.id].visible = false;
  108271. options.debug && (boxMap[tile.id].material.opacity = 0.1, boxMap[tile.id].children[0].sprite.material.opacity = 0.1);
  108272. viewer.visiVertexCount -= renderMap[tile.id].vertexCount; //xzw add
  108273. }
  108274. }
  108275. }
  108276. }
  108277. while (unloadQueue.length > 0) {
  108278. const tile = unloadQueue.pop();
  108279. if (renderMap[tile.id] && tile.contentState == TILE_CONTENT_STATE.UNLOADED) {
  108280. //console.log('removevisi', renderMap[tile.id].visible) 如果是true,visiVertexCount要减
  108281. root.remove(renderMap[tile.id]);
  108282. disposeNode(renderMap[tile.id]);
  108283. delete renderMap[tile.id];
  108284. }
  108285. if (boxMap[tile.id]) {
  108286. disposeNode(boxMap[tile.id]);
  108287. tileBoxes.remove(boxMap[tile.id]);
  108288. delete boxMap[tile.id];
  108289. }
  108290. }
  108291. const tilesLoaded = tileset.stats.get('Tiles Loaded').count;
  108292. const tilesLoading = tileset.stats.get('Tiles Loading').count;
  108293. if (props.onProgress) {
  108294. props.onProgress(tilesLoaded, tilesLoaded + tilesLoading);
  108295. }
  108296. if (props.loadingManager && !loadingEnded) {
  108297. if (tilesLoading == 0 &&
  108298. (options.preloadTilesCount == null ||
  108299. tilesLoaded >= options.preloadTilesCount)) {
  108300. loadingEnded = true;
  108301. props.loadingManager.itemEnd(props.url);
  108302. }
  108303. }
  108304. return frameState;
  108305. }
  108306. return {
  108307. model: root,
  108308. runtime: {
  108309. getTileset: () => {
  108310. return tileset;
  108311. },
  108312. getStats: () => {
  108313. return tileset.stats;
  108314. },
  108315. showTiles: (visible) => {
  108316. tileBoxes.visible = visible;
  108317. },
  108318. setWireframe: (wireframe) => {
  108319. options.wireframe = wireframe;
  108320. root.traverse((object) => {
  108321. if (object instanceof Mesh) {
  108322. object.material.wireframe = wireframe;
  108323. }
  108324. });
  108325. },
  108326. setDebug: (debug) => {
  108327. options.debug = debug;
  108328. tileBoxes.visible = debug;
  108329. },
  108330. setShading: (shading) => {
  108331. options.shading = shading;
  108332. },
  108333. getTileBoxes: () => {
  108334. return tileBoxes;
  108335. },
  108336. setViewDistanceScale: (scale) => {
  108337. tileset.options.viewDistanceScale = scale;
  108338. tileset._frameNumber++;
  108339. tilesetUpdate(tileset, renderMap, rendererReference, cameraReference);
  108340. },
  108341. setHideGround: (enabled) => {
  108342. pointcloudUniforms.hideGround.value = enabled;
  108343. },
  108344. setPointCloudColoring: (selection) => {
  108345. pointcloudUniforms.coloring.value = selection;
  108346. },
  108347. setElevationRange: (range) => {
  108348. pointcloudUniforms.elevationRange.value.set(range[0], range[1]);
  108349. },
  108350. setMaxIntensity: (intensity) => {
  108351. pointcloudUniforms.maxIntensity.value = intensity;
  108352. },
  108353. setIntensityContrast: (contrast) => {
  108354. pointcloudUniforms.intensityContrast.value = contrast;
  108355. },
  108356. setPointAlpha: (alpha) => {
  108357. pointcloudUniforms.alpha.value = alpha;
  108358. },
  108359. getLatLongHeightFromPosition: (position) => {
  108360. const cartographicPosition = tileset.ellipsoid.cartesianToCartographic(new Vector3().copy(position).applyMatrix4(new Matrix4().copy(threeMat).invert()).toArray());
  108361. return {
  108362. lat: cartographicPosition[1],
  108363. long: cartographicPosition[0],
  108364. height: cartographicPosition[2],
  108365. };
  108366. },
  108367. getPositionFromLatLongHeight: (coord) => {
  108368. const cartesianPosition = tileset.ellipsoid.cartographicToCartesian([coord.long, coord.lat, coord.height]);
  108369. return new Vector3(...cartesianPosition).applyMatrix4(threeMat);
  108370. },
  108371. getCameraFrustum: (camera) => {
  108372. const frustum = getCameraFrustum(camera);
  108373. const meshes = frustum.planes
  108374. .map((plane) => new Plane$1(plane.normal.toArray(), plane.constant))
  108375. .map((loadersPlane) => loadersPlaneToMesh(loadersPlane));
  108376. const model = new Group();
  108377. for (const mesh of meshes)
  108378. model.add(mesh);
  108379. return model;
  108380. },
  108381. update: function (dt, renderer, camera, ifForce) {
  108382. cameraReference = camera;
  108383. rendererReference = renderer;
  108384. timer += dt;
  108385. if(!ifForce) ifForce = tileset.nextForceUpdate;
  108386. tileset.nextForceUpdate = false;
  108387. if(tileset.needRenderNext){//必须在下一帧渲染刷新否则无法显示
  108388. viewer.dispatchEvent('content_changed');
  108389. }
  108390. tileset.needRenderNext = ifForce;
  108391. if (tileset && (timer >= UPDATE_INTERVAL || ifForce)) {
  108392. if (!lastRootTransform.equals(root.matrixWorld)) {
  108393. timer = 0;
  108394. lastRootTransform.copy(root.matrixWorld);
  108395. updateResetTransform();
  108396. const rootCenter = new Vector3().setFromMatrixPosition(lastRootTransform);
  108397. pointcloudUniforms.rootCenter.value.copy(rootCenter);
  108398. pointcloudUniforms.rootNormal.value.copy(new Vector3(0, 0, 1).applyMatrix4(lastRootTransform).normalize());
  108399. rootTransformInverse.copy(lastRootTransform).invert();
  108400. if (options.debug) {
  108401. /* console.log('move', tileset.root.id, boxMap[tileset.root.id].matrix.elements, boxMap[tileset.root.id].matrixWorld.elements)
  108402. boxMap[tileset.root.id].matrix.copy(root.matrixWorld);
  108403. boxMap[tileset.root.id].matrixWorld.copy(root.matrixWorld); */
  108404. //boxMap[tileset.root.id].applyMatrix4(threeMat);
  108405. tileBoxes.matrix.copy(root.matrixWorld);
  108406. //boxMap[tileset.root.id].matrixWorld.copy(threeMat);
  108407. //boxMap[tileset.root.id].applyMatrix4(lastRootTransform);//boxMap[tileset.root.id].applyMatrix4(lastRootTransform);
  108408. //boxMap[tileset.root.id].updateWorldMatrix()
  108409. }
  108410. }
  108411. if (this.lastCameraTransform == null) {
  108412. this.lastCameraTransform = new Matrix4().copy(camera.matrixWorld);
  108413. }
  108414. else {
  108415. const cameraChanged = !camera.matrixWorld.equals(this.lastCameraTransform) ||
  108416. !(camera.aspect == lastCameraAspect);
  108417. if (cameraChanged || ifForce) {
  108418. timer = 0;
  108419. tileset._frameNumber++;
  108420. camera.getWorldPosition(lastCameraPosition);
  108421. this.lastCameraTransform.copy(camera.matrixWorld);
  108422. tilesetUpdate(tileset, renderMap, renderer, camera);
  108423. }
  108424. }
  108425. }/* else{
  108426. console.log('11')
  108427. } */
  108428. },
  108429. dispose: function () {
  108430. disposeFlag = true;
  108431. tileset._destroy();
  108432. while (root.children.length > 0) {
  108433. const obj = root.children[0];
  108434. disposeNode(obj);
  108435. root.remove(obj);
  108436. }
  108437. while (tileBoxes.children.length > 0) {
  108438. const obj = tileBoxes.children[0];
  108439. tileBoxes.remove(obj);
  108440. obj.geometry.dispose();
  108441. obj.material.dispose();
  108442. }
  108443. if (ktx2Loader) {
  108444. ktx2Loader.dispose();
  108445. }
  108446. if (dracoLoader) {
  108447. dracoLoader.dispose();
  108448. }
  108449. },
  108450. limit2lowestDepth: isLowest => {//zeg add 设置是否限制为最低精度tile深度
  108451. maxDepth = isLowest ? 1 : 100; //影响到shouldRefine, 检查方法:可以看到当maxDepth降低了之后viewer.objs.children[0].runtime.getTileset().tiles.filter(e=> e.tileContent.visible)变少
  108452. if (cameraReference) {
  108453. tileset._frameNumber++;
  108454. tilesetUpdate(tileset, renderMap, rendererReference, cameraReference);
  108455. }
  108456. },
  108457. },
  108458. };
  108459. });
  108460. }
  108461. }
  108462. function createGLTFNodes(gltfLoader, tile, unlitMaterial, options, rootTransformInverse) {
  108463. return __awaiter(this, void 0, void 0, function* () {
  108464. return new Promise((resolve, reject) => {
  108465. var _a;
  108466. const rotateX = new Matrix4().makeRotationAxis(new Vector3(1, 0, 0), Math.PI / 2);
  108467. const shouldRotate = ((_a = tile.tileset.asset) === null || _a === void 0 ? void 0 : _a.gltfUpAxis) !== "Z";
  108468. // The computed trasnform already contains the root's transform, so we have to invert it
  108469. //const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(tileMatrix)//.premultiply(rootTransformInverse); //xzw 删。原先的会造成移动后tiles错乱
  108470. //const contentTransform = new Matrix4$1().fromArray(tile.computedTransform).premultiply(tile.tileset.modelMatrix).premultiply(rootTransformInverse)
  108471. // 这句同tile.computedTransform左乘tileTransform。 因为tileTransform拿不到所以使用modelMatrix。modelMatrix为tileTransform左乘rootTransform, 所以再左乘rootTransformInverse
  108472. //改动:contentTransform中的computedTransform 去掉左乘 root.modelMatrixWorld , 因为移动过后这个computedTransform没更新
  108473. gltfLoader.parse(
  108474. tile.content.type == 'glTF' ? tile.content.gltf.gltfArrayBuffer : tile.content.gltfArrayBuffer,//tile.content.gltfArrayBuffer,
  108475. tile.contentUrl ? tile.contentUrl.substr(0, tile.contentUrl.lastIndexOf('/') + 1) : '',
  108476. (gltf) => {
  108477. const tileContent = gltf.scenes[0];
  108478. tileContent.vertexCount = 0; //xzw add
  108479. tile.tileContent = tileContent; //xzw add
  108480. let needUpdate;
  108481. if(tile.rtcCenterState != !!tile.content.rtcCenter){ // 等mesh加载好才知道rtcCenter,每个mesh坐标都不一样
  108482. needUpdate = true;
  108483. //console.error('rtcCenter有变化?!')
  108484. }
  108485. tile.rtcCenterState = rtcCenterGlobal = !!tile.content.rtcCenter;
  108486. let contentTransform = tile.getContentTransform(needUpdate);
  108487. if(tile.content.rtcCenter){//大部分模型无 rtcCenter
  108488. //console.error('rtcCenter有?!') //似乎bounding中包含这个信息了 所以getContentTransform不含这个
  108489. let tranM = new Matrix4();
  108490. tranM.makeTranslation(tile.content.rtcCenter[0], tile.content.rtcCenter[1], tile.content.rtcCenter[2]);
  108491. contentTransform.premultiply(tranM);
  108492. }
  108493. if(needUpdate ){
  108494. tile._updateBoundingVolume(tile.header); //add 重新更新
  108495. }
  108496. if (shouldRotate) { //大部分模型 无需 Rotate
  108497. contentTransform.multiply(rotateX); // convert from GLTF Y-up to Z-up
  108498. }
  108499. tileContent.applyMatrix4(contentTransform);
  108500. //'https://testgis.4dage.com/LVBADUI_qp/tileset.json', //村庄 这个案例是 要rotateX 且有rtcCenter的。boundingVolume已经是转换这两者后的值所以getContentTransform不加这个
  108501. //tile总共要左乘的矩阵 rotateX -> tileTransInvert * computedTransform -> 对geometry的tranM修改 -> 整个模型的matrixWorld
  108502. tileContent.traverse((object) => {
  108503. if (object.type == "Mesh") {
  108504. const mesh = object;
  108505. //mesh.tileId = tile.id//add
  108506. const originalMaterial = mesh.material;
  108507. const originalMap = originalMaterial.map;
  108508. if (options.material) {
  108509. mesh.material = options.material.clone();
  108510. originalMaterial.dispose();
  108511. }
  108512. else if (options.shading == Shading.FlatTexture) {
  108513. mesh.material = unlitMaterial.clone();
  108514. originalMaterial.dispose();
  108515. }
  108516. if (options.shading != Shading.ShadedNoTexture) {
  108517. if (mesh.material.type == "ShaderMaterial" && !(mesh.material instanceof BasicMaterial)) {//改
  108518. mesh.material.uniforms.map = { value: originalMap };
  108519. }
  108520. else {
  108521. mesh.material.map = originalMap;
  108522. }
  108523. }
  108524. else {
  108525. if (originalMap) {
  108526. originalMap.dispose();
  108527. }
  108528. mesh.material.map = null;
  108529. }
  108530. if (options.shaderCallback) {
  108531. mesh.onBeforeRender = options.shaderCallback;
  108532. }
  108533. mesh.material.wireframe = options.wireframe;
  108534. if (options.computeNormals) {
  108535. mesh.geometry.computeVertexNormals();
  108536. }
  108537. //xzw add:
  108538. tileContent.vertexCount += mesh.geometry.attributes.position.count;
  108539. //------------------add on 2023.1.16----zeg
  108540. //mesh.geometry.applyMatrix4(contentTransform)
  108541. /* if (tile.content.rtcCenter) {
  108542. // 有些b3dm模型会将坐标写在源码的rtcCenter里 如https://testgis.4dage.com/LVBADUI_qp/tileset.json
  108543. mesh.geometry.translate(tile.content.rtcCenter[0], tile.content.rtcCenter[1], tile.content.rtcCenter[2])
  108544. } else {
  108545. mesh.geometry.scale(1, 1, -1) // 调整缩放,对应box也要进行变换(scaleZ对应box[2])
  108546. } */
  108547. //---------------------
  108548. }
  108549. });
  108550. resolve(tileContent);
  108551. },
  108552. (e) => {
  108553. reject(new Error(`error parsing gltf in tile ${tile.id}: ${e}`));
  108554. }
  108555. );
  108556. });
  108557. });
  108558. }
  108559. function createPointNodes(tile, pointcloudMaterial, options, rootTransformInverse) {
  108560. const d = {
  108561. rtc_center: tile.content.rtcCenter,
  108562. points: tile.content.attributes.positions,
  108563. intensities: tile.content.attributes.intensity,
  108564. classifications: tile.content.attributes.classification,
  108565. rgb: null,
  108566. rgba: null,
  108567. };
  108568. const { colors } = tile.content.attributes;
  108569. if (colors && colors.size === 3) {
  108570. d.rgb = colors.value;
  108571. }
  108572. if (colors && colors.size === 4) {
  108573. d.rgba = colors.value;
  108574. }
  108575. const geometry = new BufferGeometry();
  108576. geometry.setAttribute('position', new Float32BufferAttribute(d.points, 3));
  108577. const contentTransform = new Matrix4().fromArray(tile.computedTransform).premultiply(rootTransformInverse);
  108578. if (d.rgba) {
  108579. geometry.setAttribute('color', new Float32BufferAttribute(d.rgba, 4));
  108580. }
  108581. else if (d.rgb) {
  108582. geometry.setAttribute('color', new Uint8BufferAttribute(d.rgb, 3, true));
  108583. }
  108584. if (d.intensities) {
  108585. geometry.setAttribute('intensity',
  108586. // Handles both 16bit or 8bit intensity values
  108587. new BufferAttribute(d.intensities, 1, true));
  108588. }
  108589. if (d.classifications) {
  108590. geometry.setAttribute('classification', new Uint8BufferAttribute(d.classifications, 1, false));
  108591. }
  108592. const tileContent = new Points(geometry, options.material || pointcloudMaterial);
  108593. if (d.rtc_center) {
  108594. const c = d.rtc_center;
  108595. contentTransform.multiply(new Matrix4().makeTranslation(c[0], c[1], c[2]));
  108596. }
  108597. tileContent.applyMatrix4(contentTransform);
  108598. return tileContent;
  108599. }
  108600. function disposeMaterial(material) {
  108601. var _a, _b, _c, _d;
  108602. if ((_a = material === null || material === void 0 ? void 0 : material.uniforms) === null || _a === void 0 ? void 0 : _a.map) {
  108603. (_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();
  108604. }
  108605. else if (material.map) {
  108606. (_d = material.map) === null || _d === void 0 ? void 0 : _d.dispose();
  108607. }
  108608. material.dispose();
  108609. }
  108610. function disposeNode(node) {
  108611. node.traverse((object) => {
  108612. if (object.isMesh) {
  108613. object.geometry.dispose();
  108614. if (object.material.isMaterial) {
  108615. disposeMaterial(object.material);
  108616. }
  108617. else {
  108618. // an array of materials
  108619. for (const material of object.material) {
  108620. disposeMaterial(material);
  108621. }
  108622. }
  108623. }
  108624. });
  108625. for (let i = node.children.length - 1; i >= 0; i--) {
  108626. const obj = node.children[i];
  108627. node.remove(obj);
  108628. }
  108629. }
  108630. /*
  108631. 关键搜寻:
  108632. Loader3DTiles : const tileset = new Tileset3D
  108633. tileset.dispatchEvent({type:'tileLoaded',tileContent})
  108634. createGLTFNodes(gltfLoader 创建tile
  108635. executeTraversal(root, frameState) 遍历root
  108636. lastRootTransform rootTransformInverse
  108637. tileset._loadTiles 依次加载tiles
  108638. _getPriority 加载优先级 加了一句
  108639. 笔记:
  108640. 主要类:
  108641. class tileset3D 最外层整体。 获取方法: viewer.objs.children[index].runtime.getTileset()。 .tiles包含所有tiles
  108642. class tileHeader 也就是tileset里面的一个个tile 。 其上有.tileset
  108643. tileset里算的tileTransform之后是不会改变的, tile.transform也是,是json里的。
  108644. tileset.modelMatrix (通常这个值很大) 会随着位移改变
  108645. tile.computedTransform 被我修改了,之前左乘了tileset.modelMatrix,现只包含了transform信息 _updateTransform(parentTransfor 其中有_updateBoundingVolume,这个影响可见性, 在computeVisibilityWithPlaneMask中计算
  108646. tileset._cache.trim(), 然后再update //可以将所有不可见的tiles dispose
  108647. 相机靠近容易缺块的bug暂时修改如下: _visible是由computeVisibilityWithPlaneMask计算得
  108648. get isVisibleAndInRequestVolume() {
  108649. return this._inRequestVolume; //去掉了_visible ||
  108650. }
  108651. 显示所有tile似乎也不会卡顿. 但好像影响了加载顺序从而变慢了。visiVertexCount过量。 怀疑应该还是文件的bound有问题。
  108652. 原本会消失的地方虽然不会消失了但一直是模糊的
  108653. =========
  108654. 访问所有tile:
  108655. viewer.objs.children[0].runtime.getTileset().tiles
  108656. 它的mesh: tile.tileContent
  108657. 或者直接得到所有mesh: viewer.objs.children[0].children
  108658. tile.depth最低为1 , root是0
  108659. */
  108660. /**
  108661. * Description: A THREE loader for PLY ASCII files (known as the Polygon
  108662. * File Format or the Stanford Triangle Format).
  108663. *
  108664. * Limitations: ASCII decoding assumes file is UTF-8.
  108665. *
  108666. * Usage:
  108667. * var loader = new PLYLoader();
  108668. * loader.load('./models/ply/ascii/dolphins.ply', function (geometry) {
  108669. *
  108670. * scene.add( new THREE.Mesh( geometry ) );
  108671. *
  108672. * } );
  108673. *
  108674. * If the PLY file uses non standard property names, they can be mapped while
  108675. * loading. For example, the following maps the properties
  108676. * “diffuse_(red|green|blue)” in the file to standard color names.
  108677. *
  108678. * loader.setPropertyNameMapping( {
  108679. * diffuse_red: 'red',
  108680. * diffuse_green: 'green',
  108681. * diffuse_blue: 'blue'
  108682. * } );
  108683. *
  108684. */
  108685. var PLYLoader = function ( manager ) {
  108686. Loader.call( this, manager );
  108687. this.propertyNameMapping = {};
  108688. };
  108689. PLYLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  108690. constructor: PLYLoader,
  108691. load: function ( url, onLoad, onProgress, onError ) {
  108692. var scope = this;
  108693. var loader = new FileLoader( this.manager );
  108694. loader.setPath( this.path );
  108695. loader.setResponseType( 'arraybuffer' );
  108696. loader.setRequestHeader( this.requestHeader );
  108697. loader.setWithCredentials( this.withCredentials );
  108698. loader.load( url, function ( text ) {
  108699. try {
  108700. onLoad( scope.parse( text ) );
  108701. } catch ( e ) {
  108702. if ( onError ) {
  108703. onError( e );
  108704. } else {
  108705. console.error( e );
  108706. }
  108707. scope.manager.itemError( url );
  108708. }
  108709. }, onProgress, onError );
  108710. },
  108711. setPropertyNameMapping: function ( mapping ) {
  108712. this.propertyNameMapping = mapping;
  108713. },
  108714. parse: function ( data ) {
  108715. function parseHeader( data ) {
  108716. var patternHeader = /ply([\s\S]*)end_header\r?\n/;
  108717. var headerText = '';
  108718. var headerLength = 0;
  108719. var result = patternHeader.exec( data );
  108720. if ( result !== null ) {
  108721. headerText = result[ 1 ];
  108722. headerLength = new Blob( [ result[ 0 ] ] ).size;
  108723. }
  108724. var header = {
  108725. comments: [],
  108726. elements: [],
  108727. headerLength: headerLength,
  108728. objInfo: ''
  108729. };
  108730. var lines = headerText.split( '\n' );
  108731. var currentElement;
  108732. var lineType, lineValues;
  108733. function make_ply_element_property( propertValues, propertyNameMapping ) {
  108734. var property = { type: propertValues[ 0 ] };
  108735. if ( property.type === 'list' ) {
  108736. property.name = propertValues[ 3 ];
  108737. property.countType = propertValues[ 1 ];
  108738. property.itemType = propertValues[ 2 ];
  108739. } else {
  108740. property.name = propertValues[ 1 ];
  108741. }
  108742. if ( property.name in propertyNameMapping ) {
  108743. property.name = propertyNameMapping[ property.name ];
  108744. }
  108745. return property;
  108746. }
  108747. for ( var i = 0; i < lines.length; i ++ ) {
  108748. var line = lines[ i ];
  108749. line = line.trim();
  108750. if ( line === '' ) continue;
  108751. lineValues = line.split( /\s+/ );
  108752. lineType = lineValues.shift();
  108753. line = lineValues.join( ' ' );
  108754. switch ( lineType ) {
  108755. case 'format':
  108756. header.format = lineValues[ 0 ];
  108757. header.version = lineValues[ 1 ];
  108758. break;
  108759. case 'comment':
  108760. header.comments.push( line );
  108761. break;
  108762. case 'element':
  108763. if ( currentElement !== undefined ) {
  108764. header.elements.push( currentElement );
  108765. }
  108766. currentElement = {};
  108767. currentElement.name = lineValues[ 0 ];
  108768. currentElement.count = parseInt( lineValues[ 1 ] );
  108769. currentElement.properties = [];
  108770. break;
  108771. case 'property':
  108772. currentElement.properties.push( make_ply_element_property( lineValues, scope.propertyNameMapping ) );
  108773. break;
  108774. case 'obj_info':
  108775. header.objInfo = line;
  108776. break;
  108777. default:
  108778. console.log( 'unhandled', lineType, lineValues );
  108779. }
  108780. }
  108781. if ( currentElement !== undefined ) {
  108782. header.elements.push( currentElement );
  108783. }
  108784. return header;
  108785. }
  108786. function parseASCIINumber( n, type ) {
  108787. switch ( type ) {
  108788. case 'char': case 'uchar': case 'short': case 'ushort': case 'int': case 'uint':
  108789. case 'int8': case 'uint8': case 'int16': case 'uint16': case 'int32': case 'uint32':
  108790. return parseInt( n );
  108791. case 'float': case 'double': case 'float32': case 'float64':
  108792. return parseFloat( n );
  108793. }
  108794. }
  108795. function parseASCIIElement( properties, line ) {
  108796. var values = line.split( /\s+/ );
  108797. var element = {};
  108798. for ( var i = 0; i < properties.length; i ++ ) {
  108799. if ( properties[ i ].type === 'list' ) {
  108800. var list = [];
  108801. var n = parseASCIINumber( values.shift(), properties[ i ].countType );
  108802. for ( var j = 0; j < n; j ++ ) {
  108803. list.push( parseASCIINumber( values.shift(), properties[ i ].itemType ) );
  108804. }
  108805. element[ properties[ i ].name ] = list;
  108806. } else {
  108807. element[ properties[ i ].name ] = parseASCIINumber( values.shift(), properties[ i ].type );
  108808. }
  108809. }
  108810. return element;
  108811. }
  108812. function parseASCII( data, header ) {
  108813. // PLY ascii format specification, as per http://en.wikipedia.org/wiki/PLY_(file_format)
  108814. var buffer = {
  108815. indices: [],
  108816. vertices: [],
  108817. normals: [],
  108818. uvs: [],
  108819. faceVertexUvs: [],
  108820. colors: []
  108821. };
  108822. var result;
  108823. var patternBody = /end_header\s([\s\S]*)$/;
  108824. var body = '';
  108825. if ( ( result = patternBody.exec( data ) ) !== null ) {
  108826. body = result[ 1 ];
  108827. }
  108828. var lines = body.split( '\n' );
  108829. var currentElement = 0;
  108830. var currentElementCount = 0;
  108831. for ( var i = 0; i < lines.length; i ++ ) {
  108832. var line = lines[ i ];
  108833. line = line.trim();
  108834. if ( line === '' ) {
  108835. continue;
  108836. }
  108837. if ( currentElementCount >= header.elements[ currentElement ].count ) {
  108838. currentElement ++;
  108839. currentElementCount = 0;
  108840. }
  108841. var element = parseASCIIElement( header.elements[ currentElement ].properties, line );
  108842. handleElement( buffer, header.elements[ currentElement ].name, element );
  108843. currentElementCount ++;
  108844. }
  108845. return postProcess( buffer );
  108846. }
  108847. function postProcess( buffer ) {
  108848. var geometry = new BufferGeometry();
  108849. // mandatory buffer data
  108850. if ( buffer.indices.length > 0 ) {
  108851. geometry.setIndex( buffer.indices );
  108852. }
  108853. geometry.setAttribute( 'position', new Float32BufferAttribute( buffer.vertices, 3 ) );
  108854. // optional buffer data
  108855. if ( buffer.normals.length > 0 ) {
  108856. geometry.setAttribute( 'normal', new Float32BufferAttribute( buffer.normals, 3 ) );
  108857. }
  108858. if ( buffer.uvs.length > 0 ) {
  108859. geometry.setAttribute( 'uv', new Float32BufferAttribute( buffer.uvs, 2 ) );
  108860. }
  108861. if ( buffer.colors.length > 0 ) {
  108862. geometry.setAttribute( 'color', new Float32BufferAttribute( buffer.colors, 3 ) );
  108863. }
  108864. if ( buffer.faceVertexUvs.length > 0 ) {
  108865. geometry = geometry.toNonIndexed();
  108866. geometry.setAttribute( 'uv', new Float32BufferAttribute( buffer.faceVertexUvs, 2 ) );
  108867. }
  108868. geometry.computeBoundingSphere();
  108869. return geometry;
  108870. }
  108871. function handleElement( buffer, elementName, element ) {
  108872. if ( elementName === 'vertex' ) {
  108873. buffer.vertices.push( element.x, element.y, element.z );
  108874. if ( 'nx' in element && 'ny' in element && 'nz' in element ) {
  108875. buffer.normals.push( element.nx, element.ny, element.nz );
  108876. }
  108877. if ( 's' in element && 't' in element ) {
  108878. buffer.uvs.push( element.s, element.t );
  108879. }
  108880. if ( 'red' in element && 'green' in element && 'blue' in element ) {
  108881. buffer.colors.push( element.red / 255.0, element.green / 255.0, element.blue / 255.0 );
  108882. }
  108883. } else if ( elementName === 'face' ) {
  108884. var vertex_indices = element.vertex_indices || element.vertex_index; // issue #9338
  108885. var texcoord = element.texcoord;
  108886. if ( vertex_indices.length === 3 ) {
  108887. buffer.indices.push( vertex_indices[ 0 ], vertex_indices[ 1 ], vertex_indices[ 2 ] );
  108888. if ( texcoord && texcoord.length === 6 ) {
  108889. buffer.faceVertexUvs.push( texcoord[ 0 ], texcoord[ 1 ] );
  108890. buffer.faceVertexUvs.push( texcoord[ 2 ], texcoord[ 3 ] );
  108891. buffer.faceVertexUvs.push( texcoord[ 4 ], texcoord[ 5 ] );
  108892. }
  108893. } else if ( vertex_indices.length === 4 ) {
  108894. buffer.indices.push( vertex_indices[ 0 ], vertex_indices[ 1 ], vertex_indices[ 3 ] );
  108895. buffer.indices.push( vertex_indices[ 1 ], vertex_indices[ 2 ], vertex_indices[ 3 ] );
  108896. }
  108897. }
  108898. }
  108899. function binaryRead( dataview, at, type, little_endian ) {
  108900. switch ( type ) {
  108901. // corespondences for non-specific length types here match rply:
  108902. case 'int8': case 'char': return [ dataview.getInt8( at ), 1 ];
  108903. case 'uint8': case 'uchar': return [ dataview.getUint8( at ), 1 ];
  108904. case 'int16': case 'short': return [ dataview.getInt16( at, little_endian ), 2 ];
  108905. case 'uint16': case 'ushort': return [ dataview.getUint16( at, little_endian ), 2 ];
  108906. case 'int32': case 'int': return [ dataview.getInt32( at, little_endian ), 4 ];
  108907. case 'uint32': case 'uint': return [ dataview.getUint32( at, little_endian ), 4 ];
  108908. case 'float32': case 'float': return [ dataview.getFloat32( at, little_endian ), 4 ];
  108909. case 'float64': case 'double': return [ dataview.getFloat64( at, little_endian ), 8 ];
  108910. }
  108911. }
  108912. function binaryReadElement( dataview, at, properties, little_endian ) {
  108913. var element = {};
  108914. var result, read = 0;
  108915. for ( var i = 0; i < properties.length; i ++ ) {
  108916. if ( properties[ i ].type === 'list' ) {
  108917. var list = [];
  108918. result = binaryRead( dataview, at + read, properties[ i ].countType, little_endian );
  108919. var n = result[ 0 ];
  108920. read += result[ 1 ];
  108921. for ( var j = 0; j < n; j ++ ) {
  108922. result = binaryRead( dataview, at + read, properties[ i ].itemType, little_endian );
  108923. list.push( result[ 0 ] );
  108924. read += result[ 1 ];
  108925. }
  108926. element[ properties[ i ].name ] = list;
  108927. } else {
  108928. result = binaryRead( dataview, at + read, properties[ i ].type, little_endian );
  108929. element[ properties[ i ].name ] = result[ 0 ];
  108930. read += result[ 1 ];
  108931. }
  108932. }
  108933. return [ element, read ];
  108934. }
  108935. function parseBinary( data, header ) {
  108936. var buffer = {
  108937. indices: [],
  108938. vertices: [],
  108939. normals: [],
  108940. uvs: [],
  108941. faceVertexUvs: [],
  108942. colors: []
  108943. };
  108944. var little_endian = ( header.format === 'binary_little_endian' );
  108945. var body = new DataView( data, header.headerLength );
  108946. var result, loc = 0;
  108947. for ( var currentElement = 0; currentElement < header.elements.length; currentElement ++ ) {
  108948. for ( var currentElementCount = 0; currentElementCount < header.elements[ currentElement ].count; currentElementCount ++ ) {
  108949. result = binaryReadElement( body, loc, header.elements[ currentElement ].properties, little_endian );
  108950. loc += result[ 1 ];
  108951. var element = result[ 0 ];
  108952. handleElement( buffer, header.elements[ currentElement ].name, element );
  108953. }
  108954. }
  108955. return postProcess( buffer );
  108956. }
  108957. //
  108958. var geometry;
  108959. var scope = this;
  108960. if ( data instanceof ArrayBuffer ) {
  108961. var text = LoaderUtils.decodeText( new Uint8Array( data ) );
  108962. var header = parseHeader( text );
  108963. geometry = header.format === 'ascii' ? parseASCII( text, header ) : parseBinary( data, header );
  108964. } else {
  108965. geometry = parseASCII( data, parseHeader( data ) );
  108966. }
  108967. return geometry;
  108968. }
  108969. } );
  108970. /**
  108971. *
  108972. * Supersample Anti-Aliasing Render Pass
  108973. *
  108974. * @author bhouston / http://clara.io/
  108975. *
  108976. * This manual approach to SSAA re-renders the scene ones for each sample with camera jitter and accumulates the results.
  108977. *
  108978. * References: https://en.wikipedia.org/wiki/Supersampling
  108979. *
  108980. */
  108981. //较为原始的一种抗锯齿 (超级采样抗锯齿)
  108982. let SSAARenderPass = function ( clearColor, clearAlpha ) {
  108983. Pass.call( this );
  108984. //this.scene //= scene;
  108985. //this.camera = camera;
  108986. this.sampleLevel = 4; // specified as n, where the number of samples is 2^n, so sampleLevel = 4, is 2^4 samples, 16.
  108987. this.unbiased = true;
  108988. // as we need to clear the buffer in this pass, clearColor must be set to something, defaults to black.
  108989. this.clearColor = ( clearColor !== undefined ) ? clearColor : 0x000000;
  108990. this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
  108991. this.renderUniforms = {
  108992. bgTex : {value:null},
  108993. outlineTex : {value:null},
  108994. opacity : {value:1},
  108995. };
  108996. this.renderMat = new ShaderMaterial({
  108997. uniforms: this.renderUniforms,
  108998. vertexShader: CopyShader.vertexShader,
  108999. /* fragmentShader: CopyShader.fragmentShader, */
  109000. fragmentShader: `
  109001. uniform sampler2D bgTex;
  109002. uniform sampler2D outlineTex;
  109003. uniform float opacity;
  109004. varying vec2 vUv;
  109005. void main() {
  109006. vec4 color1 = texture2D( bgTex, vUv );
  109007. vec4 color2 = texture2D( outlineTex, vUv );
  109008. gl_FragColor = opacity * mix(color1, color2, color2.a) ;
  109009. }
  109010. `,
  109011. premultipliedAlpha: true,
  109012. blending: AdditiveBlending,
  109013. depthTest: false,
  109014. depthWrite: false,
  109015. transparent: true
  109016. });
  109017. this.renderMat2 = new ShaderMaterial({
  109018. uniforms: UniformsUtils.clone(CopyShader.uniforms) ,
  109019. vertexShader: CopyShader.vertexShader,
  109020. fragmentShader:`uniform float opacity;
  109021. uniform sampler2D tDiffuse;
  109022. varying vec2 vUv;
  109023. void main() {
  109024. vec4 texel = texture2D( tDiffuse, vUv );
  109025. if(texel.r == 0.0 && texel.g == 0.0 && texel.b == 0.0){
  109026. discard;
  109027. }else{
  109028. gl_FragColor = opacity * texel;
  109029. }
  109030. }
  109031. ` ,
  109032. depthTest: false,
  109033. depthWrite: false,
  109034. transparent: true
  109035. });
  109036. ////////////////////
  109037. /* this.renderMat.blendSrc = THREE.OneFactor //即将写入缓冲区的颜色。
  109038. this.renderMat.blendDst = THREE.OneFactor //缓冲区已经存在的颜色
  109039. this.renderMat.blendEquation = THREE.AddEquation;
  109040. this.renderMat.blendEquationAlpha = THREE.AddEquation;
  109041. this.renderMat.blendDstAlpha = THREE.SrcAlphaFactor
  109042. this.renderMat.blendSrcAlpha = THREE.SrcAlphaFactor */
  109043. this.camera2 = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  109044. this.scene2 = new Scene();
  109045. this.quad2 = new Mesh( new PlaneBufferGeometry( 2, 2 ), this.renderMat/* this.copyMaterial */ );
  109046. this.quad2.frustumCulled = false; // Avoid getting clipped
  109047. this.scene2.add( this.quad2 );
  109048. this.copyPass = new ShaderPass( CopyShader );
  109049. this.copyPass.renderToScreen = true;
  109050. };
  109051. SSAARenderPass.prototype = Object.assign( Object.create( Pass.prototype ), {
  109052. constructor: SSAARenderPass,
  109053. dispose: function () {
  109054. if ( this.sampleRenderTarget ) {
  109055. this.sampleRenderTarget.dispose();
  109056. this.sampleRenderTarget = null;
  109057. }
  109058. },
  109059. setSize: function ( width, height ) {
  109060. if ( this.sampleRenderTarget ) this.sampleRenderTarget.setSize( width, height );
  109061. this.childPass && this.childPass.setSize(width, height);
  109062. },
  109063. addPass: function (pass){
  109064. this.childPass = pass;
  109065. },
  109066. render: function (scene, camera, viewports, renderer, writeBuffer, readBuffer, maskActive, renderFun ) {
  109067. if(this.useCopy ){
  109068. scene = this.copyPass.scene; camera = this.copyPass.camera;
  109069. }
  109070. if ( ! this.sampleRenderTarget ) {
  109071. this.sampleRenderTarget = new WebGLRenderTarget( readBuffer.width, readBuffer.height, { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat } );
  109072. this.sampleRenderTarget.texture.name = "SSAARenderPass.sample";
  109073. }
  109074. var jitterOffsets = SSAARenderPass.JitterVectors[ Math.max( 0, Math.min( this.sampleLevel, 5 ) ) ];
  109075. var autoClear = renderer.autoClear;
  109076. renderer.autoClear = false;
  109077. var oldClearColor = renderer.getClearColor(new Color).getHex();
  109078. var oldClearAlpha = renderer.getClearAlpha();
  109079. renderer.setClearColor( this.clearColor, this.clearAlpha );
  109080. var baseSampleWeight = 1.0 / jitterOffsets.length;
  109081. var roundingRange = 1 / 32;
  109082. //this.copyUniforms[ "tDiffuse" ].value = this.sampleRenderTarget.texture;
  109083. let oldTarget = renderer.getRenderTarget();
  109084. if(oldTarget){
  109085. if(oldTarget.scissorTest){
  109086. var width = oldTarget.scissor.w, height = oldTarget.scissor.z;
  109087. }else {
  109088. var width = oldTarget.width, height = oldTarget.height;
  109089. }
  109090. }else {
  109091. var width = readBuffer.width, height = readBuffer.height;
  109092. }
  109093. // render the scene multiple times, each slightly jitter offset from the last and accumulate the results.
  109094. let opa = 0;
  109095. for ( var i = 0; i < jitterOffsets.length; i ++ ) {
  109096. var jitterOffset = jitterOffsets[ i ];
  109097. if ( camera.setViewOffset ) {
  109098. camera.setViewOffset( width, height,
  109099. jitterOffset[ 0 ] * 0.0625 , jitterOffset[ 1 ] * 0.0625 , // 0.0625 = 1 / 16
  109100. width, height );
  109101. }
  109102. var sampleWeight = baseSampleWeight;
  109103. if ( this.unbiased ) {//更柔和
  109104. var uniformCenteredDistribution = ( - 0.5 + ( i + 0.5 ) / jitterOffsets.length );
  109105. sampleWeight += roundingRange * uniformCenteredDistribution;
  109106. }
  109107. renderer.setRenderTarget(this.sampleRenderTarget);
  109108. renderer.clear();
  109109. if(this.useCopy){
  109110. this.copyPass.render(scene,camera, null,renderer, writeBuffer, readBuffer );
  109111. }else {
  109112. if(renderFun){
  109113. renderFun({target : this.sampleRenderTarget});
  109114. }else {
  109115. renderer.render( scene, camera );
  109116. }
  109117. }
  109118. renderer.setRenderTarget(oldTarget);
  109119. //---------------------
  109120. //获取outline tex
  109121. let hasOutline = this.childPass && this.childPass.render(scene, camera, renderer, writeBuffer, readBuffer, null, renderFun );
  109122. //合成到该材质
  109123. this.renderUniforms[ "bgTex" ].value = this.sampleRenderTarget.texture;
  109124. this.renderUniforms[ "outlineTex" ].value = hasOutline ? readBuffer.texture : null;
  109125. this.renderUniforms[ "opacity" ].value = sampleWeight;
  109126. /* console.log('sampleWeight', sampleWeight)
  109127. opa += sampleWeight */
  109128. if(!this.renderToScreen){
  109129. renderer.setRenderTarget(writeBuffer);
  109130. }
  109131. if(i === 0 ){
  109132. renderer.setClearColor( 0x000000, 0 ); //叠加前颜色必须0
  109133. renderer.clear();
  109134. }
  109135. renderer.render( this.scene2, this.camera2); // , this.renderToScreen ? null : writeBuffer, ( i === 0 )
  109136. if(!this.renderToScreen){
  109137. renderer.setRenderTarget(oldTarget);
  109138. }
  109139. //if(i==2)break;
  109140. }
  109141. //console.log('sum:',opa)
  109142. if ( camera.clearViewOffset )camera.clearViewOffset();
  109143. //renderer.setRenderTarget(readBuffer)
  109144. //renderer.setClearColor( 0x000000, 0 );
  109145. //renderer.clear()
  109146. /* this.quad2.material = this.renderMat2
  109147. this.renderMat2.uniforms.tDiffuse.value = writeBuffer.texture;
  109148. renderer.render( this.scene2, this.camera2);
  109149. this.quad2.material = this.renderMat */
  109150. //renderer.setRenderTarget(oldTarget)
  109151. renderer.autoClear = autoClear;
  109152. renderer.setClearColor( oldClearColor, oldClearAlpha );
  109153. /* 试了好几次,测量线的透明度还是还原不了。 clearAlpha十分影响结果。
  109154. 因为绘制测量线需要背景透明。 或许可以先全部绘制完后,再 copyshader中 抗锯齿?
  109155. 另外会有黑边。
  109156. */
  109157. }
  109158. } );
  109159. // These jitter vectors are specified in integers because it is easier.
  109160. // I am assuming a [-8,8) integer grid, but it needs to be mapped onto [-0.5,0.5)
  109161. // before being used, thus these integers need to be scaled by 1/16.
  109162. //
  109163. // Sample patterns reference: https://msdn.microsoft.com/en-us/library/windows/desktop/ff476218%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396
  109164. SSAARenderPass.JitterVectors = [
  109165. [
  109166. [ 0, 0 ]
  109167. ],
  109168. [
  109169. [ 4, 4 ], [ - 4, - 4 ]
  109170. ],
  109171. [
  109172. [ - 2, - 6 ], [ 6, - 2 ], [ - 6, 2 ], [ 2, 6 ]
  109173. ],
  109174. [
  109175. [ 1, - 3 ], [ - 1, 3 ], [ 5, 1 ], [ - 3, - 5 ],
  109176. [ - 5, 5 ], [ - 7, - 1 ], [ 3, 7 ], [ 7, - 7 ]
  109177. ],
  109178. [
  109179. [ 1, 1 ], [ - 1, - 3 ], [ - 3, 2 ], [ 4, - 1 ],
  109180. [ - 5, - 2 ], [ 2, 5 ], [ 5, 3 ], [ 3, - 5 ],
  109181. [ - 2, 6 ], [ 0, - 7 ], [ - 4, - 6 ], [ - 6, 4 ],
  109182. [ - 8, 0 ], [ 7, - 4 ], [ 6, 7 ], [ - 7, - 8 ]
  109183. ],
  109184. [
  109185. [ - 4, - 7 ], [ - 7, - 5 ], [ - 3, - 5 ], [ - 5, - 4 ],
  109186. [ - 1, - 4 ], [ - 2, - 2 ], [ - 6, - 1 ], [ - 4, 0 ],
  109187. [ - 7, 1 ], [ - 1, 2 ], [ - 6, 3 ], [ - 3, 3 ],
  109188. [ - 7, 6 ], [ - 3, 6 ], [ - 5, 7 ], [ - 1, 7 ],
  109189. [ 5, - 7 ], [ 1, - 6 ], [ 6, - 5 ], [ 4, - 4 ],
  109190. [ 2, - 3 ], [ 7, - 2 ], [ 1, - 1 ], [ 4, - 1 ],
  109191. [ 2, 1 ], [ 6, 2 ], [ 0, 4 ], [ 4, 4 ],
  109192. [ 2, 5 ], [ 7, 5 ], [ 5, 6 ], [ 3, 7 ]
  109193. ]
  109194. ];
  109195. class MaskPass extends Pass {
  109196. constructor( scene, camera ) {
  109197. super();
  109198. this.scene = scene;
  109199. this.camera = camera;
  109200. this.clear = true;
  109201. this.needsSwap = false;
  109202. this.inverse = false;
  109203. }
  109204. render( renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  109205. const context = renderer.getContext();
  109206. const state = renderer.state;
  109207. // don't update color or depth
  109208. state.buffers.color.setMask( false );
  109209. state.buffers.depth.setMask( false );
  109210. // lock buffers
  109211. state.buffers.color.setLocked( true );
  109212. state.buffers.depth.setLocked( true );
  109213. // set up stencil
  109214. let writeValue, clearValue;
  109215. if ( this.inverse ) {
  109216. writeValue = 0;
  109217. clearValue = 1;
  109218. } else {
  109219. writeValue = 1;
  109220. clearValue = 0;
  109221. }
  109222. state.buffers.stencil.setTest( true );
  109223. state.buffers.stencil.setOp( context.REPLACE, context.REPLACE, context.REPLACE );
  109224. state.buffers.stencil.setFunc( context.ALWAYS, writeValue, 0xffffffff );
  109225. state.buffers.stencil.setClear( clearValue );
  109226. state.buffers.stencil.setLocked( true );
  109227. // draw into the stencil buffer
  109228. renderer.setRenderTarget( readBuffer );
  109229. if ( this.clear ) renderer.clear();
  109230. renderer.render( this.scene, this.camera );
  109231. renderer.setRenderTarget( writeBuffer );
  109232. if ( this.clear ) renderer.clear();
  109233. renderer.render( this.scene, this.camera );
  109234. // unlock color and depth buffer for subsequent rendering
  109235. state.buffers.color.setLocked( false );
  109236. state.buffers.depth.setLocked( false );
  109237. // only render where stencil is set to 1
  109238. state.buffers.stencil.setLocked( false );
  109239. state.buffers.stencil.setFunc( context.EQUAL, 1, 0xffffffff ); // draw if == 1
  109240. state.buffers.stencil.setOp( context.KEEP, context.KEEP, context.KEEP );
  109241. state.buffers.stencil.setLocked( true );
  109242. }
  109243. }
  109244. class ClearMaskPass extends Pass {
  109245. constructor() {
  109246. super();
  109247. this.needsSwap = false;
  109248. }
  109249. render( renderer /*, writeBuffer, readBuffer, deltaTime, maskActive */ ) {
  109250. renderer.state.buffers.stencil.setLocked( false );
  109251. renderer.state.buffers.stencil.setTest( false );
  109252. }
  109253. }
  109254. /**
  109255. * @author alteredq / http://alteredqualia.com/
  109256. */
  109257. var EffectComposer = function ( renderer, renderTarget ) {
  109258. this.renderer = renderer;
  109259. if ( renderTarget === undefined ) {
  109260. var parameters = {
  109261. minFilter: LinearFilter,
  109262. magFilter: LinearFilter,
  109263. format: RGBAFormat,
  109264. stencilBuffer: false,
  109265. };
  109266. var size = renderer.getDrawingBufferSize(new Vector2);
  109267. renderTarget = new WebGLRenderTarget( size.width, size.height , parameters );
  109268. renderTarget.texture.name = 'EffectComposer.rt1';
  109269. }
  109270. this.renderTarget1 = renderTarget;
  109271. this.renderTarget2 = renderTarget.clone();
  109272. this.renderTarget2.texture.name = 'EffectComposer.rt2';
  109273. this.writeBuffer = this.renderTarget1;
  109274. this.readBuffer = this.renderTarget2;
  109275. this.passes = [];
  109276. // dependencies
  109277. /* if ( THREE.CopyShader === undefined ) {
  109278. console.error( 'THREE.EffectComposer relies on THREE.CopyShader' );
  109279. }
  109280. if ( THREE.ShaderPass === undefined ) {
  109281. console.error( 'THREE.EffectComposer relies on THREE.ShaderPass' );
  109282. } */
  109283. this.copyPass = new ShaderPass( CopyShader );
  109284. viewer.addEventListener('resize',(e)=>{ //readTarget的话是渲染一整张的,暂时无法一个个viewport渲染所以不用
  109285. this.readTarget || this.setSize(e.viewport.resolution2.x,e.viewport.resolution2.y); //暂时假设composer渲染的viewer的viewports.length == 1
  109286. });
  109287. };
  109288. Object.assign( EffectComposer.prototype, {
  109289. swapBuffers: function () {
  109290. var tmp = this.readBuffer;
  109291. this.readBuffer = this.writeBuffer;
  109292. this.writeBuffer = tmp;
  109293. },
  109294. addPass: function ( pass ) {
  109295. this.passes.push( pass );
  109296. var size = this.renderer.getDrawingBufferSize(new Vector2);
  109297. pass.setSize( size.width, size.height );
  109298. },
  109299. removePass: function(pass){ //add
  109300. let index = this.passes.indexOf(pass);
  109301. index > -1 && this.passes.splice(index,1);
  109302. },
  109303. insertPass: function ( pass, index ) {
  109304. this.passes.splice( index, 0, pass );
  109305. },
  109306. render: function ( scene, camera, viewports, renderFun ) {
  109307. var maskActive = false;
  109308. let passes = this.passes.filter(e=>e.enabled);
  109309. var pass, i, il = passes.length;
  109310. let oldTarget = this.renderer.getRenderTarget();
  109311. if(this.readTarget && oldTarget){ //add 使用当前renderTarget中的像素
  109312. this.setSize(oldTarget.width, oldTarget.height);//所有viewports一起渲染,整个画面 因暂时没办法一个个copy
  109313. oldTarget.viewport.set(0, 0, oldTarget.width, oldTarget.height);
  109314. oldTarget.scissorTest = false;
  109315. this.copyPass.render( scene, camera,viewports, this.renderer, this.readBuffer, oldTarget );
  109316. }
  109317. for ( i = 0; i < il; i ++ ) {
  109318. pass = passes[ i ];
  109319. //if(i == il-1)pass.renderToScreen = true//
  109320. pass.render( scene, camera, viewports, this.renderer, this.writeBuffer, this.readBuffer, maskActive, renderFun );
  109321. if ( pass.needsSwap ) {
  109322. if ( maskActive ) {
  109323. var context = this.renderer.context;
  109324. context.stencilFunc( context.NOTEQUAL, 1, 0xffffffff );
  109325. this.copyPass.render(null,null, viewports, this.renderer, this.writeBuffer, this.readBuffer );// delta
  109326. context.stencilFunc( context.EQUAL, 1, 0xffffffff );
  109327. }
  109328. this.swapBuffers();
  109329. }
  109330. if ( MaskPass !== undefined ) {
  109331. if ( pass instanceof MaskPass ) {
  109332. maskActive = true;
  109333. } else if ( pass instanceof ClearMaskPass ) {
  109334. maskActive = false;
  109335. }
  109336. }
  109337. }
  109338. this.renderer.setRenderTarget(oldTarget);
  109339. //add
  109340. if(!pass.renderToScreen){ //最后一个如果没有绘制到屏幕or target上
  109341. this.copyPass.renderToScreen = true;
  109342. this.copyPass.render(null,null, viewports,this.renderer, this.writeBuffer, this.readBuffer);
  109343. }
  109344. },
  109345. reset: function ( renderTarget ) {
  109346. if ( renderTarget === undefined ) {
  109347. var size = this.renderer.getDrawingBufferSize(new Vector2);
  109348. renderTarget = this.renderTarget1.clone();
  109349. renderTarget.setSize( size.width, size.height );
  109350. }
  109351. this.renderTarget1.dispose();
  109352. this.renderTarget2.dispose();
  109353. this.renderTarget1 = renderTarget;
  109354. this.renderTarget2 = renderTarget.clone();
  109355. this.writeBuffer = this.renderTarget1;
  109356. this.readBuffer = this.renderTarget2;
  109357. },
  109358. setSize: function ( width, height, scaleRatio ) {
  109359. scaleRatio = scaleRatio || this.scaleRatio || 1;
  109360. //console.log('setSize', width * scaleRatio, height * scaleRatio)
  109361. let maxTexWidth = 4096;
  109362. let w = width * scaleRatio;
  109363. let h = height * scaleRatio;
  109364. if(w > maxTexWidth || h > maxTexWidth){ //超出会崩溃
  109365. if(w>h){
  109366. scaleRatio = maxTexWidth / width;
  109367. }else {
  109368. scaleRatio = maxTexWidth / height;
  109369. }
  109370. }
  109371. w = width * scaleRatio;
  109372. h = height * scaleRatio;
  109373. this.renderTarget1.setSize( w, h );
  109374. this.renderTarget2.setSize( w, h );
  109375. for ( var i = 0; i < this.passes.length; i ++ ) {
  109376. this.passes[ i ].setSize( w, h );
  109377. }
  109378. }
  109379. } );
  109380. /**
  109381. * @author alteredq / http://alteredqualia.com/
  109382. */
  109383. class RenderPass extends Pass {
  109384. constructor( overrideMaterial, clearColor, clearAlpha ) {
  109385. super();
  109386. /* this.scene = scene;
  109387. this.camera = camera; */
  109388. this.overrideMaterial = overrideMaterial;
  109389. this.clearColor = clearColor;
  109390. this.clearAlpha = ( clearAlpha !== undefined ) ? clearAlpha : 0;
  109391. this.clear = true;
  109392. this.clearDepth = false;
  109393. this.needsSwap = false;
  109394. this._oldClearColor = new Color();
  109395. }
  109396. render(scene, camera, viewports,renderer, writeBuffer, readBuffer /*, deltaTime, maskActive */ ) {
  109397. const oldAutoClear = renderer.autoClear;
  109398. renderer.autoClear = false;
  109399. let oldClearAlpha, oldOverrideMaterial;
  109400. if ( this.overrideMaterial !== undefined ) {
  109401. oldOverrideMaterial = this.scene.overrideMaterial;
  109402. scene.overrideMaterial = this.overrideMaterial;
  109403. }
  109404. if ( this.clearColor ) {
  109405. renderer.getClearColor( this._oldClearColor );
  109406. oldClearAlpha = renderer.getClearAlpha();
  109407. renderer.setClearColor( this.clearColor, this.clearAlpha );
  109408. }
  109409. if ( this.clearDepth ) {
  109410. renderer.clearDepth();
  109411. }
  109412. let oldTarget = renderer.getRenderTarget();
  109413. if(!this.renderToScreen)renderer.setRenderTarget( readBuffer );
  109414. // TODO: Avoid using autoClear properties, see https://github.com/mrdoob/three.js/pull/15571#issuecomment-465669600
  109415. if ( this.clear ) renderer.clear( renderer.autoClearColor, renderer.autoClearDepth, renderer.autoClearStencil );
  109416. renderer.render( scene, camera );
  109417. if(!this.renderToScreen)renderer.setRenderTarget( oldTarget );
  109418. if ( this.clearColor ) {
  109419. renderer.setClearColor( this._oldClearColor, oldClearAlpha );
  109420. }
  109421. if ( this.overrideMaterial !== undefined ) {
  109422. scene.overrideMaterial = oldOverrideMaterial;
  109423. }
  109424. renderer.setRenderTarget(oldTarget);
  109425. renderer.autoClear = oldAutoClear;
  109426. }
  109427. }
  109428. /**
  109429. * NVIDIA FXAA by Timothy Lottes
  109430. * https://developer.download.nvidia.com/assets/gamedev/files/sdk/11/FXAA_WhitePaper.pdf
  109431. * - WebGL port by @supereggbert
  109432. * http://www.glge.org/demos/fxaa/
  109433. * Further improved by Daniel Sturk
  109434. */
  109435. const FXAAShader = {
  109436. uniforms: {
  109437. 'tDiffuse': { value: null },
  109438. 'resolution': { value: new Vector2( 1 / 1024, 1 / 512 ) }
  109439. },
  109440. vertexShader: /* glsl */`
  109441. varying vec2 vUv;
  109442. void main() {
  109443. vUv = uv;
  109444. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );
  109445. }`,
  109446. fragmentShader: `
  109447. precision highp float;
  109448. uniform sampler2D tDiffuse;
  109449. uniform vec2 resolution;
  109450. varying vec2 vUv;
  109451. // FXAA 3.11 implementation by NVIDIA, ported to WebGL by Agost Biro (biro@archilogic.com)
  109452. //----------------------------------------------------------------------------------
  109453. // File: es3-kepler\FXAA\assets\shaders/FXAA_DefaultES.frag
  109454. // SDK Version: v3.00
  109455. // Email: gameworks@nvidia.com
  109456. // Site: http://developer.nvidia.com/
  109457. //
  109458. // Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
  109459. //
  109460. // Redistribution and use in source and binary forms, with or without
  109461. // modification, are permitted provided that the following conditions
  109462. // are met:
  109463. // * Redistributions of source code must retain the above copyright
  109464. // notice, this list of conditions and the following disclaimer.
  109465. // * Redistributions in binary form must reproduce the above copyright
  109466. // notice, this list of conditions and the following disclaimer in the
  109467. // documentation and/or other materials provided with the distribution.
  109468. // * Neither the name of NVIDIA CORPORATION nor the names of its
  109469. // contributors may be used to endorse or promote products derived
  109470. // from this software without specific prior written permission.
  109471. //
  109472. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
  109473. // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  109474. // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  109475. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  109476. // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  109477. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  109478. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  109479. // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  109480. // OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  109481. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  109482. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  109483. //
  109484. //----------------------------------------------------------------------------------
  109485. #ifndef FXAA_DISCARD
  109486. //
  109487. // Only valid for PC OpenGL currently.
  109488. // Probably will not work when FXAA_GREEN_AS_LUMA = 1.
  109489. //
  109490. // 1 = Use discard on pixels which don't need AA.
  109491. // For APIs which enable concurrent TEX+ROP from same surface.
  109492. // 0 = Return unchanged color on pixels which don't need AA.
  109493. //
  109494. #define FXAA_DISCARD 0
  109495. #endif
  109496. /*--------------------------------------------------------------------------*/
  109497. //第三个参数加入后只能在片元着色器中调用,且只对采样器为mipmap类型纹理时有效。不明白作用??? 但警告说范围在16之内
  109498. #define FxaaTexTop(t, p) texture2D(t, p, -15.0); //-100.0);
  109499. #define FxaaTexOff(t, p, o, r) texture2D(t, p + (o * r), -15.0); //-100.0)
  109500. /*--------------------------------------------------------------------------*/
  109501. #define NUM_SAMPLES 5
  109502. // assumes colors have premultipliedAlpha, so that the calculated color contrast is scaled by alpha
  109503. float contrast( vec4 a, vec4 b ) {
  109504. vec4 diff = abs( a - b );
  109505. return max( max( max( diff.r, diff.g ), diff.b ), diff.a );
  109506. }
  109507. /*============================================================================
  109508. FXAA3 QUALITY - PC
  109509. ============================================================================*/
  109510. /*--------------------------------------------------------------------------*/
  109511. vec4 FxaaPixelShader(
  109512. vec2 posM,
  109513. sampler2D tex,
  109514. vec2 fxaaQualityRcpFrame,
  109515. float fxaaQualityEdgeThreshold,
  109516. float fxaaQualityinvEdgeThreshold
  109517. ) {
  109518. vec4 rgbaM = FxaaTexTop(tex, posM);
  109519. vec4 rgbaS = FxaaTexOff(tex, posM, vec2( 0.0, 1.0), fxaaQualityRcpFrame.xy);
  109520. vec4 rgbaE = FxaaTexOff(tex, posM, vec2( 1.0, 0.0), fxaaQualityRcpFrame.xy);
  109521. vec4 rgbaN = FxaaTexOff(tex, posM, vec2( 0.0,-1.0), fxaaQualityRcpFrame.xy);
  109522. vec4 rgbaW = FxaaTexOff(tex, posM, vec2(-1.0, 0.0), fxaaQualityRcpFrame.xy);
  109523. // . S .
  109524. // W M E
  109525. // . N .
  109526. bool earlyExit = max( max( max(
  109527. contrast( rgbaM, rgbaN ),
  109528. contrast( rgbaM, rgbaS ) ),
  109529. contrast( rgbaM, rgbaE ) ),
  109530. contrast( rgbaM, rgbaW ) )
  109531. < fxaaQualityEdgeThreshold;
  109532. // . 0 .
  109533. // 0 0 0
  109534. // . 0 .
  109535. #if (FXAA_DISCARD == 1)
  109536. if(earlyExit) FxaaDiscard;
  109537. #else
  109538. if(earlyExit) return rgbaM;
  109539. #endif
  109540. float contrastN = contrast( rgbaM, rgbaN );
  109541. float contrastS = contrast( rgbaM, rgbaS );
  109542. float contrastE = contrast( rgbaM, rgbaE );
  109543. float contrastW = contrast( rgbaM, rgbaW );
  109544. float relativeVContrast = ( contrastN + contrastS ) - ( contrastE + contrastW );
  109545. relativeVContrast *= fxaaQualityinvEdgeThreshold;
  109546. bool horzSpan = relativeVContrast > 0.;
  109547. // . 1 .
  109548. // 0 0 0
  109549. // . 1 .
  109550. // 45 deg edge detection and corners of objects, aka V/H contrast is too similar
  109551. if( abs( relativeVContrast ) < .3 ) {
  109552. // locate the edge
  109553. vec2 dirToEdge;
  109554. dirToEdge.x = contrastE > contrastW ? 1. : -1.;
  109555. dirToEdge.y = contrastS > contrastN ? 1. : -1.;
  109556. // . 2 . . 1 .
  109557. // 1 0 2 ~= 0 0 1
  109558. // . 1 . . 0 .
  109559. // tap 2 pixels and see which ones are "outside" the edge, to
  109560. // determine if the edge is vertical or horizontal
  109561. vec4 rgbaAlongH = FxaaTexOff(tex, posM, vec2( dirToEdge.x, -dirToEdge.y ), fxaaQualityRcpFrame.xy);
  109562. float matchAlongH = contrast( rgbaM, rgbaAlongH );
  109563. // . 1 .
  109564. // 0 0 1
  109565. // . 0 H
  109566. vec4 rgbaAlongV = FxaaTexOff(tex, posM, vec2( -dirToEdge.x, dirToEdge.y ), fxaaQualityRcpFrame.xy);
  109567. float matchAlongV = contrast( rgbaM, rgbaAlongV );
  109568. // V 1 .
  109569. // 0 0 1
  109570. // . 0 .
  109571. relativeVContrast = matchAlongV - matchAlongH;
  109572. relativeVContrast *= fxaaQualityinvEdgeThreshold;
  109573. if( abs( relativeVContrast ) < .3 ) { // 45 deg edge
  109574. // 1 1 .
  109575. // 0 0 1
  109576. // . 0 1
  109577. // do a simple blur
  109578. return mix(
  109579. rgbaM,
  109580. (rgbaN + rgbaS + rgbaE + rgbaW) * .25,
  109581. .4
  109582. );
  109583. }
  109584. horzSpan = relativeVContrast > 0.;
  109585. }
  109586. if(!horzSpan) rgbaN = rgbaW;
  109587. if(!horzSpan) rgbaS = rgbaE;
  109588. // . 0 . 1
  109589. // 1 0 1 -> 0
  109590. // . 0 . 1
  109591. bool pairN = contrast( rgbaM, rgbaN ) > contrast( rgbaM, rgbaS );
  109592. if(!pairN) rgbaN = rgbaS;
  109593. vec2 offNP;
  109594. offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
  109595. offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
  109596. bool doneN = false;
  109597. bool doneP = false;
  109598. float nDist = 0.;
  109599. float pDist = 0.;
  109600. vec2 posN = posM;
  109601. vec2 posP = posM;
  109602. int iterationsUsed = 0;
  109603. int iterationsUsedN = 0;
  109604. int iterationsUsedP = 0;
  109605. for( int i = 0; i < NUM_SAMPLES; i++ ) {
  109606. iterationsUsed = i;
  109607. float increment = float(i + 1);
  109608. if(!doneN) {
  109609. nDist += increment;
  109610. posN = posM + offNP * nDist;
  109611. vec4 rgbaEndN = FxaaTexTop(tex, posN.xy);
  109612. doneN = contrast( rgbaEndN, rgbaM ) > contrast( rgbaEndN, rgbaN );
  109613. iterationsUsedN = i;
  109614. }
  109615. if(!doneP) {
  109616. pDist += increment;
  109617. posP = posM - offNP * pDist;
  109618. vec4 rgbaEndP = FxaaTexTop(tex, posP.xy);
  109619. doneP = contrast( rgbaEndP, rgbaM ) > contrast( rgbaEndP, rgbaN );
  109620. iterationsUsedP = i;
  109621. }
  109622. if(doneN || doneP) break;
  109623. }
  109624. if ( !doneP && !doneN ) return rgbaM; // failed to find end of edge
  109625. float dist = min(
  109626. doneN ? float( iterationsUsedN ) / float( NUM_SAMPLES - 1 ) : 1.,
  109627. doneP ? float( iterationsUsedP ) / float( NUM_SAMPLES - 1 ) : 1.
  109628. );
  109629. // hacky way of reduces blurriness of mostly diagonal edges
  109630. // but reduces AA quality
  109631. dist = pow(dist, .5);
  109632. dist = 1. - dist;
  109633. return mix(
  109634. rgbaM,
  109635. rgbaN,
  109636. dist * .5
  109637. );
  109638. }
  109639. void main() {
  109640. const float edgeDetectionQuality = 0.1 ;//.05 ; //越高,越保留细节;越低,越平滑 但模糊
  109641. const float invEdgeDetectionQuality = 1. / edgeDetectionQuality;
  109642. gl_FragColor = FxaaPixelShader(
  109643. vUv,
  109644. tDiffuse,
  109645. resolution,
  109646. edgeDetectionQuality, // [0,1] contrast needed, otherwise early discard
  109647. invEdgeDetectionQuality
  109648. );
  109649. //单独渲染测量线有黑边,因为透明区域的clearColor是(0,0,0),模糊化的时候采用了这些黑色因子来混色。因为测量线颜色可能多种,也不能直接修改clearColor为其颜色,且还有label。
  109650. //故而无法单独渲染测量线,而需要将底图一起渲染。
  109651. }
  109652. `
  109653. };
  109654. /**
  109655. * @author spidersharma / http://eduperiment.com/
  109656. */
  109657. let OutlinePass = function ( selectedObjects ) {
  109658. /* scene = scene;
  109659. camera = camera; */
  109660. this.selectedObjects = selectedObjects !== undefined ? selectedObjects : [];
  109661. this.visibleEdgeColor = new Color( 1, 1, 1 );
  109662. this.hiddenEdgeColor = new Color( 0.1, 0.04, 0.02 );
  109663. this.edgeGlow = 0.0;
  109664. this.usePatternTexture = false;
  109665. //this.edgeThickness = 1.0;
  109666. this.edgeStrength = 50;
  109667. this.downSampleRatio = 1;//2; // 抗锯齿 值越低renderTarget size越大,抗锯齿越强,线条可越细(或许可以把模糊化去掉?)
  109668. this.pulsePeriod = 0;
  109669. this.showHiddenPart = false; //是否判断被遮住的部分,以设置hiddenEdgeColor。一般不需要
  109670. Pass.call( this );
  109671. this.resolution = new Vector2( 256, 256 );
  109672. var pars = { minFilter: LinearFilter, magFilter: LinearFilter, format: RGBAFormat };
  109673. var resx = Math.round( this.resolution.x / this.downSampleRatio );
  109674. var resy = Math.round( this.resolution.y / this.downSampleRatio );
  109675. this.renderTargetMaskBuffer = new WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
  109676. this.renderTargetMaskBuffer.texture.name = "OutlinePass.mask";
  109677. this.renderTargetMaskBuffer.texture.generateMipmaps = false;
  109678. this.depthMaterial = new MeshDepthMaterial();
  109679. this.depthMaterial.side = DoubleSide;
  109680. this.depthMaterial.depthPacking = RGBADepthPacking;
  109681. this.depthMaterial.blending = NoBlending;
  109682. this.prepareMaskMaterial = this.getPrepareMaskMaterial();
  109683. this.prepareMaskMaterial.side = DoubleSide;
  109684. this.renderTargetDepthBuffer = new WebGLRenderTarget( this.resolution.x, this.resolution.y, pars );
  109685. this.renderTargetDepthBuffer.texture.name = "OutlinePass.depth";
  109686. this.renderTargetDepthBuffer.texture.generateMipmaps = false;
  109687. this.edgeDetectionMaterial = this.getEdgeDetectionMaterial(this.edgeStrength);
  109688. this.renderTargetEdgeBuffer1 = new WebGLRenderTarget( resx, resy, pars );
  109689. this.renderTargetEdgeBuffer1.texture.name = "OutlinePass.edge1";
  109690. this.renderTargetEdgeBuffer1.texture.generateMipmaps = false;
  109691. // Overlay material
  109692. this.overlayMaterial = this.getOverlayMaterial();
  109693. // copy material
  109694. this.copyUniforms = UniformsUtils.clone( CopyShader.uniforms );
  109695. this.copyUniforms[ "opacity" ].value = 1.0;
  109696. this.materialCopy = new ShaderMaterial( {
  109697. uniforms: this.copyUniforms,
  109698. vertexShader: CopyShader.vertexShader,
  109699. fragmentShader: CopyShader.fragmentShader,
  109700. blending: NoBlending,
  109701. depthTest: false,
  109702. depthWrite: false,
  109703. transparent: true
  109704. } );
  109705. this.enabled = true;
  109706. this.needsSwap = false;
  109707. this.oldClearColor = new Color();
  109708. this.oldClearAlpha = 1;
  109709. this.camera = new OrthographicCamera( - 1, 1, 1, - 1, 0, 1 );
  109710. this.scene = new Scene();
  109711. this.quad = new Mesh( new PlaneBufferGeometry( 2, 2 ), null );
  109712. this.quad.frustumCulled = false; // Avoid getting clipped
  109713. this.scene.add( this.quad );
  109714. this.textureMatrix = new Matrix4();
  109715. viewer.addEventListener('viewerResize',(e)=>{
  109716. let size = viewer.renderer.getSize(new Vector2);
  109717. this.renderTargetEdgeBuffer1.setSize(size.x, size.y );
  109718. this.renderTargetMaskBuffer.setSize(size.x, size.y);
  109719. this.resolution.set(size.x, size.y);
  109720. });
  109721. };
  109722. OutlinePass.prototype = Object.assign( Object.create( Pass.prototype ), {
  109723. constructor: OutlinePass,
  109724. dispose: function () {
  109725. this.renderTargetMaskBuffer.dispose();
  109726. this.renderTargetEdgeBuffer1.dispose();
  109727. this.renderTargetDepthBuffer.dispose();
  109728. },
  109729. replaceDepthToViewZ( camera ) {
  109730. var type = camera.isPerspectiveCamera ? 'perspective' : 'orthographic';
  109731. if(type == this.lastCameraType )return
  109732. this.lastCameraType = type;
  109733. this.prepareMaskMaterial.fragmentShader = this.prepareMaskMaterial.fragmentShader.replace( /DEPTH_TO_VIEW_Z/g, type + 'DepthToViewZ' );
  109734. this.prepareMaskMaterial.needsUpdate = true;
  109735. },
  109736. setSize: function ( width, height ) {
  109737. },
  109738. changeVisibilityOfSelectedObjects: function ( bVisible ) {
  109739. function gatherSelectedMeshesCallBack( object ) {
  109740. /* if ( object.isMesh ) { */
  109741. if ( object.isPointcloud || object.isMesh || object.isLine || object.isSprite ) {
  109742. /* if ( bVisible ) {
  109743. object.visible = object.userData.oldVisible;
  109744. delete object.userData.oldVisible;
  109745. } else {
  109746. object.userData.oldVisible = object.visible;
  109747. object.visible = bVisible;
  109748. } */
  109749. Potree.Utils.updateVisible(object, 'overlinePass', bVisible);
  109750. }
  109751. }
  109752. for ( var i = 0; i < this.selectedObjects.length; i ++ ) {
  109753. var selectedObject = this.selectedObjects[ i ];
  109754. selectedObject.traverse( gatherSelectedMeshesCallBack );
  109755. }
  109756. },
  109757. changeVisibilityOfNonSelectedObjects: function ( bVisible , scenes) {
  109758. var selectedMeshes = [];
  109759. function gatherSelectedMeshesCallBack( object ) {
  109760. //if ( object.isMesh ) selectedMeshes.push( object );
  109761. if ( object.isPointcloud || object.isMesh || object.isLine || object.isSprite ) {
  109762. selectedMeshes.push( object );
  109763. }
  109764. }
  109765. for ( var i = 0; i < this.selectedObjects.length; i ++ ) {
  109766. var selectedObject = this.selectedObjects[ i ];
  109767. selectedObject.traverse( gatherSelectedMeshesCallBack );
  109768. }
  109769. function VisibilityChangeCallBack( object ) {
  109770. if ( object.isPointcloud || object.isMesh || object.isLine || object.isSprite ) {
  109771. var bFound = false;
  109772. for ( var i = 0; i < selectedMeshes.length; i ++ ) {
  109773. var selectedObjectId = selectedMeshes[ i ].id;
  109774. if ( selectedObjectId === object.id ) {
  109775. bFound = true;
  109776. break;
  109777. }
  109778. }
  109779. if ( ! bFound ) {
  109780. var visibility = object.visible;
  109781. Potree.Utils.updateVisible(object, 'overlinePass', bVisible); //add
  109782. //但保不齐在设置为false后,渲染时又true了,所以在其他地方update时设置visible 得用updateVisible
  109783. if(!bVisible){
  109784. object.visible = false;
  109785. }else {
  109786. object.visible = !!object.bVisible;
  109787. }
  109788. object.bVisible = visibility;
  109789. //这两种updateVisible 和 visible 设置都不能去掉, 第一块是为了防止有的visible不是通过updateVisible设置的; 第二块是为了防止渲染时updateVisible又修改了visible为true, 另外渲染时
  109790. return {stopContinue:true} //for pointcloud
  109791. }
  109792. }
  109793. }
  109794. scenes.forEach(scene=>scene.traverse( VisibilityChangeCallBack ));
  109795. },
  109796. updateTextureMatrix: function (camera) {
  109797. this.textureMatrix.set( 0.5, 0.0, 0.0, 0.5,
  109798. 0.0, 0.5, 0.0, 0.5,
  109799. 0.0, 0.0, 0.5, 0.5,
  109800. 0.0, 0.0, 0.0, 1.0 );
  109801. this.textureMatrix.multiply( camera.projectionMatrix );
  109802. this.textureMatrix.multiply( camera.matrixWorldInverse );
  109803. },
  109804. render: function (scenes, camera, viewports, renderer, writeBuffer, readBuffer, maskActive, renderFun ) {
  109805. if(!(scenes instanceof Array))scenes = [scenes];
  109806. if ( this.selectedObjects.length > 0 && this.edgeStrength > 0) {
  109807. let render2 = (target, dontRenderRtEDL=true)=>{
  109808. if(renderFun){
  109809. renderFun({target , dontRenderRtEDL });
  109810. }else {
  109811. renderer.setRenderTarget(target);
  109812. renderer.clear();
  109813. scenes.forEach(scene=>renderer.render( scene, camera));
  109814. }
  109815. };
  109816. this.oldClearColor.copy( renderer.getClearColor(new Color) );
  109817. this.oldClearAlpha = renderer.getClearAlpha();
  109818. let oldAutoClear = renderer.autoClear;
  109819. let oldTarget = renderer.getRenderTarget();
  109820. renderer.autoClear = false;
  109821. if ( maskActive ) renderer.context.disable( renderer.context.STENCIL_TEST );
  109822. renderer.setClearColor( 0xffffff, 1 );
  109823. let oldBG = viewer.background, oldBgOpacity = viewer.backgroundOpacity;
  109824. viewer.background = new Color(1,1,1);
  109825. viewer.backgroundOpacity = 1;
  109826. if(this.showHiddenPart){ //几乎不会使用
  109827. viewports.forEach(e=>{
  109828. e.oldBeforeRender = e.beforeRender;
  109829. e.beforeRender = ()=>{
  109830. e.oldBeforeRender && e.oldBeforeRender();
  109831. this.replaceDepthToViewZ( e.camera );
  109832. };
  109833. });
  109834. // Make selected objects invisible
  109835. this.changeVisibilityOfSelectedObjects( false );
  109836. scenes.forEach(scene=>{
  109837. scene.currentBackground = scene.background;
  109838. scene.background = null;
  109839. // 1. Draw Non Selected objects in the depth buffer
  109840. scene.overrideMaterial = this.depthMaterial;
  109841. });
  109842. render2(this.renderTargetDepthBuffer);
  109843. // Make selected objects visible
  109844. this.changeVisibilityOfSelectedObjects( true );
  109845. viewports.forEach(e=>{
  109846. e.beforeRender = ()=>{
  109847. e.oldBeforeRender && e.oldBeforeRender();
  109848. // Update Texture Matrix for Depth compare
  109849. this.updateTextureMatrix(e.camera);
  109850. this.prepareMaskMaterial.uniforms[ "cameraNearFar" ].value = new Vector2( e.camera.near, e.camera.far );
  109851. };
  109852. });
  109853. }else {
  109854. //不渲染背景
  109855. scenes.forEach(scene=>{
  109856. scene.currentBackground = scene.background;
  109857. scene.background = null;
  109858. });
  109859. }
  109860. let colorType, colors = new Map() , opas = new Map();
  109861. {//绘制选中部分
  109862. // Make non selected objects invisible, and draw only the selected objects, by comparing the depth buffer of non selected objects
  109863. this.changeVisibilityOfNonSelectedObjects( false , scenes);
  109864. scenes.forEach(scene=>{
  109865. scene.overrideMaterial = this.prepareMaskMaterial;
  109866. });
  109867. if(this.showHiddenPart){
  109868. this.prepareMaskMaterial.uniforms[ "depthTexture" ].value = this.renderTargetDepthBuffer.texture;
  109869. this.prepareMaskMaterial.uniforms[ "textureMatrix" ].value = this.textureMatrix;
  109870. }
  109871. //因为点云不受prepareMaskMaterial作用,所以手动将他们变为黑色不透明
  109872. viewer.scene.pointclouds.forEach(e=>{ //先将点云透明度变为1,因为点云透明度莫名其妙会影响其r值//
  109873. colorType = e.material.activeAttributeName;
  109874. e.material.activeAttributeName = 'color';
  109875. colors.set(e, e.material.color);
  109876. e.material.color = '#000000';
  109877. opas.set(e, e.material.opacity);
  109878. e.material.opacity = 1;
  109879. });
  109880. }
  109881. render2(this.renderTargetMaskBuffer);
  109882. {//恢复
  109883. viewer.scene.pointclouds.forEach(e=>{
  109884. e.material.activeAttributeName = colorType;
  109885. e.material.color = colors.get(e);
  109886. e.material.opacity = opas.get(e);
  109887. });
  109888. if(this.showHiddenPart){
  109889. viewports.forEach((e)=>{e.beforeRender = e.oldBeforeRender;});
  109890. }
  109891. scenes.forEach(scene=>{
  109892. scene.overrideMaterial = null;
  109893. scene.background = scene.currentBackground;
  109894. });
  109895. viewer.background = oldBG;
  109896. viewer.backgroundOpacity = oldBgOpacity;
  109897. this.changeVisibilityOfNonSelectedObjects( true , scenes);
  109898. }
  109899. //检测边缘并绘制
  109900. // 3. Apply Edge Detection Pass
  109901. this.quad.material = this.edgeDetectionMaterial;
  109902. this.edgeDetectionMaterial.uniforms[ "maskTexture" ].value = this.renderTargetMaskBuffer.texture;//this.renderTargetMaskDownSampleBuffer.texture;
  109903. this.edgeDetectionMaterial.uniforms[ "texSize" ].value = new Vector2(this.resolution.x, this.resolution.y );//new THREE.Vector2( this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height );
  109904. //this.edgeDetectionMaterial.uniforms[ "texSize" ].value = new THREE.Vector2(this.renderTargetMaskBuffer.width, this.renderTargetMaskBuffer.height)//new THREE.Vector2( this.renderTargetMaskDownSampleBuffer.width, this.renderTargetMaskDownSampleBuffer.height );
  109905. this.edgeDetectionMaterial.uniforms[ "edgeStrength" ].value = this.edgeStrength;
  109906. this.edgeDetectionMaterial.uniforms[ "visibleEdgeColor" ].value = this.visibleEdgeColor;//this.tempPulseColor1;
  109907. this.edgeDetectionMaterial.uniforms[ "hiddenEdgeColor" ].value = this.hiddenEdgeColor; //this.tempPulseColor2;
  109908. let buffer;
  109909. if ( this.renderToScreen ) {
  109910. this.quad.material.transparent = true;
  109911. buffer = null;
  109912. renderer.setClearColor( this.oldClearColor, this.oldClearAlpha );
  109913. render2(null,false); //普通绘制原场景
  109914. //绘制到全屏
  109915. let renderSize = renderer.getSize(new Vector2()); //是client大小
  109916. renderer.setViewport(0, 0, renderSize.x, renderSize.y); //规定视口,影响图形变换(画布的使用范围)
  109917. renderer.setScissorTest( false );
  109918. }else {
  109919. buffer = readBuffer;
  109920. renderer.setClearColor( 0x000000, 0 );
  109921. renderer.clear();
  109922. }
  109923. renderer.setRenderTarget( buffer );
  109924. renderer.render( this.scene, this.camera ); //将边缘覆盖上去
  109925. renderer.setRenderTarget(oldTarget);
  109926. renderer.setClearColor( this.oldClearColor, this.oldClearAlpha );
  109927. renderer.autoClear = oldAutoClear;
  109928. return true
  109929. }
  109930. },
  109931. getPrepareMaskMaterial: function () {
  109932. if(this.showHiddenPart){
  109933. return new ShaderMaterial( {
  109934. uniforms: {
  109935. "depthTexture": { value: null },
  109936. "cameraNearFar": { value: new Vector2( 0.5, 0.5 ) },
  109937. "textureMatrix": { value: new Matrix4() }
  109938. },
  109939. vertexShader: [
  109940. 'varying vec4 projTexCoord;',
  109941. 'varying vec4 vPosition;',
  109942. 'uniform mat4 textureMatrix;',
  109943. 'void main() {',
  109944. ' vPosition = modelViewMatrix * vec4( position, 1.0 );',
  109945. ' vec4 worldPosition = modelMatrix * vec4( position, 1.0 );',
  109946. ' projTexCoord = textureMatrix * worldPosition;',
  109947. ' gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  109948. '}'
  109949. ].join( '\n' ),
  109950. fragmentShader: [
  109951. '#include <packing>',
  109952. 'varying vec4 vPosition;',
  109953. 'varying vec4 projTexCoord;',
  109954. 'uniform sampler2D depthTexture;',
  109955. 'uniform vec2 cameraNearFar;',
  109956. 'void main() {',
  109957. ' float depth = unpackRGBAToDepth(texture2DProj( depthTexture, projTexCoord ));',
  109958. ' float viewZ = - DEPTH_TO_VIEW_Z( depth, cameraNearFar.x, cameraNearFar.y );',
  109959. ' float depthTest = (-vPosition.z > viewZ) ? 1.0 : 0.0;', //决定是否为hiddenPart
  109960. ' gl_FragColor = vec4(0.0, depthTest, 1.0, 1.0);',
  109961. '}'
  109962. ].join( '\n' )
  109963. } );//没有绘制部分的颜色是clearColor,255
  109964. }else {
  109965. return new MeshBasicMaterial({color:'#000000'}) //不检测深度,不判断遮挡
  109966. }
  109967. },
  109968. getEdgeDetectionMaterial: function (edgeStrength) {
  109969. return new ShaderMaterial( {
  109970. uniforms: {
  109971. "edgeStrength": { value: edgeStrength },
  109972. "maskTexture": { value: null },
  109973. "texSize": { value: new Vector2( 10, 10 ) },
  109974. "visibleEdgeColor": { value: new Vector3( 1.0, 1.0, 1.0 ) },
  109975. "hiddenEdgeColor": { value: new Vector3( 1.0, 1.0, 1.0 ) },
  109976. },
  109977. vertexShader:
  109978. "varying vec2 vUv;\n\
  109979. void main() {\n\
  109980. vUv = uv;\n\
  109981. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  109982. }",
  109983. /* fragmentShader:
  109984. "varying vec2 vUv;\
  109985. uniform sampler2D maskTexture;\
  109986. uniform vec2 texSize;\
  109987. uniform vec3 visibleEdgeColor;\
  109988. uniform vec3 hiddenEdgeColor;\
  109989. \
  109990. void main() {\n\
  109991. vec2 invSize = 1.0 / texSize;\
  109992. vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);\
  109993. vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);\
  109994. vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);\
  109995. vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);\
  109996. vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);\
  109997. float diff1 = (c1.r - c2.r)*0.5;\
  109998. float diff2 = (c3.r - c4.r)*0.5;\
  109999. float d = length( vec2(diff1, diff2) );\
  110000. float a1 = min(c1.g, c2.g);\
  110001. float a2 = min(c3.g, c4.g);\
  110002. float visibilityFactor = min(a1, a2);\
  110003. vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;\
  110004. gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);\
  110005. }" */
  110006. fragmentShader:
  110007. `varying vec2 vUv;
  110008. uniform sampler2D maskTexture;
  110009. uniform float edgeStrength;
  110010. uniform vec2 texSize;
  110011. uniform vec3 visibleEdgeColor;
  110012. uniform vec3 hiddenEdgeColor;
  110013. void main() {
  110014. const float thickness = 1.0;
  110015. vec2 invSize = thickness / texSize;
  110016. vec4 uvOffset = vec4(1.0, 0.0, 0.0, 1.0) * vec4(invSize, invSize);
  110017. vec4 c1 = texture2D( maskTexture, vUv + uvOffset.xy);
  110018. vec4 c2 = texture2D( maskTexture, vUv - uvOffset.xy);
  110019. vec4 c3 = texture2D( maskTexture, vUv + uvOffset.yw);
  110020. vec4 c4 = texture2D( maskTexture, vUv - uvOffset.yw);
  110021. float diff1 = (c1.r - c2.r)*0.5; //检测边缘,
  110022. float diff2 = (c3.r - c4.r)*0.5;
  110023. float d = length( vec2(diff1, diff2) ) * edgeStrength;
  110024. float a1 = min(c1.g, c2.g);
  110025. float a2 = min(c3.g, c4.g);
  110026. float visibilityFactor = min(a1, a2); //检测深度值,是否被遮挡
  110027. vec3 edgeColor = 1.0 - visibilityFactor > 0.001 ? visibleEdgeColor : hiddenEdgeColor;
  110028. //gl_FragColor = vec4(0.0,1.0,0.0,1.0);
  110029. gl_FragColor = vec4(edgeColor, 1.0) * vec4(d);
  110030. }`
  110031. } );
  110032. //为什么vec4(0.0,1.0,1.0,1.0); 显示出来的是rgb(109,255,255) ? 几乎只有绿色通道会影响红色通道
  110033. },
  110034. getSeperableBlurMaterial: function ( maxRadius ) {
  110035. return new ShaderMaterial( {
  110036. defines: {
  110037. "MAX_RADIUS": maxRadius,
  110038. },
  110039. uniforms: {
  110040. "colorTexture": { value: null },
  110041. "texSize": { value: new Vector2( 0.5, 0.5 ) },
  110042. "direction": { value: new Vector2( 0.5, 0.5 ) },
  110043. "kernelRadius": { value: 1.0 }
  110044. },
  110045. vertexShader:
  110046. "varying vec2 vUv;\n\
  110047. void main() {\n\
  110048. vUv = uv;\n\
  110049. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  110050. }",
  110051. fragmentShader:
  110052. "#include <common>\
  110053. varying vec2 vUv;\
  110054. uniform sampler2D colorTexture;\
  110055. uniform vec2 texSize;\
  110056. uniform vec2 direction;\
  110057. uniform float kernelRadius;\
  110058. \
  110059. float gaussianPdf(in float x, in float sigma) {\
  110060. return 0.39894 * exp( -0.5 * x * x/( sigma * sigma))/sigma;\
  110061. }\
  110062. void main() {\
  110063. vec2 invSize = 1.0 / texSize;\
  110064. float weightSum = gaussianPdf(0.0, kernelRadius);\
  110065. vec3 diffuseSum = texture2D( colorTexture, vUv).rgb * weightSum;\
  110066. vec2 delta = direction * invSize * kernelRadius/float(MAX_RADIUS);\
  110067. vec2 uvOffset = delta;\
  110068. for( int i = 1; i <= MAX_RADIUS; i ++ ) {\
  110069. float w = gaussianPdf(uvOffset.x, kernelRadius);\
  110070. vec3 sample1 = texture2D( colorTexture, vUv + uvOffset).rgb;\
  110071. vec3 sample2 = texture2D( colorTexture, vUv - uvOffset).rgb;\
  110072. diffuseSum += ((sample1 + sample2) * w);\
  110073. weightSum += (2.0 * w);\
  110074. uvOffset += delta;\
  110075. }\
  110076. gl_FragColor = vec4(diffuseSum/weightSum, 1.0);\
  110077. }"
  110078. } );
  110079. },
  110080. getOverlayMaterial: function () {//对边缘线进一步处理,已被废弃
  110081. return new ShaderMaterial( {
  110082. uniforms: {
  110083. "maskTexture": { value: null },
  110084. "edgeTexture1": { value: null },
  110085. "edgeTexture2": { value: null },
  110086. "patternTexture": { value: null },
  110087. "edgeStrength": { value: 1.0 },
  110088. "edgeGlow": { value: 1.0 },
  110089. "usePatternTexture": { value: 0.0 }
  110090. },
  110091. vertexShader:
  110092. "varying vec2 vUv;\n\
  110093. void main() {\n\
  110094. vUv = uv;\n\
  110095. gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n\
  110096. }",
  110097. /* fragmentShader:
  110098. "varying vec2 vUv;\
  110099. uniform sampler2D maskTexture;\
  110100. uniform sampler2D edgeTexture1;\
  110101. uniform sampler2D edgeTexture2;\
  110102. uniform sampler2D patternTexture;\
  110103. uniform float edgeStrength;\
  110104. uniform float edgeGlow;\
  110105. uniform bool usePatternTexture;\
  110106. \
  110107. void main() {\
  110108. vec4 edgeValue1 = texture2D(edgeTexture1, vUv);\
  110109. vec4 edgeValue2 = texture2D(edgeTexture2, vUv);\
  110110. vec4 maskColor = texture2D(maskTexture, vUv);\
  110111. vec4 patternColor = texture2D(patternTexture, 6.0 * vUv);\
  110112. float visibilityFactor = 1.0 - maskColor.g > 0.0 ? 1.0 : 0.5;\
  110113. vec4 edgeValue = edgeValue1 + edgeValue2 * edgeGlow;\
  110114. vec4 finalColor = edgeStrength * maskColor.r * edgeValue;\ // 删除 * maskColor.r 也就是去掉遮罩,使模型部分也有outline
  110115. if(usePatternTexture)\
  110116. finalColor += + visibilityFactor * (1.0 - maskColor.r) * (1.0 - patternColor.r);\
  110117. gl_FragColor = finalColor;\
  110118. }", */
  110119. fragmentShader:
  110120. `varying vec2 vUv;
  110121. uniform sampler2D edgeTexture1;
  110122. uniform float edgeStrength;
  110123. void main() {
  110124. gl_FragColor = edgeStrength * texture2D(edgeTexture1, vUv);
  110125. }`,
  110126. blending: AdditiveBlending,
  110127. depthTest: false,
  110128. depthWrite: false,
  110129. transparent: true
  110130. } );
  110131. }
  110132. } );
  110133. OutlinePass.BlurDirectionX = new Vector2( 1.0, 0.0 );
  110134. OutlinePass.BlurDirectionY = new Vector2( 0.0, 1.0 );
  110135. /*
  110136. 渲染步骤:(没有showHiddenPart时)
  110137. 仅绘制选中部分,材质为普通的单色材质,颜色是黑色不透明。未绘制部分的clearColor是白色不透明。
  110138. (详见prepareMaskMaterial,输出的r要为0)
  110139. 然后在上面绘制的图中,根据r的差值,得到边缘线。
  110140. 正常绘制场景之后,将上面的边缘线覆盖于其上。
  110141. (如果showHiddenPart,最开始还要先隐藏选中部分,这是为了得到非选中部分的深度值,然后再绘制选中部分时去比较选中和非选中部分之间的深度差异。以判断是否被遮挡。)
  110142. */
  110143. /**
  110144. * @author mschuetz / http://mschuetz.at
  110145. *
  110146. * adapted from THREE.OrbitControls by
  110147. *
  110148. * @author qiao / https://github.com/qiao
  110149. * @author mrdoob / http://mrdoob.com
  110150. * @author alteredq / http://alteredqualia.com/
  110151. * @author WestLangley / http://github.com/WestLangley
  110152. * @author erich666 / http://erichaines.com
  110153. *
  110154. *
  110155. *
  110156. */
  110157. let minRadius = 2;
  110158. class OrbitControls extends EventDispatcher{
  110159. constructor(viewer, viewport){
  110160. super();
  110161. this.viewer = viewer;
  110162. this.renderer = viewer.renderer;
  110163. this.scene = null;
  110164. this.sceneControls = new Scene();
  110165. this.rotationSpeed = 3; //旋转速度
  110166. viewport = viewport || viewer.viewports[0];
  110167. this.setCurrentViewport({hoverViewport:viewport, force:true}); //this.currentViewport = viewport
  110168. this.fadeFactor = 20;
  110169. this.yawDelta = 0;
  110170. this.pitchDelta = 0;
  110171. this.panDelta = new Vector2(0, 0);
  110172. this.radiusDelta = 0;
  110173. this.doubleClockZoomEnabled = true;
  110174. this.tweens = [];
  110175. this.dollyStart = new Vector2;
  110176. this.dollyEnd = new Vector2;
  110177. this.keys = {
  110178. FORWARD: ['W'.charCodeAt(0), 38],
  110179. BACKWARD: ['S'.charCodeAt(0), 40],
  110180. LEFT: ['A'.charCodeAt(0), 37],
  110181. RIGHT: ['D'.charCodeAt(0), 39],
  110182. UP: ['Q'.charCodeAt(0)],
  110183. DOWN: ['E'.charCodeAt(0)],
  110184. };
  110185. let drag = (e) => {
  110186. if(!this.enabled)return
  110187. let viewport = e.dragViewport;
  110188. if(!viewport /* || viewport.camera.type == "OrthographicCamera" */)return
  110189. //let camera = viewport.camera
  110190. if (e.drag.object !== null) {
  110191. return;
  110192. }
  110193. let mode;
  110194. if(e.isTouch){
  110195. if(e.touches.length == 1){
  110196. mode = 'rotate';
  110197. }else {
  110198. mode = 'scale-pan';
  110199. }
  110200. }else {
  110201. mode = e.buttons === Potree.defines.Buttons.LEFT ? 'rotate' : 'pan';
  110202. }
  110203. if (e.drag.startHandled === undefined) {
  110204. e.drag.startHandled = true;
  110205. this.dispatchEvent({type: 'start'});
  110206. }
  110207. let ndrag = e.drag.pointerDelta.clone();//.add(new THREE.Vector2(1,1)).multiplyScalar(0.5)
  110208. ndrag.y *= -1;
  110209. if (mode == 'rotate') {
  110210. this.yawDelta += ndrag.x * this.rotationSpeed;
  110211. this.pitchDelta += ndrag.y * this.rotationSpeed;
  110212. } else if(mode == 'pan'){
  110213. this.panDelta.x += ndrag.x;
  110214. this.panDelta.y += ndrag.y;
  110215. }else if(mode == 'scale-pan'){ //add
  110216. this.dollyEnd.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  110217. var scale = this.dollyEnd.length() / this.dollyStart.length();
  110218. this.dollyStart.copy(this.dollyEnd);
  110219. this.radiusDelta = (1-scale) * this.currentViewport.view.radius;
  110220. //------------------------
  110221. //平移
  110222. let pointer = new Vector2().addVectors(e.touches[0].pointer, e.touches[1].pointer).multiplyScalar(0.5);//两个指头的中心点
  110223. let delta = new Vector2().subVectors(pointer, this.lastScalePointer);
  110224. delta.y *= -1;
  110225. this.panDelta.add(delta);
  110226. this.lastScalePointer = pointer.clone();
  110227. //console.log('scale ',scale, this.radiusDelta)
  110228. }
  110229. this.stopTweens();
  110230. };
  110231. let drop = e => {
  110232. if(!this.enabled)return
  110233. this.dispatchEvent({type: 'end'});
  110234. };
  110235. let scroll = (e) => {
  110236. if(!this.enabled)return
  110237. let resolvedRadius = this.currentViewport.view.radius + this.radiusDelta;
  110238. if(resolvedRadius < 0.1 && e.delta>0)return; //防止缩放太小,导致很慢
  110239. this.radiusDelta += -e.delta * resolvedRadius * 0.1;
  110240. this.stopTweens();
  110241. };
  110242. let dblclick = (e) => {
  110243. if(!this.enabled)return
  110244. if(this.doubleClockZoomEnabled){
  110245. this.zoomToLocation(e.mouse);
  110246. }
  110247. };
  110248. let previousTouch = null;
  110249. let touchStart = e => {
  110250. previousTouch = e;
  110251. };
  110252. let touchEnd = e => {
  110253. previousTouch = e;
  110254. };
  110255. let touchMove = e => {
  110256. if(!this.enabled)return
  110257. if (e.touches.length === 2 && previousTouch.touches.length === 2){
  110258. let prev = previousTouch;
  110259. let curr = e;
  110260. let prevDX = prev.touches[0].pageX - prev.touches[1].pageX;
  110261. let prevDY = prev.touches[0].pageY - prev.touches[1].pageY;
  110262. let prevDist = Math.sqrt(prevDX * prevDX + prevDY * prevDY);
  110263. let currDX = curr.touches[0].pageX - curr.touches[1].pageX;
  110264. let currDY = curr.touches[0].pageY - curr.touches[1].pageY;
  110265. let currDist = Math.sqrt(currDX * currDX + currDY * currDY);
  110266. let delta = currDist / prevDist;
  110267. let resolvedRadius = this.currentViewport.view.radius + this.radiusDelta;
  110268. let newRadius = resolvedRadius / delta;
  110269. this.radiusDelta = newRadius - resolvedRadius;
  110270. this.stopTweens();
  110271. }else if(e.touches.length === 3 && previousTouch.touches.length === 3){
  110272. let prev = previousTouch;
  110273. let curr = e;
  110274. let prevMeanX = (prev.touches[0].pageX + prev.touches[1].pageX + prev.touches[2].pageX) / 3;
  110275. let prevMeanY = (prev.touches[0].pageY + prev.touches[1].pageY + prev.touches[2].pageY) / 3;
  110276. let currMeanX = (curr.touches[0].pageX + curr.touches[1].pageX + curr.touches[2].pageX) / 3;
  110277. let currMeanY = (curr.touches[0].pageY + curr.touches[1].pageY + curr.touches[2].pageY) / 3;
  110278. let delta = {
  110279. x: (currMeanX - prevMeanX) / this.renderer.domElement.clientWidth,
  110280. y: (currMeanY - prevMeanY) / this.renderer.domElement.clientHeight
  110281. };
  110282. this.panDelta.x += delta.x;
  110283. this.panDelta.y += delta.y;
  110284. this.stopTweens();
  110285. }
  110286. previousTouch = e;
  110287. };
  110288. this.addEventListener('touchstart', touchStart);
  110289. this.addEventListener('touchend', touchEnd);
  110290. this.addEventListener('touchmove', touchMove);
  110291. this.viewer.addEventListener('global_drag', drag);
  110292. this.viewer.addEventListener('global_drop', drop);
  110293. this.viewer.addEventListener('global_mousewheel', scroll);
  110294. this.viewer.addEventListener('global_dblclick', dblclick);
  110295. this.viewer.addEventListener('global_touchmove', (e)=>{
  110296. if(e.touches.length>1){//单指的就触发上一句
  110297. //console.log('global_touchmove' )
  110298. drag(e);
  110299. }
  110300. });
  110301. let prepareScale = (e)=>{//触屏的scale
  110302. this.dollyStart.subVectors(e.touches[0].pointer, e.touches[1].pointer);
  110303. this.lastScalePointer = new Vector2().addVectors(e.touches[0].pointer, e.touches[1].pointer).multiplyScalar(0.5);//两个指头的中心点
  110304. };
  110305. this.viewer.addEventListener('global_touchstart', (e)=>{
  110306. if(this.enabled && e.touches.length==2){//只监听开头两个指头
  110307. prepareScale(e);
  110308. }
  110309. });
  110310. /* this.viewer.addEventListener('global_touchend', (e)=>{
  110311. if(!this.enabled)return
  110312. if(e.touches.length==1){//停止scale,开始rotate
  110313. prepareRotate(e)
  110314. //this.pointerDragStart = null
  110315. //console.log('只剩一个', e.pointer.toArray())
  110316. }
  110317. }) */
  110318. this.viewer.addEventListener('focusOnObject',(o)=>{
  110319. if(o.position && o.CamTarget){
  110320. let distance = o.position.distanceTo(o.CamTarget);
  110321. if(distance < minRadius) minRadius = distance * 0.5; //融合页面当focus一个很小的物体时,需要将minRadius也调小
  110322. }
  110323. });
  110324. }
  110325. setScene (scene) {
  110326. this.scene = scene;
  110327. }
  110328. setCurrentViewport(o={}){//add
  110329. if(!this.enabled && !o.force )return
  110330. if(o.hoverViewport && this.currentViewport != o.hoverViewport ){
  110331. this.currentViewport = o.hoverViewport;
  110332. }
  110333. }
  110334. setEnable(enabled){
  110335. this.enabled = enabled;
  110336. }
  110337. stop(){
  110338. this.yawDelta = 0;
  110339. this.pitchDelta = 0;
  110340. this.radiusDelta = 0;
  110341. this.panDelta.set(0, 0);
  110342. }
  110343. /* zoomToLocation(mouse){
  110344. if(!this.enabled)return
  110345. let camera = this.scene.getActiveCamera();
  110346. let I = Utils.getMousePointCloudIntersection(
  110347. null, mouse, this.viewer.inputHandler.pointer,
  110348. camera,
  110349. this.viewer,
  110350. this.scene.pointclouds,
  110351. {pickClipped: true});
  110352. if (I === null) {
  110353. return;
  110354. }
  110355. let targetRadius = 0;
  110356. {
  110357. let minimumJumpDistance = 0.2;
  110358. let domElement = this.renderer.domElement;
  110359. let ray = Utils.mouseToRay(this.viewer.inputHandler.pointer , camera, domElement.clientWidth, domElement.clientHeight);
  110360. let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  110361. let lastNode = nodes[nodes.length - 1];
  110362. let radius = lastNode.getBoundingSphere(new THREE.Sphere()).radius;
  110363. targetRadius = Math.min(this.currentViewport.view.radius, radius);
  110364. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  110365. }
  110366. let d = this.currentViewport.view.direction.multiplyScalar(-1);
  110367. let cameraTargetPosition = new THREE.Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  110368. // TODO Unused: let controlsTargetPosition = I.location;
  110369. let animationDuration = 600;
  110370. let easing = TWEEN.Easing.Quartic.Out;
  110371. { // animate
  110372. let value = {x: 0};
  110373. let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
  110374. tween.easing(easing);
  110375. this.tweens.push(tween);
  110376. let startPos = this.currentViewport.view.position.clone();
  110377. let targetPos = cameraTargetPosition.clone();
  110378. let startRadius = this.currentViewport.view.radius;
  110379. let targetRadius = cameraTargetPosition.distanceTo(I.location);
  110380. tween.onUpdate(() => {
  110381. let t = value.x;
  110382. this.currentViewport.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  110383. this.currentViewport.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  110384. this.currentViewport.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  110385. this.currentViewport.view.radius = (1 - t) * startRadius + t * targetRadius;
  110386. this.viewer.setMoveSpeed(this.currentViewport.view.radius);
  110387. });
  110388. tween.onComplete(() => {
  110389. this.tweens = this.tweens.filter(e => e !== tween);
  110390. });
  110391. tween.start();
  110392. }
  110393. } */
  110394. zoomToLocation(mouse){
  110395. let I = viewer.inputHandler.intersect;
  110396. if(!I)return
  110397. let object = I.object || I.pointcloud;
  110398. I = I.location;
  110399. if(!I || !object)return;
  110400. let dis = this.currentViewport.view.position.distanceTo(I);
  110401. let bound = object.boundingBox.clone().applyMatrix4(object.matrixWorld);
  110402. let size = bound.getSize(new Vector3);
  110403. let len = size.length();
  110404. let distance = MathUtils.clamp(dis, 0.1, Math.max(len * 0.1, 3) );
  110405. minRadius = distance;
  110406. viewer.focusOnObject({ position:I }, 'point', null, {distance});
  110407. }
  110408. stopTweens () {
  110409. this.tweens.forEach(e => e.stop());
  110410. this.tweens = [];
  110411. }
  110412. update (delta) {
  110413. if(!this.enabled)return
  110414. let view = this.currentViewport.view;//this.currentViewport.view;
  110415. let camera = this.currentViewport.camera;
  110416. { // accelerate while input is given
  110417. let ih = this.viewer.inputHandler;
  110418. let moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
  110419. let moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
  110420. let moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
  110421. let moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
  110422. let moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
  110423. let moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
  110424. let moveSpeed = this.currentViewport.getMoveSpeed() / 20;
  110425. let px = 0 , py = 0, pz = 0;
  110426. if(moveForward){
  110427. py = 1 * moveSpeed;
  110428. }else if(moveBackward){
  110429. py = -1 * moveSpeed;
  110430. }
  110431. if(moveLeft){
  110432. px = -1 * moveSpeed;
  110433. }else if(moveRight){
  110434. px = 1 * moveSpeed;
  110435. }
  110436. if(moveUp){
  110437. pz = 1 * moveSpeed;
  110438. }else if(moveDown){
  110439. pz = -1 * moveSpeed;
  110440. }
  110441. (px!=0 || py!=0 || pz!=0) && view.translate(px, py, pz, true);
  110442. }
  110443. { // apply rotation
  110444. let progression = Math.min(1, this.fadeFactor * delta);
  110445. let yaw = view.yaw;
  110446. let pitch = view.pitch;
  110447. let pivot = view.getPivot();
  110448. yaw -= progression * this.yawDelta;
  110449. pitch -= progression * this.pitchDelta;
  110450. view.yaw = yaw;
  110451. view.pitch = pitch;
  110452. let V = this.currentViewport.view.direction.multiplyScalar(-view.radius);
  110453. let position = new Vector3().addVectors(pivot, V);
  110454. view.position.copy(position);
  110455. }
  110456. if(camera.type != 'OrthographicCamera'){ // apply pan
  110457. /* let progression = Math.min(1, this.fadeFactor * delta);
  110458. let panDistance = progression * view.radius * 3; */
  110459. let panDistance = 2 * view.radius * Math.tan(MathUtils.degToRad(camera.fov / 2));//参照4dkk。 平移target(也就是平移镜头位置),但还是难以保证跟手(navvis也不一定跟手,但是很奇怪在居中时中心点居然是跟手的,可能计算方式不同)
  110460. //计算了下确实是这么算的。 平移pivot。
  110461. let px = -this.panDelta.x * panDistance;
  110462. let py = this.panDelta.y * panDistance;
  110463. view.pan(px, py);
  110464. }
  110465. { // apply zoom
  110466. let progression = 1;//Math.min(1, this.fadeFactor * delta);
  110467. // let radius = view.radius + progression * this.radiusDelta * view.radius * 0.1;
  110468. let radius = view.radius + progression * this.radiusDelta;
  110469. let V = view.direction.multiplyScalar(-radius);
  110470. let position = new Vector3().addVectors(view.getPivot(), V);
  110471. if(this.constantlyForward) {// 到达中心点后还能继续向前移动,也就是能推进中心点
  110472. if(radius < minRadius){
  110473. radius = minRadius;
  110474. }
  110475. }
  110476. view.radius = radius;
  110477. view.position.copy(position);
  110478. }
  110479. {
  110480. let speed = view.radius;
  110481. this.viewer.setMoveSpeed && this.viewer.setMoveSpeed(speed);
  110482. }
  110483. { // decelerate over time
  110484. /* let progression = Math.min(1, this.fadeFactor * delta);
  110485. let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  110486. this.yawDelta *= attenuation;
  110487. this.pitchDelta *= attenuation;
  110488. this.panDelta.multiplyScalar(attenuation);
  110489. // this.radiusDelta *= attenuation;
  110490. this.radiusDelta -= progression * this.radiusDelta; */
  110491. //取消衰减,直接stop
  110492. this.stop();
  110493. }
  110494. }
  110495. };
  110496. // Adapted from three.js VRButton
  110497. class VRButton {
  110498. constructor(){
  110499. this.onStartListeners = [];
  110500. this.onEndListeners = [];
  110501. this.element = null;
  110502. }
  110503. onStart(callback){
  110504. this.onStartListeners.push(callback);
  110505. }
  110506. onEnd(callback){
  110507. this.onEndListeners.push(callback);
  110508. }
  110509. static async createButton( renderer, options ) {
  110510. if ( options ) {
  110511. console.error( 'THREE.VRButton: The "options" parameter has been removed. Please set the reference space type via renderer.xr.setReferenceSpaceType() instead.' );
  110512. }
  110513. const button = new VRButton();
  110514. const element = document.createElement( 'button' );
  110515. button.element = element;
  110516. function setEnter(){
  110517. button.element.innerHTML = `
  110518. <div style="font-size: 0.5em;">ENTER</div>
  110519. <div style="font-weight: bold;">VR</div>
  110520. `;
  110521. }
  110522. function setExit(){
  110523. button.element.innerHTML = `
  110524. <div style="font-size: 0.5em;">EXIT</div>
  110525. <div style="font-weight: bold;">VR</div>
  110526. `;
  110527. }
  110528. function showEnterVR( /*device*/ ) {
  110529. let currentSession = null;
  110530. function onSessionStarted( session ) {
  110531. session.addEventListener( 'end', onSessionEnded );
  110532. for(let listener of button.onStartListeners){
  110533. listener();
  110534. }
  110535. renderer.xr.setSession( session );
  110536. setExit();
  110537. currentSession = session;
  110538. }
  110539. function onSessionEnded( /*event*/ ) {
  110540. currentSession.removeEventListener( 'end', onSessionEnded );
  110541. for(let listener of button.onEndListeners){
  110542. listener();
  110543. }
  110544. setEnter();
  110545. currentSession = null;
  110546. }
  110547. //
  110548. button.element.style.display = '';
  110549. button.element.style.cursor = 'pointer';
  110550. setEnter();
  110551. button.element.onmouseenter = function () {
  110552. button.element.style.opacity = '1.0';
  110553. };
  110554. button.element.onmouseleave = function () {
  110555. button.element.style.opacity = '0.7';
  110556. };
  110557. button.element.onclick = function () {
  110558. if ( currentSession === null ) {
  110559. // WebXR's requestReferenceSpace only works if the corresponding feature
  110560. // was requested at session creation time. For simplicity, just ask for
  110561. // the interesting ones as optional features, but be aware that the
  110562. // requestReferenceSpace call will fail if it turns out to be unavailable.
  110563. // ('local' is always available for immersive sessions and doesn't need to
  110564. // be requested separately.)
  110565. const sessionInit = { optionalFeatures: [ 'local-floor', 'bounded-floor', 'hand-tracking' ] };
  110566. navigator.xr.requestSession( 'immersive-vr', sessionInit ).then( onSessionStarted );
  110567. } else {
  110568. currentSession.end();
  110569. }
  110570. };
  110571. }
  110572. function stylizeElement( element ) {
  110573. element.style.position = 'absolute';
  110574. element.style.bottom = '20px';
  110575. element.style.padding = '12px 6px';
  110576. element.style.border = '1px solid #fff';
  110577. element.style.borderRadius = '4px';
  110578. element.style.background = 'rgba(0,0,0,0.1)';
  110579. element.style.color = '#fff';
  110580. element.style.font = 'normal 13px sans-serif';
  110581. element.style.textAlign = 'center';
  110582. element.style.opacity = '0.7';
  110583. element.style.outline = 'none';
  110584. element.style.zIndex = '999';
  110585. }
  110586. if ( 'xr' in navigator ) {
  110587. button.element.id = 'VRButton';
  110588. button.element.style.display = 'none';
  110589. stylizeElement( button.element );
  110590. let supported = await navigator.xr.isSessionSupported( 'immersive-vr' );
  110591. if(supported){
  110592. showEnterVR();
  110593. return button;
  110594. }else {
  110595. return null;
  110596. }
  110597. } else {
  110598. if ( window.isSecureContext === false ) {
  110599. console.log("WEBXR NEEDS HTTPS");
  110600. } else {
  110601. console.log("WEBXR not available");
  110602. }
  110603. return null;
  110604. }
  110605. }
  110606. }
  110607. !function(e, a) {
  110608. "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();
  110609. }("undefined" != typeof self ? self : undefined, function() {
  110610. return function(e) {
  110611. var a = {};
  110612. function t(r) {
  110613. if (a[r])
  110614. return a[r].exports;
  110615. var n = a[r] = {
  110616. i: r,
  110617. l: !1,
  110618. exports: {}
  110619. };
  110620. return e[r].call(n.exports, n, n.exports, t),
  110621. n.l = !0,
  110622. n.exports
  110623. }
  110624. return t.m = e,
  110625. t.c = a,
  110626. t.d = function(e, a, r) {
  110627. t.o(e, a) || Object.defineProperty(e, a, {
  110628. enumerable: !0,
  110629. get: r
  110630. });
  110631. }
  110632. ,
  110633. t.r = function(e) {
  110634. "undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
  110635. value: "Module"
  110636. }),
  110637. Object.defineProperty(e, "__esModule", {
  110638. value: !0
  110639. });
  110640. }
  110641. ,
  110642. t.t = function(e, a) {
  110643. if (1 & a && (e = t(e)),
  110644. 8 & a)
  110645. return e;
  110646. if (4 & a && "object" == typeof e && e && e.__esModule)
  110647. return e;
  110648. var r = Object.create(null);
  110649. if (t.r(r),
  110650. Object.defineProperty(r, "default", {
  110651. enumerable: !0,
  110652. value: e
  110653. }),
  110654. 2 & a && "string" != typeof e)
  110655. for (var n in e)
  110656. t.d(r, n, function(a) {
  110657. return e[a]
  110658. }
  110659. .bind(null, n));
  110660. return r
  110661. }
  110662. ,
  110663. t.n = function(e) {
  110664. var a = e && e.__esModule ? function() {
  110665. return e.default
  110666. }
  110667. : function() {
  110668. return e
  110669. }
  110670. ;
  110671. return t.d(a, "a", a),
  110672. a
  110673. }
  110674. ,
  110675. t.o = function(e, a) {
  110676. return Object.prototype.hasOwnProperty.call(e, a)
  110677. }
  110678. ,
  110679. t.p = "",
  110680. t(t.s = 1)
  110681. }([function(e, a, t) {
  110682. var r, n;
  110683. !function(o, c) {
  110684. "use strict";
  110685. void 0 === (n = "function" == typeof (r = function() {
  110686. var e = function() {}
  110687. , a = "undefined"
  110688. , t = ["trace", "debug", "info", "warn", "error"];
  110689. function r(e, a) {
  110690. var t = e[a];
  110691. if ("function" == typeof t.bind)
  110692. return t.bind(e);
  110693. try {
  110694. return Function.prototype.bind.call(t, e)
  110695. } catch (a) {
  110696. return function() {
  110697. return Function.prototype.apply.apply(t, [e, arguments])
  110698. }
  110699. }
  110700. }
  110701. function n(a, r) {
  110702. for (var n = 0; n < t.length; n++) {
  110703. var o = t[n];
  110704. this[o] = n < a ? e : this.methodFactory(o, a, r);
  110705. }
  110706. this.log = this.debug;
  110707. }
  110708. function o(t, o, c) {
  110709. return function(t) {
  110710. "debug" === t && (t = "log");
  110711. return typeof console !== a && (void 0 !== console[t] ? r(console, t) : void 0 !== console.log ? r(console, "log") : e)
  110712. }(t) || function(e, t, r) {
  110713. return function() {
  110714. typeof console !== a && (n.call(this, t, r),
  110715. this[e].apply(this, arguments));
  110716. }
  110717. }
  110718. .apply(this, arguments)
  110719. }
  110720. function c(e, r, c) {
  110721. var i, u = this, s = "loglevel";
  110722. function l() {
  110723. var e;
  110724. if (typeof window !== a) {
  110725. try {
  110726. e = window.localStorage[s];
  110727. } catch (e) {}
  110728. if (typeof e === a)
  110729. try {
  110730. var t = window.document.cookie
  110731. , r = t.indexOf(encodeURIComponent(s) + "=");
  110732. -1 !== r && (e = /^([^;]+)/.exec(t.slice(r))[1]);
  110733. } catch (e) {}
  110734. return void 0 === u.levels[e] && (e = void 0),
  110735. e
  110736. }
  110737. }
  110738. e && (s += ":" + e),
  110739. u.name = e,
  110740. u.levels = {
  110741. TRACE: 0,
  110742. DEBUG: 1,
  110743. INFO: 2,
  110744. WARN: 3,
  110745. ERROR: 4,
  110746. SILENT: 5
  110747. },
  110748. u.methodFactory = c || o,
  110749. u.getLevel = function() {
  110750. return i
  110751. }
  110752. ,
  110753. u.setLevel = function(r, o) {
  110754. if ("string" == typeof r && void 0 !== u.levels[r.toUpperCase()] && (r = u.levels[r.toUpperCase()]),
  110755. !("number" == typeof r && r >= 0 && r <= u.levels.SILENT))
  110756. throw "log.setLevel() called with invalid level: " + r;
  110757. if (i = r,
  110758. !1 !== o && function(e) {
  110759. var r = (t[e] || "silent").toUpperCase();
  110760. if (typeof window === a)
  110761. return;
  110762. try {
  110763. return void (window.localStorage[s] = r)
  110764. } catch (e) {}
  110765. try {
  110766. window.document.cookie = encodeURIComponent(s) + "=" + r + ";";
  110767. } catch (e) {}
  110768. }(r),
  110769. n.call(u, r, e),
  110770. typeof console === a && r < u.levels.SILENT)
  110771. return "No console available for logging"
  110772. }
  110773. ,
  110774. u.setDefaultLevel = function(e) {
  110775. l() || u.setLevel(e, !1);
  110776. }
  110777. ,
  110778. u.enableAll = function(e) {
  110779. u.setLevel(u.levels.TRACE, e);
  110780. }
  110781. ,
  110782. u.disableAll = function(e) {
  110783. u.setLevel(u.levels.SILENT, e);
  110784. }
  110785. ;
  110786. var v = l();
  110787. null == v && (v = null == r ? "WARN" : r),
  110788. u.setLevel(v, !1);
  110789. }
  110790. var i = new c
  110791. , u = {};
  110792. i.getLogger = function(e) {
  110793. if ("string" != typeof e || "" === e)
  110794. throw new TypeError("You must supply a name when creating a logger.");
  110795. var a = u[e];
  110796. return a || (a = u[e] = new c(e,i.getLevel(),i.methodFactory)),
  110797. a
  110798. }
  110799. ;
  110800. var s = typeof window !== a ? window.log : void 0;
  110801. return i.noConflict = function() {
  110802. return typeof window !== a && window.log === i && (window.log = s),
  110803. i
  110804. }
  110805. ,
  110806. i.getLoggers = function() {
  110807. return u
  110808. }
  110809. ,
  110810. i
  110811. }
  110812. ) ? r.call(a, t, a, e) : r) || (e.exports = n);
  110813. }();
  110814. }
  110815. , function(e, a, t) {
  110816. "use strict";
  110817. function r(e) {
  110818. this._pointer = 0,
  110819. this._data = e,
  110820. this._eof = !1;
  110821. }
  110822. function n(e, a) {
  110823. 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) {
  110824. if ("0" === e)
  110825. return !1;
  110826. if ("1" === e)
  110827. return !0;
  110828. throw TypeError("String '" + e + "' cannot be cast to Boolean type")
  110829. }(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", {
  110830. code: e,
  110831. value: a
  110832. }),
  110833. a)
  110834. }
  110835. t.r(a),
  110836. r.prototype.next = function() {
  110837. var e;
  110838. if (!this.hasNext())
  110839. 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]);
  110840. return e = {
  110841. code: parseInt(this._data[this._pointer])
  110842. },
  110843. this._pointer++,
  110844. e.value = n(e.code, this._data[this._pointer].trim()),
  110845. this._pointer++,
  110846. 0 === e.code && "EOF" === e.value && (this._eof = !0),
  110847. this.lastReadGroup = e,
  110848. e
  110849. }
  110850. ,
  110851. r.prototype.peek = function() {
  110852. if (!this.hasNext())
  110853. 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]);
  110854. var e = {
  110855. code: parseInt(this._data[this._pointer])
  110856. };
  110857. return e.value = n(e.code, this._data[this._pointer + 1].trim()),
  110858. e
  110859. }
  110860. ,
  110861. r.prototype.rewind = function(e) {
  110862. e = e || 1,
  110863. this._pointer = this._pointer - 2 * e;
  110864. }
  110865. ,
  110866. r.prototype.hasNext = function() {
  110867. return !this._eof && !(this._pointer > this._data.length - 2)
  110868. }
  110869. ,
  110870. r.prototype.isEOF = function() {
  110871. return this._eof
  110872. }
  110873. ;
  110874. 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];
  110875. function c(e) {
  110876. var a = {};
  110877. e.rewind();
  110878. var t = e.next()
  110879. , r = t.code;
  110880. if (a.x = t.value,
  110881. r += 10,
  110882. (t = e.next()).code != r)
  110883. throw new Error("Expected code for point value to be " + r + " but got " + t.code + ".");
  110884. return a.y = t.value,
  110885. r += 10,
  110886. (t = e.next()).code != r ? (e.rewind(),
  110887. a) : (a.z = t.value,
  110888. a)
  110889. }
  110890. function i(e, a) {
  110891. switch (a.code) {
  110892. case 0:
  110893. e.type = a.value;
  110894. break;
  110895. case 5:
  110896. e.handle = a.value;
  110897. /* if(e.handle == "2FDDB"){
  110898. console.log(1)
  110899. } */
  110900. break;
  110901. case 6:
  110902. e.lineType = a.value;
  110903. break;
  110904. case 8:
  110905. e.layer = a.value;
  110906. break;
  110907. case 48:
  110908. e.lineTypeScale = a.value;
  110909. break;
  110910. case 60:
  110911. e.visible = 0 === a.value;
  110912. break;
  110913. case 62:
  110914. e.colorIndex = a.value,
  110915. e.color = (t = Math.abs(a.value),
  110916. o[t]);
  110917. break;
  110918. case 67:
  110919. e.inPaperSpace = 0 !== a.value;
  110920. break;
  110921. case 100:
  110922. break;
  110923. case 330:
  110924. e.ownerHandle = a.value;
  110925. break;
  110926. case 347:
  110927. e.materialObjectHandle = a.value;
  110928. break;
  110929. case 370:
  110930. e.lineweight = a.value;
  110931. break;
  110932. case 420:
  110933. e.color = a.value;
  110934. break;
  110935. case 1e3:
  110936. e.extendedData = e.extendedData || {},
  110937. e.extendedData.customStrings = e.extendedData.customStrings || [],
  110938. e.extendedData.customStrings.push(a.value);
  110939. break;
  110940. case 1001:
  110941. e.extendedData = e.extendedData || {},
  110942. e.extendedData.applicationName = a.value;
  110943. break;
  110944. default:
  110945. return !1
  110946. }
  110947. var t;
  110948. return !0
  110949. }
  110950. function u() {}
  110951. function s(e, a) {
  110952. var t, r = [], n = !1, o = !1;
  110953. for (t = 0; t <= 4; t++) {
  110954. for (var c = {}; "EOF" !== a && 0 !== a.code && !o; ) {
  110955. switch (a.code) {
  110956. case 10:
  110957. case 11:
  110958. case 12:
  110959. case 13:
  110960. if (n) {
  110961. o = !0;
  110962. continue
  110963. }
  110964. c.x = a.value,
  110965. n = !0;
  110966. break;
  110967. case 20:
  110968. case 21:
  110969. case 22:
  110970. case 23:
  110971. c.y = a.value;
  110972. break;
  110973. case 30:
  110974. case 31:
  110975. case 32:
  110976. case 33:
  110977. c.z = a.value;
  110978. break;
  110979. default:
  110980. return r
  110981. }
  110982. a = e.next();
  110983. }
  110984. r.push(c),
  110985. n = !1,
  110986. o = !1;
  110987. }
  110988. return e.rewind(),
  110989. r
  110990. }
  110991. function l() {}
  110992. function v() {}
  110993. function d() {}
  110994. function b() {}
  110995. function p() {}
  110996. function f() {}
  110997. function k() {}
  110998. function y() {}
  110999. function x(e, a) {
  111000. if (!e || e <= 0)
  111001. throw Error("n must be greater than 0 verticies");
  111002. var t, r = [], n = !1, o = !1, c = a.lastReadGroup;
  111003. for (t = 0; t < e; t++) {
  111004. for (var i = {}; "EOF" !== c && 0 !== c.code && !o; ) {
  111005. switch (c.code) {
  111006. case 10:
  111007. if (n) {
  111008. o = !0;
  111009. continue
  111010. }
  111011. i.x = c.value,
  111012. n = !0;
  111013. break;
  111014. case 20:
  111015. i.y = c.value;
  111016. break;
  111017. case 30:
  111018. i.z = c.value;
  111019. break;
  111020. case 40:
  111021. i.startWidth = c.value;
  111022. break;
  111023. case 41:
  111024. i.endWidth = c.value;
  111025. break;
  111026. case 42:
  111027. 0 != c.value && (i.bulge = c.value);
  111028. break;
  111029. default:
  111030. return n && r.push(i),
  111031. r
  111032. }
  111033. c = a.next();
  111034. }
  111035. r.push(i),
  111036. n = !1,
  111037. o = !1;
  111038. }
  111039. return a.rewind(),
  111040. r
  111041. }
  111042. function h() {}
  111043. function g() {}
  111044. function E() {}
  111045. function w() {}
  111046. function m(e, a) {
  111047. var t = {
  111048. type: a.value
  111049. };
  111050. for (a = e.next(); "EOF" != a && 0 != a.code; )
  111051. i(t, a),
  111052. a = e.next();
  111053. return t
  111054. }
  111055. function P() {}
  111056. function F() {}
  111057. function O() {}
  111058. u.ForEntityName = "3DFACE",
  111059. u.prototype.parseEntity = function(e, a) {
  111060. var t = {
  111061. type: a.value,
  111062. vertices: []
  111063. };
  111064. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111065. switch (a.code) {
  111066. case 70:
  111067. t.shape = 1 == (1 & a.value),
  111068. t.hasContinuousLinetypePattern = 128 == (128 & a.value);
  111069. break;
  111070. case 10:
  111071. t.vertices = s(e, a),
  111072. a = e.lastReadGroup;
  111073. break;
  111074. default:
  111075. i(t, a);
  111076. }
  111077. a = e.next();
  111078. }
  111079. return t
  111080. }
  111081. ,
  111082. l.ForEntityName = "ARC",
  111083. l.prototype.parseEntity = function(e, a) {
  111084. var t;
  111085. for (t = {
  111086. type: a.value
  111087. },
  111088. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111089. switch (a.code) {
  111090. case 10:
  111091. t.center = c(e);
  111092. break;
  111093. case 40:
  111094. t.radius = a.value;
  111095. break;
  111096. case 50:
  111097. t.startAngle = Math.PI / 180 * a.value;
  111098. break;
  111099. case 51:
  111100. t.endAngle = Math.PI / 180 * a.value,
  111101. t.angleLength = t.endAngle - t.startAngle;
  111102. break;
  111103. default:
  111104. i(t, a);
  111105. }
  111106. a = e.next();
  111107. }
  111108. return t
  111109. }
  111110. ,
  111111. v.ForEntityName = "ATTDEF",
  111112. v.prototype.parseEntity = function(e, a) {
  111113. var t = {
  111114. type: a.value,
  111115. scale: 1,
  111116. textStyle: "STANDARD"
  111117. };
  111118. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111119. switch (a.code) {
  111120. case 1:
  111121. t.text = a.value;
  111122. break;
  111123. case 2:
  111124. t.tag = a.value;
  111125. break;
  111126. case 3:
  111127. t.prompt = a.value;
  111128. break;
  111129. case 7:
  111130. t.textStyle = a.value;
  111131. break;
  111132. case 10:
  111133. t.startPoint = c(e);
  111134. break;
  111135. case 11:
  111136. t.endPoint = c(e);
  111137. break;
  111138. case 39:
  111139. t.thickness = a.value;
  111140. break;
  111141. case 40:
  111142. t.textHeight = a.value;
  111143. break;
  111144. case 41:
  111145. t.scale = a.value;
  111146. break;
  111147. case 50:
  111148. t.rotation = a.value;
  111149. break;
  111150. case 51:
  111151. t.obliqueAngle = a.value;
  111152. break;
  111153. case 70:
  111154. t.invisible = !!(1 & a.value),
  111155. t.constant = !!(2 & a.value),
  111156. t.verificationRequired = !!(4 & a.value),
  111157. t.preset = !!(8 & a.value);
  111158. break;
  111159. case 71:
  111160. t.backwards = !!(2 & a.value),
  111161. t.mirrored = !!(4 & a.value);
  111162. break;
  111163. case 72:
  111164. t.horizontalJustification = a.value;
  111165. break;
  111166. case 73:
  111167. t.fieldLength = a.value;
  111168. break;
  111169. case 74:
  111170. t.verticalJustification = a.value;
  111171. break;
  111172. case 100:
  111173. break;
  111174. case 210:
  111175. t.extrusionDirectionX = a.value;
  111176. break;
  111177. case 220:
  111178. t.extrusionDirectionY = a.value;
  111179. break;
  111180. case 230:
  111181. t.extrusionDirectionZ = a.value;
  111182. break;
  111183. default:
  111184. i(t, a);
  111185. }
  111186. a = e.next();
  111187. }
  111188. return t
  111189. }
  111190. ,
  111191. d.ForEntityName = "CIRCLE",
  111192. d.prototype.parseEntity = function(e, a) {
  111193. var t, r;
  111194. for (t = {
  111195. type: a.value
  111196. },
  111197. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111198. switch (a.code) {
  111199. case 10:
  111200. t.center = c(e);
  111201. break;
  111202. case 40:
  111203. t.radius = a.value;
  111204. break;
  111205. case 50:
  111206. t.startAngle = Math.PI / 180 * a.value;
  111207. break;
  111208. case 51:
  111209. (r = Math.PI / 180 * a.value) < t.startAngle ? t.angleLength = r + 2 * Math.PI - t.startAngle : t.angleLength = r - t.startAngle,
  111210. t.endAngle = r;
  111211. break;
  111212. default:
  111213. i(t, a);
  111214. }
  111215. a = e.next();
  111216. }
  111217. return t
  111218. }
  111219. ,
  111220. b.ForEntityName = "DIMENSION",
  111221. b.prototype.parseEntity = function(e, a) {
  111222. var t;
  111223. for (t = {
  111224. type: a.value
  111225. },
  111226. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111227. switch (a.code) {
  111228. case 2:
  111229. t.block = a.value;
  111230. break;
  111231. case 10:
  111232. t.anchorPoint = c(e);
  111233. break;
  111234. case 11:
  111235. t.middleOfText = c(e);
  111236. break;
  111237. case 12:
  111238. t.insertionPoint = c(e);
  111239. break;
  111240. case 13:
  111241. t.linearOrAngularPoint1 = c(e);
  111242. break;
  111243. case 14:
  111244. t.linearOrAngularPoint2 = c(e);
  111245. break;
  111246. case 15:
  111247. t.diameterOrRadiusPoint = c(e);
  111248. break;
  111249. case 16:
  111250. t.arcPoint = c(e);
  111251. break;
  111252. case 70:
  111253. t.dimensionType = a.value;
  111254. break;
  111255. case 71:
  111256. t.attachmentPoint = a.value;
  111257. break;
  111258. case 42:
  111259. t.actualMeasurement = a.value;
  111260. break;
  111261. case 1:
  111262. t.text = a.value;
  111263. break;
  111264. case 50:
  111265. t.angle = a.value;
  111266. break;
  111267. default:
  111268. i(t, a);
  111269. }
  111270. a = e.next();
  111271. }
  111272. return t
  111273. }
  111274. ,
  111275. p.ForEntityName = "ELLIPSE",
  111276. p.prototype.parseEntity = function(e, a) {
  111277. var t;
  111278. for (t = {
  111279. type: a.value
  111280. },
  111281. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111282. switch (a.code) {
  111283. case 10:
  111284. t.center = c(e);
  111285. break;
  111286. case 11:
  111287. t.majorAxisEndPoint = c(e);
  111288. break;
  111289. case 40:
  111290. t.axisRatio = a.value;
  111291. break;
  111292. case 41:
  111293. t.startAngle = a.value;
  111294. break;
  111295. case 42:
  111296. t.endAngle = a.value;
  111297. break;
  111298. case 2:
  111299. t.name = a.value;
  111300. break;
  111301. default:
  111302. i(t, a);
  111303. }
  111304. a = e.next();
  111305. }
  111306. return t
  111307. }
  111308. ,
  111309. f.ForEntityName = "INSERT",
  111310. f.prototype.parseEntity = function(e, a) {
  111311. var t;
  111312. for (t = {
  111313. type: a.value
  111314. },
  111315. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111316. switch (a.code) {
  111317. case 2:
  111318. t.name = a.value;
  111319. break;
  111320. case 41:
  111321. t.xScale = a.value;
  111322. break;
  111323. case 42:
  111324. t.yScale = a.value;
  111325. break;
  111326. case 43:
  111327. t.zScale = a.value;
  111328. break;
  111329. case 10:
  111330. t.position = c(e);
  111331. break;
  111332. case 50:
  111333. t.rotation = a.value;
  111334. break;
  111335. case 70:
  111336. t.columnCount = a.value;
  111337. break;
  111338. case 71:
  111339. t.rowCount = a.value;
  111340. break;
  111341. case 44:
  111342. t.columnSpacing = a.value;
  111343. break;
  111344. case 45:
  111345. t.rowSpacing = a.value;
  111346. break;
  111347. case 210:
  111348. t.extrusionDirection = c(e);
  111349. break;
  111350. default:
  111351. i(t, a);
  111352. }
  111353. a = e.next();
  111354. }
  111355. return t
  111356. }
  111357. ,
  111358. k.ForEntityName = "LINE",
  111359. k.prototype.parseEntity = function(e, a) {
  111360. var t = {
  111361. type: a.value,
  111362. vertices: []
  111363. };
  111364. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111365. switch (a.code) {
  111366. case 10:
  111367. t.vertices.unshift(c(e));
  111368. break;
  111369. case 11:
  111370. t.vertices.push(c(e));
  111371. break;
  111372. case 210:
  111373. t.extrusionDirection = c(e);
  111374. break;
  111375. case 100:
  111376. break;
  111377. default:
  111378. i(t, a);
  111379. }
  111380. a = e.next();
  111381. }
  111382. return t
  111383. }
  111384. ,
  111385. y.ForEntityName = "LWPOLYLINE",
  111386. y.prototype.parseEntity = function(e, a) {
  111387. var t = {
  111388. type: a.value,
  111389. vertices: []
  111390. }
  111391. , r = 0;
  111392. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111393. switch (a.code) {
  111394. case 38:
  111395. t.elevation = a.value;
  111396. break;
  111397. case 39:
  111398. t.depth = a.value;
  111399. break;
  111400. case 70:
  111401. t.shape = 1 == (1 & a.value),
  111402. t.hasContinuousLinetypePattern = 128 == (128 & a.value);
  111403. break;
  111404. case 90:
  111405. r = a.value;
  111406. break;
  111407. case 10:
  111408. //t.vertices = x(r, e);
  111409. //改,因有的文件有点问题,可能版本原因
  111410. t.vertices.push(...x(r, e));//有的文件同一个entity需要多次执行到这里,所以不能直接覆盖,要push
  111411. t.vertices = t.vertices.filter(e=>e.x!=void 0);//而且会出现空的vertix:{},所以排除下
  111412. break;
  111413. case 43:
  111414. 0 !== a.value && (t.width = a.value);
  111415. break;
  111416. case 210:
  111417. t.extrusionDirectionX = a.value;
  111418. break;
  111419. case 220:
  111420. t.extrusionDirectionY = a.value;
  111421. break;
  111422. case 230:
  111423. t.extrusionDirectionZ = a.value;
  111424. break;
  111425. default:
  111426. i(t, a);
  111427. }
  111428. a = e.next();
  111429. }
  111430. return t
  111431. }
  111432. ,
  111433. h.ForEntityName = "MTEXT",
  111434. h.prototype.parseEntity = function(e, a) {
  111435. var t = {
  111436. type: a.value
  111437. };
  111438. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111439. switch (a.code) {
  111440. case 3:
  111441. case 1:
  111442. t.text ? t.text += a.value : t.text = a.value;
  111443. break;
  111444. case 10:
  111445. t.position = c(e);
  111446. break;
  111447. case 40:
  111448. t.height = a.value;
  111449. break;
  111450. case 41:
  111451. t.width = a.value;
  111452. break;
  111453. case 50:
  111454. t.rotation = a.value;
  111455. break;
  111456. case 71:
  111457. t.attachmentPoint = a.value;
  111458. break;
  111459. case 72:
  111460. t.drawingDirection = a.value;
  111461. break;
  111462. default:
  111463. i(t, a);
  111464. }
  111465. a = e.next();
  111466. }
  111467. return t
  111468. }
  111469. ,
  111470. g.ForEntityName = "POINT",
  111471. g.prototype.parseEntity = function(e, a) {
  111472. var t;
  111473. for (t = {
  111474. type: a.value
  111475. },
  111476. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111477. switch (a.code) {
  111478. case 10:
  111479. t.position = c(e);
  111480. break;
  111481. case 39:
  111482. t.thickness = a.value;
  111483. break;
  111484. case 210:
  111485. t.extrusionDirection = c(e);
  111486. break;
  111487. case 100:
  111488. break;
  111489. default:
  111490. i(t, a);
  111491. }
  111492. a = e.next();
  111493. }
  111494. return t
  111495. }
  111496. ,
  111497. E.ForEntityName = "VERTEX",
  111498. E.prototype.parseEntity = function(e, a) {
  111499. var t = {
  111500. type: a.value
  111501. };
  111502. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111503. switch (a.code) {
  111504. case 10:
  111505. t.x = a.value;
  111506. break;
  111507. case 20:
  111508. t.y = a.value;
  111509. break;
  111510. case 30:
  111511. t.z = a.value;
  111512. break;
  111513. case 40:
  111514. case 41:
  111515. case 42:
  111516. 0 != a.value && (t.bulge = a.value);
  111517. break;
  111518. case 70:
  111519. t.curveFittingVertex = 0 != (1 & a.value),
  111520. t.curveFitTangent = 0 != (2 & a.value),
  111521. t.splineVertex = 0 != (8 & a.value),
  111522. t.splineControlPoint = 0 != (16 & a.value),
  111523. t.threeDPolylineVertex = 0 != (32 & a.value),
  111524. t.threeDPolylineMesh = 0 != (64 & a.value),
  111525. t.polyfaceMeshVertex = 0 != (128 & a.value);
  111526. break;
  111527. case 50:
  111528. case 71:
  111529. t.faceA = a.value;
  111530. break;
  111531. case 72:
  111532. t.faceB = a.value;
  111533. break;
  111534. case 73:
  111535. t.faceC = a.value;
  111536. break;
  111537. case 74:
  111538. t.faceD = a.value;
  111539. break;
  111540. default:
  111541. i(t, a);
  111542. }
  111543. a = e.next();
  111544. }
  111545. return t
  111546. }
  111547. ,
  111548. w.ForEntityName = "POLYLINE",
  111549. w.prototype.parseEntity = function(e, a) {
  111550. var t = {
  111551. type: a.value,
  111552. vertices: []
  111553. };
  111554. for (a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111555. switch (a.code) {
  111556. case 10:
  111557. case 20:
  111558. case 30:
  111559. case 39:
  111560. t.thickness = a.value;
  111561. break;
  111562. case 40:
  111563. case 41:
  111564. break;
  111565. case 70:
  111566. t.shape = 0 != (1 & a.value),
  111567. t.includesCurveFitVertices = 0 != (2 & a.value),
  111568. t.includesSplineFitVertices = 0 != (4 & a.value),
  111569. t.is3dPolyline = 0 != (8 & a.value),
  111570. t.is3dPolygonMesh = 0 != (16 & a.value),
  111571. t.is3dPolygonMeshClosed = 0 != (32 & a.value),
  111572. t.isPolyfaceMesh = 0 != (64 & a.value),
  111573. t.hasContinuousLinetypePattern = 0 != (128 & a.value);
  111574. break;
  111575. case 71:
  111576. case 72:
  111577. case 73:
  111578. case 74:
  111579. case 75:
  111580. break;
  111581. case 210:
  111582. t.extrusionDirection = c(e);
  111583. break;
  111584. default:
  111585. i(t, a);
  111586. }
  111587. a = e.next();
  111588. }
  111589. return t.vertices = function(e, a) {
  111590. var t = new E
  111591. , r = [];
  111592. for (; !e.isEOF(); )
  111593. if (0 === a.code)
  111594. if ("VERTEX" === a.value)
  111595. r.push(t.parseEntity(e, a)),
  111596. a = e.lastReadGroup;
  111597. else if ("SEQEND" === a.value) {
  111598. m(e, a);
  111599. break
  111600. }
  111601. return r
  111602. }(e, a),
  111603. t
  111604. }
  111605. ,
  111606. P.ForEntityName = "SOLID",
  111607. P.prototype.parseEntity = function(e, a) {
  111608. var t;
  111609. for ((t = {
  111610. type: a.value
  111611. }).points = [],
  111612. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111613. switch (a.code) {
  111614. case 10:
  111615. t.points[0] = c(e);
  111616. break;
  111617. case 11:
  111618. t.points[1] = c(e);
  111619. break;
  111620. case 12:
  111621. t.points[2] = c(e);
  111622. break;
  111623. case 13:
  111624. t.points[3] = c(e);
  111625. break;
  111626. case 210:
  111627. t.extrusionDirection = c(e);
  111628. break;
  111629. default:
  111630. i(t, a);
  111631. }
  111632. a = e.next();
  111633. }
  111634. return t
  111635. }
  111636. ,
  111637. F.ForEntityName = "SPLINE",
  111638. F.prototype.parseEntity = function(e, a) {
  111639. var t;
  111640. for (t = {
  111641. type: a.value
  111642. },
  111643. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111644. switch (a.code) {
  111645. case 10:
  111646. t.controlPoints || (t.controlPoints = []),
  111647. t.controlPoints.push(c(e));
  111648. break;
  111649. case 11:
  111650. t.fitPoints || (t.fitPoints = []),
  111651. t.fitPoints.push(c(e));
  111652. break;
  111653. case 12:
  111654. t.startTangent = c(e);
  111655. break;
  111656. case 13:
  111657. t.endTangent = c(e);
  111658. break;
  111659. case 40:
  111660. t.knotValues || (t.knotValues = []),
  111661. t.knotValues.push(a.value);
  111662. break;
  111663. case 70:
  111664. 0 != (1 & a.value) && (t.closed = !0),
  111665. 0 != (2 & a.value) && (t.periodic = !0),
  111666. 0 != (4 & a.value) && (t.rational = !0),
  111667. 0 != (8 & a.value) && (t.planar = !0),
  111668. 0 != (16 & a.value) && (t.planar = !0,
  111669. t.linear = !0);
  111670. break;
  111671. case 71:
  111672. t.degreeOfSplineCurve = a.value;
  111673. break;
  111674. case 72:
  111675. t.numberOfKnots = a.value;
  111676. break;
  111677. case 73:
  111678. t.numberOfControlPoints = a.value;
  111679. break;
  111680. case 74:
  111681. t.numberOfFitPoints = a.value;
  111682. break;
  111683. case 210:
  111684. t.normalVector = c(e);
  111685. break;
  111686. default:
  111687. i(t, a);
  111688. }
  111689. a = e.next();
  111690. }
  111691. return t
  111692. }
  111693. ,
  111694. O.ForEntityName = "TEXT",
  111695. O.prototype.parseEntity = function(e, a) {
  111696. var t;
  111697. for (t = {
  111698. type: a.value
  111699. },
  111700. a = e.next(); "EOF" !== a && 0 !== a.code; ) {
  111701. switch (a.code) {
  111702. case 10:
  111703. t.startPoint = c(e);
  111704. break;
  111705. case 11:
  111706. t.endPoint = c(e);
  111707. break;
  111708. case 40:
  111709. t.textHeight = a.value;
  111710. break;
  111711. case 41:
  111712. t.xScale = a.value;
  111713. break;
  111714. case 50:
  111715. t.rotation = a.value;
  111716. break;
  111717. case 1:
  111718. t.text = a.value;
  111719. break;
  111720. case 72:
  111721. t.halign = a.value;
  111722. break;
  111723. case 73:
  111724. t.valign = a.value;
  111725. break;
  111726. default:
  111727. i(t, a);
  111728. }
  111729. a = e.next();
  111730. }
  111731. return t
  111732. }
  111733. ;
  111734. var N = t(0);
  111735. function T() {
  111736. var e;
  111737. this._entityHandlers = {},
  111738. (e = this).registerEntityHandler(u),
  111739. e.registerEntityHandler(l),
  111740. e.registerEntityHandler(v),
  111741. e.registerEntityHandler(d),
  111742. e.registerEntityHandler(b),
  111743. e.registerEntityHandler(p),
  111744. e.registerEntityHandler(f),
  111745. e.registerEntityHandler(k),
  111746. e.registerEntityHandler(y),
  111747. e.registerEntityHandler(h),
  111748. e.registerEntityHandler(g),
  111749. e.registerEntityHandler(w),
  111750. e.registerEntityHandler(P),
  111751. e.registerEntityHandler(F),
  111752. e.registerEntityHandler(O);
  111753. }
  111754. function S(e) {
  111755. N.debug("unhandled group " + L(e));
  111756. }
  111757. function L(e) {
  111758. return e.code + ":" + e.value
  111759. }
  111760. N.setLevel("error"),
  111761. T.prototype.parse = function(e, a) {
  111762. throw new Error("read() not implemented. Use readSync()")
  111763. }
  111764. ,
  111765. T.prototype.registerEntityHandler = function(e) {
  111766. var a = new e;
  111767. this._entityHandlers[e.ForEntityName] = a;
  111768. }
  111769. ,
  111770. T.prototype.parseSync = function(e) {
  111771. return "string" == typeof e ? this._parse(e) : (console.error("Cannot read dxf source of type `" + typeof e),
  111772. null)
  111773. }
  111774. ,
  111775. T.prototype.parseStream = function(e, a) {
  111776. var t = ""
  111777. , r = this;
  111778. e.on("data", function(e) {
  111779. t += e;
  111780. }),
  111781. e.on("end", function() {
  111782. try {
  111783. var e = r._parse(t);
  111784. } catch (e) {
  111785. return a(e)
  111786. }
  111787. a(null, e);
  111788. }),
  111789. e.on("error", function(e) {
  111790. a(e);
  111791. });
  111792. }
  111793. ,
  111794. T.prototype._parse = function(e) {
  111795. var a, t, n = {}, c = 0, i = e.split(/\r\n|\r|\n/g);
  111796. if (!(a = new r(i)).hasNext())
  111797. throw Error("Empty file");
  111798. var u = this
  111799. , s = function(e, a) {
  111800. return t.code === e && t.value === a
  111801. }
  111802. , l = function() {
  111803. var e = null
  111804. , r = null
  111805. , n = {};
  111806. for (t = a.next(); ; ) {
  111807. if (s(0, "ENDSEC")) {
  111808. e && (n[e] = r);
  111809. break
  111810. }
  111811. 9 === t.code ? (e && (n[e] = r),
  111812. e = t.value) : 10 === t.code ? r = {
  111813. x: t.value
  111814. } : 20 === t.code ? r.y = t.value : 30 === t.code ? r.z = t.value : r = t.value,
  111815. t = a.next();
  111816. }
  111817. return t = a.next(),
  111818. n
  111819. }
  111820. , v = function() {
  111821. var e, r = {};
  111822. for (t = a.next(); "EOF" !== t.value && !s(0, "ENDSEC"); )
  111823. s(0, "BLOCK") ? (N.debug("block {"),
  111824. e = d(),
  111825. N.debug("}"),
  111826. x(e),
  111827. e.name ? r[e.name] = e : N.error('block with handle "' + e.handle + '" is missing a name.')) : (S(t),
  111828. t = a.next());
  111829. return r
  111830. }
  111831. , d = function() {
  111832. var e = {};
  111833. for (t = a.next(); "EOF" !== t.value; ) {
  111834. switch (t.code) {
  111835. case 1:
  111836. e.xrefPath = t.value,
  111837. t = a.next();
  111838. break;
  111839. case 2:
  111840. e.name = t.value,
  111841. t = a.next();
  111842. break;
  111843. case 3:
  111844. e.name2 = t.value,
  111845. t = a.next();
  111846. break;
  111847. case 5:
  111848. e.handle = t.value,
  111849. t = a.next();
  111850. break;
  111851. case 8:
  111852. e.layer = t.value,
  111853. t = a.next();
  111854. break;
  111855. case 10:
  111856. e.position = y(),
  111857. t = a.next();
  111858. break;
  111859. case 67:
  111860. e.paperSpace = !(!t.value || 1 != t.value),
  111861. t = a.next();
  111862. break;
  111863. case 70:
  111864. 0 != t.value && (e.type = t.value),
  111865. t = a.next();
  111866. break;
  111867. case 100:
  111868. t = a.next();
  111869. break;
  111870. case 330:
  111871. e.ownerHandle = t.value,
  111872. t = a.next();
  111873. break;
  111874. case 0:
  111875. if ("ENDBLK" == t.value)
  111876. break;
  111877. e.entities = k(!0);
  111878. break;
  111879. default:
  111880. S(t),
  111881. t = a.next();
  111882. }
  111883. if (s(0, "ENDBLK")) {
  111884. t = a.next();
  111885. break
  111886. }
  111887. }
  111888. return e
  111889. }
  111890. , b = function() {
  111891. var e = {};
  111892. for (t = a.next(); "EOF" !== t.value && !s(0, "ENDSEC"); ) {
  111893. s(0, "TABLE") ? (t = a.next(),
  111894. f[t.value] ? (N.debug(t.value + " Table {"),
  111895. e[f[t.value].tableName] = p(),
  111896. N.debug("}")) : N.debug("Unhandled Table " + t.value)) : t = a.next();
  111897. }
  111898. return t = a.next(),
  111899. e
  111900. };
  111901. var p = function() {
  111902. var e, r = f[t.value], n = {}, o = 0;
  111903. for (t = a.next(); !s(0, "ENDTAB"); )
  111904. switch (t.code) {
  111905. case 5:
  111906. n.handle = t.value,
  111907. t = a.next();
  111908. break;
  111909. case 330:
  111910. n.ownerHandle = t.value,
  111911. t = a.next();
  111912. break;
  111913. case 100:
  111914. "AcDbSymbolTable" === t.value ? t = a.next() : (S(t),
  111915. t = a.next());
  111916. break;
  111917. case 70:
  111918. o = t.value,
  111919. t = a.next();
  111920. break;
  111921. case 0:
  111922. t.value === r.dxfSymbolName ? n[r.tableRecordsProperty] = r.parseTableRecords() : (S(t),
  111923. t = a.next());
  111924. break;
  111925. default:
  111926. S(t),
  111927. t = a.next();
  111928. }
  111929. var c = n[r.tableRecordsProperty];
  111930. return c && (c.constructor === Array ? e = c.length : "object" == typeof c && (e = Object.keys(c).length),
  111931. o !== e && N.warn("Parsed " + e + " " + r.dxfSymbolName + "'s but expected " + o)),
  111932. t = a.next(),
  111933. n
  111934. }
  111935. , f = {
  111936. VPORT: {
  111937. tableRecordsProperty: "viewPorts",
  111938. tableName: "viewPort",
  111939. dxfSymbolName: "VPORT",
  111940. parseTableRecords: function() {
  111941. var e = []
  111942. , r = {};
  111943. for (N.debug("ViewPort {"),
  111944. t = a.next(); !s(0, "ENDTAB"); )
  111945. switch (t.code) {
  111946. case 2:
  111947. r.name = t.value,
  111948. t = a.next();
  111949. break;
  111950. case 10:
  111951. r.lowerLeftCorner = y(),
  111952. t = a.next();
  111953. break;
  111954. case 11:
  111955. r.upperRightCorner = y(),
  111956. t = a.next();
  111957. break;
  111958. case 12:
  111959. r.center = y(),
  111960. t = a.next();
  111961. break;
  111962. case 13:
  111963. r.snapBasePoint = y(),
  111964. t = a.next();
  111965. break;
  111966. case 14:
  111967. r.snapSpacing = y(),
  111968. t = a.next();
  111969. break;
  111970. case 15:
  111971. r.gridSpacing = y(),
  111972. t = a.next();
  111973. break;
  111974. case 16:
  111975. r.viewDirectionFromTarget = y(),
  111976. t = a.next();
  111977. break;
  111978. case 17:
  111979. r.viewTarget = y(),
  111980. t = a.next();
  111981. break;
  111982. case 42:
  111983. r.lensLength = t.value,
  111984. t = a.next();
  111985. break;
  111986. case 43:
  111987. r.frontClippingPlane = t.value,
  111988. t = a.next();
  111989. break;
  111990. case 44:
  111991. r.backClippingPlane = t.value,
  111992. t = a.next();
  111993. break;
  111994. case 45:
  111995. r.viewHeight = t.value,
  111996. t = a.next();
  111997. break;
  111998. case 50:
  111999. r.snapRotationAngle = t.value,
  112000. t = a.next();
  112001. break;
  112002. case 51:
  112003. r.viewTwistAngle = t.value,
  112004. t = a.next();
  112005. break;
  112006. case 79:
  112007. r.orthographicType = t.value,
  112008. t = a.next();
  112009. break;
  112010. case 110:
  112011. r.ucsOrigin = y(),
  112012. t = a.next();
  112013. break;
  112014. case 111:
  112015. r.ucsXAxis = y(),
  112016. t = a.next();
  112017. break;
  112018. case 112:
  112019. r.ucsYAxis = y(),
  112020. t = a.next();
  112021. break;
  112022. case 110:
  112023. r.ucsOrigin = y(),
  112024. t = a.next();
  112025. break;
  112026. case 281:
  112027. r.renderMode = t.value,
  112028. t = a.next();
  112029. break;
  112030. case 281:
  112031. r.defaultLightingType = t.value,
  112032. t = a.next();
  112033. break;
  112034. case 292:
  112035. r.defaultLightingOn = t.value,
  112036. t = a.next();
  112037. break;
  112038. case 330:
  112039. r.ownerHandle = t.value,
  112040. t = a.next();
  112041. break;
  112042. case 63:
  112043. case 421:
  112044. case 431:
  112045. r.ambientColor = t.value,
  112046. t = a.next();
  112047. break;
  112048. case 0:
  112049. "VPORT" === t.value && (N.debug("}"),
  112050. e.push(r),
  112051. N.debug("ViewPort {"),
  112052. r = {},
  112053. t = a.next());
  112054. break;
  112055. default:
  112056. S(t),
  112057. t = a.next();
  112058. }
  112059. return N.debug("}"),
  112060. e.push(r),
  112061. e
  112062. }
  112063. },
  112064. LTYPE: {
  112065. tableRecordsProperty: "lineTypes",
  112066. tableName: "lineType",
  112067. dxfSymbolName: "LTYPE",
  112068. parseTableRecords: function() {
  112069. var e, r, n = {}, o = {};
  112070. for (N.debug("LType {"),
  112071. t = a.next(); !s(0, "ENDTAB"); )
  112072. switch (t.code) {
  112073. case 2:
  112074. o.name = t.value,
  112075. e = t.value,
  112076. t = a.next();
  112077. break;
  112078. case 3:
  112079. o.description = t.value,
  112080. t = a.next();
  112081. break;
  112082. case 73:
  112083. (r = t.value) > 0 && (o.pattern = []),
  112084. t = a.next();
  112085. break;
  112086. case 40:
  112087. o.patternLength = t.value,
  112088. t = a.next();
  112089. break;
  112090. case 49:
  112091. o.pattern.push(t.value),
  112092. t = a.next();
  112093. break;
  112094. case 0:
  112095. N.debug("}"),
  112096. r > 0 && r !== o.pattern.length && N.warn("lengths do not match on LTYPE pattern"),
  112097. n[e] = o,
  112098. o = {},
  112099. N.debug("LType {"),
  112100. t = a.next();
  112101. break;
  112102. default:
  112103. t = a.next();
  112104. }
  112105. return N.debug("}"),
  112106. n[e] = o,
  112107. n
  112108. }
  112109. },
  112110. LAYER: {
  112111. tableRecordsProperty: "layers",
  112112. tableName: "layer",
  112113. dxfSymbolName: "LAYER",
  112114. parseTableRecords: function() {
  112115. var e, r, n = {}, c = {};
  112116. for (N.debug("Layer {"),
  112117. t = a.next(); !s(0, "ENDTAB"); )
  112118. switch (t.code) {
  112119. case 2:
  112120. c.name = t.value,
  112121. e = t.value,
  112122. t = a.next();
  112123. break;
  112124. case 62:
  112125. c.visible = t.value >= 0,
  112126. c.colorIndex = Math.abs(t.value),
  112127. c.color = (r = c.colorIndex,
  112128. o[r]),
  112129. t = a.next();
  112130. break;
  112131. case 70:
  112132. c.frozen = 0 != (1 & t.value) || 0 != (2 & t.value),
  112133. t = a.next();
  112134. break;
  112135. case 0:
  112136. "LAYER" === t.value && (N.debug("}"),
  112137. n[e] = c,
  112138. N.debug("Layer {"),
  112139. c = {},
  112140. e = void 0,
  112141. t = a.next());
  112142. break;
  112143. default:
  112144. S(t),
  112145. t = a.next();
  112146. }
  112147. return N.debug("}"),
  112148. n[e] = c,
  112149. n
  112150. }
  112151. }
  112152. }
  112153. , k = function(e) {
  112154. var r = []
  112155. , n = e ? "ENDBLK" : "ENDSEC";
  112156. for (e || (t = a.next()); ; )
  112157. if (0 === t.code) {
  112158. if (t.value === n)
  112159. break;
  112160. var o, c = u._entityHandlers[t.value];
  112161. if (null == c) {
  112162. N.warn("Unhandled entity " + t.value),
  112163. t = a.next();
  112164. continue
  112165. }
  112166. N.debug(t.value + " {"),
  112167. o = c.parseEntity(a, t),
  112168. t = a.lastReadGroup,
  112169. N.debug("}"),
  112170. x(o),
  112171. r.push(o);
  112172. } else
  112173. t = a.next();
  112174. return "ENDSEC" == n && (t = a.next()),
  112175. r
  112176. }
  112177. , y = function() {
  112178. var e = {}
  112179. , r = t.code;
  112180. if (e.x = t.value,
  112181. r += 10,
  112182. (t = a.next()).code != r)
  112183. throw new Error("Expected code for point value to be " + r + " but got " + t.code + ".");
  112184. return e.y = t.value,
  112185. r += 10,
  112186. (t = a.next()).code != r ? (a.rewind(),
  112187. e) : (e.z = t.value,
  112188. e)
  112189. }
  112190. , x = function(e) {
  112191. if (!e)
  112192. throw new TypeError("entity cannot be undefined or null");
  112193. e.handle || (e.handle = c++);
  112194. };
  112195. return function() {
  112196. for (t = a.next(); !a.isEOF(); )
  112197. if (0 === t.code && "SECTION" === t.value) {
  112198. if (2 !== (t = a.next()).code) {
  112199. console.error("Unexpected code %s after 0:SECTION", L(t)),
  112200. t = a.next();
  112201. continue
  112202. }
  112203. "HEADER" === t.value ? (N.debug("> HEADER"),
  112204. n.header = l(),
  112205. N.debug("<")) : "BLOCKS" === t.value ? (N.debug("> BLOCKS"),
  112206. n.blocks = v(),
  112207. N.debug("<")) : "ENTITIES" === t.value ? (N.debug("> ENTITIES"),
  112208. n.entities = k(!1),
  112209. N.debug("<")) : "TABLES" === t.value ? (N.debug("> TABLES"),
  112210. n.tables = b(),
  112211. N.debug("<")) : "EOF" === t.value ? N.debug("EOF") : N.warn("Skipping section '%s'", t.value);
  112212. } else
  112213. t = a.next();
  112214. }(),
  112215. n
  112216. }
  112217. ;
  112218. a.default = T;
  112219. }
  112220. ]).default
  112221. });
  112222. class DxfLoader extends EventDispatcher{
  112223. constructor(){
  112224. super();
  112225. this.parser = new Potree.DxfParser;
  112226. }
  112227. load(url,done, options={}){
  112228. Potree.loadFile(url, {returnText:true} , (data)=>{
  112229. var dxfJson = this.parser.parseSync(data);
  112230. console.log(dxfJson);
  112231. let model = this.createModel(dxfJson, options);
  112232. done(model);
  112233. });
  112234. }
  112235. createModel(data, options={}){
  112236. let root = new Object3D;
  112237. var i, entity, obj, min_x, min_y, min_z, max_x, max_y, max_z;
  112238. /* var dims = {
  112239. min: { x: false, y: false, z: false},
  112240. max: { x: false, y: false, z: false}
  112241. }; */
  112242. //let bound = THREE.Box3
  112243. for(i = 0; i < data.entities.length; i++) {
  112244. entity = data.entities[i];
  112245. obj = drawEntity(entity, data, options.unsupportTypes );
  112246. if (obj) {
  112247. var bbox = new Box3().setFromObject(obj);
  112248. /* if (bbox.min.x && ((dims.min.x === false) || (dims.min.x > bbox.min.x))) dims.min.x = bbox.min.x;
  112249. if (bbox.min.y && ((dims.min.y === false) || (dims.min.y > bbox.min.y))) dims.min.y = bbox.min.y;
  112250. if (bbox.min.z && ((dims.min.z === false) || (dims.min.z > bbox.min.z))) dims.min.z = bbox.min.z;
  112251. if (bbox.max.x && ((dims.max.x === false) || (dims.max.x < bbox.max.x))) dims.max.x = bbox.max.x;
  112252. if (bbox.max.y && ((dims.max.y === false) || (dims.max.y < bbox.max.y))) dims.max.y = bbox.max.y;
  112253. if (bbox.max.z && ((dims.max.z === false) || (dims.max.z < bbox.max.z))) dims.max.z = bbox.max.z; */
  112254. root.add(obj);
  112255. }
  112256. obj = null;
  112257. }
  112258. return root
  112259. }
  112260. }
  112261. function drawEntity(entity, data, unsupportTypes, group) {
  112262. var mesh;
  112263. if(unsupportTypes && unsupportTypes.includes(entity.type)){
  112264. console.warn('����һ��dxf������Ƶ�type��', entity.type);
  112265. return //add �����Ƹ���
  112266. }
  112267. if(entity.type === 'CIRCLE' || entity.type === 'ARC') {
  112268. mesh = drawArc(entity, data, unsupportTypes, group );
  112269. } else if(entity.type === 'LWPOLYLINE' || entity.type === 'LINE' || entity.type === 'POLYLINE') {
  112270. mesh = drawLine(entity, data, unsupportTypes, group );
  112271. } else if(entity.type === 'TEXT') {//"MTEXT" text: "{\fKaiTi|b0|i0|c134|p49;�������̨}"
  112272. mesh = drawText(entity, data, unsupportTypes, group);
  112273. } else if(entity.type === 'SOLID') {
  112274. mesh = drawSolid(entity, data);
  112275. } else if(entity.type === 'POINT') {
  112276. mesh = drawPoint(entity, data );
  112277. } else if(entity.type === 'INSERT') {//Ƕ������group
  112278. mesh = drawBlock(entity, data, unsupportTypes, group );
  112279. } else if(entity.type === 'SPLINE') {
  112280. mesh = drawSpline(entity, data);
  112281. } else if(entity.type === 'MTEXT') {
  112282. mesh = drawMtext(entity, data, unsupportTypes, group );
  112283. } else if(entity.type === 'ELLIPSE') {
  112284. mesh = drawEllipse(entity, data, unsupportTypes, group );
  112285. } else if(entity.type === 'DIMENSION') {
  112286. var dimTypeEnum = entity.dimensionType & 7;
  112287. if(dimTypeEnum === 0) {
  112288. mesh = drawDimension(entity, data);
  112289. } else {
  112290. console.log("Unsupported Dimension type: " + dimTypeEnum);
  112291. }
  112292. }
  112293. else {
  112294. console.log("Unsupported Entity Type: " + entity.type);
  112295. }
  112296. if(entity.type === 'LWPOLYLINE' || entity.type === 'LINE' || entity.type === 'POLYLINE') {
  112297. mesh = drawLine(entity, data);
  112298. }
  112299. /* if(entity.type === 'INSERT') {
  112300. mesh = drawBlock(entity, data); //group
  112301. } */
  112302. /*
  112303. �Ŷ���arc
  112304. �ƺ�ǽ�ڶ��Dz���insert���ͣ���������
  112305. */
  112306. mesh && (mesh.dxfInfo = entity); //add
  112307. return mesh;
  112308. }
  112309. function drawEllipse(entity, data) {
  112310. var color = getColor$2(entity, data);
  112311. var xrad = Math.sqrt(Math.pow(entity.majorAxisEndPoint.x,2) + Math.pow(entity.majorAxisEndPoint.y,2));
  112312. var yrad = xrad*entity.axisRatio;
  112313. var rotation = Math.atan2(entity.majorAxisEndPoint.y, entity.majorAxisEndPoint.x);
  112314. var curve = new EllipseCurve(
  112315. entity.center.x, entity.center.y,
  112316. xrad, yrad,
  112317. entity.startAngle, entity.endAngle,
  112318. false, // Always counterclockwise
  112319. rotation
  112320. );
  112321. var points = curve.getPoints( 50 );
  112322. var geometry = new BufferGeometry().setFromPoints( points );
  112323. var material = new LineBasicMaterial( { linewidth: 1, color : color } );
  112324. // Create the final object to add to the scene
  112325. var ellipse = new Line( geometry, material );
  112326. return ellipse;
  112327. }
  112328. function drawMtext(entity, data) {
  112329. var color = getColor$2(entity, data);
  112330. //if (!font) { return console.log('font parameter not set. Ignoring text entity.')}
  112331. var geometry = new TextGeometry( entity.text, {
  112332. //font: font,
  112333. size: entity.height * (4/5),
  112334. height: 1
  112335. });
  112336. var material = new MeshBasicMaterial( {color: color} );
  112337. var text = new Mesh( geometry, material );
  112338. // Measure what we rendered.
  112339. var measure = new Box3();
  112340. measure.setFromObject( text );
  112341. var textWidth = measure.max.x - measure.min.x;
  112342. // If the text ends up being wider than the box, it's supposed
  112343. // to be multiline. Doing that in threeJS is overkill.
  112344. if (textWidth > entity.width) {
  112345. console.log("Can't render this multipline MTEXT entity, sorry.", entity);
  112346. return undefined;
  112347. }
  112348. text.position.z = 0;
  112349. switch (entity.attachmentPoint) {
  112350. case 1:
  112351. // Top Left
  112352. text.position.x = entity.position.x;
  112353. text.position.y = entity.position.y - entity.height;
  112354. break;
  112355. case 2:
  112356. // Top Center
  112357. text.position.x = entity.position.x - textWidth/2;
  112358. text.position.y = entity.position.y - entity.height;
  112359. break;
  112360. case 3:
  112361. // Top Right
  112362. text.position.x = entity.position.x - textWidth;
  112363. text.position.y = entity.position.y - entity.height;
  112364. break;
  112365. case 4:
  112366. // Middle Left
  112367. text.position.x = entity.position.x;
  112368. text.position.y = entity.position.y - entity.height/2;
  112369. break;
  112370. case 5:
  112371. // Middle Center
  112372. text.position.x = entity.position.x - textWidth/2;
  112373. text.position.y = entity.position.y - entity.height/2;
  112374. break;
  112375. case 6:
  112376. // Middle Right
  112377. text.position.x = entity.position.x - textWidth;
  112378. text.position.y = entity.position.y - entity.height/2;
  112379. break;
  112380. case 7:
  112381. // Bottom Left
  112382. text.position.x = entity.position.x;
  112383. text.position.y = entity.position.y;
  112384. break;
  112385. case 8:
  112386. // Bottom Center
  112387. text.position.x = entity.position.x - textWidth/2;
  112388. text.position.y = entity.position.y;
  112389. break;
  112390. case 9:
  112391. // Bottom Right
  112392. text.position.x = entity.position.x - textWidth;
  112393. text.position.y = entity.position.y;
  112394. break;
  112395. default:
  112396. return undefined;
  112397. };
  112398. return text;
  112399. }
  112400. function drawSpline(entity, data) {
  112401. var color = getColor$2(entity, data);
  112402. var points = entity.controlPoints.map(function(vec) {
  112403. return new Vector2(vec.x, vec.y);
  112404. });
  112405. var interpolatedPoints = [];
  112406. var curve;
  112407. if (entity.degreeOfSplineCurve === 2 || entity.degreeOfSplineCurve === 3) {
  112408. for(var i = 0; i + 2 < points.length; i = i + 2) {
  112409. if (entity.degreeOfSplineCurve === 2) {
  112410. curve = new QuadraticBezierCurve(points[i], points[i + 1], points[i + 2]);
  112411. } else {
  112412. curve = new QuadraticBezierCurve3(points[i], points[i + 1], points[i + 2]);
  112413. }
  112414. interpolatedPoints.push.apply(interpolatedPoints, curve.getPoints(50));
  112415. }
  112416. } else {
  112417. curve = new SplineCurve(points);
  112418. interpolatedPoints = curve.getPoints( 100 );
  112419. }
  112420. var geometry = new BufferGeometry().setFromPoints( interpolatedPoints );
  112421. var material = new LineBasicMaterial( { linewidth: 1, color : color } );
  112422. var splineObject = new Line( geometry, material );
  112423. return splineObject;
  112424. }
  112425. function drawLine(entity, data) {
  112426. var geometry = new Geometry(),
  112427. color = getColor$2(entity, data),
  112428. material, lineType, vertex, startPoint, endPoint, bulgeGeometry,
  112429. bulge, i, line;
  112430. if (!entity.vertices) return console.log('entity missing vertices.');
  112431. // create geometry
  112432. for(i = 0; i < entity.vertices.length; i++) {
  112433. if(entity.vertices[i].bulge) {
  112434. bulge = entity.vertices[i].bulge;
  112435. startPoint = entity.vertices[i];
  112436. endPoint = i + 1 < entity.vertices.length ? entity.vertices[i + 1] : geometry.vertices[0];
  112437. bulgeGeometry = new THREEx.BulgeGeometry(startPoint, endPoint, bulge);
  112438. geometry.vertices.push.apply(geometry.vertices, bulgeGeometry.vertices);
  112439. } else {
  112440. vertex = entity.vertices[i];
  112441. geometry.vertices.push(new Vector3(vertex.x, vertex.y, 0));
  112442. }
  112443. }
  112444. if(entity.shape) geometry.vertices.push(geometry.vertices[0]);
  112445. // set material
  112446. if(entity.lineType) {
  112447. lineType = data.tables.lineType.lineTypes[entity.lineType];
  112448. }
  112449. if(lineType && lineType.pattern && lineType.pattern.length !== 0) {
  112450. material = new LineDashedMaterial({ color: color, gapSize: 4, dashSize: 4});
  112451. } else {
  112452. material = new LineBasicMaterial({ linewidth: 1, color: color });
  112453. }
  112454. // if(lineType && lineType.pattern && lineType.pattern.length !== 0) {
  112455. // geometry.computeLineDistances();
  112456. // // Ugly hack to add diffuse to this. Maybe copy the uniforms object so we
  112457. // // don't add diffuse to a material.
  112458. // lineType.material.uniforms.diffuse = { type: 'c', value: new THREE.Color(color) };
  112459. // material = new THREE.ShaderMaterial({
  112460. // uniforms: lineType.material.uniforms,
  112461. // vertexShader: lineType.material.vertexShader,
  112462. // fragmentShader: lineType.material.fragmentShader
  112463. // });
  112464. // }else {
  112465. // material = new THREE.LineBasicMaterial({ linewidth: 1, color: color });
  112466. // }
  112467. line = new Line(geometry, material);
  112468. return line;
  112469. }
  112470. function drawArc(entity, data) {
  112471. var startAngle, endAngle;
  112472. if (entity.type === 'CIRCLE') {
  112473. startAngle = entity.startAngle || 0;
  112474. endAngle = startAngle + 2 * Math.PI;
  112475. } else {
  112476. startAngle = entity.startAngle;
  112477. endAngle = entity.endAngle;
  112478. }
  112479. var curve = new ArcCurve(
  112480. 0, 0,
  112481. entity.radius,
  112482. startAngle,
  112483. endAngle);
  112484. var points = curve.getPoints( 32 );
  112485. var geometry = new BufferGeometry().setFromPoints( points );
  112486. var material = new LineBasicMaterial({ color: getColor$2(entity, data) });
  112487. var arc = new Line(geometry, material);
  112488. arc.position.x = entity.center.x;
  112489. arc.position.y = entity.center.y;
  112490. arc.position.z = entity.center.z;
  112491. return arc;
  112492. }
  112493. function drawSolid(entity, data) {
  112494. var material, mesh, verts,
  112495. geometry = new Geometry();
  112496. verts = geometry.vertices;
  112497. verts.push(new Vector3(entity.points[0].x, entity.points[0].y, entity.points[0].z));
  112498. verts.push(new Vector3(entity.points[1].x, entity.points[1].y, entity.points[1].z));
  112499. verts.push(new Vector3(entity.points[2].x, entity.points[2].y, entity.points[2].z));
  112500. verts.push(new Vector3(entity.points[3].x, entity.points[3].y, entity.points[3].z));
  112501. // Calculate which direction the points are facing (clockwise or counter-clockwise)
  112502. var vector1 = new Vector3();
  112503. var vector2 = new Vector3();
  112504. vector1.subVectors(verts[1], verts[0]);
  112505. vector2.subVectors(verts[2], verts[0]);
  112506. vector1.cross(vector2);
  112507. // If z < 0 then we must draw these in reverse order
  112508. if(vector1.z < 0) {
  112509. geometry.faces.push(new Face3(2, 1, 0));
  112510. geometry.faces.push(new Face3(2, 3, 1));
  112511. } else {
  112512. geometry.faces.push(new Face3(0, 1, 2));
  112513. geometry.faces.push(new Face3(1, 3, 2));
  112514. }
  112515. material = new MeshBasicMaterial({ color: getColor$2(entity, data) });
  112516. return new Mesh(geometry, material);
  112517. }
  112518. function drawText(entity, data) {
  112519. var geometry, material, text;
  112520. //����Ҫfont���ܻ�������
  112521. /* if(!font)
  112522. 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.');
  112523. */
  112524. geometry = new TextGeometry(entity.text, {/* font: font, */ height: 0, size: entity.textHeight || 12 });
  112525. if (entity.rotation) {
  112526. var zRotation = entity.rotation * Math.PI / 180;
  112527. geometry.rotateZ(zRotation);
  112528. }
  112529. material = new MeshBasicMaterial({ color: getColor$2(entity, data) });
  112530. text = new Mesh(geometry, material);
  112531. text.position.x = entity.startPoint.x;
  112532. text.position.y = entity.startPoint.y;
  112533. text.position.z = entity.startPoint.z;
  112534. return text;
  112535. }
  112536. function drawPoint(entity, data) {
  112537. var geometry, material, point;
  112538. geometry = new Geometry();
  112539. geometry.vertices.push(new Vector3(entity.position.x, entity.position.y, entity.position.z));
  112540. // TODO: could be more efficient. PointCloud per layer?
  112541. var numPoints = 1;
  112542. var color = getColor$2(entity, data);
  112543. var colors = new Float32Array( numPoints*3 );
  112544. colors[0] = color.r;
  112545. colors[1] = color.g;
  112546. colors[2] = color.b;
  112547. geometry.colors = colors;
  112548. geometry.computeBoundingBox();
  112549. material = new PointsMaterial( { size: 0.05, vertexColors: VertexColors } );
  112550. point = new Points(geometry, material);
  112551. //scene.add(point);
  112552. return point
  112553. }
  112554. function drawDimension(entity, data, unsupportTypes, parentGroup) {
  112555. return drawBlock(entity, data, unsupportTypes, parentGroup, true)
  112556. //��
  112557. /* var block = data.blocks[entity.block];
  112558. if (!block || !block.entities) return null;
  112559. var group = new THREE.Object3D();
  112560. // if(entity.anchorPoint) {
  112561. // group.position.x = entity.anchorPoint.x;
  112562. // group.position.y = entity.anchorPoint.y;
  112563. // group.position.z = entity.anchorPoint.z;
  112564. // }
  112565. for(var i = 0; i < block.entities.length; i++) {
  112566. var childEntity = drawEntity(block.entities[i], data, group);
  112567. if(childEntity && !group.children.includes(childEntity)) group.add(childEntity);
  112568. }
  112569. return group; */
  112570. }
  112571. function drawBlock(entity, data, unsupportTypes, parentGroup, isDimension) {
  112572. var block = data.blocks[entity.name];
  112573. if (!block.entities) return null;
  112574. var group = new Object3D();
  112575. parentGroup && parentGroup.add(group);//��ǰ���� Ϊ�˻��matrixWorld
  112576. if(!isDimension){
  112577. if(entity.position) {
  112578. group.position.x = entity.position.x;
  112579. group.position.y = entity.position.y;
  112580. group.position.z = entity.position.z;
  112581. }
  112582. if(entity.xScale){
  112583. group.scale.x = entity.xScale;
  112584. }
  112585. if(entity.yScale){
  112586. group.scale.y = entity.yScale;
  112587. }
  112588. if(entity.rotation) {
  112589. group.rotation.z = entity.rotation * Math.PI / 180;
  112590. }
  112591. //add: ���������еĻ������������Զ add zScale
  112592. var flag;
  112593. if(entity.zScale != void 0 && entity.extrusionDirection){//see (005.dxf�� others/01.dxf) extrusionDirection ={x:0,y:0,z:-1}
  112594. group.position.x *= Math.sign(entity.zScale);
  112595. group.scale.x *= Math.sign(entity.zScale);
  112596. group.rotation.z *= Math.sign(entity.zScale);
  112597. flag = 1;
  112598. //�����������extrusionDirection
  112599. }
  112600. }else {
  112601. /* if(entity.anchorPoint) {
  112602. group.position.x = entity.anchorPoint.x;
  112603. group.position.y = entity.anchorPoint.y;
  112604. group.position.z = entity.anchorPoint.z;
  112605. } */
  112606. }
  112607. //add:
  112608. group.updateMatrixWorld();
  112609. var visiEntities = block.entities.filter(e=>e.visible !== false);
  112610. //console.log("block�Ŀɼ�children����"+block.entities.length)
  112611. for(var i = 0; i < visiEntities.length; i++) {
  112612. var childEntity = drawEntity(visiEntities[i], data, unsupportTypes, group );
  112613. if(childEntity && !group.children.includes(childEntity)) group.add(childEntity);
  112614. }
  112615. return group;
  112616. }
  112617. function getColor$2(entity, data) {
  112618. var color = 0x000000; //default
  112619. if(entity.color) color = entity.color;
  112620. else if(data.tables && data.tables.layer && data.tables.layer.layers[entity.layer])
  112621. color = data.tables.layer.layers[entity.layer].color;
  112622. if(color == null || color === 0xffffff) {
  112623. color = 0x000000;
  112624. }
  112625. return color;
  112626. }
  112627. function createLineTypeShaders(data) {
  112628. var ltype, type;
  112629. if(!data.tables || !data.tables.lineType) return;
  112630. var ltypes = data.tables.lineType.lineTypes;
  112631. for(type in ltypes) {
  112632. ltype = ltypes[type];
  112633. if(!ltype.pattern) continue;
  112634. ltype.material = createDashedLineShader(ltype.pattern);
  112635. }
  112636. }
  112637. function createDashedLineShader(pattern) {
  112638. var i,
  112639. dashedLineShader = {},
  112640. totalLength = 0.0;
  112641. for(i = 0; i < pattern.length; i++) {
  112642. totalLength += Math.abs(pattern[i]);
  112643. }
  112644. dashedLineShader.uniforms = UniformsUtils.merge([
  112645. UniformsLib[ 'common' ],
  112646. UniformsLib[ 'fog' ],
  112647. {
  112648. 'pattern': { type: 'fv1', value: pattern },
  112649. 'patternLength': { type: 'f', value: totalLength }
  112650. }
  112651. ]);
  112652. dashedLineShader.vertexShader = [
  112653. 'attribute float lineDistance;',
  112654. 'varying float vLineDistance;',
  112655. ShaderChunk[ 'color_pars_vertex' ],
  112656. 'void main() {',
  112657. ShaderChunk[ 'color_vertex' ],
  112658. 'vLineDistance = lineDistance;',
  112659. 'gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );',
  112660. '}'
  112661. ].join('\n');
  112662. dashedLineShader.fragmentShader = [
  112663. 'uniform vec3 diffuse;',
  112664. 'uniform float opacity;',
  112665. 'uniform float pattern[' + pattern.length + '];',
  112666. 'uniform float patternLength;',
  112667. 'varying float vLineDistance;',
  112668. ShaderChunk[ 'color_pars_fragment' ],
  112669. ShaderChunk[ 'fog_pars_fragment' ],
  112670. 'void main() {',
  112671. 'float pos = mod(vLineDistance, patternLength);',
  112672. 'for ( int i = 0; i < ' + pattern.length + '; i++ ) {',
  112673. 'pos = pos - abs(pattern[i]);',
  112674. 'if( pos < 0.0 ) {',
  112675. 'if( pattern[i] > 0.0 ) {',
  112676. 'gl_FragColor = vec4(1.0, 0.0, 0.0, opacity );',
  112677. 'break;',
  112678. '}',
  112679. 'discard;',
  112680. '}',
  112681. '}',
  112682. ShaderChunk[ 'color_fragment' ],
  112683. ShaderChunk[ 'fog_fragment' ],
  112684. '}'
  112685. ].join('\n');
  112686. return dashedLineShader;
  112687. }
  112688. function findExtents(scene) {
  112689. for(var child of scene.children) {
  112690. var minX, maxX, minY, maxY;
  112691. if(child.position) {
  112692. minX = Math.min(child.position.x, minX);
  112693. minY = Math.min(child.position.y, minY);
  112694. maxX = Math.max(child.position.x, maxX);
  112695. maxY = Math.max(child.position.y, maxY);
  112696. }
  112697. }
  112698. return { min: { x: minX, y: minY }, max: { x: maxX, y: maxY }};
  112699. }
  112700. // Three.js extension functions. Webpack doesn't seem to like it if we modify the THREE object directly.
  112701. var THREEx = { Math: {} };
  112702. /**
  112703. * Returns the angle in radians of the vector (p1,p2). In other words, imagine
  112704. * putting the base of the vector at coordinates (0,0) and finding the angle
  112705. * from vector (1,0) to (p1,p2).
  112706. * @param {Object} p1 start point of the vector
  112707. * @param {Object} p2 end point of the vector
  112708. * @return {Number} the angle
  112709. */
  112710. THREEx.Math.angle2 = function(p1, p2) {
  112711. var v1 = new Vector2(p1.x, p1.y);
  112712. var v2 = new Vector2(p2.x, p2.y);
  112713. v2.sub(v1); // sets v2 to be our chord
  112714. v2.normalize();
  112715. if(v2.y < 0) return -Math.acos(v2.x);
  112716. return Math.acos(v2.x);
  112717. };
  112718. THREEx.Math.polar = function(point, distance, angle) {
  112719. var result = {};
  112720. result.x = point.x + distance * Math.cos(angle);
  112721. result.y = point.y + distance * Math.sin(angle);
  112722. return result;
  112723. };
  112724. /**
  112725. * Calculates points for a curve between two points
  112726. * @param startPoint - the starting point of the curve
  112727. * @param endPoint - the ending point of the curve
  112728. * @param bulge - a value indicating how much to curve
  112729. * @param segments - number of segments between the two given points
  112730. */
  112731. THREEx.BulgeGeometry = function ( startPoint, endPoint, bulge, segments ) {
  112732. var vertex, i,
  112733. center, p0, p1, angle,
  112734. radius, startAngle,
  112735. thetaAngle;
  112736. Geometry.call( this );
  112737. this.startPoint = p0 = startPoint ? new Vector2(startPoint.x, startPoint.y) : new Vector2(0,0);
  112738. this.endPoint = p1 = endPoint ? new Vector2(endPoint.x, endPoint.y) : new Vector2(1,0);
  112739. this.bulge = bulge = bulge || 1;
  112740. angle = 4 * Math.atan(bulge);
  112741. radius = p0.distanceTo(p1) / 2 / Math.sin(angle/2);
  112742. center = THREEx.Math.polar(startPoint, radius, THREEx.Math.angle2(p0,p1) + (Math.PI / 2 - angle/2));
  112743. this.segments = segments = segments || Math.max( Math.abs(Math.ceil(angle/(Math.PI/18))), 6); // By default want a segment roughly every 10 degrees
  112744. startAngle = THREEx.Math.angle2(center, p0);
  112745. thetaAngle = angle / segments;
  112746. this.vertices.push(new Vector3(p0.x, p0.y, 0));
  112747. for(i = 1; i <= segments - 1; i++) {
  112748. vertex = THREEx.Math.polar(center, Math.abs(radius), startAngle + thetaAngle * i);
  112749. this.vertices.push(new Vector3(vertex.x, vertex.y, 0));
  112750. }
  112751. };
  112752. THREEx.BulgeGeometry.prototype = Object.create( Geometry.prototype );
  112753. /* -----note--------------
  112754. */
  112755. const manager = new LoadingManager();
  112756. let loaders = {};
  112757. let mapArea;
  112758. let shelterHistory = [];
  112759. Potree.isIframeChild = window.parent!=window; //子页面
  112760. /* if(Potree.isIframeChild){
  112761. let rootWin = Common.getRootWindow()
  112762. rootWin && rootWin.viewer.dispatchEvent({type:'createIframe', window}) //给祖先页面发送信息,得不到可能跨域了或无viewer
  112763. } */
  112764. /* window.addEventListener('focus',()=>{
  112765. console.log('focus',window.winIndex)
  112766. })
  112767. window.addEventListener('blur',()=>{
  112768. console.log('blur',window.winIndex)
  112769. }) */
  112770. class Viewer extends ViewerBase{
  112771. constructor(domElement, mapArea_, args = {}){
  112772. super(domElement, $.extend(args,{name:'mainViewer', antialias:true, preserveDrawingBuffer:true}));
  112773. //注:viewer因为要分屏,尤其是四屏,preserveDrawingBuffer需要为true, 否则无法局部clear
  112774. window.viewer = this;
  112775. mapArea = mapArea_;
  112776. if(Potree.settings.editType == "pano" || Potree.settings.editType == "merge"){
  112777. this.modules = {
  112778. Alignment,
  112779. SiteModel,
  112780. volumeComputer: new VolumeComputer //暂时
  112781. };
  112782. Potree.settings.useDepthTex = false;
  112783. if(Potree.settings.editType == "pano" ){
  112784. this.modules.PanoEditor = PanoEditor$1;
  112785. }else if(Potree.settings.editType == "merge"){
  112786. this.modules.MergeEditor = MergeEditor;
  112787. this.modules.CamAniEditor = CamAniEditor;
  112788. }
  112789. }else {
  112790. this.modules = {
  112791. Clip,
  112792. Alignment,
  112793. SiteModel,
  112794. RouteGuider : new RouteGuider,
  112795. clipping: new Clipping,
  112796. ParticleEditor,
  112797. CamAniEditor,
  112798. volumeComputer: new VolumeComputer,
  112799. MergeEditor
  112800. };
  112801. }
  112802. {
  112803. Potree.timeCollect = {
  112804. //median预置一个中等值,以防止cpu过低的设备首次卡顿
  112805. //depthSampler : {minCount:400, median: 1}, //旧的 实时从图片中获取色值的用时,但是现在直接从data中取
  112806. depthSamChangeImg:{minCount:200, median: 25} //换图的用时。 需要一开始就start
  112807. };
  112808. for(let i in Potree.timeCollect){
  112809. Potree.timeCollect[i].measures = [];
  112810. Potree.timeCollect[i].sum = 0;
  112811. }
  112812. setTimeout(()=>{
  112813. for(let i in Potree.timeCollect){
  112814. Potree.timeCollect[i].start = true;
  112815. }
  112816. /* setTimeout(()=>{
  112817. console.log('timeCollect', Potree.timeCollect.depthSampler.median, Potree.timeCollect.depthSampler.ave, Potree.timeCollect.depthSampler.measures.length)
  112818. },10000) */
  112819. },2000);
  112820. }
  112821. this.navigateMode = 'free'; // 'panorama'; 'free'自由模式是只显示点云或者未进入到漫游点,
  112822. this.isEdit = true;
  112823. this.waitQueue = [];
  112824. this.unitConvert = new UoMService();
  112825. this.visible = true;
  112826. this.fpVisiDatasets = [];
  112827. this.atDatasets = [];
  112828. this.objs = new Object3D;
  112829. this.testMaxNodeCount = 0;
  112830. this.tiles3dVisiVCount = 0;
  112831. //this.lastPos = new THREE.Vector3(Infinity,Infinity,Infinity)
  112832. //-------------
  112833. var supportExtFragDepth = !!Potree.Features.EXT_DEPTH.isSupported(this.renderer.getContext()) ;//iphoneX居然不支持
  112834. //这意味着边缘增强和测量线遮挡失效
  112835. if(!supportExtFragDepth)console.error('ExtFragDepth unsupported! 边缘增强和测量线遮挡失效');
  112836. this.guiLoaded = false;
  112837. this.guiLoadTasks = [];
  112838. this.onVrListeners = [];
  112839. this.messages = [];
  112840. this.elMessages = $(`
  112841. <div id="message_listing"
  112842. style="position: absolute; z-index: 1000; left: 10px; bottom: 10px">
  112843. </div>`);
  112844. $(domElement).append(this.elMessages);
  112845. this.fakeMeasure = {};
  112846. try{
  112847. if(!Potree.settings.isOfficial)
  112848. { // generate missing dom hierarchy
  112849. if ($(domElement).find('#potree_map').length === 0) {
  112850. let potreeMap = $(`
  112851. <div id="potree_map" class="mapBox" style="position: absolute; left: 50px; top: 50px; width: 400px; height: 400px; display: none">
  112852. <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;">
  112853. </div>
  112854. <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>
  112855. </div>
  112856. `);
  112857. $(domElement).append(potreeMap);
  112858. }
  112859. if ($(domElement).find('#potree_description').length === 0) {
  112860. let potreeDescription = $(`<div id="potree_description" class="potree_info_text"></div>`);
  112861. $(domElement).append(potreeDescription);
  112862. }
  112863. if ($(domElement).find('#potree_annotations').length === 0) {
  112864. let potreeAnnotationContainer = $(`
  112865. <div id="potree_annotation_container"
  112866. style="position: absolute; z-index: 100000; width: 100%; height: 100%; pointer-events: none;"></div>`);
  112867. $(domElement).append(potreeAnnotationContainer);
  112868. }
  112869. if ($(domElement).find('#potree_quick_buttons').length === 0) {
  112870. let potreeMap = $(`
  112871. <div id="potree_quick_buttons" class="quick_buttons_container" style="">
  112872. </div>
  112873. `);
  112874. $(domElement).append(potreeMap);
  112875. }
  112876. //add
  112877. {
  112878. $(domElement).append($("<div id='potree_labels'></div>"));
  112879. if(!mapArea && (Potree.settings.editType != 'merge' /* || Potree.settings.showObjectsOnMap */)){
  112880. mapArea = $("<div id='mapGaode'></div>");
  112881. $(domElement).append(mapArea);
  112882. mapArea = mapArea[0];
  112883. }
  112884. }
  112885. /* let domRoot = this.renderer.domElement.parentElement;
  112886. let elAttach = $("<input type='button' value='test'></input>");
  112887. elAttach.css({
  112888. position : "absolute",
  112889. right : '10%',
  112890. bottom: '20px',
  112891. zIndex: "10000",
  112892. fontSize:'1em', color:"black",
  112893. background:'rgba(255,255,255,0.8)',
  112894. })
  112895. let state = false
  112896. elAttach.on("click", () => {
  112897. window.buttonFunction && window.buttonFunction()
  112898. });
  112899. domRoot.appendChild(elAttach[0]); */
  112900. }
  112901. this.tiles3dMemoryUsage = 0;
  112902. this.pointCloudLoadedCallback = args.onPointCloudLoaded || function () {};
  112903. // if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  112904. // defaultSettings.navigation = "Orbit";
  112905. // }
  112906. this.server = null;
  112907. this.fov = 60;
  112908. this.isFlipYZ = false;
  112909. this.useDEMCollisions = false;
  112910. this.generateDEM = false;
  112911. this.minNodeSize = 30; //允许加载的node的最小可见像素宽度。越大越省性能
  112912. this.edlStrength = 1.0;
  112913. this.edlRadius = 1.4;
  112914. this.edlOpacity = 1.0;
  112915. this.useEDL = false;
  112916. this.description = "";
  112917. this.classifications = ClassificationScheme.DEFAULT;
  112918. this.moveSpeed = 1;
  112919. this.lengthUnit = LengthUnits.METER;
  112920. this.lengthUnitDisplay = LengthUnits.METER;
  112921. this.showBoundingBox = false;
  112922. this.showAnnotations = true;
  112923. this.freeze = false;
  112924. this.elevationGradientRepeat = ElevationGradientRepeat.CLAMP;
  112925. this.filterReturnNumberRange = [0, 7];
  112926. this.filterNumberOfReturnsRange = [0, 7];
  112927. this.filterGPSTimeRange = [-Infinity, Infinity];
  112928. this.filterPointSourceIDRange = [0, 65535];
  112929. this.potreeRenderer = null;
  112930. this.edlRenderer = null;
  112931. this.pRenderer = null;
  112932. this.scene = null;
  112933. this.sceneVR = null;
  112934. this.overlay = null;
  112935. this.overlayCamera = null;
  112936. this.inputHandler = null;
  112937. this.controls = null;
  112938. this.clippingTool = null;
  112939. this.transformationTool = null;
  112940. this.navigationCube = null;
  112941. this.compass = null;
  112942. this.skybox = null;
  112943. this.clock = new Clock();
  112944. this.background = null;
  112945. this.buffers = new Map;
  112946. if(args.noDragAndDrop){
  112947. }else {
  112948. this.initDragAndDrop();
  112949. }
  112950. if(typeof Stats !== "undefined"){
  112951. this.stats = new Stats();
  112952. this.stats.showPanel( 0 ); // 0: fps, 1: ms, 2: mb, 3+: custom
  112953. document.body.appendChild( this.stats.dom );
  112954. }
  112955. {
  112956. this.overlay = new Scene();
  112957. this.overlayCamera = new OrthographicCamera(
  112958. 0, 1,
  112959. 1, 0,
  112960. -1000, 1000
  112961. );
  112962. }
  112963. this.pRenderer = new Renderer$1(this.renderer);
  112964. {
  112965. let near = 2.5;
  112966. let far = 10.0;
  112967. let fov = 90;
  112968. this.shadowTestCam = new PerspectiveCamera(90, 1, near, far);
  112969. this.shadowTestCam.position.set(3.50, -2.80, 8.561);
  112970. this.shadowTestCam.lookAt(new Vector3(0, 0, 4.87));
  112971. }
  112972. let scene = new ExtendScene(this.renderer);
  112973. { // create VR scene
  112974. this.sceneVR = new Scene();
  112975. // let texture = new THREE.TextureLoader().load(`${Potree.resourcePath}/images/vr_controller_help.jpg`);
  112976. // let plane = new THREE.PlaneBufferGeometry(1, 1, 1, 1);
  112977. // let infoMaterial = new THREE.MeshBasicMaterial({map: texture});
  112978. // let infoNode = new THREE.Mesh(plane, infoMaterial);
  112979. // infoNode.position.set(-0.5, 1, 0);
  112980. // infoNode.scale.set(0.4, 0.3, 1);
  112981. // infoNode.lookAt(0, 1, 0)
  112982. // this.sceneVR.add(infoNode);
  112983. // window.infoNode = infoNode;
  112984. }
  112985. this.setScene(scene);
  112986. //add: for 截图时抗锯齿
  112987. {
  112988. /* this.composer = new EffectComposer( this.renderer );
  112989. this.ssaaRenderPass = new SSAARenderPass(0x000000, 0);
  112990. this.composer.addPass( this.ssaaRenderPass );
  112991. */
  112992. //this.ssaaRenderPass.useCopy = true
  112993. //this.ssaaRenderPass.renderToScreen = true;
  112994. //this.ssaaRenderPass.needsSwap = false
  112995. //见 https://threejs.org/examples/?q=AA#webgl_postprocessing_fxaa 效果和SSAA差不多,都对透明不太友好。
  112996. /* let outlinePass = this.outlinePass = new OutlinePass( );
  112997. this.ssaaRenderPass.addPass(outlinePass)
  112998. */
  112999. //ssaa有透明度、发黑的问题所以不用了
  113000. //--------------------------
  113001. this.composer = new EffectComposer( this.renderer );
  113002. this.composer.scaleRatio = 4; //将底图和测量线绘制在一张高倍贴图上,for测量线不模糊
  113003. this.composer.readTarget = true; //把底图和测量线一起fxaa
  113004. /* const renderPass = new RenderPass();
  113005. //renderPass.clearColor = new THREE.Color( 0,0,0 );
  113006. //renderPass.clearAlpha = 0;
  113007. renderPass.clear = !this.composer.readTarget
  113008. this.composer.addPass( renderPass );
  113009. */
  113010. //for 融合页面
  113011. let outlinePass = this.outlinePass = new OutlinePass( );
  113012. outlinePass.renderToScreen = true; //这样更流畅,不用ssaa了,缺点是outline有锯齿
  113013. outlinePass.enabled = false;
  113014. this.composer.addPass( outlinePass );
  113015. outlinePass.edgeStrength = 4;
  113016. outlinePass.edgeGlow = 0;
  113017. outlinePass.visibleEdgeColor = new Color("#09a1b3");
  113018. /* this.fxaaPass = new ShaderPass( FXAAShader );
  113019. this.fxaaPass.readTarget = true //add
  113020. this.fxaaPass.setSize = function(width, height){
  113021. this.material.uniforms[ 'resolution' ].value.x = 1 / ( width ) ;
  113022. this.material.uniforms[ 'resolution' ].value.y = 1 / ( height ) ;
  113023. }
  113024. this.fxaaPass.renderToScreen = true;
  113025. this.composer.addPass( this.fxaaPass ); */
  113026. //抗锯齿截图 效果时而好时而不好,文字比较模糊
  113027. //这两个暂时不能一起用。目前刚好不需要一起用
  113028. /* this.images360.fastTranMaskPass = new FastTranPass( this.renderer )
  113029. this.composer.addPass(this.images360.fastTranMaskPass)//add */
  113030. }
  113031. {
  113032. this.mainViewport = new Viewport( this.scene.view, this.scene.cameraP, {
  113033. left:0, bottom:0, width:1, height: 1, name:'MainView'
  113034. });
  113035. this.viewports = [this.mainViewport];
  113036. Potree.settings.showCompass && (this.compass = new Compass(Potree.settings.compassDom, this.mainViewport));
  113037. //this.axis = new AxisViewer(this.mainViewport, this.renderArea )
  113038. this.magnifier = new Magnifier(this);
  113039. this.reticule = new Reticule(this);
  113040. this.scene.scene.add(this.magnifier);
  113041. this.scene.scene.add(this.reticule);
  113042. if(Potree.settings.editType != "pano" && (Potree.settings.editType != 'merge' /* || Potree.settings.showObjectsOnMap */)){
  113043. this.mapViewer = new MapViewer(mapArea/* $('#mapGaode')[0] */);
  113044. }
  113045. this.inputHandler = new InputHandler(this, this.scene.scene);
  113046. this.inputHandler.containsMouse = true;//初始化,使键盘事件在mainViewer有效
  113047. //this.inputHandler.setScene(this.scene);
  113048. //this.inputHandler.addInputListener(this);//add
  113049. this.clippingTool = new ClippingTool(this);
  113050. this.transformationTool = new TransformationTool(this);
  113051. this.navigationCube = new NavigationCube(this);
  113052. this.navigationCube.visible = false;
  113053. this.createControls();
  113054. this.clippingTool.setScene(this.scene);
  113055. let onPointcloudAdded = (e) => {
  113056. if (this.scene.pointclouds.length === 1) {
  113057. let speed = e.pointcloud.boundingBox.getSize(new Vector3()).length();
  113058. speed = speed / 2000;
  113059. this.setMoveSpeed(speed);
  113060. }
  113061. };
  113062. let onVolumeRemoved = (e) => {
  113063. this.inputHandler.deselect(e.volume);
  113064. };
  113065. this.addEventListener('scene_changed', (e) => {
  113066. this.inputHandler.setScene(e.scene);
  113067. this.clippingTool.setScene(this.scene);
  113068. if(!e.scene.hasEventListener("pointcloud_added", onPointcloudAdded)){
  113069. e.scene.addEventListener("pointcloud_added", onPointcloudAdded);
  113070. }
  113071. if(!e.scene.hasEventListener("volume_removed", onPointcloudAdded)){
  113072. e.scene.addEventListener("volume_removed", onVolumeRemoved);
  113073. }
  113074. });
  113075. this.scene.addEventListener("volume_removed", onVolumeRemoved);
  113076. this.scene.addEventListener('pointcloud_added', onPointcloudAdded);
  113077. }
  113078. { // set defaults
  113079. this.setFOV(60);
  113080. this.setEDLEnabled(false);
  113081. this.setEDLRadius(3);
  113082. this.setEDLStrength(0.01);
  113083. this.setEDLOpacity(1.0);
  113084. this.setPointBudget(1*1000*1000);
  113085. this.setShowBoundingBox(false);
  113086. this.setFreeze(false);
  113087. this.setControls(this.fpControls/* orbitControls */);
  113088. this.setBackground( new Color(Potree.config.background),1 /* 'gradient' */ );
  113089. this.scaleFactor = 1;
  113090. this.loadSettingsFromURL();
  113091. }
  113092. // start rendering!
  113093. //if(args.useDefaultRenderLoop === undefined || args.useDefaultRenderLoop === true){
  113094. //requestAnimationFrame(this.loop.bind(this));
  113095. //}
  113096. this.renderer.setAnimationLoop(this.loop.bind(this));
  113097. this.loadGUI = this.loadGUI.bind(this);
  113098. this.annotationTool = new AnnotationTool(this);
  113099. this.measuringTool = new MeasuringTool(this);
  113100. //this.profileTool = new ProfileTool(this);
  113101. this.volumeTool = new VolumeTool(this);
  113102. this.tagTool = new TagTool(this);
  113103. //-----------
  113104. CursorDeal.init(this, this.mapViewer ? [this, this.mapViewer] : [this]);//ADD
  113105. if(Potree.settings.editType == "pano"){
  113106. this.modules.PanoEditor.init();
  113107. }else if(Potree.settings.editType == "merge"){
  113108. this.modules.MergeEditor.init();
  113109. }else {
  113110. this.modules.SiteModel.init();
  113111. this.modules.ParticleEditor.init();
  113112. }
  113113. this.modules.Alignment.init();
  113114. this.images360 = new Images360(this);
  113115. this.scene.scene.add(this.objs);
  113116. loaders = {
  113117. objLoader : new OBJLoader( manager ),
  113118. mtlLoader : new MTLLoader( manager ),
  113119. glbLoader : new GLTFLoader(undefined, this.renderer, Potree.settings.libsUrl ),
  113120. plyLoader : new PLYLoader( manager ),
  113121. dxfLoader : new DxfLoader(),
  113122. shapeLoader: new Potree.ShapefileLoader()
  113123. };
  113124. //add test
  113125. /* const environment = new RoomEnvironment();
  113126. const pmremGenerator = new THREE.PMREMGenerator( this.renderer );
  113127. this.scene.scene.environment = pmremGenerator.fromScene( environment ).texture;
  113128. */
  113129. //-----------
  113130. this.modules.volumeComputer && this.modules.volumeComputer.init();
  113131. }catch(e){
  113132. this.onCrash(e);
  113133. }
  113134. //-----------------------add----------------------------------------------------
  113135. /* {
  113136. let ratio
  113137. this.addEventListener('resize',(e)=>{
  113138. if(ratio != e.deviceRatio){ //因为devicePixelRatio会影响到点云大小,所以改变时计算下点云大小
  113139. viewer.scene.pointclouds.forEach(p => {
  113140. p.changePointSize()
  113141. })
  113142. }
  113143. ratio = e.deviceRatio
  113144. })
  113145. } */
  113146. {
  113147. let pointDensity = '';
  113148. Object.defineProperty(Potree.settings , "pointDensity",{
  113149. get: function() {
  113150. return pointDensity
  113151. },
  113152. set: (density)=>{
  113153. if(density){
  113154. let config = Potree.config.pointDensity[density];
  113155. let pointBudget = config.pointBudget;
  113156. if(density == 'magnifier'){//尽可能不变pointBudget,否则点云可能会闪烁,因点云被释放又加载,如SS-t-7DUfWAUZ3V
  113157. pointBudget = Math.max(Potree.pointBudget, Potree.config.pointDensity['magnifier'].pointBudget);
  113158. }else if(this.magnifier.visible){//放大镜打开时要保证最低点云数量(全景模式没点)
  113159. pointBudget = Math.max(pointBudget, Potree.config.pointDensity['magnifier'].pointBudget);
  113160. }
  113161. viewer.setMinNodeSize(config.minNodeSize || Potree.config.minNodeSize);
  113162. viewer.setPointBudget(pointBudget );
  113163. pointDensity = density;
  113164. this.setPointLevels();
  113165. this.dispatchEvent('pointDensityChanged');
  113166. }
  113167. }
  113168. });
  113169. let UserPointDensity = '';
  113170. Object.defineProperty(Potree.settings , "UserPointDensity",{
  113171. get: function() {
  113172. return UserPointDensity
  113173. },
  113174. set: (density)=>{
  113175. if(UserPointDensity != density){
  113176. if(Potree.settings.displayMode == 'showPointCloud' && this.viewports.length != 4){//漫游模式和四屏时都有自己的pointDensity
  113177. Potree.settings.pointDensity = density;
  113178. }
  113179. UserPointDensity = density;
  113180. this.dispatchEvent('UserPointDensityChanged');
  113181. }
  113182. }
  113183. });
  113184. }
  113185. {
  113186. let cameraFar = Potree.settings.cameraFar;
  113187. Object.defineProperty(Potree.settings , "cameraFar",{
  113188. get: function() {
  113189. return cameraFar
  113190. },
  113191. set: (far)=>{
  113192. if(far != cameraFar){
  113193. if(Potree.settings.displayMode != 'showPanos' && !this.fixCamFar){
  113194. this.mainViewport.camera.far = far;
  113195. this.mainViewport.camera.updateProjectionMatrix();
  113196. }
  113197. cameraFar = far;
  113198. }
  113199. }
  113200. });
  113201. }
  113202. /* this.reticule.addEventListener('update',(e)=>{
  113203. this.needRender = true
  113204. if(this.mapViewer && this.mapViewer.attachedToViewer)this.mapViewer.needRender = true //分屏时mapViewer也有reticule
  113205. }) */
  113206. this.reticule.addEventListener('update',(e)=>{
  113207. this.reticule.hoverViewport && (this.reticule.hoverViewport.needRender = true);
  113208. this.lazyRenderViewports();
  113209. if(this.mapViewer && this.mapViewer.attachedToViewer &&
  113210. (this.mapViewer.viewports[0].needRender || this.needRender ) ) this.mapViewer.needRender = true; //分屏时mapViewer也有reticule
  113211. });
  113212. this.addEventListener('pointcloud_changed',(e)=>{
  113213. if(this.screenshoting){
  113214. this.viewports.filter(e=>!e.noPointcloud).forEach(e =>e.needRender = true);
  113215. }
  113216. else this.lazyRenderViewports();
  113217. });
  113218. this.addEventListener('allLoaded', ()=>{
  113219. setTimeout(this.testPointcloudsMaxLevel.bind(this), 1000); //延迟一丢丢,等画面出现
  113220. this.scene.pointclouds.forEach(pointcloud=>{
  113221. pointcloud.addEventListener('isVisible',(e)=>{//是否显示该点的mesh(不显示也能走)
  113222. //console.log('pointcloud isVisible', this.id, e.visible)
  113223. if(e.reason != 'displayMode' && e.reason != 'overlinePass'){
  113224. this.updateModelBound('visibleChanged');
  113225. }
  113226. this.dispatchEvent('pointcloud_changed');
  113227. });
  113228. pointcloud.material.addEventListener('material_property_changed',()=>{
  113229. this.dispatchEvent('pointcloud_changed');
  113230. });
  113231. });
  113232. window.addEventListener('unfocusPage',(e)=>{
  113233. console.log('unfocusPage',document.title);
  113234. this.setDisplay(false);
  113235. });
  113236. window.addEventListener('focusPage',(e)=>{
  113237. console.log('focusPage',document.title);
  113238. this.setDisplay(true);
  113239. });
  113240. });
  113241. if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
  113242. this.addEventListener('switchFloorplanSelect',(e)=>{//进入平面图设置后 切换选中的数据集
  113243. this.selectedFloorplan = e.pointcloud; //绝对显示
  113244. this.updateFpVisiDatasets();
  113245. let pointclouds;
  113246. if(e.pointcloud){
  113247. pointclouds = [e.pointcloud];
  113248. }else if(this.fpVisiDatasets.length){
  113249. pointclouds = this.fpVisiDatasets;
  113250. }
  113251. pointclouds && this.mapViewer.fitToDatasets(pointclouds);
  113252. });
  113253. this.modules.SiteModel.bus.addEventListener('FloorChange',(e)=>{
  113254. this.updateFpVisiDatasets();
  113255. this.updatePanosVisibles(e.currentFloor); //问:编辑空间模型时,需不需要改为显示当前选择的楼层。因为若所在楼层和选中的不一致,修改选中楼层的轮廓却改不了marker显示很奇怪,尤其刚好在一个建筑内时。
  113256. });
  113257. this.mapViewer.mapLayer.addEventListener('floorplanLoaded',()=>{
  113258. this.updateCadVisibles(this.fpVisiDatasets, true); //加载完成后重新更新下
  113259. });
  113260. /* this.modules.Clip.bus.addEventListener('updateSelectedDatasets',()=>{
  113261. this.updateFpVisiDatasets()
  113262. }) */
  113263. }
  113264. {
  113265. let updated, zoomLevel;
  113266. let update = (e)=>{
  113267. if(e.type == 'updateModelBound' || e.viewport == this.mainViewport && (e.changeInfo.positionChanged || zoomLevel != this.images360.zoomLevel)){
  113268. zoomLevel = this.images360.zoomLevel; //对updateMarkerVisibles有影响
  113269. //e.changeInfo.positionChanged && shelterHistory.clear() //清空
  113270. (e.type == 'updateModelBound' || e.changeInfo.positionChanged) && this.updateDatasetAt(); //更新所在数据集
  113271. if(Potree.settings.ifShowMarker && Potree.settings.editType != 'merge'){
  113272. Common. intervalTool.isWaiting('updateMarkerVisibles', ()=>{
  113273. if(!this.mainViewport.view.isFlying() ){
  113274. this.updateMarkerVisibles();
  113275. }
  113276. },500);
  113277. }
  113278. }
  113279. };
  113280. this.addEventListener('camera_changed', update);
  113281. this.addEventListener('updateModelBound', update);
  113282. this.addEventListener('showMarkerChanged',()=>{
  113283. this.updatePanosVisibles(this.modules.SiteModel.currentFloor);
  113284. this.updateMarkerVisibles();
  113285. });
  113286. /* if(!Potree.Features.EXT_DEPTH.isSupported()){
  113287. this.images360.addEventListener('endChangeMode',(e)=>{
  113288. if(e.mode == 'showPanos'){
  113289. this.updateMarkerVisibles()
  113290. }
  113291. }) */
  113292. this.images360.addEventListener('getNeighbourAuto',(e)=>{
  113293. if(/* Potree.settings.displayMode == 'showPanos' && */e.panos.includes(this.images360.currentPano)){
  113294. Common.intervalTool.isWaiting('updateMarkerVisibles', ()=>{
  113295. this.updateMarkerVisibles();
  113296. },500);
  113297. }
  113298. });
  113299. /* } */
  113300. }
  113301. {
  113302. let interval;
  113303. document.addEventListener('visibilitychange',(e)=>{
  113304. let v = !document.hidden;
  113305. //console.warn('visibilitychange', v )
  113306. this.dispatchEvent({type:'pageVisible', v } );
  113307. if(this.screenshoting && !v){//截图过程中离开页面需要照常loop。但是尽量别离开页面,效果只能达到90%
  113308. interval = setInterval(()=>{
  113309. //console.log('force loop', Date.now())
  113310. if(this.screenshoting){ //截图完成时如果还没回来就不loop
  113311. this.loop(Date.now());
  113312. }
  113313. },50); //实际>1000, 浏览器会放慢定时器,放慢多少不确定
  113314. }else if(v && interval){
  113315. clearInterval(interval);
  113316. }
  113317. });
  113318. }
  113319. /* if(!Potree.isIframeChild){
  113320. window.winIndex = 0;
  113321. let index = 1;
  113322. this.addEventListener('createIframe',(e)=>{//创建了子页面
  113323. let child = e.window;
  113324. child.winIndex = index ++;
  113325. })
  113326. //不知道删除iframe时是否那些模型还在内存里,需要释放吗? 如果要需要加一个事件
  113327. } */
  113328. /* {
  113329. let setInteract = ()=>{
  113330. this.interacted = true //标记这一帧用户有操作屏幕
  113331. }
  113332. this.addEventListener('global_mousedown', setInteract)
  113333. this.addEventListener('global_touchmove', setInteract)
  113334. this.addEventListener('global_mousewheel', setInteract)
  113335. }
  113336. {//针对数据集偏离中心很远后产生的精度损失而抖动
  113337. this.addEventListener('camera_changed', e => {
  113338. if(e.viewport == this.mainViewport && (e.changeInfo.positionChanged)){
  113339. if(Potree.settings.editType != 'merge' && Potree.settings.editType != 'pano'){
  113340. if(!this.mainViewport.view.isFlying() ){
  113341. let pos = this.mainViewport.view.position.clone() // this.mainViewport.camera.getWorldPosition(new THREE.Vector3)
  113342. if(pos.lengthSq() > 25000000){
  113343. Common.intervalTool.isWaiting('moveWorldCenter', ()=>{
  113344. pos = this.mainViewport.view.position.clone()
  113345. this.mainViewport.view.translateWorld(-pos.x, -pos.y, -pos.z)
  113346. this.scene.scene.position.sub(pos)
  113347. console.log('变位置', pos)
  113348. this.scene.pointclouds.forEach(cloud=>{
  113349. Alignment.setMatrix(cloud)
  113350. })
  113351. },500)
  113352. }
  113353. }
  113354. }
  113355. }
  113356. })
  113357. }*/
  113358. }
  113359. lazyRenderViewports(updateCount){
  113360. //本来要写this.needRender = true的, 但在分四个屏时防止太卡而排队render
  113361. let viewports = this.viewports;
  113362. if(viewports.length == 1 || this.needRender){
  113363. return this.needRender = true
  113364. }
  113365. const maxWaitTime = 200;
  113366. let now = Date.now();
  113367. let maxRenderCount = 1;
  113368. viewports.forEach(e=>{
  113369. if(now - e.lastRenderTime > maxWaitTime){
  113370. e.needRender = true;
  113371. }
  113372. });
  113373. let renderCount = viewports.filter(e=>e.needRender).length;
  113374. //console.log('renderCount', renderCount)
  113375. let list = viewports.filter(e=>!e.needRender).sort((a,b)=>a.lastRenderTime - b.lastRenderTime);//没有准备render的,按上次渲染时间排序,作为候补
  113376. if(renderCount < maxRenderCount){ //还有名额,补齐
  113377. list.slice(0, maxRenderCount - renderCount).forEach(e=>{
  113378. e.needRender = true;
  113379. });
  113380. }else if(list[0] && now - list[0].lastRenderTime > maxWaitTime){//名额不足时,考虑候补队列第一个是否超时,超时的话也渲染
  113381. list[0].needRender = true;
  113382. }
  113383. }
  113384. ifPointBlockedByIntersect(point , panoId, soon ){//点是否被遮挡
  113385. let ifShelter;
  113386. let now = Date.now();
  113387. let extraPanoId = panoId != void 0;
  113388. if(!this.shelterCount)return
  113389. let history = shelterHistory.find(e=>e.point.equals(point));
  113390. let cameraPos = this.mainViewport.view.position.clone();
  113391. if(panoId == void 0){
  113392. if(this.images360.isAtPano(0.05)){
  113393. panoId = this.images360.currentPano.id;
  113394. }
  113395. }
  113396. if(history){
  113397. if(panoId != void 0){
  113398. ifShelter = history.panos[panoId];
  113399. }else {
  113400. if(history.notAtPano.cameraPos && history.notAtPano.cameraPos.equals(cameraPos)){
  113401. ifShelter = history.notAtPano.ifShelter;
  113402. }
  113403. }
  113404. let index = shelterHistory.indexOf(history); //先取出,稍后放回
  113405. shelterHistory.splice(index, 1);
  113406. }else {//新增
  113407. history = {point, panos:{}, notAtPano:{}};
  113408. const minCount = 100;
  113409. if(shelterHistory.length > minCount){//去除最早的
  113410. let old;
  113411. while(old = shelterHistory[0], now - old.lastTime > 1000){//因为不知热点个数,所以需要加上时间限制,超过时间才能删。
  113412. if(old == history || shelterHistory.length == minCount)break;
  113413. shelterHistory.splice(0,1);
  113414. //console.log('delete')
  113415. }
  113416. }
  113417. }
  113418. if(ifShelter == void 0){
  113419. delete history.waitCompute;
  113420. if(this.mainViewport.view.isFlying()){
  113421. return useLastResult()
  113422. }
  113423. if(panoId != void 0){
  113424. let pano = this.images360.getPano(panoId);
  113425. if((soon || this.shelterCount.byTex<this.shelterCount.maxByTex) && pano.depthTex){
  113426. ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point, margin:Potree.config.shelterMargin, useDepthTex:true, pano, viewport:this.mainViewport } );
  113427. history.panos[panoId] = ifShelter;
  113428. this.shelterCount.byTex ++ ;
  113429. //console.log('computeByTex direct', panoId, point, ifShelter)
  113430. }else {
  113431. //console.log('延迟tex',panoId, point )
  113432. history.waitCompute = {panoId, forceGet:extraPanoId };
  113433. return useLastResult()
  113434. }
  113435. }else {
  113436. if(/* history.ifShelter == void 0 || */ this.shelterCount.byCloud<this.shelterCount.maxByCloud){//弊端:第一个总是直接计算,后面的都是延后。但无法改进,因是一个个传进来的,无法预测。
  113437. ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point, margin:Potree.config.shelterMargin, pickWindowSize:3} );
  113438. history.notAtPano = {cameraPos , ifShelter };
  113439. this.shelterCount.byCloud ++ ;
  113440. //console.log('computeByCloud direct', point.toArray())
  113441. }else {
  113442. //console.log('延迟cloud' )
  113443. history.waitCompute = {cameraPos};
  113444. return useLastResult()
  113445. }
  113446. }
  113447. }
  113448. history.ifShelter = ifShelter;
  113449. history.lastTime = now;
  113450. shelterHistory.push(history); //最新使用的保持在最后一个,使队列按照从旧到新排列
  113451. function useLastResult(){//暂时先用上一次的值
  113452. shelterHistory.push(history);
  113453. history.lastTime = now;
  113454. return history.ifShelter
  113455. }
  113456. return ifShelter
  113457. }
  113458. computeShelter(){
  113459. //先算用深度图的,然后再点云;
  113460. //let depthTiming = Potree.timeCollect.depthSampler.median
  113461. let byTex=0, byCloud=0;
  113462. let len = shelterHistory.length;
  113463. let waitCloud = [];
  113464. let maxTexCount = Common.getBestCount('shelterMaxDepthSample', 1, 50, 1, 13 /* ,true */ );
  113465. for(let i=len-1; i>=0; i--){
  113466. let history = shelterHistory[i];
  113467. if(history.waitCompute){
  113468. if(history.waitCompute.panoId != void 0){
  113469. if(!history.waitCompute.forceGet && (history.waitCompute.panoId != this.images360.currentPano.id || !this.images360.isAtPano(0.1))){
  113470. delete history.waitCompute; //取消计算
  113471. }else {
  113472. if(this.images360.currentPano.depthTex){
  113473. if(byTex >= maxTexCount)break
  113474. byTex ++;
  113475. let ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point:history.point, margin:Potree.config.shelterMargin, useDepthTex:true, viewport:this.mainViewport } );
  113476. history.panos[this.images360.currentPano.id] = ifShelter;
  113477. history.ifShelter = ifShelter;
  113478. delete history.waitCompute;
  113479. //console.log('补1', history.point.toArray())
  113480. }else {
  113481. if(this.images360.currentPano.pointcloud.hasDepthTex){
  113482. //先等待加载完深度图
  113483. }else {
  113484. waitCloud.push(history);
  113485. }
  113486. }
  113487. }
  113488. }else {
  113489. waitCloud.push(history);
  113490. }
  113491. }
  113492. }
  113493. let maxCloudCount;
  113494. if(byTex < maxTexCount && waitCloud.length ){
  113495. maxCloudCount = this.lastFrameChanged ? Common.getBestCount('shelterMaxCloud', 0, 2, 4, 8 /* ,true */ ) : 5;
  113496. let waitCloud2 = [];
  113497. if(maxCloudCount){
  113498. for(let i=0; i<waitCloud.length; i++){
  113499. let history = waitCloud[i];
  113500. if(history.waitCompute.cameraPos){
  113501. if(!viewer.mainViewport.view.position.equals(history.waitCompute.cameraPos)){
  113502. delete history.waitCompute;
  113503. //console.log('delete history.waitCompute', history)
  113504. continue; //取消计算
  113505. }else {
  113506. waitCloud2.push(history);
  113507. }
  113508. }else {
  113509. waitCloud2.push(history);
  113510. }
  113511. }
  113512. let list = waitCloud2.map(e=>e.point);
  113513. let result = Common.batchHandling.getSlice('shelterByCloud', list, {maxUseCount:maxCloudCount,useEquals:true, stopWhenAllUsed:true} ); //iphonex稳定后大概在7-10。
  113514. //list.length>0 && console.log('list',list, maxCloudCount)
  113515. result.list.forEach(e=>{
  113516. let history = waitCloud2.find(a=>a.point.equals(e));
  113517. let ifShelter = !!viewer.inputHandler.ifBlockedByIntersect({point:history.point, margin: Potree.config.shelterMargin , pickWindowSize:3, viewport:this.mainViewport} );
  113518. if(history.waitCompute.cameraPos){
  113519. history.notAtPano = {cameraPos: history.waitCompute.cameraPos , ifShelter };
  113520. }else {
  113521. history.panos[this.images360.currentPano.id] = ifShelter;
  113522. }
  113523. history.ifShelter = ifShelter;
  113524. byCloud++;
  113525. //console.log('补2', history.point.toArray())
  113526. delete history.waitCompute;
  113527. });
  113528. }
  113529. }
  113530. if(byTex || byCloud){
  113531. //console.log('shelterComputed',byTex,byCloud, maxTexCount, maxCloudCount)
  113532. Common.intervalTool.isWaiting('shelterComputed', ()=>{
  113533. //console.log('shelterComputed update')
  113534. this.dispatchEvent('shelterComputed');
  113535. },340);
  113536. }
  113537. }
  113538. updateDatasetAt(force){//更新所在数据集
  113539. let fun = ()=>{
  113540. let currPos = viewer.mainViewport.view.position;
  113541. //if(force || !currPos.equals(this.lastPos)){
  113542. //this.lastPos.copy(currPos)
  113543. var at = this.scene.pointclouds.filter(e=>
  113544. (e.visible || e.unvisibleReasons && e.unvisibleReasons.length == 1 && e.unvisibleReasons[0].reason == 'displayMode')
  113545. && e.ifContainsPoint(currPos)
  113546. );
  113547. if(Common.getDifferenceSet(at, this.atDatasets).length){
  113548. //console.log('atDatasets', at)
  113549. this.atDatasets = at;
  113550. if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
  113551. this.updateFpVisiDatasets();
  113552. if(!viewer.modules.SiteModel.currentFloor){
  113553. this.updatePanosVisibles(); //所在数据集的点位显示
  113554. }
  113555. }
  113556. this.dispatchEvent({type:'pointcloudAtChange',pointclouds:at});
  113557. }
  113558. force = false;
  113559. };
  113560. //}
  113561. if(force)fun();
  113562. else Common.intervalTool.isWaiting('atWhichDataset', fun , 300);
  113563. }
  113564. updatePanosVisibles(currentFloor){//显示当前楼层的所有panos
  113565. if(!Potree.settings.ifShowMarker)return
  113566. let inEntity = currentFloor;
  113567. //console.error('updatePanosVisibles', currentFloor)
  113568. viewer.images360.panos.forEach(pano=>{
  113569. let visible = inEntity ? inEntity.panos.includes(pano) : this.atDatasets.some(e=>e.panos.includes(pano));
  113570. Potree.Utils.updateVisible(pano, 'buildingChange', visible, 2);
  113571. });
  113572. this.dispatchEvent('content_changed');
  113573. } //注:非official的没有获取sitemodel的信息所以不执行楼层判断,marker显示不对是正常的
  113574. /* 2023.11.24 针对部分场景的楼层很矮,很容易就到楼层外了,且不能修改楼高。如SG-t-9NdCpxrUPLL#/,采取如下措施:
  113575. 1 如果不在任何一楼层,但在某个数据集中,就显示该数据集所有的marker
  113576. 2 如果当前楼层无,则显示上一次的currentFloor的marker
  113577. (目前先使用方案1)
  113578. */
  113579. updateMarkerVisibles(){//限制显示的marker个数,因镜头内marker多的时候可能会卡
  113580. if(!Potree.settings.ifShowMarker)return
  113581. const minRadius = 8 * this.images360.zoomLevel, //当视线垂直于marker时的最小可见距离,此范围内可见的pano绝对可见
  113582. maxRadius = 50 * this.images360.zoomLevel, //当视线垂直于marker时的最大可见距离,此范围外绝对不可见
  113583. hopeCount = browser.isMobile() ? 8 : 15; //期望达到的真实可见的marker数
  113584. let sheltered = (pano)=>{
  113585. if(/* Potree.settings.displayMode == 'showPanos' && !Potree.Features.EXT_DEPTH.isSupported() && */this.images360.isAtPano() && !this.mainViewport.view.isFlying()){
  113586. return !this.images360.currentPano.neighbours.includes(pano) && this.images360.currentPano != pano //起初因不支持EXT_DEPTH时无法用depthTex遮住marker, 后为了减少绘制,都判断
  113587. }
  113588. };
  113589. let panoMap = new Map; //先记录想要设置为可见的
  113590. let set = ()=>{//最后确定设置
  113591. let count = 0;
  113592. viewer.images360.panos.forEach(pano=>{
  113593. let v = panoMap.get(pano).visible;
  113594. v && count++;
  113595. Potree.Utils.updateVisible(pano.marker, 'limitMarkerShow', v );
  113596. });
  113597. //console.log('updateMarkerVisibles marker显示个数', count)
  113598. this.dispatchEvent('content_changed');
  113599. };
  113600. let isWithinDis = (pano,maxDis)=>{//是否marker到相机的距离 没有超出可视距离。可视距离考虑上倾斜角,倾斜越大可视距离越短
  113601. let camPos = viewer.mainViewport.camera.position;
  113602. let o = panoMap.get(pano);
  113603. o.dis = o.dis || camPos.distanceTo(pano.marker.position);
  113604. o.sin = o.sin || Math.sqrt(Math.abs(camPos.z - pano.marker.position.z) / o.dis); //和地面夹角的sin。 按公式是不加Math.sqrt的,但是这样大马路上在贴近地面时算出的个数非常少,所以增大点……
  113605. return o.dis < maxDis * o.sin
  113606. };
  113607. viewer.images360.panos.forEach(pano=>{//minRadius内的记录为可见
  113608. let o = {};
  113609. panoMap.set(pano, o);
  113610. if(pano.visible && !sheltered(pano) && isWithinDis(pano, minRadius)){
  113611. o.visible = true;
  113612. }
  113613. });
  113614. //不超过hopeCount的话,可以直接确定设置
  113615. if(viewer.images360.panos.filter(pano=> panoMap.get(pano).visible ).length >= hopeCount)return set()
  113616. //距离超过maxRadius就绝对不可见
  113617. let insideOutCirle = viewer.images360.panos.filter(pano=> pano.visible && !sheltered(pano) && isWithinDis(pano, maxRadius));
  113618. if(insideOutCirle.length <= hopeCount){
  113619. insideOutCirle.forEach(pano=>panoMap.get(pano).visible = true );
  113620. return set()
  113621. }
  113622. //数量超过hopeCount时,根据距离排序
  113623. insideOutCirle.sort((a,b)=>{return panoMap.get(a).dis - panoMap.get(b).dis });
  113624. let slice = insideOutCirle.slice(0,hopeCount);
  113625. slice.forEach(pano=>panoMap.get(pano).visible = true );
  113626. set();
  113627. }
  113628. updateFpVisiDatasets(){
  113629. let Clip = this.modules.Clip;
  113630. let SiteModel = this.modules.SiteModel;
  113631. let Alignment = this.modules.Alignment;
  113632. var currentFloor = SiteModel.currentFloor;
  113633. /* if(Clip.editing){//下载页面已经改为和普通时一样,根据位置判断
  113634. this.updateCadVisibles(Clip.selectedDatasets)
  113635. }else */if(this.selectedFloorplan){//平面图设置中 或 地理设置
  113636. let pointclouds = [this.selectedFloorplan];
  113637. this.updateCadVisibles(pointclouds);
  113638. }else if(SiteModel.editing || Alignment.editing){//只显示勾选的,也就是显示的点云的
  113639. let pointclouds = this.scene.pointclouds.filter(p => Potree.Utils.getObjVisiByReason(p,'datasetSelection') );
  113640. this.updateCadVisibles(pointclouds);
  113641. //this.updatePanosVisibles(currentFloor/* , pointclouds */)
  113642. }else {
  113643. let pointclouds = currentFloor ? this.findPointcloudsAtFloor(currentFloor) : [];
  113644. if(pointclouds.length == 0){
  113645. if(this.focusDatasets){
  113646. pointclouds = this.focusDatasets;
  113647. }
  113648. }
  113649. if(pointclouds.length == 0){//如果当前不在任何楼层或楼层中无数据集,就用当前所在数据集
  113650. pointclouds = this.atDatasets;
  113651. }
  113652. this.updateCadVisibles(pointclouds);
  113653. //this.updatePanosVisibles(currentFloor/* , pointclouds */)
  113654. }
  113655. }
  113656. /* findPointcloudsAtFloor(entity){//找当前楼层需要显示哪些数据集。
  113657. //数据集的belongToEntity 在这个entity内(否则会出现点击数据集飞过去平面图却不显示)。or 如果数据集有漫游点的话,需要包含>20%的漫游点。 (防止重叠体积很大但其实一个漫游点都不包含)
  113658. //重叠体积>50% 或 包含>50%的漫游点
  113659. const ratio1 = 0.2, ratio2 = 0.5, ratio3 = 0.95
  113660. var lowScores = []
  113661. var pointclouds = viewer.scene.pointclouds.filter(e=>{
  113662. let score = 0
  113663. if(e.belongToEntity && (e.belongToEntity == entity || e.belongToEntity.buildParent == entity)){//条件1 若该数据集挂载到该楼层 或 该数据集挂载到的房间属于该楼层(这样能显示该层所有房间)
  113664. return true
  113665. }
  113666. if(e.panos.length){//条件2
  113667. var insidePanos = e.panos.filter(a=>entity.ifContainsPoint(a.position));
  113668. let panoCountRatio = insidePanos.length / e.panos.length
  113669. if(panoCountRatio > ratio2)return true
  113670. score += panoCountRatio
  113671. }
  113672. //条件3
  113673. let volume = entity.intersectPointcloudVolume(e);
  113674. let volumeRatio = volume / entity.getVolume(true) //注:hole加入计算
  113675. if(volumeRatio > ratio3){ //ratio3要高一些,因为点云bounding可能很大,包含很多无点云的空间。即使整个数据集包含entity都不一定看起来在数据集中。(千万要防止两层楼都显示了)
  113676. return true
  113677. }else{
  113678. score += volumeRatio
  113679. }
  113680. lowScores.push({score, pointcloud:e})
  113681. })
  113682. if(pointclouds.length == 0){//从低分项挑一个出来。
  113683. lowScores.sort((a,b)=>{return a.score - b.score})
  113684. if(lowScores[0].score > 0.4){
  113685. pointclouds = [lowScores[0].pointcloud]
  113686. }
  113687. }
  113688. return pointclouds
  113689. } */
  113690. findPointcloudsAtFloor(entity){//找当前楼层需要显示哪些数据集。
  113691. //数据集的belongToEntity 在这个entity内(否则会出现点击数据集飞过去平面图却不显示)。or 如果数据集有漫游点的话,需要包含>20%的漫游点。 (防止重叠体积很大但其实一个漫游点都不包含)
  113692. //重叠体积>50% 或 包含>50%的漫游点
  113693. const ratio1 = 0.2, ratio2 = 0.5, ratio3 = 0.95;
  113694. var lowScores = [];
  113695. var pointclouds = viewer.scene.pointclouds.filter(e=>{
  113696. let score = 0;
  113697. if(e.belongToEntity && (e.belongToEntity == entity || e.belongToEntity.buildParent == entity)){//条件1 若该数据集挂载到该楼层 或 该数据集挂载到的房间属于该楼层(这样能显示该层所有房间)
  113698. return true
  113699. }
  113700. if(e.panos.length){//条件2
  113701. var insidePanos = e.panos.filter(a=>entity.ifContainsPoint(a.position));
  113702. let panoCountRatio = insidePanos.length / e.panos.length;
  113703. if(panoCountRatio > ratio2)return true
  113704. score += panoCountRatio * 2;
  113705. }
  113706. //条件3
  113707. let coverHeightRatio = entity.coverPointcloudHeight(e,true);//重叠高度占楼层高度的比率。
  113708. if(coverHeightRatio < 0.2) return
  113709. let {toEntity,toPointcloud} = entity.intersectPointcloudArea(e,true); //重叠面积占比
  113710. let coverAreaRatio = Math.max(toEntity,toPointcloud);//占数据集俯视面积的比率 和 占楼层的面积比率,挑一个大的。 (有的数据集被划分多个楼层,所以每层都应该显示该数据集的图。还有的数据集比较大,可能包含多个建筑,则看占楼层面积)
  113711. if(coverAreaRatio < 0.2) return
  113712. score += coverAreaRatio * coverHeightRatio;
  113713. lowScores.push({score, pointcloud:e});
  113714. });
  113715. /* if(pointclouds.length == 0){//从低分项挑一个出来。
  113716. lowScores.sort((a,b)=>{return a.score - b.score})
  113717. if(lowScores[0].score > 0.4){
  113718. pointclouds = [lowScores[0].pointcloud]
  113719. }
  113720. } */
  113721. lowScores.forEach(e=>{//一个楼层里可以包含许多个数据集 调试SG-t-ds27ym7xzjJ
  113722. if(e.score > 0.5){
  113723. pointclouds.push(e.pointcloud);
  113724. }
  113725. });
  113726. return pointclouds
  113727. }
  113728. updateCadVisibles(visiClouds, force){
  113729. //console.log('visiClouds',visiClouds)
  113730. let oldVisi = this.fpVisiDatasets;
  113731. var visiClouds = this.fpVisiDatasets = visiClouds;
  113732. if(!force){
  113733. var difference = Common.getDifferenceSet(oldVisi , visiClouds);
  113734. if(difference.length == 0)return
  113735. }
  113736. //console.log('visiClouds',visiClouds.map(e=>e.name))
  113737. viewer.scene.pointclouds.forEach(pointcloud=>{
  113738. var floorplan = viewer.mapViewer.mapLayer.getFloorplan(pointcloud.dataset_id);
  113739. var visi = visiClouds.includes(pointcloud);
  113740. if(floorplan){
  113741. Potree.Utils.updateVisible(floorplan.objectGroup, 'buildingChange', visi);
  113742. }/* else if(!visi){
  113743. let changeVisi = (e)=>{
  113744. Potree.Utils.updateVisible(e.floorplan.objectGroup, 'buildingChange', this.fpVisiDatasets.includes(pointcloud))
  113745. viewer.mapViewer.mapLayer.removeEventListener('floorplanLoaded', changeVisi)
  113746. console.log('updateCadVisibles加载后更改显示',e)
  113747. }
  113748. viewer.mapViewer.mapLayer.addEventListener('floorplanLoaded', changeVisi)
  113749. } */
  113750. //已经添加了全局的 floorplanLoaded后会updateCadVisibles,这段就删了
  113751. });
  113752. viewer.mapViewer.mapLayer.needUpdate = true; //可能需要更新加载的level程度
  113753. viewer.mapViewer.needRender = true; //若上句不触发加载也要立即重新绘制
  113754. }
  113755. //促使点云加载出最高级别
  113756. testPointcloudsMaxLevel(){ //所有点云都无需testMaxNodeLevel 就停止
  113757. let camera_changed, count = 0;
  113758. let test = (e={})=>{
  113759. camera_changed = true;
  113760. let camera = e.camera || this.scene.getActiveCamera();
  113761. Common.intervalTool.isWaiting('testPointcloudsMaxLevel', ()=>{
  113762. if(!camera_changed && count>50 || Potree.settings.displayMode == 'showPanos' || this.pauseTestMaxLevel )return //只有当camera_changed后才继续循环, 除了最开始几次需要连续加载下
  113763. camera_changed = false;
  113764. count ++;
  113765. //console.log('testPointcloudsMaxLevel中', camera.type /* count */)
  113766. let oldCount = this.testMaxNodeCount;
  113767. var success = true;
  113768. viewer.scene.pointclouds.forEach(e=>{
  113769. var wait = e.testMaxNodeLevel(camera);
  113770. if(wait){
  113771. success = false;
  113772. }
  113773. });
  113774. /* if(oldCount<=Potree.config.testNodeCount1 && this.testMaxNodeCount>Potree.config.testNodeCount1 ){//差不多等当前所在数据集nodeMaxLevel加载出来
  113775. viewer.scene.pointclouds.forEach(e=>{e.changePointSize()}) //重新更新一下大小。因之前用的是nodeMaxLevelPredict (防止刚开始因nodeMaxLevel没涨完,导致过大的点云突然出现
  113776. } */
  113777. if(!success)return true //没有全部加载完,继续循环
  113778. else {
  113779. this.removeEventListener('camera_changed',test);
  113780. console.log('testPointcloudsMaxLevel结束');
  113781. }
  113782. }, count<10 ? 250 : 500);
  113783. };
  113784. this.addEventListener('camera_changed',test);
  113785. test();
  113786. /* 检验:
  113787. viewer.scene.pointclouds.sort((a,b)=>a.nodeMaxLevelPredict.min - b.nodeMaxLevelPredict.min).forEach(e=>console.log(e.nodeMaxLevel, e.nodeMaxLevelPredict.min))
  113788. */
  113789. }
  113790. setPointLevels(){
  113791. this.scene.pointclouds.forEach(e=>{
  113792. e.setPointLevel();
  113793. });
  113794. }
  113795. onCrash(error){
  113796. console.error(error);
  113797. $(this.renderArea).empty();
  113798. if ($(this.renderArea).find('#potree_failpage').length === 0) {
  113799. let elFailPage = $(`
  113800. <div id="#potree_failpage" class="potree_failpage">
  113801. <h1>Potree Encountered An Error </h1>
  113802. <p>
  113803. This may happen if your browser or graphics card is not supported.
  113804. <br>
  113805. We recommend to use
  113806. <a href="https://www.google.com/chrome/browser" target="_blank" style="color:initial">Chrome</a>
  113807. or
  113808. <a href="https://www.mozilla.org/" target="_blank">Firefox</a>.
  113809. </p>
  113810. <p>
  113811. Please also visit <a href="http://webglreport.com/" target="_blank">webglreport.com</a> and
  113812. check whether your system supports WebGL.
  113813. </p>
  113814. <p>
  113815. If you are already using one of the recommended browsers and WebGL is enabled,
  113816. consider filing an issue report at <a href="https://github.com/potree/potree/issues" target="_blank">github</a>,<br>
  113817. including your operating system, graphics card, browser and browser version, as well as the
  113818. error message below.<br>
  113819. Please do not report errors on unsupported browsers.
  113820. </p>
  113821. <pre id="potree_error_console" style="width: 100%; height: 100%"></pre>
  113822. </div>`);
  113823. let elErrorMessage = elFailPage.find('#potree_error_console');
  113824. elErrorMessage.html(error.stack);
  113825. $(this.renderArea).append(elFailPage);
  113826. }
  113827. throw error;
  113828. }
  113829. // ------------------------------------------------------------------------------------
  113830. // Viewer API
  113831. // ------------------------------------------------------------------------------------
  113832. setScene (scene) {
  113833. if (scene === this.scene) {
  113834. return;
  113835. }
  113836. let oldScene = this.scene;
  113837. this.scene = scene;
  113838. this.dispatchEvent({
  113839. type: 'scene_changed',
  113840. oldScene: oldScene,
  113841. scene: scene
  113842. });
  113843. { // Annotations
  113844. $('.annotation').detach();
  113845. // for(let annotation of this.scene.annotations){
  113846. // this.renderArea.appendChild(annotation.domElement[0]);
  113847. // }
  113848. this.scene.annotations.traverse(annotation => {
  113849. this.renderArea.appendChild(annotation.domElement[0]);
  113850. });
  113851. if (!this.onAnnotationAdded) {
  113852. this.onAnnotationAdded = e => {
  113853. // console.log("annotation added: " + e.annotation.title);
  113854. e.annotation.traverse(node => {
  113855. $("#potree_annotation_container").append(node.domElement);
  113856. //this.renderArea.appendChild(node.domElement[0]);
  113857. node.scene = this.scene;
  113858. });
  113859. };
  113860. }
  113861. if (oldScene) {
  113862. oldScene.annotations.removeEventListener('annotation_added', this.onAnnotationAdded);
  113863. }
  113864. this.scene.annotations.addEventListener('annotation_added', this.onAnnotationAdded);
  113865. }
  113866. };
  113867. setControls(controls/* , setSpeed */){
  113868. if (controls !== this.controls) {
  113869. if (this.controls) {
  113870. this.controls.setEnable(false);
  113871. //this.inputHandler.removeInputListener(this.controls);
  113872. this.controls.moveSpeed = this.moveSpeed; //记录 (因为orbit的radius很大,转为firstPerson时要缩小)
  113873. }
  113874. this.controls = controls;
  113875. controls.moveSpeed && this.setMoveSpeed(controls.moveSpeed); //add
  113876. this.controls.setEnable(true);
  113877. //this.inputHandler.addInputListener(this.controls);
  113878. }
  113879. }
  113880. getControls () {
  113881. if(this.renderer.xr.isPresenting){
  113882. return this.vrControls;
  113883. }else {
  113884. return this.controls;
  113885. }
  113886. }
  113887. getMinNodeSize () {
  113888. return this.minNodeSize;
  113889. };
  113890. setMinNodeSize (value) {
  113891. if (this.minNodeSize !== value) {
  113892. this.minNodeSize = value;
  113893. this.dispatchEvent({'type': 'minnodesize_changed', 'viewer': this});
  113894. }
  113895. };
  113896. getBackground () {
  113897. return this.background;
  113898. }
  113899. setBackground(bg, src){
  113900. /* if (this.background === bg ) {
  113901. return;
  113902. } */
  113903. if(bg === "skybox"){
  113904. if(!src)src = Potree.resourcePath+'/textures/skybox/xingkong.jpg';
  113905. this.skybox = Utils.loadSkybox(src, this.skybox, ()=>{
  113906. this.background = bg;
  113907. });
  113908. }else { this.background = bg;
  113909. }
  113910. this.backgroundOpacity = 1;//add
  113911. this.dispatchEvent({'type': 'background_changed', 'viewer': this});
  113912. }
  113913. setDescription (value) {
  113914. this.description = value;
  113915. $('#potree_description').html(value);
  113916. //$('#potree_description').text(value);
  113917. }
  113918. getDescription(){
  113919. return this.description;
  113920. }
  113921. setShowBoundingBox (value) {
  113922. if (this.showBoundingBox !== value) {
  113923. this.showBoundingBox = value;
  113924. this.dispatchEvent({'type': 'show_boundingbox_changed', 'viewer': this});
  113925. }
  113926. };
  113927. getShowBoundingBox () {
  113928. return this.showBoundingBox;
  113929. };
  113930. setMoveSpeed (value) {
  113931. if (this.getMoveSpeed() !== value) {
  113932. this.mainViewport.setMoveSpeed(value);
  113933. this.dispatchEvent({'type': 'move_speed_changed', 'viewer': this, 'speed': value});
  113934. }
  113935. };
  113936. getMoveSpeed () {
  113937. return this.mainViewport.moveSpeed;
  113938. };
  113939. setWeightClassification (w) {
  113940. for (let i = 0; i < this.scene.pointclouds.length; i++) {
  113941. this.scene.pointclouds[i].material.weightClassification = w;
  113942. this.dispatchEvent({'type': 'attribute_weights_changed' + i, 'viewer': this});
  113943. }
  113944. };
  113945. setFreeze (value) {
  113946. value = Boolean(value);
  113947. if (this.freeze !== value) {
  113948. this.freeze = value;
  113949. this.dispatchEvent({'type': 'freeze_changed', 'viewer': this});
  113950. }
  113951. };
  113952. getFreeze () {
  113953. return this.freeze;
  113954. };
  113955. setElevationGradientRepeat(value){
  113956. if(this.elevationGradientRepeat !== value){
  113957. this.elevationGradientRepeat = value;
  113958. this.dispatchEvent({
  113959. type: "elevation_gradient_repeat_changed",
  113960. viewer: this});
  113961. }
  113962. }
  113963. setPointBudget (value) { //pointBudget: 每次刷新显示点数量的最大值。 缓存中的点数量也跟此有关,但大于这个数值。
  113964. if (Potree.pointBudget !== value && value) {
  113965. Potree.pointBudget = parseInt(value);
  113966. this.dispatchEvent({'type': 'point_budget_changed', 'viewer': this});
  113967. }
  113968. };
  113969. getPointBudget () {
  113970. return Potree.pointBudget;
  113971. };
  113972. setShowAnnotations (value) {
  113973. if (this.showAnnotations !== value) {
  113974. this.showAnnotations = value;
  113975. this.dispatchEvent({'type': 'show_annotations_changed', 'viewer': this});
  113976. }
  113977. }
  113978. getShowAnnotations () {
  113979. return this.showAnnotations;
  113980. }
  113981. setDEMCollisionsEnabled(value){
  113982. if(this.useDEMCollisions !== value){
  113983. this.useDEMCollisions = value;
  113984. this.dispatchEvent({'type': 'use_demcollisions_changed', 'viewer': this});
  113985. };
  113986. };
  113987. getDEMCollisionsEnabled () {
  113988. return this.useDEMCollisions;
  113989. };
  113990. setEDLEnabled (value) {
  113991. value = Boolean(value) && Features.SHADER_EDL.isSupported();
  113992. if (this.useEDL !== value) {
  113993. this.useEDL = value;
  113994. this.dispatchEvent({'type': 'use_edl_changed', 'viewer': this});
  113995. this.dispatchEvent('pointcloud_changed');
  113996. }
  113997. };
  113998. getEDLEnabled () {
  113999. return this.useEDL;
  114000. };
  114001. setEDLRadius (value) {
  114002. if (this.edlRadius !== value) {
  114003. this.edlRadius = value;
  114004. this.dispatchEvent({'type': 'edl_radius_changed', 'viewer': this});
  114005. this.dispatchEvent('pointcloud_changed');
  114006. }
  114007. };
  114008. getEDLRadius () {
  114009. return this.edlRadius;
  114010. };
  114011. setEDLStrength (value) {
  114012. if (this.edlStrength !== value) {
  114013. this.edlStrength = value;
  114014. this.dispatchEvent({'type': 'edl_strength_changed', 'viewer': this});
  114015. this.dispatchEvent('pointcloud_changed');
  114016. }
  114017. };
  114018. getEDLStrength () {
  114019. return this.edlStrength;
  114020. };
  114021. setEDLOpacity (value) {
  114022. if (this.edlOpacity !== value) {
  114023. this.edlOpacity = value;
  114024. this.dispatchEvent({'type': 'edl_opacity_changed', 'viewer': this});
  114025. this.dispatchEvent('pointcloud_changed');
  114026. }
  114027. };
  114028. getEDLOpacity () {
  114029. return this.edlOpacity;
  114030. };
  114031. setFOV (value) {
  114032. if (this.fov !== value) {
  114033. let oldFov = this.fov;
  114034. this.fov = value;
  114035. this.scene.cameraP.fov = this.fov; //add
  114036. this.scene.cameraP.updateProjectionMatrix(); //add
  114037. this.dispatchEvent({'type': 'fov_changed', 'viewer': this, oldFov, fov:this.fov});
  114038. }
  114039. };
  114040. getFOV () {
  114041. return this.fov;
  114042. };
  114043. disableAnnotations () {
  114044. this.scene.annotations.traverse(annotation => {
  114045. annotation.domElement.css('pointer-events', 'none');
  114046. // return annotation.visible;
  114047. });
  114048. };
  114049. enableAnnotations () {
  114050. this.scene.annotations.traverse(annotation => {
  114051. annotation.domElement.css('pointer-events', 'auto');
  114052. // return annotation.visible;
  114053. });
  114054. }
  114055. setClassifications(classifications){
  114056. this.classifications = classifications;
  114057. this.dispatchEvent({'type': 'classifications_changed', 'viewer': this});
  114058. }
  114059. setClassificationVisibility (key, value) {
  114060. if (!this.classifications[key]) {
  114061. this.classifications[key] = {visible: value, name: 'no name'};
  114062. this.dispatchEvent({'type': 'classification_visibility_changed', 'viewer': this});
  114063. } else if (this.classifications[key].visible !== value) {
  114064. this.classifications[key].visible = value;
  114065. this.dispatchEvent({'type': 'classification_visibility_changed', 'viewer': this});
  114066. }
  114067. }
  114068. toggleAllClassificationsVisibility(){
  114069. let numVisible = 0;
  114070. let numItems = 0;
  114071. for(const key of Object.keys(this.classifications)){
  114072. if(this.classifications[key].visible){
  114073. numVisible++;
  114074. }
  114075. numItems++;
  114076. }
  114077. let visible = true;
  114078. if(numVisible === numItems){
  114079. visible = false;
  114080. }
  114081. let somethingChanged = false;
  114082. for(const key of Object.keys(this.classifications)){
  114083. if(this.classifications[key].visible !== visible){
  114084. this.classifications[key].visible = visible;
  114085. somethingChanged = true;
  114086. }
  114087. }
  114088. if(somethingChanged){
  114089. this.dispatchEvent({'type': 'classification_visibility_changed', 'viewer': this});
  114090. }
  114091. }
  114092. setFilterReturnNumberRange(from, to){
  114093. this.filterReturnNumberRange = [from, to];
  114094. this.dispatchEvent({'type': 'filter_return_number_range_changed', 'viewer': this});
  114095. }
  114096. setFilterNumberOfReturnsRange(from, to){
  114097. this.filterNumberOfReturnsRange = [from, to];
  114098. this.dispatchEvent({'type': 'filter_number_of_returns_range_changed', 'viewer': this});
  114099. }
  114100. setFilterGPSTimeRange(from, to){
  114101. this.filterGPSTimeRange = [from, to];
  114102. this.dispatchEvent({'type': 'filter_gps_time_range_changed', 'viewer': this});
  114103. }
  114104. setFilterPointSourceIDRange(from, to){
  114105. this.filterPointSourceIDRange = [from, to];
  114106. this.dispatchEvent({'type': 'filter_point_source_id_range_changed', 'viewer': this});
  114107. }
  114108. setLengthUnit (value) {
  114109. switch (value) {
  114110. case 'm':
  114111. this.lengthUnit = LengthUnits.METER;
  114112. this.lengthUnitDisplay = LengthUnits.METER;
  114113. break;
  114114. case 'ft':
  114115. this.lengthUnit = LengthUnits.FEET;
  114116. this.lengthUnitDisplay = LengthUnits.FEET;
  114117. break;
  114118. case 'in':
  114119. this.lengthUnit = LengthUnits.INCH;
  114120. this.lengthUnitDisplay = LengthUnits.INCH;
  114121. break;
  114122. }
  114123. this.dispatchEvent({ 'type': 'length_unit_changed', 'viewer': this, value: value});
  114124. };
  114125. setLengthUnitAndDisplayUnit(lengthUnitValue, lengthUnitDisplayValue) {
  114126. switch (lengthUnitValue) {
  114127. case 'm':
  114128. this.lengthUnit = LengthUnits.METER;
  114129. break;
  114130. case 'ft':
  114131. this.lengthUnit = LengthUnits.FEET;
  114132. break;
  114133. case 'in':
  114134. this.lengthUnit = LengthUnits.INCH;
  114135. break;
  114136. }
  114137. switch (lengthUnitDisplayValue) {
  114138. case 'm':
  114139. this.lengthUnitDisplay = LengthUnits.METER;
  114140. break;
  114141. case 'ft':
  114142. this.lengthUnitDisplay = LengthUnits.FEET;
  114143. break;
  114144. case 'in':
  114145. this.lengthUnitDisplay = LengthUnits.INCH;
  114146. break;
  114147. }
  114148. this.dispatchEvent({ 'type': 'length_unit_changed', 'viewer': this, value: lengthUnitValue });
  114149. };
  114150. zoomTo(node, factor, animationDuration = 0){
  114151. let view = this.mainViewport.view;
  114152. let camera = this.scene.cameraP.clone();
  114153. camera.rotation.copy(this.scene.cameraP.rotation);
  114154. camera.rotation.order = "ZXY";
  114155. camera.rotation.x = Math.PI / 2 + view.pitch;
  114156. camera.rotation.z = view.yaw;
  114157. camera.updateMatrix();
  114158. camera.updateMatrixWorld();
  114159. camera.zoomTo(node, factor);
  114160. let bs;
  114161. if (node.boundingSphere) {
  114162. bs = node.boundingSphere;
  114163. } else if (node.geometry && node.geometry.boundingSphere) {
  114164. bs = node.geometry.boundingSphere;
  114165. } else {
  114166. bs = node.boundingBox.getBoundingSphere(new Sphere());
  114167. }
  114168. bs = bs.clone().applyMatrix4(node.matrixWorld);
  114169. let startPosition = view.position.clone();
  114170. let endPosition = camera.position.clone();
  114171. let startTarget = view.getPivot();
  114172. let endTarget = bs.center;
  114173. let startRadius = view.radius;
  114174. let endRadius = endPosition.distanceTo(endTarget);
  114175. let easing = TWEEN.Easing.Quartic.Out;
  114176. { // animate camera position
  114177. let pos = startPosition.clone();
  114178. let tween = new TWEEN.Tween(pos).to(endPosition, animationDuration);
  114179. tween.easing(easing);
  114180. tween.onUpdate(() => {
  114181. view.position.copy(pos);
  114182. });
  114183. tween.start();
  114184. }
  114185. { // animate camera target
  114186. let target = startTarget.clone();
  114187. let tween = new TWEEN.Tween(target).to(endTarget, animationDuration);
  114188. tween.easing(easing);
  114189. tween.onUpdate(() => {
  114190. view.lookAt(target);
  114191. });
  114192. tween.onComplete(() => {
  114193. view.lookAt(target);
  114194. this.dispatchEvent({type: 'focusing_finished', target: this});
  114195. });
  114196. this.dispatchEvent({type: 'focusing_started', target: this});
  114197. tween.start();
  114198. }
  114199. };
  114200. moveToGpsTimeVicinity(time){
  114201. const result = Potree.Utils.findClosestGpsTime(time, viewer);
  114202. const box = result.node.pointcloud.deepestNodeAt(result.position).getBoundingBox();
  114203. const diameter = box.min.distanceTo(box.max);
  114204. const camera = this.scene.getActiveCamera();
  114205. const offset = camera.getWorldDirection(new Vector3()).multiplyScalar(diameter);
  114206. const newCamPos = result.position.clone().sub(offset);
  114207. this.scene.view.position.copy(newCamPos);
  114208. this.scene.view.lookAt(result.position);
  114209. }
  114210. showAbout () {
  114211. $(function () {
  114212. $('#about-panel').dialog();
  114213. });
  114214. };
  114215. getGpsTimeExtent(){
  114216. const range = [Infinity, -Infinity];
  114217. for(const pointcloud of this.scene.pointclouds){
  114218. const attributes = pointcloud.pcoGeometry.pointAttributes.attributes;
  114219. const aGpsTime = attributes.find(a => a.name === "gps-time");
  114220. if(aGpsTime){
  114221. range[0] = Math.min(range[0], aGpsTime.range[0]);
  114222. range[1] = Math.max(range[1], aGpsTime.range[1]);
  114223. }
  114224. }
  114225. return range;
  114226. }
  114227. fitToScreen (factor = 1, animationDuration = 0) {
  114228. let box = this.getBoundingBox(this.scene.pointclouds);
  114229. let node = new Object3D();
  114230. node.boundingBox = box;
  114231. this.zoomTo(node, factor, animationDuration);
  114232. this.controls.stop();
  114233. };
  114234. toggleNavigationCube() {
  114235. this.navigationCube.visible = !this.navigationCube.visible;
  114236. /* this.viewports.push({
  114237. name:'navigationCube',
  114238. left:0, bottom:0, width:0.2,
  114239. }) */
  114240. }
  114241. /* setView(pos, view) {
  114242. if(!pos) return;
  114243. switch(pos) {
  114244. case "F":
  114245. this.setFrontView(view);
  114246. break;
  114247. case "B":
  114248. this.setBackView(view);
  114249. break;
  114250. case "L":
  114251. this.setLeftView(view);
  114252. break;
  114253. case "R":
  114254. this.setRightView(view);
  114255. break;
  114256. case "U":
  114257. this.setTopView(view);
  114258. break;
  114259. case "D":
  114260. this.setBottomView(view);
  114261. break;
  114262. }
  114263. } */
  114264. setTopView(view){
  114265. view = view || this.scene.view;
  114266. view.setCubeView("top");
  114267. this.fitToScreen();
  114268. };
  114269. setBottomView(){
  114270. this.scene.view.yaw = -Math.PI;
  114271. this.scene.view.pitch = Math.PI / 2;
  114272. this.fitToScreen();
  114273. };
  114274. setFrontView(view){
  114275. view = view || this.scene.view;
  114276. view.yaw = 0;
  114277. view.pitch = 0;
  114278. this.fitToScreen();
  114279. };
  114280. setBackView(view){
  114281. view = view || this.scene.view;
  114282. view.yaw = Math.PI;
  114283. view.pitch = 0;
  114284. this.fitToScreen();
  114285. };
  114286. setLeftView(){
  114287. this.scene.view.yaw = -Math.PI / 2;
  114288. this.scene.view.pitch = 0;
  114289. this.fitToScreen();
  114290. };
  114291. setRightView () {
  114292. this.scene.view.yaw = Math.PI / 2;
  114293. this.scene.view.pitch = 0;
  114294. this.fitToScreen();
  114295. };
  114296. flipYZ () {
  114297. this.isFlipYZ = !this.isFlipYZ;
  114298. // TODO flipyz
  114299. console.log('TODO');
  114300. }
  114301. setCameraMode(mode){
  114302. this.scene.cameraMode = mode;
  114303. viewer.mainViewport.camera = mode == CameraMode.PERSPECTIVE ? this.scene.cameraP : this.scene.cameraO; //改
  114304. for(let pointcloud of this.scene.pointclouds) {
  114305. pointcloud.material.useOrthographicCamera = mode == CameraMode.ORTHOGRAPHIC;
  114306. }
  114307. }
  114308. getProjection(){
  114309. const pointcloud = this.scene.pointclouds[0];
  114310. if(pointcloud){
  114311. return pointcloud.projection;
  114312. }else {
  114313. return null;
  114314. }
  114315. }
  114316. async loadProject(url,done){
  114317. const response = await fetch(url);
  114318. if(response.ok){
  114319. const text = await response.text();
  114320. const json = JSON5.parse(text);
  114321. // const json = JSON.parse(text);
  114322. if(json.type === "Potree"){
  114323. Potree.loadProject(viewer, json, done);
  114324. }
  114325. }else {
  114326. console.warn("未能加载:"+url );
  114327. }
  114328. }
  114329. saveProject(){
  114330. return Potree.saveProject(this);
  114331. }
  114332. loadSettingsFromURL(){
  114333. if(Utils.getParameterByName("pointSize")){
  114334. this.setPointSize(parseFloat(Utils.getParameterByName("pointSize")));
  114335. }
  114336. if(Utils.getParameterByName("FOV")){
  114337. this.setFOV(parseFloat(Utils.getParameterByName("FOV")));
  114338. }
  114339. if(Utils.getParameterByName("opacity")){
  114340. this.setOpacity(parseFloat(Utils.getParameterByName("opacity")));
  114341. }
  114342. if(Utils.getParameterByName("edlEnabled")){
  114343. let enabled = Utils.getParameterByName("edlEnabled") === "true";
  114344. this.setEDLEnabled(enabled);
  114345. }
  114346. if (Utils.getParameterByName('edlRadius')) {
  114347. this.setEDLRadius(parseFloat(Utils.getParameterByName('edlRadius')));
  114348. }
  114349. if (Utils.getParameterByName('edlStrength')) {
  114350. this.setEDLStrength(parseFloat(Utils.getParameterByName('edlStrength')));
  114351. }
  114352. if (Utils.getParameterByName('pointBudget')) {
  114353. this.setPointBudget(parseFloat(Utils.getParameterByName('pointBudget')));
  114354. }
  114355. if (Utils.getParameterByName('showBoundingBox')) {
  114356. let enabled = Utils.getParameterByName('showBoundingBox') === 'true';
  114357. if (enabled) {
  114358. this.setShowBoundingBox(true);
  114359. } else {
  114360. this.setShowBoundingBox(false);
  114361. }
  114362. }
  114363. if (Utils.getParameterByName('material')) {
  114364. let material = Utils.getParameterByName('material');
  114365. this.setMaterial(material);
  114366. }
  114367. if (Utils.getParameterByName('pointSizing')) {
  114368. let sizing = Utils.getParameterByName('pointSizing');
  114369. this.setPointSizing(sizing);
  114370. }
  114371. if (Utils.getParameterByName('quality')) {
  114372. let quality = Utils.getParameterByName('quality');
  114373. this.setQuality(quality);
  114374. }
  114375. if (Utils.getParameterByName('position')) {
  114376. let value = Utils.getParameterByName('position');
  114377. value = value.replace('[', '').replace(']', '');
  114378. let tokens = value.split(';');
  114379. let x = parseFloat(tokens[0]);
  114380. let y = parseFloat(tokens[1]);
  114381. let z = parseFloat(tokens[2]);
  114382. this.scene.view.position.set(x, y, z);
  114383. }
  114384. if (Utils.getParameterByName('target')) {
  114385. let value = Utils.getParameterByName('target');
  114386. value = value.replace('[', '').replace(']', '');
  114387. let tokens = value.split(';');
  114388. let x = parseFloat(tokens[0]);
  114389. let y = parseFloat(tokens[1]);
  114390. let z = parseFloat(tokens[2]);
  114391. this.scene.view.lookAt(new Vector3(x, y, z));
  114392. }
  114393. if (Utils.getParameterByName('background')) {
  114394. let value = Utils.getParameterByName('background');
  114395. this.setBackground(value);
  114396. }
  114397. // if(Utils.getParameterByName("elevationRange")){
  114398. // let value = Utils.getParameterByName("elevationRange");
  114399. // value = value.replace("[", "").replace("]", "");
  114400. // let tokens = value.split(";");
  114401. // let x = parseFloat(tokens[0]);
  114402. // let y = parseFloat(tokens[1]);
  114403. //
  114404. // this.setElevationRange(x, y);
  114405. // //this.scene.view.target.set(x, y, z);
  114406. // }
  114407. };
  114408. // ------------------------------------------------------------------------------------
  114409. // Viewer Internals
  114410. // ------------------------------------------------------------------------------------
  114411. createControls () {
  114412. { // create FIRST PERSON CONTROLS
  114413. this.fpControls = new FirstPersonControls(this, this.mainViewport);
  114414. this.fpControls.enabled = false;
  114415. this.fpControls.addEventListener('start', this.disableAnnotations.bind(this));
  114416. this.fpControls.addEventListener('end', this.enableAnnotations.bind(this));
  114417. /* this.addEventListener("loadPointCloudDone", ()=>{
  114418. let boundPlane = new THREE.Box3()
  114419. boundPlane.expandByPoint(this.bound.boundingBox.min.clone())//最低高度为bound的最低
  114420. boundPlane.expandByPoint(this.bound.boundingBox.max.clone().setZ(this.bound.center.z))//最高高度为bound的中心高度
  114421. FirstPersonControls.boundPlane = boundPlane
  114422. FirstPersonControls.standardSpeed = THREE.Math.clamp( Math.sqrt(this.bound.boundSize.length() )/ 100 , 0.02,0.5); //在这个boundPlane中的速度
  114423. }) */
  114424. }
  114425. // { // create GEO CONTROLS
  114426. // this.geoControls = new GeoControls(this.scene.camera, this.renderer.domElement);
  114427. // this.geoControls.enabled = false;
  114428. // this.geoControls.addEventListener("start", this.disableAnnotations.bind(this));
  114429. // this.geoControls.addEventListener("end", this.enableAnnotations.bind(this));
  114430. // this.geoControls.addEventListener("move_speed_changed", (event) => {
  114431. // this.setMoveSpeed(this.geoControls.moveSpeed);
  114432. // });
  114433. // }
  114434. { // create ORBIT CONTROLS
  114435. this.orbitControls = new OrbitControls(this);
  114436. this.orbitControls.enabled = false;
  114437. this.orbitControls.addEventListener('start', this.disableAnnotations.bind(this));
  114438. this.orbitControls.addEventListener('end', this.enableAnnotations.bind(this));
  114439. }
  114440. /* { // create EARTH CONTROLS
  114441. this.earthControls = new EarthControls(this);
  114442. this.earthControls.enabled = false;
  114443. this.earthControls.addEventListener('start', this.disableAnnotations.bind(this));
  114444. this.earthControls.addEventListener('end', this.enableAnnotations.bind(this));
  114445. }
  114446. { // create DEVICE ORIENTATION CONTROLS
  114447. this.deviceControls = new DeviceOrientationControls(this);
  114448. this.deviceControls.enabled = false;
  114449. this.deviceControls.addEventListener('start', this.disableAnnotations.bind(this));
  114450. this.deviceControls.addEventListener('end', this.enableAnnotations.bind(this));
  114451. } */
  114452. /* { // create VR CONTROLS
  114453. this.vrControls = new VRControls(this);
  114454. this.vrControls.enabled = false;
  114455. this.vrControls.addEventListener('start', this.disableAnnotations.bind(this));
  114456. this.vrControls.addEventListener('end', this.enableAnnotations.bind(this));
  114457. } */
  114458. };
  114459. toggleSidebar () {
  114460. let renderArea = $('#potree_render_area');
  114461. let isVisible = renderArea.css('left') !== '0px';
  114462. if (isVisible) {
  114463. renderArea.css('left', '0px');
  114464. } else {
  114465. renderArea.css('left', '300px');
  114466. }
  114467. };
  114468. toggleMap () {
  114469. // let map = $('#potree_map');
  114470. // map.toggle(100);
  114471. if (this.mapView) {
  114472. this.mapView.toggle();
  114473. }
  114474. };
  114475. onGUILoaded(callback){
  114476. if(this.guiLoaded){
  114477. callback();
  114478. }else {
  114479. this.guiLoadTasks.push(callback);
  114480. }
  114481. }
  114482. promiseGuiLoaded(){
  114483. return new Promise( resolve => {
  114484. if(this.guiLoaded){
  114485. resolve();
  114486. }else {
  114487. this.guiLoadTasks.push(resolve);
  114488. }
  114489. });
  114490. }
  114491. loadGUI(callback){
  114492. if(callback){
  114493. this.onGUILoaded(callback);
  114494. }
  114495. let viewer = this;
  114496. let sidebarContainer = $('#potree_sidebar_container');
  114497. sidebarContainer.load(new URL(Potree.scriptPath + '/' + (Potree.settings.sidebar || 'sidebar1.html')).href, () => {
  114498. sidebarContainer.css('width', '300px');
  114499. sidebarContainer.css('height', '100%');
  114500. let imgMenuToggle = document.createElement('img');
  114501. imgMenuToggle.src = new URL(Potree.resourcePath + '/icons/menu_button.svg').href;
  114502. imgMenuToggle.onclick = this.toggleSidebar;
  114503. imgMenuToggle.classList.add('potree_menu_toggle');
  114504. let imgMapToggle = document.createElement('img');
  114505. imgMapToggle.src = new URL(Potree.resourcePath + '/icons/map_icon.png').href;
  114506. imgMapToggle.style.display = 'none';
  114507. imgMapToggle.onclick = e => { this.toggleMap(); };
  114508. imgMapToggle.id = 'potree_map_toggle';
  114509. let elButtons = $("#potree_quick_buttons").get(0);
  114510. elButtons.append(imgMenuToggle);
  114511. elButtons.append(imgMapToggle);
  114512. VRButton.createButton(this.renderer).then(vrButton => {
  114513. if(vrButton == null){
  114514. console.log("VR not supported or active.");
  114515. return;
  114516. }
  114517. this.renderer.xr.enabled = true;
  114518. let element = vrButton.element;
  114519. element.style.position = "";
  114520. element.style.bottom = "";
  114521. element.style.left = "";
  114522. element.style.margin = "4px";
  114523. element.style.fontSize = "100%";
  114524. element.style.width = "2.5em";
  114525. element.style.height = "2.5em";
  114526. element.style.padding = "0";
  114527. element.style.textShadow = "black 2px 2px 2px";
  114528. element.style.display = "block";
  114529. elButtons.append(element);
  114530. vrButton.onStart(() => {
  114531. this.dispatchEvent({type: "vr_start"});
  114532. });
  114533. vrButton.onEnd(() => {
  114534. this.dispatchEvent({type: "vr_end"});
  114535. });
  114536. });
  114537. /* this.mapView = new MapView(this);
  114538. this.mapView.init(); */
  114539. i18n.init({
  114540. lng: 'en',
  114541. resGetPath: Potree.resourcePath + '/lang/__lng__/__ns__.json',
  114542. preload: ['en', 'fr', 'de', 'jp', 'se', 'es', 'zh'],
  114543. getAsync: true,
  114544. debug: false
  114545. }, function (t) {
  114546. // Start translation once everything is loaded
  114547. $('body').i18n();
  114548. });
  114549. $(() => {
  114550. //initSidebar(this);
  114551. let sidebar = new Sidebar(this);
  114552. sidebar.init();
  114553. this.sidebar = sidebar;
  114554. //if (callback) {
  114555. // $(callback);
  114556. //}
  114557. let elProfile = $('<div>').load(new URL(Potree.scriptPath + '/profile.html').href, () => {
  114558. $(document.body).append(elProfile.children());
  114559. this.profileWindow = new ProfileWindow(this);
  114560. this.profileWindowController = new ProfileWindowController(this);
  114561. $('#profile_window').draggable({
  114562. handle: $('#profile_titlebar'),
  114563. containment: $(document.body)
  114564. });
  114565. $('#profile_window').resizable({
  114566. containment: $(document.body),
  114567. handles: 'n, e, s, w'
  114568. });
  114569. $(() => {
  114570. this.guiLoaded = true;
  114571. for(let task of this.guiLoadTasks){
  114572. task();
  114573. }
  114574. });
  114575. });
  114576. });
  114577. });
  114578. return this.promiseGuiLoaded();
  114579. }
  114580. setLanguage (lang) {
  114581. i18n.setLng(lang);
  114582. $('body').i18n();
  114583. }
  114584. setServer (server) {
  114585. this.server = server;
  114586. }
  114587. initDragAndDrop(){
  114588. function allowDrag(e) {
  114589. e.dataTransfer.dropEffect = 'copy';
  114590. e.preventDefault();
  114591. }
  114592. let dropHandler = async (event) => {
  114593. console.log(event);
  114594. event.preventDefault();
  114595. for(const item of event.dataTransfer.items){
  114596. console.log(item);
  114597. if(item.kind !== "file"){
  114598. continue;
  114599. }
  114600. const file = item.getAsFile();
  114601. const isJson = file.name.toLowerCase().endsWith(".json");
  114602. const isGeoPackage = file.name.toLowerCase().endsWith(".gpkg");
  114603. if(isJson){
  114604. try{
  114605. const text = await file.text();
  114606. const json = JSON.parse(text);
  114607. if(json.type === "Potree"){
  114608. Potree.loadProject(viewer, json);
  114609. }
  114610. }catch(e){
  114611. console.error("failed to parse the dropped file as JSON");
  114612. console.error(e);
  114613. }
  114614. }else if(isGeoPackage){
  114615. const hasPointcloud = viewer.scene.pointclouds.length > 0;
  114616. if(!hasPointcloud){
  114617. let msg = "At least one point cloud is needed that specifies the ";
  114618. msg += "coordinate reference system before loading vector data.";
  114619. console.error(msg);
  114620. }else {
  114621. proj4.defs("WGS84", "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs");
  114622. proj4.defs("pointcloud", this.getProjection());
  114623. let transform = proj4("WGS84", "pointcloud");
  114624. const buffer = await file.arrayBuffer();
  114625. const params = {
  114626. transform: transform,
  114627. source: file.name,
  114628. };
  114629. const geo = await Potree.GeoPackageLoader.loadBuffer(buffer, params);
  114630. viewer.scene.addGeopackage(geo);
  114631. }
  114632. }
  114633. }
  114634. };
  114635. $("body")[0].addEventListener("dragenter", allowDrag);
  114636. $("body")[0].addEventListener("dragover", allowDrag);
  114637. $("body")[0].addEventListener("drop", dropHandler);
  114638. }
  114639. updateAnnotations () {
  114640. if(!this.visibleAnnotations){
  114641. this.visibleAnnotations = new Set();
  114642. }
  114643. this.scene.annotations.updateBounds();
  114644. this.scene.cameraP.updateMatrixWorld();
  114645. this.scene.cameraO.updateMatrixWorld();
  114646. let distances = [];
  114647. let renderAreaSize = this.renderer.getSize(new Vector2());
  114648. let viewer = this;
  114649. let visibleNow = [];
  114650. this.scene.annotations.traverse(annotation => {
  114651. if (annotation === this.scene.annotations) {
  114652. return true;
  114653. }
  114654. if (!annotation.visible) {
  114655. return false;
  114656. }
  114657. annotation.scene = this.scene;
  114658. let element = annotation.domElement;
  114659. let position = annotation.position.clone();
  114660. position.add(annotation.offset);
  114661. if (!position) {
  114662. position = annotation.boundingBox.getCenter(new Vector3());
  114663. }
  114664. let distance = viewer.scene.cameraP.position.distanceTo(position);
  114665. let radius = annotation.boundingBox.getBoundingSphere(new Sphere()).radius;
  114666. let screenPos = new Vector3();
  114667. let screenSize = 0;
  114668. {
  114669. // SCREEN POS
  114670. screenPos.copy(position).project(this.scene.getActiveCamera());
  114671. screenPos.x = renderAreaSize.x * (screenPos.x + 1) / 2;
  114672. screenPos.y = renderAreaSize.y * (1 - (screenPos.y + 1) / 2);
  114673. // SCREEN SIZE
  114674. if(viewer.scene.cameraMode == CameraMode.PERSPECTIVE) {
  114675. let fov = Math.PI * viewer.scene.cameraP.fov / 180;
  114676. let slope = Math.tan(fov / 2.0);
  114677. let projFactor = 0.5 * renderAreaSize.y / (slope * distance);
  114678. screenSize = radius * projFactor;
  114679. } else {
  114680. screenSize = Utils.projectedRadiusOrtho(radius, viewer.scene.cameraO.projectionMatrix, renderAreaSize.x, renderAreaSize.y);
  114681. }
  114682. }
  114683. element.css("left", screenPos.x + "px");
  114684. element.css("top", screenPos.y + "px");
  114685. //element.css("display", "block");
  114686. let zIndex = 10000000 - distance * (10000000 / this.scene.cameraP.far);
  114687. if(annotation.descriptionVisible){
  114688. zIndex += 10000000;
  114689. }
  114690. element.css("z-index", parseInt(zIndex));
  114691. if(annotation.children.length > 0){
  114692. let expand = screenSize > annotation.collapseThreshold || annotation.boundingBox.containsPoint(this.scene.getActiveCamera().position);
  114693. annotation.expand = expand;
  114694. if (!expand) {
  114695. //annotation.display = (screenPos.z >= -1 && screenPos.z <= 1);
  114696. let inFrustum = (screenPos.z >= -1 && screenPos.z <= 1);
  114697. if(inFrustum){
  114698. visibleNow.push(annotation);
  114699. }
  114700. }
  114701. return expand;
  114702. } else {
  114703. //annotation.display = (screenPos.z >= -1 && screenPos.z <= 1);
  114704. let inFrustum = (screenPos.z >= -1 && screenPos.z <= 1);
  114705. if(inFrustum){
  114706. visibleNow.push(annotation);
  114707. }
  114708. }
  114709. });
  114710. let notVisibleAnymore = new Set(this.visibleAnnotations);
  114711. for(let annotation of visibleNow){
  114712. annotation.display = true;
  114713. notVisibleAnymore.delete(annotation);
  114714. }
  114715. this.visibleAnnotations = visibleNow;
  114716. for(let annotation of notVisibleAnymore){
  114717. annotation.display = false;
  114718. }
  114719. }
  114720. updateMaterialDefaults(pointcloud){
  114721. // PROBLEM STATEMENT:
  114722. // * [min, max] of intensity, source id, etc. are computed as point clouds are loaded
  114723. // * the point cloud material won't know the range it should use until some data is loaded
  114724. // * users can modify the range at runtime, but sensible default ranges should be
  114725. // applied even if no GUI is present
  114726. // * display ranges shouldn't suddenly change even if the actual range changes over time.
  114727. // e.g. the root node has intensity range [1, 478]. One of the descendants increases range to
  114728. // [0, 2047]. We should not automatically change to the new range because that would result
  114729. // in sudden and drastic changes of brightness. We should adjust the min/max of the sidebar slider.
  114730. const material = pointcloud.material;
  114731. const attIntensity = pointcloud.getAttribute("intensity");
  114732. if(attIntensity != null && material.intensityRange[0] === Infinity){
  114733. material.intensityRange = [...attIntensity.range];
  114734. }
  114735. // const attIntensity = pointcloud.getAttribute("intensity");
  114736. // if(attIntensity && material.intensityRange[0] === Infinity){
  114737. // material.intensityRange = [...attIntensity.range];
  114738. // }
  114739. // let attributes = pointcloud.getAttributes();
  114740. // for(let attribute of attributes.attributes){
  114741. // if(attribute.range){
  114742. // let range = [...attribute.range];
  114743. // material.computedRange.set(attribute.name, range);
  114744. // //material.setRange(attribute.name, range);
  114745. // }
  114746. // }
  114747. }
  114748. update(delta, timestamp){
  114749. viewer.addTimeMark('update','start');
  114750. TWEEN.update(timestamp);
  114751. transitions.update(delta);//写在开头,因为这时候最为固定,计时准确
  114752. this.dispatchEvent({
  114753. type: 'update_start',
  114754. delta: delta,
  114755. timestamp: timestamp});
  114756. this.updateScreenSize(); //判断是否改变canvas大小
  114757. const scene = this.scene;
  114758. const camera = scene.getActiveCamera();
  114759. const visiblePointClouds = this.scene.pointclouds.filter(pc => pc.visible);
  114760. Potree.pointLoadLimit = Potree.pointBudget * 2;
  114761. /* const lTarget = camera.position.clone().add(camera.getWorldDirection(new THREE.Vector3()).multiplyScalar(1000));
  114762. this.scene.directionalLight.position.copy(camera.position);
  114763. this.scene.directionalLight.lookAt(lTarget); */
  114764. for (let pointcloud of visiblePointClouds) {
  114765. pointcloud.showBoundingBox = this.showBoundingBox;
  114766. pointcloud.generateDEM = this.generateDEM;
  114767. pointcloud.minimumNodePixelSize = this.minNodeSize;
  114768. let material = pointcloud.material;
  114769. material.uniforms.uFilterReturnNumberRange.value = this.filterReturnNumberRange;
  114770. material.uniforms.uFilterNumberOfReturnsRange.value = this.filterNumberOfReturnsRange;
  114771. material.uniforms.uFilterGPSTimeClipRange.value = this.filterGPSTimeRange;
  114772. material.uniforms.uFilterPointSourceIDClipRange.value = this.filterPointSourceIDRange;
  114773. material.classification = this.classifications;
  114774. material.recomputeClassification();
  114775. this.updateMaterialDefaults(pointcloud);
  114776. }
  114777. {
  114778. if(this.showBoundingBox){
  114779. let bbRoot = this.scene.scene.getObjectByName("potree_bounding_box_root");
  114780. if(!bbRoot){
  114781. let node = new Object3D();
  114782. node.name = "potree_bounding_box_root";
  114783. this.scene.scene.add(node);
  114784. bbRoot = node;
  114785. }
  114786. let visibleBoxes = [];
  114787. for(let pointcloud of this.scene.pointclouds){
  114788. for(let node of pointcloud.visibleNodes.filter(vn => vn.boundingBoxNode !== undefined)){
  114789. let box = node.boundingBoxNode;
  114790. visibleBoxes.push(box);
  114791. }
  114792. }
  114793. bbRoot.children = visibleBoxes;
  114794. }
  114795. }
  114796. if(this.boundNeedUpdate)this.updateModelBound(); //add
  114797. this.scene.cameraP.fov = this.fov;
  114798. let controls = this.getControls();
  114799. if (controls === this.deviceControls) {
  114800. this.controls.setScene(scene);
  114801. this.controls.update(delta);
  114802. this.scene.cameraP.position.copy(scene.view.position);
  114803. this.scene.cameraO.position.copy(scene.view.position);
  114804. } else if (controls !== null) {
  114805. controls.setScene(scene);
  114806. controls.update(delta);
  114807. //更新camera
  114808. this.viewports.forEach(viewport=>{
  114809. if(!viewport.active)return
  114810. viewport.view.applyToCamera(viewport.camera);
  114811. });
  114812. }
  114813. this.lastFrameChanged = this.cameraChanged();//判断camera画面是否改变
  114814. { // update clip boxes
  114815. let boxes = [];
  114816. // volumes with clipping enabled
  114817. boxes.push(...this.scene.volumes.filter(v => (v.clip && v instanceof BoxVolume$1)));
  114818. // profile segments
  114819. for(let profile of this.scene.profiles){
  114820. boxes.push(...profile.boxes);
  114821. }
  114822. // Needed for .getInverse(), pre-empt a determinant of 0, see #815 / #816
  114823. let degenerate = (box) => box.matrixWorld.determinant() !== 0 && box.clip;
  114824. let clipBoxes = boxes.filter(degenerate).map( box => {
  114825. box.updateMatrixWorld();
  114826. let boxInverse = box.matrixWorld.clone().invert();
  114827. //let boxPosition = box.getWorldPosition(new THREE.Vector3());
  114828. return {box: box, inverse: boxInverse/* , position: boxPosition */};
  114829. });
  114830. //改
  114831. let bigClipInBox = clipBoxes.find(e=>e.box.clipTask == ClipTask.SHOW_INSIDE_Big && !e.box.highlight);//裁剪下载 when this.modules.Clip.editing
  114832. let clipBoxes_in = clipBoxes.filter(e=>e.box.clipTask == ClipTask.SHOW_INSIDE && !e.box.highlight);
  114833. let clipBoxes_out = clipBoxes.filter(e=>e.box.clipTask == ClipTask.SHOW_OUTSIDE && !e.box.highlight);
  114834. let highlightBoxes = clipBoxes.filter(e=>e.box.highlight );
  114835. //let prismPolygons = this.modules.volumeComputer && this.modules.volumeComputer.entered ? viewer.scene.measurements.filter(e=>(e.measureType == 'MulDistance Ring') && !e.isNew) : []
  114836. let prismPolygons = this.modules.volumeComputer ? this.modules.volumeComputer.prisms.filter(e=>!e.isNew && e.visible && !e.dontHighlight && (e.baseModel || !e.modelHaventLoad)) : [];
  114837. // set clip volumes in material
  114838. for(let pointcloud of visiblePointClouds){
  114839. pointcloud.material.setClipBoxes(bigClipInBox, clipBoxes_in, clipBoxes_out, highlightBoxes, prismPolygons);
  114840. }
  114841. }
  114842. {
  114843. for(let pointcloud of visiblePointClouds){
  114844. pointcloud.material.elevationGradientRepeat = this.elevationGradientRepeat;
  114845. }
  114846. }
  114847. { // update navigation cube
  114848. this.navigationCube.update(camera.rotation);
  114849. }
  114850. this.updateAnnotations();
  114851. if(this.mapView){
  114852. this.mapView.update(delta);
  114853. if(this.mapView.sceneProjection){
  114854. $( "#potree_map_toggle" ).css("display", "block");
  114855. }
  114856. }
  114857. this.transformationTool.update();
  114858. if(Potree.settings.editType != 'pano' && Potree.settings.editType != 'merge'){
  114859. this.modules.ParticleEditor.update(delta);
  114860. }
  114861. this.mapViewer && this.mapViewer.update(delta); //地图更新
  114862. this.dispatchEvent({ type: 'update', delta: delta, timestamp: timestamp}); //在有sidebar时耗高cpu,占本update函数80%
  114863. viewer.addTimeMark('update','end');
  114864. //add ------
  114865. this.reticule.updateVisible();
  114866. }
  114867. updateViewPointcloud(camera, areaSize, isViewport){
  114868. let result = Potree.updatePointClouds(this.scene.pointclouds, camera, areaSize );
  114869. //if(isViewport)return
  114870. const tStart = performance.now();
  114871. const campos = camera.position;
  114872. let closestImage = Infinity;
  114873. for(const images of this.scene.orientedImages){
  114874. for(const image of images.images){
  114875. const distance = image.mesh.position.distanceTo(campos);
  114876. closestImage = Math.min(closestImage, distance);
  114877. }
  114878. }
  114879. //const tEnd = performance.now();
  114880. //改:不根据点云修改视野near far
  114881. var near = camera.near, far = camera.far;
  114882. if(!camera.limitFar && result.lowestSpacing !== Infinity){
  114883. //let near = result.lowestSpacing * 10.0;
  114884. let far = -this.getBoundingBox().applyMatrix4(camera.matrixWorldInverse).min.z;
  114885. far = Math.max(far * 1.5, 10000);
  114886. //near = Math.min(100.0, Math.max(0.01, near));
  114887. //near = Math.min(near, closestImage);
  114888. far = Math.max(far, near + 10000);
  114889. /* if(near === Infinity){
  114890. near = 0.1;
  114891. } */
  114892. //camera.near = near; //为了其他物体的显示,不修改near
  114893. camera.far = far;
  114894. }
  114895. /* if(this.scene.cameraMode == CameraMode.ORTHOGRAPHIC) {//???
  114896. camera.near = -camera.far;
  114897. } */
  114898. if(/* near != camera.near || */far != camera.far){
  114899. camera.updateProjectionMatrix();
  114900. }
  114901. //注:pointcloud.visibleNodes会随着near far自动更新
  114902. }
  114903. getPRenderer(){
  114904. if(this.useHQ){
  114905. if (!this.hqRenderer) {
  114906. this.hqRenderer = new HQSplatRenderer(this);
  114907. }
  114908. this.hqRenderer.useEDL = this.useEDL;
  114909. return this.hqRenderer;
  114910. }else {
  114911. /* if (this.useEDL && Features.SHADER_EDL.isSupported()) {
  114912. if (!this.edlRenderer) {
  114913. this.edlRenderer = new EDLRenderer(this);
  114914. }
  114915. return this.edlRenderer;
  114916. } else {
  114917. if (!this.potreeRenderer) {
  114918. this.potreeRenderer = new PotreeRenderer(this);
  114919. }
  114920. return this.potreeRenderer;
  114921. } */
  114922. if (!this.edlRenderer) {
  114923. this.edlRenderer = new EDLRenderer(this);
  114924. }
  114925. return this.edlRenderer;
  114926. }
  114927. }
  114928. renderVR(){//渲染部分没改完
  114929. let renderer = this.renderer;
  114930. renderer.setClearColor(0x550000, 0);
  114931. renderer.clear();
  114932. let xr = renderer.xr;
  114933. let dbg = new PerspectiveCamera();
  114934. let xrCameras = xr.getCamera(dbg);
  114935. if(xrCameras.cameras.length !== 2){
  114936. return;
  114937. }
  114938. let makeCam = this.vrControls.getCamera.bind(this.vrControls);
  114939. { // clear framebuffer
  114940. if(viewer.background === "skybox"){
  114941. renderer.setClearColor(0xff0000, 1);
  114942. }else if(viewer.background === "gradient"){
  114943. renderer.setClearColor(0x112233, 1);
  114944. }else if(viewer.background === "black"){
  114945. renderer.setClearColor(0x000000, 1);
  114946. }else if(viewer.background === "white"){
  114947. renderer.setClearColor(0xFFFFFF, 1);
  114948. }else {
  114949. renderer.setClearColor(0x000000, 0);
  114950. }
  114951. renderer.clear();
  114952. }
  114953. // render background
  114954. if(this.background === "skybox"){
  114955. let {skybox} = this;
  114956. let cam = makeCam();
  114957. skybox.camera.rotation.copy(cam.rotation);
  114958. skybox.camera.fov = cam.fov;
  114959. skybox.camera.aspect = cam.aspect;
  114960. // let dbg = new THREE.Object3D();
  114961. let dbg = skybox.parent;
  114962. // dbg.up.set(0, 0, 1);
  114963. dbg.rotation.x = Math.PI / 2;
  114964. // skybox.camera.parent = dbg;
  114965. // dbg.children.push(skybox.camera);
  114966. dbg.updateMatrix();
  114967. dbg.updateMatrixWorld();
  114968. skybox.camera.updateMatrix();
  114969. skybox.camera.updateMatrixWorld();
  114970. skybox.camera.updateProjectionMatrix();
  114971. renderer.render(skybox.scene, skybox.camera);
  114972. // renderer.render(skybox.scene, cam);
  114973. }else if(this.background === "gradient"){
  114974. // renderer.render(this.scene.sceneBG, this.scene.cameraBG);
  114975. }
  114976. this.renderer.xr.getSession().updateRenderState({
  114977. depthNear: 0.1,
  114978. depthFar: 10000
  114979. });
  114980. let cam = null;
  114981. let view = null;
  114982. { // render world scene
  114983. cam = makeCam();
  114984. cam.position.z -= 0.8 * cam.scale.x;
  114985. cam.parent = null;
  114986. // cam.near = 0.05;
  114987. cam.near = viewer.scene.getActiveCamera().near;
  114988. cam.far = viewer.scene.getActiveCamera().far;
  114989. cam.updateMatrix();
  114990. cam.updateMatrixWorld();
  114991. this.scene.scene.updateMatrix();
  114992. this.scene.scene.updateMatrixWorld();
  114993. this.scene.scene.matrixAutoUpdate = false;
  114994. let camWorld = cam.matrixWorld.clone();
  114995. view = camWorld.clone().invert();
  114996. this.scene.scene.matrix.copy(view);
  114997. this.scene.scene.matrixWorld.copy(view);
  114998. cam.matrix.identity();
  114999. cam.matrixWorld.identity();
  115000. cam.matrixWorldInverse.identity();
  115001. renderer.render(this.scene.scene, cam);
  115002. this.scene.scene.matrixWorld.identity();
  115003. }
  115004. for(let pointcloud of this.scene.pointclouds){
  115005. let viewport = xrCameras.cameras[0].viewport;
  115006. pointcloud.material.useEDL = false;
  115007. pointcloud.screenHeight = viewport.height;
  115008. pointcloud.screenWidth = viewport.width;
  115009. // automatically switch to paraboloids because they cause far less flickering in VR,
  115010. // when point sizes are larger than around 2 pixels
  115011. // if(Features.SHADER_INTERPOLATION.isSupported()){
  115012. // pointcloud.material.shape = Potree.PointShape.PARABOLOID;
  115013. // }
  115014. }
  115015. // render point clouds
  115016. for(let xrCamera of xrCameras.cameras){
  115017. let v = xrCamera.viewport;
  115018. renderer.setViewport(v.x, v.y, v.width, v.height);
  115019. // xrCamera.fov = 90;
  115020. { // estimate VR fov
  115021. let proj = xrCamera.projectionMatrix;
  115022. let inv = proj.clone().invert();
  115023. let p1 = new Vector4(0, 1, -1, 1).applyMatrix4(inv);
  115024. let rad = p1.y;
  115025. let fov = 180 * (rad / Math.PI);
  115026. xrCamera.fov = fov;
  115027. }
  115028. for(let pointcloud of this.scene.pointclouds){
  115029. const {material} = pointcloud;
  115030. material.useEDL = false;
  115031. }
  115032. let vrWorld = view.clone().invert();
  115033. vrWorld.multiply(xrCamera.matrixWorld);
  115034. let vrView = vrWorld.clone().invert();
  115035. this.pRenderer.render(this.scene.scenePointCloud, xrCamera, null, {
  115036. viewOverride: vrView,
  115037. });
  115038. }
  115039. { // render VR scene
  115040. let cam = makeCam();
  115041. cam.parent = null;
  115042. renderer.render(this.sceneVR, cam);
  115043. }
  115044. renderer.resetState();
  115045. }
  115046. clear(params={}){
  115047. let background = params.background || this.background;
  115048. let backgroundOpacity = params.backgroundOpacity == void 0 ? this.backgroundOpacity : params.backgroundOpacity;//如果想完全透明,只需要backgroundOpacity为0
  115049. let renderer = this.renderer;
  115050. //let gl = renderer.getContext()
  115051. if(background instanceof Color){ //add
  115052. renderer.setClearColor(background, backgroundOpacity);
  115053. }else if(background === "skybox"){
  115054. renderer.setClearColor(0x000000, backgroundOpacity);
  115055. } else if (background === 'gradient') {
  115056. renderer.setClearColor(0x000000, backgroundOpacity);
  115057. } else if (background === 'black') {
  115058. renderer.setClearColor(0x000000, 1);
  115059. } else if (background === 'white') {
  115060. renderer.setClearColor(0xFFFFFF, 1);
  115061. } else {
  115062. renderer.setClearColor(background, backgroundOpacity);
  115063. }
  115064. params.target || renderer.clear();
  115065. }
  115066. getBuffer(viewport){//根据不同viewport返回rtEDL的texture
  115067. var buffer = this.buffers.get(viewport);
  115068. if(!buffer){
  115069. buffer = new WebGLRenderTarget(viewport.resolution.x, viewport.resolution.y, {
  115070. minFilter: NearestFilter,
  115071. magFilter: NearestFilter,
  115072. format: RGBAFormat,
  115073. type: FloatType
  115074. });
  115075. this.buffers.set(viewport, rtEDL);
  115076. }
  115077. return buffer
  115078. }
  115079. async renderDefault(params_={}){
  115080. if(!this.visible ) return
  115081. let pRenderer = this.getPRenderer();
  115082. let viewports = params_.viewports || this.viewports;
  115083. viewer.addTimeMark('renderDefault','start');
  115084. //console.log('render', viewports.map(e=>e.name).join(','))
  115085. let renderSize;
  115086. if(params_.target){
  115087. renderSize = new Vector2(params_.target.width, params_.target.height); //是画布大小
  115088. //可能需要viewer.setSize
  115089. }else {
  115090. renderSize = this.renderer.getSize(new Vector2()); //是client大小
  115091. }
  115092. ///let needsResize = viewports.length > 1 || params_.resize //去掉原因:因为不需要渲染的viewport不在此中所以无法判断几个viewport
  115093. for(let i=0; i<viewports.length; i++){
  115094. let viewport = viewports[i];
  115095. let params = $.extend({},params_);
  115096. params.viewport = viewport;
  115097. //if(!params.target){
  115098. params.camera = params.camera || viewport.camera;
  115099. params.extraEnableLayers = viewport.extraEnableLayers;
  115100. params.cameraLayers = viewport.cameraLayers;
  115101. //}
  115102. var left,bottom,width,height;
  115103. {
  115104. left = Math.ceil(renderSize.x * viewport.left);
  115105. bottom = Math.ceil(renderSize.y * viewport.bottom);
  115106. if(params_.target){//有target时最好viewport是专门建出来的
  115107. width = renderSize.x * viewport.width; //target的大小可能和viewport不同,比如截图,这时会更改viewport大小
  115108. height = renderSize.y * viewport.height;
  115109. }else {
  115110. width = viewport.resolution.x; // 用的是client的width和height
  115111. height = viewport.resolution.y;
  115112. }
  115113. if(width == 0 || height == 0)continue;//return
  115114. width = Math.ceil(width); //使用ceil,当原本有小数时,会重叠一个像素,无所谓
  115115. height = Math.ceil(height);
  115116. let scissorTest = viewport.width<1 || viewport.height<1;
  115117. if(params_.target){
  115118. params_.target.viewport.set(left, bottom, width, height);
  115119. scissorTest && params_.target.scissor.set(left, bottom, width, height);
  115120. params_.target.scissorTest = scissorTest;
  115121. this.renderer.setRenderTarget(params_.target);
  115122. }else {
  115123. /* if(viewports.length == 1 && left == 0 && bottom == 0){
  115124. left = 1 , width-=1 //这种情况下渲染也会有问题,只有鼠标的地方刷新 估计是pick那影响的
  115125. } */
  115126. /* if(scissorTest && left == 0 && bottom == 0){
  115127. left = 1 , width-=1
  115128. } */
  115129. if(viewport.forViewOffset){ //分块渲染,渲染时的camera还是原来的,但加载点云时的camera是分块中的
  115130. viewport.forViewOffset.camera.setViewOffset(renderSize.x, renderSize.y, left, renderSize.y - bottom - height, width, height);
  115131. this.renderer.setViewport(0,0,renderSize.x, renderSize.y);
  115132. viewport.resolution.copy(viewport.forViewOffset.originViewport.resolution);
  115133. viewport.resolution2.copy(viewport.forViewOffset.originViewport.resolution2); //后续渲染都当做原先的viewport
  115134. }else {
  115135. this.renderer.setViewport(left, bottom, width, height); //规定视口,影响图形变换(画布的使用范围)
  115136. }
  115137. //scissorTest && console.log('setScissor', left, bottom, width, height)
  115138. scissorTest && this.renderer.setScissor( left, bottom, width, height );//规定渲染范围
  115139. this.renderer.setScissorTest( scissorTest );//开启WebGL剪裁测试功能,如果不开启,.setScissor方法设置的范围不起作用 | width==1且height==1时开启会只有鼠标的地方刷新,很奇怪
  115140. }
  115141. }
  115142. //if(needsResize){
  115143. this.ifEmitResize( { viewport} );
  115144. //}
  115145. viewer.dispatchEvent({type: "render.begin", viewer: viewer, viewport, params });
  115146. viewport.beforeRender && viewport.beforeRender();
  115147. if(viewport.render){
  115148. if(!viewport.render($.extend({}, params, {
  115149. renderer:this.renderer, clear:this.clear.bind(this), resize:null,
  115150. renderBG:this.renderBG.bind(this), force:true //viewer content_change时map也直接渲染吧 //!viewport.noPointcloud //如果要渲染点云,必须也一直渲染地图,否则地图会被覆盖(点云目前未能获取是否改变,也可能有其他动态物体,所以还是一直渲染的好)
  115151. }))) continue//return
  115152. }else {
  115153. this.clear(params);
  115154. pRenderer.clearTargets(params);
  115155. this.renderBG(viewport);
  115156. if(Potree.settings.notAdditiveBlending){
  115157. params.renderBeforeCloud = true;
  115158. this.renderOverlay1(params); //先渲染不透明的model。 但drawedModelOnRT时这里提前多渲染了一遍
  115159. }
  115160. }
  115161. if(!viewport.noPointcloud ){
  115162. if(params_.needWaitLoadPoint){
  115163. await this.waitPointLoad(null, params_.maxTimeForPointLoad, viewport ); //resolution得用split前整个的viewport的
  115164. }else {
  115165. this.updateViewPointcloud(params.camera, viewport.resolution, true);
  115166. }
  115167. pRenderer.render(params); //渲染点云 skybox
  115168. }
  115169. if(Potree.settings.notAdditiveBlending){ // 融合页面才用到
  115170. params.renderBeforeCloud = false;
  115171. this.renderOverlay1(params);
  115172. this.renderOverlay2(params);
  115173. }else {
  115174. this.renderOverlay(params);
  115175. }
  115176. viewport.afterRender && viewport.afterRender();
  115177. this.dispatchEvent({type: "render.end", viewer: this, viewport });
  115178. viewport.needRender = false;
  115179. viewport.lastRenderTime = Date.now();
  115180. }
  115181. /* if(params_.screenshot){ //抗锯齿
  115182. this.composer.render();
  115183. } */
  115184. this.renderer.setRenderTarget(null);
  115185. viewer.scene.pointclouds[0] && this.addFakeMeasure('visibleNodes', viewer.scene.pointclouds[0].visibleNodes.length );//
  115186. this.addFakeMeasure('numVisiblePoints', Potree.numVisiblePoints/100000);//十万 numVisiblePoints和帧率成反比(若每一帧都render的话),和render用时成正比 (y=kn+b)。但visibleNodes个数也影响,多的话也更卡。visibleNodes和numVisiblePoints不成正比,少的visibleNodes可能numVisiblePoints多
  115187. viewer.addTimeMark('renderDefault','end');
  115188. }
  115189. renderBG(viewport){
  115190. let background = viewport.background || viewer.background;
  115191. let backgroundOpacity = viewport.backgroundOpacity == void 0 ? viewer.backgroundOpacity : viewport.backgroundOpacity;//如果想完全透明,只需要backgroundOpacity为0
  115192. if(backgroundOpacity != 0){//绘制背景. 为了防止相机移动后天空不动有点死板,做一定的动态
  115193. if(background === "skybox"){
  115194. //限制相机到原点的距离。
  115195. let skyCamera = viewport.camera.type == "OrthographicCamera" ? viewer.skybox.cameraOrtho : viewer.skybox.camera;
  115196. let safeRatio = 0.02;
  115197. let safeWidth = Potree.config.skyboxBgWidth * safeRatio / 2; //相机只能在这个范围内移动
  115198. if(!viewport.skyboxFixPos){ //允许不在全景图中心,允许位移造成一定程度畸变
  115199. let dir = new Vector3().subVectors(viewport.camera.position, viewer.bound.center);
  115200. let length = dir.length();
  115201. const moveMax = 100;
  115202. let aimRadius = easing.easeOutQuart(Math.min(length, moveMax) , 0, safeWidth, moveMax); //(x, startY, wholeY, maxX) 当自变量为0-moveMax时,相机位移量为0-safeWidth
  115203. dir.multiplyScalar(aimRadius/length);
  115204. skyCamera.position.copy(dir);
  115205. }else {
  115206. skyCamera.position.set(0,0,0);
  115207. }
  115208. skyCamera.rotation.copy(viewport.camera.rotation);
  115209. skyCamera.aspect = viewport.camera.aspect;
  115210. if(viewport.camera.type == "OrthographicCamera"){ //调节zoom
  115211. skyCamera.left = viewport.camera.left; skyCamera.right = viewport.camera.right; skyCamera.top = viewport.camera.top; skyCamera.bottom = viewport.camera.bottom;
  115212. let a = Potree.config.skyboxBgWidth / 2 - safeWidth;
  115213. let minY = Math.max(skyCamera.right / a, skyCamera.top / a, viewport.skyboxMinZoom||0); //能够使skybox铺满画布的最小zoom. 提示:越远zoom越小
  115214. let maxY = Math.max(20, minY) ;//自定义一个 不会超过的最大实际zoom
  115215. //viewport.camera.zoom自变量的变化范围:
  115216. let minX = 1;
  115217. let maxX = 80;
  115218. let x = MathUtils.clamp(viewport.camera.zoom - minX, minX, maxX);
  115219. skyCamera.zoom = easing.easeOutCubic(x-minX, minY, maxY-minY, maxX-minX); //自变量范围从0开始,所以减去minX
  115220. //pos的范围先不管了 其实aimRadius是有误的,但效果还行
  115221. }else {
  115222. skyCamera.fov = viewport.camera.fov;
  115223. skyCamera.zoom = 1;
  115224. }
  115225. viewport.skyboxRenderFun && viewport.skyboxRenderFun();
  115226. skyCamera.updateProjectionMatrix();
  115227. skyCamera.updateMatrixWorld();
  115228. viewer.renderer.render(viewer.skybox.scene, skyCamera);
  115229. }else if(background === 'gradient'){
  115230. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg);
  115231. viewer.renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  115232. }else if(background === 'overlayColor'){//在不clear的前提下加一层背景色
  115233. viewer.scene.bg2.material.color.copy(viewport.backgroundColor);
  115234. viewer.scene.bg2.material.opacity = viewport.backgroundOpacity;
  115235. viewer.scene.cameraBG.layers.set(Potree.config.renderLayers.bg2);
  115236. viewer.renderer.render(viewer.scene.scene, viewer.scene.cameraBG);
  115237. }
  115238. }
  115239. //全景图的部分和点云有点相关就不移动到这了。但是如果是showPanos模式,就不要渲染背景了。
  115240. }
  115241. /*
  115242. 关于透明度:
  115243. 由于点云和mesh是分开渲染的,且材质很不一样,所以透明和blend有冲突
  115244. 1 如果点云的blend是AdditiveBlending,也就是普通的叠加模式。
  115245. 则半透明点云的depthTest和depthWrite都为false
  115246. 这时候mesh要后渲染,且depthWrite不能为false(除非depthTest也为false),否则将被点云遮住。
  115247. 2 如果点云的blend是普通型
  115248. 则半透明点云的depthTest和depthWrite都为true。(为何depthWrite不能像mesh一样为false, 否则点云自身透明会错乱,可能因为太多points了)
  115249. 这时候若mesh全部先渲染,则 透过depthWrite为false的半透明mesh看不透明点云,mesh会完全被点云遮住。但是透明的物体就是depthWrite要为false,否则也会完全遮住点云
  115250. 即使是后渲染半透明的mesh,若透过点云看mesh,mesh会完全被点云遮住(为什么之前遇到过 透过点云看mesh,点云会显示不出)
  115251. 最终选择是先渲染不透明的mesh,然后点云,然后透明的mesh。虽然点云对mesh透明会失效。
  115252. */
  115253. renderOverlay(params){
  115254. viewer.addTimeMark('renderOverlay','start');
  115255. this.renderOverlay1(params);
  115256. this.renderOverlay2(params);
  115257. viewer.addTimeMark('renderOverlay','end');
  115258. }
  115259. renderOverlay1(params){
  115260. let camera = params.camera ? params.camera : this.scene.getActiveCamera();
  115261. let renderer = params.renderer || this.renderer;
  115262. this.reticule.updateAtViewports(params.viewport);
  115263. renderer.setRenderTarget(params.target||null);
  115264. //为什么要在点云之后渲染,否则透明失效 、 会被点云覆盖
  115265. let cameraLayers;
  115266. if(params.cameraLayers) cameraLayers = params.cameraLayers;
  115267. else {
  115268. if(params.viewport.name == "mapViewport" )cameraLayers = ['bothMapAndScene', 'light'];
  115269. else {
  115270. cameraLayers = ['sceneObjects', 'light', 'bothMapAndScene' ];
  115271. if(!params.drawedModelOnRT){
  115272. cameraLayers.push('model');
  115273. }
  115274. }
  115275. }
  115276. if(cameraLayers.length){
  115277. Potree.Utils.setCameraLayers(camera, cameraLayers, params.extraEnableLayers); //透明贴图层 skybox 、reticule marker 不能遮住测量线
  115278. if('renderBeforeCloud' in params){
  115279. this.scene.scene.traverse((object)=>{
  115280. if(object.material){
  115281. Potree.Utils.updateVisible(object, 'renderOpa',
  115282. (params.renderBeforeCloud && (object.material.opacity<1 || !object.material.depthTest) || (!params.renderBeforeCloud) && (object.material.opacity==1 && object.material.depthTest))? false:true);
  115283. //点云之前渲染的话隐藏半透明的, 点云之后渲染的话隐藏不透明的。 depthTest==false的也最后渲染
  115284. }
  115285. });//ground的材质中opacity为1,所以被当做不透明了
  115286. }
  115287. viewer.dispatchEvent({type: "render.begin2" , name:'scene', viewport:params.viewport });
  115288. renderer.render(this.scene.scene, camera);
  115289. if('renderBeforeCloud' in params){
  115290. this.scene.scene.traverse((object)=>{
  115291. if(object.material){
  115292. Potree.Utils.updateVisible(object, 'renderOpa', true); //恢复
  115293. }
  115294. });
  115295. }
  115296. }
  115297. this.dispatchEvent({type: "render.pass.scene", viewer: viewer});
  115298. }
  115299. renderOverlay2(params){
  115300. let renderer = params.renderer || this.renderer;
  115301. let camera = params.camera ? params.camera : this.scene.getActiveCamera();
  115302. //清除深度 !!!!
  115303. renderer.clearDepth();
  115304. if(!params.magnifier){
  115305. //测量线
  115306. this.dispatchEvent({type: "render.pass.perspective_overlay", camera, screenshot:params.screenshot,viewport:params.viewport, renderer});
  115307. if(!params.screenshot && params.viewport.name != "mapViewport" ){
  115308. Potree.Utils.setCameraLayers(camera, ['magnifier']); //magnifier 遮住测量线
  115309. renderer.render(this.scene.scene, camera);
  115310. }
  115311. }
  115312. if(params.viewport.name != "mapViewport" ) {
  115313. Potree.Utils.setCameraLayers(camera, ['volume','transformationTool']);
  115314. //viewer.dispatchEvent({type: "render.begin2" , name:'clip&trans',viewport:params.viewport })
  115315. renderer.render(this.clippingTool.sceneVolume, camera); //official 可以删
  115316. renderer.render(this.transformationTool.scene, camera);
  115317. }
  115318. }
  115319. setLimitFar(state){//切换是否limitFar
  115320. viewer.mainViewport.camera.limitFar = !!state;
  115321. if(state){
  115322. viewer.mainViewport.camera.near = 0.02;
  115323. viewer.mainViewport.camera.far = Potree.settings.displayMode == 'showPanos' ? viewer.farWhenShowPano : Potree.settings.cameraFar;
  115324. viewer.mainViewport.camera.updateProjectionMatrix();
  115325. }
  115326. }
  115327. setClipState(state){//有时候需要暂时关闭下clip
  115328. state = !!state;
  115329. if(this.clipUnabled == !state)return
  115330. this.scene.volumes.filter(v=>/* v.clip && */ v instanceof Potree.BoxVolume).map(volume=>{
  115331. volume.clip = state;
  115332. Potree.Utils.updateVisible(volume, 'setClipState', state);
  115333. });
  115334. this.clipUnabled = !state;
  115335. }
  115336. /* 大规模WebGL应用引发浏览器崩溃的几种情况及解决办法
  115337. https://blog.csdn.net/weixin_30378311/article/details/94846947 */
  115338. async render(params={}){//add params
  115339. viewer.addTimeMark('render','start');
  115340. const vrActive = this.renderer.xr.isPresenting;
  115341. let SiteModel = viewer.modules.SiteModel;
  115342. if(this.screenshoting && !params.screenshot)return //正在截图
  115343. let s = SiteModel.editing && SiteModel.selected && (SiteModel.selected.buildType == 'room' || SiteModel.selected.buildType == 'floor'); //空间模型的房间选中材质是需要depth的,这时候需要绘制两次点云
  115344. Potree.settings.pointEnableRT = !this.screenshoting && (this.scene.measurements.filter(e=>e.visible).length > 0 || s );
  115345. if(vrActive){
  115346. this.renderVR();
  115347. }else {
  115348. let specialRender = !!params.viewports;
  115349. let viewports = params.viewports || this.viewports;
  115350. if(!this.needRender){
  115351. viewports = viewports.filter(v=>v.needRender); //可以渲染的条件是viewer或viewport的needRender为true
  115352. }
  115353. viewports = viewports.filter(v=>v.active);
  115354. if(viewports.length > 0){
  115355. params.viewports = viewports;
  115356. if(this.outlinePass.selectedObjects.length && this.outlinePass.edgeStrength > 0 && !params.screenshot
  115357. // || this.images360.fastTranMaskPass.enabled
  115358. ){
  115359. let scenes = this.inputHandler.interactiveScenes.concat(this.scene.scene).concat(viewer.scene.scenePointCloud);
  115360. this.composer.render(scenes, null, this.viewports, this.renderDefault.bind(this));
  115361. }else {
  115362. await this.renderDefault(params);
  115363. }
  115364. }
  115365. if(!specialRender) this.needRender = false;
  115366. }
  115367. viewer.addTimeMark('render','end');
  115368. }
  115369. startScreenshot(info={}, width=800, height=400, compressRatio ){//add
  115370. //let deferred = info.deferred || $.Deferred();
  115371. let getImageDeferred = info.getImageDeferred || $.Deferred();
  115372. let finishDeferred = info.finishDeferred || $.Deferred();
  115373. let viewerMaster = info.map ? this.mapViewer : this; //截图主体
  115374. let useMap = info.map || info.type == 'measure' || info.type.includes('prism2d');
  115375. if(Potree.settings.displayMode == 'showPanos' && viewer.mainViewport.view.isFlying('pos')){//如果在飞,飞完再截图
  115376. info.getImageDeferred = getImageDeferred , info.finishDeferred = finishDeferred;
  115377. let f = ()=>{
  115378. this.startScreenshot(info, width, height, compressRatio);
  115379. };
  115380. viewer.mainViewport.view.addEventListener('flyingDone', f, {once:true});
  115381. return {getImagePromise:getImageDeferred.promise(), finishPromise:finishDeferred.promise()}
  115382. }
  115383. var startTime = Date.now();
  115384. //抗锯齿待加 1 post处理 2截图大张再抗锯齿缩小
  115385. this.pauseTestMaxLevel = true;
  115386. this.screenshoting = true;
  115387. console.log('startScreenshot: '+startTime);
  115388. let updateCamera = ()=>{
  115389. viewports.forEach(e=>{
  115390. e.view.applyToCamera(e.camera); //因为fly时只更新了view所以要强制更新下camera
  115391. this.dispatchEvent({ //update map and sprite, mapChanged
  115392. type: "camera_changed",
  115393. camera: e.camera,
  115394. viewport : e,
  115395. changeInfo:{positionChanged:true,changed:true}
  115396. });
  115397. });
  115398. };
  115399. let screenshot = async ()=>{
  115400. let pose;
  115401. useMap && (viewer.mapViewer.needRender = true);
  115402. info.beforeScreenshot && info.beforeScreenshot();
  115403. let render = async ()=>{
  115404. this.needRender = true;
  115405. viewports.forEach(e=>e.active = true);
  115406. if(info.useRenderTarget){
  115407. //离屏渲染 有抗锯齿问题、在手机上速度慢 主视图一样会变内容,还是不用这个了
  115408. var { dataUrl } = viewerMaster.makeScreenshot( new Vector2(width,height), null, compressRatio );
  115409. }else {
  115410. //直接渲染 会改变canvas大小
  115411. let canvas = viewerMaster.renderer.domElement;
  115412. //canvas.width = width, canvas.height = height //不需要改canvas大小, 只需要 this.renderer.setSize(width, height ); 前面updateScreenSize已经执行
  115413. await viewerMaster.render({ screenshot : true, width , height, resize :true, needWaitLoadPoint:!!info.splitRenderInfo, maxTimeForPointLoad:info.maxTimeForPointLoad }); //需要resize
  115414. /* if(info.type.includes('prism2d')){//o.map要为true
  115415. viewer.dispatchEvent({type:'resize', viewport:viewer.mapViewer.viewports[0]}) //借用viewer通知lineMaterial resize
  115416. viewerMaster.renderOverlay()
  115417. } */
  115418. var dataUrl = canvas.toDataURL('image/png',compressRatio);
  115419. }
  115420. return dataUrl
  115421. };
  115422. let dataUrl;
  115423. if(info.splitRenderInfo){//为了防崩溃,分区域批次渲染
  115424. let {wc , hc} = info.splitRenderInfo;
  115425. let camera = viewer.mainViewport.camera;
  115426. let dataUrls = [];
  115427. let width_ = Math.ceil(1/wc * width) , height_ = Math.ceil(1/hc * height); //可能加起来比原图大,没事到时候边界会重合
  115428. viewer.updateScreenSize({forceUpdateSize:true, width:width_, height:height_, forTarget:info.useRenderTarget}); //更新viewports相机透视 使focusOnObject在此窗口大小下
  115429. for(let i=0;i<wc;i++){
  115430. let col = [];
  115431. for(let j=0;j<hc;j++){
  115432. let left = Math.ceil((-wc/2+0.5+i)*width_), top = Math.ceil((-hc/2+0.5+j)*height_);
  115433. camera.setViewOffset(width_, height_, left, top , width_, height_); //顺序从上到下从左到右
  115434. let dataUrl = await render();
  115435. //Common.downloadFile(dataUrl, 'screenshot'+ i+':'+j+'.png')
  115436. col.push({dataUrl, width:width_, height:height_});
  115437. }
  115438. dataUrls.push(col);
  115439. }
  115440. camera.clearViewOffset();
  115441. dataUrl = await Utils.combineImgs(dataUrls, compressRatio, width, height);
  115442. }else {
  115443. dataUrl = await render();
  115444. }
  115445. if(info.splitRenderInfo){
  115446. viewer.viewports = [viewer.mainViewport];
  115447. }
  115448. if(!Potree.settings.isOfficial){
  115449. Common.downloadFile(dataUrl, 'screenshot.png');
  115450. }
  115451. var finish = ()=>{
  115452. oldStates.viewports.forEach(old=>{//恢复相机
  115453. var viewport = viewports.find(v=>v.name == old.name);
  115454. viewport.left = old.left; viewport.bottom = old.bottom;
  115455. viewport.width = old.width; viewport.height = old.height;
  115456. viewport.view.copy(old.view);
  115457. //viewport.view.applyToCamera(viewport.camera);
  115458. if(viewport.camera.isOrthographicCamera){
  115459. viewport.camera.zoom = viewport.view.zoom;
  115460. }
  115461. });
  115462. viewerMaster.updateScreenSize({forceUpdateSize:true});//更新像素
  115463. /* oldStates.viewports.forEach(old=>{//恢复相机
  115464. var viewport = [mapViewport, mainViewport].find(v=>v.name == old.name);
  115465. this.dispatchEvent({ //update map
  115466. type: "camera_changed",
  115467. camera: viewport.camera,
  115468. viewport : viewport
  115469. })
  115470. }) */
  115471. updateCamera();
  115472. finishDeferred.resolve({dataUrl, pose});
  115473. info.map || setTimeout(()=>{
  115474. if(!this.screenshoting){
  115475. //Potree.settings.pointNoLimit = false
  115476. Potree.settings.pointDensity = 'high';
  115477. //console.warn('恢复pointDensity')
  115478. /* if(viewer.scene.pointclouds[0].material.oldSize_ ){
  115479. viewer.scene.pointclouds[0].material.size = viewer.scene.pointclouds[0].material.oldSize_
  115480. viewer.scene.pointclouds[0].material.oldSize_ = null
  115481. } */
  115482. }
  115483. },500); //延迟:避免连续多次截图时释放点云
  115484. this.screenshoting = false;
  115485. console.log('screenshot done: ' + startTime, 'costTime', (Date.now() - startTime) + 'ms');
  115486. };
  115487. {//恢复:
  115488. this.backgroundOpacity = oldStates.bgOpacity;
  115489. this.background = oldStates.background;
  115490. this.pauseTestMaxLevel = false;
  115491. oldStates.displayMode && (Potree.settings.displayMode = oldStates.displayMode);
  115492. if(info.type == 'measure' || info.type.includes('prism2d')){
  115493. this.modules.SiteModel.pauseUpdateEntity = false;
  115494. this.focusDatasets = null;
  115495. this.scene.measurements.forEach(e=>Potree.Utils.updateVisible(e, 'screenshot',true));
  115496. info.type == 'measure' && info.measurement.setSelected(false, 'screenshot');
  115497. }
  115498. if(info.type.includes('prism2d')){
  115499. //viewer.mapViewer.transparentBG = false;
  115500. (info.prisms || [info.prism]).forEach(prism=>{
  115501. prism.changeStyleForScreenshot(false);
  115502. if(info.type == 'prism2d-single'){
  115503. prism.baseModel && (Potree.Utils.updateVisible(prism.baseModel, 'screenshot', false, 3, 'cancel'), Potree.Utils.setObjectLayers(prism.baseModel, 'model'));
  115504. prism.setEditState(false);
  115505. }
  115506. });
  115507. }
  115508. this.images360.panos.forEach(pano=>{
  115509. Potree.Utils.updateVisible(pano, 'screenshot', true);
  115510. });
  115511. Potree.Utils.updateVisible(this.reticule, 'screenshot', true);
  115512. if(useMap){
  115513. Potree.Utils.updateVisible(this.mapViewer.cursor, 'screenshot', true);
  115514. if(oldStates.attachedToViewer != this.mapViewer.attachedToViewer){
  115515. this.mapViewer.attachToMainViewer(!!oldStates.attachedToViewer );
  115516. }
  115517. if(oldStates.attachedToViewer && this.mapViewer.splitDir != oldStates.oldSplitDir){
  115518. this.mapViewer.changeSplitScreenDir(oldStates.oldSplitDir);
  115519. }
  115520. mapViewport.noPointcloud = oldStates.noPointcloud;
  115521. Potree.Utils.updateVisible(viewer.mapViewer.mapLayer.sceneGroup, 'screenshot-prism', true);
  115522. }
  115523. let recover = ()=>{
  115524. if(Potree.settings.displayMode == 'showPanos') {
  115525. viewer.images360.flyToPano({pano:oldStates.pano, duration:0, callback:()=>{
  115526. finish();
  115527. }});
  115528. }else {
  115529. finish();
  115530. }
  115531. };
  115532. if(info.ifGetPose){
  115533. Potree.sdk.scene.getPose().done(pose_ =>{
  115534. pose = pose_;
  115535. getImageDeferred.resolve({dataUrl, pose});
  115536. recover();
  115537. });
  115538. }else {
  115539. recover();
  115540. }
  115541. }
  115542. };// screenshot end
  115543. let mapViewport;
  115544. let mainViewport = this.mainViewport;
  115545. let viewports = [], oldStates = {
  115546. viewports:[],
  115547. pano: Potree.settings.displayMode == 'showPanos' ? viewer.images360.currentPano : null,
  115548. bgOpacity : this.backgroundOpacity,
  115549. background: this.background
  115550. };
  115551. if(!info.type.includes('prism2d')){
  115552. viewports.push(mainViewport);
  115553. mainViewport.camera.isOrthographicCamera && (mainViewport.view.zoom = mainViewport.camera.zoom);
  115554. oldStates.viewports.push(mainViewport.clone());
  115555. }
  115556. if(useMap){
  115557. mapViewport = this.mapViewer.viewports[0];
  115558. mapViewport.view.zoom = mapViewport.camera.zoom;
  115559. viewports.push(mapViewport);
  115560. oldStates.viewports.push(mapViewport.clone());
  115561. oldStates.attachedToViewer = this.mapViewer.attachedToViewer;
  115562. oldStates.noPointcloud = mapViewport.noPointcloud;
  115563. oldStates.displayMode = Potree.settings.displayMode;
  115564. Potree.Utils.updateVisible(this.mapViewer.cursor, 'screenshot', false);//令mapCursor不可见
  115565. }
  115566. viewports.forEach(e=>e.active = false); //暂停渲染
  115567. if(info.hideMarkers){
  115568. this.images360.panos.forEach(pano=>{//令漫游点不可见
  115569. Potree.Utils.updateVisible(pano, 'screenshot', false);
  115570. });
  115571. }
  115572. Potree.Utils.updateVisible(this.reticule, 'screenshot', false);//令reticule不可见
  115573. if(info.bgOpacity != void 0){
  115574. this.backgroundOpacity = info.bgOpacity;
  115575. }
  115576. if(info.background != void 0){
  115577. this.background = info.background;
  115578. }
  115579. Potree.settings.pointDensity = info.pointDensity || 'screenshot';
  115580. let focusDatasets = (measurements)=>{
  115581. this.focusDatasets = [];
  115582. measurements.forEach(measure=>{
  115583. measure.points_datasets.forEach(e=>{
  115584. let p = viewer.scene.pointclouds.find(a=>a.dataset_id == e);
  115585. if(p && !this.focusDatasets.includes(p)){
  115586. this.focusDatasets.push(p);
  115587. }
  115588. });
  115589. });
  115590. this.updateFpVisiDatasets();
  115591. };
  115592. if(info.type == 'measure'){//要截图双屏
  115593. this.scene.measurements.forEach(e=>Potree.Utils.updateVisible(e,'screenshot',e == info.measurement) );
  115594. info.measurement.setSelected(true, 'screenshot');
  115595. //因为分屏后位置才最终确定,才能确定是否显示出floorplan所以先分屏
  115596. if(Potree.settings.floorplanEnable){
  115597. oldStates.oldSplitDir = this.mapViewer.splitDir;
  115598. this.mapViewer.attachToMainViewer(true, 'measure', 0.5 , {dir:'leftRight'} );
  115599. }
  115600. viewer.updateScreenSize({forceUpdateSize:true, width, height, forTarget:info.useRenderTarget}); //更新viewports相机透视 使focusOnObject在此窗口大小下
  115601. let begin = ()=>{
  115602. useMap = this.mapViewer.attachedToViewer;
  115603. updateCamera();
  115604. if(useMap){
  115605. let waitMap = ()=>{
  115606. console.log('waitMap: '+startTime, Date.now(), this.mapViewer.mapLayer.loadingInProgress );
  115607. this.mapViewer.waitLoadDone(screenshot.bind(this));//等待地图所有加载完
  115608. };
  115609. this.waitPointLoad(waitMap,info.maxTimeForPointLoad);
  115610. }else {
  115611. this.waitPointLoad(screenshot,info.maxTimeForPointLoad);
  115612. }
  115613. };
  115614. let {promise} = this.focusOnObject(info.measurement, 'measure', 0, {
  115615. basePanoSize:1024, gotoBestView:true,
  115616. //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) //有地图的话为了显示出名字需要更大范围
  115617. });//注意:不同角度截图 得到三维的会不一样,因为focusOnObject是根据方向的
  115618. promise.done(()=>{
  115619. //console.log('promise.done')
  115620. //根据当前位置更新floorplan显示
  115621. //console.log('view Pos ', this.mainViewport.view.position.toArray())
  115622. this.updateDatasetAt(true);
  115623. this.modules.SiteModel.updateEntityAt(true, {measure:info.measurement}); //更新测量线所在楼层,展示俯视图
  115624. if(!this.modules.SiteModel.inEntity){
  115625. focusDatasets([info.measurement]);
  115626. }
  115627. this.modules.SiteModel.pauseUpdateEntity = true;
  115628. //console.log('currentFloor', this.modules.SiteModel.currentFloor, 'currentDataset', this.atDatasets )
  115629. let floorplanShowed = this.mapViewer.mapLayer.maps.some(e => e.name.includes('floorplan') && e.objectGroup.visible);//如果没有floorplan展示就不分屏(如果focus时飞出数据集从而不展示怎么办。尤其是俯瞰比较长的线时容易这样,或许要根据其所在数据集强制显示)
  115630. if(!floorplanShowed && this.mapViewer.attachedToViewer){
  115631. this.mapViewer.attachToMainViewer(false); //取消分屏
  115632. viewer.updateScreenSize({forceUpdateSize:true, width, height, forTarget:info.useRenderTarget}); //更新viewports相机透视
  115633. let {promise} = this.focusOnObject(info.measurement, 'measure', 0, {basePanoSize:1024,gotoBestView:true,} );//因画面比例更改,重新focus
  115634. promise.done(()=>{
  115635. begin();
  115636. });
  115637. }else {
  115638. begin();
  115639. }
  115640. });
  115641. }else if(info.type.includes('prism2d')){
  115642. let points = [], prisms = info.type == 'prism2d-all' ? info.prisms: [info.prism];
  115643. this.mapViewer.attachToMainViewer(true, 'screenshot', 1 , {/* dir:'leftRight' */} );
  115644. viewer.updateScreenSize({forceUpdateSize:true, width, height, forTarget:info.useRenderTarget}); //更新viewports相机透视 使focusOnObject在此窗口大小下
  115645. prisms.forEach(prism=>{
  115646. points.push(...prism.points);
  115647. prism.setSelected(false);
  115648. prism.changeStyleForScreenshot(true, {hideLabel: info.type != 'prism2d-all', showName: info.type == 'prism2d-all' });
  115649. if(info.type == 'prism2d-single') {
  115650. prism.baseModel && (Potree.Utils.updateVisible(prism.baseModel, 'screenshot', true, 3, 'add'), Potree.Utils.setObjectLayers(prism.baseModel, 'bothMapAndScene'));
  115651. prism.setEditState(true);
  115652. }
  115653. });
  115654. this.scene.measurements.forEach(e=>Potree.Utils.updateVisible(e,'screenshot', prisms.includes(e)) );
  115655. this.backgroundOpacity = 0;
  115656. let {promise} = this.focusOnObject({points}, 'prisms2d', 0, {
  115657. minMapWidth: 0.5 , onlyMap:true, focusBoundCenter:true, boundExpandRatio:1.4
  115658. });
  115659. promise.done(()=>{
  115660. updateCamera();
  115661. if(info.type == 'prism2d-all'){//全部 带平面图
  115662. focusDatasets(prisms); //更新平面图 可能有漏洞,当不在任何一个数据集内的话?
  115663. this.mapViewer.waitLoadDone(screenshot.bind(this));//等待地图所有加载完
  115664. }else {//single
  115665. mapViewport.noPointcloud = false; //显示点云,而非平面图
  115666. Potree.settings.displayMode = 'showPointCloud';
  115667. Potree.Utils.updateVisible(viewer.mapViewer.mapLayer.sceneGroup, 'screenshot-prism', false);
  115668. this.waitPointLoad(screenshot, 5000);
  115669. }
  115670. });
  115671. }else {//default
  115672. let done = ()=>{
  115673. updateCamera();
  115674. if(info.splitRenderInfo){
  115675. screenshot();
  115676. }else {
  115677. this.waitPointLoad(screenshot, info.maxTimeForPointLoad);
  115678. }
  115679. };
  115680. if(info.focusObjectInfo){
  115681. viewer.updateScreenSize({forceUpdateSize:true, width, height, forTarget:info.useRenderTarget}); //更新viewports相机透视 使focusOnObject在此窗口大小下
  115682. let {promise} = this.focusOnObject( ...info.focusObjectInfo);
  115683. promise.done(()=>{
  115684. done();
  115685. });
  115686. }else {
  115687. done();
  115688. }
  115689. }
  115690. /*
  115691. 测量线的截图因为要调用分屏的,会改变画面
  115692. 但是普通截图的话,不会改变画面
  115693. */
  115694. return {getImagePromise:getImageDeferred.promise(), finishPromise:finishDeferred.promise()}
  115695. }
  115696. async waitPointLoad(done, maxTimeForPointLoad, viewport = viewer.mainViewport, resolution ){
  115697. return new Promise((resolve,reject)=>{
  115698. let finish;
  115699. let dealDone = ()=>{
  115700. viewer.removeEventListener('update',update);
  115701. viewer.removeEventListener('overPointBudget',decreaseLevel);
  115702. finish || done && done();
  115703. finish = true;
  115704. resolve();
  115705. };
  115706. let decreaseLevel = (e)=>{ //降点云level 但基本降完也不会再加载低等级的点云了,所以是否直接不降?即使质量不平均
  115707. if(e.restQueueSize < 10)return ;//差不多完成了
  115708. let pointclouds = viewer.scene.pointclouds.filter(e=>e.visibleNodes.length);
  115709. console.log('准备decreaseLevel, numVisiblePoints', e.numVisiblePoints, '最小numVisiblePoints占比', 1/pointclouds.length );
  115710. pointclouds.forEach(pointcloud=>{
  115711. let percent = pointcloud.numVisiblePoints / e.numVisiblePoints;
  115712. //console.log('numVisiblePoints占总比', pointcloud.dataset_id, percent )
  115713. if(percent < 1/pointclouds.length)return
  115714. let old = pointcloud.maxLevel;
  115715. let levels = pointcloud.visibleNodes.map(e=>e.getLevel());
  115716. let actMaxLevel = Math.max.apply(null, levels); //实际加载到的最高的node level
  115717. pointcloud.maxLevel = actMaxLevel - 1;
  115718. console.warn(pointcloud.dataset_id,'decreaseLevel,新maxLevel', actMaxLevel - 1, '原maxlevel', old );
  115719. });
  115720. };
  115721. /* if(Potree.settings.displayMode == 'showPointCloud'){
  115722. viewer.updateScreenSize({forceUpdateSize:true, width, height, forTarget:info.useRenderTarget})//需要先setSize才能加载范围内的点云
  115723. } */
  115724. //updateCamera()
  115725. //viewer.addEventListener('overPointBudget',decreaseLevel)
  115726. let update = ()=>{ //前提:已经禁止渲染,仅加载点云
  115727. let camera = viewport.forViewOffset ? viewport.forViewOffset.camera : viewport.camera;
  115728. Potree.updatePointClouds(viewer.scene.pointclouds, camera , resolution || viewport.resolution );
  115729. };
  115730. viewer.addEventListener('update',update);
  115731. update();
  115732. let maxTime = maxTimeForPointLoad || 2000;
  115733. document.hidden && (maxTime *= 6); //离开页面后会变成1秒1帧
  115734. setTimeout(()=>{
  115735. if(Potree.pointsLoading && Potree.settings.displayMode == 'showPointCloud'){//如果还在加载
  115736. viewer.addEventListener('pointsLoaded',()=>{ //点云加载完时(不一定准确)
  115737. if(!finish)console.log('加载完毕', ' numVisiblePoints', Potree.numVisiblePoints);
  115738. dealDone();
  115739. },{once:true});
  115740. let overTime = ()=>{//超时不候(其实之后等待地图还会再加载几秒)
  115741. if(document.hidden){
  115742. return setTimeout(overTime, maxTime)
  115743. }
  115744. if(!finish)console.warn('超时, numVisiblePoints', Potree.numVisiblePoints);
  115745. dealDone();
  115746. };
  115747. setTimeout(overTime, maxTime);
  115748. }else {
  115749. console.log('已经加载完,无需再加载点云 numVisiblePoints', Potree.numVisiblePoints);
  115750. dealDone();
  115751. }
  115752. },200);//先加载一段时间
  115753. })
  115754. }
  115755. focusOnObject(object, type, duration, o={} ) {
  115756. //飞向热点、测量线等 。
  115757. //console.log('focusOnObject: ', object, type)
  115758. let deferred = o.deferred || $.Deferred();
  115759. let target = new Vector3, //相机focus的位置
  115760. position = new Vector3, //相机最终位置
  115761. dis; //相机距离目标
  115762. duration = duration == void 0 ? 1200 : duration;
  115763. let camera = o.endCamera || viewer.scene.getActiveCamera();
  115764. let cameraPos = camera.position.clone();
  115765. let boundSize;
  115766. if(o.dontChangeCamDir && (o.endYaw == void 0 || o.endPitch == void 0)){ //在俯视时仅靠dir来算不准
  115767. o.endYaw = viewer.mainViewport.view.yaw;
  115768. o.endPitch = viewer.mainViewport.view.pitch;
  115769. }
  115770. let moveMap = (done)=>{
  115771. if(this.mapViewer && !o.dontMoveMap){
  115772. //console.log('mapFocusOn: '+target.toArray())
  115773. const minMapWidth = o.minMapWidth || 2; //截图的时候要显示的地图范围较大,为了显示出地区名字
  115774. const minBound = new Vector2(minMapWidth,minMapWidth);//针对垂直线,在地图上只有一个点
  115775. //原始的bound
  115776. let boundOri;
  115777. if(object.points){
  115778. boundOri = new Box3();
  115779. object.points.forEach(e=>{
  115780. boundOri.expandByPoint(e);
  115781. });
  115782. }else {
  115783. boundOri = object.boundingBox;
  115784. }
  115785. if(o.focusBoundCenter){
  115786. boundOri.getCenter(target);
  115787. }
  115788. let boundSizeOri = boundOri.getSize(new Vector3);
  115789. let boundSizeMap = boundSizeOri.clone().multiplyScalar(o.boundExpandRatio || math.linearClamp(Math.max(boundSizeOri.x, boundSizeOri.y) , [0.5, 30], [2.5, 1.2]));//为了能同时看清测量线和地图,当测量线较短时,扩大margin,防止地图过度放大
  115790. boundSizeMap.x = Math.max(minBound.x, boundSizeMap.x );
  115791. boundSizeMap.y = Math.max(minBound.y, boundSizeMap.y );
  115792. this.mapViewer.moveTo(target.clone(), boundSizeMap, duration, o.margin, null, done);
  115793. }
  115794. };
  115795. if(o.onlyMap){
  115796. moveMap(()=>{
  115797. deferred.resolve();
  115798. });
  115799. return {promise:deferred.promise()}
  115800. }
  115801. let getPosWithFullBound = (points, boundingBox, target, cameraPos )=>{//使boundingBox差不多占满屏幕时的相机到target的距离
  115802. // points 和 boundingBox 至少有一个
  115803. let scale;
  115804. if(o.dontChangeCamDir){
  115805. var inv = camera.matrixWorldInverse;
  115806. }else {
  115807. var cameraTemp = camera.clone();
  115808. let view = viewer.mainViewport.view.clone();
  115809. view.position.copy(cameraPos);
  115810. view.lookAt(target);
  115811. if(o.endPitch != void 0){
  115812. view.pitch = o.endPitch;
  115813. view.yaw = o.endYaw;
  115814. }
  115815. view.applyToCamera(cameraTemp);
  115816. //对镜头的bound
  115817. var inv = cameraTemp.matrixWorldInverse;
  115818. }
  115819. var bound = new Box3();
  115820. if(points){//使用points得到的bound更小 //如果points和boundingbox的差别较大,尤其使target和points中心不一致,那么points不一定会刚好在boundingbox内
  115821. points.forEach(e=>{
  115822. var p = e.clone().applyMatrix4(inv);
  115823. bound.expandByPoint(p);
  115824. });
  115825. scale = 1.2;
  115826. }else {
  115827. bound = boundingBox.applyMatrix4(inv);
  115828. scale = 1; //0.9;
  115829. }
  115830. boundSize = bound.getSize(new Vector3);
  115831. if(o.boundScale){
  115832. scale = o.boundScale;
  115833. }
  115834. {
  115835. boundSize.x *= scale; //稍微放大一些,不然会靠到屏幕边缘
  115836. boundSize.y *= scale;
  115837. let min = 0.0001;
  115838. boundSize.x = Math.max(min, boundSize.x);
  115839. boundSize.y = Math.max(min, boundSize.y);
  115840. }
  115841. if(camera.type == 'OrthographicCamera'){
  115842. dis = boundSize.length() / 2;
  115843. }else {
  115844. let aspect = boundSize.x / boundSize.y;
  115845. if(camera.aspect > aspect){//视野更宽则用bound的纵向来决定
  115846. dis = boundSize.y/2/ Math.tan(MathUtils.degToRad(camera.fov / 2)) + boundSize.z/2;
  115847. }else {
  115848. let hfov = cameraLight.getHFOVForCamera(camera, true);
  115849. dis = boundSize.x/2 / Math.tan(hfov / 2) + boundSize.z/2;
  115850. }
  115851. dis += camera.near;
  115852. }
  115853. dis = Math.max(0.1,dis);
  115854. //三个顶点以上的由于measure的中心不等于bound的中心,所以点会超出bound外。 且由于视椎近大远小,即使是两个点的,bound居中后线看上去仍旧不居中.
  115855. //获得相机最佳位置
  115856. let dir;
  115857. if(o.dontChangeCamDir){
  115858. dir = viewer.mainViewport.view.direction.negate();
  115859. }else {
  115860. dir = new Vector3().subVectors(cameraPos, target).normalize();
  115861. }
  115862. if(o.dontLookUp && dir.z < 0){
  115863. dir.negate();
  115864. }
  115865. position.copy(target).add(dir.multiplyScalar(dis));
  115866. if(false){//打开以检查box
  115867. if(!this.boundBox){//调试
  115868. this.boundBox = new Mesh(new BoxGeometry(1,1,1,1));
  115869. this.boundBox.material.wireframe = true;
  115870. this.boundBox.up.set(0,0,1);
  115871. Potree.Utils.setObjectLayers(this.boundBox,'sceneObjects');
  115872. this.scene.scene.add(this.boundBox);
  115873. }
  115874. this.boundBox.position.copy(target);
  115875. this.boundBox.scale.copy(boundSize);
  115876. this.boundBox.lookAt(position);
  115877. }
  115878. return position
  115879. };
  115880. if(this.images360.flying){
  115881. let f = ()=>{
  115882. this.focusOnObject(object, type, duration, $.extend(o,{deferred}));
  115883. this.images360.removeEventListener('cameraMoveDone',f);
  115884. };
  115885. this.images360.addEventListener('cameraMoveDone',f);
  115886. return {promise: deferred.promise() }
  115887. }
  115888. if (type == 'measure') {
  115889. if(object.points.length == 0){
  115890. return {promise:deferred.resolve()}
  115891. }
  115892. target.copy(object.getCenter());
  115893. //试试改变位置(方向),直视测量线。能避免倾斜角度造成的非常不居中、以及看不到面的情况
  115894. if(o.gotoBestView){//直接沿着法线方向看
  115895. if(object.points.length>2){
  115896. let facePlane = object.getFacePlane(target);
  115897. let normal = facePlane.normal.clone();
  115898. if(normal.dot(this.mainViewport.view.direction) > 0){
  115899. normal.negate(); //顺着视线
  115900. }
  115901. //normal.z = Math.max(0.2, normal.z)//尽量不要仰视
  115902. cameraPos.copy(target).add(normal);
  115903. }else {
  115904. let lineDir = new Vector3().subVectors(object.points[0],object.points[1]).normalize();
  115905. let facePlane = new Plane().setFromNormalAndCoplanarPoint(lineDir, target);
  115906. //if(cameraPos.z < target.z + 1)cameraPos.z = target.z + 1//尽量不要仰视
  115907. let dir = new Vector3().subVectors(cameraPos,target).normalize();
  115908. dir.z = Math.max(dir.z, 0.4);
  115909. cameraPos.copy(target).add(dir);//尽量不要仰视
  115910. let dis = cameraPos.distanceTo(target);
  115911. dir = lineDir.clone().multiplyScalar(dis);
  115912. let line = new Line3().set(cameraPos.clone().add(dir), cameraPos.clone().add(dir.negate())); //过相机位置作到面的垂线
  115913. facePlane.intersectLine(line, cameraPos ); //得垂足,作为新的相机位置。就能在测量线中间看测量线
  115914. }
  115915. }else {
  115916. if(object.points.length>2){
  115917. let facePlane = object.getFacePlane(target);
  115918. let normal = facePlane.normal.clone();
  115919. let angle = this.mainViewport.view.direction.angleTo(normal);
  115920. let minDiff = MathUtils.degToRad(60);
  115921. //console.log('angle',angle)
  115922. if(angle>minDiff && angle<Math.PI-minDiff){//当几乎正对时就不执行
  115923. if(angle<Math.PI/2){ //在背面
  115924. normal.negate();
  115925. }
  115926. let dir = new Vector3().subVectors(camera.position, target).normalize();
  115927. let newDir = new Vector3().addVectors(dir,normal);//两个角度的中间
  115928. cameraPos.copy(target.clone().add(newDir));
  115929. }
  115930. }else if(object.points.length == 2){ //线段
  115931. let lineDir = new Vector3().subVectors(object.points[0],object.points[1]).normalize();
  115932. let angle = this.mainViewport.view.direction.angleTo(lineDir);
  115933. let maxDiff = Math.PI*0.25;// 45度
  115934. if(angle<maxDiff || angle>Math.PI-maxDiff){//当几乎正对时就不执行
  115935. if(angle>Math.PI/2){ //令dir和lineDir成钝角
  115936. lineDir.negate();
  115937. }
  115938. let dir = new Vector3().subVectors(camera.position, target).normalize();
  115939. let mid = new Vector3().addVectors(lineDir, dir).normalize(); //中间法向量(如果刚好dir和lineDir反向,那得到的为零向量,就不移动了,但一般不会酱紫吧)
  115940. let newDir = new Vector3().addVectors(dir, mid);
  115941. cameraPos.copy(target.clone().add(newDir));
  115942. }
  115943. }else {
  115944. console.error('measure 没有facePlane points点数还不为2?');
  115945. }
  115946. }
  115947. //截图时直接飞到最佳视角,也就是平视它所在面。其余时候为了避免镜头旋转过大就算了。
  115948. position = getPosWithFullBound(object.points, null, target, cameraPos );
  115949. moveMap();
  115950. if(Potree.settings.displayMode == 'showPointCloud'){ //点云
  115951. let minDis = 0.3;
  115952. if(0 ){//如果没有被选中,会被遮挡。 2023.11.15 最好展示全局(尤其截图时),虽然被遮挡,但focus的过程是选中状态全显示的,可以看出所在范围。
  115953. let checkIntersect = ( )=>{
  115954. let intersect = this.inputHandler.ifBlockedByIntersect({point:position, cameraPos: target});// 不一定准确
  115955. if(intersect){
  115956. let blockCount = 0, unblockCount = 0, visi;
  115957. for(let i=0;i<object.points.length;i++){ //如果顶点超过一半不可见,就要更改位置
  115958. let p = object.points[i];
  115959. let blocked = this.inputHandler.ifBlockedByIntersect({point:p, margin:0.3 , cameraPos:position, pickWindowSize:4});
  115960. if(blocked){
  115961. blockCount ++;
  115962. if(blockCount / object.points.length >= 0.5){
  115963. visi = false;
  115964. break
  115965. }
  115966. }else {
  115967. unblockCount ++;
  115968. if(unblockCount / object.points.length > 0.5){
  115969. visi = true;
  115970. break
  115971. }
  115972. }
  115973. }
  115974. if(visi == void 0){
  115975. visi = unblockCount / object.points.length > 0.5;
  115976. }
  115977. let shrink = ()=>{
  115978. let dir = new Vector3().subVectors(position, target).normalize().multiplyScalar(intersect.distance);
  115979. position.copy(target).add(dir);
  115980. console.log('checkIntersect newPos', position.clone() );
  115981. };
  115982. if(!visi){//更改位置距离target如果小于最小距离,需要反向。 否则直接缩短距离。
  115983. if(intersect.distance < minDis ){
  115984. console.log('检测到intersect 反向', intersect.distance );
  115985. let position1 = position.clone();
  115986. let dir = new Vector3().subVectors(position, target);
  115987. position.copy(target).sub(dir);
  115988. let intersect2 = this.inputHandler.ifBlockedByIntersect({point: position, cameraPos:target});// 不一定准确
  115989. if(intersect2){
  115990. if(intersect2.distance < intersect.distance ){
  115991. position.copy(position1);//恢复
  115992. }
  115993. shrink();
  115994. }
  115995. }else {
  115996. shrink();
  115997. }
  115998. }
  115999. }
  116000. };
  116001. checkIntersect();
  116002. //多折线没有areaPlane 有时候会看向空白区域 - -
  116003. }
  116004. }else if(Potree.settings.displayMode == 'showPanos'){//全景 (比较难校准)
  116005. let target2, dir;
  116006. if( object.measureType.includes('MulDistance')){//因为该线不闭合,可能看向target的方向会没有线,所以换一个target
  116007. target2 = object.points[Math.round(object.points.length / 2) ];//直接看向中间点
  116008. dir = new Vector3().subVectors(target2, position).normalize();
  116009. }
  116010. let pano = viewer.images360.fitPanoTowardPoint({
  116011. /*point : target, //不使用目标点来判断是因为缺少measure角度的信息。比如虽然可以靠近线的中心,但是线朝向屏幕,那几乎就是一个点了。
  116012. //bestDistance : dis * 0.5, //乘以小数是为了尽量靠近
  116013. boundSphere: boundOri.getBoundingSphere(new THREE.Sphere), */
  116014. target,
  116015. dir,
  116016. point : position,
  116017. bestDistance : 0 ,
  116018. checkIntersect: o.checkIntersect, gotoBestView: o.gotoBestView
  116019. });
  116020. let result = {promise:deferred.promise() };
  116021. if(pano && pano.msg){
  116022. pano = pano.pano;
  116023. result.msg = pano.msg;
  116024. }
  116025. if(pano){
  116026. viewer.images360.flyToPano({pano, target : target2 || target, duration, deferred, dontMoveMap:true , basePanoSize:o.basePanoSize});//dontMoveMap不要移动map,否则flytopano会自动在map中focus到漫游点的位置,而非测量线了
  116027. if(viewer.images360.currentPano == pano){
  116028. let dis1 = viewer.images360.currentPano.position.distanceTo(target);
  116029. let dis2 = position.distanceTo(target);
  116030. //console.log('dis1 / dis2',dis1 / dis2, 'dis1-dis2', dis1-dis2)
  116031. return {msg: (dis1 / dis2 > 1.5 && dis1-dis2>10)? 'tooFar' : 'posNoChange', promise : deferred.promise() }
  116032. }
  116033. }
  116034. return result
  116035. /* if(viewer.images360.currentPano == pano){
  116036. let dis1 = viewer.images360.currentPano.position.distanceTo(target)
  116037. let dis2 = position.distanceTo(target)
  116038. //console.log('dis1 / dis2',dis1 / dis2, 'dis1-dis2', dis1-dis2)
  116039. return {msg: (dis1 / dis2 > 1.5 && dis1-dis2>10)? 'tooFar' : 'posNoChange', promise : deferred.promise() }
  116040. }else{
  116041. return {promise : deferred.promise()}
  116042. } */
  116043. //出现过到达位置后测量线标签闪烁的情况
  116044. // 测量线截图 全景 最好能放大. 但要确保该位置放大后图片加载完有点困难
  116045. }
  116046. } else if (type == 'tag' || type == 'point') {
  116047. //dimension = 1
  116048. target.copy(object.position);
  116049. let bestDistance = o.distance || 3;
  116050. if(!o.dontMoveMap && this.mapViewer){
  116051. //console.log('mapFocusOn: '+target.toArray())
  116052. this.mapViewer.moveTo(target.clone(), null, duration);
  116053. }
  116054. if(Potree.settings.displayMode == 'showPointCloud'){
  116055. if(o.dontChangePos){
  116056. position.copy(cameraPos);
  116057. }else {
  116058. dis = bestDistance;
  116059. let dir = o.direction ? o.direction.clone().negate() : this.mainViewport.view.direction.negate();// */new THREE.Vector3().subVectors(camera.position, target).normalize()
  116060. if(o.dontLookUp && dir.z<0) dir.z *= -1;
  116061. position.copy(target).add(dir.multiplyScalar(dis));
  116062. }
  116063. if(o.sameFloor){//需要在同一楼层
  116064. let atFloor = this.modules.SiteModel.pointInWhichEntity(target, 'floor');
  116065. if(atFloor){
  116066. let camFloor = this.modules.SiteModel.pointInWhichEntity(position, 'floor');
  116067. if(camFloor != atFloor){
  116068. let raycaster = new Raycaster();
  116069. let origin = target;
  116070. let dir = new Vector3().subVectors( position, target ).normalize();
  116071. raycaster.set(origin, dir);
  116072. let intersect = Potree.Utils.getIntersect(null, [atFloor.box], null, raycaster);
  116073. if(intersect){
  116074. let dis = MathUtils.clamp(intersect.distance - 0.2, camera.near, intersect.distance);
  116075. position.addVectors(origin, dir.multiplyScalar(dis));
  116076. console.log('移动到楼层');
  116077. }else {
  116078. console.error('?no intersect?');
  116079. }
  116080. }
  116081. }
  116082. }
  116083. if(o.checkIntersect){//识别被点云遮住的话
  116084. let intersect; //反向查找从target到相机的第一个intersect
  116085. intersect = this.inputHandler.ifBlockedByIntersect({point:position, margin:0, cameraPos:target} /* {point:target, margin: 0.2, cameraPos:position} */);
  116086. if(intersect){
  116087. position.copy(intersect.location);
  116088. console.log('移近');
  116089. }
  116090. }
  116091. }else if(Potree.settings.displayMode == 'showPanos'){
  116092. let pano = viewer.images360.fitPanoTowardPoint({
  116093. point : target,
  116094. dir : this.mainViewport.view.direction, //尽量不改相机方向,避免镜头晃动
  116095. checkIntersect: o.checkIntersect, sameFloor:o.sameFloor,
  116096. bestDistance, maxDis: o.maxDis //越近越好,但不要太近,bestDistance左右差不多
  116097. });
  116098. let result = {promise:deferred.promise() };
  116099. if(pano && pano.msg){
  116100. pano = pano.pano;
  116101. result.msg = pano.msg;
  116102. }
  116103. pano && viewer.images360.flyToPano({pano, target, duration, deferred, dontMoveMap:true , basePanoSize:o.basePanoSize });
  116104. return result
  116105. }
  116106. }else if(object.boundingBox && type == 'boundingBox'){//使屏幕刚好看全boundingBox
  116107. target = object.boundingBox.getCenter(new Vector3);
  116108. if(o.dir){ //指定方向
  116109. cameraPos.copy(target).sub(o.dir);
  116110. }
  116111. position = getPosWithFullBound(object.points, object.boundingBox.clone(), target, cameraPos );
  116112. if(Potree.settings.displayMode == 'showPanos'){//全景 (比较难校准)
  116113. let pano = viewer.images360.fitPanoTowardPoint({
  116114. point : position,
  116115. bestDistance : 0 ,
  116116. });
  116117. let result = {promise:deferred.promise() };
  116118. if(pano && pano.msg){
  116119. pano = pano.pano;
  116120. result.msg = pano.msg;
  116121. }
  116122. pano && viewer.images360.flyToPano({pano, target, duration, deferred, dontMoveMap:true , basePanoSize:o.basePanoSize});//dontMoveMap不要移动map,否则flytopano会自动在map中focus到漫游点的位置,而非测量线了
  116123. if(!pano){
  116124. console.error('no pano');
  116125. }
  116126. return result
  116127. //出现过到达位置后测量线标签闪烁的情况
  116128. }else {
  116129. /* if(o.dontChangeCamDir){
  116130. target = null
  116131. } */
  116132. moveMap();
  116133. }
  116134. }
  116135. if(o.startCamera && o.endCamera){
  116136. viewer.mainViewport.view.tranCamera(this.mainViewport, { endPosition:position, target ,
  116137. boundSize,
  116138. callback:()=>{
  116139. //console.log('focusOnObjectSuccess: '+object.name, type)
  116140. deferred.resolve();
  116141. }, startCamera:o.startCamera, endCamera:o.endCamera, midCamera:this.scene.cameraBasic,
  116142. endYaw:o.endYaw, endPitch:o.endPitch
  116143. }, duration);
  116144. }else if(camera.type == "OrthographicCamera"){
  116145. viewer.mainViewport.view.moveOrthoCamera(this.mainViewport, { endPosition:position, target ,
  116146. boundSize,
  116147. endYaw:o.endYaw, endPitch:o.endPitch,
  116148. callback:()=>{
  116149. //console.log('focusOnObjectSuccess: '+object.name, type)
  116150. deferred.resolve();
  116151. },
  116152. }, duration);
  116153. }else {
  116154. viewer.mainViewport.view.setView({position, target, duration,
  116155. endYaw:o.endYaw, endPitch:o.endPitch,
  116156. callback:()=>{
  116157. //console.log('focusOnObjectSuccess: '+object.name, type)
  116158. deferred.resolve();
  116159. }
  116160. });
  116161. }
  116162. this.dispatchEvent({type:'focusOnObject', CamTarget:target, position}); //给controls发送信息
  116163. return {promise:deferred.promise()}
  116164. }
  116165. flyToDataset(o={}){
  116166. var pointcloud;
  116167. if(o instanceof Object3D) pointcloud = o;
  116168. else if(o.pointcloud) pointcloud = o.pointcloud;
  116169. else pointcloud = this.scene.pointclouds.find(p => p.dataset_id == o.id);
  116170. let duration = o.duration == void 0 ? 1000 : o.duration;
  116171. if(o.focusOnPoint || !pointcloud.panosBound){//focus点云上一点,避免center区域刚好没有点
  116172. if(pointcloud.root.geometryNode){
  116173. let posArr = pointcloud.root.geometryNode.geometry.attributes.position.array;
  116174. let count = pointcloud.root.geometryNode.geometry.attributes.position.count;
  116175. let index = Math.ceil(count / 2); //随便取一个点
  116176. let point = new Vector3(posArr[index*3+0],posArr[index*3+1],posArr[index*3+2]);
  116177. //point.applyMatrix4(pointcloud.root.pointcloud.matrixWorld)
  116178. point.applyMatrix4(pointcloud.root.sceneNode.matrixWorld);
  116179. viewer.focusOnObject({position:point},'point',duration,{dontChangeCamDir:true, distance:15});
  116180. o.dontMoveMap || viewer.mapViewer.fitToPointcloud(pointcloud, duration);
  116181. console.log('flyToDataset focusOnPoint done');
  116182. return
  116183. }
  116184. }
  116185. var center = pointcloud.bound.getCenter(new Vector3);
  116186. let position;
  116187. let getPano = ()=>{//获取离中心最近的pano
  116188. let request = [];
  116189. let rank = [
  116190. Images360.scoreFunctions.distanceSquared({position: center})
  116191. ];
  116192. let r = Common.sortByScore(pointcloud.panos, request, rank);
  116193. if(r.length){
  116194. return r[0].item
  116195. }
  116196. };
  116197. if(Potree.settings.displayMode == 'showPanos'){
  116198. let pano = getPano();
  116199. if(pano){
  116200. if(pano == this.images360.currentPano) return 'posNoChange'
  116201. this.images360.flyToPano({
  116202. pano
  116203. });
  116204. }else return false
  116205. }else {
  116206. let target;
  116207. position = center;
  116208. if(pointcloud.panosBound){
  116209. let panosCenter = pointcloud.panosBound.center; //pano集中的地方,也就是真正有点云的地方
  116210. position = panosCenter.clone();
  116211. /* let ratio = 0.2
  116212. position.z = center.z * ratio + panosCenter.z * (1-ratio) //因为panos一般比较低,为了不让相机朝下时看不到点云,加一丢丢中心高度
  116213. */
  116214. let pano = getPano();
  116215. if(pano){
  116216. target = pano.position; //针对像隧道一样的场景, 中心点还是panosCenter都在没有点云的地方,所以还是看向其中一个漫游点好。
  116217. position.z = target.z; //水平, 避免朝上或朝下
  116218. }
  116219. }
  116220. if(this.modules.Clip.editing){
  116221. position.z = center.z; //剪裁时在中心高度,因为以点云为重点
  116222. this.modules.Clip.bus.dispatchEvent({type:'flyToPos', position, duration });
  116223. }else {
  116224. if(math.closeTo(position, this.images360.position)) return 'posNoChange'
  116225. viewer.mainViewport.view.setView({position, target, duration });
  116226. }
  116227. o.dontMoveMap || viewer.mapViewer.fitToPointcloud(pointcloud, duration);
  116228. }
  116229. return true
  116230. }
  116231. findClosestDatasetOnMap(position){//寻找当前平面图上离某点最近的数据集
  116232. let pointclouds = viewer.scene.pointclouds.filter(e=>e.visible);
  116233. const addScore = viewer.bound.boundSize.length();
  116234. let r = Potree.Common.sortByScore(pointclouds, [], [(e)=>{//pos2d和bound2d距离排序
  116235. let pos3d = position.clone().setZ(e.panosBound ? e.panosBound.center.z : (e.bound.min.z+e.bound.max.z)/2);
  116236. return - (e.panosBound ? e.panosBound.bounding : e.bound).distanceToPoint(pos3d)
  116237. },(e)=>{//最有可能的是地图上显示的平面图
  116238. return e in viewer.fpVisiDatasets ? addScore : 0
  116239. }]);
  116240. return r[0] && r[0].item
  116241. }
  116242. addTimeMark(name, type){
  116243. let record = Potree.timeCollect[name];
  116244. let needRecord = record && record.start && record.measures.length < record.minCount;
  116245. if(needRecord || Potree.measureTimings){
  116246. performance.mark(name+"-"+type);
  116247. if(type == 'end'){
  116248. let measure = performance.measure(name,name+"-start",name+"-end");
  116249. if(needRecord){
  116250. record.measures.push( measure.duration );
  116251. record.sum += measure.duration;
  116252. record.ave = record.sum / record.measures.length;
  116253. record.measures.sort( (a, b) => a - b );
  116254. record.median = record.measures[parseInt(record.measures.length / 2)];
  116255. }
  116256. }
  116257. }
  116258. }
  116259. addFakeMeasure(name,duration){//把一些count当做duration来统计
  116260. if(!Potree.measureTimings)return
  116261. if(!this.fakeMeasure[name]){
  116262. this.fakeMeasure[name] = [];
  116263. }
  116264. let object = {
  116265. name, duration
  116266. };
  116267. this.fakeMeasure[name].push(object);
  116268. }
  116269. resolveTimings(timestamp,log){//打印用时。 注:performance手机的精度只到整数位 。 sidebar中监听update时有高cpu的函数所以不要用demo测
  116270. if(!this.toggle){
  116271. this.toggle = timestamp;
  116272. }
  116273. let duration = timestamp - this.toggle;
  116274. if(duration > 1000.0){
  116275. if(log){
  116276. let measures = performance.getEntriesByType("measure");
  116277. for(let i in this.fakeMeasure){
  116278. measures.push(...this.fakeMeasure[i]);
  116279. }
  116280. let names = new Set();
  116281. for(let measure of measures){
  116282. names.add(measure.name);
  116283. }
  116284. let groups = new Map();
  116285. for(let name of names){
  116286. groups.set(name, {
  116287. measures: [],
  116288. sum: 0,
  116289. n: 0,
  116290. min: Infinity,
  116291. max: -Infinity
  116292. });
  116293. }
  116294. for(let measure of measures){
  116295. let group = groups.get(measure.name);
  116296. group.measures.push(measure);
  116297. group.sum += measure.duration;
  116298. group.n++;
  116299. group.min = Math.min(group.min, measure.duration);
  116300. group.max = Math.max(group.max, measure.duration);
  116301. }
  116302. /* let glQueries = Potree.resolveQueries(this.renderer.getContext()); // resolveQueries 无
  116303. for(let [key, value] of glQueries){
  116304. let group = {
  116305. measures: value.map(v => {return {duration: v}}),
  116306. sum: value.reduce( (a, i) => a + i, 0),
  116307. n: value.length,
  116308. min: Math.min(...value),
  116309. max: Math.max(...value)
  116310. };
  116311. let groupname = `[tq] ${key}`;
  116312. groups.set(groupname, group);
  116313. names.add(groupname);
  116314. } */
  116315. for(let [name, group] of groups){
  116316. group.mean = group.sum / group.n;
  116317. /* group.measures.sort( (a, b) => a.duration - b.duration );
  116318. if(group.n === 1){
  116319. group.median = group.measures[0].duration;
  116320. }else if(group.n > 1){
  116321. group.median = group.measures[parseInt(group.n / 2)].duration;
  116322. }
  116323. */
  116324. let measures = group.measures.slice();
  116325. measures.sort( (a, b) => a.duration - b.duration );
  116326. if(group.n === 1){
  116327. group.median = measures[0].duration;
  116328. }else if(group.n > 1){
  116329. group.median = measures[parseInt(group.n / 2)].duration;
  116330. }
  116331. }
  116332. let cn = Array.from(names).reduce( (a, i) => Math.max(a, i.length), 0) + 5;
  116333. let cmin = 6;
  116334. let cmed = 6;
  116335. let cmax = 6;
  116336. let csam = 4;
  116337. let message = ` ${"NAME".padEnd(cn)} |`
  116338. + ` ${"MIN".padStart(cmin)} |`
  116339. + ` ${"MEDIAN".padStart(cmed)} |`
  116340. + ` ${"MAX".padStart(cmax)} |`
  116341. + ` ${"AVE".padStart(cmax)} |`
  116342. + ` ${"SAMPLES".padStart(csam)} \n`;
  116343. message += ` ${"-".repeat(message.length) }\n`;
  116344. names = Array.from(names).sort();
  116345. for(let name of names){
  116346. let group = groups.get(name);
  116347. let min = group.min.toFixed(3);
  116348. let median = group.median.toFixed(3);
  116349. let max = group.max.toFixed(3);
  116350. let ave = group.mean.toFixed(3); //add
  116351. let n = group.n;
  116352. message += ` ${name.padEnd(cn)} |`
  116353. + ` ${min.padStart(cmin)} |`
  116354. + ` ${median.padStart(cmed)} |`
  116355. + ` ${max.padStart(cmax)} |`
  116356. + ` ${ave.padStart(cmax)} |`
  116357. + ` ${n.toString().padStart(csam)}\n`;
  116358. }
  116359. message += `\n`;
  116360. console.log(message);
  116361. }
  116362. this.fakeMeasure = {}; //clear
  116363. performance.clearMarks();
  116364. performance.clearMeasures();
  116365. this.toggle = timestamp;
  116366. }
  116367. //注意,console.log本身用时挺高,降4倍时可能占用0.5毫秒,所以不能每帧都打印
  116368. }
  116369. loop(timestamp){
  116370. //let startTime = performance.now()
  116371. //console.log('间隔:' /*, parseInt((startTime - this.lastEndTime)*100 )/100 */)
  116372. if(this.paused)return
  116373. if(performance.getEntriesByName("loopWaitNext-start").length)viewer.addTimeMark('loopWaitNext','end');
  116374. if(this.stats){
  116375. this.stats.begin();
  116376. }
  116377. performance.mark('loop-start') ;// 无论有没有reportTimings都要获取,因为getBestCound需要
  116378. this.dispatchEvent('loopStart');
  116379. this.interacted = false;
  116380. this.shelterCount = {byTex:0, byCloud:0, maxByTex: 100, maxByCloud:0 }; //清空 因ifPointBlockedByIntersect可能在任何时候触发,所以需要一开始就定义这个,且每次计算最大可计算次数太麻烦了就定义一个吧。
  116381. let deltaTime = this.clock.getDelta();
  116382. this.update(deltaTime, timestamp);
  116383. this.magnifier.render();
  116384. this.render();
  116385. this.objs.children.forEach(e=>{
  116386. if(e.fileType == '3dTiles'){
  116387. e.traverse(child=>{
  116388. if(child.runtime){
  116389. child.runtime.update(deltaTime, this.renderer, this.mainViewport.camera);
  116390. return {stopContinue:true}
  116391. }
  116392. });
  116393. }
  116394. });
  116395. // let vrActive = viewer.renderer.xr.isPresenting;
  116396. // if(vrActive){
  116397. // this.update(this.clock.getDelta(), timestamp);
  116398. // this.render();
  116399. // }else{
  116400. // this.update(this.clock.getDelta(), timestamp);
  116401. // this.render();
  116402. // }
  116403. Potree.framenumber++;
  116404. //-------------
  116405. this.images360.tileDownloader.update();
  116406. this.images360.panoRenderer.update();
  116407. this.images360.getNeighbours(this.interacted);
  116408. this.computeShelter();
  116409. //-------------
  116410. if(this.stats){
  116411. this.stats.end();
  116412. }
  116413. viewer.addTimeMark('loop','end');
  116414. viewer.addTimeMark('loopWaitNext','start');
  116415. this.resolveTimings(timestamp, Potree.measureTimings);
  116416. //Potree.measureTimings = 1
  116417. }
  116418. postError(content, params = {}){
  116419. let message = this.postMessage(content, params);
  116420. message.element.addClass("potree_message_error");
  116421. return message;
  116422. }
  116423. postMessage(content, params = {}){
  116424. let message = new Message(content);
  116425. let animationDuration = 100;
  116426. message.element.css("display", "none");
  116427. message.elClose.click( () => {
  116428. message.element.slideToggle(animationDuration);
  116429. let index = this.messages.indexOf(message);
  116430. if(index >= 0){
  116431. this.messages.splice(index, 1);
  116432. }
  116433. });
  116434. this.elMessages.prepend(message.element);
  116435. message.element.slideToggle(animationDuration);
  116436. this.messages.push(message);
  116437. if(params.duration !== undefined){
  116438. let fadeDuration = 500;
  116439. let slideOutDuration = 200;
  116440. setTimeout(() => {
  116441. message.element.animate({
  116442. opacity: 0
  116443. }, fadeDuration);
  116444. message.element.slideToggle(slideOutDuration);
  116445. }, params.duration);
  116446. }
  116447. return message;
  116448. }
  116449. getBoundingBox (pointclouds) {
  116450. //可以直接返回viewer.bound
  116451. if(!this.bound){
  116452. this.updateModelBound();
  116453. }
  116454. return this.bound.boundingBox.clone()//this.scene.getBoundingBox(pointclouds);
  116455. };
  116456. updateModelBound(reason){
  116457. this.boundNeedUpdate = false;
  116458. this.bound = Utils.computePointcloudsBound(this.scene.pointclouds.filter(pointcloud=> //只求可见
  116459. pointcloud.visible || pointcloud.unvisibleReasons && pointcloud.unvisibleReasons.length == 1 && pointcloud.unvisibleReasons[0].reason == 'displayMode'
  116460. ));
  116461. if(Potree.settings.boundAddObjs){//加上obj的bound 需要确保都updateMatrixWorld过
  116462. this.objs.children.forEach(e=>{
  116463. this.bound.boundingBox.union(e.boundingBox.clone().applyMatrix4(e.matrixWorld));
  116464. });
  116465. this.bound.boundingBox.getSize(this.bound.boundSize);
  116466. this.bound.boundingBox.getCenter(this.bound.center);
  116467. }
  116468. viewer.farWhenShowPano = this.bound.boundSize.length() * 10;//全景漫游时要能看到整个skybox 原本*2的但对于距离特远的数据集需要乘大一些否则会黑面
  116469. /* let boundPlane = new THREE.Box3()
  116470. boundPlane.expandByPoint(this.bound.boundingBox.min.clone())//最低高度为bound的最低
  116471. boundPlane.expandByPoint(this.bound.boundingBox.max.clone().setZ(this.bound.center.z))//最高高度为bound的中心高度
  116472. FirstPersonControls.boundPlane = boundPlane */
  116473. //FirstPersonControls.standardSpeed = THREE.Math.clamp( Math.sqrt(this.bound.boundSize.length() )/ 100 , 0.02,0.5); //在这个boundPlane中的速度
  116474. viewer.scene.pointclouds.forEach(e=>{//海拔范围
  116475. e.material.heightMin = this.bound.boundingBox.min.z;
  116476. e.material.heightMax = this.bound.boundingBox.max.z;
  116477. });
  116478. this.dispatchEvent({type:'updateModelBound'});
  116479. }
  116480. waitForLoad(object, isLoadedCallback){//等待加载时显示loading。主要是贴图
  116481. this.waitQueue.push({
  116482. object,
  116483. isLoadedCallback,
  116484. });
  116485. //console.warn('waitForLoad',object.id,this.waitQueue.length)
  116486. 1 === this.waitQueue.length && this.dispatchEvent({type:"loading", show:true});
  116487. }
  116488. ifAllLoaded( ){
  116489. if(this.waitQueue.length>0){
  116490. this.waitQueue = this.waitQueue.filter(function(e) {
  116491. return !e.isLoadedCallback()
  116492. });
  116493. }
  116494. //console.warn('ifAllLoaded', this.waitQueue.length)
  116495. 0 === this.waitQueue.length && this.dispatchEvent({type:"loading", show:false});
  116496. }
  116497. cancelLoad(object){//add 突然出现还没加载完就被deactivateTiledPano但还在loading的情况,所以加了这个
  116498. this.waitQueue = this.waitQueue.filter(function(e) {
  116499. return e.object != object
  116500. });
  116501. //console.log('cancelLoad', object.id)
  116502. this.ifAllLoaded();
  116503. }
  116504. setView(o={}){
  116505. let callback = ()=>{
  116506. if(o.displayMode){
  116507. Potree.settings.displayMode = o.displayMode;
  116508. }
  116509. if(!o.pano && o.currentPano )this.images360.currentPano = o.currentPano;
  116510. o.callback && o.callback();
  116511. };
  116512. if(o.pano != void 0){//pano 权重高于 position
  116513. this.images360.flyToPano(o);
  116514. }else {
  116515. this.mainViewport.view.setView($.extend({},o, {callback}));
  116516. }
  116517. }
  116518. //设置点云为标准模式
  116519. setPointStandardMat(state, pointDensity, fitPointsize){
  116520. console.log('setPointStandardMat',state);
  116521. if(state){
  116522. if(this.pointStatesBefore){
  116523. return console.warn('已设置过pointStatesBefore!')
  116524. }
  116525. this.pointStatesBefore = {
  116526. opacity : new Map(),
  116527. size: new Map(),
  116528. density:Potree.settings.pointDensity,
  116529. useEDL:this.getEDLEnabled(),
  116530. shape: viewer.scene.pointclouds[0].material.shape
  116531. };
  116532. viewer.scene.pointclouds.forEach(e=>{
  116533. this.pointStatesBefore.opacity.set(e, e.temp.pointOpacity); //因为更改pointDensity时会自动变opacity,所以这项最先获取
  116534. this.pointStatesBefore.colorType = e.material.activeAttributeName;
  116535. fitPointsize && this.pointStatesBefore.size.set(e,e.temp.pointSize); //这项不一定有用,因为会被后期覆盖
  116536. });
  116537. if(pointDensity)Potree.settings.pointDensity = pointDensity; //万一之后切换到全景模式怎么办
  116538. if(fitPointsize)Potree.settings.sizeFitToLevel = true;
  116539. viewer.scene.pointclouds.forEach(e=>{
  116540. e.material.activeAttributeName = 'rgba';
  116541. e.material.shape = Potree.PointShape['SQUARE'];
  116542. fitPointsize && e.changePointSize(Potree.config.material.realPointSize, true);
  116543. e.changePointOpacity(1);
  116544. });
  116545. viewer.setEDLEnabled(false);
  116546. }else {
  116547. if(!this.pointStatesBefore){
  116548. return console.error('未设置过pointStatesBefore!')
  116549. }
  116550. Potree.settings.sizeFitToLevel = false;
  116551. if(pointDensity)Potree.settings.pointDensity = this.pointStatesBefore.pointDensity;
  116552. viewer.scene.pointclouds.forEach(e=>{
  116553. e.material.activeAttributeName = this.pointStatesBefore.colorType;
  116554. e.changePointOpacity(this.pointStatesBefore.opacity.get(e));
  116555. e.material.shape = this.pointStatesBefore.shape;
  116556. let size = this.pointStatesBefore.size.get(e);
  116557. if(size) e.changePointSize(size);
  116558. });
  116559. viewer.setEDLEnabled(this.pointStatesBefore.useEDL);
  116560. this.pointStatesBefore = null;
  116561. }
  116562. }
  116563. //调试时显示transformControl来调节object
  116564. transformObject(object){
  116565. let seleted = viewer.inputHandler.selection[0];
  116566. if(!object){//取消
  116567. seleted && viewer.inputHandler.toggleSelection(seleted);
  116568. return
  116569. }
  116570. if(seleted && seleted != object){//要更换,先取消
  116571. this.transformObject(null);
  116572. }
  116573. if(!object.boundingBox){
  116574. object.boundingBox = new Box3(); //任意大小 只是为了显示黄色外框
  116575. //??? computeBoundingBox
  116576. }
  116577. if(!viewer.inputHandler.selection.includes(object)){
  116578. viewer.inputHandler.toggleSelection(object);
  116579. }
  116580. }
  116581. pointInWhichPointcloud(pos){//选择最接近中心的那个 使用boundSphere
  116582. let result = Common.sortByScore(this.scene.pointclouds,[],[
  116583. (pointcloud)=>{
  116584. var size = pointcloud.pcoGeometry.tightBoundingBox.getSize(new Vector3);
  116585. var center = pointcloud.bound.getCenter(new Vector3);
  116586. var length = size.length() / 2;
  116587. var dis = pos.distanceTo(center);
  116588. return length / dis //到数据集中心的距离占数据集大小越小越好
  116589. }
  116590. ]);
  116591. //若要求更准确的话,可以使用ifContainsPoint判断一下是否在bound中
  116592. let r = result[0];
  116593. return r && r.score > 1 ? result[0].item : null
  116594. }
  116595. /* createRoomEv(){
  116596. const environment = new RoomEnvironment();
  116597. const pmremGenerator = new THREE.PMREMGenerator( this.renderer );
  116598. }
  116599. */
  116600. modelLoaded(object, fileInfo_={}, done){//普通模型加载完以后
  116601. object.isModel = true;
  116602. let boundingBox = new Box3();
  116603. if(fileInfo_.parentInfo){
  116604. object.name = fileInfo_.name;
  116605. fileInfo_.parentInfo.loadedCount ++;
  116606. fileInfo_.parentInfo.modelGroup.add(object);
  116607. if(fileInfo_.parentInfo.loadedCount == fileInfo_.parentInfo.url.length){
  116608. return this.modelLoaded(fileInfo_.parentInfo.modelGroup, fileInfo_.parentInfo, done)
  116609. }else {
  116610. return
  116611. }
  116612. }
  116613. object.name = fileInfo_.name != void 0 ? fileInfo_.name : fileInfo_.fileType;
  116614. object.fileType = fileInfo_.fileType;
  116615. object.boundingBox = boundingBox; //未乘上matrixWorld的本地boundingBox
  116616. //object.scale.set(1,1,1);//先获取原始的大小时的boundingBox
  116617. object.opacity = 1; //初始化 记录
  116618. object.updateMatrixWorld();
  116619. if(fileInfo_.id != void 0)object.dataset_id = fileInfo_.id;
  116620. fileInfo_.loadCostTime = Date.now() - fileInfo_.loadStartTime;
  116621. /* let weight = Math.round((total / 1024 / 1024) * 100) / 100;*/
  116622. console.log( '加载完毕:', Common.getNameFromURL(fileInfo_.url), '耗时(ms)', fileInfo_.loadCostTime, /* 模型数据量:' + weight + 'M' */);
  116623. if(fileInfo_.fileType == '3dTiles'){
  116624. let isGroup = !object.runtime;
  116625. let children = object.runtime ? [object] : object.children;
  116626. children.forEach(object =>{
  116627. let boundingBox_ = new Box3();
  116628. let tileset = object.runtime.getTileset();
  116629. //TileHeader: tileset.root
  116630. //参见另一个工程 TileRenderer.js preprocessNode //这个坐标位置几万…… let data = boundingVolume.halfAxes //但这个似乎是premultiply( transform );过后的,可能需还原下
  116631. let json = tileset.tileset;
  116632. let box = json.root.boundingVolume.box;
  116633. if(box){
  116634. let center = new Vector3(box[0],box[1],box[2]);
  116635. let boundSize = new Vector3( );
  116636. // get the extents of the bounds in each axis
  116637. let vecX = new Vector3( box[ 3 ], box[ 4 ], box[ 5 ] );
  116638. let vecY = new Vector3( box[ 6 ], box[ 7 ], box[ 8 ] );
  116639. let vecZ = new Vector3( box[ 9 ], box[ 10 ], box[ 11 ] );
  116640. const scaleX = vecX.length();
  116641. const scaleY = vecY.length();
  116642. const scaleZ = vecZ.length();
  116643. boundingBox_.min.set( - scaleX, - scaleY, - scaleZ );
  116644. boundingBox_.max.set( scaleX, scaleY, scaleZ );
  116645. if(isGroup){//如果是多个拼成的,每个都保留原先在parent中的offset。 如果是外层,作为独立个体,不用理会位置信息,直接放中央。
  116646. object.position.copy(center);
  116647. object.position.z *= -1;
  116648. boundingBox_.translate(object.position); //由于是内层,其位移会改变整体的boundingbox
  116649. }
  116650. }else if(json.root.boundingVolume.sphere){
  116651. let sphereData = json.root.boundingVolume.sphere;
  116652. let center = new Vector3(...sphereData);
  116653. let radius = sphereData[3] / 2;
  116654. /* let sphere = new THREE.Sphere(center, radius)
  116655. let box = sphere.getBoundingBox()
  116656. boundingBox.copy(box) */
  116657. boundingBox_.min.set( - radius, - radius, - radius );
  116658. boundingBox_.max.set( radius, radius, radius );
  116659. }else {
  116660. return console.error('json boundingVolume 缺少信息')
  116661. }
  116662. //中心点居然没用。可能是漏用了什么信息,也许这和LVBADUI_qp是散的有关。
  116663. console.log('3d tiles json',json);
  116664. json.root.refine = 'ADD';
  116665. json.refine = 'ADD';
  116666. boundingBox.union(boundingBox_);
  116667. });
  116668. }else {
  116669. Potree.Utils.setObjectLayers(object, Potree.settings.showObjectsOnMap ? 'bothMapAndScene' : 'model');
  116670. object.traverse( ( child )=>{
  116671. let is = child.isMesh || child instanceof Points || child.isLine;
  116672. if (is){
  116673. child.renderOrder = Potree.config.renderOrders.model;
  116674. //if(Potree.settings.boundAddObjs){
  116675. child.geometry.computeBoundingBox();
  116676. //console.log(child.matrixWorld.clone())
  116677. boundingBox.union(child.geometry.boundingBox.clone().applyMatrix4(child.matrixWorld)); //但感觉如果最外层object大小不为1,要还原下scale再乘
  116678. //}//获取在scale为1时,表现出的大小
  116679. //Potree.Utils.makeTexDontResize(child.material.map)
  116680. //console.log(child.name, 'roughness',child.material.roughness,'metalness',child.material.metalness)
  116681. if(fileInfo_.unlit && (!(child.material instanceof BasicMaterial) /* || object.fileType == 'glb' */)){ //注释掉是因为已经写入到loader文件里了
  116682. //let material = new THREE.MeshBasicMaterial({map:child.material.map})
  116683. let material = new BasicMaterial({map : child.material.map, opacity:child.material.opacity, color:child.material.color}); //很奇怪glb的图会使原本的MeshBasicMaterial 会偏暗,所以自己重新写
  116684. //child.material.dispose()
  116685. child.material = material;
  116686. }
  116687. if(fileInfo_.useStandandMat && !(child.material instanceof MeshStandardMaterial)){
  116688. child.material = new MeshStandardMaterial();
  116689. }
  116690. if(child.material instanceof MeshStandardMaterial){
  116691. /* child.material.roughness = 0.7
  116692. child.material.metalness = 0.5 */
  116693. }
  116694. //纯色的还是不能用BasicMaterial
  116695. }
  116696. } );
  116697. }
  116698. this.objs.add(object);
  116699. if(fileInfo_.transform){
  116700. let setTransfrom = (name)=>{
  116701. let value = fileInfo_.transform[name];
  116702. if(!value)return
  116703. if(value instanceof Array){
  116704. object[name].fromArray(value);
  116705. }else {
  116706. object[name].copy(value);
  116707. }
  116708. };
  116709. setTransfrom('position');
  116710. setTransfrom('rotation');
  116711. setTransfrom('scale');
  116712. }
  116713. if(fileInfo_.moveWithPointcloud){
  116714. object.updateMatrix();
  116715. object.matrixAutoUpdate = false;
  116716. object.matrix.premultiply(viewer.scene.pointclouds[0].transformMatrix); //默认跟随第一个数据集
  116717. object.matrixWorldNeedsUpdate = true;
  116718. }
  116719. object.updateMatrixWorld();
  116720. MergeEditor.getBoundCenter(object); //初始化
  116721. done && done(object, fileInfo_);
  116722. this.dispatchEvent({type:'modelLoaded',model:object});
  116723. //如果需要点击出现transform工具需要它有select事件 如 viewer.objs.children[1].addEventListener('select',()=>{})
  116724. }
  116725. async loadModel(fileInfo, done, onProgress_, onError){
  116726. console.log('开始加载', Common.getNameFromURL(fileInfo.url) );
  116727. let boundingBox = new Box3();
  116728. /* if(!Potree.settings.boundAddObjs){
  116729. boundingBox.min.set(-0.5,-0.5,-0.5); boundingBox.max.set(0.5,0.5,0.5)
  116730. } */
  116731. if(fileInfo.objurl){
  116732. fileInfo.url = fileInfo.objurl, fileInfo.fileType = 'obj'; //兼容最早的
  116733. }
  116734. if(fileInfo.url instanceof Array){
  116735. if(fileInfo.url.length == 1){
  116736. fileInfo.url = fileInfo.url[0];
  116737. }else {
  116738. fileInfo.loadedCount = 0;
  116739. fileInfo.modelGroup = new Object3D; //parentGroup.name = fileInfo.title
  116740. fileInfo.url.forEach((url,i)=>{
  116741. let fileInfoS = Common.CloneObject(fileInfo);
  116742. fileInfoS.url = url;
  116743. fileInfoS.name = 'child-'+i;
  116744. fileInfoS.parentInfo = fileInfo;
  116745. this.loadModel(fileInfoS, done, onProgress_, onError);
  116746. });
  116747. return
  116748. }
  116749. }
  116750. fileInfo.url = Common.dealURL(fileInfo.url); //去除'+'
  116751. fileInfo.loadStartTime = Date.now();
  116752. //let fileType = fileInfo.tilesUrl ? '3dTiles' : fileInfo.objurl ? 'obj' : 'glb'
  116753. let loadDone = (object, fileInfo_ )=>{
  116754. this.modelLoaded(object, fileInfo_ || fileInfo , done);
  116755. };
  116756. let onProgress = function ( xhr ) {
  116757. if ( xhr.lengthComputable ) {
  116758. let percentComplete = xhr.loaded / xhr.total * 100;
  116759. //console.log( Math.round(percentComplete, 2) + '% downloaded' );
  116760. onProgress_ && onProgress_(percentComplete);
  116761. }
  116762. };
  116763. if(fileInfo.fileType == 'obj'){ //暂时不支持数组
  116764. if(fileInfo.mtlurl){
  116765. loaders.mtlLoader.load( fileInfo.mtlurl , (materials)=>{
  116766. materials.preload();
  116767. loaders.objLoader.setMaterials( materials ).load(fileInfo.objurl, (object, total)=>{
  116768. loadDone(object/* , total, fileInfo.objurl */);
  116769. }, onProgress, onError );
  116770. } , onProgress, onError );
  116771. }else {
  116772. loaders.objLoader.load(fileInfo.objurl, (object, total)=>{
  116773. loadDone(object);
  116774. }, onProgress, onError);
  116775. }
  116776. }else if(fileInfo.fileType == 'glb'){
  116777. loaders.glbLoader.unlitMat = true;//!!fileInfo.unlit
  116778. loaders.glbLoader.load(fileInfo.url, ( gltf, total )=>{
  116779. //console.log('loadGLTF', gltf)
  116780. loadDone(gltf.scene/* , total, fileInfo.url */);
  116781. }, onProgress, onError);
  116782. }else if(fileInfo.fileType == 'ply'){
  116783. loaders.plyLoader.load( fileInfo.url, (geometry) => {
  116784. let object;
  116785. console.log('ply加载完毕', geometry);
  116786. if(!geometry.index){//点云
  116787. object = new Points(geometry, new PointsMaterial({vertexColors:true, size:0.02}));
  116788. //141M的点云,intersect费时300ms以上
  116789. }else {//mesh
  116790. object = new Mesh(geometry);
  116791. }
  116792. loadDone(object);
  116793. });
  116794. }else if(fileInfo.fileType == '3dTiles'){
  116795. let result = await Loader3DTiles.load({
  116796. url: fileInfo.url,
  116797. gltfLoader : loaders.glbLoader,
  116798. //renderer: SceneRenderer.renderer
  116799. options: {
  116800. //dracoDecoderPath: '../utils/loaders/DRACOLoader/draco',
  116801. //basisTranscoderPath: '../utils/loaders/KTX2Loader/basis',
  116802. maximumScreenSpaceError: fileInfo.maximumScreenSpaceError || 80, //越小越清晰。 如果本身tiles很密很小这个值就不能很大。
  116803. //maxDepth: 100,
  116804. //maximumMemoryUsage: 100, //缓存大小,见tiles3DMaxMemory。单位M(但实际结果是 2.5*maximumMemoryUsage + 750 。超过2G会崩, 所以应该小于540) 若太小,密集的tile反复加载很卡. (任务管理器刷新网页后若内存不掉就要结束进程否则虚高)
  116805. debug: browser.urlHasValue('tilesBox'), //show box
  116806. parent: this.scene.scene,
  116807. is4dkk: fileInfo.is4dkk,//是否是4dkk中的模型. 通常maximumScreenSpaceError需要10
  116808. updateTime: fileInfo.updateTime, //加后缀防止缓存
  116809. },
  116810. });
  116811. console.log(result);
  116812. result.model.runtime = result.runtime;
  116813. let loaded = false;
  116814. let tileset = result.runtime.getTileset();
  116815. tileset.addEventListener('endTileLoading', function (data) {//Tileset3D
  116816. if (data.loadingCount == 0 && !loaded) {
  116817. loaded = true;
  116818. console.log('loaded!!!!!!!!!!!!!');
  116819. }
  116820. });
  116821. tileset.addEventListener('tileLoaded',(e)=>{ //每一个tile加载完要更改透明度
  116822. let opacity = result.model.parent == this.objs ? result.model.opacity : result.model.parent.opacity;//最多两层
  116823. MergeEditor.changeOpacity(e.tileContent,opacity);
  116824. //set Layers ?
  116825. });
  116826. {
  116827. let vi = true;
  116828. Object.defineProperty( result.model, "visible", {
  116829. get: function() {
  116830. return vi
  116831. },
  116832. set: function(v) {
  116833. vi = v;
  116834. tileset.visible = v; //同步,使不加载
  116835. tileset.nextForceUpdate = true;
  116836. }
  116837. });
  116838. }
  116839. loadDone(result.model/* , null, fileInfo.url */);
  116840. }else if(fileInfo.fileType == 'dxf'){
  116841. loaders.dxfLoader.load(fileInfo.url,(object)=>{
  116842. loadDone(object);
  116843. },fileInfo);
  116844. }else if(fileInfo.fileType == 'shp'){
  116845. loaders.shapeLoader.transform = viewer.transform.lonlatToLocal;
  116846. const shp = await loaders.shapeLoader.load(fileInfo.url);
  116847. const shpModel = shp.node;
  116848. loadDone(shpModel);
  116849. }else if(fileInfo.fileType == '3dgs'){
  116850. const gsViewer = new Potree.GaussianSplats3D.Viewer({
  116851. rootElement: this.renderArea,
  116852. threeScene: this.scene.scene,
  116853. renderer: this.renderer,
  116854. camera: this.mainViewport.camera,
  116855. useBuiltInControls: false,
  116856. //dropInMode: true,
  116857. // sharedMemoryForWorkers:false //否则 报错 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'DedicatedWorkerGlobalScope': SharedArrayBuffer transfer requires self.crossOriginIsolated.
  116858. });
  116859. //let path = Potree.resourcePath+'/models/gaussian/bonsai.ksplat';
  116860. gsViewer.addSplatScene(fileInfo.url, {
  116861. 'streamView': true
  116862. })
  116863. .then(() => {
  116864. gsViewer.start();
  116865. /* gsViewer.splatMesh.rotation.x = -2.365929590263301
  116866. gsViewer.splatMesh.position.z = 5 */
  116867. gsViewer.splatMesh.updateMatrix();
  116868. gsViewer.splatMesh.updateMatrixWorld();
  116869. gsViewer.splatMesh.visible = false;
  116870. //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)})
  116871. gsViewer.splatMesh.onSplatTreeReadyCallback = ()=>{
  116872. let {sceneMax,sceneMin} = gsViewer.splatMesh.splatTree.subTrees[0];
  116873. gsViewer.splatMesh.boundingBox.min.copy(sceneMin);
  116874. gsViewer.splatMesh.boundingBox.max.copy(sceneMax);
  116875. loadDone(gsViewer.splatMesh);
  116876. };
  116877. });
  116878. //window.gsViewer = gsViewer
  116879. viewer.addEventListener('render.begin2',(e)=>{
  116880. if(e.name == 'scene'){ //gsViewer.selfDrivenUpdate()
  116881. gsViewer.update();
  116882. if(gsViewer.initialized && gsViewer.splatRenderReady){
  116883. gsViewer.splatMesh.visible = true;
  116884. }
  116885. }
  116886. });
  116887. }
  116888. }
  116889. removeModel(model){
  116890. this.objs.remove(model);
  116891. let dispose = (e)=>{
  116892. e.geometry && e.geometry.dispose();
  116893. e.material && e.material.dispose();
  116894. };
  116895. model.traverse(e=>{
  116896. dispose(e);
  116897. });
  116898. if(Potree.settings.boundAddObjs){
  116899. this.updateModelBound();
  116900. }
  116901. }
  116902. setDisplay(state, cause='setDisplay'){//如果创建了iframe,主页的需要隐藏的话需要释放一些内存出来。iframe关闭前也释放下比较保险
  116903. state = !!state;
  116904. this.objs.children.forEach(e=>{
  116905. if(e.fileType == '3dTiles'){
  116906. let tileset = e.runtime.getTileset();
  116907. Potree.Utils.updateVisible(e, cause, state);
  116908. if(!state) tileset._cache.trim(); //使下一次update时dispose所有不可见的tiles
  116909. e.runtime.update(16, this.renderer, this.mainViewport.camera, true);
  116910. if(state) this.dispatchEvent('content_changed');
  116911. }
  116912. });
  116913. if(state){
  116914. Potree.pointBudget = 6*1000*1000; //先随便写一个, 随后mergeEditor.updateMemoryUsage
  116915. }else {
  116916. Potree.pointBudget = 0;
  116917. Potree.updatePointClouds(this.scene.pointclouds, this.mainViewport.camera, this.mainViewport.resolution );
  116918. this.images360.panoRenderer.disposeIdelTargets(); //如果也能清空当前使用的就好了,但是恢复就需要时间
  116919. this.images360.depthSampler.clearTexData();
  116920. }
  116921. this.dispatchEvent({type:'setDisplay',state});
  116922. this.paused = !state;
  116923. }
  116924. addFire(){
  116925. if(Potree.settings.number == 't-CwfhfqJ'){
  116926. let position = Potree.Utils.datasetPosTransform({
  116927. pointcloud:viewer.scene.pointclouds[0],
  116928. position: new Vector3(4.4318,-0.580291847759, -0.78),
  116929. fromDataset:true
  116930. });
  116931. viewer.modules.ParticleEditor.addParticle( {
  116932. type:'fire',
  116933. positions:[position],
  116934. radius:0.42,
  116935. height:10,
  116936. });
  116937. viewer.modules.ParticleEditor.addParticle( {
  116938. type:'smoke',
  116939. positions: [ new Vector3().addVectors(position,new Vector3(0,0,0.3))],
  116940. positionStyle : 'sphere' ,
  116941. positionRadius : 0.3,
  116942. sizeTween: [[0, 0.3, 0.9, 1], [0.05, 0.1, 1, 0.8]],
  116943. opacityBase : 0.2,
  116944. opacityTween :[ [0, 0.3, 0.7, 0.95, 1], [0, 0.2, 1 , 0.1, 0] ],
  116945. velocityBase : new Vector3( 0, 0, 1),
  116946. velocitySpread : new Vector3( 0.2, 0.2, -0.3),
  116947. accelerationBase : 0.2,
  116948. accelerationSpread : 0.7,
  116949. radius:0,
  116950. //particlesPerSecond : 30,
  116951. particleDeathAge : 3.0,
  116952. });
  116953. viewer.modules.ParticleEditor.addParticle( {
  116954. type:'explode',
  116955. name:'fire splash',
  116956. position: new Vector3().addVectors(position,new Vector3(0,0,0.3)),
  116957. size: 0.1,
  116958. sizeRange: 0.3,
  116959. sizeTween:[[0, 0.05, 0.3, 0.45], [0, 0.02, 0.1, 0.05] ],
  116960. opacityTween: [[0, 0.05, 0.3, 0.45], [1, 1, 0.5, 0]] ,
  116961. speed : 1, //sphere
  116962. speedRange : 4,
  116963. radius: 0.1,
  116964. acceleration : 0.3,
  116965. accelerationRange : 1,
  116966. particleSpaceTime:0,
  116967. strength:4,
  116968. });
  116969. }
  116970. }
  116971. addVideo(){
  116972. if(Potree.settings.number != 'SS-t-P6zBR73Gke')return
  116973. var geo = new PlaneGeometry(1, 1, 1, 1);
  116974. var videoInfo = this.videoInfo = [
  116975. {
  116976. id: '40-2',
  116977. url: 'https://laser-oss.4dkankan.com/testdata/SS-t-P6zBR73Gke/temp/poi/2022/05/10/0aabafee-36b8-455d-9c11-0780bf694786.mp4',
  116978. rotation:[-1.494468618954883, -1.4987317433158989, -3.061254983446741],
  116979. position:[ 19.801820617361624, 2.884673619844108, -0.03362305858221648],
  116980. scale:[3.5741423153151763, 2.8738725275578703, 1],
  116981. },
  116982. {
  116983. id: 40,
  116984. /* rotation:[-1.534692822378723, 0.01083403560862361, 3.141535283661569],
  116985. position:[17.2934294239949861, 2.413510747928117, -0.008057029580231356], */
  116986. url: 'https://laser-oss.4dkankan.com/testdata/SS-t-P6zBR73Gke/temp/poi/2022/05/09/7896d6ef-a2d6-4fd7-949c-768782a5b484.mp4',
  116987. rotation:[-1.5487684197910518, 0.021848470169552752, -3.1387534893955236],
  116988. position:[17.277316608096, 2.0840432922115846, -0.0931149415437065],
  116989. scale:[2.0821757723834047, 0.6129478480765236, 1],
  116990. visibles: [40]
  116991. },
  116992. ];
  116993. let add = (info)=>{
  116994. var video = $(`<video controls="controls" loop autoplay x5-playsinline="" webkit-playsinline="true" playsinline="true" controlslist="nodownload"></video>`)[0];
  116995. video.setAttribute("crossOrigin", 'Anonymous');
  116996. video.src = info.url || Potree.resourcePath+`/video/${Potree.settings.number}/${info.id}.mp4`;
  116997. var map = new VideoTexture(video);
  116998. var plane = this.videoPlane = new Mesh(geo, new MeshBasicMaterial({
  116999. color:"#ffffff",
  117000. transparent: !0,
  117001. depthTest:false,
  117002. opacity:0 ,
  117003. //side:2,
  117004. map
  117005. }));
  117006. plane.position.fromArray(info.position);
  117007. plane.rotation.fromArray(info.rotation);
  117008. info.scale && plane.scale.fromArray(info.scale);
  117009. this.scene.scene.add(plane);
  117010. info.plane = plane;
  117011. plane.boundingBox = new Box3(new Vector3(0,-0.5,0),new Vector3(1,-0.4,0.2));
  117012. video.addEventListener('loadeddata', function(e) {
  117013. video.play();
  117014. if(!info.visibles/* ||!viewer.images360.currentPano || info.visibles.includes(viewer.images360.currentPano.id) */){
  117015. plane.material.opacity = 1;
  117016. }
  117017. info.scale || plane.scale.set(video.videoWidth/1000,video.videoHeight/1000,1); // 1080 * 1920
  117018. console.log('video loadeddata', info.id);
  117019. });
  117020. if(info.visibles){
  117021. this.images360.addEventListener('flyToPano' ,(e)=>{//飞之前
  117022. if(info.visibles.includes(e.toPano.pano.id)){ //出现
  117023. setTimeout(()=>{
  117024. plane.visible = true;
  117025. video.currentTime = 0;
  117026. video.play();
  117027. if(video.paused){
  117028. var startPlay = ()=>{
  117029. plane.visible && video.play();
  117030. this.removeEventListener('global_mousedown', startPlay);
  117031. };
  117032. this.addEventListener('global_mousedown', startPlay);
  117033. }
  117034. Potree.settings.zoom.enabled = false;
  117035. transitions.start(lerp.property(plane.material, "opacity", 1 ) , e.toPano.duration*0.4 , ()=>{
  117036. }, 0, easing['easeInOutQuad']);
  117037. }, e.toPano.duration*0.6); //时间上不能和消失的重叠 延迟
  117038. }else {
  117039. //消失
  117040. transitions.start(lerp.property(plane.material, "opacity", 0, ) , e.toPano.duration*0.4, ()=>{
  117041. if(!info){
  117042. plane.visible = false;
  117043. video.pause();
  117044. Potree.settings.zoom.enabled = true;
  117045. }
  117046. }, 0, easing['easeInOutQuad']);
  117047. }
  117048. });
  117049. }
  117050. var startPlay = ()=>{
  117051. video.play();
  117052. //video.pause()
  117053. //video.currentTime = 0.1;
  117054. this.removeEventListener('global_mousedown', startPlay);
  117055. };
  117056. this.addEventListener('global_mousedown', startPlay);
  117057. Potree.settings.isTest && plane.addEventListener('select',(e)=>{console.log(e);});
  117058. };
  117059. videoInfo.forEach(info=>{
  117060. add(info);
  117061. });
  117062. /* this.images360.addEventListener('flyToPano' ,(e)=>{//飞之前
  117063. if(Potree.settings.displayMode != 'showPanos') return
  117064. let info = videoInfo[e.toPano.pano.id]
  117065. if(info ){ //出现
  117066. setTimeout(()=>{
  117067. plane.visible = true;
  117068. plane.position.fromArray(info.position)
  117069. plane.rotation.fromArray(info.rotation)
  117070. video.src = Potree.resourcePath+`/video/${Potree.settings.number}/${e.toPano.pano.id}.mp4`
  117071. video.play();
  117072. video.currentTime = 0
  117073. Potree.settings.zoom.enabled = false
  117074. transitions.start(lerp.property(plane.material, "opacity", 1 ) , e.toPano.duration*0.4 , ()=>{
  117075. }, 0, easing['easeInOutQuad'])
  117076. }, e.toPano.duration*0.6) //时间上不能和消失的重叠 延迟
  117077. }
  117078. //消失
  117079. transitions.start(lerp.property(plane.material, "opacity", 0, ) , e.toPano.duration*0.4, ()=>{
  117080. if(!info){
  117081. plane.visible = false
  117082. video.pause()
  117083. Potree.settings.zoom.enabled = true
  117084. }
  117085. }, 0, easing['easeInOutQuad'])
  117086. })
  117087. this.images360.addEventListener('endChangeMode',(e)=>{ //暂时不处理初始加载时就在有视频的点位上的情况
  117088. if(e.mode == 'showPanos'){
  117089. let info = videoInfo[this.images360.currentPano.id]
  117090. if(info ){ //出现
  117091. plane.visible = true;
  117092. plane.position.fromArray(info.position)
  117093. plane.rotation.fromArray(info.rotation)
  117094. plane.material.opacity = 0
  117095. video.src = Potree.resourcePath+`/video/${Potree.settings.number}/${this.images360.currentPano.id}.mp4`
  117096. video.play();
  117097. video.currentTime = 0
  117098. Potree.settings.zoom.enabled = false
  117099. transitions.start(lerp.property(plane.material, "opacity", 1, (e)=>{console.log('fadeIn',e)}) , 300 , ()=>{
  117100. }, 0, easing['easeInOutQuad'])
  117101. }
  117102. }else{
  117103. plane.visible = false;
  117104. Potree.settings.zoom.enabled = true
  117105. }
  117106. })
  117107. */
  117108. }
  117109. /* addTube(){//加水管 自动生成
  117110. if(Potree.settings.number == 't-8KbK1JjubE'){
  117111. let boundingBox = new THREE.Box3()
  117112. boundingBox.min.set(-1,-1,-1); boundingBox.max.set(1,1,1)
  117113. let radius = 0.08;
  117114. let radialSegments = 5
  117115. let radSegments = Math.PI*2 / radialSegments
  117116. var circlePts = [];//横截面
  117117. for(let i=0;i<radialSegments;i++){
  117118. let angle = radSegments * i;
  117119. circlePts.push(new THREE.Vector2(radius * Math.cos(angle), radius * Math.sin(angle) ))
  117120. }
  117121. var count = 0
  117122. var addMesh = (color, path, height)=>{//height:在path之上的高度,负数代表在path之下
  117123. var name = 'cylinder'+count
  117124. var mat = new THREE.MeshStandardMaterial({color, depthTest:false, roughness:0.4,metalness:0.5}) 
  117125. let linePath = path.map(e=>new THREE.Vector3().copy(e).setZ(e.z+height))
  117126. let geo = MeshDraw.getExtrudeGeo( circlePts, null,{ extrudePath:linePath, tension:0.2} )
  117127. var mesh = new THREE.Mesh(geo,mat);
  117128. mesh.name = name
  117129. window[name] = mesh
  117130. mesh.boundingBox = boundingBox
  117131. mesh.matrixAutoUpdate = false
  117132. mesh.matrix.copy(viewer.scene.pointclouds[0].transformMatrix)
  117133. mesh.matrixWorldNeedsUpdate = true
  117134. this.scene.scene.add(mesh);
  117135. count ++
  117136. }
  117137. let linePath, height
  117138. //地上管子 黄色
  117139. 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}
  117140. ,{"x":43.58,"y":27.7,"z":-0.97},{"x":40.22,"y":35.37,"z":-0.67}// 拐弯向右
  117141. , {"x":39.18,"y":36.71,"z":0.35},{"x":38.69,"y":36.04,"z":18.04} // 拐弯向上
  117142. ]
  117143. height = radius + 0.05;
  117144. addMesh('#b86', linePath, height)
  117145. //地下管子 藍色
  117146. 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}
  117147. ]
  117148. height = -0.5;
  117149. addMesh('#48a', linePath, height)
  117150. }
  117151. } */
  117152. addTube(datas){//加水管 自动生成
  117153. for(let number in datas){
  117154. if(number == Potree.settings.number){
  117155. let data = datas[number];
  117156. let boundingBox = new Box3();
  117157. boundingBox.min.set(-1,-1,-1); boundingBox.max.set(1,1,1);
  117158. var index = 0;
  117159. var addMesh = ({color, path, height,fromDataset, radius=0.08, datasetId=Potree.settings.originDatasetId, spaceDis, tension=0.1, visiEntity}={})=>{//height:在path之上的高度,负数代表在path之下
  117160. var name = 'tube_'+index;
  117161. let radialSegments = 30;//THREE.Math.clamp( Math.round(radius * 800), 10, 40)
  117162. let radSegments = Math.PI*2 / radialSegments;
  117163. var circlePts = [];//横截面
  117164. for(let i=0;i<radialSegments;i++){
  117165. let angle = radSegments * i;
  117166. circlePts.push(new Vector2(radius * Math.cos(angle), radius * Math.sin(angle) ));
  117167. }
  117168. var mat = new MeshStandardMaterial({color, /* wireframe:true, depthTest:false,*/ roughness:0.9,metalness:0.3}); 
  117169. let linePath = path.map(e=>{
  117170. e instanceof Array && (e = new Vector3().fromArray(e));
  117171. let pos;
  117172. if(fromDataset){
  117173. //获取:JSON.stringify(viewer.scene.measurements[0].dataset_points.map(e=>Potree.math.toPrecision(e.toArray(),3)))
  117174. pos = Potree.Utils.datasetPosTransform({ fromDataset: true, position:e, datasetId});
  117175. }else {
  117176. pos = new Vector3().copy(e);
  117177. }
  117178. return pos.setZ(pos.z+height)
  117179. });
  117180. console.log(linePath);
  117181. let geo = MeshDraw.getExtrudeGeo( circlePts, null,{ extrudePath:linePath, tension, spaceDis} );
  117182. var mesh = new Mesh(geo,mat);
  117183. mesh.name = name;
  117184. window[name] = mesh;
  117185. mesh.boundingBox = boundingBox;
  117186. mesh.matrixAutoUpdate = false;
  117187. fromDataset || mesh.matrix.copy(viewer.scene.pointclouds[0].transformMatrix);
  117188. mesh.matrixWorldNeedsUpdate = true;
  117189. this.scene.scene.add(mesh);
  117190. if(visiEntity){
  117191. this.modules.SiteModel.bus.addEventListener('buildingChange',(e)=>{
  117192. Potree.Utils.updateVisible(mesh,'isInEntity', e.entity && e.entity.name == visiEntity);
  117193. });
  117194. }
  117195. };
  117196. while(index < data.length){
  117197. addMesh(data[index]);
  117198. index++;
  117199. }
  117200. }
  117201. }
  117202. /*
  117203. 可能用到的
  117204. viewer.scene.measurements.forEach(e=>e.edgeLabels.forEach(e=>Potree.Utils.updateVisible(e,'f',false)))
  117205. JSON.stringify(viewer.scene.measurements.find(e=>e.visible).dataset_points.map(e=>Potree.math.toPrecision(e.toArray(),3)))
  117206. */
  117207. }
  117208. addSprite(e){//api
  117209. let sprite;
  117210. if(e.text != void 0){
  117211. sprite = new TextSprite(e );
  117212. }else {
  117213. let map = texLoader.load(src);
  117214. e.map = map;
  117215. sprite = new Sprite(e );
  117216. }
  117217. return sprite
  117218. }
  117219. };
  117220. //------ CLIP 默认clipTask都是clipInside ----------------------
  117221. /*
  117222. 并集相当于加法,交集相当于乘法。 所有结果都能展开成多个乘积相加。
  117223. 假设有4个clipBoxes,ABCD, 如果是 A*B + C*D ,那么这是最终结果。 如果是 (A+B)*(C+D) = A*C+A*D+B*C+B*D
  117224. */
  117225. /*
  117226. let Clips = {
  117227. boxes : [],
  117228. unionGroups : [], //二维数组。最外层要求并集,里层要求交集(如果只有一个元素就是本身)。总结起来就是要求一堆交集的并集
  117229. shaderParams:{},
  117230. needsUpdate : true,
  117231. addClip(box, clipMethod){
  117232. //不允许重复
  117233. if(this.boxes.includes(box)){
  117234. return console.warn('addClip重复添加了box',box)
  117235. }
  117236. boxes.push(box)
  117237. if(clipMethod == 'any'){//并
  117238. this.unionGroups.push([box])
  117239. }else if(clipMethod == 'all'){//交
  117240. this.unionGroups.forEach(mixGroup=>mixGroup.push(box))
  117241. }
  117242. this.needsUpdate = true
  117243. },
  117244. removeClip(box){
  117245. if(!this.boxes.includes(box)){
  117246. return console.warn('removeClip没有找到该box',box)
  117247. }
  117248. var newGroups = [];
  117249. this.unionGroups.forEach(mixGroup=>{
  117250. if(mixGroup.length == 1 && mixGroup[0] == box)return;//直接删除
  117251. newGroups.push(mixGroup.filter(e=>e!=box));
  117252. })
  117253. this.unionGroups = newGroups;
  117254. this.needsUpdate = true
  117255. }
  117256. ,
  117257. clearClip(){
  117258. this.boxes = [];
  117259. this.unionGroups = []
  117260. this.needsUpdate = true
  117261. }
  117262. ,
  117263. updateShaderParams(){//没写完 - - 见 pointcloud clip.vs
  117264. //uniform mat4 clipBoxes[num_clipboxes];
  117265. //uniform int clipBoxGroupCount;
  117266. //uniform int mixClipIndices[clipboxGroupItemCount]; //把所有的要求都直接放到数组内
  117267. //这里需要转为Float32Array..? 参考material.setClipBoxes
  117268. let everyClipGroupCount = this.unionGroups.map(e=>e.length)
  117269. let mixClipIndices = []
  117270. this.unionGroups.forEach(e=>{
  117271. mixClipIndices.push(...e)
  117272. })
  117273. this.shaderParams = {
  117274. num_clipboxes : this.boxes.length,
  117275. clipBoxGroupCount : this.unionGroups.length,
  117276. everyClipGroupCount,
  117277. clipBoxIndexCount: mixClipIndices.length,
  117278. mixClipIndices
  117279. }
  117280. }
  117281. ,
  117282. getShaderParams(){//每次要传递参数到shader中,执行这个就好
  117283. if(this.needsUpdate){
  117284. this.updateShaderParams()
  117285. }
  117286. return this.shaderParams
  117287. }
  117288. }
  117289. */
  117290. /**
  117291. * @author mschuetz / http://mschuetz.at
  117292. *
  117293. * adapted from THREE.OrbitControls by
  117294. *
  117295. * @author qiao / https://github.com/qiao
  117296. * @author mrdoob / http://mrdoob.com
  117297. * @author alteredq / http://alteredqualia.com/
  117298. * @author WestLangley / http://github.com/WestLangley
  117299. * @author erich666 / http://erichaines.com
  117300. *
  117301. *
  117302. *
  117303. */
  117304. class OrbitControls$1 extends EventDispatcher$1{
  117305. constructor(viewer){
  117306. super();
  117307. this.viewer = viewer;
  117308. this.renderer = viewer.renderer;
  117309. this.scene = null;
  117310. this.sceneControls = new Scene();
  117311. this.rotationSpeed = 5;
  117312. this.fadeFactor = 20;
  117313. this.yawDelta = 0;
  117314. this.pitchDelta = 0;
  117315. this.panDelta = new Vector2(0, 0);
  117316. this.radiusDelta = 0;
  117317. this.doubleClockZoomEnabled = true;
  117318. this.tweens = [];
  117319. let drag = (e) => {
  117320. if (e.drag.object !== null) {
  117321. return;
  117322. }
  117323. if (e.drag.startHandled === undefined) {
  117324. e.drag.startHandled = true;
  117325. this.dispatchEvent({type: 'start'});
  117326. }
  117327. let ndrag = {
  117328. x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
  117329. y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
  117330. };
  117331. if (e.drag.mouse === MOUSE$1.LEFT) {
  117332. this.yawDelta += ndrag.x * this.rotationSpeed;
  117333. this.pitchDelta += ndrag.y * this.rotationSpeed;
  117334. this.stopTweens();
  117335. } else if (e.drag.mouse === MOUSE$1.RIGHT) {
  117336. this.panDelta.x += ndrag.x;
  117337. this.panDelta.y += ndrag.y;
  117338. this.stopTweens();
  117339. }
  117340. };
  117341. let drop = e => {
  117342. this.dispatchEvent({type: 'end'});
  117343. };
  117344. let scroll = (e) => {
  117345. let resolvedRadius = this.scene.view.radius + this.radiusDelta;
  117346. this.radiusDelta += -e.delta * resolvedRadius * 0.1;
  117347. this.stopTweens();
  117348. };
  117349. let dblclick = (e) => {
  117350. if(this.doubleClockZoomEnabled){
  117351. this.zoomToLocation(e.mouse);
  117352. }
  117353. };
  117354. let previousTouch = null;
  117355. let touchStart = e => {
  117356. previousTouch = e;
  117357. };
  117358. let touchEnd = e => {
  117359. previousTouch = e;
  117360. };
  117361. let touchMove = e => {
  117362. if (e.touches.length === 2 && previousTouch.touches.length === 2){
  117363. let prev = previousTouch;
  117364. let curr = e;
  117365. let prevDX = prev.touches[0].pageX - prev.touches[1].pageX;
  117366. let prevDY = prev.touches[0].pageY - prev.touches[1].pageY;
  117367. let prevDist = Math.sqrt(prevDX * prevDX + prevDY * prevDY);
  117368. let currDX = curr.touches[0].pageX - curr.touches[1].pageX;
  117369. let currDY = curr.touches[0].pageY - curr.touches[1].pageY;
  117370. let currDist = Math.sqrt(currDX * currDX + currDY * currDY);
  117371. let delta = currDist / prevDist;
  117372. let resolvedRadius = this.scene.view.radius + this.radiusDelta;
  117373. let newRadius = resolvedRadius / delta;
  117374. this.radiusDelta = newRadius - resolvedRadius;
  117375. this.stopTweens();
  117376. }else if(e.touches.length === 3 && previousTouch.touches.length === 3){
  117377. let prev = previousTouch;
  117378. let curr = e;
  117379. let prevMeanX = (prev.touches[0].pageX + prev.touches[1].pageX + prev.touches[2].pageX) / 3;
  117380. let prevMeanY = (prev.touches[0].pageY + prev.touches[1].pageY + prev.touches[2].pageY) / 3;
  117381. let currMeanX = (curr.touches[0].pageX + curr.touches[1].pageX + curr.touches[2].pageX) / 3;
  117382. let currMeanY = (curr.touches[0].pageY + curr.touches[1].pageY + curr.touches[2].pageY) / 3;
  117383. let delta = {
  117384. x: (currMeanX - prevMeanX) / this.renderer.domElement.clientWidth,
  117385. y: (currMeanY - prevMeanY) / this.renderer.domElement.clientHeight
  117386. };
  117387. this.panDelta.x += delta.x;
  117388. this.panDelta.y += delta.y;
  117389. this.stopTweens();
  117390. }
  117391. previousTouch = e;
  117392. };
  117393. this.addEventListener('touchstart', touchStart);
  117394. this.addEventListener('touchend', touchEnd);
  117395. this.addEventListener('touchmove', touchMove);
  117396. this.addEventListener('drag', drag);
  117397. this.addEventListener('drop', drop);
  117398. this.addEventListener('mousewheel', scroll);
  117399. this.addEventListener('dblclick', dblclick);
  117400. }
  117401. setScene (scene) {
  117402. this.scene = scene;
  117403. }
  117404. stop(){
  117405. this.yawDelta = 0;
  117406. this.pitchDelta = 0;
  117407. this.radiusDelta = 0;
  117408. this.panDelta.set(0, 0);
  117409. }
  117410. zoomToLocation(mouse){
  117411. let camera = this.scene.getActiveCamera();
  117412. let I = Utils.getMousePointCloudIntersection(
  117413. mouse,
  117414. camera,
  117415. this.viewer,
  117416. this.scene.pointclouds,
  117417. {pickClipped: true});
  117418. if (I === null) {
  117419. return;
  117420. }
  117421. let targetRadius = 0;
  117422. {
  117423. let minimumJumpDistance = 0.2;
  117424. let domElement = this.renderer.domElement;
  117425. let ray = Utils.mouseToRay(mouse, camera, domElement.clientWidth, domElement.clientHeight);
  117426. let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  117427. let lastNode = nodes[nodes.length - 1];
  117428. let radius = lastNode.getBoundingSphere(new Sphere()).radius;
  117429. targetRadius = Math.min(this.scene.view.radius, radius);
  117430. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  117431. }
  117432. let d = this.scene.view.direction.multiplyScalar(-1);
  117433. let cameraTargetPosition = new Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  117434. // TODO Unused: let controlsTargetPosition = I.location;
  117435. let animationDuration = 600;
  117436. let easing = TWEEN.Easing.Quartic.Out;
  117437. { // animate
  117438. let value = {x: 0};
  117439. let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
  117440. tween.easing(easing);
  117441. this.tweens.push(tween);
  117442. let startPos = this.scene.view.position.clone();
  117443. let targetPos = cameraTargetPosition.clone();
  117444. let startRadius = this.scene.view.radius;
  117445. let targetRadius = cameraTargetPosition.distanceTo(I.location);
  117446. tween.onUpdate(() => {
  117447. let t = value.x;
  117448. this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  117449. this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  117450. this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  117451. this.scene.view.radius = (1 - t) * startRadius + t * targetRadius;
  117452. this.viewer.setMoveSpeed(this.scene.view.radius);
  117453. });
  117454. tween.onComplete(() => {
  117455. this.tweens = this.tweens.filter(e => e !== tween);
  117456. });
  117457. tween.start();
  117458. }
  117459. }
  117460. stopTweens () {
  117461. this.tweens.forEach(e => e.stop());
  117462. this.tweens = [];
  117463. }
  117464. update (delta) {
  117465. let view = this.scene.view;
  117466. { // apply rotation
  117467. let progression = Math.min(1, this.fadeFactor * delta);
  117468. let yaw = view.yaw;
  117469. let pitch = view.pitch;
  117470. let pivot = view.getPivot();
  117471. yaw -= progression * this.yawDelta;
  117472. pitch -= progression * this.pitchDelta;
  117473. view.yaw = yaw;
  117474. view.pitch = pitch;
  117475. let V = this.scene.view.direction.multiplyScalar(-view.radius);
  117476. let position = new Vector3().addVectors(pivot, V);
  117477. view.position.copy(position);
  117478. }
  117479. { // apply pan
  117480. let progression = Math.min(1, this.fadeFactor * delta);
  117481. let panDistance = progression * view.radius * 3;
  117482. let px = -this.panDelta.x * panDistance;
  117483. let py = this.panDelta.y * panDistance;
  117484. view.pan(px, py);
  117485. }
  117486. { // apply zoom
  117487. let progression = Math.min(1, this.fadeFactor * delta);
  117488. // let radius = view.radius + progression * this.radiusDelta * view.radius * 0.1;
  117489. let radius = view.radius + progression * this.radiusDelta;
  117490. let V = view.direction.multiplyScalar(-radius);
  117491. let position = new Vector3().addVectors(view.getPivot(), V);
  117492. view.radius = radius;
  117493. view.position.copy(position);
  117494. }
  117495. {
  117496. let speed = view.radius;
  117497. this.viewer.setMoveSpeed(speed);
  117498. }
  117499. { // decelerate over time
  117500. let progression = Math.min(1, this.fadeFactor * delta);
  117501. let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  117502. this.yawDelta *= attenuation;
  117503. this.pitchDelta *= attenuation;
  117504. this.panDelta.multiplyScalar(attenuation);
  117505. // this.radiusDelta *= attenuation;
  117506. this.radiusDelta -= progression * this.radiusDelta;
  117507. }
  117508. }
  117509. };
  117510. /**
  117511. * @author mschuetz / http://mschuetz.at
  117512. *
  117513. * adapted from THREE.OrbitControls by
  117514. *
  117515. * @author qiao / https://github.com/qiao
  117516. * @author mrdoob / http://mrdoob.com
  117517. * @author alteredq / http://alteredqualia.com/
  117518. * @author WestLangley / http://github.com/WestLangley
  117519. * @author erich666 / http://erichaines.com
  117520. *
  117521. *
  117522. *
  117523. */
  117524. class FirstPersonControls$1 extends EventDispatcher$1 {//old
  117525. constructor (viewer) {
  117526. super();
  117527. this.viewer = viewer;
  117528. this.renderer = viewer.renderer;
  117529. this.scene = null;
  117530. this.sceneControls = new Scene();
  117531. this.rotationSpeed = 200;
  117532. this.moveSpeed = 10;
  117533. this.lockElevation = false;
  117534. this.keys = {
  117535. FORWARD: ['W'.charCodeAt(0), 38],
  117536. BACKWARD: ['S'.charCodeAt(0), 40],
  117537. LEFT: ['A'.charCodeAt(0), 37],
  117538. RIGHT: ['D'.charCodeAt(0), 39],
  117539. UP: ['R'.charCodeAt(0), 33],
  117540. DOWN: ['F'.charCodeAt(0), 34]
  117541. };
  117542. this.fadeFactor = 50;
  117543. this.yawDelta = 0;
  117544. this.pitchDelta = 0;
  117545. this.translationDelta = new Vector3(0, 0, 0);
  117546. this.translationWorldDelta = new Vector3(0, 0, 0);
  117547. this.tweens = [];
  117548. let drag = (e) => {
  117549. if (e.drag.object !== null) {
  117550. return;
  117551. }
  117552. if (e.drag.startHandled === undefined) {
  117553. e.drag.startHandled = true;
  117554. this.dispatchEvent({type: 'start'});
  117555. }
  117556. let moveSpeed = this.viewer.getMoveSpeed();
  117557. let ndrag = {
  117558. x: e.drag.lastDrag.x / this.renderer.domElement.clientWidth,
  117559. y: e.drag.lastDrag.y / this.renderer.domElement.clientHeight
  117560. };
  117561. if (e.drag.mouse === MOUSE$1.LEFT) {
  117562. this.yawDelta += ndrag.x * this.rotationSpeed;
  117563. this.pitchDelta += ndrag.y * this.rotationSpeed;
  117564. } else if (e.drag.mouse === MOUSE$1.RIGHT) {
  117565. this.translationDelta.x -= ndrag.x * moveSpeed * 100;
  117566. this.translationDelta.z += ndrag.y * moveSpeed * 100;
  117567. }
  117568. };
  117569. let drop = e => {
  117570. this.dispatchEvent({type: 'end'});
  117571. };
  117572. let scroll = (e) => {
  117573. let speed = this.viewer.getMoveSpeed();
  117574. if (e.delta < 0) {
  117575. speed = speed * 0.9;
  117576. } else if (e.delta > 0) {
  117577. speed = speed / 0.9;
  117578. }
  117579. speed = Math.max(speed, 0.1);
  117580. this.viewer.setMoveSpeed(speed);
  117581. };
  117582. let dblclick = (e) => {
  117583. this.zoomToLocation(e.mouse);
  117584. };
  117585. this.addEventListener('drag', drag);
  117586. this.addEventListener('drop', drop);
  117587. this.addEventListener('mousewheel', scroll);
  117588. this.addEventListener('dblclick', dblclick);
  117589. }
  117590. setScene (scene) {
  117591. this.scene = scene;
  117592. }
  117593. stop(){
  117594. this.yawDelta = 0;
  117595. this.pitchDelta = 0;
  117596. this.translationDelta.set(0, 0, 0);
  117597. }
  117598. zoomToLocation(mouse){
  117599. let camera = this.scene.getActiveCamera();
  117600. let I = Utils.getMousePointCloudIntersection(
  117601. mouse,
  117602. camera,
  117603. this.viewer,
  117604. this.scene.pointclouds);
  117605. if (I === null) {
  117606. return;
  117607. }
  117608. let targetRadius = 0;
  117609. {
  117610. let minimumJumpDistance = 0.2;
  117611. let domElement = this.renderer.domElement;
  117612. let ray = Utils.mouseToRay(mouse, camera, domElement.clientWidth, domElement.clientHeight);
  117613. let nodes = I.pointcloud.nodesOnRay(I.pointcloud.visibleNodes, ray);
  117614. let lastNode = nodes[nodes.length - 1];
  117615. let radius = lastNode.getBoundingSphere(new Sphere()).radius;
  117616. targetRadius = Math.min(this.scene.view.radius, radius);
  117617. targetRadius = Math.max(minimumJumpDistance, targetRadius);
  117618. }
  117619. let d = this.scene.view.direction.multiplyScalar(-1);
  117620. let cameraTargetPosition = new Vector3().addVectors(I.location, d.multiplyScalar(targetRadius));
  117621. // TODO Unused: let controlsTargetPosition = I.location;
  117622. let animationDuration = 600;
  117623. let easing = TWEEN.Easing.Quartic.Out;
  117624. { // animate
  117625. let value = {x: 0};
  117626. let tween = new TWEEN.Tween(value).to({x: 1}, animationDuration);
  117627. tween.easing(easing);
  117628. this.tweens.push(tween);
  117629. let startPos = this.scene.view.position.clone();
  117630. let targetPos = cameraTargetPosition.clone();
  117631. let startRadius = this.scene.view.radius;
  117632. let targetRadius = cameraTargetPosition.distanceTo(I.location);
  117633. tween.onUpdate(() => {
  117634. let t = value.x;
  117635. this.scene.view.position.x = (1 - t) * startPos.x + t * targetPos.x;
  117636. this.scene.view.position.y = (1 - t) * startPos.y + t * targetPos.y;
  117637. this.scene.view.position.z = (1 - t) * startPos.z + t * targetPos.z;
  117638. this.scene.view.radius = (1 - t) * startRadius + t * targetRadius;
  117639. this.viewer.setMoveSpeed(this.scene.view.radius / 2.5);
  117640. });
  117641. tween.onComplete(() => {
  117642. this.tweens = this.tweens.filter(e => e !== tween);
  117643. });
  117644. tween.start();
  117645. }
  117646. }
  117647. update (delta) {
  117648. let view = this.scene.view;
  117649. { // cancel move animations on user input
  117650. let changes = [ this.yawDelta,
  117651. this.pitchDelta,
  117652. this.translationDelta.length(),
  117653. this.translationWorldDelta.length() ];
  117654. let changeHappens = changes.some(e => Math.abs(e) > 0.001);
  117655. if (changeHappens && this.tweens.length > 0) {
  117656. this.tweens.forEach(e => e.stop());
  117657. this.tweens = [];
  117658. }
  117659. }
  117660. { // accelerate while input is given
  117661. let ih = this.viewer.inputHandler;
  117662. let moveForward = this.keys.FORWARD.some(e => ih.pressedKeys[e]);
  117663. let moveBackward = this.keys.BACKWARD.some(e => ih.pressedKeys[e]);
  117664. let moveLeft = this.keys.LEFT.some(e => ih.pressedKeys[e]);
  117665. let moveRight = this.keys.RIGHT.some(e => ih.pressedKeys[e]);
  117666. let moveUp = this.keys.UP.some(e => ih.pressedKeys[e]);
  117667. let moveDown = this.keys.DOWN.some(e => ih.pressedKeys[e]);
  117668. if(this.lockElevation){
  117669. let dir = view.direction;
  117670. dir.z = 0;
  117671. dir.normalize();
  117672. if (moveForward && moveBackward) {
  117673. this.translationWorldDelta.set(0, 0, 0);
  117674. } else if (moveForward) {
  117675. this.translationWorldDelta.copy(dir.multiplyScalar(this.viewer.getMoveSpeed()));
  117676. } else if (moveBackward) {
  117677. this.translationWorldDelta.copy(dir.multiplyScalar(-this.viewer.getMoveSpeed()));
  117678. }
  117679. }else {
  117680. if (moveForward && moveBackward) {
  117681. this.translationDelta.y = 0;
  117682. } else if (moveForward) {
  117683. this.translationDelta.y = this.viewer.getMoveSpeed();
  117684. } else if (moveBackward) {
  117685. this.translationDelta.y = -this.viewer.getMoveSpeed();
  117686. }
  117687. }
  117688. if (moveLeft && moveRight) {
  117689. this.translationDelta.x = 0;
  117690. } else if (moveLeft) {
  117691. this.translationDelta.x = -this.viewer.getMoveSpeed();
  117692. } else if (moveRight) {
  117693. this.translationDelta.x = this.viewer.getMoveSpeed();
  117694. }
  117695. if (moveUp && moveDown) {
  117696. this.translationWorldDelta.z = 0;
  117697. } else if (moveUp) {
  117698. this.translationWorldDelta.z = this.viewer.getMoveSpeed();
  117699. } else if (moveDown) {
  117700. this.translationWorldDelta.z = -this.viewer.getMoveSpeed();
  117701. }
  117702. }
  117703. { // apply rotation
  117704. let yaw = view.yaw;
  117705. let pitch = view.pitch;
  117706. yaw -= this.yawDelta * delta;
  117707. pitch -= this.pitchDelta * delta;
  117708. view.yaw = yaw;
  117709. view.pitch = pitch;
  117710. }
  117711. { // apply translation
  117712. view.translate(
  117713. this.translationDelta.x * delta,
  117714. this.translationDelta.y * delta,
  117715. this.translationDelta.z * delta
  117716. );
  117717. view.translateWorld(
  117718. this.translationWorldDelta.x * delta,
  117719. this.translationWorldDelta.y * delta,
  117720. this.translationWorldDelta.z * delta
  117721. );
  117722. }
  117723. { // set view target according to speed
  117724. view.radius = 3 * this.viewer.getMoveSpeed();
  117725. }
  117726. { // decelerate over time
  117727. let attenuation = Math.max(0, 1 - this.fadeFactor * delta);
  117728. this.yawDelta *= attenuation;
  117729. this.pitchDelta *= attenuation;
  117730. this.translationDelta.multiplyScalar(attenuation);
  117731. this.translationWorldDelta.multiplyScalar(attenuation);
  117732. }
  117733. }
  117734. };
  117735. OrthographicCamera.prototype.zoomTo = function( node, factor = 1){
  117736. if ( !node.geometry && !node.boundingBox) {
  117737. return;
  117738. }
  117739. // TODO
  117740. //let minWS = new THREE.Vector4(node.boundingBox.min.x, node.boundingBox.min.y, node.boundingBox.min.z, 1);
  117741. //let minVS = minWS.applyMatrix4(this.matrixWorldInverse);
  117742. //let right = node.boundingBox.max.x;
  117743. //let bottom = node.boundingBox.min.y;
  117744. //let top = node.boundingBox.max.y;
  117745. this.updateProjectionMatrix();
  117746. };
  117747. PerspectiveCamera.prototype.zoomTo = function (node, factor) {
  117748. if (!node.geometry && !node.boundingSphere && !node.boundingBox) {
  117749. return;
  117750. }
  117751. if (node.geometry && node.geometry.boundingSphere === null) {
  117752. node.geometry.computeBoundingSphere();
  117753. }
  117754. node.updateMatrixWorld();
  117755. let bs;
  117756. if (node.boundingSphere) {
  117757. bs = node.boundingSphere;
  117758. } else if (node.geometry && node.geometry.boundingSphere) {
  117759. bs = node.geometry.boundingSphere;
  117760. } else {
  117761. bs = node.boundingBox.getBoundingSphere(new Sphere());
  117762. }
  117763. let _factor = factor || 1;
  117764. bs = bs.clone().applyMatrix4(node.matrixWorld);
  117765. let radius = bs.radius;
  117766. let fovr = this.fov * Math.PI / 180;
  117767. if (this.aspect < 1) {
  117768. fovr = fovr * this.aspect;
  117769. }
  117770. let distanceFactor = Math.abs(radius / Math.sin(fovr / 2)) * _factor;
  117771. let offset = this.getWorldDirection(new Vector3()).multiplyScalar(-distanceFactor);
  117772. this.position.copy(bs.center.clone().add(offset));
  117773. };
  117774. Ray.prototype.distanceToPlaneWithNegative = function (plane) {
  117775. let denominator = plane.normal.dot(this.direction);
  117776. if (denominator === 0) {
  117777. // line is coplanar, return origin
  117778. if (plane.distanceToPoint(this.origin) === 0) {
  117779. return 0;
  117780. }
  117781. // Null is preferable to undefined since undefined means.... it is undefined
  117782. return null;
  117783. }
  117784. let t = -(this.origin.dot(plane.normal) + plane.constant) / denominator;
  117785. return t;
  117786. };
  117787. const workerPool = new WorkerPool();
  117788. const version = {
  117789. major: 1,
  117790. minor: 8,
  117791. suffix: '.0'
  117792. };
  117793. let lru = new LRU();
  117794. console.log('Potree ' + version.major + '.' + version.minor + version.suffix);
  117795. let pointBudget = 1 * 1000 * 1000;
  117796. let framenumber = 0;
  117797. let numNodesLoading = 0;
  117798. let maxNodesLoading = 6;//4;
  117799. const debug = {};
  117800. exports.scriptPath = "";
  117801. if (document.currentScript && document.currentScript.src) {
  117802. exports.scriptPath = new URL(document.currentScript.src + '/..').href;
  117803. if (exports.scriptPath.slice(-1) === '/') {
  117804. exports.scriptPath = exports.scriptPath.slice(0, -1);
  117805. }
  117806. } 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)) })){
  117807. 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;
  117808. if (exports.scriptPath.slice(-1) === '/') {
  117809. exports.scriptPath = exports.scriptPath.slice(0, -1);
  117810. }
  117811. }else {
  117812. 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?');
  117813. }
  117814. let resourcePath = exports.scriptPath + '/resources';
  117815. //add:
  117816. async function loadFile(path, params , callback, onError){
  117817. params = params || {};
  117818. let fetchMethod = params.fetchMethod || 'get';
  117819. delete params.fetchMethod;
  117820. if(Potree.fileServer){
  117821. Potree.fileServer[fetchMethod](path, { params }).then(data=>{
  117822. if(data.data)data = data.data;
  117823. if(data.data)data = data.data; //融合页面getdataset需要查找两次data
  117824. callback && callback(data);
  117825. }).catch(onError);
  117826. }else {
  117827. try{
  117828. if(Object.keys(params).length > 0){
  117829. path+='?';
  117830. let index = 0;
  117831. for(let i in params){
  117832. if(index>0) path += '&';
  117833. path+=i; path+='='; path+=params[i];
  117834. index ++;
  117835. }
  117836. }
  117837. let info={};
  117838. if(fetchMethod == 'post')info.method = 'POST';
  117839. let response = await fetch(path, info);
  117840. let text = await response.text();
  117841. var data = params.returnText ? text : JSON.parse(text);
  117842. if(data.data) data = data.data;
  117843. callback && callback(data);
  117844. return data
  117845. }catch(e){
  117846. console.log('loadFile出错', e);
  117847. onError && onError(e);
  117848. }
  117849. }
  117850. //查询: http://192.168.0.26:8080/doc.html#/default/filter-%E6%BC%AB%E6%B8%B8%E7%82%B9/filterUsingGET
  117851. }
  117852. async function loadDatasets(callback,sceneCode,onError){//之后直接把path写进来
  117853. let path;
  117854. sceneCode = sceneCode || Potree.settings.number;
  117855. if(Potree.fileServer){
  117856. path = `/laser/dataset/${sceneCode}/getDataSet`;
  117857. }else {
  117858. //path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/datasets`
  117859. //现在只能加载得了本地的了
  117860. path = `${Potree.settings.urls.prefix}/laser/dataset/${sceneCode}/getDataSet`;
  117861. //path = `${Potree.scriptPath}/data/${sceneCode}/getDataSet.json`
  117862. }
  117863. return loadFile(path, null, callback,onError)
  117864. }
  117865. //目前上传平面图后如果不点击保存按钮,数据还是旧的不生效
  117866. async function loadMapEntity(datasetId, force){
  117867. if(!Potree.settings.floorplanEnable && !force && Potree.fileServer )return /* 等待平面图类型定义好会加载 */
  117868. let loaded = 0;
  117869. let needLoads = datasetId == 'all' ? viewer.scene.pointclouds.map(e=>e.dataset_id) : [datasetId];
  117870. let callback = (dataset_id, floorplanType, data )=>{
  117871. if(!data || data.length == 0)return console.log('平面图没有数据', dataset_id, floorplanType )
  117872. //要防止旧的比新的先获取到导致覆盖新的,因为两种type随时可能切换
  117873. if(floorplanType != Potree.settings.floorplanType[dataset_id]) return //如果请求的floorplanType不是当前最新的floorplanType就返回
  117874. var map = viewer.mapViewer.mapLayer.maps.find(e => e.name == 'floorplan_'+ dataset_id);
  117875. if(map){
  117876. viewer.mapViewer.mapLayer.removeMap(map);
  117877. }
  117878. var mapNew = viewer.mapViewer.mapLayer.addMapEntity(data.data || data, dataset_id);
  117879. if(map){
  117880. mapNew.visibleReasons = map.visibleReasons;
  117881. mapNew.unvisibleReasons = map.unvisibleReasons;
  117882. }
  117883. loaded ++;
  117884. };
  117885. needLoads.forEach(dataset_id=>{
  117886. let floorplanType = Potree.settings.floorplanType[dataset_id], prefix = '';
  117887. if(!Potree.fileServer){
  117888. prefix = Potree.settings.urls.prefix;
  117889. }
  117890. if(!floorplanType)return
  117891. var path;
  117892. /* if(Potree.fileServer){
  117893. path = `/laser/tiledMap/${Potree.settings.number}/tiledMap/${floorplanType}/${dataset_id}`
  117894. }else{
  117895. path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/tiled_maps`
  117896. } */
  117897. path = `${prefix}/laser/tiledMap/${Potree.settings.number}/tiledMap/${floorplanType}/${dataset_id}`;
  117898. Potree.settings.floorplanRequests[dataset_id] = true; //开始加载了
  117899. return loadFile(path, null, callback.bind(this, dataset_id, floorplanType) )
  117900. });
  117901. }
  117902. async function loadPanos(datasetId, callback){
  117903. var path;
  117904. //let query = `?datasetId=${datasetId}` //`?lat=${center.lat}&lon=${center.lon}&radius=200000`
  117905. if(Potree.fileServer){
  117906. path = `/laser/filter/${Potree.settings.number}/query`;
  117907. }else {
  117908. //path = `${Potree.settings.urls.prefix2}/indoor/${Potree.settings.number}/api/images/filter` + query
  117909. //path = `${Potree.scriptPath}/data/${Potree.settings.number}/panos-${datasetId}.json`
  117910. path = `${Potree.settings.urls.prefix}/laser/filter/${Potree.settings.number}/query`;
  117911. }
  117912. return loadFile(path, {datasetId:datasetId}, callback)
  117913. }
  117914. async function loadPanosInfo(callback){
  117915. var path;
  117916. if(Potree.fileServer){
  117917. }else {
  117918. path = `${Potree.scriptPath}/data/panoEdit/vision_edit.txt`;
  117919. }
  117920. return loadFile(path, null, callback)
  117921. }
  117922. async function loadImgVersion( callback){
  117923. var path;
  117924. //let query = `?datasetId=${datasetId}` //`?lat=${center.lat}&lon=${center.lon}&radius=200000`
  117925. /* if(Potree.fileServer){
  117926. path = `/laser/filter/${Potree.settings.number}/query`
  117927. }else{ */
  117928. path = `/laser/init/getSceneNumVersion/${Potree.settings.number}`;
  117929. //api/laser/init
  117930. //}
  117931. return loadFile(path, {fetchMethod:'post'}, callback, callback)
  117932. }
  117933. //site_model
  117934. /* {
  117935. "area": 2503.30551910935,
  117936. "attributes": {},
  117937. "center": [
  117938. 113.59568277455075,
  117939. 22.366566635195288,
  117940. 12.78751625
  117941. ],
  117942. "children": [],
  117943. "geometry_hash": 1891071345,
  117944. "id": 10,
  117945. "name": "港湾一号",
  117946. "parentId": null,
  117947. "polygon": {
  117948. "coordinates": [
  117949. [
  117950. [
  117951. 113.59590810534583,
  117952. 22.36679132753878
  117953. ],
  117954. [
  117955. 113.59590810534583,
  117956. 22.366807172528629
  117957. ],
  117958. [
  117959. 113.59545610274934,
  117960. 22.366807172528629
  117961. ],
  117962. [
  117963. 113.59545610274934,
  117964. 22.36679132753878
  117965. ]
  117966. ]
  117967. ],
  117968. "type": "Polygon"
  117969. },
  117970. "type": "BUILDING",
  117971. "volume": null,
  117972. "z_max": null,
  117973. "z_min": null
  117974. }
  117975. */
  117976. function Log$1(){
  117977. let args = Array.from(arguments);
  117978. let params = args[args.length-1];
  117979. if(params && params.font) {params = params.font, args.pop();}
  117980. else params = {};
  117981. let str = '', color = params.color || '#13f', fontSize = params.fontSize || 12;
  117982. args.forEach((e,i)=>{
  117983. i > 0 && (str += ' , ' );
  117984. /* if(params.toFixed && typeof e == 'number'){
  117985. e = e.toFixed(params.toFixed)
  117986. } */
  117987. if(params.toFixed ){
  117988. e = Potree.math.toPrecision(e, params.toFixed);
  117989. }
  117990. str += e; //object可以JSON.stringify,但不是所有都行
  117991. });
  117992. console.warn(`%c${str}`, `color:${color};font-size:${fontSize}px`);
  117993. }
  117994. function loadPointCloud$1(path, name, sceneCode, timeStamp, callback, onError){
  117995. let loaded = function(e){
  117996. e.pointcloud.name = name;
  117997. e.pointcloud.sceneCode = sceneCode; //对应4dkk的场景码
  117998. callback(e);
  117999. };
  118000. let promise = new Promise( resolve => {
  118001. // load pointcloud
  118002. if (!path){
  118003. // TODO: callback? comment? Hello? Bueller? Anyone?
  118004. } else if (path.indexOf('ept.json') > 0) {
  118005. EptLoader.load(path, function(geometry) {
  118006. if (!geometry) {
  118007. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  118008. }
  118009. else {
  118010. let pointcloud = new ExtendPointCloudOctree(geometry);
  118011. //loaded(pointcloud);
  118012. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  118013. }
  118014. });
  118015. } else if (path.indexOf('cloud.js') > 0) {
  118016. POCLoader.load(path, timeStamp, function (geometry) {
  118017. if (!geometry) {
  118018. //callback({type: 'loading_failed'});
  118019. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  118020. onError && onError();
  118021. } else {
  118022. let pointcloud = new ExtendPointCloudOctree(geometry);
  118023. // loaded(pointcloud);
  118024. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  118025. }
  118026. });
  118027. }/* else if (path.indexOf('metadata.json') > 0) { //部分浏览器(如uc)不支持NodeLoader中的1n的大数据写法
  118028. Potree.OctreeLoader.load(path).then(e => {
  118029. let geometry = e.geometry;
  118030. if(!geometry){
  118031. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  118032. }else{
  118033. let pointcloud = new ExtendPointCloudOctree(geometry);
  118034. let aPosition = pointcloud.getAttribute("position");
  118035. let material = pointcloud.material;
  118036. material.elevationRange = [
  118037. aPosition.range[0][2],
  118038. aPosition.range[1][2],
  118039. ];
  118040. // loaded(pointcloud);
  118041. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  118042. }
  118043. });
  118044. OctreeLoader.load(path, function (geometry) {
  118045. if (!geometry) {
  118046. //callback({type: 'loading_failed'});
  118047. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  118048. } else {
  118049. let pointcloud = new ExtendPointCloudOctree(geometry);
  118050. // loaded(pointcloud);
  118051. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  118052. }
  118053. });
  118054. } */else if (path.indexOf('.vpc') > 0) {
  118055. PointCloudArena4DGeometry.load(path, function (geometry) {
  118056. if (!geometry) {
  118057. //callback({type: 'loading_failed'});
  118058. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  118059. } else {
  118060. let pointcloud = new PointCloudArena4D(geometry);
  118061. // loaded(pointcloud);
  118062. resolve({type: 'pointcloud_loaded', pointcloud: pointcloud});
  118063. }
  118064. });
  118065. } else {
  118066. //callback({'type': 'loading_failed'});
  118067. console.error(new Error(`failed to load point cloud from URL: ${path}`));
  118068. }
  118069. });
  118070. if(callback){
  118071. promise.then(pointcloud => {
  118072. loaded(pointcloud);
  118073. });
  118074. }else {
  118075. return promise;
  118076. }
  118077. };
  118078. // add selectgroup
  118079. (function($){
  118080. $.fn.extend({
  118081. selectgroup: function(args = {}){
  118082. let elGroup = $(this);
  118083. let rootID = elGroup.prop("id");
  118084. let groupID = `${rootID}`;
  118085. let groupTitle = (args.title !== undefined) ? args.title : "";
  118086. let elButtons = [];
  118087. elGroup.find("option").each((index, value) => {
  118088. let buttonID = $(value).prop("id");
  118089. let label = $(value).html();
  118090. let optionValue = $(value).prop("value");
  118091. let elButton = $(`
  118092. <span style="flex-grow: 1; display: inherit">
  118093. <label for="${buttonID}" class="ui-button" style="width: 100%; padding: .4em .1em">${label}</label>
  118094. <input type="radio" name="${groupID}" id="${buttonID}" value="${optionValue}" style="display: none"/>
  118095. </span>
  118096. `);
  118097. let elLabel = elButton.find("label");
  118098. let elInput = elButton.find("input");
  118099. elInput.change( () => {
  118100. elGroup.find("label").removeClass("ui-state-active");
  118101. elGroup.find("label").addClass("ui-state-default");
  118102. if(elInput.is(":checked")){
  118103. elLabel.addClass("ui-state-active");
  118104. }else {
  118105. //elLabel.addClass("ui-state-default");
  118106. }
  118107. });
  118108. elButtons.push(elButton);
  118109. });
  118110. let elFieldset = $(`
  118111. <fieldset style="border: none; margin: 0px; padding: 0px">
  118112. <legend>${groupTitle}</legend>
  118113. <span style="display: flex">
  118114. </span>
  118115. </fieldset>
  118116. `);
  118117. let elButtonContainer = elFieldset.find("span");
  118118. for(let elButton of elButtons){
  118119. elButtonContainer.append(elButton);
  118120. }
  118121. elButtonContainer.find("label").each( (index, value) => {
  118122. $(value).css("margin", "0px");
  118123. $(value).css("border-radius", "0px");
  118124. $(value).css("border", "1px solid black");
  118125. $(value).css("border-left", "none");
  118126. });
  118127. elButtonContainer.find("label:first").each( (index, value) => {
  118128. $(value).css("border-radius", "4px 0px 0px 4px");
  118129. });
  118130. elButtonContainer.find("label:last").each( (index, value) => {
  118131. $(value).css("border-radius", "0px 4px 4px 0px");
  118132. $(value).css("border-left", "none");
  118133. });
  118134. elGroup.empty();
  118135. elGroup.append(elFieldset);
  118136. }
  118137. });
  118138. })(jQuery);
  118139. //在这之后export的内容才赋值到Potree中
  118140. exports.Action = Action;
  118141. exports.Annotation = Annotation;
  118142. exports.Box3Helper = Box3Helper$1;
  118143. exports.BoxVolume = BoxVolume$1;
  118144. exports.CameraAnimation = CameraAnimation$1;
  118145. exports.CameraMode = CameraMode;
  118146. exports.ClassificationScheme = ClassificationScheme;
  118147. exports.ClipMethod = ClipMethod;
  118148. exports.ClipTask = ClipTask;
  118149. exports.ClipVolume = ClipVolume;
  118150. exports.ClippingTool = ClippingTool;
  118151. exports.ElevationGradientRepeat = ElevationGradientRepeat;
  118152. exports.Enum = Enum;
  118153. exports.EnumItem = EnumItem;
  118154. exports.EptBinaryLoader = EptBinaryLoader;
  118155. exports.EptKey = EptKey;
  118156. exports.EptLaszipLoader = EptLaszipLoader;
  118157. exports.EptLazBatcher = EptLazBatcher;
  118158. exports.EptLoader = EptLoader;
  118159. exports.EptZstandardLoader = EptZstandardLoader;
  118160. exports.EventDispatcher = EventDispatcher$1;
  118161. exports.ExtendPointCloudMaterial = ExtendPointCloudMaterial;
  118162. exports.ExtendPointCloudOctree = ExtendPointCloudOctree;
  118163. exports.ExtendScene = ExtendScene;
  118164. exports.EyeDomeLightingMaterial = EyeDomeLightingMaterial;
  118165. exports.Features = Features;
  118166. exports.FirstPersonControls = FirstPersonControls$1;
  118167. exports.GeoPackageLoader = GeoPackageLoader;
  118168. exports.Geopackage = Geopackage$1;
  118169. exports.Gradients = Gradients;
  118170. exports.HierarchicalSlider = HierarchicalSlider;
  118171. exports.Images360 = Images360;
  118172. exports.KeyCodes = KeyCodes;
  118173. exports.LRU = LRU;
  118174. exports.LRUItem = LRUItem;
  118175. exports.LengthUnits = LengthUnits;
  118176. exports.LineDraw = LineDraw;
  118177. exports.Log = Log$1;
  118178. exports.MOUSE = MOUSE$1;
  118179. exports.MapViewer = MapViewer;
  118180. exports.Measure = Measure$1;
  118181. exports.MeasuringTool = MeasuringTool;
  118182. exports.MeshDraw = MeshDraw;
  118183. exports.Message = Message;
  118184. exports.NodeLoader = NodeLoader;
  118185. exports.NormalizationEDLMaterial = NormalizationEDLMaterial;
  118186. exports.NormalizationMaterial = NormalizationMaterial;
  118187. exports.OctreeLoader = OctreeLoader;
  118188. exports.OrbitControls = OrbitControls$1;
  118189. exports.OrientedImage = OrientedImage;
  118190. exports.OrientedImageLoader = OrientedImageLoader;
  118191. exports.OrientedImages = OrientedImages;
  118192. exports.POCLoader = POCLoader;
  118193. exports.PointAttribute = PointAttribute;
  118194. exports.PointAttributeTypes = PointAttributeTypes;
  118195. exports.PointAttributes = PointAttributes;
  118196. exports.PointCloudEptGeometry = PointCloudEptGeometry;
  118197. exports.PointCloudEptGeometryNode = PointCloudEptGeometryNode;
  118198. exports.PointCloudOctreeGeometry = PointCloudOctreeGeometry;
  118199. exports.PointCloudOctreeGeometryNode = PointCloudOctreeGeometryNode;
  118200. exports.PointCloudSM = PointCloudSM;
  118201. exports.PointCloudTree = PointCloudTree;
  118202. exports.PointCloudTreeNode = PointCloudTreeNode;
  118203. exports.PointShape = PointShape$1;
  118204. exports.PointSizeType = PointSizeType;
  118205. exports.Points = Points$1;
  118206. exports.PolygonClipVolume = PolygonClipVolume;
  118207. exports.Profile = Profile;
  118208. exports.ProfileData = ProfileData;
  118209. exports.ProfileRequest = ProfileRequest;
  118210. exports.ProfileTool = ProfileTool;
  118211. exports.Renderer = Renderer;
  118212. exports.ScreenBoxSelectTool = ScreenBoxSelectTool;
  118213. exports.ShapefileLoader = ShapefileLoader;
  118214. exports.SphereVolume = SphereVolume$2;
  118215. exports.SpotLightHelper = SpotLightHelper$1;
  118216. exports.TextSprite = TextSprite$2;
  118217. exports.TransformationTool = TransformationTool;
  118218. exports.TreeType = TreeType;
  118219. exports.Utils = Utils;
  118220. exports.Version = Version;
  118221. exports.Viewer = Viewer;
  118222. exports.Volume = Volume$1;
  118223. exports.VolumeTool = VolumeTool;
  118224. exports.WorkerPool = WorkerPool;
  118225. exports.XHRFactory = XHRFactory;
  118226. exports.config = config$1;
  118227. exports.debug = debug;
  118228. exports.framenumber = framenumber;
  118229. exports.loadDatasets = loadDatasets;
  118230. exports.loadFile = loadFile;
  118231. exports.loadImgVersion = loadImgVersion;
  118232. exports.loadMapEntity = loadMapEntity;
  118233. exports.loadPanos = loadPanos;
  118234. exports.loadPanosInfo = loadPanosInfo;
  118235. exports.loadPointCloud = loadPointCloud$1;
  118236. exports.loadProject = loadProject;
  118237. exports.lru = lru;
  118238. exports.maxNodesLoading = maxNodesLoading;
  118239. exports.mergeEditStart = mergeEditStart;
  118240. exports.numNodesLoading = numNodesLoading;
  118241. exports.panoEditStart = panoEditStart;
  118242. exports.pointBudget = pointBudget;
  118243. exports.resourcePath = resourcePath;
  118244. exports.saveProject = saveProject;
  118245. exports.settings = settings;
  118246. exports.start = start;
  118247. exports.version = version;
  118248. exports.workerPool = workerPool;
  118249. Object.defineProperty(exports, '__esModule', { value: true });
  118250. })));
  118251. //# sourceMappingURL=potree.js.map