three.core.js 735 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967
  1. /**
  2. * @license
  3. * Copyright 2010-2024 Three.js Authors
  4. * SPDX-License-Identifier: MIT
  5. */
  6. const REVISION = '172dev';
  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. /**
  207. * https://github.com/mrdoob/eventdispatcher.js/
  208. */
  209. class EventDispatcher {
  210. addEventListener( type, listener ) {
  211. if ( this._listeners === undefined ) this._listeners = {};
  212. const listeners = this._listeners;
  213. if ( listeners[ type ] === undefined ) {
  214. listeners[ type ] = [];
  215. }
  216. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  217. listeners[ type ].push( listener );
  218. }
  219. }
  220. hasEventListener( type, listener ) {
  221. if ( this._listeners === undefined ) return false;
  222. const listeners = this._listeners;
  223. return listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1;
  224. }
  225. removeEventListener( type, listener ) {
  226. if ( this._listeners === undefined ) return;
  227. const listeners = this._listeners;
  228. const listenerArray = listeners[ type ];
  229. if ( listenerArray !== undefined ) {
  230. const index = listenerArray.indexOf( listener );
  231. if ( index !== - 1 ) {
  232. listenerArray.splice( index, 1 );
  233. }
  234. }
  235. }
  236. dispatchEvent( event ) {
  237. if ( this._listeners === undefined ) return;
  238. const listeners = this._listeners;
  239. const listenerArray = listeners[ event.type ];
  240. if ( listenerArray !== undefined ) {
  241. event.target = this;
  242. // Make a copy, in case listeners are removed while iterating.
  243. const array = listenerArray.slice( 0 );
  244. for ( let i = 0, l = array.length; i < l; i ++ ) {
  245. array[ i ].call( this, event );
  246. }
  247. event.target = null;
  248. }
  249. }
  250. }
  251. 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' ];
  252. let _seed = 1234567;
  253. const DEG2RAD = Math.PI / 180;
  254. const RAD2DEG = 180 / Math.PI;
  255. // http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/21963136#21963136
  256. function generateUUID() {
  257. const d0 = Math.random() * 0xffffffff | 0;
  258. const d1 = Math.random() * 0xffffffff | 0;
  259. const d2 = Math.random() * 0xffffffff | 0;
  260. const d3 = Math.random() * 0xffffffff | 0;
  261. const uuid = _lut[ d0 & 0xff ] + _lut[ d0 >> 8 & 0xff ] + _lut[ d0 >> 16 & 0xff ] + _lut[ d0 >> 24 & 0xff ] + '-' +
  262. _lut[ d1 & 0xff ] + _lut[ d1 >> 8 & 0xff ] + '-' + _lut[ d1 >> 16 & 0x0f | 0x40 ] + _lut[ d1 >> 24 & 0xff ] + '-' +
  263. _lut[ d2 & 0x3f | 0x80 ] + _lut[ d2 >> 8 & 0xff ] + '-' + _lut[ d2 >> 16 & 0xff ] + _lut[ d2 >> 24 & 0xff ] +
  264. _lut[ d3 & 0xff ] + _lut[ d3 >> 8 & 0xff ] + _lut[ d3 >> 16 & 0xff ] + _lut[ d3 >> 24 & 0xff ];
  265. // .toLowerCase() here flattens concatenated strings to save heap memory space.
  266. return uuid.toLowerCase();
  267. }
  268. function clamp( value, min, max ) {
  269. return Math.max( min, Math.min( max, value ) );
  270. }
  271. // compute euclidean modulo of m % n
  272. // https://en.wikipedia.org/wiki/Modulo_operation
  273. function euclideanModulo( n, m ) {
  274. return ( ( n % m ) + m ) % m;
  275. }
  276. // Linear mapping from range <a1, a2> to range <b1, b2>
  277. function mapLinear( x, a1, a2, b1, b2 ) {
  278. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  279. }
  280. // https://www.gamedev.net/tutorials/programming/general-and-gameplay-programming/inverse-lerp-a-super-useful-yet-often-overlooked-function-r5230/
  281. function inverseLerp( x, y, value ) {
  282. if ( x !== y ) {
  283. return ( value - x ) / ( y - x );
  284. } else {
  285. return 0;
  286. }
  287. }
  288. // https://en.wikipedia.org/wiki/Linear_interpolation
  289. function lerp( x, y, t ) {
  290. return ( 1 - t ) * x + t * y;
  291. }
  292. // http://www.rorydriscoll.com/2016/03/07/frame-rate-independent-damping-using-lerp/
  293. function damp( x, y, lambda, dt ) {
  294. return lerp( x, y, 1 - Math.exp( - lambda * dt ) );
  295. }
  296. // https://www.desmos.com/calculator/vcsjnyz7x4
  297. function pingpong( x, length = 1 ) {
  298. return length - Math.abs( euclideanModulo( x, length * 2 ) - length );
  299. }
  300. // http://en.wikipedia.org/wiki/Smoothstep
  301. function smoothstep( x, min, max ) {
  302. if ( x <= min ) return 0;
  303. if ( x >= max ) return 1;
  304. x = ( x - min ) / ( max - min );
  305. return x * x * ( 3 - 2 * x );
  306. }
  307. function smootherstep( x, min, max ) {
  308. if ( x <= min ) return 0;
  309. if ( x >= max ) return 1;
  310. x = ( x - min ) / ( max - min );
  311. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  312. }
  313. // Random integer from <low, high> interval
  314. function randInt( low, high ) {
  315. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  316. }
  317. // Random float from <low, high> interval
  318. function randFloat( low, high ) {
  319. return low + Math.random() * ( high - low );
  320. }
  321. // Random float from <-range/2, range/2> interval
  322. function randFloatSpread( range ) {
  323. return range * ( 0.5 - Math.random() );
  324. }
  325. // Deterministic pseudo-random float in the interval [ 0, 1 ]
  326. function seededRandom( s ) {
  327. if ( s !== undefined ) _seed = s;
  328. // Mulberry32 generator
  329. let t = _seed += 0x6D2B79F5;
  330. t = Math.imul( t ^ t >>> 15, t | 1 );
  331. t ^= t + Math.imul( t ^ t >>> 7, t | 61 );
  332. return ( ( t ^ t >>> 14 ) >>> 0 ) / 4294967296;
  333. }
  334. function degToRad( degrees ) {
  335. return degrees * DEG2RAD;
  336. }
  337. function radToDeg( radians ) {
  338. return radians * RAD2DEG;
  339. }
  340. function isPowerOfTwo( value ) {
  341. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  342. }
  343. function ceilPowerOfTwo( value ) {
  344. return Math.pow( 2, Math.ceil( Math.log( value ) / Math.LN2 ) );
  345. }
  346. function floorPowerOfTwo( value ) {
  347. return Math.pow( 2, Math.floor( Math.log( value ) / Math.LN2 ) );
  348. }
  349. function setQuaternionFromProperEuler( q, a, b, c, order ) {
  350. // Intrinsic Proper Euler Angles - see https://en.wikipedia.org/wiki/Euler_angles
  351. // rotations are applied to the axes in the order specified by 'order'
  352. // rotation by angle 'a' is applied first, then by angle 'b', then by angle 'c'
  353. // angles are in radians
  354. const cos = Math.cos;
  355. const sin = Math.sin;
  356. const c2 = cos( b / 2 );
  357. const s2 = sin( b / 2 );
  358. const c13 = cos( ( a + c ) / 2 );
  359. const s13 = sin( ( a + c ) / 2 );
  360. const c1_3 = cos( ( a - c ) / 2 );
  361. const s1_3 = sin( ( a - c ) / 2 );
  362. const c3_1 = cos( ( c - a ) / 2 );
  363. const s3_1 = sin( ( c - a ) / 2 );
  364. switch ( order ) {
  365. case 'XYX':
  366. q.set( c2 * s13, s2 * c1_3, s2 * s1_3, c2 * c13 );
  367. break;
  368. case 'YZY':
  369. q.set( s2 * s1_3, c2 * s13, s2 * c1_3, c2 * c13 );
  370. break;
  371. case 'ZXZ':
  372. q.set( s2 * c1_3, s2 * s1_3, c2 * s13, c2 * c13 );
  373. break;
  374. case 'XZX':
  375. q.set( c2 * s13, s2 * s3_1, s2 * c3_1, c2 * c13 );
  376. break;
  377. case 'YXY':
  378. q.set( s2 * c3_1, c2 * s13, s2 * s3_1, c2 * c13 );
  379. break;
  380. case 'ZYZ':
  381. q.set( s2 * s3_1, s2 * c3_1, c2 * s13, c2 * c13 );
  382. break;
  383. default:
  384. console.warn( 'THREE.MathUtils: .setQuaternionFromProperEuler() encountered an unknown order: ' + order );
  385. }
  386. }
  387. function denormalize( value, array ) {
  388. switch ( array.constructor ) {
  389. case Float32Array:
  390. return value;
  391. case Uint32Array:
  392. return value / 4294967295.0;
  393. case Uint16Array:
  394. return value / 65535.0;
  395. case Uint8Array:
  396. return value / 255.0;
  397. case Int32Array:
  398. return Math.max( value / 2147483647.0, - 1.0 );
  399. case Int16Array:
  400. return Math.max( value / 32767.0, - 1.0 );
  401. case Int8Array:
  402. return Math.max( value / 127.0, - 1.0 );
  403. default:
  404. throw new Error( 'Invalid component type.' );
  405. }
  406. }
  407. function normalize( value, array ) {
  408. switch ( array.constructor ) {
  409. case Float32Array:
  410. return value;
  411. case Uint32Array:
  412. return Math.round( value * 4294967295.0 );
  413. case Uint16Array:
  414. return Math.round( value * 65535.0 );
  415. case Uint8Array:
  416. return Math.round( value * 255.0 );
  417. case Int32Array:
  418. return Math.round( value * 2147483647.0 );
  419. case Int16Array:
  420. return Math.round( value * 32767.0 );
  421. case Int8Array:
  422. return Math.round( value * 127.0 );
  423. default:
  424. throw new Error( 'Invalid component type.' );
  425. }
  426. }
  427. const MathUtils = {
  428. DEG2RAD: DEG2RAD,
  429. RAD2DEG: RAD2DEG,
  430. generateUUID: generateUUID,
  431. clamp: clamp,
  432. euclideanModulo: euclideanModulo,
  433. mapLinear: mapLinear,
  434. inverseLerp: inverseLerp,
  435. lerp: lerp,
  436. damp: damp,
  437. pingpong: pingpong,
  438. smoothstep: smoothstep,
  439. smootherstep: smootherstep,
  440. randInt: randInt,
  441. randFloat: randFloat,
  442. randFloatSpread: randFloatSpread,
  443. seededRandom: seededRandom,
  444. degToRad: degToRad,
  445. radToDeg: radToDeg,
  446. isPowerOfTwo: isPowerOfTwo,
  447. ceilPowerOfTwo: ceilPowerOfTwo,
  448. floorPowerOfTwo: floorPowerOfTwo,
  449. setQuaternionFromProperEuler: setQuaternionFromProperEuler,
  450. normalize: normalize,
  451. denormalize: denormalize
  452. };
  453. class Vector2 {
  454. constructor( x = 0, y = 0 ) {
  455. Vector2.prototype.isVector2 = true;
  456. this.x = x;
  457. this.y = y;
  458. }
  459. get width() {
  460. return this.x;
  461. }
  462. set width( value ) {
  463. this.x = value;
  464. }
  465. get height() {
  466. return this.y;
  467. }
  468. set height( value ) {
  469. this.y = value;
  470. }
  471. set( x, y ) {
  472. this.x = x;
  473. this.y = y;
  474. return this;
  475. }
  476. setScalar( scalar ) {
  477. this.x = scalar;
  478. this.y = scalar;
  479. return this;
  480. }
  481. setX( x ) {
  482. this.x = x;
  483. return this;
  484. }
  485. setY( y ) {
  486. this.y = y;
  487. return this;
  488. }
  489. setComponent( index, value ) {
  490. switch ( index ) {
  491. case 0: this.x = value; break;
  492. case 1: this.y = value; break;
  493. default: throw new Error( 'index is out of range: ' + index );
  494. }
  495. return this;
  496. }
  497. getComponent( index ) {
  498. switch ( index ) {
  499. case 0: return this.x;
  500. case 1: return this.y;
  501. default: throw new Error( 'index is out of range: ' + index );
  502. }
  503. }
  504. clone() {
  505. return new this.constructor( this.x, this.y );
  506. }
  507. copy( v ) {
  508. this.x = v.x;
  509. this.y = v.y;
  510. return this;
  511. }
  512. add( v ) {
  513. this.x += v.x;
  514. this.y += v.y;
  515. return this;
  516. }
  517. addScalar( s ) {
  518. this.x += s;
  519. this.y += s;
  520. return this;
  521. }
  522. addVectors( a, b ) {
  523. this.x = a.x + b.x;
  524. this.y = a.y + b.y;
  525. return this;
  526. }
  527. addScaledVector( v, s ) {
  528. this.x += v.x * s;
  529. this.y += v.y * s;
  530. return this;
  531. }
  532. sub( v ) {
  533. this.x -= v.x;
  534. this.y -= v.y;
  535. return this;
  536. }
  537. subScalar( s ) {
  538. this.x -= s;
  539. this.y -= s;
  540. return this;
  541. }
  542. subVectors( a, b ) {
  543. this.x = a.x - b.x;
  544. this.y = a.y - b.y;
  545. return this;
  546. }
  547. multiply( v ) {
  548. this.x *= v.x;
  549. this.y *= v.y;
  550. return this;
  551. }
  552. multiplyScalar( scalar ) {
  553. this.x *= scalar;
  554. this.y *= scalar;
  555. return this;
  556. }
  557. divide( v ) {
  558. this.x /= v.x;
  559. this.y /= v.y;
  560. return this;
  561. }
  562. divideScalar( scalar ) {
  563. return this.multiplyScalar( 1 / scalar );
  564. }
  565. applyMatrix3( m ) {
  566. const x = this.x, y = this.y;
  567. const e = m.elements;
  568. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ];
  569. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ];
  570. return this;
  571. }
  572. min( v ) {
  573. this.x = Math.min( this.x, v.x );
  574. this.y = Math.min( this.y, v.y );
  575. return this;
  576. }
  577. max( v ) {
  578. this.x = Math.max( this.x, v.x );
  579. this.y = Math.max( this.y, v.y );
  580. return this;
  581. }
  582. clamp( min, max ) {
  583. // assumes min < max, componentwise
  584. this.x = clamp( this.x, min.x, max.x );
  585. this.y = clamp( this.y, min.y, max.y );
  586. return this;
  587. }
  588. clampScalar( minVal, maxVal ) {
  589. this.x = clamp( this.x, minVal, maxVal );
  590. this.y = clamp( this.y, minVal, maxVal );
  591. return this;
  592. }
  593. clampLength( min, max ) {
  594. const length = this.length();
  595. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  596. }
  597. floor() {
  598. this.x = Math.floor( this.x );
  599. this.y = Math.floor( this.y );
  600. return this;
  601. }
  602. ceil() {
  603. this.x = Math.ceil( this.x );
  604. this.y = Math.ceil( this.y );
  605. return this;
  606. }
  607. round() {
  608. this.x = Math.round( this.x );
  609. this.y = Math.round( this.y );
  610. return this;
  611. }
  612. roundToZero() {
  613. this.x = Math.trunc( this.x );
  614. this.y = Math.trunc( this.y );
  615. return this;
  616. }
  617. negate() {
  618. this.x = - this.x;
  619. this.y = - this.y;
  620. return this;
  621. }
  622. dot( v ) {
  623. return this.x * v.x + this.y * v.y;
  624. }
  625. cross( v ) {
  626. return this.x * v.y - this.y * v.x;
  627. }
  628. lengthSq() {
  629. return this.x * this.x + this.y * this.y;
  630. }
  631. length() {
  632. return Math.sqrt( this.x * this.x + this.y * this.y );
  633. }
  634. manhattanLength() {
  635. return Math.abs( this.x ) + Math.abs( this.y );
  636. }
  637. normalize() {
  638. return this.divideScalar( this.length() || 1 );
  639. }
  640. angle() {
  641. // computes the angle in radians with respect to the positive x-axis
  642. const angle = Math.atan2( - this.y, - this.x ) + Math.PI;
  643. return angle;
  644. }
  645. angleTo( v ) {
  646. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  647. if ( denominator === 0 ) return Math.PI / 2;
  648. const theta = this.dot( v ) / denominator;
  649. // clamp, to handle numerical problems
  650. return Math.acos( clamp( theta, - 1, 1 ) );
  651. }
  652. distanceTo( v ) {
  653. return Math.sqrt( this.distanceToSquared( v ) );
  654. }
  655. distanceToSquared( v ) {
  656. const dx = this.x - v.x, dy = this.y - v.y;
  657. return dx * dx + dy * dy;
  658. }
  659. manhattanDistanceTo( v ) {
  660. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y );
  661. }
  662. setLength( length ) {
  663. return this.normalize().multiplyScalar( length );
  664. }
  665. lerp( v, alpha ) {
  666. this.x += ( v.x - this.x ) * alpha;
  667. this.y += ( v.y - this.y ) * alpha;
  668. return this;
  669. }
  670. lerpVectors( v1, v2, alpha ) {
  671. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  672. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  673. return this;
  674. }
  675. equals( v ) {
  676. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  677. }
  678. fromArray( array, offset = 0 ) {
  679. this.x = array[ offset ];
  680. this.y = array[ offset + 1 ];
  681. return this;
  682. }
  683. toArray( array = [], offset = 0 ) {
  684. array[ offset ] = this.x;
  685. array[ offset + 1 ] = this.y;
  686. return array;
  687. }
  688. fromBufferAttribute( attribute, index ) {
  689. this.x = attribute.getX( index );
  690. this.y = attribute.getY( index );
  691. return this;
  692. }
  693. rotateAround( center, angle ) {
  694. const c = Math.cos( angle ), s = Math.sin( angle );
  695. const x = this.x - center.x;
  696. const y = this.y - center.y;
  697. this.x = x * c - y * s + center.x;
  698. this.y = x * s + y * c + center.y;
  699. return this;
  700. }
  701. random() {
  702. this.x = Math.random();
  703. this.y = Math.random();
  704. return this;
  705. }
  706. *[ Symbol.iterator ]() {
  707. yield this.x;
  708. yield this.y;
  709. }
  710. }
  711. class Matrix3 {
  712. constructor( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  713. Matrix3.prototype.isMatrix3 = true;
  714. this.elements = [
  715. 1, 0, 0,
  716. 0, 1, 0,
  717. 0, 0, 1
  718. ];
  719. if ( n11 !== undefined ) {
  720. this.set( n11, n12, n13, n21, n22, n23, n31, n32, n33 );
  721. }
  722. }
  723. set( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  724. const te = this.elements;
  725. te[ 0 ] = n11; te[ 1 ] = n21; te[ 2 ] = n31;
  726. te[ 3 ] = n12; te[ 4 ] = n22; te[ 5 ] = n32;
  727. te[ 6 ] = n13; te[ 7 ] = n23; te[ 8 ] = n33;
  728. return this;
  729. }
  730. identity() {
  731. this.set(
  732. 1, 0, 0,
  733. 0, 1, 0,
  734. 0, 0, 1
  735. );
  736. return this;
  737. }
  738. copy( m ) {
  739. const te = this.elements;
  740. const me = m.elements;
  741. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ];
  742. te[ 3 ] = me[ 3 ]; te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ];
  743. te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ]; te[ 8 ] = me[ 8 ];
  744. return this;
  745. }
  746. extractBasis( xAxis, yAxis, zAxis ) {
  747. xAxis.setFromMatrix3Column( this, 0 );
  748. yAxis.setFromMatrix3Column( this, 1 );
  749. zAxis.setFromMatrix3Column( this, 2 );
  750. return this;
  751. }
  752. setFromMatrix4( m ) {
  753. const me = m.elements;
  754. this.set(
  755. me[ 0 ], me[ 4 ], me[ 8 ],
  756. me[ 1 ], me[ 5 ], me[ 9 ],
  757. me[ 2 ], me[ 6 ], me[ 10 ]
  758. );
  759. return this;
  760. }
  761. multiply( m ) {
  762. return this.multiplyMatrices( this, m );
  763. }
  764. premultiply( m ) {
  765. return this.multiplyMatrices( m, this );
  766. }
  767. multiplyMatrices( a, b ) {
  768. const ae = a.elements;
  769. const be = b.elements;
  770. const te = this.elements;
  771. const a11 = ae[ 0 ], a12 = ae[ 3 ], a13 = ae[ 6 ];
  772. const a21 = ae[ 1 ], a22 = ae[ 4 ], a23 = ae[ 7 ];
  773. const a31 = ae[ 2 ], a32 = ae[ 5 ], a33 = ae[ 8 ];
  774. const b11 = be[ 0 ], b12 = be[ 3 ], b13 = be[ 6 ];
  775. const b21 = be[ 1 ], b22 = be[ 4 ], b23 = be[ 7 ];
  776. const b31 = be[ 2 ], b32 = be[ 5 ], b33 = be[ 8 ];
  777. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31;
  778. te[ 3 ] = a11 * b12 + a12 * b22 + a13 * b32;
  779. te[ 6 ] = a11 * b13 + a12 * b23 + a13 * b33;
  780. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31;
  781. te[ 4 ] = a21 * b12 + a22 * b22 + a23 * b32;
  782. te[ 7 ] = a21 * b13 + a22 * b23 + a23 * b33;
  783. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31;
  784. te[ 5 ] = a31 * b12 + a32 * b22 + a33 * b32;
  785. te[ 8 ] = a31 * b13 + a32 * b23 + a33 * b33;
  786. return this;
  787. }
  788. multiplyScalar( s ) {
  789. const te = this.elements;
  790. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  791. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  792. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  793. return this;
  794. }
  795. determinant() {
  796. const te = this.elements;
  797. const a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  798. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  799. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  800. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  801. }
  802. invert() {
  803. const te = this.elements,
  804. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ],
  805. n12 = te[ 3 ], n22 = te[ 4 ], n32 = te[ 5 ],
  806. n13 = te[ 6 ], n23 = te[ 7 ], n33 = te[ 8 ],
  807. t11 = n33 * n22 - n32 * n23,
  808. t12 = n32 * n13 - n33 * n12,
  809. t13 = n23 * n12 - n22 * n13,
  810. det = n11 * t11 + n21 * t12 + n31 * t13;
  811. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  812. const detInv = 1 / det;
  813. te[ 0 ] = t11 * detInv;
  814. te[ 1 ] = ( n31 * n23 - n33 * n21 ) * detInv;
  815. te[ 2 ] = ( n32 * n21 - n31 * n22 ) * detInv;
  816. te[ 3 ] = t12 * detInv;
  817. te[ 4 ] = ( n33 * n11 - n31 * n13 ) * detInv;
  818. te[ 5 ] = ( n31 * n12 - n32 * n11 ) * detInv;
  819. te[ 6 ] = t13 * detInv;
  820. te[ 7 ] = ( n21 * n13 - n23 * n11 ) * detInv;
  821. te[ 8 ] = ( n22 * n11 - n21 * n12 ) * detInv;
  822. return this;
  823. }
  824. transpose() {
  825. let tmp;
  826. const m = this.elements;
  827. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  828. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  829. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  830. return this;
  831. }
  832. getNormalMatrix( matrix4 ) {
  833. return this.setFromMatrix4( matrix4 ).invert().transpose();
  834. }
  835. transposeIntoArray( r ) {
  836. const m = this.elements;
  837. r[ 0 ] = m[ 0 ];
  838. r[ 1 ] = m[ 3 ];
  839. r[ 2 ] = m[ 6 ];
  840. r[ 3 ] = m[ 1 ];
  841. r[ 4 ] = m[ 4 ];
  842. r[ 5 ] = m[ 7 ];
  843. r[ 6 ] = m[ 2 ];
  844. r[ 7 ] = m[ 5 ];
  845. r[ 8 ] = m[ 8 ];
  846. return this;
  847. }
  848. setUvTransform( tx, ty, sx, sy, rotation, cx, cy ) {
  849. const c = Math.cos( rotation );
  850. const s = Math.sin( rotation );
  851. this.set(
  852. sx * c, sx * s, - sx * ( c * cx + s * cy ) + cx + tx,
  853. - sy * s, sy * c, - sy * ( - s * cx + c * cy ) + cy + ty,
  854. 0, 0, 1
  855. );
  856. return this;
  857. }
  858. //
  859. scale( sx, sy ) {
  860. this.premultiply( _m3.makeScale( sx, sy ) );
  861. return this;
  862. }
  863. rotate( theta ) {
  864. this.premultiply( _m3.makeRotation( - theta ) );
  865. return this;
  866. }
  867. translate( tx, ty ) {
  868. this.premultiply( _m3.makeTranslation( tx, ty ) );
  869. return this;
  870. }
  871. // for 2D Transforms
  872. makeTranslation( x, y ) {
  873. if ( x.isVector2 ) {
  874. this.set(
  875. 1, 0, x.x,
  876. 0, 1, x.y,
  877. 0, 0, 1
  878. );
  879. } else {
  880. this.set(
  881. 1, 0, x,
  882. 0, 1, y,
  883. 0, 0, 1
  884. );
  885. }
  886. return this;
  887. }
  888. makeRotation( theta ) {
  889. // counterclockwise
  890. const c = Math.cos( theta );
  891. const s = Math.sin( theta );
  892. this.set(
  893. c, - s, 0,
  894. s, c, 0,
  895. 0, 0, 1
  896. );
  897. return this;
  898. }
  899. makeScale( x, y ) {
  900. this.set(
  901. x, 0, 0,
  902. 0, y, 0,
  903. 0, 0, 1
  904. );
  905. return this;
  906. }
  907. //
  908. equals( matrix ) {
  909. const te = this.elements;
  910. const me = matrix.elements;
  911. for ( let i = 0; i < 9; i ++ ) {
  912. if ( te[ i ] !== me[ i ] ) return false;
  913. }
  914. return true;
  915. }
  916. fromArray( array, offset = 0 ) {
  917. for ( let i = 0; i < 9; i ++ ) {
  918. this.elements[ i ] = array[ i + offset ];
  919. }
  920. return this;
  921. }
  922. toArray( array = [], offset = 0 ) {
  923. const te = this.elements;
  924. array[ offset ] = te[ 0 ];
  925. array[ offset + 1 ] = te[ 1 ];
  926. array[ offset + 2 ] = te[ 2 ];
  927. array[ offset + 3 ] = te[ 3 ];
  928. array[ offset + 4 ] = te[ 4 ];
  929. array[ offset + 5 ] = te[ 5 ];
  930. array[ offset + 6 ] = te[ 6 ];
  931. array[ offset + 7 ] = te[ 7 ];
  932. array[ offset + 8 ] = te[ 8 ];
  933. return array;
  934. }
  935. clone() {
  936. return new this.constructor().fromArray( this.elements );
  937. }
  938. }
  939. const _m3 = /*@__PURE__*/ new Matrix3();
  940. function arrayNeedsUint32( array ) {
  941. // assumes larger values usually on last
  942. for ( let i = array.length - 1; i >= 0; -- i ) {
  943. if ( array[ i ] >= 65535 ) return true; // account for PRIMITIVE_RESTART_FIXED_INDEX, #24565
  944. }
  945. return false;
  946. }
  947. const TYPED_ARRAYS = {
  948. Int8Array: Int8Array,
  949. Uint8Array: Uint8Array,
  950. Uint8ClampedArray: Uint8ClampedArray,
  951. Int16Array: Int16Array,
  952. Uint16Array: Uint16Array,
  953. Int32Array: Int32Array,
  954. Uint32Array: Uint32Array,
  955. Float32Array: Float32Array,
  956. Float64Array: Float64Array
  957. };
  958. function getTypedArray( type, buffer ) {
  959. return new TYPED_ARRAYS[ type ]( buffer );
  960. }
  961. function createElementNS( name ) {
  962. return document.createElementNS( 'http://www.w3.org/1999/xhtml', name );
  963. }
  964. function createCanvasElement() {
  965. const canvas = createElementNS( 'canvas' );
  966. canvas.style.display = 'block';
  967. return canvas;
  968. }
  969. const _cache = {};
  970. function warnOnce( message ) {
  971. if ( message in _cache ) return;
  972. _cache[ message ] = true;
  973. console.warn( message );
  974. }
  975. function probeAsync( gl, sync, interval ) {
  976. return new Promise( function ( resolve, reject ) {
  977. function probe() {
  978. switch ( gl.clientWaitSync( sync, gl.SYNC_FLUSH_COMMANDS_BIT, 0 ) ) {
  979. case gl.WAIT_FAILED:
  980. reject();
  981. break;
  982. case gl.TIMEOUT_EXPIRED:
  983. setTimeout( probe, interval );
  984. break;
  985. default:
  986. resolve();
  987. }
  988. }
  989. setTimeout( probe, interval );
  990. } );
  991. }
  992. function toNormalizedProjectionMatrix( projectionMatrix ) {
  993. const m = projectionMatrix.elements;
  994. // Convert [-1, 1] to [0, 1] projection matrix
  995. m[ 2 ] = 0.5 * m[ 2 ] + 0.5 * m[ 3 ];
  996. m[ 6 ] = 0.5 * m[ 6 ] + 0.5 * m[ 7 ];
  997. m[ 10 ] = 0.5 * m[ 10 ] + 0.5 * m[ 11 ];
  998. m[ 14 ] = 0.5 * m[ 14 ] + 0.5 * m[ 15 ];
  999. }
  1000. function toReversedProjectionMatrix( projectionMatrix ) {
  1001. const m = projectionMatrix.elements;
  1002. const isPerspectiveMatrix = m[ 11 ] === - 1;
  1003. // Reverse [0, 1] projection matrix
  1004. if ( isPerspectiveMatrix ) {
  1005. m[ 10 ] = - m[ 10 ] - 1;
  1006. m[ 14 ] = - m[ 14 ];
  1007. } else {
  1008. m[ 10 ] = - m[ 10 ];
  1009. m[ 14 ] = - m[ 14 ] + 1;
  1010. }
  1011. }
  1012. const LINEAR_REC709_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
  1013. 0.4123908, 0.3575843, 0.1804808,
  1014. 0.2126390, 0.7151687, 0.0721923,
  1015. 0.0193308, 0.1191948, 0.9505322
  1016. );
  1017. const XYZ_TO_LINEAR_REC709 = /*@__PURE__*/ new Matrix3().set(
  1018. 3.2409699, - 1.5373832, - 0.4986108,
  1019. - 0.9692436, 1.8759675, 0.0415551,
  1020. 0.0556301, - 0.2039770, 1.0569715
  1021. );
  1022. function createColorManagement() {
  1023. const ColorManagement = {
  1024. enabled: true,
  1025. workingColorSpace: LinearSRGBColorSpace,
  1026. /**
  1027. * Implementations of supported color spaces.
  1028. *
  1029. * Required:
  1030. * - primaries: chromaticity coordinates [ rx ry gx gy bx by ]
  1031. * - whitePoint: reference white [ x y ]
  1032. * - transfer: transfer function (pre-defined)
  1033. * - toXYZ: Matrix3 RGB to XYZ transform
  1034. * - fromXYZ: Matrix3 XYZ to RGB transform
  1035. * - luminanceCoefficients: RGB luminance coefficients
  1036. *
  1037. * Optional:
  1038. * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
  1039. * - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
  1040. *
  1041. * Reference:
  1042. * - https://www.russellcottrell.com/photo/matrixCalculator.htm
  1043. */
  1044. spaces: {},
  1045. convert: function ( color, sourceColorSpace, targetColorSpace ) {
  1046. if ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) {
  1047. return color;
  1048. }
  1049. if ( this.spaces[ sourceColorSpace ].transfer === SRGBTransfer ) {
  1050. color.r = SRGBToLinear( color.r );
  1051. color.g = SRGBToLinear( color.g );
  1052. color.b = SRGBToLinear( color.b );
  1053. }
  1054. if ( this.spaces[ sourceColorSpace ].primaries !== this.spaces[ targetColorSpace ].primaries ) {
  1055. color.applyMatrix3( this.spaces[ sourceColorSpace ].toXYZ );
  1056. color.applyMatrix3( this.spaces[ targetColorSpace ].fromXYZ );
  1057. }
  1058. if ( this.spaces[ targetColorSpace ].transfer === SRGBTransfer ) {
  1059. color.r = LinearToSRGB( color.r );
  1060. color.g = LinearToSRGB( color.g );
  1061. color.b = LinearToSRGB( color.b );
  1062. }
  1063. return color;
  1064. },
  1065. fromWorkingColorSpace: function ( color, targetColorSpace ) {
  1066. return this.convert( color, this.workingColorSpace, targetColorSpace );
  1067. },
  1068. toWorkingColorSpace: function ( color, sourceColorSpace ) {
  1069. return this.convert( color, sourceColorSpace, this.workingColorSpace );
  1070. },
  1071. getPrimaries: function ( colorSpace ) {
  1072. return this.spaces[ colorSpace ].primaries;
  1073. },
  1074. getTransfer: function ( colorSpace ) {
  1075. if ( colorSpace === NoColorSpace ) return LinearTransfer;
  1076. return this.spaces[ colorSpace ].transfer;
  1077. },
  1078. getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) {
  1079. return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients );
  1080. },
  1081. define: function ( colorSpaces ) {
  1082. Object.assign( this.spaces, colorSpaces );
  1083. },
  1084. // Internal APIs
  1085. _getMatrix: function ( targetMatrix, sourceColorSpace, targetColorSpace ) {
  1086. return targetMatrix
  1087. .copy( this.spaces[ sourceColorSpace ].toXYZ )
  1088. .multiply( this.spaces[ targetColorSpace ].fromXYZ );
  1089. },
  1090. _getDrawingBufferColorSpace: function ( colorSpace ) {
  1091. return this.spaces[ colorSpace ].outputColorSpaceConfig.drawingBufferColorSpace;
  1092. },
  1093. _getUnpackColorSpace: function ( colorSpace = this.workingColorSpace ) {
  1094. return this.spaces[ colorSpace ].workingColorSpaceConfig.unpackColorSpace;
  1095. }
  1096. };
  1097. /******************************************************************************
  1098. * sRGB definitions
  1099. */
  1100. const REC709_PRIMARIES = [ 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 ];
  1101. const REC709_LUMINANCE_COEFFICIENTS = [ 0.2126, 0.7152, 0.0722 ];
  1102. const D65 = [ 0.3127, 0.3290 ];
  1103. ColorManagement.define( {
  1104. [ LinearSRGBColorSpace ]: {
  1105. primaries: REC709_PRIMARIES,
  1106. whitePoint: D65,
  1107. transfer: LinearTransfer,
  1108. toXYZ: LINEAR_REC709_TO_XYZ,
  1109. fromXYZ: XYZ_TO_LINEAR_REC709,
  1110. luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
  1111. workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace },
  1112. outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
  1113. },
  1114. [ SRGBColorSpace ]: {
  1115. primaries: REC709_PRIMARIES,
  1116. whitePoint: D65,
  1117. transfer: SRGBTransfer,
  1118. toXYZ: LINEAR_REC709_TO_XYZ,
  1119. fromXYZ: XYZ_TO_LINEAR_REC709,
  1120. luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
  1121. outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
  1122. },
  1123. } );
  1124. return ColorManagement;
  1125. }
  1126. const ColorManagement = /*@__PURE__*/ createColorManagement();
  1127. function SRGBToLinear( c ) {
  1128. return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
  1129. }
  1130. function LinearToSRGB( c ) {
  1131. return ( c < 0.0031308 ) ? c * 12.92 : 1.055 * ( Math.pow( c, 0.41666 ) ) - 0.055;
  1132. }
  1133. let _canvas;
  1134. class ImageUtils {
  1135. static getDataURL( image ) {
  1136. if ( /^data:/i.test( image.src ) ) {
  1137. return image.src;
  1138. }
  1139. if ( typeof HTMLCanvasElement === 'undefined' ) {
  1140. return image.src;
  1141. }
  1142. let canvas;
  1143. if ( image instanceof HTMLCanvasElement ) {
  1144. canvas = image;
  1145. } else {
  1146. if ( _canvas === undefined ) _canvas = createElementNS( 'canvas' );
  1147. _canvas.width = image.width;
  1148. _canvas.height = image.height;
  1149. const context = _canvas.getContext( '2d' );
  1150. if ( image instanceof ImageData ) {
  1151. context.putImageData( image, 0, 0 );
  1152. } else {
  1153. context.drawImage( image, 0, 0, image.width, image.height );
  1154. }
  1155. canvas = _canvas;
  1156. }
  1157. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  1158. console.warn( 'THREE.ImageUtils.getDataURL: Image converted to jpg for performance reasons', image );
  1159. return canvas.toDataURL( 'image/jpeg', 0.6 );
  1160. } else {
  1161. return canvas.toDataURL( 'image/png' );
  1162. }
  1163. }
  1164. static sRGBToLinear( image ) {
  1165. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1166. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1167. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1168. const canvas = createElementNS( 'canvas' );
  1169. canvas.width = image.width;
  1170. canvas.height = image.height;
  1171. const context = canvas.getContext( '2d' );
  1172. context.drawImage( image, 0, 0, image.width, image.height );
  1173. const imageData = context.getImageData( 0, 0, image.width, image.height );
  1174. const data = imageData.data;
  1175. for ( let i = 0; i < data.length; i ++ ) {
  1176. data[ i ] = SRGBToLinear( data[ i ] / 255 ) * 255;
  1177. }
  1178. context.putImageData( imageData, 0, 0 );
  1179. return canvas;
  1180. } else if ( image.data ) {
  1181. const data = image.data.slice( 0 );
  1182. for ( let i = 0; i < data.length; i ++ ) {
  1183. if ( data instanceof Uint8Array || data instanceof Uint8ClampedArray ) {
  1184. data[ i ] = Math.floor( SRGBToLinear( data[ i ] / 255 ) * 255 );
  1185. } else {
  1186. // assuming float
  1187. data[ i ] = SRGBToLinear( data[ i ] );
  1188. }
  1189. }
  1190. return {
  1191. data: data,
  1192. width: image.width,
  1193. height: image.height
  1194. };
  1195. } else {
  1196. console.warn( 'THREE.ImageUtils.sRGBToLinear(): Unsupported image type. No color space conversion applied.' );
  1197. return image;
  1198. }
  1199. }
  1200. }
  1201. let _sourceId = 0;
  1202. class Source {
  1203. constructor( data = null ) {
  1204. this.isSource = true;
  1205. Object.defineProperty( this, 'id', { value: _sourceId ++ } );
  1206. this.uuid = generateUUID();
  1207. this.data = data;
  1208. this.dataReady = true;
  1209. this.version = 0;
  1210. }
  1211. set needsUpdate( value ) {
  1212. if ( value === true ) this.version ++;
  1213. }
  1214. toJSON( meta ) {
  1215. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1216. if ( ! isRootObject && meta.images[ this.uuid ] !== undefined ) {
  1217. return meta.images[ this.uuid ];
  1218. }
  1219. const output = {
  1220. uuid: this.uuid,
  1221. url: ''
  1222. };
  1223. const data = this.data;
  1224. if ( data !== null ) {
  1225. let url;
  1226. if ( Array.isArray( data ) ) {
  1227. // cube texture
  1228. url = [];
  1229. for ( let i = 0, l = data.length; i < l; i ++ ) {
  1230. if ( data[ i ].isDataTexture ) {
  1231. url.push( serializeImage( data[ i ].image ) );
  1232. } else {
  1233. url.push( serializeImage( data[ i ] ) );
  1234. }
  1235. }
  1236. } else {
  1237. // texture
  1238. url = serializeImage( data );
  1239. }
  1240. output.url = url;
  1241. }
  1242. if ( ! isRootObject ) {
  1243. meta.images[ this.uuid ] = output;
  1244. }
  1245. return output;
  1246. }
  1247. }
  1248. function serializeImage( image ) {
  1249. if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
  1250. ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
  1251. ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
  1252. // default images
  1253. return ImageUtils.getDataURL( image );
  1254. } else {
  1255. if ( image.data ) {
  1256. // images of DataTexture
  1257. return {
  1258. data: Array.from( image.data ),
  1259. width: image.width,
  1260. height: image.height,
  1261. type: image.data.constructor.name
  1262. };
  1263. } else {
  1264. console.warn( 'THREE.Texture: Unable to serialize Texture.' );
  1265. return {};
  1266. }
  1267. }
  1268. }
  1269. let _textureId = 0;
  1270. class Texture extends EventDispatcher {
  1271. 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 ) {
  1272. super();
  1273. this.isTexture = true;
  1274. Object.defineProperty( this, 'id', { value: _textureId ++ } );
  1275. this.uuid = generateUUID();
  1276. this.name = '';
  1277. this.source = new Source( image );
  1278. this.mipmaps = [];
  1279. this.mapping = mapping;
  1280. this.channel = 0;
  1281. this.wrapS = wrapS;
  1282. this.wrapT = wrapT;
  1283. this.magFilter = magFilter;
  1284. this.minFilter = minFilter;
  1285. this.anisotropy = anisotropy;
  1286. this.format = format;
  1287. this.internalFormat = null;
  1288. this.type = type;
  1289. this.offset = new Vector2( 0, 0 );
  1290. this.repeat = new Vector2( 1, 1 );
  1291. this.center = new Vector2( 0, 0 );
  1292. this.rotation = 0;
  1293. this.matrixAutoUpdate = true;
  1294. this.matrix = new Matrix3();
  1295. this.generateMipmaps = true;
  1296. this.premultiplyAlpha = false;
  1297. this.flipY = true;
  1298. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  1299. this.colorSpace = colorSpace;
  1300. this.userData = {};
  1301. this.version = 0;
  1302. this.onUpdate = null;
  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.userData = JSON.parse( JSON.stringify( source.userData ) );
  1344. this.needsUpdate = true;
  1345. return this;
  1346. }
  1347. toJSON( meta ) {
  1348. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1349. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1350. return meta.textures[ this.uuid ];
  1351. }
  1352. const output = {
  1353. metadata: {
  1354. version: 4.6,
  1355. type: 'Texture',
  1356. generator: 'Texture.toJSON'
  1357. },
  1358. uuid: this.uuid,
  1359. name: this.name,
  1360. image: this.source.toJSON( meta ).uuid,
  1361. mapping: this.mapping,
  1362. channel: this.channel,
  1363. repeat: [ this.repeat.x, this.repeat.y ],
  1364. offset: [ this.offset.x, this.offset.y ],
  1365. center: [ this.center.x, this.center.y ],
  1366. rotation: this.rotation,
  1367. wrap: [ this.wrapS, this.wrapT ],
  1368. format: this.format,
  1369. internalFormat: this.internalFormat,
  1370. type: this.type,
  1371. colorSpace: this.colorSpace,
  1372. minFilter: this.minFilter,
  1373. magFilter: this.magFilter,
  1374. anisotropy: this.anisotropy,
  1375. flipY: this.flipY,
  1376. generateMipmaps: this.generateMipmaps,
  1377. premultiplyAlpha: this.premultiplyAlpha,
  1378. unpackAlignment: this.unpackAlignment
  1379. };
  1380. if ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData;
  1381. if ( ! isRootObject ) {
  1382. meta.textures[ this.uuid ] = output;
  1383. }
  1384. return output;
  1385. }
  1386. dispose() {
  1387. this.dispatchEvent( { type: 'dispose' } );
  1388. }
  1389. transformUv( uv ) {
  1390. if ( this.mapping !== UVMapping ) return uv;
  1391. uv.applyMatrix3( this.matrix );
  1392. if ( uv.x < 0 || uv.x > 1 ) {
  1393. switch ( this.wrapS ) {
  1394. case RepeatWrapping:
  1395. uv.x = uv.x - Math.floor( uv.x );
  1396. break;
  1397. case ClampToEdgeWrapping:
  1398. uv.x = uv.x < 0 ? 0 : 1;
  1399. break;
  1400. case MirroredRepeatWrapping:
  1401. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1402. uv.x = Math.ceil( uv.x ) - uv.x;
  1403. } else {
  1404. uv.x = uv.x - Math.floor( uv.x );
  1405. }
  1406. break;
  1407. }
  1408. }
  1409. if ( uv.y < 0 || uv.y > 1 ) {
  1410. switch ( this.wrapT ) {
  1411. case RepeatWrapping:
  1412. uv.y = uv.y - Math.floor( uv.y );
  1413. break;
  1414. case ClampToEdgeWrapping:
  1415. uv.y = uv.y < 0 ? 0 : 1;
  1416. break;
  1417. case MirroredRepeatWrapping:
  1418. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1419. uv.y = Math.ceil( uv.y ) - uv.y;
  1420. } else {
  1421. uv.y = uv.y - Math.floor( uv.y );
  1422. }
  1423. break;
  1424. }
  1425. }
  1426. if ( this.flipY ) {
  1427. uv.y = 1 - uv.y;
  1428. }
  1429. return uv;
  1430. }
  1431. set needsUpdate( value ) {
  1432. if ( value === true ) {
  1433. this.version ++;
  1434. this.source.needsUpdate = true;
  1435. }
  1436. }
  1437. set needsPMREMUpdate( value ) {
  1438. if ( value === true ) {
  1439. this.pmremVersion ++;
  1440. }
  1441. }
  1442. }
  1443. Texture.DEFAULT_IMAGE = null;
  1444. Texture.DEFAULT_MAPPING = UVMapping;
  1445. Texture.DEFAULT_ANISOTROPY = 1;
  1446. class Vector4 {
  1447. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1448. Vector4.prototype.isVector4 = true;
  1449. this.x = x;
  1450. this.y = y;
  1451. this.z = z;
  1452. this.w = w;
  1453. }
  1454. get width() {
  1455. return this.z;
  1456. }
  1457. set width( value ) {
  1458. this.z = value;
  1459. }
  1460. get height() {
  1461. return this.w;
  1462. }
  1463. set height( value ) {
  1464. this.w = value;
  1465. }
  1466. set( x, y, z, w ) {
  1467. this.x = x;
  1468. this.y = y;
  1469. this.z = z;
  1470. this.w = w;
  1471. return this;
  1472. }
  1473. setScalar( scalar ) {
  1474. this.x = scalar;
  1475. this.y = scalar;
  1476. this.z = scalar;
  1477. this.w = scalar;
  1478. return this;
  1479. }
  1480. setX( x ) {
  1481. this.x = x;
  1482. return this;
  1483. }
  1484. setY( y ) {
  1485. this.y = y;
  1486. return this;
  1487. }
  1488. setZ( z ) {
  1489. this.z = z;
  1490. return this;
  1491. }
  1492. setW( w ) {
  1493. this.w = w;
  1494. return this;
  1495. }
  1496. setComponent( index, value ) {
  1497. switch ( index ) {
  1498. case 0: this.x = value; break;
  1499. case 1: this.y = value; break;
  1500. case 2: this.z = value; break;
  1501. case 3: this.w = value; break;
  1502. default: throw new Error( 'index is out of range: ' + index );
  1503. }
  1504. return this;
  1505. }
  1506. getComponent( index ) {
  1507. switch ( index ) {
  1508. case 0: return this.x;
  1509. case 1: return this.y;
  1510. case 2: return this.z;
  1511. case 3: return this.w;
  1512. default: throw new Error( 'index is out of range: ' + index );
  1513. }
  1514. }
  1515. clone() {
  1516. return new this.constructor( this.x, this.y, this.z, this.w );
  1517. }
  1518. copy( v ) {
  1519. this.x = v.x;
  1520. this.y = v.y;
  1521. this.z = v.z;
  1522. this.w = ( v.w !== undefined ) ? v.w : 1;
  1523. return this;
  1524. }
  1525. add( v ) {
  1526. this.x += v.x;
  1527. this.y += v.y;
  1528. this.z += v.z;
  1529. this.w += v.w;
  1530. return this;
  1531. }
  1532. addScalar( s ) {
  1533. this.x += s;
  1534. this.y += s;
  1535. this.z += s;
  1536. this.w += s;
  1537. return this;
  1538. }
  1539. addVectors( a, b ) {
  1540. this.x = a.x + b.x;
  1541. this.y = a.y + b.y;
  1542. this.z = a.z + b.z;
  1543. this.w = a.w + b.w;
  1544. return this;
  1545. }
  1546. addScaledVector( v, s ) {
  1547. this.x += v.x * s;
  1548. this.y += v.y * s;
  1549. this.z += v.z * s;
  1550. this.w += v.w * s;
  1551. return this;
  1552. }
  1553. sub( v ) {
  1554. this.x -= v.x;
  1555. this.y -= v.y;
  1556. this.z -= v.z;
  1557. this.w -= v.w;
  1558. return this;
  1559. }
  1560. subScalar( s ) {
  1561. this.x -= s;
  1562. this.y -= s;
  1563. this.z -= s;
  1564. this.w -= s;
  1565. return this;
  1566. }
  1567. subVectors( a, b ) {
  1568. this.x = a.x - b.x;
  1569. this.y = a.y - b.y;
  1570. this.z = a.z - b.z;
  1571. this.w = a.w - b.w;
  1572. return this;
  1573. }
  1574. multiply( v ) {
  1575. this.x *= v.x;
  1576. this.y *= v.y;
  1577. this.z *= v.z;
  1578. this.w *= v.w;
  1579. return this;
  1580. }
  1581. multiplyScalar( scalar ) {
  1582. this.x *= scalar;
  1583. this.y *= scalar;
  1584. this.z *= scalar;
  1585. this.w *= scalar;
  1586. return this;
  1587. }
  1588. applyMatrix4( m ) {
  1589. const x = this.x, y = this.y, z = this.z, w = this.w;
  1590. const e = m.elements;
  1591. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1592. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1593. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1594. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1595. return this;
  1596. }
  1597. divide( v ) {
  1598. this.x /= v.x;
  1599. this.y /= v.y;
  1600. this.z /= v.z;
  1601. this.w /= v.w;
  1602. return this;
  1603. }
  1604. divideScalar( scalar ) {
  1605. return this.multiplyScalar( 1 / scalar );
  1606. }
  1607. setAxisAngleFromQuaternion( q ) {
  1608. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1609. // q is assumed to be normalized
  1610. this.w = 2 * Math.acos( q.w );
  1611. const s = Math.sqrt( 1 - q.w * q.w );
  1612. if ( s < 0.0001 ) {
  1613. this.x = 1;
  1614. this.y = 0;
  1615. this.z = 0;
  1616. } else {
  1617. this.x = q.x / s;
  1618. this.y = q.y / s;
  1619. this.z = q.z / s;
  1620. }
  1621. return this;
  1622. }
  1623. setAxisAngleFromRotationMatrix( m ) {
  1624. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1625. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1626. let angle, x, y, z; // variables for result
  1627. const epsilon = 0.01, // margin to allow for rounding errors
  1628. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1629. te = m.elements,
  1630. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1631. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1632. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1633. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1634. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1635. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1636. // singularity found
  1637. // first check for identity matrix which must have +1 for all terms
  1638. // in leading diagonal and zero in other terms
  1639. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1640. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1641. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1642. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1643. // this singularity is identity matrix so angle = 0
  1644. this.set( 1, 0, 0, 0 );
  1645. return this; // zero angle, arbitrary axis
  1646. }
  1647. // otherwise this singularity is angle = 180
  1648. angle = Math.PI;
  1649. const xx = ( m11 + 1 ) / 2;
  1650. const yy = ( m22 + 1 ) / 2;
  1651. const zz = ( m33 + 1 ) / 2;
  1652. const xy = ( m12 + m21 ) / 4;
  1653. const xz = ( m13 + m31 ) / 4;
  1654. const yz = ( m23 + m32 ) / 4;
  1655. if ( ( xx > yy ) && ( xx > zz ) ) {
  1656. // m11 is the largest diagonal term
  1657. if ( xx < epsilon ) {
  1658. x = 0;
  1659. y = 0.707106781;
  1660. z = 0.707106781;
  1661. } else {
  1662. x = Math.sqrt( xx );
  1663. y = xy / x;
  1664. z = xz / x;
  1665. }
  1666. } else if ( yy > zz ) {
  1667. // m22 is the largest diagonal term
  1668. if ( yy < epsilon ) {
  1669. x = 0.707106781;
  1670. y = 0;
  1671. z = 0.707106781;
  1672. } else {
  1673. y = Math.sqrt( yy );
  1674. x = xy / y;
  1675. z = yz / y;
  1676. }
  1677. } else {
  1678. // m33 is the largest diagonal term so base result on this
  1679. if ( zz < epsilon ) {
  1680. x = 0.707106781;
  1681. y = 0.707106781;
  1682. z = 0;
  1683. } else {
  1684. z = Math.sqrt( zz );
  1685. x = xz / z;
  1686. y = yz / z;
  1687. }
  1688. }
  1689. this.set( x, y, z, angle );
  1690. return this; // return 180 deg rotation
  1691. }
  1692. // as we have reached here there are no singularities so we can handle normally
  1693. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1694. ( m13 - m31 ) * ( m13 - m31 ) +
  1695. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1696. if ( Math.abs( s ) < 0.001 ) s = 1;
  1697. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1698. // caught by singularity test above, but I've left it in just in case
  1699. this.x = ( m32 - m23 ) / s;
  1700. this.y = ( m13 - m31 ) / s;
  1701. this.z = ( m21 - m12 ) / s;
  1702. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1703. return this;
  1704. }
  1705. setFromMatrixPosition( m ) {
  1706. const e = m.elements;
  1707. this.x = e[ 12 ];
  1708. this.y = e[ 13 ];
  1709. this.z = e[ 14 ];
  1710. this.w = e[ 15 ];
  1711. return this;
  1712. }
  1713. min( v ) {
  1714. this.x = Math.min( this.x, v.x );
  1715. this.y = Math.min( this.y, v.y );
  1716. this.z = Math.min( this.z, v.z );
  1717. this.w = Math.min( this.w, v.w );
  1718. return this;
  1719. }
  1720. max( v ) {
  1721. this.x = Math.max( this.x, v.x );
  1722. this.y = Math.max( this.y, v.y );
  1723. this.z = Math.max( this.z, v.z );
  1724. this.w = Math.max( this.w, v.w );
  1725. return this;
  1726. }
  1727. clamp( min, max ) {
  1728. // assumes min < max, componentwise
  1729. this.x = clamp( this.x, min.x, max.x );
  1730. this.y = clamp( this.y, min.y, max.y );
  1731. this.z = clamp( this.z, min.z, max.z );
  1732. this.w = clamp( this.w, min.w, max.w );
  1733. return this;
  1734. }
  1735. clampScalar( minVal, maxVal ) {
  1736. this.x = clamp( this.x, minVal, maxVal );
  1737. this.y = clamp( this.y, minVal, maxVal );
  1738. this.z = clamp( this.z, minVal, maxVal );
  1739. this.w = clamp( this.w, minVal, maxVal );
  1740. return this;
  1741. }
  1742. clampLength( min, max ) {
  1743. const length = this.length();
  1744. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  1745. }
  1746. floor() {
  1747. this.x = Math.floor( this.x );
  1748. this.y = Math.floor( this.y );
  1749. this.z = Math.floor( this.z );
  1750. this.w = Math.floor( this.w );
  1751. return this;
  1752. }
  1753. ceil() {
  1754. this.x = Math.ceil( this.x );
  1755. this.y = Math.ceil( this.y );
  1756. this.z = Math.ceil( this.z );
  1757. this.w = Math.ceil( this.w );
  1758. return this;
  1759. }
  1760. round() {
  1761. this.x = Math.round( this.x );
  1762. this.y = Math.round( this.y );
  1763. this.z = Math.round( this.z );
  1764. this.w = Math.round( this.w );
  1765. return this;
  1766. }
  1767. roundToZero() {
  1768. this.x = Math.trunc( this.x );
  1769. this.y = Math.trunc( this.y );
  1770. this.z = Math.trunc( this.z );
  1771. this.w = Math.trunc( this.w );
  1772. return this;
  1773. }
  1774. negate() {
  1775. this.x = - this.x;
  1776. this.y = - this.y;
  1777. this.z = - this.z;
  1778. this.w = - this.w;
  1779. return this;
  1780. }
  1781. dot( v ) {
  1782. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1783. }
  1784. lengthSq() {
  1785. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1786. }
  1787. length() {
  1788. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1789. }
  1790. manhattanLength() {
  1791. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1792. }
  1793. normalize() {
  1794. return this.divideScalar( this.length() || 1 );
  1795. }
  1796. setLength( length ) {
  1797. return this.normalize().multiplyScalar( length );
  1798. }
  1799. lerp( v, alpha ) {
  1800. this.x += ( v.x - this.x ) * alpha;
  1801. this.y += ( v.y - this.y ) * alpha;
  1802. this.z += ( v.z - this.z ) * alpha;
  1803. this.w += ( v.w - this.w ) * alpha;
  1804. return this;
  1805. }
  1806. lerpVectors( v1, v2, alpha ) {
  1807. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1808. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1809. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1810. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1811. return this;
  1812. }
  1813. equals( v ) {
  1814. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1815. }
  1816. fromArray( array, offset = 0 ) {
  1817. this.x = array[ offset ];
  1818. this.y = array[ offset + 1 ];
  1819. this.z = array[ offset + 2 ];
  1820. this.w = array[ offset + 3 ];
  1821. return this;
  1822. }
  1823. toArray( array = [], offset = 0 ) {
  1824. array[ offset ] = this.x;
  1825. array[ offset + 1 ] = this.y;
  1826. array[ offset + 2 ] = this.z;
  1827. array[ offset + 3 ] = this.w;
  1828. return array;
  1829. }
  1830. fromBufferAttribute( attribute, index ) {
  1831. this.x = attribute.getX( index );
  1832. this.y = attribute.getY( index );
  1833. this.z = attribute.getZ( index );
  1834. this.w = attribute.getW( index );
  1835. return this;
  1836. }
  1837. random() {
  1838. this.x = Math.random();
  1839. this.y = Math.random();
  1840. this.z = Math.random();
  1841. this.w = Math.random();
  1842. return this;
  1843. }
  1844. *[ Symbol.iterator ]() {
  1845. yield this.x;
  1846. yield this.y;
  1847. yield this.z;
  1848. yield this.w;
  1849. }
  1850. }
  1851. /*
  1852. In options, we can specify:
  1853. * Texture parameters for an auto-generated target texture
  1854. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1855. */
  1856. class RenderTarget extends EventDispatcher {
  1857. constructor( width = 1, height = 1, options = {} ) {
  1858. super();
  1859. this.isRenderTarget = true;
  1860. this.width = width;
  1861. this.height = height;
  1862. this.depth = 1;
  1863. this.scissor = new Vector4( 0, 0, width, height );
  1864. this.scissorTest = false;
  1865. this.viewport = new Vector4( 0, 0, width, height );
  1866. const image = { width: width, height: height, depth: 1 };
  1867. options = Object.assign( {
  1868. generateMipmaps: false,
  1869. internalFormat: null,
  1870. minFilter: LinearFilter,
  1871. depthBuffer: true,
  1872. stencilBuffer: false,
  1873. resolveDepthBuffer: true,
  1874. resolveStencilBuffer: true,
  1875. depthTexture: null,
  1876. samples: 0,
  1877. count: 1
  1878. }, options );
  1879. const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  1880. texture.flipY = false;
  1881. texture.generateMipmaps = options.generateMipmaps;
  1882. texture.internalFormat = options.internalFormat;
  1883. this.textures = [];
  1884. const count = options.count;
  1885. for ( let i = 0; i < count; i ++ ) {
  1886. this.textures[ i ] = texture.clone();
  1887. this.textures[ i ].isRenderTargetTexture = true;
  1888. }
  1889. this.depthBuffer = options.depthBuffer;
  1890. this.stencilBuffer = options.stencilBuffer;
  1891. this.resolveDepthBuffer = options.resolveDepthBuffer;
  1892. this.resolveStencilBuffer = options.resolveStencilBuffer;
  1893. this.depthTexture = options.depthTexture;
  1894. this.samples = options.samples;
  1895. }
  1896. get texture() {
  1897. return this.textures[ 0 ];
  1898. }
  1899. set texture( value ) {
  1900. this.textures[ 0 ] = value;
  1901. }
  1902. setSize( width, height, depth = 1 ) {
  1903. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1904. this.width = width;
  1905. this.height = height;
  1906. this.depth = depth;
  1907. for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
  1908. this.textures[ i ].image.width = width;
  1909. this.textures[ i ].image.height = height;
  1910. this.textures[ i ].image.depth = depth;
  1911. }
  1912. this.dispose();
  1913. }
  1914. this.viewport.set( 0, 0, width, height );
  1915. this.scissor.set( 0, 0, width, height );
  1916. }
  1917. clone() {
  1918. return new this.constructor().copy( this );
  1919. }
  1920. copy( source ) {
  1921. this.width = source.width;
  1922. this.height = source.height;
  1923. this.depth = source.depth;
  1924. this.scissor.copy( source.scissor );
  1925. this.scissorTest = source.scissorTest;
  1926. this.viewport.copy( source.viewport );
  1927. this.textures.length = 0;
  1928. for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
  1929. this.textures[ i ] = source.textures[ i ].clone();
  1930. this.textures[ i ].isRenderTargetTexture = true;
  1931. }
  1932. // ensure image object is not shared, see #20328
  1933. const image = Object.assign( {}, source.texture.image );
  1934. this.texture.source = new Source( image );
  1935. this.depthBuffer = source.depthBuffer;
  1936. this.stencilBuffer = source.stencilBuffer;
  1937. this.resolveDepthBuffer = source.resolveDepthBuffer;
  1938. this.resolveStencilBuffer = source.resolveStencilBuffer;
  1939. if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
  1940. this.samples = source.samples;
  1941. return this;
  1942. }
  1943. dispose() {
  1944. this.dispatchEvent( { type: 'dispose' } );
  1945. }
  1946. }
  1947. class WebGLRenderTarget extends RenderTarget {
  1948. constructor( width = 1, height = 1, options = {} ) {
  1949. super( width, height, options );
  1950. this.isWebGLRenderTarget = true;
  1951. }
  1952. }
  1953. class DataArrayTexture extends Texture {
  1954. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1955. super( null );
  1956. this.isDataArrayTexture = true;
  1957. this.image = { data, width, height, depth };
  1958. this.magFilter = NearestFilter;
  1959. this.minFilter = NearestFilter;
  1960. this.wrapR = ClampToEdgeWrapping;
  1961. this.generateMipmaps = false;
  1962. this.flipY = false;
  1963. this.unpackAlignment = 1;
  1964. this.layerUpdates = new Set();
  1965. }
  1966. addLayerUpdate( layerIndex ) {
  1967. this.layerUpdates.add( layerIndex );
  1968. }
  1969. clearLayerUpdates() {
  1970. this.layerUpdates.clear();
  1971. }
  1972. }
  1973. class WebGLArrayRenderTarget extends WebGLRenderTarget {
  1974. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  1975. super( width, height, options );
  1976. this.isWebGLArrayRenderTarget = true;
  1977. this.depth = depth;
  1978. this.texture = new DataArrayTexture( null, width, height, depth );
  1979. this.texture.isRenderTargetTexture = true;
  1980. }
  1981. }
  1982. class Data3DTexture extends Texture {
  1983. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1984. // We're going to add .setXXX() methods for setting properties later.
  1985. // Users can still set in DataTexture3D directly.
  1986. //
  1987. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  1988. // texture.anisotropy = 16;
  1989. //
  1990. // See #14839
  1991. super( null );
  1992. this.isData3DTexture = true;
  1993. this.image = { data, width, height, depth };
  1994. this.magFilter = NearestFilter;
  1995. this.minFilter = NearestFilter;
  1996. this.wrapR = ClampToEdgeWrapping;
  1997. this.generateMipmaps = false;
  1998. this.flipY = false;
  1999. this.unpackAlignment = 1;
  2000. }
  2001. }
  2002. class WebGL3DRenderTarget extends WebGLRenderTarget {
  2003. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  2004. super( width, height, options );
  2005. this.isWebGL3DRenderTarget = true;
  2006. this.depth = depth;
  2007. this.texture = new Data3DTexture( null, width, height, depth );
  2008. this.texture.isRenderTargetTexture = true;
  2009. }
  2010. }
  2011. class Quaternion {
  2012. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  2013. this.isQuaternion = true;
  2014. this._x = x;
  2015. this._y = y;
  2016. this._z = z;
  2017. this._w = w;
  2018. }
  2019. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  2020. // fuzz-free, array-based Quaternion SLERP operation
  2021. let x0 = src0[ srcOffset0 + 0 ],
  2022. y0 = src0[ srcOffset0 + 1 ],
  2023. z0 = src0[ srcOffset0 + 2 ],
  2024. w0 = src0[ srcOffset0 + 3 ];
  2025. const x1 = src1[ srcOffset1 + 0 ],
  2026. y1 = src1[ srcOffset1 + 1 ],
  2027. z1 = src1[ srcOffset1 + 2 ],
  2028. w1 = src1[ srcOffset1 + 3 ];
  2029. if ( t === 0 ) {
  2030. dst[ dstOffset + 0 ] = x0;
  2031. dst[ dstOffset + 1 ] = y0;
  2032. dst[ dstOffset + 2 ] = z0;
  2033. dst[ dstOffset + 3 ] = w0;
  2034. return;
  2035. }
  2036. if ( t === 1 ) {
  2037. dst[ dstOffset + 0 ] = x1;
  2038. dst[ dstOffset + 1 ] = y1;
  2039. dst[ dstOffset + 2 ] = z1;
  2040. dst[ dstOffset + 3 ] = w1;
  2041. return;
  2042. }
  2043. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  2044. let s = 1 - t;
  2045. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2046. dir = ( cos >= 0 ? 1 : - 1 ),
  2047. sqrSin = 1 - cos * cos;
  2048. // Skip the Slerp for tiny steps to avoid numeric problems:
  2049. if ( sqrSin > Number.EPSILON ) {
  2050. const sin = Math.sqrt( sqrSin ),
  2051. len = Math.atan2( sin, cos * dir );
  2052. s = Math.sin( s * len ) / sin;
  2053. t = Math.sin( t * len ) / sin;
  2054. }
  2055. const tDir = t * dir;
  2056. x0 = x0 * s + x1 * tDir;
  2057. y0 = y0 * s + y1 * tDir;
  2058. z0 = z0 * s + z1 * tDir;
  2059. w0 = w0 * s + w1 * tDir;
  2060. // Normalize in case we just did a lerp:
  2061. if ( s === 1 - t ) {
  2062. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  2063. x0 *= f;
  2064. y0 *= f;
  2065. z0 *= f;
  2066. w0 *= f;
  2067. }
  2068. }
  2069. dst[ dstOffset ] = x0;
  2070. dst[ dstOffset + 1 ] = y0;
  2071. dst[ dstOffset + 2 ] = z0;
  2072. dst[ dstOffset + 3 ] = w0;
  2073. }
  2074. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  2075. const x0 = src0[ srcOffset0 ];
  2076. const y0 = src0[ srcOffset0 + 1 ];
  2077. const z0 = src0[ srcOffset0 + 2 ];
  2078. const w0 = src0[ srcOffset0 + 3 ];
  2079. const x1 = src1[ srcOffset1 ];
  2080. const y1 = src1[ srcOffset1 + 1 ];
  2081. const z1 = src1[ srcOffset1 + 2 ];
  2082. const w1 = src1[ srcOffset1 + 3 ];
  2083. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2084. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2085. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2086. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2087. return dst;
  2088. }
  2089. get x() {
  2090. return this._x;
  2091. }
  2092. set x( value ) {
  2093. this._x = value;
  2094. this._onChangeCallback();
  2095. }
  2096. get y() {
  2097. return this._y;
  2098. }
  2099. set y( value ) {
  2100. this._y = value;
  2101. this._onChangeCallback();
  2102. }
  2103. get z() {
  2104. return this._z;
  2105. }
  2106. set z( value ) {
  2107. this._z = value;
  2108. this._onChangeCallback();
  2109. }
  2110. get w() {
  2111. return this._w;
  2112. }
  2113. set w( value ) {
  2114. this._w = value;
  2115. this._onChangeCallback();
  2116. }
  2117. set( x, y, z, w ) {
  2118. this._x = x;
  2119. this._y = y;
  2120. this._z = z;
  2121. this._w = w;
  2122. this._onChangeCallback();
  2123. return this;
  2124. }
  2125. clone() {
  2126. return new this.constructor( this._x, this._y, this._z, this._w );
  2127. }
  2128. copy( quaternion ) {
  2129. this._x = quaternion.x;
  2130. this._y = quaternion.y;
  2131. this._z = quaternion.z;
  2132. this._w = quaternion.w;
  2133. this._onChangeCallback();
  2134. return this;
  2135. }
  2136. setFromEuler( euler, update = true ) {
  2137. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  2138. // http://www.mathworks.com/matlabcentral/fileexchange/
  2139. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2140. // content/SpinCalc.m
  2141. const cos = Math.cos;
  2142. const sin = Math.sin;
  2143. const c1 = cos( x / 2 );
  2144. const c2 = cos( y / 2 );
  2145. const c3 = cos( z / 2 );
  2146. const s1 = sin( x / 2 );
  2147. const s2 = sin( y / 2 );
  2148. const s3 = sin( z / 2 );
  2149. switch ( order ) {
  2150. case 'XYZ':
  2151. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2152. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2153. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2154. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2155. break;
  2156. case 'YXZ':
  2157. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2158. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2159. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2160. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2161. break;
  2162. case 'ZXY':
  2163. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2164. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2165. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2166. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2167. break;
  2168. case 'ZYX':
  2169. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2170. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2171. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2172. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2173. break;
  2174. case 'YZX':
  2175. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2176. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2177. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2178. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2179. break;
  2180. case 'XZY':
  2181. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2182. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2183. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2184. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2185. break;
  2186. default:
  2187. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  2188. }
  2189. if ( update === true ) this._onChangeCallback();
  2190. return this;
  2191. }
  2192. setFromAxisAngle( axis, angle ) {
  2193. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2194. // assumes axis is normalized
  2195. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  2196. this._x = axis.x * s;
  2197. this._y = axis.y * s;
  2198. this._z = axis.z * s;
  2199. this._w = Math.cos( halfAngle );
  2200. this._onChangeCallback();
  2201. return this;
  2202. }
  2203. setFromRotationMatrix( m ) {
  2204. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2205. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2206. const te = m.elements,
  2207. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2208. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2209. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  2210. trace = m11 + m22 + m33;
  2211. if ( trace > 0 ) {
  2212. const s = 0.5 / Math.sqrt( trace + 1.0 );
  2213. this._w = 0.25 / s;
  2214. this._x = ( m32 - m23 ) * s;
  2215. this._y = ( m13 - m31 ) * s;
  2216. this._z = ( m21 - m12 ) * s;
  2217. } else if ( m11 > m22 && m11 > m33 ) {
  2218. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  2219. this._w = ( m32 - m23 ) / s;
  2220. this._x = 0.25 * s;
  2221. this._y = ( m12 + m21 ) / s;
  2222. this._z = ( m13 + m31 ) / s;
  2223. } else if ( m22 > m33 ) {
  2224. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  2225. this._w = ( m13 - m31 ) / s;
  2226. this._x = ( m12 + m21 ) / s;
  2227. this._y = 0.25 * s;
  2228. this._z = ( m23 + m32 ) / s;
  2229. } else {
  2230. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  2231. this._w = ( m21 - m12 ) / s;
  2232. this._x = ( m13 + m31 ) / s;
  2233. this._y = ( m23 + m32 ) / s;
  2234. this._z = 0.25 * s;
  2235. }
  2236. this._onChangeCallback();
  2237. return this;
  2238. }
  2239. setFromUnitVectors( vFrom, vTo ) {
  2240. // assumes direction vectors vFrom and vTo are normalized
  2241. let r = vFrom.dot( vTo ) + 1;
  2242. if ( r < Number.EPSILON ) {
  2243. // vFrom and vTo point in opposite directions
  2244. r = 0;
  2245. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  2246. this._x = - vFrom.y;
  2247. this._y = vFrom.x;
  2248. this._z = 0;
  2249. this._w = r;
  2250. } else {
  2251. this._x = 0;
  2252. this._y = - vFrom.z;
  2253. this._z = vFrom.y;
  2254. this._w = r;
  2255. }
  2256. } else {
  2257. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2258. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2259. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2260. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2261. this._w = r;
  2262. }
  2263. return this.normalize();
  2264. }
  2265. angleTo( q ) {
  2266. return 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) );
  2267. }
  2268. rotateTowards( q, step ) {
  2269. const angle = this.angleTo( q );
  2270. if ( angle === 0 ) return this;
  2271. const t = Math.min( 1, step / angle );
  2272. this.slerp( q, t );
  2273. return this;
  2274. }
  2275. identity() {
  2276. return this.set( 0, 0, 0, 1 );
  2277. }
  2278. invert() {
  2279. // quaternion is assumed to have unit length
  2280. return this.conjugate();
  2281. }
  2282. conjugate() {
  2283. this._x *= - 1;
  2284. this._y *= - 1;
  2285. this._z *= - 1;
  2286. this._onChangeCallback();
  2287. return this;
  2288. }
  2289. dot( v ) {
  2290. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2291. }
  2292. lengthSq() {
  2293. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2294. }
  2295. length() {
  2296. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  2297. }
  2298. normalize() {
  2299. let l = this.length();
  2300. if ( l === 0 ) {
  2301. this._x = 0;
  2302. this._y = 0;
  2303. this._z = 0;
  2304. this._w = 1;
  2305. } else {
  2306. l = 1 / l;
  2307. this._x = this._x * l;
  2308. this._y = this._y * l;
  2309. this._z = this._z * l;
  2310. this._w = this._w * l;
  2311. }
  2312. this._onChangeCallback();
  2313. return this;
  2314. }
  2315. multiply( q ) {
  2316. return this.multiplyQuaternions( this, q );
  2317. }
  2318. premultiply( q ) {
  2319. return this.multiplyQuaternions( q, this );
  2320. }
  2321. multiplyQuaternions( a, b ) {
  2322. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2323. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  2324. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  2325. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2326. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2327. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2328. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2329. this._onChangeCallback();
  2330. return this;
  2331. }
  2332. slerp( qb, t ) {
  2333. if ( t === 0 ) return this;
  2334. if ( t === 1 ) return this.copy( qb );
  2335. const x = this._x, y = this._y, z = this._z, w = this._w;
  2336. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2337. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2338. if ( cosHalfTheta < 0 ) {
  2339. this._w = - qb._w;
  2340. this._x = - qb._x;
  2341. this._y = - qb._y;
  2342. this._z = - qb._z;
  2343. cosHalfTheta = - cosHalfTheta;
  2344. } else {
  2345. this.copy( qb );
  2346. }
  2347. if ( cosHalfTheta >= 1.0 ) {
  2348. this._w = w;
  2349. this._x = x;
  2350. this._y = y;
  2351. this._z = z;
  2352. return this;
  2353. }
  2354. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2355. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  2356. const s = 1 - t;
  2357. this._w = s * w + t * this._w;
  2358. this._x = s * x + t * this._x;
  2359. this._y = s * y + t * this._y;
  2360. this._z = s * z + t * this._z;
  2361. this.normalize(); // normalize calls _onChangeCallback()
  2362. return this;
  2363. }
  2364. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  2365. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  2366. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2367. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2368. this._w = ( w * ratioA + this._w * ratioB );
  2369. this._x = ( x * ratioA + this._x * ratioB );
  2370. this._y = ( y * ratioA + this._y * ratioB );
  2371. this._z = ( z * ratioA + this._z * ratioB );
  2372. this._onChangeCallback();
  2373. return this;
  2374. }
  2375. slerpQuaternions( qa, qb, t ) {
  2376. return this.copy( qa ).slerp( qb, t );
  2377. }
  2378. random() {
  2379. // sets this quaternion to a uniform random unit quaternnion
  2380. // Ken Shoemake
  2381. // Uniform random rotations
  2382. // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
  2383. const theta1 = 2 * Math.PI * Math.random();
  2384. const theta2 = 2 * Math.PI * Math.random();
  2385. const x0 = Math.random();
  2386. const r1 = Math.sqrt( 1 - x0 );
  2387. const r2 = Math.sqrt( x0 );
  2388. return this.set(
  2389. r1 * Math.sin( theta1 ),
  2390. r1 * Math.cos( theta1 ),
  2391. r2 * Math.sin( theta2 ),
  2392. r2 * Math.cos( theta2 ),
  2393. );
  2394. }
  2395. equals( quaternion ) {
  2396. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  2397. }
  2398. fromArray( array, offset = 0 ) {
  2399. this._x = array[ offset ];
  2400. this._y = array[ offset + 1 ];
  2401. this._z = array[ offset + 2 ];
  2402. this._w = array[ offset + 3 ];
  2403. this._onChangeCallback();
  2404. return this;
  2405. }
  2406. toArray( array = [], offset = 0 ) {
  2407. array[ offset ] = this._x;
  2408. array[ offset + 1 ] = this._y;
  2409. array[ offset + 2 ] = this._z;
  2410. array[ offset + 3 ] = this._w;
  2411. return array;
  2412. }
  2413. fromBufferAttribute( attribute, index ) {
  2414. this._x = attribute.getX( index );
  2415. this._y = attribute.getY( index );
  2416. this._z = attribute.getZ( index );
  2417. this._w = attribute.getW( index );
  2418. this._onChangeCallback();
  2419. return this;
  2420. }
  2421. toJSON() {
  2422. return this.toArray();
  2423. }
  2424. _onChange( callback ) {
  2425. this._onChangeCallback = callback;
  2426. return this;
  2427. }
  2428. _onChangeCallback() {}
  2429. *[ Symbol.iterator ]() {
  2430. yield this._x;
  2431. yield this._y;
  2432. yield this._z;
  2433. yield this._w;
  2434. }
  2435. }
  2436. class Vector3 {
  2437. constructor( x = 0, y = 0, z = 0 ) {
  2438. Vector3.prototype.isVector3 = true;
  2439. this.x = x;
  2440. this.y = y;
  2441. this.z = z;
  2442. }
  2443. set( x, y, z ) {
  2444. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  2445. this.x = x;
  2446. this.y = y;
  2447. this.z = z;
  2448. return this;
  2449. }
  2450. setScalar( scalar ) {
  2451. this.x = scalar;
  2452. this.y = scalar;
  2453. this.z = scalar;
  2454. return this;
  2455. }
  2456. setX( x ) {
  2457. this.x = x;
  2458. return this;
  2459. }
  2460. setY( y ) {
  2461. this.y = y;
  2462. return this;
  2463. }
  2464. setZ( z ) {
  2465. this.z = z;
  2466. return this;
  2467. }
  2468. setComponent( index, value ) {
  2469. switch ( index ) {
  2470. case 0: this.x = value; break;
  2471. case 1: this.y = value; break;
  2472. case 2: this.z = value; break;
  2473. default: throw new Error( 'index is out of range: ' + index );
  2474. }
  2475. return this;
  2476. }
  2477. getComponent( index ) {
  2478. switch ( index ) {
  2479. case 0: return this.x;
  2480. case 1: return this.y;
  2481. case 2: return this.z;
  2482. default: throw new Error( 'index is out of range: ' + index );
  2483. }
  2484. }
  2485. clone() {
  2486. return new this.constructor( this.x, this.y, this.z );
  2487. }
  2488. copy( v ) {
  2489. this.x = v.x;
  2490. this.y = v.y;
  2491. this.z = v.z;
  2492. return this;
  2493. }
  2494. add( v ) {
  2495. this.x += v.x;
  2496. this.y += v.y;
  2497. this.z += v.z;
  2498. return this;
  2499. }
  2500. addScalar( s ) {
  2501. this.x += s;
  2502. this.y += s;
  2503. this.z += s;
  2504. return this;
  2505. }
  2506. addVectors( a, b ) {
  2507. this.x = a.x + b.x;
  2508. this.y = a.y + b.y;
  2509. this.z = a.z + b.z;
  2510. return this;
  2511. }
  2512. addScaledVector( v, s ) {
  2513. this.x += v.x * s;
  2514. this.y += v.y * s;
  2515. this.z += v.z * s;
  2516. return this;
  2517. }
  2518. sub( v ) {
  2519. this.x -= v.x;
  2520. this.y -= v.y;
  2521. this.z -= v.z;
  2522. return this;
  2523. }
  2524. subScalar( s ) {
  2525. this.x -= s;
  2526. this.y -= s;
  2527. this.z -= s;
  2528. return this;
  2529. }
  2530. subVectors( a, b ) {
  2531. this.x = a.x - b.x;
  2532. this.y = a.y - b.y;
  2533. this.z = a.z - b.z;
  2534. return this;
  2535. }
  2536. multiply( v ) {
  2537. this.x *= v.x;
  2538. this.y *= v.y;
  2539. this.z *= v.z;
  2540. return this;
  2541. }
  2542. multiplyScalar( scalar ) {
  2543. this.x *= scalar;
  2544. this.y *= scalar;
  2545. this.z *= scalar;
  2546. return this;
  2547. }
  2548. multiplyVectors( a, b ) {
  2549. this.x = a.x * b.x;
  2550. this.y = a.y * b.y;
  2551. this.z = a.z * b.z;
  2552. return this;
  2553. }
  2554. applyEuler( euler ) {
  2555. return this.applyQuaternion( _quaternion$4.setFromEuler( euler ) );
  2556. }
  2557. applyAxisAngle( axis, angle ) {
  2558. return this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) );
  2559. }
  2560. applyMatrix3( m ) {
  2561. const x = this.x, y = this.y, z = this.z;
  2562. const e = m.elements;
  2563. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2564. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2565. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2566. return this;
  2567. }
  2568. applyNormalMatrix( m ) {
  2569. return this.applyMatrix3( m ).normalize();
  2570. }
  2571. applyMatrix4( m ) {
  2572. const x = this.x, y = this.y, z = this.z;
  2573. const e = m.elements;
  2574. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2575. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2576. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2577. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2578. return this;
  2579. }
  2580. applyQuaternion( q ) {
  2581. // quaternion q is assumed to have unit length
  2582. const vx = this.x, vy = this.y, vz = this.z;
  2583. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2584. // t = 2 * cross( q.xyz, v );
  2585. const tx = 2 * ( qy * vz - qz * vy );
  2586. const ty = 2 * ( qz * vx - qx * vz );
  2587. const tz = 2 * ( qx * vy - qy * vx );
  2588. // v + q.w * t + cross( q.xyz, t );
  2589. this.x = vx + qw * tx + qy * tz - qz * ty;
  2590. this.y = vy + qw * ty + qz * tx - qx * tz;
  2591. this.z = vz + qw * tz + qx * ty - qy * tx;
  2592. return this;
  2593. }
  2594. project( camera ) {
  2595. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2596. }
  2597. unproject( camera ) {
  2598. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2599. }
  2600. transformDirection( m ) {
  2601. // input: THREE.Matrix4 affine matrix
  2602. // vector interpreted as a direction
  2603. const x = this.x, y = this.y, z = this.z;
  2604. const e = m.elements;
  2605. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2606. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2607. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2608. return this.normalize();
  2609. }
  2610. divide( v ) {
  2611. this.x /= v.x;
  2612. this.y /= v.y;
  2613. this.z /= v.z;
  2614. return this;
  2615. }
  2616. divideScalar( scalar ) {
  2617. return this.multiplyScalar( 1 / scalar );
  2618. }
  2619. min( v ) {
  2620. this.x = Math.min( this.x, v.x );
  2621. this.y = Math.min( this.y, v.y );
  2622. this.z = Math.min( this.z, v.z );
  2623. return this;
  2624. }
  2625. max( v ) {
  2626. this.x = Math.max( this.x, v.x );
  2627. this.y = Math.max( this.y, v.y );
  2628. this.z = Math.max( this.z, v.z );
  2629. return this;
  2630. }
  2631. clamp( min, max ) {
  2632. // assumes min < max, componentwise
  2633. this.x = clamp( this.x, min.x, max.x );
  2634. this.y = clamp( this.y, min.y, max.y );
  2635. this.z = clamp( this.z, min.z, max.z );
  2636. return this;
  2637. }
  2638. clampScalar( minVal, maxVal ) {
  2639. this.x = clamp( this.x, minVal, maxVal );
  2640. this.y = clamp( this.y, minVal, maxVal );
  2641. this.z = clamp( this.z, minVal, maxVal );
  2642. return this;
  2643. }
  2644. clampLength( min, max ) {
  2645. const length = this.length();
  2646. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  2647. }
  2648. floor() {
  2649. this.x = Math.floor( this.x );
  2650. this.y = Math.floor( this.y );
  2651. this.z = Math.floor( this.z );
  2652. return this;
  2653. }
  2654. ceil() {
  2655. this.x = Math.ceil( this.x );
  2656. this.y = Math.ceil( this.y );
  2657. this.z = Math.ceil( this.z );
  2658. return this;
  2659. }
  2660. round() {
  2661. this.x = Math.round( this.x );
  2662. this.y = Math.round( this.y );
  2663. this.z = Math.round( this.z );
  2664. return this;
  2665. }
  2666. roundToZero() {
  2667. this.x = Math.trunc( this.x );
  2668. this.y = Math.trunc( this.y );
  2669. this.z = Math.trunc( this.z );
  2670. return this;
  2671. }
  2672. negate() {
  2673. this.x = - this.x;
  2674. this.y = - this.y;
  2675. this.z = - this.z;
  2676. return this;
  2677. }
  2678. dot( v ) {
  2679. return this.x * v.x + this.y * v.y + this.z * v.z;
  2680. }
  2681. // TODO lengthSquared?
  2682. lengthSq() {
  2683. return this.x * this.x + this.y * this.y + this.z * this.z;
  2684. }
  2685. length() {
  2686. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2687. }
  2688. manhattanLength() {
  2689. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2690. }
  2691. normalize() {
  2692. return this.divideScalar( this.length() || 1 );
  2693. }
  2694. setLength( length ) {
  2695. return this.normalize().multiplyScalar( length );
  2696. }
  2697. lerp( v, alpha ) {
  2698. this.x += ( v.x - this.x ) * alpha;
  2699. this.y += ( v.y - this.y ) * alpha;
  2700. this.z += ( v.z - this.z ) * alpha;
  2701. return this;
  2702. }
  2703. lerpVectors( v1, v2, alpha ) {
  2704. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2705. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2706. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2707. return this;
  2708. }
  2709. cross( v ) {
  2710. return this.crossVectors( this, v );
  2711. }
  2712. crossVectors( a, b ) {
  2713. const ax = a.x, ay = a.y, az = a.z;
  2714. const bx = b.x, by = b.y, bz = b.z;
  2715. this.x = ay * bz - az * by;
  2716. this.y = az * bx - ax * bz;
  2717. this.z = ax * by - ay * bx;
  2718. return this;
  2719. }
  2720. projectOnVector( v ) {
  2721. const denominator = v.lengthSq();
  2722. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2723. const scalar = v.dot( this ) / denominator;
  2724. return this.copy( v ).multiplyScalar( scalar );
  2725. }
  2726. projectOnPlane( planeNormal ) {
  2727. _vector$c.copy( this ).projectOnVector( planeNormal );
  2728. return this.sub( _vector$c );
  2729. }
  2730. reflect( normal ) {
  2731. // reflect incident vector off plane orthogonal to normal
  2732. // normal is assumed to have unit length
  2733. return this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2734. }
  2735. angleTo( v ) {
  2736. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2737. if ( denominator === 0 ) return Math.PI / 2;
  2738. const theta = this.dot( v ) / denominator;
  2739. // clamp, to handle numerical problems
  2740. return Math.acos( clamp( theta, - 1, 1 ) );
  2741. }
  2742. distanceTo( v ) {
  2743. return Math.sqrt( this.distanceToSquared( v ) );
  2744. }
  2745. distanceToSquared( v ) {
  2746. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2747. return dx * dx + dy * dy + dz * dz;
  2748. }
  2749. manhattanDistanceTo( v ) {
  2750. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2751. }
  2752. setFromSpherical( s ) {
  2753. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2754. }
  2755. setFromSphericalCoords( radius, phi, theta ) {
  2756. const sinPhiRadius = Math.sin( phi ) * radius;
  2757. this.x = sinPhiRadius * Math.sin( theta );
  2758. this.y = Math.cos( phi ) * radius;
  2759. this.z = sinPhiRadius * Math.cos( theta );
  2760. return this;
  2761. }
  2762. setFromCylindrical( c ) {
  2763. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2764. }
  2765. setFromCylindricalCoords( radius, theta, y ) {
  2766. this.x = radius * Math.sin( theta );
  2767. this.y = y;
  2768. this.z = radius * Math.cos( theta );
  2769. return this;
  2770. }
  2771. setFromMatrixPosition( m ) {
  2772. const e = m.elements;
  2773. this.x = e[ 12 ];
  2774. this.y = e[ 13 ];
  2775. this.z = e[ 14 ];
  2776. return this;
  2777. }
  2778. setFromMatrixScale( m ) {
  2779. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2780. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2781. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2782. this.x = sx;
  2783. this.y = sy;
  2784. this.z = sz;
  2785. return this;
  2786. }
  2787. setFromMatrixColumn( m, index ) {
  2788. return this.fromArray( m.elements, index * 4 );
  2789. }
  2790. setFromMatrix3Column( m, index ) {
  2791. return this.fromArray( m.elements, index * 3 );
  2792. }
  2793. setFromEuler( e ) {
  2794. this.x = e._x;
  2795. this.y = e._y;
  2796. this.z = e._z;
  2797. return this;
  2798. }
  2799. setFromColor( c ) {
  2800. this.x = c.r;
  2801. this.y = c.g;
  2802. this.z = c.b;
  2803. return this;
  2804. }
  2805. equals( v ) {
  2806. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2807. }
  2808. fromArray( array, offset = 0 ) {
  2809. this.x = array[ offset ];
  2810. this.y = array[ offset + 1 ];
  2811. this.z = array[ offset + 2 ];
  2812. return this;
  2813. }
  2814. toArray( array = [], offset = 0 ) {
  2815. array[ offset ] = this.x;
  2816. array[ offset + 1 ] = this.y;
  2817. array[ offset + 2 ] = this.z;
  2818. return array;
  2819. }
  2820. fromBufferAttribute( attribute, index ) {
  2821. this.x = attribute.getX( index );
  2822. this.y = attribute.getY( index );
  2823. this.z = attribute.getZ( index );
  2824. return this;
  2825. }
  2826. random() {
  2827. this.x = Math.random();
  2828. this.y = Math.random();
  2829. this.z = Math.random();
  2830. return this;
  2831. }
  2832. randomDirection() {
  2833. // https://mathworld.wolfram.com/SpherePointPicking.html
  2834. const theta = Math.random() * Math.PI * 2;
  2835. const u = Math.random() * 2 - 1;
  2836. const c = Math.sqrt( 1 - u * u );
  2837. this.x = c * Math.cos( theta );
  2838. this.y = u;
  2839. this.z = c * Math.sin( theta );
  2840. return this;
  2841. }
  2842. *[ Symbol.iterator ]() {
  2843. yield this.x;
  2844. yield this.y;
  2845. yield this.z;
  2846. }
  2847. }
  2848. const _vector$c = /*@__PURE__*/ new Vector3();
  2849. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  2850. class Box3 {
  2851. constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
  2852. this.isBox3 = true;
  2853. this.min = min;
  2854. this.max = max;
  2855. }
  2856. set( min, max ) {
  2857. this.min.copy( min );
  2858. this.max.copy( max );
  2859. return this;
  2860. }
  2861. setFromArray( array ) {
  2862. this.makeEmpty();
  2863. for ( let i = 0, il = array.length; i < il; i += 3 ) {
  2864. this.expandByPoint( _vector$b.fromArray( array, i ) );
  2865. }
  2866. return this;
  2867. }
  2868. setFromBufferAttribute( attribute ) {
  2869. this.makeEmpty();
  2870. for ( let i = 0, il = attribute.count; i < il; i ++ ) {
  2871. this.expandByPoint( _vector$b.fromBufferAttribute( attribute, i ) );
  2872. }
  2873. return this;
  2874. }
  2875. setFromPoints( points ) {
  2876. this.makeEmpty();
  2877. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2878. this.expandByPoint( points[ i ] );
  2879. }
  2880. return this;
  2881. }
  2882. setFromCenterAndSize( center, size ) {
  2883. const halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 );
  2884. this.min.copy( center ).sub( halfSize );
  2885. this.max.copy( center ).add( halfSize );
  2886. return this;
  2887. }
  2888. setFromObject( object, precise = false ) {
  2889. this.makeEmpty();
  2890. return this.expandByObject( object, precise );
  2891. }
  2892. clone() {
  2893. return new this.constructor().copy( this );
  2894. }
  2895. copy( box ) {
  2896. this.min.copy( box.min );
  2897. this.max.copy( box.max );
  2898. return this;
  2899. }
  2900. makeEmpty() {
  2901. this.min.x = this.min.y = this.min.z = + Infinity;
  2902. this.max.x = this.max.y = this.max.z = - Infinity;
  2903. return this;
  2904. }
  2905. isEmpty() {
  2906. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2907. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2908. }
  2909. getCenter( target ) {
  2910. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2911. }
  2912. getSize( target ) {
  2913. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2914. }
  2915. expandByPoint( point ) {
  2916. this.min.min( point );
  2917. this.max.max( point );
  2918. return this;
  2919. }
  2920. expandByVector( vector ) {
  2921. this.min.sub( vector );
  2922. this.max.add( vector );
  2923. return this;
  2924. }
  2925. expandByScalar( scalar ) {
  2926. this.min.addScalar( - scalar );
  2927. this.max.addScalar( scalar );
  2928. return this;
  2929. }
  2930. expandByObject( object, precise = false ) {
  2931. // Computes the world-axis-aligned bounding box of an object (including its children),
  2932. // accounting for both the object's, and children's, world transforms
  2933. object.updateWorldMatrix( false, false );
  2934. const geometry = object.geometry;
  2935. if ( geometry !== undefined ) {
  2936. const positionAttribute = geometry.getAttribute( 'position' );
  2937. // precise AABB computation based on vertex data requires at least a position attribute.
  2938. // instancing isn't supported so far and uses the normal (conservative) code path.
  2939. if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
  2940. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  2941. if ( object.isMesh === true ) {
  2942. object.getVertexPosition( i, _vector$b );
  2943. } else {
  2944. _vector$b.fromBufferAttribute( positionAttribute, i );
  2945. }
  2946. _vector$b.applyMatrix4( object.matrixWorld );
  2947. this.expandByPoint( _vector$b );
  2948. }
  2949. } else {
  2950. if ( object.boundingBox !== undefined ) {
  2951. // object-level bounding box
  2952. if ( object.boundingBox === null ) {
  2953. object.computeBoundingBox();
  2954. }
  2955. _box$4.copy( object.boundingBox );
  2956. } else {
  2957. // geometry-level bounding box
  2958. if ( geometry.boundingBox === null ) {
  2959. geometry.computeBoundingBox();
  2960. }
  2961. _box$4.copy( geometry.boundingBox );
  2962. }
  2963. _box$4.applyMatrix4( object.matrixWorld );
  2964. this.union( _box$4 );
  2965. }
  2966. }
  2967. const children = object.children;
  2968. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2969. this.expandByObject( children[ i ], precise );
  2970. }
  2971. return this;
  2972. }
  2973. containsPoint( point ) {
  2974. return point.x >= this.min.x && point.x <= this.max.x &&
  2975. point.y >= this.min.y && point.y <= this.max.y &&
  2976. point.z >= this.min.z && point.z <= this.max.z;
  2977. }
  2978. containsBox( box ) {
  2979. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2980. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2981. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2982. }
  2983. getParameter( point, target ) {
  2984. // This can potentially have a divide by zero if the box
  2985. // has a size dimension of 0.
  2986. return target.set(
  2987. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2988. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2989. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2990. );
  2991. }
  2992. intersectsBox( box ) {
  2993. // using 6 splitting planes to rule out intersections.
  2994. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  2995. box.max.y >= this.min.y && box.min.y <= this.max.y &&
  2996. box.max.z >= this.min.z && box.min.z <= this.max.z;
  2997. }
  2998. intersectsSphere( sphere ) {
  2999. // Find the point on the AABB closest to the sphere center.
  3000. this.clampPoint( sphere.center, _vector$b );
  3001. // If that point is inside the sphere, the AABB and sphere intersect.
  3002. return _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3003. }
  3004. intersectsPlane( plane ) {
  3005. // We compute the minimum and maximum dot product values. If those values
  3006. // are on the same side (back or front) of the plane, then there is no intersection.
  3007. let min, max;
  3008. if ( plane.normal.x > 0 ) {
  3009. min = plane.normal.x * this.min.x;
  3010. max = plane.normal.x * this.max.x;
  3011. } else {
  3012. min = plane.normal.x * this.max.x;
  3013. max = plane.normal.x * this.min.x;
  3014. }
  3015. if ( plane.normal.y > 0 ) {
  3016. min += plane.normal.y * this.min.y;
  3017. max += plane.normal.y * this.max.y;
  3018. } else {
  3019. min += plane.normal.y * this.max.y;
  3020. max += plane.normal.y * this.min.y;
  3021. }
  3022. if ( plane.normal.z > 0 ) {
  3023. min += plane.normal.z * this.min.z;
  3024. max += plane.normal.z * this.max.z;
  3025. } else {
  3026. min += plane.normal.z * this.max.z;
  3027. max += plane.normal.z * this.min.z;
  3028. }
  3029. return ( min <= - plane.constant && max >= - plane.constant );
  3030. }
  3031. intersectsTriangle( triangle ) {
  3032. if ( this.isEmpty() ) {
  3033. return false;
  3034. }
  3035. // compute box center and extents
  3036. this.getCenter( _center );
  3037. _extents.subVectors( this.max, _center );
  3038. // translate triangle to aabb origin
  3039. _v0$2.subVectors( triangle.a, _center );
  3040. _v1$7.subVectors( triangle.b, _center );
  3041. _v2$4.subVectors( triangle.c, _center );
  3042. // compute edge vectors for triangle
  3043. _f0.subVectors( _v1$7, _v0$2 );
  3044. _f1.subVectors( _v2$4, _v1$7 );
  3045. _f2.subVectors( _v0$2, _v2$4 );
  3046. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3047. // 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
  3048. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3049. let axes = [
  3050. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3051. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3052. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3053. ];
  3054. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3055. return false;
  3056. }
  3057. // test 3 face normals from the aabb
  3058. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3059. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3060. return false;
  3061. }
  3062. // finally testing the face normal of the triangle
  3063. // use already existing triangle edge vectors here
  3064. _triangleNormal.crossVectors( _f0, _f1 );
  3065. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3066. return satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents );
  3067. }
  3068. clampPoint( point, target ) {
  3069. return target.copy( point ).clamp( this.min, this.max );
  3070. }
  3071. distanceToPoint( point ) {
  3072. return this.clampPoint( point, _vector$b ).distanceTo( point );
  3073. }
  3074. getBoundingSphere( target ) {
  3075. if ( this.isEmpty() ) {
  3076. target.makeEmpty();
  3077. } else {
  3078. this.getCenter( target.center );
  3079. target.radius = this.getSize( _vector$b ).length() * 0.5;
  3080. }
  3081. return target;
  3082. }
  3083. intersect( box ) {
  3084. this.min.max( box.min );
  3085. this.max.min( box.max );
  3086. // 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.
  3087. if ( this.isEmpty() ) this.makeEmpty();
  3088. return this;
  3089. }
  3090. union( box ) {
  3091. this.min.min( box.min );
  3092. this.max.max( box.max );
  3093. return this;
  3094. }
  3095. applyMatrix4( matrix ) {
  3096. // transform of empty box is an empty box.
  3097. if ( this.isEmpty() ) return this;
  3098. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3099. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3100. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3101. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3102. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3103. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3104. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3105. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3106. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3107. this.setFromPoints( _points );
  3108. return this;
  3109. }
  3110. translate( offset ) {
  3111. this.min.add( offset );
  3112. this.max.add( offset );
  3113. return this;
  3114. }
  3115. equals( box ) {
  3116. return box.min.equals( this.min ) && box.max.equals( this.max );
  3117. }
  3118. }
  3119. const _points = [
  3120. /*@__PURE__*/ new Vector3(),
  3121. /*@__PURE__*/ new Vector3(),
  3122. /*@__PURE__*/ new Vector3(),
  3123. /*@__PURE__*/ new Vector3(),
  3124. /*@__PURE__*/ new Vector3(),
  3125. /*@__PURE__*/ new Vector3(),
  3126. /*@__PURE__*/ new Vector3(),
  3127. /*@__PURE__*/ new Vector3()
  3128. ];
  3129. const _vector$b = /*@__PURE__*/ new Vector3();
  3130. const _box$4 = /*@__PURE__*/ new Box3();
  3131. // triangle centered vertices
  3132. const _v0$2 = /*@__PURE__*/ new Vector3();
  3133. const _v1$7 = /*@__PURE__*/ new Vector3();
  3134. const _v2$4 = /*@__PURE__*/ new Vector3();
  3135. // triangle edge vectors
  3136. const _f0 = /*@__PURE__*/ new Vector3();
  3137. const _f1 = /*@__PURE__*/ new Vector3();
  3138. const _f2 = /*@__PURE__*/ new Vector3();
  3139. const _center = /*@__PURE__*/ new Vector3();
  3140. const _extents = /*@__PURE__*/ new Vector3();
  3141. const _triangleNormal = /*@__PURE__*/ new Vector3();
  3142. const _testAxis = /*@__PURE__*/ new Vector3();
  3143. function satForAxes( axes, v0, v1, v2, extents ) {
  3144. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3145. _testAxis.fromArray( axes, i );
  3146. // project the aabb onto the separating axis
  3147. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  3148. // project all 3 vertices of the triangle onto the separating axis
  3149. const p0 = v0.dot( _testAxis );
  3150. const p1 = v1.dot( _testAxis );
  3151. const p2 = v2.dot( _testAxis );
  3152. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3153. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3154. // points of the projected triangle are outside the projected half-length of the aabb
  3155. // the axis is separating and we can exit
  3156. return false;
  3157. }
  3158. }
  3159. return true;
  3160. }
  3161. const _box$3 = /*@__PURE__*/ new Box3();
  3162. const _v1$6 = /*@__PURE__*/ new Vector3();
  3163. const _v2$3 = /*@__PURE__*/ new Vector3();
  3164. class Sphere {
  3165. constructor( center = new Vector3(), radius = - 1 ) {
  3166. this.isSphere = true;
  3167. this.center = center;
  3168. this.radius = radius;
  3169. }
  3170. set( center, radius ) {
  3171. this.center.copy( center );
  3172. this.radius = radius;
  3173. return this;
  3174. }
  3175. setFromPoints( points, optionalCenter ) {
  3176. const center = this.center;
  3177. if ( optionalCenter !== undefined ) {
  3178. center.copy( optionalCenter );
  3179. } else {
  3180. _box$3.setFromPoints( points ).getCenter( center );
  3181. }
  3182. let maxRadiusSq = 0;
  3183. for ( let i = 0, il = points.length; i < il; i ++ ) {
  3184. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3185. }
  3186. this.radius = Math.sqrt( maxRadiusSq );
  3187. return this;
  3188. }
  3189. copy( sphere ) {
  3190. this.center.copy( sphere.center );
  3191. this.radius = sphere.radius;
  3192. return this;
  3193. }
  3194. isEmpty() {
  3195. return ( this.radius < 0 );
  3196. }
  3197. makeEmpty() {
  3198. this.center.set( 0, 0, 0 );
  3199. this.radius = - 1;
  3200. return this;
  3201. }
  3202. containsPoint( point ) {
  3203. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3204. }
  3205. distanceToPoint( point ) {
  3206. return ( point.distanceTo( this.center ) - this.radius );
  3207. }
  3208. intersectsSphere( sphere ) {
  3209. const radiusSum = this.radius + sphere.radius;
  3210. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3211. }
  3212. intersectsBox( box ) {
  3213. return box.intersectsSphere( this );
  3214. }
  3215. intersectsPlane( plane ) {
  3216. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3217. }
  3218. clampPoint( point, target ) {
  3219. const deltaLengthSq = this.center.distanceToSquared( point );
  3220. target.copy( point );
  3221. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3222. target.sub( this.center ).normalize();
  3223. target.multiplyScalar( this.radius ).add( this.center );
  3224. }
  3225. return target;
  3226. }
  3227. getBoundingBox( target ) {
  3228. if ( this.isEmpty() ) {
  3229. // Empty sphere produces empty bounding box
  3230. target.makeEmpty();
  3231. return target;
  3232. }
  3233. target.set( this.center, this.center );
  3234. target.expandByScalar( this.radius );
  3235. return target;
  3236. }
  3237. applyMatrix4( matrix ) {
  3238. this.center.applyMatrix4( matrix );
  3239. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3240. return this;
  3241. }
  3242. translate( offset ) {
  3243. this.center.add( offset );
  3244. return this;
  3245. }
  3246. expandByPoint( point ) {
  3247. if ( this.isEmpty() ) {
  3248. this.center.copy( point );
  3249. this.radius = 0;
  3250. return this;
  3251. }
  3252. _v1$6.subVectors( point, this.center );
  3253. const lengthSq = _v1$6.lengthSq();
  3254. if ( lengthSq > ( this.radius * this.radius ) ) {
  3255. // calculate the minimal sphere
  3256. const length = Math.sqrt( lengthSq );
  3257. const delta = ( length - this.radius ) * 0.5;
  3258. this.center.addScaledVector( _v1$6, delta / length );
  3259. this.radius += delta;
  3260. }
  3261. return this;
  3262. }
  3263. union( sphere ) {
  3264. if ( sphere.isEmpty() ) {
  3265. return this;
  3266. }
  3267. if ( this.isEmpty() ) {
  3268. this.copy( sphere );
  3269. return this;
  3270. }
  3271. if ( this.center.equals( sphere.center ) === true ) {
  3272. this.radius = Math.max( this.radius, sphere.radius );
  3273. } else {
  3274. _v2$3.subVectors( sphere.center, this.center ).setLength( sphere.radius );
  3275. this.expandByPoint( _v1$6.copy( sphere.center ).add( _v2$3 ) );
  3276. this.expandByPoint( _v1$6.copy( sphere.center ).sub( _v2$3 ) );
  3277. }
  3278. return this;
  3279. }
  3280. equals( sphere ) {
  3281. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3282. }
  3283. clone() {
  3284. return new this.constructor().copy( this );
  3285. }
  3286. }
  3287. const _vector$a = /*@__PURE__*/ new Vector3();
  3288. const _segCenter = /*@__PURE__*/ new Vector3();
  3289. const _segDir = /*@__PURE__*/ new Vector3();
  3290. const _diff = /*@__PURE__*/ new Vector3();
  3291. const _edge1 = /*@__PURE__*/ new Vector3();
  3292. const _edge2 = /*@__PURE__*/ new Vector3();
  3293. const _normal$1 = /*@__PURE__*/ new Vector3();
  3294. class Ray {
  3295. constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {
  3296. this.origin = origin;
  3297. this.direction = direction;
  3298. }
  3299. set( origin, direction ) {
  3300. this.origin.copy( origin );
  3301. this.direction.copy( direction );
  3302. return this;
  3303. }
  3304. copy( ray ) {
  3305. this.origin.copy( ray.origin );
  3306. this.direction.copy( ray.direction );
  3307. return this;
  3308. }
  3309. at( t, target ) {
  3310. return target.copy( this.origin ).addScaledVector( this.direction, t );
  3311. }
  3312. lookAt( v ) {
  3313. this.direction.copy( v ).sub( this.origin ).normalize();
  3314. return this;
  3315. }
  3316. recast( t ) {
  3317. this.origin.copy( this.at( t, _vector$a ) );
  3318. return this;
  3319. }
  3320. closestPointToPoint( point, target ) {
  3321. target.subVectors( point, this.origin );
  3322. const directionDistance = target.dot( this.direction );
  3323. if ( directionDistance < 0 ) {
  3324. return target.copy( this.origin );
  3325. }
  3326. return target.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3327. }
  3328. distanceToPoint( point ) {
  3329. return Math.sqrt( this.distanceSqToPoint( point ) );
  3330. }
  3331. distanceSqToPoint( point ) {
  3332. const directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction );
  3333. // point behind the ray
  3334. if ( directionDistance < 0 ) {
  3335. return this.origin.distanceToSquared( point );
  3336. }
  3337. _vector$a.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3338. return _vector$a.distanceToSquared( point );
  3339. }
  3340. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3341. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3342. // It returns the min distance between the ray and the segment
  3343. // defined by v0 and v1
  3344. // It can also set two optional targets :
  3345. // - The closest point on the ray
  3346. // - The closest point on the segment
  3347. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3348. _segDir.copy( v1 ).sub( v0 ).normalize();
  3349. _diff.copy( this.origin ).sub( _segCenter );
  3350. const segExtent = v0.distanceTo( v1 ) * 0.5;
  3351. const a01 = - this.direction.dot( _segDir );
  3352. const b0 = _diff.dot( this.direction );
  3353. const b1 = - _diff.dot( _segDir );
  3354. const c = _diff.lengthSq();
  3355. const det = Math.abs( 1 - a01 * a01 );
  3356. let s0, s1, sqrDist, extDet;
  3357. if ( det > 0 ) {
  3358. // The ray and segment are not parallel.
  3359. s0 = a01 * b1 - b0;
  3360. s1 = a01 * b0 - b1;
  3361. extDet = segExtent * det;
  3362. if ( s0 >= 0 ) {
  3363. if ( s1 >= - extDet ) {
  3364. if ( s1 <= extDet ) {
  3365. // region 0
  3366. // Minimum at interior points of ray and segment.
  3367. const invDet = 1 / det;
  3368. s0 *= invDet;
  3369. s1 *= invDet;
  3370. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3371. } else {
  3372. // region 1
  3373. s1 = segExtent;
  3374. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3375. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3376. }
  3377. } else {
  3378. // region 5
  3379. s1 = - segExtent;
  3380. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3381. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3382. }
  3383. } else {
  3384. if ( s1 <= - extDet ) {
  3385. // region 4
  3386. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3387. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3388. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3389. } else if ( s1 <= extDet ) {
  3390. // region 3
  3391. s0 = 0;
  3392. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3393. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3394. } else {
  3395. // region 2
  3396. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3397. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3398. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3399. }
  3400. }
  3401. } else {
  3402. // Ray and segment are parallel.
  3403. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3404. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3405. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3406. }
  3407. if ( optionalPointOnRay ) {
  3408. optionalPointOnRay.copy( this.origin ).addScaledVector( this.direction, s0 );
  3409. }
  3410. if ( optionalPointOnSegment ) {
  3411. optionalPointOnSegment.copy( _segCenter ).addScaledVector( _segDir, s1 );
  3412. }
  3413. return sqrDist;
  3414. }
  3415. intersectSphere( sphere, target ) {
  3416. _vector$a.subVectors( sphere.center, this.origin );
  3417. const tca = _vector$a.dot( this.direction );
  3418. const d2 = _vector$a.dot( _vector$a ) - tca * tca;
  3419. const radius2 = sphere.radius * sphere.radius;
  3420. if ( d2 > radius2 ) return null;
  3421. const thc = Math.sqrt( radius2 - d2 );
  3422. // t0 = first intersect point - entrance on front of sphere
  3423. const t0 = tca - thc;
  3424. // t1 = second intersect point - exit point on back of sphere
  3425. const t1 = tca + thc;
  3426. // test to see if t1 is behind the ray - if so, return null
  3427. if ( t1 < 0 ) return null;
  3428. // test to see if t0 is behind the ray:
  3429. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3430. // in order to always return an intersect point that is in front of the ray.
  3431. if ( t0 < 0 ) return this.at( t1, target );
  3432. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3433. return this.at( t0, target );
  3434. }
  3435. intersectsSphere( sphere ) {
  3436. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  3437. }
  3438. distanceToPlane( plane ) {
  3439. const denominator = plane.normal.dot( this.direction );
  3440. if ( denominator === 0 ) {
  3441. // line is coplanar, return origin
  3442. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3443. return 0;
  3444. }
  3445. // Null is preferable to undefined since undefined means.... it is undefined
  3446. return null;
  3447. }
  3448. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3449. // Return if the ray never intersects the plane
  3450. return t >= 0 ? t : null;
  3451. }
  3452. intersectPlane( plane, target ) {
  3453. const t = this.distanceToPlane( plane );
  3454. if ( t === null ) {
  3455. return null;
  3456. }
  3457. return this.at( t, target );
  3458. }
  3459. intersectsPlane( plane ) {
  3460. // check if the ray lies on the plane first
  3461. const distToPoint = plane.distanceToPoint( this.origin );
  3462. if ( distToPoint === 0 ) {
  3463. return true;
  3464. }
  3465. const denominator = plane.normal.dot( this.direction );
  3466. if ( denominator * distToPoint < 0 ) {
  3467. return true;
  3468. }
  3469. // ray origin is behind the plane (and is pointing behind it)
  3470. return false;
  3471. }
  3472. intersectBox( box, target ) {
  3473. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  3474. const invdirx = 1 / this.direction.x,
  3475. invdiry = 1 / this.direction.y,
  3476. invdirz = 1 / this.direction.z;
  3477. const origin = this.origin;
  3478. if ( invdirx >= 0 ) {
  3479. tmin = ( box.min.x - origin.x ) * invdirx;
  3480. tmax = ( box.max.x - origin.x ) * invdirx;
  3481. } else {
  3482. tmin = ( box.max.x - origin.x ) * invdirx;
  3483. tmax = ( box.min.x - origin.x ) * invdirx;
  3484. }
  3485. if ( invdiry >= 0 ) {
  3486. tymin = ( box.min.y - origin.y ) * invdiry;
  3487. tymax = ( box.max.y - origin.y ) * invdiry;
  3488. } else {
  3489. tymin = ( box.max.y - origin.y ) * invdiry;
  3490. tymax = ( box.min.y - origin.y ) * invdiry;
  3491. }
  3492. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3493. if ( tymin > tmin || isNaN( tmin ) ) tmin = tymin;
  3494. if ( tymax < tmax || isNaN( tmax ) ) tmax = tymax;
  3495. if ( invdirz >= 0 ) {
  3496. tzmin = ( box.min.z - origin.z ) * invdirz;
  3497. tzmax = ( box.max.z - origin.z ) * invdirz;
  3498. } else {
  3499. tzmin = ( box.max.z - origin.z ) * invdirz;
  3500. tzmax = ( box.min.z - origin.z ) * invdirz;
  3501. }
  3502. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3503. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3504. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3505. //return point closest to the ray (positive side)
  3506. if ( tmax < 0 ) return null;
  3507. return this.at( tmin >= 0 ? tmin : tmax, target );
  3508. }
  3509. intersectsBox( box ) {
  3510. return this.intersectBox( box, _vector$a ) !== null;
  3511. }
  3512. intersectTriangle( a, b, c, backfaceCulling, target ) {
  3513. // Compute the offset origin, edges, and normal.
  3514. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3515. _edge1.subVectors( b, a );
  3516. _edge2.subVectors( c, a );
  3517. _normal$1.crossVectors( _edge1, _edge2 );
  3518. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3519. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3520. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3521. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3522. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3523. let DdN = this.direction.dot( _normal$1 );
  3524. let sign;
  3525. if ( DdN > 0 ) {
  3526. if ( backfaceCulling ) return null;
  3527. sign = 1;
  3528. } else if ( DdN < 0 ) {
  3529. sign = - 1;
  3530. DdN = - DdN;
  3531. } else {
  3532. return null;
  3533. }
  3534. _diff.subVectors( this.origin, a );
  3535. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3536. // b1 < 0, no intersection
  3537. if ( DdQxE2 < 0 ) {
  3538. return null;
  3539. }
  3540. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3541. // b2 < 0, no intersection
  3542. if ( DdE1xQ < 0 ) {
  3543. return null;
  3544. }
  3545. // b1+b2 > 1, no intersection
  3546. if ( DdQxE2 + DdE1xQ > DdN ) {
  3547. return null;
  3548. }
  3549. // Line intersects triangle, check if ray does.
  3550. const QdN = - sign * _diff.dot( _normal$1 );
  3551. // t < 0, no intersection
  3552. if ( QdN < 0 ) {
  3553. return null;
  3554. }
  3555. // Ray intersects triangle.
  3556. return this.at( QdN / DdN, target );
  3557. }
  3558. applyMatrix4( matrix4 ) {
  3559. this.origin.applyMatrix4( matrix4 );
  3560. this.direction.transformDirection( matrix4 );
  3561. return this;
  3562. }
  3563. equals( ray ) {
  3564. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3565. }
  3566. clone() {
  3567. return new this.constructor().copy( this );
  3568. }
  3569. }
  3570. class Matrix4 {
  3571. constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3572. Matrix4.prototype.isMatrix4 = true;
  3573. this.elements = [
  3574. 1, 0, 0, 0,
  3575. 0, 1, 0, 0,
  3576. 0, 0, 1, 0,
  3577. 0, 0, 0, 1
  3578. ];
  3579. if ( n11 !== undefined ) {
  3580. this.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 );
  3581. }
  3582. }
  3583. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3584. const te = this.elements;
  3585. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3586. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3587. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3588. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3589. return this;
  3590. }
  3591. identity() {
  3592. this.set(
  3593. 1, 0, 0, 0,
  3594. 0, 1, 0, 0,
  3595. 0, 0, 1, 0,
  3596. 0, 0, 0, 1
  3597. );
  3598. return this;
  3599. }
  3600. clone() {
  3601. return new Matrix4().fromArray( this.elements );
  3602. }
  3603. copy( m ) {
  3604. const te = this.elements;
  3605. const me = m.elements;
  3606. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3607. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3608. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3609. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3610. return this;
  3611. }
  3612. copyPosition( m ) {
  3613. const te = this.elements, me = m.elements;
  3614. te[ 12 ] = me[ 12 ];
  3615. te[ 13 ] = me[ 13 ];
  3616. te[ 14 ] = me[ 14 ];
  3617. return this;
  3618. }
  3619. setFromMatrix3( m ) {
  3620. const me = m.elements;
  3621. this.set(
  3622. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3623. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3624. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3625. 0, 0, 0, 1
  3626. );
  3627. return this;
  3628. }
  3629. extractBasis( xAxis, yAxis, zAxis ) {
  3630. xAxis.setFromMatrixColumn( this, 0 );
  3631. yAxis.setFromMatrixColumn( this, 1 );
  3632. zAxis.setFromMatrixColumn( this, 2 );
  3633. return this;
  3634. }
  3635. makeBasis( xAxis, yAxis, zAxis ) {
  3636. this.set(
  3637. xAxis.x, yAxis.x, zAxis.x, 0,
  3638. xAxis.y, yAxis.y, zAxis.y, 0,
  3639. xAxis.z, yAxis.z, zAxis.z, 0,
  3640. 0, 0, 0, 1
  3641. );
  3642. return this;
  3643. }
  3644. extractRotation( m ) {
  3645. // this method does not support reflection matrices
  3646. const te = this.elements;
  3647. const me = m.elements;
  3648. const scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length();
  3649. const scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length();
  3650. const scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length();
  3651. te[ 0 ] = me[ 0 ] * scaleX;
  3652. te[ 1 ] = me[ 1 ] * scaleX;
  3653. te[ 2 ] = me[ 2 ] * scaleX;
  3654. te[ 3 ] = 0;
  3655. te[ 4 ] = me[ 4 ] * scaleY;
  3656. te[ 5 ] = me[ 5 ] * scaleY;
  3657. te[ 6 ] = me[ 6 ] * scaleY;
  3658. te[ 7 ] = 0;
  3659. te[ 8 ] = me[ 8 ] * scaleZ;
  3660. te[ 9 ] = me[ 9 ] * scaleZ;
  3661. te[ 10 ] = me[ 10 ] * scaleZ;
  3662. te[ 11 ] = 0;
  3663. te[ 12 ] = 0;
  3664. te[ 13 ] = 0;
  3665. te[ 14 ] = 0;
  3666. te[ 15 ] = 1;
  3667. return this;
  3668. }
  3669. makeRotationFromEuler( euler ) {
  3670. const te = this.elements;
  3671. const x = euler.x, y = euler.y, z = euler.z;
  3672. const a = Math.cos( x ), b = Math.sin( x );
  3673. const c = Math.cos( y ), d = Math.sin( y );
  3674. const e = Math.cos( z ), f = Math.sin( z );
  3675. if ( euler.order === 'XYZ' ) {
  3676. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3677. te[ 0 ] = c * e;
  3678. te[ 4 ] = - c * f;
  3679. te[ 8 ] = d;
  3680. te[ 1 ] = af + be * d;
  3681. te[ 5 ] = ae - bf * d;
  3682. te[ 9 ] = - b * c;
  3683. te[ 2 ] = bf - ae * d;
  3684. te[ 6 ] = be + af * d;
  3685. te[ 10 ] = a * c;
  3686. } else if ( euler.order === 'YXZ' ) {
  3687. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3688. te[ 0 ] = ce + df * b;
  3689. te[ 4 ] = de * b - cf;
  3690. te[ 8 ] = a * d;
  3691. te[ 1 ] = a * f;
  3692. te[ 5 ] = a * e;
  3693. te[ 9 ] = - b;
  3694. te[ 2 ] = cf * b - de;
  3695. te[ 6 ] = df + ce * b;
  3696. te[ 10 ] = a * c;
  3697. } else if ( euler.order === 'ZXY' ) {
  3698. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3699. te[ 0 ] = ce - df * b;
  3700. te[ 4 ] = - a * f;
  3701. te[ 8 ] = de + cf * b;
  3702. te[ 1 ] = cf + de * b;
  3703. te[ 5 ] = a * e;
  3704. te[ 9 ] = df - ce * b;
  3705. te[ 2 ] = - a * d;
  3706. te[ 6 ] = b;
  3707. te[ 10 ] = a * c;
  3708. } else if ( euler.order === 'ZYX' ) {
  3709. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3710. te[ 0 ] = c * e;
  3711. te[ 4 ] = be * d - af;
  3712. te[ 8 ] = ae * d + bf;
  3713. te[ 1 ] = c * f;
  3714. te[ 5 ] = bf * d + ae;
  3715. te[ 9 ] = af * d - be;
  3716. te[ 2 ] = - d;
  3717. te[ 6 ] = b * c;
  3718. te[ 10 ] = a * c;
  3719. } else if ( euler.order === 'YZX' ) {
  3720. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3721. te[ 0 ] = c * e;
  3722. te[ 4 ] = bd - ac * f;
  3723. te[ 8 ] = bc * f + ad;
  3724. te[ 1 ] = f;
  3725. te[ 5 ] = a * e;
  3726. te[ 9 ] = - b * e;
  3727. te[ 2 ] = - d * e;
  3728. te[ 6 ] = ad * f + bc;
  3729. te[ 10 ] = ac - bd * f;
  3730. } else if ( euler.order === 'XZY' ) {
  3731. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3732. te[ 0 ] = c * e;
  3733. te[ 4 ] = - f;
  3734. te[ 8 ] = d * e;
  3735. te[ 1 ] = ac * f + bd;
  3736. te[ 5 ] = a * e;
  3737. te[ 9 ] = ad * f - bc;
  3738. te[ 2 ] = bc * f - ad;
  3739. te[ 6 ] = b * e;
  3740. te[ 10 ] = bd * f + ac;
  3741. }
  3742. // bottom row
  3743. te[ 3 ] = 0;
  3744. te[ 7 ] = 0;
  3745. te[ 11 ] = 0;
  3746. // last column
  3747. te[ 12 ] = 0;
  3748. te[ 13 ] = 0;
  3749. te[ 14 ] = 0;
  3750. te[ 15 ] = 1;
  3751. return this;
  3752. }
  3753. makeRotationFromQuaternion( q ) {
  3754. return this.compose( _zero, q, _one );
  3755. }
  3756. lookAt( eye, target, up ) {
  3757. const te = this.elements;
  3758. _z.subVectors( eye, target );
  3759. if ( _z.lengthSq() === 0 ) {
  3760. // eye and target are in the same position
  3761. _z.z = 1;
  3762. }
  3763. _z.normalize();
  3764. _x.crossVectors( up, _z );
  3765. if ( _x.lengthSq() === 0 ) {
  3766. // up and z are parallel
  3767. if ( Math.abs( up.z ) === 1 ) {
  3768. _z.x += 0.0001;
  3769. } else {
  3770. _z.z += 0.0001;
  3771. }
  3772. _z.normalize();
  3773. _x.crossVectors( up, _z );
  3774. }
  3775. _x.normalize();
  3776. _y.crossVectors( _z, _x );
  3777. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3778. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3779. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3780. return this;
  3781. }
  3782. multiply( m ) {
  3783. return this.multiplyMatrices( this, m );
  3784. }
  3785. premultiply( m ) {
  3786. return this.multiplyMatrices( m, this );
  3787. }
  3788. multiplyMatrices( a, b ) {
  3789. const ae = a.elements;
  3790. const be = b.elements;
  3791. const te = this.elements;
  3792. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3793. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3794. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3795. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3796. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3797. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3798. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3799. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3800. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3801. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3802. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3803. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3804. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3805. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3806. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3807. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3808. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3809. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3810. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3811. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3812. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3813. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3814. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3815. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3816. return this;
  3817. }
  3818. multiplyScalar( s ) {
  3819. const te = this.elements;
  3820. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3821. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3822. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3823. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3824. return this;
  3825. }
  3826. determinant() {
  3827. const te = this.elements;
  3828. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3829. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3830. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3831. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3832. //TODO: make this more efficient
  3833. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3834. return (
  3835. n41 * (
  3836. + n14 * n23 * n32
  3837. - n13 * n24 * n32
  3838. - n14 * n22 * n33
  3839. + n12 * n24 * n33
  3840. + n13 * n22 * n34
  3841. - n12 * n23 * n34
  3842. ) +
  3843. n42 * (
  3844. + n11 * n23 * n34
  3845. - n11 * n24 * n33
  3846. + n14 * n21 * n33
  3847. - n13 * n21 * n34
  3848. + n13 * n24 * n31
  3849. - n14 * n23 * n31
  3850. ) +
  3851. n43 * (
  3852. + n11 * n24 * n32
  3853. - n11 * n22 * n34
  3854. - n14 * n21 * n32
  3855. + n12 * n21 * n34
  3856. + n14 * n22 * n31
  3857. - n12 * n24 * n31
  3858. ) +
  3859. n44 * (
  3860. - n13 * n22 * n31
  3861. - n11 * n23 * n32
  3862. + n11 * n22 * n33
  3863. + n13 * n21 * n32
  3864. - n12 * n21 * n33
  3865. + n12 * n23 * n31
  3866. )
  3867. );
  3868. }
  3869. transpose() {
  3870. const te = this.elements;
  3871. let tmp;
  3872. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3873. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3874. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3875. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3876. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3877. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3878. return this;
  3879. }
  3880. setPosition( x, y, z ) {
  3881. const te = this.elements;
  3882. if ( x.isVector3 ) {
  3883. te[ 12 ] = x.x;
  3884. te[ 13 ] = x.y;
  3885. te[ 14 ] = x.z;
  3886. } else {
  3887. te[ 12 ] = x;
  3888. te[ 13 ] = y;
  3889. te[ 14 ] = z;
  3890. }
  3891. return this;
  3892. }
  3893. invert() {
  3894. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3895. const te = this.elements,
  3896. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3897. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3898. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3899. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3900. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3901. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3902. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3903. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3904. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3905. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3906. const detInv = 1 / det;
  3907. te[ 0 ] = t11 * detInv;
  3908. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3909. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3910. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3911. te[ 4 ] = t12 * detInv;
  3912. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3913. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3914. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3915. te[ 8 ] = t13 * detInv;
  3916. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3917. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3918. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3919. te[ 12 ] = t14 * detInv;
  3920. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3921. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3922. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3923. return this;
  3924. }
  3925. scale( v ) {
  3926. const te = this.elements;
  3927. const x = v.x, y = v.y, z = v.z;
  3928. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3929. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3930. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3931. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3932. return this;
  3933. }
  3934. getMaxScaleOnAxis() {
  3935. const te = this.elements;
  3936. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3937. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3938. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3939. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3940. }
  3941. makeTranslation( x, y, z ) {
  3942. if ( x.isVector3 ) {
  3943. this.set(
  3944. 1, 0, 0, x.x,
  3945. 0, 1, 0, x.y,
  3946. 0, 0, 1, x.z,
  3947. 0, 0, 0, 1
  3948. );
  3949. } else {
  3950. this.set(
  3951. 1, 0, 0, x,
  3952. 0, 1, 0, y,
  3953. 0, 0, 1, z,
  3954. 0, 0, 0, 1
  3955. );
  3956. }
  3957. return this;
  3958. }
  3959. makeRotationX( theta ) {
  3960. const c = Math.cos( theta ), s = Math.sin( theta );
  3961. this.set(
  3962. 1, 0, 0, 0,
  3963. 0, c, - s, 0,
  3964. 0, s, c, 0,
  3965. 0, 0, 0, 1
  3966. );
  3967. return this;
  3968. }
  3969. makeRotationY( theta ) {
  3970. const c = Math.cos( theta ), s = Math.sin( theta );
  3971. this.set(
  3972. c, 0, s, 0,
  3973. 0, 1, 0, 0,
  3974. - s, 0, c, 0,
  3975. 0, 0, 0, 1
  3976. );
  3977. return this;
  3978. }
  3979. makeRotationZ( theta ) {
  3980. const c = Math.cos( theta ), s = Math.sin( theta );
  3981. this.set(
  3982. c, - s, 0, 0,
  3983. s, c, 0, 0,
  3984. 0, 0, 1, 0,
  3985. 0, 0, 0, 1
  3986. );
  3987. return this;
  3988. }
  3989. makeRotationAxis( axis, angle ) {
  3990. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3991. const c = Math.cos( angle );
  3992. const s = Math.sin( angle );
  3993. const t = 1 - c;
  3994. const x = axis.x, y = axis.y, z = axis.z;
  3995. const tx = t * x, ty = t * y;
  3996. this.set(
  3997. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3998. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3999. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  4000. 0, 0, 0, 1
  4001. );
  4002. return this;
  4003. }
  4004. makeScale( x, y, z ) {
  4005. this.set(
  4006. x, 0, 0, 0,
  4007. 0, y, 0, 0,
  4008. 0, 0, z, 0,
  4009. 0, 0, 0, 1
  4010. );
  4011. return this;
  4012. }
  4013. makeShear( xy, xz, yx, yz, zx, zy ) {
  4014. this.set(
  4015. 1, yx, zx, 0,
  4016. xy, 1, zy, 0,
  4017. xz, yz, 1, 0,
  4018. 0, 0, 0, 1
  4019. );
  4020. return this;
  4021. }
  4022. compose( position, quaternion, scale ) {
  4023. const te = this.elements;
  4024. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  4025. const x2 = x + x, y2 = y + y, z2 = z + z;
  4026. const xx = x * x2, xy = x * y2, xz = x * z2;
  4027. const yy = y * y2, yz = y * z2, zz = z * z2;
  4028. const wx = w * x2, wy = w * y2, wz = w * z2;
  4029. const sx = scale.x, sy = scale.y, sz = scale.z;
  4030. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  4031. te[ 1 ] = ( xy + wz ) * sx;
  4032. te[ 2 ] = ( xz - wy ) * sx;
  4033. te[ 3 ] = 0;
  4034. te[ 4 ] = ( xy - wz ) * sy;
  4035. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  4036. te[ 6 ] = ( yz + wx ) * sy;
  4037. te[ 7 ] = 0;
  4038. te[ 8 ] = ( xz + wy ) * sz;
  4039. te[ 9 ] = ( yz - wx ) * sz;
  4040. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  4041. te[ 11 ] = 0;
  4042. te[ 12 ] = position.x;
  4043. te[ 13 ] = position.y;
  4044. te[ 14 ] = position.z;
  4045. te[ 15 ] = 1;
  4046. return this;
  4047. }
  4048. decompose( position, quaternion, scale ) {
  4049. const te = this.elements;
  4050. let sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  4051. const sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  4052. const sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  4053. // if determine is negative, we need to invert one scale
  4054. const det = this.determinant();
  4055. if ( det < 0 ) sx = - sx;
  4056. position.x = te[ 12 ];
  4057. position.y = te[ 13 ];
  4058. position.z = te[ 14 ];
  4059. // scale the rotation part
  4060. _m1$2.copy( this );
  4061. const invSX = 1 / sx;
  4062. const invSY = 1 / sy;
  4063. const invSZ = 1 / sz;
  4064. _m1$2.elements[ 0 ] *= invSX;
  4065. _m1$2.elements[ 1 ] *= invSX;
  4066. _m1$2.elements[ 2 ] *= invSX;
  4067. _m1$2.elements[ 4 ] *= invSY;
  4068. _m1$2.elements[ 5 ] *= invSY;
  4069. _m1$2.elements[ 6 ] *= invSY;
  4070. _m1$2.elements[ 8 ] *= invSZ;
  4071. _m1$2.elements[ 9 ] *= invSZ;
  4072. _m1$2.elements[ 10 ] *= invSZ;
  4073. quaternion.setFromRotationMatrix( _m1$2 );
  4074. scale.x = sx;
  4075. scale.y = sy;
  4076. scale.z = sz;
  4077. return this;
  4078. }
  4079. makePerspective( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4080. const te = this.elements;
  4081. const x = 2 * near / ( right - left );
  4082. const y = 2 * near / ( top - bottom );
  4083. const a = ( right + left ) / ( right - left );
  4084. const b = ( top + bottom ) / ( top - bottom );
  4085. let c, d;
  4086. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4087. c = - ( far + near ) / ( far - near );
  4088. d = ( - 2 * far * near ) / ( far - near );
  4089. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4090. c = - far / ( far - near );
  4091. d = ( - far * near ) / ( far - near );
  4092. } else {
  4093. throw new Error( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem );
  4094. }
  4095. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  4096. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  4097. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  4098. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  4099. return this;
  4100. }
  4101. makeOrthographic( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4102. const te = this.elements;
  4103. const w = 1.0 / ( right - left );
  4104. const h = 1.0 / ( top - bottom );
  4105. const p = 1.0 / ( far - near );
  4106. const x = ( right + left ) * w;
  4107. const y = ( top + bottom ) * h;
  4108. let z, zInv;
  4109. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4110. z = ( far + near ) * p;
  4111. zInv = - 2 * p;
  4112. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4113. z = near * p;
  4114. zInv = - 1 * p;
  4115. } else {
  4116. throw new Error( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem );
  4117. }
  4118. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  4119. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  4120. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = zInv; te[ 14 ] = - z;
  4121. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  4122. return this;
  4123. }
  4124. equals( matrix ) {
  4125. const te = this.elements;
  4126. const me = matrix.elements;
  4127. for ( let i = 0; i < 16; i ++ ) {
  4128. if ( te[ i ] !== me[ i ] ) return false;
  4129. }
  4130. return true;
  4131. }
  4132. fromArray( array, offset = 0 ) {
  4133. for ( let i = 0; i < 16; i ++ ) {
  4134. this.elements[ i ] = array[ i + offset ];
  4135. }
  4136. return this;
  4137. }
  4138. toArray( array = [], offset = 0 ) {
  4139. const te = this.elements;
  4140. array[ offset ] = te[ 0 ];
  4141. array[ offset + 1 ] = te[ 1 ];
  4142. array[ offset + 2 ] = te[ 2 ];
  4143. array[ offset + 3 ] = te[ 3 ];
  4144. array[ offset + 4 ] = te[ 4 ];
  4145. array[ offset + 5 ] = te[ 5 ];
  4146. array[ offset + 6 ] = te[ 6 ];
  4147. array[ offset + 7 ] = te[ 7 ];
  4148. array[ offset + 8 ] = te[ 8 ];
  4149. array[ offset + 9 ] = te[ 9 ];
  4150. array[ offset + 10 ] = te[ 10 ];
  4151. array[ offset + 11 ] = te[ 11 ];
  4152. array[ offset + 12 ] = te[ 12 ];
  4153. array[ offset + 13 ] = te[ 13 ];
  4154. array[ offset + 14 ] = te[ 14 ];
  4155. array[ offset + 15 ] = te[ 15 ];
  4156. return array;
  4157. }
  4158. }
  4159. const _v1$5 = /*@__PURE__*/ new Vector3();
  4160. const _m1$2 = /*@__PURE__*/ new Matrix4();
  4161. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  4162. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  4163. const _x = /*@__PURE__*/ new Vector3();
  4164. const _y = /*@__PURE__*/ new Vector3();
  4165. const _z = /*@__PURE__*/ new Vector3();
  4166. const _matrix$2 = /*@__PURE__*/ new Matrix4();
  4167. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  4168. class Euler {
  4169. constructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) {
  4170. this.isEuler = true;
  4171. this._x = x;
  4172. this._y = y;
  4173. this._z = z;
  4174. this._order = order;
  4175. }
  4176. get x() {
  4177. return this._x;
  4178. }
  4179. set x( value ) {
  4180. this._x = value;
  4181. this._onChangeCallback();
  4182. }
  4183. get y() {
  4184. return this._y;
  4185. }
  4186. set y( value ) {
  4187. this._y = value;
  4188. this._onChangeCallback();
  4189. }
  4190. get z() {
  4191. return this._z;
  4192. }
  4193. set z( value ) {
  4194. this._z = value;
  4195. this._onChangeCallback();
  4196. }
  4197. get order() {
  4198. return this._order;
  4199. }
  4200. set order( value ) {
  4201. this._order = value;
  4202. this._onChangeCallback();
  4203. }
  4204. set( x, y, z, order = this._order ) {
  4205. this._x = x;
  4206. this._y = y;
  4207. this._z = z;
  4208. this._order = order;
  4209. this._onChangeCallback();
  4210. return this;
  4211. }
  4212. clone() {
  4213. return new this.constructor( this._x, this._y, this._z, this._order );
  4214. }
  4215. copy( euler ) {
  4216. this._x = euler._x;
  4217. this._y = euler._y;
  4218. this._z = euler._z;
  4219. this._order = euler._order;
  4220. this._onChangeCallback();
  4221. return this;
  4222. }
  4223. setFromRotationMatrix( m, order = this._order, update = true ) {
  4224. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4225. const te = m.elements;
  4226. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4227. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4228. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4229. switch ( order ) {
  4230. case 'XYZ':
  4231. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4232. if ( Math.abs( m13 ) < 0.9999999 ) {
  4233. this._x = Math.atan2( - m23, m33 );
  4234. this._z = Math.atan2( - m12, m11 );
  4235. } else {
  4236. this._x = Math.atan2( m32, m22 );
  4237. this._z = 0;
  4238. }
  4239. break;
  4240. case 'YXZ':
  4241. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4242. if ( Math.abs( m23 ) < 0.9999999 ) {
  4243. this._y = Math.atan2( m13, m33 );
  4244. this._z = Math.atan2( m21, m22 );
  4245. } else {
  4246. this._y = Math.atan2( - m31, m11 );
  4247. this._z = 0;
  4248. }
  4249. break;
  4250. case 'ZXY':
  4251. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4252. if ( Math.abs( m32 ) < 0.9999999 ) {
  4253. this._y = Math.atan2( - m31, m33 );
  4254. this._z = Math.atan2( - m12, m22 );
  4255. } else {
  4256. this._y = 0;
  4257. this._z = Math.atan2( m21, m11 );
  4258. }
  4259. break;
  4260. case 'ZYX':
  4261. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4262. if ( Math.abs( m31 ) < 0.9999999 ) {
  4263. this._x = Math.atan2( m32, m33 );
  4264. this._z = Math.atan2( m21, m11 );
  4265. } else {
  4266. this._x = 0;
  4267. this._z = Math.atan2( - m12, m22 );
  4268. }
  4269. break;
  4270. case 'YZX':
  4271. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4272. if ( Math.abs( m21 ) < 0.9999999 ) {
  4273. this._x = Math.atan2( - m23, m22 );
  4274. this._y = Math.atan2( - m31, m11 );
  4275. } else {
  4276. this._x = 0;
  4277. this._y = Math.atan2( m13, m33 );
  4278. }
  4279. break;
  4280. case 'XZY':
  4281. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4282. if ( Math.abs( m12 ) < 0.9999999 ) {
  4283. this._x = Math.atan2( m32, m22 );
  4284. this._y = Math.atan2( m13, m11 );
  4285. } else {
  4286. this._x = Math.atan2( - m23, m33 );
  4287. this._y = 0;
  4288. }
  4289. break;
  4290. default:
  4291. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  4292. }
  4293. this._order = order;
  4294. if ( update === true ) this._onChangeCallback();
  4295. return this;
  4296. }
  4297. setFromQuaternion( q, order, update ) {
  4298. _matrix$2.makeRotationFromQuaternion( q );
  4299. return this.setFromRotationMatrix( _matrix$2, order, update );
  4300. }
  4301. setFromVector3( v, order = this._order ) {
  4302. return this.set( v.x, v.y, v.z, order );
  4303. }
  4304. reorder( newOrder ) {
  4305. // WARNING: this discards revolution information -bhouston
  4306. _quaternion$3.setFromEuler( this );
  4307. return this.setFromQuaternion( _quaternion$3, newOrder );
  4308. }
  4309. equals( euler ) {
  4310. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4311. }
  4312. fromArray( array ) {
  4313. this._x = array[ 0 ];
  4314. this._y = array[ 1 ];
  4315. this._z = array[ 2 ];
  4316. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4317. this._onChangeCallback();
  4318. return this;
  4319. }
  4320. toArray( array = [], offset = 0 ) {
  4321. array[ offset ] = this._x;
  4322. array[ offset + 1 ] = this._y;
  4323. array[ offset + 2 ] = this._z;
  4324. array[ offset + 3 ] = this._order;
  4325. return array;
  4326. }
  4327. _onChange( callback ) {
  4328. this._onChangeCallback = callback;
  4329. return this;
  4330. }
  4331. _onChangeCallback() {}
  4332. *[ Symbol.iterator ]() {
  4333. yield this._x;
  4334. yield this._y;
  4335. yield this._z;
  4336. yield this._order;
  4337. }
  4338. }
  4339. Euler.DEFAULT_ORDER = 'XYZ';
  4340. class Layers {
  4341. constructor() {
  4342. this.mask = 1 | 0;
  4343. }
  4344. set( channel ) {
  4345. this.mask = ( 1 << channel | 0 ) >>> 0;
  4346. }
  4347. enable( channel ) {
  4348. this.mask |= 1 << channel | 0;
  4349. }
  4350. enableAll() {
  4351. this.mask = 0xffffffff | 0;
  4352. }
  4353. toggle( channel ) {
  4354. this.mask ^= 1 << channel | 0;
  4355. }
  4356. disable( channel ) {
  4357. this.mask &= ~ ( 1 << channel | 0 );
  4358. }
  4359. disableAll() {
  4360. this.mask = 0;
  4361. }
  4362. test( layers ) {
  4363. return ( this.mask & layers.mask ) !== 0;
  4364. }
  4365. isEnabled( channel ) {
  4366. return ( this.mask & ( 1 << channel | 0 ) ) !== 0;
  4367. }
  4368. }
  4369. let _object3DId = 0;
  4370. const _v1$4 = /*@__PURE__*/ new Vector3();
  4371. const _q1 = /*@__PURE__*/ new Quaternion();
  4372. const _m1$1 = /*@__PURE__*/ new Matrix4();
  4373. const _target = /*@__PURE__*/ new Vector3();
  4374. const _position$3 = /*@__PURE__*/ new Vector3();
  4375. const _scale$2 = /*@__PURE__*/ new Vector3();
  4376. const _quaternion$2 = /*@__PURE__*/ new Quaternion();
  4377. const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );
  4378. const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4379. const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
  4380. const _addedEvent = { type: 'added' };
  4381. const _removedEvent = { type: 'removed' };
  4382. const _childaddedEvent = { type: 'childadded', child: null };
  4383. const _childremovedEvent = { type: 'childremoved', child: null };
  4384. class Object3D extends EventDispatcher {
  4385. constructor() {
  4386. super();
  4387. this.isObject3D = true;
  4388. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  4389. this.uuid = generateUUID();
  4390. this.name = '';
  4391. this.type = 'Object3D';
  4392. this.parent = null;
  4393. this.children = [];
  4394. this.up = Object3D.DEFAULT_UP.clone();
  4395. const position = new Vector3();
  4396. const rotation = new Euler();
  4397. const quaternion = new Quaternion();
  4398. const scale = new Vector3( 1, 1, 1 );
  4399. function onRotationChange() {
  4400. quaternion.setFromEuler( rotation, false );
  4401. }
  4402. function onQuaternionChange() {
  4403. rotation.setFromQuaternion( quaternion, undefined, false );
  4404. }
  4405. rotation._onChange( onRotationChange );
  4406. quaternion._onChange( onQuaternionChange );
  4407. Object.defineProperties( this, {
  4408. position: {
  4409. configurable: true,
  4410. enumerable: true,
  4411. value: position
  4412. },
  4413. rotation: {
  4414. configurable: true,
  4415. enumerable: true,
  4416. value: rotation
  4417. },
  4418. quaternion: {
  4419. configurable: true,
  4420. enumerable: true,
  4421. value: quaternion
  4422. },
  4423. scale: {
  4424. configurable: true,
  4425. enumerable: true,
  4426. value: scale
  4427. },
  4428. modelViewMatrix: {
  4429. value: new Matrix4()
  4430. },
  4431. normalMatrix: {
  4432. value: new Matrix3()
  4433. }
  4434. } );
  4435. this.matrix = new Matrix4();
  4436. this.matrixWorld = new Matrix4();
  4437. this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
  4438. this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
  4439. this.matrixWorldNeedsUpdate = false;
  4440. this.layers = new Layers();
  4441. this.visible = true;
  4442. this.castShadow = false;
  4443. this.receiveShadow = false;
  4444. this.frustumCulled = true;
  4445. this.renderOrder = 0;
  4446. this.animations = [];
  4447. this.userData = {};
  4448. }
  4449. onBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4450. onAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4451. onBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4452. onAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4453. applyMatrix4( matrix ) {
  4454. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4455. this.matrix.premultiply( matrix );
  4456. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4457. }
  4458. applyQuaternion( q ) {
  4459. this.quaternion.premultiply( q );
  4460. return this;
  4461. }
  4462. setRotationFromAxisAngle( axis, angle ) {
  4463. // assumes axis is normalized
  4464. this.quaternion.setFromAxisAngle( axis, angle );
  4465. }
  4466. setRotationFromEuler( euler ) {
  4467. this.quaternion.setFromEuler( euler, true );
  4468. }
  4469. setRotationFromMatrix( m ) {
  4470. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4471. this.quaternion.setFromRotationMatrix( m );
  4472. }
  4473. setRotationFromQuaternion( q ) {
  4474. // assumes q is normalized
  4475. this.quaternion.copy( q );
  4476. }
  4477. rotateOnAxis( axis, angle ) {
  4478. // rotate object on axis in object space
  4479. // axis is assumed to be normalized
  4480. _q1.setFromAxisAngle( axis, angle );
  4481. this.quaternion.multiply( _q1 );
  4482. return this;
  4483. }
  4484. rotateOnWorldAxis( axis, angle ) {
  4485. // rotate object on axis in world space
  4486. // axis is assumed to be normalized
  4487. // method assumes no rotated parent
  4488. _q1.setFromAxisAngle( axis, angle );
  4489. this.quaternion.premultiply( _q1 );
  4490. return this;
  4491. }
  4492. rotateX( angle ) {
  4493. return this.rotateOnAxis( _xAxis, angle );
  4494. }
  4495. rotateY( angle ) {
  4496. return this.rotateOnAxis( _yAxis, angle );
  4497. }
  4498. rotateZ( angle ) {
  4499. return this.rotateOnAxis( _zAxis, angle );
  4500. }
  4501. translateOnAxis( axis, distance ) {
  4502. // translate object by distance along axis in object space
  4503. // axis is assumed to be normalized
  4504. _v1$4.copy( axis ).applyQuaternion( this.quaternion );
  4505. this.position.add( _v1$4.multiplyScalar( distance ) );
  4506. return this;
  4507. }
  4508. translateX( distance ) {
  4509. return this.translateOnAxis( _xAxis, distance );
  4510. }
  4511. translateY( distance ) {
  4512. return this.translateOnAxis( _yAxis, distance );
  4513. }
  4514. translateZ( distance ) {
  4515. return this.translateOnAxis( _zAxis, distance );
  4516. }
  4517. localToWorld( vector ) {
  4518. this.updateWorldMatrix( true, false );
  4519. return vector.applyMatrix4( this.matrixWorld );
  4520. }
  4521. worldToLocal( vector ) {
  4522. this.updateWorldMatrix( true, false );
  4523. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  4524. }
  4525. lookAt( x, y, z ) {
  4526. // This method does not support objects having non-uniformly-scaled parent(s)
  4527. if ( x.isVector3 ) {
  4528. _target.copy( x );
  4529. } else {
  4530. _target.set( x, y, z );
  4531. }
  4532. const parent = this.parent;
  4533. this.updateWorldMatrix( true, false );
  4534. _position$3.setFromMatrixPosition( this.matrixWorld );
  4535. if ( this.isCamera || this.isLight ) {
  4536. _m1$1.lookAt( _position$3, _target, this.up );
  4537. } else {
  4538. _m1$1.lookAt( _target, _position$3, this.up );
  4539. }
  4540. this.quaternion.setFromRotationMatrix( _m1$1 );
  4541. if ( parent ) {
  4542. _m1$1.extractRotation( parent.matrixWorld );
  4543. _q1.setFromRotationMatrix( _m1$1 );
  4544. this.quaternion.premultiply( _q1.invert() );
  4545. }
  4546. }
  4547. add( object ) {
  4548. if ( arguments.length > 1 ) {
  4549. for ( let i = 0; i < arguments.length; i ++ ) {
  4550. this.add( arguments[ i ] );
  4551. }
  4552. return this;
  4553. }
  4554. if ( object === this ) {
  4555. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4556. return this;
  4557. }
  4558. if ( object && object.isObject3D ) {
  4559. object.removeFromParent();
  4560. object.parent = this;
  4561. this.children.push( object );
  4562. object.dispatchEvent( _addedEvent );
  4563. _childaddedEvent.child = object;
  4564. this.dispatchEvent( _childaddedEvent );
  4565. _childaddedEvent.child = null;
  4566. } else {
  4567. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4568. }
  4569. return this;
  4570. }
  4571. remove( object ) {
  4572. if ( arguments.length > 1 ) {
  4573. for ( let i = 0; i < arguments.length; i ++ ) {
  4574. this.remove( arguments[ i ] );
  4575. }
  4576. return this;
  4577. }
  4578. const index = this.children.indexOf( object );
  4579. if ( index !== - 1 ) {
  4580. object.parent = null;
  4581. this.children.splice( index, 1 );
  4582. object.dispatchEvent( _removedEvent );
  4583. _childremovedEvent.child = object;
  4584. this.dispatchEvent( _childremovedEvent );
  4585. _childremovedEvent.child = null;
  4586. }
  4587. return this;
  4588. }
  4589. removeFromParent() {
  4590. const parent = this.parent;
  4591. if ( parent !== null ) {
  4592. parent.remove( this );
  4593. }
  4594. return this;
  4595. }
  4596. clear() {
  4597. return this.remove( ... this.children );
  4598. }
  4599. attach( object ) {
  4600. // adds object as a child of this, while maintaining the object's world transform
  4601. // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
  4602. this.updateWorldMatrix( true, false );
  4603. _m1$1.copy( this.matrixWorld ).invert();
  4604. if ( object.parent !== null ) {
  4605. object.parent.updateWorldMatrix( true, false );
  4606. _m1$1.multiply( object.parent.matrixWorld );
  4607. }
  4608. object.applyMatrix4( _m1$1 );
  4609. object.removeFromParent();
  4610. object.parent = this;
  4611. this.children.push( object );
  4612. object.updateWorldMatrix( false, true );
  4613. object.dispatchEvent( _addedEvent );
  4614. _childaddedEvent.child = object;
  4615. this.dispatchEvent( _childaddedEvent );
  4616. _childaddedEvent.child = null;
  4617. return this;
  4618. }
  4619. getObjectById( id ) {
  4620. return this.getObjectByProperty( 'id', id );
  4621. }
  4622. getObjectByName( name ) {
  4623. return this.getObjectByProperty( 'name', name );
  4624. }
  4625. getObjectByProperty( name, value ) {
  4626. if ( this[ name ] === value ) return this;
  4627. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4628. const child = this.children[ i ];
  4629. const object = child.getObjectByProperty( name, value );
  4630. if ( object !== undefined ) {
  4631. return object;
  4632. }
  4633. }
  4634. return undefined;
  4635. }
  4636. getObjectsByProperty( name, value, result = [] ) {
  4637. if ( this[ name ] === value ) result.push( this );
  4638. const children = this.children;
  4639. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4640. children[ i ].getObjectsByProperty( name, value, result );
  4641. }
  4642. return result;
  4643. }
  4644. getWorldPosition( target ) {
  4645. this.updateWorldMatrix( true, false );
  4646. return target.setFromMatrixPosition( this.matrixWorld );
  4647. }
  4648. getWorldQuaternion( target ) {
  4649. this.updateWorldMatrix( true, false );
  4650. this.matrixWorld.decompose( _position$3, target, _scale$2 );
  4651. return target;
  4652. }
  4653. getWorldScale( target ) {
  4654. this.updateWorldMatrix( true, false );
  4655. this.matrixWorld.decompose( _position$3, _quaternion$2, target );
  4656. return target;
  4657. }
  4658. getWorldDirection( target ) {
  4659. this.updateWorldMatrix( true, false );
  4660. const e = this.matrixWorld.elements;
  4661. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4662. }
  4663. raycast( /* raycaster, intersects */ ) {}
  4664. traverse( callback ) {
  4665. callback( this );
  4666. const children = this.children;
  4667. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4668. children[ i ].traverse( callback );
  4669. }
  4670. }
  4671. traverseVisible( callback ) {
  4672. if ( this.visible === false ) return;
  4673. callback( this );
  4674. const children = this.children;
  4675. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4676. children[ i ].traverseVisible( callback );
  4677. }
  4678. }
  4679. traverseAncestors( callback ) {
  4680. const parent = this.parent;
  4681. if ( parent !== null ) {
  4682. callback( parent );
  4683. parent.traverseAncestors( callback );
  4684. }
  4685. }
  4686. updateMatrix() {
  4687. this.matrix.compose( this.position, this.quaternion, this.scale );
  4688. this.matrixWorldNeedsUpdate = true;
  4689. }
  4690. updateMatrixWorld( force ) {
  4691. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4692. if ( this.matrixWorldNeedsUpdate || force ) {
  4693. if ( this.matrixWorldAutoUpdate === true ) {
  4694. if ( this.parent === null ) {
  4695. this.matrixWorld.copy( this.matrix );
  4696. } else {
  4697. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4698. }
  4699. }
  4700. this.matrixWorldNeedsUpdate = false;
  4701. force = true;
  4702. }
  4703. // make sure descendants are updated if required
  4704. const children = this.children;
  4705. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4706. const child = children[ i ];
  4707. child.updateMatrixWorld( force );
  4708. }
  4709. }
  4710. updateWorldMatrix( updateParents, updateChildren ) {
  4711. const parent = this.parent;
  4712. if ( updateParents === true && parent !== null ) {
  4713. parent.updateWorldMatrix( true, false );
  4714. }
  4715. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4716. if ( this.matrixWorldAutoUpdate === true ) {
  4717. if ( this.parent === null ) {
  4718. this.matrixWorld.copy( this.matrix );
  4719. } else {
  4720. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4721. }
  4722. }
  4723. // make sure descendants are updated
  4724. if ( updateChildren === true ) {
  4725. const children = this.children;
  4726. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4727. const child = children[ i ];
  4728. child.updateWorldMatrix( false, true );
  4729. }
  4730. }
  4731. }
  4732. toJSON( meta ) {
  4733. // meta is a string when called from JSON.stringify
  4734. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4735. const output = {};
  4736. // meta is a hash used to collect geometries, materials.
  4737. // not providing it implies that this is the root object
  4738. // being serialized.
  4739. if ( isRootObject ) {
  4740. // initialize meta obj
  4741. meta = {
  4742. geometries: {},
  4743. materials: {},
  4744. textures: {},
  4745. images: {},
  4746. shapes: {},
  4747. skeletons: {},
  4748. animations: {},
  4749. nodes: {}
  4750. };
  4751. output.metadata = {
  4752. version: 4.6,
  4753. type: 'Object',
  4754. generator: 'Object3D.toJSON'
  4755. };
  4756. }
  4757. // standard Object3D serialization
  4758. const object = {};
  4759. object.uuid = this.uuid;
  4760. object.type = this.type;
  4761. if ( this.name !== '' ) object.name = this.name;
  4762. if ( this.castShadow === true ) object.castShadow = true;
  4763. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4764. if ( this.visible === false ) object.visible = false;
  4765. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4766. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4767. if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;
  4768. object.layers = this.layers.mask;
  4769. object.matrix = this.matrix.toArray();
  4770. object.up = this.up.toArray();
  4771. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4772. // object specific properties
  4773. if ( this.isInstancedMesh ) {
  4774. object.type = 'InstancedMesh';
  4775. object.count = this.count;
  4776. object.instanceMatrix = this.instanceMatrix.toJSON();
  4777. if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
  4778. }
  4779. if ( this.isBatchedMesh ) {
  4780. object.type = 'BatchedMesh';
  4781. object.perObjectFrustumCulled = this.perObjectFrustumCulled;
  4782. object.sortObjects = this.sortObjects;
  4783. object.drawRanges = this._drawRanges;
  4784. object.reservedRanges = this._reservedRanges;
  4785. object.visibility = this._visibility;
  4786. object.active = this._active;
  4787. object.bounds = this._bounds.map( bound => ( {
  4788. boxInitialized: bound.boxInitialized,
  4789. boxMin: bound.box.min.toArray(),
  4790. boxMax: bound.box.max.toArray(),
  4791. sphereInitialized: bound.sphereInitialized,
  4792. sphereRadius: bound.sphere.radius,
  4793. sphereCenter: bound.sphere.center.toArray()
  4794. } ) );
  4795. object.maxInstanceCount = this._maxInstanceCount;
  4796. object.maxVertexCount = this._maxVertexCount;
  4797. object.maxIndexCount = this._maxIndexCount;
  4798. object.geometryInitialized = this._geometryInitialized;
  4799. object.geometryCount = this._geometryCount;
  4800. object.matricesTexture = this._matricesTexture.toJSON( meta );
  4801. if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
  4802. if ( this.boundingSphere !== null ) {
  4803. object.boundingSphere = {
  4804. center: object.boundingSphere.center.toArray(),
  4805. radius: object.boundingSphere.radius
  4806. };
  4807. }
  4808. if ( this.boundingBox !== null ) {
  4809. object.boundingBox = {
  4810. min: object.boundingBox.min.toArray(),
  4811. max: object.boundingBox.max.toArray()
  4812. };
  4813. }
  4814. }
  4815. //
  4816. function serialize( library, element ) {
  4817. if ( library[ element.uuid ] === undefined ) {
  4818. library[ element.uuid ] = element.toJSON( meta );
  4819. }
  4820. return element.uuid;
  4821. }
  4822. if ( this.isScene ) {
  4823. if ( this.background ) {
  4824. if ( this.background.isColor ) {
  4825. object.background = this.background.toJSON();
  4826. } else if ( this.background.isTexture ) {
  4827. object.background = this.background.toJSON( meta ).uuid;
  4828. }
  4829. }
  4830. if ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) {
  4831. object.environment = this.environment.toJSON( meta ).uuid;
  4832. }
  4833. } else if ( this.isMesh || this.isLine || this.isPoints ) {
  4834. object.geometry = serialize( meta.geometries, this.geometry );
  4835. const parameters = this.geometry.parameters;
  4836. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4837. const shapes = parameters.shapes;
  4838. if ( Array.isArray( shapes ) ) {
  4839. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4840. const shape = shapes[ i ];
  4841. serialize( meta.shapes, shape );
  4842. }
  4843. } else {
  4844. serialize( meta.shapes, shapes );
  4845. }
  4846. }
  4847. }
  4848. if ( this.isSkinnedMesh ) {
  4849. object.bindMode = this.bindMode;
  4850. object.bindMatrix = this.bindMatrix.toArray();
  4851. if ( this.skeleton !== undefined ) {
  4852. serialize( meta.skeletons, this.skeleton );
  4853. object.skeleton = this.skeleton.uuid;
  4854. }
  4855. }
  4856. if ( this.material !== undefined ) {
  4857. if ( Array.isArray( this.material ) ) {
  4858. const uuids = [];
  4859. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4860. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4861. }
  4862. object.material = uuids;
  4863. } else {
  4864. object.material = serialize( meta.materials, this.material );
  4865. }
  4866. }
  4867. //
  4868. if ( this.children.length > 0 ) {
  4869. object.children = [];
  4870. for ( let i = 0; i < this.children.length; i ++ ) {
  4871. object.children.push( this.children[ i ].toJSON( meta ).object );
  4872. }
  4873. }
  4874. //
  4875. if ( this.animations.length > 0 ) {
  4876. object.animations = [];
  4877. for ( let i = 0; i < this.animations.length; i ++ ) {
  4878. const animation = this.animations[ i ];
  4879. object.animations.push( serialize( meta.animations, animation ) );
  4880. }
  4881. }
  4882. if ( isRootObject ) {
  4883. const geometries = extractFromCache( meta.geometries );
  4884. const materials = extractFromCache( meta.materials );
  4885. const textures = extractFromCache( meta.textures );
  4886. const images = extractFromCache( meta.images );
  4887. const shapes = extractFromCache( meta.shapes );
  4888. const skeletons = extractFromCache( meta.skeletons );
  4889. const animations = extractFromCache( meta.animations );
  4890. const nodes = extractFromCache( meta.nodes );
  4891. if ( geometries.length > 0 ) output.geometries = geometries;
  4892. if ( materials.length > 0 ) output.materials = materials;
  4893. if ( textures.length > 0 ) output.textures = textures;
  4894. if ( images.length > 0 ) output.images = images;
  4895. if ( shapes.length > 0 ) output.shapes = shapes;
  4896. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4897. if ( animations.length > 0 ) output.animations = animations;
  4898. if ( nodes.length > 0 ) output.nodes = nodes;
  4899. }
  4900. output.object = object;
  4901. return output;
  4902. // extract data from the cache hash
  4903. // remove metadata on each item
  4904. // and return as array
  4905. function extractFromCache( cache ) {
  4906. const values = [];
  4907. for ( const key in cache ) {
  4908. const data = cache[ key ];
  4909. delete data.metadata;
  4910. values.push( data );
  4911. }
  4912. return values;
  4913. }
  4914. }
  4915. clone( recursive ) {
  4916. return new this.constructor().copy( this, recursive );
  4917. }
  4918. copy( source, recursive = true ) {
  4919. this.name = source.name;
  4920. this.up.copy( source.up );
  4921. this.position.copy( source.position );
  4922. this.rotation.order = source.rotation.order;
  4923. this.quaternion.copy( source.quaternion );
  4924. this.scale.copy( source.scale );
  4925. this.matrix.copy( source.matrix );
  4926. this.matrixWorld.copy( source.matrixWorld );
  4927. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4928. this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
  4929. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4930. this.layers.mask = source.layers.mask;
  4931. this.visible = source.visible;
  4932. this.castShadow = source.castShadow;
  4933. this.receiveShadow = source.receiveShadow;
  4934. this.frustumCulled = source.frustumCulled;
  4935. this.renderOrder = source.renderOrder;
  4936. this.animations = source.animations.slice();
  4937. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4938. if ( recursive === true ) {
  4939. for ( let i = 0; i < source.children.length; i ++ ) {
  4940. const child = source.children[ i ];
  4941. this.add( child.clone() );
  4942. }
  4943. }
  4944. return this;
  4945. }
  4946. }
  4947. Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4948. Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
  4949. Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
  4950. const _v0$1 = /*@__PURE__*/ new Vector3();
  4951. const _v1$3 = /*@__PURE__*/ new Vector3();
  4952. const _v2$2 = /*@__PURE__*/ new Vector3();
  4953. const _v3$2 = /*@__PURE__*/ new Vector3();
  4954. const _vab = /*@__PURE__*/ new Vector3();
  4955. const _vac = /*@__PURE__*/ new Vector3();
  4956. const _vbc = /*@__PURE__*/ new Vector3();
  4957. const _vap = /*@__PURE__*/ new Vector3();
  4958. const _vbp = /*@__PURE__*/ new Vector3();
  4959. const _vcp = /*@__PURE__*/ new Vector3();
  4960. const _v40 = /*@__PURE__*/ new Vector4();
  4961. const _v41 = /*@__PURE__*/ new Vector4();
  4962. const _v42 = /*@__PURE__*/ new Vector4();
  4963. class Triangle {
  4964. constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
  4965. this.a = a;
  4966. this.b = b;
  4967. this.c = c;
  4968. }
  4969. static getNormal( a, b, c, target ) {
  4970. target.subVectors( c, b );
  4971. _v0$1.subVectors( a, b );
  4972. target.cross( _v0$1 );
  4973. const targetLengthSq = target.lengthSq();
  4974. if ( targetLengthSq > 0 ) {
  4975. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4976. }
  4977. return target.set( 0, 0, 0 );
  4978. }
  4979. // static/instance method to calculate barycentric coordinates
  4980. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4981. static getBarycoord( point, a, b, c, target ) {
  4982. _v0$1.subVectors( c, a );
  4983. _v1$3.subVectors( b, a );
  4984. _v2$2.subVectors( point, a );
  4985. const dot00 = _v0$1.dot( _v0$1 );
  4986. const dot01 = _v0$1.dot( _v1$3 );
  4987. const dot02 = _v0$1.dot( _v2$2 );
  4988. const dot11 = _v1$3.dot( _v1$3 );
  4989. const dot12 = _v1$3.dot( _v2$2 );
  4990. const denom = ( dot00 * dot11 - dot01 * dot01 );
  4991. // collinear or singular triangle
  4992. if ( denom === 0 ) {
  4993. target.set( 0, 0, 0 );
  4994. return null;
  4995. }
  4996. const invDenom = 1 / denom;
  4997. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4998. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4999. // barycentric coordinates must always sum to 1
  5000. return target.set( 1 - u - v, v, u );
  5001. }
  5002. static containsPoint( point, a, b, c ) {
  5003. // if the triangle is degenerate then we can't contain a point
  5004. if ( this.getBarycoord( point, a, b, c, _v3$2 ) === null ) {
  5005. return false;
  5006. }
  5007. return ( _v3$2.x >= 0 ) && ( _v3$2.y >= 0 ) && ( ( _v3$2.x + _v3$2.y ) <= 1 );
  5008. }
  5009. static getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) {
  5010. if ( this.getBarycoord( point, p1, p2, p3, _v3$2 ) === null ) {
  5011. target.x = 0;
  5012. target.y = 0;
  5013. if ( 'z' in target ) target.z = 0;
  5014. if ( 'w' in target ) target.w = 0;
  5015. return null;
  5016. }
  5017. target.setScalar( 0 );
  5018. target.addScaledVector( v1, _v3$2.x );
  5019. target.addScaledVector( v2, _v3$2.y );
  5020. target.addScaledVector( v3, _v3$2.z );
  5021. return target;
  5022. }
  5023. static getInterpolatedAttribute( attr, i1, i2, i3, barycoord, target ) {
  5024. _v40.setScalar( 0 );
  5025. _v41.setScalar( 0 );
  5026. _v42.setScalar( 0 );
  5027. _v40.fromBufferAttribute( attr, i1 );
  5028. _v41.fromBufferAttribute( attr, i2 );
  5029. _v42.fromBufferAttribute( attr, i3 );
  5030. target.setScalar( 0 );
  5031. target.addScaledVector( _v40, barycoord.x );
  5032. target.addScaledVector( _v41, barycoord.y );
  5033. target.addScaledVector( _v42, barycoord.z );
  5034. return target;
  5035. }
  5036. static isFrontFacing( a, b, c, direction ) {
  5037. _v0$1.subVectors( c, b );
  5038. _v1$3.subVectors( a, b );
  5039. // strictly front facing
  5040. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  5041. }
  5042. set( a, b, c ) {
  5043. this.a.copy( a );
  5044. this.b.copy( b );
  5045. this.c.copy( c );
  5046. return this;
  5047. }
  5048. setFromPointsAndIndices( points, i0, i1, i2 ) {
  5049. this.a.copy( points[ i0 ] );
  5050. this.b.copy( points[ i1 ] );
  5051. this.c.copy( points[ i2 ] );
  5052. return this;
  5053. }
  5054. setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
  5055. this.a.fromBufferAttribute( attribute, i0 );
  5056. this.b.fromBufferAttribute( attribute, i1 );
  5057. this.c.fromBufferAttribute( attribute, i2 );
  5058. return this;
  5059. }
  5060. clone() {
  5061. return new this.constructor().copy( this );
  5062. }
  5063. copy( triangle ) {
  5064. this.a.copy( triangle.a );
  5065. this.b.copy( triangle.b );
  5066. this.c.copy( triangle.c );
  5067. return this;
  5068. }
  5069. getArea() {
  5070. _v0$1.subVectors( this.c, this.b );
  5071. _v1$3.subVectors( this.a, this.b );
  5072. return _v0$1.cross( _v1$3 ).length() * 0.5;
  5073. }
  5074. getMidpoint( target ) {
  5075. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  5076. }
  5077. getNormal( target ) {
  5078. return Triangle.getNormal( this.a, this.b, this.c, target );
  5079. }
  5080. getPlane( target ) {
  5081. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  5082. }
  5083. getBarycoord( point, target ) {
  5084. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  5085. }
  5086. getInterpolation( point, v1, v2, v3, target ) {
  5087. return Triangle.getInterpolation( point, this.a, this.b, this.c, v1, v2, v3, target );
  5088. }
  5089. containsPoint( point ) {
  5090. return Triangle.containsPoint( point, this.a, this.b, this.c );
  5091. }
  5092. isFrontFacing( direction ) {
  5093. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  5094. }
  5095. intersectsBox( box ) {
  5096. return box.intersectsTriangle( this );
  5097. }
  5098. closestPointToPoint( p, target ) {
  5099. const a = this.a, b = this.b, c = this.c;
  5100. let v, w;
  5101. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5102. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5103. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5104. // basically, we're distinguishing which of the voronoi regions of the triangle
  5105. // the point lies in with the minimum amount of redundant computation.
  5106. _vab.subVectors( b, a );
  5107. _vac.subVectors( c, a );
  5108. _vap.subVectors( p, a );
  5109. const d1 = _vab.dot( _vap );
  5110. const d2 = _vac.dot( _vap );
  5111. if ( d1 <= 0 && d2 <= 0 ) {
  5112. // vertex region of A; barycentric coords (1, 0, 0)
  5113. return target.copy( a );
  5114. }
  5115. _vbp.subVectors( p, b );
  5116. const d3 = _vab.dot( _vbp );
  5117. const d4 = _vac.dot( _vbp );
  5118. if ( d3 >= 0 && d4 <= d3 ) {
  5119. // vertex region of B; barycentric coords (0, 1, 0)
  5120. return target.copy( b );
  5121. }
  5122. const vc = d1 * d4 - d3 * d2;
  5123. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  5124. v = d1 / ( d1 - d3 );
  5125. // edge region of AB; barycentric coords (1-v, v, 0)
  5126. return target.copy( a ).addScaledVector( _vab, v );
  5127. }
  5128. _vcp.subVectors( p, c );
  5129. const d5 = _vab.dot( _vcp );
  5130. const d6 = _vac.dot( _vcp );
  5131. if ( d6 >= 0 && d5 <= d6 ) {
  5132. // vertex region of C; barycentric coords (0, 0, 1)
  5133. return target.copy( c );
  5134. }
  5135. const vb = d5 * d2 - d1 * d6;
  5136. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  5137. w = d2 / ( d2 - d6 );
  5138. // edge region of AC; barycentric coords (1-w, 0, w)
  5139. return target.copy( a ).addScaledVector( _vac, w );
  5140. }
  5141. const va = d3 * d6 - d5 * d4;
  5142. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  5143. _vbc.subVectors( c, b );
  5144. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  5145. // edge region of BC; barycentric coords (0, 1-w, w)
  5146. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  5147. }
  5148. // face region
  5149. const denom = 1 / ( va + vb + vc );
  5150. // u = va * denom
  5151. v = vb * denom;
  5152. w = vc * denom;
  5153. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  5154. }
  5155. equals( triangle ) {
  5156. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  5157. }
  5158. }
  5159. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5160. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5161. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5162. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5163. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5164. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5165. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5166. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5167. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5168. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5169. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5170. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5171. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5172. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5173. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5174. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5175. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5176. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5177. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5178. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5179. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5180. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5181. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5182. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5183. const _hslA = { h: 0, s: 0, l: 0 };
  5184. const _hslB = { h: 0, s: 0, l: 0 };
  5185. function hue2rgb( p, q, t ) {
  5186. if ( t < 0 ) t += 1;
  5187. if ( t > 1 ) t -= 1;
  5188. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5189. if ( t < 1 / 2 ) return q;
  5190. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5191. return p;
  5192. }
  5193. class Color {
  5194. constructor( r, g, b ) {
  5195. this.isColor = true;
  5196. this.r = 1;
  5197. this.g = 1;
  5198. this.b = 1;
  5199. return this.set( r, g, b );
  5200. }
  5201. set( r, g, b ) {
  5202. if ( g === undefined && b === undefined ) {
  5203. // r is THREE.Color, hex or string
  5204. const value = r;
  5205. if ( value && value.isColor ) {
  5206. this.copy( value );
  5207. } else if ( typeof value === 'number' ) {
  5208. this.setHex( value );
  5209. } else if ( typeof value === 'string' ) {
  5210. this.setStyle( value );
  5211. }
  5212. } else {
  5213. this.setRGB( r, g, b );
  5214. }
  5215. return this;
  5216. }
  5217. setScalar( scalar ) {
  5218. this.r = scalar;
  5219. this.g = scalar;
  5220. this.b = scalar;
  5221. return this;
  5222. }
  5223. setHex( hex, colorSpace = SRGBColorSpace ) {
  5224. hex = Math.floor( hex );
  5225. this.r = ( hex >> 16 & 255 ) / 255;
  5226. this.g = ( hex >> 8 & 255 ) / 255;
  5227. this.b = ( hex & 255 ) / 255;
  5228. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5229. return this;
  5230. }
  5231. setRGB( r, g, b, colorSpace = ColorManagement.workingColorSpace ) {
  5232. this.r = r;
  5233. this.g = g;
  5234. this.b = b;
  5235. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5236. return this;
  5237. }
  5238. setHSL( h, s, l, colorSpace = ColorManagement.workingColorSpace ) {
  5239. // h,s,l ranges are in 0.0 - 1.0
  5240. h = euclideanModulo( h, 1 );
  5241. s = clamp( s, 0, 1 );
  5242. l = clamp( l, 0, 1 );
  5243. if ( s === 0 ) {
  5244. this.r = this.g = this.b = l;
  5245. } else {
  5246. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5247. const q = ( 2 * l ) - p;
  5248. this.r = hue2rgb( q, p, h + 1 / 3 );
  5249. this.g = hue2rgb( q, p, h );
  5250. this.b = hue2rgb( q, p, h - 1 / 3 );
  5251. }
  5252. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5253. return this;
  5254. }
  5255. setStyle( style, colorSpace = SRGBColorSpace ) {
  5256. function handleAlpha( string ) {
  5257. if ( string === undefined ) return;
  5258. if ( parseFloat( string ) < 1 ) {
  5259. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5260. }
  5261. }
  5262. let m;
  5263. if ( m = /^(\w+)\(([^\)]*)\)/.exec( style ) ) {
  5264. // rgb / hsl
  5265. let color;
  5266. const name = m[ 1 ];
  5267. const components = m[ 2 ];
  5268. switch ( name ) {
  5269. case 'rgb':
  5270. case 'rgba':
  5271. if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5272. // rgb(255,0,0) rgba(255,0,0,0.5)
  5273. handleAlpha( color[ 4 ] );
  5274. return this.setRGB(
  5275. Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255,
  5276. Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255,
  5277. Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255,
  5278. colorSpace
  5279. );
  5280. }
  5281. if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5282. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5283. handleAlpha( color[ 4 ] );
  5284. return this.setRGB(
  5285. Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100,
  5286. Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100,
  5287. Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100,
  5288. colorSpace
  5289. );
  5290. }
  5291. break;
  5292. case 'hsl':
  5293. case 'hsla':
  5294. if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5295. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5296. handleAlpha( color[ 4 ] );
  5297. return this.setHSL(
  5298. parseFloat( color[ 1 ] ) / 360,
  5299. parseFloat( color[ 2 ] ) / 100,
  5300. parseFloat( color[ 3 ] ) / 100,
  5301. colorSpace
  5302. );
  5303. }
  5304. break;
  5305. default:
  5306. console.warn( 'THREE.Color: Unknown color model ' + style );
  5307. }
  5308. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  5309. // hex color
  5310. const hex = m[ 1 ];
  5311. const size = hex.length;
  5312. if ( size === 3 ) {
  5313. // #ff0
  5314. return this.setRGB(
  5315. parseInt( hex.charAt( 0 ), 16 ) / 15,
  5316. parseInt( hex.charAt( 1 ), 16 ) / 15,
  5317. parseInt( hex.charAt( 2 ), 16 ) / 15,
  5318. colorSpace
  5319. );
  5320. } else if ( size === 6 ) {
  5321. // #ff0000
  5322. return this.setHex( parseInt( hex, 16 ), colorSpace );
  5323. } else {
  5324. console.warn( 'THREE.Color: Invalid hex color ' + style );
  5325. }
  5326. } else if ( style && style.length > 0 ) {
  5327. return this.setColorName( style, colorSpace );
  5328. }
  5329. return this;
  5330. }
  5331. setColorName( style, colorSpace = SRGBColorSpace ) {
  5332. // color keywords
  5333. const hex = _colorKeywords[ style.toLowerCase() ];
  5334. if ( hex !== undefined ) {
  5335. // red
  5336. this.setHex( hex, colorSpace );
  5337. } else {
  5338. // unknown color
  5339. console.warn( 'THREE.Color: Unknown color ' + style );
  5340. }
  5341. return this;
  5342. }
  5343. clone() {
  5344. return new this.constructor( this.r, this.g, this.b );
  5345. }
  5346. copy( color ) {
  5347. this.r = color.r;
  5348. this.g = color.g;
  5349. this.b = color.b;
  5350. return this;
  5351. }
  5352. copySRGBToLinear( color ) {
  5353. this.r = SRGBToLinear( color.r );
  5354. this.g = SRGBToLinear( color.g );
  5355. this.b = SRGBToLinear( color.b );
  5356. return this;
  5357. }
  5358. copyLinearToSRGB( color ) {
  5359. this.r = LinearToSRGB( color.r );
  5360. this.g = LinearToSRGB( color.g );
  5361. this.b = LinearToSRGB( color.b );
  5362. return this;
  5363. }
  5364. convertSRGBToLinear() {
  5365. this.copySRGBToLinear( this );
  5366. return this;
  5367. }
  5368. convertLinearToSRGB() {
  5369. this.copyLinearToSRGB( this );
  5370. return this;
  5371. }
  5372. getHex( colorSpace = SRGBColorSpace ) {
  5373. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5374. 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 ) );
  5375. }
  5376. getHexString( colorSpace = SRGBColorSpace ) {
  5377. return ( '000000' + this.getHex( colorSpace ).toString( 16 ) ).slice( - 6 );
  5378. }
  5379. getHSL( target, colorSpace = ColorManagement.workingColorSpace ) {
  5380. // h,s,l ranges are in 0.0 - 1.0
  5381. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5382. const r = _color.r, g = _color.g, b = _color.b;
  5383. const max = Math.max( r, g, b );
  5384. const min = Math.min( r, g, b );
  5385. let hue, saturation;
  5386. const lightness = ( min + max ) / 2.0;
  5387. if ( min === max ) {
  5388. hue = 0;
  5389. saturation = 0;
  5390. } else {
  5391. const delta = max - min;
  5392. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5393. switch ( max ) {
  5394. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5395. case g: hue = ( b - r ) / delta + 2; break;
  5396. case b: hue = ( r - g ) / delta + 4; break;
  5397. }
  5398. hue /= 6;
  5399. }
  5400. target.h = hue;
  5401. target.s = saturation;
  5402. target.l = lightness;
  5403. return target;
  5404. }
  5405. getRGB( target, colorSpace = ColorManagement.workingColorSpace ) {
  5406. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5407. target.r = _color.r;
  5408. target.g = _color.g;
  5409. target.b = _color.b;
  5410. return target;
  5411. }
  5412. getStyle( colorSpace = SRGBColorSpace ) {
  5413. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5414. const r = _color.r, g = _color.g, b = _color.b;
  5415. if ( colorSpace !== SRGBColorSpace ) {
  5416. // Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).
  5417. return `color(${ colorSpace } ${ r.toFixed( 3 ) } ${ g.toFixed( 3 ) } ${ b.toFixed( 3 ) })`;
  5418. }
  5419. return `rgb(${ Math.round( r * 255 ) },${ Math.round( g * 255 ) },${ Math.round( b * 255 ) })`;
  5420. }
  5421. offsetHSL( h, s, l ) {
  5422. this.getHSL( _hslA );
  5423. return this.setHSL( _hslA.h + h, _hslA.s + s, _hslA.l + l );
  5424. }
  5425. add( color ) {
  5426. this.r += color.r;
  5427. this.g += color.g;
  5428. this.b += color.b;
  5429. return this;
  5430. }
  5431. addColors( color1, color2 ) {
  5432. this.r = color1.r + color2.r;
  5433. this.g = color1.g + color2.g;
  5434. this.b = color1.b + color2.b;
  5435. return this;
  5436. }
  5437. addScalar( s ) {
  5438. this.r += s;
  5439. this.g += s;
  5440. this.b += s;
  5441. return this;
  5442. }
  5443. sub( color ) {
  5444. this.r = Math.max( 0, this.r - color.r );
  5445. this.g = Math.max( 0, this.g - color.g );
  5446. this.b = Math.max( 0, this.b - color.b );
  5447. return this;
  5448. }
  5449. multiply( color ) {
  5450. this.r *= color.r;
  5451. this.g *= color.g;
  5452. this.b *= color.b;
  5453. return this;
  5454. }
  5455. multiplyScalar( s ) {
  5456. this.r *= s;
  5457. this.g *= s;
  5458. this.b *= s;
  5459. return this;
  5460. }
  5461. lerp( color, alpha ) {
  5462. this.r += ( color.r - this.r ) * alpha;
  5463. this.g += ( color.g - this.g ) * alpha;
  5464. this.b += ( color.b - this.b ) * alpha;
  5465. return this;
  5466. }
  5467. lerpColors( color1, color2, alpha ) {
  5468. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  5469. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  5470. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  5471. return this;
  5472. }
  5473. lerpHSL( color, alpha ) {
  5474. this.getHSL( _hslA );
  5475. color.getHSL( _hslB );
  5476. const h = lerp( _hslA.h, _hslB.h, alpha );
  5477. const s = lerp( _hslA.s, _hslB.s, alpha );
  5478. const l = lerp( _hslA.l, _hslB.l, alpha );
  5479. this.setHSL( h, s, l );
  5480. return this;
  5481. }
  5482. setFromVector3( v ) {
  5483. this.r = v.x;
  5484. this.g = v.y;
  5485. this.b = v.z;
  5486. return this;
  5487. }
  5488. applyMatrix3( m ) {
  5489. const r = this.r, g = this.g, b = this.b;
  5490. const e = m.elements;
  5491. this.r = e[ 0 ] * r + e[ 3 ] * g + e[ 6 ] * b;
  5492. this.g = e[ 1 ] * r + e[ 4 ] * g + e[ 7 ] * b;
  5493. this.b = e[ 2 ] * r + e[ 5 ] * g + e[ 8 ] * b;
  5494. return this;
  5495. }
  5496. equals( c ) {
  5497. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5498. }
  5499. fromArray( array, offset = 0 ) {
  5500. this.r = array[ offset ];
  5501. this.g = array[ offset + 1 ];
  5502. this.b = array[ offset + 2 ];
  5503. return this;
  5504. }
  5505. toArray( array = [], offset = 0 ) {
  5506. array[ offset ] = this.r;
  5507. array[ offset + 1 ] = this.g;
  5508. array[ offset + 2 ] = this.b;
  5509. return array;
  5510. }
  5511. fromBufferAttribute( attribute, index ) {
  5512. this.r = attribute.getX( index );
  5513. this.g = attribute.getY( index );
  5514. this.b = attribute.getZ( index );
  5515. return this;
  5516. }
  5517. toJSON() {
  5518. return this.getHex();
  5519. }
  5520. *[ Symbol.iterator ]() {
  5521. yield this.r;
  5522. yield this.g;
  5523. yield this.b;
  5524. }
  5525. }
  5526. const _color = /*@__PURE__*/ new Color();
  5527. Color.NAMES = _colorKeywords;
  5528. let _materialId = 0;
  5529. class Material extends EventDispatcher {
  5530. constructor() {
  5531. super();
  5532. this.isMaterial = true;
  5533. Object.defineProperty( this, 'id', { value: _materialId ++ } );
  5534. this.uuid = generateUUID();
  5535. this.name = '';
  5536. this.type = 'Material';
  5537. this.blending = NormalBlending;
  5538. this.side = FrontSide;
  5539. this.vertexColors = false;
  5540. this.opacity = 1;
  5541. this.transparent = false;
  5542. this.alphaHash = false;
  5543. this.blendSrc = SrcAlphaFactor;
  5544. this.blendDst = OneMinusSrcAlphaFactor;
  5545. this.blendEquation = AddEquation;
  5546. this.blendSrcAlpha = null;
  5547. this.blendDstAlpha = null;
  5548. this.blendEquationAlpha = null;
  5549. this.blendColor = new Color( 0, 0, 0 );
  5550. this.blendAlpha = 0;
  5551. this.depthFunc = LessEqualDepth;
  5552. this.depthTest = true;
  5553. this.depthWrite = true;
  5554. this.stencilWriteMask = 0xff;
  5555. this.stencilFunc = AlwaysStencilFunc;
  5556. this.stencilRef = 0;
  5557. this.stencilFuncMask = 0xff;
  5558. this.stencilFail = KeepStencilOp;
  5559. this.stencilZFail = KeepStencilOp;
  5560. this.stencilZPass = KeepStencilOp;
  5561. this.stencilWrite = false;
  5562. this.clippingPlanes = null;
  5563. this.clipIntersection = false;
  5564. this.clipShadows = false;
  5565. this.shadowSide = null;
  5566. this.colorWrite = true;
  5567. this.precision = null; // override the renderer's default precision for this material
  5568. this.polygonOffset = false;
  5569. this.polygonOffsetFactor = 0;
  5570. this.polygonOffsetUnits = 0;
  5571. this.dithering = false;
  5572. this.alphaToCoverage = false;
  5573. this.premultipliedAlpha = false;
  5574. this.forceSinglePass = false;
  5575. this.visible = true;
  5576. this.toneMapped = true;
  5577. this.userData = {};
  5578. this.version = 0;
  5579. this._alphaTest = 0;
  5580. }
  5581. get alphaTest() {
  5582. return this._alphaTest;
  5583. }
  5584. set alphaTest( value ) {
  5585. if ( this._alphaTest > 0 !== value > 0 ) {
  5586. this.version ++;
  5587. }
  5588. this._alphaTest = value;
  5589. }
  5590. // onBeforeRender and onBeforeCompile only supported in WebGLRenderer
  5591. onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}
  5592. onBeforeCompile( /* shaderobject, renderer */ ) {}
  5593. customProgramCacheKey() {
  5594. return this.onBeforeCompile.toString();
  5595. }
  5596. setValues( values ) {
  5597. if ( values === undefined ) return;
  5598. for ( const key in values ) {
  5599. const newValue = values[ key ];
  5600. if ( newValue === undefined ) {
  5601. console.warn( `THREE.Material: parameter '${ key }' has value of undefined.` );
  5602. continue;
  5603. }
  5604. const currentValue = this[ key ];
  5605. if ( currentValue === undefined ) {
  5606. console.warn( `THREE.Material: '${ key }' is not a property of THREE.${ this.type }.` );
  5607. continue;
  5608. }
  5609. if ( currentValue && currentValue.isColor ) {
  5610. currentValue.set( newValue );
  5611. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5612. currentValue.copy( newValue );
  5613. } else {
  5614. this[ key ] = newValue;
  5615. }
  5616. }
  5617. }
  5618. toJSON( meta ) {
  5619. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  5620. if ( isRootObject ) {
  5621. meta = {
  5622. textures: {},
  5623. images: {}
  5624. };
  5625. }
  5626. const data = {
  5627. metadata: {
  5628. version: 4.6,
  5629. type: 'Material',
  5630. generator: 'Material.toJSON'
  5631. }
  5632. };
  5633. // standard Material serialization
  5634. data.uuid = this.uuid;
  5635. data.type = this.type;
  5636. if ( this.name !== '' ) data.name = this.name;
  5637. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5638. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5639. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5640. if ( this.sheen !== undefined ) data.sheen = this.sheen;
  5641. if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();
  5642. if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
  5643. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5644. if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5645. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5646. if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
  5647. if ( this.specularColor && this.specularColor.isColor ) data.specularColor = this.specularColor.getHex();
  5648. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5649. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5650. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5651. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5652. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5653. }
  5654. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5655. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5656. }
  5657. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5658. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5659. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5660. }
  5661. if ( this.dispersion !== undefined ) data.dispersion = this.dispersion;
  5662. if ( this.iridescence !== undefined ) data.iridescence = this.iridescence;
  5663. if ( this.iridescenceIOR !== undefined ) data.iridescenceIOR = this.iridescenceIOR;
  5664. if ( this.iridescenceThicknessRange !== undefined ) data.iridescenceThicknessRange = this.iridescenceThicknessRange;
  5665. if ( this.iridescenceMap && this.iridescenceMap.isTexture ) {
  5666. data.iridescenceMap = this.iridescenceMap.toJSON( meta ).uuid;
  5667. }
  5668. if ( this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture ) {
  5669. data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON( meta ).uuid;
  5670. }
  5671. if ( this.anisotropy !== undefined ) data.anisotropy = this.anisotropy;
  5672. if ( this.anisotropyRotation !== undefined ) data.anisotropyRotation = this.anisotropyRotation;
  5673. if ( this.anisotropyMap && this.anisotropyMap.isTexture ) {
  5674. data.anisotropyMap = this.anisotropyMap.toJSON( meta ).uuid;
  5675. }
  5676. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5677. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5678. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5679. if ( this.lightMap && this.lightMap.isTexture ) {
  5680. data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5681. data.lightMapIntensity = this.lightMapIntensity;
  5682. }
  5683. if ( this.aoMap && this.aoMap.isTexture ) {
  5684. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5685. data.aoMapIntensity = this.aoMapIntensity;
  5686. }
  5687. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5688. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5689. data.bumpScale = this.bumpScale;
  5690. }
  5691. if ( this.normalMap && this.normalMap.isTexture ) {
  5692. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5693. data.normalMapType = this.normalMapType;
  5694. data.normalScale = this.normalScale.toArray();
  5695. }
  5696. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5697. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5698. data.displacementScale = this.displacementScale;
  5699. data.displacementBias = this.displacementBias;
  5700. }
  5701. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5702. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5703. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5704. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5705. if ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid;
  5706. if ( this.specularColorMap && this.specularColorMap.isTexture ) data.specularColorMap = this.specularColorMap.toJSON( meta ).uuid;
  5707. if ( this.envMap && this.envMap.isTexture ) {
  5708. data.envMap = this.envMap.toJSON( meta ).uuid;
  5709. if ( this.combine !== undefined ) data.combine = this.combine;
  5710. }
  5711. if ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray();
  5712. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5713. if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;
  5714. if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;
  5715. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5716. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5717. }
  5718. if ( this.transmission !== undefined ) data.transmission = this.transmission;
  5719. if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;
  5720. if ( this.thickness !== undefined ) data.thickness = this.thickness;
  5721. if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;
  5722. if ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance;
  5723. if ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex();
  5724. if ( this.size !== undefined ) data.size = this.size;
  5725. if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;
  5726. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5727. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5728. if ( this.side !== FrontSide ) data.side = this.side;
  5729. if ( this.vertexColors === true ) data.vertexColors = true;
  5730. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5731. if ( this.transparent === true ) data.transparent = true;
  5732. if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;
  5733. if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;
  5734. if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;
  5735. if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;
  5736. if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;
  5737. if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;
  5738. if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();
  5739. if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;
  5740. if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
  5741. if ( this.depthTest === false ) data.depthTest = this.depthTest;
  5742. if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
  5743. if ( this.colorWrite === false ) data.colorWrite = this.colorWrite;
  5744. if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;
  5745. if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;
  5746. if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;
  5747. if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;
  5748. if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;
  5749. if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;
  5750. if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;
  5751. if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;
  5752. // rotation (SpriteMaterial)
  5753. if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;
  5754. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5755. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5756. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5757. if ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5758. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5759. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5760. if ( this.scale !== undefined ) data.scale = this.scale;
  5761. if ( this.dithering === true ) data.dithering = true;
  5762. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5763. if ( this.alphaHash === true ) data.alphaHash = true;
  5764. if ( this.alphaToCoverage === true ) data.alphaToCoverage = true;
  5765. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;
  5766. if ( this.forceSinglePass === true ) data.forceSinglePass = true;
  5767. if ( this.wireframe === true ) data.wireframe = true;
  5768. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5769. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5770. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5771. if ( this.flatShading === true ) data.flatShading = true;
  5772. if ( this.visible === false ) data.visible = false;
  5773. if ( this.toneMapped === false ) data.toneMapped = false;
  5774. if ( this.fog === false ) data.fog = false;
  5775. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  5776. // TODO: Copied from Object3D.toJSON
  5777. function extractFromCache( cache ) {
  5778. const values = [];
  5779. for ( const key in cache ) {
  5780. const data = cache[ key ];
  5781. delete data.metadata;
  5782. values.push( data );
  5783. }
  5784. return values;
  5785. }
  5786. if ( isRootObject ) {
  5787. const textures = extractFromCache( meta.textures );
  5788. const images = extractFromCache( meta.images );
  5789. if ( textures.length > 0 ) data.textures = textures;
  5790. if ( images.length > 0 ) data.images = images;
  5791. }
  5792. return data;
  5793. }
  5794. clone() {
  5795. return new this.constructor().copy( this );
  5796. }
  5797. copy( source ) {
  5798. this.name = source.name;
  5799. this.blending = source.blending;
  5800. this.side = source.side;
  5801. this.vertexColors = source.vertexColors;
  5802. this.opacity = source.opacity;
  5803. this.transparent = source.transparent;
  5804. this.blendSrc = source.blendSrc;
  5805. this.blendDst = source.blendDst;
  5806. this.blendEquation = source.blendEquation;
  5807. this.blendSrcAlpha = source.blendSrcAlpha;
  5808. this.blendDstAlpha = source.blendDstAlpha;
  5809. this.blendEquationAlpha = source.blendEquationAlpha;
  5810. this.blendColor.copy( source.blendColor );
  5811. this.blendAlpha = source.blendAlpha;
  5812. this.depthFunc = source.depthFunc;
  5813. this.depthTest = source.depthTest;
  5814. this.depthWrite = source.depthWrite;
  5815. this.stencilWriteMask = source.stencilWriteMask;
  5816. this.stencilFunc = source.stencilFunc;
  5817. this.stencilRef = source.stencilRef;
  5818. this.stencilFuncMask = source.stencilFuncMask;
  5819. this.stencilFail = source.stencilFail;
  5820. this.stencilZFail = source.stencilZFail;
  5821. this.stencilZPass = source.stencilZPass;
  5822. this.stencilWrite = source.stencilWrite;
  5823. const srcPlanes = source.clippingPlanes;
  5824. let dstPlanes = null;
  5825. if ( srcPlanes !== null ) {
  5826. const n = srcPlanes.length;
  5827. dstPlanes = new Array( n );
  5828. for ( let i = 0; i !== n; ++ i ) {
  5829. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5830. }
  5831. }
  5832. this.clippingPlanes = dstPlanes;
  5833. this.clipIntersection = source.clipIntersection;
  5834. this.clipShadows = source.clipShadows;
  5835. this.shadowSide = source.shadowSide;
  5836. this.colorWrite = source.colorWrite;
  5837. this.precision = source.precision;
  5838. this.polygonOffset = source.polygonOffset;
  5839. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5840. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5841. this.dithering = source.dithering;
  5842. this.alphaTest = source.alphaTest;
  5843. this.alphaHash = source.alphaHash;
  5844. this.alphaToCoverage = source.alphaToCoverage;
  5845. this.premultipliedAlpha = source.premultipliedAlpha;
  5846. this.forceSinglePass = source.forceSinglePass;
  5847. this.visible = source.visible;
  5848. this.toneMapped = source.toneMapped;
  5849. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5850. return this;
  5851. }
  5852. dispose() {
  5853. this.dispatchEvent( { type: 'dispose' } );
  5854. }
  5855. set needsUpdate( value ) {
  5856. if ( value === true ) this.version ++;
  5857. }
  5858. onBuild( /* shaderobject, renderer */ ) {
  5859. console.warn( 'Material: onBuild() has been removed.' ); // @deprecated, r166
  5860. }
  5861. }
  5862. class MeshBasicMaterial extends Material {
  5863. constructor( parameters ) {
  5864. super();
  5865. this.isMeshBasicMaterial = true;
  5866. this.type = 'MeshBasicMaterial';
  5867. this.color = new Color( 0xffffff ); // emissive
  5868. this.map = null;
  5869. this.lightMap = null;
  5870. this.lightMapIntensity = 1.0;
  5871. this.aoMap = null;
  5872. this.aoMapIntensity = 1.0;
  5873. this.specularMap = null;
  5874. this.alphaMap = null;
  5875. this.envMap = null;
  5876. this.envMapRotation = new Euler();
  5877. this.combine = MultiplyOperation;
  5878. this.reflectivity = 1;
  5879. this.refractionRatio = 0.98;
  5880. this.wireframe = false;
  5881. this.wireframeLinewidth = 1;
  5882. this.wireframeLinecap = 'round';
  5883. this.wireframeLinejoin = 'round';
  5884. this.fog = true;
  5885. this.setValues( parameters );
  5886. }
  5887. copy( source ) {
  5888. super.copy( source );
  5889. this.color.copy( source.color );
  5890. this.map = source.map;
  5891. this.lightMap = source.lightMap;
  5892. this.lightMapIntensity = source.lightMapIntensity;
  5893. this.aoMap = source.aoMap;
  5894. this.aoMapIntensity = source.aoMapIntensity;
  5895. this.specularMap = source.specularMap;
  5896. this.alphaMap = source.alphaMap;
  5897. this.envMap = source.envMap;
  5898. this.envMapRotation.copy( source.envMapRotation );
  5899. this.combine = source.combine;
  5900. this.reflectivity = source.reflectivity;
  5901. this.refractionRatio = source.refractionRatio;
  5902. this.wireframe = source.wireframe;
  5903. this.wireframeLinewidth = source.wireframeLinewidth;
  5904. this.wireframeLinecap = source.wireframeLinecap;
  5905. this.wireframeLinejoin = source.wireframeLinejoin;
  5906. this.fog = source.fog;
  5907. return this;
  5908. }
  5909. }
  5910. // Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
  5911. const _tables = /*@__PURE__*/ _generateTables();
  5912. function _generateTables() {
  5913. // float32 to float16 helpers
  5914. const buffer = new ArrayBuffer( 4 );
  5915. const floatView = new Float32Array( buffer );
  5916. const uint32View = new Uint32Array( buffer );
  5917. const baseTable = new Uint32Array( 512 );
  5918. const shiftTable = new Uint32Array( 512 );
  5919. for ( let i = 0; i < 256; ++ i ) {
  5920. const e = i - 127;
  5921. // very small number (0, -0)
  5922. if ( e < - 27 ) {
  5923. baseTable[ i ] = 0x0000;
  5924. baseTable[ i | 0x100 ] = 0x8000;
  5925. shiftTable[ i ] = 24;
  5926. shiftTable[ i | 0x100 ] = 24;
  5927. // small number (denorm)
  5928. } else if ( e < - 14 ) {
  5929. baseTable[ i ] = 0x0400 >> ( - e - 14 );
  5930. baseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000;
  5931. shiftTable[ i ] = - e - 1;
  5932. shiftTable[ i | 0x100 ] = - e - 1;
  5933. // normal number
  5934. } else if ( e <= 15 ) {
  5935. baseTable[ i ] = ( e + 15 ) << 10;
  5936. baseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000;
  5937. shiftTable[ i ] = 13;
  5938. shiftTable[ i | 0x100 ] = 13;
  5939. // large number (Infinity, -Infinity)
  5940. } else if ( e < 128 ) {
  5941. baseTable[ i ] = 0x7c00;
  5942. baseTable[ i | 0x100 ] = 0xfc00;
  5943. shiftTable[ i ] = 24;
  5944. shiftTable[ i | 0x100 ] = 24;
  5945. // stay (NaN, Infinity, -Infinity)
  5946. } else {
  5947. baseTable[ i ] = 0x7c00;
  5948. baseTable[ i | 0x100 ] = 0xfc00;
  5949. shiftTable[ i ] = 13;
  5950. shiftTable[ i | 0x100 ] = 13;
  5951. }
  5952. }
  5953. // float16 to float32 helpers
  5954. const mantissaTable = new Uint32Array( 2048 );
  5955. const exponentTable = new Uint32Array( 64 );
  5956. const offsetTable = new Uint32Array( 64 );
  5957. for ( let i = 1; i < 1024; ++ i ) {
  5958. let m = i << 13; // zero pad mantissa bits
  5959. let e = 0; // zero exponent
  5960. // normalized
  5961. while ( ( m & 0x00800000 ) === 0 ) {
  5962. m <<= 1;
  5963. e -= 0x00800000; // decrement exponent
  5964. }
  5965. m &= ~ 0x00800000; // clear leading 1 bit
  5966. e += 0x38800000; // adjust bias
  5967. mantissaTable[ i ] = m | e;
  5968. }
  5969. for ( let i = 1024; i < 2048; ++ i ) {
  5970. mantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 );
  5971. }
  5972. for ( let i = 1; i < 31; ++ i ) {
  5973. exponentTable[ i ] = i << 23;
  5974. }
  5975. exponentTable[ 31 ] = 0x47800000;
  5976. exponentTable[ 32 ] = 0x80000000;
  5977. for ( let i = 33; i < 63; ++ i ) {
  5978. exponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 );
  5979. }
  5980. exponentTable[ 63 ] = 0xc7800000;
  5981. for ( let i = 1; i < 64; ++ i ) {
  5982. if ( i !== 32 ) {
  5983. offsetTable[ i ] = 1024;
  5984. }
  5985. }
  5986. return {
  5987. floatView: floatView,
  5988. uint32View: uint32View,
  5989. baseTable: baseTable,
  5990. shiftTable: shiftTable,
  5991. mantissaTable: mantissaTable,
  5992. exponentTable: exponentTable,
  5993. offsetTable: offsetTable
  5994. };
  5995. }
  5996. // float32 to float16
  5997. function toHalfFloat( val ) {
  5998. if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );
  5999. val = clamp( val, - 65504, 65504 );
  6000. _tables.floatView[ 0 ] = val;
  6001. const f = _tables.uint32View[ 0 ];
  6002. const e = ( f >> 23 ) & 0x1ff;
  6003. return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );
  6004. }
  6005. // float16 to float32
  6006. function fromHalfFloat( val ) {
  6007. const m = val >> 10;
  6008. _tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ];
  6009. return _tables.floatView[ 0 ];
  6010. }
  6011. const DataUtils = {
  6012. toHalfFloat: toHalfFloat,
  6013. fromHalfFloat: fromHalfFloat,
  6014. };
  6015. const _vector$9 = /*@__PURE__*/ new Vector3();
  6016. const _vector2$1 = /*@__PURE__*/ new Vector2();
  6017. class BufferAttribute {
  6018. constructor( array, itemSize, normalized = false ) {
  6019. if ( Array.isArray( array ) ) {
  6020. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6021. }
  6022. this.isBufferAttribute = true;
  6023. this.name = '';
  6024. this.array = array;
  6025. this.itemSize = itemSize;
  6026. this.count = array !== undefined ? array.length / itemSize : 0;
  6027. this.normalized = normalized;
  6028. this.usage = StaticDrawUsage;
  6029. this.updateRanges = [];
  6030. this.gpuType = FloatType;
  6031. this.version = 0;
  6032. }
  6033. onUploadCallback() {}
  6034. set needsUpdate( value ) {
  6035. if ( value === true ) this.version ++;
  6036. }
  6037. setUsage( value ) {
  6038. this.usage = value;
  6039. return this;
  6040. }
  6041. addUpdateRange( start, count ) {
  6042. this.updateRanges.push( { start, count } );
  6043. }
  6044. clearUpdateRanges() {
  6045. this.updateRanges.length = 0;
  6046. }
  6047. copy( source ) {
  6048. this.name = source.name;
  6049. this.array = new source.array.constructor( source.array );
  6050. this.itemSize = source.itemSize;
  6051. this.count = source.count;
  6052. this.normalized = source.normalized;
  6053. this.usage = source.usage;
  6054. this.gpuType = source.gpuType;
  6055. return this;
  6056. }
  6057. copyAt( index1, attribute, index2 ) {
  6058. index1 *= this.itemSize;
  6059. index2 *= attribute.itemSize;
  6060. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  6061. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6062. }
  6063. return this;
  6064. }
  6065. copyArray( array ) {
  6066. this.array.set( array );
  6067. return this;
  6068. }
  6069. applyMatrix3( m ) {
  6070. if ( this.itemSize === 2 ) {
  6071. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6072. _vector2$1.fromBufferAttribute( this, i );
  6073. _vector2$1.applyMatrix3( m );
  6074. this.setXY( i, _vector2$1.x, _vector2$1.y );
  6075. }
  6076. } else if ( this.itemSize === 3 ) {
  6077. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6078. _vector$9.fromBufferAttribute( this, i );
  6079. _vector$9.applyMatrix3( m );
  6080. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6081. }
  6082. }
  6083. return this;
  6084. }
  6085. applyMatrix4( m ) {
  6086. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6087. _vector$9.fromBufferAttribute( this, i );
  6088. _vector$9.applyMatrix4( m );
  6089. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6090. }
  6091. return this;
  6092. }
  6093. applyNormalMatrix( m ) {
  6094. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6095. _vector$9.fromBufferAttribute( this, i );
  6096. _vector$9.applyNormalMatrix( m );
  6097. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6098. }
  6099. return this;
  6100. }
  6101. transformDirection( m ) {
  6102. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6103. _vector$9.fromBufferAttribute( this, i );
  6104. _vector$9.transformDirection( m );
  6105. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6106. }
  6107. return this;
  6108. }
  6109. set( value, offset = 0 ) {
  6110. // Matching BufferAttribute constructor, do not normalize the array.
  6111. this.array.set( value, offset );
  6112. return this;
  6113. }
  6114. getComponent( index, component ) {
  6115. let value = this.array[ index * this.itemSize + component ];
  6116. if ( this.normalized ) value = denormalize( value, this.array );
  6117. return value;
  6118. }
  6119. setComponent( index, component, value ) {
  6120. if ( this.normalized ) value = normalize( value, this.array );
  6121. this.array[ index * this.itemSize + component ] = value;
  6122. return this;
  6123. }
  6124. getX( index ) {
  6125. let x = this.array[ index * this.itemSize ];
  6126. if ( this.normalized ) x = denormalize( x, this.array );
  6127. return x;
  6128. }
  6129. setX( index, x ) {
  6130. if ( this.normalized ) x = normalize( x, this.array );
  6131. this.array[ index * this.itemSize ] = x;
  6132. return this;
  6133. }
  6134. getY( index ) {
  6135. let y = this.array[ index * this.itemSize + 1 ];
  6136. if ( this.normalized ) y = denormalize( y, this.array );
  6137. return y;
  6138. }
  6139. setY( index, y ) {
  6140. if ( this.normalized ) y = normalize( y, this.array );
  6141. this.array[ index * this.itemSize + 1 ] = y;
  6142. return this;
  6143. }
  6144. getZ( index ) {
  6145. let z = this.array[ index * this.itemSize + 2 ];
  6146. if ( this.normalized ) z = denormalize( z, this.array );
  6147. return z;
  6148. }
  6149. setZ( index, z ) {
  6150. if ( this.normalized ) z = normalize( z, this.array );
  6151. this.array[ index * this.itemSize + 2 ] = z;
  6152. return this;
  6153. }
  6154. getW( index ) {
  6155. let w = this.array[ index * this.itemSize + 3 ];
  6156. if ( this.normalized ) w = denormalize( w, this.array );
  6157. return w;
  6158. }
  6159. setW( index, w ) {
  6160. if ( this.normalized ) w = normalize( w, this.array );
  6161. this.array[ index * this.itemSize + 3 ] = w;
  6162. return this;
  6163. }
  6164. setXY( index, x, y ) {
  6165. index *= this.itemSize;
  6166. if ( this.normalized ) {
  6167. x = normalize( x, this.array );
  6168. y = normalize( y, this.array );
  6169. }
  6170. this.array[ index + 0 ] = x;
  6171. this.array[ index + 1 ] = y;
  6172. return this;
  6173. }
  6174. setXYZ( index, x, y, z ) {
  6175. index *= this.itemSize;
  6176. if ( this.normalized ) {
  6177. x = normalize( x, this.array );
  6178. y = normalize( y, this.array );
  6179. z = normalize( z, this.array );
  6180. }
  6181. this.array[ index + 0 ] = x;
  6182. this.array[ index + 1 ] = y;
  6183. this.array[ index + 2 ] = z;
  6184. return this;
  6185. }
  6186. setXYZW( index, x, y, z, w ) {
  6187. index *= this.itemSize;
  6188. if ( this.normalized ) {
  6189. x = normalize( x, this.array );
  6190. y = normalize( y, this.array );
  6191. z = normalize( z, this.array );
  6192. w = normalize( w, this.array );
  6193. }
  6194. this.array[ index + 0 ] = x;
  6195. this.array[ index + 1 ] = y;
  6196. this.array[ index + 2 ] = z;
  6197. this.array[ index + 3 ] = w;
  6198. return this;
  6199. }
  6200. onUpload( callback ) {
  6201. this.onUploadCallback = callback;
  6202. return this;
  6203. }
  6204. clone() {
  6205. return new this.constructor( this.array, this.itemSize ).copy( this );
  6206. }
  6207. toJSON() {
  6208. const data = {
  6209. itemSize: this.itemSize,
  6210. type: this.array.constructor.name,
  6211. array: Array.from( this.array ),
  6212. normalized: this.normalized
  6213. };
  6214. if ( this.name !== '' ) data.name = this.name;
  6215. if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
  6216. return data;
  6217. }
  6218. }
  6219. //
  6220. class Int8BufferAttribute extends BufferAttribute {
  6221. constructor( array, itemSize, normalized ) {
  6222. super( new Int8Array( array ), itemSize, normalized );
  6223. }
  6224. }
  6225. class Uint8BufferAttribute extends BufferAttribute {
  6226. constructor( array, itemSize, normalized ) {
  6227. super( new Uint8Array( array ), itemSize, normalized );
  6228. }
  6229. }
  6230. class Uint8ClampedBufferAttribute extends BufferAttribute {
  6231. constructor( array, itemSize, normalized ) {
  6232. super( new Uint8ClampedArray( array ), itemSize, normalized );
  6233. }
  6234. }
  6235. class Int16BufferAttribute extends BufferAttribute {
  6236. constructor( array, itemSize, normalized ) {
  6237. super( new Int16Array( array ), itemSize, normalized );
  6238. }
  6239. }
  6240. class Uint16BufferAttribute extends BufferAttribute {
  6241. constructor( array, itemSize, normalized ) {
  6242. super( new Uint16Array( array ), itemSize, normalized );
  6243. }
  6244. }
  6245. class Int32BufferAttribute extends BufferAttribute {
  6246. constructor( array, itemSize, normalized ) {
  6247. super( new Int32Array( array ), itemSize, normalized );
  6248. }
  6249. }
  6250. class Uint32BufferAttribute extends BufferAttribute {
  6251. constructor( array, itemSize, normalized ) {
  6252. super( new Uint32Array( array ), itemSize, normalized );
  6253. }
  6254. }
  6255. class Float16BufferAttribute extends BufferAttribute {
  6256. constructor( array, itemSize, normalized ) {
  6257. super( new Uint16Array( array ), itemSize, normalized );
  6258. this.isFloat16BufferAttribute = true;
  6259. }
  6260. getX( index ) {
  6261. let x = fromHalfFloat( this.array[ index * this.itemSize ] );
  6262. if ( this.normalized ) x = denormalize( x, this.array );
  6263. return x;
  6264. }
  6265. setX( index, x ) {
  6266. if ( this.normalized ) x = normalize( x, this.array );
  6267. this.array[ index * this.itemSize ] = toHalfFloat( x );
  6268. return this;
  6269. }
  6270. getY( index ) {
  6271. let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );
  6272. if ( this.normalized ) y = denormalize( y, this.array );
  6273. return y;
  6274. }
  6275. setY( index, y ) {
  6276. if ( this.normalized ) y = normalize( y, this.array );
  6277. this.array[ index * this.itemSize + 1 ] = toHalfFloat( y );
  6278. return this;
  6279. }
  6280. getZ( index ) {
  6281. let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );
  6282. if ( this.normalized ) z = denormalize( z, this.array );
  6283. return z;
  6284. }
  6285. setZ( index, z ) {
  6286. if ( this.normalized ) z = normalize( z, this.array );
  6287. this.array[ index * this.itemSize + 2 ] = toHalfFloat( z );
  6288. return this;
  6289. }
  6290. getW( index ) {
  6291. let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );
  6292. if ( this.normalized ) w = denormalize( w, this.array );
  6293. return w;
  6294. }
  6295. setW( index, w ) {
  6296. if ( this.normalized ) w = normalize( w, this.array );
  6297. this.array[ index * this.itemSize + 3 ] = toHalfFloat( w );
  6298. return this;
  6299. }
  6300. setXY( index, x, y ) {
  6301. index *= this.itemSize;
  6302. if ( this.normalized ) {
  6303. x = normalize( x, this.array );
  6304. y = normalize( y, this.array );
  6305. }
  6306. this.array[ index + 0 ] = toHalfFloat( x );
  6307. this.array[ index + 1 ] = toHalfFloat( y );
  6308. return this;
  6309. }
  6310. setXYZ( index, x, y, z ) {
  6311. index *= this.itemSize;
  6312. if ( this.normalized ) {
  6313. x = normalize( x, this.array );
  6314. y = normalize( y, this.array );
  6315. z = normalize( z, this.array );
  6316. }
  6317. this.array[ index + 0 ] = toHalfFloat( x );
  6318. this.array[ index + 1 ] = toHalfFloat( y );
  6319. this.array[ index + 2 ] = toHalfFloat( z );
  6320. return this;
  6321. }
  6322. setXYZW( index, x, y, z, w ) {
  6323. index *= this.itemSize;
  6324. if ( this.normalized ) {
  6325. x = normalize( x, this.array );
  6326. y = normalize( y, this.array );
  6327. z = normalize( z, this.array );
  6328. w = normalize( w, this.array );
  6329. }
  6330. this.array[ index + 0 ] = toHalfFloat( x );
  6331. this.array[ index + 1 ] = toHalfFloat( y );
  6332. this.array[ index + 2 ] = toHalfFloat( z );
  6333. this.array[ index + 3 ] = toHalfFloat( w );
  6334. return this;
  6335. }
  6336. }
  6337. class Float32BufferAttribute extends BufferAttribute {
  6338. constructor( array, itemSize, normalized ) {
  6339. super( new Float32Array( array ), itemSize, normalized );
  6340. }
  6341. }
  6342. let _id$1 = 0;
  6343. const _m1 = /*@__PURE__*/ new Matrix4();
  6344. const _obj = /*@__PURE__*/ new Object3D();
  6345. const _offset = /*@__PURE__*/ new Vector3();
  6346. const _box$2 = /*@__PURE__*/ new Box3();
  6347. const _boxMorphTargets = /*@__PURE__*/ new Box3();
  6348. const _vector$8 = /*@__PURE__*/ new Vector3();
  6349. class BufferGeometry extends EventDispatcher {
  6350. constructor() {
  6351. super();
  6352. this.isBufferGeometry = true;
  6353. Object.defineProperty( this, 'id', { value: _id$1 ++ } );
  6354. this.uuid = generateUUID();
  6355. this.name = '';
  6356. this.type = 'BufferGeometry';
  6357. this.index = null;
  6358. this.indirect = null;
  6359. this.attributes = {};
  6360. this.morphAttributes = {};
  6361. this.morphTargetsRelative = false;
  6362. this.groups = [];
  6363. this.boundingBox = null;
  6364. this.boundingSphere = null;
  6365. this.drawRange = { start: 0, count: Infinity };
  6366. this.userData = {};
  6367. }
  6368. getIndex() {
  6369. return this.index;
  6370. }
  6371. setIndex( index ) {
  6372. if ( Array.isArray( index ) ) {
  6373. this.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6374. } else {
  6375. this.index = index;
  6376. }
  6377. return this;
  6378. }
  6379. setIndirect( indirect ) {
  6380. this.indirect = indirect;
  6381. return this;
  6382. }
  6383. getIndirect() {
  6384. return this.indirect;
  6385. }
  6386. getAttribute( name ) {
  6387. return this.attributes[ name ];
  6388. }
  6389. setAttribute( name, attribute ) {
  6390. this.attributes[ name ] = attribute;
  6391. return this;
  6392. }
  6393. deleteAttribute( name ) {
  6394. delete this.attributes[ name ];
  6395. return this;
  6396. }
  6397. hasAttribute( name ) {
  6398. return this.attributes[ name ] !== undefined;
  6399. }
  6400. addGroup( start, count, materialIndex = 0 ) {
  6401. this.groups.push( {
  6402. start: start,
  6403. count: count,
  6404. materialIndex: materialIndex
  6405. } );
  6406. }
  6407. clearGroups() {
  6408. this.groups = [];
  6409. }
  6410. setDrawRange( start, count ) {
  6411. this.drawRange.start = start;
  6412. this.drawRange.count = count;
  6413. }
  6414. applyMatrix4( matrix ) {
  6415. const position = this.attributes.position;
  6416. if ( position !== undefined ) {
  6417. position.applyMatrix4( matrix );
  6418. position.needsUpdate = true;
  6419. }
  6420. const normal = this.attributes.normal;
  6421. if ( normal !== undefined ) {
  6422. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6423. normal.applyNormalMatrix( normalMatrix );
  6424. normal.needsUpdate = true;
  6425. }
  6426. const tangent = this.attributes.tangent;
  6427. if ( tangent !== undefined ) {
  6428. tangent.transformDirection( matrix );
  6429. tangent.needsUpdate = true;
  6430. }
  6431. if ( this.boundingBox !== null ) {
  6432. this.computeBoundingBox();
  6433. }
  6434. if ( this.boundingSphere !== null ) {
  6435. this.computeBoundingSphere();
  6436. }
  6437. return this;
  6438. }
  6439. applyQuaternion( q ) {
  6440. _m1.makeRotationFromQuaternion( q );
  6441. this.applyMatrix4( _m1 );
  6442. return this;
  6443. }
  6444. rotateX( angle ) {
  6445. // rotate geometry around world x-axis
  6446. _m1.makeRotationX( angle );
  6447. this.applyMatrix4( _m1 );
  6448. return this;
  6449. }
  6450. rotateY( angle ) {
  6451. // rotate geometry around world y-axis
  6452. _m1.makeRotationY( angle );
  6453. this.applyMatrix4( _m1 );
  6454. return this;
  6455. }
  6456. rotateZ( angle ) {
  6457. // rotate geometry around world z-axis
  6458. _m1.makeRotationZ( angle );
  6459. this.applyMatrix4( _m1 );
  6460. return this;
  6461. }
  6462. translate( x, y, z ) {
  6463. // translate geometry
  6464. _m1.makeTranslation( x, y, z );
  6465. this.applyMatrix4( _m1 );
  6466. return this;
  6467. }
  6468. scale( x, y, z ) {
  6469. // scale geometry
  6470. _m1.makeScale( x, y, z );
  6471. this.applyMatrix4( _m1 );
  6472. return this;
  6473. }
  6474. lookAt( vector ) {
  6475. _obj.lookAt( vector );
  6476. _obj.updateMatrix();
  6477. this.applyMatrix4( _obj.matrix );
  6478. return this;
  6479. }
  6480. center() {
  6481. this.computeBoundingBox();
  6482. this.boundingBox.getCenter( _offset ).negate();
  6483. this.translate( _offset.x, _offset.y, _offset.z );
  6484. return this;
  6485. }
  6486. setFromPoints( points ) {
  6487. const positionAttribute = this.getAttribute( 'position' );
  6488. if ( positionAttribute === undefined ) {
  6489. const position = [];
  6490. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6491. const point = points[ i ];
  6492. position.push( point.x, point.y, point.z || 0 );
  6493. }
  6494. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6495. } else {
  6496. const l = Math.min( points.length, positionAttribute.count ); // make sure data do not exceed buffer size
  6497. for ( let i = 0; i < l; i ++ ) {
  6498. const point = points[ i ];
  6499. positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 );
  6500. }
  6501. if ( points.length > positionAttribute.count ) {
  6502. console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' );
  6503. }
  6504. positionAttribute.needsUpdate = true;
  6505. }
  6506. return this;
  6507. }
  6508. computeBoundingBox() {
  6509. if ( this.boundingBox === null ) {
  6510. this.boundingBox = new Box3();
  6511. }
  6512. const position = this.attributes.position;
  6513. const morphAttributesPosition = this.morphAttributes.position;
  6514. if ( position && position.isGLBufferAttribute ) {
  6515. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );
  6516. this.boundingBox.set(
  6517. new Vector3( - Infinity, - Infinity, - Infinity ),
  6518. new Vector3( + Infinity, + Infinity, + Infinity )
  6519. );
  6520. return;
  6521. }
  6522. if ( position !== undefined ) {
  6523. this.boundingBox.setFromBufferAttribute( position );
  6524. // process morph attributes if present
  6525. if ( morphAttributesPosition ) {
  6526. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6527. const morphAttribute = morphAttributesPosition[ i ];
  6528. _box$2.setFromBufferAttribute( morphAttribute );
  6529. if ( this.morphTargetsRelative ) {
  6530. _vector$8.addVectors( this.boundingBox.min, _box$2.min );
  6531. this.boundingBox.expandByPoint( _vector$8 );
  6532. _vector$8.addVectors( this.boundingBox.max, _box$2.max );
  6533. this.boundingBox.expandByPoint( _vector$8 );
  6534. } else {
  6535. this.boundingBox.expandByPoint( _box$2.min );
  6536. this.boundingBox.expandByPoint( _box$2.max );
  6537. }
  6538. }
  6539. }
  6540. } else {
  6541. this.boundingBox.makeEmpty();
  6542. }
  6543. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6544. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6545. }
  6546. }
  6547. computeBoundingSphere() {
  6548. if ( this.boundingSphere === null ) {
  6549. this.boundingSphere = new Sphere();
  6550. }
  6551. const position = this.attributes.position;
  6552. const morphAttributesPosition = this.morphAttributes.position;
  6553. if ( position && position.isGLBufferAttribute ) {
  6554. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );
  6555. this.boundingSphere.set( new Vector3(), Infinity );
  6556. return;
  6557. }
  6558. if ( position ) {
  6559. // first, find the center of the bounding sphere
  6560. const center = this.boundingSphere.center;
  6561. _box$2.setFromBufferAttribute( position );
  6562. // process morph attributes if present
  6563. if ( morphAttributesPosition ) {
  6564. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6565. const morphAttribute = morphAttributesPosition[ i ];
  6566. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6567. if ( this.morphTargetsRelative ) {
  6568. _vector$8.addVectors( _box$2.min, _boxMorphTargets.min );
  6569. _box$2.expandByPoint( _vector$8 );
  6570. _vector$8.addVectors( _box$2.max, _boxMorphTargets.max );
  6571. _box$2.expandByPoint( _vector$8 );
  6572. } else {
  6573. _box$2.expandByPoint( _boxMorphTargets.min );
  6574. _box$2.expandByPoint( _boxMorphTargets.max );
  6575. }
  6576. }
  6577. }
  6578. _box$2.getCenter( center );
  6579. // second, try to find a boundingSphere with a radius smaller than the
  6580. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6581. let maxRadiusSq = 0;
  6582. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6583. _vector$8.fromBufferAttribute( position, i );
  6584. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6585. }
  6586. // process morph attributes if present
  6587. if ( morphAttributesPosition ) {
  6588. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6589. const morphAttribute = morphAttributesPosition[ i ];
  6590. const morphTargetsRelative = this.morphTargetsRelative;
  6591. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6592. _vector$8.fromBufferAttribute( morphAttribute, j );
  6593. if ( morphTargetsRelative ) {
  6594. _offset.fromBufferAttribute( position, j );
  6595. _vector$8.add( _offset );
  6596. }
  6597. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6598. }
  6599. }
  6600. }
  6601. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6602. if ( isNaN( this.boundingSphere.radius ) ) {
  6603. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6604. }
  6605. }
  6606. }
  6607. computeTangents() {
  6608. const index = this.index;
  6609. const attributes = this.attributes;
  6610. // based on http://www.terathon.com/code/tangent.html
  6611. // (per vertex tangents)
  6612. if ( index === null ||
  6613. attributes.position === undefined ||
  6614. attributes.normal === undefined ||
  6615. attributes.uv === undefined ) {
  6616. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  6617. return;
  6618. }
  6619. const positionAttribute = attributes.position;
  6620. const normalAttribute = attributes.normal;
  6621. const uvAttribute = attributes.uv;
  6622. if ( this.hasAttribute( 'tangent' ) === false ) {
  6623. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
  6624. }
  6625. const tangentAttribute = this.getAttribute( 'tangent' );
  6626. const tan1 = [], tan2 = [];
  6627. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  6628. tan1[ i ] = new Vector3();
  6629. tan2[ i ] = new Vector3();
  6630. }
  6631. const vA = new Vector3(),
  6632. vB = new Vector3(),
  6633. vC = new Vector3(),
  6634. uvA = new Vector2(),
  6635. uvB = new Vector2(),
  6636. uvC = new Vector2(),
  6637. sdir = new Vector3(),
  6638. tdir = new Vector3();
  6639. function handleTriangle( a, b, c ) {
  6640. vA.fromBufferAttribute( positionAttribute, a );
  6641. vB.fromBufferAttribute( positionAttribute, b );
  6642. vC.fromBufferAttribute( positionAttribute, c );
  6643. uvA.fromBufferAttribute( uvAttribute, a );
  6644. uvB.fromBufferAttribute( uvAttribute, b );
  6645. uvC.fromBufferAttribute( uvAttribute, c );
  6646. vB.sub( vA );
  6647. vC.sub( vA );
  6648. uvB.sub( uvA );
  6649. uvC.sub( uvA );
  6650. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  6651. // silently ignore degenerate uv triangles having coincident or colinear vertices
  6652. if ( ! isFinite( r ) ) return;
  6653. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  6654. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  6655. tan1[ a ].add( sdir );
  6656. tan1[ b ].add( sdir );
  6657. tan1[ c ].add( sdir );
  6658. tan2[ a ].add( tdir );
  6659. tan2[ b ].add( tdir );
  6660. tan2[ c ].add( tdir );
  6661. }
  6662. let groups = this.groups;
  6663. if ( groups.length === 0 ) {
  6664. groups = [ {
  6665. start: 0,
  6666. count: index.count
  6667. } ];
  6668. }
  6669. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6670. const group = groups[ i ];
  6671. const start = group.start;
  6672. const count = group.count;
  6673. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6674. handleTriangle(
  6675. index.getX( j + 0 ),
  6676. index.getX( j + 1 ),
  6677. index.getX( j + 2 )
  6678. );
  6679. }
  6680. }
  6681. const tmp = new Vector3(), tmp2 = new Vector3();
  6682. const n = new Vector3(), n2 = new Vector3();
  6683. function handleVertex( v ) {
  6684. n.fromBufferAttribute( normalAttribute, v );
  6685. n2.copy( n );
  6686. const t = tan1[ v ];
  6687. // Gram-Schmidt orthogonalize
  6688. tmp.copy( t );
  6689. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6690. // Calculate handedness
  6691. tmp2.crossVectors( n2, t );
  6692. const test = tmp2.dot( tan2[ v ] );
  6693. const w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6694. tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );
  6695. }
  6696. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6697. const group = groups[ i ];
  6698. const start = group.start;
  6699. const count = group.count;
  6700. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6701. handleVertex( index.getX( j + 0 ) );
  6702. handleVertex( index.getX( j + 1 ) );
  6703. handleVertex( index.getX( j + 2 ) );
  6704. }
  6705. }
  6706. }
  6707. computeVertexNormals() {
  6708. const index = this.index;
  6709. const positionAttribute = this.getAttribute( 'position' );
  6710. if ( positionAttribute !== undefined ) {
  6711. let normalAttribute = this.getAttribute( 'normal' );
  6712. if ( normalAttribute === undefined ) {
  6713. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6714. this.setAttribute( 'normal', normalAttribute );
  6715. } else {
  6716. // reset existing normals to zero
  6717. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6718. normalAttribute.setXYZ( i, 0, 0, 0 );
  6719. }
  6720. }
  6721. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6722. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6723. const cb = new Vector3(), ab = new Vector3();
  6724. // indexed elements
  6725. if ( index ) {
  6726. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6727. const vA = index.getX( i + 0 );
  6728. const vB = index.getX( i + 1 );
  6729. const vC = index.getX( i + 2 );
  6730. pA.fromBufferAttribute( positionAttribute, vA );
  6731. pB.fromBufferAttribute( positionAttribute, vB );
  6732. pC.fromBufferAttribute( positionAttribute, vC );
  6733. cb.subVectors( pC, pB );
  6734. ab.subVectors( pA, pB );
  6735. cb.cross( ab );
  6736. nA.fromBufferAttribute( normalAttribute, vA );
  6737. nB.fromBufferAttribute( normalAttribute, vB );
  6738. nC.fromBufferAttribute( normalAttribute, vC );
  6739. nA.add( cb );
  6740. nB.add( cb );
  6741. nC.add( cb );
  6742. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6743. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6744. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6745. }
  6746. } else {
  6747. // non-indexed elements (unconnected triangle soup)
  6748. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6749. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6750. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6751. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6752. cb.subVectors( pC, pB );
  6753. ab.subVectors( pA, pB );
  6754. cb.cross( ab );
  6755. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6756. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6757. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6758. }
  6759. }
  6760. this.normalizeNormals();
  6761. normalAttribute.needsUpdate = true;
  6762. }
  6763. }
  6764. normalizeNormals() {
  6765. const normals = this.attributes.normal;
  6766. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6767. _vector$8.fromBufferAttribute( normals, i );
  6768. _vector$8.normalize();
  6769. normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );
  6770. }
  6771. }
  6772. toNonIndexed() {
  6773. function convertBufferAttribute( attribute, indices ) {
  6774. const array = attribute.array;
  6775. const itemSize = attribute.itemSize;
  6776. const normalized = attribute.normalized;
  6777. const array2 = new array.constructor( indices.length * itemSize );
  6778. let index = 0, index2 = 0;
  6779. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6780. if ( attribute.isInterleavedBufferAttribute ) {
  6781. index = indices[ i ] * attribute.data.stride + attribute.offset;
  6782. } else {
  6783. index = indices[ i ] * itemSize;
  6784. }
  6785. for ( let j = 0; j < itemSize; j ++ ) {
  6786. array2[ index2 ++ ] = array[ index ++ ];
  6787. }
  6788. }
  6789. return new BufferAttribute( array2, itemSize, normalized );
  6790. }
  6791. //
  6792. if ( this.index === null ) {
  6793. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6794. return this;
  6795. }
  6796. const geometry2 = new BufferGeometry();
  6797. const indices = this.index.array;
  6798. const attributes = this.attributes;
  6799. // attributes
  6800. for ( const name in attributes ) {
  6801. const attribute = attributes[ name ];
  6802. const newAttribute = convertBufferAttribute( attribute, indices );
  6803. geometry2.setAttribute( name, newAttribute );
  6804. }
  6805. // morph attributes
  6806. const morphAttributes = this.morphAttributes;
  6807. for ( const name in morphAttributes ) {
  6808. const morphArray = [];
  6809. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6810. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6811. const attribute = morphAttribute[ i ];
  6812. const newAttribute = convertBufferAttribute( attribute, indices );
  6813. morphArray.push( newAttribute );
  6814. }
  6815. geometry2.morphAttributes[ name ] = morphArray;
  6816. }
  6817. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6818. // groups
  6819. const groups = this.groups;
  6820. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6821. const group = groups[ i ];
  6822. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6823. }
  6824. return geometry2;
  6825. }
  6826. toJSON() {
  6827. const data = {
  6828. metadata: {
  6829. version: 4.6,
  6830. type: 'BufferGeometry',
  6831. generator: 'BufferGeometry.toJSON'
  6832. }
  6833. };
  6834. // standard BufferGeometry serialization
  6835. data.uuid = this.uuid;
  6836. data.type = this.type;
  6837. if ( this.name !== '' ) data.name = this.name;
  6838. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6839. if ( this.parameters !== undefined ) {
  6840. const parameters = this.parameters;
  6841. for ( const key in parameters ) {
  6842. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6843. }
  6844. return data;
  6845. }
  6846. // for simplicity the code assumes attributes are not shared across geometries, see #15811
  6847. data.data = { attributes: {} };
  6848. const index = this.index;
  6849. if ( index !== null ) {
  6850. data.data.index = {
  6851. type: index.array.constructor.name,
  6852. array: Array.prototype.slice.call( index.array )
  6853. };
  6854. }
  6855. const attributes = this.attributes;
  6856. for ( const key in attributes ) {
  6857. const attribute = attributes[ key ];
  6858. data.data.attributes[ key ] = attribute.toJSON( data.data );
  6859. }
  6860. const morphAttributes = {};
  6861. let hasMorphAttributes = false;
  6862. for ( const key in this.morphAttributes ) {
  6863. const attributeArray = this.morphAttributes[ key ];
  6864. const array = [];
  6865. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6866. const attribute = attributeArray[ i ];
  6867. array.push( attribute.toJSON( data.data ) );
  6868. }
  6869. if ( array.length > 0 ) {
  6870. morphAttributes[ key ] = array;
  6871. hasMorphAttributes = true;
  6872. }
  6873. }
  6874. if ( hasMorphAttributes ) {
  6875. data.data.morphAttributes = morphAttributes;
  6876. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6877. }
  6878. const groups = this.groups;
  6879. if ( groups.length > 0 ) {
  6880. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6881. }
  6882. const boundingSphere = this.boundingSphere;
  6883. if ( boundingSphere !== null ) {
  6884. data.data.boundingSphere = {
  6885. center: boundingSphere.center.toArray(),
  6886. radius: boundingSphere.radius
  6887. };
  6888. }
  6889. return data;
  6890. }
  6891. clone() {
  6892. return new this.constructor().copy( this );
  6893. }
  6894. copy( source ) {
  6895. // reset
  6896. this.index = null;
  6897. this.attributes = {};
  6898. this.morphAttributes = {};
  6899. this.groups = [];
  6900. this.boundingBox = null;
  6901. this.boundingSphere = null;
  6902. // used for storing cloned, shared data
  6903. const data = {};
  6904. // name
  6905. this.name = source.name;
  6906. // index
  6907. const index = source.index;
  6908. if ( index !== null ) {
  6909. this.setIndex( index.clone( data ) );
  6910. }
  6911. // attributes
  6912. const attributes = source.attributes;
  6913. for ( const name in attributes ) {
  6914. const attribute = attributes[ name ];
  6915. this.setAttribute( name, attribute.clone( data ) );
  6916. }
  6917. // morph attributes
  6918. const morphAttributes = source.morphAttributes;
  6919. for ( const name in morphAttributes ) {
  6920. const array = [];
  6921. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6922. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6923. array.push( morphAttribute[ i ].clone( data ) );
  6924. }
  6925. this.morphAttributes[ name ] = array;
  6926. }
  6927. this.morphTargetsRelative = source.morphTargetsRelative;
  6928. // groups
  6929. const groups = source.groups;
  6930. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6931. const group = groups[ i ];
  6932. this.addGroup( group.start, group.count, group.materialIndex );
  6933. }
  6934. // bounding box
  6935. const boundingBox = source.boundingBox;
  6936. if ( boundingBox !== null ) {
  6937. this.boundingBox = boundingBox.clone();
  6938. }
  6939. // bounding sphere
  6940. const boundingSphere = source.boundingSphere;
  6941. if ( boundingSphere !== null ) {
  6942. this.boundingSphere = boundingSphere.clone();
  6943. }
  6944. // draw range
  6945. this.drawRange.start = source.drawRange.start;
  6946. this.drawRange.count = source.drawRange.count;
  6947. // user data
  6948. this.userData = source.userData;
  6949. return this;
  6950. }
  6951. dispose() {
  6952. this.dispatchEvent( { type: 'dispose' } );
  6953. }
  6954. }
  6955. const _inverseMatrix$3 = /*@__PURE__*/ new Matrix4();
  6956. const _ray$3 = /*@__PURE__*/ new Ray();
  6957. const _sphere$6 = /*@__PURE__*/ new Sphere();
  6958. const _sphereHitAt = /*@__PURE__*/ new Vector3();
  6959. const _vA$1 = /*@__PURE__*/ new Vector3();
  6960. const _vB$1 = /*@__PURE__*/ new Vector3();
  6961. const _vC$1 = /*@__PURE__*/ new Vector3();
  6962. const _tempA = /*@__PURE__*/ new Vector3();
  6963. const _morphA = /*@__PURE__*/ new Vector3();
  6964. const _intersectionPoint = /*@__PURE__*/ new Vector3();
  6965. const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
  6966. class Mesh extends Object3D {
  6967. constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6968. super();
  6969. this.isMesh = true;
  6970. this.type = 'Mesh';
  6971. this.geometry = geometry;
  6972. this.material = material;
  6973. this.updateMorphTargets();
  6974. }
  6975. copy( source, recursive ) {
  6976. super.copy( source, recursive );
  6977. if ( source.morphTargetInfluences !== undefined ) {
  6978. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6979. }
  6980. if ( source.morphTargetDictionary !== undefined ) {
  6981. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6982. }
  6983. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  6984. this.geometry = source.geometry;
  6985. return this;
  6986. }
  6987. updateMorphTargets() {
  6988. const geometry = this.geometry;
  6989. const morphAttributes = geometry.morphAttributes;
  6990. const keys = Object.keys( morphAttributes );
  6991. if ( keys.length > 0 ) {
  6992. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  6993. if ( morphAttribute !== undefined ) {
  6994. this.morphTargetInfluences = [];
  6995. this.morphTargetDictionary = {};
  6996. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  6997. const name = morphAttribute[ m ].name || String( m );
  6998. this.morphTargetInfluences.push( 0 );
  6999. this.morphTargetDictionary[ name ] = m;
  7000. }
  7001. }
  7002. }
  7003. }
  7004. getVertexPosition( index, target ) {
  7005. const geometry = this.geometry;
  7006. const position = geometry.attributes.position;
  7007. const morphPosition = geometry.morphAttributes.position;
  7008. const morphTargetsRelative = geometry.morphTargetsRelative;
  7009. target.fromBufferAttribute( position, index );
  7010. const morphInfluences = this.morphTargetInfluences;
  7011. if ( morphPosition && morphInfluences ) {
  7012. _morphA.set( 0, 0, 0 );
  7013. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  7014. const influence = morphInfluences[ i ];
  7015. const morphAttribute = morphPosition[ i ];
  7016. if ( influence === 0 ) continue;
  7017. _tempA.fromBufferAttribute( morphAttribute, index );
  7018. if ( morphTargetsRelative ) {
  7019. _morphA.addScaledVector( _tempA, influence );
  7020. } else {
  7021. _morphA.addScaledVector( _tempA.sub( target ), influence );
  7022. }
  7023. }
  7024. target.add( _morphA );
  7025. }
  7026. return target;
  7027. }
  7028. raycast( raycaster, intersects ) {
  7029. const geometry = this.geometry;
  7030. const material = this.material;
  7031. const matrixWorld = this.matrixWorld;
  7032. if ( material === undefined ) return;
  7033. // test with bounding sphere in world space
  7034. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7035. _sphere$6.copy( geometry.boundingSphere );
  7036. _sphere$6.applyMatrix4( matrixWorld );
  7037. // check distance from ray origin to bounding sphere
  7038. _ray$3.copy( raycaster.ray ).recast( raycaster.near );
  7039. if ( _sphere$6.containsPoint( _ray$3.origin ) === false ) {
  7040. if ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return;
  7041. if ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return;
  7042. }
  7043. // convert ray to local space of mesh
  7044. _inverseMatrix$3.copy( matrixWorld ).invert();
  7045. _ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 );
  7046. // test with bounding box in local space
  7047. if ( geometry.boundingBox !== null ) {
  7048. if ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return;
  7049. }
  7050. // test for intersections with geometry
  7051. this._computeIntersections( raycaster, intersects, _ray$3 );
  7052. }
  7053. _computeIntersections( raycaster, intersects, rayLocalSpace ) {
  7054. let intersection;
  7055. const geometry = this.geometry;
  7056. const material = this.material;
  7057. const index = geometry.index;
  7058. const position = geometry.attributes.position;
  7059. const uv = geometry.attributes.uv;
  7060. const uv1 = geometry.attributes.uv1;
  7061. const normal = geometry.attributes.normal;
  7062. const groups = geometry.groups;
  7063. const drawRange = geometry.drawRange;
  7064. if ( index !== null ) {
  7065. // indexed buffer geometry
  7066. if ( Array.isArray( material ) ) {
  7067. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7068. const group = groups[ i ];
  7069. const groupMaterial = material[ group.materialIndex ];
  7070. const start = Math.max( group.start, drawRange.start );
  7071. const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7072. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7073. const a = index.getX( j );
  7074. const b = index.getX( j + 1 );
  7075. const c = index.getX( j + 2 );
  7076. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7077. if ( intersection ) {
  7078. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  7079. intersection.face.materialIndex = group.materialIndex;
  7080. intersects.push( intersection );
  7081. }
  7082. }
  7083. }
  7084. } else {
  7085. const start = Math.max( 0, drawRange.start );
  7086. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  7087. for ( let i = start, il = end; i < il; i += 3 ) {
  7088. const a = index.getX( i );
  7089. const b = index.getX( i + 1 );
  7090. const c = index.getX( i + 2 );
  7091. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7092. if ( intersection ) {
  7093. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  7094. intersects.push( intersection );
  7095. }
  7096. }
  7097. }
  7098. } else if ( position !== undefined ) {
  7099. // non-indexed buffer geometry
  7100. if ( Array.isArray( material ) ) {
  7101. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7102. const group = groups[ i ];
  7103. const groupMaterial = material[ group.materialIndex ];
  7104. const start = Math.max( group.start, drawRange.start );
  7105. const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7106. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7107. const a = j;
  7108. const b = j + 1;
  7109. const c = j + 2;
  7110. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7111. if ( intersection ) {
  7112. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  7113. intersection.face.materialIndex = group.materialIndex;
  7114. intersects.push( intersection );
  7115. }
  7116. }
  7117. }
  7118. } else {
  7119. const start = Math.max( 0, drawRange.start );
  7120. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  7121. for ( let i = start, il = end; i < il; i += 3 ) {
  7122. const a = i;
  7123. const b = i + 1;
  7124. const c = i + 2;
  7125. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7126. if ( intersection ) {
  7127. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  7128. intersects.push( intersection );
  7129. }
  7130. }
  7131. }
  7132. }
  7133. }
  7134. }
  7135. function checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) {
  7136. let intersect;
  7137. if ( material.side === BackSide ) {
  7138. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  7139. } else {
  7140. intersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point );
  7141. }
  7142. if ( intersect === null ) return null;
  7143. _intersectionPointWorld.copy( point );
  7144. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  7145. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  7146. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  7147. return {
  7148. distance: distance,
  7149. point: _intersectionPointWorld.clone(),
  7150. object: object
  7151. };
  7152. }
  7153. function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) {
  7154. object.getVertexPosition( a, _vA$1 );
  7155. object.getVertexPosition( b, _vB$1 );
  7156. object.getVertexPosition( c, _vC$1 );
  7157. const intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );
  7158. if ( intersection ) {
  7159. const barycoord = new Vector3();
  7160. Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord );
  7161. if ( uv ) {
  7162. intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() );
  7163. }
  7164. if ( uv1 ) {
  7165. intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() );
  7166. }
  7167. if ( normal ) {
  7168. intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );
  7169. if ( intersection.normal.dot( ray.direction ) > 0 ) {
  7170. intersection.normal.multiplyScalar( - 1 );
  7171. }
  7172. }
  7173. const face = {
  7174. a: a,
  7175. b: b,
  7176. c: c,
  7177. normal: new Vector3(),
  7178. materialIndex: 0
  7179. };
  7180. Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
  7181. intersection.face = face;
  7182. intersection.barycoord = barycoord;
  7183. }
  7184. return intersection;
  7185. }
  7186. class BoxGeometry extends BufferGeometry {
  7187. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  7188. super();
  7189. this.type = 'BoxGeometry';
  7190. this.parameters = {
  7191. width: width,
  7192. height: height,
  7193. depth: depth,
  7194. widthSegments: widthSegments,
  7195. heightSegments: heightSegments,
  7196. depthSegments: depthSegments
  7197. };
  7198. const scope = this;
  7199. // segments
  7200. widthSegments = Math.floor( widthSegments );
  7201. heightSegments = Math.floor( heightSegments );
  7202. depthSegments = Math.floor( depthSegments );
  7203. // buffers
  7204. const indices = [];
  7205. const vertices = [];
  7206. const normals = [];
  7207. const uvs = [];
  7208. // helper variables
  7209. let numberOfVertices = 0;
  7210. let groupStart = 0;
  7211. // build each side of the box geometry
  7212. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7213. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7214. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7215. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7216. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7217. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7218. // build geometry
  7219. this.setIndex( indices );
  7220. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7221. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7222. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7223. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7224. const segmentWidth = width / gridX;
  7225. const segmentHeight = height / gridY;
  7226. const widthHalf = width / 2;
  7227. const heightHalf = height / 2;
  7228. const depthHalf = depth / 2;
  7229. const gridX1 = gridX + 1;
  7230. const gridY1 = gridY + 1;
  7231. let vertexCounter = 0;
  7232. let groupCount = 0;
  7233. const vector = new Vector3();
  7234. // generate vertices, normals and uvs
  7235. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7236. const y = iy * segmentHeight - heightHalf;
  7237. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7238. const x = ix * segmentWidth - widthHalf;
  7239. // set values to correct vector component
  7240. vector[ u ] = x * udir;
  7241. vector[ v ] = y * vdir;
  7242. vector[ w ] = depthHalf;
  7243. // now apply vector to vertex buffer
  7244. vertices.push( vector.x, vector.y, vector.z );
  7245. // set values to correct vector component
  7246. vector[ u ] = 0;
  7247. vector[ v ] = 0;
  7248. vector[ w ] = depth > 0 ? 1 : - 1;
  7249. // now apply vector to normal buffer
  7250. normals.push( vector.x, vector.y, vector.z );
  7251. // uvs
  7252. uvs.push( ix / gridX );
  7253. uvs.push( 1 - ( iy / gridY ) );
  7254. // counters
  7255. vertexCounter += 1;
  7256. }
  7257. }
  7258. // indices
  7259. // 1. you need three indices to draw a single face
  7260. // 2. a single segment consists of two faces
  7261. // 3. so we need to generate six (2*3) indices per segment
  7262. for ( let iy = 0; iy < gridY; iy ++ ) {
  7263. for ( let ix = 0; ix < gridX; ix ++ ) {
  7264. const a = numberOfVertices + ix + gridX1 * iy;
  7265. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7266. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7267. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7268. // faces
  7269. indices.push( a, b, d );
  7270. indices.push( b, c, d );
  7271. // increase counter
  7272. groupCount += 6;
  7273. }
  7274. }
  7275. // add a group to the geometry. this will ensure multi material support
  7276. scope.addGroup( groupStart, groupCount, materialIndex );
  7277. // calculate new start value for groups
  7278. groupStart += groupCount;
  7279. // update total number of vertices
  7280. numberOfVertices += vertexCounter;
  7281. }
  7282. }
  7283. copy( source ) {
  7284. super.copy( source );
  7285. this.parameters = Object.assign( {}, source.parameters );
  7286. return this;
  7287. }
  7288. static fromJSON( data ) {
  7289. return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
  7290. }
  7291. }
  7292. /**
  7293. * Uniform Utilities
  7294. */
  7295. function cloneUniforms( src ) {
  7296. const dst = {};
  7297. for ( const u in src ) {
  7298. dst[ u ] = {};
  7299. for ( const p in src[ u ] ) {
  7300. const property = src[ u ][ p ];
  7301. if ( property && ( property.isColor ||
  7302. property.isMatrix3 || property.isMatrix4 ||
  7303. property.isVector2 || property.isVector3 || property.isVector4 ||
  7304. property.isTexture || property.isQuaternion ) ) {
  7305. if ( property.isRenderTargetTexture ) {
  7306. console.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' );
  7307. dst[ u ][ p ] = null;
  7308. } else {
  7309. dst[ u ][ p ] = property.clone();
  7310. }
  7311. } else if ( Array.isArray( property ) ) {
  7312. dst[ u ][ p ] = property.slice();
  7313. } else {
  7314. dst[ u ][ p ] = property;
  7315. }
  7316. }
  7317. }
  7318. return dst;
  7319. }
  7320. function mergeUniforms( uniforms ) {
  7321. const merged = {};
  7322. for ( let u = 0; u < uniforms.length; u ++ ) {
  7323. const tmp = cloneUniforms( uniforms[ u ] );
  7324. for ( const p in tmp ) {
  7325. merged[ p ] = tmp[ p ];
  7326. }
  7327. }
  7328. return merged;
  7329. }
  7330. function cloneUniformsGroups( src ) {
  7331. const dst = [];
  7332. for ( let u = 0; u < src.length; u ++ ) {
  7333. dst.push( src[ u ].clone() );
  7334. }
  7335. return dst;
  7336. }
  7337. function getUnlitUniformColorSpace( renderer ) {
  7338. const currentRenderTarget = renderer.getRenderTarget();
  7339. if ( currentRenderTarget === null ) {
  7340. // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
  7341. return renderer.outputColorSpace;
  7342. }
  7343. // https://github.com/mrdoob/three.js/issues/27868
  7344. if ( currentRenderTarget.isXRRenderTarget === true ) {
  7345. return currentRenderTarget.texture.colorSpace;
  7346. }
  7347. return ColorManagement.workingColorSpace;
  7348. }
  7349. // Legacy
  7350. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7351. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7352. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7353. class ShaderMaterial extends Material {
  7354. constructor( parameters ) {
  7355. super();
  7356. this.isShaderMaterial = true;
  7357. this.type = 'ShaderMaterial';
  7358. this.defines = {};
  7359. this.uniforms = {};
  7360. this.uniformsGroups = [];
  7361. this.vertexShader = default_vertex;
  7362. this.fragmentShader = default_fragment;
  7363. this.linewidth = 1;
  7364. this.wireframe = false;
  7365. this.wireframeLinewidth = 1;
  7366. this.fog = false; // set to use scene fog
  7367. this.lights = false; // set to use scene lights
  7368. this.clipping = false; // set to use user-defined clipping planes
  7369. this.forceSinglePass = true;
  7370. this.extensions = {
  7371. clipCullDistance: false, // set to use vertex shader clipping
  7372. multiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID
  7373. };
  7374. // When rendered geometry doesn't include these attributes but the material does,
  7375. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7376. this.defaultAttributeValues = {
  7377. 'color': [ 1, 1, 1 ],
  7378. 'uv': [ 0, 0 ],
  7379. 'uv1': [ 0, 0 ]
  7380. };
  7381. this.index0AttributeName = undefined;
  7382. this.uniformsNeedUpdate = false;
  7383. this.glslVersion = null;
  7384. if ( parameters !== undefined ) {
  7385. this.setValues( parameters );
  7386. }
  7387. }
  7388. copy( source ) {
  7389. super.copy( source );
  7390. this.fragmentShader = source.fragmentShader;
  7391. this.vertexShader = source.vertexShader;
  7392. this.uniforms = cloneUniforms( source.uniforms );
  7393. this.uniformsGroups = cloneUniformsGroups( source.uniformsGroups );
  7394. this.defines = Object.assign( {}, source.defines );
  7395. this.wireframe = source.wireframe;
  7396. this.wireframeLinewidth = source.wireframeLinewidth;
  7397. this.fog = source.fog;
  7398. this.lights = source.lights;
  7399. this.clipping = source.clipping;
  7400. this.extensions = Object.assign( {}, source.extensions );
  7401. this.glslVersion = source.glslVersion;
  7402. return this;
  7403. }
  7404. toJSON( meta ) {
  7405. const data = super.toJSON( meta );
  7406. data.glslVersion = this.glslVersion;
  7407. data.uniforms = {};
  7408. for ( const name in this.uniforms ) {
  7409. const uniform = this.uniforms[ name ];
  7410. const value = uniform.value;
  7411. if ( value && value.isTexture ) {
  7412. data.uniforms[ name ] = {
  7413. type: 't',
  7414. value: value.toJSON( meta ).uuid
  7415. };
  7416. } else if ( value && value.isColor ) {
  7417. data.uniforms[ name ] = {
  7418. type: 'c',
  7419. value: value.getHex()
  7420. };
  7421. } else if ( value && value.isVector2 ) {
  7422. data.uniforms[ name ] = {
  7423. type: 'v2',
  7424. value: value.toArray()
  7425. };
  7426. } else if ( value && value.isVector3 ) {
  7427. data.uniforms[ name ] = {
  7428. type: 'v3',
  7429. value: value.toArray()
  7430. };
  7431. } else if ( value && value.isVector4 ) {
  7432. data.uniforms[ name ] = {
  7433. type: 'v4',
  7434. value: value.toArray()
  7435. };
  7436. } else if ( value && value.isMatrix3 ) {
  7437. data.uniforms[ name ] = {
  7438. type: 'm3',
  7439. value: value.toArray()
  7440. };
  7441. } else if ( value && value.isMatrix4 ) {
  7442. data.uniforms[ name ] = {
  7443. type: 'm4',
  7444. value: value.toArray()
  7445. };
  7446. } else {
  7447. data.uniforms[ name ] = {
  7448. value: value
  7449. };
  7450. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7451. }
  7452. }
  7453. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7454. data.vertexShader = this.vertexShader;
  7455. data.fragmentShader = this.fragmentShader;
  7456. data.lights = this.lights;
  7457. data.clipping = this.clipping;
  7458. const extensions = {};
  7459. for ( const key in this.extensions ) {
  7460. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7461. }
  7462. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7463. return data;
  7464. }
  7465. }
  7466. class Camera extends Object3D {
  7467. constructor() {
  7468. super();
  7469. this.isCamera = true;
  7470. this.type = 'Camera';
  7471. this.matrixWorldInverse = new Matrix4();
  7472. this.projectionMatrix = new Matrix4();
  7473. this.projectionMatrixInverse = new Matrix4();
  7474. this.coordinateSystem = WebGLCoordinateSystem;
  7475. }
  7476. copy( source, recursive ) {
  7477. super.copy( source, recursive );
  7478. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7479. this.projectionMatrix.copy( source.projectionMatrix );
  7480. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7481. this.coordinateSystem = source.coordinateSystem;
  7482. return this;
  7483. }
  7484. getWorldDirection( target ) {
  7485. return super.getWorldDirection( target ).negate();
  7486. }
  7487. updateMatrixWorld( force ) {
  7488. super.updateMatrixWorld( force );
  7489. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7490. }
  7491. updateWorldMatrix( updateParents, updateChildren ) {
  7492. super.updateWorldMatrix( updateParents, updateChildren );
  7493. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7494. }
  7495. clone() {
  7496. return new this.constructor().copy( this );
  7497. }
  7498. }
  7499. const _v3$1 = /*@__PURE__*/ new Vector3();
  7500. const _minTarget = /*@__PURE__*/ new Vector2();
  7501. const _maxTarget = /*@__PURE__*/ new Vector2();
  7502. class PerspectiveCamera extends Camera {
  7503. constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7504. super();
  7505. this.isPerspectiveCamera = true;
  7506. this.type = 'PerspectiveCamera';
  7507. this.fov = fov;
  7508. this.zoom = 1;
  7509. this.near = near;
  7510. this.far = far;
  7511. this.focus = 10;
  7512. this.aspect = aspect;
  7513. this.view = null;
  7514. this.filmGauge = 35; // width of the film (default in millimeters)
  7515. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7516. this.updateProjectionMatrix();
  7517. }
  7518. copy( source, recursive ) {
  7519. super.copy( source, recursive );
  7520. this.fov = source.fov;
  7521. this.zoom = source.zoom;
  7522. this.near = source.near;
  7523. this.far = source.far;
  7524. this.focus = source.focus;
  7525. this.aspect = source.aspect;
  7526. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7527. this.filmGauge = source.filmGauge;
  7528. this.filmOffset = source.filmOffset;
  7529. return this;
  7530. }
  7531. /**
  7532. * Sets the FOV by focal length in respect to the current .filmGauge.
  7533. *
  7534. * The default film gauge is 35, so that the focal length can be specified for
  7535. * a 35mm (full frame) camera.
  7536. *
  7537. * Values for focal length and film gauge must have the same unit.
  7538. */
  7539. setFocalLength( focalLength ) {
  7540. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  7541. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7542. this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
  7543. this.updateProjectionMatrix();
  7544. }
  7545. /**
  7546. * Calculates the focal length from the current .fov and .filmGauge.
  7547. */
  7548. getFocalLength() {
  7549. const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
  7550. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7551. }
  7552. getEffectiveFOV() {
  7553. return RAD2DEG * 2 * Math.atan(
  7554. Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7555. }
  7556. getFilmWidth() {
  7557. // film not completely covered in portrait format (aspect < 1)
  7558. return this.filmGauge * Math.min( this.aspect, 1 );
  7559. }
  7560. getFilmHeight() {
  7561. // film not completely covered in landscape format (aspect > 1)
  7562. return this.filmGauge / Math.max( this.aspect, 1 );
  7563. }
  7564. /**
  7565. * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  7566. * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
  7567. */
  7568. getViewBounds( distance, minTarget, maxTarget ) {
  7569. _v3$1.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7570. minTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7571. _v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7572. maxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7573. }
  7574. /**
  7575. * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
  7576. * Copies the result into the target Vector2, where x is width and y is height.
  7577. */
  7578. getViewSize( distance, target ) {
  7579. this.getViewBounds( distance, _minTarget, _maxTarget );
  7580. return target.subVectors( _maxTarget, _minTarget );
  7581. }
  7582. /**
  7583. * Sets an offset in a larger frustum. This is useful for multi-window or
  7584. * multi-monitor/multi-machine setups.
  7585. *
  7586. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7587. * the monitors are in grid like this
  7588. *
  7589. * +---+---+---+
  7590. * | A | B | C |
  7591. * +---+---+---+
  7592. * | D | E | F |
  7593. * +---+---+---+
  7594. *
  7595. * then for each monitor you would call it like this
  7596. *
  7597. * const w = 1920;
  7598. * const h = 1080;
  7599. * const fullWidth = w * 3;
  7600. * const fullHeight = h * 2;
  7601. *
  7602. * --A--
  7603. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7604. * --B--
  7605. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7606. * --C--
  7607. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7608. * --D--
  7609. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7610. * --E--
  7611. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7612. * --F--
  7613. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7614. *
  7615. * Note there is no reason monitors have to be the same size or in a grid.
  7616. */
  7617. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  7618. this.aspect = fullWidth / fullHeight;
  7619. if ( this.view === null ) {
  7620. this.view = {
  7621. enabled: true,
  7622. fullWidth: 1,
  7623. fullHeight: 1,
  7624. offsetX: 0,
  7625. offsetY: 0,
  7626. width: 1,
  7627. height: 1
  7628. };
  7629. }
  7630. this.view.enabled = true;
  7631. this.view.fullWidth = fullWidth;
  7632. this.view.fullHeight = fullHeight;
  7633. this.view.offsetX = x;
  7634. this.view.offsetY = y;
  7635. this.view.width = width;
  7636. this.view.height = height;
  7637. this.updateProjectionMatrix();
  7638. }
  7639. clearViewOffset() {
  7640. if ( this.view !== null ) {
  7641. this.view.enabled = false;
  7642. }
  7643. this.updateProjectionMatrix();
  7644. }
  7645. updateProjectionMatrix() {
  7646. const near = this.near;
  7647. let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7648. let height = 2 * top;
  7649. let width = this.aspect * height;
  7650. let left = - 0.5 * width;
  7651. const view = this.view;
  7652. if ( this.view !== null && this.view.enabled ) {
  7653. const fullWidth = view.fullWidth,
  7654. fullHeight = view.fullHeight;
  7655. left += view.offsetX * width / fullWidth;
  7656. top -= view.offsetY * height / fullHeight;
  7657. width *= view.width / fullWidth;
  7658. height *= view.height / fullHeight;
  7659. }
  7660. const skew = this.filmOffset;
  7661. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7662. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
  7663. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7664. }
  7665. toJSON( meta ) {
  7666. const data = super.toJSON( meta );
  7667. data.object.fov = this.fov;
  7668. data.object.zoom = this.zoom;
  7669. data.object.near = this.near;
  7670. data.object.far = this.far;
  7671. data.object.focus = this.focus;
  7672. data.object.aspect = this.aspect;
  7673. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7674. data.object.filmGauge = this.filmGauge;
  7675. data.object.filmOffset = this.filmOffset;
  7676. return data;
  7677. }
  7678. }
  7679. const fov = - 90; // negative fov is not an error
  7680. const aspect = 1;
  7681. class CubeCamera extends Object3D {
  7682. constructor( near, far, renderTarget ) {
  7683. super();
  7684. this.type = 'CubeCamera';
  7685. this.renderTarget = renderTarget;
  7686. this.coordinateSystem = null;
  7687. this.activeMipmapLevel = 0;
  7688. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7689. cameraPX.layers = this.layers;
  7690. this.add( cameraPX );
  7691. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7692. cameraNX.layers = this.layers;
  7693. this.add( cameraNX );
  7694. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7695. cameraPY.layers = this.layers;
  7696. this.add( cameraPY );
  7697. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7698. cameraNY.layers = this.layers;
  7699. this.add( cameraNY );
  7700. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7701. cameraPZ.layers = this.layers;
  7702. this.add( cameraPZ );
  7703. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7704. cameraNZ.layers = this.layers;
  7705. this.add( cameraNZ );
  7706. }
  7707. updateCoordinateSystem() {
  7708. const coordinateSystem = this.coordinateSystem;
  7709. const cameras = this.children.concat();
  7710. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
  7711. for ( const camera of cameras ) this.remove( camera );
  7712. if ( coordinateSystem === WebGLCoordinateSystem ) {
  7713. cameraPX.up.set( 0, 1, 0 );
  7714. cameraPX.lookAt( 1, 0, 0 );
  7715. cameraNX.up.set( 0, 1, 0 );
  7716. cameraNX.lookAt( - 1, 0, 0 );
  7717. cameraPY.up.set( 0, 0, - 1 );
  7718. cameraPY.lookAt( 0, 1, 0 );
  7719. cameraNY.up.set( 0, 0, 1 );
  7720. cameraNY.lookAt( 0, - 1, 0 );
  7721. cameraPZ.up.set( 0, 1, 0 );
  7722. cameraPZ.lookAt( 0, 0, 1 );
  7723. cameraNZ.up.set( 0, 1, 0 );
  7724. cameraNZ.lookAt( 0, 0, - 1 );
  7725. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  7726. cameraPX.up.set( 0, - 1, 0 );
  7727. cameraPX.lookAt( - 1, 0, 0 );
  7728. cameraNX.up.set( 0, - 1, 0 );
  7729. cameraNX.lookAt( 1, 0, 0 );
  7730. cameraPY.up.set( 0, 0, 1 );
  7731. cameraPY.lookAt( 0, 1, 0 );
  7732. cameraNY.up.set( 0, 0, - 1 );
  7733. cameraNY.lookAt( 0, - 1, 0 );
  7734. cameraPZ.up.set( 0, - 1, 0 );
  7735. cameraPZ.lookAt( 0, 0, 1 );
  7736. cameraNZ.up.set( 0, - 1, 0 );
  7737. cameraNZ.lookAt( 0, 0, - 1 );
  7738. } else {
  7739. throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
  7740. }
  7741. for ( const camera of cameras ) {
  7742. this.add( camera );
  7743. camera.updateMatrixWorld();
  7744. }
  7745. }
  7746. update( renderer, scene ) {
  7747. if ( this.parent === null ) this.updateMatrixWorld();
  7748. const { renderTarget, activeMipmapLevel } = this;
  7749. if ( this.coordinateSystem !== renderer.coordinateSystem ) {
  7750. this.coordinateSystem = renderer.coordinateSystem;
  7751. this.updateCoordinateSystem();
  7752. }
  7753. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7754. const currentRenderTarget = renderer.getRenderTarget();
  7755. const currentActiveCubeFace = renderer.getActiveCubeFace();
  7756. const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
  7757. const currentXrEnabled = renderer.xr.enabled;
  7758. renderer.xr.enabled = false;
  7759. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7760. renderTarget.texture.generateMipmaps = false;
  7761. renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
  7762. renderer.render( scene, cameraPX );
  7763. renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
  7764. renderer.render( scene, cameraNX );
  7765. renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
  7766. renderer.render( scene, cameraPY );
  7767. renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
  7768. renderer.render( scene, cameraNY );
  7769. renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
  7770. renderer.render( scene, cameraPZ );
  7771. // mipmaps are generated during the last call of render()
  7772. // at this point, all sides of the cube render target are defined
  7773. renderTarget.texture.generateMipmaps = generateMipmaps;
  7774. renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
  7775. renderer.render( scene, cameraNZ );
  7776. renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
  7777. renderer.xr.enabled = currentXrEnabled;
  7778. renderTarget.texture.needsPMREMUpdate = true;
  7779. }
  7780. }
  7781. class CubeTexture extends Texture {
  7782. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {
  7783. images = images !== undefined ? images : [];
  7784. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7785. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  7786. this.isCubeTexture = true;
  7787. this.flipY = false;
  7788. }
  7789. get images() {
  7790. return this.image;
  7791. }
  7792. set images( value ) {
  7793. this.image = value;
  7794. }
  7795. }
  7796. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7797. constructor( size = 1, options = {} ) {
  7798. super( size, size, options );
  7799. this.isWebGLCubeRenderTarget = true;
  7800. const image = { width: size, height: size, depth: 1 };
  7801. const images = [ image, image, image, image, image, image ];
  7802. this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  7803. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7804. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7805. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7806. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7807. // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
  7808. // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
  7809. this.texture.isRenderTargetTexture = true;
  7810. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7811. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7812. }
  7813. fromEquirectangularTexture( renderer, texture ) {
  7814. this.texture.type = texture.type;
  7815. this.texture.colorSpace = texture.colorSpace;
  7816. this.texture.generateMipmaps = texture.generateMipmaps;
  7817. this.texture.minFilter = texture.minFilter;
  7818. this.texture.magFilter = texture.magFilter;
  7819. const shader = {
  7820. uniforms: {
  7821. tEquirect: { value: null },
  7822. },
  7823. vertexShader: /* glsl */`
  7824. varying vec3 vWorldDirection;
  7825. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7826. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7827. }
  7828. void main() {
  7829. vWorldDirection = transformDirection( position, modelMatrix );
  7830. #include <begin_vertex>
  7831. #include <project_vertex>
  7832. }
  7833. `,
  7834. fragmentShader: /* glsl */`
  7835. uniform sampler2D tEquirect;
  7836. varying vec3 vWorldDirection;
  7837. #include <common>
  7838. void main() {
  7839. vec3 direction = normalize( vWorldDirection );
  7840. vec2 sampleUV = equirectUv( direction );
  7841. gl_FragColor = texture2D( tEquirect, sampleUV );
  7842. }
  7843. `
  7844. };
  7845. const geometry = new BoxGeometry( 5, 5, 5 );
  7846. const material = new ShaderMaterial( {
  7847. name: 'CubemapFromEquirect',
  7848. uniforms: cloneUniforms( shader.uniforms ),
  7849. vertexShader: shader.vertexShader,
  7850. fragmentShader: shader.fragmentShader,
  7851. side: BackSide,
  7852. blending: NoBlending
  7853. } );
  7854. material.uniforms.tEquirect.value = texture;
  7855. const mesh = new Mesh( geometry, material );
  7856. const currentMinFilter = texture.minFilter;
  7857. // Avoid blurred poles
  7858. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7859. const camera = new CubeCamera( 1, 10, this );
  7860. camera.update( renderer, mesh );
  7861. texture.minFilter = currentMinFilter;
  7862. mesh.geometry.dispose();
  7863. mesh.material.dispose();
  7864. return this;
  7865. }
  7866. clear( renderer, color, depth, stencil ) {
  7867. const currentRenderTarget = renderer.getRenderTarget();
  7868. for ( let i = 0; i < 6; i ++ ) {
  7869. renderer.setRenderTarget( this, i );
  7870. renderer.clear( color, depth, stencil );
  7871. }
  7872. renderer.setRenderTarget( currentRenderTarget );
  7873. }
  7874. }
  7875. class FogExp2 {
  7876. constructor( color, density = 0.00025 ) {
  7877. this.isFogExp2 = true;
  7878. this.name = '';
  7879. this.color = new Color( color );
  7880. this.density = density;
  7881. }
  7882. clone() {
  7883. return new FogExp2( this.color, this.density );
  7884. }
  7885. toJSON( /* meta */ ) {
  7886. return {
  7887. type: 'FogExp2',
  7888. name: this.name,
  7889. color: this.color.getHex(),
  7890. density: this.density
  7891. };
  7892. }
  7893. }
  7894. class Fog {
  7895. constructor( color, near = 1, far = 1000 ) {
  7896. this.isFog = true;
  7897. this.name = '';
  7898. this.color = new Color( color );
  7899. this.near = near;
  7900. this.far = far;
  7901. }
  7902. clone() {
  7903. return new Fog( this.color, this.near, this.far );
  7904. }
  7905. toJSON( /* meta */ ) {
  7906. return {
  7907. type: 'Fog',
  7908. name: this.name,
  7909. color: this.color.getHex(),
  7910. near: this.near,
  7911. far: this.far
  7912. };
  7913. }
  7914. }
  7915. class Scene extends Object3D {
  7916. constructor() {
  7917. super();
  7918. this.isScene = true;
  7919. this.type = 'Scene';
  7920. this.background = null;
  7921. this.environment = null;
  7922. this.fog = null;
  7923. this.backgroundBlurriness = 0;
  7924. this.backgroundIntensity = 1;
  7925. this.backgroundRotation = new Euler();
  7926. this.environmentIntensity = 1;
  7927. this.environmentRotation = new Euler();
  7928. this.overrideMaterial = null;
  7929. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  7930. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
  7931. }
  7932. }
  7933. copy( source, recursive ) {
  7934. super.copy( source, recursive );
  7935. if ( source.background !== null ) this.background = source.background.clone();
  7936. if ( source.environment !== null ) this.environment = source.environment.clone();
  7937. if ( source.fog !== null ) this.fog = source.fog.clone();
  7938. this.backgroundBlurriness = source.backgroundBlurriness;
  7939. this.backgroundIntensity = source.backgroundIntensity;
  7940. this.backgroundRotation.copy( source.backgroundRotation );
  7941. this.environmentIntensity = source.environmentIntensity;
  7942. this.environmentRotation.copy( source.environmentRotation );
  7943. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  7944. this.matrixAutoUpdate = source.matrixAutoUpdate;
  7945. return this;
  7946. }
  7947. toJSON( meta ) {
  7948. const data = super.toJSON( meta );
  7949. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  7950. if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
  7951. if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;
  7952. data.object.backgroundRotation = this.backgroundRotation.toArray();
  7953. if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity;
  7954. data.object.environmentRotation = this.environmentRotation.toArray();
  7955. return data;
  7956. }
  7957. }
  7958. class InterleavedBuffer {
  7959. constructor( array, stride ) {
  7960. this.isInterleavedBuffer = true;
  7961. this.array = array;
  7962. this.stride = stride;
  7963. this.count = array !== undefined ? array.length / stride : 0;
  7964. this.usage = StaticDrawUsage;
  7965. this.updateRanges = [];
  7966. this.version = 0;
  7967. this.uuid = generateUUID();
  7968. }
  7969. onUploadCallback() {}
  7970. set needsUpdate( value ) {
  7971. if ( value === true ) this.version ++;
  7972. }
  7973. setUsage( value ) {
  7974. this.usage = value;
  7975. return this;
  7976. }
  7977. addUpdateRange( start, count ) {
  7978. this.updateRanges.push( { start, count } );
  7979. }
  7980. clearUpdateRanges() {
  7981. this.updateRanges.length = 0;
  7982. }
  7983. copy( source ) {
  7984. this.array = new source.array.constructor( source.array );
  7985. this.count = source.count;
  7986. this.stride = source.stride;
  7987. this.usage = source.usage;
  7988. return this;
  7989. }
  7990. copyAt( index1, attribute, index2 ) {
  7991. index1 *= this.stride;
  7992. index2 *= attribute.stride;
  7993. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  7994. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  7995. }
  7996. return this;
  7997. }
  7998. set( value, offset = 0 ) {
  7999. this.array.set( value, offset );
  8000. return this;
  8001. }
  8002. clone( data ) {
  8003. if ( data.arrayBuffers === undefined ) {
  8004. data.arrayBuffers = {};
  8005. }
  8006. if ( this.array.buffer._uuid === undefined ) {
  8007. this.array.buffer._uuid = generateUUID();
  8008. }
  8009. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8010. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  8011. }
  8012. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  8013. const ib = new this.constructor( array, this.stride );
  8014. ib.setUsage( this.usage );
  8015. return ib;
  8016. }
  8017. onUpload( callback ) {
  8018. this.onUploadCallback = callback;
  8019. return this;
  8020. }
  8021. toJSON( data ) {
  8022. if ( data.arrayBuffers === undefined ) {
  8023. data.arrayBuffers = {};
  8024. }
  8025. // generate UUID for array buffer if necessary
  8026. if ( this.array.buffer._uuid === undefined ) {
  8027. this.array.buffer._uuid = generateUUID();
  8028. }
  8029. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8030. data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
  8031. }
  8032. //
  8033. return {
  8034. uuid: this.uuid,
  8035. buffer: this.array.buffer._uuid,
  8036. type: this.array.constructor.name,
  8037. stride: this.stride
  8038. };
  8039. }
  8040. }
  8041. const _vector$7 = /*@__PURE__*/ new Vector3();
  8042. class InterleavedBufferAttribute {
  8043. constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
  8044. this.isInterleavedBufferAttribute = true;
  8045. this.name = '';
  8046. this.data = interleavedBuffer;
  8047. this.itemSize = itemSize;
  8048. this.offset = offset;
  8049. this.normalized = normalized;
  8050. }
  8051. get count() {
  8052. return this.data.count;
  8053. }
  8054. get array() {
  8055. return this.data.array;
  8056. }
  8057. set needsUpdate( value ) {
  8058. this.data.needsUpdate = value;
  8059. }
  8060. applyMatrix4( m ) {
  8061. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  8062. _vector$7.fromBufferAttribute( this, i );
  8063. _vector$7.applyMatrix4( m );
  8064. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8065. }
  8066. return this;
  8067. }
  8068. applyNormalMatrix( m ) {
  8069. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8070. _vector$7.fromBufferAttribute( this, i );
  8071. _vector$7.applyNormalMatrix( m );
  8072. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8073. }
  8074. return this;
  8075. }
  8076. transformDirection( m ) {
  8077. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8078. _vector$7.fromBufferAttribute( this, i );
  8079. _vector$7.transformDirection( m );
  8080. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8081. }
  8082. return this;
  8083. }
  8084. getComponent( index, component ) {
  8085. let value = this.array[ index * this.data.stride + this.offset + component ];
  8086. if ( this.normalized ) value = denormalize( value, this.array );
  8087. return value;
  8088. }
  8089. setComponent( index, component, value ) {
  8090. if ( this.normalized ) value = normalize( value, this.array );
  8091. this.data.array[ index * this.data.stride + this.offset + component ] = value;
  8092. return this;
  8093. }
  8094. setX( index, x ) {
  8095. if ( this.normalized ) x = normalize( x, this.array );
  8096. this.data.array[ index * this.data.stride + this.offset ] = x;
  8097. return this;
  8098. }
  8099. setY( index, y ) {
  8100. if ( this.normalized ) y = normalize( y, this.array );
  8101. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  8102. return this;
  8103. }
  8104. setZ( index, z ) {
  8105. if ( this.normalized ) z = normalize( z, this.array );
  8106. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  8107. return this;
  8108. }
  8109. setW( index, w ) {
  8110. if ( this.normalized ) w = normalize( w, this.array );
  8111. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  8112. return this;
  8113. }
  8114. getX( index ) {
  8115. let x = this.data.array[ index * this.data.stride + this.offset ];
  8116. if ( this.normalized ) x = denormalize( x, this.array );
  8117. return x;
  8118. }
  8119. getY( index ) {
  8120. let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
  8121. if ( this.normalized ) y = denormalize( y, this.array );
  8122. return y;
  8123. }
  8124. getZ( index ) {
  8125. let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
  8126. if ( this.normalized ) z = denormalize( z, this.array );
  8127. return z;
  8128. }
  8129. getW( index ) {
  8130. let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
  8131. if ( this.normalized ) w = denormalize( w, this.array );
  8132. return w;
  8133. }
  8134. setXY( index, x, y ) {
  8135. index = index * this.data.stride + this.offset;
  8136. if ( this.normalized ) {
  8137. x = normalize( x, this.array );
  8138. y = normalize( y, this.array );
  8139. }
  8140. this.data.array[ index + 0 ] = x;
  8141. this.data.array[ index + 1 ] = y;
  8142. return this;
  8143. }
  8144. setXYZ( index, x, y, z ) {
  8145. index = index * this.data.stride + this.offset;
  8146. if ( this.normalized ) {
  8147. x = normalize( x, this.array );
  8148. y = normalize( y, this.array );
  8149. z = normalize( z, this.array );
  8150. }
  8151. this.data.array[ index + 0 ] = x;
  8152. this.data.array[ index + 1 ] = y;
  8153. this.data.array[ index + 2 ] = z;
  8154. return this;
  8155. }
  8156. setXYZW( index, x, y, z, w ) {
  8157. index = index * this.data.stride + this.offset;
  8158. if ( this.normalized ) {
  8159. x = normalize( x, this.array );
  8160. y = normalize( y, this.array );
  8161. z = normalize( z, this.array );
  8162. w = normalize( w, this.array );
  8163. }
  8164. this.data.array[ index + 0 ] = x;
  8165. this.data.array[ index + 1 ] = y;
  8166. this.data.array[ index + 2 ] = z;
  8167. this.data.array[ index + 3 ] = w;
  8168. return this;
  8169. }
  8170. clone( data ) {
  8171. if ( data === undefined ) {
  8172. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
  8173. const array = [];
  8174. for ( let i = 0; i < this.count; i ++ ) {
  8175. const index = i * this.data.stride + this.offset;
  8176. for ( let j = 0; j < this.itemSize; j ++ ) {
  8177. array.push( this.data.array[ index + j ] );
  8178. }
  8179. }
  8180. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  8181. } else {
  8182. if ( data.interleavedBuffers === undefined ) {
  8183. data.interleavedBuffers = {};
  8184. }
  8185. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8186. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  8187. }
  8188. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  8189. }
  8190. }
  8191. toJSON( data ) {
  8192. if ( data === undefined ) {
  8193. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
  8194. const array = [];
  8195. for ( let i = 0; i < this.count; i ++ ) {
  8196. const index = i * this.data.stride + this.offset;
  8197. for ( let j = 0; j < this.itemSize; j ++ ) {
  8198. array.push( this.data.array[ index + j ] );
  8199. }
  8200. }
  8201. // de-interleave data and save it as an ordinary buffer attribute for now
  8202. return {
  8203. itemSize: this.itemSize,
  8204. type: this.array.constructor.name,
  8205. array: array,
  8206. normalized: this.normalized
  8207. };
  8208. } else {
  8209. // save as true interleaved attribute
  8210. if ( data.interleavedBuffers === undefined ) {
  8211. data.interleavedBuffers = {};
  8212. }
  8213. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8214. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  8215. }
  8216. return {
  8217. isInterleavedBufferAttribute: true,
  8218. itemSize: this.itemSize,
  8219. data: this.data.uuid,
  8220. offset: this.offset,
  8221. normalized: this.normalized
  8222. };
  8223. }
  8224. }
  8225. }
  8226. class SpriteMaterial extends Material {
  8227. constructor( parameters ) {
  8228. super();
  8229. this.isSpriteMaterial = true;
  8230. this.type = 'SpriteMaterial';
  8231. this.color = new Color( 0xffffff );
  8232. this.map = null;
  8233. this.alphaMap = null;
  8234. this.rotation = 0;
  8235. this.sizeAttenuation = true;
  8236. this.transparent = true;
  8237. this.fog = true;
  8238. this.setValues( parameters );
  8239. }
  8240. copy( source ) {
  8241. super.copy( source );
  8242. this.color.copy( source.color );
  8243. this.map = source.map;
  8244. this.alphaMap = source.alphaMap;
  8245. this.rotation = source.rotation;
  8246. this.sizeAttenuation = source.sizeAttenuation;
  8247. this.fog = source.fog;
  8248. return this;
  8249. }
  8250. }
  8251. let _geometry;
  8252. const _intersectPoint = /*@__PURE__*/ new Vector3();
  8253. const _worldScale = /*@__PURE__*/ new Vector3();
  8254. const _mvPosition = /*@__PURE__*/ new Vector3();
  8255. const _alignedPosition = /*@__PURE__*/ new Vector2();
  8256. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  8257. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  8258. const _vA = /*@__PURE__*/ new Vector3();
  8259. const _vB = /*@__PURE__*/ new Vector3();
  8260. const _vC = /*@__PURE__*/ new Vector3();
  8261. const _uvA = /*@__PURE__*/ new Vector2();
  8262. const _uvB = /*@__PURE__*/ new Vector2();
  8263. const _uvC = /*@__PURE__*/ new Vector2();
  8264. class Sprite extends Object3D {
  8265. constructor( material = new SpriteMaterial() ) {
  8266. super();
  8267. this.isSprite = true;
  8268. this.type = 'Sprite';
  8269. if ( _geometry === undefined ) {
  8270. _geometry = new BufferGeometry();
  8271. const float32Array = new Float32Array( [
  8272. - 0.5, - 0.5, 0, 0, 0,
  8273. 0.5, - 0.5, 0, 1, 0,
  8274. 0.5, 0.5, 0, 1, 1,
  8275. - 0.5, 0.5, 0, 0, 1
  8276. ] );
  8277. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  8278. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  8279. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  8280. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  8281. }
  8282. this.geometry = _geometry;
  8283. this.material = material;
  8284. this.center = new Vector2( 0.5, 0.5 );
  8285. }
  8286. raycast( raycaster, intersects ) {
  8287. if ( raycaster.camera === null ) {
  8288. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  8289. }
  8290. _worldScale.setFromMatrixScale( this.matrixWorld );
  8291. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  8292. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  8293. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  8294. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  8295. _worldScale.multiplyScalar( - _mvPosition.z );
  8296. }
  8297. const rotation = this.material.rotation;
  8298. let sin, cos;
  8299. if ( rotation !== 0 ) {
  8300. cos = Math.cos( rotation );
  8301. sin = Math.sin( rotation );
  8302. }
  8303. const center = this.center;
  8304. transformVertex( _vA.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8305. transformVertex( _vB.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8306. transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8307. _uvA.set( 0, 0 );
  8308. _uvB.set( 1, 0 );
  8309. _uvC.set( 1, 1 );
  8310. // check first triangle
  8311. let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint );
  8312. if ( intersect === null ) {
  8313. // check second triangle
  8314. transformVertex( _vB.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8315. _uvB.set( 0, 1 );
  8316. intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint );
  8317. if ( intersect === null ) {
  8318. return;
  8319. }
  8320. }
  8321. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  8322. if ( distance < raycaster.near || distance > raycaster.far ) return;
  8323. intersects.push( {
  8324. distance: distance,
  8325. point: _intersectPoint.clone(),
  8326. uv: Triangle.getInterpolation( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ),
  8327. face: null,
  8328. object: this
  8329. } );
  8330. }
  8331. copy( source, recursive ) {
  8332. super.copy( source, recursive );
  8333. if ( source.center !== undefined ) this.center.copy( source.center );
  8334. this.material = source.material;
  8335. return this;
  8336. }
  8337. }
  8338. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  8339. // compute position in camera space
  8340. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  8341. // to check if rotation is not zero
  8342. if ( sin !== undefined ) {
  8343. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  8344. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  8345. } else {
  8346. _rotatedPosition.copy( _alignedPosition );
  8347. }
  8348. vertexPosition.copy( mvPosition );
  8349. vertexPosition.x += _rotatedPosition.x;
  8350. vertexPosition.y += _rotatedPosition.y;
  8351. // transform to world space
  8352. vertexPosition.applyMatrix4( _viewWorldMatrix );
  8353. }
  8354. const _v1$2 = /*@__PURE__*/ new Vector3();
  8355. const _v2$1 = /*@__PURE__*/ new Vector3();
  8356. class LOD extends Object3D {
  8357. constructor() {
  8358. super();
  8359. this._currentLevel = 0;
  8360. this.type = 'LOD';
  8361. Object.defineProperties( this, {
  8362. levels: {
  8363. enumerable: true,
  8364. value: []
  8365. },
  8366. isLOD: {
  8367. value: true,
  8368. }
  8369. } );
  8370. this.autoUpdate = true;
  8371. }
  8372. copy( source ) {
  8373. super.copy( source, false );
  8374. const levels = source.levels;
  8375. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8376. const level = levels[ i ];
  8377. this.addLevel( level.object.clone(), level.distance, level.hysteresis );
  8378. }
  8379. this.autoUpdate = source.autoUpdate;
  8380. return this;
  8381. }
  8382. addLevel( object, distance = 0, hysteresis = 0 ) {
  8383. distance = Math.abs( distance );
  8384. const levels = this.levels;
  8385. let l;
  8386. for ( l = 0; l < levels.length; l ++ ) {
  8387. if ( distance < levels[ l ].distance ) {
  8388. break;
  8389. }
  8390. }
  8391. levels.splice( l, 0, { distance: distance, hysteresis: hysteresis, object: object } );
  8392. this.add( object );
  8393. return this;
  8394. }
  8395. removeLevel( distance ) {
  8396. const levels = this.levels;
  8397. for ( let i = 0; i < levels.length; i ++ ) {
  8398. if ( levels[ i ].distance === distance ) {
  8399. const removedElements = levels.splice( i, 1 );
  8400. this.remove( removedElements[ 0 ].object );
  8401. return true;
  8402. }
  8403. }
  8404. return false;
  8405. }
  8406. getCurrentLevel() {
  8407. return this._currentLevel;
  8408. }
  8409. getObjectForDistance( distance ) {
  8410. const levels = this.levels;
  8411. if ( levels.length > 0 ) {
  8412. let i, l;
  8413. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8414. let levelDistance = levels[ i ].distance;
  8415. if ( levels[ i ].object.visible ) {
  8416. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8417. }
  8418. if ( distance < levelDistance ) {
  8419. break;
  8420. }
  8421. }
  8422. return levels[ i - 1 ].object;
  8423. }
  8424. return null;
  8425. }
  8426. raycast( raycaster, intersects ) {
  8427. const levels = this.levels;
  8428. if ( levels.length > 0 ) {
  8429. _v1$2.setFromMatrixPosition( this.matrixWorld );
  8430. const distance = raycaster.ray.origin.distanceTo( _v1$2 );
  8431. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  8432. }
  8433. }
  8434. update( camera ) {
  8435. const levels = this.levels;
  8436. if ( levels.length > 1 ) {
  8437. _v1$2.setFromMatrixPosition( camera.matrixWorld );
  8438. _v2$1.setFromMatrixPosition( this.matrixWorld );
  8439. const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom;
  8440. levels[ 0 ].object.visible = true;
  8441. let i, l;
  8442. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8443. let levelDistance = levels[ i ].distance;
  8444. if ( levels[ i ].object.visible ) {
  8445. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8446. }
  8447. if ( distance >= levelDistance ) {
  8448. levels[ i - 1 ].object.visible = false;
  8449. levels[ i ].object.visible = true;
  8450. } else {
  8451. break;
  8452. }
  8453. }
  8454. this._currentLevel = i - 1;
  8455. for ( ; i < l; i ++ ) {
  8456. levels[ i ].object.visible = false;
  8457. }
  8458. }
  8459. }
  8460. toJSON( meta ) {
  8461. const data = super.toJSON( meta );
  8462. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  8463. data.object.levels = [];
  8464. const levels = this.levels;
  8465. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8466. const level = levels[ i ];
  8467. data.object.levels.push( {
  8468. object: level.object.uuid,
  8469. distance: level.distance,
  8470. hysteresis: level.hysteresis
  8471. } );
  8472. }
  8473. return data;
  8474. }
  8475. }
  8476. const _basePosition = /*@__PURE__*/ new Vector3();
  8477. const _skinIndex = /*@__PURE__*/ new Vector4();
  8478. const _skinWeight = /*@__PURE__*/ new Vector4();
  8479. const _vector3 = /*@__PURE__*/ new Vector3();
  8480. const _matrix4 = /*@__PURE__*/ new Matrix4();
  8481. const _vertex = /*@__PURE__*/ new Vector3();
  8482. const _sphere$5 = /*@__PURE__*/ new Sphere();
  8483. const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4();
  8484. const _ray$2 = /*@__PURE__*/ new Ray();
  8485. class SkinnedMesh extends Mesh {
  8486. constructor( geometry, material ) {
  8487. super( geometry, material );
  8488. this.isSkinnedMesh = true;
  8489. this.type = 'SkinnedMesh';
  8490. this.bindMode = AttachedBindMode;
  8491. this.bindMatrix = new Matrix4();
  8492. this.bindMatrixInverse = new Matrix4();
  8493. this.boundingBox = null;
  8494. this.boundingSphere = null;
  8495. }
  8496. computeBoundingBox() {
  8497. const geometry = this.geometry;
  8498. if ( this.boundingBox === null ) {
  8499. this.boundingBox = new Box3();
  8500. }
  8501. this.boundingBox.makeEmpty();
  8502. const positionAttribute = geometry.getAttribute( 'position' );
  8503. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8504. this.getVertexPosition( i, _vertex );
  8505. this.boundingBox.expandByPoint( _vertex );
  8506. }
  8507. }
  8508. computeBoundingSphere() {
  8509. const geometry = this.geometry;
  8510. if ( this.boundingSphere === null ) {
  8511. this.boundingSphere = new Sphere();
  8512. }
  8513. this.boundingSphere.makeEmpty();
  8514. const positionAttribute = geometry.getAttribute( 'position' );
  8515. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8516. this.getVertexPosition( i, _vertex );
  8517. this.boundingSphere.expandByPoint( _vertex );
  8518. }
  8519. }
  8520. copy( source, recursive ) {
  8521. super.copy( source, recursive );
  8522. this.bindMode = source.bindMode;
  8523. this.bindMatrix.copy( source.bindMatrix );
  8524. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  8525. this.skeleton = source.skeleton;
  8526. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8527. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8528. return this;
  8529. }
  8530. raycast( raycaster, intersects ) {
  8531. const material = this.material;
  8532. const matrixWorld = this.matrixWorld;
  8533. if ( material === undefined ) return;
  8534. // test with bounding sphere in world space
  8535. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8536. _sphere$5.copy( this.boundingSphere );
  8537. _sphere$5.applyMatrix4( matrixWorld );
  8538. if ( raycaster.ray.intersectsSphere( _sphere$5 ) === false ) return;
  8539. // convert ray to local space of skinned mesh
  8540. _inverseMatrix$2.copy( matrixWorld ).invert();
  8541. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  8542. // test with bounding box in local space
  8543. if ( this.boundingBox !== null ) {
  8544. if ( _ray$2.intersectsBox( this.boundingBox ) === false ) return;
  8545. }
  8546. // test for intersections with geometry
  8547. this._computeIntersections( raycaster, intersects, _ray$2 );
  8548. }
  8549. getVertexPosition( index, target ) {
  8550. super.getVertexPosition( index, target );
  8551. this.applyBoneTransform( index, target );
  8552. return target;
  8553. }
  8554. bind( skeleton, bindMatrix ) {
  8555. this.skeleton = skeleton;
  8556. if ( bindMatrix === undefined ) {
  8557. this.updateMatrixWorld( true );
  8558. this.skeleton.calculateInverses();
  8559. bindMatrix = this.matrixWorld;
  8560. }
  8561. this.bindMatrix.copy( bindMatrix );
  8562. this.bindMatrixInverse.copy( bindMatrix ).invert();
  8563. }
  8564. pose() {
  8565. this.skeleton.pose();
  8566. }
  8567. normalizeSkinWeights() {
  8568. const vector = new Vector4();
  8569. const skinWeight = this.geometry.attributes.skinWeight;
  8570. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  8571. vector.fromBufferAttribute( skinWeight, i );
  8572. const scale = 1.0 / vector.manhattanLength();
  8573. if ( scale !== Infinity ) {
  8574. vector.multiplyScalar( scale );
  8575. } else {
  8576. vector.set( 1, 0, 0, 0 ); // do something reasonable
  8577. }
  8578. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  8579. }
  8580. }
  8581. updateMatrixWorld( force ) {
  8582. super.updateMatrixWorld( force );
  8583. if ( this.bindMode === AttachedBindMode ) {
  8584. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  8585. } else if ( this.bindMode === DetachedBindMode ) {
  8586. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  8587. } else {
  8588. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  8589. }
  8590. }
  8591. applyBoneTransform( index, vector ) {
  8592. const skeleton = this.skeleton;
  8593. const geometry = this.geometry;
  8594. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  8595. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  8596. _basePosition.copy( vector ).applyMatrix4( this.bindMatrix );
  8597. vector.set( 0, 0, 0 );
  8598. for ( let i = 0; i < 4; i ++ ) {
  8599. const weight = _skinWeight.getComponent( i );
  8600. if ( weight !== 0 ) {
  8601. const boneIndex = _skinIndex.getComponent( i );
  8602. _matrix4.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  8603. vector.addScaledVector( _vector3.copy( _basePosition ).applyMatrix4( _matrix4 ), weight );
  8604. }
  8605. }
  8606. return vector.applyMatrix4( this.bindMatrixInverse );
  8607. }
  8608. }
  8609. class Bone extends Object3D {
  8610. constructor() {
  8611. super();
  8612. this.isBone = true;
  8613. this.type = 'Bone';
  8614. }
  8615. }
  8616. class DataTexture extends Texture {
  8617. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) {
  8618. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  8619. this.isDataTexture = true;
  8620. this.image = { data: data, width: width, height: height };
  8621. this.generateMipmaps = false;
  8622. this.flipY = false;
  8623. this.unpackAlignment = 1;
  8624. }
  8625. }
  8626. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  8627. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  8628. class Skeleton {
  8629. constructor( bones = [], boneInverses = [] ) {
  8630. this.uuid = generateUUID();
  8631. this.bones = bones.slice( 0 );
  8632. this.boneInverses = boneInverses;
  8633. this.boneMatrices = null;
  8634. this.boneTexture = null;
  8635. this.init();
  8636. }
  8637. init() {
  8638. const bones = this.bones;
  8639. const boneInverses = this.boneInverses;
  8640. this.boneMatrices = new Float32Array( bones.length * 16 );
  8641. // calculate inverse bone matrices if necessary
  8642. if ( boneInverses.length === 0 ) {
  8643. this.calculateInverses();
  8644. } else {
  8645. // handle special case
  8646. if ( bones.length !== boneInverses.length ) {
  8647. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  8648. this.boneInverses = [];
  8649. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8650. this.boneInverses.push( new Matrix4() );
  8651. }
  8652. }
  8653. }
  8654. }
  8655. calculateInverses() {
  8656. this.boneInverses.length = 0;
  8657. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8658. const inverse = new Matrix4();
  8659. if ( this.bones[ i ] ) {
  8660. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  8661. }
  8662. this.boneInverses.push( inverse );
  8663. }
  8664. }
  8665. pose() {
  8666. // recover the bind-time world matrices
  8667. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8668. const bone = this.bones[ i ];
  8669. if ( bone ) {
  8670. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  8671. }
  8672. }
  8673. // compute the local matrices, positions, rotations and scales
  8674. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8675. const bone = this.bones[ i ];
  8676. if ( bone ) {
  8677. if ( bone.parent && bone.parent.isBone ) {
  8678. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  8679. bone.matrix.multiply( bone.matrixWorld );
  8680. } else {
  8681. bone.matrix.copy( bone.matrixWorld );
  8682. }
  8683. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  8684. }
  8685. }
  8686. }
  8687. update() {
  8688. const bones = this.bones;
  8689. const boneInverses = this.boneInverses;
  8690. const boneMatrices = this.boneMatrices;
  8691. const boneTexture = this.boneTexture;
  8692. // flatten bone matrices to array
  8693. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  8694. // compute the offset between the current and the original transform
  8695. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  8696. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  8697. _offsetMatrix.toArray( boneMatrices, i * 16 );
  8698. }
  8699. if ( boneTexture !== null ) {
  8700. boneTexture.needsUpdate = true;
  8701. }
  8702. }
  8703. clone() {
  8704. return new Skeleton( this.bones, this.boneInverses );
  8705. }
  8706. computeBoneTexture() {
  8707. // layout (1 matrix = 4 pixels)
  8708. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  8709. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  8710. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  8711. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  8712. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  8713. let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  8714. size = Math.ceil( size / 4 ) * 4;
  8715. size = Math.max( size, 4 );
  8716. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  8717. boneMatrices.set( this.boneMatrices ); // copy current values
  8718. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  8719. boneTexture.needsUpdate = true;
  8720. this.boneMatrices = boneMatrices;
  8721. this.boneTexture = boneTexture;
  8722. return this;
  8723. }
  8724. getBoneByName( name ) {
  8725. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8726. const bone = this.bones[ i ];
  8727. if ( bone.name === name ) {
  8728. return bone;
  8729. }
  8730. }
  8731. return undefined;
  8732. }
  8733. dispose( ) {
  8734. if ( this.boneTexture !== null ) {
  8735. this.boneTexture.dispose();
  8736. this.boneTexture = null;
  8737. }
  8738. }
  8739. fromJSON( json, bones ) {
  8740. this.uuid = json.uuid;
  8741. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  8742. const uuid = json.bones[ i ];
  8743. let bone = bones[ uuid ];
  8744. if ( bone === undefined ) {
  8745. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  8746. bone = new Bone();
  8747. }
  8748. this.bones.push( bone );
  8749. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  8750. }
  8751. this.init();
  8752. return this;
  8753. }
  8754. toJSON() {
  8755. const data = {
  8756. metadata: {
  8757. version: 4.6,
  8758. type: 'Skeleton',
  8759. generator: 'Skeleton.toJSON'
  8760. },
  8761. bones: [],
  8762. boneInverses: []
  8763. };
  8764. data.uuid = this.uuid;
  8765. const bones = this.bones;
  8766. const boneInverses = this.boneInverses;
  8767. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  8768. const bone = bones[ i ];
  8769. data.bones.push( bone.uuid );
  8770. const boneInverse = boneInverses[ i ];
  8771. data.boneInverses.push( boneInverse.toArray() );
  8772. }
  8773. return data;
  8774. }
  8775. }
  8776. class InstancedBufferAttribute extends BufferAttribute {
  8777. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  8778. super( array, itemSize, normalized );
  8779. this.isInstancedBufferAttribute = true;
  8780. this.meshPerAttribute = meshPerAttribute;
  8781. }
  8782. copy( source ) {
  8783. super.copy( source );
  8784. this.meshPerAttribute = source.meshPerAttribute;
  8785. return this;
  8786. }
  8787. toJSON() {
  8788. const data = super.toJSON();
  8789. data.meshPerAttribute = this.meshPerAttribute;
  8790. data.isInstancedBufferAttribute = true;
  8791. return data;
  8792. }
  8793. }
  8794. const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
  8795. const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
  8796. const _instanceIntersects = [];
  8797. const _box3 = /*@__PURE__*/ new Box3();
  8798. const _identity = /*@__PURE__*/ new Matrix4();
  8799. const _mesh$1 = /*@__PURE__*/ new Mesh();
  8800. const _sphere$4 = /*@__PURE__*/ new Sphere();
  8801. class InstancedMesh extends Mesh {
  8802. constructor( geometry, material, count ) {
  8803. super( geometry, material );
  8804. this.isInstancedMesh = true;
  8805. this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
  8806. this.instanceColor = null;
  8807. this.morphTexture = null;
  8808. this.count = count;
  8809. this.boundingBox = null;
  8810. this.boundingSphere = null;
  8811. for ( let i = 0; i < count; i ++ ) {
  8812. this.setMatrixAt( i, _identity );
  8813. }
  8814. }
  8815. computeBoundingBox() {
  8816. const geometry = this.geometry;
  8817. const count = this.count;
  8818. if ( this.boundingBox === null ) {
  8819. this.boundingBox = new Box3();
  8820. }
  8821. if ( geometry.boundingBox === null ) {
  8822. geometry.computeBoundingBox();
  8823. }
  8824. this.boundingBox.makeEmpty();
  8825. for ( let i = 0; i < count; i ++ ) {
  8826. this.getMatrixAt( i, _instanceLocalMatrix );
  8827. _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix );
  8828. this.boundingBox.union( _box3 );
  8829. }
  8830. }
  8831. computeBoundingSphere() {
  8832. const geometry = this.geometry;
  8833. const count = this.count;
  8834. if ( this.boundingSphere === null ) {
  8835. this.boundingSphere = new Sphere();
  8836. }
  8837. if ( geometry.boundingSphere === null ) {
  8838. geometry.computeBoundingSphere();
  8839. }
  8840. this.boundingSphere.makeEmpty();
  8841. for ( let i = 0; i < count; i ++ ) {
  8842. this.getMatrixAt( i, _instanceLocalMatrix );
  8843. _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix );
  8844. this.boundingSphere.union( _sphere$4 );
  8845. }
  8846. }
  8847. copy( source, recursive ) {
  8848. super.copy( source, recursive );
  8849. this.instanceMatrix.copy( source.instanceMatrix );
  8850. if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone();
  8851. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  8852. this.count = source.count;
  8853. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8854. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8855. return this;
  8856. }
  8857. getColorAt( index, color ) {
  8858. color.fromArray( this.instanceColor.array, index * 3 );
  8859. }
  8860. getMatrixAt( index, matrix ) {
  8861. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  8862. }
  8863. getMorphAt( index, object ) {
  8864. const objectInfluences = object.morphTargetInfluences;
  8865. const array = this.morphTexture.source.data.data;
  8866. const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
  8867. const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
  8868. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8869. objectInfluences[ i ] = array[ dataIndex + i ];
  8870. }
  8871. }
  8872. raycast( raycaster, intersects ) {
  8873. const matrixWorld = this.matrixWorld;
  8874. const raycastTimes = this.count;
  8875. _mesh$1.geometry = this.geometry;
  8876. _mesh$1.material = this.material;
  8877. if ( _mesh$1.material === undefined ) return;
  8878. // test with bounding sphere first
  8879. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8880. _sphere$4.copy( this.boundingSphere );
  8881. _sphere$4.applyMatrix4( matrixWorld );
  8882. if ( raycaster.ray.intersectsSphere( _sphere$4 ) === false ) return;
  8883. // now test each instance
  8884. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  8885. // calculate the world matrix for each instance
  8886. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  8887. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  8888. // the mesh represents this single instance
  8889. _mesh$1.matrixWorld = _instanceWorldMatrix;
  8890. _mesh$1.raycast( raycaster, _instanceIntersects );
  8891. // process the result of raycast
  8892. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  8893. const intersect = _instanceIntersects[ i ];
  8894. intersect.instanceId = instanceId;
  8895. intersect.object = this;
  8896. intersects.push( intersect );
  8897. }
  8898. _instanceIntersects.length = 0;
  8899. }
  8900. }
  8901. setColorAt( index, color ) {
  8902. if ( this.instanceColor === null ) {
  8903. this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ).fill( 1 ), 3 );
  8904. }
  8905. color.toArray( this.instanceColor.array, index * 3 );
  8906. }
  8907. setMatrixAt( index, matrix ) {
  8908. matrix.toArray( this.instanceMatrix.array, index * 16 );
  8909. }
  8910. setMorphAt( index, object ) {
  8911. const objectInfluences = object.morphTargetInfluences;
  8912. const len = objectInfluences.length + 1; // morphBaseInfluence + all influences
  8913. if ( this.morphTexture === null ) {
  8914. this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType );
  8915. }
  8916. const array = this.morphTexture.source.data.data;
  8917. let morphInfluencesSum = 0;
  8918. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8919. morphInfluencesSum += objectInfluences[ i ];
  8920. }
  8921. const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  8922. const dataIndex = len * index;
  8923. array[ dataIndex ] = morphBaseInfluence;
  8924. array.set( objectInfluences, dataIndex + 1 );
  8925. }
  8926. updateMorphTargets() {
  8927. }
  8928. dispose() {
  8929. this.dispatchEvent( { type: 'dispose' } );
  8930. if ( this.morphTexture !== null ) {
  8931. this.morphTexture.dispose();
  8932. this.morphTexture = null;
  8933. }
  8934. return this;
  8935. }
  8936. }
  8937. const _vector1 = /*@__PURE__*/ new Vector3();
  8938. const _vector2 = /*@__PURE__*/ new Vector3();
  8939. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  8940. class Plane {
  8941. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  8942. this.isPlane = true;
  8943. // normal is assumed to be normalized
  8944. this.normal = normal;
  8945. this.constant = constant;
  8946. }
  8947. set( normal, constant ) {
  8948. this.normal.copy( normal );
  8949. this.constant = constant;
  8950. return this;
  8951. }
  8952. setComponents( x, y, z, w ) {
  8953. this.normal.set( x, y, z );
  8954. this.constant = w;
  8955. return this;
  8956. }
  8957. setFromNormalAndCoplanarPoint( normal, point ) {
  8958. this.normal.copy( normal );
  8959. this.constant = - point.dot( this.normal );
  8960. return this;
  8961. }
  8962. setFromCoplanarPoints( a, b, c ) {
  8963. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  8964. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8965. this.setFromNormalAndCoplanarPoint( normal, a );
  8966. return this;
  8967. }
  8968. copy( plane ) {
  8969. this.normal.copy( plane.normal );
  8970. this.constant = plane.constant;
  8971. return this;
  8972. }
  8973. normalize() {
  8974. // Note: will lead to a divide by zero if the plane is invalid.
  8975. const inverseNormalLength = 1.0 / this.normal.length();
  8976. this.normal.multiplyScalar( inverseNormalLength );
  8977. this.constant *= inverseNormalLength;
  8978. return this;
  8979. }
  8980. negate() {
  8981. this.constant *= - 1;
  8982. this.normal.negate();
  8983. return this;
  8984. }
  8985. distanceToPoint( point ) {
  8986. return this.normal.dot( point ) + this.constant;
  8987. }
  8988. distanceToSphere( sphere ) {
  8989. return this.distanceToPoint( sphere.center ) - sphere.radius;
  8990. }
  8991. projectPoint( point, target ) {
  8992. return target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) );
  8993. }
  8994. intersectLine( line, target ) {
  8995. const direction = line.delta( _vector1 );
  8996. const denominator = this.normal.dot( direction );
  8997. if ( denominator === 0 ) {
  8998. // line is coplanar, return origin
  8999. if ( this.distanceToPoint( line.start ) === 0 ) {
  9000. return target.copy( line.start );
  9001. }
  9002. // Unsure if this is the correct method to handle this case.
  9003. return null;
  9004. }
  9005. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9006. if ( t < 0 || t > 1 ) {
  9007. return null;
  9008. }
  9009. return target.copy( line.start ).addScaledVector( direction, t );
  9010. }
  9011. intersectsLine( line ) {
  9012. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9013. const startSign = this.distanceToPoint( line.start );
  9014. const endSign = this.distanceToPoint( line.end );
  9015. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9016. }
  9017. intersectsBox( box ) {
  9018. return box.intersectsPlane( this );
  9019. }
  9020. intersectsSphere( sphere ) {
  9021. return sphere.intersectsPlane( this );
  9022. }
  9023. coplanarPoint( target ) {
  9024. return target.copy( this.normal ).multiplyScalar( - this.constant );
  9025. }
  9026. applyMatrix4( matrix, optionalNormalMatrix ) {
  9027. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  9028. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  9029. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9030. this.constant = - referencePoint.dot( normal );
  9031. return this;
  9032. }
  9033. translate( offset ) {
  9034. this.constant -= offset.dot( this.normal );
  9035. return this;
  9036. }
  9037. equals( plane ) {
  9038. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9039. }
  9040. clone() {
  9041. return new this.constructor().copy( this );
  9042. }
  9043. }
  9044. const _sphere$3 = /*@__PURE__*/ new Sphere();
  9045. const _vector$6 = /*@__PURE__*/ new Vector3();
  9046. class Frustum {
  9047. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  9048. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  9049. }
  9050. set( p0, p1, p2, p3, p4, p5 ) {
  9051. const planes = this.planes;
  9052. planes[ 0 ].copy( p0 );
  9053. planes[ 1 ].copy( p1 );
  9054. planes[ 2 ].copy( p2 );
  9055. planes[ 3 ].copy( p3 );
  9056. planes[ 4 ].copy( p4 );
  9057. planes[ 5 ].copy( p5 );
  9058. return this;
  9059. }
  9060. copy( frustum ) {
  9061. const planes = this.planes;
  9062. for ( let i = 0; i < 6; i ++ ) {
  9063. planes[ i ].copy( frustum.planes[ i ] );
  9064. }
  9065. return this;
  9066. }
  9067. setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
  9068. const planes = this.planes;
  9069. const me = m.elements;
  9070. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  9071. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  9072. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  9073. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  9074. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  9075. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  9076. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  9077. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  9078. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  9079. if ( coordinateSystem === WebGLCoordinateSystem ) {
  9080. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  9081. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  9082. planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
  9083. } else {
  9084. throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
  9085. }
  9086. return this;
  9087. }
  9088. intersectsObject( object ) {
  9089. if ( object.boundingSphere !== undefined ) {
  9090. if ( object.boundingSphere === null ) object.computeBoundingSphere();
  9091. _sphere$3.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld );
  9092. } else {
  9093. const geometry = object.geometry;
  9094. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9095. _sphere$3.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  9096. }
  9097. return this.intersectsSphere( _sphere$3 );
  9098. }
  9099. intersectsSprite( sprite ) {
  9100. _sphere$3.center.set( 0, 0, 0 );
  9101. _sphere$3.radius = 0.7071067811865476;
  9102. _sphere$3.applyMatrix4( sprite.matrixWorld );
  9103. return this.intersectsSphere( _sphere$3 );
  9104. }
  9105. intersectsSphere( sphere ) {
  9106. const planes = this.planes;
  9107. const center = sphere.center;
  9108. const negRadius = - sphere.radius;
  9109. for ( let i = 0; i < 6; i ++ ) {
  9110. const distance = planes[ i ].distanceToPoint( center );
  9111. if ( distance < negRadius ) {
  9112. return false;
  9113. }
  9114. }
  9115. return true;
  9116. }
  9117. intersectsBox( box ) {
  9118. const planes = this.planes;
  9119. for ( let i = 0; i < 6; i ++ ) {
  9120. const plane = planes[ i ];
  9121. // corner at max distance
  9122. _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  9123. _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  9124. _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  9125. if ( plane.distanceToPoint( _vector$6 ) < 0 ) {
  9126. return false;
  9127. }
  9128. }
  9129. return true;
  9130. }
  9131. containsPoint( point ) {
  9132. const planes = this.planes;
  9133. for ( let i = 0; i < 6; i ++ ) {
  9134. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  9135. return false;
  9136. }
  9137. }
  9138. return true;
  9139. }
  9140. clone() {
  9141. return new this.constructor().copy( this );
  9142. }
  9143. }
  9144. function ascIdSort( a, b ) {
  9145. return a - b;
  9146. }
  9147. function sortOpaque( a, b ) {
  9148. return a.z - b.z;
  9149. }
  9150. function sortTransparent( a, b ) {
  9151. return b.z - a.z;
  9152. }
  9153. class MultiDrawRenderList {
  9154. constructor() {
  9155. this.index = 0;
  9156. this.pool = [];
  9157. this.list = [];
  9158. }
  9159. push( start, count, z, index ) {
  9160. const pool = this.pool;
  9161. const list = this.list;
  9162. if ( this.index >= pool.length ) {
  9163. pool.push( {
  9164. start: - 1,
  9165. count: - 1,
  9166. z: - 1,
  9167. index: - 1,
  9168. } );
  9169. }
  9170. const item = pool[ this.index ];
  9171. list.push( item );
  9172. this.index ++;
  9173. item.start = start;
  9174. item.count = count;
  9175. item.z = z;
  9176. item.index = index;
  9177. }
  9178. reset() {
  9179. this.list.length = 0;
  9180. this.index = 0;
  9181. }
  9182. }
  9183. const _matrix$1 = /*@__PURE__*/ new Matrix4();
  9184. const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
  9185. const _frustum = /*@__PURE__*/ new Frustum();
  9186. const _box$1 = /*@__PURE__*/ new Box3();
  9187. const _sphere$2 = /*@__PURE__*/ new Sphere();
  9188. const _vector$5 = /*@__PURE__*/ new Vector3();
  9189. const _forward = /*@__PURE__*/ new Vector3();
  9190. const _temp = /*@__PURE__*/ new Vector3();
  9191. const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
  9192. const _mesh = /*@__PURE__*/ new Mesh();
  9193. const _batchIntersects = [];
  9194. // copies data from attribute "src" into "target" starting at "targetOffset"
  9195. function copyAttributeData( src, target, targetOffset = 0 ) {
  9196. const itemSize = target.itemSize;
  9197. if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) {
  9198. // use the component getters and setters if the array data cannot
  9199. // be copied directly
  9200. const vertexCount = src.count;
  9201. for ( let i = 0; i < vertexCount; i ++ ) {
  9202. for ( let c = 0; c < itemSize; c ++ ) {
  9203. target.setComponent( i + targetOffset, c, src.getComponent( i, c ) );
  9204. }
  9205. }
  9206. } else {
  9207. // faster copy approach using typed array set function
  9208. target.array.set( src.array, targetOffset * itemSize );
  9209. }
  9210. target.needsUpdate = true;
  9211. }
  9212. // safely copies array contents to a potentially smaller array
  9213. function copyArrayContents( src, target ) {
  9214. if ( src.constructor !== target.constructor ) {
  9215. // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
  9216. const len = Math.min( src.length, target.length );
  9217. for ( let i = 0; i < len; i ++ ) {
  9218. target[ i ] = src[ i ];
  9219. }
  9220. } else {
  9221. // if the arrays use the same data layout we can use a fast block copy
  9222. const len = Math.min( src.length, target.length );
  9223. target.set( new src.constructor( src.buffer, 0, len ) );
  9224. }
  9225. }
  9226. class BatchedMesh extends Mesh {
  9227. get maxInstanceCount() {
  9228. return this._maxInstanceCount;
  9229. }
  9230. get instanceCount() {
  9231. return this._instanceInfo.length - this._availableInstanceIds.length;
  9232. }
  9233. get unusedVertexCount() {
  9234. return this._maxVertexCount - this._nextVertexStart;
  9235. }
  9236. get unusedIndexCount() {
  9237. return this._maxIndexCount - this._nextIndexStart;
  9238. }
  9239. constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
  9240. super( new BufferGeometry(), material );
  9241. this.isBatchedMesh = true;
  9242. this.perObjectFrustumCulled = true;
  9243. this.sortObjects = true;
  9244. this.boundingBox = null;
  9245. this.boundingSphere = null;
  9246. this.customSort = null;
  9247. // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
  9248. this._instanceInfo = [];
  9249. this._geometryInfo = [];
  9250. // instance, geometry ids that have been set as inactive, and are available to be overwritten
  9251. this._availableInstanceIds = [];
  9252. this._availableGeometryIds = [];
  9253. // used to track where the next point is that geometry should be inserted
  9254. this._nextIndexStart = 0;
  9255. this._nextVertexStart = 0;
  9256. this._geometryCount = 0;
  9257. // flags
  9258. this._visibilityChanged = true;
  9259. this._geometryInitialized = false;
  9260. // cached user options
  9261. this._maxInstanceCount = maxInstanceCount;
  9262. this._maxVertexCount = maxVertexCount;
  9263. this._maxIndexCount = maxIndexCount;
  9264. // buffers for multi draw
  9265. this._multiDrawCounts = new Int32Array( maxInstanceCount );
  9266. this._multiDrawStarts = new Int32Array( maxInstanceCount );
  9267. this._multiDrawCount = 0;
  9268. this._multiDrawInstances = null;
  9269. // Local matrix per geometry by using data texture
  9270. this._matricesTexture = null;
  9271. this._indirectTexture = null;
  9272. this._colorsTexture = null;
  9273. this._initMatricesTexture();
  9274. this._initIndirectTexture();
  9275. }
  9276. _initMatricesTexture() {
  9277. // layout (1 matrix = 4 pixels)
  9278. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  9279. // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)
  9280. // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)
  9281. // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)
  9282. // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)
  9283. let size = Math.sqrt( this._maxInstanceCount * 4 ); // 4 pixels needed for 1 matrix
  9284. size = Math.ceil( size / 4 ) * 4;
  9285. size = Math.max( size, 4 );
  9286. const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  9287. const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType );
  9288. this._matricesTexture = matricesTexture;
  9289. }
  9290. _initIndirectTexture() {
  9291. let size = Math.sqrt( this._maxInstanceCount );
  9292. size = Math.ceil( size );
  9293. const indirectArray = new Uint32Array( size * size );
  9294. const indirectTexture = new DataTexture( indirectArray, size, size, RedIntegerFormat, UnsignedIntType );
  9295. this._indirectTexture = indirectTexture;
  9296. }
  9297. _initColorsTexture() {
  9298. let size = Math.sqrt( this._maxInstanceCount );
  9299. size = Math.ceil( size );
  9300. // 4 floats per RGBA pixel initialized to white
  9301. const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
  9302. const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
  9303. colorsTexture.colorSpace = ColorManagement.workingColorSpace;
  9304. this._colorsTexture = colorsTexture;
  9305. }
  9306. _initializeGeometry( reference ) {
  9307. const geometry = this.geometry;
  9308. const maxVertexCount = this._maxVertexCount;
  9309. const maxIndexCount = this._maxIndexCount;
  9310. if ( this._geometryInitialized === false ) {
  9311. for ( const attributeName in reference.attributes ) {
  9312. const srcAttribute = reference.getAttribute( attributeName );
  9313. const { array, itemSize, normalized } = srcAttribute;
  9314. const dstArray = new array.constructor( maxVertexCount * itemSize );
  9315. const dstAttribute = new BufferAttribute( dstArray, itemSize, normalized );
  9316. geometry.setAttribute( attributeName, dstAttribute );
  9317. }
  9318. if ( reference.getIndex() !== null ) {
  9319. // Reserve last u16 index for primitive restart.
  9320. const indexArray = maxVertexCount > 65535
  9321. ? new Uint32Array( maxIndexCount )
  9322. : new Uint16Array( maxIndexCount );
  9323. geometry.setIndex( new BufferAttribute( indexArray, 1 ) );
  9324. }
  9325. this._geometryInitialized = true;
  9326. }
  9327. }
  9328. // Make sure the geometry is compatible with the existing combined geometry attributes
  9329. _validateGeometry( geometry ) {
  9330. // check to ensure the geometries are using consistent attributes and indices
  9331. const batchGeometry = this.geometry;
  9332. if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
  9333. throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
  9334. }
  9335. for ( const attributeName in batchGeometry.attributes ) {
  9336. if ( ! geometry.hasAttribute( attributeName ) ) {
  9337. throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
  9338. }
  9339. const srcAttribute = geometry.getAttribute( attributeName );
  9340. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9341. if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
  9342. throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
  9343. }
  9344. }
  9345. }
  9346. validateInstanceId( instanceId ) {
  9347. const instanceInfo = this._instanceInfo;
  9348. if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
  9349. throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
  9350. }
  9351. }
  9352. validateGeometryId( geometryId ) {
  9353. const geometryInfoList = this._geometryInfo;
  9354. if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9355. throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
  9356. }
  9357. }
  9358. setCustomSort( func ) {
  9359. this.customSort = func;
  9360. return this;
  9361. }
  9362. computeBoundingBox() {
  9363. if ( this.boundingBox === null ) {
  9364. this.boundingBox = new Box3();
  9365. }
  9366. const boundingBox = this.boundingBox;
  9367. const instanceInfo = this._instanceInfo;
  9368. boundingBox.makeEmpty();
  9369. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9370. if ( instanceInfo[ i ].active === false ) continue;
  9371. const geometryId = instanceInfo[ i ].geometryIndex;
  9372. this.getMatrixAt( i, _matrix$1 );
  9373. this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 );
  9374. boundingBox.union( _box$1 );
  9375. }
  9376. }
  9377. computeBoundingSphere() {
  9378. if ( this.boundingSphere === null ) {
  9379. this.boundingSphere = new Sphere();
  9380. }
  9381. const boundingSphere = this.boundingSphere;
  9382. const instanceInfo = this._instanceInfo;
  9383. boundingSphere.makeEmpty();
  9384. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9385. if ( instanceInfo[ i ].active === false ) continue;
  9386. const geometryId = instanceInfo[ i ].geometryIndex;
  9387. this.getMatrixAt( i, _matrix$1 );
  9388. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9389. boundingSphere.union( _sphere$2 );
  9390. }
  9391. }
  9392. addInstance( geometryId ) {
  9393. const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
  9394. // ensure we're not over geometry
  9395. if ( atCapacity && this._availableInstanceIds.length === 0 ) {
  9396. throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
  9397. }
  9398. const instanceInfo = {
  9399. visible: true,
  9400. active: true,
  9401. geometryIndex: geometryId,
  9402. };
  9403. let drawId = null;
  9404. // Prioritize using previously freed instance ids
  9405. if ( this._availableInstanceIds.length > 0 ) {
  9406. this._availableInstanceIds.sort( ascIdSort );
  9407. drawId = this._availableInstanceIds.shift();
  9408. this._instanceInfo[ drawId ] = instanceInfo;
  9409. } else {
  9410. drawId = this._instanceInfo.length;
  9411. this._instanceInfo.push( instanceInfo );
  9412. }
  9413. const matricesTexture = this._matricesTexture;
  9414. _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 );
  9415. matricesTexture.needsUpdate = true;
  9416. const colorsTexture = this._colorsTexture;
  9417. if ( colorsTexture ) {
  9418. _whiteColor.toArray( colorsTexture.image.data, drawId * 4 );
  9419. colorsTexture.needsUpdate = true;
  9420. }
  9421. this._visibilityChanged = true;
  9422. return drawId;
  9423. }
  9424. addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) {
  9425. this._initializeGeometry( geometry );
  9426. this._validateGeometry( geometry );
  9427. const geometryInfo = {
  9428. // geometry information
  9429. vertexStart: - 1,
  9430. vertexCount: - 1,
  9431. reservedVertexCount: - 1,
  9432. indexStart: - 1,
  9433. indexCount: - 1,
  9434. reservedIndexCount: - 1,
  9435. // draw range information
  9436. start: - 1,
  9437. count: - 1,
  9438. // state
  9439. boundingBox: null,
  9440. boundingSphere: null,
  9441. active: true,
  9442. };
  9443. const geometryInfoList = this._geometryInfo;
  9444. geometryInfo.vertexStart = this._nextVertexStart;
  9445. geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
  9446. const index = geometry.getIndex();
  9447. const hasIndex = index !== null;
  9448. if ( hasIndex ) {
  9449. geometryInfo.indexStart = this._nextIndexStart;
  9450. geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount;
  9451. }
  9452. if (
  9453. geometryInfo.indexStart !== - 1 &&
  9454. geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
  9455. geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
  9456. ) {
  9457. throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
  9458. }
  9459. // update id
  9460. let geometryId;
  9461. if ( this._availableGeometryIds.length > 0 ) {
  9462. this._availableGeometryIds.sort( ascIdSort );
  9463. geometryId = this._availableGeometryIds.shift();
  9464. geometryInfoList[ geometryId ] = geometryInfo;
  9465. } else {
  9466. geometryId = this._geometryCount;
  9467. this._geometryCount ++;
  9468. geometryInfoList.push( geometryInfo );
  9469. }
  9470. // update the geometry
  9471. this.setGeometryAt( geometryId, geometry );
  9472. // increment the next geometry position
  9473. this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
  9474. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9475. return geometryId;
  9476. }
  9477. setGeometryAt( geometryId, geometry ) {
  9478. if ( geometryId >= this._geometryCount ) {
  9479. throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
  9480. }
  9481. this._validateGeometry( geometry );
  9482. const batchGeometry = this.geometry;
  9483. const hasIndex = batchGeometry.getIndex() !== null;
  9484. const dstIndex = batchGeometry.getIndex();
  9485. const srcIndex = geometry.getIndex();
  9486. const geometryInfo = this._geometryInfo[ geometryId ];
  9487. if (
  9488. hasIndex &&
  9489. srcIndex.count > geometryInfo.reservedIndexCount ||
  9490. geometry.attributes.position.count > geometryInfo.reservedVertexCount
  9491. ) {
  9492. throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
  9493. }
  9494. // copy geometry buffer data over
  9495. const vertexStart = geometryInfo.vertexStart;
  9496. const reservedVertexCount = geometryInfo.reservedVertexCount;
  9497. geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
  9498. for ( const attributeName in batchGeometry.attributes ) {
  9499. // copy attribute data
  9500. const srcAttribute = geometry.getAttribute( attributeName );
  9501. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9502. copyAttributeData( srcAttribute, dstAttribute, vertexStart );
  9503. // fill the rest in with zeroes
  9504. const itemSize = srcAttribute.itemSize;
  9505. for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
  9506. const index = vertexStart + i;
  9507. for ( let c = 0; c < itemSize; c ++ ) {
  9508. dstAttribute.setComponent( index, c, 0 );
  9509. }
  9510. }
  9511. dstAttribute.needsUpdate = true;
  9512. dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
  9513. }
  9514. // copy index
  9515. if ( hasIndex ) {
  9516. const indexStart = geometryInfo.indexStart;
  9517. const reservedIndexCount = geometryInfo.reservedIndexCount;
  9518. geometryInfo.indexCount = geometry.getIndex().count;
  9519. // copy index data over
  9520. for ( let i = 0; i < srcIndex.count; i ++ ) {
  9521. dstIndex.setX( indexStart + i, vertexStart + srcIndex.getX( i ) );
  9522. }
  9523. // fill the rest in with zeroes
  9524. for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
  9525. dstIndex.setX( indexStart + i, vertexStart );
  9526. }
  9527. dstIndex.needsUpdate = true;
  9528. dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
  9529. }
  9530. // update the draw range
  9531. geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9532. geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
  9533. // store the bounding boxes
  9534. geometryInfo.boundingBox = null;
  9535. if ( geometry.boundingBox !== null ) {
  9536. geometryInfo.boundingBox = geometry.boundingBox.clone();
  9537. }
  9538. geometryInfo.boundingSphere = null;
  9539. if ( geometry.boundingSphere !== null ) {
  9540. geometryInfo.boundingSphere = geometry.boundingSphere.clone();
  9541. }
  9542. this._visibilityChanged = true;
  9543. return geometryId;
  9544. }
  9545. deleteGeometry( geometryId ) {
  9546. const geometryInfoList = this._geometryInfo;
  9547. if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9548. return this;
  9549. }
  9550. // delete any instances associated with this geometry
  9551. const instanceInfo = this._instanceInfo;
  9552. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9553. if ( instanceInfo[ i ].geometryIndex === geometryId ) {
  9554. this.deleteInstance( i );
  9555. }
  9556. }
  9557. geometryInfoList[ geometryId ].active = false;
  9558. this._availableGeometryIds.push( geometryId );
  9559. this._visibilityChanged = true;
  9560. return this;
  9561. }
  9562. deleteInstance( instanceId ) {
  9563. this.validateInstanceId( instanceId );
  9564. this._instanceInfo[ instanceId ].active = false;
  9565. this._availableInstanceIds.push( instanceId );
  9566. this._visibilityChanged = true;
  9567. return this;
  9568. }
  9569. optimize() {
  9570. // track the next indices to copy data to
  9571. let nextVertexStart = 0;
  9572. let nextIndexStart = 0;
  9573. // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
  9574. // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
  9575. const geometryInfoList = this._geometryInfo;
  9576. const indices = geometryInfoList
  9577. .map( ( e, i ) => i )
  9578. .sort( ( a, b ) => {
  9579. return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
  9580. } );
  9581. const geometry = this.geometry;
  9582. for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
  9583. // if a geometry range is inactive then don't copy anything
  9584. const index = indices[ i ];
  9585. const geometryInfo = geometryInfoList[ index ];
  9586. if ( geometryInfo.active === false ) {
  9587. continue;
  9588. }
  9589. // if a geometry contains an index buffer then shift it, as well
  9590. if ( geometry.index !== null ) {
  9591. if ( geometryInfo.indexStart !== nextIndexStart ) {
  9592. const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
  9593. const index = geometry.index;
  9594. const array = index.array;
  9595. // shift the index pointers based on how the vertex data will shift
  9596. // adjusting the index must happen first so the original vertex start value is available
  9597. const elementDelta = nextVertexStart - vertexStart;
  9598. for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
  9599. array[ j ] = array[ j ] + elementDelta;
  9600. }
  9601. index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
  9602. index.addUpdateRange( nextIndexStart, reservedIndexCount );
  9603. geometryInfo.indexStart = nextIndexStart;
  9604. }
  9605. nextIndexStart += geometryInfo.reservedIndexCount;
  9606. }
  9607. // if a geometry needs to be moved then copy attribute data to overwrite unused space
  9608. if ( geometryInfo.vertexStart !== nextVertexStart ) {
  9609. const { vertexStart, reservedVertexCount } = geometryInfo;
  9610. const attributes = geometry.attributes;
  9611. for ( const key in attributes ) {
  9612. const attribute = attributes[ key ];
  9613. const { array, itemSize } = attribute;
  9614. array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
  9615. attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
  9616. }
  9617. geometryInfo.vertexStart = nextVertexStart;
  9618. }
  9619. nextVertexStart += geometryInfo.reservedVertexCount;
  9620. geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9621. // step the next geometry points to the shifted position
  9622. this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
  9623. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9624. }
  9625. return this;
  9626. }
  9627. // get bounding box and compute it if it doesn't exist
  9628. getBoundingBoxAt( geometryId, target ) {
  9629. if ( geometryId >= this._geometryCount ) {
  9630. return null;
  9631. }
  9632. // compute bounding box
  9633. const geometry = this.geometry;
  9634. const geometryInfo = this._geometryInfo[ geometryId ];
  9635. if ( geometryInfo.boundingBox === null ) {
  9636. const box = new Box3();
  9637. const index = geometry.index;
  9638. const position = geometry.attributes.position;
  9639. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9640. let iv = i;
  9641. if ( index ) {
  9642. iv = index.getX( iv );
  9643. }
  9644. box.expandByPoint( _vector$5.fromBufferAttribute( position, iv ) );
  9645. }
  9646. geometryInfo.boundingBox = box;
  9647. }
  9648. target.copy( geometryInfo.boundingBox );
  9649. return target;
  9650. }
  9651. // get bounding sphere and compute it if it doesn't exist
  9652. getBoundingSphereAt( geometryId, target ) {
  9653. if ( geometryId >= this._geometryCount ) {
  9654. return null;
  9655. }
  9656. // compute bounding sphere
  9657. const geometry = this.geometry;
  9658. const geometryInfo = this._geometryInfo[ geometryId ];
  9659. if ( geometryInfo.boundingSphere === null ) {
  9660. const sphere = new Sphere();
  9661. this.getBoundingBoxAt( geometryId, _box$1 );
  9662. _box$1.getCenter( sphere.center );
  9663. const index = geometry.index;
  9664. const position = geometry.attributes.position;
  9665. let maxRadiusSq = 0;
  9666. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9667. let iv = i;
  9668. if ( index ) {
  9669. iv = index.getX( iv );
  9670. }
  9671. _vector$5.fromBufferAttribute( position, iv );
  9672. maxRadiusSq = Math.max( maxRadiusSq, sphere.center.distanceToSquared( _vector$5 ) );
  9673. }
  9674. sphere.radius = Math.sqrt( maxRadiusSq );
  9675. geometryInfo.boundingSphere = sphere;
  9676. }
  9677. target.copy( geometryInfo.boundingSphere );
  9678. return target;
  9679. }
  9680. setMatrixAt( instanceId, matrix ) {
  9681. this.validateInstanceId( instanceId );
  9682. const matricesTexture = this._matricesTexture;
  9683. const matricesArray = this._matricesTexture.image.data;
  9684. matrix.toArray( matricesArray, instanceId * 16 );
  9685. matricesTexture.needsUpdate = true;
  9686. return this;
  9687. }
  9688. getMatrixAt( instanceId, matrix ) {
  9689. this.validateInstanceId( instanceId );
  9690. return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
  9691. }
  9692. setColorAt( instanceId, color ) {
  9693. this.validateInstanceId( instanceId );
  9694. if ( this._colorsTexture === null ) {
  9695. this._initColorsTexture();
  9696. }
  9697. color.toArray( this._colorsTexture.image.data, instanceId * 4 );
  9698. this._colorsTexture.needsUpdate = true;
  9699. return this;
  9700. }
  9701. getColorAt( instanceId, color ) {
  9702. this.validateInstanceId( instanceId );
  9703. return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
  9704. }
  9705. setVisibleAt( instanceId, value ) {
  9706. this.validateInstanceId( instanceId );
  9707. if ( this._instanceInfo[ instanceId ].visible === value ) {
  9708. return this;
  9709. }
  9710. this._instanceInfo[ instanceId ].visible = value;
  9711. this._visibilityChanged = true;
  9712. return this;
  9713. }
  9714. getVisibleAt( instanceId ) {
  9715. this.validateInstanceId( instanceId );
  9716. return this._instanceInfo[ instanceId ].visible;
  9717. }
  9718. setGeometryIdAt( instanceId, geometryId ) {
  9719. this.validateInstanceId( instanceId );
  9720. this.validateGeometryId( geometryId );
  9721. this._instanceInfo[ instanceId ].geometryIndex = geometryId;
  9722. return this;
  9723. }
  9724. getGeometryIdAt( instanceId ) {
  9725. this.validateInstanceId( instanceId );
  9726. return this._instanceInfo[ instanceId ].geometryIndex;
  9727. }
  9728. getGeometryRangeAt( geometryId, target = {} ) {
  9729. this.validateGeometryId( geometryId );
  9730. const geometryInfo = this._geometryInfo[ geometryId ];
  9731. target.vertexStart = geometryInfo.vertexStart;
  9732. target.vertexCount = geometryInfo.vertexCount;
  9733. target.reservedVertexCount = geometryInfo.reservedVertexCount;
  9734. target.indexStart = geometryInfo.indexStart;
  9735. target.indexCount = geometryInfo.indexCount;
  9736. target.reservedIndexCount = geometryInfo.reservedIndexCount;
  9737. target.start = geometryInfo.start;
  9738. target.count = geometryInfo.count;
  9739. return target;
  9740. }
  9741. setInstanceCount( maxInstanceCount ) {
  9742. // shrink the available instances as much as possible
  9743. const availableInstanceIds = this._availableInstanceIds;
  9744. const instanceInfo = this._instanceInfo;
  9745. availableInstanceIds.sort( ascIdSort );
  9746. while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
  9747. instanceInfo.pop();
  9748. availableInstanceIds.pop();
  9749. }
  9750. // throw an error if it can't be shrunk to the desired size
  9751. if ( maxInstanceCount < instanceInfo.length ) {
  9752. throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
  9753. }
  9754. // copy the multi draw counts
  9755. const multiDrawCounts = new Int32Array( maxInstanceCount );
  9756. const multiDrawStarts = new Int32Array( maxInstanceCount );
  9757. copyArrayContents( this._multiDrawCounts, multiDrawCounts );
  9758. copyArrayContents( this._multiDrawStarts, multiDrawStarts );
  9759. this._multiDrawCounts = multiDrawCounts;
  9760. this._multiDrawStarts = multiDrawStarts;
  9761. this._maxInstanceCount = maxInstanceCount;
  9762. // update texture data for instance sampling
  9763. const indirectTexture = this._indirectTexture;
  9764. const matricesTexture = this._matricesTexture;
  9765. const colorsTexture = this._colorsTexture;
  9766. indirectTexture.dispose();
  9767. this._initIndirectTexture();
  9768. copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
  9769. matricesTexture.dispose();
  9770. this._initMatricesTexture();
  9771. copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
  9772. if ( colorsTexture ) {
  9773. colorsTexture.dispose();
  9774. this._initColorsTexture();
  9775. copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
  9776. }
  9777. }
  9778. setGeometrySize( maxVertexCount, maxIndexCount ) {
  9779. // Check if we can shrink to the requested vertex attribute size
  9780. const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
  9781. const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
  9782. if ( requiredVertexLength > maxVertexCount ) {
  9783. throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9784. }
  9785. // Check if we can shrink to the requested index attribute size
  9786. if ( this.geometry.index ) {
  9787. const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
  9788. if ( requiredIndexLength > maxIndexCount ) {
  9789. throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9790. }
  9791. }
  9792. //
  9793. // dispose of the previous geometry
  9794. const oldGeometry = this.geometry;
  9795. oldGeometry.dispose();
  9796. // recreate the geometry needed based on the previous variant
  9797. this._maxVertexCount = maxVertexCount;
  9798. this._maxIndexCount = maxIndexCount;
  9799. if ( this._geometryInitialized ) {
  9800. this._geometryInitialized = false;
  9801. this.geometry = new BufferGeometry();
  9802. this._initializeGeometry( oldGeometry );
  9803. }
  9804. // copy data from the previous geometry
  9805. const geometry = this.geometry;
  9806. if ( oldGeometry.index ) {
  9807. copyArrayContents( oldGeometry.index.array, geometry.index.array );
  9808. }
  9809. for ( const key in oldGeometry.attributes ) {
  9810. copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
  9811. }
  9812. }
  9813. raycast( raycaster, intersects ) {
  9814. const instanceInfo = this._instanceInfo;
  9815. const geometryInfoList = this._geometryInfo;
  9816. const matrixWorld = this.matrixWorld;
  9817. const batchGeometry = this.geometry;
  9818. // iterate over each geometry
  9819. _mesh.material = this.material;
  9820. _mesh.geometry.index = batchGeometry.index;
  9821. _mesh.geometry.attributes = batchGeometry.attributes;
  9822. if ( _mesh.geometry.boundingBox === null ) {
  9823. _mesh.geometry.boundingBox = new Box3();
  9824. }
  9825. if ( _mesh.geometry.boundingSphere === null ) {
  9826. _mesh.geometry.boundingSphere = new Sphere();
  9827. }
  9828. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9829. if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
  9830. continue;
  9831. }
  9832. const geometryId = instanceInfo[ i ].geometryIndex;
  9833. const geometryInfo = geometryInfoList[ geometryId ];
  9834. _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
  9835. // get the intersects
  9836. this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
  9837. this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
  9838. this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
  9839. _mesh.raycast( raycaster, _batchIntersects );
  9840. // add batch id to the intersects
  9841. for ( let j = 0, l = _batchIntersects.length; j < l; j ++ ) {
  9842. const intersect = _batchIntersects[ j ];
  9843. intersect.object = this;
  9844. intersect.batchId = i;
  9845. intersects.push( intersect );
  9846. }
  9847. _batchIntersects.length = 0;
  9848. }
  9849. _mesh.material = null;
  9850. _mesh.geometry.index = null;
  9851. _mesh.geometry.attributes = {};
  9852. _mesh.geometry.setDrawRange( 0, Infinity );
  9853. }
  9854. copy( source ) {
  9855. super.copy( source );
  9856. this.geometry = source.geometry.clone();
  9857. this.perObjectFrustumCulled = source.perObjectFrustumCulled;
  9858. this.sortObjects = source.sortObjects;
  9859. this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
  9860. this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
  9861. this._geometryInfo = source._geometryInfo.map( info => ( {
  9862. ...info,
  9863. boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
  9864. boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
  9865. } ) );
  9866. this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
  9867. this._maxInstanceCount = source._maxInstanceCount;
  9868. this._maxVertexCount = source._maxVertexCount;
  9869. this._maxIndexCount = source._maxIndexCount;
  9870. this._geometryInitialized = source._geometryInitialized;
  9871. this._geometryCount = source._geometryCount;
  9872. this._multiDrawCounts = source._multiDrawCounts.slice();
  9873. this._multiDrawStarts = source._multiDrawStarts.slice();
  9874. this._matricesTexture = source._matricesTexture.clone();
  9875. this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
  9876. if ( this._colorsTexture !== null ) {
  9877. this._colorsTexture = source._colorsTexture.clone();
  9878. this._colorsTexture.image.data = this._colorsTexture.image.data.slice();
  9879. }
  9880. return this;
  9881. }
  9882. dispose() {
  9883. // Assuming the geometry is not shared with other meshes
  9884. this.geometry.dispose();
  9885. this._matricesTexture.dispose();
  9886. this._matricesTexture = null;
  9887. this._indirectTexture.dispose();
  9888. this._indirectTexture = null;
  9889. if ( this._colorsTexture !== null ) {
  9890. this._colorsTexture.dispose();
  9891. this._colorsTexture = null;
  9892. }
  9893. return this;
  9894. }
  9895. onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) {
  9896. // if visibility has not changed and frustum culling and object sorting is not required
  9897. // then skip iterating over all items
  9898. if ( ! this._visibilityChanged && ! this.perObjectFrustumCulled && ! this.sortObjects ) {
  9899. return;
  9900. }
  9901. // the indexed version of the multi draw function requires specifying the start
  9902. // offset in bytes.
  9903. const index = geometry.getIndex();
  9904. const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
  9905. const instanceInfo = this._instanceInfo;
  9906. const multiDrawStarts = this._multiDrawStarts;
  9907. const multiDrawCounts = this._multiDrawCounts;
  9908. const geometryInfoList = this._geometryInfo;
  9909. const perObjectFrustumCulled = this.perObjectFrustumCulled;
  9910. const indirectTexture = this._indirectTexture;
  9911. const indirectArray = indirectTexture.image.data;
  9912. // prepare the frustum in the local frame
  9913. if ( perObjectFrustumCulled ) {
  9914. _matrix$1
  9915. .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
  9916. .multiply( this.matrixWorld );
  9917. _frustum.setFromProjectionMatrix(
  9918. _matrix$1,
  9919. renderer.coordinateSystem
  9920. );
  9921. }
  9922. let multiDrawCount = 0;
  9923. if ( this.sortObjects ) {
  9924. // get the camera position in the local frame
  9925. _matrix$1.copy( this.matrixWorld ).invert();
  9926. _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 );
  9927. _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 );
  9928. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9929. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9930. const geometryId = instanceInfo[ i ].geometryIndex;
  9931. // get the bounds in world space
  9932. this.getMatrixAt( i, _matrix$1 );
  9933. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9934. // determine whether the batched geometry is within the frustum
  9935. let culled = false;
  9936. if ( perObjectFrustumCulled ) {
  9937. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9938. }
  9939. if ( ! culled ) {
  9940. // get the distance from camera used for sorting
  9941. const geometryInfo = geometryInfoList[ geometryId ];
  9942. const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
  9943. _renderList.push( geometryInfo.start, geometryInfo.count, z, i );
  9944. }
  9945. }
  9946. }
  9947. // Sort the draw ranges and prep for rendering
  9948. const list = _renderList.list;
  9949. const customSort = this.customSort;
  9950. if ( customSort === null ) {
  9951. list.sort( material.transparent ? sortTransparent : sortOpaque );
  9952. } else {
  9953. customSort.call( this, list, camera );
  9954. }
  9955. for ( let i = 0, l = list.length; i < l; i ++ ) {
  9956. const item = list[ i ];
  9957. multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement;
  9958. multiDrawCounts[ multiDrawCount ] = item.count;
  9959. indirectArray[ multiDrawCount ] = item.index;
  9960. multiDrawCount ++;
  9961. }
  9962. _renderList.reset();
  9963. } else {
  9964. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9965. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9966. const geometryId = instanceInfo[ i ].geometryIndex;
  9967. // determine whether the batched geometry is within the frustum
  9968. let culled = false;
  9969. if ( perObjectFrustumCulled ) {
  9970. // get the bounds in world space
  9971. this.getMatrixAt( i, _matrix$1 );
  9972. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9973. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9974. }
  9975. if ( ! culled ) {
  9976. const geometryInfo = geometryInfoList[ geometryId ];
  9977. multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement;
  9978. multiDrawCounts[ multiDrawCount ] = geometryInfo.count;
  9979. indirectArray[ multiDrawCount ] = i;
  9980. multiDrawCount ++;
  9981. }
  9982. }
  9983. }
  9984. }
  9985. indirectTexture.needsUpdate = true;
  9986. this._multiDrawCount = multiDrawCount;
  9987. this._visibilityChanged = false;
  9988. }
  9989. onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial/* , group */ ) {
  9990. this.onBeforeRender( renderer, null, shadowCamera, geometry, depthMaterial );
  9991. }
  9992. }
  9993. class LineBasicMaterial extends Material {
  9994. constructor( parameters ) {
  9995. super();
  9996. this.isLineBasicMaterial = true;
  9997. this.type = 'LineBasicMaterial';
  9998. this.color = new Color( 0xffffff );
  9999. this.map = null;
  10000. this.linewidth = 1;
  10001. this.linecap = 'round';
  10002. this.linejoin = 'round';
  10003. this.fog = true;
  10004. this.setValues( parameters );
  10005. }
  10006. copy( source ) {
  10007. super.copy( source );
  10008. this.color.copy( source.color );
  10009. this.map = source.map;
  10010. this.linewidth = source.linewidth;
  10011. this.linecap = source.linecap;
  10012. this.linejoin = source.linejoin;
  10013. this.fog = source.fog;
  10014. return this;
  10015. }
  10016. }
  10017. const _vStart = /*@__PURE__*/ new Vector3();
  10018. const _vEnd = /*@__PURE__*/ new Vector3();
  10019. const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
  10020. const _ray$1 = /*@__PURE__*/ new Ray();
  10021. const _sphere$1 = /*@__PURE__*/ new Sphere();
  10022. const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
  10023. const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
  10024. class Line extends Object3D {
  10025. constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  10026. super();
  10027. this.isLine = true;
  10028. this.type = 'Line';
  10029. this.geometry = geometry;
  10030. this.material = material;
  10031. this.updateMorphTargets();
  10032. }
  10033. copy( source, recursive ) {
  10034. super.copy( source, recursive );
  10035. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10036. this.geometry = source.geometry;
  10037. return this;
  10038. }
  10039. computeLineDistances() {
  10040. const geometry = this.geometry;
  10041. // we assume non-indexed geometry
  10042. if ( geometry.index === null ) {
  10043. const positionAttribute = geometry.attributes.position;
  10044. const lineDistances = [ 0 ];
  10045. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  10046. _vStart.fromBufferAttribute( positionAttribute, i - 1 );
  10047. _vEnd.fromBufferAttribute( positionAttribute, i );
  10048. lineDistances[ i ] = lineDistances[ i - 1 ];
  10049. lineDistances[ i ] += _vStart.distanceTo( _vEnd );
  10050. }
  10051. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10052. } else {
  10053. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10054. }
  10055. return this;
  10056. }
  10057. raycast( raycaster, intersects ) {
  10058. const geometry = this.geometry;
  10059. const matrixWorld = this.matrixWorld;
  10060. const threshold = raycaster.params.Line.threshold;
  10061. const drawRange = geometry.drawRange;
  10062. // Checking boundingSphere distance to ray
  10063. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10064. _sphere$1.copy( geometry.boundingSphere );
  10065. _sphere$1.applyMatrix4( matrixWorld );
  10066. _sphere$1.radius += threshold;
  10067. if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
  10068. //
  10069. _inverseMatrix$1.copy( matrixWorld ).invert();
  10070. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  10071. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10072. const localThresholdSq = localThreshold * localThreshold;
  10073. const step = this.isLineSegments ? 2 : 1;
  10074. const index = geometry.index;
  10075. const attributes = geometry.attributes;
  10076. const positionAttribute = attributes.position;
  10077. if ( index !== null ) {
  10078. const start = Math.max( 0, drawRange.start );
  10079. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10080. for ( let i = start, l = end - 1; i < l; i += step ) {
  10081. const a = index.getX( i );
  10082. const b = index.getX( i + 1 );
  10083. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10084. if ( intersect ) {
  10085. intersects.push( intersect );
  10086. }
  10087. }
  10088. if ( this.isLineLoop ) {
  10089. const a = index.getX( end - 1 );
  10090. const b = index.getX( start );
  10091. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10092. if ( intersect ) {
  10093. intersects.push( intersect );
  10094. }
  10095. }
  10096. } else {
  10097. const start = Math.max( 0, drawRange.start );
  10098. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10099. for ( let i = start, l = end - 1; i < l; i += step ) {
  10100. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 );
  10101. if ( intersect ) {
  10102. intersects.push( intersect );
  10103. }
  10104. }
  10105. if ( this.isLineLoop ) {
  10106. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start );
  10107. if ( intersect ) {
  10108. intersects.push( intersect );
  10109. }
  10110. }
  10111. }
  10112. }
  10113. updateMorphTargets() {
  10114. const geometry = this.geometry;
  10115. const morphAttributes = geometry.morphAttributes;
  10116. const keys = Object.keys( morphAttributes );
  10117. if ( keys.length > 0 ) {
  10118. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10119. if ( morphAttribute !== undefined ) {
  10120. this.morphTargetInfluences = [];
  10121. this.morphTargetDictionary = {};
  10122. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10123. const name = morphAttribute[ m ].name || String( m );
  10124. this.morphTargetInfluences.push( 0 );
  10125. this.morphTargetDictionary[ name ] = m;
  10126. }
  10127. }
  10128. }
  10129. }
  10130. }
  10131. function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
  10132. const positionAttribute = object.geometry.attributes.position;
  10133. _vStart.fromBufferAttribute( positionAttribute, a );
  10134. _vEnd.fromBufferAttribute( positionAttribute, b );
  10135. const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
  10136. if ( distSq > thresholdSq ) return;
  10137. _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
  10138. const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
  10139. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10140. return {
  10141. distance: distance,
  10142. // What do we want? intersection point on the ray or on the segment??
  10143. // point: raycaster.ray.at( distance ),
  10144. point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
  10145. index: a,
  10146. face: null,
  10147. faceIndex: null,
  10148. barycoord: null,
  10149. object: object
  10150. };
  10151. }
  10152. const _start = /*@__PURE__*/ new Vector3();
  10153. const _end = /*@__PURE__*/ new Vector3();
  10154. class LineSegments extends Line {
  10155. constructor( geometry, material ) {
  10156. super( geometry, material );
  10157. this.isLineSegments = true;
  10158. this.type = 'LineSegments';
  10159. }
  10160. computeLineDistances() {
  10161. const geometry = this.geometry;
  10162. // we assume non-indexed geometry
  10163. if ( geometry.index === null ) {
  10164. const positionAttribute = geometry.attributes.position;
  10165. const lineDistances = [];
  10166. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  10167. _start.fromBufferAttribute( positionAttribute, i );
  10168. _end.fromBufferAttribute( positionAttribute, i + 1 );
  10169. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  10170. lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
  10171. }
  10172. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10173. } else {
  10174. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10175. }
  10176. return this;
  10177. }
  10178. }
  10179. class LineLoop extends Line {
  10180. constructor( geometry, material ) {
  10181. super( geometry, material );
  10182. this.isLineLoop = true;
  10183. this.type = 'LineLoop';
  10184. }
  10185. }
  10186. class PointsMaterial extends Material {
  10187. constructor( parameters ) {
  10188. super();
  10189. this.isPointsMaterial = true;
  10190. this.type = 'PointsMaterial';
  10191. this.color = new Color( 0xffffff );
  10192. this.map = null;
  10193. this.alphaMap = null;
  10194. this.size = 1;
  10195. this.sizeAttenuation = true;
  10196. this.fog = true;
  10197. this.setValues( parameters );
  10198. }
  10199. copy( source ) {
  10200. super.copy( source );
  10201. this.color.copy( source.color );
  10202. this.map = source.map;
  10203. this.alphaMap = source.alphaMap;
  10204. this.size = source.size;
  10205. this.sizeAttenuation = source.sizeAttenuation;
  10206. this.fog = source.fog;
  10207. return this;
  10208. }
  10209. }
  10210. const _inverseMatrix = /*@__PURE__*/ new Matrix4();
  10211. const _ray = /*@__PURE__*/ new Ray();
  10212. const _sphere = /*@__PURE__*/ new Sphere();
  10213. const _position$2 = /*@__PURE__*/ new Vector3();
  10214. class Points extends Object3D {
  10215. constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  10216. super();
  10217. this.isPoints = true;
  10218. this.type = 'Points';
  10219. this.geometry = geometry;
  10220. this.material = material;
  10221. this.updateMorphTargets();
  10222. }
  10223. copy( source, recursive ) {
  10224. super.copy( source, recursive );
  10225. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10226. this.geometry = source.geometry;
  10227. return this;
  10228. }
  10229. raycast( raycaster, intersects ) {
  10230. const geometry = this.geometry;
  10231. const matrixWorld = this.matrixWorld;
  10232. const threshold = raycaster.params.Points.threshold;
  10233. const drawRange = geometry.drawRange;
  10234. // Checking boundingSphere distance to ray
  10235. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10236. _sphere.copy( geometry.boundingSphere );
  10237. _sphere.applyMatrix4( matrixWorld );
  10238. _sphere.radius += threshold;
  10239. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  10240. //
  10241. _inverseMatrix.copy( matrixWorld ).invert();
  10242. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  10243. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10244. const localThresholdSq = localThreshold * localThreshold;
  10245. const index = geometry.index;
  10246. const attributes = geometry.attributes;
  10247. const positionAttribute = attributes.position;
  10248. if ( index !== null ) {
  10249. const start = Math.max( 0, drawRange.start );
  10250. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10251. for ( let i = start, il = end; i < il; i ++ ) {
  10252. const a = index.getX( i );
  10253. _position$2.fromBufferAttribute( positionAttribute, a );
  10254. testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10255. }
  10256. } else {
  10257. const start = Math.max( 0, drawRange.start );
  10258. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10259. for ( let i = start, l = end; i < l; i ++ ) {
  10260. _position$2.fromBufferAttribute( positionAttribute, i );
  10261. testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10262. }
  10263. }
  10264. }
  10265. updateMorphTargets() {
  10266. const geometry = this.geometry;
  10267. const morphAttributes = geometry.morphAttributes;
  10268. const keys = Object.keys( morphAttributes );
  10269. if ( keys.length > 0 ) {
  10270. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10271. if ( morphAttribute !== undefined ) {
  10272. this.morphTargetInfluences = [];
  10273. this.morphTargetDictionary = {};
  10274. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10275. const name = morphAttribute[ m ].name || String( m );
  10276. this.morphTargetInfluences.push( 0 );
  10277. this.morphTargetDictionary[ name ] = m;
  10278. }
  10279. }
  10280. }
  10281. }
  10282. }
  10283. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  10284. const rayPointDistanceSq = _ray.distanceSqToPoint( point );
  10285. if ( rayPointDistanceSq < localThresholdSq ) {
  10286. const intersectPoint = new Vector3();
  10287. _ray.closestPointToPoint( point, intersectPoint );
  10288. intersectPoint.applyMatrix4( matrixWorld );
  10289. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10290. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10291. intersects.push( {
  10292. distance: distance,
  10293. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10294. point: intersectPoint,
  10295. index: index,
  10296. face: null,
  10297. faceIndex: null,
  10298. barycoord: null,
  10299. object: object
  10300. } );
  10301. }
  10302. }
  10303. class Group extends Object3D {
  10304. constructor() {
  10305. super();
  10306. this.isGroup = true;
  10307. this.type = 'Group';
  10308. }
  10309. }
  10310. class VideoTexture extends Texture {
  10311. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10312. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10313. this.isVideoTexture = true;
  10314. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  10315. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  10316. this.generateMipmaps = false;
  10317. const scope = this;
  10318. function updateVideo() {
  10319. scope.needsUpdate = true;
  10320. video.requestVideoFrameCallback( updateVideo );
  10321. }
  10322. if ( 'requestVideoFrameCallback' in video ) {
  10323. video.requestVideoFrameCallback( updateVideo );
  10324. }
  10325. }
  10326. clone() {
  10327. return new this.constructor( this.image ).copy( this );
  10328. }
  10329. update() {
  10330. const video = this.image;
  10331. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  10332. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  10333. this.needsUpdate = true;
  10334. }
  10335. }
  10336. }
  10337. class FramebufferTexture extends Texture {
  10338. constructor( width, height ) {
  10339. super( { width, height } );
  10340. this.isFramebufferTexture = true;
  10341. this.magFilter = NearestFilter;
  10342. this.minFilter = NearestFilter;
  10343. this.generateMipmaps = false;
  10344. this.needsUpdate = true;
  10345. }
  10346. }
  10347. class CompressedTexture extends Texture {
  10348. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) {
  10349. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  10350. this.isCompressedTexture = true;
  10351. this.image = { width: width, height: height };
  10352. this.mipmaps = mipmaps;
  10353. // no flipping for cube textures
  10354. // (also flipping doesn't work for compressed textures )
  10355. this.flipY = false;
  10356. // can't generate mipmaps for compressed textures
  10357. // mips must be embedded in DDS files
  10358. this.generateMipmaps = false;
  10359. }
  10360. }
  10361. class CompressedArrayTexture extends CompressedTexture {
  10362. constructor( mipmaps, width, height, depth, format, type ) {
  10363. super( mipmaps, width, height, format, type );
  10364. this.isCompressedArrayTexture = true;
  10365. this.image.depth = depth;
  10366. this.wrapR = ClampToEdgeWrapping;
  10367. this.layerUpdates = new Set();
  10368. }
  10369. addLayerUpdate( layerIndex ) {
  10370. this.layerUpdates.add( layerIndex );
  10371. }
  10372. clearLayerUpdates() {
  10373. this.layerUpdates.clear();
  10374. }
  10375. }
  10376. class CompressedCubeTexture extends CompressedTexture {
  10377. constructor( images, format, type ) {
  10378. super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );
  10379. this.isCompressedCubeTexture = true;
  10380. this.isCubeTexture = true;
  10381. this.image = images;
  10382. }
  10383. }
  10384. class CanvasTexture extends Texture {
  10385. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10386. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10387. this.isCanvasTexture = true;
  10388. this.needsUpdate = true;
  10389. }
  10390. }
  10391. class DepthTexture extends Texture {
  10392. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
  10393. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  10394. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  10395. }
  10396. if ( type === undefined && format === DepthFormat ) type = UnsignedIntType;
  10397. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  10398. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10399. this.isDepthTexture = true;
  10400. this.image = { width: width, height: height };
  10401. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  10402. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  10403. this.flipY = false;
  10404. this.generateMipmaps = false;
  10405. this.compareFunction = null;
  10406. }
  10407. copy( source ) {
  10408. super.copy( source );
  10409. this.compareFunction = source.compareFunction;
  10410. return this;
  10411. }
  10412. toJSON( meta ) {
  10413. const data = super.toJSON( meta );
  10414. if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;
  10415. return data;
  10416. }
  10417. }
  10418. /**
  10419. * Extensible curve object.
  10420. *
  10421. * Some common of curve methods:
  10422. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  10423. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  10424. * .getPoints(), .getSpacedPoints()
  10425. * .getLength()
  10426. * .updateArcLengths()
  10427. *
  10428. * This following curves inherit from THREE.Curve:
  10429. *
  10430. * -- 2D curves --
  10431. * THREE.ArcCurve
  10432. * THREE.CubicBezierCurve
  10433. * THREE.EllipseCurve
  10434. * THREE.LineCurve
  10435. * THREE.QuadraticBezierCurve
  10436. * THREE.SplineCurve
  10437. *
  10438. * -- 3D curves --
  10439. * THREE.CatmullRomCurve3
  10440. * THREE.CubicBezierCurve3
  10441. * THREE.LineCurve3
  10442. * THREE.QuadraticBezierCurve3
  10443. *
  10444. * A series of curves can be represented as a THREE.CurvePath.
  10445. *
  10446. **/
  10447. class Curve {
  10448. constructor() {
  10449. this.type = 'Curve';
  10450. this.arcLengthDivisions = 200;
  10451. }
  10452. // Virtual base class method to overwrite and implement in subclasses
  10453. // - t [0 .. 1]
  10454. getPoint( /* t, optionalTarget */ ) {
  10455. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  10456. return null;
  10457. }
  10458. // Get point at relative position in curve according to arc length
  10459. // - u [0 .. 1]
  10460. getPointAt( u, optionalTarget ) {
  10461. const t = this.getUtoTmapping( u );
  10462. return this.getPoint( t, optionalTarget );
  10463. }
  10464. // Get sequence of points using getPoint( t )
  10465. getPoints( divisions = 5 ) {
  10466. const points = [];
  10467. for ( let d = 0; d <= divisions; d ++ ) {
  10468. points.push( this.getPoint( d / divisions ) );
  10469. }
  10470. return points;
  10471. }
  10472. // Get sequence of points using getPointAt( u )
  10473. getSpacedPoints( divisions = 5 ) {
  10474. const points = [];
  10475. for ( let d = 0; d <= divisions; d ++ ) {
  10476. points.push( this.getPointAt( d / divisions ) );
  10477. }
  10478. return points;
  10479. }
  10480. // Get total curve arc length
  10481. getLength() {
  10482. const lengths = this.getLengths();
  10483. return lengths[ lengths.length - 1 ];
  10484. }
  10485. // Get list of cumulative segment lengths
  10486. getLengths( divisions = this.arcLengthDivisions ) {
  10487. if ( this.cacheArcLengths &&
  10488. ( this.cacheArcLengths.length === divisions + 1 ) &&
  10489. ! this.needsUpdate ) {
  10490. return this.cacheArcLengths;
  10491. }
  10492. this.needsUpdate = false;
  10493. const cache = [];
  10494. let current, last = this.getPoint( 0 );
  10495. let sum = 0;
  10496. cache.push( 0 );
  10497. for ( let p = 1; p <= divisions; p ++ ) {
  10498. current = this.getPoint( p / divisions );
  10499. sum += current.distanceTo( last );
  10500. cache.push( sum );
  10501. last = current;
  10502. }
  10503. this.cacheArcLengths = cache;
  10504. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  10505. }
  10506. updateArcLengths() {
  10507. this.needsUpdate = true;
  10508. this.getLengths();
  10509. }
  10510. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  10511. getUtoTmapping( u, distance ) {
  10512. const arcLengths = this.getLengths();
  10513. let i = 0;
  10514. const il = arcLengths.length;
  10515. let targetArcLength; // The targeted u distance value to get
  10516. if ( distance ) {
  10517. targetArcLength = distance;
  10518. } else {
  10519. targetArcLength = u * arcLengths[ il - 1 ];
  10520. }
  10521. // binary search for the index with largest value smaller than target u distance
  10522. let low = 0, high = il - 1, comparison;
  10523. while ( low <= high ) {
  10524. 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
  10525. comparison = arcLengths[ i ] - targetArcLength;
  10526. if ( comparison < 0 ) {
  10527. low = i + 1;
  10528. } else if ( comparison > 0 ) {
  10529. high = i - 1;
  10530. } else {
  10531. high = i;
  10532. break;
  10533. // DONE
  10534. }
  10535. }
  10536. i = high;
  10537. if ( arcLengths[ i ] === targetArcLength ) {
  10538. return i / ( il - 1 );
  10539. }
  10540. // we could get finer grain at lengths, or use simple interpolation between two points
  10541. const lengthBefore = arcLengths[ i ];
  10542. const lengthAfter = arcLengths[ i + 1 ];
  10543. const segmentLength = lengthAfter - lengthBefore;
  10544. // determine where we are between the 'before' and 'after' points
  10545. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  10546. // add that fractional amount to t
  10547. const t = ( i + segmentFraction ) / ( il - 1 );
  10548. return t;
  10549. }
  10550. // Returns a unit vector tangent at t
  10551. // In case any sub curve does not implement its tangent derivation,
  10552. // 2 points a small delta apart will be used to find its gradient
  10553. // which seems to give a reasonable approximation
  10554. getTangent( t, optionalTarget ) {
  10555. const delta = 0.0001;
  10556. let t1 = t - delta;
  10557. let t2 = t + delta;
  10558. // Capping in case of danger
  10559. if ( t1 < 0 ) t1 = 0;
  10560. if ( t2 > 1 ) t2 = 1;
  10561. const pt1 = this.getPoint( t1 );
  10562. const pt2 = this.getPoint( t2 );
  10563. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  10564. tangent.copy( pt2 ).sub( pt1 ).normalize();
  10565. return tangent;
  10566. }
  10567. getTangentAt( u, optionalTarget ) {
  10568. const t = this.getUtoTmapping( u );
  10569. return this.getTangent( t, optionalTarget );
  10570. }
  10571. computeFrenetFrames( segments, closed ) {
  10572. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  10573. const normal = new Vector3();
  10574. const tangents = [];
  10575. const normals = [];
  10576. const binormals = [];
  10577. const vec = new Vector3();
  10578. const mat = new Matrix4();
  10579. // compute the tangent vectors for each segment on the curve
  10580. for ( let i = 0; i <= segments; i ++ ) {
  10581. const u = i / segments;
  10582. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  10583. }
  10584. // select an initial normal vector perpendicular to the first tangent vector,
  10585. // and in the direction of the minimum tangent xyz component
  10586. normals[ 0 ] = new Vector3();
  10587. binormals[ 0 ] = new Vector3();
  10588. let min = Number.MAX_VALUE;
  10589. const tx = Math.abs( tangents[ 0 ].x );
  10590. const ty = Math.abs( tangents[ 0 ].y );
  10591. const tz = Math.abs( tangents[ 0 ].z );
  10592. if ( tx <= min ) {
  10593. min = tx;
  10594. normal.set( 1, 0, 0 );
  10595. }
  10596. if ( ty <= min ) {
  10597. min = ty;
  10598. normal.set( 0, 1, 0 );
  10599. }
  10600. if ( tz <= min ) {
  10601. normal.set( 0, 0, 1 );
  10602. }
  10603. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  10604. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  10605. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  10606. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  10607. for ( let i = 1; i <= segments; i ++ ) {
  10608. normals[ i ] = normals[ i - 1 ].clone();
  10609. binormals[ i ] = binormals[ i - 1 ].clone();
  10610. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  10611. if ( vec.length() > Number.EPSILON ) {
  10612. vec.normalize();
  10613. const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  10614. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  10615. }
  10616. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10617. }
  10618. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  10619. if ( closed === true ) {
  10620. let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  10621. theta /= segments;
  10622. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  10623. theta = - theta;
  10624. }
  10625. for ( let i = 1; i <= segments; i ++ ) {
  10626. // twist a little...
  10627. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  10628. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10629. }
  10630. }
  10631. return {
  10632. tangents: tangents,
  10633. normals: normals,
  10634. binormals: binormals
  10635. };
  10636. }
  10637. clone() {
  10638. return new this.constructor().copy( this );
  10639. }
  10640. copy( source ) {
  10641. this.arcLengthDivisions = source.arcLengthDivisions;
  10642. return this;
  10643. }
  10644. toJSON() {
  10645. const data = {
  10646. metadata: {
  10647. version: 4.6,
  10648. type: 'Curve',
  10649. generator: 'Curve.toJSON'
  10650. }
  10651. };
  10652. data.arcLengthDivisions = this.arcLengthDivisions;
  10653. data.type = this.type;
  10654. return data;
  10655. }
  10656. fromJSON( json ) {
  10657. this.arcLengthDivisions = json.arcLengthDivisions;
  10658. return this;
  10659. }
  10660. }
  10661. class EllipseCurve extends Curve {
  10662. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  10663. super();
  10664. this.isEllipseCurve = true;
  10665. this.type = 'EllipseCurve';
  10666. this.aX = aX;
  10667. this.aY = aY;
  10668. this.xRadius = xRadius;
  10669. this.yRadius = yRadius;
  10670. this.aStartAngle = aStartAngle;
  10671. this.aEndAngle = aEndAngle;
  10672. this.aClockwise = aClockwise;
  10673. this.aRotation = aRotation;
  10674. }
  10675. getPoint( t, optionalTarget = new Vector2() ) {
  10676. const point = optionalTarget;
  10677. const twoPi = Math.PI * 2;
  10678. let deltaAngle = this.aEndAngle - this.aStartAngle;
  10679. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  10680. // ensures that deltaAngle is 0 .. 2 PI
  10681. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  10682. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  10683. if ( deltaAngle < Number.EPSILON ) {
  10684. if ( samePoints ) {
  10685. deltaAngle = 0;
  10686. } else {
  10687. deltaAngle = twoPi;
  10688. }
  10689. }
  10690. if ( this.aClockwise === true && ! samePoints ) {
  10691. if ( deltaAngle === twoPi ) {
  10692. deltaAngle = - twoPi;
  10693. } else {
  10694. deltaAngle = deltaAngle - twoPi;
  10695. }
  10696. }
  10697. const angle = this.aStartAngle + t * deltaAngle;
  10698. let x = this.aX + this.xRadius * Math.cos( angle );
  10699. let y = this.aY + this.yRadius * Math.sin( angle );
  10700. if ( this.aRotation !== 0 ) {
  10701. const cos = Math.cos( this.aRotation );
  10702. const sin = Math.sin( this.aRotation );
  10703. const tx = x - this.aX;
  10704. const ty = y - this.aY;
  10705. // Rotate the point about the center of the ellipse.
  10706. x = tx * cos - ty * sin + this.aX;
  10707. y = tx * sin + ty * cos + this.aY;
  10708. }
  10709. return point.set( x, y );
  10710. }
  10711. copy( source ) {
  10712. super.copy( source );
  10713. this.aX = source.aX;
  10714. this.aY = source.aY;
  10715. this.xRadius = source.xRadius;
  10716. this.yRadius = source.yRadius;
  10717. this.aStartAngle = source.aStartAngle;
  10718. this.aEndAngle = source.aEndAngle;
  10719. this.aClockwise = source.aClockwise;
  10720. this.aRotation = source.aRotation;
  10721. return this;
  10722. }
  10723. toJSON() {
  10724. const data = super.toJSON();
  10725. data.aX = this.aX;
  10726. data.aY = this.aY;
  10727. data.xRadius = this.xRadius;
  10728. data.yRadius = this.yRadius;
  10729. data.aStartAngle = this.aStartAngle;
  10730. data.aEndAngle = this.aEndAngle;
  10731. data.aClockwise = this.aClockwise;
  10732. data.aRotation = this.aRotation;
  10733. return data;
  10734. }
  10735. fromJSON( json ) {
  10736. super.fromJSON( json );
  10737. this.aX = json.aX;
  10738. this.aY = json.aY;
  10739. this.xRadius = json.xRadius;
  10740. this.yRadius = json.yRadius;
  10741. this.aStartAngle = json.aStartAngle;
  10742. this.aEndAngle = json.aEndAngle;
  10743. this.aClockwise = json.aClockwise;
  10744. this.aRotation = json.aRotation;
  10745. return this;
  10746. }
  10747. }
  10748. class ArcCurve extends EllipseCurve {
  10749. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  10750. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  10751. this.isArcCurve = true;
  10752. this.type = 'ArcCurve';
  10753. }
  10754. }
  10755. /**
  10756. * Centripetal CatmullRom Curve - which is useful for avoiding
  10757. * cusps and self-intersections in non-uniform catmull rom curves.
  10758. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  10759. *
  10760. * curve.type accepts centripetal(default), chordal and catmullrom
  10761. * curve.tension is used for catmullrom which defaults to 0.5
  10762. */
  10763. /*
  10764. Based on an optimized c++ solution in
  10765. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  10766. - http://ideone.com/NoEbVM
  10767. This CubicPoly class could be used for reusing some variables and calculations,
  10768. but for three.js curve use, it could be possible inlined and flatten into a single function call
  10769. which can be placed in CurveUtils.
  10770. */
  10771. function CubicPoly() {
  10772. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  10773. /*
  10774. * Compute coefficients for a cubic polynomial
  10775. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  10776. * such that
  10777. * p(0) = x0, p(1) = x1
  10778. * and
  10779. * p'(0) = t0, p'(1) = t1.
  10780. */
  10781. function init( x0, x1, t0, t1 ) {
  10782. c0 = x0;
  10783. c1 = t0;
  10784. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  10785. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  10786. }
  10787. return {
  10788. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  10789. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  10790. },
  10791. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  10792. // compute tangents when parameterized in [t1,t2]
  10793. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  10794. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  10795. // rescale tangents for parametrization in [0,1]
  10796. t1 *= dt1;
  10797. t2 *= dt1;
  10798. init( x1, x2, t1, t2 );
  10799. },
  10800. calc: function ( t ) {
  10801. const t2 = t * t;
  10802. const t3 = t2 * t;
  10803. return c0 + c1 * t + c2 * t2 + c3 * t3;
  10804. }
  10805. };
  10806. }
  10807. //
  10808. const tmp = /*@__PURE__*/ new Vector3();
  10809. const px = /*@__PURE__*/ new CubicPoly();
  10810. const py = /*@__PURE__*/ new CubicPoly();
  10811. const pz = /*@__PURE__*/ new CubicPoly();
  10812. class CatmullRomCurve3 extends Curve {
  10813. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  10814. super();
  10815. this.isCatmullRomCurve3 = true;
  10816. this.type = 'CatmullRomCurve3';
  10817. this.points = points;
  10818. this.closed = closed;
  10819. this.curveType = curveType;
  10820. this.tension = tension;
  10821. }
  10822. getPoint( t, optionalTarget = new Vector3() ) {
  10823. const point = optionalTarget;
  10824. const points = this.points;
  10825. const l = points.length;
  10826. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  10827. let intPoint = Math.floor( p );
  10828. let weight = p - intPoint;
  10829. if ( this.closed ) {
  10830. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  10831. } else if ( weight === 0 && intPoint === l - 1 ) {
  10832. intPoint = l - 2;
  10833. weight = 1;
  10834. }
  10835. let p0, p3; // 4 points (p1 & p2 defined below)
  10836. if ( this.closed || intPoint > 0 ) {
  10837. p0 = points[ ( intPoint - 1 ) % l ];
  10838. } else {
  10839. // extrapolate first point
  10840. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  10841. p0 = tmp;
  10842. }
  10843. const p1 = points[ intPoint % l ];
  10844. const p2 = points[ ( intPoint + 1 ) % l ];
  10845. if ( this.closed || intPoint + 2 < l ) {
  10846. p3 = points[ ( intPoint + 2 ) % l ];
  10847. } else {
  10848. // extrapolate last point
  10849. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  10850. p3 = tmp;
  10851. }
  10852. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  10853. // init Centripetal / Chordal Catmull-Rom
  10854. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  10855. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  10856. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  10857. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  10858. // safety check for repeated points
  10859. if ( dt1 < 1e-4 ) dt1 = 1.0;
  10860. if ( dt0 < 1e-4 ) dt0 = dt1;
  10861. if ( dt2 < 1e-4 ) dt2 = dt1;
  10862. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  10863. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  10864. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  10865. } else if ( this.curveType === 'catmullrom' ) {
  10866. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  10867. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  10868. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  10869. }
  10870. point.set(
  10871. px.calc( weight ),
  10872. py.calc( weight ),
  10873. pz.calc( weight )
  10874. );
  10875. return point;
  10876. }
  10877. copy( source ) {
  10878. super.copy( source );
  10879. this.points = [];
  10880. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  10881. const point = source.points[ i ];
  10882. this.points.push( point.clone() );
  10883. }
  10884. this.closed = source.closed;
  10885. this.curveType = source.curveType;
  10886. this.tension = source.tension;
  10887. return this;
  10888. }
  10889. toJSON() {
  10890. const data = super.toJSON();
  10891. data.points = [];
  10892. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  10893. const point = this.points[ i ];
  10894. data.points.push( point.toArray() );
  10895. }
  10896. data.closed = this.closed;
  10897. data.curveType = this.curveType;
  10898. data.tension = this.tension;
  10899. return data;
  10900. }
  10901. fromJSON( json ) {
  10902. super.fromJSON( json );
  10903. this.points = [];
  10904. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  10905. const point = json.points[ i ];
  10906. this.points.push( new Vector3().fromArray( point ) );
  10907. }
  10908. this.closed = json.closed;
  10909. this.curveType = json.curveType;
  10910. this.tension = json.tension;
  10911. return this;
  10912. }
  10913. }
  10914. /**
  10915. * Bezier Curves formulas obtained from
  10916. * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
  10917. */
  10918. function CatmullRom( t, p0, p1, p2, p3 ) {
  10919. const v0 = ( p2 - p0 ) * 0.5;
  10920. const v1 = ( p3 - p1 ) * 0.5;
  10921. const t2 = t * t;
  10922. const t3 = t * t2;
  10923. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  10924. }
  10925. //
  10926. function QuadraticBezierP0( t, p ) {
  10927. const k = 1 - t;
  10928. return k * k * p;
  10929. }
  10930. function QuadraticBezierP1( t, p ) {
  10931. return 2 * ( 1 - t ) * t * p;
  10932. }
  10933. function QuadraticBezierP2( t, p ) {
  10934. return t * t * p;
  10935. }
  10936. function QuadraticBezier( t, p0, p1, p2 ) {
  10937. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  10938. QuadraticBezierP2( t, p2 );
  10939. }
  10940. //
  10941. function CubicBezierP0( t, p ) {
  10942. const k = 1 - t;
  10943. return k * k * k * p;
  10944. }
  10945. function CubicBezierP1( t, p ) {
  10946. const k = 1 - t;
  10947. return 3 * k * k * t * p;
  10948. }
  10949. function CubicBezierP2( t, p ) {
  10950. return 3 * ( 1 - t ) * t * t * p;
  10951. }
  10952. function CubicBezierP3( t, p ) {
  10953. return t * t * t * p;
  10954. }
  10955. function CubicBezier( t, p0, p1, p2, p3 ) {
  10956. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  10957. CubicBezierP3( t, p3 );
  10958. }
  10959. class CubicBezierCurve extends Curve {
  10960. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  10961. super();
  10962. this.isCubicBezierCurve = true;
  10963. this.type = 'CubicBezierCurve';
  10964. this.v0 = v0;
  10965. this.v1 = v1;
  10966. this.v2 = v2;
  10967. this.v3 = v3;
  10968. }
  10969. getPoint( t, optionalTarget = new Vector2() ) {
  10970. const point = optionalTarget;
  10971. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  10972. point.set(
  10973. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  10974. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  10975. );
  10976. return point;
  10977. }
  10978. copy( source ) {
  10979. super.copy( source );
  10980. this.v0.copy( source.v0 );
  10981. this.v1.copy( source.v1 );
  10982. this.v2.copy( source.v2 );
  10983. this.v3.copy( source.v3 );
  10984. return this;
  10985. }
  10986. toJSON() {
  10987. const data = super.toJSON();
  10988. data.v0 = this.v0.toArray();
  10989. data.v1 = this.v1.toArray();
  10990. data.v2 = this.v2.toArray();
  10991. data.v3 = this.v3.toArray();
  10992. return data;
  10993. }
  10994. fromJSON( json ) {
  10995. super.fromJSON( json );
  10996. this.v0.fromArray( json.v0 );
  10997. this.v1.fromArray( json.v1 );
  10998. this.v2.fromArray( json.v2 );
  10999. this.v3.fromArray( json.v3 );
  11000. return this;
  11001. }
  11002. }
  11003. class CubicBezierCurve3 extends Curve {
  11004. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  11005. super();
  11006. this.isCubicBezierCurve3 = true;
  11007. this.type = 'CubicBezierCurve3';
  11008. this.v0 = v0;
  11009. this.v1 = v1;
  11010. this.v2 = v2;
  11011. this.v3 = v3;
  11012. }
  11013. getPoint( t, optionalTarget = new Vector3() ) {
  11014. const point = optionalTarget;
  11015. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11016. point.set(
  11017. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11018. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  11019. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  11020. );
  11021. return point;
  11022. }
  11023. copy( source ) {
  11024. super.copy( source );
  11025. this.v0.copy( source.v0 );
  11026. this.v1.copy( source.v1 );
  11027. this.v2.copy( source.v2 );
  11028. this.v3.copy( source.v3 );
  11029. return this;
  11030. }
  11031. toJSON() {
  11032. const data = super.toJSON();
  11033. data.v0 = this.v0.toArray();
  11034. data.v1 = this.v1.toArray();
  11035. data.v2 = this.v2.toArray();
  11036. data.v3 = this.v3.toArray();
  11037. return data;
  11038. }
  11039. fromJSON( json ) {
  11040. super.fromJSON( json );
  11041. this.v0.fromArray( json.v0 );
  11042. this.v1.fromArray( json.v1 );
  11043. this.v2.fromArray( json.v2 );
  11044. this.v3.fromArray( json.v3 );
  11045. return this;
  11046. }
  11047. }
  11048. class LineCurve extends Curve {
  11049. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  11050. super();
  11051. this.isLineCurve = true;
  11052. this.type = 'LineCurve';
  11053. this.v1 = v1;
  11054. this.v2 = v2;
  11055. }
  11056. getPoint( t, optionalTarget = new Vector2() ) {
  11057. const point = optionalTarget;
  11058. if ( t === 1 ) {
  11059. point.copy( this.v2 );
  11060. } else {
  11061. point.copy( this.v2 ).sub( this.v1 );
  11062. point.multiplyScalar( t ).add( this.v1 );
  11063. }
  11064. return point;
  11065. }
  11066. // Line curve is linear, so we can overwrite default getPointAt
  11067. getPointAt( u, optionalTarget ) {
  11068. return this.getPoint( u, optionalTarget );
  11069. }
  11070. getTangent( t, optionalTarget = new Vector2() ) {
  11071. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11072. }
  11073. getTangentAt( u, optionalTarget ) {
  11074. return this.getTangent( u, optionalTarget );
  11075. }
  11076. copy( source ) {
  11077. super.copy( source );
  11078. this.v1.copy( source.v1 );
  11079. this.v2.copy( source.v2 );
  11080. return this;
  11081. }
  11082. toJSON() {
  11083. const data = super.toJSON();
  11084. data.v1 = this.v1.toArray();
  11085. data.v2 = this.v2.toArray();
  11086. return data;
  11087. }
  11088. fromJSON( json ) {
  11089. super.fromJSON( json );
  11090. this.v1.fromArray( json.v1 );
  11091. this.v2.fromArray( json.v2 );
  11092. return this;
  11093. }
  11094. }
  11095. class LineCurve3 extends Curve {
  11096. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  11097. super();
  11098. this.isLineCurve3 = true;
  11099. this.type = 'LineCurve3';
  11100. this.v1 = v1;
  11101. this.v2 = v2;
  11102. }
  11103. getPoint( t, optionalTarget = new Vector3() ) {
  11104. const point = optionalTarget;
  11105. if ( t === 1 ) {
  11106. point.copy( this.v2 );
  11107. } else {
  11108. point.copy( this.v2 ).sub( this.v1 );
  11109. point.multiplyScalar( t ).add( this.v1 );
  11110. }
  11111. return point;
  11112. }
  11113. // Line curve is linear, so we can overwrite default getPointAt
  11114. getPointAt( u, optionalTarget ) {
  11115. return this.getPoint( u, optionalTarget );
  11116. }
  11117. getTangent( t, optionalTarget = new Vector3() ) {
  11118. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11119. }
  11120. getTangentAt( u, optionalTarget ) {
  11121. return this.getTangent( u, optionalTarget );
  11122. }
  11123. copy( source ) {
  11124. super.copy( source );
  11125. this.v1.copy( source.v1 );
  11126. this.v2.copy( source.v2 );
  11127. return this;
  11128. }
  11129. toJSON() {
  11130. const data = super.toJSON();
  11131. data.v1 = this.v1.toArray();
  11132. data.v2 = this.v2.toArray();
  11133. return data;
  11134. }
  11135. fromJSON( json ) {
  11136. super.fromJSON( json );
  11137. this.v1.fromArray( json.v1 );
  11138. this.v2.fromArray( json.v2 );
  11139. return this;
  11140. }
  11141. }
  11142. class QuadraticBezierCurve extends Curve {
  11143. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  11144. super();
  11145. this.isQuadraticBezierCurve = true;
  11146. this.type = 'QuadraticBezierCurve';
  11147. this.v0 = v0;
  11148. this.v1 = v1;
  11149. this.v2 = v2;
  11150. }
  11151. getPoint( t, optionalTarget = new Vector2() ) {
  11152. const point = optionalTarget;
  11153. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11154. point.set(
  11155. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11156. QuadraticBezier( t, v0.y, v1.y, v2.y )
  11157. );
  11158. return point;
  11159. }
  11160. copy( source ) {
  11161. super.copy( source );
  11162. this.v0.copy( source.v0 );
  11163. this.v1.copy( source.v1 );
  11164. this.v2.copy( source.v2 );
  11165. return this;
  11166. }
  11167. toJSON() {
  11168. const data = super.toJSON();
  11169. data.v0 = this.v0.toArray();
  11170. data.v1 = this.v1.toArray();
  11171. data.v2 = this.v2.toArray();
  11172. return data;
  11173. }
  11174. fromJSON( json ) {
  11175. super.fromJSON( json );
  11176. this.v0.fromArray( json.v0 );
  11177. this.v1.fromArray( json.v1 );
  11178. this.v2.fromArray( json.v2 );
  11179. return this;
  11180. }
  11181. }
  11182. class QuadraticBezierCurve3 extends Curve {
  11183. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  11184. super();
  11185. this.isQuadraticBezierCurve3 = true;
  11186. this.type = 'QuadraticBezierCurve3';
  11187. this.v0 = v0;
  11188. this.v1 = v1;
  11189. this.v2 = v2;
  11190. }
  11191. getPoint( t, optionalTarget = new Vector3() ) {
  11192. const point = optionalTarget;
  11193. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11194. point.set(
  11195. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11196. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  11197. QuadraticBezier( t, v0.z, v1.z, v2.z )
  11198. );
  11199. return point;
  11200. }
  11201. copy( source ) {
  11202. super.copy( source );
  11203. this.v0.copy( source.v0 );
  11204. this.v1.copy( source.v1 );
  11205. this.v2.copy( source.v2 );
  11206. return this;
  11207. }
  11208. toJSON() {
  11209. const data = super.toJSON();
  11210. data.v0 = this.v0.toArray();
  11211. data.v1 = this.v1.toArray();
  11212. data.v2 = this.v2.toArray();
  11213. return data;
  11214. }
  11215. fromJSON( json ) {
  11216. super.fromJSON( json );
  11217. this.v0.fromArray( json.v0 );
  11218. this.v1.fromArray( json.v1 );
  11219. this.v2.fromArray( json.v2 );
  11220. return this;
  11221. }
  11222. }
  11223. class SplineCurve extends Curve {
  11224. constructor( points = [] ) {
  11225. super();
  11226. this.isSplineCurve = true;
  11227. this.type = 'SplineCurve';
  11228. this.points = points;
  11229. }
  11230. getPoint( t, optionalTarget = new Vector2() ) {
  11231. const point = optionalTarget;
  11232. const points = this.points;
  11233. const p = ( points.length - 1 ) * t;
  11234. const intPoint = Math.floor( p );
  11235. const weight = p - intPoint;
  11236. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  11237. const p1 = points[ intPoint ];
  11238. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  11239. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  11240. point.set(
  11241. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  11242. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  11243. );
  11244. return point;
  11245. }
  11246. copy( source ) {
  11247. super.copy( source );
  11248. this.points = [];
  11249. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  11250. const point = source.points[ i ];
  11251. this.points.push( point.clone() );
  11252. }
  11253. return this;
  11254. }
  11255. toJSON() {
  11256. const data = super.toJSON();
  11257. data.points = [];
  11258. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  11259. const point = this.points[ i ];
  11260. data.points.push( point.toArray() );
  11261. }
  11262. return data;
  11263. }
  11264. fromJSON( json ) {
  11265. super.fromJSON( json );
  11266. this.points = [];
  11267. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  11268. const point = json.points[ i ];
  11269. this.points.push( new Vector2().fromArray( point ) );
  11270. }
  11271. return this;
  11272. }
  11273. }
  11274. var Curves = /*#__PURE__*/Object.freeze({
  11275. __proto__: null,
  11276. ArcCurve: ArcCurve,
  11277. CatmullRomCurve3: CatmullRomCurve3,
  11278. CubicBezierCurve: CubicBezierCurve,
  11279. CubicBezierCurve3: CubicBezierCurve3,
  11280. EllipseCurve: EllipseCurve,
  11281. LineCurve: LineCurve,
  11282. LineCurve3: LineCurve3,
  11283. QuadraticBezierCurve: QuadraticBezierCurve,
  11284. QuadraticBezierCurve3: QuadraticBezierCurve3,
  11285. SplineCurve: SplineCurve
  11286. });
  11287. /**************************************************************
  11288. * Curved Path - a curve path is simply a array of connected
  11289. * curves, but retains the api of a curve
  11290. **************************************************************/
  11291. class CurvePath extends Curve {
  11292. constructor() {
  11293. super();
  11294. this.type = 'CurvePath';
  11295. this.curves = [];
  11296. this.autoClose = false; // Automatically closes the path
  11297. }
  11298. add( curve ) {
  11299. this.curves.push( curve );
  11300. }
  11301. closePath() {
  11302. // Add a line curve if start and end of lines are not connected
  11303. const startPoint = this.curves[ 0 ].getPoint( 0 );
  11304. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  11305. if ( ! startPoint.equals( endPoint ) ) {
  11306. const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3';
  11307. this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) );
  11308. }
  11309. return this;
  11310. }
  11311. // To get accurate point with reference to
  11312. // entire path distance at time t,
  11313. // following has to be done:
  11314. // 1. Length of each sub path have to be known
  11315. // 2. Locate and identify type of curve
  11316. // 3. Get t for the curve
  11317. // 4. Return curve.getPointAt(t')
  11318. getPoint( t, optionalTarget ) {
  11319. const d = t * this.getLength();
  11320. const curveLengths = this.getCurveLengths();
  11321. let i = 0;
  11322. // To think about boundaries points.
  11323. while ( i < curveLengths.length ) {
  11324. if ( curveLengths[ i ] >= d ) {
  11325. const diff = curveLengths[ i ] - d;
  11326. const curve = this.curves[ i ];
  11327. const segmentLength = curve.getLength();
  11328. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  11329. return curve.getPointAt( u, optionalTarget );
  11330. }
  11331. i ++;
  11332. }
  11333. return null;
  11334. // loop where sum != 0, sum > d , sum+1 <d
  11335. }
  11336. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  11337. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  11338. // getPoint() depends on getLength
  11339. getLength() {
  11340. const lens = this.getCurveLengths();
  11341. return lens[ lens.length - 1 ];
  11342. }
  11343. // cacheLengths must be recalculated.
  11344. updateArcLengths() {
  11345. this.needsUpdate = true;
  11346. this.cacheLengths = null;
  11347. this.getCurveLengths();
  11348. }
  11349. // Compute lengths and cache them
  11350. // We cannot overwrite getLengths() because UtoT mapping uses it.
  11351. getCurveLengths() {
  11352. // We use cache values if curves and cache array are same length
  11353. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  11354. return this.cacheLengths;
  11355. }
  11356. // Get length of sub-curve
  11357. // Push sums into cached array
  11358. const lengths = [];
  11359. let sums = 0;
  11360. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11361. sums += this.curves[ i ].getLength();
  11362. lengths.push( sums );
  11363. }
  11364. this.cacheLengths = lengths;
  11365. return lengths;
  11366. }
  11367. getSpacedPoints( divisions = 40 ) {
  11368. const points = [];
  11369. for ( let i = 0; i <= divisions; i ++ ) {
  11370. points.push( this.getPoint( i / divisions ) );
  11371. }
  11372. if ( this.autoClose ) {
  11373. points.push( points[ 0 ] );
  11374. }
  11375. return points;
  11376. }
  11377. getPoints( divisions = 12 ) {
  11378. const points = [];
  11379. let last;
  11380. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  11381. const curve = curves[ i ];
  11382. const resolution = curve.isEllipseCurve ? divisions * 2
  11383. : ( curve.isLineCurve || curve.isLineCurve3 ) ? 1
  11384. : curve.isSplineCurve ? divisions * curve.points.length
  11385. : divisions;
  11386. const pts = curve.getPoints( resolution );
  11387. for ( let j = 0; j < pts.length; j ++ ) {
  11388. const point = pts[ j ];
  11389. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  11390. points.push( point );
  11391. last = point;
  11392. }
  11393. }
  11394. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  11395. points.push( points[ 0 ] );
  11396. }
  11397. return points;
  11398. }
  11399. copy( source ) {
  11400. super.copy( source );
  11401. this.curves = [];
  11402. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  11403. const curve = source.curves[ i ];
  11404. this.curves.push( curve.clone() );
  11405. }
  11406. this.autoClose = source.autoClose;
  11407. return this;
  11408. }
  11409. toJSON() {
  11410. const data = super.toJSON();
  11411. data.autoClose = this.autoClose;
  11412. data.curves = [];
  11413. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11414. const curve = this.curves[ i ];
  11415. data.curves.push( curve.toJSON() );
  11416. }
  11417. return data;
  11418. }
  11419. fromJSON( json ) {
  11420. super.fromJSON( json );
  11421. this.autoClose = json.autoClose;
  11422. this.curves = [];
  11423. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  11424. const curve = json.curves[ i ];
  11425. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  11426. }
  11427. return this;
  11428. }
  11429. }
  11430. class Path extends CurvePath {
  11431. constructor( points ) {
  11432. super();
  11433. this.type = 'Path';
  11434. this.currentPoint = new Vector2();
  11435. if ( points ) {
  11436. this.setFromPoints( points );
  11437. }
  11438. }
  11439. setFromPoints( points ) {
  11440. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  11441. for ( let i = 1, l = points.length; i < l; i ++ ) {
  11442. this.lineTo( points[ i ].x, points[ i ].y );
  11443. }
  11444. return this;
  11445. }
  11446. moveTo( x, y ) {
  11447. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  11448. return this;
  11449. }
  11450. lineTo( x, y ) {
  11451. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  11452. this.curves.push( curve );
  11453. this.currentPoint.set( x, y );
  11454. return this;
  11455. }
  11456. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  11457. const curve = new QuadraticBezierCurve(
  11458. this.currentPoint.clone(),
  11459. new Vector2( aCPx, aCPy ),
  11460. new Vector2( aX, aY )
  11461. );
  11462. this.curves.push( curve );
  11463. this.currentPoint.set( aX, aY );
  11464. return this;
  11465. }
  11466. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  11467. const curve = new CubicBezierCurve(
  11468. this.currentPoint.clone(),
  11469. new Vector2( aCP1x, aCP1y ),
  11470. new Vector2( aCP2x, aCP2y ),
  11471. new Vector2( aX, aY )
  11472. );
  11473. this.curves.push( curve );
  11474. this.currentPoint.set( aX, aY );
  11475. return this;
  11476. }
  11477. splineThru( pts /*Array of Vector*/ ) {
  11478. const npts = [ this.currentPoint.clone() ].concat( pts );
  11479. const curve = new SplineCurve( npts );
  11480. this.curves.push( curve );
  11481. this.currentPoint.copy( pts[ pts.length - 1 ] );
  11482. return this;
  11483. }
  11484. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11485. const x0 = this.currentPoint.x;
  11486. const y0 = this.currentPoint.y;
  11487. this.absarc( aX + x0, aY + y0, aRadius,
  11488. aStartAngle, aEndAngle, aClockwise );
  11489. return this;
  11490. }
  11491. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11492. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  11493. return this;
  11494. }
  11495. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11496. const x0 = this.currentPoint.x;
  11497. const y0 = this.currentPoint.y;
  11498. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11499. return this;
  11500. }
  11501. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11502. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11503. if ( this.curves.length > 0 ) {
  11504. // if a previous curve is present, attempt to join
  11505. const firstPoint = curve.getPoint( 0 );
  11506. if ( ! firstPoint.equals( this.currentPoint ) ) {
  11507. this.lineTo( firstPoint.x, firstPoint.y );
  11508. }
  11509. }
  11510. this.curves.push( curve );
  11511. const lastPoint = curve.getPoint( 1 );
  11512. this.currentPoint.copy( lastPoint );
  11513. return this;
  11514. }
  11515. copy( source ) {
  11516. super.copy( source );
  11517. this.currentPoint.copy( source.currentPoint );
  11518. return this;
  11519. }
  11520. toJSON() {
  11521. const data = super.toJSON();
  11522. data.currentPoint = this.currentPoint.toArray();
  11523. return data;
  11524. }
  11525. fromJSON( json ) {
  11526. super.fromJSON( json );
  11527. this.currentPoint.fromArray( json.currentPoint );
  11528. return this;
  11529. }
  11530. }
  11531. class LatheGeometry extends BufferGeometry {
  11532. 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 ) {
  11533. super();
  11534. this.type = 'LatheGeometry';
  11535. this.parameters = {
  11536. points: points,
  11537. segments: segments,
  11538. phiStart: phiStart,
  11539. phiLength: phiLength
  11540. };
  11541. segments = Math.floor( segments );
  11542. // clamp phiLength so it's in range of [ 0, 2PI ]
  11543. phiLength = clamp( phiLength, 0, Math.PI * 2 );
  11544. // buffers
  11545. const indices = [];
  11546. const vertices = [];
  11547. const uvs = [];
  11548. const initNormals = [];
  11549. const normals = [];
  11550. // helper variables
  11551. const inverseSegments = 1.0 / segments;
  11552. const vertex = new Vector3();
  11553. const uv = new Vector2();
  11554. const normal = new Vector3();
  11555. const curNormal = new Vector3();
  11556. const prevNormal = new Vector3();
  11557. let dx = 0;
  11558. let dy = 0;
  11559. // pre-compute normals for initial "meridian"
  11560. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11561. switch ( j ) {
  11562. case 0: // special handling for 1st vertex on path
  11563. dx = points[ j + 1 ].x - points[ j ].x;
  11564. dy = points[ j + 1 ].y - points[ j ].y;
  11565. normal.x = dy * 1.0;
  11566. normal.y = - dx;
  11567. normal.z = dy * 0.0;
  11568. prevNormal.copy( normal );
  11569. normal.normalize();
  11570. initNormals.push( normal.x, normal.y, normal.z );
  11571. break;
  11572. case ( points.length - 1 ): // special handling for last Vertex on path
  11573. initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z );
  11574. break;
  11575. default: // default handling for all vertices in between
  11576. dx = points[ j + 1 ].x - points[ j ].x;
  11577. dy = points[ j + 1 ].y - points[ j ].y;
  11578. normal.x = dy * 1.0;
  11579. normal.y = - dx;
  11580. normal.z = dy * 0.0;
  11581. curNormal.copy( normal );
  11582. normal.x += prevNormal.x;
  11583. normal.y += prevNormal.y;
  11584. normal.z += prevNormal.z;
  11585. normal.normalize();
  11586. initNormals.push( normal.x, normal.y, normal.z );
  11587. prevNormal.copy( curNormal );
  11588. }
  11589. }
  11590. // generate vertices, uvs and normals
  11591. for ( let i = 0; i <= segments; i ++ ) {
  11592. const phi = phiStart + i * inverseSegments * phiLength;
  11593. const sin = Math.sin( phi );
  11594. const cos = Math.cos( phi );
  11595. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11596. // vertex
  11597. vertex.x = points[ j ].x * sin;
  11598. vertex.y = points[ j ].y;
  11599. vertex.z = points[ j ].x * cos;
  11600. vertices.push( vertex.x, vertex.y, vertex.z );
  11601. // uv
  11602. uv.x = i / segments;
  11603. uv.y = j / ( points.length - 1 );
  11604. uvs.push( uv.x, uv.y );
  11605. // normal
  11606. const x = initNormals[ 3 * j + 0 ] * sin;
  11607. const y = initNormals[ 3 * j + 1 ];
  11608. const z = initNormals[ 3 * j + 0 ] * cos;
  11609. normals.push( x, y, z );
  11610. }
  11611. }
  11612. // indices
  11613. for ( let i = 0; i < segments; i ++ ) {
  11614. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  11615. const base = j + i * points.length;
  11616. const a = base;
  11617. const b = base + points.length;
  11618. const c = base + points.length + 1;
  11619. const d = base + 1;
  11620. // faces
  11621. indices.push( a, b, d );
  11622. indices.push( c, d, b );
  11623. }
  11624. }
  11625. // build geometry
  11626. this.setIndex( indices );
  11627. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11628. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11629. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11630. }
  11631. copy( source ) {
  11632. super.copy( source );
  11633. this.parameters = Object.assign( {}, source.parameters );
  11634. return this;
  11635. }
  11636. static fromJSON( data ) {
  11637. return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
  11638. }
  11639. }
  11640. class CapsuleGeometry extends LatheGeometry {
  11641. constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
  11642. const path = new Path();
  11643. path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 );
  11644. path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 );
  11645. super( path.getPoints( capSegments ), radialSegments );
  11646. this.type = 'CapsuleGeometry';
  11647. this.parameters = {
  11648. radius: radius,
  11649. length: length,
  11650. capSegments: capSegments,
  11651. radialSegments: radialSegments,
  11652. };
  11653. }
  11654. static fromJSON( data ) {
  11655. return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
  11656. }
  11657. }
  11658. class CircleGeometry extends BufferGeometry {
  11659. constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11660. super();
  11661. this.type = 'CircleGeometry';
  11662. this.parameters = {
  11663. radius: radius,
  11664. segments: segments,
  11665. thetaStart: thetaStart,
  11666. thetaLength: thetaLength
  11667. };
  11668. segments = Math.max( 3, segments );
  11669. // buffers
  11670. const indices = [];
  11671. const vertices = [];
  11672. const normals = [];
  11673. const uvs = [];
  11674. // helper variables
  11675. const vertex = new Vector3();
  11676. const uv = new Vector2();
  11677. // center point
  11678. vertices.push( 0, 0, 0 );
  11679. normals.push( 0, 0, 1 );
  11680. uvs.push( 0.5, 0.5 );
  11681. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  11682. const segment = thetaStart + s / segments * thetaLength;
  11683. // vertex
  11684. vertex.x = radius * Math.cos( segment );
  11685. vertex.y = radius * Math.sin( segment );
  11686. vertices.push( vertex.x, vertex.y, vertex.z );
  11687. // normal
  11688. normals.push( 0, 0, 1 );
  11689. // uvs
  11690. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  11691. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  11692. uvs.push( uv.x, uv.y );
  11693. }
  11694. // indices
  11695. for ( let i = 1; i <= segments; i ++ ) {
  11696. indices.push( i, i + 1, 0 );
  11697. }
  11698. // build geometry
  11699. this.setIndex( indices );
  11700. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11701. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11702. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11703. }
  11704. copy( source ) {
  11705. super.copy( source );
  11706. this.parameters = Object.assign( {}, source.parameters );
  11707. return this;
  11708. }
  11709. static fromJSON( data ) {
  11710. return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
  11711. }
  11712. }
  11713. class CylinderGeometry extends BufferGeometry {
  11714. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11715. super();
  11716. this.type = 'CylinderGeometry';
  11717. this.parameters = {
  11718. radiusTop: radiusTop,
  11719. radiusBottom: radiusBottom,
  11720. height: height,
  11721. radialSegments: radialSegments,
  11722. heightSegments: heightSegments,
  11723. openEnded: openEnded,
  11724. thetaStart: thetaStart,
  11725. thetaLength: thetaLength
  11726. };
  11727. const scope = this;
  11728. radialSegments = Math.floor( radialSegments );
  11729. heightSegments = Math.floor( heightSegments );
  11730. // buffers
  11731. const indices = [];
  11732. const vertices = [];
  11733. const normals = [];
  11734. const uvs = [];
  11735. // helper variables
  11736. let index = 0;
  11737. const indexArray = [];
  11738. const halfHeight = height / 2;
  11739. let groupStart = 0;
  11740. // generate geometry
  11741. generateTorso();
  11742. if ( openEnded === false ) {
  11743. if ( radiusTop > 0 ) generateCap( true );
  11744. if ( radiusBottom > 0 ) generateCap( false );
  11745. }
  11746. // build geometry
  11747. this.setIndex( indices );
  11748. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11749. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11750. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11751. function generateTorso() {
  11752. const normal = new Vector3();
  11753. const vertex = new Vector3();
  11754. let groupCount = 0;
  11755. // this will be used to calculate the normal
  11756. const slope = ( radiusBottom - radiusTop ) / height;
  11757. // generate vertices, normals and uvs
  11758. for ( let y = 0; y <= heightSegments; y ++ ) {
  11759. const indexRow = [];
  11760. const v = y / heightSegments;
  11761. // calculate the radius of the current row
  11762. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  11763. for ( let x = 0; x <= radialSegments; x ++ ) {
  11764. const u = x / radialSegments;
  11765. const theta = u * thetaLength + thetaStart;
  11766. const sinTheta = Math.sin( theta );
  11767. const cosTheta = Math.cos( theta );
  11768. // vertex
  11769. vertex.x = radius * sinTheta;
  11770. vertex.y = - v * height + halfHeight;
  11771. vertex.z = radius * cosTheta;
  11772. vertices.push( vertex.x, vertex.y, vertex.z );
  11773. // normal
  11774. normal.set( sinTheta, slope, cosTheta ).normalize();
  11775. normals.push( normal.x, normal.y, normal.z );
  11776. // uv
  11777. uvs.push( u, 1 - v );
  11778. // save index of vertex in respective row
  11779. indexRow.push( index ++ );
  11780. }
  11781. // now save vertices of the row in our index array
  11782. indexArray.push( indexRow );
  11783. }
  11784. // generate indices
  11785. for ( let x = 0; x < radialSegments; x ++ ) {
  11786. for ( let y = 0; y < heightSegments; y ++ ) {
  11787. // we use the index array to access the correct indices
  11788. const a = indexArray[ y ][ x ];
  11789. const b = indexArray[ y + 1 ][ x ];
  11790. const c = indexArray[ y + 1 ][ x + 1 ];
  11791. const d = indexArray[ y ][ x + 1 ];
  11792. // faces
  11793. if ( radiusTop > 0 || y !== 0 ) {
  11794. indices.push( a, b, d );
  11795. groupCount += 3;
  11796. }
  11797. if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
  11798. indices.push( b, c, d );
  11799. groupCount += 3;
  11800. }
  11801. }
  11802. }
  11803. // add a group to the geometry. this will ensure multi material support
  11804. scope.addGroup( groupStart, groupCount, 0 );
  11805. // calculate new start value for groups
  11806. groupStart += groupCount;
  11807. }
  11808. function generateCap( top ) {
  11809. // save the index of the first center vertex
  11810. const centerIndexStart = index;
  11811. const uv = new Vector2();
  11812. const vertex = new Vector3();
  11813. let groupCount = 0;
  11814. const radius = ( top === true ) ? radiusTop : radiusBottom;
  11815. const sign = ( top === true ) ? 1 : - 1;
  11816. // first we generate the center vertex data of the cap.
  11817. // because the geometry needs one set of uvs per face,
  11818. // we must generate a center vertex per face/segment
  11819. for ( let x = 1; x <= radialSegments; x ++ ) {
  11820. // vertex
  11821. vertices.push( 0, halfHeight * sign, 0 );
  11822. // normal
  11823. normals.push( 0, sign, 0 );
  11824. // uv
  11825. uvs.push( 0.5, 0.5 );
  11826. // increase index
  11827. index ++;
  11828. }
  11829. // save the index of the last center vertex
  11830. const centerIndexEnd = index;
  11831. // now we generate the surrounding vertices, normals and uvs
  11832. for ( let x = 0; x <= radialSegments; x ++ ) {
  11833. const u = x / radialSegments;
  11834. const theta = u * thetaLength + thetaStart;
  11835. const cosTheta = Math.cos( theta );
  11836. const sinTheta = Math.sin( theta );
  11837. // vertex
  11838. vertex.x = radius * sinTheta;
  11839. vertex.y = halfHeight * sign;
  11840. vertex.z = radius * cosTheta;
  11841. vertices.push( vertex.x, vertex.y, vertex.z );
  11842. // normal
  11843. normals.push( 0, sign, 0 );
  11844. // uv
  11845. uv.x = ( cosTheta * 0.5 ) + 0.5;
  11846. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  11847. uvs.push( uv.x, uv.y );
  11848. // increase index
  11849. index ++;
  11850. }
  11851. // generate indices
  11852. for ( let x = 0; x < radialSegments; x ++ ) {
  11853. const c = centerIndexStart + x;
  11854. const i = centerIndexEnd + x;
  11855. if ( top === true ) {
  11856. // face top
  11857. indices.push( i, i + 1, c );
  11858. } else {
  11859. // face bottom
  11860. indices.push( i + 1, i, c );
  11861. }
  11862. groupCount += 3;
  11863. }
  11864. // add a group to the geometry. this will ensure multi material support
  11865. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  11866. // calculate new start value for groups
  11867. groupStart += groupCount;
  11868. }
  11869. }
  11870. copy( source ) {
  11871. super.copy( source );
  11872. this.parameters = Object.assign( {}, source.parameters );
  11873. return this;
  11874. }
  11875. static fromJSON( data ) {
  11876. return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11877. }
  11878. }
  11879. class ConeGeometry extends CylinderGeometry {
  11880. constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11881. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  11882. this.type = 'ConeGeometry';
  11883. this.parameters = {
  11884. radius: radius,
  11885. height: height,
  11886. radialSegments: radialSegments,
  11887. heightSegments: heightSegments,
  11888. openEnded: openEnded,
  11889. thetaStart: thetaStart,
  11890. thetaLength: thetaLength
  11891. };
  11892. }
  11893. static fromJSON( data ) {
  11894. return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11895. }
  11896. }
  11897. class PolyhedronGeometry extends BufferGeometry {
  11898. constructor( vertices = [], indices = [], radius = 1, detail = 0 ) {
  11899. super();
  11900. this.type = 'PolyhedronGeometry';
  11901. this.parameters = {
  11902. vertices: vertices,
  11903. indices: indices,
  11904. radius: radius,
  11905. detail: detail
  11906. };
  11907. // default buffer data
  11908. const vertexBuffer = [];
  11909. const uvBuffer = [];
  11910. // the subdivision creates the vertex buffer data
  11911. subdivide( detail );
  11912. // all vertices should lie on a conceptual sphere with a given radius
  11913. applyRadius( radius );
  11914. // finally, create the uv data
  11915. generateUVs();
  11916. // build non-indexed geometry
  11917. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  11918. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  11919. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  11920. if ( detail === 0 ) {
  11921. this.computeVertexNormals(); // flat normals
  11922. } else {
  11923. this.normalizeNormals(); // smooth normals
  11924. }
  11925. // helper functions
  11926. function subdivide( detail ) {
  11927. const a = new Vector3();
  11928. const b = new Vector3();
  11929. const c = new Vector3();
  11930. // iterate over all faces and apply a subdivision with the given detail value
  11931. for ( let i = 0; i < indices.length; i += 3 ) {
  11932. // get the vertices of the face
  11933. getVertexByIndex( indices[ i + 0 ], a );
  11934. getVertexByIndex( indices[ i + 1 ], b );
  11935. getVertexByIndex( indices[ i + 2 ], c );
  11936. // perform subdivision
  11937. subdivideFace( a, b, c, detail );
  11938. }
  11939. }
  11940. function subdivideFace( a, b, c, detail ) {
  11941. const cols = detail + 1;
  11942. // we use this multidimensional array as a data structure for creating the subdivision
  11943. const v = [];
  11944. // construct all of the vertices for this subdivision
  11945. for ( let i = 0; i <= cols; i ++ ) {
  11946. v[ i ] = [];
  11947. const aj = a.clone().lerp( c, i / cols );
  11948. const bj = b.clone().lerp( c, i / cols );
  11949. const rows = cols - i;
  11950. for ( let j = 0; j <= rows; j ++ ) {
  11951. if ( j === 0 && i === cols ) {
  11952. v[ i ][ j ] = aj;
  11953. } else {
  11954. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  11955. }
  11956. }
  11957. }
  11958. // construct all of the faces
  11959. for ( let i = 0; i < cols; i ++ ) {
  11960. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  11961. const k = Math.floor( j / 2 );
  11962. if ( j % 2 === 0 ) {
  11963. pushVertex( v[ i ][ k + 1 ] );
  11964. pushVertex( v[ i + 1 ][ k ] );
  11965. pushVertex( v[ i ][ k ] );
  11966. } else {
  11967. pushVertex( v[ i ][ k + 1 ] );
  11968. pushVertex( v[ i + 1 ][ k + 1 ] );
  11969. pushVertex( v[ i + 1 ][ k ] );
  11970. }
  11971. }
  11972. }
  11973. }
  11974. function applyRadius( radius ) {
  11975. const vertex = new Vector3();
  11976. // iterate over the entire buffer and apply the radius to each vertex
  11977. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  11978. vertex.x = vertexBuffer[ i + 0 ];
  11979. vertex.y = vertexBuffer[ i + 1 ];
  11980. vertex.z = vertexBuffer[ i + 2 ];
  11981. vertex.normalize().multiplyScalar( radius );
  11982. vertexBuffer[ i + 0 ] = vertex.x;
  11983. vertexBuffer[ i + 1 ] = vertex.y;
  11984. vertexBuffer[ i + 2 ] = vertex.z;
  11985. }
  11986. }
  11987. function generateUVs() {
  11988. const vertex = new Vector3();
  11989. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  11990. vertex.x = vertexBuffer[ i + 0 ];
  11991. vertex.y = vertexBuffer[ i + 1 ];
  11992. vertex.z = vertexBuffer[ i + 2 ];
  11993. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  11994. const v = inclination( vertex ) / Math.PI + 0.5;
  11995. uvBuffer.push( u, 1 - v );
  11996. }
  11997. correctUVs();
  11998. correctSeam();
  11999. }
  12000. function correctSeam() {
  12001. // handle case when face straddles the seam, see #3269
  12002. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  12003. // uv data of a single face
  12004. const x0 = uvBuffer[ i + 0 ];
  12005. const x1 = uvBuffer[ i + 2 ];
  12006. const x2 = uvBuffer[ i + 4 ];
  12007. const max = Math.max( x0, x1, x2 );
  12008. const min = Math.min( x0, x1, x2 );
  12009. // 0.9 is somewhat arbitrary
  12010. if ( max > 0.9 && min < 0.1 ) {
  12011. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  12012. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  12013. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  12014. }
  12015. }
  12016. }
  12017. function pushVertex( vertex ) {
  12018. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  12019. }
  12020. function getVertexByIndex( index, vertex ) {
  12021. const stride = index * 3;
  12022. vertex.x = vertices[ stride + 0 ];
  12023. vertex.y = vertices[ stride + 1 ];
  12024. vertex.z = vertices[ stride + 2 ];
  12025. }
  12026. function correctUVs() {
  12027. const a = new Vector3();
  12028. const b = new Vector3();
  12029. const c = new Vector3();
  12030. const centroid = new Vector3();
  12031. const uvA = new Vector2();
  12032. const uvB = new Vector2();
  12033. const uvC = new Vector2();
  12034. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  12035. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  12036. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  12037. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  12038. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  12039. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  12040. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  12041. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  12042. const azi = azimuth( centroid );
  12043. correctUV( uvA, j + 0, a, azi );
  12044. correctUV( uvB, j + 2, b, azi );
  12045. correctUV( uvC, j + 4, c, azi );
  12046. }
  12047. }
  12048. function correctUV( uv, stride, vector, azimuth ) {
  12049. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  12050. uvBuffer[ stride ] = uv.x - 1;
  12051. }
  12052. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  12053. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  12054. }
  12055. }
  12056. // Angle around the Y axis, counter-clockwise when looking from above.
  12057. function azimuth( vector ) {
  12058. return Math.atan2( vector.z, - vector.x );
  12059. }
  12060. // Angle above the XZ plane.
  12061. function inclination( vector ) {
  12062. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  12063. }
  12064. }
  12065. copy( source ) {
  12066. super.copy( source );
  12067. this.parameters = Object.assign( {}, source.parameters );
  12068. return this;
  12069. }
  12070. static fromJSON( data ) {
  12071. return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
  12072. }
  12073. }
  12074. class DodecahedronGeometry extends PolyhedronGeometry {
  12075. constructor( radius = 1, detail = 0 ) {
  12076. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  12077. const r = 1 / t;
  12078. const vertices = [
  12079. // (±1, ±1, ±1)
  12080. - 1, - 1, - 1, - 1, - 1, 1,
  12081. - 1, 1, - 1, - 1, 1, 1,
  12082. 1, - 1, - 1, 1, - 1, 1,
  12083. 1, 1, - 1, 1, 1, 1,
  12084. // (0, ±1/φ, ±φ)
  12085. 0, - r, - t, 0, - r, t,
  12086. 0, r, - t, 0, r, t,
  12087. // (±1/φ, ±φ, 0)
  12088. - r, - t, 0, - r, t, 0,
  12089. r, - t, 0, r, t, 0,
  12090. // (±φ, 0, ±1/φ)
  12091. - t, 0, - r, t, 0, - r,
  12092. - t, 0, r, t, 0, r
  12093. ];
  12094. const indices = [
  12095. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  12096. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  12097. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  12098. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  12099. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  12100. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  12101. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  12102. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  12103. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  12104. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  12105. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  12106. 1, 12, 14, 1, 14, 5, 1, 5, 9
  12107. ];
  12108. super( vertices, indices, radius, detail );
  12109. this.type = 'DodecahedronGeometry';
  12110. this.parameters = {
  12111. radius: radius,
  12112. detail: detail
  12113. };
  12114. }
  12115. static fromJSON( data ) {
  12116. return new DodecahedronGeometry( data.radius, data.detail );
  12117. }
  12118. }
  12119. const _v0 = /*@__PURE__*/ new Vector3();
  12120. const _v1$1 = /*@__PURE__*/ new Vector3();
  12121. const _normal = /*@__PURE__*/ new Vector3();
  12122. const _triangle = /*@__PURE__*/ new Triangle();
  12123. class EdgesGeometry extends BufferGeometry {
  12124. constructor( geometry = null, thresholdAngle = 1 ) {
  12125. super();
  12126. this.type = 'EdgesGeometry';
  12127. this.parameters = {
  12128. geometry: geometry,
  12129. thresholdAngle: thresholdAngle
  12130. };
  12131. if ( geometry !== null ) {
  12132. const precisionPoints = 4;
  12133. const precision = Math.pow( 10, precisionPoints );
  12134. const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
  12135. const indexAttr = geometry.getIndex();
  12136. const positionAttr = geometry.getAttribute( 'position' );
  12137. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  12138. const indexArr = [ 0, 0, 0 ];
  12139. const vertKeys = [ 'a', 'b', 'c' ];
  12140. const hashes = new Array( 3 );
  12141. const edgeData = {};
  12142. const vertices = [];
  12143. for ( let i = 0; i < indexCount; i += 3 ) {
  12144. if ( indexAttr ) {
  12145. indexArr[ 0 ] = indexAttr.getX( i );
  12146. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  12147. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  12148. } else {
  12149. indexArr[ 0 ] = i;
  12150. indexArr[ 1 ] = i + 1;
  12151. indexArr[ 2 ] = i + 2;
  12152. }
  12153. const { a, b, c } = _triangle;
  12154. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  12155. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  12156. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  12157. _triangle.getNormal( _normal );
  12158. // create hashes for the edge from the vertices
  12159. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  12160. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  12161. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  12162. // skip degenerate triangles
  12163. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  12164. continue;
  12165. }
  12166. // iterate over every edge
  12167. for ( let j = 0; j < 3; j ++ ) {
  12168. // get the first and next vertex making up the edge
  12169. const jNext = ( j + 1 ) % 3;
  12170. const vecHash0 = hashes[ j ];
  12171. const vecHash1 = hashes[ jNext ];
  12172. const v0 = _triangle[ vertKeys[ j ] ];
  12173. const v1 = _triangle[ vertKeys[ jNext ] ];
  12174. const hash = `${ vecHash0 }_${ vecHash1 }`;
  12175. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  12176. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  12177. // if we found a sibling edge add it into the vertex array if
  12178. // it meets the angle threshold and delete the edge from the map.
  12179. if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  12180. vertices.push( v0.x, v0.y, v0.z );
  12181. vertices.push( v1.x, v1.y, v1.z );
  12182. }
  12183. edgeData[ reverseHash ] = null;
  12184. } else if ( ! ( hash in edgeData ) ) {
  12185. // if we've already got an edge here then skip adding a new one
  12186. edgeData[ hash ] = {
  12187. index0: indexArr[ j ],
  12188. index1: indexArr[ jNext ],
  12189. normal: _normal.clone(),
  12190. };
  12191. }
  12192. }
  12193. }
  12194. // iterate over all remaining, unmatched edges and add them to the vertex array
  12195. for ( const key in edgeData ) {
  12196. if ( edgeData[ key ] ) {
  12197. const { index0, index1 } = edgeData[ key ];
  12198. _v0.fromBufferAttribute( positionAttr, index0 );
  12199. _v1$1.fromBufferAttribute( positionAttr, index1 );
  12200. vertices.push( _v0.x, _v0.y, _v0.z );
  12201. vertices.push( _v1$1.x, _v1$1.y, _v1$1.z );
  12202. }
  12203. }
  12204. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  12205. }
  12206. }
  12207. copy( source ) {
  12208. super.copy( source );
  12209. this.parameters = Object.assign( {}, source.parameters );
  12210. return this;
  12211. }
  12212. }
  12213. class Shape extends Path {
  12214. constructor( points ) {
  12215. super( points );
  12216. this.uuid = generateUUID();
  12217. this.type = 'Shape';
  12218. this.holes = [];
  12219. }
  12220. getPointsHoles( divisions ) {
  12221. const holesPts = [];
  12222. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12223. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  12224. }
  12225. return holesPts;
  12226. }
  12227. // get points of shape and holes (keypoints based on segments parameter)
  12228. extractPoints( divisions ) {
  12229. return {
  12230. shape: this.getPoints( divisions ),
  12231. holes: this.getPointsHoles( divisions )
  12232. };
  12233. }
  12234. copy( source ) {
  12235. super.copy( source );
  12236. this.holes = [];
  12237. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  12238. const hole = source.holes[ i ];
  12239. this.holes.push( hole.clone() );
  12240. }
  12241. return this;
  12242. }
  12243. toJSON() {
  12244. const data = super.toJSON();
  12245. data.uuid = this.uuid;
  12246. data.holes = [];
  12247. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12248. const hole = this.holes[ i ];
  12249. data.holes.push( hole.toJSON() );
  12250. }
  12251. return data;
  12252. }
  12253. fromJSON( json ) {
  12254. super.fromJSON( json );
  12255. this.uuid = json.uuid;
  12256. this.holes = [];
  12257. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  12258. const hole = json.holes[ i ];
  12259. this.holes.push( new Path().fromJSON( hole ) );
  12260. }
  12261. return this;
  12262. }
  12263. }
  12264. /**
  12265. * Port from https://github.com/mapbox/earcut (v2.2.4)
  12266. */
  12267. const Earcut = {
  12268. triangulate: function ( data, holeIndices, dim = 2 ) {
  12269. const hasHoles = holeIndices && holeIndices.length;
  12270. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  12271. let outerNode = linkedList( data, 0, outerLen, dim, true );
  12272. const triangles = [];
  12273. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  12274. let minX, minY, maxX, maxY, x, y, invSize;
  12275. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  12276. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  12277. if ( data.length > 80 * dim ) {
  12278. minX = maxX = data[ 0 ];
  12279. minY = maxY = data[ 1 ];
  12280. for ( let i = dim; i < outerLen; i += dim ) {
  12281. x = data[ i ];
  12282. y = data[ i + 1 ];
  12283. if ( x < minX ) minX = x;
  12284. if ( y < minY ) minY = y;
  12285. if ( x > maxX ) maxX = x;
  12286. if ( y > maxY ) maxY = y;
  12287. }
  12288. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  12289. invSize = Math.max( maxX - minX, maxY - minY );
  12290. invSize = invSize !== 0 ? 32767 / invSize : 0;
  12291. }
  12292. earcutLinked( outerNode, triangles, dim, minX, minY, invSize, 0 );
  12293. return triangles;
  12294. }
  12295. };
  12296. // create a circular doubly linked list from polygon points in the specified winding order
  12297. function linkedList( data, start, end, dim, clockwise ) {
  12298. let i, last;
  12299. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  12300. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12301. } else {
  12302. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12303. }
  12304. if ( last && equals( last, last.next ) ) {
  12305. removeNode( last );
  12306. last = last.next;
  12307. }
  12308. return last;
  12309. }
  12310. // eliminate colinear or duplicate points
  12311. function filterPoints( start, end ) {
  12312. if ( ! start ) return start;
  12313. if ( ! end ) end = start;
  12314. let p = start,
  12315. again;
  12316. do {
  12317. again = false;
  12318. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  12319. removeNode( p );
  12320. p = end = p.prev;
  12321. if ( p === p.next ) break;
  12322. again = true;
  12323. } else {
  12324. p = p.next;
  12325. }
  12326. } while ( again || p !== end );
  12327. return end;
  12328. }
  12329. // main ear slicing loop which triangulates a polygon (given as a linked list)
  12330. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  12331. if ( ! ear ) return;
  12332. // interlink polygon nodes in z-order
  12333. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  12334. let stop = ear,
  12335. prev, next;
  12336. // iterate through ears, slicing them one by one
  12337. while ( ear.prev !== ear.next ) {
  12338. prev = ear.prev;
  12339. next = ear.next;
  12340. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  12341. // cut off the triangle
  12342. triangles.push( prev.i / dim | 0 );
  12343. triangles.push( ear.i / dim | 0 );
  12344. triangles.push( next.i / dim | 0 );
  12345. removeNode( ear );
  12346. // skipping the next vertex leads to less sliver triangles
  12347. ear = next.next;
  12348. stop = next.next;
  12349. continue;
  12350. }
  12351. ear = next;
  12352. // if we looped through the whole remaining polygon and can't find any more ears
  12353. if ( ear === stop ) {
  12354. // try filtering points and slicing again
  12355. if ( ! pass ) {
  12356. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  12357. // if this didn't work, try curing all small self-intersections locally
  12358. } else if ( pass === 1 ) {
  12359. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  12360. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  12361. // as a last resort, try splitting the remaining polygon into two
  12362. } else if ( pass === 2 ) {
  12363. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  12364. }
  12365. break;
  12366. }
  12367. }
  12368. }
  12369. // check whether a polygon node forms a valid ear with adjacent nodes
  12370. function isEar( ear ) {
  12371. const a = ear.prev,
  12372. b = ear,
  12373. c = ear.next;
  12374. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12375. // now make sure we don't have other points inside the potential ear
  12376. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12377. // triangle bbox; min & max are calculated like this for speed
  12378. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12379. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12380. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12381. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12382. let p = c.next;
  12383. while ( p !== a ) {
  12384. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
  12385. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) &&
  12386. area( p.prev, p, p.next ) >= 0 ) return false;
  12387. p = p.next;
  12388. }
  12389. return true;
  12390. }
  12391. function isEarHashed( ear, minX, minY, invSize ) {
  12392. const a = ear.prev,
  12393. b = ear,
  12394. c = ear.next;
  12395. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12396. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12397. // triangle bbox; min & max are calculated like this for speed
  12398. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12399. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12400. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12401. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12402. // z-order range for the current triangle bbox;
  12403. const minZ = zOrder( x0, y0, minX, minY, invSize ),
  12404. maxZ = zOrder( x1, y1, minX, minY, invSize );
  12405. let p = ear.prevZ,
  12406. n = ear.nextZ;
  12407. // look for points inside the triangle in both directions
  12408. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  12409. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12410. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12411. p = p.prevZ;
  12412. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12413. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12414. n = n.nextZ;
  12415. }
  12416. // look for remaining points in decreasing z-order
  12417. while ( p && p.z >= minZ ) {
  12418. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12419. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12420. p = p.prevZ;
  12421. }
  12422. // look for remaining points in increasing z-order
  12423. while ( n && n.z <= maxZ ) {
  12424. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12425. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12426. n = n.nextZ;
  12427. }
  12428. return true;
  12429. }
  12430. // go through all polygon nodes and cure small local self-intersections
  12431. function cureLocalIntersections( start, triangles, dim ) {
  12432. let p = start;
  12433. do {
  12434. const a = p.prev,
  12435. b = p.next.next;
  12436. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  12437. triangles.push( a.i / dim | 0 );
  12438. triangles.push( p.i / dim | 0 );
  12439. triangles.push( b.i / dim | 0 );
  12440. // remove two nodes involved
  12441. removeNode( p );
  12442. removeNode( p.next );
  12443. p = start = b;
  12444. }
  12445. p = p.next;
  12446. } while ( p !== start );
  12447. return filterPoints( p );
  12448. }
  12449. // try splitting polygon into two and triangulate them independently
  12450. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  12451. // look for a valid diagonal that divides the polygon into two
  12452. let a = start;
  12453. do {
  12454. let b = a.next.next;
  12455. while ( b !== a.prev ) {
  12456. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  12457. // split the polygon in two by the diagonal
  12458. let c = splitPolygon( a, b );
  12459. // filter colinear points around the cuts
  12460. a = filterPoints( a, a.next );
  12461. c = filterPoints( c, c.next );
  12462. // run earcut on each half
  12463. earcutLinked( a, triangles, dim, minX, minY, invSize, 0 );
  12464. earcutLinked( c, triangles, dim, minX, minY, invSize, 0 );
  12465. return;
  12466. }
  12467. b = b.next;
  12468. }
  12469. a = a.next;
  12470. } while ( a !== start );
  12471. }
  12472. // link every hole into the outer loop, producing a single-ring polygon without holes
  12473. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  12474. const queue = [];
  12475. let i, len, start, end, list;
  12476. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  12477. start = holeIndices[ i ] * dim;
  12478. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  12479. list = linkedList( data, start, end, dim, false );
  12480. if ( list === list.next ) list.steiner = true;
  12481. queue.push( getLeftmost( list ) );
  12482. }
  12483. queue.sort( compareX );
  12484. // process holes from left to right
  12485. for ( i = 0; i < queue.length; i ++ ) {
  12486. outerNode = eliminateHole( queue[ i ], outerNode );
  12487. }
  12488. return outerNode;
  12489. }
  12490. function compareX( a, b ) {
  12491. return a.x - b.x;
  12492. }
  12493. // find a bridge between vertices that connects hole with an outer ring and link it
  12494. function eliminateHole( hole, outerNode ) {
  12495. const bridge = findHoleBridge( hole, outerNode );
  12496. if ( ! bridge ) {
  12497. return outerNode;
  12498. }
  12499. const bridgeReverse = splitPolygon( bridge, hole );
  12500. // filter collinear points around the cuts
  12501. filterPoints( bridgeReverse, bridgeReverse.next );
  12502. return filterPoints( bridge, bridge.next );
  12503. }
  12504. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  12505. function findHoleBridge( hole, outerNode ) {
  12506. let p = outerNode,
  12507. qx = - Infinity,
  12508. m;
  12509. const hx = hole.x, hy = hole.y;
  12510. // find a segment intersected by a ray from the hole's leftmost point to the left;
  12511. // segment's endpoint with lesser x will be potential connection point
  12512. do {
  12513. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  12514. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  12515. if ( x <= hx && x > qx ) {
  12516. qx = x;
  12517. m = p.x < p.next.x ? p : p.next;
  12518. if ( x === hx ) return m; // hole touches outer segment; pick leftmost endpoint
  12519. }
  12520. }
  12521. p = p.next;
  12522. } while ( p !== outerNode );
  12523. if ( ! m ) return null;
  12524. // look for points inside the triangle of hole point, segment intersection and endpoint;
  12525. // if there are no points found, we have a valid connection;
  12526. // otherwise choose the point of the minimum angle with the ray as connection point
  12527. const stop = m,
  12528. mx = m.x,
  12529. my = m.y;
  12530. let tanMin = Infinity, tan;
  12531. p = m;
  12532. do {
  12533. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  12534. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  12535. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  12536. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  12537. m = p;
  12538. tanMin = tan;
  12539. }
  12540. }
  12541. p = p.next;
  12542. } while ( p !== stop );
  12543. return m;
  12544. }
  12545. // whether sector in vertex m contains sector in vertex p in the same coordinates
  12546. function sectorContainsSector( m, p ) {
  12547. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  12548. }
  12549. // interlink polygon nodes in z-order
  12550. function indexCurve( start, minX, minY, invSize ) {
  12551. let p = start;
  12552. do {
  12553. if ( p.z === 0 ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  12554. p.prevZ = p.prev;
  12555. p.nextZ = p.next;
  12556. p = p.next;
  12557. } while ( p !== start );
  12558. p.prevZ.nextZ = null;
  12559. p.prevZ = null;
  12560. sortLinked( p );
  12561. }
  12562. // Simon Tatham's linked list merge sort algorithm
  12563. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  12564. function sortLinked( list ) {
  12565. let i, p, q, e, tail, numMerges, pSize, qSize,
  12566. inSize = 1;
  12567. do {
  12568. p = list;
  12569. list = null;
  12570. tail = null;
  12571. numMerges = 0;
  12572. while ( p ) {
  12573. numMerges ++;
  12574. q = p;
  12575. pSize = 0;
  12576. for ( i = 0; i < inSize; i ++ ) {
  12577. pSize ++;
  12578. q = q.nextZ;
  12579. if ( ! q ) break;
  12580. }
  12581. qSize = inSize;
  12582. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  12583. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  12584. e = p;
  12585. p = p.nextZ;
  12586. pSize --;
  12587. } else {
  12588. e = q;
  12589. q = q.nextZ;
  12590. qSize --;
  12591. }
  12592. if ( tail ) tail.nextZ = e;
  12593. else list = e;
  12594. e.prevZ = tail;
  12595. tail = e;
  12596. }
  12597. p = q;
  12598. }
  12599. tail.nextZ = null;
  12600. inSize *= 2;
  12601. } while ( numMerges > 1 );
  12602. return list;
  12603. }
  12604. // z-order of a point given coords and inverse of the longer side of data bbox
  12605. function zOrder( x, y, minX, minY, invSize ) {
  12606. // coords are transformed into non-negative 15-bit integer range
  12607. x = ( x - minX ) * invSize | 0;
  12608. y = ( y - minY ) * invSize | 0;
  12609. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  12610. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  12611. x = ( x | ( x << 2 ) ) & 0x33333333;
  12612. x = ( x | ( x << 1 ) ) & 0x55555555;
  12613. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  12614. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  12615. y = ( y | ( y << 2 ) ) & 0x33333333;
  12616. y = ( y | ( y << 1 ) ) & 0x55555555;
  12617. return x | ( y << 1 );
  12618. }
  12619. // find the leftmost node of a polygon ring
  12620. function getLeftmost( start ) {
  12621. let p = start,
  12622. leftmost = start;
  12623. do {
  12624. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  12625. p = p.next;
  12626. } while ( p !== start );
  12627. return leftmost;
  12628. }
  12629. // check if a point lies within a convex triangle
  12630. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  12631. return ( cx - px ) * ( ay - py ) >= ( ax - px ) * ( cy - py ) &&
  12632. ( ax - px ) * ( by - py ) >= ( bx - px ) * ( ay - py ) &&
  12633. ( bx - px ) * ( cy - py ) >= ( cx - px ) * ( by - py );
  12634. }
  12635. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  12636. function isValidDiagonal( a, b ) {
  12637. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  12638. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  12639. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  12640. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  12641. }
  12642. // signed area of a triangle
  12643. function area( p, q, r ) {
  12644. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  12645. }
  12646. // check if two points are equal
  12647. function equals( p1, p2 ) {
  12648. return p1.x === p2.x && p1.y === p2.y;
  12649. }
  12650. // check if two segments intersect
  12651. function intersects( p1, q1, p2, q2 ) {
  12652. const o1 = sign( area( p1, q1, p2 ) );
  12653. const o2 = sign( area( p1, q1, q2 ) );
  12654. const o3 = sign( area( p2, q2, p1 ) );
  12655. const o4 = sign( area( p2, q2, q1 ) );
  12656. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  12657. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  12658. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  12659. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  12660. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  12661. return false;
  12662. }
  12663. // for collinear points p, q, r, check if point q lies on segment pr
  12664. function onSegment( p, q, r ) {
  12665. 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 );
  12666. }
  12667. function sign( num ) {
  12668. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  12669. }
  12670. // check if a polygon diagonal intersects any polygon segments
  12671. function intersectsPolygon( a, b ) {
  12672. let p = a;
  12673. do {
  12674. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  12675. intersects( p, p.next, a, b ) ) return true;
  12676. p = p.next;
  12677. } while ( p !== a );
  12678. return false;
  12679. }
  12680. // check if a polygon diagonal is locally inside the polygon
  12681. function locallyInside( a, b ) {
  12682. return area( a.prev, a, a.next ) < 0 ?
  12683. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  12684. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  12685. }
  12686. // check if the middle point of a polygon diagonal is inside the polygon
  12687. function middleInside( a, b ) {
  12688. let p = a,
  12689. inside = false;
  12690. const px = ( a.x + b.x ) / 2,
  12691. py = ( a.y + b.y ) / 2;
  12692. do {
  12693. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  12694. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  12695. inside = ! inside;
  12696. p = p.next;
  12697. } while ( p !== a );
  12698. return inside;
  12699. }
  12700. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  12701. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  12702. function splitPolygon( a, b ) {
  12703. const a2 = new Node( a.i, a.x, a.y ),
  12704. b2 = new Node( b.i, b.x, b.y ),
  12705. an = a.next,
  12706. bp = b.prev;
  12707. a.next = b;
  12708. b.prev = a;
  12709. a2.next = an;
  12710. an.prev = a2;
  12711. b2.next = a2;
  12712. a2.prev = b2;
  12713. bp.next = b2;
  12714. b2.prev = bp;
  12715. return b2;
  12716. }
  12717. // create a node and optionally link it with previous one (in a circular doubly linked list)
  12718. function insertNode( i, x, y, last ) {
  12719. const p = new Node( i, x, y );
  12720. if ( ! last ) {
  12721. p.prev = p;
  12722. p.next = p;
  12723. } else {
  12724. p.next = last.next;
  12725. p.prev = last;
  12726. last.next.prev = p;
  12727. last.next = p;
  12728. }
  12729. return p;
  12730. }
  12731. function removeNode( p ) {
  12732. p.next.prev = p.prev;
  12733. p.prev.next = p.next;
  12734. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  12735. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  12736. }
  12737. function Node( i, x, y ) {
  12738. // vertex index in coordinates array
  12739. this.i = i;
  12740. // vertex coordinates
  12741. this.x = x;
  12742. this.y = y;
  12743. // previous and next vertex nodes in a polygon ring
  12744. this.prev = null;
  12745. this.next = null;
  12746. // z-order curve value
  12747. this.z = 0;
  12748. // previous and next nodes in z-order
  12749. this.prevZ = null;
  12750. this.nextZ = null;
  12751. // indicates whether this is a steiner point
  12752. this.steiner = false;
  12753. }
  12754. function signedArea( data, start, end, dim ) {
  12755. let sum = 0;
  12756. for ( let i = start, j = end - dim; i < end; i += dim ) {
  12757. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  12758. j = i;
  12759. }
  12760. return sum;
  12761. }
  12762. class ShapeUtils {
  12763. // calculate area of the contour polygon
  12764. static area( contour ) {
  12765. const n = contour.length;
  12766. let a = 0.0;
  12767. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  12768. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  12769. }
  12770. return a * 0.5;
  12771. }
  12772. static isClockWise( pts ) {
  12773. return ShapeUtils.area( pts ) < 0;
  12774. }
  12775. static triangulateShape( contour, holes ) {
  12776. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  12777. const holeIndices = []; // array of hole indices
  12778. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  12779. removeDupEndPts( contour );
  12780. addContour( vertices, contour );
  12781. //
  12782. let holeIndex = contour.length;
  12783. holes.forEach( removeDupEndPts );
  12784. for ( let i = 0; i < holes.length; i ++ ) {
  12785. holeIndices.push( holeIndex );
  12786. holeIndex += holes[ i ].length;
  12787. addContour( vertices, holes[ i ] );
  12788. }
  12789. //
  12790. const triangles = Earcut.triangulate( vertices, holeIndices );
  12791. //
  12792. for ( let i = 0; i < triangles.length; i += 3 ) {
  12793. faces.push( triangles.slice( i, i + 3 ) );
  12794. }
  12795. return faces;
  12796. }
  12797. }
  12798. function removeDupEndPts( points ) {
  12799. const l = points.length;
  12800. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  12801. points.pop();
  12802. }
  12803. }
  12804. function addContour( vertices, contour ) {
  12805. for ( let i = 0; i < contour.length; i ++ ) {
  12806. vertices.push( contour[ i ].x );
  12807. vertices.push( contour[ i ].y );
  12808. }
  12809. }
  12810. /**
  12811. * Creates extruded geometry from a path shape.
  12812. *
  12813. * parameters = {
  12814. *
  12815. * curveSegments: <int>, // number of points on the curves
  12816. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  12817. * depth: <float>, // Depth to extrude the shape
  12818. *
  12819. * bevelEnabled: <bool>, // turn on bevel
  12820. * bevelThickness: <float>, // how deep into the original shape bevel goes
  12821. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  12822. * bevelOffset: <float>, // how far from shape outline does bevel start
  12823. * bevelSegments: <int>, // number of bevel layers
  12824. *
  12825. * extrudePath: <THREE.Curve> // curve to extrude shape along
  12826. *
  12827. * UVGenerator: <Object> // object that provides UV generator functions
  12828. *
  12829. * }
  12830. */
  12831. class ExtrudeGeometry extends BufferGeometry {
  12832. 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 = {} ) {
  12833. super();
  12834. this.type = 'ExtrudeGeometry';
  12835. this.parameters = {
  12836. shapes: shapes,
  12837. options: options
  12838. };
  12839. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  12840. const scope = this;
  12841. const verticesArray = [];
  12842. const uvArray = [];
  12843. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  12844. const shape = shapes[ i ];
  12845. addShape( shape );
  12846. }
  12847. // build geometry
  12848. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  12849. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  12850. this.computeVertexNormals();
  12851. // functions
  12852. function addShape( shape ) {
  12853. const placeholder = [];
  12854. // options
  12855. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  12856. const steps = options.steps !== undefined ? options.steps : 1;
  12857. const depth = options.depth !== undefined ? options.depth : 1;
  12858. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  12859. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
  12860. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
  12861. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  12862. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  12863. const extrudePath = options.extrudePath;
  12864. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  12865. //
  12866. let extrudePts, extrudeByPath = false;
  12867. let splineTube, binormal, normal, position2;
  12868. if ( extrudePath ) {
  12869. extrudePts = extrudePath.getSpacedPoints( steps );
  12870. extrudeByPath = true;
  12871. bevelEnabled = false; // bevels not supported for path extrusion
  12872. // SETUP TNB variables
  12873. // TODO1 - have a .isClosed in spline?
  12874. splineTube = extrudePath.computeFrenetFrames( steps, false );
  12875. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  12876. binormal = new Vector3();
  12877. normal = new Vector3();
  12878. position2 = new Vector3();
  12879. }
  12880. // Safeguards if bevels are not enabled
  12881. if ( ! bevelEnabled ) {
  12882. bevelSegments = 0;
  12883. bevelThickness = 0;
  12884. bevelSize = 0;
  12885. bevelOffset = 0;
  12886. }
  12887. // Variables initialization
  12888. const shapePoints = shape.extractPoints( curveSegments );
  12889. let vertices = shapePoints.shape;
  12890. const holes = shapePoints.holes;
  12891. const reverse = ! ShapeUtils.isClockWise( vertices );
  12892. if ( reverse ) {
  12893. vertices = vertices.reverse();
  12894. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  12895. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12896. const ahole = holes[ h ];
  12897. if ( ShapeUtils.isClockWise( ahole ) ) {
  12898. holes[ h ] = ahole.reverse();
  12899. }
  12900. }
  12901. }
  12902. const faces = ShapeUtils.triangulateShape( vertices, holes );
  12903. /* Vertices */
  12904. const contour = vertices; // vertices has all points but contour has only points of circumference
  12905. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12906. const ahole = holes[ h ];
  12907. vertices = vertices.concat( ahole );
  12908. }
  12909. function scalePt2( pt, vec, size ) {
  12910. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  12911. return pt.clone().addScaledVector( vec, size );
  12912. }
  12913. const vlen = vertices.length, flen = faces.length;
  12914. // Find directions for point movement
  12915. function getBevelVec( inPt, inPrev, inNext ) {
  12916. // computes for inPt the corresponding point inPt' on a new contour
  12917. // shifted by 1 unit (length of normalized vector) to the left
  12918. // if we walk along contour clockwise, this new contour is outside the old one
  12919. //
  12920. // inPt' is the intersection of the two lines parallel to the two
  12921. // adjacent edges of inPt at a distance of 1 unit on the left side.
  12922. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  12923. // good reading for geometry algorithms (here: line-line intersection)
  12924. // http://geomalgorithms.com/a05-_intersect-1.html
  12925. const v_prev_x = inPt.x - inPrev.x,
  12926. v_prev_y = inPt.y - inPrev.y;
  12927. const v_next_x = inNext.x - inPt.x,
  12928. v_next_y = inNext.y - inPt.y;
  12929. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  12930. // check for collinear edges
  12931. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12932. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  12933. // not collinear
  12934. // length of vectors for normalizing
  12935. const v_prev_len = Math.sqrt( v_prev_lensq );
  12936. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  12937. // shift adjacent points by unit vectors to the left
  12938. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  12939. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  12940. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  12941. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  12942. // scaling factor for v_prev to intersection point
  12943. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  12944. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  12945. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12946. // vector from inPt to intersection point
  12947. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  12948. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  12949. // Don't normalize!, otherwise sharp corners become ugly
  12950. // but prevent crazy spikes
  12951. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  12952. if ( v_trans_lensq <= 2 ) {
  12953. return new Vector2( v_trans_x, v_trans_y );
  12954. } else {
  12955. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  12956. }
  12957. } else {
  12958. // handle special case of collinear edges
  12959. let direction_eq = false; // assumes: opposite
  12960. if ( v_prev_x > Number.EPSILON ) {
  12961. if ( v_next_x > Number.EPSILON ) {
  12962. direction_eq = true;
  12963. }
  12964. } else {
  12965. if ( v_prev_x < - Number.EPSILON ) {
  12966. if ( v_next_x < - Number.EPSILON ) {
  12967. direction_eq = true;
  12968. }
  12969. } else {
  12970. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  12971. direction_eq = true;
  12972. }
  12973. }
  12974. }
  12975. if ( direction_eq ) {
  12976. // console.log("Warning: lines are a straight sequence");
  12977. v_trans_x = - v_prev_y;
  12978. v_trans_y = v_prev_x;
  12979. shrink_by = Math.sqrt( v_prev_lensq );
  12980. } else {
  12981. // console.log("Warning: lines are a straight spike");
  12982. v_trans_x = v_prev_x;
  12983. v_trans_y = v_prev_y;
  12984. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  12985. }
  12986. }
  12987. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  12988. }
  12989. const contourMovements = [];
  12990. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  12991. if ( j === il ) j = 0;
  12992. if ( k === il ) k = 0;
  12993. // (j)---(i)---(k)
  12994. // console.log('i,j,k', i, j , k)
  12995. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  12996. }
  12997. const holesMovements = [];
  12998. let oneHoleMovements, verticesMovements = contourMovements.concat();
  12999. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13000. const ahole = holes[ h ];
  13001. oneHoleMovements = [];
  13002. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13003. if ( j === il ) j = 0;
  13004. if ( k === il ) k = 0;
  13005. // (j)---(i)---(k)
  13006. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  13007. }
  13008. holesMovements.push( oneHoleMovements );
  13009. verticesMovements = verticesMovements.concat( oneHoleMovements );
  13010. }
  13011. // Loop bevelSegments, 1 for the front, 1 for the back
  13012. for ( let b = 0; b < bevelSegments; b ++ ) {
  13013. //for ( b = bevelSegments; b > 0; b -- ) {
  13014. const t = b / bevelSegments;
  13015. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13016. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13017. // contract shape
  13018. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13019. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13020. v( vert.x, vert.y, - z );
  13021. }
  13022. // expand holes
  13023. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13024. const ahole = holes[ h ];
  13025. oneHoleMovements = holesMovements[ h ];
  13026. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13027. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13028. v( vert.x, vert.y, - z );
  13029. }
  13030. }
  13031. }
  13032. const bs = bevelSize + bevelOffset;
  13033. // Back facing vertices
  13034. for ( let i = 0; i < vlen; i ++ ) {
  13035. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13036. if ( ! extrudeByPath ) {
  13037. v( vert.x, vert.y, 0 );
  13038. } else {
  13039. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  13040. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  13041. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  13042. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  13043. v( position2.x, position2.y, position2.z );
  13044. }
  13045. }
  13046. // Add stepped vertices...
  13047. // Including front facing vertices
  13048. for ( let s = 1; s <= steps; s ++ ) {
  13049. for ( let i = 0; i < vlen; i ++ ) {
  13050. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13051. if ( ! extrudeByPath ) {
  13052. v( vert.x, vert.y, depth / steps * s );
  13053. } else {
  13054. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  13055. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  13056. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  13057. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  13058. v( position2.x, position2.y, position2.z );
  13059. }
  13060. }
  13061. }
  13062. // Add bevel segments planes
  13063. //for ( b = 1; b <= bevelSegments; b ++ ) {
  13064. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  13065. const t = b / bevelSegments;
  13066. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13067. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13068. // contract shape
  13069. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13070. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13071. v( vert.x, vert.y, depth + z );
  13072. }
  13073. // expand holes
  13074. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13075. const ahole = holes[ h ];
  13076. oneHoleMovements = holesMovements[ h ];
  13077. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13078. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13079. if ( ! extrudeByPath ) {
  13080. v( vert.x, vert.y, depth + z );
  13081. } else {
  13082. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  13083. }
  13084. }
  13085. }
  13086. }
  13087. /* Faces */
  13088. // Top and bottom faces
  13089. buildLidFaces();
  13090. // Sides faces
  13091. buildSideFaces();
  13092. ///// Internal functions
  13093. function buildLidFaces() {
  13094. const start = verticesArray.length / 3;
  13095. if ( bevelEnabled ) {
  13096. let layer = 0; // steps + 1
  13097. let offset = vlen * layer;
  13098. // Bottom faces
  13099. for ( let i = 0; i < flen; i ++ ) {
  13100. const face = faces[ i ];
  13101. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  13102. }
  13103. layer = steps + bevelSegments * 2;
  13104. offset = vlen * layer;
  13105. // Top faces
  13106. for ( let i = 0; i < flen; i ++ ) {
  13107. const face = faces[ i ];
  13108. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  13109. }
  13110. } else {
  13111. // Bottom faces
  13112. for ( let i = 0; i < flen; i ++ ) {
  13113. const face = faces[ i ];
  13114. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  13115. }
  13116. // Top faces
  13117. for ( let i = 0; i < flen; i ++ ) {
  13118. const face = faces[ i ];
  13119. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  13120. }
  13121. }
  13122. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  13123. }
  13124. // Create faces for the z-sides of the shape
  13125. function buildSideFaces() {
  13126. const start = verticesArray.length / 3;
  13127. let layeroffset = 0;
  13128. sidewalls( contour, layeroffset );
  13129. layeroffset += contour.length;
  13130. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13131. const ahole = holes[ h ];
  13132. sidewalls( ahole, layeroffset );
  13133. //, true
  13134. layeroffset += ahole.length;
  13135. }
  13136. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  13137. }
  13138. function sidewalls( contour, layeroffset ) {
  13139. let i = contour.length;
  13140. while ( -- i >= 0 ) {
  13141. const j = i;
  13142. let k = i - 1;
  13143. if ( k < 0 ) k = contour.length - 1;
  13144. //console.log('b', i,j, i-1, k,vertices.length);
  13145. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  13146. const slen1 = vlen * s;
  13147. const slen2 = vlen * ( s + 1 );
  13148. const a = layeroffset + j + slen1,
  13149. b = layeroffset + k + slen1,
  13150. c = layeroffset + k + slen2,
  13151. d = layeroffset + j + slen2;
  13152. f4( a, b, c, d );
  13153. }
  13154. }
  13155. }
  13156. function v( x, y, z ) {
  13157. placeholder.push( x );
  13158. placeholder.push( y );
  13159. placeholder.push( z );
  13160. }
  13161. function f3( a, b, c ) {
  13162. addVertex( a );
  13163. addVertex( b );
  13164. addVertex( c );
  13165. const nextIndex = verticesArray.length / 3;
  13166. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13167. addUV( uvs[ 0 ] );
  13168. addUV( uvs[ 1 ] );
  13169. addUV( uvs[ 2 ] );
  13170. }
  13171. function f4( a, b, c, d ) {
  13172. addVertex( a );
  13173. addVertex( b );
  13174. addVertex( d );
  13175. addVertex( b );
  13176. addVertex( c );
  13177. addVertex( d );
  13178. const nextIndex = verticesArray.length / 3;
  13179. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13180. addUV( uvs[ 0 ] );
  13181. addUV( uvs[ 1 ] );
  13182. addUV( uvs[ 3 ] );
  13183. addUV( uvs[ 1 ] );
  13184. addUV( uvs[ 2 ] );
  13185. addUV( uvs[ 3 ] );
  13186. }
  13187. function addVertex( index ) {
  13188. verticesArray.push( placeholder[ index * 3 + 0 ] );
  13189. verticesArray.push( placeholder[ index * 3 + 1 ] );
  13190. verticesArray.push( placeholder[ index * 3 + 2 ] );
  13191. }
  13192. function addUV( vector2 ) {
  13193. uvArray.push( vector2.x );
  13194. uvArray.push( vector2.y );
  13195. }
  13196. }
  13197. }
  13198. copy( source ) {
  13199. super.copy( source );
  13200. this.parameters = Object.assign( {}, source.parameters );
  13201. return this;
  13202. }
  13203. toJSON() {
  13204. const data = super.toJSON();
  13205. const shapes = this.parameters.shapes;
  13206. const options = this.parameters.options;
  13207. return toJSON$1( shapes, options, data );
  13208. }
  13209. static fromJSON( data, shapes ) {
  13210. const geometryShapes = [];
  13211. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13212. const shape = shapes[ data.shapes[ j ] ];
  13213. geometryShapes.push( shape );
  13214. }
  13215. const extrudePath = data.options.extrudePath;
  13216. if ( extrudePath !== undefined ) {
  13217. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  13218. }
  13219. return new ExtrudeGeometry( geometryShapes, data.options );
  13220. }
  13221. }
  13222. const WorldUVGenerator = {
  13223. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  13224. const a_x = vertices[ indexA * 3 ];
  13225. const a_y = vertices[ indexA * 3 + 1 ];
  13226. const b_x = vertices[ indexB * 3 ];
  13227. const b_y = vertices[ indexB * 3 + 1 ];
  13228. const c_x = vertices[ indexC * 3 ];
  13229. const c_y = vertices[ indexC * 3 + 1 ];
  13230. return [
  13231. new Vector2( a_x, a_y ),
  13232. new Vector2( b_x, b_y ),
  13233. new Vector2( c_x, c_y )
  13234. ];
  13235. },
  13236. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  13237. const a_x = vertices[ indexA * 3 ];
  13238. const a_y = vertices[ indexA * 3 + 1 ];
  13239. const a_z = vertices[ indexA * 3 + 2 ];
  13240. const b_x = vertices[ indexB * 3 ];
  13241. const b_y = vertices[ indexB * 3 + 1 ];
  13242. const b_z = vertices[ indexB * 3 + 2 ];
  13243. const c_x = vertices[ indexC * 3 ];
  13244. const c_y = vertices[ indexC * 3 + 1 ];
  13245. const c_z = vertices[ indexC * 3 + 2 ];
  13246. const d_x = vertices[ indexD * 3 ];
  13247. const d_y = vertices[ indexD * 3 + 1 ];
  13248. const d_z = vertices[ indexD * 3 + 2 ];
  13249. if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
  13250. return [
  13251. new Vector2( a_x, 1 - a_z ),
  13252. new Vector2( b_x, 1 - b_z ),
  13253. new Vector2( c_x, 1 - c_z ),
  13254. new Vector2( d_x, 1 - d_z )
  13255. ];
  13256. } else {
  13257. return [
  13258. new Vector2( a_y, 1 - a_z ),
  13259. new Vector2( b_y, 1 - b_z ),
  13260. new Vector2( c_y, 1 - c_z ),
  13261. new Vector2( d_y, 1 - d_z )
  13262. ];
  13263. }
  13264. }
  13265. };
  13266. function toJSON$1( shapes, options, data ) {
  13267. data.shapes = [];
  13268. if ( Array.isArray( shapes ) ) {
  13269. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13270. const shape = shapes[ i ];
  13271. data.shapes.push( shape.uuid );
  13272. }
  13273. } else {
  13274. data.shapes.push( shapes.uuid );
  13275. }
  13276. data.options = Object.assign( {}, options );
  13277. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  13278. return data;
  13279. }
  13280. class IcosahedronGeometry extends PolyhedronGeometry {
  13281. constructor( radius = 1, detail = 0 ) {
  13282. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  13283. const vertices = [
  13284. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  13285. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  13286. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  13287. ];
  13288. const indices = [
  13289. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  13290. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  13291. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  13292. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  13293. ];
  13294. super( vertices, indices, radius, detail );
  13295. this.type = 'IcosahedronGeometry';
  13296. this.parameters = {
  13297. radius: radius,
  13298. detail: detail
  13299. };
  13300. }
  13301. static fromJSON( data ) {
  13302. return new IcosahedronGeometry( data.radius, data.detail );
  13303. }
  13304. }
  13305. class OctahedronGeometry extends PolyhedronGeometry {
  13306. constructor( radius = 1, detail = 0 ) {
  13307. const vertices = [
  13308. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  13309. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  13310. ];
  13311. const indices = [
  13312. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  13313. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  13314. 1, 3, 4, 1, 4, 2
  13315. ];
  13316. super( vertices, indices, radius, detail );
  13317. this.type = 'OctahedronGeometry';
  13318. this.parameters = {
  13319. radius: radius,
  13320. detail: detail
  13321. };
  13322. }
  13323. static fromJSON( data ) {
  13324. return new OctahedronGeometry( data.radius, data.detail );
  13325. }
  13326. }
  13327. class PlaneGeometry extends BufferGeometry {
  13328. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  13329. super();
  13330. this.type = 'PlaneGeometry';
  13331. this.parameters = {
  13332. width: width,
  13333. height: height,
  13334. widthSegments: widthSegments,
  13335. heightSegments: heightSegments
  13336. };
  13337. const width_half = width / 2;
  13338. const height_half = height / 2;
  13339. const gridX = Math.floor( widthSegments );
  13340. const gridY = Math.floor( heightSegments );
  13341. const gridX1 = gridX + 1;
  13342. const gridY1 = gridY + 1;
  13343. const segment_width = width / gridX;
  13344. const segment_height = height / gridY;
  13345. //
  13346. const indices = [];
  13347. const vertices = [];
  13348. const normals = [];
  13349. const uvs = [];
  13350. for ( let iy = 0; iy < gridY1; iy ++ ) {
  13351. const y = iy * segment_height - height_half;
  13352. for ( let ix = 0; ix < gridX1; ix ++ ) {
  13353. const x = ix * segment_width - width_half;
  13354. vertices.push( x, - y, 0 );
  13355. normals.push( 0, 0, 1 );
  13356. uvs.push( ix / gridX );
  13357. uvs.push( 1 - ( iy / gridY ) );
  13358. }
  13359. }
  13360. for ( let iy = 0; iy < gridY; iy ++ ) {
  13361. for ( let ix = 0; ix < gridX; ix ++ ) {
  13362. const a = ix + gridX1 * iy;
  13363. const b = ix + gridX1 * ( iy + 1 );
  13364. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  13365. const d = ( ix + 1 ) + gridX1 * iy;
  13366. indices.push( a, b, d );
  13367. indices.push( b, c, d );
  13368. }
  13369. }
  13370. this.setIndex( indices );
  13371. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13372. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13373. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13374. }
  13375. copy( source ) {
  13376. super.copy( source );
  13377. this.parameters = Object.assign( {}, source.parameters );
  13378. return this;
  13379. }
  13380. static fromJSON( data ) {
  13381. return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
  13382. }
  13383. }
  13384. class RingGeometry extends BufferGeometry {
  13385. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  13386. super();
  13387. this.type = 'RingGeometry';
  13388. this.parameters = {
  13389. innerRadius: innerRadius,
  13390. outerRadius: outerRadius,
  13391. thetaSegments: thetaSegments,
  13392. phiSegments: phiSegments,
  13393. thetaStart: thetaStart,
  13394. thetaLength: thetaLength
  13395. };
  13396. thetaSegments = Math.max( 3, thetaSegments );
  13397. phiSegments = Math.max( 1, phiSegments );
  13398. // buffers
  13399. const indices = [];
  13400. const vertices = [];
  13401. const normals = [];
  13402. const uvs = [];
  13403. // some helper variables
  13404. let radius = innerRadius;
  13405. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  13406. const vertex = new Vector3();
  13407. const uv = new Vector2();
  13408. // generate vertices, normals and uvs
  13409. for ( let j = 0; j <= phiSegments; j ++ ) {
  13410. for ( let i = 0; i <= thetaSegments; i ++ ) {
  13411. // values are generate from the inside of the ring to the outside
  13412. const segment = thetaStart + i / thetaSegments * thetaLength;
  13413. // vertex
  13414. vertex.x = radius * Math.cos( segment );
  13415. vertex.y = radius * Math.sin( segment );
  13416. vertices.push( vertex.x, vertex.y, vertex.z );
  13417. // normal
  13418. normals.push( 0, 0, 1 );
  13419. // uv
  13420. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  13421. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  13422. uvs.push( uv.x, uv.y );
  13423. }
  13424. // increase the radius for next row of vertices
  13425. radius += radiusStep;
  13426. }
  13427. // indices
  13428. for ( let j = 0; j < phiSegments; j ++ ) {
  13429. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  13430. for ( let i = 0; i < thetaSegments; i ++ ) {
  13431. const segment = i + thetaSegmentLevel;
  13432. const a = segment;
  13433. const b = segment + thetaSegments + 1;
  13434. const c = segment + thetaSegments + 2;
  13435. const d = segment + 1;
  13436. // faces
  13437. indices.push( a, b, d );
  13438. indices.push( b, c, d );
  13439. }
  13440. }
  13441. // build geometry
  13442. this.setIndex( indices );
  13443. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13444. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13445. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13446. }
  13447. copy( source ) {
  13448. super.copy( source );
  13449. this.parameters = Object.assign( {}, source.parameters );
  13450. return this;
  13451. }
  13452. static fromJSON( data ) {
  13453. return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
  13454. }
  13455. }
  13456. class ShapeGeometry extends BufferGeometry {
  13457. constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) {
  13458. super();
  13459. this.type = 'ShapeGeometry';
  13460. this.parameters = {
  13461. shapes: shapes,
  13462. curveSegments: curveSegments
  13463. };
  13464. // buffers
  13465. const indices = [];
  13466. const vertices = [];
  13467. const normals = [];
  13468. const uvs = [];
  13469. // helper variables
  13470. let groupStart = 0;
  13471. let groupCount = 0;
  13472. // allow single and array values for "shapes" parameter
  13473. if ( Array.isArray( shapes ) === false ) {
  13474. addShape( shapes );
  13475. } else {
  13476. for ( let i = 0; i < shapes.length; i ++ ) {
  13477. addShape( shapes[ i ] );
  13478. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  13479. groupStart += groupCount;
  13480. groupCount = 0;
  13481. }
  13482. }
  13483. // build geometry
  13484. this.setIndex( indices );
  13485. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13486. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13487. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13488. // helper functions
  13489. function addShape( shape ) {
  13490. const indexOffset = vertices.length / 3;
  13491. const points = shape.extractPoints( curveSegments );
  13492. let shapeVertices = points.shape;
  13493. const shapeHoles = points.holes;
  13494. // check direction of vertices
  13495. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  13496. shapeVertices = shapeVertices.reverse();
  13497. }
  13498. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13499. const shapeHole = shapeHoles[ i ];
  13500. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  13501. shapeHoles[ i ] = shapeHole.reverse();
  13502. }
  13503. }
  13504. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  13505. // join vertices of inner and outer paths to a single array
  13506. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13507. const shapeHole = shapeHoles[ i ];
  13508. shapeVertices = shapeVertices.concat( shapeHole );
  13509. }
  13510. // vertices, normals, uvs
  13511. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  13512. const vertex = shapeVertices[ i ];
  13513. vertices.push( vertex.x, vertex.y, 0 );
  13514. normals.push( 0, 0, 1 );
  13515. uvs.push( vertex.x, vertex.y ); // world uvs
  13516. }
  13517. // indices
  13518. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  13519. const face = faces[ i ];
  13520. const a = face[ 0 ] + indexOffset;
  13521. const b = face[ 1 ] + indexOffset;
  13522. const c = face[ 2 ] + indexOffset;
  13523. indices.push( a, b, c );
  13524. groupCount += 3;
  13525. }
  13526. }
  13527. }
  13528. copy( source ) {
  13529. super.copy( source );
  13530. this.parameters = Object.assign( {}, source.parameters );
  13531. return this;
  13532. }
  13533. toJSON() {
  13534. const data = super.toJSON();
  13535. const shapes = this.parameters.shapes;
  13536. return toJSON( shapes, data );
  13537. }
  13538. static fromJSON( data, shapes ) {
  13539. const geometryShapes = [];
  13540. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13541. const shape = shapes[ data.shapes[ j ] ];
  13542. geometryShapes.push( shape );
  13543. }
  13544. return new ShapeGeometry( geometryShapes, data.curveSegments );
  13545. }
  13546. }
  13547. function toJSON( shapes, data ) {
  13548. data.shapes = [];
  13549. if ( Array.isArray( shapes ) ) {
  13550. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13551. const shape = shapes[ i ];
  13552. data.shapes.push( shape.uuid );
  13553. }
  13554. } else {
  13555. data.shapes.push( shapes.uuid );
  13556. }
  13557. return data;
  13558. }
  13559. class SphereGeometry extends BufferGeometry {
  13560. constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  13561. super();
  13562. this.type = 'SphereGeometry';
  13563. this.parameters = {
  13564. radius: radius,
  13565. widthSegments: widthSegments,
  13566. heightSegments: heightSegments,
  13567. phiStart: phiStart,
  13568. phiLength: phiLength,
  13569. thetaStart: thetaStart,
  13570. thetaLength: thetaLength
  13571. };
  13572. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  13573. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  13574. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  13575. let index = 0;
  13576. const grid = [];
  13577. const vertex = new Vector3();
  13578. const normal = new Vector3();
  13579. // buffers
  13580. const indices = [];
  13581. const vertices = [];
  13582. const normals = [];
  13583. const uvs = [];
  13584. // generate vertices, normals and uvs
  13585. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  13586. const verticesRow = [];
  13587. const v = iy / heightSegments;
  13588. // special case for the poles
  13589. let uOffset = 0;
  13590. if ( iy === 0 && thetaStart === 0 ) {
  13591. uOffset = 0.5 / widthSegments;
  13592. } else if ( iy === heightSegments && thetaEnd === Math.PI ) {
  13593. uOffset = - 0.5 / widthSegments;
  13594. }
  13595. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  13596. const u = ix / widthSegments;
  13597. // vertex
  13598. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13599. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  13600. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13601. vertices.push( vertex.x, vertex.y, vertex.z );
  13602. // normal
  13603. normal.copy( vertex ).normalize();
  13604. normals.push( normal.x, normal.y, normal.z );
  13605. // uv
  13606. uvs.push( u + uOffset, 1 - v );
  13607. verticesRow.push( index ++ );
  13608. }
  13609. grid.push( verticesRow );
  13610. }
  13611. // indices
  13612. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  13613. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  13614. const a = grid[ iy ][ ix + 1 ];
  13615. const b = grid[ iy ][ ix ];
  13616. const c = grid[ iy + 1 ][ ix ];
  13617. const d = grid[ iy + 1 ][ ix + 1 ];
  13618. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  13619. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  13620. }
  13621. }
  13622. // build geometry
  13623. this.setIndex( indices );
  13624. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13625. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13626. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13627. }
  13628. copy( source ) {
  13629. super.copy( source );
  13630. this.parameters = Object.assign( {}, source.parameters );
  13631. return this;
  13632. }
  13633. static fromJSON( data ) {
  13634. return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
  13635. }
  13636. }
  13637. class TetrahedronGeometry extends PolyhedronGeometry {
  13638. constructor( radius = 1, detail = 0 ) {
  13639. const vertices = [
  13640. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  13641. ];
  13642. const indices = [
  13643. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  13644. ];
  13645. super( vertices, indices, radius, detail );
  13646. this.type = 'TetrahedronGeometry';
  13647. this.parameters = {
  13648. radius: radius,
  13649. detail: detail
  13650. };
  13651. }
  13652. static fromJSON( data ) {
  13653. return new TetrahedronGeometry( data.radius, data.detail );
  13654. }
  13655. }
  13656. class TorusGeometry extends BufferGeometry {
  13657. constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
  13658. super();
  13659. this.type = 'TorusGeometry';
  13660. this.parameters = {
  13661. radius: radius,
  13662. tube: tube,
  13663. radialSegments: radialSegments,
  13664. tubularSegments: tubularSegments,
  13665. arc: arc
  13666. };
  13667. radialSegments = Math.floor( radialSegments );
  13668. tubularSegments = Math.floor( tubularSegments );
  13669. // buffers
  13670. const indices = [];
  13671. const vertices = [];
  13672. const normals = [];
  13673. const uvs = [];
  13674. // helper variables
  13675. const center = new Vector3();
  13676. const vertex = new Vector3();
  13677. const normal = new Vector3();
  13678. // generate vertices, normals and uvs
  13679. for ( let j = 0; j <= radialSegments; j ++ ) {
  13680. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13681. const u = i / tubularSegments * arc;
  13682. const v = j / radialSegments * Math.PI * 2;
  13683. // vertex
  13684. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  13685. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  13686. vertex.z = tube * Math.sin( v );
  13687. vertices.push( vertex.x, vertex.y, vertex.z );
  13688. // normal
  13689. center.x = radius * Math.cos( u );
  13690. center.y = radius * Math.sin( u );
  13691. normal.subVectors( vertex, center ).normalize();
  13692. normals.push( normal.x, normal.y, normal.z );
  13693. // uv
  13694. uvs.push( i / tubularSegments );
  13695. uvs.push( j / radialSegments );
  13696. }
  13697. }
  13698. // generate indices
  13699. for ( let j = 1; j <= radialSegments; j ++ ) {
  13700. for ( let i = 1; i <= tubularSegments; i ++ ) {
  13701. // indices
  13702. const a = ( tubularSegments + 1 ) * j + i - 1;
  13703. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  13704. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  13705. const d = ( tubularSegments + 1 ) * j + i;
  13706. // faces
  13707. indices.push( a, b, d );
  13708. indices.push( b, c, d );
  13709. }
  13710. }
  13711. // build geometry
  13712. this.setIndex( indices );
  13713. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13714. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13715. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13716. }
  13717. copy( source ) {
  13718. super.copy( source );
  13719. this.parameters = Object.assign( {}, source.parameters );
  13720. return this;
  13721. }
  13722. static fromJSON( data ) {
  13723. return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
  13724. }
  13725. }
  13726. class TorusKnotGeometry extends BufferGeometry {
  13727. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  13728. super();
  13729. this.type = 'TorusKnotGeometry';
  13730. this.parameters = {
  13731. radius: radius,
  13732. tube: tube,
  13733. tubularSegments: tubularSegments,
  13734. radialSegments: radialSegments,
  13735. p: p,
  13736. q: q
  13737. };
  13738. tubularSegments = Math.floor( tubularSegments );
  13739. radialSegments = Math.floor( radialSegments );
  13740. // buffers
  13741. const indices = [];
  13742. const vertices = [];
  13743. const normals = [];
  13744. const uvs = [];
  13745. // helper variables
  13746. const vertex = new Vector3();
  13747. const normal = new Vector3();
  13748. const P1 = new Vector3();
  13749. const P2 = new Vector3();
  13750. const B = new Vector3();
  13751. const T = new Vector3();
  13752. const N = new Vector3();
  13753. // generate vertices, normals and uvs
  13754. for ( let i = 0; i <= tubularSegments; ++ i ) {
  13755. // the radian "u" is used to calculate the position on the torus curve of the current tubular segment
  13756. const u = i / tubularSegments * p * Math.PI * 2;
  13757. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  13758. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  13759. calculatePositionOnCurve( u, p, q, radius, P1 );
  13760. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  13761. // calculate orthonormal basis
  13762. T.subVectors( P2, P1 );
  13763. N.addVectors( P2, P1 );
  13764. B.crossVectors( T, N );
  13765. N.crossVectors( B, T );
  13766. // normalize B, N. T can be ignored, we don't use it
  13767. B.normalize();
  13768. N.normalize();
  13769. for ( let j = 0; j <= radialSegments; ++ j ) {
  13770. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  13771. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  13772. const v = j / radialSegments * Math.PI * 2;
  13773. const cx = - tube * Math.cos( v );
  13774. const cy = tube * Math.sin( v );
  13775. // now calculate the final vertex position.
  13776. // first we orient the extrusion with our basis vectors, then we add it to the current position on the curve
  13777. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  13778. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  13779. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  13780. vertices.push( vertex.x, vertex.y, vertex.z );
  13781. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  13782. normal.subVectors( vertex, P1 ).normalize();
  13783. normals.push( normal.x, normal.y, normal.z );
  13784. // uv
  13785. uvs.push( i / tubularSegments );
  13786. uvs.push( j / radialSegments );
  13787. }
  13788. }
  13789. // generate indices
  13790. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13791. for ( let i = 1; i <= radialSegments; i ++ ) {
  13792. // indices
  13793. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13794. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13795. const c = ( radialSegments + 1 ) * j + i;
  13796. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13797. // faces
  13798. indices.push( a, b, d );
  13799. indices.push( b, c, d );
  13800. }
  13801. }
  13802. // build geometry
  13803. this.setIndex( indices );
  13804. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13805. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13806. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13807. // this function calculates the current position on the torus curve
  13808. function calculatePositionOnCurve( u, p, q, radius, position ) {
  13809. const cu = Math.cos( u );
  13810. const su = Math.sin( u );
  13811. const quOverP = q / p * u;
  13812. const cs = Math.cos( quOverP );
  13813. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  13814. position.y = radius * ( 2 + cs ) * su * 0.5;
  13815. position.z = radius * Math.sin( quOverP ) * 0.5;
  13816. }
  13817. }
  13818. copy( source ) {
  13819. super.copy( source );
  13820. this.parameters = Object.assign( {}, source.parameters );
  13821. return this;
  13822. }
  13823. static fromJSON( data ) {
  13824. return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
  13825. }
  13826. }
  13827. class TubeGeometry extends BufferGeometry {
  13828. 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 ) {
  13829. super();
  13830. this.type = 'TubeGeometry';
  13831. this.parameters = {
  13832. path: path,
  13833. tubularSegments: tubularSegments,
  13834. radius: radius,
  13835. radialSegments: radialSegments,
  13836. closed: closed
  13837. };
  13838. const frames = path.computeFrenetFrames( tubularSegments, closed );
  13839. // expose internals
  13840. this.tangents = frames.tangents;
  13841. this.normals = frames.normals;
  13842. this.binormals = frames.binormals;
  13843. // helper variables
  13844. const vertex = new Vector3();
  13845. const normal = new Vector3();
  13846. const uv = new Vector2();
  13847. let P = new Vector3();
  13848. // buffer
  13849. const vertices = [];
  13850. const normals = [];
  13851. const uvs = [];
  13852. const indices = [];
  13853. // create buffer data
  13854. generateBufferData();
  13855. // build geometry
  13856. this.setIndex( indices );
  13857. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13858. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13859. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13860. // functions
  13861. function generateBufferData() {
  13862. for ( let i = 0; i < tubularSegments; i ++ ) {
  13863. generateSegment( i );
  13864. }
  13865. // if the geometry is not closed, generate the last row of vertices and normals
  13866. // at the regular position on the given path
  13867. //
  13868. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  13869. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  13870. // uvs are generated in a separate function.
  13871. // this makes it easy compute correct values for closed geometries
  13872. generateUVs();
  13873. // finally create faces
  13874. generateIndices();
  13875. }
  13876. function generateSegment( i ) {
  13877. // we use getPointAt to sample evenly distributed points from the given path
  13878. P = path.getPointAt( i / tubularSegments, P );
  13879. // retrieve corresponding normal and binormal
  13880. const N = frames.normals[ i ];
  13881. const B = frames.binormals[ i ];
  13882. // generate normals and vertices for the current segment
  13883. for ( let j = 0; j <= radialSegments; j ++ ) {
  13884. const v = j / radialSegments * Math.PI * 2;
  13885. const sin = Math.sin( v );
  13886. const cos = - Math.cos( v );
  13887. // normal
  13888. normal.x = ( cos * N.x + sin * B.x );
  13889. normal.y = ( cos * N.y + sin * B.y );
  13890. normal.z = ( cos * N.z + sin * B.z );
  13891. normal.normalize();
  13892. normals.push( normal.x, normal.y, normal.z );
  13893. // vertex
  13894. vertex.x = P.x + radius * normal.x;
  13895. vertex.y = P.y + radius * normal.y;
  13896. vertex.z = P.z + radius * normal.z;
  13897. vertices.push( vertex.x, vertex.y, vertex.z );
  13898. }
  13899. }
  13900. function generateIndices() {
  13901. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13902. for ( let i = 1; i <= radialSegments; i ++ ) {
  13903. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13904. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13905. const c = ( radialSegments + 1 ) * j + i;
  13906. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13907. // faces
  13908. indices.push( a, b, d );
  13909. indices.push( b, c, d );
  13910. }
  13911. }
  13912. }
  13913. function generateUVs() {
  13914. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13915. for ( let j = 0; j <= radialSegments; j ++ ) {
  13916. uv.x = i / tubularSegments;
  13917. uv.y = j / radialSegments;
  13918. uvs.push( uv.x, uv.y );
  13919. }
  13920. }
  13921. }
  13922. }
  13923. copy( source ) {
  13924. super.copy( source );
  13925. this.parameters = Object.assign( {}, source.parameters );
  13926. return this;
  13927. }
  13928. toJSON() {
  13929. const data = super.toJSON();
  13930. data.path = this.parameters.path.toJSON();
  13931. return data;
  13932. }
  13933. static fromJSON( data ) {
  13934. // This only works for built-in curves (e.g. CatmullRomCurve3).
  13935. // User defined curves or instances of CurvePath will not be deserialized.
  13936. return new TubeGeometry(
  13937. new Curves[ data.path.type ]().fromJSON( data.path ),
  13938. data.tubularSegments,
  13939. data.radius,
  13940. data.radialSegments,
  13941. data.closed
  13942. );
  13943. }
  13944. }
  13945. class WireframeGeometry extends BufferGeometry {
  13946. constructor( geometry = null ) {
  13947. super();
  13948. this.type = 'WireframeGeometry';
  13949. this.parameters = {
  13950. geometry: geometry
  13951. };
  13952. if ( geometry !== null ) {
  13953. // buffer
  13954. const vertices = [];
  13955. const edges = new Set();
  13956. // helper variables
  13957. const start = new Vector3();
  13958. const end = new Vector3();
  13959. if ( geometry.index !== null ) {
  13960. // indexed BufferGeometry
  13961. const position = geometry.attributes.position;
  13962. const indices = geometry.index;
  13963. let groups = geometry.groups;
  13964. if ( groups.length === 0 ) {
  13965. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  13966. }
  13967. // create a data structure that contains all edges without duplicates
  13968. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  13969. const group = groups[ o ];
  13970. const groupStart = group.start;
  13971. const groupCount = group.count;
  13972. for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
  13973. for ( let j = 0; j < 3; j ++ ) {
  13974. const index1 = indices.getX( i + j );
  13975. const index2 = indices.getX( i + ( j + 1 ) % 3 );
  13976. start.fromBufferAttribute( position, index1 );
  13977. end.fromBufferAttribute( position, index2 );
  13978. if ( isUniqueEdge( start, end, edges ) === true ) {
  13979. vertices.push( start.x, start.y, start.z );
  13980. vertices.push( end.x, end.y, end.z );
  13981. }
  13982. }
  13983. }
  13984. }
  13985. } else {
  13986. // non-indexed BufferGeometry
  13987. const position = geometry.attributes.position;
  13988. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  13989. for ( let j = 0; j < 3; j ++ ) {
  13990. // three edges per triangle, an edge is represented as (index1, index2)
  13991. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  13992. const index1 = 3 * i + j;
  13993. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  13994. start.fromBufferAttribute( position, index1 );
  13995. end.fromBufferAttribute( position, index2 );
  13996. if ( isUniqueEdge( start, end, edges ) === true ) {
  13997. vertices.push( start.x, start.y, start.z );
  13998. vertices.push( end.x, end.y, end.z );
  13999. }
  14000. }
  14001. }
  14002. }
  14003. // build geometry
  14004. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14005. }
  14006. }
  14007. copy( source ) {
  14008. super.copy( source );
  14009. this.parameters = Object.assign( {}, source.parameters );
  14010. return this;
  14011. }
  14012. }
  14013. function isUniqueEdge( start, end, edges ) {
  14014. const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
  14015. const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
  14016. if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
  14017. return false;
  14018. } else {
  14019. edges.add( hash1 );
  14020. edges.add( hash2 );
  14021. return true;
  14022. }
  14023. }
  14024. var Geometries = /*#__PURE__*/Object.freeze({
  14025. __proto__: null,
  14026. BoxGeometry: BoxGeometry,
  14027. CapsuleGeometry: CapsuleGeometry,
  14028. CircleGeometry: CircleGeometry,
  14029. ConeGeometry: ConeGeometry,
  14030. CylinderGeometry: CylinderGeometry,
  14031. DodecahedronGeometry: DodecahedronGeometry,
  14032. EdgesGeometry: EdgesGeometry,
  14033. ExtrudeGeometry: ExtrudeGeometry,
  14034. IcosahedronGeometry: IcosahedronGeometry,
  14035. LatheGeometry: LatheGeometry,
  14036. OctahedronGeometry: OctahedronGeometry,
  14037. PlaneGeometry: PlaneGeometry,
  14038. PolyhedronGeometry: PolyhedronGeometry,
  14039. RingGeometry: RingGeometry,
  14040. ShapeGeometry: ShapeGeometry,
  14041. SphereGeometry: SphereGeometry,
  14042. TetrahedronGeometry: TetrahedronGeometry,
  14043. TorusGeometry: TorusGeometry,
  14044. TorusKnotGeometry: TorusKnotGeometry,
  14045. TubeGeometry: TubeGeometry,
  14046. WireframeGeometry: WireframeGeometry
  14047. });
  14048. class ShadowMaterial extends Material {
  14049. constructor( parameters ) {
  14050. super();
  14051. this.isShadowMaterial = true;
  14052. this.type = 'ShadowMaterial';
  14053. this.color = new Color( 0x000000 );
  14054. this.transparent = true;
  14055. this.fog = true;
  14056. this.setValues( parameters );
  14057. }
  14058. copy( source ) {
  14059. super.copy( source );
  14060. this.color.copy( source.color );
  14061. this.fog = source.fog;
  14062. return this;
  14063. }
  14064. }
  14065. class RawShaderMaterial extends ShaderMaterial {
  14066. constructor( parameters ) {
  14067. super( parameters );
  14068. this.isRawShaderMaterial = true;
  14069. this.type = 'RawShaderMaterial';
  14070. }
  14071. }
  14072. class MeshStandardMaterial extends Material {
  14073. constructor( parameters ) {
  14074. super();
  14075. this.isMeshStandardMaterial = true;
  14076. this.type = 'MeshStandardMaterial';
  14077. this.defines = { 'STANDARD': '' };
  14078. this.color = new Color( 0xffffff ); // diffuse
  14079. this.roughness = 1.0;
  14080. this.metalness = 0.0;
  14081. this.map = null;
  14082. this.lightMap = null;
  14083. this.lightMapIntensity = 1.0;
  14084. this.aoMap = null;
  14085. this.aoMapIntensity = 1.0;
  14086. this.emissive = new Color( 0x000000 );
  14087. this.emissiveIntensity = 1.0;
  14088. this.emissiveMap = null;
  14089. this.bumpMap = null;
  14090. this.bumpScale = 1;
  14091. this.normalMap = null;
  14092. this.normalMapType = TangentSpaceNormalMap;
  14093. this.normalScale = new Vector2( 1, 1 );
  14094. this.displacementMap = null;
  14095. this.displacementScale = 1;
  14096. this.displacementBias = 0;
  14097. this.roughnessMap = null;
  14098. this.metalnessMap = null;
  14099. this.alphaMap = null;
  14100. this.envMap = null;
  14101. this.envMapRotation = new Euler();
  14102. this.envMapIntensity = 1.0;
  14103. this.wireframe = false;
  14104. this.wireframeLinewidth = 1;
  14105. this.wireframeLinecap = 'round';
  14106. this.wireframeLinejoin = 'round';
  14107. this.flatShading = false;
  14108. this.fog = true;
  14109. this.setValues( parameters );
  14110. }
  14111. copy( source ) {
  14112. super.copy( source );
  14113. this.defines = { 'STANDARD': '' };
  14114. this.color.copy( source.color );
  14115. this.roughness = source.roughness;
  14116. this.metalness = source.metalness;
  14117. this.map = source.map;
  14118. this.lightMap = source.lightMap;
  14119. this.lightMapIntensity = source.lightMapIntensity;
  14120. this.aoMap = source.aoMap;
  14121. this.aoMapIntensity = source.aoMapIntensity;
  14122. this.emissive.copy( source.emissive );
  14123. this.emissiveMap = source.emissiveMap;
  14124. this.emissiveIntensity = source.emissiveIntensity;
  14125. this.bumpMap = source.bumpMap;
  14126. this.bumpScale = source.bumpScale;
  14127. this.normalMap = source.normalMap;
  14128. this.normalMapType = source.normalMapType;
  14129. this.normalScale.copy( source.normalScale );
  14130. this.displacementMap = source.displacementMap;
  14131. this.displacementScale = source.displacementScale;
  14132. this.displacementBias = source.displacementBias;
  14133. this.roughnessMap = source.roughnessMap;
  14134. this.metalnessMap = source.metalnessMap;
  14135. this.alphaMap = source.alphaMap;
  14136. this.envMap = source.envMap;
  14137. this.envMapRotation.copy( source.envMapRotation );
  14138. this.envMapIntensity = source.envMapIntensity;
  14139. this.wireframe = source.wireframe;
  14140. this.wireframeLinewidth = source.wireframeLinewidth;
  14141. this.wireframeLinecap = source.wireframeLinecap;
  14142. this.wireframeLinejoin = source.wireframeLinejoin;
  14143. this.flatShading = source.flatShading;
  14144. this.fog = source.fog;
  14145. return this;
  14146. }
  14147. }
  14148. class MeshPhysicalMaterial extends MeshStandardMaterial {
  14149. constructor( parameters ) {
  14150. super();
  14151. this.isMeshPhysicalMaterial = true;
  14152. this.defines = {
  14153. 'STANDARD': '',
  14154. 'PHYSICAL': ''
  14155. };
  14156. this.type = 'MeshPhysicalMaterial';
  14157. this.anisotropyRotation = 0;
  14158. this.anisotropyMap = null;
  14159. this.clearcoatMap = null;
  14160. this.clearcoatRoughness = 0.0;
  14161. this.clearcoatRoughnessMap = null;
  14162. this.clearcoatNormalScale = new Vector2( 1, 1 );
  14163. this.clearcoatNormalMap = null;
  14164. this.ior = 1.5;
  14165. Object.defineProperty( this, 'reflectivity', {
  14166. get: function () {
  14167. return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  14168. },
  14169. set: function ( reflectivity ) {
  14170. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  14171. }
  14172. } );
  14173. this.iridescenceMap = null;
  14174. this.iridescenceIOR = 1.3;
  14175. this.iridescenceThicknessRange = [ 100, 400 ];
  14176. this.iridescenceThicknessMap = null;
  14177. this.sheenColor = new Color( 0x000000 );
  14178. this.sheenColorMap = null;
  14179. this.sheenRoughness = 1.0;
  14180. this.sheenRoughnessMap = null;
  14181. this.transmissionMap = null;
  14182. this.thickness = 0;
  14183. this.thicknessMap = null;
  14184. this.attenuationDistance = Infinity;
  14185. this.attenuationColor = new Color( 1, 1, 1 );
  14186. this.specularIntensity = 1.0;
  14187. this.specularIntensityMap = null;
  14188. this.specularColor = new Color( 1, 1, 1 );
  14189. this.specularColorMap = null;
  14190. this._anisotropy = 0;
  14191. this._clearcoat = 0;
  14192. this._dispersion = 0;
  14193. this._iridescence = 0;
  14194. this._sheen = 0.0;
  14195. this._transmission = 0;
  14196. this.setValues( parameters );
  14197. }
  14198. get anisotropy() {
  14199. return this._anisotropy;
  14200. }
  14201. set anisotropy( value ) {
  14202. if ( this._anisotropy > 0 !== value > 0 ) {
  14203. this.version ++;
  14204. }
  14205. this._anisotropy = value;
  14206. }
  14207. get clearcoat() {
  14208. return this._clearcoat;
  14209. }
  14210. set clearcoat( value ) {
  14211. if ( this._clearcoat > 0 !== value > 0 ) {
  14212. this.version ++;
  14213. }
  14214. this._clearcoat = value;
  14215. }
  14216. get iridescence() {
  14217. return this._iridescence;
  14218. }
  14219. set iridescence( value ) {
  14220. if ( this._iridescence > 0 !== value > 0 ) {
  14221. this.version ++;
  14222. }
  14223. this._iridescence = value;
  14224. }
  14225. get dispersion() {
  14226. return this._dispersion;
  14227. }
  14228. set dispersion( value ) {
  14229. if ( this._dispersion > 0 !== value > 0 ) {
  14230. this.version ++;
  14231. }
  14232. this._dispersion = value;
  14233. }
  14234. get sheen() {
  14235. return this._sheen;
  14236. }
  14237. set sheen( value ) {
  14238. if ( this._sheen > 0 !== value > 0 ) {
  14239. this.version ++;
  14240. }
  14241. this._sheen = value;
  14242. }
  14243. get transmission() {
  14244. return this._transmission;
  14245. }
  14246. set transmission( value ) {
  14247. if ( this._transmission > 0 !== value > 0 ) {
  14248. this.version ++;
  14249. }
  14250. this._transmission = value;
  14251. }
  14252. copy( source ) {
  14253. super.copy( source );
  14254. this.defines = {
  14255. 'STANDARD': '',
  14256. 'PHYSICAL': ''
  14257. };
  14258. this.anisotropy = source.anisotropy;
  14259. this.anisotropyRotation = source.anisotropyRotation;
  14260. this.anisotropyMap = source.anisotropyMap;
  14261. this.clearcoat = source.clearcoat;
  14262. this.clearcoatMap = source.clearcoatMap;
  14263. this.clearcoatRoughness = source.clearcoatRoughness;
  14264. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  14265. this.clearcoatNormalMap = source.clearcoatNormalMap;
  14266. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  14267. this.dispersion = source.dispersion;
  14268. this.ior = source.ior;
  14269. this.iridescence = source.iridescence;
  14270. this.iridescenceMap = source.iridescenceMap;
  14271. this.iridescenceIOR = source.iridescenceIOR;
  14272. this.iridescenceThicknessRange = [ ...source.iridescenceThicknessRange ];
  14273. this.iridescenceThicknessMap = source.iridescenceThicknessMap;
  14274. this.sheen = source.sheen;
  14275. this.sheenColor.copy( source.sheenColor );
  14276. this.sheenColorMap = source.sheenColorMap;
  14277. this.sheenRoughness = source.sheenRoughness;
  14278. this.sheenRoughnessMap = source.sheenRoughnessMap;
  14279. this.transmission = source.transmission;
  14280. this.transmissionMap = source.transmissionMap;
  14281. this.thickness = source.thickness;
  14282. this.thicknessMap = source.thicknessMap;
  14283. this.attenuationDistance = source.attenuationDistance;
  14284. this.attenuationColor.copy( source.attenuationColor );
  14285. this.specularIntensity = source.specularIntensity;
  14286. this.specularIntensityMap = source.specularIntensityMap;
  14287. this.specularColor.copy( source.specularColor );
  14288. this.specularColorMap = source.specularColorMap;
  14289. return this;
  14290. }
  14291. }
  14292. class MeshPhongMaterial extends Material {
  14293. constructor( parameters ) {
  14294. super();
  14295. this.isMeshPhongMaterial = true;
  14296. this.type = 'MeshPhongMaterial';
  14297. this.color = new Color( 0xffffff ); // diffuse
  14298. this.specular = new Color( 0x111111 );
  14299. this.shininess = 30;
  14300. this.map = null;
  14301. this.lightMap = null;
  14302. this.lightMapIntensity = 1.0;
  14303. this.aoMap = null;
  14304. this.aoMapIntensity = 1.0;
  14305. this.emissive = new Color( 0x000000 );
  14306. this.emissiveIntensity = 1.0;
  14307. this.emissiveMap = null;
  14308. this.bumpMap = null;
  14309. this.bumpScale = 1;
  14310. this.normalMap = null;
  14311. this.normalMapType = TangentSpaceNormalMap;
  14312. this.normalScale = new Vector2( 1, 1 );
  14313. this.displacementMap = null;
  14314. this.displacementScale = 1;
  14315. this.displacementBias = 0;
  14316. this.specularMap = null;
  14317. this.alphaMap = null;
  14318. this.envMap = null;
  14319. this.envMapRotation = new Euler();
  14320. this.combine = MultiplyOperation;
  14321. this.reflectivity = 1;
  14322. this.refractionRatio = 0.98;
  14323. this.wireframe = false;
  14324. this.wireframeLinewidth = 1;
  14325. this.wireframeLinecap = 'round';
  14326. this.wireframeLinejoin = 'round';
  14327. this.flatShading = false;
  14328. this.fog = true;
  14329. this.setValues( parameters );
  14330. }
  14331. copy( source ) {
  14332. super.copy( source );
  14333. this.color.copy( source.color );
  14334. this.specular.copy( source.specular );
  14335. this.shininess = source.shininess;
  14336. this.map = source.map;
  14337. this.lightMap = source.lightMap;
  14338. this.lightMapIntensity = source.lightMapIntensity;
  14339. this.aoMap = source.aoMap;
  14340. this.aoMapIntensity = source.aoMapIntensity;
  14341. this.emissive.copy( source.emissive );
  14342. this.emissiveMap = source.emissiveMap;
  14343. this.emissiveIntensity = source.emissiveIntensity;
  14344. this.bumpMap = source.bumpMap;
  14345. this.bumpScale = source.bumpScale;
  14346. this.normalMap = source.normalMap;
  14347. this.normalMapType = source.normalMapType;
  14348. this.normalScale.copy( source.normalScale );
  14349. this.displacementMap = source.displacementMap;
  14350. this.displacementScale = source.displacementScale;
  14351. this.displacementBias = source.displacementBias;
  14352. this.specularMap = source.specularMap;
  14353. this.alphaMap = source.alphaMap;
  14354. this.envMap = source.envMap;
  14355. this.envMapRotation.copy( source.envMapRotation );
  14356. this.combine = source.combine;
  14357. this.reflectivity = source.reflectivity;
  14358. this.refractionRatio = source.refractionRatio;
  14359. this.wireframe = source.wireframe;
  14360. this.wireframeLinewidth = source.wireframeLinewidth;
  14361. this.wireframeLinecap = source.wireframeLinecap;
  14362. this.wireframeLinejoin = source.wireframeLinejoin;
  14363. this.flatShading = source.flatShading;
  14364. this.fog = source.fog;
  14365. return this;
  14366. }
  14367. }
  14368. class MeshToonMaterial extends Material {
  14369. constructor( parameters ) {
  14370. super();
  14371. this.isMeshToonMaterial = true;
  14372. this.defines = { 'TOON': '' };
  14373. this.type = 'MeshToonMaterial';
  14374. this.color = new Color( 0xffffff );
  14375. this.map = null;
  14376. this.gradientMap = null;
  14377. this.lightMap = null;
  14378. this.lightMapIntensity = 1.0;
  14379. this.aoMap = null;
  14380. this.aoMapIntensity = 1.0;
  14381. this.emissive = new Color( 0x000000 );
  14382. this.emissiveIntensity = 1.0;
  14383. this.emissiveMap = null;
  14384. this.bumpMap = null;
  14385. this.bumpScale = 1;
  14386. this.normalMap = null;
  14387. this.normalMapType = TangentSpaceNormalMap;
  14388. this.normalScale = new Vector2( 1, 1 );
  14389. this.displacementMap = null;
  14390. this.displacementScale = 1;
  14391. this.displacementBias = 0;
  14392. this.alphaMap = null;
  14393. this.wireframe = false;
  14394. this.wireframeLinewidth = 1;
  14395. this.wireframeLinecap = 'round';
  14396. this.wireframeLinejoin = 'round';
  14397. this.fog = true;
  14398. this.setValues( parameters );
  14399. }
  14400. copy( source ) {
  14401. super.copy( source );
  14402. this.color.copy( source.color );
  14403. this.map = source.map;
  14404. this.gradientMap = source.gradientMap;
  14405. this.lightMap = source.lightMap;
  14406. this.lightMapIntensity = source.lightMapIntensity;
  14407. this.aoMap = source.aoMap;
  14408. this.aoMapIntensity = source.aoMapIntensity;
  14409. this.emissive.copy( source.emissive );
  14410. this.emissiveMap = source.emissiveMap;
  14411. this.emissiveIntensity = source.emissiveIntensity;
  14412. this.bumpMap = source.bumpMap;
  14413. this.bumpScale = source.bumpScale;
  14414. this.normalMap = source.normalMap;
  14415. this.normalMapType = source.normalMapType;
  14416. this.normalScale.copy( source.normalScale );
  14417. this.displacementMap = source.displacementMap;
  14418. this.displacementScale = source.displacementScale;
  14419. this.displacementBias = source.displacementBias;
  14420. this.alphaMap = source.alphaMap;
  14421. this.wireframe = source.wireframe;
  14422. this.wireframeLinewidth = source.wireframeLinewidth;
  14423. this.wireframeLinecap = source.wireframeLinecap;
  14424. this.wireframeLinejoin = source.wireframeLinejoin;
  14425. this.fog = source.fog;
  14426. return this;
  14427. }
  14428. }
  14429. class MeshNormalMaterial extends Material {
  14430. constructor( parameters ) {
  14431. super();
  14432. this.isMeshNormalMaterial = true;
  14433. this.type = 'MeshNormalMaterial';
  14434. this.bumpMap = null;
  14435. this.bumpScale = 1;
  14436. this.normalMap = null;
  14437. this.normalMapType = TangentSpaceNormalMap;
  14438. this.normalScale = new Vector2( 1, 1 );
  14439. this.displacementMap = null;
  14440. this.displacementScale = 1;
  14441. this.displacementBias = 0;
  14442. this.wireframe = false;
  14443. this.wireframeLinewidth = 1;
  14444. this.flatShading = false;
  14445. this.setValues( parameters );
  14446. }
  14447. copy( source ) {
  14448. super.copy( source );
  14449. this.bumpMap = source.bumpMap;
  14450. this.bumpScale = source.bumpScale;
  14451. this.normalMap = source.normalMap;
  14452. this.normalMapType = source.normalMapType;
  14453. this.normalScale.copy( source.normalScale );
  14454. this.displacementMap = source.displacementMap;
  14455. this.displacementScale = source.displacementScale;
  14456. this.displacementBias = source.displacementBias;
  14457. this.wireframe = source.wireframe;
  14458. this.wireframeLinewidth = source.wireframeLinewidth;
  14459. this.flatShading = source.flatShading;
  14460. return this;
  14461. }
  14462. }
  14463. class MeshLambertMaterial extends Material {
  14464. constructor( parameters ) {
  14465. super();
  14466. this.isMeshLambertMaterial = true;
  14467. this.type = 'MeshLambertMaterial';
  14468. this.color = new Color( 0xffffff ); // diffuse
  14469. this.map = null;
  14470. this.lightMap = null;
  14471. this.lightMapIntensity = 1.0;
  14472. this.aoMap = null;
  14473. this.aoMapIntensity = 1.0;
  14474. this.emissive = new Color( 0x000000 );
  14475. this.emissiveIntensity = 1.0;
  14476. this.emissiveMap = null;
  14477. this.bumpMap = null;
  14478. this.bumpScale = 1;
  14479. this.normalMap = null;
  14480. this.normalMapType = TangentSpaceNormalMap;
  14481. this.normalScale = new Vector2( 1, 1 );
  14482. this.displacementMap = null;
  14483. this.displacementScale = 1;
  14484. this.displacementBias = 0;
  14485. this.specularMap = null;
  14486. this.alphaMap = null;
  14487. this.envMap = null;
  14488. this.envMapRotation = new Euler();
  14489. this.combine = MultiplyOperation;
  14490. this.reflectivity = 1;
  14491. this.refractionRatio = 0.98;
  14492. this.wireframe = false;
  14493. this.wireframeLinewidth = 1;
  14494. this.wireframeLinecap = 'round';
  14495. this.wireframeLinejoin = 'round';
  14496. this.flatShading = false;
  14497. this.fog = true;
  14498. this.setValues( parameters );
  14499. }
  14500. copy( source ) {
  14501. super.copy( source );
  14502. this.color.copy( source.color );
  14503. this.map = source.map;
  14504. this.lightMap = source.lightMap;
  14505. this.lightMapIntensity = source.lightMapIntensity;
  14506. this.aoMap = source.aoMap;
  14507. this.aoMapIntensity = source.aoMapIntensity;
  14508. this.emissive.copy( source.emissive );
  14509. this.emissiveMap = source.emissiveMap;
  14510. this.emissiveIntensity = source.emissiveIntensity;
  14511. this.bumpMap = source.bumpMap;
  14512. this.bumpScale = source.bumpScale;
  14513. this.normalMap = source.normalMap;
  14514. this.normalMapType = source.normalMapType;
  14515. this.normalScale.copy( source.normalScale );
  14516. this.displacementMap = source.displacementMap;
  14517. this.displacementScale = source.displacementScale;
  14518. this.displacementBias = source.displacementBias;
  14519. this.specularMap = source.specularMap;
  14520. this.alphaMap = source.alphaMap;
  14521. this.envMap = source.envMap;
  14522. this.envMapRotation.copy( source.envMapRotation );
  14523. this.combine = source.combine;
  14524. this.reflectivity = source.reflectivity;
  14525. this.refractionRatio = source.refractionRatio;
  14526. this.wireframe = source.wireframe;
  14527. this.wireframeLinewidth = source.wireframeLinewidth;
  14528. this.wireframeLinecap = source.wireframeLinecap;
  14529. this.wireframeLinejoin = source.wireframeLinejoin;
  14530. this.flatShading = source.flatShading;
  14531. this.fog = source.fog;
  14532. return this;
  14533. }
  14534. }
  14535. class MeshDepthMaterial extends Material {
  14536. constructor( parameters ) {
  14537. super();
  14538. this.isMeshDepthMaterial = true;
  14539. this.type = 'MeshDepthMaterial';
  14540. this.depthPacking = BasicDepthPacking;
  14541. this.map = null;
  14542. this.alphaMap = null;
  14543. this.displacementMap = null;
  14544. this.displacementScale = 1;
  14545. this.displacementBias = 0;
  14546. this.wireframe = false;
  14547. this.wireframeLinewidth = 1;
  14548. this.setValues( parameters );
  14549. }
  14550. copy( source ) {
  14551. super.copy( source );
  14552. this.depthPacking = source.depthPacking;
  14553. this.map = source.map;
  14554. this.alphaMap = source.alphaMap;
  14555. this.displacementMap = source.displacementMap;
  14556. this.displacementScale = source.displacementScale;
  14557. this.displacementBias = source.displacementBias;
  14558. this.wireframe = source.wireframe;
  14559. this.wireframeLinewidth = source.wireframeLinewidth;
  14560. return this;
  14561. }
  14562. }
  14563. class MeshDistanceMaterial extends Material {
  14564. constructor( parameters ) {
  14565. super();
  14566. this.isMeshDistanceMaterial = true;
  14567. this.type = 'MeshDistanceMaterial';
  14568. this.map = null;
  14569. this.alphaMap = null;
  14570. this.displacementMap = null;
  14571. this.displacementScale = 1;
  14572. this.displacementBias = 0;
  14573. this.setValues( parameters );
  14574. }
  14575. copy( source ) {
  14576. super.copy( source );
  14577. this.map = source.map;
  14578. this.alphaMap = source.alphaMap;
  14579. this.displacementMap = source.displacementMap;
  14580. this.displacementScale = source.displacementScale;
  14581. this.displacementBias = source.displacementBias;
  14582. return this;
  14583. }
  14584. }
  14585. class MeshMatcapMaterial extends Material {
  14586. constructor( parameters ) {
  14587. super();
  14588. this.isMeshMatcapMaterial = true;
  14589. this.defines = { 'MATCAP': '' };
  14590. this.type = 'MeshMatcapMaterial';
  14591. this.color = new Color( 0xffffff ); // diffuse
  14592. this.matcap = null;
  14593. this.map = null;
  14594. this.bumpMap = null;
  14595. this.bumpScale = 1;
  14596. this.normalMap = null;
  14597. this.normalMapType = TangentSpaceNormalMap;
  14598. this.normalScale = new Vector2( 1, 1 );
  14599. this.displacementMap = null;
  14600. this.displacementScale = 1;
  14601. this.displacementBias = 0;
  14602. this.alphaMap = null;
  14603. this.flatShading = false;
  14604. this.fog = true;
  14605. this.setValues( parameters );
  14606. }
  14607. copy( source ) {
  14608. super.copy( source );
  14609. this.defines = { 'MATCAP': '' };
  14610. this.color.copy( source.color );
  14611. this.matcap = source.matcap;
  14612. this.map = source.map;
  14613. this.bumpMap = source.bumpMap;
  14614. this.bumpScale = source.bumpScale;
  14615. this.normalMap = source.normalMap;
  14616. this.normalMapType = source.normalMapType;
  14617. this.normalScale.copy( source.normalScale );
  14618. this.displacementMap = source.displacementMap;
  14619. this.displacementScale = source.displacementScale;
  14620. this.displacementBias = source.displacementBias;
  14621. this.alphaMap = source.alphaMap;
  14622. this.flatShading = source.flatShading;
  14623. this.fog = source.fog;
  14624. return this;
  14625. }
  14626. }
  14627. class LineDashedMaterial extends LineBasicMaterial {
  14628. constructor( parameters ) {
  14629. super();
  14630. this.isLineDashedMaterial = true;
  14631. this.type = 'LineDashedMaterial';
  14632. this.scale = 1;
  14633. this.dashSize = 3;
  14634. this.gapSize = 1;
  14635. this.setValues( parameters );
  14636. }
  14637. copy( source ) {
  14638. super.copy( source );
  14639. this.scale = source.scale;
  14640. this.dashSize = source.dashSize;
  14641. this.gapSize = source.gapSize;
  14642. return this;
  14643. }
  14644. }
  14645. // converts an array to a specific type
  14646. function convertArray( array, type, forceClone ) {
  14647. if ( ! array || // let 'undefined' and 'null' pass
  14648. ! forceClone && array.constructor === type ) return array;
  14649. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  14650. return new type( array ); // create typed array
  14651. }
  14652. return Array.prototype.slice.call( array ); // create Array
  14653. }
  14654. function isTypedArray( object ) {
  14655. return ArrayBuffer.isView( object ) &&
  14656. ! ( object instanceof DataView );
  14657. }
  14658. // returns an array by which times and values can be sorted
  14659. function getKeyframeOrder( times ) {
  14660. function compareTime( i, j ) {
  14661. return times[ i ] - times[ j ];
  14662. }
  14663. const n = times.length;
  14664. const result = new Array( n );
  14665. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  14666. result.sort( compareTime );
  14667. return result;
  14668. }
  14669. // uses the array previously returned by 'getKeyframeOrder' to sort data
  14670. function sortedArray( values, stride, order ) {
  14671. const nValues = values.length;
  14672. const result = new values.constructor( nValues );
  14673. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  14674. const srcOffset = order[ i ] * stride;
  14675. for ( let j = 0; j !== stride; ++ j ) {
  14676. result[ dstOffset ++ ] = values[ srcOffset + j ];
  14677. }
  14678. }
  14679. return result;
  14680. }
  14681. // function for parsing AOS keyframe formats
  14682. function flattenJSON( jsonKeys, times, values, valuePropertyName ) {
  14683. let i = 1, key = jsonKeys[ 0 ];
  14684. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  14685. key = jsonKeys[ i ++ ];
  14686. }
  14687. if ( key === undefined ) return; // no data
  14688. let value = key[ valuePropertyName ];
  14689. if ( value === undefined ) return; // no data
  14690. if ( Array.isArray( value ) ) {
  14691. do {
  14692. value = key[ valuePropertyName ];
  14693. if ( value !== undefined ) {
  14694. times.push( key.time );
  14695. values.push.apply( values, value ); // push all elements
  14696. }
  14697. key = jsonKeys[ i ++ ];
  14698. } while ( key !== undefined );
  14699. } else if ( value.toArray !== undefined ) {
  14700. // ...assume THREE.Math-ish
  14701. do {
  14702. value = key[ valuePropertyName ];
  14703. if ( value !== undefined ) {
  14704. times.push( key.time );
  14705. value.toArray( values, values.length );
  14706. }
  14707. key = jsonKeys[ i ++ ];
  14708. } while ( key !== undefined );
  14709. } else {
  14710. // otherwise push as-is
  14711. do {
  14712. value = key[ valuePropertyName ];
  14713. if ( value !== undefined ) {
  14714. times.push( key.time );
  14715. values.push( value );
  14716. }
  14717. key = jsonKeys[ i ++ ];
  14718. } while ( key !== undefined );
  14719. }
  14720. }
  14721. function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  14722. const clip = sourceClip.clone();
  14723. clip.name = name;
  14724. const tracks = [];
  14725. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14726. const track = clip.tracks[ i ];
  14727. const valueSize = track.getValueSize();
  14728. const times = [];
  14729. const values = [];
  14730. for ( let j = 0; j < track.times.length; ++ j ) {
  14731. const frame = track.times[ j ] * fps;
  14732. if ( frame < startFrame || frame >= endFrame ) continue;
  14733. times.push( track.times[ j ] );
  14734. for ( let k = 0; k < valueSize; ++ k ) {
  14735. values.push( track.values[ j * valueSize + k ] );
  14736. }
  14737. }
  14738. if ( times.length === 0 ) continue;
  14739. track.times = convertArray( times, track.times.constructor );
  14740. track.values = convertArray( values, track.values.constructor );
  14741. tracks.push( track );
  14742. }
  14743. clip.tracks = tracks;
  14744. // find minimum .times value across all tracks in the trimmed clip
  14745. let minStartTime = Infinity;
  14746. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14747. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  14748. minStartTime = clip.tracks[ i ].times[ 0 ];
  14749. }
  14750. }
  14751. // shift all tracks such that clip begins at t=0
  14752. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14753. clip.tracks[ i ].shift( - 1 * minStartTime );
  14754. }
  14755. clip.resetDuration();
  14756. return clip;
  14757. }
  14758. function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  14759. if ( fps <= 0 ) fps = 30;
  14760. const numTracks = referenceClip.tracks.length;
  14761. const referenceTime = referenceFrame / fps;
  14762. // Make each track's values relative to the values at the reference frame
  14763. for ( let i = 0; i < numTracks; ++ i ) {
  14764. const referenceTrack = referenceClip.tracks[ i ];
  14765. const referenceTrackType = referenceTrack.ValueTypeName;
  14766. // Skip this track if it's non-numeric
  14767. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  14768. // Find the track in the target clip whose name and type matches the reference track
  14769. const targetTrack = targetClip.tracks.find( function ( track ) {
  14770. return track.name === referenceTrack.name
  14771. && track.ValueTypeName === referenceTrackType;
  14772. } );
  14773. if ( targetTrack === undefined ) continue;
  14774. let referenceOffset = 0;
  14775. const referenceValueSize = referenceTrack.getValueSize();
  14776. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14777. referenceOffset = referenceValueSize / 3;
  14778. }
  14779. let targetOffset = 0;
  14780. const targetValueSize = targetTrack.getValueSize();
  14781. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14782. targetOffset = targetValueSize / 3;
  14783. }
  14784. const lastIndex = referenceTrack.times.length - 1;
  14785. let referenceValue;
  14786. // Find the value to subtract out of the track
  14787. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  14788. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  14789. const startIndex = referenceOffset;
  14790. const endIndex = referenceValueSize - referenceOffset;
  14791. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14792. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  14793. // Reference frame is after the last keyframe, so just use the last keyframe
  14794. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  14795. const endIndex = startIndex + referenceValueSize - referenceOffset;
  14796. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14797. } else {
  14798. // Interpolate to the reference value
  14799. const interpolant = referenceTrack.createInterpolant();
  14800. const startIndex = referenceOffset;
  14801. const endIndex = referenceValueSize - referenceOffset;
  14802. interpolant.evaluate( referenceTime );
  14803. referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );
  14804. }
  14805. // Conjugate the quaternion
  14806. if ( referenceTrackType === 'quaternion' ) {
  14807. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  14808. referenceQuat.toArray( referenceValue );
  14809. }
  14810. // Subtract the reference value from all of the track values
  14811. const numTimes = targetTrack.times.length;
  14812. for ( let j = 0; j < numTimes; ++ j ) {
  14813. const valueStart = j * targetValueSize + targetOffset;
  14814. if ( referenceTrackType === 'quaternion' ) {
  14815. // Multiply the conjugate for quaternion track types
  14816. Quaternion.multiplyQuaternionsFlat(
  14817. targetTrack.values,
  14818. valueStart,
  14819. referenceValue,
  14820. 0,
  14821. targetTrack.values,
  14822. valueStart
  14823. );
  14824. } else {
  14825. const valueEnd = targetValueSize - targetOffset * 2;
  14826. // Subtract each value for all other numeric track types
  14827. for ( let k = 0; k < valueEnd; ++ k ) {
  14828. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  14829. }
  14830. }
  14831. }
  14832. }
  14833. targetClip.blendMode = AdditiveAnimationBlendMode;
  14834. return targetClip;
  14835. }
  14836. const AnimationUtils = {
  14837. convertArray: convertArray,
  14838. isTypedArray: isTypedArray,
  14839. getKeyframeOrder: getKeyframeOrder,
  14840. sortedArray: sortedArray,
  14841. flattenJSON: flattenJSON,
  14842. subclip: subclip,
  14843. makeClipAdditive: makeClipAdditive
  14844. };
  14845. /**
  14846. * Abstract base class of interpolants over parametric samples.
  14847. *
  14848. * The parameter domain is one dimensional, typically the time or a path
  14849. * along a curve defined by the data.
  14850. *
  14851. * The sample values can have any dimensionality and derived classes may
  14852. * apply special interpretations to the data.
  14853. *
  14854. * This class provides the interval seek in a Template Method, deferring
  14855. * the actual interpolation to derived classes.
  14856. *
  14857. * Time complexity is O(1) for linear access crossing at most two points
  14858. * and O(log N) for random access, where N is the number of positions.
  14859. *
  14860. * References:
  14861. *
  14862. * http://www.oodesign.com/template-method-pattern.html
  14863. *
  14864. */
  14865. class Interpolant {
  14866. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  14867. this.parameterPositions = parameterPositions;
  14868. this._cachedIndex = 0;
  14869. this.resultBuffer = resultBuffer !== undefined ?
  14870. resultBuffer : new sampleValues.constructor( sampleSize );
  14871. this.sampleValues = sampleValues;
  14872. this.valueSize = sampleSize;
  14873. this.settings = null;
  14874. this.DefaultSettings_ = {};
  14875. }
  14876. evaluate( t ) {
  14877. const pp = this.parameterPositions;
  14878. let i1 = this._cachedIndex,
  14879. t1 = pp[ i1 ],
  14880. t0 = pp[ i1 - 1 ];
  14881. validate_interval: {
  14882. seek: {
  14883. let right;
  14884. linear_scan: {
  14885. //- See http://jsperf.com/comparison-to-undefined/3
  14886. //- slower code:
  14887. //-
  14888. //- if ( t >= t1 || t1 === undefined ) {
  14889. forward_scan: if ( ! ( t < t1 ) ) {
  14890. for ( let giveUpAt = i1 + 2; ; ) {
  14891. if ( t1 === undefined ) {
  14892. if ( t < t0 ) break forward_scan;
  14893. // after end
  14894. i1 = pp.length;
  14895. this._cachedIndex = i1;
  14896. return this.copySampleValue_( i1 - 1 );
  14897. }
  14898. if ( i1 === giveUpAt ) break; // this loop
  14899. t0 = t1;
  14900. t1 = pp[ ++ i1 ];
  14901. if ( t < t1 ) {
  14902. // we have arrived at the sought interval
  14903. break seek;
  14904. }
  14905. }
  14906. // prepare binary search on the right side of the index
  14907. right = pp.length;
  14908. break linear_scan;
  14909. }
  14910. //- slower code:
  14911. //- if ( t < t0 || t0 === undefined ) {
  14912. if ( ! ( t >= t0 ) ) {
  14913. // looping?
  14914. const t1global = pp[ 1 ];
  14915. if ( t < t1global ) {
  14916. i1 = 2; // + 1, using the scan for the details
  14917. t0 = t1global;
  14918. }
  14919. // linear reverse scan
  14920. for ( let giveUpAt = i1 - 2; ; ) {
  14921. if ( t0 === undefined ) {
  14922. // before start
  14923. this._cachedIndex = 0;
  14924. return this.copySampleValue_( 0 );
  14925. }
  14926. if ( i1 === giveUpAt ) break; // this loop
  14927. t1 = t0;
  14928. t0 = pp[ -- i1 - 1 ];
  14929. if ( t >= t0 ) {
  14930. // we have arrived at the sought interval
  14931. break seek;
  14932. }
  14933. }
  14934. // prepare binary search on the left side of the index
  14935. right = i1;
  14936. i1 = 0;
  14937. break linear_scan;
  14938. }
  14939. // the interval is valid
  14940. break validate_interval;
  14941. } // linear scan
  14942. // binary search
  14943. while ( i1 < right ) {
  14944. const mid = ( i1 + right ) >>> 1;
  14945. if ( t < pp[ mid ] ) {
  14946. right = mid;
  14947. } else {
  14948. i1 = mid + 1;
  14949. }
  14950. }
  14951. t1 = pp[ i1 ];
  14952. t0 = pp[ i1 - 1 ];
  14953. // check boundary cases, again
  14954. if ( t0 === undefined ) {
  14955. this._cachedIndex = 0;
  14956. return this.copySampleValue_( 0 );
  14957. }
  14958. if ( t1 === undefined ) {
  14959. i1 = pp.length;
  14960. this._cachedIndex = i1;
  14961. return this.copySampleValue_( i1 - 1 );
  14962. }
  14963. } // seek
  14964. this._cachedIndex = i1;
  14965. this.intervalChanged_( i1, t0, t1 );
  14966. } // validate_interval
  14967. return this.interpolate_( i1, t0, t, t1 );
  14968. }
  14969. getSettings_() {
  14970. return this.settings || this.DefaultSettings_;
  14971. }
  14972. copySampleValue_( index ) {
  14973. // copies a sample value to the result buffer
  14974. const result = this.resultBuffer,
  14975. values = this.sampleValues,
  14976. stride = this.valueSize,
  14977. offset = index * stride;
  14978. for ( let i = 0; i !== stride; ++ i ) {
  14979. result[ i ] = values[ offset + i ];
  14980. }
  14981. return result;
  14982. }
  14983. // Template methods for derived classes:
  14984. interpolate_( /* i1, t0, t, t1 */ ) {
  14985. throw new Error( 'call to abstract method' );
  14986. // implementations shall return this.resultBuffer
  14987. }
  14988. intervalChanged_( /* i1, t0, t1 */ ) {
  14989. // empty
  14990. }
  14991. }
  14992. /**
  14993. * Fast and simple cubic spline interpolant.
  14994. *
  14995. * It was derived from a Hermitian construction setting the first derivative
  14996. * at each sample position to the linear slope between neighboring positions
  14997. * over their parameter interval.
  14998. */
  14999. class CubicInterpolant extends Interpolant {
  15000. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15001. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15002. this._weightPrev = - 0;
  15003. this._offsetPrev = - 0;
  15004. this._weightNext = - 0;
  15005. this._offsetNext = - 0;
  15006. this.DefaultSettings_ = {
  15007. endingStart: ZeroCurvatureEnding,
  15008. endingEnd: ZeroCurvatureEnding
  15009. };
  15010. }
  15011. intervalChanged_( i1, t0, t1 ) {
  15012. const pp = this.parameterPositions;
  15013. let iPrev = i1 - 2,
  15014. iNext = i1 + 1,
  15015. tPrev = pp[ iPrev ],
  15016. tNext = pp[ iNext ];
  15017. if ( tPrev === undefined ) {
  15018. switch ( this.getSettings_().endingStart ) {
  15019. case ZeroSlopeEnding:
  15020. // f'(t0) = 0
  15021. iPrev = i1;
  15022. tPrev = 2 * t0 - t1;
  15023. break;
  15024. case WrapAroundEnding:
  15025. // use the other end of the curve
  15026. iPrev = pp.length - 2;
  15027. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  15028. break;
  15029. default: // ZeroCurvatureEnding
  15030. // f''(t0) = 0 a.k.a. Natural Spline
  15031. iPrev = i1;
  15032. tPrev = t1;
  15033. }
  15034. }
  15035. if ( tNext === undefined ) {
  15036. switch ( this.getSettings_().endingEnd ) {
  15037. case ZeroSlopeEnding:
  15038. // f'(tN) = 0
  15039. iNext = i1;
  15040. tNext = 2 * t1 - t0;
  15041. break;
  15042. case WrapAroundEnding:
  15043. // use the other end of the curve
  15044. iNext = 1;
  15045. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  15046. break;
  15047. default: // ZeroCurvatureEnding
  15048. // f''(tN) = 0, a.k.a. Natural Spline
  15049. iNext = i1 - 1;
  15050. tNext = t0;
  15051. }
  15052. }
  15053. const halfDt = ( t1 - t0 ) * 0.5,
  15054. stride = this.valueSize;
  15055. this._weightPrev = halfDt / ( t0 - tPrev );
  15056. this._weightNext = halfDt / ( tNext - t1 );
  15057. this._offsetPrev = iPrev * stride;
  15058. this._offsetNext = iNext * stride;
  15059. }
  15060. interpolate_( i1, t0, t, t1 ) {
  15061. const result = this.resultBuffer,
  15062. values = this.sampleValues,
  15063. stride = this.valueSize,
  15064. o1 = i1 * stride, o0 = o1 - stride,
  15065. oP = this._offsetPrev, oN = this._offsetNext,
  15066. wP = this._weightPrev, wN = this._weightNext,
  15067. p = ( t - t0 ) / ( t1 - t0 ),
  15068. pp = p * p,
  15069. ppp = pp * p;
  15070. // evaluate polynomials
  15071. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  15072. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  15073. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  15074. const sN = wN * ppp - wN * pp;
  15075. // combine data linearly
  15076. for ( let i = 0; i !== stride; ++ i ) {
  15077. result[ i ] =
  15078. sP * values[ oP + i ] +
  15079. s0 * values[ o0 + i ] +
  15080. s1 * values[ o1 + i ] +
  15081. sN * values[ oN + i ];
  15082. }
  15083. return result;
  15084. }
  15085. }
  15086. class LinearInterpolant extends Interpolant {
  15087. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15088. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15089. }
  15090. interpolate_( i1, t0, t, t1 ) {
  15091. const result = this.resultBuffer,
  15092. values = this.sampleValues,
  15093. stride = this.valueSize,
  15094. offset1 = i1 * stride,
  15095. offset0 = offset1 - stride,
  15096. weight1 = ( t - t0 ) / ( t1 - t0 ),
  15097. weight0 = 1 - weight1;
  15098. for ( let i = 0; i !== stride; ++ i ) {
  15099. result[ i ] =
  15100. values[ offset0 + i ] * weight0 +
  15101. values[ offset1 + i ] * weight1;
  15102. }
  15103. return result;
  15104. }
  15105. }
  15106. /**
  15107. *
  15108. * Interpolant that evaluates to the sample value at the position preceding
  15109. * the parameter.
  15110. */
  15111. class DiscreteInterpolant extends Interpolant {
  15112. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15113. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15114. }
  15115. interpolate_( i1 /*, t0, t, t1 */ ) {
  15116. return this.copySampleValue_( i1 - 1 );
  15117. }
  15118. }
  15119. class KeyframeTrack {
  15120. constructor( name, times, values, interpolation ) {
  15121. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  15122. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  15123. this.name = name;
  15124. this.times = convertArray( times, this.TimeBufferType );
  15125. this.values = convertArray( values, this.ValueBufferType );
  15126. this.setInterpolation( interpolation || this.DefaultInterpolation );
  15127. }
  15128. // Serialization (in static context, because of constructor invocation
  15129. // and automatic invocation of .toJSON):
  15130. static toJSON( track ) {
  15131. const trackType = track.constructor;
  15132. let json;
  15133. // derived classes can define a static toJSON method
  15134. if ( trackType.toJSON !== this.toJSON ) {
  15135. json = trackType.toJSON( track );
  15136. } else {
  15137. // by default, we assume the data can be serialized as-is
  15138. json = {
  15139. 'name': track.name,
  15140. 'times': convertArray( track.times, Array ),
  15141. 'values': convertArray( track.values, Array )
  15142. };
  15143. const interpolation = track.getInterpolation();
  15144. if ( interpolation !== track.DefaultInterpolation ) {
  15145. json.interpolation = interpolation;
  15146. }
  15147. }
  15148. json.type = track.ValueTypeName; // mandatory
  15149. return json;
  15150. }
  15151. InterpolantFactoryMethodDiscrete( result ) {
  15152. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  15153. }
  15154. InterpolantFactoryMethodLinear( result ) {
  15155. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15156. }
  15157. InterpolantFactoryMethodSmooth( result ) {
  15158. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  15159. }
  15160. setInterpolation( interpolation ) {
  15161. let factoryMethod;
  15162. switch ( interpolation ) {
  15163. case InterpolateDiscrete:
  15164. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  15165. break;
  15166. case InterpolateLinear:
  15167. factoryMethod = this.InterpolantFactoryMethodLinear;
  15168. break;
  15169. case InterpolateSmooth:
  15170. factoryMethod = this.InterpolantFactoryMethodSmooth;
  15171. break;
  15172. }
  15173. if ( factoryMethod === undefined ) {
  15174. const message = 'unsupported interpolation for ' +
  15175. this.ValueTypeName + ' keyframe track named ' + this.name;
  15176. if ( this.createInterpolant === undefined ) {
  15177. // fall back to default, unless the default itself is messed up
  15178. if ( interpolation !== this.DefaultInterpolation ) {
  15179. this.setInterpolation( this.DefaultInterpolation );
  15180. } else {
  15181. throw new Error( message ); // fatal, in this case
  15182. }
  15183. }
  15184. console.warn( 'THREE.KeyframeTrack:', message );
  15185. return this;
  15186. }
  15187. this.createInterpolant = factoryMethod;
  15188. return this;
  15189. }
  15190. getInterpolation() {
  15191. switch ( this.createInterpolant ) {
  15192. case this.InterpolantFactoryMethodDiscrete:
  15193. return InterpolateDiscrete;
  15194. case this.InterpolantFactoryMethodLinear:
  15195. return InterpolateLinear;
  15196. case this.InterpolantFactoryMethodSmooth:
  15197. return InterpolateSmooth;
  15198. }
  15199. }
  15200. getValueSize() {
  15201. return this.values.length / this.times.length;
  15202. }
  15203. // move all keyframes either forwards or backwards in time
  15204. shift( timeOffset ) {
  15205. if ( timeOffset !== 0.0 ) {
  15206. const times = this.times;
  15207. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15208. times[ i ] += timeOffset;
  15209. }
  15210. }
  15211. return this;
  15212. }
  15213. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  15214. scale( timeScale ) {
  15215. if ( timeScale !== 1.0 ) {
  15216. const times = this.times;
  15217. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15218. times[ i ] *= timeScale;
  15219. }
  15220. }
  15221. return this;
  15222. }
  15223. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  15224. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  15225. trim( startTime, endTime ) {
  15226. const times = this.times,
  15227. nKeys = times.length;
  15228. let from = 0,
  15229. to = nKeys - 1;
  15230. while ( from !== nKeys && times[ from ] < startTime ) {
  15231. ++ from;
  15232. }
  15233. while ( to !== - 1 && times[ to ] > endTime ) {
  15234. -- to;
  15235. }
  15236. ++ to; // inclusive -> exclusive bound
  15237. if ( from !== 0 || to !== nKeys ) {
  15238. // empty tracks are forbidden, so keep at least one keyframe
  15239. if ( from >= to ) {
  15240. to = Math.max( to, 1 );
  15241. from = to - 1;
  15242. }
  15243. const stride = this.getValueSize();
  15244. this.times = times.slice( from, to );
  15245. this.values = this.values.slice( from * stride, to * stride );
  15246. }
  15247. return this;
  15248. }
  15249. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  15250. validate() {
  15251. let valid = true;
  15252. const valueSize = this.getValueSize();
  15253. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  15254. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  15255. valid = false;
  15256. }
  15257. const times = this.times,
  15258. values = this.values,
  15259. nKeys = times.length;
  15260. if ( nKeys === 0 ) {
  15261. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  15262. valid = false;
  15263. }
  15264. let prevTime = null;
  15265. for ( let i = 0; i !== nKeys; i ++ ) {
  15266. const currTime = times[ i ];
  15267. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  15268. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  15269. valid = false;
  15270. break;
  15271. }
  15272. if ( prevTime !== null && prevTime > currTime ) {
  15273. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  15274. valid = false;
  15275. break;
  15276. }
  15277. prevTime = currTime;
  15278. }
  15279. if ( values !== undefined ) {
  15280. if ( isTypedArray( values ) ) {
  15281. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  15282. const value = values[ i ];
  15283. if ( isNaN( value ) ) {
  15284. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  15285. valid = false;
  15286. break;
  15287. }
  15288. }
  15289. }
  15290. }
  15291. return valid;
  15292. }
  15293. // removes equivalent sequential keys as common in morph target sequences
  15294. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  15295. optimize() {
  15296. // times or values may be shared with other tracks, so overwriting is unsafe
  15297. const times = this.times.slice(),
  15298. values = this.values.slice(),
  15299. stride = this.getValueSize(),
  15300. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  15301. lastIndex = times.length - 1;
  15302. let writeIndex = 1;
  15303. for ( let i = 1; i < lastIndex; ++ i ) {
  15304. let keep = false;
  15305. const time = times[ i ];
  15306. const timeNext = times[ i + 1 ];
  15307. // remove adjacent keyframes scheduled at the same time
  15308. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  15309. if ( ! smoothInterpolation ) {
  15310. // remove unnecessary keyframes same as their neighbors
  15311. const offset = i * stride,
  15312. offsetP = offset - stride,
  15313. offsetN = offset + stride;
  15314. for ( let j = 0; j !== stride; ++ j ) {
  15315. const value = values[ offset + j ];
  15316. if ( value !== values[ offsetP + j ] ||
  15317. value !== values[ offsetN + j ] ) {
  15318. keep = true;
  15319. break;
  15320. }
  15321. }
  15322. } else {
  15323. keep = true;
  15324. }
  15325. }
  15326. // in-place compaction
  15327. if ( keep ) {
  15328. if ( i !== writeIndex ) {
  15329. times[ writeIndex ] = times[ i ];
  15330. const readOffset = i * stride,
  15331. writeOffset = writeIndex * stride;
  15332. for ( let j = 0; j !== stride; ++ j ) {
  15333. values[ writeOffset + j ] = values[ readOffset + j ];
  15334. }
  15335. }
  15336. ++ writeIndex;
  15337. }
  15338. }
  15339. // flush last keyframe (compaction looks ahead)
  15340. if ( lastIndex > 0 ) {
  15341. times[ writeIndex ] = times[ lastIndex ];
  15342. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  15343. values[ writeOffset + j ] = values[ readOffset + j ];
  15344. }
  15345. ++ writeIndex;
  15346. }
  15347. if ( writeIndex !== times.length ) {
  15348. this.times = times.slice( 0, writeIndex );
  15349. this.values = values.slice( 0, writeIndex * stride );
  15350. } else {
  15351. this.times = times;
  15352. this.values = values;
  15353. }
  15354. return this;
  15355. }
  15356. clone() {
  15357. const times = this.times.slice();
  15358. const values = this.values.slice();
  15359. const TypedKeyframeTrack = this.constructor;
  15360. const track = new TypedKeyframeTrack( this.name, times, values );
  15361. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  15362. track.createInterpolant = this.createInterpolant;
  15363. return track;
  15364. }
  15365. }
  15366. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  15367. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  15368. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  15369. /**
  15370. * A Track of Boolean keyframe values.
  15371. */
  15372. class BooleanKeyframeTrack extends KeyframeTrack {
  15373. // No interpolation parameter because only InterpolateDiscrete is valid.
  15374. constructor( name, times, values ) {
  15375. super( name, times, values );
  15376. }
  15377. }
  15378. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  15379. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  15380. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15381. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15382. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15383. /**
  15384. * A Track of keyframe values that represent color.
  15385. */
  15386. class ColorKeyframeTrack extends KeyframeTrack {}
  15387. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  15388. /**
  15389. * A Track of numeric keyframe values.
  15390. */
  15391. class NumberKeyframeTrack extends KeyframeTrack {}
  15392. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  15393. /**
  15394. * Spherical linear unit quaternion interpolant.
  15395. */
  15396. class QuaternionLinearInterpolant extends Interpolant {
  15397. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15398. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15399. }
  15400. interpolate_( i1, t0, t, t1 ) {
  15401. const result = this.resultBuffer,
  15402. values = this.sampleValues,
  15403. stride = this.valueSize,
  15404. alpha = ( t - t0 ) / ( t1 - t0 );
  15405. let offset = i1 * stride;
  15406. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  15407. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  15408. }
  15409. return result;
  15410. }
  15411. }
  15412. /**
  15413. * A Track of quaternion keyframe values.
  15414. */
  15415. class QuaternionKeyframeTrack extends KeyframeTrack {
  15416. InterpolantFactoryMethodLinear( result ) {
  15417. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15418. }
  15419. }
  15420. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  15421. // ValueBufferType is inherited
  15422. // DefaultInterpolation is inherited;
  15423. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15424. /**
  15425. * A Track that interpolates Strings
  15426. */
  15427. class StringKeyframeTrack extends KeyframeTrack {
  15428. // No interpolation parameter because only InterpolateDiscrete is valid.
  15429. constructor( name, times, values ) {
  15430. super( name, times, values );
  15431. }
  15432. }
  15433. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  15434. StringKeyframeTrack.prototype.ValueBufferType = Array;
  15435. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15436. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15437. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15438. /**
  15439. * A Track of vectored keyframe values.
  15440. */
  15441. class VectorKeyframeTrack extends KeyframeTrack {}
  15442. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  15443. class AnimationClip {
  15444. constructor( name = '', duration = - 1, tracks = [], blendMode = NormalAnimationBlendMode ) {
  15445. this.name = name;
  15446. this.tracks = tracks;
  15447. this.duration = duration;
  15448. this.blendMode = blendMode;
  15449. this.uuid = generateUUID();
  15450. // this means it should figure out its duration by scanning the tracks
  15451. if ( this.duration < 0 ) {
  15452. this.resetDuration();
  15453. }
  15454. }
  15455. static parse( json ) {
  15456. const tracks = [],
  15457. jsonTracks = json.tracks,
  15458. frameTime = 1.0 / ( json.fps || 1.0 );
  15459. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  15460. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  15461. }
  15462. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  15463. clip.uuid = json.uuid;
  15464. return clip;
  15465. }
  15466. static toJSON( clip ) {
  15467. const tracks = [],
  15468. clipTracks = clip.tracks;
  15469. const json = {
  15470. 'name': clip.name,
  15471. 'duration': clip.duration,
  15472. 'tracks': tracks,
  15473. 'uuid': clip.uuid,
  15474. 'blendMode': clip.blendMode
  15475. };
  15476. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  15477. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  15478. }
  15479. return json;
  15480. }
  15481. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  15482. const numMorphTargets = morphTargetSequence.length;
  15483. const tracks = [];
  15484. for ( let i = 0; i < numMorphTargets; i ++ ) {
  15485. let times = [];
  15486. let values = [];
  15487. times.push(
  15488. ( i + numMorphTargets - 1 ) % numMorphTargets,
  15489. i,
  15490. ( i + 1 ) % numMorphTargets );
  15491. values.push( 0, 1, 0 );
  15492. const order = getKeyframeOrder( times );
  15493. times = sortedArray( times, 1, order );
  15494. values = sortedArray( values, 1, order );
  15495. // if there is a key at the first frame, duplicate it as the
  15496. // last frame as well for perfect loop.
  15497. if ( ! noLoop && times[ 0 ] === 0 ) {
  15498. times.push( numMorphTargets );
  15499. values.push( values[ 0 ] );
  15500. }
  15501. tracks.push(
  15502. new NumberKeyframeTrack(
  15503. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  15504. times, values
  15505. ).scale( 1.0 / fps ) );
  15506. }
  15507. return new this( name, - 1, tracks );
  15508. }
  15509. static findByName( objectOrClipArray, name ) {
  15510. let clipArray = objectOrClipArray;
  15511. if ( ! Array.isArray( objectOrClipArray ) ) {
  15512. const o = objectOrClipArray;
  15513. clipArray = o.geometry && o.geometry.animations || o.animations;
  15514. }
  15515. for ( let i = 0; i < clipArray.length; i ++ ) {
  15516. if ( clipArray[ i ].name === name ) {
  15517. return clipArray[ i ];
  15518. }
  15519. }
  15520. return null;
  15521. }
  15522. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  15523. const animationToMorphTargets = {};
  15524. // tested with https://regex101.com/ on trick sequences
  15525. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  15526. const pattern = /^([\w-]*?)([\d]+)$/;
  15527. // sort morph target names into animation groups based
  15528. // patterns like Walk_001, Walk_002, Run_001, Run_002
  15529. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  15530. const morphTarget = morphTargets[ i ];
  15531. const parts = morphTarget.name.match( pattern );
  15532. if ( parts && parts.length > 1 ) {
  15533. const name = parts[ 1 ];
  15534. let animationMorphTargets = animationToMorphTargets[ name ];
  15535. if ( ! animationMorphTargets ) {
  15536. animationToMorphTargets[ name ] = animationMorphTargets = [];
  15537. }
  15538. animationMorphTargets.push( morphTarget );
  15539. }
  15540. }
  15541. const clips = [];
  15542. for ( const name in animationToMorphTargets ) {
  15543. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  15544. }
  15545. return clips;
  15546. }
  15547. // parse the animation.hierarchy format
  15548. static parseAnimation( animation, bones ) {
  15549. if ( ! animation ) {
  15550. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  15551. return null;
  15552. }
  15553. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  15554. // only return track if there are actually keys.
  15555. if ( animationKeys.length !== 0 ) {
  15556. const times = [];
  15557. const values = [];
  15558. flattenJSON( animationKeys, times, values, propertyName );
  15559. // empty keys are filtered out, so check again
  15560. if ( times.length !== 0 ) {
  15561. destTracks.push( new trackType( trackName, times, values ) );
  15562. }
  15563. }
  15564. };
  15565. const tracks = [];
  15566. const clipName = animation.name || 'default';
  15567. const fps = animation.fps || 30;
  15568. const blendMode = animation.blendMode;
  15569. // automatic length determination in AnimationClip.
  15570. let duration = animation.length || - 1;
  15571. const hierarchyTracks = animation.hierarchy || [];
  15572. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  15573. const animationKeys = hierarchyTracks[ h ].keys;
  15574. // skip empty tracks
  15575. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  15576. // process morph targets
  15577. if ( animationKeys[ 0 ].morphTargets ) {
  15578. // figure out all morph targets used in this track
  15579. const morphTargetNames = {};
  15580. let k;
  15581. for ( k = 0; k < animationKeys.length; k ++ ) {
  15582. if ( animationKeys[ k ].morphTargets ) {
  15583. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  15584. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  15585. }
  15586. }
  15587. }
  15588. // create a track for each morph target with all zero
  15589. // morphTargetInfluences except for the keys in which
  15590. // the morphTarget is named.
  15591. for ( const morphTargetName in morphTargetNames ) {
  15592. const times = [];
  15593. const values = [];
  15594. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  15595. const animationKey = animationKeys[ k ];
  15596. times.push( animationKey.time );
  15597. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  15598. }
  15599. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  15600. }
  15601. duration = morphTargetNames.length * fps;
  15602. } else {
  15603. // ...assume skeletal animation
  15604. const boneName = '.bones[' + bones[ h ].name + ']';
  15605. addNonemptyTrack(
  15606. VectorKeyframeTrack, boneName + '.position',
  15607. animationKeys, 'pos', tracks );
  15608. addNonemptyTrack(
  15609. QuaternionKeyframeTrack, boneName + '.quaternion',
  15610. animationKeys, 'rot', tracks );
  15611. addNonemptyTrack(
  15612. VectorKeyframeTrack, boneName + '.scale',
  15613. animationKeys, 'scl', tracks );
  15614. }
  15615. }
  15616. if ( tracks.length === 0 ) {
  15617. return null;
  15618. }
  15619. const clip = new this( clipName, duration, tracks, blendMode );
  15620. return clip;
  15621. }
  15622. resetDuration() {
  15623. const tracks = this.tracks;
  15624. let duration = 0;
  15625. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  15626. const track = this.tracks[ i ];
  15627. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  15628. }
  15629. this.duration = duration;
  15630. return this;
  15631. }
  15632. trim() {
  15633. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15634. this.tracks[ i ].trim( 0, this.duration );
  15635. }
  15636. return this;
  15637. }
  15638. validate() {
  15639. let valid = true;
  15640. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15641. valid = valid && this.tracks[ i ].validate();
  15642. }
  15643. return valid;
  15644. }
  15645. optimize() {
  15646. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15647. this.tracks[ i ].optimize();
  15648. }
  15649. return this;
  15650. }
  15651. clone() {
  15652. const tracks = [];
  15653. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15654. tracks.push( this.tracks[ i ].clone() );
  15655. }
  15656. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  15657. }
  15658. toJSON() {
  15659. return this.constructor.toJSON( this );
  15660. }
  15661. }
  15662. function getTrackTypeForValueTypeName( typeName ) {
  15663. switch ( typeName.toLowerCase() ) {
  15664. case 'scalar':
  15665. case 'double':
  15666. case 'float':
  15667. case 'number':
  15668. case 'integer':
  15669. return NumberKeyframeTrack;
  15670. case 'vector':
  15671. case 'vector2':
  15672. case 'vector3':
  15673. case 'vector4':
  15674. return VectorKeyframeTrack;
  15675. case 'color':
  15676. return ColorKeyframeTrack;
  15677. case 'quaternion':
  15678. return QuaternionKeyframeTrack;
  15679. case 'bool':
  15680. case 'boolean':
  15681. return BooleanKeyframeTrack;
  15682. case 'string':
  15683. return StringKeyframeTrack;
  15684. }
  15685. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  15686. }
  15687. function parseKeyframeTrack( json ) {
  15688. if ( json.type === undefined ) {
  15689. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  15690. }
  15691. const trackType = getTrackTypeForValueTypeName( json.type );
  15692. if ( json.times === undefined ) {
  15693. const times = [], values = [];
  15694. flattenJSON( json.keys, times, values, 'value' );
  15695. json.times = times;
  15696. json.values = values;
  15697. }
  15698. // derived classes can define a static parse method
  15699. if ( trackType.parse !== undefined ) {
  15700. return trackType.parse( json );
  15701. } else {
  15702. // by default, we assume a constructor compatible with the base
  15703. return new trackType( json.name, json.times, json.values, json.interpolation );
  15704. }
  15705. }
  15706. const Cache = {
  15707. enabled: false,
  15708. files: {},
  15709. add: function ( key, file ) {
  15710. if ( this.enabled === false ) return;
  15711. // console.log( 'THREE.Cache', 'Adding key:', key );
  15712. this.files[ key ] = file;
  15713. },
  15714. get: function ( key ) {
  15715. if ( this.enabled === false ) return;
  15716. // console.log( 'THREE.Cache', 'Checking key:', key );
  15717. return this.files[ key ];
  15718. },
  15719. remove: function ( key ) {
  15720. delete this.files[ key ];
  15721. },
  15722. clear: function () {
  15723. this.files = {};
  15724. }
  15725. };
  15726. class LoadingManager {
  15727. constructor( onLoad, onProgress, onError ) {
  15728. const scope = this;
  15729. let isLoading = false;
  15730. let itemsLoaded = 0;
  15731. let itemsTotal = 0;
  15732. let urlModifier = undefined;
  15733. const handlers = [];
  15734. // Refer to #5689 for the reason why we don't set .onStart
  15735. // in the constructor
  15736. this.onStart = undefined;
  15737. this.onLoad = onLoad;
  15738. this.onProgress = onProgress;
  15739. this.onError = onError;
  15740. this.itemStart = function ( url ) {
  15741. itemsTotal ++;
  15742. if ( isLoading === false ) {
  15743. if ( scope.onStart !== undefined ) {
  15744. scope.onStart( url, itemsLoaded, itemsTotal );
  15745. }
  15746. }
  15747. isLoading = true;
  15748. };
  15749. this.itemEnd = function ( url ) {
  15750. itemsLoaded ++;
  15751. if ( scope.onProgress !== undefined ) {
  15752. scope.onProgress( url, itemsLoaded, itemsTotal );
  15753. }
  15754. if ( itemsLoaded === itemsTotal ) {
  15755. isLoading = false;
  15756. if ( scope.onLoad !== undefined ) {
  15757. scope.onLoad();
  15758. }
  15759. }
  15760. };
  15761. this.itemError = function ( url ) {
  15762. if ( scope.onError !== undefined ) {
  15763. scope.onError( url );
  15764. }
  15765. };
  15766. this.resolveURL = function ( url ) {
  15767. if ( urlModifier ) {
  15768. return urlModifier( url );
  15769. }
  15770. return url;
  15771. };
  15772. this.setURLModifier = function ( transform ) {
  15773. urlModifier = transform;
  15774. return this;
  15775. };
  15776. this.addHandler = function ( regex, loader ) {
  15777. handlers.push( regex, loader );
  15778. return this;
  15779. };
  15780. this.removeHandler = function ( regex ) {
  15781. const index = handlers.indexOf( regex );
  15782. if ( index !== - 1 ) {
  15783. handlers.splice( index, 2 );
  15784. }
  15785. return this;
  15786. };
  15787. this.getHandler = function ( file ) {
  15788. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  15789. const regex = handlers[ i ];
  15790. const loader = handlers[ i + 1 ];
  15791. if ( regex.global ) regex.lastIndex = 0; // see #17920
  15792. if ( regex.test( file ) ) {
  15793. return loader;
  15794. }
  15795. }
  15796. return null;
  15797. };
  15798. }
  15799. }
  15800. const DefaultLoadingManager = /*@__PURE__*/ new LoadingManager();
  15801. class Loader {
  15802. constructor( manager ) {
  15803. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  15804. this.crossOrigin = 'anonymous';
  15805. this.withCredentials = false;
  15806. this.path = '';
  15807. this.resourcePath = '';
  15808. this.requestHeader = {};
  15809. }
  15810. load( /* url, onLoad, onProgress, onError */ ) {}
  15811. loadAsync( url, onProgress ) {
  15812. const scope = this;
  15813. return new Promise( function ( resolve, reject ) {
  15814. scope.load( url, resolve, onProgress, reject );
  15815. } );
  15816. }
  15817. parse( /* data */ ) {}
  15818. setCrossOrigin( crossOrigin ) {
  15819. this.crossOrigin = crossOrigin;
  15820. return this;
  15821. }
  15822. setWithCredentials( value ) {
  15823. this.withCredentials = value;
  15824. return this;
  15825. }
  15826. setPath( path ) {
  15827. this.path = path;
  15828. return this;
  15829. }
  15830. setResourcePath( resourcePath ) {
  15831. this.resourcePath = resourcePath;
  15832. return this;
  15833. }
  15834. setRequestHeader( requestHeader ) {
  15835. this.requestHeader = requestHeader;
  15836. return this;
  15837. }
  15838. }
  15839. Loader.DEFAULT_MATERIAL_NAME = '__DEFAULT';
  15840. const loading = {};
  15841. class HttpError extends Error {
  15842. constructor( message, response ) {
  15843. super( message );
  15844. this.response = response;
  15845. }
  15846. }
  15847. class FileLoader extends Loader {
  15848. constructor( manager ) {
  15849. super( manager );
  15850. }
  15851. load( url, onLoad, onProgress, onError ) {
  15852. if ( url === undefined ) url = '';
  15853. if ( this.path !== undefined ) url = this.path + url;
  15854. url = this.manager.resolveURL( url );
  15855. const cached = Cache.get( url );
  15856. if ( cached !== undefined ) {
  15857. this.manager.itemStart( url );
  15858. setTimeout( () => {
  15859. if ( onLoad ) onLoad( cached );
  15860. this.manager.itemEnd( url );
  15861. }, 0 );
  15862. return cached;
  15863. }
  15864. // Check if request is duplicate
  15865. if ( loading[ url ] !== undefined ) {
  15866. loading[ url ].push( {
  15867. onLoad: onLoad,
  15868. onProgress: onProgress,
  15869. onError: onError
  15870. } );
  15871. return;
  15872. }
  15873. // Initialise array for duplicate requests
  15874. loading[ url ] = [];
  15875. loading[ url ].push( {
  15876. onLoad: onLoad,
  15877. onProgress: onProgress,
  15878. onError: onError,
  15879. } );
  15880. // create request
  15881. const req = new Request( url, {
  15882. headers: new Headers( this.requestHeader ),
  15883. credentials: this.withCredentials ? 'include' : 'same-origin',
  15884. // An abort controller could be added within a future PR
  15885. } );
  15886. // record states ( avoid data race )
  15887. const mimeType = this.mimeType;
  15888. const responseType = this.responseType;
  15889. // start the fetch
  15890. fetch( req )
  15891. .then( response => {
  15892. if ( response.status === 200 || response.status === 0 ) {
  15893. // Some browsers return HTTP Status 0 when using non-http protocol
  15894. // e.g. 'file://' or 'data://'. Handle as success.
  15895. if ( response.status === 0 ) {
  15896. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  15897. }
  15898. // Workaround: Checking if response.body === undefined for Alipay browser #23548
  15899. if ( typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined ) {
  15900. return response;
  15901. }
  15902. const callbacks = loading[ url ];
  15903. const reader = response.body.getReader();
  15904. // Nginx needs X-File-Size check
  15905. // https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
  15906. const contentLength = response.headers.get( 'X-File-Size' ) || response.headers.get( 'Content-Length' );
  15907. const total = contentLength ? parseInt( contentLength ) : 0;
  15908. const lengthComputable = total !== 0;
  15909. let loaded = 0;
  15910. // periodically read data into the new stream tracking while download progress
  15911. const stream = new ReadableStream( {
  15912. start( controller ) {
  15913. readData();
  15914. function readData() {
  15915. reader.read().then( ( { done, value } ) => {
  15916. if ( done ) {
  15917. controller.close();
  15918. } else {
  15919. loaded += value.byteLength;
  15920. const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } );
  15921. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15922. const callback = callbacks[ i ];
  15923. if ( callback.onProgress ) callback.onProgress( event );
  15924. }
  15925. controller.enqueue( value );
  15926. readData();
  15927. }
  15928. }, ( e ) => {
  15929. controller.error( e );
  15930. } );
  15931. }
  15932. }
  15933. } );
  15934. return new Response( stream );
  15935. } else {
  15936. throw new HttpError( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response );
  15937. }
  15938. } )
  15939. .then( response => {
  15940. switch ( responseType ) {
  15941. case 'arraybuffer':
  15942. return response.arrayBuffer();
  15943. case 'blob':
  15944. return response.blob();
  15945. case 'document':
  15946. return response.text()
  15947. .then( text => {
  15948. const parser = new DOMParser();
  15949. return parser.parseFromString( text, mimeType );
  15950. } );
  15951. case 'json':
  15952. return response.json();
  15953. default:
  15954. if ( mimeType === undefined ) {
  15955. return response.text();
  15956. } else {
  15957. // sniff encoding
  15958. const re = /charset="?([^;"\s]*)"?/i;
  15959. const exec = re.exec( mimeType );
  15960. const label = exec && exec[ 1 ] ? exec[ 1 ].toLowerCase() : undefined;
  15961. const decoder = new TextDecoder( label );
  15962. return response.arrayBuffer().then( ab => decoder.decode( ab ) );
  15963. }
  15964. }
  15965. } )
  15966. .then( data => {
  15967. // Add to cache only on HTTP success, so that we do not cache
  15968. // error response bodies as proper responses to requests.
  15969. Cache.add( url, data );
  15970. const callbacks = loading[ url ];
  15971. delete loading[ url ];
  15972. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15973. const callback = callbacks[ i ];
  15974. if ( callback.onLoad ) callback.onLoad( data );
  15975. }
  15976. } )
  15977. .catch( err => {
  15978. // Abort errors and other errors are handled the same
  15979. const callbacks = loading[ url ];
  15980. if ( callbacks === undefined ) {
  15981. // When onLoad was called and url was deleted in `loading`
  15982. this.manager.itemError( url );
  15983. throw err;
  15984. }
  15985. delete loading[ url ];
  15986. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15987. const callback = callbacks[ i ];
  15988. if ( callback.onError ) callback.onError( err );
  15989. }
  15990. this.manager.itemError( url );
  15991. } )
  15992. .finally( () => {
  15993. this.manager.itemEnd( url );
  15994. } );
  15995. this.manager.itemStart( url );
  15996. }
  15997. setResponseType( value ) {
  15998. this.responseType = value;
  15999. return this;
  16000. }
  16001. setMimeType( value ) {
  16002. this.mimeType = value;
  16003. return this;
  16004. }
  16005. }
  16006. class AnimationLoader extends Loader {
  16007. constructor( manager ) {
  16008. super( manager );
  16009. }
  16010. load( url, onLoad, onProgress, onError ) {
  16011. const scope = this;
  16012. const loader = new FileLoader( this.manager );
  16013. loader.setPath( this.path );
  16014. loader.setRequestHeader( this.requestHeader );
  16015. loader.setWithCredentials( this.withCredentials );
  16016. loader.load( url, function ( text ) {
  16017. try {
  16018. onLoad( scope.parse( JSON.parse( text ) ) );
  16019. } catch ( e ) {
  16020. if ( onError ) {
  16021. onError( e );
  16022. } else {
  16023. console.error( e );
  16024. }
  16025. scope.manager.itemError( url );
  16026. }
  16027. }, onProgress, onError );
  16028. }
  16029. parse( json ) {
  16030. const animations = [];
  16031. for ( let i = 0; i < json.length; i ++ ) {
  16032. const clip = AnimationClip.parse( json[ i ] );
  16033. animations.push( clip );
  16034. }
  16035. return animations;
  16036. }
  16037. }
  16038. /**
  16039. * Abstract Base class to block based textures loader (dds, pvr, ...)
  16040. *
  16041. * Sub classes have to implement the parse() method which will be used in load().
  16042. */
  16043. class CompressedTextureLoader extends Loader {
  16044. constructor( manager ) {
  16045. super( manager );
  16046. }
  16047. load( url, onLoad, onProgress, onError ) {
  16048. const scope = this;
  16049. const images = [];
  16050. const texture = new CompressedTexture();
  16051. const loader = new FileLoader( this.manager );
  16052. loader.setPath( this.path );
  16053. loader.setResponseType( 'arraybuffer' );
  16054. loader.setRequestHeader( this.requestHeader );
  16055. loader.setWithCredentials( scope.withCredentials );
  16056. let loaded = 0;
  16057. function loadTexture( i ) {
  16058. loader.load( url[ i ], function ( buffer ) {
  16059. const texDatas = scope.parse( buffer, true );
  16060. images[ i ] = {
  16061. width: texDatas.width,
  16062. height: texDatas.height,
  16063. format: texDatas.format,
  16064. mipmaps: texDatas.mipmaps
  16065. };
  16066. loaded += 1;
  16067. if ( loaded === 6 ) {
  16068. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  16069. texture.image = images;
  16070. texture.format = texDatas.format;
  16071. texture.needsUpdate = true;
  16072. if ( onLoad ) onLoad( texture );
  16073. }
  16074. }, onProgress, onError );
  16075. }
  16076. if ( Array.isArray( url ) ) {
  16077. for ( let i = 0, il = url.length; i < il; ++ i ) {
  16078. loadTexture( i );
  16079. }
  16080. } else {
  16081. // compressed cubemap texture stored in a single DDS file
  16082. loader.load( url, function ( buffer ) {
  16083. const texDatas = scope.parse( buffer, true );
  16084. if ( texDatas.isCubemap ) {
  16085. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  16086. for ( let f = 0; f < faces; f ++ ) {
  16087. images[ f ] = { mipmaps: [] };
  16088. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  16089. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  16090. images[ f ].format = texDatas.format;
  16091. images[ f ].width = texDatas.width;
  16092. images[ f ].height = texDatas.height;
  16093. }
  16094. }
  16095. texture.image = images;
  16096. } else {
  16097. texture.image.width = texDatas.width;
  16098. texture.image.height = texDatas.height;
  16099. texture.mipmaps = texDatas.mipmaps;
  16100. }
  16101. if ( texDatas.mipmapCount === 1 ) {
  16102. texture.minFilter = LinearFilter;
  16103. }
  16104. texture.format = texDatas.format;
  16105. texture.needsUpdate = true;
  16106. if ( onLoad ) onLoad( texture );
  16107. }, onProgress, onError );
  16108. }
  16109. return texture;
  16110. }
  16111. }
  16112. class ImageLoader extends Loader {
  16113. constructor( manager ) {
  16114. super( manager );
  16115. }
  16116. load( url, onLoad, onProgress, onError ) {
  16117. if ( this.path !== undefined ) url = this.path + url;
  16118. url = this.manager.resolveURL( url );
  16119. const scope = this;
  16120. const cached = Cache.get( url );
  16121. if ( cached !== undefined ) {
  16122. scope.manager.itemStart( url );
  16123. setTimeout( function () {
  16124. if ( onLoad ) onLoad( cached );
  16125. scope.manager.itemEnd( url );
  16126. }, 0 );
  16127. return cached;
  16128. }
  16129. const image = createElementNS( 'img' );
  16130. function onImageLoad() {
  16131. removeEventListeners();
  16132. Cache.add( url, this );
  16133. if ( onLoad ) onLoad( this );
  16134. scope.manager.itemEnd( url );
  16135. }
  16136. function onImageError( event ) {
  16137. removeEventListeners();
  16138. if ( onError ) onError( event );
  16139. scope.manager.itemError( url );
  16140. scope.manager.itemEnd( url );
  16141. }
  16142. function removeEventListeners() {
  16143. image.removeEventListener( 'load', onImageLoad, false );
  16144. image.removeEventListener( 'error', onImageError, false );
  16145. }
  16146. image.addEventListener( 'load', onImageLoad, false );
  16147. image.addEventListener( 'error', onImageError, false );
  16148. if ( url.slice( 0, 5 ) !== 'data:' ) {
  16149. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  16150. }
  16151. scope.manager.itemStart( url );
  16152. image.src = url;
  16153. return image;
  16154. }
  16155. }
  16156. class CubeTextureLoader extends Loader {
  16157. constructor( manager ) {
  16158. super( manager );
  16159. }
  16160. load( urls, onLoad, onProgress, onError ) {
  16161. const texture = new CubeTexture();
  16162. texture.colorSpace = SRGBColorSpace;
  16163. const loader = new ImageLoader( this.manager );
  16164. loader.setCrossOrigin( this.crossOrigin );
  16165. loader.setPath( this.path );
  16166. let loaded = 0;
  16167. function loadTexture( i ) {
  16168. loader.load( urls[ i ], function ( image ) {
  16169. texture.images[ i ] = image;
  16170. loaded ++;
  16171. if ( loaded === 6 ) {
  16172. texture.needsUpdate = true;
  16173. if ( onLoad ) onLoad( texture );
  16174. }
  16175. }, undefined, onError );
  16176. }
  16177. for ( let i = 0; i < urls.length; ++ i ) {
  16178. loadTexture( i );
  16179. }
  16180. return texture;
  16181. }
  16182. }
  16183. /**
  16184. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  16185. *
  16186. * Sub classes have to implement the parse() method which will be used in load().
  16187. */
  16188. class DataTextureLoader extends Loader {
  16189. constructor( manager ) {
  16190. super( manager );
  16191. }
  16192. load( url, onLoad, onProgress, onError ) {
  16193. const scope = this;
  16194. const texture = new DataTexture();
  16195. const loader = new FileLoader( this.manager );
  16196. loader.setResponseType( 'arraybuffer' );
  16197. loader.setRequestHeader( this.requestHeader );
  16198. loader.setPath( this.path );
  16199. loader.setWithCredentials( scope.withCredentials );
  16200. loader.load( url, function ( buffer ) {
  16201. let texData;
  16202. try {
  16203. texData = scope.parse( buffer );
  16204. } catch ( error ) {
  16205. if ( onError !== undefined ) {
  16206. onError( error );
  16207. } else {
  16208. console.error( error );
  16209. return;
  16210. }
  16211. }
  16212. if ( texData.image !== undefined ) {
  16213. texture.image = texData.image;
  16214. } else if ( texData.data !== undefined ) {
  16215. texture.image.width = texData.width;
  16216. texture.image.height = texData.height;
  16217. texture.image.data = texData.data;
  16218. }
  16219. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  16220. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  16221. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  16222. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  16223. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  16224. if ( texData.colorSpace !== undefined ) {
  16225. texture.colorSpace = texData.colorSpace;
  16226. }
  16227. if ( texData.flipY !== undefined ) {
  16228. texture.flipY = texData.flipY;
  16229. }
  16230. if ( texData.format !== undefined ) {
  16231. texture.format = texData.format;
  16232. }
  16233. if ( texData.type !== undefined ) {
  16234. texture.type = texData.type;
  16235. }
  16236. if ( texData.mipmaps !== undefined ) {
  16237. texture.mipmaps = texData.mipmaps;
  16238. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  16239. }
  16240. if ( texData.mipmapCount === 1 ) {
  16241. texture.minFilter = LinearFilter;
  16242. }
  16243. if ( texData.generateMipmaps !== undefined ) {
  16244. texture.generateMipmaps = texData.generateMipmaps;
  16245. }
  16246. texture.needsUpdate = true;
  16247. if ( onLoad ) onLoad( texture, texData );
  16248. }, onProgress, onError );
  16249. return texture;
  16250. }
  16251. }
  16252. class TextureLoader extends Loader {
  16253. constructor( manager ) {
  16254. super( manager );
  16255. }
  16256. load( url, onLoad, onProgress, onError ) {
  16257. const texture = new Texture();
  16258. const loader = new ImageLoader( this.manager );
  16259. loader.setCrossOrigin( this.crossOrigin );
  16260. loader.setPath( this.path );
  16261. loader.load( url, function ( image ) {
  16262. texture.image = image;
  16263. texture.needsUpdate = true;
  16264. if ( onLoad !== undefined ) {
  16265. onLoad( texture );
  16266. }
  16267. }, onProgress, onError );
  16268. return texture;
  16269. }
  16270. }
  16271. class Light extends Object3D {
  16272. constructor( color, intensity = 1 ) {
  16273. super();
  16274. this.isLight = true;
  16275. this.type = 'Light';
  16276. this.color = new Color( color );
  16277. this.intensity = intensity;
  16278. }
  16279. dispose() {
  16280. // Empty here in base class; some subclasses override.
  16281. }
  16282. copy( source, recursive ) {
  16283. super.copy( source, recursive );
  16284. this.color.copy( source.color );
  16285. this.intensity = source.intensity;
  16286. return this;
  16287. }
  16288. toJSON( meta ) {
  16289. const data = super.toJSON( meta );
  16290. data.object.color = this.color.getHex();
  16291. data.object.intensity = this.intensity;
  16292. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  16293. if ( this.distance !== undefined ) data.object.distance = this.distance;
  16294. if ( this.angle !== undefined ) data.object.angle = this.angle;
  16295. if ( this.decay !== undefined ) data.object.decay = this.decay;
  16296. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  16297. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  16298. if ( this.target !== undefined ) data.object.target = this.target.uuid;
  16299. return data;
  16300. }
  16301. }
  16302. class HemisphereLight extends Light {
  16303. constructor( skyColor, groundColor, intensity ) {
  16304. super( skyColor, intensity );
  16305. this.isHemisphereLight = true;
  16306. this.type = 'HemisphereLight';
  16307. this.position.copy( Object3D.DEFAULT_UP );
  16308. this.updateMatrix();
  16309. this.groundColor = new Color( groundColor );
  16310. }
  16311. copy( source, recursive ) {
  16312. super.copy( source, recursive );
  16313. this.groundColor.copy( source.groundColor );
  16314. return this;
  16315. }
  16316. }
  16317. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  16318. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  16319. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  16320. class LightShadow {
  16321. constructor( camera ) {
  16322. this.camera = camera;
  16323. this.intensity = 1;
  16324. this.bias = 0;
  16325. this.normalBias = 0;
  16326. this.radius = 1;
  16327. this.blurSamples = 8;
  16328. this.mapSize = new Vector2( 512, 512 );
  16329. this.map = null;
  16330. this.mapPass = null;
  16331. this.matrix = new Matrix4();
  16332. this.autoUpdate = true;
  16333. this.needsUpdate = false;
  16334. this._frustum = new Frustum();
  16335. this._frameExtents = new Vector2( 1, 1 );
  16336. this._viewportCount = 1;
  16337. this._viewports = [
  16338. new Vector4( 0, 0, 1, 1 )
  16339. ];
  16340. }
  16341. getViewportCount() {
  16342. return this._viewportCount;
  16343. }
  16344. getFrustum() {
  16345. return this._frustum;
  16346. }
  16347. updateMatrices( light ) {
  16348. const shadowCamera = this.camera;
  16349. const shadowMatrix = this.matrix;
  16350. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  16351. shadowCamera.position.copy( _lightPositionWorld$1 );
  16352. _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld );
  16353. shadowCamera.lookAt( _lookTarget$1 );
  16354. shadowCamera.updateMatrixWorld();
  16355. _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  16356. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  16357. shadowMatrix.set(
  16358. 0.5, 0.0, 0.0, 0.5,
  16359. 0.0, 0.5, 0.0, 0.5,
  16360. 0.0, 0.0, 0.5, 0.5,
  16361. 0.0, 0.0, 0.0, 1.0
  16362. );
  16363. shadowMatrix.multiply( _projScreenMatrix$1 );
  16364. }
  16365. getViewport( viewportIndex ) {
  16366. return this._viewports[ viewportIndex ];
  16367. }
  16368. getFrameExtents() {
  16369. return this._frameExtents;
  16370. }
  16371. dispose() {
  16372. if ( this.map ) {
  16373. this.map.dispose();
  16374. }
  16375. if ( this.mapPass ) {
  16376. this.mapPass.dispose();
  16377. }
  16378. }
  16379. copy( source ) {
  16380. this.camera = source.camera.clone();
  16381. this.intensity = source.intensity;
  16382. this.bias = source.bias;
  16383. this.radius = source.radius;
  16384. this.mapSize.copy( source.mapSize );
  16385. return this;
  16386. }
  16387. clone() {
  16388. return new this.constructor().copy( this );
  16389. }
  16390. toJSON() {
  16391. const object = {};
  16392. if ( this.intensity !== 1 ) object.intensity = this.intensity;
  16393. if ( this.bias !== 0 ) object.bias = this.bias;
  16394. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  16395. if ( this.radius !== 1 ) object.radius = this.radius;
  16396. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  16397. object.camera = this.camera.toJSON( false ).object;
  16398. delete object.camera.matrix;
  16399. return object;
  16400. }
  16401. }
  16402. class SpotLightShadow extends LightShadow {
  16403. constructor() {
  16404. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  16405. this.isSpotLightShadow = true;
  16406. this.focus = 1;
  16407. }
  16408. updateMatrices( light ) {
  16409. const camera = this.camera;
  16410. const fov = RAD2DEG * 2 * light.angle * this.focus;
  16411. const aspect = this.mapSize.width / this.mapSize.height;
  16412. const far = light.distance || camera.far;
  16413. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  16414. camera.fov = fov;
  16415. camera.aspect = aspect;
  16416. camera.far = far;
  16417. camera.updateProjectionMatrix();
  16418. }
  16419. super.updateMatrices( light );
  16420. }
  16421. copy( source ) {
  16422. super.copy( source );
  16423. this.focus = source.focus;
  16424. return this;
  16425. }
  16426. }
  16427. class SpotLight extends Light {
  16428. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) {
  16429. super( color, intensity );
  16430. this.isSpotLight = true;
  16431. this.type = 'SpotLight';
  16432. this.position.copy( Object3D.DEFAULT_UP );
  16433. this.updateMatrix();
  16434. this.target = new Object3D();
  16435. this.distance = distance;
  16436. this.angle = angle;
  16437. this.penumbra = penumbra;
  16438. this.decay = decay;
  16439. this.map = null;
  16440. this.shadow = new SpotLightShadow();
  16441. }
  16442. get power() {
  16443. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16444. // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
  16445. return this.intensity * Math.PI;
  16446. }
  16447. set power( power ) {
  16448. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16449. this.intensity = power / Math.PI;
  16450. }
  16451. dispose() {
  16452. this.shadow.dispose();
  16453. }
  16454. copy( source, recursive ) {
  16455. super.copy( source, recursive );
  16456. this.distance = source.distance;
  16457. this.angle = source.angle;
  16458. this.penumbra = source.penumbra;
  16459. this.decay = source.decay;
  16460. this.target = source.target.clone();
  16461. this.shadow = source.shadow.clone();
  16462. return this;
  16463. }
  16464. }
  16465. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  16466. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  16467. const _lookTarget = /*@__PURE__*/ new Vector3();
  16468. class PointLightShadow extends LightShadow {
  16469. constructor() {
  16470. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  16471. this.isPointLightShadow = true;
  16472. this._frameExtents = new Vector2( 4, 2 );
  16473. this._viewportCount = 6;
  16474. this._viewports = [
  16475. // These viewports map a cube-map onto a 2D texture with the
  16476. // following orientation:
  16477. //
  16478. // xzXZ
  16479. // y Y
  16480. //
  16481. // X - Positive x direction
  16482. // x - Negative x direction
  16483. // Y - Positive y direction
  16484. // y - Negative y direction
  16485. // Z - Positive z direction
  16486. // z - Negative z direction
  16487. // positive X
  16488. new Vector4( 2, 1, 1, 1 ),
  16489. // negative X
  16490. new Vector4( 0, 1, 1, 1 ),
  16491. // positive Z
  16492. new Vector4( 3, 1, 1, 1 ),
  16493. // negative Z
  16494. new Vector4( 1, 1, 1, 1 ),
  16495. // positive Y
  16496. new Vector4( 3, 0, 1, 1 ),
  16497. // negative Y
  16498. new Vector4( 1, 0, 1, 1 )
  16499. ];
  16500. this._cubeDirections = [
  16501. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  16502. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  16503. ];
  16504. this._cubeUps = [
  16505. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  16506. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  16507. ];
  16508. }
  16509. updateMatrices( light, viewportIndex = 0 ) {
  16510. const camera = this.camera;
  16511. const shadowMatrix = this.matrix;
  16512. const far = light.distance || camera.far;
  16513. if ( far !== camera.far ) {
  16514. camera.far = far;
  16515. camera.updateProjectionMatrix();
  16516. }
  16517. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  16518. camera.position.copy( _lightPositionWorld );
  16519. _lookTarget.copy( camera.position );
  16520. _lookTarget.add( this._cubeDirections[ viewportIndex ] );
  16521. camera.up.copy( this._cubeUps[ viewportIndex ] );
  16522. camera.lookAt( _lookTarget );
  16523. camera.updateMatrixWorld();
  16524. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  16525. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  16526. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  16527. }
  16528. }
  16529. class PointLight extends Light {
  16530. constructor( color, intensity, distance = 0, decay = 2 ) {
  16531. super( color, intensity );
  16532. this.isPointLight = true;
  16533. this.type = 'PointLight';
  16534. this.distance = distance;
  16535. this.decay = decay;
  16536. this.shadow = new PointLightShadow();
  16537. }
  16538. get power() {
  16539. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16540. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  16541. return this.intensity * 4 * Math.PI;
  16542. }
  16543. set power( power ) {
  16544. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16545. this.intensity = power / ( 4 * Math.PI );
  16546. }
  16547. dispose() {
  16548. this.shadow.dispose();
  16549. }
  16550. copy( source, recursive ) {
  16551. super.copy( source, recursive );
  16552. this.distance = source.distance;
  16553. this.decay = source.decay;
  16554. this.shadow = source.shadow.clone();
  16555. return this;
  16556. }
  16557. }
  16558. class OrthographicCamera extends Camera {
  16559. constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  16560. super();
  16561. this.isOrthographicCamera = true;
  16562. this.type = 'OrthographicCamera';
  16563. this.zoom = 1;
  16564. this.view = null;
  16565. this.left = left;
  16566. this.right = right;
  16567. this.top = top;
  16568. this.bottom = bottom;
  16569. this.near = near;
  16570. this.far = far;
  16571. this.updateProjectionMatrix();
  16572. }
  16573. copy( source, recursive ) {
  16574. super.copy( source, recursive );
  16575. this.left = source.left;
  16576. this.right = source.right;
  16577. this.top = source.top;
  16578. this.bottom = source.bottom;
  16579. this.near = source.near;
  16580. this.far = source.far;
  16581. this.zoom = source.zoom;
  16582. this.view = source.view === null ? null : Object.assign( {}, source.view );
  16583. return this;
  16584. }
  16585. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  16586. if ( this.view === null ) {
  16587. this.view = {
  16588. enabled: true,
  16589. fullWidth: 1,
  16590. fullHeight: 1,
  16591. offsetX: 0,
  16592. offsetY: 0,
  16593. width: 1,
  16594. height: 1
  16595. };
  16596. }
  16597. this.view.enabled = true;
  16598. this.view.fullWidth = fullWidth;
  16599. this.view.fullHeight = fullHeight;
  16600. this.view.offsetX = x;
  16601. this.view.offsetY = y;
  16602. this.view.width = width;
  16603. this.view.height = height;
  16604. this.updateProjectionMatrix();
  16605. }
  16606. clearViewOffset() {
  16607. if ( this.view !== null ) {
  16608. this.view.enabled = false;
  16609. }
  16610. this.updateProjectionMatrix();
  16611. }
  16612. updateProjectionMatrix() {
  16613. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  16614. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  16615. const cx = ( this.right + this.left ) / 2;
  16616. const cy = ( this.top + this.bottom ) / 2;
  16617. let left = cx - dx;
  16618. let right = cx + dx;
  16619. let top = cy + dy;
  16620. let bottom = cy - dy;
  16621. if ( this.view !== null && this.view.enabled ) {
  16622. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  16623. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  16624. left += scaleW * this.view.offsetX;
  16625. right = left + scaleW * this.view.width;
  16626. top -= scaleH * this.view.offsetY;
  16627. bottom = top - scaleH * this.view.height;
  16628. }
  16629. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
  16630. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  16631. }
  16632. toJSON( meta ) {
  16633. const data = super.toJSON( meta );
  16634. data.object.zoom = this.zoom;
  16635. data.object.left = this.left;
  16636. data.object.right = this.right;
  16637. data.object.top = this.top;
  16638. data.object.bottom = this.bottom;
  16639. data.object.near = this.near;
  16640. data.object.far = this.far;
  16641. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  16642. return data;
  16643. }
  16644. }
  16645. class DirectionalLightShadow extends LightShadow {
  16646. constructor() {
  16647. super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  16648. this.isDirectionalLightShadow = true;
  16649. }
  16650. }
  16651. class DirectionalLight extends Light {
  16652. constructor( color, intensity ) {
  16653. super( color, intensity );
  16654. this.isDirectionalLight = true;
  16655. this.type = 'DirectionalLight';
  16656. this.position.copy( Object3D.DEFAULT_UP );
  16657. this.updateMatrix();
  16658. this.target = new Object3D();
  16659. this.shadow = new DirectionalLightShadow();
  16660. }
  16661. dispose() {
  16662. this.shadow.dispose();
  16663. }
  16664. copy( source ) {
  16665. super.copy( source );
  16666. this.target = source.target.clone();
  16667. this.shadow = source.shadow.clone();
  16668. return this;
  16669. }
  16670. }
  16671. class AmbientLight extends Light {
  16672. constructor( color, intensity ) {
  16673. super( color, intensity );
  16674. this.isAmbientLight = true;
  16675. this.type = 'AmbientLight';
  16676. }
  16677. }
  16678. class RectAreaLight extends Light {
  16679. constructor( color, intensity, width = 10, height = 10 ) {
  16680. super( color, intensity );
  16681. this.isRectAreaLight = true;
  16682. this.type = 'RectAreaLight';
  16683. this.width = width;
  16684. this.height = height;
  16685. }
  16686. get power() {
  16687. // compute the light's luminous power (in lumens) from its intensity (in nits)
  16688. return this.intensity * this.width * this.height * Math.PI;
  16689. }
  16690. set power( power ) {
  16691. // set the light's intensity (in nits) from the desired luminous power (in lumens)
  16692. this.intensity = power / ( this.width * this.height * Math.PI );
  16693. }
  16694. copy( source ) {
  16695. super.copy( source );
  16696. this.width = source.width;
  16697. this.height = source.height;
  16698. return this;
  16699. }
  16700. toJSON( meta ) {
  16701. const data = super.toJSON( meta );
  16702. data.object.width = this.width;
  16703. data.object.height = this.height;
  16704. return data;
  16705. }
  16706. }
  16707. /**
  16708. * Primary reference:
  16709. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16710. *
  16711. * Secondary reference:
  16712. * https://www.ppsloan.org/publications/StupidSH36.pdf
  16713. */
  16714. // 3-band SH defined by 9 coefficients
  16715. class SphericalHarmonics3 {
  16716. constructor() {
  16717. this.isSphericalHarmonics3 = true;
  16718. this.coefficients = [];
  16719. for ( let i = 0; i < 9; i ++ ) {
  16720. this.coefficients.push( new Vector3() );
  16721. }
  16722. }
  16723. set( coefficients ) {
  16724. for ( let i = 0; i < 9; i ++ ) {
  16725. this.coefficients[ i ].copy( coefficients[ i ] );
  16726. }
  16727. return this;
  16728. }
  16729. zero() {
  16730. for ( let i = 0; i < 9; i ++ ) {
  16731. this.coefficients[ i ].set( 0, 0, 0 );
  16732. }
  16733. return this;
  16734. }
  16735. // get the radiance in the direction of the normal
  16736. // target is a Vector3
  16737. getAt( normal, target ) {
  16738. // normal is assumed to be unit length
  16739. const x = normal.x, y = normal.y, z = normal.z;
  16740. const coeff = this.coefficients;
  16741. // band 0
  16742. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  16743. // band 1
  16744. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  16745. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  16746. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  16747. // band 2
  16748. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  16749. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  16750. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  16751. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  16752. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  16753. return target;
  16754. }
  16755. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  16756. // target is a Vector3
  16757. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16758. getIrradianceAt( normal, target ) {
  16759. // normal is assumed to be unit length
  16760. const x = normal.x, y = normal.y, z = normal.z;
  16761. const coeff = this.coefficients;
  16762. // band 0
  16763. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  16764. // band 1
  16765. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  16766. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  16767. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  16768. // band 2
  16769. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  16770. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  16771. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  16772. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  16773. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  16774. return target;
  16775. }
  16776. add( sh ) {
  16777. for ( let i = 0; i < 9; i ++ ) {
  16778. this.coefficients[ i ].add( sh.coefficients[ i ] );
  16779. }
  16780. return this;
  16781. }
  16782. addScaledSH( sh, s ) {
  16783. for ( let i = 0; i < 9; i ++ ) {
  16784. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  16785. }
  16786. return this;
  16787. }
  16788. scale( s ) {
  16789. for ( let i = 0; i < 9; i ++ ) {
  16790. this.coefficients[ i ].multiplyScalar( s );
  16791. }
  16792. return this;
  16793. }
  16794. lerp( sh, alpha ) {
  16795. for ( let i = 0; i < 9; i ++ ) {
  16796. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  16797. }
  16798. return this;
  16799. }
  16800. equals( sh ) {
  16801. for ( let i = 0; i < 9; i ++ ) {
  16802. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  16803. return false;
  16804. }
  16805. }
  16806. return true;
  16807. }
  16808. copy( sh ) {
  16809. return this.set( sh.coefficients );
  16810. }
  16811. clone() {
  16812. return new this.constructor().copy( this );
  16813. }
  16814. fromArray( array, offset = 0 ) {
  16815. const coefficients = this.coefficients;
  16816. for ( let i = 0; i < 9; i ++ ) {
  16817. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  16818. }
  16819. return this;
  16820. }
  16821. toArray( array = [], offset = 0 ) {
  16822. const coefficients = this.coefficients;
  16823. for ( let i = 0; i < 9; i ++ ) {
  16824. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  16825. }
  16826. return array;
  16827. }
  16828. // evaluate the basis functions
  16829. // shBasis is an Array[ 9 ]
  16830. static getBasisAt( normal, shBasis ) {
  16831. // normal is assumed to be unit length
  16832. const x = normal.x, y = normal.y, z = normal.z;
  16833. // band 0
  16834. shBasis[ 0 ] = 0.282095;
  16835. // band 1
  16836. shBasis[ 1 ] = 0.488603 * y;
  16837. shBasis[ 2 ] = 0.488603 * z;
  16838. shBasis[ 3 ] = 0.488603 * x;
  16839. // band 2
  16840. shBasis[ 4 ] = 1.092548 * x * y;
  16841. shBasis[ 5 ] = 1.092548 * y * z;
  16842. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  16843. shBasis[ 7 ] = 1.092548 * x * z;
  16844. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  16845. }
  16846. }
  16847. class LightProbe extends Light {
  16848. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  16849. super( undefined, intensity );
  16850. this.isLightProbe = true;
  16851. this.sh = sh;
  16852. }
  16853. copy( source ) {
  16854. super.copy( source );
  16855. this.sh.copy( source.sh );
  16856. return this;
  16857. }
  16858. fromJSON( json ) {
  16859. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  16860. this.sh.fromArray( json.sh );
  16861. return this;
  16862. }
  16863. toJSON( meta ) {
  16864. const data = super.toJSON( meta );
  16865. data.object.sh = this.sh.toArray();
  16866. return data;
  16867. }
  16868. }
  16869. class MaterialLoader extends Loader {
  16870. constructor( manager ) {
  16871. super( manager );
  16872. this.textures = {};
  16873. }
  16874. load( url, onLoad, onProgress, onError ) {
  16875. const scope = this;
  16876. const loader = new FileLoader( scope.manager );
  16877. loader.setPath( scope.path );
  16878. loader.setRequestHeader( scope.requestHeader );
  16879. loader.setWithCredentials( scope.withCredentials );
  16880. loader.load( url, function ( text ) {
  16881. try {
  16882. onLoad( scope.parse( JSON.parse( text ) ) );
  16883. } catch ( e ) {
  16884. if ( onError ) {
  16885. onError( e );
  16886. } else {
  16887. console.error( e );
  16888. }
  16889. scope.manager.itemError( url );
  16890. }
  16891. }, onProgress, onError );
  16892. }
  16893. parse( json ) {
  16894. const textures = this.textures;
  16895. function getTexture( name ) {
  16896. if ( textures[ name ] === undefined ) {
  16897. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  16898. }
  16899. return textures[ name ];
  16900. }
  16901. const material = this.createMaterialFromType( json.type );
  16902. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  16903. if ( json.name !== undefined ) material.name = json.name;
  16904. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  16905. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  16906. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  16907. if ( json.sheen !== undefined ) material.sheen = json.sheen;
  16908. if ( json.sheenColor !== undefined ) material.sheenColor = new Color().setHex( json.sheenColor );
  16909. if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness;
  16910. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  16911. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  16912. if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity;
  16913. if ( json.specularColor !== undefined && material.specularColor !== undefined ) material.specularColor.setHex( json.specularColor );
  16914. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  16915. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  16916. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  16917. if ( json.dispersion !== undefined ) material.dispersion = json.dispersion;
  16918. if ( json.iridescence !== undefined ) material.iridescence = json.iridescence;
  16919. if ( json.iridescenceIOR !== undefined ) material.iridescenceIOR = json.iridescenceIOR;
  16920. if ( json.iridescenceThicknessRange !== undefined ) material.iridescenceThicknessRange = json.iridescenceThicknessRange;
  16921. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  16922. if ( json.thickness !== undefined ) material.thickness = json.thickness;
  16923. if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance;
  16924. if ( json.attenuationColor !== undefined && material.attenuationColor !== undefined ) material.attenuationColor.setHex( json.attenuationColor );
  16925. if ( json.anisotropy !== undefined ) material.anisotropy = json.anisotropy;
  16926. if ( json.anisotropyRotation !== undefined ) material.anisotropyRotation = json.anisotropyRotation;
  16927. if ( json.fog !== undefined ) material.fog = json.fog;
  16928. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  16929. if ( json.blending !== undefined ) material.blending = json.blending;
  16930. if ( json.combine !== undefined ) material.combine = json.combine;
  16931. if ( json.side !== undefined ) material.side = json.side;
  16932. if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
  16933. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  16934. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  16935. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  16936. if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
  16937. if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc;
  16938. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  16939. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  16940. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  16941. if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc;
  16942. if ( json.blendDst !== undefined ) material.blendDst = json.blendDst;
  16943. if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation;
  16944. if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha;
  16945. if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha;
  16946. if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha;
  16947. if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor );
  16948. if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha;
  16949. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  16950. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  16951. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  16952. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  16953. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  16954. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  16955. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  16956. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  16957. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  16958. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  16959. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  16960. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  16961. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  16962. if ( json.linewidth !== undefined ) material.linewidth = json.linewidth;
  16963. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  16964. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  16965. if ( json.scale !== undefined ) material.scale = json.scale;
  16966. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  16967. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  16968. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  16969. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  16970. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  16971. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  16972. if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass;
  16973. if ( json.visible !== undefined ) material.visible = json.visible;
  16974. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  16975. if ( json.userData !== undefined ) material.userData = json.userData;
  16976. if ( json.vertexColors !== undefined ) {
  16977. if ( typeof json.vertexColors === 'number' ) {
  16978. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  16979. } else {
  16980. material.vertexColors = json.vertexColors;
  16981. }
  16982. }
  16983. // Shader Material
  16984. if ( json.uniforms !== undefined ) {
  16985. for ( const name in json.uniforms ) {
  16986. const uniform = json.uniforms[ name ];
  16987. material.uniforms[ name ] = {};
  16988. switch ( uniform.type ) {
  16989. case 't':
  16990. material.uniforms[ name ].value = getTexture( uniform.value );
  16991. break;
  16992. case 'c':
  16993. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  16994. break;
  16995. case 'v2':
  16996. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  16997. break;
  16998. case 'v3':
  16999. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  17000. break;
  17001. case 'v4':
  17002. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  17003. break;
  17004. case 'm3':
  17005. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  17006. break;
  17007. case 'm4':
  17008. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  17009. break;
  17010. default:
  17011. material.uniforms[ name ].value = uniform.value;
  17012. }
  17013. }
  17014. }
  17015. if ( json.defines !== undefined ) material.defines = json.defines;
  17016. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  17017. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  17018. if ( json.glslVersion !== undefined ) material.glslVersion = json.glslVersion;
  17019. if ( json.extensions !== undefined ) {
  17020. for ( const key in json.extensions ) {
  17021. material.extensions[ key ] = json.extensions[ key ];
  17022. }
  17023. }
  17024. if ( json.lights !== undefined ) material.lights = json.lights;
  17025. if ( json.clipping !== undefined ) material.clipping = json.clipping;
  17026. // for PointsMaterial
  17027. if ( json.size !== undefined ) material.size = json.size;
  17028. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  17029. // maps
  17030. if ( json.map !== undefined ) material.map = getTexture( json.map );
  17031. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  17032. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  17033. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  17034. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  17035. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  17036. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  17037. if ( json.normalScale !== undefined ) {
  17038. let normalScale = json.normalScale;
  17039. if ( Array.isArray( normalScale ) === false ) {
  17040. // Blender exporter used to export a scalar. See #7459
  17041. normalScale = [ normalScale, normalScale ];
  17042. }
  17043. material.normalScale = new Vector2().fromArray( normalScale );
  17044. }
  17045. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  17046. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  17047. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  17048. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  17049. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  17050. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  17051. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  17052. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  17053. if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap );
  17054. if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap );
  17055. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  17056. if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation );
  17057. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  17058. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  17059. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  17060. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  17061. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  17062. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  17063. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  17064. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  17065. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  17066. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  17067. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  17068. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  17069. if ( json.iridescenceMap !== undefined ) material.iridescenceMap = getTexture( json.iridescenceMap );
  17070. if ( json.iridescenceThicknessMap !== undefined ) material.iridescenceThicknessMap = getTexture( json.iridescenceThicknessMap );
  17071. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  17072. if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap );
  17073. if ( json.anisotropyMap !== undefined ) material.anisotropyMap = getTexture( json.anisotropyMap );
  17074. if ( json.sheenColorMap !== undefined ) material.sheenColorMap = getTexture( json.sheenColorMap );
  17075. if ( json.sheenRoughnessMap !== undefined ) material.sheenRoughnessMap = getTexture( json.sheenRoughnessMap );
  17076. return material;
  17077. }
  17078. setTextures( value ) {
  17079. this.textures = value;
  17080. return this;
  17081. }
  17082. createMaterialFromType( type ) {
  17083. return MaterialLoader.createMaterialFromType( type );
  17084. }
  17085. static createMaterialFromType( type ) {
  17086. const materialLib = {
  17087. ShadowMaterial,
  17088. SpriteMaterial,
  17089. RawShaderMaterial,
  17090. ShaderMaterial,
  17091. PointsMaterial,
  17092. MeshPhysicalMaterial,
  17093. MeshStandardMaterial,
  17094. MeshPhongMaterial,
  17095. MeshToonMaterial,
  17096. MeshNormalMaterial,
  17097. MeshLambertMaterial,
  17098. MeshDepthMaterial,
  17099. MeshDistanceMaterial,
  17100. MeshBasicMaterial,
  17101. MeshMatcapMaterial,
  17102. LineDashedMaterial,
  17103. LineBasicMaterial,
  17104. Material
  17105. };
  17106. return new materialLib[ type ]();
  17107. }
  17108. }
  17109. class LoaderUtils {
  17110. static decodeText( array ) { // @deprecated, r165
  17111. console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
  17112. if ( typeof TextDecoder !== 'undefined' ) {
  17113. return new TextDecoder().decode( array );
  17114. }
  17115. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  17116. // throws a "maximum call stack size exceeded" error for large arrays.
  17117. let s = '';
  17118. for ( let i = 0, il = array.length; i < il; i ++ ) {
  17119. // Implicitly assumes little-endian.
  17120. s += String.fromCharCode( array[ i ] );
  17121. }
  17122. try {
  17123. // merges multi-byte utf-8 characters.
  17124. return decodeURIComponent( escape( s ) );
  17125. } catch ( e ) { // see #16358
  17126. return s;
  17127. }
  17128. }
  17129. static extractUrlBase( url ) {
  17130. const index = url.lastIndexOf( '/' );
  17131. if ( index === - 1 ) return './';
  17132. return url.slice( 0, index + 1 );
  17133. }
  17134. static resolveURL( url, path ) {
  17135. // Invalid URL
  17136. if ( typeof url !== 'string' || url === '' ) return '';
  17137. // Host Relative URL
  17138. if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
  17139. path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
  17140. }
  17141. // Absolute URL http://,https://,//
  17142. if ( /^(https?:)?\/\//i.test( url ) ) return url;
  17143. // Data URI
  17144. if ( /^data:.*,.*$/i.test( url ) ) return url;
  17145. // Blob URL
  17146. if ( /^blob:.*$/i.test( url ) ) return url;
  17147. // Relative URL
  17148. return path + url;
  17149. }
  17150. }
  17151. class InstancedBufferGeometry extends BufferGeometry {
  17152. constructor() {
  17153. super();
  17154. this.isInstancedBufferGeometry = true;
  17155. this.type = 'InstancedBufferGeometry';
  17156. this.instanceCount = Infinity;
  17157. }
  17158. copy( source ) {
  17159. super.copy( source );
  17160. this.instanceCount = source.instanceCount;
  17161. return this;
  17162. }
  17163. toJSON() {
  17164. const data = super.toJSON();
  17165. data.instanceCount = this.instanceCount;
  17166. data.isInstancedBufferGeometry = true;
  17167. return data;
  17168. }
  17169. }
  17170. class BufferGeometryLoader extends Loader {
  17171. constructor( manager ) {
  17172. super( manager );
  17173. }
  17174. load( url, onLoad, onProgress, onError ) {
  17175. const scope = this;
  17176. const loader = new FileLoader( scope.manager );
  17177. loader.setPath( scope.path );
  17178. loader.setRequestHeader( scope.requestHeader );
  17179. loader.setWithCredentials( scope.withCredentials );
  17180. loader.load( url, function ( text ) {
  17181. try {
  17182. onLoad( scope.parse( JSON.parse( text ) ) );
  17183. } catch ( e ) {
  17184. if ( onError ) {
  17185. onError( e );
  17186. } else {
  17187. console.error( e );
  17188. }
  17189. scope.manager.itemError( url );
  17190. }
  17191. }, onProgress, onError );
  17192. }
  17193. parse( json ) {
  17194. const interleavedBufferMap = {};
  17195. const arrayBufferMap = {};
  17196. function getInterleavedBuffer( json, uuid ) {
  17197. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  17198. const interleavedBuffers = json.interleavedBuffers;
  17199. const interleavedBuffer = interleavedBuffers[ uuid ];
  17200. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  17201. const array = getTypedArray( interleavedBuffer.type, buffer );
  17202. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  17203. ib.uuid = interleavedBuffer.uuid;
  17204. interleavedBufferMap[ uuid ] = ib;
  17205. return ib;
  17206. }
  17207. function getArrayBuffer( json, uuid ) {
  17208. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  17209. const arrayBuffers = json.arrayBuffers;
  17210. const arrayBuffer = arrayBuffers[ uuid ];
  17211. const ab = new Uint32Array( arrayBuffer ).buffer;
  17212. arrayBufferMap[ uuid ] = ab;
  17213. return ab;
  17214. }
  17215. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  17216. const index = json.data.index;
  17217. if ( index !== undefined ) {
  17218. const typedArray = getTypedArray( index.type, index.array );
  17219. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  17220. }
  17221. const attributes = json.data.attributes;
  17222. for ( const key in attributes ) {
  17223. const attribute = attributes[ key ];
  17224. let bufferAttribute;
  17225. if ( attribute.isInterleavedBufferAttribute ) {
  17226. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17227. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17228. } else {
  17229. const typedArray = getTypedArray( attribute.type, attribute.array );
  17230. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  17231. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  17232. }
  17233. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17234. if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage );
  17235. geometry.setAttribute( key, bufferAttribute );
  17236. }
  17237. const morphAttributes = json.data.morphAttributes;
  17238. if ( morphAttributes ) {
  17239. for ( const key in morphAttributes ) {
  17240. const attributeArray = morphAttributes[ key ];
  17241. const array = [];
  17242. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  17243. const attribute = attributeArray[ i ];
  17244. let bufferAttribute;
  17245. if ( attribute.isInterleavedBufferAttribute ) {
  17246. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17247. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17248. } else {
  17249. const typedArray = getTypedArray( attribute.type, attribute.array );
  17250. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  17251. }
  17252. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17253. array.push( bufferAttribute );
  17254. }
  17255. geometry.morphAttributes[ key ] = array;
  17256. }
  17257. }
  17258. const morphTargetsRelative = json.data.morphTargetsRelative;
  17259. if ( morphTargetsRelative ) {
  17260. geometry.morphTargetsRelative = true;
  17261. }
  17262. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  17263. if ( groups !== undefined ) {
  17264. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  17265. const group = groups[ i ];
  17266. geometry.addGroup( group.start, group.count, group.materialIndex );
  17267. }
  17268. }
  17269. const boundingSphere = json.data.boundingSphere;
  17270. if ( boundingSphere !== undefined ) {
  17271. const center = new Vector3();
  17272. if ( boundingSphere.center !== undefined ) {
  17273. center.fromArray( boundingSphere.center );
  17274. }
  17275. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  17276. }
  17277. if ( json.name ) geometry.name = json.name;
  17278. if ( json.userData ) geometry.userData = json.userData;
  17279. return geometry;
  17280. }
  17281. }
  17282. class ObjectLoader extends Loader {
  17283. constructor( manager ) {
  17284. super( manager );
  17285. }
  17286. load( url, onLoad, onProgress, onError ) {
  17287. const scope = this;
  17288. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17289. this.resourcePath = this.resourcePath || path;
  17290. const loader = new FileLoader( this.manager );
  17291. loader.setPath( this.path );
  17292. loader.setRequestHeader( this.requestHeader );
  17293. loader.setWithCredentials( this.withCredentials );
  17294. loader.load( url, function ( text ) {
  17295. let json = null;
  17296. try {
  17297. json = JSON.parse( text );
  17298. } catch ( error ) {
  17299. if ( onError !== undefined ) onError( error );
  17300. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  17301. return;
  17302. }
  17303. const metadata = json.metadata;
  17304. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17305. if ( onError !== undefined ) onError( new Error( 'THREE.ObjectLoader: Can\'t load ' + url ) );
  17306. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17307. return;
  17308. }
  17309. scope.parse( json, onLoad );
  17310. }, onProgress, onError );
  17311. }
  17312. async loadAsync( url, onProgress ) {
  17313. const scope = this;
  17314. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17315. this.resourcePath = this.resourcePath || path;
  17316. const loader = new FileLoader( this.manager );
  17317. loader.setPath( this.path );
  17318. loader.setRequestHeader( this.requestHeader );
  17319. loader.setWithCredentials( this.withCredentials );
  17320. const text = await loader.loadAsync( url, onProgress );
  17321. const json = JSON.parse( text );
  17322. const metadata = json.metadata;
  17323. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17324. throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17325. }
  17326. return await scope.parseAsync( json );
  17327. }
  17328. parse( json, onLoad ) {
  17329. const animations = this.parseAnimations( json.animations );
  17330. const shapes = this.parseShapes( json.shapes );
  17331. const geometries = this.parseGeometries( json.geometries, shapes );
  17332. const images = this.parseImages( json.images, function () {
  17333. if ( onLoad !== undefined ) onLoad( object );
  17334. } );
  17335. const textures = this.parseTextures( json.textures, images );
  17336. const materials = this.parseMaterials( json.materials, textures );
  17337. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17338. const skeletons = this.parseSkeletons( json.skeletons, object );
  17339. this.bindSkeletons( object, skeletons );
  17340. this.bindLightTargets( object );
  17341. //
  17342. if ( onLoad !== undefined ) {
  17343. let hasImages = false;
  17344. for ( const uuid in images ) {
  17345. if ( images[ uuid ].data instanceof HTMLImageElement ) {
  17346. hasImages = true;
  17347. break;
  17348. }
  17349. }
  17350. if ( hasImages === false ) onLoad( object );
  17351. }
  17352. return object;
  17353. }
  17354. async parseAsync( json ) {
  17355. const animations = this.parseAnimations( json.animations );
  17356. const shapes = this.parseShapes( json.shapes );
  17357. const geometries = this.parseGeometries( json.geometries, shapes );
  17358. const images = await this.parseImagesAsync( json.images );
  17359. const textures = this.parseTextures( json.textures, images );
  17360. const materials = this.parseMaterials( json.materials, textures );
  17361. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17362. const skeletons = this.parseSkeletons( json.skeletons, object );
  17363. this.bindSkeletons( object, skeletons );
  17364. this.bindLightTargets( object );
  17365. return object;
  17366. }
  17367. parseShapes( json ) {
  17368. const shapes = {};
  17369. if ( json !== undefined ) {
  17370. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17371. const shape = new Shape().fromJSON( json[ i ] );
  17372. shapes[ shape.uuid ] = shape;
  17373. }
  17374. }
  17375. return shapes;
  17376. }
  17377. parseSkeletons( json, object ) {
  17378. const skeletons = {};
  17379. const bones = {};
  17380. // generate bone lookup table
  17381. object.traverse( function ( child ) {
  17382. if ( child.isBone ) bones[ child.uuid ] = child;
  17383. } );
  17384. // create skeletons
  17385. if ( json !== undefined ) {
  17386. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17387. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  17388. skeletons[ skeleton.uuid ] = skeleton;
  17389. }
  17390. }
  17391. return skeletons;
  17392. }
  17393. parseGeometries( json, shapes ) {
  17394. const geometries = {};
  17395. if ( json !== undefined ) {
  17396. const bufferGeometryLoader = new BufferGeometryLoader();
  17397. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17398. let geometry;
  17399. const data = json[ i ];
  17400. switch ( data.type ) {
  17401. case 'BufferGeometry':
  17402. case 'InstancedBufferGeometry':
  17403. geometry = bufferGeometryLoader.parse( data );
  17404. break;
  17405. default:
  17406. if ( data.type in Geometries ) {
  17407. geometry = Geometries[ data.type ].fromJSON( data, shapes );
  17408. } else {
  17409. console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` );
  17410. }
  17411. }
  17412. geometry.uuid = data.uuid;
  17413. if ( data.name !== undefined ) geometry.name = data.name;
  17414. if ( data.userData !== undefined ) geometry.userData = data.userData;
  17415. geometries[ data.uuid ] = geometry;
  17416. }
  17417. }
  17418. return geometries;
  17419. }
  17420. parseMaterials( json, textures ) {
  17421. const cache = {}; // MultiMaterial
  17422. const materials = {};
  17423. if ( json !== undefined ) {
  17424. const loader = new MaterialLoader();
  17425. loader.setTextures( textures );
  17426. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17427. const data = json[ i ];
  17428. if ( cache[ data.uuid ] === undefined ) {
  17429. cache[ data.uuid ] = loader.parse( data );
  17430. }
  17431. materials[ data.uuid ] = cache[ data.uuid ];
  17432. }
  17433. }
  17434. return materials;
  17435. }
  17436. parseAnimations( json ) {
  17437. const animations = {};
  17438. if ( json !== undefined ) {
  17439. for ( let i = 0; i < json.length; i ++ ) {
  17440. const data = json[ i ];
  17441. const clip = AnimationClip.parse( data );
  17442. animations[ clip.uuid ] = clip;
  17443. }
  17444. }
  17445. return animations;
  17446. }
  17447. parseImages( json, onLoad ) {
  17448. const scope = this;
  17449. const images = {};
  17450. let loader;
  17451. function loadImage( url ) {
  17452. scope.manager.itemStart( url );
  17453. return loader.load( url, function () {
  17454. scope.manager.itemEnd( url );
  17455. }, undefined, function () {
  17456. scope.manager.itemError( url );
  17457. scope.manager.itemEnd( url );
  17458. } );
  17459. }
  17460. function deserializeImage( image ) {
  17461. if ( typeof image === 'string' ) {
  17462. const url = image;
  17463. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17464. return loadImage( path );
  17465. } else {
  17466. if ( image.data ) {
  17467. return {
  17468. data: getTypedArray( image.type, image.data ),
  17469. width: image.width,
  17470. height: image.height
  17471. };
  17472. } else {
  17473. return null;
  17474. }
  17475. }
  17476. }
  17477. if ( json !== undefined && json.length > 0 ) {
  17478. const manager = new LoadingManager( onLoad );
  17479. loader = new ImageLoader( manager );
  17480. loader.setCrossOrigin( this.crossOrigin );
  17481. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17482. const image = json[ i ];
  17483. const url = image.url;
  17484. if ( Array.isArray( url ) ) {
  17485. // load array of images e.g CubeTexture
  17486. const imageArray = [];
  17487. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17488. const currentUrl = url[ j ];
  17489. const deserializedImage = deserializeImage( currentUrl );
  17490. if ( deserializedImage !== null ) {
  17491. if ( deserializedImage instanceof HTMLImageElement ) {
  17492. imageArray.push( deserializedImage );
  17493. } else {
  17494. // special case: handle array of data textures for cube textures
  17495. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17496. }
  17497. }
  17498. }
  17499. images[ image.uuid ] = new Source( imageArray );
  17500. } else {
  17501. // load single image
  17502. const deserializedImage = deserializeImage( image.url );
  17503. images[ image.uuid ] = new Source( deserializedImage );
  17504. }
  17505. }
  17506. }
  17507. return images;
  17508. }
  17509. async parseImagesAsync( json ) {
  17510. const scope = this;
  17511. const images = {};
  17512. let loader;
  17513. async function deserializeImage( image ) {
  17514. if ( typeof image === 'string' ) {
  17515. const url = image;
  17516. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17517. return await loader.loadAsync( path );
  17518. } else {
  17519. if ( image.data ) {
  17520. return {
  17521. data: getTypedArray( image.type, image.data ),
  17522. width: image.width,
  17523. height: image.height
  17524. };
  17525. } else {
  17526. return null;
  17527. }
  17528. }
  17529. }
  17530. if ( json !== undefined && json.length > 0 ) {
  17531. loader = new ImageLoader( this.manager );
  17532. loader.setCrossOrigin( this.crossOrigin );
  17533. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17534. const image = json[ i ];
  17535. const url = image.url;
  17536. if ( Array.isArray( url ) ) {
  17537. // load array of images e.g CubeTexture
  17538. const imageArray = [];
  17539. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17540. const currentUrl = url[ j ];
  17541. const deserializedImage = await deserializeImage( currentUrl );
  17542. if ( deserializedImage !== null ) {
  17543. if ( deserializedImage instanceof HTMLImageElement ) {
  17544. imageArray.push( deserializedImage );
  17545. } else {
  17546. // special case: handle array of data textures for cube textures
  17547. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17548. }
  17549. }
  17550. }
  17551. images[ image.uuid ] = new Source( imageArray );
  17552. } else {
  17553. // load single image
  17554. const deserializedImage = await deserializeImage( image.url );
  17555. images[ image.uuid ] = new Source( deserializedImage );
  17556. }
  17557. }
  17558. }
  17559. return images;
  17560. }
  17561. parseTextures( json, images ) {
  17562. function parseConstant( value, type ) {
  17563. if ( typeof value === 'number' ) return value;
  17564. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  17565. return type[ value ];
  17566. }
  17567. const textures = {};
  17568. if ( json !== undefined ) {
  17569. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17570. const data = json[ i ];
  17571. if ( data.image === undefined ) {
  17572. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  17573. }
  17574. if ( images[ data.image ] === undefined ) {
  17575. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  17576. }
  17577. const source = images[ data.image ];
  17578. const image = source.data;
  17579. let texture;
  17580. if ( Array.isArray( image ) ) {
  17581. texture = new CubeTexture();
  17582. if ( image.length === 6 ) texture.needsUpdate = true;
  17583. } else {
  17584. if ( image && image.data ) {
  17585. texture = new DataTexture();
  17586. } else {
  17587. texture = new Texture();
  17588. }
  17589. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  17590. }
  17591. texture.source = source;
  17592. texture.uuid = data.uuid;
  17593. if ( data.name !== undefined ) texture.name = data.name;
  17594. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  17595. if ( data.channel !== undefined ) texture.channel = data.channel;
  17596. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  17597. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  17598. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  17599. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  17600. if ( data.wrap !== undefined ) {
  17601. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  17602. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  17603. }
  17604. if ( data.format !== undefined ) texture.format = data.format;
  17605. if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat;
  17606. if ( data.type !== undefined ) texture.type = data.type;
  17607. if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace;
  17608. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  17609. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  17610. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  17611. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  17612. if ( data.generateMipmaps !== undefined ) texture.generateMipmaps = data.generateMipmaps;
  17613. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  17614. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  17615. if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction;
  17616. if ( data.userData !== undefined ) texture.userData = data.userData;
  17617. textures[ data.uuid ] = texture;
  17618. }
  17619. }
  17620. return textures;
  17621. }
  17622. parseObject( data, geometries, materials, textures, animations ) {
  17623. let object;
  17624. function getGeometry( name ) {
  17625. if ( geometries[ name ] === undefined ) {
  17626. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  17627. }
  17628. return geometries[ name ];
  17629. }
  17630. function getMaterial( name ) {
  17631. if ( name === undefined ) return undefined;
  17632. if ( Array.isArray( name ) ) {
  17633. const array = [];
  17634. for ( let i = 0, l = name.length; i < l; i ++ ) {
  17635. const uuid = name[ i ];
  17636. if ( materials[ uuid ] === undefined ) {
  17637. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  17638. }
  17639. array.push( materials[ uuid ] );
  17640. }
  17641. return array;
  17642. }
  17643. if ( materials[ name ] === undefined ) {
  17644. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  17645. }
  17646. return materials[ name ];
  17647. }
  17648. function getTexture( uuid ) {
  17649. if ( textures[ uuid ] === undefined ) {
  17650. console.warn( 'THREE.ObjectLoader: Undefined texture', uuid );
  17651. }
  17652. return textures[ uuid ];
  17653. }
  17654. let geometry, material;
  17655. switch ( data.type ) {
  17656. case 'Scene':
  17657. object = new Scene();
  17658. if ( data.background !== undefined ) {
  17659. if ( Number.isInteger( data.background ) ) {
  17660. object.background = new Color( data.background );
  17661. } else {
  17662. object.background = getTexture( data.background );
  17663. }
  17664. }
  17665. if ( data.environment !== undefined ) {
  17666. object.environment = getTexture( data.environment );
  17667. }
  17668. if ( data.fog !== undefined ) {
  17669. if ( data.fog.type === 'Fog' ) {
  17670. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  17671. } else if ( data.fog.type === 'FogExp2' ) {
  17672. object.fog = new FogExp2( data.fog.color, data.fog.density );
  17673. }
  17674. if ( data.fog.name !== '' ) {
  17675. object.fog.name = data.fog.name;
  17676. }
  17677. }
  17678. if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
  17679. if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
  17680. if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );
  17681. if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity;
  17682. if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );
  17683. break;
  17684. case 'PerspectiveCamera':
  17685. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  17686. if ( data.focus !== undefined ) object.focus = data.focus;
  17687. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17688. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  17689. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  17690. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17691. break;
  17692. case 'OrthographicCamera':
  17693. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  17694. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17695. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17696. break;
  17697. case 'AmbientLight':
  17698. object = new AmbientLight( data.color, data.intensity );
  17699. break;
  17700. case 'DirectionalLight':
  17701. object = new DirectionalLight( data.color, data.intensity );
  17702. object.target = data.target || '';
  17703. break;
  17704. case 'PointLight':
  17705. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  17706. break;
  17707. case 'RectAreaLight':
  17708. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  17709. break;
  17710. case 'SpotLight':
  17711. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  17712. object.target = data.target || '';
  17713. break;
  17714. case 'HemisphereLight':
  17715. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  17716. break;
  17717. case 'LightProbe':
  17718. object = new LightProbe().fromJSON( data );
  17719. break;
  17720. case 'SkinnedMesh':
  17721. geometry = getGeometry( data.geometry );
  17722. material = getMaterial( data.material );
  17723. object = new SkinnedMesh( geometry, material );
  17724. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  17725. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  17726. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  17727. break;
  17728. case 'Mesh':
  17729. geometry = getGeometry( data.geometry );
  17730. material = getMaterial( data.material );
  17731. object = new Mesh( geometry, material );
  17732. break;
  17733. case 'InstancedMesh':
  17734. geometry = getGeometry( data.geometry );
  17735. material = getMaterial( data.material );
  17736. const count = data.count;
  17737. const instanceMatrix = data.instanceMatrix;
  17738. const instanceColor = data.instanceColor;
  17739. object = new InstancedMesh( geometry, material, count );
  17740. object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  17741. if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize );
  17742. break;
  17743. case 'BatchedMesh':
  17744. geometry = getGeometry( data.geometry );
  17745. material = getMaterial( data.material );
  17746. object = new BatchedMesh( data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material );
  17747. object.geometry = geometry;
  17748. object.perObjectFrustumCulled = data.perObjectFrustumCulled;
  17749. object.sortObjects = data.sortObjects;
  17750. object._drawRanges = data.drawRanges;
  17751. object._reservedRanges = data.reservedRanges;
  17752. object._visibility = data.visibility;
  17753. object._active = data.active;
  17754. object._bounds = data.bounds.map( bound => {
  17755. const box = new Box3();
  17756. box.min.fromArray( bound.boxMin );
  17757. box.max.fromArray( bound.boxMax );
  17758. const sphere = new Sphere();
  17759. sphere.radius = bound.sphereRadius;
  17760. sphere.center.fromArray( bound.sphereCenter );
  17761. return {
  17762. boxInitialized: bound.boxInitialized,
  17763. box: box,
  17764. sphereInitialized: bound.sphereInitialized,
  17765. sphere: sphere
  17766. };
  17767. } );
  17768. object._maxInstanceCount = data.maxInstanceCount;
  17769. object._maxVertexCount = data.maxVertexCount;
  17770. object._maxIndexCount = data.maxIndexCount;
  17771. object._geometryInitialized = data.geometryInitialized;
  17772. object._geometryCount = data.geometryCount;
  17773. object._matricesTexture = getTexture( data.matricesTexture.uuid );
  17774. if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
  17775. break;
  17776. case 'LOD':
  17777. object = new LOD();
  17778. break;
  17779. case 'Line':
  17780. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  17781. break;
  17782. case 'LineLoop':
  17783. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  17784. break;
  17785. case 'LineSegments':
  17786. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  17787. break;
  17788. case 'PointCloud':
  17789. case 'Points':
  17790. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  17791. break;
  17792. case 'Sprite':
  17793. object = new Sprite( getMaterial( data.material ) );
  17794. break;
  17795. case 'Group':
  17796. object = new Group();
  17797. break;
  17798. case 'Bone':
  17799. object = new Bone();
  17800. break;
  17801. default:
  17802. object = new Object3D();
  17803. }
  17804. object.uuid = data.uuid;
  17805. if ( data.name !== undefined ) object.name = data.name;
  17806. if ( data.matrix !== undefined ) {
  17807. object.matrix.fromArray( data.matrix );
  17808. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  17809. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  17810. } else {
  17811. if ( data.position !== undefined ) object.position.fromArray( data.position );
  17812. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  17813. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  17814. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  17815. }
  17816. if ( data.up !== undefined ) object.up.fromArray( data.up );
  17817. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  17818. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  17819. if ( data.shadow ) {
  17820. if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
  17821. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  17822. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  17823. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  17824. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  17825. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  17826. }
  17827. if ( data.visible !== undefined ) object.visible = data.visible;
  17828. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  17829. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  17830. if ( data.userData !== undefined ) object.userData = data.userData;
  17831. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  17832. if ( data.children !== undefined ) {
  17833. const children = data.children;
  17834. for ( let i = 0; i < children.length; i ++ ) {
  17835. object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
  17836. }
  17837. }
  17838. if ( data.animations !== undefined ) {
  17839. const objectAnimations = data.animations;
  17840. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  17841. const uuid = objectAnimations[ i ];
  17842. object.animations.push( animations[ uuid ] );
  17843. }
  17844. }
  17845. if ( data.type === 'LOD' ) {
  17846. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  17847. const levels = data.levels;
  17848. for ( let l = 0; l < levels.length; l ++ ) {
  17849. const level = levels[ l ];
  17850. const child = object.getObjectByProperty( 'uuid', level.object );
  17851. if ( child !== undefined ) {
  17852. object.addLevel( child, level.distance, level.hysteresis );
  17853. }
  17854. }
  17855. }
  17856. return object;
  17857. }
  17858. bindSkeletons( object, skeletons ) {
  17859. if ( Object.keys( skeletons ).length === 0 ) return;
  17860. object.traverse( function ( child ) {
  17861. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  17862. const skeleton = skeletons[ child.skeleton ];
  17863. if ( skeleton === undefined ) {
  17864. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  17865. } else {
  17866. child.bind( skeleton, child.bindMatrix );
  17867. }
  17868. }
  17869. } );
  17870. }
  17871. bindLightTargets( object ) {
  17872. object.traverse( function ( child ) {
  17873. if ( child.isDirectionalLight || child.isSpotLight ) {
  17874. const uuid = child.target;
  17875. const target = object.getObjectByProperty( 'uuid', uuid );
  17876. if ( target !== undefined ) {
  17877. child.target = target;
  17878. } else {
  17879. child.target = new Object3D();
  17880. }
  17881. }
  17882. } );
  17883. }
  17884. }
  17885. const TEXTURE_MAPPING = {
  17886. UVMapping: UVMapping,
  17887. CubeReflectionMapping: CubeReflectionMapping,
  17888. CubeRefractionMapping: CubeRefractionMapping,
  17889. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  17890. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  17891. CubeUVReflectionMapping: CubeUVReflectionMapping
  17892. };
  17893. const TEXTURE_WRAPPING = {
  17894. RepeatWrapping: RepeatWrapping,
  17895. ClampToEdgeWrapping: ClampToEdgeWrapping,
  17896. MirroredRepeatWrapping: MirroredRepeatWrapping
  17897. };
  17898. const TEXTURE_FILTER = {
  17899. NearestFilter: NearestFilter,
  17900. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  17901. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  17902. LinearFilter: LinearFilter,
  17903. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  17904. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  17905. };
  17906. class ImageBitmapLoader extends Loader {
  17907. constructor( manager ) {
  17908. super( manager );
  17909. this.isImageBitmapLoader = true;
  17910. if ( typeof createImageBitmap === 'undefined' ) {
  17911. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  17912. }
  17913. if ( typeof fetch === 'undefined' ) {
  17914. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  17915. }
  17916. this.options = { premultiplyAlpha: 'none' };
  17917. }
  17918. setOptions( options ) {
  17919. this.options = options;
  17920. return this;
  17921. }
  17922. load( url, onLoad, onProgress, onError ) {
  17923. if ( url === undefined ) url = '';
  17924. if ( this.path !== undefined ) url = this.path + url;
  17925. url = this.manager.resolveURL( url );
  17926. const scope = this;
  17927. const cached = Cache.get( url );
  17928. if ( cached !== undefined ) {
  17929. scope.manager.itemStart( url );
  17930. // If cached is a promise, wait for it to resolve
  17931. if ( cached.then ) {
  17932. cached.then( imageBitmap => {
  17933. if ( onLoad ) onLoad( imageBitmap );
  17934. scope.manager.itemEnd( url );
  17935. } ).catch( e => {
  17936. if ( onError ) onError( e );
  17937. } );
  17938. return;
  17939. }
  17940. // If cached is not a promise (i.e., it's already an imageBitmap)
  17941. setTimeout( function () {
  17942. if ( onLoad ) onLoad( cached );
  17943. scope.manager.itemEnd( url );
  17944. }, 0 );
  17945. return cached;
  17946. }
  17947. const fetchOptions = {};
  17948. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  17949. fetchOptions.headers = this.requestHeader;
  17950. const promise = fetch( url, fetchOptions ).then( function ( res ) {
  17951. return res.blob();
  17952. } ).then( function ( blob ) {
  17953. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  17954. } ).then( function ( imageBitmap ) {
  17955. Cache.add( url, imageBitmap );
  17956. if ( onLoad ) onLoad( imageBitmap );
  17957. scope.manager.itemEnd( url );
  17958. return imageBitmap;
  17959. } ).catch( function ( e ) {
  17960. if ( onError ) onError( e );
  17961. Cache.remove( url );
  17962. scope.manager.itemError( url );
  17963. scope.manager.itemEnd( url );
  17964. } );
  17965. Cache.add( url, promise );
  17966. scope.manager.itemStart( url );
  17967. }
  17968. }
  17969. let _context;
  17970. class AudioContext {
  17971. static getContext() {
  17972. if ( _context === undefined ) {
  17973. _context = new ( window.AudioContext || window.webkitAudioContext )();
  17974. }
  17975. return _context;
  17976. }
  17977. static setContext( value ) {
  17978. _context = value;
  17979. }
  17980. }
  17981. class AudioLoader extends Loader {
  17982. constructor( manager ) {
  17983. super( manager );
  17984. }
  17985. load( url, onLoad, onProgress, onError ) {
  17986. const scope = this;
  17987. const loader = new FileLoader( this.manager );
  17988. loader.setResponseType( 'arraybuffer' );
  17989. loader.setPath( this.path );
  17990. loader.setRequestHeader( this.requestHeader );
  17991. loader.setWithCredentials( this.withCredentials );
  17992. loader.load( url, function ( buffer ) {
  17993. try {
  17994. // Create a copy of the buffer. The `decodeAudioData` method
  17995. // detaches the buffer when complete, preventing reuse.
  17996. const bufferCopy = buffer.slice( 0 );
  17997. const context = AudioContext.getContext();
  17998. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  17999. onLoad( audioBuffer );
  18000. } ).catch( handleError );
  18001. } catch ( e ) {
  18002. handleError( e );
  18003. }
  18004. }, onProgress, onError );
  18005. function handleError( e ) {
  18006. if ( onError ) {
  18007. onError( e );
  18008. } else {
  18009. console.error( e );
  18010. }
  18011. scope.manager.itemError( url );
  18012. }
  18013. }
  18014. }
  18015. const _eyeRight = /*@__PURE__*/ new Matrix4();
  18016. const _eyeLeft = /*@__PURE__*/ new Matrix4();
  18017. const _projectionMatrix = /*@__PURE__*/ new Matrix4();
  18018. class StereoCamera {
  18019. constructor() {
  18020. this.type = 'StereoCamera';
  18021. this.aspect = 1;
  18022. this.eyeSep = 0.064;
  18023. this.cameraL = new PerspectiveCamera();
  18024. this.cameraL.layers.enable( 1 );
  18025. this.cameraL.matrixAutoUpdate = false;
  18026. this.cameraR = new PerspectiveCamera();
  18027. this.cameraR.layers.enable( 2 );
  18028. this.cameraR.matrixAutoUpdate = false;
  18029. this._cache = {
  18030. focus: null,
  18031. fov: null,
  18032. aspect: null,
  18033. near: null,
  18034. far: null,
  18035. zoom: null,
  18036. eyeSep: null
  18037. };
  18038. }
  18039. update( camera ) {
  18040. const cache = this._cache;
  18041. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  18042. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  18043. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  18044. if ( needsUpdate ) {
  18045. cache.focus = camera.focus;
  18046. cache.fov = camera.fov;
  18047. cache.aspect = camera.aspect * this.aspect;
  18048. cache.near = camera.near;
  18049. cache.far = camera.far;
  18050. cache.zoom = camera.zoom;
  18051. cache.eyeSep = this.eyeSep;
  18052. // Off-axis stereoscopic effect based on
  18053. // http://paulbourke.net/stereographics/stereorender/
  18054. _projectionMatrix.copy( camera.projectionMatrix );
  18055. const eyeSepHalf = cache.eyeSep / 2;
  18056. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  18057. const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  18058. let xmin, xmax;
  18059. // translate xOffset
  18060. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  18061. _eyeRight.elements[ 12 ] = eyeSepHalf;
  18062. // for left eye
  18063. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  18064. xmax = ymax * cache.aspect + eyeSepOnProjection;
  18065. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18066. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18067. this.cameraL.projectionMatrix.copy( _projectionMatrix );
  18068. // for right eye
  18069. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  18070. xmax = ymax * cache.aspect - eyeSepOnProjection;
  18071. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18072. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18073. this.cameraR.projectionMatrix.copy( _projectionMatrix );
  18074. }
  18075. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  18076. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  18077. }
  18078. }
  18079. class ArrayCamera extends PerspectiveCamera {
  18080. constructor( array = [] ) {
  18081. super();
  18082. this.isArrayCamera = true;
  18083. this.cameras = array;
  18084. }
  18085. }
  18086. class Clock {
  18087. constructor( autoStart = true ) {
  18088. this.autoStart = autoStart;
  18089. this.startTime = 0;
  18090. this.oldTime = 0;
  18091. this.elapsedTime = 0;
  18092. this.running = false;
  18093. }
  18094. start() {
  18095. this.startTime = now();
  18096. this.oldTime = this.startTime;
  18097. this.elapsedTime = 0;
  18098. this.running = true;
  18099. }
  18100. stop() {
  18101. this.getElapsedTime();
  18102. this.running = false;
  18103. this.autoStart = false;
  18104. }
  18105. getElapsedTime() {
  18106. this.getDelta();
  18107. return this.elapsedTime;
  18108. }
  18109. getDelta() {
  18110. let diff = 0;
  18111. if ( this.autoStart && ! this.running ) {
  18112. this.start();
  18113. return 0;
  18114. }
  18115. if ( this.running ) {
  18116. const newTime = now();
  18117. diff = ( newTime - this.oldTime ) / 1000;
  18118. this.oldTime = newTime;
  18119. this.elapsedTime += diff;
  18120. }
  18121. return diff;
  18122. }
  18123. }
  18124. function now() {
  18125. return performance.now();
  18126. }
  18127. const _position$1 = /*@__PURE__*/ new Vector3();
  18128. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  18129. const _scale$1 = /*@__PURE__*/ new Vector3();
  18130. const _orientation$1 = /*@__PURE__*/ new Vector3();
  18131. class AudioListener extends Object3D {
  18132. constructor() {
  18133. super();
  18134. this.type = 'AudioListener';
  18135. this.context = AudioContext.getContext();
  18136. this.gain = this.context.createGain();
  18137. this.gain.connect( this.context.destination );
  18138. this.filter = null;
  18139. this.timeDelta = 0;
  18140. // private
  18141. this._clock = new Clock();
  18142. }
  18143. getInput() {
  18144. return this.gain;
  18145. }
  18146. removeFilter() {
  18147. if ( this.filter !== null ) {
  18148. this.gain.disconnect( this.filter );
  18149. this.filter.disconnect( this.context.destination );
  18150. this.gain.connect( this.context.destination );
  18151. this.filter = null;
  18152. }
  18153. return this;
  18154. }
  18155. getFilter() {
  18156. return this.filter;
  18157. }
  18158. setFilter( value ) {
  18159. if ( this.filter !== null ) {
  18160. this.gain.disconnect( this.filter );
  18161. this.filter.disconnect( this.context.destination );
  18162. } else {
  18163. this.gain.disconnect( this.context.destination );
  18164. }
  18165. this.filter = value;
  18166. this.gain.connect( this.filter );
  18167. this.filter.connect( this.context.destination );
  18168. return this;
  18169. }
  18170. getMasterVolume() {
  18171. return this.gain.gain.value;
  18172. }
  18173. setMasterVolume( value ) {
  18174. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18175. return this;
  18176. }
  18177. updateMatrixWorld( force ) {
  18178. super.updateMatrixWorld( force );
  18179. const listener = this.context.listener;
  18180. const up = this.up;
  18181. this.timeDelta = this._clock.getDelta();
  18182. this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 );
  18183. _orientation$1.set( 0, 0, - 1 ).applyQuaternion( _quaternion$1 );
  18184. if ( listener.positionX ) {
  18185. // code path for Chrome (see #14393)
  18186. const endTime = this.context.currentTime + this.timeDelta;
  18187. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  18188. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  18189. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  18190. listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime );
  18191. listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime );
  18192. listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  18193. listener.upX.linearRampToValueAtTime( up.x, endTime );
  18194. listener.upY.linearRampToValueAtTime( up.y, endTime );
  18195. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  18196. } else {
  18197. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  18198. listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z );
  18199. }
  18200. }
  18201. }
  18202. class Audio extends Object3D {
  18203. constructor( listener ) {
  18204. super();
  18205. this.type = 'Audio';
  18206. this.listener = listener;
  18207. this.context = listener.context;
  18208. this.gain = this.context.createGain();
  18209. this.gain.connect( listener.getInput() );
  18210. this.autoplay = false;
  18211. this.buffer = null;
  18212. this.detune = 0;
  18213. this.loop = false;
  18214. this.loopStart = 0;
  18215. this.loopEnd = 0;
  18216. this.offset = 0;
  18217. this.duration = undefined;
  18218. this.playbackRate = 1;
  18219. this.isPlaying = false;
  18220. this.hasPlaybackControl = true;
  18221. this.source = null;
  18222. this.sourceType = 'empty';
  18223. this._startedAt = 0;
  18224. this._progress = 0;
  18225. this._connected = false;
  18226. this.filters = [];
  18227. }
  18228. getOutput() {
  18229. return this.gain;
  18230. }
  18231. setNodeSource( audioNode ) {
  18232. this.hasPlaybackControl = false;
  18233. this.sourceType = 'audioNode';
  18234. this.source = audioNode;
  18235. this.connect();
  18236. return this;
  18237. }
  18238. setMediaElementSource( mediaElement ) {
  18239. this.hasPlaybackControl = false;
  18240. this.sourceType = 'mediaNode';
  18241. this.source = this.context.createMediaElementSource( mediaElement );
  18242. this.connect();
  18243. return this;
  18244. }
  18245. setMediaStreamSource( mediaStream ) {
  18246. this.hasPlaybackControl = false;
  18247. this.sourceType = 'mediaStreamNode';
  18248. this.source = this.context.createMediaStreamSource( mediaStream );
  18249. this.connect();
  18250. return this;
  18251. }
  18252. setBuffer( audioBuffer ) {
  18253. this.buffer = audioBuffer;
  18254. this.sourceType = 'buffer';
  18255. if ( this.autoplay ) this.play();
  18256. return this;
  18257. }
  18258. play( delay = 0 ) {
  18259. if ( this.isPlaying === true ) {
  18260. console.warn( 'THREE.Audio: Audio is already playing.' );
  18261. return;
  18262. }
  18263. if ( this.hasPlaybackControl === false ) {
  18264. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18265. return;
  18266. }
  18267. this._startedAt = this.context.currentTime + delay;
  18268. const source = this.context.createBufferSource();
  18269. source.buffer = this.buffer;
  18270. source.loop = this.loop;
  18271. source.loopStart = this.loopStart;
  18272. source.loopEnd = this.loopEnd;
  18273. source.onended = this.onEnded.bind( this );
  18274. source.start( this._startedAt, this._progress + this.offset, this.duration );
  18275. this.isPlaying = true;
  18276. this.source = source;
  18277. this.setDetune( this.detune );
  18278. this.setPlaybackRate( this.playbackRate );
  18279. return this.connect();
  18280. }
  18281. pause() {
  18282. if ( this.hasPlaybackControl === false ) {
  18283. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18284. return;
  18285. }
  18286. if ( this.isPlaying === true ) {
  18287. // update current progress
  18288. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  18289. if ( this.loop === true ) {
  18290. // ensure _progress does not exceed duration with looped audios
  18291. this._progress = this._progress % ( this.duration || this.buffer.duration );
  18292. }
  18293. this.source.stop();
  18294. this.source.onended = null;
  18295. this.isPlaying = false;
  18296. }
  18297. return this;
  18298. }
  18299. stop( delay = 0 ) {
  18300. if ( this.hasPlaybackControl === false ) {
  18301. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18302. return;
  18303. }
  18304. this._progress = 0;
  18305. if ( this.source !== null ) {
  18306. this.source.stop( this.context.currentTime + delay );
  18307. this.source.onended = null;
  18308. }
  18309. this.isPlaying = false;
  18310. return this;
  18311. }
  18312. connect() {
  18313. if ( this.filters.length > 0 ) {
  18314. this.source.connect( this.filters[ 0 ] );
  18315. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18316. this.filters[ i - 1 ].connect( this.filters[ i ] );
  18317. }
  18318. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  18319. } else {
  18320. this.source.connect( this.getOutput() );
  18321. }
  18322. this._connected = true;
  18323. return this;
  18324. }
  18325. disconnect() {
  18326. if ( this._connected === false ) {
  18327. return;
  18328. }
  18329. if ( this.filters.length > 0 ) {
  18330. this.source.disconnect( this.filters[ 0 ] );
  18331. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18332. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  18333. }
  18334. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  18335. } else {
  18336. this.source.disconnect( this.getOutput() );
  18337. }
  18338. this._connected = false;
  18339. return this;
  18340. }
  18341. getFilters() {
  18342. return this.filters;
  18343. }
  18344. setFilters( value ) {
  18345. if ( ! value ) value = [];
  18346. if ( this._connected === true ) {
  18347. this.disconnect();
  18348. this.filters = value.slice();
  18349. this.connect();
  18350. } else {
  18351. this.filters = value.slice();
  18352. }
  18353. return this;
  18354. }
  18355. setDetune( value ) {
  18356. this.detune = value;
  18357. if ( this.isPlaying === true && this.source.detune !== undefined ) {
  18358. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  18359. }
  18360. return this;
  18361. }
  18362. getDetune() {
  18363. return this.detune;
  18364. }
  18365. getFilter() {
  18366. return this.getFilters()[ 0 ];
  18367. }
  18368. setFilter( filter ) {
  18369. return this.setFilters( filter ? [ filter ] : [] );
  18370. }
  18371. setPlaybackRate( value ) {
  18372. if ( this.hasPlaybackControl === false ) {
  18373. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18374. return;
  18375. }
  18376. this.playbackRate = value;
  18377. if ( this.isPlaying === true ) {
  18378. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  18379. }
  18380. return this;
  18381. }
  18382. getPlaybackRate() {
  18383. return this.playbackRate;
  18384. }
  18385. onEnded() {
  18386. this.isPlaying = false;
  18387. this._progress = 0;
  18388. }
  18389. getLoop() {
  18390. if ( this.hasPlaybackControl === false ) {
  18391. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18392. return false;
  18393. }
  18394. return this.loop;
  18395. }
  18396. setLoop( value ) {
  18397. if ( this.hasPlaybackControl === false ) {
  18398. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18399. return;
  18400. }
  18401. this.loop = value;
  18402. if ( this.isPlaying === true ) {
  18403. this.source.loop = this.loop;
  18404. }
  18405. return this;
  18406. }
  18407. setLoopStart( value ) {
  18408. this.loopStart = value;
  18409. return this;
  18410. }
  18411. setLoopEnd( value ) {
  18412. this.loopEnd = value;
  18413. return this;
  18414. }
  18415. getVolume() {
  18416. return this.gain.gain.value;
  18417. }
  18418. setVolume( value ) {
  18419. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18420. return this;
  18421. }
  18422. copy( source, recursive ) {
  18423. super.copy( source, recursive );
  18424. if ( source.sourceType !== 'buffer' ) {
  18425. console.warn( 'THREE.Audio: Audio source type cannot be copied.' );
  18426. return this;
  18427. }
  18428. this.autoplay = source.autoplay;
  18429. this.buffer = source.buffer;
  18430. this.detune = source.detune;
  18431. this.loop = source.loop;
  18432. this.loopStart = source.loopStart;
  18433. this.loopEnd = source.loopEnd;
  18434. this.offset = source.offset;
  18435. this.duration = source.duration;
  18436. this.playbackRate = source.playbackRate;
  18437. this.hasPlaybackControl = source.hasPlaybackControl;
  18438. this.sourceType = source.sourceType;
  18439. this.filters = source.filters.slice();
  18440. return this;
  18441. }
  18442. clone( recursive ) {
  18443. return new this.constructor( this.listener ).copy( this, recursive );
  18444. }
  18445. }
  18446. const _position = /*@__PURE__*/ new Vector3();
  18447. const _quaternion = /*@__PURE__*/ new Quaternion();
  18448. const _scale = /*@__PURE__*/ new Vector3();
  18449. const _orientation = /*@__PURE__*/ new Vector3();
  18450. class PositionalAudio extends Audio {
  18451. constructor( listener ) {
  18452. super( listener );
  18453. this.panner = this.context.createPanner();
  18454. this.panner.panningModel = 'HRTF';
  18455. this.panner.connect( this.gain );
  18456. }
  18457. connect() {
  18458. super.connect();
  18459. this.panner.connect( this.gain );
  18460. }
  18461. disconnect() {
  18462. super.disconnect();
  18463. this.panner.disconnect( this.gain );
  18464. }
  18465. getOutput() {
  18466. return this.panner;
  18467. }
  18468. getRefDistance() {
  18469. return this.panner.refDistance;
  18470. }
  18471. setRefDistance( value ) {
  18472. this.panner.refDistance = value;
  18473. return this;
  18474. }
  18475. getRolloffFactor() {
  18476. return this.panner.rolloffFactor;
  18477. }
  18478. setRolloffFactor( value ) {
  18479. this.panner.rolloffFactor = value;
  18480. return this;
  18481. }
  18482. getDistanceModel() {
  18483. return this.panner.distanceModel;
  18484. }
  18485. setDistanceModel( value ) {
  18486. this.panner.distanceModel = value;
  18487. return this;
  18488. }
  18489. getMaxDistance() {
  18490. return this.panner.maxDistance;
  18491. }
  18492. setMaxDistance( value ) {
  18493. this.panner.maxDistance = value;
  18494. return this;
  18495. }
  18496. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  18497. this.panner.coneInnerAngle = coneInnerAngle;
  18498. this.panner.coneOuterAngle = coneOuterAngle;
  18499. this.panner.coneOuterGain = coneOuterGain;
  18500. return this;
  18501. }
  18502. updateMatrixWorld( force ) {
  18503. super.updateMatrixWorld( force );
  18504. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  18505. this.matrixWorld.decompose( _position, _quaternion, _scale );
  18506. _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
  18507. const panner = this.panner;
  18508. if ( panner.positionX ) {
  18509. // code path for Chrome and Firefox (see #14393)
  18510. const endTime = this.context.currentTime + this.listener.timeDelta;
  18511. panner.positionX.linearRampToValueAtTime( _position.x, endTime );
  18512. panner.positionY.linearRampToValueAtTime( _position.y, endTime );
  18513. panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
  18514. panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
  18515. panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
  18516. panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
  18517. } else {
  18518. panner.setPosition( _position.x, _position.y, _position.z );
  18519. panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
  18520. }
  18521. }
  18522. }
  18523. class AudioAnalyser {
  18524. constructor( audio, fftSize = 2048 ) {
  18525. this.analyser = audio.context.createAnalyser();
  18526. this.analyser.fftSize = fftSize;
  18527. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  18528. audio.getOutput().connect( this.analyser );
  18529. }
  18530. getFrequencyData() {
  18531. this.analyser.getByteFrequencyData( this.data );
  18532. return this.data;
  18533. }
  18534. getAverageFrequency() {
  18535. let value = 0;
  18536. const data = this.getFrequencyData();
  18537. for ( let i = 0; i < data.length; i ++ ) {
  18538. value += data[ i ];
  18539. }
  18540. return value / data.length;
  18541. }
  18542. }
  18543. class PropertyMixer {
  18544. constructor( binding, typeName, valueSize ) {
  18545. this.binding = binding;
  18546. this.valueSize = valueSize;
  18547. let mixFunction,
  18548. mixFunctionAdditive,
  18549. setIdentity;
  18550. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  18551. //
  18552. // interpolators can use .buffer as their .result
  18553. // the data then goes to 'incoming'
  18554. //
  18555. // 'accu0' and 'accu1' are used frame-interleaved for
  18556. // the cumulative result and are compared to detect
  18557. // changes
  18558. //
  18559. // 'orig' stores the original state of the property
  18560. //
  18561. // 'add' is used for additive cumulative results
  18562. //
  18563. // 'work' is optional and is only present for quaternion types. It is used
  18564. // to store intermediate quaternion multiplication results
  18565. switch ( typeName ) {
  18566. case 'quaternion':
  18567. mixFunction = this._slerp;
  18568. mixFunctionAdditive = this._slerpAdditive;
  18569. setIdentity = this._setAdditiveIdentityQuaternion;
  18570. this.buffer = new Float64Array( valueSize * 6 );
  18571. this._workIndex = 5;
  18572. break;
  18573. case 'string':
  18574. case 'bool':
  18575. mixFunction = this._select;
  18576. // Use the regular mix function and for additive on these types,
  18577. // additive is not relevant for non-numeric types
  18578. mixFunctionAdditive = this._select;
  18579. setIdentity = this._setAdditiveIdentityOther;
  18580. this.buffer = new Array( valueSize * 5 );
  18581. break;
  18582. default:
  18583. mixFunction = this._lerp;
  18584. mixFunctionAdditive = this._lerpAdditive;
  18585. setIdentity = this._setAdditiveIdentityNumeric;
  18586. this.buffer = new Float64Array( valueSize * 5 );
  18587. }
  18588. this._mixBufferRegion = mixFunction;
  18589. this._mixBufferRegionAdditive = mixFunctionAdditive;
  18590. this._setIdentity = setIdentity;
  18591. this._origIndex = 3;
  18592. this._addIndex = 4;
  18593. this.cumulativeWeight = 0;
  18594. this.cumulativeWeightAdditive = 0;
  18595. this.useCount = 0;
  18596. this.referenceCount = 0;
  18597. }
  18598. // accumulate data in the 'incoming' region into 'accu<i>'
  18599. accumulate( accuIndex, weight ) {
  18600. // note: happily accumulating nothing when weight = 0, the caller knows
  18601. // the weight and shouldn't have made the call in the first place
  18602. const buffer = this.buffer,
  18603. stride = this.valueSize,
  18604. offset = accuIndex * stride + stride;
  18605. let currentWeight = this.cumulativeWeight;
  18606. if ( currentWeight === 0 ) {
  18607. // accuN := incoming * weight
  18608. for ( let i = 0; i !== stride; ++ i ) {
  18609. buffer[ offset + i ] = buffer[ i ];
  18610. }
  18611. currentWeight = weight;
  18612. } else {
  18613. // accuN := accuN + incoming * weight
  18614. currentWeight += weight;
  18615. const mix = weight / currentWeight;
  18616. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  18617. }
  18618. this.cumulativeWeight = currentWeight;
  18619. }
  18620. // accumulate data in the 'incoming' region into 'add'
  18621. accumulateAdditive( weight ) {
  18622. const buffer = this.buffer,
  18623. stride = this.valueSize,
  18624. offset = stride * this._addIndex;
  18625. if ( this.cumulativeWeightAdditive === 0 ) {
  18626. // add = identity
  18627. this._setIdentity();
  18628. }
  18629. // add := add + incoming * weight
  18630. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  18631. this.cumulativeWeightAdditive += weight;
  18632. }
  18633. // apply the state of 'accu<i>' to the binding when accus differ
  18634. apply( accuIndex ) {
  18635. const stride = this.valueSize,
  18636. buffer = this.buffer,
  18637. offset = accuIndex * stride + stride,
  18638. weight = this.cumulativeWeight,
  18639. weightAdditive = this.cumulativeWeightAdditive,
  18640. binding = this.binding;
  18641. this.cumulativeWeight = 0;
  18642. this.cumulativeWeightAdditive = 0;
  18643. if ( weight < 1 ) {
  18644. // accuN := accuN + original * ( 1 - cumulativeWeight )
  18645. const originalValueOffset = stride * this._origIndex;
  18646. this._mixBufferRegion(
  18647. buffer, offset, originalValueOffset, 1 - weight, stride );
  18648. }
  18649. if ( weightAdditive > 0 ) {
  18650. // accuN := accuN + additive accuN
  18651. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  18652. }
  18653. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  18654. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  18655. // value has changed -> update scene graph
  18656. binding.setValue( buffer, offset );
  18657. break;
  18658. }
  18659. }
  18660. }
  18661. // remember the state of the bound property and copy it to both accus
  18662. saveOriginalState() {
  18663. const binding = this.binding;
  18664. const buffer = this.buffer,
  18665. stride = this.valueSize,
  18666. originalValueOffset = stride * this._origIndex;
  18667. binding.getValue( buffer, originalValueOffset );
  18668. // accu[0..1] := orig -- initially detect changes against the original
  18669. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  18670. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  18671. }
  18672. // Add to identity for additive
  18673. this._setIdentity();
  18674. this.cumulativeWeight = 0;
  18675. this.cumulativeWeightAdditive = 0;
  18676. }
  18677. // apply the state previously taken via 'saveOriginalState' to the binding
  18678. restoreOriginalState() {
  18679. const originalValueOffset = this.valueSize * 3;
  18680. this.binding.setValue( this.buffer, originalValueOffset );
  18681. }
  18682. _setAdditiveIdentityNumeric() {
  18683. const startIndex = this._addIndex * this.valueSize;
  18684. const endIndex = startIndex + this.valueSize;
  18685. for ( let i = startIndex; i < endIndex; i ++ ) {
  18686. this.buffer[ i ] = 0;
  18687. }
  18688. }
  18689. _setAdditiveIdentityQuaternion() {
  18690. this._setAdditiveIdentityNumeric();
  18691. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  18692. }
  18693. _setAdditiveIdentityOther() {
  18694. const startIndex = this._origIndex * this.valueSize;
  18695. const targetIndex = this._addIndex * this.valueSize;
  18696. for ( let i = 0; i < this.valueSize; i ++ ) {
  18697. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  18698. }
  18699. }
  18700. // mix functions
  18701. _select( buffer, dstOffset, srcOffset, t, stride ) {
  18702. if ( t >= 0.5 ) {
  18703. for ( let i = 0; i !== stride; ++ i ) {
  18704. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  18705. }
  18706. }
  18707. }
  18708. _slerp( buffer, dstOffset, srcOffset, t ) {
  18709. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  18710. }
  18711. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18712. const workOffset = this._workIndex * stride;
  18713. // Store result in intermediate buffer offset
  18714. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  18715. // Slerp to the intermediate result
  18716. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  18717. }
  18718. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  18719. const s = 1 - t;
  18720. for ( let i = 0; i !== stride; ++ i ) {
  18721. const j = dstOffset + i;
  18722. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  18723. }
  18724. }
  18725. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18726. for ( let i = 0; i !== stride; ++ i ) {
  18727. const j = dstOffset + i;
  18728. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  18729. }
  18730. }
  18731. }
  18732. // Characters [].:/ are reserved for track binding syntax.
  18733. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  18734. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  18735. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  18736. // only latin characters, and the unicode \p{L} is not yet supported. So
  18737. // instead, we exclude reserved characters and match everything else.
  18738. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  18739. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  18740. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  18741. // be matched to parse the rest of the track name.
  18742. const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  18743. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  18744. const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  18745. // Object on target node, and accessor. May not contain reserved
  18746. // characters. Accessor may contain any character except closing bracket.
  18747. const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  18748. // Property and accessor. May not contain reserved characters. Accessor may
  18749. // contain any non-bracket characters.
  18750. const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  18751. const _trackRe = new RegExp( ''
  18752. + '^'
  18753. + _directoryRe
  18754. + _nodeRe
  18755. + _objectRe
  18756. + _propertyRe
  18757. + '$'
  18758. );
  18759. const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ];
  18760. class Composite {
  18761. constructor( targetGroup, path, optionalParsedPath ) {
  18762. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  18763. this._targetGroup = targetGroup;
  18764. this._bindings = targetGroup.subscribe_( path, parsedPath );
  18765. }
  18766. getValue( array, offset ) {
  18767. this.bind(); // bind all binding
  18768. const firstValidIndex = this._targetGroup.nCachedObjects_,
  18769. binding = this._bindings[ firstValidIndex ];
  18770. // and only call .getValue on the first
  18771. if ( binding !== undefined ) binding.getValue( array, offset );
  18772. }
  18773. setValue( array, offset ) {
  18774. const bindings = this._bindings;
  18775. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18776. bindings[ i ].setValue( array, offset );
  18777. }
  18778. }
  18779. bind() {
  18780. const bindings = this._bindings;
  18781. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18782. bindings[ i ].bind();
  18783. }
  18784. }
  18785. unbind() {
  18786. const bindings = this._bindings;
  18787. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18788. bindings[ i ].unbind();
  18789. }
  18790. }
  18791. }
  18792. // Note: This class uses a State pattern on a per-method basis:
  18793. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  18794. // prototype version of these methods with one that represents
  18795. // the bound state. When the property is not found, the methods
  18796. // become no-ops.
  18797. class PropertyBinding {
  18798. constructor( rootNode, path, parsedPath ) {
  18799. this.path = path;
  18800. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  18801. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName );
  18802. this.rootNode = rootNode;
  18803. // initial state of these methods that calls 'bind'
  18804. this.getValue = this._getValue_unbound;
  18805. this.setValue = this._setValue_unbound;
  18806. }
  18807. static create( root, path, parsedPath ) {
  18808. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  18809. return new PropertyBinding( root, path, parsedPath );
  18810. } else {
  18811. return new PropertyBinding.Composite( root, path, parsedPath );
  18812. }
  18813. }
  18814. /**
  18815. * Replaces spaces with underscores and removes unsupported characters from
  18816. * node names, to ensure compatibility with parseTrackName().
  18817. *
  18818. * @param {string} name Node name to be sanitized.
  18819. * @return {string}
  18820. */
  18821. static sanitizeNodeName( name ) {
  18822. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  18823. }
  18824. static parseTrackName( trackName ) {
  18825. const matches = _trackRe.exec( trackName );
  18826. if ( matches === null ) {
  18827. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  18828. }
  18829. const results = {
  18830. // directoryName: matches[ 1 ], // (tschw) currently unused
  18831. nodeName: matches[ 2 ],
  18832. objectName: matches[ 3 ],
  18833. objectIndex: matches[ 4 ],
  18834. propertyName: matches[ 5 ], // required
  18835. propertyIndex: matches[ 6 ]
  18836. };
  18837. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  18838. if ( lastDot !== undefined && lastDot !== - 1 ) {
  18839. const objectName = results.nodeName.substring( lastDot + 1 );
  18840. // Object names must be checked against an allowlist. Otherwise, there
  18841. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  18842. // 'bar' could be the objectName, or part of a nodeName (which can
  18843. // include '.' characters).
  18844. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  18845. results.nodeName = results.nodeName.substring( 0, lastDot );
  18846. results.objectName = objectName;
  18847. }
  18848. }
  18849. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  18850. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  18851. }
  18852. return results;
  18853. }
  18854. static findNode( root, nodeName ) {
  18855. if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  18856. return root;
  18857. }
  18858. // search into skeleton bones.
  18859. if ( root.skeleton ) {
  18860. const bone = root.skeleton.getBoneByName( nodeName );
  18861. if ( bone !== undefined ) {
  18862. return bone;
  18863. }
  18864. }
  18865. // search into node subtree.
  18866. if ( root.children ) {
  18867. const searchNodeSubtree = function ( children ) {
  18868. for ( let i = 0; i < children.length; i ++ ) {
  18869. const childNode = children[ i ];
  18870. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  18871. return childNode;
  18872. }
  18873. const result = searchNodeSubtree( childNode.children );
  18874. if ( result ) return result;
  18875. }
  18876. return null;
  18877. };
  18878. const subTreeNode = searchNodeSubtree( root.children );
  18879. if ( subTreeNode ) {
  18880. return subTreeNode;
  18881. }
  18882. }
  18883. return null;
  18884. }
  18885. // these are used to "bind" a nonexistent property
  18886. _getValue_unavailable() {}
  18887. _setValue_unavailable() {}
  18888. // Getters
  18889. _getValue_direct( buffer, offset ) {
  18890. buffer[ offset ] = this.targetObject[ this.propertyName ];
  18891. }
  18892. _getValue_array( buffer, offset ) {
  18893. const source = this.resolvedProperty;
  18894. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  18895. buffer[ offset ++ ] = source[ i ];
  18896. }
  18897. }
  18898. _getValue_arrayElement( buffer, offset ) {
  18899. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  18900. }
  18901. _getValue_toArray( buffer, offset ) {
  18902. this.resolvedProperty.toArray( buffer, offset );
  18903. }
  18904. // Direct
  18905. _setValue_direct( buffer, offset ) {
  18906. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18907. }
  18908. _setValue_direct_setNeedsUpdate( buffer, offset ) {
  18909. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18910. this.targetObject.needsUpdate = true;
  18911. }
  18912. _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18913. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18914. this.targetObject.matrixWorldNeedsUpdate = true;
  18915. }
  18916. // EntireArray
  18917. _setValue_array( buffer, offset ) {
  18918. const dest = this.resolvedProperty;
  18919. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18920. dest[ i ] = buffer[ offset ++ ];
  18921. }
  18922. }
  18923. _setValue_array_setNeedsUpdate( buffer, offset ) {
  18924. const dest = this.resolvedProperty;
  18925. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18926. dest[ i ] = buffer[ offset ++ ];
  18927. }
  18928. this.targetObject.needsUpdate = true;
  18929. }
  18930. _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18931. const dest = this.resolvedProperty;
  18932. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18933. dest[ i ] = buffer[ offset ++ ];
  18934. }
  18935. this.targetObject.matrixWorldNeedsUpdate = true;
  18936. }
  18937. // ArrayElement
  18938. _setValue_arrayElement( buffer, offset ) {
  18939. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18940. }
  18941. _setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  18942. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18943. this.targetObject.needsUpdate = true;
  18944. }
  18945. _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18946. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18947. this.targetObject.matrixWorldNeedsUpdate = true;
  18948. }
  18949. // HasToFromArray
  18950. _setValue_fromArray( buffer, offset ) {
  18951. this.resolvedProperty.fromArray( buffer, offset );
  18952. }
  18953. _setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  18954. this.resolvedProperty.fromArray( buffer, offset );
  18955. this.targetObject.needsUpdate = true;
  18956. }
  18957. _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18958. this.resolvedProperty.fromArray( buffer, offset );
  18959. this.targetObject.matrixWorldNeedsUpdate = true;
  18960. }
  18961. _getValue_unbound( targetArray, offset ) {
  18962. this.bind();
  18963. this.getValue( targetArray, offset );
  18964. }
  18965. _setValue_unbound( sourceArray, offset ) {
  18966. this.bind();
  18967. this.setValue( sourceArray, offset );
  18968. }
  18969. // create getter / setter pair for a property in the scene graph
  18970. bind() {
  18971. let targetObject = this.node;
  18972. const parsedPath = this.parsedPath;
  18973. const objectName = parsedPath.objectName;
  18974. const propertyName = parsedPath.propertyName;
  18975. let propertyIndex = parsedPath.propertyIndex;
  18976. if ( ! targetObject ) {
  18977. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName );
  18978. this.node = targetObject;
  18979. }
  18980. // set fail state so we can just 'return' on error
  18981. this.getValue = this._getValue_unavailable;
  18982. this.setValue = this._setValue_unavailable;
  18983. // ensure there is a value node
  18984. if ( ! targetObject ) {
  18985. console.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' );
  18986. return;
  18987. }
  18988. if ( objectName ) {
  18989. let objectIndex = parsedPath.objectIndex;
  18990. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  18991. switch ( objectName ) {
  18992. case 'materials':
  18993. if ( ! targetObject.material ) {
  18994. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  18995. return;
  18996. }
  18997. if ( ! targetObject.material.materials ) {
  18998. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  18999. return;
  19000. }
  19001. targetObject = targetObject.material.materials;
  19002. break;
  19003. case 'bones':
  19004. if ( ! targetObject.skeleton ) {
  19005. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  19006. return;
  19007. }
  19008. // potential future optimization: skip this if propertyIndex is already an integer
  19009. // and convert the integer string to a true integer.
  19010. targetObject = targetObject.skeleton.bones;
  19011. // support resolving morphTarget names into indices.
  19012. for ( let i = 0; i < targetObject.length; i ++ ) {
  19013. if ( targetObject[ i ].name === objectIndex ) {
  19014. objectIndex = i;
  19015. break;
  19016. }
  19017. }
  19018. break;
  19019. case 'map':
  19020. if ( 'map' in targetObject ) {
  19021. targetObject = targetObject.map;
  19022. break;
  19023. }
  19024. if ( ! targetObject.material ) {
  19025. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19026. return;
  19027. }
  19028. if ( ! targetObject.material.map ) {
  19029. console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this );
  19030. return;
  19031. }
  19032. targetObject = targetObject.material.map;
  19033. break;
  19034. default:
  19035. if ( targetObject[ objectName ] === undefined ) {
  19036. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  19037. return;
  19038. }
  19039. targetObject = targetObject[ objectName ];
  19040. }
  19041. if ( objectIndex !== undefined ) {
  19042. if ( targetObject[ objectIndex ] === undefined ) {
  19043. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  19044. return;
  19045. }
  19046. targetObject = targetObject[ objectIndex ];
  19047. }
  19048. }
  19049. // resolve property
  19050. const nodeProperty = targetObject[ propertyName ];
  19051. if ( nodeProperty === undefined ) {
  19052. const nodeName = parsedPath.nodeName;
  19053. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  19054. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  19055. return;
  19056. }
  19057. // determine versioning scheme
  19058. let versioning = this.Versioning.None;
  19059. this.targetObject = targetObject;
  19060. if ( targetObject.needsUpdate !== undefined ) { // material
  19061. versioning = this.Versioning.NeedsUpdate;
  19062. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  19063. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  19064. }
  19065. // determine how the property gets bound
  19066. let bindingType = this.BindingType.Direct;
  19067. if ( propertyIndex !== undefined ) {
  19068. // access a sub element of the property array (only primitives are supported right now)
  19069. if ( propertyName === 'morphTargetInfluences' ) {
  19070. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  19071. // support resolving morphTarget names into indices.
  19072. if ( ! targetObject.geometry ) {
  19073. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  19074. return;
  19075. }
  19076. if ( ! targetObject.geometry.morphAttributes ) {
  19077. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  19078. return;
  19079. }
  19080. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  19081. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  19082. }
  19083. }
  19084. bindingType = this.BindingType.ArrayElement;
  19085. this.resolvedProperty = nodeProperty;
  19086. this.propertyIndex = propertyIndex;
  19087. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  19088. // must use copy for Object3D.Euler/Quaternion
  19089. bindingType = this.BindingType.HasFromToArray;
  19090. this.resolvedProperty = nodeProperty;
  19091. } else if ( Array.isArray( nodeProperty ) ) {
  19092. bindingType = this.BindingType.EntireArray;
  19093. this.resolvedProperty = nodeProperty;
  19094. } else {
  19095. this.propertyName = propertyName;
  19096. }
  19097. // select getter / setter
  19098. this.getValue = this.GetterByBindingType[ bindingType ];
  19099. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  19100. }
  19101. unbind() {
  19102. this.node = null;
  19103. // back to the prototype version of getValue / setValue
  19104. // note: avoiding to mutate the shape of 'this' via 'delete'
  19105. this.getValue = this._getValue_unbound;
  19106. this.setValue = this._setValue_unbound;
  19107. }
  19108. }
  19109. PropertyBinding.Composite = Composite;
  19110. PropertyBinding.prototype.BindingType = {
  19111. Direct: 0,
  19112. EntireArray: 1,
  19113. ArrayElement: 2,
  19114. HasFromToArray: 3
  19115. };
  19116. PropertyBinding.prototype.Versioning = {
  19117. None: 0,
  19118. NeedsUpdate: 1,
  19119. MatrixWorldNeedsUpdate: 2
  19120. };
  19121. PropertyBinding.prototype.GetterByBindingType = [
  19122. PropertyBinding.prototype._getValue_direct,
  19123. PropertyBinding.prototype._getValue_array,
  19124. PropertyBinding.prototype._getValue_arrayElement,
  19125. PropertyBinding.prototype._getValue_toArray,
  19126. ];
  19127. PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
  19128. [
  19129. // Direct
  19130. PropertyBinding.prototype._setValue_direct,
  19131. PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
  19132. PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
  19133. ], [
  19134. // EntireArray
  19135. PropertyBinding.prototype._setValue_array,
  19136. PropertyBinding.prototype._setValue_array_setNeedsUpdate,
  19137. PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
  19138. ], [
  19139. // ArrayElement
  19140. PropertyBinding.prototype._setValue_arrayElement,
  19141. PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
  19142. PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
  19143. ], [
  19144. // HasToFromArray
  19145. PropertyBinding.prototype._setValue_fromArray,
  19146. PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
  19147. PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
  19148. ]
  19149. ];
  19150. /**
  19151. *
  19152. * A group of objects that receives a shared animation state.
  19153. *
  19154. * Usage:
  19155. *
  19156. * - Add objects you would otherwise pass as 'root' to the
  19157. * constructor or the .clipAction method of AnimationMixer.
  19158. *
  19159. * - Instead pass this object as 'root'.
  19160. *
  19161. * - You can also add and remove objects later when the mixer
  19162. * is running.
  19163. *
  19164. * Note:
  19165. *
  19166. * Objects of this class appear as one object to the mixer,
  19167. * so cache control of the individual objects must be done
  19168. * on the group.
  19169. *
  19170. * Limitation:
  19171. *
  19172. * - The animated properties must be compatible among the
  19173. * all objects in the group.
  19174. *
  19175. * - A single property can either be controlled through a
  19176. * target group or directly, but not both.
  19177. */
  19178. class AnimationObjectGroup {
  19179. constructor() {
  19180. this.isAnimationObjectGroup = true;
  19181. this.uuid = generateUUID();
  19182. // cached objects followed by the active ones
  19183. this._objects = Array.prototype.slice.call( arguments );
  19184. this.nCachedObjects_ = 0; // threshold
  19185. // note: read by PropertyBinding.Composite
  19186. const indices = {};
  19187. this._indicesByUUID = indices; // for bookkeeping
  19188. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19189. indices[ arguments[ i ].uuid ] = i;
  19190. }
  19191. this._paths = []; // inside: string
  19192. this._parsedPaths = []; // inside: { we don't care, here }
  19193. this._bindings = []; // inside: Array< PropertyBinding >
  19194. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  19195. const scope = this;
  19196. this.stats = {
  19197. objects: {
  19198. get total() {
  19199. return scope._objects.length;
  19200. },
  19201. get inUse() {
  19202. return this.total - scope.nCachedObjects_;
  19203. }
  19204. },
  19205. get bindingsPerObject() {
  19206. return scope._bindings.length;
  19207. }
  19208. };
  19209. }
  19210. add() {
  19211. const objects = this._objects,
  19212. indicesByUUID = this._indicesByUUID,
  19213. paths = this._paths,
  19214. parsedPaths = this._parsedPaths,
  19215. bindings = this._bindings,
  19216. nBindings = bindings.length;
  19217. let knownObject = undefined,
  19218. nObjects = objects.length,
  19219. nCachedObjects = this.nCachedObjects_;
  19220. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19221. const object = arguments[ i ],
  19222. uuid = object.uuid;
  19223. let index = indicesByUUID[ uuid ];
  19224. if ( index === undefined ) {
  19225. // unknown object -> add it to the ACTIVE region
  19226. index = nObjects ++;
  19227. indicesByUUID[ uuid ] = index;
  19228. objects.push( object );
  19229. // accounting is done, now do the same for all bindings
  19230. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19231. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  19232. }
  19233. } else if ( index < nCachedObjects ) {
  19234. knownObject = objects[ index ];
  19235. // move existing object to the ACTIVE region
  19236. const firstActiveIndex = -- nCachedObjects,
  19237. lastCachedObject = objects[ firstActiveIndex ];
  19238. indicesByUUID[ lastCachedObject.uuid ] = index;
  19239. objects[ index ] = lastCachedObject;
  19240. indicesByUUID[ uuid ] = firstActiveIndex;
  19241. objects[ firstActiveIndex ] = object;
  19242. // accounting is done, now do the same for all bindings
  19243. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19244. const bindingsForPath = bindings[ j ],
  19245. lastCached = bindingsForPath[ firstActiveIndex ];
  19246. let binding = bindingsForPath[ index ];
  19247. bindingsForPath[ index ] = lastCached;
  19248. if ( binding === undefined ) {
  19249. // since we do not bother to create new bindings
  19250. // for objects that are cached, the binding may
  19251. // or may not exist
  19252. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  19253. }
  19254. bindingsForPath[ firstActiveIndex ] = binding;
  19255. }
  19256. } else if ( objects[ index ] !== knownObject ) {
  19257. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  19258. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  19259. } // else the object is already where we want it to be
  19260. } // for arguments
  19261. this.nCachedObjects_ = nCachedObjects;
  19262. }
  19263. remove() {
  19264. const objects = this._objects,
  19265. indicesByUUID = this._indicesByUUID,
  19266. bindings = this._bindings,
  19267. nBindings = bindings.length;
  19268. let nCachedObjects = this.nCachedObjects_;
  19269. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19270. const object = arguments[ i ],
  19271. uuid = object.uuid,
  19272. index = indicesByUUID[ uuid ];
  19273. if ( index !== undefined && index >= nCachedObjects ) {
  19274. // move existing object into the CACHED region
  19275. const lastCachedIndex = nCachedObjects ++,
  19276. firstActiveObject = objects[ lastCachedIndex ];
  19277. indicesByUUID[ firstActiveObject.uuid ] = index;
  19278. objects[ index ] = firstActiveObject;
  19279. indicesByUUID[ uuid ] = lastCachedIndex;
  19280. objects[ lastCachedIndex ] = object;
  19281. // accounting is done, now do the same for all bindings
  19282. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19283. const bindingsForPath = bindings[ j ],
  19284. firstActive = bindingsForPath[ lastCachedIndex ],
  19285. binding = bindingsForPath[ index ];
  19286. bindingsForPath[ index ] = firstActive;
  19287. bindingsForPath[ lastCachedIndex ] = binding;
  19288. }
  19289. }
  19290. } // for arguments
  19291. this.nCachedObjects_ = nCachedObjects;
  19292. }
  19293. // remove & forget
  19294. uncache() {
  19295. const objects = this._objects,
  19296. indicesByUUID = this._indicesByUUID,
  19297. bindings = this._bindings,
  19298. nBindings = bindings.length;
  19299. let nCachedObjects = this.nCachedObjects_,
  19300. nObjects = objects.length;
  19301. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19302. const object = arguments[ i ],
  19303. uuid = object.uuid,
  19304. index = indicesByUUID[ uuid ];
  19305. if ( index !== undefined ) {
  19306. delete indicesByUUID[ uuid ];
  19307. if ( index < nCachedObjects ) {
  19308. // object is cached, shrink the CACHED region
  19309. const firstActiveIndex = -- nCachedObjects,
  19310. lastCachedObject = objects[ firstActiveIndex ],
  19311. lastIndex = -- nObjects,
  19312. lastObject = objects[ lastIndex ];
  19313. // last cached object takes this object's place
  19314. indicesByUUID[ lastCachedObject.uuid ] = index;
  19315. objects[ index ] = lastCachedObject;
  19316. // last object goes to the activated slot and pop
  19317. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  19318. objects[ firstActiveIndex ] = lastObject;
  19319. objects.pop();
  19320. // accounting is done, now do the same for all bindings
  19321. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19322. const bindingsForPath = bindings[ j ],
  19323. lastCached = bindingsForPath[ firstActiveIndex ],
  19324. last = bindingsForPath[ lastIndex ];
  19325. bindingsForPath[ index ] = lastCached;
  19326. bindingsForPath[ firstActiveIndex ] = last;
  19327. bindingsForPath.pop();
  19328. }
  19329. } else {
  19330. // object is active, just swap with the last and pop
  19331. const lastIndex = -- nObjects,
  19332. lastObject = objects[ lastIndex ];
  19333. if ( lastIndex > 0 ) {
  19334. indicesByUUID[ lastObject.uuid ] = index;
  19335. }
  19336. objects[ index ] = lastObject;
  19337. objects.pop();
  19338. // accounting is done, now do the same for all bindings
  19339. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19340. const bindingsForPath = bindings[ j ];
  19341. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  19342. bindingsForPath.pop();
  19343. }
  19344. } // cached or active
  19345. } // if object is known
  19346. } // for arguments
  19347. this.nCachedObjects_ = nCachedObjects;
  19348. }
  19349. // Internal interface used by befriended PropertyBinding.Composite:
  19350. subscribe_( path, parsedPath ) {
  19351. // returns an array of bindings for the given path that is changed
  19352. // according to the contained objects in the group
  19353. const indicesByPath = this._bindingsIndicesByPath;
  19354. let index = indicesByPath[ path ];
  19355. const bindings = this._bindings;
  19356. if ( index !== undefined ) return bindings[ index ];
  19357. const paths = this._paths,
  19358. parsedPaths = this._parsedPaths,
  19359. objects = this._objects,
  19360. nObjects = objects.length,
  19361. nCachedObjects = this.nCachedObjects_,
  19362. bindingsForPath = new Array( nObjects );
  19363. index = bindings.length;
  19364. indicesByPath[ path ] = index;
  19365. paths.push( path );
  19366. parsedPaths.push( parsedPath );
  19367. bindings.push( bindingsForPath );
  19368. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  19369. const object = objects[ i ];
  19370. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  19371. }
  19372. return bindingsForPath;
  19373. }
  19374. unsubscribe_( path ) {
  19375. // tells the group to forget about a property path and no longer
  19376. // update the array previously obtained with 'subscribe_'
  19377. const indicesByPath = this._bindingsIndicesByPath,
  19378. index = indicesByPath[ path ];
  19379. if ( index !== undefined ) {
  19380. const paths = this._paths,
  19381. parsedPaths = this._parsedPaths,
  19382. bindings = this._bindings,
  19383. lastBindingsIndex = bindings.length - 1,
  19384. lastBindings = bindings[ lastBindingsIndex ],
  19385. lastBindingsPath = path[ lastBindingsIndex ];
  19386. indicesByPath[ lastBindingsPath ] = index;
  19387. bindings[ index ] = lastBindings;
  19388. bindings.pop();
  19389. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  19390. parsedPaths.pop();
  19391. paths[ index ] = paths[ lastBindingsIndex ];
  19392. paths.pop();
  19393. }
  19394. }
  19395. }
  19396. class AnimationAction {
  19397. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  19398. this._mixer = mixer;
  19399. this._clip = clip;
  19400. this._localRoot = localRoot;
  19401. this.blendMode = blendMode;
  19402. const tracks = clip.tracks,
  19403. nTracks = tracks.length,
  19404. interpolants = new Array( nTracks );
  19405. const interpolantSettings = {
  19406. endingStart: ZeroCurvatureEnding,
  19407. endingEnd: ZeroCurvatureEnding
  19408. };
  19409. for ( let i = 0; i !== nTracks; ++ i ) {
  19410. const interpolant = tracks[ i ].createInterpolant( null );
  19411. interpolants[ i ] = interpolant;
  19412. interpolant.settings = interpolantSettings;
  19413. }
  19414. this._interpolantSettings = interpolantSettings;
  19415. this._interpolants = interpolants; // bound by the mixer
  19416. // inside: PropertyMixer (managed by the mixer)
  19417. this._propertyBindings = new Array( nTracks );
  19418. this._cacheIndex = null; // for the memory manager
  19419. this._byClipCacheIndex = null; // for the memory manager
  19420. this._timeScaleInterpolant = null;
  19421. this._weightInterpolant = null;
  19422. this.loop = LoopRepeat;
  19423. this._loopCount = - 1;
  19424. // global mixer time when the action is to be started
  19425. // it's set back to 'null' upon start of the action
  19426. this._startTime = null;
  19427. // scaled local time of the action
  19428. // gets clamped or wrapped to 0..clip.duration according to loop
  19429. this.time = 0;
  19430. this.timeScale = 1;
  19431. this._effectiveTimeScale = 1;
  19432. this.weight = 1;
  19433. this._effectiveWeight = 1;
  19434. this.repetitions = Infinity; // no. of repetitions when looping
  19435. this.paused = false; // true -> zero effective time scale
  19436. this.enabled = true; // false -> zero effective weight
  19437. this.clampWhenFinished = false;// keep feeding the last frame?
  19438. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  19439. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  19440. }
  19441. // State & Scheduling
  19442. play() {
  19443. this._mixer._activateAction( this );
  19444. return this;
  19445. }
  19446. stop() {
  19447. this._mixer._deactivateAction( this );
  19448. return this.reset();
  19449. }
  19450. reset() {
  19451. this.paused = false;
  19452. this.enabled = true;
  19453. this.time = 0; // restart clip
  19454. this._loopCount = - 1;// forget previous loops
  19455. this._startTime = null;// forget scheduling
  19456. return this.stopFading().stopWarping();
  19457. }
  19458. isRunning() {
  19459. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  19460. this._startTime === null && this._mixer._isActiveAction( this );
  19461. }
  19462. // return true when play has been called
  19463. isScheduled() {
  19464. return this._mixer._isActiveAction( this );
  19465. }
  19466. startAt( time ) {
  19467. this._startTime = time;
  19468. return this;
  19469. }
  19470. setLoop( mode, repetitions ) {
  19471. this.loop = mode;
  19472. this.repetitions = repetitions;
  19473. return this;
  19474. }
  19475. // Weight
  19476. // set the weight stopping any scheduled fading
  19477. // although .enabled = false yields an effective weight of zero, this
  19478. // method does *not* change .enabled, because it would be confusing
  19479. setEffectiveWeight( weight ) {
  19480. this.weight = weight;
  19481. // note: same logic as when updated at runtime
  19482. this._effectiveWeight = this.enabled ? weight : 0;
  19483. return this.stopFading();
  19484. }
  19485. // return the weight considering fading and .enabled
  19486. getEffectiveWeight() {
  19487. return this._effectiveWeight;
  19488. }
  19489. fadeIn( duration ) {
  19490. return this._scheduleFading( duration, 0, 1 );
  19491. }
  19492. fadeOut( duration ) {
  19493. return this._scheduleFading( duration, 1, 0 );
  19494. }
  19495. crossFadeFrom( fadeOutAction, duration, warp ) {
  19496. fadeOutAction.fadeOut( duration );
  19497. this.fadeIn( duration );
  19498. if ( warp ) {
  19499. const fadeInDuration = this._clip.duration,
  19500. fadeOutDuration = fadeOutAction._clip.duration,
  19501. startEndRatio = fadeOutDuration / fadeInDuration,
  19502. endStartRatio = fadeInDuration / fadeOutDuration;
  19503. fadeOutAction.warp( 1.0, startEndRatio, duration );
  19504. this.warp( endStartRatio, 1.0, duration );
  19505. }
  19506. return this;
  19507. }
  19508. crossFadeTo( fadeInAction, duration, warp ) {
  19509. return fadeInAction.crossFadeFrom( this, duration, warp );
  19510. }
  19511. stopFading() {
  19512. const weightInterpolant = this._weightInterpolant;
  19513. if ( weightInterpolant !== null ) {
  19514. this._weightInterpolant = null;
  19515. this._mixer._takeBackControlInterpolant( weightInterpolant );
  19516. }
  19517. return this;
  19518. }
  19519. // Time Scale Control
  19520. // set the time scale stopping any scheduled warping
  19521. // although .paused = true yields an effective time scale of zero, this
  19522. // method does *not* change .paused, because it would be confusing
  19523. setEffectiveTimeScale( timeScale ) {
  19524. this.timeScale = timeScale;
  19525. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  19526. return this.stopWarping();
  19527. }
  19528. // return the time scale considering warping and .paused
  19529. getEffectiveTimeScale() {
  19530. return this._effectiveTimeScale;
  19531. }
  19532. setDuration( duration ) {
  19533. this.timeScale = this._clip.duration / duration;
  19534. return this.stopWarping();
  19535. }
  19536. syncWith( action ) {
  19537. this.time = action.time;
  19538. this.timeScale = action.timeScale;
  19539. return this.stopWarping();
  19540. }
  19541. halt( duration ) {
  19542. return this.warp( this._effectiveTimeScale, 0, duration );
  19543. }
  19544. warp( startTimeScale, endTimeScale, duration ) {
  19545. const mixer = this._mixer,
  19546. now = mixer.time,
  19547. timeScale = this.timeScale;
  19548. let interpolant = this._timeScaleInterpolant;
  19549. if ( interpolant === null ) {
  19550. interpolant = mixer._lendControlInterpolant();
  19551. this._timeScaleInterpolant = interpolant;
  19552. }
  19553. const times = interpolant.parameterPositions,
  19554. values = interpolant.sampleValues;
  19555. times[ 0 ] = now;
  19556. times[ 1 ] = now + duration;
  19557. values[ 0 ] = startTimeScale / timeScale;
  19558. values[ 1 ] = endTimeScale / timeScale;
  19559. return this;
  19560. }
  19561. stopWarping() {
  19562. const timeScaleInterpolant = this._timeScaleInterpolant;
  19563. if ( timeScaleInterpolant !== null ) {
  19564. this._timeScaleInterpolant = null;
  19565. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  19566. }
  19567. return this;
  19568. }
  19569. // Object Accessors
  19570. getMixer() {
  19571. return this._mixer;
  19572. }
  19573. getClip() {
  19574. return this._clip;
  19575. }
  19576. getRoot() {
  19577. return this._localRoot || this._mixer._root;
  19578. }
  19579. // Interna
  19580. _update( time, deltaTime, timeDirection, accuIndex ) {
  19581. // called by the mixer
  19582. if ( ! this.enabled ) {
  19583. // call ._updateWeight() to update ._effectiveWeight
  19584. this._updateWeight( time );
  19585. return;
  19586. }
  19587. const startTime = this._startTime;
  19588. if ( startTime !== null ) {
  19589. // check for scheduled start of action
  19590. const timeRunning = ( time - startTime ) * timeDirection;
  19591. if ( timeRunning < 0 || timeDirection === 0 ) {
  19592. deltaTime = 0;
  19593. } else {
  19594. this._startTime = null; // unschedule
  19595. deltaTime = timeDirection * timeRunning;
  19596. }
  19597. }
  19598. // apply time scale and advance time
  19599. deltaTime *= this._updateTimeScale( time );
  19600. const clipTime = this._updateTime( deltaTime );
  19601. // note: _updateTime may disable the action resulting in
  19602. // an effective weight of 0
  19603. const weight = this._updateWeight( time );
  19604. if ( weight > 0 ) {
  19605. const interpolants = this._interpolants;
  19606. const propertyMixers = this._propertyBindings;
  19607. switch ( this.blendMode ) {
  19608. case AdditiveAnimationBlendMode:
  19609. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19610. interpolants[ j ].evaluate( clipTime );
  19611. propertyMixers[ j ].accumulateAdditive( weight );
  19612. }
  19613. break;
  19614. case NormalAnimationBlendMode:
  19615. default:
  19616. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19617. interpolants[ j ].evaluate( clipTime );
  19618. propertyMixers[ j ].accumulate( accuIndex, weight );
  19619. }
  19620. }
  19621. }
  19622. }
  19623. _updateWeight( time ) {
  19624. let weight = 0;
  19625. if ( this.enabled ) {
  19626. weight = this.weight;
  19627. const interpolant = this._weightInterpolant;
  19628. if ( interpolant !== null ) {
  19629. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19630. weight *= interpolantValue;
  19631. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19632. this.stopFading();
  19633. if ( interpolantValue === 0 ) {
  19634. // faded out, disable
  19635. this.enabled = false;
  19636. }
  19637. }
  19638. }
  19639. }
  19640. this._effectiveWeight = weight;
  19641. return weight;
  19642. }
  19643. _updateTimeScale( time ) {
  19644. let timeScale = 0;
  19645. if ( ! this.paused ) {
  19646. timeScale = this.timeScale;
  19647. const interpolant = this._timeScaleInterpolant;
  19648. if ( interpolant !== null ) {
  19649. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19650. timeScale *= interpolantValue;
  19651. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19652. this.stopWarping();
  19653. if ( timeScale === 0 ) {
  19654. // motion has halted, pause
  19655. this.paused = true;
  19656. } else {
  19657. // warp done - apply final time scale
  19658. this.timeScale = timeScale;
  19659. }
  19660. }
  19661. }
  19662. }
  19663. this._effectiveTimeScale = timeScale;
  19664. return timeScale;
  19665. }
  19666. _updateTime( deltaTime ) {
  19667. const duration = this._clip.duration;
  19668. const loop = this.loop;
  19669. let time = this.time + deltaTime;
  19670. let loopCount = this._loopCount;
  19671. const pingPong = ( loop === LoopPingPong );
  19672. if ( deltaTime === 0 ) {
  19673. if ( loopCount === - 1 ) return time;
  19674. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  19675. }
  19676. if ( loop === LoopOnce ) {
  19677. if ( loopCount === - 1 ) {
  19678. // just started
  19679. this._loopCount = 0;
  19680. this._setEndings( true, true, false );
  19681. }
  19682. handle_stop: {
  19683. if ( time >= duration ) {
  19684. time = duration;
  19685. } else if ( time < 0 ) {
  19686. time = 0;
  19687. } else {
  19688. this.time = time;
  19689. break handle_stop;
  19690. }
  19691. if ( this.clampWhenFinished ) this.paused = true;
  19692. else this.enabled = false;
  19693. this.time = time;
  19694. this._mixer.dispatchEvent( {
  19695. type: 'finished', action: this,
  19696. direction: deltaTime < 0 ? - 1 : 1
  19697. } );
  19698. }
  19699. } else { // repetitive Repeat or PingPong
  19700. if ( loopCount === - 1 ) {
  19701. // just started
  19702. if ( deltaTime >= 0 ) {
  19703. loopCount = 0;
  19704. this._setEndings( true, this.repetitions === 0, pingPong );
  19705. } else {
  19706. // when looping in reverse direction, the initial
  19707. // transition through zero counts as a repetition,
  19708. // so leave loopCount at -1
  19709. this._setEndings( this.repetitions === 0, true, pingPong );
  19710. }
  19711. }
  19712. if ( time >= duration || time < 0 ) {
  19713. // wrap around
  19714. const loopDelta = Math.floor( time / duration ); // signed
  19715. time -= duration * loopDelta;
  19716. loopCount += Math.abs( loopDelta );
  19717. const pending = this.repetitions - loopCount;
  19718. if ( pending <= 0 ) {
  19719. // have to stop (switch state, clamp time, fire event)
  19720. if ( this.clampWhenFinished ) this.paused = true;
  19721. else this.enabled = false;
  19722. time = deltaTime > 0 ? duration : 0;
  19723. this.time = time;
  19724. this._mixer.dispatchEvent( {
  19725. type: 'finished', action: this,
  19726. direction: deltaTime > 0 ? 1 : - 1
  19727. } );
  19728. } else {
  19729. // keep running
  19730. if ( pending === 1 ) {
  19731. // entering the last round
  19732. const atStart = deltaTime < 0;
  19733. this._setEndings( atStart, ! atStart, pingPong );
  19734. } else {
  19735. this._setEndings( false, false, pingPong );
  19736. }
  19737. this._loopCount = loopCount;
  19738. this.time = time;
  19739. this._mixer.dispatchEvent( {
  19740. type: 'loop', action: this, loopDelta: loopDelta
  19741. } );
  19742. }
  19743. } else {
  19744. this.time = time;
  19745. }
  19746. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  19747. // invert time for the "pong round"
  19748. return duration - time;
  19749. }
  19750. }
  19751. return time;
  19752. }
  19753. _setEndings( atStart, atEnd, pingPong ) {
  19754. const settings = this._interpolantSettings;
  19755. if ( pingPong ) {
  19756. settings.endingStart = ZeroSlopeEnding;
  19757. settings.endingEnd = ZeroSlopeEnding;
  19758. } else {
  19759. // assuming for LoopOnce atStart == atEnd == true
  19760. if ( atStart ) {
  19761. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19762. } else {
  19763. settings.endingStart = WrapAroundEnding;
  19764. }
  19765. if ( atEnd ) {
  19766. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19767. } else {
  19768. settings.endingEnd = WrapAroundEnding;
  19769. }
  19770. }
  19771. }
  19772. _scheduleFading( duration, weightNow, weightThen ) {
  19773. const mixer = this._mixer, now = mixer.time;
  19774. let interpolant = this._weightInterpolant;
  19775. if ( interpolant === null ) {
  19776. interpolant = mixer._lendControlInterpolant();
  19777. this._weightInterpolant = interpolant;
  19778. }
  19779. const times = interpolant.parameterPositions,
  19780. values = interpolant.sampleValues;
  19781. times[ 0 ] = now;
  19782. values[ 0 ] = weightNow;
  19783. times[ 1 ] = now + duration;
  19784. values[ 1 ] = weightThen;
  19785. return this;
  19786. }
  19787. }
  19788. const _controlInterpolantsResultBuffer = new Float32Array( 1 );
  19789. class AnimationMixer extends EventDispatcher {
  19790. constructor( root ) {
  19791. super();
  19792. this._root = root;
  19793. this._initMemoryManager();
  19794. this._accuIndex = 0;
  19795. this.time = 0;
  19796. this.timeScale = 1.0;
  19797. }
  19798. _bindAction( action, prototypeAction ) {
  19799. const root = action._localRoot || this._root,
  19800. tracks = action._clip.tracks,
  19801. nTracks = tracks.length,
  19802. bindings = action._propertyBindings,
  19803. interpolants = action._interpolants,
  19804. rootUuid = root.uuid,
  19805. bindingsByRoot = this._bindingsByRootAndName;
  19806. let bindingsByName = bindingsByRoot[ rootUuid ];
  19807. if ( bindingsByName === undefined ) {
  19808. bindingsByName = {};
  19809. bindingsByRoot[ rootUuid ] = bindingsByName;
  19810. }
  19811. for ( let i = 0; i !== nTracks; ++ i ) {
  19812. const track = tracks[ i ],
  19813. trackName = track.name;
  19814. let binding = bindingsByName[ trackName ];
  19815. if ( binding !== undefined ) {
  19816. ++ binding.referenceCount;
  19817. bindings[ i ] = binding;
  19818. } else {
  19819. binding = bindings[ i ];
  19820. if ( binding !== undefined ) {
  19821. // existing binding, make sure the cache knows
  19822. if ( binding._cacheIndex === null ) {
  19823. ++ binding.referenceCount;
  19824. this._addInactiveBinding( binding, rootUuid, trackName );
  19825. }
  19826. continue;
  19827. }
  19828. const path = prototypeAction && prototypeAction.
  19829. _propertyBindings[ i ].binding.parsedPath;
  19830. binding = new PropertyMixer(
  19831. PropertyBinding.create( root, trackName, path ),
  19832. track.ValueTypeName, track.getValueSize() );
  19833. ++ binding.referenceCount;
  19834. this._addInactiveBinding( binding, rootUuid, trackName );
  19835. bindings[ i ] = binding;
  19836. }
  19837. interpolants[ i ].resultBuffer = binding.buffer;
  19838. }
  19839. }
  19840. _activateAction( action ) {
  19841. if ( ! this._isActiveAction( action ) ) {
  19842. if ( action._cacheIndex === null ) {
  19843. // this action has been forgotten by the cache, but the user
  19844. // appears to be still using it -> rebind
  19845. const rootUuid = ( action._localRoot || this._root ).uuid,
  19846. clipUuid = action._clip.uuid,
  19847. actionsForClip = this._actionsByClip[ clipUuid ];
  19848. this._bindAction( action,
  19849. actionsForClip && actionsForClip.knownActions[ 0 ] );
  19850. this._addInactiveAction( action, clipUuid, rootUuid );
  19851. }
  19852. const bindings = action._propertyBindings;
  19853. // increment reference counts / sort out state
  19854. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19855. const binding = bindings[ i ];
  19856. if ( binding.useCount ++ === 0 ) {
  19857. this._lendBinding( binding );
  19858. binding.saveOriginalState();
  19859. }
  19860. }
  19861. this._lendAction( action );
  19862. }
  19863. }
  19864. _deactivateAction( action ) {
  19865. if ( this._isActiveAction( action ) ) {
  19866. const bindings = action._propertyBindings;
  19867. // decrement reference counts / sort out state
  19868. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19869. const binding = bindings[ i ];
  19870. if ( -- binding.useCount === 0 ) {
  19871. binding.restoreOriginalState();
  19872. this._takeBackBinding( binding );
  19873. }
  19874. }
  19875. this._takeBackAction( action );
  19876. }
  19877. }
  19878. // Memory manager
  19879. _initMemoryManager() {
  19880. this._actions = []; // 'nActiveActions' followed by inactive ones
  19881. this._nActiveActions = 0;
  19882. this._actionsByClip = {};
  19883. // inside:
  19884. // {
  19885. // knownActions: Array< AnimationAction > - used as prototypes
  19886. // actionByRoot: AnimationAction - lookup
  19887. // }
  19888. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  19889. this._nActiveBindings = 0;
  19890. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  19891. this._controlInterpolants = []; // same game as above
  19892. this._nActiveControlInterpolants = 0;
  19893. const scope = this;
  19894. this.stats = {
  19895. actions: {
  19896. get total() {
  19897. return scope._actions.length;
  19898. },
  19899. get inUse() {
  19900. return scope._nActiveActions;
  19901. }
  19902. },
  19903. bindings: {
  19904. get total() {
  19905. return scope._bindings.length;
  19906. },
  19907. get inUse() {
  19908. return scope._nActiveBindings;
  19909. }
  19910. },
  19911. controlInterpolants: {
  19912. get total() {
  19913. return scope._controlInterpolants.length;
  19914. },
  19915. get inUse() {
  19916. return scope._nActiveControlInterpolants;
  19917. }
  19918. }
  19919. };
  19920. }
  19921. // Memory management for AnimationAction objects
  19922. _isActiveAction( action ) {
  19923. const index = action._cacheIndex;
  19924. return index !== null && index < this._nActiveActions;
  19925. }
  19926. _addInactiveAction( action, clipUuid, rootUuid ) {
  19927. const actions = this._actions,
  19928. actionsByClip = this._actionsByClip;
  19929. let actionsForClip = actionsByClip[ clipUuid ];
  19930. if ( actionsForClip === undefined ) {
  19931. actionsForClip = {
  19932. knownActions: [ action ],
  19933. actionByRoot: {}
  19934. };
  19935. action._byClipCacheIndex = 0;
  19936. actionsByClip[ clipUuid ] = actionsForClip;
  19937. } else {
  19938. const knownActions = actionsForClip.knownActions;
  19939. action._byClipCacheIndex = knownActions.length;
  19940. knownActions.push( action );
  19941. }
  19942. action._cacheIndex = actions.length;
  19943. actions.push( action );
  19944. actionsForClip.actionByRoot[ rootUuid ] = action;
  19945. }
  19946. _removeInactiveAction( action ) {
  19947. const actions = this._actions,
  19948. lastInactiveAction = actions[ actions.length - 1 ],
  19949. cacheIndex = action._cacheIndex;
  19950. lastInactiveAction._cacheIndex = cacheIndex;
  19951. actions[ cacheIndex ] = lastInactiveAction;
  19952. actions.pop();
  19953. action._cacheIndex = null;
  19954. const clipUuid = action._clip.uuid,
  19955. actionsByClip = this._actionsByClip,
  19956. actionsForClip = actionsByClip[ clipUuid ],
  19957. knownActionsForClip = actionsForClip.knownActions,
  19958. lastKnownAction =
  19959. knownActionsForClip[ knownActionsForClip.length - 1 ],
  19960. byClipCacheIndex = action._byClipCacheIndex;
  19961. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  19962. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  19963. knownActionsForClip.pop();
  19964. action._byClipCacheIndex = null;
  19965. const actionByRoot = actionsForClip.actionByRoot,
  19966. rootUuid = ( action._localRoot || this._root ).uuid;
  19967. delete actionByRoot[ rootUuid ];
  19968. if ( knownActionsForClip.length === 0 ) {
  19969. delete actionsByClip[ clipUuid ];
  19970. }
  19971. this._removeInactiveBindingsForAction( action );
  19972. }
  19973. _removeInactiveBindingsForAction( action ) {
  19974. const bindings = action._propertyBindings;
  19975. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19976. const binding = bindings[ i ];
  19977. if ( -- binding.referenceCount === 0 ) {
  19978. this._removeInactiveBinding( binding );
  19979. }
  19980. }
  19981. }
  19982. _lendAction( action ) {
  19983. // [ active actions | inactive actions ]
  19984. // [ active actions >| inactive actions ]
  19985. // s a
  19986. // <-swap->
  19987. // a s
  19988. const actions = this._actions,
  19989. prevIndex = action._cacheIndex,
  19990. lastActiveIndex = this._nActiveActions ++,
  19991. firstInactiveAction = actions[ lastActiveIndex ];
  19992. action._cacheIndex = lastActiveIndex;
  19993. actions[ lastActiveIndex ] = action;
  19994. firstInactiveAction._cacheIndex = prevIndex;
  19995. actions[ prevIndex ] = firstInactiveAction;
  19996. }
  19997. _takeBackAction( action ) {
  19998. // [ active actions | inactive actions ]
  19999. // [ active actions |< inactive actions ]
  20000. // a s
  20001. // <-swap->
  20002. // s a
  20003. const actions = this._actions,
  20004. prevIndex = action._cacheIndex,
  20005. firstInactiveIndex = -- this._nActiveActions,
  20006. lastActiveAction = actions[ firstInactiveIndex ];
  20007. action._cacheIndex = firstInactiveIndex;
  20008. actions[ firstInactiveIndex ] = action;
  20009. lastActiveAction._cacheIndex = prevIndex;
  20010. actions[ prevIndex ] = lastActiveAction;
  20011. }
  20012. // Memory management for PropertyMixer objects
  20013. _addInactiveBinding( binding, rootUuid, trackName ) {
  20014. const bindingsByRoot = this._bindingsByRootAndName,
  20015. bindings = this._bindings;
  20016. let bindingByName = bindingsByRoot[ rootUuid ];
  20017. if ( bindingByName === undefined ) {
  20018. bindingByName = {};
  20019. bindingsByRoot[ rootUuid ] = bindingByName;
  20020. }
  20021. bindingByName[ trackName ] = binding;
  20022. binding._cacheIndex = bindings.length;
  20023. bindings.push( binding );
  20024. }
  20025. _removeInactiveBinding( binding ) {
  20026. const bindings = this._bindings,
  20027. propBinding = binding.binding,
  20028. rootUuid = propBinding.rootNode.uuid,
  20029. trackName = propBinding.path,
  20030. bindingsByRoot = this._bindingsByRootAndName,
  20031. bindingByName = bindingsByRoot[ rootUuid ],
  20032. lastInactiveBinding = bindings[ bindings.length - 1 ],
  20033. cacheIndex = binding._cacheIndex;
  20034. lastInactiveBinding._cacheIndex = cacheIndex;
  20035. bindings[ cacheIndex ] = lastInactiveBinding;
  20036. bindings.pop();
  20037. delete bindingByName[ trackName ];
  20038. if ( Object.keys( bindingByName ).length === 0 ) {
  20039. delete bindingsByRoot[ rootUuid ];
  20040. }
  20041. }
  20042. _lendBinding( binding ) {
  20043. const bindings = this._bindings,
  20044. prevIndex = binding._cacheIndex,
  20045. lastActiveIndex = this._nActiveBindings ++,
  20046. firstInactiveBinding = bindings[ lastActiveIndex ];
  20047. binding._cacheIndex = lastActiveIndex;
  20048. bindings[ lastActiveIndex ] = binding;
  20049. firstInactiveBinding._cacheIndex = prevIndex;
  20050. bindings[ prevIndex ] = firstInactiveBinding;
  20051. }
  20052. _takeBackBinding( binding ) {
  20053. const bindings = this._bindings,
  20054. prevIndex = binding._cacheIndex,
  20055. firstInactiveIndex = -- this._nActiveBindings,
  20056. lastActiveBinding = bindings[ firstInactiveIndex ];
  20057. binding._cacheIndex = firstInactiveIndex;
  20058. bindings[ firstInactiveIndex ] = binding;
  20059. lastActiveBinding._cacheIndex = prevIndex;
  20060. bindings[ prevIndex ] = lastActiveBinding;
  20061. }
  20062. // Memory management of Interpolants for weight and time scale
  20063. _lendControlInterpolant() {
  20064. const interpolants = this._controlInterpolants,
  20065. lastActiveIndex = this._nActiveControlInterpolants ++;
  20066. let interpolant = interpolants[ lastActiveIndex ];
  20067. if ( interpolant === undefined ) {
  20068. interpolant = new LinearInterpolant(
  20069. new Float32Array( 2 ), new Float32Array( 2 ),
  20070. 1, _controlInterpolantsResultBuffer );
  20071. interpolant.__cacheIndex = lastActiveIndex;
  20072. interpolants[ lastActiveIndex ] = interpolant;
  20073. }
  20074. return interpolant;
  20075. }
  20076. _takeBackControlInterpolant( interpolant ) {
  20077. const interpolants = this._controlInterpolants,
  20078. prevIndex = interpolant.__cacheIndex,
  20079. firstInactiveIndex = -- this._nActiveControlInterpolants,
  20080. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  20081. interpolant.__cacheIndex = firstInactiveIndex;
  20082. interpolants[ firstInactiveIndex ] = interpolant;
  20083. lastActiveInterpolant.__cacheIndex = prevIndex;
  20084. interpolants[ prevIndex ] = lastActiveInterpolant;
  20085. }
  20086. // return an action for a clip optionally using a custom root target
  20087. // object (this method allocates a lot of dynamic memory in case a
  20088. // previously unknown clip/root combination is specified)
  20089. clipAction( clip, optionalRoot, blendMode ) {
  20090. const root = optionalRoot || this._root,
  20091. rootUuid = root.uuid;
  20092. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  20093. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  20094. const actionsForClip = this._actionsByClip[ clipUuid ];
  20095. let prototypeAction = null;
  20096. if ( blendMode === undefined ) {
  20097. if ( clipObject !== null ) {
  20098. blendMode = clipObject.blendMode;
  20099. } else {
  20100. blendMode = NormalAnimationBlendMode;
  20101. }
  20102. }
  20103. if ( actionsForClip !== undefined ) {
  20104. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  20105. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  20106. return existingAction;
  20107. }
  20108. // we know the clip, so we don't have to parse all
  20109. // the bindings again but can just copy
  20110. prototypeAction = actionsForClip.knownActions[ 0 ];
  20111. // also, take the clip from the prototype action
  20112. if ( clipObject === null )
  20113. clipObject = prototypeAction._clip;
  20114. }
  20115. // clip must be known when specified via string
  20116. if ( clipObject === null ) return null;
  20117. // allocate all resources required to run it
  20118. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  20119. this._bindAction( newAction, prototypeAction );
  20120. // and make the action known to the memory manager
  20121. this._addInactiveAction( newAction, clipUuid, rootUuid );
  20122. return newAction;
  20123. }
  20124. // get an existing action
  20125. existingAction( clip, optionalRoot ) {
  20126. const root = optionalRoot || this._root,
  20127. rootUuid = root.uuid,
  20128. clipObject = typeof clip === 'string' ?
  20129. AnimationClip.findByName( root, clip ) : clip,
  20130. clipUuid = clipObject ? clipObject.uuid : clip,
  20131. actionsForClip = this._actionsByClip[ clipUuid ];
  20132. if ( actionsForClip !== undefined ) {
  20133. return actionsForClip.actionByRoot[ rootUuid ] || null;
  20134. }
  20135. return null;
  20136. }
  20137. // deactivates all previously scheduled actions
  20138. stopAllAction() {
  20139. const actions = this._actions,
  20140. nActions = this._nActiveActions;
  20141. for ( let i = nActions - 1; i >= 0; -- i ) {
  20142. actions[ i ].stop();
  20143. }
  20144. return this;
  20145. }
  20146. // advance the time and update apply the animation
  20147. update( deltaTime ) {
  20148. deltaTime *= this.timeScale;
  20149. const actions = this._actions,
  20150. nActions = this._nActiveActions,
  20151. time = this.time += deltaTime,
  20152. timeDirection = Math.sign( deltaTime ),
  20153. accuIndex = this._accuIndex ^= 1;
  20154. // run active actions
  20155. for ( let i = 0; i !== nActions; ++ i ) {
  20156. const action = actions[ i ];
  20157. action._update( time, deltaTime, timeDirection, accuIndex );
  20158. }
  20159. // update scene graph
  20160. const bindings = this._bindings,
  20161. nBindings = this._nActiveBindings;
  20162. for ( let i = 0; i !== nBindings; ++ i ) {
  20163. bindings[ i ].apply( accuIndex );
  20164. }
  20165. return this;
  20166. }
  20167. // Allows you to seek to a specific time in an animation.
  20168. setTime( timeInSeconds ) {
  20169. this.time = 0; // Zero out time attribute for AnimationMixer object;
  20170. for ( let i = 0; i < this._actions.length; i ++ ) {
  20171. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  20172. }
  20173. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  20174. }
  20175. // return this mixer's root target object
  20176. getRoot() {
  20177. return this._root;
  20178. }
  20179. // free all resources specific to a particular clip
  20180. uncacheClip( clip ) {
  20181. const actions = this._actions,
  20182. clipUuid = clip.uuid,
  20183. actionsByClip = this._actionsByClip,
  20184. actionsForClip = actionsByClip[ clipUuid ];
  20185. if ( actionsForClip !== undefined ) {
  20186. // note: just calling _removeInactiveAction would mess up the
  20187. // iteration state and also require updating the state we can
  20188. // just throw away
  20189. const actionsToRemove = actionsForClip.knownActions;
  20190. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  20191. const action = actionsToRemove[ i ];
  20192. this._deactivateAction( action );
  20193. const cacheIndex = action._cacheIndex,
  20194. lastInactiveAction = actions[ actions.length - 1 ];
  20195. action._cacheIndex = null;
  20196. action._byClipCacheIndex = null;
  20197. lastInactiveAction._cacheIndex = cacheIndex;
  20198. actions[ cacheIndex ] = lastInactiveAction;
  20199. actions.pop();
  20200. this._removeInactiveBindingsForAction( action );
  20201. }
  20202. delete actionsByClip[ clipUuid ];
  20203. }
  20204. }
  20205. // free all resources specific to a particular root target object
  20206. uncacheRoot( root ) {
  20207. const rootUuid = root.uuid,
  20208. actionsByClip = this._actionsByClip;
  20209. for ( const clipUuid in actionsByClip ) {
  20210. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  20211. action = actionByRoot[ rootUuid ];
  20212. if ( action !== undefined ) {
  20213. this._deactivateAction( action );
  20214. this._removeInactiveAction( action );
  20215. }
  20216. }
  20217. const bindingsByRoot = this._bindingsByRootAndName,
  20218. bindingByName = bindingsByRoot[ rootUuid ];
  20219. if ( bindingByName !== undefined ) {
  20220. for ( const trackName in bindingByName ) {
  20221. const binding = bindingByName[ trackName ];
  20222. binding.restoreOriginalState();
  20223. this._removeInactiveBinding( binding );
  20224. }
  20225. }
  20226. }
  20227. // remove a targeted clip from the cache
  20228. uncacheAction( clip, optionalRoot ) {
  20229. const action = this.existingAction( clip, optionalRoot );
  20230. if ( action !== null ) {
  20231. this._deactivateAction( action );
  20232. this._removeInactiveAction( action );
  20233. }
  20234. }
  20235. }
  20236. class Uniform {
  20237. constructor( value ) {
  20238. this.value = value;
  20239. }
  20240. clone() {
  20241. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  20242. }
  20243. }
  20244. let _id = 0;
  20245. class UniformsGroup extends EventDispatcher {
  20246. constructor() {
  20247. super();
  20248. this.isUniformsGroup = true;
  20249. Object.defineProperty( this, 'id', { value: _id ++ } );
  20250. this.name = '';
  20251. this.usage = StaticDrawUsage;
  20252. this.uniforms = [];
  20253. }
  20254. add( uniform ) {
  20255. this.uniforms.push( uniform );
  20256. return this;
  20257. }
  20258. remove( uniform ) {
  20259. const index = this.uniforms.indexOf( uniform );
  20260. if ( index !== - 1 ) this.uniforms.splice( index, 1 );
  20261. return this;
  20262. }
  20263. setName( name ) {
  20264. this.name = name;
  20265. return this;
  20266. }
  20267. setUsage( value ) {
  20268. this.usage = value;
  20269. return this;
  20270. }
  20271. dispose() {
  20272. this.dispatchEvent( { type: 'dispose' } );
  20273. return this;
  20274. }
  20275. copy( source ) {
  20276. this.name = source.name;
  20277. this.usage = source.usage;
  20278. const uniformsSource = source.uniforms;
  20279. this.uniforms.length = 0;
  20280. for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
  20281. const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
  20282. for ( let j = 0; j < uniforms.length; j ++ ) {
  20283. this.uniforms.push( uniforms[ j ].clone() );
  20284. }
  20285. }
  20286. return this;
  20287. }
  20288. clone() {
  20289. return new this.constructor().copy( this );
  20290. }
  20291. }
  20292. class InstancedInterleavedBuffer extends InterleavedBuffer {
  20293. constructor( array, stride, meshPerAttribute = 1 ) {
  20294. super( array, stride );
  20295. this.isInstancedInterleavedBuffer = true;
  20296. this.meshPerAttribute = meshPerAttribute;
  20297. }
  20298. copy( source ) {
  20299. super.copy( source );
  20300. this.meshPerAttribute = source.meshPerAttribute;
  20301. return this;
  20302. }
  20303. clone( data ) {
  20304. const ib = super.clone( data );
  20305. ib.meshPerAttribute = this.meshPerAttribute;
  20306. return ib;
  20307. }
  20308. toJSON( data ) {
  20309. const json = super.toJSON( data );
  20310. json.isInstancedInterleavedBuffer = true;
  20311. json.meshPerAttribute = this.meshPerAttribute;
  20312. return json;
  20313. }
  20314. }
  20315. class GLBufferAttribute {
  20316. constructor( buffer, type, itemSize, elementSize, count ) {
  20317. this.isGLBufferAttribute = true;
  20318. this.name = '';
  20319. this.buffer = buffer;
  20320. this.type = type;
  20321. this.itemSize = itemSize;
  20322. this.elementSize = elementSize;
  20323. this.count = count;
  20324. this.version = 0;
  20325. }
  20326. set needsUpdate( value ) {
  20327. if ( value === true ) this.version ++;
  20328. }
  20329. setBuffer( buffer ) {
  20330. this.buffer = buffer;
  20331. return this;
  20332. }
  20333. setType( type, elementSize ) {
  20334. this.type = type;
  20335. this.elementSize = elementSize;
  20336. return this;
  20337. }
  20338. setItemSize( itemSize ) {
  20339. this.itemSize = itemSize;
  20340. return this;
  20341. }
  20342. setCount( count ) {
  20343. this.count = count;
  20344. return this;
  20345. }
  20346. }
  20347. const _matrix = /*@__PURE__*/ new Matrix4();
  20348. class Raycaster {
  20349. constructor( origin, direction, near = 0, far = Infinity ) {
  20350. this.ray = new Ray( origin, direction );
  20351. // direction is assumed to be normalized (for accurate distance calculations)
  20352. this.near = near;
  20353. this.far = far;
  20354. this.camera = null;
  20355. this.layers = new Layers();
  20356. this.params = {
  20357. Mesh: {},
  20358. Line: { threshold: 1 },
  20359. LOD: {},
  20360. Points: { threshold: 1 },
  20361. Sprite: {}
  20362. };
  20363. }
  20364. set( origin, direction ) {
  20365. // direction is assumed to be normalized (for accurate distance calculations)
  20366. this.ray.set( origin, direction );
  20367. }
  20368. setFromCamera( coords, camera ) {
  20369. if ( camera.isPerspectiveCamera ) {
  20370. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  20371. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  20372. this.camera = camera;
  20373. } else if ( camera.isOrthographicCamera ) {
  20374. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  20375. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  20376. this.camera = camera;
  20377. } else {
  20378. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  20379. }
  20380. }
  20381. setFromXRController( controller ) {
  20382. _matrix.identity().extractRotation( controller.matrixWorld );
  20383. this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
  20384. this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
  20385. return this;
  20386. }
  20387. intersectObject( object, recursive = true, intersects = [] ) {
  20388. intersect( object, this, intersects, recursive );
  20389. intersects.sort( ascSort );
  20390. return intersects;
  20391. }
  20392. intersectObjects( objects, recursive = true, intersects = [] ) {
  20393. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  20394. intersect( objects[ i ], this, intersects, recursive );
  20395. }
  20396. intersects.sort( ascSort );
  20397. return intersects;
  20398. }
  20399. }
  20400. function ascSort( a, b ) {
  20401. return a.distance - b.distance;
  20402. }
  20403. function intersect( object, raycaster, intersects, recursive ) {
  20404. let propagate = true;
  20405. if ( object.layers.test( raycaster.layers ) ) {
  20406. const result = object.raycast( raycaster, intersects );
  20407. if ( result === false ) propagate = false;
  20408. }
  20409. if ( propagate === true && recursive === true ) {
  20410. const children = object.children;
  20411. for ( let i = 0, l = children.length; i < l; i ++ ) {
  20412. intersect( children[ i ], raycaster, intersects, true );
  20413. }
  20414. }
  20415. }
  20416. /**
  20417. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  20418. *
  20419. * phi (the polar angle) is measured from the positive y-axis. The positive y-axis is up.
  20420. * theta (the azimuthal angle) is measured from the positive z-axis.
  20421. */
  20422. class Spherical {
  20423. constructor( radius = 1, phi = 0, theta = 0 ) {
  20424. this.radius = radius;
  20425. this.phi = phi; // polar angle
  20426. this.theta = theta; // azimuthal angle
  20427. return this;
  20428. }
  20429. set( radius, phi, theta ) {
  20430. this.radius = radius;
  20431. this.phi = phi;
  20432. this.theta = theta;
  20433. return this;
  20434. }
  20435. copy( other ) {
  20436. this.radius = other.radius;
  20437. this.phi = other.phi;
  20438. this.theta = other.theta;
  20439. return this;
  20440. }
  20441. // restrict phi to be between EPS and PI-EPS
  20442. makeSafe() {
  20443. const EPS = 0.000001;
  20444. this.phi = clamp( this.phi, EPS, Math.PI - EPS );
  20445. return this;
  20446. }
  20447. setFromVector3( v ) {
  20448. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20449. }
  20450. setFromCartesianCoords( x, y, z ) {
  20451. this.radius = Math.sqrt( x * x + y * y + z * z );
  20452. if ( this.radius === 0 ) {
  20453. this.theta = 0;
  20454. this.phi = 0;
  20455. } else {
  20456. this.theta = Math.atan2( x, z );
  20457. this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) );
  20458. }
  20459. return this;
  20460. }
  20461. clone() {
  20462. return new this.constructor().copy( this );
  20463. }
  20464. }
  20465. /**
  20466. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  20467. */
  20468. class Cylindrical {
  20469. constructor( radius = 1, theta = 0, y = 0 ) {
  20470. this.radius = radius; // distance from the origin to a point in the x-z plane
  20471. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  20472. this.y = y; // height above the x-z plane
  20473. return this;
  20474. }
  20475. set( radius, theta, y ) {
  20476. this.radius = radius;
  20477. this.theta = theta;
  20478. this.y = y;
  20479. return this;
  20480. }
  20481. copy( other ) {
  20482. this.radius = other.radius;
  20483. this.theta = other.theta;
  20484. this.y = other.y;
  20485. return this;
  20486. }
  20487. setFromVector3( v ) {
  20488. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20489. }
  20490. setFromCartesianCoords( x, y, z ) {
  20491. this.radius = Math.sqrt( x * x + z * z );
  20492. this.theta = Math.atan2( x, z );
  20493. this.y = y;
  20494. return this;
  20495. }
  20496. clone() {
  20497. return new this.constructor().copy( this );
  20498. }
  20499. }
  20500. class Matrix2 {
  20501. constructor( n11, n12, n21, n22 ) {
  20502. Matrix2.prototype.isMatrix2 = true;
  20503. this.elements = [
  20504. 1, 0,
  20505. 0, 1,
  20506. ];
  20507. if ( n11 !== undefined ) {
  20508. this.set( n11, n12, n21, n22 );
  20509. }
  20510. }
  20511. identity() {
  20512. this.set(
  20513. 1, 0,
  20514. 0, 1,
  20515. );
  20516. return this;
  20517. }
  20518. fromArray( array, offset = 0 ) {
  20519. for ( let i = 0; i < 4; i ++ ) {
  20520. this.elements[ i ] = array[ i + offset ];
  20521. }
  20522. return this;
  20523. }
  20524. set( n11, n12, n21, n22 ) {
  20525. const te = this.elements;
  20526. te[ 0 ] = n11; te[ 2 ] = n12;
  20527. te[ 1 ] = n21; te[ 3 ] = n22;
  20528. return this;
  20529. }
  20530. }
  20531. const _vector$4 = /*@__PURE__*/ new Vector2();
  20532. class Box2 {
  20533. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  20534. this.isBox2 = true;
  20535. this.min = min;
  20536. this.max = max;
  20537. }
  20538. set( min, max ) {
  20539. this.min.copy( min );
  20540. this.max.copy( max );
  20541. return this;
  20542. }
  20543. setFromPoints( points ) {
  20544. this.makeEmpty();
  20545. for ( let i = 0, il = points.length; i < il; i ++ ) {
  20546. this.expandByPoint( points[ i ] );
  20547. }
  20548. return this;
  20549. }
  20550. setFromCenterAndSize( center, size ) {
  20551. const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 );
  20552. this.min.copy( center ).sub( halfSize );
  20553. this.max.copy( center ).add( halfSize );
  20554. return this;
  20555. }
  20556. clone() {
  20557. return new this.constructor().copy( this );
  20558. }
  20559. copy( box ) {
  20560. this.min.copy( box.min );
  20561. this.max.copy( box.max );
  20562. return this;
  20563. }
  20564. makeEmpty() {
  20565. this.min.x = this.min.y = + Infinity;
  20566. this.max.x = this.max.y = - Infinity;
  20567. return this;
  20568. }
  20569. isEmpty() {
  20570. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  20571. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  20572. }
  20573. getCenter( target ) {
  20574. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  20575. }
  20576. getSize( target ) {
  20577. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  20578. }
  20579. expandByPoint( point ) {
  20580. this.min.min( point );
  20581. this.max.max( point );
  20582. return this;
  20583. }
  20584. expandByVector( vector ) {
  20585. this.min.sub( vector );
  20586. this.max.add( vector );
  20587. return this;
  20588. }
  20589. expandByScalar( scalar ) {
  20590. this.min.addScalar( - scalar );
  20591. this.max.addScalar( scalar );
  20592. return this;
  20593. }
  20594. containsPoint( point ) {
  20595. return point.x >= this.min.x && point.x <= this.max.x &&
  20596. point.y >= this.min.y && point.y <= this.max.y;
  20597. }
  20598. containsBox( box ) {
  20599. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  20600. this.min.y <= box.min.y && box.max.y <= this.max.y;
  20601. }
  20602. getParameter( point, target ) {
  20603. // This can potentially have a divide by zero if the box
  20604. // has a size dimension of 0.
  20605. return target.set(
  20606. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  20607. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  20608. );
  20609. }
  20610. intersectsBox( box ) {
  20611. // using 4 splitting planes to rule out intersections
  20612. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  20613. box.max.y >= this.min.y && box.min.y <= this.max.y;
  20614. }
  20615. clampPoint( point, target ) {
  20616. return target.copy( point ).clamp( this.min, this.max );
  20617. }
  20618. distanceToPoint( point ) {
  20619. return this.clampPoint( point, _vector$4 ).distanceTo( point );
  20620. }
  20621. intersect( box ) {
  20622. this.min.max( box.min );
  20623. this.max.min( box.max );
  20624. if ( this.isEmpty() ) this.makeEmpty();
  20625. return this;
  20626. }
  20627. union( box ) {
  20628. this.min.min( box.min );
  20629. this.max.max( box.max );
  20630. return this;
  20631. }
  20632. translate( offset ) {
  20633. this.min.add( offset );
  20634. this.max.add( offset );
  20635. return this;
  20636. }
  20637. equals( box ) {
  20638. return box.min.equals( this.min ) && box.max.equals( this.max );
  20639. }
  20640. }
  20641. const _startP = /*@__PURE__*/ new Vector3();
  20642. const _startEnd = /*@__PURE__*/ new Vector3();
  20643. class Line3 {
  20644. constructor( start = new Vector3(), end = new Vector3() ) {
  20645. this.start = start;
  20646. this.end = end;
  20647. }
  20648. set( start, end ) {
  20649. this.start.copy( start );
  20650. this.end.copy( end );
  20651. return this;
  20652. }
  20653. copy( line ) {
  20654. this.start.copy( line.start );
  20655. this.end.copy( line.end );
  20656. return this;
  20657. }
  20658. getCenter( target ) {
  20659. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  20660. }
  20661. delta( target ) {
  20662. return target.subVectors( this.end, this.start );
  20663. }
  20664. distanceSq() {
  20665. return this.start.distanceToSquared( this.end );
  20666. }
  20667. distance() {
  20668. return this.start.distanceTo( this.end );
  20669. }
  20670. at( t, target ) {
  20671. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20672. }
  20673. closestPointToPointParameter( point, clampToLine ) {
  20674. _startP.subVectors( point, this.start );
  20675. _startEnd.subVectors( this.end, this.start );
  20676. const startEnd2 = _startEnd.dot( _startEnd );
  20677. const startEnd_startP = _startEnd.dot( _startP );
  20678. let t = startEnd_startP / startEnd2;
  20679. if ( clampToLine ) {
  20680. t = clamp( t, 0, 1 );
  20681. }
  20682. return t;
  20683. }
  20684. closestPointToPoint( point, clampToLine, target ) {
  20685. const t = this.closestPointToPointParameter( point, clampToLine );
  20686. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20687. }
  20688. applyMatrix4( matrix ) {
  20689. this.start.applyMatrix4( matrix );
  20690. this.end.applyMatrix4( matrix );
  20691. return this;
  20692. }
  20693. equals( line ) {
  20694. return line.start.equals( this.start ) && line.end.equals( this.end );
  20695. }
  20696. clone() {
  20697. return new this.constructor().copy( this );
  20698. }
  20699. }
  20700. const _vector$3 = /*@__PURE__*/ new Vector3();
  20701. class SpotLightHelper extends Object3D {
  20702. constructor( light, color ) {
  20703. super();
  20704. this.light = light;
  20705. this.matrixAutoUpdate = false;
  20706. this.color = color;
  20707. this.type = 'SpotLightHelper';
  20708. const geometry = new BufferGeometry();
  20709. const positions = [
  20710. 0, 0, 0, 0, 0, 1,
  20711. 0, 0, 0, 1, 0, 1,
  20712. 0, 0, 0, - 1, 0, 1,
  20713. 0, 0, 0, 0, 1, 1,
  20714. 0, 0, 0, 0, - 1, 1
  20715. ];
  20716. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  20717. const p1 = ( i / l ) * Math.PI * 2;
  20718. const p2 = ( j / l ) * Math.PI * 2;
  20719. positions.push(
  20720. Math.cos( p1 ), Math.sin( p1 ), 1,
  20721. Math.cos( p2 ), Math.sin( p2 ), 1
  20722. );
  20723. }
  20724. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  20725. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  20726. this.cone = new LineSegments( geometry, material );
  20727. this.add( this.cone );
  20728. this.update();
  20729. }
  20730. dispose() {
  20731. this.cone.geometry.dispose();
  20732. this.cone.material.dispose();
  20733. }
  20734. update() {
  20735. this.light.updateWorldMatrix( true, false );
  20736. this.light.target.updateWorldMatrix( true, false );
  20737. // update the local matrix based on the parent and light target transforms
  20738. if ( this.parent ) {
  20739. this.parent.updateWorldMatrix( true );
  20740. this.matrix
  20741. .copy( this.parent.matrixWorld )
  20742. .invert()
  20743. .multiply( this.light.matrixWorld );
  20744. } else {
  20745. this.matrix.copy( this.light.matrixWorld );
  20746. }
  20747. this.matrixWorld.copy( this.light.matrixWorld );
  20748. const coneLength = this.light.distance ? this.light.distance : 1000;
  20749. const coneWidth = coneLength * Math.tan( this.light.angle );
  20750. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20751. _vector$3.setFromMatrixPosition( this.light.target.matrixWorld );
  20752. this.cone.lookAt( _vector$3 );
  20753. if ( this.color !== undefined ) {
  20754. this.cone.material.color.set( this.color );
  20755. } else {
  20756. this.cone.material.color.copy( this.light.color );
  20757. }
  20758. }
  20759. }
  20760. const _vector$2 = /*@__PURE__*/ new Vector3();
  20761. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  20762. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  20763. class SkeletonHelper extends LineSegments {
  20764. constructor( object ) {
  20765. const bones = getBoneList( object );
  20766. const geometry = new BufferGeometry();
  20767. const vertices = [];
  20768. const colors = [];
  20769. const color1 = new Color( 0, 0, 1 );
  20770. const color2 = new Color( 0, 1, 0 );
  20771. for ( let i = 0; i < bones.length; i ++ ) {
  20772. const bone = bones[ i ];
  20773. if ( bone.parent && bone.parent.isBone ) {
  20774. vertices.push( 0, 0, 0 );
  20775. vertices.push( 0, 0, 0 );
  20776. colors.push( color1.r, color1.g, color1.b );
  20777. colors.push( color2.r, color2.g, color2.b );
  20778. }
  20779. }
  20780. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20781. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20782. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  20783. super( geometry, material );
  20784. this.isSkeletonHelper = true;
  20785. this.type = 'SkeletonHelper';
  20786. this.root = object;
  20787. this.bones = bones;
  20788. this.matrix = object.matrixWorld;
  20789. this.matrixAutoUpdate = false;
  20790. }
  20791. updateMatrixWorld( force ) {
  20792. const bones = this.bones;
  20793. const geometry = this.geometry;
  20794. const position = geometry.getAttribute( 'position' );
  20795. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  20796. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  20797. const bone = bones[ i ];
  20798. if ( bone.parent && bone.parent.isBone ) {
  20799. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  20800. _vector$2.setFromMatrixPosition( _boneMatrix );
  20801. position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z );
  20802. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  20803. _vector$2.setFromMatrixPosition( _boneMatrix );
  20804. position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z );
  20805. j += 2;
  20806. }
  20807. }
  20808. geometry.getAttribute( 'position' ).needsUpdate = true;
  20809. super.updateMatrixWorld( force );
  20810. }
  20811. dispose() {
  20812. this.geometry.dispose();
  20813. this.material.dispose();
  20814. }
  20815. }
  20816. function getBoneList( object ) {
  20817. const boneList = [];
  20818. if ( object.isBone === true ) {
  20819. boneList.push( object );
  20820. }
  20821. for ( let i = 0; i < object.children.length; i ++ ) {
  20822. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  20823. }
  20824. return boneList;
  20825. }
  20826. class PointLightHelper extends Mesh {
  20827. constructor( light, sphereSize, color ) {
  20828. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  20829. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20830. super( geometry, material );
  20831. this.light = light;
  20832. this.color = color;
  20833. this.type = 'PointLightHelper';
  20834. this.matrix = this.light.matrixWorld;
  20835. this.matrixAutoUpdate = false;
  20836. this.update();
  20837. /*
  20838. // TODO: delete this comment?
  20839. const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20840. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20841. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20842. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20843. const d = light.distance;
  20844. if ( d === 0.0 ) {
  20845. this.lightDistance.visible = false;
  20846. } else {
  20847. this.lightDistance.scale.set( d, d, d );
  20848. }
  20849. this.add( this.lightDistance );
  20850. */
  20851. }
  20852. dispose() {
  20853. this.geometry.dispose();
  20854. this.material.dispose();
  20855. }
  20856. update() {
  20857. this.light.updateWorldMatrix( true, false );
  20858. if ( this.color !== undefined ) {
  20859. this.material.color.set( this.color );
  20860. } else {
  20861. this.material.color.copy( this.light.color );
  20862. }
  20863. /*
  20864. const d = this.light.distance;
  20865. if ( d === 0.0 ) {
  20866. this.lightDistance.visible = false;
  20867. } else {
  20868. this.lightDistance.visible = true;
  20869. this.lightDistance.scale.set( d, d, d );
  20870. }
  20871. */
  20872. }
  20873. }
  20874. const _vector$1 = /*@__PURE__*/ new Vector3();
  20875. const _color1 = /*@__PURE__*/ new Color();
  20876. const _color2 = /*@__PURE__*/ new Color();
  20877. class HemisphereLightHelper extends Object3D {
  20878. constructor( light, size, color ) {
  20879. super();
  20880. this.light = light;
  20881. this.matrix = light.matrixWorld;
  20882. this.matrixAutoUpdate = false;
  20883. this.color = color;
  20884. this.type = 'HemisphereLightHelper';
  20885. const geometry = new OctahedronGeometry( size );
  20886. geometry.rotateY( Math.PI * 0.5 );
  20887. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20888. if ( this.color === undefined ) this.material.vertexColors = true;
  20889. const position = geometry.getAttribute( 'position' );
  20890. const colors = new Float32Array( position.count * 3 );
  20891. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  20892. this.add( new Mesh( geometry, this.material ) );
  20893. this.update();
  20894. }
  20895. dispose() {
  20896. this.children[ 0 ].geometry.dispose();
  20897. this.children[ 0 ].material.dispose();
  20898. }
  20899. update() {
  20900. const mesh = this.children[ 0 ];
  20901. if ( this.color !== undefined ) {
  20902. this.material.color.set( this.color );
  20903. } else {
  20904. const colors = mesh.geometry.getAttribute( 'color' );
  20905. _color1.copy( this.light.color );
  20906. _color2.copy( this.light.groundColor );
  20907. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  20908. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  20909. colors.setXYZ( i, color.r, color.g, color.b );
  20910. }
  20911. colors.needsUpdate = true;
  20912. }
  20913. this.light.updateWorldMatrix( true, false );
  20914. mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20915. }
  20916. }
  20917. class GridHelper extends LineSegments {
  20918. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  20919. color1 = new Color( color1 );
  20920. color2 = new Color( color2 );
  20921. const center = divisions / 2;
  20922. const step = size / divisions;
  20923. const halfSize = size / 2;
  20924. const vertices = [], colors = [];
  20925. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  20926. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  20927. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  20928. const color = i === center ? color1 : color2;
  20929. color.toArray( colors, j ); j += 3;
  20930. color.toArray( colors, j ); j += 3;
  20931. color.toArray( colors, j ); j += 3;
  20932. color.toArray( colors, j ); j += 3;
  20933. }
  20934. const geometry = new BufferGeometry();
  20935. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20936. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20937. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  20938. super( geometry, material );
  20939. this.type = 'GridHelper';
  20940. }
  20941. dispose() {
  20942. this.geometry.dispose();
  20943. this.material.dispose();
  20944. }
  20945. }
  20946. class PolarGridHelper extends LineSegments {
  20947. constructor( radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  20948. color1 = new Color( color1 );
  20949. color2 = new Color( color2 );
  20950. const vertices = [];
  20951. const colors = [];
  20952. // create the sectors
  20953. if ( sectors > 1 ) {
  20954. for ( let i = 0; i < sectors; i ++ ) {
  20955. const v = ( i / sectors ) * ( Math.PI * 2 );
  20956. const x = Math.sin( v ) * radius;
  20957. const z = Math.cos( v ) * radius;
  20958. vertices.push( 0, 0, 0 );
  20959. vertices.push( x, 0, z );
  20960. const color = ( i & 1 ) ? color1 : color2;
  20961. colors.push( color.r, color.g, color.b );
  20962. colors.push( color.r, color.g, color.b );
  20963. }
  20964. }
  20965. // create the rings
  20966. for ( let i = 0; i < rings; i ++ ) {
  20967. const color = ( i & 1 ) ? color1 : color2;
  20968. const r = radius - ( radius / rings * i );
  20969. for ( let j = 0; j < divisions; j ++ ) {
  20970. // first vertex
  20971. let v = ( j / divisions ) * ( Math.PI * 2 );
  20972. let x = Math.sin( v ) * r;
  20973. let z = Math.cos( v ) * r;
  20974. vertices.push( x, 0, z );
  20975. colors.push( color.r, color.g, color.b );
  20976. // second vertex
  20977. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  20978. x = Math.sin( v ) * r;
  20979. z = Math.cos( v ) * r;
  20980. vertices.push( x, 0, z );
  20981. colors.push( color.r, color.g, color.b );
  20982. }
  20983. }
  20984. const geometry = new BufferGeometry();
  20985. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20986. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20987. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  20988. super( geometry, material );
  20989. this.type = 'PolarGridHelper';
  20990. }
  20991. dispose() {
  20992. this.geometry.dispose();
  20993. this.material.dispose();
  20994. }
  20995. }
  20996. const _v1 = /*@__PURE__*/ new Vector3();
  20997. const _v2 = /*@__PURE__*/ new Vector3();
  20998. const _v3 = /*@__PURE__*/ new Vector3();
  20999. class DirectionalLightHelper extends Object3D {
  21000. constructor( light, size, color ) {
  21001. super();
  21002. this.light = light;
  21003. this.matrix = light.matrixWorld;
  21004. this.matrixAutoUpdate = false;
  21005. this.color = color;
  21006. this.type = 'DirectionalLightHelper';
  21007. if ( size === undefined ) size = 1;
  21008. let geometry = new BufferGeometry();
  21009. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  21010. - size, size, 0,
  21011. size, size, 0,
  21012. size, - size, 0,
  21013. - size, - size, 0,
  21014. - size, size, 0
  21015. ], 3 ) );
  21016. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  21017. this.lightPlane = new Line( geometry, material );
  21018. this.add( this.lightPlane );
  21019. geometry = new BufferGeometry();
  21020. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  21021. this.targetLine = new Line( geometry, material );
  21022. this.add( this.targetLine );
  21023. this.update();
  21024. }
  21025. dispose() {
  21026. this.lightPlane.geometry.dispose();
  21027. this.lightPlane.material.dispose();
  21028. this.targetLine.geometry.dispose();
  21029. this.targetLine.material.dispose();
  21030. }
  21031. update() {
  21032. this.light.updateWorldMatrix( true, false );
  21033. this.light.target.updateWorldMatrix( true, false );
  21034. _v1.setFromMatrixPosition( this.light.matrixWorld );
  21035. _v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21036. _v3.subVectors( _v2, _v1 );
  21037. this.lightPlane.lookAt( _v2 );
  21038. if ( this.color !== undefined ) {
  21039. this.lightPlane.material.color.set( this.color );
  21040. this.targetLine.material.color.set( this.color );
  21041. } else {
  21042. this.lightPlane.material.color.copy( this.light.color );
  21043. this.targetLine.material.color.copy( this.light.color );
  21044. }
  21045. this.targetLine.lookAt( _v2 );
  21046. this.targetLine.scale.z = _v3.length();
  21047. }
  21048. }
  21049. const _vector = /*@__PURE__*/ new Vector3();
  21050. const _camera = /*@__PURE__*/ new Camera();
  21051. /**
  21052. * - shows frustum, line of sight and up of the camera
  21053. * - suitable for fast updates
  21054. * - based on frustum visualization in lightgl.js shadowmap example
  21055. * https://github.com/evanw/lightgl.js/blob/master/tests/shadowmap.html
  21056. */
  21057. class CameraHelper extends LineSegments {
  21058. constructor( camera ) {
  21059. const geometry = new BufferGeometry();
  21060. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  21061. const vertices = [];
  21062. const colors = [];
  21063. const pointMap = {};
  21064. // near
  21065. addLine( 'n1', 'n2' );
  21066. addLine( 'n2', 'n4' );
  21067. addLine( 'n4', 'n3' );
  21068. addLine( 'n3', 'n1' );
  21069. // far
  21070. addLine( 'f1', 'f2' );
  21071. addLine( 'f2', 'f4' );
  21072. addLine( 'f4', 'f3' );
  21073. addLine( 'f3', 'f1' );
  21074. // sides
  21075. addLine( 'n1', 'f1' );
  21076. addLine( 'n2', 'f2' );
  21077. addLine( 'n3', 'f3' );
  21078. addLine( 'n4', 'f4' );
  21079. // cone
  21080. addLine( 'p', 'n1' );
  21081. addLine( 'p', 'n2' );
  21082. addLine( 'p', 'n3' );
  21083. addLine( 'p', 'n4' );
  21084. // up
  21085. addLine( 'u1', 'u2' );
  21086. addLine( 'u2', 'u3' );
  21087. addLine( 'u3', 'u1' );
  21088. // target
  21089. addLine( 'c', 't' );
  21090. addLine( 'p', 'c' );
  21091. // cross
  21092. addLine( 'cn1', 'cn2' );
  21093. addLine( 'cn3', 'cn4' );
  21094. addLine( 'cf1', 'cf2' );
  21095. addLine( 'cf3', 'cf4' );
  21096. function addLine( a, b ) {
  21097. addPoint( a );
  21098. addPoint( b );
  21099. }
  21100. function addPoint( id ) {
  21101. vertices.push( 0, 0, 0 );
  21102. colors.push( 0, 0, 0 );
  21103. if ( pointMap[ id ] === undefined ) {
  21104. pointMap[ id ] = [];
  21105. }
  21106. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  21107. }
  21108. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21109. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21110. super( geometry, material );
  21111. this.type = 'CameraHelper';
  21112. this.camera = camera;
  21113. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  21114. this.matrix = camera.matrixWorld;
  21115. this.matrixAutoUpdate = false;
  21116. this.pointMap = pointMap;
  21117. this.update();
  21118. // colors
  21119. const colorFrustum = new Color( 0xffaa00 );
  21120. const colorCone = new Color( 0xff0000 );
  21121. const colorUp = new Color( 0x00aaff );
  21122. const colorTarget = new Color( 0xffffff );
  21123. const colorCross = new Color( 0x333333 );
  21124. this.setColors( colorFrustum, colorCone, colorUp, colorTarget, colorCross );
  21125. }
  21126. setColors( frustum, cone, up, target, cross ) {
  21127. const geometry = this.geometry;
  21128. const colorAttribute = geometry.getAttribute( 'color' );
  21129. // near
  21130. colorAttribute.setXYZ( 0, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 1, frustum.r, frustum.g, frustum.b ); // n1, n2
  21131. colorAttribute.setXYZ( 2, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 3, frustum.r, frustum.g, frustum.b ); // n2, n4
  21132. colorAttribute.setXYZ( 4, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 5, frustum.r, frustum.g, frustum.b ); // n4, n3
  21133. colorAttribute.setXYZ( 6, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 7, frustum.r, frustum.g, frustum.b ); // n3, n1
  21134. // far
  21135. colorAttribute.setXYZ( 8, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 9, frustum.r, frustum.g, frustum.b ); // f1, f2
  21136. colorAttribute.setXYZ( 10, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 11, frustum.r, frustum.g, frustum.b ); // f2, f4
  21137. colorAttribute.setXYZ( 12, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 13, frustum.r, frustum.g, frustum.b ); // f4, f3
  21138. colorAttribute.setXYZ( 14, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 15, frustum.r, frustum.g, frustum.b ); // f3, f1
  21139. // sides
  21140. colorAttribute.setXYZ( 16, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 17, frustum.r, frustum.g, frustum.b ); // n1, f1
  21141. colorAttribute.setXYZ( 18, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 19, frustum.r, frustum.g, frustum.b ); // n2, f2
  21142. colorAttribute.setXYZ( 20, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 21, frustum.r, frustum.g, frustum.b ); // n3, f3
  21143. colorAttribute.setXYZ( 22, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 23, frustum.r, frustum.g, frustum.b ); // n4, f4
  21144. // cone
  21145. colorAttribute.setXYZ( 24, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 25, cone.r, cone.g, cone.b ); // p, n1
  21146. colorAttribute.setXYZ( 26, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 27, cone.r, cone.g, cone.b ); // p, n2
  21147. colorAttribute.setXYZ( 28, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 29, cone.r, cone.g, cone.b ); // p, n3
  21148. colorAttribute.setXYZ( 30, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 31, cone.r, cone.g, cone.b ); // p, n4
  21149. // up
  21150. colorAttribute.setXYZ( 32, up.r, up.g, up.b ); colorAttribute.setXYZ( 33, up.r, up.g, up.b ); // u1, u2
  21151. colorAttribute.setXYZ( 34, up.r, up.g, up.b ); colorAttribute.setXYZ( 35, up.r, up.g, up.b ); // u2, u3
  21152. colorAttribute.setXYZ( 36, up.r, up.g, up.b ); colorAttribute.setXYZ( 37, up.r, up.g, up.b ); // u3, u1
  21153. // target
  21154. colorAttribute.setXYZ( 38, target.r, target.g, target.b ); colorAttribute.setXYZ( 39, target.r, target.g, target.b ); // c, t
  21155. colorAttribute.setXYZ( 40, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 41, cross.r, cross.g, cross.b ); // p, c
  21156. // cross
  21157. colorAttribute.setXYZ( 42, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 43, cross.r, cross.g, cross.b ); // cn1, cn2
  21158. colorAttribute.setXYZ( 44, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 45, cross.r, cross.g, cross.b ); // cn3, cn4
  21159. colorAttribute.setXYZ( 46, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 47, cross.r, cross.g, cross.b ); // cf1, cf2
  21160. colorAttribute.setXYZ( 48, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 49, cross.r, cross.g, cross.b ); // cf3, cf4
  21161. colorAttribute.needsUpdate = true;
  21162. }
  21163. update() {
  21164. const geometry = this.geometry;
  21165. const pointMap = this.pointMap;
  21166. const w = 1, h = 1;
  21167. // we need just camera projection matrix inverse
  21168. // world matrix must be identity
  21169. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  21170. // center / target
  21171. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  21172. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  21173. // near
  21174. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  21175. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  21176. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  21177. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  21178. // far
  21179. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  21180. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  21181. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  21182. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  21183. // up
  21184. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  21185. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  21186. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  21187. // cross
  21188. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  21189. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  21190. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  21191. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  21192. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  21193. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  21194. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  21195. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  21196. geometry.getAttribute( 'position' ).needsUpdate = true;
  21197. }
  21198. dispose() {
  21199. this.geometry.dispose();
  21200. this.material.dispose();
  21201. }
  21202. }
  21203. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  21204. _vector.set( x, y, z ).unproject( camera );
  21205. const points = pointMap[ point ];
  21206. if ( points !== undefined ) {
  21207. const position = geometry.getAttribute( 'position' );
  21208. for ( let i = 0, l = points.length; i < l; i ++ ) {
  21209. position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
  21210. }
  21211. }
  21212. }
  21213. const _box = /*@__PURE__*/ new Box3();
  21214. class BoxHelper extends LineSegments {
  21215. constructor( object, color = 0xffff00 ) {
  21216. 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 ] );
  21217. const positions = new Float32Array( 8 * 3 );
  21218. const geometry = new BufferGeometry();
  21219. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21220. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  21221. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21222. this.object = object;
  21223. this.type = 'BoxHelper';
  21224. this.matrixAutoUpdate = false;
  21225. this.update();
  21226. }
  21227. update( object ) {
  21228. if ( object !== undefined ) {
  21229. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  21230. }
  21231. if ( this.object !== undefined ) {
  21232. _box.setFromObject( this.object );
  21233. }
  21234. if ( _box.isEmpty() ) return;
  21235. const min = _box.min;
  21236. const max = _box.max;
  21237. /*
  21238. 5____4
  21239. 1/___0/|
  21240. | 6__|_7
  21241. 2/___3/
  21242. 0: max.x, max.y, max.z
  21243. 1: min.x, max.y, max.z
  21244. 2: min.x, min.y, max.z
  21245. 3: max.x, min.y, max.z
  21246. 4: max.x, max.y, min.z
  21247. 5: min.x, max.y, min.z
  21248. 6: min.x, min.y, min.z
  21249. 7: max.x, min.y, min.z
  21250. */
  21251. const position = this.geometry.attributes.position;
  21252. const array = position.array;
  21253. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21254. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21255. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21256. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21257. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21258. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21259. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21260. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21261. position.needsUpdate = true;
  21262. this.geometry.computeBoundingSphere();
  21263. }
  21264. setFromObject( object ) {
  21265. this.object = object;
  21266. this.update();
  21267. return this;
  21268. }
  21269. copy( source, recursive ) {
  21270. super.copy( source, recursive );
  21271. this.object = source.object;
  21272. return this;
  21273. }
  21274. dispose() {
  21275. this.geometry.dispose();
  21276. this.material.dispose();
  21277. }
  21278. }
  21279. class Box3Helper extends LineSegments {
  21280. constructor( box, color = 0xffff00 ) {
  21281. 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 ] );
  21282. 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 ];
  21283. const geometry = new BufferGeometry();
  21284. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21285. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21286. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21287. this.box = box;
  21288. this.type = 'Box3Helper';
  21289. this.geometry.computeBoundingSphere();
  21290. }
  21291. updateMatrixWorld( force ) {
  21292. const box = this.box;
  21293. if ( box.isEmpty() ) return;
  21294. box.getCenter( this.position );
  21295. box.getSize( this.scale );
  21296. this.scale.multiplyScalar( 0.5 );
  21297. super.updateMatrixWorld( force );
  21298. }
  21299. dispose() {
  21300. this.geometry.dispose();
  21301. this.material.dispose();
  21302. }
  21303. }
  21304. class PlaneHelper extends Line {
  21305. constructor( plane, size = 1, hex = 0xffff00 ) {
  21306. const color = hex;
  21307. 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 ];
  21308. const geometry = new BufferGeometry();
  21309. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21310. geometry.computeBoundingSphere();
  21311. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21312. this.type = 'PlaneHelper';
  21313. this.plane = plane;
  21314. this.size = size;
  21315. const positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  21316. const geometry2 = new BufferGeometry();
  21317. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  21318. geometry2.computeBoundingSphere();
  21319. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  21320. }
  21321. updateMatrixWorld( force ) {
  21322. this.position.set( 0, 0, 0 );
  21323. this.scale.set( 0.5 * this.size, 0.5 * this.size, 1 );
  21324. this.lookAt( this.plane.normal );
  21325. this.translateZ( - this.plane.constant );
  21326. super.updateMatrixWorld( force );
  21327. }
  21328. dispose() {
  21329. this.geometry.dispose();
  21330. this.material.dispose();
  21331. this.children[ 0 ].geometry.dispose();
  21332. this.children[ 0 ].material.dispose();
  21333. }
  21334. }
  21335. const _axis = /*@__PURE__*/ new Vector3();
  21336. let _lineGeometry, _coneGeometry;
  21337. class ArrowHelper extends Object3D {
  21338. // dir is assumed to be normalized
  21339. 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 ) {
  21340. super();
  21341. this.type = 'ArrowHelper';
  21342. if ( _lineGeometry === undefined ) {
  21343. _lineGeometry = new BufferGeometry();
  21344. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  21345. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21346. _coneGeometry.translate( 0, - 0.5, 0 );
  21347. }
  21348. this.position.copy( origin );
  21349. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21350. this.line.matrixAutoUpdate = false;
  21351. this.add( this.line );
  21352. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  21353. this.cone.matrixAutoUpdate = false;
  21354. this.add( this.cone );
  21355. this.setDirection( dir );
  21356. this.setLength( length, headLength, headWidth );
  21357. }
  21358. setDirection( dir ) {
  21359. // dir is assumed to be normalized
  21360. if ( dir.y > 0.99999 ) {
  21361. this.quaternion.set( 0, 0, 0, 1 );
  21362. } else if ( dir.y < - 0.99999 ) {
  21363. this.quaternion.set( 1, 0, 0, 0 );
  21364. } else {
  21365. _axis.set( dir.z, 0, - dir.x ).normalize();
  21366. const radians = Math.acos( dir.y );
  21367. this.quaternion.setFromAxisAngle( _axis, radians );
  21368. }
  21369. }
  21370. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21371. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  21372. this.line.updateMatrix();
  21373. this.cone.scale.set( headWidth, headLength, headWidth );
  21374. this.cone.position.y = length;
  21375. this.cone.updateMatrix();
  21376. }
  21377. setColor( color ) {
  21378. this.line.material.color.set( color );
  21379. this.cone.material.color.set( color );
  21380. }
  21381. copy( source ) {
  21382. super.copy( source, false );
  21383. this.line.copy( source.line );
  21384. this.cone.copy( source.cone );
  21385. return this;
  21386. }
  21387. dispose() {
  21388. this.line.geometry.dispose();
  21389. this.line.material.dispose();
  21390. this.cone.geometry.dispose();
  21391. this.cone.material.dispose();
  21392. }
  21393. }
  21394. class AxesHelper extends LineSegments {
  21395. constructor( size = 1 ) {
  21396. const vertices = [
  21397. 0, 0, 0, size, 0, 0,
  21398. 0, 0, 0, 0, size, 0,
  21399. 0, 0, 0, 0, 0, size
  21400. ];
  21401. const colors = [
  21402. 1, 0, 0, 1, 0.6, 0,
  21403. 0, 1, 0, 0.6, 1, 0,
  21404. 0, 0, 1, 0, 0.6, 1
  21405. ];
  21406. const geometry = new BufferGeometry();
  21407. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21408. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21409. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21410. super( geometry, material );
  21411. this.type = 'AxesHelper';
  21412. }
  21413. setColors( xAxisColor, yAxisColor, zAxisColor ) {
  21414. const color = new Color();
  21415. const array = this.geometry.attributes.color.array;
  21416. color.set( xAxisColor );
  21417. color.toArray( array, 0 );
  21418. color.toArray( array, 3 );
  21419. color.set( yAxisColor );
  21420. color.toArray( array, 6 );
  21421. color.toArray( array, 9 );
  21422. color.set( zAxisColor );
  21423. color.toArray( array, 12 );
  21424. color.toArray( array, 15 );
  21425. this.geometry.attributes.color.needsUpdate = true;
  21426. return this;
  21427. }
  21428. dispose() {
  21429. this.geometry.dispose();
  21430. this.material.dispose();
  21431. }
  21432. }
  21433. class ShapePath {
  21434. constructor() {
  21435. this.type = 'ShapePath';
  21436. this.color = new Color();
  21437. this.subPaths = [];
  21438. this.currentPath = null;
  21439. }
  21440. moveTo( x, y ) {
  21441. this.currentPath = new Path();
  21442. this.subPaths.push( this.currentPath );
  21443. this.currentPath.moveTo( x, y );
  21444. return this;
  21445. }
  21446. lineTo( x, y ) {
  21447. this.currentPath.lineTo( x, y );
  21448. return this;
  21449. }
  21450. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  21451. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21452. return this;
  21453. }
  21454. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21455. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21456. return this;
  21457. }
  21458. splineThru( pts ) {
  21459. this.currentPath.splineThru( pts );
  21460. return this;
  21461. }
  21462. toShapes( isCCW ) {
  21463. function toShapesNoHoles( inSubpaths ) {
  21464. const shapes = [];
  21465. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21466. const tmpPath = inSubpaths[ i ];
  21467. const tmpShape = new Shape();
  21468. tmpShape.curves = tmpPath.curves;
  21469. shapes.push( tmpShape );
  21470. }
  21471. return shapes;
  21472. }
  21473. function isPointInsidePolygon( inPt, inPolygon ) {
  21474. const polyLen = inPolygon.length;
  21475. // inPt on polygon contour => immediate success or
  21476. // toggling of inside/outside at every single! intersection point of an edge
  21477. // with the horizontal line through inPt, left of inPt
  21478. // not counting lowerY endpoints of edges and whole edges on that line
  21479. let inside = false;
  21480. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21481. let edgeLowPt = inPolygon[ p ];
  21482. let edgeHighPt = inPolygon[ q ];
  21483. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  21484. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  21485. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21486. // not parallel
  21487. if ( edgeDy < 0 ) {
  21488. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21489. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21490. }
  21491. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21492. if ( inPt.y === edgeLowPt.y ) {
  21493. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21494. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21495. } else {
  21496. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21497. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21498. if ( perpEdge < 0 ) continue;
  21499. inside = ! inside; // true intersection left of inPt
  21500. }
  21501. } else {
  21502. // parallel or collinear
  21503. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21504. // edge lies on the same horizontal line as inPt
  21505. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21506. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21507. // continue;
  21508. }
  21509. }
  21510. return inside;
  21511. }
  21512. const isClockWise = ShapeUtils.isClockWise;
  21513. const subPaths = this.subPaths;
  21514. if ( subPaths.length === 0 ) return [];
  21515. let solid, tmpPath, tmpShape;
  21516. const shapes = [];
  21517. if ( subPaths.length === 1 ) {
  21518. tmpPath = subPaths[ 0 ];
  21519. tmpShape = new Shape();
  21520. tmpShape.curves = tmpPath.curves;
  21521. shapes.push( tmpShape );
  21522. return shapes;
  21523. }
  21524. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21525. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21526. // console.log("Holes first", holesFirst);
  21527. const betterShapeHoles = [];
  21528. const newShapes = [];
  21529. let newShapeHoles = [];
  21530. let mainIdx = 0;
  21531. let tmpPoints;
  21532. newShapes[ mainIdx ] = undefined;
  21533. newShapeHoles[ mainIdx ] = [];
  21534. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  21535. tmpPath = subPaths[ i ];
  21536. tmpPoints = tmpPath.getPoints();
  21537. solid = isClockWise( tmpPoints );
  21538. solid = isCCW ? ! solid : solid;
  21539. if ( solid ) {
  21540. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21541. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21542. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21543. if ( holesFirst ) mainIdx ++;
  21544. newShapeHoles[ mainIdx ] = [];
  21545. //console.log('cw', i);
  21546. } else {
  21547. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21548. //console.log('ccw', i);
  21549. }
  21550. }
  21551. // only Holes? -> probably all Shapes with wrong orientation
  21552. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21553. if ( newShapes.length > 1 ) {
  21554. let ambiguous = false;
  21555. let toChange = 0;
  21556. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21557. betterShapeHoles[ sIdx ] = [];
  21558. }
  21559. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21560. const sho = newShapeHoles[ sIdx ];
  21561. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21562. const ho = sho[ hIdx ];
  21563. let hole_unassigned = true;
  21564. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21565. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21566. if ( sIdx !== s2Idx ) toChange ++;
  21567. if ( hole_unassigned ) {
  21568. hole_unassigned = false;
  21569. betterShapeHoles[ s2Idx ].push( ho );
  21570. } else {
  21571. ambiguous = true;
  21572. }
  21573. }
  21574. }
  21575. if ( hole_unassigned ) {
  21576. betterShapeHoles[ sIdx ].push( ho );
  21577. }
  21578. }
  21579. }
  21580. if ( toChange > 0 && ambiguous === false ) {
  21581. newShapeHoles = betterShapeHoles;
  21582. }
  21583. }
  21584. let tmpHoles;
  21585. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  21586. tmpShape = newShapes[ i ].s;
  21587. shapes.push( tmpShape );
  21588. tmpHoles = newShapeHoles[ i ];
  21589. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21590. tmpShape.holes.push( tmpHoles[ j ].h );
  21591. }
  21592. }
  21593. //console.log("shape", shapes);
  21594. return shapes;
  21595. }
  21596. }
  21597. class Controls extends EventDispatcher {
  21598. constructor( object, domElement = null ) {
  21599. super();
  21600. this.object = object;
  21601. this.domElement = domElement;
  21602. this.enabled = true;
  21603. this.state = - 1;
  21604. this.keys = {};
  21605. this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
  21606. this.touches = { ONE: null, TWO: null };
  21607. }
  21608. connect() {}
  21609. disconnect() {}
  21610. dispose() {}
  21611. update( /* delta */ ) {}
  21612. }
  21613. function contain( texture, aspect ) {
  21614. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21615. if ( imageAspect > aspect ) {
  21616. texture.repeat.x = 1;
  21617. texture.repeat.y = imageAspect / aspect;
  21618. texture.offset.x = 0;
  21619. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21620. } else {
  21621. texture.repeat.x = aspect / imageAspect;
  21622. texture.repeat.y = 1;
  21623. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21624. texture.offset.y = 0;
  21625. }
  21626. return texture;
  21627. }
  21628. function cover( texture, aspect ) {
  21629. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21630. if ( imageAspect > aspect ) {
  21631. texture.repeat.x = aspect / imageAspect;
  21632. texture.repeat.y = 1;
  21633. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21634. texture.offset.y = 0;
  21635. } else {
  21636. texture.repeat.x = 1;
  21637. texture.repeat.y = imageAspect / aspect;
  21638. texture.offset.x = 0;
  21639. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21640. }
  21641. return texture;
  21642. }
  21643. function fill( texture ) {
  21644. texture.repeat.x = 1;
  21645. texture.repeat.y = 1;
  21646. texture.offset.x = 0;
  21647. texture.offset.y = 0;
  21648. return texture;
  21649. }
  21650. /**
  21651. * Given the width, height, format, and type of a texture. Determines how many
  21652. * bytes must be used to represent the texture.
  21653. */
  21654. function getByteLength( width, height, format, type ) {
  21655. const typeByteLength = getTextureTypeByteLength( type );
  21656. switch ( format ) {
  21657. // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
  21658. case AlphaFormat:
  21659. return width * height;
  21660. case LuminanceFormat:
  21661. return width * height;
  21662. case LuminanceAlphaFormat:
  21663. return width * height * 2;
  21664. case RedFormat:
  21665. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21666. case RedIntegerFormat:
  21667. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21668. case RGFormat:
  21669. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21670. case RGIntegerFormat:
  21671. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21672. case RGBFormat:
  21673. return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21674. case RGBAFormat:
  21675. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21676. case RGBAIntegerFormat:
  21677. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21678. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/
  21679. case RGB_S3TC_DXT1_Format:
  21680. case RGBA_S3TC_DXT1_Format:
  21681. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21682. case RGBA_S3TC_DXT3_Format:
  21683. case RGBA_S3TC_DXT5_Format:
  21684. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21685. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/
  21686. case RGB_PVRTC_2BPPV1_Format:
  21687. case RGBA_PVRTC_2BPPV1_Format:
  21688. return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4;
  21689. case RGB_PVRTC_4BPPV1_Format:
  21690. case RGBA_PVRTC_4BPPV1_Format:
  21691. return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2;
  21692. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/
  21693. case RGB_ETC1_Format:
  21694. case RGB_ETC2_Format:
  21695. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21696. case RGBA_ETC2_EAC_Format:
  21697. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21698. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
  21699. case RGBA_ASTC_4x4_Format:
  21700. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21701. case RGBA_ASTC_5x4_Format:
  21702. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21703. case RGBA_ASTC_5x5_Format:
  21704. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21705. case RGBA_ASTC_6x5_Format:
  21706. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21707. case RGBA_ASTC_6x6_Format:
  21708. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21709. case RGBA_ASTC_8x5_Format:
  21710. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21711. case RGBA_ASTC_8x6_Format:
  21712. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21713. case RGBA_ASTC_8x8_Format:
  21714. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21715. case RGBA_ASTC_10x5_Format:
  21716. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21717. case RGBA_ASTC_10x6_Format:
  21718. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21719. case RGBA_ASTC_10x8_Format:
  21720. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21721. case RGBA_ASTC_10x10_Format:
  21722. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21723. case RGBA_ASTC_12x10_Format:
  21724. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21725. case RGBA_ASTC_12x12_Format:
  21726. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;
  21727. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
  21728. case RGBA_BPTC_Format:
  21729. case RGB_BPTC_SIGNED_Format:
  21730. case RGB_BPTC_UNSIGNED_Format:
  21731. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21732. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
  21733. case RED_RGTC1_Format:
  21734. case SIGNED_RED_RGTC1_Format:
  21735. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
  21736. case RED_GREEN_RGTC2_Format:
  21737. case SIGNED_RED_GREEN_RGTC2_Format:
  21738. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21739. }
  21740. throw new Error(
  21741. `Unable to determine texture byte length for ${format} format.`,
  21742. );
  21743. }
  21744. function getTextureTypeByteLength( type ) {
  21745. switch ( type ) {
  21746. case UnsignedByteType:
  21747. case ByteType:
  21748. return { byteLength: 1, components: 1 };
  21749. case UnsignedShortType:
  21750. case ShortType:
  21751. case HalfFloatType:
  21752. return { byteLength: 2, components: 1 };
  21753. case UnsignedShort4444Type:
  21754. case UnsignedShort5551Type:
  21755. return { byteLength: 2, components: 4 };
  21756. case UnsignedIntType:
  21757. case IntType:
  21758. case FloatType:
  21759. return { byteLength: 4, components: 1 };
  21760. case UnsignedInt5999Type:
  21761. return { byteLength: 4, components: 3 };
  21762. }
  21763. throw new Error( `Unknown texture type ${type}.` );
  21764. }
  21765. const TextureUtils = {
  21766. contain,
  21767. cover,
  21768. fill,
  21769. getByteLength
  21770. };
  21771. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  21772. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  21773. revision: REVISION,
  21774. } } ) );
  21775. }
  21776. if ( typeof window !== 'undefined' ) {
  21777. if ( window.__THREE__ ) {
  21778. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  21779. } else {
  21780. window.__THREE__ = REVISION;
  21781. }
  21782. }
  21783. 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, 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, 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, VideoTexture, WebGL3DRenderTarget, WebGLArrayRenderTarget, WebGLCoordinateSystem, WebGLCubeRenderTarget, WebGLRenderTarget, WebGPUCoordinateSystem, WireframeGeometry, WrapAroundEnding, ZeroCurvatureEnding, ZeroFactor, ZeroSlopeEnding, ZeroStencilOp, arrayNeedsUint32, cloneUniforms, createCanvasElement, createElementNS, getByteLength, getUnlitUniformColorSpace, mergeUniforms, probeAsync, toNormalizedProjectionMatrix, toReversedProjectionMatrix, warnOnce };
粤ICP备19079148号