three.core.js 735 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113361143611536116361173611836119361203612136122361233612436125361263612736128361293613036131361323613336134361353613636137361383613936140361413614236143361443614536146361473614836149361503615136152361533615436155361563615736158361593616036161361623616336164361653616636167361683616936170361713617236173361743617536176361773617836179361803618136182361833618436185361863618736188361893619036191361923619336194361953619636197361983619936200362013620236203362043620536206362073620836209362103621136212362133621436215362163621736218362193622036221362223622336224362253622636227362283622936230362313623236233362343623536236362373623836239362403624136242362433624436245362463624736248362493625036251362523625336254362553625636257362583625936260362613626236263362643626536266362673626836269362703627136272362733627436275362763627736278362793628036281362823628336284362853628636287362883628936290362913629236293362943629536296362973629836299363003630136302363033630436305363063630736308363093631036311363123631336314363153631636317363183631936320363213632236323363243632536326363273632836329363303633136332363333633436335363363633736338363393634036341363423634336344363453634636347363483634936350363513635236353363543635536356363573635836359363603636136362363633636436365363663636736368363693637036371363723637336374363753637636377363783637936380363813638236383363843638536386363873638836389363903639136392363933639436395363963639736398363993640036401364023640336404364053640636407364083640936410364113641236413364143641536416364173641836419364203642136422364233642436425364263642736428364293643036431364323643336434364353643636437364383643936440364413644236443364443644536446364473644836449364503645136452364533645436455364563645736458364593646036461364623646336464364653646636467364683646936470364713647236473364743647536476364773647836479364803648136482364833648436485364863648736488364893649036491364923649336494364953649636497364983649936500365013650236503365043650536506365073650836509365103651136512365133651436515365163651736518365193652036521365223652336524365253652636527365283652936530365313653236533365343653536536365373653836539365403654136542365433654436545365463654736548365493655036551365523655336554365553655636557365583655936560365613656236563365643656536566365673656836569365703657136572365733657436575365763657736578365793658036581365823658336584365853658636587365883658936590365913659236593365943659536596365973659836599366003660136602366033660436605366063660736608366093661036611366123661336614366153661636617366183661936620366213662236623366243662536626366273662836629366303663136632366333663436635366363663736638366393664036641366423664336644366453664636647366483664936650366513665236653366543665536656366573665836659366603666136662366633666436665366663666736668366693667036671366723667336674366753667636677366783667936680366813668236683366843668536686366873668836689366903669136692366933669436695366963669736698366993670036701367023670336704367053670636707367083670936710367113671236713367143671536716367173671836719367203672136722367233672436725367263672736728367293673036731367323673336734367353673636737367383673936740367413674236743367443674536746367473674836749367503675136752367533675436755367563675736758367593676036761367623676336764367653676636767367683676936770367713677236773367743677536776367773677836779367803678136782367833678436785367863678736788367893679036791367923679336794367953679636797367983679936800368013680236803368043680536806368073680836809368103681136812368133681436815368163681736818368193682036821368223682336824368253682636827368283682936830368313683236833368343683536836368373683836839368403684136842368433684436845368463684736848368493685036851368523685336854368553685636857368583685936860368613686236863368643686536866368673686836869368703687136872368733687436875368763687736878368793688036881368823688336884368853688636887368883688936890368913689236893368943689536896368973689836899369003690136902369033690436905369063690736908369093691036911369123691336914369153691636917369183691936920369213692236923369243692536926369273692836929369303693136932369333693436935369363693736938369393694036941369423694336944369453694636947369483694936950369513695236953369543695536956369573695836959369603696136962369633696436965369663696736968369693697036971369723697336974369753697636977369783697936980369813698236983369843698536986369873698836989
  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.renderTarget = null; // assign texture to a render target
  1304. this.isRenderTargetTexture = false; // indicates whether a texture belongs to a render target or not
  1305. this.pmremVersion = 0; // indicates whether this texture should be processed by PMREMGenerator or not (only relevant for render target textures)
  1306. }
  1307. get image() {
  1308. return this.source.data;
  1309. }
  1310. set image( value = null ) {
  1311. this.source.data = value;
  1312. }
  1313. updateMatrix() {
  1314. this.matrix.setUvTransform( this.offset.x, this.offset.y, this.repeat.x, this.repeat.y, this.rotation, this.center.x, this.center.y );
  1315. }
  1316. clone() {
  1317. return new this.constructor().copy( this );
  1318. }
  1319. copy( source ) {
  1320. this.name = source.name;
  1321. this.source = source.source;
  1322. this.mipmaps = source.mipmaps.slice( 0 );
  1323. this.mapping = source.mapping;
  1324. this.channel = source.channel;
  1325. this.wrapS = source.wrapS;
  1326. this.wrapT = source.wrapT;
  1327. this.magFilter = source.magFilter;
  1328. this.minFilter = source.minFilter;
  1329. this.anisotropy = source.anisotropy;
  1330. this.format = source.format;
  1331. this.internalFormat = source.internalFormat;
  1332. this.type = source.type;
  1333. this.offset.copy( source.offset );
  1334. this.repeat.copy( source.repeat );
  1335. this.center.copy( source.center );
  1336. this.rotation = source.rotation;
  1337. this.matrixAutoUpdate = source.matrixAutoUpdate;
  1338. this.matrix.copy( source.matrix );
  1339. this.generateMipmaps = source.generateMipmaps;
  1340. this.premultiplyAlpha = source.premultiplyAlpha;
  1341. this.flipY = source.flipY;
  1342. this.unpackAlignment = source.unpackAlignment;
  1343. this.colorSpace = source.colorSpace;
  1344. this.renderTarget = source.renderTarget;
  1345. this.isRenderTargetTexture = source.isRenderTargetTexture;
  1346. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  1347. this.needsUpdate = true;
  1348. return this;
  1349. }
  1350. toJSON( meta ) {
  1351. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  1352. if ( ! isRootObject && meta.textures[ this.uuid ] !== undefined ) {
  1353. return meta.textures[ this.uuid ];
  1354. }
  1355. const output = {
  1356. metadata: {
  1357. version: 4.6,
  1358. type: 'Texture',
  1359. generator: 'Texture.toJSON'
  1360. },
  1361. uuid: this.uuid,
  1362. name: this.name,
  1363. image: this.source.toJSON( meta ).uuid,
  1364. mapping: this.mapping,
  1365. channel: this.channel,
  1366. repeat: [ this.repeat.x, this.repeat.y ],
  1367. offset: [ this.offset.x, this.offset.y ],
  1368. center: [ this.center.x, this.center.y ],
  1369. rotation: this.rotation,
  1370. wrap: [ this.wrapS, this.wrapT ],
  1371. format: this.format,
  1372. internalFormat: this.internalFormat,
  1373. type: this.type,
  1374. colorSpace: this.colorSpace,
  1375. minFilter: this.minFilter,
  1376. magFilter: this.magFilter,
  1377. anisotropy: this.anisotropy,
  1378. flipY: this.flipY,
  1379. generateMipmaps: this.generateMipmaps,
  1380. premultiplyAlpha: this.premultiplyAlpha,
  1381. unpackAlignment: this.unpackAlignment
  1382. };
  1383. if ( Object.keys( this.userData ).length > 0 ) output.userData = this.userData;
  1384. if ( ! isRootObject ) {
  1385. meta.textures[ this.uuid ] = output;
  1386. }
  1387. return output;
  1388. }
  1389. dispose() {
  1390. this.dispatchEvent( { type: 'dispose' } );
  1391. }
  1392. transformUv( uv ) {
  1393. if ( this.mapping !== UVMapping ) return uv;
  1394. uv.applyMatrix3( this.matrix );
  1395. if ( uv.x < 0 || uv.x > 1 ) {
  1396. switch ( this.wrapS ) {
  1397. case RepeatWrapping:
  1398. uv.x = uv.x - Math.floor( uv.x );
  1399. break;
  1400. case ClampToEdgeWrapping:
  1401. uv.x = uv.x < 0 ? 0 : 1;
  1402. break;
  1403. case MirroredRepeatWrapping:
  1404. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  1405. uv.x = Math.ceil( uv.x ) - uv.x;
  1406. } else {
  1407. uv.x = uv.x - Math.floor( uv.x );
  1408. }
  1409. break;
  1410. }
  1411. }
  1412. if ( uv.y < 0 || uv.y > 1 ) {
  1413. switch ( this.wrapT ) {
  1414. case RepeatWrapping:
  1415. uv.y = uv.y - Math.floor( uv.y );
  1416. break;
  1417. case ClampToEdgeWrapping:
  1418. uv.y = uv.y < 0 ? 0 : 1;
  1419. break;
  1420. case MirroredRepeatWrapping:
  1421. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  1422. uv.y = Math.ceil( uv.y ) - uv.y;
  1423. } else {
  1424. uv.y = uv.y - Math.floor( uv.y );
  1425. }
  1426. break;
  1427. }
  1428. }
  1429. if ( this.flipY ) {
  1430. uv.y = 1 - uv.y;
  1431. }
  1432. return uv;
  1433. }
  1434. set needsUpdate( value ) {
  1435. if ( value === true ) {
  1436. this.version ++;
  1437. this.source.needsUpdate = true;
  1438. }
  1439. }
  1440. set needsPMREMUpdate( value ) {
  1441. if ( value === true ) {
  1442. this.pmremVersion ++;
  1443. }
  1444. }
  1445. }
  1446. Texture.DEFAULT_IMAGE = null;
  1447. Texture.DEFAULT_MAPPING = UVMapping;
  1448. Texture.DEFAULT_ANISOTROPY = 1;
  1449. class Vector4 {
  1450. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  1451. Vector4.prototype.isVector4 = true;
  1452. this.x = x;
  1453. this.y = y;
  1454. this.z = z;
  1455. this.w = w;
  1456. }
  1457. get width() {
  1458. return this.z;
  1459. }
  1460. set width( value ) {
  1461. this.z = value;
  1462. }
  1463. get height() {
  1464. return this.w;
  1465. }
  1466. set height( value ) {
  1467. this.w = value;
  1468. }
  1469. set( x, y, z, w ) {
  1470. this.x = x;
  1471. this.y = y;
  1472. this.z = z;
  1473. this.w = w;
  1474. return this;
  1475. }
  1476. setScalar( scalar ) {
  1477. this.x = scalar;
  1478. this.y = scalar;
  1479. this.z = scalar;
  1480. this.w = scalar;
  1481. return this;
  1482. }
  1483. setX( x ) {
  1484. this.x = x;
  1485. return this;
  1486. }
  1487. setY( y ) {
  1488. this.y = y;
  1489. return this;
  1490. }
  1491. setZ( z ) {
  1492. this.z = z;
  1493. return this;
  1494. }
  1495. setW( w ) {
  1496. this.w = w;
  1497. return this;
  1498. }
  1499. setComponent( index, value ) {
  1500. switch ( index ) {
  1501. case 0: this.x = value; break;
  1502. case 1: this.y = value; break;
  1503. case 2: this.z = value; break;
  1504. case 3: this.w = value; break;
  1505. default: throw new Error( 'index is out of range: ' + index );
  1506. }
  1507. return this;
  1508. }
  1509. getComponent( index ) {
  1510. switch ( index ) {
  1511. case 0: return this.x;
  1512. case 1: return this.y;
  1513. case 2: return this.z;
  1514. case 3: return this.w;
  1515. default: throw new Error( 'index is out of range: ' + index );
  1516. }
  1517. }
  1518. clone() {
  1519. return new this.constructor( this.x, this.y, this.z, this.w );
  1520. }
  1521. copy( v ) {
  1522. this.x = v.x;
  1523. this.y = v.y;
  1524. this.z = v.z;
  1525. this.w = ( v.w !== undefined ) ? v.w : 1;
  1526. return this;
  1527. }
  1528. add( v ) {
  1529. this.x += v.x;
  1530. this.y += v.y;
  1531. this.z += v.z;
  1532. this.w += v.w;
  1533. return this;
  1534. }
  1535. addScalar( s ) {
  1536. this.x += s;
  1537. this.y += s;
  1538. this.z += s;
  1539. this.w += s;
  1540. return this;
  1541. }
  1542. addVectors( a, b ) {
  1543. this.x = a.x + b.x;
  1544. this.y = a.y + b.y;
  1545. this.z = a.z + b.z;
  1546. this.w = a.w + b.w;
  1547. return this;
  1548. }
  1549. addScaledVector( v, s ) {
  1550. this.x += v.x * s;
  1551. this.y += v.y * s;
  1552. this.z += v.z * s;
  1553. this.w += v.w * s;
  1554. return this;
  1555. }
  1556. sub( v ) {
  1557. this.x -= v.x;
  1558. this.y -= v.y;
  1559. this.z -= v.z;
  1560. this.w -= v.w;
  1561. return this;
  1562. }
  1563. subScalar( s ) {
  1564. this.x -= s;
  1565. this.y -= s;
  1566. this.z -= s;
  1567. this.w -= s;
  1568. return this;
  1569. }
  1570. subVectors( a, b ) {
  1571. this.x = a.x - b.x;
  1572. this.y = a.y - b.y;
  1573. this.z = a.z - b.z;
  1574. this.w = a.w - b.w;
  1575. return this;
  1576. }
  1577. multiply( v ) {
  1578. this.x *= v.x;
  1579. this.y *= v.y;
  1580. this.z *= v.z;
  1581. this.w *= v.w;
  1582. return this;
  1583. }
  1584. multiplyScalar( scalar ) {
  1585. this.x *= scalar;
  1586. this.y *= scalar;
  1587. this.z *= scalar;
  1588. this.w *= scalar;
  1589. return this;
  1590. }
  1591. applyMatrix4( m ) {
  1592. const x = this.x, y = this.y, z = this.z, w = this.w;
  1593. const e = m.elements;
  1594. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1595. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1596. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1597. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1598. return this;
  1599. }
  1600. divide( v ) {
  1601. this.x /= v.x;
  1602. this.y /= v.y;
  1603. this.z /= v.z;
  1604. this.w /= v.w;
  1605. return this;
  1606. }
  1607. divideScalar( scalar ) {
  1608. return this.multiplyScalar( 1 / scalar );
  1609. }
  1610. setAxisAngleFromQuaternion( q ) {
  1611. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1612. // q is assumed to be normalized
  1613. this.w = 2 * Math.acos( q.w );
  1614. const s = Math.sqrt( 1 - q.w * q.w );
  1615. if ( s < 0.0001 ) {
  1616. this.x = 1;
  1617. this.y = 0;
  1618. this.z = 0;
  1619. } else {
  1620. this.x = q.x / s;
  1621. this.y = q.y / s;
  1622. this.z = q.z / s;
  1623. }
  1624. return this;
  1625. }
  1626. setAxisAngleFromRotationMatrix( m ) {
  1627. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1628. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1629. let angle, x, y, z; // variables for result
  1630. const epsilon = 0.01, // margin to allow for rounding errors
  1631. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1632. te = m.elements,
  1633. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1634. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1635. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1636. if ( ( Math.abs( m12 - m21 ) < epsilon ) &&
  1637. ( Math.abs( m13 - m31 ) < epsilon ) &&
  1638. ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1639. // singularity found
  1640. // first check for identity matrix which must have +1 for all terms
  1641. // in leading diagonal and zero in other terms
  1642. if ( ( Math.abs( m12 + m21 ) < epsilon2 ) &&
  1643. ( Math.abs( m13 + m31 ) < epsilon2 ) &&
  1644. ( Math.abs( m23 + m32 ) < epsilon2 ) &&
  1645. ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1646. // this singularity is identity matrix so angle = 0
  1647. this.set( 1, 0, 0, 0 );
  1648. return this; // zero angle, arbitrary axis
  1649. }
  1650. // otherwise this singularity is angle = 180
  1651. angle = Math.PI;
  1652. const xx = ( m11 + 1 ) / 2;
  1653. const yy = ( m22 + 1 ) / 2;
  1654. const zz = ( m33 + 1 ) / 2;
  1655. const xy = ( m12 + m21 ) / 4;
  1656. const xz = ( m13 + m31 ) / 4;
  1657. const yz = ( m23 + m32 ) / 4;
  1658. if ( ( xx > yy ) && ( xx > zz ) ) {
  1659. // m11 is the largest diagonal term
  1660. if ( xx < epsilon ) {
  1661. x = 0;
  1662. y = 0.707106781;
  1663. z = 0.707106781;
  1664. } else {
  1665. x = Math.sqrt( xx );
  1666. y = xy / x;
  1667. z = xz / x;
  1668. }
  1669. } else if ( yy > zz ) {
  1670. // m22 is the largest diagonal term
  1671. if ( yy < epsilon ) {
  1672. x = 0.707106781;
  1673. y = 0;
  1674. z = 0.707106781;
  1675. } else {
  1676. y = Math.sqrt( yy );
  1677. x = xy / y;
  1678. z = yz / y;
  1679. }
  1680. } else {
  1681. // m33 is the largest diagonal term so base result on this
  1682. if ( zz < epsilon ) {
  1683. x = 0.707106781;
  1684. y = 0.707106781;
  1685. z = 0;
  1686. } else {
  1687. z = Math.sqrt( zz );
  1688. x = xz / z;
  1689. y = yz / z;
  1690. }
  1691. }
  1692. this.set( x, y, z, angle );
  1693. return this; // return 180 deg rotation
  1694. }
  1695. // as we have reached here there are no singularities so we can handle normally
  1696. let s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 ) +
  1697. ( m13 - m31 ) * ( m13 - m31 ) +
  1698. ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1699. if ( Math.abs( s ) < 0.001 ) s = 1;
  1700. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1701. // caught by singularity test above, but I've left it in just in case
  1702. this.x = ( m32 - m23 ) / s;
  1703. this.y = ( m13 - m31 ) / s;
  1704. this.z = ( m21 - m12 ) / s;
  1705. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1706. return this;
  1707. }
  1708. setFromMatrixPosition( m ) {
  1709. const e = m.elements;
  1710. this.x = e[ 12 ];
  1711. this.y = e[ 13 ];
  1712. this.z = e[ 14 ];
  1713. this.w = e[ 15 ];
  1714. return this;
  1715. }
  1716. min( v ) {
  1717. this.x = Math.min( this.x, v.x );
  1718. this.y = Math.min( this.y, v.y );
  1719. this.z = Math.min( this.z, v.z );
  1720. this.w = Math.min( this.w, v.w );
  1721. return this;
  1722. }
  1723. max( v ) {
  1724. this.x = Math.max( this.x, v.x );
  1725. this.y = Math.max( this.y, v.y );
  1726. this.z = Math.max( this.z, v.z );
  1727. this.w = Math.max( this.w, v.w );
  1728. return this;
  1729. }
  1730. clamp( min, max ) {
  1731. // assumes min < max, componentwise
  1732. this.x = clamp( this.x, min.x, max.x );
  1733. this.y = clamp( this.y, min.y, max.y );
  1734. this.z = clamp( this.z, min.z, max.z );
  1735. this.w = clamp( this.w, min.w, max.w );
  1736. return this;
  1737. }
  1738. clampScalar( minVal, maxVal ) {
  1739. this.x = clamp( this.x, minVal, maxVal );
  1740. this.y = clamp( this.y, minVal, maxVal );
  1741. this.z = clamp( this.z, minVal, maxVal );
  1742. this.w = clamp( this.w, minVal, maxVal );
  1743. return this;
  1744. }
  1745. clampLength( min, max ) {
  1746. const length = this.length();
  1747. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  1748. }
  1749. floor() {
  1750. this.x = Math.floor( this.x );
  1751. this.y = Math.floor( this.y );
  1752. this.z = Math.floor( this.z );
  1753. this.w = Math.floor( this.w );
  1754. return this;
  1755. }
  1756. ceil() {
  1757. this.x = Math.ceil( this.x );
  1758. this.y = Math.ceil( this.y );
  1759. this.z = Math.ceil( this.z );
  1760. this.w = Math.ceil( this.w );
  1761. return this;
  1762. }
  1763. round() {
  1764. this.x = Math.round( this.x );
  1765. this.y = Math.round( this.y );
  1766. this.z = Math.round( this.z );
  1767. this.w = Math.round( this.w );
  1768. return this;
  1769. }
  1770. roundToZero() {
  1771. this.x = Math.trunc( this.x );
  1772. this.y = Math.trunc( this.y );
  1773. this.z = Math.trunc( this.z );
  1774. this.w = Math.trunc( this.w );
  1775. return this;
  1776. }
  1777. negate() {
  1778. this.x = - this.x;
  1779. this.y = - this.y;
  1780. this.z = - this.z;
  1781. this.w = - this.w;
  1782. return this;
  1783. }
  1784. dot( v ) {
  1785. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1786. }
  1787. lengthSq() {
  1788. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1789. }
  1790. length() {
  1791. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1792. }
  1793. manhattanLength() {
  1794. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1795. }
  1796. normalize() {
  1797. return this.divideScalar( this.length() || 1 );
  1798. }
  1799. setLength( length ) {
  1800. return this.normalize().multiplyScalar( length );
  1801. }
  1802. lerp( v, alpha ) {
  1803. this.x += ( v.x - this.x ) * alpha;
  1804. this.y += ( v.y - this.y ) * alpha;
  1805. this.z += ( v.z - this.z ) * alpha;
  1806. this.w += ( v.w - this.w ) * alpha;
  1807. return this;
  1808. }
  1809. lerpVectors( v1, v2, alpha ) {
  1810. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  1811. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  1812. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  1813. this.w = v1.w + ( v2.w - v1.w ) * alpha;
  1814. return this;
  1815. }
  1816. equals( v ) {
  1817. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1818. }
  1819. fromArray( array, offset = 0 ) {
  1820. this.x = array[ offset ];
  1821. this.y = array[ offset + 1 ];
  1822. this.z = array[ offset + 2 ];
  1823. this.w = array[ offset + 3 ];
  1824. return this;
  1825. }
  1826. toArray( array = [], offset = 0 ) {
  1827. array[ offset ] = this.x;
  1828. array[ offset + 1 ] = this.y;
  1829. array[ offset + 2 ] = this.z;
  1830. array[ offset + 3 ] = this.w;
  1831. return array;
  1832. }
  1833. fromBufferAttribute( attribute, index ) {
  1834. this.x = attribute.getX( index );
  1835. this.y = attribute.getY( index );
  1836. this.z = attribute.getZ( index );
  1837. this.w = attribute.getW( index );
  1838. return this;
  1839. }
  1840. random() {
  1841. this.x = Math.random();
  1842. this.y = Math.random();
  1843. this.z = Math.random();
  1844. this.w = Math.random();
  1845. return this;
  1846. }
  1847. *[ Symbol.iterator ]() {
  1848. yield this.x;
  1849. yield this.y;
  1850. yield this.z;
  1851. yield this.w;
  1852. }
  1853. }
  1854. /*
  1855. In options, we can specify:
  1856. * Texture parameters for an auto-generated target texture
  1857. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  1858. */
  1859. class RenderTarget extends EventDispatcher {
  1860. constructor( width = 1, height = 1, options = {} ) {
  1861. super();
  1862. this.isRenderTarget = true;
  1863. this.width = width;
  1864. this.height = height;
  1865. this.depth = 1;
  1866. this.scissor = new Vector4( 0, 0, width, height );
  1867. this.scissorTest = false;
  1868. this.viewport = new Vector4( 0, 0, width, height );
  1869. const image = { width: width, height: height, depth: 1 };
  1870. options = Object.assign( {
  1871. generateMipmaps: false,
  1872. internalFormat: null,
  1873. minFilter: LinearFilter,
  1874. depthBuffer: true,
  1875. stencilBuffer: false,
  1876. resolveDepthBuffer: true,
  1877. resolveStencilBuffer: true,
  1878. depthTexture: null,
  1879. samples: 0,
  1880. count: 1
  1881. }, options );
  1882. const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  1883. texture.flipY = false;
  1884. texture.generateMipmaps = options.generateMipmaps;
  1885. texture.internalFormat = options.internalFormat;
  1886. this.textures = [];
  1887. const count = options.count;
  1888. for ( let i = 0; i < count; i ++ ) {
  1889. this.textures[ i ] = texture.clone();
  1890. this.textures[ i ].isRenderTargetTexture = true;
  1891. this.textures[ i ].renderTarget = this;
  1892. }
  1893. this.depthBuffer = options.depthBuffer;
  1894. this.stencilBuffer = options.stencilBuffer;
  1895. this.resolveDepthBuffer = options.resolveDepthBuffer;
  1896. this.resolveStencilBuffer = options.resolveStencilBuffer;
  1897. this._depthTexture = null;
  1898. this.depthTexture = options.depthTexture;
  1899. this.samples = options.samples;
  1900. }
  1901. get texture() {
  1902. return this.textures[ 0 ];
  1903. }
  1904. set texture( value ) {
  1905. this.textures[ 0 ] = value;
  1906. }
  1907. set depthTexture( current ) {
  1908. if ( this._depthTexture !== null ) this._depthTexture.renderTarget = null;
  1909. if ( current !== null ) current.renderTarget = this;
  1910. this._depthTexture = current;
  1911. }
  1912. get depthTexture() {
  1913. return this._depthTexture;
  1914. }
  1915. setSize( width, height, depth = 1 ) {
  1916. if ( this.width !== width || this.height !== height || this.depth !== depth ) {
  1917. this.width = width;
  1918. this.height = height;
  1919. this.depth = depth;
  1920. for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
  1921. this.textures[ i ].image.width = width;
  1922. this.textures[ i ].image.height = height;
  1923. this.textures[ i ].image.depth = depth;
  1924. }
  1925. this.dispose();
  1926. }
  1927. this.viewport.set( 0, 0, width, height );
  1928. this.scissor.set( 0, 0, width, height );
  1929. }
  1930. clone() {
  1931. return new this.constructor().copy( this );
  1932. }
  1933. copy( source ) {
  1934. this.width = source.width;
  1935. this.height = source.height;
  1936. this.depth = source.depth;
  1937. this.scissor.copy( source.scissor );
  1938. this.scissorTest = source.scissorTest;
  1939. this.viewport.copy( source.viewport );
  1940. this.textures.length = 0;
  1941. for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
  1942. this.textures[ i ] = source.textures[ i ].clone();
  1943. this.textures[ i ].isRenderTargetTexture = true;
  1944. this.textures[ i ].renderTarget = this;
  1945. }
  1946. // ensure image object is not shared, see #20328
  1947. const image = Object.assign( {}, source.texture.image );
  1948. this.texture.source = new Source( image );
  1949. this.depthBuffer = source.depthBuffer;
  1950. this.stencilBuffer = source.stencilBuffer;
  1951. this.resolveDepthBuffer = source.resolveDepthBuffer;
  1952. this.resolveStencilBuffer = source.resolveStencilBuffer;
  1953. if ( source.depthTexture !== null ) this.depthTexture = source.depthTexture.clone();
  1954. this.samples = source.samples;
  1955. return this;
  1956. }
  1957. dispose() {
  1958. this.dispatchEvent( { type: 'dispose' } );
  1959. }
  1960. }
  1961. class WebGLRenderTarget extends RenderTarget {
  1962. constructor( width = 1, height = 1, options = {} ) {
  1963. super( width, height, options );
  1964. this.isWebGLRenderTarget = true;
  1965. }
  1966. }
  1967. class DataArrayTexture extends Texture {
  1968. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1969. super( null );
  1970. this.isDataArrayTexture = true;
  1971. this.image = { data, width, height, depth };
  1972. this.magFilter = NearestFilter;
  1973. this.minFilter = NearestFilter;
  1974. this.wrapR = ClampToEdgeWrapping;
  1975. this.generateMipmaps = false;
  1976. this.flipY = false;
  1977. this.unpackAlignment = 1;
  1978. this.layerUpdates = new Set();
  1979. }
  1980. addLayerUpdate( layerIndex ) {
  1981. this.layerUpdates.add( layerIndex );
  1982. }
  1983. clearLayerUpdates() {
  1984. this.layerUpdates.clear();
  1985. }
  1986. }
  1987. class WebGLArrayRenderTarget extends WebGLRenderTarget {
  1988. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  1989. super( width, height, options );
  1990. this.isWebGLArrayRenderTarget = true;
  1991. this.depth = depth;
  1992. this.texture = new DataArrayTexture( null, width, height, depth );
  1993. this.texture.isRenderTargetTexture = true;
  1994. }
  1995. }
  1996. class Data3DTexture extends Texture {
  1997. constructor( data = null, width = 1, height = 1, depth = 1 ) {
  1998. // We're going to add .setXXX() methods for setting properties later.
  1999. // Users can still set in DataTexture3D directly.
  2000. //
  2001. // const texture = new THREE.DataTexture3D( data, width, height, depth );
  2002. // texture.anisotropy = 16;
  2003. //
  2004. // See #14839
  2005. super( null );
  2006. this.isData3DTexture = true;
  2007. this.image = { data, width, height, depth };
  2008. this.magFilter = NearestFilter;
  2009. this.minFilter = NearestFilter;
  2010. this.wrapR = ClampToEdgeWrapping;
  2011. this.generateMipmaps = false;
  2012. this.flipY = false;
  2013. this.unpackAlignment = 1;
  2014. }
  2015. }
  2016. class WebGL3DRenderTarget extends WebGLRenderTarget {
  2017. constructor( width = 1, height = 1, depth = 1, options = {} ) {
  2018. super( width, height, options );
  2019. this.isWebGL3DRenderTarget = true;
  2020. this.depth = depth;
  2021. this.texture = new Data3DTexture( null, width, height, depth );
  2022. this.texture.isRenderTargetTexture = true;
  2023. }
  2024. }
  2025. class Quaternion {
  2026. constructor( x = 0, y = 0, z = 0, w = 1 ) {
  2027. this.isQuaternion = true;
  2028. this._x = x;
  2029. this._y = y;
  2030. this._z = z;
  2031. this._w = w;
  2032. }
  2033. static slerpFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  2034. // fuzz-free, array-based Quaternion SLERP operation
  2035. let x0 = src0[ srcOffset0 + 0 ],
  2036. y0 = src0[ srcOffset0 + 1 ],
  2037. z0 = src0[ srcOffset0 + 2 ],
  2038. w0 = src0[ srcOffset0 + 3 ];
  2039. const x1 = src1[ srcOffset1 + 0 ],
  2040. y1 = src1[ srcOffset1 + 1 ],
  2041. z1 = src1[ srcOffset1 + 2 ],
  2042. w1 = src1[ srcOffset1 + 3 ];
  2043. if ( t === 0 ) {
  2044. dst[ dstOffset + 0 ] = x0;
  2045. dst[ dstOffset + 1 ] = y0;
  2046. dst[ dstOffset + 2 ] = z0;
  2047. dst[ dstOffset + 3 ] = w0;
  2048. return;
  2049. }
  2050. if ( t === 1 ) {
  2051. dst[ dstOffset + 0 ] = x1;
  2052. dst[ dstOffset + 1 ] = y1;
  2053. dst[ dstOffset + 2 ] = z1;
  2054. dst[ dstOffset + 3 ] = w1;
  2055. return;
  2056. }
  2057. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  2058. let s = 1 - t;
  2059. const cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  2060. dir = ( cos >= 0 ? 1 : - 1 ),
  2061. sqrSin = 1 - cos * cos;
  2062. // Skip the Slerp for tiny steps to avoid numeric problems:
  2063. if ( sqrSin > Number.EPSILON ) {
  2064. const sin = Math.sqrt( sqrSin ),
  2065. len = Math.atan2( sin, cos * dir );
  2066. s = Math.sin( s * len ) / sin;
  2067. t = Math.sin( t * len ) / sin;
  2068. }
  2069. const tDir = t * dir;
  2070. x0 = x0 * s + x1 * tDir;
  2071. y0 = y0 * s + y1 * tDir;
  2072. z0 = z0 * s + z1 * tDir;
  2073. w0 = w0 * s + w1 * tDir;
  2074. // Normalize in case we just did a lerp:
  2075. if ( s === 1 - t ) {
  2076. const f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  2077. x0 *= f;
  2078. y0 *= f;
  2079. z0 *= f;
  2080. w0 *= f;
  2081. }
  2082. }
  2083. dst[ dstOffset ] = x0;
  2084. dst[ dstOffset + 1 ] = y0;
  2085. dst[ dstOffset + 2 ] = z0;
  2086. dst[ dstOffset + 3 ] = w0;
  2087. }
  2088. static multiplyQuaternionsFlat( dst, dstOffset, src0, srcOffset0, src1, srcOffset1 ) {
  2089. const x0 = src0[ srcOffset0 ];
  2090. const y0 = src0[ srcOffset0 + 1 ];
  2091. const z0 = src0[ srcOffset0 + 2 ];
  2092. const w0 = src0[ srcOffset0 + 3 ];
  2093. const x1 = src1[ srcOffset1 ];
  2094. const y1 = src1[ srcOffset1 + 1 ];
  2095. const z1 = src1[ srcOffset1 + 2 ];
  2096. const w1 = src1[ srcOffset1 + 3 ];
  2097. dst[ dstOffset ] = x0 * w1 + w0 * x1 + y0 * z1 - z0 * y1;
  2098. dst[ dstOffset + 1 ] = y0 * w1 + w0 * y1 + z0 * x1 - x0 * z1;
  2099. dst[ dstOffset + 2 ] = z0 * w1 + w0 * z1 + x0 * y1 - y0 * x1;
  2100. dst[ dstOffset + 3 ] = w0 * w1 - x0 * x1 - y0 * y1 - z0 * z1;
  2101. return dst;
  2102. }
  2103. get x() {
  2104. return this._x;
  2105. }
  2106. set x( value ) {
  2107. this._x = value;
  2108. this._onChangeCallback();
  2109. }
  2110. get y() {
  2111. return this._y;
  2112. }
  2113. set y( value ) {
  2114. this._y = value;
  2115. this._onChangeCallback();
  2116. }
  2117. get z() {
  2118. return this._z;
  2119. }
  2120. set z( value ) {
  2121. this._z = value;
  2122. this._onChangeCallback();
  2123. }
  2124. get w() {
  2125. return this._w;
  2126. }
  2127. set w( value ) {
  2128. this._w = value;
  2129. this._onChangeCallback();
  2130. }
  2131. set( x, y, z, w ) {
  2132. this._x = x;
  2133. this._y = y;
  2134. this._z = z;
  2135. this._w = w;
  2136. this._onChangeCallback();
  2137. return this;
  2138. }
  2139. clone() {
  2140. return new this.constructor( this._x, this._y, this._z, this._w );
  2141. }
  2142. copy( quaternion ) {
  2143. this._x = quaternion.x;
  2144. this._y = quaternion.y;
  2145. this._z = quaternion.z;
  2146. this._w = quaternion.w;
  2147. this._onChangeCallback();
  2148. return this;
  2149. }
  2150. setFromEuler( euler, update = true ) {
  2151. const x = euler._x, y = euler._y, z = euler._z, order = euler._order;
  2152. // http://www.mathworks.com/matlabcentral/fileexchange/
  2153. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  2154. // content/SpinCalc.m
  2155. const cos = Math.cos;
  2156. const sin = Math.sin;
  2157. const c1 = cos( x / 2 );
  2158. const c2 = cos( y / 2 );
  2159. const c3 = cos( z / 2 );
  2160. const s1 = sin( x / 2 );
  2161. const s2 = sin( y / 2 );
  2162. const s3 = sin( z / 2 );
  2163. switch ( order ) {
  2164. case 'XYZ':
  2165. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2166. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2167. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2168. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2169. break;
  2170. case 'YXZ':
  2171. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2172. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2173. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2174. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2175. break;
  2176. case 'ZXY':
  2177. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2178. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2179. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2180. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2181. break;
  2182. case 'ZYX':
  2183. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2184. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2185. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2186. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2187. break;
  2188. case 'YZX':
  2189. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  2190. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  2191. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  2192. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  2193. break;
  2194. case 'XZY':
  2195. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  2196. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  2197. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  2198. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  2199. break;
  2200. default:
  2201. console.warn( 'THREE.Quaternion: .setFromEuler() encountered an unknown order: ' + order );
  2202. }
  2203. if ( update === true ) this._onChangeCallback();
  2204. return this;
  2205. }
  2206. setFromAxisAngle( axis, angle ) {
  2207. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  2208. // assumes axis is normalized
  2209. const halfAngle = angle / 2, s = Math.sin( halfAngle );
  2210. this._x = axis.x * s;
  2211. this._y = axis.y * s;
  2212. this._z = axis.z * s;
  2213. this._w = Math.cos( halfAngle );
  2214. this._onChangeCallback();
  2215. return this;
  2216. }
  2217. setFromRotationMatrix( m ) {
  2218. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  2219. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2220. const te = m.elements,
  2221. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  2222. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  2223. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  2224. trace = m11 + m22 + m33;
  2225. if ( trace > 0 ) {
  2226. const s = 0.5 / Math.sqrt( trace + 1.0 );
  2227. this._w = 0.25 / s;
  2228. this._x = ( m32 - m23 ) * s;
  2229. this._y = ( m13 - m31 ) * s;
  2230. this._z = ( m21 - m12 ) * s;
  2231. } else if ( m11 > m22 && m11 > m33 ) {
  2232. const s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  2233. this._w = ( m32 - m23 ) / s;
  2234. this._x = 0.25 * s;
  2235. this._y = ( m12 + m21 ) / s;
  2236. this._z = ( m13 + m31 ) / s;
  2237. } else if ( m22 > m33 ) {
  2238. const s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  2239. this._w = ( m13 - m31 ) / s;
  2240. this._x = ( m12 + m21 ) / s;
  2241. this._y = 0.25 * s;
  2242. this._z = ( m23 + m32 ) / s;
  2243. } else {
  2244. const s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  2245. this._w = ( m21 - m12 ) / s;
  2246. this._x = ( m13 + m31 ) / s;
  2247. this._y = ( m23 + m32 ) / s;
  2248. this._z = 0.25 * s;
  2249. }
  2250. this._onChangeCallback();
  2251. return this;
  2252. }
  2253. setFromUnitVectors( vFrom, vTo ) {
  2254. // assumes direction vectors vFrom and vTo are normalized
  2255. let r = vFrom.dot( vTo ) + 1;
  2256. if ( r < Number.EPSILON ) {
  2257. // vFrom and vTo point in opposite directions
  2258. r = 0;
  2259. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  2260. this._x = - vFrom.y;
  2261. this._y = vFrom.x;
  2262. this._z = 0;
  2263. this._w = r;
  2264. } else {
  2265. this._x = 0;
  2266. this._y = - vFrom.z;
  2267. this._z = vFrom.y;
  2268. this._w = r;
  2269. }
  2270. } else {
  2271. // crossVectors( vFrom, vTo ); // inlined to avoid cyclic dependency on Vector3
  2272. this._x = vFrom.y * vTo.z - vFrom.z * vTo.y;
  2273. this._y = vFrom.z * vTo.x - vFrom.x * vTo.z;
  2274. this._z = vFrom.x * vTo.y - vFrom.y * vTo.x;
  2275. this._w = r;
  2276. }
  2277. return this.normalize();
  2278. }
  2279. angleTo( q ) {
  2280. return 2 * Math.acos( Math.abs( clamp( this.dot( q ), - 1, 1 ) ) );
  2281. }
  2282. rotateTowards( q, step ) {
  2283. const angle = this.angleTo( q );
  2284. if ( angle === 0 ) return this;
  2285. const t = Math.min( 1, step / angle );
  2286. this.slerp( q, t );
  2287. return this;
  2288. }
  2289. identity() {
  2290. return this.set( 0, 0, 0, 1 );
  2291. }
  2292. invert() {
  2293. // quaternion is assumed to have unit length
  2294. return this.conjugate();
  2295. }
  2296. conjugate() {
  2297. this._x *= - 1;
  2298. this._y *= - 1;
  2299. this._z *= - 1;
  2300. this._onChangeCallback();
  2301. return this;
  2302. }
  2303. dot( v ) {
  2304. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  2305. }
  2306. lengthSq() {
  2307. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  2308. }
  2309. length() {
  2310. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  2311. }
  2312. normalize() {
  2313. let l = this.length();
  2314. if ( l === 0 ) {
  2315. this._x = 0;
  2316. this._y = 0;
  2317. this._z = 0;
  2318. this._w = 1;
  2319. } else {
  2320. l = 1 / l;
  2321. this._x = this._x * l;
  2322. this._y = this._y * l;
  2323. this._z = this._z * l;
  2324. this._w = this._w * l;
  2325. }
  2326. this._onChangeCallback();
  2327. return this;
  2328. }
  2329. multiply( q ) {
  2330. return this.multiplyQuaternions( this, q );
  2331. }
  2332. premultiply( q ) {
  2333. return this.multiplyQuaternions( q, this );
  2334. }
  2335. multiplyQuaternions( a, b ) {
  2336. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  2337. const qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  2338. const qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  2339. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  2340. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  2341. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  2342. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  2343. this._onChangeCallback();
  2344. return this;
  2345. }
  2346. slerp( qb, t ) {
  2347. if ( t === 0 ) return this;
  2348. if ( t === 1 ) return this.copy( qb );
  2349. const x = this._x, y = this._y, z = this._z, w = this._w;
  2350. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  2351. let cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  2352. if ( cosHalfTheta < 0 ) {
  2353. this._w = - qb._w;
  2354. this._x = - qb._x;
  2355. this._y = - qb._y;
  2356. this._z = - qb._z;
  2357. cosHalfTheta = - cosHalfTheta;
  2358. } else {
  2359. this.copy( qb );
  2360. }
  2361. if ( cosHalfTheta >= 1.0 ) {
  2362. this._w = w;
  2363. this._x = x;
  2364. this._y = y;
  2365. this._z = z;
  2366. return this;
  2367. }
  2368. const sqrSinHalfTheta = 1.0 - cosHalfTheta * cosHalfTheta;
  2369. if ( sqrSinHalfTheta <= Number.EPSILON ) {
  2370. const s = 1 - t;
  2371. this._w = s * w + t * this._w;
  2372. this._x = s * x + t * this._x;
  2373. this._y = s * y + t * this._y;
  2374. this._z = s * z + t * this._z;
  2375. this.normalize(); // normalize calls _onChangeCallback()
  2376. return this;
  2377. }
  2378. const sinHalfTheta = Math.sqrt( sqrSinHalfTheta );
  2379. const halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  2380. const ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  2381. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  2382. this._w = ( w * ratioA + this._w * ratioB );
  2383. this._x = ( x * ratioA + this._x * ratioB );
  2384. this._y = ( y * ratioA + this._y * ratioB );
  2385. this._z = ( z * ratioA + this._z * ratioB );
  2386. this._onChangeCallback();
  2387. return this;
  2388. }
  2389. slerpQuaternions( qa, qb, t ) {
  2390. return this.copy( qa ).slerp( qb, t );
  2391. }
  2392. random() {
  2393. // sets this quaternion to a uniform random unit quaternnion
  2394. // Ken Shoemake
  2395. // Uniform random rotations
  2396. // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
  2397. const theta1 = 2 * Math.PI * Math.random();
  2398. const theta2 = 2 * Math.PI * Math.random();
  2399. const x0 = Math.random();
  2400. const r1 = Math.sqrt( 1 - x0 );
  2401. const r2 = Math.sqrt( x0 );
  2402. return this.set(
  2403. r1 * Math.sin( theta1 ),
  2404. r1 * Math.cos( theta1 ),
  2405. r2 * Math.sin( theta2 ),
  2406. r2 * Math.cos( theta2 ),
  2407. );
  2408. }
  2409. equals( quaternion ) {
  2410. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  2411. }
  2412. fromArray( array, offset = 0 ) {
  2413. this._x = array[ offset ];
  2414. this._y = array[ offset + 1 ];
  2415. this._z = array[ offset + 2 ];
  2416. this._w = array[ offset + 3 ];
  2417. this._onChangeCallback();
  2418. return this;
  2419. }
  2420. toArray( array = [], offset = 0 ) {
  2421. array[ offset ] = this._x;
  2422. array[ offset + 1 ] = this._y;
  2423. array[ offset + 2 ] = this._z;
  2424. array[ offset + 3 ] = this._w;
  2425. return array;
  2426. }
  2427. fromBufferAttribute( attribute, index ) {
  2428. this._x = attribute.getX( index );
  2429. this._y = attribute.getY( index );
  2430. this._z = attribute.getZ( index );
  2431. this._w = attribute.getW( index );
  2432. this._onChangeCallback();
  2433. return this;
  2434. }
  2435. toJSON() {
  2436. return this.toArray();
  2437. }
  2438. _onChange( callback ) {
  2439. this._onChangeCallback = callback;
  2440. return this;
  2441. }
  2442. _onChangeCallback() {}
  2443. *[ Symbol.iterator ]() {
  2444. yield this._x;
  2445. yield this._y;
  2446. yield this._z;
  2447. yield this._w;
  2448. }
  2449. }
  2450. class Vector3 {
  2451. constructor( x = 0, y = 0, z = 0 ) {
  2452. Vector3.prototype.isVector3 = true;
  2453. this.x = x;
  2454. this.y = y;
  2455. this.z = z;
  2456. }
  2457. set( x, y, z ) {
  2458. if ( z === undefined ) z = this.z; // sprite.scale.set(x,y)
  2459. this.x = x;
  2460. this.y = y;
  2461. this.z = z;
  2462. return this;
  2463. }
  2464. setScalar( scalar ) {
  2465. this.x = scalar;
  2466. this.y = scalar;
  2467. this.z = scalar;
  2468. return this;
  2469. }
  2470. setX( x ) {
  2471. this.x = x;
  2472. return this;
  2473. }
  2474. setY( y ) {
  2475. this.y = y;
  2476. return this;
  2477. }
  2478. setZ( z ) {
  2479. this.z = z;
  2480. return this;
  2481. }
  2482. setComponent( index, value ) {
  2483. switch ( index ) {
  2484. case 0: this.x = value; break;
  2485. case 1: this.y = value; break;
  2486. case 2: this.z = value; break;
  2487. default: throw new Error( 'index is out of range: ' + index );
  2488. }
  2489. return this;
  2490. }
  2491. getComponent( index ) {
  2492. switch ( index ) {
  2493. case 0: return this.x;
  2494. case 1: return this.y;
  2495. case 2: return this.z;
  2496. default: throw new Error( 'index is out of range: ' + index );
  2497. }
  2498. }
  2499. clone() {
  2500. return new this.constructor( this.x, this.y, this.z );
  2501. }
  2502. copy( v ) {
  2503. this.x = v.x;
  2504. this.y = v.y;
  2505. this.z = v.z;
  2506. return this;
  2507. }
  2508. add( v ) {
  2509. this.x += v.x;
  2510. this.y += v.y;
  2511. this.z += v.z;
  2512. return this;
  2513. }
  2514. addScalar( s ) {
  2515. this.x += s;
  2516. this.y += s;
  2517. this.z += s;
  2518. return this;
  2519. }
  2520. addVectors( a, b ) {
  2521. this.x = a.x + b.x;
  2522. this.y = a.y + b.y;
  2523. this.z = a.z + b.z;
  2524. return this;
  2525. }
  2526. addScaledVector( v, s ) {
  2527. this.x += v.x * s;
  2528. this.y += v.y * s;
  2529. this.z += v.z * s;
  2530. return this;
  2531. }
  2532. sub( v ) {
  2533. this.x -= v.x;
  2534. this.y -= v.y;
  2535. this.z -= v.z;
  2536. return this;
  2537. }
  2538. subScalar( s ) {
  2539. this.x -= s;
  2540. this.y -= s;
  2541. this.z -= s;
  2542. return this;
  2543. }
  2544. subVectors( a, b ) {
  2545. this.x = a.x - b.x;
  2546. this.y = a.y - b.y;
  2547. this.z = a.z - b.z;
  2548. return this;
  2549. }
  2550. multiply( v ) {
  2551. this.x *= v.x;
  2552. this.y *= v.y;
  2553. this.z *= v.z;
  2554. return this;
  2555. }
  2556. multiplyScalar( scalar ) {
  2557. this.x *= scalar;
  2558. this.y *= scalar;
  2559. this.z *= scalar;
  2560. return this;
  2561. }
  2562. multiplyVectors( a, b ) {
  2563. this.x = a.x * b.x;
  2564. this.y = a.y * b.y;
  2565. this.z = a.z * b.z;
  2566. return this;
  2567. }
  2568. applyEuler( euler ) {
  2569. return this.applyQuaternion( _quaternion$4.setFromEuler( euler ) );
  2570. }
  2571. applyAxisAngle( axis, angle ) {
  2572. return this.applyQuaternion( _quaternion$4.setFromAxisAngle( axis, angle ) );
  2573. }
  2574. applyMatrix3( m ) {
  2575. const x = this.x, y = this.y, z = this.z;
  2576. const e = m.elements;
  2577. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  2578. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  2579. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  2580. return this;
  2581. }
  2582. applyNormalMatrix( m ) {
  2583. return this.applyMatrix3( m ).normalize();
  2584. }
  2585. applyMatrix4( m ) {
  2586. const x = this.x, y = this.y, z = this.z;
  2587. const e = m.elements;
  2588. const w = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] );
  2589. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * w;
  2590. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * w;
  2591. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * w;
  2592. return this;
  2593. }
  2594. applyQuaternion( q ) {
  2595. // quaternion q is assumed to have unit length
  2596. const vx = this.x, vy = this.y, vz = this.z;
  2597. const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
  2598. // t = 2 * cross( q.xyz, v );
  2599. const tx = 2 * ( qy * vz - qz * vy );
  2600. const ty = 2 * ( qz * vx - qx * vz );
  2601. const tz = 2 * ( qx * vy - qy * vx );
  2602. // v + q.w * t + cross( q.xyz, t );
  2603. this.x = vx + qw * tx + qy * tz - qz * ty;
  2604. this.y = vy + qw * ty + qz * tx - qx * tz;
  2605. this.z = vz + qw * tz + qx * ty - qy * tx;
  2606. return this;
  2607. }
  2608. project( camera ) {
  2609. return this.applyMatrix4( camera.matrixWorldInverse ).applyMatrix4( camera.projectionMatrix );
  2610. }
  2611. unproject( camera ) {
  2612. return this.applyMatrix4( camera.projectionMatrixInverse ).applyMatrix4( camera.matrixWorld );
  2613. }
  2614. transformDirection( m ) {
  2615. // input: THREE.Matrix4 affine matrix
  2616. // vector interpreted as a direction
  2617. const x = this.x, y = this.y, z = this.z;
  2618. const e = m.elements;
  2619. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  2620. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  2621. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  2622. return this.normalize();
  2623. }
  2624. divide( v ) {
  2625. this.x /= v.x;
  2626. this.y /= v.y;
  2627. this.z /= v.z;
  2628. return this;
  2629. }
  2630. divideScalar( scalar ) {
  2631. return this.multiplyScalar( 1 / scalar );
  2632. }
  2633. min( v ) {
  2634. this.x = Math.min( this.x, v.x );
  2635. this.y = Math.min( this.y, v.y );
  2636. this.z = Math.min( this.z, v.z );
  2637. return this;
  2638. }
  2639. max( v ) {
  2640. this.x = Math.max( this.x, v.x );
  2641. this.y = Math.max( this.y, v.y );
  2642. this.z = Math.max( this.z, v.z );
  2643. return this;
  2644. }
  2645. clamp( min, max ) {
  2646. // assumes min < max, componentwise
  2647. this.x = clamp( this.x, min.x, max.x );
  2648. this.y = clamp( this.y, min.y, max.y );
  2649. this.z = clamp( this.z, min.z, max.z );
  2650. return this;
  2651. }
  2652. clampScalar( minVal, maxVal ) {
  2653. this.x = clamp( this.x, minVal, maxVal );
  2654. this.y = clamp( this.y, minVal, maxVal );
  2655. this.z = clamp( this.z, minVal, maxVal );
  2656. return this;
  2657. }
  2658. clampLength( min, max ) {
  2659. const length = this.length();
  2660. return this.divideScalar( length || 1 ).multiplyScalar( clamp( length, min, max ) );
  2661. }
  2662. floor() {
  2663. this.x = Math.floor( this.x );
  2664. this.y = Math.floor( this.y );
  2665. this.z = Math.floor( this.z );
  2666. return this;
  2667. }
  2668. ceil() {
  2669. this.x = Math.ceil( this.x );
  2670. this.y = Math.ceil( this.y );
  2671. this.z = Math.ceil( this.z );
  2672. return this;
  2673. }
  2674. round() {
  2675. this.x = Math.round( this.x );
  2676. this.y = Math.round( this.y );
  2677. this.z = Math.round( this.z );
  2678. return this;
  2679. }
  2680. roundToZero() {
  2681. this.x = Math.trunc( this.x );
  2682. this.y = Math.trunc( this.y );
  2683. this.z = Math.trunc( this.z );
  2684. return this;
  2685. }
  2686. negate() {
  2687. this.x = - this.x;
  2688. this.y = - this.y;
  2689. this.z = - this.z;
  2690. return this;
  2691. }
  2692. dot( v ) {
  2693. return this.x * v.x + this.y * v.y + this.z * v.z;
  2694. }
  2695. // TODO lengthSquared?
  2696. lengthSq() {
  2697. return this.x * this.x + this.y * this.y + this.z * this.z;
  2698. }
  2699. length() {
  2700. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  2701. }
  2702. manhattanLength() {
  2703. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  2704. }
  2705. normalize() {
  2706. return this.divideScalar( this.length() || 1 );
  2707. }
  2708. setLength( length ) {
  2709. return this.normalize().multiplyScalar( length );
  2710. }
  2711. lerp( v, alpha ) {
  2712. this.x += ( v.x - this.x ) * alpha;
  2713. this.y += ( v.y - this.y ) * alpha;
  2714. this.z += ( v.z - this.z ) * alpha;
  2715. return this;
  2716. }
  2717. lerpVectors( v1, v2, alpha ) {
  2718. this.x = v1.x + ( v2.x - v1.x ) * alpha;
  2719. this.y = v1.y + ( v2.y - v1.y ) * alpha;
  2720. this.z = v1.z + ( v2.z - v1.z ) * alpha;
  2721. return this;
  2722. }
  2723. cross( v ) {
  2724. return this.crossVectors( this, v );
  2725. }
  2726. crossVectors( a, b ) {
  2727. const ax = a.x, ay = a.y, az = a.z;
  2728. const bx = b.x, by = b.y, bz = b.z;
  2729. this.x = ay * bz - az * by;
  2730. this.y = az * bx - ax * bz;
  2731. this.z = ax * by - ay * bx;
  2732. return this;
  2733. }
  2734. projectOnVector( v ) {
  2735. const denominator = v.lengthSq();
  2736. if ( denominator === 0 ) return this.set( 0, 0, 0 );
  2737. const scalar = v.dot( this ) / denominator;
  2738. return this.copy( v ).multiplyScalar( scalar );
  2739. }
  2740. projectOnPlane( planeNormal ) {
  2741. _vector$c.copy( this ).projectOnVector( planeNormal );
  2742. return this.sub( _vector$c );
  2743. }
  2744. reflect( normal ) {
  2745. // reflect incident vector off plane orthogonal to normal
  2746. // normal is assumed to have unit length
  2747. return this.sub( _vector$c.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  2748. }
  2749. angleTo( v ) {
  2750. const denominator = Math.sqrt( this.lengthSq() * v.lengthSq() );
  2751. if ( denominator === 0 ) return Math.PI / 2;
  2752. const theta = this.dot( v ) / denominator;
  2753. // clamp, to handle numerical problems
  2754. return Math.acos( clamp( theta, - 1, 1 ) );
  2755. }
  2756. distanceTo( v ) {
  2757. return Math.sqrt( this.distanceToSquared( v ) );
  2758. }
  2759. distanceToSquared( v ) {
  2760. const dx = this.x - v.x, dy = this.y - v.y, dz = this.z - v.z;
  2761. return dx * dx + dy * dy + dz * dz;
  2762. }
  2763. manhattanDistanceTo( v ) {
  2764. return Math.abs( this.x - v.x ) + Math.abs( this.y - v.y ) + Math.abs( this.z - v.z );
  2765. }
  2766. setFromSpherical( s ) {
  2767. return this.setFromSphericalCoords( s.radius, s.phi, s.theta );
  2768. }
  2769. setFromSphericalCoords( radius, phi, theta ) {
  2770. const sinPhiRadius = Math.sin( phi ) * radius;
  2771. this.x = sinPhiRadius * Math.sin( theta );
  2772. this.y = Math.cos( phi ) * radius;
  2773. this.z = sinPhiRadius * Math.cos( theta );
  2774. return this;
  2775. }
  2776. setFromCylindrical( c ) {
  2777. return this.setFromCylindricalCoords( c.radius, c.theta, c.y );
  2778. }
  2779. setFromCylindricalCoords( radius, theta, y ) {
  2780. this.x = radius * Math.sin( theta );
  2781. this.y = y;
  2782. this.z = radius * Math.cos( theta );
  2783. return this;
  2784. }
  2785. setFromMatrixPosition( m ) {
  2786. const e = m.elements;
  2787. this.x = e[ 12 ];
  2788. this.y = e[ 13 ];
  2789. this.z = e[ 14 ];
  2790. return this;
  2791. }
  2792. setFromMatrixScale( m ) {
  2793. const sx = this.setFromMatrixColumn( m, 0 ).length();
  2794. const sy = this.setFromMatrixColumn( m, 1 ).length();
  2795. const sz = this.setFromMatrixColumn( m, 2 ).length();
  2796. this.x = sx;
  2797. this.y = sy;
  2798. this.z = sz;
  2799. return this;
  2800. }
  2801. setFromMatrixColumn( m, index ) {
  2802. return this.fromArray( m.elements, index * 4 );
  2803. }
  2804. setFromMatrix3Column( m, index ) {
  2805. return this.fromArray( m.elements, index * 3 );
  2806. }
  2807. setFromEuler( e ) {
  2808. this.x = e._x;
  2809. this.y = e._y;
  2810. this.z = e._z;
  2811. return this;
  2812. }
  2813. setFromColor( c ) {
  2814. this.x = c.r;
  2815. this.y = c.g;
  2816. this.z = c.b;
  2817. return this;
  2818. }
  2819. equals( v ) {
  2820. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  2821. }
  2822. fromArray( array, offset = 0 ) {
  2823. this.x = array[ offset ];
  2824. this.y = array[ offset + 1 ];
  2825. this.z = array[ offset + 2 ];
  2826. return this;
  2827. }
  2828. toArray( array = [], offset = 0 ) {
  2829. array[ offset ] = this.x;
  2830. array[ offset + 1 ] = this.y;
  2831. array[ offset + 2 ] = this.z;
  2832. return array;
  2833. }
  2834. fromBufferAttribute( attribute, index ) {
  2835. this.x = attribute.getX( index );
  2836. this.y = attribute.getY( index );
  2837. this.z = attribute.getZ( index );
  2838. return this;
  2839. }
  2840. random() {
  2841. this.x = Math.random();
  2842. this.y = Math.random();
  2843. this.z = Math.random();
  2844. return this;
  2845. }
  2846. randomDirection() {
  2847. // https://mathworld.wolfram.com/SpherePointPicking.html
  2848. const theta = Math.random() * Math.PI * 2;
  2849. const u = Math.random() * 2 - 1;
  2850. const c = Math.sqrt( 1 - u * u );
  2851. this.x = c * Math.cos( theta );
  2852. this.y = u;
  2853. this.z = c * Math.sin( theta );
  2854. return this;
  2855. }
  2856. *[ Symbol.iterator ]() {
  2857. yield this.x;
  2858. yield this.y;
  2859. yield this.z;
  2860. }
  2861. }
  2862. const _vector$c = /*@__PURE__*/ new Vector3();
  2863. const _quaternion$4 = /*@__PURE__*/ new Quaternion();
  2864. class Box3 {
  2865. constructor( min = new Vector3( + Infinity, + Infinity, + Infinity ), max = new Vector3( - Infinity, - Infinity, - Infinity ) ) {
  2866. this.isBox3 = true;
  2867. this.min = min;
  2868. this.max = max;
  2869. }
  2870. set( min, max ) {
  2871. this.min.copy( min );
  2872. this.max.copy( max );
  2873. return this;
  2874. }
  2875. setFromArray( array ) {
  2876. this.makeEmpty();
  2877. for ( let i = 0, il = array.length; i < il; i += 3 ) {
  2878. this.expandByPoint( _vector$b.fromArray( array, i ) );
  2879. }
  2880. return this;
  2881. }
  2882. setFromBufferAttribute( attribute ) {
  2883. this.makeEmpty();
  2884. for ( let i = 0, il = attribute.count; i < il; i ++ ) {
  2885. this.expandByPoint( _vector$b.fromBufferAttribute( attribute, i ) );
  2886. }
  2887. return this;
  2888. }
  2889. setFromPoints( points ) {
  2890. this.makeEmpty();
  2891. for ( let i = 0, il = points.length; i < il; i ++ ) {
  2892. this.expandByPoint( points[ i ] );
  2893. }
  2894. return this;
  2895. }
  2896. setFromCenterAndSize( center, size ) {
  2897. const halfSize = _vector$b.copy( size ).multiplyScalar( 0.5 );
  2898. this.min.copy( center ).sub( halfSize );
  2899. this.max.copy( center ).add( halfSize );
  2900. return this;
  2901. }
  2902. setFromObject( object, precise = false ) {
  2903. this.makeEmpty();
  2904. return this.expandByObject( object, precise );
  2905. }
  2906. clone() {
  2907. return new this.constructor().copy( this );
  2908. }
  2909. copy( box ) {
  2910. this.min.copy( box.min );
  2911. this.max.copy( box.max );
  2912. return this;
  2913. }
  2914. makeEmpty() {
  2915. this.min.x = this.min.y = this.min.z = + Infinity;
  2916. this.max.x = this.max.y = this.max.z = - Infinity;
  2917. return this;
  2918. }
  2919. isEmpty() {
  2920. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2921. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2922. }
  2923. getCenter( target ) {
  2924. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2925. }
  2926. getSize( target ) {
  2927. return this.isEmpty() ? target.set( 0, 0, 0 ) : target.subVectors( this.max, this.min );
  2928. }
  2929. expandByPoint( point ) {
  2930. this.min.min( point );
  2931. this.max.max( point );
  2932. return this;
  2933. }
  2934. expandByVector( vector ) {
  2935. this.min.sub( vector );
  2936. this.max.add( vector );
  2937. return this;
  2938. }
  2939. expandByScalar( scalar ) {
  2940. this.min.addScalar( - scalar );
  2941. this.max.addScalar( scalar );
  2942. return this;
  2943. }
  2944. expandByObject( object, precise = false ) {
  2945. // Computes the world-axis-aligned bounding box of an object (including its children),
  2946. // accounting for both the object's, and children's, world transforms
  2947. object.updateWorldMatrix( false, false );
  2948. const geometry = object.geometry;
  2949. if ( geometry !== undefined ) {
  2950. const positionAttribute = geometry.getAttribute( 'position' );
  2951. // precise AABB computation based on vertex data requires at least a position attribute.
  2952. // instancing isn't supported so far and uses the normal (conservative) code path.
  2953. if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
  2954. for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
  2955. if ( object.isMesh === true ) {
  2956. object.getVertexPosition( i, _vector$b );
  2957. } else {
  2958. _vector$b.fromBufferAttribute( positionAttribute, i );
  2959. }
  2960. _vector$b.applyMatrix4( object.matrixWorld );
  2961. this.expandByPoint( _vector$b );
  2962. }
  2963. } else {
  2964. if ( object.boundingBox !== undefined ) {
  2965. // object-level bounding box
  2966. if ( object.boundingBox === null ) {
  2967. object.computeBoundingBox();
  2968. }
  2969. _box$4.copy( object.boundingBox );
  2970. } else {
  2971. // geometry-level bounding box
  2972. if ( geometry.boundingBox === null ) {
  2973. geometry.computeBoundingBox();
  2974. }
  2975. _box$4.copy( geometry.boundingBox );
  2976. }
  2977. _box$4.applyMatrix4( object.matrixWorld );
  2978. this.union( _box$4 );
  2979. }
  2980. }
  2981. const children = object.children;
  2982. for ( let i = 0, l = children.length; i < l; i ++ ) {
  2983. this.expandByObject( children[ i ], precise );
  2984. }
  2985. return this;
  2986. }
  2987. containsPoint( point ) {
  2988. return point.x >= this.min.x && point.x <= this.max.x &&
  2989. point.y >= this.min.y && point.y <= this.max.y &&
  2990. point.z >= this.min.z && point.z <= this.max.z;
  2991. }
  2992. containsBox( box ) {
  2993. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  2994. this.min.y <= box.min.y && box.max.y <= this.max.y &&
  2995. this.min.z <= box.min.z && box.max.z <= this.max.z;
  2996. }
  2997. getParameter( point, target ) {
  2998. // This can potentially have a divide by zero if the box
  2999. // has a size dimension of 0.
  3000. return target.set(
  3001. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  3002. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  3003. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  3004. );
  3005. }
  3006. intersectsBox( box ) {
  3007. // using 6 splitting planes to rule out intersections.
  3008. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  3009. box.max.y >= this.min.y && box.min.y <= this.max.y &&
  3010. box.max.z >= this.min.z && box.min.z <= this.max.z;
  3011. }
  3012. intersectsSphere( sphere ) {
  3013. // Find the point on the AABB closest to the sphere center.
  3014. this.clampPoint( sphere.center, _vector$b );
  3015. // If that point is inside the sphere, the AABB and sphere intersect.
  3016. return _vector$b.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  3017. }
  3018. intersectsPlane( plane ) {
  3019. // We compute the minimum and maximum dot product values. If those values
  3020. // are on the same side (back or front) of the plane, then there is no intersection.
  3021. let min, max;
  3022. if ( plane.normal.x > 0 ) {
  3023. min = plane.normal.x * this.min.x;
  3024. max = plane.normal.x * this.max.x;
  3025. } else {
  3026. min = plane.normal.x * this.max.x;
  3027. max = plane.normal.x * this.min.x;
  3028. }
  3029. if ( plane.normal.y > 0 ) {
  3030. min += plane.normal.y * this.min.y;
  3031. max += plane.normal.y * this.max.y;
  3032. } else {
  3033. min += plane.normal.y * this.max.y;
  3034. max += plane.normal.y * this.min.y;
  3035. }
  3036. if ( plane.normal.z > 0 ) {
  3037. min += plane.normal.z * this.min.z;
  3038. max += plane.normal.z * this.max.z;
  3039. } else {
  3040. min += plane.normal.z * this.max.z;
  3041. max += plane.normal.z * this.min.z;
  3042. }
  3043. return ( min <= - plane.constant && max >= - plane.constant );
  3044. }
  3045. intersectsTriangle( triangle ) {
  3046. if ( this.isEmpty() ) {
  3047. return false;
  3048. }
  3049. // compute box center and extents
  3050. this.getCenter( _center );
  3051. _extents.subVectors( this.max, _center );
  3052. // translate triangle to aabb origin
  3053. _v0$2.subVectors( triangle.a, _center );
  3054. _v1$7.subVectors( triangle.b, _center );
  3055. _v2$4.subVectors( triangle.c, _center );
  3056. // compute edge vectors for triangle
  3057. _f0.subVectors( _v1$7, _v0$2 );
  3058. _f1.subVectors( _v2$4, _v1$7 );
  3059. _f2.subVectors( _v0$2, _v2$4 );
  3060. // test against axes that are given by cross product combinations of the edges of the triangle and the edges of the aabb
  3061. // 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
  3062. // axis_ij = u_i x f_j (u0, u1, u2 = face normals of aabb = x,y,z axes vectors since aabb is axis aligned)
  3063. let axes = [
  3064. 0, - _f0.z, _f0.y, 0, - _f1.z, _f1.y, 0, - _f2.z, _f2.y,
  3065. _f0.z, 0, - _f0.x, _f1.z, 0, - _f1.x, _f2.z, 0, - _f2.x,
  3066. - _f0.y, _f0.x, 0, - _f1.y, _f1.x, 0, - _f2.y, _f2.x, 0
  3067. ];
  3068. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3069. return false;
  3070. }
  3071. // test 3 face normals from the aabb
  3072. axes = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
  3073. if ( ! satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents ) ) {
  3074. return false;
  3075. }
  3076. // finally testing the face normal of the triangle
  3077. // use already existing triangle edge vectors here
  3078. _triangleNormal.crossVectors( _f0, _f1 );
  3079. axes = [ _triangleNormal.x, _triangleNormal.y, _triangleNormal.z ];
  3080. return satForAxes( axes, _v0$2, _v1$7, _v2$4, _extents );
  3081. }
  3082. clampPoint( point, target ) {
  3083. return target.copy( point ).clamp( this.min, this.max );
  3084. }
  3085. distanceToPoint( point ) {
  3086. return this.clampPoint( point, _vector$b ).distanceTo( point );
  3087. }
  3088. getBoundingSphere( target ) {
  3089. if ( this.isEmpty() ) {
  3090. target.makeEmpty();
  3091. } else {
  3092. this.getCenter( target.center );
  3093. target.radius = this.getSize( _vector$b ).length() * 0.5;
  3094. }
  3095. return target;
  3096. }
  3097. intersect( box ) {
  3098. this.min.max( box.min );
  3099. this.max.min( box.max );
  3100. // 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.
  3101. if ( this.isEmpty() ) this.makeEmpty();
  3102. return this;
  3103. }
  3104. union( box ) {
  3105. this.min.min( box.min );
  3106. this.max.max( box.max );
  3107. return this;
  3108. }
  3109. applyMatrix4( matrix ) {
  3110. // transform of empty box is an empty box.
  3111. if ( this.isEmpty() ) return this;
  3112. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  3113. _points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  3114. _points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  3115. _points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  3116. _points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  3117. _points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  3118. _points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  3119. _points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  3120. _points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  3121. this.setFromPoints( _points );
  3122. return this;
  3123. }
  3124. translate( offset ) {
  3125. this.min.add( offset );
  3126. this.max.add( offset );
  3127. return this;
  3128. }
  3129. equals( box ) {
  3130. return box.min.equals( this.min ) && box.max.equals( this.max );
  3131. }
  3132. }
  3133. const _points = [
  3134. /*@__PURE__*/ new Vector3(),
  3135. /*@__PURE__*/ new Vector3(),
  3136. /*@__PURE__*/ new Vector3(),
  3137. /*@__PURE__*/ new Vector3(),
  3138. /*@__PURE__*/ new Vector3(),
  3139. /*@__PURE__*/ new Vector3(),
  3140. /*@__PURE__*/ new Vector3(),
  3141. /*@__PURE__*/ new Vector3()
  3142. ];
  3143. const _vector$b = /*@__PURE__*/ new Vector3();
  3144. const _box$4 = /*@__PURE__*/ new Box3();
  3145. // triangle centered vertices
  3146. const _v0$2 = /*@__PURE__*/ new Vector3();
  3147. const _v1$7 = /*@__PURE__*/ new Vector3();
  3148. const _v2$4 = /*@__PURE__*/ new Vector3();
  3149. // triangle edge vectors
  3150. const _f0 = /*@__PURE__*/ new Vector3();
  3151. const _f1 = /*@__PURE__*/ new Vector3();
  3152. const _f2 = /*@__PURE__*/ new Vector3();
  3153. const _center = /*@__PURE__*/ new Vector3();
  3154. const _extents = /*@__PURE__*/ new Vector3();
  3155. const _triangleNormal = /*@__PURE__*/ new Vector3();
  3156. const _testAxis = /*@__PURE__*/ new Vector3();
  3157. function satForAxes( axes, v0, v1, v2, extents ) {
  3158. for ( let i = 0, j = axes.length - 3; i <= j; i += 3 ) {
  3159. _testAxis.fromArray( axes, i );
  3160. // project the aabb onto the separating axis
  3161. const r = extents.x * Math.abs( _testAxis.x ) + extents.y * Math.abs( _testAxis.y ) + extents.z * Math.abs( _testAxis.z );
  3162. // project all 3 vertices of the triangle onto the separating axis
  3163. const p0 = v0.dot( _testAxis );
  3164. const p1 = v1.dot( _testAxis );
  3165. const p2 = v2.dot( _testAxis );
  3166. // actual test, basically see if either of the most extreme of the triangle points intersects r
  3167. if ( Math.max( - Math.max( p0, p1, p2 ), Math.min( p0, p1, p2 ) ) > r ) {
  3168. // points of the projected triangle are outside the projected half-length of the aabb
  3169. // the axis is separating and we can exit
  3170. return false;
  3171. }
  3172. }
  3173. return true;
  3174. }
  3175. const _box$3 = /*@__PURE__*/ new Box3();
  3176. const _v1$6 = /*@__PURE__*/ new Vector3();
  3177. const _v2$3 = /*@__PURE__*/ new Vector3();
  3178. class Sphere {
  3179. constructor( center = new Vector3(), radius = - 1 ) {
  3180. this.isSphere = true;
  3181. this.center = center;
  3182. this.radius = radius;
  3183. }
  3184. set( center, radius ) {
  3185. this.center.copy( center );
  3186. this.radius = radius;
  3187. return this;
  3188. }
  3189. setFromPoints( points, optionalCenter ) {
  3190. const center = this.center;
  3191. if ( optionalCenter !== undefined ) {
  3192. center.copy( optionalCenter );
  3193. } else {
  3194. _box$3.setFromPoints( points ).getCenter( center );
  3195. }
  3196. let maxRadiusSq = 0;
  3197. for ( let i = 0, il = points.length; i < il; i ++ ) {
  3198. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3199. }
  3200. this.radius = Math.sqrt( maxRadiusSq );
  3201. return this;
  3202. }
  3203. copy( sphere ) {
  3204. this.center.copy( sphere.center );
  3205. this.radius = sphere.radius;
  3206. return this;
  3207. }
  3208. isEmpty() {
  3209. return ( this.radius < 0 );
  3210. }
  3211. makeEmpty() {
  3212. this.center.set( 0, 0, 0 );
  3213. this.radius = - 1;
  3214. return this;
  3215. }
  3216. containsPoint( point ) {
  3217. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3218. }
  3219. distanceToPoint( point ) {
  3220. return ( point.distanceTo( this.center ) - this.radius );
  3221. }
  3222. intersectsSphere( sphere ) {
  3223. const radiusSum = this.radius + sphere.radius;
  3224. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3225. }
  3226. intersectsBox( box ) {
  3227. return box.intersectsSphere( this );
  3228. }
  3229. intersectsPlane( plane ) {
  3230. return Math.abs( plane.distanceToPoint( this.center ) ) <= this.radius;
  3231. }
  3232. clampPoint( point, target ) {
  3233. const deltaLengthSq = this.center.distanceToSquared( point );
  3234. target.copy( point );
  3235. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3236. target.sub( this.center ).normalize();
  3237. target.multiplyScalar( this.radius ).add( this.center );
  3238. }
  3239. return target;
  3240. }
  3241. getBoundingBox( target ) {
  3242. if ( this.isEmpty() ) {
  3243. // Empty sphere produces empty bounding box
  3244. target.makeEmpty();
  3245. return target;
  3246. }
  3247. target.set( this.center, this.center );
  3248. target.expandByScalar( this.radius );
  3249. return target;
  3250. }
  3251. applyMatrix4( matrix ) {
  3252. this.center.applyMatrix4( matrix );
  3253. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3254. return this;
  3255. }
  3256. translate( offset ) {
  3257. this.center.add( offset );
  3258. return this;
  3259. }
  3260. expandByPoint( point ) {
  3261. if ( this.isEmpty() ) {
  3262. this.center.copy( point );
  3263. this.radius = 0;
  3264. return this;
  3265. }
  3266. _v1$6.subVectors( point, this.center );
  3267. const lengthSq = _v1$6.lengthSq();
  3268. if ( lengthSq > ( this.radius * this.radius ) ) {
  3269. // calculate the minimal sphere
  3270. const length = Math.sqrt( lengthSq );
  3271. const delta = ( length - this.radius ) * 0.5;
  3272. this.center.addScaledVector( _v1$6, delta / length );
  3273. this.radius += delta;
  3274. }
  3275. return this;
  3276. }
  3277. union( sphere ) {
  3278. if ( sphere.isEmpty() ) {
  3279. return this;
  3280. }
  3281. if ( this.isEmpty() ) {
  3282. this.copy( sphere );
  3283. return this;
  3284. }
  3285. if ( this.center.equals( sphere.center ) === true ) {
  3286. this.radius = Math.max( this.radius, sphere.radius );
  3287. } else {
  3288. _v2$3.subVectors( sphere.center, this.center ).setLength( sphere.radius );
  3289. this.expandByPoint( _v1$6.copy( sphere.center ).add( _v2$3 ) );
  3290. this.expandByPoint( _v1$6.copy( sphere.center ).sub( _v2$3 ) );
  3291. }
  3292. return this;
  3293. }
  3294. equals( sphere ) {
  3295. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3296. }
  3297. clone() {
  3298. return new this.constructor().copy( this );
  3299. }
  3300. }
  3301. const _vector$a = /*@__PURE__*/ new Vector3();
  3302. const _segCenter = /*@__PURE__*/ new Vector3();
  3303. const _segDir = /*@__PURE__*/ new Vector3();
  3304. const _diff = /*@__PURE__*/ new Vector3();
  3305. const _edge1 = /*@__PURE__*/ new Vector3();
  3306. const _edge2 = /*@__PURE__*/ new Vector3();
  3307. const _normal$1 = /*@__PURE__*/ new Vector3();
  3308. class Ray {
  3309. constructor( origin = new Vector3(), direction = new Vector3( 0, 0, - 1 ) ) {
  3310. this.origin = origin;
  3311. this.direction = direction;
  3312. }
  3313. set( origin, direction ) {
  3314. this.origin.copy( origin );
  3315. this.direction.copy( direction );
  3316. return this;
  3317. }
  3318. copy( ray ) {
  3319. this.origin.copy( ray.origin );
  3320. this.direction.copy( ray.direction );
  3321. return this;
  3322. }
  3323. at( t, target ) {
  3324. return target.copy( this.origin ).addScaledVector( this.direction, t );
  3325. }
  3326. lookAt( v ) {
  3327. this.direction.copy( v ).sub( this.origin ).normalize();
  3328. return this;
  3329. }
  3330. recast( t ) {
  3331. this.origin.copy( this.at( t, _vector$a ) );
  3332. return this;
  3333. }
  3334. closestPointToPoint( point, target ) {
  3335. target.subVectors( point, this.origin );
  3336. const directionDistance = target.dot( this.direction );
  3337. if ( directionDistance < 0 ) {
  3338. return target.copy( this.origin );
  3339. }
  3340. return target.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3341. }
  3342. distanceToPoint( point ) {
  3343. return Math.sqrt( this.distanceSqToPoint( point ) );
  3344. }
  3345. distanceSqToPoint( point ) {
  3346. const directionDistance = _vector$a.subVectors( point, this.origin ).dot( this.direction );
  3347. // point behind the ray
  3348. if ( directionDistance < 0 ) {
  3349. return this.origin.distanceToSquared( point );
  3350. }
  3351. _vector$a.copy( this.origin ).addScaledVector( this.direction, directionDistance );
  3352. return _vector$a.distanceToSquared( point );
  3353. }
  3354. distanceSqToSegment( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3355. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteDistRaySegment.h
  3356. // It returns the min distance between the ray and the segment
  3357. // defined by v0 and v1
  3358. // It can also set two optional targets :
  3359. // - The closest point on the ray
  3360. // - The closest point on the segment
  3361. _segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3362. _segDir.copy( v1 ).sub( v0 ).normalize();
  3363. _diff.copy( this.origin ).sub( _segCenter );
  3364. const segExtent = v0.distanceTo( v1 ) * 0.5;
  3365. const a01 = - this.direction.dot( _segDir );
  3366. const b0 = _diff.dot( this.direction );
  3367. const b1 = - _diff.dot( _segDir );
  3368. const c = _diff.lengthSq();
  3369. const det = Math.abs( 1 - a01 * a01 );
  3370. let s0, s1, sqrDist, extDet;
  3371. if ( det > 0 ) {
  3372. // The ray and segment are not parallel.
  3373. s0 = a01 * b1 - b0;
  3374. s1 = a01 * b0 - b1;
  3375. extDet = segExtent * det;
  3376. if ( s0 >= 0 ) {
  3377. if ( s1 >= - extDet ) {
  3378. if ( s1 <= extDet ) {
  3379. // region 0
  3380. // Minimum at interior points of ray and segment.
  3381. const invDet = 1 / det;
  3382. s0 *= invDet;
  3383. s1 *= invDet;
  3384. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3385. } else {
  3386. // region 1
  3387. s1 = segExtent;
  3388. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3389. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3390. }
  3391. } else {
  3392. // region 5
  3393. s1 = - segExtent;
  3394. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3395. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3396. }
  3397. } else {
  3398. if ( s1 <= - extDet ) {
  3399. // region 4
  3400. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3401. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3402. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3403. } else if ( s1 <= extDet ) {
  3404. // region 3
  3405. s0 = 0;
  3406. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3407. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3408. } else {
  3409. // region 2
  3410. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3411. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3412. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3413. }
  3414. }
  3415. } else {
  3416. // Ray and segment are parallel.
  3417. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3418. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3419. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3420. }
  3421. if ( optionalPointOnRay ) {
  3422. optionalPointOnRay.copy( this.origin ).addScaledVector( this.direction, s0 );
  3423. }
  3424. if ( optionalPointOnSegment ) {
  3425. optionalPointOnSegment.copy( _segCenter ).addScaledVector( _segDir, s1 );
  3426. }
  3427. return sqrDist;
  3428. }
  3429. intersectSphere( sphere, target ) {
  3430. _vector$a.subVectors( sphere.center, this.origin );
  3431. const tca = _vector$a.dot( this.direction );
  3432. const d2 = _vector$a.dot( _vector$a ) - tca * tca;
  3433. const radius2 = sphere.radius * sphere.radius;
  3434. if ( d2 > radius2 ) return null;
  3435. const thc = Math.sqrt( radius2 - d2 );
  3436. // t0 = first intersect point - entrance on front of sphere
  3437. const t0 = tca - thc;
  3438. // t1 = second intersect point - exit point on back of sphere
  3439. const t1 = tca + thc;
  3440. // test to see if t1 is behind the ray - if so, return null
  3441. if ( t1 < 0 ) return null;
  3442. // test to see if t0 is behind the ray:
  3443. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3444. // in order to always return an intersect point that is in front of the ray.
  3445. if ( t0 < 0 ) return this.at( t1, target );
  3446. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3447. return this.at( t0, target );
  3448. }
  3449. intersectsSphere( sphere ) {
  3450. return this.distanceSqToPoint( sphere.center ) <= ( sphere.radius * sphere.radius );
  3451. }
  3452. distanceToPlane( plane ) {
  3453. const denominator = plane.normal.dot( this.direction );
  3454. if ( denominator === 0 ) {
  3455. // line is coplanar, return origin
  3456. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3457. return 0;
  3458. }
  3459. // Null is preferable to undefined since undefined means.... it is undefined
  3460. return null;
  3461. }
  3462. const t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3463. // Return if the ray never intersects the plane
  3464. return t >= 0 ? t : null;
  3465. }
  3466. intersectPlane( plane, target ) {
  3467. const t = this.distanceToPlane( plane );
  3468. if ( t === null ) {
  3469. return null;
  3470. }
  3471. return this.at( t, target );
  3472. }
  3473. intersectsPlane( plane ) {
  3474. // check if the ray lies on the plane first
  3475. const distToPoint = plane.distanceToPoint( this.origin );
  3476. if ( distToPoint === 0 ) {
  3477. return true;
  3478. }
  3479. const denominator = plane.normal.dot( this.direction );
  3480. if ( denominator * distToPoint < 0 ) {
  3481. return true;
  3482. }
  3483. // ray origin is behind the plane (and is pointing behind it)
  3484. return false;
  3485. }
  3486. intersectBox( box, target ) {
  3487. let tmin, tmax, tymin, tymax, tzmin, tzmax;
  3488. const invdirx = 1 / this.direction.x,
  3489. invdiry = 1 / this.direction.y,
  3490. invdirz = 1 / this.direction.z;
  3491. const origin = this.origin;
  3492. if ( invdirx >= 0 ) {
  3493. tmin = ( box.min.x - origin.x ) * invdirx;
  3494. tmax = ( box.max.x - origin.x ) * invdirx;
  3495. } else {
  3496. tmin = ( box.max.x - origin.x ) * invdirx;
  3497. tmax = ( box.min.x - origin.x ) * invdirx;
  3498. }
  3499. if ( invdiry >= 0 ) {
  3500. tymin = ( box.min.y - origin.y ) * invdiry;
  3501. tymax = ( box.max.y - origin.y ) * invdiry;
  3502. } else {
  3503. tymin = ( box.max.y - origin.y ) * invdiry;
  3504. tymax = ( box.min.y - origin.y ) * invdiry;
  3505. }
  3506. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3507. if ( tymin > tmin || isNaN( tmin ) ) tmin = tymin;
  3508. if ( tymax < tmax || isNaN( tmax ) ) tmax = tymax;
  3509. if ( invdirz >= 0 ) {
  3510. tzmin = ( box.min.z - origin.z ) * invdirz;
  3511. tzmax = ( box.max.z - origin.z ) * invdirz;
  3512. } else {
  3513. tzmin = ( box.max.z - origin.z ) * invdirz;
  3514. tzmax = ( box.min.z - origin.z ) * invdirz;
  3515. }
  3516. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3517. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3518. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3519. //return point closest to the ray (positive side)
  3520. if ( tmax < 0 ) return null;
  3521. return this.at( tmin >= 0 ? tmin : tmax, target );
  3522. }
  3523. intersectsBox( box ) {
  3524. return this.intersectBox( box, _vector$a ) !== null;
  3525. }
  3526. intersectTriangle( a, b, c, backfaceCulling, target ) {
  3527. // Compute the offset origin, edges, and normal.
  3528. // from https://github.com/pmjoniak/GeometricTools/blob/master/GTEngine/Include/Mathematics/GteIntrRay3Triangle3.h
  3529. _edge1.subVectors( b, a );
  3530. _edge2.subVectors( c, a );
  3531. _normal$1.crossVectors( _edge1, _edge2 );
  3532. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3533. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3534. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3535. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3536. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3537. let DdN = this.direction.dot( _normal$1 );
  3538. let sign;
  3539. if ( DdN > 0 ) {
  3540. if ( backfaceCulling ) return null;
  3541. sign = 1;
  3542. } else if ( DdN < 0 ) {
  3543. sign = - 1;
  3544. DdN = - DdN;
  3545. } else {
  3546. return null;
  3547. }
  3548. _diff.subVectors( this.origin, a );
  3549. const DdQxE2 = sign * this.direction.dot( _edge2.crossVectors( _diff, _edge2 ) );
  3550. // b1 < 0, no intersection
  3551. if ( DdQxE2 < 0 ) {
  3552. return null;
  3553. }
  3554. const DdE1xQ = sign * this.direction.dot( _edge1.cross( _diff ) );
  3555. // b2 < 0, no intersection
  3556. if ( DdE1xQ < 0 ) {
  3557. return null;
  3558. }
  3559. // b1+b2 > 1, no intersection
  3560. if ( DdQxE2 + DdE1xQ > DdN ) {
  3561. return null;
  3562. }
  3563. // Line intersects triangle, check if ray does.
  3564. const QdN = - sign * _diff.dot( _normal$1 );
  3565. // t < 0, no intersection
  3566. if ( QdN < 0 ) {
  3567. return null;
  3568. }
  3569. // Ray intersects triangle.
  3570. return this.at( QdN / DdN, target );
  3571. }
  3572. applyMatrix4( matrix4 ) {
  3573. this.origin.applyMatrix4( matrix4 );
  3574. this.direction.transformDirection( matrix4 );
  3575. return this;
  3576. }
  3577. equals( ray ) {
  3578. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3579. }
  3580. clone() {
  3581. return new this.constructor().copy( this );
  3582. }
  3583. }
  3584. class Matrix4 {
  3585. constructor( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3586. Matrix4.prototype.isMatrix4 = true;
  3587. this.elements = [
  3588. 1, 0, 0, 0,
  3589. 0, 1, 0, 0,
  3590. 0, 0, 1, 0,
  3591. 0, 0, 0, 1
  3592. ];
  3593. if ( n11 !== undefined ) {
  3594. this.set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 );
  3595. }
  3596. }
  3597. set( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  3598. const te = this.elements;
  3599. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  3600. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  3601. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  3602. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  3603. return this;
  3604. }
  3605. identity() {
  3606. this.set(
  3607. 1, 0, 0, 0,
  3608. 0, 1, 0, 0,
  3609. 0, 0, 1, 0,
  3610. 0, 0, 0, 1
  3611. );
  3612. return this;
  3613. }
  3614. clone() {
  3615. return new Matrix4().fromArray( this.elements );
  3616. }
  3617. copy( m ) {
  3618. const te = this.elements;
  3619. const me = m.elements;
  3620. te[ 0 ] = me[ 0 ]; te[ 1 ] = me[ 1 ]; te[ 2 ] = me[ 2 ]; te[ 3 ] = me[ 3 ];
  3621. te[ 4 ] = me[ 4 ]; te[ 5 ] = me[ 5 ]; te[ 6 ] = me[ 6 ]; te[ 7 ] = me[ 7 ];
  3622. te[ 8 ] = me[ 8 ]; te[ 9 ] = me[ 9 ]; te[ 10 ] = me[ 10 ]; te[ 11 ] = me[ 11 ];
  3623. te[ 12 ] = me[ 12 ]; te[ 13 ] = me[ 13 ]; te[ 14 ] = me[ 14 ]; te[ 15 ] = me[ 15 ];
  3624. return this;
  3625. }
  3626. copyPosition( m ) {
  3627. const te = this.elements, me = m.elements;
  3628. te[ 12 ] = me[ 12 ];
  3629. te[ 13 ] = me[ 13 ];
  3630. te[ 14 ] = me[ 14 ];
  3631. return this;
  3632. }
  3633. setFromMatrix3( m ) {
  3634. const me = m.elements;
  3635. this.set(
  3636. me[ 0 ], me[ 3 ], me[ 6 ], 0,
  3637. me[ 1 ], me[ 4 ], me[ 7 ], 0,
  3638. me[ 2 ], me[ 5 ], me[ 8 ], 0,
  3639. 0, 0, 0, 1
  3640. );
  3641. return this;
  3642. }
  3643. extractBasis( xAxis, yAxis, zAxis ) {
  3644. xAxis.setFromMatrixColumn( this, 0 );
  3645. yAxis.setFromMatrixColumn( this, 1 );
  3646. zAxis.setFromMatrixColumn( this, 2 );
  3647. return this;
  3648. }
  3649. makeBasis( xAxis, yAxis, zAxis ) {
  3650. this.set(
  3651. xAxis.x, yAxis.x, zAxis.x, 0,
  3652. xAxis.y, yAxis.y, zAxis.y, 0,
  3653. xAxis.z, yAxis.z, zAxis.z, 0,
  3654. 0, 0, 0, 1
  3655. );
  3656. return this;
  3657. }
  3658. extractRotation( m ) {
  3659. // this method does not support reflection matrices
  3660. const te = this.elements;
  3661. const me = m.elements;
  3662. const scaleX = 1 / _v1$5.setFromMatrixColumn( m, 0 ).length();
  3663. const scaleY = 1 / _v1$5.setFromMatrixColumn( m, 1 ).length();
  3664. const scaleZ = 1 / _v1$5.setFromMatrixColumn( m, 2 ).length();
  3665. te[ 0 ] = me[ 0 ] * scaleX;
  3666. te[ 1 ] = me[ 1 ] * scaleX;
  3667. te[ 2 ] = me[ 2 ] * scaleX;
  3668. te[ 3 ] = 0;
  3669. te[ 4 ] = me[ 4 ] * scaleY;
  3670. te[ 5 ] = me[ 5 ] * scaleY;
  3671. te[ 6 ] = me[ 6 ] * scaleY;
  3672. te[ 7 ] = 0;
  3673. te[ 8 ] = me[ 8 ] * scaleZ;
  3674. te[ 9 ] = me[ 9 ] * scaleZ;
  3675. te[ 10 ] = me[ 10 ] * scaleZ;
  3676. te[ 11 ] = 0;
  3677. te[ 12 ] = 0;
  3678. te[ 13 ] = 0;
  3679. te[ 14 ] = 0;
  3680. te[ 15 ] = 1;
  3681. return this;
  3682. }
  3683. makeRotationFromEuler( euler ) {
  3684. const te = this.elements;
  3685. const x = euler.x, y = euler.y, z = euler.z;
  3686. const a = Math.cos( x ), b = Math.sin( x );
  3687. const c = Math.cos( y ), d = Math.sin( y );
  3688. const e = Math.cos( z ), f = Math.sin( z );
  3689. if ( euler.order === 'XYZ' ) {
  3690. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3691. te[ 0 ] = c * e;
  3692. te[ 4 ] = - c * f;
  3693. te[ 8 ] = d;
  3694. te[ 1 ] = af + be * d;
  3695. te[ 5 ] = ae - bf * d;
  3696. te[ 9 ] = - b * c;
  3697. te[ 2 ] = bf - ae * d;
  3698. te[ 6 ] = be + af * d;
  3699. te[ 10 ] = a * c;
  3700. } else if ( euler.order === 'YXZ' ) {
  3701. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3702. te[ 0 ] = ce + df * b;
  3703. te[ 4 ] = de * b - cf;
  3704. te[ 8 ] = a * d;
  3705. te[ 1 ] = a * f;
  3706. te[ 5 ] = a * e;
  3707. te[ 9 ] = - b;
  3708. te[ 2 ] = cf * b - de;
  3709. te[ 6 ] = df + ce * b;
  3710. te[ 10 ] = a * c;
  3711. } else if ( euler.order === 'ZXY' ) {
  3712. const ce = c * e, cf = c * f, de = d * e, df = d * f;
  3713. te[ 0 ] = ce - df * b;
  3714. te[ 4 ] = - a * f;
  3715. te[ 8 ] = de + cf * b;
  3716. te[ 1 ] = cf + de * b;
  3717. te[ 5 ] = a * e;
  3718. te[ 9 ] = df - ce * b;
  3719. te[ 2 ] = - a * d;
  3720. te[ 6 ] = b;
  3721. te[ 10 ] = a * c;
  3722. } else if ( euler.order === 'ZYX' ) {
  3723. const ae = a * e, af = a * f, be = b * e, bf = b * f;
  3724. te[ 0 ] = c * e;
  3725. te[ 4 ] = be * d - af;
  3726. te[ 8 ] = ae * d + bf;
  3727. te[ 1 ] = c * f;
  3728. te[ 5 ] = bf * d + ae;
  3729. te[ 9 ] = af * d - be;
  3730. te[ 2 ] = - d;
  3731. te[ 6 ] = b * c;
  3732. te[ 10 ] = a * c;
  3733. } else if ( euler.order === 'YZX' ) {
  3734. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3735. te[ 0 ] = c * e;
  3736. te[ 4 ] = bd - ac * f;
  3737. te[ 8 ] = bc * f + ad;
  3738. te[ 1 ] = f;
  3739. te[ 5 ] = a * e;
  3740. te[ 9 ] = - b * e;
  3741. te[ 2 ] = - d * e;
  3742. te[ 6 ] = ad * f + bc;
  3743. te[ 10 ] = ac - bd * f;
  3744. } else if ( euler.order === 'XZY' ) {
  3745. const ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  3746. te[ 0 ] = c * e;
  3747. te[ 4 ] = - f;
  3748. te[ 8 ] = d * e;
  3749. te[ 1 ] = ac * f + bd;
  3750. te[ 5 ] = a * e;
  3751. te[ 9 ] = ad * f - bc;
  3752. te[ 2 ] = bc * f - ad;
  3753. te[ 6 ] = b * e;
  3754. te[ 10 ] = bd * f + ac;
  3755. }
  3756. // bottom row
  3757. te[ 3 ] = 0;
  3758. te[ 7 ] = 0;
  3759. te[ 11 ] = 0;
  3760. // last column
  3761. te[ 12 ] = 0;
  3762. te[ 13 ] = 0;
  3763. te[ 14 ] = 0;
  3764. te[ 15 ] = 1;
  3765. return this;
  3766. }
  3767. makeRotationFromQuaternion( q ) {
  3768. return this.compose( _zero, q, _one );
  3769. }
  3770. lookAt( eye, target, up ) {
  3771. const te = this.elements;
  3772. _z.subVectors( eye, target );
  3773. if ( _z.lengthSq() === 0 ) {
  3774. // eye and target are in the same position
  3775. _z.z = 1;
  3776. }
  3777. _z.normalize();
  3778. _x.crossVectors( up, _z );
  3779. if ( _x.lengthSq() === 0 ) {
  3780. // up and z are parallel
  3781. if ( Math.abs( up.z ) === 1 ) {
  3782. _z.x += 0.0001;
  3783. } else {
  3784. _z.z += 0.0001;
  3785. }
  3786. _z.normalize();
  3787. _x.crossVectors( up, _z );
  3788. }
  3789. _x.normalize();
  3790. _y.crossVectors( _z, _x );
  3791. te[ 0 ] = _x.x; te[ 4 ] = _y.x; te[ 8 ] = _z.x;
  3792. te[ 1 ] = _x.y; te[ 5 ] = _y.y; te[ 9 ] = _z.y;
  3793. te[ 2 ] = _x.z; te[ 6 ] = _y.z; te[ 10 ] = _z.z;
  3794. return this;
  3795. }
  3796. multiply( m ) {
  3797. return this.multiplyMatrices( this, m );
  3798. }
  3799. premultiply( m ) {
  3800. return this.multiplyMatrices( m, this );
  3801. }
  3802. multiplyMatrices( a, b ) {
  3803. const ae = a.elements;
  3804. const be = b.elements;
  3805. const te = this.elements;
  3806. const a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3807. const a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3808. const a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3809. const a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3810. const b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3811. const b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3812. const b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3813. const b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3814. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3815. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3816. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3817. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3818. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3819. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3820. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3821. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3822. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3823. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3824. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3825. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3826. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3827. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3828. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3829. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3830. return this;
  3831. }
  3832. multiplyScalar( s ) {
  3833. const te = this.elements;
  3834. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3835. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3836. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3837. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3838. return this;
  3839. }
  3840. determinant() {
  3841. const te = this.elements;
  3842. const n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3843. const n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3844. const n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3845. const n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3846. //TODO: make this more efficient
  3847. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3848. return (
  3849. n41 * (
  3850. + n14 * n23 * n32
  3851. - n13 * n24 * n32
  3852. - n14 * n22 * n33
  3853. + n12 * n24 * n33
  3854. + n13 * n22 * n34
  3855. - n12 * n23 * n34
  3856. ) +
  3857. n42 * (
  3858. + n11 * n23 * n34
  3859. - n11 * n24 * n33
  3860. + n14 * n21 * n33
  3861. - n13 * n21 * n34
  3862. + n13 * n24 * n31
  3863. - n14 * n23 * n31
  3864. ) +
  3865. n43 * (
  3866. + n11 * n24 * n32
  3867. - n11 * n22 * n34
  3868. - n14 * n21 * n32
  3869. + n12 * n21 * n34
  3870. + n14 * n22 * n31
  3871. - n12 * n24 * n31
  3872. ) +
  3873. n44 * (
  3874. - n13 * n22 * n31
  3875. - n11 * n23 * n32
  3876. + n11 * n22 * n33
  3877. + n13 * n21 * n32
  3878. - n12 * n21 * n33
  3879. + n12 * n23 * n31
  3880. )
  3881. );
  3882. }
  3883. transpose() {
  3884. const te = this.elements;
  3885. let tmp;
  3886. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3887. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3888. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3889. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3890. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3891. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3892. return this;
  3893. }
  3894. setPosition( x, y, z ) {
  3895. const te = this.elements;
  3896. if ( x.isVector3 ) {
  3897. te[ 12 ] = x.x;
  3898. te[ 13 ] = x.y;
  3899. te[ 14 ] = x.z;
  3900. } else {
  3901. te[ 12 ] = x;
  3902. te[ 13 ] = y;
  3903. te[ 14 ] = z;
  3904. }
  3905. return this;
  3906. }
  3907. invert() {
  3908. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3909. const te = this.elements,
  3910. n11 = te[ 0 ], n21 = te[ 1 ], n31 = te[ 2 ], n41 = te[ 3 ],
  3911. n12 = te[ 4 ], n22 = te[ 5 ], n32 = te[ 6 ], n42 = te[ 7 ],
  3912. n13 = te[ 8 ], n23 = te[ 9 ], n33 = te[ 10 ], n43 = te[ 11 ],
  3913. n14 = te[ 12 ], n24 = te[ 13 ], n34 = te[ 14 ], n44 = te[ 15 ],
  3914. t11 = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44,
  3915. t12 = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44,
  3916. t13 = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44,
  3917. t14 = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3918. const det = n11 * t11 + n21 * t12 + n31 * t13 + n41 * t14;
  3919. if ( det === 0 ) return this.set( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
  3920. const detInv = 1 / det;
  3921. te[ 0 ] = t11 * detInv;
  3922. te[ 1 ] = ( n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44 ) * detInv;
  3923. te[ 2 ] = ( n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44 ) * detInv;
  3924. te[ 3 ] = ( n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43 ) * detInv;
  3925. te[ 4 ] = t12 * detInv;
  3926. te[ 5 ] = ( n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44 ) * detInv;
  3927. te[ 6 ] = ( n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44 ) * detInv;
  3928. te[ 7 ] = ( n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43 ) * detInv;
  3929. te[ 8 ] = t13 * detInv;
  3930. te[ 9 ] = ( n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44 ) * detInv;
  3931. te[ 10 ] = ( n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44 ) * detInv;
  3932. te[ 11 ] = ( n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43 ) * detInv;
  3933. te[ 12 ] = t14 * detInv;
  3934. te[ 13 ] = ( n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34 ) * detInv;
  3935. te[ 14 ] = ( n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34 ) * detInv;
  3936. te[ 15 ] = ( n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33 ) * detInv;
  3937. return this;
  3938. }
  3939. scale( v ) {
  3940. const te = this.elements;
  3941. const x = v.x, y = v.y, z = v.z;
  3942. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3943. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3944. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3945. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3946. return this;
  3947. }
  3948. getMaxScaleOnAxis() {
  3949. const te = this.elements;
  3950. const scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3951. const scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3952. const scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3953. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3954. }
  3955. makeTranslation( x, y, z ) {
  3956. if ( x.isVector3 ) {
  3957. this.set(
  3958. 1, 0, 0, x.x,
  3959. 0, 1, 0, x.y,
  3960. 0, 0, 1, x.z,
  3961. 0, 0, 0, 1
  3962. );
  3963. } else {
  3964. this.set(
  3965. 1, 0, 0, x,
  3966. 0, 1, 0, y,
  3967. 0, 0, 1, z,
  3968. 0, 0, 0, 1
  3969. );
  3970. }
  3971. return this;
  3972. }
  3973. makeRotationX( theta ) {
  3974. const c = Math.cos( theta ), s = Math.sin( theta );
  3975. this.set(
  3976. 1, 0, 0, 0,
  3977. 0, c, - s, 0,
  3978. 0, s, c, 0,
  3979. 0, 0, 0, 1
  3980. );
  3981. return this;
  3982. }
  3983. makeRotationY( theta ) {
  3984. const c = Math.cos( theta ), s = Math.sin( theta );
  3985. this.set(
  3986. c, 0, s, 0,
  3987. 0, 1, 0, 0,
  3988. - s, 0, c, 0,
  3989. 0, 0, 0, 1
  3990. );
  3991. return this;
  3992. }
  3993. makeRotationZ( theta ) {
  3994. const c = Math.cos( theta ), s = Math.sin( theta );
  3995. this.set(
  3996. c, - s, 0, 0,
  3997. s, c, 0, 0,
  3998. 0, 0, 1, 0,
  3999. 0, 0, 0, 1
  4000. );
  4001. return this;
  4002. }
  4003. makeRotationAxis( axis, angle ) {
  4004. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  4005. const c = Math.cos( angle );
  4006. const s = Math.sin( angle );
  4007. const t = 1 - c;
  4008. const x = axis.x, y = axis.y, z = axis.z;
  4009. const tx = t * x, ty = t * y;
  4010. this.set(
  4011. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  4012. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  4013. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  4014. 0, 0, 0, 1
  4015. );
  4016. return this;
  4017. }
  4018. makeScale( x, y, z ) {
  4019. this.set(
  4020. x, 0, 0, 0,
  4021. 0, y, 0, 0,
  4022. 0, 0, z, 0,
  4023. 0, 0, 0, 1
  4024. );
  4025. return this;
  4026. }
  4027. makeShear( xy, xz, yx, yz, zx, zy ) {
  4028. this.set(
  4029. 1, yx, zx, 0,
  4030. xy, 1, zy, 0,
  4031. xz, yz, 1, 0,
  4032. 0, 0, 0, 1
  4033. );
  4034. return this;
  4035. }
  4036. compose( position, quaternion, scale ) {
  4037. const te = this.elements;
  4038. const x = quaternion._x, y = quaternion._y, z = quaternion._z, w = quaternion._w;
  4039. const x2 = x + x, y2 = y + y, z2 = z + z;
  4040. const xx = x * x2, xy = x * y2, xz = x * z2;
  4041. const yy = y * y2, yz = y * z2, zz = z * z2;
  4042. const wx = w * x2, wy = w * y2, wz = w * z2;
  4043. const sx = scale.x, sy = scale.y, sz = scale.z;
  4044. te[ 0 ] = ( 1 - ( yy + zz ) ) * sx;
  4045. te[ 1 ] = ( xy + wz ) * sx;
  4046. te[ 2 ] = ( xz - wy ) * sx;
  4047. te[ 3 ] = 0;
  4048. te[ 4 ] = ( xy - wz ) * sy;
  4049. te[ 5 ] = ( 1 - ( xx + zz ) ) * sy;
  4050. te[ 6 ] = ( yz + wx ) * sy;
  4051. te[ 7 ] = 0;
  4052. te[ 8 ] = ( xz + wy ) * sz;
  4053. te[ 9 ] = ( yz - wx ) * sz;
  4054. te[ 10 ] = ( 1 - ( xx + yy ) ) * sz;
  4055. te[ 11 ] = 0;
  4056. te[ 12 ] = position.x;
  4057. te[ 13 ] = position.y;
  4058. te[ 14 ] = position.z;
  4059. te[ 15 ] = 1;
  4060. return this;
  4061. }
  4062. decompose( position, quaternion, scale ) {
  4063. const te = this.elements;
  4064. let sx = _v1$5.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  4065. const sy = _v1$5.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  4066. const sz = _v1$5.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  4067. // if determine is negative, we need to invert one scale
  4068. const det = this.determinant();
  4069. if ( det < 0 ) sx = - sx;
  4070. position.x = te[ 12 ];
  4071. position.y = te[ 13 ];
  4072. position.z = te[ 14 ];
  4073. // scale the rotation part
  4074. _m1$2.copy( this );
  4075. const invSX = 1 / sx;
  4076. const invSY = 1 / sy;
  4077. const invSZ = 1 / sz;
  4078. _m1$2.elements[ 0 ] *= invSX;
  4079. _m1$2.elements[ 1 ] *= invSX;
  4080. _m1$2.elements[ 2 ] *= invSX;
  4081. _m1$2.elements[ 4 ] *= invSY;
  4082. _m1$2.elements[ 5 ] *= invSY;
  4083. _m1$2.elements[ 6 ] *= invSY;
  4084. _m1$2.elements[ 8 ] *= invSZ;
  4085. _m1$2.elements[ 9 ] *= invSZ;
  4086. _m1$2.elements[ 10 ] *= invSZ;
  4087. quaternion.setFromRotationMatrix( _m1$2 );
  4088. scale.x = sx;
  4089. scale.y = sy;
  4090. scale.z = sz;
  4091. return this;
  4092. }
  4093. makePerspective( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4094. const te = this.elements;
  4095. const x = 2 * near / ( right - left );
  4096. const y = 2 * near / ( top - bottom );
  4097. const a = ( right + left ) / ( right - left );
  4098. const b = ( top + bottom ) / ( top - bottom );
  4099. let c, d;
  4100. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4101. c = - ( far + near ) / ( far - near );
  4102. d = ( - 2 * far * near ) / ( far - near );
  4103. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4104. c = - far / ( far - near );
  4105. d = ( - far * near ) / ( far - near );
  4106. } else {
  4107. throw new Error( 'THREE.Matrix4.makePerspective(): Invalid coordinate system: ' + coordinateSystem );
  4108. }
  4109. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  4110. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  4111. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  4112. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  4113. return this;
  4114. }
  4115. makeOrthographic( left, right, top, bottom, near, far, coordinateSystem = WebGLCoordinateSystem ) {
  4116. const te = this.elements;
  4117. const w = 1.0 / ( right - left );
  4118. const h = 1.0 / ( top - bottom );
  4119. const p = 1.0 / ( far - near );
  4120. const x = ( right + left ) * w;
  4121. const y = ( top + bottom ) * h;
  4122. let z, zInv;
  4123. if ( coordinateSystem === WebGLCoordinateSystem ) {
  4124. z = ( far + near ) * p;
  4125. zInv = - 2 * p;
  4126. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  4127. z = near * p;
  4128. zInv = - 1 * p;
  4129. } else {
  4130. throw new Error( 'THREE.Matrix4.makeOrthographic(): Invalid coordinate system: ' + coordinateSystem );
  4131. }
  4132. te[ 0 ] = 2 * w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  4133. te[ 1 ] = 0; te[ 5 ] = 2 * h; te[ 9 ] = 0; te[ 13 ] = - y;
  4134. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = zInv; te[ 14 ] = - z;
  4135. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  4136. return this;
  4137. }
  4138. equals( matrix ) {
  4139. const te = this.elements;
  4140. const me = matrix.elements;
  4141. for ( let i = 0; i < 16; i ++ ) {
  4142. if ( te[ i ] !== me[ i ] ) return false;
  4143. }
  4144. return true;
  4145. }
  4146. fromArray( array, offset = 0 ) {
  4147. for ( let i = 0; i < 16; i ++ ) {
  4148. this.elements[ i ] = array[ i + offset ];
  4149. }
  4150. return this;
  4151. }
  4152. toArray( array = [], offset = 0 ) {
  4153. const te = this.elements;
  4154. array[ offset ] = te[ 0 ];
  4155. array[ offset + 1 ] = te[ 1 ];
  4156. array[ offset + 2 ] = te[ 2 ];
  4157. array[ offset + 3 ] = te[ 3 ];
  4158. array[ offset + 4 ] = te[ 4 ];
  4159. array[ offset + 5 ] = te[ 5 ];
  4160. array[ offset + 6 ] = te[ 6 ];
  4161. array[ offset + 7 ] = te[ 7 ];
  4162. array[ offset + 8 ] = te[ 8 ];
  4163. array[ offset + 9 ] = te[ 9 ];
  4164. array[ offset + 10 ] = te[ 10 ];
  4165. array[ offset + 11 ] = te[ 11 ];
  4166. array[ offset + 12 ] = te[ 12 ];
  4167. array[ offset + 13 ] = te[ 13 ];
  4168. array[ offset + 14 ] = te[ 14 ];
  4169. array[ offset + 15 ] = te[ 15 ];
  4170. return array;
  4171. }
  4172. }
  4173. const _v1$5 = /*@__PURE__*/ new Vector3();
  4174. const _m1$2 = /*@__PURE__*/ new Matrix4();
  4175. const _zero = /*@__PURE__*/ new Vector3( 0, 0, 0 );
  4176. const _one = /*@__PURE__*/ new Vector3( 1, 1, 1 );
  4177. const _x = /*@__PURE__*/ new Vector3();
  4178. const _y = /*@__PURE__*/ new Vector3();
  4179. const _z = /*@__PURE__*/ new Vector3();
  4180. const _matrix$2 = /*@__PURE__*/ new Matrix4();
  4181. const _quaternion$3 = /*@__PURE__*/ new Quaternion();
  4182. class Euler {
  4183. constructor( x = 0, y = 0, z = 0, order = Euler.DEFAULT_ORDER ) {
  4184. this.isEuler = true;
  4185. this._x = x;
  4186. this._y = y;
  4187. this._z = z;
  4188. this._order = order;
  4189. }
  4190. get x() {
  4191. return this._x;
  4192. }
  4193. set x( value ) {
  4194. this._x = value;
  4195. this._onChangeCallback();
  4196. }
  4197. get y() {
  4198. return this._y;
  4199. }
  4200. set y( value ) {
  4201. this._y = value;
  4202. this._onChangeCallback();
  4203. }
  4204. get z() {
  4205. return this._z;
  4206. }
  4207. set z( value ) {
  4208. this._z = value;
  4209. this._onChangeCallback();
  4210. }
  4211. get order() {
  4212. return this._order;
  4213. }
  4214. set order( value ) {
  4215. this._order = value;
  4216. this._onChangeCallback();
  4217. }
  4218. set( x, y, z, order = this._order ) {
  4219. this._x = x;
  4220. this._y = y;
  4221. this._z = z;
  4222. this._order = order;
  4223. this._onChangeCallback();
  4224. return this;
  4225. }
  4226. clone() {
  4227. return new this.constructor( this._x, this._y, this._z, this._order );
  4228. }
  4229. copy( euler ) {
  4230. this._x = euler._x;
  4231. this._y = euler._y;
  4232. this._z = euler._z;
  4233. this._order = euler._order;
  4234. this._onChangeCallback();
  4235. return this;
  4236. }
  4237. setFromRotationMatrix( m, order = this._order, update = true ) {
  4238. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4239. const te = m.elements;
  4240. const m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  4241. const m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  4242. const m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  4243. switch ( order ) {
  4244. case 'XYZ':
  4245. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  4246. if ( Math.abs( m13 ) < 0.9999999 ) {
  4247. this._x = Math.atan2( - m23, m33 );
  4248. this._z = Math.atan2( - m12, m11 );
  4249. } else {
  4250. this._x = Math.atan2( m32, m22 );
  4251. this._z = 0;
  4252. }
  4253. break;
  4254. case 'YXZ':
  4255. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  4256. if ( Math.abs( m23 ) < 0.9999999 ) {
  4257. this._y = Math.atan2( m13, m33 );
  4258. this._z = Math.atan2( m21, m22 );
  4259. } else {
  4260. this._y = Math.atan2( - m31, m11 );
  4261. this._z = 0;
  4262. }
  4263. break;
  4264. case 'ZXY':
  4265. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  4266. if ( Math.abs( m32 ) < 0.9999999 ) {
  4267. this._y = Math.atan2( - m31, m33 );
  4268. this._z = Math.atan2( - m12, m22 );
  4269. } else {
  4270. this._y = 0;
  4271. this._z = Math.atan2( m21, m11 );
  4272. }
  4273. break;
  4274. case 'ZYX':
  4275. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  4276. if ( Math.abs( m31 ) < 0.9999999 ) {
  4277. this._x = Math.atan2( m32, m33 );
  4278. this._z = Math.atan2( m21, m11 );
  4279. } else {
  4280. this._x = 0;
  4281. this._z = Math.atan2( - m12, m22 );
  4282. }
  4283. break;
  4284. case 'YZX':
  4285. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  4286. if ( Math.abs( m21 ) < 0.9999999 ) {
  4287. this._x = Math.atan2( - m23, m22 );
  4288. this._y = Math.atan2( - m31, m11 );
  4289. } else {
  4290. this._x = 0;
  4291. this._y = Math.atan2( m13, m33 );
  4292. }
  4293. break;
  4294. case 'XZY':
  4295. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  4296. if ( Math.abs( m12 ) < 0.9999999 ) {
  4297. this._x = Math.atan2( m32, m22 );
  4298. this._y = Math.atan2( m13, m11 );
  4299. } else {
  4300. this._x = Math.atan2( - m23, m33 );
  4301. this._y = 0;
  4302. }
  4303. break;
  4304. default:
  4305. console.warn( 'THREE.Euler: .setFromRotationMatrix() encountered an unknown order: ' + order );
  4306. }
  4307. this._order = order;
  4308. if ( update === true ) this._onChangeCallback();
  4309. return this;
  4310. }
  4311. setFromQuaternion( q, order, update ) {
  4312. _matrix$2.makeRotationFromQuaternion( q );
  4313. return this.setFromRotationMatrix( _matrix$2, order, update );
  4314. }
  4315. setFromVector3( v, order = this._order ) {
  4316. return this.set( v.x, v.y, v.z, order );
  4317. }
  4318. reorder( newOrder ) {
  4319. // WARNING: this discards revolution information -bhouston
  4320. _quaternion$3.setFromEuler( this );
  4321. return this.setFromQuaternion( _quaternion$3, newOrder );
  4322. }
  4323. equals( euler ) {
  4324. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  4325. }
  4326. fromArray( array ) {
  4327. this._x = array[ 0 ];
  4328. this._y = array[ 1 ];
  4329. this._z = array[ 2 ];
  4330. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  4331. this._onChangeCallback();
  4332. return this;
  4333. }
  4334. toArray( array = [], offset = 0 ) {
  4335. array[ offset ] = this._x;
  4336. array[ offset + 1 ] = this._y;
  4337. array[ offset + 2 ] = this._z;
  4338. array[ offset + 3 ] = this._order;
  4339. return array;
  4340. }
  4341. _onChange( callback ) {
  4342. this._onChangeCallback = callback;
  4343. return this;
  4344. }
  4345. _onChangeCallback() {}
  4346. *[ Symbol.iterator ]() {
  4347. yield this._x;
  4348. yield this._y;
  4349. yield this._z;
  4350. yield this._order;
  4351. }
  4352. }
  4353. Euler.DEFAULT_ORDER = 'XYZ';
  4354. class Layers {
  4355. constructor() {
  4356. this.mask = 1 | 0;
  4357. }
  4358. set( channel ) {
  4359. this.mask = ( 1 << channel | 0 ) >>> 0;
  4360. }
  4361. enable( channel ) {
  4362. this.mask |= 1 << channel | 0;
  4363. }
  4364. enableAll() {
  4365. this.mask = 0xffffffff | 0;
  4366. }
  4367. toggle( channel ) {
  4368. this.mask ^= 1 << channel | 0;
  4369. }
  4370. disable( channel ) {
  4371. this.mask &= ~ ( 1 << channel | 0 );
  4372. }
  4373. disableAll() {
  4374. this.mask = 0;
  4375. }
  4376. test( layers ) {
  4377. return ( this.mask & layers.mask ) !== 0;
  4378. }
  4379. isEnabled( channel ) {
  4380. return ( this.mask & ( 1 << channel | 0 ) ) !== 0;
  4381. }
  4382. }
  4383. let _object3DId = 0;
  4384. const _v1$4 = /*@__PURE__*/ new Vector3();
  4385. const _q1 = /*@__PURE__*/ new Quaternion();
  4386. const _m1$1 = /*@__PURE__*/ new Matrix4();
  4387. const _target = /*@__PURE__*/ new Vector3();
  4388. const _position$3 = /*@__PURE__*/ new Vector3();
  4389. const _scale$2 = /*@__PURE__*/ new Vector3();
  4390. const _quaternion$2 = /*@__PURE__*/ new Quaternion();
  4391. const _xAxis = /*@__PURE__*/ new Vector3( 1, 0, 0 );
  4392. const _yAxis = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4393. const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
  4394. const _addedEvent = { type: 'added' };
  4395. const _removedEvent = { type: 'removed' };
  4396. const _childaddedEvent = { type: 'childadded', child: null };
  4397. const _childremovedEvent = { type: 'childremoved', child: null };
  4398. class Object3D extends EventDispatcher {
  4399. constructor() {
  4400. super();
  4401. this.isObject3D = true;
  4402. Object.defineProperty( this, 'id', { value: _object3DId ++ } );
  4403. this.uuid = generateUUID();
  4404. this.name = '';
  4405. this.type = 'Object3D';
  4406. this.parent = null;
  4407. this.children = [];
  4408. this.up = Object3D.DEFAULT_UP.clone();
  4409. const position = new Vector3();
  4410. const rotation = new Euler();
  4411. const quaternion = new Quaternion();
  4412. const scale = new Vector3( 1, 1, 1 );
  4413. function onRotationChange() {
  4414. quaternion.setFromEuler( rotation, false );
  4415. }
  4416. function onQuaternionChange() {
  4417. rotation.setFromQuaternion( quaternion, undefined, false );
  4418. }
  4419. rotation._onChange( onRotationChange );
  4420. quaternion._onChange( onQuaternionChange );
  4421. Object.defineProperties( this, {
  4422. position: {
  4423. configurable: true,
  4424. enumerable: true,
  4425. value: position
  4426. },
  4427. rotation: {
  4428. configurable: true,
  4429. enumerable: true,
  4430. value: rotation
  4431. },
  4432. quaternion: {
  4433. configurable: true,
  4434. enumerable: true,
  4435. value: quaternion
  4436. },
  4437. scale: {
  4438. configurable: true,
  4439. enumerable: true,
  4440. value: scale
  4441. },
  4442. modelViewMatrix: {
  4443. value: new Matrix4()
  4444. },
  4445. normalMatrix: {
  4446. value: new Matrix3()
  4447. }
  4448. } );
  4449. this.matrix = new Matrix4();
  4450. this.matrixWorld = new Matrix4();
  4451. this.matrixAutoUpdate = Object3D.DEFAULT_MATRIX_AUTO_UPDATE;
  4452. this.matrixWorldAutoUpdate = Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE; // checked by the renderer
  4453. this.matrixWorldNeedsUpdate = false;
  4454. this.layers = new Layers();
  4455. this.visible = true;
  4456. this.castShadow = false;
  4457. this.receiveShadow = false;
  4458. this.frustumCulled = true;
  4459. this.renderOrder = 0;
  4460. this.animations = [];
  4461. this.userData = {};
  4462. }
  4463. onBeforeShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4464. onAfterShadow( /* renderer, object, camera, shadowCamera, geometry, depthMaterial, group */ ) {}
  4465. onBeforeRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4466. onAfterRender( /* renderer, scene, camera, geometry, material, group */ ) {}
  4467. applyMatrix4( matrix ) {
  4468. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4469. this.matrix.premultiply( matrix );
  4470. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4471. }
  4472. applyQuaternion( q ) {
  4473. this.quaternion.premultiply( q );
  4474. return this;
  4475. }
  4476. setRotationFromAxisAngle( axis, angle ) {
  4477. // assumes axis is normalized
  4478. this.quaternion.setFromAxisAngle( axis, angle );
  4479. }
  4480. setRotationFromEuler( euler ) {
  4481. this.quaternion.setFromEuler( euler, true );
  4482. }
  4483. setRotationFromMatrix( m ) {
  4484. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4485. this.quaternion.setFromRotationMatrix( m );
  4486. }
  4487. setRotationFromQuaternion( q ) {
  4488. // assumes q is normalized
  4489. this.quaternion.copy( q );
  4490. }
  4491. rotateOnAxis( axis, angle ) {
  4492. // rotate object on axis in object space
  4493. // axis is assumed to be normalized
  4494. _q1.setFromAxisAngle( axis, angle );
  4495. this.quaternion.multiply( _q1 );
  4496. return this;
  4497. }
  4498. rotateOnWorldAxis( axis, angle ) {
  4499. // rotate object on axis in world space
  4500. // axis is assumed to be normalized
  4501. // method assumes no rotated parent
  4502. _q1.setFromAxisAngle( axis, angle );
  4503. this.quaternion.premultiply( _q1 );
  4504. return this;
  4505. }
  4506. rotateX( angle ) {
  4507. return this.rotateOnAxis( _xAxis, angle );
  4508. }
  4509. rotateY( angle ) {
  4510. return this.rotateOnAxis( _yAxis, angle );
  4511. }
  4512. rotateZ( angle ) {
  4513. return this.rotateOnAxis( _zAxis, angle );
  4514. }
  4515. translateOnAxis( axis, distance ) {
  4516. // translate object by distance along axis in object space
  4517. // axis is assumed to be normalized
  4518. _v1$4.copy( axis ).applyQuaternion( this.quaternion );
  4519. this.position.add( _v1$4.multiplyScalar( distance ) );
  4520. return this;
  4521. }
  4522. translateX( distance ) {
  4523. return this.translateOnAxis( _xAxis, distance );
  4524. }
  4525. translateY( distance ) {
  4526. return this.translateOnAxis( _yAxis, distance );
  4527. }
  4528. translateZ( distance ) {
  4529. return this.translateOnAxis( _zAxis, distance );
  4530. }
  4531. localToWorld( vector ) {
  4532. this.updateWorldMatrix( true, false );
  4533. return vector.applyMatrix4( this.matrixWorld );
  4534. }
  4535. worldToLocal( vector ) {
  4536. this.updateWorldMatrix( true, false );
  4537. return vector.applyMatrix4( _m1$1.copy( this.matrixWorld ).invert() );
  4538. }
  4539. lookAt( x, y, z ) {
  4540. // This method does not support objects having non-uniformly-scaled parent(s)
  4541. if ( x.isVector3 ) {
  4542. _target.copy( x );
  4543. } else {
  4544. _target.set( x, y, z );
  4545. }
  4546. const parent = this.parent;
  4547. this.updateWorldMatrix( true, false );
  4548. _position$3.setFromMatrixPosition( this.matrixWorld );
  4549. if ( this.isCamera || this.isLight ) {
  4550. _m1$1.lookAt( _position$3, _target, this.up );
  4551. } else {
  4552. _m1$1.lookAt( _target, _position$3, this.up );
  4553. }
  4554. this.quaternion.setFromRotationMatrix( _m1$1 );
  4555. if ( parent ) {
  4556. _m1$1.extractRotation( parent.matrixWorld );
  4557. _q1.setFromRotationMatrix( _m1$1 );
  4558. this.quaternion.premultiply( _q1.invert() );
  4559. }
  4560. }
  4561. add( object ) {
  4562. if ( arguments.length > 1 ) {
  4563. for ( let i = 0; i < arguments.length; i ++ ) {
  4564. this.add( arguments[ i ] );
  4565. }
  4566. return this;
  4567. }
  4568. if ( object === this ) {
  4569. console.error( 'THREE.Object3D.add: object can\'t be added as a child of itself.', object );
  4570. return this;
  4571. }
  4572. if ( object && object.isObject3D ) {
  4573. object.removeFromParent();
  4574. object.parent = this;
  4575. this.children.push( object );
  4576. object.dispatchEvent( _addedEvent );
  4577. _childaddedEvent.child = object;
  4578. this.dispatchEvent( _childaddedEvent );
  4579. _childaddedEvent.child = null;
  4580. } else {
  4581. console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
  4582. }
  4583. return this;
  4584. }
  4585. remove( object ) {
  4586. if ( arguments.length > 1 ) {
  4587. for ( let i = 0; i < arguments.length; i ++ ) {
  4588. this.remove( arguments[ i ] );
  4589. }
  4590. return this;
  4591. }
  4592. const index = this.children.indexOf( object );
  4593. if ( index !== - 1 ) {
  4594. object.parent = null;
  4595. this.children.splice( index, 1 );
  4596. object.dispatchEvent( _removedEvent );
  4597. _childremovedEvent.child = object;
  4598. this.dispatchEvent( _childremovedEvent );
  4599. _childremovedEvent.child = null;
  4600. }
  4601. return this;
  4602. }
  4603. removeFromParent() {
  4604. const parent = this.parent;
  4605. if ( parent !== null ) {
  4606. parent.remove( this );
  4607. }
  4608. return this;
  4609. }
  4610. clear() {
  4611. return this.remove( ... this.children );
  4612. }
  4613. attach( object ) {
  4614. // adds object as a child of this, while maintaining the object's world transform
  4615. // Note: This method does not support scene graphs having non-uniformly-scaled nodes(s)
  4616. this.updateWorldMatrix( true, false );
  4617. _m1$1.copy( this.matrixWorld ).invert();
  4618. if ( object.parent !== null ) {
  4619. object.parent.updateWorldMatrix( true, false );
  4620. _m1$1.multiply( object.parent.matrixWorld );
  4621. }
  4622. object.applyMatrix4( _m1$1 );
  4623. object.removeFromParent();
  4624. object.parent = this;
  4625. this.children.push( object );
  4626. object.updateWorldMatrix( false, true );
  4627. object.dispatchEvent( _addedEvent );
  4628. _childaddedEvent.child = object;
  4629. this.dispatchEvent( _childaddedEvent );
  4630. _childaddedEvent.child = null;
  4631. return this;
  4632. }
  4633. getObjectById( id ) {
  4634. return this.getObjectByProperty( 'id', id );
  4635. }
  4636. getObjectByName( name ) {
  4637. return this.getObjectByProperty( 'name', name );
  4638. }
  4639. getObjectByProperty( name, value ) {
  4640. if ( this[ name ] === value ) return this;
  4641. for ( let i = 0, l = this.children.length; i < l; i ++ ) {
  4642. const child = this.children[ i ];
  4643. const object = child.getObjectByProperty( name, value );
  4644. if ( object !== undefined ) {
  4645. return object;
  4646. }
  4647. }
  4648. return undefined;
  4649. }
  4650. getObjectsByProperty( name, value, result = [] ) {
  4651. if ( this[ name ] === value ) result.push( this );
  4652. const children = this.children;
  4653. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4654. children[ i ].getObjectsByProperty( name, value, result );
  4655. }
  4656. return result;
  4657. }
  4658. getWorldPosition( target ) {
  4659. this.updateWorldMatrix( true, false );
  4660. return target.setFromMatrixPosition( this.matrixWorld );
  4661. }
  4662. getWorldQuaternion( target ) {
  4663. this.updateWorldMatrix( true, false );
  4664. this.matrixWorld.decompose( _position$3, target, _scale$2 );
  4665. return target;
  4666. }
  4667. getWorldScale( target ) {
  4668. this.updateWorldMatrix( true, false );
  4669. this.matrixWorld.decompose( _position$3, _quaternion$2, target );
  4670. return target;
  4671. }
  4672. getWorldDirection( target ) {
  4673. this.updateWorldMatrix( true, false );
  4674. const e = this.matrixWorld.elements;
  4675. return target.set( e[ 8 ], e[ 9 ], e[ 10 ] ).normalize();
  4676. }
  4677. raycast( /* raycaster, intersects */ ) {}
  4678. traverse( callback ) {
  4679. callback( this );
  4680. const children = this.children;
  4681. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4682. children[ i ].traverse( callback );
  4683. }
  4684. }
  4685. traverseVisible( callback ) {
  4686. if ( this.visible === false ) return;
  4687. callback( this );
  4688. const children = this.children;
  4689. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4690. children[ i ].traverseVisible( callback );
  4691. }
  4692. }
  4693. traverseAncestors( callback ) {
  4694. const parent = this.parent;
  4695. if ( parent !== null ) {
  4696. callback( parent );
  4697. parent.traverseAncestors( callback );
  4698. }
  4699. }
  4700. updateMatrix() {
  4701. this.matrix.compose( this.position, this.quaternion, this.scale );
  4702. this.matrixWorldNeedsUpdate = true;
  4703. }
  4704. updateMatrixWorld( force ) {
  4705. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4706. if ( this.matrixWorldNeedsUpdate || force ) {
  4707. if ( this.matrixWorldAutoUpdate === true ) {
  4708. if ( this.parent === null ) {
  4709. this.matrixWorld.copy( this.matrix );
  4710. } else {
  4711. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4712. }
  4713. }
  4714. this.matrixWorldNeedsUpdate = false;
  4715. force = true;
  4716. }
  4717. // make sure descendants are updated if required
  4718. const children = this.children;
  4719. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4720. const child = children[ i ];
  4721. child.updateMatrixWorld( force );
  4722. }
  4723. }
  4724. updateWorldMatrix( updateParents, updateChildren ) {
  4725. const parent = this.parent;
  4726. if ( updateParents === true && parent !== null ) {
  4727. parent.updateWorldMatrix( true, false );
  4728. }
  4729. if ( this.matrixAutoUpdate ) this.updateMatrix();
  4730. if ( this.matrixWorldAutoUpdate === true ) {
  4731. if ( this.parent === null ) {
  4732. this.matrixWorld.copy( this.matrix );
  4733. } else {
  4734. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4735. }
  4736. }
  4737. // make sure descendants are updated
  4738. if ( updateChildren === true ) {
  4739. const children = this.children;
  4740. for ( let i = 0, l = children.length; i < l; i ++ ) {
  4741. const child = children[ i ];
  4742. child.updateWorldMatrix( false, true );
  4743. }
  4744. }
  4745. }
  4746. toJSON( meta ) {
  4747. // meta is a string when called from JSON.stringify
  4748. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  4749. const output = {};
  4750. // meta is a hash used to collect geometries, materials.
  4751. // not providing it implies that this is the root object
  4752. // being serialized.
  4753. if ( isRootObject ) {
  4754. // initialize meta obj
  4755. meta = {
  4756. geometries: {},
  4757. materials: {},
  4758. textures: {},
  4759. images: {},
  4760. shapes: {},
  4761. skeletons: {},
  4762. animations: {},
  4763. nodes: {}
  4764. };
  4765. output.metadata = {
  4766. version: 4.6,
  4767. type: 'Object',
  4768. generator: 'Object3D.toJSON'
  4769. };
  4770. }
  4771. // standard Object3D serialization
  4772. const object = {};
  4773. object.uuid = this.uuid;
  4774. object.type = this.type;
  4775. if ( this.name !== '' ) object.name = this.name;
  4776. if ( this.castShadow === true ) object.castShadow = true;
  4777. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4778. if ( this.visible === false ) object.visible = false;
  4779. if ( this.frustumCulled === false ) object.frustumCulled = false;
  4780. if ( this.renderOrder !== 0 ) object.renderOrder = this.renderOrder;
  4781. if ( Object.keys( this.userData ).length > 0 ) object.userData = this.userData;
  4782. object.layers = this.layers.mask;
  4783. object.matrix = this.matrix.toArray();
  4784. object.up = this.up.toArray();
  4785. if ( this.matrixAutoUpdate === false ) object.matrixAutoUpdate = false;
  4786. // object specific properties
  4787. if ( this.isInstancedMesh ) {
  4788. object.type = 'InstancedMesh';
  4789. object.count = this.count;
  4790. object.instanceMatrix = this.instanceMatrix.toJSON();
  4791. if ( this.instanceColor !== null ) object.instanceColor = this.instanceColor.toJSON();
  4792. }
  4793. if ( this.isBatchedMesh ) {
  4794. object.type = 'BatchedMesh';
  4795. object.perObjectFrustumCulled = this.perObjectFrustumCulled;
  4796. object.sortObjects = this.sortObjects;
  4797. object.drawRanges = this._drawRanges;
  4798. object.reservedRanges = this._reservedRanges;
  4799. object.visibility = this._visibility;
  4800. object.active = this._active;
  4801. object.bounds = this._bounds.map( bound => ( {
  4802. boxInitialized: bound.boxInitialized,
  4803. boxMin: bound.box.min.toArray(),
  4804. boxMax: bound.box.max.toArray(),
  4805. sphereInitialized: bound.sphereInitialized,
  4806. sphereRadius: bound.sphere.radius,
  4807. sphereCenter: bound.sphere.center.toArray()
  4808. } ) );
  4809. object.maxInstanceCount = this._maxInstanceCount;
  4810. object.maxVertexCount = this._maxVertexCount;
  4811. object.maxIndexCount = this._maxIndexCount;
  4812. object.geometryInitialized = this._geometryInitialized;
  4813. object.geometryCount = this._geometryCount;
  4814. object.matricesTexture = this._matricesTexture.toJSON( meta );
  4815. if ( this._colorsTexture !== null ) object.colorsTexture = this._colorsTexture.toJSON( meta );
  4816. if ( this.boundingSphere !== null ) {
  4817. object.boundingSphere = {
  4818. center: object.boundingSphere.center.toArray(),
  4819. radius: object.boundingSphere.radius
  4820. };
  4821. }
  4822. if ( this.boundingBox !== null ) {
  4823. object.boundingBox = {
  4824. min: object.boundingBox.min.toArray(),
  4825. max: object.boundingBox.max.toArray()
  4826. };
  4827. }
  4828. }
  4829. //
  4830. function serialize( library, element ) {
  4831. if ( library[ element.uuid ] === undefined ) {
  4832. library[ element.uuid ] = element.toJSON( meta );
  4833. }
  4834. return element.uuid;
  4835. }
  4836. if ( this.isScene ) {
  4837. if ( this.background ) {
  4838. if ( this.background.isColor ) {
  4839. object.background = this.background.toJSON();
  4840. } else if ( this.background.isTexture ) {
  4841. object.background = this.background.toJSON( meta ).uuid;
  4842. }
  4843. }
  4844. if ( this.environment && this.environment.isTexture && this.environment.isRenderTargetTexture !== true ) {
  4845. object.environment = this.environment.toJSON( meta ).uuid;
  4846. }
  4847. } else if ( this.isMesh || this.isLine || this.isPoints ) {
  4848. object.geometry = serialize( meta.geometries, this.geometry );
  4849. const parameters = this.geometry.parameters;
  4850. if ( parameters !== undefined && parameters.shapes !== undefined ) {
  4851. const shapes = parameters.shapes;
  4852. if ( Array.isArray( shapes ) ) {
  4853. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  4854. const shape = shapes[ i ];
  4855. serialize( meta.shapes, shape );
  4856. }
  4857. } else {
  4858. serialize( meta.shapes, shapes );
  4859. }
  4860. }
  4861. }
  4862. if ( this.isSkinnedMesh ) {
  4863. object.bindMode = this.bindMode;
  4864. object.bindMatrix = this.bindMatrix.toArray();
  4865. if ( this.skeleton !== undefined ) {
  4866. serialize( meta.skeletons, this.skeleton );
  4867. object.skeleton = this.skeleton.uuid;
  4868. }
  4869. }
  4870. if ( this.material !== undefined ) {
  4871. if ( Array.isArray( this.material ) ) {
  4872. const uuids = [];
  4873. for ( let i = 0, l = this.material.length; i < l; i ++ ) {
  4874. uuids.push( serialize( meta.materials, this.material[ i ] ) );
  4875. }
  4876. object.material = uuids;
  4877. } else {
  4878. object.material = serialize( meta.materials, this.material );
  4879. }
  4880. }
  4881. //
  4882. if ( this.children.length > 0 ) {
  4883. object.children = [];
  4884. for ( let i = 0; i < this.children.length; i ++ ) {
  4885. object.children.push( this.children[ i ].toJSON( meta ).object );
  4886. }
  4887. }
  4888. //
  4889. if ( this.animations.length > 0 ) {
  4890. object.animations = [];
  4891. for ( let i = 0; i < this.animations.length; i ++ ) {
  4892. const animation = this.animations[ i ];
  4893. object.animations.push( serialize( meta.animations, animation ) );
  4894. }
  4895. }
  4896. if ( isRootObject ) {
  4897. const geometries = extractFromCache( meta.geometries );
  4898. const materials = extractFromCache( meta.materials );
  4899. const textures = extractFromCache( meta.textures );
  4900. const images = extractFromCache( meta.images );
  4901. const shapes = extractFromCache( meta.shapes );
  4902. const skeletons = extractFromCache( meta.skeletons );
  4903. const animations = extractFromCache( meta.animations );
  4904. const nodes = extractFromCache( meta.nodes );
  4905. if ( geometries.length > 0 ) output.geometries = geometries;
  4906. if ( materials.length > 0 ) output.materials = materials;
  4907. if ( textures.length > 0 ) output.textures = textures;
  4908. if ( images.length > 0 ) output.images = images;
  4909. if ( shapes.length > 0 ) output.shapes = shapes;
  4910. if ( skeletons.length > 0 ) output.skeletons = skeletons;
  4911. if ( animations.length > 0 ) output.animations = animations;
  4912. if ( nodes.length > 0 ) output.nodes = nodes;
  4913. }
  4914. output.object = object;
  4915. return output;
  4916. // extract data from the cache hash
  4917. // remove metadata on each item
  4918. // and return as array
  4919. function extractFromCache( cache ) {
  4920. const values = [];
  4921. for ( const key in cache ) {
  4922. const data = cache[ key ];
  4923. delete data.metadata;
  4924. values.push( data );
  4925. }
  4926. return values;
  4927. }
  4928. }
  4929. clone( recursive ) {
  4930. return new this.constructor().copy( this, recursive );
  4931. }
  4932. copy( source, recursive = true ) {
  4933. this.name = source.name;
  4934. this.up.copy( source.up );
  4935. this.position.copy( source.position );
  4936. this.rotation.order = source.rotation.order;
  4937. this.quaternion.copy( source.quaternion );
  4938. this.scale.copy( source.scale );
  4939. this.matrix.copy( source.matrix );
  4940. this.matrixWorld.copy( source.matrixWorld );
  4941. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4942. this.matrixWorldAutoUpdate = source.matrixWorldAutoUpdate;
  4943. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4944. this.layers.mask = source.layers.mask;
  4945. this.visible = source.visible;
  4946. this.castShadow = source.castShadow;
  4947. this.receiveShadow = source.receiveShadow;
  4948. this.frustumCulled = source.frustumCulled;
  4949. this.renderOrder = source.renderOrder;
  4950. this.animations = source.animations.slice();
  4951. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4952. if ( recursive === true ) {
  4953. for ( let i = 0; i < source.children.length; i ++ ) {
  4954. const child = source.children[ i ];
  4955. this.add( child.clone() );
  4956. }
  4957. }
  4958. return this;
  4959. }
  4960. }
  4961. Object3D.DEFAULT_UP = /*@__PURE__*/ new Vector3( 0, 1, 0 );
  4962. Object3D.DEFAULT_MATRIX_AUTO_UPDATE = true;
  4963. Object3D.DEFAULT_MATRIX_WORLD_AUTO_UPDATE = true;
  4964. const _v0$1 = /*@__PURE__*/ new Vector3();
  4965. const _v1$3 = /*@__PURE__*/ new Vector3();
  4966. const _v2$2 = /*@__PURE__*/ new Vector3();
  4967. const _v3$2 = /*@__PURE__*/ new Vector3();
  4968. const _vab = /*@__PURE__*/ new Vector3();
  4969. const _vac = /*@__PURE__*/ new Vector3();
  4970. const _vbc = /*@__PURE__*/ new Vector3();
  4971. const _vap = /*@__PURE__*/ new Vector3();
  4972. const _vbp = /*@__PURE__*/ new Vector3();
  4973. const _vcp = /*@__PURE__*/ new Vector3();
  4974. const _v40 = /*@__PURE__*/ new Vector4();
  4975. const _v41 = /*@__PURE__*/ new Vector4();
  4976. const _v42 = /*@__PURE__*/ new Vector4();
  4977. class Triangle {
  4978. constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
  4979. this.a = a;
  4980. this.b = b;
  4981. this.c = c;
  4982. }
  4983. static getNormal( a, b, c, target ) {
  4984. target.subVectors( c, b );
  4985. _v0$1.subVectors( a, b );
  4986. target.cross( _v0$1 );
  4987. const targetLengthSq = target.lengthSq();
  4988. if ( targetLengthSq > 0 ) {
  4989. return target.multiplyScalar( 1 / Math.sqrt( targetLengthSq ) );
  4990. }
  4991. return target.set( 0, 0, 0 );
  4992. }
  4993. // static/instance method to calculate barycentric coordinates
  4994. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4995. static getBarycoord( point, a, b, c, target ) {
  4996. _v0$1.subVectors( c, a );
  4997. _v1$3.subVectors( b, a );
  4998. _v2$2.subVectors( point, a );
  4999. const dot00 = _v0$1.dot( _v0$1 );
  5000. const dot01 = _v0$1.dot( _v1$3 );
  5001. const dot02 = _v0$1.dot( _v2$2 );
  5002. const dot11 = _v1$3.dot( _v1$3 );
  5003. const dot12 = _v1$3.dot( _v2$2 );
  5004. const denom = ( dot00 * dot11 - dot01 * dot01 );
  5005. // collinear or singular triangle
  5006. if ( denom === 0 ) {
  5007. target.set( 0, 0, 0 );
  5008. return null;
  5009. }
  5010. const invDenom = 1 / denom;
  5011. const u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  5012. const v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  5013. // barycentric coordinates must always sum to 1
  5014. return target.set( 1 - u - v, v, u );
  5015. }
  5016. static containsPoint( point, a, b, c ) {
  5017. // if the triangle is degenerate then we can't contain a point
  5018. if ( this.getBarycoord( point, a, b, c, _v3$2 ) === null ) {
  5019. return false;
  5020. }
  5021. return ( _v3$2.x >= 0 ) && ( _v3$2.y >= 0 ) && ( ( _v3$2.x + _v3$2.y ) <= 1 );
  5022. }
  5023. static getInterpolation( point, p1, p2, p3, v1, v2, v3, target ) {
  5024. if ( this.getBarycoord( point, p1, p2, p3, _v3$2 ) === null ) {
  5025. target.x = 0;
  5026. target.y = 0;
  5027. if ( 'z' in target ) target.z = 0;
  5028. if ( 'w' in target ) target.w = 0;
  5029. return null;
  5030. }
  5031. target.setScalar( 0 );
  5032. target.addScaledVector( v1, _v3$2.x );
  5033. target.addScaledVector( v2, _v3$2.y );
  5034. target.addScaledVector( v3, _v3$2.z );
  5035. return target;
  5036. }
  5037. static getInterpolatedAttribute( attr, i1, i2, i3, barycoord, target ) {
  5038. _v40.setScalar( 0 );
  5039. _v41.setScalar( 0 );
  5040. _v42.setScalar( 0 );
  5041. _v40.fromBufferAttribute( attr, i1 );
  5042. _v41.fromBufferAttribute( attr, i2 );
  5043. _v42.fromBufferAttribute( attr, i3 );
  5044. target.setScalar( 0 );
  5045. target.addScaledVector( _v40, barycoord.x );
  5046. target.addScaledVector( _v41, barycoord.y );
  5047. target.addScaledVector( _v42, barycoord.z );
  5048. return target;
  5049. }
  5050. static isFrontFacing( a, b, c, direction ) {
  5051. _v0$1.subVectors( c, b );
  5052. _v1$3.subVectors( a, b );
  5053. // strictly front facing
  5054. return ( _v0$1.cross( _v1$3 ).dot( direction ) < 0 ) ? true : false;
  5055. }
  5056. set( a, b, c ) {
  5057. this.a.copy( a );
  5058. this.b.copy( b );
  5059. this.c.copy( c );
  5060. return this;
  5061. }
  5062. setFromPointsAndIndices( points, i0, i1, i2 ) {
  5063. this.a.copy( points[ i0 ] );
  5064. this.b.copy( points[ i1 ] );
  5065. this.c.copy( points[ i2 ] );
  5066. return this;
  5067. }
  5068. setFromAttributeAndIndices( attribute, i0, i1, i2 ) {
  5069. this.a.fromBufferAttribute( attribute, i0 );
  5070. this.b.fromBufferAttribute( attribute, i1 );
  5071. this.c.fromBufferAttribute( attribute, i2 );
  5072. return this;
  5073. }
  5074. clone() {
  5075. return new this.constructor().copy( this );
  5076. }
  5077. copy( triangle ) {
  5078. this.a.copy( triangle.a );
  5079. this.b.copy( triangle.b );
  5080. this.c.copy( triangle.c );
  5081. return this;
  5082. }
  5083. getArea() {
  5084. _v0$1.subVectors( this.c, this.b );
  5085. _v1$3.subVectors( this.a, this.b );
  5086. return _v0$1.cross( _v1$3 ).length() * 0.5;
  5087. }
  5088. getMidpoint( target ) {
  5089. return target.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  5090. }
  5091. getNormal( target ) {
  5092. return Triangle.getNormal( this.a, this.b, this.c, target );
  5093. }
  5094. getPlane( target ) {
  5095. return target.setFromCoplanarPoints( this.a, this.b, this.c );
  5096. }
  5097. getBarycoord( point, target ) {
  5098. return Triangle.getBarycoord( point, this.a, this.b, this.c, target );
  5099. }
  5100. getInterpolation( point, v1, v2, v3, target ) {
  5101. return Triangle.getInterpolation( point, this.a, this.b, this.c, v1, v2, v3, target );
  5102. }
  5103. containsPoint( point ) {
  5104. return Triangle.containsPoint( point, this.a, this.b, this.c );
  5105. }
  5106. isFrontFacing( direction ) {
  5107. return Triangle.isFrontFacing( this.a, this.b, this.c, direction );
  5108. }
  5109. intersectsBox( box ) {
  5110. return box.intersectsTriangle( this );
  5111. }
  5112. closestPointToPoint( p, target ) {
  5113. const a = this.a, b = this.b, c = this.c;
  5114. let v, w;
  5115. // algorithm thanks to Real-Time Collision Detection by Christer Ericson,
  5116. // published by Morgan Kaufmann Publishers, (c) 2005 Elsevier Inc.,
  5117. // under the accompanying license; see chapter 5.1.5 for detailed explanation.
  5118. // basically, we're distinguishing which of the voronoi regions of the triangle
  5119. // the point lies in with the minimum amount of redundant computation.
  5120. _vab.subVectors( b, a );
  5121. _vac.subVectors( c, a );
  5122. _vap.subVectors( p, a );
  5123. const d1 = _vab.dot( _vap );
  5124. const d2 = _vac.dot( _vap );
  5125. if ( d1 <= 0 && d2 <= 0 ) {
  5126. // vertex region of A; barycentric coords (1, 0, 0)
  5127. return target.copy( a );
  5128. }
  5129. _vbp.subVectors( p, b );
  5130. const d3 = _vab.dot( _vbp );
  5131. const d4 = _vac.dot( _vbp );
  5132. if ( d3 >= 0 && d4 <= d3 ) {
  5133. // vertex region of B; barycentric coords (0, 1, 0)
  5134. return target.copy( b );
  5135. }
  5136. const vc = d1 * d4 - d3 * d2;
  5137. if ( vc <= 0 && d1 >= 0 && d3 <= 0 ) {
  5138. v = d1 / ( d1 - d3 );
  5139. // edge region of AB; barycentric coords (1-v, v, 0)
  5140. return target.copy( a ).addScaledVector( _vab, v );
  5141. }
  5142. _vcp.subVectors( p, c );
  5143. const d5 = _vab.dot( _vcp );
  5144. const d6 = _vac.dot( _vcp );
  5145. if ( d6 >= 0 && d5 <= d6 ) {
  5146. // vertex region of C; barycentric coords (0, 0, 1)
  5147. return target.copy( c );
  5148. }
  5149. const vb = d5 * d2 - d1 * d6;
  5150. if ( vb <= 0 && d2 >= 0 && d6 <= 0 ) {
  5151. w = d2 / ( d2 - d6 );
  5152. // edge region of AC; barycentric coords (1-w, 0, w)
  5153. return target.copy( a ).addScaledVector( _vac, w );
  5154. }
  5155. const va = d3 * d6 - d5 * d4;
  5156. if ( va <= 0 && ( d4 - d3 ) >= 0 && ( d5 - d6 ) >= 0 ) {
  5157. _vbc.subVectors( c, b );
  5158. w = ( d4 - d3 ) / ( ( d4 - d3 ) + ( d5 - d6 ) );
  5159. // edge region of BC; barycentric coords (0, 1-w, w)
  5160. return target.copy( b ).addScaledVector( _vbc, w ); // edge region of BC
  5161. }
  5162. // face region
  5163. const denom = 1 / ( va + vb + vc );
  5164. // u = va * denom
  5165. v = vb * denom;
  5166. w = vc * denom;
  5167. return target.copy( a ).addScaledVector( _vab, v ).addScaledVector( _vac, w );
  5168. }
  5169. equals( triangle ) {
  5170. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  5171. }
  5172. }
  5173. const _colorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  5174. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  5175. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  5176. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  5177. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  5178. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  5179. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  5180. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  5181. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  5182. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  5183. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  5184. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  5185. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  5186. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  5187. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  5188. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  5189. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  5190. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  5191. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  5192. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'rebeccapurple': 0x663399, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  5193. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  5194. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  5195. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  5196. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  5197. const _hslA = { h: 0, s: 0, l: 0 };
  5198. const _hslB = { h: 0, s: 0, l: 0 };
  5199. function hue2rgb( p, q, t ) {
  5200. if ( t < 0 ) t += 1;
  5201. if ( t > 1 ) t -= 1;
  5202. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  5203. if ( t < 1 / 2 ) return q;
  5204. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  5205. return p;
  5206. }
  5207. class Color {
  5208. constructor( r, g, b ) {
  5209. this.isColor = true;
  5210. this.r = 1;
  5211. this.g = 1;
  5212. this.b = 1;
  5213. return this.set( r, g, b );
  5214. }
  5215. set( r, g, b ) {
  5216. if ( g === undefined && b === undefined ) {
  5217. // r is THREE.Color, hex or string
  5218. const value = r;
  5219. if ( value && value.isColor ) {
  5220. this.copy( value );
  5221. } else if ( typeof value === 'number' ) {
  5222. this.setHex( value );
  5223. } else if ( typeof value === 'string' ) {
  5224. this.setStyle( value );
  5225. }
  5226. } else {
  5227. this.setRGB( r, g, b );
  5228. }
  5229. return this;
  5230. }
  5231. setScalar( scalar ) {
  5232. this.r = scalar;
  5233. this.g = scalar;
  5234. this.b = scalar;
  5235. return this;
  5236. }
  5237. setHex( hex, colorSpace = SRGBColorSpace ) {
  5238. hex = Math.floor( hex );
  5239. this.r = ( hex >> 16 & 255 ) / 255;
  5240. this.g = ( hex >> 8 & 255 ) / 255;
  5241. this.b = ( hex & 255 ) / 255;
  5242. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5243. return this;
  5244. }
  5245. setRGB( r, g, b, colorSpace = ColorManagement.workingColorSpace ) {
  5246. this.r = r;
  5247. this.g = g;
  5248. this.b = b;
  5249. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5250. return this;
  5251. }
  5252. setHSL( h, s, l, colorSpace = ColorManagement.workingColorSpace ) {
  5253. // h,s,l ranges are in 0.0 - 1.0
  5254. h = euclideanModulo( h, 1 );
  5255. s = clamp( s, 0, 1 );
  5256. l = clamp( l, 0, 1 );
  5257. if ( s === 0 ) {
  5258. this.r = this.g = this.b = l;
  5259. } else {
  5260. const p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  5261. const q = ( 2 * l ) - p;
  5262. this.r = hue2rgb( q, p, h + 1 / 3 );
  5263. this.g = hue2rgb( q, p, h );
  5264. this.b = hue2rgb( q, p, h - 1 / 3 );
  5265. }
  5266. ColorManagement.toWorkingColorSpace( this, colorSpace );
  5267. return this;
  5268. }
  5269. setStyle( style, colorSpace = SRGBColorSpace ) {
  5270. function handleAlpha( string ) {
  5271. if ( string === undefined ) return;
  5272. if ( parseFloat( string ) < 1 ) {
  5273. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  5274. }
  5275. }
  5276. let m;
  5277. if ( m = /^(\w+)\(([^\)]*)\)/.exec( style ) ) {
  5278. // rgb / hsl
  5279. let color;
  5280. const name = m[ 1 ];
  5281. const components = m[ 2 ];
  5282. switch ( name ) {
  5283. case 'rgb':
  5284. case 'rgba':
  5285. if ( color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5286. // rgb(255,0,0) rgba(255,0,0,0.5)
  5287. handleAlpha( color[ 4 ] );
  5288. return this.setRGB(
  5289. Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255,
  5290. Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255,
  5291. Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255,
  5292. colorSpace
  5293. );
  5294. }
  5295. if ( color = /^\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5296. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  5297. handleAlpha( color[ 4 ] );
  5298. return this.setRGB(
  5299. Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100,
  5300. Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100,
  5301. Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100,
  5302. colorSpace
  5303. );
  5304. }
  5305. break;
  5306. case 'hsl':
  5307. case 'hsla':
  5308. if ( color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)\%\s*,\s*(\d*\.?\d+)\%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec( components ) ) {
  5309. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  5310. handleAlpha( color[ 4 ] );
  5311. return this.setHSL(
  5312. parseFloat( color[ 1 ] ) / 360,
  5313. parseFloat( color[ 2 ] ) / 100,
  5314. parseFloat( color[ 3 ] ) / 100,
  5315. colorSpace
  5316. );
  5317. }
  5318. break;
  5319. default:
  5320. console.warn( 'THREE.Color: Unknown color model ' + style );
  5321. }
  5322. } else if ( m = /^\#([A-Fa-f\d]+)$/.exec( style ) ) {
  5323. // hex color
  5324. const hex = m[ 1 ];
  5325. const size = hex.length;
  5326. if ( size === 3 ) {
  5327. // #ff0
  5328. return this.setRGB(
  5329. parseInt( hex.charAt( 0 ), 16 ) / 15,
  5330. parseInt( hex.charAt( 1 ), 16 ) / 15,
  5331. parseInt( hex.charAt( 2 ), 16 ) / 15,
  5332. colorSpace
  5333. );
  5334. } else if ( size === 6 ) {
  5335. // #ff0000
  5336. return this.setHex( parseInt( hex, 16 ), colorSpace );
  5337. } else {
  5338. console.warn( 'THREE.Color: Invalid hex color ' + style );
  5339. }
  5340. } else if ( style && style.length > 0 ) {
  5341. return this.setColorName( style, colorSpace );
  5342. }
  5343. return this;
  5344. }
  5345. setColorName( style, colorSpace = SRGBColorSpace ) {
  5346. // color keywords
  5347. const hex = _colorKeywords[ style.toLowerCase() ];
  5348. if ( hex !== undefined ) {
  5349. // red
  5350. this.setHex( hex, colorSpace );
  5351. } else {
  5352. // unknown color
  5353. console.warn( 'THREE.Color: Unknown color ' + style );
  5354. }
  5355. return this;
  5356. }
  5357. clone() {
  5358. return new this.constructor( this.r, this.g, this.b );
  5359. }
  5360. copy( color ) {
  5361. this.r = color.r;
  5362. this.g = color.g;
  5363. this.b = color.b;
  5364. return this;
  5365. }
  5366. copySRGBToLinear( color ) {
  5367. this.r = SRGBToLinear( color.r );
  5368. this.g = SRGBToLinear( color.g );
  5369. this.b = SRGBToLinear( color.b );
  5370. return this;
  5371. }
  5372. copyLinearToSRGB( color ) {
  5373. this.r = LinearToSRGB( color.r );
  5374. this.g = LinearToSRGB( color.g );
  5375. this.b = LinearToSRGB( color.b );
  5376. return this;
  5377. }
  5378. convertSRGBToLinear() {
  5379. this.copySRGBToLinear( this );
  5380. return this;
  5381. }
  5382. convertLinearToSRGB() {
  5383. this.copyLinearToSRGB( this );
  5384. return this;
  5385. }
  5386. getHex( colorSpace = SRGBColorSpace ) {
  5387. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5388. 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 ) );
  5389. }
  5390. getHexString( colorSpace = SRGBColorSpace ) {
  5391. return ( '000000' + this.getHex( colorSpace ).toString( 16 ) ).slice( - 6 );
  5392. }
  5393. getHSL( target, colorSpace = ColorManagement.workingColorSpace ) {
  5394. // h,s,l ranges are in 0.0 - 1.0
  5395. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5396. const r = _color.r, g = _color.g, b = _color.b;
  5397. const max = Math.max( r, g, b );
  5398. const min = Math.min( r, g, b );
  5399. let hue, saturation;
  5400. const lightness = ( min + max ) / 2.0;
  5401. if ( min === max ) {
  5402. hue = 0;
  5403. saturation = 0;
  5404. } else {
  5405. const delta = max - min;
  5406. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  5407. switch ( max ) {
  5408. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  5409. case g: hue = ( b - r ) / delta + 2; break;
  5410. case b: hue = ( r - g ) / delta + 4; break;
  5411. }
  5412. hue /= 6;
  5413. }
  5414. target.h = hue;
  5415. target.s = saturation;
  5416. target.l = lightness;
  5417. return target;
  5418. }
  5419. getRGB( target, colorSpace = ColorManagement.workingColorSpace ) {
  5420. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5421. target.r = _color.r;
  5422. target.g = _color.g;
  5423. target.b = _color.b;
  5424. return target;
  5425. }
  5426. getStyle( colorSpace = SRGBColorSpace ) {
  5427. ColorManagement.fromWorkingColorSpace( _color.copy( this ), colorSpace );
  5428. const r = _color.r, g = _color.g, b = _color.b;
  5429. if ( colorSpace !== SRGBColorSpace ) {
  5430. // Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).
  5431. return `color(${ colorSpace } ${ r.toFixed( 3 ) } ${ g.toFixed( 3 ) } ${ b.toFixed( 3 ) })`;
  5432. }
  5433. return `rgb(${ Math.round( r * 255 ) },${ Math.round( g * 255 ) },${ Math.round( b * 255 ) })`;
  5434. }
  5435. offsetHSL( h, s, l ) {
  5436. this.getHSL( _hslA );
  5437. return this.setHSL( _hslA.h + h, _hslA.s + s, _hslA.l + l );
  5438. }
  5439. add( color ) {
  5440. this.r += color.r;
  5441. this.g += color.g;
  5442. this.b += color.b;
  5443. return this;
  5444. }
  5445. addColors( color1, color2 ) {
  5446. this.r = color1.r + color2.r;
  5447. this.g = color1.g + color2.g;
  5448. this.b = color1.b + color2.b;
  5449. return this;
  5450. }
  5451. addScalar( s ) {
  5452. this.r += s;
  5453. this.g += s;
  5454. this.b += s;
  5455. return this;
  5456. }
  5457. sub( color ) {
  5458. this.r = Math.max( 0, this.r - color.r );
  5459. this.g = Math.max( 0, this.g - color.g );
  5460. this.b = Math.max( 0, this.b - color.b );
  5461. return this;
  5462. }
  5463. multiply( color ) {
  5464. this.r *= color.r;
  5465. this.g *= color.g;
  5466. this.b *= color.b;
  5467. return this;
  5468. }
  5469. multiplyScalar( s ) {
  5470. this.r *= s;
  5471. this.g *= s;
  5472. this.b *= s;
  5473. return this;
  5474. }
  5475. lerp( color, alpha ) {
  5476. this.r += ( color.r - this.r ) * alpha;
  5477. this.g += ( color.g - this.g ) * alpha;
  5478. this.b += ( color.b - this.b ) * alpha;
  5479. return this;
  5480. }
  5481. lerpColors( color1, color2, alpha ) {
  5482. this.r = color1.r + ( color2.r - color1.r ) * alpha;
  5483. this.g = color1.g + ( color2.g - color1.g ) * alpha;
  5484. this.b = color1.b + ( color2.b - color1.b ) * alpha;
  5485. return this;
  5486. }
  5487. lerpHSL( color, alpha ) {
  5488. this.getHSL( _hslA );
  5489. color.getHSL( _hslB );
  5490. const h = lerp( _hslA.h, _hslB.h, alpha );
  5491. const s = lerp( _hslA.s, _hslB.s, alpha );
  5492. const l = lerp( _hslA.l, _hslB.l, alpha );
  5493. this.setHSL( h, s, l );
  5494. return this;
  5495. }
  5496. setFromVector3( v ) {
  5497. this.r = v.x;
  5498. this.g = v.y;
  5499. this.b = v.z;
  5500. return this;
  5501. }
  5502. applyMatrix3( m ) {
  5503. const r = this.r, g = this.g, b = this.b;
  5504. const e = m.elements;
  5505. this.r = e[ 0 ] * r + e[ 3 ] * g + e[ 6 ] * b;
  5506. this.g = e[ 1 ] * r + e[ 4 ] * g + e[ 7 ] * b;
  5507. this.b = e[ 2 ] * r + e[ 5 ] * g + e[ 8 ] * b;
  5508. return this;
  5509. }
  5510. equals( c ) {
  5511. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  5512. }
  5513. fromArray( array, offset = 0 ) {
  5514. this.r = array[ offset ];
  5515. this.g = array[ offset + 1 ];
  5516. this.b = array[ offset + 2 ];
  5517. return this;
  5518. }
  5519. toArray( array = [], offset = 0 ) {
  5520. array[ offset ] = this.r;
  5521. array[ offset + 1 ] = this.g;
  5522. array[ offset + 2 ] = this.b;
  5523. return array;
  5524. }
  5525. fromBufferAttribute( attribute, index ) {
  5526. this.r = attribute.getX( index );
  5527. this.g = attribute.getY( index );
  5528. this.b = attribute.getZ( index );
  5529. return this;
  5530. }
  5531. toJSON() {
  5532. return this.getHex();
  5533. }
  5534. *[ Symbol.iterator ]() {
  5535. yield this.r;
  5536. yield this.g;
  5537. yield this.b;
  5538. }
  5539. }
  5540. const _color = /*@__PURE__*/ new Color();
  5541. Color.NAMES = _colorKeywords;
  5542. let _materialId = 0;
  5543. class Material extends EventDispatcher {
  5544. constructor() {
  5545. super();
  5546. this.isMaterial = true;
  5547. Object.defineProperty( this, 'id', { value: _materialId ++ } );
  5548. this.uuid = generateUUID();
  5549. this.name = '';
  5550. this.type = 'Material';
  5551. this.blending = NormalBlending;
  5552. this.side = FrontSide;
  5553. this.vertexColors = false;
  5554. this.opacity = 1;
  5555. this.transparent = false;
  5556. this.alphaHash = false;
  5557. this.blendSrc = SrcAlphaFactor;
  5558. this.blendDst = OneMinusSrcAlphaFactor;
  5559. this.blendEquation = AddEquation;
  5560. this.blendSrcAlpha = null;
  5561. this.blendDstAlpha = null;
  5562. this.blendEquationAlpha = null;
  5563. this.blendColor = new Color( 0, 0, 0 );
  5564. this.blendAlpha = 0;
  5565. this.depthFunc = LessEqualDepth;
  5566. this.depthTest = true;
  5567. this.depthWrite = true;
  5568. this.stencilWriteMask = 0xff;
  5569. this.stencilFunc = AlwaysStencilFunc;
  5570. this.stencilRef = 0;
  5571. this.stencilFuncMask = 0xff;
  5572. this.stencilFail = KeepStencilOp;
  5573. this.stencilZFail = KeepStencilOp;
  5574. this.stencilZPass = KeepStencilOp;
  5575. this.stencilWrite = false;
  5576. this.clippingPlanes = null;
  5577. this.clipIntersection = false;
  5578. this.clipShadows = false;
  5579. this.shadowSide = null;
  5580. this.colorWrite = true;
  5581. this.precision = null; // override the renderer's default precision for this material
  5582. this.polygonOffset = false;
  5583. this.polygonOffsetFactor = 0;
  5584. this.polygonOffsetUnits = 0;
  5585. this.dithering = false;
  5586. this.alphaToCoverage = false;
  5587. this.premultipliedAlpha = false;
  5588. this.forceSinglePass = false;
  5589. this.visible = true;
  5590. this.toneMapped = true;
  5591. this.userData = {};
  5592. this.version = 0;
  5593. this._alphaTest = 0;
  5594. }
  5595. get alphaTest() {
  5596. return this._alphaTest;
  5597. }
  5598. set alphaTest( value ) {
  5599. if ( this._alphaTest > 0 !== value > 0 ) {
  5600. this.version ++;
  5601. }
  5602. this._alphaTest = value;
  5603. }
  5604. // onBeforeRender and onBeforeCompile only supported in WebGLRenderer
  5605. onBeforeRender( /* renderer, scene, camera, geometry, object, group */ ) {}
  5606. onBeforeCompile( /* shaderobject, renderer */ ) {}
  5607. customProgramCacheKey() {
  5608. return this.onBeforeCompile.toString();
  5609. }
  5610. setValues( values ) {
  5611. if ( values === undefined ) return;
  5612. for ( const key in values ) {
  5613. const newValue = values[ key ];
  5614. if ( newValue === undefined ) {
  5615. console.warn( `THREE.Material: parameter '${ key }' has value of undefined.` );
  5616. continue;
  5617. }
  5618. const currentValue = this[ key ];
  5619. if ( currentValue === undefined ) {
  5620. console.warn( `THREE.Material: '${ key }' is not a property of THREE.${ this.type }.` );
  5621. continue;
  5622. }
  5623. if ( currentValue && currentValue.isColor ) {
  5624. currentValue.set( newValue );
  5625. } else if ( ( currentValue && currentValue.isVector3 ) && ( newValue && newValue.isVector3 ) ) {
  5626. currentValue.copy( newValue );
  5627. } else {
  5628. this[ key ] = newValue;
  5629. }
  5630. }
  5631. }
  5632. toJSON( meta ) {
  5633. const isRootObject = ( meta === undefined || typeof meta === 'string' );
  5634. if ( isRootObject ) {
  5635. meta = {
  5636. textures: {},
  5637. images: {}
  5638. };
  5639. }
  5640. const data = {
  5641. metadata: {
  5642. version: 4.6,
  5643. type: 'Material',
  5644. generator: 'Material.toJSON'
  5645. }
  5646. };
  5647. // standard Material serialization
  5648. data.uuid = this.uuid;
  5649. data.type = this.type;
  5650. if ( this.name !== '' ) data.name = this.name;
  5651. if ( this.color && this.color.isColor ) data.color = this.color.getHex();
  5652. if ( this.roughness !== undefined ) data.roughness = this.roughness;
  5653. if ( this.metalness !== undefined ) data.metalness = this.metalness;
  5654. if ( this.sheen !== undefined ) data.sheen = this.sheen;
  5655. if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();
  5656. if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
  5657. if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
  5658. if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
  5659. if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
  5660. if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
  5661. if ( this.specularColor && this.specularColor.isColor ) data.specularColor = this.specularColor.getHex();
  5662. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  5663. if ( this.clearcoat !== undefined ) data.clearcoat = this.clearcoat;
  5664. if ( this.clearcoatRoughness !== undefined ) data.clearcoatRoughness = this.clearcoatRoughness;
  5665. if ( this.clearcoatMap && this.clearcoatMap.isTexture ) {
  5666. data.clearcoatMap = this.clearcoatMap.toJSON( meta ).uuid;
  5667. }
  5668. if ( this.clearcoatRoughnessMap && this.clearcoatRoughnessMap.isTexture ) {
  5669. data.clearcoatRoughnessMap = this.clearcoatRoughnessMap.toJSON( meta ).uuid;
  5670. }
  5671. if ( this.clearcoatNormalMap && this.clearcoatNormalMap.isTexture ) {
  5672. data.clearcoatNormalMap = this.clearcoatNormalMap.toJSON( meta ).uuid;
  5673. data.clearcoatNormalScale = this.clearcoatNormalScale.toArray();
  5674. }
  5675. if ( this.dispersion !== undefined ) data.dispersion = this.dispersion;
  5676. if ( this.iridescence !== undefined ) data.iridescence = this.iridescence;
  5677. if ( this.iridescenceIOR !== undefined ) data.iridescenceIOR = this.iridescenceIOR;
  5678. if ( this.iridescenceThicknessRange !== undefined ) data.iridescenceThicknessRange = this.iridescenceThicknessRange;
  5679. if ( this.iridescenceMap && this.iridescenceMap.isTexture ) {
  5680. data.iridescenceMap = this.iridescenceMap.toJSON( meta ).uuid;
  5681. }
  5682. if ( this.iridescenceThicknessMap && this.iridescenceThicknessMap.isTexture ) {
  5683. data.iridescenceThicknessMap = this.iridescenceThicknessMap.toJSON( meta ).uuid;
  5684. }
  5685. if ( this.anisotropy !== undefined ) data.anisotropy = this.anisotropy;
  5686. if ( this.anisotropyRotation !== undefined ) data.anisotropyRotation = this.anisotropyRotation;
  5687. if ( this.anisotropyMap && this.anisotropyMap.isTexture ) {
  5688. data.anisotropyMap = this.anisotropyMap.toJSON( meta ).uuid;
  5689. }
  5690. if ( this.map && this.map.isTexture ) data.map = this.map.toJSON( meta ).uuid;
  5691. if ( this.matcap && this.matcap.isTexture ) data.matcap = this.matcap.toJSON( meta ).uuid;
  5692. if ( this.alphaMap && this.alphaMap.isTexture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  5693. if ( this.lightMap && this.lightMap.isTexture ) {
  5694. data.lightMap = this.lightMap.toJSON( meta ).uuid;
  5695. data.lightMapIntensity = this.lightMapIntensity;
  5696. }
  5697. if ( this.aoMap && this.aoMap.isTexture ) {
  5698. data.aoMap = this.aoMap.toJSON( meta ).uuid;
  5699. data.aoMapIntensity = this.aoMapIntensity;
  5700. }
  5701. if ( this.bumpMap && this.bumpMap.isTexture ) {
  5702. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  5703. data.bumpScale = this.bumpScale;
  5704. }
  5705. if ( this.normalMap && this.normalMap.isTexture ) {
  5706. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  5707. data.normalMapType = this.normalMapType;
  5708. data.normalScale = this.normalScale.toArray();
  5709. }
  5710. if ( this.displacementMap && this.displacementMap.isTexture ) {
  5711. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  5712. data.displacementScale = this.displacementScale;
  5713. data.displacementBias = this.displacementBias;
  5714. }
  5715. if ( this.roughnessMap && this.roughnessMap.isTexture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  5716. if ( this.metalnessMap && this.metalnessMap.isTexture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  5717. if ( this.emissiveMap && this.emissiveMap.isTexture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  5718. if ( this.specularMap && this.specularMap.isTexture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  5719. if ( this.specularIntensityMap && this.specularIntensityMap.isTexture ) data.specularIntensityMap = this.specularIntensityMap.toJSON( meta ).uuid;
  5720. if ( this.specularColorMap && this.specularColorMap.isTexture ) data.specularColorMap = this.specularColorMap.toJSON( meta ).uuid;
  5721. if ( this.envMap && this.envMap.isTexture ) {
  5722. data.envMap = this.envMap.toJSON( meta ).uuid;
  5723. if ( this.combine !== undefined ) data.combine = this.combine;
  5724. }
  5725. if ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray();
  5726. if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
  5727. if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;
  5728. if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;
  5729. if ( this.gradientMap && this.gradientMap.isTexture ) {
  5730. data.gradientMap = this.gradientMap.toJSON( meta ).uuid;
  5731. }
  5732. if ( this.transmission !== undefined ) data.transmission = this.transmission;
  5733. if ( this.transmissionMap && this.transmissionMap.isTexture ) data.transmissionMap = this.transmissionMap.toJSON( meta ).uuid;
  5734. if ( this.thickness !== undefined ) data.thickness = this.thickness;
  5735. if ( this.thicknessMap && this.thicknessMap.isTexture ) data.thicknessMap = this.thicknessMap.toJSON( meta ).uuid;
  5736. if ( this.attenuationDistance !== undefined && this.attenuationDistance !== Infinity ) data.attenuationDistance = this.attenuationDistance;
  5737. if ( this.attenuationColor !== undefined ) data.attenuationColor = this.attenuationColor.getHex();
  5738. if ( this.size !== undefined ) data.size = this.size;
  5739. if ( this.shadowSide !== null ) data.shadowSide = this.shadowSide;
  5740. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  5741. if ( this.blending !== NormalBlending ) data.blending = this.blending;
  5742. if ( this.side !== FrontSide ) data.side = this.side;
  5743. if ( this.vertexColors === true ) data.vertexColors = true;
  5744. if ( this.opacity < 1 ) data.opacity = this.opacity;
  5745. if ( this.transparent === true ) data.transparent = true;
  5746. if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;
  5747. if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;
  5748. if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;
  5749. if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;
  5750. if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;
  5751. if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;
  5752. if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();
  5753. if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;
  5754. if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
  5755. if ( this.depthTest === false ) data.depthTest = this.depthTest;
  5756. if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
  5757. if ( this.colorWrite === false ) data.colorWrite = this.colorWrite;
  5758. if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;
  5759. if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;
  5760. if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;
  5761. if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;
  5762. if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;
  5763. if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;
  5764. if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;
  5765. if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;
  5766. // rotation (SpriteMaterial)
  5767. if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;
  5768. if ( this.polygonOffset === true ) data.polygonOffset = true;
  5769. if ( this.polygonOffsetFactor !== 0 ) data.polygonOffsetFactor = this.polygonOffsetFactor;
  5770. if ( this.polygonOffsetUnits !== 0 ) data.polygonOffsetUnits = this.polygonOffsetUnits;
  5771. if ( this.linewidth !== undefined && this.linewidth !== 1 ) data.linewidth = this.linewidth;
  5772. if ( this.dashSize !== undefined ) data.dashSize = this.dashSize;
  5773. if ( this.gapSize !== undefined ) data.gapSize = this.gapSize;
  5774. if ( this.scale !== undefined ) data.scale = this.scale;
  5775. if ( this.dithering === true ) data.dithering = true;
  5776. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  5777. if ( this.alphaHash === true ) data.alphaHash = true;
  5778. if ( this.alphaToCoverage === true ) data.alphaToCoverage = true;
  5779. if ( this.premultipliedAlpha === true ) data.premultipliedAlpha = true;
  5780. if ( this.forceSinglePass === true ) data.forceSinglePass = true;
  5781. if ( this.wireframe === true ) data.wireframe = true;
  5782. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  5783. if ( this.wireframeLinecap !== 'round' ) data.wireframeLinecap = this.wireframeLinecap;
  5784. if ( this.wireframeLinejoin !== 'round' ) data.wireframeLinejoin = this.wireframeLinejoin;
  5785. if ( this.flatShading === true ) data.flatShading = true;
  5786. if ( this.visible === false ) data.visible = false;
  5787. if ( this.toneMapped === false ) data.toneMapped = false;
  5788. if ( this.fog === false ) data.fog = false;
  5789. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  5790. // TODO: Copied from Object3D.toJSON
  5791. function extractFromCache( cache ) {
  5792. const values = [];
  5793. for ( const key in cache ) {
  5794. const data = cache[ key ];
  5795. delete data.metadata;
  5796. values.push( data );
  5797. }
  5798. return values;
  5799. }
  5800. if ( isRootObject ) {
  5801. const textures = extractFromCache( meta.textures );
  5802. const images = extractFromCache( meta.images );
  5803. if ( textures.length > 0 ) data.textures = textures;
  5804. if ( images.length > 0 ) data.images = images;
  5805. }
  5806. return data;
  5807. }
  5808. clone() {
  5809. return new this.constructor().copy( this );
  5810. }
  5811. copy( source ) {
  5812. this.name = source.name;
  5813. this.blending = source.blending;
  5814. this.side = source.side;
  5815. this.vertexColors = source.vertexColors;
  5816. this.opacity = source.opacity;
  5817. this.transparent = source.transparent;
  5818. this.blendSrc = source.blendSrc;
  5819. this.blendDst = source.blendDst;
  5820. this.blendEquation = source.blendEquation;
  5821. this.blendSrcAlpha = source.blendSrcAlpha;
  5822. this.blendDstAlpha = source.blendDstAlpha;
  5823. this.blendEquationAlpha = source.blendEquationAlpha;
  5824. this.blendColor.copy( source.blendColor );
  5825. this.blendAlpha = source.blendAlpha;
  5826. this.depthFunc = source.depthFunc;
  5827. this.depthTest = source.depthTest;
  5828. this.depthWrite = source.depthWrite;
  5829. this.stencilWriteMask = source.stencilWriteMask;
  5830. this.stencilFunc = source.stencilFunc;
  5831. this.stencilRef = source.stencilRef;
  5832. this.stencilFuncMask = source.stencilFuncMask;
  5833. this.stencilFail = source.stencilFail;
  5834. this.stencilZFail = source.stencilZFail;
  5835. this.stencilZPass = source.stencilZPass;
  5836. this.stencilWrite = source.stencilWrite;
  5837. const srcPlanes = source.clippingPlanes;
  5838. let dstPlanes = null;
  5839. if ( srcPlanes !== null ) {
  5840. const n = srcPlanes.length;
  5841. dstPlanes = new Array( n );
  5842. for ( let i = 0; i !== n; ++ i ) {
  5843. dstPlanes[ i ] = srcPlanes[ i ].clone();
  5844. }
  5845. }
  5846. this.clippingPlanes = dstPlanes;
  5847. this.clipIntersection = source.clipIntersection;
  5848. this.clipShadows = source.clipShadows;
  5849. this.shadowSide = source.shadowSide;
  5850. this.colorWrite = source.colorWrite;
  5851. this.precision = source.precision;
  5852. this.polygonOffset = source.polygonOffset;
  5853. this.polygonOffsetFactor = source.polygonOffsetFactor;
  5854. this.polygonOffsetUnits = source.polygonOffsetUnits;
  5855. this.dithering = source.dithering;
  5856. this.alphaTest = source.alphaTest;
  5857. this.alphaHash = source.alphaHash;
  5858. this.alphaToCoverage = source.alphaToCoverage;
  5859. this.premultipliedAlpha = source.premultipliedAlpha;
  5860. this.forceSinglePass = source.forceSinglePass;
  5861. this.visible = source.visible;
  5862. this.toneMapped = source.toneMapped;
  5863. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5864. return this;
  5865. }
  5866. dispose() {
  5867. this.dispatchEvent( { type: 'dispose' } );
  5868. }
  5869. set needsUpdate( value ) {
  5870. if ( value === true ) this.version ++;
  5871. }
  5872. onBuild( /* shaderobject, renderer */ ) {
  5873. console.warn( 'Material: onBuild() has been removed.' ); // @deprecated, r166
  5874. }
  5875. }
  5876. class MeshBasicMaterial extends Material {
  5877. constructor( parameters ) {
  5878. super();
  5879. this.isMeshBasicMaterial = true;
  5880. this.type = 'MeshBasicMaterial';
  5881. this.color = new Color( 0xffffff ); // emissive
  5882. this.map = null;
  5883. this.lightMap = null;
  5884. this.lightMapIntensity = 1.0;
  5885. this.aoMap = null;
  5886. this.aoMapIntensity = 1.0;
  5887. this.specularMap = null;
  5888. this.alphaMap = null;
  5889. this.envMap = null;
  5890. this.envMapRotation = new Euler();
  5891. this.combine = MultiplyOperation;
  5892. this.reflectivity = 1;
  5893. this.refractionRatio = 0.98;
  5894. this.wireframe = false;
  5895. this.wireframeLinewidth = 1;
  5896. this.wireframeLinecap = 'round';
  5897. this.wireframeLinejoin = 'round';
  5898. this.fog = true;
  5899. this.setValues( parameters );
  5900. }
  5901. copy( source ) {
  5902. super.copy( source );
  5903. this.color.copy( source.color );
  5904. this.map = source.map;
  5905. this.lightMap = source.lightMap;
  5906. this.lightMapIntensity = source.lightMapIntensity;
  5907. this.aoMap = source.aoMap;
  5908. this.aoMapIntensity = source.aoMapIntensity;
  5909. this.specularMap = source.specularMap;
  5910. this.alphaMap = source.alphaMap;
  5911. this.envMap = source.envMap;
  5912. this.envMapRotation.copy( source.envMapRotation );
  5913. this.combine = source.combine;
  5914. this.reflectivity = source.reflectivity;
  5915. this.refractionRatio = source.refractionRatio;
  5916. this.wireframe = source.wireframe;
  5917. this.wireframeLinewidth = source.wireframeLinewidth;
  5918. this.wireframeLinecap = source.wireframeLinecap;
  5919. this.wireframeLinejoin = source.wireframeLinejoin;
  5920. this.fog = source.fog;
  5921. return this;
  5922. }
  5923. }
  5924. // Fast Half Float Conversions, http://www.fox-toolkit.org/ftp/fasthalffloatconversion.pdf
  5925. const _tables = /*@__PURE__*/ _generateTables();
  5926. function _generateTables() {
  5927. // float32 to float16 helpers
  5928. const buffer = new ArrayBuffer( 4 );
  5929. const floatView = new Float32Array( buffer );
  5930. const uint32View = new Uint32Array( buffer );
  5931. const baseTable = new Uint32Array( 512 );
  5932. const shiftTable = new Uint32Array( 512 );
  5933. for ( let i = 0; i < 256; ++ i ) {
  5934. const e = i - 127;
  5935. // very small number (0, -0)
  5936. if ( e < - 27 ) {
  5937. baseTable[ i ] = 0x0000;
  5938. baseTable[ i | 0x100 ] = 0x8000;
  5939. shiftTable[ i ] = 24;
  5940. shiftTable[ i | 0x100 ] = 24;
  5941. // small number (denorm)
  5942. } else if ( e < - 14 ) {
  5943. baseTable[ i ] = 0x0400 >> ( - e - 14 );
  5944. baseTable[ i | 0x100 ] = ( 0x0400 >> ( - e - 14 ) ) | 0x8000;
  5945. shiftTable[ i ] = - e - 1;
  5946. shiftTable[ i | 0x100 ] = - e - 1;
  5947. // normal number
  5948. } else if ( e <= 15 ) {
  5949. baseTable[ i ] = ( e + 15 ) << 10;
  5950. baseTable[ i | 0x100 ] = ( ( e + 15 ) << 10 ) | 0x8000;
  5951. shiftTable[ i ] = 13;
  5952. shiftTable[ i | 0x100 ] = 13;
  5953. // large number (Infinity, -Infinity)
  5954. } else if ( e < 128 ) {
  5955. baseTable[ i ] = 0x7c00;
  5956. baseTable[ i | 0x100 ] = 0xfc00;
  5957. shiftTable[ i ] = 24;
  5958. shiftTable[ i | 0x100 ] = 24;
  5959. // stay (NaN, Infinity, -Infinity)
  5960. } else {
  5961. baseTable[ i ] = 0x7c00;
  5962. baseTable[ i | 0x100 ] = 0xfc00;
  5963. shiftTable[ i ] = 13;
  5964. shiftTable[ i | 0x100 ] = 13;
  5965. }
  5966. }
  5967. // float16 to float32 helpers
  5968. const mantissaTable = new Uint32Array( 2048 );
  5969. const exponentTable = new Uint32Array( 64 );
  5970. const offsetTable = new Uint32Array( 64 );
  5971. for ( let i = 1; i < 1024; ++ i ) {
  5972. let m = i << 13; // zero pad mantissa bits
  5973. let e = 0; // zero exponent
  5974. // normalized
  5975. while ( ( m & 0x00800000 ) === 0 ) {
  5976. m <<= 1;
  5977. e -= 0x00800000; // decrement exponent
  5978. }
  5979. m &= ~ 0x00800000; // clear leading 1 bit
  5980. e += 0x38800000; // adjust bias
  5981. mantissaTable[ i ] = m | e;
  5982. }
  5983. for ( let i = 1024; i < 2048; ++ i ) {
  5984. mantissaTable[ i ] = 0x38000000 + ( ( i - 1024 ) << 13 );
  5985. }
  5986. for ( let i = 1; i < 31; ++ i ) {
  5987. exponentTable[ i ] = i << 23;
  5988. }
  5989. exponentTable[ 31 ] = 0x47800000;
  5990. exponentTable[ 32 ] = 0x80000000;
  5991. for ( let i = 33; i < 63; ++ i ) {
  5992. exponentTable[ i ] = 0x80000000 + ( ( i - 32 ) << 23 );
  5993. }
  5994. exponentTable[ 63 ] = 0xc7800000;
  5995. for ( let i = 1; i < 64; ++ i ) {
  5996. if ( i !== 32 ) {
  5997. offsetTable[ i ] = 1024;
  5998. }
  5999. }
  6000. return {
  6001. floatView: floatView,
  6002. uint32View: uint32View,
  6003. baseTable: baseTable,
  6004. shiftTable: shiftTable,
  6005. mantissaTable: mantissaTable,
  6006. exponentTable: exponentTable,
  6007. offsetTable: offsetTable
  6008. };
  6009. }
  6010. // float32 to float16
  6011. function toHalfFloat( val ) {
  6012. if ( Math.abs( val ) > 65504 ) console.warn( 'THREE.DataUtils.toHalfFloat(): Value out of range.' );
  6013. val = clamp( val, - 65504, 65504 );
  6014. _tables.floatView[ 0 ] = val;
  6015. const f = _tables.uint32View[ 0 ];
  6016. const e = ( f >> 23 ) & 0x1ff;
  6017. return _tables.baseTable[ e ] + ( ( f & 0x007fffff ) >> _tables.shiftTable[ e ] );
  6018. }
  6019. // float16 to float32
  6020. function fromHalfFloat( val ) {
  6021. const m = val >> 10;
  6022. _tables.uint32View[ 0 ] = _tables.mantissaTable[ _tables.offsetTable[ m ] + ( val & 0x3ff ) ] + _tables.exponentTable[ m ];
  6023. return _tables.floatView[ 0 ];
  6024. }
  6025. const DataUtils = {
  6026. toHalfFloat: toHalfFloat,
  6027. fromHalfFloat: fromHalfFloat,
  6028. };
  6029. const _vector$9 = /*@__PURE__*/ new Vector3();
  6030. const _vector2$1 = /*@__PURE__*/ new Vector2();
  6031. class BufferAttribute {
  6032. constructor( array, itemSize, normalized = false ) {
  6033. if ( Array.isArray( array ) ) {
  6034. throw new TypeError( 'THREE.BufferAttribute: array should be a Typed Array.' );
  6035. }
  6036. this.isBufferAttribute = true;
  6037. this.name = '';
  6038. this.array = array;
  6039. this.itemSize = itemSize;
  6040. this.count = array !== undefined ? array.length / itemSize : 0;
  6041. this.normalized = normalized;
  6042. this.usage = StaticDrawUsage;
  6043. this.updateRanges = [];
  6044. this.gpuType = FloatType;
  6045. this.version = 0;
  6046. }
  6047. onUploadCallback() {}
  6048. set needsUpdate( value ) {
  6049. if ( value === true ) this.version ++;
  6050. }
  6051. setUsage( value ) {
  6052. this.usage = value;
  6053. return this;
  6054. }
  6055. addUpdateRange( start, count ) {
  6056. this.updateRanges.push( { start, count } );
  6057. }
  6058. clearUpdateRanges() {
  6059. this.updateRanges.length = 0;
  6060. }
  6061. copy( source ) {
  6062. this.name = source.name;
  6063. this.array = new source.array.constructor( source.array );
  6064. this.itemSize = source.itemSize;
  6065. this.count = source.count;
  6066. this.normalized = source.normalized;
  6067. this.usage = source.usage;
  6068. this.gpuType = source.gpuType;
  6069. return this;
  6070. }
  6071. copyAt( index1, attribute, index2 ) {
  6072. index1 *= this.itemSize;
  6073. index2 *= attribute.itemSize;
  6074. for ( let i = 0, l = this.itemSize; i < l; i ++ ) {
  6075. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  6076. }
  6077. return this;
  6078. }
  6079. copyArray( array ) {
  6080. this.array.set( array );
  6081. return this;
  6082. }
  6083. applyMatrix3( m ) {
  6084. if ( this.itemSize === 2 ) {
  6085. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6086. _vector2$1.fromBufferAttribute( this, i );
  6087. _vector2$1.applyMatrix3( m );
  6088. this.setXY( i, _vector2$1.x, _vector2$1.y );
  6089. }
  6090. } else if ( this.itemSize === 3 ) {
  6091. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6092. _vector$9.fromBufferAttribute( this, i );
  6093. _vector$9.applyMatrix3( m );
  6094. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6095. }
  6096. }
  6097. return this;
  6098. }
  6099. applyMatrix4( m ) {
  6100. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6101. _vector$9.fromBufferAttribute( this, i );
  6102. _vector$9.applyMatrix4( m );
  6103. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6104. }
  6105. return this;
  6106. }
  6107. applyNormalMatrix( m ) {
  6108. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6109. _vector$9.fromBufferAttribute( this, i );
  6110. _vector$9.applyNormalMatrix( m );
  6111. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6112. }
  6113. return this;
  6114. }
  6115. transformDirection( m ) {
  6116. for ( let i = 0, l = this.count; i < l; i ++ ) {
  6117. _vector$9.fromBufferAttribute( this, i );
  6118. _vector$9.transformDirection( m );
  6119. this.setXYZ( i, _vector$9.x, _vector$9.y, _vector$9.z );
  6120. }
  6121. return this;
  6122. }
  6123. set( value, offset = 0 ) {
  6124. // Matching BufferAttribute constructor, do not normalize the array.
  6125. this.array.set( value, offset );
  6126. return this;
  6127. }
  6128. getComponent( index, component ) {
  6129. let value = this.array[ index * this.itemSize + component ];
  6130. if ( this.normalized ) value = denormalize( value, this.array );
  6131. return value;
  6132. }
  6133. setComponent( index, component, value ) {
  6134. if ( this.normalized ) value = normalize( value, this.array );
  6135. this.array[ index * this.itemSize + component ] = value;
  6136. return this;
  6137. }
  6138. getX( index ) {
  6139. let x = this.array[ index * this.itemSize ];
  6140. if ( this.normalized ) x = denormalize( x, this.array );
  6141. return x;
  6142. }
  6143. setX( index, x ) {
  6144. if ( this.normalized ) x = normalize( x, this.array );
  6145. this.array[ index * this.itemSize ] = x;
  6146. return this;
  6147. }
  6148. getY( index ) {
  6149. let y = this.array[ index * this.itemSize + 1 ];
  6150. if ( this.normalized ) y = denormalize( y, this.array );
  6151. return y;
  6152. }
  6153. setY( index, y ) {
  6154. if ( this.normalized ) y = normalize( y, this.array );
  6155. this.array[ index * this.itemSize + 1 ] = y;
  6156. return this;
  6157. }
  6158. getZ( index ) {
  6159. let z = this.array[ index * this.itemSize + 2 ];
  6160. if ( this.normalized ) z = denormalize( z, this.array );
  6161. return z;
  6162. }
  6163. setZ( index, z ) {
  6164. if ( this.normalized ) z = normalize( z, this.array );
  6165. this.array[ index * this.itemSize + 2 ] = z;
  6166. return this;
  6167. }
  6168. getW( index ) {
  6169. let w = this.array[ index * this.itemSize + 3 ];
  6170. if ( this.normalized ) w = denormalize( w, this.array );
  6171. return w;
  6172. }
  6173. setW( index, w ) {
  6174. if ( this.normalized ) w = normalize( w, this.array );
  6175. this.array[ index * this.itemSize + 3 ] = w;
  6176. return this;
  6177. }
  6178. setXY( index, x, y ) {
  6179. index *= this.itemSize;
  6180. if ( this.normalized ) {
  6181. x = normalize( x, this.array );
  6182. y = normalize( y, this.array );
  6183. }
  6184. this.array[ index + 0 ] = x;
  6185. this.array[ index + 1 ] = y;
  6186. return this;
  6187. }
  6188. setXYZ( index, x, y, z ) {
  6189. index *= this.itemSize;
  6190. if ( this.normalized ) {
  6191. x = normalize( x, this.array );
  6192. y = normalize( y, this.array );
  6193. z = normalize( z, this.array );
  6194. }
  6195. this.array[ index + 0 ] = x;
  6196. this.array[ index + 1 ] = y;
  6197. this.array[ index + 2 ] = z;
  6198. return this;
  6199. }
  6200. setXYZW( index, x, y, z, w ) {
  6201. index *= this.itemSize;
  6202. if ( this.normalized ) {
  6203. x = normalize( x, this.array );
  6204. y = normalize( y, this.array );
  6205. z = normalize( z, this.array );
  6206. w = normalize( w, this.array );
  6207. }
  6208. this.array[ index + 0 ] = x;
  6209. this.array[ index + 1 ] = y;
  6210. this.array[ index + 2 ] = z;
  6211. this.array[ index + 3 ] = w;
  6212. return this;
  6213. }
  6214. onUpload( callback ) {
  6215. this.onUploadCallback = callback;
  6216. return this;
  6217. }
  6218. clone() {
  6219. return new this.constructor( this.array, this.itemSize ).copy( this );
  6220. }
  6221. toJSON() {
  6222. const data = {
  6223. itemSize: this.itemSize,
  6224. type: this.array.constructor.name,
  6225. array: Array.from( this.array ),
  6226. normalized: this.normalized
  6227. };
  6228. if ( this.name !== '' ) data.name = this.name;
  6229. if ( this.usage !== StaticDrawUsage ) data.usage = this.usage;
  6230. return data;
  6231. }
  6232. }
  6233. //
  6234. class Int8BufferAttribute extends BufferAttribute {
  6235. constructor( array, itemSize, normalized ) {
  6236. super( new Int8Array( array ), itemSize, normalized );
  6237. }
  6238. }
  6239. class Uint8BufferAttribute extends BufferAttribute {
  6240. constructor( array, itemSize, normalized ) {
  6241. super( new Uint8Array( array ), itemSize, normalized );
  6242. }
  6243. }
  6244. class Uint8ClampedBufferAttribute extends BufferAttribute {
  6245. constructor( array, itemSize, normalized ) {
  6246. super( new Uint8ClampedArray( array ), itemSize, normalized );
  6247. }
  6248. }
  6249. class Int16BufferAttribute extends BufferAttribute {
  6250. constructor( array, itemSize, normalized ) {
  6251. super( new Int16Array( array ), itemSize, normalized );
  6252. }
  6253. }
  6254. class Uint16BufferAttribute extends BufferAttribute {
  6255. constructor( array, itemSize, normalized ) {
  6256. super( new Uint16Array( array ), itemSize, normalized );
  6257. }
  6258. }
  6259. class Int32BufferAttribute extends BufferAttribute {
  6260. constructor( array, itemSize, normalized ) {
  6261. super( new Int32Array( array ), itemSize, normalized );
  6262. }
  6263. }
  6264. class Uint32BufferAttribute extends BufferAttribute {
  6265. constructor( array, itemSize, normalized ) {
  6266. super( new Uint32Array( array ), itemSize, normalized );
  6267. }
  6268. }
  6269. class Float16BufferAttribute extends BufferAttribute {
  6270. constructor( array, itemSize, normalized ) {
  6271. super( new Uint16Array( array ), itemSize, normalized );
  6272. this.isFloat16BufferAttribute = true;
  6273. }
  6274. getX( index ) {
  6275. let x = fromHalfFloat( this.array[ index * this.itemSize ] );
  6276. if ( this.normalized ) x = denormalize( x, this.array );
  6277. return x;
  6278. }
  6279. setX( index, x ) {
  6280. if ( this.normalized ) x = normalize( x, this.array );
  6281. this.array[ index * this.itemSize ] = toHalfFloat( x );
  6282. return this;
  6283. }
  6284. getY( index ) {
  6285. let y = fromHalfFloat( this.array[ index * this.itemSize + 1 ] );
  6286. if ( this.normalized ) y = denormalize( y, this.array );
  6287. return y;
  6288. }
  6289. setY( index, y ) {
  6290. if ( this.normalized ) y = normalize( y, this.array );
  6291. this.array[ index * this.itemSize + 1 ] = toHalfFloat( y );
  6292. return this;
  6293. }
  6294. getZ( index ) {
  6295. let z = fromHalfFloat( this.array[ index * this.itemSize + 2 ] );
  6296. if ( this.normalized ) z = denormalize( z, this.array );
  6297. return z;
  6298. }
  6299. setZ( index, z ) {
  6300. if ( this.normalized ) z = normalize( z, this.array );
  6301. this.array[ index * this.itemSize + 2 ] = toHalfFloat( z );
  6302. return this;
  6303. }
  6304. getW( index ) {
  6305. let w = fromHalfFloat( this.array[ index * this.itemSize + 3 ] );
  6306. if ( this.normalized ) w = denormalize( w, this.array );
  6307. return w;
  6308. }
  6309. setW( index, w ) {
  6310. if ( this.normalized ) w = normalize( w, this.array );
  6311. this.array[ index * this.itemSize + 3 ] = toHalfFloat( w );
  6312. return this;
  6313. }
  6314. setXY( index, x, y ) {
  6315. index *= this.itemSize;
  6316. if ( this.normalized ) {
  6317. x = normalize( x, this.array );
  6318. y = normalize( y, this.array );
  6319. }
  6320. this.array[ index + 0 ] = toHalfFloat( x );
  6321. this.array[ index + 1 ] = toHalfFloat( y );
  6322. return this;
  6323. }
  6324. setXYZ( index, x, y, z ) {
  6325. index *= this.itemSize;
  6326. if ( this.normalized ) {
  6327. x = normalize( x, this.array );
  6328. y = normalize( y, this.array );
  6329. z = normalize( z, this.array );
  6330. }
  6331. this.array[ index + 0 ] = toHalfFloat( x );
  6332. this.array[ index + 1 ] = toHalfFloat( y );
  6333. this.array[ index + 2 ] = toHalfFloat( z );
  6334. return this;
  6335. }
  6336. setXYZW( index, x, y, z, w ) {
  6337. index *= this.itemSize;
  6338. if ( this.normalized ) {
  6339. x = normalize( x, this.array );
  6340. y = normalize( y, this.array );
  6341. z = normalize( z, this.array );
  6342. w = normalize( w, this.array );
  6343. }
  6344. this.array[ index + 0 ] = toHalfFloat( x );
  6345. this.array[ index + 1 ] = toHalfFloat( y );
  6346. this.array[ index + 2 ] = toHalfFloat( z );
  6347. this.array[ index + 3 ] = toHalfFloat( w );
  6348. return this;
  6349. }
  6350. }
  6351. class Float32BufferAttribute extends BufferAttribute {
  6352. constructor( array, itemSize, normalized ) {
  6353. super( new Float32Array( array ), itemSize, normalized );
  6354. }
  6355. }
  6356. let _id$1 = 0;
  6357. const _m1 = /*@__PURE__*/ new Matrix4();
  6358. const _obj = /*@__PURE__*/ new Object3D();
  6359. const _offset = /*@__PURE__*/ new Vector3();
  6360. const _box$2 = /*@__PURE__*/ new Box3();
  6361. const _boxMorphTargets = /*@__PURE__*/ new Box3();
  6362. const _vector$8 = /*@__PURE__*/ new Vector3();
  6363. class BufferGeometry extends EventDispatcher {
  6364. constructor() {
  6365. super();
  6366. this.isBufferGeometry = true;
  6367. Object.defineProperty( this, 'id', { value: _id$1 ++ } );
  6368. this.uuid = generateUUID();
  6369. this.name = '';
  6370. this.type = 'BufferGeometry';
  6371. this.index = null;
  6372. this.indirect = null;
  6373. this.attributes = {};
  6374. this.morphAttributes = {};
  6375. this.morphTargetsRelative = false;
  6376. this.groups = [];
  6377. this.boundingBox = null;
  6378. this.boundingSphere = null;
  6379. this.drawRange = { start: 0, count: Infinity };
  6380. this.userData = {};
  6381. }
  6382. getIndex() {
  6383. return this.index;
  6384. }
  6385. setIndex( index ) {
  6386. if ( Array.isArray( index ) ) {
  6387. this.index = new ( arrayNeedsUint32( index ) ? Uint32BufferAttribute : Uint16BufferAttribute )( index, 1 );
  6388. } else {
  6389. this.index = index;
  6390. }
  6391. return this;
  6392. }
  6393. setIndirect( indirect ) {
  6394. this.indirect = indirect;
  6395. return this;
  6396. }
  6397. getIndirect() {
  6398. return this.indirect;
  6399. }
  6400. getAttribute( name ) {
  6401. return this.attributes[ name ];
  6402. }
  6403. setAttribute( name, attribute ) {
  6404. this.attributes[ name ] = attribute;
  6405. return this;
  6406. }
  6407. deleteAttribute( name ) {
  6408. delete this.attributes[ name ];
  6409. return this;
  6410. }
  6411. hasAttribute( name ) {
  6412. return this.attributes[ name ] !== undefined;
  6413. }
  6414. addGroup( start, count, materialIndex = 0 ) {
  6415. this.groups.push( {
  6416. start: start,
  6417. count: count,
  6418. materialIndex: materialIndex
  6419. } );
  6420. }
  6421. clearGroups() {
  6422. this.groups = [];
  6423. }
  6424. setDrawRange( start, count ) {
  6425. this.drawRange.start = start;
  6426. this.drawRange.count = count;
  6427. }
  6428. applyMatrix4( matrix ) {
  6429. const position = this.attributes.position;
  6430. if ( position !== undefined ) {
  6431. position.applyMatrix4( matrix );
  6432. position.needsUpdate = true;
  6433. }
  6434. const normal = this.attributes.normal;
  6435. if ( normal !== undefined ) {
  6436. const normalMatrix = new Matrix3().getNormalMatrix( matrix );
  6437. normal.applyNormalMatrix( normalMatrix );
  6438. normal.needsUpdate = true;
  6439. }
  6440. const tangent = this.attributes.tangent;
  6441. if ( tangent !== undefined ) {
  6442. tangent.transformDirection( matrix );
  6443. tangent.needsUpdate = true;
  6444. }
  6445. if ( this.boundingBox !== null ) {
  6446. this.computeBoundingBox();
  6447. }
  6448. if ( this.boundingSphere !== null ) {
  6449. this.computeBoundingSphere();
  6450. }
  6451. return this;
  6452. }
  6453. applyQuaternion( q ) {
  6454. _m1.makeRotationFromQuaternion( q );
  6455. this.applyMatrix4( _m1 );
  6456. return this;
  6457. }
  6458. rotateX( angle ) {
  6459. // rotate geometry around world x-axis
  6460. _m1.makeRotationX( angle );
  6461. this.applyMatrix4( _m1 );
  6462. return this;
  6463. }
  6464. rotateY( angle ) {
  6465. // rotate geometry around world y-axis
  6466. _m1.makeRotationY( angle );
  6467. this.applyMatrix4( _m1 );
  6468. return this;
  6469. }
  6470. rotateZ( angle ) {
  6471. // rotate geometry around world z-axis
  6472. _m1.makeRotationZ( angle );
  6473. this.applyMatrix4( _m1 );
  6474. return this;
  6475. }
  6476. translate( x, y, z ) {
  6477. // translate geometry
  6478. _m1.makeTranslation( x, y, z );
  6479. this.applyMatrix4( _m1 );
  6480. return this;
  6481. }
  6482. scale( x, y, z ) {
  6483. // scale geometry
  6484. _m1.makeScale( x, y, z );
  6485. this.applyMatrix4( _m1 );
  6486. return this;
  6487. }
  6488. lookAt( vector ) {
  6489. _obj.lookAt( vector );
  6490. _obj.updateMatrix();
  6491. this.applyMatrix4( _obj.matrix );
  6492. return this;
  6493. }
  6494. center() {
  6495. this.computeBoundingBox();
  6496. this.boundingBox.getCenter( _offset ).negate();
  6497. this.translate( _offset.x, _offset.y, _offset.z );
  6498. return this;
  6499. }
  6500. setFromPoints( points ) {
  6501. const positionAttribute = this.getAttribute( 'position' );
  6502. if ( positionAttribute === undefined ) {
  6503. const position = [];
  6504. for ( let i = 0, l = points.length; i < l; i ++ ) {
  6505. const point = points[ i ];
  6506. position.push( point.x, point.y, point.z || 0 );
  6507. }
  6508. this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
  6509. } else {
  6510. const l = Math.min( points.length, positionAttribute.count ); // make sure data do not exceed buffer size
  6511. for ( let i = 0; i < l; i ++ ) {
  6512. const point = points[ i ];
  6513. positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 );
  6514. }
  6515. if ( points.length > positionAttribute.count ) {
  6516. console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' );
  6517. }
  6518. positionAttribute.needsUpdate = true;
  6519. }
  6520. return this;
  6521. }
  6522. computeBoundingBox() {
  6523. if ( this.boundingBox === null ) {
  6524. this.boundingBox = new Box3();
  6525. }
  6526. const position = this.attributes.position;
  6527. const morphAttributesPosition = this.morphAttributes.position;
  6528. if ( position && position.isGLBufferAttribute ) {
  6529. console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );
  6530. this.boundingBox.set(
  6531. new Vector3( - Infinity, - Infinity, - Infinity ),
  6532. new Vector3( + Infinity, + Infinity, + Infinity )
  6533. );
  6534. return;
  6535. }
  6536. if ( position !== undefined ) {
  6537. this.boundingBox.setFromBufferAttribute( position );
  6538. // process morph attributes if present
  6539. if ( morphAttributesPosition ) {
  6540. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6541. const morphAttribute = morphAttributesPosition[ i ];
  6542. _box$2.setFromBufferAttribute( morphAttribute );
  6543. if ( this.morphTargetsRelative ) {
  6544. _vector$8.addVectors( this.boundingBox.min, _box$2.min );
  6545. this.boundingBox.expandByPoint( _vector$8 );
  6546. _vector$8.addVectors( this.boundingBox.max, _box$2.max );
  6547. this.boundingBox.expandByPoint( _vector$8 );
  6548. } else {
  6549. this.boundingBox.expandByPoint( _box$2.min );
  6550. this.boundingBox.expandByPoint( _box$2.max );
  6551. }
  6552. }
  6553. }
  6554. } else {
  6555. this.boundingBox.makeEmpty();
  6556. }
  6557. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6558. console.error( 'THREE.BufferGeometry.computeBoundingBox(): Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6559. }
  6560. }
  6561. computeBoundingSphere() {
  6562. if ( this.boundingSphere === null ) {
  6563. this.boundingSphere = new Sphere();
  6564. }
  6565. const position = this.attributes.position;
  6566. const morphAttributesPosition = this.morphAttributes.position;
  6567. if ( position && position.isGLBufferAttribute ) {
  6568. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );
  6569. this.boundingSphere.set( new Vector3(), Infinity );
  6570. return;
  6571. }
  6572. if ( position ) {
  6573. // first, find the center of the bounding sphere
  6574. const center = this.boundingSphere.center;
  6575. _box$2.setFromBufferAttribute( position );
  6576. // process morph attributes if present
  6577. if ( morphAttributesPosition ) {
  6578. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6579. const morphAttribute = morphAttributesPosition[ i ];
  6580. _boxMorphTargets.setFromBufferAttribute( morphAttribute );
  6581. if ( this.morphTargetsRelative ) {
  6582. _vector$8.addVectors( _box$2.min, _boxMorphTargets.min );
  6583. _box$2.expandByPoint( _vector$8 );
  6584. _vector$8.addVectors( _box$2.max, _boxMorphTargets.max );
  6585. _box$2.expandByPoint( _vector$8 );
  6586. } else {
  6587. _box$2.expandByPoint( _boxMorphTargets.min );
  6588. _box$2.expandByPoint( _boxMorphTargets.max );
  6589. }
  6590. }
  6591. }
  6592. _box$2.getCenter( center );
  6593. // second, try to find a boundingSphere with a radius smaller than the
  6594. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6595. let maxRadiusSq = 0;
  6596. for ( let i = 0, il = position.count; i < il; i ++ ) {
  6597. _vector$8.fromBufferAttribute( position, i );
  6598. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6599. }
  6600. // process morph attributes if present
  6601. if ( morphAttributesPosition ) {
  6602. for ( let i = 0, il = morphAttributesPosition.length; i < il; i ++ ) {
  6603. const morphAttribute = morphAttributesPosition[ i ];
  6604. const morphTargetsRelative = this.morphTargetsRelative;
  6605. for ( let j = 0, jl = morphAttribute.count; j < jl; j ++ ) {
  6606. _vector$8.fromBufferAttribute( morphAttribute, j );
  6607. if ( morphTargetsRelative ) {
  6608. _offset.fromBufferAttribute( position, j );
  6609. _vector$8.add( _offset );
  6610. }
  6611. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( _vector$8 ) );
  6612. }
  6613. }
  6614. }
  6615. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6616. if ( isNaN( this.boundingSphere.radius ) ) {
  6617. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6618. }
  6619. }
  6620. }
  6621. computeTangents() {
  6622. const index = this.index;
  6623. const attributes = this.attributes;
  6624. // based on http://www.terathon.com/code/tangent.html
  6625. // (per vertex tangents)
  6626. if ( index === null ||
  6627. attributes.position === undefined ||
  6628. attributes.normal === undefined ||
  6629. attributes.uv === undefined ) {
  6630. console.error( 'THREE.BufferGeometry: .computeTangents() failed. Missing required attributes (index, position, normal or uv)' );
  6631. return;
  6632. }
  6633. const positionAttribute = attributes.position;
  6634. const normalAttribute = attributes.normal;
  6635. const uvAttribute = attributes.uv;
  6636. if ( this.hasAttribute( 'tangent' ) === false ) {
  6637. this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
  6638. }
  6639. const tangentAttribute = this.getAttribute( 'tangent' );
  6640. const tan1 = [], tan2 = [];
  6641. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  6642. tan1[ i ] = new Vector3();
  6643. tan2[ i ] = new Vector3();
  6644. }
  6645. const vA = new Vector3(),
  6646. vB = new Vector3(),
  6647. vC = new Vector3(),
  6648. uvA = new Vector2(),
  6649. uvB = new Vector2(),
  6650. uvC = new Vector2(),
  6651. sdir = new Vector3(),
  6652. tdir = new Vector3();
  6653. function handleTriangle( a, b, c ) {
  6654. vA.fromBufferAttribute( positionAttribute, a );
  6655. vB.fromBufferAttribute( positionAttribute, b );
  6656. vC.fromBufferAttribute( positionAttribute, c );
  6657. uvA.fromBufferAttribute( uvAttribute, a );
  6658. uvB.fromBufferAttribute( uvAttribute, b );
  6659. uvC.fromBufferAttribute( uvAttribute, c );
  6660. vB.sub( vA );
  6661. vC.sub( vA );
  6662. uvB.sub( uvA );
  6663. uvC.sub( uvA );
  6664. const r = 1.0 / ( uvB.x * uvC.y - uvC.x * uvB.y );
  6665. // silently ignore degenerate uv triangles having coincident or colinear vertices
  6666. if ( ! isFinite( r ) ) return;
  6667. sdir.copy( vB ).multiplyScalar( uvC.y ).addScaledVector( vC, - uvB.y ).multiplyScalar( r );
  6668. tdir.copy( vC ).multiplyScalar( uvB.x ).addScaledVector( vB, - uvC.x ).multiplyScalar( r );
  6669. tan1[ a ].add( sdir );
  6670. tan1[ b ].add( sdir );
  6671. tan1[ c ].add( sdir );
  6672. tan2[ a ].add( tdir );
  6673. tan2[ b ].add( tdir );
  6674. tan2[ c ].add( tdir );
  6675. }
  6676. let groups = this.groups;
  6677. if ( groups.length === 0 ) {
  6678. groups = [ {
  6679. start: 0,
  6680. count: index.count
  6681. } ];
  6682. }
  6683. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6684. const group = groups[ i ];
  6685. const start = group.start;
  6686. const count = group.count;
  6687. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6688. handleTriangle(
  6689. index.getX( j + 0 ),
  6690. index.getX( j + 1 ),
  6691. index.getX( j + 2 )
  6692. );
  6693. }
  6694. }
  6695. const tmp = new Vector3(), tmp2 = new Vector3();
  6696. const n = new Vector3(), n2 = new Vector3();
  6697. function handleVertex( v ) {
  6698. n.fromBufferAttribute( normalAttribute, v );
  6699. n2.copy( n );
  6700. const t = tan1[ v ];
  6701. // Gram-Schmidt orthogonalize
  6702. tmp.copy( t );
  6703. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6704. // Calculate handedness
  6705. tmp2.crossVectors( n2, t );
  6706. const test = tmp2.dot( tan2[ v ] );
  6707. const w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6708. tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );
  6709. }
  6710. for ( let i = 0, il = groups.length; i < il; ++ i ) {
  6711. const group = groups[ i ];
  6712. const start = group.start;
  6713. const count = group.count;
  6714. for ( let j = start, jl = start + count; j < jl; j += 3 ) {
  6715. handleVertex( index.getX( j + 0 ) );
  6716. handleVertex( index.getX( j + 1 ) );
  6717. handleVertex( index.getX( j + 2 ) );
  6718. }
  6719. }
  6720. }
  6721. computeVertexNormals() {
  6722. const index = this.index;
  6723. const positionAttribute = this.getAttribute( 'position' );
  6724. if ( positionAttribute !== undefined ) {
  6725. let normalAttribute = this.getAttribute( 'normal' );
  6726. if ( normalAttribute === undefined ) {
  6727. normalAttribute = new BufferAttribute( new Float32Array( positionAttribute.count * 3 ), 3 );
  6728. this.setAttribute( 'normal', normalAttribute );
  6729. } else {
  6730. // reset existing normals to zero
  6731. for ( let i = 0, il = normalAttribute.count; i < il; i ++ ) {
  6732. normalAttribute.setXYZ( i, 0, 0, 0 );
  6733. }
  6734. }
  6735. const pA = new Vector3(), pB = new Vector3(), pC = new Vector3();
  6736. const nA = new Vector3(), nB = new Vector3(), nC = new Vector3();
  6737. const cb = new Vector3(), ab = new Vector3();
  6738. // indexed elements
  6739. if ( index ) {
  6740. for ( let i = 0, il = index.count; i < il; i += 3 ) {
  6741. const vA = index.getX( i + 0 );
  6742. const vB = index.getX( i + 1 );
  6743. const vC = index.getX( i + 2 );
  6744. pA.fromBufferAttribute( positionAttribute, vA );
  6745. pB.fromBufferAttribute( positionAttribute, vB );
  6746. pC.fromBufferAttribute( positionAttribute, vC );
  6747. cb.subVectors( pC, pB );
  6748. ab.subVectors( pA, pB );
  6749. cb.cross( ab );
  6750. nA.fromBufferAttribute( normalAttribute, vA );
  6751. nB.fromBufferAttribute( normalAttribute, vB );
  6752. nC.fromBufferAttribute( normalAttribute, vC );
  6753. nA.add( cb );
  6754. nB.add( cb );
  6755. nC.add( cb );
  6756. normalAttribute.setXYZ( vA, nA.x, nA.y, nA.z );
  6757. normalAttribute.setXYZ( vB, nB.x, nB.y, nB.z );
  6758. normalAttribute.setXYZ( vC, nC.x, nC.y, nC.z );
  6759. }
  6760. } else {
  6761. // non-indexed elements (unconnected triangle soup)
  6762. for ( let i = 0, il = positionAttribute.count; i < il; i += 3 ) {
  6763. pA.fromBufferAttribute( positionAttribute, i + 0 );
  6764. pB.fromBufferAttribute( positionAttribute, i + 1 );
  6765. pC.fromBufferAttribute( positionAttribute, i + 2 );
  6766. cb.subVectors( pC, pB );
  6767. ab.subVectors( pA, pB );
  6768. cb.cross( ab );
  6769. normalAttribute.setXYZ( i + 0, cb.x, cb.y, cb.z );
  6770. normalAttribute.setXYZ( i + 1, cb.x, cb.y, cb.z );
  6771. normalAttribute.setXYZ( i + 2, cb.x, cb.y, cb.z );
  6772. }
  6773. }
  6774. this.normalizeNormals();
  6775. normalAttribute.needsUpdate = true;
  6776. }
  6777. }
  6778. normalizeNormals() {
  6779. const normals = this.attributes.normal;
  6780. for ( let i = 0, il = normals.count; i < il; i ++ ) {
  6781. _vector$8.fromBufferAttribute( normals, i );
  6782. _vector$8.normalize();
  6783. normals.setXYZ( i, _vector$8.x, _vector$8.y, _vector$8.z );
  6784. }
  6785. }
  6786. toNonIndexed() {
  6787. function convertBufferAttribute( attribute, indices ) {
  6788. const array = attribute.array;
  6789. const itemSize = attribute.itemSize;
  6790. const normalized = attribute.normalized;
  6791. const array2 = new array.constructor( indices.length * itemSize );
  6792. let index = 0, index2 = 0;
  6793. for ( let i = 0, l = indices.length; i < l; i ++ ) {
  6794. if ( attribute.isInterleavedBufferAttribute ) {
  6795. index = indices[ i ] * attribute.data.stride + attribute.offset;
  6796. } else {
  6797. index = indices[ i ] * itemSize;
  6798. }
  6799. for ( let j = 0; j < itemSize; j ++ ) {
  6800. array2[ index2 ++ ] = array[ index ++ ];
  6801. }
  6802. }
  6803. return new BufferAttribute( array2, itemSize, normalized );
  6804. }
  6805. //
  6806. if ( this.index === null ) {
  6807. console.warn( 'THREE.BufferGeometry.toNonIndexed(): BufferGeometry is already non-indexed.' );
  6808. return this;
  6809. }
  6810. const geometry2 = new BufferGeometry();
  6811. const indices = this.index.array;
  6812. const attributes = this.attributes;
  6813. // attributes
  6814. for ( const name in attributes ) {
  6815. const attribute = attributes[ name ];
  6816. const newAttribute = convertBufferAttribute( attribute, indices );
  6817. geometry2.setAttribute( name, newAttribute );
  6818. }
  6819. // morph attributes
  6820. const morphAttributes = this.morphAttributes;
  6821. for ( const name in morphAttributes ) {
  6822. const morphArray = [];
  6823. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6824. for ( let i = 0, il = morphAttribute.length; i < il; i ++ ) {
  6825. const attribute = morphAttribute[ i ];
  6826. const newAttribute = convertBufferAttribute( attribute, indices );
  6827. morphArray.push( newAttribute );
  6828. }
  6829. geometry2.morphAttributes[ name ] = morphArray;
  6830. }
  6831. geometry2.morphTargetsRelative = this.morphTargetsRelative;
  6832. // groups
  6833. const groups = this.groups;
  6834. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6835. const group = groups[ i ];
  6836. geometry2.addGroup( group.start, group.count, group.materialIndex );
  6837. }
  6838. return geometry2;
  6839. }
  6840. toJSON() {
  6841. const data = {
  6842. metadata: {
  6843. version: 4.6,
  6844. type: 'BufferGeometry',
  6845. generator: 'BufferGeometry.toJSON'
  6846. }
  6847. };
  6848. // standard BufferGeometry serialization
  6849. data.uuid = this.uuid;
  6850. data.type = this.type;
  6851. if ( this.name !== '' ) data.name = this.name;
  6852. if ( Object.keys( this.userData ).length > 0 ) data.userData = this.userData;
  6853. if ( this.parameters !== undefined ) {
  6854. const parameters = this.parameters;
  6855. for ( const key in parameters ) {
  6856. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6857. }
  6858. return data;
  6859. }
  6860. // for simplicity the code assumes attributes are not shared across geometries, see #15811
  6861. data.data = { attributes: {} };
  6862. const index = this.index;
  6863. if ( index !== null ) {
  6864. data.data.index = {
  6865. type: index.array.constructor.name,
  6866. array: Array.prototype.slice.call( index.array )
  6867. };
  6868. }
  6869. const attributes = this.attributes;
  6870. for ( const key in attributes ) {
  6871. const attribute = attributes[ key ];
  6872. data.data.attributes[ key ] = attribute.toJSON( data.data );
  6873. }
  6874. const morphAttributes = {};
  6875. let hasMorphAttributes = false;
  6876. for ( const key in this.morphAttributes ) {
  6877. const attributeArray = this.morphAttributes[ key ];
  6878. const array = [];
  6879. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  6880. const attribute = attributeArray[ i ];
  6881. array.push( attribute.toJSON( data.data ) );
  6882. }
  6883. if ( array.length > 0 ) {
  6884. morphAttributes[ key ] = array;
  6885. hasMorphAttributes = true;
  6886. }
  6887. }
  6888. if ( hasMorphAttributes ) {
  6889. data.data.morphAttributes = morphAttributes;
  6890. data.data.morphTargetsRelative = this.morphTargetsRelative;
  6891. }
  6892. const groups = this.groups;
  6893. if ( groups.length > 0 ) {
  6894. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6895. }
  6896. const boundingSphere = this.boundingSphere;
  6897. if ( boundingSphere !== null ) {
  6898. data.data.boundingSphere = {
  6899. center: boundingSphere.center.toArray(),
  6900. radius: boundingSphere.radius
  6901. };
  6902. }
  6903. return data;
  6904. }
  6905. clone() {
  6906. return new this.constructor().copy( this );
  6907. }
  6908. copy( source ) {
  6909. // reset
  6910. this.index = null;
  6911. this.attributes = {};
  6912. this.morphAttributes = {};
  6913. this.groups = [];
  6914. this.boundingBox = null;
  6915. this.boundingSphere = null;
  6916. // used for storing cloned, shared data
  6917. const data = {};
  6918. // name
  6919. this.name = source.name;
  6920. // index
  6921. const index = source.index;
  6922. if ( index !== null ) {
  6923. this.setIndex( index.clone( data ) );
  6924. }
  6925. // attributes
  6926. const attributes = source.attributes;
  6927. for ( const name in attributes ) {
  6928. const attribute = attributes[ name ];
  6929. this.setAttribute( name, attribute.clone( data ) );
  6930. }
  6931. // morph attributes
  6932. const morphAttributes = source.morphAttributes;
  6933. for ( const name in morphAttributes ) {
  6934. const array = [];
  6935. const morphAttribute = morphAttributes[ name ]; // morphAttribute: array of Float32BufferAttributes
  6936. for ( let i = 0, l = morphAttribute.length; i < l; i ++ ) {
  6937. array.push( morphAttribute[ i ].clone( data ) );
  6938. }
  6939. this.morphAttributes[ name ] = array;
  6940. }
  6941. this.morphTargetsRelative = source.morphTargetsRelative;
  6942. // groups
  6943. const groups = source.groups;
  6944. for ( let i = 0, l = groups.length; i < l; i ++ ) {
  6945. const group = groups[ i ];
  6946. this.addGroup( group.start, group.count, group.materialIndex );
  6947. }
  6948. // bounding box
  6949. const boundingBox = source.boundingBox;
  6950. if ( boundingBox !== null ) {
  6951. this.boundingBox = boundingBox.clone();
  6952. }
  6953. // bounding sphere
  6954. const boundingSphere = source.boundingSphere;
  6955. if ( boundingSphere !== null ) {
  6956. this.boundingSphere = boundingSphere.clone();
  6957. }
  6958. // draw range
  6959. this.drawRange.start = source.drawRange.start;
  6960. this.drawRange.count = source.drawRange.count;
  6961. // user data
  6962. this.userData = source.userData;
  6963. return this;
  6964. }
  6965. dispose() {
  6966. this.dispatchEvent( { type: 'dispose' } );
  6967. }
  6968. }
  6969. const _inverseMatrix$3 = /*@__PURE__*/ new Matrix4();
  6970. const _ray$3 = /*@__PURE__*/ new Ray();
  6971. const _sphere$6 = /*@__PURE__*/ new Sphere();
  6972. const _sphereHitAt = /*@__PURE__*/ new Vector3();
  6973. const _vA$1 = /*@__PURE__*/ new Vector3();
  6974. const _vB$1 = /*@__PURE__*/ new Vector3();
  6975. const _vC$1 = /*@__PURE__*/ new Vector3();
  6976. const _tempA = /*@__PURE__*/ new Vector3();
  6977. const _morphA = /*@__PURE__*/ new Vector3();
  6978. const _intersectionPoint = /*@__PURE__*/ new Vector3();
  6979. const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
  6980. class Mesh extends Object3D {
  6981. constructor( geometry = new BufferGeometry(), material = new MeshBasicMaterial() ) {
  6982. super();
  6983. this.isMesh = true;
  6984. this.type = 'Mesh';
  6985. this.geometry = geometry;
  6986. this.material = material;
  6987. this.updateMorphTargets();
  6988. }
  6989. copy( source, recursive ) {
  6990. super.copy( source, recursive );
  6991. if ( source.morphTargetInfluences !== undefined ) {
  6992. this.morphTargetInfluences = source.morphTargetInfluences.slice();
  6993. }
  6994. if ( source.morphTargetDictionary !== undefined ) {
  6995. this.morphTargetDictionary = Object.assign( {}, source.morphTargetDictionary );
  6996. }
  6997. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  6998. this.geometry = source.geometry;
  6999. return this;
  7000. }
  7001. updateMorphTargets() {
  7002. const geometry = this.geometry;
  7003. const morphAttributes = geometry.morphAttributes;
  7004. const keys = Object.keys( morphAttributes );
  7005. if ( keys.length > 0 ) {
  7006. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  7007. if ( morphAttribute !== undefined ) {
  7008. this.morphTargetInfluences = [];
  7009. this.morphTargetDictionary = {};
  7010. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  7011. const name = morphAttribute[ m ].name || String( m );
  7012. this.morphTargetInfluences.push( 0 );
  7013. this.morphTargetDictionary[ name ] = m;
  7014. }
  7015. }
  7016. }
  7017. }
  7018. getVertexPosition( index, target ) {
  7019. const geometry = this.geometry;
  7020. const position = geometry.attributes.position;
  7021. const morphPosition = geometry.morphAttributes.position;
  7022. const morphTargetsRelative = geometry.morphTargetsRelative;
  7023. target.fromBufferAttribute( position, index );
  7024. const morphInfluences = this.morphTargetInfluences;
  7025. if ( morphPosition && morphInfluences ) {
  7026. _morphA.set( 0, 0, 0 );
  7027. for ( let i = 0, il = morphPosition.length; i < il; i ++ ) {
  7028. const influence = morphInfluences[ i ];
  7029. const morphAttribute = morphPosition[ i ];
  7030. if ( influence === 0 ) continue;
  7031. _tempA.fromBufferAttribute( morphAttribute, index );
  7032. if ( morphTargetsRelative ) {
  7033. _morphA.addScaledVector( _tempA, influence );
  7034. } else {
  7035. _morphA.addScaledVector( _tempA.sub( target ), influence );
  7036. }
  7037. }
  7038. target.add( _morphA );
  7039. }
  7040. return target;
  7041. }
  7042. raycast( raycaster, intersects ) {
  7043. const geometry = this.geometry;
  7044. const material = this.material;
  7045. const matrixWorld = this.matrixWorld;
  7046. if ( material === undefined ) return;
  7047. // test with bounding sphere in world space
  7048. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  7049. _sphere$6.copy( geometry.boundingSphere );
  7050. _sphere$6.applyMatrix4( matrixWorld );
  7051. // check distance from ray origin to bounding sphere
  7052. _ray$3.copy( raycaster.ray ).recast( raycaster.near );
  7053. if ( _sphere$6.containsPoint( _ray$3.origin ) === false ) {
  7054. if ( _ray$3.intersectSphere( _sphere$6, _sphereHitAt ) === null ) return;
  7055. if ( _ray$3.origin.distanceToSquared( _sphereHitAt ) > ( raycaster.far - raycaster.near ) ** 2 ) return;
  7056. }
  7057. // convert ray to local space of mesh
  7058. _inverseMatrix$3.copy( matrixWorld ).invert();
  7059. _ray$3.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$3 );
  7060. // test with bounding box in local space
  7061. if ( geometry.boundingBox !== null ) {
  7062. if ( _ray$3.intersectsBox( geometry.boundingBox ) === false ) return;
  7063. }
  7064. // test for intersections with geometry
  7065. this._computeIntersections( raycaster, intersects, _ray$3 );
  7066. }
  7067. _computeIntersections( raycaster, intersects, rayLocalSpace ) {
  7068. let intersection;
  7069. const geometry = this.geometry;
  7070. const material = this.material;
  7071. const index = geometry.index;
  7072. const position = geometry.attributes.position;
  7073. const uv = geometry.attributes.uv;
  7074. const uv1 = geometry.attributes.uv1;
  7075. const normal = geometry.attributes.normal;
  7076. const groups = geometry.groups;
  7077. const drawRange = geometry.drawRange;
  7078. if ( index !== null ) {
  7079. // indexed buffer geometry
  7080. if ( Array.isArray( material ) ) {
  7081. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7082. const group = groups[ i ];
  7083. const groupMaterial = material[ group.materialIndex ];
  7084. const start = Math.max( group.start, drawRange.start );
  7085. const end = Math.min( index.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7086. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7087. const a = index.getX( j );
  7088. const b = index.getX( j + 1 );
  7089. const c = index.getX( j + 2 );
  7090. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7091. if ( intersection ) {
  7092. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in indexed buffer semantics
  7093. intersection.face.materialIndex = group.materialIndex;
  7094. intersects.push( intersection );
  7095. }
  7096. }
  7097. }
  7098. } else {
  7099. const start = Math.max( 0, drawRange.start );
  7100. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  7101. for ( let i = start, il = end; i < il; i += 3 ) {
  7102. const a = index.getX( i );
  7103. const b = index.getX( i + 1 );
  7104. const c = index.getX( i + 2 );
  7105. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7106. if ( intersection ) {
  7107. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indexed buffer semantics
  7108. intersects.push( intersection );
  7109. }
  7110. }
  7111. }
  7112. } else if ( position !== undefined ) {
  7113. // non-indexed buffer geometry
  7114. if ( Array.isArray( material ) ) {
  7115. for ( let i = 0, il = groups.length; i < il; i ++ ) {
  7116. const group = groups[ i ];
  7117. const groupMaterial = material[ group.materialIndex ];
  7118. const start = Math.max( group.start, drawRange.start );
  7119. const end = Math.min( position.count, Math.min( ( group.start + group.count ), ( drawRange.start + drawRange.count ) ) );
  7120. for ( let j = start, jl = end; j < jl; j += 3 ) {
  7121. const a = j;
  7122. const b = j + 1;
  7123. const c = j + 2;
  7124. intersection = checkGeometryIntersection( this, groupMaterial, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7125. if ( intersection ) {
  7126. intersection.faceIndex = Math.floor( j / 3 ); // triangle number in non-indexed buffer semantics
  7127. intersection.face.materialIndex = group.materialIndex;
  7128. intersects.push( intersection );
  7129. }
  7130. }
  7131. }
  7132. } else {
  7133. const start = Math.max( 0, drawRange.start );
  7134. const end = Math.min( position.count, ( drawRange.start + drawRange.count ) );
  7135. for ( let i = start, il = end; i < il; i += 3 ) {
  7136. const a = i;
  7137. const b = i + 1;
  7138. const c = i + 2;
  7139. intersection = checkGeometryIntersection( this, material, raycaster, rayLocalSpace, uv, uv1, normal, a, b, c );
  7140. if ( intersection ) {
  7141. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in non-indexed buffer semantics
  7142. intersects.push( intersection );
  7143. }
  7144. }
  7145. }
  7146. }
  7147. }
  7148. }
  7149. function checkIntersection$1( object, material, raycaster, ray, pA, pB, pC, point ) {
  7150. let intersect;
  7151. if ( material.side === BackSide ) {
  7152. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  7153. } else {
  7154. intersect = ray.intersectTriangle( pA, pB, pC, ( material.side === FrontSide ), point );
  7155. }
  7156. if ( intersect === null ) return null;
  7157. _intersectionPointWorld.copy( point );
  7158. _intersectionPointWorld.applyMatrix4( object.matrixWorld );
  7159. const distance = raycaster.ray.origin.distanceTo( _intersectionPointWorld );
  7160. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  7161. return {
  7162. distance: distance,
  7163. point: _intersectionPointWorld.clone(),
  7164. object: object
  7165. };
  7166. }
  7167. function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, normal, a, b, c ) {
  7168. object.getVertexPosition( a, _vA$1 );
  7169. object.getVertexPosition( b, _vB$1 );
  7170. object.getVertexPosition( c, _vC$1 );
  7171. const intersection = checkIntersection$1( object, material, raycaster, ray, _vA$1, _vB$1, _vC$1, _intersectionPoint );
  7172. if ( intersection ) {
  7173. const barycoord = new Vector3();
  7174. Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord );
  7175. if ( uv ) {
  7176. intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() );
  7177. }
  7178. if ( uv1 ) {
  7179. intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() );
  7180. }
  7181. if ( normal ) {
  7182. intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );
  7183. if ( intersection.normal.dot( ray.direction ) > 0 ) {
  7184. intersection.normal.multiplyScalar( - 1 );
  7185. }
  7186. }
  7187. const face = {
  7188. a: a,
  7189. b: b,
  7190. c: c,
  7191. normal: new Vector3(),
  7192. materialIndex: 0
  7193. };
  7194. Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
  7195. intersection.face = face;
  7196. intersection.barycoord = barycoord;
  7197. }
  7198. return intersection;
  7199. }
  7200. class BoxGeometry extends BufferGeometry {
  7201. constructor( width = 1, height = 1, depth = 1, widthSegments = 1, heightSegments = 1, depthSegments = 1 ) {
  7202. super();
  7203. this.type = 'BoxGeometry';
  7204. this.parameters = {
  7205. width: width,
  7206. height: height,
  7207. depth: depth,
  7208. widthSegments: widthSegments,
  7209. heightSegments: heightSegments,
  7210. depthSegments: depthSegments
  7211. };
  7212. const scope = this;
  7213. // segments
  7214. widthSegments = Math.floor( widthSegments );
  7215. heightSegments = Math.floor( heightSegments );
  7216. depthSegments = Math.floor( depthSegments );
  7217. // buffers
  7218. const indices = [];
  7219. const vertices = [];
  7220. const normals = [];
  7221. const uvs = [];
  7222. // helper variables
  7223. let numberOfVertices = 0;
  7224. let groupStart = 0;
  7225. // build each side of the box geometry
  7226. buildPlane( 'z', 'y', 'x', - 1, - 1, depth, height, width, depthSegments, heightSegments, 0 ); // px
  7227. buildPlane( 'z', 'y', 'x', 1, - 1, depth, height, - width, depthSegments, heightSegments, 1 ); // nx
  7228. buildPlane( 'x', 'z', 'y', 1, 1, width, depth, height, widthSegments, depthSegments, 2 ); // py
  7229. buildPlane( 'x', 'z', 'y', 1, - 1, width, depth, - height, widthSegments, depthSegments, 3 ); // ny
  7230. buildPlane( 'x', 'y', 'z', 1, - 1, width, height, depth, widthSegments, heightSegments, 4 ); // pz
  7231. buildPlane( 'x', 'y', 'z', - 1, - 1, width, height, - depth, widthSegments, heightSegments, 5 ); // nz
  7232. // build geometry
  7233. this.setIndex( indices );
  7234. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  7235. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  7236. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  7237. function buildPlane( u, v, w, udir, vdir, width, height, depth, gridX, gridY, materialIndex ) {
  7238. const segmentWidth = width / gridX;
  7239. const segmentHeight = height / gridY;
  7240. const widthHalf = width / 2;
  7241. const heightHalf = height / 2;
  7242. const depthHalf = depth / 2;
  7243. const gridX1 = gridX + 1;
  7244. const gridY1 = gridY + 1;
  7245. let vertexCounter = 0;
  7246. let groupCount = 0;
  7247. const vector = new Vector3();
  7248. // generate vertices, normals and uvs
  7249. for ( let iy = 0; iy < gridY1; iy ++ ) {
  7250. const y = iy * segmentHeight - heightHalf;
  7251. for ( let ix = 0; ix < gridX1; ix ++ ) {
  7252. const x = ix * segmentWidth - widthHalf;
  7253. // set values to correct vector component
  7254. vector[ u ] = x * udir;
  7255. vector[ v ] = y * vdir;
  7256. vector[ w ] = depthHalf;
  7257. // now apply vector to vertex buffer
  7258. vertices.push( vector.x, vector.y, vector.z );
  7259. // set values to correct vector component
  7260. vector[ u ] = 0;
  7261. vector[ v ] = 0;
  7262. vector[ w ] = depth > 0 ? 1 : - 1;
  7263. // now apply vector to normal buffer
  7264. normals.push( vector.x, vector.y, vector.z );
  7265. // uvs
  7266. uvs.push( ix / gridX );
  7267. uvs.push( 1 - ( iy / gridY ) );
  7268. // counters
  7269. vertexCounter += 1;
  7270. }
  7271. }
  7272. // indices
  7273. // 1. you need three indices to draw a single face
  7274. // 2. a single segment consists of two faces
  7275. // 3. so we need to generate six (2*3) indices per segment
  7276. for ( let iy = 0; iy < gridY; iy ++ ) {
  7277. for ( let ix = 0; ix < gridX; ix ++ ) {
  7278. const a = numberOfVertices + ix + gridX1 * iy;
  7279. const b = numberOfVertices + ix + gridX1 * ( iy + 1 );
  7280. const c = numberOfVertices + ( ix + 1 ) + gridX1 * ( iy + 1 );
  7281. const d = numberOfVertices + ( ix + 1 ) + gridX1 * iy;
  7282. // faces
  7283. indices.push( a, b, d );
  7284. indices.push( b, c, d );
  7285. // increase counter
  7286. groupCount += 6;
  7287. }
  7288. }
  7289. // add a group to the geometry. this will ensure multi material support
  7290. scope.addGroup( groupStart, groupCount, materialIndex );
  7291. // calculate new start value for groups
  7292. groupStart += groupCount;
  7293. // update total number of vertices
  7294. numberOfVertices += vertexCounter;
  7295. }
  7296. }
  7297. copy( source ) {
  7298. super.copy( source );
  7299. this.parameters = Object.assign( {}, source.parameters );
  7300. return this;
  7301. }
  7302. static fromJSON( data ) {
  7303. return new BoxGeometry( data.width, data.height, data.depth, data.widthSegments, data.heightSegments, data.depthSegments );
  7304. }
  7305. }
  7306. /**
  7307. * Uniform Utilities
  7308. */
  7309. function cloneUniforms( src ) {
  7310. const dst = {};
  7311. for ( const u in src ) {
  7312. dst[ u ] = {};
  7313. for ( const p in src[ u ] ) {
  7314. const property = src[ u ][ p ];
  7315. if ( property && ( property.isColor ||
  7316. property.isMatrix3 || property.isMatrix4 ||
  7317. property.isVector2 || property.isVector3 || property.isVector4 ||
  7318. property.isTexture || property.isQuaternion ) ) {
  7319. if ( property.isRenderTargetTexture ) {
  7320. console.warn( 'UniformsUtils: Textures of render targets cannot be cloned via cloneUniforms() or mergeUniforms().' );
  7321. dst[ u ][ p ] = null;
  7322. } else {
  7323. dst[ u ][ p ] = property.clone();
  7324. }
  7325. } else if ( Array.isArray( property ) ) {
  7326. dst[ u ][ p ] = property.slice();
  7327. } else {
  7328. dst[ u ][ p ] = property;
  7329. }
  7330. }
  7331. }
  7332. return dst;
  7333. }
  7334. function mergeUniforms( uniforms ) {
  7335. const merged = {};
  7336. for ( let u = 0; u < uniforms.length; u ++ ) {
  7337. const tmp = cloneUniforms( uniforms[ u ] );
  7338. for ( const p in tmp ) {
  7339. merged[ p ] = tmp[ p ];
  7340. }
  7341. }
  7342. return merged;
  7343. }
  7344. function cloneUniformsGroups( src ) {
  7345. const dst = [];
  7346. for ( let u = 0; u < src.length; u ++ ) {
  7347. dst.push( src[ u ].clone() );
  7348. }
  7349. return dst;
  7350. }
  7351. function getUnlitUniformColorSpace( renderer ) {
  7352. const currentRenderTarget = renderer.getRenderTarget();
  7353. if ( currentRenderTarget === null ) {
  7354. // https://github.com/mrdoob/three.js/pull/23937#issuecomment-1111067398
  7355. return renderer.outputColorSpace;
  7356. }
  7357. // https://github.com/mrdoob/three.js/issues/27868
  7358. if ( currentRenderTarget.isXRRenderTarget === true ) {
  7359. return currentRenderTarget.texture.colorSpace;
  7360. }
  7361. return ColorManagement.workingColorSpace;
  7362. }
  7363. // Legacy
  7364. const UniformsUtils = { clone: cloneUniforms, merge: mergeUniforms };
  7365. var default_vertex = "void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}";
  7366. var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}";
  7367. class ShaderMaterial extends Material {
  7368. constructor( parameters ) {
  7369. super();
  7370. this.isShaderMaterial = true;
  7371. this.type = 'ShaderMaterial';
  7372. this.defines = {};
  7373. this.uniforms = {};
  7374. this.uniformsGroups = [];
  7375. this.vertexShader = default_vertex;
  7376. this.fragmentShader = default_fragment;
  7377. this.linewidth = 1;
  7378. this.wireframe = false;
  7379. this.wireframeLinewidth = 1;
  7380. this.fog = false; // set to use scene fog
  7381. this.lights = false; // set to use scene lights
  7382. this.clipping = false; // set to use user-defined clipping planes
  7383. this.forceSinglePass = true;
  7384. this.extensions = {
  7385. clipCullDistance: false, // set to use vertex shader clipping
  7386. multiDraw: false // set to use vertex shader multi_draw / enable gl_DrawID
  7387. };
  7388. // When rendered geometry doesn't include these attributes but the material does,
  7389. // use these default values in WebGL. This avoids errors when buffer data is missing.
  7390. this.defaultAttributeValues = {
  7391. 'color': [ 1, 1, 1 ],
  7392. 'uv': [ 0, 0 ],
  7393. 'uv1': [ 0, 0 ]
  7394. };
  7395. this.index0AttributeName = undefined;
  7396. this.uniformsNeedUpdate = false;
  7397. this.glslVersion = null;
  7398. if ( parameters !== undefined ) {
  7399. this.setValues( parameters );
  7400. }
  7401. }
  7402. copy( source ) {
  7403. super.copy( source );
  7404. this.fragmentShader = source.fragmentShader;
  7405. this.vertexShader = source.vertexShader;
  7406. this.uniforms = cloneUniforms( source.uniforms );
  7407. this.uniformsGroups = cloneUniformsGroups( source.uniformsGroups );
  7408. this.defines = Object.assign( {}, source.defines );
  7409. this.wireframe = source.wireframe;
  7410. this.wireframeLinewidth = source.wireframeLinewidth;
  7411. this.fog = source.fog;
  7412. this.lights = source.lights;
  7413. this.clipping = source.clipping;
  7414. this.extensions = Object.assign( {}, source.extensions );
  7415. this.glslVersion = source.glslVersion;
  7416. return this;
  7417. }
  7418. toJSON( meta ) {
  7419. const data = super.toJSON( meta );
  7420. data.glslVersion = this.glslVersion;
  7421. data.uniforms = {};
  7422. for ( const name in this.uniforms ) {
  7423. const uniform = this.uniforms[ name ];
  7424. const value = uniform.value;
  7425. if ( value && value.isTexture ) {
  7426. data.uniforms[ name ] = {
  7427. type: 't',
  7428. value: value.toJSON( meta ).uuid
  7429. };
  7430. } else if ( value && value.isColor ) {
  7431. data.uniforms[ name ] = {
  7432. type: 'c',
  7433. value: value.getHex()
  7434. };
  7435. } else if ( value && value.isVector2 ) {
  7436. data.uniforms[ name ] = {
  7437. type: 'v2',
  7438. value: value.toArray()
  7439. };
  7440. } else if ( value && value.isVector3 ) {
  7441. data.uniforms[ name ] = {
  7442. type: 'v3',
  7443. value: value.toArray()
  7444. };
  7445. } else if ( value && value.isVector4 ) {
  7446. data.uniforms[ name ] = {
  7447. type: 'v4',
  7448. value: value.toArray()
  7449. };
  7450. } else if ( value && value.isMatrix3 ) {
  7451. data.uniforms[ name ] = {
  7452. type: 'm3',
  7453. value: value.toArray()
  7454. };
  7455. } else if ( value && value.isMatrix4 ) {
  7456. data.uniforms[ name ] = {
  7457. type: 'm4',
  7458. value: value.toArray()
  7459. };
  7460. } else {
  7461. data.uniforms[ name ] = {
  7462. value: value
  7463. };
  7464. // note: the array variants v2v, v3v, v4v, m4v and tv are not supported so far
  7465. }
  7466. }
  7467. if ( Object.keys( this.defines ).length > 0 ) data.defines = this.defines;
  7468. data.vertexShader = this.vertexShader;
  7469. data.fragmentShader = this.fragmentShader;
  7470. data.lights = this.lights;
  7471. data.clipping = this.clipping;
  7472. const extensions = {};
  7473. for ( const key in this.extensions ) {
  7474. if ( this.extensions[ key ] === true ) extensions[ key ] = true;
  7475. }
  7476. if ( Object.keys( extensions ).length > 0 ) data.extensions = extensions;
  7477. return data;
  7478. }
  7479. }
  7480. class Camera extends Object3D {
  7481. constructor() {
  7482. super();
  7483. this.isCamera = true;
  7484. this.type = 'Camera';
  7485. this.matrixWorldInverse = new Matrix4();
  7486. this.projectionMatrix = new Matrix4();
  7487. this.projectionMatrixInverse = new Matrix4();
  7488. this.coordinateSystem = WebGLCoordinateSystem;
  7489. }
  7490. copy( source, recursive ) {
  7491. super.copy( source, recursive );
  7492. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7493. this.projectionMatrix.copy( source.projectionMatrix );
  7494. this.projectionMatrixInverse.copy( source.projectionMatrixInverse );
  7495. this.coordinateSystem = source.coordinateSystem;
  7496. return this;
  7497. }
  7498. getWorldDirection( target ) {
  7499. return super.getWorldDirection( target ).negate();
  7500. }
  7501. updateMatrixWorld( force ) {
  7502. super.updateMatrixWorld( force );
  7503. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7504. }
  7505. updateWorldMatrix( updateParents, updateChildren ) {
  7506. super.updateWorldMatrix( updateParents, updateChildren );
  7507. this.matrixWorldInverse.copy( this.matrixWorld ).invert();
  7508. }
  7509. clone() {
  7510. return new this.constructor().copy( this );
  7511. }
  7512. }
  7513. const _v3$1 = /*@__PURE__*/ new Vector3();
  7514. const _minTarget = /*@__PURE__*/ new Vector2();
  7515. const _maxTarget = /*@__PURE__*/ new Vector2();
  7516. class PerspectiveCamera extends Camera {
  7517. constructor( fov = 50, aspect = 1, near = 0.1, far = 2000 ) {
  7518. super();
  7519. this.isPerspectiveCamera = true;
  7520. this.type = 'PerspectiveCamera';
  7521. this.fov = fov;
  7522. this.zoom = 1;
  7523. this.near = near;
  7524. this.far = far;
  7525. this.focus = 10;
  7526. this.aspect = aspect;
  7527. this.view = null;
  7528. this.filmGauge = 35; // width of the film (default in millimeters)
  7529. this.filmOffset = 0; // horizontal film offset (same unit as gauge)
  7530. this.updateProjectionMatrix();
  7531. }
  7532. copy( source, recursive ) {
  7533. super.copy( source, recursive );
  7534. this.fov = source.fov;
  7535. this.zoom = source.zoom;
  7536. this.near = source.near;
  7537. this.far = source.far;
  7538. this.focus = source.focus;
  7539. this.aspect = source.aspect;
  7540. this.view = source.view === null ? null : Object.assign( {}, source.view );
  7541. this.filmGauge = source.filmGauge;
  7542. this.filmOffset = source.filmOffset;
  7543. return this;
  7544. }
  7545. /**
  7546. * Sets the FOV by focal length in respect to the current .filmGauge.
  7547. *
  7548. * The default film gauge is 35, so that the focal length can be specified for
  7549. * a 35mm (full frame) camera.
  7550. *
  7551. * Values for focal length and film gauge must have the same unit.
  7552. */
  7553. setFocalLength( focalLength ) {
  7554. /** see {@link http://www.bobatkins.com/photography/technical/field_of_view.html} */
  7555. const vExtentSlope = 0.5 * this.getFilmHeight() / focalLength;
  7556. this.fov = RAD2DEG * 2 * Math.atan( vExtentSlope );
  7557. this.updateProjectionMatrix();
  7558. }
  7559. /**
  7560. * Calculates the focal length from the current .fov and .filmGauge.
  7561. */
  7562. getFocalLength() {
  7563. const vExtentSlope = Math.tan( DEG2RAD * 0.5 * this.fov );
  7564. return 0.5 * this.getFilmHeight() / vExtentSlope;
  7565. }
  7566. getEffectiveFOV() {
  7567. return RAD2DEG * 2 * Math.atan(
  7568. Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom );
  7569. }
  7570. getFilmWidth() {
  7571. // film not completely covered in portrait format (aspect < 1)
  7572. return this.filmGauge * Math.min( this.aspect, 1 );
  7573. }
  7574. getFilmHeight() {
  7575. // film not completely covered in landscape format (aspect > 1)
  7576. return this.filmGauge / Math.max( this.aspect, 1 );
  7577. }
  7578. /**
  7579. * Computes the 2D bounds of the camera's viewable rectangle at a given distance along the viewing direction.
  7580. * Sets minTarget and maxTarget to the coordinates of the lower-left and upper-right corners of the view rectangle.
  7581. */
  7582. getViewBounds( distance, minTarget, maxTarget ) {
  7583. _v3$1.set( - 1, - 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7584. minTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7585. _v3$1.set( 1, 1, 0.5 ).applyMatrix4( this.projectionMatrixInverse );
  7586. maxTarget.set( _v3$1.x, _v3$1.y ).multiplyScalar( - distance / _v3$1.z );
  7587. }
  7588. /**
  7589. * Computes the width and height of the camera's viewable rectangle at a given distance along the viewing direction.
  7590. * Copies the result into the target Vector2, where x is width and y is height.
  7591. */
  7592. getViewSize( distance, target ) {
  7593. this.getViewBounds( distance, _minTarget, _maxTarget );
  7594. return target.subVectors( _maxTarget, _minTarget );
  7595. }
  7596. /**
  7597. * Sets an offset in a larger frustum. This is useful for multi-window or
  7598. * multi-monitor/multi-machine setups.
  7599. *
  7600. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7601. * the monitors are in grid like this
  7602. *
  7603. * +---+---+---+
  7604. * | A | B | C |
  7605. * +---+---+---+
  7606. * | D | E | F |
  7607. * +---+---+---+
  7608. *
  7609. * then for each monitor you would call it like this
  7610. *
  7611. * const w = 1920;
  7612. * const h = 1080;
  7613. * const fullWidth = w * 3;
  7614. * const fullHeight = h * 2;
  7615. *
  7616. * --A--
  7617. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7618. * --B--
  7619. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7620. * --C--
  7621. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7622. * --D--
  7623. * camera.setViewOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7624. * --E--
  7625. * camera.setViewOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7626. * --F--
  7627. * camera.setViewOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7628. *
  7629. * Note there is no reason monitors have to be the same size or in a grid.
  7630. */
  7631. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  7632. this.aspect = fullWidth / fullHeight;
  7633. if ( this.view === null ) {
  7634. this.view = {
  7635. enabled: true,
  7636. fullWidth: 1,
  7637. fullHeight: 1,
  7638. offsetX: 0,
  7639. offsetY: 0,
  7640. width: 1,
  7641. height: 1
  7642. };
  7643. }
  7644. this.view.enabled = true;
  7645. this.view.fullWidth = fullWidth;
  7646. this.view.fullHeight = fullHeight;
  7647. this.view.offsetX = x;
  7648. this.view.offsetY = y;
  7649. this.view.width = width;
  7650. this.view.height = height;
  7651. this.updateProjectionMatrix();
  7652. }
  7653. clearViewOffset() {
  7654. if ( this.view !== null ) {
  7655. this.view.enabled = false;
  7656. }
  7657. this.updateProjectionMatrix();
  7658. }
  7659. updateProjectionMatrix() {
  7660. const near = this.near;
  7661. let top = near * Math.tan( DEG2RAD * 0.5 * this.fov ) / this.zoom;
  7662. let height = 2 * top;
  7663. let width = this.aspect * height;
  7664. let left = - 0.5 * width;
  7665. const view = this.view;
  7666. if ( this.view !== null && this.view.enabled ) {
  7667. const fullWidth = view.fullWidth,
  7668. fullHeight = view.fullHeight;
  7669. left += view.offsetX * width / fullWidth;
  7670. top -= view.offsetY * height / fullHeight;
  7671. width *= view.width / fullWidth;
  7672. height *= view.height / fullHeight;
  7673. }
  7674. const skew = this.filmOffset;
  7675. if ( skew !== 0 ) left += near * skew / this.getFilmWidth();
  7676. this.projectionMatrix.makePerspective( left, left + width, top, top - height, near, this.far, this.coordinateSystem );
  7677. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  7678. }
  7679. toJSON( meta ) {
  7680. const data = super.toJSON( meta );
  7681. data.object.fov = this.fov;
  7682. data.object.zoom = this.zoom;
  7683. data.object.near = this.near;
  7684. data.object.far = this.far;
  7685. data.object.focus = this.focus;
  7686. data.object.aspect = this.aspect;
  7687. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  7688. data.object.filmGauge = this.filmGauge;
  7689. data.object.filmOffset = this.filmOffset;
  7690. return data;
  7691. }
  7692. }
  7693. const fov = - 90; // negative fov is not an error
  7694. const aspect = 1;
  7695. class CubeCamera extends Object3D {
  7696. constructor( near, far, renderTarget ) {
  7697. super();
  7698. this.type = 'CubeCamera';
  7699. this.renderTarget = renderTarget;
  7700. this.coordinateSystem = null;
  7701. this.activeMipmapLevel = 0;
  7702. const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
  7703. cameraPX.layers = this.layers;
  7704. this.add( cameraPX );
  7705. const cameraNX = new PerspectiveCamera( fov, aspect, near, far );
  7706. cameraNX.layers = this.layers;
  7707. this.add( cameraNX );
  7708. const cameraPY = new PerspectiveCamera( fov, aspect, near, far );
  7709. cameraPY.layers = this.layers;
  7710. this.add( cameraPY );
  7711. const cameraNY = new PerspectiveCamera( fov, aspect, near, far );
  7712. cameraNY.layers = this.layers;
  7713. this.add( cameraNY );
  7714. const cameraPZ = new PerspectiveCamera( fov, aspect, near, far );
  7715. cameraPZ.layers = this.layers;
  7716. this.add( cameraPZ );
  7717. const cameraNZ = new PerspectiveCamera( fov, aspect, near, far );
  7718. cameraNZ.layers = this.layers;
  7719. this.add( cameraNZ );
  7720. }
  7721. updateCoordinateSystem() {
  7722. const coordinateSystem = this.coordinateSystem;
  7723. const cameras = this.children.concat();
  7724. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = cameras;
  7725. for ( const camera of cameras ) this.remove( camera );
  7726. if ( coordinateSystem === WebGLCoordinateSystem ) {
  7727. cameraPX.up.set( 0, 1, 0 );
  7728. cameraPX.lookAt( 1, 0, 0 );
  7729. cameraNX.up.set( 0, 1, 0 );
  7730. cameraNX.lookAt( - 1, 0, 0 );
  7731. cameraPY.up.set( 0, 0, - 1 );
  7732. cameraPY.lookAt( 0, 1, 0 );
  7733. cameraNY.up.set( 0, 0, 1 );
  7734. cameraNY.lookAt( 0, - 1, 0 );
  7735. cameraPZ.up.set( 0, 1, 0 );
  7736. cameraPZ.lookAt( 0, 0, 1 );
  7737. cameraNZ.up.set( 0, 1, 0 );
  7738. cameraNZ.lookAt( 0, 0, - 1 );
  7739. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  7740. cameraPX.up.set( 0, - 1, 0 );
  7741. cameraPX.lookAt( - 1, 0, 0 );
  7742. cameraNX.up.set( 0, - 1, 0 );
  7743. cameraNX.lookAt( 1, 0, 0 );
  7744. cameraPY.up.set( 0, 0, 1 );
  7745. cameraPY.lookAt( 0, 1, 0 );
  7746. cameraNY.up.set( 0, 0, - 1 );
  7747. cameraNY.lookAt( 0, - 1, 0 );
  7748. cameraPZ.up.set( 0, - 1, 0 );
  7749. cameraPZ.lookAt( 0, 0, 1 );
  7750. cameraNZ.up.set( 0, - 1, 0 );
  7751. cameraNZ.lookAt( 0, 0, - 1 );
  7752. } else {
  7753. throw new Error( 'THREE.CubeCamera.updateCoordinateSystem(): Invalid coordinate system: ' + coordinateSystem );
  7754. }
  7755. for ( const camera of cameras ) {
  7756. this.add( camera );
  7757. camera.updateMatrixWorld();
  7758. }
  7759. }
  7760. update( renderer, scene ) {
  7761. if ( this.parent === null ) this.updateMatrixWorld();
  7762. const { renderTarget, activeMipmapLevel } = this;
  7763. if ( this.coordinateSystem !== renderer.coordinateSystem ) {
  7764. this.coordinateSystem = renderer.coordinateSystem;
  7765. this.updateCoordinateSystem();
  7766. }
  7767. const [ cameraPX, cameraNX, cameraPY, cameraNY, cameraPZ, cameraNZ ] = this.children;
  7768. const currentRenderTarget = renderer.getRenderTarget();
  7769. const currentActiveCubeFace = renderer.getActiveCubeFace();
  7770. const currentActiveMipmapLevel = renderer.getActiveMipmapLevel();
  7771. const currentXrEnabled = renderer.xr.enabled;
  7772. renderer.xr.enabled = false;
  7773. const generateMipmaps = renderTarget.texture.generateMipmaps;
  7774. renderTarget.texture.generateMipmaps = false;
  7775. renderer.setRenderTarget( renderTarget, 0, activeMipmapLevel );
  7776. renderer.render( scene, cameraPX );
  7777. renderer.setRenderTarget( renderTarget, 1, activeMipmapLevel );
  7778. renderer.render( scene, cameraNX );
  7779. renderer.setRenderTarget( renderTarget, 2, activeMipmapLevel );
  7780. renderer.render( scene, cameraPY );
  7781. renderer.setRenderTarget( renderTarget, 3, activeMipmapLevel );
  7782. renderer.render( scene, cameraNY );
  7783. renderer.setRenderTarget( renderTarget, 4, activeMipmapLevel );
  7784. renderer.render( scene, cameraPZ );
  7785. // mipmaps are generated during the last call of render()
  7786. // at this point, all sides of the cube render target are defined
  7787. renderTarget.texture.generateMipmaps = generateMipmaps;
  7788. renderer.setRenderTarget( renderTarget, 5, activeMipmapLevel );
  7789. renderer.render( scene, cameraNZ );
  7790. renderer.setRenderTarget( currentRenderTarget, currentActiveCubeFace, currentActiveMipmapLevel );
  7791. renderer.xr.enabled = currentXrEnabled;
  7792. renderTarget.texture.needsPMREMUpdate = true;
  7793. }
  7794. }
  7795. class CubeTexture extends Texture {
  7796. constructor( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace ) {
  7797. images = images !== undefined ? images : [];
  7798. mapping = mapping !== undefined ? mapping : CubeReflectionMapping;
  7799. super( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  7800. this.isCubeTexture = true;
  7801. this.flipY = false;
  7802. }
  7803. get images() {
  7804. return this.image;
  7805. }
  7806. set images( value ) {
  7807. this.image = value;
  7808. }
  7809. }
  7810. class WebGLCubeRenderTarget extends WebGLRenderTarget {
  7811. constructor( size = 1, options = {} ) {
  7812. super( size, size, options );
  7813. this.isWebGLCubeRenderTarget = true;
  7814. const image = { width: size, height: size, depth: 1 };
  7815. const images = [ image, image, image, image, image, image ];
  7816. this.texture = new CubeTexture( images, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
  7817. // By convention -- likely based on the RenderMan spec from the 1990's -- cube maps are specified by WebGL (and three.js)
  7818. // in a coordinate system in which positive-x is to the right when looking up the positive-z axis -- in other words,
  7819. // in a left-handed coordinate system. By continuing this convention, preexisting cube maps continued to render correctly.
  7820. // three.js uses a right-handed coordinate system. So environment maps used in three.js appear to have px and nx swapped
  7821. // and the flag isRenderTargetTexture controls this conversion. The flip is not required when using WebGLCubeRenderTarget.texture
  7822. // as a cube texture (this is detected when isRenderTargetTexture is set to true for cube textures).
  7823. this.texture.isRenderTargetTexture = true;
  7824. this.texture.generateMipmaps = options.generateMipmaps !== undefined ? options.generateMipmaps : false;
  7825. this.texture.minFilter = options.minFilter !== undefined ? options.minFilter : LinearFilter;
  7826. }
  7827. fromEquirectangularTexture( renderer, texture ) {
  7828. this.texture.type = texture.type;
  7829. this.texture.colorSpace = texture.colorSpace;
  7830. this.texture.generateMipmaps = texture.generateMipmaps;
  7831. this.texture.minFilter = texture.minFilter;
  7832. this.texture.magFilter = texture.magFilter;
  7833. const shader = {
  7834. uniforms: {
  7835. tEquirect: { value: null },
  7836. },
  7837. vertexShader: /* glsl */`
  7838. varying vec3 vWorldDirection;
  7839. vec3 transformDirection( in vec3 dir, in mat4 matrix ) {
  7840. return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );
  7841. }
  7842. void main() {
  7843. vWorldDirection = transformDirection( position, modelMatrix );
  7844. #include <begin_vertex>
  7845. #include <project_vertex>
  7846. }
  7847. `,
  7848. fragmentShader: /* glsl */`
  7849. uniform sampler2D tEquirect;
  7850. varying vec3 vWorldDirection;
  7851. #include <common>
  7852. void main() {
  7853. vec3 direction = normalize( vWorldDirection );
  7854. vec2 sampleUV = equirectUv( direction );
  7855. gl_FragColor = texture2D( tEquirect, sampleUV );
  7856. }
  7857. `
  7858. };
  7859. const geometry = new BoxGeometry( 5, 5, 5 );
  7860. const material = new ShaderMaterial( {
  7861. name: 'CubemapFromEquirect',
  7862. uniforms: cloneUniforms( shader.uniforms ),
  7863. vertexShader: shader.vertexShader,
  7864. fragmentShader: shader.fragmentShader,
  7865. side: BackSide,
  7866. blending: NoBlending
  7867. } );
  7868. material.uniforms.tEquirect.value = texture;
  7869. const mesh = new Mesh( geometry, material );
  7870. const currentMinFilter = texture.minFilter;
  7871. // Avoid blurred poles
  7872. if ( texture.minFilter === LinearMipmapLinearFilter ) texture.minFilter = LinearFilter;
  7873. const camera = new CubeCamera( 1, 10, this );
  7874. camera.update( renderer, mesh );
  7875. texture.minFilter = currentMinFilter;
  7876. mesh.geometry.dispose();
  7877. mesh.material.dispose();
  7878. return this;
  7879. }
  7880. clear( renderer, color, depth, stencil ) {
  7881. const currentRenderTarget = renderer.getRenderTarget();
  7882. for ( let i = 0; i < 6; i ++ ) {
  7883. renderer.setRenderTarget( this, i );
  7884. renderer.clear( color, depth, stencil );
  7885. }
  7886. renderer.setRenderTarget( currentRenderTarget );
  7887. }
  7888. }
  7889. class FogExp2 {
  7890. constructor( color, density = 0.00025 ) {
  7891. this.isFogExp2 = true;
  7892. this.name = '';
  7893. this.color = new Color( color );
  7894. this.density = density;
  7895. }
  7896. clone() {
  7897. return new FogExp2( this.color, this.density );
  7898. }
  7899. toJSON( /* meta */ ) {
  7900. return {
  7901. type: 'FogExp2',
  7902. name: this.name,
  7903. color: this.color.getHex(),
  7904. density: this.density
  7905. };
  7906. }
  7907. }
  7908. class Fog {
  7909. constructor( color, near = 1, far = 1000 ) {
  7910. this.isFog = true;
  7911. this.name = '';
  7912. this.color = new Color( color );
  7913. this.near = near;
  7914. this.far = far;
  7915. }
  7916. clone() {
  7917. return new Fog( this.color, this.near, this.far );
  7918. }
  7919. toJSON( /* meta */ ) {
  7920. return {
  7921. type: 'Fog',
  7922. name: this.name,
  7923. color: this.color.getHex(),
  7924. near: this.near,
  7925. far: this.far
  7926. };
  7927. }
  7928. }
  7929. class Scene extends Object3D {
  7930. constructor() {
  7931. super();
  7932. this.isScene = true;
  7933. this.type = 'Scene';
  7934. this.background = null;
  7935. this.environment = null;
  7936. this.fog = null;
  7937. this.backgroundBlurriness = 0;
  7938. this.backgroundIntensity = 1;
  7939. this.backgroundRotation = new Euler();
  7940. this.environmentIntensity = 1;
  7941. this.environmentRotation = new Euler();
  7942. this.overrideMaterial = null;
  7943. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  7944. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) );
  7945. }
  7946. }
  7947. copy( source, recursive ) {
  7948. super.copy( source, recursive );
  7949. if ( source.background !== null ) this.background = source.background.clone();
  7950. if ( source.environment !== null ) this.environment = source.environment.clone();
  7951. if ( source.fog !== null ) this.fog = source.fog.clone();
  7952. this.backgroundBlurriness = source.backgroundBlurriness;
  7953. this.backgroundIntensity = source.backgroundIntensity;
  7954. this.backgroundRotation.copy( source.backgroundRotation );
  7955. this.environmentIntensity = source.environmentIntensity;
  7956. this.environmentRotation.copy( source.environmentRotation );
  7957. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  7958. this.matrixAutoUpdate = source.matrixAutoUpdate;
  7959. return this;
  7960. }
  7961. toJSON( meta ) {
  7962. const data = super.toJSON( meta );
  7963. if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
  7964. if ( this.backgroundBlurriness > 0 ) data.object.backgroundBlurriness = this.backgroundBlurriness;
  7965. if ( this.backgroundIntensity !== 1 ) data.object.backgroundIntensity = this.backgroundIntensity;
  7966. data.object.backgroundRotation = this.backgroundRotation.toArray();
  7967. if ( this.environmentIntensity !== 1 ) data.object.environmentIntensity = this.environmentIntensity;
  7968. data.object.environmentRotation = this.environmentRotation.toArray();
  7969. return data;
  7970. }
  7971. }
  7972. class InterleavedBuffer {
  7973. constructor( array, stride ) {
  7974. this.isInterleavedBuffer = true;
  7975. this.array = array;
  7976. this.stride = stride;
  7977. this.count = array !== undefined ? array.length / stride : 0;
  7978. this.usage = StaticDrawUsage;
  7979. this.updateRanges = [];
  7980. this.version = 0;
  7981. this.uuid = generateUUID();
  7982. }
  7983. onUploadCallback() {}
  7984. set needsUpdate( value ) {
  7985. if ( value === true ) this.version ++;
  7986. }
  7987. setUsage( value ) {
  7988. this.usage = value;
  7989. return this;
  7990. }
  7991. addUpdateRange( start, count ) {
  7992. this.updateRanges.push( { start, count } );
  7993. }
  7994. clearUpdateRanges() {
  7995. this.updateRanges.length = 0;
  7996. }
  7997. copy( source ) {
  7998. this.array = new source.array.constructor( source.array );
  7999. this.count = source.count;
  8000. this.stride = source.stride;
  8001. this.usage = source.usage;
  8002. return this;
  8003. }
  8004. copyAt( index1, attribute, index2 ) {
  8005. index1 *= this.stride;
  8006. index2 *= attribute.stride;
  8007. for ( let i = 0, l = this.stride; i < l; i ++ ) {
  8008. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  8009. }
  8010. return this;
  8011. }
  8012. set( value, offset = 0 ) {
  8013. this.array.set( value, offset );
  8014. return this;
  8015. }
  8016. clone( data ) {
  8017. if ( data.arrayBuffers === undefined ) {
  8018. data.arrayBuffers = {};
  8019. }
  8020. if ( this.array.buffer._uuid === undefined ) {
  8021. this.array.buffer._uuid = generateUUID();
  8022. }
  8023. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8024. data.arrayBuffers[ this.array.buffer._uuid ] = this.array.slice( 0 ).buffer;
  8025. }
  8026. const array = new this.array.constructor( data.arrayBuffers[ this.array.buffer._uuid ] );
  8027. const ib = new this.constructor( array, this.stride );
  8028. ib.setUsage( this.usage );
  8029. return ib;
  8030. }
  8031. onUpload( callback ) {
  8032. this.onUploadCallback = callback;
  8033. return this;
  8034. }
  8035. toJSON( data ) {
  8036. if ( data.arrayBuffers === undefined ) {
  8037. data.arrayBuffers = {};
  8038. }
  8039. // generate UUID for array buffer if necessary
  8040. if ( this.array.buffer._uuid === undefined ) {
  8041. this.array.buffer._uuid = generateUUID();
  8042. }
  8043. if ( data.arrayBuffers[ this.array.buffer._uuid ] === undefined ) {
  8044. data.arrayBuffers[ this.array.buffer._uuid ] = Array.from( new Uint32Array( this.array.buffer ) );
  8045. }
  8046. //
  8047. return {
  8048. uuid: this.uuid,
  8049. buffer: this.array.buffer._uuid,
  8050. type: this.array.constructor.name,
  8051. stride: this.stride
  8052. };
  8053. }
  8054. }
  8055. const _vector$7 = /*@__PURE__*/ new Vector3();
  8056. class InterleavedBufferAttribute {
  8057. constructor( interleavedBuffer, itemSize, offset, normalized = false ) {
  8058. this.isInterleavedBufferAttribute = true;
  8059. this.name = '';
  8060. this.data = interleavedBuffer;
  8061. this.itemSize = itemSize;
  8062. this.offset = offset;
  8063. this.normalized = normalized;
  8064. }
  8065. get count() {
  8066. return this.data.count;
  8067. }
  8068. get array() {
  8069. return this.data.array;
  8070. }
  8071. set needsUpdate( value ) {
  8072. this.data.needsUpdate = value;
  8073. }
  8074. applyMatrix4( m ) {
  8075. for ( let i = 0, l = this.data.count; i < l; i ++ ) {
  8076. _vector$7.fromBufferAttribute( this, i );
  8077. _vector$7.applyMatrix4( m );
  8078. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8079. }
  8080. return this;
  8081. }
  8082. applyNormalMatrix( m ) {
  8083. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8084. _vector$7.fromBufferAttribute( this, i );
  8085. _vector$7.applyNormalMatrix( m );
  8086. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8087. }
  8088. return this;
  8089. }
  8090. transformDirection( m ) {
  8091. for ( let i = 0, l = this.count; i < l; i ++ ) {
  8092. _vector$7.fromBufferAttribute( this, i );
  8093. _vector$7.transformDirection( m );
  8094. this.setXYZ( i, _vector$7.x, _vector$7.y, _vector$7.z );
  8095. }
  8096. return this;
  8097. }
  8098. getComponent( index, component ) {
  8099. let value = this.array[ index * this.data.stride + this.offset + component ];
  8100. if ( this.normalized ) value = denormalize( value, this.array );
  8101. return value;
  8102. }
  8103. setComponent( index, component, value ) {
  8104. if ( this.normalized ) value = normalize( value, this.array );
  8105. this.data.array[ index * this.data.stride + this.offset + component ] = value;
  8106. return this;
  8107. }
  8108. setX( index, x ) {
  8109. if ( this.normalized ) x = normalize( x, this.array );
  8110. this.data.array[ index * this.data.stride + this.offset ] = x;
  8111. return this;
  8112. }
  8113. setY( index, y ) {
  8114. if ( this.normalized ) y = normalize( y, this.array );
  8115. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  8116. return this;
  8117. }
  8118. setZ( index, z ) {
  8119. if ( this.normalized ) z = normalize( z, this.array );
  8120. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  8121. return this;
  8122. }
  8123. setW( index, w ) {
  8124. if ( this.normalized ) w = normalize( w, this.array );
  8125. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  8126. return this;
  8127. }
  8128. getX( index ) {
  8129. let x = this.data.array[ index * this.data.stride + this.offset ];
  8130. if ( this.normalized ) x = denormalize( x, this.array );
  8131. return x;
  8132. }
  8133. getY( index ) {
  8134. let y = this.data.array[ index * this.data.stride + this.offset + 1 ];
  8135. if ( this.normalized ) y = denormalize( y, this.array );
  8136. return y;
  8137. }
  8138. getZ( index ) {
  8139. let z = this.data.array[ index * this.data.stride + this.offset + 2 ];
  8140. if ( this.normalized ) z = denormalize( z, this.array );
  8141. return z;
  8142. }
  8143. getW( index ) {
  8144. let w = this.data.array[ index * this.data.stride + this.offset + 3 ];
  8145. if ( this.normalized ) w = denormalize( w, this.array );
  8146. return w;
  8147. }
  8148. setXY( index, x, y ) {
  8149. index = index * this.data.stride + this.offset;
  8150. if ( this.normalized ) {
  8151. x = normalize( x, this.array );
  8152. y = normalize( y, this.array );
  8153. }
  8154. this.data.array[ index + 0 ] = x;
  8155. this.data.array[ index + 1 ] = y;
  8156. return this;
  8157. }
  8158. setXYZ( index, x, y, z ) {
  8159. index = index * this.data.stride + this.offset;
  8160. if ( this.normalized ) {
  8161. x = normalize( x, this.array );
  8162. y = normalize( y, this.array );
  8163. z = normalize( z, this.array );
  8164. }
  8165. this.data.array[ index + 0 ] = x;
  8166. this.data.array[ index + 1 ] = y;
  8167. this.data.array[ index + 2 ] = z;
  8168. return this;
  8169. }
  8170. setXYZW( index, x, y, z, w ) {
  8171. index = index * this.data.stride + this.offset;
  8172. if ( this.normalized ) {
  8173. x = normalize( x, this.array );
  8174. y = normalize( y, this.array );
  8175. z = normalize( z, this.array );
  8176. w = normalize( w, this.array );
  8177. }
  8178. this.data.array[ index + 0 ] = x;
  8179. this.data.array[ index + 1 ] = y;
  8180. this.data.array[ index + 2 ] = z;
  8181. this.data.array[ index + 3 ] = w;
  8182. return this;
  8183. }
  8184. clone( data ) {
  8185. if ( data === undefined ) {
  8186. console.log( 'THREE.InterleavedBufferAttribute.clone(): Cloning an interleaved buffer attribute will de-interleave buffer data.' );
  8187. const array = [];
  8188. for ( let i = 0; i < this.count; i ++ ) {
  8189. const index = i * this.data.stride + this.offset;
  8190. for ( let j = 0; j < this.itemSize; j ++ ) {
  8191. array.push( this.data.array[ index + j ] );
  8192. }
  8193. }
  8194. return new BufferAttribute( new this.array.constructor( array ), this.itemSize, this.normalized );
  8195. } else {
  8196. if ( data.interleavedBuffers === undefined ) {
  8197. data.interleavedBuffers = {};
  8198. }
  8199. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8200. data.interleavedBuffers[ this.data.uuid ] = this.data.clone( data );
  8201. }
  8202. return new InterleavedBufferAttribute( data.interleavedBuffers[ this.data.uuid ], this.itemSize, this.offset, this.normalized );
  8203. }
  8204. }
  8205. toJSON( data ) {
  8206. if ( data === undefined ) {
  8207. console.log( 'THREE.InterleavedBufferAttribute.toJSON(): Serializing an interleaved buffer attribute will de-interleave buffer data.' );
  8208. const array = [];
  8209. for ( let i = 0; i < this.count; i ++ ) {
  8210. const index = i * this.data.stride + this.offset;
  8211. for ( let j = 0; j < this.itemSize; j ++ ) {
  8212. array.push( this.data.array[ index + j ] );
  8213. }
  8214. }
  8215. // de-interleave data and save it as an ordinary buffer attribute for now
  8216. return {
  8217. itemSize: this.itemSize,
  8218. type: this.array.constructor.name,
  8219. array: array,
  8220. normalized: this.normalized
  8221. };
  8222. } else {
  8223. // save as true interleaved attribute
  8224. if ( data.interleavedBuffers === undefined ) {
  8225. data.interleavedBuffers = {};
  8226. }
  8227. if ( data.interleavedBuffers[ this.data.uuid ] === undefined ) {
  8228. data.interleavedBuffers[ this.data.uuid ] = this.data.toJSON( data );
  8229. }
  8230. return {
  8231. isInterleavedBufferAttribute: true,
  8232. itemSize: this.itemSize,
  8233. data: this.data.uuid,
  8234. offset: this.offset,
  8235. normalized: this.normalized
  8236. };
  8237. }
  8238. }
  8239. }
  8240. class SpriteMaterial extends Material {
  8241. constructor( parameters ) {
  8242. super();
  8243. this.isSpriteMaterial = true;
  8244. this.type = 'SpriteMaterial';
  8245. this.color = new Color( 0xffffff );
  8246. this.map = null;
  8247. this.alphaMap = null;
  8248. this.rotation = 0;
  8249. this.sizeAttenuation = true;
  8250. this.transparent = true;
  8251. this.fog = true;
  8252. this.setValues( parameters );
  8253. }
  8254. copy( source ) {
  8255. super.copy( source );
  8256. this.color.copy( source.color );
  8257. this.map = source.map;
  8258. this.alphaMap = source.alphaMap;
  8259. this.rotation = source.rotation;
  8260. this.sizeAttenuation = source.sizeAttenuation;
  8261. this.fog = source.fog;
  8262. return this;
  8263. }
  8264. }
  8265. let _geometry;
  8266. const _intersectPoint = /*@__PURE__*/ new Vector3();
  8267. const _worldScale = /*@__PURE__*/ new Vector3();
  8268. const _mvPosition = /*@__PURE__*/ new Vector3();
  8269. const _alignedPosition = /*@__PURE__*/ new Vector2();
  8270. const _rotatedPosition = /*@__PURE__*/ new Vector2();
  8271. const _viewWorldMatrix = /*@__PURE__*/ new Matrix4();
  8272. const _vA = /*@__PURE__*/ new Vector3();
  8273. const _vB = /*@__PURE__*/ new Vector3();
  8274. const _vC = /*@__PURE__*/ new Vector3();
  8275. const _uvA = /*@__PURE__*/ new Vector2();
  8276. const _uvB = /*@__PURE__*/ new Vector2();
  8277. const _uvC = /*@__PURE__*/ new Vector2();
  8278. class Sprite extends Object3D {
  8279. constructor( material = new SpriteMaterial() ) {
  8280. super();
  8281. this.isSprite = true;
  8282. this.type = 'Sprite';
  8283. if ( _geometry === undefined ) {
  8284. _geometry = new BufferGeometry();
  8285. const float32Array = new Float32Array( [
  8286. - 0.5, - 0.5, 0, 0, 0,
  8287. 0.5, - 0.5, 0, 1, 0,
  8288. 0.5, 0.5, 0, 1, 1,
  8289. - 0.5, 0.5, 0, 0, 1
  8290. ] );
  8291. const interleavedBuffer = new InterleavedBuffer( float32Array, 5 );
  8292. _geometry.setIndex( [ 0, 1, 2, 0, 2, 3 ] );
  8293. _geometry.setAttribute( 'position', new InterleavedBufferAttribute( interleavedBuffer, 3, 0, false ) );
  8294. _geometry.setAttribute( 'uv', new InterleavedBufferAttribute( interleavedBuffer, 2, 3, false ) );
  8295. }
  8296. this.geometry = _geometry;
  8297. this.material = material;
  8298. this.center = new Vector2( 0.5, 0.5 );
  8299. }
  8300. raycast( raycaster, intersects ) {
  8301. if ( raycaster.camera === null ) {
  8302. console.error( 'THREE.Sprite: "Raycaster.camera" needs to be set in order to raycast against sprites.' );
  8303. }
  8304. _worldScale.setFromMatrixScale( this.matrixWorld );
  8305. _viewWorldMatrix.copy( raycaster.camera.matrixWorld );
  8306. this.modelViewMatrix.multiplyMatrices( raycaster.camera.matrixWorldInverse, this.matrixWorld );
  8307. _mvPosition.setFromMatrixPosition( this.modelViewMatrix );
  8308. if ( raycaster.camera.isPerspectiveCamera && this.material.sizeAttenuation === false ) {
  8309. _worldScale.multiplyScalar( - _mvPosition.z );
  8310. }
  8311. const rotation = this.material.rotation;
  8312. let sin, cos;
  8313. if ( rotation !== 0 ) {
  8314. cos = Math.cos( rotation );
  8315. sin = Math.sin( rotation );
  8316. }
  8317. const center = this.center;
  8318. transformVertex( _vA.set( - 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8319. transformVertex( _vB.set( 0.5, - 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8320. transformVertex( _vC.set( 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8321. _uvA.set( 0, 0 );
  8322. _uvB.set( 1, 0 );
  8323. _uvC.set( 1, 1 );
  8324. // check first triangle
  8325. let intersect = raycaster.ray.intersectTriangle( _vA, _vB, _vC, false, _intersectPoint );
  8326. if ( intersect === null ) {
  8327. // check second triangle
  8328. transformVertex( _vB.set( - 0.5, 0.5, 0 ), _mvPosition, center, _worldScale, sin, cos );
  8329. _uvB.set( 0, 1 );
  8330. intersect = raycaster.ray.intersectTriangle( _vA, _vC, _vB, false, _intersectPoint );
  8331. if ( intersect === null ) {
  8332. return;
  8333. }
  8334. }
  8335. const distance = raycaster.ray.origin.distanceTo( _intersectPoint );
  8336. if ( distance < raycaster.near || distance > raycaster.far ) return;
  8337. intersects.push( {
  8338. distance: distance,
  8339. point: _intersectPoint.clone(),
  8340. uv: Triangle.getInterpolation( _intersectPoint, _vA, _vB, _vC, _uvA, _uvB, _uvC, new Vector2() ),
  8341. face: null,
  8342. object: this
  8343. } );
  8344. }
  8345. copy( source, recursive ) {
  8346. super.copy( source, recursive );
  8347. if ( source.center !== undefined ) this.center.copy( source.center );
  8348. this.material = source.material;
  8349. return this;
  8350. }
  8351. }
  8352. function transformVertex( vertexPosition, mvPosition, center, scale, sin, cos ) {
  8353. // compute position in camera space
  8354. _alignedPosition.subVectors( vertexPosition, center ).addScalar( 0.5 ).multiply( scale );
  8355. // to check if rotation is not zero
  8356. if ( sin !== undefined ) {
  8357. _rotatedPosition.x = ( cos * _alignedPosition.x ) - ( sin * _alignedPosition.y );
  8358. _rotatedPosition.y = ( sin * _alignedPosition.x ) + ( cos * _alignedPosition.y );
  8359. } else {
  8360. _rotatedPosition.copy( _alignedPosition );
  8361. }
  8362. vertexPosition.copy( mvPosition );
  8363. vertexPosition.x += _rotatedPosition.x;
  8364. vertexPosition.y += _rotatedPosition.y;
  8365. // transform to world space
  8366. vertexPosition.applyMatrix4( _viewWorldMatrix );
  8367. }
  8368. const _v1$2 = /*@__PURE__*/ new Vector3();
  8369. const _v2$1 = /*@__PURE__*/ new Vector3();
  8370. class LOD extends Object3D {
  8371. constructor() {
  8372. super();
  8373. this._currentLevel = 0;
  8374. this.type = 'LOD';
  8375. Object.defineProperties( this, {
  8376. levels: {
  8377. enumerable: true,
  8378. value: []
  8379. },
  8380. isLOD: {
  8381. value: true,
  8382. }
  8383. } );
  8384. this.autoUpdate = true;
  8385. }
  8386. copy( source ) {
  8387. super.copy( source, false );
  8388. const levels = source.levels;
  8389. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8390. const level = levels[ i ];
  8391. this.addLevel( level.object.clone(), level.distance, level.hysteresis );
  8392. }
  8393. this.autoUpdate = source.autoUpdate;
  8394. return this;
  8395. }
  8396. addLevel( object, distance = 0, hysteresis = 0 ) {
  8397. distance = Math.abs( distance );
  8398. const levels = this.levels;
  8399. let l;
  8400. for ( l = 0; l < levels.length; l ++ ) {
  8401. if ( distance < levels[ l ].distance ) {
  8402. break;
  8403. }
  8404. }
  8405. levels.splice( l, 0, { distance: distance, hysteresis: hysteresis, object: object } );
  8406. this.add( object );
  8407. return this;
  8408. }
  8409. removeLevel( distance ) {
  8410. const levels = this.levels;
  8411. for ( let i = 0; i < levels.length; i ++ ) {
  8412. if ( levels[ i ].distance === distance ) {
  8413. const removedElements = levels.splice( i, 1 );
  8414. this.remove( removedElements[ 0 ].object );
  8415. return true;
  8416. }
  8417. }
  8418. return false;
  8419. }
  8420. getCurrentLevel() {
  8421. return this._currentLevel;
  8422. }
  8423. getObjectForDistance( distance ) {
  8424. const levels = this.levels;
  8425. if ( levels.length > 0 ) {
  8426. let i, l;
  8427. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8428. let levelDistance = levels[ i ].distance;
  8429. if ( levels[ i ].object.visible ) {
  8430. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8431. }
  8432. if ( distance < levelDistance ) {
  8433. break;
  8434. }
  8435. }
  8436. return levels[ i - 1 ].object;
  8437. }
  8438. return null;
  8439. }
  8440. raycast( raycaster, intersects ) {
  8441. const levels = this.levels;
  8442. if ( levels.length > 0 ) {
  8443. _v1$2.setFromMatrixPosition( this.matrixWorld );
  8444. const distance = raycaster.ray.origin.distanceTo( _v1$2 );
  8445. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  8446. }
  8447. }
  8448. update( camera ) {
  8449. const levels = this.levels;
  8450. if ( levels.length > 1 ) {
  8451. _v1$2.setFromMatrixPosition( camera.matrixWorld );
  8452. _v2$1.setFromMatrixPosition( this.matrixWorld );
  8453. const distance = _v1$2.distanceTo( _v2$1 ) / camera.zoom;
  8454. levels[ 0 ].object.visible = true;
  8455. let i, l;
  8456. for ( i = 1, l = levels.length; i < l; i ++ ) {
  8457. let levelDistance = levels[ i ].distance;
  8458. if ( levels[ i ].object.visible ) {
  8459. levelDistance -= levelDistance * levels[ i ].hysteresis;
  8460. }
  8461. if ( distance >= levelDistance ) {
  8462. levels[ i - 1 ].object.visible = false;
  8463. levels[ i ].object.visible = true;
  8464. } else {
  8465. break;
  8466. }
  8467. }
  8468. this._currentLevel = i - 1;
  8469. for ( ; i < l; i ++ ) {
  8470. levels[ i ].object.visible = false;
  8471. }
  8472. }
  8473. }
  8474. toJSON( meta ) {
  8475. const data = super.toJSON( meta );
  8476. if ( this.autoUpdate === false ) data.object.autoUpdate = false;
  8477. data.object.levels = [];
  8478. const levels = this.levels;
  8479. for ( let i = 0, l = levels.length; i < l; i ++ ) {
  8480. const level = levels[ i ];
  8481. data.object.levels.push( {
  8482. object: level.object.uuid,
  8483. distance: level.distance,
  8484. hysteresis: level.hysteresis
  8485. } );
  8486. }
  8487. return data;
  8488. }
  8489. }
  8490. const _basePosition = /*@__PURE__*/ new Vector3();
  8491. const _skinIndex = /*@__PURE__*/ new Vector4();
  8492. const _skinWeight = /*@__PURE__*/ new Vector4();
  8493. const _vector3 = /*@__PURE__*/ new Vector3();
  8494. const _matrix4 = /*@__PURE__*/ new Matrix4();
  8495. const _vertex = /*@__PURE__*/ new Vector3();
  8496. const _sphere$5 = /*@__PURE__*/ new Sphere();
  8497. const _inverseMatrix$2 = /*@__PURE__*/ new Matrix4();
  8498. const _ray$2 = /*@__PURE__*/ new Ray();
  8499. class SkinnedMesh extends Mesh {
  8500. constructor( geometry, material ) {
  8501. super( geometry, material );
  8502. this.isSkinnedMesh = true;
  8503. this.type = 'SkinnedMesh';
  8504. this.bindMode = AttachedBindMode;
  8505. this.bindMatrix = new Matrix4();
  8506. this.bindMatrixInverse = new Matrix4();
  8507. this.boundingBox = null;
  8508. this.boundingSphere = null;
  8509. }
  8510. computeBoundingBox() {
  8511. const geometry = this.geometry;
  8512. if ( this.boundingBox === null ) {
  8513. this.boundingBox = new Box3();
  8514. }
  8515. this.boundingBox.makeEmpty();
  8516. const positionAttribute = geometry.getAttribute( 'position' );
  8517. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8518. this.getVertexPosition( i, _vertex );
  8519. this.boundingBox.expandByPoint( _vertex );
  8520. }
  8521. }
  8522. computeBoundingSphere() {
  8523. const geometry = this.geometry;
  8524. if ( this.boundingSphere === null ) {
  8525. this.boundingSphere = new Sphere();
  8526. }
  8527. this.boundingSphere.makeEmpty();
  8528. const positionAttribute = geometry.getAttribute( 'position' );
  8529. for ( let i = 0; i < positionAttribute.count; i ++ ) {
  8530. this.getVertexPosition( i, _vertex );
  8531. this.boundingSphere.expandByPoint( _vertex );
  8532. }
  8533. }
  8534. copy( source, recursive ) {
  8535. super.copy( source, recursive );
  8536. this.bindMode = source.bindMode;
  8537. this.bindMatrix.copy( source.bindMatrix );
  8538. this.bindMatrixInverse.copy( source.bindMatrixInverse );
  8539. this.skeleton = source.skeleton;
  8540. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8541. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8542. return this;
  8543. }
  8544. raycast( raycaster, intersects ) {
  8545. const material = this.material;
  8546. const matrixWorld = this.matrixWorld;
  8547. if ( material === undefined ) return;
  8548. // test with bounding sphere in world space
  8549. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8550. _sphere$5.copy( this.boundingSphere );
  8551. _sphere$5.applyMatrix4( matrixWorld );
  8552. if ( raycaster.ray.intersectsSphere( _sphere$5 ) === false ) return;
  8553. // convert ray to local space of skinned mesh
  8554. _inverseMatrix$2.copy( matrixWorld ).invert();
  8555. _ray$2.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$2 );
  8556. // test with bounding box in local space
  8557. if ( this.boundingBox !== null ) {
  8558. if ( _ray$2.intersectsBox( this.boundingBox ) === false ) return;
  8559. }
  8560. // test for intersections with geometry
  8561. this._computeIntersections( raycaster, intersects, _ray$2 );
  8562. }
  8563. getVertexPosition( index, target ) {
  8564. super.getVertexPosition( index, target );
  8565. this.applyBoneTransform( index, target );
  8566. return target;
  8567. }
  8568. bind( skeleton, bindMatrix ) {
  8569. this.skeleton = skeleton;
  8570. if ( bindMatrix === undefined ) {
  8571. this.updateMatrixWorld( true );
  8572. this.skeleton.calculateInverses();
  8573. bindMatrix = this.matrixWorld;
  8574. }
  8575. this.bindMatrix.copy( bindMatrix );
  8576. this.bindMatrixInverse.copy( bindMatrix ).invert();
  8577. }
  8578. pose() {
  8579. this.skeleton.pose();
  8580. }
  8581. normalizeSkinWeights() {
  8582. const vector = new Vector4();
  8583. const skinWeight = this.geometry.attributes.skinWeight;
  8584. for ( let i = 0, l = skinWeight.count; i < l; i ++ ) {
  8585. vector.fromBufferAttribute( skinWeight, i );
  8586. const scale = 1.0 / vector.manhattanLength();
  8587. if ( scale !== Infinity ) {
  8588. vector.multiplyScalar( scale );
  8589. } else {
  8590. vector.set( 1, 0, 0, 0 ); // do something reasonable
  8591. }
  8592. skinWeight.setXYZW( i, vector.x, vector.y, vector.z, vector.w );
  8593. }
  8594. }
  8595. updateMatrixWorld( force ) {
  8596. super.updateMatrixWorld( force );
  8597. if ( this.bindMode === AttachedBindMode ) {
  8598. this.bindMatrixInverse.copy( this.matrixWorld ).invert();
  8599. } else if ( this.bindMode === DetachedBindMode ) {
  8600. this.bindMatrixInverse.copy( this.bindMatrix ).invert();
  8601. } else {
  8602. console.warn( 'THREE.SkinnedMesh: Unrecognized bindMode: ' + this.bindMode );
  8603. }
  8604. }
  8605. applyBoneTransform( index, vector ) {
  8606. const skeleton = this.skeleton;
  8607. const geometry = this.geometry;
  8608. _skinIndex.fromBufferAttribute( geometry.attributes.skinIndex, index );
  8609. _skinWeight.fromBufferAttribute( geometry.attributes.skinWeight, index );
  8610. _basePosition.copy( vector ).applyMatrix4( this.bindMatrix );
  8611. vector.set( 0, 0, 0 );
  8612. for ( let i = 0; i < 4; i ++ ) {
  8613. const weight = _skinWeight.getComponent( i );
  8614. if ( weight !== 0 ) {
  8615. const boneIndex = _skinIndex.getComponent( i );
  8616. _matrix4.multiplyMatrices( skeleton.bones[ boneIndex ].matrixWorld, skeleton.boneInverses[ boneIndex ] );
  8617. vector.addScaledVector( _vector3.copy( _basePosition ).applyMatrix4( _matrix4 ), weight );
  8618. }
  8619. }
  8620. return vector.applyMatrix4( this.bindMatrixInverse );
  8621. }
  8622. }
  8623. class Bone extends Object3D {
  8624. constructor() {
  8625. super();
  8626. this.isBone = true;
  8627. this.type = 'Bone';
  8628. }
  8629. }
  8630. class DataTexture extends Texture {
  8631. constructor( data = null, width = 1, height = 1, format, type, mapping, wrapS, wrapT, magFilter = NearestFilter, minFilter = NearestFilter, anisotropy, colorSpace ) {
  8632. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  8633. this.isDataTexture = true;
  8634. this.image = { data: data, width: width, height: height };
  8635. this.generateMipmaps = false;
  8636. this.flipY = false;
  8637. this.unpackAlignment = 1;
  8638. }
  8639. }
  8640. const _offsetMatrix = /*@__PURE__*/ new Matrix4();
  8641. const _identityMatrix = /*@__PURE__*/ new Matrix4();
  8642. class Skeleton {
  8643. constructor( bones = [], boneInverses = [] ) {
  8644. this.uuid = generateUUID();
  8645. this.bones = bones.slice( 0 );
  8646. this.boneInverses = boneInverses;
  8647. this.boneMatrices = null;
  8648. this.boneTexture = null;
  8649. this.init();
  8650. }
  8651. init() {
  8652. const bones = this.bones;
  8653. const boneInverses = this.boneInverses;
  8654. this.boneMatrices = new Float32Array( bones.length * 16 );
  8655. // calculate inverse bone matrices if necessary
  8656. if ( boneInverses.length === 0 ) {
  8657. this.calculateInverses();
  8658. } else {
  8659. // handle special case
  8660. if ( bones.length !== boneInverses.length ) {
  8661. console.warn( 'THREE.Skeleton: Number of inverse bone matrices does not match amount of bones.' );
  8662. this.boneInverses = [];
  8663. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8664. this.boneInverses.push( new Matrix4() );
  8665. }
  8666. }
  8667. }
  8668. }
  8669. calculateInverses() {
  8670. this.boneInverses.length = 0;
  8671. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8672. const inverse = new Matrix4();
  8673. if ( this.bones[ i ] ) {
  8674. inverse.copy( this.bones[ i ].matrixWorld ).invert();
  8675. }
  8676. this.boneInverses.push( inverse );
  8677. }
  8678. }
  8679. pose() {
  8680. // recover the bind-time world matrices
  8681. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8682. const bone = this.bones[ i ];
  8683. if ( bone ) {
  8684. bone.matrixWorld.copy( this.boneInverses[ i ] ).invert();
  8685. }
  8686. }
  8687. // compute the local matrices, positions, rotations and scales
  8688. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8689. const bone = this.bones[ i ];
  8690. if ( bone ) {
  8691. if ( bone.parent && bone.parent.isBone ) {
  8692. bone.matrix.copy( bone.parent.matrixWorld ).invert();
  8693. bone.matrix.multiply( bone.matrixWorld );
  8694. } else {
  8695. bone.matrix.copy( bone.matrixWorld );
  8696. }
  8697. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  8698. }
  8699. }
  8700. }
  8701. update() {
  8702. const bones = this.bones;
  8703. const boneInverses = this.boneInverses;
  8704. const boneMatrices = this.boneMatrices;
  8705. const boneTexture = this.boneTexture;
  8706. // flatten bone matrices to array
  8707. for ( let i = 0, il = bones.length; i < il; i ++ ) {
  8708. // compute the offset between the current and the original transform
  8709. const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
  8710. _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
  8711. _offsetMatrix.toArray( boneMatrices, i * 16 );
  8712. }
  8713. if ( boneTexture !== null ) {
  8714. boneTexture.needsUpdate = true;
  8715. }
  8716. }
  8717. clone() {
  8718. return new Skeleton( this.bones, this.boneInverses );
  8719. }
  8720. computeBoneTexture() {
  8721. // layout (1 matrix = 4 pixels)
  8722. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  8723. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  8724. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  8725. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  8726. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  8727. let size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  8728. size = Math.ceil( size / 4 ) * 4;
  8729. size = Math.max( size, 4 );
  8730. const boneMatrices = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  8731. boneMatrices.set( this.boneMatrices ); // copy current values
  8732. const boneTexture = new DataTexture( boneMatrices, size, size, RGBAFormat, FloatType );
  8733. boneTexture.needsUpdate = true;
  8734. this.boneMatrices = boneMatrices;
  8735. this.boneTexture = boneTexture;
  8736. return this;
  8737. }
  8738. getBoneByName( name ) {
  8739. for ( let i = 0, il = this.bones.length; i < il; i ++ ) {
  8740. const bone = this.bones[ i ];
  8741. if ( bone.name === name ) {
  8742. return bone;
  8743. }
  8744. }
  8745. return undefined;
  8746. }
  8747. dispose( ) {
  8748. if ( this.boneTexture !== null ) {
  8749. this.boneTexture.dispose();
  8750. this.boneTexture = null;
  8751. }
  8752. }
  8753. fromJSON( json, bones ) {
  8754. this.uuid = json.uuid;
  8755. for ( let i = 0, l = json.bones.length; i < l; i ++ ) {
  8756. const uuid = json.bones[ i ];
  8757. let bone = bones[ uuid ];
  8758. if ( bone === undefined ) {
  8759. console.warn( 'THREE.Skeleton: No bone found with UUID:', uuid );
  8760. bone = new Bone();
  8761. }
  8762. this.bones.push( bone );
  8763. this.boneInverses.push( new Matrix4().fromArray( json.boneInverses[ i ] ) );
  8764. }
  8765. this.init();
  8766. return this;
  8767. }
  8768. toJSON() {
  8769. const data = {
  8770. metadata: {
  8771. version: 4.6,
  8772. type: 'Skeleton',
  8773. generator: 'Skeleton.toJSON'
  8774. },
  8775. bones: [],
  8776. boneInverses: []
  8777. };
  8778. data.uuid = this.uuid;
  8779. const bones = this.bones;
  8780. const boneInverses = this.boneInverses;
  8781. for ( let i = 0, l = bones.length; i < l; i ++ ) {
  8782. const bone = bones[ i ];
  8783. data.bones.push( bone.uuid );
  8784. const boneInverse = boneInverses[ i ];
  8785. data.boneInverses.push( boneInverse.toArray() );
  8786. }
  8787. return data;
  8788. }
  8789. }
  8790. class InstancedBufferAttribute extends BufferAttribute {
  8791. constructor( array, itemSize, normalized, meshPerAttribute = 1 ) {
  8792. super( array, itemSize, normalized );
  8793. this.isInstancedBufferAttribute = true;
  8794. this.meshPerAttribute = meshPerAttribute;
  8795. }
  8796. copy( source ) {
  8797. super.copy( source );
  8798. this.meshPerAttribute = source.meshPerAttribute;
  8799. return this;
  8800. }
  8801. toJSON() {
  8802. const data = super.toJSON();
  8803. data.meshPerAttribute = this.meshPerAttribute;
  8804. data.isInstancedBufferAttribute = true;
  8805. return data;
  8806. }
  8807. }
  8808. const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
  8809. const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
  8810. const _instanceIntersects = [];
  8811. const _box3 = /*@__PURE__*/ new Box3();
  8812. const _identity = /*@__PURE__*/ new Matrix4();
  8813. const _mesh$1 = /*@__PURE__*/ new Mesh();
  8814. const _sphere$4 = /*@__PURE__*/ new Sphere();
  8815. class InstancedMesh extends Mesh {
  8816. constructor( geometry, material, count ) {
  8817. super( geometry, material );
  8818. this.isInstancedMesh = true;
  8819. this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
  8820. this.instanceColor = null;
  8821. this.morphTexture = null;
  8822. this.count = count;
  8823. this.boundingBox = null;
  8824. this.boundingSphere = null;
  8825. for ( let i = 0; i < count; i ++ ) {
  8826. this.setMatrixAt( i, _identity );
  8827. }
  8828. }
  8829. computeBoundingBox() {
  8830. const geometry = this.geometry;
  8831. const count = this.count;
  8832. if ( this.boundingBox === null ) {
  8833. this.boundingBox = new Box3();
  8834. }
  8835. if ( geometry.boundingBox === null ) {
  8836. geometry.computeBoundingBox();
  8837. }
  8838. this.boundingBox.makeEmpty();
  8839. for ( let i = 0; i < count; i ++ ) {
  8840. this.getMatrixAt( i, _instanceLocalMatrix );
  8841. _box3.copy( geometry.boundingBox ).applyMatrix4( _instanceLocalMatrix );
  8842. this.boundingBox.union( _box3 );
  8843. }
  8844. }
  8845. computeBoundingSphere() {
  8846. const geometry = this.geometry;
  8847. const count = this.count;
  8848. if ( this.boundingSphere === null ) {
  8849. this.boundingSphere = new Sphere();
  8850. }
  8851. if ( geometry.boundingSphere === null ) {
  8852. geometry.computeBoundingSphere();
  8853. }
  8854. this.boundingSphere.makeEmpty();
  8855. for ( let i = 0; i < count; i ++ ) {
  8856. this.getMatrixAt( i, _instanceLocalMatrix );
  8857. _sphere$4.copy( geometry.boundingSphere ).applyMatrix4( _instanceLocalMatrix );
  8858. this.boundingSphere.union( _sphere$4 );
  8859. }
  8860. }
  8861. copy( source, recursive ) {
  8862. super.copy( source, recursive );
  8863. this.instanceMatrix.copy( source.instanceMatrix );
  8864. if ( source.morphTexture !== null ) this.morphTexture = source.morphTexture.clone();
  8865. if ( source.instanceColor !== null ) this.instanceColor = source.instanceColor.clone();
  8866. this.count = source.count;
  8867. if ( source.boundingBox !== null ) this.boundingBox = source.boundingBox.clone();
  8868. if ( source.boundingSphere !== null ) this.boundingSphere = source.boundingSphere.clone();
  8869. return this;
  8870. }
  8871. getColorAt( index, color ) {
  8872. color.fromArray( this.instanceColor.array, index * 3 );
  8873. }
  8874. getMatrixAt( index, matrix ) {
  8875. matrix.fromArray( this.instanceMatrix.array, index * 16 );
  8876. }
  8877. getMorphAt( index, object ) {
  8878. const objectInfluences = object.morphTargetInfluences;
  8879. const array = this.morphTexture.source.data.data;
  8880. const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
  8881. const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
  8882. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8883. objectInfluences[ i ] = array[ dataIndex + i ];
  8884. }
  8885. }
  8886. raycast( raycaster, intersects ) {
  8887. const matrixWorld = this.matrixWorld;
  8888. const raycastTimes = this.count;
  8889. _mesh$1.geometry = this.geometry;
  8890. _mesh$1.material = this.material;
  8891. if ( _mesh$1.material === undefined ) return;
  8892. // test with bounding sphere first
  8893. if ( this.boundingSphere === null ) this.computeBoundingSphere();
  8894. _sphere$4.copy( this.boundingSphere );
  8895. _sphere$4.applyMatrix4( matrixWorld );
  8896. if ( raycaster.ray.intersectsSphere( _sphere$4 ) === false ) return;
  8897. // now test each instance
  8898. for ( let instanceId = 0; instanceId < raycastTimes; instanceId ++ ) {
  8899. // calculate the world matrix for each instance
  8900. this.getMatrixAt( instanceId, _instanceLocalMatrix );
  8901. _instanceWorldMatrix.multiplyMatrices( matrixWorld, _instanceLocalMatrix );
  8902. // the mesh represents this single instance
  8903. _mesh$1.matrixWorld = _instanceWorldMatrix;
  8904. _mesh$1.raycast( raycaster, _instanceIntersects );
  8905. // process the result of raycast
  8906. for ( let i = 0, l = _instanceIntersects.length; i < l; i ++ ) {
  8907. const intersect = _instanceIntersects[ i ];
  8908. intersect.instanceId = instanceId;
  8909. intersect.object = this;
  8910. intersects.push( intersect );
  8911. }
  8912. _instanceIntersects.length = 0;
  8913. }
  8914. }
  8915. setColorAt( index, color ) {
  8916. if ( this.instanceColor === null ) {
  8917. this.instanceColor = new InstancedBufferAttribute( new Float32Array( this.instanceMatrix.count * 3 ).fill( 1 ), 3 );
  8918. }
  8919. color.toArray( this.instanceColor.array, index * 3 );
  8920. }
  8921. setMatrixAt( index, matrix ) {
  8922. matrix.toArray( this.instanceMatrix.array, index * 16 );
  8923. }
  8924. setMorphAt( index, object ) {
  8925. const objectInfluences = object.morphTargetInfluences;
  8926. const len = objectInfluences.length + 1; // morphBaseInfluence + all influences
  8927. if ( this.morphTexture === null ) {
  8928. this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType );
  8929. }
  8930. const array = this.morphTexture.source.data.data;
  8931. let morphInfluencesSum = 0;
  8932. for ( let i = 0; i < objectInfluences.length; i ++ ) {
  8933. morphInfluencesSum += objectInfluences[ i ];
  8934. }
  8935. const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
  8936. const dataIndex = len * index;
  8937. array[ dataIndex ] = morphBaseInfluence;
  8938. array.set( objectInfluences, dataIndex + 1 );
  8939. }
  8940. updateMorphTargets() {
  8941. }
  8942. dispose() {
  8943. this.dispatchEvent( { type: 'dispose' } );
  8944. if ( this.morphTexture !== null ) {
  8945. this.morphTexture.dispose();
  8946. this.morphTexture = null;
  8947. }
  8948. return this;
  8949. }
  8950. }
  8951. const _vector1 = /*@__PURE__*/ new Vector3();
  8952. const _vector2 = /*@__PURE__*/ new Vector3();
  8953. const _normalMatrix = /*@__PURE__*/ new Matrix3();
  8954. class Plane {
  8955. constructor( normal = new Vector3( 1, 0, 0 ), constant = 0 ) {
  8956. this.isPlane = true;
  8957. // normal is assumed to be normalized
  8958. this.normal = normal;
  8959. this.constant = constant;
  8960. }
  8961. set( normal, constant ) {
  8962. this.normal.copy( normal );
  8963. this.constant = constant;
  8964. return this;
  8965. }
  8966. setComponents( x, y, z, w ) {
  8967. this.normal.set( x, y, z );
  8968. this.constant = w;
  8969. return this;
  8970. }
  8971. setFromNormalAndCoplanarPoint( normal, point ) {
  8972. this.normal.copy( normal );
  8973. this.constant = - point.dot( this.normal );
  8974. return this;
  8975. }
  8976. setFromCoplanarPoints( a, b, c ) {
  8977. const normal = _vector1.subVectors( c, b ).cross( _vector2.subVectors( a, b ) ).normalize();
  8978. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  8979. this.setFromNormalAndCoplanarPoint( normal, a );
  8980. return this;
  8981. }
  8982. copy( plane ) {
  8983. this.normal.copy( plane.normal );
  8984. this.constant = plane.constant;
  8985. return this;
  8986. }
  8987. normalize() {
  8988. // Note: will lead to a divide by zero if the plane is invalid.
  8989. const inverseNormalLength = 1.0 / this.normal.length();
  8990. this.normal.multiplyScalar( inverseNormalLength );
  8991. this.constant *= inverseNormalLength;
  8992. return this;
  8993. }
  8994. negate() {
  8995. this.constant *= - 1;
  8996. this.normal.negate();
  8997. return this;
  8998. }
  8999. distanceToPoint( point ) {
  9000. return this.normal.dot( point ) + this.constant;
  9001. }
  9002. distanceToSphere( sphere ) {
  9003. return this.distanceToPoint( sphere.center ) - sphere.radius;
  9004. }
  9005. projectPoint( point, target ) {
  9006. return target.copy( point ).addScaledVector( this.normal, - this.distanceToPoint( point ) );
  9007. }
  9008. intersectLine( line, target ) {
  9009. const direction = line.delta( _vector1 );
  9010. const denominator = this.normal.dot( direction );
  9011. if ( denominator === 0 ) {
  9012. // line is coplanar, return origin
  9013. if ( this.distanceToPoint( line.start ) === 0 ) {
  9014. return target.copy( line.start );
  9015. }
  9016. // Unsure if this is the correct method to handle this case.
  9017. return null;
  9018. }
  9019. const t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  9020. if ( t < 0 || t > 1 ) {
  9021. return null;
  9022. }
  9023. return target.copy( line.start ).addScaledVector( direction, t );
  9024. }
  9025. intersectsLine( line ) {
  9026. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  9027. const startSign = this.distanceToPoint( line.start );
  9028. const endSign = this.distanceToPoint( line.end );
  9029. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  9030. }
  9031. intersectsBox( box ) {
  9032. return box.intersectsPlane( this );
  9033. }
  9034. intersectsSphere( sphere ) {
  9035. return sphere.intersectsPlane( this );
  9036. }
  9037. coplanarPoint( target ) {
  9038. return target.copy( this.normal ).multiplyScalar( - this.constant );
  9039. }
  9040. applyMatrix4( matrix, optionalNormalMatrix ) {
  9041. const normalMatrix = optionalNormalMatrix || _normalMatrix.getNormalMatrix( matrix );
  9042. const referencePoint = this.coplanarPoint( _vector1 ).applyMatrix4( matrix );
  9043. const normal = this.normal.applyMatrix3( normalMatrix ).normalize();
  9044. this.constant = - referencePoint.dot( normal );
  9045. return this;
  9046. }
  9047. translate( offset ) {
  9048. this.constant -= offset.dot( this.normal );
  9049. return this;
  9050. }
  9051. equals( plane ) {
  9052. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  9053. }
  9054. clone() {
  9055. return new this.constructor().copy( this );
  9056. }
  9057. }
  9058. const _sphere$3 = /*@__PURE__*/ new Sphere();
  9059. const _vector$6 = /*@__PURE__*/ new Vector3();
  9060. class Frustum {
  9061. constructor( p0 = new Plane(), p1 = new Plane(), p2 = new Plane(), p3 = new Plane(), p4 = new Plane(), p5 = new Plane() ) {
  9062. this.planes = [ p0, p1, p2, p3, p4, p5 ];
  9063. }
  9064. set( p0, p1, p2, p3, p4, p5 ) {
  9065. const planes = this.planes;
  9066. planes[ 0 ].copy( p0 );
  9067. planes[ 1 ].copy( p1 );
  9068. planes[ 2 ].copy( p2 );
  9069. planes[ 3 ].copy( p3 );
  9070. planes[ 4 ].copy( p4 );
  9071. planes[ 5 ].copy( p5 );
  9072. return this;
  9073. }
  9074. copy( frustum ) {
  9075. const planes = this.planes;
  9076. for ( let i = 0; i < 6; i ++ ) {
  9077. planes[ i ].copy( frustum.planes[ i ] );
  9078. }
  9079. return this;
  9080. }
  9081. setFromProjectionMatrix( m, coordinateSystem = WebGLCoordinateSystem ) {
  9082. const planes = this.planes;
  9083. const me = m.elements;
  9084. const me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  9085. const me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  9086. const me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  9087. const me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  9088. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  9089. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  9090. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  9091. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  9092. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  9093. if ( coordinateSystem === WebGLCoordinateSystem ) {
  9094. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  9095. } else if ( coordinateSystem === WebGPUCoordinateSystem ) {
  9096. planes[ 5 ].setComponents( me2, me6, me10, me14 ).normalize();
  9097. } else {
  9098. throw new Error( 'THREE.Frustum.setFromProjectionMatrix(): Invalid coordinate system: ' + coordinateSystem );
  9099. }
  9100. return this;
  9101. }
  9102. intersectsObject( object ) {
  9103. if ( object.boundingSphere !== undefined ) {
  9104. if ( object.boundingSphere === null ) object.computeBoundingSphere();
  9105. _sphere$3.copy( object.boundingSphere ).applyMatrix4( object.matrixWorld );
  9106. } else {
  9107. const geometry = object.geometry;
  9108. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9109. _sphere$3.copy( geometry.boundingSphere ).applyMatrix4( object.matrixWorld );
  9110. }
  9111. return this.intersectsSphere( _sphere$3 );
  9112. }
  9113. intersectsSprite( sprite ) {
  9114. _sphere$3.center.set( 0, 0, 0 );
  9115. _sphere$3.radius = 0.7071067811865476;
  9116. _sphere$3.applyMatrix4( sprite.matrixWorld );
  9117. return this.intersectsSphere( _sphere$3 );
  9118. }
  9119. intersectsSphere( sphere ) {
  9120. const planes = this.planes;
  9121. const center = sphere.center;
  9122. const negRadius = - sphere.radius;
  9123. for ( let i = 0; i < 6; i ++ ) {
  9124. const distance = planes[ i ].distanceToPoint( center );
  9125. if ( distance < negRadius ) {
  9126. return false;
  9127. }
  9128. }
  9129. return true;
  9130. }
  9131. intersectsBox( box ) {
  9132. const planes = this.planes;
  9133. for ( let i = 0; i < 6; i ++ ) {
  9134. const plane = planes[ i ];
  9135. // corner at max distance
  9136. _vector$6.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  9137. _vector$6.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  9138. _vector$6.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  9139. if ( plane.distanceToPoint( _vector$6 ) < 0 ) {
  9140. return false;
  9141. }
  9142. }
  9143. return true;
  9144. }
  9145. containsPoint( point ) {
  9146. const planes = this.planes;
  9147. for ( let i = 0; i < 6; i ++ ) {
  9148. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  9149. return false;
  9150. }
  9151. }
  9152. return true;
  9153. }
  9154. clone() {
  9155. return new this.constructor().copy( this );
  9156. }
  9157. }
  9158. function ascIdSort( a, b ) {
  9159. return a - b;
  9160. }
  9161. function sortOpaque( a, b ) {
  9162. return a.z - b.z;
  9163. }
  9164. function sortTransparent( a, b ) {
  9165. return b.z - a.z;
  9166. }
  9167. class MultiDrawRenderList {
  9168. constructor() {
  9169. this.index = 0;
  9170. this.pool = [];
  9171. this.list = [];
  9172. }
  9173. push( start, count, z, index ) {
  9174. const pool = this.pool;
  9175. const list = this.list;
  9176. if ( this.index >= pool.length ) {
  9177. pool.push( {
  9178. start: - 1,
  9179. count: - 1,
  9180. z: - 1,
  9181. index: - 1,
  9182. } );
  9183. }
  9184. const item = pool[ this.index ];
  9185. list.push( item );
  9186. this.index ++;
  9187. item.start = start;
  9188. item.count = count;
  9189. item.z = z;
  9190. item.index = index;
  9191. }
  9192. reset() {
  9193. this.list.length = 0;
  9194. this.index = 0;
  9195. }
  9196. }
  9197. const _matrix$1 = /*@__PURE__*/ new Matrix4();
  9198. const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
  9199. const _frustum = /*@__PURE__*/ new Frustum();
  9200. const _box$1 = /*@__PURE__*/ new Box3();
  9201. const _sphere$2 = /*@__PURE__*/ new Sphere();
  9202. const _vector$5 = /*@__PURE__*/ new Vector3();
  9203. const _forward = /*@__PURE__*/ new Vector3();
  9204. const _temp = /*@__PURE__*/ new Vector3();
  9205. const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
  9206. const _mesh = /*@__PURE__*/ new Mesh();
  9207. const _batchIntersects = [];
  9208. // copies data from attribute "src" into "target" starting at "targetOffset"
  9209. function copyAttributeData( src, target, targetOffset = 0 ) {
  9210. const itemSize = target.itemSize;
  9211. if ( src.isInterleavedBufferAttribute || src.array.constructor !== target.array.constructor ) {
  9212. // use the component getters and setters if the array data cannot
  9213. // be copied directly
  9214. const vertexCount = src.count;
  9215. for ( let i = 0; i < vertexCount; i ++ ) {
  9216. for ( let c = 0; c < itemSize; c ++ ) {
  9217. target.setComponent( i + targetOffset, c, src.getComponent( i, c ) );
  9218. }
  9219. }
  9220. } else {
  9221. // faster copy approach using typed array set function
  9222. target.array.set( src.array, targetOffset * itemSize );
  9223. }
  9224. target.needsUpdate = true;
  9225. }
  9226. // safely copies array contents to a potentially smaller array
  9227. function copyArrayContents( src, target ) {
  9228. if ( src.constructor !== target.constructor ) {
  9229. // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
  9230. const len = Math.min( src.length, target.length );
  9231. for ( let i = 0; i < len; i ++ ) {
  9232. target[ i ] = src[ i ];
  9233. }
  9234. } else {
  9235. // if the arrays use the same data layout we can use a fast block copy
  9236. const len = Math.min( src.length, target.length );
  9237. target.set( new src.constructor( src.buffer, 0, len ) );
  9238. }
  9239. }
  9240. class BatchedMesh extends Mesh {
  9241. get maxInstanceCount() {
  9242. return this._maxInstanceCount;
  9243. }
  9244. get instanceCount() {
  9245. return this._instanceInfo.length - this._availableInstanceIds.length;
  9246. }
  9247. get unusedVertexCount() {
  9248. return this._maxVertexCount - this._nextVertexStart;
  9249. }
  9250. get unusedIndexCount() {
  9251. return this._maxIndexCount - this._nextIndexStart;
  9252. }
  9253. constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
  9254. super( new BufferGeometry(), material );
  9255. this.isBatchedMesh = true;
  9256. this.perObjectFrustumCulled = true;
  9257. this.sortObjects = true;
  9258. this.boundingBox = null;
  9259. this.boundingSphere = null;
  9260. this.customSort = null;
  9261. // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
  9262. this._instanceInfo = [];
  9263. this._geometryInfo = [];
  9264. // instance, geometry ids that have been set as inactive, and are available to be overwritten
  9265. this._availableInstanceIds = [];
  9266. this._availableGeometryIds = [];
  9267. // used to track where the next point is that geometry should be inserted
  9268. this._nextIndexStart = 0;
  9269. this._nextVertexStart = 0;
  9270. this._geometryCount = 0;
  9271. // flags
  9272. this._visibilityChanged = true;
  9273. this._geometryInitialized = false;
  9274. // cached user options
  9275. this._maxInstanceCount = maxInstanceCount;
  9276. this._maxVertexCount = maxVertexCount;
  9277. this._maxIndexCount = maxIndexCount;
  9278. // buffers for multi draw
  9279. this._multiDrawCounts = new Int32Array( maxInstanceCount );
  9280. this._multiDrawStarts = new Int32Array( maxInstanceCount );
  9281. this._multiDrawCount = 0;
  9282. this._multiDrawInstances = null;
  9283. // Local matrix per geometry by using data texture
  9284. this._matricesTexture = null;
  9285. this._indirectTexture = null;
  9286. this._colorsTexture = null;
  9287. this._initMatricesTexture();
  9288. this._initIndirectTexture();
  9289. }
  9290. _initMatricesTexture() {
  9291. // layout (1 matrix = 4 pixels)
  9292. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  9293. // with 8x8 pixel texture max 16 matrices * 4 pixels = (8 * 8)
  9294. // 16x16 pixel texture max 64 matrices * 4 pixels = (16 * 16)
  9295. // 32x32 pixel texture max 256 matrices * 4 pixels = (32 * 32)
  9296. // 64x64 pixel texture max 1024 matrices * 4 pixels = (64 * 64)
  9297. let size = Math.sqrt( this._maxInstanceCount * 4 ); // 4 pixels needed for 1 matrix
  9298. size = Math.ceil( size / 4 ) * 4;
  9299. size = Math.max( size, 4 );
  9300. const matricesArray = new Float32Array( size * size * 4 ); // 4 floats per RGBA pixel
  9301. const matricesTexture = new DataTexture( matricesArray, size, size, RGBAFormat, FloatType );
  9302. this._matricesTexture = matricesTexture;
  9303. }
  9304. _initIndirectTexture() {
  9305. let size = Math.sqrt( this._maxInstanceCount );
  9306. size = Math.ceil( size );
  9307. const indirectArray = new Uint32Array( size * size );
  9308. const indirectTexture = new DataTexture( indirectArray, size, size, RedIntegerFormat, UnsignedIntType );
  9309. this._indirectTexture = indirectTexture;
  9310. }
  9311. _initColorsTexture() {
  9312. let size = Math.sqrt( this._maxInstanceCount );
  9313. size = Math.ceil( size );
  9314. // 4 floats per RGBA pixel initialized to white
  9315. const colorsArray = new Float32Array( size * size * 4 ).fill( 1 );
  9316. const colorsTexture = new DataTexture( colorsArray, size, size, RGBAFormat, FloatType );
  9317. colorsTexture.colorSpace = ColorManagement.workingColorSpace;
  9318. this._colorsTexture = colorsTexture;
  9319. }
  9320. _initializeGeometry( reference ) {
  9321. const geometry = this.geometry;
  9322. const maxVertexCount = this._maxVertexCount;
  9323. const maxIndexCount = this._maxIndexCount;
  9324. if ( this._geometryInitialized === false ) {
  9325. for ( const attributeName in reference.attributes ) {
  9326. const srcAttribute = reference.getAttribute( attributeName );
  9327. const { array, itemSize, normalized } = srcAttribute;
  9328. const dstArray = new array.constructor( maxVertexCount * itemSize );
  9329. const dstAttribute = new BufferAttribute( dstArray, itemSize, normalized );
  9330. geometry.setAttribute( attributeName, dstAttribute );
  9331. }
  9332. if ( reference.getIndex() !== null ) {
  9333. // Reserve last u16 index for primitive restart.
  9334. const indexArray = maxVertexCount > 65535
  9335. ? new Uint32Array( maxIndexCount )
  9336. : new Uint16Array( maxIndexCount );
  9337. geometry.setIndex( new BufferAttribute( indexArray, 1 ) );
  9338. }
  9339. this._geometryInitialized = true;
  9340. }
  9341. }
  9342. // Make sure the geometry is compatible with the existing combined geometry attributes
  9343. _validateGeometry( geometry ) {
  9344. // check to ensure the geometries are using consistent attributes and indices
  9345. const batchGeometry = this.geometry;
  9346. if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
  9347. throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
  9348. }
  9349. for ( const attributeName in batchGeometry.attributes ) {
  9350. if ( ! geometry.hasAttribute( attributeName ) ) {
  9351. throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
  9352. }
  9353. const srcAttribute = geometry.getAttribute( attributeName );
  9354. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9355. if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
  9356. throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
  9357. }
  9358. }
  9359. }
  9360. validateInstanceId( instanceId ) {
  9361. const instanceInfo = this._instanceInfo;
  9362. if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
  9363. throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
  9364. }
  9365. }
  9366. validateGeometryId( geometryId ) {
  9367. const geometryInfoList = this._geometryInfo;
  9368. if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9369. throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
  9370. }
  9371. }
  9372. setCustomSort( func ) {
  9373. this.customSort = func;
  9374. return this;
  9375. }
  9376. computeBoundingBox() {
  9377. if ( this.boundingBox === null ) {
  9378. this.boundingBox = new Box3();
  9379. }
  9380. const boundingBox = this.boundingBox;
  9381. const instanceInfo = this._instanceInfo;
  9382. boundingBox.makeEmpty();
  9383. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9384. if ( instanceInfo[ i ].active === false ) continue;
  9385. const geometryId = instanceInfo[ i ].geometryIndex;
  9386. this.getMatrixAt( i, _matrix$1 );
  9387. this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 );
  9388. boundingBox.union( _box$1 );
  9389. }
  9390. }
  9391. computeBoundingSphere() {
  9392. if ( this.boundingSphere === null ) {
  9393. this.boundingSphere = new Sphere();
  9394. }
  9395. const boundingSphere = this.boundingSphere;
  9396. const instanceInfo = this._instanceInfo;
  9397. boundingSphere.makeEmpty();
  9398. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9399. if ( instanceInfo[ i ].active === false ) continue;
  9400. const geometryId = instanceInfo[ i ].geometryIndex;
  9401. this.getMatrixAt( i, _matrix$1 );
  9402. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9403. boundingSphere.union( _sphere$2 );
  9404. }
  9405. }
  9406. addInstance( geometryId ) {
  9407. const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
  9408. // ensure we're not over geometry
  9409. if ( atCapacity && this._availableInstanceIds.length === 0 ) {
  9410. throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
  9411. }
  9412. const instanceInfo = {
  9413. visible: true,
  9414. active: true,
  9415. geometryIndex: geometryId,
  9416. };
  9417. let drawId = null;
  9418. // Prioritize using previously freed instance ids
  9419. if ( this._availableInstanceIds.length > 0 ) {
  9420. this._availableInstanceIds.sort( ascIdSort );
  9421. drawId = this._availableInstanceIds.shift();
  9422. this._instanceInfo[ drawId ] = instanceInfo;
  9423. } else {
  9424. drawId = this._instanceInfo.length;
  9425. this._instanceInfo.push( instanceInfo );
  9426. }
  9427. const matricesTexture = this._matricesTexture;
  9428. _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 );
  9429. matricesTexture.needsUpdate = true;
  9430. const colorsTexture = this._colorsTexture;
  9431. if ( colorsTexture ) {
  9432. _whiteColor.toArray( colorsTexture.image.data, drawId * 4 );
  9433. colorsTexture.needsUpdate = true;
  9434. }
  9435. this._visibilityChanged = true;
  9436. return drawId;
  9437. }
  9438. addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) {
  9439. this._initializeGeometry( geometry );
  9440. this._validateGeometry( geometry );
  9441. const geometryInfo = {
  9442. // geometry information
  9443. vertexStart: - 1,
  9444. vertexCount: - 1,
  9445. reservedVertexCount: - 1,
  9446. indexStart: - 1,
  9447. indexCount: - 1,
  9448. reservedIndexCount: - 1,
  9449. // draw range information
  9450. start: - 1,
  9451. count: - 1,
  9452. // state
  9453. boundingBox: null,
  9454. boundingSphere: null,
  9455. active: true,
  9456. };
  9457. const geometryInfoList = this._geometryInfo;
  9458. geometryInfo.vertexStart = this._nextVertexStart;
  9459. geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
  9460. const index = geometry.getIndex();
  9461. const hasIndex = index !== null;
  9462. if ( hasIndex ) {
  9463. geometryInfo.indexStart = this._nextIndexStart;
  9464. geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount;
  9465. }
  9466. if (
  9467. geometryInfo.indexStart !== - 1 &&
  9468. geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
  9469. geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
  9470. ) {
  9471. throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
  9472. }
  9473. // update id
  9474. let geometryId;
  9475. if ( this._availableGeometryIds.length > 0 ) {
  9476. this._availableGeometryIds.sort( ascIdSort );
  9477. geometryId = this._availableGeometryIds.shift();
  9478. geometryInfoList[ geometryId ] = geometryInfo;
  9479. } else {
  9480. geometryId = this._geometryCount;
  9481. this._geometryCount ++;
  9482. geometryInfoList.push( geometryInfo );
  9483. }
  9484. // update the geometry
  9485. this.setGeometryAt( geometryId, geometry );
  9486. // increment the next geometry position
  9487. this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
  9488. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9489. return geometryId;
  9490. }
  9491. setGeometryAt( geometryId, geometry ) {
  9492. if ( geometryId >= this._geometryCount ) {
  9493. throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
  9494. }
  9495. this._validateGeometry( geometry );
  9496. const batchGeometry = this.geometry;
  9497. const hasIndex = batchGeometry.getIndex() !== null;
  9498. const dstIndex = batchGeometry.getIndex();
  9499. const srcIndex = geometry.getIndex();
  9500. const geometryInfo = this._geometryInfo[ geometryId ];
  9501. if (
  9502. hasIndex &&
  9503. srcIndex.count > geometryInfo.reservedIndexCount ||
  9504. geometry.attributes.position.count > geometryInfo.reservedVertexCount
  9505. ) {
  9506. throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
  9507. }
  9508. // copy geometry buffer data over
  9509. const vertexStart = geometryInfo.vertexStart;
  9510. const reservedVertexCount = geometryInfo.reservedVertexCount;
  9511. geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
  9512. for ( const attributeName in batchGeometry.attributes ) {
  9513. // copy attribute data
  9514. const srcAttribute = geometry.getAttribute( attributeName );
  9515. const dstAttribute = batchGeometry.getAttribute( attributeName );
  9516. copyAttributeData( srcAttribute, dstAttribute, vertexStart );
  9517. // fill the rest in with zeroes
  9518. const itemSize = srcAttribute.itemSize;
  9519. for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
  9520. const index = vertexStart + i;
  9521. for ( let c = 0; c < itemSize; c ++ ) {
  9522. dstAttribute.setComponent( index, c, 0 );
  9523. }
  9524. }
  9525. dstAttribute.needsUpdate = true;
  9526. dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
  9527. }
  9528. // copy index
  9529. if ( hasIndex ) {
  9530. const indexStart = geometryInfo.indexStart;
  9531. const reservedIndexCount = geometryInfo.reservedIndexCount;
  9532. geometryInfo.indexCount = geometry.getIndex().count;
  9533. // copy index data over
  9534. for ( let i = 0; i < srcIndex.count; i ++ ) {
  9535. dstIndex.setX( indexStart + i, vertexStart + srcIndex.getX( i ) );
  9536. }
  9537. // fill the rest in with zeroes
  9538. for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
  9539. dstIndex.setX( indexStart + i, vertexStart );
  9540. }
  9541. dstIndex.needsUpdate = true;
  9542. dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
  9543. }
  9544. // update the draw range
  9545. geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9546. geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
  9547. // store the bounding boxes
  9548. geometryInfo.boundingBox = null;
  9549. if ( geometry.boundingBox !== null ) {
  9550. geometryInfo.boundingBox = geometry.boundingBox.clone();
  9551. }
  9552. geometryInfo.boundingSphere = null;
  9553. if ( geometry.boundingSphere !== null ) {
  9554. geometryInfo.boundingSphere = geometry.boundingSphere.clone();
  9555. }
  9556. this._visibilityChanged = true;
  9557. return geometryId;
  9558. }
  9559. deleteGeometry( geometryId ) {
  9560. const geometryInfoList = this._geometryInfo;
  9561. if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
  9562. return this;
  9563. }
  9564. // delete any instances associated with this geometry
  9565. const instanceInfo = this._instanceInfo;
  9566. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9567. if ( instanceInfo[ i ].geometryIndex === geometryId ) {
  9568. this.deleteInstance( i );
  9569. }
  9570. }
  9571. geometryInfoList[ geometryId ].active = false;
  9572. this._availableGeometryIds.push( geometryId );
  9573. this._visibilityChanged = true;
  9574. return this;
  9575. }
  9576. deleteInstance( instanceId ) {
  9577. this.validateInstanceId( instanceId );
  9578. this._instanceInfo[ instanceId ].active = false;
  9579. this._availableInstanceIds.push( instanceId );
  9580. this._visibilityChanged = true;
  9581. return this;
  9582. }
  9583. optimize() {
  9584. // track the next indices to copy data to
  9585. let nextVertexStart = 0;
  9586. let nextIndexStart = 0;
  9587. // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
  9588. // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
  9589. const geometryInfoList = this._geometryInfo;
  9590. const indices = geometryInfoList
  9591. .map( ( e, i ) => i )
  9592. .sort( ( a, b ) => {
  9593. return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
  9594. } );
  9595. const geometry = this.geometry;
  9596. for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
  9597. // if a geometry range is inactive then don't copy anything
  9598. const index = indices[ i ];
  9599. const geometryInfo = geometryInfoList[ index ];
  9600. if ( geometryInfo.active === false ) {
  9601. continue;
  9602. }
  9603. // if a geometry contains an index buffer then shift it, as well
  9604. if ( geometry.index !== null ) {
  9605. if ( geometryInfo.indexStart !== nextIndexStart ) {
  9606. const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
  9607. const index = geometry.index;
  9608. const array = index.array;
  9609. // shift the index pointers based on how the vertex data will shift
  9610. // adjusting the index must happen first so the original vertex start value is available
  9611. const elementDelta = nextVertexStart - vertexStart;
  9612. for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
  9613. array[ j ] = array[ j ] + elementDelta;
  9614. }
  9615. index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
  9616. index.addUpdateRange( nextIndexStart, reservedIndexCount );
  9617. geometryInfo.indexStart = nextIndexStart;
  9618. }
  9619. nextIndexStart += geometryInfo.reservedIndexCount;
  9620. }
  9621. // if a geometry needs to be moved then copy attribute data to overwrite unused space
  9622. if ( geometryInfo.vertexStart !== nextVertexStart ) {
  9623. const { vertexStart, reservedVertexCount } = geometryInfo;
  9624. const attributes = geometry.attributes;
  9625. for ( const key in attributes ) {
  9626. const attribute = attributes[ key ];
  9627. const { array, itemSize } = attribute;
  9628. array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
  9629. attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
  9630. }
  9631. geometryInfo.vertexStart = nextVertexStart;
  9632. }
  9633. nextVertexStart += geometryInfo.reservedVertexCount;
  9634. geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
  9635. // step the next geometry points to the shifted position
  9636. this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
  9637. this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
  9638. }
  9639. return this;
  9640. }
  9641. // get bounding box and compute it if it doesn't exist
  9642. getBoundingBoxAt( geometryId, target ) {
  9643. if ( geometryId >= this._geometryCount ) {
  9644. return null;
  9645. }
  9646. // compute bounding box
  9647. const geometry = this.geometry;
  9648. const geometryInfo = this._geometryInfo[ geometryId ];
  9649. if ( geometryInfo.boundingBox === null ) {
  9650. const box = new Box3();
  9651. const index = geometry.index;
  9652. const position = geometry.attributes.position;
  9653. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9654. let iv = i;
  9655. if ( index ) {
  9656. iv = index.getX( iv );
  9657. }
  9658. box.expandByPoint( _vector$5.fromBufferAttribute( position, iv ) );
  9659. }
  9660. geometryInfo.boundingBox = box;
  9661. }
  9662. target.copy( geometryInfo.boundingBox );
  9663. return target;
  9664. }
  9665. // get bounding sphere and compute it if it doesn't exist
  9666. getBoundingSphereAt( geometryId, target ) {
  9667. if ( geometryId >= this._geometryCount ) {
  9668. return null;
  9669. }
  9670. // compute bounding sphere
  9671. const geometry = this.geometry;
  9672. const geometryInfo = this._geometryInfo[ geometryId ];
  9673. if ( geometryInfo.boundingSphere === null ) {
  9674. const sphere = new Sphere();
  9675. this.getBoundingBoxAt( geometryId, _box$1 );
  9676. _box$1.getCenter( sphere.center );
  9677. const index = geometry.index;
  9678. const position = geometry.attributes.position;
  9679. let maxRadiusSq = 0;
  9680. for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
  9681. let iv = i;
  9682. if ( index ) {
  9683. iv = index.getX( iv );
  9684. }
  9685. _vector$5.fromBufferAttribute( position, iv );
  9686. maxRadiusSq = Math.max( maxRadiusSq, sphere.center.distanceToSquared( _vector$5 ) );
  9687. }
  9688. sphere.radius = Math.sqrt( maxRadiusSq );
  9689. geometryInfo.boundingSphere = sphere;
  9690. }
  9691. target.copy( geometryInfo.boundingSphere );
  9692. return target;
  9693. }
  9694. setMatrixAt( instanceId, matrix ) {
  9695. this.validateInstanceId( instanceId );
  9696. const matricesTexture = this._matricesTexture;
  9697. const matricesArray = this._matricesTexture.image.data;
  9698. matrix.toArray( matricesArray, instanceId * 16 );
  9699. matricesTexture.needsUpdate = true;
  9700. return this;
  9701. }
  9702. getMatrixAt( instanceId, matrix ) {
  9703. this.validateInstanceId( instanceId );
  9704. return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
  9705. }
  9706. setColorAt( instanceId, color ) {
  9707. this.validateInstanceId( instanceId );
  9708. if ( this._colorsTexture === null ) {
  9709. this._initColorsTexture();
  9710. }
  9711. color.toArray( this._colorsTexture.image.data, instanceId * 4 );
  9712. this._colorsTexture.needsUpdate = true;
  9713. return this;
  9714. }
  9715. getColorAt( instanceId, color ) {
  9716. this.validateInstanceId( instanceId );
  9717. return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
  9718. }
  9719. setVisibleAt( instanceId, value ) {
  9720. this.validateInstanceId( instanceId );
  9721. if ( this._instanceInfo[ instanceId ].visible === value ) {
  9722. return this;
  9723. }
  9724. this._instanceInfo[ instanceId ].visible = value;
  9725. this._visibilityChanged = true;
  9726. return this;
  9727. }
  9728. getVisibleAt( instanceId ) {
  9729. this.validateInstanceId( instanceId );
  9730. return this._instanceInfo[ instanceId ].visible;
  9731. }
  9732. setGeometryIdAt( instanceId, geometryId ) {
  9733. this.validateInstanceId( instanceId );
  9734. this.validateGeometryId( geometryId );
  9735. this._instanceInfo[ instanceId ].geometryIndex = geometryId;
  9736. return this;
  9737. }
  9738. getGeometryIdAt( instanceId ) {
  9739. this.validateInstanceId( instanceId );
  9740. return this._instanceInfo[ instanceId ].geometryIndex;
  9741. }
  9742. getGeometryRangeAt( geometryId, target = {} ) {
  9743. this.validateGeometryId( geometryId );
  9744. const geometryInfo = this._geometryInfo[ geometryId ];
  9745. target.vertexStart = geometryInfo.vertexStart;
  9746. target.vertexCount = geometryInfo.vertexCount;
  9747. target.reservedVertexCount = geometryInfo.reservedVertexCount;
  9748. target.indexStart = geometryInfo.indexStart;
  9749. target.indexCount = geometryInfo.indexCount;
  9750. target.reservedIndexCount = geometryInfo.reservedIndexCount;
  9751. target.start = geometryInfo.start;
  9752. target.count = geometryInfo.count;
  9753. return target;
  9754. }
  9755. setInstanceCount( maxInstanceCount ) {
  9756. // shrink the available instances as much as possible
  9757. const availableInstanceIds = this._availableInstanceIds;
  9758. const instanceInfo = this._instanceInfo;
  9759. availableInstanceIds.sort( ascIdSort );
  9760. while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
  9761. instanceInfo.pop();
  9762. availableInstanceIds.pop();
  9763. }
  9764. // throw an error if it can't be shrunk to the desired size
  9765. if ( maxInstanceCount < instanceInfo.length ) {
  9766. throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
  9767. }
  9768. // copy the multi draw counts
  9769. const multiDrawCounts = new Int32Array( maxInstanceCount );
  9770. const multiDrawStarts = new Int32Array( maxInstanceCount );
  9771. copyArrayContents( this._multiDrawCounts, multiDrawCounts );
  9772. copyArrayContents( this._multiDrawStarts, multiDrawStarts );
  9773. this._multiDrawCounts = multiDrawCounts;
  9774. this._multiDrawStarts = multiDrawStarts;
  9775. this._maxInstanceCount = maxInstanceCount;
  9776. // update texture data for instance sampling
  9777. const indirectTexture = this._indirectTexture;
  9778. const matricesTexture = this._matricesTexture;
  9779. const colorsTexture = this._colorsTexture;
  9780. indirectTexture.dispose();
  9781. this._initIndirectTexture();
  9782. copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
  9783. matricesTexture.dispose();
  9784. this._initMatricesTexture();
  9785. copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
  9786. if ( colorsTexture ) {
  9787. colorsTexture.dispose();
  9788. this._initColorsTexture();
  9789. copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
  9790. }
  9791. }
  9792. setGeometrySize( maxVertexCount, maxIndexCount ) {
  9793. // Check if we can shrink to the requested vertex attribute size
  9794. const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
  9795. const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
  9796. if ( requiredVertexLength > maxVertexCount ) {
  9797. throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9798. }
  9799. // Check if we can shrink to the requested index attribute size
  9800. if ( this.geometry.index ) {
  9801. const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
  9802. if ( requiredIndexLength > maxIndexCount ) {
  9803. throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
  9804. }
  9805. }
  9806. //
  9807. // dispose of the previous geometry
  9808. const oldGeometry = this.geometry;
  9809. oldGeometry.dispose();
  9810. // recreate the geometry needed based on the previous variant
  9811. this._maxVertexCount = maxVertexCount;
  9812. this._maxIndexCount = maxIndexCount;
  9813. if ( this._geometryInitialized ) {
  9814. this._geometryInitialized = false;
  9815. this.geometry = new BufferGeometry();
  9816. this._initializeGeometry( oldGeometry );
  9817. }
  9818. // copy data from the previous geometry
  9819. const geometry = this.geometry;
  9820. if ( oldGeometry.index ) {
  9821. copyArrayContents( oldGeometry.index.array, geometry.index.array );
  9822. }
  9823. for ( const key in oldGeometry.attributes ) {
  9824. copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
  9825. }
  9826. }
  9827. raycast( raycaster, intersects ) {
  9828. const instanceInfo = this._instanceInfo;
  9829. const geometryInfoList = this._geometryInfo;
  9830. const matrixWorld = this.matrixWorld;
  9831. const batchGeometry = this.geometry;
  9832. // iterate over each geometry
  9833. _mesh.material = this.material;
  9834. _mesh.geometry.index = batchGeometry.index;
  9835. _mesh.geometry.attributes = batchGeometry.attributes;
  9836. if ( _mesh.geometry.boundingBox === null ) {
  9837. _mesh.geometry.boundingBox = new Box3();
  9838. }
  9839. if ( _mesh.geometry.boundingSphere === null ) {
  9840. _mesh.geometry.boundingSphere = new Sphere();
  9841. }
  9842. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9843. if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
  9844. continue;
  9845. }
  9846. const geometryId = instanceInfo[ i ].geometryIndex;
  9847. const geometryInfo = geometryInfoList[ geometryId ];
  9848. _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
  9849. // get the intersects
  9850. this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
  9851. this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
  9852. this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
  9853. _mesh.raycast( raycaster, _batchIntersects );
  9854. // add batch id to the intersects
  9855. for ( let j = 0, l = _batchIntersects.length; j < l; j ++ ) {
  9856. const intersect = _batchIntersects[ j ];
  9857. intersect.object = this;
  9858. intersect.batchId = i;
  9859. intersects.push( intersect );
  9860. }
  9861. _batchIntersects.length = 0;
  9862. }
  9863. _mesh.material = null;
  9864. _mesh.geometry.index = null;
  9865. _mesh.geometry.attributes = {};
  9866. _mesh.geometry.setDrawRange( 0, Infinity );
  9867. }
  9868. copy( source ) {
  9869. super.copy( source );
  9870. this.geometry = source.geometry.clone();
  9871. this.perObjectFrustumCulled = source.perObjectFrustumCulled;
  9872. this.sortObjects = source.sortObjects;
  9873. this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
  9874. this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
  9875. this._geometryInfo = source._geometryInfo.map( info => ( {
  9876. ...info,
  9877. boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
  9878. boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
  9879. } ) );
  9880. this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
  9881. this._maxInstanceCount = source._maxInstanceCount;
  9882. this._maxVertexCount = source._maxVertexCount;
  9883. this._maxIndexCount = source._maxIndexCount;
  9884. this._geometryInitialized = source._geometryInitialized;
  9885. this._geometryCount = source._geometryCount;
  9886. this._multiDrawCounts = source._multiDrawCounts.slice();
  9887. this._multiDrawStarts = source._multiDrawStarts.slice();
  9888. this._matricesTexture = source._matricesTexture.clone();
  9889. this._matricesTexture.image.data = this._matricesTexture.image.data.slice();
  9890. if ( this._colorsTexture !== null ) {
  9891. this._colorsTexture = source._colorsTexture.clone();
  9892. this._colorsTexture.image.data = this._colorsTexture.image.data.slice();
  9893. }
  9894. return this;
  9895. }
  9896. dispose() {
  9897. // Assuming the geometry is not shared with other meshes
  9898. this.geometry.dispose();
  9899. this._matricesTexture.dispose();
  9900. this._matricesTexture = null;
  9901. this._indirectTexture.dispose();
  9902. this._indirectTexture = null;
  9903. if ( this._colorsTexture !== null ) {
  9904. this._colorsTexture.dispose();
  9905. this._colorsTexture = null;
  9906. }
  9907. return this;
  9908. }
  9909. onBeforeRender( renderer, scene, camera, geometry, material/*, _group*/ ) {
  9910. // if visibility has not changed and frustum culling and object sorting is not required
  9911. // then skip iterating over all items
  9912. if ( ! this._visibilityChanged && ! this.perObjectFrustumCulled && ! this.sortObjects ) {
  9913. return;
  9914. }
  9915. // the indexed version of the multi draw function requires specifying the start
  9916. // offset in bytes.
  9917. const index = geometry.getIndex();
  9918. const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
  9919. const instanceInfo = this._instanceInfo;
  9920. const multiDrawStarts = this._multiDrawStarts;
  9921. const multiDrawCounts = this._multiDrawCounts;
  9922. const geometryInfoList = this._geometryInfo;
  9923. const perObjectFrustumCulled = this.perObjectFrustumCulled;
  9924. const indirectTexture = this._indirectTexture;
  9925. const indirectArray = indirectTexture.image.data;
  9926. // prepare the frustum in the local frame
  9927. if ( perObjectFrustumCulled ) {
  9928. _matrix$1
  9929. .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
  9930. .multiply( this.matrixWorld );
  9931. _frustum.setFromProjectionMatrix(
  9932. _matrix$1,
  9933. renderer.coordinateSystem
  9934. );
  9935. }
  9936. let multiDrawCount = 0;
  9937. if ( this.sortObjects ) {
  9938. // get the camera position in the local frame
  9939. _matrix$1.copy( this.matrixWorld ).invert();
  9940. _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 );
  9941. _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 );
  9942. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9943. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9944. const geometryId = instanceInfo[ i ].geometryIndex;
  9945. // get the bounds in world space
  9946. this.getMatrixAt( i, _matrix$1 );
  9947. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9948. // determine whether the batched geometry is within the frustum
  9949. let culled = false;
  9950. if ( perObjectFrustumCulled ) {
  9951. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9952. }
  9953. if ( ! culled ) {
  9954. // get the distance from camera used for sorting
  9955. const geometryInfo = geometryInfoList[ geometryId ];
  9956. const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
  9957. _renderList.push( geometryInfo.start, geometryInfo.count, z, i );
  9958. }
  9959. }
  9960. }
  9961. // Sort the draw ranges and prep for rendering
  9962. const list = _renderList.list;
  9963. const customSort = this.customSort;
  9964. if ( customSort === null ) {
  9965. list.sort( material.transparent ? sortTransparent : sortOpaque );
  9966. } else {
  9967. customSort.call( this, list, camera );
  9968. }
  9969. for ( let i = 0, l = list.length; i < l; i ++ ) {
  9970. const item = list[ i ];
  9971. multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement;
  9972. multiDrawCounts[ multiDrawCount ] = item.count;
  9973. indirectArray[ multiDrawCount ] = item.index;
  9974. multiDrawCount ++;
  9975. }
  9976. _renderList.reset();
  9977. } else {
  9978. for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
  9979. if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
  9980. const geometryId = instanceInfo[ i ].geometryIndex;
  9981. // determine whether the batched geometry is within the frustum
  9982. let culled = false;
  9983. if ( perObjectFrustumCulled ) {
  9984. // get the bounds in world space
  9985. this.getMatrixAt( i, _matrix$1 );
  9986. this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
  9987. culled = ! _frustum.intersectsSphere( _sphere$2 );
  9988. }
  9989. if ( ! culled ) {
  9990. const geometryInfo = geometryInfoList[ geometryId ];
  9991. multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement;
  9992. multiDrawCounts[ multiDrawCount ] = geometryInfo.count;
  9993. indirectArray[ multiDrawCount ] = i;
  9994. multiDrawCount ++;
  9995. }
  9996. }
  9997. }
  9998. }
  9999. indirectTexture.needsUpdate = true;
  10000. this._multiDrawCount = multiDrawCount;
  10001. this._visibilityChanged = false;
  10002. }
  10003. onBeforeShadow( renderer, object, camera, shadowCamera, geometry, depthMaterial/* , group */ ) {
  10004. this.onBeforeRender( renderer, null, shadowCamera, geometry, depthMaterial );
  10005. }
  10006. }
  10007. class LineBasicMaterial extends Material {
  10008. constructor( parameters ) {
  10009. super();
  10010. this.isLineBasicMaterial = true;
  10011. this.type = 'LineBasicMaterial';
  10012. this.color = new Color( 0xffffff );
  10013. this.map = null;
  10014. this.linewidth = 1;
  10015. this.linecap = 'round';
  10016. this.linejoin = 'round';
  10017. this.fog = true;
  10018. this.setValues( parameters );
  10019. }
  10020. copy( source ) {
  10021. super.copy( source );
  10022. this.color.copy( source.color );
  10023. this.map = source.map;
  10024. this.linewidth = source.linewidth;
  10025. this.linecap = source.linecap;
  10026. this.linejoin = source.linejoin;
  10027. this.fog = source.fog;
  10028. return this;
  10029. }
  10030. }
  10031. const _vStart = /*@__PURE__*/ new Vector3();
  10032. const _vEnd = /*@__PURE__*/ new Vector3();
  10033. const _inverseMatrix$1 = /*@__PURE__*/ new Matrix4();
  10034. const _ray$1 = /*@__PURE__*/ new Ray();
  10035. const _sphere$1 = /*@__PURE__*/ new Sphere();
  10036. const _intersectPointOnRay = /*@__PURE__*/ new Vector3();
  10037. const _intersectPointOnSegment = /*@__PURE__*/ new Vector3();
  10038. class Line extends Object3D {
  10039. constructor( geometry = new BufferGeometry(), material = new LineBasicMaterial() ) {
  10040. super();
  10041. this.isLine = true;
  10042. this.type = 'Line';
  10043. this.geometry = geometry;
  10044. this.material = material;
  10045. this.updateMorphTargets();
  10046. }
  10047. copy( source, recursive ) {
  10048. super.copy( source, recursive );
  10049. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10050. this.geometry = source.geometry;
  10051. return this;
  10052. }
  10053. computeLineDistances() {
  10054. const geometry = this.geometry;
  10055. // we assume non-indexed geometry
  10056. if ( geometry.index === null ) {
  10057. const positionAttribute = geometry.attributes.position;
  10058. const lineDistances = [ 0 ];
  10059. for ( let i = 1, l = positionAttribute.count; i < l; i ++ ) {
  10060. _vStart.fromBufferAttribute( positionAttribute, i - 1 );
  10061. _vEnd.fromBufferAttribute( positionAttribute, i );
  10062. lineDistances[ i ] = lineDistances[ i - 1 ];
  10063. lineDistances[ i ] += _vStart.distanceTo( _vEnd );
  10064. }
  10065. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10066. } else {
  10067. console.warn( 'THREE.Line.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10068. }
  10069. return this;
  10070. }
  10071. raycast( raycaster, intersects ) {
  10072. const geometry = this.geometry;
  10073. const matrixWorld = this.matrixWorld;
  10074. const threshold = raycaster.params.Line.threshold;
  10075. const drawRange = geometry.drawRange;
  10076. // Checking boundingSphere distance to ray
  10077. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10078. _sphere$1.copy( geometry.boundingSphere );
  10079. _sphere$1.applyMatrix4( matrixWorld );
  10080. _sphere$1.radius += threshold;
  10081. if ( raycaster.ray.intersectsSphere( _sphere$1 ) === false ) return;
  10082. //
  10083. _inverseMatrix$1.copy( matrixWorld ).invert();
  10084. _ray$1.copy( raycaster.ray ).applyMatrix4( _inverseMatrix$1 );
  10085. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10086. const localThresholdSq = localThreshold * localThreshold;
  10087. const step = this.isLineSegments ? 2 : 1;
  10088. const index = geometry.index;
  10089. const attributes = geometry.attributes;
  10090. const positionAttribute = attributes.position;
  10091. if ( index !== null ) {
  10092. const start = Math.max( 0, drawRange.start );
  10093. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10094. for ( let i = start, l = end - 1; i < l; i += step ) {
  10095. const a = index.getX( i );
  10096. const b = index.getX( i + 1 );
  10097. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10098. if ( intersect ) {
  10099. intersects.push( intersect );
  10100. }
  10101. }
  10102. if ( this.isLineLoop ) {
  10103. const a = index.getX( end - 1 );
  10104. const b = index.getX( start );
  10105. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, a, b );
  10106. if ( intersect ) {
  10107. intersects.push( intersect );
  10108. }
  10109. }
  10110. } else {
  10111. const start = Math.max( 0, drawRange.start );
  10112. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10113. for ( let i = start, l = end - 1; i < l; i += step ) {
  10114. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, i, i + 1 );
  10115. if ( intersect ) {
  10116. intersects.push( intersect );
  10117. }
  10118. }
  10119. if ( this.isLineLoop ) {
  10120. const intersect = checkIntersection( this, raycaster, _ray$1, localThresholdSq, end - 1, start );
  10121. if ( intersect ) {
  10122. intersects.push( intersect );
  10123. }
  10124. }
  10125. }
  10126. }
  10127. updateMorphTargets() {
  10128. const geometry = this.geometry;
  10129. const morphAttributes = geometry.morphAttributes;
  10130. const keys = Object.keys( morphAttributes );
  10131. if ( keys.length > 0 ) {
  10132. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10133. if ( morphAttribute !== undefined ) {
  10134. this.morphTargetInfluences = [];
  10135. this.morphTargetDictionary = {};
  10136. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10137. const name = morphAttribute[ m ].name || String( m );
  10138. this.morphTargetInfluences.push( 0 );
  10139. this.morphTargetDictionary[ name ] = m;
  10140. }
  10141. }
  10142. }
  10143. }
  10144. }
  10145. function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
  10146. const positionAttribute = object.geometry.attributes.position;
  10147. _vStart.fromBufferAttribute( positionAttribute, a );
  10148. _vEnd.fromBufferAttribute( positionAttribute, b );
  10149. const distSq = ray.distanceSqToSegment( _vStart, _vEnd, _intersectPointOnRay, _intersectPointOnSegment );
  10150. if ( distSq > thresholdSq ) return;
  10151. _intersectPointOnRay.applyMatrix4( object.matrixWorld ); // Move back to world space for distance calculation
  10152. const distance = raycaster.ray.origin.distanceTo( _intersectPointOnRay );
  10153. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10154. return {
  10155. distance: distance,
  10156. // What do we want? intersection point on the ray or on the segment??
  10157. // point: raycaster.ray.at( distance ),
  10158. point: _intersectPointOnSegment.clone().applyMatrix4( object.matrixWorld ),
  10159. index: a,
  10160. face: null,
  10161. faceIndex: null,
  10162. barycoord: null,
  10163. object: object
  10164. };
  10165. }
  10166. const _start = /*@__PURE__*/ new Vector3();
  10167. const _end = /*@__PURE__*/ new Vector3();
  10168. class LineSegments extends Line {
  10169. constructor( geometry, material ) {
  10170. super( geometry, material );
  10171. this.isLineSegments = true;
  10172. this.type = 'LineSegments';
  10173. }
  10174. computeLineDistances() {
  10175. const geometry = this.geometry;
  10176. // we assume non-indexed geometry
  10177. if ( geometry.index === null ) {
  10178. const positionAttribute = geometry.attributes.position;
  10179. const lineDistances = [];
  10180. for ( let i = 0, l = positionAttribute.count; i < l; i += 2 ) {
  10181. _start.fromBufferAttribute( positionAttribute, i );
  10182. _end.fromBufferAttribute( positionAttribute, i + 1 );
  10183. lineDistances[ i ] = ( i === 0 ) ? 0 : lineDistances[ i - 1 ];
  10184. lineDistances[ i + 1 ] = lineDistances[ i ] + _start.distanceTo( _end );
  10185. }
  10186. geometry.setAttribute( 'lineDistance', new Float32BufferAttribute( lineDistances, 1 ) );
  10187. } else {
  10188. console.warn( 'THREE.LineSegments.computeLineDistances(): Computation only possible with non-indexed BufferGeometry.' );
  10189. }
  10190. return this;
  10191. }
  10192. }
  10193. class LineLoop extends Line {
  10194. constructor( geometry, material ) {
  10195. super( geometry, material );
  10196. this.isLineLoop = true;
  10197. this.type = 'LineLoop';
  10198. }
  10199. }
  10200. class PointsMaterial extends Material {
  10201. constructor( parameters ) {
  10202. super();
  10203. this.isPointsMaterial = true;
  10204. this.type = 'PointsMaterial';
  10205. this.color = new Color( 0xffffff );
  10206. this.map = null;
  10207. this.alphaMap = null;
  10208. this.size = 1;
  10209. this.sizeAttenuation = true;
  10210. this.fog = true;
  10211. this.setValues( parameters );
  10212. }
  10213. copy( source ) {
  10214. super.copy( source );
  10215. this.color.copy( source.color );
  10216. this.map = source.map;
  10217. this.alphaMap = source.alphaMap;
  10218. this.size = source.size;
  10219. this.sizeAttenuation = source.sizeAttenuation;
  10220. this.fog = source.fog;
  10221. return this;
  10222. }
  10223. }
  10224. const _inverseMatrix = /*@__PURE__*/ new Matrix4();
  10225. const _ray = /*@__PURE__*/ new Ray();
  10226. const _sphere = /*@__PURE__*/ new Sphere();
  10227. const _position$2 = /*@__PURE__*/ new Vector3();
  10228. class Points extends Object3D {
  10229. constructor( geometry = new BufferGeometry(), material = new PointsMaterial() ) {
  10230. super();
  10231. this.isPoints = true;
  10232. this.type = 'Points';
  10233. this.geometry = geometry;
  10234. this.material = material;
  10235. this.updateMorphTargets();
  10236. }
  10237. copy( source, recursive ) {
  10238. super.copy( source, recursive );
  10239. this.material = Array.isArray( source.material ) ? source.material.slice() : source.material;
  10240. this.geometry = source.geometry;
  10241. return this;
  10242. }
  10243. raycast( raycaster, intersects ) {
  10244. const geometry = this.geometry;
  10245. const matrixWorld = this.matrixWorld;
  10246. const threshold = raycaster.params.Points.threshold;
  10247. const drawRange = geometry.drawRange;
  10248. // Checking boundingSphere distance to ray
  10249. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10250. _sphere.copy( geometry.boundingSphere );
  10251. _sphere.applyMatrix4( matrixWorld );
  10252. _sphere.radius += threshold;
  10253. if ( raycaster.ray.intersectsSphere( _sphere ) === false ) return;
  10254. //
  10255. _inverseMatrix.copy( matrixWorld ).invert();
  10256. _ray.copy( raycaster.ray ).applyMatrix4( _inverseMatrix );
  10257. const localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10258. const localThresholdSq = localThreshold * localThreshold;
  10259. const index = geometry.index;
  10260. const attributes = geometry.attributes;
  10261. const positionAttribute = attributes.position;
  10262. if ( index !== null ) {
  10263. const start = Math.max( 0, drawRange.start );
  10264. const end = Math.min( index.count, ( drawRange.start + drawRange.count ) );
  10265. for ( let i = start, il = end; i < il; i ++ ) {
  10266. const a = index.getX( i );
  10267. _position$2.fromBufferAttribute( positionAttribute, a );
  10268. testPoint( _position$2, a, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10269. }
  10270. } else {
  10271. const start = Math.max( 0, drawRange.start );
  10272. const end = Math.min( positionAttribute.count, ( drawRange.start + drawRange.count ) );
  10273. for ( let i = start, l = end; i < l; i ++ ) {
  10274. _position$2.fromBufferAttribute( positionAttribute, i );
  10275. testPoint( _position$2, i, localThresholdSq, matrixWorld, raycaster, intersects, this );
  10276. }
  10277. }
  10278. }
  10279. updateMorphTargets() {
  10280. const geometry = this.geometry;
  10281. const morphAttributes = geometry.morphAttributes;
  10282. const keys = Object.keys( morphAttributes );
  10283. if ( keys.length > 0 ) {
  10284. const morphAttribute = morphAttributes[ keys[ 0 ] ];
  10285. if ( morphAttribute !== undefined ) {
  10286. this.morphTargetInfluences = [];
  10287. this.morphTargetDictionary = {};
  10288. for ( let m = 0, ml = morphAttribute.length; m < ml; m ++ ) {
  10289. const name = morphAttribute[ m ].name || String( m );
  10290. this.morphTargetInfluences.push( 0 );
  10291. this.morphTargetDictionary[ name ] = m;
  10292. }
  10293. }
  10294. }
  10295. }
  10296. }
  10297. function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, intersects, object ) {
  10298. const rayPointDistanceSq = _ray.distanceSqToPoint( point );
  10299. if ( rayPointDistanceSq < localThresholdSq ) {
  10300. const intersectPoint = new Vector3();
  10301. _ray.closestPointToPoint( point, intersectPoint );
  10302. intersectPoint.applyMatrix4( matrixWorld );
  10303. const distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10304. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10305. intersects.push( {
  10306. distance: distance,
  10307. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10308. point: intersectPoint,
  10309. index: index,
  10310. face: null,
  10311. faceIndex: null,
  10312. barycoord: null,
  10313. object: object
  10314. } );
  10315. }
  10316. }
  10317. class Group extends Object3D {
  10318. constructor() {
  10319. super();
  10320. this.isGroup = true;
  10321. this.type = 'Group';
  10322. }
  10323. }
  10324. class VideoTexture extends Texture {
  10325. constructor( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10326. super( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10327. this.isVideoTexture = true;
  10328. this.minFilter = minFilter !== undefined ? minFilter : LinearFilter;
  10329. this.magFilter = magFilter !== undefined ? magFilter : LinearFilter;
  10330. this.generateMipmaps = false;
  10331. const scope = this;
  10332. function updateVideo() {
  10333. scope.needsUpdate = true;
  10334. video.requestVideoFrameCallback( updateVideo );
  10335. }
  10336. if ( 'requestVideoFrameCallback' in video ) {
  10337. video.requestVideoFrameCallback( updateVideo );
  10338. }
  10339. }
  10340. clone() {
  10341. return new this.constructor( this.image ).copy( this );
  10342. }
  10343. update() {
  10344. const video = this.image;
  10345. const hasVideoFrameCallback = 'requestVideoFrameCallback' in video;
  10346. if ( hasVideoFrameCallback === false && video.readyState >= video.HAVE_CURRENT_DATA ) {
  10347. this.needsUpdate = true;
  10348. }
  10349. }
  10350. }
  10351. class FramebufferTexture extends Texture {
  10352. constructor( width, height ) {
  10353. super( { width, height } );
  10354. this.isFramebufferTexture = true;
  10355. this.magFilter = NearestFilter;
  10356. this.minFilter = NearestFilter;
  10357. this.generateMipmaps = false;
  10358. this.needsUpdate = true;
  10359. }
  10360. }
  10361. class CompressedTexture extends Texture {
  10362. constructor( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, colorSpace ) {
  10363. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy, colorSpace );
  10364. this.isCompressedTexture = true;
  10365. this.image = { width: width, height: height };
  10366. this.mipmaps = mipmaps;
  10367. // no flipping for cube textures
  10368. // (also flipping doesn't work for compressed textures )
  10369. this.flipY = false;
  10370. // can't generate mipmaps for compressed textures
  10371. // mips must be embedded in DDS files
  10372. this.generateMipmaps = false;
  10373. }
  10374. }
  10375. class CompressedArrayTexture extends CompressedTexture {
  10376. constructor( mipmaps, width, height, depth, format, type ) {
  10377. super( mipmaps, width, height, format, type );
  10378. this.isCompressedArrayTexture = true;
  10379. this.image.depth = depth;
  10380. this.wrapR = ClampToEdgeWrapping;
  10381. this.layerUpdates = new Set();
  10382. }
  10383. addLayerUpdate( layerIndex ) {
  10384. this.layerUpdates.add( layerIndex );
  10385. }
  10386. clearLayerUpdates() {
  10387. this.layerUpdates.clear();
  10388. }
  10389. }
  10390. class CompressedCubeTexture extends CompressedTexture {
  10391. constructor( images, format, type ) {
  10392. super( undefined, images[ 0 ].width, images[ 0 ].height, format, type, CubeReflectionMapping );
  10393. this.isCompressedCubeTexture = true;
  10394. this.isCubeTexture = true;
  10395. this.image = images;
  10396. }
  10397. }
  10398. class CanvasTexture extends Texture {
  10399. constructor( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10400. super( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10401. this.isCanvasTexture = true;
  10402. this.needsUpdate = true;
  10403. }
  10404. }
  10405. class DepthTexture extends Texture {
  10406. constructor( width, height, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy, format = DepthFormat ) {
  10407. if ( format !== DepthFormat && format !== DepthStencilFormat ) {
  10408. throw new Error( 'DepthTexture format must be either THREE.DepthFormat or THREE.DepthStencilFormat' );
  10409. }
  10410. if ( type === undefined && format === DepthFormat ) type = UnsignedIntType;
  10411. if ( type === undefined && format === DepthStencilFormat ) type = UnsignedInt248Type;
  10412. super( null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10413. this.isDepthTexture = true;
  10414. this.image = { width: width, height: height };
  10415. this.magFilter = magFilter !== undefined ? magFilter : NearestFilter;
  10416. this.minFilter = minFilter !== undefined ? minFilter : NearestFilter;
  10417. this.flipY = false;
  10418. this.generateMipmaps = false;
  10419. this.compareFunction = null;
  10420. }
  10421. copy( source ) {
  10422. super.copy( source );
  10423. this.compareFunction = source.compareFunction;
  10424. return this;
  10425. }
  10426. toJSON( meta ) {
  10427. const data = super.toJSON( meta );
  10428. if ( this.compareFunction !== null ) data.compareFunction = this.compareFunction;
  10429. return data;
  10430. }
  10431. }
  10432. /**
  10433. * Extensible curve object.
  10434. *
  10435. * Some common of curve methods:
  10436. * .getPoint( t, optionalTarget ), .getTangent( t, optionalTarget )
  10437. * .getPointAt( u, optionalTarget ), .getTangentAt( u, optionalTarget )
  10438. * .getPoints(), .getSpacedPoints()
  10439. * .getLength()
  10440. * .updateArcLengths()
  10441. *
  10442. * This following curves inherit from THREE.Curve:
  10443. *
  10444. * -- 2D curves --
  10445. * THREE.ArcCurve
  10446. * THREE.CubicBezierCurve
  10447. * THREE.EllipseCurve
  10448. * THREE.LineCurve
  10449. * THREE.QuadraticBezierCurve
  10450. * THREE.SplineCurve
  10451. *
  10452. * -- 3D curves --
  10453. * THREE.CatmullRomCurve3
  10454. * THREE.CubicBezierCurve3
  10455. * THREE.LineCurve3
  10456. * THREE.QuadraticBezierCurve3
  10457. *
  10458. * A series of curves can be represented as a THREE.CurvePath.
  10459. *
  10460. **/
  10461. class Curve {
  10462. constructor() {
  10463. this.type = 'Curve';
  10464. this.arcLengthDivisions = 200;
  10465. }
  10466. // Virtual base class method to overwrite and implement in subclasses
  10467. // - t [0 .. 1]
  10468. getPoint( /* t, optionalTarget */ ) {
  10469. console.warn( 'THREE.Curve: .getPoint() not implemented.' );
  10470. return null;
  10471. }
  10472. // Get point at relative position in curve according to arc length
  10473. // - u [0 .. 1]
  10474. getPointAt( u, optionalTarget ) {
  10475. const t = this.getUtoTmapping( u );
  10476. return this.getPoint( t, optionalTarget );
  10477. }
  10478. // Get sequence of points using getPoint( t )
  10479. getPoints( divisions = 5 ) {
  10480. const points = [];
  10481. for ( let d = 0; d <= divisions; d ++ ) {
  10482. points.push( this.getPoint( d / divisions ) );
  10483. }
  10484. return points;
  10485. }
  10486. // Get sequence of points using getPointAt( u )
  10487. getSpacedPoints( divisions = 5 ) {
  10488. const points = [];
  10489. for ( let d = 0; d <= divisions; d ++ ) {
  10490. points.push( this.getPointAt( d / divisions ) );
  10491. }
  10492. return points;
  10493. }
  10494. // Get total curve arc length
  10495. getLength() {
  10496. const lengths = this.getLengths();
  10497. return lengths[ lengths.length - 1 ];
  10498. }
  10499. // Get list of cumulative segment lengths
  10500. getLengths( divisions = this.arcLengthDivisions ) {
  10501. if ( this.cacheArcLengths &&
  10502. ( this.cacheArcLengths.length === divisions + 1 ) &&
  10503. ! this.needsUpdate ) {
  10504. return this.cacheArcLengths;
  10505. }
  10506. this.needsUpdate = false;
  10507. const cache = [];
  10508. let current, last = this.getPoint( 0 );
  10509. let sum = 0;
  10510. cache.push( 0 );
  10511. for ( let p = 1; p <= divisions; p ++ ) {
  10512. current = this.getPoint( p / divisions );
  10513. sum += current.distanceTo( last );
  10514. cache.push( sum );
  10515. last = current;
  10516. }
  10517. this.cacheArcLengths = cache;
  10518. return cache; // { sums: cache, sum: sum }; Sum is in the last element.
  10519. }
  10520. updateArcLengths() {
  10521. this.needsUpdate = true;
  10522. this.getLengths();
  10523. }
  10524. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  10525. getUtoTmapping( u, distance ) {
  10526. const arcLengths = this.getLengths();
  10527. let i = 0;
  10528. const il = arcLengths.length;
  10529. let targetArcLength; // The targeted u distance value to get
  10530. if ( distance ) {
  10531. targetArcLength = distance;
  10532. } else {
  10533. targetArcLength = u * arcLengths[ il - 1 ];
  10534. }
  10535. // binary search for the index with largest value smaller than target u distance
  10536. let low = 0, high = il - 1, comparison;
  10537. while ( low <= high ) {
  10538. 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
  10539. comparison = arcLengths[ i ] - targetArcLength;
  10540. if ( comparison < 0 ) {
  10541. low = i + 1;
  10542. } else if ( comparison > 0 ) {
  10543. high = i - 1;
  10544. } else {
  10545. high = i;
  10546. break;
  10547. // DONE
  10548. }
  10549. }
  10550. i = high;
  10551. if ( arcLengths[ i ] === targetArcLength ) {
  10552. return i / ( il - 1 );
  10553. }
  10554. // we could get finer grain at lengths, or use simple interpolation between two points
  10555. const lengthBefore = arcLengths[ i ];
  10556. const lengthAfter = arcLengths[ i + 1 ];
  10557. const segmentLength = lengthAfter - lengthBefore;
  10558. // determine where we are between the 'before' and 'after' points
  10559. const segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  10560. // add that fractional amount to t
  10561. const t = ( i + segmentFraction ) / ( il - 1 );
  10562. return t;
  10563. }
  10564. // Returns a unit vector tangent at t
  10565. // In case any sub curve does not implement its tangent derivation,
  10566. // 2 points a small delta apart will be used to find its gradient
  10567. // which seems to give a reasonable approximation
  10568. getTangent( t, optionalTarget ) {
  10569. const delta = 0.0001;
  10570. let t1 = t - delta;
  10571. let t2 = t + delta;
  10572. // Capping in case of danger
  10573. if ( t1 < 0 ) t1 = 0;
  10574. if ( t2 > 1 ) t2 = 1;
  10575. const pt1 = this.getPoint( t1 );
  10576. const pt2 = this.getPoint( t2 );
  10577. const tangent = optionalTarget || ( ( pt1.isVector2 ) ? new Vector2() : new Vector3() );
  10578. tangent.copy( pt2 ).sub( pt1 ).normalize();
  10579. return tangent;
  10580. }
  10581. getTangentAt( u, optionalTarget ) {
  10582. const t = this.getUtoTmapping( u );
  10583. return this.getTangent( t, optionalTarget );
  10584. }
  10585. computeFrenetFrames( segments, closed ) {
  10586. // see http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  10587. const normal = new Vector3();
  10588. const tangents = [];
  10589. const normals = [];
  10590. const binormals = [];
  10591. const vec = new Vector3();
  10592. const mat = new Matrix4();
  10593. // compute the tangent vectors for each segment on the curve
  10594. for ( let i = 0; i <= segments; i ++ ) {
  10595. const u = i / segments;
  10596. tangents[ i ] = this.getTangentAt( u, new Vector3() );
  10597. }
  10598. // select an initial normal vector perpendicular to the first tangent vector,
  10599. // and in the direction of the minimum tangent xyz component
  10600. normals[ 0 ] = new Vector3();
  10601. binormals[ 0 ] = new Vector3();
  10602. let min = Number.MAX_VALUE;
  10603. const tx = Math.abs( tangents[ 0 ].x );
  10604. const ty = Math.abs( tangents[ 0 ].y );
  10605. const tz = Math.abs( tangents[ 0 ].z );
  10606. if ( tx <= min ) {
  10607. min = tx;
  10608. normal.set( 1, 0, 0 );
  10609. }
  10610. if ( ty <= min ) {
  10611. min = ty;
  10612. normal.set( 0, 1, 0 );
  10613. }
  10614. if ( tz <= min ) {
  10615. normal.set( 0, 0, 1 );
  10616. }
  10617. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  10618. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  10619. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  10620. // compute the slowly-varying normal and binormal vectors for each segment on the curve
  10621. for ( let i = 1; i <= segments; i ++ ) {
  10622. normals[ i ] = normals[ i - 1 ].clone();
  10623. binormals[ i ] = binormals[ i - 1 ].clone();
  10624. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  10625. if ( vec.length() > Number.EPSILON ) {
  10626. vec.normalize();
  10627. const theta = Math.acos( clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  10628. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  10629. }
  10630. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10631. }
  10632. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  10633. if ( closed === true ) {
  10634. let theta = Math.acos( clamp( normals[ 0 ].dot( normals[ segments ] ), - 1, 1 ) );
  10635. theta /= segments;
  10636. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ segments ] ) ) > 0 ) {
  10637. theta = - theta;
  10638. }
  10639. for ( let i = 1; i <= segments; i ++ ) {
  10640. // twist a little...
  10641. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  10642. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  10643. }
  10644. }
  10645. return {
  10646. tangents: tangents,
  10647. normals: normals,
  10648. binormals: binormals
  10649. };
  10650. }
  10651. clone() {
  10652. return new this.constructor().copy( this );
  10653. }
  10654. copy( source ) {
  10655. this.arcLengthDivisions = source.arcLengthDivisions;
  10656. return this;
  10657. }
  10658. toJSON() {
  10659. const data = {
  10660. metadata: {
  10661. version: 4.6,
  10662. type: 'Curve',
  10663. generator: 'Curve.toJSON'
  10664. }
  10665. };
  10666. data.arcLengthDivisions = this.arcLengthDivisions;
  10667. data.type = this.type;
  10668. return data;
  10669. }
  10670. fromJSON( json ) {
  10671. this.arcLengthDivisions = json.arcLengthDivisions;
  10672. return this;
  10673. }
  10674. }
  10675. class EllipseCurve extends Curve {
  10676. constructor( aX = 0, aY = 0, xRadius = 1, yRadius = 1, aStartAngle = 0, aEndAngle = Math.PI * 2, aClockwise = false, aRotation = 0 ) {
  10677. super();
  10678. this.isEllipseCurve = true;
  10679. this.type = 'EllipseCurve';
  10680. this.aX = aX;
  10681. this.aY = aY;
  10682. this.xRadius = xRadius;
  10683. this.yRadius = yRadius;
  10684. this.aStartAngle = aStartAngle;
  10685. this.aEndAngle = aEndAngle;
  10686. this.aClockwise = aClockwise;
  10687. this.aRotation = aRotation;
  10688. }
  10689. getPoint( t, optionalTarget = new Vector2() ) {
  10690. const point = optionalTarget;
  10691. const twoPi = Math.PI * 2;
  10692. let deltaAngle = this.aEndAngle - this.aStartAngle;
  10693. const samePoints = Math.abs( deltaAngle ) < Number.EPSILON;
  10694. // ensures that deltaAngle is 0 .. 2 PI
  10695. while ( deltaAngle < 0 ) deltaAngle += twoPi;
  10696. while ( deltaAngle > twoPi ) deltaAngle -= twoPi;
  10697. if ( deltaAngle < Number.EPSILON ) {
  10698. if ( samePoints ) {
  10699. deltaAngle = 0;
  10700. } else {
  10701. deltaAngle = twoPi;
  10702. }
  10703. }
  10704. if ( this.aClockwise === true && ! samePoints ) {
  10705. if ( deltaAngle === twoPi ) {
  10706. deltaAngle = - twoPi;
  10707. } else {
  10708. deltaAngle = deltaAngle - twoPi;
  10709. }
  10710. }
  10711. const angle = this.aStartAngle + t * deltaAngle;
  10712. let x = this.aX + this.xRadius * Math.cos( angle );
  10713. let y = this.aY + this.yRadius * Math.sin( angle );
  10714. if ( this.aRotation !== 0 ) {
  10715. const cos = Math.cos( this.aRotation );
  10716. const sin = Math.sin( this.aRotation );
  10717. const tx = x - this.aX;
  10718. const ty = y - this.aY;
  10719. // Rotate the point about the center of the ellipse.
  10720. x = tx * cos - ty * sin + this.aX;
  10721. y = tx * sin + ty * cos + this.aY;
  10722. }
  10723. return point.set( x, y );
  10724. }
  10725. copy( source ) {
  10726. super.copy( source );
  10727. this.aX = source.aX;
  10728. this.aY = source.aY;
  10729. this.xRadius = source.xRadius;
  10730. this.yRadius = source.yRadius;
  10731. this.aStartAngle = source.aStartAngle;
  10732. this.aEndAngle = source.aEndAngle;
  10733. this.aClockwise = source.aClockwise;
  10734. this.aRotation = source.aRotation;
  10735. return this;
  10736. }
  10737. toJSON() {
  10738. const data = super.toJSON();
  10739. data.aX = this.aX;
  10740. data.aY = this.aY;
  10741. data.xRadius = this.xRadius;
  10742. data.yRadius = this.yRadius;
  10743. data.aStartAngle = this.aStartAngle;
  10744. data.aEndAngle = this.aEndAngle;
  10745. data.aClockwise = this.aClockwise;
  10746. data.aRotation = this.aRotation;
  10747. return data;
  10748. }
  10749. fromJSON( json ) {
  10750. super.fromJSON( json );
  10751. this.aX = json.aX;
  10752. this.aY = json.aY;
  10753. this.xRadius = json.xRadius;
  10754. this.yRadius = json.yRadius;
  10755. this.aStartAngle = json.aStartAngle;
  10756. this.aEndAngle = json.aEndAngle;
  10757. this.aClockwise = json.aClockwise;
  10758. this.aRotation = json.aRotation;
  10759. return this;
  10760. }
  10761. }
  10762. class ArcCurve extends EllipseCurve {
  10763. constructor( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  10764. super( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  10765. this.isArcCurve = true;
  10766. this.type = 'ArcCurve';
  10767. }
  10768. }
  10769. /**
  10770. * Centripetal CatmullRom Curve - which is useful for avoiding
  10771. * cusps and self-intersections in non-uniform catmull rom curves.
  10772. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  10773. *
  10774. * curve.type accepts centripetal(default), chordal and catmullrom
  10775. * curve.tension is used for catmullrom which defaults to 0.5
  10776. */
  10777. /*
  10778. Based on an optimized c++ solution in
  10779. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  10780. - http://ideone.com/NoEbVM
  10781. This CubicPoly class could be used for reusing some variables and calculations,
  10782. but for three.js curve use, it could be possible inlined and flatten into a single function call
  10783. which can be placed in CurveUtils.
  10784. */
  10785. function CubicPoly() {
  10786. let c0 = 0, c1 = 0, c2 = 0, c3 = 0;
  10787. /*
  10788. * Compute coefficients for a cubic polynomial
  10789. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  10790. * such that
  10791. * p(0) = x0, p(1) = x1
  10792. * and
  10793. * p'(0) = t0, p'(1) = t1.
  10794. */
  10795. function init( x0, x1, t0, t1 ) {
  10796. c0 = x0;
  10797. c1 = t0;
  10798. c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  10799. c3 = 2 * x0 - 2 * x1 + t0 + t1;
  10800. }
  10801. return {
  10802. initCatmullRom: function ( x0, x1, x2, x3, tension ) {
  10803. init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  10804. },
  10805. initNonuniformCatmullRom: function ( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  10806. // compute tangents when parameterized in [t1,t2]
  10807. let t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  10808. let t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  10809. // rescale tangents for parametrization in [0,1]
  10810. t1 *= dt1;
  10811. t2 *= dt1;
  10812. init( x1, x2, t1, t2 );
  10813. },
  10814. calc: function ( t ) {
  10815. const t2 = t * t;
  10816. const t3 = t2 * t;
  10817. return c0 + c1 * t + c2 * t2 + c3 * t3;
  10818. }
  10819. };
  10820. }
  10821. //
  10822. const tmp = /*@__PURE__*/ new Vector3();
  10823. const px = /*@__PURE__*/ new CubicPoly();
  10824. const py = /*@__PURE__*/ new CubicPoly();
  10825. const pz = /*@__PURE__*/ new CubicPoly();
  10826. class CatmullRomCurve3 extends Curve {
  10827. constructor( points = [], closed = false, curveType = 'centripetal', tension = 0.5 ) {
  10828. super();
  10829. this.isCatmullRomCurve3 = true;
  10830. this.type = 'CatmullRomCurve3';
  10831. this.points = points;
  10832. this.closed = closed;
  10833. this.curveType = curveType;
  10834. this.tension = tension;
  10835. }
  10836. getPoint( t, optionalTarget = new Vector3() ) {
  10837. const point = optionalTarget;
  10838. const points = this.points;
  10839. const l = points.length;
  10840. const p = ( l - ( this.closed ? 0 : 1 ) ) * t;
  10841. let intPoint = Math.floor( p );
  10842. let weight = p - intPoint;
  10843. if ( this.closed ) {
  10844. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / l ) + 1 ) * l;
  10845. } else if ( weight === 0 && intPoint === l - 1 ) {
  10846. intPoint = l - 2;
  10847. weight = 1;
  10848. }
  10849. let p0, p3; // 4 points (p1 & p2 defined below)
  10850. if ( this.closed || intPoint > 0 ) {
  10851. p0 = points[ ( intPoint - 1 ) % l ];
  10852. } else {
  10853. // extrapolate first point
  10854. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  10855. p0 = tmp;
  10856. }
  10857. const p1 = points[ intPoint % l ];
  10858. const p2 = points[ ( intPoint + 1 ) % l ];
  10859. if ( this.closed || intPoint + 2 < l ) {
  10860. p3 = points[ ( intPoint + 2 ) % l ];
  10861. } else {
  10862. // extrapolate last point
  10863. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  10864. p3 = tmp;
  10865. }
  10866. if ( this.curveType === 'centripetal' || this.curveType === 'chordal' ) {
  10867. // init Centripetal / Chordal Catmull-Rom
  10868. const pow = this.curveType === 'chordal' ? 0.5 : 0.25;
  10869. let dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  10870. let dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  10871. let dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  10872. // safety check for repeated points
  10873. if ( dt1 < 1e-4 ) dt1 = 1.0;
  10874. if ( dt0 < 1e-4 ) dt0 = dt1;
  10875. if ( dt2 < 1e-4 ) dt2 = dt1;
  10876. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  10877. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  10878. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  10879. } else if ( this.curveType === 'catmullrom' ) {
  10880. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, this.tension );
  10881. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, this.tension );
  10882. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, this.tension );
  10883. }
  10884. point.set(
  10885. px.calc( weight ),
  10886. py.calc( weight ),
  10887. pz.calc( weight )
  10888. );
  10889. return point;
  10890. }
  10891. copy( source ) {
  10892. super.copy( source );
  10893. this.points = [];
  10894. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  10895. const point = source.points[ i ];
  10896. this.points.push( point.clone() );
  10897. }
  10898. this.closed = source.closed;
  10899. this.curveType = source.curveType;
  10900. this.tension = source.tension;
  10901. return this;
  10902. }
  10903. toJSON() {
  10904. const data = super.toJSON();
  10905. data.points = [];
  10906. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  10907. const point = this.points[ i ];
  10908. data.points.push( point.toArray() );
  10909. }
  10910. data.closed = this.closed;
  10911. data.curveType = this.curveType;
  10912. data.tension = this.tension;
  10913. return data;
  10914. }
  10915. fromJSON( json ) {
  10916. super.fromJSON( json );
  10917. this.points = [];
  10918. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  10919. const point = json.points[ i ];
  10920. this.points.push( new Vector3().fromArray( point ) );
  10921. }
  10922. this.closed = json.closed;
  10923. this.curveType = json.curveType;
  10924. this.tension = json.tension;
  10925. return this;
  10926. }
  10927. }
  10928. /**
  10929. * Bezier Curves formulas obtained from
  10930. * https://en.wikipedia.org/wiki/B%C3%A9zier_curve
  10931. */
  10932. function CatmullRom( t, p0, p1, p2, p3 ) {
  10933. const v0 = ( p2 - p0 ) * 0.5;
  10934. const v1 = ( p3 - p1 ) * 0.5;
  10935. const t2 = t * t;
  10936. const t3 = t * t2;
  10937. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  10938. }
  10939. //
  10940. function QuadraticBezierP0( t, p ) {
  10941. const k = 1 - t;
  10942. return k * k * p;
  10943. }
  10944. function QuadraticBezierP1( t, p ) {
  10945. return 2 * ( 1 - t ) * t * p;
  10946. }
  10947. function QuadraticBezierP2( t, p ) {
  10948. return t * t * p;
  10949. }
  10950. function QuadraticBezier( t, p0, p1, p2 ) {
  10951. return QuadraticBezierP0( t, p0 ) + QuadraticBezierP1( t, p1 ) +
  10952. QuadraticBezierP2( t, p2 );
  10953. }
  10954. //
  10955. function CubicBezierP0( t, p ) {
  10956. const k = 1 - t;
  10957. return k * k * k * p;
  10958. }
  10959. function CubicBezierP1( t, p ) {
  10960. const k = 1 - t;
  10961. return 3 * k * k * t * p;
  10962. }
  10963. function CubicBezierP2( t, p ) {
  10964. return 3 * ( 1 - t ) * t * t * p;
  10965. }
  10966. function CubicBezierP3( t, p ) {
  10967. return t * t * t * p;
  10968. }
  10969. function CubicBezier( t, p0, p1, p2, p3 ) {
  10970. return CubicBezierP0( t, p0 ) + CubicBezierP1( t, p1 ) + CubicBezierP2( t, p2 ) +
  10971. CubicBezierP3( t, p3 );
  10972. }
  10973. class CubicBezierCurve extends Curve {
  10974. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2(), v3 = new Vector2() ) {
  10975. super();
  10976. this.isCubicBezierCurve = true;
  10977. this.type = 'CubicBezierCurve';
  10978. this.v0 = v0;
  10979. this.v1 = v1;
  10980. this.v2 = v2;
  10981. this.v3 = v3;
  10982. }
  10983. getPoint( t, optionalTarget = new Vector2() ) {
  10984. const point = optionalTarget;
  10985. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  10986. point.set(
  10987. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  10988. CubicBezier( t, v0.y, v1.y, v2.y, v3.y )
  10989. );
  10990. return point;
  10991. }
  10992. copy( source ) {
  10993. super.copy( source );
  10994. this.v0.copy( source.v0 );
  10995. this.v1.copy( source.v1 );
  10996. this.v2.copy( source.v2 );
  10997. this.v3.copy( source.v3 );
  10998. return this;
  10999. }
  11000. toJSON() {
  11001. const data = super.toJSON();
  11002. data.v0 = this.v0.toArray();
  11003. data.v1 = this.v1.toArray();
  11004. data.v2 = this.v2.toArray();
  11005. data.v3 = this.v3.toArray();
  11006. return data;
  11007. }
  11008. fromJSON( json ) {
  11009. super.fromJSON( json );
  11010. this.v0.fromArray( json.v0 );
  11011. this.v1.fromArray( json.v1 );
  11012. this.v2.fromArray( json.v2 );
  11013. this.v3.fromArray( json.v3 );
  11014. return this;
  11015. }
  11016. }
  11017. class CubicBezierCurve3 extends Curve {
  11018. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3(), v3 = new Vector3() ) {
  11019. super();
  11020. this.isCubicBezierCurve3 = true;
  11021. this.type = 'CubicBezierCurve3';
  11022. this.v0 = v0;
  11023. this.v1 = v1;
  11024. this.v2 = v2;
  11025. this.v3 = v3;
  11026. }
  11027. getPoint( t, optionalTarget = new Vector3() ) {
  11028. const point = optionalTarget;
  11029. const v0 = this.v0, v1 = this.v1, v2 = this.v2, v3 = this.v3;
  11030. point.set(
  11031. CubicBezier( t, v0.x, v1.x, v2.x, v3.x ),
  11032. CubicBezier( t, v0.y, v1.y, v2.y, v3.y ),
  11033. CubicBezier( t, v0.z, v1.z, v2.z, v3.z )
  11034. );
  11035. return point;
  11036. }
  11037. copy( source ) {
  11038. super.copy( source );
  11039. this.v0.copy( source.v0 );
  11040. this.v1.copy( source.v1 );
  11041. this.v2.copy( source.v2 );
  11042. this.v3.copy( source.v3 );
  11043. return this;
  11044. }
  11045. toJSON() {
  11046. const data = super.toJSON();
  11047. data.v0 = this.v0.toArray();
  11048. data.v1 = this.v1.toArray();
  11049. data.v2 = this.v2.toArray();
  11050. data.v3 = this.v3.toArray();
  11051. return data;
  11052. }
  11053. fromJSON( json ) {
  11054. super.fromJSON( json );
  11055. this.v0.fromArray( json.v0 );
  11056. this.v1.fromArray( json.v1 );
  11057. this.v2.fromArray( json.v2 );
  11058. this.v3.fromArray( json.v3 );
  11059. return this;
  11060. }
  11061. }
  11062. class LineCurve extends Curve {
  11063. constructor( v1 = new Vector2(), v2 = new Vector2() ) {
  11064. super();
  11065. this.isLineCurve = true;
  11066. this.type = 'LineCurve';
  11067. this.v1 = v1;
  11068. this.v2 = v2;
  11069. }
  11070. getPoint( t, optionalTarget = new Vector2() ) {
  11071. const point = optionalTarget;
  11072. if ( t === 1 ) {
  11073. point.copy( this.v2 );
  11074. } else {
  11075. point.copy( this.v2 ).sub( this.v1 );
  11076. point.multiplyScalar( t ).add( this.v1 );
  11077. }
  11078. return point;
  11079. }
  11080. // Line curve is linear, so we can overwrite default getPointAt
  11081. getPointAt( u, optionalTarget ) {
  11082. return this.getPoint( u, optionalTarget );
  11083. }
  11084. getTangent( t, optionalTarget = new Vector2() ) {
  11085. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11086. }
  11087. getTangentAt( u, optionalTarget ) {
  11088. return this.getTangent( u, optionalTarget );
  11089. }
  11090. copy( source ) {
  11091. super.copy( source );
  11092. this.v1.copy( source.v1 );
  11093. this.v2.copy( source.v2 );
  11094. return this;
  11095. }
  11096. toJSON() {
  11097. const data = super.toJSON();
  11098. data.v1 = this.v1.toArray();
  11099. data.v2 = this.v2.toArray();
  11100. return data;
  11101. }
  11102. fromJSON( json ) {
  11103. super.fromJSON( json );
  11104. this.v1.fromArray( json.v1 );
  11105. this.v2.fromArray( json.v2 );
  11106. return this;
  11107. }
  11108. }
  11109. class LineCurve3 extends Curve {
  11110. constructor( v1 = new Vector3(), v2 = new Vector3() ) {
  11111. super();
  11112. this.isLineCurve3 = true;
  11113. this.type = 'LineCurve3';
  11114. this.v1 = v1;
  11115. this.v2 = v2;
  11116. }
  11117. getPoint( t, optionalTarget = new Vector3() ) {
  11118. const point = optionalTarget;
  11119. if ( t === 1 ) {
  11120. point.copy( this.v2 );
  11121. } else {
  11122. point.copy( this.v2 ).sub( this.v1 );
  11123. point.multiplyScalar( t ).add( this.v1 );
  11124. }
  11125. return point;
  11126. }
  11127. // Line curve is linear, so we can overwrite default getPointAt
  11128. getPointAt( u, optionalTarget ) {
  11129. return this.getPoint( u, optionalTarget );
  11130. }
  11131. getTangent( t, optionalTarget = new Vector3() ) {
  11132. return optionalTarget.subVectors( this.v2, this.v1 ).normalize();
  11133. }
  11134. getTangentAt( u, optionalTarget ) {
  11135. return this.getTangent( u, optionalTarget );
  11136. }
  11137. copy( source ) {
  11138. super.copy( source );
  11139. this.v1.copy( source.v1 );
  11140. this.v2.copy( source.v2 );
  11141. return this;
  11142. }
  11143. toJSON() {
  11144. const data = super.toJSON();
  11145. data.v1 = this.v1.toArray();
  11146. data.v2 = this.v2.toArray();
  11147. return data;
  11148. }
  11149. fromJSON( json ) {
  11150. super.fromJSON( json );
  11151. this.v1.fromArray( json.v1 );
  11152. this.v2.fromArray( json.v2 );
  11153. return this;
  11154. }
  11155. }
  11156. class QuadraticBezierCurve extends Curve {
  11157. constructor( v0 = new Vector2(), v1 = new Vector2(), v2 = new Vector2() ) {
  11158. super();
  11159. this.isQuadraticBezierCurve = true;
  11160. this.type = 'QuadraticBezierCurve';
  11161. this.v0 = v0;
  11162. this.v1 = v1;
  11163. this.v2 = v2;
  11164. }
  11165. getPoint( t, optionalTarget = new Vector2() ) {
  11166. const point = optionalTarget;
  11167. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11168. point.set(
  11169. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11170. QuadraticBezier( t, v0.y, v1.y, v2.y )
  11171. );
  11172. return point;
  11173. }
  11174. copy( source ) {
  11175. super.copy( source );
  11176. this.v0.copy( source.v0 );
  11177. this.v1.copy( source.v1 );
  11178. this.v2.copy( source.v2 );
  11179. return this;
  11180. }
  11181. toJSON() {
  11182. const data = super.toJSON();
  11183. data.v0 = this.v0.toArray();
  11184. data.v1 = this.v1.toArray();
  11185. data.v2 = this.v2.toArray();
  11186. return data;
  11187. }
  11188. fromJSON( json ) {
  11189. super.fromJSON( json );
  11190. this.v0.fromArray( json.v0 );
  11191. this.v1.fromArray( json.v1 );
  11192. this.v2.fromArray( json.v2 );
  11193. return this;
  11194. }
  11195. }
  11196. class QuadraticBezierCurve3 extends Curve {
  11197. constructor( v0 = new Vector3(), v1 = new Vector3(), v2 = new Vector3() ) {
  11198. super();
  11199. this.isQuadraticBezierCurve3 = true;
  11200. this.type = 'QuadraticBezierCurve3';
  11201. this.v0 = v0;
  11202. this.v1 = v1;
  11203. this.v2 = v2;
  11204. }
  11205. getPoint( t, optionalTarget = new Vector3() ) {
  11206. const point = optionalTarget;
  11207. const v0 = this.v0, v1 = this.v1, v2 = this.v2;
  11208. point.set(
  11209. QuadraticBezier( t, v0.x, v1.x, v2.x ),
  11210. QuadraticBezier( t, v0.y, v1.y, v2.y ),
  11211. QuadraticBezier( t, v0.z, v1.z, v2.z )
  11212. );
  11213. return point;
  11214. }
  11215. copy( source ) {
  11216. super.copy( source );
  11217. this.v0.copy( source.v0 );
  11218. this.v1.copy( source.v1 );
  11219. this.v2.copy( source.v2 );
  11220. return this;
  11221. }
  11222. toJSON() {
  11223. const data = super.toJSON();
  11224. data.v0 = this.v0.toArray();
  11225. data.v1 = this.v1.toArray();
  11226. data.v2 = this.v2.toArray();
  11227. return data;
  11228. }
  11229. fromJSON( json ) {
  11230. super.fromJSON( json );
  11231. this.v0.fromArray( json.v0 );
  11232. this.v1.fromArray( json.v1 );
  11233. this.v2.fromArray( json.v2 );
  11234. return this;
  11235. }
  11236. }
  11237. class SplineCurve extends Curve {
  11238. constructor( points = [] ) {
  11239. super();
  11240. this.isSplineCurve = true;
  11241. this.type = 'SplineCurve';
  11242. this.points = points;
  11243. }
  11244. getPoint( t, optionalTarget = new Vector2() ) {
  11245. const point = optionalTarget;
  11246. const points = this.points;
  11247. const p = ( points.length - 1 ) * t;
  11248. const intPoint = Math.floor( p );
  11249. const weight = p - intPoint;
  11250. const p0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  11251. const p1 = points[ intPoint ];
  11252. const p2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  11253. const p3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  11254. point.set(
  11255. CatmullRom( weight, p0.x, p1.x, p2.x, p3.x ),
  11256. CatmullRom( weight, p0.y, p1.y, p2.y, p3.y )
  11257. );
  11258. return point;
  11259. }
  11260. copy( source ) {
  11261. super.copy( source );
  11262. this.points = [];
  11263. for ( let i = 0, l = source.points.length; i < l; i ++ ) {
  11264. const point = source.points[ i ];
  11265. this.points.push( point.clone() );
  11266. }
  11267. return this;
  11268. }
  11269. toJSON() {
  11270. const data = super.toJSON();
  11271. data.points = [];
  11272. for ( let i = 0, l = this.points.length; i < l; i ++ ) {
  11273. const point = this.points[ i ];
  11274. data.points.push( point.toArray() );
  11275. }
  11276. return data;
  11277. }
  11278. fromJSON( json ) {
  11279. super.fromJSON( json );
  11280. this.points = [];
  11281. for ( let i = 0, l = json.points.length; i < l; i ++ ) {
  11282. const point = json.points[ i ];
  11283. this.points.push( new Vector2().fromArray( point ) );
  11284. }
  11285. return this;
  11286. }
  11287. }
  11288. var Curves = /*#__PURE__*/Object.freeze({
  11289. __proto__: null,
  11290. ArcCurve: ArcCurve,
  11291. CatmullRomCurve3: CatmullRomCurve3,
  11292. CubicBezierCurve: CubicBezierCurve,
  11293. CubicBezierCurve3: CubicBezierCurve3,
  11294. EllipseCurve: EllipseCurve,
  11295. LineCurve: LineCurve,
  11296. LineCurve3: LineCurve3,
  11297. QuadraticBezierCurve: QuadraticBezierCurve,
  11298. QuadraticBezierCurve3: QuadraticBezierCurve3,
  11299. SplineCurve: SplineCurve
  11300. });
  11301. /**************************************************************
  11302. * Curved Path - a curve path is simply a array of connected
  11303. * curves, but retains the api of a curve
  11304. **************************************************************/
  11305. class CurvePath extends Curve {
  11306. constructor() {
  11307. super();
  11308. this.type = 'CurvePath';
  11309. this.curves = [];
  11310. this.autoClose = false; // Automatically closes the path
  11311. }
  11312. add( curve ) {
  11313. this.curves.push( curve );
  11314. }
  11315. closePath() {
  11316. // Add a line curve if start and end of lines are not connected
  11317. const startPoint = this.curves[ 0 ].getPoint( 0 );
  11318. const endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  11319. if ( ! startPoint.equals( endPoint ) ) {
  11320. const lineType = ( startPoint.isVector2 === true ) ? 'LineCurve' : 'LineCurve3';
  11321. this.curves.push( new Curves[ lineType ]( endPoint, startPoint ) );
  11322. }
  11323. return this;
  11324. }
  11325. // To get accurate point with reference to
  11326. // entire path distance at time t,
  11327. // following has to be done:
  11328. // 1. Length of each sub path have to be known
  11329. // 2. Locate and identify type of curve
  11330. // 3. Get t for the curve
  11331. // 4. Return curve.getPointAt(t')
  11332. getPoint( t, optionalTarget ) {
  11333. const d = t * this.getLength();
  11334. const curveLengths = this.getCurveLengths();
  11335. let i = 0;
  11336. // To think about boundaries points.
  11337. while ( i < curveLengths.length ) {
  11338. if ( curveLengths[ i ] >= d ) {
  11339. const diff = curveLengths[ i ] - d;
  11340. const curve = this.curves[ i ];
  11341. const segmentLength = curve.getLength();
  11342. const u = segmentLength === 0 ? 0 : 1 - diff / segmentLength;
  11343. return curve.getPointAt( u, optionalTarget );
  11344. }
  11345. i ++;
  11346. }
  11347. return null;
  11348. // loop where sum != 0, sum > d , sum+1 <d
  11349. }
  11350. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  11351. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  11352. // getPoint() depends on getLength
  11353. getLength() {
  11354. const lens = this.getCurveLengths();
  11355. return lens[ lens.length - 1 ];
  11356. }
  11357. // cacheLengths must be recalculated.
  11358. updateArcLengths() {
  11359. this.needsUpdate = true;
  11360. this.cacheLengths = null;
  11361. this.getCurveLengths();
  11362. }
  11363. // Compute lengths and cache them
  11364. // We cannot overwrite getLengths() because UtoT mapping uses it.
  11365. getCurveLengths() {
  11366. // We use cache values if curves and cache array are same length
  11367. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  11368. return this.cacheLengths;
  11369. }
  11370. // Get length of sub-curve
  11371. // Push sums into cached array
  11372. const lengths = [];
  11373. let sums = 0;
  11374. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11375. sums += this.curves[ i ].getLength();
  11376. lengths.push( sums );
  11377. }
  11378. this.cacheLengths = lengths;
  11379. return lengths;
  11380. }
  11381. getSpacedPoints( divisions = 40 ) {
  11382. const points = [];
  11383. for ( let i = 0; i <= divisions; i ++ ) {
  11384. points.push( this.getPoint( i / divisions ) );
  11385. }
  11386. if ( this.autoClose ) {
  11387. points.push( points[ 0 ] );
  11388. }
  11389. return points;
  11390. }
  11391. getPoints( divisions = 12 ) {
  11392. const points = [];
  11393. let last;
  11394. for ( let i = 0, curves = this.curves; i < curves.length; i ++ ) {
  11395. const curve = curves[ i ];
  11396. const resolution = curve.isEllipseCurve ? divisions * 2
  11397. : ( curve.isLineCurve || curve.isLineCurve3 ) ? 1
  11398. : curve.isSplineCurve ? divisions * curve.points.length
  11399. : divisions;
  11400. const pts = curve.getPoints( resolution );
  11401. for ( let j = 0; j < pts.length; j ++ ) {
  11402. const point = pts[ j ];
  11403. if ( last && last.equals( point ) ) continue; // ensures no consecutive points are duplicates
  11404. points.push( point );
  11405. last = point;
  11406. }
  11407. }
  11408. if ( this.autoClose && points.length > 1 && ! points[ points.length - 1 ].equals( points[ 0 ] ) ) {
  11409. points.push( points[ 0 ] );
  11410. }
  11411. return points;
  11412. }
  11413. copy( source ) {
  11414. super.copy( source );
  11415. this.curves = [];
  11416. for ( let i = 0, l = source.curves.length; i < l; i ++ ) {
  11417. const curve = source.curves[ i ];
  11418. this.curves.push( curve.clone() );
  11419. }
  11420. this.autoClose = source.autoClose;
  11421. return this;
  11422. }
  11423. toJSON() {
  11424. const data = super.toJSON();
  11425. data.autoClose = this.autoClose;
  11426. data.curves = [];
  11427. for ( let i = 0, l = this.curves.length; i < l; i ++ ) {
  11428. const curve = this.curves[ i ];
  11429. data.curves.push( curve.toJSON() );
  11430. }
  11431. return data;
  11432. }
  11433. fromJSON( json ) {
  11434. super.fromJSON( json );
  11435. this.autoClose = json.autoClose;
  11436. this.curves = [];
  11437. for ( let i = 0, l = json.curves.length; i < l; i ++ ) {
  11438. const curve = json.curves[ i ];
  11439. this.curves.push( new Curves[ curve.type ]().fromJSON( curve ) );
  11440. }
  11441. return this;
  11442. }
  11443. }
  11444. class Path extends CurvePath {
  11445. constructor( points ) {
  11446. super();
  11447. this.type = 'Path';
  11448. this.currentPoint = new Vector2();
  11449. if ( points ) {
  11450. this.setFromPoints( points );
  11451. }
  11452. }
  11453. setFromPoints( points ) {
  11454. this.moveTo( points[ 0 ].x, points[ 0 ].y );
  11455. for ( let i = 1, l = points.length; i < l; i ++ ) {
  11456. this.lineTo( points[ i ].x, points[ i ].y );
  11457. }
  11458. return this;
  11459. }
  11460. moveTo( x, y ) {
  11461. this.currentPoint.set( x, y ); // TODO consider referencing vectors instead of copying?
  11462. return this;
  11463. }
  11464. lineTo( x, y ) {
  11465. const curve = new LineCurve( this.currentPoint.clone(), new Vector2( x, y ) );
  11466. this.curves.push( curve );
  11467. this.currentPoint.set( x, y );
  11468. return this;
  11469. }
  11470. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  11471. const curve = new QuadraticBezierCurve(
  11472. this.currentPoint.clone(),
  11473. new Vector2( aCPx, aCPy ),
  11474. new Vector2( aX, aY )
  11475. );
  11476. this.curves.push( curve );
  11477. this.currentPoint.set( aX, aY );
  11478. return this;
  11479. }
  11480. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  11481. const curve = new CubicBezierCurve(
  11482. this.currentPoint.clone(),
  11483. new Vector2( aCP1x, aCP1y ),
  11484. new Vector2( aCP2x, aCP2y ),
  11485. new Vector2( aX, aY )
  11486. );
  11487. this.curves.push( curve );
  11488. this.currentPoint.set( aX, aY );
  11489. return this;
  11490. }
  11491. splineThru( pts /*Array of Vector*/ ) {
  11492. const npts = [ this.currentPoint.clone() ].concat( pts );
  11493. const curve = new SplineCurve( npts );
  11494. this.curves.push( curve );
  11495. this.currentPoint.copy( pts[ pts.length - 1 ] );
  11496. return this;
  11497. }
  11498. arc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11499. const x0 = this.currentPoint.x;
  11500. const y0 = this.currentPoint.y;
  11501. this.absarc( aX + x0, aY + y0, aRadius,
  11502. aStartAngle, aEndAngle, aClockwise );
  11503. return this;
  11504. }
  11505. absarc( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  11506. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  11507. return this;
  11508. }
  11509. ellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11510. const x0 = this.currentPoint.x;
  11511. const y0 = this.currentPoint.y;
  11512. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11513. return this;
  11514. }
  11515. absellipse( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  11516. const curve = new EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  11517. if ( this.curves.length > 0 ) {
  11518. // if a previous curve is present, attempt to join
  11519. const firstPoint = curve.getPoint( 0 );
  11520. if ( ! firstPoint.equals( this.currentPoint ) ) {
  11521. this.lineTo( firstPoint.x, firstPoint.y );
  11522. }
  11523. }
  11524. this.curves.push( curve );
  11525. const lastPoint = curve.getPoint( 1 );
  11526. this.currentPoint.copy( lastPoint );
  11527. return this;
  11528. }
  11529. copy( source ) {
  11530. super.copy( source );
  11531. this.currentPoint.copy( source.currentPoint );
  11532. return this;
  11533. }
  11534. toJSON() {
  11535. const data = super.toJSON();
  11536. data.currentPoint = this.currentPoint.toArray();
  11537. return data;
  11538. }
  11539. fromJSON( json ) {
  11540. super.fromJSON( json );
  11541. this.currentPoint.fromArray( json.currentPoint );
  11542. return this;
  11543. }
  11544. }
  11545. class LatheGeometry extends BufferGeometry {
  11546. 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 ) {
  11547. super();
  11548. this.type = 'LatheGeometry';
  11549. this.parameters = {
  11550. points: points,
  11551. segments: segments,
  11552. phiStart: phiStart,
  11553. phiLength: phiLength
  11554. };
  11555. segments = Math.floor( segments );
  11556. // clamp phiLength so it's in range of [ 0, 2PI ]
  11557. phiLength = clamp( phiLength, 0, Math.PI * 2 );
  11558. // buffers
  11559. const indices = [];
  11560. const vertices = [];
  11561. const uvs = [];
  11562. const initNormals = [];
  11563. const normals = [];
  11564. // helper variables
  11565. const inverseSegments = 1.0 / segments;
  11566. const vertex = new Vector3();
  11567. const uv = new Vector2();
  11568. const normal = new Vector3();
  11569. const curNormal = new Vector3();
  11570. const prevNormal = new Vector3();
  11571. let dx = 0;
  11572. let dy = 0;
  11573. // pre-compute normals for initial "meridian"
  11574. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11575. switch ( j ) {
  11576. case 0: // special handling for 1st vertex on path
  11577. dx = points[ j + 1 ].x - points[ j ].x;
  11578. dy = points[ j + 1 ].y - points[ j ].y;
  11579. normal.x = dy * 1.0;
  11580. normal.y = - dx;
  11581. normal.z = dy * 0.0;
  11582. prevNormal.copy( normal );
  11583. normal.normalize();
  11584. initNormals.push( normal.x, normal.y, normal.z );
  11585. break;
  11586. case ( points.length - 1 ): // special handling for last Vertex on path
  11587. initNormals.push( prevNormal.x, prevNormal.y, prevNormal.z );
  11588. break;
  11589. default: // default handling for all vertices in between
  11590. dx = points[ j + 1 ].x - points[ j ].x;
  11591. dy = points[ j + 1 ].y - points[ j ].y;
  11592. normal.x = dy * 1.0;
  11593. normal.y = - dx;
  11594. normal.z = dy * 0.0;
  11595. curNormal.copy( normal );
  11596. normal.x += prevNormal.x;
  11597. normal.y += prevNormal.y;
  11598. normal.z += prevNormal.z;
  11599. normal.normalize();
  11600. initNormals.push( normal.x, normal.y, normal.z );
  11601. prevNormal.copy( curNormal );
  11602. }
  11603. }
  11604. // generate vertices, uvs and normals
  11605. for ( let i = 0; i <= segments; i ++ ) {
  11606. const phi = phiStart + i * inverseSegments * phiLength;
  11607. const sin = Math.sin( phi );
  11608. const cos = Math.cos( phi );
  11609. for ( let j = 0; j <= ( points.length - 1 ); j ++ ) {
  11610. // vertex
  11611. vertex.x = points[ j ].x * sin;
  11612. vertex.y = points[ j ].y;
  11613. vertex.z = points[ j ].x * cos;
  11614. vertices.push( vertex.x, vertex.y, vertex.z );
  11615. // uv
  11616. uv.x = i / segments;
  11617. uv.y = j / ( points.length - 1 );
  11618. uvs.push( uv.x, uv.y );
  11619. // normal
  11620. const x = initNormals[ 3 * j + 0 ] * sin;
  11621. const y = initNormals[ 3 * j + 1 ];
  11622. const z = initNormals[ 3 * j + 0 ] * cos;
  11623. normals.push( x, y, z );
  11624. }
  11625. }
  11626. // indices
  11627. for ( let i = 0; i < segments; i ++ ) {
  11628. for ( let j = 0; j < ( points.length - 1 ); j ++ ) {
  11629. const base = j + i * points.length;
  11630. const a = base;
  11631. const b = base + points.length;
  11632. const c = base + points.length + 1;
  11633. const d = base + 1;
  11634. // faces
  11635. indices.push( a, b, d );
  11636. indices.push( c, d, b );
  11637. }
  11638. }
  11639. // build geometry
  11640. this.setIndex( indices );
  11641. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11642. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11643. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11644. }
  11645. copy( source ) {
  11646. super.copy( source );
  11647. this.parameters = Object.assign( {}, source.parameters );
  11648. return this;
  11649. }
  11650. static fromJSON( data ) {
  11651. return new LatheGeometry( data.points, data.segments, data.phiStart, data.phiLength );
  11652. }
  11653. }
  11654. class CapsuleGeometry extends LatheGeometry {
  11655. constructor( radius = 1, length = 1, capSegments = 4, radialSegments = 8 ) {
  11656. const path = new Path();
  11657. path.absarc( 0, - length / 2, radius, Math.PI * 1.5, 0 );
  11658. path.absarc( 0, length / 2, radius, 0, Math.PI * 0.5 );
  11659. super( path.getPoints( capSegments ), radialSegments );
  11660. this.type = 'CapsuleGeometry';
  11661. this.parameters = {
  11662. radius: radius,
  11663. length: length,
  11664. capSegments: capSegments,
  11665. radialSegments: radialSegments,
  11666. };
  11667. }
  11668. static fromJSON( data ) {
  11669. return new CapsuleGeometry( data.radius, data.length, data.capSegments, data.radialSegments );
  11670. }
  11671. }
  11672. class CircleGeometry extends BufferGeometry {
  11673. constructor( radius = 1, segments = 32, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11674. super();
  11675. this.type = 'CircleGeometry';
  11676. this.parameters = {
  11677. radius: radius,
  11678. segments: segments,
  11679. thetaStart: thetaStart,
  11680. thetaLength: thetaLength
  11681. };
  11682. segments = Math.max( 3, segments );
  11683. // buffers
  11684. const indices = [];
  11685. const vertices = [];
  11686. const normals = [];
  11687. const uvs = [];
  11688. // helper variables
  11689. const vertex = new Vector3();
  11690. const uv = new Vector2();
  11691. // center point
  11692. vertices.push( 0, 0, 0 );
  11693. normals.push( 0, 0, 1 );
  11694. uvs.push( 0.5, 0.5 );
  11695. for ( let s = 0, i = 3; s <= segments; s ++, i += 3 ) {
  11696. const segment = thetaStart + s / segments * thetaLength;
  11697. // vertex
  11698. vertex.x = radius * Math.cos( segment );
  11699. vertex.y = radius * Math.sin( segment );
  11700. vertices.push( vertex.x, vertex.y, vertex.z );
  11701. // normal
  11702. normals.push( 0, 0, 1 );
  11703. // uvs
  11704. uv.x = ( vertices[ i ] / radius + 1 ) / 2;
  11705. uv.y = ( vertices[ i + 1 ] / radius + 1 ) / 2;
  11706. uvs.push( uv.x, uv.y );
  11707. }
  11708. // indices
  11709. for ( let i = 1; i <= segments; i ++ ) {
  11710. indices.push( i, i + 1, 0 );
  11711. }
  11712. // build geometry
  11713. this.setIndex( indices );
  11714. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11715. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11716. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11717. }
  11718. copy( source ) {
  11719. super.copy( source );
  11720. this.parameters = Object.assign( {}, source.parameters );
  11721. return this;
  11722. }
  11723. static fromJSON( data ) {
  11724. return new CircleGeometry( data.radius, data.segments, data.thetaStart, data.thetaLength );
  11725. }
  11726. }
  11727. class CylinderGeometry extends BufferGeometry {
  11728. constructor( radiusTop = 1, radiusBottom = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11729. super();
  11730. this.type = 'CylinderGeometry';
  11731. this.parameters = {
  11732. radiusTop: radiusTop,
  11733. radiusBottom: radiusBottom,
  11734. height: height,
  11735. radialSegments: radialSegments,
  11736. heightSegments: heightSegments,
  11737. openEnded: openEnded,
  11738. thetaStart: thetaStart,
  11739. thetaLength: thetaLength
  11740. };
  11741. const scope = this;
  11742. radialSegments = Math.floor( radialSegments );
  11743. heightSegments = Math.floor( heightSegments );
  11744. // buffers
  11745. const indices = [];
  11746. const vertices = [];
  11747. const normals = [];
  11748. const uvs = [];
  11749. // helper variables
  11750. let index = 0;
  11751. const indexArray = [];
  11752. const halfHeight = height / 2;
  11753. let groupStart = 0;
  11754. // generate geometry
  11755. generateTorso();
  11756. if ( openEnded === false ) {
  11757. if ( radiusTop > 0 ) generateCap( true );
  11758. if ( radiusBottom > 0 ) generateCap( false );
  11759. }
  11760. // build geometry
  11761. this.setIndex( indices );
  11762. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  11763. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  11764. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  11765. function generateTorso() {
  11766. const normal = new Vector3();
  11767. const vertex = new Vector3();
  11768. let groupCount = 0;
  11769. // this will be used to calculate the normal
  11770. const slope = ( radiusBottom - radiusTop ) / height;
  11771. // generate vertices, normals and uvs
  11772. for ( let y = 0; y <= heightSegments; y ++ ) {
  11773. const indexRow = [];
  11774. const v = y / heightSegments;
  11775. // calculate the radius of the current row
  11776. const radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  11777. for ( let x = 0; x <= radialSegments; x ++ ) {
  11778. const u = x / radialSegments;
  11779. const theta = u * thetaLength + thetaStart;
  11780. const sinTheta = Math.sin( theta );
  11781. const cosTheta = Math.cos( theta );
  11782. // vertex
  11783. vertex.x = radius * sinTheta;
  11784. vertex.y = - v * height + halfHeight;
  11785. vertex.z = radius * cosTheta;
  11786. vertices.push( vertex.x, vertex.y, vertex.z );
  11787. // normal
  11788. normal.set( sinTheta, slope, cosTheta ).normalize();
  11789. normals.push( normal.x, normal.y, normal.z );
  11790. // uv
  11791. uvs.push( u, 1 - v );
  11792. // save index of vertex in respective row
  11793. indexRow.push( index ++ );
  11794. }
  11795. // now save vertices of the row in our index array
  11796. indexArray.push( indexRow );
  11797. }
  11798. // generate indices
  11799. for ( let x = 0; x < radialSegments; x ++ ) {
  11800. for ( let y = 0; y < heightSegments; y ++ ) {
  11801. // we use the index array to access the correct indices
  11802. const a = indexArray[ y ][ x ];
  11803. const b = indexArray[ y + 1 ][ x ];
  11804. const c = indexArray[ y + 1 ][ x + 1 ];
  11805. const d = indexArray[ y ][ x + 1 ];
  11806. // faces
  11807. if ( radiusTop > 0 || y !== 0 ) {
  11808. indices.push( a, b, d );
  11809. groupCount += 3;
  11810. }
  11811. if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
  11812. indices.push( b, c, d );
  11813. groupCount += 3;
  11814. }
  11815. }
  11816. }
  11817. // add a group to the geometry. this will ensure multi material support
  11818. scope.addGroup( groupStart, groupCount, 0 );
  11819. // calculate new start value for groups
  11820. groupStart += groupCount;
  11821. }
  11822. function generateCap( top ) {
  11823. // save the index of the first center vertex
  11824. const centerIndexStart = index;
  11825. const uv = new Vector2();
  11826. const vertex = new Vector3();
  11827. let groupCount = 0;
  11828. const radius = ( top === true ) ? radiusTop : radiusBottom;
  11829. const sign = ( top === true ) ? 1 : - 1;
  11830. // first we generate the center vertex data of the cap.
  11831. // because the geometry needs one set of uvs per face,
  11832. // we must generate a center vertex per face/segment
  11833. for ( let x = 1; x <= radialSegments; x ++ ) {
  11834. // vertex
  11835. vertices.push( 0, halfHeight * sign, 0 );
  11836. // normal
  11837. normals.push( 0, sign, 0 );
  11838. // uv
  11839. uvs.push( 0.5, 0.5 );
  11840. // increase index
  11841. index ++;
  11842. }
  11843. // save the index of the last center vertex
  11844. const centerIndexEnd = index;
  11845. // now we generate the surrounding vertices, normals and uvs
  11846. for ( let x = 0; x <= radialSegments; x ++ ) {
  11847. const u = x / radialSegments;
  11848. const theta = u * thetaLength + thetaStart;
  11849. const cosTheta = Math.cos( theta );
  11850. const sinTheta = Math.sin( theta );
  11851. // vertex
  11852. vertex.x = radius * sinTheta;
  11853. vertex.y = halfHeight * sign;
  11854. vertex.z = radius * cosTheta;
  11855. vertices.push( vertex.x, vertex.y, vertex.z );
  11856. // normal
  11857. normals.push( 0, sign, 0 );
  11858. // uv
  11859. uv.x = ( cosTheta * 0.5 ) + 0.5;
  11860. uv.y = ( sinTheta * 0.5 * sign ) + 0.5;
  11861. uvs.push( uv.x, uv.y );
  11862. // increase index
  11863. index ++;
  11864. }
  11865. // generate indices
  11866. for ( let x = 0; x < radialSegments; x ++ ) {
  11867. const c = centerIndexStart + x;
  11868. const i = centerIndexEnd + x;
  11869. if ( top === true ) {
  11870. // face top
  11871. indices.push( i, i + 1, c );
  11872. } else {
  11873. // face bottom
  11874. indices.push( i + 1, i, c );
  11875. }
  11876. groupCount += 3;
  11877. }
  11878. // add a group to the geometry. this will ensure multi material support
  11879. scope.addGroup( groupStart, groupCount, top === true ? 1 : 2 );
  11880. // calculate new start value for groups
  11881. groupStart += groupCount;
  11882. }
  11883. }
  11884. copy( source ) {
  11885. super.copy( source );
  11886. this.parameters = Object.assign( {}, source.parameters );
  11887. return this;
  11888. }
  11889. static fromJSON( data ) {
  11890. return new CylinderGeometry( data.radiusTop, data.radiusBottom, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11891. }
  11892. }
  11893. class ConeGeometry extends CylinderGeometry {
  11894. constructor( radius = 1, height = 1, radialSegments = 32, heightSegments = 1, openEnded = false, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  11895. super( 0, radius, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength );
  11896. this.type = 'ConeGeometry';
  11897. this.parameters = {
  11898. radius: radius,
  11899. height: height,
  11900. radialSegments: radialSegments,
  11901. heightSegments: heightSegments,
  11902. openEnded: openEnded,
  11903. thetaStart: thetaStart,
  11904. thetaLength: thetaLength
  11905. };
  11906. }
  11907. static fromJSON( data ) {
  11908. return new ConeGeometry( data.radius, data.height, data.radialSegments, data.heightSegments, data.openEnded, data.thetaStart, data.thetaLength );
  11909. }
  11910. }
  11911. class PolyhedronGeometry extends BufferGeometry {
  11912. constructor( vertices = [], indices = [], radius = 1, detail = 0 ) {
  11913. super();
  11914. this.type = 'PolyhedronGeometry';
  11915. this.parameters = {
  11916. vertices: vertices,
  11917. indices: indices,
  11918. radius: radius,
  11919. detail: detail
  11920. };
  11921. // default buffer data
  11922. const vertexBuffer = [];
  11923. const uvBuffer = [];
  11924. // the subdivision creates the vertex buffer data
  11925. subdivide( detail );
  11926. // all vertices should lie on a conceptual sphere with a given radius
  11927. applyRadius( radius );
  11928. // finally, create the uv data
  11929. generateUVs();
  11930. // build non-indexed geometry
  11931. this.setAttribute( 'position', new Float32BufferAttribute( vertexBuffer, 3 ) );
  11932. this.setAttribute( 'normal', new Float32BufferAttribute( vertexBuffer.slice(), 3 ) );
  11933. this.setAttribute( 'uv', new Float32BufferAttribute( uvBuffer, 2 ) );
  11934. if ( detail === 0 ) {
  11935. this.computeVertexNormals(); // flat normals
  11936. } else {
  11937. this.normalizeNormals(); // smooth normals
  11938. }
  11939. // helper functions
  11940. function subdivide( detail ) {
  11941. const a = new Vector3();
  11942. const b = new Vector3();
  11943. const c = new Vector3();
  11944. // iterate over all faces and apply a subdivision with the given detail value
  11945. for ( let i = 0; i < indices.length; i += 3 ) {
  11946. // get the vertices of the face
  11947. getVertexByIndex( indices[ i + 0 ], a );
  11948. getVertexByIndex( indices[ i + 1 ], b );
  11949. getVertexByIndex( indices[ i + 2 ], c );
  11950. // perform subdivision
  11951. subdivideFace( a, b, c, detail );
  11952. }
  11953. }
  11954. function subdivideFace( a, b, c, detail ) {
  11955. const cols = detail + 1;
  11956. // we use this multidimensional array as a data structure for creating the subdivision
  11957. const v = [];
  11958. // construct all of the vertices for this subdivision
  11959. for ( let i = 0; i <= cols; i ++ ) {
  11960. v[ i ] = [];
  11961. const aj = a.clone().lerp( c, i / cols );
  11962. const bj = b.clone().lerp( c, i / cols );
  11963. const rows = cols - i;
  11964. for ( let j = 0; j <= rows; j ++ ) {
  11965. if ( j === 0 && i === cols ) {
  11966. v[ i ][ j ] = aj;
  11967. } else {
  11968. v[ i ][ j ] = aj.clone().lerp( bj, j / rows );
  11969. }
  11970. }
  11971. }
  11972. // construct all of the faces
  11973. for ( let i = 0; i < cols; i ++ ) {
  11974. for ( let j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  11975. const k = Math.floor( j / 2 );
  11976. if ( j % 2 === 0 ) {
  11977. pushVertex( v[ i ][ k + 1 ] );
  11978. pushVertex( v[ i + 1 ][ k ] );
  11979. pushVertex( v[ i ][ k ] );
  11980. } else {
  11981. pushVertex( v[ i ][ k + 1 ] );
  11982. pushVertex( v[ i + 1 ][ k + 1 ] );
  11983. pushVertex( v[ i + 1 ][ k ] );
  11984. }
  11985. }
  11986. }
  11987. }
  11988. function applyRadius( radius ) {
  11989. const vertex = new Vector3();
  11990. // iterate over the entire buffer and apply the radius to each vertex
  11991. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  11992. vertex.x = vertexBuffer[ i + 0 ];
  11993. vertex.y = vertexBuffer[ i + 1 ];
  11994. vertex.z = vertexBuffer[ i + 2 ];
  11995. vertex.normalize().multiplyScalar( radius );
  11996. vertexBuffer[ i + 0 ] = vertex.x;
  11997. vertexBuffer[ i + 1 ] = vertex.y;
  11998. vertexBuffer[ i + 2 ] = vertex.z;
  11999. }
  12000. }
  12001. function generateUVs() {
  12002. const vertex = new Vector3();
  12003. for ( let i = 0; i < vertexBuffer.length; i += 3 ) {
  12004. vertex.x = vertexBuffer[ i + 0 ];
  12005. vertex.y = vertexBuffer[ i + 1 ];
  12006. vertex.z = vertexBuffer[ i + 2 ];
  12007. const u = azimuth( vertex ) / 2 / Math.PI + 0.5;
  12008. const v = inclination( vertex ) / Math.PI + 0.5;
  12009. uvBuffer.push( u, 1 - v );
  12010. }
  12011. correctUVs();
  12012. correctSeam();
  12013. }
  12014. function correctSeam() {
  12015. // handle case when face straddles the seam, see #3269
  12016. for ( let i = 0; i < uvBuffer.length; i += 6 ) {
  12017. // uv data of a single face
  12018. const x0 = uvBuffer[ i + 0 ];
  12019. const x1 = uvBuffer[ i + 2 ];
  12020. const x2 = uvBuffer[ i + 4 ];
  12021. const max = Math.max( x0, x1, x2 );
  12022. const min = Math.min( x0, x1, x2 );
  12023. // 0.9 is somewhat arbitrary
  12024. if ( max > 0.9 && min < 0.1 ) {
  12025. if ( x0 < 0.2 ) uvBuffer[ i + 0 ] += 1;
  12026. if ( x1 < 0.2 ) uvBuffer[ i + 2 ] += 1;
  12027. if ( x2 < 0.2 ) uvBuffer[ i + 4 ] += 1;
  12028. }
  12029. }
  12030. }
  12031. function pushVertex( vertex ) {
  12032. vertexBuffer.push( vertex.x, vertex.y, vertex.z );
  12033. }
  12034. function getVertexByIndex( index, vertex ) {
  12035. const stride = index * 3;
  12036. vertex.x = vertices[ stride + 0 ];
  12037. vertex.y = vertices[ stride + 1 ];
  12038. vertex.z = vertices[ stride + 2 ];
  12039. }
  12040. function correctUVs() {
  12041. const a = new Vector3();
  12042. const b = new Vector3();
  12043. const c = new Vector3();
  12044. const centroid = new Vector3();
  12045. const uvA = new Vector2();
  12046. const uvB = new Vector2();
  12047. const uvC = new Vector2();
  12048. for ( let i = 0, j = 0; i < vertexBuffer.length; i += 9, j += 6 ) {
  12049. a.set( vertexBuffer[ i + 0 ], vertexBuffer[ i + 1 ], vertexBuffer[ i + 2 ] );
  12050. b.set( vertexBuffer[ i + 3 ], vertexBuffer[ i + 4 ], vertexBuffer[ i + 5 ] );
  12051. c.set( vertexBuffer[ i + 6 ], vertexBuffer[ i + 7 ], vertexBuffer[ i + 8 ] );
  12052. uvA.set( uvBuffer[ j + 0 ], uvBuffer[ j + 1 ] );
  12053. uvB.set( uvBuffer[ j + 2 ], uvBuffer[ j + 3 ] );
  12054. uvC.set( uvBuffer[ j + 4 ], uvBuffer[ j + 5 ] );
  12055. centroid.copy( a ).add( b ).add( c ).divideScalar( 3 );
  12056. const azi = azimuth( centroid );
  12057. correctUV( uvA, j + 0, a, azi );
  12058. correctUV( uvB, j + 2, b, azi );
  12059. correctUV( uvC, j + 4, c, azi );
  12060. }
  12061. }
  12062. function correctUV( uv, stride, vector, azimuth ) {
  12063. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) {
  12064. uvBuffer[ stride ] = uv.x - 1;
  12065. }
  12066. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) {
  12067. uvBuffer[ stride ] = azimuth / 2 / Math.PI + 0.5;
  12068. }
  12069. }
  12070. // Angle around the Y axis, counter-clockwise when looking from above.
  12071. function azimuth( vector ) {
  12072. return Math.atan2( vector.z, - vector.x );
  12073. }
  12074. // Angle above the XZ plane.
  12075. function inclination( vector ) {
  12076. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  12077. }
  12078. }
  12079. copy( source ) {
  12080. super.copy( source );
  12081. this.parameters = Object.assign( {}, source.parameters );
  12082. return this;
  12083. }
  12084. static fromJSON( data ) {
  12085. return new PolyhedronGeometry( data.vertices, data.indices, data.radius, data.details );
  12086. }
  12087. }
  12088. class DodecahedronGeometry extends PolyhedronGeometry {
  12089. constructor( radius = 1, detail = 0 ) {
  12090. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  12091. const r = 1 / t;
  12092. const vertices = [
  12093. // (±1, ±1, ±1)
  12094. - 1, - 1, - 1, - 1, - 1, 1,
  12095. - 1, 1, - 1, - 1, 1, 1,
  12096. 1, - 1, - 1, 1, - 1, 1,
  12097. 1, 1, - 1, 1, 1, 1,
  12098. // (0, ±1/φ, ±φ)
  12099. 0, - r, - t, 0, - r, t,
  12100. 0, r, - t, 0, r, t,
  12101. // (±1/φ, ±φ, 0)
  12102. - r, - t, 0, - r, t, 0,
  12103. r, - t, 0, r, t, 0,
  12104. // (±φ, 0, ±1/φ)
  12105. - t, 0, - r, t, 0, - r,
  12106. - t, 0, r, t, 0, r
  12107. ];
  12108. const indices = [
  12109. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  12110. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  12111. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  12112. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  12113. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  12114. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  12115. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  12116. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  12117. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  12118. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  12119. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  12120. 1, 12, 14, 1, 14, 5, 1, 5, 9
  12121. ];
  12122. super( vertices, indices, radius, detail );
  12123. this.type = 'DodecahedronGeometry';
  12124. this.parameters = {
  12125. radius: radius,
  12126. detail: detail
  12127. };
  12128. }
  12129. static fromJSON( data ) {
  12130. return new DodecahedronGeometry( data.radius, data.detail );
  12131. }
  12132. }
  12133. const _v0 = /*@__PURE__*/ new Vector3();
  12134. const _v1$1 = /*@__PURE__*/ new Vector3();
  12135. const _normal = /*@__PURE__*/ new Vector3();
  12136. const _triangle = /*@__PURE__*/ new Triangle();
  12137. class EdgesGeometry extends BufferGeometry {
  12138. constructor( geometry = null, thresholdAngle = 1 ) {
  12139. super();
  12140. this.type = 'EdgesGeometry';
  12141. this.parameters = {
  12142. geometry: geometry,
  12143. thresholdAngle: thresholdAngle
  12144. };
  12145. if ( geometry !== null ) {
  12146. const precisionPoints = 4;
  12147. const precision = Math.pow( 10, precisionPoints );
  12148. const thresholdDot = Math.cos( DEG2RAD * thresholdAngle );
  12149. const indexAttr = geometry.getIndex();
  12150. const positionAttr = geometry.getAttribute( 'position' );
  12151. const indexCount = indexAttr ? indexAttr.count : positionAttr.count;
  12152. const indexArr = [ 0, 0, 0 ];
  12153. const vertKeys = [ 'a', 'b', 'c' ];
  12154. const hashes = new Array( 3 );
  12155. const edgeData = {};
  12156. const vertices = [];
  12157. for ( let i = 0; i < indexCount; i += 3 ) {
  12158. if ( indexAttr ) {
  12159. indexArr[ 0 ] = indexAttr.getX( i );
  12160. indexArr[ 1 ] = indexAttr.getX( i + 1 );
  12161. indexArr[ 2 ] = indexAttr.getX( i + 2 );
  12162. } else {
  12163. indexArr[ 0 ] = i;
  12164. indexArr[ 1 ] = i + 1;
  12165. indexArr[ 2 ] = i + 2;
  12166. }
  12167. const { a, b, c } = _triangle;
  12168. a.fromBufferAttribute( positionAttr, indexArr[ 0 ] );
  12169. b.fromBufferAttribute( positionAttr, indexArr[ 1 ] );
  12170. c.fromBufferAttribute( positionAttr, indexArr[ 2 ] );
  12171. _triangle.getNormal( _normal );
  12172. // create hashes for the edge from the vertices
  12173. hashes[ 0 ] = `${ Math.round( a.x * precision ) },${ Math.round( a.y * precision ) },${ Math.round( a.z * precision ) }`;
  12174. hashes[ 1 ] = `${ Math.round( b.x * precision ) },${ Math.round( b.y * precision ) },${ Math.round( b.z * precision ) }`;
  12175. hashes[ 2 ] = `${ Math.round( c.x * precision ) },${ Math.round( c.y * precision ) },${ Math.round( c.z * precision ) }`;
  12176. // skip degenerate triangles
  12177. if ( hashes[ 0 ] === hashes[ 1 ] || hashes[ 1 ] === hashes[ 2 ] || hashes[ 2 ] === hashes[ 0 ] ) {
  12178. continue;
  12179. }
  12180. // iterate over every edge
  12181. for ( let j = 0; j < 3; j ++ ) {
  12182. // get the first and next vertex making up the edge
  12183. const jNext = ( j + 1 ) % 3;
  12184. const vecHash0 = hashes[ j ];
  12185. const vecHash1 = hashes[ jNext ];
  12186. const v0 = _triangle[ vertKeys[ j ] ];
  12187. const v1 = _triangle[ vertKeys[ jNext ] ];
  12188. const hash = `${ vecHash0 }_${ vecHash1 }`;
  12189. const reverseHash = `${ vecHash1 }_${ vecHash0 }`;
  12190. if ( reverseHash in edgeData && edgeData[ reverseHash ] ) {
  12191. // if we found a sibling edge add it into the vertex array if
  12192. // it meets the angle threshold and delete the edge from the map.
  12193. if ( _normal.dot( edgeData[ reverseHash ].normal ) <= thresholdDot ) {
  12194. vertices.push( v0.x, v0.y, v0.z );
  12195. vertices.push( v1.x, v1.y, v1.z );
  12196. }
  12197. edgeData[ reverseHash ] = null;
  12198. } else if ( ! ( hash in edgeData ) ) {
  12199. // if we've already got an edge here then skip adding a new one
  12200. edgeData[ hash ] = {
  12201. index0: indexArr[ j ],
  12202. index1: indexArr[ jNext ],
  12203. normal: _normal.clone(),
  12204. };
  12205. }
  12206. }
  12207. }
  12208. // iterate over all remaining, unmatched edges and add them to the vertex array
  12209. for ( const key in edgeData ) {
  12210. if ( edgeData[ key ] ) {
  12211. const { index0, index1 } = edgeData[ key ];
  12212. _v0.fromBufferAttribute( positionAttr, index0 );
  12213. _v1$1.fromBufferAttribute( positionAttr, index1 );
  12214. vertices.push( _v0.x, _v0.y, _v0.z );
  12215. vertices.push( _v1$1.x, _v1$1.y, _v1$1.z );
  12216. }
  12217. }
  12218. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  12219. }
  12220. }
  12221. copy( source ) {
  12222. super.copy( source );
  12223. this.parameters = Object.assign( {}, source.parameters );
  12224. return this;
  12225. }
  12226. }
  12227. class Shape extends Path {
  12228. constructor( points ) {
  12229. super( points );
  12230. this.uuid = generateUUID();
  12231. this.type = 'Shape';
  12232. this.holes = [];
  12233. }
  12234. getPointsHoles( divisions ) {
  12235. const holesPts = [];
  12236. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12237. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  12238. }
  12239. return holesPts;
  12240. }
  12241. // get points of shape and holes (keypoints based on segments parameter)
  12242. extractPoints( divisions ) {
  12243. return {
  12244. shape: this.getPoints( divisions ),
  12245. holes: this.getPointsHoles( divisions )
  12246. };
  12247. }
  12248. copy( source ) {
  12249. super.copy( source );
  12250. this.holes = [];
  12251. for ( let i = 0, l = source.holes.length; i < l; i ++ ) {
  12252. const hole = source.holes[ i ];
  12253. this.holes.push( hole.clone() );
  12254. }
  12255. return this;
  12256. }
  12257. toJSON() {
  12258. const data = super.toJSON();
  12259. data.uuid = this.uuid;
  12260. data.holes = [];
  12261. for ( let i = 0, l = this.holes.length; i < l; i ++ ) {
  12262. const hole = this.holes[ i ];
  12263. data.holes.push( hole.toJSON() );
  12264. }
  12265. return data;
  12266. }
  12267. fromJSON( json ) {
  12268. super.fromJSON( json );
  12269. this.uuid = json.uuid;
  12270. this.holes = [];
  12271. for ( let i = 0, l = json.holes.length; i < l; i ++ ) {
  12272. const hole = json.holes[ i ];
  12273. this.holes.push( new Path().fromJSON( hole ) );
  12274. }
  12275. return this;
  12276. }
  12277. }
  12278. /**
  12279. * Port from https://github.com/mapbox/earcut (v2.2.4)
  12280. */
  12281. const Earcut = {
  12282. triangulate: function ( data, holeIndices, dim = 2 ) {
  12283. const hasHoles = holeIndices && holeIndices.length;
  12284. const outerLen = hasHoles ? holeIndices[ 0 ] * dim : data.length;
  12285. let outerNode = linkedList( data, 0, outerLen, dim, true );
  12286. const triangles = [];
  12287. if ( ! outerNode || outerNode.next === outerNode.prev ) return triangles;
  12288. let minX, minY, maxX, maxY, x, y, invSize;
  12289. if ( hasHoles ) outerNode = eliminateHoles( data, holeIndices, outerNode, dim );
  12290. // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
  12291. if ( data.length > 80 * dim ) {
  12292. minX = maxX = data[ 0 ];
  12293. minY = maxY = data[ 1 ];
  12294. for ( let i = dim; i < outerLen; i += dim ) {
  12295. x = data[ i ];
  12296. y = data[ i + 1 ];
  12297. if ( x < minX ) minX = x;
  12298. if ( y < minY ) minY = y;
  12299. if ( x > maxX ) maxX = x;
  12300. if ( y > maxY ) maxY = y;
  12301. }
  12302. // minX, minY and invSize are later used to transform coords into integers for z-order calculation
  12303. invSize = Math.max( maxX - minX, maxY - minY );
  12304. invSize = invSize !== 0 ? 32767 / invSize : 0;
  12305. }
  12306. earcutLinked( outerNode, triangles, dim, minX, minY, invSize, 0 );
  12307. return triangles;
  12308. }
  12309. };
  12310. // create a circular doubly linked list from polygon points in the specified winding order
  12311. function linkedList( data, start, end, dim, clockwise ) {
  12312. let i, last;
  12313. if ( clockwise === ( signedArea( data, start, end, dim ) > 0 ) ) {
  12314. for ( i = start; i < end; i += dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12315. } else {
  12316. for ( i = end - dim; i >= start; i -= dim ) last = insertNode( i, data[ i ], data[ i + 1 ], last );
  12317. }
  12318. if ( last && equals( last, last.next ) ) {
  12319. removeNode( last );
  12320. last = last.next;
  12321. }
  12322. return last;
  12323. }
  12324. // eliminate colinear or duplicate points
  12325. function filterPoints( start, end ) {
  12326. if ( ! start ) return start;
  12327. if ( ! end ) end = start;
  12328. let p = start,
  12329. again;
  12330. do {
  12331. again = false;
  12332. if ( ! p.steiner && ( equals( p, p.next ) || area( p.prev, p, p.next ) === 0 ) ) {
  12333. removeNode( p );
  12334. p = end = p.prev;
  12335. if ( p === p.next ) break;
  12336. again = true;
  12337. } else {
  12338. p = p.next;
  12339. }
  12340. } while ( again || p !== end );
  12341. return end;
  12342. }
  12343. // main ear slicing loop which triangulates a polygon (given as a linked list)
  12344. function earcutLinked( ear, triangles, dim, minX, minY, invSize, pass ) {
  12345. if ( ! ear ) return;
  12346. // interlink polygon nodes in z-order
  12347. if ( ! pass && invSize ) indexCurve( ear, minX, minY, invSize );
  12348. let stop = ear,
  12349. prev, next;
  12350. // iterate through ears, slicing them one by one
  12351. while ( ear.prev !== ear.next ) {
  12352. prev = ear.prev;
  12353. next = ear.next;
  12354. if ( invSize ? isEarHashed( ear, minX, minY, invSize ) : isEar( ear ) ) {
  12355. // cut off the triangle
  12356. triangles.push( prev.i / dim | 0 );
  12357. triangles.push( ear.i / dim | 0 );
  12358. triangles.push( next.i / dim | 0 );
  12359. removeNode( ear );
  12360. // skipping the next vertex leads to less sliver triangles
  12361. ear = next.next;
  12362. stop = next.next;
  12363. continue;
  12364. }
  12365. ear = next;
  12366. // if we looped through the whole remaining polygon and can't find any more ears
  12367. if ( ear === stop ) {
  12368. // try filtering points and slicing again
  12369. if ( ! pass ) {
  12370. earcutLinked( filterPoints( ear ), triangles, dim, minX, minY, invSize, 1 );
  12371. // if this didn't work, try curing all small self-intersections locally
  12372. } else if ( pass === 1 ) {
  12373. ear = cureLocalIntersections( filterPoints( ear ), triangles, dim );
  12374. earcutLinked( ear, triangles, dim, minX, minY, invSize, 2 );
  12375. // as a last resort, try splitting the remaining polygon into two
  12376. } else if ( pass === 2 ) {
  12377. splitEarcut( ear, triangles, dim, minX, minY, invSize );
  12378. }
  12379. break;
  12380. }
  12381. }
  12382. }
  12383. // check whether a polygon node forms a valid ear with adjacent nodes
  12384. function isEar( ear ) {
  12385. const a = ear.prev,
  12386. b = ear,
  12387. c = ear.next;
  12388. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12389. // now make sure we don't have other points inside the potential ear
  12390. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12391. // triangle bbox; min & max are calculated like this for speed
  12392. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12393. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12394. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12395. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12396. let p = c.next;
  12397. while ( p !== a ) {
  12398. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 &&
  12399. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) &&
  12400. area( p.prev, p, p.next ) >= 0 ) return false;
  12401. p = p.next;
  12402. }
  12403. return true;
  12404. }
  12405. function isEarHashed( ear, minX, minY, invSize ) {
  12406. const a = ear.prev,
  12407. b = ear,
  12408. c = ear.next;
  12409. if ( area( a, b, c ) >= 0 ) return false; // reflex, can't be an ear
  12410. const ax = a.x, bx = b.x, cx = c.x, ay = a.y, by = b.y, cy = c.y;
  12411. // triangle bbox; min & max are calculated like this for speed
  12412. const x0 = ax < bx ? ( ax < cx ? ax : cx ) : ( bx < cx ? bx : cx ),
  12413. y0 = ay < by ? ( ay < cy ? ay : cy ) : ( by < cy ? by : cy ),
  12414. x1 = ax > bx ? ( ax > cx ? ax : cx ) : ( bx > cx ? bx : cx ),
  12415. y1 = ay > by ? ( ay > cy ? ay : cy ) : ( by > cy ? by : cy );
  12416. // z-order range for the current triangle bbox;
  12417. const minZ = zOrder( x0, y0, minX, minY, invSize ),
  12418. maxZ = zOrder( x1, y1, minX, minY, invSize );
  12419. let p = ear.prevZ,
  12420. n = ear.nextZ;
  12421. // look for points inside the triangle in both directions
  12422. while ( p && p.z >= minZ && n && n.z <= maxZ ) {
  12423. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12424. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12425. p = p.prevZ;
  12426. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12427. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12428. n = n.nextZ;
  12429. }
  12430. // look for remaining points in decreasing z-order
  12431. while ( p && p.z >= minZ ) {
  12432. if ( p.x >= x0 && p.x <= x1 && p.y >= y0 && p.y <= y1 && p !== a && p !== c &&
  12433. pointInTriangle( ax, ay, bx, by, cx, cy, p.x, p.y ) && area( p.prev, p, p.next ) >= 0 ) return false;
  12434. p = p.prevZ;
  12435. }
  12436. // look for remaining points in increasing z-order
  12437. while ( n && n.z <= maxZ ) {
  12438. if ( n.x >= x0 && n.x <= x1 && n.y >= y0 && n.y <= y1 && n !== a && n !== c &&
  12439. pointInTriangle( ax, ay, bx, by, cx, cy, n.x, n.y ) && area( n.prev, n, n.next ) >= 0 ) return false;
  12440. n = n.nextZ;
  12441. }
  12442. return true;
  12443. }
  12444. // go through all polygon nodes and cure small local self-intersections
  12445. function cureLocalIntersections( start, triangles, dim ) {
  12446. let p = start;
  12447. do {
  12448. const a = p.prev,
  12449. b = p.next.next;
  12450. if ( ! equals( a, b ) && intersects( a, p, p.next, b ) && locallyInside( a, b ) && locallyInside( b, a ) ) {
  12451. triangles.push( a.i / dim | 0 );
  12452. triangles.push( p.i / dim | 0 );
  12453. triangles.push( b.i / dim | 0 );
  12454. // remove two nodes involved
  12455. removeNode( p );
  12456. removeNode( p.next );
  12457. p = start = b;
  12458. }
  12459. p = p.next;
  12460. } while ( p !== start );
  12461. return filterPoints( p );
  12462. }
  12463. // try splitting polygon into two and triangulate them independently
  12464. function splitEarcut( start, triangles, dim, minX, minY, invSize ) {
  12465. // look for a valid diagonal that divides the polygon into two
  12466. let a = start;
  12467. do {
  12468. let b = a.next.next;
  12469. while ( b !== a.prev ) {
  12470. if ( a.i !== b.i && isValidDiagonal( a, b ) ) {
  12471. // split the polygon in two by the diagonal
  12472. let c = splitPolygon( a, b );
  12473. // filter colinear points around the cuts
  12474. a = filterPoints( a, a.next );
  12475. c = filterPoints( c, c.next );
  12476. // run earcut on each half
  12477. earcutLinked( a, triangles, dim, minX, minY, invSize, 0 );
  12478. earcutLinked( c, triangles, dim, minX, minY, invSize, 0 );
  12479. return;
  12480. }
  12481. b = b.next;
  12482. }
  12483. a = a.next;
  12484. } while ( a !== start );
  12485. }
  12486. // link every hole into the outer loop, producing a single-ring polygon without holes
  12487. function eliminateHoles( data, holeIndices, outerNode, dim ) {
  12488. const queue = [];
  12489. let i, len, start, end, list;
  12490. for ( i = 0, len = holeIndices.length; i < len; i ++ ) {
  12491. start = holeIndices[ i ] * dim;
  12492. end = i < len - 1 ? holeIndices[ i + 1 ] * dim : data.length;
  12493. list = linkedList( data, start, end, dim, false );
  12494. if ( list === list.next ) list.steiner = true;
  12495. queue.push( getLeftmost( list ) );
  12496. }
  12497. queue.sort( compareX );
  12498. // process holes from left to right
  12499. for ( i = 0; i < queue.length; i ++ ) {
  12500. outerNode = eliminateHole( queue[ i ], outerNode );
  12501. }
  12502. return outerNode;
  12503. }
  12504. function compareX( a, b ) {
  12505. return a.x - b.x;
  12506. }
  12507. // find a bridge between vertices that connects hole with an outer ring and link it
  12508. function eliminateHole( hole, outerNode ) {
  12509. const bridge = findHoleBridge( hole, outerNode );
  12510. if ( ! bridge ) {
  12511. return outerNode;
  12512. }
  12513. const bridgeReverse = splitPolygon( bridge, hole );
  12514. // filter collinear points around the cuts
  12515. filterPoints( bridgeReverse, bridgeReverse.next );
  12516. return filterPoints( bridge, bridge.next );
  12517. }
  12518. // David Eberly's algorithm for finding a bridge between hole and outer polygon
  12519. function findHoleBridge( hole, outerNode ) {
  12520. let p = outerNode,
  12521. qx = - Infinity,
  12522. m;
  12523. const hx = hole.x, hy = hole.y;
  12524. // find a segment intersected by a ray from the hole's leftmost point to the left;
  12525. // segment's endpoint with lesser x will be potential connection point
  12526. do {
  12527. if ( hy <= p.y && hy >= p.next.y && p.next.y !== p.y ) {
  12528. const x = p.x + ( hy - p.y ) * ( p.next.x - p.x ) / ( p.next.y - p.y );
  12529. if ( x <= hx && x > qx ) {
  12530. qx = x;
  12531. m = p.x < p.next.x ? p : p.next;
  12532. if ( x === hx ) return m; // hole touches outer segment; pick leftmost endpoint
  12533. }
  12534. }
  12535. p = p.next;
  12536. } while ( p !== outerNode );
  12537. if ( ! m ) return null;
  12538. // look for points inside the triangle of hole point, segment intersection and endpoint;
  12539. // if there are no points found, we have a valid connection;
  12540. // otherwise choose the point of the minimum angle with the ray as connection point
  12541. const stop = m,
  12542. mx = m.x,
  12543. my = m.y;
  12544. let tanMin = Infinity, tan;
  12545. p = m;
  12546. do {
  12547. if ( hx >= p.x && p.x >= mx && hx !== p.x &&
  12548. pointInTriangle( hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y ) ) {
  12549. tan = Math.abs( hy - p.y ) / ( hx - p.x ); // tangential
  12550. if ( locallyInside( p, hole ) && ( tan < tanMin || ( tan === tanMin && ( p.x > m.x || ( p.x === m.x && sectorContainsSector( m, p ) ) ) ) ) ) {
  12551. m = p;
  12552. tanMin = tan;
  12553. }
  12554. }
  12555. p = p.next;
  12556. } while ( p !== stop );
  12557. return m;
  12558. }
  12559. // whether sector in vertex m contains sector in vertex p in the same coordinates
  12560. function sectorContainsSector( m, p ) {
  12561. return area( m.prev, m, p.prev ) < 0 && area( p.next, m, m.next ) < 0;
  12562. }
  12563. // interlink polygon nodes in z-order
  12564. function indexCurve( start, minX, minY, invSize ) {
  12565. let p = start;
  12566. do {
  12567. if ( p.z === 0 ) p.z = zOrder( p.x, p.y, minX, minY, invSize );
  12568. p.prevZ = p.prev;
  12569. p.nextZ = p.next;
  12570. p = p.next;
  12571. } while ( p !== start );
  12572. p.prevZ.nextZ = null;
  12573. p.prevZ = null;
  12574. sortLinked( p );
  12575. }
  12576. // Simon Tatham's linked list merge sort algorithm
  12577. // http://www.chiark.greenend.org.uk/~sgtatham/algorithms/listsort.html
  12578. function sortLinked( list ) {
  12579. let i, p, q, e, tail, numMerges, pSize, qSize,
  12580. inSize = 1;
  12581. do {
  12582. p = list;
  12583. list = null;
  12584. tail = null;
  12585. numMerges = 0;
  12586. while ( p ) {
  12587. numMerges ++;
  12588. q = p;
  12589. pSize = 0;
  12590. for ( i = 0; i < inSize; i ++ ) {
  12591. pSize ++;
  12592. q = q.nextZ;
  12593. if ( ! q ) break;
  12594. }
  12595. qSize = inSize;
  12596. while ( pSize > 0 || ( qSize > 0 && q ) ) {
  12597. if ( pSize !== 0 && ( qSize === 0 || ! q || p.z <= q.z ) ) {
  12598. e = p;
  12599. p = p.nextZ;
  12600. pSize --;
  12601. } else {
  12602. e = q;
  12603. q = q.nextZ;
  12604. qSize --;
  12605. }
  12606. if ( tail ) tail.nextZ = e;
  12607. else list = e;
  12608. e.prevZ = tail;
  12609. tail = e;
  12610. }
  12611. p = q;
  12612. }
  12613. tail.nextZ = null;
  12614. inSize *= 2;
  12615. } while ( numMerges > 1 );
  12616. return list;
  12617. }
  12618. // z-order of a point given coords and inverse of the longer side of data bbox
  12619. function zOrder( x, y, minX, minY, invSize ) {
  12620. // coords are transformed into non-negative 15-bit integer range
  12621. x = ( x - minX ) * invSize | 0;
  12622. y = ( y - minY ) * invSize | 0;
  12623. x = ( x | ( x << 8 ) ) & 0x00FF00FF;
  12624. x = ( x | ( x << 4 ) ) & 0x0F0F0F0F;
  12625. x = ( x | ( x << 2 ) ) & 0x33333333;
  12626. x = ( x | ( x << 1 ) ) & 0x55555555;
  12627. y = ( y | ( y << 8 ) ) & 0x00FF00FF;
  12628. y = ( y | ( y << 4 ) ) & 0x0F0F0F0F;
  12629. y = ( y | ( y << 2 ) ) & 0x33333333;
  12630. y = ( y | ( y << 1 ) ) & 0x55555555;
  12631. return x | ( y << 1 );
  12632. }
  12633. // find the leftmost node of a polygon ring
  12634. function getLeftmost( start ) {
  12635. let p = start,
  12636. leftmost = start;
  12637. do {
  12638. if ( p.x < leftmost.x || ( p.x === leftmost.x && p.y < leftmost.y ) ) leftmost = p;
  12639. p = p.next;
  12640. } while ( p !== start );
  12641. return leftmost;
  12642. }
  12643. // check if a point lies within a convex triangle
  12644. function pointInTriangle( ax, ay, bx, by, cx, cy, px, py ) {
  12645. return ( cx - px ) * ( ay - py ) >= ( ax - px ) * ( cy - py ) &&
  12646. ( ax - px ) * ( by - py ) >= ( bx - px ) * ( ay - py ) &&
  12647. ( bx - px ) * ( cy - py ) >= ( cx - px ) * ( by - py );
  12648. }
  12649. // check if a diagonal between two polygon nodes is valid (lies in polygon interior)
  12650. function isValidDiagonal( a, b ) {
  12651. return a.next.i !== b.i && a.prev.i !== b.i && ! intersectsPolygon( a, b ) && // dones't intersect other edges
  12652. ( locallyInside( a, b ) && locallyInside( b, a ) && middleInside( a, b ) && // locally visible
  12653. ( area( a.prev, a, b.prev ) || area( a, b.prev, b ) ) || // does not create opposite-facing sectors
  12654. equals( a, b ) && area( a.prev, a, a.next ) > 0 && area( b.prev, b, b.next ) > 0 ); // special zero-length case
  12655. }
  12656. // signed area of a triangle
  12657. function area( p, q, r ) {
  12658. return ( q.y - p.y ) * ( r.x - q.x ) - ( q.x - p.x ) * ( r.y - q.y );
  12659. }
  12660. // check if two points are equal
  12661. function equals( p1, p2 ) {
  12662. return p1.x === p2.x && p1.y === p2.y;
  12663. }
  12664. // check if two segments intersect
  12665. function intersects( p1, q1, p2, q2 ) {
  12666. const o1 = sign( area( p1, q1, p2 ) );
  12667. const o2 = sign( area( p1, q1, q2 ) );
  12668. const o3 = sign( area( p2, q2, p1 ) );
  12669. const o4 = sign( area( p2, q2, q1 ) );
  12670. if ( o1 !== o2 && o3 !== o4 ) return true; // general case
  12671. if ( o1 === 0 && onSegment( p1, p2, q1 ) ) return true; // p1, q1 and p2 are collinear and p2 lies on p1q1
  12672. if ( o2 === 0 && onSegment( p1, q2, q1 ) ) return true; // p1, q1 and q2 are collinear and q2 lies on p1q1
  12673. if ( o3 === 0 && onSegment( p2, p1, q2 ) ) return true; // p2, q2 and p1 are collinear and p1 lies on p2q2
  12674. if ( o4 === 0 && onSegment( p2, q1, q2 ) ) return true; // p2, q2 and q1 are collinear and q1 lies on p2q2
  12675. return false;
  12676. }
  12677. // for collinear points p, q, r, check if point q lies on segment pr
  12678. function onSegment( p, q, r ) {
  12679. 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 );
  12680. }
  12681. function sign( num ) {
  12682. return num > 0 ? 1 : num < 0 ? - 1 : 0;
  12683. }
  12684. // check if a polygon diagonal intersects any polygon segments
  12685. function intersectsPolygon( a, b ) {
  12686. let p = a;
  12687. do {
  12688. if ( p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i &&
  12689. intersects( p, p.next, a, b ) ) return true;
  12690. p = p.next;
  12691. } while ( p !== a );
  12692. return false;
  12693. }
  12694. // check if a polygon diagonal is locally inside the polygon
  12695. function locallyInside( a, b ) {
  12696. return area( a.prev, a, a.next ) < 0 ?
  12697. area( a, b, a.next ) >= 0 && area( a, a.prev, b ) >= 0 :
  12698. area( a, b, a.prev ) < 0 || area( a, a.next, b ) < 0;
  12699. }
  12700. // check if the middle point of a polygon diagonal is inside the polygon
  12701. function middleInside( a, b ) {
  12702. let p = a,
  12703. inside = false;
  12704. const px = ( a.x + b.x ) / 2,
  12705. py = ( a.y + b.y ) / 2;
  12706. do {
  12707. if ( ( ( p.y > py ) !== ( p.next.y > py ) ) && p.next.y !== p.y &&
  12708. ( px < ( p.next.x - p.x ) * ( py - p.y ) / ( p.next.y - p.y ) + p.x ) )
  12709. inside = ! inside;
  12710. p = p.next;
  12711. } while ( p !== a );
  12712. return inside;
  12713. }
  12714. // link two polygon vertices with a bridge; if the vertices belong to the same ring, it splits polygon into two;
  12715. // if one belongs to the outer ring and another to a hole, it merges it into a single ring
  12716. function splitPolygon( a, b ) {
  12717. const a2 = new Node( a.i, a.x, a.y ),
  12718. b2 = new Node( b.i, b.x, b.y ),
  12719. an = a.next,
  12720. bp = b.prev;
  12721. a.next = b;
  12722. b.prev = a;
  12723. a2.next = an;
  12724. an.prev = a2;
  12725. b2.next = a2;
  12726. a2.prev = b2;
  12727. bp.next = b2;
  12728. b2.prev = bp;
  12729. return b2;
  12730. }
  12731. // create a node and optionally link it with previous one (in a circular doubly linked list)
  12732. function insertNode( i, x, y, last ) {
  12733. const p = new Node( i, x, y );
  12734. if ( ! last ) {
  12735. p.prev = p;
  12736. p.next = p;
  12737. } else {
  12738. p.next = last.next;
  12739. p.prev = last;
  12740. last.next.prev = p;
  12741. last.next = p;
  12742. }
  12743. return p;
  12744. }
  12745. function removeNode( p ) {
  12746. p.next.prev = p.prev;
  12747. p.prev.next = p.next;
  12748. if ( p.prevZ ) p.prevZ.nextZ = p.nextZ;
  12749. if ( p.nextZ ) p.nextZ.prevZ = p.prevZ;
  12750. }
  12751. function Node( i, x, y ) {
  12752. // vertex index in coordinates array
  12753. this.i = i;
  12754. // vertex coordinates
  12755. this.x = x;
  12756. this.y = y;
  12757. // previous and next vertex nodes in a polygon ring
  12758. this.prev = null;
  12759. this.next = null;
  12760. // z-order curve value
  12761. this.z = 0;
  12762. // previous and next nodes in z-order
  12763. this.prevZ = null;
  12764. this.nextZ = null;
  12765. // indicates whether this is a steiner point
  12766. this.steiner = false;
  12767. }
  12768. function signedArea( data, start, end, dim ) {
  12769. let sum = 0;
  12770. for ( let i = start, j = end - dim; i < end; i += dim ) {
  12771. sum += ( data[ j ] - data[ i ] ) * ( data[ i + 1 ] + data[ j + 1 ] );
  12772. j = i;
  12773. }
  12774. return sum;
  12775. }
  12776. class ShapeUtils {
  12777. // calculate area of the contour polygon
  12778. static area( contour ) {
  12779. const n = contour.length;
  12780. let a = 0.0;
  12781. for ( let p = n - 1, q = 0; q < n; p = q ++ ) {
  12782. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  12783. }
  12784. return a * 0.5;
  12785. }
  12786. static isClockWise( pts ) {
  12787. return ShapeUtils.area( pts ) < 0;
  12788. }
  12789. static triangulateShape( contour, holes ) {
  12790. const vertices = []; // flat array of vertices like [ x0,y0, x1,y1, x2,y2, ... ]
  12791. const holeIndices = []; // array of hole indices
  12792. const faces = []; // final array of vertex indices like [ [ a,b,d ], [ b,c,d ] ]
  12793. removeDupEndPts( contour );
  12794. addContour( vertices, contour );
  12795. //
  12796. let holeIndex = contour.length;
  12797. holes.forEach( removeDupEndPts );
  12798. for ( let i = 0; i < holes.length; i ++ ) {
  12799. holeIndices.push( holeIndex );
  12800. holeIndex += holes[ i ].length;
  12801. addContour( vertices, holes[ i ] );
  12802. }
  12803. //
  12804. const triangles = Earcut.triangulate( vertices, holeIndices );
  12805. //
  12806. for ( let i = 0; i < triangles.length; i += 3 ) {
  12807. faces.push( triangles.slice( i, i + 3 ) );
  12808. }
  12809. return faces;
  12810. }
  12811. }
  12812. function removeDupEndPts( points ) {
  12813. const l = points.length;
  12814. if ( l > 2 && points[ l - 1 ].equals( points[ 0 ] ) ) {
  12815. points.pop();
  12816. }
  12817. }
  12818. function addContour( vertices, contour ) {
  12819. for ( let i = 0; i < contour.length; i ++ ) {
  12820. vertices.push( contour[ i ].x );
  12821. vertices.push( contour[ i ].y );
  12822. }
  12823. }
  12824. /**
  12825. * Creates extruded geometry from a path shape.
  12826. *
  12827. * parameters = {
  12828. *
  12829. * curveSegments: <int>, // number of points on the curves
  12830. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  12831. * depth: <float>, // Depth to extrude the shape
  12832. *
  12833. * bevelEnabled: <bool>, // turn on bevel
  12834. * bevelThickness: <float>, // how deep into the original shape bevel goes
  12835. * bevelSize: <float>, // how far from shape outline (including bevelOffset) is bevel
  12836. * bevelOffset: <float>, // how far from shape outline does bevel start
  12837. * bevelSegments: <int>, // number of bevel layers
  12838. *
  12839. * extrudePath: <THREE.Curve> // curve to extrude shape along
  12840. *
  12841. * UVGenerator: <Object> // object that provides UV generator functions
  12842. *
  12843. * }
  12844. */
  12845. class ExtrudeGeometry extends BufferGeometry {
  12846. 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 = {} ) {
  12847. super();
  12848. this.type = 'ExtrudeGeometry';
  12849. this.parameters = {
  12850. shapes: shapes,
  12851. options: options
  12852. };
  12853. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  12854. const scope = this;
  12855. const verticesArray = [];
  12856. const uvArray = [];
  12857. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  12858. const shape = shapes[ i ];
  12859. addShape( shape );
  12860. }
  12861. // build geometry
  12862. this.setAttribute( 'position', new Float32BufferAttribute( verticesArray, 3 ) );
  12863. this.setAttribute( 'uv', new Float32BufferAttribute( uvArray, 2 ) );
  12864. this.computeVertexNormals();
  12865. // functions
  12866. function addShape( shape ) {
  12867. const placeholder = [];
  12868. // options
  12869. const curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  12870. const steps = options.steps !== undefined ? options.steps : 1;
  12871. const depth = options.depth !== undefined ? options.depth : 1;
  12872. let bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true;
  12873. let bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 0.2;
  12874. let bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 0.1;
  12875. let bevelOffset = options.bevelOffset !== undefined ? options.bevelOffset : 0;
  12876. let bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  12877. const extrudePath = options.extrudePath;
  12878. const uvgen = options.UVGenerator !== undefined ? options.UVGenerator : WorldUVGenerator;
  12879. //
  12880. let extrudePts, extrudeByPath = false;
  12881. let splineTube, binormal, normal, position2;
  12882. if ( extrudePath ) {
  12883. extrudePts = extrudePath.getSpacedPoints( steps );
  12884. extrudeByPath = true;
  12885. bevelEnabled = false; // bevels not supported for path extrusion
  12886. // SETUP TNB variables
  12887. // TODO1 - have a .isClosed in spline?
  12888. splineTube = extrudePath.computeFrenetFrames( steps, false );
  12889. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  12890. binormal = new Vector3();
  12891. normal = new Vector3();
  12892. position2 = new Vector3();
  12893. }
  12894. // Safeguards if bevels are not enabled
  12895. if ( ! bevelEnabled ) {
  12896. bevelSegments = 0;
  12897. bevelThickness = 0;
  12898. bevelSize = 0;
  12899. bevelOffset = 0;
  12900. }
  12901. // Variables initialization
  12902. const shapePoints = shape.extractPoints( curveSegments );
  12903. let vertices = shapePoints.shape;
  12904. const holes = shapePoints.holes;
  12905. const reverse = ! ShapeUtils.isClockWise( vertices );
  12906. if ( reverse ) {
  12907. vertices = vertices.reverse();
  12908. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  12909. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12910. const ahole = holes[ h ];
  12911. if ( ShapeUtils.isClockWise( ahole ) ) {
  12912. holes[ h ] = ahole.reverse();
  12913. }
  12914. }
  12915. }
  12916. const faces = ShapeUtils.triangulateShape( vertices, holes );
  12917. /* Vertices */
  12918. const contour = vertices; // vertices has all points but contour has only points of circumference
  12919. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  12920. const ahole = holes[ h ];
  12921. vertices = vertices.concat( ahole );
  12922. }
  12923. function scalePt2( pt, vec, size ) {
  12924. if ( ! vec ) console.error( 'THREE.ExtrudeGeometry: vec does not exist' );
  12925. return pt.clone().addScaledVector( vec, size );
  12926. }
  12927. const vlen = vertices.length, flen = faces.length;
  12928. // Find directions for point movement
  12929. function getBevelVec( inPt, inPrev, inNext ) {
  12930. // computes for inPt the corresponding point inPt' on a new contour
  12931. // shifted by 1 unit (length of normalized vector) to the left
  12932. // if we walk along contour clockwise, this new contour is outside the old one
  12933. //
  12934. // inPt' is the intersection of the two lines parallel to the two
  12935. // adjacent edges of inPt at a distance of 1 unit on the left side.
  12936. let v_trans_x, v_trans_y, shrink_by; // resulting translation vector for inPt
  12937. // good reading for geometry algorithms (here: line-line intersection)
  12938. // http://geomalgorithms.com/a05-_intersect-1.html
  12939. const v_prev_x = inPt.x - inPrev.x,
  12940. v_prev_y = inPt.y - inPrev.y;
  12941. const v_next_x = inNext.x - inPt.x,
  12942. v_next_y = inNext.y - inPt.y;
  12943. const v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  12944. // check for collinear edges
  12945. const collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12946. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  12947. // not collinear
  12948. // length of vectors for normalizing
  12949. const v_prev_len = Math.sqrt( v_prev_lensq );
  12950. const v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  12951. // shift adjacent points by unit vectors to the left
  12952. const ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  12953. const ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  12954. const ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  12955. const ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  12956. // scaling factor for v_prev to intersection point
  12957. const sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  12958. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  12959. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  12960. // vector from inPt to intersection point
  12961. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  12962. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  12963. // Don't normalize!, otherwise sharp corners become ugly
  12964. // but prevent crazy spikes
  12965. const v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  12966. if ( v_trans_lensq <= 2 ) {
  12967. return new Vector2( v_trans_x, v_trans_y );
  12968. } else {
  12969. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  12970. }
  12971. } else {
  12972. // handle special case of collinear edges
  12973. let direction_eq = false; // assumes: opposite
  12974. if ( v_prev_x > Number.EPSILON ) {
  12975. if ( v_next_x > Number.EPSILON ) {
  12976. direction_eq = true;
  12977. }
  12978. } else {
  12979. if ( v_prev_x < - Number.EPSILON ) {
  12980. if ( v_next_x < - Number.EPSILON ) {
  12981. direction_eq = true;
  12982. }
  12983. } else {
  12984. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  12985. direction_eq = true;
  12986. }
  12987. }
  12988. }
  12989. if ( direction_eq ) {
  12990. // console.log("Warning: lines are a straight sequence");
  12991. v_trans_x = - v_prev_y;
  12992. v_trans_y = v_prev_x;
  12993. shrink_by = Math.sqrt( v_prev_lensq );
  12994. } else {
  12995. // console.log("Warning: lines are a straight spike");
  12996. v_trans_x = v_prev_x;
  12997. v_trans_y = v_prev_y;
  12998. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  12999. }
  13000. }
  13001. return new Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  13002. }
  13003. const contourMovements = [];
  13004. for ( let i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13005. if ( j === il ) j = 0;
  13006. if ( k === il ) k = 0;
  13007. // (j)---(i)---(k)
  13008. // console.log('i,j,k', i, j , k)
  13009. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  13010. }
  13011. const holesMovements = [];
  13012. let oneHoleMovements, verticesMovements = contourMovements.concat();
  13013. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13014. const ahole = holes[ h ];
  13015. oneHoleMovements = [];
  13016. for ( let i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  13017. if ( j === il ) j = 0;
  13018. if ( k === il ) k = 0;
  13019. // (j)---(i)---(k)
  13020. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  13021. }
  13022. holesMovements.push( oneHoleMovements );
  13023. verticesMovements = verticesMovements.concat( oneHoleMovements );
  13024. }
  13025. // Loop bevelSegments, 1 for the front, 1 for the back
  13026. for ( let b = 0; b < bevelSegments; b ++ ) {
  13027. //for ( b = bevelSegments; b > 0; b -- ) {
  13028. const t = b / bevelSegments;
  13029. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13030. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13031. // contract shape
  13032. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13033. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13034. v( vert.x, vert.y, - z );
  13035. }
  13036. // expand holes
  13037. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13038. const ahole = holes[ h ];
  13039. oneHoleMovements = holesMovements[ h ];
  13040. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13041. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13042. v( vert.x, vert.y, - z );
  13043. }
  13044. }
  13045. }
  13046. const bs = bevelSize + bevelOffset;
  13047. // Back facing vertices
  13048. for ( let i = 0; i < vlen; i ++ ) {
  13049. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13050. if ( ! extrudeByPath ) {
  13051. v( vert.x, vert.y, 0 );
  13052. } else {
  13053. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  13054. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  13055. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  13056. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  13057. v( position2.x, position2.y, position2.z );
  13058. }
  13059. }
  13060. // Add stepped vertices...
  13061. // Including front facing vertices
  13062. for ( let s = 1; s <= steps; s ++ ) {
  13063. for ( let i = 0; i < vlen; i ++ ) {
  13064. const vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  13065. if ( ! extrudeByPath ) {
  13066. v( vert.x, vert.y, depth / steps * s );
  13067. } else {
  13068. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  13069. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  13070. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  13071. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  13072. v( position2.x, position2.y, position2.z );
  13073. }
  13074. }
  13075. }
  13076. // Add bevel segments planes
  13077. //for ( b = 1; b <= bevelSegments; b ++ ) {
  13078. for ( let b = bevelSegments - 1; b >= 0; b -- ) {
  13079. const t = b / bevelSegments;
  13080. const z = bevelThickness * Math.cos( t * Math.PI / 2 );
  13081. const bs = bevelSize * Math.sin( t * Math.PI / 2 ) + bevelOffset;
  13082. // contract shape
  13083. for ( let i = 0, il = contour.length; i < il; i ++ ) {
  13084. const vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  13085. v( vert.x, vert.y, depth + z );
  13086. }
  13087. // expand holes
  13088. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13089. const ahole = holes[ h ];
  13090. oneHoleMovements = holesMovements[ h ];
  13091. for ( let i = 0, il = ahole.length; i < il; i ++ ) {
  13092. const vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  13093. if ( ! extrudeByPath ) {
  13094. v( vert.x, vert.y, depth + z );
  13095. } else {
  13096. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  13097. }
  13098. }
  13099. }
  13100. }
  13101. /* Faces */
  13102. // Top and bottom faces
  13103. buildLidFaces();
  13104. // Sides faces
  13105. buildSideFaces();
  13106. ///// Internal functions
  13107. function buildLidFaces() {
  13108. const start = verticesArray.length / 3;
  13109. if ( bevelEnabled ) {
  13110. let layer = 0; // steps + 1
  13111. let offset = vlen * layer;
  13112. // Bottom faces
  13113. for ( let i = 0; i < flen; i ++ ) {
  13114. const face = faces[ i ];
  13115. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  13116. }
  13117. layer = steps + bevelSegments * 2;
  13118. offset = vlen * layer;
  13119. // Top faces
  13120. for ( let i = 0; i < flen; i ++ ) {
  13121. const face = faces[ i ];
  13122. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  13123. }
  13124. } else {
  13125. // Bottom faces
  13126. for ( let i = 0; i < flen; i ++ ) {
  13127. const face = faces[ i ];
  13128. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  13129. }
  13130. // Top faces
  13131. for ( let i = 0; i < flen; i ++ ) {
  13132. const face = faces[ i ];
  13133. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  13134. }
  13135. }
  13136. scope.addGroup( start, verticesArray.length / 3 - start, 0 );
  13137. }
  13138. // Create faces for the z-sides of the shape
  13139. function buildSideFaces() {
  13140. const start = verticesArray.length / 3;
  13141. let layeroffset = 0;
  13142. sidewalls( contour, layeroffset );
  13143. layeroffset += contour.length;
  13144. for ( let h = 0, hl = holes.length; h < hl; h ++ ) {
  13145. const ahole = holes[ h ];
  13146. sidewalls( ahole, layeroffset );
  13147. //, true
  13148. layeroffset += ahole.length;
  13149. }
  13150. scope.addGroup( start, verticesArray.length / 3 - start, 1 );
  13151. }
  13152. function sidewalls( contour, layeroffset ) {
  13153. let i = contour.length;
  13154. while ( -- i >= 0 ) {
  13155. const j = i;
  13156. let k = i - 1;
  13157. if ( k < 0 ) k = contour.length - 1;
  13158. //console.log('b', i,j, i-1, k,vertices.length);
  13159. for ( let s = 0, sl = ( steps + bevelSegments * 2 ); s < sl; s ++ ) {
  13160. const slen1 = vlen * s;
  13161. const slen2 = vlen * ( s + 1 );
  13162. const a = layeroffset + j + slen1,
  13163. b = layeroffset + k + slen1,
  13164. c = layeroffset + k + slen2,
  13165. d = layeroffset + j + slen2;
  13166. f4( a, b, c, d );
  13167. }
  13168. }
  13169. }
  13170. function v( x, y, z ) {
  13171. placeholder.push( x );
  13172. placeholder.push( y );
  13173. placeholder.push( z );
  13174. }
  13175. function f3( a, b, c ) {
  13176. addVertex( a );
  13177. addVertex( b );
  13178. addVertex( c );
  13179. const nextIndex = verticesArray.length / 3;
  13180. const uvs = uvgen.generateTopUV( scope, verticesArray, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13181. addUV( uvs[ 0 ] );
  13182. addUV( uvs[ 1 ] );
  13183. addUV( uvs[ 2 ] );
  13184. }
  13185. function f4( a, b, c, d ) {
  13186. addVertex( a );
  13187. addVertex( b );
  13188. addVertex( d );
  13189. addVertex( b );
  13190. addVertex( c );
  13191. addVertex( d );
  13192. const nextIndex = verticesArray.length / 3;
  13193. const uvs = uvgen.generateSideWallUV( scope, verticesArray, nextIndex - 6, nextIndex - 3, nextIndex - 2, nextIndex - 1 );
  13194. addUV( uvs[ 0 ] );
  13195. addUV( uvs[ 1 ] );
  13196. addUV( uvs[ 3 ] );
  13197. addUV( uvs[ 1 ] );
  13198. addUV( uvs[ 2 ] );
  13199. addUV( uvs[ 3 ] );
  13200. }
  13201. function addVertex( index ) {
  13202. verticesArray.push( placeholder[ index * 3 + 0 ] );
  13203. verticesArray.push( placeholder[ index * 3 + 1 ] );
  13204. verticesArray.push( placeholder[ index * 3 + 2 ] );
  13205. }
  13206. function addUV( vector2 ) {
  13207. uvArray.push( vector2.x );
  13208. uvArray.push( vector2.y );
  13209. }
  13210. }
  13211. }
  13212. copy( source ) {
  13213. super.copy( source );
  13214. this.parameters = Object.assign( {}, source.parameters );
  13215. return this;
  13216. }
  13217. toJSON() {
  13218. const data = super.toJSON();
  13219. const shapes = this.parameters.shapes;
  13220. const options = this.parameters.options;
  13221. return toJSON$1( shapes, options, data );
  13222. }
  13223. static fromJSON( data, shapes ) {
  13224. const geometryShapes = [];
  13225. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13226. const shape = shapes[ data.shapes[ j ] ];
  13227. geometryShapes.push( shape );
  13228. }
  13229. const extrudePath = data.options.extrudePath;
  13230. if ( extrudePath !== undefined ) {
  13231. data.options.extrudePath = new Curves[ extrudePath.type ]().fromJSON( extrudePath );
  13232. }
  13233. return new ExtrudeGeometry( geometryShapes, data.options );
  13234. }
  13235. }
  13236. const WorldUVGenerator = {
  13237. generateTopUV: function ( geometry, vertices, indexA, indexB, indexC ) {
  13238. const a_x = vertices[ indexA * 3 ];
  13239. const a_y = vertices[ indexA * 3 + 1 ];
  13240. const b_x = vertices[ indexB * 3 ];
  13241. const b_y = vertices[ indexB * 3 + 1 ];
  13242. const c_x = vertices[ indexC * 3 ];
  13243. const c_y = vertices[ indexC * 3 + 1 ];
  13244. return [
  13245. new Vector2( a_x, a_y ),
  13246. new Vector2( b_x, b_y ),
  13247. new Vector2( c_x, c_y )
  13248. ];
  13249. },
  13250. generateSideWallUV: function ( geometry, vertices, indexA, indexB, indexC, indexD ) {
  13251. const a_x = vertices[ indexA * 3 ];
  13252. const a_y = vertices[ indexA * 3 + 1 ];
  13253. const a_z = vertices[ indexA * 3 + 2 ];
  13254. const b_x = vertices[ indexB * 3 ];
  13255. const b_y = vertices[ indexB * 3 + 1 ];
  13256. const b_z = vertices[ indexB * 3 + 2 ];
  13257. const c_x = vertices[ indexC * 3 ];
  13258. const c_y = vertices[ indexC * 3 + 1 ];
  13259. const c_z = vertices[ indexC * 3 + 2 ];
  13260. const d_x = vertices[ indexD * 3 ];
  13261. const d_y = vertices[ indexD * 3 + 1 ];
  13262. const d_z = vertices[ indexD * 3 + 2 ];
  13263. if ( Math.abs( a_y - b_y ) < Math.abs( a_x - b_x ) ) {
  13264. return [
  13265. new Vector2( a_x, 1 - a_z ),
  13266. new Vector2( b_x, 1 - b_z ),
  13267. new Vector2( c_x, 1 - c_z ),
  13268. new Vector2( d_x, 1 - d_z )
  13269. ];
  13270. } else {
  13271. return [
  13272. new Vector2( a_y, 1 - a_z ),
  13273. new Vector2( b_y, 1 - b_z ),
  13274. new Vector2( c_y, 1 - c_z ),
  13275. new Vector2( d_y, 1 - d_z )
  13276. ];
  13277. }
  13278. }
  13279. };
  13280. function toJSON$1( shapes, options, data ) {
  13281. data.shapes = [];
  13282. if ( Array.isArray( shapes ) ) {
  13283. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13284. const shape = shapes[ i ];
  13285. data.shapes.push( shape.uuid );
  13286. }
  13287. } else {
  13288. data.shapes.push( shapes.uuid );
  13289. }
  13290. data.options = Object.assign( {}, options );
  13291. if ( options.extrudePath !== undefined ) data.options.extrudePath = options.extrudePath.toJSON();
  13292. return data;
  13293. }
  13294. class IcosahedronGeometry extends PolyhedronGeometry {
  13295. constructor( radius = 1, detail = 0 ) {
  13296. const t = ( 1 + Math.sqrt( 5 ) ) / 2;
  13297. const vertices = [
  13298. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  13299. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  13300. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  13301. ];
  13302. const indices = [
  13303. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  13304. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  13305. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  13306. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  13307. ];
  13308. super( vertices, indices, radius, detail );
  13309. this.type = 'IcosahedronGeometry';
  13310. this.parameters = {
  13311. radius: radius,
  13312. detail: detail
  13313. };
  13314. }
  13315. static fromJSON( data ) {
  13316. return new IcosahedronGeometry( data.radius, data.detail );
  13317. }
  13318. }
  13319. class OctahedronGeometry extends PolyhedronGeometry {
  13320. constructor( radius = 1, detail = 0 ) {
  13321. const vertices = [
  13322. 1, 0, 0, - 1, 0, 0, 0, 1, 0,
  13323. 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  13324. ];
  13325. const indices = [
  13326. 0, 2, 4, 0, 4, 3, 0, 3, 5,
  13327. 0, 5, 2, 1, 2, 5, 1, 5, 3,
  13328. 1, 3, 4, 1, 4, 2
  13329. ];
  13330. super( vertices, indices, radius, detail );
  13331. this.type = 'OctahedronGeometry';
  13332. this.parameters = {
  13333. radius: radius,
  13334. detail: detail
  13335. };
  13336. }
  13337. static fromJSON( data ) {
  13338. return new OctahedronGeometry( data.radius, data.detail );
  13339. }
  13340. }
  13341. class PlaneGeometry extends BufferGeometry {
  13342. constructor( width = 1, height = 1, widthSegments = 1, heightSegments = 1 ) {
  13343. super();
  13344. this.type = 'PlaneGeometry';
  13345. this.parameters = {
  13346. width: width,
  13347. height: height,
  13348. widthSegments: widthSegments,
  13349. heightSegments: heightSegments
  13350. };
  13351. const width_half = width / 2;
  13352. const height_half = height / 2;
  13353. const gridX = Math.floor( widthSegments );
  13354. const gridY = Math.floor( heightSegments );
  13355. const gridX1 = gridX + 1;
  13356. const gridY1 = gridY + 1;
  13357. const segment_width = width / gridX;
  13358. const segment_height = height / gridY;
  13359. //
  13360. const indices = [];
  13361. const vertices = [];
  13362. const normals = [];
  13363. const uvs = [];
  13364. for ( let iy = 0; iy < gridY1; iy ++ ) {
  13365. const y = iy * segment_height - height_half;
  13366. for ( let ix = 0; ix < gridX1; ix ++ ) {
  13367. const x = ix * segment_width - width_half;
  13368. vertices.push( x, - y, 0 );
  13369. normals.push( 0, 0, 1 );
  13370. uvs.push( ix / gridX );
  13371. uvs.push( 1 - ( iy / gridY ) );
  13372. }
  13373. }
  13374. for ( let iy = 0; iy < gridY; iy ++ ) {
  13375. for ( let ix = 0; ix < gridX; ix ++ ) {
  13376. const a = ix + gridX1 * iy;
  13377. const b = ix + gridX1 * ( iy + 1 );
  13378. const c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  13379. const d = ( ix + 1 ) + gridX1 * iy;
  13380. indices.push( a, b, d );
  13381. indices.push( b, c, d );
  13382. }
  13383. }
  13384. this.setIndex( indices );
  13385. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13386. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13387. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13388. }
  13389. copy( source ) {
  13390. super.copy( source );
  13391. this.parameters = Object.assign( {}, source.parameters );
  13392. return this;
  13393. }
  13394. static fromJSON( data ) {
  13395. return new PlaneGeometry( data.width, data.height, data.widthSegments, data.heightSegments );
  13396. }
  13397. }
  13398. class RingGeometry extends BufferGeometry {
  13399. constructor( innerRadius = 0.5, outerRadius = 1, thetaSegments = 32, phiSegments = 1, thetaStart = 0, thetaLength = Math.PI * 2 ) {
  13400. super();
  13401. this.type = 'RingGeometry';
  13402. this.parameters = {
  13403. innerRadius: innerRadius,
  13404. outerRadius: outerRadius,
  13405. thetaSegments: thetaSegments,
  13406. phiSegments: phiSegments,
  13407. thetaStart: thetaStart,
  13408. thetaLength: thetaLength
  13409. };
  13410. thetaSegments = Math.max( 3, thetaSegments );
  13411. phiSegments = Math.max( 1, phiSegments );
  13412. // buffers
  13413. const indices = [];
  13414. const vertices = [];
  13415. const normals = [];
  13416. const uvs = [];
  13417. // some helper variables
  13418. let radius = innerRadius;
  13419. const radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  13420. const vertex = new Vector3();
  13421. const uv = new Vector2();
  13422. // generate vertices, normals and uvs
  13423. for ( let j = 0; j <= phiSegments; j ++ ) {
  13424. for ( let i = 0; i <= thetaSegments; i ++ ) {
  13425. // values are generate from the inside of the ring to the outside
  13426. const segment = thetaStart + i / thetaSegments * thetaLength;
  13427. // vertex
  13428. vertex.x = radius * Math.cos( segment );
  13429. vertex.y = radius * Math.sin( segment );
  13430. vertices.push( vertex.x, vertex.y, vertex.z );
  13431. // normal
  13432. normals.push( 0, 0, 1 );
  13433. // uv
  13434. uv.x = ( vertex.x / outerRadius + 1 ) / 2;
  13435. uv.y = ( vertex.y / outerRadius + 1 ) / 2;
  13436. uvs.push( uv.x, uv.y );
  13437. }
  13438. // increase the radius for next row of vertices
  13439. radius += radiusStep;
  13440. }
  13441. // indices
  13442. for ( let j = 0; j < phiSegments; j ++ ) {
  13443. const thetaSegmentLevel = j * ( thetaSegments + 1 );
  13444. for ( let i = 0; i < thetaSegments; i ++ ) {
  13445. const segment = i + thetaSegmentLevel;
  13446. const a = segment;
  13447. const b = segment + thetaSegments + 1;
  13448. const c = segment + thetaSegments + 2;
  13449. const d = segment + 1;
  13450. // faces
  13451. indices.push( a, b, d );
  13452. indices.push( b, c, d );
  13453. }
  13454. }
  13455. // build geometry
  13456. this.setIndex( indices );
  13457. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13458. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13459. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13460. }
  13461. copy( source ) {
  13462. super.copy( source );
  13463. this.parameters = Object.assign( {}, source.parameters );
  13464. return this;
  13465. }
  13466. static fromJSON( data ) {
  13467. return new RingGeometry( data.innerRadius, data.outerRadius, data.thetaSegments, data.phiSegments, data.thetaStart, data.thetaLength );
  13468. }
  13469. }
  13470. class ShapeGeometry extends BufferGeometry {
  13471. constructor( shapes = new Shape( [ new Vector2( 0, 0.5 ), new Vector2( - 0.5, - 0.5 ), new Vector2( 0.5, - 0.5 ) ] ), curveSegments = 12 ) {
  13472. super();
  13473. this.type = 'ShapeGeometry';
  13474. this.parameters = {
  13475. shapes: shapes,
  13476. curveSegments: curveSegments
  13477. };
  13478. // buffers
  13479. const indices = [];
  13480. const vertices = [];
  13481. const normals = [];
  13482. const uvs = [];
  13483. // helper variables
  13484. let groupStart = 0;
  13485. let groupCount = 0;
  13486. // allow single and array values for "shapes" parameter
  13487. if ( Array.isArray( shapes ) === false ) {
  13488. addShape( shapes );
  13489. } else {
  13490. for ( let i = 0; i < shapes.length; i ++ ) {
  13491. addShape( shapes[ i ] );
  13492. this.addGroup( groupStart, groupCount, i ); // enables MultiMaterial support
  13493. groupStart += groupCount;
  13494. groupCount = 0;
  13495. }
  13496. }
  13497. // build geometry
  13498. this.setIndex( indices );
  13499. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13500. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13501. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13502. // helper functions
  13503. function addShape( shape ) {
  13504. const indexOffset = vertices.length / 3;
  13505. const points = shape.extractPoints( curveSegments );
  13506. let shapeVertices = points.shape;
  13507. const shapeHoles = points.holes;
  13508. // check direction of vertices
  13509. if ( ShapeUtils.isClockWise( shapeVertices ) === false ) {
  13510. shapeVertices = shapeVertices.reverse();
  13511. }
  13512. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13513. const shapeHole = shapeHoles[ i ];
  13514. if ( ShapeUtils.isClockWise( shapeHole ) === true ) {
  13515. shapeHoles[ i ] = shapeHole.reverse();
  13516. }
  13517. }
  13518. const faces = ShapeUtils.triangulateShape( shapeVertices, shapeHoles );
  13519. // join vertices of inner and outer paths to a single array
  13520. for ( let i = 0, l = shapeHoles.length; i < l; i ++ ) {
  13521. const shapeHole = shapeHoles[ i ];
  13522. shapeVertices = shapeVertices.concat( shapeHole );
  13523. }
  13524. // vertices, normals, uvs
  13525. for ( let i = 0, l = shapeVertices.length; i < l; i ++ ) {
  13526. const vertex = shapeVertices[ i ];
  13527. vertices.push( vertex.x, vertex.y, 0 );
  13528. normals.push( 0, 0, 1 );
  13529. uvs.push( vertex.x, vertex.y ); // world uvs
  13530. }
  13531. // indices
  13532. for ( let i = 0, l = faces.length; i < l; i ++ ) {
  13533. const face = faces[ i ];
  13534. const a = face[ 0 ] + indexOffset;
  13535. const b = face[ 1 ] + indexOffset;
  13536. const c = face[ 2 ] + indexOffset;
  13537. indices.push( a, b, c );
  13538. groupCount += 3;
  13539. }
  13540. }
  13541. }
  13542. copy( source ) {
  13543. super.copy( source );
  13544. this.parameters = Object.assign( {}, source.parameters );
  13545. return this;
  13546. }
  13547. toJSON() {
  13548. const data = super.toJSON();
  13549. const shapes = this.parameters.shapes;
  13550. return toJSON( shapes, data );
  13551. }
  13552. static fromJSON( data, shapes ) {
  13553. const geometryShapes = [];
  13554. for ( let j = 0, jl = data.shapes.length; j < jl; j ++ ) {
  13555. const shape = shapes[ data.shapes[ j ] ];
  13556. geometryShapes.push( shape );
  13557. }
  13558. return new ShapeGeometry( geometryShapes, data.curveSegments );
  13559. }
  13560. }
  13561. function toJSON( shapes, data ) {
  13562. data.shapes = [];
  13563. if ( Array.isArray( shapes ) ) {
  13564. for ( let i = 0, l = shapes.length; i < l; i ++ ) {
  13565. const shape = shapes[ i ];
  13566. data.shapes.push( shape.uuid );
  13567. }
  13568. } else {
  13569. data.shapes.push( shapes.uuid );
  13570. }
  13571. return data;
  13572. }
  13573. class SphereGeometry extends BufferGeometry {
  13574. constructor( radius = 1, widthSegments = 32, heightSegments = 16, phiStart = 0, phiLength = Math.PI * 2, thetaStart = 0, thetaLength = Math.PI ) {
  13575. super();
  13576. this.type = 'SphereGeometry';
  13577. this.parameters = {
  13578. radius: radius,
  13579. widthSegments: widthSegments,
  13580. heightSegments: heightSegments,
  13581. phiStart: phiStart,
  13582. phiLength: phiLength,
  13583. thetaStart: thetaStart,
  13584. thetaLength: thetaLength
  13585. };
  13586. widthSegments = Math.max( 3, Math.floor( widthSegments ) );
  13587. heightSegments = Math.max( 2, Math.floor( heightSegments ) );
  13588. const thetaEnd = Math.min( thetaStart + thetaLength, Math.PI );
  13589. let index = 0;
  13590. const grid = [];
  13591. const vertex = new Vector3();
  13592. const normal = new Vector3();
  13593. // buffers
  13594. const indices = [];
  13595. const vertices = [];
  13596. const normals = [];
  13597. const uvs = [];
  13598. // generate vertices, normals and uvs
  13599. for ( let iy = 0; iy <= heightSegments; iy ++ ) {
  13600. const verticesRow = [];
  13601. const v = iy / heightSegments;
  13602. // special case for the poles
  13603. let uOffset = 0;
  13604. if ( iy === 0 && thetaStart === 0 ) {
  13605. uOffset = 0.5 / widthSegments;
  13606. } else if ( iy === heightSegments && thetaEnd === Math.PI ) {
  13607. uOffset = - 0.5 / widthSegments;
  13608. }
  13609. for ( let ix = 0; ix <= widthSegments; ix ++ ) {
  13610. const u = ix / widthSegments;
  13611. // vertex
  13612. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13613. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  13614. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  13615. vertices.push( vertex.x, vertex.y, vertex.z );
  13616. // normal
  13617. normal.copy( vertex ).normalize();
  13618. normals.push( normal.x, normal.y, normal.z );
  13619. // uv
  13620. uvs.push( u + uOffset, 1 - v );
  13621. verticesRow.push( index ++ );
  13622. }
  13623. grid.push( verticesRow );
  13624. }
  13625. // indices
  13626. for ( let iy = 0; iy < heightSegments; iy ++ ) {
  13627. for ( let ix = 0; ix < widthSegments; ix ++ ) {
  13628. const a = grid[ iy ][ ix + 1 ];
  13629. const b = grid[ iy ][ ix ];
  13630. const c = grid[ iy + 1 ][ ix ];
  13631. const d = grid[ iy + 1 ][ ix + 1 ];
  13632. if ( iy !== 0 || thetaStart > 0 ) indices.push( a, b, d );
  13633. if ( iy !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( b, c, d );
  13634. }
  13635. }
  13636. // build geometry
  13637. this.setIndex( indices );
  13638. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13639. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13640. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13641. }
  13642. copy( source ) {
  13643. super.copy( source );
  13644. this.parameters = Object.assign( {}, source.parameters );
  13645. return this;
  13646. }
  13647. static fromJSON( data ) {
  13648. return new SphereGeometry( data.radius, data.widthSegments, data.heightSegments, data.phiStart, data.phiLength, data.thetaStart, data.thetaLength );
  13649. }
  13650. }
  13651. class TetrahedronGeometry extends PolyhedronGeometry {
  13652. constructor( radius = 1, detail = 0 ) {
  13653. const vertices = [
  13654. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  13655. ];
  13656. const indices = [
  13657. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  13658. ];
  13659. super( vertices, indices, radius, detail );
  13660. this.type = 'TetrahedronGeometry';
  13661. this.parameters = {
  13662. radius: radius,
  13663. detail: detail
  13664. };
  13665. }
  13666. static fromJSON( data ) {
  13667. return new TetrahedronGeometry( data.radius, data.detail );
  13668. }
  13669. }
  13670. class TorusGeometry extends BufferGeometry {
  13671. constructor( radius = 1, tube = 0.4, radialSegments = 12, tubularSegments = 48, arc = Math.PI * 2 ) {
  13672. super();
  13673. this.type = 'TorusGeometry';
  13674. this.parameters = {
  13675. radius: radius,
  13676. tube: tube,
  13677. radialSegments: radialSegments,
  13678. tubularSegments: tubularSegments,
  13679. arc: arc
  13680. };
  13681. radialSegments = Math.floor( radialSegments );
  13682. tubularSegments = Math.floor( tubularSegments );
  13683. // buffers
  13684. const indices = [];
  13685. const vertices = [];
  13686. const normals = [];
  13687. const uvs = [];
  13688. // helper variables
  13689. const center = new Vector3();
  13690. const vertex = new Vector3();
  13691. const normal = new Vector3();
  13692. // generate vertices, normals and uvs
  13693. for ( let j = 0; j <= radialSegments; j ++ ) {
  13694. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13695. const u = i / tubularSegments * arc;
  13696. const v = j / radialSegments * Math.PI * 2;
  13697. // vertex
  13698. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  13699. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  13700. vertex.z = tube * Math.sin( v );
  13701. vertices.push( vertex.x, vertex.y, vertex.z );
  13702. // normal
  13703. center.x = radius * Math.cos( u );
  13704. center.y = radius * Math.sin( u );
  13705. normal.subVectors( vertex, center ).normalize();
  13706. normals.push( normal.x, normal.y, normal.z );
  13707. // uv
  13708. uvs.push( i / tubularSegments );
  13709. uvs.push( j / radialSegments );
  13710. }
  13711. }
  13712. // generate indices
  13713. for ( let j = 1; j <= radialSegments; j ++ ) {
  13714. for ( let i = 1; i <= tubularSegments; i ++ ) {
  13715. // indices
  13716. const a = ( tubularSegments + 1 ) * j + i - 1;
  13717. const b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  13718. const c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  13719. const d = ( tubularSegments + 1 ) * j + i;
  13720. // faces
  13721. indices.push( a, b, d );
  13722. indices.push( b, c, d );
  13723. }
  13724. }
  13725. // build geometry
  13726. this.setIndex( indices );
  13727. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13728. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13729. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13730. }
  13731. copy( source ) {
  13732. super.copy( source );
  13733. this.parameters = Object.assign( {}, source.parameters );
  13734. return this;
  13735. }
  13736. static fromJSON( data ) {
  13737. return new TorusGeometry( data.radius, data.tube, data.radialSegments, data.tubularSegments, data.arc );
  13738. }
  13739. }
  13740. class TorusKnotGeometry extends BufferGeometry {
  13741. constructor( radius = 1, tube = 0.4, tubularSegments = 64, radialSegments = 8, p = 2, q = 3 ) {
  13742. super();
  13743. this.type = 'TorusKnotGeometry';
  13744. this.parameters = {
  13745. radius: radius,
  13746. tube: tube,
  13747. tubularSegments: tubularSegments,
  13748. radialSegments: radialSegments,
  13749. p: p,
  13750. q: q
  13751. };
  13752. tubularSegments = Math.floor( tubularSegments );
  13753. radialSegments = Math.floor( radialSegments );
  13754. // buffers
  13755. const indices = [];
  13756. const vertices = [];
  13757. const normals = [];
  13758. const uvs = [];
  13759. // helper variables
  13760. const vertex = new Vector3();
  13761. const normal = new Vector3();
  13762. const P1 = new Vector3();
  13763. const P2 = new Vector3();
  13764. const B = new Vector3();
  13765. const T = new Vector3();
  13766. const N = new Vector3();
  13767. // generate vertices, normals and uvs
  13768. for ( let i = 0; i <= tubularSegments; ++ i ) {
  13769. // the radian "u" is used to calculate the position on the torus curve of the current tubular segment
  13770. const u = i / tubularSegments * p * Math.PI * 2;
  13771. // now we calculate two points. P1 is our current position on the curve, P2 is a little farther ahead.
  13772. // these points are used to create a special "coordinate space", which is necessary to calculate the correct vertex positions
  13773. calculatePositionOnCurve( u, p, q, radius, P1 );
  13774. calculatePositionOnCurve( u + 0.01, p, q, radius, P2 );
  13775. // calculate orthonormal basis
  13776. T.subVectors( P2, P1 );
  13777. N.addVectors( P2, P1 );
  13778. B.crossVectors( T, N );
  13779. N.crossVectors( B, T );
  13780. // normalize B, N. T can be ignored, we don't use it
  13781. B.normalize();
  13782. N.normalize();
  13783. for ( let j = 0; j <= radialSegments; ++ j ) {
  13784. // now calculate the vertices. they are nothing more than an extrusion of the torus curve.
  13785. // because we extrude a shape in the xy-plane, there is no need to calculate a z-value.
  13786. const v = j / radialSegments * Math.PI * 2;
  13787. const cx = - tube * Math.cos( v );
  13788. const cy = tube * Math.sin( v );
  13789. // now calculate the final vertex position.
  13790. // first we orient the extrusion with our basis vectors, then we add it to the current position on the curve
  13791. vertex.x = P1.x + ( cx * N.x + cy * B.x );
  13792. vertex.y = P1.y + ( cx * N.y + cy * B.y );
  13793. vertex.z = P1.z + ( cx * N.z + cy * B.z );
  13794. vertices.push( vertex.x, vertex.y, vertex.z );
  13795. // normal (P1 is always the center/origin of the extrusion, thus we can use it to calculate the normal)
  13796. normal.subVectors( vertex, P1 ).normalize();
  13797. normals.push( normal.x, normal.y, normal.z );
  13798. // uv
  13799. uvs.push( i / tubularSegments );
  13800. uvs.push( j / radialSegments );
  13801. }
  13802. }
  13803. // generate indices
  13804. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13805. for ( let i = 1; i <= radialSegments; i ++ ) {
  13806. // indices
  13807. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13808. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13809. const c = ( radialSegments + 1 ) * j + i;
  13810. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13811. // faces
  13812. indices.push( a, b, d );
  13813. indices.push( b, c, d );
  13814. }
  13815. }
  13816. // build geometry
  13817. this.setIndex( indices );
  13818. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13819. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13820. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13821. // this function calculates the current position on the torus curve
  13822. function calculatePositionOnCurve( u, p, q, radius, position ) {
  13823. const cu = Math.cos( u );
  13824. const su = Math.sin( u );
  13825. const quOverP = q / p * u;
  13826. const cs = Math.cos( quOverP );
  13827. position.x = radius * ( 2 + cs ) * 0.5 * cu;
  13828. position.y = radius * ( 2 + cs ) * su * 0.5;
  13829. position.z = radius * Math.sin( quOverP ) * 0.5;
  13830. }
  13831. }
  13832. copy( source ) {
  13833. super.copy( source );
  13834. this.parameters = Object.assign( {}, source.parameters );
  13835. return this;
  13836. }
  13837. static fromJSON( data ) {
  13838. return new TorusKnotGeometry( data.radius, data.tube, data.tubularSegments, data.radialSegments, data.p, data.q );
  13839. }
  13840. }
  13841. class TubeGeometry extends BufferGeometry {
  13842. 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 ) {
  13843. super();
  13844. this.type = 'TubeGeometry';
  13845. this.parameters = {
  13846. path: path,
  13847. tubularSegments: tubularSegments,
  13848. radius: radius,
  13849. radialSegments: radialSegments,
  13850. closed: closed
  13851. };
  13852. const frames = path.computeFrenetFrames( tubularSegments, closed );
  13853. // expose internals
  13854. this.tangents = frames.tangents;
  13855. this.normals = frames.normals;
  13856. this.binormals = frames.binormals;
  13857. // helper variables
  13858. const vertex = new Vector3();
  13859. const normal = new Vector3();
  13860. const uv = new Vector2();
  13861. let P = new Vector3();
  13862. // buffer
  13863. const vertices = [];
  13864. const normals = [];
  13865. const uvs = [];
  13866. const indices = [];
  13867. // create buffer data
  13868. generateBufferData();
  13869. // build geometry
  13870. this.setIndex( indices );
  13871. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  13872. this.setAttribute( 'normal', new Float32BufferAttribute( normals, 3 ) );
  13873. this.setAttribute( 'uv', new Float32BufferAttribute( uvs, 2 ) );
  13874. // functions
  13875. function generateBufferData() {
  13876. for ( let i = 0; i < tubularSegments; i ++ ) {
  13877. generateSegment( i );
  13878. }
  13879. // if the geometry is not closed, generate the last row of vertices and normals
  13880. // at the regular position on the given path
  13881. //
  13882. // if the geometry is closed, duplicate the first row of vertices and normals (uvs will differ)
  13883. generateSegment( ( closed === false ) ? tubularSegments : 0 );
  13884. // uvs are generated in a separate function.
  13885. // this makes it easy compute correct values for closed geometries
  13886. generateUVs();
  13887. // finally create faces
  13888. generateIndices();
  13889. }
  13890. function generateSegment( i ) {
  13891. // we use getPointAt to sample evenly distributed points from the given path
  13892. P = path.getPointAt( i / tubularSegments, P );
  13893. // retrieve corresponding normal and binormal
  13894. const N = frames.normals[ i ];
  13895. const B = frames.binormals[ i ];
  13896. // generate normals and vertices for the current segment
  13897. for ( let j = 0; j <= radialSegments; j ++ ) {
  13898. const v = j / radialSegments * Math.PI * 2;
  13899. const sin = Math.sin( v );
  13900. const cos = - Math.cos( v );
  13901. // normal
  13902. normal.x = ( cos * N.x + sin * B.x );
  13903. normal.y = ( cos * N.y + sin * B.y );
  13904. normal.z = ( cos * N.z + sin * B.z );
  13905. normal.normalize();
  13906. normals.push( normal.x, normal.y, normal.z );
  13907. // vertex
  13908. vertex.x = P.x + radius * normal.x;
  13909. vertex.y = P.y + radius * normal.y;
  13910. vertex.z = P.z + radius * normal.z;
  13911. vertices.push( vertex.x, vertex.y, vertex.z );
  13912. }
  13913. }
  13914. function generateIndices() {
  13915. for ( let j = 1; j <= tubularSegments; j ++ ) {
  13916. for ( let i = 1; i <= radialSegments; i ++ ) {
  13917. const a = ( radialSegments + 1 ) * ( j - 1 ) + ( i - 1 );
  13918. const b = ( radialSegments + 1 ) * j + ( i - 1 );
  13919. const c = ( radialSegments + 1 ) * j + i;
  13920. const d = ( radialSegments + 1 ) * ( j - 1 ) + i;
  13921. // faces
  13922. indices.push( a, b, d );
  13923. indices.push( b, c, d );
  13924. }
  13925. }
  13926. }
  13927. function generateUVs() {
  13928. for ( let i = 0; i <= tubularSegments; i ++ ) {
  13929. for ( let j = 0; j <= radialSegments; j ++ ) {
  13930. uv.x = i / tubularSegments;
  13931. uv.y = j / radialSegments;
  13932. uvs.push( uv.x, uv.y );
  13933. }
  13934. }
  13935. }
  13936. }
  13937. copy( source ) {
  13938. super.copy( source );
  13939. this.parameters = Object.assign( {}, source.parameters );
  13940. return this;
  13941. }
  13942. toJSON() {
  13943. const data = super.toJSON();
  13944. data.path = this.parameters.path.toJSON();
  13945. return data;
  13946. }
  13947. static fromJSON( data ) {
  13948. // This only works for built-in curves (e.g. CatmullRomCurve3).
  13949. // User defined curves or instances of CurvePath will not be deserialized.
  13950. return new TubeGeometry(
  13951. new Curves[ data.path.type ]().fromJSON( data.path ),
  13952. data.tubularSegments,
  13953. data.radius,
  13954. data.radialSegments,
  13955. data.closed
  13956. );
  13957. }
  13958. }
  13959. class WireframeGeometry extends BufferGeometry {
  13960. constructor( geometry = null ) {
  13961. super();
  13962. this.type = 'WireframeGeometry';
  13963. this.parameters = {
  13964. geometry: geometry
  13965. };
  13966. if ( geometry !== null ) {
  13967. // buffer
  13968. const vertices = [];
  13969. const edges = new Set();
  13970. // helper variables
  13971. const start = new Vector3();
  13972. const end = new Vector3();
  13973. if ( geometry.index !== null ) {
  13974. // indexed BufferGeometry
  13975. const position = geometry.attributes.position;
  13976. const indices = geometry.index;
  13977. let groups = geometry.groups;
  13978. if ( groups.length === 0 ) {
  13979. groups = [ { start: 0, count: indices.count, materialIndex: 0 } ];
  13980. }
  13981. // create a data structure that contains all edges without duplicates
  13982. for ( let o = 0, ol = groups.length; o < ol; ++ o ) {
  13983. const group = groups[ o ];
  13984. const groupStart = group.start;
  13985. const groupCount = group.count;
  13986. for ( let i = groupStart, l = ( groupStart + groupCount ); i < l; i += 3 ) {
  13987. for ( let j = 0; j < 3; j ++ ) {
  13988. const index1 = indices.getX( i + j );
  13989. const index2 = indices.getX( i + ( j + 1 ) % 3 );
  13990. start.fromBufferAttribute( position, index1 );
  13991. end.fromBufferAttribute( position, index2 );
  13992. if ( isUniqueEdge( start, end, edges ) === true ) {
  13993. vertices.push( start.x, start.y, start.z );
  13994. vertices.push( end.x, end.y, end.z );
  13995. }
  13996. }
  13997. }
  13998. }
  13999. } else {
  14000. // non-indexed BufferGeometry
  14001. const position = geometry.attributes.position;
  14002. for ( let i = 0, l = ( position.count / 3 ); i < l; i ++ ) {
  14003. for ( let j = 0; j < 3; j ++ ) {
  14004. // three edges per triangle, an edge is represented as (index1, index2)
  14005. // e.g. the first triangle has the following edges: (0,1),(1,2),(2,0)
  14006. const index1 = 3 * i + j;
  14007. const index2 = 3 * i + ( ( j + 1 ) % 3 );
  14008. start.fromBufferAttribute( position, index1 );
  14009. end.fromBufferAttribute( position, index2 );
  14010. if ( isUniqueEdge( start, end, edges ) === true ) {
  14011. vertices.push( start.x, start.y, start.z );
  14012. vertices.push( end.x, end.y, end.z );
  14013. }
  14014. }
  14015. }
  14016. }
  14017. // build geometry
  14018. this.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  14019. }
  14020. }
  14021. copy( source ) {
  14022. super.copy( source );
  14023. this.parameters = Object.assign( {}, source.parameters );
  14024. return this;
  14025. }
  14026. }
  14027. function isUniqueEdge( start, end, edges ) {
  14028. const hash1 = `${start.x},${start.y},${start.z}-${end.x},${end.y},${end.z}`;
  14029. const hash2 = `${end.x},${end.y},${end.z}-${start.x},${start.y},${start.z}`; // coincident edge
  14030. if ( edges.has( hash1 ) === true || edges.has( hash2 ) === true ) {
  14031. return false;
  14032. } else {
  14033. edges.add( hash1 );
  14034. edges.add( hash2 );
  14035. return true;
  14036. }
  14037. }
  14038. var Geometries = /*#__PURE__*/Object.freeze({
  14039. __proto__: null,
  14040. BoxGeometry: BoxGeometry,
  14041. CapsuleGeometry: CapsuleGeometry,
  14042. CircleGeometry: CircleGeometry,
  14043. ConeGeometry: ConeGeometry,
  14044. CylinderGeometry: CylinderGeometry,
  14045. DodecahedronGeometry: DodecahedronGeometry,
  14046. EdgesGeometry: EdgesGeometry,
  14047. ExtrudeGeometry: ExtrudeGeometry,
  14048. IcosahedronGeometry: IcosahedronGeometry,
  14049. LatheGeometry: LatheGeometry,
  14050. OctahedronGeometry: OctahedronGeometry,
  14051. PlaneGeometry: PlaneGeometry,
  14052. PolyhedronGeometry: PolyhedronGeometry,
  14053. RingGeometry: RingGeometry,
  14054. ShapeGeometry: ShapeGeometry,
  14055. SphereGeometry: SphereGeometry,
  14056. TetrahedronGeometry: TetrahedronGeometry,
  14057. TorusGeometry: TorusGeometry,
  14058. TorusKnotGeometry: TorusKnotGeometry,
  14059. TubeGeometry: TubeGeometry,
  14060. WireframeGeometry: WireframeGeometry
  14061. });
  14062. class ShadowMaterial extends Material {
  14063. constructor( parameters ) {
  14064. super();
  14065. this.isShadowMaterial = true;
  14066. this.type = 'ShadowMaterial';
  14067. this.color = new Color( 0x000000 );
  14068. this.transparent = true;
  14069. this.fog = true;
  14070. this.setValues( parameters );
  14071. }
  14072. copy( source ) {
  14073. super.copy( source );
  14074. this.color.copy( source.color );
  14075. this.fog = source.fog;
  14076. return this;
  14077. }
  14078. }
  14079. class RawShaderMaterial extends ShaderMaterial {
  14080. constructor( parameters ) {
  14081. super( parameters );
  14082. this.isRawShaderMaterial = true;
  14083. this.type = 'RawShaderMaterial';
  14084. }
  14085. }
  14086. class MeshStandardMaterial extends Material {
  14087. constructor( parameters ) {
  14088. super();
  14089. this.isMeshStandardMaterial = true;
  14090. this.type = 'MeshStandardMaterial';
  14091. this.defines = { 'STANDARD': '' };
  14092. this.color = new Color( 0xffffff ); // diffuse
  14093. this.roughness = 1.0;
  14094. this.metalness = 0.0;
  14095. this.map = null;
  14096. this.lightMap = null;
  14097. this.lightMapIntensity = 1.0;
  14098. this.aoMap = null;
  14099. this.aoMapIntensity = 1.0;
  14100. this.emissive = new Color( 0x000000 );
  14101. this.emissiveIntensity = 1.0;
  14102. this.emissiveMap = null;
  14103. this.bumpMap = null;
  14104. this.bumpScale = 1;
  14105. this.normalMap = null;
  14106. this.normalMapType = TangentSpaceNormalMap;
  14107. this.normalScale = new Vector2( 1, 1 );
  14108. this.displacementMap = null;
  14109. this.displacementScale = 1;
  14110. this.displacementBias = 0;
  14111. this.roughnessMap = null;
  14112. this.metalnessMap = null;
  14113. this.alphaMap = null;
  14114. this.envMap = null;
  14115. this.envMapRotation = new Euler();
  14116. this.envMapIntensity = 1.0;
  14117. this.wireframe = false;
  14118. this.wireframeLinewidth = 1;
  14119. this.wireframeLinecap = 'round';
  14120. this.wireframeLinejoin = 'round';
  14121. this.flatShading = false;
  14122. this.fog = true;
  14123. this.setValues( parameters );
  14124. }
  14125. copy( source ) {
  14126. super.copy( source );
  14127. this.defines = { 'STANDARD': '' };
  14128. this.color.copy( source.color );
  14129. this.roughness = source.roughness;
  14130. this.metalness = source.metalness;
  14131. this.map = source.map;
  14132. this.lightMap = source.lightMap;
  14133. this.lightMapIntensity = source.lightMapIntensity;
  14134. this.aoMap = source.aoMap;
  14135. this.aoMapIntensity = source.aoMapIntensity;
  14136. this.emissive.copy( source.emissive );
  14137. this.emissiveMap = source.emissiveMap;
  14138. this.emissiveIntensity = source.emissiveIntensity;
  14139. this.bumpMap = source.bumpMap;
  14140. this.bumpScale = source.bumpScale;
  14141. this.normalMap = source.normalMap;
  14142. this.normalMapType = source.normalMapType;
  14143. this.normalScale.copy( source.normalScale );
  14144. this.displacementMap = source.displacementMap;
  14145. this.displacementScale = source.displacementScale;
  14146. this.displacementBias = source.displacementBias;
  14147. this.roughnessMap = source.roughnessMap;
  14148. this.metalnessMap = source.metalnessMap;
  14149. this.alphaMap = source.alphaMap;
  14150. this.envMap = source.envMap;
  14151. this.envMapRotation.copy( source.envMapRotation );
  14152. this.envMapIntensity = source.envMapIntensity;
  14153. this.wireframe = source.wireframe;
  14154. this.wireframeLinewidth = source.wireframeLinewidth;
  14155. this.wireframeLinecap = source.wireframeLinecap;
  14156. this.wireframeLinejoin = source.wireframeLinejoin;
  14157. this.flatShading = source.flatShading;
  14158. this.fog = source.fog;
  14159. return this;
  14160. }
  14161. }
  14162. class MeshPhysicalMaterial extends MeshStandardMaterial {
  14163. constructor( parameters ) {
  14164. super();
  14165. this.isMeshPhysicalMaterial = true;
  14166. this.defines = {
  14167. 'STANDARD': '',
  14168. 'PHYSICAL': ''
  14169. };
  14170. this.type = 'MeshPhysicalMaterial';
  14171. this.anisotropyRotation = 0;
  14172. this.anisotropyMap = null;
  14173. this.clearcoatMap = null;
  14174. this.clearcoatRoughness = 0.0;
  14175. this.clearcoatRoughnessMap = null;
  14176. this.clearcoatNormalScale = new Vector2( 1, 1 );
  14177. this.clearcoatNormalMap = null;
  14178. this.ior = 1.5;
  14179. Object.defineProperty( this, 'reflectivity', {
  14180. get: function () {
  14181. return ( clamp( 2.5 * ( this.ior - 1 ) / ( this.ior + 1 ), 0, 1 ) );
  14182. },
  14183. set: function ( reflectivity ) {
  14184. this.ior = ( 1 + 0.4 * reflectivity ) / ( 1 - 0.4 * reflectivity );
  14185. }
  14186. } );
  14187. this.iridescenceMap = null;
  14188. this.iridescenceIOR = 1.3;
  14189. this.iridescenceThicknessRange = [ 100, 400 ];
  14190. this.iridescenceThicknessMap = null;
  14191. this.sheenColor = new Color( 0x000000 );
  14192. this.sheenColorMap = null;
  14193. this.sheenRoughness = 1.0;
  14194. this.sheenRoughnessMap = null;
  14195. this.transmissionMap = null;
  14196. this.thickness = 0;
  14197. this.thicknessMap = null;
  14198. this.attenuationDistance = Infinity;
  14199. this.attenuationColor = new Color( 1, 1, 1 );
  14200. this.specularIntensity = 1.0;
  14201. this.specularIntensityMap = null;
  14202. this.specularColor = new Color( 1, 1, 1 );
  14203. this.specularColorMap = null;
  14204. this._anisotropy = 0;
  14205. this._clearcoat = 0;
  14206. this._dispersion = 0;
  14207. this._iridescence = 0;
  14208. this._sheen = 0.0;
  14209. this._transmission = 0;
  14210. this.setValues( parameters );
  14211. }
  14212. get anisotropy() {
  14213. return this._anisotropy;
  14214. }
  14215. set anisotropy( value ) {
  14216. if ( this._anisotropy > 0 !== value > 0 ) {
  14217. this.version ++;
  14218. }
  14219. this._anisotropy = value;
  14220. }
  14221. get clearcoat() {
  14222. return this._clearcoat;
  14223. }
  14224. set clearcoat( value ) {
  14225. if ( this._clearcoat > 0 !== value > 0 ) {
  14226. this.version ++;
  14227. }
  14228. this._clearcoat = value;
  14229. }
  14230. get iridescence() {
  14231. return this._iridescence;
  14232. }
  14233. set iridescence( value ) {
  14234. if ( this._iridescence > 0 !== value > 0 ) {
  14235. this.version ++;
  14236. }
  14237. this._iridescence = value;
  14238. }
  14239. get dispersion() {
  14240. return this._dispersion;
  14241. }
  14242. set dispersion( value ) {
  14243. if ( this._dispersion > 0 !== value > 0 ) {
  14244. this.version ++;
  14245. }
  14246. this._dispersion = value;
  14247. }
  14248. get sheen() {
  14249. return this._sheen;
  14250. }
  14251. set sheen( value ) {
  14252. if ( this._sheen > 0 !== value > 0 ) {
  14253. this.version ++;
  14254. }
  14255. this._sheen = value;
  14256. }
  14257. get transmission() {
  14258. return this._transmission;
  14259. }
  14260. set transmission( value ) {
  14261. if ( this._transmission > 0 !== value > 0 ) {
  14262. this.version ++;
  14263. }
  14264. this._transmission = value;
  14265. }
  14266. copy( source ) {
  14267. super.copy( source );
  14268. this.defines = {
  14269. 'STANDARD': '',
  14270. 'PHYSICAL': ''
  14271. };
  14272. this.anisotropy = source.anisotropy;
  14273. this.anisotropyRotation = source.anisotropyRotation;
  14274. this.anisotropyMap = source.anisotropyMap;
  14275. this.clearcoat = source.clearcoat;
  14276. this.clearcoatMap = source.clearcoatMap;
  14277. this.clearcoatRoughness = source.clearcoatRoughness;
  14278. this.clearcoatRoughnessMap = source.clearcoatRoughnessMap;
  14279. this.clearcoatNormalMap = source.clearcoatNormalMap;
  14280. this.clearcoatNormalScale.copy( source.clearcoatNormalScale );
  14281. this.dispersion = source.dispersion;
  14282. this.ior = source.ior;
  14283. this.iridescence = source.iridescence;
  14284. this.iridescenceMap = source.iridescenceMap;
  14285. this.iridescenceIOR = source.iridescenceIOR;
  14286. this.iridescenceThicknessRange = [ ...source.iridescenceThicknessRange ];
  14287. this.iridescenceThicknessMap = source.iridescenceThicknessMap;
  14288. this.sheen = source.sheen;
  14289. this.sheenColor.copy( source.sheenColor );
  14290. this.sheenColorMap = source.sheenColorMap;
  14291. this.sheenRoughness = source.sheenRoughness;
  14292. this.sheenRoughnessMap = source.sheenRoughnessMap;
  14293. this.transmission = source.transmission;
  14294. this.transmissionMap = source.transmissionMap;
  14295. this.thickness = source.thickness;
  14296. this.thicknessMap = source.thicknessMap;
  14297. this.attenuationDistance = source.attenuationDistance;
  14298. this.attenuationColor.copy( source.attenuationColor );
  14299. this.specularIntensity = source.specularIntensity;
  14300. this.specularIntensityMap = source.specularIntensityMap;
  14301. this.specularColor.copy( source.specularColor );
  14302. this.specularColorMap = source.specularColorMap;
  14303. return this;
  14304. }
  14305. }
  14306. class MeshPhongMaterial extends Material {
  14307. constructor( parameters ) {
  14308. super();
  14309. this.isMeshPhongMaterial = true;
  14310. this.type = 'MeshPhongMaterial';
  14311. this.color = new Color( 0xffffff ); // diffuse
  14312. this.specular = new Color( 0x111111 );
  14313. this.shininess = 30;
  14314. this.map = null;
  14315. this.lightMap = null;
  14316. this.lightMapIntensity = 1.0;
  14317. this.aoMap = null;
  14318. this.aoMapIntensity = 1.0;
  14319. this.emissive = new Color( 0x000000 );
  14320. this.emissiveIntensity = 1.0;
  14321. this.emissiveMap = null;
  14322. this.bumpMap = null;
  14323. this.bumpScale = 1;
  14324. this.normalMap = null;
  14325. this.normalMapType = TangentSpaceNormalMap;
  14326. this.normalScale = new Vector2( 1, 1 );
  14327. this.displacementMap = null;
  14328. this.displacementScale = 1;
  14329. this.displacementBias = 0;
  14330. this.specularMap = null;
  14331. this.alphaMap = null;
  14332. this.envMap = null;
  14333. this.envMapRotation = new Euler();
  14334. this.combine = MultiplyOperation;
  14335. this.reflectivity = 1;
  14336. this.refractionRatio = 0.98;
  14337. this.wireframe = false;
  14338. this.wireframeLinewidth = 1;
  14339. this.wireframeLinecap = 'round';
  14340. this.wireframeLinejoin = 'round';
  14341. this.flatShading = false;
  14342. this.fog = true;
  14343. this.setValues( parameters );
  14344. }
  14345. copy( source ) {
  14346. super.copy( source );
  14347. this.color.copy( source.color );
  14348. this.specular.copy( source.specular );
  14349. this.shininess = source.shininess;
  14350. this.map = source.map;
  14351. this.lightMap = source.lightMap;
  14352. this.lightMapIntensity = source.lightMapIntensity;
  14353. this.aoMap = source.aoMap;
  14354. this.aoMapIntensity = source.aoMapIntensity;
  14355. this.emissive.copy( source.emissive );
  14356. this.emissiveMap = source.emissiveMap;
  14357. this.emissiveIntensity = source.emissiveIntensity;
  14358. this.bumpMap = source.bumpMap;
  14359. this.bumpScale = source.bumpScale;
  14360. this.normalMap = source.normalMap;
  14361. this.normalMapType = source.normalMapType;
  14362. this.normalScale.copy( source.normalScale );
  14363. this.displacementMap = source.displacementMap;
  14364. this.displacementScale = source.displacementScale;
  14365. this.displacementBias = source.displacementBias;
  14366. this.specularMap = source.specularMap;
  14367. this.alphaMap = source.alphaMap;
  14368. this.envMap = source.envMap;
  14369. this.envMapRotation.copy( source.envMapRotation );
  14370. this.combine = source.combine;
  14371. this.reflectivity = source.reflectivity;
  14372. this.refractionRatio = source.refractionRatio;
  14373. this.wireframe = source.wireframe;
  14374. this.wireframeLinewidth = source.wireframeLinewidth;
  14375. this.wireframeLinecap = source.wireframeLinecap;
  14376. this.wireframeLinejoin = source.wireframeLinejoin;
  14377. this.flatShading = source.flatShading;
  14378. this.fog = source.fog;
  14379. return this;
  14380. }
  14381. }
  14382. class MeshToonMaterial extends Material {
  14383. constructor( parameters ) {
  14384. super();
  14385. this.isMeshToonMaterial = true;
  14386. this.defines = { 'TOON': '' };
  14387. this.type = 'MeshToonMaterial';
  14388. this.color = new Color( 0xffffff );
  14389. this.map = null;
  14390. this.gradientMap = null;
  14391. this.lightMap = null;
  14392. this.lightMapIntensity = 1.0;
  14393. this.aoMap = null;
  14394. this.aoMapIntensity = 1.0;
  14395. this.emissive = new Color( 0x000000 );
  14396. this.emissiveIntensity = 1.0;
  14397. this.emissiveMap = null;
  14398. this.bumpMap = null;
  14399. this.bumpScale = 1;
  14400. this.normalMap = null;
  14401. this.normalMapType = TangentSpaceNormalMap;
  14402. this.normalScale = new Vector2( 1, 1 );
  14403. this.displacementMap = null;
  14404. this.displacementScale = 1;
  14405. this.displacementBias = 0;
  14406. this.alphaMap = null;
  14407. this.wireframe = false;
  14408. this.wireframeLinewidth = 1;
  14409. this.wireframeLinecap = 'round';
  14410. this.wireframeLinejoin = 'round';
  14411. this.fog = true;
  14412. this.setValues( parameters );
  14413. }
  14414. copy( source ) {
  14415. super.copy( source );
  14416. this.color.copy( source.color );
  14417. this.map = source.map;
  14418. this.gradientMap = source.gradientMap;
  14419. this.lightMap = source.lightMap;
  14420. this.lightMapIntensity = source.lightMapIntensity;
  14421. this.aoMap = source.aoMap;
  14422. this.aoMapIntensity = source.aoMapIntensity;
  14423. this.emissive.copy( source.emissive );
  14424. this.emissiveMap = source.emissiveMap;
  14425. this.emissiveIntensity = source.emissiveIntensity;
  14426. this.bumpMap = source.bumpMap;
  14427. this.bumpScale = source.bumpScale;
  14428. this.normalMap = source.normalMap;
  14429. this.normalMapType = source.normalMapType;
  14430. this.normalScale.copy( source.normalScale );
  14431. this.displacementMap = source.displacementMap;
  14432. this.displacementScale = source.displacementScale;
  14433. this.displacementBias = source.displacementBias;
  14434. this.alphaMap = source.alphaMap;
  14435. this.wireframe = source.wireframe;
  14436. this.wireframeLinewidth = source.wireframeLinewidth;
  14437. this.wireframeLinecap = source.wireframeLinecap;
  14438. this.wireframeLinejoin = source.wireframeLinejoin;
  14439. this.fog = source.fog;
  14440. return this;
  14441. }
  14442. }
  14443. class MeshNormalMaterial extends Material {
  14444. constructor( parameters ) {
  14445. super();
  14446. this.isMeshNormalMaterial = true;
  14447. this.type = 'MeshNormalMaterial';
  14448. this.bumpMap = null;
  14449. this.bumpScale = 1;
  14450. this.normalMap = null;
  14451. this.normalMapType = TangentSpaceNormalMap;
  14452. this.normalScale = new Vector2( 1, 1 );
  14453. this.displacementMap = null;
  14454. this.displacementScale = 1;
  14455. this.displacementBias = 0;
  14456. this.wireframe = false;
  14457. this.wireframeLinewidth = 1;
  14458. this.flatShading = false;
  14459. this.setValues( parameters );
  14460. }
  14461. copy( source ) {
  14462. super.copy( source );
  14463. this.bumpMap = source.bumpMap;
  14464. this.bumpScale = source.bumpScale;
  14465. this.normalMap = source.normalMap;
  14466. this.normalMapType = source.normalMapType;
  14467. this.normalScale.copy( source.normalScale );
  14468. this.displacementMap = source.displacementMap;
  14469. this.displacementScale = source.displacementScale;
  14470. this.displacementBias = source.displacementBias;
  14471. this.wireframe = source.wireframe;
  14472. this.wireframeLinewidth = source.wireframeLinewidth;
  14473. this.flatShading = source.flatShading;
  14474. return this;
  14475. }
  14476. }
  14477. class MeshLambertMaterial extends Material {
  14478. constructor( parameters ) {
  14479. super();
  14480. this.isMeshLambertMaterial = true;
  14481. this.type = 'MeshLambertMaterial';
  14482. this.color = new Color( 0xffffff ); // diffuse
  14483. this.map = null;
  14484. this.lightMap = null;
  14485. this.lightMapIntensity = 1.0;
  14486. this.aoMap = null;
  14487. this.aoMapIntensity = 1.0;
  14488. this.emissive = new Color( 0x000000 );
  14489. this.emissiveIntensity = 1.0;
  14490. this.emissiveMap = null;
  14491. this.bumpMap = null;
  14492. this.bumpScale = 1;
  14493. this.normalMap = null;
  14494. this.normalMapType = TangentSpaceNormalMap;
  14495. this.normalScale = new Vector2( 1, 1 );
  14496. this.displacementMap = null;
  14497. this.displacementScale = 1;
  14498. this.displacementBias = 0;
  14499. this.specularMap = null;
  14500. this.alphaMap = null;
  14501. this.envMap = null;
  14502. this.envMapRotation = new Euler();
  14503. this.combine = MultiplyOperation;
  14504. this.reflectivity = 1;
  14505. this.refractionRatio = 0.98;
  14506. this.wireframe = false;
  14507. this.wireframeLinewidth = 1;
  14508. this.wireframeLinecap = 'round';
  14509. this.wireframeLinejoin = 'round';
  14510. this.flatShading = false;
  14511. this.fog = true;
  14512. this.setValues( parameters );
  14513. }
  14514. copy( source ) {
  14515. super.copy( source );
  14516. this.color.copy( source.color );
  14517. this.map = source.map;
  14518. this.lightMap = source.lightMap;
  14519. this.lightMapIntensity = source.lightMapIntensity;
  14520. this.aoMap = source.aoMap;
  14521. this.aoMapIntensity = source.aoMapIntensity;
  14522. this.emissive.copy( source.emissive );
  14523. this.emissiveMap = source.emissiveMap;
  14524. this.emissiveIntensity = source.emissiveIntensity;
  14525. this.bumpMap = source.bumpMap;
  14526. this.bumpScale = source.bumpScale;
  14527. this.normalMap = source.normalMap;
  14528. this.normalMapType = source.normalMapType;
  14529. this.normalScale.copy( source.normalScale );
  14530. this.displacementMap = source.displacementMap;
  14531. this.displacementScale = source.displacementScale;
  14532. this.displacementBias = source.displacementBias;
  14533. this.specularMap = source.specularMap;
  14534. this.alphaMap = source.alphaMap;
  14535. this.envMap = source.envMap;
  14536. this.envMapRotation.copy( source.envMapRotation );
  14537. this.combine = source.combine;
  14538. this.reflectivity = source.reflectivity;
  14539. this.refractionRatio = source.refractionRatio;
  14540. this.wireframe = source.wireframe;
  14541. this.wireframeLinewidth = source.wireframeLinewidth;
  14542. this.wireframeLinecap = source.wireframeLinecap;
  14543. this.wireframeLinejoin = source.wireframeLinejoin;
  14544. this.flatShading = source.flatShading;
  14545. this.fog = source.fog;
  14546. return this;
  14547. }
  14548. }
  14549. class MeshDepthMaterial extends Material {
  14550. constructor( parameters ) {
  14551. super();
  14552. this.isMeshDepthMaterial = true;
  14553. this.type = 'MeshDepthMaterial';
  14554. this.depthPacking = BasicDepthPacking;
  14555. this.map = null;
  14556. this.alphaMap = null;
  14557. this.displacementMap = null;
  14558. this.displacementScale = 1;
  14559. this.displacementBias = 0;
  14560. this.wireframe = false;
  14561. this.wireframeLinewidth = 1;
  14562. this.setValues( parameters );
  14563. }
  14564. copy( source ) {
  14565. super.copy( source );
  14566. this.depthPacking = source.depthPacking;
  14567. this.map = source.map;
  14568. this.alphaMap = source.alphaMap;
  14569. this.displacementMap = source.displacementMap;
  14570. this.displacementScale = source.displacementScale;
  14571. this.displacementBias = source.displacementBias;
  14572. this.wireframe = source.wireframe;
  14573. this.wireframeLinewidth = source.wireframeLinewidth;
  14574. return this;
  14575. }
  14576. }
  14577. class MeshDistanceMaterial extends Material {
  14578. constructor( parameters ) {
  14579. super();
  14580. this.isMeshDistanceMaterial = true;
  14581. this.type = 'MeshDistanceMaterial';
  14582. this.map = null;
  14583. this.alphaMap = null;
  14584. this.displacementMap = null;
  14585. this.displacementScale = 1;
  14586. this.displacementBias = 0;
  14587. this.setValues( parameters );
  14588. }
  14589. copy( source ) {
  14590. super.copy( source );
  14591. this.map = source.map;
  14592. this.alphaMap = source.alphaMap;
  14593. this.displacementMap = source.displacementMap;
  14594. this.displacementScale = source.displacementScale;
  14595. this.displacementBias = source.displacementBias;
  14596. return this;
  14597. }
  14598. }
  14599. class MeshMatcapMaterial extends Material {
  14600. constructor( parameters ) {
  14601. super();
  14602. this.isMeshMatcapMaterial = true;
  14603. this.defines = { 'MATCAP': '' };
  14604. this.type = 'MeshMatcapMaterial';
  14605. this.color = new Color( 0xffffff ); // diffuse
  14606. this.matcap = null;
  14607. this.map = null;
  14608. this.bumpMap = null;
  14609. this.bumpScale = 1;
  14610. this.normalMap = null;
  14611. this.normalMapType = TangentSpaceNormalMap;
  14612. this.normalScale = new Vector2( 1, 1 );
  14613. this.displacementMap = null;
  14614. this.displacementScale = 1;
  14615. this.displacementBias = 0;
  14616. this.alphaMap = null;
  14617. this.flatShading = false;
  14618. this.fog = true;
  14619. this.setValues( parameters );
  14620. }
  14621. copy( source ) {
  14622. super.copy( source );
  14623. this.defines = { 'MATCAP': '' };
  14624. this.color.copy( source.color );
  14625. this.matcap = source.matcap;
  14626. this.map = source.map;
  14627. this.bumpMap = source.bumpMap;
  14628. this.bumpScale = source.bumpScale;
  14629. this.normalMap = source.normalMap;
  14630. this.normalMapType = source.normalMapType;
  14631. this.normalScale.copy( source.normalScale );
  14632. this.displacementMap = source.displacementMap;
  14633. this.displacementScale = source.displacementScale;
  14634. this.displacementBias = source.displacementBias;
  14635. this.alphaMap = source.alphaMap;
  14636. this.flatShading = source.flatShading;
  14637. this.fog = source.fog;
  14638. return this;
  14639. }
  14640. }
  14641. class LineDashedMaterial extends LineBasicMaterial {
  14642. constructor( parameters ) {
  14643. super();
  14644. this.isLineDashedMaterial = true;
  14645. this.type = 'LineDashedMaterial';
  14646. this.scale = 1;
  14647. this.dashSize = 3;
  14648. this.gapSize = 1;
  14649. this.setValues( parameters );
  14650. }
  14651. copy( source ) {
  14652. super.copy( source );
  14653. this.scale = source.scale;
  14654. this.dashSize = source.dashSize;
  14655. this.gapSize = source.gapSize;
  14656. return this;
  14657. }
  14658. }
  14659. // converts an array to a specific type
  14660. function convertArray( array, type, forceClone ) {
  14661. if ( ! array || // let 'undefined' and 'null' pass
  14662. ! forceClone && array.constructor === type ) return array;
  14663. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  14664. return new type( array ); // create typed array
  14665. }
  14666. return Array.prototype.slice.call( array ); // create Array
  14667. }
  14668. function isTypedArray( object ) {
  14669. return ArrayBuffer.isView( object ) &&
  14670. ! ( object instanceof DataView );
  14671. }
  14672. // returns an array by which times and values can be sorted
  14673. function getKeyframeOrder( times ) {
  14674. function compareTime( i, j ) {
  14675. return times[ i ] - times[ j ];
  14676. }
  14677. const n = times.length;
  14678. const result = new Array( n );
  14679. for ( let i = 0; i !== n; ++ i ) result[ i ] = i;
  14680. result.sort( compareTime );
  14681. return result;
  14682. }
  14683. // uses the array previously returned by 'getKeyframeOrder' to sort data
  14684. function sortedArray( values, stride, order ) {
  14685. const nValues = values.length;
  14686. const result = new values.constructor( nValues );
  14687. for ( let i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  14688. const srcOffset = order[ i ] * stride;
  14689. for ( let j = 0; j !== stride; ++ j ) {
  14690. result[ dstOffset ++ ] = values[ srcOffset + j ];
  14691. }
  14692. }
  14693. return result;
  14694. }
  14695. // function for parsing AOS keyframe formats
  14696. function flattenJSON( jsonKeys, times, values, valuePropertyName ) {
  14697. let i = 1, key = jsonKeys[ 0 ];
  14698. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  14699. key = jsonKeys[ i ++ ];
  14700. }
  14701. if ( key === undefined ) return; // no data
  14702. let value = key[ valuePropertyName ];
  14703. if ( value === undefined ) return; // no data
  14704. if ( Array.isArray( value ) ) {
  14705. do {
  14706. value = key[ valuePropertyName ];
  14707. if ( value !== undefined ) {
  14708. times.push( key.time );
  14709. values.push.apply( values, value ); // push all elements
  14710. }
  14711. key = jsonKeys[ i ++ ];
  14712. } while ( key !== undefined );
  14713. } else if ( value.toArray !== undefined ) {
  14714. // ...assume THREE.Math-ish
  14715. do {
  14716. value = key[ valuePropertyName ];
  14717. if ( value !== undefined ) {
  14718. times.push( key.time );
  14719. value.toArray( values, values.length );
  14720. }
  14721. key = jsonKeys[ i ++ ];
  14722. } while ( key !== undefined );
  14723. } else {
  14724. // otherwise push as-is
  14725. do {
  14726. value = key[ valuePropertyName ];
  14727. if ( value !== undefined ) {
  14728. times.push( key.time );
  14729. values.push( value );
  14730. }
  14731. key = jsonKeys[ i ++ ];
  14732. } while ( key !== undefined );
  14733. }
  14734. }
  14735. function subclip( sourceClip, name, startFrame, endFrame, fps = 30 ) {
  14736. const clip = sourceClip.clone();
  14737. clip.name = name;
  14738. const tracks = [];
  14739. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14740. const track = clip.tracks[ i ];
  14741. const valueSize = track.getValueSize();
  14742. const times = [];
  14743. const values = [];
  14744. for ( let j = 0; j < track.times.length; ++ j ) {
  14745. const frame = track.times[ j ] * fps;
  14746. if ( frame < startFrame || frame >= endFrame ) continue;
  14747. times.push( track.times[ j ] );
  14748. for ( let k = 0; k < valueSize; ++ k ) {
  14749. values.push( track.values[ j * valueSize + k ] );
  14750. }
  14751. }
  14752. if ( times.length === 0 ) continue;
  14753. track.times = convertArray( times, track.times.constructor );
  14754. track.values = convertArray( values, track.values.constructor );
  14755. tracks.push( track );
  14756. }
  14757. clip.tracks = tracks;
  14758. // find minimum .times value across all tracks in the trimmed clip
  14759. let minStartTime = Infinity;
  14760. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14761. if ( minStartTime > clip.tracks[ i ].times[ 0 ] ) {
  14762. minStartTime = clip.tracks[ i ].times[ 0 ];
  14763. }
  14764. }
  14765. // shift all tracks such that clip begins at t=0
  14766. for ( let i = 0; i < clip.tracks.length; ++ i ) {
  14767. clip.tracks[ i ].shift( - 1 * minStartTime );
  14768. }
  14769. clip.resetDuration();
  14770. return clip;
  14771. }
  14772. function makeClipAdditive( targetClip, referenceFrame = 0, referenceClip = targetClip, fps = 30 ) {
  14773. if ( fps <= 0 ) fps = 30;
  14774. const numTracks = referenceClip.tracks.length;
  14775. const referenceTime = referenceFrame / fps;
  14776. // Make each track's values relative to the values at the reference frame
  14777. for ( let i = 0; i < numTracks; ++ i ) {
  14778. const referenceTrack = referenceClip.tracks[ i ];
  14779. const referenceTrackType = referenceTrack.ValueTypeName;
  14780. // Skip this track if it's non-numeric
  14781. if ( referenceTrackType === 'bool' || referenceTrackType === 'string' ) continue;
  14782. // Find the track in the target clip whose name and type matches the reference track
  14783. const targetTrack = targetClip.tracks.find( function ( track ) {
  14784. return track.name === referenceTrack.name
  14785. && track.ValueTypeName === referenceTrackType;
  14786. } );
  14787. if ( targetTrack === undefined ) continue;
  14788. let referenceOffset = 0;
  14789. const referenceValueSize = referenceTrack.getValueSize();
  14790. if ( referenceTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14791. referenceOffset = referenceValueSize / 3;
  14792. }
  14793. let targetOffset = 0;
  14794. const targetValueSize = targetTrack.getValueSize();
  14795. if ( targetTrack.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline ) {
  14796. targetOffset = targetValueSize / 3;
  14797. }
  14798. const lastIndex = referenceTrack.times.length - 1;
  14799. let referenceValue;
  14800. // Find the value to subtract out of the track
  14801. if ( referenceTime <= referenceTrack.times[ 0 ] ) {
  14802. // Reference frame is earlier than the first keyframe, so just use the first keyframe
  14803. const startIndex = referenceOffset;
  14804. const endIndex = referenceValueSize - referenceOffset;
  14805. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14806. } else if ( referenceTime >= referenceTrack.times[ lastIndex ] ) {
  14807. // Reference frame is after the last keyframe, so just use the last keyframe
  14808. const startIndex = lastIndex * referenceValueSize + referenceOffset;
  14809. const endIndex = startIndex + referenceValueSize - referenceOffset;
  14810. referenceValue = referenceTrack.values.slice( startIndex, endIndex );
  14811. } else {
  14812. // Interpolate to the reference value
  14813. const interpolant = referenceTrack.createInterpolant();
  14814. const startIndex = referenceOffset;
  14815. const endIndex = referenceValueSize - referenceOffset;
  14816. interpolant.evaluate( referenceTime );
  14817. referenceValue = interpolant.resultBuffer.slice( startIndex, endIndex );
  14818. }
  14819. // Conjugate the quaternion
  14820. if ( referenceTrackType === 'quaternion' ) {
  14821. const referenceQuat = new Quaternion().fromArray( referenceValue ).normalize().conjugate();
  14822. referenceQuat.toArray( referenceValue );
  14823. }
  14824. // Subtract the reference value from all of the track values
  14825. const numTimes = targetTrack.times.length;
  14826. for ( let j = 0; j < numTimes; ++ j ) {
  14827. const valueStart = j * targetValueSize + targetOffset;
  14828. if ( referenceTrackType === 'quaternion' ) {
  14829. // Multiply the conjugate for quaternion track types
  14830. Quaternion.multiplyQuaternionsFlat(
  14831. targetTrack.values,
  14832. valueStart,
  14833. referenceValue,
  14834. 0,
  14835. targetTrack.values,
  14836. valueStart
  14837. );
  14838. } else {
  14839. const valueEnd = targetValueSize - targetOffset * 2;
  14840. // Subtract each value for all other numeric track types
  14841. for ( let k = 0; k < valueEnd; ++ k ) {
  14842. targetTrack.values[ valueStart + k ] -= referenceValue[ k ];
  14843. }
  14844. }
  14845. }
  14846. }
  14847. targetClip.blendMode = AdditiveAnimationBlendMode;
  14848. return targetClip;
  14849. }
  14850. const AnimationUtils = {
  14851. convertArray: convertArray,
  14852. isTypedArray: isTypedArray,
  14853. getKeyframeOrder: getKeyframeOrder,
  14854. sortedArray: sortedArray,
  14855. flattenJSON: flattenJSON,
  14856. subclip: subclip,
  14857. makeClipAdditive: makeClipAdditive
  14858. };
  14859. /**
  14860. * Abstract base class of interpolants over parametric samples.
  14861. *
  14862. * The parameter domain is one dimensional, typically the time or a path
  14863. * along a curve defined by the data.
  14864. *
  14865. * The sample values can have any dimensionality and derived classes may
  14866. * apply special interpretations to the data.
  14867. *
  14868. * This class provides the interval seek in a Template Method, deferring
  14869. * the actual interpolation to derived classes.
  14870. *
  14871. * Time complexity is O(1) for linear access crossing at most two points
  14872. * and O(log N) for random access, where N is the number of positions.
  14873. *
  14874. * References:
  14875. *
  14876. * http://www.oodesign.com/template-method-pattern.html
  14877. *
  14878. */
  14879. class Interpolant {
  14880. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  14881. this.parameterPositions = parameterPositions;
  14882. this._cachedIndex = 0;
  14883. this.resultBuffer = resultBuffer !== undefined ?
  14884. resultBuffer : new sampleValues.constructor( sampleSize );
  14885. this.sampleValues = sampleValues;
  14886. this.valueSize = sampleSize;
  14887. this.settings = null;
  14888. this.DefaultSettings_ = {};
  14889. }
  14890. evaluate( t ) {
  14891. const pp = this.parameterPositions;
  14892. let i1 = this._cachedIndex,
  14893. t1 = pp[ i1 ],
  14894. t0 = pp[ i1 - 1 ];
  14895. validate_interval: {
  14896. seek: {
  14897. let right;
  14898. linear_scan: {
  14899. //- See http://jsperf.com/comparison-to-undefined/3
  14900. //- slower code:
  14901. //-
  14902. //- if ( t >= t1 || t1 === undefined ) {
  14903. forward_scan: if ( ! ( t < t1 ) ) {
  14904. for ( let giveUpAt = i1 + 2; ; ) {
  14905. if ( t1 === undefined ) {
  14906. if ( t < t0 ) break forward_scan;
  14907. // after end
  14908. i1 = pp.length;
  14909. this._cachedIndex = i1;
  14910. return this.copySampleValue_( i1 - 1 );
  14911. }
  14912. if ( i1 === giveUpAt ) break; // this loop
  14913. t0 = t1;
  14914. t1 = pp[ ++ i1 ];
  14915. if ( t < t1 ) {
  14916. // we have arrived at the sought interval
  14917. break seek;
  14918. }
  14919. }
  14920. // prepare binary search on the right side of the index
  14921. right = pp.length;
  14922. break linear_scan;
  14923. }
  14924. //- slower code:
  14925. //- if ( t < t0 || t0 === undefined ) {
  14926. if ( ! ( t >= t0 ) ) {
  14927. // looping?
  14928. const t1global = pp[ 1 ];
  14929. if ( t < t1global ) {
  14930. i1 = 2; // + 1, using the scan for the details
  14931. t0 = t1global;
  14932. }
  14933. // linear reverse scan
  14934. for ( let giveUpAt = i1 - 2; ; ) {
  14935. if ( t0 === undefined ) {
  14936. // before start
  14937. this._cachedIndex = 0;
  14938. return this.copySampleValue_( 0 );
  14939. }
  14940. if ( i1 === giveUpAt ) break; // this loop
  14941. t1 = t0;
  14942. t0 = pp[ -- i1 - 1 ];
  14943. if ( t >= t0 ) {
  14944. // we have arrived at the sought interval
  14945. break seek;
  14946. }
  14947. }
  14948. // prepare binary search on the left side of the index
  14949. right = i1;
  14950. i1 = 0;
  14951. break linear_scan;
  14952. }
  14953. // the interval is valid
  14954. break validate_interval;
  14955. } // linear scan
  14956. // binary search
  14957. while ( i1 < right ) {
  14958. const mid = ( i1 + right ) >>> 1;
  14959. if ( t < pp[ mid ] ) {
  14960. right = mid;
  14961. } else {
  14962. i1 = mid + 1;
  14963. }
  14964. }
  14965. t1 = pp[ i1 ];
  14966. t0 = pp[ i1 - 1 ];
  14967. // check boundary cases, again
  14968. if ( t0 === undefined ) {
  14969. this._cachedIndex = 0;
  14970. return this.copySampleValue_( 0 );
  14971. }
  14972. if ( t1 === undefined ) {
  14973. i1 = pp.length;
  14974. this._cachedIndex = i1;
  14975. return this.copySampleValue_( i1 - 1 );
  14976. }
  14977. } // seek
  14978. this._cachedIndex = i1;
  14979. this.intervalChanged_( i1, t0, t1 );
  14980. } // validate_interval
  14981. return this.interpolate_( i1, t0, t, t1 );
  14982. }
  14983. getSettings_() {
  14984. return this.settings || this.DefaultSettings_;
  14985. }
  14986. copySampleValue_( index ) {
  14987. // copies a sample value to the result buffer
  14988. const result = this.resultBuffer,
  14989. values = this.sampleValues,
  14990. stride = this.valueSize,
  14991. offset = index * stride;
  14992. for ( let i = 0; i !== stride; ++ i ) {
  14993. result[ i ] = values[ offset + i ];
  14994. }
  14995. return result;
  14996. }
  14997. // Template methods for derived classes:
  14998. interpolate_( /* i1, t0, t, t1 */ ) {
  14999. throw new Error( 'call to abstract method' );
  15000. // implementations shall return this.resultBuffer
  15001. }
  15002. intervalChanged_( /* i1, t0, t1 */ ) {
  15003. // empty
  15004. }
  15005. }
  15006. /**
  15007. * Fast and simple cubic spline interpolant.
  15008. *
  15009. * It was derived from a Hermitian construction setting the first derivative
  15010. * at each sample position to the linear slope between neighboring positions
  15011. * over their parameter interval.
  15012. */
  15013. class CubicInterpolant extends Interpolant {
  15014. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15015. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15016. this._weightPrev = - 0;
  15017. this._offsetPrev = - 0;
  15018. this._weightNext = - 0;
  15019. this._offsetNext = - 0;
  15020. this.DefaultSettings_ = {
  15021. endingStart: ZeroCurvatureEnding,
  15022. endingEnd: ZeroCurvatureEnding
  15023. };
  15024. }
  15025. intervalChanged_( i1, t0, t1 ) {
  15026. const pp = this.parameterPositions;
  15027. let iPrev = i1 - 2,
  15028. iNext = i1 + 1,
  15029. tPrev = pp[ iPrev ],
  15030. tNext = pp[ iNext ];
  15031. if ( tPrev === undefined ) {
  15032. switch ( this.getSettings_().endingStart ) {
  15033. case ZeroSlopeEnding:
  15034. // f'(t0) = 0
  15035. iPrev = i1;
  15036. tPrev = 2 * t0 - t1;
  15037. break;
  15038. case WrapAroundEnding:
  15039. // use the other end of the curve
  15040. iPrev = pp.length - 2;
  15041. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  15042. break;
  15043. default: // ZeroCurvatureEnding
  15044. // f''(t0) = 0 a.k.a. Natural Spline
  15045. iPrev = i1;
  15046. tPrev = t1;
  15047. }
  15048. }
  15049. if ( tNext === undefined ) {
  15050. switch ( this.getSettings_().endingEnd ) {
  15051. case ZeroSlopeEnding:
  15052. // f'(tN) = 0
  15053. iNext = i1;
  15054. tNext = 2 * t1 - t0;
  15055. break;
  15056. case WrapAroundEnding:
  15057. // use the other end of the curve
  15058. iNext = 1;
  15059. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  15060. break;
  15061. default: // ZeroCurvatureEnding
  15062. // f''(tN) = 0, a.k.a. Natural Spline
  15063. iNext = i1 - 1;
  15064. tNext = t0;
  15065. }
  15066. }
  15067. const halfDt = ( t1 - t0 ) * 0.5,
  15068. stride = this.valueSize;
  15069. this._weightPrev = halfDt / ( t0 - tPrev );
  15070. this._weightNext = halfDt / ( tNext - t1 );
  15071. this._offsetPrev = iPrev * stride;
  15072. this._offsetNext = iNext * stride;
  15073. }
  15074. interpolate_( i1, t0, t, t1 ) {
  15075. const result = this.resultBuffer,
  15076. values = this.sampleValues,
  15077. stride = this.valueSize,
  15078. o1 = i1 * stride, o0 = o1 - stride,
  15079. oP = this._offsetPrev, oN = this._offsetNext,
  15080. wP = this._weightPrev, wN = this._weightNext,
  15081. p = ( t - t0 ) / ( t1 - t0 ),
  15082. pp = p * p,
  15083. ppp = pp * p;
  15084. // evaluate polynomials
  15085. const sP = - wP * ppp + 2 * wP * pp - wP * p;
  15086. const s0 = ( 1 + wP ) * ppp + ( - 1.5 - 2 * wP ) * pp + ( - 0.5 + wP ) * p + 1;
  15087. const s1 = ( - 1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  15088. const sN = wN * ppp - wN * pp;
  15089. // combine data linearly
  15090. for ( let i = 0; i !== stride; ++ i ) {
  15091. result[ i ] =
  15092. sP * values[ oP + i ] +
  15093. s0 * values[ o0 + i ] +
  15094. s1 * values[ o1 + i ] +
  15095. sN * values[ oN + i ];
  15096. }
  15097. return result;
  15098. }
  15099. }
  15100. class LinearInterpolant extends Interpolant {
  15101. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15102. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15103. }
  15104. interpolate_( i1, t0, t, t1 ) {
  15105. const result = this.resultBuffer,
  15106. values = this.sampleValues,
  15107. stride = this.valueSize,
  15108. offset1 = i1 * stride,
  15109. offset0 = offset1 - stride,
  15110. weight1 = ( t - t0 ) / ( t1 - t0 ),
  15111. weight0 = 1 - weight1;
  15112. for ( let i = 0; i !== stride; ++ i ) {
  15113. result[ i ] =
  15114. values[ offset0 + i ] * weight0 +
  15115. values[ offset1 + i ] * weight1;
  15116. }
  15117. return result;
  15118. }
  15119. }
  15120. /**
  15121. *
  15122. * Interpolant that evaluates to the sample value at the position preceding
  15123. * the parameter.
  15124. */
  15125. class DiscreteInterpolant extends Interpolant {
  15126. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15127. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15128. }
  15129. interpolate_( i1 /*, t0, t, t1 */ ) {
  15130. return this.copySampleValue_( i1 - 1 );
  15131. }
  15132. }
  15133. class KeyframeTrack {
  15134. constructor( name, times, values, interpolation ) {
  15135. if ( name === undefined ) throw new Error( 'THREE.KeyframeTrack: track name is undefined' );
  15136. if ( times === undefined || times.length === 0 ) throw new Error( 'THREE.KeyframeTrack: no keyframes in track named ' + name );
  15137. this.name = name;
  15138. this.times = convertArray( times, this.TimeBufferType );
  15139. this.values = convertArray( values, this.ValueBufferType );
  15140. this.setInterpolation( interpolation || this.DefaultInterpolation );
  15141. }
  15142. // Serialization (in static context, because of constructor invocation
  15143. // and automatic invocation of .toJSON):
  15144. static toJSON( track ) {
  15145. const trackType = track.constructor;
  15146. let json;
  15147. // derived classes can define a static toJSON method
  15148. if ( trackType.toJSON !== this.toJSON ) {
  15149. json = trackType.toJSON( track );
  15150. } else {
  15151. // by default, we assume the data can be serialized as-is
  15152. json = {
  15153. 'name': track.name,
  15154. 'times': convertArray( track.times, Array ),
  15155. 'values': convertArray( track.values, Array )
  15156. };
  15157. const interpolation = track.getInterpolation();
  15158. if ( interpolation !== track.DefaultInterpolation ) {
  15159. json.interpolation = interpolation;
  15160. }
  15161. }
  15162. json.type = track.ValueTypeName; // mandatory
  15163. return json;
  15164. }
  15165. InterpolantFactoryMethodDiscrete( result ) {
  15166. return new DiscreteInterpolant( this.times, this.values, this.getValueSize(), result );
  15167. }
  15168. InterpolantFactoryMethodLinear( result ) {
  15169. return new LinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15170. }
  15171. InterpolantFactoryMethodSmooth( result ) {
  15172. return new CubicInterpolant( this.times, this.values, this.getValueSize(), result );
  15173. }
  15174. setInterpolation( interpolation ) {
  15175. let factoryMethod;
  15176. switch ( interpolation ) {
  15177. case InterpolateDiscrete:
  15178. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  15179. break;
  15180. case InterpolateLinear:
  15181. factoryMethod = this.InterpolantFactoryMethodLinear;
  15182. break;
  15183. case InterpolateSmooth:
  15184. factoryMethod = this.InterpolantFactoryMethodSmooth;
  15185. break;
  15186. }
  15187. if ( factoryMethod === undefined ) {
  15188. const message = 'unsupported interpolation for ' +
  15189. this.ValueTypeName + ' keyframe track named ' + this.name;
  15190. if ( this.createInterpolant === undefined ) {
  15191. // fall back to default, unless the default itself is messed up
  15192. if ( interpolation !== this.DefaultInterpolation ) {
  15193. this.setInterpolation( this.DefaultInterpolation );
  15194. } else {
  15195. throw new Error( message ); // fatal, in this case
  15196. }
  15197. }
  15198. console.warn( 'THREE.KeyframeTrack:', message );
  15199. return this;
  15200. }
  15201. this.createInterpolant = factoryMethod;
  15202. return this;
  15203. }
  15204. getInterpolation() {
  15205. switch ( this.createInterpolant ) {
  15206. case this.InterpolantFactoryMethodDiscrete:
  15207. return InterpolateDiscrete;
  15208. case this.InterpolantFactoryMethodLinear:
  15209. return InterpolateLinear;
  15210. case this.InterpolantFactoryMethodSmooth:
  15211. return InterpolateSmooth;
  15212. }
  15213. }
  15214. getValueSize() {
  15215. return this.values.length / this.times.length;
  15216. }
  15217. // move all keyframes either forwards or backwards in time
  15218. shift( timeOffset ) {
  15219. if ( timeOffset !== 0.0 ) {
  15220. const times = this.times;
  15221. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15222. times[ i ] += timeOffset;
  15223. }
  15224. }
  15225. return this;
  15226. }
  15227. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  15228. scale( timeScale ) {
  15229. if ( timeScale !== 1.0 ) {
  15230. const times = this.times;
  15231. for ( let i = 0, n = times.length; i !== n; ++ i ) {
  15232. times[ i ] *= timeScale;
  15233. }
  15234. }
  15235. return this;
  15236. }
  15237. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  15238. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  15239. trim( startTime, endTime ) {
  15240. const times = this.times,
  15241. nKeys = times.length;
  15242. let from = 0,
  15243. to = nKeys - 1;
  15244. while ( from !== nKeys && times[ from ] < startTime ) {
  15245. ++ from;
  15246. }
  15247. while ( to !== - 1 && times[ to ] > endTime ) {
  15248. -- to;
  15249. }
  15250. ++ to; // inclusive -> exclusive bound
  15251. if ( from !== 0 || to !== nKeys ) {
  15252. // empty tracks are forbidden, so keep at least one keyframe
  15253. if ( from >= to ) {
  15254. to = Math.max( to, 1 );
  15255. from = to - 1;
  15256. }
  15257. const stride = this.getValueSize();
  15258. this.times = times.slice( from, to );
  15259. this.values = this.values.slice( from * stride, to * stride );
  15260. }
  15261. return this;
  15262. }
  15263. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  15264. validate() {
  15265. let valid = true;
  15266. const valueSize = this.getValueSize();
  15267. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  15268. console.error( 'THREE.KeyframeTrack: Invalid value size in track.', this );
  15269. valid = false;
  15270. }
  15271. const times = this.times,
  15272. values = this.values,
  15273. nKeys = times.length;
  15274. if ( nKeys === 0 ) {
  15275. console.error( 'THREE.KeyframeTrack: Track is empty.', this );
  15276. valid = false;
  15277. }
  15278. let prevTime = null;
  15279. for ( let i = 0; i !== nKeys; i ++ ) {
  15280. const currTime = times[ i ];
  15281. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  15282. console.error( 'THREE.KeyframeTrack: Time is not a valid number.', this, i, currTime );
  15283. valid = false;
  15284. break;
  15285. }
  15286. if ( prevTime !== null && prevTime > currTime ) {
  15287. console.error( 'THREE.KeyframeTrack: Out of order keys.', this, i, currTime, prevTime );
  15288. valid = false;
  15289. break;
  15290. }
  15291. prevTime = currTime;
  15292. }
  15293. if ( values !== undefined ) {
  15294. if ( isTypedArray( values ) ) {
  15295. for ( let i = 0, n = values.length; i !== n; ++ i ) {
  15296. const value = values[ i ];
  15297. if ( isNaN( value ) ) {
  15298. console.error( 'THREE.KeyframeTrack: Value is not a valid number.', this, i, value );
  15299. valid = false;
  15300. break;
  15301. }
  15302. }
  15303. }
  15304. }
  15305. return valid;
  15306. }
  15307. // removes equivalent sequential keys as common in morph target sequences
  15308. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  15309. optimize() {
  15310. // times or values may be shared with other tracks, so overwriting is unsafe
  15311. const times = this.times.slice(),
  15312. values = this.values.slice(),
  15313. stride = this.getValueSize(),
  15314. smoothInterpolation = this.getInterpolation() === InterpolateSmooth,
  15315. lastIndex = times.length - 1;
  15316. let writeIndex = 1;
  15317. for ( let i = 1; i < lastIndex; ++ i ) {
  15318. let keep = false;
  15319. const time = times[ i ];
  15320. const timeNext = times[ i + 1 ];
  15321. // remove adjacent keyframes scheduled at the same time
  15322. if ( time !== timeNext && ( i !== 1 || time !== times[ 0 ] ) ) {
  15323. if ( ! smoothInterpolation ) {
  15324. // remove unnecessary keyframes same as their neighbors
  15325. const offset = i * stride,
  15326. offsetP = offset - stride,
  15327. offsetN = offset + stride;
  15328. for ( let j = 0; j !== stride; ++ j ) {
  15329. const value = values[ offset + j ];
  15330. if ( value !== values[ offsetP + j ] ||
  15331. value !== values[ offsetN + j ] ) {
  15332. keep = true;
  15333. break;
  15334. }
  15335. }
  15336. } else {
  15337. keep = true;
  15338. }
  15339. }
  15340. // in-place compaction
  15341. if ( keep ) {
  15342. if ( i !== writeIndex ) {
  15343. times[ writeIndex ] = times[ i ];
  15344. const readOffset = i * stride,
  15345. writeOffset = writeIndex * stride;
  15346. for ( let j = 0; j !== stride; ++ j ) {
  15347. values[ writeOffset + j ] = values[ readOffset + j ];
  15348. }
  15349. }
  15350. ++ writeIndex;
  15351. }
  15352. }
  15353. // flush last keyframe (compaction looks ahead)
  15354. if ( lastIndex > 0 ) {
  15355. times[ writeIndex ] = times[ lastIndex ];
  15356. for ( let readOffset = lastIndex * stride, writeOffset = writeIndex * stride, j = 0; j !== stride; ++ j ) {
  15357. values[ writeOffset + j ] = values[ readOffset + j ];
  15358. }
  15359. ++ writeIndex;
  15360. }
  15361. if ( writeIndex !== times.length ) {
  15362. this.times = times.slice( 0, writeIndex );
  15363. this.values = values.slice( 0, writeIndex * stride );
  15364. } else {
  15365. this.times = times;
  15366. this.values = values;
  15367. }
  15368. return this;
  15369. }
  15370. clone() {
  15371. const times = this.times.slice();
  15372. const values = this.values.slice();
  15373. const TypedKeyframeTrack = this.constructor;
  15374. const track = new TypedKeyframeTrack( this.name, times, values );
  15375. // Interpolant argument to constructor is not saved, so copy the factory method directly.
  15376. track.createInterpolant = this.createInterpolant;
  15377. return track;
  15378. }
  15379. }
  15380. KeyframeTrack.prototype.TimeBufferType = Float32Array;
  15381. KeyframeTrack.prototype.ValueBufferType = Float32Array;
  15382. KeyframeTrack.prototype.DefaultInterpolation = InterpolateLinear;
  15383. /**
  15384. * A Track of Boolean keyframe values.
  15385. */
  15386. class BooleanKeyframeTrack extends KeyframeTrack {
  15387. // No interpolation parameter because only InterpolateDiscrete is valid.
  15388. constructor( name, times, values ) {
  15389. super( name, times, values );
  15390. }
  15391. }
  15392. BooleanKeyframeTrack.prototype.ValueTypeName = 'bool';
  15393. BooleanKeyframeTrack.prototype.ValueBufferType = Array;
  15394. BooleanKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15395. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15396. BooleanKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15397. /**
  15398. * A Track of keyframe values that represent color.
  15399. */
  15400. class ColorKeyframeTrack extends KeyframeTrack {}
  15401. ColorKeyframeTrack.prototype.ValueTypeName = 'color';
  15402. /**
  15403. * A Track of numeric keyframe values.
  15404. */
  15405. class NumberKeyframeTrack extends KeyframeTrack {}
  15406. NumberKeyframeTrack.prototype.ValueTypeName = 'number';
  15407. /**
  15408. * Spherical linear unit quaternion interpolant.
  15409. */
  15410. class QuaternionLinearInterpolant extends Interpolant {
  15411. constructor( parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  15412. super( parameterPositions, sampleValues, sampleSize, resultBuffer );
  15413. }
  15414. interpolate_( i1, t0, t, t1 ) {
  15415. const result = this.resultBuffer,
  15416. values = this.sampleValues,
  15417. stride = this.valueSize,
  15418. alpha = ( t - t0 ) / ( t1 - t0 );
  15419. let offset = i1 * stride;
  15420. for ( let end = offset + stride; offset !== end; offset += 4 ) {
  15421. Quaternion.slerpFlat( result, 0, values, offset - stride, values, offset, alpha );
  15422. }
  15423. return result;
  15424. }
  15425. }
  15426. /**
  15427. * A Track of quaternion keyframe values.
  15428. */
  15429. class QuaternionKeyframeTrack extends KeyframeTrack {
  15430. InterpolantFactoryMethodLinear( result ) {
  15431. return new QuaternionLinearInterpolant( this.times, this.values, this.getValueSize(), result );
  15432. }
  15433. }
  15434. QuaternionKeyframeTrack.prototype.ValueTypeName = 'quaternion';
  15435. // ValueBufferType is inherited
  15436. // DefaultInterpolation is inherited;
  15437. QuaternionKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15438. /**
  15439. * A Track that interpolates Strings
  15440. */
  15441. class StringKeyframeTrack extends KeyframeTrack {
  15442. // No interpolation parameter because only InterpolateDiscrete is valid.
  15443. constructor( name, times, values ) {
  15444. super( name, times, values );
  15445. }
  15446. }
  15447. StringKeyframeTrack.prototype.ValueTypeName = 'string';
  15448. StringKeyframeTrack.prototype.ValueBufferType = Array;
  15449. StringKeyframeTrack.prototype.DefaultInterpolation = InterpolateDiscrete;
  15450. StringKeyframeTrack.prototype.InterpolantFactoryMethodLinear = undefined;
  15451. StringKeyframeTrack.prototype.InterpolantFactoryMethodSmooth = undefined;
  15452. /**
  15453. * A Track of vectored keyframe values.
  15454. */
  15455. class VectorKeyframeTrack extends KeyframeTrack {}
  15456. VectorKeyframeTrack.prototype.ValueTypeName = 'vector';
  15457. class AnimationClip {
  15458. constructor( name = '', duration = - 1, tracks = [], blendMode = NormalAnimationBlendMode ) {
  15459. this.name = name;
  15460. this.tracks = tracks;
  15461. this.duration = duration;
  15462. this.blendMode = blendMode;
  15463. this.uuid = generateUUID();
  15464. // this means it should figure out its duration by scanning the tracks
  15465. if ( this.duration < 0 ) {
  15466. this.resetDuration();
  15467. }
  15468. }
  15469. static parse( json ) {
  15470. const tracks = [],
  15471. jsonTracks = json.tracks,
  15472. frameTime = 1.0 / ( json.fps || 1.0 );
  15473. for ( let i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  15474. tracks.push( parseKeyframeTrack( jsonTracks[ i ] ).scale( frameTime ) );
  15475. }
  15476. const clip = new this( json.name, json.duration, tracks, json.blendMode );
  15477. clip.uuid = json.uuid;
  15478. return clip;
  15479. }
  15480. static toJSON( clip ) {
  15481. const tracks = [],
  15482. clipTracks = clip.tracks;
  15483. const json = {
  15484. 'name': clip.name,
  15485. 'duration': clip.duration,
  15486. 'tracks': tracks,
  15487. 'uuid': clip.uuid,
  15488. 'blendMode': clip.blendMode
  15489. };
  15490. for ( let i = 0, n = clipTracks.length; i !== n; ++ i ) {
  15491. tracks.push( KeyframeTrack.toJSON( clipTracks[ i ] ) );
  15492. }
  15493. return json;
  15494. }
  15495. static CreateFromMorphTargetSequence( name, morphTargetSequence, fps, noLoop ) {
  15496. const numMorphTargets = morphTargetSequence.length;
  15497. const tracks = [];
  15498. for ( let i = 0; i < numMorphTargets; i ++ ) {
  15499. let times = [];
  15500. let values = [];
  15501. times.push(
  15502. ( i + numMorphTargets - 1 ) % numMorphTargets,
  15503. i,
  15504. ( i + 1 ) % numMorphTargets );
  15505. values.push( 0, 1, 0 );
  15506. const order = getKeyframeOrder( times );
  15507. times = sortedArray( times, 1, order );
  15508. values = sortedArray( values, 1, order );
  15509. // if there is a key at the first frame, duplicate it as the
  15510. // last frame as well for perfect loop.
  15511. if ( ! noLoop && times[ 0 ] === 0 ) {
  15512. times.push( numMorphTargets );
  15513. values.push( values[ 0 ] );
  15514. }
  15515. tracks.push(
  15516. new NumberKeyframeTrack(
  15517. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  15518. times, values
  15519. ).scale( 1.0 / fps ) );
  15520. }
  15521. return new this( name, - 1, tracks );
  15522. }
  15523. static findByName( objectOrClipArray, name ) {
  15524. let clipArray = objectOrClipArray;
  15525. if ( ! Array.isArray( objectOrClipArray ) ) {
  15526. const o = objectOrClipArray;
  15527. clipArray = o.geometry && o.geometry.animations || o.animations;
  15528. }
  15529. for ( let i = 0; i < clipArray.length; i ++ ) {
  15530. if ( clipArray[ i ].name === name ) {
  15531. return clipArray[ i ];
  15532. }
  15533. }
  15534. return null;
  15535. }
  15536. static CreateClipsFromMorphTargetSequences( morphTargets, fps, noLoop ) {
  15537. const animationToMorphTargets = {};
  15538. // tested with https://regex101.com/ on trick sequences
  15539. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  15540. const pattern = /^([\w-]*?)([\d]+)$/;
  15541. // sort morph target names into animation groups based
  15542. // patterns like Walk_001, Walk_002, Run_001, Run_002
  15543. for ( let i = 0, il = morphTargets.length; i < il; i ++ ) {
  15544. const morphTarget = morphTargets[ i ];
  15545. const parts = morphTarget.name.match( pattern );
  15546. if ( parts && parts.length > 1 ) {
  15547. const name = parts[ 1 ];
  15548. let animationMorphTargets = animationToMorphTargets[ name ];
  15549. if ( ! animationMorphTargets ) {
  15550. animationToMorphTargets[ name ] = animationMorphTargets = [];
  15551. }
  15552. animationMorphTargets.push( morphTarget );
  15553. }
  15554. }
  15555. const clips = [];
  15556. for ( const name in animationToMorphTargets ) {
  15557. clips.push( this.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps, noLoop ) );
  15558. }
  15559. return clips;
  15560. }
  15561. // parse the animation.hierarchy format
  15562. static parseAnimation( animation, bones ) {
  15563. if ( ! animation ) {
  15564. console.error( 'THREE.AnimationClip: No animation in JSONLoader data.' );
  15565. return null;
  15566. }
  15567. const addNonemptyTrack = function ( trackType, trackName, animationKeys, propertyName, destTracks ) {
  15568. // only return track if there are actually keys.
  15569. if ( animationKeys.length !== 0 ) {
  15570. const times = [];
  15571. const values = [];
  15572. flattenJSON( animationKeys, times, values, propertyName );
  15573. // empty keys are filtered out, so check again
  15574. if ( times.length !== 0 ) {
  15575. destTracks.push( new trackType( trackName, times, values ) );
  15576. }
  15577. }
  15578. };
  15579. const tracks = [];
  15580. const clipName = animation.name || 'default';
  15581. const fps = animation.fps || 30;
  15582. const blendMode = animation.blendMode;
  15583. // automatic length determination in AnimationClip.
  15584. let duration = animation.length || - 1;
  15585. const hierarchyTracks = animation.hierarchy || [];
  15586. for ( let h = 0; h < hierarchyTracks.length; h ++ ) {
  15587. const animationKeys = hierarchyTracks[ h ].keys;
  15588. // skip empty tracks
  15589. if ( ! animationKeys || animationKeys.length === 0 ) continue;
  15590. // process morph targets
  15591. if ( animationKeys[ 0 ].morphTargets ) {
  15592. // figure out all morph targets used in this track
  15593. const morphTargetNames = {};
  15594. let k;
  15595. for ( k = 0; k < animationKeys.length; k ++ ) {
  15596. if ( animationKeys[ k ].morphTargets ) {
  15597. for ( let m = 0; m < animationKeys[ k ].morphTargets.length; m ++ ) {
  15598. morphTargetNames[ animationKeys[ k ].morphTargets[ m ] ] = - 1;
  15599. }
  15600. }
  15601. }
  15602. // create a track for each morph target with all zero
  15603. // morphTargetInfluences except for the keys in which
  15604. // the morphTarget is named.
  15605. for ( const morphTargetName in morphTargetNames ) {
  15606. const times = [];
  15607. const values = [];
  15608. for ( let m = 0; m !== animationKeys[ k ].morphTargets.length; ++ m ) {
  15609. const animationKey = animationKeys[ k ];
  15610. times.push( animationKey.time );
  15611. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 );
  15612. }
  15613. tracks.push( new NumberKeyframeTrack( '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  15614. }
  15615. duration = morphTargetNames.length * fps;
  15616. } else {
  15617. // ...assume skeletal animation
  15618. const boneName = '.bones[' + bones[ h ].name + ']';
  15619. addNonemptyTrack(
  15620. VectorKeyframeTrack, boneName + '.position',
  15621. animationKeys, 'pos', tracks );
  15622. addNonemptyTrack(
  15623. QuaternionKeyframeTrack, boneName + '.quaternion',
  15624. animationKeys, 'rot', tracks );
  15625. addNonemptyTrack(
  15626. VectorKeyframeTrack, boneName + '.scale',
  15627. animationKeys, 'scl', tracks );
  15628. }
  15629. }
  15630. if ( tracks.length === 0 ) {
  15631. return null;
  15632. }
  15633. const clip = new this( clipName, duration, tracks, blendMode );
  15634. return clip;
  15635. }
  15636. resetDuration() {
  15637. const tracks = this.tracks;
  15638. let duration = 0;
  15639. for ( let i = 0, n = tracks.length; i !== n; ++ i ) {
  15640. const track = this.tracks[ i ];
  15641. duration = Math.max( duration, track.times[ track.times.length - 1 ] );
  15642. }
  15643. this.duration = duration;
  15644. return this;
  15645. }
  15646. trim() {
  15647. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15648. this.tracks[ i ].trim( 0, this.duration );
  15649. }
  15650. return this;
  15651. }
  15652. validate() {
  15653. let valid = true;
  15654. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15655. valid = valid && this.tracks[ i ].validate();
  15656. }
  15657. return valid;
  15658. }
  15659. optimize() {
  15660. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15661. this.tracks[ i ].optimize();
  15662. }
  15663. return this;
  15664. }
  15665. clone() {
  15666. const tracks = [];
  15667. for ( let i = 0; i < this.tracks.length; i ++ ) {
  15668. tracks.push( this.tracks[ i ].clone() );
  15669. }
  15670. return new this.constructor( this.name, this.duration, tracks, this.blendMode );
  15671. }
  15672. toJSON() {
  15673. return this.constructor.toJSON( this );
  15674. }
  15675. }
  15676. function getTrackTypeForValueTypeName( typeName ) {
  15677. switch ( typeName.toLowerCase() ) {
  15678. case 'scalar':
  15679. case 'double':
  15680. case 'float':
  15681. case 'number':
  15682. case 'integer':
  15683. return NumberKeyframeTrack;
  15684. case 'vector':
  15685. case 'vector2':
  15686. case 'vector3':
  15687. case 'vector4':
  15688. return VectorKeyframeTrack;
  15689. case 'color':
  15690. return ColorKeyframeTrack;
  15691. case 'quaternion':
  15692. return QuaternionKeyframeTrack;
  15693. case 'bool':
  15694. case 'boolean':
  15695. return BooleanKeyframeTrack;
  15696. case 'string':
  15697. return StringKeyframeTrack;
  15698. }
  15699. throw new Error( 'THREE.KeyframeTrack: Unsupported typeName: ' + typeName );
  15700. }
  15701. function parseKeyframeTrack( json ) {
  15702. if ( json.type === undefined ) {
  15703. throw new Error( 'THREE.KeyframeTrack: track type undefined, can not parse' );
  15704. }
  15705. const trackType = getTrackTypeForValueTypeName( json.type );
  15706. if ( json.times === undefined ) {
  15707. const times = [], values = [];
  15708. flattenJSON( json.keys, times, values, 'value' );
  15709. json.times = times;
  15710. json.values = values;
  15711. }
  15712. // derived classes can define a static parse method
  15713. if ( trackType.parse !== undefined ) {
  15714. return trackType.parse( json );
  15715. } else {
  15716. // by default, we assume a constructor compatible with the base
  15717. return new trackType( json.name, json.times, json.values, json.interpolation );
  15718. }
  15719. }
  15720. const Cache = {
  15721. enabled: false,
  15722. files: {},
  15723. add: function ( key, file ) {
  15724. if ( this.enabled === false ) return;
  15725. // console.log( 'THREE.Cache', 'Adding key:', key );
  15726. this.files[ key ] = file;
  15727. },
  15728. get: function ( key ) {
  15729. if ( this.enabled === false ) return;
  15730. // console.log( 'THREE.Cache', 'Checking key:', key );
  15731. return this.files[ key ];
  15732. },
  15733. remove: function ( key ) {
  15734. delete this.files[ key ];
  15735. },
  15736. clear: function () {
  15737. this.files = {};
  15738. }
  15739. };
  15740. class LoadingManager {
  15741. constructor( onLoad, onProgress, onError ) {
  15742. const scope = this;
  15743. let isLoading = false;
  15744. let itemsLoaded = 0;
  15745. let itemsTotal = 0;
  15746. let urlModifier = undefined;
  15747. const handlers = [];
  15748. // Refer to #5689 for the reason why we don't set .onStart
  15749. // in the constructor
  15750. this.onStart = undefined;
  15751. this.onLoad = onLoad;
  15752. this.onProgress = onProgress;
  15753. this.onError = onError;
  15754. this.itemStart = function ( url ) {
  15755. itemsTotal ++;
  15756. if ( isLoading === false ) {
  15757. if ( scope.onStart !== undefined ) {
  15758. scope.onStart( url, itemsLoaded, itemsTotal );
  15759. }
  15760. }
  15761. isLoading = true;
  15762. };
  15763. this.itemEnd = function ( url ) {
  15764. itemsLoaded ++;
  15765. if ( scope.onProgress !== undefined ) {
  15766. scope.onProgress( url, itemsLoaded, itemsTotal );
  15767. }
  15768. if ( itemsLoaded === itemsTotal ) {
  15769. isLoading = false;
  15770. if ( scope.onLoad !== undefined ) {
  15771. scope.onLoad();
  15772. }
  15773. }
  15774. };
  15775. this.itemError = function ( url ) {
  15776. if ( scope.onError !== undefined ) {
  15777. scope.onError( url );
  15778. }
  15779. };
  15780. this.resolveURL = function ( url ) {
  15781. if ( urlModifier ) {
  15782. return urlModifier( url );
  15783. }
  15784. return url;
  15785. };
  15786. this.setURLModifier = function ( transform ) {
  15787. urlModifier = transform;
  15788. return this;
  15789. };
  15790. this.addHandler = function ( regex, loader ) {
  15791. handlers.push( regex, loader );
  15792. return this;
  15793. };
  15794. this.removeHandler = function ( regex ) {
  15795. const index = handlers.indexOf( regex );
  15796. if ( index !== - 1 ) {
  15797. handlers.splice( index, 2 );
  15798. }
  15799. return this;
  15800. };
  15801. this.getHandler = function ( file ) {
  15802. for ( let i = 0, l = handlers.length; i < l; i += 2 ) {
  15803. const regex = handlers[ i ];
  15804. const loader = handlers[ i + 1 ];
  15805. if ( regex.global ) regex.lastIndex = 0; // see #17920
  15806. if ( regex.test( file ) ) {
  15807. return loader;
  15808. }
  15809. }
  15810. return null;
  15811. };
  15812. }
  15813. }
  15814. const DefaultLoadingManager = /*@__PURE__*/ new LoadingManager();
  15815. class Loader {
  15816. constructor( manager ) {
  15817. this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
  15818. this.crossOrigin = 'anonymous';
  15819. this.withCredentials = false;
  15820. this.path = '';
  15821. this.resourcePath = '';
  15822. this.requestHeader = {};
  15823. }
  15824. load( /* url, onLoad, onProgress, onError */ ) {}
  15825. loadAsync( url, onProgress ) {
  15826. const scope = this;
  15827. return new Promise( function ( resolve, reject ) {
  15828. scope.load( url, resolve, onProgress, reject );
  15829. } );
  15830. }
  15831. parse( /* data */ ) {}
  15832. setCrossOrigin( crossOrigin ) {
  15833. this.crossOrigin = crossOrigin;
  15834. return this;
  15835. }
  15836. setWithCredentials( value ) {
  15837. this.withCredentials = value;
  15838. return this;
  15839. }
  15840. setPath( path ) {
  15841. this.path = path;
  15842. return this;
  15843. }
  15844. setResourcePath( resourcePath ) {
  15845. this.resourcePath = resourcePath;
  15846. return this;
  15847. }
  15848. setRequestHeader( requestHeader ) {
  15849. this.requestHeader = requestHeader;
  15850. return this;
  15851. }
  15852. }
  15853. Loader.DEFAULT_MATERIAL_NAME = '__DEFAULT';
  15854. const loading = {};
  15855. class HttpError extends Error {
  15856. constructor( message, response ) {
  15857. super( message );
  15858. this.response = response;
  15859. }
  15860. }
  15861. class FileLoader extends Loader {
  15862. constructor( manager ) {
  15863. super( manager );
  15864. }
  15865. load( url, onLoad, onProgress, onError ) {
  15866. if ( url === undefined ) url = '';
  15867. if ( this.path !== undefined ) url = this.path + url;
  15868. url = this.manager.resolveURL( url );
  15869. const cached = Cache.get( url );
  15870. if ( cached !== undefined ) {
  15871. this.manager.itemStart( url );
  15872. setTimeout( () => {
  15873. if ( onLoad ) onLoad( cached );
  15874. this.manager.itemEnd( url );
  15875. }, 0 );
  15876. return cached;
  15877. }
  15878. // Check if request is duplicate
  15879. if ( loading[ url ] !== undefined ) {
  15880. loading[ url ].push( {
  15881. onLoad: onLoad,
  15882. onProgress: onProgress,
  15883. onError: onError
  15884. } );
  15885. return;
  15886. }
  15887. // Initialise array for duplicate requests
  15888. loading[ url ] = [];
  15889. loading[ url ].push( {
  15890. onLoad: onLoad,
  15891. onProgress: onProgress,
  15892. onError: onError,
  15893. } );
  15894. // create request
  15895. const req = new Request( url, {
  15896. headers: new Headers( this.requestHeader ),
  15897. credentials: this.withCredentials ? 'include' : 'same-origin',
  15898. // An abort controller could be added within a future PR
  15899. } );
  15900. // record states ( avoid data race )
  15901. const mimeType = this.mimeType;
  15902. const responseType = this.responseType;
  15903. // start the fetch
  15904. fetch( req )
  15905. .then( response => {
  15906. if ( response.status === 200 || response.status === 0 ) {
  15907. // Some browsers return HTTP Status 0 when using non-http protocol
  15908. // e.g. 'file://' or 'data://'. Handle as success.
  15909. if ( response.status === 0 ) {
  15910. console.warn( 'THREE.FileLoader: HTTP Status 0 received.' );
  15911. }
  15912. // Workaround: Checking if response.body === undefined for Alipay browser #23548
  15913. if ( typeof ReadableStream === 'undefined' || response.body === undefined || response.body.getReader === undefined ) {
  15914. return response;
  15915. }
  15916. const callbacks = loading[ url ];
  15917. const reader = response.body.getReader();
  15918. // Nginx needs X-File-Size check
  15919. // https://serverfault.com/questions/482875/why-does-nginx-remove-content-length-header-for-chunked-content
  15920. const contentLength = response.headers.get( 'X-File-Size' ) || response.headers.get( 'Content-Length' );
  15921. const total = contentLength ? parseInt( contentLength ) : 0;
  15922. const lengthComputable = total !== 0;
  15923. let loaded = 0;
  15924. // periodically read data into the new stream tracking while download progress
  15925. const stream = new ReadableStream( {
  15926. start( controller ) {
  15927. readData();
  15928. function readData() {
  15929. reader.read().then( ( { done, value } ) => {
  15930. if ( done ) {
  15931. controller.close();
  15932. } else {
  15933. loaded += value.byteLength;
  15934. const event = new ProgressEvent( 'progress', { lengthComputable, loaded, total } );
  15935. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15936. const callback = callbacks[ i ];
  15937. if ( callback.onProgress ) callback.onProgress( event );
  15938. }
  15939. controller.enqueue( value );
  15940. readData();
  15941. }
  15942. }, ( e ) => {
  15943. controller.error( e );
  15944. } );
  15945. }
  15946. }
  15947. } );
  15948. return new Response( stream );
  15949. } else {
  15950. throw new HttpError( `fetch for "${response.url}" responded with ${response.status}: ${response.statusText}`, response );
  15951. }
  15952. } )
  15953. .then( response => {
  15954. switch ( responseType ) {
  15955. case 'arraybuffer':
  15956. return response.arrayBuffer();
  15957. case 'blob':
  15958. return response.blob();
  15959. case 'document':
  15960. return response.text()
  15961. .then( text => {
  15962. const parser = new DOMParser();
  15963. return parser.parseFromString( text, mimeType );
  15964. } );
  15965. case 'json':
  15966. return response.json();
  15967. default:
  15968. if ( mimeType === undefined ) {
  15969. return response.text();
  15970. } else {
  15971. // sniff encoding
  15972. const re = /charset="?([^;"\s]*)"?/i;
  15973. const exec = re.exec( mimeType );
  15974. const label = exec && exec[ 1 ] ? exec[ 1 ].toLowerCase() : undefined;
  15975. const decoder = new TextDecoder( label );
  15976. return response.arrayBuffer().then( ab => decoder.decode( ab ) );
  15977. }
  15978. }
  15979. } )
  15980. .then( data => {
  15981. // Add to cache only on HTTP success, so that we do not cache
  15982. // error response bodies as proper responses to requests.
  15983. Cache.add( url, data );
  15984. const callbacks = loading[ url ];
  15985. delete loading[ url ];
  15986. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  15987. const callback = callbacks[ i ];
  15988. if ( callback.onLoad ) callback.onLoad( data );
  15989. }
  15990. } )
  15991. .catch( err => {
  15992. // Abort errors and other errors are handled the same
  15993. const callbacks = loading[ url ];
  15994. if ( callbacks === undefined ) {
  15995. // When onLoad was called and url was deleted in `loading`
  15996. this.manager.itemError( url );
  15997. throw err;
  15998. }
  15999. delete loading[ url ];
  16000. for ( let i = 0, il = callbacks.length; i < il; i ++ ) {
  16001. const callback = callbacks[ i ];
  16002. if ( callback.onError ) callback.onError( err );
  16003. }
  16004. this.manager.itemError( url );
  16005. } )
  16006. .finally( () => {
  16007. this.manager.itemEnd( url );
  16008. } );
  16009. this.manager.itemStart( url );
  16010. }
  16011. setResponseType( value ) {
  16012. this.responseType = value;
  16013. return this;
  16014. }
  16015. setMimeType( value ) {
  16016. this.mimeType = value;
  16017. return this;
  16018. }
  16019. }
  16020. class AnimationLoader extends Loader {
  16021. constructor( manager ) {
  16022. super( manager );
  16023. }
  16024. load( url, onLoad, onProgress, onError ) {
  16025. const scope = this;
  16026. const loader = new FileLoader( this.manager );
  16027. loader.setPath( this.path );
  16028. loader.setRequestHeader( this.requestHeader );
  16029. loader.setWithCredentials( this.withCredentials );
  16030. loader.load( url, function ( text ) {
  16031. try {
  16032. onLoad( scope.parse( JSON.parse( text ) ) );
  16033. } catch ( e ) {
  16034. if ( onError ) {
  16035. onError( e );
  16036. } else {
  16037. console.error( e );
  16038. }
  16039. scope.manager.itemError( url );
  16040. }
  16041. }, onProgress, onError );
  16042. }
  16043. parse( json ) {
  16044. const animations = [];
  16045. for ( let i = 0; i < json.length; i ++ ) {
  16046. const clip = AnimationClip.parse( json[ i ] );
  16047. animations.push( clip );
  16048. }
  16049. return animations;
  16050. }
  16051. }
  16052. /**
  16053. * Abstract Base class to block based textures loader (dds, pvr, ...)
  16054. *
  16055. * Sub classes have to implement the parse() method which will be used in load().
  16056. */
  16057. class CompressedTextureLoader extends Loader {
  16058. constructor( manager ) {
  16059. super( manager );
  16060. }
  16061. load( url, onLoad, onProgress, onError ) {
  16062. const scope = this;
  16063. const images = [];
  16064. const texture = new CompressedTexture();
  16065. const loader = new FileLoader( this.manager );
  16066. loader.setPath( this.path );
  16067. loader.setResponseType( 'arraybuffer' );
  16068. loader.setRequestHeader( this.requestHeader );
  16069. loader.setWithCredentials( scope.withCredentials );
  16070. let loaded = 0;
  16071. function loadTexture( i ) {
  16072. loader.load( url[ i ], function ( buffer ) {
  16073. const texDatas = scope.parse( buffer, true );
  16074. images[ i ] = {
  16075. width: texDatas.width,
  16076. height: texDatas.height,
  16077. format: texDatas.format,
  16078. mipmaps: texDatas.mipmaps
  16079. };
  16080. loaded += 1;
  16081. if ( loaded === 6 ) {
  16082. if ( texDatas.mipmapCount === 1 ) texture.minFilter = LinearFilter;
  16083. texture.image = images;
  16084. texture.format = texDatas.format;
  16085. texture.needsUpdate = true;
  16086. if ( onLoad ) onLoad( texture );
  16087. }
  16088. }, onProgress, onError );
  16089. }
  16090. if ( Array.isArray( url ) ) {
  16091. for ( let i = 0, il = url.length; i < il; ++ i ) {
  16092. loadTexture( i );
  16093. }
  16094. } else {
  16095. // compressed cubemap texture stored in a single DDS file
  16096. loader.load( url, function ( buffer ) {
  16097. const texDatas = scope.parse( buffer, true );
  16098. if ( texDatas.isCubemap ) {
  16099. const faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  16100. for ( let f = 0; f < faces; f ++ ) {
  16101. images[ f ] = { mipmaps: [] };
  16102. for ( let i = 0; i < texDatas.mipmapCount; i ++ ) {
  16103. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  16104. images[ f ].format = texDatas.format;
  16105. images[ f ].width = texDatas.width;
  16106. images[ f ].height = texDatas.height;
  16107. }
  16108. }
  16109. texture.image = images;
  16110. } else {
  16111. texture.image.width = texDatas.width;
  16112. texture.image.height = texDatas.height;
  16113. texture.mipmaps = texDatas.mipmaps;
  16114. }
  16115. if ( texDatas.mipmapCount === 1 ) {
  16116. texture.minFilter = LinearFilter;
  16117. }
  16118. texture.format = texDatas.format;
  16119. texture.needsUpdate = true;
  16120. if ( onLoad ) onLoad( texture );
  16121. }, onProgress, onError );
  16122. }
  16123. return texture;
  16124. }
  16125. }
  16126. class ImageLoader extends Loader {
  16127. constructor( manager ) {
  16128. super( manager );
  16129. }
  16130. load( url, onLoad, onProgress, onError ) {
  16131. if ( this.path !== undefined ) url = this.path + url;
  16132. url = this.manager.resolveURL( url );
  16133. const scope = this;
  16134. const cached = Cache.get( url );
  16135. if ( cached !== undefined ) {
  16136. scope.manager.itemStart( url );
  16137. setTimeout( function () {
  16138. if ( onLoad ) onLoad( cached );
  16139. scope.manager.itemEnd( url );
  16140. }, 0 );
  16141. return cached;
  16142. }
  16143. const image = createElementNS( 'img' );
  16144. function onImageLoad() {
  16145. removeEventListeners();
  16146. Cache.add( url, this );
  16147. if ( onLoad ) onLoad( this );
  16148. scope.manager.itemEnd( url );
  16149. }
  16150. function onImageError( event ) {
  16151. removeEventListeners();
  16152. if ( onError ) onError( event );
  16153. scope.manager.itemError( url );
  16154. scope.manager.itemEnd( url );
  16155. }
  16156. function removeEventListeners() {
  16157. image.removeEventListener( 'load', onImageLoad, false );
  16158. image.removeEventListener( 'error', onImageError, false );
  16159. }
  16160. image.addEventListener( 'load', onImageLoad, false );
  16161. image.addEventListener( 'error', onImageError, false );
  16162. if ( url.slice( 0, 5 ) !== 'data:' ) {
  16163. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  16164. }
  16165. scope.manager.itemStart( url );
  16166. image.src = url;
  16167. return image;
  16168. }
  16169. }
  16170. class CubeTextureLoader extends Loader {
  16171. constructor( manager ) {
  16172. super( manager );
  16173. }
  16174. load( urls, onLoad, onProgress, onError ) {
  16175. const texture = new CubeTexture();
  16176. texture.colorSpace = SRGBColorSpace;
  16177. const loader = new ImageLoader( this.manager );
  16178. loader.setCrossOrigin( this.crossOrigin );
  16179. loader.setPath( this.path );
  16180. let loaded = 0;
  16181. function loadTexture( i ) {
  16182. loader.load( urls[ i ], function ( image ) {
  16183. texture.images[ i ] = image;
  16184. loaded ++;
  16185. if ( loaded === 6 ) {
  16186. texture.needsUpdate = true;
  16187. if ( onLoad ) onLoad( texture );
  16188. }
  16189. }, undefined, onError );
  16190. }
  16191. for ( let i = 0; i < urls.length; ++ i ) {
  16192. loadTexture( i );
  16193. }
  16194. return texture;
  16195. }
  16196. }
  16197. /**
  16198. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  16199. *
  16200. * Sub classes have to implement the parse() method which will be used in load().
  16201. */
  16202. class DataTextureLoader extends Loader {
  16203. constructor( manager ) {
  16204. super( manager );
  16205. }
  16206. load( url, onLoad, onProgress, onError ) {
  16207. const scope = this;
  16208. const texture = new DataTexture();
  16209. const loader = new FileLoader( this.manager );
  16210. loader.setResponseType( 'arraybuffer' );
  16211. loader.setRequestHeader( this.requestHeader );
  16212. loader.setPath( this.path );
  16213. loader.setWithCredentials( scope.withCredentials );
  16214. loader.load( url, function ( buffer ) {
  16215. let texData;
  16216. try {
  16217. texData = scope.parse( buffer );
  16218. } catch ( error ) {
  16219. if ( onError !== undefined ) {
  16220. onError( error );
  16221. } else {
  16222. console.error( error );
  16223. return;
  16224. }
  16225. }
  16226. if ( texData.image !== undefined ) {
  16227. texture.image = texData.image;
  16228. } else if ( texData.data !== undefined ) {
  16229. texture.image.width = texData.width;
  16230. texture.image.height = texData.height;
  16231. texture.image.data = texData.data;
  16232. }
  16233. texture.wrapS = texData.wrapS !== undefined ? texData.wrapS : ClampToEdgeWrapping;
  16234. texture.wrapT = texData.wrapT !== undefined ? texData.wrapT : ClampToEdgeWrapping;
  16235. texture.magFilter = texData.magFilter !== undefined ? texData.magFilter : LinearFilter;
  16236. texture.minFilter = texData.minFilter !== undefined ? texData.minFilter : LinearFilter;
  16237. texture.anisotropy = texData.anisotropy !== undefined ? texData.anisotropy : 1;
  16238. if ( texData.colorSpace !== undefined ) {
  16239. texture.colorSpace = texData.colorSpace;
  16240. }
  16241. if ( texData.flipY !== undefined ) {
  16242. texture.flipY = texData.flipY;
  16243. }
  16244. if ( texData.format !== undefined ) {
  16245. texture.format = texData.format;
  16246. }
  16247. if ( texData.type !== undefined ) {
  16248. texture.type = texData.type;
  16249. }
  16250. if ( texData.mipmaps !== undefined ) {
  16251. texture.mipmaps = texData.mipmaps;
  16252. texture.minFilter = LinearMipmapLinearFilter; // presumably...
  16253. }
  16254. if ( texData.mipmapCount === 1 ) {
  16255. texture.minFilter = LinearFilter;
  16256. }
  16257. if ( texData.generateMipmaps !== undefined ) {
  16258. texture.generateMipmaps = texData.generateMipmaps;
  16259. }
  16260. texture.needsUpdate = true;
  16261. if ( onLoad ) onLoad( texture, texData );
  16262. }, onProgress, onError );
  16263. return texture;
  16264. }
  16265. }
  16266. class TextureLoader extends Loader {
  16267. constructor( manager ) {
  16268. super( manager );
  16269. }
  16270. load( url, onLoad, onProgress, onError ) {
  16271. const texture = new Texture();
  16272. const loader = new ImageLoader( this.manager );
  16273. loader.setCrossOrigin( this.crossOrigin );
  16274. loader.setPath( this.path );
  16275. loader.load( url, function ( image ) {
  16276. texture.image = image;
  16277. texture.needsUpdate = true;
  16278. if ( onLoad !== undefined ) {
  16279. onLoad( texture );
  16280. }
  16281. }, onProgress, onError );
  16282. return texture;
  16283. }
  16284. }
  16285. class Light extends Object3D {
  16286. constructor( color, intensity = 1 ) {
  16287. super();
  16288. this.isLight = true;
  16289. this.type = 'Light';
  16290. this.color = new Color( color );
  16291. this.intensity = intensity;
  16292. }
  16293. dispose() {
  16294. // Empty here in base class; some subclasses override.
  16295. }
  16296. copy( source, recursive ) {
  16297. super.copy( source, recursive );
  16298. this.color.copy( source.color );
  16299. this.intensity = source.intensity;
  16300. return this;
  16301. }
  16302. toJSON( meta ) {
  16303. const data = super.toJSON( meta );
  16304. data.object.color = this.color.getHex();
  16305. data.object.intensity = this.intensity;
  16306. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  16307. if ( this.distance !== undefined ) data.object.distance = this.distance;
  16308. if ( this.angle !== undefined ) data.object.angle = this.angle;
  16309. if ( this.decay !== undefined ) data.object.decay = this.decay;
  16310. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  16311. if ( this.shadow !== undefined ) data.object.shadow = this.shadow.toJSON();
  16312. if ( this.target !== undefined ) data.object.target = this.target.uuid;
  16313. return data;
  16314. }
  16315. }
  16316. class HemisphereLight extends Light {
  16317. constructor( skyColor, groundColor, intensity ) {
  16318. super( skyColor, intensity );
  16319. this.isHemisphereLight = true;
  16320. this.type = 'HemisphereLight';
  16321. this.position.copy( Object3D.DEFAULT_UP );
  16322. this.updateMatrix();
  16323. this.groundColor = new Color( groundColor );
  16324. }
  16325. copy( source, recursive ) {
  16326. super.copy( source, recursive );
  16327. this.groundColor.copy( source.groundColor );
  16328. return this;
  16329. }
  16330. }
  16331. const _projScreenMatrix$1 = /*@__PURE__*/ new Matrix4();
  16332. const _lightPositionWorld$1 = /*@__PURE__*/ new Vector3();
  16333. const _lookTarget$1 = /*@__PURE__*/ new Vector3();
  16334. class LightShadow {
  16335. constructor( camera ) {
  16336. this.camera = camera;
  16337. this.intensity = 1;
  16338. this.bias = 0;
  16339. this.normalBias = 0;
  16340. this.radius = 1;
  16341. this.blurSamples = 8;
  16342. this.mapSize = new Vector2( 512, 512 );
  16343. this.map = null;
  16344. this.mapPass = null;
  16345. this.matrix = new Matrix4();
  16346. this.autoUpdate = true;
  16347. this.needsUpdate = false;
  16348. this._frustum = new Frustum();
  16349. this._frameExtents = new Vector2( 1, 1 );
  16350. this._viewportCount = 1;
  16351. this._viewports = [
  16352. new Vector4( 0, 0, 1, 1 )
  16353. ];
  16354. }
  16355. getViewportCount() {
  16356. return this._viewportCount;
  16357. }
  16358. getFrustum() {
  16359. return this._frustum;
  16360. }
  16361. updateMatrices( light ) {
  16362. const shadowCamera = this.camera;
  16363. const shadowMatrix = this.matrix;
  16364. _lightPositionWorld$1.setFromMatrixPosition( light.matrixWorld );
  16365. shadowCamera.position.copy( _lightPositionWorld$1 );
  16366. _lookTarget$1.setFromMatrixPosition( light.target.matrixWorld );
  16367. shadowCamera.lookAt( _lookTarget$1 );
  16368. shadowCamera.updateMatrixWorld();
  16369. _projScreenMatrix$1.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  16370. this._frustum.setFromProjectionMatrix( _projScreenMatrix$1 );
  16371. shadowMatrix.set(
  16372. 0.5, 0.0, 0.0, 0.5,
  16373. 0.0, 0.5, 0.0, 0.5,
  16374. 0.0, 0.0, 0.5, 0.5,
  16375. 0.0, 0.0, 0.0, 1.0
  16376. );
  16377. shadowMatrix.multiply( _projScreenMatrix$1 );
  16378. }
  16379. getViewport( viewportIndex ) {
  16380. return this._viewports[ viewportIndex ];
  16381. }
  16382. getFrameExtents() {
  16383. return this._frameExtents;
  16384. }
  16385. dispose() {
  16386. if ( this.map ) {
  16387. this.map.dispose();
  16388. }
  16389. if ( this.mapPass ) {
  16390. this.mapPass.dispose();
  16391. }
  16392. }
  16393. copy( source ) {
  16394. this.camera = source.camera.clone();
  16395. this.intensity = source.intensity;
  16396. this.bias = source.bias;
  16397. this.radius = source.radius;
  16398. this.mapSize.copy( source.mapSize );
  16399. return this;
  16400. }
  16401. clone() {
  16402. return new this.constructor().copy( this );
  16403. }
  16404. toJSON() {
  16405. const object = {};
  16406. if ( this.intensity !== 1 ) object.intensity = this.intensity;
  16407. if ( this.bias !== 0 ) object.bias = this.bias;
  16408. if ( this.normalBias !== 0 ) object.normalBias = this.normalBias;
  16409. if ( this.radius !== 1 ) object.radius = this.radius;
  16410. if ( this.mapSize.x !== 512 || this.mapSize.y !== 512 ) object.mapSize = this.mapSize.toArray();
  16411. object.camera = this.camera.toJSON( false ).object;
  16412. delete object.camera.matrix;
  16413. return object;
  16414. }
  16415. }
  16416. class SpotLightShadow extends LightShadow {
  16417. constructor() {
  16418. super( new PerspectiveCamera( 50, 1, 0.5, 500 ) );
  16419. this.isSpotLightShadow = true;
  16420. this.focus = 1;
  16421. }
  16422. updateMatrices( light ) {
  16423. const camera = this.camera;
  16424. const fov = RAD2DEG * 2 * light.angle * this.focus;
  16425. const aspect = this.mapSize.width / this.mapSize.height;
  16426. const far = light.distance || camera.far;
  16427. if ( fov !== camera.fov || aspect !== camera.aspect || far !== camera.far ) {
  16428. camera.fov = fov;
  16429. camera.aspect = aspect;
  16430. camera.far = far;
  16431. camera.updateProjectionMatrix();
  16432. }
  16433. super.updateMatrices( light );
  16434. }
  16435. copy( source ) {
  16436. super.copy( source );
  16437. this.focus = source.focus;
  16438. return this;
  16439. }
  16440. }
  16441. class SpotLight extends Light {
  16442. constructor( color, intensity, distance = 0, angle = Math.PI / 3, penumbra = 0, decay = 2 ) {
  16443. super( color, intensity );
  16444. this.isSpotLight = true;
  16445. this.type = 'SpotLight';
  16446. this.position.copy( Object3D.DEFAULT_UP );
  16447. this.updateMatrix();
  16448. this.target = new Object3D();
  16449. this.distance = distance;
  16450. this.angle = angle;
  16451. this.penumbra = penumbra;
  16452. this.decay = decay;
  16453. this.map = null;
  16454. this.shadow = new SpotLightShadow();
  16455. }
  16456. get power() {
  16457. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16458. // by convention for a spotlight, luminous power (lm) = π * luminous intensity (cd)
  16459. return this.intensity * Math.PI;
  16460. }
  16461. set power( power ) {
  16462. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16463. this.intensity = power / Math.PI;
  16464. }
  16465. dispose() {
  16466. this.shadow.dispose();
  16467. }
  16468. copy( source, recursive ) {
  16469. super.copy( source, recursive );
  16470. this.distance = source.distance;
  16471. this.angle = source.angle;
  16472. this.penumbra = source.penumbra;
  16473. this.decay = source.decay;
  16474. this.target = source.target.clone();
  16475. this.shadow = source.shadow.clone();
  16476. return this;
  16477. }
  16478. }
  16479. const _projScreenMatrix = /*@__PURE__*/ new Matrix4();
  16480. const _lightPositionWorld = /*@__PURE__*/ new Vector3();
  16481. const _lookTarget = /*@__PURE__*/ new Vector3();
  16482. class PointLightShadow extends LightShadow {
  16483. constructor() {
  16484. super( new PerspectiveCamera( 90, 1, 0.5, 500 ) );
  16485. this.isPointLightShadow = true;
  16486. this._frameExtents = new Vector2( 4, 2 );
  16487. this._viewportCount = 6;
  16488. this._viewports = [
  16489. // These viewports map a cube-map onto a 2D texture with the
  16490. // following orientation:
  16491. //
  16492. // xzXZ
  16493. // y Y
  16494. //
  16495. // X - Positive x direction
  16496. // x - Negative x direction
  16497. // Y - Positive y direction
  16498. // y - Negative y direction
  16499. // Z - Positive z direction
  16500. // z - Negative z direction
  16501. // positive X
  16502. new Vector4( 2, 1, 1, 1 ),
  16503. // negative X
  16504. new Vector4( 0, 1, 1, 1 ),
  16505. // positive Z
  16506. new Vector4( 3, 1, 1, 1 ),
  16507. // negative Z
  16508. new Vector4( 1, 1, 1, 1 ),
  16509. // positive Y
  16510. new Vector4( 3, 0, 1, 1 ),
  16511. // negative Y
  16512. new Vector4( 1, 0, 1, 1 )
  16513. ];
  16514. this._cubeDirections = [
  16515. new Vector3( 1, 0, 0 ), new Vector3( - 1, 0, 0 ), new Vector3( 0, 0, 1 ),
  16516. new Vector3( 0, 0, - 1 ), new Vector3( 0, 1, 0 ), new Vector3( 0, - 1, 0 )
  16517. ];
  16518. this._cubeUps = [
  16519. new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ), new Vector3( 0, 1, 0 ),
  16520. new Vector3( 0, 1, 0 ), new Vector3( 0, 0, 1 ), new Vector3( 0, 0, - 1 )
  16521. ];
  16522. }
  16523. updateMatrices( light, viewportIndex = 0 ) {
  16524. const camera = this.camera;
  16525. const shadowMatrix = this.matrix;
  16526. const far = light.distance || camera.far;
  16527. if ( far !== camera.far ) {
  16528. camera.far = far;
  16529. camera.updateProjectionMatrix();
  16530. }
  16531. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  16532. camera.position.copy( _lightPositionWorld );
  16533. _lookTarget.copy( camera.position );
  16534. _lookTarget.add( this._cubeDirections[ viewportIndex ] );
  16535. camera.up.copy( this._cubeUps[ viewportIndex ] );
  16536. camera.lookAt( _lookTarget );
  16537. camera.updateMatrixWorld();
  16538. shadowMatrix.makeTranslation( - _lightPositionWorld.x, - _lightPositionWorld.y, - _lightPositionWorld.z );
  16539. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  16540. this._frustum.setFromProjectionMatrix( _projScreenMatrix );
  16541. }
  16542. }
  16543. class PointLight extends Light {
  16544. constructor( color, intensity, distance = 0, decay = 2 ) {
  16545. super( color, intensity );
  16546. this.isPointLight = true;
  16547. this.type = 'PointLight';
  16548. this.distance = distance;
  16549. this.decay = decay;
  16550. this.shadow = new PointLightShadow();
  16551. }
  16552. get power() {
  16553. // compute the light's luminous power (in lumens) from its intensity (in candela)
  16554. // for an isotropic light source, luminous power (lm) = 4 π luminous intensity (cd)
  16555. return this.intensity * 4 * Math.PI;
  16556. }
  16557. set power( power ) {
  16558. // set the light's intensity (in candela) from the desired luminous power (in lumens)
  16559. this.intensity = power / ( 4 * Math.PI );
  16560. }
  16561. dispose() {
  16562. this.shadow.dispose();
  16563. }
  16564. copy( source, recursive ) {
  16565. super.copy( source, recursive );
  16566. this.distance = source.distance;
  16567. this.decay = source.decay;
  16568. this.shadow = source.shadow.clone();
  16569. return this;
  16570. }
  16571. }
  16572. class OrthographicCamera extends Camera {
  16573. constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
  16574. super();
  16575. this.isOrthographicCamera = true;
  16576. this.type = 'OrthographicCamera';
  16577. this.zoom = 1;
  16578. this.view = null;
  16579. this.left = left;
  16580. this.right = right;
  16581. this.top = top;
  16582. this.bottom = bottom;
  16583. this.near = near;
  16584. this.far = far;
  16585. this.updateProjectionMatrix();
  16586. }
  16587. copy( source, recursive ) {
  16588. super.copy( source, recursive );
  16589. this.left = source.left;
  16590. this.right = source.right;
  16591. this.top = source.top;
  16592. this.bottom = source.bottom;
  16593. this.near = source.near;
  16594. this.far = source.far;
  16595. this.zoom = source.zoom;
  16596. this.view = source.view === null ? null : Object.assign( {}, source.view );
  16597. return this;
  16598. }
  16599. setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
  16600. if ( this.view === null ) {
  16601. this.view = {
  16602. enabled: true,
  16603. fullWidth: 1,
  16604. fullHeight: 1,
  16605. offsetX: 0,
  16606. offsetY: 0,
  16607. width: 1,
  16608. height: 1
  16609. };
  16610. }
  16611. this.view.enabled = true;
  16612. this.view.fullWidth = fullWidth;
  16613. this.view.fullHeight = fullHeight;
  16614. this.view.offsetX = x;
  16615. this.view.offsetY = y;
  16616. this.view.width = width;
  16617. this.view.height = height;
  16618. this.updateProjectionMatrix();
  16619. }
  16620. clearViewOffset() {
  16621. if ( this.view !== null ) {
  16622. this.view.enabled = false;
  16623. }
  16624. this.updateProjectionMatrix();
  16625. }
  16626. updateProjectionMatrix() {
  16627. const dx = ( this.right - this.left ) / ( 2 * this.zoom );
  16628. const dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  16629. const cx = ( this.right + this.left ) / 2;
  16630. const cy = ( this.top + this.bottom ) / 2;
  16631. let left = cx - dx;
  16632. let right = cx + dx;
  16633. let top = cy + dy;
  16634. let bottom = cy - dy;
  16635. if ( this.view !== null && this.view.enabled ) {
  16636. const scaleW = ( this.right - this.left ) / this.view.fullWidth / this.zoom;
  16637. const scaleH = ( this.top - this.bottom ) / this.view.fullHeight / this.zoom;
  16638. left += scaleW * this.view.offsetX;
  16639. right = left + scaleW * this.view.width;
  16640. top -= scaleH * this.view.offsetY;
  16641. bottom = top - scaleH * this.view.height;
  16642. }
  16643. this.projectionMatrix.makeOrthographic( left, right, top, bottom, this.near, this.far, this.coordinateSystem );
  16644. this.projectionMatrixInverse.copy( this.projectionMatrix ).invert();
  16645. }
  16646. toJSON( meta ) {
  16647. const data = super.toJSON( meta );
  16648. data.object.zoom = this.zoom;
  16649. data.object.left = this.left;
  16650. data.object.right = this.right;
  16651. data.object.top = this.top;
  16652. data.object.bottom = this.bottom;
  16653. data.object.near = this.near;
  16654. data.object.far = this.far;
  16655. if ( this.view !== null ) data.object.view = Object.assign( {}, this.view );
  16656. return data;
  16657. }
  16658. }
  16659. class DirectionalLightShadow extends LightShadow {
  16660. constructor() {
  16661. super( new OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  16662. this.isDirectionalLightShadow = true;
  16663. }
  16664. }
  16665. class DirectionalLight extends Light {
  16666. constructor( color, intensity ) {
  16667. super( color, intensity );
  16668. this.isDirectionalLight = true;
  16669. this.type = 'DirectionalLight';
  16670. this.position.copy( Object3D.DEFAULT_UP );
  16671. this.updateMatrix();
  16672. this.target = new Object3D();
  16673. this.shadow = new DirectionalLightShadow();
  16674. }
  16675. dispose() {
  16676. this.shadow.dispose();
  16677. }
  16678. copy( source ) {
  16679. super.copy( source );
  16680. this.target = source.target.clone();
  16681. this.shadow = source.shadow.clone();
  16682. return this;
  16683. }
  16684. }
  16685. class AmbientLight extends Light {
  16686. constructor( color, intensity ) {
  16687. super( color, intensity );
  16688. this.isAmbientLight = true;
  16689. this.type = 'AmbientLight';
  16690. }
  16691. }
  16692. class RectAreaLight extends Light {
  16693. constructor( color, intensity, width = 10, height = 10 ) {
  16694. super( color, intensity );
  16695. this.isRectAreaLight = true;
  16696. this.type = 'RectAreaLight';
  16697. this.width = width;
  16698. this.height = height;
  16699. }
  16700. get power() {
  16701. // compute the light's luminous power (in lumens) from its intensity (in nits)
  16702. return this.intensity * this.width * this.height * Math.PI;
  16703. }
  16704. set power( power ) {
  16705. // set the light's intensity (in nits) from the desired luminous power (in lumens)
  16706. this.intensity = power / ( this.width * this.height * Math.PI );
  16707. }
  16708. copy( source ) {
  16709. super.copy( source );
  16710. this.width = source.width;
  16711. this.height = source.height;
  16712. return this;
  16713. }
  16714. toJSON( meta ) {
  16715. const data = super.toJSON( meta );
  16716. data.object.width = this.width;
  16717. data.object.height = this.height;
  16718. return data;
  16719. }
  16720. }
  16721. /**
  16722. * Primary reference:
  16723. * https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16724. *
  16725. * Secondary reference:
  16726. * https://www.ppsloan.org/publications/StupidSH36.pdf
  16727. */
  16728. // 3-band SH defined by 9 coefficients
  16729. class SphericalHarmonics3 {
  16730. constructor() {
  16731. this.isSphericalHarmonics3 = true;
  16732. this.coefficients = [];
  16733. for ( let i = 0; i < 9; i ++ ) {
  16734. this.coefficients.push( new Vector3() );
  16735. }
  16736. }
  16737. set( coefficients ) {
  16738. for ( let i = 0; i < 9; i ++ ) {
  16739. this.coefficients[ i ].copy( coefficients[ i ] );
  16740. }
  16741. return this;
  16742. }
  16743. zero() {
  16744. for ( let i = 0; i < 9; i ++ ) {
  16745. this.coefficients[ i ].set( 0, 0, 0 );
  16746. }
  16747. return this;
  16748. }
  16749. // get the radiance in the direction of the normal
  16750. // target is a Vector3
  16751. getAt( normal, target ) {
  16752. // normal is assumed to be unit length
  16753. const x = normal.x, y = normal.y, z = normal.z;
  16754. const coeff = this.coefficients;
  16755. // band 0
  16756. target.copy( coeff[ 0 ] ).multiplyScalar( 0.282095 );
  16757. // band 1
  16758. target.addScaledVector( coeff[ 1 ], 0.488603 * y );
  16759. target.addScaledVector( coeff[ 2 ], 0.488603 * z );
  16760. target.addScaledVector( coeff[ 3 ], 0.488603 * x );
  16761. // band 2
  16762. target.addScaledVector( coeff[ 4 ], 1.092548 * ( x * y ) );
  16763. target.addScaledVector( coeff[ 5 ], 1.092548 * ( y * z ) );
  16764. target.addScaledVector( coeff[ 6 ], 0.315392 * ( 3.0 * z * z - 1.0 ) );
  16765. target.addScaledVector( coeff[ 7 ], 1.092548 * ( x * z ) );
  16766. target.addScaledVector( coeff[ 8 ], 0.546274 * ( x * x - y * y ) );
  16767. return target;
  16768. }
  16769. // get the irradiance (radiance convolved with cosine lobe) in the direction of the normal
  16770. // target is a Vector3
  16771. // https://graphics.stanford.edu/papers/envmap/envmap.pdf
  16772. getIrradianceAt( normal, target ) {
  16773. // normal is assumed to be unit length
  16774. const x = normal.x, y = normal.y, z = normal.z;
  16775. const coeff = this.coefficients;
  16776. // band 0
  16777. target.copy( coeff[ 0 ] ).multiplyScalar( 0.886227 ); // π * 0.282095
  16778. // band 1
  16779. target.addScaledVector( coeff[ 1 ], 2.0 * 0.511664 * y ); // ( 2 * π / 3 ) * 0.488603
  16780. target.addScaledVector( coeff[ 2 ], 2.0 * 0.511664 * z );
  16781. target.addScaledVector( coeff[ 3 ], 2.0 * 0.511664 * x );
  16782. // band 2
  16783. target.addScaledVector( coeff[ 4 ], 2.0 * 0.429043 * x * y ); // ( π / 4 ) * 1.092548
  16784. target.addScaledVector( coeff[ 5 ], 2.0 * 0.429043 * y * z );
  16785. target.addScaledVector( coeff[ 6 ], 0.743125 * z * z - 0.247708 ); // ( π / 4 ) * 0.315392 * 3
  16786. target.addScaledVector( coeff[ 7 ], 2.0 * 0.429043 * x * z );
  16787. target.addScaledVector( coeff[ 8 ], 0.429043 * ( x * x - y * y ) ); // ( π / 4 ) * 0.546274
  16788. return target;
  16789. }
  16790. add( sh ) {
  16791. for ( let i = 0; i < 9; i ++ ) {
  16792. this.coefficients[ i ].add( sh.coefficients[ i ] );
  16793. }
  16794. return this;
  16795. }
  16796. addScaledSH( sh, s ) {
  16797. for ( let i = 0; i < 9; i ++ ) {
  16798. this.coefficients[ i ].addScaledVector( sh.coefficients[ i ], s );
  16799. }
  16800. return this;
  16801. }
  16802. scale( s ) {
  16803. for ( let i = 0; i < 9; i ++ ) {
  16804. this.coefficients[ i ].multiplyScalar( s );
  16805. }
  16806. return this;
  16807. }
  16808. lerp( sh, alpha ) {
  16809. for ( let i = 0; i < 9; i ++ ) {
  16810. this.coefficients[ i ].lerp( sh.coefficients[ i ], alpha );
  16811. }
  16812. return this;
  16813. }
  16814. equals( sh ) {
  16815. for ( let i = 0; i < 9; i ++ ) {
  16816. if ( ! this.coefficients[ i ].equals( sh.coefficients[ i ] ) ) {
  16817. return false;
  16818. }
  16819. }
  16820. return true;
  16821. }
  16822. copy( sh ) {
  16823. return this.set( sh.coefficients );
  16824. }
  16825. clone() {
  16826. return new this.constructor().copy( this );
  16827. }
  16828. fromArray( array, offset = 0 ) {
  16829. const coefficients = this.coefficients;
  16830. for ( let i = 0; i < 9; i ++ ) {
  16831. coefficients[ i ].fromArray( array, offset + ( i * 3 ) );
  16832. }
  16833. return this;
  16834. }
  16835. toArray( array = [], offset = 0 ) {
  16836. const coefficients = this.coefficients;
  16837. for ( let i = 0; i < 9; i ++ ) {
  16838. coefficients[ i ].toArray( array, offset + ( i * 3 ) );
  16839. }
  16840. return array;
  16841. }
  16842. // evaluate the basis functions
  16843. // shBasis is an Array[ 9 ]
  16844. static getBasisAt( normal, shBasis ) {
  16845. // normal is assumed to be unit length
  16846. const x = normal.x, y = normal.y, z = normal.z;
  16847. // band 0
  16848. shBasis[ 0 ] = 0.282095;
  16849. // band 1
  16850. shBasis[ 1 ] = 0.488603 * y;
  16851. shBasis[ 2 ] = 0.488603 * z;
  16852. shBasis[ 3 ] = 0.488603 * x;
  16853. // band 2
  16854. shBasis[ 4 ] = 1.092548 * x * y;
  16855. shBasis[ 5 ] = 1.092548 * y * z;
  16856. shBasis[ 6 ] = 0.315392 * ( 3 * z * z - 1 );
  16857. shBasis[ 7 ] = 1.092548 * x * z;
  16858. shBasis[ 8 ] = 0.546274 * ( x * x - y * y );
  16859. }
  16860. }
  16861. class LightProbe extends Light {
  16862. constructor( sh = new SphericalHarmonics3(), intensity = 1 ) {
  16863. super( undefined, intensity );
  16864. this.isLightProbe = true;
  16865. this.sh = sh;
  16866. }
  16867. copy( source ) {
  16868. super.copy( source );
  16869. this.sh.copy( source.sh );
  16870. return this;
  16871. }
  16872. fromJSON( json ) {
  16873. this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
  16874. this.sh.fromArray( json.sh );
  16875. return this;
  16876. }
  16877. toJSON( meta ) {
  16878. const data = super.toJSON( meta );
  16879. data.object.sh = this.sh.toArray();
  16880. return data;
  16881. }
  16882. }
  16883. class MaterialLoader extends Loader {
  16884. constructor( manager ) {
  16885. super( manager );
  16886. this.textures = {};
  16887. }
  16888. load( url, onLoad, onProgress, onError ) {
  16889. const scope = this;
  16890. const loader = new FileLoader( scope.manager );
  16891. loader.setPath( scope.path );
  16892. loader.setRequestHeader( scope.requestHeader );
  16893. loader.setWithCredentials( scope.withCredentials );
  16894. loader.load( url, function ( text ) {
  16895. try {
  16896. onLoad( scope.parse( JSON.parse( text ) ) );
  16897. } catch ( e ) {
  16898. if ( onError ) {
  16899. onError( e );
  16900. } else {
  16901. console.error( e );
  16902. }
  16903. scope.manager.itemError( url );
  16904. }
  16905. }, onProgress, onError );
  16906. }
  16907. parse( json ) {
  16908. const textures = this.textures;
  16909. function getTexture( name ) {
  16910. if ( textures[ name ] === undefined ) {
  16911. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  16912. }
  16913. return textures[ name ];
  16914. }
  16915. const material = this.createMaterialFromType( json.type );
  16916. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  16917. if ( json.name !== undefined ) material.name = json.name;
  16918. if ( json.color !== undefined && material.color !== undefined ) material.color.setHex( json.color );
  16919. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  16920. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  16921. if ( json.sheen !== undefined ) material.sheen = json.sheen;
  16922. if ( json.sheenColor !== undefined ) material.sheenColor = new Color().setHex( json.sheenColor );
  16923. if ( json.sheenRoughness !== undefined ) material.sheenRoughness = json.sheenRoughness;
  16924. if ( json.emissive !== undefined && material.emissive !== undefined ) material.emissive.setHex( json.emissive );
  16925. if ( json.specular !== undefined && material.specular !== undefined ) material.specular.setHex( json.specular );
  16926. if ( json.specularIntensity !== undefined ) material.specularIntensity = json.specularIntensity;
  16927. if ( json.specularColor !== undefined && material.specularColor !== undefined ) material.specularColor.setHex( json.specularColor );
  16928. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  16929. if ( json.clearcoat !== undefined ) material.clearcoat = json.clearcoat;
  16930. if ( json.clearcoatRoughness !== undefined ) material.clearcoatRoughness = json.clearcoatRoughness;
  16931. if ( json.dispersion !== undefined ) material.dispersion = json.dispersion;
  16932. if ( json.iridescence !== undefined ) material.iridescence = json.iridescence;
  16933. if ( json.iridescenceIOR !== undefined ) material.iridescenceIOR = json.iridescenceIOR;
  16934. if ( json.iridescenceThicknessRange !== undefined ) material.iridescenceThicknessRange = json.iridescenceThicknessRange;
  16935. if ( json.transmission !== undefined ) material.transmission = json.transmission;
  16936. if ( json.thickness !== undefined ) material.thickness = json.thickness;
  16937. if ( json.attenuationDistance !== undefined ) material.attenuationDistance = json.attenuationDistance;
  16938. if ( json.attenuationColor !== undefined && material.attenuationColor !== undefined ) material.attenuationColor.setHex( json.attenuationColor );
  16939. if ( json.anisotropy !== undefined ) material.anisotropy = json.anisotropy;
  16940. if ( json.anisotropyRotation !== undefined ) material.anisotropyRotation = json.anisotropyRotation;
  16941. if ( json.fog !== undefined ) material.fog = json.fog;
  16942. if ( json.flatShading !== undefined ) material.flatShading = json.flatShading;
  16943. if ( json.blending !== undefined ) material.blending = json.blending;
  16944. if ( json.combine !== undefined ) material.combine = json.combine;
  16945. if ( json.side !== undefined ) material.side = json.side;
  16946. if ( json.shadowSide !== undefined ) material.shadowSide = json.shadowSide;
  16947. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  16948. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  16949. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  16950. if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
  16951. if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc;
  16952. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  16953. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  16954. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  16955. if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc;
  16956. if ( json.blendDst !== undefined ) material.blendDst = json.blendDst;
  16957. if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation;
  16958. if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha;
  16959. if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha;
  16960. if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha;
  16961. if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor );
  16962. if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha;
  16963. if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
  16964. if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
  16965. if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
  16966. if ( json.stencilFuncMask !== undefined ) material.stencilFuncMask = json.stencilFuncMask;
  16967. if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
  16968. if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
  16969. if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
  16970. if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
  16971. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  16972. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  16973. if ( json.wireframeLinecap !== undefined ) material.wireframeLinecap = json.wireframeLinecap;
  16974. if ( json.wireframeLinejoin !== undefined ) material.wireframeLinejoin = json.wireframeLinejoin;
  16975. if ( json.rotation !== undefined ) material.rotation = json.rotation;
  16976. if ( json.linewidth !== undefined ) material.linewidth = json.linewidth;
  16977. if ( json.dashSize !== undefined ) material.dashSize = json.dashSize;
  16978. if ( json.gapSize !== undefined ) material.gapSize = json.gapSize;
  16979. if ( json.scale !== undefined ) material.scale = json.scale;
  16980. if ( json.polygonOffset !== undefined ) material.polygonOffset = json.polygonOffset;
  16981. if ( json.polygonOffsetFactor !== undefined ) material.polygonOffsetFactor = json.polygonOffsetFactor;
  16982. if ( json.polygonOffsetUnits !== undefined ) material.polygonOffsetUnits = json.polygonOffsetUnits;
  16983. if ( json.dithering !== undefined ) material.dithering = json.dithering;
  16984. if ( json.alphaToCoverage !== undefined ) material.alphaToCoverage = json.alphaToCoverage;
  16985. if ( json.premultipliedAlpha !== undefined ) material.premultipliedAlpha = json.premultipliedAlpha;
  16986. if ( json.forceSinglePass !== undefined ) material.forceSinglePass = json.forceSinglePass;
  16987. if ( json.visible !== undefined ) material.visible = json.visible;
  16988. if ( json.toneMapped !== undefined ) material.toneMapped = json.toneMapped;
  16989. if ( json.userData !== undefined ) material.userData = json.userData;
  16990. if ( json.vertexColors !== undefined ) {
  16991. if ( typeof json.vertexColors === 'number' ) {
  16992. material.vertexColors = ( json.vertexColors > 0 ) ? true : false;
  16993. } else {
  16994. material.vertexColors = json.vertexColors;
  16995. }
  16996. }
  16997. // Shader Material
  16998. if ( json.uniforms !== undefined ) {
  16999. for ( const name in json.uniforms ) {
  17000. const uniform = json.uniforms[ name ];
  17001. material.uniforms[ name ] = {};
  17002. switch ( uniform.type ) {
  17003. case 't':
  17004. material.uniforms[ name ].value = getTexture( uniform.value );
  17005. break;
  17006. case 'c':
  17007. material.uniforms[ name ].value = new Color().setHex( uniform.value );
  17008. break;
  17009. case 'v2':
  17010. material.uniforms[ name ].value = new Vector2().fromArray( uniform.value );
  17011. break;
  17012. case 'v3':
  17013. material.uniforms[ name ].value = new Vector3().fromArray( uniform.value );
  17014. break;
  17015. case 'v4':
  17016. material.uniforms[ name ].value = new Vector4().fromArray( uniform.value );
  17017. break;
  17018. case 'm3':
  17019. material.uniforms[ name ].value = new Matrix3().fromArray( uniform.value );
  17020. break;
  17021. case 'm4':
  17022. material.uniforms[ name ].value = new Matrix4().fromArray( uniform.value );
  17023. break;
  17024. default:
  17025. material.uniforms[ name ].value = uniform.value;
  17026. }
  17027. }
  17028. }
  17029. if ( json.defines !== undefined ) material.defines = json.defines;
  17030. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  17031. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  17032. if ( json.glslVersion !== undefined ) material.glslVersion = json.glslVersion;
  17033. if ( json.extensions !== undefined ) {
  17034. for ( const key in json.extensions ) {
  17035. material.extensions[ key ] = json.extensions[ key ];
  17036. }
  17037. }
  17038. if ( json.lights !== undefined ) material.lights = json.lights;
  17039. if ( json.clipping !== undefined ) material.clipping = json.clipping;
  17040. // for PointsMaterial
  17041. if ( json.size !== undefined ) material.size = json.size;
  17042. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  17043. // maps
  17044. if ( json.map !== undefined ) material.map = getTexture( json.map );
  17045. if ( json.matcap !== undefined ) material.matcap = getTexture( json.matcap );
  17046. if ( json.alphaMap !== undefined ) material.alphaMap = getTexture( json.alphaMap );
  17047. if ( json.bumpMap !== undefined ) material.bumpMap = getTexture( json.bumpMap );
  17048. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  17049. if ( json.normalMap !== undefined ) material.normalMap = getTexture( json.normalMap );
  17050. if ( json.normalMapType !== undefined ) material.normalMapType = json.normalMapType;
  17051. if ( json.normalScale !== undefined ) {
  17052. let normalScale = json.normalScale;
  17053. if ( Array.isArray( normalScale ) === false ) {
  17054. // Blender exporter used to export a scalar. See #7459
  17055. normalScale = [ normalScale, normalScale ];
  17056. }
  17057. material.normalScale = new Vector2().fromArray( normalScale );
  17058. }
  17059. if ( json.displacementMap !== undefined ) material.displacementMap = getTexture( json.displacementMap );
  17060. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  17061. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  17062. if ( json.roughnessMap !== undefined ) material.roughnessMap = getTexture( json.roughnessMap );
  17063. if ( json.metalnessMap !== undefined ) material.metalnessMap = getTexture( json.metalnessMap );
  17064. if ( json.emissiveMap !== undefined ) material.emissiveMap = getTexture( json.emissiveMap );
  17065. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  17066. if ( json.specularMap !== undefined ) material.specularMap = getTexture( json.specularMap );
  17067. if ( json.specularIntensityMap !== undefined ) material.specularIntensityMap = getTexture( json.specularIntensityMap );
  17068. if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap );
  17069. if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
  17070. if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation );
  17071. if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
  17072. if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
  17073. if ( json.refractionRatio !== undefined ) material.refractionRatio = json.refractionRatio;
  17074. if ( json.lightMap !== undefined ) material.lightMap = getTexture( json.lightMap );
  17075. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  17076. if ( json.aoMap !== undefined ) material.aoMap = getTexture( json.aoMap );
  17077. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  17078. if ( json.gradientMap !== undefined ) material.gradientMap = getTexture( json.gradientMap );
  17079. if ( json.clearcoatMap !== undefined ) material.clearcoatMap = getTexture( json.clearcoatMap );
  17080. if ( json.clearcoatRoughnessMap !== undefined ) material.clearcoatRoughnessMap = getTexture( json.clearcoatRoughnessMap );
  17081. if ( json.clearcoatNormalMap !== undefined ) material.clearcoatNormalMap = getTexture( json.clearcoatNormalMap );
  17082. if ( json.clearcoatNormalScale !== undefined ) material.clearcoatNormalScale = new Vector2().fromArray( json.clearcoatNormalScale );
  17083. if ( json.iridescenceMap !== undefined ) material.iridescenceMap = getTexture( json.iridescenceMap );
  17084. if ( json.iridescenceThicknessMap !== undefined ) material.iridescenceThicknessMap = getTexture( json.iridescenceThicknessMap );
  17085. if ( json.transmissionMap !== undefined ) material.transmissionMap = getTexture( json.transmissionMap );
  17086. if ( json.thicknessMap !== undefined ) material.thicknessMap = getTexture( json.thicknessMap );
  17087. if ( json.anisotropyMap !== undefined ) material.anisotropyMap = getTexture( json.anisotropyMap );
  17088. if ( json.sheenColorMap !== undefined ) material.sheenColorMap = getTexture( json.sheenColorMap );
  17089. if ( json.sheenRoughnessMap !== undefined ) material.sheenRoughnessMap = getTexture( json.sheenRoughnessMap );
  17090. return material;
  17091. }
  17092. setTextures( value ) {
  17093. this.textures = value;
  17094. return this;
  17095. }
  17096. createMaterialFromType( type ) {
  17097. return MaterialLoader.createMaterialFromType( type );
  17098. }
  17099. static createMaterialFromType( type ) {
  17100. const materialLib = {
  17101. ShadowMaterial,
  17102. SpriteMaterial,
  17103. RawShaderMaterial,
  17104. ShaderMaterial,
  17105. PointsMaterial,
  17106. MeshPhysicalMaterial,
  17107. MeshStandardMaterial,
  17108. MeshPhongMaterial,
  17109. MeshToonMaterial,
  17110. MeshNormalMaterial,
  17111. MeshLambertMaterial,
  17112. MeshDepthMaterial,
  17113. MeshDistanceMaterial,
  17114. MeshBasicMaterial,
  17115. MeshMatcapMaterial,
  17116. LineDashedMaterial,
  17117. LineBasicMaterial,
  17118. Material
  17119. };
  17120. return new materialLib[ type ]();
  17121. }
  17122. }
  17123. class LoaderUtils {
  17124. static decodeText( array ) { // @deprecated, r165
  17125. console.warn( 'THREE.LoaderUtils: decodeText() has been deprecated with r165 and will be removed with r175. Use TextDecoder instead.' );
  17126. if ( typeof TextDecoder !== 'undefined' ) {
  17127. return new TextDecoder().decode( array );
  17128. }
  17129. // Avoid the String.fromCharCode.apply(null, array) shortcut, which
  17130. // throws a "maximum call stack size exceeded" error for large arrays.
  17131. let s = '';
  17132. for ( let i = 0, il = array.length; i < il; i ++ ) {
  17133. // Implicitly assumes little-endian.
  17134. s += String.fromCharCode( array[ i ] );
  17135. }
  17136. try {
  17137. // merges multi-byte utf-8 characters.
  17138. return decodeURIComponent( escape( s ) );
  17139. } catch ( e ) { // see #16358
  17140. return s;
  17141. }
  17142. }
  17143. static extractUrlBase( url ) {
  17144. const index = url.lastIndexOf( '/' );
  17145. if ( index === - 1 ) return './';
  17146. return url.slice( 0, index + 1 );
  17147. }
  17148. static resolveURL( url, path ) {
  17149. // Invalid URL
  17150. if ( typeof url !== 'string' || url === '' ) return '';
  17151. // Host Relative URL
  17152. if ( /^https?:\/\//i.test( path ) && /^\//.test( url ) ) {
  17153. path = path.replace( /(^https?:\/\/[^\/]+).*/i, '$1' );
  17154. }
  17155. // Absolute URL http://,https://,//
  17156. if ( /^(https?:)?\/\//i.test( url ) ) return url;
  17157. // Data URI
  17158. if ( /^data:.*,.*$/i.test( url ) ) return url;
  17159. // Blob URL
  17160. if ( /^blob:.*$/i.test( url ) ) return url;
  17161. // Relative URL
  17162. return path + url;
  17163. }
  17164. }
  17165. class InstancedBufferGeometry extends BufferGeometry {
  17166. constructor() {
  17167. super();
  17168. this.isInstancedBufferGeometry = true;
  17169. this.type = 'InstancedBufferGeometry';
  17170. this.instanceCount = Infinity;
  17171. }
  17172. copy( source ) {
  17173. super.copy( source );
  17174. this.instanceCount = source.instanceCount;
  17175. return this;
  17176. }
  17177. toJSON() {
  17178. const data = super.toJSON();
  17179. data.instanceCount = this.instanceCount;
  17180. data.isInstancedBufferGeometry = true;
  17181. return data;
  17182. }
  17183. }
  17184. class BufferGeometryLoader extends Loader {
  17185. constructor( manager ) {
  17186. super( manager );
  17187. }
  17188. load( url, onLoad, onProgress, onError ) {
  17189. const scope = this;
  17190. const loader = new FileLoader( scope.manager );
  17191. loader.setPath( scope.path );
  17192. loader.setRequestHeader( scope.requestHeader );
  17193. loader.setWithCredentials( scope.withCredentials );
  17194. loader.load( url, function ( text ) {
  17195. try {
  17196. onLoad( scope.parse( JSON.parse( text ) ) );
  17197. } catch ( e ) {
  17198. if ( onError ) {
  17199. onError( e );
  17200. } else {
  17201. console.error( e );
  17202. }
  17203. scope.manager.itemError( url );
  17204. }
  17205. }, onProgress, onError );
  17206. }
  17207. parse( json ) {
  17208. const interleavedBufferMap = {};
  17209. const arrayBufferMap = {};
  17210. function getInterleavedBuffer( json, uuid ) {
  17211. if ( interleavedBufferMap[ uuid ] !== undefined ) return interleavedBufferMap[ uuid ];
  17212. const interleavedBuffers = json.interleavedBuffers;
  17213. const interleavedBuffer = interleavedBuffers[ uuid ];
  17214. const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
  17215. const array = getTypedArray( interleavedBuffer.type, buffer );
  17216. const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
  17217. ib.uuid = interleavedBuffer.uuid;
  17218. interleavedBufferMap[ uuid ] = ib;
  17219. return ib;
  17220. }
  17221. function getArrayBuffer( json, uuid ) {
  17222. if ( arrayBufferMap[ uuid ] !== undefined ) return arrayBufferMap[ uuid ];
  17223. const arrayBuffers = json.arrayBuffers;
  17224. const arrayBuffer = arrayBuffers[ uuid ];
  17225. const ab = new Uint32Array( arrayBuffer ).buffer;
  17226. arrayBufferMap[ uuid ] = ab;
  17227. return ab;
  17228. }
  17229. const geometry = json.isInstancedBufferGeometry ? new InstancedBufferGeometry() : new BufferGeometry();
  17230. const index = json.data.index;
  17231. if ( index !== undefined ) {
  17232. const typedArray = getTypedArray( index.type, index.array );
  17233. geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
  17234. }
  17235. const attributes = json.data.attributes;
  17236. for ( const key in attributes ) {
  17237. const attribute = attributes[ key ];
  17238. let bufferAttribute;
  17239. if ( attribute.isInterleavedBufferAttribute ) {
  17240. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17241. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17242. } else {
  17243. const typedArray = getTypedArray( attribute.type, attribute.array );
  17244. const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
  17245. bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
  17246. }
  17247. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17248. if ( attribute.usage !== undefined ) bufferAttribute.setUsage( attribute.usage );
  17249. geometry.setAttribute( key, bufferAttribute );
  17250. }
  17251. const morphAttributes = json.data.morphAttributes;
  17252. if ( morphAttributes ) {
  17253. for ( const key in morphAttributes ) {
  17254. const attributeArray = morphAttributes[ key ];
  17255. const array = [];
  17256. for ( let i = 0, il = attributeArray.length; i < il; i ++ ) {
  17257. const attribute = attributeArray[ i ];
  17258. let bufferAttribute;
  17259. if ( attribute.isInterleavedBufferAttribute ) {
  17260. const interleavedBuffer = getInterleavedBuffer( json.data, attribute.data );
  17261. bufferAttribute = new InterleavedBufferAttribute( interleavedBuffer, attribute.itemSize, attribute.offset, attribute.normalized );
  17262. } else {
  17263. const typedArray = getTypedArray( attribute.type, attribute.array );
  17264. bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
  17265. }
  17266. if ( attribute.name !== undefined ) bufferAttribute.name = attribute.name;
  17267. array.push( bufferAttribute );
  17268. }
  17269. geometry.morphAttributes[ key ] = array;
  17270. }
  17271. }
  17272. const morphTargetsRelative = json.data.morphTargetsRelative;
  17273. if ( morphTargetsRelative ) {
  17274. geometry.morphTargetsRelative = true;
  17275. }
  17276. const groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  17277. if ( groups !== undefined ) {
  17278. for ( let i = 0, n = groups.length; i !== n; ++ i ) {
  17279. const group = groups[ i ];
  17280. geometry.addGroup( group.start, group.count, group.materialIndex );
  17281. }
  17282. }
  17283. const boundingSphere = json.data.boundingSphere;
  17284. if ( boundingSphere !== undefined ) {
  17285. const center = new Vector3();
  17286. if ( boundingSphere.center !== undefined ) {
  17287. center.fromArray( boundingSphere.center );
  17288. }
  17289. geometry.boundingSphere = new Sphere( center, boundingSphere.radius );
  17290. }
  17291. if ( json.name ) geometry.name = json.name;
  17292. if ( json.userData ) geometry.userData = json.userData;
  17293. return geometry;
  17294. }
  17295. }
  17296. class ObjectLoader extends Loader {
  17297. constructor( manager ) {
  17298. super( manager );
  17299. }
  17300. load( url, onLoad, onProgress, onError ) {
  17301. const scope = this;
  17302. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17303. this.resourcePath = this.resourcePath || path;
  17304. const loader = new FileLoader( this.manager );
  17305. loader.setPath( this.path );
  17306. loader.setRequestHeader( this.requestHeader );
  17307. loader.setWithCredentials( this.withCredentials );
  17308. loader.load( url, function ( text ) {
  17309. let json = null;
  17310. try {
  17311. json = JSON.parse( text );
  17312. } catch ( error ) {
  17313. if ( onError !== undefined ) onError( error );
  17314. console.error( 'THREE:ObjectLoader: Can\'t parse ' + url + '.', error.message );
  17315. return;
  17316. }
  17317. const metadata = json.metadata;
  17318. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17319. if ( onError !== undefined ) onError( new Error( 'THREE.ObjectLoader: Can\'t load ' + url ) );
  17320. console.error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17321. return;
  17322. }
  17323. scope.parse( json, onLoad );
  17324. }, onProgress, onError );
  17325. }
  17326. async loadAsync( url, onProgress ) {
  17327. const scope = this;
  17328. const path = ( this.path === '' ) ? LoaderUtils.extractUrlBase( url ) : this.path;
  17329. this.resourcePath = this.resourcePath || path;
  17330. const loader = new FileLoader( this.manager );
  17331. loader.setPath( this.path );
  17332. loader.setRequestHeader( this.requestHeader );
  17333. loader.setWithCredentials( this.withCredentials );
  17334. const text = await loader.loadAsync( url, onProgress );
  17335. const json = JSON.parse( text );
  17336. const metadata = json.metadata;
  17337. if ( metadata === undefined || metadata.type === undefined || metadata.type.toLowerCase() === 'geometry' ) {
  17338. throw new Error( 'THREE.ObjectLoader: Can\'t load ' + url );
  17339. }
  17340. return await scope.parseAsync( json );
  17341. }
  17342. parse( json, onLoad ) {
  17343. const animations = this.parseAnimations( json.animations );
  17344. const shapes = this.parseShapes( json.shapes );
  17345. const geometries = this.parseGeometries( json.geometries, shapes );
  17346. const images = this.parseImages( json.images, function () {
  17347. if ( onLoad !== undefined ) onLoad( object );
  17348. } );
  17349. const textures = this.parseTextures( json.textures, images );
  17350. const materials = this.parseMaterials( json.materials, textures );
  17351. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17352. const skeletons = this.parseSkeletons( json.skeletons, object );
  17353. this.bindSkeletons( object, skeletons );
  17354. this.bindLightTargets( object );
  17355. //
  17356. if ( onLoad !== undefined ) {
  17357. let hasImages = false;
  17358. for ( const uuid in images ) {
  17359. if ( images[ uuid ].data instanceof HTMLImageElement ) {
  17360. hasImages = true;
  17361. break;
  17362. }
  17363. }
  17364. if ( hasImages === false ) onLoad( object );
  17365. }
  17366. return object;
  17367. }
  17368. async parseAsync( json ) {
  17369. const animations = this.parseAnimations( json.animations );
  17370. const shapes = this.parseShapes( json.shapes );
  17371. const geometries = this.parseGeometries( json.geometries, shapes );
  17372. const images = await this.parseImagesAsync( json.images );
  17373. const textures = this.parseTextures( json.textures, images );
  17374. const materials = this.parseMaterials( json.materials, textures );
  17375. const object = this.parseObject( json.object, geometries, materials, textures, animations );
  17376. const skeletons = this.parseSkeletons( json.skeletons, object );
  17377. this.bindSkeletons( object, skeletons );
  17378. this.bindLightTargets( object );
  17379. return object;
  17380. }
  17381. parseShapes( json ) {
  17382. const shapes = {};
  17383. if ( json !== undefined ) {
  17384. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17385. const shape = new Shape().fromJSON( json[ i ] );
  17386. shapes[ shape.uuid ] = shape;
  17387. }
  17388. }
  17389. return shapes;
  17390. }
  17391. parseSkeletons( json, object ) {
  17392. const skeletons = {};
  17393. const bones = {};
  17394. // generate bone lookup table
  17395. object.traverse( function ( child ) {
  17396. if ( child.isBone ) bones[ child.uuid ] = child;
  17397. } );
  17398. // create skeletons
  17399. if ( json !== undefined ) {
  17400. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17401. const skeleton = new Skeleton().fromJSON( json[ i ], bones );
  17402. skeletons[ skeleton.uuid ] = skeleton;
  17403. }
  17404. }
  17405. return skeletons;
  17406. }
  17407. parseGeometries( json, shapes ) {
  17408. const geometries = {};
  17409. if ( json !== undefined ) {
  17410. const bufferGeometryLoader = new BufferGeometryLoader();
  17411. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17412. let geometry;
  17413. const data = json[ i ];
  17414. switch ( data.type ) {
  17415. case 'BufferGeometry':
  17416. case 'InstancedBufferGeometry':
  17417. geometry = bufferGeometryLoader.parse( data );
  17418. break;
  17419. default:
  17420. if ( data.type in Geometries ) {
  17421. geometry = Geometries[ data.type ].fromJSON( data, shapes );
  17422. } else {
  17423. console.warn( `THREE.ObjectLoader: Unsupported geometry type "${ data.type }"` );
  17424. }
  17425. }
  17426. geometry.uuid = data.uuid;
  17427. if ( data.name !== undefined ) geometry.name = data.name;
  17428. if ( data.userData !== undefined ) geometry.userData = data.userData;
  17429. geometries[ data.uuid ] = geometry;
  17430. }
  17431. }
  17432. return geometries;
  17433. }
  17434. parseMaterials( json, textures ) {
  17435. const cache = {}; // MultiMaterial
  17436. const materials = {};
  17437. if ( json !== undefined ) {
  17438. const loader = new MaterialLoader();
  17439. loader.setTextures( textures );
  17440. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17441. const data = json[ i ];
  17442. if ( cache[ data.uuid ] === undefined ) {
  17443. cache[ data.uuid ] = loader.parse( data );
  17444. }
  17445. materials[ data.uuid ] = cache[ data.uuid ];
  17446. }
  17447. }
  17448. return materials;
  17449. }
  17450. parseAnimations( json ) {
  17451. const animations = {};
  17452. if ( json !== undefined ) {
  17453. for ( let i = 0; i < json.length; i ++ ) {
  17454. const data = json[ i ];
  17455. const clip = AnimationClip.parse( data );
  17456. animations[ clip.uuid ] = clip;
  17457. }
  17458. }
  17459. return animations;
  17460. }
  17461. parseImages( json, onLoad ) {
  17462. const scope = this;
  17463. const images = {};
  17464. let loader;
  17465. function loadImage( url ) {
  17466. scope.manager.itemStart( url );
  17467. return loader.load( url, function () {
  17468. scope.manager.itemEnd( url );
  17469. }, undefined, function () {
  17470. scope.manager.itemError( url );
  17471. scope.manager.itemEnd( url );
  17472. } );
  17473. }
  17474. function deserializeImage( image ) {
  17475. if ( typeof image === 'string' ) {
  17476. const url = image;
  17477. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17478. return loadImage( path );
  17479. } else {
  17480. if ( image.data ) {
  17481. return {
  17482. data: getTypedArray( image.type, image.data ),
  17483. width: image.width,
  17484. height: image.height
  17485. };
  17486. } else {
  17487. return null;
  17488. }
  17489. }
  17490. }
  17491. if ( json !== undefined && json.length > 0 ) {
  17492. const manager = new LoadingManager( onLoad );
  17493. loader = new ImageLoader( manager );
  17494. loader.setCrossOrigin( this.crossOrigin );
  17495. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17496. const image = json[ i ];
  17497. const url = image.url;
  17498. if ( Array.isArray( url ) ) {
  17499. // load array of images e.g CubeTexture
  17500. const imageArray = [];
  17501. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17502. const currentUrl = url[ j ];
  17503. const deserializedImage = deserializeImage( currentUrl );
  17504. if ( deserializedImage !== null ) {
  17505. if ( deserializedImage instanceof HTMLImageElement ) {
  17506. imageArray.push( deserializedImage );
  17507. } else {
  17508. // special case: handle array of data textures for cube textures
  17509. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17510. }
  17511. }
  17512. }
  17513. images[ image.uuid ] = new Source( imageArray );
  17514. } else {
  17515. // load single image
  17516. const deserializedImage = deserializeImage( image.url );
  17517. images[ image.uuid ] = new Source( deserializedImage );
  17518. }
  17519. }
  17520. }
  17521. return images;
  17522. }
  17523. async parseImagesAsync( json ) {
  17524. const scope = this;
  17525. const images = {};
  17526. let loader;
  17527. async function deserializeImage( image ) {
  17528. if ( typeof image === 'string' ) {
  17529. const url = image;
  17530. const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
  17531. return await loader.loadAsync( path );
  17532. } else {
  17533. if ( image.data ) {
  17534. return {
  17535. data: getTypedArray( image.type, image.data ),
  17536. width: image.width,
  17537. height: image.height
  17538. };
  17539. } else {
  17540. return null;
  17541. }
  17542. }
  17543. }
  17544. if ( json !== undefined && json.length > 0 ) {
  17545. loader = new ImageLoader( this.manager );
  17546. loader.setCrossOrigin( this.crossOrigin );
  17547. for ( let i = 0, il = json.length; i < il; i ++ ) {
  17548. const image = json[ i ];
  17549. const url = image.url;
  17550. if ( Array.isArray( url ) ) {
  17551. // load array of images e.g CubeTexture
  17552. const imageArray = [];
  17553. for ( let j = 0, jl = url.length; j < jl; j ++ ) {
  17554. const currentUrl = url[ j ];
  17555. const deserializedImage = await deserializeImage( currentUrl );
  17556. if ( deserializedImage !== null ) {
  17557. if ( deserializedImage instanceof HTMLImageElement ) {
  17558. imageArray.push( deserializedImage );
  17559. } else {
  17560. // special case: handle array of data textures for cube textures
  17561. imageArray.push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
  17562. }
  17563. }
  17564. }
  17565. images[ image.uuid ] = new Source( imageArray );
  17566. } else {
  17567. // load single image
  17568. const deserializedImage = await deserializeImage( image.url );
  17569. images[ image.uuid ] = new Source( deserializedImage );
  17570. }
  17571. }
  17572. }
  17573. return images;
  17574. }
  17575. parseTextures( json, images ) {
  17576. function parseConstant( value, type ) {
  17577. if ( typeof value === 'number' ) return value;
  17578. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  17579. return type[ value ];
  17580. }
  17581. const textures = {};
  17582. if ( json !== undefined ) {
  17583. for ( let i = 0, l = json.length; i < l; i ++ ) {
  17584. const data = json[ i ];
  17585. if ( data.image === undefined ) {
  17586. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  17587. }
  17588. if ( images[ data.image ] === undefined ) {
  17589. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  17590. }
  17591. const source = images[ data.image ];
  17592. const image = source.data;
  17593. let texture;
  17594. if ( Array.isArray( image ) ) {
  17595. texture = new CubeTexture();
  17596. if ( image.length === 6 ) texture.needsUpdate = true;
  17597. } else {
  17598. if ( image && image.data ) {
  17599. texture = new DataTexture();
  17600. } else {
  17601. texture = new Texture();
  17602. }
  17603. if ( image ) texture.needsUpdate = true; // textures can have undefined image data
  17604. }
  17605. texture.source = source;
  17606. texture.uuid = data.uuid;
  17607. if ( data.name !== undefined ) texture.name = data.name;
  17608. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping, TEXTURE_MAPPING );
  17609. if ( data.channel !== undefined ) texture.channel = data.channel;
  17610. if ( data.offset !== undefined ) texture.offset.fromArray( data.offset );
  17611. if ( data.repeat !== undefined ) texture.repeat.fromArray( data.repeat );
  17612. if ( data.center !== undefined ) texture.center.fromArray( data.center );
  17613. if ( data.rotation !== undefined ) texture.rotation = data.rotation;
  17614. if ( data.wrap !== undefined ) {
  17615. texture.wrapS = parseConstant( data.wrap[ 0 ], TEXTURE_WRAPPING );
  17616. texture.wrapT = parseConstant( data.wrap[ 1 ], TEXTURE_WRAPPING );
  17617. }
  17618. if ( data.format !== undefined ) texture.format = data.format;
  17619. if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat;
  17620. if ( data.type !== undefined ) texture.type = data.type;
  17621. if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace;
  17622. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
  17623. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
  17624. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  17625. if ( data.flipY !== undefined ) texture.flipY = data.flipY;
  17626. if ( data.generateMipmaps !== undefined ) texture.generateMipmaps = data.generateMipmaps;
  17627. if ( data.premultiplyAlpha !== undefined ) texture.premultiplyAlpha = data.premultiplyAlpha;
  17628. if ( data.unpackAlignment !== undefined ) texture.unpackAlignment = data.unpackAlignment;
  17629. if ( data.compareFunction !== undefined ) texture.compareFunction = data.compareFunction;
  17630. if ( data.userData !== undefined ) texture.userData = data.userData;
  17631. textures[ data.uuid ] = texture;
  17632. }
  17633. }
  17634. return textures;
  17635. }
  17636. parseObject( data, geometries, materials, textures, animations ) {
  17637. let object;
  17638. function getGeometry( name ) {
  17639. if ( geometries[ name ] === undefined ) {
  17640. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  17641. }
  17642. return geometries[ name ];
  17643. }
  17644. function getMaterial( name ) {
  17645. if ( name === undefined ) return undefined;
  17646. if ( Array.isArray( name ) ) {
  17647. const array = [];
  17648. for ( let i = 0, l = name.length; i < l; i ++ ) {
  17649. const uuid = name[ i ];
  17650. if ( materials[ uuid ] === undefined ) {
  17651. console.warn( 'THREE.ObjectLoader: Undefined material', uuid );
  17652. }
  17653. array.push( materials[ uuid ] );
  17654. }
  17655. return array;
  17656. }
  17657. if ( materials[ name ] === undefined ) {
  17658. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  17659. }
  17660. return materials[ name ];
  17661. }
  17662. function getTexture( uuid ) {
  17663. if ( textures[ uuid ] === undefined ) {
  17664. console.warn( 'THREE.ObjectLoader: Undefined texture', uuid );
  17665. }
  17666. return textures[ uuid ];
  17667. }
  17668. let geometry, material;
  17669. switch ( data.type ) {
  17670. case 'Scene':
  17671. object = new Scene();
  17672. if ( data.background !== undefined ) {
  17673. if ( Number.isInteger( data.background ) ) {
  17674. object.background = new Color( data.background );
  17675. } else {
  17676. object.background = getTexture( data.background );
  17677. }
  17678. }
  17679. if ( data.environment !== undefined ) {
  17680. object.environment = getTexture( data.environment );
  17681. }
  17682. if ( data.fog !== undefined ) {
  17683. if ( data.fog.type === 'Fog' ) {
  17684. object.fog = new Fog( data.fog.color, data.fog.near, data.fog.far );
  17685. } else if ( data.fog.type === 'FogExp2' ) {
  17686. object.fog = new FogExp2( data.fog.color, data.fog.density );
  17687. }
  17688. if ( data.fog.name !== '' ) {
  17689. object.fog.name = data.fog.name;
  17690. }
  17691. }
  17692. if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
  17693. if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
  17694. if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );
  17695. if ( data.environmentIntensity !== undefined ) object.environmentIntensity = data.environmentIntensity;
  17696. if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );
  17697. break;
  17698. case 'PerspectiveCamera':
  17699. object = new PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  17700. if ( data.focus !== undefined ) object.focus = data.focus;
  17701. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17702. if ( data.filmGauge !== undefined ) object.filmGauge = data.filmGauge;
  17703. if ( data.filmOffset !== undefined ) object.filmOffset = data.filmOffset;
  17704. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17705. break;
  17706. case 'OrthographicCamera':
  17707. object = new OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  17708. if ( data.zoom !== undefined ) object.zoom = data.zoom;
  17709. if ( data.view !== undefined ) object.view = Object.assign( {}, data.view );
  17710. break;
  17711. case 'AmbientLight':
  17712. object = new AmbientLight( data.color, data.intensity );
  17713. break;
  17714. case 'DirectionalLight':
  17715. object = new DirectionalLight( data.color, data.intensity );
  17716. object.target = data.target || '';
  17717. break;
  17718. case 'PointLight':
  17719. object = new PointLight( data.color, data.intensity, data.distance, data.decay );
  17720. break;
  17721. case 'RectAreaLight':
  17722. object = new RectAreaLight( data.color, data.intensity, data.width, data.height );
  17723. break;
  17724. case 'SpotLight':
  17725. object = new SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  17726. object.target = data.target || '';
  17727. break;
  17728. case 'HemisphereLight':
  17729. object = new HemisphereLight( data.color, data.groundColor, data.intensity );
  17730. break;
  17731. case 'LightProbe':
  17732. object = new LightProbe().fromJSON( data );
  17733. break;
  17734. case 'SkinnedMesh':
  17735. geometry = getGeometry( data.geometry );
  17736. material = getMaterial( data.material );
  17737. object = new SkinnedMesh( geometry, material );
  17738. if ( data.bindMode !== undefined ) object.bindMode = data.bindMode;
  17739. if ( data.bindMatrix !== undefined ) object.bindMatrix.fromArray( data.bindMatrix );
  17740. if ( data.skeleton !== undefined ) object.skeleton = data.skeleton;
  17741. break;
  17742. case 'Mesh':
  17743. geometry = getGeometry( data.geometry );
  17744. material = getMaterial( data.material );
  17745. object = new Mesh( geometry, material );
  17746. break;
  17747. case 'InstancedMesh':
  17748. geometry = getGeometry( data.geometry );
  17749. material = getMaterial( data.material );
  17750. const count = data.count;
  17751. const instanceMatrix = data.instanceMatrix;
  17752. const instanceColor = data.instanceColor;
  17753. object = new InstancedMesh( geometry, material, count );
  17754. object.instanceMatrix = new InstancedBufferAttribute( new Float32Array( instanceMatrix.array ), 16 );
  17755. if ( instanceColor !== undefined ) object.instanceColor = new InstancedBufferAttribute( new Float32Array( instanceColor.array ), instanceColor.itemSize );
  17756. break;
  17757. case 'BatchedMesh':
  17758. geometry = getGeometry( data.geometry );
  17759. material = getMaterial( data.material );
  17760. object = new BatchedMesh( data.maxInstanceCount, data.maxVertexCount, data.maxIndexCount, material );
  17761. object.geometry = geometry;
  17762. object.perObjectFrustumCulled = data.perObjectFrustumCulled;
  17763. object.sortObjects = data.sortObjects;
  17764. object._drawRanges = data.drawRanges;
  17765. object._reservedRanges = data.reservedRanges;
  17766. object._visibility = data.visibility;
  17767. object._active = data.active;
  17768. object._bounds = data.bounds.map( bound => {
  17769. const box = new Box3();
  17770. box.min.fromArray( bound.boxMin );
  17771. box.max.fromArray( bound.boxMax );
  17772. const sphere = new Sphere();
  17773. sphere.radius = bound.sphereRadius;
  17774. sphere.center.fromArray( bound.sphereCenter );
  17775. return {
  17776. boxInitialized: bound.boxInitialized,
  17777. box: box,
  17778. sphereInitialized: bound.sphereInitialized,
  17779. sphere: sphere
  17780. };
  17781. } );
  17782. object._maxInstanceCount = data.maxInstanceCount;
  17783. object._maxVertexCount = data.maxVertexCount;
  17784. object._maxIndexCount = data.maxIndexCount;
  17785. object._geometryInitialized = data.geometryInitialized;
  17786. object._geometryCount = data.geometryCount;
  17787. object._matricesTexture = getTexture( data.matricesTexture.uuid );
  17788. if ( data.colorsTexture !== undefined ) object._colorsTexture = getTexture( data.colorsTexture.uuid );
  17789. break;
  17790. case 'LOD':
  17791. object = new LOD();
  17792. break;
  17793. case 'Line':
  17794. object = new Line( getGeometry( data.geometry ), getMaterial( data.material ) );
  17795. break;
  17796. case 'LineLoop':
  17797. object = new LineLoop( getGeometry( data.geometry ), getMaterial( data.material ) );
  17798. break;
  17799. case 'LineSegments':
  17800. object = new LineSegments( getGeometry( data.geometry ), getMaterial( data.material ) );
  17801. break;
  17802. case 'PointCloud':
  17803. case 'Points':
  17804. object = new Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  17805. break;
  17806. case 'Sprite':
  17807. object = new Sprite( getMaterial( data.material ) );
  17808. break;
  17809. case 'Group':
  17810. object = new Group();
  17811. break;
  17812. case 'Bone':
  17813. object = new Bone();
  17814. break;
  17815. default:
  17816. object = new Object3D();
  17817. }
  17818. object.uuid = data.uuid;
  17819. if ( data.name !== undefined ) object.name = data.name;
  17820. if ( data.matrix !== undefined ) {
  17821. object.matrix.fromArray( data.matrix );
  17822. if ( data.matrixAutoUpdate !== undefined ) object.matrixAutoUpdate = data.matrixAutoUpdate;
  17823. if ( object.matrixAutoUpdate ) object.matrix.decompose( object.position, object.quaternion, object.scale );
  17824. } else {
  17825. if ( data.position !== undefined ) object.position.fromArray( data.position );
  17826. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  17827. if ( data.quaternion !== undefined ) object.quaternion.fromArray( data.quaternion );
  17828. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  17829. }
  17830. if ( data.up !== undefined ) object.up.fromArray( data.up );
  17831. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  17832. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  17833. if ( data.shadow ) {
  17834. if ( data.shadow.intensity !== undefined ) object.shadow.intensity = data.shadow.intensity;
  17835. if ( data.shadow.bias !== undefined ) object.shadow.bias = data.shadow.bias;
  17836. if ( data.shadow.normalBias !== undefined ) object.shadow.normalBias = data.shadow.normalBias;
  17837. if ( data.shadow.radius !== undefined ) object.shadow.radius = data.shadow.radius;
  17838. if ( data.shadow.mapSize !== undefined ) object.shadow.mapSize.fromArray( data.shadow.mapSize );
  17839. if ( data.shadow.camera !== undefined ) object.shadow.camera = this.parseObject( data.shadow.camera );
  17840. }
  17841. if ( data.visible !== undefined ) object.visible = data.visible;
  17842. if ( data.frustumCulled !== undefined ) object.frustumCulled = data.frustumCulled;
  17843. if ( data.renderOrder !== undefined ) object.renderOrder = data.renderOrder;
  17844. if ( data.userData !== undefined ) object.userData = data.userData;
  17845. if ( data.layers !== undefined ) object.layers.mask = data.layers;
  17846. if ( data.children !== undefined ) {
  17847. const children = data.children;
  17848. for ( let i = 0; i < children.length; i ++ ) {
  17849. object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
  17850. }
  17851. }
  17852. if ( data.animations !== undefined ) {
  17853. const objectAnimations = data.animations;
  17854. for ( let i = 0; i < objectAnimations.length; i ++ ) {
  17855. const uuid = objectAnimations[ i ];
  17856. object.animations.push( animations[ uuid ] );
  17857. }
  17858. }
  17859. if ( data.type === 'LOD' ) {
  17860. if ( data.autoUpdate !== undefined ) object.autoUpdate = data.autoUpdate;
  17861. const levels = data.levels;
  17862. for ( let l = 0; l < levels.length; l ++ ) {
  17863. const level = levels[ l ];
  17864. const child = object.getObjectByProperty( 'uuid', level.object );
  17865. if ( child !== undefined ) {
  17866. object.addLevel( child, level.distance, level.hysteresis );
  17867. }
  17868. }
  17869. }
  17870. return object;
  17871. }
  17872. bindSkeletons( object, skeletons ) {
  17873. if ( Object.keys( skeletons ).length === 0 ) return;
  17874. object.traverse( function ( child ) {
  17875. if ( child.isSkinnedMesh === true && child.skeleton !== undefined ) {
  17876. const skeleton = skeletons[ child.skeleton ];
  17877. if ( skeleton === undefined ) {
  17878. console.warn( 'THREE.ObjectLoader: No skeleton found with UUID:', child.skeleton );
  17879. } else {
  17880. child.bind( skeleton, child.bindMatrix );
  17881. }
  17882. }
  17883. } );
  17884. }
  17885. bindLightTargets( object ) {
  17886. object.traverse( function ( child ) {
  17887. if ( child.isDirectionalLight || child.isSpotLight ) {
  17888. const uuid = child.target;
  17889. const target = object.getObjectByProperty( 'uuid', uuid );
  17890. if ( target !== undefined ) {
  17891. child.target = target;
  17892. } else {
  17893. child.target = new Object3D();
  17894. }
  17895. }
  17896. } );
  17897. }
  17898. }
  17899. const TEXTURE_MAPPING = {
  17900. UVMapping: UVMapping,
  17901. CubeReflectionMapping: CubeReflectionMapping,
  17902. CubeRefractionMapping: CubeRefractionMapping,
  17903. EquirectangularReflectionMapping: EquirectangularReflectionMapping,
  17904. EquirectangularRefractionMapping: EquirectangularRefractionMapping,
  17905. CubeUVReflectionMapping: CubeUVReflectionMapping
  17906. };
  17907. const TEXTURE_WRAPPING = {
  17908. RepeatWrapping: RepeatWrapping,
  17909. ClampToEdgeWrapping: ClampToEdgeWrapping,
  17910. MirroredRepeatWrapping: MirroredRepeatWrapping
  17911. };
  17912. const TEXTURE_FILTER = {
  17913. NearestFilter: NearestFilter,
  17914. NearestMipmapNearestFilter: NearestMipmapNearestFilter,
  17915. NearestMipmapLinearFilter: NearestMipmapLinearFilter,
  17916. LinearFilter: LinearFilter,
  17917. LinearMipmapNearestFilter: LinearMipmapNearestFilter,
  17918. LinearMipmapLinearFilter: LinearMipmapLinearFilter
  17919. };
  17920. class ImageBitmapLoader extends Loader {
  17921. constructor( manager ) {
  17922. super( manager );
  17923. this.isImageBitmapLoader = true;
  17924. if ( typeof createImageBitmap === 'undefined' ) {
  17925. console.warn( 'THREE.ImageBitmapLoader: createImageBitmap() not supported.' );
  17926. }
  17927. if ( typeof fetch === 'undefined' ) {
  17928. console.warn( 'THREE.ImageBitmapLoader: fetch() not supported.' );
  17929. }
  17930. this.options = { premultiplyAlpha: 'none' };
  17931. }
  17932. setOptions( options ) {
  17933. this.options = options;
  17934. return this;
  17935. }
  17936. load( url, onLoad, onProgress, onError ) {
  17937. if ( url === undefined ) url = '';
  17938. if ( this.path !== undefined ) url = this.path + url;
  17939. url = this.manager.resolveURL( url );
  17940. const scope = this;
  17941. const cached = Cache.get( url );
  17942. if ( cached !== undefined ) {
  17943. scope.manager.itemStart( url );
  17944. // If cached is a promise, wait for it to resolve
  17945. if ( cached.then ) {
  17946. cached.then( imageBitmap => {
  17947. if ( onLoad ) onLoad( imageBitmap );
  17948. scope.manager.itemEnd( url );
  17949. } ).catch( e => {
  17950. if ( onError ) onError( e );
  17951. } );
  17952. return;
  17953. }
  17954. // If cached is not a promise (i.e., it's already an imageBitmap)
  17955. setTimeout( function () {
  17956. if ( onLoad ) onLoad( cached );
  17957. scope.manager.itemEnd( url );
  17958. }, 0 );
  17959. return cached;
  17960. }
  17961. const fetchOptions = {};
  17962. fetchOptions.credentials = ( this.crossOrigin === 'anonymous' ) ? 'same-origin' : 'include';
  17963. fetchOptions.headers = this.requestHeader;
  17964. const promise = fetch( url, fetchOptions ).then( function ( res ) {
  17965. return res.blob();
  17966. } ).then( function ( blob ) {
  17967. return createImageBitmap( blob, Object.assign( scope.options, { colorSpaceConversion: 'none' } ) );
  17968. } ).then( function ( imageBitmap ) {
  17969. Cache.add( url, imageBitmap );
  17970. if ( onLoad ) onLoad( imageBitmap );
  17971. scope.manager.itemEnd( url );
  17972. return imageBitmap;
  17973. } ).catch( function ( e ) {
  17974. if ( onError ) onError( e );
  17975. Cache.remove( url );
  17976. scope.manager.itemError( url );
  17977. scope.manager.itemEnd( url );
  17978. } );
  17979. Cache.add( url, promise );
  17980. scope.manager.itemStart( url );
  17981. }
  17982. }
  17983. let _context;
  17984. class AudioContext {
  17985. static getContext() {
  17986. if ( _context === undefined ) {
  17987. _context = new ( window.AudioContext || window.webkitAudioContext )();
  17988. }
  17989. return _context;
  17990. }
  17991. static setContext( value ) {
  17992. _context = value;
  17993. }
  17994. }
  17995. class AudioLoader extends Loader {
  17996. constructor( manager ) {
  17997. super( manager );
  17998. }
  17999. load( url, onLoad, onProgress, onError ) {
  18000. const scope = this;
  18001. const loader = new FileLoader( this.manager );
  18002. loader.setResponseType( 'arraybuffer' );
  18003. loader.setPath( this.path );
  18004. loader.setRequestHeader( this.requestHeader );
  18005. loader.setWithCredentials( this.withCredentials );
  18006. loader.load( url, function ( buffer ) {
  18007. try {
  18008. // Create a copy of the buffer. The `decodeAudioData` method
  18009. // detaches the buffer when complete, preventing reuse.
  18010. const bufferCopy = buffer.slice( 0 );
  18011. const context = AudioContext.getContext();
  18012. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  18013. onLoad( audioBuffer );
  18014. } ).catch( handleError );
  18015. } catch ( e ) {
  18016. handleError( e );
  18017. }
  18018. }, onProgress, onError );
  18019. function handleError( e ) {
  18020. if ( onError ) {
  18021. onError( e );
  18022. } else {
  18023. console.error( e );
  18024. }
  18025. scope.manager.itemError( url );
  18026. }
  18027. }
  18028. }
  18029. const _eyeRight = /*@__PURE__*/ new Matrix4();
  18030. const _eyeLeft = /*@__PURE__*/ new Matrix4();
  18031. const _projectionMatrix = /*@__PURE__*/ new Matrix4();
  18032. class StereoCamera {
  18033. constructor() {
  18034. this.type = 'StereoCamera';
  18035. this.aspect = 1;
  18036. this.eyeSep = 0.064;
  18037. this.cameraL = new PerspectiveCamera();
  18038. this.cameraL.layers.enable( 1 );
  18039. this.cameraL.matrixAutoUpdate = false;
  18040. this.cameraR = new PerspectiveCamera();
  18041. this.cameraR.layers.enable( 2 );
  18042. this.cameraR.matrixAutoUpdate = false;
  18043. this._cache = {
  18044. focus: null,
  18045. fov: null,
  18046. aspect: null,
  18047. near: null,
  18048. far: null,
  18049. zoom: null,
  18050. eyeSep: null
  18051. };
  18052. }
  18053. update( camera ) {
  18054. const cache = this._cache;
  18055. const needsUpdate = cache.focus !== camera.focus || cache.fov !== camera.fov ||
  18056. cache.aspect !== camera.aspect * this.aspect || cache.near !== camera.near ||
  18057. cache.far !== camera.far || cache.zoom !== camera.zoom || cache.eyeSep !== this.eyeSep;
  18058. if ( needsUpdate ) {
  18059. cache.focus = camera.focus;
  18060. cache.fov = camera.fov;
  18061. cache.aspect = camera.aspect * this.aspect;
  18062. cache.near = camera.near;
  18063. cache.far = camera.far;
  18064. cache.zoom = camera.zoom;
  18065. cache.eyeSep = this.eyeSep;
  18066. // Off-axis stereoscopic effect based on
  18067. // http://paulbourke.net/stereographics/stereorender/
  18068. _projectionMatrix.copy( camera.projectionMatrix );
  18069. const eyeSepHalf = cache.eyeSep / 2;
  18070. const eyeSepOnProjection = eyeSepHalf * cache.near / cache.focus;
  18071. const ymax = ( cache.near * Math.tan( DEG2RAD * cache.fov * 0.5 ) ) / cache.zoom;
  18072. let xmin, xmax;
  18073. // translate xOffset
  18074. _eyeLeft.elements[ 12 ] = - eyeSepHalf;
  18075. _eyeRight.elements[ 12 ] = eyeSepHalf;
  18076. // for left eye
  18077. xmin = - ymax * cache.aspect + eyeSepOnProjection;
  18078. xmax = ymax * cache.aspect + eyeSepOnProjection;
  18079. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18080. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18081. this.cameraL.projectionMatrix.copy( _projectionMatrix );
  18082. // for right eye
  18083. xmin = - ymax * cache.aspect - eyeSepOnProjection;
  18084. xmax = ymax * cache.aspect - eyeSepOnProjection;
  18085. _projectionMatrix.elements[ 0 ] = 2 * cache.near / ( xmax - xmin );
  18086. _projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  18087. this.cameraR.projectionMatrix.copy( _projectionMatrix );
  18088. }
  18089. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeLeft );
  18090. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( _eyeRight );
  18091. }
  18092. }
  18093. class ArrayCamera extends PerspectiveCamera {
  18094. constructor( array = [] ) {
  18095. super();
  18096. this.isArrayCamera = true;
  18097. this.cameras = array;
  18098. }
  18099. }
  18100. class Clock {
  18101. constructor( autoStart = true ) {
  18102. this.autoStart = autoStart;
  18103. this.startTime = 0;
  18104. this.oldTime = 0;
  18105. this.elapsedTime = 0;
  18106. this.running = false;
  18107. }
  18108. start() {
  18109. this.startTime = now();
  18110. this.oldTime = this.startTime;
  18111. this.elapsedTime = 0;
  18112. this.running = true;
  18113. }
  18114. stop() {
  18115. this.getElapsedTime();
  18116. this.running = false;
  18117. this.autoStart = false;
  18118. }
  18119. getElapsedTime() {
  18120. this.getDelta();
  18121. return this.elapsedTime;
  18122. }
  18123. getDelta() {
  18124. let diff = 0;
  18125. if ( this.autoStart && ! this.running ) {
  18126. this.start();
  18127. return 0;
  18128. }
  18129. if ( this.running ) {
  18130. const newTime = now();
  18131. diff = ( newTime - this.oldTime ) / 1000;
  18132. this.oldTime = newTime;
  18133. this.elapsedTime += diff;
  18134. }
  18135. return diff;
  18136. }
  18137. }
  18138. function now() {
  18139. return performance.now();
  18140. }
  18141. const _position$1 = /*@__PURE__*/ new Vector3();
  18142. const _quaternion$1 = /*@__PURE__*/ new Quaternion();
  18143. const _scale$1 = /*@__PURE__*/ new Vector3();
  18144. const _orientation$1 = /*@__PURE__*/ new Vector3();
  18145. class AudioListener extends Object3D {
  18146. constructor() {
  18147. super();
  18148. this.type = 'AudioListener';
  18149. this.context = AudioContext.getContext();
  18150. this.gain = this.context.createGain();
  18151. this.gain.connect( this.context.destination );
  18152. this.filter = null;
  18153. this.timeDelta = 0;
  18154. // private
  18155. this._clock = new Clock();
  18156. }
  18157. getInput() {
  18158. return this.gain;
  18159. }
  18160. removeFilter() {
  18161. if ( this.filter !== null ) {
  18162. this.gain.disconnect( this.filter );
  18163. this.filter.disconnect( this.context.destination );
  18164. this.gain.connect( this.context.destination );
  18165. this.filter = null;
  18166. }
  18167. return this;
  18168. }
  18169. getFilter() {
  18170. return this.filter;
  18171. }
  18172. setFilter( value ) {
  18173. if ( this.filter !== null ) {
  18174. this.gain.disconnect( this.filter );
  18175. this.filter.disconnect( this.context.destination );
  18176. } else {
  18177. this.gain.disconnect( this.context.destination );
  18178. }
  18179. this.filter = value;
  18180. this.gain.connect( this.filter );
  18181. this.filter.connect( this.context.destination );
  18182. return this;
  18183. }
  18184. getMasterVolume() {
  18185. return this.gain.gain.value;
  18186. }
  18187. setMasterVolume( value ) {
  18188. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18189. return this;
  18190. }
  18191. updateMatrixWorld( force ) {
  18192. super.updateMatrixWorld( force );
  18193. const listener = this.context.listener;
  18194. const up = this.up;
  18195. this.timeDelta = this._clock.getDelta();
  18196. this.matrixWorld.decompose( _position$1, _quaternion$1, _scale$1 );
  18197. _orientation$1.set( 0, 0, - 1 ).applyQuaternion( _quaternion$1 );
  18198. if ( listener.positionX ) {
  18199. // code path for Chrome (see #14393)
  18200. const endTime = this.context.currentTime + this.timeDelta;
  18201. listener.positionX.linearRampToValueAtTime( _position$1.x, endTime );
  18202. listener.positionY.linearRampToValueAtTime( _position$1.y, endTime );
  18203. listener.positionZ.linearRampToValueAtTime( _position$1.z, endTime );
  18204. listener.forwardX.linearRampToValueAtTime( _orientation$1.x, endTime );
  18205. listener.forwardY.linearRampToValueAtTime( _orientation$1.y, endTime );
  18206. listener.forwardZ.linearRampToValueAtTime( _orientation$1.z, endTime );
  18207. listener.upX.linearRampToValueAtTime( up.x, endTime );
  18208. listener.upY.linearRampToValueAtTime( up.y, endTime );
  18209. listener.upZ.linearRampToValueAtTime( up.z, endTime );
  18210. } else {
  18211. listener.setPosition( _position$1.x, _position$1.y, _position$1.z );
  18212. listener.setOrientation( _orientation$1.x, _orientation$1.y, _orientation$1.z, up.x, up.y, up.z );
  18213. }
  18214. }
  18215. }
  18216. class Audio extends Object3D {
  18217. constructor( listener ) {
  18218. super();
  18219. this.type = 'Audio';
  18220. this.listener = listener;
  18221. this.context = listener.context;
  18222. this.gain = this.context.createGain();
  18223. this.gain.connect( listener.getInput() );
  18224. this.autoplay = false;
  18225. this.buffer = null;
  18226. this.detune = 0;
  18227. this.loop = false;
  18228. this.loopStart = 0;
  18229. this.loopEnd = 0;
  18230. this.offset = 0;
  18231. this.duration = undefined;
  18232. this.playbackRate = 1;
  18233. this.isPlaying = false;
  18234. this.hasPlaybackControl = true;
  18235. this.source = null;
  18236. this.sourceType = 'empty';
  18237. this._startedAt = 0;
  18238. this._progress = 0;
  18239. this._connected = false;
  18240. this.filters = [];
  18241. }
  18242. getOutput() {
  18243. return this.gain;
  18244. }
  18245. setNodeSource( audioNode ) {
  18246. this.hasPlaybackControl = false;
  18247. this.sourceType = 'audioNode';
  18248. this.source = audioNode;
  18249. this.connect();
  18250. return this;
  18251. }
  18252. setMediaElementSource( mediaElement ) {
  18253. this.hasPlaybackControl = false;
  18254. this.sourceType = 'mediaNode';
  18255. this.source = this.context.createMediaElementSource( mediaElement );
  18256. this.connect();
  18257. return this;
  18258. }
  18259. setMediaStreamSource( mediaStream ) {
  18260. this.hasPlaybackControl = false;
  18261. this.sourceType = 'mediaStreamNode';
  18262. this.source = this.context.createMediaStreamSource( mediaStream );
  18263. this.connect();
  18264. return this;
  18265. }
  18266. setBuffer( audioBuffer ) {
  18267. this.buffer = audioBuffer;
  18268. this.sourceType = 'buffer';
  18269. if ( this.autoplay ) this.play();
  18270. return this;
  18271. }
  18272. play( delay = 0 ) {
  18273. if ( this.isPlaying === true ) {
  18274. console.warn( 'THREE.Audio: Audio is already playing.' );
  18275. return;
  18276. }
  18277. if ( this.hasPlaybackControl === false ) {
  18278. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18279. return;
  18280. }
  18281. this._startedAt = this.context.currentTime + delay;
  18282. const source = this.context.createBufferSource();
  18283. source.buffer = this.buffer;
  18284. source.loop = this.loop;
  18285. source.loopStart = this.loopStart;
  18286. source.loopEnd = this.loopEnd;
  18287. source.onended = this.onEnded.bind( this );
  18288. source.start( this._startedAt, this._progress + this.offset, this.duration );
  18289. this.isPlaying = true;
  18290. this.source = source;
  18291. this.setDetune( this.detune );
  18292. this.setPlaybackRate( this.playbackRate );
  18293. return this.connect();
  18294. }
  18295. pause() {
  18296. if ( this.hasPlaybackControl === false ) {
  18297. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18298. return;
  18299. }
  18300. if ( this.isPlaying === true ) {
  18301. // update current progress
  18302. this._progress += Math.max( this.context.currentTime - this._startedAt, 0 ) * this.playbackRate;
  18303. if ( this.loop === true ) {
  18304. // ensure _progress does not exceed duration with looped audios
  18305. this._progress = this._progress % ( this.duration || this.buffer.duration );
  18306. }
  18307. this.source.stop();
  18308. this.source.onended = null;
  18309. this.isPlaying = false;
  18310. }
  18311. return this;
  18312. }
  18313. stop( delay = 0 ) {
  18314. if ( this.hasPlaybackControl === false ) {
  18315. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18316. return;
  18317. }
  18318. this._progress = 0;
  18319. if ( this.source !== null ) {
  18320. this.source.stop( this.context.currentTime + delay );
  18321. this.source.onended = null;
  18322. }
  18323. this.isPlaying = false;
  18324. return this;
  18325. }
  18326. connect() {
  18327. if ( this.filters.length > 0 ) {
  18328. this.source.connect( this.filters[ 0 ] );
  18329. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18330. this.filters[ i - 1 ].connect( this.filters[ i ] );
  18331. }
  18332. this.filters[ this.filters.length - 1 ].connect( this.getOutput() );
  18333. } else {
  18334. this.source.connect( this.getOutput() );
  18335. }
  18336. this._connected = true;
  18337. return this;
  18338. }
  18339. disconnect() {
  18340. if ( this._connected === false ) {
  18341. return;
  18342. }
  18343. if ( this.filters.length > 0 ) {
  18344. this.source.disconnect( this.filters[ 0 ] );
  18345. for ( let i = 1, l = this.filters.length; i < l; i ++ ) {
  18346. this.filters[ i - 1 ].disconnect( this.filters[ i ] );
  18347. }
  18348. this.filters[ this.filters.length - 1 ].disconnect( this.getOutput() );
  18349. } else {
  18350. this.source.disconnect( this.getOutput() );
  18351. }
  18352. this._connected = false;
  18353. return this;
  18354. }
  18355. getFilters() {
  18356. return this.filters;
  18357. }
  18358. setFilters( value ) {
  18359. if ( ! value ) value = [];
  18360. if ( this._connected === true ) {
  18361. this.disconnect();
  18362. this.filters = value.slice();
  18363. this.connect();
  18364. } else {
  18365. this.filters = value.slice();
  18366. }
  18367. return this;
  18368. }
  18369. setDetune( value ) {
  18370. this.detune = value;
  18371. if ( this.isPlaying === true && this.source.detune !== undefined ) {
  18372. this.source.detune.setTargetAtTime( this.detune, this.context.currentTime, 0.01 );
  18373. }
  18374. return this;
  18375. }
  18376. getDetune() {
  18377. return this.detune;
  18378. }
  18379. getFilter() {
  18380. return this.getFilters()[ 0 ];
  18381. }
  18382. setFilter( filter ) {
  18383. return this.setFilters( filter ? [ filter ] : [] );
  18384. }
  18385. setPlaybackRate( value ) {
  18386. if ( this.hasPlaybackControl === false ) {
  18387. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18388. return;
  18389. }
  18390. this.playbackRate = value;
  18391. if ( this.isPlaying === true ) {
  18392. this.source.playbackRate.setTargetAtTime( this.playbackRate, this.context.currentTime, 0.01 );
  18393. }
  18394. return this;
  18395. }
  18396. getPlaybackRate() {
  18397. return this.playbackRate;
  18398. }
  18399. onEnded() {
  18400. this.isPlaying = false;
  18401. this._progress = 0;
  18402. }
  18403. getLoop() {
  18404. if ( this.hasPlaybackControl === false ) {
  18405. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18406. return false;
  18407. }
  18408. return this.loop;
  18409. }
  18410. setLoop( value ) {
  18411. if ( this.hasPlaybackControl === false ) {
  18412. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  18413. return;
  18414. }
  18415. this.loop = value;
  18416. if ( this.isPlaying === true ) {
  18417. this.source.loop = this.loop;
  18418. }
  18419. return this;
  18420. }
  18421. setLoopStart( value ) {
  18422. this.loopStart = value;
  18423. return this;
  18424. }
  18425. setLoopEnd( value ) {
  18426. this.loopEnd = value;
  18427. return this;
  18428. }
  18429. getVolume() {
  18430. return this.gain.gain.value;
  18431. }
  18432. setVolume( value ) {
  18433. this.gain.gain.setTargetAtTime( value, this.context.currentTime, 0.01 );
  18434. return this;
  18435. }
  18436. copy( source, recursive ) {
  18437. super.copy( source, recursive );
  18438. if ( source.sourceType !== 'buffer' ) {
  18439. console.warn( 'THREE.Audio: Audio source type cannot be copied.' );
  18440. return this;
  18441. }
  18442. this.autoplay = source.autoplay;
  18443. this.buffer = source.buffer;
  18444. this.detune = source.detune;
  18445. this.loop = source.loop;
  18446. this.loopStart = source.loopStart;
  18447. this.loopEnd = source.loopEnd;
  18448. this.offset = source.offset;
  18449. this.duration = source.duration;
  18450. this.playbackRate = source.playbackRate;
  18451. this.hasPlaybackControl = source.hasPlaybackControl;
  18452. this.sourceType = source.sourceType;
  18453. this.filters = source.filters.slice();
  18454. return this;
  18455. }
  18456. clone( recursive ) {
  18457. return new this.constructor( this.listener ).copy( this, recursive );
  18458. }
  18459. }
  18460. const _position = /*@__PURE__*/ new Vector3();
  18461. const _quaternion = /*@__PURE__*/ new Quaternion();
  18462. const _scale = /*@__PURE__*/ new Vector3();
  18463. const _orientation = /*@__PURE__*/ new Vector3();
  18464. class PositionalAudio extends Audio {
  18465. constructor( listener ) {
  18466. super( listener );
  18467. this.panner = this.context.createPanner();
  18468. this.panner.panningModel = 'HRTF';
  18469. this.panner.connect( this.gain );
  18470. }
  18471. connect() {
  18472. super.connect();
  18473. this.panner.connect( this.gain );
  18474. }
  18475. disconnect() {
  18476. super.disconnect();
  18477. this.panner.disconnect( this.gain );
  18478. }
  18479. getOutput() {
  18480. return this.panner;
  18481. }
  18482. getRefDistance() {
  18483. return this.panner.refDistance;
  18484. }
  18485. setRefDistance( value ) {
  18486. this.panner.refDistance = value;
  18487. return this;
  18488. }
  18489. getRolloffFactor() {
  18490. return this.panner.rolloffFactor;
  18491. }
  18492. setRolloffFactor( value ) {
  18493. this.panner.rolloffFactor = value;
  18494. return this;
  18495. }
  18496. getDistanceModel() {
  18497. return this.panner.distanceModel;
  18498. }
  18499. setDistanceModel( value ) {
  18500. this.panner.distanceModel = value;
  18501. return this;
  18502. }
  18503. getMaxDistance() {
  18504. return this.panner.maxDistance;
  18505. }
  18506. setMaxDistance( value ) {
  18507. this.panner.maxDistance = value;
  18508. return this;
  18509. }
  18510. setDirectionalCone( coneInnerAngle, coneOuterAngle, coneOuterGain ) {
  18511. this.panner.coneInnerAngle = coneInnerAngle;
  18512. this.panner.coneOuterAngle = coneOuterAngle;
  18513. this.panner.coneOuterGain = coneOuterGain;
  18514. return this;
  18515. }
  18516. updateMatrixWorld( force ) {
  18517. super.updateMatrixWorld( force );
  18518. if ( this.hasPlaybackControl === true && this.isPlaying === false ) return;
  18519. this.matrixWorld.decompose( _position, _quaternion, _scale );
  18520. _orientation.set( 0, 0, 1 ).applyQuaternion( _quaternion );
  18521. const panner = this.panner;
  18522. if ( panner.positionX ) {
  18523. // code path for Chrome and Firefox (see #14393)
  18524. const endTime = this.context.currentTime + this.listener.timeDelta;
  18525. panner.positionX.linearRampToValueAtTime( _position.x, endTime );
  18526. panner.positionY.linearRampToValueAtTime( _position.y, endTime );
  18527. panner.positionZ.linearRampToValueAtTime( _position.z, endTime );
  18528. panner.orientationX.linearRampToValueAtTime( _orientation.x, endTime );
  18529. panner.orientationY.linearRampToValueAtTime( _orientation.y, endTime );
  18530. panner.orientationZ.linearRampToValueAtTime( _orientation.z, endTime );
  18531. } else {
  18532. panner.setPosition( _position.x, _position.y, _position.z );
  18533. panner.setOrientation( _orientation.x, _orientation.y, _orientation.z );
  18534. }
  18535. }
  18536. }
  18537. class AudioAnalyser {
  18538. constructor( audio, fftSize = 2048 ) {
  18539. this.analyser = audio.context.createAnalyser();
  18540. this.analyser.fftSize = fftSize;
  18541. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  18542. audio.getOutput().connect( this.analyser );
  18543. }
  18544. getFrequencyData() {
  18545. this.analyser.getByteFrequencyData( this.data );
  18546. return this.data;
  18547. }
  18548. getAverageFrequency() {
  18549. let value = 0;
  18550. const data = this.getFrequencyData();
  18551. for ( let i = 0; i < data.length; i ++ ) {
  18552. value += data[ i ];
  18553. }
  18554. return value / data.length;
  18555. }
  18556. }
  18557. class PropertyMixer {
  18558. constructor( binding, typeName, valueSize ) {
  18559. this.binding = binding;
  18560. this.valueSize = valueSize;
  18561. let mixFunction,
  18562. mixFunctionAdditive,
  18563. setIdentity;
  18564. // buffer layout: [ incoming | accu0 | accu1 | orig | addAccu | (optional work) ]
  18565. //
  18566. // interpolators can use .buffer as their .result
  18567. // the data then goes to 'incoming'
  18568. //
  18569. // 'accu0' and 'accu1' are used frame-interleaved for
  18570. // the cumulative result and are compared to detect
  18571. // changes
  18572. //
  18573. // 'orig' stores the original state of the property
  18574. //
  18575. // 'add' is used for additive cumulative results
  18576. //
  18577. // 'work' is optional and is only present for quaternion types. It is used
  18578. // to store intermediate quaternion multiplication results
  18579. switch ( typeName ) {
  18580. case 'quaternion':
  18581. mixFunction = this._slerp;
  18582. mixFunctionAdditive = this._slerpAdditive;
  18583. setIdentity = this._setAdditiveIdentityQuaternion;
  18584. this.buffer = new Float64Array( valueSize * 6 );
  18585. this._workIndex = 5;
  18586. break;
  18587. case 'string':
  18588. case 'bool':
  18589. mixFunction = this._select;
  18590. // Use the regular mix function and for additive on these types,
  18591. // additive is not relevant for non-numeric types
  18592. mixFunctionAdditive = this._select;
  18593. setIdentity = this._setAdditiveIdentityOther;
  18594. this.buffer = new Array( valueSize * 5 );
  18595. break;
  18596. default:
  18597. mixFunction = this._lerp;
  18598. mixFunctionAdditive = this._lerpAdditive;
  18599. setIdentity = this._setAdditiveIdentityNumeric;
  18600. this.buffer = new Float64Array( valueSize * 5 );
  18601. }
  18602. this._mixBufferRegion = mixFunction;
  18603. this._mixBufferRegionAdditive = mixFunctionAdditive;
  18604. this._setIdentity = setIdentity;
  18605. this._origIndex = 3;
  18606. this._addIndex = 4;
  18607. this.cumulativeWeight = 0;
  18608. this.cumulativeWeightAdditive = 0;
  18609. this.useCount = 0;
  18610. this.referenceCount = 0;
  18611. }
  18612. // accumulate data in the 'incoming' region into 'accu<i>'
  18613. accumulate( accuIndex, weight ) {
  18614. // note: happily accumulating nothing when weight = 0, the caller knows
  18615. // the weight and shouldn't have made the call in the first place
  18616. const buffer = this.buffer,
  18617. stride = this.valueSize,
  18618. offset = accuIndex * stride + stride;
  18619. let currentWeight = this.cumulativeWeight;
  18620. if ( currentWeight === 0 ) {
  18621. // accuN := incoming * weight
  18622. for ( let i = 0; i !== stride; ++ i ) {
  18623. buffer[ offset + i ] = buffer[ i ];
  18624. }
  18625. currentWeight = weight;
  18626. } else {
  18627. // accuN := accuN + incoming * weight
  18628. currentWeight += weight;
  18629. const mix = weight / currentWeight;
  18630. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  18631. }
  18632. this.cumulativeWeight = currentWeight;
  18633. }
  18634. // accumulate data in the 'incoming' region into 'add'
  18635. accumulateAdditive( weight ) {
  18636. const buffer = this.buffer,
  18637. stride = this.valueSize,
  18638. offset = stride * this._addIndex;
  18639. if ( this.cumulativeWeightAdditive === 0 ) {
  18640. // add = identity
  18641. this._setIdentity();
  18642. }
  18643. // add := add + incoming * weight
  18644. this._mixBufferRegionAdditive( buffer, offset, 0, weight, stride );
  18645. this.cumulativeWeightAdditive += weight;
  18646. }
  18647. // apply the state of 'accu<i>' to the binding when accus differ
  18648. apply( accuIndex ) {
  18649. const stride = this.valueSize,
  18650. buffer = this.buffer,
  18651. offset = accuIndex * stride + stride,
  18652. weight = this.cumulativeWeight,
  18653. weightAdditive = this.cumulativeWeightAdditive,
  18654. binding = this.binding;
  18655. this.cumulativeWeight = 0;
  18656. this.cumulativeWeightAdditive = 0;
  18657. if ( weight < 1 ) {
  18658. // accuN := accuN + original * ( 1 - cumulativeWeight )
  18659. const originalValueOffset = stride * this._origIndex;
  18660. this._mixBufferRegion(
  18661. buffer, offset, originalValueOffset, 1 - weight, stride );
  18662. }
  18663. if ( weightAdditive > 0 ) {
  18664. // accuN := accuN + additive accuN
  18665. this._mixBufferRegionAdditive( buffer, offset, this._addIndex * stride, 1, stride );
  18666. }
  18667. for ( let i = stride, e = stride + stride; i !== e; ++ i ) {
  18668. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  18669. // value has changed -> update scene graph
  18670. binding.setValue( buffer, offset );
  18671. break;
  18672. }
  18673. }
  18674. }
  18675. // remember the state of the bound property and copy it to both accus
  18676. saveOriginalState() {
  18677. const binding = this.binding;
  18678. const buffer = this.buffer,
  18679. stride = this.valueSize,
  18680. originalValueOffset = stride * this._origIndex;
  18681. binding.getValue( buffer, originalValueOffset );
  18682. // accu[0..1] := orig -- initially detect changes against the original
  18683. for ( let i = stride, e = originalValueOffset; i !== e; ++ i ) {
  18684. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  18685. }
  18686. // Add to identity for additive
  18687. this._setIdentity();
  18688. this.cumulativeWeight = 0;
  18689. this.cumulativeWeightAdditive = 0;
  18690. }
  18691. // apply the state previously taken via 'saveOriginalState' to the binding
  18692. restoreOriginalState() {
  18693. const originalValueOffset = this.valueSize * 3;
  18694. this.binding.setValue( this.buffer, originalValueOffset );
  18695. }
  18696. _setAdditiveIdentityNumeric() {
  18697. const startIndex = this._addIndex * this.valueSize;
  18698. const endIndex = startIndex + this.valueSize;
  18699. for ( let i = startIndex; i < endIndex; i ++ ) {
  18700. this.buffer[ i ] = 0;
  18701. }
  18702. }
  18703. _setAdditiveIdentityQuaternion() {
  18704. this._setAdditiveIdentityNumeric();
  18705. this.buffer[ this._addIndex * this.valueSize + 3 ] = 1;
  18706. }
  18707. _setAdditiveIdentityOther() {
  18708. const startIndex = this._origIndex * this.valueSize;
  18709. const targetIndex = this._addIndex * this.valueSize;
  18710. for ( let i = 0; i < this.valueSize; i ++ ) {
  18711. this.buffer[ targetIndex + i ] = this.buffer[ startIndex + i ];
  18712. }
  18713. }
  18714. // mix functions
  18715. _select( buffer, dstOffset, srcOffset, t, stride ) {
  18716. if ( t >= 0.5 ) {
  18717. for ( let i = 0; i !== stride; ++ i ) {
  18718. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  18719. }
  18720. }
  18721. }
  18722. _slerp( buffer, dstOffset, srcOffset, t ) {
  18723. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, srcOffset, t );
  18724. }
  18725. _slerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18726. const workOffset = this._workIndex * stride;
  18727. // Store result in intermediate buffer offset
  18728. Quaternion.multiplyQuaternionsFlat( buffer, workOffset, buffer, dstOffset, buffer, srcOffset );
  18729. // Slerp to the intermediate result
  18730. Quaternion.slerpFlat( buffer, dstOffset, buffer, dstOffset, buffer, workOffset, t );
  18731. }
  18732. _lerp( buffer, dstOffset, srcOffset, t, stride ) {
  18733. const s = 1 - t;
  18734. for ( let i = 0; i !== stride; ++ i ) {
  18735. const j = dstOffset + i;
  18736. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  18737. }
  18738. }
  18739. _lerpAdditive( buffer, dstOffset, srcOffset, t, stride ) {
  18740. for ( let i = 0; i !== stride; ++ i ) {
  18741. const j = dstOffset + i;
  18742. buffer[ j ] = buffer[ j ] + buffer[ srcOffset + i ] * t;
  18743. }
  18744. }
  18745. }
  18746. // Characters [].:/ are reserved for track binding syntax.
  18747. const _RESERVED_CHARS_RE = '\\[\\]\\.:\\/';
  18748. const _reservedRe = new RegExp( '[' + _RESERVED_CHARS_RE + ']', 'g' );
  18749. // Attempts to allow node names from any language. ES5's `\w` regexp matches
  18750. // only latin characters, and the unicode \p{L} is not yet supported. So
  18751. // instead, we exclude reserved characters and match everything else.
  18752. const _wordChar = '[^' + _RESERVED_CHARS_RE + ']';
  18753. const _wordCharOrDot = '[^' + _RESERVED_CHARS_RE.replace( '\\.', '' ) + ']';
  18754. // Parent directories, delimited by '/' or ':'. Currently unused, but must
  18755. // be matched to parse the rest of the track name.
  18756. const _directoryRe = /*@__PURE__*/ /((?:WC+[\/:])*)/.source.replace( 'WC', _wordChar );
  18757. // Target node. May contain word characters (a-zA-Z0-9_) and '.' or '-'.
  18758. const _nodeRe = /*@__PURE__*/ /(WCOD+)?/.source.replace( 'WCOD', _wordCharOrDot );
  18759. // Object on target node, and accessor. May not contain reserved
  18760. // characters. Accessor may contain any character except closing bracket.
  18761. const _objectRe = /*@__PURE__*/ /(?:\.(WC+)(?:\[(.+)\])?)?/.source.replace( 'WC', _wordChar );
  18762. // Property and accessor. May not contain reserved characters. Accessor may
  18763. // contain any non-bracket characters.
  18764. const _propertyRe = /*@__PURE__*/ /\.(WC+)(?:\[(.+)\])?/.source.replace( 'WC', _wordChar );
  18765. const _trackRe = new RegExp( ''
  18766. + '^'
  18767. + _directoryRe
  18768. + _nodeRe
  18769. + _objectRe
  18770. + _propertyRe
  18771. + '$'
  18772. );
  18773. const _supportedObjectNames = [ 'material', 'materials', 'bones', 'map' ];
  18774. class Composite {
  18775. constructor( targetGroup, path, optionalParsedPath ) {
  18776. const parsedPath = optionalParsedPath || PropertyBinding.parseTrackName( path );
  18777. this._targetGroup = targetGroup;
  18778. this._bindings = targetGroup.subscribe_( path, parsedPath );
  18779. }
  18780. getValue( array, offset ) {
  18781. this.bind(); // bind all binding
  18782. const firstValidIndex = this._targetGroup.nCachedObjects_,
  18783. binding = this._bindings[ firstValidIndex ];
  18784. // and only call .getValue on the first
  18785. if ( binding !== undefined ) binding.getValue( array, offset );
  18786. }
  18787. setValue( array, offset ) {
  18788. const bindings = this._bindings;
  18789. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18790. bindings[ i ].setValue( array, offset );
  18791. }
  18792. }
  18793. bind() {
  18794. const bindings = this._bindings;
  18795. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18796. bindings[ i ].bind();
  18797. }
  18798. }
  18799. unbind() {
  18800. const bindings = this._bindings;
  18801. for ( let i = this._targetGroup.nCachedObjects_, n = bindings.length; i !== n; ++ i ) {
  18802. bindings[ i ].unbind();
  18803. }
  18804. }
  18805. }
  18806. // Note: This class uses a State pattern on a per-method basis:
  18807. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  18808. // prototype version of these methods with one that represents
  18809. // the bound state. When the property is not found, the methods
  18810. // become no-ops.
  18811. class PropertyBinding {
  18812. constructor( rootNode, path, parsedPath ) {
  18813. this.path = path;
  18814. this.parsedPath = parsedPath || PropertyBinding.parseTrackName( path );
  18815. this.node = PropertyBinding.findNode( rootNode, this.parsedPath.nodeName );
  18816. this.rootNode = rootNode;
  18817. // initial state of these methods that calls 'bind'
  18818. this.getValue = this._getValue_unbound;
  18819. this.setValue = this._setValue_unbound;
  18820. }
  18821. static create( root, path, parsedPath ) {
  18822. if ( ! ( root && root.isAnimationObjectGroup ) ) {
  18823. return new PropertyBinding( root, path, parsedPath );
  18824. } else {
  18825. return new PropertyBinding.Composite( root, path, parsedPath );
  18826. }
  18827. }
  18828. /**
  18829. * Replaces spaces with underscores and removes unsupported characters from
  18830. * node names, to ensure compatibility with parseTrackName().
  18831. *
  18832. * @param {string} name Node name to be sanitized.
  18833. * @return {string}
  18834. */
  18835. static sanitizeNodeName( name ) {
  18836. return name.replace( /\s/g, '_' ).replace( _reservedRe, '' );
  18837. }
  18838. static parseTrackName( trackName ) {
  18839. const matches = _trackRe.exec( trackName );
  18840. if ( matches === null ) {
  18841. throw new Error( 'PropertyBinding: Cannot parse trackName: ' + trackName );
  18842. }
  18843. const results = {
  18844. // directoryName: matches[ 1 ], // (tschw) currently unused
  18845. nodeName: matches[ 2 ],
  18846. objectName: matches[ 3 ],
  18847. objectIndex: matches[ 4 ],
  18848. propertyName: matches[ 5 ], // required
  18849. propertyIndex: matches[ 6 ]
  18850. };
  18851. const lastDot = results.nodeName && results.nodeName.lastIndexOf( '.' );
  18852. if ( lastDot !== undefined && lastDot !== - 1 ) {
  18853. const objectName = results.nodeName.substring( lastDot + 1 );
  18854. // Object names must be checked against an allowlist. Otherwise, there
  18855. // is no way to parse 'foo.bar.baz': 'baz' must be a property, but
  18856. // 'bar' could be the objectName, or part of a nodeName (which can
  18857. // include '.' characters).
  18858. if ( _supportedObjectNames.indexOf( objectName ) !== - 1 ) {
  18859. results.nodeName = results.nodeName.substring( 0, lastDot );
  18860. results.objectName = objectName;
  18861. }
  18862. }
  18863. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  18864. throw new Error( 'PropertyBinding: can not parse propertyName from trackName: ' + trackName );
  18865. }
  18866. return results;
  18867. }
  18868. static findNode( root, nodeName ) {
  18869. if ( nodeName === undefined || nodeName === '' || nodeName === '.' || nodeName === - 1 || nodeName === root.name || nodeName === root.uuid ) {
  18870. return root;
  18871. }
  18872. // search into skeleton bones.
  18873. if ( root.skeleton ) {
  18874. const bone = root.skeleton.getBoneByName( nodeName );
  18875. if ( bone !== undefined ) {
  18876. return bone;
  18877. }
  18878. }
  18879. // search into node subtree.
  18880. if ( root.children ) {
  18881. const searchNodeSubtree = function ( children ) {
  18882. for ( let i = 0; i < children.length; i ++ ) {
  18883. const childNode = children[ i ];
  18884. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  18885. return childNode;
  18886. }
  18887. const result = searchNodeSubtree( childNode.children );
  18888. if ( result ) return result;
  18889. }
  18890. return null;
  18891. };
  18892. const subTreeNode = searchNodeSubtree( root.children );
  18893. if ( subTreeNode ) {
  18894. return subTreeNode;
  18895. }
  18896. }
  18897. return null;
  18898. }
  18899. // these are used to "bind" a nonexistent property
  18900. _getValue_unavailable() {}
  18901. _setValue_unavailable() {}
  18902. // Getters
  18903. _getValue_direct( buffer, offset ) {
  18904. buffer[ offset ] = this.targetObject[ this.propertyName ];
  18905. }
  18906. _getValue_array( buffer, offset ) {
  18907. const source = this.resolvedProperty;
  18908. for ( let i = 0, n = source.length; i !== n; ++ i ) {
  18909. buffer[ offset ++ ] = source[ i ];
  18910. }
  18911. }
  18912. _getValue_arrayElement( buffer, offset ) {
  18913. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  18914. }
  18915. _getValue_toArray( buffer, offset ) {
  18916. this.resolvedProperty.toArray( buffer, offset );
  18917. }
  18918. // Direct
  18919. _setValue_direct( buffer, offset ) {
  18920. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18921. }
  18922. _setValue_direct_setNeedsUpdate( buffer, offset ) {
  18923. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18924. this.targetObject.needsUpdate = true;
  18925. }
  18926. _setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18927. this.targetObject[ this.propertyName ] = buffer[ offset ];
  18928. this.targetObject.matrixWorldNeedsUpdate = true;
  18929. }
  18930. // EntireArray
  18931. _setValue_array( buffer, offset ) {
  18932. const dest = this.resolvedProperty;
  18933. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18934. dest[ i ] = buffer[ offset ++ ];
  18935. }
  18936. }
  18937. _setValue_array_setNeedsUpdate( buffer, offset ) {
  18938. const dest = this.resolvedProperty;
  18939. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18940. dest[ i ] = buffer[ offset ++ ];
  18941. }
  18942. this.targetObject.needsUpdate = true;
  18943. }
  18944. _setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18945. const dest = this.resolvedProperty;
  18946. for ( let i = 0, n = dest.length; i !== n; ++ i ) {
  18947. dest[ i ] = buffer[ offset ++ ];
  18948. }
  18949. this.targetObject.matrixWorldNeedsUpdate = true;
  18950. }
  18951. // ArrayElement
  18952. _setValue_arrayElement( buffer, offset ) {
  18953. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18954. }
  18955. _setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  18956. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18957. this.targetObject.needsUpdate = true;
  18958. }
  18959. _setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18960. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  18961. this.targetObject.matrixWorldNeedsUpdate = true;
  18962. }
  18963. // HasToFromArray
  18964. _setValue_fromArray( buffer, offset ) {
  18965. this.resolvedProperty.fromArray( buffer, offset );
  18966. }
  18967. _setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  18968. this.resolvedProperty.fromArray( buffer, offset );
  18969. this.targetObject.needsUpdate = true;
  18970. }
  18971. _setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  18972. this.resolvedProperty.fromArray( buffer, offset );
  18973. this.targetObject.matrixWorldNeedsUpdate = true;
  18974. }
  18975. _getValue_unbound( targetArray, offset ) {
  18976. this.bind();
  18977. this.getValue( targetArray, offset );
  18978. }
  18979. _setValue_unbound( sourceArray, offset ) {
  18980. this.bind();
  18981. this.setValue( sourceArray, offset );
  18982. }
  18983. // create getter / setter pair for a property in the scene graph
  18984. bind() {
  18985. let targetObject = this.node;
  18986. const parsedPath = this.parsedPath;
  18987. const objectName = parsedPath.objectName;
  18988. const propertyName = parsedPath.propertyName;
  18989. let propertyIndex = parsedPath.propertyIndex;
  18990. if ( ! targetObject ) {
  18991. targetObject = PropertyBinding.findNode( this.rootNode, parsedPath.nodeName );
  18992. this.node = targetObject;
  18993. }
  18994. // set fail state so we can just 'return' on error
  18995. this.getValue = this._getValue_unavailable;
  18996. this.setValue = this._setValue_unavailable;
  18997. // ensure there is a value node
  18998. if ( ! targetObject ) {
  18999. console.warn( 'THREE.PropertyBinding: No target node found for track: ' + this.path + '.' );
  19000. return;
  19001. }
  19002. if ( objectName ) {
  19003. let objectIndex = parsedPath.objectIndex;
  19004. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  19005. switch ( objectName ) {
  19006. case 'materials':
  19007. if ( ! targetObject.material ) {
  19008. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19009. return;
  19010. }
  19011. if ( ! targetObject.material.materials ) {
  19012. console.error( 'THREE.PropertyBinding: Can not bind to material.materials as node.material does not have a materials array.', this );
  19013. return;
  19014. }
  19015. targetObject = targetObject.material.materials;
  19016. break;
  19017. case 'bones':
  19018. if ( ! targetObject.skeleton ) {
  19019. console.error( 'THREE.PropertyBinding: Can not bind to bones as node does not have a skeleton.', this );
  19020. return;
  19021. }
  19022. // potential future optimization: skip this if propertyIndex is already an integer
  19023. // and convert the integer string to a true integer.
  19024. targetObject = targetObject.skeleton.bones;
  19025. // support resolving morphTarget names into indices.
  19026. for ( let i = 0; i < targetObject.length; i ++ ) {
  19027. if ( targetObject[ i ].name === objectIndex ) {
  19028. objectIndex = i;
  19029. break;
  19030. }
  19031. }
  19032. break;
  19033. case 'map':
  19034. if ( 'map' in targetObject ) {
  19035. targetObject = targetObject.map;
  19036. break;
  19037. }
  19038. if ( ! targetObject.material ) {
  19039. console.error( 'THREE.PropertyBinding: Can not bind to material as node does not have a material.', this );
  19040. return;
  19041. }
  19042. if ( ! targetObject.material.map ) {
  19043. console.error( 'THREE.PropertyBinding: Can not bind to material.map as node.material does not have a map.', this );
  19044. return;
  19045. }
  19046. targetObject = targetObject.material.map;
  19047. break;
  19048. default:
  19049. if ( targetObject[ objectName ] === undefined ) {
  19050. console.error( 'THREE.PropertyBinding: Can not bind to objectName of node undefined.', this );
  19051. return;
  19052. }
  19053. targetObject = targetObject[ objectName ];
  19054. }
  19055. if ( objectIndex !== undefined ) {
  19056. if ( targetObject[ objectIndex ] === undefined ) {
  19057. console.error( 'THREE.PropertyBinding: Trying to bind to objectIndex of objectName, but is undefined.', this, targetObject );
  19058. return;
  19059. }
  19060. targetObject = targetObject[ objectIndex ];
  19061. }
  19062. }
  19063. // resolve property
  19064. const nodeProperty = targetObject[ propertyName ];
  19065. if ( nodeProperty === undefined ) {
  19066. const nodeName = parsedPath.nodeName;
  19067. console.error( 'THREE.PropertyBinding: Trying to update property for track: ' + nodeName +
  19068. '.' + propertyName + ' but it wasn\'t found.', targetObject );
  19069. return;
  19070. }
  19071. // determine versioning scheme
  19072. let versioning = this.Versioning.None;
  19073. this.targetObject = targetObject;
  19074. if ( targetObject.isMaterial === true ) {
  19075. versioning = this.Versioning.NeedsUpdate;
  19076. } else if ( targetObject.isObject3D === true ) {
  19077. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  19078. }
  19079. // determine how the property gets bound
  19080. let bindingType = this.BindingType.Direct;
  19081. if ( propertyIndex !== undefined ) {
  19082. // access a sub element of the property array (only primitives are supported right now)
  19083. if ( propertyName === 'morphTargetInfluences' ) {
  19084. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  19085. // support resolving morphTarget names into indices.
  19086. if ( ! targetObject.geometry ) {
  19087. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.', this );
  19088. return;
  19089. }
  19090. if ( ! targetObject.geometry.morphAttributes ) {
  19091. console.error( 'THREE.PropertyBinding: Can not bind to morphTargetInfluences because node does not have a geometry.morphAttributes.', this );
  19092. return;
  19093. }
  19094. if ( targetObject.morphTargetDictionary[ propertyIndex ] !== undefined ) {
  19095. propertyIndex = targetObject.morphTargetDictionary[ propertyIndex ];
  19096. }
  19097. }
  19098. bindingType = this.BindingType.ArrayElement;
  19099. this.resolvedProperty = nodeProperty;
  19100. this.propertyIndex = propertyIndex;
  19101. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  19102. // must use copy for Object3D.Euler/Quaternion
  19103. bindingType = this.BindingType.HasFromToArray;
  19104. this.resolvedProperty = nodeProperty;
  19105. } else if ( Array.isArray( nodeProperty ) ) {
  19106. bindingType = this.BindingType.EntireArray;
  19107. this.resolvedProperty = nodeProperty;
  19108. } else {
  19109. this.propertyName = propertyName;
  19110. }
  19111. // select getter / setter
  19112. this.getValue = this.GetterByBindingType[ bindingType ];
  19113. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  19114. }
  19115. unbind() {
  19116. this.node = null;
  19117. // back to the prototype version of getValue / setValue
  19118. // note: avoiding to mutate the shape of 'this' via 'delete'
  19119. this.getValue = this._getValue_unbound;
  19120. this.setValue = this._setValue_unbound;
  19121. }
  19122. }
  19123. PropertyBinding.Composite = Composite;
  19124. PropertyBinding.prototype.BindingType = {
  19125. Direct: 0,
  19126. EntireArray: 1,
  19127. ArrayElement: 2,
  19128. HasFromToArray: 3
  19129. };
  19130. PropertyBinding.prototype.Versioning = {
  19131. None: 0,
  19132. NeedsUpdate: 1,
  19133. MatrixWorldNeedsUpdate: 2
  19134. };
  19135. PropertyBinding.prototype.GetterByBindingType = [
  19136. PropertyBinding.prototype._getValue_direct,
  19137. PropertyBinding.prototype._getValue_array,
  19138. PropertyBinding.prototype._getValue_arrayElement,
  19139. PropertyBinding.prototype._getValue_toArray,
  19140. ];
  19141. PropertyBinding.prototype.SetterByBindingTypeAndVersioning = [
  19142. [
  19143. // Direct
  19144. PropertyBinding.prototype._setValue_direct,
  19145. PropertyBinding.prototype._setValue_direct_setNeedsUpdate,
  19146. PropertyBinding.prototype._setValue_direct_setMatrixWorldNeedsUpdate,
  19147. ], [
  19148. // EntireArray
  19149. PropertyBinding.prototype._setValue_array,
  19150. PropertyBinding.prototype._setValue_array_setNeedsUpdate,
  19151. PropertyBinding.prototype._setValue_array_setMatrixWorldNeedsUpdate,
  19152. ], [
  19153. // ArrayElement
  19154. PropertyBinding.prototype._setValue_arrayElement,
  19155. PropertyBinding.prototype._setValue_arrayElement_setNeedsUpdate,
  19156. PropertyBinding.prototype._setValue_arrayElement_setMatrixWorldNeedsUpdate,
  19157. ], [
  19158. // HasToFromArray
  19159. PropertyBinding.prototype._setValue_fromArray,
  19160. PropertyBinding.prototype._setValue_fromArray_setNeedsUpdate,
  19161. PropertyBinding.prototype._setValue_fromArray_setMatrixWorldNeedsUpdate,
  19162. ]
  19163. ];
  19164. /**
  19165. *
  19166. * A group of objects that receives a shared animation state.
  19167. *
  19168. * Usage:
  19169. *
  19170. * - Add objects you would otherwise pass as 'root' to the
  19171. * constructor or the .clipAction method of AnimationMixer.
  19172. *
  19173. * - Instead pass this object as 'root'.
  19174. *
  19175. * - You can also add and remove objects later when the mixer
  19176. * is running.
  19177. *
  19178. * Note:
  19179. *
  19180. * Objects of this class appear as one object to the mixer,
  19181. * so cache control of the individual objects must be done
  19182. * on the group.
  19183. *
  19184. * Limitation:
  19185. *
  19186. * - The animated properties must be compatible among the
  19187. * all objects in the group.
  19188. *
  19189. * - A single property can either be controlled through a
  19190. * target group or directly, but not both.
  19191. */
  19192. class AnimationObjectGroup {
  19193. constructor() {
  19194. this.isAnimationObjectGroup = true;
  19195. this.uuid = generateUUID();
  19196. // cached objects followed by the active ones
  19197. this._objects = Array.prototype.slice.call( arguments );
  19198. this.nCachedObjects_ = 0; // threshold
  19199. // note: read by PropertyBinding.Composite
  19200. const indices = {};
  19201. this._indicesByUUID = indices; // for bookkeeping
  19202. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19203. indices[ arguments[ i ].uuid ] = i;
  19204. }
  19205. this._paths = []; // inside: string
  19206. this._parsedPaths = []; // inside: { we don't care, here }
  19207. this._bindings = []; // inside: Array< PropertyBinding >
  19208. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  19209. const scope = this;
  19210. this.stats = {
  19211. objects: {
  19212. get total() {
  19213. return scope._objects.length;
  19214. },
  19215. get inUse() {
  19216. return this.total - scope.nCachedObjects_;
  19217. }
  19218. },
  19219. get bindingsPerObject() {
  19220. return scope._bindings.length;
  19221. }
  19222. };
  19223. }
  19224. add() {
  19225. const objects = this._objects,
  19226. indicesByUUID = this._indicesByUUID,
  19227. paths = this._paths,
  19228. parsedPaths = this._parsedPaths,
  19229. bindings = this._bindings,
  19230. nBindings = bindings.length;
  19231. let knownObject = undefined,
  19232. nObjects = objects.length,
  19233. nCachedObjects = this.nCachedObjects_;
  19234. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19235. const object = arguments[ i ],
  19236. uuid = object.uuid;
  19237. let index = indicesByUUID[ uuid ];
  19238. if ( index === undefined ) {
  19239. // unknown object -> add it to the ACTIVE region
  19240. index = nObjects ++;
  19241. indicesByUUID[ uuid ] = index;
  19242. objects.push( object );
  19243. // accounting is done, now do the same for all bindings
  19244. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19245. bindings[ j ].push( new PropertyBinding( object, paths[ j ], parsedPaths[ j ] ) );
  19246. }
  19247. } else if ( index < nCachedObjects ) {
  19248. knownObject = objects[ index ];
  19249. // move existing object to the ACTIVE region
  19250. const firstActiveIndex = -- nCachedObjects,
  19251. lastCachedObject = objects[ firstActiveIndex ];
  19252. indicesByUUID[ lastCachedObject.uuid ] = index;
  19253. objects[ index ] = lastCachedObject;
  19254. indicesByUUID[ uuid ] = firstActiveIndex;
  19255. objects[ firstActiveIndex ] = object;
  19256. // accounting is done, now do the same for all bindings
  19257. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19258. const bindingsForPath = bindings[ j ],
  19259. lastCached = bindingsForPath[ firstActiveIndex ];
  19260. let binding = bindingsForPath[ index ];
  19261. bindingsForPath[ index ] = lastCached;
  19262. if ( binding === undefined ) {
  19263. // since we do not bother to create new bindings
  19264. // for objects that are cached, the binding may
  19265. // or may not exist
  19266. binding = new PropertyBinding( object, paths[ j ], parsedPaths[ j ] );
  19267. }
  19268. bindingsForPath[ firstActiveIndex ] = binding;
  19269. }
  19270. } else if ( objects[ index ] !== knownObject ) {
  19271. console.error( 'THREE.AnimationObjectGroup: Different objects with the same UUID ' +
  19272. 'detected. Clean the caches or recreate your infrastructure when reloading scenes.' );
  19273. } // else the object is already where we want it to be
  19274. } // for arguments
  19275. this.nCachedObjects_ = nCachedObjects;
  19276. }
  19277. remove() {
  19278. const objects = this._objects,
  19279. indicesByUUID = this._indicesByUUID,
  19280. bindings = this._bindings,
  19281. nBindings = bindings.length;
  19282. let nCachedObjects = this.nCachedObjects_;
  19283. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19284. const object = arguments[ i ],
  19285. uuid = object.uuid,
  19286. index = indicesByUUID[ uuid ];
  19287. if ( index !== undefined && index >= nCachedObjects ) {
  19288. // move existing object into the CACHED region
  19289. const lastCachedIndex = nCachedObjects ++,
  19290. firstActiveObject = objects[ lastCachedIndex ];
  19291. indicesByUUID[ firstActiveObject.uuid ] = index;
  19292. objects[ index ] = firstActiveObject;
  19293. indicesByUUID[ uuid ] = lastCachedIndex;
  19294. objects[ lastCachedIndex ] = object;
  19295. // accounting is done, now do the same for all bindings
  19296. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19297. const bindingsForPath = bindings[ j ],
  19298. firstActive = bindingsForPath[ lastCachedIndex ],
  19299. binding = bindingsForPath[ index ];
  19300. bindingsForPath[ index ] = firstActive;
  19301. bindingsForPath[ lastCachedIndex ] = binding;
  19302. }
  19303. }
  19304. } // for arguments
  19305. this.nCachedObjects_ = nCachedObjects;
  19306. }
  19307. // remove & forget
  19308. uncache() {
  19309. const objects = this._objects,
  19310. indicesByUUID = this._indicesByUUID,
  19311. bindings = this._bindings,
  19312. nBindings = bindings.length;
  19313. let nCachedObjects = this.nCachedObjects_,
  19314. nObjects = objects.length;
  19315. for ( let i = 0, n = arguments.length; i !== n; ++ i ) {
  19316. const object = arguments[ i ],
  19317. uuid = object.uuid,
  19318. index = indicesByUUID[ uuid ];
  19319. if ( index !== undefined ) {
  19320. delete indicesByUUID[ uuid ];
  19321. if ( index < nCachedObjects ) {
  19322. // object is cached, shrink the CACHED region
  19323. const firstActiveIndex = -- nCachedObjects,
  19324. lastCachedObject = objects[ firstActiveIndex ],
  19325. lastIndex = -- nObjects,
  19326. lastObject = objects[ lastIndex ];
  19327. // last cached object takes this object's place
  19328. indicesByUUID[ lastCachedObject.uuid ] = index;
  19329. objects[ index ] = lastCachedObject;
  19330. // last object goes to the activated slot and pop
  19331. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  19332. objects[ firstActiveIndex ] = lastObject;
  19333. objects.pop();
  19334. // accounting is done, now do the same for all bindings
  19335. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19336. const bindingsForPath = bindings[ j ],
  19337. lastCached = bindingsForPath[ firstActiveIndex ],
  19338. last = bindingsForPath[ lastIndex ];
  19339. bindingsForPath[ index ] = lastCached;
  19340. bindingsForPath[ firstActiveIndex ] = last;
  19341. bindingsForPath.pop();
  19342. }
  19343. } else {
  19344. // object is active, just swap with the last and pop
  19345. const lastIndex = -- nObjects,
  19346. lastObject = objects[ lastIndex ];
  19347. if ( lastIndex > 0 ) {
  19348. indicesByUUID[ lastObject.uuid ] = index;
  19349. }
  19350. objects[ index ] = lastObject;
  19351. objects.pop();
  19352. // accounting is done, now do the same for all bindings
  19353. for ( let j = 0, m = nBindings; j !== m; ++ j ) {
  19354. const bindingsForPath = bindings[ j ];
  19355. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  19356. bindingsForPath.pop();
  19357. }
  19358. } // cached or active
  19359. } // if object is known
  19360. } // for arguments
  19361. this.nCachedObjects_ = nCachedObjects;
  19362. }
  19363. // Internal interface used by befriended PropertyBinding.Composite:
  19364. subscribe_( path, parsedPath ) {
  19365. // returns an array of bindings for the given path that is changed
  19366. // according to the contained objects in the group
  19367. const indicesByPath = this._bindingsIndicesByPath;
  19368. let index = indicesByPath[ path ];
  19369. const bindings = this._bindings;
  19370. if ( index !== undefined ) return bindings[ index ];
  19371. const paths = this._paths,
  19372. parsedPaths = this._parsedPaths,
  19373. objects = this._objects,
  19374. nObjects = objects.length,
  19375. nCachedObjects = this.nCachedObjects_,
  19376. bindingsForPath = new Array( nObjects );
  19377. index = bindings.length;
  19378. indicesByPath[ path ] = index;
  19379. paths.push( path );
  19380. parsedPaths.push( parsedPath );
  19381. bindings.push( bindingsForPath );
  19382. for ( let i = nCachedObjects, n = objects.length; i !== n; ++ i ) {
  19383. const object = objects[ i ];
  19384. bindingsForPath[ i ] = new PropertyBinding( object, path, parsedPath );
  19385. }
  19386. return bindingsForPath;
  19387. }
  19388. unsubscribe_( path ) {
  19389. // tells the group to forget about a property path and no longer
  19390. // update the array previously obtained with 'subscribe_'
  19391. const indicesByPath = this._bindingsIndicesByPath,
  19392. index = indicesByPath[ path ];
  19393. if ( index !== undefined ) {
  19394. const paths = this._paths,
  19395. parsedPaths = this._parsedPaths,
  19396. bindings = this._bindings,
  19397. lastBindingsIndex = bindings.length - 1,
  19398. lastBindings = bindings[ lastBindingsIndex ],
  19399. lastBindingsPath = path[ lastBindingsIndex ];
  19400. indicesByPath[ lastBindingsPath ] = index;
  19401. bindings[ index ] = lastBindings;
  19402. bindings.pop();
  19403. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  19404. parsedPaths.pop();
  19405. paths[ index ] = paths[ lastBindingsIndex ];
  19406. paths.pop();
  19407. }
  19408. }
  19409. }
  19410. class AnimationAction {
  19411. constructor( mixer, clip, localRoot = null, blendMode = clip.blendMode ) {
  19412. this._mixer = mixer;
  19413. this._clip = clip;
  19414. this._localRoot = localRoot;
  19415. this.blendMode = blendMode;
  19416. const tracks = clip.tracks,
  19417. nTracks = tracks.length,
  19418. interpolants = new Array( nTracks );
  19419. const interpolantSettings = {
  19420. endingStart: ZeroCurvatureEnding,
  19421. endingEnd: ZeroCurvatureEnding
  19422. };
  19423. for ( let i = 0; i !== nTracks; ++ i ) {
  19424. const interpolant = tracks[ i ].createInterpolant( null );
  19425. interpolants[ i ] = interpolant;
  19426. interpolant.settings = interpolantSettings;
  19427. }
  19428. this._interpolantSettings = interpolantSettings;
  19429. this._interpolants = interpolants; // bound by the mixer
  19430. // inside: PropertyMixer (managed by the mixer)
  19431. this._propertyBindings = new Array( nTracks );
  19432. this._cacheIndex = null; // for the memory manager
  19433. this._byClipCacheIndex = null; // for the memory manager
  19434. this._timeScaleInterpolant = null;
  19435. this._weightInterpolant = null;
  19436. this.loop = LoopRepeat;
  19437. this._loopCount = - 1;
  19438. // global mixer time when the action is to be started
  19439. // it's set back to 'null' upon start of the action
  19440. this._startTime = null;
  19441. // scaled local time of the action
  19442. // gets clamped or wrapped to 0..clip.duration according to loop
  19443. this.time = 0;
  19444. this.timeScale = 1;
  19445. this._effectiveTimeScale = 1;
  19446. this.weight = 1;
  19447. this._effectiveWeight = 1;
  19448. this.repetitions = Infinity; // no. of repetitions when looping
  19449. this.paused = false; // true -> zero effective time scale
  19450. this.enabled = true; // false -> zero effective weight
  19451. this.clampWhenFinished = false;// keep feeding the last frame?
  19452. this.zeroSlopeAtStart = true;// for smooth interpolation w/o separate
  19453. this.zeroSlopeAtEnd = true;// clips for start, loop and end
  19454. }
  19455. // State & Scheduling
  19456. play() {
  19457. this._mixer._activateAction( this );
  19458. return this;
  19459. }
  19460. stop() {
  19461. this._mixer._deactivateAction( this );
  19462. return this.reset();
  19463. }
  19464. reset() {
  19465. this.paused = false;
  19466. this.enabled = true;
  19467. this.time = 0; // restart clip
  19468. this._loopCount = - 1;// forget previous loops
  19469. this._startTime = null;// forget scheduling
  19470. return this.stopFading().stopWarping();
  19471. }
  19472. isRunning() {
  19473. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  19474. this._startTime === null && this._mixer._isActiveAction( this );
  19475. }
  19476. // return true when play has been called
  19477. isScheduled() {
  19478. return this._mixer._isActiveAction( this );
  19479. }
  19480. startAt( time ) {
  19481. this._startTime = time;
  19482. return this;
  19483. }
  19484. setLoop( mode, repetitions ) {
  19485. this.loop = mode;
  19486. this.repetitions = repetitions;
  19487. return this;
  19488. }
  19489. // Weight
  19490. // set the weight stopping any scheduled fading
  19491. // although .enabled = false yields an effective weight of zero, this
  19492. // method does *not* change .enabled, because it would be confusing
  19493. setEffectiveWeight( weight ) {
  19494. this.weight = weight;
  19495. // note: same logic as when updated at runtime
  19496. this._effectiveWeight = this.enabled ? weight : 0;
  19497. return this.stopFading();
  19498. }
  19499. // return the weight considering fading and .enabled
  19500. getEffectiveWeight() {
  19501. return this._effectiveWeight;
  19502. }
  19503. fadeIn( duration ) {
  19504. return this._scheduleFading( duration, 0, 1 );
  19505. }
  19506. fadeOut( duration ) {
  19507. return this._scheduleFading( duration, 1, 0 );
  19508. }
  19509. crossFadeFrom( fadeOutAction, duration, warp ) {
  19510. fadeOutAction.fadeOut( duration );
  19511. this.fadeIn( duration );
  19512. if ( warp ) {
  19513. const fadeInDuration = this._clip.duration,
  19514. fadeOutDuration = fadeOutAction._clip.duration,
  19515. startEndRatio = fadeOutDuration / fadeInDuration,
  19516. endStartRatio = fadeInDuration / fadeOutDuration;
  19517. fadeOutAction.warp( 1.0, startEndRatio, duration );
  19518. this.warp( endStartRatio, 1.0, duration );
  19519. }
  19520. return this;
  19521. }
  19522. crossFadeTo( fadeInAction, duration, warp ) {
  19523. return fadeInAction.crossFadeFrom( this, duration, warp );
  19524. }
  19525. stopFading() {
  19526. const weightInterpolant = this._weightInterpolant;
  19527. if ( weightInterpolant !== null ) {
  19528. this._weightInterpolant = null;
  19529. this._mixer._takeBackControlInterpolant( weightInterpolant );
  19530. }
  19531. return this;
  19532. }
  19533. // Time Scale Control
  19534. // set the time scale stopping any scheduled warping
  19535. // although .paused = true yields an effective time scale of zero, this
  19536. // method does *not* change .paused, because it would be confusing
  19537. setEffectiveTimeScale( timeScale ) {
  19538. this.timeScale = timeScale;
  19539. this._effectiveTimeScale = this.paused ? 0 : timeScale;
  19540. return this.stopWarping();
  19541. }
  19542. // return the time scale considering warping and .paused
  19543. getEffectiveTimeScale() {
  19544. return this._effectiveTimeScale;
  19545. }
  19546. setDuration( duration ) {
  19547. this.timeScale = this._clip.duration / duration;
  19548. return this.stopWarping();
  19549. }
  19550. syncWith( action ) {
  19551. this.time = action.time;
  19552. this.timeScale = action.timeScale;
  19553. return this.stopWarping();
  19554. }
  19555. halt( duration ) {
  19556. return this.warp( this._effectiveTimeScale, 0, duration );
  19557. }
  19558. warp( startTimeScale, endTimeScale, duration ) {
  19559. const mixer = this._mixer,
  19560. now = mixer.time,
  19561. timeScale = this.timeScale;
  19562. let interpolant = this._timeScaleInterpolant;
  19563. if ( interpolant === null ) {
  19564. interpolant = mixer._lendControlInterpolant();
  19565. this._timeScaleInterpolant = interpolant;
  19566. }
  19567. const times = interpolant.parameterPositions,
  19568. values = interpolant.sampleValues;
  19569. times[ 0 ] = now;
  19570. times[ 1 ] = now + duration;
  19571. values[ 0 ] = startTimeScale / timeScale;
  19572. values[ 1 ] = endTimeScale / timeScale;
  19573. return this;
  19574. }
  19575. stopWarping() {
  19576. const timeScaleInterpolant = this._timeScaleInterpolant;
  19577. if ( timeScaleInterpolant !== null ) {
  19578. this._timeScaleInterpolant = null;
  19579. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  19580. }
  19581. return this;
  19582. }
  19583. // Object Accessors
  19584. getMixer() {
  19585. return this._mixer;
  19586. }
  19587. getClip() {
  19588. return this._clip;
  19589. }
  19590. getRoot() {
  19591. return this._localRoot || this._mixer._root;
  19592. }
  19593. // Interna
  19594. _update( time, deltaTime, timeDirection, accuIndex ) {
  19595. // called by the mixer
  19596. if ( ! this.enabled ) {
  19597. // call ._updateWeight() to update ._effectiveWeight
  19598. this._updateWeight( time );
  19599. return;
  19600. }
  19601. const startTime = this._startTime;
  19602. if ( startTime !== null ) {
  19603. // check for scheduled start of action
  19604. const timeRunning = ( time - startTime ) * timeDirection;
  19605. if ( timeRunning < 0 || timeDirection === 0 ) {
  19606. deltaTime = 0;
  19607. } else {
  19608. this._startTime = null; // unschedule
  19609. deltaTime = timeDirection * timeRunning;
  19610. }
  19611. }
  19612. // apply time scale and advance time
  19613. deltaTime *= this._updateTimeScale( time );
  19614. const clipTime = this._updateTime( deltaTime );
  19615. // note: _updateTime may disable the action resulting in
  19616. // an effective weight of 0
  19617. const weight = this._updateWeight( time );
  19618. if ( weight > 0 ) {
  19619. const interpolants = this._interpolants;
  19620. const propertyMixers = this._propertyBindings;
  19621. switch ( this.blendMode ) {
  19622. case AdditiveAnimationBlendMode:
  19623. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19624. interpolants[ j ].evaluate( clipTime );
  19625. propertyMixers[ j ].accumulateAdditive( weight );
  19626. }
  19627. break;
  19628. case NormalAnimationBlendMode:
  19629. default:
  19630. for ( let j = 0, m = interpolants.length; j !== m; ++ j ) {
  19631. interpolants[ j ].evaluate( clipTime );
  19632. propertyMixers[ j ].accumulate( accuIndex, weight );
  19633. }
  19634. }
  19635. }
  19636. }
  19637. _updateWeight( time ) {
  19638. let weight = 0;
  19639. if ( this.enabled ) {
  19640. weight = this.weight;
  19641. const interpolant = this._weightInterpolant;
  19642. if ( interpolant !== null ) {
  19643. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19644. weight *= interpolantValue;
  19645. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19646. this.stopFading();
  19647. if ( interpolantValue === 0 ) {
  19648. // faded out, disable
  19649. this.enabled = false;
  19650. }
  19651. }
  19652. }
  19653. }
  19654. this._effectiveWeight = weight;
  19655. return weight;
  19656. }
  19657. _updateTimeScale( time ) {
  19658. let timeScale = 0;
  19659. if ( ! this.paused ) {
  19660. timeScale = this.timeScale;
  19661. const interpolant = this._timeScaleInterpolant;
  19662. if ( interpolant !== null ) {
  19663. const interpolantValue = interpolant.evaluate( time )[ 0 ];
  19664. timeScale *= interpolantValue;
  19665. if ( time > interpolant.parameterPositions[ 1 ] ) {
  19666. this.stopWarping();
  19667. if ( timeScale === 0 ) {
  19668. // motion has halted, pause
  19669. this.paused = true;
  19670. } else {
  19671. // warp done - apply final time scale
  19672. this.timeScale = timeScale;
  19673. }
  19674. }
  19675. }
  19676. }
  19677. this._effectiveTimeScale = timeScale;
  19678. return timeScale;
  19679. }
  19680. _updateTime( deltaTime ) {
  19681. const duration = this._clip.duration;
  19682. const loop = this.loop;
  19683. let time = this.time + deltaTime;
  19684. let loopCount = this._loopCount;
  19685. const pingPong = ( loop === LoopPingPong );
  19686. if ( deltaTime === 0 ) {
  19687. if ( loopCount === - 1 ) return time;
  19688. return ( pingPong && ( loopCount & 1 ) === 1 ) ? duration - time : time;
  19689. }
  19690. if ( loop === LoopOnce ) {
  19691. if ( loopCount === - 1 ) {
  19692. // just started
  19693. this._loopCount = 0;
  19694. this._setEndings( true, true, false );
  19695. }
  19696. handle_stop: {
  19697. if ( time >= duration ) {
  19698. time = duration;
  19699. } else if ( time < 0 ) {
  19700. time = 0;
  19701. } else {
  19702. this.time = time;
  19703. break handle_stop;
  19704. }
  19705. if ( this.clampWhenFinished ) this.paused = true;
  19706. else this.enabled = false;
  19707. this.time = time;
  19708. this._mixer.dispatchEvent( {
  19709. type: 'finished', action: this,
  19710. direction: deltaTime < 0 ? - 1 : 1
  19711. } );
  19712. }
  19713. } else { // repetitive Repeat or PingPong
  19714. if ( loopCount === - 1 ) {
  19715. // just started
  19716. if ( deltaTime >= 0 ) {
  19717. loopCount = 0;
  19718. this._setEndings( true, this.repetitions === 0, pingPong );
  19719. } else {
  19720. // when looping in reverse direction, the initial
  19721. // transition through zero counts as a repetition,
  19722. // so leave loopCount at -1
  19723. this._setEndings( this.repetitions === 0, true, pingPong );
  19724. }
  19725. }
  19726. if ( time >= duration || time < 0 ) {
  19727. // wrap around
  19728. const loopDelta = Math.floor( time / duration ); // signed
  19729. time -= duration * loopDelta;
  19730. loopCount += Math.abs( loopDelta );
  19731. const pending = this.repetitions - loopCount;
  19732. if ( pending <= 0 ) {
  19733. // have to stop (switch state, clamp time, fire event)
  19734. if ( this.clampWhenFinished ) this.paused = true;
  19735. else this.enabled = false;
  19736. time = deltaTime > 0 ? duration : 0;
  19737. this.time = time;
  19738. this._mixer.dispatchEvent( {
  19739. type: 'finished', action: this,
  19740. direction: deltaTime > 0 ? 1 : - 1
  19741. } );
  19742. } else {
  19743. // keep running
  19744. if ( pending === 1 ) {
  19745. // entering the last round
  19746. const atStart = deltaTime < 0;
  19747. this._setEndings( atStart, ! atStart, pingPong );
  19748. } else {
  19749. this._setEndings( false, false, pingPong );
  19750. }
  19751. this._loopCount = loopCount;
  19752. this.time = time;
  19753. this._mixer.dispatchEvent( {
  19754. type: 'loop', action: this, loopDelta: loopDelta
  19755. } );
  19756. }
  19757. } else {
  19758. this.time = time;
  19759. }
  19760. if ( pingPong && ( loopCount & 1 ) === 1 ) {
  19761. // invert time for the "pong round"
  19762. return duration - time;
  19763. }
  19764. }
  19765. return time;
  19766. }
  19767. _setEndings( atStart, atEnd, pingPong ) {
  19768. const settings = this._interpolantSettings;
  19769. if ( pingPong ) {
  19770. settings.endingStart = ZeroSlopeEnding;
  19771. settings.endingEnd = ZeroSlopeEnding;
  19772. } else {
  19773. // assuming for LoopOnce atStart == atEnd == true
  19774. if ( atStart ) {
  19775. settings.endingStart = this.zeroSlopeAtStart ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19776. } else {
  19777. settings.endingStart = WrapAroundEnding;
  19778. }
  19779. if ( atEnd ) {
  19780. settings.endingEnd = this.zeroSlopeAtEnd ? ZeroSlopeEnding : ZeroCurvatureEnding;
  19781. } else {
  19782. settings.endingEnd = WrapAroundEnding;
  19783. }
  19784. }
  19785. }
  19786. _scheduleFading( duration, weightNow, weightThen ) {
  19787. const mixer = this._mixer, now = mixer.time;
  19788. let interpolant = this._weightInterpolant;
  19789. if ( interpolant === null ) {
  19790. interpolant = mixer._lendControlInterpolant();
  19791. this._weightInterpolant = interpolant;
  19792. }
  19793. const times = interpolant.parameterPositions,
  19794. values = interpolant.sampleValues;
  19795. times[ 0 ] = now;
  19796. values[ 0 ] = weightNow;
  19797. times[ 1 ] = now + duration;
  19798. values[ 1 ] = weightThen;
  19799. return this;
  19800. }
  19801. }
  19802. const _controlInterpolantsResultBuffer = new Float32Array( 1 );
  19803. class AnimationMixer extends EventDispatcher {
  19804. constructor( root ) {
  19805. super();
  19806. this._root = root;
  19807. this._initMemoryManager();
  19808. this._accuIndex = 0;
  19809. this.time = 0;
  19810. this.timeScale = 1.0;
  19811. }
  19812. _bindAction( action, prototypeAction ) {
  19813. const root = action._localRoot || this._root,
  19814. tracks = action._clip.tracks,
  19815. nTracks = tracks.length,
  19816. bindings = action._propertyBindings,
  19817. interpolants = action._interpolants,
  19818. rootUuid = root.uuid,
  19819. bindingsByRoot = this._bindingsByRootAndName;
  19820. let bindingsByName = bindingsByRoot[ rootUuid ];
  19821. if ( bindingsByName === undefined ) {
  19822. bindingsByName = {};
  19823. bindingsByRoot[ rootUuid ] = bindingsByName;
  19824. }
  19825. for ( let i = 0; i !== nTracks; ++ i ) {
  19826. const track = tracks[ i ],
  19827. trackName = track.name;
  19828. let binding = bindingsByName[ trackName ];
  19829. if ( binding !== undefined ) {
  19830. ++ binding.referenceCount;
  19831. bindings[ i ] = binding;
  19832. } else {
  19833. binding = bindings[ i ];
  19834. if ( binding !== undefined ) {
  19835. // existing binding, make sure the cache knows
  19836. if ( binding._cacheIndex === null ) {
  19837. ++ binding.referenceCount;
  19838. this._addInactiveBinding( binding, rootUuid, trackName );
  19839. }
  19840. continue;
  19841. }
  19842. const path = prototypeAction && prototypeAction.
  19843. _propertyBindings[ i ].binding.parsedPath;
  19844. binding = new PropertyMixer(
  19845. PropertyBinding.create( root, trackName, path ),
  19846. track.ValueTypeName, track.getValueSize() );
  19847. ++ binding.referenceCount;
  19848. this._addInactiveBinding( binding, rootUuid, trackName );
  19849. bindings[ i ] = binding;
  19850. }
  19851. interpolants[ i ].resultBuffer = binding.buffer;
  19852. }
  19853. }
  19854. _activateAction( action ) {
  19855. if ( ! this._isActiveAction( action ) ) {
  19856. if ( action._cacheIndex === null ) {
  19857. // this action has been forgotten by the cache, but the user
  19858. // appears to be still using it -> rebind
  19859. const rootUuid = ( action._localRoot || this._root ).uuid,
  19860. clipUuid = action._clip.uuid,
  19861. actionsForClip = this._actionsByClip[ clipUuid ];
  19862. this._bindAction( action,
  19863. actionsForClip && actionsForClip.knownActions[ 0 ] );
  19864. this._addInactiveAction( action, clipUuid, rootUuid );
  19865. }
  19866. const bindings = action._propertyBindings;
  19867. // increment 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. this._lendBinding( binding );
  19872. binding.saveOriginalState();
  19873. }
  19874. }
  19875. this._lendAction( action );
  19876. }
  19877. }
  19878. _deactivateAction( action ) {
  19879. if ( this._isActiveAction( action ) ) {
  19880. const bindings = action._propertyBindings;
  19881. // decrement reference counts / sort out state
  19882. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19883. const binding = bindings[ i ];
  19884. if ( -- binding.useCount === 0 ) {
  19885. binding.restoreOriginalState();
  19886. this._takeBackBinding( binding );
  19887. }
  19888. }
  19889. this._takeBackAction( action );
  19890. }
  19891. }
  19892. // Memory manager
  19893. _initMemoryManager() {
  19894. this._actions = []; // 'nActiveActions' followed by inactive ones
  19895. this._nActiveActions = 0;
  19896. this._actionsByClip = {};
  19897. // inside:
  19898. // {
  19899. // knownActions: Array< AnimationAction > - used as prototypes
  19900. // actionByRoot: AnimationAction - lookup
  19901. // }
  19902. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  19903. this._nActiveBindings = 0;
  19904. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  19905. this._controlInterpolants = []; // same game as above
  19906. this._nActiveControlInterpolants = 0;
  19907. const scope = this;
  19908. this.stats = {
  19909. actions: {
  19910. get total() {
  19911. return scope._actions.length;
  19912. },
  19913. get inUse() {
  19914. return scope._nActiveActions;
  19915. }
  19916. },
  19917. bindings: {
  19918. get total() {
  19919. return scope._bindings.length;
  19920. },
  19921. get inUse() {
  19922. return scope._nActiveBindings;
  19923. }
  19924. },
  19925. controlInterpolants: {
  19926. get total() {
  19927. return scope._controlInterpolants.length;
  19928. },
  19929. get inUse() {
  19930. return scope._nActiveControlInterpolants;
  19931. }
  19932. }
  19933. };
  19934. }
  19935. // Memory management for AnimationAction objects
  19936. _isActiveAction( action ) {
  19937. const index = action._cacheIndex;
  19938. return index !== null && index < this._nActiveActions;
  19939. }
  19940. _addInactiveAction( action, clipUuid, rootUuid ) {
  19941. const actions = this._actions,
  19942. actionsByClip = this._actionsByClip;
  19943. let actionsForClip = actionsByClip[ clipUuid ];
  19944. if ( actionsForClip === undefined ) {
  19945. actionsForClip = {
  19946. knownActions: [ action ],
  19947. actionByRoot: {}
  19948. };
  19949. action._byClipCacheIndex = 0;
  19950. actionsByClip[ clipUuid ] = actionsForClip;
  19951. } else {
  19952. const knownActions = actionsForClip.knownActions;
  19953. action._byClipCacheIndex = knownActions.length;
  19954. knownActions.push( action );
  19955. }
  19956. action._cacheIndex = actions.length;
  19957. actions.push( action );
  19958. actionsForClip.actionByRoot[ rootUuid ] = action;
  19959. }
  19960. _removeInactiveAction( action ) {
  19961. const actions = this._actions,
  19962. lastInactiveAction = actions[ actions.length - 1 ],
  19963. cacheIndex = action._cacheIndex;
  19964. lastInactiveAction._cacheIndex = cacheIndex;
  19965. actions[ cacheIndex ] = lastInactiveAction;
  19966. actions.pop();
  19967. action._cacheIndex = null;
  19968. const clipUuid = action._clip.uuid,
  19969. actionsByClip = this._actionsByClip,
  19970. actionsForClip = actionsByClip[ clipUuid ],
  19971. knownActionsForClip = actionsForClip.knownActions,
  19972. lastKnownAction =
  19973. knownActionsForClip[ knownActionsForClip.length - 1 ],
  19974. byClipCacheIndex = action._byClipCacheIndex;
  19975. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  19976. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  19977. knownActionsForClip.pop();
  19978. action._byClipCacheIndex = null;
  19979. const actionByRoot = actionsForClip.actionByRoot,
  19980. rootUuid = ( action._localRoot || this._root ).uuid;
  19981. delete actionByRoot[ rootUuid ];
  19982. if ( knownActionsForClip.length === 0 ) {
  19983. delete actionsByClip[ clipUuid ];
  19984. }
  19985. this._removeInactiveBindingsForAction( action );
  19986. }
  19987. _removeInactiveBindingsForAction( action ) {
  19988. const bindings = action._propertyBindings;
  19989. for ( let i = 0, n = bindings.length; i !== n; ++ i ) {
  19990. const binding = bindings[ i ];
  19991. if ( -- binding.referenceCount === 0 ) {
  19992. this._removeInactiveBinding( binding );
  19993. }
  19994. }
  19995. }
  19996. _lendAction( action ) {
  19997. // [ active actions | inactive actions ]
  19998. // [ active actions >| inactive actions ]
  19999. // s a
  20000. // <-swap->
  20001. // a s
  20002. const actions = this._actions,
  20003. prevIndex = action._cacheIndex,
  20004. lastActiveIndex = this._nActiveActions ++,
  20005. firstInactiveAction = actions[ lastActiveIndex ];
  20006. action._cacheIndex = lastActiveIndex;
  20007. actions[ lastActiveIndex ] = action;
  20008. firstInactiveAction._cacheIndex = prevIndex;
  20009. actions[ prevIndex ] = firstInactiveAction;
  20010. }
  20011. _takeBackAction( action ) {
  20012. // [ active actions | inactive actions ]
  20013. // [ active actions |< inactive actions ]
  20014. // a s
  20015. // <-swap->
  20016. // s a
  20017. const actions = this._actions,
  20018. prevIndex = action._cacheIndex,
  20019. firstInactiveIndex = -- this._nActiveActions,
  20020. lastActiveAction = actions[ firstInactiveIndex ];
  20021. action._cacheIndex = firstInactiveIndex;
  20022. actions[ firstInactiveIndex ] = action;
  20023. lastActiveAction._cacheIndex = prevIndex;
  20024. actions[ prevIndex ] = lastActiveAction;
  20025. }
  20026. // Memory management for PropertyMixer objects
  20027. _addInactiveBinding( binding, rootUuid, trackName ) {
  20028. const bindingsByRoot = this._bindingsByRootAndName,
  20029. bindings = this._bindings;
  20030. let bindingByName = bindingsByRoot[ rootUuid ];
  20031. if ( bindingByName === undefined ) {
  20032. bindingByName = {};
  20033. bindingsByRoot[ rootUuid ] = bindingByName;
  20034. }
  20035. bindingByName[ trackName ] = binding;
  20036. binding._cacheIndex = bindings.length;
  20037. bindings.push( binding );
  20038. }
  20039. _removeInactiveBinding( binding ) {
  20040. const bindings = this._bindings,
  20041. propBinding = binding.binding,
  20042. rootUuid = propBinding.rootNode.uuid,
  20043. trackName = propBinding.path,
  20044. bindingsByRoot = this._bindingsByRootAndName,
  20045. bindingByName = bindingsByRoot[ rootUuid ],
  20046. lastInactiveBinding = bindings[ bindings.length - 1 ],
  20047. cacheIndex = binding._cacheIndex;
  20048. lastInactiveBinding._cacheIndex = cacheIndex;
  20049. bindings[ cacheIndex ] = lastInactiveBinding;
  20050. bindings.pop();
  20051. delete bindingByName[ trackName ];
  20052. if ( Object.keys( bindingByName ).length === 0 ) {
  20053. delete bindingsByRoot[ rootUuid ];
  20054. }
  20055. }
  20056. _lendBinding( binding ) {
  20057. const bindings = this._bindings,
  20058. prevIndex = binding._cacheIndex,
  20059. lastActiveIndex = this._nActiveBindings ++,
  20060. firstInactiveBinding = bindings[ lastActiveIndex ];
  20061. binding._cacheIndex = lastActiveIndex;
  20062. bindings[ lastActiveIndex ] = binding;
  20063. firstInactiveBinding._cacheIndex = prevIndex;
  20064. bindings[ prevIndex ] = firstInactiveBinding;
  20065. }
  20066. _takeBackBinding( binding ) {
  20067. const bindings = this._bindings,
  20068. prevIndex = binding._cacheIndex,
  20069. firstInactiveIndex = -- this._nActiveBindings,
  20070. lastActiveBinding = bindings[ firstInactiveIndex ];
  20071. binding._cacheIndex = firstInactiveIndex;
  20072. bindings[ firstInactiveIndex ] = binding;
  20073. lastActiveBinding._cacheIndex = prevIndex;
  20074. bindings[ prevIndex ] = lastActiveBinding;
  20075. }
  20076. // Memory management of Interpolants for weight and time scale
  20077. _lendControlInterpolant() {
  20078. const interpolants = this._controlInterpolants,
  20079. lastActiveIndex = this._nActiveControlInterpolants ++;
  20080. let interpolant = interpolants[ lastActiveIndex ];
  20081. if ( interpolant === undefined ) {
  20082. interpolant = new LinearInterpolant(
  20083. new Float32Array( 2 ), new Float32Array( 2 ),
  20084. 1, _controlInterpolantsResultBuffer );
  20085. interpolant.__cacheIndex = lastActiveIndex;
  20086. interpolants[ lastActiveIndex ] = interpolant;
  20087. }
  20088. return interpolant;
  20089. }
  20090. _takeBackControlInterpolant( interpolant ) {
  20091. const interpolants = this._controlInterpolants,
  20092. prevIndex = interpolant.__cacheIndex,
  20093. firstInactiveIndex = -- this._nActiveControlInterpolants,
  20094. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  20095. interpolant.__cacheIndex = firstInactiveIndex;
  20096. interpolants[ firstInactiveIndex ] = interpolant;
  20097. lastActiveInterpolant.__cacheIndex = prevIndex;
  20098. interpolants[ prevIndex ] = lastActiveInterpolant;
  20099. }
  20100. // return an action for a clip optionally using a custom root target
  20101. // object (this method allocates a lot of dynamic memory in case a
  20102. // previously unknown clip/root combination is specified)
  20103. clipAction( clip, optionalRoot, blendMode ) {
  20104. const root = optionalRoot || this._root,
  20105. rootUuid = root.uuid;
  20106. let clipObject = typeof clip === 'string' ? AnimationClip.findByName( root, clip ) : clip;
  20107. const clipUuid = clipObject !== null ? clipObject.uuid : clip;
  20108. const actionsForClip = this._actionsByClip[ clipUuid ];
  20109. let prototypeAction = null;
  20110. if ( blendMode === undefined ) {
  20111. if ( clipObject !== null ) {
  20112. blendMode = clipObject.blendMode;
  20113. } else {
  20114. blendMode = NormalAnimationBlendMode;
  20115. }
  20116. }
  20117. if ( actionsForClip !== undefined ) {
  20118. const existingAction = actionsForClip.actionByRoot[ rootUuid ];
  20119. if ( existingAction !== undefined && existingAction.blendMode === blendMode ) {
  20120. return existingAction;
  20121. }
  20122. // we know the clip, so we don't have to parse all
  20123. // the bindings again but can just copy
  20124. prototypeAction = actionsForClip.knownActions[ 0 ];
  20125. // also, take the clip from the prototype action
  20126. if ( clipObject === null )
  20127. clipObject = prototypeAction._clip;
  20128. }
  20129. // clip must be known when specified via string
  20130. if ( clipObject === null ) return null;
  20131. // allocate all resources required to run it
  20132. const newAction = new AnimationAction( this, clipObject, optionalRoot, blendMode );
  20133. this._bindAction( newAction, prototypeAction );
  20134. // and make the action known to the memory manager
  20135. this._addInactiveAction( newAction, clipUuid, rootUuid );
  20136. return newAction;
  20137. }
  20138. // get an existing action
  20139. existingAction( clip, optionalRoot ) {
  20140. const root = optionalRoot || this._root,
  20141. rootUuid = root.uuid,
  20142. clipObject = typeof clip === 'string' ?
  20143. AnimationClip.findByName( root, clip ) : clip,
  20144. clipUuid = clipObject ? clipObject.uuid : clip,
  20145. actionsForClip = this._actionsByClip[ clipUuid ];
  20146. if ( actionsForClip !== undefined ) {
  20147. return actionsForClip.actionByRoot[ rootUuid ] || null;
  20148. }
  20149. return null;
  20150. }
  20151. // deactivates all previously scheduled actions
  20152. stopAllAction() {
  20153. const actions = this._actions,
  20154. nActions = this._nActiveActions;
  20155. for ( let i = nActions - 1; i >= 0; -- i ) {
  20156. actions[ i ].stop();
  20157. }
  20158. return this;
  20159. }
  20160. // advance the time and update apply the animation
  20161. update( deltaTime ) {
  20162. deltaTime *= this.timeScale;
  20163. const actions = this._actions,
  20164. nActions = this._nActiveActions,
  20165. time = this.time += deltaTime,
  20166. timeDirection = Math.sign( deltaTime ),
  20167. accuIndex = this._accuIndex ^= 1;
  20168. // run active actions
  20169. for ( let i = 0; i !== nActions; ++ i ) {
  20170. const action = actions[ i ];
  20171. action._update( time, deltaTime, timeDirection, accuIndex );
  20172. }
  20173. // update scene graph
  20174. const bindings = this._bindings,
  20175. nBindings = this._nActiveBindings;
  20176. for ( let i = 0; i !== nBindings; ++ i ) {
  20177. bindings[ i ].apply( accuIndex );
  20178. }
  20179. return this;
  20180. }
  20181. // Allows you to seek to a specific time in an animation.
  20182. setTime( timeInSeconds ) {
  20183. this.time = 0; // Zero out time attribute for AnimationMixer object;
  20184. for ( let i = 0; i < this._actions.length; i ++ ) {
  20185. this._actions[ i ].time = 0; // Zero out time attribute for all associated AnimationAction objects.
  20186. }
  20187. return this.update( timeInSeconds ); // Update used to set exact time. Returns "this" AnimationMixer object.
  20188. }
  20189. // return this mixer's root target object
  20190. getRoot() {
  20191. return this._root;
  20192. }
  20193. // free all resources specific to a particular clip
  20194. uncacheClip( clip ) {
  20195. const actions = this._actions,
  20196. clipUuid = clip.uuid,
  20197. actionsByClip = this._actionsByClip,
  20198. actionsForClip = actionsByClip[ clipUuid ];
  20199. if ( actionsForClip !== undefined ) {
  20200. // note: just calling _removeInactiveAction would mess up the
  20201. // iteration state and also require updating the state we can
  20202. // just throw away
  20203. const actionsToRemove = actionsForClip.knownActions;
  20204. for ( let i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  20205. const action = actionsToRemove[ i ];
  20206. this._deactivateAction( action );
  20207. const cacheIndex = action._cacheIndex,
  20208. lastInactiveAction = actions[ actions.length - 1 ];
  20209. action._cacheIndex = null;
  20210. action._byClipCacheIndex = null;
  20211. lastInactiveAction._cacheIndex = cacheIndex;
  20212. actions[ cacheIndex ] = lastInactiveAction;
  20213. actions.pop();
  20214. this._removeInactiveBindingsForAction( action );
  20215. }
  20216. delete actionsByClip[ clipUuid ];
  20217. }
  20218. }
  20219. // free all resources specific to a particular root target object
  20220. uncacheRoot( root ) {
  20221. const rootUuid = root.uuid,
  20222. actionsByClip = this._actionsByClip;
  20223. for ( const clipUuid in actionsByClip ) {
  20224. const actionByRoot = actionsByClip[ clipUuid ].actionByRoot,
  20225. action = actionByRoot[ rootUuid ];
  20226. if ( action !== undefined ) {
  20227. this._deactivateAction( action );
  20228. this._removeInactiveAction( action );
  20229. }
  20230. }
  20231. const bindingsByRoot = this._bindingsByRootAndName,
  20232. bindingByName = bindingsByRoot[ rootUuid ];
  20233. if ( bindingByName !== undefined ) {
  20234. for ( const trackName in bindingByName ) {
  20235. const binding = bindingByName[ trackName ];
  20236. binding.restoreOriginalState();
  20237. this._removeInactiveBinding( binding );
  20238. }
  20239. }
  20240. }
  20241. // remove a targeted clip from the cache
  20242. uncacheAction( clip, optionalRoot ) {
  20243. const action = this.existingAction( clip, optionalRoot );
  20244. if ( action !== null ) {
  20245. this._deactivateAction( action );
  20246. this._removeInactiveAction( action );
  20247. }
  20248. }
  20249. }
  20250. class Uniform {
  20251. constructor( value ) {
  20252. this.value = value;
  20253. }
  20254. clone() {
  20255. return new Uniform( this.value.clone === undefined ? this.value : this.value.clone() );
  20256. }
  20257. }
  20258. let _id = 0;
  20259. class UniformsGroup extends EventDispatcher {
  20260. constructor() {
  20261. super();
  20262. this.isUniformsGroup = true;
  20263. Object.defineProperty( this, 'id', { value: _id ++ } );
  20264. this.name = '';
  20265. this.usage = StaticDrawUsage;
  20266. this.uniforms = [];
  20267. }
  20268. add( uniform ) {
  20269. this.uniforms.push( uniform );
  20270. return this;
  20271. }
  20272. remove( uniform ) {
  20273. const index = this.uniforms.indexOf( uniform );
  20274. if ( index !== - 1 ) this.uniforms.splice( index, 1 );
  20275. return this;
  20276. }
  20277. setName( name ) {
  20278. this.name = name;
  20279. return this;
  20280. }
  20281. setUsage( value ) {
  20282. this.usage = value;
  20283. return this;
  20284. }
  20285. dispose() {
  20286. this.dispatchEvent( { type: 'dispose' } );
  20287. return this;
  20288. }
  20289. copy( source ) {
  20290. this.name = source.name;
  20291. this.usage = source.usage;
  20292. const uniformsSource = source.uniforms;
  20293. this.uniforms.length = 0;
  20294. for ( let i = 0, l = uniformsSource.length; i < l; i ++ ) {
  20295. const uniforms = Array.isArray( uniformsSource[ i ] ) ? uniformsSource[ i ] : [ uniformsSource[ i ] ];
  20296. for ( let j = 0; j < uniforms.length; j ++ ) {
  20297. this.uniforms.push( uniforms[ j ].clone() );
  20298. }
  20299. }
  20300. return this;
  20301. }
  20302. clone() {
  20303. return new this.constructor().copy( this );
  20304. }
  20305. }
  20306. class InstancedInterleavedBuffer extends InterleavedBuffer {
  20307. constructor( array, stride, meshPerAttribute = 1 ) {
  20308. super( array, stride );
  20309. this.isInstancedInterleavedBuffer = true;
  20310. this.meshPerAttribute = meshPerAttribute;
  20311. }
  20312. copy( source ) {
  20313. super.copy( source );
  20314. this.meshPerAttribute = source.meshPerAttribute;
  20315. return this;
  20316. }
  20317. clone( data ) {
  20318. const ib = super.clone( data );
  20319. ib.meshPerAttribute = this.meshPerAttribute;
  20320. return ib;
  20321. }
  20322. toJSON( data ) {
  20323. const json = super.toJSON( data );
  20324. json.isInstancedInterleavedBuffer = true;
  20325. json.meshPerAttribute = this.meshPerAttribute;
  20326. return json;
  20327. }
  20328. }
  20329. class GLBufferAttribute {
  20330. constructor( buffer, type, itemSize, elementSize, count ) {
  20331. this.isGLBufferAttribute = true;
  20332. this.name = '';
  20333. this.buffer = buffer;
  20334. this.type = type;
  20335. this.itemSize = itemSize;
  20336. this.elementSize = elementSize;
  20337. this.count = count;
  20338. this.version = 0;
  20339. }
  20340. set needsUpdate( value ) {
  20341. if ( value === true ) this.version ++;
  20342. }
  20343. setBuffer( buffer ) {
  20344. this.buffer = buffer;
  20345. return this;
  20346. }
  20347. setType( type, elementSize ) {
  20348. this.type = type;
  20349. this.elementSize = elementSize;
  20350. return this;
  20351. }
  20352. setItemSize( itemSize ) {
  20353. this.itemSize = itemSize;
  20354. return this;
  20355. }
  20356. setCount( count ) {
  20357. this.count = count;
  20358. return this;
  20359. }
  20360. }
  20361. const _matrix = /*@__PURE__*/ new Matrix4();
  20362. class Raycaster {
  20363. constructor( origin, direction, near = 0, far = Infinity ) {
  20364. this.ray = new Ray( origin, direction );
  20365. // direction is assumed to be normalized (for accurate distance calculations)
  20366. this.near = near;
  20367. this.far = far;
  20368. this.camera = null;
  20369. this.layers = new Layers();
  20370. this.params = {
  20371. Mesh: {},
  20372. Line: { threshold: 1 },
  20373. LOD: {},
  20374. Points: { threshold: 1 },
  20375. Sprite: {}
  20376. };
  20377. }
  20378. set( origin, direction ) {
  20379. // direction is assumed to be normalized (for accurate distance calculations)
  20380. this.ray.set( origin, direction );
  20381. }
  20382. setFromCamera( coords, camera ) {
  20383. if ( camera.isPerspectiveCamera ) {
  20384. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  20385. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  20386. this.camera = camera;
  20387. } else if ( camera.isOrthographicCamera ) {
  20388. this.ray.origin.set( coords.x, coords.y, ( camera.near + camera.far ) / ( camera.near - camera.far ) ).unproject( camera ); // set origin in plane of camera
  20389. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  20390. this.camera = camera;
  20391. } else {
  20392. console.error( 'THREE.Raycaster: Unsupported camera type: ' + camera.type );
  20393. }
  20394. }
  20395. setFromXRController( controller ) {
  20396. _matrix.identity().extractRotation( controller.matrixWorld );
  20397. this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
  20398. this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
  20399. return this;
  20400. }
  20401. intersectObject( object, recursive = true, intersects = [] ) {
  20402. intersect( object, this, intersects, recursive );
  20403. intersects.sort( ascSort );
  20404. return intersects;
  20405. }
  20406. intersectObjects( objects, recursive = true, intersects = [] ) {
  20407. for ( let i = 0, l = objects.length; i < l; i ++ ) {
  20408. intersect( objects[ i ], this, intersects, recursive );
  20409. }
  20410. intersects.sort( ascSort );
  20411. return intersects;
  20412. }
  20413. }
  20414. function ascSort( a, b ) {
  20415. return a.distance - b.distance;
  20416. }
  20417. function intersect( object, raycaster, intersects, recursive ) {
  20418. let propagate = true;
  20419. if ( object.layers.test( raycaster.layers ) ) {
  20420. const result = object.raycast( raycaster, intersects );
  20421. if ( result === false ) propagate = false;
  20422. }
  20423. if ( propagate === true && recursive === true ) {
  20424. const children = object.children;
  20425. for ( let i = 0, l = children.length; i < l; i ++ ) {
  20426. intersect( children[ i ], raycaster, intersects, true );
  20427. }
  20428. }
  20429. }
  20430. /**
  20431. * Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
  20432. *
  20433. * phi (the polar angle) is measured from the positive y-axis. The positive y-axis is up.
  20434. * theta (the azimuthal angle) is measured from the positive z-axis.
  20435. */
  20436. class Spherical {
  20437. constructor( radius = 1, phi = 0, theta = 0 ) {
  20438. this.radius = radius;
  20439. this.phi = phi; // polar angle
  20440. this.theta = theta; // azimuthal angle
  20441. return this;
  20442. }
  20443. set( radius, phi, theta ) {
  20444. this.radius = radius;
  20445. this.phi = phi;
  20446. this.theta = theta;
  20447. return this;
  20448. }
  20449. copy( other ) {
  20450. this.radius = other.radius;
  20451. this.phi = other.phi;
  20452. this.theta = other.theta;
  20453. return this;
  20454. }
  20455. // restrict phi to be between EPS and PI-EPS
  20456. makeSafe() {
  20457. const EPS = 0.000001;
  20458. this.phi = clamp( this.phi, EPS, Math.PI - EPS );
  20459. return this;
  20460. }
  20461. setFromVector3( v ) {
  20462. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20463. }
  20464. setFromCartesianCoords( x, y, z ) {
  20465. this.radius = Math.sqrt( x * x + y * y + z * z );
  20466. if ( this.radius === 0 ) {
  20467. this.theta = 0;
  20468. this.phi = 0;
  20469. } else {
  20470. this.theta = Math.atan2( x, z );
  20471. this.phi = Math.acos( clamp( y / this.radius, - 1, 1 ) );
  20472. }
  20473. return this;
  20474. }
  20475. clone() {
  20476. return new this.constructor().copy( this );
  20477. }
  20478. }
  20479. /**
  20480. * Ref: https://en.wikipedia.org/wiki/Cylindrical_coordinate_system
  20481. */
  20482. class Cylindrical {
  20483. constructor( radius = 1, theta = 0, y = 0 ) {
  20484. this.radius = radius; // distance from the origin to a point in the x-z plane
  20485. this.theta = theta; // counterclockwise angle in the x-z plane measured in radians from the positive z-axis
  20486. this.y = y; // height above the x-z plane
  20487. return this;
  20488. }
  20489. set( radius, theta, y ) {
  20490. this.radius = radius;
  20491. this.theta = theta;
  20492. this.y = y;
  20493. return this;
  20494. }
  20495. copy( other ) {
  20496. this.radius = other.radius;
  20497. this.theta = other.theta;
  20498. this.y = other.y;
  20499. return this;
  20500. }
  20501. setFromVector3( v ) {
  20502. return this.setFromCartesianCoords( v.x, v.y, v.z );
  20503. }
  20504. setFromCartesianCoords( x, y, z ) {
  20505. this.radius = Math.sqrt( x * x + z * z );
  20506. this.theta = Math.atan2( x, z );
  20507. this.y = y;
  20508. return this;
  20509. }
  20510. clone() {
  20511. return new this.constructor().copy( this );
  20512. }
  20513. }
  20514. class Matrix2 {
  20515. constructor( n11, n12, n21, n22 ) {
  20516. Matrix2.prototype.isMatrix2 = true;
  20517. this.elements = [
  20518. 1, 0,
  20519. 0, 1,
  20520. ];
  20521. if ( n11 !== undefined ) {
  20522. this.set( n11, n12, n21, n22 );
  20523. }
  20524. }
  20525. identity() {
  20526. this.set(
  20527. 1, 0,
  20528. 0, 1,
  20529. );
  20530. return this;
  20531. }
  20532. fromArray( array, offset = 0 ) {
  20533. for ( let i = 0; i < 4; i ++ ) {
  20534. this.elements[ i ] = array[ i + offset ];
  20535. }
  20536. return this;
  20537. }
  20538. set( n11, n12, n21, n22 ) {
  20539. const te = this.elements;
  20540. te[ 0 ] = n11; te[ 2 ] = n12;
  20541. te[ 1 ] = n21; te[ 3 ] = n22;
  20542. return this;
  20543. }
  20544. }
  20545. const _vector$4 = /*@__PURE__*/ new Vector2();
  20546. class Box2 {
  20547. constructor( min = new Vector2( + Infinity, + Infinity ), max = new Vector2( - Infinity, - Infinity ) ) {
  20548. this.isBox2 = true;
  20549. this.min = min;
  20550. this.max = max;
  20551. }
  20552. set( min, max ) {
  20553. this.min.copy( min );
  20554. this.max.copy( max );
  20555. return this;
  20556. }
  20557. setFromPoints( points ) {
  20558. this.makeEmpty();
  20559. for ( let i = 0, il = points.length; i < il; i ++ ) {
  20560. this.expandByPoint( points[ i ] );
  20561. }
  20562. return this;
  20563. }
  20564. setFromCenterAndSize( center, size ) {
  20565. const halfSize = _vector$4.copy( size ).multiplyScalar( 0.5 );
  20566. this.min.copy( center ).sub( halfSize );
  20567. this.max.copy( center ).add( halfSize );
  20568. return this;
  20569. }
  20570. clone() {
  20571. return new this.constructor().copy( this );
  20572. }
  20573. copy( box ) {
  20574. this.min.copy( box.min );
  20575. this.max.copy( box.max );
  20576. return this;
  20577. }
  20578. makeEmpty() {
  20579. this.min.x = this.min.y = + Infinity;
  20580. this.max.x = this.max.y = - Infinity;
  20581. return this;
  20582. }
  20583. isEmpty() {
  20584. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  20585. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  20586. }
  20587. getCenter( target ) {
  20588. return this.isEmpty() ? target.set( 0, 0 ) : target.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  20589. }
  20590. getSize( target ) {
  20591. return this.isEmpty() ? target.set( 0, 0 ) : target.subVectors( this.max, this.min );
  20592. }
  20593. expandByPoint( point ) {
  20594. this.min.min( point );
  20595. this.max.max( point );
  20596. return this;
  20597. }
  20598. expandByVector( vector ) {
  20599. this.min.sub( vector );
  20600. this.max.add( vector );
  20601. return this;
  20602. }
  20603. expandByScalar( scalar ) {
  20604. this.min.addScalar( - scalar );
  20605. this.max.addScalar( scalar );
  20606. return this;
  20607. }
  20608. containsPoint( point ) {
  20609. return point.x >= this.min.x && point.x <= this.max.x &&
  20610. point.y >= this.min.y && point.y <= this.max.y;
  20611. }
  20612. containsBox( box ) {
  20613. return this.min.x <= box.min.x && box.max.x <= this.max.x &&
  20614. this.min.y <= box.min.y && box.max.y <= this.max.y;
  20615. }
  20616. getParameter( point, target ) {
  20617. // This can potentially have a divide by zero if the box
  20618. // has a size dimension of 0.
  20619. return target.set(
  20620. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  20621. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  20622. );
  20623. }
  20624. intersectsBox( box ) {
  20625. // using 4 splitting planes to rule out intersections
  20626. return box.max.x >= this.min.x && box.min.x <= this.max.x &&
  20627. box.max.y >= this.min.y && box.min.y <= this.max.y;
  20628. }
  20629. clampPoint( point, target ) {
  20630. return target.copy( point ).clamp( this.min, this.max );
  20631. }
  20632. distanceToPoint( point ) {
  20633. return this.clampPoint( point, _vector$4 ).distanceTo( point );
  20634. }
  20635. intersect( box ) {
  20636. this.min.max( box.min );
  20637. this.max.min( box.max );
  20638. if ( this.isEmpty() ) this.makeEmpty();
  20639. return this;
  20640. }
  20641. union( box ) {
  20642. this.min.min( box.min );
  20643. this.max.max( box.max );
  20644. return this;
  20645. }
  20646. translate( offset ) {
  20647. this.min.add( offset );
  20648. this.max.add( offset );
  20649. return this;
  20650. }
  20651. equals( box ) {
  20652. return box.min.equals( this.min ) && box.max.equals( this.max );
  20653. }
  20654. }
  20655. const _startP = /*@__PURE__*/ new Vector3();
  20656. const _startEnd = /*@__PURE__*/ new Vector3();
  20657. class Line3 {
  20658. constructor( start = new Vector3(), end = new Vector3() ) {
  20659. this.start = start;
  20660. this.end = end;
  20661. }
  20662. set( start, end ) {
  20663. this.start.copy( start );
  20664. this.end.copy( end );
  20665. return this;
  20666. }
  20667. copy( line ) {
  20668. this.start.copy( line.start );
  20669. this.end.copy( line.end );
  20670. return this;
  20671. }
  20672. getCenter( target ) {
  20673. return target.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  20674. }
  20675. delta( target ) {
  20676. return target.subVectors( this.end, this.start );
  20677. }
  20678. distanceSq() {
  20679. return this.start.distanceToSquared( this.end );
  20680. }
  20681. distance() {
  20682. return this.start.distanceTo( this.end );
  20683. }
  20684. at( t, target ) {
  20685. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20686. }
  20687. closestPointToPointParameter( point, clampToLine ) {
  20688. _startP.subVectors( point, this.start );
  20689. _startEnd.subVectors( this.end, this.start );
  20690. const startEnd2 = _startEnd.dot( _startEnd );
  20691. const startEnd_startP = _startEnd.dot( _startP );
  20692. let t = startEnd_startP / startEnd2;
  20693. if ( clampToLine ) {
  20694. t = clamp( t, 0, 1 );
  20695. }
  20696. return t;
  20697. }
  20698. closestPointToPoint( point, clampToLine, target ) {
  20699. const t = this.closestPointToPointParameter( point, clampToLine );
  20700. return this.delta( target ).multiplyScalar( t ).add( this.start );
  20701. }
  20702. applyMatrix4( matrix ) {
  20703. this.start.applyMatrix4( matrix );
  20704. this.end.applyMatrix4( matrix );
  20705. return this;
  20706. }
  20707. equals( line ) {
  20708. return line.start.equals( this.start ) && line.end.equals( this.end );
  20709. }
  20710. clone() {
  20711. return new this.constructor().copy( this );
  20712. }
  20713. }
  20714. const _vector$3 = /*@__PURE__*/ new Vector3();
  20715. class SpotLightHelper extends Object3D {
  20716. constructor( light, color ) {
  20717. super();
  20718. this.light = light;
  20719. this.matrixAutoUpdate = false;
  20720. this.color = color;
  20721. this.type = 'SpotLightHelper';
  20722. const geometry = new BufferGeometry();
  20723. const positions = [
  20724. 0, 0, 0, 0, 0, 1,
  20725. 0, 0, 0, 1, 0, 1,
  20726. 0, 0, 0, - 1, 0, 1,
  20727. 0, 0, 0, 0, 1, 1,
  20728. 0, 0, 0, 0, - 1, 1
  20729. ];
  20730. for ( let i = 0, j = 1, l = 32; i < l; i ++, j ++ ) {
  20731. const p1 = ( i / l ) * Math.PI * 2;
  20732. const p2 = ( j / l ) * Math.PI * 2;
  20733. positions.push(
  20734. Math.cos( p1 ), Math.sin( p1 ), 1,
  20735. Math.cos( p2 ), Math.sin( p2 ), 1
  20736. );
  20737. }
  20738. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  20739. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  20740. this.cone = new LineSegments( geometry, material );
  20741. this.add( this.cone );
  20742. this.update();
  20743. }
  20744. dispose() {
  20745. this.cone.geometry.dispose();
  20746. this.cone.material.dispose();
  20747. }
  20748. update() {
  20749. this.light.updateWorldMatrix( true, false );
  20750. this.light.target.updateWorldMatrix( true, false );
  20751. // update the local matrix based on the parent and light target transforms
  20752. if ( this.parent ) {
  20753. this.parent.updateWorldMatrix( true );
  20754. this.matrix
  20755. .copy( this.parent.matrixWorld )
  20756. .invert()
  20757. .multiply( this.light.matrixWorld );
  20758. } else {
  20759. this.matrix.copy( this.light.matrixWorld );
  20760. }
  20761. this.matrixWorld.copy( this.light.matrixWorld );
  20762. const coneLength = this.light.distance ? this.light.distance : 1000;
  20763. const coneWidth = coneLength * Math.tan( this.light.angle );
  20764. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  20765. _vector$3.setFromMatrixPosition( this.light.target.matrixWorld );
  20766. this.cone.lookAt( _vector$3 );
  20767. if ( this.color !== undefined ) {
  20768. this.cone.material.color.set( this.color );
  20769. } else {
  20770. this.cone.material.color.copy( this.light.color );
  20771. }
  20772. }
  20773. }
  20774. const _vector$2 = /*@__PURE__*/ new Vector3();
  20775. const _boneMatrix = /*@__PURE__*/ new Matrix4();
  20776. const _matrixWorldInv = /*@__PURE__*/ new Matrix4();
  20777. class SkeletonHelper extends LineSegments {
  20778. constructor( object ) {
  20779. const bones = getBoneList( object );
  20780. const geometry = new BufferGeometry();
  20781. const vertices = [];
  20782. const colors = [];
  20783. const color1 = new Color( 0, 0, 1 );
  20784. const color2 = new Color( 0, 1, 0 );
  20785. for ( let i = 0; i < bones.length; i ++ ) {
  20786. const bone = bones[ i ];
  20787. if ( bone.parent && bone.parent.isBone ) {
  20788. vertices.push( 0, 0, 0 );
  20789. vertices.push( 0, 0, 0 );
  20790. colors.push( color1.r, color1.g, color1.b );
  20791. colors.push( color2.r, color2.g, color2.b );
  20792. }
  20793. }
  20794. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20795. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20796. const material = new LineBasicMaterial( { vertexColors: true, depthTest: false, depthWrite: false, toneMapped: false, transparent: true } );
  20797. super( geometry, material );
  20798. this.isSkeletonHelper = true;
  20799. this.type = 'SkeletonHelper';
  20800. this.root = object;
  20801. this.bones = bones;
  20802. this.matrix = object.matrixWorld;
  20803. this.matrixAutoUpdate = false;
  20804. }
  20805. updateMatrixWorld( force ) {
  20806. const bones = this.bones;
  20807. const geometry = this.geometry;
  20808. const position = geometry.getAttribute( 'position' );
  20809. _matrixWorldInv.copy( this.root.matrixWorld ).invert();
  20810. for ( let i = 0, j = 0; i < bones.length; i ++ ) {
  20811. const bone = bones[ i ];
  20812. if ( bone.parent && bone.parent.isBone ) {
  20813. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.matrixWorld );
  20814. _vector$2.setFromMatrixPosition( _boneMatrix );
  20815. position.setXYZ( j, _vector$2.x, _vector$2.y, _vector$2.z );
  20816. _boneMatrix.multiplyMatrices( _matrixWorldInv, bone.parent.matrixWorld );
  20817. _vector$2.setFromMatrixPosition( _boneMatrix );
  20818. position.setXYZ( j + 1, _vector$2.x, _vector$2.y, _vector$2.z );
  20819. j += 2;
  20820. }
  20821. }
  20822. geometry.getAttribute( 'position' ).needsUpdate = true;
  20823. super.updateMatrixWorld( force );
  20824. }
  20825. dispose() {
  20826. this.geometry.dispose();
  20827. this.material.dispose();
  20828. }
  20829. }
  20830. function getBoneList( object ) {
  20831. const boneList = [];
  20832. if ( object.isBone === true ) {
  20833. boneList.push( object );
  20834. }
  20835. for ( let i = 0; i < object.children.length; i ++ ) {
  20836. boneList.push.apply( boneList, getBoneList( object.children[ i ] ) );
  20837. }
  20838. return boneList;
  20839. }
  20840. class PointLightHelper extends Mesh {
  20841. constructor( light, sphereSize, color ) {
  20842. const geometry = new SphereGeometry( sphereSize, 4, 2 );
  20843. const material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20844. super( geometry, material );
  20845. this.light = light;
  20846. this.color = color;
  20847. this.type = 'PointLightHelper';
  20848. this.matrix = this.light.matrixWorld;
  20849. this.matrixAutoUpdate = false;
  20850. this.update();
  20851. /*
  20852. // TODO: delete this comment?
  20853. const distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  20854. const distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  20855. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  20856. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  20857. const d = light.distance;
  20858. if ( d === 0.0 ) {
  20859. this.lightDistance.visible = false;
  20860. } else {
  20861. this.lightDistance.scale.set( d, d, d );
  20862. }
  20863. this.add( this.lightDistance );
  20864. */
  20865. }
  20866. dispose() {
  20867. this.geometry.dispose();
  20868. this.material.dispose();
  20869. }
  20870. update() {
  20871. this.light.updateWorldMatrix( true, false );
  20872. if ( this.color !== undefined ) {
  20873. this.material.color.set( this.color );
  20874. } else {
  20875. this.material.color.copy( this.light.color );
  20876. }
  20877. /*
  20878. const d = this.light.distance;
  20879. if ( d === 0.0 ) {
  20880. this.lightDistance.visible = false;
  20881. } else {
  20882. this.lightDistance.visible = true;
  20883. this.lightDistance.scale.set( d, d, d );
  20884. }
  20885. */
  20886. }
  20887. }
  20888. const _vector$1 = /*@__PURE__*/ new Vector3();
  20889. const _color1 = /*@__PURE__*/ new Color();
  20890. const _color2 = /*@__PURE__*/ new Color();
  20891. class HemisphereLightHelper extends Object3D {
  20892. constructor( light, size, color ) {
  20893. super();
  20894. this.light = light;
  20895. this.matrix = light.matrixWorld;
  20896. this.matrixAutoUpdate = false;
  20897. this.color = color;
  20898. this.type = 'HemisphereLightHelper';
  20899. const geometry = new OctahedronGeometry( size );
  20900. geometry.rotateY( Math.PI * 0.5 );
  20901. this.material = new MeshBasicMaterial( { wireframe: true, fog: false, toneMapped: false } );
  20902. if ( this.color === undefined ) this.material.vertexColors = true;
  20903. const position = geometry.getAttribute( 'position' );
  20904. const colors = new Float32Array( position.count * 3 );
  20905. geometry.setAttribute( 'color', new BufferAttribute( colors, 3 ) );
  20906. this.add( new Mesh( geometry, this.material ) );
  20907. this.update();
  20908. }
  20909. dispose() {
  20910. this.children[ 0 ].geometry.dispose();
  20911. this.children[ 0 ].material.dispose();
  20912. }
  20913. update() {
  20914. const mesh = this.children[ 0 ];
  20915. if ( this.color !== undefined ) {
  20916. this.material.color.set( this.color );
  20917. } else {
  20918. const colors = mesh.geometry.getAttribute( 'color' );
  20919. _color1.copy( this.light.color );
  20920. _color2.copy( this.light.groundColor );
  20921. for ( let i = 0, l = colors.count; i < l; i ++ ) {
  20922. const color = ( i < ( l / 2 ) ) ? _color1 : _color2;
  20923. colors.setXYZ( i, color.r, color.g, color.b );
  20924. }
  20925. colors.needsUpdate = true;
  20926. }
  20927. this.light.updateWorldMatrix( true, false );
  20928. mesh.lookAt( _vector$1.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20929. }
  20930. }
  20931. class GridHelper extends LineSegments {
  20932. constructor( size = 10, divisions = 10, color1 = 0x444444, color2 = 0x888888 ) {
  20933. color1 = new Color( color1 );
  20934. color2 = new Color( color2 );
  20935. const center = divisions / 2;
  20936. const step = size / divisions;
  20937. const halfSize = size / 2;
  20938. const vertices = [], colors = [];
  20939. for ( let i = 0, j = 0, k = - halfSize; i <= divisions; i ++, k += step ) {
  20940. vertices.push( - halfSize, 0, k, halfSize, 0, k );
  20941. vertices.push( k, 0, - halfSize, k, 0, halfSize );
  20942. const color = i === center ? color1 : color2;
  20943. color.toArray( colors, j ); j += 3;
  20944. color.toArray( colors, j ); j += 3;
  20945. color.toArray( colors, j ); j += 3;
  20946. color.toArray( colors, j ); j += 3;
  20947. }
  20948. const geometry = new BufferGeometry();
  20949. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  20950. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  20951. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  20952. super( geometry, material );
  20953. this.type = 'GridHelper';
  20954. }
  20955. dispose() {
  20956. this.geometry.dispose();
  20957. this.material.dispose();
  20958. }
  20959. }
  20960. class PolarGridHelper extends LineSegments {
  20961. constructor( radius = 10, sectors = 16, rings = 8, divisions = 64, color1 = 0x444444, color2 = 0x888888 ) {
  20962. color1 = new Color( color1 );
  20963. color2 = new Color( color2 );
  20964. const vertices = [];
  20965. const colors = [];
  20966. // create the sectors
  20967. if ( sectors > 1 ) {
  20968. for ( let i = 0; i < sectors; i ++ ) {
  20969. const v = ( i / sectors ) * ( Math.PI * 2 );
  20970. const x = Math.sin( v ) * radius;
  20971. const z = Math.cos( v ) * radius;
  20972. vertices.push( 0, 0, 0 );
  20973. vertices.push( x, 0, z );
  20974. const color = ( i & 1 ) ? color1 : color2;
  20975. colors.push( color.r, color.g, color.b );
  20976. colors.push( color.r, color.g, color.b );
  20977. }
  20978. }
  20979. // create the rings
  20980. for ( let i = 0; i < rings; i ++ ) {
  20981. const color = ( i & 1 ) ? color1 : color2;
  20982. const r = radius - ( radius / rings * i );
  20983. for ( let j = 0; j < divisions; j ++ ) {
  20984. // first vertex
  20985. let v = ( j / divisions ) * ( Math.PI * 2 );
  20986. let x = Math.sin( v ) * r;
  20987. let z = Math.cos( v ) * r;
  20988. vertices.push( x, 0, z );
  20989. colors.push( color.r, color.g, color.b );
  20990. // second vertex
  20991. v = ( ( j + 1 ) / divisions ) * ( Math.PI * 2 );
  20992. x = Math.sin( v ) * r;
  20993. z = Math.cos( v ) * r;
  20994. vertices.push( x, 0, z );
  20995. colors.push( color.r, color.g, color.b );
  20996. }
  20997. }
  20998. const geometry = new BufferGeometry();
  20999. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21000. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21001. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21002. super( geometry, material );
  21003. this.type = 'PolarGridHelper';
  21004. }
  21005. dispose() {
  21006. this.geometry.dispose();
  21007. this.material.dispose();
  21008. }
  21009. }
  21010. const _v1 = /*@__PURE__*/ new Vector3();
  21011. const _v2 = /*@__PURE__*/ new Vector3();
  21012. const _v3 = /*@__PURE__*/ new Vector3();
  21013. class DirectionalLightHelper extends Object3D {
  21014. constructor( light, size, color ) {
  21015. super();
  21016. this.light = light;
  21017. this.matrix = light.matrixWorld;
  21018. this.matrixAutoUpdate = false;
  21019. this.color = color;
  21020. this.type = 'DirectionalLightHelper';
  21021. if ( size === undefined ) size = 1;
  21022. let geometry = new BufferGeometry();
  21023. geometry.setAttribute( 'position', new Float32BufferAttribute( [
  21024. - size, size, 0,
  21025. size, size, 0,
  21026. size, - size, 0,
  21027. - size, - size, 0,
  21028. - size, size, 0
  21029. ], 3 ) );
  21030. const material = new LineBasicMaterial( { fog: false, toneMapped: false } );
  21031. this.lightPlane = new Line( geometry, material );
  21032. this.add( this.lightPlane );
  21033. geometry = new BufferGeometry();
  21034. geometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 0, 1 ], 3 ) );
  21035. this.targetLine = new Line( geometry, material );
  21036. this.add( this.targetLine );
  21037. this.update();
  21038. }
  21039. dispose() {
  21040. this.lightPlane.geometry.dispose();
  21041. this.lightPlane.material.dispose();
  21042. this.targetLine.geometry.dispose();
  21043. this.targetLine.material.dispose();
  21044. }
  21045. update() {
  21046. this.light.updateWorldMatrix( true, false );
  21047. this.light.target.updateWorldMatrix( true, false );
  21048. _v1.setFromMatrixPosition( this.light.matrixWorld );
  21049. _v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21050. _v3.subVectors( _v2, _v1 );
  21051. this.lightPlane.lookAt( _v2 );
  21052. if ( this.color !== undefined ) {
  21053. this.lightPlane.material.color.set( this.color );
  21054. this.targetLine.material.color.set( this.color );
  21055. } else {
  21056. this.lightPlane.material.color.copy( this.light.color );
  21057. this.targetLine.material.color.copy( this.light.color );
  21058. }
  21059. this.targetLine.lookAt( _v2 );
  21060. this.targetLine.scale.z = _v3.length();
  21061. }
  21062. }
  21063. const _vector = /*@__PURE__*/ new Vector3();
  21064. const _camera = /*@__PURE__*/ new Camera();
  21065. /**
  21066. * - shows frustum, line of sight and up of the camera
  21067. * - suitable for fast updates
  21068. * - based on frustum visualization in lightgl.js shadowmap example
  21069. * https://github.com/evanw/lightgl.js/blob/master/tests/shadowmap.html
  21070. */
  21071. class CameraHelper extends LineSegments {
  21072. constructor( camera ) {
  21073. const geometry = new BufferGeometry();
  21074. const material = new LineBasicMaterial( { color: 0xffffff, vertexColors: true, toneMapped: false } );
  21075. const vertices = [];
  21076. const colors = [];
  21077. const pointMap = {};
  21078. // near
  21079. addLine( 'n1', 'n2' );
  21080. addLine( 'n2', 'n4' );
  21081. addLine( 'n4', 'n3' );
  21082. addLine( 'n3', 'n1' );
  21083. // far
  21084. addLine( 'f1', 'f2' );
  21085. addLine( 'f2', 'f4' );
  21086. addLine( 'f4', 'f3' );
  21087. addLine( 'f3', 'f1' );
  21088. // sides
  21089. addLine( 'n1', 'f1' );
  21090. addLine( 'n2', 'f2' );
  21091. addLine( 'n3', 'f3' );
  21092. addLine( 'n4', 'f4' );
  21093. // cone
  21094. addLine( 'p', 'n1' );
  21095. addLine( 'p', 'n2' );
  21096. addLine( 'p', 'n3' );
  21097. addLine( 'p', 'n4' );
  21098. // up
  21099. addLine( 'u1', 'u2' );
  21100. addLine( 'u2', 'u3' );
  21101. addLine( 'u3', 'u1' );
  21102. // target
  21103. addLine( 'c', 't' );
  21104. addLine( 'p', 'c' );
  21105. // cross
  21106. addLine( 'cn1', 'cn2' );
  21107. addLine( 'cn3', 'cn4' );
  21108. addLine( 'cf1', 'cf2' );
  21109. addLine( 'cf3', 'cf4' );
  21110. function addLine( a, b ) {
  21111. addPoint( a );
  21112. addPoint( b );
  21113. }
  21114. function addPoint( id ) {
  21115. vertices.push( 0, 0, 0 );
  21116. colors.push( 0, 0, 0 );
  21117. if ( pointMap[ id ] === undefined ) {
  21118. pointMap[ id ] = [];
  21119. }
  21120. pointMap[ id ].push( ( vertices.length / 3 ) - 1 );
  21121. }
  21122. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21123. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21124. super( geometry, material );
  21125. this.type = 'CameraHelper';
  21126. this.camera = camera;
  21127. if ( this.camera.updateProjectionMatrix ) this.camera.updateProjectionMatrix();
  21128. this.matrix = camera.matrixWorld;
  21129. this.matrixAutoUpdate = false;
  21130. this.pointMap = pointMap;
  21131. this.update();
  21132. // colors
  21133. const colorFrustum = new Color( 0xffaa00 );
  21134. const colorCone = new Color( 0xff0000 );
  21135. const colorUp = new Color( 0x00aaff );
  21136. const colorTarget = new Color( 0xffffff );
  21137. const colorCross = new Color( 0x333333 );
  21138. this.setColors( colorFrustum, colorCone, colorUp, colorTarget, colorCross );
  21139. }
  21140. setColors( frustum, cone, up, target, cross ) {
  21141. const geometry = this.geometry;
  21142. const colorAttribute = geometry.getAttribute( 'color' );
  21143. // near
  21144. colorAttribute.setXYZ( 0, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 1, frustum.r, frustum.g, frustum.b ); // n1, n2
  21145. colorAttribute.setXYZ( 2, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 3, frustum.r, frustum.g, frustum.b ); // n2, n4
  21146. colorAttribute.setXYZ( 4, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 5, frustum.r, frustum.g, frustum.b ); // n4, n3
  21147. colorAttribute.setXYZ( 6, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 7, frustum.r, frustum.g, frustum.b ); // n3, n1
  21148. // far
  21149. colorAttribute.setXYZ( 8, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 9, frustum.r, frustum.g, frustum.b ); // f1, f2
  21150. colorAttribute.setXYZ( 10, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 11, frustum.r, frustum.g, frustum.b ); // f2, f4
  21151. colorAttribute.setXYZ( 12, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 13, frustum.r, frustum.g, frustum.b ); // f4, f3
  21152. colorAttribute.setXYZ( 14, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 15, frustum.r, frustum.g, frustum.b ); // f3, f1
  21153. // sides
  21154. colorAttribute.setXYZ( 16, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 17, frustum.r, frustum.g, frustum.b ); // n1, f1
  21155. colorAttribute.setXYZ( 18, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 19, frustum.r, frustum.g, frustum.b ); // n2, f2
  21156. colorAttribute.setXYZ( 20, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 21, frustum.r, frustum.g, frustum.b ); // n3, f3
  21157. colorAttribute.setXYZ( 22, frustum.r, frustum.g, frustum.b ); colorAttribute.setXYZ( 23, frustum.r, frustum.g, frustum.b ); // n4, f4
  21158. // cone
  21159. colorAttribute.setXYZ( 24, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 25, cone.r, cone.g, cone.b ); // p, n1
  21160. colorAttribute.setXYZ( 26, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 27, cone.r, cone.g, cone.b ); // p, n2
  21161. colorAttribute.setXYZ( 28, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 29, cone.r, cone.g, cone.b ); // p, n3
  21162. colorAttribute.setXYZ( 30, cone.r, cone.g, cone.b ); colorAttribute.setXYZ( 31, cone.r, cone.g, cone.b ); // p, n4
  21163. // up
  21164. colorAttribute.setXYZ( 32, up.r, up.g, up.b ); colorAttribute.setXYZ( 33, up.r, up.g, up.b ); // u1, u2
  21165. colorAttribute.setXYZ( 34, up.r, up.g, up.b ); colorAttribute.setXYZ( 35, up.r, up.g, up.b ); // u2, u3
  21166. colorAttribute.setXYZ( 36, up.r, up.g, up.b ); colorAttribute.setXYZ( 37, up.r, up.g, up.b ); // u3, u1
  21167. // target
  21168. colorAttribute.setXYZ( 38, target.r, target.g, target.b ); colorAttribute.setXYZ( 39, target.r, target.g, target.b ); // c, t
  21169. colorAttribute.setXYZ( 40, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 41, cross.r, cross.g, cross.b ); // p, c
  21170. // cross
  21171. colorAttribute.setXYZ( 42, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 43, cross.r, cross.g, cross.b ); // cn1, cn2
  21172. colorAttribute.setXYZ( 44, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 45, cross.r, cross.g, cross.b ); // cn3, cn4
  21173. colorAttribute.setXYZ( 46, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 47, cross.r, cross.g, cross.b ); // cf1, cf2
  21174. colorAttribute.setXYZ( 48, cross.r, cross.g, cross.b ); colorAttribute.setXYZ( 49, cross.r, cross.g, cross.b ); // cf3, cf4
  21175. colorAttribute.needsUpdate = true;
  21176. }
  21177. update() {
  21178. const geometry = this.geometry;
  21179. const pointMap = this.pointMap;
  21180. const w = 1, h = 1;
  21181. // we need just camera projection matrix inverse
  21182. // world matrix must be identity
  21183. _camera.projectionMatrixInverse.copy( this.camera.projectionMatrixInverse );
  21184. // center / target
  21185. setPoint( 'c', pointMap, geometry, _camera, 0, 0, - 1 );
  21186. setPoint( 't', pointMap, geometry, _camera, 0, 0, 1 );
  21187. // near
  21188. setPoint( 'n1', pointMap, geometry, _camera, - w, - h, - 1 );
  21189. setPoint( 'n2', pointMap, geometry, _camera, w, - h, - 1 );
  21190. setPoint( 'n3', pointMap, geometry, _camera, - w, h, - 1 );
  21191. setPoint( 'n4', pointMap, geometry, _camera, w, h, - 1 );
  21192. // far
  21193. setPoint( 'f1', pointMap, geometry, _camera, - w, - h, 1 );
  21194. setPoint( 'f2', pointMap, geometry, _camera, w, - h, 1 );
  21195. setPoint( 'f3', pointMap, geometry, _camera, - w, h, 1 );
  21196. setPoint( 'f4', pointMap, geometry, _camera, w, h, 1 );
  21197. // up
  21198. setPoint( 'u1', pointMap, geometry, _camera, w * 0.7, h * 1.1, - 1 );
  21199. setPoint( 'u2', pointMap, geometry, _camera, - w * 0.7, h * 1.1, - 1 );
  21200. setPoint( 'u3', pointMap, geometry, _camera, 0, h * 2, - 1 );
  21201. // cross
  21202. setPoint( 'cf1', pointMap, geometry, _camera, - w, 0, 1 );
  21203. setPoint( 'cf2', pointMap, geometry, _camera, w, 0, 1 );
  21204. setPoint( 'cf3', pointMap, geometry, _camera, 0, - h, 1 );
  21205. setPoint( 'cf4', pointMap, geometry, _camera, 0, h, 1 );
  21206. setPoint( 'cn1', pointMap, geometry, _camera, - w, 0, - 1 );
  21207. setPoint( 'cn2', pointMap, geometry, _camera, w, 0, - 1 );
  21208. setPoint( 'cn3', pointMap, geometry, _camera, 0, - h, - 1 );
  21209. setPoint( 'cn4', pointMap, geometry, _camera, 0, h, - 1 );
  21210. geometry.getAttribute( 'position' ).needsUpdate = true;
  21211. }
  21212. dispose() {
  21213. this.geometry.dispose();
  21214. this.material.dispose();
  21215. }
  21216. }
  21217. function setPoint( point, pointMap, geometry, camera, x, y, z ) {
  21218. _vector.set( x, y, z ).unproject( camera );
  21219. const points = pointMap[ point ];
  21220. if ( points !== undefined ) {
  21221. const position = geometry.getAttribute( 'position' );
  21222. for ( let i = 0, l = points.length; i < l; i ++ ) {
  21223. position.setXYZ( points[ i ], _vector.x, _vector.y, _vector.z );
  21224. }
  21225. }
  21226. }
  21227. const _box = /*@__PURE__*/ new Box3();
  21228. class BoxHelper extends LineSegments {
  21229. constructor( object, color = 0xffff00 ) {
  21230. 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 ] );
  21231. const positions = new Float32Array( 8 * 3 );
  21232. const geometry = new BufferGeometry();
  21233. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21234. geometry.setAttribute( 'position', new BufferAttribute( positions, 3 ) );
  21235. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21236. this.object = object;
  21237. this.type = 'BoxHelper';
  21238. this.matrixAutoUpdate = false;
  21239. this.update();
  21240. }
  21241. update( object ) {
  21242. if ( object !== undefined ) {
  21243. console.warn( 'THREE.BoxHelper: .update() has no longer arguments.' );
  21244. }
  21245. if ( this.object !== undefined ) {
  21246. _box.setFromObject( this.object );
  21247. }
  21248. if ( _box.isEmpty() ) return;
  21249. const min = _box.min;
  21250. const max = _box.max;
  21251. /*
  21252. 5____4
  21253. 1/___0/|
  21254. | 6__|_7
  21255. 2/___3/
  21256. 0: max.x, max.y, max.z
  21257. 1: min.x, max.y, max.z
  21258. 2: min.x, min.y, max.z
  21259. 3: max.x, min.y, max.z
  21260. 4: max.x, max.y, min.z
  21261. 5: min.x, max.y, min.z
  21262. 6: min.x, min.y, min.z
  21263. 7: max.x, min.y, min.z
  21264. */
  21265. const position = this.geometry.attributes.position;
  21266. const array = position.array;
  21267. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21268. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21269. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21270. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21271. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21272. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21273. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21274. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21275. position.needsUpdate = true;
  21276. this.geometry.computeBoundingSphere();
  21277. }
  21278. setFromObject( object ) {
  21279. this.object = object;
  21280. this.update();
  21281. return this;
  21282. }
  21283. copy( source, recursive ) {
  21284. super.copy( source, recursive );
  21285. this.object = source.object;
  21286. return this;
  21287. }
  21288. dispose() {
  21289. this.geometry.dispose();
  21290. this.material.dispose();
  21291. }
  21292. }
  21293. class Box3Helper extends LineSegments {
  21294. constructor( box, color = 0xffff00 ) {
  21295. 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 ] );
  21296. 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 ];
  21297. const geometry = new BufferGeometry();
  21298. geometry.setIndex( new BufferAttribute( indices, 1 ) );
  21299. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21300. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21301. this.box = box;
  21302. this.type = 'Box3Helper';
  21303. this.geometry.computeBoundingSphere();
  21304. }
  21305. updateMatrixWorld( force ) {
  21306. const box = this.box;
  21307. if ( box.isEmpty() ) return;
  21308. box.getCenter( this.position );
  21309. box.getSize( this.scale );
  21310. this.scale.multiplyScalar( 0.5 );
  21311. super.updateMatrixWorld( force );
  21312. }
  21313. dispose() {
  21314. this.geometry.dispose();
  21315. this.material.dispose();
  21316. }
  21317. }
  21318. class PlaneHelper extends Line {
  21319. constructor( plane, size = 1, hex = 0xffff00 ) {
  21320. const color = hex;
  21321. 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 ];
  21322. const geometry = new BufferGeometry();
  21323. geometry.setAttribute( 'position', new Float32BufferAttribute( positions, 3 ) );
  21324. geometry.computeBoundingSphere();
  21325. super( geometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21326. this.type = 'PlaneHelper';
  21327. this.plane = plane;
  21328. this.size = size;
  21329. const positions2 = [ 1, 1, 0, - 1, 1, 0, - 1, - 1, 0, 1, 1, 0, - 1, - 1, 0, 1, - 1, 0 ];
  21330. const geometry2 = new BufferGeometry();
  21331. geometry2.setAttribute( 'position', new Float32BufferAttribute( positions2, 3 ) );
  21332. geometry2.computeBoundingSphere();
  21333. this.add( new Mesh( geometry2, new MeshBasicMaterial( { color: color, opacity: 0.2, transparent: true, depthWrite: false, toneMapped: false } ) ) );
  21334. }
  21335. updateMatrixWorld( force ) {
  21336. this.position.set( 0, 0, 0 );
  21337. this.scale.set( 0.5 * this.size, 0.5 * this.size, 1 );
  21338. this.lookAt( this.plane.normal );
  21339. this.translateZ( - this.plane.constant );
  21340. super.updateMatrixWorld( force );
  21341. }
  21342. dispose() {
  21343. this.geometry.dispose();
  21344. this.material.dispose();
  21345. this.children[ 0 ].geometry.dispose();
  21346. this.children[ 0 ].material.dispose();
  21347. }
  21348. }
  21349. const _axis = /*@__PURE__*/ new Vector3();
  21350. let _lineGeometry, _coneGeometry;
  21351. class ArrowHelper extends Object3D {
  21352. // dir is assumed to be normalized
  21353. 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 ) {
  21354. super();
  21355. this.type = 'ArrowHelper';
  21356. if ( _lineGeometry === undefined ) {
  21357. _lineGeometry = new BufferGeometry();
  21358. _lineGeometry.setAttribute( 'position', new Float32BufferAttribute( [ 0, 0, 0, 0, 1, 0 ], 3 ) );
  21359. _coneGeometry = new CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21360. _coneGeometry.translate( 0, - 0.5, 0 );
  21361. }
  21362. this.position.copy( origin );
  21363. this.line = new Line( _lineGeometry, new LineBasicMaterial( { color: color, toneMapped: false } ) );
  21364. this.line.matrixAutoUpdate = false;
  21365. this.add( this.line );
  21366. this.cone = new Mesh( _coneGeometry, new MeshBasicMaterial( { color: color, toneMapped: false } ) );
  21367. this.cone.matrixAutoUpdate = false;
  21368. this.add( this.cone );
  21369. this.setDirection( dir );
  21370. this.setLength( length, headLength, headWidth );
  21371. }
  21372. setDirection( dir ) {
  21373. // dir is assumed to be normalized
  21374. if ( dir.y > 0.99999 ) {
  21375. this.quaternion.set( 0, 0, 0, 1 );
  21376. } else if ( dir.y < - 0.99999 ) {
  21377. this.quaternion.set( 1, 0, 0, 0 );
  21378. } else {
  21379. _axis.set( dir.z, 0, - dir.x ).normalize();
  21380. const radians = Math.acos( dir.y );
  21381. this.quaternion.setFromAxisAngle( _axis, radians );
  21382. }
  21383. }
  21384. setLength( length, headLength = length * 0.2, headWidth = headLength * 0.2 ) {
  21385. this.line.scale.set( 1, Math.max( 0.0001, length - headLength ), 1 ); // see #17458
  21386. this.line.updateMatrix();
  21387. this.cone.scale.set( headWidth, headLength, headWidth );
  21388. this.cone.position.y = length;
  21389. this.cone.updateMatrix();
  21390. }
  21391. setColor( color ) {
  21392. this.line.material.color.set( color );
  21393. this.cone.material.color.set( color );
  21394. }
  21395. copy( source ) {
  21396. super.copy( source, false );
  21397. this.line.copy( source.line );
  21398. this.cone.copy( source.cone );
  21399. return this;
  21400. }
  21401. dispose() {
  21402. this.line.geometry.dispose();
  21403. this.line.material.dispose();
  21404. this.cone.geometry.dispose();
  21405. this.cone.material.dispose();
  21406. }
  21407. }
  21408. class AxesHelper extends LineSegments {
  21409. constructor( size = 1 ) {
  21410. const vertices = [
  21411. 0, 0, 0, size, 0, 0,
  21412. 0, 0, 0, 0, size, 0,
  21413. 0, 0, 0, 0, 0, size
  21414. ];
  21415. const colors = [
  21416. 1, 0, 0, 1, 0.6, 0,
  21417. 0, 1, 0, 0.6, 1, 0,
  21418. 0, 0, 1, 0, 0.6, 1
  21419. ];
  21420. const geometry = new BufferGeometry();
  21421. geometry.setAttribute( 'position', new Float32BufferAttribute( vertices, 3 ) );
  21422. geometry.setAttribute( 'color', new Float32BufferAttribute( colors, 3 ) );
  21423. const material = new LineBasicMaterial( { vertexColors: true, toneMapped: false } );
  21424. super( geometry, material );
  21425. this.type = 'AxesHelper';
  21426. }
  21427. setColors( xAxisColor, yAxisColor, zAxisColor ) {
  21428. const color = new Color();
  21429. const array = this.geometry.attributes.color.array;
  21430. color.set( xAxisColor );
  21431. color.toArray( array, 0 );
  21432. color.toArray( array, 3 );
  21433. color.set( yAxisColor );
  21434. color.toArray( array, 6 );
  21435. color.toArray( array, 9 );
  21436. color.set( zAxisColor );
  21437. color.toArray( array, 12 );
  21438. color.toArray( array, 15 );
  21439. this.geometry.attributes.color.needsUpdate = true;
  21440. return this;
  21441. }
  21442. dispose() {
  21443. this.geometry.dispose();
  21444. this.material.dispose();
  21445. }
  21446. }
  21447. class ShapePath {
  21448. constructor() {
  21449. this.type = 'ShapePath';
  21450. this.color = new Color();
  21451. this.subPaths = [];
  21452. this.currentPath = null;
  21453. }
  21454. moveTo( x, y ) {
  21455. this.currentPath = new Path();
  21456. this.subPaths.push( this.currentPath );
  21457. this.currentPath.moveTo( x, y );
  21458. return this;
  21459. }
  21460. lineTo( x, y ) {
  21461. this.currentPath.lineTo( x, y );
  21462. return this;
  21463. }
  21464. quadraticCurveTo( aCPx, aCPy, aX, aY ) {
  21465. this.currentPath.quadraticCurveTo( aCPx, aCPy, aX, aY );
  21466. return this;
  21467. }
  21468. bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  21469. this.currentPath.bezierCurveTo( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY );
  21470. return this;
  21471. }
  21472. splineThru( pts ) {
  21473. this.currentPath.splineThru( pts );
  21474. return this;
  21475. }
  21476. toShapes( isCCW ) {
  21477. function toShapesNoHoles( inSubpaths ) {
  21478. const shapes = [];
  21479. for ( let i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21480. const tmpPath = inSubpaths[ i ];
  21481. const tmpShape = new Shape();
  21482. tmpShape.curves = tmpPath.curves;
  21483. shapes.push( tmpShape );
  21484. }
  21485. return shapes;
  21486. }
  21487. function isPointInsidePolygon( inPt, inPolygon ) {
  21488. const polyLen = inPolygon.length;
  21489. // inPt on polygon contour => immediate success or
  21490. // toggling of inside/outside at every single! intersection point of an edge
  21491. // with the horizontal line through inPt, left of inPt
  21492. // not counting lowerY endpoints of edges and whole edges on that line
  21493. let inside = false;
  21494. for ( let p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21495. let edgeLowPt = inPolygon[ p ];
  21496. let edgeHighPt = inPolygon[ q ];
  21497. let edgeDx = edgeHighPt.x - edgeLowPt.x;
  21498. let edgeDy = edgeHighPt.y - edgeLowPt.y;
  21499. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21500. // not parallel
  21501. if ( edgeDy < 0 ) {
  21502. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21503. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21504. }
  21505. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21506. if ( inPt.y === edgeLowPt.y ) {
  21507. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21508. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21509. } else {
  21510. const perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21511. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21512. if ( perpEdge < 0 ) continue;
  21513. inside = ! inside; // true intersection left of inPt
  21514. }
  21515. } else {
  21516. // parallel or collinear
  21517. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21518. // edge lies on the same horizontal line as inPt
  21519. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21520. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21521. // continue;
  21522. }
  21523. }
  21524. return inside;
  21525. }
  21526. const isClockWise = ShapeUtils.isClockWise;
  21527. const subPaths = this.subPaths;
  21528. if ( subPaths.length === 0 ) return [];
  21529. let solid, tmpPath, tmpShape;
  21530. const shapes = [];
  21531. if ( subPaths.length === 1 ) {
  21532. tmpPath = subPaths[ 0 ];
  21533. tmpShape = new Shape();
  21534. tmpShape.curves = tmpPath.curves;
  21535. shapes.push( tmpShape );
  21536. return shapes;
  21537. }
  21538. let holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21539. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21540. // console.log("Holes first", holesFirst);
  21541. const betterShapeHoles = [];
  21542. const newShapes = [];
  21543. let newShapeHoles = [];
  21544. let mainIdx = 0;
  21545. let tmpPoints;
  21546. newShapes[ mainIdx ] = undefined;
  21547. newShapeHoles[ mainIdx ] = [];
  21548. for ( let i = 0, l = subPaths.length; i < l; i ++ ) {
  21549. tmpPath = subPaths[ i ];
  21550. tmpPoints = tmpPath.getPoints();
  21551. solid = isClockWise( tmpPoints );
  21552. solid = isCCW ? ! solid : solid;
  21553. if ( solid ) {
  21554. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21555. newShapes[ mainIdx ] = { s: new Shape(), p: tmpPoints };
  21556. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21557. if ( holesFirst ) mainIdx ++;
  21558. newShapeHoles[ mainIdx ] = [];
  21559. //console.log('cw', i);
  21560. } else {
  21561. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21562. //console.log('ccw', i);
  21563. }
  21564. }
  21565. // only Holes? -> probably all Shapes with wrong orientation
  21566. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21567. if ( newShapes.length > 1 ) {
  21568. let ambiguous = false;
  21569. let toChange = 0;
  21570. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21571. betterShapeHoles[ sIdx ] = [];
  21572. }
  21573. for ( let sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21574. const sho = newShapeHoles[ sIdx ];
  21575. for ( let hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21576. const ho = sho[ hIdx ];
  21577. let hole_unassigned = true;
  21578. for ( let s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21579. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21580. if ( sIdx !== s2Idx ) toChange ++;
  21581. if ( hole_unassigned ) {
  21582. hole_unassigned = false;
  21583. betterShapeHoles[ s2Idx ].push( ho );
  21584. } else {
  21585. ambiguous = true;
  21586. }
  21587. }
  21588. }
  21589. if ( hole_unassigned ) {
  21590. betterShapeHoles[ sIdx ].push( ho );
  21591. }
  21592. }
  21593. }
  21594. if ( toChange > 0 && ambiguous === false ) {
  21595. newShapeHoles = betterShapeHoles;
  21596. }
  21597. }
  21598. let tmpHoles;
  21599. for ( let i = 0, il = newShapes.length; i < il; i ++ ) {
  21600. tmpShape = newShapes[ i ].s;
  21601. shapes.push( tmpShape );
  21602. tmpHoles = newShapeHoles[ i ];
  21603. for ( let j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21604. tmpShape.holes.push( tmpHoles[ j ].h );
  21605. }
  21606. }
  21607. //console.log("shape", shapes);
  21608. return shapes;
  21609. }
  21610. }
  21611. class Controls extends EventDispatcher {
  21612. constructor( object, domElement = null ) {
  21613. super();
  21614. this.object = object;
  21615. this.domElement = domElement;
  21616. this.enabled = true;
  21617. this.state = - 1;
  21618. this.keys = {};
  21619. this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };
  21620. this.touches = { ONE: null, TWO: null };
  21621. }
  21622. connect() {}
  21623. disconnect() {}
  21624. dispose() {}
  21625. update( /* delta */ ) {}
  21626. }
  21627. function contain( texture, aspect ) {
  21628. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21629. if ( imageAspect > aspect ) {
  21630. texture.repeat.x = 1;
  21631. texture.repeat.y = imageAspect / aspect;
  21632. texture.offset.x = 0;
  21633. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21634. } else {
  21635. texture.repeat.x = aspect / imageAspect;
  21636. texture.repeat.y = 1;
  21637. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21638. texture.offset.y = 0;
  21639. }
  21640. return texture;
  21641. }
  21642. function cover( texture, aspect ) {
  21643. const imageAspect = ( texture.image && texture.image.width ) ? texture.image.width / texture.image.height : 1;
  21644. if ( imageAspect > aspect ) {
  21645. texture.repeat.x = aspect / imageAspect;
  21646. texture.repeat.y = 1;
  21647. texture.offset.x = ( 1 - texture.repeat.x ) / 2;
  21648. texture.offset.y = 0;
  21649. } else {
  21650. texture.repeat.x = 1;
  21651. texture.repeat.y = imageAspect / aspect;
  21652. texture.offset.x = 0;
  21653. texture.offset.y = ( 1 - texture.repeat.y ) / 2;
  21654. }
  21655. return texture;
  21656. }
  21657. function fill( texture ) {
  21658. texture.repeat.x = 1;
  21659. texture.repeat.y = 1;
  21660. texture.offset.x = 0;
  21661. texture.offset.y = 0;
  21662. return texture;
  21663. }
  21664. /**
  21665. * Given the width, height, format, and type of a texture. Determines how many
  21666. * bytes must be used to represent the texture.
  21667. */
  21668. function getByteLength( width, height, format, type ) {
  21669. const typeByteLength = getTextureTypeByteLength( type );
  21670. switch ( format ) {
  21671. // https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml
  21672. case AlphaFormat:
  21673. return width * height;
  21674. case LuminanceFormat:
  21675. return width * height;
  21676. case LuminanceAlphaFormat:
  21677. return width * height * 2;
  21678. case RedFormat:
  21679. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21680. case RedIntegerFormat:
  21681. return ( ( width * height ) / typeByteLength.components ) * typeByteLength.byteLength;
  21682. case RGFormat:
  21683. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21684. case RGIntegerFormat:
  21685. return ( ( width * height * 2 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21686. case RGBFormat:
  21687. return ( ( width * height * 3 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21688. case RGBAFormat:
  21689. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21690. case RGBAIntegerFormat:
  21691. return ( ( width * height * 4 ) / typeByteLength.components ) * typeByteLength.byteLength;
  21692. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_s3tc_srgb/
  21693. case RGB_S3TC_DXT1_Format:
  21694. case RGBA_S3TC_DXT1_Format:
  21695. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21696. case RGBA_S3TC_DXT3_Format:
  21697. case RGBA_S3TC_DXT5_Format:
  21698. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21699. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_pvrtc/
  21700. case RGB_PVRTC_2BPPV1_Format:
  21701. case RGBA_PVRTC_2BPPV1_Format:
  21702. return ( Math.max( width, 16 ) * Math.max( height, 8 ) ) / 4;
  21703. case RGB_PVRTC_4BPPV1_Format:
  21704. case RGBA_PVRTC_4BPPV1_Format:
  21705. return ( Math.max( width, 8 ) * Math.max( height, 8 ) ) / 2;
  21706. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_etc/
  21707. case RGB_ETC1_Format:
  21708. case RGB_ETC2_Format:
  21709. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 8;
  21710. case RGBA_ETC2_EAC_Format:
  21711. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21712. // https://registry.khronos.org/webgl/extensions/WEBGL_compressed_texture_astc/
  21713. case RGBA_ASTC_4x4_Format:
  21714. return Math.floor( ( width + 3 ) / 4 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21715. case RGBA_ASTC_5x4_Format:
  21716. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 3 ) / 4 ) * 16;
  21717. case RGBA_ASTC_5x5_Format:
  21718. return Math.floor( ( width + 4 ) / 5 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21719. case RGBA_ASTC_6x5_Format:
  21720. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21721. case RGBA_ASTC_6x6_Format:
  21722. return Math.floor( ( width + 5 ) / 6 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21723. case RGBA_ASTC_8x5_Format:
  21724. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21725. case RGBA_ASTC_8x6_Format:
  21726. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21727. case RGBA_ASTC_8x8_Format:
  21728. return Math.floor( ( width + 7 ) / 8 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21729. case RGBA_ASTC_10x5_Format:
  21730. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 4 ) / 5 ) * 16;
  21731. case RGBA_ASTC_10x6_Format:
  21732. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 5 ) / 6 ) * 16;
  21733. case RGBA_ASTC_10x8_Format:
  21734. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 7 ) / 8 ) * 16;
  21735. case RGBA_ASTC_10x10_Format:
  21736. return Math.floor( ( width + 9 ) / 10 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21737. case RGBA_ASTC_12x10_Format:
  21738. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 9 ) / 10 ) * 16;
  21739. case RGBA_ASTC_12x12_Format:
  21740. return Math.floor( ( width + 11 ) / 12 ) * Math.floor( ( height + 11 ) / 12 ) * 16;
  21741. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_bptc/
  21742. case RGBA_BPTC_Format:
  21743. case RGB_BPTC_SIGNED_Format:
  21744. case RGB_BPTC_UNSIGNED_Format:
  21745. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21746. // https://registry.khronos.org/webgl/extensions/EXT_texture_compression_rgtc/
  21747. case RED_RGTC1_Format:
  21748. case SIGNED_RED_RGTC1_Format:
  21749. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 8;
  21750. case RED_GREEN_RGTC2_Format:
  21751. case SIGNED_RED_GREEN_RGTC2_Format:
  21752. return Math.ceil( width / 4 ) * Math.ceil( height / 4 ) * 16;
  21753. }
  21754. throw new Error(
  21755. `Unable to determine texture byte length for ${format} format.`,
  21756. );
  21757. }
  21758. function getTextureTypeByteLength( type ) {
  21759. switch ( type ) {
  21760. case UnsignedByteType:
  21761. case ByteType:
  21762. return { byteLength: 1, components: 1 };
  21763. case UnsignedShortType:
  21764. case ShortType:
  21765. case HalfFloatType:
  21766. return { byteLength: 2, components: 1 };
  21767. case UnsignedShort4444Type:
  21768. case UnsignedShort5551Type:
  21769. return { byteLength: 2, components: 4 };
  21770. case UnsignedIntType:
  21771. case IntType:
  21772. case FloatType:
  21773. return { byteLength: 4, components: 1 };
  21774. case UnsignedInt5999Type:
  21775. return { byteLength: 4, components: 3 };
  21776. }
  21777. throw new Error( `Unknown texture type ${type}.` );
  21778. }
  21779. const TextureUtils = {
  21780. contain,
  21781. cover,
  21782. fill,
  21783. getByteLength
  21784. };
  21785. if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
  21786. __THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'register', { detail: {
  21787. revision: REVISION,
  21788. } } ) );
  21789. }
  21790. if ( typeof window !== 'undefined' ) {
  21791. if ( window.__THREE__ ) {
  21792. console.warn( 'WARNING: Multiple instances of Three.js being imported.' );
  21793. } else {
  21794. window.__THREE__ = REVISION;
  21795. }
  21796. }
  21797. 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号