three.core.js 743 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989369903699136992369933699436995369963699736998369993700037001370023700337004370053700637007370083700937010370113701237013370143701537016370173701837019370203702137022370233702437025370263702737028370293703037031370323703337034370353703637037370383703937040370413704237043370443704537046370473704837049370503705137052370533705437055370563705737058370593706037061370623706337064370653706637067370683706937070370713707237073370743707537076370773707837079370803708137082370833708437085370863708737088370893709037091370923709337094370953709637097370983709937100371013710237103371043710537106371073710837109371103711137112371133711437115371163711737118371193712037121371223712337124371253712637127371283712937130371313713237133371343713537136371373713837139371403714137142371433714437145371463714737148371493715037151371523715337154371553715637157371583715937160371613716237163371643716537166371673716837169371703717137172371733717437175371763717737178371793718037181371823718337184371853718637187371883718937190371913719237193371943719537196371973719837199372003720137202372033720437205372063720737208372093721037211372123721337214372153721637217372183721937220372213722237223372243722537226372273722837229372303723137232372333723437235372363723737238372393724037241372423724337244372453724637247372483724937250372513725237253372543725537256372573725837259372603726137262372633726437265372663726737268372693727037271372723727337274372753727637277372783727937280372813728237283372843728537286372873728837289372903729137292372933729437295372963729737298372993730037301373023730337304373053730637307373083730937310373113731237313373143731537316373173731837319373203732137322373233732437325373263732737328373293733037331373323733337334373353733637337373383733937340373413734237343373443734537346373473734837349373503735137352373533735437355373563735737358373593736037361373623736337364373653736637367373683736937370373713737237373373743737537376373773737837379373803738137382373833738437385373863738737388373893739037391373923739337394373953739637397373983739937400374013740237403374043740537406374073740837409374103741137412374133741437415374163741737418374193742037421
  1. /**
  2. * @license
  3. * Copyright 2010-2025 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. const REVISION = '173dev';
  7. const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
  8. const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
  9. const CullFaceNone = 0;
  10. const CullFaceBack = 1;
  11. const CullFaceFront = 2;
  12. const CullFaceFrontBack = 3;
  13. const BasicShadowMap = 0;
  14. const PCFShadowMap = 1;
  15. const PCFSoftShadowMap = 2;
  16. const VSMShadowMap = 3;
  17. const FrontSide = 0;
  18. const BackSide = 1;
  19. const DoubleSide = 2;
  20. const NoBlending = 0;
  21. const NormalBlending = 1;
  22. const AdditiveBlending = 2;
  23. const SubtractiveBlending = 3;
  24. const MultiplyBlending = 4;
  25. const CustomBlending = 5;
  26. const AddEquation = 100;
  27. const SubtractEquation = 101;
  28. const ReverseSubtractEquation = 102;
  29. const MinEquation = 103;
  30. const MaxEquation = 104;
  31. const ZeroFactor = 200;
  32. const OneFactor = 201;
  33. const SrcColorFactor = 202;
  34. const OneMinusSrcColorFactor = 203;
  35. const SrcAlphaFactor = 204;
  36. const OneMinusSrcAlphaFactor = 205;
  37. const DstAlphaFactor = 206;
  38. const OneMinusDstAlphaFactor = 207;
  39. const DstColorFactor = 208;
  40. const OneMinusDstColorFactor = 209;
  41. const SrcAlphaSaturateFactor = 210;
  42. const ConstantColorFactor = 211;
  43. const OneMinusConstantColorFactor = 212;
  44. const ConstantAlphaFactor = 213;
  45. const OneMinusConstantAlphaFactor = 214;
  46. const NeverDepth = 0;
  47. const AlwaysDepth = 1;
  48. const LessDepth = 2;
  49. const LessEqualDepth = 3;
  50. const EqualDepth = 4;
  51. const GreaterEqualDepth = 5;
  52. const GreaterDepth = 6;
  53. const NotEqualDepth = 7;
  54. const MultiplyOperation = 0;
  55. const MixOperation = 1;
  56. const AddOperation = 2;
  57. const NoToneMapping = 0;
  58. const LinearToneMapping = 1;
  59. const ReinhardToneMapping = 2;
  60. const CineonToneMapping = 3;
  61. const ACESFilmicToneMapping = 4;
  62. const CustomToneMapping = 5;
  63. const AgXToneMapping = 6;
  64. const NeutralToneMapping = 7;
  65. const AttachedBindMode = 'attached';
  66. const DetachedBindMode = 'detached';
  67. const UVMapping = 300;
  68. const CubeReflectionMapping = 301;
  69. const CubeRefractionMapping = 302;
  70. const EquirectangularReflectionMapping = 303;
  71. const EquirectangularRefractionMapping = 304;
  72. const CubeUVReflectionMapping = 306;
  73. const RepeatWrapping = 1000;
  74. const ClampToEdgeWrapping = 1001;
  75. const MirroredRepeatWrapping = 1002;
  76. const NearestFilter = 1003;
  77. const NearestMipmapNearestFilter = 1004;
  78. const NearestMipMapNearestFilter = 1004;
  79. const NearestMipmapLinearFilter = 1005;
  80. const NearestMipMapLinearFilter = 1005;
  81. const LinearFilter = 1006;
  82. const LinearMipmapNearestFilter = 1007;
  83. const LinearMipMapNearestFilter = 1007;
  84. const LinearMipmapLinearFilter = 1008;
  85. const LinearMipMapLinearFilter = 1008;
  86. const UnsignedByteType = 1009;
  87. const ByteType = 1010;
  88. const ShortType = 1011;
  89. const UnsignedShortType = 1012;
  90. const IntType = 1013;
  91. const UnsignedIntType = 1014;
  92. const FloatType = 1015;
  93. const HalfFloatType = 1016;
  94. const UnsignedShort4444Type = 1017;
  95. const UnsignedShort5551Type = 1018;
  96. const UnsignedInt248Type = 1020;
  97. const UnsignedInt5999Type = 35902;
  98. const AlphaFormat = 1021;
  99. const RGBFormat = 1022;
  100. const RGBAFormat = 1023;
  101. const LuminanceFormat = 1024;
  102. const LuminanceAlphaFormat = 1025;
  103. const DepthFormat = 1026;
  104. const DepthStencilFormat = 1027;
  105. const RedFormat = 1028;
  106. const RedIntegerFormat = 1029;
  107. const RGFormat = 1030;
  108. const RGIntegerFormat = 1031;
  109. const RGBIntegerFormat = 1032;
  110. const RGBAIntegerFormat = 1033;
  111. const RGB_S3TC_DXT1_Format = 33776;
  112. const RGBA_S3TC_DXT1_Format = 33777;
  113. const RGBA_S3TC_DXT3_Format = 33778;
  114. const RGBA_S3TC_DXT5_Format = 33779;
  115. const RGB_PVRTC_4BPPV1_Format = 35840;
  116. const RGB_PVRTC_2BPPV1_Format = 35841;
  117. const RGBA_PVRTC_4BPPV1_Format = 35842;
  118. const RGBA_PVRTC_2BPPV1_Format = 35843;
  119. const RGB_ETC1_Format = 36196;
  120. const RGB_ETC2_Format = 37492;
  121. const RGBA_ETC2_EAC_Format = 37496;
  122. const RGBA_ASTC_4x4_Format = 37808;
  123. const RGBA_ASTC_5x4_Format = 37809;
  124. const RGBA_ASTC_5x5_Format = 37810;
  125. const RGBA_ASTC_6x5_Format = 37811;
  126. const RGBA_ASTC_6x6_Format = 37812;
  127. const RGBA_ASTC_8x5_Format = 37813;
  128. const RGBA_ASTC_8x6_Format = 37814;
  129. const RGBA_ASTC_8x8_Format = 37815;
  130. const RGBA_ASTC_10x5_Format = 37816;
  131. const RGBA_ASTC_10x6_Format = 37817;
  132. const RGBA_ASTC_10x8_Format = 37818;
  133. const RGBA_ASTC_10x10_Format = 37819;
  134. const RGBA_ASTC_12x10_Format = 37820;
  135. const RGBA_ASTC_12x12_Format = 37821;
  136. const RGBA_BPTC_Format = 36492;
  137. const RGB_BPTC_SIGNED_Format = 36494;
  138. const RGB_BPTC_UNSIGNED_Format = 36495;
  139. const RED_RGTC1_Format = 36283;
  140. const SIGNED_RED_RGTC1_Format = 36284;
  141. const RED_GREEN_RGTC2_Format = 36285;
  142. const SIGNED_RED_GREEN_RGTC2_Format = 36286;
  143. const LoopOnce = 2200;
  144. const LoopRepeat = 2201;
  145. const LoopPingPong = 2202;
  146. const InterpolateDiscrete = 2300;
  147. const InterpolateLinear = 2301;
  148. const InterpolateSmooth = 2302;
  149. const ZeroCurvatureEnding = 2400;
  150. const ZeroSlopeEnding = 2401;
  151. const WrapAroundEnding = 2402;
  152. const NormalAnimationBlendMode = 2500;
  153. const AdditiveAnimationBlendMode = 2501;
  154. const TrianglesDrawMode = 0;
  155. const TriangleStripDrawMode = 1;
  156. const TriangleFanDrawMode = 2;
  157. const BasicDepthPacking = 3200;
  158. const RGBADepthPacking = 3201;
  159. const RGBDepthPacking = 3202;
  160. const RGDepthPacking = 3203;
  161. const TangentSpaceNormalMap = 0;
  162. const ObjectSpaceNormalMap = 1;
  163. // Color space string identifiers, matching CSS Color Module Level 4 and WebGPU names where available.
  164. const NoColorSpace = '';
  165. const SRGBColorSpace = 'srgb';
  166. const LinearSRGBColorSpace = 'srgb-linear';
  167. const LinearTransfer = 'linear';
  168. const SRGBTransfer = 'srgb';
  169. const ZeroStencilOp = 0;
  170. const KeepStencilOp = 7680;
  171. const ReplaceStencilOp = 7681;
  172. const IncrementStencilOp = 7682;
  173. const DecrementStencilOp = 7683;
  174. const IncrementWrapStencilOp = 34055;
  175. const DecrementWrapStencilOp = 34056;
  176. const InvertStencilOp = 5386;
  177. const NeverStencilFunc = 512;
  178. const LessStencilFunc = 513;
  179. const EqualStencilFunc = 514;
  180. const LessEqualStencilFunc = 515;
  181. const GreaterStencilFunc = 516;
  182. const NotEqualStencilFunc = 517;
  183. const GreaterEqualStencilFunc = 518;
  184. const AlwaysStencilFunc = 519;
  185. const NeverCompare = 512;
  186. const LessCompare = 513;
  187. const EqualCompare = 514;
  188. const LessEqualCompare = 515;
  189. const GreaterCompare = 516;
  190. const NotEqualCompare = 517;
  191. const GreaterEqualCompare = 518;
  192. const AlwaysCompare = 519;
  193. const StaticDrawUsage = 35044;
  194. const DynamicDrawUsage = 35048;
  195. const StreamDrawUsage = 35040;
  196. const StaticReadUsage = 35045;
  197. const DynamicReadUsage = 35049;
  198. const StreamReadUsage = 35041;
  199. const StaticCopyUsage = 35046;
  200. const DynamicCopyUsage = 35050;
  201. const StreamCopyUsage = 35042;
  202. const GLSL1 = '100';
  203. const GLSL3 = '300 es';
  204. const WebGLCoordinateSystem = 2000;
  205. const WebGPUCoordinateSystem = 2001;
  206. const TimestampQuery = {
  207. COMPUTE: 'compute',
  208. RENDER: 'render'
  209. };
  210. /**
  211. * https://github.com/mrdoob/eventdispatcher.js/
  212. */
  213. class EventDispatcher {
  214. addEventListener( type, listener ) {
  215. if ( this._listeners === undefined ) this._listeners = {};
  216. const listeners = this._listeners;
  217. if ( listeners[ type ] === undefined ) {
  218. listeners[ type ] = [];
  219. }
  220. if ( listeners[ type ].indexOf( listener ) === -1 ) {
  221. listeners[ type ].push( listener );
  222. }
  223. }
  224. hasEventListener( type, listener ) {
  225. const listeners = this._listeners;
  226. if ( listeners === undefined ) return false;
  227. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== -1;
  228. }
  229. removeEventListener( type, listener ) {
  230. const listeners = this._listeners;
  231. if ( listeners === undefined ) return;
  232. const listenerArray = listeners[ type ];
  233. if ( listenerArray !== undefined ) {
  234. const index = listenerArray.indexOf( listener );
  235. if ( index !== -1 ) {
  236. listenerArray.splice( index, 1 );
  237. }
  238. }
  239. }
  240. dispatchEvent( event ) {
  241. const listeners = this._listeners;
  242. if ( listeners === undefined ) return;
  243. const listenerArray = listeners[ event.type ];
  244. if ( listenerArray !== undefined ) {
  245. event.target = this;
  246. // Make a copy, in case listeners are removed while iterating.
  247. const array = listenerArray.slice( 0 );
  248. for ( let i = 0, l = array.length; i < l; i ++ ) {
  249. array[ i ].call( this, event );
  250. }
  251. event.target = null;
  252. }
  253. }
  254. }
  255. const _lut = [ '00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '0a', '0b', '0c', '0d', '0e', '0f', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '1a', '1b', '1c', '1d', '1e', '1f', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '2a', '2b', '2c', '2d', '2e', '2f', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '3a', '3b', '3c', '3d', '3e', '3f', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '4a', '4b', '4c', '4d', '4e', '4f', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '5a', '5b', '5c', '5d', '5e', '5f', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e', '7f', '80', '81', '82', '83', '84', '85', '86', '87', '88', '89', '8a', '8b', '8c', '8d', '8e', '8f', '90', '91', '92', '93', '94', '95', '96', '97', '98', '99', '9a', '9b', '9c', '9d', '9e', '9f', 'a0', 'a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9', 'aa', 'ab', 'ac', 'ad', 'ae', 'af', 'b0', 'b1', 'b2', 'b3', 'b4', 'b5', 'b6', 'b7', 'b8', 'b9', 'ba', 'bb', 'bc', 'bd', 'be', 'bf', 'c0', 'c1', 'c2', 'c3', 'c4', 'c5', 'c6', 'c7', 'c8', 'c9', 'ca', 'cb', 'cc', 'cd', 'ce', 'cf', 'd0', 'd1', 'd2', 'd3', 'd4', 'd5', 'd6', 'd7', 'd8', 'd9', 'da', 'db', 'dc', 'dd', 'de', 'df', 'e0', 'e1', 'e2', 'e3', 'e4', 'e5', 'e6', 'e7', 'e8', 'e9', 'ea', 'eb', 'ec', 'ed', 'ee', 'ef', 'f0', 'f1', 'f2', 'f3', 'f4', 'f5', 'f6', 'f7', 'f8', 'f9', 'fa', 'fb', 'fc', 'fd', 'fe', 'ff' ];
  256. let _seed = 1234567;
  257. const DEG2RAD = Math.PI / 180;
  258. const RAD2DEG = 180 / Math.PI;
  259. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  260. function generateUUID() {
  261. const d0 = Math.random() * 0xffffffff | 0;
  262. const d1 = Math.random() * 0xffffffff | 0;
  263. const d2 = Math.random() * 0xffffffff | 0;
  264. const d3 = Math.random() * 0xffffffff | 0;
  265. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  266. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  267. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  268. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  269. // .toLowerCase() here flattens concatenated strings to save heap memory space.
  270. return uuid.toLowerCase();
  271. }
  272. function clamp( value, min, max ) {
  273. return Math.max( min, Math.min( max, value ) );
  274. }
  275. // compute euclidean modulo of m % n
  276. // https://en.wikipedia.org/wiki/Modulo_operation
  277. function euclideanModulo( n, m ) {
  278. return ( ( n % m ) + m ) % m;
  279. }
  280. // Linear mapping from range <a1, a2> to range <b1, b2>
  281. function mapLinear( x, a1, a2, b1, b2 ) {
  282. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  283. }
  284. // https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/
  285. function inverseLerp( x, y, value ) {
  286. if ( x !== y ) {
  287. return ( value - x ) / ( y - x );
  288. } else {
  289. return 0;
  290. }
  291. }
  292. // https://en.wikipedia.org/wiki/Linear_interpolation
  293. function lerp( x, y, t ) {
  294. return ( 1 - t ) * x + t * y;
  295. }
  296. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  297. function damp( x, y, lambda, dt ) {
  298. return lerp( x, y, 1 - Math.exp( - lambda * dt ) );
  299. }
  300. // https://www.desmos.com/calculator/vcsjnyz7x4
  301. function pingpong( x, length = 1 ) {
  302. return length - Math.abs( euclideanModulo( x, length * 2 ) - length );
  303. }
  304. // http://en.wikipedia.org/wiki/Smoothstep
  305. function smoothstep( x, min, max ) {
  306. if ( x <= min ) return 0;
  307. if ( x >= max ) return 1;
  308. x = ( x - min ) / ( max - min );
  309. return x * x * ( 3 - 2 * x );
  310. }
  311. function smootherstep( x, min, max ) {
  312. if ( x <= min ) return 0;
  313. if ( x >= max ) return 1;
  314. x = ( x - min ) / ( max - min );
  315. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  316. }
  317. // Random integer from <low, high> interval
  318. function randInt( low, high ) {
  319. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  320. }
  321. // Random float from <low, high> interval
  322. function randFloat( low, high ) {
  323. return low + Math.random() * ( high - low );
  324. }
  325. // Random float from <-range/2, range/2> interval
  326. function randFloatSpread( range ) {
  327. return range * ( 0.5 - Math.random() );
  328. }
  329. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  330. function seededRandom( s ) {
  331. if ( s !== undefined ) _seed = s;
  332. // Mulberry32 generator
  333. let t = _seed += 0x6D2B79F5;
  334. t = Math.imul( t ^ t >>> 15, t | 1 );
  335. t ^= t + Math.imul( t ^ t >>> 7, t | 61 );
  336. return ( ( t ^ t >>> 14 ) >>> 0 ) / 4294967296;
  337. }
  338. function degToRad( degrees ) {
  339. return degrees * DEG2RAD;
  340. }
  341. function radToDeg( radians ) {
  342. return radians * RAD2DEG;
  343. }
  344. function isPowerOfTwo( value ) {
  345. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  346. }
  347. function ceilPowerOfTwo( value ) {
  348. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  349. }
  350. function floorPowerOfTwo( value ) {
  351. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  352. }
  353. function setQuaternionFromProperEuler( q, a, b, c, order ) {
  354. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  355. // rotations are applied to the axes in the order specified by 'order'
  356. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  357. // angles are in radians
  358. const cos = Math.cos;
  359. const sin = Math.sin;
  360. const c2 = cos( b / 2 );
  361. const s2 = sin( b / 2 );
  362. const c13 = cos( ( a + c ) / 2 );
  363. const s13 = sin( ( a + c ) / 2 );
  364. const c1_3 = cos( ( a - c ) / 2 );
  365. const s1_3 = sin( ( a - c ) / 2 );
  366. const c3_1 = cos( ( c - a ) / 2 );
  367. const s3_1 = sin( ( c - a ) / 2 );
  368. switch ( order ) {
  369. case 'XYX':
  370. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  371. break;
  372. case 'YZY':
  373. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  374. break;
  375. case 'ZXZ':
  376. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  377. break;
  378. case 'XZX':
  379. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  380. break;
  381. case 'YXY':
  382. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  383. break;
  384. case 'ZYZ':
  385. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  386. break;
  387. default:
  388. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  389. }
  390. }
  391. function denormalize( value, array ) {
  392. switch ( array.constructor ) {
  393. case Float32Array:
  394. return value;
  395. case Uint32Array:
  396. return value / 4294967295.0;
  397. case Uint16Array:
  398. return value / 65535.0;
  399. case Uint8Array:
  400. return value / 255.0;
  401. case Int32Array:
  402. return Math.max( value / 2147483647.0, -1 );
  403. case Int16Array:
  404. return Math.max( value / 32767.0, -1 );
  405. case Int8Array:
  406. return Math.max( value / 127.0, -1 );
  407. default:
  408. throw new Error( 'Invalid component type.' );
  409. }
  410. }
  411. function normalize( value, array ) {
  412. switch ( array.constructor ) {
  413. case Float32Array:
  414. return value;
  415. case Uint32Array:
  416. return Math.round( value * 4294967295.0 );
  417. case Uint16Array:
  418. return Math.round( value * 65535.0 );
  419. case Uint8Array:
  420. return Math.round( value * 255.0 );
  421. case Int32Array:
  422. return Math.round( value * 2147483647.0 );
  423. case Int16Array:
  424. return Math.round( value * 32767.0 );
  425. case Int8Array:
  426. return Math.round( value * 127.0 );
  427. default:
  428. throw new Error( 'Invalid component type.' );
  429. }
  430. }
  431. const MathUtils = {
  432. DEG2RAD: DEG2RAD,
  433. RAD2DEG: RAD2DEG,
  434. generateUUID: generateUUID,
  435. clamp: clamp,
  436. euclideanModulo: euclideanModulo,
  437. mapLinear: mapLinear,
  438. inverseLerp: inverseLerp,
  439. lerp: lerp,
  440. damp: damp,
  441. pingpong: pingpong,
  442. smoothstep: smoothstep,
  443. smootherstep: smootherstep,
  444. randInt: randInt,
  445. randFloat: randFloat,
  446. randFloatSpread: randFloatSpread,
  447. seededRandom: seededRandom,
  448. degToRad: degToRad,
  449. radToDeg: radToDeg,
  450. isPowerOfTwo: isPowerOfTwo,
  451. ceilPowerOfTwo: ceilPowerOfTwo,
  452. floorPowerOfTwo: floorPowerOfTwo,
  453. setQuaternionFromProperEuler: setQuaternionFromProperEuler,
  454. normalize: normalize,
  455. denormalize: denormalize
  456. };
  457. class Vector2 {
  458. constructor( x = 0, y = 0 ) {
  459. Vector2.prototype.isVector2 = true;
  460. this.x = x;
  461. this.y = y;
  462. }
  463. get width() {
  464. return this.x;
  465. }
  466. set width( value ) {
  467. this.x = value;
  468. }
  469. get height() {
  470. return this.y;
  471. }
  472. set height( value ) {
  473. this.y = value;
  474. }
  475. set( x, y ) {
  476. this.x = x;
  477. this.y = y;
  478. return this;
  479. }
  480. setScalar( scalar ) {
  481. this.x = scalar;
  482. this.y = scalar;
  483. return this;
  484. }
  485. setX( x ) {
  486. this.x = x;
  487. return this;
  488. }
  489. setY( y ) {
  490. this.y = y;
  491. return this;
  492. }
  493. setComponent( index, value ) {
  494. switch ( index ) {
  495. case 0: this.x = value; break;
  496. case 1: this.y = value; break;
  497. default: throw new Error( 'index is out of range: ' + index );
  498. }
  499. return this;
  500. }
  501. getComponent( index ) {
  502. switch ( index ) {
  503. case 0: return this.x;
  504. case 1: return this.y;
  505. default: throw new Error( 'index is out of range: ' + index );
  506. }
  507. }
  508. clone() {
  509. return new this.constructor( this.x, this.y );
  510. }
  511. copy( v ) {
  512. this.x = v.x;
  513. this.y = v.y;
  514. return this;
  515. }
  516. add( v ) {
  517. this.x += v.x;
  518. this.y += v.y;
  519. return this;
  520. }
  521. addScalar( s ) {
  522. this.x += s;
  523. this.y += s;
  524. return this;
  525. }
  526. addVectors( a, b ) {
  527. this.x = a.x + b.x;
  528. this.y = a.y + b.y;
  529. return this;
  530. }
  531. addScaledVector( v, s ) {
  532. this.x += v.x * s;
  533. this.y += v.y * s;
  534. return this;
  535. }
  536. sub( v ) {
  537. this.x -= v.x;
  538. this.y -= v.y;
  539. return this;
  540. }
  541. subScalar( s ) {
  542. this.x -= s;
  543. this.y -= s;
  544. return this;
  545. }
  546. subVectors( a, b ) {
  547. this.x = a.x - b.x;
  548. this.y = a.y - b.y;
  549. return this;
  550. }
  551. multiply( v ) {
  552. this.x *= v.x;
  553. this.y *= v.y;
  554. return this;
  555. }
  556. multiplyScalar( scalar ) {
  557. this.x *= scalar;
  558. this.y *= scalar;
  559. return this;
  560. }
  561. divide( v ) {
  562. this.x /= v.x;
  563. this.y /= v.y;
  564. return this;
  565. }
  566. divideScalar( scalar ) {
  567. return this.multiplyScalar( 1 / scalar );
  568. }
  569. applyMatrix3( m ) {
  570. const x = this.x, y = this.y;
  571. const e = m.elements;
  572. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  573. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  574. return this;
  575. }
  576. min( v ) {
  577. this.x = Math.min( this.x, v.x );
  578. this.y = Math.min( this.y, v.y );
  579. return this;
  580. }
  581. max( v ) {
  582. this.x = Math.max( this.x, v.x );
  583. this.y = Math.max( this.y, v.y );
  584. return this;
  585. }
  586. clamp( min, max ) {
  587. // assumes min < max, componentwise
  588. this.x = clamp( this.x, min.x, max.x );
  589. this.y = clamp( this.y, min.y, max.y );
  590. return this;
  591. }
  592. clampScalar( minVal, maxVal ) {
  593. this.x = clamp( this.x, minVal, maxVal );
  594. this.y = clamp( this.y, minVal, maxVal );
  595. return this;
  596. }
  597. clampLength( min, max ) {
  598. const length = this.length();
  599. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  600. }
  601. floor() {
  602. this.x = Math.floor( this.x );
  603. this.y = Math.floor( this.y );
  604. return this;
  605. }
  606. ceil() {
  607. this.x = Math.ceil( this.x );
  608. this.y = Math.ceil( this.y );
  609. return this;
  610. }
  611. round() {
  612. this.x = Math.round( this.x );
  613. this.y = Math.round( this.y );
  614. return this;
  615. }
  616. roundToZero() {
  617. this.x = Math.trunc( this.x );
  618. this.y = Math.trunc( this.y );
  619. return this;
  620. }
  621. negate() {
  622. this.x = - this.x;
  623. this.y = - this.y;
  624. return this;
  625. }
  626. dot( v ) {
  627. return this.x * v.x + this.y * v.y;
  628. }
  629. cross( v ) {
  630. return this.x * v.y - this.y * v.x;
  631. }
  632. lengthSq() {
  633. return this.x * this.x + this.y * this.y;
  634. }
  635. length() {
  636. return Math.sqrt( this.x * this.x + this.y * this.y );
  637. }
  638. manhattanLength() {
  639. return Math.abs( this.x ) + Math.abs( this.y );
  640. }
  641. normalize() {
  642. return this.divideScalar( this.length() || 1 );
  643. }
  644. angle() {
  645. // computes the angle in radians with respect to the positive x-axis
  646. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  647. return angle;
  648. }
  649. angleTo( v ) {
  650. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  651. if ( denominator === 0 ) return Math.PI / 2;
  652. const theta = this.dot( v ) / denominator;
  653. // clamp, to handle numerical problems
  654. return Math.acos( clamp( theta, -1, 1 ) );
  655. }
  656. distanceTo( v ) {
  657. return Math.sqrt( this.distanceToSquared( v ) );
  658. }
  659. distanceToSquared( v ) {
  660. const dx = this.x - v.x, dy = this.y - v.y;
  661. return dx * dx + dy * dy;
  662. }
  663. manhattanDistanceTo( v ) {
  664. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  665. }
  666. setLength( length ) {
  667. return this.normalize().multiplyScalar( length );
  668. }
  669. lerp( v, alpha ) {
  670. this.x += ( v.x - this.x ) * alpha;
  671. this.y += ( v.y - this.y ) * alpha;
  672. return this;
  673. }
  674. lerpVectors( v1, v2, alpha ) {
  675. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  676. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  677. return this;
  678. }
  679. equals( v ) {
  680. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  681. }
  682. fromArray( array, offset = 0 ) {
  683. this.x = array[ offset ];
  684. this.y = array[ offset + 1 ];
  685. return this;
  686. }
  687. toArray( array = [], offset = 0 ) {
  688. array[ offset ] = this.x;
  689. array[ offset + 1 ] = this.y;
  690. return array;
  691. }
  692. fromBufferAttribute( attribute, index ) {
  693. this.x = attribute.getX( index );
  694. this.y = attribute.getY( index );
  695. return this;
  696. }
  697. rotateAround( center, angle ) {
  698. const c = Math.cos( angle ), s = Math.sin( angle );
  699. const x = this.x - center.x;
  700. const y = this.y - center.y;
  701. this.x = x * c - y * s + center.x;
  702. this.y = x * s + y * c + center.y;
  703. return this;
  704. }
  705. random() {
  706. this.x = Math.random();
  707. this.y = Math.random();
  708. return this;
  709. }
  710. *[ Symbol.iterator ]() {
  711. yield this.x;
  712. yield this.y;
  713. }
  714. }
  715. class Matrix3 {
  716. constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  717. Matrix3.prototype.isMatrix3 = true;
  718. this.elements = [
  719. 1, 0, 0,
  720. 0, 1, 0,
  721. 0, 0, 1
  722. ];
  723. if ( n11 !== undefined ) {
  724. this.set( n11, n12, n13, n21, n22, n23, n31, n32, n33 );
  725. }
  726. }
  727. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  728. const te = this.elements;
  729. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  730. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  731. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  732. return this;
  733. }
  734. identity() {
  735. this.set(
  736. 1, 0, 0,
  737. 0, 1, 0,
  738. 0, 0, 1
  739. );
  740. return this;
  741. }
  742. copy( m ) {
  743. const te = this.elements;
  744. const me = m.elements;
  745. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  746. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  747. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  748. return this;
  749. }
  750. extractBasis( xAxis, yAxis, zAxis ) {
  751. xAxis.setFromMatrix3Column( this, 0 );
  752. yAxis.setFromMatrix3Column( this, 1 );
  753. zAxis.setFromMatrix3Column( this, 2 );
  754. return this;
  755. }
  756. setFromMatrix4( m ) {
  757. const me = m.elements;
  758. this.set(
  759. me[ 0 ], me[ 4 ], me[ 8 ],
  760. me[ 1 ], me[ 5 ], me[ 9 ],
  761. me[ 2 ], me[ 6 ], me[ 10 ]
  762. );
  763. return this;
  764. }
  765. multiply( m ) {
  766. return this.multiplyMatrices( this, m );
  767. }
  768. premultiply( m ) {
  769. return this.multiplyMatrices( m, this );
  770. }
  771. multiplyMatrices( a, b ) {
  772. const ae = a.elements;
  773. const be = b.elements;
  774. const te = this.elements;
  775. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  776. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  777. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  778. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  779. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  780. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  781. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  782. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  783. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  784. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  785. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  786. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  787. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  788. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  789. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  790. return this;
  791. }
  792. multiplyScalar( s ) {
  793. const te = this.elements;
  794. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  795. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  796. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  797. return this;
  798. }
  799. determinant() {
  800. const te = this.elements;
  801. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  802. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  803. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  804. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  805. }
  806. invert() {
  807. const te = this.elements,
  808. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  809. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  810. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  811. t11 = n33 * n22 - n32 * n23,
  812. t12 = n32 * n13 - n33 * n12,
  813. t13 = n23 * n12 - n22 * n13,
  814. det = n11 * t11 + n21 * t12 + n31 * t13;
  815. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  816. const detInv = 1 / det;
  817. te[ 0 ] = t11 * detInv;
  818. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  819. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  820. te[ 3 ] = t12 * detInv;
  821. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  822. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  823. te[ 6 ] = t13 * detInv;
  824. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  825. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  826. return this;
  827. }
  828. transpose() {
  829. let tmp;
  830. const m = this.elements;
  831. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  832. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  833. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  834. return this;
  835. }
  836. getNormalMatrix( matrix4 ) {
  837. return this.setFromMatrix4( matrix4 ).invert().transpose();
  838. }
  839. transposeIntoArray( r ) {
  840. const m = this.elements;
  841. r[ 0 ] = m[ 0 ];
  842. r[ 1 ] = m[ 3 ];
  843. r[ 2 ] = m[ 6 ];
  844. r[ 3 ] = m[ 1 ];
  845. r[ 4 ] = m[ 4 ];
  846. r[ 5 ] = m[ 7 ];
  847. r[ 6 ] = m[ 2 ];
  848. r[ 7 ] = m[ 5 ];
  849. r[ 8 ] = m[ 8 ];
  850. return this;
  851. }
  852. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  853. const c = Math.cos( rotation );
  854. const s = Math.sin( rotation );
  855. this.set(
  856. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  857. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  858. 0, 0, 1
  859. );
  860. return this;
  861. }
  862. //
  863. scale( sx, sy ) {
  864. this.premultiply( _m3.makeScale( sx, sy ) );
  865. return this;
  866. }
  867. rotate( theta ) {
  868. this.premultiply( _m3.makeRotation( - theta ) );
  869. return this;
  870. }
  871. translate( tx, ty ) {
  872. this.premultiply( _m3.makeTranslation( tx, ty ) );
  873. return this;
  874. }
  875. // for 2D Transforms
  876. makeTranslation( x, y ) {
  877. if ( x.isVector2 ) {
  878. this.set(
  879. 1, 0, x.x,
  880. 0, 1, x.y,
  881. 0, 0, 1
  882. );
  883. } else {
  884. this.set(
  885. 1, 0, x,
  886. 0, 1, y,
  887. 0, 0, 1
  888. );
  889. }
  890. return this;
  891. }
  892. makeRotation( theta ) {
  893. // counterclockwise
  894. const c = Math.cos( theta );
  895. const s = Math.sin( theta );
  896. this.set(
  897. c, - s, 0,
  898. s, c, 0,
  899. 0, 0, 1
  900. );
  901. return this;
  902. }
  903. makeScale( x, y ) {
  904. this.set(
  905. x, 0, 0,
  906. 0, y, 0,
  907. 0, 0, 1
  908. );
  909. return this;
  910. }
  911. //
  912. equals( matrix ) {
  913. const te = this.elements;
  914. const me = matrix.elements;
  915. for ( let i = 0; i < 9; i ++ ) {
  916. if ( te[ i ] !== me[ i ] ) return false;
  917. }
  918. return true;
  919. }
  920. fromArray( array, offset = 0 ) {
  921. for ( let i = 0; i < 9; i ++ ) {
  922. this.elements[ i ] = array[ i + offset ];
  923. }
  924. return this;
  925. }
  926. toArray( array = [], offset = 0 ) {
  927. const te = this.elements;
  928. array[ offset ] = te[ 0 ];
  929. array[ offset + 1 ] = te[ 1 ];
  930. array[ offset + 2 ] = te[ 2 ];
  931. array[ offset + 3 ] = te[ 3 ];
  932. array[ offset + 4 ] = te[ 4 ];
  933. array[ offset + 5 ] = te[ 5 ];
  934. array[ offset + 6 ] = te[ 6 ];
  935. array[ offset + 7 ] = te[ 7 ];
  936. array[ offset + 8 ] = te[ 8 ];
  937. return array;
  938. }
  939. clone() {
  940. return new this.constructor().fromArray( this.elements );
  941. }
  942. }
  943. const _m3 = /*@__PURE__*/ new Matrix3();
  944. function arrayNeedsUint32( array ) {
  945. // assumes larger values usually on last
  946. for ( let i = array.length - 1; i >= 0; -- i ) {
  947. if ( array[ i ] >= 65535 ) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565
  948. }
  949. return false;
  950. }
  951. const TYPED_ARRAYS = {
  952. Int8Array: Int8Array,
  953. Uint8Array: Uint8Array,
  954. Uint8ClampedArray: Uint8ClampedArray,
  955. Int16Array: Int16Array,
  956. Uint16Array: Uint16Array,
  957. Int32Array: Int32Array,
  958. Uint32Array: Uint32Array,
  959. Float32Array: Float32Array,
  960. Float64Array: Float64Array
  961. };
  962. function getTypedArray( type, buffer ) {
  963. return new TYPED_ARRAYS[ type ]( buffer );
  964. }
  965. function createElementNS( name ) {
  966. return document.createElementNS( 'http://www.w3.org/1999/xhtml', name );
  967. }
  968. function createCanvasElement() {
  969. const canvas = createElementNS( 'canvas' );
  970. canvas.style.display = 'block';
  971. return canvas;
  972. }
  973. const _cache = {};
  974. function warnOnce( message ) {
  975. if ( message in _cache ) return;
  976. _cache[ message ] = true;
  977. console.warn( message );
  978. }
  979. function probeAsync( gl, sync, interval ) {
  980. return new Promise( function ( resolve, reject ) {
  981. function probe() {
  982. switch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) {
  983. case gl.WAIT_FAILED:
  984. reject();
  985. break;
  986. case gl.TIMEOUT_EXPIRED:
  987. setTimeout( probe, interval );
  988. break;
  989. default:
  990. resolve();
  991. }
  992. }
  993. setTimeout( probe, interval );
  994. } );
  995. }
  996. function toNormalizedProjectionMatrix( projectionMatrix ) {
  997. const m = projectionMatrix.elements;
  998. // Convert [-1, 1] to [0, 1] projection matrix
  999. m[ 2 ] = 0.5 * m[ 2 ] + 0.5 * m[ 3 ];
  1000. m[ 6 ] = 0.5 * m[ 6 ] + 0.5 * m[ 7 ];
  1001. m[ 10 ] = 0.5 * m[ 10 ] + 0.5 * m[ 11 ];
  1002. m[ 14 ] = 0.5 * m[ 14 ] + 0.5 * m[ 15 ];
  1003. }
  1004. function toReversedProjectionMatrix( projectionMatrix ) {
  1005. const m = projectionMatrix.elements;
  1006. const isPerspectiveMatrix = m[ 11 ] === -1;
  1007. // Reverse [0, 1] projection matrix
  1008. if ( isPerspectiveMatrix ) {
  1009. m[ 10 ] = - m[ 10 ] - 1;
  1010. m[ 14 ] = - m[ 14 ];
  1011. } else {
  1012. m[ 10 ] = - m[ 10 ];
  1013. m[ 14 ] = - m[ 14 ] + 1;
  1014. }
  1015. }
  1016. const LINEAR_REC709_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  1017. 0.4123908, 0.3575843, 0.1804808,
  1018. 0.2126390, 0.7151687, 0.0721923,
  1019. 0.0193308, 0.1191948, 0.9505322
  1020. );
  1021. const XYZ_TO_LINEAR_REC709 = /*@__PURE__*/ new Matrix3().set(
  1022. 3.2409699, -1.5373832, -0.4986108,
  1023. -0.9692436, 1.8759675, 0.0415551,
  1024. 0.0556301, -0.203977, 1.0569715
  1025. );
  1026. function createColorManagement() {
  1027. const ColorManagement = {
  1028. enabled: true,
  1029. workingColorSpace: LinearSRGBColorSpace,
  1030. /**
  1031. * Implementations of supported color spaces.
  1032. *
  1033. * Required:
  1034. * - primaries: chromaticity coordinates [ rx ry gx gy bx by ]
  1035. * - whitePoint: reference white [ x y ]
  1036. * - transfer: transfer function (pre-defined)
  1037. * - toXYZ: Matrix3 RGB to XYZ transform
  1038. * - fromXYZ: Matrix3 XYZ to RGB transform
  1039. * - luminanceCoefficients: RGB luminance coefficients
  1040. *
  1041. * Optional:
  1042. * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
  1043. * - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
  1044. *
  1045. * Reference:
  1046. * - https://www.russellcottrell.com/photo/matrixCalculator.htm
  1047. */
  1048. spaces: {},
  1049. convert: function ( color, sourceColorSpace, targetColorSpace ) {
  1050. if ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) {
  1051. return color;
  1052. }
  1053. if ( this.spaces[ sourceColorSpace ].transfer === SRGBTransfer ) {
  1054. color.r = SRGBToLinear( color.r );
  1055. color.g = SRGBToLinear( color.g );
  1056. color.b = SRGBToLinear( color.b );
  1057. }
  1058. if ( this.spaces[ sourceColorSpace ].primaries !== this.spaces[ targetColorSpace ].primaries ) {
  1059. color.applyMatrix3( this.spaces[ sourceColorSpace ].toXYZ );
  1060. color.applyMatrix3( this.spaces[ targetColorSpace ].fromXYZ );
  1061. }
  1062. if ( this.spaces[ targetColorSpace ].transfer === SRGBTransfer ) {
  1063. color.r = LinearToSRGB( color.r );
  1064. color.g = LinearToSRGB( color.g );
  1065. color.b = LinearToSRGB( color.b );
  1066. }
  1067. return color;
  1068. },
  1069. fromWorkingColorSpace: function ( color, targetColorSpace ) {
  1070. return this.convert( color, this.workingColorSpace, targetColorSpace );
  1071. },
  1072. toWorkingColorSpace: function ( color, sourceColorSpace ) {
  1073. return this.convert( color, sourceColorSpace, this.workingColorSpace );
  1074. },
  1075. getPrimaries: function ( colorSpace ) {
  1076. return this.spaces[ colorSpace ].primaries;
  1077. },
  1078. getTransfer: function ( colorSpace ) {
  1079. if ( colorSpace === NoColorSpace ) return LinearTransfer;
  1080. return this.spaces[ colorSpace ].transfer;
  1081. },
  1082. getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) {
  1083. return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients );
  1084. },
  1085. define: function ( colorSpaces ) {
  1086. Object.assign( this.spaces, colorSpaces );
  1087. },
  1088. // Internal APIs
  1089. _getMatrix: function ( targetMatrix, sourceColorSpace, targetColorSpace ) {
  1090. return targetMatrix
  1091. .copy( this.spaces[ sourceColorSpace ].toXYZ )
  1092. .multiply( this.spaces[ targetColorSpace ].fromXYZ );
  1093. },
  1094. _getDrawingBufferColorSpace: function ( colorSpace ) {
  1095. return this.spaces[ colorSpace ].outputColorSpaceConfig.drawingBufferColorSpace;
  1096. },
  1097. _getUnpackColorSpace: function ( colorSpace = this.workingColorSpace ) {
  1098. return this.spaces[ colorSpace ].workingColorSpaceConfig.unpackColorSpace;
  1099. }
  1100. };
  1101. /******************************************************************************
  1102. * sRGB definitions
  1103. */
  1104. const REC709_PRIMARIES = [ 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 ];
  1105. const REC709_LUMINANCE_COEFFICIENTS = [ 0.2126, 0.7152, 0.0722 ];
  1106. const D65 = [ 0.3127, 0.3290 ];
  1107. ColorManagement.define( {
  1108. [ LinearSRGBColorSpace ]: {
  1109. primaries: REC709_PRIMARIES,
  1110. whitePoint: D65,
  1111. transfer: LinearTransfer,
  1112. toXYZ: LINEAR_REC709_TO_XYZ,
  1113. fromXYZ: XYZ_TO_LINEAR_REC709,
  1114. luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
  1115. workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace },
  1116. outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
  1117. },
  1118. [ SRGBColorSpace ]: {
  1119. primaries: REC709_PRIMARIES,
  1120. whitePoint: D65,
  1121. transfer: SRGBTransfer,
  1122. toXYZ: LINEAR_REC709_TO_XYZ,
  1123. fromXYZ: XYZ_TO_LINEAR_REC709,
  1124. luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
  1125. outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
  1126. },
  1127. } );
  1128. return ColorManagement;
  1129. }
  1130. const ColorManagement = /*@__PURE__*/ createColorManagement();
  1131. function SRGBToLinear( c ) {
  1132. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  1133. }
  1134. function LinearToSRGB( c ) {
  1135. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  1136. }
  1137. let _canvas;
  1138. class ImageUtils {
  1139. static getDataURL( image ) {
  1140. if ( /^data:/i.test( image.src ) ) {
  1141. return image.src;
  1142. }
  1143. if ( typeof HTMLCanvasElement === 'undefined' ) {
  1144. return image.src;
  1145. }
  1146. let canvas;
  1147. if ( image instanceof HTMLCanvasElement ) {
  1148. canvas = image;
  1149. } else {
  1150. if ( _canvas === undefined ) _canvas = createElementNS( 'canvas' );
  1151. _canvas.width = image.width;
  1152. _canvas.height = image.height;
  1153. const context = _canvas.getContext( '2d' );
  1154. if ( image instanceof ImageData ) {
  1155. context.putImageData( image, 0, 0 );
  1156. } else {
  1157. context.drawImage( image, 0, 0, image.width, image.height );
  1158. }
  1159. canvas = _canvas;
  1160. }
  1161. return canvas.toDataURL( 'image/png' );
  1162. }
  1163. static sRGBToLinear( image ) {
  1164. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1165. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1166. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1167. const canvas = createElementNS( 'canvas' );
  1168. canvas.width = image.width;
  1169. canvas.height = image.height;
  1170. const context = canvas.getContext( '2d' );
  1171. context.drawImage( image, 0, 0, image.width, image.height );
  1172. const imageData = context.getImageData( 0, 0, image.width, image.height );
  1173. const data = imageData.data;
  1174. for ( let i = 0; i < data.length; i ++ ) {
  1175. data[ i ] = SRGBToLinear( data[ i ] / 255 ) * 255;
  1176. }
  1177. context.putImageData( imageData, 0, 0 );
  1178. return canvas;
  1179. } else if ( image.data ) {
  1180. const data = image.data.slice( 0 );
  1181. for ( let i = 0; i < data.length; i ++ ) {
  1182. if ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) {
  1183. data[ i ] = Math.floor( SRGBToLinear( data[ i ] / 255 ) * 255 );
  1184. } else {
  1185. // assuming float
  1186. data[ i ] = SRGBToLinear( data[ i ] );
  1187. }
  1188. }
  1189. return {
  1190. data: data,
  1191. width: image.width,
  1192. height: image.height
  1193. };
  1194. } else {
  1195. console.warn( 'THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.' );
  1196. return image;
  1197. }
  1198. }
  1199. }
  1200. let _sourceId = 0;
  1201. class Source {
  1202. constructor( data = null ) {
  1203. this.isSource = true;
  1204. Object.defineProperty( this, 'id', { value: _sourceId ++ } );
  1205. this.uuid = generateUUID();
  1206. this.data = data;
  1207. this.dataReady = true;
  1208. this.version = 0;
  1209. }
  1210. set needsUpdate( value ) {
  1211. if ( value === true ) this.version ++;
  1212. }
  1213. toJSON( meta ) {
  1214. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1215. if ( ! isRootObject && meta.images[ this.uuid ] !== undefined ) {
  1216. return meta.images[ this.uuid ];
  1217. }
  1218. const output = {
  1219. uuid: this.uuid,
  1220. url: ''
  1221. };
  1222. const data = this.data;
  1223. if ( data !== null ) {
  1224. let url;
  1225. if ( Array.isArray( data ) ) {
  1226. // cube texture
  1227. url = [];
  1228. for ( let i = 0, l = data.length; i < l; i ++ ) {
  1229. if ( data[ i ].isDataTexture ) {
  1230. url.push( serializeImage( data[ i ].image ) );
  1231. } else {
  1232. url.push( serializeImage( data[ i ] ) );
  1233. }
  1234. }
  1235. } else {
  1236. // texture
  1237. url = serializeImage( data );
  1238. }
  1239. output.url = url;
  1240. }
  1241. if ( ! isRootObject ) {
  1242. meta.images[ this.uuid ] = output;
  1243. }
  1244. return output;
  1245. }
  1246. }
  1247. function serializeImage( image ) {
  1248. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1249. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1250. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1251. // default images
  1252. return ImageUtils.getDataURL( image );
  1253. } else {
  1254. if ( image.data ) {
  1255. // images of DataTexture
  1256. return {
  1257. data: Array.from( image.data ),
  1258. width: image.width,
  1259. height: image.height,
  1260. type: image.data.constructor.name
  1261. };
  1262. } else {
  1263. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1264. return {};
  1265. }
  1266. }
  1267. }
  1268. let _textureId = 0;
  1269. class Texture extends EventDispatcher {
  1270. constructor( image = Texture.DEFAULT_IMAGE, mapping = Texture.DEFAULT_MAPPING, wrapS = ClampToEdgeWrapping, wrapT = ClampToEdgeWrapping, magFilter = LinearFilter, minFilter = LinearMipmapLinearFilter, format = RGBAFormat, type = UnsignedByteType, anisotropy = Texture.DEFAULT_ANISOTROPY, colorSpace = NoColorSpace ) {
  1271. super();
  1272. this.isTexture = true;
  1273. Object.defineProperty( this, 'id', { value: _textureId ++ } );
  1274. this.uuid = generateUUID();
  1275. this.name = '';
  1276. this.source = new Source( image );
  1277. this.mipmaps = [];
  1278. this.mapping = mapping;
  1279. this.channel = 0;
  1280. this.wrapS = wrapS;
  1281. this.wrapT = wrapT;
  1282. this.magFilter = magFilter;
  1283. this.minFilter = minFilter;
  1284. this.anisotropy = anisotropy;
  1285. this.format = format;
  1286. this.internalFormat = null;
  1287. this.type = type;
  1288. this.offset = new Vector2( 0, 0 );
  1289. this.repeat = new Vector2( 1, 1 );
  1290. this.center = new Vector2( 0, 0 );
  1291. this.rotation = 0;
  1292. this.matrixAutoUpdate = true;
  1293. this.matrix = new Matrix3();
  1294. this.generateMipmaps = true;
  1295. this.premultiplyAlpha = false;
  1296. this.flipY = true;
  1297. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1298. this.colorSpace = colorSpace;
  1299. this.userData = {};
  1300. this.version = 0;
  1301. this.onUpdate = null;
  1302. this.renderTarget = null; // assign texture to a render target
  1303. this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
  1304. this.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)
  1305. }
  1306. get image() {
  1307. return this.source.data;
  1308. }
  1309. set image( value = null ) {
  1310. this.source.data = value;
  1311. }
  1312. updateMatrix() {
  1313. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1314. }
  1315. clone() {
  1316. return new this.constructor().copy( this );
  1317. }
  1318. copy( source ) {
  1319. this.name = source.name;
  1320. this.source = source.source;
  1321. this.mipmaps = source.mipmaps.slice( 0 );
  1322. this.mapping = source.mapping;
  1323. this.channel = source.channel;
  1324. this.wrapS = source.wrapS;
  1325. this.wrapT = source.wrapT;
  1326. this.magFilter = source.magFilter;
  1327. this.minFilter = source.minFilter;
  1328. this.anisotropy = source.anisotropy;
  1329. this.format = source.format;
  1330. this.internalFormat = source.internalFormat;
  1331. this.type = source.type;
  1332. this.offset.copy( source.offset );
  1333. this.repeat.copy( source.repeat );
  1334. this.center.copy( source.center );
  1335. this.rotation = source.rotation;
  1336. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1337. this.matrix.copy( source.matrix );
  1338. this.generateMipmaps = source.generateMipmaps;
  1339. this.premultiplyAlpha = source.premultiplyAlpha;
  1340. this.flipY = source.flipY;
  1341. this.unpackAlignment = source.unpackAlignment;
  1342. this.colorSpace = source.colorSpace;
  1343. this.renderTarget = source.renderTarget;
  1344. this.isRenderTargetTexture = source.isRenderTargetTexture;
  1345. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  1346. this.needsUpdate = true;
  1347. return this;
  1348. }
  1349. toJSON( meta ) {
  1350. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1351. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1352. return meta.textures[ this.uuid ];
  1353. }
  1354. const output = {
  1355. metadata: {
  1356. version: 4.6,
  1357. type: 'Texture',
  1358. generator: 'Texture.toJSON'
  1359. },
  1360. uuid: this.uuid,
  1361. name: this.name,
  1362. image: this.source.toJSON( meta ).uuid,
  1363. mapping: this.mapping,
  1364. channel: this.channel,
  1365. repeat: [ this.repeat.x, this.repeat.y ],
  1366. offset: [ this.offset.x, this.offset.y ],
  1367. center: [ this.center.x, this.center.y ],
  1368. rotation: this.rotation,
  1369. wrap: [ this.wrapS, this.wrapT ],
  1370. format: this.format,
  1371. internalFormat: this.internalFormat,
  1372. type: this.type,
  1373. colorSpace: this.colorSpace,
  1374. minFilter: this.minFilter,
  1375. magFilter: this.magFilter,
  1376. anisotropy: this.anisotropy,
  1377. flipY: this.flipY,
  1378. generateMipmaps: this.generateMipmaps,
  1379. premultiplyAlpha: this.premultiplyAlpha,
  1380. unpackAlignment: this.unpackAlignment
  1381. };
  1382. if ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData;
  1383. if ( ! isRootObject ) {
  1384. meta.textures[ this.uuid ] = output;
  1385. }
  1386. return output;
  1387. }
  1388. dispose() {
  1389. this.dispatchEvent( { type: 'dispose' } );
  1390. }
  1391. transformUv( uv ) {
  1392. if ( this.mapping !== UVMapping ) return uv;
  1393. uv.applyMatrix3( this.matrix );
  1394. if ( uv.x < 0 || uv.x > 1 ) {
  1395. switch ( this.wrapS ) {
  1396. case RepeatWrapping:
  1397. uv.x = uv.x - Math.floor( uv.x );
  1398. break;
  1399. case ClampToEdgeWrapping:
  1400. uv.x = uv.x < 0 ? 0 : 1;
  1401. break;
  1402. case MirroredRepeatWrapping:
  1403. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1404. uv.x = Math.ceil( uv.x ) - uv.x;
  1405. } else {
  1406. uv.x = uv.x - Math.floor( uv.x );
  1407. }
  1408. break;
  1409. }
  1410. }
  1411. if ( uv.y < 0 || uv.y > 1 ) {
  1412. switch ( this.wrapT ) {
  1413. case RepeatWrapping:
  1414. uv.y = uv.y - Math.floor( uv.y );
  1415. break;
  1416. case ClampToEdgeWrapping:
  1417. uv.y = uv.y < 0 ? 0 : 1;
  1418. break;
  1419. case MirroredRepeatWrapping:
  1420. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1421. uv.y = Math.ceil( uv.y ) - uv.y;
  1422. } else {
  1423. uv.y = uv.y - Math.floor( uv.y );
  1424. }
  1425. break;
  1426. }
  1427. }
  1428. if ( this.flipY ) {
  1429. uv.y = 1 - uv.y;
  1430. }
  1431. return uv;
  1432. }
  1433. set needsUpdate( value ) {
  1434. if ( value === true ) {
  1435. this.version ++;
  1436. this.source.needsUpdate = true;
  1437. }
  1438. }
  1439. set needsPMREMUpdate( value ) {
  1440. if ( value === true ) {
  1441. this.pmremVersion ++;
  1442. }
  1443. }
  1444. }
  1445. Texture.DEFAULT_IMAGE = null;
  1446. Texture.DEFAULT_MAPPING = UVMapping;
  1447. Texture.DEFAULT_ANISOTROPY = 1;
  1448. class Vector4 {
  1449. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1450. Vector4.prototype.isVector4 = true;
  1451. this.x = x;
  1452. this.y = y;
  1453. this.z = z;
  1454. this.w = w;
  1455. }
  1456. get width() {
  1457. return this.z;
  1458. }
  1459. set width( value ) {
  1460. this.z = value;
  1461. }
  1462. get height() {
  1463. return this.w;
  1464. }
  1465. set height( value ) {
  1466. this.w = value;
  1467. }
  1468. set( x, y, z, w ) {
  1469. this.x = x;
  1470. this.y = y;
  1471. this.z = z;
  1472. this.w = w;
  1473. return this;
  1474. }
  1475. setScalar( scalar ) {
  1476. this.x = scalar;
  1477. this.y = scalar;
  1478. this.z = scalar;
  1479. this.w = scalar;
  1480. return this;
  1481. }
  1482. setX( x ) {
  1483. this.x = x;
  1484. return this;
  1485. }
  1486. setY( y ) {
  1487. this.y = y;
  1488. return this;
  1489. }
  1490. setZ( z ) {
  1491. this.z = z;
  1492. return this;
  1493. }
  1494. setW( w ) {
  1495. this.w = w;
  1496. return this;
  1497. }
  1498. setComponent( index, value ) {
  1499. switch ( index ) {
  1500. case 0: this.x = value; break;
  1501. case 1: this.y = value; break;
  1502. case 2: this.z = value; break;
  1503. case 3: this.w = value; break;
  1504. default: throw new Error( 'index is out of range: ' + index );
  1505. }
  1506. return this;
  1507. }
  1508. getComponent( index ) {
  1509. switch ( index ) {
  1510. case 0: return this.x;
  1511. case 1: return this.y;
  1512. case 2: return this.z;
  1513. case 3: return this.w;
  1514. default: throw new Error( 'index is out of range: ' + index );
  1515. }
  1516. }
  1517. clone() {
  1518. return new this.constructor( this.x, this.y, this.z, this.w );
  1519. }
  1520. copy( v ) {
  1521. this.x = v.x;
  1522. this.y = v.y;
  1523. this.z = v.z;
  1524. this.w = ( v.w !== undefined ) ? v.w : 1;
  1525. return this;
  1526. }
  1527. add( v ) {
  1528. this.x += v.x;
  1529. this.y += v.y;
  1530. this.z += v.z;
  1531. this.w += v.w;
  1532. return this;
  1533. }
  1534. addScalar( s ) {
  1535. this.x += s;
  1536. this.y += s;
  1537. this.z += s;
  1538. this.w += s;
  1539. return this;
  1540. }
  1541. addVectors( a, b ) {
  1542. this.x = a.x + b.x;
  1543. this.y = a.y + b.y;
  1544. this.z = a.z + b.z;
  1545. this.w = a.w + b.w;
  1546. return this;
  1547. }
  1548. addScaledVector( v, s ) {
  1549. this.x += v.x * s;
  1550. this.y += v.y * s;
  1551. this.z += v.z * s;
  1552. this.w += v.w * s;
  1553. return this;
  1554. }
  1555. sub( v ) {
  1556. this.x -= v.x;
  1557. this.y -= v.y;
  1558. this.z -= v.z;
  1559. this.w -= v.w;
  1560. return this;
  1561. }
  1562. subScalar( s ) {
  1563. this.x -= s;
  1564. this.y -= s;
  1565. this.z -= s;
  1566. this.w -= s;
  1567. return this;
  1568. }
  1569. subVectors( a, b ) {
  1570. this.x = a.x - b.x;
  1571. this.y = a.y - b.y;
  1572. this.z = a.z - b.z;
  1573. this.w = a.w - b.w;
  1574. return this;
  1575. }
  1576. multiply( v ) {
  1577. this.x *= v.x;
  1578. this.y *= v.y;
  1579. this.z *= v.z;
  1580. this.w *= v.w;
  1581. return this;
  1582. }
  1583. multiplyScalar( scalar ) {
  1584. this.x *= scalar;
  1585. this.y *= scalar;
  1586. this.z *= scalar;
  1587. this.w *= scalar;
  1588. return this;
  1589. }
  1590. applyMatrix4( m ) {
  1591. const x = this.x, y = this.y, z = this.z, w = this.w;
  1592. const e = m.elements;
  1593. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1594. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1595. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1596. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1597. return this;
  1598. }
  1599. divide( v ) {
  1600. this.x /= v.x;
  1601. this.y /= v.y;
  1602. this.z /= v.z;
  1603. this.w /= v.w;
  1604. return this;
  1605. }
  1606. divideScalar( scalar ) {
  1607. return this.multiplyScalar( 1 / scalar );
  1608. }
  1609. setAxisAngleFromQuaternion( q ) {
  1610. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1611. // q is assumed to be normalized
  1612. this.w = 2 * Math.acos( q.w );
  1613. const s = Math.sqrt( 1 - q.w * q.w );
  1614. if ( s < 0.0001 ) {
  1615. this.x = 1;
  1616. this.y = 0;
  1617. this.z = 0;
  1618. } else {
  1619. this.x = q.x / s;
  1620. this.y = q.y / s;
  1621. this.z = q.z / s;
  1622. }
  1623. return this;
  1624. }
  1625. setAxisAngleFromRotationMatrix( m ) {
  1626. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1627. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1628. let angle, x, y, z; // variables for result
  1629. const epsilon = 0.01, // margin to allow for rounding errors
  1630. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1631. te = m.elements,
  1632. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1633. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1634. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1635. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1636. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1637. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1638. // singularity found
  1639. // first check for identity matrix which must have +1 for all terms
  1640. // in leading diagonal and zero in other terms
  1641. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1642. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1643. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1644. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1645. // this singularity is identity matrix so angle = 0
  1646. this.set( 1, 0, 0, 0 );
  1647. return this; // zero angle, arbitrary axis
  1648. }
  1649. // otherwise this singularity is angle = 180
  1650. angle = Math.PI;
  1651. const xx = ( m11 + 1 ) / 2;
  1652. const yy = ( m22 + 1 ) / 2;
  1653. const zz = ( m33 + 1 ) / 2;
  1654. const xy = ( m12 + m21 ) / 4;
  1655. const xz = ( m13 + m31 ) / 4;
  1656. const yz = ( m23 + m32 ) / 4;
  1657. if ( ( xx > yy ) && ( xx > zz ) ) {
  1658. // m11 is the largest diagonal term
  1659. if ( xx < epsilon ) {
  1660. x = 0;
  1661. y = 0.707106781;
  1662. z = 0.707106781;
  1663. } else {
  1664. x = Math.sqrt( xx );
  1665. y = xy / x;
  1666. z = xz / x;
  1667. }
  1668. } else if ( yy > zz ) {
  1669. // m22 is the largest diagonal term
  1670. if ( yy < epsilon ) {
  1671. x = 0.707106781;
  1672. y = 0;
  1673. z = 0.707106781;
  1674. } else {
  1675. y = Math.sqrt( yy );
  1676. x = xy / y;
  1677. z = yz / y;
  1678. }
  1679. } else {
  1680. // m33 is the largest diagonal term so base result on this
  1681. if ( zz < epsilon ) {
  1682. x = 0.707106781;
  1683. y = 0.707106781;
  1684. z = 0;
  1685. } else {
  1686. z = Math.sqrt( zz );
  1687. x = xz / z;
  1688. y = yz / z;
  1689. }
  1690. }
  1691. this.set( x, y, z, angle );
  1692. return this; // return 180 deg rotation
  1693. }
  1694. // as we have reached here there are no singularities so we can handle normally
  1695. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1696. ( m13 - m31 ) * ( m13 - m31 ) +
  1697. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1698. if ( Math.abs( s ) < 0.001 ) s = 1;
  1699. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1700. // caught by singularity test above, but I've left it in just in case
  1701. this.x = ( m32 - m23 ) / s;
  1702. this.y = ( m13 - m31 ) / s;
  1703. this.z = ( m21 - m12 ) / s;
  1704. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1705. return this;
  1706. }
  1707. setFromMatrixPosition( m ) {
  1708. const e = m.elements;
  1709. this.x = e[ 12 ];
  1710. this.y = e[ 13 ];
  1711. this.z = e[ 14 ];
  1712. this.w = e[ 15 ];
  1713. return this;
  1714. }
  1715. min( v ) {
  1716. this.x = Math.min( this.x, v.x );
  1717. this.y = Math.min( this.y, v.y );
  1718. this.z = Math.min( this.z, v.z );
  1719. this.w = Math.min( this.w, v.w );
  1720. return this;
  1721. }
  1722. max( v ) {
  1723. this.x = Math.max( this.x, v.x );
  1724. this.y = Math.max( this.y, v.y );
  1725. this.z = Math.max( this.z, v.z );
  1726. this.w = Math.max( this.w, v.w );
  1727. return this;
  1728. }
  1729. clamp( min, max ) {
  1730. // assumes min < max, componentwise
  1731. this.x = clamp( this.x, min.x, max.x );
  1732. this.y = clamp( this.y, min.y, max.y );
  1733. this.z = clamp( this.z, min.z, max.z );
  1734. this.w = clamp( this.w, min.w, max.w );
  1735. return this;
  1736. }
  1737. clampScalar( minVal, maxVal ) {
  1738. this.x = clamp( this.x, minVal, maxVal );
  1739. this.y = clamp( this.y, minVal, maxVal );
  1740. this.z = clamp( this.z, minVal, maxVal );
  1741. this.w = clamp( this.w, minVal, maxVal );
  1742. return this;
  1743. }
  1744. clampLength( min, max ) {
  1745. const length = this.length();
  1746. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  1747. }
  1748. floor() {
  1749. this.x = Math.floor( this.x );
  1750. this.y = Math.floor( this.y );
  1751. this.z = Math.floor( this.z );
  1752. this.w = Math.floor( this.w );
  1753. return this;
  1754. }
  1755. ceil() {
  1756. this.x = Math.ceil( this.x );
  1757. this.y = Math.ceil( this.y );
  1758. this.z = Math.ceil( this.z );
  1759. this.w = Math.ceil( this.w );
  1760. return this;
  1761. }
  1762. round() {
  1763. this.x = Math.round( this.x );
  1764. this.y = Math.round( this.y );
  1765. this.z = Math.round( this.z );
  1766. this.w = Math.round( this.w );
  1767. return this;
  1768. }
  1769. roundToZero() {
  1770. this.x = Math.trunc( this.x );
  1771. this.y = Math.trunc( this.y );
  1772. this.z = Math.trunc( this.z );
  1773. this.w = Math.trunc( this.w );
  1774. return this;
  1775. }
  1776. negate() {
  1777. this.x = - this.x;
  1778. this.y = - this.y;
  1779. this.z = - this.z;
  1780. this.w = - this.w;
  1781. return this;
  1782. }
  1783. dot( v ) {
  1784. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1785. }
  1786. lengthSq() {
  1787. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1788. }
  1789. length() {
  1790. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1791. }
  1792. manhattanLength() {
  1793. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1794. }
  1795. normalize() {
  1796. return this.divideScalar( this.length() || 1 );
  1797. }
  1798. setLength( length ) {
  1799. return this.normalize().multiplyScalar( length );
  1800. }
  1801. lerp( v, alpha ) {
  1802. this.x += ( v.x - this.x ) * alpha;
  1803. this.y += ( v.y - this.y ) * alpha;
  1804. this.z += ( v.z - this.z ) * alpha;
  1805. this.w += ( v.w - this.w ) * alpha;
  1806. return this;
  1807. }
  1808. lerpVectors( v1, v2, alpha ) {
  1809. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1810. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1811. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1812. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1813. return this;
  1814. }
  1815. equals( v ) {
  1816. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1817. }
  1818. fromArray( array, offset = 0 ) {
  1819. this.x = array[ offset ];
  1820. this.y = array[ offset + 1 ];
  1821. this.z = array[ offset + 2 ];
  1822. this.w = array[ offset + 3 ];
  1823. return this;
  1824. }
  1825. toArray( array = [], offset = 0 ) {
  1826. array[ offset ] = this.x;
  1827. array[ offset + 1 ] = this.y;
  1828. array[ offset + 2 ] = this.z;
  1829. array[ offset + 3 ] = this.w;
  1830. return array;
  1831. }
  1832. fromBufferAttribute( attribute, index ) {
  1833. this.x = attribute.getX( index );
  1834. this.y = attribute.getY( index );
  1835. this.z = attribute.getZ( index );
  1836. this.w = attribute.getW( index );
  1837. return this;
  1838. }
  1839. random() {
  1840. this.x = Math.random();
  1841. this.y = Math.random();
  1842. this.z = Math.random();
  1843. this.w = Math.random();
  1844. return this;
  1845. }
  1846. *[ Symbol.iterator ]() {
  1847. yield this.x;
  1848. yield this.y;
  1849. yield this.z;
  1850. yield this.w;
  1851. }
  1852. }
  1853. /*
  1854. In options, we can specify:
  1855. * Texture parameters for an auto-generated target texture
  1856. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1857. */
  1858. class RenderTarget extends EventDispatcher {
  1859. constructor( width = 1, height = 1, options = {} ) {
  1860. super();
  1861. this.isRenderTarget = true;
  1862. this.width = width;
  1863. this.height = height;
  1864. this.depth = 1;
  1865. this.scissor = new Vector4( 0, 0, width, height );
  1866. this.scissorTest = false;
  1867. this.viewport = new Vector4( 0, 0, width, height );
  1868. const image = { width: width, height: height, depth: 1 };
  1869. options = Object.assign( {
  1870. generateMipmaps: false,
  1871. internalFormat: null,
  1872. minFilter: LinearFilter,
  1873. depthBuffer: true,
  1874. stencilBuffer: false,
  1875. resolveDepthBuffer: true,
  1876. resolveStencilBuffer: true,
  1877. depthTexture: null,
  1878. samples: 0,
  1879. count: 1
  1880. }, options );
  1881. const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  1882. texture.flipY = false;
  1883. texture.generateMipmaps = options.generateMipmaps;
  1884. texture.internalFormat = options.internalFormat;
  1885. this.textures = [];
  1886. const count = options.count;
  1887. for ( let i = 0; i < count; i ++ ) {
  1888. this.textures[ i ] = texture.clone();
  1889. this.textures[ i ].isRenderTargetTexture = true;
  1890. this.textures[ i ].renderTarget = this;
  1891. }
  1892. this.depthBuffer = options.depthBuffer;
  1893. this.stencilBuffer = options.stencilBuffer;
  1894. this.resolveDepthBuffer = options.resolveDepthBuffer;
  1895. this.resolveStencilBuffer = options.resolveStencilBuffer;
  1896. this._depthTexture = null;
  1897. this.depthTexture = options.depthTexture;
  1898. this.samples = options.samples;
  1899. }
  1900. get texture() {
  1901. return this.textures[ 0 ];
  1902. }
  1903. set texture( value ) {
  1904. this.textures[ 0 ] = value;
  1905. }
  1906. set depthTexture( current ) {
  1907. if ( this._depthTexture !== null ) this._depthTexture.renderTarget = null;
  1908. if ( current !== null ) current.renderTarget = this;
  1909. this._depthTexture = current;
  1910. }
  1911. get depthTexture() {
  1912. return this._depthTexture;
  1913. }
  1914. setSize( width, height, depth = 1 ) {
  1915. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1916. this.width = width;
  1917. this.height = height;
  1918. this.depth = depth;
  1919. for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
  1920. this.textures[ i ].image.width = width;
  1921. this.textures[ i ].image.height = height;
  1922. this.textures[ i ].image.depth = depth;
  1923. }
  1924. this.dispose();
  1925. }
  1926. this.viewport.set( 0, 0, width, height );
  1927. this.scissor.set( 0, 0, width, height );
  1928. }
  1929. clone() {
  1930. return new this.constructor().copy( this );
  1931. }
  1932. copy( source ) {
  1933. this.width = source.width;
  1934. this.height = source.height;
  1935. this.depth = source.depth;
  1936. this.scissor.copy( source.scissor );
  1937. this.scissorTest = source.scissorTest;
  1938. this.viewport.copy( source.viewport );
  1939. this.textures.length = 0;
  1940. for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
  1941. this.textures[ i ] = source.textures[ i ].clone();
  1942. this.textures[ i ].isRenderTargetTexture = true;
  1943. this.textures[ i ].renderTarget = this;
  1944. }
  1945. // ensure image object is not shared, see #20328
  1946. const image = Object.assign( {}, source.texture.image );
  1947. this.texture.source = new Source( image );
  1948. this.depthBuffer = source.depthBuffer;
  1949. this.stencilBuffer = source.stencilBuffer;
  1950. this.resolveDepthBuffer = source.resolveDepthBuffer;
  1951. this.resolveStencilBuffer = source.resolveStencilBuffer;
  1952. if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
  1953. this.samples = source.samples;
  1954. return this;
  1955. }
  1956. dispose() {
  1957. this.dispatchEvent( { type: 'dispose' } );
  1958. }
  1959. }
  1960. class WebGLRenderTarget extends RenderTarget {
  1961. constructor( width = 1, height = 1, options = {} ) {
  1962. super( width, height, options );
  1963. this.isWebGLRenderTarget = true;
  1964. }
  1965. }
  1966. class DataArrayTexture extends Texture {
  1967. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1968. super( null );
  1969. this.isDataArrayTexture = true;
  1970. this.image = { data, width, height, depth };
  1971. this.magFilter = NearestFilter;
  1972. this.minFilter = NearestFilter;
  1973. this.wrapR = ClampToEdgeWrapping;
  1974. this.generateMipmaps = false;
  1975. this.flipY = false;
  1976. this.unpackAlignment = 1;
  1977. this.layerUpdates = new Set();
  1978. }
  1979. addLayerUpdate( layerIndex ) {
  1980. this.layerUpdates.add( layerIndex );
  1981. }
  1982. clearLayerUpdates() {
  1983. this.layerUpdates.clear();
  1984. }
  1985. }
  1986. class WebGLArrayRenderTarget extends WebGLRenderTarget {
  1987. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  1988. super( width, height, options );
  1989. this.isWebGLArrayRenderTarget = true;
  1990. this.depth = depth;
  1991. this.texture = new DataArrayTexture( null, width, height, depth );
  1992. this.texture.isRenderTargetTexture = true;
  1993. }
  1994. }
  1995. class Data3DTexture extends Texture {
  1996. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1997. // We're going to add .setXXX() methods for setting properties later.
  1998. // Users can still set in Data3DTexture directly.
  1999. //
  2000. // const texture = new THREE.Data3DTexture( data, width, height, depth );
  2001. // texture.anisotropy = 16;
  2002. //
  2003. // See #14839
  2004. super( null );
  2005. this.isData3DTexture = true;
  2006. this.image = { data, width, height, depth };
  2007. this.magFilter = NearestFilter;
  2008. this.minFilter = NearestFilter;
  2009. this.wrapR = ClampToEdgeWrapping;
  2010. this.generateMipmaps = false;
  2011. this.flipY = false;
  2012. this.unpackAlignment = 1;
  2013. }
  2014. }
  2015. class WebGL3DRenderTarget extends WebGLRenderTarget {
  2016. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  2017. super( width, height, options );
  2018. this.isWebGL3DRenderTarget = true;
  2019. this.depth = depth;
  2020. this.texture = new Data3DTexture( null, width, height, depth );
  2021. this.texture.isRenderTargetTexture = true;
  2022. }
  2023. }
  2024. class Quaternion {
  2025. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  2026. this.isQuaternion = true;
  2027. this._x = x;
  2028. this._y = y;
  2029. this._z = z;
  2030. this._w = w;
  2031. }
  2032. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  2033. // fuzz-free, array-based Quaternion SLERP operation
  2034. let x0 = src0[ srcOffset0 + 0 ],
  2035. y0 = src0[ srcOffset0 + 1 ],
  2036. z0 = src0[ srcOffset0 + 2 ],
  2037. w0 = src0[ srcOffset0 + 3 ];
  2038. const x1 = src1[ srcOffset1 + 0 ],
  2039. y1 = src1[ srcOffset1 + 1 ],
  2040. z1 = src1[ srcOffset1 + 2 ],
  2041. w1 = src1[ srcOffset1 + 3 ];
  2042. if ( t === 0 ) {
  2043. dst[ dstOffset + 0 ] = x0;
  2044. dst[ dstOffset + 1 ] = y0;
  2045. dst[ dstOffset + 2 ] = z0;
  2046. dst[ dstOffset + 3 ] = w0;
  2047. return;
  2048. }
  2049. if ( t === 1 ) {
  2050. dst[ dstOffset + 0 ] = x1;
  2051. dst[ dstOffset + 1 ] = y1;
  2052. dst[ dstOffset + 2 ] = z1;
  2053. dst[ dstOffset + 3 ] = w1;
  2054. return;
  2055. }
  2056. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  2057. let s = 1 - t;
  2058. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2059. dir = ( cos >= 0 ? 1 : -1 ),
  2060. sqrSin = 1 - cos * cos;
  2061. // Skip the Slerp for tiny steps to avoid numeric problems:
  2062. if ( sqrSin > Number.EPSILON ) {
  2063. const sin = Math.sqrt( sqrSin ),
  2064. len = Math.atan2( sin, cos * dir );
  2065. s = Math.sin( s * len ) / sin;
  2066. t = Math.sin( t * len ) / sin;
  2067. }
  2068. const tDir = t * dir;
  2069. x0 = x0 * s + x1 * tDir;
  2070. y0 = y0 * s + y1 * tDir;
  2071. z0 = z0 * s + z1 * tDir;
  2072. w0 = w0 * s + w1 * tDir;
  2073. // Normalize in case we just did a lerp:
  2074. if ( s === 1 - t ) {
  2075. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  2076. x0 *= f;
  2077. y0 *= f;
  2078. z0 *= f;
  2079. w0 *= f;
  2080. }
  2081. }
  2082. dst[ dstOffset ] = x0;
  2083. dst[ dstOffset + 1 ] = y0;
  2084. dst[ dstOffset + 2 ] = z0;
  2085. dst[ dstOffset + 3 ] = w0;
  2086. }
  2087. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  2088. const x0 = src0[ srcOffset0 ];
  2089. const y0 = src0[ srcOffset0 + 1 ];
  2090. const z0 = src0[ srcOffset0 + 2 ];
  2091. const w0 = src0[ srcOffset0 + 3 ];
  2092. const x1 = src1[ srcOffset1 ];
  2093. const y1 = src1[ srcOffset1 + 1 ];
  2094. const z1 = src1[ srcOffset1 + 2 ];
  2095. const w1 = src1[ srcOffset1 + 3 ];
  2096. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2097. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2098. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2099. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2100. return dst;
  2101. }
  2102. get x() {
  2103. return this._x;
  2104. }
  2105. set x( value ) {
  2106. this._x = value;
  2107. this._onChangeCallback();
  2108. }
  2109. get y() {
  2110. return this._y;
  2111. }
  2112. set y( value ) {
  2113. this._y = value;
  2114. this._onChangeCallback();
  2115. }
  2116. get z() {
  2117. return this._z;
  2118. }
  2119. set z( value ) {
  2120. this._z = value;
  2121. this._onChangeCallback();
  2122. }
  2123. get w() {
  2124. return this._w;
  2125. }
  2126. set w( value ) {
  2127. this._w = value;
  2128. this._onChangeCallback();
  2129. }
  2130. set( x, y, z, w ) {
  2131. this._x = x;
  2132. this._y = y;
  2133. this._z = z;
  2134. this._w = w;
  2135. this._onChangeCallback();
  2136. return this;
  2137. }
  2138. clone() {
  2139. return new this.constructor( this._x, this._y, this._z, this._w );
  2140. }
  2141. copy( quaternion ) {
  2142. this._x = quaternion.x;
  2143. this._y = quaternion.y;
  2144. this._z = quaternion.z;
  2145. this._w = quaternion.w;
  2146. this._onChangeCallback();
  2147. return this;
  2148. }
  2149. setFromEuler( euler, update = true ) {
  2150. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  2151. // http://www.mathworks.com/matlabcentral/fileexchange/
  2152. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2153. // content/SpinCalc.m
  2154. const cos = Math.cos;
  2155. const sin = Math.sin;
  2156. const c1 = cos( x / 2 );
  2157. const c2 = cos( y / 2 );
  2158. const c3 = cos( z / 2 );
  2159. const s1 = sin( x / 2 );
  2160. const s2 = sin( y / 2 );
  2161. const s3 = sin( z / 2 );
  2162. switch ( order ) {
  2163. case 'XYZ':
  2164. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2165. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2166. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2167. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2168. break;
  2169. case 'YXZ':
  2170. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2171. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2172. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2173. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2174. break;
  2175. case 'ZXY':
  2176. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2177. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2178. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2179. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2180. break;
  2181. case 'ZYX':
  2182. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2183. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2184. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2185. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2186. break;
  2187. case 'YZX':
  2188. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2189. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2190. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2191. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2192. break;
  2193. case 'XZY':
  2194. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2195. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2196. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2197. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2198. break;
  2199. default:
  2200. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  2201. }
  2202. if ( update === true ) this._onChangeCallback();
  2203. return this;
  2204. }
  2205. setFromAxisAngle( axis, angle ) {
  2206. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2207. // assumes axis is normalized
  2208. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  2209. this._x = axis.x * s;
  2210. this._y = axis.y * s;
  2211. this._z = axis.z * s;
  2212. this._w = Math.cos( halfAngle );
  2213. this._onChangeCallback();
  2214. return this;
  2215. }
  2216. setFromRotationMatrix( m ) {
  2217. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2218. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2219. const te = m.elements,
  2220. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2221. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2222. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  2223. trace = m11 + m22 + m33;
  2224. if ( trace > 0 ) {
  2225. const s = 0.5 / Math.sqrt( trace + 1.0 );
  2226. this._w = 0.25 / s;
  2227. this._x = ( m32 - m23 ) * s;
  2228. this._y = ( m13 - m31 ) * s;
  2229. this._z = ( m21 - m12 ) * s;
  2230. } else if ( m11 > m22 && m11 > m33 ) {
  2231. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  2232. this._w = ( m32 - m23 ) / s;
  2233. this._x = 0.25 * s;
  2234. this._y = ( m12 + m21 ) / s;
  2235. this._z = ( m13 + m31 ) / s;
  2236. } else if ( m22 > m33 ) {
  2237. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  2238. this._w = ( m13 - m31 ) / s;
  2239. this._x = ( m12 + m21 ) / s;
  2240. this._y = 0.25 * s;
  2241. this._z = ( m23 + m32 ) / s;
  2242. } else {
  2243. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  2244. this._w = ( m21 - m12 ) / s;
  2245. this._x = ( m13 + m31 ) / s;
  2246. this._y = ( m23 + m32 ) / s;
  2247. this._z = 0.25 * s;
  2248. }
  2249. this._onChangeCallback();
  2250. return this;
  2251. }
  2252. setFromUnitVectors( vFrom, vTo ) {
  2253. // assumes direction vectors vFrom and vTo are normalized
  2254. let r = vFrom.dot( vTo ) + 1;
  2255. if ( r < Number.EPSILON ) {
  2256. // vFrom and vTo point in opposite directions
  2257. r = 0;
  2258. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  2259. this._x = - vFrom.y;
  2260. this._y = vFrom.x;
  2261. this._z = 0;
  2262. this._w = r;
  2263. } else {
  2264. this._x = 0;
  2265. this._y = - vFrom.z;
  2266. this._z = vFrom.y;
  2267. this._w = r;
  2268. }
  2269. } else {
  2270. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2271. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2272. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2273. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2274. this._w = r;
  2275. }
  2276. return this.normalize();
  2277. }
  2278. angleTo( q ) {
  2279. return 2 * Math.acos( Math.abs( clamp( this.dot( q ), -1, 1 ) ) );
  2280. }
  2281. rotateTowards( q, step ) {
  2282. const angle = this.angleTo( q );
  2283. if ( angle === 0 ) return this;
  2284. const t = Math.min( 1, step / angle );
  2285. this.slerp( q, t );
  2286. return this;
  2287. }
  2288. identity() {
  2289. return this.set( 0, 0, 0, 1 );
  2290. }
  2291. invert() {
  2292. // quaternion is assumed to have unit length
  2293. return this.conjugate();
  2294. }
  2295. conjugate() {
  2296. this._x *= -1;
  2297. this._y *= -1;
  2298. this._z *= -1;
  2299. this._onChangeCallback();
  2300. return this;
  2301. }
  2302. dot( v ) {
  2303. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2304. }
  2305. lengthSq() {
  2306. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2307. }
  2308. length() {
  2309. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  2310. }
  2311. normalize() {
  2312. let l = this.length();
  2313. if ( l === 0 ) {
  2314. this._x = 0;
  2315. this._y = 0;
  2316. this._z = 0;
  2317. this._w = 1;
  2318. } else {
  2319. l = 1 / l;
  2320. this._x = this._x * l;
  2321. this._y = this._y * l;
  2322. this._z = this._z * l;
  2323. this._w = this._w * l;
  2324. }
  2325. this._onChangeCallback();
  2326. return this;
  2327. }
  2328. multiply( q ) {
  2329. return this.multiplyQuaternions( this, q );
  2330. }
  2331. premultiply( q ) {
  2332. return this.multiplyQuaternions( q, this );
  2333. }
  2334. multiplyQuaternions( a, b ) {
  2335. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2336. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  2337. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  2338. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2339. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2340. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2341. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2342. this._onChangeCallback();
  2343. return this;
  2344. }
  2345. slerp( qb, t ) {
  2346. if ( t === 0 ) return this;
  2347. if ( t === 1 ) return this.copy( qb );
  2348. const x = this._x, y = this._y, z = this._z, w = this._w;
  2349. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2350. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2351. if ( cosHalfTheta < 0 ) {
  2352. this._w = - qb._w;
  2353. this._x = - qb._x;
  2354. this._y = - qb._y;
  2355. this._z = - qb._z;
  2356. cosHalfTheta = - cosHalfTheta;
  2357. } else {
  2358. this.copy( qb );
  2359. }
  2360. if ( cosHalfTheta >= 1.0 ) {
  2361. this._w = w;
  2362. this._x = x;
  2363. this._y = y;
  2364. this._z = z;
  2365. return this;
  2366. }
  2367. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2368. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  2369. const s = 1 - t;
  2370. this._w = s * w + t * this._w;
  2371. this._x = s * x + t * this._x;
  2372. this._y = s * y + t * this._y;
  2373. this._z = s * z + t * this._z;
  2374. this.normalize(); // normalize calls _onChangeCallback()
  2375. return this;
  2376. }
  2377. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  2378. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  2379. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2380. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2381. this._w = ( w * ratioA + this._w * ratioB );
  2382. this._x = ( x * ratioA + this._x * ratioB );
  2383. this._y = ( y * ratioA + this._y * ratioB );
  2384. this._z = ( z * ratioA + this._z * ratioB );
  2385. this._onChangeCallback();
  2386. return this;
  2387. }
  2388. slerpQuaternions( qa, qb, t ) {
  2389. return this.copy( qa ).slerp( qb, t );
  2390. }
  2391. random() {
  2392. // sets this quaternion to a uniform random unit quaternnion
  2393. // Ken Shoemake
  2394. // Uniform random rotations
  2395. // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
  2396. const theta1 = 2 * Math.PI * Math.random();
  2397. const theta2 = 2 * Math.PI * Math.random();
  2398. const x0 = Math.random();
  2399. const r1 = Math.sqrt( 1 - x0 );
  2400. const r2 = Math.sqrt( x0 );
  2401. return this.set(
  2402. r1 * Math.sin( theta1 ),
  2403. r1 * Math.cos( theta1 ),
  2404. r2 * Math.sin( theta2 ),
  2405. r2 * Math.cos( theta2 ),
  2406. );
  2407. }
  2408. equals( quaternion ) {
  2409. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  2410. }
  2411. fromArray( array, offset = 0 ) {
  2412. this._x = array[ offset ];
  2413. this._y = array[ offset + 1 ];
  2414. this._z = array[ offset + 2 ];
  2415. this._w = array[ offset + 3 ];
  2416. this._onChangeCallback();
  2417. return this;
  2418. }
  2419. toArray( array = [], offset = 0 ) {
  2420. array[ offset ] = this._x;
  2421. array[ offset + 1 ] = this._y;
  2422. array[ offset + 2 ] = this._z;
  2423. array[ offset + 3 ] = this._w;
  2424. return array;
  2425. }
  2426. fromBufferAttribute( attribute, index ) {
  2427. this._x = attribute.getX( index );
  2428. this._y = attribute.getY( index );
  2429. this._z = attribute.getZ( index );
  2430. this._w = attribute.getW( index );
  2431. this._onChangeCallback();
  2432. return this;
  2433. }
  2434. toJSON() {
  2435. return this.toArray();
  2436. }
  2437. _onChange( callback ) {
  2438. this._onChangeCallback = callback;
  2439. return this;
  2440. }
  2441. _onChangeCallback() {}
  2442. *[ Symbol.iterator ]() {
  2443. yield this._x;
  2444. yield this._y;
  2445. yield this._z;
  2446. yield this._w;
  2447. }
  2448. }
  2449. class Vector3 {
  2450. constructor( x = 0, y = 0, z = 0 ) {
  2451. Vector3.prototype.isVector3 = true;
  2452. this.x = x;
  2453. this.y = y;
  2454. this.z = z;
  2455. }
  2456. set( x, y, z ) {
  2457. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  2458. this.x = x;
  2459. this.y = y;
  2460. this.z = z;
  2461. return this;
  2462. }
  2463. setScalar( scalar ) {
  2464. this.x = scalar;
  2465. this.y = scalar;
  2466. this.z = scalar;
  2467. return this;
  2468. }
  2469. setX( x ) {
  2470. this.x = x;
  2471. return this;
  2472. }
  2473. setY( y ) {
  2474. this.y = y;
  2475. return this;
  2476. }
  2477. setZ( z ) {
  2478. this.z = z;
  2479. return this;
  2480. }
  2481. setComponent( index, value ) {
  2482. switch ( index ) {
  2483. case 0: this.x = value; break;
  2484. case 1: this.y = value; break;
  2485. case 2: this.z = value; break;
  2486. default: throw new Error( 'index is out of range: ' + index );
  2487. }
  2488. return this;
  2489. }
  2490. getComponent( index ) {
  2491. switch ( index ) {
  2492. case 0: return this.x;
  2493. case 1: return this.y;
  2494. case 2: return this.z;
  2495. default: throw new Error( 'index is out of range: ' + index );
  2496. }
  2497. }
  2498. clone() {
  2499. return new this.constructor( this.x, this.y, this.z );
  2500. }
  2501. copy( v ) {
  2502. this.x = v.x;
  2503. this.y = v.y;
  2504. this.z = v.z;
  2505. return this;
  2506. }
  2507. add( v ) {
  2508. this.x += v.x;
  2509. this.y += v.y;
  2510. this.z += v.z;
  2511. return this;
  2512. }
  2513. addScalar( s ) {
  2514. this.x += s;
  2515. this.y += s;
  2516. this.z += s;
  2517. return this;
  2518. }
  2519. addVectors( a, b ) {
  2520. this.x = a.x + b.x;
  2521. this.y = a.y + b.y;
  2522. this.z = a.z + b.z;
  2523. return this;
  2524. }
  2525. addScaledVector( v, s ) {
  2526. this.x += v.x * s;
  2527. this.y += v.y * s;
  2528. this.z += v.z * s;
  2529. return this;
  2530. }
  2531. sub( v ) {
  2532. this.x -= v.x;
  2533. this.y -= v.y;
  2534. this.z -= v.z;
  2535. return this;
  2536. }
  2537. subScalar( s ) {
  2538. this.x -= s;
  2539. this.y -= s;
  2540. this.z -= s;
  2541. return this;
  2542. }
  2543. subVectors( a, b ) {
  2544. this.x = a.x - b.x;
  2545. this.y = a.y - b.y;
  2546. this.z = a.z - b.z;
  2547. return this;
  2548. }
  2549. multiply( v ) {
  2550. this.x *= v.x;
  2551. this.y *= v.y;
  2552. this.z *= v.z;
  2553. return this;
  2554. }
  2555. multiplyScalar( scalar ) {
  2556. this.x *= scalar;
  2557. this.y *= scalar;
  2558. this.z *= scalar;
  2559. return this;
  2560. }
  2561. multiplyVectors( a, b ) {
  2562. this.x = a.x * b.x;
  2563. this.y = a.y * b.y;
  2564. this.z = a.z * b.z;
  2565. return this;
  2566. }
  2567. applyEuler( euler ) {
  2568. return this.applyQuaternion( _quaternion$4.setFromEuler( euler ) );
  2569. }
  2570. applyAxisAngle( axis, angle ) {
  2571. return this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) );
  2572. }
  2573. applyMatrix3( m ) {
  2574. const x = this.x, y = this.y, z = this.z;
  2575. const e = m.elements;
  2576. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2577. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2578. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2579. return this;
  2580. }
  2581. applyNormalMatrix( m ) {
  2582. return this.applyMatrix3( m ).normalize();
  2583. }
  2584. applyMatrix4( m ) {
  2585. const x = this.x, y = this.y, z = this.z;
  2586. const e = m.elements;
  2587. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2588. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2589. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2590. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2591. return this;
  2592. }
  2593. applyQuaternion( q ) {
  2594. // quaternion q is assumed to have unit length
  2595. const vx = this.x, vy = this.y, vz = this.z;
  2596. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2597. // t = 2 * cross( q.xyz, v );
  2598. const tx = 2 * ( qy * vz - qz * vy );
  2599. const ty = 2 * ( qz * vx - qx * vz );
  2600. const tz = 2 * ( qx * vy - qy * vx );
  2601. // v + q.w * t + cross( q.xyz, t );
  2602. this.x = vx + qw * tx + qy * tz - qz * ty;
  2603. this.y = vy + qw * ty + qz * tx - qx * tz;
  2604. this.z = vz + qw * tz + qx * ty - qy * tx;
  2605. return this;
  2606. }
  2607. project( camera ) {
  2608. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2609. }
  2610. unproject( camera ) {
  2611. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2612. }
  2613. transformDirection( m ) {
  2614. // input: THREE.Matrix4 affine matrix
  2615. // vector interpreted as a direction
  2616. const x = this.x, y = this.y, z = this.z;
  2617. const e = m.elements;
  2618. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2619. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2620. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2621. return this.normalize();
  2622. }
  2623. divide( v ) {
  2624. this.x /= v.x;
  2625. this.y /= v.y;
  2626. this.z /= v.z;
  2627. return this;
  2628. }
  2629. divideScalar( scalar ) {
  2630. return this.multiplyScalar( 1 / scalar );
  2631. }
  2632. min( v ) {
  2633. this.x = Math.min( this.x, v.x );
  2634. this.y = Math.min( this.y, v.y );
  2635. this.z = Math.min( this.z, v.z );
  2636. return this;
  2637. }
  2638. max( v ) {
  2639. this.x = Math.max( this.x, v.x );
  2640. this.y = Math.max( this.y, v.y );
  2641. this.z = Math.max( this.z, v.z );
  2642. return this;
  2643. }
  2644. clamp( min, max ) {
  2645. // assumes min < max, componentwise
  2646. this.x = clamp( this.x, min.x, max.x );
  2647. this.y = clamp( this.y, min.y, max.y );
  2648. this.z = clamp( this.z, min.z, max.z );
  2649. return this;
  2650. }
  2651. clampScalar( minVal, maxVal ) {
  2652. this.x = clamp( this.x, minVal, maxVal );
  2653. this.y = clamp( this.y, minVal, maxVal );
  2654. this.z = clamp( this.z, minVal, maxVal );
  2655. return this;
  2656. }
  2657. clampLength( min, max ) {
  2658. const length = this.length();
  2659. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  2660. }
  2661. floor() {
  2662. this.x = Math.floor( this.x );
  2663. this.y = Math.floor( this.y );
  2664. this.z = Math.floor( this.z );
  2665. return this;
  2666. }
  2667. ceil() {
  2668. this.x = Math.ceil( this.x );
  2669. this.y = Math.ceil( this.y );
  2670. this.z = Math.ceil( this.z );
  2671. return this;
  2672. }
  2673. round() {
  2674. this.x = Math.round( this.x );
  2675. this.y = Math.round( this.y );
  2676. this.z = Math.round( this.z );
  2677. return this;
  2678. }
  2679. roundToZero() {
  2680. this.x = Math.trunc( this.x );
  2681. this.y = Math.trunc( this.y );
  2682. this.z = Math.trunc( this.z );
  2683. return this;
  2684. }
  2685. negate() {
  2686. this.x = - this.x;
  2687. this.y = - this.y;
  2688. this.z = - this.z;
  2689. return this;
  2690. }
  2691. dot( v ) {
  2692. return this.x * v.x + this.y * v.y + this.z * v.z;
  2693. }
  2694. // TODO lengthSquared?
  2695. lengthSq() {
  2696. return this.x * this.x + this.y * this.y + this.z * this.z;
  2697. }
  2698. length() {
  2699. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2700. }
  2701. manhattanLength() {
  2702. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2703. }
  2704. normalize() {
  2705. return this.divideScalar( this.length() || 1 );
  2706. }
  2707. setLength( length ) {
  2708. return this.normalize().multiplyScalar( length );
  2709. }
  2710. lerp( v, alpha ) {
  2711. this.x += ( v.x - this.x ) * alpha;
  2712. this.y += ( v.y - this.y ) * alpha;
  2713. this.z += ( v.z - this.z ) * alpha;
  2714. return this;
  2715. }
  2716. lerpVectors( v1, v2, alpha ) {
  2717. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2718. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2719. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2720. return this;
  2721. }
  2722. cross( v ) {
  2723. return this.crossVectors( this, v );
  2724. }
  2725. crossVectors( a, b ) {
  2726. const ax = a.x, ay = a.y, az = a.z;
  2727. const bx = b.x, by = b.y, bz = b.z;
  2728. this.x = ay * bz - az * by;
  2729. this.y = az * bx - ax * bz;
  2730. this.z = ax * by - ay * bx;
  2731. return this;
  2732. }
  2733. projectOnVector( v ) {
  2734. const denominator = v.lengthSq();
  2735. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2736. const scalar = v.dot( this ) / denominator;
  2737. return this.copy( v ).multiplyScalar( scalar );
  2738. }
  2739. projectOnPlane( planeNormal ) {
  2740. _vector$c.copy( this ).projectOnVector( planeNormal );
  2741. return this.sub( _vector$c );
  2742. }
  2743. reflect( normal ) {
  2744. // reflect incident vector off plane orthogonal to normal
  2745. // normal is assumed to have unit length
  2746. return this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2747. }
  2748. angleTo( v ) {
  2749. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2750. if ( denominator === 0 ) return Math.PI / 2;
  2751. const theta = this.dot( v ) / denominator;
  2752. // clamp, to handle numerical problems
  2753. return Math.acos( clamp( theta, -1, 1 ) );
  2754. }
  2755. distanceTo( v ) {
  2756. return Math.sqrt( this.distanceToSquared( v ) );
  2757. }
  2758. distanceToSquared( v ) {
  2759. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2760. return dx * dx + dy * dy + dz * dz;
  2761. }
  2762. manhattanDistanceTo( v ) {
  2763. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2764. }
  2765. setFromSpherical( s ) {
  2766. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2767. }
  2768. setFromSphericalCoords( radius, phi, theta ) {
  2769. const sinPhiRadius = Math.sin( phi ) * radius;
  2770. this.x = sinPhiRadius * Math.sin( theta );
  2771. this.y = Math.cos( phi ) * radius;
  2772. this.z = sinPhiRadius * Math.cos( theta );
  2773. return this;
  2774. }
  2775. setFromCylindrical( c ) {
  2776. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2777. }
  2778. setFromCylindricalCoords( radius, theta, y ) {
  2779. this.x = radius * Math.sin( theta );
  2780. this.y = y;
  2781. this.z = radius * Math.cos( theta );
  2782. return this;
  2783. }
  2784. setFromMatrixPosition( m ) {
  2785. const e = m.elements;
  2786. this.x = e[ 12 ];
  2787. this.y = e[ 13 ];
  2788. this.z = e[ 14 ];
  2789. return this;
  2790. }
  2791. setFromMatrixScale( m ) {
  2792. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2793. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2794. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2795. this.x = sx;
  2796. this.y = sy;
  2797. this.z = sz;
  2798. return this;
  2799. }
  2800. setFromMatrixColumn( m, index ) {
  2801. return this.fromArray( m.elements, index * 4 );
  2802. }
  2803. setFromMatrix3Column( m, index ) {
  2804. return this.fromArray( m.elements, index * 3 );
  2805. }
  2806. setFromEuler( e ) {
  2807. this.x = e._x;
  2808. this.y = e._y;
  2809. this.z = e._z;
  2810. return this;
  2811. }
  2812. setFromColor( c ) {
  2813. this.x = c.r;
  2814. this.y = c.g;
  2815. this.z = c.b;
  2816. return this;
  2817. }
  2818. equals( v ) {
  2819. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2820. }
  2821. fromArray( array, offset = 0 ) {
  2822. this.x = array[ offset ];
  2823. this.y = array[ offset + 1 ];
  2824. this.z = array[ offset + 2 ];
  2825. return this;
  2826. }
  2827. toArray( array = [], offset = 0 ) {
  2828. array[ offset ] = this.x;
  2829. array[ offset + 1 ] = this.y;
  2830. array[ offset + 2 ] = this.z;
  2831. return array;
  2832. }
  2833. fromBufferAttribute( attribute, index ) {
  2834. this.x = attribute.getX( index );
  2835. this.y = attribute.getY( index );
  2836. this.z = attribute.getZ( index );
  2837. return this;
  2838. }
  2839. random() {
  2840. this.x = Math.random();
  2841. this.y = Math.random();
  2842. this.z = Math.random();
  2843. return this;
  2844. }
  2845. randomDirection() {
  2846. // https://mathworld.wolfram.com/SpherePointPicking.html
  2847. const theta = Math.random() * Math.PI * 2;
  2848. const u = Math.random() * 2 - 1;
  2849. const c = Math.sqrt( 1 - u * u );
  2850. this.x = c * Math.cos( theta );
  2851. this.y = u;
  2852. this.z = c * Math.sin( theta );
  2853. return this;
  2854. }
  2855. *[ Symbol.iterator ]() {
  2856. yield this.x;
  2857. yield this.y;
  2858. yield this.z;
  2859. }
  2860. }
  2861. const _vector$c = /*@__PURE__*/ new Vector3();
  2862. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  2863. class Box3 {
  2864. constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
  2865. this.isBox3 = true;
  2866. this.min = min;
  2867. this.max = max;
  2868. }
  2869. set( min, max ) {
  2870. this.min.copy( min );
  2871. this.max.copy( max );
  2872. return this;
  2873. }
  2874. setFromArray( array ) {
  2875. this.makeEmpty();
  2876. for ( let i = 0, il = array.length; i < il; i += 3 ) {
  2877. this.expandByPoint( _vector$b.fromArray( array, i ) );
  2878. }
  2879. return this;
  2880. }
  2881. setFromBufferAttribute( attribute ) {
  2882. this.makeEmpty();
  2883. for ( let i = 0, il = attribute.count; i < il; i ++ ) {
  2884. this.expandByPoint( _vector$b.fromBufferAttribute( attribute, i ) );
  2885. }
  2886. return this;
  2887. }
  2888. setFromPoints( points ) {
  2889. this.makeEmpty();
  2890. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2891. this.expandByPoint( points[ i ] );
  2892. }
  2893. return this;
  2894. }
  2895. setFromCenterAndSize( center, size ) {
  2896. const halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 );
  2897. this.min.copy( center ).sub( halfSize );
  2898. this.max.copy( center ).add( halfSize );
  2899. return this;
  2900. }
  2901. setFromObject( object, precise = false ) {
  2902. this.makeEmpty();
  2903. return this.expandByObject( object, precise );
  2904. }
  2905. clone() {
  2906. return new this.constructor().copy( this );
  2907. }
  2908. copy( box ) {
  2909. this.min.copy( box.min );
  2910. this.max.copy( box.max );
  2911. return this;
  2912. }
  2913. makeEmpty() {
  2914. this.min.x = this.min.y = this.min.z = + Infinity;
  2915. this.max.x = this.max.y = this.max.z = - Infinity;
  2916. return this;
  2917. }
  2918. isEmpty() {
  2919. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2920. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2921. }
  2922. getCenter( target ) {
  2923. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2924. }
  2925. getSize( target ) {
  2926. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2927. }
  2928. expandByPoint( point ) {
  2929. this.min.min( point );
  2930. this.max.max( point );
  2931. return this;
  2932. }
  2933. expandByVector( vector ) {
  2934. this.min.sub( vector );
  2935. this.max.add( vector );
  2936. return this;
  2937. }
  2938. expandByScalar( scalar ) {
  2939. this.min.addScalar( - scalar );
  2940. this.max.addScalar( scalar );
  2941. return this;
  2942. }
  2943. expandByObject( object, precise = false ) {
  2944. // Computes the world-axis-aligned bounding box of an object (including its children),
  2945. // accounting for both the object's, and children's, world transforms
  2946. object.updateWorldMatrix( false, false );
  2947. const geometry = object.geometry;
  2948. if ( geometry !== undefined ) {
  2949. const positionAttribute = geometry.getAttribute( 'position' );
  2950. // precise AABB computation based on vertex data requires at least a position attribute.
  2951. // instancing isn't supported so far and uses the normal (conservative) code path.
  2952. if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
  2953. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  2954. if ( object.isMesh === true ) {
  2955. object.getVertexPosition( i, _vector$b );
  2956. } else {
  2957. _vector$b.fromBufferAttribute( positionAttribute, i );
  2958. }
  2959. _vector$b.applyMatrix4( object.matrixWorld );
  2960. this.expandByPoint( _vector$b );
  2961. }
  2962. } else {
  2963. if ( object.boundingBox !== undefined ) {
  2964. // object-level bounding box
  2965. if ( object.boundingBox === null ) {
  2966. object.computeBoundingBox();
  2967. }
  2968. _box$4.copy( object.boundingBox );
  2969. } else {
  2970. // geometry-level bounding box
  2971. if ( geometry.boundingBox === null ) {
  2972. geometry.computeBoundingBox();
  2973. }
  2974. _box$4.copy( geometry.boundingBox );
  2975. }
  2976. _box$4.applyMatrix4( object.matrixWorld );
  2977. this.union( _box$4 );
  2978. }
  2979. }
  2980. const children = object.children;
  2981. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2982. this.expandByObject( children[ i ], precise );
  2983. }
  2984. return this;
  2985. }
  2986. containsPoint( point ) {
  2987. return point.x >= this.min.x && point.x <= this.max.x &&
  2988. point.y >= this.min.y && point.y <= this.max.y &&
  2989. point.z >= this.min.z && point.z <= this.max.z;
  2990. }
  2991. containsBox( box ) {
  2992. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2993. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2994. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2995. }
  2996. getParameter( point, target ) {
  2997. // This can potentially have a divide by zero if the box
  2998. // has a size dimension of 0.
  2999. return target.set(
  3000. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3001. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3002. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3003. );
  3004. }
  3005. intersectsBox( box ) {
  3006. // using 6 splitting planes to rule out intersections.
  3007. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  3008. box.max.y >= this.min.y && box.min.y <= this.max.y &&
  3009. box.max.z >= this.min.z && box.min.z <= this.max.z;
  3010. }
  3011. intersectsSphere( sphere ) {
  3012. // Find the point on the AABB closest to the sphere center.
  3013. this.clampPoint( sphere.center, _vector$b );
  3014. // If that point is inside the sphere, the AABB and sphere intersect.
  3015. return _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3016. }
  3017. intersectsPlane( plane ) {
  3018. // We compute the minimum and maximum dot product values. If those values
  3019. // are on the same side (back or front) of the plane, then there is no intersection.
  3020. let min, max;
  3021. if ( plane.normal.x > 0 ) {
  3022. min = plane.normal.x * this.min.x;
  3023. max = plane.normal.x * this.max.x;
  3024. } else {
  3025. min = plane.normal.x * this.max.x;
  3026. max = plane.normal.x * this.min.x;
  3027. }
  3028. if ( plane.normal.y > 0 ) {
  3029. min += plane.normal.y * this.min.y;
  3030. max += plane.normal.y * this.max.y;
  3031. } else {
  3032. min += plane.normal.y * this.max.y;
  3033. max += plane.normal.y * this.min.y;
  3034. }
  3035. if ( plane.normal.z > 0 ) {
  3036. min += plane.normal.z * this.min.z;
  3037. max += plane.normal.z * this.max.z;
  3038. } else {
  3039. min += plane.normal.z * this.max.z;
  3040. max += plane.normal.z * this.min.z;
  3041. }
  3042. return ( min <= - plane.constant && max >= - plane.constant );
  3043. }
  3044. intersectsTriangle( triangle ) {
  3045. if ( this.isEmpty() ) {
  3046. return false;
  3047. }
  3048. // compute box center and extents
  3049. this.getCenter( _center );
  3050. _extents.subVectors( this.max, _center );
  3051. // translate triangle to aabb origin
  3052. _v0$2.subVectors( triangle.a, _center );
  3053. _v1$7.subVectors( triangle.b, _center );
  3054. _v2$4.subVectors( triangle.c, _center );
  3055. // compute edge vectors for triangle
  3056. _f0.subVectors( _v1$7, _v0$2 );
  3057. _f1.subVectors( _v2$4, _v1$7 );
  3058. _f2.subVectors( _v0$2, _v2$4 );
  3059. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3060. // 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
  3061. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3062. let axes = [
  3063. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3064. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3065. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3066. ];
  3067. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3068. return false;
  3069. }
  3070. // test 3 face normals from the aabb
  3071. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3072. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3073. return false;
  3074. }
  3075. // finally testing the face normal of the triangle
  3076. // use already existing triangle edge vectors here
  3077. _triangleNormal.crossVectors( _f0, _f1 );
  3078. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3079. return satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents );
  3080. }
  3081. clampPoint( point, target ) {
  3082. return target.copy( point ).clamp( this.min, this.max );
  3083. }
  3084. distanceToPoint( point ) {
  3085. return this.clampPoint( point, _vector$b ).distanceTo( point );
  3086. }
  3087. getBoundingSphere( target ) {
  3088. if ( this.isEmpty() ) {
  3089. target.makeEmpty();
  3090. } else {
  3091. this.getCenter( target.center );
  3092. target.radius = this.getSize( _vector$b ).length() * 0.5;
  3093. }
  3094. return target;
  3095. }
  3096. intersect( box ) {
  3097. this.min.max( box.min );
  3098. this.max.min( box.max );
  3099. // 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.
  3100. if ( this.isEmpty() ) this.makeEmpty();
  3101. return this;
  3102. }
  3103. union( box ) {
  3104. this.min.min( box.min );
  3105. this.max.max( box.max );
  3106. return this;
  3107. }
  3108. applyMatrix4( matrix ) {
  3109. // transform of empty box is an empty box.
  3110. if ( this.isEmpty() ) return this;
  3111. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3112. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3113. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3114. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3115. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3116. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3117. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3118. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3119. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3120. this.setFromPoints( _points );
  3121. return this;
  3122. }
  3123. translate( offset ) {
  3124. this.min.add( offset );
  3125. this.max.add( offset );
  3126. return this;
  3127. }
  3128. equals( box ) {
  3129. return box.min.equals( this.min ) && box.max.equals( this.max );
  3130. }
  3131. }
  3132. const _points = [
  3133. /*@__PURE__*/ new Vector3(),
  3134. /*@__PURE__*/ new Vector3(),
  3135. /*@__PURE__*/ new Vector3(),
  3136. /*@__PURE__*/ new Vector3(),
  3137. /*@__PURE__*/ new Vector3(),
  3138. /*@__PURE__*/ new Vector3(),
  3139. /*@__PURE__*/ new Vector3(),
  3140. /*@__PURE__*/ new Vector3()
  3141. ];
  3142. const _vector$b = /*@__PURE__*/ new Vector3();
  3143. const _box$4 = /*@__PURE__*/ new Box3();
  3144. // triangle centered vertices
  3145. const _v0$2 = /*@__PURE__*/ new Vector3();
  3146. const _v1$7 = /*@__PURE__*/ new Vector3();
  3147. const _v2$4 = /*@__PURE__*/ new Vector3();
  3148. // triangle edge vectors
  3149. const _f0 = /*@__PURE__*/ new Vector3();
  3150. const _f1 = /*@__PURE__*/ new Vector3();
  3151. const _f2 = /*@__PURE__*/ new Vector3();
  3152. const _center = /*@__PURE__*/ new Vector3();
  3153. const _extents = /*@__PURE__*/ new Vector3();
  3154. const _triangleNormal = /*@__PURE__*/ new Vector3();
  3155. const _testAxis = /*@__PURE__*/ new Vector3();
  3156. function satForAxes( axes, v0, v1, v2, extents ) {
  3157. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3158. _testAxis.fromArray( axes, i );
  3159. // project the aabb onto the separating axis
  3160. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  3161. // project all 3 vertices of the triangle onto the separating axis
  3162. const p0 = v0.dot( _testAxis );
  3163. const p1 = v1.dot( _testAxis );
  3164. const p2 = v2.dot( _testAxis );
  3165. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3166. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3167. // points of the projected triangle are outside the projected half-length of the aabb
  3168. // the axis is separating and we can exit
  3169. return false;
  3170. }
  3171. }
  3172. return true;
  3173. }
  3174. const _box$3 = /*@__PURE__*/ new Box3();
  3175. const _v1$6 = /*@__PURE__*/ new Vector3();
  3176. const _v2$3 = /*@__PURE__*/ new Vector3();
  3177. class Sphere {
  3178. constructor( center = new Vector3(), radius = -1 ) {
  3179. this.isSphere = true;
  3180. this.center = center;
  3181. this.radius = radius;
  3182. }
  3183. set( center, radius ) {
  3184. this.center.copy( center );
  3185. this.radius = radius;
  3186. return this;
  3187. }
  3188. setFromPoints( points, optionalCenter ) {
  3189. const center = this.center;
  3190. if ( optionalCenter !== undefined ) {
  3191. center.copy( optionalCenter );
  3192. } else {
  3193. _box$3.setFromPoints( points ).getCenter( center );
  3194. }
  3195. let maxRadiusSq = 0;
  3196. for ( let i = 0, il = points.length; i < il; i ++ ) {
  3197. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3198. }
  3199. this.radius = Math.sqrt( maxRadiusSq );
  3200. return this;
  3201. }
  3202. copy( sphere ) {
  3203. this.center.copy( sphere.center );
  3204. this.radius = sphere.radius;
  3205. return this;
  3206. }
  3207. isEmpty() {
  3208. return ( this.radius < 0 );
  3209. }
  3210. makeEmpty() {
  3211. this.center.set( 0, 0, 0 );
  3212. this.radius = -1;
  3213. return this;
  3214. }
  3215. containsPoint( point ) {
  3216. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3217. }
  3218. distanceToPoint( point ) {
  3219. return ( point.distanceTo( this.center ) - this.radius );
  3220. }
  3221. intersectsSphere( sphere ) {
  3222. const radiusSum = this.radius + sphere.radius;
  3223. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3224. }
  3225. intersectsBox( box ) {
  3226. return box.intersectsSphere( this );
  3227. }
  3228. intersectsPlane( plane ) {
  3229. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3230. }
  3231. clampPoint( point, target ) {
  3232. const deltaLengthSq = this.center.distanceToSquared( point );
  3233. target.copy( point );
  3234. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3235. target.sub( this.center ).normalize();
  3236. target.multiplyScalar( this.radius ).add( this.center );
  3237. }
  3238. return target;
  3239. }
  3240. getBoundingBox( target ) {
  3241. if ( this.isEmpty() ) {
  3242. // Empty sphere produces empty bounding box
  3243. target.makeEmpty();
  3244. return target;
  3245. }
  3246. target.set( this.center, this.center );
  3247. target.expandByScalar( this.radius );
  3248. return target;
  3249. }
  3250. applyMatrix4( matrix ) {
  3251. this.center.applyMatrix4( matrix );
  3252. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3253. return this;
  3254. }
  3255. translate( offset ) {
  3256. this.center.add( offset );
  3257. return this;
  3258. }
  3259. expandByPoint( point ) {
  3260. if ( this.isEmpty() ) {
  3261. this.center.copy( point );
  3262. this.radius = 0;
  3263. return this;
  3264. }
  3265. _v1$6.subVectors( point, this.center );
  3266. const lengthSq = _v1$6.lengthSq();
  3267. if ( lengthSq > ( this.radius * this.radius ) ) {
  3268. // calculate the minimal sphere
  3269. const length = Math.sqrt( lengthSq );
  3270. const delta = ( length - this.radius ) * 0.5;
  3271. this.center.addScaledVector( _v1$6, delta / length );
  3272. this.radius += delta;
  3273. }
  3274. return this;
  3275. }
  3276. union( sphere ) {
  3277. if ( sphere.isEmpty() ) {
  3278. return this;
  3279. }
  3280. if ( this.isEmpty() ) {
  3281. this.copy( sphere );
  3282. return this;
  3283. }
  3284. if ( this.center.equals( sphere.center ) === true ) {
  3285. this.radius = Math.max( this.radius, sphere.radius );
  3286. } else {
  3287. _v2$3.subVectors( sphere.center, this.center ).setLength( sphere.radius );
  3288. this.expandByPoint( _v1$6.copy( sphere.center ).add( _v2$3 ) );
  3289. this.expandByPoint( _v1$6.copy( sphere.center ).sub( _v2$3 ) );
  3290. }
  3291. return this;
  3292. }
  3293. equals( sphere ) {
  3294. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3295. }
  3296. clone() {
  3297. return new this.constructor().copy( this );
  3298. }
  3299. }
  3300. const _vector$a = /*@__PURE__*/ new Vector3();
  3301. const _segCenter = /*@__PURE__*/ new Vector3();
  3302. const _segDir = /*@__PURE__*/ new Vector3();
  3303. const _diff = /*@__PURE__*/ new Vector3();
  3304. const _edge1 = /*@__PURE__*/ new Vector3();
  3305. const _edge2 = /*@__PURE__*/ new Vector3();
  3306. const _normal$1 = /*@__PURE__*/ new Vector3();
  3307. class Ray {
  3308. constructor( origin = new Vector3(), direction = new Vector3( 0, 0, -1 ) ) {
  3309. this.origin = origin;
  3310. this.direction = direction;
  3311. }
  3312. set( origin, direction ) {
  3313. this.origin.copy( origin );
  3314. this.direction.copy( direction );
  3315. return this;
  3316. }
  3317. copy( ray ) {
  3318. this.origin.copy( ray.origin );
  3319. this.direction.copy( ray.direction );
  3320. return this;
  3321. }
  3322. at( t, target ) {
  3323. return target.copy( this.origin ).addScaledVector( this.direction, t );
  3324. }
  3325. lookAt( v ) {
  3326. this.direction.copy( v ).sub( this.origin ).normalize();
  3327. return this;
  3328. }
  3329. recast( t ) {
  3330. this.origin.copy( this.at( t, _vector$a ) );
  3331. return this;
  3332. }
  3333. closestPointToPoint( point, target ) {
  3334. target.subVectors( point, this.origin );
  3335. const directionDistance = target.dot( this.direction );
  3336. if ( directionDistance < 0 ) {
  3337. return target.copy( this.origin );
  3338. }
  3339. return target.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3340. }
  3341. distanceToPoint( point ) {
  3342. return Math.sqrt( this.distanceSqToPoint( point ) );
  3343. }
  3344. distanceSqToPoint( point ) {
  3345. const directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction );
  3346. // point behind the ray
  3347. if ( directionDistance < 0 ) {
  3348. return this.origin.distanceToSquared( point );
  3349. }
  3350. _vector$a.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3351. return _vector$a.distanceToSquared( point );
  3352. }
  3353. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3354. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3355. // It returns the min distance between the ray and the segment
  3356. // defined by v0 and v1
  3357. // It can also set two optional targets :
  3358. // - The closest point on the ray
  3359. // - The closest point on the segment
  3360. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3361. _segDir.copy( v1 ).sub( v0 ).normalize();
  3362. _diff.copy( this.origin ).sub( _segCenter );
  3363. const segExtent = v0.distanceTo( v1 ) * 0.5;
  3364. const a01 = - this.direction.dot( _segDir );
  3365. const b0 = _diff.dot( this.direction );
  3366. const b1 = - _diff.dot( _segDir );
  3367. const c = _diff.lengthSq();
  3368. const det = Math.abs( 1 - a01 * a01 );
  3369. let s0, s1, sqrDist, extDet;
  3370. if ( det > 0 ) {
  3371. // The ray and segment are not parallel.
  3372. s0 = a01 * b1 - b0;
  3373. s1 = a01 * b0 - b1;
  3374. extDet = segExtent * det;
  3375. if ( s0 >= 0 ) {
  3376. if ( s1 >= - extDet ) {
  3377. if ( s1 <= extDet ) {
  3378. // region 0
  3379. // Minimum at interior points of ray and segment.
  3380. const invDet = 1 / det;
  3381. s0 *= invDet;
  3382. s1 *= invDet;
  3383. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3384. } else {
  3385. // region 1
  3386. s1 = segExtent;
  3387. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3388. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3389. }
  3390. } else {
  3391. // region 5
  3392. s1 = - segExtent;
  3393. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3394. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3395. }
  3396. } else {
  3397. if ( s1 <= - extDet ) {
  3398. // region 4
  3399. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3400. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3401. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3402. } else if ( s1 <= extDet ) {
  3403. // region 3
  3404. s0 = 0;
  3405. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3406. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3407. } else {
  3408. // region 2
  3409. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3410. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3411. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3412. }
  3413. }
  3414. } else {
  3415. // Ray and segment are parallel.
  3416. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3417. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3418. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3419. }
  3420. if ( optionalPointOnRay ) {
  3421. optionalPointOnRay.copy( this.origin ).addScaledVector( this.direction, s0 );
  3422. }
  3423. if ( optionalPointOnSegment ) {
  3424. optionalPointOnSegment.copy( _segCenter ).addScaledVector( _segDir, s1 );
  3425. }
  3426. return sqrDist;
  3427. }
  3428. intersectSphere( sphere, target ) {
  3429. _vector$a.subVectors( sphere.center, this.origin );
  3430. const tca = _vector$a.dot( this.direction );
  3431. const d2 = _vector$a.dot( _vector$a ) - tca * tca;
  3432. const radius2 = sphere.radius * sphere.radius;
  3433. if ( d2 > radius2 ) return null;
  3434. const thc = Math.sqrt( radius2 - d2 );
  3435. // t0 = first intersect point - entrance on front of sphere
  3436. const t0 = tca - thc;
  3437. // t1 = second intersect point - exit point on back of sphere
  3438. const t1 = tca + thc;
  3439. // test to see if t1 is behind the ray - if so, return null
  3440. if ( t1 < 0 ) return null;
  3441. // test to see if t0 is behind the ray:
  3442. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3443. // in order to always return an intersect point that is in front of the ray.
  3444. if ( t0 < 0 ) return this.at( t1, target );
  3445. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3446. return this.at( t0, target );
  3447. }
  3448. intersectsSphere( sphere ) {
  3449. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  3450. }
  3451. distanceToPlane( plane ) {
  3452. const denominator = plane.normal.dot( this.direction );
  3453. if ( denominator === 0 ) {
  3454. // line is coplanar, return origin
  3455. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3456. return 0;
  3457. }
  3458. // Null is preferable to undefined since undefined means.... it is undefined
  3459. return null;
  3460. }
  3461. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3462. // Return if the ray never intersects the plane
  3463. return t >= 0 ? t : null;
  3464. }
  3465. intersectPlane( plane, target ) {
  3466. const t = this.distanceToPlane( plane );
  3467. if ( t === null ) {
  3468. return null;
  3469. }
  3470. return this.at( t, target );
  3471. }
  3472. intersectsPlane( plane ) {
  3473. // check if the ray lies on the plane first
  3474. const distToPoint = plane.distanceToPoint( this.origin );
  3475. if ( distToPoint === 0 ) {
  3476. return true;
  3477. }
  3478. const denominator = plane.normal.dot( this.direction );
  3479. if ( denominator * distToPoint < 0 ) {
  3480. return true;
  3481. }
  3482. // ray origin is behind the plane (and is pointing behind it)
  3483. return false;
  3484. }
  3485. intersectBox( box, target ) {
  3486. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  3487. const invdirx = 1 / this.direction.x,
  3488. invdiry = 1 / this.direction.y,
  3489. invdirz = 1 / this.direction.z;
  3490. const origin = this.origin;
  3491. if ( invdirx >= 0 ) {
  3492. tmin = ( box.min.x - origin.x ) * invdirx;
  3493. tmax = ( box.max.x - origin.x ) * invdirx;
  3494. } else {
  3495. tmin = ( box.max.x - origin.x ) * invdirx;
  3496. tmax = ( box.min.x - origin.x ) * invdirx;
  3497. }
  3498. if ( invdiry >= 0 ) {
  3499. tymin = ( box.min.y - origin.y ) * invdiry;
  3500. tymax = ( box.max.y - origin.y ) * invdiry;
  3501. } else {
  3502. tymin = ( box.max.y - origin.y ) * invdiry;
  3503. tymax = ( box.min.y - origin.y ) * invdiry;
  3504. }
  3505. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3506. if ( tymin > tmin || isNaN( tmin ) ) tmin = tymin;
  3507. if ( tymax < tmax || isNaN( tmax ) ) tmax = tymax;
  3508. if ( invdirz >= 0 ) {
  3509. tzmin = ( box.min.z - origin.z ) * invdirz;
  3510. tzmax = ( box.max.z - origin.z ) * invdirz;
  3511. } else {
  3512. tzmin = ( box.max.z - origin.z ) * invdirz;
  3513. tzmax = ( box.min.z - origin.z ) * invdirz;
  3514. }
  3515. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3516. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3517. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3518. //return point closest to the ray (positive side)
  3519. if ( tmax < 0 ) return null;
  3520. return this.at( tmin >= 0 ? tmin : tmax, target );
  3521. }
  3522. intersectsBox( box ) {
  3523. return this.intersectBox( box, _vector$a ) !== null;
  3524. }
  3525. intersectTriangle( a, b, c, backfaceCulling, target ) {
  3526. // Compute the offset origin, edges, and normal.
  3527. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3528. _edge1.subVectors( b, a );
  3529. _edge2.subVectors( c, a );
  3530. _normal$1.crossVectors( _edge1, _edge2 );
  3531. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3532. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3533. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3534. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3535. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3536. let DdN = this.direction.dot( _normal$1 );
  3537. let sign;
  3538. if ( DdN > 0 ) {
  3539. if ( backfaceCulling ) return null;
  3540. sign = 1;
  3541. } else if ( DdN < 0 ) {
  3542. sign = -1;
  3543. DdN = - DdN;
  3544. } else {
  3545. return null;
  3546. }
  3547. _diff.subVectors( this.origin, a );
  3548. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3549. // b1 < 0, no intersection
  3550. if ( DdQxE2 < 0 ) {
  3551. return null;
  3552. }
  3553. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3554. // b2 < 0, no intersection
  3555. if ( DdE1xQ < 0 ) {
  3556. return null;
  3557. }
  3558. // b1+b2 > 1, no intersection
  3559. if ( DdQxE2 + DdE1xQ > DdN ) {
  3560. return null;
  3561. }
  3562. // Line intersects triangle, check if ray does.
  3563. const QdN = - sign * _diff.dot( _normal$1 );
  3564. // t < 0, no intersection
  3565. if ( QdN < 0 ) {
  3566. return null;
  3567. }
  3568. // Ray intersects triangle.
  3569. return this.at( QdN / DdN, target );
  3570. }
  3571. applyMatrix4( matrix4 ) {
  3572. this.origin.applyMatrix4( matrix4 );
  3573. this.direction.transformDirection( matrix4 );
  3574. return this;
  3575. }
  3576. equals( ray ) {
  3577. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3578. }
  3579. clone() {
  3580. return new this.constructor().copy( this );
  3581. }
  3582. }
  3583. class Matrix4 {
  3584. constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3585. Matrix4.prototype.isMatrix4 = true;
  3586. this.elements = [
  3587. 1, 0, 0, 0,
  3588. 0, 1, 0, 0,
  3589. 0, 0, 1, 0,
  3590. 0, 0, 0, 1
  3591. ];
  3592. if ( n11 !== undefined ) {
  3593. this.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 );
  3594. }
  3595. }
  3596. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3597. const te = this.elements;
  3598. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3599. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3600. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3601. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3602. return this;
  3603. }
  3604. identity() {
  3605. this.set(
  3606. 1, 0, 0, 0,
  3607. 0, 1, 0, 0,
  3608. 0, 0, 1, 0,
  3609. 0, 0, 0, 1
  3610. );
  3611. return this;
  3612. }
  3613. clone() {
  3614. return new Matrix4().fromArray( this.elements );
  3615. }
  3616. copy( m ) {
  3617. const te = this.elements;
  3618. const me = m.elements;
  3619. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3620. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3621. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3622. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3623. return this;
  3624. }
  3625. copyPosition( m ) {
  3626. const te = this.elements, me = m.elements;
  3627. te[ 12 ] = me[ 12 ];
  3628. te[ 13 ] = me[ 13 ];
  3629. te[ 14 ] = me[ 14 ];
  3630. return this;
  3631. }
  3632. setFromMatrix3( m ) {
  3633. const me = m.elements;
  3634. this.set(
  3635. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3636. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3637. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3638. 0, 0, 0, 1
  3639. );
  3640. return this;
  3641. }
  3642. extractBasis( xAxis, yAxis, zAxis ) {
  3643. xAxis.setFromMatrixColumn( this, 0 );
  3644. yAxis.setFromMatrixColumn( this, 1 );
  3645. zAxis.setFromMatrixColumn( this, 2 );
  3646. return this;
  3647. }
  3648. makeBasis( xAxis, yAxis, zAxis ) {
  3649. this.set(
  3650. xAxis.x, yAxis.x, zAxis.x, 0,
  3651. xAxis.y, yAxis.y, zAxis.y, 0,
  3652. xAxis.z, yAxis.z, zAxis.z, 0,
  3653. 0, 0, 0, 1
  3654. );
  3655. return this;
  3656. }
  3657. extractRotation( m ) {
  3658. // this method does not support reflection matrices
  3659. const te = this.elements;
  3660. const me = m.elements;
  3661. const scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length();
  3662. const scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length();
  3663. const scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length();
  3664. te[ 0 ] = me[ 0 ] * scaleX;
  3665. te[ 1 ] = me[ 1 ] * scaleX;
  3666. te[ 2 ] = me[ 2 ] * scaleX;
  3667. te[ 3 ] = 0;
  3668. te[ 4 ] = me[ 4 ] * scaleY;
  3669. te[ 5 ] = me[ 5 ] * scaleY;
  3670. te[ 6 ] = me[ 6 ] * scaleY;
  3671. te[ 7 ] = 0;
  3672. te[ 8 ] = me[ 8 ] * scaleZ;
  3673. te[ 9 ] = me[ 9 ] * scaleZ;
  3674. te[ 10 ] = me[ 10 ] * scaleZ;
  3675. te[ 11 ] = 0;
  3676. te[ 12 ] = 0;
  3677. te[ 13 ] = 0;
  3678. te[ 14 ] = 0;
  3679. te[ 15 ] = 1;
  3680. return this;
  3681. }
  3682. makeRotationFromEuler( euler ) {
  3683. const te = this.elements;
  3684. const x = euler.x, y = euler.y, z = euler.z;
  3685. const a = Math.cos( x ), b = Math.sin( x );
  3686. const c = Math.cos( y ), d = Math.sin( y );
  3687. const e = Math.cos( z ), f = Math.sin( z );
  3688. if ( euler.order === 'XYZ' ) {
  3689. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3690. te[ 0 ] = c * e;
  3691. te[ 4 ] = - c * f;
  3692. te[ 8 ] = d;
  3693. te[ 1 ] = af + be * d;
  3694. te[ 5 ] = ae - bf * d;
  3695. te[ 9 ] = - b * c;
  3696. te[ 2 ] = bf - ae * d;
  3697. te[ 6 ] = be + af * d;
  3698. te[ 10 ] = a * c;
  3699. } else if ( euler.order === 'YXZ' ) {
  3700. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3701. te[ 0 ] = ce + df * b;
  3702. te[ 4 ] = de * b - cf;
  3703. te[ 8 ] = a * d;
  3704. te[ 1 ] = a * f;
  3705. te[ 5 ] = a * e;
  3706. te[ 9 ] = - b;
  3707. te[ 2 ] = cf * b - de;
  3708. te[ 6 ] = df + ce * b;
  3709. te[ 10 ] = a * c;
  3710. } else if ( euler.order === 'ZXY' ) {
  3711. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3712. te[ 0 ] = ce - df * b;
  3713. te[ 4 ] = - a * f;
  3714. te[ 8 ] = de + cf * b;
  3715. te[ 1 ] = cf + de * b;
  3716. te[ 5 ] = a * e;
  3717. te[ 9 ] = df - ce * b;
  3718. te[ 2 ] = - a * d;
  3719. te[ 6 ] = b;
  3720. te[ 10 ] = a * c;
  3721. } else if ( euler.order === 'ZYX' ) {
  3722. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3723. te[ 0 ] = c * e;
  3724. te[ 4 ] = be * d - af;
  3725. te[ 8 ] = ae * d + bf;
  3726. te[ 1 ] = c * f;
  3727. te[ 5 ] = bf * d + ae;
  3728. te[ 9 ] = af * d - be;
  3729. te[ 2 ] = - d;
  3730. te[ 6 ] = b * c;
  3731. te[ 10 ] = a * c;
  3732. } else if ( euler.order === 'YZX' ) {
  3733. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3734. te[ 0 ] = c * e;
  3735. te[ 4 ] = bd - ac * f;
  3736. te[ 8 ] = bc * f + ad;
  3737. te[ 1 ] = f;
  3738. te[ 5 ] = a * e;
  3739. te[ 9 ] = - b * e;
  3740. te[ 2 ] = - d * e;
  3741. te[ 6 ] = ad * f + bc;
  3742. te[ 10 ] = ac - bd * f;
  3743. } else if ( euler.order === 'XZY' ) {
  3744. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3745. te[ 0 ] = c * e;
  3746. te[ 4 ] = - f;
  3747. te[ 8 ] = d * e;
  3748. te[ 1 ] = ac * f + bd;
  3749. te[ 5 ] = a * e;
  3750. te[ 9 ] = ad * f - bc;
  3751. te[ 2 ] = bc * f - ad;
  3752. te[ 6 ] = b * e;
  3753. te[ 10 ] = bd * f + ac;
  3754. }
  3755. // bottom row
  3756. te[ 3 ] = 0;
  3757. te[ 7 ] = 0;
  3758. te[ 11 ] = 0;
  3759. // last column
  3760. te[ 12 ] = 0;
  3761. te[ 13 ] = 0;
  3762. te[ 14 ] = 0;
  3763. te[ 15 ] = 1;
  3764. return this;
  3765. }
  3766. makeRotationFromQuaternion( q ) {
  3767. return this.compose( _zero, q, _one );
  3768. }
  3769. lookAt( eye, target, up ) {
  3770. const te = this.elements;
  3771. _z.subVectors( eye, target );
  3772. if ( _z.lengthSq() === 0 ) {
  3773. // eye and target are in the same position
  3774. _z.z = 1;
  3775. }
  3776. _z.normalize();
  3777. _x.crossVectors( up, _z );
  3778. if ( _x.lengthSq() === 0 ) {
  3779. // up and z are parallel
  3780. if ( Math.abs( up.z ) === 1 ) {
  3781. _z.x += 0.0001;
  3782. } else {
  3783. _z.z += 0.0001;
  3784. }
  3785. _z.normalize();
  3786. _x.crossVectors( up, _z );
  3787. }
  3788. _x.normalize();
  3789. _y.crossVectors( _z, _x );
  3790. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3791. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3792. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3793. return this;
  3794. }
  3795. multiply( m ) {
  3796. return this.multiplyMatrices( this, m );
  3797. }
  3798. premultiply( m ) {
  3799. return this.multiplyMatrices( m, this );
  3800. }
  3801. multiplyMatrices( a, b ) {
  3802. const ae = a.elements;
  3803. const be = b.elements;
  3804. const te = this.elements;
  3805. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3806. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3807. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3808. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3809. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3810. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3811. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3812. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3813. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3814. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3815. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3816. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3817. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3818. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3819. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3820. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3821. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3822. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3823. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3824. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3825. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3826. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3827. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3828. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3829. return this;
  3830. }
  3831. multiplyScalar( s ) {
  3832. const te = this.elements;
  3833. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3834. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3835. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3836. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3837. return this;
  3838. }
  3839. determinant() {
  3840. const te = this.elements;
  3841. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3842. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3843. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3844. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3845. //TODO: make this more efficient
  3846. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3847. return (
  3848. n41 * (
  3849. + n14 * n23 * n32
  3850. - n13 * n24 * n32
  3851. - n14 * n22 * n33
  3852. + n12 * n24 * n33
  3853. + n13 * n22 * n34
  3854. - n12 * n23 * n34
  3855. ) +
  3856. n42 * (
  3857. + n11 * n23 * n34
  3858. - n11 * n24 * n33
  3859. + n14 * n21 * n33
  3860. - n13 * n21 * n34
  3861. + n13 * n24 * n31
  3862. - n14 * n23 * n31
  3863. ) +
  3864. n43 * (
  3865. + n11 * n24 * n32
  3866. - n11 * n22 * n34
  3867. - n14 * n21 * n32
  3868. + n12 * n21 * n34
  3869. + n14 * n22 * n31
  3870. - n12 * n24 * n31
  3871. ) +
  3872. n44 * (
  3873. - n13 * n22 * n31
  3874. - n11 * n23 * n32
  3875. + n11 * n22 * n33
  3876. + n13 * n21 * n32
  3877. - n12 * n21 * n33
  3878. + n12 * n23 * n31
  3879. )
  3880. );
  3881. }
  3882. transpose() {
  3883. const te = this.elements;
  3884. let tmp;
  3885. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3886. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3887. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3888. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3889. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3890. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3891. return this;
  3892. }
  3893. setPosition( x, y, z ) {
  3894. const te = this.elements;
  3895. if ( x.isVector3 ) {
  3896. te[ 12 ] = x.x;
  3897. te[ 13 ] = x.y;
  3898. te[ 14 ] = x.z;
  3899. } else {
  3900. te[ 12 ] = x;
  3901. te[ 13 ] = y;
  3902. te[ 14 ] = z;
  3903. }
  3904. return this;
  3905. }
  3906. invert() {
  3907. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3908. const te = this.elements,
  3909. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3910. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3911. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3912. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3913. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3914. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3915. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3916. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3917. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3918. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3919. const detInv = 1 / det;
  3920. te[ 0 ] = t11 * detInv;
  3921. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3922. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3923. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3924. te[ 4 ] = t12 * detInv;
  3925. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3926. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3927. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3928. te[ 8 ] = t13 * detInv;
  3929. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3930. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3931. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3932. te[ 12 ] = t14 * detInv;
  3933. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3934. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3935. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3936. return this;
  3937. }
  3938. scale( v ) {
  3939. const te = this.elements;
  3940. const x = v.x, y = v.y, z = v.z;
  3941. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3942. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3943. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3944. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3945. return this;
  3946. }
  3947. getMaxScaleOnAxis() {
  3948. const te = this.elements;
  3949. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3950. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3951. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3952. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3953. }
  3954. makeTranslation( x, y, z ) {
  3955. if ( x.isVector3 ) {
  3956. this.set(
  3957. 1, 0, 0, x.x,
  3958. 0, 1, 0, x.y,
  3959. 0, 0, 1, x.z,
  3960. 0, 0, 0, 1
  3961. );
  3962. } else {
  3963. this.set(
  3964. 1, 0, 0, x,
  3965. 0, 1, 0, y,
  3966. 0, 0, 1, z,
  3967. 0, 0, 0, 1
  3968. );
  3969. }
  3970. return this;
  3971. }
  3972. makeRotationX( theta ) {
  3973. const c = Math.cos( theta ), s = Math.sin( theta );
  3974. this.set(
  3975. 1, 0, 0, 0,
  3976. 0, c, - s, 0,
  3977. 0, s, c, 0,
  3978. 0, 0, 0, 1
  3979. );
  3980. return this;
  3981. }
  3982. makeRotationY( theta ) {
  3983. const c = Math.cos( theta ), s = Math.sin( theta );
  3984. this.set(
  3985. c, 0, s, 0,
  3986. 0, 1, 0, 0,
  3987. - s, 0, c, 0,
  3988. 0, 0, 0, 1
  3989. );
  3990. return this;
  3991. }
  3992. makeRotationZ( theta ) {
  3993. const c = Math.cos( theta ), s = Math.sin( theta );
  3994. this.set(
  3995. c, - s, 0, 0,
  3996. s, c, 0, 0,
  3997. 0, 0, 1, 0,
  3998. 0, 0, 0, 1
  3999. );
  4000. return this;
  4001. }
  4002. makeRotationAxis( axis, angle ) {
  4003. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4004. const c = Math.cos( angle );
  4005. const s = Math.sin( angle );
  4006. const t = 1 - c;
  4007. const x = axis.x, y = axis.y, z = axis.z;
  4008. const tx = t * x, ty = t * y;
  4009. this.set(
  4010. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  4011. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  4012. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  4013. 0, 0, 0, 1
  4014. );
  4015. return this;
  4016. }
  4017. makeScale( x, y, z ) {
  4018. this.set(
  4019. x, 0, 0, 0,
  4020. 0, y, 0, 0,
  4021. 0, 0, z, 0,
  4022. 0, 0, 0, 1
  4023. );
  4024. return this;
  4025. }
  4026. makeShear( xy, xz, yx, yz, zx, zy ) {
  4027. this.set(
  4028. 1, yx, zx, 0,
  4029. xy, 1, zy, 0,
  4030. xz, yz, 1, 0,
  4031. 0, 0, 0, 1
  4032. );
  4033. return this;
  4034. }
  4035. compose( position, quaternion, scale ) {
  4036. const te = this.elements;
  4037. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  4038. const x2 = x + x, y2 = y + y, z2 = z + z;
  4039. const xx = x * x2, xy = x * y2, xz = x * z2;
  4040. const yy = y * y2, yz = y * z2, zz = z * z2;
  4041. const wx = w * x2, wy = w * y2, wz = w * z2;
  4042. const sx = scale.x, sy = scale.y, sz = scale.z;
  4043. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  4044. te[ 1 ] = ( xy + wz ) * sx;
  4045. te[ 2 ] = ( xz - wy ) * sx;
  4046. te[ 3 ] = 0;
  4047. te[ 4 ] = ( xy - wz ) * sy;
  4048. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  4049. te[ 6 ] = ( yz + wx ) * sy;
  4050. te[ 7 ] = 0;
  4051. te[ 8 ] = ( xz + wy ) * sz;
  4052. te[ 9 ] = ( yz - wx ) * sz;
  4053. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  4054. te[ 11 ] = 0;
  4055. te[ 12 ] = position.x;
  4056. te[ 13 ] = position.y;
  4057. te[ 14 ] = position.z;
  4058. te[ 15 ] = 1;
  4059. return this;
  4060. }
  4061. decompose( position, quaternion, scale ) {
  4062. const te = this.elements;
  4063. let sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  4064. const sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  4065. const sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  4066. // if determine is negative, we need to invert one scale
  4067. const det = this.determinant();
  4068. if ( det < 0 ) sx = - sx;
  4069. position.x = te[ 12 ];
  4070. position.y = te[ 13 ];
  4071. position.z = te[ 14 ];
  4072. // scale the rotation part
  4073. _m1$2.copy( this );
  4074. const invSX = 1 / sx;
  4075. const invSY = 1 / sy;
  4076. const invSZ = 1 / sz;
  4077. _m1$2.elements[ 0 ] *= invSX;
  4078. _m1$2.elements[ 1 ] *= invSX;
  4079. _m1$2.elements[ 2 ] *= invSX;
  4080. _m1$2.elements[ 4 ] *= invSY;
  4081. _m1$2.elements[ 5 ] *= invSY;
  4082. _m1$2.elements[ 6 ] *= invSY;
  4083. _m1$2.elements[ 8 ] *= invSZ;
  4084. _m1$2.elements[ 9 ] *= invSZ;
  4085. _m1$2.elements[ 10 ] *= invSZ;
  4086. quaternion.setFromRotationMatrix( _m1$2 );
  4087. scale.x = sx;
  4088. scale.y = sy;
  4089. scale.z = sz;
  4090. return this;
  4091. }
  4092. makePerspective( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4093. const te = this.elements;
  4094. const x = 2 * near / ( right - left );
  4095. const y = 2 * near / ( top - bottom );
  4096. const a = ( right + left ) / ( right - left );
  4097. const b = ( top + bottom ) / ( top - bottom );
  4098. let c, d;
  4099. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4100. c = - ( far + near ) / ( far - near );
  4101. d = ( -2 * far * near ) / ( far - near );
  4102. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4103. c = - far / ( far - near );
  4104. d = ( - far * near ) / ( far - near );
  4105. } else {
  4106. throw new Error( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem );
  4107. }
  4108. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  4109. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  4110. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  4111. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = -1; te[ 15 ] = 0;
  4112. return this;
  4113. }
  4114. makeOrthographic( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4115. const te = this.elements;
  4116. const w = 1.0 / ( right - left );
  4117. const h = 1.0 / ( top - bottom );
  4118. const p = 1.0 / ( far - near );
  4119. const x = ( right + left ) * w;
  4120. const y = ( top + bottom ) * h;
  4121. let z, zInv;
  4122. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4123. z = ( far + near ) * p;
  4124. zInv = -2 * p;
  4125. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4126. z = near * p;
  4127. zInv = -1 * p;
  4128. } else {
  4129. throw new Error( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem );
  4130. }
  4131. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  4132. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  4133. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = zInv; te[ 14 ] = - z;
  4134. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  4135. return this;
  4136. }
  4137. equals( matrix ) {
  4138. const te = this.elements;
  4139. const me = matrix.elements;
  4140. for ( let i = 0; i < 16; i ++ ) {
  4141. if ( te[ i ] !== me[ i ] ) return false;
  4142. }
  4143. return true;
  4144. }
  4145. fromArray( array, offset = 0 ) {
  4146. for ( let i = 0; i < 16; i ++ ) {
  4147. this.elements[ i ] = array[ i + offset ];
  4148. }
  4149. return this;
  4150. }
  4151. toArray( array = [], offset = 0 ) {
  4152. const te = this.elements;
  4153. array[ offset ] = te[ 0 ];
  4154. array[ offset + 1 ] = te[ 1 ];
  4155. array[ offset + 2 ] = te[ 2 ];
  4156. array[ offset + 3 ] = te[ 3 ];
  4157. array[ offset + 4 ] = te[ 4 ];
  4158. array[ offset + 5 ] = te[ 5 ];
  4159. array[ offset + 6 ] = te[ 6 ];
  4160. array[ offset + 7 ] = te[ 7 ];
  4161. array[ offset + 8 ] = te[ 8 ];
  4162. array[ offset + 9 ] = te[ 9 ];
  4163. array[ offset + 10 ] = te[ 10 ];
  4164. array[ offset + 11 ] = te[ 11 ];
  4165. array[ offset + 12 ] = te[ 12 ];
  4166. array[ offset + 13 ] = te[ 13 ];
  4167. array[ offset + 14 ] = te[ 14 ];
  4168. array[ offset + 15 ] = te[ 15 ];
  4169. return array;
  4170. }
  4171. }
  4172. const _v1$5 = /*@__PURE__*/ new Vector3();
  4173. const _m1$2 = /*@__PURE__*/ new Matrix4();
  4174. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  4175. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  4176. const _x = /*@__PURE__*/ new Vector3();
  4177. const _y = /*@__PURE__*/ new Vector3();
  4178. const _z = /*@__PURE__*/ new Vector3();
  4179. const _matrix$2 = /*@__PURE__*/ new Matrix4();
  4180. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  4181. class Euler {
  4182. constructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) {
  4183. this.isEuler = true;
  4184. this._x = x;
  4185. this._y = y;
  4186. this._z = z;
  4187. this._order = order;
  4188. }
  4189. get x() {
  4190. return this._x;
  4191. }
  4192. set x( value ) {
  4193. this._x = value;
  4194. this._onChangeCallback();
  4195. }
  4196. get y() {
  4197. return this._y;
  4198. }
  4199. set y( value ) {
  4200. this._y = value;
  4201. this._onChangeCallback();
  4202. }
  4203. get z() {
  4204. return this._z;
  4205. }
  4206. set z( value ) {
  4207. this._z = value;
  4208. this._onChangeCallback();
  4209. }
  4210. get order() {
  4211. return this._order;
  4212. }
  4213. set order( value ) {
  4214. this._order = value;
  4215. this._onChangeCallback();
  4216. }
  4217. set( x, y, z, order = this._order ) {
  4218. this._x = x;
  4219. this._y = y;
  4220. this._z = z;
  4221. this._order = order;
  4222. this._onChangeCallback();
  4223. return this;
  4224. }
  4225. clone() {
  4226. return new this.constructor( this._x, this._y, this._z, this._order );
  4227. }
  4228. copy( euler ) {
  4229. this._x = euler._x;
  4230. this._y = euler._y;
  4231. this._z = euler._z;
  4232. this._order = euler._order;
  4233. this._onChangeCallback();
  4234. return this;
  4235. }
  4236. setFromRotationMatrix( m, order = this._order, update = true ) {
  4237. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4238. const te = m.elements;
  4239. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4240. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4241. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4242. switch ( order ) {
  4243. case 'XYZ':
  4244. this._y = Math.asin( clamp( m13, -1, 1 ) );
  4245. if ( Math.abs( m13 ) < 0.9999999 ) {
  4246. this._x = Math.atan2( - m23, m33 );
  4247. this._z = Math.atan2( - m12, m11 );
  4248. } else {
  4249. this._x = Math.atan2( m32, m22 );
  4250. this._z = 0;
  4251. }
  4252. break;
  4253. case 'YXZ':
  4254. this._x = Math.asin( - clamp( m23, -1, 1 ) );
  4255. if ( Math.abs( m23 ) < 0.9999999 ) {
  4256. this._y = Math.atan2( m13, m33 );
  4257. this._z = Math.atan2( m21, m22 );
  4258. } else {
  4259. this._y = Math.atan2( - m31, m11 );
  4260. this._z = 0;
  4261. }
  4262. break;
  4263. case 'ZXY':
  4264. this._x = Math.asin( clamp( m32, -1, 1 ) );
  4265. if ( Math.abs( m32 ) < 0.9999999 ) {
  4266. this._y = Math.atan2( - m31, m33 );
  4267. this._z = Math.atan2( - m12, m22 );
  4268. } else {
  4269. this._y = 0;
  4270. this._z = Math.atan2( m21, m11 );
  4271. }
  4272. break;
  4273. case 'ZYX':
  4274. this._y = Math.asin( - clamp( m31, -1, 1 ) );
  4275. if ( Math.abs( m31 ) < 0.9999999 ) {
  4276. this._x = Math.atan2( m32, m33 );
  4277. this._z = Math.atan2( m21, m11 );
  4278. } else {
  4279. this._x = 0;
  4280. this._z = Math.atan2( - m12, m22 );
  4281. }
  4282. break;
  4283. case 'YZX':
  4284. this._z = Math.asin( clamp( m21, -1, 1 ) );
  4285. if ( Math.abs( m21 ) < 0.9999999 ) {
  4286. this._x = Math.atan2( - m23, m22 );
  4287. this._y = Math.atan2( - m31, m11 );
  4288. } else {
  4289. this._x = 0;
  4290. this._y = Math.atan2( m13, m33 );
  4291. }
  4292. break;
  4293. case 'XZY':
  4294. this._z = Math.asin( - clamp( m12, -1, 1 ) );
  4295. if ( Math.abs( m12 ) < 0.9999999 ) {
  4296. this._x = Math.atan2( m32, m22 );
  4297. this._y = Math.atan2( m13, m11 );
  4298. } else {
  4299. this._x = Math.atan2( - m23, m33 );
  4300. this._y = 0;
  4301. }
  4302. break;
  4303. default:
  4304. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  4305. }
  4306. this._order = order;
  4307. if ( update === true ) this._onChangeCallback();
  4308. return this;
  4309. }
  4310. setFromQuaternion( q, order, update ) {
  4311. _matrix$2.makeRotationFromQuaternion( q );
  4312. return this.setFromRotationMatrix( _matrix$2, order, update );
  4313. }
  4314. setFromVector3( v, order = this._order ) {
  4315. return this.set( v.x, v.y, v.z, order );
  4316. }
  4317. reorder( newOrder ) {
  4318. // WARNING: this discards revolution information -bhouston
  4319. _quaternion$3.setFromEuler( this );
  4320. return this.setFromQuaternion( _quaternion$3, newOrder );
  4321. }
  4322. equals( euler ) {
  4323. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4324. }
  4325. fromArray( array ) {
  4326. this._x = array[ 0 ];
  4327. this._y = array[ 1 ];
  4328. this._z = array[ 2 ];
  4329. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4330. this._onChangeCallback();
  4331. return this;
  4332. }
  4333. toArray( array = [], offset = 0 ) {
  4334. array[ offset ] = this._x;
  4335. array[ offset + 1 ] = this._y;
  4336. array[ offset + 2 ] = this._z;
  4337. array[ offset + 3 ] = this._order;
  4338. return array;
  4339. }
  4340. _onChange( callback ) {
  4341. this._onChangeCallback = callback;
  4342. return this;
  4343. }
  4344. _onChangeCallback() {}
  4345. *[ Symbol.iterator ]() {
  4346. yield this._x;
  4347. yield this._y;
  4348. yield this._z;
  4349. yield this._order;
  4350. }
  4351. }
  4352. Euler.DEFAULT_ORDER = 'XYZ';
  4353. class Layers {
  4354. constructor() {
  4355. this.mask = 1 | 0;
  4356. }
  4357. set( channel ) {
  4358. this.mask = ( 1 << channel | 0 ) >>> 0;
  4359. }
  4360. enable( channel ) {
  4361. this.mask |= 1 << channel | 0;
  4362. }
  4363. enableAll() {
  4364. this.mask = 0xffffffff | 0;
  4365. }
  4366. toggle( channel ) {
  4367. this.mask ^= 1 << channel | 0;
  4368. }
  4369. disable( channel ) {
  4370. this.mask &= ~ ( 1 << channel | 0 );
  4371. }
  4372. disableAll() {
  4373. this.mask = 0;
  4374. }
  4375. test( layers ) {
  4376. return ( this.mask & layers.mask ) !== 0;
  4377. }
  4378. isEnabled( channel ) {
  4379. return ( this.mask & ( 1 << channel | 0 ) ) !== 0;
  4380. }
  4381. }
  4382. let _object3DId = 0;
  4383. const _v1$4 = /*@__PURE__*/ new Vector3();
  4384. const _q1 = /*@__PURE__*/ new Quaternion();
  4385. const _m1$1 = /*@__PURE__*/ new Matrix4();
  4386. const _target = /*@__PURE__*/ new Vector3();
  4387. const _position$3 = /*@__PURE__*/ new Vector3();
  4388. const _scale$2 = /*@__PURE__*/ new Vector3();
  4389. const _quaternion$2 = /*@__PURE__*/ new Quaternion();
  4390. const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );
  4391. const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4392. const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
  4393. const _addedEvent = { type: 'added' };
  4394. const _removedEvent = { type: 'removed' };
  4395. const _childaddedEvent = { type: 'childadded', child: null };
  4396. const _childremovedEvent = { type: 'childremoved', child: null };
  4397. class Object3D extends EventDispatcher {
  4398. constructor() {
  4399. super();
  4400. this.isObject3D = true;
  4401. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  4402. this.uuid = generateUUID();
  4403. this.name = '';
  4404. this.type = 'Object3D';
  4405. this.parent = null;
  4406. this.children = [];
  4407. this.up = Object3D.DEFAULT_UP.clone();
  4408. const position = new Vector3();
  4409. const rotation = new Euler();
  4410. const quaternion = new Quaternion();
  4411. const scale = new Vector3( 1, 1, 1 );
  4412. function onRotationChange() {
  4413. quaternion.setFromEuler( rotation, false );
  4414. }
  4415. function onQuaternionChange() {
  4416. rotation.setFromQuaternion( quaternion, undefined, false );
  4417. }
  4418. rotation._onChange( onRotationChange );
  4419. quaternion._onChange( onQuaternionChange );
  4420. Object.defineProperties( this, {
  4421. position: {
  4422. configurable: true,
  4423. enumerable: true,
  4424. value: position
  4425. },
  4426. rotation: {
  4427. configurable: true,
  4428. enumerable: true,
  4429. value: rotation
  4430. },
  4431. quaternion: {
  4432. configurable: true,
  4433. enumerable: true,
  4434. value: quaternion
  4435. },
  4436. scale: {
  4437. configurable: true,
  4438. enumerable: true,
  4439. value: scale
  4440. },
  4441. modelViewMatrix: {
  4442. value: new Matrix4()
  4443. },
  4444. normalMatrix: {
  4445. value: new Matrix3()
  4446. }
  4447. } );
  4448. this.matrix = new Matrix4();
  4449. this.matrixWorld = new Matrix4();
  4450. this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
  4451. this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
  4452. this.matrixWorldNeedsUpdate = false;
  4453. this.layers = new Layers();
  4454. this.visible = true;
  4455. this.castShadow = false;
  4456. this.receiveShadow = false;
  4457. this.frustumCulled = true;
  4458. this.renderOrder = 0;
  4459. this.animations = [];
  4460. this.userData = {};
  4461. }
  4462. onBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4463. onAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4464. onBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4465. onAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4466. applyMatrix4( matrix ) {
  4467. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4468. this.matrix.premultiply( matrix );
  4469. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4470. }
  4471. applyQuaternion( q ) {
  4472. this.quaternion.premultiply( q );
  4473. return this;
  4474. }
  4475. setRotationFromAxisAngle( axis, angle ) {
  4476. // assumes axis is normalized
  4477. this.quaternion.setFromAxisAngle( axis, angle );
  4478. }
  4479. setRotationFromEuler( euler ) {
  4480. this.quaternion.setFromEuler( euler, true );
  4481. }
  4482. setRotationFromMatrix( m ) {
  4483. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4484. this.quaternion.setFromRotationMatrix( m );
  4485. }
  4486. setRotationFromQuaternion( q ) {
  4487. // assumes q is normalized
  4488. this.quaternion.copy( q );
  4489. }
  4490. rotateOnAxis( axis, angle ) {
  4491. // rotate object on axis in object space
  4492. // axis is assumed to be normalized
  4493. _q1.setFromAxisAngle( axis, angle );
  4494. this.quaternion.multiply( _q1 );
  4495. return this;
  4496. }
  4497. rotateOnWorldAxis( axis, angle ) {
  4498. // rotate object on axis in world space
  4499. // axis is assumed to be normalized
  4500. // method assumes no rotated parent
  4501. _q1.setFromAxisAngle( axis, angle );
  4502. this.quaternion.premultiply( _q1 );
  4503. return this;
  4504. }
  4505. rotateX( angle ) {
  4506. return this.rotateOnAxis( _xAxis, angle );
  4507. }
  4508. rotateY( angle ) {
  4509. return this.rotateOnAxis( _yAxis, angle );
  4510. }
  4511. rotateZ( angle ) {
  4512. return this.rotateOnAxis( _zAxis, angle );
  4513. }
  4514. translateOnAxis( axis, distance ) {
  4515. // translate object by distance along axis in object space
  4516. // axis is assumed to be normalized
  4517. _v1$4.copy( axis ).applyQuaternion( this.quaternion );
  4518. this.position.add( _v1$4.multiplyScalar( distance ) );
  4519. return this;
  4520. }
  4521. translateX( distance ) {
  4522. return this.translateOnAxis( _xAxis, distance );
  4523. }
  4524. translateY( distance ) {
  4525. return this.translateOnAxis( _yAxis, distance );
  4526. }
  4527. translateZ( distance ) {
  4528. return this.translateOnAxis( _zAxis, distance );
  4529. }
  4530. localToWorld( vector ) {
  4531. this.updateWorldMatrix( true, false );
  4532. return vector.applyMatrix4( this.matrixWorld );
  4533. }
  4534. worldToLocal( vector ) {
  4535. this.updateWorldMatrix( true, false );
  4536. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  4537. }
  4538. lookAt( x, y, z ) {
  4539. // This method does not support objects having non-uniformly-scaled parent(s)
  4540. if ( x.isVector3 ) {
  4541. _target.copy( x );
  4542. } else {
  4543. _target.set( x, y, z );
  4544. }
  4545. const parent = this.parent;
  4546. this.updateWorldMatrix( true, false );
  4547. _position$3.setFromMatrixPosition( this.matrixWorld );
  4548. if ( this.isCamera || this.isLight ) {
  4549. _m1$1.lookAt( _position$3, _target, this.up );
  4550. } else {
  4551. _m1$1.lookAt( _target, _position$3, this.up );
  4552. }
  4553. this.quaternion.setFromRotationMatrix( _m1$1 );
  4554. if ( parent ) {
  4555. _m1$1.extractRotation( parent.matrixWorld );
  4556. _q1.setFromRotationMatrix( _m1$1 );
  4557. this.quaternion.premultiply( _q1.invert() );
  4558. }
  4559. }
  4560. add( object ) {
  4561. if ( arguments.length > 1 ) {
  4562. for ( let i = 0; i < arguments.length; i ++ ) {
  4563. this.add( arguments[ i ] );
  4564. }
  4565. return this;
  4566. }
  4567. if ( object === this ) {
  4568. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4569. return this;
  4570. }
  4571. if ( object && object.isObject3D ) {
  4572. object.removeFromParent();
  4573. object.parent = this;
  4574. this.children.push( object );
  4575. object.dispatchEvent( _addedEvent );
  4576. _childaddedEvent.child = object;
  4577. this.dispatchEvent( _childaddedEvent );
  4578. _childaddedEvent.child = null;
  4579. } else {
  4580. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4581. }
  4582. return this;
  4583. }
  4584. remove( object ) {
  4585. if ( arguments.length > 1 ) {
  4586. for ( let i = 0; i < arguments.length; i ++ ) {
  4587. this.remove( arguments[ i ] );
  4588. }
  4589. return this;
  4590. }
  4591. const index = this.children.indexOf( object );
  4592. if ( index !== -1 ) {
  4593. object.parent = null;
  4594. this.children.splice( index, 1 );
  4595. object.dispatchEvent( _removedEvent );
  4596. _childremovedEvent.child = object;
  4597. this.dispatchEvent( _childremovedEvent );
  4598. _childremovedEvent.child = null;
  4599. }
  4600. return this;
  4601. }
  4602. removeFromParent() {
  4603. const parent = this.parent;
  4604. if ( parent !== null ) {
  4605. parent.remove( this );
  4606. }
  4607. return this;
  4608. }
  4609. clear() {
  4610. return this.remove( ... this.children );
  4611. }
  4612. attach( object ) {
  4613. // adds object as a child of this, while maintaining the object's world transform
  4614. // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
  4615. this.updateWorldMatrix( true, false );
  4616. _m1$1.copy( this.matrixWorld ).invert();
  4617. if ( object.parent !== null ) {
  4618. object.parent.updateWorldMatrix( true, false );
  4619. _m1$1.multiply( object.parent.matrixWorld );
  4620. }
  4621. object.applyMatrix4( _m1$1 );
  4622. object.removeFromParent();
  4623. object.parent = this;
  4624. this.children.push( object );
  4625. object.updateWorldMatrix( false, true );
  4626. object.dispatchEvent( _addedEvent );
  4627. _childaddedEvent.child = object;
  4628. this.dispatchEvent( _childaddedEvent );
  4629. _childaddedEvent.child = null;
  4630. return this;
  4631. }
  4632. getObjectById( id ) {
  4633. return this.getObjectByProperty( 'id', id );
  4634. }
  4635. getObjectByName( name ) {
  4636. return this.getObjectByProperty( 'name', name );
  4637. }
  4638. getObjectByProperty( name, value ) {
  4639. if ( this[ name ] === value ) return this;
  4640. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4641. const child = this.children[ i ];
  4642. const object = child.getObjectByProperty( name, value );
  4643. if ( object !== undefined ) {
  4644. return object;
  4645. }
  4646. }
  4647. return undefined;
  4648. }
  4649. getObjectsByProperty( name, value, result = [] ) {
  4650. if ( this[ name ] === value ) result.push( this );
  4651. const children = this.children;
  4652. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4653. children[ i ].getObjectsByProperty( name, value, result );
  4654. }
  4655. return result;
  4656. }
  4657. getWorldPosition( target ) {
  4658. this.updateWorldMatrix( true, false );
  4659. return target.setFromMatrixPosition( this.matrixWorld );
  4660. }
  4661. getWorldQuaternion( target ) {
  4662. this.updateWorldMatrix( true, false );
  4663. this.matrixWorld.decompose( _position$3, target, _scale$2 );
  4664. return target;
  4665. }
  4666. getWorldScale( target ) {
  4667. this.updateWorldMatrix( true, false );
  4668. this.matrixWorld.decompose( _position$3, _quaternion$2, target );
  4669. return target;
  4670. }
  4671. getWorldDirection( target ) {
  4672. this.updateWorldMatrix( true, false );
  4673. const e = this.matrixWorld.elements;
  4674. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4675. }
  4676. raycast( /* raycaster, intersects */ ) {}
  4677. traverse( callback ) {
  4678. callback( this );
  4679. const children = this.children;
  4680. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4681. children[ i ].traverse( callback );
  4682. }
  4683. }
  4684. traverseVisible( callback ) {
  4685. if ( this.visible === false ) return;
  4686. callback( this );
  4687. const children = this.children;
  4688. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4689. children[ i ].traverseVisible( callback );
  4690. }
  4691. }
  4692. traverseAncestors( callback ) {
  4693. const parent = this.parent;
  4694. if ( parent !== null ) {
  4695. callback( parent );
  4696. parent.traverseAncestors( callback );
  4697. }
  4698. }
  4699. updateMatrix() {
  4700. this.matrix.compose( this.position, this.quaternion, this.scale );
  4701. this.matrixWorldNeedsUpdate = true;
  4702. }
  4703. updateMatrixWorld( force ) {
  4704. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4705. if ( this.matrixWorldNeedsUpdate || force ) {
  4706. if ( this.matrixWorldAutoUpdate === true ) {
  4707. if ( this.parent === null ) {
  4708. this.matrixWorld.copy( this.matrix );
  4709. } else {
  4710. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4711. }
  4712. }
  4713. this.matrixWorldNeedsUpdate = false;
  4714. force = true;
  4715. }
  4716. // make sure descendants are updated if required
  4717. const children = this.children;
  4718. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4719. const child = children[ i ];
  4720. child.updateMatrixWorld( force );
  4721. }
  4722. }
  4723. updateWorldMatrix( updateParents, updateChildren ) {
  4724. const parent = this.parent;
  4725. if ( updateParents === true && parent !== null ) {
  4726. parent.updateWorldMatrix( true, false );
  4727. }
  4728. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4729. if ( this.matrixWorldAutoUpdate === true ) {
  4730. if ( this.parent === null ) {
  4731. this.matrixWorld.copy( this.matrix );
  4732. } else {
  4733. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4734. }
  4735. }
  4736. // make sure descendants are updated
  4737. if ( updateChildren === true ) {
  4738. const children = this.children;
  4739. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4740. const child = children[ i ];
  4741. child.updateWorldMatrix( false, true );
  4742. }
  4743. }
  4744. }
  4745. toJSON( meta ) {
  4746. // meta is a string when called from JSON.stringify
  4747. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4748. const output = {};
  4749. // meta is a hash used to collect geometries, materials.
  4750. // not providing it implies that this is the root object
  4751. // being serialized.
  4752. if ( isRootObject ) {
  4753. // initialize meta obj
  4754. meta = {
  4755. geometries: {},
  4756. materials: {},
  4757. textures: {},
  4758. images: {},
  4759. shapes: {},
  4760. skeletons: {},
  4761. animations: {},
  4762. nodes: {}
  4763. };
  4764. output.metadata = {
  4765. version: 4.6,
  4766. type: 'Object',
  4767. generator: 'Object3D.toJSON'
  4768. };
  4769. }
  4770. // standard Object3D serialization
  4771. const object = {};
  4772. object.uuid = this.uuid;
  4773. object.type = this.type;
  4774. if ( this.name !== '' ) object.name = this.name;
  4775. if ( this.castShadow === true ) object.castShadow = true;
  4776. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4777. if ( this.visible === false ) object.visible = false;
  4778. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4779. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4780. if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;
  4781. object.layers = this.layers.mask;
  4782. object.matrix = this.matrix.toArray();
  4783. object.up = this.up.toArray();
  4784. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4785. // object specific properties
  4786. if ( this.isInstancedMesh ) {
  4787. object.type = 'InstancedMesh';
  4788. object.count = this.count;
  4789. object.instanceMatrix = this.instanceMatrix.toJSON();
  4790. if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
  4791. }
  4792. if ( this.isBatchedMesh ) {
  4793. object.type = 'BatchedMesh';
  4794. object.perObjectFrustumCulled = this.perObjectFrustumCulled;
  4795. object.sortObjects = this.sortObjects;
  4796. object.drawRanges = this._drawRanges;
  4797. object.reservedRanges = this._reservedRanges;
  4798. object.visibility = this._visibility;
  4799. object.active = this._active;
  4800. object.bounds = this._bounds.map( bound => ( {
  4801. boxInitialized: bound.boxInitialized,
  4802. boxMin: bound.box.min.toArray(),
  4803. boxMax: bound.box.max.toArray(),
  4804. sphereInitialized: bound.sphereInitialized,
  4805. sphereRadius: bound.sphere.radius,
  4806. sphereCenter: bound.sphere.center.toArray()
  4807. } ) );
  4808. object.maxInstanceCount = this._maxInstanceCount;
  4809. object.maxVertexCount = this._maxVertexCount;
  4810. object.maxIndexCount = this._maxIndexCount;
  4811. object.geometryInitialized = this._geometryInitialized;
  4812. object.geometryCount = this._geometryCount;
  4813. object.matricesTexture = this._matricesTexture.toJSON( meta );
  4814. if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
  4815. if ( this.boundingSphere !== null ) {
  4816. object.boundingSphere = {
  4817. center: object.boundingSphere.center.toArray(),
  4818. radius: object.boundingSphere.radius
  4819. };
  4820. }
  4821. if ( this.boundingBox !== null ) {
  4822. object.boundingBox = {
  4823. min: object.boundingBox.min.toArray(),
  4824. max: object.boundingBox.max.toArray()
  4825. };
  4826. }
  4827. }
  4828. //
  4829. function serialize( library, element ) {
  4830. if ( library[ element.uuid ] === undefined ) {
  4831. library[ element.uuid ] = element.toJSON( meta );
  4832. }
  4833. return element.uuid;
  4834. }
  4835. if ( this.isScene ) {
  4836. if ( this.background ) {
  4837. if ( this.background.isColor ) {
  4838. object.background = this.background.toJSON();
  4839. } else if ( this.background.isTexture ) {
  4840. object.background = this.background.toJSON( meta ).uuid;
  4841. }
  4842. }
  4843. if ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) {
  4844. object.environment = this.environment.toJSON( meta ).uuid;
  4845. }
  4846. } else if ( this.isMesh || this.isLine || this.isPoints ) {
  4847. object.geometry = serialize( meta.geometries, this.geometry );
  4848. const parameters = this.geometry.parameters;
  4849. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4850. const shapes = parameters.shapes;
  4851. if ( Array.isArray( shapes ) ) {
  4852. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4853. const shape = shapes[ i ];
  4854. serialize( meta.shapes, shape );
  4855. }
  4856. } else {
  4857. serialize( meta.shapes, shapes );
  4858. }
  4859. }
  4860. }
  4861. if ( this.isSkinnedMesh ) {
  4862. object.bindMode = this.bindMode;
  4863. object.bindMatrix = this.bindMatrix.toArray();
  4864. if ( this.skeleton !== undefined ) {
  4865. serialize( meta.skeletons, this.skeleton );
  4866. object.skeleton = this.skeleton.uuid;
  4867. }
  4868. }
  4869. if ( this.material !== undefined ) {
  4870. if ( Array.isArray( this.material ) ) {
  4871. const uuids = [];
  4872. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4873. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4874. }
  4875. object.material = uuids;
  4876. } else {
  4877. object.material = serialize( meta.materials, this.material );
  4878. }
  4879. }
  4880. //
  4881. if ( this.children.length > 0 ) {
  4882. object.children = [];
  4883. for ( let i = 0; i < this.children.length; i ++ ) {
  4884. object.children.push( this.children[ i ].toJSON( meta ).object );
  4885. }
  4886. }
  4887. //
  4888. if ( this.animations.length > 0 ) {
  4889. object.animations = [];
  4890. for ( let i = 0; i < this.animations.length; i ++ ) {
  4891. const animation = this.animations[ i ];
  4892. object.animations.push( serialize( meta.animations, animation ) );
  4893. }
  4894. }
  4895. if ( isRootObject ) {
  4896. const geometries = extractFromCache( meta.geometries );
  4897. const materials = extractFromCache( meta.materials );
  4898. const textures = extractFromCache( meta.textures );
  4899. const images = extractFromCache( meta.images );
  4900. const shapes = extractFromCache( meta.shapes );
  4901. const skeletons = extractFromCache( meta.skeletons );
  4902. const animations = extractFromCache( meta.animations );
  4903. const nodes = extractFromCache( meta.nodes );
  4904. if ( geometries.length > 0 ) output.geometries = geometries;
  4905. if ( materials.length > 0 ) output.materials = materials;
  4906. if ( textures.length > 0 ) output.textures = textures;
  4907. if ( images.length > 0 ) output.images = images;
  4908. if ( shapes.length > 0 ) output.shapes = shapes;
  4909. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4910. if ( animations.length > 0 ) output.animations = animations;
  4911. if ( nodes.length > 0 ) output.nodes = nodes;
  4912. }
  4913. output.object = object;
  4914. return output;
  4915. // extract data from the cache hash
  4916. // remove metadata on each item
  4917. // and return as array
  4918. function extractFromCache( cache ) {
  4919. const values = [];
  4920. for ( const key in cache ) {
  4921. const data = cache[ key ];
  4922. delete data.metadata;
  4923. values.push( data );
  4924. }
  4925. return values;
  4926. }
  4927. }
  4928. clone( recursive ) {
  4929. return new this.constructor().copy( this, recursive );
  4930. }
  4931. copy( source, recursive = true ) {
  4932. this.name = source.name;
  4933. this.up.copy( source.up );
  4934. this.position.copy( source.position );
  4935. this.rotation.order = source.rotation.order;
  4936. this.quaternion.copy( source.quaternion );
  4937. this.scale.copy( source.scale );
  4938. this.matrix.copy( source.matrix );
  4939. this.matrixWorld.copy( source.matrixWorld );
  4940. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4941. this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
  4942. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4943. this.layers.mask = source.layers.mask;
  4944. this.visible = source.visible;
  4945. this.castShadow = source.castShadow;
  4946. this.receiveShadow = source.receiveShadow;
  4947. this.frustumCulled = source.frustumCulled;
  4948. this.renderOrder = source.renderOrder;
  4949. this.animations = source.animations.slice();
  4950. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4951. if ( recursive === true ) {
  4952. for ( let i = 0; i < source.children.length; i ++ ) {
  4953. const child = source.children[ i ];
  4954. this.add( child.clone() );
  4955. }
  4956. }
  4957. return this;
  4958. }
  4959. }
  4960. Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4961. Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
  4962. Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
  4963. const _v0$1 = /*@__PURE__*/ new Vector3();
  4964. const _v1$3 = /*@__PURE__*/ new Vector3();
  4965. const _v2$2 = /*@__PURE__*/ new Vector3();
  4966. const _v3$2 = /*@__PURE__*/ new Vector3();
  4967. const _vab = /*@__PURE__*/ new Vector3();
  4968. const _vac = /*@__PURE__*/ new Vector3();
  4969. const _vbc = /*@__PURE__*/ new Vector3();
  4970. const _vap = /*@__PURE__*/ new Vector3();
  4971. const _vbp = /*@__PURE__*/ new Vector3();
  4972. const _vcp = /*@__PURE__*/ new Vector3();
  4973. const _v40 = /*@__PURE__*/ new Vector4();
  4974. const _v41 = /*@__PURE__*/ new Vector4();
  4975. const _v42 = /*@__PURE__*/ new Vector4();
  4976. class Triangle {
  4977. constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
  4978. this.a = a;
  4979. this.b = b;
  4980. this.c = c;
  4981. }
  4982. static getNormal( a, b, c, target ) {
  4983. target.subVectors( c, b );
  4984. _v0$1.subVectors( a, b );
  4985. target.cross( _v0$1 );
  4986. const targetLengthSq = target.lengthSq();
  4987. if ( targetLengthSq > 0 ) {
  4988. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4989. }
  4990. return target.set( 0, 0, 0 );
  4991. }
  4992. // static/instance method to calculate barycentric coordinates
  4993. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4994. static getBarycoord( point, a, b, c, target ) {
  4995. _v0$1.subVectors( c, a );
  4996. _v1$3.subVectors( b, a );
  4997. _v2$2.subVectors( point, a );
  4998. const dot00 = _v0$1.dot( _v0$1 );
  4999. const dot01 = _v0$1.dot( _v1$3 );
  5000. const dot02 = _v0$1.dot( _v2$2 );
  5001. const dot11 = _v1$3.dot( _v1$3 );
  5002. const dot12 = _v1$3.dot( _v2$2 );
  5003. const denom = ( dot00 * dot11 - dot01 * dot01 );
  5004. // collinear or singular triangle
  5005. if ( denom === 0 ) {
  5006. target.set( 0, 0, 0 );
  5007. return null;
  5008. }
  5009. const invDenom = 1 / denom;
  5010. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  5011. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  5012. // barycentric coordinates must always sum to 1
  5013. return target.set( 1 - u - v, v, u );
  5014. }
  5015. static containsPoint( point, a, b, c ) {
  5016. // if the triangle is degenerate then we can't contain a point
  5017. if ( this.getBarycoord( point, a, b, c, _v3$2 ) === null ) {
  5018. return false;
  5019. }
  5020. return ( _v3$2.x >= 0 ) && ( _v3$2.y >= 0 ) && ( ( _v3$2.x + _v3$2.y ) <= 1 );
  5021. }
  5022. static getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) {
  5023. if ( this.getBarycoord( point, p1, p2, p3, _v3$2 ) === null ) {
  5024. target.x = 0;
  5025. target.y = 0;
  5026. if ( 'z' in target ) target.z = 0;
  5027. if ( 'w' in target ) target.w = 0;
  5028. return null;
  5029. }
  5030. target.setScalar( 0 );
  5031. target.addScaledVector( v1, _v3$2.x );
  5032. target.addScaledVector( v2, _v3$2.y );
  5033. target.addScaledVector( v3, _v3$2.z );
  5034. return target;
  5035. }
  5036. static getInterpolatedAttribute( attr, i1, i2, i3, barycoord, target ) {
  5037. _v40.setScalar( 0 );
  5038. _v41.setScalar( 0 );
  5039. _v42.setScalar( 0 );
  5040. _v40.fromBufferAttribute( attr, i1 );
  5041. _v41.fromBufferAttribute( attr, i2 );
  5042. _v42.fromBufferAttribute( attr, i3 );
  5043. target.setScalar( 0 );
  5044. target.addScaledVector( _v40, barycoord.x );
  5045. target.addScaledVector( _v41, barycoord.y );
  5046. target.addScaledVector( _v42, barycoord.z );
  5047. return target;
  5048. }
  5049. static isFrontFacing( a, b, c, direction ) {
  5050. _v0$1.subVectors( c, b );
  5051. _v1$3.subVectors( a, b );
  5052. // strictly front facing
  5053. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  5054. }
  5055. set( a, b, c ) {
  5056. this.a.copy( a );
  5057. this.b.copy( b );
  5058. this.c.copy( c );
  5059. return this;
  5060. }
  5061. setFromPointsAndIndices( points, i0, i1, i2 ) {
  5062. this.a.copy( points[ i0 ] );
  5063. this.b.copy( points[ i1 ] );
  5064. this.c.copy( points[ i2 ] );
  5065. return this;
  5066. }
  5067. setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
  5068. this.a.fromBufferAttribute( attribute, i0 );
  5069. this.b.fromBufferAttribute( attribute, i1 );
  5070. this.c.fromBufferAttribute( attribute, i2 );
  5071. return this;
  5072. }
  5073. clone() {
  5074. return new this.constructor().copy( this );
  5075. }
  5076. copy( triangle ) {
  5077. this.a.copy( triangle.a );
  5078. this.b.copy( triangle.b );
  5079. this.c.copy( triangle.c );
  5080. return this;
  5081. }
  5082. getArea() {
  5083. _v0$1.subVectors( this.c, this.b );
  5084. _v1$3.subVectors( this.a, this.b );
  5085. return _v0$1.cross( _v1$3 ).length() * 0.5;
  5086. }
  5087. getMidpoint( target ) {
  5088. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  5089. }
  5090. getNormal( target ) {
  5091. return Triangle.getNormal( this.a, this.b, this.c, target );
  5092. }
  5093. getPlane( target ) {
  5094. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  5095. }
  5096. getBarycoord( point, target ) {
  5097. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  5098. }
  5099. getInterpolation( point, v1, v2, v3, target ) {
  5100. return Triangle.getInterpolation( point, this.a, this.b, this.c, v1, v2, v3, target );
  5101. }
  5102. containsPoint( point ) {
  5103. return Triangle.containsPoint( point, this.a, this.b, this.c );
  5104. }
  5105. isFrontFacing( direction ) {
  5106. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  5107. }
  5108. intersectsBox( box ) {
  5109. return box.intersectsTriangle( this );
  5110. }
  5111. closestPointToPoint( p, target ) {
  5112. const a = this.a, b = this.b, c = this.c;
  5113. let v, w;
  5114. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5115. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5116. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5117. // basically, we're distinguishing which of the voronoi regions of the triangle
  5118. // the point lies in with the minimum amount of redundant computation.
  5119. _vab.subVectors( b, a );
  5120. _vac.subVectors( c, a );
  5121. _vap.subVectors( p, a );
  5122. const d1 = _vab.dot( _vap );
  5123. const d2 = _vac.dot( _vap );
  5124. if ( d1 <= 0 && d2 <= 0 ) {
  5125. // vertex region of A; barycentric coords (1, 0, 0)
  5126. return target.copy( a );
  5127. }
  5128. _vbp.subVectors( p, b );
  5129. const d3 = _vab.dot( _vbp );
  5130. const d4 = _vac.dot( _vbp );
  5131. if ( d3 >= 0 && d4 <= d3 ) {
  5132. // vertex region of B; barycentric coords (0, 1, 0)
  5133. return target.copy( b );
  5134. }
  5135. const vc = d1 * d4 - d3 * d2;
  5136. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  5137. v = d1 / ( d1 - d3 );
  5138. // edge region of AB; barycentric coords (1-v, v, 0)
  5139. return target.copy( a ).addScaledVector( _vab, v );
  5140. }
  5141. _vcp.subVectors( p, c );
  5142. const d5 = _vab.dot( _vcp );
  5143. const d6 = _vac.dot( _vcp );
  5144. if ( d6 >= 0 && d5 <= d6 ) {
  5145. // vertex region of C; barycentric coords (0, 0, 1)
  5146. return target.copy( c );
  5147. }
  5148. const vb = d5 * d2 - d1 * d6;
  5149. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  5150. w = d2 / ( d2 - d6 );
  5151. // edge region of AC; barycentric coords (1-w, 0, w)
  5152. return target.copy( a ).addScaledVector( _vac, w );
  5153. }
  5154. const va = d3 * d6 - d5 * d4;
  5155. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  5156. _vbc.subVectors( c, b );
  5157. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  5158. // edge region of BC; barycentric coords (0, 1-w, w)
  5159. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  5160. }
  5161. // face region
  5162. const denom = 1 / ( va + vb + vc );
  5163. // u = va * denom
  5164. v = vb * denom;
  5165. w = vc * denom;
  5166. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  5167. }
  5168. equals( triangle ) {
  5169. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  5170. }
  5171. }
  5172. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5173. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5174. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5175. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5176. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5177. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5178. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5179. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5180. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5181. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5182. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5183. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5184. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5185. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5186. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5187. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5188. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5189. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5190. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5191. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5192. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5193. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5194. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5195. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5196. const _hslA = { h: 0, s: 0, l: 0 };
  5197. const _hslB = { h: 0, s: 0, l: 0 };
  5198. function hue2rgb( p, q, t ) {
  5199. if ( t < 0 ) t += 1;
  5200. if ( t > 1 ) t -= 1;
  5201. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5202. if ( t < 1 / 2 ) return q;
  5203. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5204. return p;
  5205. }
  5206. class Color {
  5207. constructor( r, g, b ) {
  5208. this.isColor = true;
  5209. this.r = 1;
  5210. this.g = 1;
  5211. this.b = 1;
  5212. return this.set( r, g, b );
  5213. }
  5214. set( r, g, b ) {
  5215. if ( g === undefined && b === undefined ) {
  5216. // r is THREE.Color, hex or string
  5217. const value = r;
  5218. if ( value && value.isColor ) {
  5219. this.copy( value );
  5220. } else if ( typeof value === 'number' ) {
  5221. this.setHex( value );
  5222. } else if ( typeof value === 'string' ) {
  5223. this.setStyle( value );
  5224. }
  5225. } else {
  5226. this.setRGB( r, g, b );
  5227. }
  5228. return this;
  5229. }
  5230. setScalar( scalar ) {
  5231. this.r = scalar;
  5232. this.g = scalar;
  5233. this.b = scalar;
  5234. return this;
  5235. }
  5236. setHex( hex, colorSpace = SRGBColorSpace ) {
  5237. hex = Math.floor( hex );
  5238. this.r = ( hex >> 16 & 255 ) / 255;
  5239. this.g = ( hex >> 8 & 255 ) / 255;
  5240. this.b = ( hex & 255 ) / 255;
  5241. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5242. return this;
  5243. }
  5244. setRGB( r, g, b, colorSpace = ColorManagement.workingColorSpace ) {
  5245. this.r = r;
  5246. this.g = g;
  5247. this.b = b;
  5248. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5249. return this;
  5250. }
  5251. setHSL( h, s, l, colorSpace = ColorManagement.workingColorSpace ) {
  5252. // h,s,l ranges are in 0.0 - 1.0
  5253. h = euclideanModulo( h, 1 );
  5254. s = clamp( s, 0, 1 );
  5255. l = clamp( l, 0, 1 );
  5256. if ( s === 0 ) {
  5257. this.r = this.g = this.b = l;
  5258. } else {
  5259. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5260. const q = ( 2 * l ) - p;
  5261. this.r = hue2rgb( q, p, h + 1 / 3 );
  5262. this.g = hue2rgb( q, p, h );
  5263. this.b = hue2rgb( q, p, h - 1 / 3 );
  5264. }
  5265. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5266. return this;
  5267. }
  5268. setStyle( style, colorSpace = SRGBColorSpace ) {
  5269. function handleAlpha( string ) {
  5270. if ( string === undefined ) return;
  5271. if ( parseFloat( string ) < 1 ) {
  5272. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5273. }
  5274. }
  5275. let m;
  5276. if ( m = /^(\w+)\(([^\)]*)\)/.exec( style ) ) {
  5277. // rgb / hsl
  5278. let color;
  5279. const name = m[ 1 ];
  5280. const components = m[ 2 ];
  5281. switch ( name ) {
  5282. case 'rgb':
  5283. case 'rgba':
  5284. if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5285. // rgb(255,0,0) rgba(255,0,0,0.5)
  5286. handleAlpha( color[ 4 ] );
  5287. return this.setRGB(
  5288. Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255,
  5289. Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255,
  5290. Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255,
  5291. colorSpace
  5292. );
  5293. }
  5294. if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5295. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5296. handleAlpha( color[ 4 ] );
  5297. return this.setRGB(
  5298. Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100,
  5299. Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100,
  5300. Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100,
  5301. colorSpace
  5302. );
  5303. }
  5304. break;
  5305. case 'hsl':
  5306. case 'hsla':
  5307. if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5308. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5309. handleAlpha( color[ 4 ] );
  5310. return this.setHSL(
  5311. parseFloat( color[ 1 ] ) / 360,
  5312. parseFloat( color[ 2 ] ) / 100,
  5313. parseFloat( color[ 3 ] ) / 100,
  5314. colorSpace
  5315. );
  5316. }
  5317. break;
  5318. default:
  5319. console.warn( 'THREE.Color: Unknown color model ' + style );
  5320. }
  5321. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  5322. // hex color
  5323. const hex = m[ 1 ];
  5324. const size = hex.length;
  5325. if ( size === 3 ) {
  5326. // #ff0
  5327. return this.setRGB(
  5328. parseInt( hex.charAt( 0 ), 16 ) / 15,
  5329. parseInt( hex.charAt( 1 ), 16 ) / 15,
  5330. parseInt( hex.charAt( 2 ), 16 ) / 15,
  5331. colorSpace
  5332. );
  5333. } else if ( size === 6 ) {
  5334. // #ff0000
  5335. return this.setHex( parseInt( hex, 16 ), colorSpace );
  5336. } else {
  5337. console.warn( 'THREE.Color: Invalid hex color ' + style );
  5338. }
  5339. } else if ( style && style.length > 0 ) {
  5340. return this.setColorName( style, colorSpace );
  5341. }
  5342. return this;
  5343. }
  5344. setColorName( style, colorSpace = SRGBColorSpace ) {
  5345. // color keywords
  5346. const hex = _colorKeywords[ style.toLowerCase() ];
  5347. if ( hex !== undefined ) {
  5348. // red
  5349. this.setHex( hex, colorSpace );
  5350. } else {
  5351. // unknown color
  5352. console.warn( 'THREE.Color: Unknown color ' + style );
  5353. }
  5354. return this;
  5355. }
  5356. clone() {
  5357. return new this.constructor( this.r, this.g, this.b );
  5358. }
  5359. copy( color ) {
  5360. this.r = color.r;
  5361. this.g = color.g;
  5362. this.b = color.b;
  5363. return this;
  5364. }
  5365. copySRGBToLinear( color ) {
  5366. this.r = SRGBToLinear( color.r );
  5367. this.g = SRGBToLinear( color.g );
  5368. this.b = SRGBToLinear( color.b );
  5369. return this;
  5370. }
  5371. copyLinearToSRGB( color ) {
  5372. this.r = LinearToSRGB( color.r );
  5373. this.g = LinearToSRGB( color.g );
  5374. this.b = LinearToSRGB( color.b );
  5375. return this;
  5376. }
  5377. convertSRGBToLinear() {
  5378. this.copySRGBToLinear( this );
  5379. return this;
  5380. }
  5381. convertLinearToSRGB() {
  5382. this.copyLinearToSRGB( this );
  5383. return this;
  5384. }
  5385. getHex( colorSpace = SRGBColorSpace ) {
  5386. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5387. return Math.round( clamp( _color.r * 255, 0, 255 ) ) * 65536 + Math.round( clamp( _color.g * 255, 0, 255 ) ) * 256 + Math.round( clamp( _color.b * 255, 0, 255 ) );
  5388. }
  5389. getHexString( colorSpace = SRGBColorSpace ) {
  5390. return ( '000000' + this.getHex( colorSpace ).toString( 16 ) ).slice( -6 );
  5391. }
  5392. getHSL( target, colorSpace = ColorManagement.workingColorSpace ) {
  5393. // h,s,l ranges are in 0.0 - 1.0
  5394. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5395. const r = _color.r, g = _color.g, b = _color.b;
  5396. const max = Math.max( r, g, b );
  5397. const min = Math.min( r, g, b );
  5398. let hue, saturation;
  5399. const lightness = ( min + max ) / 2.0;
  5400. if ( min === max ) {
  5401. hue = 0;
  5402. saturation = 0;
  5403. } else {
  5404. const delta = max - min;
  5405. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5406. switch ( max ) {
  5407. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5408. case g: hue = ( b - r ) / delta + 2; break;
  5409. case b: hue = ( r - g ) / delta + 4; break;
  5410. }
  5411. hue /= 6;
  5412. }
  5413. target.h = hue;
  5414. target.s = saturation;
  5415. target.l = lightness;
  5416. return target;
  5417. }
  5418. getRGB( target, colorSpace = ColorManagement.workingColorSpace ) {
  5419. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5420. target.r = _color.r;
  5421. target.g = _color.g;
  5422. target.b = _color.b;
  5423. return target;
  5424. }
  5425. getStyle( colorSpace = SRGBColorSpace ) {
  5426. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5427. const r = _color.r, g = _color.g, b = _color.b;
  5428. if ( colorSpace !== SRGBColorSpace ) {
  5429. // Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).
  5430. return `color(${ colorSpace } ${ r.toFixed( 3 ) } ${ g.toFixed( 3 ) } ${ b.toFixed( 3 ) })`;
  5431. }
  5432. return `rgb(${ Math.round( r * 255 ) },${ Math.round( g * 255 ) },${ Math.round( b * 255 ) })`;
  5433. }
  5434. offsetHSL( h, s, l ) {
  5435. this.getHSL( _hslA );
  5436. return this.setHSL( _hslA.h + h, _hslA.s + s, _hslA.l + l );
  5437. }
  5438. add( color ) {
  5439. this.r += color.r;
  5440. this.g += color.g;
  5441. this.b += color.b;
  5442. return this;
  5443. }
  5444. addColors( color1, color2 ) {
  5445. this.r = color1.r + color2.r;
  5446. this.g = color1.g + color2.g;
  5447. this.b = color1.b + color2.b;
  5448. return this;
  5449. }
  5450. addScalar( s ) {
  5451. this.r += s;
  5452. this.g += s;
  5453. this.b += s;
  5454. return this;
  5455. }
  5456. sub( color ) {
  5457. this.r = Math.max( 0, this.r - color.r );
  5458. this.g = Math.max( 0, this.g - color.g );
  5459. this.b = Math.max( 0, this.b - color.b );
  5460. return this;
  5461. }
  5462. multiply( color ) {
  5463. this.r *= color.r;
  5464. this.g *= color.g;
  5465. this.b *= color.b;
  5466. return this;
  5467. }
  5468. multiplyScalar( s ) {
  5469. this.r *= s;
  5470. this.g *= s;
  5471. this.b *= s;
  5472. return this;
  5473. }
  5474. lerp( color, alpha ) {
  5475. this.r += ( color.r - this.r ) * alpha;
  5476. this.g += ( color.g - this.g ) * alpha;
  5477. this.b += ( color.b - this.b ) * alpha;
  5478. return this;
  5479. }
  5480. lerpColors( color1, color2, alpha ) {
  5481. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  5482. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  5483. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  5484. return this;
  5485. }
  5486. lerpHSL( color, alpha ) {
  5487. this.getHSL( _hslA );
  5488. color.getHSL( _hslB );
  5489. const h = lerp( _hslA.h, _hslB.h, alpha );
  5490. const s = lerp( _hslA.s, _hslB.s, alpha );
  5491. const l = lerp( _hslA.l, _hslB.l, alpha );
  5492. this.setHSL( h, s, l );
  5493. return this;
  5494. }
  5495. setFromVector3( v ) {
  5496. this.r = v.x;
  5497. this.g = v.y;
  5498. this.b = v.z;
  5499. return this;
  5500. }
  5501. applyMatrix3( m ) {
  5502. const r = this.r, g = this.g, b = this.b;
  5503. const e = m.elements;
  5504. this.r = e[ 0 ] * r + e[ 3 ] * g + e[ 6 ] * b;
  5505. this.g = e[ 1 ] * r + e[ 4 ] * g + e[ 7 ] * b;
  5506. this.b = e[ 2 ] * r + e[ 5 ] * g + e[ 8 ] * b;
  5507. return this;
  5508. }
  5509. equals( c ) {
  5510. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5511. }
  5512. fromArray( array, offset = 0 ) {
  5513. this.r = array[ offset ];
  5514. this.g = array[ offset + 1 ];
  5515. this.b = array[ offset + 2 ];
  5516. return this;
  5517. }
  5518. toArray( array = [], offset = 0 ) {
  5519. array[ offset ] = this.r;
  5520. array[ offset + 1 ] = this.g;
  5521. array[ offset + 2 ] = this.b;
  5522. return array;
  5523. }
  5524. fromBufferAttribute( attribute, index ) {
  5525. this.r = attribute.getX( index );
  5526. this.g = attribute.getY( index );
  5527. this.b = attribute.getZ( index );
  5528. return this;
  5529. }
  5530. toJSON() {
  5531. return this.getHex();
  5532. }
  5533. *[ Symbol.iterator ]() {
  5534. yield this.r;
  5535. yield this.g;
  5536. yield this.b;
  5537. }
  5538. }
  5539. const _color = /*@__PURE__*/ new Color();
  5540. Color.NAMES = _colorKeywords;
  5541. let _materialId = 0;
  5542. class Material extends EventDispatcher {
  5543. constructor() {
  5544. super();
  5545. this.isMaterial = true;
  5546. Object.defineProperty( this, 'id', { value: _materialId ++ } );
  5547. this.uuid = generateUUID();
  5548. this.name = '';
  5549. this.type = 'Material';
  5550. this.blending = NormalBlending;
  5551. this.side = FrontSide;
  5552. this.vertexColors = false;
  5553. this.opacity = 1;
  5554. this.transparent = false;
  5555. this.alphaHash = false;
  5556. this.blendSrc = SrcAlphaFactor;
  5557. this.blendDst = OneMinusSrcAlphaFactor;
  5558. this.blendEquation = AddEquation;
  5559. this.blendSrcAlpha = null;
  5560. this.blendDstAlpha = null;
  5561. this.blendEquationAlpha = null;
  5562. this.blendColor = new Color( 0, 0, 0 );
  5563. this.blendAlpha = 0;
  5564. this.depthFunc = LessEqualDepth;
  5565. this.depthTest = true;
  5566. this.depthWrite = true;
  5567. this.stencilWriteMask = 0xff;
  5568. this.stencilFunc = AlwaysStencilFunc;
  5569. this.stencilRef = 0;
  5570. this.stencilFuncMask = 0xff;
  5571. this.stencilFail = KeepStencilOp;
  5572. this.stencilZFail = KeepStencilOp;
  5573. this.stencilZPass = KeepStencilOp;
  5574. this.stencilWrite = false;
  5575. this.clippingPlanes = null;
  5576. this.clipIntersection = false;
  5577. this.clipShadows = false;
  5578. this.shadowSide = null;
  5579. this.colorWrite = true;
  5580. this.precision = null; // override the renderer's default precision for this material
  5581. this.polygonOffset = false;
  5582. this.polygonOffsetFactor = 0;
  5583. this.polygonOffsetUnits = 0;
  5584. this.dithering = false;
  5585. this.alphaToCoverage = false;
  5586. this.premultipliedAlpha = false;
  5587. this.forceSinglePass = false;
  5588. this.visible = true;
  5589. this.toneMapped = true;
  5590. this.userData = {};
  5591. this.version = 0;
  5592. this._alphaTest = 0;
  5593. }
  5594. get alphaTest() {
  5595. return this._alphaTest;
  5596. }
  5597. set alphaTest( value ) {
  5598. if ( this._alphaTest > 0 !== value > 0 ) {
  5599. this.version ++;
  5600. }
  5601. this._alphaTest = value;
  5602. }
  5603. // onBeforeRender and onBeforeCompile only supported in WebGLRenderer
  5604. onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}
  5605. onBeforeCompile( /* shaderobject, renderer */ ) {}
  5606. customProgramCacheKey() {
  5607. return this.onBeforeCompile.toString();
  5608. }
  5609. setValues( values ) {
  5610. if ( values === undefined ) return;
  5611. for ( const key in values ) {
  5612. const newValue = values[ key ];
  5613. if ( newValue === undefined ) {
  5614. console.warn( `THREE.Material: parameter '${ key }' has value of undefined.` );
  5615. continue;
  5616. }
  5617. const currentValue = this[ key ];
  5618. if ( currentValue === undefined ) {
  5619. console.warn( `THREE.Material: '${ key }' is not a property of THREE.${ this.type }.` );
  5620. continue;
  5621. }
  5622. if ( currentValue && currentValue.isColor ) {
  5623. currentValue.set( newValue );
  5624. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5625. currentValue.copy( newValue );
  5626. } else {
  5627. this[ key ] = newValue;
  5628. }
  5629. }
  5630. }
  5631. toJSON( meta ) {
  5632. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  5633. if ( isRootObject ) {
  5634. meta = {
  5635. textures: {},
  5636. images: {}
  5637. };
  5638. }
  5639. const data = {
  5640. metadata: {
  5641. version: 4.6,
  5642. type: 'Material',
  5643. generator: 'Material.toJSON'
  5644. }
  5645. };
  5646. // standard Material serialization
  5647. data.uuid = this.uuid;
  5648. data.type = this.type;
  5649. if ( this.name !== '' ) data.name = this.name;
  5650. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5651. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5652. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5653. if ( this.sheen !== undefined ) data.sheen = this.sheen;
  5654. if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();
  5655. if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
  5656. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5657. if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5658. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5659. if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
  5660. if ( this.specularColor && this.specularColor.isColor ) data.specularColor = this.specularColor.getHex();
  5661. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5662. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5663. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5664. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5665. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5666. }
  5667. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5668. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5669. }
  5670. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5671. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5672. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5673. }
  5674. if ( this.dispersion !== undefined ) data.dispersion = this.dispersion;
  5675. if ( this.iridescence !== undefined ) data.iridescence = this.iridescence;
  5676. if ( this.iridescenceIOR !== undefined ) data.iridescenceIOR = this.iridescenceIOR;
  5677. if ( this.iridescenceThicknessRange !== undefined ) data.iridescenceThicknessRange = this.iridescenceThicknessRange;
  5678. if ( this.iridescenceMap && this.iridescenceMap.isTexture ) {
  5679. data.iridescenceMap = this.iridescenceMap.toJSON( meta ).uuid;
  5680. }
  5681. if ( this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture ) {
  5682. data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON( meta ).uuid;
  5683. }
  5684. if ( this.anisotropy !== undefined ) data.anisotropy = this.anisotropy;
  5685. if ( this.anisotropyRotation !== undefined ) data.anisotropyRotation = this.anisotropyRotation;
  5686. if ( this.anisotropyMap && this.anisotropyMap.isTexture ) {
  5687. data.anisotropyMap = this.anisotropyMap.toJSON( meta ).uuid;
  5688. }
  5689. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5690. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5691. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5692. if ( this.lightMap && this.lightMap.isTexture ) {
  5693. data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5694. data.lightMapIntensity = this.lightMapIntensity;
  5695. }
  5696. if ( this.aoMap && this.aoMap.isTexture ) {
  5697. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5698. data.aoMapIntensity = this.aoMapIntensity;
  5699. }
  5700. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5701. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5702. data.bumpScale = this.bumpScale;
  5703. }
  5704. if ( this.normalMap && this.normalMap.isTexture ) {
  5705. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5706. data.normalMapType = this.normalMapType;
  5707. data.normalScale = this.normalScale.toArray();
  5708. }
  5709. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5710. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5711. data.displacementScale = this.displacementScale;
  5712. data.displacementBias = this.displacementBias;
  5713. }
  5714. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5715. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5716. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5717. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5718. if ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid;
  5719. if ( this.specularColorMap && this.specularColorMap.isTexture ) data.specularColorMap = this.specularColorMap.toJSON( meta ).uuid;
  5720. if ( this.envMap && this.envMap.isTexture ) {
  5721. data.envMap = this.envMap.toJSON( meta ).uuid;
  5722. if ( this.combine !== undefined ) data.combine = this.combine;
  5723. }
  5724. if ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray();
  5725. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5726. if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;
  5727. if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;
  5728. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5729. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5730. }
  5731. if ( this.transmission !== undefined ) data.transmission = this.transmission;
  5732. if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;
  5733. if ( this.thickness !== undefined ) data.thickness = this.thickness;
  5734. if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;
  5735. if ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance;
  5736. if ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex();
  5737. if ( this.size !== undefined ) data.size = this.size;
  5738. if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;
  5739. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5740. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5741. if ( this.side !== FrontSide ) data.side = this.side;
  5742. if ( this.vertexColors === true ) data.vertexColors = true;
  5743. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5744. if ( this.transparent === true ) data.transparent = true;
  5745. if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;
  5746. if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;
  5747. if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;
  5748. if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;
  5749. if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;
  5750. if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;
  5751. if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();
  5752. if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;
  5753. if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
  5754. if ( this.depthTest === false ) data.depthTest = this.depthTest;
  5755. if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
  5756. if ( this.colorWrite === false ) data.colorWrite = this.colorWrite;
  5757. if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;
  5758. if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;
  5759. if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;
  5760. if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;
  5761. if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;
  5762. if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;
  5763. if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;
  5764. if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;
  5765. // rotation (SpriteMaterial)
  5766. if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;
  5767. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5768. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5769. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5770. if ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5771. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5772. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5773. if ( this.scale !== undefined ) data.scale = this.scale;
  5774. if ( this.dithering === true ) data.dithering = true;
  5775. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5776. if ( this.alphaHash === true ) data.alphaHash = true;
  5777. if ( this.alphaToCoverage === true ) data.alphaToCoverage = true;
  5778. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;
  5779. if ( this.forceSinglePass === true ) data.forceSinglePass = true;
  5780. if ( this.wireframe === true ) data.wireframe = true;
  5781. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5782. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5783. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5784. if ( this.flatShading === true ) data.flatShading = true;
  5785. if ( this.visible === false ) data.visible = false;
  5786. if ( this.toneMapped === false ) data.toneMapped = false;
  5787. if ( this.fog === false ) data.fog = false;
  5788. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  5789. // TODO: Copied from Object3D.toJSON
  5790. function extractFromCache( cache ) {
  5791. const values = [];
  5792. for ( const key in cache ) {
  5793. const data = cache[ key ];
  5794. delete data.metadata;
  5795. values.push( data );
  5796. }
  5797. return values;
  5798. }
  5799. if ( isRootObject ) {
  5800. const textures = extractFromCache( meta.textures );
  5801. const images = extractFromCache( meta.images );
  5802. if ( textures.length > 0 ) data.textures = textures;
  5803. if ( images.length > 0 ) data.images = images;
  5804. }
  5805. return data;
  5806. }
  5807. clone() {
  5808. return new this.constructor().copy( this );
  5809. }
  5810. copy( source ) {
  5811. this.name = source.name;
  5812. this.blending = source.blending;
  5813. this.side = source.side;
  5814. this.vertexColors = source.vertexColors;
  5815. this.opacity = source.opacity;
  5816. this.transparent = source.transparent;
  5817. this.blendSrc = source.blendSrc;
  5818. this.blendDst = source.blendDst;
  5819. this.blendEquation = source.blendEquation;
  5820. this.blendSrcAlpha = source.blendSrcAlpha;
  5821. this.blendDstAlpha = source.blendDstAlpha;
  5822. this.blendEquationAlpha = source.blendEquationAlpha;
  5823. this.blendColor.copy( source.blendColor );
  5824. this.blendAlpha = source.blendAlpha;
  5825. this.depthFunc = source.depthFunc;
  5826. this.depthTest = source.depthTest;
  5827. this.depthWrite = source.depthWrite;
  5828. this.stencilWriteMask = source.stencilWriteMask;
  5829. this.stencilFunc = source.stencilFunc;
  5830. this.stencilRef = source.stencilRef;
  5831. this.stencilFuncMask = source.stencilFuncMask;
  5832. this.stencilFail = source.stencilFail;
  5833. this.stencilZFail = source.stencilZFail;
  5834. this.stencilZPass = source.stencilZPass;
  5835. this.stencilWrite = source.stencilWrite;
  5836. const srcPlanes = source.clippingPlanes;
  5837. let dstPlanes = null;
  5838. if ( srcPlanes !== null ) {
  5839. const n = srcPlanes.length;
  5840. dstPlanes = new Array( n );
  5841. for ( let i = 0; i !== n; ++ i ) {
  5842. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5843. }
  5844. }
  5845. this.clippingPlanes = dstPlanes;
  5846. this.clipIntersection = source.clipIntersection;
  5847. this.clipShadows = source.clipShadows;
  5848. this.shadowSide = source.shadowSide;
  5849. this.colorWrite = source.colorWrite;
  5850. this.precision = source.precision;
  5851. this.polygonOffset = source.polygonOffset;
  5852. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5853. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5854. this.dithering = source.dithering;
  5855. this.alphaTest = source.alphaTest;
  5856. this.alphaHash = source.alphaHash;
  5857. this.alphaToCoverage = source.alphaToCoverage;
  5858. this.premultipliedAlpha = source.premultipliedAlpha;
  5859. this.forceSinglePass = source.forceSinglePass;
  5860. this.visible = source.visible;
  5861. this.toneMapped = source.toneMapped;
  5862. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5863. return this;
  5864. }
  5865. dispose() {
  5866. this.dispatchEvent( { type: 'dispose' } );
  5867. }
  5868. set needsUpdate( value ) {
  5869. if ( value === true ) this.version ++;
  5870. }
  5871. onBuild( /* shaderobject, renderer */ ) {
  5872. console.warn( 'Material: onBuild() has been removed.' ); // @deprecated, r166
  5873. }
  5874. }
  5875. class MeshBasicMaterial extends Material {
  5876. constructor( parameters ) {
  5877. super();
  5878. this.isMeshBasicMaterial = true;
  5879. this.type = 'MeshBasicMaterial';
  5880. this.color = new Color( 0xffffff ); // emissive
  5881. this.map = null;
  5882. this.lightMap = null;
  5883. this.lightMapIntensity = 1.0;
  5884. this.aoMap = null;
  5885. this.aoMapIntensity = 1.0;
  5886. this.specularMap = null;
  5887. this.alphaMap = null;
  5888. this.envMap = null;
  5889. this.envMapRotation = new Euler();
  5890. this.combine = MultiplyOperation;
  5891. this.reflectivity = 1;
  5892. this.refractionRatio = 0.98;
  5893. this.wireframe = false;
  5894. this.wireframeLinewidth = 1;
  5895. this.wireframeLinecap = 'round';
  5896. this.wireframeLinejoin = 'round';
  5897. this.fog = true;
  5898. this.setValues( parameters );
  5899. }
  5900. copy( source ) {
  5901. super.copy( source );
  5902. this.color.copy( source.color );
  5903. this.map = source.map;
  5904. this.lightMap = source.lightMap;
  5905. this.lightMapIntensity = source.lightMapIntensity;
  5906. this.aoMap = source.aoMap;
  5907. this.aoMapIntensity = source.aoMapIntensity;
  5908. this.specularMap = source.specularMap;
  5909. this.alphaMap = source.alphaMap;
  5910. this.envMap = source.envMap;
  5911. this.envMapRotation.copy( source.envMapRotation );
  5912. this.combine = source.combine;
  5913. this.reflectivity = source.reflectivity;
  5914. this.refractionRatio = source.refractionRatio;
  5915. this.wireframe = source.wireframe;
  5916. this.wireframeLinewidth = source.wireframeLinewidth;
  5917. this.wireframeLinecap = source.wireframeLinecap;
  5918. this.wireframeLinejoin = source.wireframeLinejoin;
  5919. this.fog = source.fog;
  5920. return this;
  5921. }
  5922. }
  5923. // Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
  5924. const _tables = /*@__PURE__*/ _generateTables();
  5925. function _generateTables() {
  5926. // float32 to float16 helpers
  5927. const buffer = new ArrayBuffer( 4 );
  5928. const floatView = new Float32Array( buffer );
  5929. const uint32View = new Uint32Array( buffer );
  5930. const baseTable = new Uint32Array( 512 );
  5931. const shiftTable = new Uint32Array( 512 );
  5932. for ( let i = 0; i < 256; ++ i ) {
  5933. const e = i - 127;
  5934. // very small number (0, -0)
  5935. if ( e < -27 ) {
  5936. baseTable[ i ] = 0x0000;
  5937. baseTable[ i | 0x100 ] = 0x8000;
  5938. shiftTable[ i ] = 24;
  5939. shiftTable[ i | 0x100 ] = 24;
  5940. // small number (denorm)
  5941. } else if ( e < -14 ) {
  5942. baseTable[ i ] = 0x0400 >> ( - e - 14 );
  5943. baseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000;
  5944. shiftTable[ i ] = - e - 1;
  5945. shiftTable[ i | 0x100 ] = - e - 1;
  5946. // normal number
  5947. } else if ( e <= 15 ) {
  5948. baseTable[ i ] = ( e + 15 ) << 10;
  5949. baseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000;
  5950. shiftTable[ i ] = 13;
  5951. shiftTable[ i | 0x100 ] = 13;
  5952. // large number (Infinity, -Infinity)
  5953. } else if ( e < 128 ) {
  5954. baseTable[ i ] = 0x7c00;
  5955. baseTable[ i | 0x100 ] = 0xfc00;
  5956. shiftTable[ i ] = 24;
  5957. shiftTable[ i | 0x100 ] = 24;
  5958. // stay (NaN, Infinity, -Infinity)
  5959. } else {
  5960. baseTable[ i ] = 0x7c00;
  5961. baseTable[ i | 0x100 ] = 0xfc00;
  5962. shiftTable[ i ] = 13;
  5963. shiftTable[ i | 0x100 ] = 13;
  5964. }
  5965. }
  5966. // float16 to float32 helpers
  5967. const mantissaTable = new Uint32Array( 2048 );
  5968. const exponentTable = new Uint32Array( 64 );
  5969. const offsetTable = new Uint32Array( 64 );
  5970. for ( let i = 1; i < 1024; ++ i ) {
  5971. let m = i << 13; // zero pad mantissa bits
  5972. let e = 0; // zero exponent
  5973. // normalized
  5974. while ( ( m & 0x00800000 ) === 0 ) {
  5975. m <<= 1;
  5976. e -= 0x00800000; // decrement exponent
  5977. }
  5978. m &= -8388609; // clear leading 1 bit
  5979. e += 0x38800000; // adjust bias
  5980. mantissaTable[ i ] = m | e;
  5981. }
  5982. for ( let i = 1024; i < 2048; ++ i ) {
  5983. mantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 );
  5984. }
  5985. for ( let i = 1; i < 31; ++ i ) {
  5986. exponentTable[ i ] = i << 23;
  5987. }
  5988. exponentTable[ 31 ] = 0x47800000;
  5989. exponentTable[ 32 ] = 0x80000000;
  5990. for ( let i = 33; i < 63; ++ i ) {
  5991. exponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 );
  5992. }
  5993. exponentTable[ 63 ] = 0xc7800000;
  5994. for ( let i = 1; i < 64; ++ i ) {
  5995. if ( i !== 32 ) {
  5996. offsetTable[ i ] = 1024;
  5997. }
  5998. }
  5999. return {
  6000. floatView: floatView,
  6001. uint32View: uint32View,
  6002. baseTable: baseTable,
  6003. shiftTable: shiftTable,
  6004. mantissaTable: mantissaTable,
  6005. exponentTable: exponentTable,
  6006. offsetTable: offsetTable
  6007. };
  6008. }
  6009. // float32 to float16
  6010. function toHalfFloat( val ) {
  6011. if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );
  6012. val = clamp( val, -65504, 65504 );
  6013. _tables.floatView[ 0 ] = val;
  6014. const f = _tables.uint32View[ 0 ];
  6015. const e = ( f >> 23 ) & 0x1ff;
  6016. return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );
  6017. }
  6018. // float16 to float32
  6019. function fromHalfFloat( val ) {
  6020. const m = val >> 10;
  6021. _tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ];
  6022. return _tables.floatView[ 0 ];
  6023. }
  6024. const DataUtils = {
  6025. toHalfFloat: toHalfFloat,
  6026. fromHalfFloat: fromHalfFloat,
  6027. };
  6028. const _vector$9 = /*@__PURE__*/ new Vector3();
  6029. const _vector2$1 = /*@__PURE__*/ new Vector2();
  6030. let _id$2 = 0;
  6031. class BufferAttribute {
  6032. constructor( array, itemSize, normalized = false ) {
  6033. if ( Array.isArray( array ) ) {
  6034. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6035. }
  6036. this.isBufferAttribute = true;
  6037. Object.defineProperty( this, 'id', { value: _id$2 ++ } );
  6038. this.name = '';
  6039. this.array = array;
  6040. this.itemSize = itemSize;
  6041. this.count = array !== undefined ? array.length / itemSize : 0;
  6042. this.normalized = normalized;
  6043. this.usage = StaticDrawUsage;
  6044. this.updateRanges = [];
  6045. this.gpuType = FloatType;
  6046. this.version = 0;
  6047. }
  6048. onUploadCallback() {}
  6049. set needsUpdate( value ) {
  6050. if ( value === true ) this.version ++;
  6051. }
  6052. setUsage( value ) {
  6053. this.usage = value;
  6054. return this;
  6055. }
  6056. addUpdateRange( start, count ) {
  6057. this.updateRanges.push( { start, count } );
  6058. }
  6059. clearUpdateRanges() {
  6060. this.updateRanges.length = 0;
  6061. }
  6062. copy( source ) {
  6063. this.name = source.name;
  6064. this.array = new source.array.constructor( source.array );
  6065. this.itemSize = source.itemSize;
  6066. this.count = source.count;
  6067. this.normalized = source.normalized;
  6068. this.usage = source.usage;
  6069. this.gpuType = source.gpuType;
  6070. return this;
  6071. }
  6072. copyAt( index1, attribute, index2 ) {
  6073. index1 *= this.itemSize;
  6074. index2 *= attribute.itemSize;
  6075. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  6076. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6077. }
  6078. return this;
  6079. }
  6080. copyArray( array ) {
  6081. this.array.set( array );
  6082. return this;
  6083. }
  6084. applyMatrix3( m ) {
  6085. if ( this.itemSize === 2 ) {
  6086. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6087. _vector2$1.fromBufferAttribute( this, i );
  6088. _vector2$1.applyMatrix3( m );
  6089. this.setXY( i, _vector2$1.x, _vector2$1.y );
  6090. }
  6091. } else if ( this.itemSize === 3 ) {
  6092. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6093. _vector$9.fromBufferAttribute( this, i );
  6094. _vector$9.applyMatrix3( m );
  6095. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6096. }
  6097. }
  6098. return this;
  6099. }
  6100. applyMatrix4( m ) {
  6101. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6102. _vector$9.fromBufferAttribute( this, i );
  6103. _vector$9.applyMatrix4( m );
  6104. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6105. }
  6106. return this;
  6107. }
  6108. applyNormalMatrix( m ) {
  6109. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6110. _vector$9.fromBufferAttribute( this, i );
  6111. _vector$9.applyNormalMatrix( m );
  6112. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6113. }
  6114. return this;
  6115. }
  6116. transformDirection( m ) {
  6117. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6118. _vector$9.fromBufferAttribute( this, i );
  6119. _vector$9.transformDirection( m );
  6120. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6121. }
  6122. return this;
  6123. }
  6124. set( value, offset = 0 ) {
  6125. // Matching BufferAttribute constructor, do not normalize the array.
  6126. this.array.set( value, offset );
  6127. return this;
  6128. }
  6129. getComponent( index, component ) {
  6130. let value = this.array[ index * this.itemSize + component ];
  6131. if ( this.normalized ) value = denormalize( value, this.array );
  6132. return value;
  6133. }
  6134. setComponent( index, component, value ) {
  6135. if ( this.normalized ) value = normalize( value, this.array );
  6136. this.array[ index * this.itemSize + component ] = value;
  6137. return this;
  6138. }
  6139. getX( index ) {
  6140. let x = this.array[ index * this.itemSize ];
  6141. if ( this.normalized ) x = denormalize( x, this.array );
  6142. return x;
  6143. }
  6144. setX( index, x ) {
  6145. if ( this.normalized ) x = normalize( x, this.array );
  6146. this.array[ index * this.itemSize ] = x;
  6147. return this;
  6148. }
  6149. getY( index ) {
  6150. let y = this.array[ index * this.itemSize + 1 ];
  6151. if ( this.normalized ) y = denormalize( y, this.array );
  6152. return y;
  6153. }
  6154. setY( index, y ) {
  6155. if ( this.normalized ) y = normalize( y, this.array );
  6156. this.array[ index * this.itemSize + 1 ] = y;
  6157. return this;
  6158. }
  6159. getZ( index ) {
  6160. let z = this.array[ index * this.itemSize + 2 ];
  6161. if ( this.normalized ) z = denormalize( z, this.array );
  6162. return z;
  6163. }
  6164. setZ( index, z ) {
  6165. if ( this.normalized ) z = normalize( z, this.array );
  6166. this.array[ index * this.itemSize + 2 ] = z;
  6167. return this;
  6168. }
  6169. getW( index ) {
  6170. let w = this.array[ index * this.itemSize + 3 ];
  6171. if ( this.normalized ) w = denormalize( w, this.array );
  6172. return w;
  6173. }
  6174. setW( index, w ) {
  6175. if ( this.normalized ) w = normalize( w, this.array );
  6176. this.array[ index * this.itemSize + 3 ] = w;
  6177. return this;
  6178. }
  6179. setXY( index, x, y ) {
  6180. index *= this.itemSize;
  6181. if ( this.normalized ) {
  6182. x = normalize( x, this.array );
  6183. y = normalize( y, this.array );
  6184. }
  6185. this.array[ index + 0 ] = x;
  6186. this.array[ index + 1 ] = y;
  6187. return this;
  6188. }
  6189. setXYZ( index, x, y, z ) {
  6190. index *= this.itemSize;
  6191. if ( this.normalized ) {
  6192. x = normalize( x, this.array );
  6193. y = normalize( y, this.array );
  6194. z = normalize( z, this.array );
  6195. }
  6196. this.array[ index + 0 ] = x;
  6197. this.array[ index + 1 ] = y;
  6198. this.array[ index + 2 ] = z;
  6199. return this;
  6200. }
  6201. setXYZW( index, x, y, z, w ) {
  6202. index *= this.itemSize;
  6203. if ( this.normalized ) {
  6204. x = normalize( x, this.array );
  6205. y = normalize( y, this.array );
  6206. z = normalize( z, this.array );
  6207. w = normalize( w, this.array );
  6208. }
  6209. this.array[ index + 0 ] = x;
  6210. this.array[ index + 1 ] = y;
  6211. this.array[ index + 2 ] = z;
  6212. this.array[ index + 3 ] = w;
  6213. return this;
  6214. }
  6215. onUpload( callback ) {
  6216. this.onUploadCallback = callback;
  6217. return this;
  6218. }
  6219. clone() {
  6220. return new this.constructor( this.array, this.itemSize ).copy( this );
  6221. }
  6222. toJSON() {
  6223. const data = {
  6224. itemSize: this.itemSize,
  6225. type: this.array.constructor.name,
  6226. array: Array.from( this.array ),
  6227. normalized: this.normalized
  6228. };
  6229. if ( this.name !== '' ) data.name = this.name;
  6230. if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
  6231. return data;
  6232. }
  6233. }
  6234. //
  6235. class Int8BufferAttribute extends BufferAttribute {
  6236. constructor( array, itemSize, normalized ) {
  6237. super( new Int8Array( array ), itemSize, normalized );
  6238. }
  6239. }
  6240. class Uint8BufferAttribute extends BufferAttribute {
  6241. constructor( array, itemSize, normalized ) {
  6242. super( new Uint8Array( array ), itemSize, normalized );
  6243. }
  6244. }
  6245. class Uint8ClampedBufferAttribute extends BufferAttribute {
  6246. constructor( array, itemSize, normalized ) {
  6247. super( new Uint8ClampedArray( array ), itemSize, normalized );
  6248. }
  6249. }
  6250. class Int16BufferAttribute extends BufferAttribute {
  6251. constructor( array, itemSize, normalized ) {
  6252. super( new Int16Array( array ), itemSize, normalized );
  6253. }
  6254. }
  6255. class Uint16BufferAttribute extends BufferAttribute {
  6256. constructor( array, itemSize, normalized ) {
  6257. super( new Uint16Array( array ), itemSize, normalized );
  6258. }
  6259. }
  6260. class Int32BufferAttribute extends BufferAttribute {
  6261. constructor( array, itemSize, normalized ) {
  6262. super( new Int32Array( array ), itemSize, normalized );
  6263. }
  6264. }
  6265. class Uint32BufferAttribute extends BufferAttribute {
  6266. constructor( array, itemSize, normalized ) {
  6267. super( new Uint32Array( array ), itemSize, normalized );
  6268. }
  6269. }
  6270. class Float16BufferAttribute extends BufferAttribute {
  6271. constructor( array, itemSize, normalized ) {
  6272. super( new Uint16Array( array ), itemSize, normalized );
  6273. this.isFloat16BufferAttribute = true;
  6274. }
  6275. getX( index ) {
  6276. let x = fromHalfFloat( this.array[ index * this.itemSize ] );
  6277. if ( this.normalized ) x = denormalize( x, this.array );
  6278. return x;
  6279. }
  6280. setX( index, x ) {
  6281. if ( this.normalized ) x = normalize( x, this.array );
  6282. this.array[ index * this.itemSize ] = toHalfFloat( x );
  6283. return this;
  6284. }
  6285. getY( index ) {
  6286. let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );
  6287. if ( this.normalized ) y = denormalize( y, this.array );
  6288. return y;
  6289. }
  6290. setY( index, y ) {
  6291. if ( this.normalized ) y = normalize( y, this.array );
  6292. this.array[ index * this.itemSize + 1 ] = toHalfFloat( y );
  6293. return this;
  6294. }
  6295. getZ( index ) {
  6296. let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );
  6297. if ( this.normalized ) z = denormalize( z, this.array );
  6298. return z;
  6299. }
  6300. setZ( index, z ) {
  6301. if ( this.normalized ) z = normalize( z, this.array );
  6302. this.array[ index * this.itemSize + 2 ] = toHalfFloat( z );
  6303. return this;
  6304. }
  6305. getW( index ) {
  6306. let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );
  6307. if ( this.normalized ) w = denormalize( w, this.array );
  6308. return w;
  6309. }
  6310. setW( index, w ) {
  6311. if ( this.normalized ) w = normalize( w, this.array );
  6312. this.array[ index * this.itemSize + 3 ] = toHalfFloat( w );
  6313. return this;
  6314. }
  6315. setXY( index, x, y ) {
  6316. index *= this.itemSize;
  6317. if ( this.normalized ) {
  6318. x = normalize( x, this.array );
  6319. y = normalize( y, this.array );
  6320. }
  6321. this.array[ index + 0 ] = toHalfFloat( x );
  6322. this.array[ index + 1 ] = toHalfFloat( y );
  6323. return this;
  6324. }
  6325. setXYZ( index, x, y, z ) {
  6326. index *= this.itemSize;
  6327. if ( this.normalized ) {
  6328. x = normalize( x, this.array );
  6329. y = normalize( y, this.array );
  6330. z = normalize( z, this.array );
  6331. }
  6332. this.array[ index + 0 ] = toHalfFloat( x );
  6333. this.array[ index + 1 ] = toHalfFloat( y );
  6334. this.array[ index + 2 ] = toHalfFloat( z );
  6335. return this;
  6336. }
  6337. setXYZW( index, x, y, z, w ) {
  6338. index *= this.itemSize;
  6339. if ( this.normalized ) {
  6340. x = normalize( x, this.array );
  6341. y = normalize( y, this.array );
  6342. z = normalize( z, this.array );
  6343. w = normalize( w, this.array );
  6344. }
  6345. this.array[ index + 0 ] = toHalfFloat( x );
  6346. this.array[ index + 1 ] = toHalfFloat( y );
  6347. this.array[ index + 2 ] = toHalfFloat( z );
  6348. this.array[ index + 3 ] = toHalfFloat( w );
  6349. return this;
  6350. }
  6351. }
  6352. class Float32BufferAttribute extends BufferAttribute {
  6353. constructor( array, itemSize, normalized ) {
  6354. super( new Float32Array( array ), itemSize, normalized );
  6355. }
  6356. }
  6357. let _id$1 = 0;
  6358. const _m1 = /*@__PURE__*/ new Matrix4();
  6359. const _obj = /*@__PURE__*/ new Object3D();
  6360. const _offset = /*@__PURE__*/ new Vector3();
  6361. const _box$2 = /*@__PURE__*/ new Box3();
  6362. const _boxMorphTargets = /*@__PURE__*/ new Box3();
  6363. const _vector$8 = /*@__PURE__*/ new Vector3();
  6364. class BufferGeometry extends EventDispatcher {
  6365. constructor() {
  6366. super();
  6367. this.isBufferGeometry = true;
  6368. Object.defineProperty( this, 'id', { value: _id$1 ++ } );
  6369. this.uuid = generateUUID();
  6370. this.name = '';
  6371. this.type = 'BufferGeometry';
  6372. this.index = null;
  6373. this.indirect = null;
  6374. this.attributes = {};
  6375. this.morphAttributes = {};
  6376. this.morphTargetsRelative = false;
  6377. this.groups = [];
  6378. this.boundingBox = null;
  6379. this.boundingSphere = null;
  6380. this.drawRange = { start: 0, count: Infinity };
  6381. this.userData = {};
  6382. }
  6383. getIndex() {
  6384. return this.index;
  6385. }
  6386. setIndex( index ) {
  6387. if ( Array.isArray( index ) ) {
  6388. this.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6389. } else {
  6390. this.index = index;
  6391. }
  6392. return this;
  6393. }
  6394. setIndirect( indirect ) {
  6395. this.indirect = indirect;
  6396. return this;
  6397. }
  6398. getIndirect() {
  6399. return this.indirect;
  6400. }
  6401. getAttribute( name ) {
  6402. return this.attributes[ name ];
  6403. }
  6404. setAttribute( name, attribute ) {
  6405. this.attributes[ name ] = attribute;
  6406. return this;
  6407. }
  6408. deleteAttribute( name ) {
  6409. delete this.attributes[ name ];
  6410. return this;
  6411. }
  6412. hasAttribute( name ) {
  6413. return this.attributes[ name ] !== undefined;
  6414. }
  6415. addGroup( start, count, materialIndex = 0 ) {
  6416. this.groups.push( {
  6417. start: start,
  6418. count: count,
  6419. materialIndex: materialIndex
  6420. } );
  6421. }
  6422. clearGroups() {
  6423. this.groups = [];
  6424. }
  6425. setDrawRange( start, count ) {
  6426. this.drawRange.start = start;
  6427. this.drawRange.count = count;
  6428. }
  6429. applyMatrix4( matrix ) {
  6430. const position = this.attributes.position;
  6431. if ( position !== undefined ) {
  6432. position.applyMatrix4( matrix );
  6433. position.needsUpdate = true;
  6434. }
  6435. const normal = this.attributes.normal;
  6436. if ( normal !== undefined ) {
  6437. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6438. normal.applyNormalMatrix( normalMatrix );
  6439. normal.needsUpdate = true;
  6440. }
  6441. const tangent = this.attributes.tangent;
  6442. if ( tangent !== undefined ) {
  6443. tangent.transformDirection( matrix );
  6444. tangent.needsUpdate = true;
  6445. }
  6446. if ( this.boundingBox !== null ) {
  6447. this.computeBoundingBox();
  6448. }
  6449. if ( this.boundingSphere !== null ) {
  6450. this.computeBoundingSphere();
  6451. }
  6452. return this;
  6453. }
  6454. applyQuaternion( q ) {
  6455. _m1.makeRotationFromQuaternion( q );
  6456. this.applyMatrix4( _m1 );
  6457. return this;
  6458. }
  6459. rotateX( angle ) {
  6460. // rotate geometry around world x-axis
  6461. _m1.makeRotationX( angle );
  6462. this.applyMatrix4( _m1 );
  6463. return this;
  6464. }
  6465. rotateY( angle ) {
  6466. // rotate geometry around world y-axis
  6467. _m1.makeRotationY( angle );
  6468. this.applyMatrix4( _m1 );
  6469. return this;
  6470. }
  6471. rotateZ( angle ) {
  6472. // rotate geometry around world z-axis
  6473. _m1.makeRotationZ( angle );
  6474. this.applyMatrix4( _m1 );
  6475. return this;
  6476. }
  6477. translate( x, y, z ) {
  6478. // translate geometry
  6479. _m1.makeTranslation( x, y, z );
  6480. this.applyMatrix4( _m1 );
  6481. return this;
  6482. }
  6483. scale( x, y, z ) {
  6484. // scale geometry
  6485. _m1.makeScale( x, y, z );
  6486. this.applyMatrix4( _m1 );
  6487. return this;
  6488. }
  6489. lookAt( vector ) {
  6490. _obj.lookAt( vector );
  6491. _obj.updateMatrix();
  6492. this.applyMatrix4( _obj.matrix );
  6493. return this;
  6494. }
  6495. center() {
  6496. this.computeBoundingBox();
  6497. this.boundingBox.getCenter( _offset ).negate();
  6498. this.translate( _offset.x, _offset.y, _offset.z );
  6499. return this;
  6500. }
  6501. setFromPoints( points ) {
  6502. const positionAttribute = this.getAttribute( 'position' );
  6503. if ( positionAttribute === undefined ) {
  6504. const position = [];
  6505. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6506. const point = points[ i ];
  6507. position.push( point.x, point.y, point.z || 0 );
  6508. }
  6509. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6510. } else {
  6511. const l = Math.min( points.length, positionAttribute.count ); // make sure data do not exceed buffer size
  6512. for ( let i = 0; i < l; i ++ ) {
  6513. const point = points[ i ];
  6514. positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 );
  6515. }
  6516. if ( points.length > positionAttribute.count ) {
  6517. console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' );
  6518. }
  6519. positionAttribute.needsUpdate = true;
  6520. }
  6521. return this;
  6522. }
  6523. computeBoundingBox() {
  6524. if ( this.boundingBox === null ) {
  6525. this.boundingBox = new Box3();
  6526. }
  6527. const position = this.attributes.position;
  6528. const morphAttributesPosition = this.morphAttributes.position;
  6529. if ( position && position.isGLBufferAttribute ) {
  6530. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );
  6531. this.boundingBox.set(
  6532. new Vector3( - Infinity, - Infinity, - Infinity ),
  6533. new Vector3( + Infinity, + Infinity, + Infinity )
  6534. );
  6535. return;
  6536. }
  6537. if ( position !== undefined ) {
  6538. this.boundingBox.setFromBufferAttribute( position );
  6539. // process morph attributes if present
  6540. if ( morphAttributesPosition ) {
  6541. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6542. const morphAttribute = morphAttributesPosition[ i ];
  6543. _box$2.setFromBufferAttribute( morphAttribute );
  6544. if ( this.morphTargetsRelative ) {
  6545. _vector$8.addVectors( this.boundingBox.min, _box$2.min );
  6546. this.boundingBox.expandByPoint( _vector$8 );
  6547. _vector$8.addVectors( this.boundingBox.max, _box$2.max );
  6548. this.boundingBox.expandByPoint( _vector$8 );
  6549. } else {
  6550. this.boundingBox.expandByPoint( _box$2.min );
  6551. this.boundingBox.expandByPoint( _box$2.max );
  6552. }
  6553. }
  6554. }
  6555. } else {
  6556. this.boundingBox.makeEmpty();
  6557. }
  6558. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6559. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6560. }
  6561. }
  6562. computeBoundingSphere() {
  6563. if ( this.boundingSphere === null ) {
  6564. this.boundingSphere = new Sphere();
  6565. }
  6566. const position = this.attributes.position;
  6567. const morphAttributesPosition = this.morphAttributes.position;
  6568. if ( position && position.isGLBufferAttribute ) {
  6569. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );
  6570. this.boundingSphere.set( new Vector3(), Infinity );
  6571. return;
  6572. }
  6573. if ( position ) {
  6574. // first, find the center of the bounding sphere
  6575. const center = this.boundingSphere.center;
  6576. _box$2.setFromBufferAttribute( position );
  6577. // process morph attributes if present
  6578. if ( morphAttributesPosition ) {
  6579. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6580. const morphAttribute = morphAttributesPosition[ i ];
  6581. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6582. if ( this.morphTargetsRelative ) {
  6583. _vector$8.addVectors( _box$2.min, _boxMorphTargets.min );
  6584. _box$2.expandByPoint( _vector$8 );
  6585. _vector$8.addVectors( _box$2.max, _boxMorphTargets.max );
  6586. _box$2.expandByPoint( _vector$8 );
  6587. } else {
  6588. _box$2.expandByPoint( _boxMorphTargets.min );
  6589. _box$2.expandByPoint( _boxMorphTargets.max );
  6590. }
  6591. }
  6592. }
  6593. _box$2.getCenter( center );
  6594. // second, try to find a boundingSphere with a radius smaller than the
  6595. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6596. let maxRadiusSq = 0;
  6597. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6598. _vector$8.fromBufferAttribute( position, i );
  6599. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6600. }
  6601. // process morph attributes if present
  6602. if ( morphAttributesPosition ) {
  6603. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6604. const morphAttribute = morphAttributesPosition[ i ];
  6605. const morphTargetsRelative = this.morphTargetsRelative;
  6606. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6607. _vector$8.fromBufferAttribute( morphAttribute, j );
  6608. if ( morphTargetsRelative ) {
  6609. _offset.fromBufferAttribute( position, j );
  6610. _vector$8.add( _offset );
  6611. }
  6612. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6613. }
  6614. }
  6615. }
  6616. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6617. if ( isNaN( this.boundingSphere.radius ) ) {
  6618. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6619. }
  6620. }
  6621. }
  6622. computeTangents() {
  6623. const index = this.index;
  6624. const attributes = this.attributes;
  6625. // based on http://www.terathon.com/code/tangent.html
  6626. // (per vertex tangents)
  6627. if ( index === null ||
  6628. attributes.position === undefined ||
  6629. attributes.normal === undefined ||
  6630. attributes.uv === undefined ) {
  6631. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  6632. return;
  6633. }
  6634. const positionAttribute = attributes.position;
  6635. const normalAttribute = attributes.normal;
  6636. const uvAttribute = attributes.uv;
  6637. if ( this.hasAttribute( 'tangent' ) === false ) {
  6638. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
  6639. }
  6640. const tangentAttribute = this.getAttribute( 'tangent' );
  6641. const tan1 = [], tan2 = [];
  6642. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  6643. tan1[ i ] = new Vector3();
  6644. tan2[ i ] = new Vector3();
  6645. }
  6646. const vA = new Vector3(),
  6647. vB = new Vector3(),
  6648. vC = new Vector3(),
  6649. uvA = new Vector2(),
  6650. uvB = new Vector2(),
  6651. uvC = new Vector2(),
  6652. sdir = new Vector3(),
  6653. tdir = new Vector3();
  6654. function handleTriangle( a, b, c ) {
  6655. vA.fromBufferAttribute( positionAttribute, a );
  6656. vB.fromBufferAttribute( positionAttribute, b );
  6657. vC.fromBufferAttribute( positionAttribute, c );
  6658. uvA.fromBufferAttribute( uvAttribute, a );
  6659. uvB.fromBufferAttribute( uvAttribute, b );
  6660. uvC.fromBufferAttribute( uvAttribute, c );
  6661. vB.sub( vA );
  6662. vC.sub( vA );
  6663. uvB.sub( uvA );
  6664. uvC.sub( uvA );
  6665. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  6666. // silently ignore degenerate uv triangles having coincident or colinear vertices
  6667. if ( ! isFinite( r ) ) return;
  6668. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  6669. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  6670. tan1[ a ].add( sdir );
  6671. tan1[ b ].add( sdir );
  6672. tan1[ c ].add( sdir );
  6673. tan2[ a ].add( tdir );
  6674. tan2[ b ].add( tdir );
  6675. tan2[ c ].add( tdir );
  6676. }
  6677. let groups = this.groups;
  6678. if ( groups.length === 0 ) {
  6679. groups = [ {
  6680. start: 0,
  6681. count: index.count
  6682. } ];
  6683. }
  6684. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6685. const group = groups[ i ];
  6686. const start = group.start;
  6687. const count = group.count;
  6688. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6689. handleTriangle(
  6690. index.getX( j + 0 ),
  6691. index.getX( j + 1 ),
  6692. index.getX( j + 2 )
  6693. );
  6694. }
  6695. }
  6696. const tmp = new Vector3(), tmp2 = new Vector3();
  6697. const n = new Vector3(), n2 = new Vector3();
  6698. function handleVertex( v ) {
  6699. n.fromBufferAttribute( normalAttribute, v );
  6700. n2.copy( n );
  6701. const t = tan1[ v ];
  6702. // Gram-Schmidt orthogonalize
  6703. tmp.copy( t );
  6704. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6705. // Calculate handedness
  6706. tmp2.crossVectors( n2, t );
  6707. const test = tmp2.dot( tan2[ v ] );
  6708. const w = ( test < 0.0 ) ? -1 : 1.0;
  6709. tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );
  6710. }
  6711. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6712. const group = groups[ i ];
  6713. const start = group.start;
  6714. const count = group.count;
  6715. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6716. handleVertex( index.getX( j + 0 ) );
  6717. handleVertex( index.getX( j + 1 ) );
  6718. handleVertex( index.getX( j + 2 ) );
  6719. }
  6720. }
  6721. }
  6722. computeVertexNormals() {
  6723. const index = this.index;
  6724. const positionAttribute = this.getAttribute( 'position' );
  6725. if ( positionAttribute !== undefined ) {
  6726. let normalAttribute = this.getAttribute( 'normal' );
  6727. if ( normalAttribute === undefined ) {
  6728. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6729. this.setAttribute( 'normal', normalAttribute );
  6730. } else {
  6731. // reset existing normals to zero
  6732. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6733. normalAttribute.setXYZ( i, 0, 0, 0 );
  6734. }
  6735. }
  6736. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6737. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6738. const cb = new Vector3(), ab = new Vector3();
  6739. // indexed elements
  6740. if ( index ) {
  6741. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6742. const vA = index.getX( i + 0 );
  6743. const vB = index.getX( i + 1 );
  6744. const vC = index.getX( i + 2 );
  6745. pA.fromBufferAttribute( positionAttribute, vA );
  6746. pB.fromBufferAttribute( positionAttribute, vB );
  6747. pC.fromBufferAttribute( positionAttribute, vC );
  6748. cb.subVectors( pC, pB );
  6749. ab.subVectors( pA, pB );
  6750. cb.cross( ab );
  6751. nA.fromBufferAttribute( normalAttribute, vA );
  6752. nB.fromBufferAttribute( normalAttribute, vB );
  6753. nC.fromBufferAttribute( normalAttribute, vC );
  6754. nA.add( cb );
  6755. nB.add( cb );
  6756. nC.add( cb );
  6757. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6758. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6759. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6760. }
  6761. } else {
  6762. // non-indexed elements (unconnected triangle soup)
  6763. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6764. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6765. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6766. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6767. cb.subVectors( pC, pB );
  6768. ab.subVectors( pA, pB );
  6769. cb.cross( ab );
  6770. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6771. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6772. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6773. }
  6774. }
  6775. this.normalizeNormals();
  6776. normalAttribute.needsUpdate = true;
  6777. }
  6778. }
  6779. normalizeNormals() {
  6780. const normals = this.attributes.normal;
  6781. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6782. _vector$8.fromBufferAttribute( normals, i );
  6783. _vector$8.normalize();
  6784. normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );
  6785. }
  6786. }
  6787. toNonIndexed() {
  6788. function convertBufferAttribute( attribute, indices ) {
  6789. const array = attribute.array;
  6790. const itemSize = attribute.itemSize;
  6791. const normalized = attribute.normalized;
  6792. const array2 = new array.constructor( indices.length * itemSize );
  6793. let index = 0, index2 = 0;
  6794. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6795. if ( attribute.isInterleavedBufferAttribute ) {
  6796. index = indices[ i ] * attribute.data.stride + attribute.offset;
  6797. } else {
  6798. index = indices[ i ] * itemSize;
  6799. }
  6800. for ( let j = 0; j < itemSize; j ++ ) {
  6801. array2[ index2 ++ ] = array[ index ++ ];
  6802. }
  6803. }
  6804. return new BufferAttribute( array2, itemSize, normalized );
  6805. }
  6806. //
  6807. if ( this.index === null ) {
  6808. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6809. return this;
  6810. }
  6811. const geometry2 = new BufferGeometry();
  6812. const indices = this.index.array;
  6813. const attributes = this.attributes;
  6814. // attributes
  6815. for ( const name in attributes ) {
  6816. const attribute = attributes[ name ];
  6817. const newAttribute = convertBufferAttribute( attribute, indices );
  6818. geometry2.setAttribute( name, newAttribute );
  6819. }
  6820. // morph attributes
  6821. const morphAttributes = this.morphAttributes;
  6822. for ( const name in morphAttributes ) {
  6823. const morphArray = [];
  6824. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6825. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6826. const attribute = morphAttribute[ i ];
  6827. const newAttribute = convertBufferAttribute( attribute, indices );
  6828. morphArray.push( newAttribute );
  6829. }
  6830. geometry2.morphAttributes[ name ] = morphArray;
  6831. }
  6832. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6833. // groups
  6834. const groups = this.groups;
  6835. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6836. const group = groups[ i ];
  6837. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6838. }
  6839. return geometry2;
  6840. }
  6841. toJSON() {
  6842. const data = {
  6843. metadata: {
  6844. version: 4.6,
  6845. type: 'BufferGeometry',
  6846. generator: 'BufferGeometry.toJSON'
  6847. }
  6848. };
  6849. // standard BufferGeometry serialization
  6850. data.uuid = this.uuid;
  6851. data.type = this.type;
  6852. if ( this.name !== '' ) data.name = this.name;
  6853. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6854. if ( this.parameters !== undefined ) {
  6855. const parameters = this.parameters;
  6856. for ( const key in parameters ) {
  6857. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6858. }
  6859. return data;
  6860. }
  6861. // for simplicity the code assumes attributes are not shared across geometries, see #15811
  6862. data.data = { attributes: {} };
  6863. const index = this.index;
  6864. if ( index !== null ) {
  6865. data.data.index = {
  6866. type: index.array.constructor.name,
  6867. array: Array.prototype.slice.call( index.array )
  6868. };
  6869. }
  6870. const attributes = this.attributes;
  6871. for ( const key in attributes ) {
  6872. const attribute = attributes[ key ];
  6873. data.data.attributes[ key ] = attribute.toJSON( data.data );
  6874. }
  6875. const morphAttributes = {};
  6876. let hasMorphAttributes = false;
  6877. for ( const key in this.morphAttributes ) {
  6878. const attributeArray = this.morphAttributes[ key ];
  6879. const array = [];
  6880. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6881. const attribute = attributeArray[ i ];
  6882. array.push( attribute.toJSON( data.data ) );
  6883. }
  6884. if ( array.length > 0 ) {
  6885. morphAttributes[ key ] = array;
  6886. hasMorphAttributes = true;
  6887. }
  6888. }
  6889. if ( hasMorphAttributes ) {
  6890. data.data.morphAttributes = morphAttributes;
  6891. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6892. }
  6893. const groups = this.groups;
  6894. if ( groups.length > 0 ) {
  6895. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6896. }
  6897. const boundingSphere = this.boundingSphere;
  6898. if ( boundingSphere !== null ) {
  6899. data.data.boundingSphere = {
  6900. center: boundingSphere.center.toArray(),
  6901. radius: boundingSphere.radius
  6902. };
  6903. }
  6904. return data;
  6905. }
  6906. clone() {
  6907. return new this.constructor().copy( this );
  6908. }
  6909. copy( source ) {
  6910. // reset
  6911. this.index = null;
  6912. this.attributes = {};
  6913. this.morphAttributes = {};
  6914. this.groups = [];
  6915. this.boundingBox = null;
  6916. this.boundingSphere = null;
  6917. // used for storing cloned, shared data
  6918. const data = {};
  6919. // name
  6920. this.name = source.name;
  6921. // index
  6922. const index = source.index;
  6923. if ( index !== null ) {
  6924. this.setIndex( index.clone( data ) );
  6925. }
  6926. // attributes
  6927. const attributes = source.attributes;
  6928. for ( const name in attributes ) {
  6929. const attribute = attributes[ name ];
  6930. this.setAttribute( name, attribute.clone( data ) );
  6931. }
  6932. // morph attributes
  6933. const morphAttributes = source.morphAttributes;
  6934. for ( const name in morphAttributes ) {
  6935. const array = [];
  6936. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6937. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6938. array.push( morphAttribute[ i ].clone( data ) );
  6939. }
  6940. this.morphAttributes[ name ] = array;
  6941. }
  6942. this.morphTargetsRelative = source.morphTargetsRelative;
  6943. // groups
  6944. const groups = source.groups;
  6945. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6946. const group = groups[ i ];
  6947. this.addGroup( group.start, group.count, group.materialIndex );
  6948. }
  6949. // bounding box
  6950. const boundingBox = source.boundingBox;
  6951. if ( boundingBox !== null ) {
  6952. this.boundingBox = boundingBox.clone();
  6953. }
  6954. // bounding sphere
  6955. const boundingSphere = source.boundingSphere;
  6956. if ( boundingSphere !== null ) {
  6957. this.boundingSphere = boundingSphere.clone();
  6958. }
  6959. // draw range
  6960. this.drawRange.start = source.drawRange.start;
  6961. this.drawRange.count = source.drawRange.count;
  6962. // user data
  6963. this.userData = source.userData;
  6964. return this;
  6965. }
  6966. dispose() {
  6967. this.dispatchEvent( { type: 'dispose' } );
  6968. }
  6969. }
  6970. const _inverseMatrix$3 = /*@__PURE__*/ new Matrix4();
  6971. const _ray$3 = /*@__PURE__*/ new Ray();
  6972. const _sphere$6 = /*@__PURE__*/ new Sphere();
  6973. const _sphereHitAt = /*@__PURE__*/ new Vector3();
  6974. const _vA$1 = /*@__PURE__*/ new Vector3();
  6975. const _vB$1 = /*@__PURE__*/ new Vector3();
  6976. const _vC$1 = /*@__PURE__*/ new Vector3();
  6977. const _tempA = /*@__PURE__*/ new Vector3();
  6978. const _morphA = /*@__PURE__*/ new Vector3();
  6979. const _intersectionPoint = /*@__PURE__*/ new Vector3();
  6980. const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
  6981. class Mesh extends Object3D {
  6982. constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6983. super();
  6984. this.isMesh = true;
  6985. this.type = 'Mesh';
  6986. this.geometry = geometry;
  6987. this.material = material;
  6988. this.updateMorphTargets();
  6989. }
  6990. copy( source, recursive ) {
  6991. super.copy( source, recursive );
  6992. if ( source.morphTargetInfluences !== undefined ) {
  6993. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6994. }
  6995. if ( source.morphTargetDictionary !== undefined ) {
  6996. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6997. }
  6998. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  6999. this.geometry = source.geometry;
  7000. return this;
  7001. }
  7002. updateMorphTargets() {
  7003. const geometry = this.geometry;
  7004. const morphAttributes = geometry.morphAttributes;
  7005. const keys = Object.keys( morphAttributes );
  7006. if ( keys.length > 0 ) {
  7007. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  7008. if ( morphAttribute !== undefined ) {
  7009. this.morphTargetInfluences = [];
  7010. this.morphTargetDictionary = {};
  7011. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  7012. const name = morphAttribute[ m ].name || String( m );
  7013. this.morphTargetInfluences.push( 0 );
  7014. this.morphTargetDictionary[ name ] = m;
  7015. }
  7016. }
  7017. }
  7018. }
  7019. getVertexPosition( index, target ) {
  7020. const geometry = this.geometry;
  7021. const position = geometry.attributes.position;
  7022. const morphPosition = geometry.morphAttributes.position;
  7023. const morphTargetsRelative = geometry.morphTargetsRelative;
  7024. target.fromBufferAttribute( position, index );
  7025. const morphInfluences = this.morphTargetInfluences;
  7026. if ( morphPosition && morphInfluences ) {
  7027. _morphA.set( 0, 0, 0 );
  7028. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  7029. const influence = morphInfluences[ i ];
  7030. const morphAttribute = morphPosition[ i ];
  7031. if ( influence === 0 ) continue;
  7032. _tempA.fromBufferAttribute( morphAttribute, index );
  7033. if ( morphTargetsRelative ) {
  7034. _morphA.addScaledVector( _tempA, influence );
  7035. } else {
  7036. _morphA.addScaledVector( _tempA.sub( target ), influence );
  7037. }
  7038. }
  7039. target.add( _morphA );
  7040. }
  7041. return target;
  7042. }
  7043. raycast( raycaster, intersects ) {
  7044. const geometry = this.geometry;
  7045. const material = this.material;
  7046. const matrixWorld = this.matrixWorld;
  7047. if ( material === undefined ) return;
  7048. // test with bounding sphere in world space
  7049. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7050. _sphere$6.copy( geometry.boundingSphere );
  7051. _sphere$6.applyMatrix4( matrixWorld );
  7052. // check distance from ray origin to bounding sphere
  7053. _ray$3.copy( raycaster.ray ).recast( raycaster.near );
  7054. if ( _sphere$6.containsPoint( _ray$3.origin ) === false ) {
  7055. if ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return;
  7056. if ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return;
  7057. }
  7058. // convert ray to local space of mesh
  7059. _inverseMatrix$3.copy( matrixWorld ).invert();
  7060. _ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 );
  7061. // test with bounding box in local space
  7062. if ( geometry.boundingBox !== null ) {
  7063. if ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return;
  7064. }
  7065. // test for intersections with geometry
  7066. this._computeIntersections( raycaster, intersects, _ray$3 );
  7067. }
  7068. _computeIntersections( raycaster, intersects, rayLocalSpace ) {
  7069. let intersection;
  7070. const geometry = this.geometry;
  7071. const material = this.material;
  7072. const index = geometry.index;
  7073. const position = geometry.attributes.position;
  7074. const uv = geometry.attributes.uv;
  7075. const uv1 = geometry.attributes.uv1;
  7076. const normal = geometry.attributes.normal;
  7077. const groups = geometry.groups;
  7078. const drawRange = geometry.drawRange;
  7079. if ( index !== null ) {
  7080. // indexed buffer geometry
  7081. if ( Array.isArray( material ) ) {
  7082. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7083. const group = groups[ i ];
  7084. const groupMaterial = material[ group.materialIndex ];
  7085. const start = Math.max( group.start, drawRange.start );
  7086. const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7087. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7088. const a = index.getX( j );
  7089. const b = index.getX( j + 1 );
  7090. const c = index.getX( j + 2 );
  7091. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7092. if ( intersection ) {
  7093. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  7094. intersection.face.materialIndex = group.materialIndex;
  7095. intersects.push( intersection );
  7096. }
  7097. }
  7098. }
  7099. } else {
  7100. const start = Math.max( 0, drawRange.start );
  7101. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  7102. for ( let i = start, il = end; i < il; i += 3 ) {
  7103. const a = index.getX( i );
  7104. const b = index.getX( i + 1 );
  7105. const c = index.getX( i + 2 );
  7106. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7107. if ( intersection ) {
  7108. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  7109. intersects.push( intersection );
  7110. }
  7111. }
  7112. }
  7113. } else if ( position !== undefined ) {
  7114. // non-indexed buffer geometry
  7115. if ( Array.isArray( material ) ) {
  7116. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7117. const group = groups[ i ];
  7118. const groupMaterial = material[ group.materialIndex ];
  7119. const start = Math.max( group.start, drawRange.start );
  7120. const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7121. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7122. const a = j;
  7123. const b = j + 1;
  7124. const c = j + 2;
  7125. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7126. if ( intersection ) {
  7127. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  7128. intersection.face.materialIndex = group.materialIndex;
  7129. intersects.push( intersection );
  7130. }
  7131. }
  7132. }
  7133. } else {
  7134. const start = Math.max( 0, drawRange.start );
  7135. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  7136. for ( let i = start, il = end; i < il; i += 3 ) {
  7137. const a = i;
  7138. const b = i + 1;
  7139. const c = i + 2;
  7140. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7141. if ( intersection ) {
  7142. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  7143. intersects.push( intersection );
  7144. }
  7145. }
  7146. }
  7147. }
  7148. }
  7149. }
  7150. function checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) {
  7151. let intersect;
  7152. if ( material.side === BackSide ) {
  7153. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  7154. } else {
  7155. intersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point );
  7156. }
  7157. if ( intersect === null ) return null;
  7158. _intersectionPointWorld.copy( point );
  7159. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  7160. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  7161. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  7162. return {
  7163. distance: distance,
  7164. point: _intersectionPointWorld.clone(),
  7165. object: object
  7166. };
  7167. }
  7168. function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) {
  7169. object.getVertexPosition( a, _vA$1 );
  7170. object.getVertexPosition( b, _vB$1 );
  7171. object.getVertexPosition( c, _vC$1 );
  7172. const intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );
  7173. if ( intersection ) {
  7174. const barycoord = new Vector3();
  7175. Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord );
  7176. if ( uv ) {
  7177. intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() );
  7178. }
  7179. if ( uv1 ) {
  7180. intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() );
  7181. }
  7182. if ( normal ) {
  7183. intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );
  7184. if ( intersection.normal.dot( ray.direction ) > 0 ) {
  7185. intersection.normal.multiplyScalar( -1 );
  7186. }
  7187. }
  7188. const face = {
  7189. a: a,
  7190. b: b,
  7191. c: c,
  7192. normal: new Vector3(),
  7193. materialIndex: 0
  7194. };
  7195. Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
  7196. intersection.face = face;
  7197. intersection.barycoord = barycoord;
  7198. }
  7199. return intersection;
  7200. }
  7201. class BoxGeometry extends BufferGeometry {
  7202. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  7203. super();
  7204. this.type = 'BoxGeometry';
  7205. this.parameters = {
  7206. width: width,
  7207. height: height,
  7208. depth: depth,
  7209. widthSegments: widthSegments,
  7210. heightSegments: heightSegments,
  7211. depthSegments: depthSegments
  7212. };
  7213. const scope = this;
  7214. // segments
  7215. widthSegments = Math.floor( widthSegments );
  7216. heightSegments = Math.floor( heightSegments );
  7217. depthSegments = Math.floor( depthSegments );
  7218. // buffers
  7219. const indices = [];
  7220. const vertices = [];
  7221. const normals = [];
  7222. const uvs = [];
  7223. // helper variables
  7224. let numberOfVertices = 0;
  7225. let groupStart = 0;
  7226. // build each side of the box geometry
  7227. buildPlane( 'z', 'y', 'x', -1, -1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7228. buildPlane( 'z', 'y', 'x', 1, -1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7229. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7230. buildPlane( 'x', 'z', 'y', 1, -1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7231. buildPlane( 'x', 'y', 'z', 1, -1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7232. buildPlane( 'x', 'y', 'z', -1, -1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7233. // build geometry
  7234. this.setIndex( indices );
  7235. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7236. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7237. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7238. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7239. const segmentWidth = width / gridX;
  7240. const segmentHeight = height / gridY;
  7241. const widthHalf = width / 2;
  7242. const heightHalf = height / 2;
  7243. const depthHalf = depth / 2;
  7244. const gridX1 = gridX + 1;
  7245. const gridY1 = gridY + 1;
  7246. let vertexCounter = 0;
  7247. let groupCount = 0;
  7248. const vector = new Vector3();
  7249. // generate vertices, normals and uvs
  7250. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7251. const y = iy * segmentHeight - heightHalf;
  7252. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7253. const x = ix * segmentWidth - widthHalf;
  7254. // set values to correct vector component
  7255. vector[ u ] = x * udir;
  7256. vector[ v ] = y * vdir;
  7257. vector[ w ] = depthHalf;
  7258. // now apply vector to vertex buffer
  7259. vertices.push( vector.x, vector.y, vector.z );
  7260. // set values to correct vector component
  7261. vector[ u ] = 0;
  7262. vector[ v ] = 0;
  7263. vector[ w ] = depth > 0 ? 1 : -1;
  7264. // now apply vector to normal buffer
  7265. normals.push( vector.x, vector.y, vector.z );
  7266. // uvs
  7267. uvs.push( ix / gridX );
  7268. uvs.push( 1 - ( iy / gridY ) );
  7269. // counters
  7270. vertexCounter += 1;
  7271. }
  7272. }
  7273. // indices
  7274. // 1. you need three indices to draw a single face
  7275. // 2. a single segment consists of two faces
  7276. // 3. so we need to generate six (2*3) indices per segment
  7277. for ( let iy = 0; iy < gridY; iy ++ ) {
  7278. for ( let ix = 0; ix < gridX; ix ++ ) {
  7279. const a = numberOfVertices + ix + gridX1 * iy;
  7280. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7281. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7282. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7283. // faces
  7284. indices.push( a, b, d );
  7285. indices.push( b, c, d );
  7286. // increase counter
  7287. groupCount += 6;
  7288. }
  7289. }
  7290. // add a group to the geometry. this will ensure multi material support
  7291. scope.addGroup( groupStart, groupCount, materialIndex );
  7292. // calculate new start value for groups
  7293. groupStart += groupCount;
  7294. // update total number of vertices
  7295. numberOfVertices += vertexCounter;
  7296. }
  7297. }
  7298. copy( source ) {
  7299. super.copy( source );
  7300. this.parameters = Object.assign( {}, source.parameters );
  7301. return this;
  7302. }
  7303. static fromJSON( data ) {
  7304. return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
  7305. }
  7306. }
  7307. /**
  7308. * Uniform Utilities
  7309. */
  7310. function cloneUniforms( src ) {
  7311. const dst = {};
  7312. for ( const u in src ) {
  7313. dst[ u ] = {};
  7314. for ( const p in src[ u ] ) {
  7315. const property = src[ u ][ p ];
  7316. if ( property && ( property.isColor ||
  7317. property.isMatrix3 || property.isMatrix4 ||
  7318. property.isVector2 || property.isVector3 || property.isVector4 ||
  7319. property.isTexture || property.isQuaternion ) ) {
  7320. if ( property.isRenderTargetTexture ) {
  7321. console.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' );
  7322. dst[ u ][ p ] = null;
  7323. } else {
  7324. dst[ u ][ p ] = property.clone();
  7325. }
  7326. } else if ( Array.isArray( property ) ) {
  7327. dst[ u ][ p ] = property.slice();
  7328. } else {
  7329. dst[ u ][ p ] = property;
  7330. }
  7331. }
  7332. }
  7333. return dst;
  7334. }
  7335. function mergeUniforms( uniforms ) {
  7336. const merged = {};
  7337. for ( let u = 0; u < uniforms.length; u ++ ) {
  7338. const tmp = cloneUniforms( uniforms[ u ] );
  7339. for ( const p in tmp ) {
  7340. merged[ p ] = tmp[ p ];
  7341. }
  7342. }
  7343. return merged;
  7344. }
  7345. function cloneUniformsGroups( src ) {
  7346. const dst = [];
  7347. for ( let u = 0; u < src.length; u ++ ) {
  7348. dst.push( src[ u ].clone() );
  7349. }
  7350. return dst;
  7351. }
  7352. function getUnlitUniformColorSpace( renderer ) {
  7353. const currentRenderTarget = renderer.getRenderTarget();
  7354. if ( currentRenderTarget === null ) {
  7355. // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
  7356. return renderer.outputColorSpace;
  7357. }
  7358. // https://github.com/mrdoob/three.js/issues/27868
  7359. if ( currentRenderTarget.isXRRenderTarget === true ) {
  7360. return currentRenderTarget.texture.colorSpace;
  7361. }
  7362. return ColorManagement.workingColorSpace;
  7363. }
  7364. // Legacy
  7365. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7366. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7367. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7368. class ShaderMaterial extends Material {
  7369. constructor( parameters ) {
  7370. super();
  7371. this.isShaderMaterial = true;
  7372. this.type = 'ShaderMaterial';
  7373. this.defines = {};
  7374. this.uniforms = {};
  7375. this.uniformsGroups = [];
  7376. this.vertexShader = default_vertex;
  7377. this.fragmentShader = default_fragment;
  7378. this.linewidth = 1;
  7379. this.wireframe = false;
  7380. this.wireframeLinewidth = 1;
  7381. this.fog = false; // set to use scene fog
  7382. this.lights = false; // set to use scene lights
  7383. this.clipping = false; // set to use user-defined clipping planes
  7384. this.forceSinglePass = true;
  7385. this.extensions = {
  7386. clipCullDistance: false, // set to use vertex shader clipping
  7387. multiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID
  7388. };
  7389. // When rendered geometry doesn't include these attributes but the material does,
  7390. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7391. this.defaultAttributeValues = {
  7392. 'color': [ 1, 1, 1 ],
  7393. 'uv': [ 0, 0 ],
  7394. 'uv1': [ 0, 0 ]
  7395. };
  7396. this.index0AttributeName = undefined;
  7397. this.uniformsNeedUpdate = false;
  7398. this.glslVersion = null;
  7399. if ( parameters !== undefined ) {
  7400. this.setValues( parameters );
  7401. }
  7402. }
  7403. copy( source ) {
  7404. super.copy( source );
  7405. this.fragmentShader = source.fragmentShader;
  7406. this.vertexShader = source.vertexShader;
  7407. this.uniforms = cloneUniforms( source.uniforms );
  7408. this.uniformsGroups = cloneUniformsGroups( source.uniformsGroups );
  7409. this.defines = Object.assign( {}, source.defines );
  7410. this.wireframe = source.wireframe;
  7411. this.wireframeLinewidth = source.wireframeLinewidth;
  7412. this.fog = source.fog;
  7413. this.lights = source.lights;
  7414. this.clipping = source.clipping;
  7415. this.extensions = Object.assign( {}, source.extensions );
  7416. this.glslVersion = source.glslVersion;
  7417. return this;
  7418. }
  7419. toJSON( meta ) {
  7420. const data = super.toJSON( meta );
  7421. data.glslVersion = this.glslVersion;
  7422. data.uniforms = {};
  7423. for ( const name in this.uniforms ) {
  7424. const uniform = this.uniforms[ name ];
  7425. const value = uniform.value;
  7426. if ( value && value.isTexture ) {
  7427. data.uniforms[ name ] = {
  7428. type: 't',
  7429. value: value.toJSON( meta ).uuid
  7430. };
  7431. } else if ( value && value.isColor ) {
  7432. data.uniforms[ name ] = {
  7433. type: 'c',
  7434. value: value.getHex()
  7435. };
  7436. } else if ( value && value.isVector2 ) {
  7437. data.uniforms[ name ] = {
  7438. type: 'v2',
  7439. value: value.toArray()
  7440. };
  7441. } else if ( value && value.isVector3 ) {
  7442. data.uniforms[ name ] = {
  7443. type: 'v3',
  7444. value: value.toArray()
  7445. };
  7446. } else if ( value && value.isVector4 ) {
  7447. data.uniforms[ name ] = {
  7448. type: 'v4',
  7449. value: value.toArray()
  7450. };
  7451. } else if ( value && value.isMatrix3 ) {
  7452. data.uniforms[ name ] = {
  7453. type: 'm3',
  7454. value: value.toArray()
  7455. };
  7456. } else if ( value && value.isMatrix4 ) {
  7457. data.uniforms[ name ] = {
  7458. type: 'm4',
  7459. value: value.toArray()
  7460. };
  7461. } else {
  7462. data.uniforms[ name ] = {
  7463. value: value
  7464. };
  7465. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7466. }
  7467. }
  7468. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7469. data.vertexShader = this.vertexShader;
  7470. data.fragmentShader = this.fragmentShader;
  7471. data.lights = this.lights;
  7472. data.clipping = this.clipping;
  7473. const extensions = {};
  7474. for ( const key in this.extensions ) {
  7475. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7476. }
  7477. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7478. return data;
  7479. }
  7480. }
  7481. class Camera extends Object3D {
  7482. constructor() {
  7483. super();
  7484. this.isCamera = true;
  7485. this.type = 'Camera';
  7486. this.matrixWorldInverse = new Matrix4();
  7487. this.projectionMatrix = new Matrix4();
  7488. this.projectionMatrixInverse = new Matrix4();
  7489. this.coordinateSystem = WebGLCoordinateSystem;
  7490. }
  7491. copy( source, recursive ) {
  7492. super.copy( source, recursive );
  7493. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7494. this.projectionMatrix.copy( source.projectionMatrix );
  7495. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7496. this.coordinateSystem = source.coordinateSystem;
  7497. return this;
  7498. }
  7499. getWorldDirection( target ) {
  7500. return super.getWorldDirection( target ).negate();
  7501. }
  7502. updateMatrixWorld( force ) {
  7503. super.updateMatrixWorld( force );
  7504. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7505. }
  7506. updateWorldMatrix( updateParents, updateChildren ) {
  7507. super.updateWorldMatrix( updateParents, updateChildren );
  7508. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7509. }
  7510. clone() {
  7511. return new this.constructor().copy( this );
  7512. }
  7513. }
  7514. const _v3$1 = /*@__PURE__*/ new Vector3();
  7515. const _minTarget = /*@__PURE__*/ new Vector2();
  7516. const _maxTarget = /*@__PURE__*/ new Vector2();
  7517. class PerspectiveCamera extends Camera {
  7518. constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7519. super();
  7520. this.isPerspectiveCamera = true;
  7521. this.type = 'PerspectiveCamera';
  7522. this.fov = fov;
  7523. this.zoom = 1;
  7524. this.near = near;
  7525. this.far = far;
  7526. this.focus = 10;
  7527. this.aspect = aspect;
  7528. this.view = null;
  7529. this.filmGauge = 35; // width of the film (default in millimeters)
  7530. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7531. this.updateProjectionMatrix();
  7532. }
  7533. copy( source, recursive ) {
  7534. super.copy( source, recursive );
  7535. this.fov = source.fov;
  7536. this.zoom = source.zoom;
  7537. this.near = source.near;
  7538. this.far = source.far;
  7539. this.focus = source.focus;
  7540. this.aspect = source.aspect;
  7541. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7542. this.filmGauge = source.filmGauge;
  7543. this.filmOffset = source.filmOffset;
  7544. return this;
  7545. }
  7546. /**
  7547. * Sets the FOV by focal length in respect to the current .filmGauge.
  7548. *
  7549. * The default film gauge is 35, so that the focal length can be specified for
  7550. * a 35mm (full frame) camera.
  7551. *
  7552. * @param {number} focalLength - Values for focal length and film gauge must have the same unit.
  7553. */
  7554. setFocalLength( focalLength ) {
  7555. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  7556. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7557. this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
  7558. this.updateProjectionMatrix();
  7559. }
  7560. /**
  7561. * Calculates the focal length from the current .fov and .filmGauge.
  7562. *
  7563. * @returns {number}
  7564. */
  7565. getFocalLength() {
  7566. const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
  7567. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7568. }
  7569. getEffectiveFOV() {
  7570. return RAD2DEG * 2 * Math.atan(
  7571. Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7572. }
  7573. getFilmWidth() {
  7574. // film not completely covered in portrait format (aspect < 1)
  7575. return this.filmGauge * Math.min( this.aspect, 1 );
  7576. }
  7577. getFilmHeight() {
  7578. // film not completely covered in landscape format (aspect > 1)
  7579. return this.filmGauge / Math.max( this.aspect, 1 );
  7580. }
  7581. /**
  7582. * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  7583. * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
  7584. *
  7585. * @param {number} distance
  7586. * @param {Vector2} minTarget
  7587. * @param {Vector2} maxTarget
  7588. */
  7589. getViewBounds( distance, minTarget, maxTarget ) {
  7590. _v3$1.set( -1, -1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7591. minTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7592. _v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7593. maxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7594. }
  7595. /**
  7596. * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
  7597. *
  7598. * @param {number} distance
  7599. * @param {Vector2} target - Vector2 target used to store result where x is width and y is height.
  7600. * @returns {Vector2}
  7601. */
  7602. getViewSize( distance, target ) {
  7603. this.getViewBounds( distance, _minTarget, _maxTarget );
  7604. return target.subVectors( _maxTarget, _minTarget );
  7605. }
  7606. /**
  7607. * Sets an offset in a larger frustum. This is useful for multi-window or
  7608. * multi-monitor/multi-machine setups.
  7609. *
  7610. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7611. * the monitors are in grid like this
  7612. *
  7613. * +---+---+---+
  7614. * | A | B | C |
  7615. * +---+---+---+
  7616. * | D | E | F |
  7617. * +---+---+---+
  7618. *
  7619. * then for each monitor you would call it like this
  7620. *
  7621. * const w = 1920;
  7622. * const h = 1080;
  7623. * const fullWidth = w * 3;
  7624. * const fullHeight = h * 2;
  7625. *
  7626. * --A--
  7627. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7628. * --B--
  7629. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7630. * --C--
  7631. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7632. * --D--
  7633. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7634. * --E--
  7635. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7636. * --F--
  7637. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7638. *
  7639. * Note there is no reason monitors have to be the same size or in a grid.
  7640. *
  7641. * @param {number} fullWidth
  7642. * @param {number} fullHeight
  7643. * @param {number} x
  7644. * @param {number} y
  7645. * @param {number} width
  7646. * @param {number} height
  7647. */
  7648. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  7649. this.aspect = fullWidth / fullHeight;
  7650. if ( this.view === null ) {
  7651. this.view = {
  7652. enabled: true,
  7653. fullWidth: 1,
  7654. fullHeight: 1,
  7655. offsetX: 0,
  7656. offsetY: 0,
  7657. width: 1,
  7658. height: 1
  7659. };
  7660. }
  7661. this.view.enabled = true;
  7662. this.view.fullWidth = fullWidth;
  7663. this.view.fullHeight = fullHeight;
  7664. this.view.offsetX = x;
  7665. this.view.offsetY = y;
  7666. this.view.width = width;
  7667. this.view.height = height;
  7668. this.updateProjectionMatrix();
  7669. }
  7670. clearViewOffset() {
  7671. if ( this.view !== null ) {
  7672. this.view.enabled = false;
  7673. }
  7674. this.updateProjectionMatrix();
  7675. }
  7676. updateProjectionMatrix() {
  7677. const near = this.near;
  7678. let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7679. let height = 2 * top;
  7680. let width = this.aspect * height;
  7681. let left = -0.5 * width;
  7682. const view = this.view;
  7683. if ( this.view !== null && this.view.enabled ) {
  7684. const fullWidth = view.fullWidth,
  7685. fullHeight = view.fullHeight;
  7686. left += view.offsetX * width / fullWidth;
  7687. top -= view.offsetY * height / fullHeight;
  7688. width *= view.width / fullWidth;
  7689. height *= view.height / fullHeight;
  7690. }
  7691. const skew = this.filmOffset;
  7692. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7693. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
  7694. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7695. }
  7696. toJSON( meta ) {
  7697. const data = super.toJSON( meta );
  7698. data.object.fov = this.fov;
  7699. data.object.zoom = this.zoom;
  7700. data.object.near = this.near;
  7701. data.object.far = this.far;
  7702. data.object.focus = this.focus;
  7703. data.object.aspect = this.aspect;
  7704. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7705. data.object.filmGauge = this.filmGauge;
  7706. data.object.filmOffset = this.filmOffset;
  7707. return data;
  7708. }
  7709. }
  7710. const fov = -90; // negative fov is not an error
  7711. const aspect = 1;
  7712. class CubeCamera extends Object3D {
  7713. constructor( near, far, renderTarget ) {
  7714. super();
  7715. this.type = 'CubeCamera';
  7716. this.renderTarget = renderTarget;
  7717. this.coordinateSystem = null;
  7718. this.activeMipmapLevel = 0;
  7719. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7720. cameraPX.layers = this.layers;
  7721. this.add( cameraPX );
  7722. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7723. cameraNX.layers = this.layers;
  7724. this.add( cameraNX );
  7725. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7726. cameraPY.layers = this.layers;
  7727. this.add( cameraPY );
  7728. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7729. cameraNY.layers = this.layers;
  7730. this.add( cameraNY );
  7731. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7732. cameraPZ.layers = this.layers;
  7733. this.add( cameraPZ );
  7734. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7735. cameraNZ.layers = this.layers;
  7736. this.add( cameraNZ );
  7737. }
  7738. updateCoordinateSystem() {
  7739. const coordinateSystem = this.coordinateSystem;
  7740. const cameras = this.children.concat();
  7741. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
  7742. for ( const camera of cameras ) this.remove( camera );
  7743. if ( coordinateSystem === WebGLCoordinateSystem ) {
  7744. cameraPX.up.set( 0, 1, 0 );
  7745. cameraPX.lookAt( 1, 0, 0 );
  7746. cameraNX.up.set( 0, 1, 0 );
  7747. cameraNX.lookAt( -1, 0, 0 );
  7748. cameraPY.up.set( 0, 0, -1 );
  7749. cameraPY.lookAt( 0, 1, 0 );
  7750. cameraNY.up.set( 0, 0, 1 );
  7751. cameraNY.lookAt( 0, -1, 0 );
  7752. cameraPZ.up.set( 0, 1, 0 );
  7753. cameraPZ.lookAt( 0, 0, 1 );
  7754. cameraNZ.up.set( 0, 1, 0 );
  7755. cameraNZ.lookAt( 0, 0, -1 );
  7756. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  7757. cameraPX.up.set( 0, -1, 0 );
  7758. cameraPX.lookAt( -1, 0, 0 );
  7759. cameraNX.up.set( 0, -1, 0 );
  7760. cameraNX.lookAt( 1, 0, 0 );
  7761. cameraPY.up.set( 0, 0, 1 );
  7762. cameraPY.lookAt( 0, 1, 0 );
  7763. cameraNY.up.set( 0, 0, -1 );
  7764. cameraNY.lookAt( 0, -1, 0 );
  7765. cameraPZ.up.set( 0, -1, 0 );
  7766. cameraPZ.lookAt( 0, 0, 1 );
  7767. cameraNZ.up.set( 0, -1, 0 );
  7768. cameraNZ.lookAt( 0, 0, -1 );
  7769. } else {
  7770. throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
  7771. }
  7772. for ( const camera of cameras ) {
  7773. this.add( camera );
  7774. camera.updateMatrixWorld();
  7775. }
  7776. }
  7777. update( renderer, scene ) {
  7778. if ( this.parent === null ) this.updateMatrixWorld();
  7779. const { renderTarget, activeMipmapLevel } = this;
  7780. if ( this.coordinateSystem !== renderer.coordinateSystem ) {
  7781. this.coordinateSystem = renderer.coordinateSystem;
  7782. this.updateCoordinateSystem();
  7783. }
  7784. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7785. const currentRenderTarget = renderer.getRenderTarget();
  7786. const currentActiveCubeFace = renderer.getActiveCubeFace();
  7787. const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
  7788. const currentXrEnabled = renderer.xr.enabled;
  7789. renderer.xr.enabled = false;
  7790. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7791. renderTarget.texture.generateMipmaps = false;
  7792. renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
  7793. renderer.render( scene, cameraPX );
  7794. renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
  7795. renderer.render( scene, cameraNX );
  7796. renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
  7797. renderer.render( scene, cameraPY );
  7798. renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
  7799. renderer.render( scene, cameraNY );
  7800. renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
  7801. renderer.render( scene, cameraPZ );
  7802. // mipmaps are generated during the last call of render()
  7803. // at this point, all sides of the cube render target are defined
  7804. renderTarget.texture.generateMipmaps = generateMipmaps;
  7805. renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
  7806. renderer.render( scene, cameraNZ );
  7807. renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
  7808. renderer.xr.enabled = currentXrEnabled;
  7809. renderTarget.texture.needsPMREMUpdate = true;
  7810. }
  7811. }
  7812. class CubeTexture extends Texture {
  7813. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {
  7814. images = images !== undefined ? images : [];
  7815. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7816. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  7817. this.isCubeTexture = true;
  7818. this.flipY = false;
  7819. }
  7820. get images() {
  7821. return this.image;
  7822. }
  7823. set images( value ) {
  7824. this.image = value;
  7825. }
  7826. }
  7827. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7828. constructor( size = 1, options = {} ) {
  7829. super( size, size, options );
  7830. this.isWebGLCubeRenderTarget = true;
  7831. const image = { width: size, height: size, depth: 1 };
  7832. const images = [ image, image, image, image, image, image ];
  7833. this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  7834. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7835. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7836. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7837. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7838. // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
  7839. // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
  7840. this.texture.isRenderTargetTexture = true;
  7841. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7842. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7843. }
  7844. fromEquirectangularTexture( renderer, texture ) {
  7845. this.texture.type = texture.type;
  7846. this.texture.colorSpace = texture.colorSpace;
  7847. this.texture.generateMipmaps = texture.generateMipmaps;
  7848. this.texture.minFilter = texture.minFilter;
  7849. this.texture.magFilter = texture.magFilter;
  7850. const shader = {
  7851. uniforms: {
  7852. tEquirect: { value: null },
  7853. },
  7854. vertexShader: /* glsl */`
  7855. varying vec3 vWorldDirection;
  7856. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7857. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7858. }
  7859. void main() {
  7860. vWorldDirection = transformDirection( position, modelMatrix );
  7861. #include <begin_vertex>
  7862. #include <project_vertex>
  7863. }
  7864. `,
  7865. fragmentShader: /* glsl */`
  7866. uniform sampler2D tEquirect;
  7867. varying vec3 vWorldDirection;
  7868. #include <common>
  7869. void main() {
  7870. vec3 direction = normalize( vWorldDirection );
  7871. vec2 sampleUV = equirectUv( direction );
  7872. gl_FragColor = texture2D( tEquirect, sampleUV );
  7873. }
  7874. `
  7875. };
  7876. const geometry = new BoxGeometry( 5, 5, 5 );
  7877. const material = new ShaderMaterial( {
  7878. name: 'CubemapFromEquirect',
  7879. uniforms: cloneUniforms( shader.uniforms ),
  7880. vertexShader: shader.vertexShader,
  7881. fragmentShader: shader.fragmentShader,
  7882. side: BackSide,
  7883. blending: NoBlending
  7884. } );
  7885. material.uniforms.tEquirect.value = texture;
  7886. const mesh = new Mesh( geometry, material );
  7887. const currentMinFilter = texture.minFilter;
  7888. // Avoid blurred poles
  7889. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7890. const camera = new CubeCamera( 1, 10, this );
  7891. camera.update( renderer, mesh );
  7892. texture.minFilter = currentMinFilter;
  7893. mesh.geometry.dispose();
  7894. mesh.material.dispose();
  7895. return this;
  7896. }
  7897. clear( renderer, color, depth, stencil ) {
  7898. const currentRenderTarget = renderer.getRenderTarget();
  7899. for ( let i = 0; i < 6; i ++ ) {
  7900. renderer.setRenderTarget( this, i );
  7901. renderer.clear( color, depth, stencil );
  7902. }
  7903. renderer.setRenderTarget( currentRenderTarget );
  7904. }
  7905. }
  7906. class Group extends Object3D {
  7907. constructor() {
  7908. super();
  7909. this.isGroup = true;
  7910. this.type = 'Group';
  7911. }
  7912. }
  7913. const _moveEvent = { type: 'move' };
  7914. class WebXRController {
  7915. constructor() {
  7916. this._targetRay = null;
  7917. this._grip = null;
  7918. this._hand = null;
  7919. }
  7920. getHandSpace() {
  7921. if ( this._hand === null ) {
  7922. this._hand = new Group();
  7923. this._hand.matrixAutoUpdate = false;
  7924. this._hand.visible = false;
  7925. this._hand.joints = {};
  7926. this._hand.inputState = { pinching: false };
  7927. }
  7928. return this._hand;
  7929. }
  7930. getTargetRaySpace() {
  7931. if ( this._targetRay === null ) {
  7932. this._targetRay = new Group();
  7933. this._targetRay.matrixAutoUpdate = false;
  7934. this._targetRay.visible = false;
  7935. this._targetRay.hasLinearVelocity = false;
  7936. this._targetRay.linearVelocity = new Vector3();
  7937. this._targetRay.hasAngularVelocity = false;
  7938. this._targetRay.angularVelocity = new Vector3();
  7939. }
  7940. return this._targetRay;
  7941. }
  7942. getGripSpace() {
  7943. if ( this._grip === null ) {
  7944. this._grip = new Group();
  7945. this._grip.matrixAutoUpdate = false;
  7946. this._grip.visible = false;
  7947. this._grip.hasLinearVelocity = false;
  7948. this._grip.linearVelocity = new Vector3();
  7949. this._grip.hasAngularVelocity = false;
  7950. this._grip.angularVelocity = new Vector3();
  7951. }
  7952. return this._grip;
  7953. }
  7954. dispatchEvent( event ) {
  7955. if ( this._targetRay !== null ) {
  7956. this._targetRay.dispatchEvent( event );
  7957. }
  7958. if ( this._grip !== null ) {
  7959. this._grip.dispatchEvent( event );
  7960. }
  7961. if ( this._hand !== null ) {
  7962. this._hand.dispatchEvent( event );
  7963. }
  7964. return this;
  7965. }
  7966. connect( inputSource ) {
  7967. if ( inputSource && inputSource.hand ) {
  7968. const hand = this._hand;
  7969. if ( hand ) {
  7970. for ( const inputjoint of inputSource.hand.values() ) {
  7971. // Initialize hand with joints when connected
  7972. this._getHandJoint( hand, inputjoint );
  7973. }
  7974. }
  7975. }
  7976. this.dispatchEvent( { type: 'connected', data: inputSource } );
  7977. return this;
  7978. }
  7979. disconnect( inputSource ) {
  7980. this.dispatchEvent( { type: 'disconnected', data: inputSource } );
  7981. if ( this._targetRay !== null ) {
  7982. this._targetRay.visible = false;
  7983. }
  7984. if ( this._grip !== null ) {
  7985. this._grip.visible = false;
  7986. }
  7987. if ( this._hand !== null ) {
  7988. this._hand.visible = false;
  7989. }
  7990. return this;
  7991. }
  7992. update( inputSource, frame, referenceSpace ) {
  7993. let inputPose = null;
  7994. let gripPose = null;
  7995. let handPose = null;
  7996. const targetRay = this._targetRay;
  7997. const grip = this._grip;
  7998. const hand = this._hand;
  7999. if ( inputSource && frame.session.visibilityState !== 'visible-blurred' ) {
  8000. if ( hand && inputSource.hand ) {
  8001. handPose = true;
  8002. for ( const inputjoint of inputSource.hand.values() ) {
  8003. // Update the joints groups with the XRJoint poses
  8004. const jointPose = frame.getJointPose( inputjoint, referenceSpace );
  8005. // The transform of this joint will be updated with the joint pose on each frame
  8006. const joint = this._getHandJoint( hand, inputjoint );
  8007. if ( jointPose !== null ) {
  8008. joint.matrix.fromArray( jointPose.transform.matrix );
  8009. joint.matrix.decompose( joint.position, joint.rotation, joint.scale );
  8010. joint.matrixWorldNeedsUpdate = true;
  8011. joint.jointRadius = jointPose.radius;
  8012. }
  8013. joint.visible = jointPose !== null;
  8014. }
  8015. // Custom events
  8016. // Check pinchz
  8017. const indexTip = hand.joints[ 'index-finger-tip' ];
  8018. const thumbTip = hand.joints[ 'thumb-tip' ];
  8019. const distance = indexTip.position.distanceTo( thumbTip.position );
  8020. const distanceToPinch = 0.02;
  8021. const threshold = 0.005;
  8022. if ( hand.inputState.pinching && distance > distanceToPinch + threshold ) {
  8023. hand.inputState.pinching = false;
  8024. this.dispatchEvent( {
  8025. type: 'pinchend',
  8026. handedness: inputSource.handedness,
  8027. target: this
  8028. } );
  8029. } else if ( ! hand.inputState.pinching && distance <= distanceToPinch - threshold ) {
  8030. hand.inputState.pinching = true;
  8031. this.dispatchEvent( {
  8032. type: 'pinchstart',
  8033. handedness: inputSource.handedness,
  8034. target: this
  8035. } );
  8036. }
  8037. } else {
  8038. if ( grip !== null && inputSource.gripSpace ) {
  8039. gripPose = frame.getPose( inputSource.gripSpace, referenceSpace );
  8040. if ( gripPose !== null ) {
  8041. grip.matrix.fromArray( gripPose.transform.matrix );
  8042. grip.matrix.decompose( grip.position, grip.rotation, grip.scale );
  8043. grip.matrixWorldNeedsUpdate = true;
  8044. if ( gripPose.linearVelocity ) {
  8045. grip.hasLinearVelocity = true;
  8046. grip.linearVelocity.copy( gripPose.linearVelocity );
  8047. } else {
  8048. grip.hasLinearVelocity = false;
  8049. }
  8050. if ( gripPose.angularVelocity ) {
  8051. grip.hasAngularVelocity = true;
  8052. grip.angularVelocity.copy( gripPose.angularVelocity );
  8053. } else {
  8054. grip.hasAngularVelocity = false;
  8055. }
  8056. }
  8057. }
  8058. }
  8059. if ( targetRay !== null ) {
  8060. inputPose = frame.getPose( inputSource.targetRaySpace, referenceSpace );
  8061. // Some runtimes (namely Vive Cosmos with Vive OpenXR Runtime) have only grip space and ray space is equal to it
  8062. if ( inputPose === null && gripPose !== null ) {
  8063. inputPose = gripPose;
  8064. }
  8065. if ( inputPose !== null ) {
  8066. targetRay.matrix.fromArray( inputPose.transform.matrix );
  8067. targetRay.matrix.decompose( targetRay.position, targetRay.rotation, targetRay.scale );
  8068. targetRay.matrixWorldNeedsUpdate = true;
  8069. if ( inputPose.linearVelocity ) {
  8070. targetRay.hasLinearVelocity = true;
  8071. targetRay.linearVelocity.copy( inputPose.linearVelocity );
  8072. } else {
  8073. targetRay.hasLinearVelocity = false;
  8074. }
  8075. if ( inputPose.angularVelocity ) {
  8076. targetRay.hasAngularVelocity = true;
  8077. targetRay.angularVelocity.copy( inputPose.angularVelocity );
  8078. } else {
  8079. targetRay.hasAngularVelocity = false;
  8080. }
  8081. this.dispatchEvent( _moveEvent );
  8082. }
  8083. }
  8084. }
  8085. if ( targetRay !== null ) {
  8086. targetRay.visible = ( inputPose !== null );
  8087. }
  8088. if ( grip !== null ) {
  8089. grip.visible = ( gripPose !== null );
  8090. }
  8091. if ( hand !== null ) {
  8092. hand.visible = ( handPose !== null );
  8093. }
  8094. return this;
  8095. }
  8096. // private method
  8097. _getHandJoint( hand, inputjoint ) {
  8098. if ( hand.joints[ inputjoint.jointName ] === undefined ) {
  8099. const joint = new Group();
  8100. joint.matrixAutoUpdate = false;
  8101. joint.visible = false;
  8102. hand.joints[ inputjoint.jointName ] = joint;
  8103. hand.add( joint );
  8104. }
  8105. return hand.joints[ inputjoint.jointName ];
  8106. }
  8107. }
  8108. class FogExp2 {
  8109. constructor( color, density = 0.00025 ) {
  8110. this.isFogExp2 = true;
  8111. this.name = '';
  8112. this.color = new Color( color );
  8113. this.density = density;
  8114. }
  8115. clone() {
  8116. return new FogExp2( this.color, this.density );
  8117. }
  8118. toJSON( /* meta */ ) {
  8119. return {
  8120. type: 'FogExp2',
  8121. name: this.name,
  8122. color: this.color.getHex(),
  8123. density: this.density
  8124. };
  8125. }
  8126. }
  8127. class Fog {
  8128. constructor( color, near = 1, far = 1000 ) {
  8129. this.isFog = true;
  8130. this.name = '';
  8131. this.color = new Color( color );
  8132. this.near = near;
  8133. this.far = far;
  8134. }
  8135. clone() {
  8136. return new Fog( this.color, this.near, this.far );
  8137. }
  8138. toJSON( /* meta */ ) {
  8139. return {
  8140. type: 'Fog',
  8141. name: this.name,
  8142. color: this.color.getHex(),
  8143. near: this.near,
  8144. far: this.far
  8145. };
  8146. }
  8147. }
  8148. class Scene extends Object3D {
  8149. constructor() {
  8150. super();
  8151. this.isScene = true;
  8152. this.type = 'Scene';
  8153. this.background = null;
  8154. this.environment = null;
  8155. this.fog = null;
  8156. this.backgroundBlurriness = 0;
  8157. this.backgroundIntensity = 1;
  8158. this.backgroundRotation = new Euler();
  8159. this.environmentIntensity = 1;
  8160. this.environmentRotation = new Euler();
  8161. this.overrideMaterial = null;
  8162. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  8163. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
  8164. }
  8165. }
  8166. copy( source, recursive ) {
  8167. super.copy( source, recursive );
  8168. if ( source.background !== null ) this.background = source.background.clone();
  8169. if ( source.environment !== null ) this.environment = source.environment.clone();
  8170. if ( source.fog !== null ) this.fog = source.fog.clone();
  8171. this.backgroundBlurriness = source.backgroundBlurriness;
  8172. this.backgroundIntensity = source.backgroundIntensity;
  8173. this.backgroundRotation.copy( source.backgroundRotation );
  8174. this.environmentIntensity = source.environmentIntensity;
  8175. this.environmentRotation.copy( source.environmentRotation );
  8176. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  8177. this.matrixAutoUpdate = source.matrixAutoUpdate;
  8178. return this;
  8179. }
  8180. toJSON( meta ) {
  8181. const data = super.toJSON( meta );
  8182. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  8183. if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
  8184. if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;
  8185. data.object.backgroundRotation = this.backgroundRotation.toArray();
  8186. if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity;
  8187. data.object.environmentRotation = this.environmentRotation.toArray();
  8188. return data;
  8189. }
  8190. }
  8191. class InterleavedBuffer {
  8192. constructor( array, stride ) {
  8193. this.isInterleavedBuffer = true;
  8194. this.array = array;
  8195. this.stride = stride;
  8196. this.count = array !== undefined ? array.length / stride : 0;
  8197. this.usage = StaticDrawUsage;
  8198. this.updateRanges = [];
  8199. this.version = 0;
  8200. this.uuid = generateUUID();
  8201. }
  8202. onUploadCallback() {}
  8203. set needsUpdate( value ) {
  8204. if ( value === true ) this.version ++;
  8205. }
  8206. setUsage( value ) {
  8207. this.usage = value;
  8208. return this;
  8209. }
  8210. addUpdateRange( start, count ) {
  8211. this.updateRanges.push( { start, count } );
  8212. }
  8213. clearUpdateRanges() {
  8214. this.updateRanges.length = 0;
  8215. }
  8216. copy( source ) {
  8217. this.array = new source.array.constructor( source.array );
  8218. this.count = source.count;
  8219. this.stride = source.stride;
  8220. this.usage = source.usage;
  8221. return this;
  8222. }
  8223. copyAt( index1, attribute, index2 ) {
  8224. index1 *= this.stride;
  8225. index2 *= attribute.stride;
  8226. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  8227. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  8228. }
  8229. return this;
  8230. }
  8231. set( value, offset = 0 ) {
  8232. this.array.set( value, offset );
  8233. return this;
  8234. }
  8235. clone( data ) {
  8236. if ( data.arrayBuffers === undefined ) {
  8237. data.arrayBuffers = {};
  8238. }
  8239. if ( this.array.buffer._uuid === undefined ) {
  8240. this.array.buffer._uuid = generateUUID();
  8241. }
  8242. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8243. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  8244. }
  8245. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  8246. const ib = new this.constructor( array, this.stride );
  8247. ib.setUsage( this.usage );
  8248. return ib;
  8249. }
  8250. onUpload( callback ) {
  8251. this.onUploadCallback = callback;
  8252. return this;
  8253. }
  8254. toJSON( data ) {
  8255. if ( data.arrayBuffers === undefined ) {
  8256. data.arrayBuffers = {};
  8257. }
  8258. // generate UUID for array buffer if necessary
  8259. if ( this.array.buffer._uuid === undefined ) {
  8260. this.array.buffer._uuid = generateUUID();
  8261. }
  8262. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8263. data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
  8264. }
  8265. //
  8266. return {
  8267. uuid: this.uuid,
  8268. buffer: this.array.buffer._uuid,
  8269. type: this.array.constructor.name,
  8270. stride: this.stride
  8271. };
  8272. }
  8273. }
  8274. const _vector$7 = /*@__PURE__*/ new Vector3();
  8275. class InterleavedBufferAttribute {
  8276. constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
  8277. this.isInterleavedBufferAttribute = true;
  8278. this.name = '';
  8279. this.data = interleavedBuffer;
  8280. this.itemSize = itemSize;
  8281. this.offset = offset;
  8282. this.normalized = normalized;
  8283. }
  8284. get count() {
  8285. return this.data.count;
  8286. }
  8287. get array() {
  8288. return this.data.array;
  8289. }
  8290. set needsUpdate( value ) {
  8291. this.data.needsUpdate = value;
  8292. }
  8293. applyMatrix4( m ) {
  8294. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  8295. _vector$7.fromBufferAttribute( this, i );
  8296. _vector$7.applyMatrix4( m );
  8297. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8298. }
  8299. return this;
  8300. }
  8301. applyNormalMatrix( m ) {
  8302. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8303. _vector$7.fromBufferAttribute( this, i );
  8304. _vector$7.applyNormalMatrix( m );
  8305. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8306. }
  8307. return this;
  8308. }
  8309. transformDirection( m ) {
  8310. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8311. _vector$7.fromBufferAttribute( this, i );
  8312. _vector$7.transformDirection( m );
  8313. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8314. }
  8315. return this;
  8316. }
  8317. getComponent( index, component ) {
  8318. let value = this.array[ index * this.data.stride + this.offset + component ];
  8319. if ( this.normalized ) value = denormalize( value, this.array );
  8320. return value;
  8321. }
  8322. setComponent( index, component, value ) {
  8323. if ( this.normalized ) value = normalize( value, this.array );
  8324. this.data.array[ index * this.data.stride + this.offset + component ] = value;
  8325. return this;
  8326. }
  8327. setX( index, x ) {
  8328. if ( this.normalized ) x = normalize( x, this.array );
  8329. this.data.array[ index * this.data.stride + this.offset ] = x;
  8330. return this;
  8331. }
  8332. setY( index, y ) {
  8333. if ( this.normalized ) y = normalize( y, this.array );
  8334. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  8335. return this;
  8336. }
  8337. setZ( index, z ) {
  8338. if ( this.normalized ) z = normalize( z, this.array );
  8339. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  8340. return this;
  8341. }
  8342. setW( index, w ) {
  8343. if ( this.normalized ) w = normalize( w, this.array );
  8344. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  8345. return this;
  8346. }
  8347. getX( index ) {
  8348. let x = this.data.array[ index * this.data.stride + this.offset ];
  8349. if ( this.normalized ) x = denormalize( x, this.array );
  8350. return x;
  8351. }
  8352. getY( index ) {
  8353. let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
  8354. if ( this.normalized ) y = denormalize( y, this.array );
  8355. return y;
  8356. }
  8357. getZ( index ) {
  8358. let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
  8359. if ( this.normalized ) z = denormalize( z, this.array );
  8360. return z;
  8361. }
  8362. getW( index ) {
  8363. let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
  8364. if ( this.normalized ) w = denormalize( w, this.array );
  8365. return w;
  8366. }
  8367. setXY( index, x, y ) {
  8368. index = index * this.data.stride + this.offset;
  8369. if ( this.normalized ) {
  8370. x = normalize( x, this.array );
  8371. y = normalize( y, this.array );
  8372. }
  8373. this.data.array[ index + 0 ] = x;
  8374. this.data.array[ index + 1 ] = y;
  8375. return this;
  8376. }
  8377. setXYZ( index, x, y, z ) {
  8378. index = index * this.data.stride + this.offset;
  8379. if ( this.normalized ) {
  8380. x = normalize( x, this.array );
  8381. y = normalize( y, this.array );
  8382. z = normalize( z, this.array );
  8383. }
  8384. this.data.array[ index + 0 ] = x;
  8385. this.data.array[ index + 1 ] = y;
  8386. this.data.array[ index + 2 ] = z;
  8387. return this;
  8388. }
  8389. setXYZW( index, x, y, z, w ) {
  8390. index = index * this.data.stride + this.offset;
  8391. if ( this.normalized ) {
  8392. x = normalize( x, this.array );
  8393. y = normalize( y, this.array );
  8394. z = normalize( z, this.array );
  8395. w = normalize( w, this.array );
  8396. }
  8397. this.data.array[ index + 0 ] = x;
  8398. this.data.array[ index + 1 ] = y;
  8399. this.data.array[ index + 2 ] = z;
  8400. this.data.array[ index + 3 ] = w;
  8401. return this;
  8402. }
  8403. clone( data ) {
  8404. if ( data === undefined ) {
  8405. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
  8406. const array = [];
  8407. for ( let i = 0; i < this.count; i ++ ) {
  8408. const index = i * this.data.stride + this.offset;
  8409. for ( let j = 0; j < this.itemSize; j ++ ) {
  8410. array.push( this.data.array[ index + j ] );
  8411. }
  8412. }
  8413. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  8414. } else {
  8415. if ( data.interleavedBuffers === undefined ) {
  8416. data.interleavedBuffers = {};
  8417. }
  8418. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8419. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  8420. }
  8421. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  8422. }
  8423. }
  8424. toJSON( data ) {
  8425. if ( data === undefined ) {
  8426. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
  8427. const array = [];
  8428. for ( let i = 0; i < this.count; i ++ ) {
  8429. const index = i * this.data.stride + this.offset;
  8430. for ( let j = 0; j < this.itemSize; j ++ ) {
  8431. array.push( this.data.array[ index + j ] );
  8432. }
  8433. }
  8434. // de-interleave data and save it as an ordinary buffer attribute for now
  8435. return {
  8436. itemSize: this.itemSize,
  8437. type: this.array.constructor.name,
  8438. array: array,
  8439. normalized: this.normalized
  8440. };
  8441. } else {
  8442. // save as true interleaved attribute
  8443. if ( data.interleavedBuffers === undefined ) {
  8444. data.interleavedBuffers = {};
  8445. }
  8446. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8447. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  8448. }
  8449. return {
  8450. isInterleavedBufferAttribute: true,
  8451. itemSize: this.itemSize,
  8452. data: this.data.uuid,
  8453. offset: this.offset,
  8454. normalized: this.normalized
  8455. };
  8456. }
  8457. }
  8458. }
  8459. class SpriteMaterial extends Material {
  8460. constructor( parameters ) {
  8461. super();
  8462. this.isSpriteMaterial = true;
  8463. this.type = 'SpriteMaterial';
  8464. this.color = new Color( 0xffffff );
  8465. this.map = null;
  8466. this.alphaMap = null;
  8467. this.rotation = 0;
  8468. this.sizeAttenuation = true;
  8469. this.transparent = true;
  8470. this.fog = true;
  8471. this.setValues( parameters );
  8472. }
  8473. copy( source ) {
  8474. super.copy( source );
  8475. this.color.copy( source.color );
  8476. this.map = source.map;
  8477. this.alphaMap = source.alphaMap;
  8478. this.rotation = source.rotation;
  8479. this.sizeAttenuation = source.sizeAttenuation;
  8480. this.fog = source.fog;
  8481. return this;
  8482. }
  8483. }
  8484. let _geometry;
  8485. const _intersectPoint = /*@__PURE__*/ new Vector3();
  8486. const _worldScale = /*@__PURE__*/ new Vector3();
  8487. const _mvPosition = /*@__PURE__*/ new Vector3();
  8488. const _alignedPosition = /*@__PURE__*/ new Vector2();
  8489. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  8490. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  8491. const _vA = /*@__PURE__*/ new Vector3();
  8492. const _vB = /*@__PURE__*/ new Vector3();
  8493. const _vC = /*@__PURE__*/ new Vector3();
  8494. const _uvA = /*@__PURE__*/ new Vector2();
  8495. const _uvB = /*@__PURE__*/ new Vector2();
  8496. const _uvC = /*@__PURE__*/ new Vector2();
  8497. class Sprite extends Object3D {
  8498. constructor( material = new SpriteMaterial() ) {
  8499. super();
  8500. this.isSprite = true;
  8501. this.type = 'Sprite';
  8502. if ( _geometry === undefined ) {
  8503. _geometry = new BufferGeometry();
  8504. const float32Array = new Float32Array( [
  8505. -0.5, -0.5, 0, 0, 0,
  8506. 0.5, -0.5, 0, 1, 0,
  8507. 0.5, 0.5, 0, 1, 1,
  8508. -0.5, 0.5, 0, 0, 1
  8509. ] );
  8510. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  8511. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  8512. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  8513. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  8514. }
  8515. this.geometry = _geometry;
  8516. this.material = material;
  8517. this.center = new Vector2( 0.5, 0.5 );
  8518. }
  8519. raycast( raycaster, intersects ) {
  8520. if ( raycaster.camera === null ) {
  8521. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  8522. }
  8523. _worldScale.setFromMatrixScale( this.matrixWorld );
  8524. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  8525. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  8526. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  8527. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  8528. _worldScale.multiplyScalar( - _mvPosition.z );
  8529. }
  8530. const rotation = this.material.rotation;
  8531. let sin, cos;
  8532. if ( rotation !== 0 ) {
  8533. cos = Math.cos( rotation );
  8534. sin = Math.sin( rotation );
  8535. }
  8536. const center = this.center;
  8537. transformVertex( _vA.set( -0.5, -0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8538. transformVertex( _vB.set( 0.5, -0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8539. transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8540. _uvA.set( 0, 0 );
  8541. _uvB.set( 1, 0 );
  8542. _uvC.set( 1, 1 );
  8543. // check first triangle
  8544. let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint );
  8545. if ( intersect === null ) {
  8546. // check second triangle
  8547. transformVertex( _vB.set( -0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8548. _uvB.set( 0, 1 );
  8549. intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint );
  8550. if ( intersect === null ) {
  8551. return;
  8552. }
  8553. }
  8554. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  8555. if ( distance < raycaster.near || distance > raycaster.far ) return;
  8556. intersects.push( {
  8557. distance: distance,
  8558. point: _intersectPoint.clone(),
  8559. uv: Triangle.getInterpolation( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ),
  8560. face: null,
  8561. object: this
  8562. } );
  8563. }
  8564. copy( source, recursive ) {
  8565. super.copy( source, recursive );
  8566. if ( source.center !== undefined ) this.center.copy( source.center );
  8567. this.material = source.material;
  8568. return this;
  8569. }
  8570. }
  8571. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  8572. // compute position in camera space
  8573. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  8574. // to check if rotation is not zero
  8575. if ( sin !== undefined ) {
  8576. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  8577. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  8578. } else {
  8579. _rotatedPosition.copy( _alignedPosition );
  8580. }
  8581. vertexPosition.copy( mvPosition );
  8582. vertexPosition.x += _rotatedPosition.x;
  8583. vertexPosition.y += _rotatedPosition.y;
  8584. // transform to world space
  8585. vertexPosition.applyMatrix4( _viewWorldMatrix );
  8586. }
  8587. const _v1$2 = /*@__PURE__*/ new Vector3();
  8588. const _v2$1 = /*@__PURE__*/ new Vector3();
  8589. class LOD extends Object3D {
  8590. constructor() {
  8591. super();
  8592. this._currentLevel = 0;
  8593. this.type = 'LOD';
  8594. Object.defineProperties( this, {
  8595. levels: {
  8596. enumerable: true,
  8597. value: []
  8598. },
  8599. isLOD: {
  8600. value: true,
  8601. }
  8602. } );
  8603. this.autoUpdate = true;
  8604. }
  8605. copy( source ) {
  8606. super.copy( source, false );
  8607. const levels = source.levels;
  8608. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8609. const level = levels[ i ];
  8610. this.addLevel( level.object.clone(), level.distance, level.hysteresis );
  8611. }
  8612. this.autoUpdate = source.autoUpdate;
  8613. return this;
  8614. }
  8615. addLevel( object, distance = 0, hysteresis = 0 ) {
  8616. distance = Math.abs( distance );
  8617. const levels = this.levels;
  8618. let l;
  8619. for ( l = 0; l < levels.length; l ++ ) {
  8620. if ( distance < levels[ l ].distance ) {
  8621. break;
  8622. }
  8623. }
  8624. levels.splice( l, 0, { distance: distance, hysteresis: hysteresis, object: object } );
  8625. this.add( object );
  8626. return this;
  8627. }
  8628. removeLevel( distance ) {
  8629. const levels = this.levels;
  8630. for ( let i = 0; i < levels.length; i ++ ) {
  8631. if ( levels[ i ].distance === distance ) {
  8632. const removedElements = levels.splice( i, 1 );
  8633. this.remove( removedElements[ 0 ].object );
  8634. return true;
  8635. }
  8636. }
  8637. return false;
  8638. }
  8639. getCurrentLevel() {
  8640. return this._currentLevel;
  8641. }
  8642. getObjectForDistance( distance ) {
  8643. const levels = this.levels;
  8644. if ( levels.length > 0 ) {
  8645. let i, l;
  8646. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8647. let levelDistance = levels[ i ].distance;
  8648. if ( levels[ i ].object.visible ) {
  8649. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8650. }
  8651. if ( distance < levelDistance ) {
  8652. break;
  8653. }
  8654. }
  8655. return levels[ i - 1 ].object;
  8656. }
  8657. return null;
  8658. }
  8659. raycast( raycaster, intersects ) {
  8660. const levels = this.levels;
  8661. if ( levels.length > 0 ) {
  8662. _v1$2.setFromMatrixPosition( this.matrixWorld );
  8663. const distance = raycaster.ray.origin.distanceTo( _v1$2 );
  8664. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  8665. }
  8666. }
  8667. update( camera ) {
  8668. const levels = this.levels;
  8669. if ( levels.length > 1 ) {
  8670. _v1$2.setFromMatrixPosition( camera.matrixWorld );
  8671. _v2$1.setFromMatrixPosition( this.matrixWorld );
  8672. const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom;
  8673. levels[ 0 ].object.visible = true;
  8674. let i, l;
  8675. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8676. let levelDistance = levels[ i ].distance;
  8677. if ( levels[ i ].object.visible ) {
  8678. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8679. }
  8680. if ( distance >= levelDistance ) {
  8681. levels[ i - 1 ].object.visible = false;
  8682. levels[ i ].object.visible = true;
  8683. } else {
  8684. break;
  8685. }
  8686. }
  8687. this._currentLevel = i - 1;
  8688. for ( ; i < l; i ++ ) {
  8689. levels[ i ].object.visible = false;
  8690. }
  8691. }
  8692. }
  8693. toJSON( meta ) {
  8694. const data = super.toJSON( meta );
  8695. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  8696. data.object.levels = [];
  8697. const levels = this.levels;
  8698. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8699. const level = levels[ i ];
  8700. data.object.levels.push( {
  8701. object: level.object.uuid,
  8702. distance: level.distance,
  8703. hysteresis: level.hysteresis
  8704. } );
  8705. }
  8706. return data;
  8707. }
  8708. }
  8709. const _basePosition = /*@__PURE__*/ new Vector3();
  8710. const _skinIndex = /*@__PURE__*/ new Vector4();
  8711. const _skinWeight = /*@__PURE__*/ new Vector4();
  8712. const _vector3 = /*@__PURE__*/ new Vector3();
  8713. const _matrix4 = /*@__PURE__*/ new Matrix4();
  8714. const _vertex = /*@__PURE__*/ new Vector3();
  8715. const _sphere$5 = /*@__PURE__*/ new Sphere();
  8716. const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4();
  8717. const _ray$2 = /*@__PURE__*/ new Ray();
  8718. class SkinnedMesh extends Mesh {
  8719. constructor( geometry, material ) {
  8720. super( geometry, material );
  8721. this.isSkinnedMesh = true;
  8722. this.type = 'SkinnedMesh';
  8723. this.bindMode = AttachedBindMode;
  8724. this.bindMatrix = new Matrix4();
  8725. this.bindMatrixInverse = new Matrix4();
  8726. this.boundingBox = null;
  8727. this.boundingSphere = null;
  8728. }
  8729. computeBoundingBox() {
  8730. const geometry = this.geometry;
  8731. if ( this.boundingBox === null ) {
  8732. this.boundingBox = new Box3();
  8733. }
  8734. this.boundingBox.makeEmpty();
  8735. const positionAttribute = geometry.getAttribute( 'position' );
  8736. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8737. this.getVertexPosition( i, _vertex );
  8738. this.boundingBox.expandByPoint( _vertex );
  8739. }
  8740. }
  8741. computeBoundingSphere() {
  8742. const geometry = this.geometry;
  8743. if ( this.boundingSphere === null ) {
  8744. this.boundingSphere = new Sphere();
  8745. }
  8746. this.boundingSphere.makeEmpty();
  8747. const positionAttribute = geometry.getAttribute( 'position' );
  8748. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8749. this.getVertexPosition( i, _vertex );
  8750. this.boundingSphere.expandByPoint( _vertex );
  8751. }
  8752. }
  8753. copy( source, recursive ) {
  8754. super.copy( source, recursive );
  8755. this.bindMode = source.bindMode;
  8756. this.bindMatrix.copy( source.bindMatrix );
  8757. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  8758. this.skeleton = source.skeleton;
  8759. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8760. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8761. return this;
  8762. }
  8763. raycast( raycaster, intersects ) {
  8764. const material = this.material;
  8765. const matrixWorld = this.matrixWorld;
  8766. if ( material === undefined ) return;
  8767. // test with bounding sphere in world space
  8768. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8769. _sphere$5.copy( this.boundingSphere );
  8770. _sphere$5.applyMatrix4( matrixWorld );
  8771. if ( raycaster.ray.intersectsSphere( _sphere$5 ) === false ) return;
  8772. // convert ray to local space of skinned mesh
  8773. _inverseMatrix$2.copy( matrixWorld ).invert();
  8774. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  8775. // test with bounding box in local space
  8776. if ( this.boundingBox !== null ) {
  8777. if ( _ray$2.intersectsBox( this.boundingBox ) === false ) return;
  8778. }
  8779. // test for intersections with geometry
  8780. this._computeIntersections( raycaster, intersects, _ray$2 );
  8781. }
  8782. getVertexPosition( index, target ) {
  8783. super.getVertexPosition( index, target );
  8784. this.applyBoneTransform( index, target );
  8785. return target;
  8786. }
  8787. bind( skeleton, bindMatrix ) {
  8788. this.skeleton = skeleton;
  8789. if ( bindMatrix === undefined ) {
  8790. this.updateMatrixWorld( true );
  8791. this.skeleton.calculateInverses();
  8792. bindMatrix = this.matrixWorld;
  8793. }
  8794. this.bindMatrix.copy( bindMatrix );
  8795. this.bindMatrixInverse.copy( bindMatrix ).invert();
  8796. }
  8797. pose() {
  8798. this.skeleton.pose();
  8799. }
  8800. normalizeSkinWeights() {
  8801. const vector = new Vector4();
  8802. const skinWeight = this.geometry.attributes.skinWeight;
  8803. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  8804. vector.fromBufferAttribute( skinWeight, i );
  8805. const scale = 1.0 / vector.manhattanLength();
  8806. if ( scale !== Infinity ) {
  8807. vector.multiplyScalar( scale );
  8808. } else {
  8809. vector.set( 1, 0, 0, 0 ); // do something reasonable
  8810. }
  8811. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  8812. }
  8813. }
  8814. updateMatrixWorld( force ) {
  8815. super.updateMatrixWorld( force );
  8816. if ( this.bindMode === AttachedBindMode ) {
  8817. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  8818. } else if ( this.bindMode === DetachedBindMode ) {
  8819. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  8820. } else {
  8821. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  8822. }
  8823. }
  8824. applyBoneTransform( index, vector ) {
  8825. const skeleton = this.skeleton;
  8826. const geometry = this.geometry;
  8827. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  8828. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  8829. _basePosition.copy( vector ).applyMatrix4( this.bindMatrix );
  8830. vector.set( 0, 0, 0 );
  8831. for ( let i = 0; i < 4; i ++ ) {
  8832. const weight = _skinWeight.getComponent( i );
  8833. if ( weight !== 0 ) {
  8834. const boneIndex = _skinIndex.getComponent( i );
  8835. _matrix4.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  8836. vector.addScaledVector( _vector3.copy( _basePosition ).applyMatrix4( _matrix4 ), weight );
  8837. }
  8838. }
  8839. return vector.applyMatrix4( this.bindMatrixInverse );
  8840. }
  8841. }
  8842. class Bone extends Object3D {
  8843. constructor() {
  8844. super();
  8845. this.isBone = true;
  8846. this.type = 'Bone';
  8847. }
  8848. }
  8849. class DataTexture extends Texture {
  8850. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) {
  8851. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  8852. this.isDataTexture = true;
  8853. this.image = { data: data, width: width, height: height };
  8854. this.generateMipmaps = false;
  8855. this.flipY = false;
  8856. this.unpackAlignment = 1;
  8857. }
  8858. }
  8859. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  8860. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  8861. class Skeleton {
  8862. constructor( bones = [], boneInverses = [] ) {
  8863. this.uuid = generateUUID();
  8864. this.bones = bones.slice( 0 );
  8865. this.boneInverses = boneInverses;
  8866. this.boneMatrices = null;
  8867. this.boneTexture = null;
  8868. this.init();
  8869. }
  8870. init() {
  8871. const bones = this.bones;
  8872. const boneInverses = this.boneInverses;
  8873. this.boneMatrices = new Float32Array( bones.length * 16 );
  8874. // calculate inverse bone matrices if necessary
  8875. if ( boneInverses.length === 0 ) {
  8876. this.calculateInverses();
  8877. } else {
  8878. // handle special case
  8879. if ( bones.length !== boneInverses.length ) {
  8880. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  8881. this.boneInverses = [];
  8882. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8883. this.boneInverses.push( new Matrix4() );
  8884. }
  8885. }
  8886. }
  8887. }
  8888. calculateInverses() {
  8889. this.boneInverses.length = 0;
  8890. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8891. const inverse = new Matrix4();
  8892. if ( this.bones[ i ] ) {
  8893. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  8894. }
  8895. this.boneInverses.push( inverse );
  8896. }
  8897. }
  8898. pose() {
  8899. // recover the bind-time world matrices
  8900. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8901. const bone = this.bones[ i ];
  8902. if ( bone ) {
  8903. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  8904. }
  8905. }
  8906. // compute the local matrices, positions, rotations and scales
  8907. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8908. const bone = this.bones[ i ];
  8909. if ( bone ) {
  8910. if ( bone.parent && bone.parent.isBone ) {
  8911. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  8912. bone.matrix.multiply( bone.matrixWorld );
  8913. } else {
  8914. bone.matrix.copy( bone.matrixWorld );
  8915. }
  8916. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  8917. }
  8918. }
  8919. }
  8920. update() {
  8921. const bones = this.bones;
  8922. const boneInverses = this.boneInverses;
  8923. const boneMatrices = this.boneMatrices;
  8924. const boneTexture = this.boneTexture;
  8925. // flatten bone matrices to array
  8926. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  8927. // compute the offset between the current and the original transform
  8928. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  8929. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  8930. _offsetMatrix.toArray( boneMatrices, i * 16 );
  8931. }
  8932. if ( boneTexture !== null ) {
  8933. boneTexture.needsUpdate = true;
  8934. }
  8935. }
  8936. clone() {
  8937. return new Skeleton( this.bones, this.boneInverses );
  8938. }
  8939. computeBoneTexture() {
  8940. // layout (1 matrix = 4 pixels)
  8941. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  8942. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  8943. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  8944. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  8945. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  8946. let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  8947. size = Math.ceil( size / 4 ) * 4;
  8948. size = Math.max( size, 4 );
  8949. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  8950. boneMatrices.set( this.boneMatrices ); // copy current values
  8951. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  8952. boneTexture.needsUpdate = true;
  8953. this.boneMatrices = boneMatrices;
  8954. this.boneTexture = boneTexture;
  8955. return this;
  8956. }
  8957. getBoneByName( name ) {
  8958. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8959. const bone = this.bones[ i ];
  8960. if ( bone.name === name ) {
  8961. return bone;
  8962. }
  8963. }
  8964. return undefined;
  8965. }
  8966. dispose( ) {
  8967. if ( this.boneTexture !== null ) {
  8968. this.boneTexture.dispose();
  8969. this.boneTexture = null;
  8970. }
  8971. }
  8972. fromJSON( json, bones ) {
  8973. this.uuid = json.uuid;
  8974. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  8975. const uuid = json.bones[ i ];
  8976. let bone = bones[ uuid ];
  8977. if ( bone === undefined ) {
  8978. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  8979. bone = new Bone();
  8980. }
  8981. this.bones.push( bone );
  8982. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  8983. }
  8984. this.init();
  8985. return this;
  8986. }
  8987. toJSON() {
  8988. const data = {
  8989. metadata: {
  8990. version: 4.6,
  8991. type: 'Skeleton',
  8992. generator: 'Skeleton.toJSON'
  8993. },
  8994. bones: [],
  8995. boneInverses: []
  8996. };
  8997. data.uuid = this.uuid;
  8998. const bones = this.bones;
  8999. const boneInverses = this.boneInverses;
  9000. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  9001. const bone = bones[ i ];
  9002. data.bones.push( bone.uuid );
  9003. const boneInverse = boneInverses[ i ];
  9004. data.boneInverses.push( boneInverse.toArray() );
  9005. }
  9006. return data;
  9007. }
  9008. }
  9009. class InstancedBufferAttribute extends BufferAttribute {
  9010. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  9011. super( array, itemSize, normalized );
  9012. this.isInstancedBufferAttribute = true;
  9013. this.meshPerAttribute = meshPerAttribute;
  9014. }
  9015. copy( source ) {
  9016. super.copy( source );
  9017. this.meshPerAttribute = source.meshPerAttribute;
  9018. return this;
  9019. }
  9020. toJSON() {
  9021. const data = super.toJSON();
  9022. data.meshPerAttribute = this.meshPerAttribute;
  9023. data.isInstancedBufferAttribute = true;
  9024. return data;
  9025. }
  9026. }
  9027. const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
  9028. const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
  9029. const _instanceIntersects = [];
  9030. const _box3 = /*@__PURE__*/ new Box3();
  9031. const _identity = /*@__PURE__*/ new Matrix4();
  9032. const _mesh$1 = /*@__PURE__*/ new Mesh();
  9033. const _sphere$4 = /*@__PURE__*/ new Sphere();
  9034. class InstancedMesh extends Mesh {
  9035. constructor( geometry, material, count ) {
  9036. super( geometry, material );
  9037. this.isInstancedMesh = true;
  9038. this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
  9039. this.instanceColor = null;
  9040. this.morphTexture = null;
  9041. this.count = count;
  9042. this.boundingBox = null;
  9043. this.boundingSphere = null;
  9044. for ( let i = 0; i < count; i ++ ) {
  9045. this.setMatrixAt( i, _identity );
  9046. }
  9047. }
  9048. computeBoundingBox() {
  9049. const geometry = this.geometry;
  9050. const count = this.count;
  9051. if ( this.boundingBox === null ) {
  9052. this.boundingBox = new Box3();
  9053. }
  9054. if ( geometry.boundingBox === null ) {
  9055. geometry.computeBoundingBox();
  9056. }
  9057. this.boundingBox.makeEmpty();
  9058. for ( let i = 0; i < count; i ++ ) {
  9059. this.getMatrixAt( i, _instanceLocalMatrix );
  9060. _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix );
  9061. this.boundingBox.union( _box3 );
  9062. }
  9063. }
  9064. computeBoundingSphere() {
  9065. const geometry = this.geometry;
  9066. const count = this.count;
  9067. if ( this.boundingSphere === null ) {
  9068. this.boundingSphere = new Sphere();
  9069. }
  9070. if ( geometry.boundingSphere === null ) {
  9071. geometry.computeBoundingSphere();
  9072. }
  9073. this.boundingSphere.makeEmpty();
  9074. for ( let i = 0; i < count; i ++ ) {
  9075. this.getMatrixAt( i, _instanceLocalMatrix );
  9076. _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix );
  9077. this.boundingSphere.union( _sphere$4 );
  9078. }
  9079. }
  9080. copy( source, recursive ) {
  9081. super.copy( source, recursive );
  9082. this.instanceMatrix.copy( source.instanceMatrix );
  9083. if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone();
  9084. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  9085. this.count = source.count;
  9086. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  9087. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  9088. return this;
  9089. }
  9090. getColorAt( index, color ) {
  9091. color.fromArray( this.instanceColor.array, index * 3 );
  9092. }
  9093. getMatrixAt( index, matrix ) {
  9094. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  9095. }
  9096. getMorphAt( index, object ) {
  9097. const objectInfluences = object.morphTargetInfluences;
  9098. const array = this.morphTexture.source.data.data;
  9099. const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
  9100. const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
  9101. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  9102. objectInfluences[ i ] = array[ dataIndex + i ];
  9103. }
  9104. }
  9105. raycast( raycaster, intersects ) {
  9106. const matrixWorld = this.matrixWorld;
  9107. const raycastTimes = this.count;
  9108. _mesh$1.geometry = this.geometry;
  9109. _mesh$1.material = this.material;
  9110. if ( _mesh$1.material === undefined ) return;
  9111. // test with bounding sphere first
  9112. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  9113. _sphere$4.copy( this.boundingSphere );
  9114. _sphere$4.applyMatrix4( matrixWorld );
  9115. if ( raycaster.ray.intersectsSphere( _sphere$4 ) === false ) return;
  9116. // now test each instance
  9117. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  9118. // calculate the world matrix for each instance
  9119. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  9120. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  9121. // the mesh represents this single instance
  9122. _mesh$1.matrixWorld = _instanceWorldMatrix;
  9123. _mesh$1.raycast( raycaster, _instanceIntersects );
  9124. // process the result of raycast
  9125. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  9126. const intersect = _instanceIntersects[ i ];
  9127. intersect.instanceId = instanceId;
  9128. intersect.object = this;
  9129. intersects.push( intersect );
  9130. }
  9131. _instanceIntersects.length = 0;
  9132. }
  9133. }
  9134. setColorAt( index, color ) {
  9135. if ( this.instanceColor === null ) {
  9136. this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ).fill( 1 ), 3 );
  9137. }
  9138. color.toArray( this.instanceColor.array, index * 3 );
  9139. }
  9140. setMatrixAt( index, matrix ) {
  9141. matrix.toArray( this.instanceMatrix.array, index * 16 );
  9142. }
  9143. setMorphAt( index, object ) {
  9144. const objectInfluences = object.morphTargetInfluences;
  9145. const len = objectInfluences.length + 1; // morphBaseInfluence + all influences
  9146. if ( this.morphTexture === null ) {
  9147. this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType );
  9148. }
  9149. const array = this.morphTexture.source.data.data;
  9150. let morphInfluencesSum = 0;
  9151. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  9152. morphInfluencesSum += objectInfluences[ i ];
  9153. }
  9154. const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  9155. const dataIndex = len * index;
  9156. array[ dataIndex ] = morphBaseInfluence;
  9157. array.set( objectInfluences, dataIndex + 1 );
  9158. }
  9159. updateMorphTargets() {
  9160. }
  9161. dispose() {
  9162. this.dispatchEvent( { type: 'dispose' } );
  9163. if ( this.morphTexture !== null ) {
  9164. this.morphTexture.dispose();
  9165. this.morphTexture = null;
  9166. }
  9167. return this;
  9168. }
  9169. }
  9170. const _vector1 = /*@__PURE__*/ new Vector3();
  9171. const _vector2 = /*@__PURE__*/ new Vector3();
  9172. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  9173. class Plane {
  9174. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  9175. this.isPlane = true;
  9176. // normal is assumed to be normalized
  9177. this.normal = normal;
  9178. this.constant = constant;
  9179. }
  9180. set( normal, constant ) {
  9181. this.normal.copy( normal );
  9182. this.constant = constant;
  9183. return this;
  9184. }
  9185. setComponents( x, y, z, w ) {
  9186. this.normal.set( x, y, z );
  9187. this.constant = w;
  9188. return this;
  9189. }
  9190. setFromNormalAndCoplanarPoint( normal, point ) {
  9191. this.normal.copy( normal );
  9192. this.constant = - point.dot( this.normal );
  9193. return this;
  9194. }
  9195. setFromCoplanarPoints( a, b, c ) {
  9196. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  9197. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  9198. this.setFromNormalAndCoplanarPoint( normal, a );
  9199. return this;
  9200. }
  9201. copy( plane ) {
  9202. this.normal.copy( plane.normal );
  9203. this.constant = plane.constant;
  9204. return this;
  9205. }
  9206. normalize() {
  9207. // Note: will lead to a divide by zero if the plane is invalid.
  9208. const inverseNormalLength = 1.0 / this.normal.length();
  9209. this.normal.multiplyScalar( inverseNormalLength );
  9210. this.constant *= inverseNormalLength;
  9211. return this;
  9212. }
  9213. negate() {
  9214. this.constant *= -1;
  9215. this.normal.negate();
  9216. return this;
  9217. }
  9218. distanceToPoint( point ) {
  9219. return this.normal.dot( point ) + this.constant;
  9220. }
  9221. distanceToSphere( sphere ) {
  9222. return this.distanceToPoint( sphere.center ) - sphere.radius;
  9223. }
  9224. projectPoint( point, target ) {
  9225. return target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) );
  9226. }
  9227. intersectLine( line, target ) {
  9228. const direction = line.delta( _vector1 );
  9229. const denominator = this.normal.dot( direction );
  9230. if ( denominator === 0 ) {
  9231. // line is coplanar, return origin
  9232. if ( this.distanceToPoint( line.start ) === 0 ) {
  9233. return target.copy( line.start );
  9234. }
  9235. // Unsure if this is the correct method to handle this case.
  9236. return null;
  9237. }
  9238. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9239. if ( t < 0 || t > 1 ) {
  9240. return null;
  9241. }
  9242. return target.copy( line.start ).addScaledVector( direction, t );
  9243. }
  9244. intersectsLine( line ) {
  9245. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9246. const startSign = this.distanceToPoint( line.start );
  9247. const endSign = this.distanceToPoint( line.end );
  9248. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9249. }
  9250. intersectsBox( box ) {
  9251. return box.intersectsPlane( this );
  9252. }
  9253. intersectsSphere( sphere ) {
  9254. return sphere.intersectsPlane( this );
  9255. }
  9256. coplanarPoint( target ) {
  9257. return target.copy( this.normal ).multiplyScalar( - this.constant );
  9258. }
  9259. applyMatrix4( matrix, optionalNormalMatrix ) {
  9260. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  9261. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  9262. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9263. this.constant = - referencePoint.dot( normal );
  9264. return this;
  9265. }
  9266. translate( offset ) {
  9267. this.constant -= offset.dot( this.normal );
  9268. return this;
  9269. }
  9270. equals( plane ) {
  9271. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9272. }
  9273. clone() {
  9274. return new this.constructor().copy( this );
  9275. }
  9276. }
  9277. const _sphere$3 = /*@__PURE__*/ new Sphere();
  9278. const _vector$6 = /*@__PURE__*/ new Vector3();
  9279. class Frustum {
  9280. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  9281. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  9282. }
  9283. set( p0, p1, p2, p3, p4, p5 ) {
  9284. const planes = this.planes;
  9285. planes[ 0 ].copy( p0 );
  9286. planes[ 1 ].copy( p1 );
  9287. planes[ 2 ].copy( p2 );
  9288. planes[ 3 ].copy( p3 );
  9289. planes[ 4 ].copy( p4 );
  9290. planes[ 5 ].copy( p5 );
  9291. return this;
  9292. }
  9293. copy( frustum ) {
  9294. const planes = this.planes;
  9295. for ( let i = 0; i < 6; i ++ ) {
  9296. planes[ i ].copy( frustum.planes[ i ] );
  9297. }
  9298. return this;
  9299. }
  9300. setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
  9301. const planes = this.planes;
  9302. const me = m.elements;
  9303. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  9304. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  9305. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  9306. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  9307. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  9308. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  9309. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  9310. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  9311. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  9312. if ( coordinateSystem === WebGLCoordinateSystem ) {
  9313. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  9314. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  9315. planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
  9316. } else {
  9317. throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
  9318. }
  9319. return this;
  9320. }
  9321. intersectsObject( object ) {
  9322. if ( object.boundingSphere !== undefined ) {
  9323. if ( object.boundingSphere === null ) object.computeBoundingSphere();
  9324. _sphere$3.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld );
  9325. } else {
  9326. const geometry = object.geometry;
  9327. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9328. _sphere$3.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  9329. }
  9330. return this.intersectsSphere( _sphere$3 );
  9331. }
  9332. intersectsSprite( sprite ) {
  9333. _sphere$3.center.set( 0, 0, 0 );
  9334. _sphere$3.radius = 0.7071067811865476;
  9335. _sphere$3.applyMatrix4( sprite.matrixWorld );
  9336. return this.intersectsSphere( _sphere$3 );
  9337. }
  9338. intersectsSphere( sphere ) {
  9339. const planes = this.planes;
  9340. const center = sphere.center;
  9341. const negRadius = - sphere.radius;
  9342. for ( let i = 0; i < 6; i ++ ) {
  9343. const distance = planes[ i ].distanceToPoint( center );
  9344. if ( distance < negRadius ) {
  9345. return false;
  9346. }
  9347. }
  9348. return true;
  9349. }
  9350. intersectsBox( box ) {
  9351. const planes = this.planes;
  9352. for ( let i = 0; i < 6; i ++ ) {
  9353. const plane = planes[ i ];
  9354. // corner at max distance
  9355. _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  9356. _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  9357. _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  9358. if ( plane.distanceToPoint( _vector$6 ) < 0 ) {
  9359. return false;
  9360. }
  9361. }
  9362. return true;
  9363. }
  9364. containsPoint( point ) {
  9365. const planes = this.planes;
  9366. for ( let i = 0; i < 6; i ++ ) {
  9367. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  9368. return false;
  9369. }
  9370. }
  9371. return true;
  9372. }
  9373. clone() {
  9374. return new this.constructor().copy( this );
  9375. }
  9376. }
  9377. function ascIdSort( a, b ) {
  9378. return a - b;
  9379. }
  9380. function sortOpaque( a, b ) {
  9381. return a.z - b.z;
  9382. }
  9383. function sortTransparent( a, b ) {
  9384. return b.z - a.z;
  9385. }
  9386. class MultiDrawRenderList {
  9387. constructor() {
  9388. this.index = 0;
  9389. this.pool = [];
  9390. this.list = [];
  9391. }
  9392. push( start, count, z, index ) {
  9393. const pool = this.pool;
  9394. const list = this.list;
  9395. if ( this.index >= pool.length ) {
  9396. pool.push( {
  9397. start: -1,
  9398. count: -1,
  9399. z: -1,
  9400. index: -1,
  9401. } );
  9402. }
  9403. const item = pool[ this.index ];
  9404. list.push( item );
  9405. this.index ++;
  9406. item.start = start;
  9407. item.count = count;
  9408. item.z = z;
  9409. item.index = index;
  9410. }
  9411. reset() {
  9412. this.list.length = 0;
  9413. this.index = 0;
  9414. }
  9415. }
  9416. const _matrix$1 = /*@__PURE__*/ new Matrix4();
  9417. const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
  9418. const _frustum = /*@__PURE__*/ new Frustum();
  9419. const _box$1 = /*@__PURE__*/ new Box3();
  9420. const _sphere$2 = /*@__PURE__*/ new Sphere();
  9421. const _vector$5 = /*@__PURE__*/ new Vector3();
  9422. const _forward = /*@__PURE__*/ new Vector3();
  9423. const _temp = /*@__PURE__*/ new Vector3();
  9424. const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
  9425. const _mesh = /*@__PURE__*/ new Mesh();
  9426. const _batchIntersects = [];
  9427. // copies data from attribute "src" into "target" starting at "targetOffset"
  9428. function copyAttributeData( src, target, targetOffset = 0 ) {
  9429. const itemSize = target.itemSize;
  9430. if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) {
  9431. // use the component getters and setters if the array data cannot
  9432. // be copied directly
  9433. const vertexCount = src.count;
  9434. for ( let i = 0; i < vertexCount; i ++ ) {
  9435. for ( let c = 0; c < itemSize; c ++ ) {
  9436. target.setComponent( i + targetOffset, c, src.getComponent( i, c ) );
  9437. }
  9438. }
  9439. } else {
  9440. // faster copy approach using typed array set function
  9441. target.array.set( src.array, targetOffset * itemSize );
  9442. }
  9443. target.needsUpdate = true;
  9444. }
  9445. // safely copies array contents to a potentially smaller array
  9446. function copyArrayContents( src, target ) {
  9447. if ( src.constructor !== target.constructor ) {
  9448. // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
  9449. const len = Math.min( src.length, target.length );
  9450. for ( let i = 0; i < len; i ++ ) {
  9451. target[ i ] = src[ i ];
  9452. }
  9453. } else {
  9454. // if the arrays use the same data layout we can use a fast block copy
  9455. const len = Math.min( src.length, target.length );
  9456. target.set( new src.constructor( src.buffer, 0, len ) );
  9457. }
  9458. }
  9459. class BatchedMesh extends Mesh {
  9460. get maxInstanceCount() {
  9461. return this._maxInstanceCount;
  9462. }
  9463. get instanceCount() {
  9464. return this._instanceInfo.length - this._availableInstanceIds.length;
  9465. }
  9466. get unusedVertexCount() {
  9467. return this._maxVertexCount - this._nextVertexStart;
  9468. }
  9469. get unusedIndexCount() {
  9470. return this._maxIndexCount - this._nextIndexStart;
  9471. }
  9472. constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
  9473. super( new BufferGeometry(), material );
  9474. this.isBatchedMesh = true;
  9475. this.perObjectFrustumCulled = true;
  9476. this.sortObjects = true;
  9477. this.boundingBox = null;
  9478. this.boundingSphere = null;
  9479. this.customSort = null;
  9480. // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
  9481. this._instanceInfo = [];
  9482. this._geometryInfo = [];
  9483. // instance, geometry ids that have been set as inactive, and are available to be overwritten
  9484. this._availableInstanceIds = [];
  9485. this._availableGeometryIds = [];
  9486. // used to track where the next point is that geometry should be inserted
  9487. this._nextIndexStart = 0;
  9488. this._nextVertexStart = 0;
  9489. this._geometryCount = 0;
  9490. // flags
  9491. this._visibilityChanged = true;
  9492. this._geometryInitialized = false;
  9493. // cached user options
  9494. this._maxInstanceCount = maxInstanceCount;
  9495. this._maxVertexCount = maxVertexCount;
  9496. this._maxIndexCount = maxIndexCount;
  9497. // buffers for multi draw
  9498. this._multiDrawCounts = new Int32Array( maxInstanceCount );
  9499. this._multiDrawStarts = new Int32Array( maxInstanceCount );
  9500. this._multiDrawCount = 0;
  9501. this._multiDrawInstances = null;
  9502. // Local matrix per geometry by using data texture
  9503. this._matricesTexture = null;
  9504. this._indirectTexture = null;
  9505. this._colorsTexture = null;
  9506. this._initMatricesTexture();
  9507. this._initIndirectTexture();
  9508. }
  9509. _initMatricesTexture() {
  9510. // layout (1 matrix = 4 pixels)
  9511. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  9512. // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)
  9513. // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)
  9514. // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)
  9515. // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)
  9516. let size = Math.sqrt( this._maxInstanceCount * 4 ); // 4 pixels needed for 1 matrix
  9517. size = Math.ceil( size / 4 ) * 4;
  9518. size = Math.max( size, 4 );
  9519. const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  9520. const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType );
  9521. this._matricesTexture = matricesTexture;
  9522. }
  9523. _initIndirectTexture() {
  9524. let size = Math.sqrt( this._maxInstanceCount );
  9525. size = Math.ceil( size );
  9526. const indirectArray = new Uint32Array( size * size );
  9527. const indirectTexture = new DataTexture( indirectArray, size, size, RedIntegerFormat, UnsignedIntType );
  9528. this._indirectTexture = indirectTexture;
  9529. }
  9530. _initColorsTexture() {
  9531. let size = Math.sqrt( this._maxInstanceCount );
  9532. size = Math.ceil( size );
  9533. // 4 floats per RGBA pixel initialized to white
  9534. const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
  9535. const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
  9536. colorsTexture.colorSpace = ColorManagement.workingColorSpace;
  9537. this._colorsTexture = colorsTexture;
  9538. }
  9539. _initializeGeometry( reference ) {
  9540. const geometry = this.geometry;
  9541. const maxVertexCount = this._maxVertexCount;
  9542. const maxIndexCount = this._maxIndexCount;
  9543. if ( this._geometryInitialized === false ) {
  9544. for ( const attributeName in reference.attributes ) {
  9545. const srcAttribute = reference.getAttribute( attributeName );
  9546. const { array, itemSize, normalized } = srcAttribute;
  9547. const dstArray = new array.constructor( maxVertexCount * itemSize );
  9548. const dstAttribute = new BufferAttribute( dstArray, itemSize, normalized );
  9549. geometry.setAttribute( attributeName, dstAttribute );
  9550. }
  9551. if ( reference.getIndex() !== null ) {
  9552. // Reserve last u16 index for primitive restart.
  9553. const indexArray = maxVertexCount > 65535
  9554. ? new Uint32Array( maxIndexCount )
  9555. : new Uint16Array( maxIndexCount );
  9556. geometry.setIndex( new BufferAttribute( indexArray, 1 ) );
  9557. }
  9558. this._geometryInitialized = true;
  9559. }
  9560. }
  9561. // Make sure the geometry is compatible with the existing combined geometry attributes
  9562. _validateGeometry( geometry ) {
  9563. // check to ensure the geometries are using consistent attributes and indices
  9564. const batchGeometry = this.geometry;
  9565. if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
  9566. throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
  9567. }
  9568. for ( const attributeName in batchGeometry.attributes ) {
  9569. if ( ! geometry.hasAttribute( attributeName ) ) {
  9570. throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
  9571. }
  9572. const srcAttribute = geometry.getAttribute( attributeName );
  9573. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9574. if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
  9575. throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
  9576. }
  9577. }
  9578. }
  9579. validateInstanceId( instanceId ) {
  9580. const instanceInfo = this._instanceInfo;
  9581. if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
  9582. throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
  9583. }
  9584. }
  9585. validateGeometryId( geometryId ) {
  9586. const geometryInfoList = this._geometryInfo;
  9587. if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9588. throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
  9589. }
  9590. }
  9591. setCustomSort( func ) {
  9592. this.customSort = func;
  9593. return this;
  9594. }
  9595. computeBoundingBox() {
  9596. if ( this.boundingBox === null ) {
  9597. this.boundingBox = new Box3();
  9598. }
  9599. const boundingBox = this.boundingBox;
  9600. const instanceInfo = this._instanceInfo;
  9601. boundingBox.makeEmpty();
  9602. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9603. if ( instanceInfo[ i ].active === false ) continue;
  9604. const geometryId = instanceInfo[ i ].geometryIndex;
  9605. this.getMatrixAt( i, _matrix$1 );
  9606. this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 );
  9607. boundingBox.union( _box$1 );
  9608. }
  9609. }
  9610. computeBoundingSphere() {
  9611. if ( this.boundingSphere === null ) {
  9612. this.boundingSphere = new Sphere();
  9613. }
  9614. const boundingSphere = this.boundingSphere;
  9615. const instanceInfo = this._instanceInfo;
  9616. boundingSphere.makeEmpty();
  9617. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9618. if ( instanceInfo[ i ].active === false ) continue;
  9619. const geometryId = instanceInfo[ i ].geometryIndex;
  9620. this.getMatrixAt( i, _matrix$1 );
  9621. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9622. boundingSphere.union( _sphere$2 );
  9623. }
  9624. }
  9625. addInstance( geometryId ) {
  9626. const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
  9627. // ensure we're not over geometry
  9628. if ( atCapacity && this._availableInstanceIds.length === 0 ) {
  9629. throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
  9630. }
  9631. const instanceInfo = {
  9632. visible: true,
  9633. active: true,
  9634. geometryIndex: geometryId,
  9635. };
  9636. let drawId = null;
  9637. // Prioritize using previously freed instance ids
  9638. if ( this._availableInstanceIds.length > 0 ) {
  9639. this._availableInstanceIds.sort( ascIdSort );
  9640. drawId = this._availableInstanceIds.shift();
  9641. this._instanceInfo[ drawId ] = instanceInfo;
  9642. } else {
  9643. drawId = this._instanceInfo.length;
  9644. this._instanceInfo.push( instanceInfo );
  9645. }
  9646. const matricesTexture = this._matricesTexture;
  9647. _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 );
  9648. matricesTexture.needsUpdate = true;
  9649. const colorsTexture = this._colorsTexture;
  9650. if ( colorsTexture ) {
  9651. _whiteColor.toArray( colorsTexture.image.data, drawId * 4 );
  9652. colorsTexture.needsUpdate = true;
  9653. }
  9654. this._visibilityChanged = true;
  9655. return drawId;
  9656. }
  9657. addGeometry( geometry, reservedVertexCount = -1, reservedIndexCount = -1 ) {
  9658. this._initializeGeometry( geometry );
  9659. this._validateGeometry( geometry );
  9660. const geometryInfo = {
  9661. // geometry information
  9662. vertexStart: -1,
  9663. vertexCount: -1,
  9664. reservedVertexCount: -1,
  9665. indexStart: -1,
  9666. indexCount: -1,
  9667. reservedIndexCount: -1,
  9668. // draw range information
  9669. start: -1,
  9670. count: -1,
  9671. // state
  9672. boundingBox: null,
  9673. boundingSphere: null,
  9674. active: true,
  9675. };
  9676. const geometryInfoList = this._geometryInfo;
  9677. geometryInfo.vertexStart = this._nextVertexStart;
  9678. geometryInfo.reservedVertexCount = reservedVertexCount === -1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
  9679. const index = geometry.getIndex();
  9680. const hasIndex = index !== null;
  9681. if ( hasIndex ) {
  9682. geometryInfo.indexStart = this._nextIndexStart;
  9683. geometryInfo.reservedIndexCount = reservedIndexCount === -1 ? index.count : reservedIndexCount;
  9684. }
  9685. if (
  9686. geometryInfo.indexStart !== -1 &&
  9687. geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
  9688. geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
  9689. ) {
  9690. throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
  9691. }
  9692. // update id
  9693. let geometryId;
  9694. if ( this._availableGeometryIds.length > 0 ) {
  9695. this._availableGeometryIds.sort( ascIdSort );
  9696. geometryId = this._availableGeometryIds.shift();
  9697. geometryInfoList[ geometryId ] = geometryInfo;
  9698. } else {
  9699. geometryId = this._geometryCount;
  9700. this._geometryCount ++;
  9701. geometryInfoList.push( geometryInfo );
  9702. }
  9703. // update the geometry
  9704. this.setGeometryAt( geometryId, geometry );
  9705. // increment the next geometry position
  9706. this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
  9707. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9708. return geometryId;
  9709. }
  9710. setGeometryAt( geometryId, geometry ) {
  9711. if ( geometryId >= this._geometryCount ) {
  9712. throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
  9713. }
  9714. this._validateGeometry( geometry );
  9715. const batchGeometry = this.geometry;
  9716. const hasIndex = batchGeometry.getIndex() !== null;
  9717. const dstIndex = batchGeometry.getIndex();
  9718. const srcIndex = geometry.getIndex();
  9719. const geometryInfo = this._geometryInfo[ geometryId ];
  9720. if (
  9721. hasIndex &&
  9722. srcIndex.count > geometryInfo.reservedIndexCount ||
  9723. geometry.attributes.position.count > geometryInfo.reservedVertexCount
  9724. ) {
  9725. throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
  9726. }
  9727. // copy geometry buffer data over
  9728. const vertexStart = geometryInfo.vertexStart;
  9729. const reservedVertexCount = geometryInfo.reservedVertexCount;
  9730. geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
  9731. for ( const attributeName in batchGeometry.attributes ) {
  9732. // copy attribute data
  9733. const srcAttribute = geometry.getAttribute( attributeName );
  9734. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9735. copyAttributeData( srcAttribute, dstAttribute, vertexStart );
  9736. // fill the rest in with zeroes
  9737. const itemSize = srcAttribute.itemSize;
  9738. for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
  9739. const index = vertexStart + i;
  9740. for ( let c = 0; c < itemSize; c ++ ) {
  9741. dstAttribute.setComponent( index, c, 0 );
  9742. }
  9743. }
  9744. dstAttribute.needsUpdate = true;
  9745. dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
  9746. }
  9747. // copy index
  9748. if ( hasIndex ) {
  9749. const indexStart = geometryInfo.indexStart;
  9750. const reservedIndexCount = geometryInfo.reservedIndexCount;
  9751. geometryInfo.indexCount = geometry.getIndex().count;
  9752. // copy index data over
  9753. for ( let i = 0; i < srcIndex.count; i ++ ) {
  9754. dstIndex.setX( indexStart + i, vertexStart + srcIndex.getX( i ) );
  9755. }
  9756. // fill the rest in with zeroes
  9757. for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
  9758. dstIndex.setX( indexStart + i, vertexStart );
  9759. }
  9760. dstIndex.needsUpdate = true;
  9761. dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
  9762. }
  9763. // update the draw range
  9764. geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9765. geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
  9766. // store the bounding boxes
  9767. geometryInfo.boundingBox = null;
  9768. if ( geometry.boundingBox !== null ) {
  9769. geometryInfo.boundingBox = geometry.boundingBox.clone();
  9770. }
  9771. geometryInfo.boundingSphere = null;
  9772. if ( geometry.boundingSphere !== null ) {
  9773. geometryInfo.boundingSphere = geometry.boundingSphere.clone();
  9774. }
  9775. this._visibilityChanged = true;
  9776. return geometryId;
  9777. }
  9778. deleteGeometry( geometryId ) {
  9779. const geometryInfoList = this._geometryInfo;
  9780. if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9781. return this;
  9782. }
  9783. // delete any instances associated with this geometry
  9784. const instanceInfo = this._instanceInfo;
  9785. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9786. if ( instanceInfo[ i ].active && instanceInfo[ i ].geometryIndex === geometryId ) {
  9787. this.deleteInstance( i );
  9788. }
  9789. }
  9790. geometryInfoList[ geometryId ].active = false;
  9791. this._availableGeometryIds.push( geometryId );
  9792. this._visibilityChanged = true;
  9793. return this;
  9794. }
  9795. deleteInstance( instanceId ) {
  9796. this.validateInstanceId( instanceId );
  9797. this._instanceInfo[ instanceId ].active = false;
  9798. this._availableInstanceIds.push( instanceId );
  9799. this._visibilityChanged = true;
  9800. return this;
  9801. }
  9802. optimize() {
  9803. // track the next indices to copy data to
  9804. let nextVertexStart = 0;
  9805. let nextIndexStart = 0;
  9806. // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
  9807. // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
  9808. const geometryInfoList = this._geometryInfo;
  9809. const indices = geometryInfoList
  9810. .map( ( e, i ) => i )
  9811. .sort( ( a, b ) => {
  9812. return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
  9813. } );
  9814. const geometry = this.geometry;
  9815. for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
  9816. // if a geometry range is inactive then don't copy anything
  9817. const index = indices[ i ];
  9818. const geometryInfo = geometryInfoList[ index ];
  9819. if ( geometryInfo.active === false ) {
  9820. continue;
  9821. }
  9822. // if a geometry contains an index buffer then shift it, as well
  9823. if ( geometry.index !== null ) {
  9824. if ( geometryInfo.indexStart !== nextIndexStart ) {
  9825. const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
  9826. const index = geometry.index;
  9827. const array = index.array;
  9828. // shift the index pointers based on how the vertex data will shift
  9829. // adjusting the index must happen first so the original vertex start value is available
  9830. const elementDelta = nextVertexStart - vertexStart;
  9831. for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
  9832. array[ j ] = array[ j ] + elementDelta;
  9833. }
  9834. index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
  9835. index.addUpdateRange( nextIndexStart, reservedIndexCount );
  9836. geometryInfo.indexStart = nextIndexStart;
  9837. }
  9838. nextIndexStart += geometryInfo.reservedIndexCount;
  9839. }
  9840. // if a geometry needs to be moved then copy attribute data to overwrite unused space
  9841. if ( geometryInfo.vertexStart !== nextVertexStart ) {
  9842. const { vertexStart, reservedVertexCount } = geometryInfo;
  9843. const attributes = geometry.attributes;
  9844. for ( const key in attributes ) {
  9845. const attribute = attributes[ key ];
  9846. const { array, itemSize } = attribute;
  9847. array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
  9848. attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
  9849. }
  9850. geometryInfo.vertexStart = nextVertexStart;
  9851. }
  9852. nextVertexStart += geometryInfo.reservedVertexCount;
  9853. geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9854. // step the next geometry points to the shifted position
  9855. this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
  9856. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9857. }
  9858. return this;
  9859. }
  9860. // get bounding box and compute it if it doesn't exist
  9861. getBoundingBoxAt( geometryId, target ) {
  9862. if ( geometryId >= this._geometryCount ) {
  9863. return null;
  9864. }
  9865. // compute bounding box
  9866. const geometry = this.geometry;
  9867. const geometryInfo = this._geometryInfo[ geometryId ];
  9868. if ( geometryInfo.boundingBox === null ) {
  9869. const box = new Box3();
  9870. const index = geometry.index;
  9871. const position = geometry.attributes.position;
  9872. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9873. let iv = i;
  9874. if ( index ) {
  9875. iv = index.getX( iv );
  9876. }
  9877. box.expandByPoint( _vector$5.fromBufferAttribute( position, iv ) );
  9878. }
  9879. geometryInfo.boundingBox = box;
  9880. }
  9881. target.copy( geometryInfo.boundingBox );
  9882. return target;
  9883. }
  9884. // get bounding sphere and compute it if it doesn't exist
  9885. getBoundingSphereAt( geometryId, target ) {
  9886. if ( geometryId >= this._geometryCount ) {
  9887. return null;
  9888. }
  9889. // compute bounding sphere
  9890. const geometry = this.geometry;
  9891. const geometryInfo = this._geometryInfo[ geometryId ];
  9892. if ( geometryInfo.boundingSphere === null ) {
  9893. const sphere = new Sphere();
  9894. this.getBoundingBoxAt( geometryId, _box$1 );
  9895. _box$1.getCenter( sphere.center );
  9896. const index = geometry.index;
  9897. const position = geometry.attributes.position;
  9898. let maxRadiusSq = 0;
  9899. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9900. let iv = i;
  9901. if ( index ) {
  9902. iv = index.getX( iv );
  9903. }
  9904. _vector$5.fromBufferAttribute( position, iv );
  9905. maxRadiusSq = Math.max( maxRadiusSq, sphere.center.distanceToSquared( _vector$5 ) );
  9906. }
  9907. sphere.radius = Math.sqrt( maxRadiusSq );
  9908. geometryInfo.boundingSphere = sphere;
  9909. }
  9910. target.copy( geometryInfo.boundingSphere );
  9911. return target;
  9912. }
  9913. setMatrixAt( instanceId, matrix ) {
  9914. this.validateInstanceId( instanceId );
  9915. const matricesTexture = this._matricesTexture;
  9916. const matricesArray = this._matricesTexture.image.data;
  9917. matrix.toArray( matricesArray, instanceId * 16 );
  9918. matricesTexture.needsUpdate = true;
  9919. return this;
  9920. }
  9921. getMatrixAt( instanceId, matrix ) {
  9922. this.validateInstanceId( instanceId );
  9923. return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
  9924. }
  9925. setColorAt( instanceId, color ) {
  9926. this.validateInstanceId( instanceId );
  9927. if ( this._colorsTexture === null ) {
  9928. this._initColorsTexture();
  9929. }
  9930. color.toArray( this._colorsTexture.image.data, instanceId * 4 );
  9931. this._colorsTexture.needsUpdate = true;
  9932. return this;
  9933. }
  9934. getColorAt( instanceId, color ) {
  9935. this.validateInstanceId( instanceId );
  9936. return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
  9937. }
  9938. setVisibleAt( instanceId, value ) {
  9939. this.validateInstanceId( instanceId );
  9940. if ( this._instanceInfo[ instanceId ].visible === value ) {
  9941. return this;
  9942. }
  9943. this._instanceInfo[ instanceId ].visible = value;
  9944. this._visibilityChanged = true;
  9945. return this;
  9946. }
  9947. getVisibleAt( instanceId ) {
  9948. this.validateInstanceId( instanceId );
  9949. return this._instanceInfo[ instanceId ].visible;
  9950. }
  9951. setGeometryIdAt( instanceId, geometryId ) {
  9952. this.validateInstanceId( instanceId );
  9953. this.validateGeometryId( geometryId );
  9954. this._instanceInfo[ instanceId ].geometryIndex = geometryId;
  9955. return this;
  9956. }
  9957. getGeometryIdAt( instanceId ) {
  9958. this.validateInstanceId( instanceId );
  9959. return this._instanceInfo[ instanceId ].geometryIndex;
  9960. }
  9961. getGeometryRangeAt( geometryId, target = {} ) {
  9962. this.validateGeometryId( geometryId );
  9963. const geometryInfo = this._geometryInfo[ geometryId ];
  9964. target.vertexStart = geometryInfo.vertexStart;
  9965. target.vertexCount = geometryInfo.vertexCount;
  9966. target.reservedVertexCount = geometryInfo.reservedVertexCount;
  9967. target.indexStart = geometryInfo.indexStart;
  9968. target.indexCount = geometryInfo.indexCount;
  9969. target.reservedIndexCount = geometryInfo.reservedIndexCount;
  9970. target.start = geometryInfo.start;
  9971. target.count = geometryInfo.count;
  9972. return target;
  9973. }
  9974. setInstanceCount( maxInstanceCount ) {
  9975. // shrink the available instances as much as possible
  9976. const availableInstanceIds = this._availableInstanceIds;
  9977. const instanceInfo = this._instanceInfo;
  9978. availableInstanceIds.sort( ascIdSort );
  9979. while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
  9980. instanceInfo.pop();
  9981. availableInstanceIds.pop();
  9982. }
  9983. // throw an error if it can't be shrunk to the desired size
  9984. if ( maxInstanceCount < instanceInfo.length ) {
  9985. throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
  9986. }
  9987. // copy the multi draw counts
  9988. const multiDrawCounts = new Int32Array( maxInstanceCount );
  9989. const multiDrawStarts = new Int32Array( maxInstanceCount );
  9990. copyArrayContents( this._multiDrawCounts, multiDrawCounts );
  9991. copyArrayContents( this._multiDrawStarts, multiDrawStarts );
  9992. this._multiDrawCounts = multiDrawCounts;
  9993. this._multiDrawStarts = multiDrawStarts;
  9994. this._maxInstanceCount = maxInstanceCount;
  9995. // update texture data for instance sampling
  9996. const indirectTexture = this._indirectTexture;
  9997. const matricesTexture = this._matricesTexture;
  9998. const colorsTexture = this._colorsTexture;
  9999. indirectTexture.dispose();
  10000. this._initIndirectTexture();
  10001. copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
  10002. matricesTexture.dispose();
  10003. this._initMatricesTexture();
  10004. copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
  10005. if ( colorsTexture ) {
  10006. colorsTexture.dispose();
  10007. this._initColorsTexture();
  10008. copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
  10009. }
  10010. }
  10011. setGeometrySize( maxVertexCount, maxIndexCount ) {
  10012. // Check if we can shrink to the requested vertex attribute size
  10013. const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
  10014. const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
  10015. if ( requiredVertexLength > maxVertexCount ) {
  10016. throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  10017. }
  10018. // Check if we can shrink to the requested index attribute size
  10019. if ( this.geometry.index ) {
  10020. const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
  10021. if ( requiredIndexLength > maxIndexCount ) {
  10022. throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  10023. }
  10024. }
  10025. //
  10026. // dispose of the previous geometry
  10027. const oldGeometry = this.geometry;
  10028. oldGeometry.dispose();
  10029. // recreate the geometry needed based on the previous variant
  10030. this._maxVertexCount = maxVertexCount;
  10031. this._maxIndexCount = maxIndexCount;
  10032. if ( this._geometryInitialized ) {
  10033. this._geometryInitialized = false;
  10034. this.geometry = new BufferGeometry();
  10035. this._initializeGeometry( oldGeometry );
  10036. }
  10037. // copy data from the previous geometry
  10038. const geometry = this.geometry;
  10039. if ( oldGeometry.index ) {
  10040. copyArrayContents( oldGeometry.index.array, geometry.index.array );
  10041. }
  10042. for ( const key in oldGeometry.attributes ) {
  10043. copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
  10044. }
  10045. }
  10046. raycast( raycaster, intersects ) {
  10047. const instanceInfo = this._instanceInfo;
  10048. const geometryInfoList = this._geometryInfo;
  10049. const matrixWorld = this.matrixWorld;
  10050. const batchGeometry = this.geometry;
  10051. // iterate over each geometry
  10052. _mesh.material = this.material;
  10053. _mesh.geometry.index = batchGeometry.index;
  10054. _mesh.geometry.attributes = batchGeometry.attributes;
  10055. if ( _mesh.geometry.boundingBox === null ) {
  10056. _mesh.geometry.boundingBox = new Box3();
  10057. }
  10058. if ( _mesh.geometry.boundingSphere === null ) {
  10059. _mesh.geometry.boundingSphere = new Sphere();
  10060. }
  10061. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  10062. if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
  10063. continue;
  10064. }
  10065. const geometryId = instanceInfo[ i ].geometryIndex;
  10066. const geometryInfo = geometryInfoList[ geometryId ];
  10067. _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
  10068. // get the intersects
  10069. this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
  10070. this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
  10071. this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
  10072. _mesh.raycast( raycaster, _batchIntersects );
  10073. // add batch id to the intersects
  10074. for ( let j = 0, l = _batchIntersects.length; j < l; j ++ ) {
  10075. const intersect = _batchIntersects[ j ];
  10076. intersect.object = this;
  10077. intersect.batchId = i;
  10078. intersects.push( intersect );
  10079. }
  10080. _batchIntersects.length = 0;
  10081. }
  10082. _mesh.material = null;
  10083. _mesh.geometry.index = null;
  10084. _mesh.geometry.attributes = {};
  10085. _mesh.geometry.setDrawRange( 0, Infinity );
  10086. }
  10087. copy( source ) {
  10088. super.copy( source );
  10089. this.geometry = source.geometry.clone();
  10090. this.perObjectFrustumCulled = source.perObjectFrustumCulled;
  10091. this.sortObjects = source.sortObjects;
  10092. this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
  10093. this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
  10094. this._geometryInfo = source._geometryInfo.map( info => ( {
  10095. ...info,
  10096. boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
  10097. boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
  10098. } ) );
  10099. this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
  10100. this._maxInstanceCount = source._maxInstanceCount;
  10101. this._maxVertexCount = source._maxVertexCount;
  10102. this._maxIndexCount = source._maxIndexCount;
  10103. this._geometryInitialized = source._geometryInitialized;
  10104. this._geometryCount = source._geometryCount;
  10105. this._multiDrawCounts = source._multiDrawCounts.slice();
  10106. this._multiDrawStarts = source._multiDrawStarts.slice();
  10107. this._matricesTexture = source._matricesTexture.clone();
  10108. this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
  10109. if ( this._colorsTexture !== null ) {
  10110. this._colorsTexture = source._colorsTexture.clone();
  10111. this._colorsTexture.image.data = this._colorsTexture.image.data.slice();
  10112. }
  10113. return this;
  10114. }
  10115. dispose() {
  10116. // Assuming the geometry is not shared with other meshes
  10117. this.geometry.dispose();
  10118. this._matricesTexture.dispose();
  10119. this._matricesTexture = null;
  10120. this._indirectTexture.dispose();
  10121. this._indirectTexture = null;
  10122. if ( this._colorsTexture !== null ) {
  10123. this._colorsTexture.dispose();
  10124. this._colorsTexture = null;
  10125. }
  10126. return this;
  10127. }
  10128. onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) {
  10129. // if visibility has not changed and frustum culling and object sorting is not required
  10130. // then skip iterating over all items
  10131. if ( ! this._visibilityChanged && ! this.perObjectFrustumCulled && ! this.sortObjects ) {
  10132. return;
  10133. }
  10134. // the indexed version of the multi draw function requires specifying the start
  10135. // offset in bytes.
  10136. const index = geometry.getIndex();
  10137. const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
  10138. const instanceInfo = this._instanceInfo;
  10139. const multiDrawStarts = this._multiDrawStarts;
  10140. const multiDrawCounts = this._multiDrawCounts;
  10141. const geometryInfoList = this._geometryInfo;
  10142. const perObjectFrustumCulled = this.perObjectFrustumCulled;
  10143. const indirectTexture = this._indirectTexture;
  10144. const indirectArray = indirectTexture.image.data;
  10145. // prepare the frustum in the local frame
  10146. if ( perObjectFrustumCulled ) {
  10147. _matrix$1
  10148. .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
  10149. .multiply( this.matrixWorld );
  10150. _frustum.setFromProjectionMatrix(
  10151. _matrix$1,
  10152. renderer.coordinateSystem
  10153. );
  10154. }
  10155. let multiDrawCount = 0;
  10156. if ( this.sortObjects ) {
  10157. // get the camera position in the local frame
  10158. _matrix$1.copy( this.matrixWorld ).invert();
  10159. _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 );
  10160. _forward.set( 0, 0, -1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 );
  10161. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  10162. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  10163. const geometryId = instanceInfo[ i ].geometryIndex;
  10164. // get the bounds in world space
  10165. this.getMatrixAt( i, _matrix$1 );
  10166. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  10167. // determine whether the batched geometry is within the frustum
  10168. let culled = false;
  10169. if ( perObjectFrustumCulled ) {
  10170. culled = ! _frustum.intersectsSphere( _sphere$2 );
  10171. }
  10172. if ( ! culled ) {
  10173. // get the distance from camera used for sorting
  10174. const geometryInfo = geometryInfoList[ geometryId ];
  10175. const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
  10176. _renderList.push( geometryInfo.start, geometryInfo.count, z, i );
  10177. }
  10178. }
  10179. }
  10180. // Sort the draw ranges and prep for rendering
  10181. const list = _renderList.list;
  10182. const customSort = this.customSort;
  10183. if ( customSort === null ) {
  10184. list.sort( material.transparent ? sortTransparent : sortOpaque );
  10185. } else {
  10186. customSort.call( this, list, camera );
  10187. }
  10188. for ( let i = 0, l = list.length; i < l; i ++ ) {
  10189. const item = list[ i ];
  10190. multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement;
  10191. multiDrawCounts[ multiDrawCount ] = item.count;
  10192. indirectArray[ multiDrawCount ] = item.index;
  10193. multiDrawCount ++;
  10194. }
  10195. _renderList.reset();
  10196. } else {
  10197. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  10198. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  10199. const geometryId = instanceInfo[ i ].geometryIndex;
  10200. // determine whether the batched geometry is within the frustum
  10201. let culled = false;
  10202. if ( perObjectFrustumCulled ) {
  10203. // get the bounds in world space
  10204. this.getMatrixAt( i, _matrix$1 );
  10205. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  10206. culled = ! _frustum.intersectsSphere( _sphere$2 );
  10207. }
  10208. if ( ! culled ) {
  10209. const geometryInfo = geometryInfoList[ geometryId ];
  10210. multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement;
  10211. multiDrawCounts[ multiDrawCount ] = geometryInfo.count;
  10212. indirectArray[ multiDrawCount ] = i;
  10213. multiDrawCount ++;
  10214. }
  10215. }
  10216. }
  10217. }
  10218. indirectTexture.needsUpdate = true;
  10219. this._multiDrawCount = multiDrawCount;
  10220. this._visibilityChanged = false;
  10221. }
  10222. onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial/* , group */ ) {
  10223. this.onBeforeRender( renderer, null, shadowCamera, geometry, depthMaterial );
  10224. }
  10225. }
  10226. class LineBasicMaterial extends Material {
  10227. constructor( parameters ) {
  10228. super();
  10229. this.isLineBasicMaterial = true;
  10230. this.type = 'LineBasicMaterial';
  10231. this.color = new Color( 0xffffff );
  10232. this.map = null;
  10233. this.linewidth = 1;
  10234. this.linecap = 'round';
  10235. this.linejoin = 'round';
  10236. this.fog = true;
  10237. this.setValues( parameters );
  10238. }
  10239. copy( source ) {
  10240. super.copy( source );
  10241. this.color.copy( source.color );
  10242. this.map = source.map;
  10243. this.linewidth = source.linewidth;
  10244. this.linecap = source.linecap;
  10245. this.linejoin = source.linejoin;
  10246. this.fog = source.fog;
  10247. return this;
  10248. }
  10249. }
  10250. const _vStart = /*@__PURE__*/ new Vector3();
  10251. const _vEnd = /*@__PURE__*/ new Vector3();
  10252. const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
  10253. const _ray$1 = /*@__PURE__*/ new Ray();
  10254. const _sphere$1 = /*@__PURE__*/ new Sphere();
  10255. const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
  10256. const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
  10257. class Line extends Object3D {
  10258. constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  10259. super();
  10260. this.isLine = true;
  10261. this.type = 'Line';
  10262. this.geometry = geometry;
  10263. this.material = material;
  10264. this.updateMorphTargets();
  10265. }
  10266. copy( source, recursive ) {
  10267. super.copy( source, recursive );
  10268. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10269. this.geometry = source.geometry;
  10270. return this;
  10271. }
  10272. computeLineDistances() {
  10273. const geometry = this.geometry;
  10274. // we assume non-indexed geometry
  10275. if ( geometry.index === null ) {
  10276. const positionAttribute = geometry.attributes.position;
  10277. const lineDistances = [ 0 ];
  10278. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  10279. _vStart.fromBufferAttribute( positionAttribute, i - 1 );
  10280. _vEnd.fromBufferAttribute( positionAttribute, i );
  10281. lineDistances[ i ] = lineDistances[ i - 1 ];
  10282. lineDistances[ i ] += _vStart.distanceTo( _vEnd );
  10283. }
  10284. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10285. } else {
  10286. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10287. }
  10288. return this;
  10289. }
  10290. raycast( raycaster, intersects ) {
  10291. const geometry = this.geometry;
  10292. const matrixWorld = this.matrixWorld;
  10293. const threshold = raycaster.params.Line.threshold;
  10294. const drawRange = geometry.drawRange;
  10295. // Checking boundingSphere distance to ray
  10296. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10297. _sphere$1.copy( geometry.boundingSphere );
  10298. _sphere$1.applyMatrix4( matrixWorld );
  10299. _sphere$1.radius += threshold;
  10300. if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
  10301. //
  10302. _inverseMatrix$1.copy( matrixWorld ).invert();
  10303. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  10304. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10305. const localThresholdSq = localThreshold * localThreshold;
  10306. const step = this.isLineSegments ? 2 : 1;
  10307. const index = geometry.index;
  10308. const attributes = geometry.attributes;
  10309. const positionAttribute = attributes.position;
  10310. if ( index !== null ) {
  10311. const start = Math.max( 0, drawRange.start );
  10312. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10313. for ( let i = start, l = end - 1; i < l; i += step ) {
  10314. const a = index.getX( i );
  10315. const b = index.getX( i + 1 );
  10316. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10317. if ( intersect ) {
  10318. intersects.push( intersect );
  10319. }
  10320. }
  10321. if ( this.isLineLoop ) {
  10322. const a = index.getX( end - 1 );
  10323. const b = index.getX( start );
  10324. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10325. if ( intersect ) {
  10326. intersects.push( intersect );
  10327. }
  10328. }
  10329. } else {
  10330. const start = Math.max( 0, drawRange.start );
  10331. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10332. for ( let i = start, l = end - 1; i < l; i += step ) {
  10333. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 );
  10334. if ( intersect ) {
  10335. intersects.push( intersect );
  10336. }
  10337. }
  10338. if ( this.isLineLoop ) {
  10339. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start );
  10340. if ( intersect ) {
  10341. intersects.push( intersect );
  10342. }
  10343. }
  10344. }
  10345. }
  10346. updateMorphTargets() {
  10347. const geometry = this.geometry;
  10348. const morphAttributes = geometry.morphAttributes;
  10349. const keys = Object.keys( morphAttributes );
  10350. if ( keys.length > 0 ) {
  10351. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10352. if ( morphAttribute !== undefined ) {
  10353. this.morphTargetInfluences = [];
  10354. this.morphTargetDictionary = {};
  10355. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10356. const name = morphAttribute[ m ].name || String( m );
  10357. this.morphTargetInfluences.push( 0 );
  10358. this.morphTargetDictionary[ name ] = m;
  10359. }
  10360. }
  10361. }
  10362. }
  10363. }
  10364. function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
  10365. const positionAttribute = object.geometry.attributes.position;
  10366. _vStart.fromBufferAttribute( positionAttribute, a );
  10367. _vEnd.fromBufferAttribute( positionAttribute, b );
  10368. const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
  10369. if ( distSq > thresholdSq ) return;
  10370. _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
  10371. const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
  10372. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10373. return {
  10374. distance: distance,
  10375. // What do we want? intersection point on the ray or on the segment??
  10376. // point: raycaster.ray.at( distance ),
  10377. point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
  10378. index: a,
  10379. face: null,
  10380. faceIndex: null,
  10381. barycoord: null,
  10382. object: object
  10383. };
  10384. }
  10385. const _start = /*@__PURE__*/ new Vector3();
  10386. const _end = /*@__PURE__*/ new Vector3();
  10387. class LineSegments extends Line {
  10388. constructor( geometry, material ) {
  10389. super( geometry, material );
  10390. this.isLineSegments = true;
  10391. this.type = 'LineSegments';
  10392. }
  10393. computeLineDistances() {
  10394. const geometry = this.geometry;
  10395. // we assume non-indexed geometry
  10396. if ( geometry.index === null ) {
  10397. const positionAttribute = geometry.attributes.position;
  10398. const lineDistances = [];
  10399. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  10400. _start.fromBufferAttribute( positionAttribute, i );
  10401. _end.fromBufferAttribute( positionAttribute, i + 1 );
  10402. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  10403. lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
  10404. }
  10405. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10406. } else {
  10407. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10408. }
  10409. return this;
  10410. }
  10411. }
  10412. class LineLoop extends Line {
  10413. constructor( geometry, material ) {
  10414. super( geometry, material );
  10415. this.isLineLoop = true;
  10416. this.type = 'LineLoop';
  10417. }
  10418. }
  10419. class PointsMaterial extends Material {
  10420. constructor( parameters ) {
  10421. super();
  10422. this.isPointsMaterial = true;
  10423. this.type = 'PointsMaterial';
  10424. this.color = new Color( 0xffffff );
  10425. this.map = null;
  10426. this.alphaMap = null;
  10427. this.size = 1;
  10428. this.sizeAttenuation = true;
  10429. this.fog = true;
  10430. this.setValues( parameters );
  10431. }
  10432. copy( source ) {
  10433. super.copy( source );
  10434. this.color.copy( source.color );
  10435. this.map = source.map;
  10436. this.alphaMap = source.alphaMap;
  10437. this.size = source.size;
  10438. this.sizeAttenuation = source.sizeAttenuation;
  10439. this.fog = source.fog;
  10440. return this;
  10441. }
  10442. }
  10443. const _inverseMatrix = /*@__PURE__*/ new Matrix4();
  10444. const _ray = /*@__PURE__*/ new Ray();
  10445. const _sphere = /*@__PURE__*/ new Sphere();
  10446. const _position$2 = /*@__PURE__*/ new Vector3();
  10447. class Points extends Object3D {
  10448. constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  10449. super();
  10450. this.isPoints = true;
  10451. this.type = 'Points';
  10452. this.geometry = geometry;
  10453. this.material = material;
  10454. this.updateMorphTargets();
  10455. }
  10456. copy( source, recursive ) {
  10457. super.copy( source, recursive );
  10458. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10459. this.geometry = source.geometry;
  10460. return this;
  10461. }
  10462. raycast( raycaster, intersects ) {
  10463. const geometry = this.geometry;
  10464. const matrixWorld = this.matrixWorld;
  10465. const threshold = raycaster.params.Points.threshold;
  10466. const drawRange = geometry.drawRange;
  10467. // Checking boundingSphere distance to ray
  10468. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10469. _sphere.copy( geometry.boundingSphere );
  10470. _sphere.applyMatrix4( matrixWorld );
  10471. _sphere.radius += threshold;
  10472. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  10473. //
  10474. _inverseMatrix.copy( matrixWorld ).invert();
  10475. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  10476. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10477. const localThresholdSq = localThreshold * localThreshold;
  10478. const index = geometry.index;
  10479. const attributes = geometry.attributes;
  10480. const positionAttribute = attributes.position;
  10481. if ( index !== null ) {
  10482. const start = Math.max( 0, drawRange.start );
  10483. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10484. for ( let i = start, il = end; i < il; i ++ ) {
  10485. const a = index.getX( i );
  10486. _position$2.fromBufferAttribute( positionAttribute, a );
  10487. testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10488. }
  10489. } else {
  10490. const start = Math.max( 0, drawRange.start );
  10491. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10492. for ( let i = start, l = end; i < l; i ++ ) {
  10493. _position$2.fromBufferAttribute( positionAttribute, i );
  10494. testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10495. }
  10496. }
  10497. }
  10498. updateMorphTargets() {
  10499. const geometry = this.geometry;
  10500. const morphAttributes = geometry.morphAttributes;
  10501. const keys = Object.keys( morphAttributes );
  10502. if ( keys.length > 0 ) {
  10503. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10504. if ( morphAttribute !== undefined ) {
  10505. this.morphTargetInfluences = [];
  10506. this.morphTargetDictionary = {};
  10507. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10508. const name = morphAttribute[ m ].name || String( m );
  10509. this.morphTargetInfluences.push( 0 );
  10510. this.morphTargetDictionary[ name ] = m;
  10511. }
  10512. }
  10513. }
  10514. }
  10515. }
  10516. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  10517. const rayPointDistanceSq = _ray.distanceSqToPoint( point );
  10518. if ( rayPointDistanceSq < localThresholdSq ) {
  10519. const intersectPoint = new Vector3();
  10520. _ray.closestPointToPoint( point, intersectPoint );
  10521. intersectPoint.applyMatrix4( matrixWorld );
  10522. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10523. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10524. intersects.push( {
  10525. distance: distance,
  10526. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10527. point: intersectPoint,
  10528. index: index,
  10529. face: null,
  10530. faceIndex: null,
  10531. barycoord: null,
  10532. object: object
  10533. } );
  10534. }
  10535. }
  10536. class VideoTexture extends Texture {
  10537. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10538. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10539. this.isVideoTexture = true;
  10540. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  10541. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  10542. this.generateMipmaps = false;
  10543. const scope = this;
  10544. function updateVideo() {
  10545. scope.needsUpdate = true;
  10546. video.requestVideoFrameCallback( updateVideo );
  10547. }
  10548. if ( 'requestVideoFrameCallback' in video ) {
  10549. video.requestVideoFrameCallback( updateVideo );
  10550. }
  10551. }
  10552. clone() {
  10553. return new this.constructor( this.image ).copy( this );
  10554. }
  10555. update() {
  10556. const video = this.image;
  10557. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  10558. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  10559. this.needsUpdate = true;
  10560. }
  10561. }
  10562. }
  10563. class VideoFrameTexture extends VideoTexture {
  10564. constructor( mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10565. super( {}, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10566. this.isVideoFrameTexture = true;
  10567. }
  10568. update() {
  10569. // overwrites `VideoTexture.update()` with an empty method since
  10570. // this type of texture is updated via `setFrame()`.
  10571. }
  10572. clone() {
  10573. return new this.constructor().copy( this ); // restoring Texture.clone()
  10574. }
  10575. setFrame( frame ) {
  10576. this.image = frame;
  10577. this.needsUpdate = true;
  10578. }
  10579. }
  10580. class FramebufferTexture extends Texture {
  10581. constructor( width, height ) {
  10582. super( { width, height } );
  10583. this.isFramebufferTexture = true;
  10584. this.magFilter = NearestFilter;
  10585. this.minFilter = NearestFilter;
  10586. this.generateMipmaps = false;
  10587. this.needsUpdate = true;
  10588. }
  10589. }
  10590. class CompressedTexture extends Texture {
  10591. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) {
  10592. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  10593. this.isCompressedTexture = true;
  10594. this.image = { width: width, height: height };
  10595. this.mipmaps = mipmaps;
  10596. // no flipping for cube textures
  10597. // (also flipping doesn't work for compressed textures )
  10598. this.flipY = false;
  10599. // can't generate mipmaps for compressed textures
  10600. // mips must be embedded in DDS files
  10601. this.generateMipmaps = false;
  10602. }
  10603. }
  10604. class CompressedArrayTexture extends CompressedTexture {
  10605. constructor( mipmaps, width, height, depth, format, type ) {
  10606. super( mipmaps, width, height, format, type );
  10607. this.isCompressedArrayTexture = true;
  10608. this.image.depth = depth;
  10609. this.wrapR = ClampToEdgeWrapping;
  10610. this.layerUpdates = new Set();
  10611. }
  10612. addLayerUpdate( layerIndex ) {
  10613. this.layerUpdates.add( layerIndex );
  10614. }
  10615. clearLayerUpdates() {
  10616. this.layerUpdates.clear();
  10617. }
  10618. }
  10619. class CompressedCubeTexture extends CompressedTexture {
  10620. constructor( images, format, type ) {
  10621. super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );
  10622. this.isCompressedCubeTexture = true;
  10623. this.isCubeTexture = true;
  10624. this.image = images;
  10625. }
  10626. }
  10627. class CanvasTexture extends Texture {
  10628. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10629. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10630. this.isCanvasTexture = true;
  10631. this.needsUpdate = true;
  10632. }
  10633. }
  10634. class DepthTexture extends Texture {
  10635. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
  10636. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  10637. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  10638. }
  10639. if ( type === undefined && format === DepthFormat ) type = UnsignedIntType;
  10640. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  10641. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10642. this.isDepthTexture = true;
  10643. this.image = { width: width, height: height };
  10644. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  10645. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  10646. this.flipY = false;
  10647. this.generateMipmaps = false;
  10648. this.compareFunction = null;
  10649. }
  10650. copy( source ) {
  10651. super.copy( source );
  10652. this.compareFunction = source.compareFunction;
  10653. return this;
  10654. }
  10655. toJSON( meta ) {
  10656. const data = super.toJSON( meta );
  10657. if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;
  10658. return data;
  10659. }
  10660. }
  10661. /**
  10662. * Extensible curve object.
  10663. *
  10664. * Some common of curve methods:
  10665. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  10666. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  10667. * .getPoints(), .getSpacedPoints()
  10668. * .getLength()
  10669. * .updateArcLengths()
  10670. *
  10671. * This following curves inherit from THREE.Curve:
  10672. *
  10673. * -- 2D curves --
  10674. * THREE.ArcCurve
  10675. * THREE.CubicBezierCurve
  10676. * THREE.EllipseCurve
  10677. * THREE.LineCurve
  10678. * THREE.QuadraticBezierCurve
  10679. * THREE.SplineCurve
  10680. *
  10681. * -- 3D curves --
  10682. * THREE.CatmullRomCurve3
  10683. * THREE.CubicBezierCurve3
  10684. * THREE.LineCurve3
  10685. * THREE.QuadraticBezierCurve3
  10686. *
  10687. * A series of curves can be represented as a THREE.CurvePath.
  10688. *
  10689. **/
  10690. class Curve {
  10691. constructor() {
  10692. this.type = 'Curve';
  10693. this.arcLengthDivisions = 200;
  10694. }
  10695. // Virtual base class method to overwrite and implement in subclasses
  10696. // - t [0 .. 1]
  10697. getPoint( /* t, optionalTarget */ ) {
  10698. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  10699. return null;
  10700. }
  10701. // Get point at relative position in curve according to arc length
  10702. // - u [0 .. 1]
  10703. getPointAt( u, optionalTarget ) {
  10704. const t = this.getUtoTmapping( u );
  10705. return this.getPoint( t, optionalTarget );
  10706. }
  10707. // Get sequence of points using getPoint( t )
  10708. getPoints( divisions = 5 ) {
  10709. const points = [];
  10710. for ( let d = 0; d <= divisions; d ++ ) {
  10711. points.push( this.getPoint( d / divisions ) );
  10712. }
  10713. return points;
  10714. }
  10715. // Get sequence of points using getPointAt( u )
  10716. getSpacedPoints( divisions = 5 ) {
  10717. const points = [];
  10718. for ( let d = 0; d <= divisions; d ++ ) {
  10719. points.push( this.getPointAt( d / divisions ) );
  10720. }
  10721. return points;
  10722. }
  10723. // Get total curve arc length
  10724. getLength() {
  10725. const lengths = this.getLengths();
  10726. return lengths[ lengths.length - 1 ];
  10727. }
  10728. // Get list of cumulative segment lengths
  10729. getLengths( divisions = this.arcLengthDivisions ) {
  10730. if ( this.cacheArcLengths &&
  10731. ( this.cacheArcLengths.length === divisions + 1 ) &&
  10732. ! this.needsUpdate ) {
  10733. return this.cacheArcLengths;
  10734. }
  10735. this.needsUpdate = false;
  10736. const cache = [];
  10737. let current, last = this.getPoint( 0 );
  10738. let sum = 0;
  10739. cache.push( 0 );
  10740. for ( let p = 1; p <= divisions; p ++ ) {
  10741. current = this.getPoint( p / divisions );
  10742. sum += current.distanceTo( last );
  10743. cache.push( sum );
  10744. last = current;
  10745. }
  10746. this.cacheArcLengths = cache;
  10747. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  10748. }
  10749. updateArcLengths() {
  10750. this.needsUpdate = true;
  10751. this.getLengths();
  10752. }
  10753. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  10754. getUtoTmapping( u, distance ) {
  10755. const arcLengths = this.getLengths();
  10756. let i = 0;
  10757. const il = arcLengths.length;
  10758. let targetArcLength; // The targeted u distance value to get
  10759. if ( distance ) {
  10760. targetArcLength = distance;
  10761. } else {
  10762. targetArcLength = u * arcLengths[ il - 1 ];
  10763. }
  10764. // binary search for the index with largest value smaller than target u distance
  10765. let low = 0, high = il - 1, comparison;
  10766. while ( low <= high ) {
  10767. 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
  10768. comparison = arcLengths[ i ] - targetArcLength;
  10769. if ( comparison < 0 ) {
  10770. low = i + 1;
  10771. } else if ( comparison > 0 ) {
  10772. high = i - 1;
  10773. } else {
  10774. high = i;
  10775. break;
  10776. // DONE
  10777. }
  10778. }
  10779. i = high;
  10780. if ( arcLengths[ i ] === targetArcLength ) {
  10781. return i / ( il - 1 );
  10782. }
  10783. // we could get finer grain at lengths, or use simple interpolation between two points
  10784. const lengthBefore = arcLengths[ i ];
  10785. const lengthAfter = arcLengths[ i + 1 ];
  10786. const segmentLength = lengthAfter - lengthBefore;
  10787. // determine where we are between the 'before' and 'after' points
  10788. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  10789. // add that fractional amount to t
  10790. const t = ( i + segmentFraction ) / ( il - 1 );
  10791. return t;
  10792. }
  10793. // Returns a unit vector tangent at t
  10794. // In case any sub curve does not implement its tangent derivation,
  10795. // 2 points a small delta apart will be used to find its gradient
  10796. // which seems to give a reasonable approximation
  10797. getTangent( t, optionalTarget ) {
  10798. const delta = 0.0001;
  10799. let t1 = t - delta;
  10800. let t2 = t + delta;
  10801. // Capping in case of danger
  10802. if ( t1 < 0 ) t1 = 0;
  10803. if ( t2 > 1 ) t2 = 1;
  10804. const pt1 = this.getPoint( t1 );
  10805. const pt2 = this.getPoint( t2 );
  10806. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  10807. tangent.copy( pt2 ).sub( pt1 ).normalize();
  10808. return tangent;
  10809. }
  10810. getTangentAt( u, optionalTarget ) {
  10811. const t = this.getUtoTmapping( u );
  10812. return this.getTangent( t, optionalTarget );
  10813. }
  10814. computeFrenetFrames( segments, closed ) {
  10815. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  10816. const normal = new Vector3();
  10817. const tangents = [];
  10818. const normals = [];
  10819. const binormals = [];
  10820. const vec = new Vector3();
  10821. const mat = new Matrix4();
  10822. // compute the tangent vectors for each segment on the curve
  10823. for ( let i = 0; i <= segments; i ++ ) {
  10824. const u = i / segments;
  10825. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  10826. }
  10827. // select an initial normal vector perpendicular to the first tangent vector,
  10828. // and in the direction of the minimum tangent xyz component
  10829. normals[ 0 ] = new Vector3();
  10830. binormals[ 0 ] = new Vector3();
  10831. let min = Number.MAX_VALUE;
  10832. const tx = Math.abs( tangents[ 0 ].x );
  10833. const ty = Math.abs( tangents[ 0 ].y );
  10834. const tz = Math.abs( tangents[ 0 ].z );
  10835. if ( tx <= min ) {
  10836. min = tx;
  10837. normal.set( 1, 0, 0 );
  10838. }
  10839. if ( ty <= min ) {
  10840. min = ty;
  10841. normal.set( 0, 1, 0 );
  10842. }
  10843. if ( tz <= min ) {
  10844. normal.set( 0, 0, 1 );
  10845. }
  10846. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  10847. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  10848. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  10849. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  10850. for ( let i = 1; i <= segments; i ++ ) {
  10851. normals[ i ] = normals[ i - 1 ].clone();
  10852. binormals[ i ] = binormals[ i - 1 ].clone();
  10853. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  10854. if ( vec.length() > Number.EPSILON ) {
  10855. vec.normalize();
  10856. const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), -1, 1 ) ); // clamp for floating pt errors
  10857. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  10858. }
  10859. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10860. }
  10861. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  10862. if ( closed === true ) {
  10863. let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), -1, 1 ) );
  10864. theta /= segments;
  10865. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  10866. theta = - theta;
  10867. }
  10868. for ( let i = 1; i <= segments; i ++ ) {
  10869. // twist a little...
  10870. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  10871. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10872. }
  10873. }
  10874. return {
  10875. tangents: tangents,
  10876. normals: normals,
  10877. binormals: binormals
  10878. };
  10879. }
  10880. clone() {
  10881. return new this.constructor().copy( this );
  10882. }
  10883. copy( source ) {
  10884. this.arcLengthDivisions = source.arcLengthDivisions;
  10885. return this;
  10886. }
  10887. toJSON() {
  10888. const data = {
  10889. metadata: {
  10890. version: 4.6,
  10891. type: 'Curve',
  10892. generator: 'Curve.toJSON'
  10893. }
  10894. };
  10895. data.arcLengthDivisions = this.arcLengthDivisions;
  10896. data.type = this.type;
  10897. return data;
  10898. }
  10899. fromJSON( json ) {
  10900. this.arcLengthDivisions = json.arcLengthDivisions;
  10901. return this;
  10902. }
  10903. }
  10904. class EllipseCurve extends Curve {
  10905. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  10906. super();
  10907. this.isEllipseCurve = true;
  10908. this.type = 'EllipseCurve';
  10909. this.aX = aX;
  10910. this.aY = aY;
  10911. this.xRadius = xRadius;
  10912. this.yRadius = yRadius;
  10913. this.aStartAngle = aStartAngle;
  10914. this.aEndAngle = aEndAngle;
  10915. this.aClockwise = aClockwise;
  10916. this.aRotation = aRotation;
  10917. }
  10918. getPoint( t, optionalTarget = new Vector2() ) {
  10919. const point = optionalTarget;
  10920. const twoPi = Math.PI * 2;
  10921. let deltaAngle = this.aEndAngle - this.aStartAngle;
  10922. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  10923. // ensures that deltaAngle is 0 .. 2 PI
  10924. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  10925. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  10926. if ( deltaAngle < Number.EPSILON ) {
  10927. if ( samePoints ) {
  10928. deltaAngle = 0;
  10929. } else {
  10930. deltaAngle = twoPi;
  10931. }
  10932. }
  10933. if ( this.aClockwise === true && ! samePoints ) {
  10934. if ( deltaAngle === twoPi ) {
  10935. deltaAngle = - twoPi;
  10936. } else {
  10937. deltaAngle = deltaAngle - twoPi;
  10938. }
  10939. }
  10940. const angle = this.aStartAngle + t * deltaAngle;
  10941. let x = this.aX + this.xRadius * Math.cos( angle );
  10942. let y = this.aY + this.yRadius * Math.sin( angle );
  10943. if ( this.aRotation !== 0 ) {
  10944. const cos = Math.cos( this.aRotation );
  10945. const sin = Math.sin( this.aRotation );
  10946. const tx = x - this.aX;
  10947. const ty = y - this.aY;
  10948. // Rotate the point about the center of the ellipse.
  10949. x = tx * cos - ty * sin + this.aX;
  10950. y = tx * sin + ty * cos + this.aY;
  10951. }
  10952. return point.set( x, y );
  10953. }
  10954. copy( source ) {
  10955. super.copy( source );
  10956. this.aX = source.aX;
  10957. this.aY = source.aY;
  10958. this.xRadius = source.xRadius;
  10959. this.yRadius = source.yRadius;
  10960. this.aStartAngle = source.aStartAngle;
  10961. this.aEndAngle = source.aEndAngle;
  10962. this.aClockwise = source.aClockwise;
  10963. this.aRotation = source.aRotation;
  10964. return this;
  10965. }
  10966. toJSON() {
  10967. const data = super.toJSON();
  10968. data.aX = this.aX;
  10969. data.aY = this.aY;
  10970. data.xRadius = this.xRadius;
  10971. data.yRadius = this.yRadius;
  10972. data.aStartAngle = this.aStartAngle;
  10973. data.aEndAngle = this.aEndAngle;
  10974. data.aClockwise = this.aClockwise;
  10975. data.aRotation = this.aRotation;
  10976. return data;
  10977. }
  10978. fromJSON( json ) {
  10979. super.fromJSON( json );
  10980. this.aX = json.aX;
  10981. this.aY = json.aY;
  10982. this.xRadius = json.xRadius;
  10983. this.yRadius = json.yRadius;
  10984. this.aStartAngle = json.aStartAngle;
  10985. this.aEndAngle = json.aEndAngle;
  10986. this.aClockwise = json.aClockwise;
  10987. this.aRotation = json.aRotation;
  10988. return this;
  10989. }
  10990. }
  10991. class ArcCurve extends EllipseCurve {
  10992. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  10993. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  10994. this.isArcCurve = true;
  10995. this.type = 'ArcCurve';
  10996. }
  10997. }
  10998. /**
  10999. * Centripetal CatmullRom Curve - which is useful for avoiding
  11000. * cusps and self-intersections in non-uniform catmull rom curves.
  11001. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  11002. *
  11003. * curve.type accepts centripetal(default), chordal and catmullrom
  11004. * curve.tension is used for catmullrom which defaults to 0.5
  11005. */
  11006. /*
  11007. Based on an optimized c++ solution in
  11008. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  11009. - http://ideone.com/NoEbVM
  11010. This CubicPoly class could be used for reusing some variables and calculations,
  11011. but for three.js curve use, it could be possible inlined and flatten into a single function call
  11012. which can be placed in CurveUtils.
  11013. */
  11014. function CubicPoly() {
  11015. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  11016. /*
  11017. * Compute coefficients for a cubic polynomial
  11018. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  11019. * such that
  11020. * p(0) = x0, p(1) = x1
  11021. * and
  11022. * p'(0) = t0, p'(1) = t1.
  11023. */
  11024. function init( x0, x1, t0, t1 ) {
  11025. c0 = x0;
  11026. c1 = t0;
  11027. c2 = -3 * x0 + 3 * x1 - 2 * t0 - t1;
  11028. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  11029. }
  11030. return {
  11031. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  11032. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  11033. },
  11034. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  11035. // compute tangents when parameterized in [t1,t2]
  11036. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  11037. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  11038. // rescale tangents for parametrization in [0,1]
  11039. t1 *= dt1;
  11040. t2 *= dt1;
  11041. init( x1, x2, t1, t2 );
  11042. },
  11043. calc: function ( t ) {
  11044. const t2 = t * t;
  11045. const t3 = t2 * t;
  11046. return c0 + c1 * t + c2 * t2 + c3 * t3;
  11047. }
  11048. };
  11049. }
  11050. //
  11051. const tmp = /*@__PURE__*/ new Vector3();
  11052. const px = /*@__PURE__*/ new CubicPoly();
  11053. const py = /*@__PURE__*/ new CubicPoly();
  11054. const pz = /*@__PURE__*/ new CubicPoly();
  11055. class CatmullRomCurve3 extends Curve {
  11056. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  11057. super();
  11058. this.isCatmullRomCurve3 = true;
  11059. this.type = 'CatmullRomCurve3';
  11060. this.points = points;
  11061. this.closed = closed;
  11062. this.curveType = curveType;
  11063. this.tension = tension;
  11064. }
  11065. getPoint( t, optionalTarget = new Vector3() ) {
  11066. const point = optionalTarget;
  11067. const points = this.points;
  11068. const l = points.length;
  11069. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  11070. let intPoint = Math.floor( p );
  11071. let weight = p - intPoint;
  11072. if ( this.closed ) {
  11073. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  11074. } else if ( weight === 0 && intPoint === l - 1 ) {
  11075. intPoint = l - 2;
  11076. weight = 1;
  11077. }
  11078. let p0, p3; // 4 points (p1 & p2 defined below)
  11079. if ( this.closed || intPoint > 0 ) {
  11080. p0 = points[ ( intPoint - 1 ) % l ];
  11081. } else {
  11082. // extrapolate first point
  11083. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  11084. p0 = tmp;
  11085. }
  11086. const p1 = points[ intPoint % l ];
  11087. const p2 = points[ ( intPoint + 1 ) % l ];
  11088. if ( this.closed || intPoint + 2 < l ) {
  11089. p3 = points[ ( intPoint + 2 ) % l ];
  11090. } else {
  11091. // extrapolate last point
  11092. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  11093. p3 = tmp;
  11094. }
  11095. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  11096. // init Centripetal / Chordal Catmull-Rom
  11097. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  11098. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  11099. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  11100. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  11101. // safety check for repeated points
  11102. if ( dt1 < 1e-4 ) dt1 = 1.0;
  11103. if ( dt0 < 1e-4 ) dt0 = dt1;
  11104. if ( dt2 < 1e-4 ) dt2 = dt1;
  11105. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  11106. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  11107. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  11108. } else if ( this.curveType === 'catmullrom' ) {
  11109. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  11110. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  11111. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  11112. }
  11113. point.set(
  11114. px.calc( weight ),
  11115. py.calc( weight ),
  11116. pz.calc( weight )
  11117. );
  11118. return point;
  11119. }
  11120. copy( source ) {
  11121. super.copy( source );
  11122. this.points = [];
  11123. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  11124. const point = source.points[ i ];
  11125. this.points.push( point.clone() );
  11126. }
  11127. this.closed = source.closed;
  11128. this.curveType = source.curveType;
  11129. this.tension = source.tension;
  11130. return this;
  11131. }
  11132. toJSON() {
  11133. const data = super.toJSON();
  11134. data.points = [];
  11135. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  11136. const point = this.points[ i ];
  11137. data.points.push( point.toArray() );
  11138. }
  11139. data.closed = this.closed;
  11140. data.curveType = this.curveType;
  11141. data.tension = this.tension;
  11142. return data;
  11143. }
  11144. fromJSON( json ) {
  11145. super.fromJSON( json );
  11146. this.points = [];
  11147. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  11148. const point = json.points[ i ];
  11149. this.points.push( new Vector3().fromArray( point ) );
  11150. }
  11151. this.closed = json.closed;
  11152. this.curveType = json.curveType;
  11153. this.tension = json.tension;
  11154. return this;
  11155. }
  11156. }
  11157. /**
  11158. * Bezier Curves formulas obtained from
  11159. * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
  11160. */
  11161. function CatmullRom( t, p0, p1, p2, p3 ) {
  11162. const v0 = ( p2 - p0 ) * 0.5;
  11163. const v1 = ( p3 - p1 ) * 0.5;
  11164. const t2 = t * t;
  11165. const t3 = t * t2;
  11166. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( -3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  11167. }
  11168. //
  11169. function QuadraticBezierP0( t, p ) {
  11170. const k = 1 - t;
  11171. return k * k * p;
  11172. }
  11173. function QuadraticBezierP1( t, p ) {
  11174. return 2 * ( 1 - t ) * t * p;
  11175. }
  11176. function QuadraticBezierP2( t, p ) {
  11177. return t * t * p;
  11178. }
  11179. function QuadraticBezier( t, p0, p1, p2 ) {
  11180. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  11181. QuadraticBezierP2( t, p2 );
  11182. }
  11183. //
  11184. function CubicBezierP0( t, p ) {
  11185. const k = 1 - t;
  11186. return k * k * k * p;
  11187. }
  11188. function CubicBezierP1( t, p ) {
  11189. const k = 1 - t;
  11190. return 3 * k * k * t * p;
  11191. }
  11192. function CubicBezierP2( t, p ) {
  11193. return 3 * ( 1 - t ) * t * t * p;
  11194. }
  11195. function CubicBezierP3( t, p ) {
  11196. return t * t * t * p;
  11197. }
  11198. function CubicBezier( t, p0, p1, p2, p3 ) {
  11199. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  11200. CubicBezierP3( t, p3 );
  11201. }
  11202. class CubicBezierCurve extends Curve {
  11203. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  11204. super();
  11205. this.isCubicBezierCurve = true;
  11206. this.type = 'CubicBezierCurve';
  11207. this.v0 = v0;
  11208. this.v1 = v1;
  11209. this.v2 = v2;
  11210. this.v3 = v3;
  11211. }
  11212. getPoint( t, optionalTarget = new Vector2() ) {
  11213. const point = optionalTarget;
  11214. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11215. point.set(
  11216. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11217. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  11218. );
  11219. return point;
  11220. }
  11221. copy( source ) {
  11222. super.copy( source );
  11223. this.v0.copy( source.v0 );
  11224. this.v1.copy( source.v1 );
  11225. this.v2.copy( source.v2 );
  11226. this.v3.copy( source.v3 );
  11227. return this;
  11228. }
  11229. toJSON() {
  11230. const data = super.toJSON();
  11231. data.v0 = this.v0.toArray();
  11232. data.v1 = this.v1.toArray();
  11233. data.v2 = this.v2.toArray();
  11234. data.v3 = this.v3.toArray();
  11235. return data;
  11236. }
  11237. fromJSON( json ) {
  11238. super.fromJSON( json );
  11239. this.v0.fromArray( json.v0 );
  11240. this.v1.fromArray( json.v1 );
  11241. this.v2.fromArray( json.v2 );
  11242. this.v3.fromArray( json.v3 );
  11243. return this;
  11244. }
  11245. }
  11246. class CubicBezierCurve3 extends Curve {
  11247. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  11248. super();
  11249. this.isCubicBezierCurve3 = true;
  11250. this.type = 'CubicBezierCurve3';
  11251. this.v0 = v0;
  11252. this.v1 = v1;
  11253. this.v2 = v2;
  11254. this.v3 = v3;
  11255. }
  11256. getPoint( t, optionalTarget = new Vector3() ) {
  11257. const point = optionalTarget;
  11258. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11259. point.set(
  11260. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11261. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  11262. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  11263. );
  11264. return point;
  11265. }
  11266. copy( source ) {
  11267. super.copy( source );
  11268. this.v0.copy( source.v0 );
  11269. this.v1.copy( source.v1 );
  11270. this.v2.copy( source.v2 );
  11271. this.v3.copy( source.v3 );
  11272. return this;
  11273. }
  11274. toJSON() {
  11275. const data = super.toJSON();
  11276. data.v0 = this.v0.toArray();
  11277. data.v1 = this.v1.toArray();
  11278. data.v2 = this.v2.toArray();
  11279. data.v3 = this.v3.toArray();
  11280. return data;
  11281. }
  11282. fromJSON( json ) {
  11283. super.fromJSON( json );
  11284. this.v0.fromArray( json.v0 );
  11285. this.v1.fromArray( json.v1 );
  11286. this.v2.fromArray( json.v2 );
  11287. this.v3.fromArray( json.v3 );
  11288. return this;
  11289. }
  11290. }
  11291. class LineCurve extends Curve {
  11292. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  11293. super();
  11294. this.isLineCurve = true;
  11295. this.type = 'LineCurve';
  11296. this.v1 = v1;
  11297. this.v2 = v2;
  11298. }
  11299. getPoint( t, optionalTarget = new Vector2() ) {
  11300. const point = optionalTarget;
  11301. if ( t === 1 ) {
  11302. point.copy( this.v2 );
  11303. } else {
  11304. point.copy( this.v2 ).sub( this.v1 );
  11305. point.multiplyScalar( t ).add( this.v1 );
  11306. }
  11307. return point;
  11308. }
  11309. // Line curve is linear, so we can overwrite default getPointAt
  11310. getPointAt( u, optionalTarget ) {
  11311. return this.getPoint( u, optionalTarget );
  11312. }
  11313. getTangent( t, optionalTarget = new Vector2() ) {
  11314. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11315. }
  11316. getTangentAt( u, optionalTarget ) {
  11317. return this.getTangent( u, optionalTarget );
  11318. }
  11319. copy( source ) {
  11320. super.copy( source );
  11321. this.v1.copy( source.v1 );
  11322. this.v2.copy( source.v2 );
  11323. return this;
  11324. }
  11325. toJSON() {
  11326. const data = super.toJSON();
  11327. data.v1 = this.v1.toArray();
  11328. data.v2 = this.v2.toArray();
  11329. return data;
  11330. }
  11331. fromJSON( json ) {
  11332. super.fromJSON( json );
  11333. this.v1.fromArray( json.v1 );
  11334. this.v2.fromArray( json.v2 );
  11335. return this;
  11336. }
  11337. }
  11338. class LineCurve3 extends Curve {
  11339. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  11340. super();
  11341. this.isLineCurve3 = true;
  11342. this.type = 'LineCurve3';
  11343. this.v1 = v1;
  11344. this.v2 = v2;
  11345. }
  11346. getPoint( t, optionalTarget = new Vector3() ) {
  11347. const point = optionalTarget;
  11348. if ( t === 1 ) {
  11349. point.copy( this.v2 );
  11350. } else {
  11351. point.copy( this.v2 ).sub( this.v1 );
  11352. point.multiplyScalar( t ).add( this.v1 );
  11353. }
  11354. return point;
  11355. }
  11356. // Line curve is linear, so we can overwrite default getPointAt
  11357. getPointAt( u, optionalTarget ) {
  11358. return this.getPoint( u, optionalTarget );
  11359. }
  11360. getTangent( t, optionalTarget = new Vector3() ) {
  11361. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11362. }
  11363. getTangentAt( u, optionalTarget ) {
  11364. return this.getTangent( u, optionalTarget );
  11365. }
  11366. copy( source ) {
  11367. super.copy( source );
  11368. this.v1.copy( source.v1 );
  11369. this.v2.copy( source.v2 );
  11370. return this;
  11371. }
  11372. toJSON() {
  11373. const data = super.toJSON();
  11374. data.v1 = this.v1.toArray();
  11375. data.v2 = this.v2.toArray();
  11376. return data;
  11377. }
  11378. fromJSON( json ) {
  11379. super.fromJSON( json );
  11380. this.v1.fromArray( json.v1 );
  11381. this.v2.fromArray( json.v2 );
  11382. return this;
  11383. }
  11384. }
  11385. class QuadraticBezierCurve extends Curve {
  11386. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  11387. super();
  11388. this.isQuadraticBezierCurve = true;
  11389. this.type = 'QuadraticBezierCurve';
  11390. this.v0 = v0;
  11391. this.v1 = v1;
  11392. this.v2 = v2;
  11393. }
  11394. getPoint( t, optionalTarget = new Vector2() ) {
  11395. const point = optionalTarget;
  11396. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11397. point.set(
  11398. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11399. QuadraticBezier( t, v0.y, v1.y, v2.y )
  11400. );
  11401. return point;
  11402. }
  11403. copy( source ) {
  11404. super.copy( source );
  11405. this.v0.copy( source.v0 );
  11406. this.v1.copy( source.v1 );
  11407. this.v2.copy( source.v2 );
  11408. return this;
  11409. }
  11410. toJSON() {
  11411. const data = super.toJSON();
  11412. data.v0 = this.v0.toArray();
  11413. data.v1 = this.v1.toArray();
  11414. data.v2 = this.v2.toArray();
  11415. return data;
  11416. }
  11417. fromJSON( json ) {
  11418. super.fromJSON( json );
  11419. this.v0.fromArray( json.v0 );
  11420. this.v1.fromArray( json.v1 );
  11421. this.v2.fromArray( json.v2 );
  11422. return this;
  11423. }
  11424. }
  11425. class QuadraticBezierCurve3 extends Curve {
  11426. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  11427. super();
  11428. this.isQuadraticBezierCurve3 = true;
  11429. this.type = 'QuadraticBezierCurve3';
  11430. this.v0 = v0;
  11431. this.v1 = v1;
  11432. this.v2 = v2;
  11433. }
  11434. getPoint( t, optionalTarget = new Vector3() ) {
  11435. const point = optionalTarget;
  11436. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11437. point.set(
  11438. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11439. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  11440. QuadraticBezier( t, v0.z, v1.z, v2.z )
  11441. );
  11442. return point;
  11443. }
  11444. copy( source ) {
  11445. super.copy( source );
  11446. this.v0.copy( source.v0 );
  11447. this.v1.copy( source.v1 );
  11448. this.v2.copy( source.v2 );
  11449. return this;
  11450. }
  11451. toJSON() {
  11452. const data = super.toJSON();
  11453. data.v0 = this.v0.toArray();
  11454. data.v1 = this.v1.toArray();
  11455. data.v2 = this.v2.toArray();
  11456. return data;
  11457. }
  11458. fromJSON( json ) {
  11459. super.fromJSON( json );
  11460. this.v0.fromArray( json.v0 );
  11461. this.v1.fromArray( json.v1 );
  11462. this.v2.fromArray( json.v2 );
  11463. return this;
  11464. }
  11465. }
  11466. class SplineCurve extends Curve {
  11467. constructor( points = [] ) {
  11468. super();
  11469. this.isSplineCurve = true;
  11470. this.type = 'SplineCurve';
  11471. this.points = points;
  11472. }
  11473. getPoint( t, optionalTarget = new Vector2() ) {
  11474. const point = optionalTarget;
  11475. const points = this.points;
  11476. const p = ( points.length - 1 ) * t;
  11477. const intPoint = Math.floor( p );
  11478. const weight = p - intPoint;
  11479. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  11480. const p1 = points[ intPoint ];
  11481. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  11482. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  11483. point.set(
  11484. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  11485. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  11486. );
  11487. return point;
  11488. }
  11489. copy( source ) {
  11490. super.copy( source );
  11491. this.points = [];
  11492. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  11493. const point = source.points[ i ];
  11494. this.points.push( point.clone() );
  11495. }
  11496. return this;
  11497. }
  11498. toJSON() {
  11499. const data = super.toJSON();
  11500. data.points = [];
  11501. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  11502. const point = this.points[ i ];
  11503. data.points.push( point.toArray() );
  11504. }
  11505. return data;
  11506. }
  11507. fromJSON( json ) {
  11508. super.fromJSON( json );
  11509. this.points = [];
  11510. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  11511. const point = json.points[ i ];
  11512. this.points.push( new Vector2().fromArray( point ) );
  11513. }
  11514. return this;
  11515. }
  11516. }
  11517. var Curves = /*#__PURE__*/Object.freeze({
  11518. __proto__: null,
  11519. ArcCurve: ArcCurve,
  11520. CatmullRomCurve3: CatmullRomCurve3,
  11521. CubicBezierCurve: CubicBezierCurve,
  11522. CubicBezierCurve3: CubicBezierCurve3,
  11523. EllipseCurve: EllipseCurve,
  11524. LineCurve: LineCurve,
  11525. LineCurve3: LineCurve3,
  11526. QuadraticBezierCurve: QuadraticBezierCurve,
  11527. QuadraticBezierCurve3: QuadraticBezierCurve3,
  11528. SplineCurve: SplineCurve
  11529. });
  11530. /**************************************************************
  11531. * Curved Path - a curve path is simply a array of connected
  11532. * curves, but retains the api of a curve
  11533. **************************************************************/
  11534. class CurvePath extends Curve {
  11535. constructor() {
  11536. super();
  11537. this.type = 'CurvePath';
  11538. this.curves = [];
  11539. this.autoClose = false; // Automatically closes the path
  11540. }
  11541. add( curve ) {
  11542. this.curves.push( curve );
  11543. }
  11544. closePath() {
  11545. // Add a line curve if start and end of lines are not connected
  11546. const startPoint = this.curves[ 0 ].getPoint( 0 );
  11547. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  11548. if ( ! startPoint.equals( endPoint ) ) {
  11549. const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3';
  11550. this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) );
  11551. }
  11552. return this;
  11553. }
  11554. // To get accurate point with reference to
  11555. // entire path distance at time t,
  11556. // following has to be done:
  11557. // 1. Length of each sub path have to be known
  11558. // 2. Locate and identify type of curve
  11559. // 3. Get t for the curve
  11560. // 4. Return curve.getPointAt(t')
  11561. getPoint( t, optionalTarget ) {
  11562. const d = t * this.getLength();
  11563. const curveLengths = this.getCurveLengths();
  11564. let i = 0;
  11565. // To think about boundaries points.
  11566. while ( i < curveLengths.length ) {
  11567. if ( curveLengths[ i ] >= d ) {
  11568. const diff = curveLengths[ i ] - d;
  11569. const curve = this.curves[ i ];
  11570. const segmentLength = curve.getLength();
  11571. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  11572. return curve.getPointAt( u, optionalTarget );
  11573. }
  11574. i ++;
  11575. }
  11576. return null;
  11577. // loop where sum != 0, sum > d , sum+1 <d
  11578. }
  11579. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  11580. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  11581. // getPoint() depends on getLength
  11582. getLength() {
  11583. const lens = this.getCurveLengths();
  11584. return lens[ lens.length - 1 ];
  11585. }
  11586. // cacheLengths must be recalculated.
  11587. updateArcLengths() {
  11588. this.needsUpdate = true;
  11589. this.cacheLengths = null;
  11590. this.getCurveLengths();
  11591. }
  11592. // Compute lengths and cache them
  11593. // We cannot overwrite getLengths() because UtoT mapping uses it.
  11594. getCurveLengths() {
  11595. // We use cache values if curves and cache array are same length
  11596. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  11597. return this.cacheLengths;
  11598. }
  11599. // Get length of sub-curve
  11600. // Push sums into cached array
  11601. const lengths = [];
  11602. let sums = 0;
  11603. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11604. sums += this.curves[ i ].getLength();
  11605. lengths.push( sums );
  11606. }
  11607. this.cacheLengths = lengths;
  11608. return lengths;
  11609. }
  11610. getSpacedPoints( divisions = 40 ) {
  11611. const points = [];
  11612. for ( let i = 0; i <= divisions; i ++ ) {
  11613. points.push( this.getPoint( i / divisions ) );
  11614. }
  11615. if ( this.autoClose ) {
  11616. points.push( points[ 0 ] );
  11617. }
  11618. return points;
  11619. }
  11620. getPoints( divisions = 12 ) {
  11621. const points = [];
  11622. let last;
  11623. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  11624. const curve = curves[ i ];
  11625. const resolution = curve.isEllipseCurve ? divisions * 2
  11626. : ( curve.isLineCurve || curve.isLineCurve3 ) ? 1
  11627. : curve.isSplineCurve ? divisions * curve.points.length
  11628. : divisions;
  11629. const pts = curve.getPoints( resolution );
  11630. for ( let j = 0; j < pts.length; j ++ ) {
  11631. const point = pts[ j ];
  11632. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  11633. points.push( point );
  11634. last = point;
  11635. }
  11636. }
  11637. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  11638. points.push( points[ 0 ] );
  11639. }
  11640. return points;
  11641. }
  11642. copy( source ) {
  11643. super.copy( source );
  11644. this.curves = [];
  11645. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  11646. const curve = source.curves[ i ];
  11647. this.curves.push( curve.clone() );
  11648. }
  11649. this.autoClose = source.autoClose;
  11650. return this;
  11651. }
  11652. toJSON() {
  11653. const data = super.toJSON();
  11654. data.autoClose = this.autoClose;
  11655. data.curves = [];
  11656. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11657. const curve = this.curves[ i ];
  11658. data.curves.push( curve.toJSON() );
  11659. }
  11660. return data;
  11661. }
  11662. fromJSON( json ) {
  11663. super.fromJSON( json );
  11664. this.autoClose = json.autoClose;
  11665. this.curves = [];
  11666. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  11667. const curve = json.curves[ i ];
  11668. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  11669. }
  11670. return this;
  11671. }
  11672. }
  11673. class Path extends CurvePath {
  11674. constructor( points ) {
  11675. super();
  11676. this.type = 'Path';
  11677. this.currentPoint = new Vector2();
  11678. if ( points ) {
  11679. this.setFromPoints( points );
  11680. }
  11681. }
  11682. setFromPoints( points ) {
  11683. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  11684. for ( let i = 1, l = points.length; i < l; i ++ ) {
  11685. this.lineTo( points[ i ].x, points[ i ].y );
  11686. }
  11687. return this;
  11688. }
  11689. moveTo( x, y ) {
  11690. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  11691. return this;
  11692. }
  11693. lineTo( x, y ) {
  11694. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  11695. this.curves.push( curve );
  11696. this.currentPoint.set( x, y );
  11697. return this;
  11698. }
  11699. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  11700. const curve = new QuadraticBezierCurve(
  11701. this.currentPoint.clone(),
  11702. new Vector2( aCPx, aCPy ),
  11703. new Vector2( aX, aY )
  11704. );
  11705. this.curves.push( curve );
  11706. this.currentPoint.set( aX, aY );
  11707. return this;
  11708. }
  11709. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  11710. const curve = new CubicBezierCurve(
  11711. this.currentPoint.clone(),
  11712. new Vector2( aCP1x, aCP1y ),
  11713. new Vector2( aCP2x, aCP2y ),
  11714. new Vector2( aX, aY )
  11715. );
  11716. this.curves.push( curve );
  11717. this.currentPoint.set( aX, aY );
  11718. return this;
  11719. }
  11720. splineThru( pts /*Array of Vector*/ ) {
  11721. const npts = [ this.currentPoint.clone() ].concat( pts );
  11722. const curve = new SplineCurve( npts );
  11723. this.curves.push( curve );
  11724. this.currentPoint.copy( pts[ pts.length - 1 ] );
  11725. return this;
  11726. }
  11727. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11728. const x0 = this.currentPoint.x;
  11729. const y0 = this.currentPoint.y;
  11730. this.absarc( aX + x0, aY + y0, aRadius,
  11731. aStartAngle, aEndAngle, aClockwise );
  11732. return this;
  11733. }
  11734. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11735. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  11736. return this;
  11737. }
  11738. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11739. const x0 = this.currentPoint.x;
  11740. const y0 = this.currentPoint.y;
  11741. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11742. return this;
  11743. }
  11744. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11745. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11746. if ( this.curves.length > 0 ) {
  11747. // if a previous curve is present, attempt to join
  11748. const firstPoint = curve.getPoint( 0 );
  11749. if ( ! firstPoint.equals( this.currentPoint ) ) {
  11750. this.lineTo( firstPoint.x, firstPoint.y );
  11751. }
  11752. }
  11753. this.curves.push( curve );
  11754. const lastPoint = curve.getPoint( 1 );
  11755. this.currentPoint.copy( lastPoint );
  11756. return this;
  11757. }
  11758. copy( source ) {
  11759. super.copy( source );
  11760. this.currentPoint.copy( source.currentPoint );
  11761. return this;
  11762. }
  11763. toJSON() {
  11764. const data = super.toJSON();
  11765. data.currentPoint = this.currentPoint.toArray();
  11766. return data;
  11767. }
  11768. fromJSON( json ) {
  11769. super.fromJSON( json );
  11770. this.currentPoint.fromArray( json.currentPoint );
  11771. return this;
  11772. }
  11773. }
  11774. class LatheGeometry extends BufferGeometry {
  11775. constructor( points = [ new Vector2( 0, -0.5 ), new Vector2( 0.5, 0 ), new Vector2( 0, 0.5 ) ], segments = 12, phiStart = 0, phiLength = Math.PI * 2 ) {
  11776. super();
  11777. this.type = 'LatheGeometry';
  11778. this.parameters = {
  11779. points: points,
  11780. segments: segments,
  11781. phiStart: phiStart,
  11782. phiLength: phiLength
  11783. };
  11784. segments = Math.floor( segments );
  11785. // clamp phiLength so it's in range of [ 0, 2PI ]
  11786. phiLength = clamp( phiLength, 0, Math.PI * 2 );
  11787. // buffers
  11788. const indices = [];
  11789. const vertices = [];
  11790. const uvs = [];
  11791. const initNormals = [];
  11792. const normals = [];
  11793. // helper variables
  11794. const inverseSegments = 1.0 / segments;
  11795. const vertex = new Vector3();
  11796. const uv = new Vector2();
  11797. const normal = new Vector3();
  11798. const curNormal = new Vector3();
  11799. const prevNormal = new Vector3();
  11800. let dx = 0;
  11801. let dy = 0;
  11802. // pre-compute normals for initial "meridian"
  11803. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11804. switch ( j ) {
  11805. case 0: // special handling for 1st vertex on path
  11806. dx = points[ j + 1 ].x - points[ j ].x;
  11807. dy = points[ j + 1 ].y - points[ j ].y;
  11808. normal.x = dy * 1.0;
  11809. normal.y = - dx;
  11810. normal.z = dy * 0.0;
  11811. prevNormal.copy( normal );
  11812. normal.normalize();
  11813. initNormals.push( normal.x, normal.y, normal.z );
  11814. break;
  11815. case ( points.length - 1 ): // special handling for last Vertex on path
  11816. initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z );
  11817. break;
  11818. default: // default handling for all vertices in between
  11819. dx = points[ j + 1 ].x - points[ j ].x;
  11820. dy = points[ j + 1 ].y - points[ j ].y;
  11821. normal.x = dy * 1.0;
  11822. normal.y = - dx;
  11823. normal.z = dy * 0.0;
  11824. curNormal.copy( normal );
  11825. normal.x += prevNormal.x;
  11826. normal.y += prevNormal.y;
  11827. normal.z += prevNormal.z;
  11828. normal.normalize();
  11829. initNormals.push( normal.x, normal.y, normal.z );
  11830. prevNormal.copy( curNormal );
  11831. }
  11832. }
  11833. // generate vertices, uvs and normals
  11834. for ( let i = 0; i <= segments; i ++ ) {
  11835. const phi = phiStart + i * inverseSegments * phiLength;
  11836. const sin = Math.sin( phi );
  11837. const cos = Math.cos( phi );
  11838. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11839. // vertex
  11840. vertex.x = points[ j ].x * sin;
  11841. vertex.y = points[ j ].y;
  11842. vertex.z = points[ j ].x * cos;
  11843. vertices.push( vertex.x, vertex.y, vertex.z );
  11844. // uv
  11845. uv.x = i / segments;
  11846. uv.y = j / ( points.length - 1 );
  11847. uvs.push( uv.x, uv.y );
  11848. // normal
  11849. const x = initNormals[ 3 * j + 0 ] * sin;
  11850. const y = initNormals[ 3 * j + 1 ];
  11851. const z = initNormals[ 3 * j + 0 ] * cos;
  11852. normals.push( x, y, z );
  11853. }
  11854. }
  11855. // indices
  11856. for ( let i = 0; i < segments; i ++ ) {
  11857. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  11858. const base = j + i * points.length;
  11859. const a = base;
  11860. const b = base + points.length;
  11861. const c = base + points.length + 1;
  11862. const d = base + 1;
  11863. // faces
  11864. indices.push( a, b, d );
  11865. indices.push( c, d, b );
  11866. }
  11867. }
  11868. // build geometry
  11869. this.setIndex( indices );
  11870. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11871. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11872. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11873. }
  11874. copy( source ) {
  11875. super.copy( source );
  11876. this.parameters = Object.assign( {}, source.parameters );
  11877. return this;
  11878. }
  11879. static fromJSON( data ) {
  11880. return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
  11881. }
  11882. }
  11883. class CapsuleGeometry extends LatheGeometry {
  11884. constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
  11885. const path = new Path();
  11886. path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 );
  11887. path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 );
  11888. super( path.getPoints( capSegments ), radialSegments );
  11889. this.type = 'CapsuleGeometry';
  11890. this.parameters = {
  11891. radius: radius,
  11892. length: length,
  11893. capSegments: capSegments,
  11894. radialSegments: radialSegments,
  11895. };
  11896. }
  11897. static fromJSON( data ) {
  11898. return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
  11899. }
  11900. }
  11901. class CircleGeometry extends BufferGeometry {
  11902. constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11903. super();
  11904. this.type = 'CircleGeometry';
  11905. this.parameters = {
  11906. radius: radius,
  11907. segments: segments,
  11908. thetaStart: thetaStart,
  11909. thetaLength: thetaLength
  11910. };
  11911. segments = Math.max( 3, segments );
  11912. // buffers
  11913. const indices = [];
  11914. const vertices = [];
  11915. const normals = [];
  11916. const uvs = [];
  11917. // helper variables
  11918. const vertex = new Vector3();
  11919. const uv = new Vector2();
  11920. // center point
  11921. vertices.push( 0, 0, 0 );
  11922. normals.push( 0, 0, 1 );
  11923. uvs.push( 0.5, 0.5 );
  11924. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  11925. const segment = thetaStart + s / segments * thetaLength;
  11926. // vertex
  11927. vertex.x = radius * Math.cos( segment );
  11928. vertex.y = radius * Math.sin( segment );
  11929. vertices.push( vertex.x, vertex.y, vertex.z );
  11930. // normal
  11931. normals.push( 0, 0, 1 );
  11932. // uvs
  11933. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  11934. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  11935. uvs.push( uv.x, uv.y );
  11936. }
  11937. // indices
  11938. for ( let i = 1; i <= segments; i ++ ) {
  11939. indices.push( i, i + 1, 0 );
  11940. }
  11941. // build geometry
  11942. this.setIndex( indices );
  11943. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11944. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11945. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11946. }
  11947. copy( source ) {
  11948. super.copy( source );
  11949. this.parameters = Object.assign( {}, source.parameters );
  11950. return this;
  11951. }
  11952. static fromJSON( data ) {
  11953. return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
  11954. }
  11955. }
  11956. class CylinderGeometry extends BufferGeometry {
  11957. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11958. super();
  11959. this.type = 'CylinderGeometry';
  11960. this.parameters = {
  11961. radiusTop: radiusTop,
  11962. radiusBottom: radiusBottom,
  11963. height: height,
  11964. radialSegments: radialSegments,
  11965. heightSegments: heightSegments,
  11966. openEnded: openEnded,
  11967. thetaStart: thetaStart,
  11968. thetaLength: thetaLength
  11969. };
  11970. const scope = this;
  11971. radialSegments = Math.floor( radialSegments );
  11972. heightSegments = Math.floor( heightSegments );
  11973. // buffers
  11974. const indices = [];
  11975. const vertices = [];
  11976. const normals = [];
  11977. const uvs = [];
  11978. // helper variables
  11979. let index = 0;
  11980. const indexArray = [];
  11981. const halfHeight = height / 2;
  11982. let groupStart = 0;
  11983. // generate geometry
  11984. generateTorso();
  11985. if ( openEnded === false ) {
  11986. if ( radiusTop > 0 ) generateCap( true );
  11987. if ( radiusBottom > 0 ) generateCap( false );
  11988. }
  11989. // build geometry
  11990. this.setIndex( indices );
  11991. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11992. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11993. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11994. function generateTorso() {
  11995. const normal = new Vector3();
  11996. const vertex = new Vector3();
  11997. let groupCount = 0;
  11998. // this will be used to calculate the normal
  11999. const slope = ( radiusBottom - radiusTop ) / height;
  12000. // generate vertices, normals and uvs
  12001. for ( let y = 0; y <= heightSegments; y ++ ) {
  12002. const indexRow = [];
  12003. const v = y / heightSegments;
  12004. // calculate the radius of the current row
  12005. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  12006. for ( let x = 0; x <= radialSegments; x ++ ) {
  12007. const u = x / radialSegments;
  12008. const theta = u * thetaLength + thetaStart;
  12009. const sinTheta = Math.sin( theta );
  12010. const cosTheta = Math.cos( theta );
  12011. // vertex
  12012. vertex.x = radius * sinTheta;
  12013. vertex.y = - v * height + halfHeight;
  12014. vertex.z = radius * cosTheta;
  12015. vertices.push( vertex.x, vertex.y, vertex.z );
  12016. // normal
  12017. normal.set( sinTheta, slope, cosTheta ).normalize();
  12018. normals.push( normal.x, normal.y, normal.z );
  12019. // uv
  12020. uvs.push( u, 1 - v );
  12021. // save index of vertex in respective row
  12022. indexRow.push( index ++ );
  12023. }
  12024. // now save vertices of the row in our index array
  12025. indexArray.push( indexRow );
  12026. }
  12027. // generate indices
  12028. for ( let x = 0; x < radialSegments; x ++ ) {
  12029. for ( let y = 0; y < heightSegments; y ++ ) {
  12030. // we use the index array to access the correct indices
  12031. const a = indexArray[ y ][ x ];
  12032. const b = indexArray[ y + 1 ][ x ];
  12033. const c = indexArray[ y + 1 ][ x + 1 ];
  12034. const d = indexArray[ y ][ x + 1 ];
  12035. // faces
  12036. if ( radiusTop > 0 || y !== 0 ) {
  12037. indices.push( a, b, d );
  12038. groupCount += 3;
  12039. }
  12040. if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
  12041. indices.push( b, c, d );
  12042. groupCount += 3;
  12043. }
  12044. }
  12045. }
  12046. // add a group to the geometry. this will ensure multi material support
  12047. scope.addGroup( groupStart, groupCount, 0 );
  12048. // calculate new start value for groups
  12049. groupStart += groupCount;
  12050. }
  12051. function generateCap( top ) {
  12052. // save the index of the first center vertex
  12053. const centerIndexStart = index;
  12054. const uv = new Vector2();
  12055. const vertex = new Vector3();
  12056. let groupCount = 0;
  12057. const radius = ( top === true ) ? radiusTop : radiusBottom;
  12058. const sign = ( top === true ) ? 1 : -1;
  12059. // first we generate the center vertex data of the cap.
  12060. // because the geometry needs one set of uvs per face,
  12061. // we must generate a center vertex per face/segment
  12062. for ( let x = 1; x <= radialSegments; x ++ ) {
  12063. // vertex
  12064. vertices.push( 0, halfHeight * sign, 0 );
  12065. // normal
  12066. normals.push( 0, sign, 0 );
  12067. // uv
  12068. uvs.push( 0.5, 0.5 );
  12069. // increase index
  12070. index ++;
  12071. }
  12072. // save the index of the last center vertex
  12073. const centerIndexEnd = index;
  12074. // now we generate the surrounding vertices, normals and uvs
  12075. for ( let x = 0; x <= radialSegments; x ++ ) {
  12076. const u = x / radialSegments;
  12077. const theta = u * thetaLength + thetaStart;
  12078. const cosTheta = Math.cos( theta );
  12079. const sinTheta = Math.sin( theta );
  12080. // vertex
  12081. vertex.x = radius * sinTheta;
  12082. vertex.y = halfHeight * sign;
  12083. vertex.z = radius * cosTheta;
  12084. vertices.push( vertex.x, vertex.y, vertex.z );
  12085. // normal
  12086. normals.push( 0, sign, 0 );
  12087. // uv
  12088. uv.x = ( cosTheta * 0.5 ) + 0.5;
  12089. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  12090. uvs.push( uv.x, uv.y );
  12091. // increase index
  12092. index ++;
  12093. }
  12094. // generate indices
  12095. for ( let x = 0; x < radialSegments; x ++ ) {
  12096. const c = centerIndexStart + x;
  12097. const i = centerIndexEnd + x;
  12098. if ( top === true ) {
  12099. // face top
  12100. indices.push( i, i + 1, c );
  12101. } else {
  12102. // face bottom
  12103. indices.push( i + 1, i, c );
  12104. }
  12105. groupCount += 3;
  12106. }
  12107. // add a group to the geometry. this will ensure multi material support
  12108. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  12109. // calculate new start value for groups
  12110. groupStart += groupCount;
  12111. }
  12112. }
  12113. copy( source ) {
  12114. super.copy( source );
  12115. this.parameters = Object.assign( {}, source.parameters );
  12116. return this;
  12117. }
  12118. static fromJSON( data ) {
  12119. return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  12120. }
  12121. }
  12122. class ConeGeometry extends CylinderGeometry {
  12123. constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  12124. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  12125. this.type = 'ConeGeometry';
  12126. this.parameters = {
  12127. radius: radius,
  12128. height: height,
  12129. radialSegments: radialSegments,
  12130. heightSegments: heightSegments,
  12131. openEnded: openEnded,
  12132. thetaStart: thetaStart,
  12133. thetaLength: thetaLength
  12134. };
  12135. }
  12136. static fromJSON( data ) {
  12137. return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  12138. }
  12139. }
  12140. class PolyhedronGeometry extends BufferGeometry {
  12141. constructor( vertices = [], indices = [], radius = 1, detail = 0 ) {
  12142. super();
  12143. this.type = 'PolyhedronGeometry';
  12144. this.parameters = {
  12145. vertices: vertices,
  12146. indices: indices,
  12147. radius: radius,
  12148. detail: detail
  12149. };
  12150. // default buffer data
  12151. const vertexBuffer = [];
  12152. const uvBuffer = [];
  12153. // the subdivision creates the vertex buffer data
  12154. subdivide( detail );
  12155. // all vertices should lie on a conceptual sphere with a given radius
  12156. applyRadius( radius );
  12157. // finally, create the uv data
  12158. generateUVs();
  12159. // build non-indexed geometry
  12160. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  12161. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  12162. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  12163. if ( detail === 0 ) {
  12164. this.computeVertexNormals(); // flat normals
  12165. } else {
  12166. this.normalizeNormals(); // smooth normals
  12167. }
  12168. // helper functions
  12169. function subdivide( detail ) {
  12170. const a = new Vector3();
  12171. const b = new Vector3();
  12172. const c = new Vector3();
  12173. // iterate over all faces and apply a subdivision with the given detail value
  12174. for ( let i = 0; i < indices.length; i += 3 ) {
  12175. // get the vertices of the face
  12176. getVertexByIndex( indices[ i + 0 ], a );
  12177. getVertexByIndex( indices[ i + 1 ], b );
  12178. getVertexByIndex( indices[ i + 2 ], c );
  12179. // perform subdivision
  12180. subdivideFace( a, b, c, detail );
  12181. }
  12182. }
  12183. function subdivideFace( a, b, c, detail ) {
  12184. const cols = detail + 1;
  12185. // we use this multidimensional array as a data structure for creating the subdivision
  12186. const v = [];
  12187. // construct all of the vertices for this subdivision
  12188. for ( let i = 0; i <= cols; i ++ ) {
  12189. v[ i ] = [];
  12190. const aj = a.clone().lerp( c, i / cols );
  12191. const bj = b.clone().lerp( c, i / cols );
  12192. const rows = cols - i;
  12193. for ( let j = 0; j <= rows; j ++ ) {
  12194. if ( j === 0 && i === cols ) {
  12195. v[ i ][ j ] = aj;
  12196. } else {
  12197. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  12198. }
  12199. }
  12200. }
  12201. // construct all of the faces
  12202. for ( let i = 0; i < cols; i ++ ) {
  12203. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  12204. const k = Math.floor( j / 2 );
  12205. if ( j % 2 === 0 ) {
  12206. pushVertex( v[ i ][ k + 1 ] );
  12207. pushVertex( v[ i + 1 ][ k ] );
  12208. pushVertex( v[ i ][ k ] );
  12209. } else {
  12210. pushVertex( v[ i ][ k + 1 ] );
  12211. pushVertex( v[ i + 1 ][ k + 1 ] );
  12212. pushVertex( v[ i + 1 ][ k ] );
  12213. }
  12214. }
  12215. }
  12216. }
  12217. function applyRadius( radius ) {
  12218. const vertex = new Vector3();
  12219. // iterate over the entire buffer and apply the radius to each vertex
  12220. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  12221. vertex.x = vertexBuffer[ i + 0 ];
  12222. vertex.y = vertexBuffer[ i + 1 ];
  12223. vertex.z = vertexBuffer[ i + 2 ];
  12224. vertex.normalize().multiplyScalar( radius );
  12225. vertexBuffer[ i + 0 ] = vertex.x;
  12226. vertexBuffer[ i + 1 ] = vertex.y;
  12227. vertexBuffer[ i + 2 ] = vertex.z;
  12228. }
  12229. }
  12230. function generateUVs() {
  12231. const vertex = new Vector3();
  12232. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  12233. vertex.x = vertexBuffer[ i + 0 ];
  12234. vertex.y = vertexBuffer[ i + 1 ];
  12235. vertex.z = vertexBuffer[ i + 2 ];
  12236. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  12237. const v = inclination( vertex ) / Math.PI + 0.5;
  12238. uvBuffer.push( u, 1 - v );
  12239. }
  12240. correctUVs();
  12241. correctSeam();
  12242. }
  12243. function correctSeam() {
  12244. // handle case when face straddles the seam, see #3269
  12245. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  12246. // uv data of a single face
  12247. const x0 = uvBuffer[ i + 0 ];
  12248. const x1 = uvBuffer[ i + 2 ];
  12249. const x2 = uvBuffer[ i + 4 ];
  12250. const max = Math.max( x0, x1, x2 );
  12251. const min = Math.min( x0, x1, x2 );
  12252. // 0.9 is somewhat arbitrary
  12253. if ( max > 0.9 && min < 0.1 ) {
  12254. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  12255. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  12256. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  12257. }
  12258. }
  12259. }
  12260. function pushVertex( vertex ) {
  12261. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  12262. }
  12263. function getVertexByIndex( index, vertex ) {
  12264. const stride = index * 3;
  12265. vertex.x = vertices[ stride + 0 ];
  12266. vertex.y = vertices[ stride + 1 ];
  12267. vertex.z = vertices[ stride + 2 ];
  12268. }
  12269. function correctUVs() {
  12270. const a = new Vector3();
  12271. const b = new Vector3();
  12272. const c = new Vector3();
  12273. const centroid = new Vector3();
  12274. const uvA = new Vector2();
  12275. const uvB = new Vector2();
  12276. const uvC = new Vector2();
  12277. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  12278. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  12279. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  12280. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  12281. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  12282. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  12283. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  12284. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  12285. const azi = azimuth( centroid );
  12286. correctUV( uvA, j + 0, a, azi );
  12287. correctUV( uvB, j + 2, b, azi );
  12288. correctUV( uvC, j + 4, c, azi );
  12289. }
  12290. }
  12291. function correctUV( uv, stride, vector, azimuth ) {
  12292. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  12293. uvBuffer[ stride ] = uv.x - 1;
  12294. }
  12295. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  12296. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  12297. }
  12298. }
  12299. // Angle around the Y axis, counter-clockwise when looking from above.
  12300. function azimuth( vector ) {
  12301. return Math.atan2( vector.z, - vector.x );
  12302. }
  12303. // Angle above the XZ plane.
  12304. function inclination( vector ) {
  12305. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  12306. }
  12307. }
  12308. copy( source ) {
  12309. super.copy( source );
  12310. this.parameters = Object.assign( {}, source.parameters );
  12311. return this;
  12312. }
  12313. static fromJSON( data ) {
  12314. return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
  12315. }
  12316. }
  12317. class DodecahedronGeometry extends PolyhedronGeometry {
  12318. constructor( radius = 1, detail = 0 ) {
  12319. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  12320. const r = 1 / t;
  12321. const vertices = [
  12322. // (±1, ±1, ±1)
  12323. -1, -1, -1, -1, -1, 1,
  12324. -1, 1, -1, -1, 1, 1,
  12325. 1, -1, -1, 1, -1, 1,
  12326. 1, 1, -1, 1, 1, 1,
  12327. // (0, ±1/φ, ±φ)
  12328. 0, - r, - t, 0, - r, t,
  12329. 0, r, - t, 0, r, t,
  12330. // (±1/φ, ±φ, 0)
  12331. - r, - t, 0, - r, t, 0,
  12332. r, - t, 0, r, t, 0,
  12333. // (±φ, 0, ±1/φ)
  12334. - t, 0, - r, t, 0, - r,
  12335. - t, 0, r, t, 0, r
  12336. ];
  12337. const indices = [
  12338. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  12339. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  12340. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  12341. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  12342. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  12343. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  12344. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  12345. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  12346. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  12347. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  12348. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  12349. 1, 12, 14, 1, 14, 5, 1, 5, 9
  12350. ];
  12351. super( vertices, indices, radius, detail );
  12352. this.type = 'DodecahedronGeometry';
  12353. this.parameters = {
  12354. radius: radius,
  12355. detail: detail
  12356. };
  12357. }
  12358. static fromJSON( data ) {
  12359. return new DodecahedronGeometry( data.radius, data.detail );
  12360. }
  12361. }
  12362. const _v0 = /*@__PURE__*/ new Vector3();
  12363. const _v1$1 = /*@__PURE__*/ new Vector3();
  12364. const _normal = /*@__PURE__*/ new Vector3();
  12365. const _triangle = /*@__PURE__*/ new Triangle();
  12366. class EdgesGeometry extends BufferGeometry {
  12367. constructor( geometry = null, thresholdAngle = 1 ) {
  12368. super();
  12369. this.type = 'EdgesGeometry';
  12370. this.parameters = {
  12371. geometry: geometry,
  12372. thresholdAngle: thresholdAngle
  12373. };
  12374. if ( geometry !== null ) {
  12375. const precisionPoints = 4;
  12376. const precision = Math.pow( 10, precisionPoints );
  12377. const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
  12378. const indexAttr = geometry.getIndex();
  12379. const positionAttr = geometry.getAttribute( 'position' );
  12380. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  12381. const indexArr = [ 0, 0, 0 ];
  12382. const vertKeys = [ 'a', 'b', 'c' ];
  12383. const hashes = new Array( 3 );
  12384. const edgeData = {};
  12385. const vertices = [];
  12386. for ( let i = 0; i < indexCount; i += 3 ) {
  12387. if ( indexAttr ) {
  12388. indexArr[ 0 ] = indexAttr.getX( i );
  12389. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  12390. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  12391. } else {
  12392. indexArr[ 0 ] = i;
  12393. indexArr[ 1 ] = i + 1;
  12394. indexArr[ 2 ] = i + 2;
  12395. }
  12396. const { a, b, c } = _triangle;
  12397. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  12398. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  12399. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  12400. _triangle.getNormal( _normal );
  12401. // create hashes for the edge from the vertices
  12402. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  12403. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  12404. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  12405. // skip degenerate triangles
  12406. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  12407. continue;
  12408. }
  12409. // iterate over every edge
  12410. for ( let j = 0; j < 3; j ++ ) {
  12411. // get the first and next vertex making up the edge
  12412. const jNext = ( j + 1 ) % 3;
  12413. const vecHash0 = hashes[ j ];
  12414. const vecHash1 = hashes[ jNext ];
  12415. const v0 = _triangle[ vertKeys[ j ] ];
  12416. const v1 = _triangle[ vertKeys[ jNext ] ];
  12417. const hash = `${ vecHash0 }_${ vecHash1 }`;
  12418. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  12419. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  12420. // if we found a sibling edge add it into the vertex array if
  12421. // it meets the angle threshold and delete the edge from the map.
  12422. if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  12423. vertices.push( v0.x, v0.y, v0.z );
  12424. vertices.push( v1.x, v1.y, v1.z );
  12425. }
  12426. edgeData[ reverseHash ] = null;
  12427. } else if ( ! ( hash in edgeData ) ) {
  12428. // if we've already got an edge here then skip adding a new one
  12429. edgeData[ hash ] = {
  12430. index0: indexArr[ j ],
  12431. index1: indexArr[ jNext ],
  12432. normal: _normal.clone(),
  12433. };
  12434. }
  12435. }
  12436. }
  12437. // iterate over all remaining, unmatched edges and add them to the vertex array
  12438. for ( const key in edgeData ) {
  12439. if ( edgeData[ key ] ) {
  12440. const { index0, index1 } = edgeData[ key ];
  12441. _v0.fromBufferAttribute( positionAttr, index0 );
  12442. _v1$1.fromBufferAttribute( positionAttr, index1 );
  12443. vertices.push( _v0.x, _v0.y, _v0.z );
  12444. vertices.push( _v1$1.x, _v1$1.y, _v1$1.z );
  12445. }
  12446. }
  12447. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  12448. }
  12449. }
  12450. copy( source ) {
  12451. super.copy( source );
  12452. this.parameters = Object.assign( {}, source.parameters );
  12453. return this;
  12454. }
  12455. }
  12456. class Shape extends Path {
  12457. constructor( points ) {
  12458. super( points );
  12459. this.uuid = generateUUID();
  12460. this.type = 'Shape';
  12461. this.holes = [];
  12462. }
  12463. getPointsHoles( divisions ) {
  12464. const holesPts = [];
  12465. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12466. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  12467. }
  12468. return holesPts;
  12469. }
  12470. // get points of shape and holes (keypoints based on segments parameter)
  12471. extractPoints( divisions ) {
  12472. return {
  12473. shape: this.getPoints( divisions ),
  12474. holes: this.getPointsHoles( divisions )
  12475. };
  12476. }
  12477. copy( source ) {
  12478. super.copy( source );
  12479. this.holes = [];
  12480. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  12481. const hole = source.holes[ i ];
  12482. this.holes.push( hole.clone() );
  12483. }
  12484. return this;
  12485. }
  12486. toJSON() {
  12487. const data = super.toJSON();
  12488. data.uuid = this.uuid;
  12489. data.holes = [];
  12490. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12491. const hole = this.holes[ i ];
  12492. data.holes.push( hole.toJSON() );
  12493. }
  12494. return data;
  12495. }
  12496. fromJSON( json ) {
  12497. super.fromJSON( json );
  12498. this.uuid = json.uuid;
  12499. this.holes = [];
  12500. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  12501. const hole = json.holes[ i ];
  12502. this.holes.push( new Path().fromJSON( hole ) );
  12503. }
  12504. return this;
  12505. }
  12506. }
  12507. /**
  12508. * Port from https://github.com/mapbox/earcut (v2.2.4)
  12509. */
  12510. const Earcut = {
  12511. triangulate: function ( data, holeIndices, dim = 2 ) {
  12512. const hasHoles = holeIndices && holeIndices.length;
  12513. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  12514. let outerNode = linkedList( data, 0, outerLen, dim, true );
  12515. const triangles = [];
  12516. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  12517. let minX, minY, maxX, maxY, x, y, invSize;
  12518. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  12519. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  12520. if ( data.length > 80 * dim ) {
  12521. minX = maxX = data[ 0 ];
  12522. minY = maxY = data[ 1 ];
  12523. for ( let i = dim; i < outerLen; i += dim ) {
  12524. x = data[ i ];
  12525. y = data[ i + 1 ];
  12526. if ( x < minX ) minX = x;
  12527. if ( y < minY ) minY = y;
  12528. if ( x > maxX ) maxX = x;
  12529. if ( y > maxY ) maxY = y;
  12530. }
  12531. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  12532. invSize = Math.max( maxX - minX, maxY - minY );
  12533. invSize = invSize !== 0 ? 32767 / invSize : 0;
  12534. }
  12535. earcutLinked( outerNode, triangles, dim, minX, minY, invSize, 0 );
  12536. return triangles;
  12537. }
  12538. };
  12539. // create a circular doubly linked list from polygon points in the specified winding order
  12540. function linkedList( data, start, end, dim, clockwise ) {
  12541. let i, last;
  12542. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  12543. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12544. } else {
  12545. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12546. }
  12547. if ( last && equals( last, last.next ) ) {
  12548. removeNode( last );
  12549. last = last.next;
  12550. }
  12551. return last;
  12552. }
  12553. // eliminate colinear or duplicate points
  12554. function filterPoints( start, end ) {
  12555. if ( ! start ) return start;
  12556. if ( ! end ) end = start;
  12557. let p = start,
  12558. again;
  12559. do {
  12560. again = false;
  12561. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  12562. removeNode( p );
  12563. p = end = p.prev;
  12564. if ( p === p.next ) break;
  12565. again = true;
  12566. } else {
  12567. p = p.next;
  12568. }
  12569. } while ( again || p !== end );
  12570. return end;
  12571. }
  12572. // main ear slicing loop which triangulates a polygon (given as a linked list)
  12573. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  12574. if ( ! ear ) return;
  12575. // interlink polygon nodes in z-order
  12576. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  12577. let stop = ear,
  12578. prev, next;
  12579. // iterate through ears, slicing them one by one
  12580. while ( ear.prev !== ear.next ) {
  12581. prev = ear.prev;
  12582. next = ear.next;
  12583. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  12584. // cut off the triangle
  12585. triangles.push( prev.i / dim | 0 );
  12586. triangles.push( ear.i / dim | 0 );
  12587. triangles.push( next.i / dim | 0 );
  12588. removeNode( ear );
  12589. // skipping the next vertex leads to less sliver triangles
  12590. ear = next.next;
  12591. stop = next.next;
  12592. continue;
  12593. }
  12594. ear = next;
  12595. // if we looped through the whole remaining polygon and can't find any more ears
  12596. if ( ear === stop ) {
  12597. // try filtering points and slicing again
  12598. if ( ! pass ) {
  12599. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  12600. // if this didn't work, try curing all small self-intersections locally
  12601. } else if ( pass === 1 ) {
  12602. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  12603. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  12604. // as a last resort, try splitting the remaining polygon into two
  12605. } else if ( pass === 2 ) {
  12606. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  12607. }
  12608. break;
  12609. }
  12610. }
  12611. }
  12612. // check whether a polygon node forms a valid ear with adjacent nodes
  12613. function isEar( ear ) {
  12614. const a = ear.prev,
  12615. b = ear,
  12616. c = ear.next;
  12617. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12618. // now make sure we don't have other points inside the potential ear
  12619. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12620. // triangle bbox; min & max are calculated like this for speed
  12621. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12622. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12623. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12624. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12625. let p = c.next;
  12626. while ( p !== a ) {
  12627. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
  12628. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) &&
  12629. area( p.prev, p, p.next ) >= 0 ) return false;
  12630. p = p.next;
  12631. }
  12632. return true;
  12633. }
  12634. function isEarHashed( ear, minX, minY, invSize ) {
  12635. const a = ear.prev,
  12636. b = ear,
  12637. c = ear.next;
  12638. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12639. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12640. // triangle bbox; min & max are calculated like this for speed
  12641. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12642. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12643. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12644. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12645. // z-order range for the current triangle bbox;
  12646. const minZ = zOrder( x0, y0, minX, minY, invSize ),
  12647. maxZ = zOrder( x1, y1, minX, minY, invSize );
  12648. let p = ear.prevZ,
  12649. n = ear.nextZ;
  12650. // look for points inside the triangle in both directions
  12651. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  12652. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12653. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12654. p = p.prevZ;
  12655. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12656. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12657. n = n.nextZ;
  12658. }
  12659. // look for remaining points in decreasing z-order
  12660. while ( p && p.z >= minZ ) {
  12661. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12662. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12663. p = p.prevZ;
  12664. }
  12665. // look for remaining points in increasing z-order
  12666. while ( n && n.z <= maxZ ) {
  12667. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12668. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12669. n = n.nextZ;
  12670. }
  12671. return true;
  12672. }
  12673. // go through all polygon nodes and cure small local self-intersections
  12674. function cureLocalIntersections( start, triangles, dim ) {
  12675. let p = start;
  12676. do {
  12677. const a = p.prev,
  12678. b = p.next.next;
  12679. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  12680. triangles.push( a.i / dim | 0 );
  12681. triangles.push( p.i / dim | 0 );
  12682. triangles.push( b.i / dim | 0 );
  12683. // remove two nodes involved
  12684. removeNode( p );
  12685. removeNode( p.next );
  12686. p = start = b;
  12687. }
  12688. p = p.next;
  12689. } while ( p !== start );
  12690. return filterPoints( p );
  12691. }
  12692. // try splitting polygon into two and triangulate them independently
  12693. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  12694. // look for a valid diagonal that divides the polygon into two
  12695. let a = start;
  12696. do {
  12697. let b = a.next.next;
  12698. while ( b !== a.prev ) {
  12699. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  12700. // split the polygon in two by the diagonal
  12701. let c = splitPolygon( a, b );
  12702. // filter colinear points around the cuts
  12703. a = filterPoints( a, a.next );
  12704. c = filterPoints( c, c.next );
  12705. // run earcut on each half
  12706. earcutLinked( a, triangles, dim, minX, minY, invSize, 0 );
  12707. earcutLinked( c, triangles, dim, minX, minY, invSize, 0 );
  12708. return;
  12709. }
  12710. b = b.next;
  12711. }
  12712. a = a.next;
  12713. } while ( a !== start );
  12714. }
  12715. // link every hole into the outer loop, producing a single-ring polygon without holes
  12716. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  12717. const queue = [];
  12718. let i, len, start, end, list;
  12719. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  12720. start = holeIndices[ i ] * dim;
  12721. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  12722. list = linkedList( data, start, end, dim, false );
  12723. if ( list === list.next ) list.steiner = true;
  12724. queue.push( getLeftmost( list ) );
  12725. }
  12726. queue.sort( compareX );
  12727. // process holes from left to right
  12728. for ( i = 0; i < queue.length; i ++ ) {
  12729. outerNode = eliminateHole( queue[ i ], outerNode );
  12730. }
  12731. return outerNode;
  12732. }
  12733. function compareX( a, b ) {
  12734. return a.x - b.x;
  12735. }
  12736. // find a bridge between vertices that connects hole with an outer ring and link it
  12737. function eliminateHole( hole, outerNode ) {
  12738. const bridge = findHoleBridge( hole, outerNode );
  12739. if ( ! bridge ) {
  12740. return outerNode;
  12741. }
  12742. const bridgeReverse = splitPolygon( bridge, hole );
  12743. // filter collinear points around the cuts
  12744. filterPoints( bridgeReverse, bridgeReverse.next );
  12745. return filterPoints( bridge, bridge.next );
  12746. }
  12747. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  12748. function findHoleBridge( hole, outerNode ) {
  12749. let p = outerNode,
  12750. qx = - Infinity,
  12751. m;
  12752. const hx = hole.x, hy = hole.y;
  12753. // find a segment intersected by a ray from the hole's leftmost point to the left;
  12754. // segment's endpoint with lesser x will be potential connection point
  12755. do {
  12756. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  12757. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  12758. if ( x <= hx && x > qx ) {
  12759. qx = x;
  12760. m = p.x < p.next.x ? p : p.next;
  12761. if ( x === hx ) return m; // hole touches outer segment; pick leftmost endpoint
  12762. }
  12763. }
  12764. p = p.next;
  12765. } while ( p !== outerNode );
  12766. if ( ! m ) return null;
  12767. // look for points inside the triangle of hole point, segment intersection and endpoint;
  12768. // if there are no points found, we have a valid connection;
  12769. // otherwise choose the point of the minimum angle with the ray as connection point
  12770. const stop = m,
  12771. mx = m.x,
  12772. my = m.y;
  12773. let tanMin = Infinity, tan;
  12774. p = m;
  12775. do {
  12776. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  12777. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  12778. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  12779. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  12780. m = p;
  12781. tanMin = tan;
  12782. }
  12783. }
  12784. p = p.next;
  12785. } while ( p !== stop );
  12786. return m;
  12787. }
  12788. // whether sector in vertex m contains sector in vertex p in the same coordinates
  12789. function sectorContainsSector( m, p ) {
  12790. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  12791. }
  12792. // interlink polygon nodes in z-order
  12793. function indexCurve( start, minX, minY, invSize ) {
  12794. let p = start;
  12795. do {
  12796. if ( p.z === 0 ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  12797. p.prevZ = p.prev;
  12798. p.nextZ = p.next;
  12799. p = p.next;
  12800. } while ( p !== start );
  12801. p.prevZ.nextZ = null;
  12802. p.prevZ = null;
  12803. sortLinked( p );
  12804. }
  12805. // Simon Tatham's linked list merge sort algorithm
  12806. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  12807. function sortLinked( list ) {
  12808. let i, p, q, e, tail, numMerges, pSize, qSize,
  12809. inSize = 1;
  12810. do {
  12811. p = list;
  12812. list = null;
  12813. tail = null;
  12814. numMerges = 0;
  12815. while ( p ) {
  12816. numMerges ++;
  12817. q = p;
  12818. pSize = 0;
  12819. for ( i = 0; i < inSize; i ++ ) {
  12820. pSize ++;
  12821. q = q.nextZ;
  12822. if ( ! q ) break;
  12823. }
  12824. qSize = inSize;
  12825. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  12826. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  12827. e = p;
  12828. p = p.nextZ;
  12829. pSize --;
  12830. } else {
  12831. e = q;
  12832. q = q.nextZ;
  12833. qSize --;
  12834. }
  12835. if ( tail ) tail.nextZ = e;
  12836. else list = e;
  12837. e.prevZ = tail;
  12838. tail = e;
  12839. }
  12840. p = q;
  12841. }
  12842. tail.nextZ = null;
  12843. inSize *= 2;
  12844. } while ( numMerges > 1 );
  12845. return list;
  12846. }
  12847. // z-order of a point given coords and inverse of the longer side of data bbox
  12848. function zOrder( x, y, minX, minY, invSize ) {
  12849. // coords are transformed into non-negative 15-bit integer range
  12850. x = ( x - minX ) * invSize | 0;
  12851. y = ( y - minY ) * invSize | 0;
  12852. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  12853. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  12854. x = ( x | ( x << 2 ) ) & 0x33333333;
  12855. x = ( x | ( x << 1 ) ) & 0x55555555;
  12856. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  12857. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  12858. y = ( y | ( y << 2 ) ) & 0x33333333;
  12859. y = ( y | ( y << 1 ) ) & 0x55555555;
  12860. return x | ( y << 1 );
  12861. }
  12862. // find the leftmost node of a polygon ring
  12863. function getLeftmost( start ) {
  12864. let p = start,
  12865. leftmost = start;
  12866. do {
  12867. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  12868. p = p.next;
  12869. } while ( p !== start );
  12870. return leftmost;
  12871. }
  12872. // check if a point lies within a convex triangle
  12873. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  12874. return ( cx - px ) * ( ay - py ) >= ( ax - px ) * ( cy - py ) &&
  12875. ( ax - px ) * ( by - py ) >= ( bx - px ) * ( ay - py ) &&
  12876. ( bx - px ) * ( cy - py ) >= ( cx - px ) * ( by - py );
  12877. }
  12878. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  12879. function isValidDiagonal( a, b ) {
  12880. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // doesn't intersect other edges
  12881. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  12882. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  12883. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  12884. }
  12885. // signed area of a triangle
  12886. function area( p, q, r ) {
  12887. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  12888. }
  12889. // check if two points are equal
  12890. function equals( p1, p2 ) {
  12891. return p1.x === p2.x && p1.y === p2.y;
  12892. }
  12893. // check if two segments intersect
  12894. function intersects( p1, q1, p2, q2 ) {
  12895. const o1 = sign( area( p1, q1, p2 ) );
  12896. const o2 = sign( area( p1, q1, q2 ) );
  12897. const o3 = sign( area( p2, q2, p1 ) );
  12898. const o4 = sign( area( p2, q2, q1 ) );
  12899. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  12900. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  12901. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  12902. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  12903. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  12904. return false;
  12905. }
  12906. // for collinear points p, q, r, check if point q lies on segment pr
  12907. function onSegment( p, q, r ) {
  12908. 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 );
  12909. }
  12910. function sign( num ) {
  12911. return num > 0 ? 1 : num < 0 ? -1 : 0;
  12912. }
  12913. // check if a polygon diagonal intersects any polygon segments
  12914. function intersectsPolygon( a, b ) {
  12915. let p = a;
  12916. do {
  12917. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  12918. intersects( p, p.next, a, b ) ) return true;
  12919. p = p.next;
  12920. } while ( p !== a );
  12921. return false;
  12922. }
  12923. // check if a polygon diagonal is locally inside the polygon
  12924. function locallyInside( a, b ) {
  12925. return area( a.prev, a, a.next ) < 0 ?
  12926. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  12927. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  12928. }
  12929. // check if the middle point of a polygon diagonal is inside the polygon
  12930. function middleInside( a, b ) {
  12931. let p = a,
  12932. inside = false;
  12933. const px = ( a.x + b.x ) / 2,
  12934. py = ( a.y + b.y ) / 2;
  12935. do {
  12936. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  12937. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  12938. inside = ! inside;
  12939. p = p.next;
  12940. } while ( p !== a );
  12941. return inside;
  12942. }
  12943. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  12944. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  12945. function splitPolygon( a, b ) {
  12946. const a2 = new Node( a.i, a.x, a.y ),
  12947. b2 = new Node( b.i, b.x, b.y ),
  12948. an = a.next,
  12949. bp = b.prev;
  12950. a.next = b;
  12951. b.prev = a;
  12952. a2.next = an;
  12953. an.prev = a2;
  12954. b2.next = a2;
  12955. a2.prev = b2;
  12956. bp.next = b2;
  12957. b2.prev = bp;
  12958. return b2;
  12959. }
  12960. // create a node and optionally link it with previous one (in a circular doubly linked list)
  12961. function insertNode( i, x, y, last ) {
  12962. const p = new Node( i, x, y );
  12963. if ( ! last ) {
  12964. p.prev = p;
  12965. p.next = p;
  12966. } else {
  12967. p.next = last.next;
  12968. p.prev = last;
  12969. last.next.prev = p;
  12970. last.next = p;
  12971. }
  12972. return p;
  12973. }
  12974. function removeNode( p ) {
  12975. p.next.prev = p.prev;
  12976. p.prev.next = p.next;
  12977. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  12978. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  12979. }
  12980. function Node( i, x, y ) {
  12981. // vertex index in coordinates array
  12982. this.i = i;
  12983. // vertex coordinates
  12984. this.x = x;
  12985. this.y = y;
  12986. // previous and next vertex nodes in a polygon ring
  12987. this.prev = null;
  12988. this.next = null;
  12989. // z-order curve value
  12990. this.z = 0;
  12991. // previous and next nodes in z-order
  12992. this.prevZ = null;
  12993. this.nextZ = null;
  12994. // indicates whether this is a steiner point
  12995. this.steiner = false;
  12996. }
  12997. function signedArea( data, start, end, dim ) {
  12998. let sum = 0;
  12999. for ( let i = start, j = end - dim; i < end; i += dim ) {
  13000. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  13001. j = i;
  13002. }
  13003. return sum;
  13004. }
  13005. class ShapeUtils {
  13006. // calculate area of the contour polygon
  13007. static area( contour ) {
  13008. const n = contour.length;
  13009. let a = 0.0;
  13010. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  13011. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  13012. }
  13013. return a * 0.5;
  13014. }
  13015. static isClockWise( pts ) {
  13016. return ShapeUtils.area( pts ) < 0;
  13017. }
  13018. static triangulateShape( contour, holes ) {
  13019. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  13020. const holeIndices = []; // array of hole indices
  13021. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  13022. removeDupEndPts( contour );
  13023. addContour( vertices, contour );
  13024. //
  13025. let holeIndex = contour.length;
  13026. holes.forEach( removeDupEndPts );
  13027. for ( let i = 0; i < holes.length; i ++ ) {
  13028. holeIndices.push( holeIndex );
  13029. holeIndex += holes[ i ].length;
  13030. addContour( vertices, holes[ i ] );
  13031. }
  13032. //
  13033. const triangles = Earcut.triangulate( vertices, holeIndices );
  13034. //
  13035. for ( let i = 0; i < triangles.length; i += 3 ) {
  13036. faces.push( triangles.slice( i, i + 3 ) );
  13037. }
  13038. return faces;
  13039. }
  13040. }
  13041. function removeDupEndPts( points ) {
  13042. const l = points.length;
  13043. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  13044. points.pop();
  13045. }
  13046. }
  13047. function addContour( vertices, contour ) {
  13048. for ( let i = 0; i < contour.length; i ++ ) {
  13049. vertices.push( contour[ i ].x );
  13050. vertices.push( contour[ i ].y );
  13051. }
  13052. }
  13053. /**
  13054. * Creates extruded geometry from a path shape.
  13055. *
  13056. * parameters = {
  13057. *
  13058. * curveSegments: <int>, // number of points on the curves
  13059. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  13060. * depth: <float>, // Depth to extrude the shape
  13061. *
  13062. * bevelEnabled: <bool>, // turn on bevel
  13063. * bevelThickness: <float>, // how deep into the original shape bevel goes
  13064. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  13065. * bevelOffset: <float>, // how far from shape outline does bevel start
  13066. * bevelSegments: <int>, // number of bevel layers
  13067. *
  13068. * extrudePath: <THREE.Curve> // curve to extrude shape along
  13069. *
  13070. * UVGenerator: <Object> // object that provides UV generator functions
  13071. *
  13072. * }
  13073. */
  13074. class ExtrudeGeometry extends BufferGeometry {
  13075. constructor( shapes = new Shape( [ new Vector2( 0.5, 0.5 ), new Vector2( -0.5, 0.5 ), new Vector2( -0.5, -0.5 ), new Vector2( 0.5, -0.5 ) ] ), options = {} ) {
  13076. super();
  13077. this.type = 'ExtrudeGeometry';
  13078. this.parameters = {
  13079. shapes: shapes,
  13080. options: options
  13081. };
  13082. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  13083. const scope = this;
  13084. const verticesArray = [];
  13085. const uvArray = [];
  13086. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13087. const shape = shapes[ i ];
  13088. addShape( shape );
  13089. }
  13090. // build geometry
  13091. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  13092. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  13093. this.computeVertexNormals();
  13094. // functions
  13095. function addShape( shape ) {
  13096. const placeholder = [];
  13097. // options
  13098. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  13099. const steps = options.steps !== undefined ? options.steps : 1;
  13100. const depth = options.depth !== undefined ? options.depth : 1;
  13101. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  13102. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
  13103. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
  13104. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  13105. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  13106. const extrudePath = options.extrudePath;
  13107. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  13108. //
  13109. let extrudePts, extrudeByPath = false;
  13110. let splineTube, binormal, normal, position2;
  13111. if ( extrudePath ) {
  13112. extrudePts = extrudePath.getSpacedPoints( steps );
  13113. extrudeByPath = true;
  13114. bevelEnabled = false; // bevels not supported for path extrusion
  13115. // SETUP TNB variables
  13116. // TODO1 - have a .isClosed in spline?
  13117. splineTube = extrudePath.computeFrenetFrames( steps, false );
  13118. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  13119. binormal = new Vector3();
  13120. normal = new Vector3();
  13121. position2 = new Vector3();
  13122. }
  13123. // Safeguards if bevels are not enabled
  13124. if ( ! bevelEnabled ) {
  13125. bevelSegments = 0;
  13126. bevelThickness = 0;
  13127. bevelSize = 0;
  13128. bevelOffset = 0;
  13129. }
  13130. // Variables initialization
  13131. const shapePoints = shape.extractPoints( curveSegments );
  13132. let vertices = shapePoints.shape;
  13133. const holes = shapePoints.holes;
  13134. const reverse = ! ShapeUtils.isClockWise( vertices );
  13135. if ( reverse ) {
  13136. vertices = vertices.reverse();
  13137. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  13138. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13139. const ahole = holes[ h ];
  13140. if ( ShapeUtils.isClockWise( ahole ) ) {
  13141. holes[ h ] = ahole.reverse();
  13142. }
  13143. }
  13144. }
  13145. const faces = ShapeUtils.triangulateShape( vertices, holes );
  13146. /* Vertices */
  13147. const contour = vertices; // vertices has all points but contour has only points of circumference
  13148. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13149. const ahole = holes[ h ];
  13150. vertices = vertices.concat( ahole );
  13151. }
  13152. function scalePt2( pt, vec, size ) {
  13153. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  13154. return pt.clone().addScaledVector( vec, size );
  13155. }
  13156. const vlen = vertices.length, flen = faces.length;
  13157. // Find directions for point movement
  13158. function getBevelVec( inPt, inPrev, inNext ) {
  13159. // computes for inPt the corresponding point inPt' on a new contour
  13160. // shifted by 1 unit (length of normalized vector) to the left
  13161. // if we walk along contour clockwise, this new contour is outside the old one
  13162. //
  13163. // inPt' is the intersection of the two lines parallel to the two
  13164. // adjacent edges of inPt at a distance of 1 unit on the left side.
  13165. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  13166. // good reading for geometry algorithms (here: line-line intersection)
  13167. // http://geomalgorithms.com/a05-_intersect-1.html
  13168. const v_prev_x = inPt.x - inPrev.x,
  13169. v_prev_y = inPt.y - inPrev.y;
  13170. const v_next_x = inNext.x - inPt.x,
  13171. v_next_y = inNext.y - inPt.y;
  13172. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  13173. // check for collinear edges
  13174. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  13175. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  13176. // not collinear
  13177. // length of vectors for normalizing
  13178. const v_prev_len = Math.sqrt( v_prev_lensq );
  13179. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  13180. // shift adjacent points by unit vectors to the left
  13181. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  13182. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  13183. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  13184. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  13185. // scaling factor for v_prev to intersection point
  13186. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  13187. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  13188. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  13189. // vector from inPt to intersection point
  13190. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  13191. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  13192. // Don't normalize!, otherwise sharp corners become ugly
  13193. // but prevent crazy spikes
  13194. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  13195. if ( v_trans_lensq <= 2 ) {
  13196. return new Vector2( v_trans_x, v_trans_y );
  13197. } else {
  13198. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  13199. }
  13200. } else {
  13201. // handle special case of collinear edges
  13202. let direction_eq = false; // assumes: opposite
  13203. if ( v_prev_x > Number.EPSILON ) {
  13204. if ( v_next_x > Number.EPSILON ) {
  13205. direction_eq = true;
  13206. }
  13207. } else {
  13208. if ( v_prev_x < - Number.EPSILON ) {
  13209. if ( v_next_x < - Number.EPSILON ) {
  13210. direction_eq = true;
  13211. }
  13212. } else {
  13213. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  13214. direction_eq = true;
  13215. }
  13216. }
  13217. }
  13218. if ( direction_eq ) {
  13219. // console.log("Warning: lines are a straight sequence");
  13220. v_trans_x = - v_prev_y;
  13221. v_trans_y = v_prev_x;
  13222. shrink_by = Math.sqrt( v_prev_lensq );
  13223. } else {
  13224. // console.log("Warning: lines are a straight spike");
  13225. v_trans_x = v_prev_x;
  13226. v_trans_y = v_prev_y;
  13227. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  13228. }
  13229. }
  13230. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  13231. }
  13232. const contourMovements = [];
  13233. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13234. if ( j === il ) j = 0;
  13235. if ( k === il ) k = 0;
  13236. // (j)---(i)---(k)
  13237. // console.log('i,j,k', i, j , k)
  13238. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  13239. }
  13240. const holesMovements = [];
  13241. let oneHoleMovements, verticesMovements = contourMovements.concat();
  13242. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13243. const ahole = holes[ h ];
  13244. oneHoleMovements = [];
  13245. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13246. if ( j === il ) j = 0;
  13247. if ( k === il ) k = 0;
  13248. // (j)---(i)---(k)
  13249. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  13250. }
  13251. holesMovements.push( oneHoleMovements );
  13252. verticesMovements = verticesMovements.concat( oneHoleMovements );
  13253. }
  13254. // Loop bevelSegments, 1 for the front, 1 for the back
  13255. for ( let b = 0; b < bevelSegments; b ++ ) {
  13256. //for ( b = bevelSegments; b > 0; b -- ) {
  13257. const t = b / bevelSegments;
  13258. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13259. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13260. // contract shape
  13261. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13262. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13263. v( vert.x, vert.y, - z );
  13264. }
  13265. // expand holes
  13266. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13267. const ahole = holes[ h ];
  13268. oneHoleMovements = holesMovements[ h ];
  13269. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13270. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13271. v( vert.x, vert.y, - z );
  13272. }
  13273. }
  13274. }
  13275. const bs = bevelSize + bevelOffset;
  13276. // Back facing vertices
  13277. for ( let i = 0; i < vlen; i ++ ) {
  13278. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13279. if ( ! extrudeByPath ) {
  13280. v( vert.x, vert.y, 0 );
  13281. } else {
  13282. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  13283. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  13284. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  13285. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  13286. v( position2.x, position2.y, position2.z );
  13287. }
  13288. }
  13289. // Add stepped vertices...
  13290. // Including front facing vertices
  13291. for ( let s = 1; s <= steps; s ++ ) {
  13292. for ( let i = 0; i < vlen; i ++ ) {
  13293. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13294. if ( ! extrudeByPath ) {
  13295. v( vert.x, vert.y, depth / steps * s );
  13296. } else {
  13297. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  13298. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  13299. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  13300. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  13301. v( position2.x, position2.y, position2.z );
  13302. }
  13303. }
  13304. }
  13305. // Add bevel segments planes
  13306. //for ( b = 1; b <= bevelSegments; b ++ ) {
  13307. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  13308. const t = b / bevelSegments;
  13309. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13310. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13311. // contract shape
  13312. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13313. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13314. v( vert.x, vert.y, depth + z );
  13315. }
  13316. // expand holes
  13317. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13318. const ahole = holes[ h ];
  13319. oneHoleMovements = holesMovements[ h ];
  13320. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13321. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13322. if ( ! extrudeByPath ) {
  13323. v( vert.x, vert.y, depth + z );
  13324. } else {
  13325. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  13326. }
  13327. }
  13328. }
  13329. }
  13330. /* Faces */
  13331. // Top and bottom faces
  13332. buildLidFaces();
  13333. // Sides faces
  13334. buildSideFaces();
  13335. ///// Internal functions
  13336. function buildLidFaces() {
  13337. const start = verticesArray.length / 3;
  13338. if ( bevelEnabled ) {
  13339. let layer = 0; // steps + 1
  13340. let offset = vlen * layer;
  13341. // Bottom faces
  13342. for ( let i = 0; i < flen; i ++ ) {
  13343. const face = faces[ i ];
  13344. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  13345. }
  13346. layer = steps + bevelSegments * 2;
  13347. offset = vlen * layer;
  13348. // Top faces
  13349. for ( let i = 0; i < flen; i ++ ) {
  13350. const face = faces[ i ];
  13351. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  13352. }
  13353. } else {
  13354. // Bottom faces
  13355. for ( let i = 0; i < flen; i ++ ) {
  13356. const face = faces[ i ];
  13357. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  13358. }
  13359. // Top faces
  13360. for ( let i = 0; i < flen; i ++ ) {
  13361. const face = faces[ i ];
  13362. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  13363. }
  13364. }
  13365. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  13366. }
  13367. // Create faces for the z-sides of the shape
  13368. function buildSideFaces() {
  13369. const start = verticesArray.length / 3;
  13370. let layeroffset = 0;
  13371. sidewalls( contour, layeroffset );
  13372. layeroffset += contour.length;
  13373. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13374. const ahole = holes[ h ];
  13375. sidewalls( ahole, layeroffset );
  13376. //, true
  13377. layeroffset += ahole.length;
  13378. }
  13379. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  13380. }
  13381. function sidewalls( contour, layeroffset ) {
  13382. let i = contour.length;
  13383. while ( -- i >= 0 ) {
  13384. const j = i;
  13385. let k = i - 1;
  13386. if ( k < 0 ) k = contour.length - 1;
  13387. //console.log('b', i,j, i-1, k,vertices.length);
  13388. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  13389. const slen1 = vlen * s;
  13390. const slen2 = vlen * ( s + 1 );
  13391. const a = layeroffset + j + slen1,
  13392. b = layeroffset + k + slen1,
  13393. c = layeroffset + k + slen2,
  13394. d = layeroffset + j + slen2;
  13395. f4( a, b, c, d );
  13396. }
  13397. }
  13398. }
  13399. function v( x, y, z ) {
  13400. placeholder.push( x );
  13401. placeholder.push( y );
  13402. placeholder.push( z );
  13403. }
  13404. function f3( a, b, c ) {
  13405. addVertex( a );
  13406. addVertex( b );
  13407. addVertex( c );
  13408. const nextIndex = verticesArray.length / 3;
  13409. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13410. addUV( uvs[ 0 ] );
  13411. addUV( uvs[ 1 ] );
  13412. addUV( uvs[ 2 ] );
  13413. }
  13414. function f4( a, b, c, d ) {
  13415. addVertex( a );
  13416. addVertex( b );
  13417. addVertex( d );
  13418. addVertex( b );
  13419. addVertex( c );
  13420. addVertex( d );
  13421. const nextIndex = verticesArray.length / 3;
  13422. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13423. addUV( uvs[ 0 ] );
  13424. addUV( uvs[ 1 ] );
  13425. addUV( uvs[ 3 ] );
  13426. addUV( uvs[ 1 ] );
  13427. addUV( uvs[ 2 ] );
  13428. addUV( uvs[ 3 ] );
  13429. }
  13430. function addVertex( index ) {
  13431. verticesArray.push( placeholder[ index * 3 + 0 ] );
  13432. verticesArray.push( placeholder[ index * 3 + 1 ] );
  13433. verticesArray.push( placeholder[ index * 3 + 2 ] );
  13434. }
  13435. function addUV( vector2 ) {
  13436. uvArray.push( vector2.x );
  13437. uvArray.push( vector2.y );
  13438. }
  13439. }
  13440. }
  13441. copy( source ) {
  13442. super.copy( source );
  13443. this.parameters = Object.assign( {}, source.parameters );
  13444. return this;
  13445. }
  13446. toJSON() {
  13447. const data = super.toJSON();
  13448. const shapes = this.parameters.shapes;
  13449. const options = this.parameters.options;
  13450. return toJSON$1( shapes, options, data );
  13451. }
  13452. static fromJSON( data, shapes ) {
  13453. const geometryShapes = [];
  13454. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13455. const shape = shapes[ data.shapes[ j ] ];
  13456. geometryShapes.push( shape );
  13457. }
  13458. const extrudePath = data.options.extrudePath;
  13459. if ( extrudePath !== undefined ) {
  13460. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  13461. }
  13462. return new ExtrudeGeometry( geometryShapes, data.options );
  13463. }
  13464. }
  13465. const WorldUVGenerator = {
  13466. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  13467. const a_x = vertices[ indexA * 3 ];
  13468. const a_y = vertices[ indexA * 3 + 1 ];
  13469. const b_x = vertices[ indexB * 3 ];
  13470. const b_y = vertices[ indexB * 3 + 1 ];
  13471. const c_x = vertices[ indexC * 3 ];
  13472. const c_y = vertices[ indexC * 3 + 1 ];
  13473. return [
  13474. new Vector2( a_x, a_y ),
  13475. new Vector2( b_x, b_y ),
  13476. new Vector2( c_x, c_y )
  13477. ];
  13478. },
  13479. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  13480. const a_x = vertices[ indexA * 3 ];
  13481. const a_y = vertices[ indexA * 3 + 1 ];
  13482. const a_z = vertices[ indexA * 3 + 2 ];
  13483. const b_x = vertices[ indexB * 3 ];
  13484. const b_y = vertices[ indexB * 3 + 1 ];
  13485. const b_z = vertices[ indexB * 3 + 2 ];
  13486. const c_x = vertices[ indexC * 3 ];
  13487. const c_y = vertices[ indexC * 3 + 1 ];
  13488. const c_z = vertices[ indexC * 3 + 2 ];
  13489. const d_x = vertices[ indexD * 3 ];
  13490. const d_y = vertices[ indexD * 3 + 1 ];
  13491. const d_z = vertices[ indexD * 3 + 2 ];
  13492. if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
  13493. return [
  13494. new Vector2( a_x, 1 - a_z ),
  13495. new Vector2( b_x, 1 - b_z ),
  13496. new Vector2( c_x, 1 - c_z ),
  13497. new Vector2( d_x, 1 - d_z )
  13498. ];
  13499. } else {
  13500. return [
  13501. new Vector2( a_y, 1 - a_z ),
  13502. new Vector2( b_y, 1 - b_z ),
  13503. new Vector2( c_y, 1 - c_z ),
  13504. new Vector2( d_y, 1 - d_z )
  13505. ];
  13506. }
  13507. }
  13508. };
  13509. function toJSON$1( shapes, options, data ) {
  13510. data.shapes = [];
  13511. if ( Array.isArray( shapes ) ) {
  13512. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13513. const shape = shapes[ i ];
  13514. data.shapes.push( shape.uuid );
  13515. }
  13516. } else {
  13517. data.shapes.push( shapes.uuid );
  13518. }
  13519. data.options = Object.assign( {}, options );
  13520. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  13521. return data;
  13522. }
  13523. class IcosahedronGeometry extends PolyhedronGeometry {
  13524. constructor( radius = 1, detail = 0 ) {
  13525. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  13526. const vertices = [
  13527. -1, t, 0, 1, t, 0, -1, - t, 0, 1, - t, 0,
  13528. 0, -1, t, 0, 1, t, 0, -1, - t, 0, 1, - t,
  13529. t, 0, -1, t, 0, 1, - t, 0, -1, - t, 0, 1
  13530. ];
  13531. const indices = [
  13532. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  13533. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  13534. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  13535. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  13536. ];
  13537. super( vertices, indices, radius, detail );
  13538. this.type = 'IcosahedronGeometry';
  13539. this.parameters = {
  13540. radius: radius,
  13541. detail: detail
  13542. };
  13543. }
  13544. static fromJSON( data ) {
  13545. return new IcosahedronGeometry( data.radius, data.detail );
  13546. }
  13547. }
  13548. class OctahedronGeometry extends PolyhedronGeometry {
  13549. constructor( radius = 1, detail = 0 ) {
  13550. const vertices = [
  13551. 1, 0, 0, -1, 0, 0, 0, 1, 0,
  13552. 0, -1, 0, 0, 0, 1, 0, 0, -1
  13553. ];
  13554. const indices = [
  13555. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  13556. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  13557. 1, 3, 4, 1, 4, 2
  13558. ];
  13559. super( vertices, indices, radius, detail );
  13560. this.type = 'OctahedronGeometry';
  13561. this.parameters = {
  13562. radius: radius,
  13563. detail: detail
  13564. };
  13565. }
  13566. static fromJSON( data ) {
  13567. return new OctahedronGeometry( data.radius, data.detail );
  13568. }
  13569. }
  13570. class PlaneGeometry extends BufferGeometry {
  13571. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  13572. super();
  13573. this.type = 'PlaneGeometry';
  13574. this.parameters = {
  13575. width: width,
  13576. height: height,
  13577. widthSegments: widthSegments,
  13578. heightSegments: heightSegments
  13579. };
  13580. const width_half = width / 2;
  13581. const height_half = height / 2;
  13582. const gridX = Math.floor( widthSegments );
  13583. const gridY = Math.floor( heightSegments );
  13584. const gridX1 = gridX + 1;
  13585. const gridY1 = gridY + 1;
  13586. const segment_width = width / gridX;
  13587. const segment_height = height / gridY;
  13588. //
  13589. const indices = [];
  13590. const vertices = [];
  13591. const normals = [];
  13592. const uvs = [];
  13593. for ( let iy = 0; iy < gridY1; iy ++ ) {
  13594. const y = iy * segment_height - height_half;
  13595. for ( let ix = 0; ix < gridX1; ix ++ ) {
  13596. const x = ix * segment_width - width_half;
  13597. vertices.push( x, - y, 0 );
  13598. normals.push( 0, 0, 1 );
  13599. uvs.push( ix / gridX );
  13600. uvs.push( 1 - ( iy / gridY ) );
  13601. }
  13602. }
  13603. for ( let iy = 0; iy < gridY; iy ++ ) {
  13604. for ( let ix = 0; ix < gridX; ix ++ ) {
  13605. const a = ix + gridX1 * iy;
  13606. const b = ix + gridX1 * ( iy + 1 );
  13607. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  13608. const d = ( ix + 1 ) + gridX1 * iy;
  13609. indices.push( a, b, d );
  13610. indices.push( b, c, d );
  13611. }
  13612. }
  13613. this.setIndex( indices );
  13614. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13615. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13616. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13617. }
  13618. copy( source ) {
  13619. super.copy( source );
  13620. this.parameters = Object.assign( {}, source.parameters );
  13621. return this;
  13622. }
  13623. static fromJSON( data ) {
  13624. return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
  13625. }
  13626. }
  13627. class RingGeometry extends BufferGeometry {
  13628. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  13629. super();
  13630. this.type = 'RingGeometry';
  13631. this.parameters = {
  13632. innerRadius: innerRadius,
  13633. outerRadius: outerRadius,
  13634. thetaSegments: thetaSegments,
  13635. phiSegments: phiSegments,
  13636. thetaStart: thetaStart,
  13637. thetaLength: thetaLength
  13638. };
  13639. thetaSegments = Math.max( 3, thetaSegments );
  13640. phiSegments = Math.max( 1, phiSegments );
  13641. // buffers
  13642. const indices = [];
  13643. const vertices = [];
  13644. const normals = [];
  13645. const uvs = [];
  13646. // some helper variables
  13647. let radius = innerRadius;
  13648. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  13649. const vertex = new Vector3();
  13650. const uv = new Vector2();
  13651. // generate vertices, normals and uvs
  13652. for ( let j = 0; j <= phiSegments; j ++ ) {
  13653. for ( let i = 0; i <= thetaSegments; i ++ ) {
  13654. // values are generate from the inside of the ring to the outside
  13655. const segment = thetaStart + i / thetaSegments * thetaLength;
  13656. // vertex
  13657. vertex.x = radius * Math.cos( segment );
  13658. vertex.y = radius * Math.sin( segment );
  13659. vertices.push( vertex.x, vertex.y, vertex.z );
  13660. // normal
  13661. normals.push( 0, 0, 1 );
  13662. // uv
  13663. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  13664. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  13665. uvs.push( uv.x, uv.y );
  13666. }
  13667. // increase the radius for next row of vertices
  13668. radius += radiusStep;
  13669. }
  13670. // indices
  13671. for ( let j = 0; j < phiSegments; j ++ ) {
  13672. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  13673. for ( let i = 0; i < thetaSegments; i ++ ) {
  13674. const segment = i + thetaSegmentLevel;
  13675. const a = segment;
  13676. const b = segment + thetaSegments + 1;
  13677. const c = segment + thetaSegments + 2;
  13678. const d = segment + 1;
  13679. // faces
  13680. indices.push( a, b, d );
  13681. indices.push( b, c, d );
  13682. }
  13683. }
  13684. // build geometry
  13685. this.setIndex( indices );
  13686. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13687. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13688. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13689. }
  13690. copy( source ) {
  13691. super.copy( source );
  13692. this.parameters = Object.assign( {}, source.parameters );
  13693. return this;
  13694. }
  13695. static fromJSON( data ) {
  13696. return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
  13697. }
  13698. }
  13699. class ShapeGeometry extends BufferGeometry {
  13700. constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( -0.5, -0.5 ), new Vector2( 0.5, -0.5 ) ] ), curveSegments = 12 ) {
  13701. super();
  13702. this.type = 'ShapeGeometry';
  13703. this.parameters = {
  13704. shapes: shapes,
  13705. curveSegments: curveSegments
  13706. };
  13707. // buffers
  13708. const indices = [];
  13709. const vertices = [];
  13710. const normals = [];
  13711. const uvs = [];
  13712. // helper variables
  13713. let groupStart = 0;
  13714. let groupCount = 0;
  13715. // allow single and array values for "shapes" parameter
  13716. if ( Array.isArray( shapes ) === false ) {
  13717. addShape( shapes );
  13718. } else {
  13719. for ( let i = 0; i < shapes.length; i ++ ) {
  13720. addShape( shapes[ i ] );
  13721. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  13722. groupStart += groupCount;
  13723. groupCount = 0;
  13724. }
  13725. }
  13726. // build geometry
  13727. this.setIndex( indices );
  13728. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13729. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13730. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13731. // helper functions
  13732. function addShape( shape ) {
  13733. const indexOffset = vertices.length / 3;
  13734. const points = shape.extractPoints( curveSegments );
  13735. let shapeVertices = points.shape;
  13736. const shapeHoles = points.holes;
  13737. // check direction of vertices
  13738. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  13739. shapeVertices = shapeVertices.reverse();
  13740. }
  13741. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13742. const shapeHole = shapeHoles[ i ];
  13743. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  13744. shapeHoles[ i ] = shapeHole.reverse();
  13745. }
  13746. }
  13747. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  13748. // join vertices of inner and outer paths to a single array
  13749. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13750. const shapeHole = shapeHoles[ i ];
  13751. shapeVertices = shapeVertices.concat( shapeHole );
  13752. }
  13753. // vertices, normals, uvs
  13754. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  13755. const vertex = shapeVertices[ i ];
  13756. vertices.push( vertex.x, vertex.y, 0 );
  13757. normals.push( 0, 0, 1 );
  13758. uvs.push( vertex.x, vertex.y ); // world uvs
  13759. }
  13760. // indices
  13761. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  13762. const face = faces[ i ];
  13763. const a = face[ 0 ] + indexOffset;
  13764. const b = face[ 1 ] + indexOffset;
  13765. const c = face[ 2 ] + indexOffset;
  13766. indices.push( a, b, c );
  13767. groupCount += 3;
  13768. }
  13769. }
  13770. }
  13771. copy( source ) {
  13772. super.copy( source );
  13773. this.parameters = Object.assign( {}, source.parameters );
  13774. return this;
  13775. }
  13776. toJSON() {
  13777. const data = super.toJSON();
  13778. const shapes = this.parameters.shapes;
  13779. return toJSON( shapes, data );
  13780. }
  13781. static fromJSON( data, shapes ) {
  13782. const geometryShapes = [];
  13783. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13784. const shape = shapes[ data.shapes[ j ] ];
  13785. geometryShapes.push( shape );
  13786. }
  13787. return new ShapeGeometry( geometryShapes, data.curveSegments );
  13788. }
  13789. }
  13790. function toJSON( shapes, data ) {
  13791. data.shapes = [];
  13792. if ( Array.isArray( shapes ) ) {
  13793. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13794. const shape = shapes[ i ];
  13795. data.shapes.push( shape.uuid );
  13796. }
  13797. } else {
  13798. data.shapes.push( shapes.uuid );
  13799. }
  13800. return data;
  13801. }
  13802. class SphereGeometry extends BufferGeometry {
  13803. constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  13804. super();
  13805. this.type = 'SphereGeometry';
  13806. this.parameters = {
  13807. radius: radius,
  13808. widthSegments: widthSegments,
  13809. heightSegments: heightSegments,
  13810. phiStart: phiStart,
  13811. phiLength: phiLength,
  13812. thetaStart: thetaStart,
  13813. thetaLength: thetaLength
  13814. };
  13815. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  13816. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  13817. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  13818. let index = 0;
  13819. const grid = [];
  13820. const vertex = new Vector3();
  13821. const normal = new Vector3();
  13822. // buffers
  13823. const indices = [];
  13824. const vertices = [];
  13825. const normals = [];
  13826. const uvs = [];
  13827. // generate vertices, normals and uvs
  13828. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  13829. const verticesRow = [];
  13830. const v = iy / heightSegments;
  13831. // special case for the poles
  13832. let uOffset = 0;
  13833. if ( iy === 0 && thetaStart === 0 ) {
  13834. uOffset = 0.5 / widthSegments;
  13835. } else if ( iy === heightSegments && thetaEnd === Math.PI ) {
  13836. uOffset = -0.5 / widthSegments;
  13837. }
  13838. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  13839. const u = ix / widthSegments;
  13840. // vertex
  13841. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13842. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  13843. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13844. vertices.push( vertex.x, vertex.y, vertex.z );
  13845. // normal
  13846. normal.copy( vertex ).normalize();
  13847. normals.push( normal.x, normal.y, normal.z );
  13848. // uv
  13849. uvs.push( u + uOffset, 1 - v );
  13850. verticesRow.push( index ++ );
  13851. }
  13852. grid.push( verticesRow );
  13853. }
  13854. // indices
  13855. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  13856. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  13857. const a = grid[ iy ][ ix + 1 ];
  13858. const b = grid[ iy ][ ix ];
  13859. const c = grid[ iy + 1 ][ ix ];
  13860. const d = grid[ iy + 1 ][ ix + 1 ];
  13861. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  13862. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  13863. }
  13864. }
  13865. // build geometry
  13866. this.setIndex( indices );
  13867. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13868. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13869. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13870. }
  13871. copy( source ) {
  13872. super.copy( source );
  13873. this.parameters = Object.assign( {}, source.parameters );
  13874. return this;
  13875. }
  13876. static fromJSON( data ) {
  13877. return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
  13878. }
  13879. }
  13880. class TetrahedronGeometry extends PolyhedronGeometry {
  13881. constructor( radius = 1, detail = 0 ) {
  13882. const vertices = [
  13883. 1, 1, 1, -1, -1, 1, -1, 1, -1, 1, -1, -1
  13884. ];
  13885. const indices = [
  13886. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  13887. ];
  13888. super( vertices, indices, radius, detail );
  13889. this.type = 'TetrahedronGeometry';
  13890. this.parameters = {
  13891. radius: radius,
  13892. detail: detail
  13893. };
  13894. }
  13895. static fromJSON( data ) {
  13896. return new TetrahedronGeometry( data.radius, data.detail );
  13897. }
  13898. }
  13899. class TorusGeometry extends BufferGeometry {
  13900. constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
  13901. super();
  13902. this.type = 'TorusGeometry';
  13903. this.parameters = {
  13904. radius: radius,
  13905. tube: tube,
  13906. radialSegments: radialSegments,
  13907. tubularSegments: tubularSegments,
  13908. arc: arc
  13909. };
  13910. radialSegments = Math.floor( radialSegments );
  13911. tubularSegments = Math.floor( tubularSegments );
  13912. // buffers
  13913. const indices = [];
  13914. const vertices = [];
  13915. const normals = [];
  13916. const uvs = [];
  13917. // helper variables
  13918. const center = new Vector3();
  13919. const vertex = new Vector3();
  13920. const normal = new Vector3();
  13921. // generate vertices, normals and uvs
  13922. for ( let j = 0; j <= radialSegments; j ++ ) {
  13923. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13924. const u = i / tubularSegments * arc;
  13925. const v = j / radialSegments * Math.PI * 2;
  13926. // vertex
  13927. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  13928. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  13929. vertex.z = tube * Math.sin( v );
  13930. vertices.push( vertex.x, vertex.y, vertex.z );
  13931. // normal
  13932. center.x = radius * Math.cos( u );
  13933. center.y = radius * Math.sin( u );
  13934. normal.subVectors( vertex, center ).normalize();
  13935. normals.push( normal.x, normal.y, normal.z );
  13936. // uv
  13937. uvs.push( i / tubularSegments );
  13938. uvs.push( j / radialSegments );
  13939. }
  13940. }
  13941. // generate indices
  13942. for ( let j = 1; j <= radialSegments; j ++ ) {
  13943. for ( let i = 1; i <= tubularSegments; i ++ ) {
  13944. // indices
  13945. const a = ( tubularSegments + 1 ) * j + i - 1;
  13946. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  13947. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  13948. const d = ( tubularSegments + 1 ) * j + i;
  13949. // faces
  13950. indices.push( a, b, d );
  13951. indices.push( b, c, d );
  13952. }
  13953. }
  13954. // build geometry
  13955. this.setIndex( indices );
  13956. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13957. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13958. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13959. }
  13960. copy( source ) {
  13961. super.copy( source );
  13962. this.parameters = Object.assign( {}, source.parameters );
  13963. return this;
  13964. }
  13965. static fromJSON( data ) {
  13966. return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
  13967. }
  13968. }
  13969. class TorusKnotGeometry extends BufferGeometry {
  13970. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  13971. super();
  13972. this.type = 'TorusKnotGeometry';
  13973. this.parameters = {
  13974. radius: radius,
  13975. tube: tube,
  13976. tubularSegments: tubularSegments,
  13977. radialSegments: radialSegments,
  13978. p: p,
  13979. q: q
  13980. };
  13981. tubularSegments = Math.floor( tubularSegments );
  13982. radialSegments = Math.floor( radialSegments );
  13983. // buffers
  13984. const indices = [];
  13985. const vertices = [];
  13986. const normals = [];
  13987. const uvs = [];
  13988. // helper variables
  13989. const vertex = new Vector3();
  13990. const normal = new Vector3();
  13991. const P1 = new Vector3();
  13992. const P2 = new Vector3();
  13993. const B = new Vector3();
  13994. const T = new Vector3();
  13995. const N = new Vector3();
  13996. // generate vertices, normals and uvs
  13997. for ( let i = 0; i <= tubularSegments; ++ i ) {
  13998. // the radian "u" is used to calculate the position on the torus curve of the current tubular segment
  13999. const u = i / tubularSegments * p * Math.PI * 2;
  14000. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  14001. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  14002. calculatePositionOnCurve( u, p, q, radius, P1 );
  14003. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  14004. // calculate orthonormal basis
  14005. T.subVectors( P2, P1 );
  14006. N.addVectors( P2, P1 );
  14007. B.crossVectors( T, N );
  14008. N.crossVectors( B, T );
  14009. // normalize B, N. T can be ignored, we don't use it
  14010. B.normalize();
  14011. N.normalize();
  14012. for ( let j = 0; j <= radialSegments; ++ j ) {
  14013. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  14014. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  14015. const v = j / radialSegments * Math.PI * 2;
  14016. const cx = - tube * Math.cos( v );
  14017. const cy = tube * Math.sin( v );
  14018. // now calculate the final vertex position.
  14019. // first we orient the extrusion with our basis vectors, then we add it to the current position on the curve
  14020. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  14021. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  14022. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  14023. vertices.push( vertex.x, vertex.y, vertex.z );
  14024. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  14025. normal.subVectors( vertex, P1 ).normalize();
  14026. normals.push( normal.x, normal.y, normal.z );
  14027. // uv
  14028. uvs.push( i / tubularSegments );
  14029. uvs.push( j / radialSegments );
  14030. }
  14031. }
  14032. // generate indices
  14033. for ( let j = 1; j <= tubularSegments; j ++ ) {
  14034. for ( let i = 1; i <= radialSegments; i ++ ) {
  14035. // indices
  14036. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  14037. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  14038. const c = ( radialSegments + 1 ) * j + i;
  14039. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  14040. // faces
  14041. indices.push( a, b, d );
  14042. indices.push( b, c, d );
  14043. }
  14044. }
  14045. // build geometry
  14046. this.setIndex( indices );
  14047. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14048. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14049. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14050. // this function calculates the current position on the torus curve
  14051. function calculatePositionOnCurve( u, p, q, radius, position ) {
  14052. const cu = Math.cos( u );
  14053. const su = Math.sin( u );
  14054. const quOverP = q / p * u;
  14055. const cs = Math.cos( quOverP );
  14056. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  14057. position.y = radius * ( 2 + cs ) * su * 0.5;
  14058. position.z = radius * Math.sin( quOverP ) * 0.5;
  14059. }
  14060. }
  14061. copy( source ) {
  14062. super.copy( source );
  14063. this.parameters = Object.assign( {}, source.parameters );
  14064. return this;
  14065. }
  14066. static fromJSON( data ) {
  14067. return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
  14068. }
  14069. }
  14070. class TubeGeometry extends BufferGeometry {
  14071. constructor( path = new QuadraticBezierCurve3( new Vector3( -1, -1, 0 ), new Vector3( -1, 1, 0 ), new Vector3( 1, 1, 0 ) ), tubularSegments = 64, radius = 1, radialSegments = 8, closed = false ) {
  14072. super();
  14073. this.type = 'TubeGeometry';
  14074. this.parameters = {
  14075. path: path,
  14076. tubularSegments: tubularSegments,
  14077. radius: radius,
  14078. radialSegments: radialSegments,
  14079. closed: closed
  14080. };
  14081. const frames = path.computeFrenetFrames( tubularSegments, closed );
  14082. // expose internals
  14083. this.tangents = frames.tangents;
  14084. this.normals = frames.normals;
  14085. this.binormals = frames.binormals;
  14086. // helper variables
  14087. const vertex = new Vector3();
  14088. const normal = new Vector3();
  14089. const uv = new Vector2();
  14090. let P = new Vector3();
  14091. // buffer
  14092. const vertices = [];
  14093. const normals = [];
  14094. const uvs = [];
  14095. const indices = [];
  14096. // create buffer data
  14097. generateBufferData();
  14098. // build geometry
  14099. this.setIndex( indices );
  14100. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14101. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  14102. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  14103. // functions
  14104. function generateBufferData() {
  14105. for ( let i = 0; i < tubularSegments; i ++ ) {
  14106. generateSegment( i );
  14107. }
  14108. // if the geometry is not closed, generate the last row of vertices and normals
  14109. // at the regular position on the given path
  14110. //
  14111. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  14112. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  14113. // uvs are generated in a separate function.
  14114. // this makes it easy compute correct values for closed geometries
  14115. generateUVs();
  14116. // finally create faces
  14117. generateIndices();
  14118. }
  14119. function generateSegment( i ) {
  14120. // we use getPointAt to sample evenly distributed points from the given path
  14121. P = path.getPointAt( i / tubularSegments, P );
  14122. // retrieve corresponding normal and binormal
  14123. const N = frames.normals[ i ];
  14124. const B = frames.binormals[ i ];
  14125. // generate normals and vertices for the current segment
  14126. for ( let j = 0; j <= radialSegments; j ++ ) {
  14127. const v = j / radialSegments * Math.PI * 2;
  14128. const sin = Math.sin( v );
  14129. const cos = - Math.cos( v );
  14130. // normal
  14131. normal.x = ( cos * N.x + sin * B.x );
  14132. normal.y = ( cos * N.y + sin * B.y );
  14133. normal.z = ( cos * N.z + sin * B.z );
  14134. normal.normalize();
  14135. normals.push( normal.x, normal.y, normal.z );
  14136. // vertex
  14137. vertex.x = P.x + radius * normal.x;
  14138. vertex.y = P.y + radius * normal.y;
  14139. vertex.z = P.z + radius * normal.z;
  14140. vertices.push( vertex.x, vertex.y, vertex.z );
  14141. }
  14142. }
  14143. function generateIndices() {
  14144. for ( let j = 1; j <= tubularSegments; j ++ ) {
  14145. for ( let i = 1; i <= radialSegments; i ++ ) {
  14146. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  14147. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  14148. const c = ( radialSegments + 1 ) * j + i;
  14149. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  14150. // faces
  14151. indices.push( a, b, d );
  14152. indices.push( b, c, d );
  14153. }
  14154. }
  14155. }
  14156. function generateUVs() {
  14157. for ( let i = 0; i <= tubularSegments; i ++ ) {
  14158. for ( let j = 0; j <= radialSegments; j ++ ) {
  14159. uv.x = i / tubularSegments;
  14160. uv.y = j / radialSegments;
  14161. uvs.push( uv.x, uv.y );
  14162. }
  14163. }
  14164. }
  14165. }
  14166. copy( source ) {
  14167. super.copy( source );
  14168. this.parameters = Object.assign( {}, source.parameters );
  14169. return this;
  14170. }
  14171. toJSON() {
  14172. const data = super.toJSON();
  14173. data.path = this.parameters.path.toJSON();
  14174. return data;
  14175. }
  14176. static fromJSON( data ) {
  14177. // This only works for built-in curves (e.g. CatmullRomCurve3).
  14178. // User defined curves or instances of CurvePath will not be deserialized.
  14179. return new TubeGeometry(
  14180. new Curves[ data.path.type ]().fromJSON( data.path ),
  14181. data.tubularSegments,
  14182. data.radius,
  14183. data.radialSegments,
  14184. data.closed
  14185. );
  14186. }
  14187. }
  14188. class WireframeGeometry extends BufferGeometry {
  14189. constructor( geometry = null ) {
  14190. super();
  14191. this.type = 'WireframeGeometry';
  14192. this.parameters = {
  14193. geometry: geometry
  14194. };
  14195. if ( geometry !== null ) {
  14196. // buffer
  14197. const vertices = [];
  14198. const edges = new Set();
  14199. // helper variables
  14200. const start = new Vector3();
  14201. const end = new Vector3();
  14202. if ( geometry.index !== null ) {
  14203. // indexed BufferGeometry
  14204. const position = geometry.attributes.position;
  14205. const indices = geometry.index;
  14206. let groups = geometry.groups;
  14207. if ( groups.length === 0 ) {
  14208. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  14209. }
  14210. // create a data structure that contains all edges without duplicates
  14211. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  14212. const group = groups[ o ];
  14213. const groupStart = group.start;
  14214. const groupCount = group.count;
  14215. for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
  14216. for ( let j = 0; j < 3; j ++ ) {
  14217. const index1 = indices.getX( i + j );
  14218. const index2 = indices.getX( i + ( j + 1 ) % 3 );
  14219. start.fromBufferAttribute( position, index1 );
  14220. end.fromBufferAttribute( position, index2 );
  14221. if ( isUniqueEdge( start, end, edges ) === true ) {
  14222. vertices.push( start.x, start.y, start.z );
  14223. vertices.push( end.x, end.y, end.z );
  14224. }
  14225. }
  14226. }
  14227. }
  14228. } else {
  14229. // non-indexed BufferGeometry
  14230. const position = geometry.attributes.position;
  14231. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  14232. for ( let j = 0; j < 3; j ++ ) {
  14233. // three edges per triangle, an edge is represented as (index1, index2)
  14234. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  14235. const index1 = 3 * i + j;
  14236. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  14237. start.fromBufferAttribute( position, index1 );
  14238. end.fromBufferAttribute( position, index2 );
  14239. if ( isUniqueEdge( start, end, edges ) === true ) {
  14240. vertices.push( start.x, start.y, start.z );
  14241. vertices.push( end.x, end.y, end.z );
  14242. }
  14243. }
  14244. }
  14245. }
  14246. // build geometry
  14247. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14248. }
  14249. }
  14250. copy( source ) {
  14251. super.copy( source );
  14252. this.parameters = Object.assign( {}, source.parameters );
  14253. return this;
  14254. }
  14255. }
  14256. function isUniqueEdge( start, end, edges ) {
  14257. const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
  14258. const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
  14259. if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
  14260. return false;
  14261. } else {
  14262. edges.add( hash1 );
  14263. edges.add( hash2 );
  14264. return true;
  14265. }
  14266. }
  14267. var Geometries = /*#__PURE__*/Object.freeze({
  14268. __proto__: null,
  14269. BoxGeometry: BoxGeometry,
  14270. CapsuleGeometry: CapsuleGeometry,
  14271. CircleGeometry: CircleGeometry,
  14272. ConeGeometry: ConeGeometry,
  14273. CylinderGeometry: CylinderGeometry,
  14274. DodecahedronGeometry: DodecahedronGeometry,
  14275. EdgesGeometry: EdgesGeometry,
  14276. ExtrudeGeometry: ExtrudeGeometry,
  14277. IcosahedronGeometry: IcosahedronGeometry,
  14278. LatheGeometry: LatheGeometry,
  14279. OctahedronGeometry: OctahedronGeometry,
  14280. PlaneGeometry: PlaneGeometry,
  14281. PolyhedronGeometry: PolyhedronGeometry,
  14282. RingGeometry: RingGeometry,
  14283. ShapeGeometry: ShapeGeometry,
  14284. SphereGeometry: SphereGeometry,
  14285. TetrahedronGeometry: TetrahedronGeometry,
  14286. TorusGeometry: TorusGeometry,
  14287. TorusKnotGeometry: TorusKnotGeometry,
  14288. TubeGeometry: TubeGeometry,
  14289. WireframeGeometry: WireframeGeometry
  14290. });
  14291. class ShadowMaterial extends Material {
  14292. constructor( parameters ) {
  14293. super();
  14294. this.isShadowMaterial = true;
  14295. this.type = 'ShadowMaterial';
  14296. this.color = new Color( 0x000000 );
  14297. this.transparent = true;
  14298. this.fog = true;
  14299. this.setValues( parameters );
  14300. }
  14301. copy( source ) {
  14302. super.copy( source );
  14303. this.color.copy( source.color );
  14304. this.fog = source.fog;
  14305. return this;
  14306. }
  14307. }
  14308. class RawShaderMaterial extends ShaderMaterial {
  14309. constructor( parameters ) {
  14310. super( parameters );
  14311. this.isRawShaderMaterial = true;
  14312. this.type = 'RawShaderMaterial';
  14313. }
  14314. }
  14315. class MeshStandardMaterial extends Material {
  14316. constructor( parameters ) {
  14317. super();
  14318. this.isMeshStandardMaterial = true;
  14319. this.type = 'MeshStandardMaterial';
  14320. this.defines = { 'STANDARD': '' };
  14321. this.color = new Color( 0xffffff ); // diffuse
  14322. this.roughness = 1.0;
  14323. this.metalness = 0.0;
  14324. this.map = null;
  14325. this.lightMap = null;
  14326. this.lightMapIntensity = 1.0;
  14327. this.aoMap = null;
  14328. this.aoMapIntensity = 1.0;
  14329. this.emissive = new Color( 0x000000 );
  14330. this.emissiveIntensity = 1.0;
  14331. this.emissiveMap = null;
  14332. this.bumpMap = null;
  14333. this.bumpScale = 1;
  14334. this.normalMap = null;
  14335. this.normalMapType = TangentSpaceNormalMap;
  14336. this.normalScale = new Vector2( 1, 1 );
  14337. this.displacementMap = null;
  14338. this.displacementScale = 1;
  14339. this.displacementBias = 0;
  14340. this.roughnessMap = null;
  14341. this.metalnessMap = null;
  14342. this.alphaMap = null;
  14343. this.envMap = null;
  14344. this.envMapRotation = new Euler();
  14345. this.envMapIntensity = 1.0;
  14346. this.wireframe = false;
  14347. this.wireframeLinewidth = 1;
  14348. this.wireframeLinecap = 'round';
  14349. this.wireframeLinejoin = 'round';
  14350. this.flatShading = false;
  14351. this.fog = true;
  14352. this.setValues( parameters );
  14353. }
  14354. copy( source ) {
  14355. super.copy( source );
  14356. this.defines = { 'STANDARD': '' };
  14357. this.color.copy( source.color );
  14358. this.roughness = source.roughness;
  14359. this.metalness = source.metalness;
  14360. this.map = source.map;
  14361. this.lightMap = source.lightMap;
  14362. this.lightMapIntensity = source.lightMapIntensity;
  14363. this.aoMap = source.aoMap;
  14364. this.aoMapIntensity = source.aoMapIntensity;
  14365. this.emissive.copy( source.emissive );
  14366. this.emissiveMap = source.emissiveMap;
  14367. this.emissiveIntensity = source.emissiveIntensity;
  14368. this.bumpMap = source.bumpMap;
  14369. this.bumpScale = source.bumpScale;
  14370. this.normalMap = source.normalMap;
  14371. this.normalMapType = source.normalMapType;
  14372. this.normalScale.copy( source.normalScale );
  14373. this.displacementMap = source.displacementMap;
  14374. this.displacementScale = source.displacementScale;
  14375. this.displacementBias = source.displacementBias;
  14376. this.roughnessMap = source.roughnessMap;
  14377. this.metalnessMap = source.metalnessMap;
  14378. this.alphaMap = source.alphaMap;
  14379. this.envMap = source.envMap;
  14380. this.envMapRotation.copy( source.envMapRotation );
  14381. this.envMapIntensity = source.envMapIntensity;
  14382. this.wireframe = source.wireframe;
  14383. this.wireframeLinewidth = source.wireframeLinewidth;
  14384. this.wireframeLinecap = source.wireframeLinecap;
  14385. this.wireframeLinejoin = source.wireframeLinejoin;
  14386. this.flatShading = source.flatShading;
  14387. this.fog = source.fog;
  14388. return this;
  14389. }
  14390. }
  14391. class MeshPhysicalMaterial extends MeshStandardMaterial {
  14392. constructor( parameters ) {
  14393. super();
  14394. this.isMeshPhysicalMaterial = true;
  14395. this.defines = {
  14396. 'STANDARD': '',
  14397. 'PHYSICAL': ''
  14398. };
  14399. this.type = 'MeshPhysicalMaterial';
  14400. this.anisotropyRotation = 0;
  14401. this.anisotropyMap = null;
  14402. this.clearcoatMap = null;
  14403. this.clearcoatRoughness = 0.0;
  14404. this.clearcoatRoughnessMap = null;
  14405. this.clearcoatNormalScale = new Vector2( 1, 1 );
  14406. this.clearcoatNormalMap = null;
  14407. this.ior = 1.5;
  14408. Object.defineProperty( this, 'reflectivity', {
  14409. get: function () {
  14410. return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  14411. },
  14412. set: function ( reflectivity ) {
  14413. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  14414. }
  14415. } );
  14416. this.iridescenceMap = null;
  14417. this.iridescenceIOR = 1.3;
  14418. this.iridescenceThicknessRange = [ 100, 400 ];
  14419. this.iridescenceThicknessMap = null;
  14420. this.sheenColor = new Color( 0x000000 );
  14421. this.sheenColorMap = null;
  14422. this.sheenRoughness = 1.0;
  14423. this.sheenRoughnessMap = null;
  14424. this.transmissionMap = null;
  14425. this.thickness = 0;
  14426. this.thicknessMap = null;
  14427. this.attenuationDistance = Infinity;
  14428. this.attenuationColor = new Color( 1, 1, 1 );
  14429. this.specularIntensity = 1.0;
  14430. this.specularIntensityMap = null;
  14431. this.specularColor = new Color( 1, 1, 1 );
  14432. this.specularColorMap = null;
  14433. this._anisotropy = 0;
  14434. this._clearcoat = 0;
  14435. this._dispersion = 0;
  14436. this._iridescence = 0;
  14437. this._sheen = 0.0;
  14438. this._transmission = 0;
  14439. this.setValues( parameters );
  14440. }
  14441. get anisotropy() {
  14442. return this._anisotropy;
  14443. }
  14444. set anisotropy( value ) {
  14445. if ( this._anisotropy > 0 !== value > 0 ) {
  14446. this.version ++;
  14447. }
  14448. this._anisotropy = value;
  14449. }
  14450. get clearcoat() {
  14451. return this._clearcoat;
  14452. }
  14453. set clearcoat( value ) {
  14454. if ( this._clearcoat > 0 !== value > 0 ) {
  14455. this.version ++;
  14456. }
  14457. this._clearcoat = value;
  14458. }
  14459. get iridescence() {
  14460. return this._iridescence;
  14461. }
  14462. set iridescence( value ) {
  14463. if ( this._iridescence > 0 !== value > 0 ) {
  14464. this.version ++;
  14465. }
  14466. this._iridescence = value;
  14467. }
  14468. get dispersion() {
  14469. return this._dispersion;
  14470. }
  14471. set dispersion( value ) {
  14472. if ( this._dispersion > 0 !== value > 0 ) {
  14473. this.version ++;
  14474. }
  14475. this._dispersion = value;
  14476. }
  14477. get sheen() {
  14478. return this._sheen;
  14479. }
  14480. set sheen( value ) {
  14481. if ( this._sheen > 0 !== value > 0 ) {
  14482. this.version ++;
  14483. }
  14484. this._sheen = value;
  14485. }
  14486. get transmission() {
  14487. return this._transmission;
  14488. }
  14489. set transmission( value ) {
  14490. if ( this._transmission > 0 !== value > 0 ) {
  14491. this.version ++;
  14492. }
  14493. this._transmission = value;
  14494. }
  14495. copy( source ) {
  14496. super.copy( source );
  14497. this.defines = {
  14498. 'STANDARD': '',
  14499. 'PHYSICAL': ''
  14500. };
  14501. this.anisotropy = source.anisotropy;
  14502. this.anisotropyRotation = source.anisotropyRotation;
  14503. this.anisotropyMap = source.anisotropyMap;
  14504. this.clearcoat = source.clearcoat;
  14505. this.clearcoatMap = source.clearcoatMap;
  14506. this.clearcoatRoughness = source.clearcoatRoughness;
  14507. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  14508. this.clearcoatNormalMap = source.clearcoatNormalMap;
  14509. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  14510. this.dispersion = source.dispersion;
  14511. this.ior = source.ior;
  14512. this.iridescence = source.iridescence;
  14513. this.iridescenceMap = source.iridescenceMap;
  14514. this.iridescenceIOR = source.iridescenceIOR;
  14515. this.iridescenceThicknessRange = [ ...source.iridescenceThicknessRange ];
  14516. this.iridescenceThicknessMap = source.iridescenceThicknessMap;
  14517. this.sheen = source.sheen;
  14518. this.sheenColor.copy( source.sheenColor );
  14519. this.sheenColorMap = source.sheenColorMap;
  14520. this.sheenRoughness = source.sheenRoughness;
  14521. this.sheenRoughnessMap = source.sheenRoughnessMap;
  14522. this.transmission = source.transmission;
  14523. this.transmissionMap = source.transmissionMap;
  14524. this.thickness = source.thickness;
  14525. this.thicknessMap = source.thicknessMap;
  14526. this.attenuationDistance = source.attenuationDistance;
  14527. this.attenuationColor.copy( source.attenuationColor );
  14528. this.specularIntensity = source.specularIntensity;
  14529. this.specularIntensityMap = source.specularIntensityMap;
  14530. this.specularColor.copy( source.specularColor );
  14531. this.specularColorMap = source.specularColorMap;
  14532. return this;
  14533. }
  14534. }
  14535. class MeshPhongMaterial extends Material {
  14536. constructor( parameters ) {
  14537. super();
  14538. this.isMeshPhongMaterial = true;
  14539. this.type = 'MeshPhongMaterial';
  14540. this.color = new Color( 0xffffff ); // diffuse
  14541. this.specular = new Color( 0x111111 );
  14542. this.shininess = 30;
  14543. this.map = null;
  14544. this.lightMap = null;
  14545. this.lightMapIntensity = 1.0;
  14546. this.aoMap = null;
  14547. this.aoMapIntensity = 1.0;
  14548. this.emissive = new Color( 0x000000 );
  14549. this.emissiveIntensity = 1.0;
  14550. this.emissiveMap = null;
  14551. this.bumpMap = null;
  14552. this.bumpScale = 1;
  14553. this.normalMap = null;
  14554. this.normalMapType = TangentSpaceNormalMap;
  14555. this.normalScale = new Vector2( 1, 1 );
  14556. this.displacementMap = null;
  14557. this.displacementScale = 1;
  14558. this.displacementBias = 0;
  14559. this.specularMap = null;
  14560. this.alphaMap = null;
  14561. this.envMap = null;
  14562. this.envMapRotation = new Euler();
  14563. this.combine = MultiplyOperation;
  14564. this.reflectivity = 1;
  14565. this.refractionRatio = 0.98;
  14566. this.wireframe = false;
  14567. this.wireframeLinewidth = 1;
  14568. this.wireframeLinecap = 'round';
  14569. this.wireframeLinejoin = 'round';
  14570. this.flatShading = false;
  14571. this.fog = true;
  14572. this.setValues( parameters );
  14573. }
  14574. copy( source ) {
  14575. super.copy( source );
  14576. this.color.copy( source.color );
  14577. this.specular.copy( source.specular );
  14578. this.shininess = source.shininess;
  14579. this.map = source.map;
  14580. this.lightMap = source.lightMap;
  14581. this.lightMapIntensity = source.lightMapIntensity;
  14582. this.aoMap = source.aoMap;
  14583. this.aoMapIntensity = source.aoMapIntensity;
  14584. this.emissive.copy( source.emissive );
  14585. this.emissiveMap = source.emissiveMap;
  14586. this.emissiveIntensity = source.emissiveIntensity;
  14587. this.bumpMap = source.bumpMap;
  14588. this.bumpScale = source.bumpScale;
  14589. this.normalMap = source.normalMap;
  14590. this.normalMapType = source.normalMapType;
  14591. this.normalScale.copy( source.normalScale );
  14592. this.displacementMap = source.displacementMap;
  14593. this.displacementScale = source.displacementScale;
  14594. this.displacementBias = source.displacementBias;
  14595. this.specularMap = source.specularMap;
  14596. this.alphaMap = source.alphaMap;
  14597. this.envMap = source.envMap;
  14598. this.envMapRotation.copy( source.envMapRotation );
  14599. this.combine = source.combine;
  14600. this.reflectivity = source.reflectivity;
  14601. this.refractionRatio = source.refractionRatio;
  14602. this.wireframe = source.wireframe;
  14603. this.wireframeLinewidth = source.wireframeLinewidth;
  14604. this.wireframeLinecap = source.wireframeLinecap;
  14605. this.wireframeLinejoin = source.wireframeLinejoin;
  14606. this.flatShading = source.flatShading;
  14607. this.fog = source.fog;
  14608. return this;
  14609. }
  14610. }
  14611. class MeshToonMaterial extends Material {
  14612. constructor( parameters ) {
  14613. super();
  14614. this.isMeshToonMaterial = true;
  14615. this.defines = { 'TOON': '' };
  14616. this.type = 'MeshToonMaterial';
  14617. this.color = new Color( 0xffffff );
  14618. this.map = null;
  14619. this.gradientMap = null;
  14620. this.lightMap = null;
  14621. this.lightMapIntensity = 1.0;
  14622. this.aoMap = null;
  14623. this.aoMapIntensity = 1.0;
  14624. this.emissive = new Color( 0x000000 );
  14625. this.emissiveIntensity = 1.0;
  14626. this.emissiveMap = null;
  14627. this.bumpMap = null;
  14628. this.bumpScale = 1;
  14629. this.normalMap = null;
  14630. this.normalMapType = TangentSpaceNormalMap;
  14631. this.normalScale = new Vector2( 1, 1 );
  14632. this.displacementMap = null;
  14633. this.displacementScale = 1;
  14634. this.displacementBias = 0;
  14635. this.alphaMap = null;
  14636. this.wireframe = false;
  14637. this.wireframeLinewidth = 1;
  14638. this.wireframeLinecap = 'round';
  14639. this.wireframeLinejoin = 'round';
  14640. this.fog = true;
  14641. this.setValues( parameters );
  14642. }
  14643. copy( source ) {
  14644. super.copy( source );
  14645. this.color.copy( source.color );
  14646. this.map = source.map;
  14647. this.gradientMap = source.gradientMap;
  14648. this.lightMap = source.lightMap;
  14649. this.lightMapIntensity = source.lightMapIntensity;
  14650. this.aoMap = source.aoMap;
  14651. this.aoMapIntensity = source.aoMapIntensity;
  14652. this.emissive.copy( source.emissive );
  14653. this.emissiveMap = source.emissiveMap;
  14654. this.emissiveIntensity = source.emissiveIntensity;
  14655. this.bumpMap = source.bumpMap;
  14656. this.bumpScale = source.bumpScale;
  14657. this.normalMap = source.normalMap;
  14658. this.normalMapType = source.normalMapType;
  14659. this.normalScale.copy( source.normalScale );
  14660. this.displacementMap = source.displacementMap;
  14661. this.displacementScale = source.displacementScale;
  14662. this.displacementBias = source.displacementBias;
  14663. this.alphaMap = source.alphaMap;
  14664. this.wireframe = source.wireframe;
  14665. this.wireframeLinewidth = source.wireframeLinewidth;
  14666. this.wireframeLinecap = source.wireframeLinecap;
  14667. this.wireframeLinejoin = source.wireframeLinejoin;
  14668. this.fog = source.fog;
  14669. return this;
  14670. }
  14671. }
  14672. class MeshNormalMaterial extends Material {
  14673. constructor( parameters ) {
  14674. super();
  14675. this.isMeshNormalMaterial = true;
  14676. this.type = 'MeshNormalMaterial';
  14677. this.bumpMap = null;
  14678. this.bumpScale = 1;
  14679. this.normalMap = null;
  14680. this.normalMapType = TangentSpaceNormalMap;
  14681. this.normalScale = new Vector2( 1, 1 );
  14682. this.displacementMap = null;
  14683. this.displacementScale = 1;
  14684. this.displacementBias = 0;
  14685. this.wireframe = false;
  14686. this.wireframeLinewidth = 1;
  14687. this.flatShading = false;
  14688. this.setValues( parameters );
  14689. }
  14690. copy( source ) {
  14691. super.copy( source );
  14692. this.bumpMap = source.bumpMap;
  14693. this.bumpScale = source.bumpScale;
  14694. this.normalMap = source.normalMap;
  14695. this.normalMapType = source.normalMapType;
  14696. this.normalScale.copy( source.normalScale );
  14697. this.displacementMap = source.displacementMap;
  14698. this.displacementScale = source.displacementScale;
  14699. this.displacementBias = source.displacementBias;
  14700. this.wireframe = source.wireframe;
  14701. this.wireframeLinewidth = source.wireframeLinewidth;
  14702. this.flatShading = source.flatShading;
  14703. return this;
  14704. }
  14705. }
  14706. class MeshLambertMaterial extends Material {
  14707. constructor( parameters ) {
  14708. super();
  14709. this.isMeshLambertMaterial = true;
  14710. this.type = 'MeshLambertMaterial';
  14711. this.color = new Color( 0xffffff ); // diffuse
  14712. this.map = null;
  14713. this.lightMap = null;
  14714. this.lightMapIntensity = 1.0;
  14715. this.aoMap = null;
  14716. this.aoMapIntensity = 1.0;
  14717. this.emissive = new Color( 0x000000 );
  14718. this.emissiveIntensity = 1.0;
  14719. this.emissiveMap = null;
  14720. this.bumpMap = null;
  14721. this.bumpScale = 1;
  14722. this.normalMap = null;
  14723. this.normalMapType = TangentSpaceNormalMap;
  14724. this.normalScale = new Vector2( 1, 1 );
  14725. this.displacementMap = null;
  14726. this.displacementScale = 1;
  14727. this.displacementBias = 0;
  14728. this.specularMap = null;
  14729. this.alphaMap = null;
  14730. this.envMap = null;
  14731. this.envMapRotation = new Euler();
  14732. this.combine = MultiplyOperation;
  14733. this.reflectivity = 1;
  14734. this.refractionRatio = 0.98;
  14735. this.wireframe = false;
  14736. this.wireframeLinewidth = 1;
  14737. this.wireframeLinecap = 'round';
  14738. this.wireframeLinejoin = 'round';
  14739. this.flatShading = false;
  14740. this.fog = true;
  14741. this.setValues( parameters );
  14742. }
  14743. copy( source ) {
  14744. super.copy( source );
  14745. this.color.copy( source.color );
  14746. this.map = source.map;
  14747. this.lightMap = source.lightMap;
  14748. this.lightMapIntensity = source.lightMapIntensity;
  14749. this.aoMap = source.aoMap;
  14750. this.aoMapIntensity = source.aoMapIntensity;
  14751. this.emissive.copy( source.emissive );
  14752. this.emissiveMap = source.emissiveMap;
  14753. this.emissiveIntensity = source.emissiveIntensity;
  14754. this.bumpMap = source.bumpMap;
  14755. this.bumpScale = source.bumpScale;
  14756. this.normalMap = source.normalMap;
  14757. this.normalMapType = source.normalMapType;
  14758. this.normalScale.copy( source.normalScale );
  14759. this.displacementMap = source.displacementMap;
  14760. this.displacementScale = source.displacementScale;
  14761. this.displacementBias = source.displacementBias;
  14762. this.specularMap = source.specularMap;
  14763. this.alphaMap = source.alphaMap;
  14764. this.envMap = source.envMap;
  14765. this.envMapRotation.copy( source.envMapRotation );
  14766. this.combine = source.combine;
  14767. this.reflectivity = source.reflectivity;
  14768. this.refractionRatio = source.refractionRatio;
  14769. this.wireframe = source.wireframe;
  14770. this.wireframeLinewidth = source.wireframeLinewidth;
  14771. this.wireframeLinecap = source.wireframeLinecap;
  14772. this.wireframeLinejoin = source.wireframeLinejoin;
  14773. this.flatShading = source.flatShading;
  14774. this.fog = source.fog;
  14775. return this;
  14776. }
  14777. }
  14778. class MeshDepthMaterial extends Material {
  14779. constructor( parameters ) {
  14780. super();
  14781. this.isMeshDepthMaterial = true;
  14782. this.type = 'MeshDepthMaterial';
  14783. this.depthPacking = BasicDepthPacking;
  14784. this.map = null;
  14785. this.alphaMap = null;
  14786. this.displacementMap = null;
  14787. this.displacementScale = 1;
  14788. this.displacementBias = 0;
  14789. this.wireframe = false;
  14790. this.wireframeLinewidth = 1;
  14791. this.setValues( parameters );
  14792. }
  14793. copy( source ) {
  14794. super.copy( source );
  14795. this.depthPacking = source.depthPacking;
  14796. this.map = source.map;
  14797. this.alphaMap = source.alphaMap;
  14798. this.displacementMap = source.displacementMap;
  14799. this.displacementScale = source.displacementScale;
  14800. this.displacementBias = source.displacementBias;
  14801. this.wireframe = source.wireframe;
  14802. this.wireframeLinewidth = source.wireframeLinewidth;
  14803. return this;
  14804. }
  14805. }
  14806. class MeshDistanceMaterial extends Material {
  14807. constructor( parameters ) {
  14808. super();
  14809. this.isMeshDistanceMaterial = true;
  14810. this.type = 'MeshDistanceMaterial';
  14811. this.map = null;
  14812. this.alphaMap = null;
  14813. this.displacementMap = null;
  14814. this.displacementScale = 1;
  14815. this.displacementBias = 0;
  14816. this.setValues( parameters );
  14817. }
  14818. copy( source ) {
  14819. super.copy( source );
  14820. this.map = source.map;
  14821. this.alphaMap = source.alphaMap;
  14822. this.displacementMap = source.displacementMap;
  14823. this.displacementScale = source.displacementScale;
  14824. this.displacementBias = source.displacementBias;
  14825. return this;
  14826. }
  14827. }
  14828. class MeshMatcapMaterial extends Material {
  14829. constructor( parameters ) {
  14830. super();
  14831. this.isMeshMatcapMaterial = true;
  14832. this.defines = { 'MATCAP': '' };
  14833. this.type = 'MeshMatcapMaterial';
  14834. this.color = new Color( 0xffffff ); // diffuse
  14835. this.matcap = null;
  14836. this.map = null;
  14837. this.bumpMap = null;
  14838. this.bumpScale = 1;
  14839. this.normalMap = null;
  14840. this.normalMapType = TangentSpaceNormalMap;
  14841. this.normalScale = new Vector2( 1, 1 );
  14842. this.displacementMap = null;
  14843. this.displacementScale = 1;
  14844. this.displacementBias = 0;
  14845. this.alphaMap = null;
  14846. this.flatShading = false;
  14847. this.fog = true;
  14848. this.setValues( parameters );
  14849. }
  14850. copy( source ) {
  14851. super.copy( source );
  14852. this.defines = { 'MATCAP': '' };
  14853. this.color.copy( source.color );
  14854. this.matcap = source.matcap;
  14855. this.map = source.map;
  14856. this.bumpMap = source.bumpMap;
  14857. this.bumpScale = source.bumpScale;
  14858. this.normalMap = source.normalMap;
  14859. this.normalMapType = source.normalMapType;
  14860. this.normalScale.copy( source.normalScale );
  14861. this.displacementMap = source.displacementMap;
  14862. this.displacementScale = source.displacementScale;
  14863. this.displacementBias = source.displacementBias;
  14864. this.alphaMap = source.alphaMap;
  14865. this.flatShading = source.flatShading;
  14866. this.fog = source.fog;
  14867. return this;
  14868. }
  14869. }
  14870. class LineDashedMaterial extends LineBasicMaterial {
  14871. constructor( parameters ) {
  14872. super();
  14873. this.isLineDashedMaterial = true;
  14874. this.type = 'LineDashedMaterial';
  14875. this.scale = 1;
  14876. this.dashSize = 3;
  14877. this.gapSize = 1;
  14878. this.setValues( parameters );
  14879. }
  14880. copy( source ) {
  14881. super.copy( source );
  14882. this.scale = source.scale;
  14883. this.dashSize = source.dashSize;
  14884. this.gapSize = source.gapSize;
  14885. return this;
  14886. }
  14887. }
  14888. // converts an array to a specific type
  14889. function convertArray( array, type, forceClone ) {
  14890. if ( ! array || // let 'undefined' and 'null' pass
  14891. ! forceClone && array.constructor === type ) return array;
  14892. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  14893. return new type( array ); // create typed array
  14894. }
  14895. return Array.prototype.slice.call( array ); // create Array
  14896. }
  14897. function isTypedArray( object ) {
  14898. return ArrayBuffer.isView( object ) &&
  14899. ! ( object instanceof DataView );
  14900. }
  14901. // returns an array by which times and values can be sorted
  14902. function getKeyframeOrder( times ) {
  14903. function compareTime( i, j ) {
  14904. return times[ i ] - times[ j ];
  14905. }
  14906. const n = times.length;
  14907. const result = new Array( n );
  14908. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  14909. result.sort( compareTime );
  14910. return result;
  14911. }
  14912. // uses the array previously returned by 'getKeyframeOrder' to sort data
  14913. function sortedArray( values, stride, order ) {
  14914. const nValues = values.length;
  14915. const result = new values.constructor( nValues );
  14916. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  14917. const srcOffset = order[ i ] * stride;
  14918. for ( let j = 0; j !== stride; ++ j ) {
  14919. result[ dstOffset ++ ] = values[ srcOffset + j ];
  14920. }
  14921. }
  14922. return result;
  14923. }
  14924. // function for parsing AOS keyframe formats
  14925. function flattenJSON( jsonKeys, times, values, valuePropertyName ) {
  14926. let i = 1, key = jsonKeys[ 0 ];
  14927. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  14928. key = jsonKeys[ i ++ ];
  14929. }
  14930. if ( key === undefined ) return; // no data
  14931. let value = key[ valuePropertyName ];
  14932. if ( value === undefined ) return; // no data
  14933. if ( Array.isArray( value ) ) {
  14934. do {
  14935. value = key[ valuePropertyName ];
  14936. if ( value !== undefined ) {
  14937. times.push( key.time );
  14938. values.push.apply( values, value ); // push all elements
  14939. }
  14940. key = jsonKeys[ i ++ ];
  14941. } while ( key !== undefined );
  14942. } else if ( value.toArray !== undefined ) {
  14943. // ...assume THREE.Math-ish
  14944. do {
  14945. value = key[ valuePropertyName ];
  14946. if ( value !== undefined ) {
  14947. times.push( key.time );
  14948. value.toArray( values, values.length );
  14949. }
  14950. key = jsonKeys[ i ++ ];
  14951. } while ( key !== undefined );
  14952. } else {
  14953. // otherwise push as-is
  14954. do {
  14955. value = key[ valuePropertyName ];
  14956. if ( value !== undefined ) {
  14957. times.push( key.time );
  14958. values.push( value );
  14959. }
  14960. key = jsonKeys[ i ++ ];
  14961. } while ( key !== undefined );
  14962. }
  14963. }
  14964. function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  14965. const clip = sourceClip.clone();
  14966. clip.name = name;
  14967. const tracks = [];
  14968. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14969. const track = clip.tracks[ i ];
  14970. const valueSize = track.getValueSize();
  14971. const times = [];
  14972. const values = [];
  14973. for ( let j = 0; j < track.times.length; ++ j ) {
  14974. const frame = track.times[ j ] * fps;
  14975. if ( frame < startFrame || frame >= endFrame ) continue;
  14976. times.push( track.times[ j ] );
  14977. for ( let k = 0; k < valueSize; ++ k ) {
  14978. values.push( track.values[ j * valueSize + k ] );
  14979. }
  14980. }
  14981. if ( times.length === 0 ) continue;
  14982. track.times = convertArray( times, track.times.constructor );
  14983. track.values = convertArray( values, track.values.constructor );
  14984. tracks.push( track );
  14985. }
  14986. clip.tracks = tracks;
  14987. // find minimum .times value across all tracks in the trimmed clip
  14988. let minStartTime = Infinity;
  14989. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14990. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  14991. minStartTime = clip.tracks[ i ].times[ 0 ];
  14992. }
  14993. }
  14994. // shift all tracks such that clip begins at t=0
  14995. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14996. clip.tracks[ i ].shift( -1 * minStartTime );
  14997. }
  14998. clip.resetDuration();
  14999. return clip;
  15000. }
  15001. function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  15002. if ( fps <= 0 ) fps = 30;
  15003. const numTracks = referenceClip.tracks.length;
  15004. const referenceTime = referenceFrame / fps;
  15005. // Make each track's values relative to the values at the reference frame
  15006. for ( let i = 0; i < numTracks; ++ i ) {
  15007. const referenceTrack = referenceClip.tracks[ i ];
  15008. const referenceTrackType = referenceTrack.ValueTypeName;
  15009. // Skip this track if it's non-numeric
  15010. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  15011. // Find the track in the target clip whose name and type matches the reference track
  15012. const targetTrack = targetClip.tracks.find( function ( track ) {
  15013. return track.name === referenceTrack.name
  15014. && track.ValueTypeName === referenceTrackType;
  15015. } );
  15016. if ( targetTrack === undefined ) continue;
  15017. let referenceOffset = 0;
  15018. const referenceValueSize = referenceTrack.getValueSize();
  15019. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  15020. referenceOffset = referenceValueSize / 3;
  15021. }
  15022. let targetOffset = 0;
  15023. const targetValueSize = targetTrack.getValueSize();
  15024. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  15025. targetOffset = targetValueSize / 3;
  15026. }
  15027. const lastIndex = referenceTrack.times.length - 1;
  15028. let referenceValue;
  15029. // Find the value to subtract out of the track
  15030. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  15031. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  15032. const startIndex = referenceOffset;
  15033. const endIndex = referenceValueSize - referenceOffset;
  15034. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  15035. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  15036. // Reference frame is after the last keyframe, so just use the last keyframe
  15037. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  15038. const endIndex = startIndex + referenceValueSize - referenceOffset;
  15039. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  15040. } else {
  15041. // Interpolate to the reference value
  15042. const interpolant = referenceTrack.createInterpolant();
  15043. const startIndex = referenceOffset;
  15044. const endIndex = referenceValueSize - referenceOffset;
  15045. interpolant.evaluate( referenceTime );
  15046. referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );
  15047. }
  15048. // Conjugate the quaternion
  15049. if ( referenceTrackType === 'quaternion' ) {
  15050. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  15051. referenceQuat.toArray( referenceValue );
  15052. }
  15053. // Subtract the reference value from all of the track values
  15054. const numTimes = targetTrack.times.length;
  15055. for ( let j = 0; j < numTimes; ++ j ) {
  15056. const valueStart = j * targetValueSize + targetOffset;
  15057. if ( referenceTrackType === 'quaternion' ) {
  15058. // Multiply the conjugate for quaternion track types
  15059. Quaternion.multiplyQuaternionsFlat(
  15060. targetTrack.values,
  15061. valueStart,
  15062. referenceValue,
  15063. 0,
  15064. targetTrack.values,
  15065. valueStart
  15066. );
  15067. } else {
  15068. const valueEnd = targetValueSize - targetOffset * 2;
  15069. // Subtract each value for all other numeric track types
  15070. for ( let k = 0; k < valueEnd; ++ k ) {
  15071. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  15072. }
  15073. }
  15074. }
  15075. }
  15076. targetClip.blendMode = AdditiveAnimationBlendMode;
  15077. return targetClip;
  15078. }
  15079. const AnimationUtils = {
  15080. convertArray: convertArray,
  15081. isTypedArray: isTypedArray,
  15082. getKeyframeOrder: getKeyframeOrder,
  15083. sortedArray: sortedArray,
  15084. flattenJSON: flattenJSON,
  15085. subclip: subclip,
  15086. makeClipAdditive: makeClipAdditive
  15087. };
  15088. /**
  15089. * Abstract base class of interpolants over parametric samples.
  15090. *
  15091. * The parameter domain is one dimensional, typically the time or a path
  15092. * along a curve defined by the data.
  15093. *
  15094. * The sample values can have any dimensionality and derived classes may
  15095. * apply special interpretations to the data.
  15096. *
  15097. * This class provides the interval seek in a Template Method, deferring
  15098. * the actual interpolation to derived classes.
  15099. *
  15100. * Time complexity is O(1) for linear access crossing at most two points
  15101. * and O(log N) for random access, where N is the number of positions.
  15102. *
  15103. * References:
  15104. *
  15105. * http://www.oodesign.com/template-method-pattern.html
  15106. *
  15107. */
  15108. class Interpolant {
  15109. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15110. this.parameterPositions = parameterPositions;
  15111. this._cachedIndex = 0;
  15112. this.resultBuffer = resultBuffer !== undefined ?
  15113. resultBuffer : new sampleValues.constructor( sampleSize );
  15114. this.sampleValues = sampleValues;
  15115. this.valueSize = sampleSize;
  15116. this.settings = null;
  15117. this.DefaultSettings_ = {};
  15118. }
  15119. evaluate( t ) {
  15120. const pp = this.parameterPositions;
  15121. let i1 = this._cachedIndex,
  15122. t1 = pp[ i1 ],
  15123. t0 = pp[ i1 - 1 ];
  15124. validate_interval: {
  15125. seek: {
  15126. let right;
  15127. linear_scan: {
  15128. //- See http://jsperf.com/comparison-to-undefined/3
  15129. //- slower code:
  15130. //-
  15131. //- if ( t >= t1 || t1 === undefined ) {
  15132. forward_scan: if ( ! ( t < t1 ) ) {
  15133. for ( let giveUpAt = i1 + 2; ; ) {
  15134. if ( t1 === undefined ) {
  15135. if ( t < t0 ) break forward_scan;
  15136. // after end
  15137. i1 = pp.length;
  15138. this._cachedIndex = i1;
  15139. return this.copySampleValue_( i1 - 1 );
  15140. }
  15141. if ( i1 === giveUpAt ) break; // this loop
  15142. t0 = t1;
  15143. t1 = pp[ ++ i1 ];
  15144. if ( t < t1 ) {
  15145. // we have arrived at the sought interval
  15146. break seek;
  15147. }
  15148. }
  15149. // prepare binary search on the right side of the index
  15150. right = pp.length;
  15151. break linear_scan;
  15152. }
  15153. //- slower code:
  15154. //- if ( t < t0 || t0 === undefined ) {
  15155. if ( ! ( t >= t0 ) ) {
  15156. // looping?
  15157. const t1global = pp[ 1 ];
  15158. if ( t < t1global ) {
  15159. i1 = 2; // + 1, using the scan for the details
  15160. t0 = t1global;
  15161. }
  15162. // linear reverse scan
  15163. for ( let giveUpAt = i1 - 2; ; ) {
  15164. if ( t0 === undefined ) {
  15165. // before start
  15166. this._cachedIndex = 0;
  15167. return this.copySampleValue_( 0 );
  15168. }
  15169. if ( i1 === giveUpAt ) break; // this loop
  15170. t1 = t0;
  15171. t0 = pp[ -- i1 - 1 ];
  15172. if ( t >= t0 ) {
  15173. // we have arrived at the sought interval
  15174. break seek;
  15175. }
  15176. }
  15177. // prepare binary search on the left side of the index
  15178. right = i1;
  15179. i1 = 0;
  15180. break linear_scan;
  15181. }
  15182. // the interval is valid
  15183. break validate_interval;
  15184. } // linear scan
  15185. // binary search
  15186. while ( i1 < right ) {
  15187. const mid = ( i1 + right ) >>> 1;
  15188. if ( t < pp[ mid ] ) {
  15189. right = mid;
  15190. } else {
  15191. i1 = mid + 1;
  15192. }
  15193. }
  15194. t1 = pp[ i1 ];
  15195. t0 = pp[ i1 - 1 ];
  15196. // check boundary cases, again
  15197. if ( t0 === undefined ) {
  15198. this._cachedIndex = 0;
  15199. return this.copySampleValue_( 0 );
  15200. }
  15201. if ( t1 === undefined ) {
  15202. i1 = pp.length;
  15203. this._cachedIndex = i1;
  15204. return this.copySampleValue_( i1 - 1 );
  15205. }
  15206. } // seek
  15207. this._cachedIndex = i1;
  15208. this.intervalChanged_( i1, t0, t1 );
  15209. } // validate_interval
  15210. return this.interpolate_( i1, t0, t, t1 );
  15211. }
  15212. getSettings_() {
  15213. return this.settings || this.DefaultSettings_;
  15214. }
  15215. copySampleValue_( index ) {
  15216. // copies a sample value to the result buffer
  15217. const result = this.resultBuffer,
  15218. values = this.sampleValues,
  15219. stride = this.valueSize,
  15220. offset = index * stride;
  15221. for ( let i = 0; i !== stride; ++ i ) {
  15222. result[ i ] = values[ offset + i ];
  15223. }
  15224. return result;
  15225. }
  15226. // Template methods for derived classes:
  15227. interpolate_( /* i1, t0, t, t1 */ ) {
  15228. throw new Error( 'call to abstract method' );
  15229. // implementations shall return this.resultBuffer
  15230. }
  15231. intervalChanged_( /* i1, t0, t1 */ ) {
  15232. // empty
  15233. }
  15234. }
  15235. /**
  15236. * Fast and simple cubic spline interpolant.
  15237. *
  15238. * It was derived from a Hermitian construction setting the first derivative
  15239. * at each sample position to the linear slope between neighboring positions
  15240. * over their parameter interval.
  15241. */
  15242. class CubicInterpolant extends Interpolant {
  15243. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15244. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15245. this._weightPrev = -0;
  15246. this._offsetPrev = -0;
  15247. this._weightNext = -0;
  15248. this._offsetNext = -0;
  15249. this.DefaultSettings_ = {
  15250. endingStart: ZeroCurvatureEnding,
  15251. endingEnd: ZeroCurvatureEnding
  15252. };
  15253. }
  15254. intervalChanged_( i1, t0, t1 ) {
  15255. const pp = this.parameterPositions;
  15256. let iPrev = i1 - 2,
  15257. iNext = i1 + 1,
  15258. tPrev = pp[ iPrev ],
  15259. tNext = pp[ iNext ];
  15260. if ( tPrev === undefined ) {
  15261. switch ( this.getSettings_().endingStart ) {
  15262. case ZeroSlopeEnding:
  15263. // f'(t0) = 0
  15264. iPrev = i1;
  15265. tPrev = 2 * t0 - t1;
  15266. break;
  15267. case WrapAroundEnding:
  15268. // use the other end of the curve
  15269. iPrev = pp.length - 2;
  15270. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  15271. break;
  15272. default: // ZeroCurvatureEnding
  15273. // f''(t0) = 0 a.k.a. Natural Spline
  15274. iPrev = i1;
  15275. tPrev = t1;
  15276. }
  15277. }
  15278. if ( tNext === undefined ) {
  15279. switch ( this.getSettings_().endingEnd ) {
  15280. case ZeroSlopeEnding:
  15281. // f'(tN) = 0
  15282. iNext = i1;
  15283. tNext = 2 * t1 - t0;
  15284. break;
  15285. case WrapAroundEnding:
  15286. // use the other end of the curve
  15287. iNext = 1;
  15288. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  15289. break;
  15290. default: // ZeroCurvatureEnding
  15291. // f''(tN) = 0, a.k.a. Natural Spline
  15292. iNext = i1 - 1;
  15293. tNext = t0;
  15294. }
  15295. }
  15296. const halfDt = ( t1 - t0 ) * 0.5,
  15297. stride = this.valueSize;
  15298. this._weightPrev = halfDt / ( t0 - tPrev );
  15299. this._weightNext = halfDt / ( tNext - t1 );
  15300. this._offsetPrev = iPrev * stride;
  15301. this._offsetNext = iNext * stride;
  15302. }
  15303. interpolate_( i1, t0, t, t1 ) {
  15304. const result = this.resultBuffer,
  15305. values = this.sampleValues,
  15306. stride = this.valueSize,
  15307. o1 = i1 * stride, o0 = o1 - stride,
  15308. oP = this._offsetPrev, oN = this._offsetNext,
  15309. wP = this._weightPrev, wN = this._weightNext,
  15310. p = ( t - t0 ) / ( t1 - t0 ),
  15311. pp = p * p,
  15312. ppp = pp * p;
  15313. // evaluate polynomials
  15314. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  15315. const s0 = ( 1 + wP ) * ppp + ( -1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  15316. const s1 = ( -1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  15317. const sN = wN * ppp - wN * pp;
  15318. // combine data linearly
  15319. for ( let i = 0; i !== stride; ++ i ) {
  15320. result[ i ] =
  15321. sP * values[ oP + i ] +
  15322. s0 * values[ o0 + i ] +
  15323. s1 * values[ o1 + i ] +
  15324. sN * values[ oN + i ];
  15325. }
  15326. return result;
  15327. }
  15328. }
  15329. class LinearInterpolant extends Interpolant {
  15330. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15331. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15332. }
  15333. interpolate_( i1, t0, t, t1 ) {
  15334. const result = this.resultBuffer,
  15335. values = this.sampleValues,
  15336. stride = this.valueSize,
  15337. offset1 = i1 * stride,
  15338. offset0 = offset1 - stride,
  15339. weight1 = ( t - t0 ) / ( t1 - t0 ),
  15340. weight0 = 1 - weight1;
  15341. for ( let i = 0; i !== stride; ++ i ) {
  15342. result[ i ] =
  15343. values[ offset0 + i ] * weight0 +
  15344. values[ offset1 + i ] * weight1;
  15345. }
  15346. return result;
  15347. }
  15348. }
  15349. /**
  15350. *
  15351. * Interpolant that evaluates to the sample value at the position preceding
  15352. * the parameter.
  15353. */
  15354. class DiscreteInterpolant extends Interpolant {
  15355. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15356. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15357. }
  15358. interpolate_( i1 /*, t0, t, t1 */ ) {
  15359. return this.copySampleValue_( i1 - 1 );
  15360. }
  15361. }
  15362. class KeyframeTrack {
  15363. constructor( name, times, values, interpolation ) {
  15364. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  15365. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  15366. this.name = name;
  15367. this.times = convertArray( times, this.TimeBufferType );
  15368. this.values = convertArray( values, this.ValueBufferType );
  15369. this.setInterpolation( interpolation || this.DefaultInterpolation );
  15370. }
  15371. // Serialization (in static context, because of constructor invocation
  15372. // and automatic invocation of .toJSON):
  15373. static toJSON( track ) {
  15374. const trackType = track.constructor;
  15375. let json;
  15376. // derived classes can define a static toJSON method
  15377. if ( trackType.toJSON !== this.toJSON ) {
  15378. json = trackType.toJSON( track );
  15379. } else {
  15380. // by default, we assume the data can be serialized as-is
  15381. json = {
  15382. 'name': track.name,
  15383. 'times': convertArray( track.times, Array ),
  15384. 'values': convertArray( track.values, Array )
  15385. };
  15386. const interpolation = track.getInterpolation();
  15387. if ( interpolation !== track.DefaultInterpolation ) {
  15388. json.interpolation = interpolation;
  15389. }
  15390. }
  15391. json.type = track.ValueTypeName; // mandatory
  15392. return json;
  15393. }
  15394. InterpolantFactoryMethodDiscrete( result ) {
  15395. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  15396. }
  15397. InterpolantFactoryMethodLinear( result ) {
  15398. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15399. }
  15400. InterpolantFactoryMethodSmooth( result ) {
  15401. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  15402. }
  15403. setInterpolation( interpolation ) {
  15404. let factoryMethod;
  15405. switch ( interpolation ) {
  15406. case InterpolateDiscrete:
  15407. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  15408. break;
  15409. case InterpolateLinear:
  15410. factoryMethod = this.InterpolantFactoryMethodLinear;
  15411. break;
  15412. case InterpolateSmooth:
  15413. factoryMethod = this.InterpolantFactoryMethodSmooth;
  15414. break;
  15415. }
  15416. if ( factoryMethod === undefined ) {
  15417. const message = 'unsupported interpolation for ' +
  15418. this.ValueTypeName + ' keyframe track named ' + this.name;
  15419. if ( this.createInterpolant === undefined ) {
  15420. // fall back to default, unless the default itself is messed up
  15421. if ( interpolation !== this.DefaultInterpolation ) {
  15422. this.setInterpolation( this.DefaultInterpolation );
  15423. } else {
  15424. throw new Error( message ); // fatal, in this case
  15425. }
  15426. }
  15427. console.warn( 'THREE.KeyframeTrack:', message );
  15428. return this;
  15429. }
  15430. this.createInterpolant = factoryMethod;
  15431. return this;
  15432. }
  15433. getInterpolation() {
  15434. switch ( this.createInterpolant ) {
  15435. case this.InterpolantFactoryMethodDiscrete:
  15436. return InterpolateDiscrete;
  15437. case this.InterpolantFactoryMethodLinear:
  15438. return InterpolateLinear;
  15439. case this.InterpolantFactoryMethodSmooth:
  15440. return InterpolateSmooth;
  15441. }
  15442. }
  15443. getValueSize() {
  15444. return this.values.length / this.times.length;
  15445. }
  15446. // move all keyframes either forwards or backwards in time
  15447. shift( timeOffset ) {
  15448. if ( timeOffset !== 0.0 ) {
  15449. const times = this.times;
  15450. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15451. times[ i ] += timeOffset;
  15452. }
  15453. }
  15454. return this;
  15455. }
  15456. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  15457. scale( timeScale ) {
  15458. if ( timeScale !== 1.0 ) {
  15459. const times = this.times;
  15460. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15461. times[ i ] *= timeScale;
  15462. }
  15463. }
  15464. return this;
  15465. }
  15466. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  15467. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  15468. trim( startTime, endTime ) {
  15469. const times = this.times,
  15470. nKeys = times.length;
  15471. let from = 0,
  15472. to = nKeys - 1;
  15473. while ( from !== nKeys && times[ from ] < startTime ) {
  15474. ++ from;
  15475. }
  15476. while ( to !== -1 && times[ to ] > endTime ) {
  15477. -- to;
  15478. }
  15479. ++ to; // inclusive -> exclusive bound
  15480. if ( from !== 0 || to !== nKeys ) {
  15481. // empty tracks are forbidden, so keep at least one keyframe
  15482. if ( from >= to ) {
  15483. to = Math.max( to, 1 );
  15484. from = to - 1;
  15485. }
  15486. const stride = this.getValueSize();
  15487. this.times = times.slice( from, to );
  15488. this.values = this.values.slice( from * stride, to * stride );
  15489. }
  15490. return this;
  15491. }
  15492. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  15493. validate() {
  15494. let valid = true;
  15495. const valueSize = this.getValueSize();
  15496. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  15497. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  15498. valid = false;
  15499. }
  15500. const times = this.times,
  15501. values = this.values,
  15502. nKeys = times.length;
  15503. if ( nKeys === 0 ) {
  15504. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  15505. valid = false;
  15506. }
  15507. let prevTime = null;
  15508. for ( let i = 0; i !== nKeys; i ++ ) {
  15509. const currTime = times[ i ];
  15510. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  15511. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  15512. valid = false;
  15513. break;
  15514. }
  15515. if ( prevTime !== null && prevTime > currTime ) {
  15516. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  15517. valid = false;
  15518. break;
  15519. }
  15520. prevTime = currTime;
  15521. }
  15522. if ( values !== undefined ) {
  15523. if ( isTypedArray( values ) ) {
  15524. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  15525. const value = values[ i ];
  15526. if ( isNaN( value ) ) {
  15527. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  15528. valid = false;
  15529. break;
  15530. }
  15531. }
  15532. }
  15533. }
  15534. return valid;
  15535. }
  15536. // removes equivalent sequential keys as common in morph target sequences
  15537. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  15538. optimize() {
  15539. // times or values may be shared with other tracks, so overwriting is unsafe
  15540. const times = this.times.slice(),
  15541. values = this.values.slice(),
  15542. stride = this.getValueSize(),
  15543. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  15544. lastIndex = times.length - 1;
  15545. let writeIndex = 1;
  15546. for ( let i = 1; i < lastIndex; ++ i ) {
  15547. let keep = false;
  15548. const time = times[ i ];
  15549. const timeNext = times[ i + 1 ];
  15550. // remove adjacent keyframes scheduled at the same time
  15551. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  15552. if ( ! smoothInterpolation ) {
  15553. // remove unnecessary keyframes same as their neighbors
  15554. const offset = i * stride,
  15555. offsetP = offset - stride,
  15556. offsetN = offset + stride;
  15557. for ( let j = 0; j !== stride; ++ j ) {
  15558. const value = values[ offset + j ];
  15559. if ( value !== values[ offsetP + j ] ||
  15560. value !== values[ offsetN + j ] ) {
  15561. keep = true;
  15562. break;
  15563. }
  15564. }
  15565. } else {
  15566. keep = true;
  15567. }
  15568. }
  15569. // in-place compaction
  15570. if ( keep ) {
  15571. if ( i !== writeIndex ) {
  15572. times[ writeIndex ] = times[ i ];
  15573. const readOffset = i * stride,
  15574. writeOffset = writeIndex * stride;
  15575. for ( let j = 0; j !== stride; ++ j ) {
  15576. values[ writeOffset + j ] = values[ readOffset + j ];
  15577. }
  15578. }
  15579. ++ writeIndex;
  15580. }
  15581. }
  15582. // flush last keyframe (compaction looks ahead)
  15583. if ( lastIndex > 0 ) {
  15584. times[ writeIndex ] = times[ lastIndex ];
  15585. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  15586. values[ writeOffset + j ] = values[ readOffset + j ];
  15587. }
  15588. ++ writeIndex;
  15589. }
  15590. if ( writeIndex !== times.length ) {
  15591. this.times = times.slice( 0, writeIndex );
  15592. this.values = values.slice( 0, writeIndex * stride );
  15593. } else {
  15594. this.times = times;
  15595. this.values = values;
  15596. }
  15597. return this;
  15598. }
  15599. clone() {
  15600. const times = this.times.slice();
  15601. const values = this.values.slice();
  15602. const TypedKeyframeTrack = this.constructor;
  15603. const track = new TypedKeyframeTrack( this.name, times, values );
  15604. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  15605. track.createInterpolant = this.createInterpolant;
  15606. return track;
  15607. }
  15608. }
  15609. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  15610. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  15611. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  15612. /**
  15613. * A Track of Boolean keyframe values.
  15614. */
  15615. class BooleanKeyframeTrack extends KeyframeTrack {
  15616. // No interpolation parameter because only InterpolateDiscrete is valid.
  15617. constructor( name, times, values ) {
  15618. super( name, times, values );
  15619. }
  15620. }
  15621. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  15622. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  15623. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15624. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15625. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15626. /**
  15627. * A Track of keyframe values that represent color.
  15628. */
  15629. class ColorKeyframeTrack extends KeyframeTrack {}
  15630. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  15631. /**
  15632. * A Track of numeric keyframe values.
  15633. */
  15634. class NumberKeyframeTrack extends KeyframeTrack {}
  15635. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  15636. /**
  15637. * Spherical linear unit quaternion interpolant.
  15638. */
  15639. class QuaternionLinearInterpolant extends Interpolant {
  15640. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15641. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15642. }
  15643. interpolate_( i1, t0, t, t1 ) {
  15644. const result = this.resultBuffer,
  15645. values = this.sampleValues,
  15646. stride = this.valueSize,
  15647. alpha = ( t - t0 ) / ( t1 - t0 );
  15648. let offset = i1 * stride;
  15649. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  15650. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  15651. }
  15652. return result;
  15653. }
  15654. }
  15655. /**
  15656. * A Track of quaternion keyframe values.
  15657. */
  15658. class QuaternionKeyframeTrack extends KeyframeTrack {
  15659. InterpolantFactoryMethodLinear( result ) {
  15660. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15661. }
  15662. }
  15663. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  15664. // ValueBufferType is inherited
  15665. // DefaultInterpolation is inherited;
  15666. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15667. /**
  15668. * A Track that interpolates Strings
  15669. */
  15670. class StringKeyframeTrack extends KeyframeTrack {
  15671. // No interpolation parameter because only InterpolateDiscrete is valid.
  15672. constructor( name, times, values ) {
  15673. super( name, times, values );
  15674. }
  15675. }
  15676. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  15677. StringKeyframeTrack.prototype.ValueBufferType = Array;
  15678. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15679. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15680. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15681. /**
  15682. * A Track of vectored keyframe values.
  15683. */
  15684. class VectorKeyframeTrack extends KeyframeTrack {}
  15685. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  15686. class AnimationClip {
  15687. constructor( name = '', duration = -1, tracks = [], blendMode = NormalAnimationBlendMode ) {
  15688. this.name = name;
  15689. this.tracks = tracks;
  15690. this.duration = duration;
  15691. this.blendMode = blendMode;
  15692. this.uuid = generateUUID();
  15693. // this means it should figure out its duration by scanning the tracks
  15694. if ( this.duration < 0 ) {
  15695. this.resetDuration();
  15696. }
  15697. }
  15698. static parse( json ) {
  15699. const tracks = [],
  15700. jsonTracks = json.tracks,
  15701. frameTime = 1.0 / ( json.fps || 1.0 );
  15702. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  15703. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  15704. }
  15705. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  15706. clip.uuid = json.uuid;
  15707. return clip;
  15708. }
  15709. static toJSON( clip ) {
  15710. const tracks = [],
  15711. clipTracks = clip.tracks;
  15712. const json = {
  15713. 'name': clip.name,
  15714. 'duration': clip.duration,
  15715. 'tracks': tracks,
  15716. 'uuid': clip.uuid,
  15717. 'blendMode': clip.blendMode
  15718. };
  15719. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  15720. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  15721. }
  15722. return json;
  15723. }
  15724. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  15725. const numMorphTargets = morphTargetSequence.length;
  15726. const tracks = [];
  15727. for ( let i = 0; i < numMorphTargets; i ++ ) {
  15728. let times = [];
  15729. let values = [];
  15730. times.push(
  15731. ( i + numMorphTargets - 1 ) % numMorphTargets,
  15732. i,
  15733. ( i + 1 ) % numMorphTargets );
  15734. values.push( 0, 1, 0 );
  15735. const order = getKeyframeOrder( times );
  15736. times = sortedArray( times, 1, order );
  15737. values = sortedArray( values, 1, order );
  15738. // if there is a key at the first frame, duplicate it as the
  15739. // last frame as well for perfect loop.
  15740. if ( ! noLoop && times[ 0 ] === 0 ) {
  15741. times.push( numMorphTargets );
  15742. values.push( values[ 0 ] );
  15743. }
  15744. tracks.push(
  15745. new NumberKeyframeTrack(
  15746. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  15747. times, values
  15748. ).scale( 1.0 / fps ) );
  15749. }
  15750. return new this( name, -1, tracks );
  15751. }
  15752. static findByName( objectOrClipArray, name ) {
  15753. let clipArray = objectOrClipArray;
  15754. if ( ! Array.isArray( objectOrClipArray ) ) {
  15755. const o = objectOrClipArray;
  15756. clipArray = o.geometry && o.geometry.animations || o.animations;
  15757. }
  15758. for ( let i = 0; i < clipArray.length; i ++ ) {
  15759. if ( clipArray[ i ].name === name ) {
  15760. return clipArray[ i ];
  15761. }
  15762. }
  15763. return null;
  15764. }
  15765. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  15766. const animationToMorphTargets = {};
  15767. // tested with https://regex101.com/ on trick sequences
  15768. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  15769. const pattern = /^([\w-]*?)([\d]+)$/;
  15770. // sort morph target names into animation groups based
  15771. // patterns like Walk_001, Walk_002, Run_001, Run_002
  15772. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  15773. const morphTarget = morphTargets[ i ];
  15774. const parts = morphTarget.name.match( pattern );
  15775. if ( parts && parts.length > 1 ) {
  15776. const name = parts[ 1 ];
  15777. let animationMorphTargets = animationToMorphTargets[ name ];
  15778. if ( ! animationMorphTargets ) {
  15779. animationToMorphTargets[ name ] = animationMorphTargets = [];
  15780. }
  15781. animationMorphTargets.push( morphTarget );
  15782. }
  15783. }
  15784. const clips = [];
  15785. for ( const name in animationToMorphTargets ) {
  15786. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  15787. }
  15788. return clips;
  15789. }
  15790. // parse the animation.hierarchy format
  15791. static parseAnimation( animation, bones ) {
  15792. if ( ! animation ) {
  15793. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  15794. return null;
  15795. }
  15796. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  15797. // only return track if there are actually keys.
  15798. if ( animationKeys.length !== 0 ) {
  15799. const times = [];
  15800. const values = [];
  15801. flattenJSON( animationKeys, times, values, propertyName );
  15802. // empty keys are filtered out, so check again
  15803. if ( times.length !== 0 ) {
  15804. destTracks.push( new trackType( trackName, times, values ) );
  15805. }
  15806. }
  15807. };
  15808. const tracks = [];
  15809. const clipName = animation.name || 'default';
  15810. const fps = animation.fps || 30;
  15811. const blendMode = animation.blendMode;
  15812. // automatic length determination in AnimationClip.
  15813. let duration = animation.length || -1;
  15814. const hierarchyTracks = animation.hierarchy || [];
  15815. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  15816. const animationKeys = hierarchyTracks[ h ].keys;
  15817. // skip empty tracks
  15818. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  15819. // process morph targets
  15820. if ( animationKeys[ 0 ].morphTargets ) {
  15821. // figure out all morph targets used in this track
  15822. const morphTargetNames = {};
  15823. let k;
  15824. for ( k = 0; k < animationKeys.length; k ++ ) {
  15825. if ( animationKeys[ k ].morphTargets ) {
  15826. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  15827. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = -1;
  15828. }
  15829. }
  15830. }
  15831. // create a track for each morph target with all zero
  15832. // morphTargetInfluences except for the keys in which
  15833. // the morphTarget is named.
  15834. for ( const morphTargetName in morphTargetNames ) {
  15835. const times = [];
  15836. const values = [];
  15837. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  15838. const animationKey = animationKeys[ k ];
  15839. times.push( animationKey.time );
  15840. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  15841. }
  15842. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  15843. }
  15844. duration = morphTargetNames.length * fps;
  15845. } else {
  15846. // ...assume skeletal animation
  15847. const boneName = '.bones[' + bones[ h ].name + ']';
  15848. addNonemptyTrack(
  15849. VectorKeyframeTrack, boneName + '.position',
  15850. animationKeys, 'pos', tracks );
  15851. addNonemptyTrack(
  15852. QuaternionKeyframeTrack, boneName + '.quaternion',
  15853. animationKeys, 'rot', tracks );
  15854. addNonemptyTrack(
  15855. VectorKeyframeTrack, boneName + '.scale',
  15856. animationKeys, 'scl', tracks );
  15857. }
  15858. }
  15859. if ( tracks.length === 0 ) {
  15860. return null;
  15861. }
  15862. const clip = new this( clipName, duration, tracks, blendMode );
  15863. return clip;
  15864. }
  15865. resetDuration() {
  15866. const tracks = this.tracks;
  15867. let duration = 0;
  15868. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  15869. const track = this.tracks[ i ];
  15870. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  15871. }
  15872. this.duration = duration;
  15873. return this;
  15874. }
  15875. trim() {
  15876. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15877. this.tracks[ i ].trim( 0, this.duration );
  15878. }
  15879. return this;
  15880. }
  15881. validate() {
  15882. let valid = true;
  15883. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15884. valid = valid && this.tracks[ i ].validate();
  15885. }
  15886. return valid;
  15887. }
  15888. optimize() {
  15889. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15890. this.tracks[ i ].optimize();
  15891. }
  15892. return this;
  15893. }
  15894. clone() {
  15895. const tracks = [];
  15896. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15897. tracks.push( this.tracks[ i ].clone() );
  15898. }
  15899. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  15900. }
  15901. toJSON() {
  15902. return this.constructor.toJSON( this );
  15903. }
  15904. }
  15905. function getTrackTypeForValueTypeName( typeName ) {
  15906. switch ( typeName.toLowerCase() ) {
  15907. case 'scalar':
  15908. case 'double':
  15909. case 'float':
  15910. case 'number':
  15911. case 'integer':
  15912. return NumberKeyframeTrack;
  15913. case 'vector':
  15914. case 'vector2':
  15915. case 'vector3':
  15916. case 'vector4':
  15917. return VectorKeyframeTrack;
  15918. case 'color':
  15919. return ColorKeyframeTrack;
  15920. case 'quaternion':
  15921. return QuaternionKeyframeTrack;
  15922. case 'bool':
  15923. case 'boolean':
  15924. return BooleanKeyframeTrack;
  15925. case 'string':
  15926. return StringKeyframeTrack;
  15927. }
  15928. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  15929. }
  15930. function parseKeyframeTrack( json ) {
  15931. if ( json.type === undefined ) {
  15932. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  15933. }
  15934. const trackType = getTrackTypeForValueTypeName( json.type );
  15935. if ( json.times === undefined ) {
  15936. const times = [], values = [];
  15937. flattenJSON( json.keys, times, values, 'value' );
  15938. json.times = times;
  15939. json.values = values;
  15940. }
  15941. // derived classes can define a static parse method
  15942. if ( trackType.parse !== undefined ) {
  15943. return trackType.parse( json );
  15944. } else {
  15945. // by default, we assume a constructor compatible with the base
  15946. return new trackType( json.name, json.times, json.values, json.interpolation );
  15947. }
  15948. }
  15949. const Cache = {
  15950. enabled: false,
  15951. files: {},
  15952. add: function ( key, file ) {
  15953. if ( this.enabled === false ) return;
  15954. // console.log( 'THREE.Cache', 'Adding key:', key );
  15955. this.files[ key ] = file;
  15956. },
  15957. get: function ( key ) {
  15958. if ( this.enabled === false ) return;
  15959. // console.log( 'THREE.Cache', 'Checking key:', key );
  15960. return this.files[ key ];
  15961. },
  15962. remove: function ( key ) {
  15963. delete this.files[ key ];
  15964. },
  15965. clear: function () {
  15966. this.files = {};
  15967. }
  15968. };
  15969. class LoadingManager {
  15970. constructor( onLoad, onProgress, onError ) {
  15971. const scope = this;
  15972. let isLoading = false;
  15973. let itemsLoaded = 0;
  15974. let itemsTotal = 0;
  15975. let urlModifier = undefined;
  15976. const handlers = [];
  15977. // Refer to #5689 for the reason why we don't set .onStart
  15978. // in the constructor
  15979. this.onStart = undefined;
  15980. this.onLoad = onLoad;
  15981. this.onProgress = onProgress;
  15982. this.onError = onError;
  15983. this.itemStart = function ( url ) {
  15984. itemsTotal ++;
  15985. if ( isLoading === false ) {
  15986. if ( scope.onStart !== undefined ) {
  15987. scope.onStart( url, itemsLoaded, itemsTotal );
  15988. }
  15989. }
  15990. isLoading = true;
  15991. };
  15992. this.itemEnd = function ( url ) {
  15993. itemsLoaded ++;
  15994. if ( scope.onProgress !== undefined ) {
  15995. scope.onProgress( url, itemsLoaded, itemsTotal );
  15996. }
  15997. if ( itemsLoaded === itemsTotal ) {
  15998. isLoading = false;
  15999. if ( scope.onLoad !== undefined ) {
  16000. scope.onLoad();
  16001. }
  16002. }
  16003. };
  16004. this.itemError = function ( url ) {
  16005. if ( scope.onError !== undefined ) {
  16006. scope.onError( url );
  16007. }
  16008. };
  16009. this.resolveURL = function ( url ) {
  16010. if ( urlModifier ) {
  16011. return urlModifier( url );
  16012. }
  16013. return url;
  16014. };
  16015. this.setURLModifier = function ( transform ) {
  16016. urlModifier = transform;
  16017. return this;
  16018. };
  16019. this.addHandler = function ( regex, loader ) {
  16020. handlers.push( regex, loader );
  16021. return this;
  16022. };
  16023. this.removeHandler = function ( regex ) {
  16024. const index = handlers.indexOf( regex );
  16025. if ( index !== -1 ) {
  16026. handlers.splice( index, 2 );
  16027. }
  16028. return this;
  16029. };
  16030. this.getHandler = function ( file ) {
  16031. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  16032. const regex = handlers[ i ];
  16033. const loader = handlers[ i + 1 ];
  16034. if ( regex.global ) regex.lastIndex = 0; // see #17920
  16035. if ( regex.test( file ) ) {
  16036. return loader;
  16037. }
  16038. }
  16039. return null;
  16040. };
  16041. }
  16042. }
  16043. const DefaultLoadingManager = /*@__PURE__*/ new LoadingManager();
  16044. class Loader {
  16045. constructor( manager ) {
  16046. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  16047. this.crossOrigin = 'anonymous';
  16048. this.withCredentials = false;
  16049. this.path = '';
  16050. this.resourcePath = '';
  16051. this.requestHeader = {};
  16052. }
  16053. load( /* url, onLoad, onProgress, onError */ ) {}
  16054. loadAsync( url, onProgress ) {
  16055. const scope = this;
  16056. return new Promise( function ( resolve, reject ) {
  16057. scope.load( url, resolve, onProgress, reject );
  16058. } );
  16059. }
  16060. parse( /* data */ ) {}
  16061. setCrossOrigin( crossOrigin ) {
  16062. this.crossOrigin = crossOrigin;
  16063. return this;
  16064. }
  16065. setWithCredentials( value ) {
  16066. this.withCredentials = value;
  16067. return this;
  16068. }
  16069. setPath( path ) {
  16070. this.path = path;
  16071. return this;
  16072. }
  16073. setResourcePath( resourcePath ) {
  16074. this.resourcePath = resourcePath;
  16075. return this;
  16076. }
  16077. setRequestHeader( requestHeader ) {
  16078. this.requestHeader = requestHeader;
  16079. return this;
  16080. }
  16081. }
  16082. Loader.DEFAULT_MATERIAL_NAME = '__DEFAULT';
  16083. const loading = {};
  16084. class HttpError extends Error {
  16085. constructor( message, response ) {
  16086. super( message );
  16087. this.response = response;
  16088. }
  16089. }
  16090. class FileLoader extends Loader {
  16091. constructor( manager ) {
  16092. super( manager );
  16093. }
  16094. load( url, onLoad, onProgress, onError ) {
  16095. if ( url === undefined ) url = '';
  16096. if ( this.path !== undefined ) url = this.path + url;
  16097. url = this.manager.resolveURL( url );
  16098. const cached = Cache.get( url );
  16099. if ( cached !== undefined ) {
  16100. this.manager.itemStart( url );
  16101. setTimeout( () => {
  16102. if ( onLoad ) onLoad( cached );
  16103. this.manager.itemEnd( url );
  16104. }, 0 );
  16105. return cached;
  16106. }
  16107. // Check if request is duplicate
  16108. if ( loading[ url ] !== undefined ) {
  16109. loading[ url ].push( {
  16110. onLoad: onLoad,
  16111. onProgress: onProgress,
  16112. onError: onError
  16113. } );
  16114. return;
  16115. }
  16116. // Initialise array for duplicate requests
  16117. loading[ url ] = [];
  16118. loading[ url ].push( {
  16119. onLoad: onLoad,
  16120. onProgress: onProgress,
  16121. onError: onError,
  16122. } );
  16123. // create request
  16124. const req = new Request( url, {
  16125. headers: new Headers( this.requestHeader ),
  16126. credentials: this.withCredentials ? 'include' : 'same-origin',
  16127. // An abort controller could be added within a future PR
  16128. } );
  16129. // record states ( avoid data race )
  16130. const mimeType = this.mimeType;
  16131. const responseType = this.responseType;
  16132. // start the fetch
  16133. fetch( req )
  16134. .then( response => {
  16135. if ( response.status === 200 || response.status === 0 ) {
  16136. // Some browsers return HTTP Status 0 when using non-http protocol
  16137. // e.g. 'file://' or 'data://'. Handle as success.
  16138. if ( response.status === 0 ) {
  16139. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  16140. }
  16141. // Workaround: Checking if response.body === undefined for Alipay browser #23548
  16142. if ( typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined ) {
  16143. return response;
  16144. }
  16145. const callbacks = loading[ url ];
  16146. const reader = response.body.getReader();
  16147. // Nginx needs X-File-Size check
  16148. // https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
  16149. const contentLength = response.headers.get( 'X-File-Size' ) || response.headers.get( 'Content-Length' );
  16150. const total = contentLength ? parseInt( contentLength ) : 0;
  16151. const lengthComputable = total !== 0;
  16152. let loaded = 0;
  16153. // periodically read data into the new stream tracking while download progress
  16154. const stream = new ReadableStream( {
  16155. start( controller ) {
  16156. readData();
  16157. function readData() {
  16158. reader.read().then( ( { done, value } ) => {
  16159. if ( done ) {
  16160. controller.close();
  16161. } else {
  16162. loaded += value.byteLength;
  16163. const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } );
  16164. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  16165. const callback = callbacks[ i ];
  16166. if ( callback.onProgress ) callback.onProgress( event );
  16167. }
  16168. controller.enqueue( value );
  16169. readData();
  16170. }
  16171. }, ( e ) => {
  16172. controller.error( e );
  16173. } );
  16174. }
  16175. }
  16176. } );
  16177. return new Response( stream );
  16178. } else {
  16179. throw new HttpError( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response );
  16180. }
  16181. } )
  16182. .then( response => {
  16183. switch ( responseType ) {
  16184. case 'arraybuffer':
  16185. return response.arrayBuffer();
  16186. case 'blob':
  16187. return response.blob();
  16188. case 'document':
  16189. return response.text()
  16190. .then( text => {
  16191. const parser = new DOMParser();
  16192. return parser.parseFromString( text, mimeType );
  16193. } );
  16194. case 'json':
  16195. return response.json();
  16196. default:
  16197. if ( mimeType === undefined ) {
  16198. return response.text();
  16199. } else {
  16200. // sniff encoding
  16201. const re = /charset="?([^;"\s]*)"?/i;
  16202. const exec = re.exec( mimeType );
  16203. const label = exec && exec[ 1 ] ? exec[ 1 ].toLowerCase() : undefined;
  16204. const decoder = new TextDecoder( label );
  16205. return response.arrayBuffer().then( ab => decoder.decode( ab ) );
  16206. }
  16207. }
  16208. } )
  16209. .then( data => {
  16210. // Add to cache only on HTTP success, so that we do not cache
  16211. // error response bodies as proper responses to requests.
  16212. Cache.add( url, data );
  16213. const callbacks = loading[ url ];
  16214. delete loading[ url ];
  16215. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  16216. const callback = callbacks[ i ];
  16217. if ( callback.onLoad ) callback.onLoad( data );
  16218. }
  16219. } )
  16220. .catch( err => {
  16221. // Abort errors and other errors are handled the same
  16222. const callbacks = loading[ url ];
  16223. if ( callbacks === undefined ) {
  16224. // When onLoad was called and url was deleted in `loading`
  16225. this.manager.itemError( url );
  16226. throw err;
  16227. }
  16228. delete loading[ url ];
  16229. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  16230. const callback = callbacks[ i ];
  16231. if ( callback.onError ) callback.onError( err );
  16232. }
  16233. this.manager.itemError( url );
  16234. } )
  16235. .finally( () => {
  16236. this.manager.itemEnd( url );
  16237. } );
  16238. this.manager.itemStart( url );
  16239. }
  16240. setResponseType( value ) {
  16241. this.responseType = value;
  16242. return this;
  16243. }
  16244. setMimeType( value ) {
  16245. this.mimeType = value;
  16246. return this;
  16247. }
  16248. }
  16249. class AnimationLoader extends Loader {
  16250. constructor( manager ) {
  16251. super( manager );
  16252. }
  16253. load( url, onLoad, onProgress, onError ) {
  16254. const scope = this;
  16255. const loader = new FileLoader( this.manager );
  16256. loader.setPath( this.path );
  16257. loader.setRequestHeader( this.requestHeader );
  16258. loader.setWithCredentials( this.withCredentials );
  16259. loader.load( url, function ( text ) {
  16260. try {
  16261. onLoad( scope.parse( JSON.parse( text ) ) );
  16262. } catch ( e ) {
  16263. if ( onError ) {
  16264. onError( e );
  16265. } else {
  16266. console.error( e );
  16267. }
  16268. scope.manager.itemError( url );
  16269. }
  16270. }, onProgress, onError );
  16271. }
  16272. parse( json ) {
  16273. const animations = [];
  16274. for ( let i = 0; i < json.length; i ++ ) {
  16275. const clip = AnimationClip.parse( json[ i ] );
  16276. animations.push( clip );
  16277. }
  16278. return animations;
  16279. }
  16280. }
  16281. /**
  16282. * Abstract Base class to block based textures loader (dds, pvr, ...)
  16283. *
  16284. * Sub classes have to implement the parse() method which will be used in load().
  16285. */
  16286. class CompressedTextureLoader extends Loader {
  16287. constructor( manager ) {
  16288. super( manager );
  16289. }
  16290. load( url, onLoad, onProgress, onError ) {
  16291. const scope = this;
  16292. const images = [];
  16293. const texture = new CompressedTexture();
  16294. const loader = new FileLoader( this.manager );
  16295. loader.setPath( this.path );
  16296. loader.setResponseType( 'arraybuffer' );
  16297. loader.setRequestHeader( this.requestHeader );
  16298. loader.setWithCredentials( scope.withCredentials );
  16299. let loaded = 0;
  16300. function loadTexture( i ) {
  16301. loader.load( url[ i ], function ( buffer ) {
  16302. const texDatas = scope.parse( buffer, true );
  16303. images[ i ] = {
  16304. width: texDatas.width,
  16305. height: texDatas.height,
  16306. format: texDatas.format,
  16307. mipmaps: texDatas.mipmaps
  16308. };
  16309. loaded += 1;
  16310. if ( loaded === 6 ) {
  16311. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  16312. texture.image = images;
  16313. texture.format = texDatas.format;
  16314. texture.needsUpdate = true;
  16315. if ( onLoad ) onLoad( texture );
  16316. }
  16317. }, onProgress, onError );
  16318. }
  16319. if ( Array.isArray( url ) ) {
  16320. for ( let i = 0, il = url.length; i < il; ++ i ) {
  16321. loadTexture( i );
  16322. }
  16323. } else {
  16324. // compressed cubemap texture stored in a single DDS file
  16325. loader.load( url, function ( buffer ) {
  16326. const texDatas = scope.parse( buffer, true );
  16327. if ( texDatas.isCubemap ) {
  16328. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  16329. for ( let f = 0; f < faces; f ++ ) {
  16330. images[ f ] = { mipmaps: [] };
  16331. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  16332. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  16333. images[ f ].format = texDatas.format;
  16334. images[ f ].width = texDatas.width;
  16335. images[ f ].height = texDatas.height;
  16336. }
  16337. }
  16338. texture.image = images;
  16339. } else {
  16340. texture.image.width = texDatas.width;
  16341. texture.image.height = texDatas.height;
  16342. texture.mipmaps = texDatas.mipmaps;
  16343. }
  16344. if ( texDatas.mipmapCount === 1 ) {
  16345. texture.minFilter = LinearFilter;
  16346. }
  16347. texture.format = texDatas.format;
  16348. texture.needsUpdate = true;
  16349. if ( onLoad ) onLoad( texture );
  16350. }, onProgress, onError );
  16351. }
  16352. return texture;
  16353. }
  16354. }
  16355. class ImageLoader extends Loader {
  16356. constructor( manager ) {
  16357. super( manager );
  16358. }
  16359. load( url, onLoad, onProgress, onError ) {
  16360. if ( this.path !== undefined ) url = this.path + url;
  16361. url = this.manager.resolveURL( url );
  16362. const scope = this;
  16363. const cached = Cache.get( url );
  16364. if ( cached !== undefined ) {
  16365. scope.manager.itemStart( url );
  16366. setTimeout( function () {
  16367. if ( onLoad ) onLoad( cached );
  16368. scope.manager.itemEnd( url );
  16369. }, 0 );
  16370. return cached;
  16371. }
  16372. const image = createElementNS( 'img' );
  16373. function onImageLoad() {
  16374. removeEventListeners();
  16375. Cache.add( url, this );
  16376. if ( onLoad ) onLoad( this );
  16377. scope.manager.itemEnd( url );
  16378. }
  16379. function onImageError( event ) {
  16380. removeEventListeners();
  16381. if ( onError ) onError( event );
  16382. scope.manager.itemError( url );
  16383. scope.manager.itemEnd( url );
  16384. }
  16385. function removeEventListeners() {
  16386. image.removeEventListener( 'load', onImageLoad, false );
  16387. image.removeEventListener( 'error', onImageError, false );
  16388. }
  16389. image.addEventListener( 'load', onImageLoad, false );
  16390. image.addEventListener( 'error', onImageError, false );
  16391. if ( url.slice( 0, 5 ) !== 'data:' ) {
  16392. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  16393. }
  16394. scope.manager.itemStart( url );
  16395. image.src = url;
  16396. return image;
  16397. }
  16398. }
  16399. class CubeTextureLoader extends Loader {
  16400. constructor( manager ) {
  16401. super( manager );
  16402. }
  16403. load( urls, onLoad, onProgress, onError ) {
  16404. const texture = new CubeTexture();
  16405. texture.colorSpace = SRGBColorSpace;
  16406. const loader = new ImageLoader( this.manager );
  16407. loader.setCrossOrigin( this.crossOrigin );
  16408. loader.setPath( this.path );
  16409. let loaded = 0;
  16410. function loadTexture( i ) {
  16411. loader.load( urls[ i ], function ( image ) {
  16412. texture.images[ i ] = image;
  16413. loaded ++;
  16414. if ( loaded === 6 ) {
  16415. texture.needsUpdate = true;
  16416. if ( onLoad ) onLoad( texture );
  16417. }
  16418. }, undefined, onError );
  16419. }
  16420. for ( let i = 0; i < urls.length; ++ i ) {
  16421. loadTexture( i );
  16422. }
  16423. return texture;
  16424. }
  16425. }
  16426. /**
  16427. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  16428. *
  16429. * Sub classes have to implement the parse() method which will be used in load().
  16430. */
  16431. class DataTextureLoader extends Loader {
  16432. constructor( manager ) {
  16433. super( manager );
  16434. }
  16435. load( url, onLoad, onProgress, onError ) {
  16436. const scope = this;
  16437. const texture = new DataTexture();
  16438. const loader = new FileLoader( this.manager );
  16439. loader.setResponseType( 'arraybuffer' );
  16440. loader.setRequestHeader( this.requestHeader );
  16441. loader.setPath( this.path );
  16442. loader.setWithCredentials( scope.withCredentials );
  16443. loader.load( url, function ( buffer ) {
  16444. let texData;
  16445. try {
  16446. texData = scope.parse( buffer );
  16447. } catch ( error ) {
  16448. if ( onError !== undefined ) {
  16449. onError( error );
  16450. } else {
  16451. console.error( error );
  16452. return;
  16453. }
  16454. }
  16455. if ( texData.image !== undefined ) {
  16456. texture.image = texData.image;
  16457. } else if ( texData.data !== undefined ) {
  16458. texture.image.width = texData.width;
  16459. texture.image.height = texData.height;
  16460. texture.image.data = texData.data;
  16461. }
  16462. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  16463. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  16464. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  16465. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  16466. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  16467. if ( texData.colorSpace !== undefined ) {
  16468. texture.colorSpace = texData.colorSpace;
  16469. }
  16470. if ( texData.flipY !== undefined ) {
  16471. texture.flipY = texData.flipY;
  16472. }
  16473. if ( texData.format !== undefined ) {
  16474. texture.format = texData.format;
  16475. }
  16476. if ( texData.type !== undefined ) {
  16477. texture.type = texData.type;
  16478. }
  16479. if ( texData.mipmaps !== undefined ) {
  16480. texture.mipmaps = texData.mipmaps;
  16481. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  16482. }
  16483. if ( texData.mipmapCount === 1 ) {
  16484. texture.minFilter = LinearFilter;
  16485. }
  16486. if ( texData.generateMipmaps !== undefined ) {
  16487. texture.generateMipmaps = texData.generateMipmaps;
  16488. }
  16489. texture.needsUpdate = true;
  16490. if ( onLoad ) onLoad( texture, texData );
  16491. }, onProgress, onError );
  16492. return texture;
  16493. }
  16494. }
  16495. class TextureLoader extends Loader {
  16496. constructor( manager ) {
  16497. super( manager );
  16498. }
  16499. load( url, onLoad, onProgress, onError ) {
  16500. const texture = new Texture();
  16501. const loader = new ImageLoader( this.manager );
  16502. loader.setCrossOrigin( this.crossOrigin );
  16503. loader.setPath( this.path );
  16504. loader.load( url, function ( image ) {
  16505. texture.image = image;
  16506. texture.needsUpdate = true;
  16507. if ( onLoad !== undefined ) {
  16508. onLoad( texture );
  16509. }
  16510. }, onProgress, onError );
  16511. return texture;
  16512. }
  16513. }
  16514. class Light extends Object3D {
  16515. constructor( color, intensity = 1 ) {
  16516. super();
  16517. this.isLight = true;
  16518. this.type = 'Light';
  16519. this.color = new Color( color );
  16520. this.intensity = intensity;
  16521. }
  16522. dispose() {
  16523. // Empty here in base class; some subclasses override.
  16524. }
  16525. copy( source, recursive ) {
  16526. super.copy( source, recursive );
  16527. this.color.copy( source.color );
  16528. this.intensity = source.intensity;
  16529. return this;
  16530. }
  16531. toJSON( meta ) {
  16532. const data = super.toJSON( meta );
  16533. data.object.color = this.color.getHex();
  16534. data.object.intensity = this.intensity;
  16535. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  16536. if ( this.distance !== undefined ) data.object.distance = this.distance;
  16537. if ( this.angle !== undefined ) data.object.angle = this.angle;
  16538. if ( this.decay !== undefined ) data.object.decay = this.decay;
  16539. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  16540. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  16541. if ( this.target !== undefined ) data.object.target = this.target.uuid;
  16542. return data;
  16543. }
  16544. }
  16545. class HemisphereLight extends Light {
  16546. constructor( skyColor, groundColor, intensity ) {
  16547. super( skyColor, intensity );
  16548. this.isHemisphereLight = true;
  16549. this.type = 'HemisphereLight';
  16550. this.position.copy( Object3D.DEFAULT_UP );
  16551. this.updateMatrix();
  16552. this.groundColor = new Color( groundColor );
  16553. }
  16554. copy( source, recursive ) {
  16555. super.copy( source, recursive );
  16556. this.groundColor.copy( source.groundColor );
  16557. return this;
  16558. }
  16559. }
  16560. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  16561. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  16562. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  16563. class LightShadow {
  16564. constructor( camera ) {
  16565. this.camera = camera;
  16566. this.intensity = 1;
  16567. this.bias = 0;
  16568. this.normalBias = 0;
  16569. this.radius = 1;
  16570. this.blurSamples = 8;
  16571. this.mapSize = new Vector2( 512, 512 );
  16572. this.map = null;
  16573. this.mapPass = null;
  16574. this.matrix = new Matrix4();
  16575. this.autoUpdate = true;
  16576. this.needsUpdate = false;
  16577. this._frustum = new Frustum();
  16578. this._frameExtents = new Vector2( 1, 1 );
  16579. this._viewportCount = 1;
  16580. this._viewports = [
  16581. new Vector4( 0, 0, 1, 1 )
  16582. ];
  16583. }
  16584. getViewportCount() {
  16585. return this._viewportCount;
  16586. }
  16587. getFrustum() {
  16588. return this._frustum;
  16589. }
  16590. updateMatrices( light ) {
  16591. const shadowCamera = this.camera;
  16592. const shadowMatrix = this.matrix;
  16593. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  16594. shadowCamera.position.copy( _lightPositionWorld$1 );
  16595. _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld );
  16596. shadowCamera.lookAt( _lookTarget$1 );
  16597. shadowCamera.updateMatrixWorld();
  16598. _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  16599. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  16600. shadowMatrix.set(
  16601. 0.5, 0.0, 0.0, 0.5,
  16602. 0.0, 0.5, 0.0, 0.5,
  16603. 0.0, 0.0, 0.5, 0.5,
  16604. 0.0, 0.0, 0.0, 1.0
  16605. );
  16606. shadowMatrix.multiply( _projScreenMatrix$1 );
  16607. }
  16608. getViewport( viewportIndex ) {
  16609. return this._viewports[ viewportIndex ];
  16610. }
  16611. getFrameExtents() {
  16612. return this._frameExtents;
  16613. }
  16614. dispose() {
  16615. if ( this.map ) {
  16616. this.map.dispose();
  16617. }
  16618. if ( this.mapPass ) {
  16619. this.mapPass.dispose();
  16620. }
  16621. }
  16622. copy( source ) {
  16623. this.camera = source.camera.clone();
  16624. this.intensity = source.intensity;
  16625. this.bias = source.bias;
  16626. this.radius = source.radius;
  16627. this.mapSize.copy( source.mapSize );
  16628. return this;
  16629. }
  16630. clone() {
  16631. return new this.constructor().copy( this );
  16632. }
  16633. toJSON() {
  16634. const object = {};
  16635. if ( this.intensity !== 1 ) object.intensity = this.intensity;
  16636. if ( this.bias !== 0 ) object.bias = this.bias;
  16637. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  16638. if ( this.radius !== 1 ) object.radius = this.radius;
  16639. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  16640. object.camera = this.camera.toJSON( false ).object;
  16641. delete object.camera.matrix;
  16642. return object;
  16643. }
  16644. }
  16645. class SpotLightShadow extends LightShadow {
  16646. constructor() {
  16647. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  16648. this.isSpotLightShadow = true;
  16649. this.focus = 1;
  16650. }
  16651. updateMatrices( light ) {
  16652. const camera = this.camera;
  16653. const fov = RAD2DEG * 2 * light.angle * this.focus;
  16654. const aspect = this.mapSize.width / this.mapSize.height;
  16655. const far = light.distance || camera.far;
  16656. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  16657. camera.fov = fov;
  16658. camera.aspect = aspect;
  16659. camera.far = far;
  16660. camera.updateProjectionMatrix();
  16661. }
  16662. super.updateMatrices( light );
  16663. }
  16664. copy( source ) {
  16665. super.copy( source );
  16666. this.focus = source.focus;
  16667. return this;
  16668. }
  16669. }
  16670. class SpotLight extends Light {
  16671. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) {
  16672. super( color, intensity );
  16673. this.isSpotLight = true;
  16674. this.type = 'SpotLight';
  16675. this.position.copy( Object3D.DEFAULT_UP );
  16676. this.updateMatrix();
  16677. this.target = new Object3D();
  16678. this.distance = distance;
  16679. this.angle = angle;
  16680. this.penumbra = penumbra;
  16681. this.decay = decay;
  16682. this.map = null;
  16683. this.shadow = new SpotLightShadow();
  16684. }
  16685. get power() {
  16686. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16687. // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
  16688. return this.intensity * Math.PI;
  16689. }
  16690. set power( power ) {
  16691. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16692. this.intensity = power / Math.PI;
  16693. }
  16694. dispose() {
  16695. this.shadow.dispose();
  16696. }
  16697. copy( source, recursive ) {
  16698. super.copy( source, recursive );
  16699. this.distance = source.distance;
  16700. this.angle = source.angle;
  16701. this.penumbra = source.penumbra;
  16702. this.decay = source.decay;
  16703. this.target = source.target.clone();
  16704. this.shadow = source.shadow.clone();
  16705. return this;
  16706. }
  16707. }
  16708. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  16709. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  16710. const _lookTarget = /*@__PURE__*/ new Vector3();
  16711. class PointLightShadow extends LightShadow {
  16712. constructor() {
  16713. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  16714. this.isPointLightShadow = true;
  16715. this._frameExtents = new Vector2( 4, 2 );
  16716. this._viewportCount = 6;
  16717. this._viewports = [
  16718. // These viewports map a cube-map onto a 2D texture with the
  16719. // following orientation:
  16720. //
  16721. // xzXZ
  16722. // y Y
  16723. //
  16724. // X - Positive x direction
  16725. // x - Negative x direction
  16726. // Y - Positive y direction
  16727. // y - Negative y direction
  16728. // Z - Positive z direction
  16729. // z - Negative z direction
  16730. // positive X
  16731. new Vector4( 2, 1, 1, 1 ),
  16732. // negative X
  16733. new Vector4( 0, 1, 1, 1 ),
  16734. // positive Z
  16735. new Vector4( 3, 1, 1, 1 ),
  16736. // negative Z
  16737. new Vector4( 1, 1, 1, 1 ),
  16738. // positive Y
  16739. new Vector4( 3, 0, 1, 1 ),
  16740. // negative Y
  16741. new Vector4( 1, 0, 1, 1 )
  16742. ];
  16743. this._cubeDirections = [
  16744. new Vector3( 1, 0, 0 ), new Vector3( -1, 0, 0 ), new Vector3( 0, 0, 1 ),
  16745. new Vector3( 0, 0, -1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, -1, 0 )
  16746. ];
  16747. this._cubeUps = [
  16748. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  16749. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, -1 )
  16750. ];
  16751. }
  16752. updateMatrices( light, viewportIndex = 0 ) {
  16753. const camera = this.camera;
  16754. const shadowMatrix = this.matrix;
  16755. const far = light.distance || camera.far;
  16756. if ( far !== camera.far ) {
  16757. camera.far = far;
  16758. camera.updateProjectionMatrix();
  16759. }
  16760. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  16761. camera.position.copy( _lightPositionWorld );
  16762. _lookTarget.copy( camera.position );
  16763. _lookTarget.add( this._cubeDirections[ viewportIndex ] );
  16764. camera.up.copy( this._cubeUps[ viewportIndex ] );
  16765. camera.lookAt( _lookTarget );
  16766. camera.updateMatrixWorld();
  16767. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  16768. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  16769. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  16770. }
  16771. }
  16772. class PointLight extends Light {
  16773. constructor( color, intensity, distance = 0, decay = 2 ) {
  16774. super( color, intensity );
  16775. this.isPointLight = true;
  16776. this.type = 'PointLight';
  16777. this.distance = distance;
  16778. this.decay = decay;
  16779. this.shadow = new PointLightShadow();
  16780. }
  16781. get power() {
  16782. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16783. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  16784. return this.intensity * 4 * Math.PI;
  16785. }
  16786. set power( power ) {
  16787. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16788. this.intensity = power / ( 4 * Math.PI );
  16789. }
  16790. dispose() {
  16791. this.shadow.dispose();
  16792. }
  16793. copy( source, recursive ) {
  16794. super.copy( source, recursive );
  16795. this.distance = source.distance;
  16796. this.decay = source.decay;
  16797. this.shadow = source.shadow.clone();
  16798. return this;
  16799. }
  16800. }
  16801. class OrthographicCamera extends Camera {
  16802. constructor( left = -1, right = 1, top = 1, bottom = -1, near = 0.1, far = 2000 ) {
  16803. super();
  16804. this.isOrthographicCamera = true;
  16805. this.type = 'OrthographicCamera';
  16806. this.zoom = 1;
  16807. this.view = null;
  16808. this.left = left;
  16809. this.right = right;
  16810. this.top = top;
  16811. this.bottom = bottom;
  16812. this.near = near;
  16813. this.far = far;
  16814. this.updateProjectionMatrix();
  16815. }
  16816. copy( source, recursive ) {
  16817. super.copy( source, recursive );
  16818. this.left = source.left;
  16819. this.right = source.right;
  16820. this.top = source.top;
  16821. this.bottom = source.bottom;
  16822. this.near = source.near;
  16823. this.far = source.far;
  16824. this.zoom = source.zoom;
  16825. this.view = source.view === null ? null : Object.assign( {}, source.view );
  16826. return this;
  16827. }
  16828. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  16829. if ( this.view === null ) {
  16830. this.view = {
  16831. enabled: true,
  16832. fullWidth: 1,
  16833. fullHeight: 1,
  16834. offsetX: 0,
  16835. offsetY: 0,
  16836. width: 1,
  16837. height: 1
  16838. };
  16839. }
  16840. this.view.enabled = true;
  16841. this.view.fullWidth = fullWidth;
  16842. this.view.fullHeight = fullHeight;
  16843. this.view.offsetX = x;
  16844. this.view.offsetY = y;
  16845. this.view.width = width;
  16846. this.view.height = height;
  16847. this.updateProjectionMatrix();
  16848. }
  16849. clearViewOffset() {
  16850. if ( this.view !== null ) {
  16851. this.view.enabled = false;
  16852. }
  16853. this.updateProjectionMatrix();
  16854. }
  16855. updateProjectionMatrix() {
  16856. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  16857. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  16858. const cx = ( this.right + this.left ) / 2;
  16859. const cy = ( this.top + this.bottom ) / 2;
  16860. let left = cx - dx;
  16861. let right = cx + dx;
  16862. let top = cy + dy;
  16863. let bottom = cy - dy;
  16864. if ( this.view !== null && this.view.enabled ) {
  16865. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  16866. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  16867. left += scaleW * this.view.offsetX;
  16868. right = left + scaleW * this.view.width;
  16869. top -= scaleH * this.view.offsetY;
  16870. bottom = top - scaleH * this.view.height;
  16871. }
  16872. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
  16873. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  16874. }
  16875. toJSON( meta ) {
  16876. const data = super.toJSON( meta );
  16877. data.object.zoom = this.zoom;
  16878. data.object.left = this.left;
  16879. data.object.right = this.right;
  16880. data.object.top = this.top;
  16881. data.object.bottom = this.bottom;
  16882. data.object.near = this.near;
  16883. data.object.far = this.far;
  16884. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  16885. return data;
  16886. }
  16887. }
  16888. class DirectionalLightShadow extends LightShadow {
  16889. constructor() {
  16890. super( new OrthographicCamera( -5, 5, 5, -5, 0.5, 500 ) );
  16891. this.isDirectionalLightShadow = true;
  16892. }
  16893. }
  16894. class DirectionalLight extends Light {
  16895. constructor( color, intensity ) {
  16896. super( color, intensity );
  16897. this.isDirectionalLight = true;
  16898. this.type = 'DirectionalLight';
  16899. this.position.copy( Object3D.DEFAULT_UP );
  16900. this.updateMatrix();
  16901. this.target = new Object3D();
  16902. this.shadow = new DirectionalLightShadow();
  16903. }
  16904. dispose() {
  16905. this.shadow.dispose();
  16906. }
  16907. copy( source ) {
  16908. super.copy( source );
  16909. this.target = source.target.clone();
  16910. this.shadow = source.shadow.clone();
  16911. return this;
  16912. }
  16913. }
  16914. class AmbientLight extends Light {
  16915. constructor( color, intensity ) {
  16916. super( color, intensity );
  16917. this.isAmbientLight = true;
  16918. this.type = 'AmbientLight';
  16919. }
  16920. }
  16921. class RectAreaLight extends Light {
  16922. constructor( color, intensity, width = 10, height = 10 ) {
  16923. super( color, intensity );
  16924. this.isRectAreaLight = true;
  16925. this.type = 'RectAreaLight';
  16926. this.width = width;
  16927. this.height = height;
  16928. }
  16929. get power() {
  16930. // compute the light's luminous power (in lumens) from its intensity (in nits)
  16931. return this.intensity * this.width * this.height * Math.PI;
  16932. }
  16933. set power( power ) {
  16934. // set the light's intensity (in nits) from the desired luminous power (in lumens)
  16935. this.intensity = power / ( this.width * this.height * Math.PI );
  16936. }
  16937. copy( source ) {
  16938. super.copy( source );
  16939. this.width = source.width;
  16940. this.height = source.height;
  16941. return this;
  16942. }
  16943. toJSON( meta ) {
  16944. const data = super.toJSON( meta );
  16945. data.object.width = this.width;
  16946. data.object.height = this.height;
  16947. return data;
  16948. }
  16949. }
  16950. /**
  16951. * Primary reference:
  16952. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16953. *
  16954. * Secondary reference:
  16955. * https://www.ppsloan.org/publications/StupidSH36.pdf
  16956. */
  16957. // 3-band SH defined by 9 coefficients
  16958. class SphericalHarmonics3 {
  16959. constructor() {
  16960. this.isSphericalHarmonics3 = true;
  16961. this.coefficients = [];
  16962. for ( let i = 0; i < 9; i ++ ) {
  16963. this.coefficients.push( new Vector3() );
  16964. }
  16965. }
  16966. set( coefficients ) {
  16967. for ( let i = 0; i < 9; i ++ ) {
  16968. this.coefficients[ i ].copy( coefficients[ i ] );
  16969. }
  16970. return this;
  16971. }
  16972. zero() {
  16973. for ( let i = 0; i < 9; i ++ ) {
  16974. this.coefficients[ i ].set( 0, 0, 0 );
  16975. }
  16976. return this;
  16977. }
  16978. // get the radiance in the direction of the normal
  16979. // target is a Vector3
  16980. getAt( normal, target ) {
  16981. // normal is assumed to be unit length
  16982. const x = normal.x, y = normal.y, z = normal.z;
  16983. const coeff = this.coefficients;
  16984. // band 0
  16985. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  16986. // band 1
  16987. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  16988. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  16989. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  16990. // band 2
  16991. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  16992. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  16993. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  16994. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  16995. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  16996. return target;
  16997. }
  16998. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  16999. // target is a Vector3
  17000. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  17001. getIrradianceAt( normal, target ) {
  17002. // normal is assumed to be unit length
  17003. const x = normal.x, y = normal.y, z = normal.z;
  17004. const coeff = this.coefficients;
  17005. // band 0
  17006. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  17007. // band 1
  17008. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  17009. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  17010. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  17011. // band 2
  17012. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  17013. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  17014. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  17015. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  17016. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  17017. return target;
  17018. }
  17019. add( sh ) {
  17020. for ( let i = 0; i < 9; i ++ ) {
  17021. this.coefficients[ i ].add( sh.coefficients[ i ] );
  17022. }
  17023. return this;
  17024. }
  17025. addScaledSH( sh, s ) {
  17026. for ( let i = 0; i < 9; i ++ ) {
  17027. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  17028. }
  17029. return this;
  17030. }
  17031. scale( s ) {
  17032. for ( let i = 0; i < 9; i ++ ) {
  17033. this.coefficients[ i ].multiplyScalar( s );
  17034. }
  17035. return this;
  17036. }
  17037. lerp( sh, alpha ) {
  17038. for ( let i = 0; i < 9; i ++ ) {
  17039. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  17040. }
  17041. return this;
  17042. }
  17043. equals( sh ) {
  17044. for ( let i = 0; i < 9; i ++ ) {
  17045. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  17046. return false;
  17047. }
  17048. }
  17049. return true;
  17050. }
  17051. copy( sh ) {
  17052. return this.set( sh.coefficients );
  17053. }
  17054. clone() {
  17055. return new this.constructor().copy( this );
  17056. }
  17057. fromArray( array, offset = 0 ) {
  17058. const coefficients = this.coefficients;
  17059. for ( let i = 0; i < 9; i ++ ) {
  17060. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  17061. }
  17062. return this;
  17063. }
  17064. toArray( array = [], offset = 0 ) {
  17065. const coefficients = this.coefficients;
  17066. for ( let i = 0; i < 9; i ++ ) {
  17067. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  17068. }
  17069. return array;
  17070. }
  17071. // evaluate the basis functions
  17072. // shBasis is an Array[ 9 ]
  17073. static getBasisAt( normal, shBasis ) {
  17074. // normal is assumed to be unit length
  17075. const x = normal.x, y = normal.y, z = normal.z;
  17076. // band 0
  17077. shBasis[ 0 ] = 0.282095;
  17078. // band 1
  17079. shBasis[ 1 ] = 0.488603 * y;
  17080. shBasis[ 2 ] = 0.488603 * z;
  17081. shBasis[ 3 ] = 0.488603 * x;
  17082. // band 2
  17083. shBasis[ 4 ] = 1.092548 * x * y;
  17084. shBasis[ 5 ] = 1.092548 * y * z;
  17085. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  17086. shBasis[ 7 ] = 1.092548 * x * z;
  17087. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  17088. }
  17089. }
  17090. class LightProbe extends Light {
  17091. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  17092. super( undefined, intensity );
  17093. this.isLightProbe = true;
  17094. this.sh = sh;
  17095. }
  17096. copy( source ) {
  17097. super.copy( source );
  17098. this.sh.copy( source.sh );
  17099. return this;
  17100. }
  17101. fromJSON( json ) {
  17102. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  17103. this.sh.fromArray( json.sh );
  17104. return this;
  17105. }
  17106. toJSON( meta ) {
  17107. const data = super.toJSON( meta );
  17108. data.object.sh = this.sh.toArray();
  17109. return data;
  17110. }
  17111. }
  17112. class MaterialLoader extends Loader {
  17113. constructor( manager ) {
  17114. super( manager );
  17115. this.textures = {};
  17116. }
  17117. load( url, onLoad, onProgress, onError ) {
  17118. const scope = this;
  17119. const loader = new FileLoader( scope.manager );
  17120. loader.setPath( scope.path );
  17121. loader.setRequestHeader( scope.requestHeader );
  17122. loader.setWithCredentials( scope.withCredentials );
  17123. loader.load( url, function ( text ) {
  17124. try {
  17125. onLoad( scope.parse( JSON.parse( text ) ) );
  17126. } catch ( e ) {
  17127. if ( onError ) {
  17128. onError( e );
  17129. } else {
  17130. console.error( e );
  17131. }
  17132. scope.manager.itemError( url );
  17133. }
  17134. }, onProgress, onError );
  17135. }
  17136. parse( json ) {
  17137. const textures = this.textures;
  17138. function getTexture( name ) {
  17139. if ( textures[ name ] === undefined ) {
  17140. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  17141. }
  17142. return textures[ name ];
  17143. }
  17144. const material = this.createMaterialFromType( json.type );
  17145. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  17146. if ( json.name !== undefined ) material.name = json.name;
  17147. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  17148. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  17149. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  17150. if ( json.sheen !== undefined ) material.sheen = json.sheen;
  17151. if ( json.sheenColor !== undefined ) material.sheenColor = new Color().setHex( json.sheenColor );
  17152. if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness;
  17153. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  17154. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  17155. if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity;
  17156. if ( json.specularColor !== undefined && material.specularColor !== undefined ) material.specularColor.setHex( json.specularColor );
  17157. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  17158. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  17159. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  17160. if ( json.dispersion !== undefined ) material.dispersion = json.dispersion;
  17161. if ( json.iridescence !== undefined ) material.iridescence = json.iridescence;
  17162. if ( json.iridescenceIOR !== undefined ) material.iridescenceIOR = json.iridescenceIOR;
  17163. if ( json.iridescenceThicknessRange !== undefined ) material.iridescenceThicknessRange = json.iridescenceThicknessRange;
  17164. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  17165. if ( json.thickness !== undefined ) material.thickness = json.thickness;
  17166. if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance;
  17167. if ( json.attenuationColor !== undefined && material.attenuationColor !== undefined ) material.attenuationColor.setHex( json.attenuationColor );
  17168. if ( json.anisotropy !== undefined ) material.anisotropy = json.anisotropy;
  17169. if ( json.anisotropyRotation !== undefined ) material.anisotropyRotation = json.anisotropyRotation;
  17170. if ( json.fog !== undefined ) material.fog = json.fog;
  17171. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  17172. if ( json.blending !== undefined ) material.blending = json.blending;
  17173. if ( json.combine !== undefined ) material.combine = json.combine;
  17174. if ( json.side !== undefined ) material.side = json.side;
  17175. if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
  17176. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  17177. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  17178. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  17179. if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
  17180. if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc;
  17181. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  17182. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  17183. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  17184. if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc;
  17185. if ( json.blendDst !== undefined ) material.blendDst = json.blendDst;
  17186. if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation;
  17187. if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha;
  17188. if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha;
  17189. if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha;
  17190. if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor );
  17191. if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha;
  17192. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  17193. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  17194. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  17195. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  17196. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  17197. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  17198. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  17199. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  17200. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  17201. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  17202. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  17203. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  17204. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  17205. if ( json.linewidth !== undefined ) material.linewidth = json.linewidth;
  17206. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  17207. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  17208. if ( json.scale !== undefined ) material.scale = json.scale;
  17209. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  17210. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  17211. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  17212. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  17213. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  17214. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  17215. if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass;
  17216. if ( json.visible !== undefined ) material.visible = json.visible;
  17217. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  17218. if ( json.userData !== undefined ) material.userData = json.userData;
  17219. if ( json.vertexColors !== undefined ) {
  17220. if ( typeof json.vertexColors === 'number' ) {
  17221. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  17222. } else {
  17223. material.vertexColors = json.vertexColors;
  17224. }
  17225. }
  17226. // Shader Material
  17227. if ( json.uniforms !== undefined ) {
  17228. for ( const name in json.uniforms ) {
  17229. const uniform = json.uniforms[ name ];
  17230. material.uniforms[ name ] = {};
  17231. switch ( uniform.type ) {
  17232. case 't':
  17233. material.uniforms[ name ].value = getTexture( uniform.value );
  17234. break;
  17235. case 'c':
  17236. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  17237. break;
  17238. case 'v2':
  17239. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  17240. break;
  17241. case 'v3':
  17242. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  17243. break;
  17244. case 'v4':
  17245. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  17246. break;
  17247. case 'm3':
  17248. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  17249. break;
  17250. case 'm4':
  17251. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  17252. break;
  17253. default:
  17254. material.uniforms[ name ].value = uniform.value;
  17255. }
  17256. }
  17257. }
  17258. if ( json.defines !== undefined ) material.defines = json.defines;
  17259. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  17260. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  17261. if ( json.glslVersion !== undefined ) material.glslVersion = json.glslVersion;
  17262. if ( json.extensions !== undefined ) {
  17263. for ( const key in json.extensions ) {
  17264. material.extensions[ key ] = json.extensions[ key ];
  17265. }
  17266. }
  17267. if ( json.lights !== undefined ) material.lights = json.lights;
  17268. if ( json.clipping !== undefined ) material.clipping = json.clipping;
  17269. // for PointsMaterial
  17270. if ( json.size !== undefined ) material.size = json.size;
  17271. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  17272. // maps
  17273. if ( json.map !== undefined ) material.map = getTexture( json.map );
  17274. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  17275. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  17276. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  17277. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  17278. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  17279. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  17280. if ( json.normalScale !== undefined ) {
  17281. let normalScale = json.normalScale;
  17282. if ( Array.isArray( normalScale ) === false ) {
  17283. // Blender exporter used to export a scalar. See #7459
  17284. normalScale = [ normalScale, normalScale ];
  17285. }
  17286. material.normalScale = new Vector2().fromArray( normalScale );
  17287. }
  17288. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  17289. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  17290. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  17291. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  17292. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  17293. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  17294. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  17295. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  17296. if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap );
  17297. if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap );
  17298. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  17299. if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation );
  17300. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  17301. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  17302. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  17303. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  17304. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  17305. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  17306. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  17307. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  17308. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  17309. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  17310. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  17311. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  17312. if ( json.iridescenceMap !== undefined ) material.iridescenceMap = getTexture( json.iridescenceMap );
  17313. if ( json.iridescenceThicknessMap !== undefined ) material.iridescenceThicknessMap = getTexture( json.iridescenceThicknessMap );
  17314. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  17315. if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap );
  17316. if ( json.anisotropyMap !== undefined ) material.anisotropyMap = getTexture( json.anisotropyMap );
  17317. if ( json.sheenColorMap !== undefined ) material.sheenColorMap = getTexture( json.sheenColorMap );
  17318. if ( json.sheenRoughnessMap !== undefined ) material.sheenRoughnessMap = getTexture( json.sheenRoughnessMap );
  17319. return material;
  17320. }
  17321. setTextures( value ) {
  17322. this.textures = value;
  17323. return this;
  17324. }
  17325. createMaterialFromType( type ) {
  17326. return MaterialLoader.createMaterialFromType( type );
  17327. }
  17328. static createMaterialFromType( type ) {
  17329. const materialLib = {
  17330. ShadowMaterial,
  17331. SpriteMaterial,
  17332. RawShaderMaterial,
  17333. ShaderMaterial,
  17334. PointsMaterial,
  17335. MeshPhysicalMaterial,
  17336. MeshStandardMaterial,
  17337. MeshPhongMaterial,
  17338. MeshToonMaterial,
  17339. MeshNormalMaterial,
  17340. MeshLambertMaterial,
  17341. MeshDepthMaterial,
  17342. MeshDistanceMaterial,
  17343. MeshBasicMaterial,
  17344. MeshMatcapMaterial,
  17345. LineDashedMaterial,
  17346. LineBasicMaterial,
  17347. Material
  17348. };
  17349. return new materialLib[ type ]();
  17350. }
  17351. }
  17352. class LoaderUtils {
  17353. static decodeText( array ) { // @deprecated, r165
  17354. console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
  17355. if ( typeof TextDecoder !== 'undefined' ) {
  17356. return new TextDecoder().decode( array );
  17357. }
  17358. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  17359. // throws a "maximum call stack size exceeded" error for large arrays.
  17360. let s = '';
  17361. for ( let i = 0, il = array.length; i < il; i ++ ) {
  17362. // Implicitly assumes little-endian.
  17363. s += String.fromCharCode( array[ i ] );
  17364. }
  17365. try {
  17366. // merges multi-byte utf-8 characters.
  17367. return decodeURIComponent( escape( s ) );
  17368. } catch ( e ) { // see #16358
  17369. return s;
  17370. }
  17371. }
  17372. static extractUrlBase( url ) {
  17373. const index = url.lastIndexOf( '/' );
  17374. if ( index === -1 ) return './';
  17375. return url.slice( 0, index + 1 );
  17376. }
  17377. static resolveURL( url, path ) {
  17378. // Invalid URL
  17379. if ( typeof url !== 'string' || url === '' ) return '';
  17380. // Host Relative URL
  17381. if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
  17382. path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
  17383. }
  17384. // Absolute URL http://,https://,//
  17385. if ( /^(https?:)?\/\//i.test( url ) ) return url;
  17386. // Data URI
  17387. if ( /^data:.*,.*$/i.test( url ) ) return url;
  17388. // Blob URL
  17389. if ( /^blob:.*$/i.test( url ) ) return url;
  17390. // Relative URL
  17391. return path + url;
  17392. }
  17393. }
  17394. class InstancedBufferGeometry extends BufferGeometry {
  17395. constructor() {
  17396. super();
  17397. this.isInstancedBufferGeometry = true;
  17398. this.type = 'InstancedBufferGeometry';
  17399. this.instanceCount = Infinity;
  17400. }
  17401. copy( source ) {
  17402. super.copy( source );
  17403. this.instanceCount = source.instanceCount;
  17404. return this;
  17405. }
  17406. toJSON() {
  17407. const data = super.toJSON();
  17408. data.instanceCount = this.instanceCount;
  17409. data.isInstancedBufferGeometry = true;
  17410. return data;
  17411. }
  17412. }
  17413. class BufferGeometryLoader extends Loader {
  17414. constructor( manager ) {
  17415. super( manager );
  17416. }
  17417. load( url, onLoad, onProgress, onError ) {
  17418. const scope = this;
  17419. const loader = new FileLoader( scope.manager );
  17420. loader.setPath( scope.path );
  17421. loader.setRequestHeader( scope.requestHeader );
  17422. loader.setWithCredentials( scope.withCredentials );
  17423. loader.load( url, function ( text ) {
  17424. try {
  17425. onLoad( scope.parse( JSON.parse( text ) ) );
  17426. } catch ( e ) {
  17427. if ( onError ) {
  17428. onError( e );
  17429. } else {
  17430. console.error( e );
  17431. }
  17432. scope.manager.itemError( url );
  17433. }
  17434. }, onProgress, onError );
  17435. }
  17436. parse( json ) {
  17437. const interleavedBufferMap = {};
  17438. const arrayBufferMap = {};
  17439. function getInterleavedBuffer( json, uuid ) {
  17440. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  17441. const interleavedBuffers = json.interleavedBuffers;
  17442. const interleavedBuffer = interleavedBuffers[ uuid ];
  17443. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  17444. const array = getTypedArray( interleavedBuffer.type, buffer );
  17445. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  17446. ib.uuid = interleavedBuffer.uuid;
  17447. interleavedBufferMap[ uuid ] = ib;
  17448. return ib;
  17449. }
  17450. function getArrayBuffer( json, uuid ) {
  17451. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  17452. const arrayBuffers = json.arrayBuffers;
  17453. const arrayBuffer = arrayBuffers[ uuid ];
  17454. const ab = new Uint32Array( arrayBuffer ).buffer;
  17455. arrayBufferMap[ uuid ] = ab;
  17456. return ab;
  17457. }
  17458. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  17459. const index = json.data.index;
  17460. if ( index !== undefined ) {
  17461. const typedArray = getTypedArray( index.type, index.array );
  17462. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  17463. }
  17464. const attributes = json.data.attributes;
  17465. for ( const key in attributes ) {
  17466. const attribute = attributes[ key ];
  17467. let bufferAttribute;
  17468. if ( attribute.isInterleavedBufferAttribute ) {
  17469. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17470. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17471. } else {
  17472. const typedArray = getTypedArray( attribute.type, attribute.array );
  17473. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  17474. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  17475. }
  17476. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17477. if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage );
  17478. geometry.setAttribute( key, bufferAttribute );
  17479. }
  17480. const morphAttributes = json.data.morphAttributes;
  17481. if ( morphAttributes ) {
  17482. for ( const key in morphAttributes ) {
  17483. const attributeArray = morphAttributes[ key ];
  17484. const array = [];
  17485. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  17486. const attribute = attributeArray[ i ];
  17487. let bufferAttribute;
  17488. if ( attribute.isInterleavedBufferAttribute ) {
  17489. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17490. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17491. } else {
  17492. const typedArray = getTypedArray( attribute.type, attribute.array );
  17493. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  17494. }
  17495. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17496. array.push( bufferAttribute );
  17497. }
  17498. geometry.morphAttributes[ key ] = array;
  17499. }
  17500. }
  17501. const morphTargetsRelative = json.data.morphTargetsRelative;
  17502. if ( morphTargetsRelative ) {
  17503. geometry.morphTargetsRelative = true;
  17504. }
  17505. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  17506. if ( groups !== undefined ) {
  17507. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  17508. const group = groups[ i ];
  17509. geometry.addGroup( group.start, group.count, group.materialIndex );
  17510. }
  17511. }
  17512. const boundingSphere = json.data.boundingSphere;
  17513. if ( boundingSphere !== undefined ) {
  17514. const center = new Vector3();
  17515. if ( boundingSphere.center !== undefined ) {
  17516. center.fromArray( boundingSphere.center );
  17517. }
  17518. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  17519. }
  17520. if ( json.name ) geometry.name = json.name;
  17521. if ( json.userData ) geometry.userData = json.userData;
  17522. return geometry;
  17523. }
  17524. }
  17525. class ObjectLoader extends Loader {
  17526. constructor( manager ) {
  17527. super( manager );
  17528. }
  17529. load( url, onLoad, onProgress, onError ) {
  17530. const scope = this;
  17531. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17532. this.resourcePath = this.resourcePath || path;
  17533. const loader = new FileLoader( this.manager );
  17534. loader.setPath( this.path );
  17535. loader.setRequestHeader( this.requestHeader );
  17536. loader.setWithCredentials( this.withCredentials );
  17537. loader.load( url, function ( text ) {
  17538. let json = null;
  17539. try {
  17540. json = JSON.parse( text );
  17541. } catch ( error ) {
  17542. if ( onError !== undefined ) onError( error );
  17543. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  17544. return;
  17545. }
  17546. const metadata = json.metadata;
  17547. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17548. if ( onError !== undefined ) onError( new Error( 'THREE.ObjectLoader: Can\'t load ' + url ) );
  17549. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17550. return;
  17551. }
  17552. scope.parse( json, onLoad );
  17553. }, onProgress, onError );
  17554. }
  17555. async loadAsync( url, onProgress ) {
  17556. const scope = this;
  17557. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17558. this.resourcePath = this.resourcePath || path;
  17559. const loader = new FileLoader( this.manager );
  17560. loader.setPath( this.path );
  17561. loader.setRequestHeader( this.requestHeader );
  17562. loader.setWithCredentials( this.withCredentials );
  17563. const text = await loader.loadAsync( url, onProgress );
  17564. const json = JSON.parse( text );
  17565. const metadata = json.metadata;
  17566. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17567. throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17568. }
  17569. return await scope.parseAsync( json );
  17570. }
  17571. parse( json, onLoad ) {
  17572. const animations = this.parseAnimations( json.animations );
  17573. const shapes = this.parseShapes( json.shapes );
  17574. const geometries = this.parseGeometries( json.geometries, shapes );
  17575. const images = this.parseImages( json.images, function () {
  17576. if ( onLoad !== undefined ) onLoad( object );
  17577. } );
  17578. const textures = this.parseTextures( json.textures, images );
  17579. const materials = this.parseMaterials( json.materials, textures );
  17580. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17581. const skeletons = this.parseSkeletons( json.skeletons, object );
  17582. this.bindSkeletons( object, skeletons );
  17583. this.bindLightTargets( object );
  17584. //
  17585. if ( onLoad !== undefined ) {
  17586. let hasImages = false;
  17587. for ( const uuid in images ) {
  17588. if ( images[ uuid ].data instanceof HTMLImageElement ) {
  17589. hasImages = true;
  17590. break;
  17591. }
  17592. }
  17593. if ( hasImages === false ) onLoad( object );
  17594. }
  17595. return object;
  17596. }
  17597. async parseAsync( json ) {
  17598. const animations = this.parseAnimations( json.animations );
  17599. const shapes = this.parseShapes( json.shapes );
  17600. const geometries = this.parseGeometries( json.geometries, shapes );
  17601. const images = await this.parseImagesAsync( json.images );
  17602. const textures = this.parseTextures( json.textures, images );
  17603. const materials = this.parseMaterials( json.materials, textures );
  17604. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17605. const skeletons = this.parseSkeletons( json.skeletons, object );
  17606. this.bindSkeletons( object, skeletons );
  17607. this.bindLightTargets( object );
  17608. return object;
  17609. }
  17610. parseShapes( json ) {
  17611. const shapes = {};
  17612. if ( json !== undefined ) {
  17613. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17614. const shape = new Shape().fromJSON( json[ i ] );
  17615. shapes[ shape.uuid ] = shape;
  17616. }
  17617. }
  17618. return shapes;
  17619. }
  17620. parseSkeletons( json, object ) {
  17621. const skeletons = {};
  17622. const bones = {};
  17623. // generate bone lookup table
  17624. object.traverse( function ( child ) {
  17625. if ( child.isBone ) bones[ child.uuid ] = child;
  17626. } );
  17627. // create skeletons
  17628. if ( json !== undefined ) {
  17629. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17630. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  17631. skeletons[ skeleton.uuid ] = skeleton;
  17632. }
  17633. }
  17634. return skeletons;
  17635. }
  17636. parseGeometries( json, shapes ) {
  17637. const geometries = {};
  17638. if ( json !== undefined ) {
  17639. const bufferGeometryLoader = new BufferGeometryLoader();
  17640. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17641. let geometry;
  17642. const data = json[ i ];
  17643. switch ( data.type ) {
  17644. case 'BufferGeometry':
  17645. case 'InstancedBufferGeometry':
  17646. geometry = bufferGeometryLoader.parse( data );
  17647. break;
  17648. default:
  17649. if ( data.type in Geometries ) {
  17650. geometry = Geometries[ data.type ].fromJSON( data, shapes );
  17651. } else {
  17652. console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` );
  17653. }
  17654. }
  17655. geometry.uuid = data.uuid;
  17656. if ( data.name !== undefined ) geometry.name = data.name;
  17657. if ( data.userData !== undefined ) geometry.userData = data.userData;
  17658. geometries[ data.uuid ] = geometry;
  17659. }
  17660. }
  17661. return geometries;
  17662. }
  17663. parseMaterials( json, textures ) {
  17664. const cache = {}; // MultiMaterial
  17665. const materials = {};
  17666. if ( json !== undefined ) {
  17667. const loader = new MaterialLoader();
  17668. loader.setTextures( textures );
  17669. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17670. const data = json[ i ];
  17671. if ( cache[ data.uuid ] === undefined ) {
  17672. cache[ data.uuid ] = loader.parse( data );
  17673. }
  17674. materials[ data.uuid ] = cache[ data.uuid ];
  17675. }
  17676. }
  17677. return materials;
  17678. }
  17679. parseAnimations( json ) {
  17680. const animations = {};
  17681. if ( json !== undefined ) {
  17682. for ( let i = 0; i < json.length; i ++ ) {
  17683. const data = json[ i ];
  17684. const clip = AnimationClip.parse( data );
  17685. animations[ clip.uuid ] = clip;
  17686. }
  17687. }
  17688. return animations;
  17689. }
  17690. parseImages( json, onLoad ) {
  17691. const scope = this;
  17692. const images = {};
  17693. let loader;
  17694. function loadImage( url ) {
  17695. scope.manager.itemStart( url );
  17696. return loader.load( url, function () {
  17697. scope.manager.itemEnd( url );
  17698. }, undefined, function () {
  17699. scope.manager.itemError( url );
  17700. scope.manager.itemEnd( url );
  17701. } );
  17702. }
  17703. function deserializeImage( image ) {
  17704. if ( typeof image === 'string' ) {
  17705. const url = image;
  17706. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17707. return loadImage( path );
  17708. } else {
  17709. if ( image.data ) {
  17710. return {
  17711. data: getTypedArray( image.type, image.data ),
  17712. width: image.width,
  17713. height: image.height
  17714. };
  17715. } else {
  17716. return null;
  17717. }
  17718. }
  17719. }
  17720. if ( json !== undefined && json.length > 0 ) {
  17721. const manager = new LoadingManager( onLoad );
  17722. loader = new ImageLoader( manager );
  17723. loader.setCrossOrigin( this.crossOrigin );
  17724. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17725. const image = json[ i ];
  17726. const url = image.url;
  17727. if ( Array.isArray( url ) ) {
  17728. // load array of images e.g CubeTexture
  17729. const imageArray = [];
  17730. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17731. const currentUrl = url[ j ];
  17732. const deserializedImage = deserializeImage( currentUrl );
  17733. if ( deserializedImage !== null ) {
  17734. if ( deserializedImage instanceof HTMLImageElement ) {
  17735. imageArray.push( deserializedImage );
  17736. } else {
  17737. // special case: handle array of data textures for cube textures
  17738. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17739. }
  17740. }
  17741. }
  17742. images[ image.uuid ] = new Source( imageArray );
  17743. } else {
  17744. // load single image
  17745. const deserializedImage = deserializeImage( image.url );
  17746. images[ image.uuid ] = new Source( deserializedImage );
  17747. }
  17748. }
  17749. }
  17750. return images;
  17751. }
  17752. async parseImagesAsync( json ) {
  17753. const scope = this;
  17754. const images = {};
  17755. let loader;
  17756. async function deserializeImage( image ) {
  17757. if ( typeof image === 'string' ) {
  17758. const url = image;
  17759. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17760. return await loader.loadAsync( path );
  17761. } else {
  17762. if ( image.data ) {
  17763. return {
  17764. data: getTypedArray( image.type, image.data ),
  17765. width: image.width,
  17766. height: image.height
  17767. };
  17768. } else {
  17769. return null;
  17770. }
  17771. }
  17772. }
  17773. if ( json !== undefined && json.length > 0 ) {
  17774. loader = new ImageLoader( this.manager );
  17775. loader.setCrossOrigin( this.crossOrigin );
  17776. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17777. const image = json[ i ];
  17778. const url = image.url;
  17779. if ( Array.isArray( url ) ) {
  17780. // load array of images e.g CubeTexture
  17781. const imageArray = [];
  17782. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17783. const currentUrl = url[ j ];
  17784. const deserializedImage = await deserializeImage( currentUrl );
  17785. if ( deserializedImage !== null ) {
  17786. if ( deserializedImage instanceof HTMLImageElement ) {
  17787. imageArray.push( deserializedImage );
  17788. } else {
  17789. // special case: handle array of data textures for cube textures
  17790. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17791. }
  17792. }
  17793. }
  17794. images[ image.uuid ] = new Source( imageArray );
  17795. } else {
  17796. // load single image
  17797. const deserializedImage = await deserializeImage( image.url );
  17798. images[ image.uuid ] = new Source( deserializedImage );
  17799. }
  17800. }
  17801. }
  17802. return images;
  17803. }
  17804. parseTextures( json, images ) {
  17805. function parseConstant( value, type ) {
  17806. if ( typeof value === 'number' ) return value;
  17807. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  17808. return type[ value ];
  17809. }
  17810. const textures = {};
  17811. if ( json !== undefined ) {
  17812. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17813. const data = json[ i ];
  17814. if ( data.image === undefined ) {
  17815. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  17816. }
  17817. if ( images[ data.image ] === undefined ) {
  17818. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  17819. }
  17820. const source = images[ data.image ];
  17821. const image = source.data;
  17822. let texture;
  17823. if ( Array.isArray( image ) ) {
  17824. texture = new CubeTexture();
  17825. if ( image.length === 6 ) texture.needsUpdate = true;
  17826. } else {
  17827. if ( image && image.data ) {
  17828. texture = new DataTexture();
  17829. } else {
  17830. texture = new Texture();
  17831. }
  17832. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  17833. }
  17834. texture.source = source;
  17835. texture.uuid = data.uuid;
  17836. if ( data.name !== undefined ) texture.name = data.name;
  17837. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  17838. if ( data.channel !== undefined ) texture.channel = data.channel;
  17839. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  17840. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  17841. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  17842. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  17843. if ( data.wrap !== undefined ) {
  17844. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  17845. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  17846. }
  17847. if ( data.format !== undefined ) texture.format = data.format;
  17848. if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat;
  17849. if ( data.type !== undefined ) texture.type = data.type;
  17850. if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace;
  17851. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  17852. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  17853. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  17854. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  17855. if ( data.generateMipmaps !== undefined ) texture.generateMipmaps = data.generateMipmaps;
  17856. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  17857. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  17858. if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction;
  17859. if ( data.userData !== undefined ) texture.userData = data.userData;
  17860. textures[ data.uuid ] = texture;
  17861. }
  17862. }
  17863. return textures;
  17864. }
  17865. parseObject( data, geometries, materials, textures, animations ) {
  17866. let object;
  17867. function getGeometry( name ) {
  17868. if ( geometries[ name ] === undefined ) {
  17869. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  17870. }
  17871. return geometries[ name ];
  17872. }
  17873. function getMaterial( name ) {
  17874. if ( name === undefined ) return undefined;
  17875. if ( Array.isArray( name ) ) {
  17876. const array = [];
  17877. for ( let i = 0, l = name.length; i < l; i ++ ) {
  17878. const uuid = name[ i ];
  17879. if ( materials[ uuid ] === undefined ) {
  17880. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  17881. }
  17882. array.push( materials[ uuid ] );
  17883. }
  17884. return array;
  17885. }
  17886. if ( materials[ name ] === undefined ) {
  17887. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  17888. }
  17889. return materials[ name ];
  17890. }
  17891. function getTexture( uuid ) {
  17892. if ( textures[ uuid ] === undefined ) {
  17893. console.warn( 'THREE.ObjectLoader: Undefined texture', uuid );
  17894. }
  17895. return textures[ uuid ];
  17896. }
  17897. let geometry, material;
  17898. switch ( data.type ) {
  17899. case 'Scene':
  17900. object = new Scene();
  17901. if ( data.background !== undefined ) {
  17902. if ( Number.isInteger( data.background ) ) {
  17903. object.background = new Color( data.background );
  17904. } else {
  17905. object.background = getTexture( data.background );
  17906. }
  17907. }
  17908. if ( data.environment !== undefined ) {
  17909. object.environment = getTexture( data.environment );
  17910. }
  17911. if ( data.fog !== undefined ) {
  17912. if ( data.fog.type === 'Fog' ) {
  17913. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  17914. } else if ( data.fog.type === 'FogExp2' ) {
  17915. object.fog = new FogExp2( data.fog.color, data.fog.density );
  17916. }
  17917. if ( data.fog.name !== '' ) {
  17918. object.fog.name = data.fog.name;
  17919. }
  17920. }
  17921. if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
  17922. if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
  17923. if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );
  17924. if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity;
  17925. if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );
  17926. break;
  17927. case 'PerspectiveCamera':
  17928. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  17929. if ( data.focus !== undefined ) object.focus = data.focus;
  17930. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17931. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  17932. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  17933. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17934. break;
  17935. case 'OrthographicCamera':
  17936. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  17937. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17938. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17939. break;
  17940. case 'AmbientLight':
  17941. object = new AmbientLight( data.color, data.intensity );
  17942. break;
  17943. case 'DirectionalLight':
  17944. object = new DirectionalLight( data.color, data.intensity );
  17945. object.target = data.target || '';
  17946. break;
  17947. case 'PointLight':
  17948. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  17949. break;
  17950. case 'RectAreaLight':
  17951. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  17952. break;
  17953. case 'SpotLight':
  17954. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  17955. object.target = data.target || '';
  17956. break;
  17957. case 'HemisphereLight':
  17958. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  17959. break;
  17960. case 'LightProbe':
  17961. object = new LightProbe().fromJSON( data );
  17962. break;
  17963. case 'SkinnedMesh':
  17964. geometry = getGeometry( data.geometry );
  17965. material = getMaterial( data.material );
  17966. object = new SkinnedMesh( geometry, material );
  17967. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  17968. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  17969. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  17970. break;
  17971. case 'Mesh':
  17972. geometry = getGeometry( data.geometry );
  17973. material = getMaterial( data.material );
  17974. object = new Mesh( geometry, material );
  17975. break;
  17976. case 'InstancedMesh':
  17977. geometry = getGeometry( data.geometry );
  17978. material = getMaterial( data.material );
  17979. const count = data.count;
  17980. const instanceMatrix = data.instanceMatrix;
  17981. const instanceColor = data.instanceColor;
  17982. object = new InstancedMesh( geometry, material, count );
  17983. object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  17984. if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize );
  17985. break;
  17986. case 'BatchedMesh':
  17987. geometry = getGeometry( data.geometry );
  17988. material = getMaterial( data.material );
  17989. object = new BatchedMesh( data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material );
  17990. object.geometry = geometry;
  17991. object.perObjectFrustumCulled = data.perObjectFrustumCulled;
  17992. object.sortObjects = data.sortObjects;
  17993. object._drawRanges = data.drawRanges;
  17994. object._reservedRanges = data.reservedRanges;
  17995. object._visibility = data.visibility;
  17996. object._active = data.active;
  17997. object._bounds = data.bounds.map( bound => {
  17998. const box = new Box3();
  17999. box.min.fromArray( bound.boxMin );
  18000. box.max.fromArray( bound.boxMax );
  18001. const sphere = new Sphere();
  18002. sphere.radius = bound.sphereRadius;
  18003. sphere.center.fromArray( bound.sphereCenter );
  18004. return {
  18005. boxInitialized: bound.boxInitialized,
  18006. box: box,
  18007. sphereInitialized: bound.sphereInitialized,
  18008. sphere: sphere
  18009. };
  18010. } );
  18011. object._maxInstanceCount = data.maxInstanceCount;
  18012. object._maxVertexCount = data.maxVertexCount;
  18013. object._maxIndexCount = data.maxIndexCount;
  18014. object._geometryInitialized = data.geometryInitialized;
  18015. object._geometryCount = data.geometryCount;
  18016. object._matricesTexture = getTexture( data.matricesTexture.uuid );
  18017. if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
  18018. break;
  18019. case 'LOD':
  18020. object = new LOD();
  18021. break;
  18022. case 'Line':
  18023. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  18024. break;
  18025. case 'LineLoop':
  18026. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  18027. break;
  18028. case 'LineSegments':
  18029. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  18030. break;
  18031. case 'PointCloud':
  18032. case 'Points':
  18033. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  18034. break;
  18035. case 'Sprite':
  18036. object = new Sprite( getMaterial( data.material ) );
  18037. break;
  18038. case 'Group':
  18039. object = new Group();
  18040. break;
  18041. case 'Bone':
  18042. object = new Bone();
  18043. break;
  18044. default:
  18045. object = new Object3D();
  18046. }
  18047. object.uuid = data.uuid;
  18048. if ( data.name !== undefined ) object.name = data.name;
  18049. if ( data.matrix !== undefined ) {
  18050. object.matrix.fromArray( data.matrix );
  18051. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  18052. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  18053. } else {
  18054. if ( data.position !== undefined ) object.position.fromArray( data.position );
  18055. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  18056. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  18057. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  18058. }
  18059. if ( data.up !== undefined ) object.up.fromArray( data.up );
  18060. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  18061. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  18062. if ( data.shadow ) {
  18063. if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
  18064. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  18065. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  18066. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  18067. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  18068. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  18069. }
  18070. if ( data.visible !== undefined ) object.visible = data.visible;
  18071. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  18072. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  18073. if ( data.userData !== undefined ) object.userData = data.userData;
  18074. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  18075. if ( data.children !== undefined ) {
  18076. const children = data.children;
  18077. for ( let i = 0; i < children.length; i ++ ) {
  18078. object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
  18079. }
  18080. }
  18081. if ( data.animations !== undefined ) {
  18082. const objectAnimations = data.animations;
  18083. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  18084. const uuid = objectAnimations[ i ];
  18085. object.animations.push( animations[ uuid ] );
  18086. }
  18087. }
  18088. if ( data.type === 'LOD' ) {
  18089. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  18090. const levels = data.levels;
  18091. for ( let l = 0; l < levels.length; l ++ ) {
  18092. const level = levels[ l ];
  18093. const child = object.getObjectByProperty( 'uuid', level.object );
  18094. if ( child !== undefined ) {
  18095. object.addLevel( child, level.distance, level.hysteresis );
  18096. }
  18097. }
  18098. }
  18099. return object;
  18100. }
  18101. bindSkeletons( object, skeletons ) {
  18102. if ( Object.keys( skeletons ).length === 0 ) return;
  18103. object.traverse( function ( child ) {
  18104. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  18105. const skeleton = skeletons[ child.skeleton ];
  18106. if ( skeleton === undefined ) {
  18107. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  18108. } else {
  18109. child.bind( skeleton, child.bindMatrix );
  18110. }
  18111. }
  18112. } );
  18113. }
  18114. bindLightTargets( object ) {
  18115. object.traverse( function ( child ) {
  18116. if ( child.isDirectionalLight || child.isSpotLight ) {
  18117. const uuid = child.target;
  18118. const target = object.getObjectByProperty( 'uuid', uuid );
  18119. if ( target !== undefined ) {
  18120. child.target = target;
  18121. } else {
  18122. child.target = new Object3D();
  18123. }
  18124. }
  18125. } );
  18126. }
  18127. }
  18128. const TEXTURE_MAPPING = {
  18129. UVMapping: UVMapping,
  18130. CubeReflectionMapping: CubeReflectionMapping,
  18131. CubeRefractionMapping: CubeRefractionMapping,
  18132. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  18133. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  18134. CubeUVReflectionMapping: CubeUVReflectionMapping
  18135. };
  18136. const TEXTURE_WRAPPING = {
  18137. RepeatWrapping: RepeatWrapping,
  18138. ClampToEdgeWrapping: ClampToEdgeWrapping,
  18139. MirroredRepeatWrapping: MirroredRepeatWrapping
  18140. };
  18141. const TEXTURE_FILTER = {
  18142. NearestFilter: NearestFilter,
  18143. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  18144. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  18145. LinearFilter: LinearFilter,
  18146. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  18147. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  18148. };
  18149. class ImageBitmapLoader extends Loader {
  18150. constructor( manager ) {
  18151. super( manager );
  18152. this.isImageBitmapLoader = true;
  18153. if ( typeof createImageBitmap === 'undefined' ) {
  18154. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  18155. }
  18156. if ( typeof fetch === 'undefined' ) {
  18157. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  18158. }
  18159. this.options = { premultiplyAlpha: 'none' };
  18160. }
  18161. setOptions( options ) {
  18162. this.options = options;
  18163. return this;
  18164. }
  18165. load( url, onLoad, onProgress, onError ) {
  18166. if ( url === undefined ) url = '';
  18167. if ( this.path !== undefined ) url = this.path + url;
  18168. url = this.manager.resolveURL( url );
  18169. const scope = this;
  18170. const cached = Cache.get( url );
  18171. if ( cached !== undefined ) {
  18172. scope.manager.itemStart( url );
  18173. // If cached is a promise, wait for it to resolve
  18174. if ( cached.then ) {
  18175. cached.then( imageBitmap => {
  18176. if ( onLoad ) onLoad( imageBitmap );
  18177. scope.manager.itemEnd( url );
  18178. } ).catch( e => {
  18179. if ( onError ) onError( e );
  18180. } );
  18181. return;
  18182. }
  18183. // If cached is not a promise (i.e., it's already an imageBitmap)
  18184. setTimeout( function () {
  18185. if ( onLoad ) onLoad( cached );
  18186. scope.manager.itemEnd( url );
  18187. }, 0 );
  18188. return cached;
  18189. }
  18190. const fetchOptions = {};
  18191. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  18192. fetchOptions.headers = this.requestHeader;
  18193. const promise = fetch( url, fetchOptions ).then( function ( res ) {
  18194. return res.blob();
  18195. } ).then( function ( blob ) {
  18196. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  18197. } ).then( function ( imageBitmap ) {
  18198. Cache.add( url, imageBitmap );
  18199. if ( onLoad ) onLoad( imageBitmap );
  18200. scope.manager.itemEnd( url );
  18201. return imageBitmap;
  18202. } ).catch( function ( e ) {
  18203. if ( onError ) onError( e );
  18204. Cache.remove( url );
  18205. scope.manager.itemError( url );
  18206. scope.manager.itemEnd( url );
  18207. } );
  18208. Cache.add( url, promise );
  18209. scope.manager.itemStart( url );
  18210. }
  18211. }
  18212. let _context;
  18213. class AudioContext {
  18214. static getContext() {
  18215. if ( _context === undefined ) {
  18216. _context = new ( window.AudioContext || window.webkitAudioContext )();
  18217. }
  18218. return _context;
  18219. }
  18220. static setContext( value ) {
  18221. _context = value;
  18222. }
  18223. }
  18224. class AudioLoader extends Loader {
  18225. constructor( manager ) {
  18226. super( manager );
  18227. }
  18228. load( url, onLoad, onProgress, onError ) {
  18229. const scope = this;
  18230. const loader = new FileLoader( this.manager );
  18231. loader.setResponseType( 'arraybuffer' );
  18232. loader.setPath( this.path );
  18233. loader.setRequestHeader( this.requestHeader );
  18234. loader.setWithCredentials( this.withCredentials );
  18235. loader.load( url, function ( buffer ) {
  18236. try {
  18237. // Create a copy of the buffer. The `decodeAudioData` method
  18238. // detaches the buffer when complete, preventing reuse.
  18239. const bufferCopy = buffer.slice( 0 );
  18240. const context = AudioContext.getContext();
  18241. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  18242. onLoad( audioBuffer );
  18243. } ).catch( handleError );
  18244. } catch ( e ) {
  18245. handleError( e );
  18246. }
  18247. }, onProgress, onError );
  18248. function handleError( e ) {
  18249. if ( onError ) {
  18250. onError( e );
  18251. } else {
  18252. console.error( e );
  18253. }
  18254. scope.manager.itemError( url );
  18255. }
  18256. }
  18257. }
  18258. const _eyeRight = /*@__PURE__*/ new Matrix4();
  18259. const _eyeLeft = /*@__PURE__*/ new Matrix4();
  18260. const _projectionMatrix = /*@__PURE__*/ new Matrix4();
  18261. class StereoCamera {
  18262. constructor() {
  18263. this.type = 'StereoCamera';
  18264. this.aspect = 1;
  18265. this.eyeSep = 0.064;
  18266. this.cameraL = new PerspectiveCamera();
  18267. this.cameraL.layers.enable( 1 );
  18268. this.cameraL.matrixAutoUpdate = false;
  18269. this.cameraR = new PerspectiveCamera();
  18270. this.cameraR.layers.enable( 2 );
  18271. this.cameraR.matrixAutoUpdate = false;
  18272. this._cache = {
  18273. focus: null,
  18274. fov: null,
  18275. aspect: null,
  18276. near: null,
  18277. far: null,
  18278. zoom: null,
  18279. eyeSep: null
  18280. };
  18281. }
  18282. update( camera ) {
  18283. const cache = this._cache;
  18284. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  18285. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  18286. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  18287. if ( needsUpdate ) {
  18288. cache.focus = camera.focus;
  18289. cache.fov = camera.fov;
  18290. cache.aspect = camera.aspect * this.aspect;
  18291. cache.near = camera.near;
  18292. cache.far = camera.far;
  18293. cache.zoom = camera.zoom;
  18294. cache.eyeSep = this.eyeSep;
  18295. // Off-axis stereoscopic effect based on
  18296. // http://paulbourke.net/stereographics/stereorender/
  18297. _projectionMatrix.copy( camera.projectionMatrix );
  18298. const eyeSepHalf = cache.eyeSep / 2;
  18299. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  18300. const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  18301. let xmin, xmax;
  18302. // translate xOffset
  18303. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  18304. _eyeRight.elements[ 12 ] = eyeSepHalf;
  18305. // for left eye
  18306. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  18307. xmax = ymax * cache.aspect + eyeSepOnProjection;
  18308. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18309. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18310. this.cameraL.projectionMatrix.copy( _projectionMatrix );
  18311. // for right eye
  18312. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  18313. xmax = ymax * cache.aspect - eyeSepOnProjection;
  18314. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18315. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18316. this.cameraR.projectionMatrix.copy( _projectionMatrix );
  18317. }
  18318. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  18319. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  18320. }
  18321. }
  18322. class ArrayCamera extends PerspectiveCamera {
  18323. constructor( array = [] ) {
  18324. super();
  18325. this.isArrayCamera = true;
  18326. this.cameras = array;
  18327. this.index = 0;
  18328. }
  18329. }
  18330. class Clock {
  18331. constructor( autoStart = true ) {
  18332. this.autoStart = autoStart;
  18333. this.startTime = 0;
  18334. this.oldTime = 0;
  18335. this.elapsedTime = 0;
  18336. this.running = false;
  18337. }
  18338. start() {
  18339. this.startTime = now();
  18340. this.oldTime = this.startTime;
  18341. this.elapsedTime = 0;
  18342. this.running = true;
  18343. }
  18344. stop() {
  18345. this.getElapsedTime();
  18346. this.running = false;
  18347. this.autoStart = false;
  18348. }
  18349. getElapsedTime() {
  18350. this.getDelta();
  18351. return this.elapsedTime;
  18352. }
  18353. getDelta() {
  18354. let diff = 0;
  18355. if ( this.autoStart && ! this.running ) {
  18356. this.start();
  18357. return 0;
  18358. }
  18359. if ( this.running ) {
  18360. const newTime = now();
  18361. diff = ( newTime - this.oldTime ) / 1000;
  18362. this.oldTime = newTime;
  18363. this.elapsedTime += diff;
  18364. }
  18365. return diff;
  18366. }
  18367. }
  18368. function now() {
  18369. return performance.now();
  18370. }
  18371. const _position$1 = /*@__PURE__*/ new Vector3();
  18372. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  18373. const _scale$1 = /*@__PURE__*/ new Vector3();
  18374. const _orientation$1 = /*@__PURE__*/ new Vector3();
  18375. class AudioListener extends Object3D {
  18376. constructor() {
  18377. super();
  18378. this.type = 'AudioListener';
  18379. this.context = AudioContext.getContext();
  18380. this.gain = this.context.createGain();
  18381. this.gain.connect( this.context.destination );
  18382. this.filter = null;
  18383. this.timeDelta = 0;
  18384. // private
  18385. this._clock = new Clock();
  18386. }
  18387. getInput() {
  18388. return this.gain;
  18389. }
  18390. removeFilter() {
  18391. if ( this.filter !== null ) {
  18392. this.gain.disconnect( this.filter );
  18393. this.filter.disconnect( this.context.destination );
  18394. this.gain.connect( this.context.destination );
  18395. this.filter = null;
  18396. }
  18397. return this;
  18398. }
  18399. getFilter() {
  18400. return this.filter;
  18401. }
  18402. setFilter( value ) {
  18403. if ( this.filter !== null ) {
  18404. this.gain.disconnect( this.filter );
  18405. this.filter.disconnect( this.context.destination );
  18406. } else {
  18407. this.gain.disconnect( this.context.destination );
  18408. }
  18409. this.filter = value;
  18410. this.gain.connect( this.filter );
  18411. this.filter.connect( this.context.destination );
  18412. return this;
  18413. }
  18414. getMasterVolume() {
  18415. return this.gain.gain.value;
  18416. }
  18417. setMasterVolume( value ) {
  18418. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18419. return this;
  18420. }
  18421. updateMatrixWorld( force ) {
  18422. super.updateMatrixWorld( force );
  18423. const listener = this.context.listener;
  18424. const up = this.up;
  18425. this.timeDelta = this._clock.getDelta();
  18426. this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 );
  18427. _orientation$1.set( 0, 0, -1 ).applyQuaternion( _quaternion$1 );
  18428. if ( listener.positionX ) {
  18429. // code path for Chrome (see #14393)
  18430. const endTime = this.context.currentTime + this.timeDelta;
  18431. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  18432. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  18433. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  18434. listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime );
  18435. listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime );
  18436. listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  18437. listener.upX.linearRampToValueAtTime( up.x, endTime );
  18438. listener.upY.linearRampToValueAtTime( up.y, endTime );
  18439. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  18440. } else {
  18441. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  18442. listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z );
  18443. }
  18444. }
  18445. }
  18446. class Audio extends Object3D {
  18447. constructor( listener ) {
  18448. super();
  18449. this.type = 'Audio';
  18450. this.listener = listener;
  18451. this.context = listener.context;
  18452. this.gain = this.context.createGain();
  18453. this.gain.connect( listener.getInput() );
  18454. this.autoplay = false;
  18455. this.buffer = null;
  18456. this.detune = 0;
  18457. this.loop = false;
  18458. this.loopStart = 0;
  18459. this.loopEnd = 0;
  18460. this.offset = 0;
  18461. this.duration = undefined;
  18462. this.playbackRate = 1;
  18463. this.isPlaying = false;
  18464. this.hasPlaybackControl = true;
  18465. this.source = null;
  18466. this.sourceType = 'empty';
  18467. this._startedAt = 0;
  18468. this._progress = 0;
  18469. this._connected = false;
  18470. this.filters = [];
  18471. }
  18472. getOutput() {
  18473. return this.gain;
  18474. }
  18475. setNodeSource( audioNode ) {
  18476. this.hasPlaybackControl = false;
  18477. this.sourceType = 'audioNode';
  18478. this.source = audioNode;
  18479. this.connect();
  18480. return this;
  18481. }
  18482. setMediaElementSource( mediaElement ) {
  18483. this.hasPlaybackControl = false;
  18484. this.sourceType = 'mediaNode';
  18485. this.source = this.context.createMediaElementSource( mediaElement );
  18486. this.connect();
  18487. return this;
  18488. }
  18489. setMediaStreamSource( mediaStream ) {
  18490. this.hasPlaybackControl = false;
  18491. this.sourceType = 'mediaStreamNode';
  18492. this.source = this.context.createMediaStreamSource( mediaStream );
  18493. this.connect();
  18494. return this;
  18495. }
  18496. setBuffer( audioBuffer ) {
  18497. this.buffer = audioBuffer;
  18498. this.sourceType = 'buffer';
  18499. if ( this.autoplay ) this.play();
  18500. return this;
  18501. }
  18502. play( delay = 0 ) {
  18503. if ( this.isPlaying === true ) {
  18504. console.warn( 'THREE.Audio: Audio is already playing.' );
  18505. return;
  18506. }
  18507. if ( this.hasPlaybackControl === false ) {
  18508. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18509. return;
  18510. }
  18511. this._startedAt = this.context.currentTime + delay;
  18512. const source = this.context.createBufferSource();
  18513. source.buffer = this.buffer;
  18514. source.loop = this.loop;
  18515. source.loopStart = this.loopStart;
  18516. source.loopEnd = this.loopEnd;
  18517. source.onended = this.onEnded.bind( this );
  18518. source.start( this._startedAt, this._progress + this.offset, this.duration );
  18519. this.isPlaying = true;
  18520. this.source = source;
  18521. this.setDetune( this.detune );
  18522. this.setPlaybackRate( this.playbackRate );
  18523. return this.connect();
  18524. }
  18525. pause() {
  18526. if ( this.hasPlaybackControl === false ) {
  18527. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18528. return;
  18529. }
  18530. if ( this.isPlaying === true ) {
  18531. // update current progress
  18532. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  18533. if ( this.loop === true ) {
  18534. // ensure _progress does not exceed duration with looped audios
  18535. this._progress = this._progress % ( this.duration || this.buffer.duration );
  18536. }
  18537. this.source.stop();
  18538. this.source.onended = null;
  18539. this.isPlaying = false;
  18540. }
  18541. return this;
  18542. }
  18543. stop( delay = 0 ) {
  18544. if ( this.hasPlaybackControl === false ) {
  18545. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18546. return;
  18547. }
  18548. this._progress = 0;
  18549. if ( this.source !== null ) {
  18550. this.source.stop( this.context.currentTime + delay );
  18551. this.source.onended = null;
  18552. }
  18553. this.isPlaying = false;
  18554. return this;
  18555. }
  18556. connect() {
  18557. if ( this.filters.length > 0 ) {
  18558. this.source.connect( this.filters[ 0 ] );
  18559. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18560. this.filters[ i - 1 ].connect( this.filters[ i ] );
  18561. }
  18562. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  18563. } else {
  18564. this.source.connect( this.getOutput() );
  18565. }
  18566. this._connected = true;
  18567. return this;
  18568. }
  18569. disconnect() {
  18570. if ( this._connected === false ) {
  18571. return;
  18572. }
  18573. if ( this.filters.length > 0 ) {
  18574. this.source.disconnect( this.filters[ 0 ] );
  18575. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18576. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  18577. }
  18578. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  18579. } else {
  18580. this.source.disconnect( this.getOutput() );
  18581. }
  18582. this._connected = false;
  18583. return this;
  18584. }
  18585. getFilters() {
  18586. return this.filters;
  18587. }
  18588. setFilters( value ) {
  18589. if ( ! value ) value = [];
  18590. if ( this._connected === true ) {
  18591. this.disconnect();
  18592. this.filters = value.slice();
  18593. this.connect();
  18594. } else {
  18595. this.filters = value.slice();
  18596. }
  18597. return this;
  18598. }
  18599. setDetune( value ) {
  18600. this.detune = value;
  18601. if ( this.isPlaying === true && this.source.detune !== undefined ) {
  18602. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  18603. }
  18604. return this;
  18605. }
  18606. getDetune() {
  18607. return this.detune;
  18608. }
  18609. getFilter() {
  18610. return this.getFilters()[ 0 ];
  18611. }
  18612. setFilter( filter ) {
  18613. return this.setFilters( filter ? [ filter ] : [] );
  18614. }
  18615. setPlaybackRate( value ) {
  18616. if ( this.hasPlaybackControl === false ) {
  18617. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18618. return;
  18619. }
  18620. this.playbackRate = value;
  18621. if ( this.isPlaying === true ) {
  18622. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  18623. }
  18624. return this;
  18625. }
  18626. getPlaybackRate() {
  18627. return this.playbackRate;
  18628. }
  18629. onEnded() {
  18630. this.isPlaying = false;
  18631. this._progress = 0;
  18632. }
  18633. getLoop() {
  18634. if ( this.hasPlaybackControl === false ) {
  18635. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18636. return false;
  18637. }
  18638. return this.loop;
  18639. }
  18640. setLoop( value ) {
  18641. if ( this.hasPlaybackControl === false ) {
  18642. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18643. return;
  18644. }
  18645. this.loop = value;
  18646. if ( this.isPlaying === true ) {
  18647. this.source.loop = this.loop;
  18648. }
  18649. return this;
  18650. }
  18651. setLoopStart( value ) {
  18652. this.loopStart = value;
  18653. return this;
  18654. }
  18655. setLoopEnd( value ) {
  18656. this.loopEnd = value;
  18657. return this;
  18658. }
  18659. getVolume() {
  18660. return this.gain.gain.value;
  18661. }
  18662. setVolume( value ) {
  18663. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18664. return this;
  18665. }
  18666. copy( source, recursive ) {
  18667. super.copy( source, recursive );
  18668. if ( source.sourceType !== 'buffer' ) {
  18669. console.warn( 'THREE.Audio: Audio source type cannot be copied.' );
  18670. return this;
  18671. }
  18672. this.autoplay = source.autoplay;
  18673. this.buffer = source.buffer;
  18674. this.detune = source.detune;
  18675. this.loop = source.loop;
  18676. this.loopStart = source.loopStart;
  18677. this.loopEnd = source.loopEnd;
  18678. this.offset = source.offset;
  18679. this.duration = source.duration;
  18680. this.playbackRate = source.playbackRate;
  18681. this.hasPlaybackControl = source.hasPlaybackControl;
  18682. this.sourceType = source.sourceType;
  18683. this.filters = source.filters.slice();
  18684. return this;
  18685. }
  18686. clone( recursive ) {
  18687. return new this.constructor( this.listener ).copy( this, recursive );
  18688. }
  18689. }
  18690. const _position = /*@__PURE__*/ new Vector3();
  18691. const _quaternion = /*@__PURE__*/ new Quaternion();
  18692. const _scale = /*@__PURE__*/ new Vector3();
  18693. const _orientation = /*@__PURE__*/ new Vector3();
  18694. class PositionalAudio extends Audio {
  18695. constructor( listener ) {
  18696. super( listener );
  18697. this.panner = this.context.createPanner();
  18698. this.panner.panningModel = 'HRTF';
  18699. this.panner.connect( this.gain );
  18700. }
  18701. connect() {
  18702. super.connect();
  18703. this.panner.connect( this.gain );
  18704. }
  18705. disconnect() {
  18706. super.disconnect();
  18707. this.panner.disconnect( this.gain );
  18708. }
  18709. getOutput() {
  18710. return this.panner;
  18711. }
  18712. getRefDistance() {
  18713. return this.panner.refDistance;
  18714. }
  18715. setRefDistance( value ) {
  18716. this.panner.refDistance = value;
  18717. return this;
  18718. }
  18719. getRolloffFactor() {
  18720. return this.panner.rolloffFactor;
  18721. }
  18722. setRolloffFactor( value ) {
  18723. this.panner.rolloffFactor = value;
  18724. return this;
  18725. }
  18726. getDistanceModel() {
  18727. return this.panner.distanceModel;
  18728. }
  18729. setDistanceModel( value ) {
  18730. this.panner.distanceModel = value;
  18731. return this;
  18732. }
  18733. getMaxDistance() {
  18734. return this.panner.maxDistance;
  18735. }
  18736. setMaxDistance( value ) {
  18737. this.panner.maxDistance = value;
  18738. return this;
  18739. }
  18740. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  18741. this.panner.coneInnerAngle = coneInnerAngle;
  18742. this.panner.coneOuterAngle = coneOuterAngle;
  18743. this.panner.coneOuterGain = coneOuterGain;
  18744. return this;
  18745. }
  18746. updateMatrixWorld( force ) {
  18747. super.updateMatrixWorld( force );
  18748. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  18749. this.matrixWorld.decompose( _position, _quaternion, _scale );
  18750. _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
  18751. const panner = this.panner;
  18752. if ( panner.positionX ) {
  18753. // code path for Chrome and Firefox (see #14393)
  18754. const endTime = this.context.currentTime + this.listener.timeDelta;
  18755. panner.positionX.linearRampToValueAtTime( _position.x, endTime );
  18756. panner.positionY.linearRampToValueAtTime( _position.y, endTime );
  18757. panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
  18758. panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
  18759. panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
  18760. panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
  18761. } else {
  18762. panner.setPosition( _position.x, _position.y, _position.z );
  18763. panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
  18764. }
  18765. }
  18766. }
  18767. class AudioAnalyser {
  18768. constructor( audio, fftSize = 2048 ) {
  18769. this.analyser = audio.context.createAnalyser();
  18770. this.analyser.fftSize = fftSize;
  18771. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  18772. audio.getOutput().connect( this.analyser );
  18773. }
  18774. getFrequencyData() {
  18775. this.analyser.getByteFrequencyData( this.data );
  18776. return this.data;
  18777. }
  18778. getAverageFrequency() {
  18779. let value = 0;
  18780. const data = this.getFrequencyData();
  18781. for ( let i = 0; i < data.length; i ++ ) {
  18782. value += data[ i ];
  18783. }
  18784. return value / data.length;
  18785. }
  18786. }
  18787. class PropertyMixer {
  18788. constructor( binding, typeName, valueSize ) {
  18789. this.binding = binding;
  18790. this.valueSize = valueSize;
  18791. let mixFunction,
  18792. mixFunctionAdditive,
  18793. setIdentity;
  18794. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  18795. //
  18796. // interpolators can use .buffer as their .result
  18797. // the data then goes to 'incoming'
  18798. //
  18799. // 'accu0' and 'accu1' are used frame-interleaved for
  18800. // the cumulative result and are compared to detect
  18801. // changes
  18802. //
  18803. // 'orig' stores the original state of the property
  18804. //
  18805. // 'add' is used for additive cumulative results
  18806. //
  18807. // 'work' is optional and is only present for quaternion types. It is used
  18808. // to store intermediate quaternion multiplication results
  18809. switch ( typeName ) {
  18810. case 'quaternion':
  18811. mixFunction = this._slerp;
  18812. mixFunctionAdditive = this._slerpAdditive;
  18813. setIdentity = this._setAdditiveIdentityQuaternion;
  18814. this.buffer = new Float64Array( valueSize * 6 );
  18815. this._workIndex = 5;
  18816. break;
  18817. case 'string':
  18818. case 'bool':
  18819. mixFunction = this._select;
  18820. // Use the regular mix function and for additive on these types,
  18821. // additive is not relevant for non-numeric types
  18822. mixFunctionAdditive = this._select;
  18823. setIdentity = this._setAdditiveIdentityOther;
  18824. this.buffer = new Array( valueSize * 5 );
  18825. break;
  18826. default:
  18827. mixFunction = this._lerp;
  18828. mixFunctionAdditive = this._lerpAdditive;
  18829. setIdentity = this._setAdditiveIdentityNumeric;
  18830. this.buffer = new Float64Array( valueSize * 5 );
  18831. }
  18832. this._mixBufferRegion = mixFunction;
  18833. this._mixBufferRegionAdditive = mixFunctionAdditive;
  18834. this._setIdentity = setIdentity;
  18835. this._origIndex = 3;
  18836. this._addIndex = 4;
  18837. this.cumulativeWeight = 0;
  18838. this.cumulativeWeightAdditive = 0;
  18839. this.useCount = 0;
  18840. this.referenceCount = 0;
  18841. }
  18842. // accumulate data in the 'incoming' region into 'accu<i>'
  18843. accumulate( accuIndex, weight ) {
  18844. // note: happily accumulating nothing when weight = 0, the caller knows
  18845. // the weight and shouldn't have made the call in the first place
  18846. const buffer = this.buffer,
  18847. stride = this.valueSize,
  18848. offset = accuIndex * stride + stride;
  18849. let currentWeight = this.cumulativeWeight;
  18850. if ( currentWeight === 0 ) {
  18851. // accuN := incoming * weight
  18852. for ( let i = 0; i !== stride; ++ i ) {
  18853. buffer[ offset + i ] = buffer[ i ];
  18854. }
  18855. currentWeight = weight;
  18856. } else {
  18857. // accuN := accuN + incoming * weight
  18858. currentWeight += weight;
  18859. const mix = weight / currentWeight;
  18860. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  18861. }
  18862. this.cumulativeWeight = currentWeight;
  18863. }
  18864. // accumulate data in the 'incoming' region into 'add'
  18865. accumulateAdditive( weight ) {
  18866. const buffer = this.buffer,
  18867. stride = this.valueSize,
  18868. offset = stride * this._addIndex;
  18869. if ( this.cumulativeWeightAdditive === 0 ) {
  18870. // add = identity
  18871. this._setIdentity();
  18872. }
  18873. // add := add + incoming * weight
  18874. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  18875. this.cumulativeWeightAdditive += weight;
  18876. }
  18877. // apply the state of 'accu<i>' to the binding when accus differ
  18878. apply( accuIndex ) {
  18879. const stride = this.valueSize,
  18880. buffer = this.buffer,
  18881. offset = accuIndex * stride + stride,
  18882. weight = this.cumulativeWeight,
  18883. weightAdditive = this.cumulativeWeightAdditive,
  18884. binding = this.binding;
  18885. this.cumulativeWeight = 0;
  18886. this.cumulativeWeightAdditive = 0;
  18887. if ( weight < 1 ) {
  18888. // accuN := accuN + original * ( 1 - cumulativeWeight )
  18889. const originalValueOffset = stride * this._origIndex;
  18890. this._mixBufferRegion(
  18891. buffer, offset, originalValueOffset, 1 - weight, stride );
  18892. }
  18893. if ( weightAdditive > 0 ) {
  18894. // accuN := accuN + additive accuN
  18895. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  18896. }
  18897. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  18898. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  18899. // value has changed -> update scene graph
  18900. binding.setValue( buffer, offset );
  18901. break;
  18902. }
  18903. }
  18904. }
  18905. // remember the state of the bound property and copy it to both accus
  18906. saveOriginalState() {
  18907. const binding = this.binding;
  18908. const buffer = this.buffer,
  18909. stride = this.valueSize,
  18910. originalValueOffset = stride * this._origIndex;
  18911. binding.getValue( buffer, originalValueOffset );
  18912. // accu[0..1] := orig -- initially detect changes against the original
  18913. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  18914. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  18915. }
  18916. // Add to identity for additive
  18917. this._setIdentity();
  18918. this.cumulativeWeight = 0;
  18919. this.cumulativeWeightAdditive = 0;
  18920. }
  18921. // apply the state previously taken via 'saveOriginalState' to the binding
  18922. restoreOriginalState() {
  18923. const originalValueOffset = this.valueSize * 3;
  18924. this.binding.setValue( this.buffer, originalValueOffset );
  18925. }
  18926. _setAdditiveIdentityNumeric() {
  18927. const startIndex = this._addIndex * this.valueSize;
  18928. const endIndex = startIndex + this.valueSize;
  18929. for ( let i = startIndex; i < endIndex; i ++ ) {
  18930. this.buffer[ i ] = 0;
  18931. }
  18932. }
  18933. _setAdditiveIdentityQuaternion() {
  18934. this._setAdditiveIdentityNumeric();
  18935. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  18936. }
  18937. _setAdditiveIdentityOther() {
  18938. const startIndex = this._origIndex * this.valueSize;
  18939. const targetIndex = this._addIndex * this.valueSize;
  18940. for ( let i = 0; i < this.valueSize; i ++ ) {
  18941. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  18942. }
  18943. }
  18944. // mix functions
  18945. _select( buffer, dstOffset, srcOffset, t, stride ) {
  18946. if ( t >= 0.5 ) {
  18947. for ( let i = 0; i !== stride; ++ i ) {
  18948. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  18949. }
  18950. }
  18951. }
  18952. _slerp( buffer, dstOffset, srcOffset, t ) {
  18953. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  18954. }
  18955. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18956. const workOffset = this._workIndex * stride;
  18957. // Store result in intermediate buffer offset
  18958. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  18959. // Slerp to the intermediate result
  18960. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  18961. }
  18962. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  18963. const s = 1 - t;
  18964. for ( let i = 0; i !== stride; ++ i ) {
  18965. const j = dstOffset + i;
  18966. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  18967. }
  18968. }
  18969. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18970. for ( let i = 0; i !== stride; ++ i ) {
  18971. const j = dstOffset + i;
  18972. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  18973. }
  18974. }
  18975. }
  18976. // Characters [].:/ are reserved for track binding syntax.
  18977. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  18978. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  18979. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  18980. // only latin characters, and the unicode \p{L} is not yet supported. So
  18981. // instead, we exclude reserved characters and match everything else.
  18982. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  18983. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  18984. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  18985. // be matched to parse the rest of the track name.
  18986. const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  18987. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  18988. const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  18989. // Object on target node, and accessor. May not contain reserved
  18990. // characters. Accessor may contain any character except closing bracket.
  18991. const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  18992. // Property and accessor. May not contain reserved characters. Accessor may
  18993. // contain any non-bracket characters.
  18994. const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  18995. const _trackRe = new RegExp( ''
  18996. + '^'
  18997. + _directoryRe
  18998. + _nodeRe
  18999. + _objectRe
  19000. + _propertyRe
  19001. + '$'
  19002. );
  19003. const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ];
  19004. class Composite {
  19005. constructor( targetGroup, path, optionalParsedPath ) {
  19006. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  19007. this._targetGroup = targetGroup;
  19008. this._bindings = targetGroup.subscribe_( path, parsedPath );
  19009. }
  19010. getValue( array, offset ) {
  19011. this.bind(); // bind all binding
  19012. const firstValidIndex = this._targetGroup.nCachedObjects_,
  19013. binding = this._bindings[ firstValidIndex ];
  19014. // and only call .getValue on the first
  19015. if ( binding !== undefined ) binding.getValue( array, offset );
  19016. }
  19017. setValue( array, offset ) {
  19018. const bindings = this._bindings;
  19019. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  19020. bindings[ i ].setValue( array, offset );
  19021. }
  19022. }
  19023. bind() {
  19024. const bindings = this._bindings;
  19025. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  19026. bindings[ i ].bind();
  19027. }
  19028. }
  19029. unbind() {
  19030. const bindings = this._bindings;
  19031. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  19032. bindings[ i ].unbind();
  19033. }
  19034. }
  19035. }
  19036. // Note: This class uses a State pattern on a per-method basis:
  19037. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  19038. // prototype version of these methods with one that represents
  19039. // the bound state. When the property is not found, the methods
  19040. // become no-ops.
  19041. class PropertyBinding {
  19042. constructor( rootNode, path, parsedPath ) {
  19043. this.path = path;
  19044. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  19045. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName );
  19046. this.rootNode = rootNode;
  19047. // initial state of these methods that calls 'bind'
  19048. this.getValue = this._getValue_unbound;
  19049. this.setValue = this._setValue_unbound;
  19050. }
  19051. static create( root, path, parsedPath ) {
  19052. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  19053. return new PropertyBinding( root, path, parsedPath );
  19054. } else {
  19055. return new PropertyBinding.Composite( root, path, parsedPath );
  19056. }
  19057. }
  19058. /**
  19059. * Replaces spaces with underscores and removes unsupported characters from
  19060. * node names, to ensure compatibility with parseTrackName().
  19061. *
  19062. * @param {string} name Node name to be sanitized.
  19063. * @return {string}
  19064. */
  19065. static sanitizeNodeName( name ) {
  19066. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  19067. }
  19068. static parseTrackName( trackName ) {
  19069. const matches = _trackRe.exec( trackName );
  19070. if ( matches === null ) {
  19071. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  19072. }
  19073. const results = {
  19074. // directoryName: matches[ 1 ], // (tschw) currently unused
  19075. nodeName: matches[ 2 ],
  19076. objectName: matches[ 3 ],
  19077. objectIndex: matches[ 4 ],
  19078. propertyName: matches[ 5 ], // required
  19079. propertyIndex: matches[ 6 ]
  19080. };
  19081. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  19082. if ( lastDot !== undefined && lastDot !== -1 ) {
  19083. const objectName = results.nodeName.substring( lastDot + 1 );
  19084. // Object names must be checked against an allowlist. Otherwise, there
  19085. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  19086. // 'bar' could be the objectName, or part of a nodeName (which can
  19087. // include '.' characters).
  19088. if ( _supportedObjectNames.indexOf( objectName ) !== -1 ) {
  19089. results.nodeName = results.nodeName.substring( 0, lastDot );
  19090. results.objectName = objectName;
  19091. }
  19092. }
  19093. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  19094. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  19095. }
  19096. return results;
  19097. }
  19098. static findNode( root, nodeName ) {
  19099. if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  19100. return root;
  19101. }
  19102. // search into skeleton bones.
  19103. if ( root.skeleton ) {
  19104. const bone = root.skeleton.getBoneByName( nodeName );
  19105. if ( bone !== undefined ) {
  19106. return bone;
  19107. }
  19108. }
  19109. // search into node subtree.
  19110. if ( root.children ) {
  19111. const searchNodeSubtree = function ( children ) {
  19112. for ( let i = 0; i < children.length; i ++ ) {
  19113. const childNode = children[ i ];
  19114. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  19115. return childNode;
  19116. }
  19117. const result = searchNodeSubtree( childNode.children );
  19118. if ( result ) return result;
  19119. }
  19120. return null;
  19121. };
  19122. const subTreeNode = searchNodeSubtree( root.children );
  19123. if ( subTreeNode ) {
  19124. return subTreeNode;
  19125. }
  19126. }
  19127. return null;
  19128. }
  19129. // these are used to "bind" a nonexistent property
  19130. _getValue_unavailable() {}
  19131. _setValue_unavailable() {}
  19132. // Getters
  19133. _getValue_direct( buffer, offset ) {
  19134. buffer[ offset ] = this.targetObject[ this.propertyName ];
  19135. }
  19136. _getValue_array( buffer, offset ) {
  19137. const source = this.resolvedProperty;
  19138. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  19139. buffer[ offset ++ ] = source[ i ];
  19140. }
  19141. }
  19142. _getValue_arrayElement( buffer, offset ) {
  19143. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  19144. }
  19145. _getValue_toArray( buffer, offset ) {
  19146. this.resolvedProperty.toArray( buffer, offset );
  19147. }
  19148. // Direct
  19149. _setValue_direct( buffer, offset ) {
  19150. this.targetObject[ this.propertyName ] = buffer[ offset ];
  19151. }
  19152. _setValue_direct_setNeedsUpdate( buffer, offset ) {
  19153. this.targetObject[ this.propertyName ] = buffer[ offset ];
  19154. this.targetObject.needsUpdate = true;
  19155. }
  19156. _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  19157. this.targetObject[ this.propertyName ] = buffer[ offset ];
  19158. this.targetObject.matrixWorldNeedsUpdate = true;
  19159. }
  19160. // EntireArray
  19161. _setValue_array( buffer, offset ) {
  19162. const dest = this.resolvedProperty;
  19163. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  19164. dest[ i ] = buffer[ offset ++ ];
  19165. }
  19166. }
  19167. _setValue_array_setNeedsUpdate( buffer, offset ) {
  19168. const dest = this.resolvedProperty;
  19169. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  19170. dest[ i ] = buffer[ offset ++ ];
  19171. }
  19172. this.targetObject.needsUpdate = true;
  19173. }
  19174. _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  19175. const dest = this.resolvedProperty;
  19176. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  19177. dest[ i ] = buffer[ offset ++ ];
  19178. }
  19179. this.targetObject.matrixWorldNeedsUpdate = true;
  19180. }
  19181. // ArrayElement
  19182. _setValue_arrayElement( buffer, offset ) {
  19183. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  19184. }
  19185. _setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  19186. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  19187. this.targetObject.needsUpdate = true;
  19188. }
  19189. _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  19190. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  19191. this.targetObject.matrixWorldNeedsUpdate = true;
  19192. }
  19193. // HasToFromArray
  19194. _setValue_fromArray( buffer, offset ) {
  19195. this.resolvedProperty.fromArray( buffer, offset );
  19196. }
  19197. _setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  19198. this.resolvedProperty.fromArray( buffer, offset );
  19199. this.targetObject.needsUpdate = true;
  19200. }
  19201. _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  19202. this.resolvedProperty.fromArray( buffer, offset );
  19203. this.targetObject.matrixWorldNeedsUpdate = true;
  19204. }
  19205. _getValue_unbound( targetArray, offset ) {
  19206. this.bind();
  19207. this.getValue( targetArray, offset );
  19208. }
  19209. _setValue_unbound( sourceArray, offset ) {
  19210. this.bind();
  19211. this.setValue( sourceArray, offset );
  19212. }
  19213. // create getter / setter pair for a property in the scene graph
  19214. bind() {
  19215. let targetObject = this.node;
  19216. const parsedPath = this.parsedPath;
  19217. const objectName = parsedPath.objectName;
  19218. const propertyName = parsedPath.propertyName;
  19219. let propertyIndex = parsedPath.propertyIndex;
  19220. if ( ! targetObject ) {
  19221. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName );
  19222. this.node = targetObject;
  19223. }
  19224. // set fail state so we can just 'return' on error
  19225. this.getValue = this._getValue_unavailable;
  19226. this.setValue = this._setValue_unavailable;
  19227. // ensure there is a value node
  19228. if ( ! targetObject ) {
  19229. console.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' );
  19230. return;
  19231. }
  19232. if ( objectName ) {
  19233. let objectIndex = parsedPath.objectIndex;
  19234. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  19235. switch ( objectName ) {
  19236. case 'materials':
  19237. if ( ! targetObject.material ) {
  19238. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19239. return;
  19240. }
  19241. if ( ! targetObject.material.materials ) {
  19242. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  19243. return;
  19244. }
  19245. targetObject = targetObject.material.materials;
  19246. break;
  19247. case 'bones':
  19248. if ( ! targetObject.skeleton ) {
  19249. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  19250. return;
  19251. }
  19252. // potential future optimization: skip this if propertyIndex is already an integer
  19253. // and convert the integer string to a true integer.
  19254. targetObject = targetObject.skeleton.bones;
  19255. // support resolving morphTarget names into indices.
  19256. for ( let i = 0; i < targetObject.length; i ++ ) {
  19257. if ( targetObject[ i ].name === objectIndex ) {
  19258. objectIndex = i;
  19259. break;
  19260. }
  19261. }
  19262. break;
  19263. case 'map':
  19264. if ( 'map' in targetObject ) {
  19265. targetObject = targetObject.map;
  19266. break;
  19267. }
  19268. if ( ! targetObject.material ) {
  19269. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19270. return;
  19271. }
  19272. if ( ! targetObject.material.map ) {
  19273. console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this );
  19274. return;
  19275. }
  19276. targetObject = targetObject.material.map;
  19277. break;
  19278. default:
  19279. if ( targetObject[ objectName ] === undefined ) {
  19280. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  19281. return;
  19282. }
  19283. targetObject = targetObject[ objectName ];
  19284. }
  19285. if ( objectIndex !== undefined ) {
  19286. if ( targetObject[ objectIndex ] === undefined ) {
  19287. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  19288. return;
  19289. }
  19290. targetObject = targetObject[ objectIndex ];
  19291. }
  19292. }
  19293. // resolve property
  19294. const nodeProperty = targetObject[ propertyName ];
  19295. if ( nodeProperty === undefined ) {
  19296. const nodeName = parsedPath.nodeName;
  19297. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  19298. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  19299. return;
  19300. }
  19301. // determine versioning scheme
  19302. let versioning = this.Versioning.None;
  19303. this.targetObject = targetObject;
  19304. if ( targetObject.isMaterial === true ) {
  19305. versioning = this.Versioning.NeedsUpdate;
  19306. } else if ( targetObject.isObject3D === true ) {
  19307. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  19308. }
  19309. // determine how the property gets bound
  19310. let bindingType = this.BindingType.Direct;
  19311. if ( propertyIndex !== undefined ) {
  19312. // access a sub element of the property array (only primitives are supported right now)
  19313. if ( propertyName === 'morphTargetInfluences' ) {
  19314. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  19315. // support resolving morphTarget names into indices.
  19316. if ( ! targetObject.geometry ) {
  19317. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  19318. return;
  19319. }
  19320. if ( ! targetObject.geometry.morphAttributes ) {
  19321. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  19322. return;
  19323. }
  19324. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  19325. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  19326. }
  19327. }
  19328. bindingType = this.BindingType.ArrayElement;
  19329. this.resolvedProperty = nodeProperty;
  19330. this.propertyIndex = propertyIndex;
  19331. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  19332. // must use copy for Object3D.Euler/Quaternion
  19333. bindingType = this.BindingType.HasFromToArray;
  19334. this.resolvedProperty = nodeProperty;
  19335. } else if ( Array.isArray( nodeProperty ) ) {
  19336. bindingType = this.BindingType.EntireArray;
  19337. this.resolvedProperty = nodeProperty;
  19338. } else {
  19339. this.propertyName = propertyName;
  19340. }
  19341. // select getter / setter
  19342. this.getValue = this.GetterByBindingType[ bindingType ];
  19343. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  19344. }
  19345. unbind() {
  19346. this.node = null;
  19347. // back to the prototype version of getValue / setValue
  19348. // note: avoiding to mutate the shape of 'this' via 'delete'
  19349. this.getValue = this._getValue_unbound;
  19350. this.setValue = this._setValue_unbound;
  19351. }
  19352. }
  19353. PropertyBinding.Composite = Composite;
  19354. PropertyBinding.prototype.BindingType = {
  19355. Direct: 0,
  19356. EntireArray: 1,
  19357. ArrayElement: 2,
  19358. HasFromToArray: 3
  19359. };
  19360. PropertyBinding.prototype.Versioning = {
  19361. None: 0,
  19362. NeedsUpdate: 1,
  19363. MatrixWorldNeedsUpdate: 2
  19364. };
  19365. PropertyBinding.prototype.GetterByBindingType = [
  19366. PropertyBinding.prototype._getValue_direct,
  19367. PropertyBinding.prototype._getValue_array,
  19368. PropertyBinding.prototype._getValue_arrayElement,
  19369. PropertyBinding.prototype._getValue_toArray,
  19370. ];
  19371. PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
  19372. [
  19373. // Direct
  19374. PropertyBinding.prototype._setValue_direct,
  19375. PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
  19376. PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
  19377. ], [
  19378. // EntireArray
  19379. PropertyBinding.prototype._setValue_array,
  19380. PropertyBinding.prototype._setValue_array_setNeedsUpdate,
  19381. PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
  19382. ], [
  19383. // ArrayElement
  19384. PropertyBinding.prototype._setValue_arrayElement,
  19385. PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
  19386. PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
  19387. ], [
  19388. // HasToFromArray
  19389. PropertyBinding.prototype._setValue_fromArray,
  19390. PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
  19391. PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
  19392. ]
  19393. ];
  19394. /**
  19395. *
  19396. * A group of objects that receives a shared animation state.
  19397. *
  19398. * Usage:
  19399. *
  19400. * - Add objects you would otherwise pass as 'root' to the
  19401. * constructor or the .clipAction method of AnimationMixer.
  19402. *
  19403. * - Instead pass this object as 'root'.
  19404. *
  19405. * - You can also add and remove objects later when the mixer
  19406. * is running.
  19407. *
  19408. * Note:
  19409. *
  19410. * Objects of this class appear as one object to the mixer,
  19411. * so cache control of the individual objects must be done
  19412. * on the group.
  19413. *
  19414. * Limitation:
  19415. *
  19416. * - The animated properties must be compatible among the
  19417. * all objects in the group.
  19418. *
  19419. * - A single property can either be controlled through a
  19420. * target group or directly, but not both.
  19421. */
  19422. class AnimationObjectGroup {
  19423. constructor() {
  19424. this.isAnimationObjectGroup = true;
  19425. this.uuid = generateUUID();
  19426. // cached objects followed by the active ones
  19427. this._objects = Array.prototype.slice.call( arguments );
  19428. this.nCachedObjects_ = 0; // threshold
  19429. // note: read by PropertyBinding.Composite
  19430. const indices = {};
  19431. this._indicesByUUID = indices; // for bookkeeping
  19432. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19433. indices[ arguments[ i ].uuid ] = i;
  19434. }
  19435. this._paths = []; // inside: string
  19436. this._parsedPaths = []; // inside: { we don't care, here }
  19437. this._bindings = []; // inside: Array< PropertyBinding >
  19438. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  19439. const scope = this;
  19440. this.stats = {
  19441. objects: {
  19442. get total() {
  19443. return scope._objects.length;
  19444. },
  19445. get inUse() {
  19446. return this.total - scope.nCachedObjects_;
  19447. }
  19448. },
  19449. get bindingsPerObject() {
  19450. return scope._bindings.length;
  19451. }
  19452. };
  19453. }
  19454. add() {
  19455. const objects = this._objects,
  19456. indicesByUUID = this._indicesByUUID,
  19457. paths = this._paths,
  19458. parsedPaths = this._parsedPaths,
  19459. bindings = this._bindings,
  19460. nBindings = bindings.length;
  19461. let knownObject = undefined,
  19462. nObjects = objects.length,
  19463. nCachedObjects = this.nCachedObjects_;
  19464. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19465. const object = arguments[ i ],
  19466. uuid = object.uuid;
  19467. let index = indicesByUUID[ uuid ];
  19468. if ( index === undefined ) {
  19469. // unknown object -> add it to the ACTIVE region
  19470. index = nObjects ++;
  19471. indicesByUUID[ uuid ] = index;
  19472. objects.push( object );
  19473. // accounting is done, now do the same for all bindings
  19474. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19475. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  19476. }
  19477. } else if ( index < nCachedObjects ) {
  19478. knownObject = objects[ index ];
  19479. // move existing object to the ACTIVE region
  19480. const firstActiveIndex = -- nCachedObjects,
  19481. lastCachedObject = objects[ firstActiveIndex ];
  19482. indicesByUUID[ lastCachedObject.uuid ] = index;
  19483. objects[ index ] = lastCachedObject;
  19484. indicesByUUID[ uuid ] = firstActiveIndex;
  19485. objects[ firstActiveIndex ] = object;
  19486. // accounting is done, now do the same for all bindings
  19487. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19488. const bindingsForPath = bindings[ j ],
  19489. lastCached = bindingsForPath[ firstActiveIndex ];
  19490. let binding = bindingsForPath[ index ];
  19491. bindingsForPath[ index ] = lastCached;
  19492. if ( binding === undefined ) {
  19493. // since we do not bother to create new bindings
  19494. // for objects that are cached, the binding may
  19495. // or may not exist
  19496. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  19497. }
  19498. bindingsForPath[ firstActiveIndex ] = binding;
  19499. }
  19500. } else if ( objects[ index ] !== knownObject ) {
  19501. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  19502. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  19503. } // else the object is already where we want it to be
  19504. } // for arguments
  19505. this.nCachedObjects_ = nCachedObjects;
  19506. }
  19507. remove() {
  19508. const objects = this._objects,
  19509. indicesByUUID = this._indicesByUUID,
  19510. bindings = this._bindings,
  19511. nBindings = bindings.length;
  19512. let nCachedObjects = this.nCachedObjects_;
  19513. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19514. const object = arguments[ i ],
  19515. uuid = object.uuid,
  19516. index = indicesByUUID[ uuid ];
  19517. if ( index !== undefined && index >= nCachedObjects ) {
  19518. // move existing object into the CACHED region
  19519. const lastCachedIndex = nCachedObjects ++,
  19520. firstActiveObject = objects[ lastCachedIndex ];
  19521. indicesByUUID[ firstActiveObject.uuid ] = index;
  19522. objects[ index ] = firstActiveObject;
  19523. indicesByUUID[ uuid ] = lastCachedIndex;
  19524. objects[ lastCachedIndex ] = object;
  19525. // accounting is done, now do the same for all bindings
  19526. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19527. const bindingsForPath = bindings[ j ],
  19528. firstActive = bindingsForPath[ lastCachedIndex ],
  19529. binding = bindingsForPath[ index ];
  19530. bindingsForPath[ index ] = firstActive;
  19531. bindingsForPath[ lastCachedIndex ] = binding;
  19532. }
  19533. }
  19534. } // for arguments
  19535. this.nCachedObjects_ = nCachedObjects;
  19536. }
  19537. // remove & forget
  19538. uncache() {
  19539. const objects = this._objects,
  19540. indicesByUUID = this._indicesByUUID,
  19541. bindings = this._bindings,
  19542. nBindings = bindings.length;
  19543. let nCachedObjects = this.nCachedObjects_,
  19544. nObjects = objects.length;
  19545. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19546. const object = arguments[ i ],
  19547. uuid = object.uuid,
  19548. index = indicesByUUID[ uuid ];
  19549. if ( index !== undefined ) {
  19550. delete indicesByUUID[ uuid ];
  19551. if ( index < nCachedObjects ) {
  19552. // object is cached, shrink the CACHED region
  19553. const firstActiveIndex = -- nCachedObjects,
  19554. lastCachedObject = objects[ firstActiveIndex ],
  19555. lastIndex = -- nObjects,
  19556. lastObject = objects[ lastIndex ];
  19557. // last cached object takes this object's place
  19558. indicesByUUID[ lastCachedObject.uuid ] = index;
  19559. objects[ index ] = lastCachedObject;
  19560. // last object goes to the activated slot and pop
  19561. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  19562. objects[ firstActiveIndex ] = lastObject;
  19563. objects.pop();
  19564. // accounting is done, now do the same for all bindings
  19565. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19566. const bindingsForPath = bindings[ j ],
  19567. lastCached = bindingsForPath[ firstActiveIndex ],
  19568. last = bindingsForPath[ lastIndex ];
  19569. bindingsForPath[ index ] = lastCached;
  19570. bindingsForPath[ firstActiveIndex ] = last;
  19571. bindingsForPath.pop();
  19572. }
  19573. } else {
  19574. // object is active, just swap with the last and pop
  19575. const lastIndex = -- nObjects,
  19576. lastObject = objects[ lastIndex ];
  19577. if ( lastIndex > 0 ) {
  19578. indicesByUUID[ lastObject.uuid ] = index;
  19579. }
  19580. objects[ index ] = lastObject;
  19581. objects.pop();
  19582. // accounting is done, now do the same for all bindings
  19583. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19584. const bindingsForPath = bindings[ j ];
  19585. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  19586. bindingsForPath.pop();
  19587. }
  19588. } // cached or active
  19589. } // if object is known
  19590. } // for arguments
  19591. this.nCachedObjects_ = nCachedObjects;
  19592. }
  19593. // Internal interface used by befriended PropertyBinding.Composite:
  19594. subscribe_( path, parsedPath ) {
  19595. // returns an array of bindings for the given path that is changed
  19596. // according to the contained objects in the group
  19597. const indicesByPath = this._bindingsIndicesByPath;
  19598. let index = indicesByPath[ path ];
  19599. const bindings = this._bindings;
  19600. if ( index !== undefined ) return bindings[ index ];
  19601. const paths = this._paths,
  19602. parsedPaths = this._parsedPaths,
  19603. objects = this._objects,
  19604. nObjects = objects.length,
  19605. nCachedObjects = this.nCachedObjects_,
  19606. bindingsForPath = new Array( nObjects );
  19607. index = bindings.length;
  19608. indicesByPath[ path ] = index;
  19609. paths.push( path );
  19610. parsedPaths.push( parsedPath );
  19611. bindings.push( bindingsForPath );
  19612. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  19613. const object = objects[ i ];
  19614. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  19615. }
  19616. return bindingsForPath;
  19617. }
  19618. unsubscribe_( path ) {
  19619. // tells the group to forget about a property path and no longer
  19620. // update the array previously obtained with 'subscribe_'
  19621. const indicesByPath = this._bindingsIndicesByPath,
  19622. index = indicesByPath[ path ];
  19623. if ( index !== undefined ) {
  19624. const paths = this._paths,
  19625. parsedPaths = this._parsedPaths,
  19626. bindings = this._bindings,
  19627. lastBindingsIndex = bindings.length - 1,
  19628. lastBindings = bindings[ lastBindingsIndex ],
  19629. lastBindingsPath = path[ lastBindingsIndex ];
  19630. indicesByPath[ lastBindingsPath ] = index;
  19631. bindings[ index ] = lastBindings;
  19632. bindings.pop();
  19633. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  19634. parsedPaths.pop();
  19635. paths[ index ] = paths[ lastBindingsIndex ];
  19636. paths.pop();
  19637. }
  19638. }
  19639. }
  19640. class AnimationAction {
  19641. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  19642. this._mixer = mixer;
  19643. this._clip = clip;
  19644. this._localRoot = localRoot;
  19645. this.blendMode = blendMode;
  19646. const tracks = clip.tracks,
  19647. nTracks = tracks.length,
  19648. interpolants = new Array( nTracks );
  19649. const interpolantSettings = {
  19650. endingStart: ZeroCurvatureEnding,
  19651. endingEnd: ZeroCurvatureEnding
  19652. };
  19653. for ( let i = 0; i !== nTracks; ++ i ) {
  19654. const interpolant = tracks[ i ].createInterpolant( null );
  19655. interpolants[ i ] = interpolant;
  19656. interpolant.settings = interpolantSettings;
  19657. }
  19658. this._interpolantSettings = interpolantSettings;
  19659. this._interpolants = interpolants; // bound by the mixer
  19660. // inside: PropertyMixer (managed by the mixer)
  19661. this._propertyBindings = new Array( nTracks );
  19662. this._cacheIndex = null; // for the memory manager
  19663. this._byClipCacheIndex = null; // for the memory manager
  19664. this._timeScaleInterpolant = null;
  19665. this._weightInterpolant = null;
  19666. this.loop = LoopRepeat;
  19667. this._loopCount = -1;
  19668. // global mixer time when the action is to be started
  19669. // it's set back to 'null' upon start of the action
  19670. this._startTime = null;
  19671. // scaled local time of the action
  19672. // gets clamped or wrapped to 0..clip.duration according to loop
  19673. this.time = 0;
  19674. this.timeScale = 1;
  19675. this._effectiveTimeScale = 1;
  19676. this.weight = 1;
  19677. this._effectiveWeight = 1;
  19678. this.repetitions = Infinity; // no. of repetitions when looping
  19679. this.paused = false; // true -> zero effective time scale
  19680. this.enabled = true; // false -> zero effective weight
  19681. this.clampWhenFinished = false;// keep feeding the last frame?
  19682. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  19683. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  19684. }
  19685. // State & Scheduling
  19686. play() {
  19687. this._mixer._activateAction( this );
  19688. return this;
  19689. }
  19690. stop() {
  19691. this._mixer._deactivateAction( this );
  19692. return this.reset();
  19693. }
  19694. reset() {
  19695. this.paused = false;
  19696. this.enabled = true;
  19697. this.time = 0; // restart clip
  19698. this._loopCount = -1;// forget previous loops
  19699. this._startTime = null;// forget scheduling
  19700. return this.stopFading().stopWarping();
  19701. }
  19702. isRunning() {
  19703. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  19704. this._startTime === null && this._mixer._isActiveAction( this );
  19705. }
  19706. // return true when play has been called
  19707. isScheduled() {
  19708. return this._mixer._isActiveAction( this );
  19709. }
  19710. startAt( time ) {
  19711. this._startTime = time;
  19712. return this;
  19713. }
  19714. setLoop( mode, repetitions ) {
  19715. this.loop = mode;
  19716. this.repetitions = repetitions;
  19717. return this;
  19718. }
  19719. // Weight
  19720. // set the weight stopping any scheduled fading
  19721. // although .enabled = false yields an effective weight of zero, this
  19722. // method does *not* change .enabled, because it would be confusing
  19723. setEffectiveWeight( weight ) {
  19724. this.weight = weight;
  19725. // note: same logic as when updated at runtime
  19726. this._effectiveWeight = this.enabled ? weight : 0;
  19727. return this.stopFading();
  19728. }
  19729. // return the weight considering fading and .enabled
  19730. getEffectiveWeight() {
  19731. return this._effectiveWeight;
  19732. }
  19733. fadeIn( duration ) {
  19734. return this._scheduleFading( duration, 0, 1 );
  19735. }
  19736. fadeOut( duration ) {
  19737. return this._scheduleFading( duration, 1, 0 );
  19738. }
  19739. crossFadeFrom( fadeOutAction, duration, warp ) {
  19740. fadeOutAction.fadeOut( duration );
  19741. this.fadeIn( duration );
  19742. if ( warp ) {
  19743. const fadeInDuration = this._clip.duration,
  19744. fadeOutDuration = fadeOutAction._clip.duration,
  19745. startEndRatio = fadeOutDuration / fadeInDuration,
  19746. endStartRatio = fadeInDuration / fadeOutDuration;
  19747. fadeOutAction.warp( 1.0, startEndRatio, duration );
  19748. this.warp( endStartRatio, 1.0, duration );
  19749. }
  19750. return this;
  19751. }
  19752. crossFadeTo( fadeInAction, duration, warp ) {
  19753. return fadeInAction.crossFadeFrom( this, duration, warp );
  19754. }
  19755. stopFading() {
  19756. const weightInterpolant = this._weightInterpolant;
  19757. if ( weightInterpolant !== null ) {
  19758. this._weightInterpolant = null;
  19759. this._mixer._takeBackControlInterpolant( weightInterpolant );
  19760. }
  19761. return this;
  19762. }
  19763. // Time Scale Control
  19764. // set the time scale stopping any scheduled warping
  19765. // although .paused = true yields an effective time scale of zero, this
  19766. // method does *not* change .paused, because it would be confusing
  19767. setEffectiveTimeScale( timeScale ) {
  19768. this.timeScale = timeScale;
  19769. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  19770. return this.stopWarping();
  19771. }
  19772. // return the time scale considering warping and .paused
  19773. getEffectiveTimeScale() {
  19774. return this._effectiveTimeScale;
  19775. }
  19776. setDuration( duration ) {
  19777. this.timeScale = this._clip.duration / duration;
  19778. return this.stopWarping();
  19779. }
  19780. syncWith( action ) {
  19781. this.time = action.time;
  19782. this.timeScale = action.timeScale;
  19783. return this.stopWarping();
  19784. }
  19785. halt( duration ) {
  19786. return this.warp( this._effectiveTimeScale, 0, duration );
  19787. }
  19788. warp( startTimeScale, endTimeScale, duration ) {
  19789. const mixer = this._mixer,
  19790. now = mixer.time,
  19791. timeScale = this.timeScale;
  19792. let interpolant = this._timeScaleInterpolant;
  19793. if ( interpolant === null ) {
  19794. interpolant = mixer._lendControlInterpolant();
  19795. this._timeScaleInterpolant = interpolant;
  19796. }
  19797. const times = interpolant.parameterPositions,
  19798. values = interpolant.sampleValues;
  19799. times[ 0 ] = now;
  19800. times[ 1 ] = now + duration;
  19801. values[ 0 ] = startTimeScale / timeScale;
  19802. values[ 1 ] = endTimeScale / timeScale;
  19803. return this;
  19804. }
  19805. stopWarping() {
  19806. const timeScaleInterpolant = this._timeScaleInterpolant;
  19807. if ( timeScaleInterpolant !== null ) {
  19808. this._timeScaleInterpolant = null;
  19809. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  19810. }
  19811. return this;
  19812. }
  19813. // Object Accessors
  19814. getMixer() {
  19815. return this._mixer;
  19816. }
  19817. getClip() {
  19818. return this._clip;
  19819. }
  19820. getRoot() {
  19821. return this._localRoot || this._mixer._root;
  19822. }
  19823. // Interna
  19824. _update( time, deltaTime, timeDirection, accuIndex ) {
  19825. // called by the mixer
  19826. if ( ! this.enabled ) {
  19827. // call ._updateWeight() to update ._effectiveWeight
  19828. this._updateWeight( time );
  19829. return;
  19830. }
  19831. const startTime = this._startTime;
  19832. if ( startTime !== null ) {
  19833. // check for scheduled start of action
  19834. const timeRunning = ( time - startTime ) * timeDirection;
  19835. if ( timeRunning < 0 || timeDirection === 0 ) {
  19836. deltaTime = 0;
  19837. } else {
  19838. this._startTime = null; // unschedule
  19839. deltaTime = timeDirection * timeRunning;
  19840. }
  19841. }
  19842. // apply time scale and advance time
  19843. deltaTime *= this._updateTimeScale( time );
  19844. const clipTime = this._updateTime( deltaTime );
  19845. // note: _updateTime may disable the action resulting in
  19846. // an effective weight of 0
  19847. const weight = this._updateWeight( time );
  19848. if ( weight > 0 ) {
  19849. const interpolants = this._interpolants;
  19850. const propertyMixers = this._propertyBindings;
  19851. switch ( this.blendMode ) {
  19852. case AdditiveAnimationBlendMode:
  19853. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19854. interpolants[ j ].evaluate( clipTime );
  19855. propertyMixers[ j ].accumulateAdditive( weight );
  19856. }
  19857. break;
  19858. case NormalAnimationBlendMode:
  19859. default:
  19860. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19861. interpolants[ j ].evaluate( clipTime );
  19862. propertyMixers[ j ].accumulate( accuIndex, weight );
  19863. }
  19864. }
  19865. }
  19866. }
  19867. _updateWeight( time ) {
  19868. let weight = 0;
  19869. if ( this.enabled ) {
  19870. weight = this.weight;
  19871. const interpolant = this._weightInterpolant;
  19872. if ( interpolant !== null ) {
  19873. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19874. weight *= interpolantValue;
  19875. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19876. this.stopFading();
  19877. if ( interpolantValue === 0 ) {
  19878. // faded out, disable
  19879. this.enabled = false;
  19880. }
  19881. }
  19882. }
  19883. }
  19884. this._effectiveWeight = weight;
  19885. return weight;
  19886. }
  19887. _updateTimeScale( time ) {
  19888. let timeScale = 0;
  19889. if ( ! this.paused ) {
  19890. timeScale = this.timeScale;
  19891. const interpolant = this._timeScaleInterpolant;
  19892. if ( interpolant !== null ) {
  19893. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19894. timeScale *= interpolantValue;
  19895. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19896. this.stopWarping();
  19897. if ( timeScale === 0 ) {
  19898. // motion has halted, pause
  19899. this.paused = true;
  19900. } else {
  19901. // warp done - apply final time scale
  19902. this.timeScale = timeScale;
  19903. }
  19904. }
  19905. }
  19906. }
  19907. this._effectiveTimeScale = timeScale;
  19908. return timeScale;
  19909. }
  19910. _updateTime( deltaTime ) {
  19911. const duration = this._clip.duration;
  19912. const loop = this.loop;
  19913. let time = this.time + deltaTime;
  19914. let loopCount = this._loopCount;
  19915. const pingPong = ( loop === LoopPingPong );
  19916. if ( deltaTime === 0 ) {
  19917. if ( loopCount === -1 ) return time;
  19918. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  19919. }
  19920. if ( loop === LoopOnce ) {
  19921. if ( loopCount === -1 ) {
  19922. // just started
  19923. this._loopCount = 0;
  19924. this._setEndings( true, true, false );
  19925. }
  19926. handle_stop: {
  19927. if ( time >= duration ) {
  19928. time = duration;
  19929. } else if ( time < 0 ) {
  19930. time = 0;
  19931. } else {
  19932. this.time = time;
  19933. break handle_stop;
  19934. }
  19935. if ( this.clampWhenFinished ) this.paused = true;
  19936. else this.enabled = false;
  19937. this.time = time;
  19938. this._mixer.dispatchEvent( {
  19939. type: 'finished', action: this,
  19940. direction: deltaTime < 0 ? -1 : 1
  19941. } );
  19942. }
  19943. } else { // repetitive Repeat or PingPong
  19944. if ( loopCount === -1 ) {
  19945. // just started
  19946. if ( deltaTime >= 0 ) {
  19947. loopCount = 0;
  19948. this._setEndings( true, this.repetitions === 0, pingPong );
  19949. } else {
  19950. // when looping in reverse direction, the initial
  19951. // transition through zero counts as a repetition,
  19952. // so leave loopCount at -1
  19953. this._setEndings( this.repetitions === 0, true, pingPong );
  19954. }
  19955. }
  19956. if ( time >= duration || time < 0 ) {
  19957. // wrap around
  19958. const loopDelta = Math.floor( time / duration ); // signed
  19959. time -= duration * loopDelta;
  19960. loopCount += Math.abs( loopDelta );
  19961. const pending = this.repetitions - loopCount;
  19962. if ( pending <= 0 ) {
  19963. // have to stop (switch state, clamp time, fire event)
  19964. if ( this.clampWhenFinished ) this.paused = true;
  19965. else this.enabled = false;
  19966. time = deltaTime > 0 ? duration : 0;
  19967. this.time = time;
  19968. this._mixer.dispatchEvent( {
  19969. type: 'finished', action: this,
  19970. direction: deltaTime > 0 ? 1 : -1
  19971. } );
  19972. } else {
  19973. // keep running
  19974. if ( pending === 1 ) {
  19975. // entering the last round
  19976. const atStart = deltaTime < 0;
  19977. this._setEndings( atStart, ! atStart, pingPong );
  19978. } else {
  19979. this._setEndings( false, false, pingPong );
  19980. }
  19981. this._loopCount = loopCount;
  19982. this.time = time;
  19983. this._mixer.dispatchEvent( {
  19984. type: 'loop', action: this, loopDelta: loopDelta
  19985. } );
  19986. }
  19987. } else {
  19988. this.time = time;
  19989. }
  19990. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  19991. // invert time for the "pong round"
  19992. return duration - time;
  19993. }
  19994. }
  19995. return time;
  19996. }
  19997. _setEndings( atStart, atEnd, pingPong ) {
  19998. const settings = this._interpolantSettings;
  19999. if ( pingPong ) {
  20000. settings.endingStart = ZeroSlopeEnding;
  20001. settings.endingEnd = ZeroSlopeEnding;
  20002. } else {
  20003. // assuming for LoopOnce atStart == atEnd == true
  20004. if ( atStart ) {
  20005. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  20006. } else {
  20007. settings.endingStart = WrapAroundEnding;
  20008. }
  20009. if ( atEnd ) {
  20010. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  20011. } else {
  20012. settings.endingEnd = WrapAroundEnding;
  20013. }
  20014. }
  20015. }
  20016. _scheduleFading( duration, weightNow, weightThen ) {
  20017. const mixer = this._mixer, now = mixer.time;
  20018. let interpolant = this._weightInterpolant;
  20019. if ( interpolant === null ) {
  20020. interpolant = mixer._lendControlInterpolant();
  20021. this._weightInterpolant = interpolant;
  20022. }
  20023. const times = interpolant.parameterPositions,
  20024. values = interpolant.sampleValues;
  20025. times[ 0 ] = now;
  20026. values[ 0 ] = weightNow;
  20027. times[ 1 ] = now + duration;
  20028. values[ 1 ] = weightThen;
  20029. return this;
  20030. }
  20031. }
  20032. const _controlInterpolantsResultBuffer = new Float32Array( 1 );
  20033. class AnimationMixer extends EventDispatcher {
  20034. constructor( root ) {
  20035. super();
  20036. this._root = root;
  20037. this._initMemoryManager();
  20038. this._accuIndex = 0;
  20039. this.time = 0;
  20040. this.timeScale = 1.0;
  20041. }
  20042. _bindAction( action, prototypeAction ) {
  20043. const root = action._localRoot || this._root,
  20044. tracks = action._clip.tracks,
  20045. nTracks = tracks.length,
  20046. bindings = action._propertyBindings,
  20047. interpolants = action._interpolants,
  20048. rootUuid = root.uuid,
  20049. bindingsByRoot = this._bindingsByRootAndName;
  20050. let bindingsByName = bindingsByRoot[ rootUuid ];
  20051. if ( bindingsByName === undefined ) {
  20052. bindingsByName = {};
  20053. bindingsByRoot[ rootUuid ] = bindingsByName;
  20054. }
  20055. for ( let i = 0; i !== nTracks; ++ i ) {
  20056. const track = tracks[ i ],
  20057. trackName = track.name;
  20058. let binding = bindingsByName[ trackName ];
  20059. if ( binding !== undefined ) {
  20060. ++ binding.referenceCount;
  20061. bindings[ i ] = binding;
  20062. } else {
  20063. binding = bindings[ i ];
  20064. if ( binding !== undefined ) {
  20065. // existing binding, make sure the cache knows
  20066. if ( binding._cacheIndex === null ) {
  20067. ++ binding.referenceCount;
  20068. this._addInactiveBinding( binding, rootUuid, trackName );
  20069. }
  20070. continue;
  20071. }
  20072. const path = prototypeAction && prototypeAction.
  20073. _propertyBindings[ i ].binding.parsedPath;
  20074. binding = new PropertyMixer(
  20075. PropertyBinding.create( root, trackName, path ),
  20076. track.ValueTypeName, track.getValueSize() );
  20077. ++ binding.referenceCount;
  20078. this._addInactiveBinding( binding, rootUuid, trackName );
  20079. bindings[ i ] = binding;
  20080. }
  20081. interpolants[ i ].resultBuffer = binding.buffer;
  20082. }
  20083. }
  20084. _activateAction( action ) {
  20085. if ( ! this._isActiveAction( action ) ) {
  20086. if ( action._cacheIndex === null ) {
  20087. // this action has been forgotten by the cache, but the user
  20088. // appears to be still using it -> rebind
  20089. const rootUuid = ( action._localRoot || this._root ).uuid,
  20090. clipUuid = action._clip.uuid,
  20091. actionsForClip = this._actionsByClip[ clipUuid ];
  20092. this._bindAction( action,
  20093. actionsForClip && actionsForClip.knownActions[ 0 ] );
  20094. this._addInactiveAction( action, clipUuid, rootUuid );
  20095. }
  20096. const bindings = action._propertyBindings;
  20097. // increment reference counts / sort out state
  20098. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  20099. const binding = bindings[ i ];
  20100. if ( binding.useCount ++ === 0 ) {
  20101. this._lendBinding( binding );
  20102. binding.saveOriginalState();
  20103. }
  20104. }
  20105. this._lendAction( action );
  20106. }
  20107. }
  20108. _deactivateAction( action ) {
  20109. if ( this._isActiveAction( action ) ) {
  20110. const bindings = action._propertyBindings;
  20111. // decrement reference counts / sort out state
  20112. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  20113. const binding = bindings[ i ];
  20114. if ( -- binding.useCount === 0 ) {
  20115. binding.restoreOriginalState();
  20116. this._takeBackBinding( binding );
  20117. }
  20118. }
  20119. this._takeBackAction( action );
  20120. }
  20121. }
  20122. // Memory manager
  20123. _initMemoryManager() {
  20124. this._actions = []; // 'nActiveActions' followed by inactive ones
  20125. this._nActiveActions = 0;
  20126. this._actionsByClip = {};
  20127. // inside:
  20128. // {
  20129. // knownActions: Array< AnimationAction > - used as prototypes
  20130. // actionByRoot: AnimationAction - lookup
  20131. // }
  20132. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  20133. this._nActiveBindings = 0;
  20134. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  20135. this._controlInterpolants = []; // same game as above
  20136. this._nActiveControlInterpolants = 0;
  20137. const scope = this;
  20138. this.stats = {
  20139. actions: {
  20140. get total() {
  20141. return scope._actions.length;
  20142. },
  20143. get inUse() {
  20144. return scope._nActiveActions;
  20145. }
  20146. },
  20147. bindings: {
  20148. get total() {
  20149. return scope._bindings.length;
  20150. },
  20151. get inUse() {
  20152. return scope._nActiveBindings;
  20153. }
  20154. },
  20155. controlInterpolants: {
  20156. get total() {
  20157. return scope._controlInterpolants.length;
  20158. },
  20159. get inUse() {
  20160. return scope._nActiveControlInterpolants;
  20161. }
  20162. }
  20163. };
  20164. }
  20165. // Memory management for AnimationAction objects
  20166. _isActiveAction( action ) {
  20167. const index = action._cacheIndex;
  20168. return index !== null && index < this._nActiveActions;
  20169. }
  20170. _addInactiveAction( action, clipUuid, rootUuid ) {
  20171. const actions = this._actions,
  20172. actionsByClip = this._actionsByClip;
  20173. let actionsForClip = actionsByClip[ clipUuid ];
  20174. if ( actionsForClip === undefined ) {
  20175. actionsForClip = {
  20176. knownActions: [ action ],
  20177. actionByRoot: {}
  20178. };
  20179. action._byClipCacheIndex = 0;
  20180. actionsByClip[ clipUuid ] = actionsForClip;
  20181. } else {
  20182. const knownActions = actionsForClip.knownActions;
  20183. action._byClipCacheIndex = knownActions.length;
  20184. knownActions.push( action );
  20185. }
  20186. action._cacheIndex = actions.length;
  20187. actions.push( action );
  20188. actionsForClip.actionByRoot[ rootUuid ] = action;
  20189. }
  20190. _removeInactiveAction( action ) {
  20191. const actions = this._actions,
  20192. lastInactiveAction = actions[ actions.length - 1 ],
  20193. cacheIndex = action._cacheIndex;
  20194. lastInactiveAction._cacheIndex = cacheIndex;
  20195. actions[ cacheIndex ] = lastInactiveAction;
  20196. actions.pop();
  20197. action._cacheIndex = null;
  20198. const clipUuid = action._clip.uuid,
  20199. actionsByClip = this._actionsByClip,
  20200. actionsForClip = actionsByClip[ clipUuid ],
  20201. knownActionsForClip = actionsForClip.knownActions,
  20202. lastKnownAction =
  20203. knownActionsForClip[ knownActionsForClip.length - 1 ],
  20204. byClipCacheIndex = action._byClipCacheIndex;
  20205. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  20206. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  20207. knownActionsForClip.pop();
  20208. action._byClipCacheIndex = null;
  20209. const actionByRoot = actionsForClip.actionByRoot,
  20210. rootUuid = ( action._localRoot || this._root ).uuid;
  20211. delete actionByRoot[ rootUuid ];
  20212. if ( knownActionsForClip.length === 0 ) {
  20213. delete actionsByClip[ clipUuid ];
  20214. }
  20215. this._removeInactiveBindingsForAction( action );
  20216. }
  20217. _removeInactiveBindingsForAction( action ) {
  20218. const bindings = action._propertyBindings;
  20219. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  20220. const binding = bindings[ i ];
  20221. if ( -- binding.referenceCount === 0 ) {
  20222. this._removeInactiveBinding( binding );
  20223. }
  20224. }
  20225. }
  20226. _lendAction( action ) {
  20227. // [ active actions | inactive actions ]
  20228. // [ active actions >| inactive actions ]
  20229. // s a
  20230. // <-swap->
  20231. // a s
  20232. const actions = this._actions,
  20233. prevIndex = action._cacheIndex,
  20234. lastActiveIndex = this._nActiveActions ++,
  20235. firstInactiveAction = actions[ lastActiveIndex ];
  20236. action._cacheIndex = lastActiveIndex;
  20237. actions[ lastActiveIndex ] = action;
  20238. firstInactiveAction._cacheIndex = prevIndex;
  20239. actions[ prevIndex ] = firstInactiveAction;
  20240. }
  20241. _takeBackAction( action ) {
  20242. // [ active actions | inactive actions ]
  20243. // [ active actions |< inactive actions ]
  20244. // a s
  20245. // <-swap->
  20246. // s a
  20247. const actions = this._actions,
  20248. prevIndex = action._cacheIndex,
  20249. firstInactiveIndex = -- this._nActiveActions,
  20250. lastActiveAction = actions[ firstInactiveIndex ];
  20251. action._cacheIndex = firstInactiveIndex;
  20252. actions[ firstInactiveIndex ] = action;
  20253. lastActiveAction._cacheIndex = prevIndex;
  20254. actions[ prevIndex ] = lastActiveAction;
  20255. }
  20256. // Memory management for PropertyMixer objects
  20257. _addInactiveBinding( binding, rootUuid, trackName ) {
  20258. const bindingsByRoot = this._bindingsByRootAndName,
  20259. bindings = this._bindings;
  20260. let bindingByName = bindingsByRoot[ rootUuid ];
  20261. if ( bindingByName === undefined ) {
  20262. bindingByName = {};
  20263. bindingsByRoot[ rootUuid ] = bindingByName;
  20264. }
  20265. bindingByName[ trackName ] = binding;
  20266. binding._cacheIndex = bindings.length;
  20267. bindings.push( binding );
  20268. }
  20269. _removeInactiveBinding( binding ) {
  20270. const bindings = this._bindings,
  20271. propBinding = binding.binding,
  20272. rootUuid = propBinding.rootNode.uuid,
  20273. trackName = propBinding.path,
  20274. bindingsByRoot = this._bindingsByRootAndName,
  20275. bindingByName = bindingsByRoot[ rootUuid ],
  20276. lastInactiveBinding = bindings[ bindings.length - 1 ],
  20277. cacheIndex = binding._cacheIndex;
  20278. lastInactiveBinding._cacheIndex = cacheIndex;
  20279. bindings[ cacheIndex ] = lastInactiveBinding;
  20280. bindings.pop();
  20281. delete bindingByName[ trackName ];
  20282. if ( Object.keys( bindingByName ).length === 0 ) {
  20283. delete bindingsByRoot[ rootUuid ];
  20284. }
  20285. }
  20286. _lendBinding( binding ) {
  20287. const bindings = this._bindings,
  20288. prevIndex = binding._cacheIndex,
  20289. lastActiveIndex = this._nActiveBindings ++,
  20290. firstInactiveBinding = bindings[ lastActiveIndex ];
  20291. binding._cacheIndex = lastActiveIndex;
  20292. bindings[ lastActiveIndex ] = binding;
  20293. firstInactiveBinding._cacheIndex = prevIndex;
  20294. bindings[ prevIndex ] = firstInactiveBinding;
  20295. }
  20296. _takeBackBinding( binding ) {
  20297. const bindings = this._bindings,
  20298. prevIndex = binding._cacheIndex,
  20299. firstInactiveIndex = -- this._nActiveBindings,
  20300. lastActiveBinding = bindings[ firstInactiveIndex ];
  20301. binding._cacheIndex = firstInactiveIndex;
  20302. bindings[ firstInactiveIndex ] = binding;
  20303. lastActiveBinding._cacheIndex = prevIndex;
  20304. bindings[ prevIndex ] = lastActiveBinding;
  20305. }
  20306. // Memory management of Interpolants for weight and time scale
  20307. _lendControlInterpolant() {
  20308. const interpolants = this._controlInterpolants,
  20309. lastActiveIndex = this._nActiveControlInterpolants ++;
  20310. let interpolant = interpolants[ lastActiveIndex ];
  20311. if ( interpolant === undefined ) {
  20312. interpolant = new LinearInterpolant(
  20313. new Float32Array( 2 ), new Float32Array( 2 ),
  20314. 1, _controlInterpolantsResultBuffer );
  20315. interpolant.__cacheIndex = lastActiveIndex;
  20316. interpolants[ lastActiveIndex ] = interpolant;
  20317. }
  20318. return interpolant;
  20319. }
  20320. _takeBackControlInterpolant( interpolant ) {
  20321. const interpolants = this._controlInterpolants,
  20322. prevIndex = interpolant.__cacheIndex,
  20323. firstInactiveIndex = -- this._nActiveControlInterpolants,
  20324. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  20325. interpolant.__cacheIndex = firstInactiveIndex;
  20326. interpolants[ firstInactiveIndex ] = interpolant;
  20327. lastActiveInterpolant.__cacheIndex = prevIndex;
  20328. interpolants[ prevIndex ] = lastActiveInterpolant;
  20329. }
  20330. // return an action for a clip optionally using a custom root target
  20331. // object (this method allocates a lot of dynamic memory in case a
  20332. // previously unknown clip/root combination is specified)
  20333. clipAction( clip, optionalRoot, blendMode ) {
  20334. const root = optionalRoot || this._root,
  20335. rootUuid = root.uuid;
  20336. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  20337. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  20338. const actionsForClip = this._actionsByClip[ clipUuid ];
  20339. let prototypeAction = null;
  20340. if ( blendMode === undefined ) {
  20341. if ( clipObject !== null ) {
  20342. blendMode = clipObject.blendMode;
  20343. } else {
  20344. blendMode = NormalAnimationBlendMode;
  20345. }
  20346. }
  20347. if ( actionsForClip !== undefined ) {
  20348. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  20349. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  20350. return existingAction;
  20351. }
  20352. // we know the clip, so we don't have to parse all
  20353. // the bindings again but can just copy
  20354. prototypeAction = actionsForClip.knownActions[ 0 ];
  20355. // also, take the clip from the prototype action
  20356. if ( clipObject === null )
  20357. clipObject = prototypeAction._clip;
  20358. }
  20359. // clip must be known when specified via string
  20360. if ( clipObject === null ) return null;
  20361. // allocate all resources required to run it
  20362. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  20363. this._bindAction( newAction, prototypeAction );
  20364. // and make the action known to the memory manager
  20365. this._addInactiveAction( newAction, clipUuid, rootUuid );
  20366. return newAction;
  20367. }
  20368. // get an existing action
  20369. existingAction( clip, optionalRoot ) {
  20370. const root = optionalRoot || this._root,
  20371. rootUuid = root.uuid,
  20372. clipObject = typeof clip === 'string' ?
  20373. AnimationClip.findByName( root, clip ) : clip,
  20374. clipUuid = clipObject ? clipObject.uuid : clip,
  20375. actionsForClip = this._actionsByClip[ clipUuid ];
  20376. if ( actionsForClip !== undefined ) {
  20377. return actionsForClip.actionByRoot[ rootUuid ] || null;
  20378. }
  20379. return null;
  20380. }
  20381. // deactivates all previously scheduled actions
  20382. stopAllAction() {
  20383. const actions = this._actions,
  20384. nActions = this._nActiveActions;
  20385. for ( let i = nActions - 1; i >= 0; -- i ) {
  20386. actions[ i ].stop();
  20387. }
  20388. return this;
  20389. }
  20390. // advance the time and update apply the animation
  20391. update( deltaTime ) {
  20392. deltaTime *= this.timeScale;
  20393. const actions = this._actions,
  20394. nActions = this._nActiveActions,
  20395. time = this.time += deltaTime,
  20396. timeDirection = Math.sign( deltaTime ),
  20397. accuIndex = this._accuIndex ^= 1;
  20398. // run active actions
  20399. for ( let i = 0; i !== nActions; ++ i ) {
  20400. const action = actions[ i ];
  20401. action._update( time, deltaTime, timeDirection, accuIndex );
  20402. }
  20403. // update scene graph
  20404. const bindings = this._bindings,
  20405. nBindings = this._nActiveBindings;
  20406. for ( let i = 0; i !== nBindings; ++ i ) {
  20407. bindings[ i ].apply( accuIndex );
  20408. }
  20409. return this;
  20410. }
  20411. // Allows you to seek to a specific time in an animation.
  20412. setTime( timeInSeconds ) {
  20413. this.time = 0; // Zero out time attribute for AnimationMixer object;
  20414. for ( let i = 0; i < this._actions.length; i ++ ) {
  20415. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  20416. }
  20417. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  20418. }
  20419. // return this mixer's root target object
  20420. getRoot() {
  20421. return this._root;
  20422. }
  20423. // free all resources specific to a particular clip
  20424. uncacheClip( clip ) {
  20425. const actions = this._actions,
  20426. clipUuid = clip.uuid,
  20427. actionsByClip = this._actionsByClip,
  20428. actionsForClip = actionsByClip[ clipUuid ];
  20429. if ( actionsForClip !== undefined ) {
  20430. // note: just calling _removeInactiveAction would mess up the
  20431. // iteration state and also require updating the state we can
  20432. // just throw away
  20433. const actionsToRemove = actionsForClip.knownActions;
  20434. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  20435. const action = actionsToRemove[ i ];
  20436. this._deactivateAction( action );
  20437. const cacheIndex = action._cacheIndex,
  20438. lastInactiveAction = actions[ actions.length - 1 ];
  20439. action._cacheIndex = null;
  20440. action._byClipCacheIndex = null;
  20441. lastInactiveAction._cacheIndex = cacheIndex;
  20442. actions[ cacheIndex ] = lastInactiveAction;
  20443. actions.pop();
  20444. this._removeInactiveBindingsForAction( action );
  20445. }
  20446. delete actionsByClip[ clipUuid ];
  20447. }
  20448. }
  20449. // free all resources specific to a particular root target object
  20450. uncacheRoot( root ) {
  20451. const rootUuid = root.uuid,
  20452. actionsByClip = this._actionsByClip;
  20453. for ( const clipUuid in actionsByClip ) {
  20454. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  20455. action = actionByRoot[ rootUuid ];
  20456. if ( action !== undefined ) {
  20457. this._deactivateAction( action );
  20458. this._removeInactiveAction( action );
  20459. }
  20460. }
  20461. const bindingsByRoot = this._bindingsByRootAndName,
  20462. bindingByName = bindingsByRoot[ rootUuid ];
  20463. if ( bindingByName !== undefined ) {
  20464. for ( const trackName in bindingByName ) {
  20465. const binding = bindingByName[ trackName ];
  20466. binding.restoreOriginalState();
  20467. this._removeInactiveBinding( binding );
  20468. }
  20469. }
  20470. }
  20471. // remove a targeted clip from the cache
  20472. uncacheAction( clip, optionalRoot ) {
  20473. const action = this.existingAction( clip, optionalRoot );
  20474. if ( action !== null ) {
  20475. this._deactivateAction( action );
  20476. this._removeInactiveAction( action );
  20477. }
  20478. }
  20479. }
  20480. class RenderTarget3D extends RenderTarget {
  20481. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  20482. super( width, height, options );
  20483. this.isRenderTarget3D = true;
  20484. this.depth = depth;
  20485. this.texture = new Data3DTexture( null, width, height, depth );
  20486. this.texture.isRenderTargetTexture = true;
  20487. }
  20488. }
  20489. class RenderTargetArray extends RenderTarget {
  20490. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  20491. super( width, height, options );
  20492. this.isRenderTargetArray = true;
  20493. this.depth = depth;
  20494. this.texture = new DataArrayTexture( null, width, height, depth );
  20495. this.texture.isRenderTargetTexture = true;
  20496. }
  20497. }
  20498. class Uniform {
  20499. constructor( value ) {
  20500. this.value = value;
  20501. }
  20502. clone() {
  20503. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  20504. }
  20505. }
  20506. let _id = 0;
  20507. class UniformsGroup extends EventDispatcher {
  20508. constructor() {
  20509. super();
  20510. this.isUniformsGroup = true;
  20511. Object.defineProperty( this, 'id', { value: _id ++ } );
  20512. this.name = '';
  20513. this.usage = StaticDrawUsage;
  20514. this.uniforms = [];
  20515. }
  20516. add( uniform ) {
  20517. this.uniforms.push( uniform );
  20518. return this;
  20519. }
  20520. remove( uniform ) {
  20521. const index = this.uniforms.indexOf( uniform );
  20522. if ( index !== -1 ) this.uniforms.splice( index, 1 );
  20523. return this;
  20524. }
  20525. setName( name ) {
  20526. this.name = name;
  20527. return this;
  20528. }
  20529. setUsage( value ) {
  20530. this.usage = value;
  20531. return this;
  20532. }
  20533. dispose() {
  20534. this.dispatchEvent( { type: 'dispose' } );
  20535. return this;
  20536. }
  20537. copy( source ) {
  20538. this.name = source.name;
  20539. this.usage = source.usage;
  20540. const uniformsSource = source.uniforms;
  20541. this.uniforms.length = 0;
  20542. for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
  20543. const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
  20544. for ( let j = 0; j < uniforms.length; j ++ ) {
  20545. this.uniforms.push( uniforms[ j ].clone() );
  20546. }
  20547. }
  20548. return this;
  20549. }
  20550. clone() {
  20551. return new this.constructor().copy( this );
  20552. }
  20553. }
  20554. class InstancedInterleavedBuffer extends InterleavedBuffer {
  20555. constructor( array, stride, meshPerAttribute = 1 ) {
  20556. super( array, stride );
  20557. this.isInstancedInterleavedBuffer = true;
  20558. this.meshPerAttribute = meshPerAttribute;
  20559. }
  20560. copy( source ) {
  20561. super.copy( source );
  20562. this.meshPerAttribute = source.meshPerAttribute;
  20563. return this;
  20564. }
  20565. clone( data ) {
  20566. const ib = super.clone( data );
  20567. ib.meshPerAttribute = this.meshPerAttribute;
  20568. return ib;
  20569. }
  20570. toJSON( data ) {
  20571. const json = super.toJSON( data );
  20572. json.isInstancedInterleavedBuffer = true;
  20573. json.meshPerAttribute = this.meshPerAttribute;
  20574. return json;
  20575. }
  20576. }
  20577. class GLBufferAttribute {
  20578. constructor( buffer, type, itemSize, elementSize, count ) {
  20579. this.isGLBufferAttribute = true;
  20580. this.name = '';
  20581. this.buffer = buffer;
  20582. this.type = type;
  20583. this.itemSize = itemSize;
  20584. this.elementSize = elementSize;
  20585. this.count = count;
  20586. this.version = 0;
  20587. }
  20588. set needsUpdate( value ) {
  20589. if ( value === true ) this.version ++;
  20590. }
  20591. setBuffer( buffer ) {
  20592. this.buffer = buffer;
  20593. return this;
  20594. }
  20595. setType( type, elementSize ) {
  20596. this.type = type;
  20597. this.elementSize = elementSize;
  20598. return this;
  20599. }
  20600. setItemSize( itemSize ) {
  20601. this.itemSize = itemSize;
  20602. return this;
  20603. }
  20604. setCount( count ) {
  20605. this.count = count;
  20606. return this;
  20607. }
  20608. }
  20609. const _matrix = /*@__PURE__*/ new Matrix4();
  20610. class Raycaster {
  20611. constructor( origin, direction, near = 0, far = Infinity ) {
  20612. this.ray = new Ray( origin, direction );
  20613. // direction is assumed to be normalized (for accurate distance calculations)
  20614. this.near = near;
  20615. this.far = far;
  20616. this.camera = null;
  20617. this.layers = new Layers();
  20618. this.params = {
  20619. Mesh: {},
  20620. Line: { threshold: 1 },
  20621. LOD: {},
  20622. Points: { threshold: 1 },
  20623. Sprite: {}
  20624. };
  20625. }
  20626. set( origin, direction ) {
  20627. // direction is assumed to be normalized (for accurate distance calculations)
  20628. this.ray.set( origin, direction );
  20629. }
  20630. setFromCamera( coords, camera ) {
  20631. if ( camera.isPerspectiveCamera ) {
  20632. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  20633. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  20634. this.camera = camera;
  20635. } else if ( camera.isOrthographicCamera ) {
  20636. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  20637. this.ray.direction.set( 0, 0, -1 ).transformDirection( camera.matrixWorld );
  20638. this.camera = camera;
  20639. } else {
  20640. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  20641. }
  20642. }
  20643. setFromXRController( controller ) {
  20644. _matrix.identity().extractRotation( controller.matrixWorld );
  20645. this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
  20646. this.ray.direction.set( 0, 0, -1 ).applyMatrix4( _matrix );
  20647. return this;
  20648. }
  20649. intersectObject( object, recursive = true, intersects = [] ) {
  20650. intersect( object, this, intersects, recursive );
  20651. intersects.sort( ascSort );
  20652. return intersects;
  20653. }
  20654. intersectObjects( objects, recursive = true, intersects = [] ) {
  20655. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  20656. intersect( objects[ i ], this, intersects, recursive );
  20657. }
  20658. intersects.sort( ascSort );
  20659. return intersects;
  20660. }
  20661. }
  20662. function ascSort( a, b ) {
  20663. return a.distance - b.distance;
  20664. }
  20665. function intersect( object, raycaster, intersects, recursive ) {
  20666. let propagate = true;
  20667. if ( object.layers.test( raycaster.layers ) ) {
  20668. const result = object.raycast( raycaster, intersects );
  20669. if ( result === false ) propagate = false;
  20670. }
  20671. if ( propagate === true && recursive === true ) {
  20672. const children = object.children;
  20673. for ( let i = 0, l = children.length; i < l; i ++ ) {
  20674. intersect( children[ i ], raycaster, intersects, true );
  20675. }
  20676. }
  20677. }
  20678. /**
  20679. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  20680. *
  20681. * phi (the polar angle) is measured from the positive y-axis. The positive y-axis is up.
  20682. * theta (the azimuthal angle) is measured from the positive z-axis.
  20683. */
  20684. class Spherical {
  20685. constructor( radius = 1, phi = 0, theta = 0 ) {
  20686. this.radius = radius;
  20687. this.phi = phi; // polar angle
  20688. this.theta = theta; // azimuthal angle
  20689. return this;
  20690. }
  20691. set( radius, phi, theta ) {
  20692. this.radius = radius;
  20693. this.phi = phi;
  20694. this.theta = theta;
  20695. return this;
  20696. }
  20697. copy( other ) {
  20698. this.radius = other.radius;
  20699. this.phi = other.phi;
  20700. this.theta = other.theta;
  20701. return this;
  20702. }
  20703. // restrict phi to be between EPS and PI-EPS
  20704. makeSafe() {
  20705. const EPS = 0.000001;
  20706. this.phi = clamp( this.phi, EPS, Math.PI - EPS );
  20707. return this;
  20708. }
  20709. setFromVector3( v ) {
  20710. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20711. }
  20712. setFromCartesianCoords( x, y, z ) {
  20713. this.radius = Math.sqrt( x * x + y * y + z * z );
  20714. if ( this.radius === 0 ) {
  20715. this.theta = 0;
  20716. this.phi = 0;
  20717. } else {
  20718. this.theta = Math.atan2( x, z );
  20719. this.phi = Math.acos( clamp( y / this.radius, -1, 1 ) );
  20720. }
  20721. return this;
  20722. }
  20723. clone() {
  20724. return new this.constructor().copy( this );
  20725. }
  20726. }
  20727. /**
  20728. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  20729. */
  20730. class Cylindrical {
  20731. constructor( radius = 1, theta = 0, y = 0 ) {
  20732. this.radius = radius; // distance from the origin to a point in the x-z plane
  20733. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  20734. this.y = y; // height above the x-z plane
  20735. return this;
  20736. }
  20737. set( radius, theta, y ) {
  20738. this.radius = radius;
  20739. this.theta = theta;
  20740. this.y = y;
  20741. return this;
  20742. }
  20743. copy( other ) {
  20744. this.radius = other.radius;
  20745. this.theta = other.theta;
  20746. this.y = other.y;
  20747. return this;
  20748. }
  20749. setFromVector3( v ) {
  20750. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20751. }
  20752. setFromCartesianCoords( x, y, z ) {
  20753. this.radius = Math.sqrt( x * x + z * z );
  20754. this.theta = Math.atan2( x, z );
  20755. this.y = y;
  20756. return this;
  20757. }
  20758. clone() {
  20759. return new this.constructor().copy( this );
  20760. }
  20761. }
  20762. class Matrix2 {
  20763. constructor( n11, n12, n21, n22 ) {
  20764. Matrix2.prototype.isMatrix2 = true;
  20765. this.elements = [
  20766. 1, 0,
  20767. 0, 1,
  20768. ];
  20769. if ( n11 !== undefined ) {
  20770. this.set( n11, n12, n21, n22 );
  20771. }
  20772. }
  20773. identity() {
  20774. this.set(
  20775. 1, 0,
  20776. 0, 1,
  20777. );
  20778. return this;
  20779. }
  20780. fromArray( array, offset = 0 ) {
  20781. for ( let i = 0; i < 4; i ++ ) {
  20782. this.elements[ i ] = array[ i + offset ];
  20783. }
  20784. return this;
  20785. }
  20786. set( n11, n12, n21, n22 ) {
  20787. const te = this.elements;
  20788. te[ 0 ] = n11; te[ 2 ] = n12;
  20789. te[ 1 ] = n21; te[ 3 ] = n22;
  20790. return this;
  20791. }
  20792. }
  20793. const _vector$4 = /*@__PURE__*/ new Vector2();
  20794. class Box2 {
  20795. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  20796. this.isBox2 = true;
  20797. this.min = min;
  20798. this.max = max;
  20799. }
  20800. set( min, max ) {
  20801. this.min.copy( min );
  20802. this.max.copy( max );
  20803. return this;
  20804. }
  20805. setFromPoints( points ) {
  20806. this.makeEmpty();
  20807. for ( let i = 0, il = points.length; i < il; i ++ ) {
  20808. this.expandByPoint( points[ i ] );
  20809. }
  20810. return this;
  20811. }
  20812. setFromCenterAndSize( center, size ) {
  20813. const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 );
  20814. this.min.copy( center ).sub( halfSize );
  20815. this.max.copy( center ).add( halfSize );
  20816. return this;
  20817. }
  20818. clone() {
  20819. return new this.constructor().copy( this );
  20820. }
  20821. copy( box ) {
  20822. this.min.copy( box.min );
  20823. this.max.copy( box.max );
  20824. return this;
  20825. }
  20826. makeEmpty() {
  20827. this.min.x = this.min.y = + Infinity;
  20828. this.max.x = this.max.y = - Infinity;
  20829. return this;
  20830. }
  20831. isEmpty() {
  20832. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  20833. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  20834. }
  20835. getCenter( target ) {
  20836. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  20837. }
  20838. getSize( target ) {
  20839. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  20840. }
  20841. expandByPoint( point ) {
  20842. this.min.min( point );
  20843. this.max.max( point );
  20844. return this;
  20845. }
  20846. expandByVector( vector ) {
  20847. this.min.sub( vector );
  20848. this.max.add( vector );
  20849. return this;
  20850. }
  20851. expandByScalar( scalar ) {
  20852. this.min.addScalar( - scalar );
  20853. this.max.addScalar( scalar );
  20854. return this;
  20855. }
  20856. containsPoint( point ) {
  20857. return point.x >= this.min.x && point.x <= this.max.x &&
  20858. point.y >= this.min.y && point.y <= this.max.y;
  20859. }
  20860. containsBox( box ) {
  20861. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  20862. this.min.y <= box.min.y && box.max.y <= this.max.y;
  20863. }
  20864. getParameter( point, target ) {
  20865. // This can potentially have a divide by zero if the box
  20866. // has a size dimension of 0.
  20867. return target.set(
  20868. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  20869. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  20870. );
  20871. }
  20872. intersectsBox( box ) {
  20873. // using 4 splitting planes to rule out intersections
  20874. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  20875. box.max.y >= this.min.y && box.min.y <= this.max.y;
  20876. }
  20877. clampPoint( point, target ) {
  20878. return target.copy( point ).clamp( this.min, this.max );
  20879. }
  20880. distanceToPoint( point ) {
  20881. return this.clampPoint( point, _vector$4 ).distanceTo( point );
  20882. }
  20883. intersect( box ) {
  20884. this.min.max( box.min );
  20885. this.max.min( box.max );
  20886. if ( this.isEmpty() ) this.makeEmpty();
  20887. return this;
  20888. }
  20889. union( box ) {
  20890. this.min.min( box.min );
  20891. this.max.max( box.max );
  20892. return this;
  20893. }
  20894. translate( offset ) {
  20895. this.min.add( offset );
  20896. this.max.add( offset );
  20897. return this;
  20898. }
  20899. equals( box ) {
  20900. return box.min.equals( this.min ) && box.max.equals( this.max );
  20901. }
  20902. }
  20903. const _startP = /*@__PURE__*/ new Vector3();
  20904. const _startEnd = /*@__PURE__*/ new Vector3();
  20905. class Line3 {
  20906. constructor( start = new Vector3(), end = new Vector3() ) {
  20907. this.start = start;
  20908. this.end = end;
  20909. }
  20910. set( start, end ) {
  20911. this.start.copy( start );
  20912. this.end.copy( end );
  20913. return this;
  20914. }
  20915. copy( line ) {
  20916. this.start.copy( line.start );
  20917. this.end.copy( line.end );
  20918. return this;
  20919. }
  20920. getCenter( target ) {
  20921. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  20922. }
  20923. delta( target ) {
  20924. return target.subVectors( this.end, this.start );
  20925. }
  20926. distanceSq() {
  20927. return this.start.distanceToSquared( this.end );
  20928. }
  20929. distance() {
  20930. return this.start.distanceTo( this.end );
  20931. }
  20932. at( t, target ) {
  20933. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20934. }
  20935. closestPointToPointParameter( point, clampToLine ) {
  20936. _startP.subVectors( point, this.start );
  20937. _startEnd.subVectors( this.end, this.start );
  20938. const startEnd2 = _startEnd.dot( _startEnd );
  20939. const startEnd_startP = _startEnd.dot( _startP );
  20940. let t = startEnd_startP / startEnd2;
  20941. if ( clampToLine ) {
  20942. t = clamp( t, 0, 1 );
  20943. }
  20944. return t;
  20945. }
  20946. closestPointToPoint( point, clampToLine, target ) {
  20947. const t = this.closestPointToPointParameter( point, clampToLine );
  20948. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20949. }
  20950. applyMatrix4( matrix ) {
  20951. this.start.applyMatrix4( matrix );
  20952. this.end.applyMatrix4( matrix );
  20953. return this;
  20954. }
  20955. equals( line ) {
  20956. return line.start.equals( this.start ) && line.end.equals( this.end );
  20957. }
  20958. clone() {
  20959. return new this.constructor().copy( this );
  20960. }
  20961. }
  20962. const _vector$3 = /*@__PURE__*/ new Vector3();
  20963. class SpotLightHelper extends Object3D {
  20964. constructor( light, color ) {
  20965. super();
  20966. this.light = light;
  20967. this.matrixAutoUpdate = false;
  20968. this.color = color;
  20969. this.type = 'SpotLightHelper';
  20970. const geometry = new BufferGeometry();
  20971. const positions = [
  20972. 0, 0, 0, 0, 0, 1,
  20973. 0, 0, 0, 1, 0, 1,
  20974. 0, 0, 0, -1, 0, 1,
  20975. 0, 0, 0, 0, 1, 1,
  20976. 0, 0, 0, 0, -1, 1
  20977. ];
  20978. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  20979. const p1 = ( i / l ) * Math.PI * 2;
  20980. const p2 = ( j / l ) * Math.PI * 2;
  20981. positions.push(
  20982. Math.cos( p1 ), Math.sin( p1 ), 1,
  20983. Math.cos( p2 ), Math.sin( p2 ), 1
  20984. );
  20985. }
  20986. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  20987. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  20988. this.cone = new LineSegments( geometry, material );
  20989. this.add( this.cone );
  20990. this.update();
  20991. }
  20992. dispose() {
  20993. this.cone.geometry.dispose();
  20994. this.cone.material.dispose();
  20995. }
  20996. update() {
  20997. this.light.updateWorldMatrix( true, false );
  20998. this.light.target.updateWorldMatrix( true, false );
  20999. // update the local matrix based on the parent and light target transforms
  21000. if ( this.parent ) {
  21001. this.parent.updateWorldMatrix( true );
  21002. this.matrix
  21003. .copy( this.parent.matrixWorld )
  21004. .invert()
  21005. .multiply( this.light.matrixWorld );
  21006. } else {
  21007. this.matrix.copy( this.light.matrixWorld );
  21008. }
  21009. this.matrixWorld.copy( this.light.matrixWorld );
  21010. const coneLength = this.light.distance ? this.light.distance : 1000;
  21011. const coneWidth = coneLength * Math.tan( this.light.angle );
  21012. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21013. _vector$3.setFromMatrixPosition( this.light.target.matrixWorld );
  21014. this.cone.lookAt( _vector$3 );
  21015. if ( this.color !== undefined ) {
  21016. this.cone.material.color.set( this.color );
  21017. } else {
  21018. this.cone.material.color.copy( this.light.color );
  21019. }
  21020. }
  21021. }
  21022. const _vector$2 = /*@__PURE__*/ new Vector3();
  21023. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  21024. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  21025. class SkeletonHelper extends LineSegments {
  21026. constructor( object ) {
  21027. const bones = getBoneList( object );
  21028. const geometry = new BufferGeometry();
  21029. const vertices = [];
  21030. const colors = [];
  21031. const color1 = new Color( 0, 0, 1 );
  21032. const color2 = new Color( 0, 1, 0 );
  21033. for ( let i = 0; i < bones.length; i ++ ) {
  21034. const bone = bones[ i ];
  21035. if ( bone.parent && bone.parent.isBone ) {
  21036. vertices.push( 0, 0, 0 );
  21037. vertices.push( 0, 0, 0 );
  21038. colors.push( color1.r, color1.g, color1.b );
  21039. colors.push( color2.r, color2.g, color2.b );
  21040. }
  21041. }
  21042. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21043. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21044. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  21045. super( geometry, material );
  21046. this.isSkeletonHelper = true;
  21047. this.type = 'SkeletonHelper';
  21048. this.root = object;
  21049. this.bones = bones;
  21050. this.matrix = object.matrixWorld;
  21051. this.matrixAutoUpdate = false;
  21052. }
  21053. updateMatrixWorld( force ) {
  21054. const bones = this.bones;
  21055. const geometry = this.geometry;
  21056. const position = geometry.getAttribute( 'position' );
  21057. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  21058. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  21059. const bone = bones[ i ];
  21060. if ( bone.parent && bone.parent.isBone ) {
  21061. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  21062. _vector$2.setFromMatrixPosition( _boneMatrix );
  21063. position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z );
  21064. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  21065. _vector$2.setFromMatrixPosition( _boneMatrix );
  21066. position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z );
  21067. j += 2;
  21068. }
  21069. }
  21070. geometry.getAttribute( 'position' ).needsUpdate = true;
  21071. super.updateMatrixWorld( force );
  21072. }
  21073. dispose() {
  21074. this.geometry.dispose();
  21075. this.material.dispose();
  21076. }
  21077. }
  21078. function getBoneList( object ) {
  21079. const boneList = [];
  21080. if ( object.isBone === true ) {
  21081. boneList.push( object );
  21082. }
  21083. for ( let i = 0; i < object.children.length; i ++ ) {
  21084. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  21085. }
  21086. return boneList;
  21087. }
  21088. class PointLightHelper extends Mesh {
  21089. constructor( light, sphereSize, color ) {
  21090. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  21091. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  21092. super( geometry, material );
  21093. this.light = light;
  21094. this.color = color;
  21095. this.type = 'PointLightHelper';
  21096. this.matrix = this.light.matrixWorld;
  21097. this.matrixAutoUpdate = false;
  21098. this.update();
  21099. /*
  21100. // TODO: delete this comment?
  21101. const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21102. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21103. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21104. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21105. const d = light.distance;
  21106. if ( d === 0.0 ) {
  21107. this.lightDistance.visible = false;
  21108. } else {
  21109. this.lightDistance.scale.set( d, d, d );
  21110. }
  21111. this.add( this.lightDistance );
  21112. */
  21113. }
  21114. dispose() {
  21115. this.geometry.dispose();
  21116. this.material.dispose();
  21117. }
  21118. update() {
  21119. this.light.updateWorldMatrix( true, false );
  21120. if ( this.color !== undefined ) {
  21121. this.material.color.set( this.color );
  21122. } else {
  21123. this.material.color.copy( this.light.color );
  21124. }
  21125. /*
  21126. const d = this.light.distance;
  21127. if ( d === 0.0 ) {
  21128. this.lightDistance.visible = false;
  21129. } else {
  21130. this.lightDistance.visible = true;
  21131. this.lightDistance.scale.set( d, d, d );
  21132. }
  21133. */
  21134. }
  21135. }
  21136. const _vector$1 = /*@__PURE__*/ new Vector3();
  21137. const _color1 = /*@__PURE__*/ new Color();
  21138. const _color2 = /*@__PURE__*/ new Color();
  21139. class HemisphereLightHelper extends Object3D {
  21140. constructor( light, size, color ) {
  21141. super();
  21142. this.light = light;
  21143. this.matrix = light.matrixWorld;
  21144. this.matrixAutoUpdate = false;
  21145. this.color = color;
  21146. this.type = 'HemisphereLightHelper';
  21147. const geometry = new OctahedronGeometry( size );
  21148. geometry.rotateY( Math.PI * 0.5 );
  21149. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  21150. if ( this.color === undefined ) this.material.vertexColors = true;
  21151. const position = geometry.getAttribute( 'position' );
  21152. const colors = new Float32Array( position.count * 3 );
  21153. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  21154. this.add( new Mesh( geometry, this.material ) );
  21155. this.update();
  21156. }
  21157. dispose() {
  21158. this.children[ 0 ].geometry.dispose();
  21159. this.children[ 0 ].material.dispose();
  21160. }
  21161. update() {
  21162. const mesh = this.children[ 0 ];
  21163. if ( this.color !== undefined ) {
  21164. this.material.color.set( this.color );
  21165. } else {
  21166. const colors = mesh.geometry.getAttribute( 'color' );
  21167. _color1.copy( this.light.color );
  21168. _color2.copy( this.light.groundColor );
  21169. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  21170. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  21171. colors.setXYZ( i, color.r, color.g, color.b );
  21172. }
  21173. colors.needsUpdate = true;
  21174. }
  21175. this.light.updateWorldMatrix( true, false );
  21176. mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21177. }
  21178. }
  21179. class GridHelper extends LineSegments {
  21180. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  21181. color1 = new Color( color1 );
  21182. color2 = new Color( color2 );
  21183. const center = divisions / 2;
  21184. const step = size / divisions;
  21185. const halfSize = size / 2;
  21186. const vertices = [], colors = [];
  21187. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  21188. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  21189. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  21190. const color = i === center ? color1 : color2;
  21191. color.toArray( colors, j ); j += 3;
  21192. color.toArray( colors, j ); j += 3;
  21193. color.toArray( colors, j ); j += 3;
  21194. color.toArray( colors, j ); j += 3;
  21195. }
  21196. const geometry = new BufferGeometry();
  21197. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21198. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21199. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21200. super( geometry, material );
  21201. this.type = 'GridHelper';
  21202. }
  21203. dispose() {
  21204. this.geometry.dispose();
  21205. this.material.dispose();
  21206. }
  21207. }
  21208. class PolarGridHelper extends LineSegments {
  21209. constructor( radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  21210. color1 = new Color( color1 );
  21211. color2 = new Color( color2 );
  21212. const vertices = [];
  21213. const colors = [];
  21214. // create the sectors
  21215. if ( sectors > 1 ) {
  21216. for ( let i = 0; i < sectors; i ++ ) {
  21217. const v = ( i / sectors ) * ( Math.PI * 2 );
  21218. const x = Math.sin( v ) * radius;
  21219. const z = Math.cos( v ) * radius;
  21220. vertices.push( 0, 0, 0 );
  21221. vertices.push( x, 0, z );
  21222. const color = ( i & 1 ) ? color1 : color2;
  21223. colors.push( color.r, color.g, color.b );
  21224. colors.push( color.r, color.g, color.b );
  21225. }
  21226. }
  21227. // create the rings
  21228. for ( let i = 0; i < rings; i ++ ) {
  21229. const color = ( i & 1 ) ? color1 : color2;
  21230. const r = radius - ( radius / rings * i );
  21231. for ( let j = 0; j < divisions; j ++ ) {
  21232. // first vertex
  21233. let v = ( j / divisions ) * ( Math.PI * 2 );
  21234. let x = Math.sin( v ) * r;
  21235. let z = Math.cos( v ) * r;
  21236. vertices.push( x, 0, z );
  21237. colors.push( color.r, color.g, color.b );
  21238. // second vertex
  21239. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  21240. x = Math.sin( v ) * r;
  21241. z = Math.cos( v ) * r;
  21242. vertices.push( x, 0, z );
  21243. colors.push( color.r, color.g, color.b );
  21244. }
  21245. }
  21246. const geometry = new BufferGeometry();
  21247. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21248. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21249. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21250. super( geometry, material );
  21251. this.type = 'PolarGridHelper';
  21252. }
  21253. dispose() {
  21254. this.geometry.dispose();
  21255. this.material.dispose();
  21256. }
  21257. }
  21258. const _v1 = /*@__PURE__*/ new Vector3();
  21259. const _v2 = /*@__PURE__*/ new Vector3();
  21260. const _v3 = /*@__PURE__*/ new Vector3();
  21261. class DirectionalLightHelper extends Object3D {
  21262. constructor( light, size, color ) {
  21263. super();
  21264. this.light = light;
  21265. this.matrix = light.matrixWorld;
  21266. this.matrixAutoUpdate = false;
  21267. this.color = color;
  21268. this.type = 'DirectionalLightHelper';
  21269. if ( size === undefined ) size = 1;
  21270. let geometry = new BufferGeometry();
  21271. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  21272. - size, size, 0,
  21273. size, size, 0,
  21274. size, - size, 0,
  21275. - size, - size, 0,
  21276. - size, size, 0
  21277. ], 3 ) );
  21278. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  21279. this.lightPlane = new Line( geometry, material );
  21280. this.add( this.lightPlane );
  21281. geometry = new BufferGeometry();
  21282. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  21283. this.targetLine = new Line( geometry, material );
  21284. this.add( this.targetLine );
  21285. this.update();
  21286. }
  21287. dispose() {
  21288. this.lightPlane.geometry.dispose();
  21289. this.lightPlane.material.dispose();
  21290. this.targetLine.geometry.dispose();
  21291. this.targetLine.material.dispose();
  21292. }
  21293. update() {
  21294. this.light.updateWorldMatrix( true, false );
  21295. this.light.target.updateWorldMatrix( true, false );
  21296. _v1.setFromMatrixPosition( this.light.matrixWorld );
  21297. _v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21298. _v3.subVectors( _v2, _v1 );
  21299. this.lightPlane.lookAt( _v2 );
  21300. if ( this.color !== undefined ) {
  21301. this.lightPlane.material.color.set( this.color );
  21302. this.targetLine.material.color.set( this.color );
  21303. } else {
  21304. this.lightPlane.material.color.copy( this.light.color );
  21305. this.targetLine.material.color.copy( this.light.color );
  21306. }
  21307. this.targetLine.lookAt( _v2 );
  21308. this.targetLine.scale.z = _v3.length();
  21309. }
  21310. }
  21311. const _vector = /*@__PURE__*/ new Vector3();
  21312. const _camera = /*@__PURE__*/ new Camera();
  21313. /**
  21314. * - shows frustum, line of sight and up of the camera
  21315. * - suitable for fast updates
  21316. * - based on frustum visualization in lightgl.js shadowmap example
  21317. * https://github.com/evanw/lightgl.js/blob/master/tests/shadowmap.html
  21318. */
  21319. class CameraHelper extends LineSegments {
  21320. constructor( camera ) {
  21321. const geometry = new BufferGeometry();
  21322. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  21323. const vertices = [];
  21324. const colors = [];
  21325. const pointMap = {};
  21326. // near
  21327. addLine( 'n1', 'n2' );
  21328. addLine( 'n2', 'n4' );
  21329. addLine( 'n4', 'n3' );
  21330. addLine( 'n3', 'n1' );
  21331. // far
  21332. addLine( 'f1', 'f2' );
  21333. addLine( 'f2', 'f4' );
  21334. addLine( 'f4', 'f3' );
  21335. addLine( 'f3', 'f1' );
  21336. // sides
  21337. addLine( 'n1', 'f1' );
  21338. addLine( 'n2', 'f2' );
  21339. addLine( 'n3', 'f3' );
  21340. addLine( 'n4', 'f4' );
  21341. // cone
  21342. addLine( 'p', 'n1' );
  21343. addLine( 'p', 'n2' );
  21344. addLine( 'p', 'n3' );
  21345. addLine( 'p', 'n4' );
  21346. // up
  21347. addLine( 'u1', 'u2' );
  21348. addLine( 'u2', 'u3' );
  21349. addLine( 'u3', 'u1' );
  21350. // target
  21351. addLine( 'c', 't' );
  21352. addLine( 'p', 'c' );
  21353. // cross
  21354. addLine( 'cn1', 'cn2' );
  21355. addLine( 'cn3', 'cn4' );
  21356. addLine( 'cf1', 'cf2' );
  21357. addLine( 'cf3', 'cf4' );
  21358. function addLine( a, b ) {
  21359. addPoint( a );
  21360. addPoint( b );
  21361. }
  21362. function addPoint( id ) {
  21363. vertices.push( 0, 0, 0 );
  21364. colors.push( 0, 0, 0 );
  21365. if ( pointMap[ id ] === undefined ) {
  21366. pointMap[ id ] = [];
  21367. }
  21368. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  21369. }
  21370. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21371. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21372. super( geometry, material );
  21373. this.type = 'CameraHelper';
  21374. this.camera = camera;
  21375. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  21376. this.matrix = camera.matrixWorld;
  21377. this.matrixAutoUpdate = false;
  21378. this.pointMap = pointMap;
  21379. this.update();
  21380. // colors
  21381. const colorFrustum = new Color( 0xffaa00 );
  21382. const colorCone = new Color( 0xff0000 );
  21383. const colorUp = new Color( 0x00aaff );
  21384. const colorTarget = new Color( 0xffffff );
  21385. const colorCross = new Color( 0x333333 );
  21386. this.setColors( colorFrustum, colorCone, colorUp, colorTarget, colorCross );
  21387. }
  21388. setColors( frustum, cone, up, target, cross ) {
  21389. const geometry = this.geometry;
  21390. const colorAttribute = geometry.getAttribute( 'color' );
  21391. // near
  21392. colorAttribute.setXYZ( 0, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 1, frustum.r, frustum.g, frustum.b ); // n1, n2
  21393. colorAttribute.setXYZ( 2, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 3, frustum.r, frustum.g, frustum.b ); // n2, n4
  21394. colorAttribute.setXYZ( 4, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 5, frustum.r, frustum.g, frustum.b ); // n4, n3
  21395. colorAttribute.setXYZ( 6, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 7, frustum.r, frustum.g, frustum.b ); // n3, n1
  21396. // far
  21397. colorAttribute.setXYZ( 8, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 9, frustum.r, frustum.g, frustum.b ); // f1, f2
  21398. colorAttribute.setXYZ( 10, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 11, frustum.r, frustum.g, frustum.b ); // f2, f4
  21399. colorAttribute.setXYZ( 12, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 13, frustum.r, frustum.g, frustum.b ); // f4, f3
  21400. colorAttribute.setXYZ( 14, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 15, frustum.r, frustum.g, frustum.b ); // f3, f1
  21401. // sides
  21402. colorAttribute.setXYZ( 16, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 17, frustum.r, frustum.g, frustum.b ); // n1, f1
  21403. colorAttribute.setXYZ( 18, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 19, frustum.r, frustum.g, frustum.b ); // n2, f2
  21404. colorAttribute.setXYZ( 20, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 21, frustum.r, frustum.g, frustum.b ); // n3, f3
  21405. colorAttribute.setXYZ( 22, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 23, frustum.r, frustum.g, frustum.b ); // n4, f4
  21406. // cone
  21407. colorAttribute.setXYZ( 24, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 25, cone.r, cone.g, cone.b ); // p, n1
  21408. colorAttribute.setXYZ( 26, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 27, cone.r, cone.g, cone.b ); // p, n2
  21409. colorAttribute.setXYZ( 28, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 29, cone.r, cone.g, cone.b ); // p, n3
  21410. colorAttribute.setXYZ( 30, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 31, cone.r, cone.g, cone.b ); // p, n4
  21411. // up
  21412. colorAttribute.setXYZ( 32, up.r, up.g, up.b ); colorAttribute.setXYZ( 33, up.r, up.g, up.b ); // u1, u2
  21413. colorAttribute.setXYZ( 34, up.r, up.g, up.b ); colorAttribute.setXYZ( 35, up.r, up.g, up.b ); // u2, u3
  21414. colorAttribute.setXYZ( 36, up.r, up.g, up.b ); colorAttribute.setXYZ( 37, up.r, up.g, up.b ); // u3, u1
  21415. // target
  21416. colorAttribute.setXYZ( 38, target.r, target.g, target.b ); colorAttribute.setXYZ( 39, target.r, target.g, target.b ); // c, t
  21417. colorAttribute.setXYZ( 40, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 41, cross.r, cross.g, cross.b ); // p, c
  21418. // cross
  21419. colorAttribute.setXYZ( 42, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 43, cross.r, cross.g, cross.b ); // cn1, cn2
  21420. colorAttribute.setXYZ( 44, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 45, cross.r, cross.g, cross.b ); // cn3, cn4
  21421. colorAttribute.setXYZ( 46, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 47, cross.r, cross.g, cross.b ); // cf1, cf2
  21422. colorAttribute.setXYZ( 48, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 49, cross.r, cross.g, cross.b ); // cf3, cf4
  21423. colorAttribute.needsUpdate = true;
  21424. }
  21425. update() {
  21426. const geometry = this.geometry;
  21427. const pointMap = this.pointMap;
  21428. const w = 1, h = 1;
  21429. // we need just camera projection matrix inverse
  21430. // world matrix must be identity
  21431. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  21432. // Adjust z values based on coordinate system
  21433. const nearZ = this.camera.coordinateSystem === WebGLCoordinateSystem ? -1 : 0;
  21434. // center / target
  21435. setPoint( 'c', pointMap, geometry, _camera, 0, 0, nearZ );
  21436. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  21437. // near
  21438. setPoint( 'n1', pointMap, geometry, _camera, -1, -1, nearZ );
  21439. setPoint( 'n2', pointMap, geometry, _camera, w, -1, nearZ );
  21440. setPoint( 'n3', pointMap, geometry, _camera, -1, h, nearZ );
  21441. setPoint( 'n4', pointMap, geometry, _camera, w, h, nearZ );
  21442. // far
  21443. setPoint( 'f1', pointMap, geometry, _camera, -1, -1, 1 );
  21444. setPoint( 'f2', pointMap, geometry, _camera, w, -1, 1 );
  21445. setPoint( 'f3', pointMap, geometry, _camera, -1, h, 1 );
  21446. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  21447. // up
  21448. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, nearZ );
  21449. setPoint( 'u2', pointMap, geometry, _camera, -1 * 0.7, h * 1.1, nearZ );
  21450. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, nearZ );
  21451. // cross
  21452. setPoint( 'cf1', pointMap, geometry, _camera, -1, 0, 1 );
  21453. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  21454. setPoint( 'cf3', pointMap, geometry, _camera, 0, -1, 1 );
  21455. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  21456. setPoint( 'cn1', pointMap, geometry, _camera, -1, 0, nearZ );
  21457. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, nearZ );
  21458. setPoint( 'cn3', pointMap, geometry, _camera, 0, -1, nearZ );
  21459. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, nearZ );
  21460. geometry.getAttribute( 'position' ).needsUpdate = true;
  21461. }
  21462. dispose() {
  21463. this.geometry.dispose();
  21464. this.material.dispose();
  21465. }
  21466. }
  21467. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  21468. _vector.set( x, y, z ).unproject( camera );
  21469. const points = pointMap[ point ];
  21470. if ( points !== undefined ) {
  21471. const position = geometry.getAttribute( 'position' );
  21472. for ( let i = 0, l = points.length; i < l; i ++ ) {
  21473. position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
  21474. }
  21475. }
  21476. }
  21477. const _box = /*@__PURE__*/ new Box3();
  21478. class BoxHelper extends LineSegments {
  21479. constructor( object, color = 0xffff00 ) {
  21480. 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 ] );
  21481. const positions = new Float32Array( 8 * 3 );
  21482. const geometry = new BufferGeometry();
  21483. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21484. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  21485. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21486. this.object = object;
  21487. this.type = 'BoxHelper';
  21488. this.matrixAutoUpdate = false;
  21489. this.update();
  21490. }
  21491. update( object ) {
  21492. if ( object !== undefined ) {
  21493. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  21494. }
  21495. if ( this.object !== undefined ) {
  21496. _box.setFromObject( this.object );
  21497. }
  21498. if ( _box.isEmpty() ) return;
  21499. const min = _box.min;
  21500. const max = _box.max;
  21501. /*
  21502. 5____4
  21503. 1/___0/|
  21504. | 6__|_7
  21505. 2/___3/
  21506. 0: max.x, max.y, max.z
  21507. 1: min.x, max.y, max.z
  21508. 2: min.x, min.y, max.z
  21509. 3: max.x, min.y, max.z
  21510. 4: max.x, max.y, min.z
  21511. 5: min.x, max.y, min.z
  21512. 6: min.x, min.y, min.z
  21513. 7: max.x, min.y, min.z
  21514. */
  21515. const position = this.geometry.attributes.position;
  21516. const array = position.array;
  21517. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21518. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21519. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21520. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21521. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21522. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21523. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21524. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21525. position.needsUpdate = true;
  21526. this.geometry.computeBoundingSphere();
  21527. }
  21528. setFromObject( object ) {
  21529. this.object = object;
  21530. this.update();
  21531. return this;
  21532. }
  21533. copy( source, recursive ) {
  21534. super.copy( source, recursive );
  21535. this.object = source.object;
  21536. return this;
  21537. }
  21538. dispose() {
  21539. this.geometry.dispose();
  21540. this.material.dispose();
  21541. }
  21542. }
  21543. class Box3Helper extends LineSegments {
  21544. constructor( box, color = 0xffff00 ) {
  21545. 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 ] );
  21546. 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 ];
  21547. const geometry = new BufferGeometry();
  21548. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21549. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21550. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21551. this.box = box;
  21552. this.type = 'Box3Helper';
  21553. this.geometry.computeBoundingSphere();
  21554. }
  21555. updateMatrixWorld( force ) {
  21556. const box = this.box;
  21557. if ( box.isEmpty() ) return;
  21558. box.getCenter( this.position );
  21559. box.getSize( this.scale );
  21560. this.scale.multiplyScalar( 0.5 );
  21561. super.updateMatrixWorld( force );
  21562. }
  21563. dispose() {
  21564. this.geometry.dispose();
  21565. this.material.dispose();
  21566. }
  21567. }
  21568. class PlaneHelper extends Line {
  21569. constructor( plane, size = 1, hex = 0xffff00 ) {
  21570. const color = hex;
  21571. const positions = [ 1, -1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, -1, 0, 1, 1, 0 ];
  21572. const geometry = new BufferGeometry();
  21573. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21574. geometry.computeBoundingSphere();
  21575. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21576. this.type = 'PlaneHelper';
  21577. this.plane = plane;
  21578. this.size = size;
  21579. const positions2 = [ 1, 1, 0, -1, 1, 0, -1, -1, 0, 1, 1, 0, -1, -1, 0, 1, -1, 0 ];
  21580. const geometry2 = new BufferGeometry();
  21581. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  21582. geometry2.computeBoundingSphere();
  21583. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  21584. }
  21585. updateMatrixWorld( force ) {
  21586. this.position.set( 0, 0, 0 );
  21587. this.scale.set( 0.5 * this.size, 0.5 * this.size, 1 );
  21588. this.lookAt( this.plane.normal );
  21589. this.translateZ( - this.plane.constant );
  21590. super.updateMatrixWorld( force );
  21591. }
  21592. dispose() {
  21593. this.geometry.dispose();
  21594. this.material.dispose();
  21595. this.children[ 0 ].geometry.dispose();
  21596. this.children[ 0 ].material.dispose();
  21597. }
  21598. }
  21599. const _axis = /*@__PURE__*/ new Vector3();
  21600. let _lineGeometry, _coneGeometry;
  21601. class ArrowHelper extends Object3D {
  21602. // dir is assumed to be normalized
  21603. constructor( dir = new Vector3( 0, 0, 1 ), origin = new Vector3( 0, 0, 0 ), length = 1, color = 0xffff00, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21604. super();
  21605. this.type = 'ArrowHelper';
  21606. if ( _lineGeometry === undefined ) {
  21607. _lineGeometry = new BufferGeometry();
  21608. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  21609. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21610. _coneGeometry.translate( 0, -0.5, 0 );
  21611. }
  21612. this.position.copy( origin );
  21613. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21614. this.line.matrixAutoUpdate = false;
  21615. this.add( this.line );
  21616. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  21617. this.cone.matrixAutoUpdate = false;
  21618. this.add( this.cone );
  21619. this.setDirection( dir );
  21620. this.setLength( length, headLength, headWidth );
  21621. }
  21622. setDirection( dir ) {
  21623. // dir is assumed to be normalized
  21624. if ( dir.y > 0.99999 ) {
  21625. this.quaternion.set( 0, 0, 0, 1 );
  21626. } else if ( dir.y < -0.99999 ) {
  21627. this.quaternion.set( 1, 0, 0, 0 );
  21628. } else {
  21629. _axis.set( dir.z, 0, - dir.x ).normalize();
  21630. const radians = Math.acos( dir.y );
  21631. this.quaternion.setFromAxisAngle( _axis, radians );
  21632. }
  21633. }
  21634. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21635. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  21636. this.line.updateMatrix();
  21637. this.cone.scale.set( headWidth, headLength, headWidth );
  21638. this.cone.position.y = length;
  21639. this.cone.updateMatrix();
  21640. }
  21641. setColor( color ) {
  21642. this.line.material.color.set( color );
  21643. this.cone.material.color.set( color );
  21644. }
  21645. copy( source ) {
  21646. super.copy( source, false );
  21647. this.line.copy( source.line );
  21648. this.cone.copy( source.cone );
  21649. return this;
  21650. }
  21651. dispose() {
  21652. this.line.geometry.dispose();
  21653. this.line.material.dispose();
  21654. this.cone.geometry.dispose();
  21655. this.cone.material.dispose();
  21656. }
  21657. }
  21658. class AxesHelper extends LineSegments {
  21659. constructor( size = 1 ) {
  21660. const vertices = [
  21661. 0, 0, 0, size, 0, 0,
  21662. 0, 0, 0, 0, size, 0,
  21663. 0, 0, 0, 0, 0, size
  21664. ];
  21665. const colors = [
  21666. 1, 0, 0, 1, 0.6, 0,
  21667. 0, 1, 0, 0.6, 1, 0,
  21668. 0, 0, 1, 0, 0.6, 1
  21669. ];
  21670. const geometry = new BufferGeometry();
  21671. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21672. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21673. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21674. super( geometry, material );
  21675. this.type = 'AxesHelper';
  21676. }
  21677. setColors( xAxisColor, yAxisColor, zAxisColor ) {
  21678. const color = new Color();
  21679. const array = this.geometry.attributes.color.array;
  21680. color.set( xAxisColor );
  21681. color.toArray( array, 0 );
  21682. color.toArray( array, 3 );
  21683. color.set( yAxisColor );
  21684. color.toArray( array, 6 );
  21685. color.toArray( array, 9 );
  21686. color.set( zAxisColor );
  21687. color.toArray( array, 12 );
  21688. color.toArray( array, 15 );
  21689. this.geometry.attributes.color.needsUpdate = true;
  21690. return this;
  21691. }
  21692. dispose() {
  21693. this.geometry.dispose();
  21694. this.material.dispose();
  21695. }
  21696. }
  21697. class ShapePath {
  21698. constructor() {
  21699. this.type = 'ShapePath';
  21700. this.color = new Color();
  21701. this.subPaths = [];
  21702. this.currentPath = null;
  21703. }
  21704. moveTo( x, y ) {
  21705. this.currentPath = new Path();
  21706. this.subPaths.push( this.currentPath );
  21707. this.currentPath.moveTo( x, y );
  21708. return this;
  21709. }
  21710. lineTo( x, y ) {
  21711. this.currentPath.lineTo( x, y );
  21712. return this;
  21713. }
  21714. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  21715. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21716. return this;
  21717. }
  21718. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21719. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21720. return this;
  21721. }
  21722. splineThru( pts ) {
  21723. this.currentPath.splineThru( pts );
  21724. return this;
  21725. }
  21726. toShapes( isCCW ) {
  21727. function toShapesNoHoles( inSubpaths ) {
  21728. const shapes = [];
  21729. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21730. const tmpPath = inSubpaths[ i ];
  21731. const tmpShape = new Shape();
  21732. tmpShape.curves = tmpPath.curves;
  21733. shapes.push( tmpShape );
  21734. }
  21735. return shapes;
  21736. }
  21737. function isPointInsidePolygon( inPt, inPolygon ) {
  21738. const polyLen = inPolygon.length;
  21739. // inPt on polygon contour => immediate success or
  21740. // toggling of inside/outside at every single! intersection point of an edge
  21741. // with the horizontal line through inPt, left of inPt
  21742. // not counting lowerY endpoints of edges and whole edges on that line
  21743. let inside = false;
  21744. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21745. let edgeLowPt = inPolygon[ p ];
  21746. let edgeHighPt = inPolygon[ q ];
  21747. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  21748. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  21749. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21750. // not parallel
  21751. if ( edgeDy < 0 ) {
  21752. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21753. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21754. }
  21755. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21756. if ( inPt.y === edgeLowPt.y ) {
  21757. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21758. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21759. } else {
  21760. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21761. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21762. if ( perpEdge < 0 ) continue;
  21763. inside = ! inside; // true intersection left of inPt
  21764. }
  21765. } else {
  21766. // parallel or collinear
  21767. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21768. // edge lies on the same horizontal line as inPt
  21769. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21770. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21771. // continue;
  21772. }
  21773. }
  21774. return inside;
  21775. }
  21776. const isClockWise = ShapeUtils.isClockWise;
  21777. const subPaths = this.subPaths;
  21778. if ( subPaths.length === 0 ) return [];
  21779. let solid, tmpPath, tmpShape;
  21780. const shapes = [];
  21781. if ( subPaths.length === 1 ) {
  21782. tmpPath = subPaths[ 0 ];
  21783. tmpShape = new Shape();
  21784. tmpShape.curves = tmpPath.curves;
  21785. shapes.push( tmpShape );
  21786. return shapes;
  21787. }
  21788. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21789. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21790. // console.log("Holes first", holesFirst);
  21791. const betterShapeHoles = [];
  21792. const newShapes = [];
  21793. let newShapeHoles = [];
  21794. let mainIdx = 0;
  21795. let tmpPoints;
  21796. newShapes[ mainIdx ] = undefined;
  21797. newShapeHoles[ mainIdx ] = [];
  21798. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  21799. tmpPath = subPaths[ i ];
  21800. tmpPoints = tmpPath.getPoints();
  21801. solid = isClockWise( tmpPoints );
  21802. solid = isCCW ? ! solid : solid;
  21803. if ( solid ) {
  21804. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21805. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21806. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21807. if ( holesFirst ) mainIdx ++;
  21808. newShapeHoles[ mainIdx ] = [];
  21809. //console.log('cw', i);
  21810. } else {
  21811. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21812. //console.log('ccw', i);
  21813. }
  21814. }
  21815. // only Holes? -> probably all Shapes with wrong orientation
  21816. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21817. if ( newShapes.length > 1 ) {
  21818. let ambiguous = false;
  21819. let toChange = 0;
  21820. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21821. betterShapeHoles[ sIdx ] = [];
  21822. }
  21823. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21824. const sho = newShapeHoles[ sIdx ];
  21825. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21826. const ho = sho[ hIdx ];
  21827. let hole_unassigned = true;
  21828. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21829. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21830. if ( sIdx !== s2Idx ) toChange ++;
  21831. if ( hole_unassigned ) {
  21832. hole_unassigned = false;
  21833. betterShapeHoles[ s2Idx ].push( ho );
  21834. } else {
  21835. ambiguous = true;
  21836. }
  21837. }
  21838. }
  21839. if ( hole_unassigned ) {
  21840. betterShapeHoles[ sIdx ].push( ho );
  21841. }
  21842. }
  21843. }
  21844. if ( toChange > 0 && ambiguous === false ) {
  21845. newShapeHoles = betterShapeHoles;
  21846. }
  21847. }
  21848. let tmpHoles;
  21849. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  21850. tmpShape = newShapes[ i ].s;
  21851. shapes.push( tmpShape );
  21852. tmpHoles = newShapeHoles[ i ];
  21853. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21854. tmpShape.holes.push( tmpHoles[ j ].h );
  21855. }
  21856. }
  21857. //console.log("shape", shapes);
  21858. return shapes;
  21859. }
  21860. }
  21861. class Controls extends EventDispatcher {
  21862. constructor( object, domElement = null ) {
  21863. super();
  21864. this.object = object;
  21865. this.domElement = domElement;
  21866. this.enabled = true;
  21867. this.state = -1;
  21868. this.keys = {};
  21869. this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
  21870. this.touches = { ONE: null, TWO: null };
  21871. }
  21872. connect() {}
  21873. disconnect() {}
  21874. dispose() {}
  21875. update( /* delta */ ) {}
  21876. }
  21877. function contain( texture, aspect ) {
  21878. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21879. if ( imageAspect > aspect ) {
  21880. texture.repeat.x = 1;
  21881. texture.repeat.y = imageAspect / aspect;
  21882. texture.offset.x = 0;
  21883. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21884. } else {
  21885. texture.repeat.x = aspect / imageAspect;
  21886. texture.repeat.y = 1;
  21887. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21888. texture.offset.y = 0;
  21889. }
  21890. return texture;
  21891. }
  21892. function cover( texture, aspect ) {
  21893. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21894. if ( imageAspect > aspect ) {
  21895. texture.repeat.x = aspect / imageAspect;
  21896. texture.repeat.y = 1;
  21897. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21898. texture.offset.y = 0;
  21899. } else {
  21900. texture.repeat.x = 1;
  21901. texture.repeat.y = imageAspect / aspect;
  21902. texture.offset.x = 0;
  21903. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21904. }
  21905. return texture;
  21906. }
  21907. function fill( texture ) {
  21908. texture.repeat.x = 1;
  21909. texture.repeat.y = 1;
  21910. texture.offset.x = 0;
  21911. texture.offset.y = 0;
  21912. return texture;
  21913. }
  21914. /**
  21915. * Given the width, height, format, and type of a texture. Determines how many
  21916. * bytes must be used to represent the texture.
  21917. *
  21918. * @param {Number} width
  21919. * @param {Number} height
  21920. * @param {Number} format
  21921. * @param {Number} type
  21922. * @return {Number} The number of bytes required to represent the texture.
  21923. */
  21924. function getByteLength( width, height, format, type ) {
  21925. const typeByteLength = getTextureTypeByteLength( type );
  21926. switch ( format ) {
  21927. // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
  21928. case AlphaFormat:
  21929. return width * height;
  21930. case LuminanceFormat:
  21931. return width * height;
  21932. case LuminanceAlphaFormat:
  21933. return width * height * 2;
  21934. case RedFormat:
  21935. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21936. case RedIntegerFormat:
  21937. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21938. case RGFormat:
  21939. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21940. case RGIntegerFormat:
  21941. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21942. case RGBFormat:
  21943. return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21944. case RGBAFormat:
  21945. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21946. case RGBAIntegerFormat:
  21947. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21948. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/
  21949. case RGB_S3TC_DXT1_Format:
  21950. case RGBA_S3TC_DXT1_Format:
  21951. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21952. case RGBA_S3TC_DXT3_Format:
  21953. case RGBA_S3TC_DXT5_Format:
  21954. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21955. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/
  21956. case RGB_PVRTC_2BPPV1_Format:
  21957. case RGBA_PVRTC_2BPPV1_Format:
  21958. return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4;
  21959. case RGB_PVRTC_4BPPV1_Format:
  21960. case RGBA_PVRTC_4BPPV1_Format:
  21961. return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2;
  21962. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/
  21963. case RGB_ETC1_Format:
  21964. case RGB_ETC2_Format:
  21965. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21966. case RGBA_ETC2_EAC_Format:
  21967. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21968. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
  21969. case RGBA_ASTC_4x4_Format:
  21970. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21971. case RGBA_ASTC_5x4_Format:
  21972. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21973. case RGBA_ASTC_5x5_Format:
  21974. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21975. case RGBA_ASTC_6x5_Format:
  21976. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21977. case RGBA_ASTC_6x6_Format:
  21978. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21979. case RGBA_ASTC_8x5_Format:
  21980. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21981. case RGBA_ASTC_8x6_Format:
  21982. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21983. case RGBA_ASTC_8x8_Format:
  21984. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21985. case RGBA_ASTC_10x5_Format:
  21986. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21987. case RGBA_ASTC_10x6_Format:
  21988. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21989. case RGBA_ASTC_10x8_Format:
  21990. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21991. case RGBA_ASTC_10x10_Format:
  21992. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21993. case RGBA_ASTC_12x10_Format:
  21994. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21995. case RGBA_ASTC_12x12_Format:
  21996. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;
  21997. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
  21998. case RGBA_BPTC_Format:
  21999. case RGB_BPTC_SIGNED_Format:
  22000. case RGB_BPTC_UNSIGNED_Format:
  22001. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  22002. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
  22003. case RED_RGTC1_Format:
  22004. case SIGNED_RED_RGTC1_Format:
  22005. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
  22006. case RED_GREEN_RGTC2_Format:
  22007. case SIGNED_RED_GREEN_RGTC2_Format:
  22008. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  22009. }
  22010. throw new Error(
  22011. `Unable to determine texture byte length for ${format} format.`,
  22012. );
  22013. }
  22014. function getTextureTypeByteLength( type ) {
  22015. switch ( type ) {
  22016. case UnsignedByteType:
  22017. case ByteType:
  22018. return { byteLength: 1, components: 1 };
  22019. case UnsignedShortType:
  22020. case ShortType:
  22021. case HalfFloatType:
  22022. return { byteLength: 2, components: 1 };
  22023. case UnsignedShort4444Type:
  22024. case UnsignedShort5551Type:
  22025. return { byteLength: 2, components: 4 };
  22026. case UnsignedIntType:
  22027. case IntType:
  22028. case FloatType:
  22029. return { byteLength: 4, components: 1 };
  22030. case UnsignedInt5999Type:
  22031. return { byteLength: 4, components: 3 };
  22032. }
  22033. throw new Error( `Unknown texture type ${type}.` );
  22034. }
  22035. const TextureUtils = {
  22036. contain,
  22037. cover,
  22038. fill,
  22039. getByteLength
  22040. };
  22041. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  22042. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  22043. revision: REVISION,
  22044. } } ) );
  22045. }
  22046. if ( typeof window !== 'undefined' ) {
  22047. if ( window.__THREE__ ) {
  22048. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  22049. } else {
  22050. window.__THREE__ = REVISION;
  22051. }
  22052. }
  22053. export { ACESFilmicToneMapping, AddEquation, AddOperation, AdditiveAnimationBlendMode, AdditiveBlending, AgXToneMapping, AlphaFormat, AlwaysCompare, AlwaysDepth, AlwaysStencilFunc, AmbientLight, AnimationAction, AnimationClip, AnimationLoader, AnimationMixer, AnimationObjectGroup, AnimationUtils, ArcCurve, ArrayCamera, ArrowHelper, AttachedBindMode, Audio, AudioAnalyser, AudioContext, AudioListener, AudioLoader, AxesHelper, BackSide, BasicDepthPacking, BasicShadowMap, BatchedMesh, Bone, BooleanKeyframeTrack, Box2, Box3, Box3Helper, BoxGeometry, BoxHelper, BufferAttribute, BufferGeometry, BufferGeometryLoader, ByteType, Cache, Camera, CameraHelper, CanvasTexture, CapsuleGeometry, CatmullRomCurve3, CineonToneMapping, CircleGeometry, ClampToEdgeWrapping, Clock, Color, ColorKeyframeTrack, ColorManagement, CompressedArrayTexture, CompressedCubeTexture, CompressedTexture, CompressedTextureLoader, ConeGeometry, ConstantAlphaFactor, ConstantColorFactor, Controls, CubeCamera, CubeReflectionMapping, CubeRefractionMapping, CubeTexture, CubeTextureLoader, CubeUVReflectionMapping, CubicBezierCurve, CubicBezierCurve3, CubicInterpolant, CullFaceBack, CullFaceFront, CullFaceFrontBack, CullFaceNone, Curve, CurvePath, CustomBlending, CustomToneMapping, CylinderGeometry, Cylindrical, Data3DTexture, DataArrayTexture, DataTexture, DataTextureLoader, DataUtils, DecrementStencilOp, DecrementWrapStencilOp, DefaultLoadingManager, DepthFormat, DepthStencilFormat, DepthTexture, DetachedBindMode, DirectionalLight, DirectionalLightHelper, DiscreteInterpolant, DodecahedronGeometry, DoubleSide, DstAlphaFactor, DstColorFactor, DynamicCopyUsage, DynamicDrawUsage, DynamicReadUsage, EdgesGeometry, EllipseCurve, EqualCompare, EqualDepth, EqualStencilFunc, EquirectangularReflectionMapping, EquirectangularRefractionMapping, Euler, EventDispatcher, ExtrudeGeometry, FileLoader, Float16BufferAttribute, Float32BufferAttribute, FloatType, Fog, FogExp2, FramebufferTexture, FrontSide, Frustum, GLBufferAttribute, GLSL1, GLSL3, GreaterCompare, GreaterDepth, GreaterEqualCompare, GreaterEqualDepth, GreaterEqualStencilFunc, GreaterStencilFunc, GridHelper, Group, HalfFloatType, HemisphereLight, HemisphereLightHelper, IcosahedronGeometry, ImageBitmapLoader, ImageLoader, ImageUtils, IncrementStencilOp, IncrementWrapStencilOp, InstancedBufferAttribute, InstancedBufferGeometry, InstancedInterleavedBuffer, InstancedMesh, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntType, InterleavedBuffer, InterleavedBufferAttribute, Interpolant, InterpolateDiscrete, InterpolateLinear, InterpolateSmooth, InvertStencilOp, KeepStencilOp, KeyframeTrack, LOD, LatheGeometry, Layers, LessCompare, LessDepth, LessEqualCompare, LessEqualDepth, LessEqualStencilFunc, LessStencilFunc, Light, LightProbe, Line, Line3, LineBasicMaterial, LineCurve, LineCurve3, LineDashedMaterial, LineLoop, LineSegments, LinearFilter, LinearInterpolant, LinearMipMapLinearFilter, LinearMipMapNearestFilter, LinearMipmapLinearFilter, LinearMipmapNearestFilter, LinearSRGBColorSpace, LinearToneMapping, LinearTransfer, Loader, LoaderUtils, LoadingManager, LoopOnce, LoopPingPong, LoopRepeat, LuminanceAlphaFormat, LuminanceFormat, MOUSE, Material, MaterialLoader, MathUtils, Matrix2, Matrix3, Matrix4, MaxEquation, Mesh, MeshBasicMaterial, MeshDepthMaterial, MeshDistanceMaterial, MeshLambertMaterial, MeshMatcapMaterial, MeshNormalMaterial, MeshPhongMaterial, MeshPhysicalMaterial, MeshStandardMaterial, MeshToonMaterial, MinEquation, MirroredRepeatWrapping, MixOperation, MultiplyBlending, MultiplyOperation, NearestFilter, NearestMipMapLinearFilter, NearestMipMapNearestFilter, NearestMipmapLinearFilter, NearestMipmapNearestFilter, NeutralToneMapping, NeverCompare, NeverDepth, NeverStencilFunc, NoBlending, NoColorSpace, NoToneMapping, NormalAnimationBlendMode, NormalBlending, NotEqualCompare, NotEqualDepth, NotEqualStencilFunc, NumberKeyframeTrack, Object3D, ObjectLoader, ObjectSpaceNormalMap, OctahedronGeometry, OneFactor, OneMinusConstantAlphaFactor, OneMinusConstantColorFactor, OneMinusDstAlphaFactor, OneMinusDstColorFactor, OneMinusSrcAlphaFactor, OneMinusSrcColorFactor, OrthographicCamera, PCFShadowMap, PCFSoftShadowMap, Path, PerspectiveCamera, Plane, PlaneGeometry, PlaneHelper, PointLight, PointLightHelper, Points, PointsMaterial, PolarGridHelper, PolyhedronGeometry, PositionalAudio, PropertyBinding, PropertyMixer, QuadraticBezierCurve, QuadraticBezierCurve3, Quaternion, QuaternionKeyframeTrack, QuaternionLinearInterpolant, RAD2DEG, RED_GREEN_RGTC2_Format, RED_RGTC1_Format, REVISION, RGBADepthPacking, RGBAFormat, RGBAIntegerFormat, RGBA_ASTC_10x10_Format, RGBA_ASTC_10x5_Format, RGBA_ASTC_10x6_Format, RGBA_ASTC_10x8_Format, RGBA_ASTC_12x10_Format, RGBA_ASTC_12x12_Format, RGBA_ASTC_4x4_Format, RGBA_ASTC_5x4_Format, RGBA_ASTC_5x5_Format, RGBA_ASTC_6x5_Format, RGBA_ASTC_6x6_Format, RGBA_ASTC_8x5_Format, RGBA_ASTC_8x6_Format, RGBA_ASTC_8x8_Format, RGBA_BPTC_Format, RGBA_ETC2_EAC_Format, RGBA_PVRTC_2BPPV1_Format, RGBA_PVRTC_4BPPV1_Format, RGBA_S3TC_DXT1_Format, RGBA_S3TC_DXT3_Format, RGBA_S3TC_DXT5_Format, RGBDepthPacking, RGBFormat, RGBIntegerFormat, RGB_BPTC_SIGNED_Format, RGB_BPTC_UNSIGNED_Format, RGB_ETC1_Format, RGB_ETC2_Format, RGB_PVRTC_2BPPV1_Format, RGB_PVRTC_4BPPV1_Format, RGB_S3TC_DXT1_Format, RGDepthPacking, RGFormat, RGIntegerFormat, RawShaderMaterial, Ray, Raycaster, RectAreaLight, RedFormat, RedIntegerFormat, ReinhardToneMapping, RenderTarget, RenderTarget3D, RenderTargetArray, RepeatWrapping, ReplaceStencilOp, ReverseSubtractEquation, RingGeometry, SIGNED_RED_GREEN_RGTC2_Format, SIGNED_RED_RGTC1_Format, SRGBColorSpace, SRGBTransfer, Scene, ShaderMaterial, ShadowMaterial, Shape, ShapeGeometry, ShapePath, ShapeUtils, ShortType, Skeleton, SkeletonHelper, SkinnedMesh, Source, Sphere, SphereGeometry, Spherical, SphericalHarmonics3, SplineCurve, SpotLight, SpotLightHelper, Sprite, SpriteMaterial, SrcAlphaFactor, SrcAlphaSaturateFactor, SrcColorFactor, StaticCopyUsage, StaticDrawUsage, StaticReadUsage, StereoCamera, StreamCopyUsage, StreamDrawUsage, StreamReadUsage, StringKeyframeTrack, SubtractEquation, SubtractiveBlending, TOUCH, TangentSpaceNormalMap, TetrahedronGeometry, Texture, TextureLoader, TextureUtils, TimestampQuery, TorusGeometry, TorusKnotGeometry, Triangle, TriangleFanDrawMode, TriangleStripDrawMode, TrianglesDrawMode, TubeGeometry, UVMapping, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Uniform, UniformsGroup, UniformsUtils, UnsignedByteType, UnsignedInt248Type, UnsignedInt5999Type, UnsignedIntType, UnsignedShort4444Type, UnsignedShort5551Type, UnsignedShortType, VSMShadowMap, Vector2, Vector3, Vector4, VectorKeyframeTrack, VideoFrameTexture, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGPUCoordinateSystem, WebXRController, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, arrayNeedsUint32, cloneUniforms, createCanvasElement, createElementNS, getByteLength, getUnlitUniformColorSpace, mergeUniforms, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce };
粤ICP备19079148号